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