Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 2 | |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 3 | #include <amdblocks/biosram.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 4 | #include <acpi/acpi.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 5 | #include <arch/cpu.h> |
Kyösti Mälkki | a963acd | 2019-08-16 20:34:25 +0300 | [diff] [blame] | 6 | #include <arch/romstage.h> |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 7 | #include <cbmem.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 8 | #include <console/console.h> |
Arthur Heymans | 78ab06a | 2021-05-29 06:58:38 +0200 | [diff] [blame] | 9 | #include <cpu/x86/lapic.h> |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 10 | #include <halt.h> |
| 11 | #include <program_loading.h> |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 12 | #include <romstage_handoff.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 13 | #include <smp/node.h> |
| 14 | #include <string.h> |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 15 | #include <timestamp.h> |
Arthur Heymans | bab9e2e | 2021-05-29 07:30:33 +0200 | [diff] [blame] | 16 | #include <romstage_common.h> |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 17 | #include <northbridge/amd/agesa/agesa_helper.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 18 | #include <northbridge/amd/agesa/state_machine.h> |
| 19 | |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 20 | void __weak board_BeforeAgesa(struct sysinfo *cb) { } |
| 21 | |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 22 | static void fill_sysinfo(struct sysinfo *cb) |
| 23 | { |
| 24 | memset(cb, 0, sizeof(*cb)); |
| 25 | cb->s3resume = acpi_is_wakeup_s3(); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 26 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 27 | agesa_set_interface(cb); |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 28 | } |
| 29 | |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 30 | /* APs will enter directly here from bootblock, bypassing verstage |
| 31 | * and potential fallback / normal bootflow detection. |
| 32 | */ |
| 33 | static void ap_romstage_main(void); |
| 34 | |
Arthur Heymans | bab9e2e | 2021-05-29 07:30:33 +0200 | [diff] [blame] | 35 | void __noreturn romstage_main(void) |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 36 | { |
| 37 | struct sysinfo romstage_state; |
| 38 | struct sysinfo *cb = &romstage_state; |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 39 | int cbmem_initted = 0; |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 40 | |
Arthur Heymans | 78ab06a | 2021-05-29 06:58:38 +0200 | [diff] [blame] | 41 | printk(BIOS_DEBUG, "APIC %02u: CPU Family_Model = %08x\n", |
Arthur Heymans | b0b12dd | 2021-05-29 07:08:36 +0200 | [diff] [blame] | 42 | initial_lapicid(), cpuid_eax(1)); |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 43 | |
Arthur Heymans | a552cfc | 2021-05-29 07:11:10 +0200 | [diff] [blame] | 44 | fill_sysinfo(cb); |
| 45 | |
| 46 | board_BeforeAgesa(cb); |
| 47 | |
Kyösti Mälkki | 520717d | 2019-12-15 21:37:48 +0200 | [diff] [blame] | 48 | set_ap_entry_ptr(ap_romstage_main); |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 49 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 50 | agesa_execute_state(cb, AMD_INIT_RESET); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 51 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 52 | agesa_execute_state(cb, AMD_INIT_EARLY); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 53 | |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 54 | timestamp_add_now(TS_INITRAM_START); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 55 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 56 | if (!cb->s3resume) |
| 57 | agesa_execute_state(cb, AMD_INIT_POST); |
| 58 | else |
| 59 | agesa_execute_state(cb, AMD_INIT_RESUME); |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 60 | |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 61 | timestamp_add_now(TS_INITRAM_END); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 62 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 63 | /* Work around AGESA setting all memory as WB on normal |
| 64 | * boot path. |
| 65 | */ |
| 66 | fixup_cbmem_to_UC(cb->s3resume); |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 67 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 68 | cbmem_initted = !cbmem_recovery(cb->s3resume); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 69 | |
| 70 | if (cb->s3resume && !cbmem_initted) { |
| 71 | printk(BIOS_EMERG, "Unable to recover CBMEM\n"); |
| 72 | halt(); |
| 73 | } |
| 74 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 75 | romstage_handoff_init(cb->s3resume); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 76 | |
Arthur Heymans | 876a1b4 | 2022-02-15 11:06:10 +0100 | [diff] [blame] | 77 | prepare_and_run_postcar(); |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 78 | /* We do not return. */ |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 79 | } |
| 80 | |
Kyösti Mälkki | 33d0fb8 | 2019-11-29 06:38:46 +0200 | [diff] [blame] | 81 | static void ap_romstage_main(void) |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 82 | { |
| 83 | struct sysinfo romstage_state; |
| 84 | struct sysinfo *cb = &romstage_state; |
| 85 | |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 86 | fill_sysinfo(cb); |
| 87 | |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 88 | agesa_execute_state(cb, AMD_INIT_RESET); |
| 89 | |
| 90 | agesa_execute_state(cb, AMD_INIT_EARLY); |
| 91 | |
| 92 | /* Not reached. */ |
| 93 | halt(); |
| 94 | } |
Kyösti Mälkki | 33d0fb8 | 2019-11-29 06:38:46 +0200 | [diff] [blame] | 95 | |
Kyösti Mälkki | 2446c1e | 2020-07-09 07:13:37 +0300 | [diff] [blame] | 96 | void *cbmem_top_chipset(void) |
| 97 | { |
| 98 | /* Top of CBMEM is at highest usable DRAM address below 4GiB. */ |
| 99 | return (void *)restore_top_of_low_cacheable(); |
| 100 | } |