Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marshall Dawson | 9df969a | 2017-07-25 18:46:46 -0600 | [diff] [blame] | 2 | |
Kyösti Mälkki | 021c621 | 2021-01-26 11:28:47 +0200 | [diff] [blame] | 3 | #include <amdblocks/acpi.h> |
Michał Żygowski | 5a66202 | 2019-12-02 17:02:00 +0100 | [diff] [blame] | 4 | #include <amdblocks/biosram.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 5 | #include <device/pci_ops.h> |
Marshall Dawson | 18b477e | 2017-09-21 12:27:12 -0600 | [diff] [blame] | 6 | #include <arch/cpu.h> |
Kyösti Mälkki | a963acd | 2019-08-16 20:34:25 +0300 | [diff] [blame] | 7 | #include <arch/romstage.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 8 | #include <acpi/acpi.h> |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 9 | #include <cpu/x86/msr.h> |
| 10 | #include <cpu/x86/mtrr.h> |
Kyösti Mälkki | b2a5f0b | 2019-08-04 19:54:32 +0300 | [diff] [blame] | 11 | #include <cpu/x86/smm.h> |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 12 | #include <cpu/amd/mtrr.h> |
Marshall Dawson | 9df969a | 2017-07-25 18:46:46 -0600 | [diff] [blame] | 13 | #include <cbmem.h> |
Marshall Dawson | 18b477e | 2017-09-21 12:27:12 -0600 | [diff] [blame] | 14 | #include <commonlib/helpers.h> |
Marshall Dawson | 9df969a | 2017-07-25 18:46:46 -0600 | [diff] [blame] | 15 | #include <console/console.h> |
Marshall Dawson | 3e4e4c5 | 2017-11-10 16:08:37 -0700 | [diff] [blame] | 16 | #include <device/device.h> |
Marshall Dawson | 9df969a | 2017-07-25 18:46:46 -0600 | [diff] [blame] | 17 | #include <program_loading.h> |
Marshall Dawson | 8f2a7e0 | 2017-11-01 11:44:48 -0600 | [diff] [blame] | 18 | #include <romstage_handoff.h> |
Daniel Kurtz | c6c8972 | 2018-05-24 17:57:37 -0600 | [diff] [blame] | 19 | #include <elog.h> |
Richard Spiegel | 0ad74ac | 2017-12-08 16:53:29 -0700 | [diff] [blame] | 20 | #include <amdblocks/agesawrapper.h> |
| 21 | #include <amdblocks/agesawrapper_call.h> |
Marshall Dawson | 9df969a | 2017-07-25 18:46:46 -0600 | [diff] [blame] | 22 | #include <soc/northbridge.h> |
Felix Held | dba3229 | 2020-03-31 23:54:44 +0200 | [diff] [blame] | 23 | #include <soc/pci_devs.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 24 | #include <soc/southbridge.h> |
Marshall Dawson | 9df969a | 2017-07-25 18:46:46 -0600 | [diff] [blame] | 25 | #include <amdblocks/psp.h> |
| 26 | |
Elyes HAOUAS | c338507 | 2019-03-21 15:38:06 +0100 | [diff] [blame] | 27 | #include "chip.h" |
| 28 | |
Kyösti Mälkki | 9e591c4 | 2021-01-09 12:37:25 +0200 | [diff] [blame] | 29 | void __weak mainboard_romstage_entry(void) |
Martin Roth | 2c3e3ef | 2018-04-11 16:35:08 -0600 | [diff] [blame] | 30 | { |
| 31 | /* By default, don't do anything */ |
| 32 | } |
| 33 | |
Raul E Rangel | 873b4e7 | 2018-06-12 10:53:55 -0600 | [diff] [blame] | 34 | static void agesa_call(void) |
| 35 | { |
| 36 | post_code(0x37); |
Kyösti Mälkki | 6e512c4 | 2018-06-14 06:57:05 +0300 | [diff] [blame] | 37 | do_agesawrapper(AMD_INIT_RESET, "amdinitreset"); |
Raul E Rangel | 873b4e7 | 2018-06-12 10:53:55 -0600 | [diff] [blame] | 38 | |
| 39 | post_code(0x38); |
| 40 | /* APs will not exit amdinitearly */ |
Kyösti Mälkki | 6e512c4 | 2018-06-14 06:57:05 +0300 | [diff] [blame] | 41 | do_agesawrapper(AMD_INIT_EARLY, "amdinitearly"); |
Raul E Rangel | 873b4e7 | 2018-06-12 10:53:55 -0600 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static void bsp_agesa_call(void) |
| 45 | { |
| 46 | set_ap_entry_ptr(agesa_call); /* indicate the path to the AP */ |
| 47 | agesa_call(); |
| 48 | } |
| 49 | |
Marshall Dawson | 9df969a | 2017-07-25 18:46:46 -0600 | [diff] [blame] | 50 | asmlinkage void car_stage_entry(void) |
| 51 | { |
Marshall Dawson | 18b477e | 2017-09-21 12:27:12 -0600 | [diff] [blame] | 52 | struct postcar_frame pcf; |
| 53 | uintptr_t top_of_ram; |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 54 | msr_t base, mask; |
| 55 | msr_t mtrr_cap = rdmsr(MTRR_CAP_MSR); |
| 56 | int vmtrrs = mtrr_cap.lo & MTRR_CAP_VCNT; |
Kyösti Mälkki | 9e591c4 | 2021-01-09 12:37:25 +0200 | [diff] [blame] | 57 | int s3_resume = acpi_is_wakeup_s3(); |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 58 | int i; |
| 59 | |
Marshall Dawson | 9df969a | 2017-07-25 18:46:46 -0600 | [diff] [blame] | 60 | console_init(); |
| 61 | |
Felix Held | dba3229 | 2020-03-31 23:54:44 +0200 | [diff] [blame] | 62 | soc_enable_psp_early(); |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 63 | if (CONFIG(SOC_AMD_PSP_SELECTABLE_SMU_FW)) |
Felix Held | dba3229 | 2020-03-31 23:54:44 +0200 | [diff] [blame] | 64 | psp_load_named_blob(BLOB_SMU_FW, "smu_fw"); |
Raul E Rangel | 873b4e7 | 2018-06-12 10:53:55 -0600 | [diff] [blame] | 65 | |
Kyösti Mälkki | 9e591c4 | 2021-01-09 12:37:25 +0200 | [diff] [blame] | 66 | mainboard_romstage_entry(); |
Kyösti Mälkki | 7f50afb | 2019-09-11 17:12:26 +0300 | [diff] [blame] | 67 | elog_boot_notify(s3_resume); |
Raul E Rangel | 873b4e7 | 2018-06-12 10:53:55 -0600 | [diff] [blame] | 68 | |
| 69 | bsp_agesa_call(); |
| 70 | |
Marshall Dawson | 8f2a7e0 | 2017-11-01 11:44:48 -0600 | [diff] [blame] | 71 | if (!s3_resume) { |
| 72 | post_code(0x40); |
Kyösti Mälkki | 6e512c4 | 2018-06-14 06:57:05 +0300 | [diff] [blame] | 73 | do_agesawrapper(AMD_INIT_POST, "amdinitpost"); |
Marshall Dawson | 9df969a | 2017-07-25 18:46:46 -0600 | [diff] [blame] | 74 | |
Marshall Dawson | 8f2a7e0 | 2017-11-01 11:44:48 -0600 | [diff] [blame] | 75 | post_code(0x41); |
| 76 | /* |
| 77 | * TODO: This is a hack to work around current AGESA behavior. |
| 78 | * AGESA needs to change to reflect that coreboot owns |
| 79 | * the MTRRs. |
| 80 | * |
| 81 | * After setting up DRAM, AGESA also completes the configuration |
| 82 | * of the MTRRs, setting regions to WB. Anything written to |
Elyes HAOUAS | ba4dbf8 | 2021-01-16 15:02:17 +0100 | [diff] [blame] | 83 | * memory between now and when CAR is dismantled will be |
Marshall Dawson | 8f2a7e0 | 2017-11-01 11:44:48 -0600 | [diff] [blame] | 84 | * in cache and lost. For now, set the regions UC to ensure |
| 85 | * the writes get to DRAM. |
| 86 | */ |
| 87 | for (i = 0 ; i < vmtrrs ; i++) { |
| 88 | base = rdmsr(MTRR_PHYS_BASE(i)); |
| 89 | mask = rdmsr(MTRR_PHYS_MASK(i)); |
| 90 | if (!(mask.lo & MTRR_PHYS_MASK_VALID)) |
| 91 | continue; |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 92 | |
Marshall Dawson | 8f2a7e0 | 2017-11-01 11:44:48 -0600 | [diff] [blame] | 93 | if ((base.lo & 0x7) == MTRR_TYPE_WRBACK) { |
| 94 | base.lo &= ~0x7; |
| 95 | base.lo |= MTRR_TYPE_UNCACHEABLE; |
| 96 | wrmsr(MTRR_PHYS_BASE(i), base); |
| 97 | } |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 98 | } |
Marshall Dawson | 8f2a7e0 | 2017-11-01 11:44:48 -0600 | [diff] [blame] | 99 | /* Disable WB from to region 4GB-TOM2. */ |
| 100 | msr_t sys_cfg = rdmsr(SYSCFG_MSR); |
| 101 | sys_cfg.lo &= ~SYSCFG_MSR_TOM2WB; |
| 102 | wrmsr(SYSCFG_MSR, sys_cfg); |
| 103 | } else { |
| 104 | printk(BIOS_INFO, "S3 detected\n"); |
| 105 | post_code(0x60); |
Kyösti Mälkki | 6e512c4 | 2018-06-14 06:57:05 +0300 | [diff] [blame] | 106 | do_agesawrapper(AMD_INIT_RESUME, "amdinitresume"); |
Marshall Dawson | 8f2a7e0 | 2017-11-01 11:44:48 -0600 | [diff] [blame] | 107 | |
| 108 | post_code(0x61); |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 109 | } |
Marshall Dawson | 9df969a | 2017-07-25 18:46:46 -0600 | [diff] [blame] | 110 | |
| 111 | post_code(0x42); |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 112 | psp_notify_dram(); |
| 113 | |
| 114 | post_code(0x43); |
Marshall Dawson | 8f2a7e0 | 2017-11-01 11:44:48 -0600 | [diff] [blame] | 115 | if (cbmem_recovery(s3_resume)) |
| 116 | printk(BIOS_CRIT, "Failed to recover cbmem\n"); |
| 117 | if (romstage_handoff_init(s3_resume)) |
| 118 | printk(BIOS_ERR, "Failed to set romstage handoff data\n"); |
Marshall Dawson | 9df969a | 2017-07-25 18:46:46 -0600 | [diff] [blame] | 119 | |
Kyösti Mälkki | 7cdb047 | 2019-08-08 11:16:06 +0300 | [diff] [blame] | 120 | if (CONFIG(SMM_TSEG)) |
| 121 | smm_list_regions(); |
| 122 | |
Marshall Dawson | 18b477e | 2017-09-21 12:27:12 -0600 | [diff] [blame] | 123 | post_code(0x44); |
Kyösti Mälkki | 6e2d0c1 | 2019-06-28 10:08:51 +0300 | [diff] [blame] | 124 | if (postcar_frame_init(&pcf, 0)) |
Marshall Dawson | 18b477e | 2017-09-21 12:27:12 -0600 | [diff] [blame] | 125 | die("Unable to initialize postcar frame.\n"); |
| 126 | |
Marshall Dawson | 9df969a | 2017-07-25 18:46:46 -0600 | [diff] [blame] | 127 | /* |
Marshall Dawson | 18b477e | 2017-09-21 12:27:12 -0600 | [diff] [blame] | 128 | * We need to make sure ramstage will be run cached. At this point exact |
| 129 | * location of ramstage in cbmem is not known. Instruct postcar to cache |
| 130 | * 16 megs under cbmem top which is a safe bet to cover ramstage. |
Marshall Dawson | 9df969a | 2017-07-25 18:46:46 -0600 | [diff] [blame] | 131 | */ |
Marshall Dawson | 18b477e | 2017-09-21 12:27:12 -0600 | [diff] [blame] | 132 | top_of_ram = (uintptr_t) cbmem_top(); |
Marshall Dawson | 18b477e | 2017-09-21 12:27:12 -0600 | [diff] [blame] | 133 | postcar_frame_add_mtrr(&pcf, top_of_ram - 16*MiB, 16*MiB, |
| 134 | MTRR_TYPE_WRBACK); |
Marshall Dawson | 9df969a | 2017-07-25 18:46:46 -0600 | [diff] [blame] | 135 | |
Marshall Dawson | 18b477e | 2017-09-21 12:27:12 -0600 | [diff] [blame] | 136 | /* Cache the memory-mapped boot media. */ |
Nico Huber | 6ea6775 | 2018-05-27 14:37:52 +0200 | [diff] [blame] | 137 | postcar_frame_add_romcache(&pcf, MTRR_TYPE_WRPROT); |
Marshall Dawson | 9df969a | 2017-07-25 18:46:46 -0600 | [diff] [blame] | 138 | |
Subrata Banik | 3eff037 | 2019-09-10 15:51:17 +0530 | [diff] [blame] | 139 | /* Cache the TSEG region */ |
| 140 | postcar_enable_tseg_cache(&pcf); |
Marshall Dawson | 18b477e | 2017-09-21 12:27:12 -0600 | [diff] [blame] | 141 | |
| 142 | post_code(0x45); |
| 143 | run_postcar_phase(&pcf); |
| 144 | |
| 145 | post_code(0x50); /* Should never see this post code. */ |
Marshall Dawson | 9df969a | 2017-07-25 18:46:46 -0600 | [diff] [blame] | 146 | } |
Richard Spiegel | 67c2a7b | 2017-11-09 16:04:35 -0700 | [diff] [blame] | 147 | |
| 148 | void SetMemParams(AMD_POST_PARAMS *PostParams) |
| 149 | { |
| 150 | const struct soc_amd_stoneyridge_config *cfg; |
Kyösti Mälkki | e737755 | 2018-06-21 16:20:55 +0300 | [diff] [blame] | 151 | const struct device *dev = pcidev_path_on_root(GNB_DEVFN); |
Richard Spiegel | 67c2a7b | 2017-11-09 16:04:35 -0700 | [diff] [blame] | 152 | |
| 153 | if (!dev || !dev->chip_info) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 154 | printk(BIOS_ERR, "Cannot find SoC devicetree config\n"); |
Aaron Durbin | 36dbf1d | 2017-11-10 13:16:23 -0700 | [diff] [blame] | 155 | /* In case of a BIOS error, only attempt to set UMA. */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 156 | PostParams->MemConfig.UmaMode = CONFIG(GFXUMA) ? |
Aaron Durbin | 36dbf1d | 2017-11-10 13:16:23 -0700 | [diff] [blame] | 157 | UMA_AUTO : UMA_NONE; |
Richard Spiegel | 67c2a7b | 2017-11-09 16:04:35 -0700 | [diff] [blame] | 158 | return; |
| 159 | } |
| 160 | |
| 161 | cfg = dev->chip_info; |
Aaron Durbin | 36dbf1d | 2017-11-10 13:16:23 -0700 | [diff] [blame] | 162 | |
Richard Spiegel | 67c2a7b | 2017-11-09 16:04:35 -0700 | [diff] [blame] | 163 | PostParams->MemConfig.EnableMemClr = cfg->dram_clear_on_reset; |
Aaron Durbin | 36dbf1d | 2017-11-10 13:16:23 -0700 | [diff] [blame] | 164 | |
| 165 | switch (cfg->uma_mode) { |
| 166 | case UMAMODE_NONE: |
| 167 | PostParams->MemConfig.UmaMode = UMA_NONE; |
| 168 | break; |
| 169 | case UMAMODE_SPECIFIED_SIZE: |
| 170 | PostParams->MemConfig.UmaMode = UMA_SPECIFIED; |
| 171 | /* 64 KiB blocks. */ |
| 172 | PostParams->MemConfig.UmaSize = cfg->uma_size / (64 * KiB); |
| 173 | break; |
| 174 | case UMAMODE_AUTO_LEGACY: |
| 175 | PostParams->MemConfig.UmaMode = UMA_AUTO; |
| 176 | PostParams->MemConfig.UmaVersion = UMA_LEGACY; |
| 177 | break; |
| 178 | case UMAMODE_AUTO_NON_LEGACY: |
| 179 | PostParams->MemConfig.UmaMode = UMA_AUTO; |
| 180 | PostParams->MemConfig.UmaVersion = UMA_NON_LEGACY; |
| 181 | break; |
| 182 | } |
Richard Spiegel | 67c2a7b | 2017-11-09 16:04:35 -0700 | [diff] [blame] | 183 | } |
Richard Spiegel | dd9b1d1 | 2018-09-20 14:50:11 -0700 | [diff] [blame] | 184 | |
| 185 | void soc_customize_init_early(AMD_EARLY_PARAMS *InitEarly) |
| 186 | { |
| 187 | const struct soc_amd_stoneyridge_config *cfg; |
Kyösti Mälkki | e737755 | 2018-06-21 16:20:55 +0300 | [diff] [blame] | 188 | const struct device *dev = pcidev_path_on_root(GNB_DEVFN); |
Richard Spiegel | dd9b1d1 | 2018-09-20 14:50:11 -0700 | [diff] [blame] | 189 | struct _PLATFORM_CONFIGURATION *platform; |
| 190 | |
| 191 | if (!dev || !dev->chip_info) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 192 | printk(BIOS_WARNING, "Cannot find SoC devicetree" |
Richard Spiegel | dd9b1d1 | 2018-09-20 14:50:11 -0700 | [diff] [blame] | 193 | " config, STAPM unchanged\n"); |
| 194 | return; |
| 195 | } |
| 196 | cfg = dev->chip_info; |
| 197 | platform = &InitEarly->PlatformConfig; |
Richard Spiegel | de5d040 | 2018-10-11 08:15:43 -0700 | [diff] [blame] | 198 | if ((cfg->stapm_percent) && (cfg->stapm_time_ms) && |
| 199 | (cfg->stapm_power_mw)) { |
Richard Spiegel | dd9b1d1 | 2018-09-20 14:50:11 -0700 | [diff] [blame] | 200 | platform->PlatStapmConfig.CfgStapmScalar = cfg->stapm_percent; |
| 201 | platform->PlatStapmConfig.CfgStapmTimeConstant = |
Richard Spiegel | de5d040 | 2018-10-11 08:15:43 -0700 | [diff] [blame] | 202 | cfg->stapm_time_ms; |
| 203 | platform->PkgPwrLimitDC = cfg->stapm_power_mw; |
| 204 | platform->PkgPwrLimitAC = cfg->stapm_power_mw; |
Richard Spiegel | dd9b1d1 | 2018-09-20 14:50:11 -0700 | [diff] [blame] | 205 | platform->PlatStapmConfig.CfgStapmBoost = StapmBoostEnabled; |
| 206 | } |
| 207 | } |
Kyösti Mälkki | 021c621 | 2021-01-26 11:28:47 +0200 | [diff] [blame] | 208 | |
| 209 | static void migrate_power_state(int is_recovery) |
| 210 | { |
| 211 | struct chipset_power_state *state; |
| 212 | state = cbmem_add(CBMEM_ID_POWER_STATE, sizeof(*state)); |
| 213 | if (state) { |
| 214 | acpi_fill_pm_gpe_state(&state->gpe_state); |
| 215 | acpi_pm_gpe_add_events_print_events(); |
| 216 | } |
Kyösti Mälkki | 021c621 | 2021-01-26 11:28:47 +0200 | [diff] [blame] | 217 | } |
| 218 | ROMSTAGE_CBMEM_INIT_HOOK(migrate_power_state) |