aboutsummaryrefslogtreecommitdiff
path: root/src/arch/x86/include/smm_call.h
blob: dc780399e0ecf205d5e1cf00bb306dc08aacc543 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* SPDX-License-Identifier: GPL-2.0-only */

#include <stdint.h>
#include <cpu/x86/smm.h>

/*
 * Call the APMC SMI handler that resides in SMM. First, the command and sub-command are stored
 * in eax, and the argument pointer is stored in ebx, then the command byte is written to the
 * APMC IO port to trigger the SMI. The APMC SMI handler then reads the command from the APMC
 * IO port and the contents of eax and ebx from the SMM state save area.
 *
 * static inline because the resulting assembly is often smaller than
 * the call sequence due to constant folding.
 */
static inline u32 call_smm(u8 cmd, u8 subcmd, void *arg)
{
	const uint16_t apmc_port = pm_acpi_smi_cmd_port();
	u32 res = 0;
	__asm__ __volatile__ (
		"outb %%al, %%dx"
		: "=a" (res)
		: "a" ((subcmd << 8) | cmd),
		  "b" (arg),
		  "d" (apmc_port)
		: "memory");
	return res;
}