Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 3 | |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 4 | #include <amdblocks/biosram.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 5 | #include <arch/acpi.h> |
| 6 | #include <arch/cpu.h> |
Kyösti Mälkki | a963acd | 2019-08-16 20:34:25 +0300 | [diff] [blame] | 7 | #include <arch/romstage.h> |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 8 | #include <cbmem.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 9 | #include <console/console.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; |
| 39 | u8 initial_apic_id = (u8) (cpuid_ebx(1) >> 24); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 40 | int cbmem_initted = 0; |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 41 | |
| 42 | fill_sysinfo(cb); |
| 43 | |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 44 | if (initial_apic_id == 0) { |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 45 | |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 46 | timestamp_add_now(TS_START_ROMSTAGE); |
| 47 | |
Kyösti Mälkki | 3d5e1e5 | 2019-12-03 14:06:02 +0200 | [diff] [blame] | 48 | board_BeforeAgesa(cb); |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 49 | |
| 50 | console_init(); |
| 51 | } |
| 52 | |
| 53 | printk(BIOS_DEBUG, "APIC %02d: CPU Family_Model = %08x\n", |
| 54 | initial_apic_id, cpuid_eax(1)); |
| 55 | |
Kyösti Mälkki | 520717d | 2019-12-15 21:37:48 +0200 | [diff] [blame] | 56 | set_ap_entry_ptr(ap_romstage_main); |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 57 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 58 | agesa_execute_state(cb, AMD_INIT_RESET); |
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 | agesa_execute_state(cb, AMD_INIT_EARLY); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 61 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 62 | timestamp_add_now(TS_BEFORE_INITRAM); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 63 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 64 | if (!cb->s3resume) |
| 65 | agesa_execute_state(cb, AMD_INIT_POST); |
| 66 | else |
| 67 | agesa_execute_state(cb, AMD_INIT_RESUME); |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 68 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 69 | timestamp_add_now(TS_AFTER_INITRAM); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 70 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 71 | /* Work around AGESA setting all memory as WB on normal |
| 72 | * boot path. |
| 73 | */ |
| 74 | fixup_cbmem_to_UC(cb->s3resume); |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 75 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 76 | cbmem_initted = !cbmem_recovery(cb->s3resume); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 77 | |
| 78 | if (cb->s3resume && !cbmem_initted) { |
| 79 | printk(BIOS_EMERG, "Unable to recover CBMEM\n"); |
| 80 | halt(); |
| 81 | } |
| 82 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 83 | romstage_handoff_init(cb->s3resume); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 84 | |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 85 | postcar_frame_init(&pcf, HIGH_ROMSTAGE_STACK_SIZE); |
| 86 | recover_postcar_frame(&pcf, cb->s3resume); |
| 87 | |
| 88 | run_postcar_phase(&pcf); |
| 89 | /* We do not return. */ |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 90 | } |
| 91 | |
Kyösti Mälkki | 33d0fb8 | 2019-11-29 06:38:46 +0200 | [diff] [blame] | 92 | static void ap_romstage_main(void) |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 93 | { |
| 94 | struct sysinfo romstage_state; |
| 95 | struct sysinfo *cb = &romstage_state; |
| 96 | |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 97 | fill_sysinfo(cb); |
| 98 | |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 99 | agesa_execute_state(cb, AMD_INIT_RESET); |
| 100 | |
| 101 | agesa_execute_state(cb, AMD_INIT_EARLY); |
| 102 | |
| 103 | /* Not reached. */ |
| 104 | halt(); |
| 105 | } |
Kyösti Mälkki | 33d0fb8 | 2019-11-29 06:38:46 +0200 | [diff] [blame] | 106 | |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 107 | asmlinkage void car_stage_entry(void) |
| 108 | { |
| 109 | romstage_main(); |
| 110 | } |