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 | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 26 | #include <smp/node.h> |
| 27 | #include <string.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 | b0931d3 | 2017-07-17 11:58:06 +0300 | [diff] [blame^] | 31 | void asmlinkage early_all_cores(void) |
| 32 | { |
| 33 | amd_initmmio(); |
| 34 | } |
| 35 | |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 36 | static void fill_sysinfo(struct sysinfo *cb) |
| 37 | { |
| 38 | memset(cb, 0, sizeof(*cb)); |
| 39 | cb->s3resume = acpi_is_wakeup_s3(); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 40 | |
| 41 | if (!HAS_LEGACY_WRAPPER) |
| 42 | agesa_set_interface(cb); |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | void * asmlinkage romstage_main(unsigned long bist) |
| 46 | { |
| 47 | struct sysinfo romstage_state; |
| 48 | struct sysinfo *cb = &romstage_state; |
| 49 | u8 initial_apic_id = (u8) (cpuid_ebx(1) >> 24); |
| 50 | |
| 51 | fill_sysinfo(cb); |
| 52 | |
| 53 | if ((initial_apic_id == 0) && boot_cpu()) { |
| 54 | |
| 55 | platform_once(cb); |
| 56 | |
| 57 | console_init(); |
| 58 | } |
| 59 | |
| 60 | printk(BIOS_DEBUG, "APIC %02d: CPU Family_Model = %08x\n", |
| 61 | initial_apic_id, cpuid_eax(1)); |
| 62 | |
| 63 | /* Halt if there was a built in self test failure */ |
| 64 | report_bist_failure(bist); |
| 65 | |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 66 | if (!HAS_LEGACY_WRAPPER) { |
| 67 | |
| 68 | agesa_execute_state(cb, AMD_INIT_RESET); |
| 69 | |
| 70 | agesa_execute_state(cb, AMD_INIT_EARLY); |
| 71 | |
| 72 | if (!cb->s3resume) |
| 73 | agesa_execute_state(cb, AMD_INIT_POST); |
| 74 | else |
| 75 | agesa_execute_state(cb, AMD_INIT_RESUME); |
| 76 | |
| 77 | } else { |
| 78 | |
| 79 | agesa_main(cb); |
| 80 | |
| 81 | } |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 82 | |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 83 | uintptr_t stack_top = CACHE_TMP_RAMTOP; |
| 84 | if (cb->s3resume) { |
| 85 | if (cbmem_recovery(1)) { |
| 86 | printk(BIOS_EMERG, "Unable to recover CBMEM\n"); |
| 87 | halt(); |
| 88 | } |
| 89 | stack_top = romstage_ram_stack_base(HIGH_ROMSTAGE_STACK_SIZE, |
| 90 | ROMSTAGE_STACK_CBMEM); |
| 91 | stack_top += HIGH_ROMSTAGE_STACK_SIZE; |
| 92 | } |
| 93 | |
| 94 | printk(BIOS_DEBUG, "Move CAR stack.\n"); |
| 95 | return (void*)stack_top; |
| 96 | } |
| 97 | |
| 98 | void asmlinkage romstage_after_car(void) |
| 99 | { |
| 100 | struct sysinfo romstage_state; |
| 101 | struct sysinfo *cb = &romstage_state; |
| 102 | |
| 103 | printk(BIOS_DEBUG, "CAR disabled.\n"); |
| 104 | |
| 105 | fill_sysinfo(cb); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 106 | |
| 107 | if (!HAS_LEGACY_WRAPPER) { |
| 108 | if (!cb->s3resume) |
| 109 | agesa_execute_state(cb, AMD_INIT_ENV); |
| 110 | else |
| 111 | agesa_execute_state(cb, AMD_S3LATE_RESTORE); |
| 112 | } else { |
| 113 | |
| 114 | agesa_postcar(cb); |
| 115 | } |
Kyösti Mälkki | ba22e15 | 2016-11-23 06:47:15 +0200 | [diff] [blame] | 116 | |
| 117 | if (cb->s3resume) |
| 118 | set_resume_cache(); |
| 119 | |
| 120 | run_ramstage(); |
Kyösti Mälkki | df7ff31 | 2016-11-25 12:02:00 +0200 | [diff] [blame] | 121 | } |