blob: 7955345a46b09d3c1b225133cbe47260f0438502 [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älkkief40c0c2017-09-02 17:25:21 +030033#if IS_ENABLED(CONFIG_LATE_CBMEM_INIT)
34#error "Only EARLY_CBMEM_INIT is supported."
35#endif
36
Kyösti Mälkkib0931d32017-07-17 11:58:06 +030037void asmlinkage early_all_cores(void)
38{
39 amd_initmmio();
40}
41
Kyösti Mälkkia3d644f2017-07-17 11:58:06 +030042void __attribute__((weak)) platform_once(struct sysinfo *cb)
43{
44 board_BeforeAgesa(cb);
45}
46
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020047static void fill_sysinfo(struct sysinfo *cb)
48{
49 memset(cb, 0, sizeof(*cb));
50 cb->s3resume = acpi_is_wakeup_s3();
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020051
52 if (!HAS_LEGACY_WRAPPER)
53 agesa_set_interface(cb);
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020054}
55
56void * asmlinkage romstage_main(unsigned long bist)
57{
58 struct sysinfo romstage_state;
59 struct sysinfo *cb = &romstage_state;
60 u8 initial_apic_id = (u8) (cpuid_ebx(1) >> 24);
Kyösti Mälkkifb32be42017-04-12 04:31:54 +030061 int cbmem_initted = 0;
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020062
63 fill_sysinfo(cb);
64
65 if ((initial_apic_id == 0) && boot_cpu()) {
66
Kyösti Mälkki7369e832017-07-17 23:00:31 +030067 timestamp_init(timestamp_get());
68 timestamp_add_now(TS_START_ROMSTAGE);
69
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020070 platform_once(cb);
71
72 console_init();
73 }
74
75 printk(BIOS_DEBUG, "APIC %02d: CPU Family_Model = %08x\n",
76 initial_apic_id, cpuid_eax(1));
77
78 /* Halt if there was a built in self test failure */
79 report_bist_failure(bist);
80
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020081 if (!HAS_LEGACY_WRAPPER) {
82
83 agesa_execute_state(cb, AMD_INIT_RESET);
84
85 agesa_execute_state(cb, AMD_INIT_EARLY);
86
Kyösti Mälkki7369e832017-07-17 23:00:31 +030087 timestamp_add_now(TS_BEFORE_INITRAM);
88
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020089 if (!cb->s3resume)
90 agesa_execute_state(cb, AMD_INIT_POST);
91 else
92 agesa_execute_state(cb, AMD_INIT_RESUME);
93
Kyösti Mälkki7369e832017-07-17 23:00:31 +030094 /* FIXME: Detect if TSC frequency changed during raminit? */
95 timestamp_rescale_table(1, 4);
96 timestamp_add_now(TS_AFTER_INITRAM);
97
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020098 } else {
99
100 agesa_main(cb);
101
102 }
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +0200103
Kyösti Mälkkief40c0c2017-09-02 17:25:21 +0300104 cbmem_initted = !cbmem_recovery(cb->s3resume);
Kyösti Mälkkifb32be42017-04-12 04:31:54 +0300105
106 if (cb->s3resume && !cbmem_initted) {
107 printk(BIOS_EMERG, "Unable to recover CBMEM\n");
108 halt();
109 }
110
Kyösti Mälkkief40c0c2017-09-02 17:25:21 +0300111 uintptr_t stack_top = romstage_ram_stack_base(HIGH_ROMSTAGE_STACK_SIZE,
112 ROMSTAGE_STACK_CBMEM);
113 stack_top += HIGH_ROMSTAGE_STACK_SIZE;
Kyösti Mälkkiba22e152016-11-23 06:47:15 +0200114
Kyösti Mälkkief40c0c2017-09-02 17:25:21 +0300115 romstage_handoff_init(cb->s3resume);
Kyösti Mälkkifb32be42017-04-12 04:31:54 +0300116
Kyösti Mälkkiba22e152016-11-23 06:47:15 +0200117 printk(BIOS_DEBUG, "Move CAR stack.\n");
118 return (void*)stack_top;
119}
120
121void asmlinkage romstage_after_car(void)
122{
123 struct sysinfo romstage_state;
124 struct sysinfo *cb = &romstage_state;
125
126 printk(BIOS_DEBUG, "CAR disabled.\n");
127
128 fill_sysinfo(cb);
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +0200129
Kyösti Mälkki21e609c2017-03-09 20:08:15 +0200130 if (HAS_LEGACY_WRAPPER)
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +0200131 agesa_postcar(cb);
Kyösti Mälkkiba22e152016-11-23 06:47:15 +0200132
Kyösti Mälkki903ce252016-11-25 11:21:02 +0200133 if (!IS_ENABLED(CONFIG_CPU_AMD_PI) && cb->s3resume)
Kyösti Mälkkiba22e152016-11-23 06:47:15 +0200134 set_resume_cache();
135
136 run_ramstage();
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +0200137}