Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 2 | |
| 3 | #include <types.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 4 | #include <arch/io.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 5 | #include <device/pci_ops.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 6 | #include <console/console.h> |
Patrick Rudolph | 9f8f115 | 2020-05-06 11:58:45 +0200 | [diff] [blame] | 7 | #include <commonlib/region.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 8 | #include <device/pci_def.h> |
| 9 | #include <cpu/x86/smm.h> |
Kyösti Mälkki | e31ec29 | 2019-08-10 17:27:01 +0300 | [diff] [blame] | 10 | #include <cpu/intel/em64t101_save_state.h> |
Duncan Laurie | 51cb26d | 2012-06-23 15:22:43 -0700 | [diff] [blame] | 11 | #include <northbridge/intel/sandybridge/sandybridge.h> |
Kyösti Mälkki | 661ad46 | 2020-12-29 06:26:21 +0200 | [diff] [blame] | 12 | #include <soc/nvs.h> |
Vladimir Serbinenko | 4141b47 | 2015-05-16 13:48:10 +0200 | [diff] [blame] | 13 | #include <southbridge/intel/bd82x6x/me.h> |
Patrick Rudolph | e8e66f4 | 2016-02-06 17:42:42 +0100 | [diff] [blame] | 14 | #include <southbridge/intel/common/gpio.h> |
Vladimir Serbinenko | 4141b47 | 2015-05-16 13:48:10 +0200 | [diff] [blame] | 15 | #include <cpu/intel/model_206ax/model_206ax.h> |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 16 | #include <southbridge/intel/common/pmutil.h> |
Tristan Corrick | 63626b1 | 2018-11-30 22:53:50 +1300 | [diff] [blame] | 17 | #include <southbridge/intel/common/finalize.h> |
Duncan Laurie | 51cb26d | 2012-06-23 15:22:43 -0700 | [diff] [blame] | 18 | |
Elyes HAOUAS | 74aa99a | 2019-03-16 08:40:06 +0100 | [diff] [blame] | 19 | #include "pch.h" |
Elyes HAOUAS | 74aa99a | 2019-03-16 08:40:06 +0100 | [diff] [blame] | 20 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 21 | int southbridge_io_trap_handler(int smif) |
| 22 | { |
| 23 | switch (smif) { |
| 24 | case 0x32: |
| 25 | printk(BIOS_DEBUG, "OS Init\n"); |
| 26 | /* gnvs->smif: |
| 27 | * On success, the IO Trap Handler returns 0 |
| 28 | * On failure, the IO Trap Handler returns a value != 0 |
| 29 | */ |
| 30 | gnvs->smif = 0; |
| 31 | return 1; /* IO trap handled */ |
| 32 | } |
| 33 | |
| 34 | /* Not handled */ |
| 35 | return 0; |
| 36 | } |
| 37 | |
Vladimir Serbinenko | 6a7aeb3 | 2014-01-05 11:37:32 +0100 | [diff] [blame] | 38 | static void southbridge_gate_memory_reset_real(int offset, |
| 39 | u16 use, u16 io, u16 lvl) |
| 40 | { |
| 41 | u32 reg32; |
| 42 | |
| 43 | /* Make sure it is set as GPIO */ |
| 44 | reg32 = inl(use); |
| 45 | if (!(reg32 & (1 << offset))) { |
| 46 | reg32 |= (1 << offset); |
| 47 | outl(reg32, use); |
| 48 | } |
| 49 | |
| 50 | /* Make sure it is set as output */ |
| 51 | reg32 = inl(io); |
| 52 | if (reg32 & (1 << offset)) { |
| 53 | reg32 &= ~(1 << offset); |
| 54 | outl(reg32, io); |
| 55 | } |
| 56 | |
| 57 | /* Drive the output low */ |
| 58 | reg32 = inl(lvl); |
| 59 | reg32 &= ~(1 << offset); |
| 60 | outl(reg32, lvl); |
| 61 | } |
| 62 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 63 | /* |
| 64 | * Drive GPIO 60 low to gate memory reset in S3. |
| 65 | * |
| 66 | * Intel reference designs all use GPIO 60 but it is |
| 67 | * not a requirement and boards could use a different pin. |
| 68 | */ |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 69 | void southbridge_gate_memory_reset(void) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 70 | { |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 71 | u16 gpiobase; |
| 72 | |
Angel Pons | 78c45bd | 2021-01-06 02:40:14 +0100 | [diff] [blame] | 73 | gpiobase = pci_read_config16(PCH_LPC_DEV, GPIOBASE) & 0xfffc; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 74 | if (!gpiobase) |
| 75 | return; |
| 76 | |
Vladimir Serbinenko | 6a7aeb3 | 2014-01-05 11:37:32 +0100 | [diff] [blame] | 77 | if (CONFIG_DRAM_RESET_GATE_GPIO >= 32) |
| 78 | southbridge_gate_memory_reset_real(CONFIG_DRAM_RESET_GATE_GPIO - 32, |
| 79 | gpiobase + GPIO_USE_SEL2, |
| 80 | gpiobase + GP_IO_SEL2, |
| 81 | gpiobase + GP_LVL2); |
| 82 | else |
| 83 | southbridge_gate_memory_reset_real(CONFIG_DRAM_RESET_GATE_GPIO, |
| 84 | gpiobase + GPIO_USE_SEL, |
| 85 | gpiobase + GP_IO_SEL, |
| 86 | gpiobase + GP_LVL); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 87 | } |
| 88 | |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 89 | void southbridge_smi_monitor(void) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 90 | { |
| 91 | #define IOTRAP(x) (trap_sts & (1 << x)) |
| 92 | u32 trap_sts, trap_cycle; |
| 93 | u32 data, mask = 0; |
| 94 | int i; |
| 95 | |
| 96 | trap_sts = RCBA32(0x1e00); // TRSR - Trap Status Register |
| 97 | RCBA32(0x1e00) = trap_sts; // Clear trap(s) in TRSR |
| 98 | |
| 99 | trap_cycle = RCBA32(0x1e10); |
| 100 | for (i=16; i<20; i++) { |
| 101 | if (trap_cycle & (1 << i)) |
| 102 | mask |= (0xff << ((i - 16) << 2)); |
| 103 | } |
| 104 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 105 | /* IOTRAP(3) SMI function call */ |
| 106 | if (IOTRAP(3)) { |
| 107 | if (gnvs && gnvs->smif) |
| 108 | io_trap_handler(gnvs->smif); // call function smif |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | /* IOTRAP(2) currently unused |
| 113 | * IOTRAP(1) currently unused */ |
| 114 | |
| 115 | /* IOTRAP(0) SMIC */ |
| 116 | if (IOTRAP(0)) { |
| 117 | if (!(trap_cycle & (1 << 24))) { // It's a write |
| 118 | printk(BIOS_DEBUG, "SMI1 command\n"); |
| 119 | data = RCBA32(0x1e18); |
| 120 | data &= mask; |
| 121 | // if (smi1) |
Elyes HAOUAS | b0f1988 | 2018-06-09 11:59:00 +0200 | [diff] [blame] | 122 | // southbridge_smi_command(data); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 123 | // return; |
| 124 | } |
| 125 | // Fall through to debug |
| 126 | } |
| 127 | |
| 128 | printk(BIOS_DEBUG, " trapped io address = 0x%x\n", trap_cycle & 0xfffc); |
Elyes HAOUAS | 70d79a4 | 2016-08-21 18:36:06 +0200 | [diff] [blame] | 129 | for (i=0; i < 4; i++) if (IOTRAP(i)) printk(BIOS_DEBUG, " TRAP = %d\n", i); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 130 | printk(BIOS_DEBUG, " AHBE = %x\n", (trap_cycle >> 16) & 0xf); |
| 131 | printk(BIOS_DEBUG, " MASK = 0x%08x\n", mask); |
| 132 | printk(BIOS_DEBUG, " read/write: %s\n", (trap_cycle & (1 << 24)) ? "read" : "write"); |
| 133 | |
| 134 | if (!(trap_cycle & (1 << 24))) { |
| 135 | /* Write Cycle */ |
| 136 | data = RCBA32(0x1e18); |
| 137 | printk(BIOS_DEBUG, " iotrap written data = 0x%08x\n", data); |
| 138 | } |
| 139 | #undef IOTRAP |
| 140 | } |
| 141 | |
Angel Pons | 2fa7f07 | 2021-01-06 00:48:39 +0100 | [diff] [blame] | 142 | /* |
| 143 | * PCH BIOS Spec Rev 0.7.0, Section 13.5 |
| 144 | * Additional xHCI Controller Configurations Prior to Entering S3/S4 |
| 145 | */ |
| 146 | static void xhci_a0_suspend_smm_workaround(void) |
| 147 | { |
| 148 | /* Workaround only applies to Panther Point stepping A0 */ |
| 149 | if (pch_silicon_revision() != PCH_STEP_A0) |
| 150 | return; |
| 151 | |
| 152 | /* The BAR is 64-bit, account for it being above 4 GiB */ |
| 153 | if (pci_read_config32(PCH_XHCI_DEV, PCI_BASE_ADDRESS_0 + 4)) |
| 154 | return; |
| 155 | |
| 156 | /* PCH datasheet indicates that only the upper 16 bits are valid */ |
| 157 | uintptr_t xhci_bar = pci_read_config32(PCH_XHCI_DEV, PCI_BASE_ADDRESS_0) & |
| 158 | ~PCI_BASE_ADDRESS_MEM_ATTR_MASK; |
| 159 | |
| 160 | if (smm_points_to_smram((void *)xhci_bar, 64 * KiB)) |
| 161 | return; |
| 162 | |
| 163 | /* Step 1: Set power state to D0 */ |
| 164 | pci_and_config16(PCH_XHCI_DEV, XHCI_PWR_CNTL_STS, ~(3 << 0)); |
| 165 | |
| 166 | /* Step 2 */ |
| 167 | pci_or_config16(PCH_XHCI_DEV, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY); |
| 168 | |
| 169 | /* Steps 3 to 6: If USB3 PORTSC current connect status (bit 0) is set, do IOBP magic */ |
| 170 | for (unsigned int port = 0; port < 4; port++) { |
| 171 | if (read32((void *)(xhci_bar + XHCI_PORTSC_x_USB3(port))) & (1 << 0)) |
| 172 | pch_iobp_update(0xec000082 + 0x100 * port, ~0, 3 << 2); |
| 173 | } |
| 174 | |
| 175 | /* Step 7 */ |
| 176 | pci_and_config16(PCH_XHCI_DEV, PCI_COMMAND, ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY)); |
| 177 | |
| 178 | /* Step 8: Set power state to D3 */ |
| 179 | pci_or_config16(PCH_XHCI_DEV, XHCI_PWR_CNTL_STS, 3 << 0); |
| 180 | } |
| 181 | |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 182 | void southbridge_smm_xhci_sleep(u8 slp_type) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 183 | { |
Angel Pons | 2fa7f07 | 2021-01-06 00:48:39 +0100 | [diff] [blame] | 184 | /* Only Panther Point has xHCI */ |
| 185 | if (pch_silicon_type() != PCH_TYPE_PPT) |
| 186 | return; |
| 187 | |
| 188 | /* Verify that RCBA is still valid */ |
Angel Pons | 6e732d3 | 2021-01-28 13:56:18 +0100 | [diff] [blame] | 189 | if (pci_read_config32(PCH_LPC_DEV, RCBA) != (CONFIG_FIXED_RCBA_MMIO_BASE | RCBA_ENABLE)) |
Angel Pons | 2fa7f07 | 2021-01-06 00:48:39 +0100 | [diff] [blame] | 190 | return; |
| 191 | |
| 192 | if (RCBA32(FD) & PCH_DISABLE_XHCI) |
| 193 | return; |
| 194 | |
| 195 | switch (slp_type) { |
| 196 | case ACPI_S3: |
| 197 | case ACPI_S4: |
| 198 | xhci_a0_suspend_smm_workaround(); |
| 199 | break; |
| 200 | |
| 201 | case ACPI_S5: |
| 202 | /* |
| 203 | * PCH BIOS Spec Rev 0.7.0, Section 13.5 |
| 204 | * Additional xHCI Controller Configurations Prior to Entering S5 |
| 205 | * |
| 206 | * For all steppings: |
| 207 | * Step 1: Set power state to D3 (bits 1:0) |
| 208 | * Step 2: Set PME# enable bit (bit 8) |
| 209 | */ |
| 210 | pci_or_config16(PCH_XHCI_DEV, XHCI_PWR_CNTL_STS, 1 << 8 | 3 << 0); |
| 211 | break; |
| 212 | } |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 213 | } |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 214 | |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 215 | void southbridge_finalize_all(void) |
| 216 | { |
| 217 | intel_me_finalize_smm(); |
| 218 | intel_pch_finalize_smm(); |
| 219 | intel_sandybridge_finalize_smm(); |
| 220 | intel_model_206ax_finalize_smm(); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 221 | } |