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