coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
spd.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <cbfs.h>
4 #include <console/console.h>
7 #include <soc/pei_data.h>
8 #include <soc/pei_wrapper.h>
9 #include <string.h>
10 #include <types.h>
11 
12 #define SPD_DRAM_TYPE 2
13 #define SPD_DRAM_DDR3 0x0b
14 #define SPD_DRAM_LPDDR3 0xf1
15 #define SPD_DENSITY_BANKS 4
16 #define SPD_ADDRESSING 5
17 #define SPD_ORGANIZATION 7
18 #define SPD_BUS_DEV_WIDTH 8
19 #define SPD_PART_OFF 128
20 #define SPD_PART_LEN 18
21 
22 #define SPD_LEN 256
23 
25 {
26  const int spd_banks[8] = { 8, 16, 32, 64, -1, -1, -1, -1 };
27  const int spd_capmb[8] = { 1, 2, 4, 8, 16, 32, 64, 0 };
28  const int spd_rows[8] = { 12, 13, 14, 15, 16, -1, -1, -1 };
29  const int spd_cols[8] = { 9, 10, 11, 12, -1, -1, -1, -1 };
30  const int spd_ranks[8] = { 1, 2, 3, 4, -1, -1, -1, -1 };
31  const int spd_devw[8] = { 4, 8, 16, 32, -1, -1, -1, -1 };
32  const int spd_busw[8] = { 8, 16, 32, 64, -1, -1, -1, -1 };
33  char spd_name[SPD_PART_LEN+1] = { 0 };
34 
35  int banks = spd_banks[(spd[SPD_DENSITY_BANKS] >> 4) & 7];
36  int capmb = spd_capmb[spd[SPD_DENSITY_BANKS] & 7] * 256;
37  int rows = spd_rows[(spd[SPD_ADDRESSING] >> 3) & 7];
38  int cols = spd_cols[spd[SPD_ADDRESSING] & 7];
39  int ranks = spd_ranks[(spd[SPD_ORGANIZATION] >> 3) & 7];
40  int devw = spd_devw[spd[SPD_ORGANIZATION] & 7];
41  int busw = spd_busw[spd[SPD_BUS_DEV_WIDTH] & 7];
42 
43  /* Module type */
44  printk(BIOS_INFO, "SPD: module type is ");
45  switch (spd[SPD_DRAM_TYPE]) {
46  case SPD_DRAM_DDR3:
47  printk(BIOS_INFO, "DDR3\n");
48  break;
49  case SPD_DRAM_LPDDR3:
50  printk(BIOS_INFO, "LPDDR3\n");
51  break;
52  default:
53  printk(BIOS_INFO, "Unknown (%02x)\n", spd[SPD_DRAM_TYPE]);
54  break;
55  }
56 
57  /* Module Part Number */
58  memcpy(spd_name, &spd[SPD_PART_OFF], SPD_PART_LEN);
59  spd_name[SPD_PART_LEN] = 0;
60  printk(BIOS_INFO, "SPD: module part is %s\n", spd_name);
61 
62  printk(BIOS_INFO, "SPD: banks %d, ranks %d, rows %d, columns %d, "
63  "density %d Mb\n", banks, ranks, rows, cols, capmb);
64  printk(BIOS_INFO, "SPD: device width %d bits, bus width %d bits\n",
65  devw, busw);
66 
67  if (capmb > 0 && busw > 0 && devw > 0 && ranks > 0) {
68  /* SIZE = DENSITY / 8 * BUS_WIDTH / SDRAM_WIDTH * RANKS */
69  printk(BIOS_INFO, "SPD: module size is %u MB (per channel)\n",
70  capmb / 8 * busw / devw * ranks);
71  }
72 }
73 
74 static void fill_spd_for_index(uint8_t spd[], unsigned int spd_index)
75 {
76  size_t spd_file_len;
77  uint8_t *spd_file = cbfs_map("spd.bin", &spd_file_len);
78 
79  printk(BIOS_DEBUG, "SPD index %d\n", spd_index);
80 
81  if (!spd_file)
82  die("SPD data not found.");
83 
84  if (spd_file_len < SPD_LEN)
85  die("Missing SPD data.");
86 
87  if (spd_file_len < ((spd_index + 1) * SPD_LEN)) {
88  printk(BIOS_ERR, "SPD index override to 0 - old hardware?\n");
89  spd_index = 0;
90  }
91 
92  memcpy(spd, spd_file + (spd_index * SPD_LEN), SPD_LEN);
93 
94  /* Make sure a valid SPD was found */
95  if (spd[0] == 0)
96  die("Invalid SPD data.");
97 
99 }
100 
101 /* Copy SPD data for on-board memory */
103 {
104  const unsigned int spd_index = variant_get_spd_index();
105 
107 
109  memcpy(pei_data->spd_data[1][0], pei_data->spd_data[0][0], SPD_LEN);
110  else
112 }
void * memcpy(void *dest, const void *src, size_t n)
Definition: memcpy.c:7
static void * cbfs_map(const char *name, size_t *size_out)
Definition: cbfs.h:246
#define printk(level,...)
Definition: stdlib.h:16
void __noreturn die(const char *fmt,...)
Definition: die.c:17
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define SPD_LEN
Definition: spd.c:22
#define SPD_DENSITY_BANKS
Definition: spd.c:15
#define SPD_PART_LEN
Definition: spd.c:20
#define SPD_DRAM_LPDDR3
Definition: spd.c:14
#define SPD_ADDRESSING
Definition: spd.c:16
#define SPD_ORGANIZATION
Definition: spd.c:17
#define SPD_BUS_DEV_WIDTH
Definition: spd.c:18
#define SPD_DRAM_TYPE
Definition: spd.c:12
static void fill_spd_for_index(uint8_t spd[], unsigned int spd_index)
Definition: spd.c:74
static void mainboard_print_spd_info(uint8_t spd[])
Definition: spd.c:24
#define SPD_PART_OFF
Definition: spd.c:19
void mainboard_fill_spd_data(struct pei_data *pei_data)
Definition: spd.c:102
#define SPD_DRAM_DDR3
Definition: spd.c:13
bool variant_is_dual_channel(const unsigned int spd_index)
Definition: spd.c:22
unsigned int variant_get_spd_index(void)
Definition: spd.c:11
static const int spd_index[32]
Definition: memory.c:10
unsigned char uint8_t
Definition: stdint.h:8
int dimm_channel1_disabled
Definition: pei_data.h:69
uint8_t spd_data[4][SPD_LEN]
Definition: pei_data.h:85