Angel Pons | 6bc1374 | 2020-04-05 15:46:38 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Ravi Sarawadi | 09195ac | 2017-07-20 15:11:19 -0700 | [diff] [blame] | 2 | |
| 3 | #include <cbmem.h> |
| 4 | #include <console/console.h> |
| 5 | #include <fsp/util.h> |
| 6 | #include <memory_info.h> |
| 7 | #include <soc/intel/common/smbios.h> |
| 8 | #include <soc/meminit.h> |
| 9 | #include <string.h> |
| 10 | |
Subrata Banik | 6ee716e | 2018-02-08 16:50:21 +0530 | [diff] [blame] | 11 | #define FSP_SMBIOS_MEMORY_INFO_GUID \ |
| 12 | { \ |
| 13 | 0x8c, 0x10, 0xa1, 0x01, 0xee, 0x9d, 0x84, 0x49, \ |
| 14 | 0x88, 0xc3, 0xee, 0xe8, 0xc4, 0x9e, 0xfb, 0x89 \ |
| 15 | } |
| 16 | |
Aaron Durbin | 9a30c72 | 2018-08-07 12:04:21 -0600 | [diff] [blame] | 17 | void save_lpddr4_dimm_info_part_num(const char *dram_part_num) |
Ravi Sarawadi | 09195ac | 2017-07-20 15:11:19 -0700 | [diff] [blame] | 18 | { |
| 19 | int channel, dimm, dimm_max, index; |
| 20 | size_t hob_size; |
| 21 | const DIMM_INFO *src_dimm; |
| 22 | struct dimm_info *dest_dimm; |
| 23 | struct memory_info *mem_info; |
| 24 | const CHANNEL_INFO *channel_info; |
| 25 | const FSP_SMBIOS_MEMORY_INFO *memory_info_hob; |
Subrata Banik | 6ee716e | 2018-02-08 16:50:21 +0530 | [diff] [blame] | 26 | const uint8_t smbios_memory_info_guid[16] = |
| 27 | FSP_SMBIOS_MEMORY_INFO_GUID; |
Ravi Sarawadi | 09195ac | 2017-07-20 15:11:19 -0700 | [diff] [blame] | 28 | |
Aaron Durbin | 9a30c72 | 2018-08-07 12:04:21 -0600 | [diff] [blame] | 29 | if (!dram_part_num) |
| 30 | dram_part_num = "Unknown"; |
Ravi Sarawadi | 09195ac | 2017-07-20 15:11:19 -0700 | [diff] [blame] | 31 | |
Subrata Banik | 6ee716e | 2018-02-08 16:50:21 +0530 | [diff] [blame] | 32 | /* Locate the memory info HOB */ |
| 33 | memory_info_hob = fsp_find_extension_hob_by_guid( |
| 34 | smbios_memory_info_guid, |
| 35 | &hob_size); |
| 36 | |
| 37 | if (memory_info_hob == NULL || hob_size == 0) { |
| 38 | printk(BIOS_ERR, "SMBIOS memory info HOB is missing\n"); |
| 39 | return; |
| 40 | } |
Ravi Sarawadi | 09195ac | 2017-07-20 15:11:19 -0700 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * Allocate CBMEM area for DIMM information used to populate SMBIOS |
| 44 | * table 17 |
| 45 | */ |
| 46 | mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(*mem_info)); |
| 47 | if (mem_info == NULL) { |
| 48 | printk(BIOS_ERR, "CBMEM entry for DIMM info missing\n"); |
| 49 | return; |
| 50 | } |
| 51 | memset(mem_info, 0, sizeof(*mem_info)); |
| 52 | |
| 53 | /* Describe the first N DIMMs in the system */ |
| 54 | index = 0; |
| 55 | dimm_max = ARRAY_SIZE(mem_info->dimm); |
| 56 | |
| 57 | for (channel = 0; channel < memory_info_hob->ChannelCount; channel++) { |
| 58 | if (index >= dimm_max) |
| 59 | break; |
| 60 | channel_info = &memory_info_hob->ChannelInfo[channel]; |
| 61 | for (dimm = 0; dimm < channel_info->DimmCount; dimm++) { |
| 62 | if (index >= dimm_max) |
| 63 | break; |
| 64 | src_dimm = &channel_info->DimmInfo[dimm]; |
| 65 | dest_dimm = &mem_info->dimm[index]; |
| 66 | |
| 67 | if (!src_dimm->SizeInMb) |
| 68 | continue; |
| 69 | |
| 70 | /* Populate the DIMM information */ |
| 71 | dimm_info_fill(dest_dimm, |
| 72 | src_dimm->SizeInMb, |
| 73 | memory_info_hob->MemoryType, |
| 74 | memory_info_hob->MemoryFrequencyInMHz, |
Francois Toguo | 993f68a | 2019-02-04 17:05:51 -0800 | [diff] [blame] | 75 | 0, |
Ravi Sarawadi | 09195ac | 2017-07-20 15:11:19 -0700 | [diff] [blame] | 76 | channel_info->ChannelId, |
| 77 | src_dimm->DimmId, |
Aaron Durbin | 9a30c72 | 2018-08-07 12:04:21 -0600 | [diff] [blame] | 78 | dram_part_num, |
| 79 | strlen(dram_part_num), |
Duncan Laurie | 46340d0 | 2019-05-17 14:57:31 -0600 | [diff] [blame] | 80 | NULL, /* SPD not available */ |
Christian Walter | f972322 | 2019-05-28 10:37:24 +0200 | [diff] [blame] | 81 | memory_info_hob->DataWidth, |
| 82 | 0, |
Duncan Laurie | 1a86cda | 2019-06-10 14:00:56 -0700 | [diff] [blame] | 83 | 0, |
| 84 | src_dimm->MfgId, |
Christian Walter | f972322 | 2019-05-28 10:37:24 +0200 | [diff] [blame] | 85 | 0); |
Ravi Sarawadi | 09195ac | 2017-07-20 15:11:19 -0700 | [diff] [blame] | 86 | index++; |
| 87 | } |
| 88 | } |
| 89 | mem_info->dimm_cnt = index; |
| 90 | printk(BIOS_DEBUG, "%d DIMMs found\n", mem_info->dimm_cnt); |
| 91 | } |
Aaron Durbin | 9a30c72 | 2018-08-07 12:04:21 -0600 | [diff] [blame] | 92 | |
| 93 | void save_lpddr4_dimm_info(const struct lpddr4_cfg *lp4cfg, size_t mem_sku) |
| 94 | { |
| 95 | const char *part_num = NULL; |
| 96 | |
| 97 | if (mem_sku >= lp4cfg->num_skus) { |
| 98 | printk(BIOS_ERR, "Too few LPDDR4 SKUs: 0x%zx/0x%zx\n", |
| 99 | mem_sku, lp4cfg->num_skus); |
| 100 | } else { |
| 101 | part_num = lp4cfg->skus[mem_sku].part_num; |
| 102 | } |
| 103 | |
| 104 | save_lpddr4_dimm_info_part_num(part_num); |
| 105 | } |