blob: fe3a57102106b1d1f68342be41abc1635117f4f2 [file] [log] [blame]
Arthur Heymanse69d2df2020-12-01 18:29:13 +01001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <console/console.h>
4#include <cpu/x86/mp.h>
5#include <stdint.h>
6#include <cpu/intel/smm_reloc.h>
7#include <cpu/amd/amd64_save_state.h>
8#include <mainboard/emulation/qemu-i440fx/fw_cfg.h>
9
10static void get_smm_info(uintptr_t *perm_smbase, size_t *perm_smsize,
11 size_t *smm_save_state_size)
12{
13 printk(BIOS_DEBUG, "Setting up SMI for CPU\n");
14
Arthur Heymans4db2e8e2021-10-28 16:48:36 +020015 if (CONFIG(SMM_TSEG))
16 smm_subregion(SMM_SUBREGION_HANDLER, perm_smbase, perm_smsize);
17
18 if (CONFIG(SMM_ASEG)) {
19 smm_open_aseg();
20 *perm_smbase = 0xa0000;
21 *perm_smsize = 0x10000;
22 }
Arthur Heymanse69d2df2020-12-01 18:29:13 +010023
24 /* FIXME: on X86_64 the save state size is smaller than the size of the SMM stub */
25 *smm_save_state_size = sizeof(amd64_smm_state_save_area_t);
Benjamin Doron8c5994f2021-03-20 15:41:57 +000026 printk(BIOS_DEBUG, "Save state size: 0x%zx bytes\n", *smm_save_state_size);
Arthur Heymanse69d2df2020-12-01 18:29:13 +010027}
28
29/*
30 * The relocation work is actually performed in SMM context, but the code
31 * resides in the ramstage module. This occurs by trampolining from the default
32 * SMRAM entry point to here.
33 */
34static void relocation_handler(int cpu, uintptr_t curr_smbase,
35 uintptr_t staggered_smbase)
36{
37 /* The em64t101 save state is sufficiently compatible with older
38 save states with regards of smbase, smm_revision. */
39 amd64_smm_state_save_area_t *save_state;
40 u32 smbase = staggered_smbase;
41
42 save_state = (void *)(curr_smbase + SMM_DEFAULT_SIZE - sizeof(*save_state));
43 save_state->smbase = smbase;
44
45 printk(BIOS_DEBUG, "In relocation handler: cpu %d\n", cpu);
46 printk(BIOS_DEBUG, "SMM revision: 0x%08x\n", save_state->smm_revision);
47 printk(BIOS_DEBUG, "New SMBASE=0x%08x\n", smbase);
48}
49
50static void post_mp_init(void)
51{
52 /* Now that all APs have been relocated as well as the BSP let SMIs start flowing. */
53 global_smi_enable();
54
55 /* Lock down the SMRAM space. */
56 smm_lock();
57}
58
59const struct mp_ops mp_ops_with_smm = {
60 .get_cpu_count = fw_cfg_max_cpus,
61 .get_smm_info = get_smm_info,
62 .pre_mp_smm_init = smm_southbridge_clear_state,
63 .relocation_handler = relocation_handler,
64 .post_mp_init = post_mp_init,
65};