| 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #ifndef __SOC_INTEL_COMMON_BLOCK_MEMINIT_H__ |
| 4 | #define __SOC_INTEL_COMMON_BLOCK_MEMINIT_H__ |
| 5 | |
| 6 | #include <fsp/api.h> |
| 7 | #include <types.h> |
| 8 | |
| 9 | /* |
| 10 | * Calculates the number of channels depending upon the data bus width of the |
| 11 | * platform and the channel width. |
| 12 | */ |
| 13 | #define CHANNEL_COUNT(ch_width) (CONFIG_DATA_BUS_WIDTH / (ch_width)) |
| 14 | |
| 15 | /* |
| 16 | * UPDs for FSP-M are organized depending upon the MRC's view of channel. Thus, |
| 17 | * the number of channels as seen by the MRC are dependent on the channel width |
| 18 | * assumption in the UPDs. These channels might not necessarily be the same as |
| 19 | * the physical channels supported by the platform. |
| 20 | */ |
| 21 | #define MRC_CHANNELS CHANNEL_COUNT(CONFIG_MRC_CHANNEL_WIDTH) |
| 22 | |
| 23 | /* Different memory topologies supported by the platform. */ |
| 24 | enum mem_topology { |
| 25 | MEM_TOPO_MEMORY_DOWN = BIT(0), // memory is soldered onto board |
| 26 | MEM_TOPO_DIMM_MODULE = BIT(1), // memory is composed of DIMM modules |
| 27 | MEM_TOPO_MIXED = MEM_TOPO_MEMORY_DOWN | MEM_TOPO_DIMM_MODULE, |
| 28 | }; |
| 29 | |
| 30 | /* |
| 31 | * SPD provides information about the memory module. Depending upon the memory |
| 32 | * topology, the SPD data can be obtained from different sources. Example: for |
| 33 | * memory down topology, SPD is read from CBFS using cbfs_index. For DIMM |
| 34 | * modules, SPD is read from EEPROM using the DIMM addresses provided by the |
| 35 | * mainboard. |
| 36 | */ |
| 37 | struct mem_spd { |
| 38 | enum mem_topology topo; |
| 39 | /* |
| 40 | * SPD data is read from CBFS spd.bin file using cbfs_index to locate |
| 41 | * the entry. This is used in case of MEM_TOPO_MEMORY_DOWN and |
| 42 | * MEM_TOPO_MIXED topologies. |
| 43 | */ |
| 44 | size_t cbfs_index; |
| 45 | |
| 46 | /* |
| 47 | * SPD data is read from on-module EEPROM using the DIMM addresses |
| 48 | * provided by the mainboard. This is used in case of |
| 49 | * MEM_TOPO_DIMM_MODULE and MEM_TOPO_MIXED topologies. |
| 50 | * |
| 51 | * Up to a maximum of MRC_CHANNELS * CONFIG_DIMMS_PER_CHANNEL addresses |
| 52 | * can be provided by mainboard. However, depending upon the memory |
| 53 | * technology being used and the number of physical channels supported |
| 54 | * by that technology, the actual channels might be less than |
| 55 | * MRC_CHANNELS. |
| 56 | */ |
| 57 | struct { |
| 58 | uint8_t addr_dimm[CONFIG_DIMMS_PER_CHANNEL]; |
| 59 | } smbus[MRC_CHANNELS]; |
| 60 | |
| 61 | /* If the SPD data is provided in a memory buffer, spd_data.in_mem needs to be |
| 62 | * set to 'true'. In this case spd_data.ptr points to the memory buffer where the |
| 63 | * SPD data is stored in and spd_data.len stores the length of the SPD data |
| 64 | * in that buffer. In this case cbfs_index is ignored. |
| 65 | */ |
| 66 | struct { |
| 67 | bool in_mem; |
| 68 | size_t len; |
| 69 | uintptr_t ptr; |
| 70 | } spd_data; |
| 71 | }; |
| 72 | |
| 73 | /* Information about memory technology supported by SoC */ |
| 74 | struct soc_mem_cfg { |
| 75 | /* |
| 76 | * Number of physical channels that are supported by the memory |
| 77 | * technology. |
| 78 | */ |
| 79 | size_t num_phys_channels; |
| 80 | |
| 81 | /* |
| 82 | * Map of physical channel numbers to MRC channel numbers. This is |
| 83 | * helpful in identifying what SPD entries need to be filled for a |
| 84 | * physical channel. |
| 85 | * |
| 86 | * Example: MRC supports 8 channels 0 - 7, but a memory technology |
| 87 | * supports only 2 physical channels 0 - 1. In this case, the map could |
| 88 | * be: |
| 89 | * [0] = 0, |
| 90 | * [1] = 4, |
| 91 | * indicating that physical channel 0 is mapped to MRC channel 0 and |
| 92 | * physical channel 1 is mapped to MRC channel 4. |
| 93 | */ |
| 94 | size_t phys_to_mrc_map[MRC_CHANNELS]; |
| 95 | |
| 96 | /* |
| 97 | * Masks to be applied in case of memory down topology. For memory down |
| 98 | * topology, there is no separate EEPROM. Thus, the masks need to be |
| 99 | * hard-coded by the SoC to indicate what combinations are supported. |
| 100 | * This is a mask of physical channels for the memory technology. |
| 101 | * |
| 102 | * Example: For the memory technology supporting 2 physical channels, |
| 103 | * where the population rules restrict use of channel 0 for |
| 104 | * half-channel, half_channel mask would be set to 0x1 indicating |
| 105 | * channel 0 is always populated. |
| 106 | */ |
| 107 | struct { |
| 108 | /* |
| 109 | * Mask of physical channels that are populated in case of |
| 110 | * half-channel configuration. |
| 111 | */ |
| 112 | uint32_t half_channel; |
| 113 | /* |
| 114 | * Mask of physical channels that are populated with memory |
| 115 | * down parts in case of mixed topology. |
| 116 | */ |
| 117 | uint32_t mixed_topo; |
| 118 | } md_phy_masks; |
| 119 | }; |
| 120 | |
| 121 | /* Flags indicating how the channels are populated. */ |
| 122 | enum channel_population { |
| 123 | NO_CHANNEL_POPULATED = 0, |
| 124 | TOP_HALF_POPULATED = BIT(0), |
| 125 | BOTTOM_HALF_POPULATED = BIT(1), |
| 126 | FULLY_POPULATED = TOP_HALF_POPULATED | BOTTOM_HALF_POPULATED, |
| 127 | }; |
| 128 | |
| 129 | /* |
| 130 | * Data for the memory channels that can be used by SoC code to populate FSP |
| 131 | * UPDs. |
| 132 | */ |
| 133 | struct mem_channel_data { |
| 134 | /* Pointer to SPD data for each DIMM of each channel */ |
| 135 | uintptr_t spd[MRC_CHANNELS][CONFIG_DIMMS_PER_CHANNEL]; |
| 136 | /* Length of SPD data */ |
| 137 | size_t spd_len; |
| 138 | /* Flags indicating how channels are populated */ |
| 139 | enum channel_population ch_population_flags; |
| 140 | }; |
| 141 | |
| 142 | /* |
| 143 | * This change populates data regarding memory channels in `struct |
| 144 | * mem_channel_data` using the following inputs from SoC code: |
| 145 | * memupd : FSP-M UPD configuration. |
| 146 | * soc_mem_cfg : SoC-specific information about the memory technology used by |
| 147 | * the mainboard. |
| 148 | * spd_info : Information about the memory topology. |
| 149 | * half_populated: Hint from mainboard if channels are half populated. |
| 150 | */ |
| 151 | void mem_populate_channel_data(FSPM_UPD *memupd, const struct soc_mem_cfg *soc_mem_cfg, |
| 152 | const struct mem_spd *spd_info, |
| 153 | bool half_populated, |
| 154 | struct mem_channel_data *data); |
| 155 | |
| 156 | /* |
| 157 | * Given a channel number and the maximum number of supported channels, this |
| 158 | * function returns if a channel is populated. This is useful for populating |
| 159 | * DQ/DQS UPDs by the SoC code. |
| 160 | */ |
| 161 | static inline bool channel_is_populated(size_t curr_ch, size_t max_ch, |
| 162 | enum channel_population flags) |
| 163 | { |
| 164 | if ((curr_ch * 2) < max_ch) |
| 165 | return !!(flags & BOTTOM_HALF_POPULATED); |
| 166 | |
| 167 | return !!(flags & TOP_HALF_POPULATED); |
| 168 | } |
| 169 | |
| 170 | #endif /* __SOC_INTEL_COMMON_BLOCK_MEMINIT_H__ */ |