blob: dc780399e0ecf205d5e1cf00bb306dc08aacc543 [file] [log] [blame]
Patrick Georgi11f00792020-03-04 15:10:45 +01001/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Georgi3d767252018-03-15 14:04:35 +01002
Patrick Georgi3d767252018-03-15 14:04:35 +01003#include <stdint.h>
4#include <cpu/x86/smm.h>
5
6/*
Felix Heldc6322e12024-01-05 17:04:34 +01007 * Call the APMC SMI handler that resides in SMM. First, the command and sub-command are stored
8 * in eax, and the argument pointer is stored in ebx, then the command byte is written to the
9 * APMC IO port to trigger the SMI. The APMC SMI handler then reads the command from the APMC
10 * IO port and the contents of eax and ebx from the SMM state save area.
Patrick Georgi3d767252018-03-15 14:04:35 +010011 *
12 * static inline because the resulting assembly is often smaller than
13 * the call sequence due to constant folding.
14 */
15static inline u32 call_smm(u8 cmd, u8 subcmd, void *arg)
16{
Felix Held11ecbcf2024-01-04 18:01:18 +010017 const uint16_t apmc_port = pm_acpi_smi_cmd_port();
Patrick Georgi3d767252018-03-15 14:04:35 +010018 u32 res = 0;
19 __asm__ __volatile__ (
Felix Held8dd5b9d2024-01-04 17:52:41 +010020 "outb %%al, %%dx"
Patrick Georgi3d767252018-03-15 14:04:35 +010021 : "=a" (res)
Felix Held8dd5b9d2024-01-04 17:52:41 +010022 : "a" ((subcmd << 8) | cmd),
23 "b" (arg),
Felix Held11ecbcf2024-01-04 18:01:18 +010024 "d" (apmc_port)
Felix Held8dd5b9d2024-01-04 17:52:41 +010025 : "memory");
Patrick Georgi3d767252018-03-15 14:04:35 +010026 return res;
27}