Alexandru Gagniuc | 2dbd08f | 2014-04-10 14:35:59 -0500 | [diff] [blame] | 1 | /* |
| 2 | * SMI handler for Hudson southbridges |
| 3 | * |
| 4 | * Copyright (C) 2014 Alexandru Gagniuc <mr.nuke.me@gmail.com> |
| 5 | * Subject to the GNU GPL v2, or (at your option) any later version. |
| 6 | */ |
| 7 | |
Alexandru Gagniuc | 288c958 | 2014-04-14 16:35:34 -0500 | [diff] [blame] | 8 | #include "hudson.h" |
Alexandru Gagniuc | 2dbd08f | 2014-04-10 14:35:59 -0500 | [diff] [blame] | 9 | #include "smi.h" |
| 10 | |
| 11 | #include <console/console.h> |
| 12 | #include <cpu/x86/smm.h> |
| 13 | #include <delay.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 | |
| 44 | if (mainboard_smi_apmc) |
| 45 | mainboard_smi_apmc(cmd); |
| 46 | } |
| 47 | |
Alexandru Gagniuc | 2dbd08f | 2014-04-10 14:35:59 -0500 | [diff] [blame] | 48 | int southbridge_io_trap_handler(int smif) |
| 49 | { |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | static void process_smi_sci(void) |
| 54 | { |
| 55 | const uint32_t status = smi_read32(0x10); |
| 56 | |
| 57 | /* Clear events to prevent re-entering SMI if event isn't handled */ |
| 58 | smi_write32(0x10, status); |
| 59 | } |
| 60 | |
| 61 | static void process_gpe_smi(void) |
| 62 | { |
| 63 | const uint32_t status = smi_read32(0x80); |
Alexandru Gagniuc | 22d90e3 | 2014-04-14 14:38:19 -0500 | [diff] [blame] | 64 | const uint32_t gevent_mask = (1 << 24) - 1; |
| 65 | |
| 66 | /* Only Bits [23:0] indicate GEVENT SMIs. */ |
| 67 | if (status & gevent_mask) { |
Martin Roth | 3c3a50c | 2014-12-16 20:50:26 -0700 | [diff] [blame^] | 68 | /* A GEVENT SMI occurred */ |
Alexandru Gagniuc | 22d90e3 | 2014-04-14 14:38:19 -0500 | [diff] [blame] | 69 | if (mainboard_smi_gpi) |
| 70 | mainboard_smi_gpi(status & gevent_mask); |
| 71 | } |
Alexandru Gagniuc | 2dbd08f | 2014-04-10 14:35:59 -0500 | [diff] [blame] | 72 | |
| 73 | /* Clear events to prevent re-entering SMI if event isn't handled */ |
| 74 | smi_write32(0x80, status); |
| 75 | } |
| 76 | |
| 77 | static void process_smi_0x84(void) |
| 78 | { |
| 79 | const uint32_t status = smi_read32(0x84); |
| 80 | |
| 81 | /* Clear events to prevent re-entering SMI if event isn't handled */ |
| 82 | smi_write32(0x84, status); |
| 83 | } |
| 84 | |
| 85 | static void process_smi_0x88(void) |
| 86 | { |
| 87 | const uint32_t status = smi_read32(0x88); |
| 88 | |
Alexandru Gagniuc | 288c958 | 2014-04-14 16:35:34 -0500 | [diff] [blame] | 89 | if (status & SMI_0x88_ACPI_COMMAND) { |
| 90 | /* Command received via ACPI SMI command port */ |
| 91 | hudson_apmc_smi_handler(); |
| 92 | } |
Alexandru Gagniuc | 2dbd08f | 2014-04-10 14:35:59 -0500 | [diff] [blame] | 93 | /* Clear events to prevent re-entering SMI if event isn't handled */ |
| 94 | smi_write32(0x88, status); |
| 95 | } |
| 96 | |
| 97 | static void process_smi_0x8c(void) |
| 98 | { |
| 99 | const uint32_t status = smi_read32(0x8c); |
| 100 | |
| 101 | /* Clear events to prevent re-entering SMI if event isn't handled */ |
| 102 | smi_write32(0x8c, status); |
| 103 | } |
| 104 | |
| 105 | static void process_smi_0x90(void) |
| 106 | { |
| 107 | const uint32_t status = smi_read32(0x90); |
| 108 | |
| 109 | /* Clear events to prevent re-entering SMI if event isn't handled */ |
| 110 | smi_write32(0x90, status); |
| 111 | } |
| 112 | |
| 113 | void southbridge_smi_handler(unsigned int node, smm_state_save_area_t *state_save) |
| 114 | { |
| 115 | const uint16_t smi_src = smi_read16(0x94); |
| 116 | |
| 117 | if (smi_src & SMI_SOURCE_SCI) |
| 118 | process_smi_sci(); |
| 119 | if (smi_src & SMI_SOURCE_GPE) |
| 120 | process_gpe_smi(); |
| 121 | if (smi_src & SMI_SOURCE_0x84) |
| 122 | process_smi_0x84(); |
| 123 | if (smi_src & SMI_SOURCE_0x88) |
| 124 | process_smi_0x88(); |
| 125 | if (smi_src & SMI_SOURCE_IRQ_TRAP) |
| 126 | process_smi_0x8c(); |
| 127 | if (smi_src & SMI_SOURCE_0x90) |
| 128 | process_smi_0x90(); |
| 129 | } |
| 130 | |
| 131 | void southbridge_smi_set_eos(void) |
| 132 | { |
| 133 | uint32_t reg = smi_read32(SMI_REG_SMITRIG0); |
| 134 | reg |= SMITRG0_EOS; |
| 135 | smi_write32(SMI_REG_SMITRIG0, reg); |
| 136 | } |