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