| 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <stdint.h> |
| 4 | #include <cpu/x86/smm.h> |
| 5 | |
| 6 | /* |
| 7 | * 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. |
| 11 | * |
| 12 | * static inline because the resulting assembly is often smaller than |
| 13 | * the call sequence due to constant folding. |
| 14 | */ |
| 15 | static inline u32 call_smm(u8 cmd, u8 subcmd, void *arg) |
| 16 | { |
| 17 | const uint16_t apmc_port = pm_acpi_smi_cmd_port(); |
| 18 | u32 res = 0; |
| 19 | __asm__ __volatile__ ( |
| 20 | "outb %%al, %%dx" |
| 21 | : "=a" (res) |
| 22 | : "a" ((subcmd << 8) | cmd), |
| 23 | "b" (arg), |
| 24 | "d" (apmc_port) |
| 25 | : "memory"); |
| 26 | return res; |
| 27 | } |