Angel Pons | 0612b27 | 2020-04-05 15:46:56 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Barnali Sarkar | e13b775 | 2017-02-21 16:24:49 +0530 | [diff] [blame] | 2 | |
| 3 | #include <smbios.h> |
| 4 | #include "smbios.h" |
| 5 | #include <string.h> |
Elyes HAOUAS | f97c1c9 | 2019-12-03 18:22:06 +0100 | [diff] [blame] | 6 | #include <commonlib/helpers.h> |
Barnali Sarkar | e13b775 | 2017-02-21 16:24:49 +0530 | [diff] [blame] | 7 | #include <console/console.h> |
Duncan Laurie | 1a86cda | 2019-06-10 14:00:56 -0700 | [diff] [blame] | 8 | #include <device/dram/ddr3.h> |
Subrata Banik | 3afa467 | 2021-10-27 20:53:49 +0530 | [diff] [blame] | 9 | #include <dimm_info_util.h> |
| 10 | |
| 11 | #define EXTENSION_BUS_WIDTH_8BITS 8 |
Barnali Sarkar | e13b775 | 2017-02-21 16:24:49 +0530 | [diff] [blame] | 12 | |
| 13 | /* Fill the SMBIOS memory information from FSP MEM_INFO_DATA_HOB in CBMEM.*/ |
| 14 | void dimm_info_fill(struct dimm_info *dimm, u32 dimm_capacity, u8 ddr_type, |
Francois Toguo | 993f68a | 2019-02-04 17:05:51 -0800 | [diff] [blame] | 15 | u32 frequency, u8 rank_per_dimm, u8 channel_id, u8 dimm_id, |
Barnali Sarkar | 6497cd9 | 2017-03-07 17:11:03 +0530 | [diff] [blame] | 16 | const char *module_part_num, size_t module_part_number_size, |
Christian Walter | f972322 | 2019-05-28 10:37:24 +0200 | [diff] [blame] | 17 | const u8 *module_serial_num, u16 data_width, u32 vdd_voltage, |
Duncan Laurie | 1a86cda | 2019-06-10 14:00:56 -0700 | [diff] [blame] | 18 | bool ecc_support, u16 mod_id, u8 mod_type) |
Barnali Sarkar | e13b775 | 2017-02-21 16:24:49 +0530 | [diff] [blame] | 19 | { |
Duncan Laurie | 1a86cda | 2019-06-10 14:00:56 -0700 | [diff] [blame] | 20 | dimm->mod_id = mod_id; |
| 21 | /* Translate to DDR2 module type field that SMBIOS code expects. */ |
| 22 | switch (mod_type) { |
Angel Pons | 1857138 | 2021-03-28 13:49:39 +0200 | [diff] [blame] | 23 | case SPD_DDR3_DIMM_TYPE_SO_DIMM: |
Duncan Laurie | 1a86cda | 2019-06-10 14:00:56 -0700 | [diff] [blame] | 24 | dimm->mod_type = SPD_SODIMM; |
| 25 | break; |
Angel Pons | 1857138 | 2021-03-28 13:49:39 +0200 | [diff] [blame] | 26 | case SPD_DDR3_DIMM_TYPE_72B_SO_CDIMM: |
Duncan Laurie | 1a86cda | 2019-06-10 14:00:56 -0700 | [diff] [blame] | 27 | dimm->mod_type = SPD_72B_SO_CDIMM; |
| 28 | break; |
Angel Pons | 1857138 | 2021-03-28 13:49:39 +0200 | [diff] [blame] | 29 | case SPD_DDR3_DIMM_TYPE_72B_SO_RDIMM: |
Duncan Laurie | 1a86cda | 2019-06-10 14:00:56 -0700 | [diff] [blame] | 30 | dimm->mod_type = SPD_72B_SO_RDIMM; |
| 31 | break; |
Angel Pons | 1857138 | 2021-03-28 13:49:39 +0200 | [diff] [blame] | 32 | case SPD_DDR3_DIMM_TYPE_UDIMM: |
Duncan Laurie | 1a86cda | 2019-06-10 14:00:56 -0700 | [diff] [blame] | 33 | dimm->mod_type = SPD_UDIMM; |
| 34 | break; |
Angel Pons | 1857138 | 2021-03-28 13:49:39 +0200 | [diff] [blame] | 35 | case SPD_DDR3_DIMM_TYPE_RDIMM: |
Duncan Laurie | 1a86cda | 2019-06-10 14:00:56 -0700 | [diff] [blame] | 36 | dimm->mod_type = SPD_RDIMM; |
| 37 | break; |
Angel Pons | 1857138 | 2021-03-28 13:49:39 +0200 | [diff] [blame] | 38 | case SPD_DDR3_DIMM_TYPE_UNDEFINED: |
Duncan Laurie | 1a86cda | 2019-06-10 14:00:56 -0700 | [diff] [blame] | 39 | default: |
| 40 | dimm->mod_type = SPD_UNDEFINED; |
| 41 | break; |
| 42 | } |
Barnali Sarkar | e13b775 | 2017-02-21 16:24:49 +0530 | [diff] [blame] | 43 | dimm->dimm_size = dimm_capacity; |
| 44 | dimm->ddr_type = ddr_type; |
| 45 | dimm->ddr_frequency = frequency; |
Francois Toguo | 993f68a | 2019-02-04 17:05:51 -0800 | [diff] [blame] | 46 | dimm->rank_per_dimm = rank_per_dimm; |
Barnali Sarkar | e13b775 | 2017-02-21 16:24:49 +0530 | [diff] [blame] | 47 | dimm->channel_num = channel_id; |
| 48 | dimm->dimm_num = dimm_id; |
Christian Walter | f972322 | 2019-05-28 10:37:24 +0200 | [diff] [blame] | 49 | if (vdd_voltage > 0xFFFF) { |
| 50 | dimm->vdd_voltage = 0xFFFF; |
| 51 | } else { |
| 52 | dimm->vdd_voltage = vdd_voltage; |
| 53 | } |
| 54 | |
Barnali Sarkar | e13b775 | 2017-02-21 16:24:49 +0530 | [diff] [blame] | 55 | strncpy((char *)dimm->module_part_number, |
| 56 | module_part_num, |
Elyes HAOUAS | f97c1c9 | 2019-12-03 18:22:06 +0100 | [diff] [blame] | 57 | MIN(sizeof(dimm->module_part_number), |
Barnali Sarkar | 6497cd9 | 2017-03-07 17:11:03 +0530 | [diff] [blame] | 58 | module_part_number_size)); |
Duncan Laurie | 46340d0 | 2019-05-17 14:57:31 -0600 | [diff] [blame] | 59 | if (module_serial_num) |
| 60 | memcpy(dimm->serial, module_serial_num, |
| 61 | DIMM_INFO_SERIAL_SIZE); |
Subrata Banik | 3afa467 | 2021-10-27 20:53:49 +0530 | [diff] [blame] | 62 | |
| 63 | uint16_t total_width = data_width; |
Christian Walter | f972322 | 2019-05-28 10:37:24 +0200 | [diff] [blame] | 64 | |
| 65 | if (ecc_support) |
Subrata Banik | 3afa467 | 2021-10-27 20:53:49 +0530 | [diff] [blame] | 66 | total_width += EXTENSION_BUS_WIDTH_8BITS; |
| 67 | |
Subrata Banik | 3306f37 | 2021-10-26 13:19:20 +0530 | [diff] [blame] | 68 | dimm->bus_width = smbios_bus_width_to_spd_width(ddr_type, total_width, data_width); |
Barnali Sarkar | e13b775 | 2017-02-21 16:24:49 +0530 | [diff] [blame] | 69 | } |