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 | |
Matt Papageorge | ea0f225 | 2021-03-30 11:41:22 -0500 | [diff] [blame] | 39 | static void fill_dxio_descriptors(FSP_M_CONFIG *mcfg, |
| 40 | const fsp_dxio_descriptor *descs, size_t num) |
| 41 | { |
| 42 | size_t i; |
| 43 | |
| 44 | ASSERT_MSG(num <= FSPM_UPD_DXIO_DESCRIPTOR_COUNT, |
| 45 | "Too many DXIO descriptors provided."); |
| 46 | |
| 47 | for (i = 0; i < num; i++) { |
| 48 | memcpy(mcfg->dxio_descriptor[i], &descs[i], sizeof(mcfg->dxio_descriptor[0])); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | static void fill_ddi_descriptors(FSP_M_CONFIG *mcfg, |
| 53 | const fsp_ddi_descriptor *descs, size_t num) |
| 54 | { |
| 55 | size_t i; |
| 56 | |
| 57 | ASSERT_MSG(num <= FSPM_UPD_DDI_DESCRIPTOR_COUNT, |
| 58 | "Too many DDI descriptors provided."); |
| 59 | |
| 60 | for (i = 0; i < num; i++) { |
| 61 | memcpy(&mcfg->ddi_descriptor[i], &descs[i], sizeof(mcfg->ddi_descriptor[0])); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | static void fsp_fill_pcie_ddi_descriptors(FSP_M_CONFIG *mcfg) |
| 66 | { |
| 67 | const fsp_dxio_descriptor *fsp_dxio; |
| 68 | const fsp_ddi_descriptor *fsp_ddi; |
| 69 | size_t num_dxio; |
| 70 | size_t num_ddi; |
| 71 | |
| 72 | mainboard_get_dxio_ddi_descriptors(&fsp_dxio, &num_dxio, |
| 73 | &fsp_ddi, &num_ddi); |
| 74 | fill_dxio_descriptors(mcfg, fsp_dxio, num_dxio); |
| 75 | fill_ddi_descriptors(mcfg, fsp_ddi, num_ddi); |
| 76 | } |
Felix Held | 2421de6 | 2021-03-26 01:13:53 +0100 | [diff] [blame] | 77 | |
Felix Held | 1ed5a63 | 2021-05-04 21:51:43 +0200 | [diff] [blame] | 78 | static void fsp_assign_ioapic_upds(FSP_M_CONFIG *mcfg) |
| 79 | { |
| 80 | mcfg->gnb_ioapic_base = GNB_IO_APIC_ADDR; |
| 81 | mcfg->gnb_ioapic_id = GNB_IOAPIC_ID; |
| 82 | mcfg->fch_ioapic_id = FCH_IOAPIC_ID; |
| 83 | } |
| 84 | |
Felix Held | 2421de6 | 2021-03-26 01:13:53 +0100 | [diff] [blame] | 85 | void platform_fsp_memory_init_params_cb(FSPM_UPD *mupd, uint32_t version) |
| 86 | { |
| 87 | FSP_M_CONFIG *mcfg = &mupd->FspmConfig; |
Felix Held | d0b5164 | 2021-04-08 22:25:19 +0200 | [diff] [blame] | 88 | const struct soc_amd_cezanne_config *config = config_of_soc(); |
Felix Held | 2421de6 | 2021-03-26 01:13:53 +0100 | [diff] [blame] | 89 | |
| 90 | mupd->FspmArchUpd.NvsBufferPtr = (uintptr_t)soc_fill_apob_cache(); |
| 91 | |
| 92 | mcfg->pci_express_base_addr = CONFIG_MMCONF_BASE_ADDRESS; |
| 93 | mcfg->tseg_size = CONFIG_SMM_TSEG_SIZE; |
Felix Held | 2421de6 | 2021-03-26 01:13:53 +0100 | [diff] [blame] | 94 | mcfg->serial_port_base = uart_platform_base(CONFIG_UART_FOR_CONSOLE); |
| 95 | mcfg->serial_port_use_mmio = CONFIG(DRIVERS_UART_8250MEM); |
Felix Held | 2421de6 | 2021-03-26 01:13:53 +0100 | [diff] [blame] | 96 | mcfg->serial_port_baudrate = get_uart_baudrate(); |
| 97 | mcfg->serial_port_refclk = uart_platform_refclk(); |
Matt Papageorge | ea0f225 | 2021-03-30 11:41:22 -0500 | [diff] [blame] | 98 | |
Felix Held | d0b5164 | 2021-04-08 22:25:19 +0200 | [diff] [blame] | 99 | /* 0 is default */ |
| 100 | mcfg->ccx_down_core_mode = config->downcore_mode; |
| 101 | mcfg->ccx_disable_smt = config->disable_smt; |
| 102 | |
Felix Held | d3be9ba | 2021-04-19 21:40:35 +0200 | [diff] [blame] | 103 | /* when stt_control isn't 1, FSP will ignore the other stt values */ |
| 104 | mcfg->stt_control = config->stt_control; |
| 105 | mcfg->stt_pcb_sensor_count = config->stt_pcb_sensor_count; |
| 106 | mcfg->stt_min_limit = config->stt_min_limit; |
| 107 | mcfg->stt_m1 = config->stt_m1; |
| 108 | mcfg->stt_m2 = config->stt_m2; |
| 109 | mcfg->stt_m3 = config->stt_m3; |
| 110 | mcfg->stt_m4 = config->stt_m4; |
| 111 | mcfg->stt_m5 = config->stt_m5; |
| 112 | mcfg->stt_m6 = config->stt_m6; |
| 113 | mcfg->stt_c_apu = config->stt_c_apu; |
| 114 | mcfg->stt_c_gpu = config->stt_c_gpu; |
| 115 | mcfg->stt_c_hs2 = config->stt_c_hs2; |
| 116 | mcfg->stt_alpha_apu = config->stt_alpha_apu; |
| 117 | mcfg->stt_alpha_gpu = config->stt_alpha_gpu; |
| 118 | mcfg->stt_alpha_hs2 = config->stt_alpha_hs2; |
| 119 | mcfg->stt_skin_temp_apu = config->stt_skin_temp_apu; |
| 120 | mcfg->stt_skin_temp_gpu = config->stt_skin_temp_gpu; |
| 121 | mcfg->stt_skin_temp_hs2 = config->stt_skin_temp_hs2; |
| 122 | mcfg->stt_error_coeff = config->stt_error_coeff; |
| 123 | mcfg->stt_error_rate_coefficient = config->stt_error_rate_coefficient; |
| 124 | |
| 125 | /* all following fields being 0 is a valid config */ |
| 126 | mcfg->stapm_boost = config->stapm_boost; |
Martin Roth | 9c17665 | 2021-04-23 12:24:35 -0600 | [diff] [blame] | 127 | mcfg->stapm_time_constant = config->stapm_time_constant_s; |
Felix Held | d3be9ba | 2021-04-19 21:40:35 +0200 | [diff] [blame] | 128 | mcfg->apu_only_sppt_limit = config->apu_only_sppt_limit; |
Martin Roth | 9c17665 | 2021-04-23 12:24:35 -0600 | [diff] [blame] | 129 | mcfg->sustained_power_limit = config->sustained_power_limit_mW; |
| 130 | mcfg->fast_ppt_limit = config->fast_ppt_limit_mW; |
| 131 | mcfg->slow_ppt_limit = config->slow_ppt_limit_mW; |
Martin Roth | 029d997 | 2021-04-23 12:22:59 -0600 | [diff] [blame] | 132 | mcfg->slow_ppt_time_constant = config->slow_ppt_time_constant_s; |
| 133 | mcfg->thermctl_limit = config->thermctl_limit_degreeC; |
Felix Held | d3be9ba | 2021-04-19 21:40:35 +0200 | [diff] [blame] | 134 | |
| 135 | /* 0 is default */ |
| 136 | mcfg->smartshift_enable = config->smartshift_enable; |
| 137 | |
| 138 | /* 0 is default */ |
| 139 | mcfg->system_configuration = config->system_configuration; |
| 140 | |
| 141 | /* when cppc_ctrl is 0 the other values won't be used */ |
| 142 | mcfg->cppc_ctrl = config->cppc_ctrl; |
| 143 | mcfg->cppc_perf_limit_max_range = config->cppc_perf_limit_max_range; |
| 144 | mcfg->cppc_perf_limit_min_range = config->cppc_perf_limit_min_range; |
| 145 | mcfg->cppc_epp_max_range = config->cppc_epp_max_range; |
| 146 | mcfg->cppc_epp_min_range = config->cppc_epp_min_range; |
| 147 | mcfg->cppc_preferred_cores = config->cppc_preferred_cores; |
| 148 | |
Karthikeyan Ramasubramanian | 5ad85d9 | 2021-04-22 16:59:08 -0600 | [diff] [blame] | 149 | /* S0i3 enable */ |
| 150 | mcfg->s0i3_enable = config->s0ix_enable; |
| 151 | |
Chris Wang | 0679392 | 2021-04-29 00:11:01 +0800 | [diff] [blame] | 152 | /* voltage regulator telemetry settings */ |
| 153 | mcfg->telemetry_vddcrvddfull_scale_current = |
| 154 | config->telemetry_vddcrvddfull_scale_current_mA; |
| 155 | mcfg->telemetry_vddcrvddoffset = |
| 156 | config->telemetry_vddcrvddoffset; |
| 157 | mcfg->telemetry_vddcrsocfull_scale_current = |
| 158 | config->telemetry_vddcrsocfull_scale_current_mA; |
| 159 | mcfg->telemetry_vddcrsocOffset = |
| 160 | config->telemetry_vddcrsocoffset; |
| 161 | |
Felix Held | 9a24c3f | 2021-05-25 20:45:08 +0200 | [diff] [blame] | 162 | /* PCIe power vs. speed */ |
| 163 | mcfg->pspp_policy = config->pspp_policy; |
| 164 | |
Karthikeyan Ramasubramanian | cdbedb6 | 2021-05-10 17:02:58 -0600 | [diff] [blame] | 165 | mcfg->enable_nb_azalia = devtree_gfx_hda_dev_enabled(); |
| 166 | |
Julian Schroeder | d2f3308 | 2021-05-11 10:44:13 -0500 | [diff] [blame] | 167 | if (config->usb_phy_custom) |
| 168 | mcfg->usb_phy = (struct usb_phy_config *)&config->usb_phy; |
| 169 | else |
| 170 | mcfg->usb_phy = NULL; |
| 171 | |
Matt Papageorge | ea0f225 | 2021-03-30 11:41:22 -0500 | [diff] [blame] | 172 | fsp_fill_pcie_ddi_descriptors(mcfg); |
Felix Held | 1ed5a63 | 2021-05-04 21:51:43 +0200 | [diff] [blame] | 173 | fsp_assign_ioapic_upds(mcfg); |
Felix Held | 2421de6 | 2021-03-26 01:13:53 +0100 | [diff] [blame] | 174 | } |