Felix Held | 2421de6 | 2021-03-26 01:13:53 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <amdblocks/apob_cache.h> |
Felix Held | 1ed5a63 | 2021-05-04 21:51:43 +0200 | [diff] [blame] | 4 | #include <amdblocks/ioapic.h> |
Felix Held | 2421de6 | 2021-03-26 01:13:53 +0100 | [diff] [blame] | 5 | #include <amdblocks/memmap.h> |
Matt Papageorge | ea0f225 | 2021-03-30 11:41:22 -0500 | [diff] [blame] | 6 | #include <assert.h> |
Felix Held | 2421de6 | 2021-03-26 01:13:53 +0100 | [diff] [blame] | 7 | #include <console/uart.h> |
Felix Held | d0b5164 | 2021-04-08 22:25:19 +0200 | [diff] [blame] | 8 | #include <device/device.h> |
Felix Held | 2421de6 | 2021-03-26 01:13:53 +0100 | [diff] [blame] | 9 | #include <fsp/api.h> |
Matt Papageorge | ea0f225 | 2021-03-30 11:41:22 -0500 | [diff] [blame] | 10 | #include <soc/platform_descriptors.h> |
Karthikeyan Ramasubramanian | cdbedb6 | 2021-05-10 17:02:58 -0600 | [diff] [blame] | 11 | #include <soc/pci_devs.h> |
Matt Papageorge | ea0f225 | 2021-03-30 11:41:22 -0500 | [diff] [blame] | 12 | #include <string.h> |
| 13 | #include <types.h> |
Felix Held | d0b5164 | 2021-04-08 22:25:19 +0200 | [diff] [blame] | 14 | #include "chip.h" |
Matt Papageorge | ea0f225 | 2021-03-30 11:41:22 -0500 | [diff] [blame] | 15 | |
Karthikeyan Ramasubramanian | cdbedb6 | 2021-05-10 17:02:58 -0600 | [diff] [blame] | 16 | static const struct device_path gfx_hda_path[] = { |
| 17 | { |
| 18 | .type = DEVICE_PATH_PCI, |
| 19 | .pci.devfn = PCIE_ABC_A_DEVFN |
| 20 | }, |
| 21 | { |
| 22 | .type = DEVICE_PATH_PCI, |
| 23 | .pci.devfn = GFX_HDA_DEVFN |
| 24 | }, |
| 25 | }; |
| 26 | |
| 27 | static bool devtree_gfx_hda_dev_enabled(void) |
| 28 | { |
| 29 | const struct device *gfx_hda_dev; |
| 30 | |
| 31 | gfx_hda_dev = find_dev_nested_path(pci_root_bus(), gfx_hda_path, |
| 32 | ARRAY_SIZE(gfx_hda_path)); |
| 33 | if (!gfx_hda_dev) |
| 34 | return false; |
| 35 | |
| 36 | return gfx_hda_dev->enabled; |
| 37 | } |
| 38 | |
Felix Held | 42583de | 2021-06-19 00:06:02 +0200 | [diff] [blame] | 39 | static const struct device_path hda_path[] = { |
| 40 | { |
| 41 | .type = DEVICE_PATH_PCI, |
| 42 | .pci.devfn = PCIE_ABC_A_DEVFN |
| 43 | }, |
| 44 | { |
| 45 | .type = DEVICE_PATH_PCI, |
| 46 | .pci.devfn = HD_AUDIO_DEVFN |
| 47 | }, |
| 48 | }; |
| 49 | |
| 50 | static bool devtree_hda_dev_enabled(void) |
| 51 | { |
| 52 | const struct device *hda_dev; |
| 53 | |
| 54 | hda_dev = find_dev_nested_path(pci_root_bus(), hda_path, ARRAY_SIZE(hda_path)); |
| 55 | |
| 56 | if (!hda_dev) |
| 57 | return false; |
| 58 | |
| 59 | return hda_dev->enabled; |
| 60 | } |
| 61 | |
Felix Held | ea668d7 | 2021-06-18 16:33:49 +0200 | [diff] [blame] | 62 | static const struct device_path sata0_path[] = { |
| 63 | { |
| 64 | .type = DEVICE_PATH_PCI, |
| 65 | .pci.devfn = PCIE_GPP_B_DEVFN |
| 66 | }, |
| 67 | { |
| 68 | .type = DEVICE_PATH_PCI, |
| 69 | .pci.devfn = SATA0_DEVFN |
| 70 | }, |
| 71 | }; |
| 72 | |
| 73 | static const struct device_path sata1_path[] = { |
| 74 | { |
| 75 | .type = DEVICE_PATH_PCI, |
| 76 | .pci.devfn = PCIE_GPP_B_DEVFN |
| 77 | }, |
| 78 | { |
| 79 | .type = DEVICE_PATH_PCI, |
| 80 | .pci.devfn = SATA1_DEVFN |
| 81 | }, |
| 82 | }; |
| 83 | |
| 84 | static bool devtree_sata_dev_enabled(void) |
| 85 | { |
| 86 | const struct device *ahci0_dev, *ahci1_dev; |
| 87 | |
| 88 | ahci0_dev = find_dev_nested_path(pci_root_bus(), sata0_path, ARRAY_SIZE(sata0_path)); |
| 89 | ahci1_dev = find_dev_nested_path(pci_root_bus(), sata1_path, ARRAY_SIZE(sata1_path)); |
| 90 | |
| 91 | if (!ahci0_dev || !ahci1_dev) |
| 92 | return false; |
| 93 | |
| 94 | return ahci0_dev->enabled || ahci1_dev->enabled; |
| 95 | } |
| 96 | |
Martin Roth | 9d9dae1 | 2021-05-12 13:03:21 -0600 | [diff] [blame] | 97 | __weak void mb_pre_fspm(void) |
| 98 | { |
| 99 | } |
| 100 | |
Matt Papageorge | ea0f225 | 2021-03-30 11:41:22 -0500 | [diff] [blame] | 101 | static void fill_dxio_descriptors(FSP_M_CONFIG *mcfg, |
| 102 | const fsp_dxio_descriptor *descs, size_t num) |
| 103 | { |
| 104 | size_t i; |
| 105 | |
| 106 | ASSERT_MSG(num <= FSPM_UPD_DXIO_DESCRIPTOR_COUNT, |
| 107 | "Too many DXIO descriptors provided."); |
| 108 | |
| 109 | for (i = 0; i < num; i++) { |
| 110 | memcpy(mcfg->dxio_descriptor[i], &descs[i], sizeof(mcfg->dxio_descriptor[0])); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | static void fill_ddi_descriptors(FSP_M_CONFIG *mcfg, |
| 115 | const fsp_ddi_descriptor *descs, size_t num) |
| 116 | { |
| 117 | size_t i; |
| 118 | |
| 119 | ASSERT_MSG(num <= FSPM_UPD_DDI_DESCRIPTOR_COUNT, |
| 120 | "Too many DDI descriptors provided."); |
| 121 | |
| 122 | for (i = 0; i < num; i++) { |
| 123 | memcpy(&mcfg->ddi_descriptor[i], &descs[i], sizeof(mcfg->ddi_descriptor[0])); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | static void fsp_fill_pcie_ddi_descriptors(FSP_M_CONFIG *mcfg) |
| 128 | { |
| 129 | const fsp_dxio_descriptor *fsp_dxio; |
| 130 | const fsp_ddi_descriptor *fsp_ddi; |
| 131 | size_t num_dxio; |
| 132 | size_t num_ddi; |
| 133 | |
| 134 | mainboard_get_dxio_ddi_descriptors(&fsp_dxio, &num_dxio, |
| 135 | &fsp_ddi, &num_ddi); |
| 136 | fill_dxio_descriptors(mcfg, fsp_dxio, num_dxio); |
| 137 | fill_ddi_descriptors(mcfg, fsp_ddi, num_ddi); |
| 138 | } |
Felix Held | 2421de6 | 2021-03-26 01:13:53 +0100 | [diff] [blame] | 139 | |
Felix Held | 1ed5a63 | 2021-05-04 21:51:43 +0200 | [diff] [blame] | 140 | static void fsp_assign_ioapic_upds(FSP_M_CONFIG *mcfg) |
| 141 | { |
| 142 | mcfg->gnb_ioapic_base = GNB_IO_APIC_ADDR; |
| 143 | mcfg->gnb_ioapic_id = GNB_IOAPIC_ID; |
| 144 | mcfg->fch_ioapic_id = FCH_IOAPIC_ID; |
| 145 | } |
| 146 | |
Felix Held | 2421de6 | 2021-03-26 01:13:53 +0100 | [diff] [blame] | 147 | void platform_fsp_memory_init_params_cb(FSPM_UPD *mupd, uint32_t version) |
| 148 | { |
| 149 | FSP_M_CONFIG *mcfg = &mupd->FspmConfig; |
Felix Held | d0b5164 | 2021-04-08 22:25:19 +0200 | [diff] [blame] | 150 | const struct soc_amd_cezanne_config *config = config_of_soc(); |
Felix Held | 2421de6 | 2021-03-26 01:13:53 +0100 | [diff] [blame] | 151 | |
| 152 | mupd->FspmArchUpd.NvsBufferPtr = (uintptr_t)soc_fill_apob_cache(); |
| 153 | |
| 154 | mcfg->pci_express_base_addr = CONFIG_MMCONF_BASE_ADDRESS; |
| 155 | mcfg->tseg_size = CONFIG_SMM_TSEG_SIZE; |
Felix Held | 2421de6 | 2021-03-26 01:13:53 +0100 | [diff] [blame] | 156 | mcfg->serial_port_base = uart_platform_base(CONFIG_UART_FOR_CONSOLE); |
| 157 | mcfg->serial_port_use_mmio = CONFIG(DRIVERS_UART_8250MEM); |
Felix Held | 2421de6 | 2021-03-26 01:13:53 +0100 | [diff] [blame] | 158 | mcfg->serial_port_baudrate = get_uart_baudrate(); |
| 159 | mcfg->serial_port_refclk = uart_platform_refclk(); |
Matt Papageorge | ea0f225 | 2021-03-30 11:41:22 -0500 | [diff] [blame] | 160 | |
Felix Held | d0b5164 | 2021-04-08 22:25:19 +0200 | [diff] [blame] | 161 | /* 0 is default */ |
| 162 | mcfg->ccx_down_core_mode = config->downcore_mode; |
| 163 | mcfg->ccx_disable_smt = config->disable_smt; |
| 164 | |
Felix Held | d3be9ba | 2021-04-19 21:40:35 +0200 | [diff] [blame] | 165 | /* when stt_control isn't 1, FSP will ignore the other stt values */ |
| 166 | mcfg->stt_control = config->stt_control; |
| 167 | mcfg->stt_pcb_sensor_count = config->stt_pcb_sensor_count; |
| 168 | mcfg->stt_min_limit = config->stt_min_limit; |
| 169 | mcfg->stt_m1 = config->stt_m1; |
| 170 | mcfg->stt_m2 = config->stt_m2; |
| 171 | mcfg->stt_m3 = config->stt_m3; |
| 172 | mcfg->stt_m4 = config->stt_m4; |
| 173 | mcfg->stt_m5 = config->stt_m5; |
| 174 | mcfg->stt_m6 = config->stt_m6; |
| 175 | mcfg->stt_c_apu = config->stt_c_apu; |
| 176 | mcfg->stt_c_gpu = config->stt_c_gpu; |
| 177 | mcfg->stt_c_hs2 = config->stt_c_hs2; |
| 178 | mcfg->stt_alpha_apu = config->stt_alpha_apu; |
| 179 | mcfg->stt_alpha_gpu = config->stt_alpha_gpu; |
| 180 | mcfg->stt_alpha_hs2 = config->stt_alpha_hs2; |
| 181 | mcfg->stt_skin_temp_apu = config->stt_skin_temp_apu; |
| 182 | mcfg->stt_skin_temp_gpu = config->stt_skin_temp_gpu; |
| 183 | mcfg->stt_skin_temp_hs2 = config->stt_skin_temp_hs2; |
| 184 | mcfg->stt_error_coeff = config->stt_error_coeff; |
| 185 | mcfg->stt_error_rate_coefficient = config->stt_error_rate_coefficient; |
| 186 | |
| 187 | /* all following fields being 0 is a valid config */ |
| 188 | mcfg->stapm_boost = config->stapm_boost; |
Martin Roth | 9c17665 | 2021-04-23 12:24:35 -0600 | [diff] [blame] | 189 | mcfg->stapm_time_constant = config->stapm_time_constant_s; |
Felix Held | d3be9ba | 2021-04-19 21:40:35 +0200 | [diff] [blame] | 190 | mcfg->apu_only_sppt_limit = config->apu_only_sppt_limit; |
Martin Roth | 9c17665 | 2021-04-23 12:24:35 -0600 | [diff] [blame] | 191 | mcfg->sustained_power_limit = config->sustained_power_limit_mW; |
| 192 | mcfg->fast_ppt_limit = config->fast_ppt_limit_mW; |
| 193 | mcfg->slow_ppt_limit = config->slow_ppt_limit_mW; |
Martin Roth | 029d997 | 2021-04-23 12:22:59 -0600 | [diff] [blame] | 194 | mcfg->slow_ppt_time_constant = config->slow_ppt_time_constant_s; |
| 195 | mcfg->thermctl_limit = config->thermctl_limit_degreeC; |
Felix Held | d3be9ba | 2021-04-19 21:40:35 +0200 | [diff] [blame] | 196 | |
| 197 | /* 0 is default */ |
| 198 | mcfg->smartshift_enable = config->smartshift_enable; |
| 199 | |
| 200 | /* 0 is default */ |
| 201 | mcfg->system_configuration = config->system_configuration; |
| 202 | |
| 203 | /* when cppc_ctrl is 0 the other values won't be used */ |
| 204 | mcfg->cppc_ctrl = config->cppc_ctrl; |
| 205 | mcfg->cppc_perf_limit_max_range = config->cppc_perf_limit_max_range; |
| 206 | mcfg->cppc_perf_limit_min_range = config->cppc_perf_limit_min_range; |
| 207 | mcfg->cppc_epp_max_range = config->cppc_epp_max_range; |
| 208 | mcfg->cppc_epp_min_range = config->cppc_epp_min_range; |
| 209 | mcfg->cppc_preferred_cores = config->cppc_preferred_cores; |
| 210 | |
Karthikeyan Ramasubramanian | 5ad85d9 | 2021-04-22 16:59:08 -0600 | [diff] [blame] | 211 | /* S0i3 enable */ |
| 212 | mcfg->s0i3_enable = config->s0ix_enable; |
Jason Glenesk | 0834d86 | 2021-08-03 03:39:36 -0700 | [diff] [blame] | 213 | mcfg->iommu_support = is_devfn_enabled(IOMMU_DEVFN); |
Karthikeyan Ramasubramanian | 5ad85d9 | 2021-04-22 16:59:08 -0600 | [diff] [blame] | 214 | |
Chris Wang | 0679392 | 2021-04-29 00:11:01 +0800 | [diff] [blame] | 215 | /* voltage regulator telemetry settings */ |
| 216 | mcfg->telemetry_vddcrvddfull_scale_current = |
| 217 | config->telemetry_vddcrvddfull_scale_current_mA; |
| 218 | mcfg->telemetry_vddcrvddoffset = |
| 219 | config->telemetry_vddcrvddoffset; |
| 220 | mcfg->telemetry_vddcrsocfull_scale_current = |
| 221 | config->telemetry_vddcrsocfull_scale_current_mA; |
| 222 | mcfg->telemetry_vddcrsocOffset = |
| 223 | config->telemetry_vddcrsocoffset; |
| 224 | |
Felix Held | 9a24c3f | 2021-05-25 20:45:08 +0200 | [diff] [blame] | 225 | /* PCIe power vs. speed */ |
| 226 | mcfg->pspp_policy = config->pspp_policy; |
| 227 | |
Karthikeyan Ramasubramanian | cdbedb6 | 2021-05-10 17:02:58 -0600 | [diff] [blame] | 228 | mcfg->enable_nb_azalia = devtree_gfx_hda_dev_enabled(); |
Felix Held | 42583de | 2021-06-19 00:06:02 +0200 | [diff] [blame] | 229 | mcfg->hda_enable = devtree_hda_dev_enabled(); |
Felix Held | ea668d7 | 2021-06-18 16:33:49 +0200 | [diff] [blame] | 230 | mcfg->sata_enable = devtree_sata_dev_enabled(); |
Karthikeyan Ramasubramanian | cdbedb6 | 2021-05-10 17:02:58 -0600 | [diff] [blame] | 231 | |
Julian Schroeder | 4671983 | 2021-09-07 14:54:19 -0500 | [diff] [blame] | 232 | if (config->usb_phy_custom) { |
Julian Schroeder | d2f3308 | 2021-05-11 10:44:13 -0500 | [diff] [blame] | 233 | mcfg->usb_phy = (struct usb_phy_config *)&config->usb_phy; |
Julian Schroeder | 4671983 | 2021-09-07 14:54:19 -0500 | [diff] [blame] | 234 | mcfg->usb_phy->Version_Major = 0xd; |
| 235 | mcfg->usb_phy->Version_Minor = 0x6; |
| 236 | mcfg->usb_phy->TableLength = 100; |
| 237 | } |
Julian Schroeder | d2f3308 | 2021-05-11 10:44:13 -0500 | [diff] [blame] | 238 | else |
| 239 | mcfg->usb_phy = NULL; |
| 240 | |
Matt Papageorge | ea0f225 | 2021-03-30 11:41:22 -0500 | [diff] [blame] | 241 | fsp_fill_pcie_ddi_descriptors(mcfg); |
Felix Held | 1ed5a63 | 2021-05-04 21:51:43 +0200 | [diff] [blame] | 242 | fsp_assign_ioapic_upds(mcfg); |
Martin Roth | 9d9dae1 | 2021-05-12 13:03:21 -0600 | [diff] [blame] | 243 | mb_pre_fspm(); |
Felix Held | 2421de6 | 2021-03-26 01:13:53 +0100 | [diff] [blame] | 244 | } |