soc/intel/common/block/smbus: Set SPD array NULL if no DIMM present

Set SPD array NULL if no DIMM present. do_smbus_read_byte returns
negative value if SMBus transaction fails.

BUG=b:154445630,b:151702387
TEST=Check SPD is NULL if no DIMM in the slot.

Signed-off-by: Eric Lai <ericr_lai@compal.corp-partner.google.com>
Change-Id: Ie81adbfab5bb1d5c557fe549a158cb68e26b1162
Reviewed-on: https://review.coreboot.org/c/coreboot/+/40558
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@google.com>
This commit is contained in:
Eric Lai 2020-04-21 15:32:20 +08:00 committed by Tim Wawrzynczak
parent d2b2be3929
commit 0ee9b14c09
1 changed files with 15 additions and 8 deletions

View File

@ -38,14 +38,14 @@ static void smbus_read_spd(u8 *spd, u8 addr)
}
}
static void get_spd(u8 *spd, u8 addr)
/* return -1 if SMBus errors otherwise return 0 */
static int get_spd(u8 *spd, u8 addr)
{
if (do_smbus_read_byte(SMBUS_IO_BASE, addr, 0) == 0xff) {
/* If address is not 0, it will return CB_ERR(-1) if no dimm */
if (do_smbus_read_byte(SMBUS_IO_BASE, addr, 0) < 0) {
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;
return -1;
}
smbus_read_spd(spd, addr);
@ -58,6 +58,7 @@ static void get_spd(u8 *spd, u8 addr)
/* Restore to page 0 */
do_smbus_write_byte(SMBUS_IO_BASE, SPD_PAGE_0, 0, 0);
}
return 0;
}
static u8 spd_data[CONFIG_DIMM_MAX * CONFIG_DIMM_SPD_SIZE];
@ -66,9 +67,15 @@ 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]);
if (blk->addr_map[i] == 0) {
blk->spd_array[i] = NULL;
continue;
}
if (get_spd(&spd_data[i * CONFIG_DIMM_SPD_SIZE], blk->addr_map[i]) == 0)
blk->spd_array[i] = &spd_data[i * CONFIG_DIMM_SPD_SIZE];
else
blk->spd_array[i] = NULL;
}
update_spd_len(blk);