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