Patrick Georgi | 11f0079 | 2020-03-04 15:10:45 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Georgi | 3d76725 | 2018-03-15 14:04:35 +0100 | [diff] [blame] | 2 | |
Patrick Georgi | 3d76725 | 2018-03-15 14:04:35 +0100 | [diff] [blame] | 3 | #include <stdint.h> |
| 4 | #include <cpu/x86/smm.h> |
| 5 | |
| 6 | /* |
Felix Held | c6322e1 | 2024-01-05 17:04:34 +0100 | [diff] [blame] | 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. |
Patrick Georgi | 3d76725 | 2018-03-15 14:04:35 +0100 | [diff] [blame] | 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 | { |
Felix Held | 11ecbcf | 2024-01-04 18:01:18 +0100 | [diff] [blame] | 17 | const uint16_t apmc_port = pm_acpi_smi_cmd_port(); |
Patrick Georgi | 3d76725 | 2018-03-15 14:04:35 +0100 | [diff] [blame] | 18 | u32 res = 0; |
| 19 | __asm__ __volatile__ ( |
Felix Held | 8dd5b9d | 2024-01-04 17:52:41 +0100 | [diff] [blame] | 20 | "outb %%al, %%dx" |
Patrick Georgi | 3d76725 | 2018-03-15 14:04:35 +0100 | [diff] [blame] | 21 | : "=a" (res) |
Felix Held | 8dd5b9d | 2024-01-04 17:52:41 +0100 | [diff] [blame] | 22 | : "a" ((subcmd << 8) | cmd), |
| 23 | "b" (arg), |
Felix Held | 11ecbcf | 2024-01-04 18:01:18 +0100 | [diff] [blame] | 24 | "d" (apmc_port) |
Felix Held | 8dd5b9d | 2024-01-04 17:52:41 +0100 | [diff] [blame] | 25 | : "memory"); |
Patrick Georgi | 3d76725 | 2018-03-15 14:04:35 +0100 | [diff] [blame] | 26 | return res; |
| 27 | } |