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 | 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 <cpu/amd/car.h> |
| 20 | #include <cpu/x86/bist.h> |
| 21 | #include <console/console.h> |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 22 | #include <halt.h> |
| 23 | #include <program_loading.h> |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 24 | #include <romstage_handoff.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 25 | #include <smp/node.h> |
| 26 | #include <string.h> |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 27 | #include <timestamp.h> |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 28 | #include <northbridge/amd/agesa/agesa_helper.h> |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 29 | #include <northbridge/amd/agesa/state_machine.h> |
| 30 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 31 | #if !CONFIG(POSTCAR_STAGE) |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 32 | #error "Only POSTCAR_STAGE is supported." |
| 33 | #endif |
| 34 | #if HAS_LEGACY_WRAPPER |
| 35 | #error "LEGACY_WRAPPER code not supported" |
| 36 | #endif |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 37 | |
Kyösti Mälkki | b0931d3 | 2017-07-17 11:58:06 +0300 | [diff] [blame] | 38 | void asmlinkage early_all_cores(void) |
| 39 | { |
| 40 | amd_initmmio(); |
| 41 | } |
| 42 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 43 | void __weak platform_once(struct sysinfo *cb) |
Kyösti Mälkki | a3d644f | 2017-07-17 11:58:06 +0300 | [diff] [blame] | 44 | { |
| 45 | board_BeforeAgesa(cb); |
| 46 | } |
| 47 | |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 48 | static void fill_sysinfo(struct sysinfo *cb) |
| 49 | { |
| 50 | memset(cb, 0, sizeof(*cb)); |
| 51 | cb->s3resume = acpi_is_wakeup_s3(); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 52 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 53 | agesa_set_interface(cb); |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 54 | } |
| 55 | |
Elyes HAOUAS | b0b0c8c | 2018-07-08 12:33:47 +0200 | [diff] [blame] | 56 | void *asmlinkage romstage_main(unsigned long bist) |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 57 | { |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 58 | struct postcar_frame pcf; |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 59 | struct sysinfo romstage_state; |
| 60 | struct sysinfo *cb = &romstage_state; |
| 61 | u8 initial_apic_id = (u8) (cpuid_ebx(1) >> 24); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 62 | int cbmem_initted = 0; |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 63 | |
| 64 | fill_sysinfo(cb); |
| 65 | |
| 66 | if ((initial_apic_id == 0) && boot_cpu()) { |
| 67 | |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 68 | timestamp_init(timestamp_get()); |
| 69 | timestamp_add_now(TS_START_ROMSTAGE); |
| 70 | |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 71 | platform_once(cb); |
| 72 | |
| 73 | console_init(); |
| 74 | } |
| 75 | |
| 76 | printk(BIOS_DEBUG, "APIC %02d: CPU Family_Model = %08x\n", |
| 77 | initial_apic_id, cpuid_eax(1)); |
| 78 | |
| 79 | /* Halt if there was a built in self test failure */ |
| 80 | report_bist_failure(bist); |
| 81 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 82 | agesa_execute_state(cb, AMD_INIT_RESET); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 83 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 84 | agesa_execute_state(cb, AMD_INIT_EARLY); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 85 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 86 | timestamp_add_now(TS_BEFORE_INITRAM); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 87 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 88 | if (!cb->s3resume) |
| 89 | agesa_execute_state(cb, AMD_INIT_POST); |
| 90 | else |
| 91 | agesa_execute_state(cb, AMD_INIT_RESUME); |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 92 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 93 | timestamp_add_now(TS_AFTER_INITRAM); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 94 | |
Kyösti Mälkki | 0f6c0b1 | 2017-09-07 06:46:46 +0300 | [diff] [blame] | 95 | /* Work around AGESA setting all memory as WB on normal |
| 96 | * boot path. |
| 97 | */ |
| 98 | fixup_cbmem_to_UC(cb->s3resume); |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 99 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 100 | cbmem_initted = !cbmem_recovery(cb->s3resume); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 101 | |
| 102 | if (cb->s3resume && !cbmem_initted) { |
| 103 | printk(BIOS_EMERG, "Unable to recover CBMEM\n"); |
| 104 | halt(); |
| 105 | } |
| 106 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 107 | romstage_handoff_init(cb->s3resume); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 108 | |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame] | 109 | postcar_frame_init(&pcf, HIGH_ROMSTAGE_STACK_SIZE); |
| 110 | recover_postcar_frame(&pcf, cb->s3resume); |
| 111 | |
| 112 | run_postcar_phase(&pcf); |
| 113 | /* We do not return. */ |
| 114 | return NULL; |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 115 | } |