Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Martin Roth | ebace9f | 2018-05-26 18:56:17 -0600 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * SMI handler for Hudson southbridges |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 5 | */ |
| 6 | |
Michał Żygowski | f3db2ae | 2019-11-24 13:26:10 +0100 | [diff] [blame] | 7 | #include <amdblocks/acpimmio.h> |
Kyösti Mälkki | bdaec07 | 2019-03-02 23:18:29 +0200 | [diff] [blame] | 8 | #include <arch/io.h> |
Elyes HAOUAS | bf0970e | 2019-03-21 11:10:03 +0100 | [diff] [blame] | 9 | #include <cpu/x86/smm.h> |
| 10 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 11 | #include "hudson.h" |
| 12 | #include "smi.h" |
| 13 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 14 | #define SMI_0x88_ACPI_COMMAND (1 << 11) |
| 15 | |
| 16 | enum smi_source { |
| 17 | SMI_SOURCE_SCI = (1 << 0), |
| 18 | SMI_SOURCE_GPE = (1 << 1), |
| 19 | SMI_SOURCE_0x84 = (1 << 2), |
| 20 | SMI_SOURCE_0x88 = (1 << 3), |
| 21 | SMI_SOURCE_IRQ_TRAP = (1 << 4), |
| 22 | SMI_SOURCE_0x90 = (1 << 5) |
| 23 | }; |
| 24 | |
| 25 | static void hudson_apmc_smi_handler(void) |
| 26 | { |
| 27 | u32 reg32; |
Felix Held | 1b558eb | 2024-01-08 17:10:37 +0100 | [diff] [blame] | 28 | const uint8_t cmd = apm_get_apmc(); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 29 | |
| 30 | switch (cmd) { |
Felix Held | 74beb5d | 2024-01-08 17:02:23 +0100 | [diff] [blame] | 31 | case APM_CNT_ACPI_ENABLE: |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 32 | reg32 = inl(ACPI_PM1_CNT_BLK); |
| 33 | reg32 |= (1 << 0); /* SCI_EN */ |
| 34 | outl(reg32, ACPI_PM1_CNT_BLK); |
| 35 | break; |
Felix Held | 74beb5d | 2024-01-08 17:02:23 +0100 | [diff] [blame] | 36 | case APM_CNT_ACPI_DISABLE: |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 37 | reg32 = inl(ACPI_PM1_CNT_BLK); |
| 38 | reg32 &= ~(1 << 0); /* clear SCI_EN */ |
| 39 | outl(ACPI_PM1_CNT_BLK, reg32); |
| 40 | break; |
| 41 | } |
| 42 | |
Kyösti Mälkki | 48b3dbc | 2014-12-29 19:36:50 +0200 | [diff] [blame] | 43 | mainboard_smi_apmc(cmd); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 44 | } |
| 45 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 46 | static void process_smi_sci(void) |
| 47 | { |
| 48 | const uint32_t status = smi_read32(0x10); |
| 49 | |
| 50 | /* Clear events to prevent re-entering SMI if event isn't handled */ |
| 51 | smi_write32(0x10, status); |
| 52 | } |
| 53 | |
| 54 | static void process_gpe_smi(void) |
| 55 | { |
| 56 | const uint32_t status = smi_read32(0x80); |
| 57 | const uint32_t gevent_mask = (1 << 24) - 1; |
| 58 | |
| 59 | /* Only Bits [23:0] indicate GEVENT SMIs. */ |
| 60 | if (status & gevent_mask) { |
Martin Roth | 2ed0aa2 | 2016-01-05 20:58:58 -0700 | [diff] [blame] | 61 | /* A GEVENT SMI occurred */ |
Kyösti Mälkki | 48b3dbc | 2014-12-29 19:36:50 +0200 | [diff] [blame] | 62 | mainboard_smi_gpi(status & gevent_mask); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /* Clear events to prevent re-entering SMI if event isn't handled */ |
| 66 | smi_write32(0x80, status); |
| 67 | } |
| 68 | |
| 69 | static void process_smi_0x84(void) |
| 70 | { |
| 71 | const uint32_t status = smi_read32(0x84); |
| 72 | |
| 73 | /* Clear events to prevent re-entering SMI if event isn't handled */ |
| 74 | smi_write32(0x84, status); |
| 75 | } |
| 76 | |
| 77 | static void process_smi_0x88(void) |
| 78 | { |
| 79 | const uint32_t status = smi_read32(0x88); |
| 80 | |
| 81 | if (status & SMI_0x88_ACPI_COMMAND) { |
| 82 | /* Command received via ACPI SMI command port */ |
| 83 | hudson_apmc_smi_handler(); |
| 84 | } |
| 85 | /* Clear events to prevent re-entering SMI if event isn't handled */ |
| 86 | smi_write32(0x88, status); |
| 87 | } |
| 88 | |
| 89 | static void process_smi_0x8c(void) |
| 90 | { |
| 91 | const uint32_t status = smi_read32(0x8c); |
| 92 | |
| 93 | /* Clear events to prevent re-entering SMI if event isn't handled */ |
| 94 | smi_write32(0x8c, status); |
| 95 | } |
| 96 | |
| 97 | static void process_smi_0x90(void) |
| 98 | { |
| 99 | const uint32_t status = smi_read32(0x90); |
| 100 | |
| 101 | /* Clear events to prevent re-entering SMI if event isn't handled */ |
| 102 | smi_write32(0x90, status); |
| 103 | } |
| 104 | |
Kyösti Mälkki | 1ef039b | 2019-08-10 15:32:03 +0300 | [diff] [blame] | 105 | void southbridge_smi_handler(void) |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 106 | { |
| 107 | const uint16_t smi_src = smi_read16(0x94); |
| 108 | |
| 109 | if (smi_src & SMI_SOURCE_SCI) |
| 110 | process_smi_sci(); |
| 111 | if (smi_src & SMI_SOURCE_GPE) |
| 112 | process_gpe_smi(); |
| 113 | if (smi_src & SMI_SOURCE_0x84) |
| 114 | process_smi_0x84(); |
| 115 | if (smi_src & SMI_SOURCE_0x88) |
| 116 | process_smi_0x88(); |
| 117 | if (smi_src & SMI_SOURCE_IRQ_TRAP) |
| 118 | process_smi_0x8c(); |
| 119 | if (smi_src & SMI_SOURCE_0x90) |
| 120 | process_smi_0x90(); |
| 121 | } |
| 122 | |
| 123 | void southbridge_smi_set_eos(void) |
| 124 | { |
| 125 | uint32_t reg = smi_read32(SMI_REG_SMITRIG0); |
| 126 | reg |= SMITRG0_EOS; |
| 127 | smi_write32(SMI_REG_SMITRIG0, reg); |
| 128 | } |