Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 2 of the License. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 14 | #include <amdblocks/biosram.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 15 | #include <arch/acpi.h> |
| 16 | #include <arch/cpu.h> |
Kyösti Mälkki | a963acd | 2019-08-16 20:34:25 +0300 | [diff] [blame] | 17 | #include <arch/romstage.h> |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 18 | #include <cbmem.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 19 | #include <console/console.h> |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 20 | #include <halt.h> |
| 21 | #include <program_loading.h> |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 22 | #include <romstage_handoff.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 23 | #include <smp/node.h> |
| 24 | #include <string.h> |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 25 | #include <timestamp.h> |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 26 | #include <northbridge/amd/agesa/agesa_helper.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 27 | #include <northbridge/amd/agesa/state_machine.h> |
| 28 | |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 29 | void __weak board_BeforeAgesa(struct sysinfo *cb) { } |
| 30 | |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 31 | static void fill_sysinfo(struct sysinfo *cb) |
| 32 | { |
| 33 | memset(cb, 0, sizeof(*cb)); |
| 34 | cb->s3resume = acpi_is_wakeup_s3(); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 35 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 36 | agesa_set_interface(cb); |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 37 | } |
| 38 | |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 39 | /* APs will enter directly here from bootblock, bypassing verstage |
| 40 | * and potential fallback / normal bootflow detection. |
| 41 | */ |
| 42 | static void ap_romstage_main(void); |
| 43 | |
Kyösti Mälkki | 33d0fb8 | 2019-11-29 06:38:46 +0200 | [diff] [blame] | 44 | static void romstage_main(void) |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 45 | { |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 46 | struct postcar_frame pcf; |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 47 | struct sysinfo romstage_state; |
| 48 | struct sysinfo *cb = &romstage_state; |
| 49 | u8 initial_apic_id = (u8) (cpuid_ebx(1) >> 24); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 50 | int cbmem_initted = 0; |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 51 | |
| 52 | fill_sysinfo(cb); |
| 53 | |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 54 | if (initial_apic_id == 0) { |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 55 | |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 56 | timestamp_add_now(TS_START_ROMSTAGE); |
| 57 | |
Kyösti Mälkki | 3d5e1e5 | 2019-12-03 14:06:02 +0200 | [diff] [blame] | 58 | board_BeforeAgesa(cb); |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 59 | |
| 60 | console_init(); |
| 61 | } |
| 62 | |
| 63 | printk(BIOS_DEBUG, "APIC %02d: CPU Family_Model = %08x\n", |
| 64 | initial_apic_id, cpuid_eax(1)); |
| 65 | |
Kyösti Mälkki | 520717d | 2019-12-15 21:37:48 +0200 | [diff] [blame] | 66 | set_ap_entry_ptr(ap_romstage_main); |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 67 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 68 | agesa_execute_state(cb, AMD_INIT_RESET); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 69 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 70 | agesa_execute_state(cb, AMD_INIT_EARLY); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 71 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 72 | timestamp_add_now(TS_BEFORE_INITRAM); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 73 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 74 | if (!cb->s3resume) |
| 75 | agesa_execute_state(cb, AMD_INIT_POST); |
| 76 | else |
| 77 | agesa_execute_state(cb, AMD_INIT_RESUME); |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 78 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 79 | timestamp_add_now(TS_AFTER_INITRAM); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 80 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 81 | /* Work around AGESA setting all memory as WB on normal |
| 82 | * boot path. |
| 83 | */ |
| 84 | fixup_cbmem_to_UC(cb->s3resume); |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 85 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 86 | cbmem_initted = !cbmem_recovery(cb->s3resume); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 87 | |
| 88 | if (cb->s3resume && !cbmem_initted) { |
| 89 | printk(BIOS_EMERG, "Unable to recover CBMEM\n"); |
| 90 | halt(); |
| 91 | } |
| 92 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 93 | romstage_handoff_init(cb->s3resume); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 94 | |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 95 | postcar_frame_init(&pcf, HIGH_ROMSTAGE_STACK_SIZE); |
| 96 | recover_postcar_frame(&pcf, cb->s3resume); |
| 97 | |
| 98 | run_postcar_phase(&pcf); |
| 99 | /* We do not return. */ |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 100 | } |
| 101 | |
Kyösti Mälkki | 33d0fb8 | 2019-11-29 06:38:46 +0200 | [diff] [blame] | 102 | static void ap_romstage_main(void) |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 103 | { |
| 104 | struct sysinfo romstage_state; |
| 105 | struct sysinfo *cb = &romstage_state; |
| 106 | |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 107 | fill_sysinfo(cb); |
| 108 | |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 109 | agesa_execute_state(cb, AMD_INIT_RESET); |
| 110 | |
| 111 | agesa_execute_state(cb, AMD_INIT_EARLY); |
| 112 | |
| 113 | /* Not reached. */ |
| 114 | halt(); |
| 115 | } |
Kyösti Mälkki | 33d0fb8 | 2019-11-29 06:38:46 +0200 | [diff] [blame] | 116 | |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 117 | asmlinkage void car_stage_entry(void) |
| 118 | { |
| 119 | romstage_main(); |
| 120 | } |