blob: d5b20b76f932b4c01630c44b67d452cb80a2e69e [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>
20#include <cpu/x86/bist.h>
21#include <console/console.h>
Kyösti Mälkkiba22e152016-11-23 06:47:15 +020022#include <halt.h>
23#include <program_loading.h>
Kyösti Mälkkifb32be42017-04-12 04:31:54 +030024#include <romstage_handoff.h>
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020025#include <smp/node.h>
26#include <string.h>
Kyösti Mälkki7369e832017-07-17 23:00:31 +030027#include <timestamp.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
Julius Wernercd49cce2019-03-05 16:53:33 -080031#if !CONFIG(POSTCAR_STAGE)
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030032#error "Only POSTCAR_STAGE is supported."
33#endif
34#if HAS_LEGACY_WRAPPER
35#error "LEGACY_WRAPPER code not supported"
36#endif
Kyösti Mälkkief40c0c2017-09-02 17:25:21 +030037
Kyösti Mälkkib0931d32017-07-17 11:58:06 +030038void asmlinkage early_all_cores(void)
39{
40 amd_initmmio();
41}
42
Aaron Durbin64031672018-04-21 14:45:32 -060043void __weak platform_once(struct sysinfo *cb)
Kyösti Mälkkia3d644f2017-07-17 11:58:06 +030044{
45 board_BeforeAgesa(cb);
46}
47
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020048static void fill_sysinfo(struct sysinfo *cb)
49{
50 memset(cb, 0, sizeof(*cb));
51 cb->s3resume = acpi_is_wakeup_s3();
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020052
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030053 agesa_set_interface(cb);
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020054}
55
Elyes HAOUASb0b0c8c2018-07-08 12:33:47 +020056void *asmlinkage romstage_main(unsigned long bist)
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020057{
Kyösti Mälkki63fac812017-09-02 16:41:43 +030058 struct postcar_frame pcf;
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020059 struct sysinfo romstage_state;
60 struct sysinfo *cb = &romstage_state;
61 u8 initial_apic_id = (u8) (cpuid_ebx(1) >> 24);
Kyösti Mälkkifb32be42017-04-12 04:31:54 +030062 int cbmem_initted = 0;
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020063
64 fill_sysinfo(cb);
65
66 if ((initial_apic_id == 0) && boot_cpu()) {
67
Kyösti Mälkki7369e832017-07-17 23:00:31 +030068 timestamp_init(timestamp_get());
69 timestamp_add_now(TS_START_ROMSTAGE);
70
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020071 platform_once(cb);
72
73 console_init();
74 }
75
76 printk(BIOS_DEBUG, "APIC %02d: CPU Family_Model = %08x\n",
77 initial_apic_id, cpuid_eax(1));
78
79 /* Halt if there was a built in self test failure */
80 report_bist_failure(bist);
81
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030082 agesa_execute_state(cb, AMD_INIT_RESET);
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020083
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030084 agesa_execute_state(cb, AMD_INIT_EARLY);
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020085
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030086 timestamp_add_now(TS_BEFORE_INITRAM);
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020087
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030088 if (!cb->s3resume)
89 agesa_execute_state(cb, AMD_INIT_POST);
90 else
91 agesa_execute_state(cb, AMD_INIT_RESUME);
Kyösti Mälkki7369e832017-07-17 23:00:31 +030092
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030093 /* FIXME: Detect if TSC frequency changed during raminit? */
94 timestamp_rescale_table(1, 4);
95 timestamp_add_now(TS_AFTER_INITRAM);
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020096
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +030097 /* Work around AGESA setting all memory as WB on normal
98 * boot path.
99 */
100 fixup_cbmem_to_UC(cb->s3resume);
Kyösti Mälkki63fac812017-09-02 16:41:43 +0300101
Kyösti Mälkkief40c0c2017-09-02 17:25:21 +0300102 cbmem_initted = !cbmem_recovery(cb->s3resume);
Kyösti Mälkkifb32be42017-04-12 04:31:54 +0300103
104 if (cb->s3resume && !cbmem_initted) {
105 printk(BIOS_EMERG, "Unable to recover CBMEM\n");
106 halt();
107 }
108
Kyösti Mälkkief40c0c2017-09-02 17:25:21 +0300109 romstage_handoff_init(cb->s3resume);
Kyösti Mälkkifb32be42017-04-12 04:31:54 +0300110
Kyösti Mälkki63fac812017-09-02 16:41:43 +0300111 postcar_frame_init(&pcf, HIGH_ROMSTAGE_STACK_SIZE);
112 recover_postcar_frame(&pcf, cb->s3resume);
113
114 run_postcar_phase(&pcf);
115 /* We do not return. */
116 return NULL;
Kyösti Mälkkiba22e152016-11-23 06:47:15 +0200117}