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