Debian Codegraph @

src/soc/amd/common/block/cpu/smm/smi_apmc.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 #include <acpi/acpi.h>
4 #include <amdblocks/acpi.h>
5 #include <amdblocks/psp.h>
6 #include <amdblocks/smm.h>
7 #include <arch/io.h>
8 #include <cpu/amd/amd64_save_state.h>
9 #include <cpu/x86/smm.h>
10 #include <elog.h>
11 #include <smmstore.h>
12 #include <types.h>
13
14 /* bits in smm_io_trap */
15 #define SMM_IO_TRAP_PORT_OFFSET 16
16 #define SMM_IO_TRAP_PORT_ADDRESS_MASK 0xffff
17 #define SMM_IO_TRAP_RW (1 << 0)
18 #define SMM_IO_TRAP_VALID (1 << 1)
19
20 static inline u16 get_io_address(u32 info)
21 {
22 return ((info >> SMM_IO_TRAP_PORT_OFFSET) &
23 SMM_IO_TRAP_PORT_ADDRESS_MASK);
24 }
25
26 static void *find_save_state(int cmd)
27 {
28 unsigned int core;
29 amd64_smm_state_save_area_t *state;
30 u32 smm_io_trap;
31 u8 reg_al;
32
33 /* Check all nodes looking for the one that issued the IO */
34 for (core = 0; core < CONFIG_MAX_CPUS; core++) {
35 state = smm_get_save_state(core);
36 if (!state)
37 continue;
38 smm_io_trap = state->smm_io_trap_offset;
39 /* Check for Valid IO Trap Word (bit1==1) */
40 if (!(smm_io_trap & SMM_IO_TRAP_VALID))
41 continue;
42 /* Make sure it was a write (bit0==0) */
43 if (smm_io_trap & SMM_IO_TRAP_RW)
44 continue;
45 /* Check for APMC IO port */
46 if (pm_acpi_smi_cmd_port() != get_io_address(smm_io_trap))
47 continue;
48 /* Check AL against the requested command */
49 reg_al = state->rax;
50 if (reg_al == cmd)
51 return state;
52 }
53 return NULL;
54 }
55
56 void handle_smi_gsmi(void)
57 {
58 u8 sub_command;
59 amd64_smm_state_save_area_t *io_smi;
60 u32 reg_ebx;
61
62 io_smi = find_save_state(APM_CNT_ELOG_GSMI);
63 if (!io_smi)
64 return;
65 /* Command and return value in EAX */
66 sub_command = (io_smi->rax >> 8) & 0xff;
67
68 /* Parameter buffer in EBX */
69 reg_ebx = io_smi->rbx;
70
71 /* drivers/elog/gsmi.c */
72 io_smi->rax = gsmi_exec(sub_command, &reg_ebx);
73 }
74
75 void handle_smi_store(void)
76 {
77 u8 sub_command;
78 amd64_smm_state_save_area_t *io_smi;
79 u32 reg_ebx;
80
81 io_smi = find_save_state(APM_CNT_SMMSTORE);
82 if (!io_smi)
83 return;
84 /* Command and return value in EAX */
85 sub_command = (io_smi->rax >> 8) & 0xff;
86
87 /* Parameter buffer in EBX */
88 reg_ebx = io_smi->rbx;
89
90 /* drivers/smmstore/smi.c */
91 io_smi->rax = smmstore_exec(sub_command, (void *)(uintptr_t)reg_ebx);
92 }
93
94 void fch_apmc_smi_handler(void)
95 {
96 const uint8_t cmd = apm_get_apmc();
97
98 switch (cmd) {
99 case APM_CNT_ACPI_ENABLE:
100 acpi_clear_pm_gpe_status();
101 acpi_enable_sci();
102 break;
103 case APM_CNT_ACPI_DISABLE:
104 acpi_disable_sci();
105 break;
106 case APM_CNT_ELOG_GSMI:
107 if (CONFIG(ELOG_GSMI))
108 handle_smi_gsmi();
109 break;
110 case APM_CNT_SMMSTORE:
111 if (CONFIG(SMMSTORE))
112 handle_smi_store();
113 break;
114 case APM_CNT_SMMINFO:
115 psp_notify_smm();
116 break;
117 }
118
119 mainboard_smi_apmc(cmd);
120 }