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> |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 16 | #include <northbridge/amd/agesa/agesa_helper.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 17 | #include <northbridge/amd/agesa/state_machine.h> |
| 18 | |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 19 | void __weak board_BeforeAgesa(struct sysinfo *cb) { } |
| 20 | |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 21 | static void fill_sysinfo(struct sysinfo *cb) |
| 22 | { |
| 23 | memset(cb, 0, sizeof(*cb)); |
| 24 | cb->s3resume = acpi_is_wakeup_s3(); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 25 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 26 | agesa_set_interface(cb); |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 27 | } |
| 28 | |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 29 | /* APs will enter directly here from bootblock, bypassing verstage |
| 30 | * and potential fallback / normal bootflow detection. |
| 31 | */ |
| 32 | static void ap_romstage_main(void); |
| 33 | |
Kyösti Mälkki | 33d0fb8 | 2019-11-29 06:38:46 +0200 | [diff] [blame] | 34 | static void romstage_main(void) |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 35 | { |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 36 | struct postcar_frame pcf; |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 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 | |
| 41 | fill_sysinfo(cb); |
| 42 | |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 43 | timestamp_add_now(TS_ROMSTAGE_START); |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 44 | |
Arthur Heymans | b0b12dd | 2021-05-29 07:08:36 +0200 | [diff] [blame] | 45 | board_BeforeAgesa(cb); |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 46 | |
Arthur Heymans | b0b12dd | 2021-05-29 07:08:36 +0200 | [diff] [blame] | 47 | console_init(); |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 48 | |
Arthur Heymans | 78ab06a | 2021-05-29 06:58:38 +0200 | [diff] [blame] | 49 | printk(BIOS_DEBUG, "APIC %02u: CPU Family_Model = %08x\n", |
Arthur Heymans | b0b12dd | 2021-05-29 07:08:36 +0200 | [diff] [blame] | 50 | initial_lapicid(), cpuid_eax(1)); |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 51 | |
Kyösti Mälkki | 520717d | 2019-12-15 21:37:48 +0200 | [diff] [blame] | 52 | set_ap_entry_ptr(ap_romstage_main); |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 53 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 54 | agesa_execute_state(cb, AMD_INIT_RESET); |
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 | agesa_execute_state(cb, AMD_INIT_EARLY); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 57 | |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 58 | timestamp_add_now(TS_INITRAM_START); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 59 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 60 | if (!cb->s3resume) |
| 61 | agesa_execute_state(cb, AMD_INIT_POST); |
| 62 | else |
| 63 | agesa_execute_state(cb, AMD_INIT_RESUME); |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 64 | |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 65 | timestamp_add_now(TS_INITRAM_END); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 66 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 67 | /* Work around AGESA setting all memory as WB on normal |
| 68 | * boot path. |
| 69 | */ |
| 70 | fixup_cbmem_to_UC(cb->s3resume); |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 71 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 72 | cbmem_initted = !cbmem_recovery(cb->s3resume); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 73 | |
| 74 | if (cb->s3resume && !cbmem_initted) { |
| 75 | printk(BIOS_EMERG, "Unable to recover CBMEM\n"); |
| 76 | halt(); |
| 77 | } |
| 78 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 79 | romstage_handoff_init(cb->s3resume); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 80 | |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 81 | postcar_frame_init(&pcf, HIGH_ROMSTAGE_STACK_SIZE); |
| 82 | recover_postcar_frame(&pcf, cb->s3resume); |
| 83 | |
| 84 | run_postcar_phase(&pcf); |
| 85 | /* We do not return. */ |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 86 | } |
| 87 | |
Kyösti Mälkki | 33d0fb8 | 2019-11-29 06:38:46 +0200 | [diff] [blame] | 88 | static void ap_romstage_main(void) |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 89 | { |
| 90 | struct sysinfo romstage_state; |
| 91 | struct sysinfo *cb = &romstage_state; |
| 92 | |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 93 | fill_sysinfo(cb); |
| 94 | |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 95 | agesa_execute_state(cb, AMD_INIT_RESET); |
| 96 | |
| 97 | agesa_execute_state(cb, AMD_INIT_EARLY); |
| 98 | |
| 99 | /* Not reached. */ |
| 100 | halt(); |
| 101 | } |
Kyösti Mälkki | 33d0fb8 | 2019-11-29 06:38:46 +0200 | [diff] [blame] | 102 | |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 103 | asmlinkage void car_stage_entry(void) |
| 104 | { |
| 105 | romstage_main(); |
| 106 | } |
Kyösti Mälkki | 2446c1e | 2020-07-09 07:13:37 +0300 | [diff] [blame] | 107 | |
| 108 | void *cbmem_top_chipset(void) |
| 109 | { |
| 110 | /* Top of CBMEM is at highest usable DRAM address below 4GiB. */ |
| 111 | return (void *)restore_top_of_low_cacheable(); |
| 112 | } |