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 | 33d0fb8 | 2019-11-29 06:38:46 +0200 | [diff] [blame] | 18 | #include <bootblock_common.h> |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 19 | #include <cbmem.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 20 | #include <console/console.h> |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 21 | #include <halt.h> |
| 22 | #include <program_loading.h> |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 23 | #include <romstage_handoff.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 24 | #include <smp/node.h> |
| 25 | #include <string.h> |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 26 | #include <timestamp.h> |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 27 | #include <northbridge/amd/agesa/agesa_helper.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 28 | #include <northbridge/amd/agesa/state_machine.h> |
| 29 | |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 30 | void __weak board_BeforeAgesa(struct sysinfo *cb) { } |
| 31 | |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 32 | static void fill_sysinfo(struct sysinfo *cb) |
| 33 | { |
| 34 | memset(cb, 0, sizeof(*cb)); |
| 35 | cb->s3resume = acpi_is_wakeup_s3(); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 36 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 37 | agesa_set_interface(cb); |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 38 | } |
| 39 | |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 40 | /* APs will enter directly here from bootblock, bypassing verstage |
| 41 | * and potential fallback / normal bootflow detection. |
| 42 | */ |
| 43 | static void ap_romstage_main(void); |
| 44 | |
Kyösti Mälkki | 33d0fb8 | 2019-11-29 06:38:46 +0200 | [diff] [blame] | 45 | static void romstage_main(void) |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 46 | { |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 47 | struct postcar_frame pcf; |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 48 | struct sysinfo romstage_state; |
| 49 | struct sysinfo *cb = &romstage_state; |
| 50 | u8 initial_apic_id = (u8) (cpuid_ebx(1) >> 24); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 51 | int cbmem_initted = 0; |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 52 | |
Kyösti Mälkki | 9266ce9 | 2019-11-25 18:21:05 +0200 | [diff] [blame] | 53 | /* Enable PCI MMIO configuration. */ |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 54 | if (CONFIG(ROMCC_BOOTBLOCK)) |
| 55 | amd_initmmio(); |
Kyösti Mälkki | 9266ce9 | 2019-11-25 18:21:05 +0200 | [diff] [blame] | 56 | |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 57 | fill_sysinfo(cb); |
| 58 | |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 59 | if (initial_apic_id == 0) { |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 60 | |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 61 | if (CONFIG(ROMCC_BOOTBLOCK)) |
| 62 | timestamp_init(timestamp_get()); |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 63 | timestamp_add_now(TS_START_ROMSTAGE); |
| 64 | |
Kyösti Mälkki | 3d5e1e5 | 2019-12-03 14:06:02 +0200 | [diff] [blame] | 65 | board_BeforeAgesa(cb); |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 66 | |
| 67 | console_init(); |
| 68 | } |
| 69 | |
| 70 | printk(BIOS_DEBUG, "APIC %02d: CPU Family_Model = %08x\n", |
| 71 | initial_apic_id, cpuid_eax(1)); |
| 72 | |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 73 | if (!CONFIG(ROMCC_BOOTBLOCK)) |
| 74 | set_ap_entry_ptr(ap_romstage_main); |
| 75 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 76 | agesa_execute_state(cb, AMD_INIT_RESET); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 77 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 78 | agesa_execute_state(cb, AMD_INIT_EARLY); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 79 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 80 | timestamp_add_now(TS_BEFORE_INITRAM); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 81 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 82 | if (!cb->s3resume) |
| 83 | agesa_execute_state(cb, AMD_INIT_POST); |
| 84 | else |
| 85 | agesa_execute_state(cb, AMD_INIT_RESUME); |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 86 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 87 | timestamp_add_now(TS_AFTER_INITRAM); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 88 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 89 | /* Work around AGESA setting all memory as WB on normal |
| 90 | * boot path. |
| 91 | */ |
| 92 | fixup_cbmem_to_UC(cb->s3resume); |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 93 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 94 | cbmem_initted = !cbmem_recovery(cb->s3resume); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 95 | |
| 96 | if (cb->s3resume && !cbmem_initted) { |
| 97 | printk(BIOS_EMERG, "Unable to recover CBMEM\n"); |
| 98 | halt(); |
| 99 | } |
| 100 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 101 | romstage_handoff_init(cb->s3resume); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 102 | |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 103 | postcar_frame_init(&pcf, HIGH_ROMSTAGE_STACK_SIZE); |
| 104 | recover_postcar_frame(&pcf, cb->s3resume); |
| 105 | |
| 106 | run_postcar_phase(&pcf); |
| 107 | /* We do not return. */ |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 108 | } |
| 109 | |
Kyösti Mälkki | 33d0fb8 | 2019-11-29 06:38:46 +0200 | [diff] [blame] | 110 | static void ap_romstage_main(void) |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 111 | { |
| 112 | struct sysinfo romstage_state; |
| 113 | struct sysinfo *cb = &romstage_state; |
| 114 | |
| 115 | /* Enable PCI MMIO configuration. */ |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 116 | if (CONFIG(ROMCC_BOOTBLOCK)) |
| 117 | amd_initmmio(); |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 118 | |
| 119 | fill_sysinfo(cb); |
| 120 | |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame] | 121 | agesa_execute_state(cb, AMD_INIT_RESET); |
| 122 | |
| 123 | agesa_execute_state(cb, AMD_INIT_EARLY); |
| 124 | |
| 125 | /* Not reached. */ |
| 126 | halt(); |
| 127 | } |
Kyösti Mälkki | 33d0fb8 | 2019-11-29 06:38:46 +0200 | [diff] [blame] | 128 | |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 129 | #if CONFIG(ROMCC_BOOTBLOCK) |
Kyösti Mälkki | 33d0fb8 | 2019-11-29 06:38:46 +0200 | [diff] [blame] | 130 | /* This wrapper enables easy transition away from ROMCC_BOOTBLOCK |
| 131 | * keeping changes in cache_as_ram.S easy to manage. |
| 132 | */ |
| 133 | asmlinkage void bootblock_c_entry(uint64_t base_timestamp) |
| 134 | { |
| 135 | romstage_main(); |
| 136 | } |
| 137 | |
| 138 | asmlinkage void ap_bootblock_c_entry(void) |
| 139 | { |
| 140 | ap_romstage_main(); |
| 141 | } |
Michał Żygowski | 1b12b64 | 2019-11-24 16:32:05 +0100 | [diff] [blame] | 142 | #else |
| 143 | asmlinkage void car_stage_entry(void) |
| 144 | { |
| 145 | romstage_main(); |
| 146 | } |
| 147 | #endif |