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 | |
| 14 | #include <arch/acpi.h> |
| 15 | #include <arch/cpu.h> |
Kyösti Mälkki | a963acd | 2019-08-16 20:34:25 +0300 | [diff] [blame] | 16 | #include <arch/romstage.h> |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 17 | #include <cbmem.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 18 | #include <cpu/amd/car.h> |
| 19 | #include <cpu/x86/bist.h> |
| 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 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 30 | void __weak platform_once(struct sysinfo *cb) |
Kyösti Mälkki | a3d644f | 2017-07-17 11:58:06 +0300 | [diff] [blame] | 31 | { |
| 32 | board_BeforeAgesa(cb); |
| 33 | } |
| 34 | |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 35 | static void fill_sysinfo(struct sysinfo *cb) |
| 36 | { |
| 37 | memset(cb, 0, sizeof(*cb)); |
| 38 | cb->s3resume = acpi_is_wakeup_s3(); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 39 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 40 | agesa_set_interface(cb); |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 41 | } |
| 42 | |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame^] | 43 | static void bsp_romstage_main(unsigned long bist) |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 44 | { |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 45 | struct postcar_frame pcf; |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 46 | struct sysinfo romstage_state; |
| 47 | struct sysinfo *cb = &romstage_state; |
| 48 | u8 initial_apic_id = (u8) (cpuid_ebx(1) >> 24); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 49 | int cbmem_initted = 0; |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 50 | |
Kyösti Mälkki | 9266ce9 | 2019-11-25 18:21:05 +0200 | [diff] [blame] | 51 | /* Enable PCI MMIO configuration. */ |
| 52 | amd_initmmio(); |
| 53 | |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 54 | fill_sysinfo(cb); |
| 55 | |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame^] | 56 | if (initial_apic_id == 0) { |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 57 | |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 58 | timestamp_init(timestamp_get()); |
| 59 | timestamp_add_now(TS_START_ROMSTAGE); |
| 60 | |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 61 | platform_once(cb); |
| 62 | |
| 63 | console_init(); |
| 64 | } |
| 65 | |
| 66 | printk(BIOS_DEBUG, "APIC %02d: CPU Family_Model = %08x\n", |
| 67 | initial_apic_id, cpuid_eax(1)); |
| 68 | |
| 69 | /* Halt if there was a built in self test failure */ |
| 70 | report_bist_failure(bist); |
| 71 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 72 | agesa_execute_state(cb, AMD_INIT_RESET); |
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 | agesa_execute_state(cb, AMD_INIT_EARLY); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 75 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 76 | timestamp_add_now(TS_BEFORE_INITRAM); |
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 | if (!cb->s3resume) |
| 79 | agesa_execute_state(cb, AMD_INIT_POST); |
| 80 | else |
| 81 | agesa_execute_state(cb, AMD_INIT_RESUME); |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 82 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 83 | timestamp_add_now(TS_AFTER_INITRAM); |
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 | /* Work around AGESA setting all memory as WB on normal |
| 86 | * boot path. |
| 87 | */ |
| 88 | fixup_cbmem_to_UC(cb->s3resume); |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 89 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 90 | cbmem_initted = !cbmem_recovery(cb->s3resume); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 91 | |
| 92 | if (cb->s3resume && !cbmem_initted) { |
| 93 | printk(BIOS_EMERG, "Unable to recover CBMEM\n"); |
| 94 | halt(); |
| 95 | } |
| 96 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 97 | romstage_handoff_init(cb->s3resume); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 98 | |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 99 | postcar_frame_init(&pcf, HIGH_ROMSTAGE_STACK_SIZE); |
| 100 | recover_postcar_frame(&pcf, cb->s3resume); |
| 101 | |
| 102 | run_postcar_phase(&pcf); |
| 103 | /* We do not return. */ |
Kyösti Mälkki | dc34a9d | 2019-11-28 15:04:17 +0200 | [diff] [blame^] | 104 | } |
| 105 | |
| 106 | static void __noreturn ap_romstage_main(unsigned long bist) |
| 107 | { |
| 108 | struct sysinfo romstage_state; |
| 109 | struct sysinfo *cb = &romstage_state; |
| 110 | |
| 111 | /* Enable PCI MMIO configuration. */ |
| 112 | amd_initmmio(); |
| 113 | |
| 114 | fill_sysinfo(cb); |
| 115 | |
| 116 | /* Halt if there was a built in self test failure */ |
| 117 | report_bist_failure(bist); |
| 118 | |
| 119 | agesa_execute_state(cb, AMD_INIT_RESET); |
| 120 | |
| 121 | agesa_execute_state(cb, AMD_INIT_EARLY); |
| 122 | |
| 123 | /* Not reached. */ |
| 124 | halt(); |
| 125 | } |
| 126 | |
| 127 | asmlinkage void romstage_main(unsigned long bist) |
| 128 | { |
| 129 | if (boot_cpu()) |
| 130 | bsp_romstage_main(bist); |
| 131 | else |
| 132 | ap_romstage_main(bist); |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 133 | } |