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 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 31 | #if IS_ENABLED(CONFIG_LATE_CBMEM_INIT) |
| 32 | #error "Only EARLY_CBMEM_INIT is supported." |
| 33 | #endif |
| 34 | |
Kyösti Mälkki | b0931d3 | 2017-07-17 11:58:06 +0300 | [diff] [blame] | 35 | void asmlinkage early_all_cores(void) |
| 36 | { |
| 37 | amd_initmmio(); |
| 38 | } |
| 39 | |
Kyösti Mälkki | a3d644f | 2017-07-17 11:58:06 +0300 | [diff] [blame] | 40 | void __attribute__((weak)) platform_once(struct sysinfo *cb) |
| 41 | { |
| 42 | board_BeforeAgesa(cb); |
| 43 | } |
| 44 | |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 45 | static void fill_sysinfo(struct sysinfo *cb) |
| 46 | { |
| 47 | memset(cb, 0, sizeof(*cb)); |
| 48 | cb->s3resume = acpi_is_wakeup_s3(); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 49 | |
| 50 | if (!HAS_LEGACY_WRAPPER) |
| 51 | agesa_set_interface(cb); |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | void * asmlinkage romstage_main(unsigned long bist) |
| 55 | { |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame^] | 56 | struct postcar_frame pcf; |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 57 | struct sysinfo romstage_state; |
| 58 | struct sysinfo *cb = &romstage_state; |
| 59 | u8 initial_apic_id = (u8) (cpuid_ebx(1) >> 24); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 60 | int cbmem_initted = 0; |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 61 | |
| 62 | fill_sysinfo(cb); |
| 63 | |
| 64 | if ((initial_apic_id == 0) && boot_cpu()) { |
| 65 | |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 66 | timestamp_init(timestamp_get()); |
| 67 | timestamp_add_now(TS_START_ROMSTAGE); |
| 68 | |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 69 | platform_once(cb); |
| 70 | |
| 71 | console_init(); |
| 72 | } |
| 73 | |
| 74 | printk(BIOS_DEBUG, "APIC %02d: CPU Family_Model = %08x\n", |
| 75 | initial_apic_id, cpuid_eax(1)); |
| 76 | |
| 77 | /* Halt if there was a built in self test failure */ |
| 78 | report_bist_failure(bist); |
| 79 | |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 80 | if (!HAS_LEGACY_WRAPPER) { |
| 81 | |
| 82 | agesa_execute_state(cb, AMD_INIT_RESET); |
| 83 | |
| 84 | agesa_execute_state(cb, AMD_INIT_EARLY); |
| 85 | |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 86 | timestamp_add_now(TS_BEFORE_INITRAM); |
| 87 | |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 88 | if (!cb->s3resume) |
| 89 | agesa_execute_state(cb, AMD_INIT_POST); |
| 90 | else |
| 91 | agesa_execute_state(cb, AMD_INIT_RESUME); |
| 92 | |
Kyösti Mälkki | 7369e83 | 2017-07-17 23:00:31 +0300 | [diff] [blame] | 93 | /* FIXME: Detect if TSC frequency changed during raminit? */ |
| 94 | timestamp_rescale_table(1, 4); |
| 95 | timestamp_add_now(TS_AFTER_INITRAM); |
| 96 | |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 97 | } else { |
| 98 | |
| 99 | agesa_main(cb); |
| 100 | |
| 101 | } |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 102 | |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame^] | 103 | if (IS_ENABLED(CONFIG_POSTCAR_STAGE)) |
| 104 | fixup_cbmem_to_UC(cb->s3resume); |
| 105 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 106 | cbmem_initted = !cbmem_recovery(cb->s3resume); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 107 | |
| 108 | if (cb->s3resume && !cbmem_initted) { |
| 109 | printk(BIOS_EMERG, "Unable to recover CBMEM\n"); |
| 110 | halt(); |
| 111 | } |
| 112 | |
Kyösti Mälkki | ef40c0c | 2017-09-02 17:25:21 +0300 | [diff] [blame] | 113 | romstage_handoff_init(cb->s3resume); |
Kyösti Mälkki | fb32be4 | 2017-04-12 04:31:54 +0300 | [diff] [blame] | 114 | |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame^] | 115 | if (!IS_ENABLED(CONFIG_POSTCAR_STAGE)) { |
| 116 | uintptr_t stack_top = romstage_ram_stack_base( |
| 117 | HIGH_ROMSTAGE_STACK_SIZE, ROMSTAGE_STACK_CBMEM); |
| 118 | stack_top += HIGH_ROMSTAGE_STACK_SIZE; |
| 119 | printk(BIOS_DEBUG, "Move CAR stack.\n"); |
| 120 | return (void*)stack_top; |
| 121 | } |
| 122 | |
| 123 | postcar_frame_init(&pcf, HIGH_ROMSTAGE_STACK_SIZE); |
| 124 | recover_postcar_frame(&pcf, cb->s3resume); |
| 125 | |
| 126 | run_postcar_phase(&pcf); |
| 127 | /* We do not return. */ |
| 128 | return NULL; |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 129 | } |
| 130 | |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame^] | 131 | #if !IS_ENABLED(CONFIG_POSTCAR_STAGE) |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 132 | void asmlinkage romstage_after_car(void) |
| 133 | { |
| 134 | struct sysinfo romstage_state; |
| 135 | struct sysinfo *cb = &romstage_state; |
| 136 | |
| 137 | printk(BIOS_DEBUG, "CAR disabled.\n"); |
| 138 | |
| 139 | fill_sysinfo(cb); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 140 | |
Kyösti Mälkki | 21e609c | 2017-03-09 20:08:15 +0200 | [diff] [blame] | 141 | if (HAS_LEGACY_WRAPPER) |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 142 | agesa_postcar(cb); |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 143 | |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 144 | run_ramstage(); |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 145 | } |
Kyösti Mälkki | 63fac81 | 2017-09-02 16:41:43 +0300 | [diff] [blame^] | 146 | #endif |