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> |
Duncan Laurie | 1a86cda | 2019-06-10 14:00:56 -0700 | [diff] [blame] | 7 | #include <device/dram/ddr3.h> |
Subrata Banik | 3afa467 | 2021-10-27 20:53:49 +0530 | [diff] [blame] | 8 | #include <dimm_info_util.h> |
| 9 | |
| 10 | #define EXTENSION_BUS_WIDTH_8BITS 8 |
Barnali Sarkar | e13b775 | 2017-02-21 16:24:49 +0530 | [diff] [blame] | 11 | |
| 12 | /* Fill the SMBIOS memory information from FSP MEM_INFO_DATA_HOB in CBMEM.*/ |
| 13 | 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] | 14 | u32 frequency, u8 rank_per_dimm, u8 channel_id, u8 dimm_id, |
Barnali Sarkar | 6497cd9 | 2017-03-07 17:11:03 +0530 | [diff] [blame] | 15 | const char *module_part_num, size_t module_part_number_size, |
Christian Walter | f972322 | 2019-05-28 10:37:24 +0200 | [diff] [blame] | 16 | const u8 *module_serial_num, u16 data_width, u32 vdd_voltage, |
Eric Lai | b15946d | 2023-06-13 10:21:58 +0800 | [diff] [blame] | 17 | bool ecc_support, u16 mod_id, u8 mod_type, u8 ctrlr_id, |
| 18 | u32 max_frequency) |
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; |
Subrata Banik | 6de8b42 | 2021-10-26 20:46:21 +0530 | [diff] [blame] | 21 | dimm->mod_type = mod_type; |
Barnali Sarkar | e13b775 | 2017-02-21 16:24:49 +0530 | [diff] [blame] | 22 | dimm->dimm_size = dimm_capacity; |
| 23 | dimm->ddr_type = ddr_type; |
Eric Lai | b15946d | 2023-06-13 10:21:58 +0800 | [diff] [blame] | 24 | /* keep ddr_frequency for backward compatible */ |
Barnali Sarkar | e13b775 | 2017-02-21 16:24:49 +0530 | [diff] [blame] | 25 | dimm->ddr_frequency = frequency; |
Eric Lai | b15946d | 2023-06-13 10:21:58 +0800 | [diff] [blame] | 26 | dimm->configured_speed_mts = frequency; |
| 27 | dimm->max_speed_mts = max_frequency; |
Francois Toguo | 993f68a | 2019-02-04 17:05:51 -0800 | [diff] [blame] | 28 | dimm->rank_per_dimm = rank_per_dimm; |
Barnali Sarkar | e13b775 | 2017-02-21 16:24:49 +0530 | [diff] [blame] | 29 | dimm->channel_num = channel_id; |
| 30 | dimm->dimm_num = dimm_id; |
David Milosevic | 6be82a4 | 2022-10-18 19:17:19 +0200 | [diff] [blame] | 31 | dimm->ctrlr_num = ctrlr_id; |
| 32 | |
Christian Walter | f972322 | 2019-05-28 10:37:24 +0200 | [diff] [blame] | 33 | if (vdd_voltage > 0xFFFF) { |
| 34 | dimm->vdd_voltage = 0xFFFF; |
| 35 | } else { |
| 36 | dimm->vdd_voltage = vdd_voltage; |
| 37 | } |
| 38 | |
Barnali Sarkar | e13b775 | 2017-02-21 16:24:49 +0530 | [diff] [blame] | 39 | strncpy((char *)dimm->module_part_number, |
| 40 | module_part_num, |
Elyes HAOUAS | f97c1c9 | 2019-12-03 18:22:06 +0100 | [diff] [blame] | 41 | MIN(sizeof(dimm->module_part_number), |
Barnali Sarkar | 6497cd9 | 2017-03-07 17:11:03 +0530 | [diff] [blame] | 42 | module_part_number_size)); |
Duncan Laurie | 46340d0 | 2019-05-17 14:57:31 -0600 | [diff] [blame] | 43 | if (module_serial_num) |
| 44 | memcpy(dimm->serial, module_serial_num, |
| 45 | DIMM_INFO_SERIAL_SIZE); |
Subrata Banik | 3afa467 | 2021-10-27 20:53:49 +0530 | [diff] [blame] | 46 | |
| 47 | uint16_t total_width = data_width; |
Christian Walter | f972322 | 2019-05-28 10:37:24 +0200 | [diff] [blame] | 48 | |
| 49 | if (ecc_support) |
Subrata Banik | 3afa467 | 2021-10-27 20:53:49 +0530 | [diff] [blame] | 50 | total_width += EXTENSION_BUS_WIDTH_8BITS; |
| 51 | |
Subrata Banik | 3306f37 | 2021-10-26 13:19:20 +0530 | [diff] [blame] | 52 | 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] | 53 | } |