lib/spd_bin,soc/intel/common: Move get_spd_smbus()
Only smbuslib.c and spd_bin.c share the same prototypes for SMBUS functions. Therefore, get_spd_smbus() currently only works with soc/intel/.../smbuslib.c and can be implemented there locally. This allows removal of <device/early_smbus.h>. Change-Id: Ic2d9d83ede6388a01d40c6e4768f6bb6bf899c00 Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/38121 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com>
This commit is contained in:
parent
4ae9f1e5d8
commit
756646757e
|
@ -1,56 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of the coreboot project.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2011 Alexandru Gagniuc <mr.nuke.me@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file device/early_smbus.h
|
|
||||||
*
|
|
||||||
* This file defines a common API for accessing the SMBus during early
|
|
||||||
* initialization. It defines the prototypes for common SMBus functions. The
|
|
||||||
* actual implementations are hardware-dependent.
|
|
||||||
*
|
|
||||||
* The first parameter of all SMBus functions take a u32 value smbus_dev which
|
|
||||||
* represents some information on how to access the device, and is
|
|
||||||
* implementation defined. Usually, it just contains the IO base for the smbus.
|
|
||||||
* To get this argument @ref smbus_get_device() can be used.
|
|
||||||
*
|
|
||||||
* The header only defines the prototypes. Several steps are needed to use
|
|
||||||
* these:
|
|
||||||
*
|
|
||||||
* 1. Include this header
|
|
||||||
* @code{.c}
|
|
||||||
* #include <device/early_smbus.h>
|
|
||||||
* @endcode
|
|
||||||
*
|
|
||||||
* 2. Implement early_smbus.c for the hardware, or find a compatible
|
|
||||||
* implementation.
|
|
||||||
*
|
|
||||||
* 3. Link against the file that implements these functions. In the Makefile.inc
|
|
||||||
* of the chipset, add:
|
|
||||||
* @code
|
|
||||||
* romstage-y += ./path/to/early_smbus.c
|
|
||||||
* @endcode
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DEVICE_EARLY_SMBUS_H
|
|
||||||
#define DEVICE_EARLY_SMBUS_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
u16 smbus_read_word(u8 addr, u8 offset);
|
|
||||||
u8 smbus_read_byte(u8 addr, u8 offset);
|
|
||||||
u8 smbus_write_byte(u8 addr, u8 offset, u8 value);
|
|
||||||
|
|
||||||
#endif /* DEVICE_EARLY_SMBUS_H */
|
|
|
@ -17,11 +17,8 @@
|
||||||
#include <console/console.h>
|
#include <console/console.h>
|
||||||
#include <spd_bin.h>
|
#include <spd_bin.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <device/early_smbus.h>
|
|
||||||
#include <device/dram/ddr3.h>
|
#include <device/dram/ddr3.h>
|
||||||
|
|
||||||
static u8 spd_data[CONFIG_DIMM_MAX * CONFIG_DIMM_SPD_SIZE];
|
|
||||||
|
|
||||||
void dump_spd_info(struct spd_block *blk)
|
void dump_spd_info(struct spd_block *blk)
|
||||||
{
|
{
|
||||||
u8 i;
|
u8 i;
|
||||||
|
@ -189,20 +186,6 @@ void print_spd_info(uint8_t spd[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_spd_len(struct spd_block *blk)
|
|
||||||
{
|
|
||||||
u8 i, j = 0;
|
|
||||||
for (i = 0 ; i < CONFIG_DIMM_MAX; i++)
|
|
||||||
if (blk->spd_array[i] != NULL)
|
|
||||||
j |= blk->spd_array[i][SPD_DRAM_TYPE];
|
|
||||||
|
|
||||||
/* If spd used is DDR4, then its length is 512 byte. */
|
|
||||||
if (j == SPD_DRAM_DDR4)
|
|
||||||
blk->len = SPD_PAGE_LEN_DDR4;
|
|
||||||
else
|
|
||||||
blk->len = SPD_PAGE_LEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_spd_cbfs_rdev(struct region_device *spd_rdev, u8 spd_index)
|
int get_spd_cbfs_rdev(struct region_device *spd_rdev, u8 spd_index)
|
||||||
{
|
{
|
||||||
struct cbfsf fh;
|
struct cbfsf fh;
|
||||||
|
@ -216,57 +199,6 @@ int get_spd_cbfs_rdev(struct region_device *spd_rdev, u8 spd_index)
|
||||||
CONFIG_DIMM_SPD_SIZE);
|
CONFIG_DIMM_SPD_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void smbus_read_spd(u8 *spd, u8 addr)
|
|
||||||
{
|
|
||||||
u16 i;
|
|
||||||
u8 step = 1;
|
|
||||||
|
|
||||||
if (CONFIG(SPD_READ_BY_WORD))
|
|
||||||
step = sizeof(uint16_t);
|
|
||||||
|
|
||||||
for (i = 0; i < SPD_PAGE_LEN; i += step) {
|
|
||||||
if (CONFIG(SPD_READ_BY_WORD))
|
|
||||||
((u16*)spd)[i / sizeof(uint16_t)] =
|
|
||||||
smbus_read_word(addr, i);
|
|
||||||
else
|
|
||||||
spd[i] = smbus_read_byte(addr, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void get_spd(u8 *spd, u8 addr)
|
|
||||||
{
|
|
||||||
if (smbus_read_byte(addr, 0) == 0xff) {
|
|
||||||
printk(BIOS_INFO, "No memory dimm at address %02X\n",
|
|
||||||
addr << 1);
|
|
||||||
/* Make sure spd is zeroed if dimm doesn't exist. */
|
|
||||||
memset(spd, 0, CONFIG_DIMM_SPD_SIZE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
smbus_read_spd(spd, addr);
|
|
||||||
|
|
||||||
/* Check if module is DDR4, DDR4 spd is 512 byte. */
|
|
||||||
if (spd[SPD_DRAM_TYPE] == SPD_DRAM_DDR4 &&
|
|
||||||
CONFIG_DIMM_SPD_SIZE > SPD_PAGE_LEN) {
|
|
||||||
/* Switch to page 1 */
|
|
||||||
smbus_write_byte(SPD_PAGE_1, 0, 0);
|
|
||||||
smbus_read_spd(spd + SPD_PAGE_LEN, addr);
|
|
||||||
/* Restore to page 0 */
|
|
||||||
smbus_write_byte(SPD_PAGE_0, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void get_spd_smbus(struct spd_block *blk)
|
|
||||||
{
|
|
||||||
u8 i;
|
|
||||||
for (i = 0 ; i < CONFIG_DIMM_MAX; i++) {
|
|
||||||
get_spd(&spd_data[i * CONFIG_DIMM_SPD_SIZE],
|
|
||||||
blk->addr_map[i]);
|
|
||||||
blk->spd_array[i] = &spd_data[i * CONFIG_DIMM_SPD_SIZE];
|
|
||||||
}
|
|
||||||
|
|
||||||
update_spd_len(blk);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if CONFIG_DIMM_SPD_SIZE == 128
|
#if CONFIG_DIMM_SPD_SIZE == 128
|
||||||
int read_ddr3_spd_from_cbfs(u8 *buf, int idx)
|
int read_ddr3_spd_from_cbfs(u8 *buf, int idx)
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,8 +14,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <arch/io.h>
|
#include <arch/io.h>
|
||||||
#include <device/early_smbus.h>
|
#include <console/console.h>
|
||||||
#include <device/smbus_def.h>
|
#include <device/smbus_def.h>
|
||||||
|
#include <spd_bin.h>
|
||||||
|
#include <string.h>
|
||||||
#include <timer.h>
|
#include <timer.h>
|
||||||
#include "smbuslib.h"
|
#include "smbuslib.h"
|
||||||
|
|
||||||
|
@ -176,17 +178,84 @@ int do_smbus_read_word(unsigned int smbus_base, u8 device, unsigned int address)
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 smbus_read_word(u8 addr, u8 offset)
|
static u16 smbus_read_word(u8 addr, u8 offset)
|
||||||
{
|
{
|
||||||
return do_smbus_read_word(SMBUS_IO_BASE, addr, offset);
|
return do_smbus_read_word(SMBUS_IO_BASE, addr, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 smbus_read_byte(u8 addr, u8 offset)
|
static u8 smbus_read_byte(u8 addr, u8 offset)
|
||||||
{
|
{
|
||||||
return do_smbus_read_byte(SMBUS_IO_BASE, addr, offset);
|
return do_smbus_read_byte(SMBUS_IO_BASE, addr, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 smbus_write_byte(u8 addr, u8 offset, u8 value)
|
static u8 smbus_write_byte(u8 addr, u8 offset, u8 value)
|
||||||
{
|
{
|
||||||
return do_smbus_write_byte(SMBUS_IO_BASE, addr, offset, value);
|
return do_smbus_write_byte(SMBUS_IO_BASE, addr, offset, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void update_spd_len(struct spd_block *blk)
|
||||||
|
{
|
||||||
|
u8 i, j = 0;
|
||||||
|
for (i = 0 ; i < CONFIG_DIMM_MAX; i++)
|
||||||
|
if (blk->spd_array[i] != NULL)
|
||||||
|
j |= blk->spd_array[i][SPD_DRAM_TYPE];
|
||||||
|
|
||||||
|
/* If spd used is DDR4, then its length is 512 byte. */
|
||||||
|
if (j == SPD_DRAM_DDR4)
|
||||||
|
blk->len = SPD_PAGE_LEN_DDR4;
|
||||||
|
else
|
||||||
|
blk->len = SPD_PAGE_LEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void smbus_read_spd(u8 *spd, u8 addr)
|
||||||
|
{
|
||||||
|
u16 i;
|
||||||
|
u8 step = 1;
|
||||||
|
|
||||||
|
if (CONFIG(SPD_READ_BY_WORD))
|
||||||
|
step = sizeof(uint16_t);
|
||||||
|
|
||||||
|
for (i = 0; i < SPD_PAGE_LEN; i += step) {
|
||||||
|
if (CONFIG(SPD_READ_BY_WORD))
|
||||||
|
((u16*)spd)[i / sizeof(uint16_t)] =
|
||||||
|
smbus_read_word(addr, i);
|
||||||
|
else
|
||||||
|
spd[i] = smbus_read_byte(addr, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void get_spd(u8 *spd, u8 addr)
|
||||||
|
{
|
||||||
|
if (smbus_read_byte(addr, 0) == 0xff) {
|
||||||
|
printk(BIOS_INFO, "No memory dimm at address %02X\n",
|
||||||
|
addr << 1);
|
||||||
|
/* Make sure spd is zeroed if dimm doesn't exist. */
|
||||||
|
memset(spd, 0, CONFIG_DIMM_SPD_SIZE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
smbus_read_spd(spd, addr);
|
||||||
|
|
||||||
|
/* Check if module is DDR4, DDR4 spd is 512 byte. */
|
||||||
|
if (spd[SPD_DRAM_TYPE] == SPD_DRAM_DDR4 &&
|
||||||
|
CONFIG_DIMM_SPD_SIZE > SPD_PAGE_LEN) {
|
||||||
|
/* Switch to page 1 */
|
||||||
|
smbus_write_byte(SPD_PAGE_1, 0, 0);
|
||||||
|
smbus_read_spd(spd + SPD_PAGE_LEN, addr);
|
||||||
|
/* Restore to page 0 */
|
||||||
|
smbus_write_byte(SPD_PAGE_0, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static u8 spd_data[CONFIG_DIMM_MAX * CONFIG_DIMM_SPD_SIZE];
|
||||||
|
|
||||||
|
void get_spd_smbus(struct spd_block *blk)
|
||||||
|
{
|
||||||
|
u8 i;
|
||||||
|
for (i = 0 ; i < CONFIG_DIMM_MAX; i++) {
|
||||||
|
get_spd(&spd_data[i * CONFIG_DIMM_SPD_SIZE],
|
||||||
|
blk->addr_map[i]);
|
||||||
|
blk->spd_array[i] = &spd_data[i * CONFIG_DIMM_SPD_SIZE];
|
||||||
|
}
|
||||||
|
|
||||||
|
update_spd_len(blk);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue