Debian Codegraph @

src/soc/intel/broadwell/spd.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <cbfs.h>
4 #include <console/console.h>
5 #include <device/dram/ddr3.h>
6 #include <soc/pei_data.h>
7 #include <soc/pei_wrapper.h>
8 #include <spd.h>
9 #include <string.h>
10 #include <types.h>
11
12 #define SPD_DENSITY_BANKS 4
13 #define SPD_ADDRESSING 5
14 #define SPD_ORGANIZATION 7
15 #define SPD_BUS_DEV_WIDTH 8
16
17 static void print_spd_info(uint8_t spd[])
18 {
19 const int spd_banks[8] = { 8, 16, 32, 64, -1, -1, -1, -1 };
20 const int spd_capmb[8] = { 1, 2, 4, 8, 16, 32, 64, 0 };
21 const int spd_rows[8] = { 12, 13, 14, 15, 16, -1, -1, -1 };
22 const int spd_cols[8] = { 9, 10, 11, 12, -1, -1, -1, -1 };
23 const int spd_ranks[8] = { 1, 2, 3, 4, -1, -1, -1, -1 };
24 const int spd_devw[8] = { 4, 8, 16, 32, -1, -1, -1, -1 };
25 const int spd_busw[8] = { 8, 16, 32, 64, -1, -1, -1, -1 };
26 char spd_name[SPD_DDR3_PART_LEN + 1] = { 0 };
27
28 int banks = spd_banks[(spd[SPD_DENSITY_BANKS] >> 4) & 7];
29 int capmb = spd_capmb[spd[SPD_DENSITY_BANKS] & 7] * 256;
30 int rows = spd_rows[(spd[SPD_ADDRESSING] >> 3) & 7];
31 int cols = spd_cols[spd[SPD_ADDRESSING] & 7];
32 int ranks = spd_ranks[(spd[SPD_ORGANIZATION] >> 3) & 7];
33 int devw = spd_devw[spd[SPD_ORGANIZATION] & 7];
34 int busw = spd_busw[spd[SPD_BUS_DEV_WIDTH] & 7];
35
36 /* Module type */
37 printk(BIOS_INFO, "SPD: module type is ");
38 switch (spd[SPD_MEMORY_TYPE]) {
39 case SPD_MEMORY_TYPE_SDRAM_DDR3:
40 printk(BIOS_INFO, "DDR3\n");
41 break;
42 case SPD_MEMORY_TYPE_LPDDR3_INTEL:
43 printk(BIOS_INFO, "LPDDR3\n");
44 break;
45 default:
46 printk(BIOS_INFO, "Unknown (%02x)\n", spd[SPD_MEMORY_TYPE]);
47 break;
48 }
49
50 /* Module Part Number */
51 memcpy(spd_name, &spd[SPD_DDR3_PART_NUM], SPD_DDR3_PART_LEN);
52 spd_name[SPD_DDR3_PART_LEN] = 0;
53 printk(BIOS_INFO, "SPD: module part is %s\n", spd_name);
54
55 printk(BIOS_INFO, "SPD: banks %d, ranks %d, rows %d, columns %d, "
56 "density %d Mb\n", banks, ranks, rows, cols, capmb);
57 printk(BIOS_INFO, "SPD: device width %d bits, bus width %d bits\n",
58 devw, busw);
59
60 if (capmb > 0 && busw > 0 && devw > 0 && ranks > 0) {
61 /* SIZE = DENSITY / 8 * BUS_WIDTH / SDRAM_WIDTH * RANKS */
62 printk(BIOS_INFO, "SPD: module size is %u MB (per channel)\n",
63 capmb / 8 * busw / devw * ranks);
64 }
65 }
66
67 void copy_spd(struct pei_data *pei_data, struct spd_info *spdi)
68 {
69 size_t spd_file_len;
70 uint8_t *spd_file = cbfs_map("spd.bin", &spd_file_len);
71
72 printk(BIOS_DEBUG, "SPD index %d\n", spdi->spd_index);
73
74 if (!spd_file)
75 die("SPD data not found.");
76
77 if (spd_file_len < SPD_SIZE_MAX_DDR3)
78 die("Missing SPD data.");
79
80 if (spd_file_len < ((spdi->spd_index + 1) * SPD_SIZE_MAX_DDR3)) {
81 printk(BIOS_ERR, "SPD index override to 0 - old hardware?\n");
82 spdi->spd_index = 0;
83 }
84
85 uint8_t *const spd = spd_file + (spdi->spd_index * SPD_SIZE_MAX_DDR3);
86
87 /* Make sure a valid SPD was found */
88 if (spd[0] == 0)
89 die("Invalid SPD data.");
90
91 print_spd_info(spd);
92
93 for (size_t i = 0; i < ARRAY_SIZE(spdi->addresses); i++) {
94 if (spdi->addresses[i] == SPD_MEMORY_DOWN)
95 memcpy(pei_data->spd_data[i / 2][i % 2], spd, SPD_SIZE_MAX_DDR3);
96 }
97 }