Kyösti Mälkki | b658548 | 2020-06-01 15:11:14 +0300 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <arch/io.h> |
| 4 | #include <console/console.h> |
| 5 | #include <cpu/x86/smm.h> |
Felix Held | c0a4c89 | 2024-01-04 18:31:35 +0100 | [diff] [blame^] | 6 | #include <smm_call.h> |
Elyes Haouas | 45d3205 | 2022-10-07 10:07:12 +0200 | [diff] [blame] | 7 | #include <stdint.h> |
Kyösti Mälkki | b658548 | 2020-06-01 15:11:14 +0300 | [diff] [blame] | 8 | |
Kyösti Mälkki | 9a1620f | 2021-01-08 13:27:33 +0200 | [diff] [blame] | 9 | static void apmc_log(const char *fn, u8 cmd) |
Kyösti Mälkki | b658548 | 2020-06-01 15:11:14 +0300 | [diff] [blame] | 10 | { |
Kyösti Mälkki | b658548 | 2020-06-01 15:11:14 +0300 | [diff] [blame] | 11 | switch (cmd) { |
Kyösti Mälkki | b658548 | 2020-06-01 15:11:14 +0300 | [diff] [blame] | 12 | case APM_CNT_ACPI_DISABLE: |
Kyösti Mälkki | 9a1620f | 2021-01-08 13:27:33 +0200 | [diff] [blame] | 13 | printk(BIOS_DEBUG, "%s: Disabling ACPI.\n", fn); |
Kyösti Mälkki | b658548 | 2020-06-01 15:11:14 +0300 | [diff] [blame] | 14 | break; |
| 15 | case APM_CNT_ACPI_ENABLE: |
Kyösti Mälkki | 9a1620f | 2021-01-08 13:27:33 +0200 | [diff] [blame] | 16 | printk(BIOS_DEBUG, "%s: Enabling ACPI.\n", fn); |
Kyösti Mälkki | b658548 | 2020-06-01 15:11:14 +0300 | [diff] [blame] | 17 | break; |
Kyösti Mälkki | b658548 | 2020-06-01 15:11:14 +0300 | [diff] [blame] | 18 | case APM_CNT_FINALIZE: |
Kyösti Mälkki | 9a1620f | 2021-01-08 13:27:33 +0200 | [diff] [blame] | 19 | printk(BIOS_DEBUG, "%s: Finalizing SMM.\n", fn); |
Kyösti Mälkki | b658548 | 2020-06-01 15:11:14 +0300 | [diff] [blame] | 20 | break; |
| 21 | case APM_CNT_ELOG_GSMI: |
| 22 | break; |
| 23 | case APM_CNT_SMMSTORE: |
| 24 | break; |
| 25 | case APM_CNT_SMMINFO: |
| 26 | break; |
| 27 | default: |
Kyösti Mälkki | 9a1620f | 2021-01-08 13:27:33 +0200 | [diff] [blame] | 28 | printk(BIOS_DEBUG, "%s: Unknown APMC 0x%02x.\n", fn, cmd); |
Kyösti Mälkki | b658548 | 2020-06-01 15:11:14 +0300 | [diff] [blame] | 29 | break; |
| 30 | } |
Kyösti Mälkki | 9a1620f | 2021-01-08 13:27:33 +0200 | [diff] [blame] | 31 | } |
| 32 | |
Felix Held | 21710ea | 2024-01-05 19:16:48 +0100 | [diff] [blame] | 33 | enum cb_err apm_control(u8 cmd) |
Kyösti Mälkki | 9a1620f | 2021-01-08 13:27:33 +0200 | [diff] [blame] | 34 | { |
| 35 | /* Never proceed inside SMI handler or without one. */ |
| 36 | if (ENV_SMM || !CONFIG(HAVE_SMI_HANDLER)) |
Felix Held | 21710ea | 2024-01-05 19:16:48 +0100 | [diff] [blame] | 37 | return CB_ERR; |
Kyösti Mälkki | 9a1620f | 2021-01-08 13:27:33 +0200 | [diff] [blame] | 38 | |
| 39 | apmc_log(__func__, cmd); |
Kyösti Mälkki | b658548 | 2020-06-01 15:11:14 +0300 | [diff] [blame] | 40 | |
| 41 | /* Now raise the SMI. */ |
Felix Held | c0a4c89 | 2024-01-04 18:31:35 +0100 | [diff] [blame^] | 42 | call_smm(cmd, 0, NULL); |
Kyösti Mälkki | b658548 | 2020-06-01 15:11:14 +0300 | [diff] [blame] | 43 | |
| 44 | printk(BIOS_DEBUG, "APMC done.\n"); |
Felix Held | 21710ea | 2024-01-05 19:16:48 +0100 | [diff] [blame] | 45 | return CB_SUCCESS; |
Kyösti Mälkki | b658548 | 2020-06-01 15:11:14 +0300 | [diff] [blame] | 46 | } |
Kyösti Mälkki | 9a1620f | 2021-01-08 13:27:33 +0200 | [diff] [blame] | 47 | |
| 48 | u8 apm_get_apmc(void) |
| 49 | { |
Felix Held | c4fbc91 | 2023-12-14 20:59:54 +0100 | [diff] [blame] | 50 | /* Read command byte from APMC SMI IO port */ |
| 51 | u8 cmd = inb(pm_acpi_smi_cmd_port()); |
Kyösti Mälkki | 9a1620f | 2021-01-08 13:27:33 +0200 | [diff] [blame] | 52 | |
| 53 | apmc_log("SMI#", cmd); |
| 54 | return cmd; |
| 55 | } |