blob: fad49c305cfb09573e7d6ed8c8d02be7e9601cfb [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älkkia963acd2019-08-16 20:34:25 +030018#include <arch/romstage.h>
Kyösti Mälkkiba22e152016-11-23 06:47:15 +020019#include <cbmem.h>
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020020#include <cpu/amd/car.h>
21#include <cpu/x86/bist.h>
22#include <console/console.h>
Kyösti Mälkkiba22e152016-11-23 06:47:15 +020023#include <halt.h>
24#include <program_loading.h>
Kyösti Mälkkifb32be42017-04-12 04:31:54 +030025#include <romstage_handoff.h>
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020026#include <smp/node.h>
27#include <string.h>
Kyösti Mälkki7369e832017-07-17 23:00:31 +030028#include <timestamp.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
Julius Wernercd49cce2019-03-05 16:53:33 -080032#if !CONFIG(POSTCAR_STAGE)
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030033#error "Only POSTCAR_STAGE is supported."
34#endif
35#if HAS_LEGACY_WRAPPER
36#error "LEGACY_WRAPPER code not supported"
37#endif
Kyösti Mälkkief40c0c2017-09-02 17:25:21 +030038
Kyösti Mälkkib0931d32017-07-17 11:58:06 +030039void asmlinkage early_all_cores(void)
40{
41 amd_initmmio();
42}
43
Aaron Durbin64031672018-04-21 14:45:32 -060044void __weak platform_once(struct sysinfo *cb)
Kyösti Mälkkia3d644f2017-07-17 11:58:06 +030045{
46 board_BeforeAgesa(cb);
47}
48
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020049static void fill_sysinfo(struct sysinfo *cb)
50{
51 memset(cb, 0, sizeof(*cb));
52 cb->s3resume = acpi_is_wakeup_s3();
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020053
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030054 agesa_set_interface(cb);
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020055}
56
Elyes HAOUASb0b0c8c2018-07-08 12:33:47 +020057void *asmlinkage romstage_main(unsigned long bist)
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020058{
Kyösti Mälkki63fac812017-09-02 16:41:43 +030059 struct postcar_frame pcf;
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020060 struct sysinfo romstage_state;
61 struct sysinfo *cb = &romstage_state;
62 u8 initial_apic_id = (u8) (cpuid_ebx(1) >> 24);
Kyösti Mälkkifb32be42017-04-12 04:31:54 +030063 int cbmem_initted = 0;
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020064
65 fill_sysinfo(cb);
66
67 if ((initial_apic_id == 0) && boot_cpu()) {
68
Kyösti Mälkki7369e832017-07-17 23:00:31 +030069 timestamp_init(timestamp_get());
70 timestamp_add_now(TS_START_ROMSTAGE);
71
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020072 platform_once(cb);
73
74 console_init();
75 }
76
77 printk(BIOS_DEBUG, "APIC %02d: CPU Family_Model = %08x\n",
78 initial_apic_id, cpuid_eax(1));
79
80 /* Halt if there was a built in self test failure */
81 report_bist_failure(bist);
82
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030083 agesa_execute_state(cb, AMD_INIT_RESET);
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020084
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030085 agesa_execute_state(cb, AMD_INIT_EARLY);
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020086
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030087 timestamp_add_now(TS_BEFORE_INITRAM);
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020088
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030089 if (!cb->s3resume)
90 agesa_execute_state(cb, AMD_INIT_POST);
91 else
92 agesa_execute_state(cb, AMD_INIT_RESUME);
Kyösti Mälkki7369e832017-07-17 23:00:31 +030093
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030094 timestamp_add_now(TS_AFTER_INITRAM);
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020095
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030096 /* Work around AGESA setting all memory as WB on normal
97 * boot path.
98 */
99 fixup_cbmem_to_UC(cb->s3resume);
Kyösti Mälkki63fac812017-09-02 16:41:43 +0300100
Kyösti Mälkkief40c0c2017-09-02 17:25:21 +0300101 cbmem_initted = !cbmem_recovery(cb->s3resume);
Kyösti Mälkkifb32be42017-04-12 04:31:54 +0300102
103 if (cb->s3resume && !cbmem_initted) {
104 printk(BIOS_EMERG, "Unable to recover CBMEM\n");
105 halt();
106 }
107
Kyösti Mälkkief40c0c2017-09-02 17:25:21 +0300108 romstage_handoff_init(cb->s3resume);
Kyösti Mälkkifb32be42017-04-12 04:31:54 +0300109
Kyösti Mälkki63fac812017-09-02 16:41:43 +0300110 postcar_frame_init(&pcf, HIGH_ROMSTAGE_STACK_SIZE);
111 recover_postcar_frame(&pcf, cb->s3resume);
112
113 run_postcar_phase(&pcf);
114 /* We do not return. */
115 return NULL;
Kyösti Mälkkiba22e152016-11-23 06:47:15 +0200116}