blob: fc918f916f340e1ce2c5473635716771412b4a19 [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marshall Dawson9df969a2017-07-25 18:46:46 -06002
Arthur Heymansbab9e2e2021-05-29 07:30:33 +02003#include <acpi/acpi.h>
Kyösti Mälkki021c6212021-01-26 11:28:47 +02004#include <amdblocks/acpi.h>
Arthur Heymansbab9e2e2021-05-29 07:30:33 +02005#include <amdblocks/agesawrapper_call.h>
Elyes Haouasf743e0c2022-10-31 13:46:00 +01006#include <amdblocks/agesawrapper.h>
Michał Żygowski5a662022019-12-02 17:02:00 +01007#include <amdblocks/biosram.h>
Martin Roth81804272022-11-20 20:30:18 -07008#include <amdblocks/post_codes.h>
Arthur Heymansbab9e2e2021-05-29 07:30:33 +02009#include <amdblocks/psp.h>
Kyösti Mälkkia963acd2019-08-16 20:34:25 +030010#include <arch/romstage.h>
Marshall Dawson9df969a2017-07-25 18:46:46 -060011#include <cbmem.h>
Marshall Dawson18b477e2017-09-21 12:27:12 -060012#include <commonlib/helpers.h>
Marshall Dawson9df969a2017-07-25 18:46:46 -060013#include <console/console.h>
Arthur Heymansbab9e2e2021-05-29 07:30:33 +020014#include <cpu/amd/mtrr.h>
Elyes Haouasf743e0c2022-10-31 13:46:00 +010015#include <cpu/cpu.h>
Arthur Heymansbab9e2e2021-05-29 07:30:33 +020016#include <cpu/x86/msr.h>
17#include <cpu/x86/mtrr.h>
18#include <cpu/x86/smm.h>
Marshall Dawson3e4e4c52017-11-10 16:08:37 -070019#include <device/device.h>
Arthur Heymansbab9e2e2021-05-29 07:30:33 +020020#include <device/pci_ops.h>
Daniel Kurtzc6c89722018-05-24 17:57:37 -060021#include <elog.h>
Arthur Heymansbab9e2e2021-05-29 07:30:33 +020022#include <program_loading.h>
23#include <romstage_common.h>
24#include <romstage_handoff.h>
Felix Held4892d732023-03-03 16:08:57 +010025#include <soc/iomap.h>
Marshall Dawson9df969a2017-07-25 18:46:46 -060026#include <soc/northbridge.h>
Felix Helddba32292020-03-31 23:54:44 +020027#include <soc/pci_devs.h>
Marc Jonesdfeb1c42017-08-07 19:08:24 -060028#include <soc/southbridge.h>
Arthur Heymans796147f2022-02-15 10:59:41 +010029#include <stdint.h>
Marshall Dawson9df969a2017-07-25 18:46:46 -060030
Elyes HAOUASc3385072019-03-21 15:38:06 +010031#include "chip.h"
32
Kyösti Mälkki9e591c42021-01-09 12:37:25 +020033void __weak mainboard_romstage_entry(void)
Martin Roth2c3e3ef2018-04-11 16:35:08 -060034{
35 /* By default, don't do anything */
36}
37
Raul E Rangel873b4e72018-06-12 10:53:55 -060038static void agesa_call(void)
39{
Yuchen He1e67adb2023-07-25 21:28:36 +020040 post_code(POSTCODE_AGESA_AMDINITRESET);
Kyösti Mälkki6e512c42018-06-14 06:57:05 +030041 do_agesawrapper(AMD_INIT_RESET, "amdinitreset");
Raul E Rangel873b4e72018-06-12 10:53:55 -060042
Yuchen He1e67adb2023-07-25 21:28:36 +020043 post_code(POSTCODE_AGESA_AMDINITEARLY);
Raul E Rangel873b4e72018-06-12 10:53:55 -060044 /* APs will not exit amdinitearly */
Kyösti Mälkki6e512c42018-06-14 06:57:05 +030045 do_agesawrapper(AMD_INIT_EARLY, "amdinitearly");
Raul E Rangel873b4e72018-06-12 10:53:55 -060046}
47
48static void bsp_agesa_call(void)
49{
50 set_ap_entry_ptr(agesa_call); /* indicate the path to the AP */
51 agesa_call();
52}
Arthur Heymansbab9e2e2021-05-29 07:30:33 +020053void __noreturn romstage_main(void)
Marshall Dawson9df969a2017-07-25 18:46:46 -060054{
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060055 msr_t base, mask;
56 msr_t mtrr_cap = rdmsr(MTRR_CAP_MSR);
57 int vmtrrs = mtrr_cap.lo & MTRR_CAP_VCNT;
Kyösti Mälkki9e591c42021-01-09 12:37:25 +020058 int s3_resume = acpi_is_wakeup_s3();
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060059 int i;
60
Felix Helddba32292020-03-31 23:54:44 +020061 soc_enable_psp_early();
Julius Wernercd49cce2019-03-05 16:53:33 -080062 if (CONFIG(SOC_AMD_PSP_SELECTABLE_SMU_FW))
Felix Helddba32292020-03-31 23:54:44 +020063 psp_load_named_blob(BLOB_SMU_FW, "smu_fw");
Raul E Rangel873b4e72018-06-12 10:53:55 -060064
Kyösti Mälkki9e591c42021-01-09 12:37:25 +020065 mainboard_romstage_entry();
Kyösti Mälkki7f50afb2019-09-11 17:12:26 +030066 elog_boot_notify(s3_resume);
Raul E Rangel873b4e72018-06-12 10:53:55 -060067
68 bsp_agesa_call();
69
Marshall Dawson8f2a7e02017-11-01 11:44:48 -060070 if (!s3_resume) {
Yuchen He1e67adb2023-07-25 21:28:36 +020071 post_code(POSTCODE_AGESA_AMDINITPOST);
Kyösti Mälkki6e512c42018-06-14 06:57:05 +030072 do_agesawrapper(AMD_INIT_POST, "amdinitpost");
Marshall Dawson9df969a2017-07-25 18:46:46 -060073
Yuchen He1e67adb2023-07-25 21:28:36 +020074 post_code(POSTCODE_AGESA_AMDINITPOST_DONE);
Marshall Dawson8f2a7e02017-11-01 11:44:48 -060075 /*
76 * TODO: This is a hack to work around current AGESA behavior.
77 * AGESA needs to change to reflect that coreboot owns
78 * the MTRRs.
79 *
80 * After setting up DRAM, AGESA also completes the configuration
81 * of the MTRRs, setting regions to WB. Anything written to
Elyes HAOUASba4dbf82021-01-16 15:02:17 +010082 * memory between now and when CAR is dismantled will be
Marshall Dawson8f2a7e02017-11-01 11:44:48 -060083 * in cache and lost. For now, set the regions UC to ensure
84 * the writes get to DRAM.
85 */
86 for (i = 0 ; i < vmtrrs ; i++) {
87 base = rdmsr(MTRR_PHYS_BASE(i));
88 mask = rdmsr(MTRR_PHYS_MASK(i));
89 if (!(mask.lo & MTRR_PHYS_MASK_VALID))
90 continue;
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060091
Marshall Dawson8f2a7e02017-11-01 11:44:48 -060092 if ((base.lo & 0x7) == MTRR_TYPE_WRBACK) {
93 base.lo &= ~0x7;
94 base.lo |= MTRR_TYPE_UNCACHEABLE;
95 wrmsr(MTRR_PHYS_BASE(i), base);
96 }
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060097 }
Marshall Dawson8f2a7e02017-11-01 11:44:48 -060098 /* Disable WB from to region 4GB-TOM2. */
99 msr_t sys_cfg = rdmsr(SYSCFG_MSR);
100 sys_cfg.lo &= ~SYSCFG_MSR_TOM2WB;
101 wrmsr(SYSCFG_MSR, sys_cfg);
102 } else {
103 printk(BIOS_INFO, "S3 detected\n");
Yuchen He1e67adb2023-07-25 21:28:36 +0200104 post_code(POSTCODE_AGESA_AMDINITRESUME);
Kyösti Mälkki6e512c42018-06-14 06:57:05 +0300105 do_agesawrapper(AMD_INIT_RESUME, "amdinitresume");
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600106
Yuchen He1e67adb2023-07-25 21:28:36 +0200107 post_code(POSTCODE_AGESA_AMDINITRESUME_DONE);
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -0600108 }
Marshall Dawson9df969a2017-07-25 18:46:46 -0600109
Yuchen He1e67adb2023-07-25 21:28:36 +0200110 post_code(POSTCODE_PSP_NOTIFY_DRAM);
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -0600111 psp_notify_dram();
112
Yuchen He1e67adb2023-07-25 21:28:36 +0200113 post_code(POSTCODE_PSP_NOTIFY_DRAM_DONE);
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600114 if (cbmem_recovery(s3_resume))
115 printk(BIOS_CRIT, "Failed to recover cbmem\n");
116 if (romstage_handoff_init(s3_resume))
117 printk(BIOS_ERR, "Failed to set romstage handoff data\n");
Marshall Dawson9df969a2017-07-25 18:46:46 -0600118
Kyösti Mälkki7cdb0472019-08-08 11:16:06 +0300119 if (CONFIG(SMM_TSEG))
120 smm_list_regions();
121
Yuchen He1e67adb2023-07-25 21:28:36 +0200122 post_code(POSTCODE_ROMSTAGE_RUN_POSTCAR);
Arthur Heymans876a1b42022-02-15 11:06:10 +0100123 prepare_and_run_postcar();
Arthur Heymans796147f2022-02-15 10:59:41 +0100124}
Marshall Dawson18b477e2017-09-21 12:27:12 -0600125
Arthur Heymans796147f2022-02-15 10:59:41 +0100126void fill_postcar_frame(struct postcar_frame *pcf)
127{
128 uintptr_t top_of_ram = (uintptr_t)cbmem_top();
129 postcar_frame_add_mtrr(pcf, top_of_ram - 16 * MiB, 16 * MiB, MTRR_TYPE_WRBACK);
Marshall Dawson9df969a2017-07-25 18:46:46 -0600130
Subrata Banik3eff0372019-09-10 15:51:17 +0530131 /* Cache the TSEG region */
Arthur Heymans796147f2022-02-15 10:59:41 +0100132 postcar_enable_tseg_cache(pcf);
Marshall Dawson9df969a2017-07-25 18:46:46 -0600133}
Richard Spiegel67c2a7b2017-11-09 16:04:35 -0700134
135void SetMemParams(AMD_POST_PARAMS *PostParams)
136{
137 const struct soc_amd_stoneyridge_config *cfg;
Kyösti Mälkkie7377552018-06-21 16:20:55 +0300138 const struct device *dev = pcidev_path_on_root(GNB_DEVFN);
Richard Spiegel67c2a7b2017-11-09 16:04:35 -0700139
140 if (!dev || !dev->chip_info) {
Julius Wernere9665952022-01-21 17:06:20 -0800141 printk(BIOS_ERR, "Cannot find SoC devicetree config\n");
Aaron Durbin36dbf1d2017-11-10 13:16:23 -0700142 /* In case of a BIOS error, only attempt to set UMA. */
Julius Wernercd49cce2019-03-05 16:53:33 -0800143 PostParams->MemConfig.UmaMode = CONFIG(GFXUMA) ?
Aaron Durbin36dbf1d2017-11-10 13:16:23 -0700144 UMA_AUTO : UMA_NONE;
Richard Spiegel67c2a7b2017-11-09 16:04:35 -0700145 return;
146 }
147
148 cfg = dev->chip_info;
Aaron Durbin36dbf1d2017-11-10 13:16:23 -0700149
Richard Spiegel67c2a7b2017-11-09 16:04:35 -0700150 PostParams->MemConfig.EnableMemClr = cfg->dram_clear_on_reset;
Aaron Durbin36dbf1d2017-11-10 13:16:23 -0700151
152 switch (cfg->uma_mode) {
153 case UMAMODE_NONE:
154 PostParams->MemConfig.UmaMode = UMA_NONE;
155 break;
156 case UMAMODE_SPECIFIED_SIZE:
157 PostParams->MemConfig.UmaMode = UMA_SPECIFIED;
158 /* 64 KiB blocks. */
159 PostParams->MemConfig.UmaSize = cfg->uma_size / (64 * KiB);
160 break;
161 case UMAMODE_AUTO_LEGACY:
162 PostParams->MemConfig.UmaMode = UMA_AUTO;
163 PostParams->MemConfig.UmaVersion = UMA_LEGACY;
164 break;
165 case UMAMODE_AUTO_NON_LEGACY:
166 PostParams->MemConfig.UmaMode = UMA_AUTO;
167 PostParams->MemConfig.UmaVersion = UMA_NON_LEGACY;
168 break;
169 }
Richard Spiegel67c2a7b2017-11-09 16:04:35 -0700170}
Richard Spiegeldd9b1d12018-09-20 14:50:11 -0700171
172void soc_customize_init_early(AMD_EARLY_PARAMS *InitEarly)
173{
174 const struct soc_amd_stoneyridge_config *cfg;
Kyösti Mälkkie7377552018-06-21 16:20:55 +0300175 const struct device *dev = pcidev_path_on_root(GNB_DEVFN);
Richard Spiegeldd9b1d12018-09-20 14:50:11 -0700176 struct _PLATFORM_CONFIGURATION *platform;
177
178 if (!dev || !dev->chip_info) {
Julius Wernere9665952022-01-21 17:06:20 -0800179 printk(BIOS_WARNING, "Cannot find SoC devicetree"
Richard Spiegeldd9b1d12018-09-20 14:50:11 -0700180 " config, STAPM unchanged\n");
181 return;
182 }
183 cfg = dev->chip_info;
184 platform = &InitEarly->PlatformConfig;
Richard Spiegelde5d0402018-10-11 08:15:43 -0700185 if ((cfg->stapm_percent) && (cfg->stapm_time_ms) &&
186 (cfg->stapm_power_mw)) {
Richard Spiegeldd9b1d12018-09-20 14:50:11 -0700187 platform->PlatStapmConfig.CfgStapmScalar = cfg->stapm_percent;
188 platform->PlatStapmConfig.CfgStapmTimeConstant =
Richard Spiegelde5d0402018-10-11 08:15:43 -0700189 cfg->stapm_time_ms;
190 platform->PkgPwrLimitDC = cfg->stapm_power_mw;
191 platform->PkgPwrLimitAC = cfg->stapm_power_mw;
Richard Spiegeldd9b1d12018-09-20 14:50:11 -0700192 platform->PlatStapmConfig.CfgStapmBoost = StapmBoostEnabled;
193 }
Felix Held4892d732023-03-03 16:08:57 +0100194
195 /* Make binaryPi use ACPI_CSTATE_CONTROL as C state control IO range. It gets written
196 into MSR_CSTATE_ADDRESS and used in the _CST packages in the PSTATE SSDT. */
197 platform->CStateIoBaseAddress = ACPI_CSTATE_CONTROL;
Richard Spiegeldd9b1d12018-09-20 14:50:11 -0700198}
Kyösti Mälkki021c6212021-01-26 11:28:47 +0200199
200static void migrate_power_state(int is_recovery)
201{
202 struct chipset_power_state *state;
203 state = cbmem_add(CBMEM_ID_POWER_STATE, sizeof(*state));
204 if (state) {
205 acpi_fill_pm_gpe_state(&state->gpe_state);
206 acpi_pm_gpe_add_events_print_events();
207 }
Kyösti Mälkki021c6212021-01-26 11:28:47 +0200208}
Kyösti Mälkkifa3bc042022-03-31 07:40:10 +0300209CBMEM_CREATION_HOOK(migrate_power_state);