blob: fc4a0b488cff2448fec6319ebe44d37895f67e10 [file] [log] [blame]
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +02001/*
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älkkiba22e152016-11-23 06:47:15 +020018#include <cbmem.h>
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020019#include <cpu/amd/car.h>
Kyösti Mälkkiba22e152016-11-23 06:47:15 +020020#include <cpu/amd/agesa/s3_resume.h>
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020021#include <cpu/x86/bist.h>
Kyösti Mälkkiba22e152016-11-23 06:47:15 +020022#include <cpu/x86/mtrr.h>
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020023#include <console/console.h>
Kyösti Mälkkiba22e152016-11-23 06:47:15 +020024#include <halt.h>
25#include <program_loading.h>
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020026#include <smp/node.h>
27#include <string.h>
Kyösti Mälkkiba22e152016-11-23 06:47:15 +020028#include <northbridge/amd/agesa/agesa_helper.h>
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020029#include <northbridge/amd/agesa/state_machine.h>
30
Kyösti Mälkkib0931d32017-07-17 11:58:06 +030031void asmlinkage early_all_cores(void)
32{
33 amd_initmmio();
34}
35
Kyösti Mälkkia3d644f2017-07-17 11:58:06 +030036void __attribute__((weak)) platform_once(struct sysinfo *cb)
37{
38 board_BeforeAgesa(cb);
39}
40
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020041static void fill_sysinfo(struct sysinfo *cb)
42{
43 memset(cb, 0, sizeof(*cb));
44 cb->s3resume = acpi_is_wakeup_s3();
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020045
46 if (!HAS_LEGACY_WRAPPER)
47 agesa_set_interface(cb);
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020048}
49
50void * asmlinkage romstage_main(unsigned long bist)
51{
52 struct sysinfo romstage_state;
53 struct sysinfo *cb = &romstage_state;
54 u8 initial_apic_id = (u8) (cpuid_ebx(1) >> 24);
55
56 fill_sysinfo(cb);
57
58 if ((initial_apic_id == 0) && boot_cpu()) {
59
60 platform_once(cb);
61
62 console_init();
63 }
64
65 printk(BIOS_DEBUG, "APIC %02d: CPU Family_Model = %08x\n",
66 initial_apic_id, cpuid_eax(1));
67
68 /* Halt if there was a built in self test failure */
69 report_bist_failure(bist);
70
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020071 if (!HAS_LEGACY_WRAPPER) {
72
73 agesa_execute_state(cb, AMD_INIT_RESET);
74
75 agesa_execute_state(cb, AMD_INIT_EARLY);
76
77 if (!cb->s3resume)
78 agesa_execute_state(cb, AMD_INIT_POST);
79 else
80 agesa_execute_state(cb, AMD_INIT_RESUME);
81
82 } else {
83
84 agesa_main(cb);
85
86 }
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020087
Kyösti Mälkkiba22e152016-11-23 06:47:15 +020088 uintptr_t stack_top = CACHE_TMP_RAMTOP;
89 if (cb->s3resume) {
90 if (cbmem_recovery(1)) {
91 printk(BIOS_EMERG, "Unable to recover CBMEM\n");
92 halt();
93 }
94 stack_top = romstage_ram_stack_base(HIGH_ROMSTAGE_STACK_SIZE,
95 ROMSTAGE_STACK_CBMEM);
96 stack_top += HIGH_ROMSTAGE_STACK_SIZE;
97 }
98
99 printk(BIOS_DEBUG, "Move CAR stack.\n");
100 return (void*)stack_top;
101}
102
103void asmlinkage romstage_after_car(void)
104{
105 struct sysinfo romstage_state;
106 struct sysinfo *cb = &romstage_state;
107
108 printk(BIOS_DEBUG, "CAR disabled.\n");
109
110 fill_sysinfo(cb);
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +0200111
112 if (!HAS_LEGACY_WRAPPER) {
113 if (!cb->s3resume)
114 agesa_execute_state(cb, AMD_INIT_ENV);
115 else
116 agesa_execute_state(cb, AMD_S3LATE_RESTORE);
117 } else {
118
119 agesa_postcar(cb);
120 }
Kyösti Mälkkiba22e152016-11-23 06:47:15 +0200121
122 if (cb->s3resume)
123 set_resume_cache();
124
125 run_ramstage();
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +0200126}