Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | /* TODO: Check if this is still correct */ |
| 4 | |
| 5 | #include <amdblocks/apob_cache.h> |
| 6 | #include <amdblocks/ioapic.h> |
| 7 | #include <amdblocks/memmap.h> |
| 8 | #include <assert.h> |
Felix Held | 7969a5c | 2022-11-29 17:54:18 +0100 | [diff] [blame] | 9 | #include <console/console.h> |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 10 | #include <console/uart.h> |
| 11 | #include <device/device.h> |
| 12 | #include <fsp/api.h> |
| 13 | #include <soc/platform_descriptors.h> |
| 14 | #include <soc/pci_devs.h> |
| 15 | #include <string.h> |
| 16 | #include <types.h> |
Jon Murphy | 4f73242 | 2022-08-05 15:43:44 -0600 | [diff] [blame] | 17 | #include <vendorcode/amd/fsp/mendocino/FspUsb.h> |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 18 | #include "chip.h" |
| 19 | |
Felix Held | 56fa67c | 2022-06-15 21:42:29 +0200 | [diff] [blame] | 20 | __weak void mb_pre_fspm(FSP_M_CONFIG *mcfg) |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 21 | { |
| 22 | } |
| 23 | |
| 24 | static void fill_dxio_descriptors(FSP_M_CONFIG *mcfg, |
| 25 | const fsp_dxio_descriptor *descs, size_t num) |
| 26 | { |
| 27 | size_t i; |
| 28 | |
| 29 | ASSERT_MSG(num <= FSPM_UPD_DXIO_DESCRIPTOR_COUNT, |
| 30 | "Too many DXIO descriptors provided."); |
| 31 | |
| 32 | for (i = 0; i < num; i++) { |
| 33 | memcpy(mcfg->dxio_descriptor[i], &descs[i], sizeof(mcfg->dxio_descriptor[0])); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | static void fill_ddi_descriptors(FSP_M_CONFIG *mcfg, |
| 38 | const fsp_ddi_descriptor *descs, size_t num) |
| 39 | { |
| 40 | size_t i; |
| 41 | |
| 42 | ASSERT_MSG(num <= FSPM_UPD_DDI_DESCRIPTOR_COUNT, |
| 43 | "Too many DDI descriptors provided."); |
| 44 | |
| 45 | for (i = 0; i < num; i++) { |
| 46 | memcpy(&mcfg->ddi_descriptor[i], &descs[i], sizeof(mcfg->ddi_descriptor[0])); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | static void fsp_fill_pcie_ddi_descriptors(FSP_M_CONFIG *mcfg) |
| 51 | { |
Jon Murphy | 2e1d168 | 2022-03-16 07:26:01 -0600 | [diff] [blame] | 52 | const fsp_dxio_descriptor *fsp_dxio = NULL; |
| 53 | const fsp_ddi_descriptor *fsp_ddi = NULL; |
| 54 | size_t num_dxio = 0; |
| 55 | size_t num_ddi = 0; |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 56 | |
| 57 | mainboard_get_dxio_ddi_descriptors(&fsp_dxio, &num_dxio, |
| 58 | &fsp_ddi, &num_ddi); |
| 59 | fill_dxio_descriptors(mcfg, fsp_dxio, num_dxio); |
| 60 | fill_ddi_descriptors(mcfg, fsp_ddi, num_ddi); |
| 61 | } |
| 62 | |
| 63 | static void fsp_assign_ioapic_upds(FSP_M_CONFIG *mcfg) |
| 64 | { |
| 65 | mcfg->gnb_ioapic_base = GNB_IO_APIC_ADDR; |
| 66 | mcfg->gnb_ioapic_id = GNB_IOAPIC_ID; |
| 67 | mcfg->fch_ioapic_id = FCH_IOAPIC_ID; |
| 68 | } |
| 69 | |
| 70 | void platform_fsp_memory_init_params_cb(FSPM_UPD *mupd, uint32_t version) |
| 71 | { |
| 72 | FSP_M_CONFIG *mcfg = &mupd->FspmConfig; |
Jon Murphy | 4f73242 | 2022-08-05 15:43:44 -0600 | [diff] [blame] | 73 | const struct soc_amd_mendocino_config *config = config_of_soc(); |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 74 | |
| 75 | mupd->FspmArchUpd.NvsBufferPtr = (uintptr_t)soc_fill_apob_cache(); |
| 76 | |
| 77 | mcfg->pci_express_base_addr = CONFIG_ECAM_MMCONF_BASE_ADDRESS; |
| 78 | mcfg->tseg_size = CONFIG_SMM_TSEG_SIZE; |
| 79 | mcfg->serial_port_base = uart_platform_base(CONFIG_UART_FOR_CONSOLE); |
| 80 | mcfg->serial_port_use_mmio = CONFIG(DRIVERS_UART_8250MEM); |
| 81 | mcfg->serial_port_baudrate = get_uart_baudrate(); |
| 82 | mcfg->serial_port_refclk = uart_platform_refclk(); |
| 83 | |
| 84 | /* 0 is default */ |
| 85 | mcfg->ccx_down_core_mode = config->downcore_mode; |
| 86 | mcfg->ccx_disable_smt = config->disable_smt; |
| 87 | |
| 88 | /* when stt_control isn't 1, FSP will ignore the other stt values */ |
| 89 | mcfg->stt_control = config->stt_control; |
| 90 | mcfg->stt_pcb_sensor_count = config->stt_pcb_sensor_count; |
| 91 | mcfg->stt_min_limit = config->stt_min_limit; |
| 92 | mcfg->stt_m1 = config->stt_m1; |
| 93 | mcfg->stt_m2 = config->stt_m2; |
| 94 | mcfg->stt_m3 = config->stt_m3; |
| 95 | mcfg->stt_m4 = config->stt_m4; |
| 96 | mcfg->stt_m5 = config->stt_m5; |
| 97 | mcfg->stt_m6 = config->stt_m6; |
| 98 | mcfg->stt_c_apu = config->stt_c_apu; |
| 99 | mcfg->stt_c_gpu = config->stt_c_gpu; |
| 100 | mcfg->stt_c_hs2 = config->stt_c_hs2; |
| 101 | mcfg->stt_alpha_apu = config->stt_alpha_apu; |
| 102 | mcfg->stt_alpha_gpu = config->stt_alpha_gpu; |
| 103 | mcfg->stt_alpha_hs2 = config->stt_alpha_hs2; |
| 104 | mcfg->stt_skin_temp_apu = config->stt_skin_temp_apu; |
| 105 | mcfg->stt_skin_temp_gpu = config->stt_skin_temp_gpu; |
| 106 | mcfg->stt_skin_temp_hs2 = config->stt_skin_temp_hs2; |
| 107 | mcfg->stt_error_coeff = config->stt_error_coeff; |
| 108 | mcfg->stt_error_rate_coefficient = config->stt_error_rate_coefficient; |
| 109 | |
| 110 | /* all following fields being 0 is a valid config */ |
| 111 | mcfg->stapm_boost = config->stapm_boost; |
| 112 | mcfg->stapm_time_constant = config->stapm_time_constant_s; |
| 113 | mcfg->apu_only_sppt_limit = config->apu_only_sppt_limit; |
| 114 | mcfg->sustained_power_limit = config->sustained_power_limit_mW; |
| 115 | mcfg->fast_ppt_limit = config->fast_ppt_limit_mW; |
| 116 | mcfg->slow_ppt_limit = config->slow_ppt_limit_mW; |
| 117 | mcfg->slow_ppt_time_constant = config->slow_ppt_time_constant_s; |
| 118 | mcfg->thermctl_limit = config->thermctl_limit_degreeC; |
| 119 | |
| 120 | /* 0 is default */ |
| 121 | mcfg->smartshift_enable = config->smartshift_enable; |
| 122 | |
| 123 | /* 0 is default */ |
| 124 | mcfg->system_configuration = config->system_configuration; |
| 125 | |
Felix Held | 665476d | 2022-08-03 22:18:18 +0200 | [diff] [blame] | 126 | /* when cppc_ctrl is 0 the other values won't be used */ |
| 127 | mcfg->cppc_ctrl = config->cppc_ctrl; |
| 128 | mcfg->cppc_perf_limit_max_range = config->cppc_perf_limit_max_range; |
| 129 | mcfg->cppc_perf_limit_min_range = config->cppc_perf_limit_min_range; |
| 130 | mcfg->cppc_epp_max_range = config->cppc_epp_max_range; |
| 131 | mcfg->cppc_epp_min_range = config->cppc_epp_min_range; |
| 132 | mcfg->cppc_preferred_cores = config->cppc_preferred_cores; |
| 133 | |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 134 | /* S0i3 enable */ |
| 135 | mcfg->s0i3_enable = config->s0ix_enable; |
| 136 | mcfg->iommu_support = is_devfn_enabled(IOMMU_DEVFN); |
| 137 | |
| 138 | /* voltage regulator telemetry settings */ |
| 139 | mcfg->telemetry_vddcrvddfull_scale_current = |
| 140 | config->telemetry_vddcrvddfull_scale_current_mA; |
| 141 | mcfg->telemetry_vddcrvddoffset = |
| 142 | config->telemetry_vddcrvddoffset; |
| 143 | mcfg->telemetry_vddcrsocfull_scale_current = |
| 144 | config->telemetry_vddcrsocfull_scale_current_mA; |
| 145 | mcfg->telemetry_vddcrsocOffset = |
| 146 | config->telemetry_vddcrsocoffset; |
| 147 | |
| 148 | /* PCIe power vs. speed */ |
| 149 | mcfg->pspp_policy = config->pspp_policy; |
| 150 | |
| 151 | mcfg->enable_nb_azalia = is_dev_enabled(DEV_PTR(gfx_hda)); |
| 152 | mcfg->hda_enable = is_dev_enabled(DEV_PTR(hda)); |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 153 | |
| 154 | if (config->usb_phy_custom) { |
Fred Reitberger | 35f73bc | 2022-05-06 15:51:00 -0400 | [diff] [blame] | 155 | /* devicetree config is const, use local copy */ |
| 156 | static struct usb_phy_config lcl_usb_phy; |
| 157 | lcl_usb_phy = config->usb_phy; |
Felix Held | 75873db | 2022-11-22 17:05:05 +0100 | [diff] [blame] | 158 | lcl_usb_phy.Version_Major = FSP_USB_STRUCT_MAJOR_VERSION; |
| 159 | lcl_usb_phy.Version_Minor = FSP_USB_STRUCT_MINOR_VERSION; |
| 160 | lcl_usb_phy.TableLength = sizeof(struct usb_phy_config); |
Felix Held | 7969a5c | 2022-11-29 17:54:18 +0100 | [diff] [blame] | 161 | if ((uintptr_t)&lcl_usb_phy <= UINT32_MAX) { |
| 162 | mcfg->usb_phy_ptr = (uint32_t)(uintptr_t)&lcl_usb_phy; |
| 163 | } else { |
| 164 | printk(BIOS_ERR, "USB PHY config struct above 4GB; can't pass USB PHY " |
| 165 | "configuration to 32 bit FSP.\n"); |
| 166 | mcfg->usb_phy_ptr = 0; |
| 167 | } |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 168 | } else { |
Felix Held | 7969a5c | 2022-11-29 17:54:18 +0100 | [diff] [blame] | 169 | mcfg->usb_phy_ptr = 0; |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 170 | } |
| 171 | |
Chris.Wang | ad12b4f | 2022-12-28 17:07:48 +0800 | [diff] [blame] | 172 | mcfg->dxio_tx_vboost_enable = config->dxio_tx_vboost_enable; |
Chris Wang | c2059fa | 2023-04-26 19:27:54 +0800 | [diff] [blame] | 173 | mcfg->edp_panel_t8_ms = config->edp_panel_t8_ms; |
Chris Wang | f927026 | 2023-04-26 19:48:05 +0800 | [diff] [blame] | 174 | mcfg->edp_panel_t9_ms = config->edp_panel_t9_ms; |
Chris.Wang | ad12b4f | 2022-12-28 17:07:48 +0800 | [diff] [blame] | 175 | |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 176 | fsp_fill_pcie_ddi_descriptors(mcfg); |
| 177 | fsp_assign_ioapic_upds(mcfg); |
Felix Held | 56fa67c | 2022-06-15 21:42:29 +0200 | [diff] [blame] | 178 | mb_pre_fspm(mcfg); |
Patrick Huang | 509321f | 2023-03-22 13:18:03 +0800 | [diff] [blame] | 179 | |
| 180 | mcfg->fch_usb_3_port_force_gen1 = config->usb3_port_force_gen1.usb3_port_force_gen1_en; |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 181 | } |