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