Julien Viard de Galbert | 2d0aaa7 | 2018-02-26 18:32:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Google Inc. |
| 5 | * Copyright (C) 2015-2016 Intel Corporation. |
| 6 | * Copyright (C) 2017-2018 Online SAS. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | */ |
| 17 | |
| 18 | #include <cbmem.h> |
| 19 | #include <console/console.h> |
| 20 | #include <string.h> |
| 21 | |
| 22 | #include <soc/hob_mem.h> |
| 23 | |
| 24 | #include <smbios.h> |
| 25 | #include <memory_info.h> |
| 26 | #include <soc/ramstage.h> |
| 27 | |
| 28 | /* Save the DIMM information for SMBIOS table 17 */ |
| 29 | void soc_save_dimm_info(void) |
| 30 | { |
| 31 | int channel; |
| 32 | const CHANNEL_INFO *channel_info; |
| 33 | int dimm; |
| 34 | const DIMM_INFO *dimm_info; |
| 35 | int dimm_max; |
| 36 | int index; |
| 37 | struct memory_info *mem_info; |
| 38 | const FSP_SMBIOS_MEMORY_INFO *memory_info_hob; |
| 39 | |
| 40 | /* Get the memory info HOB */ |
| 41 | memory_info_hob = soc_get_fsp_smbios_memory_info_hob(); |
| 42 | |
| 43 | if (memory_info_hob == NULL) |
| 44 | return; |
| 45 | |
| 46 | /* Display the data in the FSP_SMBIOS_MEMORY_INFO HOB */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame^] | 47 | if (CONFIG(DISPLAY_HOBS)) |
Julien Viard de Galbert | 2d0aaa7 | 2018-02-26 18:32:59 +0100 | [diff] [blame] | 48 | soc_display_fsp_smbios_memory_info_hob(memory_info_hob); |
| 49 | |
| 50 | /* |
| 51 | * Allocate CBMEM area for DIMM information used to populate SMBIOS |
| 52 | * table 17 |
| 53 | */ |
| 54 | mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(*mem_info)); |
| 55 | printk(BIOS_DEBUG, "CBMEM entry for DIMM info: 0x%p\n", mem_info); |
| 56 | if (mem_info == NULL) |
| 57 | return; |
| 58 | memset(mem_info, 0, sizeof(*mem_info)); |
| 59 | |
| 60 | /* Describe the first N DIMMs in the system */ |
| 61 | index = 0; |
| 62 | dimm_max = ARRAY_SIZE(mem_info->dimm); |
| 63 | for (channel = 0; channel < memory_info_hob->ChannelCount; channel++) { |
| 64 | if (index >= dimm_max) |
| 65 | break; |
| 66 | channel_info = &memory_info_hob->ChannelInfo[channel]; |
| 67 | for (dimm = 0; dimm < channel_info->DimmCount; dimm++) { |
| 68 | if (index >= dimm_max) |
| 69 | break; |
| 70 | dimm_info = &channel_info->DimmInfo[dimm]; |
| 71 | |
| 72 | /* Populate the DIMM information */ |
| 73 | if (!dimm_info->SizeInMb) |
| 74 | continue; |
| 75 | |
| 76 | mem_info->dimm[index].dimm_size = |
| 77 | dimm_info->SizeInMb; |
| 78 | mem_info->dimm[index].ddr_type = |
| 79 | memory_info_hob->MemoryType; |
| 80 | mem_info->dimm[index].ddr_frequency = |
| 81 | memory_info_hob->MemoryFrequencyInMHz; |
| 82 | mem_info->dimm[index].channel_num = |
| 83 | channel_info->ChannelId; |
| 84 | mem_info->dimm[index].dimm_num = |
| 85 | dimm_info->DimmId; |
| 86 | |
| 87 | strncpy((char *) |
| 88 | mem_info->dimm[index].module_part_number, |
| 89 | (char *)dimm_info->ModulePartNum, 18); |
| 90 | mem_info->dimm[index].mod_id = |
| 91 | dimm_info->MfgId; |
| 92 | switch (memory_info_hob->DataWidth) { |
| 93 | default: |
| 94 | case 8: |
| 95 | mem_info->dimm[index].bus_width = |
| 96 | MEMORY_BUS_WIDTH_8; |
| 97 | break; |
| 98 | |
| 99 | case 16: |
| 100 | mem_info->dimm[index].bus_width = |
| 101 | MEMORY_BUS_WIDTH_16; |
| 102 | break; |
| 103 | |
| 104 | case 32: |
| 105 | mem_info->dimm[index].bus_width = |
| 106 | MEMORY_BUS_WIDTH_32; |
| 107 | break; |
| 108 | |
| 109 | case 64: |
| 110 | mem_info->dimm[index].bus_width = |
| 111 | MEMORY_BUS_WIDTH_64; |
| 112 | break; |
| 113 | |
| 114 | case 128: |
| 115 | mem_info->dimm[index].bus_width = |
| 116 | MEMORY_BUS_WIDTH_128; |
| 117 | break; |
| 118 | } |
| 119 | |
| 120 | /* Add any mainboard specific information */ |
| 121 | mainboard_add_dimm_info(mem_info, channel, dimm, index); |
| 122 | index++; |
| 123 | } |
| 124 | } |
| 125 | mem_info->dimm_cnt = index; |
| 126 | printk(BIOS_DEBUG, "%d DIMMs found\n", mem_info->dimm_cnt); |
| 127 | } |
| 128 | |
| 129 | /* Add any mainboard specific information */ |
| 130 | __attribute__((weak)) void mainboard_add_dimm_info(struct memory_info *mem_info, |
| 131 | int channel, int dimm, |
| 132 | int index) |
| 133 | { |
| 134 | printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__); |
| 135 | } |