blob: 8caafb716fdaed51ba25c60eb824fdabfa931fc0 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin76c37002012-10-30 09:03:43 -05002
3#include <types.h>
Aaron Durbin76c37002012-10-30 09:03:43 -05004#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Aaron Durbin76c37002012-10-30 09:03:43 -05006#include <console/console.h>
7#include <cpu/x86/cache.h>
8#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>
Aaron Durbin76c37002012-10-30 09:03:43 -050011#include <elog.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010012#include <halt.h>
Kyösti Mälkkicbf95712020-01-05 08:05:45 +020013#include <option.h>
Tristan Corrick63626b12018-11-30 22:53:50 +130014#include <southbridge/intel/common/finalize.h>
Tristan Corrick09fc6342018-11-30 22:53:01 +130015#include <northbridge/intel/haswell/haswell.h>
16#include <cpu/intel/haswell/haswell.h>
Kyösti Mälkki661ad462020-12-29 06:26:21 +020017#include <soc/nvs.h>
Matt DeVillier8187f112018-12-24 21:46:46 -060018#include <smmstore.h>
Tristan Corrick63626b12018-11-30 22:53:50 +130019#include "me.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050020#include "pch.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050021
Aaron Durbin76c37002012-10-30 09:03:43 -050022/**
23 * @brief Set the EOS bit
24 */
25void southbridge_smi_set_eos(void)
26{
Duncan Laurie467f31d2013-03-08 17:00:37 -080027 enable_smi(EOS);
Aaron Durbin76c37002012-10-30 09:03:43 -050028}
29
30static void busmaster_disable_on_bus(int bus)
31{
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020032 int slot, func;
33 unsigned int val;
34 unsigned char hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -050035
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020036 for (slot = 0; slot < 0x20; slot++) {
37 for (func = 0; func < 8; func++) {
Elyes HAOUAS68c851b2018-06-12 22:06:09 +020038 pci_devfn_t dev = PCI_DEV(bus, slot, func);
Aaron Durbin76c37002012-10-30 09:03:43 -050039
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020040 val = pci_read_config32(dev, PCI_VENDOR_ID);
Aaron Durbin76c37002012-10-30 09:03:43 -050041
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020042 if (val == 0xffffffff || val == 0x00000000 ||
43 val == 0x0000ffff || val == 0xffff0000)
44 continue;
Aaron Durbin76c37002012-10-30 09:03:43 -050045
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020046 /* Disable Bus Mastering for this one device */
Angel Ponsbf9bc502020-06-08 00:12:43 +020047 pci_and_config16(dev, PCI_COMMAND, ~PCI_COMMAND_MASTER);
Aaron Durbin76c37002012-10-30 09:03:43 -050048
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020049 /* If this is a bridge, then follow it. */
50 hdr = pci_read_config8(dev, PCI_HEADER_TYPE);
51 hdr &= 0x7f;
52 if (hdr == PCI_HEADER_TYPE_BRIDGE ||
53 hdr == PCI_HEADER_TYPE_CARDBUS) {
54 unsigned int buses;
55 buses = pci_read_config32(dev, PCI_PRIMARY_BUS);
56 busmaster_disable_on_bus((buses >> 8) & 0xff);
57 }
58 }
59 }
Aaron Durbin76c37002012-10-30 09:03:43 -050060}
61
Kyösti Mälkki3c181862021-01-08 19:01:30 +020062static int power_on_after_fail(void)
Aaron Durbin76c37002012-10-30 09:03:43 -050063{
Angel Pons2aaf7c02020-09-24 18:03:18 +020064 /* save and recover RTC port values */
Aaron Durbin76c37002012-10-30 09:03:43 -050065 u8 tmp70, tmp72;
66 tmp70 = inb(0x70);
67 tmp72 = inb(0x72);
Angel Pons88dcb312021-04-26 17:10:28 +020068 const unsigned int s5pwr = get_uint_option("power_on_after_fail",
Angel Pons62719a32021-04-19 13:15:28 +020069 CONFIG_MAINBOARD_POWER_FAILURE_STATE);
Aaron Durbin76c37002012-10-30 09:03:43 -050070 outb(tmp70, 0x70);
71 outb(tmp72, 0x72);
72
Kyösti Mälkki3c181862021-01-08 19:01:30 +020073 /* For "KEEP", switch to "OFF" - KEEP is software emulated. */
74 return (s5pwr == MAINBOARD_POWER_ON);
75}
76
77static void southbridge_smi_sleep(void)
78{
79 u32 reg32;
80 u8 slp_typ;
81 u16 pmbase = get_pmbase();
82
Aaron Durbin76c37002012-10-30 09:03:43 -050083 /* First, disable further SMIs */
Duncan Laurie467f31d2013-03-08 17:00:37 -080084 disable_smi(SLP_SMI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -050085
86 /* Figure out SLP_TYP */
87 reg32 = inl(pmbase + PM1_CNT);
88 printk(BIOS_SPEW, "SMI#: SLP = 0x%08x\n", reg32);
Aaron Durbinda5f5092016-07-13 23:23:16 -050089 slp_typ = acpi_sleep_from_pm1(reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -050090
91 /* Do any mainboard sleep handling */
Aaron Durbinda5f5092016-07-13 23:23:16 -050092 mainboard_smi_sleep(slp_typ);
Aaron Durbin76c37002012-10-30 09:03:43 -050093
Duncan Laurie2d9d39a2013-05-29 15:27:55 -070094 /* USB sleep preparations */
Julius Wernercd49cce2019-03-05 16:53:33 -080095#if !CONFIG(FINALIZE_USB_ROUTE_XHCI)
Duncan Laurie1f529082013-07-30 15:53:45 -070096 usb_ehci_sleep_prepare(PCH_EHCI1_DEV, slp_typ);
97 usb_ehci_sleep_prepare(PCH_EHCI2_DEV, slp_typ);
Duncan Laurie911cedf2013-07-30 16:05:55 -070098#endif
Duncan Laurie1f529082013-07-30 15:53:45 -070099 usb_xhci_sleep_prepare(PCH_XHCI_DEV, slp_typ);
Duncan Laurie2d9d39a2013-05-29 15:27:55 -0700100
Aaron Durbin76c37002012-10-30 09:03:43 -0500101 /* Log S3, S4, and S5 entry */
Aaron Durbinda5f5092016-07-13 23:23:16 -0500102 if (slp_typ >= ACPI_S3)
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +0200103 elog_gsmi_add_event_byte(ELOG_TYPE_ACPI_ENTER, slp_typ);
Aaron Durbin76c37002012-10-30 09:03:43 -0500104
105 /* Next, do the deed.
106 */
107
108 switch (slp_typ) {
Aaron Durbinda5f5092016-07-13 23:23:16 -0500109 case ACPI_S0:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800110 printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n");
111 break;
Aaron Durbinda5f5092016-07-13 23:23:16 -0500112 case ACPI_S1:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800113 printk(BIOS_DEBUG, "SMI#: Entering S1 (Assert STPCLK#)\n");
114 break;
Aaron Durbinda5f5092016-07-13 23:23:16 -0500115 case ACPI_S3:
Aaron Durbin76c37002012-10-30 09:03:43 -0500116 printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n");
117
Aaron Durbin76c37002012-10-30 09:03:43 -0500118 /* Invalidate the cache before going to S3 */
119 wbinvd();
120 break;
Aaron Durbinda5f5092016-07-13 23:23:16 -0500121 case ACPI_S4:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800122 printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n");
123 break;
Aaron Durbinda5f5092016-07-13 23:23:16 -0500124 case ACPI_S5:
Aaron Durbin76c37002012-10-30 09:03:43 -0500125 printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n");
126
Duncan Laurie467f31d2013-03-08 17:00:37 -0800127 /* Disable all GPE */
128 disable_all_gpe();
Aaron Durbin76c37002012-10-30 09:03:43 -0500129
Kyösti Mälkki3c181862021-01-08 19:01:30 +0200130 /* Always set the flag in case CMOS was changed on runtime. */
131 if (power_on_after_fail())
132 pci_and_config8(PCH_LPC_DEV, GEN_PMCON_3, ~1);
Angel Pons2aaf7c02020-09-24 18:03:18 +0200133 else
Kyösti Mälkki3c181862021-01-08 19:01:30 +0200134 pci_or_config8(PCH_LPC_DEV, GEN_PMCON_3, 1);
Aaron Durbin76c37002012-10-30 09:03:43 -0500135
136 /* also iterates over all bridges on bus 0 */
137 busmaster_disable_on_bus(0);
138 break;
Duncan Laurie467f31d2013-03-08 17:00:37 -0800139 default:
140 printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n");
141 break;
Aaron Durbin76c37002012-10-30 09:03:43 -0500142 }
143
Angel Pons2aaf7c02020-09-24 18:03:18 +0200144 /*
145 * Write back to the SLP register to cause the originally intended
Aaron Durbin76c37002012-10-30 09:03:43 -0500146 * event again. We need to set BIT13 (SLP_EN) though to make the
147 * sleep happen.
148 */
Duncan Laurie467f31d2013-03-08 17:00:37 -0800149 enable_pm1_control(SLP_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500150
151 /* Make sure to stop executing code here for S3/S4/S5 */
Aaron Durbinda5f5092016-07-13 23:23:16 -0500152 if (slp_typ >= ACPI_S3)
Patrick Georgi546953c2014-11-29 10:38:17 +0100153 halt();
Aaron Durbin76c37002012-10-30 09:03:43 -0500154
Angel Pons2aaf7c02020-09-24 18:03:18 +0200155 /*
156 * In most sleep states, the code flow of this function ends at
Aaron Durbin76c37002012-10-30 09:03:43 -0500157 * the line above. However, if we entered sleep state S1 and wake
158 * up again, we will continue to execute code in this function.
159 */
160 reg32 = inl(pmbase + PM1_CNT);
161 if (reg32 & SCI_EN) {
162 /* The OS is not an ACPI OS, so we set the state to S0 */
Duncan Laurie467f31d2013-03-08 17:00:37 -0800163 disable_pm1_control(SLP_EN | SLP_TYP);
Aaron Durbin76c37002012-10-30 09:03:43 -0500164 }
165}
166
167/*
168 * Look for Synchronous IO SMI and use save state from that
169 * core in case we are not running on the same core that
170 * initiated the IO transaction.
171 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500172static em64t101_smm_state_save_area_t *smi_apmc_find_state_save(u8 cmd)
173{
174 em64t101_smm_state_save_area_t *state;
Aaron Durbin76c37002012-10-30 09:03:43 -0500175 int node;
176
177 /* Check all nodes looking for the one that issued the IO */
178 for (node = 0; node < CONFIG_MAX_CPUS; node++) {
Aaron Durbin29ffa542012-12-21 21:21:48 -0600179 state = smm_get_save_state(node);
Aaron Durbin76c37002012-10-30 09:03:43 -0500180
Elyes HAOUAS581fe582018-04-26 09:57:07 +0200181 /* Check for Synchronous IO (bit0 == 1) */
Aaron Durbin76c37002012-10-30 09:03:43 -0500182 if (!(state->io_misc_info & (1 << 0)))
183 continue;
184
Elyes HAOUAS581fe582018-04-26 09:57:07 +0200185 /* Make sure it was a write (bit4 == 0) */
Aaron Durbin76c37002012-10-30 09:03:43 -0500186 if (state->io_misc_info & (1 << 4))
187 continue;
188
189 /* Check for APMC IO port */
190 if (((state->io_misc_info >> 16) & 0xff) != APM_CNT)
191 continue;
192
193 /* Check AX against the requested command */
194 if ((state->rax & 0xff) != cmd)
195 continue;
196
197 return state;
198 }
199
200 return NULL;
201}
202
Aaron Durbin76c37002012-10-30 09:03:43 -0500203static void southbridge_smi_gsmi(void)
204{
205 u32 *ret, *param;
206 u8 sub_command;
207 em64t101_smm_state_save_area_t *io_smi =
Patrick Georgid61839c2018-12-03 16:10:33 +0100208 smi_apmc_find_state_save(APM_CNT_ELOG_GSMI);
Aaron Durbin76c37002012-10-30 09:03:43 -0500209
210 if (!io_smi)
211 return;
212
213 /* Command and return value in EAX */
Angel Pons2aaf7c02020-09-24 18:03:18 +0200214 ret = (u32 *)&io_smi->rax;
Aaron Durbin76c37002012-10-30 09:03:43 -0500215 sub_command = (u8)(*ret >> 8);
216
217 /* Parameter buffer in EBX */
Angel Pons2aaf7c02020-09-24 18:03:18 +0200218 param = (u32 *)&io_smi->rbx;
Aaron Durbin76c37002012-10-30 09:03:43 -0500219
220 /* drivers/elog/gsmi.c */
221 *ret = gsmi_exec(sub_command, param);
222}
Aaron Durbin76c37002012-10-30 09:03:43 -0500223
Matt DeVillier8187f112018-12-24 21:46:46 -0600224static void southbridge_smi_store(void)
225{
226 u8 sub_command, ret;
227 em64t101_smm_state_save_area_t *io_smi =
228 smi_apmc_find_state_save(APM_CNT_SMMSTORE);
229 uint32_t reg_ebx;
230
231 if (!io_smi)
232 return;
233 /* Command and return value in EAX */
234 sub_command = (io_smi->rax >> 8) & 0xff;
235
236 /* Parameter buffer in EBX */
237 reg_ebx = io_smi->rbx;
238
239 /* drivers/smmstore/smi.c */
240 ret = smmstore_exec(sub_command, (void *)reg_ebx);
241 io_smi->rax = ret;
242}
243
Aaron Durbin29ffa542012-12-21 21:21:48 -0600244static void southbridge_smi_apmc(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500245{
Aaron Durbin76c37002012-10-30 09:03:43 -0500246 u8 reg8;
Tristan Corrick09fc6342018-11-30 22:53:01 +1300247 static int chipset_finalized = 0;
Aaron Durbin76c37002012-10-30 09:03:43 -0500248
Kyösti Mälkki9a1620f2021-01-08 13:27:33 +0200249 reg8 = apm_get_apmc();
Aaron Durbin76c37002012-10-30 09:03:43 -0500250 switch (reg8) {
Tristan Corrick09fc6342018-11-30 22:53:01 +1300251 case APM_CNT_FINALIZE:
252 if (chipset_finalized) {
253 printk(BIOS_DEBUG, "SMI#: Already finalized\n");
254 return;
255 }
256
257 intel_pch_finalize_smm();
Tristan Corrick09fc6342018-11-30 22:53:01 +1300258 intel_cpu_haswell_finalize_smm();
259
260 chipset_finalized = 1;
261 break;
Aaron Durbin76c37002012-10-30 09:03:43 -0500262 case APM_CNT_ACPI_DISABLE:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800263 disable_pm1_control(SCI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500264 break;
265 case APM_CNT_ACPI_ENABLE:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800266 enable_pm1_control(SCI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500267 break;
Kyösti Mälkkib486f292020-06-18 14:05:35 +0300268 case APM_CNT_ROUTE_ALL_XHCI:
Duncan Laurie911cedf2013-07-30 16:05:55 -0700269 usb_xhci_route_all();
Duncan Laurie911cedf2013-07-30 16:05:55 -0700270 break;
Patrick Georgid61839c2018-12-03 16:10:33 +0100271 case APM_CNT_ELOG_GSMI:
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +0200272 if (CONFIG(ELOG_GSMI))
273 southbridge_smi_gsmi();
Aaron Durbin76c37002012-10-30 09:03:43 -0500274 break;
Matt DeVillier8187f112018-12-24 21:46:46 -0600275 case APM_CNT_SMMSTORE:
276 if (CONFIG(SMMSTORE))
277 southbridge_smi_store();
278 break;
Aaron Durbin76c37002012-10-30 09:03:43 -0500279 }
280
Aaron Durbin29ffa542012-12-21 21:21:48 -0600281 mainboard_smi_apmc(reg8);
Aaron Durbin76c37002012-10-30 09:03:43 -0500282}
283
Aaron Durbin29ffa542012-12-21 21:21:48 -0600284static void southbridge_smi_pm1(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500285{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800286 u16 pm1_sts = clear_pm1_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500287
288 /* While OSPM is not active, poweroff immediately
289 * on a power button event.
290 */
291 if (pm1_sts & PWRBTN_STS) {
Angel Pons2aaf7c02020-09-24 18:03:18 +0200292 /* power button pressed */
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +0200293 elog_gsmi_add_event(ELOG_TYPE_POWER_BUTTON);
Angel Pons8963f7d2020-10-24 12:20:28 +0200294 disable_pm1_control(-1);
Duncan Laurie467f31d2013-03-08 17:00:37 -0800295 enable_pm1_control(SLP_EN | (SLP_TYP_S5 << 10));
Aaron Durbin76c37002012-10-30 09:03:43 -0500296 }
297}
298
Aaron Durbin29ffa542012-12-21 21:21:48 -0600299static void southbridge_smi_gpe0(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500300{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800301 clear_gpe_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500302}
303
Aaron Durbin29ffa542012-12-21 21:21:48 -0600304static void southbridge_smi_gpi(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500305{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800306 mainboard_smi_gpi(clear_alt_smi_status());
Aaron Durbin76c37002012-10-30 09:03:43 -0500307
Duncan Laurie467f31d2013-03-08 17:00:37 -0800308 /* Clear again after mainboard handler */
309 clear_alt_smi_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500310}
311
Aaron Durbin29ffa542012-12-21 21:21:48 -0600312static void southbridge_smi_mc(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500313{
Angel Pons2aaf7c02020-09-24 18:03:18 +0200314 u32 reg32 = inl(get_pmbase() + SMI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500315
Duncan Laurie467f31d2013-03-08 17:00:37 -0800316 /* Are microcontroller SMIs enabled? */
Aaron Durbin76c37002012-10-30 09:03:43 -0500317 if ((reg32 & MCSMI_EN) == 0)
318 return;
319
320 printk(BIOS_DEBUG, "Microcontroller SMI.\n");
321}
322
Aaron Durbin29ffa542012-12-21 21:21:48 -0600323static void southbridge_smi_tco(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500324{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800325 u32 tco_sts = clear_tco_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500326
327 /* Any TCO event? */
328 if (!tco_sts)
329 return;
330
Angel Pons2aaf7c02020-09-24 18:03:18 +0200331 // BIOSWR
332 if (tco_sts & (1 << 8)) {
Angel Ponscc36c4c2021-03-30 10:49:24 +0200333 u8 bios_cntl = pci_read_config8(PCH_LPC_DEV, BIOS_CNTL);
Aaron Durbin76c37002012-10-30 09:03:43 -0500334
335 if (bios_cntl & 1) {
Angel Pons2aaf7c02020-09-24 18:03:18 +0200336 /*
337 * BWE is RW, so the SMI was caused by a
Aaron Durbin76c37002012-10-30 09:03:43 -0500338 * write to BWE, not by a write to the BIOS
Angel Pons2aaf7c02020-09-24 18:03:18 +0200339 *
340 * This is the place where we notice someone
Aaron Durbin76c37002012-10-30 09:03:43 -0500341 * is trying to tinker with the BIOS. We are
342 * trying to be nice and just ignore it. A more
343 * resolute answer would be to power down the
344 * box.
345 */
346 printk(BIOS_DEBUG, "Switching back to RO\n");
Angel Ponscc36c4c2021-03-30 10:49:24 +0200347 pci_write_config8(PCH_LPC_DEV, BIOS_CNTL, (bios_cntl & ~1));
Aaron Durbin76c37002012-10-30 09:03:43 -0500348 } /* No else for now? */
349 } else if (tco_sts & (1 << 3)) { /* TIMEOUT */
350 /* Handle TCO timeout */
351 printk(BIOS_DEBUG, "TCO Timeout.\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500352 }
353}
354
Aaron Durbin29ffa542012-12-21 21:21:48 -0600355static void southbridge_smi_periodic(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500356{
Angel Pons2aaf7c02020-09-24 18:03:18 +0200357 u32 reg32 = inl(get_pmbase() + SMI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500358
359 /* Are periodic SMIs enabled? */
360 if ((reg32 & PERIODIC_EN) == 0)
361 return;
362
363 printk(BIOS_DEBUG, "Periodic SMI.\n");
364}
365
Aaron Durbin29ffa542012-12-21 21:21:48 -0600366static void southbridge_smi_monitor(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500367{
368#define IOTRAP(x) (trap_sts & (1 << x))
369 u32 trap_sts, trap_cycle;
Elyes HAOUAS2a66dd22020-08-07 15:22:12 +0200370 u32 mask = 0;
Aaron Durbin76c37002012-10-30 09:03:43 -0500371 int i;
372
373 trap_sts = RCBA32(0x1e00); // TRSR - Trap Status Register
374 RCBA32(0x1e00) = trap_sts; // Clear trap(s) in TRSR
375
376 trap_cycle = RCBA32(0x1e10);
Angel Pons2aaf7c02020-09-24 18:03:18 +0200377 for (i = 16; i < 20; i++) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500378 if (trap_cycle & (1 << i))
Kyösti Mälkkia0720432022-12-03 19:35:53 +0200379 mask |= (0xff << ((i - 16) << 3));
Aaron Durbin76c37002012-10-30 09:03:43 -0500380 }
381
Aaron Durbin76c37002012-10-30 09:03:43 -0500382 /* IOTRAP(3) SMI function call */
383 if (IOTRAP(3)) {
384 if (gnvs && gnvs->smif)
385 io_trap_handler(gnvs->smif); // call function smif
386 return;
387 }
388
389 /* IOTRAP(2) currently unused
390 * IOTRAP(1) currently unused */
391
392 /* IOTRAP(0) SMIC */
393 if (IOTRAP(0)) {
Angel Pons2aaf7c02020-09-24 18:03:18 +0200394 // It's a write
395 if (!(trap_cycle & (1 << 24))) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500396 printk(BIOS_DEBUG, "SMI1 command\n");
Elyes HAOUAS2a66dd22020-08-07 15:22:12 +0200397 (void)RCBA32(0x1e18);
398 // data = RCBA32(0x1e18);
399 // data &= mask;
Aaron Durbin76c37002012-10-30 09:03:43 -0500400 // if (smi1)
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200401 // southbridge_smi_command(data);
Aaron Durbin76c37002012-10-30 09:03:43 -0500402 // return;
403 }
404 // Fall through to debug
405 }
406
Duncan Laurie467f31d2013-03-08 17:00:37 -0800407 printk(BIOS_DEBUG, " trapped io address = 0x%x\n",
408 trap_cycle & 0xfffc);
Angel Pons2aaf7c02020-09-24 18:03:18 +0200409 for (i = 0; i < 4; i++)
410 if (IOTRAP(i))
411 printk(BIOS_DEBUG, " TRAP = %d\n", i);
Aaron Durbin76c37002012-10-30 09:03:43 -0500412 printk(BIOS_DEBUG, " AHBE = %x\n", (trap_cycle >> 16) & 0xf);
413 printk(BIOS_DEBUG, " MASK = 0x%08x\n", mask);
Duncan Laurie467f31d2013-03-08 17:00:37 -0800414 printk(BIOS_DEBUG, " read/write: %s\n",
415 (trap_cycle & (1 << 24)) ? "read" : "write");
Aaron Durbin76c37002012-10-30 09:03:43 -0500416
417 if (!(trap_cycle & (1 << 24))) {
418 /* Write Cycle */
Elyes HAOUAS2a66dd22020-08-07 15:22:12 +0200419 printk(BIOS_DEBUG, " iotrap written data = 0x%08x\n", RCBA32(0x1e18));
Aaron Durbin76c37002012-10-30 09:03:43 -0500420 }
421#undef IOTRAP
422}
423
Aaron Durbin29ffa542012-12-21 21:21:48 -0600424typedef void (*smi_handler_t)(void);
Aaron Durbin76c37002012-10-30 09:03:43 -0500425
426static smi_handler_t southbridge_smi[32] = {
427 NULL, // [0] reserved
428 NULL, // [1] reserved
429 NULL, // [2] BIOS_STS
430 NULL, // [3] LEGACY_USB_STS
431 southbridge_smi_sleep, // [4] SLP_SMI_STS
432 southbridge_smi_apmc, // [5] APM_STS
433 NULL, // [6] SWSMI_TMR_STS
434 NULL, // [7] reserved
435 southbridge_smi_pm1, // [8] PM1_STS
436 southbridge_smi_gpe0, // [9] GPE0_STS
437 southbridge_smi_gpi, // [10] GPI_STS
438 southbridge_smi_mc, // [11] MCSMI_STS
439 NULL, // [12] DEVMON_STS
440 southbridge_smi_tco, // [13] TCO_STS
441 southbridge_smi_periodic, // [14] PERIODIC_STS
442 NULL, // [15] SERIRQ_SMI_STS
443 NULL, // [16] SMBUS_SMI_STS
444 NULL, // [17] LEGACY_USB2_STS
445 NULL, // [18] INTEL_USB2_STS
446 NULL, // [19] reserved
447 NULL, // [20] PCI_EXP_SMI_STS
448 southbridge_smi_monitor, // [21] MONITOR_STS
449 NULL, // [22] reserved
450 NULL, // [23] reserved
451 NULL, // [24] reserved
452 NULL, // [25] EL_SMI_STS
453 NULL, // [26] SPI_STS
454 NULL, // [27] reserved
455 NULL, // [28] reserved
456 NULL, // [29] reserved
457 NULL, // [30] reserved
458 NULL // [31] reserved
459};
460
461/**
462 * @brief Interrupt handler for SMI#
Aaron Durbin76c37002012-10-30 09:03:43 -0500463 */
Aaron Durbin29ffa542012-12-21 21:21:48 -0600464void southbridge_smi_handler(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500465{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800466 int i;
Aaron Durbin76c37002012-10-30 09:03:43 -0500467 u32 smi_sts;
468
Aaron Durbin76c37002012-10-30 09:03:43 -0500469 /* We need to clear the SMI status registers, or we won't see what's
470 * happening in the following calls.
471 */
Duncan Laurie467f31d2013-03-08 17:00:37 -0800472 smi_sts = clear_smi_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500473
474 /* Call SMI sub handler for each of the status bits */
475 for (i = 0; i < 31; i++) {
476 if (smi_sts & (1 << i)) {
477 if (southbridge_smi[i]) {
Aaron Durbin29ffa542012-12-21 21:21:48 -0600478 southbridge_smi[i]();
Aaron Durbin76c37002012-10-30 09:03:43 -0500479 } else {
Duncan Laurie467f31d2013-03-08 17:00:37 -0800480 printk(BIOS_DEBUG,
Martin Roth2ed0aa22016-01-05 20:58:58 -0700481 "SMI_STS[%d] occurred, but no "
Duncan Laurie467f31d2013-03-08 17:00:37 -0800482 "handler available.\n", i);
Aaron Durbin76c37002012-10-30 09:03:43 -0500483 }
484 }
485 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500486}