Debian Codegraph @

src/southbridge/intel/bd82x6x/smihandler.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <arch/io.h>
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>
13 #include <gpio.h>
14 #include <soc/nvs.h>
15 #include <southbridge/intel/bd82x6x/me.h>
16 #include <southbridge/intel/common/finalize.h>
17 #include <southbridge/intel/common/pmutil.h>
18 #include <types.h>
19
20 #include "pch.h"
21
22 /*
23 * Drive reset gate GPIO low to gate memory reset in S3.
24 *
25 * Intel reference designs all use GPIO 60 but it is
26 * not a requirement and boards could use a different pin.
27 */
28 void southbridge_gate_memory_reset(void)
29 {
30
31 gpio_output(CONFIG_DRAM_RESET_GATE_GPIO, 0);
32 }
33
34 void southbridge_smi_monitor(void)
35 {
36 #define IOTRAP(x) (trap_sts & (1 << x))
37 u32 trap_sts, trap_cycle;
38 u32 data, mask = 0;
39 int i;
40
41 trap_sts = RCBA32(0x1e00); // TRSR - Trap Status Register
42 RCBA32(0x1e00) = trap_sts; // Clear trap(s) in TRSR
43
44 trap_cycle = RCBA32(0x1e10);
45 for (i=16; i<20; i++) {
46 if (trap_cycle & (1 << i))
47 mask |= (0xff << ((i - 16) << 3));
48 }
49
50 /* IOTRAP(3) SMI function call */
51 if (IOTRAP(3)) {
52 if (gnvs && gnvs->smif)
53 io_trap_handler(gnvs->smif); // call function smif
54 return;
55 }
56
57 /* IOTRAP(2) currently unused
58 * IOTRAP(1) currently unused */
59
60 /* IOTRAP(0) SMIC */
61 if (IOTRAP(0)) {
62 if (!(trap_cycle & (1 << 24))) { // It's a write
63 printk(BIOS_DEBUG, "SMI1 command\n");
64 data = RCBA32(0x1e18);
65 data &= mask;
66 // if (smi1)
67 // southbridge_smi_command(data);
68 // return;
69 }
70 // Fall through to debug
71 }
72
73 printk(BIOS_DEBUG, " trapped io address = 0x%x\n", trap_cycle & 0xfffc);
74 for (i=0; i < 4; i++) if (IOTRAP(i)) printk(BIOS_DEBUG, " TRAP = %d\n", i);
75 printk(BIOS_DEBUG, " AHBE = %x\n", (trap_cycle >> 16) & 0xf);
76 printk(BIOS_DEBUG, " MASK = 0x%08x\n", mask);
77 printk(BIOS_DEBUG, " read/write: %s\n", (trap_cycle & (1 << 24)) ? "read" : "write");
78
79 if (!(trap_cycle & (1 << 24))) {
80 /* Write Cycle */
81 data = RCBA32(0x1e18);
82 printk(BIOS_DEBUG, " iotrap written data = 0x%08x\n", data);
83 }
84 #undef IOTRAP
85 }
86
87 /*
88 * PCH BIOS Spec Rev 0.7.0, Section 13.5
89 * Additional xHCI Controller Configurations Prior to Entering S3/S4
90 */
91 static void xhci_a0_suspend_smm_workaround(void)
92 {
93 /* Workaround only applies to Panther Point stepping A0 */
94 if (pch_silicon_revision() != PCH_STEP_A0)
95 return;
96
97 /* The BAR is 64-bit, account for it being above 4 GiB */
98 if (pci_read_config32(PCH_XHCI_DEV, PCI_BASE_ADDRESS_0 + 4))
99 return;
100
101 /* PCH datasheet indicates that only the upper 16 bits are valid */
102 uintptr_t xhci_bar = pci_read_config32(PCH_XHCI_DEV, PCI_BASE_ADDRESS_0) &
103 ~PCI_BASE_ADDRESS_MEM_ATTR_MASK;
104
105 if (smm_points_to_smram((void *)xhci_bar, 64 * KiB))
106 return;
107
108 /* Step 1: Set power state to D0 */
109 pci_and_config16(PCH_XHCI_DEV, XHCI_PWR_CNTL_STS, ~(3 << 0));
110
111 /* Step 2 */
112 pci_or_config16(PCH_XHCI_DEV, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
113
114 /* Steps 3 to 6: If USB3 PORTSC current connect status (bit 0) is set, do IOBP magic */
115 for (unsigned int port = 0; port < 4; port++) {
116 if (read32p((xhci_bar + XHCI_PORTSC_x_USB3(port))) & (1 << 0))
117 pch_iobp_update(0xec000082 + 0x100 * port, ~0, 3 << 2);
118 }
119
120 /* Step 7 */
121 pci_and_config16(PCH_XHCI_DEV, PCI_COMMAND, ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY));
122
123 /* Step 8: Set power state to D3 */
124 pci_or_config16(PCH_XHCI_DEV, XHCI_PWR_CNTL_STS, 3 << 0);
125 }
126
127 void southbridge_smm_xhci_sleep(u8 slp_type)
128 {
129 /* Only Panther Point has xHCI */
130 if (pch_silicon_type() != PCH_TYPE_PPT)
131 return;
132
133 /* Verify that RCBA is still valid */
134 if (pci_read_config32(PCH_LPC_DEV, RCBA) != (CONFIG_FIXED_RCBA_MMIO_BASE | RCBA_ENABLE))
135 return;
136
137 if (RCBA32(FD) & PCH_DISABLE_XHCI)
138 return;
139
140 switch (slp_type) {
141 case ACPI_S3:
142 case ACPI_S4:
143 xhci_a0_suspend_smm_workaround();
144 break;
145
146 case ACPI_S5:
147 /*
148 * PCH BIOS Spec Rev 0.7.0, Section 13.5
149 * Additional xHCI Controller Configurations Prior to Entering S5
150 *
151 * For all steppings:
152 * Step 1: Set power state to D3 (bits 1:0)
153 * Step 2: Set PME# enable bit (bit 8)
154 */
155 pci_or_config16(PCH_XHCI_DEV, XHCI_PWR_CNTL_STS, 1 << 8 | 3 << 0);
156 break;
157 }
158 }
159
160 void southbridge_finalize_all(void)
161 {
162 intel_me_finalize_smm();
163 intel_pch_finalize_smm();
164 intel_sandybridge_finalize_smm();
165 intel_model_206ax_finalize_smm();
166 }