1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <commonlib/region.h>
5 #include <console/console.h>
6 #include <cpu/intel/em64t101_save_state.h>
7 #include <cpu/intel/model_206ax/model_206ax.h>
8 #include <cpu/x86/smm.h>
9 #include <device/mmio.h>
10 #include <device/pci_def.h>
11 #include <device/pci_ops.h>
12 #include <northbridge/intel/sandybridge/sandybridge.h>
14 #include <southbridge/intel/bd82x6x/me.h>
15 #include <southbridge/intel/common/finalize.h>
16 #include <southbridge/intel/common/gpio.h>
17 #include <southbridge/intel/common/pmutil.h>
22 static void southbridge_gate_memory_reset_real(int offset
,
23 u16 use
, u16 io
, u16 lvl
)
27 /* Make sure it is set as GPIO */
29 if (!(reg32
& (1 << offset
))) {
30 reg32
|= (1 << offset
);
34 /* Make sure it is set as output */
36 if (reg32
& (1 << offset
)) {
37 reg32
&= ~(1 << offset
);
41 /* Drive the output low */
43 reg32
&= ~(1 << offset
);
48 * Drive GPIO 60 low to gate memory reset in S3.
50 * Intel reference designs all use GPIO 60 but it is
51 * not a requirement and boards could use a different pin.
53 void southbridge_gate_memory_reset(void)
57 gpiobase
= pci_read_config16(PCH_LPC_DEV
, GPIOBASE
) & 0xfffc;
61 if (CONFIG_DRAM_RESET_GATE_GPIO
>= 32)
62 southbridge_gate_memory_reset_real(CONFIG_DRAM_RESET_GATE_GPIO
- 32,
63 gpiobase
+ GPIO_USE_SEL2
,
64 gpiobase
+ GP_IO_SEL2
,
67 southbridge_gate_memory_reset_real(CONFIG_DRAM_RESET_GATE_GPIO
,
68 gpiobase
+ GPIO_USE_SEL
,
73 void southbridge_smi_monitor(void)
75 #define IOTRAP(x) (trap_sts & (1 << x))
76 u32 trap_sts
, trap_cycle
;
80 trap_sts
= RCBA32(0x1e00); // TRSR - Trap Status Register
81 RCBA32(0x1e00) = trap_sts
; // Clear trap(s) in TRSR
83 trap_cycle
= RCBA32(0x1e10);
84 for (i
=16; i
<20; i
++) {
85 if (trap_cycle
& (1 << i
))
86 mask
|= (0xff << ((i
- 16) << 3));
89 /* IOTRAP(3) SMI function call */
91 if (gnvs
&& gnvs
->smif
)
92 io_trap_handler(gnvs
->smif
); // call function smif
96 /* IOTRAP(2) currently unused
97 * IOTRAP(1) currently unused */
101 if (!(trap_cycle
& (1 << 24))) { // It's a write
102 printk(BIOS_DEBUG
, "SMI1 command\n");
103 data
= RCBA32(0x1e18);
106 // southbridge_smi_command(data);
109 // Fall through to debug
112 printk(BIOS_DEBUG
, " trapped io address = 0x%x\n", trap_cycle
& 0xfffc);
113 for (i
=0; i
< 4; i
++) if (IOTRAP(i
)) printk(BIOS_DEBUG
, " TRAP = %d\n", i
);
114 printk(BIOS_DEBUG
, " AHBE = %x\n", (trap_cycle
>> 16) & 0xf);
115 printk(BIOS_DEBUG
, " MASK = 0x%08x\n", mask
);
116 printk(BIOS_DEBUG
, " read/write: %s\n", (trap_cycle
& (1 << 24)) ? "read" : "write");
118 if (!(trap_cycle
& (1 << 24))) {
120 data
= RCBA32(0x1e18);
121 printk(BIOS_DEBUG
, " iotrap written data = 0x%08x\n", data
);
127 * PCH BIOS Spec Rev 0.7.0, Section 13.5
128 * Additional xHCI Controller Configurations Prior to Entering S3/S4
130 static void xhci_a0_suspend_smm_workaround(void)
132 /* Workaround only applies to Panther Point stepping A0 */
133 if (pch_silicon_revision() != PCH_STEP_A0
)
136 /* The BAR is 64-bit, account for it being above 4 GiB */
137 if (pci_read_config32(PCH_XHCI_DEV
, PCI_BASE_ADDRESS_0
+ 4))
140 /* PCH datasheet indicates that only the upper 16 bits are valid */
141 uintptr_t xhci_bar
= pci_read_config32(PCH_XHCI_DEV
, PCI_BASE_ADDRESS_0
) &
142 ~PCI_BASE_ADDRESS_MEM_ATTR_MASK
;
144 if (smm_points_to_smram((void *)xhci_bar
, 64 * KiB
))
147 /* Step 1: Set power state to D0 */
148 pci_and_config16(PCH_XHCI_DEV
, XHCI_PWR_CNTL_STS
, ~(3 << 0));
151 pci_or_config16(PCH_XHCI_DEV
, PCI_COMMAND
, PCI_COMMAND_MASTER
| PCI_COMMAND_MEMORY
);
153 /* Steps 3 to 6: If USB3 PORTSC current connect status (bit 0) is set, do IOBP magic */
154 for (unsigned int port
= 0; port
< 4; port
++) {
155 if (read32p((xhci_bar
+ XHCI_PORTSC_x_USB3(port
))) & (1 << 0))
156 pch_iobp_update(0xec000082 + 0x100 * port
, ~0, 3 << 2);
160 pci_and_config16(PCH_XHCI_DEV
, PCI_COMMAND
, ~(PCI_COMMAND_MASTER
| PCI_COMMAND_MEMORY
));
162 /* Step 8: Set power state to D3 */
163 pci_or_config16(PCH_XHCI_DEV
, XHCI_PWR_CNTL_STS
, 3 << 0);
166 void southbridge_smm_xhci_sleep(u8 slp_type
)
168 /* Only Panther Point has xHCI */
169 if (pch_silicon_type() != PCH_TYPE_PPT
)
172 /* Verify that RCBA is still valid */
173 if (pci_read_config32(PCH_LPC_DEV
, RCBA
) != (CONFIG_FIXED_RCBA_MMIO_BASE
| RCBA_ENABLE
))
176 if (RCBA32(FD
) & PCH_DISABLE_XHCI
)
182 xhci_a0_suspend_smm_workaround();
187 * PCH BIOS Spec Rev 0.7.0, Section 13.5
188 * Additional xHCI Controller Configurations Prior to Entering S5
191 * Step 1: Set power state to D3 (bits 1:0)
192 * Step 2: Set PME# enable bit (bit 8)
194 pci_or_config16(PCH_XHCI_DEV
, XHCI_PWR_CNTL_STS
, 1 << 8 | 3 << 0);
199 void southbridge_finalize_all(void)
201 intel_me_finalize_smm();
202 intel_pch_finalize_smm();
203 intel_sandybridge_finalize_smm();
204 intel_model_206ax_finalize_smm();