spd_bin: Replace get_spd_cbfs_rdev() with spd_cbfs_map()

In pursuit of the goal of eliminating the proliferation of raw region
devices to represent CBFS files outside of the CBFS core code, this
patch removes the get_spd_cbfs_rdev() API and instead replaces it with
spd_cbfs_map() which will find and map the SPD file in one go and return
a pointer to the relevant section. (This makes it impossible to unmap
the mapping again, which all but one of the users didn't bother to do
anyway since the API is only used on platforms with memory-mapped
flash. Presumably this will stay that way in the future so this is not
something worth worrying about.)

Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: Iec7571bec809f2f0712e7a97b4c853b8b40702d1
Reviewed-on: https://review.coreboot.org/c/coreboot/+/50350
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Wim Vervoorn <wvervoorn@eltan.com>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
Julius Werner 2021-02-05 17:27:45 -08:00 committed by Patrick Georgi
parent 806deb6661
commit a9b44f4c79
12 changed files with 46 additions and 69 deletions

View File

@ -43,8 +43,7 @@ struct spd_block {
}; };
void print_spd_info(uint8_t spd[]); void print_spd_info(uint8_t spd[]);
/* Return 0 on success & -1 on failure */ uintptr_t spd_cbfs_map(u8 spd_index);
int get_spd_cbfs_rdev(struct region_device *spd_rdev, u8 spd_index);
void dump_spd_info(struct spd_block *blk); void dump_spd_info(struct spd_block *blk);
void get_spd_smbus(struct spd_block *blk); void get_spd_smbus(struct spd_block *blk);

View File

@ -210,17 +210,16 @@ void print_spd_info(uint8_t spd[])
} }
} }
int get_spd_cbfs_rdev(struct region_device *spd_rdev, u8 spd_index) uintptr_t spd_cbfs_map(u8 spd_index)
{ {
struct cbfsf fh; enum cbfs_type cbfs_type = CBFS_TYPE_SPD;
size_t size;
uint32_t cbfs_type = CBFS_TYPE_SPD; void *map = cbfs_type_map("spd.bin", &size, &cbfs_type);
if (!map || size < (spd_index + 1) * CONFIG_DIMM_SPD_SIZE)
return 0;
if (cbfs_boot_locate(&fh, "spd.bin", &cbfs_type) < 0) return (uintptr_t)map + spd_index * CONFIG_DIMM_SPD_SIZE;
return -1;
cbfs_file_data(spd_rdev, &fh);
return rdev_chain(spd_rdev, spd_rdev, spd_index * CONFIG_DIMM_SPD_SIZE,
CONFIG_DIMM_SPD_SIZE);
} }
#if CONFIG_DIMM_SPD_SIZE == 128 #if CONFIG_DIMM_SPD_SIZE == 128

View File

@ -18,7 +18,6 @@
void mainboard_memory_init_params(struct romstage_params *params, void mainboard_memory_init_params(struct romstage_params *params,
MEMORY_INIT_UPD *memory_params) MEMORY_INIT_UPD *memory_params)
{ {
struct region_device spd_rdev;
u8 spd_index = 0; u8 spd_index = 0;
if (!CONFIG(ONBOARD_SAMSUNG_MEM)) { if (!CONFIG(ONBOARD_SAMSUNG_MEM)) {
@ -28,11 +27,10 @@ void mainboard_memory_init_params(struct romstage_params *params,
spd_index = 2; spd_index = 2;
} }
if (get_spd_cbfs_rdev(&spd_rdev, spd_index) < 0)
die("spd.bin not found\n");
memory_params->PcdMemoryTypeEnable = MEM_DDR3; memory_params->PcdMemoryTypeEnable = MEM_DDR3;
memory_params->PcdMemorySpdPtr = (uintptr_t)rdev_mmap_full(&spd_rdev); memory_params->PcdMemorySpdPtr = spd_cbfs_map(spd_index);
if (!memory_params->PcdMemorySpdPtr)
die("spd.bin not found\n");
memory_params->PcdMemChannel0Config = 1; /* Memory down */ memory_params->PcdMemChannel0Config = 1; /* Memory down */
memory_params->PcdMemChannel1Config = 2; /* Disabled */ memory_params->PcdMemChannel1Config = 2; /* Disabled */
} }

View File

@ -4,6 +4,7 @@
#include <console/console.h> #include <console/console.h>
#include <gpio.h> #include <gpio.h>
#include <spd_bin.h> #include <spd_bin.h>
#include <string.h>
#include <variant/gpio.h> #include <variant/gpio.h>
#include <amdblocks/dimm_spd.h> #include <amdblocks/dimm_spd.h>
@ -22,25 +23,22 @@ uint8_t __weak variant_memory_sku(void)
int __weak variant_mainboard_read_spd(uint8_t spdAddress, int __weak variant_mainboard_read_spd(uint8_t spdAddress,
char *buf, size_t len) char *buf, size_t len)
{ {
struct region_device spd_rdev;
u8 spd_index = variant_memory_sku(); u8 spd_index = variant_memory_sku();
printk(BIOS_INFO, "%s SPD index %d\n", __func__, spd_index); printk(BIOS_INFO, "%s SPD index %d\n", __func__, spd_index);
if (get_spd_cbfs_rdev(&spd_rdev, spd_index) < 0) { void *spd = (void *)spd_cbfs_map(spd_index);
if (!spd) {
printk(BIOS_ERR, "Error: spd.bin not found\n"); printk(BIOS_ERR, "Error: spd.bin not found\n");
return -1; return -1;
} }
if (len != region_device_sz(&spd_rdev)) { if (len != CONFIG_DIMM_SPD_SIZE) {
printk(BIOS_ERR, "Error: spd.bin is not the correct size\n"); printk(BIOS_ERR, "Error: spd.bin is not the correct size\n");
return -1; return -1;
} }
if (rdev_readat(&spd_rdev, buf, 0, len) != len) { memcpy(buf, spd, len);
printk(BIOS_ERR, "Error: couldn't read spd.bin\n");
return -1;
}
return 0; return 0;
} }

View File

@ -14,15 +14,12 @@ void mainboard_memory_init_params(FSPM_UPD *mupd)
printk(BIOS_DEBUG, "spd index is 0x%x\n", spd_index); printk(BIOS_DEBUG, "spd index is 0x%x\n", spd_index);
if (spd_index > 0 && spd_index != 2) { if (spd_index > 0 && spd_index != 2) {
struct region_device spd_rdev; mem_cfg->MemorySpdDataLen = CONFIG_DIMM_SPD_SIZE;
if (get_spd_cbfs_rdev(&spd_rdev, spd_index) < 0)
die("spd.bin not found\n");
mem_cfg->MemorySpdDataLen = region_device_sz(&spd_rdev);
/* Memory leak is ok since we have memory mapped boot media */ /* Memory leak is ok since we have memory mapped boot media */
mem_cfg->MemorySpdPtr00 = (uintptr_t)rdev_mmap_full(&spd_rdev); mem_cfg->MemorySpdPtr00 = spd_cbfs_map(spd_index);
if (!mem_cfg->MemorySpdPtr00)
die("spd.bin not found\n");
mem_cfg->MemorySpdPtr10 = mem_cfg->MemorySpdPtr00; mem_cfg->MemorySpdPtr10 = mem_cfg->MemorySpdPtr00;
mem_cfg->SpdAddressTable[0] = 0x0; mem_cfg->SpdAddressTable[0] = 0x0;

View File

@ -28,14 +28,12 @@ void mainboard_memory_init_params(FSPM_UPD *mupd)
mainboard_fill_rcomp_strength_data(&mem_cfg->RcompTarget); mainboard_fill_rcomp_strength_data(&mem_cfg->RcompTarget);
if (CONFIG(BOARD_INTEL_KBLRVP3)) { if (CONFIG(BOARD_INTEL_KBLRVP3)) {
struct region_device spd_rdev;
mem_cfg->DqPinsInterleaved = 0; mem_cfg->DqPinsInterleaved = 0;
if (get_spd_cbfs_rdev(&spd_rdev, spd_index) < 0) mem_cfg->MemorySpdDataLen = CONFIG_DIMM_SPD_SIZE;
die("spd.bin not found\n");
mem_cfg->MemorySpdDataLen = region_device_sz(&spd_rdev);
/* Memory leak is ok since we have memory mapped boot media */ /* Memory leak is ok since we have memory mapped boot media */
mem_cfg->MemorySpdPtr00 = (uintptr_t)rdev_mmap_full(&spd_rdev); mem_cfg->MemorySpdPtr00 = spd_cbfs_map(spd_index);
if (!mem_cfg->MemorySpdPtr00)
die("spd.bin not found\n");
} else { /* CONFIG_BOARD_INTEL_KBLRVP7 and CONFIG_BOARD_INTEL_KBLRVP8 */ } else { /* CONFIG_BOARD_INTEL_KBLRVP7 and CONFIG_BOARD_INTEL_KBLRVP8 */
struct spd_block blk = { struct spd_block blk = {
.addr_map = { 0x50, 0x51, 0x52, 0x53, }, .addr_map = { 0x50, 0x51, 0x52, 0x53, },

View File

@ -12,7 +12,6 @@
void mainboard_memory_init_params(struct romstage_params *params, void mainboard_memory_init_params(struct romstage_params *params,
MEMORY_INIT_UPD *memory_params) MEMORY_INIT_UPD *memory_params)
{ {
struct region_device spd_rdev;
u8 spd_index = 0; u8 spd_index = 0;
if (CONFIG(ONBOARD_MEM_MICRON)) if (CONFIG(ONBOARD_MEM_MICRON))
@ -20,11 +19,10 @@ void mainboard_memory_init_params(struct romstage_params *params,
else if (CONFIG(ONBOARD_MEM_KINGSTON)) else if (CONFIG(ONBOARD_MEM_KINGSTON))
spd_index = 2; spd_index = 2;
if (get_spd_cbfs_rdev(&spd_rdev, spd_index) < 0)
die("spd.bin not found\n");
memory_params->PcdMemoryTypeEnable = MEM_DDR3; memory_params->PcdMemoryTypeEnable = MEM_DDR3;
memory_params->PcdMemorySpdPtr = (uintptr_t)rdev_mmap_full(&spd_rdev); memory_params->PcdMemorySpdPtr = spd_cbfs_map(spd_index);
if (!memory_params->PcdMemorySpdPtr)
die("spd.bin not found\n");
memory_params->PcdMemChannel0Config = 1; /* Memory down */ memory_params->PcdMemChannel0Config = 1; /* Memory down */
memory_params->PcdMemChannel1Config = 2; /* Disabled */ memory_params->PcdMemChannel1Config = 2; /* Disabled */
} }

View File

@ -30,15 +30,13 @@ void mainboard_memory_init_params(FSPM_UPD *mupd)
mainboard_fill_rcomp_res_data(&mem_cfg->RcompResistor); mainboard_fill_rcomp_res_data(&mem_cfg->RcompResistor);
mainboard_fill_rcomp_strength_data(&mem_cfg->RcompTarget); mainboard_fill_rcomp_strength_data(&mem_cfg->RcompTarget);
struct region_device spd_rdev;
mem_cfg->DqPinsInterleaved = 0; mem_cfg->DqPinsInterleaved = 0;
if (get_spd_cbfs_rdev(&spd_rdev, spd_index) < 0) mem_cfg->MemorySpdDataLen = CONFIG_DIMM_SPD_SIZE;
die("spd.bin not found\n");
mem_cfg->MemorySpdDataLen = region_device_sz(&spd_rdev);
/* Memory leak is ok since we have memory mapped boot media */ /* Memory leak is ok since we have memory mapped boot media */
// TODO evaluate google/eve way of loading // TODO evaluate google/eve way of loading
mem_cfg->MemorySpdPtr00 = (uintptr_t)rdev_mmap_full(&spd_rdev); mem_cfg->MemorySpdPtr00 = spd_cbfs_map(spd_index);
if (!mem_cfg->MemorySpdPtr00)
die("spd.bin not found\n");
mem_cfg->MemorySpdPtr10 = mem_cfg->MemorySpdPtr00; mem_cfg->MemorySpdPtr10 = mem_cfg->MemorySpdPtr00;
mupd->FspmTestConfig.DmiVc1 = 1; mupd->FspmTestConfig.DmiVc1 = 1;

View File

@ -86,19 +86,17 @@ static void meminit_cbfs_spd_index(FSP_M_CONFIG *mem_cfg,
assert(mem_slot < NUM_DIMM_SLOT); assert(mem_slot < NUM_DIMM_SLOT);
if ((spd_data_ptr == 0) || (last_spd_index != spd_index)) { if ((spd_data_ptr == 0) || (last_spd_index != spd_index)) {
struct region_device spd_rdev;
printk(BIOS_DEBUG, "SPD INDEX = %d\n", spd_index); printk(BIOS_DEBUG, "SPD INDEX = %d\n", spd_index);
if (get_spd_cbfs_rdev(&spd_rdev, spd_index) < 0) spd_data_ptr = spd_cbfs_map(spd_index);
if (!spd_data_ptr)
die("spd.bin not found or incorrect index\n"); die("spd.bin not found or incorrect index\n");
spd_data_len = region_device_sz(&spd_rdev); spd_data_len = CONFIG_DIMM_SPD_SIZE;
/* Memory leak is ok since we have memory mapped boot media */ /* Memory leak is ok since we have memory mapped boot media */
assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED)); assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED));
spd_data_ptr = (uintptr_t)rdev_mmap_full(&spd_rdev);
last_spd_index = spd_index; last_spd_index = spd_index;
print_spd_info((unsigned char *)spd_data_ptr); print_spd_info((unsigned char *)spd_data_ptr);
} }

View File

@ -39,7 +39,6 @@ static void read_spd_md(const struct soc_mem_cfg *soc_mem_cfg, const struct mem_
{ {
size_t ch; size_t ch;
size_t num_phys_ch = soc_mem_cfg->num_phys_channels; size_t num_phys_ch = soc_mem_cfg->num_phys_channels;
struct region_device spd_rdev;
uintptr_t spd_data; uintptr_t spd_data;
/* /*
@ -63,15 +62,14 @@ static void read_spd_md(const struct soc_mem_cfg *soc_mem_cfg, const struct mem_
printk(BIOS_DEBUG, "SPD index = %zu\n", info->cbfs_index); printk(BIOS_DEBUG, "SPD index = %zu\n", info->cbfs_index);
if (get_spd_cbfs_rdev(&spd_rdev, info->cbfs_index) < 0)
die("SPD not found in CBFS or incorrect index!\n");
/* Memory leak is ok as long as we have memory mapped boot media */ /* Memory leak is ok as long as we have memory mapped boot media */
_Static_assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED), _Static_assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED),
"Function assumes memory-mapped boot media"); "Function assumes memory-mapped boot media");
spd_data = (uintptr_t)rdev_mmap_full(&spd_rdev); *spd_len = CONFIG_DIMM_SPD_SIZE;
*spd_len = region_device_sz(&spd_rdev); spd_data = spd_cbfs_map(info->cbfs_index);
if (!spd_data)
die("SPD not found in CBFS or incorrect index!\n");
print_spd_info((uint8_t *)spd_data); print_spd_info((uint8_t *)spd_data);

View File

@ -10,19 +10,17 @@
static void spd_read_from_cbfs(const struct spd_info *spd_info, uintptr_t *spd_data_ptr, static void spd_read_from_cbfs(const struct spd_info *spd_info, uintptr_t *spd_data_ptr,
size_t *spd_data_len) size_t *spd_data_len)
{ {
struct region_device spd_rdev;
size_t spd_index = spd_info->spd_spec.spd_index; size_t spd_index = spd_info->spd_spec.spd_index;
printk(BIOS_DEBUG, "SPD INDEX = %lu\n", spd_index); printk(BIOS_DEBUG, "SPD INDEX = %lu\n", spd_index);
if (get_spd_cbfs_rdev(&spd_rdev, spd_index) < 0)
die("spd.bin not found or incorrect index\n");
*spd_data_len = region_device_sz(&spd_rdev);
/* Memory leak is ok since we have memory mapped boot media */ /* Memory leak is ok since we have memory mapped boot media */
assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED)); assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED));
*spd_data_ptr = (uintptr_t)rdev_mmap_full(&spd_rdev); *spd_data_len = CONFIG_DIMM_SPD_SIZE;
*spd_data_ptr = spd_cbfs_map(spd_index);
if (!*spd_data_ptr)
die("spd.bin not found or incorrect index\n");
} }
static void get_spd_data(const struct spd_info *spd_info, uintptr_t *spd_data_ptr, static void get_spd_data(const struct spd_info *spd_info, uintptr_t *spd_data_ptr,

View File

@ -10,19 +10,17 @@
static void spd_read_from_cbfs(const struct spd_info *spd_info, uintptr_t *spd_data_ptr, static void spd_read_from_cbfs(const struct spd_info *spd_info, uintptr_t *spd_data_ptr,
size_t *spd_data_len) size_t *spd_data_len)
{ {
struct region_device spd_rdev;
size_t spd_index = spd_info->spd_spec.spd_index; size_t spd_index = spd_info->spd_spec.spd_index;
printk(BIOS_DEBUG, "SPD INDEX = %lu\n", spd_index); printk(BIOS_DEBUG, "SPD INDEX = %lu\n", spd_index);
if (get_spd_cbfs_rdev(&spd_rdev, spd_index) < 0)
die("spd.bin not found or incorrect index\n");
*spd_data_len = region_device_sz(&spd_rdev);
/* Memory leak is ok since we have memory mapped boot media */ /* Memory leak is ok since we have memory mapped boot media */
assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED)); assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED));
*spd_data_ptr = (uintptr_t)rdev_mmap_full(&spd_rdev); *spd_data_len = CONFIG_DIMM_SPD_SIZE;
*spd_data_ptr = spd_cbfs_map(spd_index);
if (!*spd_data_ptr)
die("spd.bin not found or incorrect index\n");
} }
static void get_spd_data(const struct spd_info *spd_info, uintptr_t *spd_data_ptr, static void get_spd_data(const struct spd_info *spd_info, uintptr_t *spd_data_ptr,