blob: 28337f69133f9686da3be1d23bc773a57956c80c [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer8e073822012-04-04 00:07:22 +02002
3#include <types.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +02004#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +02006#include <console/console.h>
Patrick Rudolph9f8f1152020-05-06 11:58:45 +02007#include <commonlib/region.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +02008#include <device/pci_def.h>
9#include <cpu/x86/smm.h>
Kyösti Mälkkie31ec292019-08-10 17:27:01 +030010#include <cpu/intel/em64t101_save_state.h>
Duncan Laurie51cb26d2012-06-23 15:22:43 -070011#include <northbridge/intel/sandybridge/sandybridge.h>
Kyösti Mälkki661ad462020-12-29 06:26:21 +020012#include <soc/nvs.h>
Vladimir Serbinenko4141b472015-05-16 13:48:10 +020013#include <southbridge/intel/bd82x6x/me.h>
Patrick Rudolphe8e66f42016-02-06 17:42:42 +010014#include <southbridge/intel/common/gpio.h>
Vladimir Serbinenko4141b472015-05-16 13:48:10 +020015#include <cpu/intel/model_206ax/model_206ax.h>
Arthur Heymansa0508172018-01-25 11:30:22 +010016#include <southbridge/intel/common/pmutil.h>
Tristan Corrick63626b12018-11-30 22:53:50 +130017#include <southbridge/intel/common/finalize.h>
Duncan Laurie51cb26d2012-06-23 15:22:43 -070018
Elyes HAOUAS74aa99a2019-03-16 08:40:06 +010019#include "pch.h"
Elyes HAOUAS74aa99a2019-03-16 08:40:06 +010020
Stefan Reinauer8e073822012-04-04 00:07:22 +020021int 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 Serbinenko6a7aeb32014-01-05 11:37:32 +010038static 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 Reinauer8e073822012-04-04 00:07:22 +020063/*
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 Heymansa0508172018-01-25 11:30:22 +010069void southbridge_gate_memory_reset(void)
Stefan Reinauer8e073822012-04-04 00:07:22 +020070{
Stefan Reinauer8e073822012-04-04 00:07:22 +020071 u16 gpiobase;
72
Angel Pons78c45bd2021-01-06 02:40:14 +010073 gpiobase = pci_read_config16(PCH_LPC_DEV, GPIOBASE) & 0xfffc;
Stefan Reinauer8e073822012-04-04 00:07:22 +020074 if (!gpiobase)
75 return;
76
Vladimir Serbinenko6a7aeb32014-01-05 11:37:32 +010077 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 Reinauer8e073822012-04-04 00:07:22 +020087}
88
Arthur Heymansa0508172018-01-25 11:30:22 +010089void southbridge_smi_monitor(void)
Stefan Reinauer8e073822012-04-04 00:07:22 +020090{
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 Reinauer8e073822012-04-04 00:07:22 +0200105 /* 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 HAOUASb0f19882018-06-09 11:59:00 +0200122 // southbridge_smi_command(data);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200123 // return;
124 }
125 // Fall through to debug
126 }
127
128 printk(BIOS_DEBUG, " trapped io address = 0x%x\n", trap_cycle & 0xfffc);
Elyes HAOUAS70d79a42016-08-21 18:36:06 +0200129 for (i=0; i < 4; i++) if (IOTRAP(i)) printk(BIOS_DEBUG, " TRAP = %d\n", i);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200130 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 Pons2fa7f072021-01-06 00:48:39 +0100142/*
143 * PCH BIOS Spec Rev 0.7.0, Section 13.5
144 * Additional xHCI Controller Configurations Prior to Entering S3/S4
145 */
146static 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 Heymansa0508172018-01-25 11:30:22 +0100182void southbridge_smm_xhci_sleep(u8 slp_type)
Stefan Reinauer8e073822012-04-04 00:07:22 +0200183{
Angel Pons2fa7f072021-01-06 00:48:39 +0100184 /* Only Panther Point has xHCI */
185 if (pch_silicon_type() != PCH_TYPE_PPT)
186 return;
187
188 /* Verify that RCBA is still valid */
Angel Pons6e732d32021-01-28 13:56:18 +0100189 if (pci_read_config32(PCH_LPC_DEV, RCBA) != (CONFIG_FIXED_RCBA_MMIO_BASE | RCBA_ENABLE))
Angel Pons2fa7f072021-01-06 00:48:39 +0100190 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 Heymansa0508172018-01-25 11:30:22 +0100213}
Stefan Reinauer8e073822012-04-04 00:07:22 +0200214
Arthur Heymansa0508172018-01-25 11:30:22 +0100215void 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 Reinauer8e073822012-04-04 00:07:22 +0200221}