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 |
Alexandru Gagniuc | 2dbd08f | 2014-04-10 14:35:59 -0500 | [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 | |
Alexandru Gagniuc | 288c958 | 2014-04-14 16:35:34 -0500 | [diff] [blame] | 11 | #include "hudson.h" |
Alexandru Gagniuc | 2dbd08f | 2014-04-10 14:35:59 -0500 | [diff] [blame] | 12 | #include "smi.h" |
| 13 | |
Alexandru Gagniuc | 288c958 | 2014-04-14 16:35:34 -0500 | [diff] [blame] | 14 | #define SMI_0x88_ACPI_COMMAND (1 << 11) |
Alexandru Gagniuc | 2dbd08f | 2014-04-10 14:35:59 -0500 | [diff] [blame] | 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 | |
Alexandru Gagniuc | 288c958 | 2014-04-14 16:35:34 -0500 | [diff] [blame] | 25 | static void hudson_apmc_smi_handler(void) |
| 26 | { |
| 27 | u32 reg32; |
| 28 | const uint8_t cmd = inb(ACPI_SMI_CTL_PORT); |
| 29 | |
| 30 | switch (cmd) { |
| 31 | case ACPI_SMI_CMD_ENABLE: |
| 32 | reg32 = inl(ACPI_PM1_CNT_BLK); |
| 33 | reg32 |= (1 << 0); /* SCI_EN */ |
| 34 | outl(reg32, ACPI_PM1_CNT_BLK); |
| 35 | break; |
| 36 | case ACPI_SMI_CMD_DISABLE: |
| 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); |
Alexandru Gagniuc | 288c958 | 2014-04-14 16:35:34 -0500 | [diff] [blame] | 44 | } |
| 45 | |
Alexandru Gagniuc | 2dbd08f | 2014-04-10 14:35:59 -0500 | [diff] [blame] | 46 | int southbridge_io_trap_handler(int smif) |
| 47 | { |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | static void process_smi_sci(void) |
| 52 | { |
| 53 | const uint32_t status = smi_read32(0x10); |
| 54 | |
| 55 | /* Clear events to prevent re-entering SMI if event isn't handled */ |
| 56 | smi_write32(0x10, status); |
| 57 | } |
| 58 | |
| 59 | static void process_gpe_smi(void) |
| 60 | { |
| 61 | const uint32_t status = smi_read32(0x80); |
Alexandru Gagniuc | 22d90e3 | 2014-04-14 14:38:19 -0500 | [diff] [blame] | 62 | const uint32_t gevent_mask = (1 << 24) - 1; |
| 63 | |
| 64 | /* Only Bits [23:0] indicate GEVENT SMIs. */ |
| 65 | if (status & gevent_mask) { |
Martin Roth | 3c3a50c | 2014-12-16 20:50:26 -0700 | [diff] [blame] | 66 | /* A GEVENT SMI occurred */ |
Kyösti Mälkki | 48b3dbc | 2014-12-29 19:36:50 +0200 | [diff] [blame] | 67 | mainboard_smi_gpi(status & gevent_mask); |
Alexandru Gagniuc | 22d90e3 | 2014-04-14 14:38:19 -0500 | [diff] [blame] | 68 | } |
Alexandru Gagniuc | 2dbd08f | 2014-04-10 14:35:59 -0500 | [diff] [blame] | 69 | |
| 70 | /* Clear events to prevent re-entering SMI if event isn't handled */ |
| 71 | smi_write32(0x80, status); |
| 72 | } |
| 73 | |
| 74 | static void process_smi_0x84(void) |
| 75 | { |
| 76 | const uint32_t status = smi_read32(0x84); |
| 77 | |
| 78 | /* Clear events to prevent re-entering SMI if event isn't handled */ |
| 79 | smi_write32(0x84, status); |
| 80 | } |
| 81 | |
| 82 | static void process_smi_0x88(void) |
| 83 | { |
| 84 | const uint32_t status = smi_read32(0x88); |
| 85 | |
Alexandru Gagniuc | 288c958 | 2014-04-14 16:35:34 -0500 | [diff] [blame] | 86 | if (status & SMI_0x88_ACPI_COMMAND) { |
| 87 | /* Command received via ACPI SMI command port */ |
| 88 | hudson_apmc_smi_handler(); |
| 89 | } |
Alexandru Gagniuc | 2dbd08f | 2014-04-10 14:35:59 -0500 | [diff] [blame] | 90 | /* Clear events to prevent re-entering SMI if event isn't handled */ |
| 91 | smi_write32(0x88, status); |
| 92 | } |
| 93 | |
| 94 | static void process_smi_0x8c(void) |
| 95 | { |
| 96 | const uint32_t status = smi_read32(0x8c); |
| 97 | |
| 98 | /* Clear events to prevent re-entering SMI if event isn't handled */ |
| 99 | smi_write32(0x8c, status); |
| 100 | } |
| 101 | |
| 102 | static void process_smi_0x90(void) |
| 103 | { |
| 104 | const uint32_t status = smi_read32(0x90); |
| 105 | |
| 106 | /* Clear events to prevent re-entering SMI if event isn't handled */ |
| 107 | smi_write32(0x90, status); |
| 108 | } |
| 109 | |
Kyösti Mälkki | 1ef039b | 2019-08-10 15:32:03 +0300 | [diff] [blame] | 110 | void southbridge_smi_handler(void) |
Alexandru Gagniuc | 2dbd08f | 2014-04-10 14:35:59 -0500 | [diff] [blame] | 111 | { |
| 112 | const uint16_t smi_src = smi_read16(0x94); |
| 113 | |
| 114 | if (smi_src & SMI_SOURCE_SCI) |
| 115 | process_smi_sci(); |
| 116 | if (smi_src & SMI_SOURCE_GPE) |
| 117 | process_gpe_smi(); |
| 118 | if (smi_src & SMI_SOURCE_0x84) |
| 119 | process_smi_0x84(); |
| 120 | if (smi_src & SMI_SOURCE_0x88) |
| 121 | process_smi_0x88(); |
| 122 | if (smi_src & SMI_SOURCE_IRQ_TRAP) |
| 123 | process_smi_0x8c(); |
| 124 | if (smi_src & SMI_SOURCE_0x90) |
| 125 | process_smi_0x90(); |
| 126 | } |
| 127 | |
| 128 | void southbridge_smi_set_eos(void) |
| 129 | { |
| 130 | uint32_t reg = smi_read32(SMI_REG_SMITRIG0); |
| 131 | reg |= SMITRG0_EOS; |
| 132 | smi_write32(SMI_REG_SMITRIG0, reg); |
| 133 | } |