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 | * |
| 4 | * Copyright (C) 2017 Kyösti Mälkki |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <arch/acpi.h> |
| 17 | #include <arch/cpu.h> |
Kyösti Mälkki | a963acd | 2019-08-16 20:34:25 +0300 | [diff] [blame^] | 18 | #include <arch/romstage.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 <cpu/amd/car.h> |
| 21 | #include <cpu/x86/bist.h> |
| 22 | #include <console/console.h> |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 23 | #include <halt.h> |
| 24 | #include <program_loading.h> |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 25 | #include <romstage_handoff.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 26 | #include <smp/node.h> |
| 27 | #include <string.h> |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 28 | #include <timestamp.h> |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 29 | #include <northbridge/amd/agesa/agesa_helper.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 30 | #include <northbridge/amd/agesa/state_machine.h> |
| 31 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 32 | #if !CONFIG(POSTCAR_STAGE) |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 33 | #error "Only POSTCAR_STAGE is supported." |
| 34 | #endif |
| 35 | #if HAS_LEGACY_WRAPPER |
| 36 | #error "LEGACY_WRAPPER code not supported" |
| 37 | #endif |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 38 | |
Kyösti Mälkki | b0931d3 | 2017-07-17 11:58:06 +0300 | [diff] [blame] | 39 | void asmlinkage early_all_cores(void) |
| 40 | { |
| 41 | amd_initmmio(); |
| 42 | } |
| 43 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 44 | void __weak platform_once(struct sysinfo *cb) |
Kyösti Mälkki | a3d644f | 2017-07-17 11:58:06 +0300 | [diff] [blame] | 45 | { |
| 46 | board_BeforeAgesa(cb); |
| 47 | } |
| 48 | |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 49 | static void fill_sysinfo(struct sysinfo *cb) |
| 50 | { |
| 51 | memset(cb, 0, sizeof(*cb)); |
| 52 | cb->s3resume = acpi_is_wakeup_s3(); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 53 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 54 | agesa_set_interface(cb); |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 55 | } |
| 56 | |
Elyes HAOUAS | b0b0c8c | 2018-07-08 12:33:47 +0200 | [diff] [blame] | 57 | void *asmlinkage romstage_main(unsigned long bist) |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 58 | { |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 59 | struct postcar_frame pcf; |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 60 | struct sysinfo romstage_state; |
| 61 | struct sysinfo *cb = &romstage_state; |
| 62 | u8 initial_apic_id = (u8) (cpuid_ebx(1) >> 24); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 63 | int cbmem_initted = 0; |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 64 | |
| 65 | fill_sysinfo(cb); |
| 66 | |
| 67 | if ((initial_apic_id == 0) && boot_cpu()) { |
| 68 | |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 69 | timestamp_init(timestamp_get()); |
| 70 | timestamp_add_now(TS_START_ROMSTAGE); |
| 71 | |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 72 | platform_once(cb); |
| 73 | |
| 74 | console_init(); |
| 75 | } |
| 76 | |
| 77 | printk(BIOS_DEBUG, "APIC %02d: CPU Family_Model = %08x\n", |
| 78 | initial_apic_id, cpuid_eax(1)); |
| 79 | |
| 80 | /* Halt if there was a built in self test failure */ |
| 81 | report_bist_failure(bist); |
| 82 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 83 | agesa_execute_state(cb, AMD_INIT_RESET); |
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 | agesa_execute_state(cb, AMD_INIT_EARLY); |
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 | timestamp_add_now(TS_BEFORE_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 | if (!cb->s3resume) |
| 90 | agesa_execute_state(cb, AMD_INIT_POST); |
| 91 | else |
| 92 | agesa_execute_state(cb, AMD_INIT_RESUME); |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 93 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 94 | timestamp_add_now(TS_AFTER_INITRAM); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 95 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 96 | /* Work around AGESA setting all memory as WB on normal |
| 97 | * boot path. |
| 98 | */ |
| 99 | fixup_cbmem_to_UC(cb->s3resume); |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 100 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 101 | cbmem_initted = !cbmem_recovery(cb->s3resume); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 102 | |
| 103 | if (cb->s3resume && !cbmem_initted) { |
| 104 | printk(BIOS_EMERG, "Unable to recover CBMEM\n"); |
| 105 | halt(); |
| 106 | } |
| 107 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 108 | romstage_handoff_init(cb->s3resume); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 109 | |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 110 | postcar_frame_init(&pcf, HIGH_ROMSTAGE_STACK_SIZE); |
| 111 | recover_postcar_frame(&pcf, cb->s3resume); |
| 112 | |
| 113 | run_postcar_phase(&pcf); |
| 114 | /* We do not return. */ |
| 115 | return NULL; |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 116 | } |