blob: 11808e2cf30b2082f7542de7c2c23246e18b5b5e [file] [log] [blame]
Patrick Rudolphff251d22021-02-11 15:09:22 +01001/* SPDX-License-Identifier: GPL-2.0-or-later */
2
3#include <device/dram/spd.h>
Subrata Banik6de8b422021-10-26 20:46:21 +05304#include <spd.h>
Patrick Rudolphff251d22021-02-11 15:09:22 +01005
6const char *spd_manufacturer_name(const uint16_t mod_id)
7{
8 switch (mod_id) {
9 case 0x9b85:
10 return "Crucial";
11 case 0x4304:
12 return "Ramaxel";
13 case 0x4f01:
14 return "Transcend";
15 case 0x9801:
16 return "Kingston";
17 case 0x987f:
JingleHsuWiwynn5f08ef92021-09-16 13:43:34 +080018 case 0xad00:
Patrick Rudolphff251d22021-02-11 15:09:22 +010019 return "Hynix";
20 case 0x9e02:
21 return "Corsair";
22 case 0xb004:
23 return "OCZ";
24 case 0xad80:
25 return "Hynix/Hyundai";
26 case 0x3486:
27 return "Super Talent";
28 case 0xcd04:
29 return "GSkill";
30 case 0xce80:
JingleHsuWiwynn5f08ef92021-09-16 13:43:34 +080031 case 0xce00:
Patrick Rudolphff251d22021-02-11 15:09:22 +010032 return "Samsung";
33 case 0xfe02:
34 return "Elpida";
35 case 0x2c80:
JingleHsuWiwynn5f08ef92021-09-16 13:43:34 +080036 case 0x2c00:
Patrick Rudolphff251d22021-02-11 15:09:22 +010037 return "Micron";
38 default:
39 return NULL;
40 }
41}
Subrata Banik6de8b422021-10-26 20:46:21 +053042
43static void convert_default_module_type_to_spd_info(struct spd_info *info)
44{
45 info->form_factor = MEMORY_FORMFACTOR_UNKNOWN;
46 info->type_detail = MEMORY_TYPE_DETAIL_UNKNOWN;
47}
48
49static void convert_ddr2_module_type_to_spd_info(enum ddr2_module_type module_type,
50 struct spd_info *info)
51{
52 switch (module_type) {
53 case DDR2_SPD_RDIMM:
54 case DDR2_SPD_MINI_RDIMM:
55 info->form_factor = MEMORY_FORMFACTOR_RIMM;
56 info->type_detail = MEMORY_TYPE_DETAIL_REGISTERED;
57 break;
58 case DDR2_SPD_UDIMM:
59 case DDR2_SPD_MINI_UDIMM:
60 info->form_factor = MEMORY_FORMFACTOR_DIMM;
61 info->type_detail = MEMORY_TYPE_DETAIL_UNBUFFERED;
62 break;
63 case DDR2_SPD_MICRO_DIMM:
64 info->form_factor = MEMORY_FORMFACTOR_DIMM;
65 info->type_detail = MEMORY_TYPE_DETAIL_UNKNOWN;
66 break;
67 case DDR2_SPD_SODIMM:
68 info->form_factor = MEMORY_FORMFACTOR_SODIMM;
69 info->type_detail = MEMORY_TYPE_DETAIL_UNKNOWN;
70 break;
71 default:
72 convert_default_module_type_to_spd_info(info);
73 break;
74 }
75}
76
77static void convert_ddr3_module_type_to_spd_info(enum ddr3_module_type module_type,
78 struct spd_info *info)
79{
80 switch (module_type) {
81 case DDR3_SPD_RDIMM:
82 case DDR3_SPD_MINI_RDIMM:
83 info->form_factor = MEMORY_FORMFACTOR_RIMM;
84 info->type_detail = MEMORY_TYPE_DETAIL_REGISTERED;
85 break;
86 case DDR3_SPD_UDIMM:
87 case DDR3_SPD_MINI_UDIMM:
88 info->form_factor = MEMORY_FORMFACTOR_DIMM;
89 info->type_detail = MEMORY_TYPE_DETAIL_UNBUFFERED;
90 break;
91 case DDR3_SPD_MICRO_DIMM:
92 info->form_factor = MEMORY_FORMFACTOR_DIMM;
93 info->type_detail = MEMORY_TYPE_DETAIL_UNKNOWN;
94 break;
95 case DDR3_SPD_SODIMM:
96 case DDR3_SPD_72B_SO_UDIMM:
97 info->form_factor = MEMORY_FORMFACTOR_SODIMM;
98 info->type_detail = MEMORY_TYPE_DETAIL_UNKNOWN;
99 break;
100 default:
101 convert_default_module_type_to_spd_info(info);
102 break;
103 }
104}
105
106static void convert_ddr4_module_type_to_spd_info(enum ddr4_module_type module_type,
107 struct spd_info *info)
108{
109 switch (module_type) {
110 case DDR4_SPD_RDIMM:
111 case DDR4_SPD_MINI_RDIMM:
112 info->form_factor = MEMORY_FORMFACTOR_RIMM;
113 info->type_detail = MEMORY_TYPE_DETAIL_REGISTERED;
114 break;
115 case DDR4_SPD_UDIMM:
116 case DDR4_SPD_MINI_UDIMM:
117 info->form_factor = MEMORY_FORMFACTOR_DIMM;
118 info->type_detail = MEMORY_TYPE_DETAIL_UNBUFFERED;
119 break;
120 case DDR4_SPD_SODIMM:
121 case DDR4_SPD_72B_SO_UDIMM:
122 info->form_factor = MEMORY_FORMFACTOR_SODIMM;
123 info->type_detail = MEMORY_TYPE_DETAIL_UNKNOWN;
124 break;
125 default:
126 convert_default_module_type_to_spd_info(info);
127 break;
128 }
129}
130
131static void convert_ddr5_module_type_to_spd_info(enum ddr5_module_type module_type,
132 struct spd_info *info)
133{
134 switch (module_type) {
135 case DDR5_SPD_RDIMM:
136 case DDR5_SPD_MINI_RDIMM:
137 info->form_factor = MEMORY_FORMFACTOR_RIMM;
138 info->type_detail = MEMORY_TYPE_DETAIL_REGISTERED;
139 break;
140 case DDR5_SPD_UDIMM:
141 case DDR5_SPD_MINI_UDIMM:
142 info->form_factor = MEMORY_FORMFACTOR_DIMM;
143 info->type_detail = MEMORY_TYPE_DETAIL_UNBUFFERED;
144 break;
145 case DDR5_SPD_SODIMM:
146 case DDR5_SPD_72B_SO_UDIMM:
147 info->form_factor = MEMORY_FORMFACTOR_SODIMM;
148 info->type_detail = MEMORY_TYPE_DETAIL_UNKNOWN;
149 break;
150 case DDR5_SPD_2DPC:
151 info->form_factor = MEMORY_FORMFACTOR_PROPRIETARY_CARD;
152 info->type_detail = MEMORY_TYPE_DETAIL_UNKNOWN;
153 break;
154 default:
155 convert_default_module_type_to_spd_info(info);
156 break;
157 }
158}
159
160static void convert_lpx_module_type_to_spd_info(enum lpx_module_type module_type,
161 struct spd_info *info)
162{
163 switch (module_type) {
164 case LPX_SPD_NONDIMM:
165 info->form_factor = MEMORY_FORMFACTOR_ROC;
166 info->type_detail = MEMORY_TYPE_DETAIL_UNKNOWN;
167 break;
168 default:
169 convert_default_module_type_to_spd_info(info);
170 break;
171 }
172}
173
174void get_spd_info(smbios_memory_type memory_type, uint8_t module_type, struct spd_info *info)
175{
176 switch (memory_type) {
177 case MEMORY_TYPE_DDR2:
178 convert_ddr2_module_type_to_spd_info(module_type, info);
179 break;
180 case MEMORY_TYPE_DDR3:
181 convert_ddr3_module_type_to_spd_info(module_type, info);
182 break;
183 case MEMORY_TYPE_DDR4:
184 convert_ddr4_module_type_to_spd_info(module_type, info);
185 break;
186 case MEMORY_TYPE_DDR5:
187 convert_ddr5_module_type_to_spd_info(module_type, info);
188 break;
189 case MEMORY_TYPE_LPDDR3:
190 case MEMORY_TYPE_LPDDR4:
191 case MEMORY_TYPE_LPDDR5:
192 convert_lpx_module_type_to_spd_info(module_type, info);
193 break;
194 default:
195 convert_default_module_type_to_spd_info(info);
196 break;
197 }
198}
199
200static uint8_t convert_default_form_factor_to_module_type(void)
201{
202 return SPD_UNDEFINED;
203}
204
205static uint8_t convert_ddrx_form_factor_to_module_type(smbios_memory_type memory_type,
206 smbios_memory_form_factor form_factor)
207{
208 uint8_t module_type;
209
210 switch (form_factor) {
211 case MEMORY_FORMFACTOR_DIMM:
212 return DDR2_SPD_UDIMM;
213 case MEMORY_FORMFACTOR_RIMM:
214 return DDR2_SPD_RDIMM;
215 case MEMORY_FORMFACTOR_SODIMM:
216 module_type = (memory_type == MEMORY_TYPE_DDR2) ? DDR2_SPD_SODIMM
217 : DDR3_SPD_SODIMM;
218 return module_type;
219 default:
220 return convert_default_form_factor_to_module_type();
221 }
222}
223
224static uint8_t convert_lpx_form_factor_to_module_type(smbios_memory_form_factor form_factor)
225{
226 switch (form_factor) {
227 case MEMORY_FORMFACTOR_ROC:
228 return LPX_SPD_NONDIMM;
229 default:
230 return convert_default_form_factor_to_module_type();
231 }
232}
233
234uint8_t convert_form_factor_to_module_type(smbios_memory_type memory_type,
235 smbios_memory_form_factor form_factor)
236{
237 uint8_t module_type;
238
239 switch (memory_type) {
240 case MEMORY_TYPE_DDR2:
241 case MEMORY_TYPE_DDR3:
242 case MEMORY_TYPE_DDR4:
243 case MEMORY_TYPE_DDR5:
244 module_type = convert_ddrx_form_factor_to_module_type(memory_type, form_factor);
245 break;
246 case MEMORY_TYPE_LPDDR3:
247 case MEMORY_TYPE_LPDDR4:
248 case MEMORY_TYPE_LPDDR5:
249 module_type = convert_lpx_form_factor_to_module_type(form_factor);
250 break;
251 default:
252 module_type = convert_default_form_factor_to_module_type();
253 break;
254 }
255
256 return module_type;
257}