2020-04-02 23:48:34 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2016-10-26 16:13:14 +02:00
|
|
|
|
|
|
|
#include <cbfs.h>
|
|
|
|
#include <console/console.h>
|
2020-10-01 09:37:38 +02:00
|
|
|
#include <memory_info.h>
|
2016-10-26 16:13:14 +02:00
|
|
|
#include <spd_bin.h>
|
|
|
|
#include <string.h>
|
2017-01-28 15:59:25 +01:00
|
|
|
#include <device/dram/ddr3.h>
|
2016-10-26 16:13:14 +02:00
|
|
|
|
|
|
|
void dump_spd_info(struct spd_block *blk)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_DIMM_MAX; i++)
|
|
|
|
if (blk->spd_array[i] != NULL && blk->spd_array[i][0] != 0) {
|
2017-06-08 22:28:59 +02:00
|
|
|
printk(BIOS_DEBUG, "SPD @ 0x%02X\n", blk->addr_map[i]);
|
2016-10-26 16:13:14 +02:00
|
|
|
print_spd_info(blk->spd_array[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-01 09:37:38 +02:00
|
|
|
const char * __weak mainboard_get_dram_part_num(void)
|
|
|
|
{
|
|
|
|
/* Default weak implementation, no need to override part number. */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-03-07 06:55:33 +01:00
|
|
|
static bool use_ddr4_params(int dram_type)
|
2016-10-26 16:13:14 +02:00
|
|
|
{
|
2020-03-07 06:55:33 +01:00
|
|
|
switch (dram_type) {
|
|
|
|
case SPD_DRAM_DDR3:
|
|
|
|
case SPD_DRAM_LPDDR3_INTEL:
|
|
|
|
return false;
|
2020-03-13 10:16:20 +01:00
|
|
|
/* Below DDR type share the same attributes */
|
2020-03-07 06:55:33 +01:00
|
|
|
case SPD_DRAM_LPDDR3_JEDEC:
|
|
|
|
case SPD_DRAM_DDR4:
|
|
|
|
case SPD_DRAM_LPDDR4:
|
2020-03-13 10:16:20 +01:00
|
|
|
case SPD_DRAM_LPDDR4X:
|
2020-03-07 06:55:33 +01:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
printk(BIOS_ERR, "Defaulting to using DDR4 params. Please add dram_type check for %d to %s\n",
|
|
|
|
dram_type, __func__);
|
|
|
|
return true;
|
|
|
|
}
|
2019-09-02 09:01:56 +02:00
|
|
|
}
|
2016-10-26 16:13:14 +02:00
|
|
|
|
2019-09-02 09:01:56 +02:00
|
|
|
static const char *spd_get_module_type_string(int dram_type)
|
|
|
|
{
|
|
|
|
switch (dram_type) {
|
|
|
|
case SPD_DRAM_DDR3:
|
|
|
|
return "DDR3";
|
|
|
|
case SPD_DRAM_LPDDR3_INTEL:
|
|
|
|
case SPD_DRAM_LPDDR3_JEDEC:
|
|
|
|
return "LPDDR3";
|
|
|
|
case SPD_DRAM_DDR4:
|
|
|
|
return "DDR4";
|
2020-03-06 14:18:30 +01:00
|
|
|
case SPD_DRAM_LPDDR4:
|
|
|
|
return "LPDDR4";
|
2020-03-13 10:16:20 +01:00
|
|
|
case SPD_DRAM_LPDDR4X:
|
|
|
|
return "LPDDR4X";
|
|
|
|
case SPD_DRAM_DDR5:
|
|
|
|
return "DDR5";
|
|
|
|
case SPD_DRAM_LPDDR5:
|
|
|
|
return "LPDDR5";
|
2019-09-02 09:01:56 +02:00
|
|
|
}
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
2016-10-26 16:13:14 +02:00
|
|
|
|
2019-09-02 09:01:56 +02:00
|
|
|
static int spd_get_banks(const uint8_t spd[], int dram_type)
|
|
|
|
{
|
|
|
|
static const int ddr3_banks[4] = { 8, 16, 32, 64 };
|
|
|
|
static const int ddr4_banks[10] = { 4, 8, -1, -1, 8, 16, -1, -1, 16, 32 };
|
|
|
|
int index = (spd[SPD_DENSITY_BANKS] >> 4) & 0xf;
|
2020-03-13 10:21:59 +01:00
|
|
|
|
|
|
|
if (use_ddr4_params(dram_type)) {
|
2019-09-02 09:01:56 +02:00
|
|
|
if (index >= ARRAY_SIZE(ddr4_banks))
|
|
|
|
return -1;
|
|
|
|
return ddr4_banks[index];
|
2020-03-13 10:21:59 +01:00
|
|
|
} else {
|
|
|
|
if (index >= ARRAY_SIZE(ddr3_banks))
|
|
|
|
return -1;
|
|
|
|
return ddr3_banks[index];
|
2019-09-02 09:01:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int spd_get_capmb(const uint8_t spd[])
|
|
|
|
{
|
2020-03-06 14:18:30 +01:00
|
|
|
static const int spd_capmb[13] = { 1, 2, 4, 8, 16, 32, 64,
|
|
|
|
128, 48, 96, 12, 24, 72 };
|
2019-09-02 09:01:56 +02:00
|
|
|
int index = spd[SPD_DENSITY_BANKS] & 0xf;
|
|
|
|
if (index >= ARRAY_SIZE(spd_capmb))
|
|
|
|
return -1;
|
|
|
|
return spd_capmb[index] * 256;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int spd_get_rows(const uint8_t spd[])
|
|
|
|
{
|
|
|
|
static const int spd_rows[7] = { 12, 13, 14, 15, 16, 17, 18 };
|
|
|
|
int index = (spd[SPD_ADDRESSING] >> 3) & 7;
|
|
|
|
if (index >= ARRAY_SIZE(spd_rows))
|
|
|
|
return -1;
|
|
|
|
return spd_rows[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int spd_get_cols(const uint8_t spd[])
|
|
|
|
{
|
|
|
|
static const int spd_cols[4] = { 9, 10, 11, 12 };
|
|
|
|
int index = spd[SPD_ADDRESSING] & 7;
|
|
|
|
if (index >= ARRAY_SIZE(spd_cols))
|
|
|
|
return -1;
|
|
|
|
return spd_cols[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int spd_get_ranks(const uint8_t spd[], int dram_type)
|
|
|
|
{
|
|
|
|
static const int spd_ranks[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
2020-03-07 06:55:33 +01:00
|
|
|
int organ_offset = use_ddr4_params(dram_type) ? DDR4_ORGANIZATION
|
|
|
|
: DDR3_ORGANIZATION;
|
2019-09-02 09:01:56 +02:00
|
|
|
int index = (spd[organ_offset] >> 3) & 7;
|
|
|
|
if (index >= ARRAY_SIZE(spd_ranks))
|
|
|
|
return -1;
|
|
|
|
return spd_ranks[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int spd_get_devw(const uint8_t spd[], int dram_type)
|
|
|
|
{
|
|
|
|
static const int spd_devw[4] = { 4, 8, 16, 32 };
|
2020-03-07 06:55:33 +01:00
|
|
|
int organ_offset = use_ddr4_params(dram_type) ? DDR4_ORGANIZATION
|
|
|
|
: DDR3_ORGANIZATION;
|
2019-09-02 09:01:56 +02:00
|
|
|
int index = spd[organ_offset] & 7;
|
|
|
|
if (index >= ARRAY_SIZE(spd_devw))
|
|
|
|
return -1;
|
|
|
|
return spd_devw[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int spd_get_busw(const uint8_t spd[], int dram_type)
|
|
|
|
{
|
|
|
|
static const int spd_busw[4] = { 8, 16, 32, 64 };
|
2020-03-07 06:55:33 +01:00
|
|
|
int busw_offset = use_ddr4_params(dram_type) ? DDR4_BUS_DEV_WIDTH
|
|
|
|
: DDR3_BUS_DEV_WIDTH;
|
2019-09-02 09:01:56 +02:00
|
|
|
int index = spd[busw_offset] & 7;
|
|
|
|
if (index >= ARRAY_SIZE(spd_busw))
|
|
|
|
return -1;
|
|
|
|
return spd_busw[index];
|
|
|
|
}
|
|
|
|
|
2020-09-17 02:08:00 +02:00
|
|
|
static void spd_get_name(const uint8_t spd[], int type, const char **spd_name, size_t *len)
|
2019-09-02 09:01:56 +02:00
|
|
|
{
|
2020-09-17 02:08:00 +02:00
|
|
|
*spd_name = mainboard_get_dram_part_num();
|
|
|
|
if (*spd_name != NULL) {
|
|
|
|
*len = strlen(*spd_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
2016-10-26 16:13:14 +02:00
|
|
|
case SPD_DRAM_DDR3:
|
2020-09-17 02:08:00 +02:00
|
|
|
*spd_name = (const char *) &spd[DDR3_SPD_PART_OFF];
|
|
|
|
*len = DDR3_SPD_PART_LEN;
|
2016-10-26 16:13:14 +02:00
|
|
|
break;
|
|
|
|
case SPD_DRAM_LPDDR3_INTEL:
|
2020-09-17 02:08:00 +02:00
|
|
|
*spd_name = (const char *) &spd[LPDDR3_SPD_PART_OFF];
|
|
|
|
*len = LPDDR3_SPD_PART_LEN;
|
2016-10-26 16:13:14 +02:00
|
|
|
break;
|
2020-09-17 02:08:00 +02:00
|
|
|
/* LPDDR3, LPDDR4 and DDR4 have same part number offset and length */
|
2020-03-07 06:55:33 +01:00
|
|
|
case SPD_DRAM_LPDDR3_JEDEC:
|
2016-10-26 16:13:14 +02:00
|
|
|
case SPD_DRAM_DDR4:
|
2020-03-06 14:18:30 +01:00
|
|
|
case SPD_DRAM_LPDDR4:
|
2020-10-01 01:37:01 +02:00
|
|
|
case SPD_DRAM_LPDDR4X:
|
2020-09-17 02:08:00 +02:00
|
|
|
*spd_name = (const char *) &spd[DDR4_SPD_PART_OFF];
|
|
|
|
*len = DDR4_SPD_PART_LEN;
|
2016-10-26 16:13:14 +02:00
|
|
|
break;
|
|
|
|
default:
|
2020-09-17 02:08:00 +02:00
|
|
|
*len = 0;
|
2016-10-26 16:13:14 +02:00
|
|
|
break;
|
|
|
|
}
|
2019-09-02 09:01:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_spd_info(uint8_t spd[])
|
|
|
|
{
|
2020-09-17 02:08:00 +02:00
|
|
|
const char *nameptr = NULL;
|
|
|
|
size_t len;
|
2019-09-02 09:01:56 +02:00
|
|
|
int type = spd[SPD_DRAM_TYPE];
|
|
|
|
int banks = spd_get_banks(spd, type);
|
|
|
|
int capmb = spd_get_capmb(spd);
|
|
|
|
int rows = spd_get_rows(spd);
|
|
|
|
int cols = spd_get_cols(spd);
|
|
|
|
int ranks = spd_get_ranks(spd, type);
|
|
|
|
int devw = spd_get_devw(spd, type);
|
|
|
|
int busw = spd_get_busw(spd, type);
|
|
|
|
|
|
|
|
/* Module type */
|
|
|
|
printk(BIOS_INFO, "SPD: module type is %s\n",
|
|
|
|
spd_get_module_type_string(type));
|
|
|
|
/* Module Part Number */
|
2020-09-17 02:08:00 +02:00
|
|
|
spd_get_name(spd, type, &nameptr, &len);
|
|
|
|
if (nameptr)
|
|
|
|
printk(BIOS_INFO, "SPD: module part number is %.*s\n", (int) len, nameptr);
|
2016-10-26 16:13:14 +02:00
|
|
|
|
|
|
|
printk(BIOS_INFO,
|
|
|
|
"SPD: banks %d, ranks %d, rows %d, columns %d, density %d Mb\n",
|
|
|
|
banks, ranks, rows, cols, capmb);
|
|
|
|
printk(BIOS_INFO, "SPD: device width %d bits, bus width %d bits\n",
|
|
|
|
devw, busw);
|
|
|
|
|
|
|
|
if (capmb > 0 && busw > 0 && devw > 0 && ranks > 0) {
|
|
|
|
/* SIZE = DENSITY / 8 * BUS_WIDTH / SDRAM_WIDTH * RANKS */
|
|
|
|
printk(BIOS_INFO, "SPD: module size is %u MB (per channel)\n",
|
|
|
|
capmb / 8 * busw / devw * ranks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_spd_cbfs_rdev(struct region_device *spd_rdev, u8 spd_index)
|
|
|
|
{
|
|
|
|
struct cbfsf fh;
|
|
|
|
|
|
|
|
uint32_t cbfs_type = CBFS_TYPE_SPD;
|
|
|
|
|
2016-12-13 15:57:15 +01:00
|
|
|
if (cbfs_boot_locate(&fh, "spd.bin", &cbfs_type) < 0)
|
|
|
|
return -1;
|
2016-10-26 16:13:14 +02:00
|
|
|
cbfs_file_data(spd_rdev, &fh);
|
|
|
|
return rdev_chain(spd_rdev, spd_rdev, spd_index * CONFIG_DIMM_SPD_SIZE,
|
|
|
|
CONFIG_DIMM_SPD_SIZE);
|
|
|
|
}
|
|
|
|
|
2017-01-28 15:59:25 +01:00
|
|
|
#if CONFIG_DIMM_SPD_SIZE == 128
|
|
|
|
int read_ddr3_spd_from_cbfs(u8 *buf, int idx)
|
|
|
|
{
|
|
|
|
const int SPD_CRC_HI = 127;
|
|
|
|
const int SPD_CRC_LO = 126;
|
|
|
|
|
cbfs: Simplify load/map API names, remove type arguments
This patch renames cbfs_boot_map_with_leak() and cbfs_boot_load_file()
to cbfs_map() and cbfs_load() respectively. This is supposed to be the
start of a new, better organized CBFS API where the most common
operations have the most simple and straight-forward names. Less
commonly used variants of these operations (e.g. cbfs_ro_load() or
cbfs_region_load()) can be introduced later. It seems unnecessary to
keep carrying around "boot" in the names of most CBFS APIs if the vast
majority of accesses go to the boot CBFS (instead, more unusual
operations should have longer names that describe how they diverge from
the common ones).
cbfs_map() is paired with a new cbfs_unmap() to allow callers to cleanly
reap mappings when desired. A few new cbfs_unmap() calls are added to
generic code where it makes sense, but it seems unnecessary to introduce
this everywhere in platform or architecture specific code where the boot
medium is known to be memory-mapped anyway. In fact, even for
non-memory-mapped platforms, sometimes leaking a mapping to the CBFS
cache is a much cleaner solution than jumping through hoops to provide
some other storage for some long-lived file object, and it shouldn't be
outright forbidden when it makes sense.
Additionally, remove the type arguments from these function signatures.
The goal is to eventually remove type arguments for lookup from the
whole CBFS API. Filenames already uniquely identify CBFS files. The type
field is just informational, and there should be APIs to allow callers
to check it when desired, but it's not clear what we gain from forcing
this as a parameter into every single CBFS access when the vast majority
of the time it provides no additional value and is just clutter.
Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: Ib24325400815a9c3d25f66c61829a24a239bb88e
Reviewed-on: https://review.coreboot.org/c/coreboot/+/39304
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Wim Vervoorn <wvervoorn@eltan.com>
Reviewed-by: Mariusz Szafrański <mariuszx.szafranski@intel.com>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2020-03-05 01:52:08 +01:00
|
|
|
char *spd_file;
|
2017-01-28 15:59:25 +01:00
|
|
|
size_t spd_file_len = 0;
|
|
|
|
size_t min_len = (idx + 1) * CONFIG_DIMM_SPD_SIZE;
|
|
|
|
|
cbfs: Simplify load/map API names, remove type arguments
This patch renames cbfs_boot_map_with_leak() and cbfs_boot_load_file()
to cbfs_map() and cbfs_load() respectively. This is supposed to be the
start of a new, better organized CBFS API where the most common
operations have the most simple and straight-forward names. Less
commonly used variants of these operations (e.g. cbfs_ro_load() or
cbfs_region_load()) can be introduced later. It seems unnecessary to
keep carrying around "boot" in the names of most CBFS APIs if the vast
majority of accesses go to the boot CBFS (instead, more unusual
operations should have longer names that describe how they diverge from
the common ones).
cbfs_map() is paired with a new cbfs_unmap() to allow callers to cleanly
reap mappings when desired. A few new cbfs_unmap() calls are added to
generic code where it makes sense, but it seems unnecessary to introduce
this everywhere in platform or architecture specific code where the boot
medium is known to be memory-mapped anyway. In fact, even for
non-memory-mapped platforms, sometimes leaking a mapping to the CBFS
cache is a much cleaner solution than jumping through hoops to provide
some other storage for some long-lived file object, and it shouldn't be
outright forbidden when it makes sense.
Additionally, remove the type arguments from these function signatures.
The goal is to eventually remove type arguments for lookup from the
whole CBFS API. Filenames already uniquely identify CBFS files. The type
field is just informational, and there should be APIs to allow callers
to check it when desired, but it's not clear what we gain from forcing
this as a parameter into every single CBFS access when the vast majority
of the time it provides no additional value and is just clutter.
Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: Ib24325400815a9c3d25f66c61829a24a239bb88e
Reviewed-on: https://review.coreboot.org/c/coreboot/+/39304
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Wim Vervoorn <wvervoorn@eltan.com>
Reviewed-by: Mariusz Szafrański <mariuszx.szafranski@intel.com>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2020-03-05 01:52:08 +01:00
|
|
|
spd_file = cbfs_map("spd.bin", &spd_file_len);
|
2017-01-28 15:59:25 +01:00
|
|
|
if (!spd_file)
|
|
|
|
printk(BIOS_EMERG, "file [spd.bin] not found in CBFS");
|
|
|
|
if (spd_file_len < min_len)
|
|
|
|
printk(BIOS_EMERG, "Missing SPD data.");
|
|
|
|
if (!spd_file || spd_file_len < min_len)
|
|
|
|
return -1;
|
|
|
|
|
2017-03-11 00:23:24 +01:00
|
|
|
memcpy(buf, spd_file + (idx * CONFIG_DIMM_SPD_SIZE),
|
|
|
|
CONFIG_DIMM_SPD_SIZE);
|
cbfs: Simplify load/map API names, remove type arguments
This patch renames cbfs_boot_map_with_leak() and cbfs_boot_load_file()
to cbfs_map() and cbfs_load() respectively. This is supposed to be the
start of a new, better organized CBFS API where the most common
operations have the most simple and straight-forward names. Less
commonly used variants of these operations (e.g. cbfs_ro_load() or
cbfs_region_load()) can be introduced later. It seems unnecessary to
keep carrying around "boot" in the names of most CBFS APIs if the vast
majority of accesses go to the boot CBFS (instead, more unusual
operations should have longer names that describe how they diverge from
the common ones).
cbfs_map() is paired with a new cbfs_unmap() to allow callers to cleanly
reap mappings when desired. A few new cbfs_unmap() calls are added to
generic code where it makes sense, but it seems unnecessary to introduce
this everywhere in platform or architecture specific code where the boot
medium is known to be memory-mapped anyway. In fact, even for
non-memory-mapped platforms, sometimes leaking a mapping to the CBFS
cache is a much cleaner solution than jumping through hoops to provide
some other storage for some long-lived file object, and it shouldn't be
outright forbidden when it makes sense.
Additionally, remove the type arguments from these function signatures.
The goal is to eventually remove type arguments for lookup from the
whole CBFS API. Filenames already uniquely identify CBFS files. The type
field is just informational, and there should be APIs to allow callers
to check it when desired, but it's not clear what we gain from forcing
this as a parameter into every single CBFS access when the vast majority
of the time it provides no additional value and is just clutter.
Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: Ib24325400815a9c3d25f66c61829a24a239bb88e
Reviewed-on: https://review.coreboot.org/c/coreboot/+/39304
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Wim Vervoorn <wvervoorn@eltan.com>
Reviewed-by: Mariusz Szafrański <mariuszx.szafranski@intel.com>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2020-03-05 01:52:08 +01:00
|
|
|
cbfs_unmap(spd_file);
|
2017-01-28 15:59:25 +01:00
|
|
|
|
|
|
|
u16 crc = spd_ddr3_calc_crc(buf, CONFIG_DIMM_SPD_SIZE);
|
|
|
|
|
|
|
|
if (((buf[SPD_CRC_LO] == 0) && (buf[SPD_CRC_HI] == 0))
|
2017-03-10 01:21:34 +01:00
|
|
|
|| (buf[SPD_CRC_LO] != (crc & 0xff))
|
|
|
|
|| (buf[SPD_CRC_HI] != (crc >> 8))) {
|
2017-03-11 00:23:24 +01:00
|
|
|
printk(BIOS_WARNING,
|
|
|
|
"SPD CRC %02x%02x is invalid, should be %04x\n",
|
2017-01-28 15:59:25 +01:00
|
|
|
buf[SPD_CRC_HI], buf[SPD_CRC_LO], crc);
|
|
|
|
buf[SPD_CRC_LO] = crc & 0xff;
|
|
|
|
buf[SPD_CRC_HI] = crc >> 8;
|
|
|
|
u16 i;
|
|
|
|
printk(BIOS_WARNING, "\nDisplay the SPD");
|
|
|
|
for (i = 0; i < CONFIG_DIMM_SPD_SIZE; i++) {
|
2017-03-09 03:02:24 +01:00
|
|
|
if ((i % 16) == 0x00)
|
2017-01-28 15:59:25 +01:00
|
|
|
printk(BIOS_WARNING, "\n%02x: ", i);
|
|
|
|
printk(BIOS_WARNING, "%02x ", buf[i]);
|
|
|
|
}
|
|
|
|
printk(BIOS_WARNING, "\n");
|
2017-03-10 01:21:34 +01:00
|
|
|
}
|
|
|
|
return 0;
|
2017-01-28 15:59:25 +01:00
|
|
|
}
|
|
|
|
#endif
|