blob: f9a8c9705a322ad93e4c65a5f9a13d0f5cd1cfe9 [file] [log] [blame]
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +02001/*
2 * This file is part of the coreboot project.
3 *
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +02004 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#include <arch/acpi.h>
15#include <arch/cpu.h>
Kyösti Mälkkia963acd2019-08-16 20:34:25 +030016#include <arch/romstage.h>
Kyösti Mälkkiba22e152016-11-23 06:47:15 +020017#include <cbmem.h>
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020018#include <cpu/amd/car.h>
19#include <cpu/x86/bist.h>
20#include <console/console.h>
Kyösti Mälkkiba22e152016-11-23 06:47:15 +020021#include <halt.h>
22#include <program_loading.h>
Kyösti Mälkkifb32be42017-04-12 04:31:54 +030023#include <romstage_handoff.h>
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020024#include <smp/node.h>
25#include <string.h>
Kyösti Mälkki7369e832017-07-17 23:00:31 +030026#include <timestamp.h>
Kyösti Mälkkiba22e152016-11-23 06:47:15 +020027#include <northbridge/amd/agesa/agesa_helper.h>
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020028#include <northbridge/amd/agesa/state_machine.h>
29
Aaron Durbin64031672018-04-21 14:45:32 -060030void __weak platform_once(struct sysinfo *cb)
Kyösti Mälkkia3d644f2017-07-17 11:58:06 +030031{
32 board_BeforeAgesa(cb);
33}
34
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020035static void fill_sysinfo(struct sysinfo *cb)
36{
37 memset(cb, 0, sizeof(*cb));
38 cb->s3resume = acpi_is_wakeup_s3();
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020039
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030040 agesa_set_interface(cb);
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020041}
42
Kyösti Mälkkidc34a9d2019-11-28 15:04:17 +020043static void bsp_romstage_main(unsigned long bist)
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020044{
Kyösti Mälkki63fac812017-09-02 16:41:43 +030045 struct postcar_frame pcf;
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020046 struct sysinfo romstage_state;
47 struct sysinfo *cb = &romstage_state;
48 u8 initial_apic_id = (u8) (cpuid_ebx(1) >> 24);
Kyösti Mälkkifb32be42017-04-12 04:31:54 +030049 int cbmem_initted = 0;
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020050
Kyösti Mälkki9266ce92019-11-25 18:21:05 +020051 /* Enable PCI MMIO configuration. */
52 amd_initmmio();
53
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020054 fill_sysinfo(cb);
55
Kyösti Mälkkidc34a9d2019-11-28 15:04:17 +020056 if (initial_apic_id == 0) {
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020057
Kyösti Mälkki7369e832017-07-17 23:00:31 +030058 timestamp_init(timestamp_get());
59 timestamp_add_now(TS_START_ROMSTAGE);
60
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020061 platform_once(cb);
62
63 console_init();
64 }
65
66 printk(BIOS_DEBUG, "APIC %02d: CPU Family_Model = %08x\n",
67 initial_apic_id, cpuid_eax(1));
68
69 /* Halt if there was a built in self test failure */
70 report_bist_failure(bist);
71
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030072 agesa_execute_state(cb, AMD_INIT_RESET);
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020073
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030074 agesa_execute_state(cb, AMD_INIT_EARLY);
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020075
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030076 timestamp_add_now(TS_BEFORE_INITRAM);
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020077
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030078 if (!cb->s3resume)
79 agesa_execute_state(cb, AMD_INIT_POST);
80 else
81 agesa_execute_state(cb, AMD_INIT_RESUME);
Kyösti Mälkki7369e832017-07-17 23:00:31 +030082
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030083 timestamp_add_now(TS_AFTER_INITRAM);
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020084
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030085 /* Work around AGESA setting all memory as WB on normal
86 * boot path.
87 */
88 fixup_cbmem_to_UC(cb->s3resume);
Kyösti Mälkki63fac812017-09-02 16:41:43 +030089
Kyösti Mälkkief40c0c2017-09-02 17:25:21 +030090 cbmem_initted = !cbmem_recovery(cb->s3resume);
Kyösti Mälkkifb32be42017-04-12 04:31:54 +030091
92 if (cb->s3resume && !cbmem_initted) {
93 printk(BIOS_EMERG, "Unable to recover CBMEM\n");
94 halt();
95 }
96
Kyösti Mälkkief40c0c2017-09-02 17:25:21 +030097 romstage_handoff_init(cb->s3resume);
Kyösti Mälkkifb32be42017-04-12 04:31:54 +030098
Kyösti Mälkki63fac812017-09-02 16:41:43 +030099 postcar_frame_init(&pcf, HIGH_ROMSTAGE_STACK_SIZE);
100 recover_postcar_frame(&pcf, cb->s3resume);
101
102 run_postcar_phase(&pcf);
103 /* We do not return. */
Kyösti Mälkkidc34a9d2019-11-28 15:04:17 +0200104}
105
106static void __noreturn ap_romstage_main(unsigned long bist)
107{
108 struct sysinfo romstage_state;
109 struct sysinfo *cb = &romstage_state;
110
111 /* Enable PCI MMIO configuration. */
112 amd_initmmio();
113
114 fill_sysinfo(cb);
115
116 /* Halt if there was a built in self test failure */
117 report_bist_failure(bist);
118
119 agesa_execute_state(cb, AMD_INIT_RESET);
120
121 agesa_execute_state(cb, AMD_INIT_EARLY);
122
123 /* Not reached. */
124 halt();
125}
126
127asmlinkage void romstage_main(unsigned long bist)
128{
129 if (boot_cpu())
130 bsp_romstage_main(bist);
131 else
132 ap_romstage_main(bist);
Kyösti Mälkkiba22e152016-11-23 06:47:15 +0200133}