blob: a7d2ff90b7917571f401f477f32ff8653cec22bc [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älkki7369e832017-07-17 23:00:31 +030029#include <timestamp.h>
Kyösti Mälkkiba22e152016-11-23 06:47:15 +020030#include <northbridge/amd/agesa/agesa_helper.h>
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020031#include <northbridge/amd/agesa/state_machine.h>
32
Kyösti Mälkkib0931d32017-07-17 11:58:06 +030033void asmlinkage early_all_cores(void)
34{
35 amd_initmmio();
36}
37
Kyösti Mälkkia3d644f2017-07-17 11:58:06 +030038void __attribute__((weak)) platform_once(struct sysinfo *cb)
39{
40 board_BeforeAgesa(cb);
41}
42
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020043static void fill_sysinfo(struct sysinfo *cb)
44{
45 memset(cb, 0, sizeof(*cb));
46 cb->s3resume = acpi_is_wakeup_s3();
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020047
48 if (!HAS_LEGACY_WRAPPER)
49 agesa_set_interface(cb);
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020050}
51
52void * 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älkkifb32be42017-04-12 04:31:54 +030057 uintptr_t stack_top = CACHE_TMP_RAMTOP;
58 int cbmem_initted = 0;
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020059
60 fill_sysinfo(cb);
61
62 if ((initial_apic_id == 0) && boot_cpu()) {
63
Kyösti Mälkki7369e832017-07-17 23:00:31 +030064 timestamp_init(timestamp_get());
65 timestamp_add_now(TS_START_ROMSTAGE);
66
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020067 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älkki28c4d2f2016-11-25 11:21:02 +020078 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älkki7369e832017-07-17 23:00:31 +030084 timestamp_add_now(TS_BEFORE_INITRAM);
85
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020086 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älkki7369e832017-07-17 23:00:31 +030091 /* 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älkki28c4d2f2016-11-25 11:21:02 +020095 } else {
96
97 agesa_main(cb);
98
99 }
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +0200100
Kyösti Mälkkifb32be42017-04-12 04:31:54 +0300101 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älkkiba22e152016-11-23 06:47:15 +0200110 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älkkifb32be42017-04-12 04:31:54 +0300115 if (IS_ENABLED(CONFIG_EARLY_CBMEM_INIT))
116 romstage_handoff_init(cb->s3resume);
117
Kyösti Mälkkiba22e152016-11-23 06:47:15 +0200118 printk(BIOS_DEBUG, "Move CAR stack.\n");
119 return (void*)stack_top;
120}
121
122void 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älkki28c4d2f2016-11-25 11:21:02 +0200130
Kyösti Mälkki21e609c2017-03-09 20:08:15 +0200131 if (HAS_LEGACY_WRAPPER)
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +0200132 agesa_postcar(cb);
Kyösti Mälkkiba22e152016-11-23 06:47:15 +0200133
134 if (cb->s3resume)
135 set_resume_cache();
136
137 run_ramstage();
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +0200138}