blob: 738c05b113794f310a269af3e0c244cfb7eefb2f [file] [log] [blame]
Patrick Rudolphff251d22021-02-11 15:09:22 +01001/* SPDX-License-Identifier: GPL-2.0-or-later */
2
Elyes Haouas5a047462022-12-28 11:43:49 +01003#include <device/dram/ddr2.h>
Patrick Rudolphff251d22021-02-11 15:09:22 +01004#include <device/dram/spd.h>
Subrata Banik6de8b422021-10-26 20:46:21 +05305#include <spd.h>
Elyes Haouas04c3b5a2022-10-07 10:08:05 +02006#include <stddef.h>
Patrick Rudolphff251d22021-02-11 15:09:22 +01007
8const char *spd_manufacturer_name(const uint16_t mod_id)
9{
10 switch (mod_id) {
11 case 0x9b85:
12 return "Crucial";
13 case 0x4304:
14 return "Ramaxel";
15 case 0x4f01:
16 return "Transcend";
17 case 0x9801:
18 return "Kingston";
19 case 0x987f:
JingleHsuWiwynn5f08ef92021-09-16 13:43:34 +080020 case 0xad00:
Patrick Rudolphff251d22021-02-11 15:09:22 +010021 return "Hynix";
22 case 0x9e02:
23 return "Corsair";
24 case 0xb004:
25 return "OCZ";
26 case 0xad80:
27 return "Hynix/Hyundai";
28 case 0x3486:
29 return "Super Talent";
30 case 0xcd04:
31 return "GSkill";
32 case 0xce80:
JingleHsuWiwynn5f08ef92021-09-16 13:43:34 +080033 case 0xce00:
Patrick Rudolphff251d22021-02-11 15:09:22 +010034 return "Samsung";
35 case 0xfe02:
36 return "Elpida";
37 case 0x2c80:
JingleHsuWiwynn5f08ef92021-09-16 13:43:34 +080038 case 0x2c00:
Patrick Rudolphff251d22021-02-11 15:09:22 +010039 return "Micron";
40 default:
41 return NULL;
42 }
43}
Subrata Banik6de8b422021-10-26 20:46:21 +053044
45static void convert_default_module_type_to_spd_info(struct spd_info *info)
46{
47 info->form_factor = MEMORY_FORMFACTOR_UNKNOWN;
48 info->type_detail = MEMORY_TYPE_DETAIL_UNKNOWN;
49}
50
Elyes Haouas5a047462022-12-28 11:43:49 +010051static void convert_ddr2_module_type_to_spd_info(enum spd_dimm_type_ddr2 module_type,
Elyes Haouasc705ecd2022-05-29 14:58:00 +020052 struct spd_info *info)
Subrata Banik6de8b422021-10-26 20:46:21 +053053{
54 switch (module_type) {
Elyes Haouas5a047462022-12-28 11:43:49 +010055 case SPD_DDR2_DIMM_TYPE_RDIMM:
56 case SPD_DDR2_DIMM_TYPE_MINI_RDIMM:
Subrata Banik6de8b422021-10-26 20:46:21 +053057 info->form_factor = MEMORY_FORMFACTOR_RIMM;
58 info->type_detail = MEMORY_TYPE_DETAIL_REGISTERED;
59 break;
Elyes Haouas5a047462022-12-28 11:43:49 +010060 case SPD_DDR2_DIMM_TYPE_UDIMM:
61 case SPD_DDR2_DIMM_TYPE_MINI_UDIMM:
Subrata Banik6de8b422021-10-26 20:46:21 +053062 info->form_factor = MEMORY_FORMFACTOR_DIMM;
63 info->type_detail = MEMORY_TYPE_DETAIL_UNBUFFERED;
64 break;
Elyes Haouas5a047462022-12-28 11:43:49 +010065 case SPD_DDR2_DIMM_TYPE_MICRO_DIMM:
Subrata Banik6de8b422021-10-26 20:46:21 +053066 info->form_factor = MEMORY_FORMFACTOR_DIMM;
67 info->type_detail = MEMORY_TYPE_DETAIL_UNKNOWN;
68 break;
Elyes Haouas5a047462022-12-28 11:43:49 +010069 case SPD_DDR2_DIMM_TYPE_SO_DIMM:
Subrata Banik6de8b422021-10-26 20:46:21 +053070 info->form_factor = MEMORY_FORMFACTOR_SODIMM;
71 info->type_detail = MEMORY_TYPE_DETAIL_UNKNOWN;
72 break;
73 default:
74 convert_default_module_type_to_spd_info(info);
75 break;
76 }
77}
78
79static void convert_ddr3_module_type_to_spd_info(enum ddr3_module_type module_type,
Elyes Haouasc705ecd2022-05-29 14:58:00 +020080 struct spd_info *info)
Subrata Banik6de8b422021-10-26 20:46:21 +053081{
82 switch (module_type) {
83 case DDR3_SPD_RDIMM:
84 case DDR3_SPD_MINI_RDIMM:
85 info->form_factor = MEMORY_FORMFACTOR_RIMM;
86 info->type_detail = MEMORY_TYPE_DETAIL_REGISTERED;
87 break;
88 case DDR3_SPD_UDIMM:
89 case DDR3_SPD_MINI_UDIMM:
90 info->form_factor = MEMORY_FORMFACTOR_DIMM;
91 info->type_detail = MEMORY_TYPE_DETAIL_UNBUFFERED;
92 break;
93 case DDR3_SPD_MICRO_DIMM:
94 info->form_factor = MEMORY_FORMFACTOR_DIMM;
95 info->type_detail = MEMORY_TYPE_DETAIL_UNKNOWN;
96 break;
97 case DDR3_SPD_SODIMM:
98 case DDR3_SPD_72B_SO_UDIMM:
99 info->form_factor = MEMORY_FORMFACTOR_SODIMM;
100 info->type_detail = MEMORY_TYPE_DETAIL_UNKNOWN;
101 break;
102 default:
103 convert_default_module_type_to_spd_info(info);
104 break;
105 }
106}
107
108static void convert_ddr4_module_type_to_spd_info(enum ddr4_module_type module_type,
Elyes Haouasc705ecd2022-05-29 14:58:00 +0200109 struct spd_info *info)
Subrata Banik6de8b422021-10-26 20:46:21 +0530110{
111 switch (module_type) {
112 case DDR4_SPD_RDIMM:
113 case DDR4_SPD_MINI_RDIMM:
114 info->form_factor = MEMORY_FORMFACTOR_RIMM;
115 info->type_detail = MEMORY_TYPE_DETAIL_REGISTERED;
116 break;
117 case DDR4_SPD_UDIMM:
118 case DDR4_SPD_MINI_UDIMM:
119 info->form_factor = MEMORY_FORMFACTOR_DIMM;
120 info->type_detail = MEMORY_TYPE_DETAIL_UNBUFFERED;
121 break;
122 case DDR4_SPD_SODIMM:
123 case DDR4_SPD_72B_SO_UDIMM:
124 info->form_factor = MEMORY_FORMFACTOR_SODIMM;
125 info->type_detail = MEMORY_TYPE_DETAIL_UNKNOWN;
126 break;
127 default:
128 convert_default_module_type_to_spd_info(info);
129 break;
130 }
131}
132
133static void convert_ddr5_module_type_to_spd_info(enum ddr5_module_type module_type,
Elyes Haouasc705ecd2022-05-29 14:58:00 +0200134 struct spd_info *info)
Subrata Banik6de8b422021-10-26 20:46:21 +0530135{
136 switch (module_type) {
137 case DDR5_SPD_RDIMM:
138 case DDR5_SPD_MINI_RDIMM:
139 info->form_factor = MEMORY_FORMFACTOR_RIMM;
140 info->type_detail = MEMORY_TYPE_DETAIL_REGISTERED;
141 break;
142 case DDR5_SPD_UDIMM:
143 case DDR5_SPD_MINI_UDIMM:
144 info->form_factor = MEMORY_FORMFACTOR_DIMM;
145 info->type_detail = MEMORY_TYPE_DETAIL_UNBUFFERED;
146 break;
147 case DDR5_SPD_SODIMM:
148 case DDR5_SPD_72B_SO_UDIMM:
149 info->form_factor = MEMORY_FORMFACTOR_SODIMM;
150 info->type_detail = MEMORY_TYPE_DETAIL_UNKNOWN;
151 break;
152 case DDR5_SPD_2DPC:
153 info->form_factor = MEMORY_FORMFACTOR_PROPRIETARY_CARD;
154 info->type_detail = MEMORY_TYPE_DETAIL_UNKNOWN;
155 break;
156 default:
157 convert_default_module_type_to_spd_info(info);
158 break;
159 }
160}
161
162static void convert_lpx_module_type_to_spd_info(enum lpx_module_type module_type,
Elyes Haouasc705ecd2022-05-29 14:58:00 +0200163 struct spd_info *info)
Subrata Banik6de8b422021-10-26 20:46:21 +0530164{
165 switch (module_type) {
166 case LPX_SPD_NONDIMM:
167 info->form_factor = MEMORY_FORMFACTOR_ROC;
168 info->type_detail = MEMORY_TYPE_DETAIL_UNKNOWN;
169 break;
170 default:
171 convert_default_module_type_to_spd_info(info);
172 break;
173 }
174}
175
176void get_spd_info(smbios_memory_type memory_type, uint8_t module_type, struct spd_info *info)
177{
178 switch (memory_type) {
179 case MEMORY_TYPE_DDR2:
180 convert_ddr2_module_type_to_spd_info(module_type, info);
181 break;
182 case MEMORY_TYPE_DDR3:
183 convert_ddr3_module_type_to_spd_info(module_type, info);
184 break;
185 case MEMORY_TYPE_DDR4:
186 convert_ddr4_module_type_to_spd_info(module_type, info);
187 break;
188 case MEMORY_TYPE_DDR5:
189 convert_ddr5_module_type_to_spd_info(module_type, info);
190 break;
191 case MEMORY_TYPE_LPDDR3:
192 case MEMORY_TYPE_LPDDR4:
193 case MEMORY_TYPE_LPDDR5:
194 convert_lpx_module_type_to_spd_info(module_type, info);
195 break;
196 default:
197 convert_default_module_type_to_spd_info(info);
198 break;
199 }
200}
201
202static uint8_t convert_default_form_factor_to_module_type(void)
203{
204 return SPD_UNDEFINED;
205}
206
207static uint8_t convert_ddrx_form_factor_to_module_type(smbios_memory_type memory_type,
Elyes Haouasc705ecd2022-05-29 14:58:00 +0200208 smbios_memory_form_factor form_factor)
Subrata Banik6de8b422021-10-26 20:46:21 +0530209{
210 uint8_t module_type;
211
212 switch (form_factor) {
213 case MEMORY_FORMFACTOR_DIMM:
Elyes Haouas5a047462022-12-28 11:43:49 +0100214 return SPD_DDR2_DIMM_TYPE_UDIMM;
Subrata Banik6de8b422021-10-26 20:46:21 +0530215 case MEMORY_FORMFACTOR_RIMM:
Elyes Haouas5a047462022-12-28 11:43:49 +0100216 return SPD_DDR2_DIMM_TYPE_RDIMM;
Subrata Banik6de8b422021-10-26 20:46:21 +0530217 case MEMORY_FORMFACTOR_SODIMM:
Elyes Haouas5a047462022-12-28 11:43:49 +0100218 module_type = (memory_type == MEMORY_TYPE_DDR2) ? SPD_DDR2_DIMM_TYPE_SO_DIMM :
Elyes Haouasc705ecd2022-05-29 14:58:00 +0200219 DDR3_SPD_SODIMM;
Subrata Banik6de8b422021-10-26 20:46:21 +0530220 return module_type;
221 default:
222 return convert_default_form_factor_to_module_type();
223 }
224}
225
226static uint8_t convert_lpx_form_factor_to_module_type(smbios_memory_form_factor form_factor)
227{
228 switch (form_factor) {
229 case MEMORY_FORMFACTOR_ROC:
230 return LPX_SPD_NONDIMM;
231 default:
232 return convert_default_form_factor_to_module_type();
233 }
234}
235
236uint8_t convert_form_factor_to_module_type(smbios_memory_type memory_type,
Elyes Haouasc705ecd2022-05-29 14:58:00 +0200237 smbios_memory_form_factor form_factor)
Subrata Banik6de8b422021-10-26 20:46:21 +0530238{
239 uint8_t module_type;
240
241 switch (memory_type) {
242 case MEMORY_TYPE_DDR2:
243 case MEMORY_TYPE_DDR3:
244 case MEMORY_TYPE_DDR4:
245 case MEMORY_TYPE_DDR5:
246 module_type = convert_ddrx_form_factor_to_module_type(memory_type, form_factor);
247 break;
248 case MEMORY_TYPE_LPDDR3:
249 case MEMORY_TYPE_LPDDR4:
250 case MEMORY_TYPE_LPDDR5:
251 module_type = convert_lpx_form_factor_to_module_type(form_factor);
252 break;
253 default:
254 module_type = convert_default_form_factor_to_module_type();
255 break;
256 }
257
258 return module_type;
259}