blob: cb98e7b6d3fd2e08625ae0a059a7eb8792df903f [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älkkifb32be42017-04-12 04:31:54 +030026#include <romstage_handoff.h>
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020027#include <smp/node.h>
28#include <string.h>
Kyösti Mälkkiba22e152016-11-23 06:47:15 +020029#include <northbridge/amd/agesa/agesa_helper.h>
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020030#include <northbridge/amd/agesa/state_machine.h>
31
Kyösti Mälkkib0931d32017-07-17 11:58:06 +030032void asmlinkage early_all_cores(void)
33{
34 amd_initmmio();
35}
36
Kyösti Mälkkia3d644f2017-07-17 11:58:06 +030037void __attribute__((weak)) platform_once(struct sysinfo *cb)
38{
39 board_BeforeAgesa(cb);
40}
41
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020042static void fill_sysinfo(struct sysinfo *cb)
43{
44 memset(cb, 0, sizeof(*cb));
45 cb->s3resume = acpi_is_wakeup_s3();
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020046
47 if (!HAS_LEGACY_WRAPPER)
48 agesa_set_interface(cb);
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020049}
50
51void * asmlinkage romstage_main(unsigned long bist)
52{
53 struct sysinfo romstage_state;
54 struct sysinfo *cb = &romstage_state;
55 u8 initial_apic_id = (u8) (cpuid_ebx(1) >> 24);
Kyösti Mälkkifb32be42017-04-12 04:31:54 +030056 uintptr_t stack_top = CACHE_TMP_RAMTOP;
57 int cbmem_initted = 0;
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020058
59 fill_sysinfo(cb);
60
61 if ((initial_apic_id == 0) && boot_cpu()) {
62
63 platform_once(cb);
64
65 console_init();
66 }
67
68 printk(BIOS_DEBUG, "APIC %02d: CPU Family_Model = %08x\n",
69 initial_apic_id, cpuid_eax(1));
70
71 /* Halt if there was a built in self test failure */
72 report_bist_failure(bist);
73
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020074 if (!HAS_LEGACY_WRAPPER) {
75
76 agesa_execute_state(cb, AMD_INIT_RESET);
77
78 agesa_execute_state(cb, AMD_INIT_EARLY);
79
80 if (!cb->s3resume)
81 agesa_execute_state(cb, AMD_INIT_POST);
82 else
83 agesa_execute_state(cb, AMD_INIT_RESUME);
84
85 } else {
86
87 agesa_main(cb);
88
89 }
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020090
Kyösti Mälkkifb32be42017-04-12 04:31:54 +030091 if (IS_ENABLED(CONFIG_EARLY_CBMEM_INIT) || cb->s3resume)
92 cbmem_initted = !cbmem_recovery(cb->s3resume);
93
94 if (cb->s3resume && !cbmem_initted) {
95 printk(BIOS_EMERG, "Unable to recover CBMEM\n");
96 halt();
97 }
98
99 if (IS_ENABLED(CONFIG_EARLY_CBMEM_INIT) || cb->s3resume) {
Kyösti Mälkkiba22e152016-11-23 06:47:15 +0200100 stack_top = romstage_ram_stack_base(HIGH_ROMSTAGE_STACK_SIZE,
101 ROMSTAGE_STACK_CBMEM);
102 stack_top += HIGH_ROMSTAGE_STACK_SIZE;
103 }
104
Kyösti Mälkkifb32be42017-04-12 04:31:54 +0300105 if (IS_ENABLED(CONFIG_EARLY_CBMEM_INIT))
106 romstage_handoff_init(cb->s3resume);
107
Kyösti Mälkkiba22e152016-11-23 06:47:15 +0200108 printk(BIOS_DEBUG, "Move CAR stack.\n");
109 return (void*)stack_top;
110}
111
112void asmlinkage romstage_after_car(void)
113{
114 struct sysinfo romstage_state;
115 struct sysinfo *cb = &romstage_state;
116
117 printk(BIOS_DEBUG, "CAR disabled.\n");
118
119 fill_sysinfo(cb);
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +0200120
Kyösti Mälkki21e609c2017-03-09 20:08:15 +0200121 if (HAS_LEGACY_WRAPPER)
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +0200122 agesa_postcar(cb);
Kyösti Mälkkiba22e152016-11-23 06:47:15 +0200123
124 if (cb->s3resume)
125 set_resume_cache();
126
127 run_ramstage();
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +0200128}