blob: 4ac4ff948d8f3d070b6ecc250fdd8d8223ef1255 [file] [log] [blame]
Aaron Durbin76c37002012-10-30 09:03:43 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
Duncan Laurie467f31d2013-03-08 17:00:37 -08005 * Copyright 2013 Google Inc.
Aaron Durbin76c37002012-10-30 09:03:43 -05006 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; version 2 of
10 * the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Aaron Durbin76c37002012-10-30 09:03:43 -050016 */
17
18#include <types.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050019#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020020#include <device/pci_ops.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050021#include <console/console.h>
22#include <cpu/x86/cache.h>
23#include <device/pci_def.h>
24#include <cpu/x86/smm.h>
Kyösti Mälkkie31ec292019-08-10 17:27:01 +030025#include <cpu/intel/em64t101_save_state.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050026#include <elog.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010027#include <halt.h>
Kyösti Mälkkicbf95712020-01-05 08:05:45 +020028#include <option.h>
Tristan Corrick63626b12018-11-30 22:53:50 +130029#include <southbridge/intel/common/finalize.h>
Tristan Corrick09fc6342018-11-30 22:53:01 +130030#include <northbridge/intel/haswell/haswell.h>
31#include <cpu/intel/haswell/haswell.h>
Matt DeVillier8187f112018-12-24 21:46:46 -060032#include <smmstore.h>
Tristan Corrick63626b12018-11-30 22:53:50 +130033#include "me.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050034#include "pch.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050035#include "nvs.h"
36
Aaron Durbin76c37002012-10-30 09:03:43 -050037static u8 smm_initialized = 0;
38
39/* GNVS needs to be updated by an 0xEA PM Trap (B2) after it has been located
40 * by coreboot.
41 */
Aaron Durbin29ffa542012-12-21 21:21:48 -060042static global_nvs_t *gnvs;
Aaron Durbin76c37002012-10-30 09:03:43 -050043global_nvs_t *smm_get_gnvs(void)
44{
45 return gnvs;
46}
47
Aaron Durbin76c37002012-10-30 09:03:43 -050048int southbridge_io_trap_handler(int smif)
49{
50 switch (smif) {
51 case 0x32:
52 printk(BIOS_DEBUG, "OS Init\n");
53 /* gnvs->smif:
54 * On success, the IO Trap Handler returns 0
55 * On failure, the IO Trap Handler returns a value != 0
56 */
57 gnvs->smif = 0;
58 return 1; /* IO trap handled */
59 }
60
61 /* Not handled */
62 return 0;
63}
64
65/**
66 * @brief Set the EOS bit
67 */
68void southbridge_smi_set_eos(void)
69{
Duncan Laurie467f31d2013-03-08 17:00:37 -080070 enable_smi(EOS);
Aaron Durbin76c37002012-10-30 09:03:43 -050071}
72
73static void busmaster_disable_on_bus(int bus)
74{
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020075 int slot, func;
76 unsigned int val;
77 unsigned char hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -050078
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020079 for (slot = 0; slot < 0x20; slot++) {
80 for (func = 0; func < 8; func++) {
81 u32 reg32;
Elyes HAOUAS68c851b2018-06-12 22:06:09 +020082 pci_devfn_t dev = PCI_DEV(bus, slot, func);
Aaron Durbin76c37002012-10-30 09:03:43 -050083
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020084 val = pci_read_config32(dev, PCI_VENDOR_ID);
Aaron Durbin76c37002012-10-30 09:03:43 -050085
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020086 if (val == 0xffffffff || val == 0x00000000 ||
87 val == 0x0000ffff || val == 0xffff0000)
88 continue;
Aaron Durbin76c37002012-10-30 09:03:43 -050089
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020090 /* Disable Bus Mastering for this one device */
91 reg32 = pci_read_config32(dev, PCI_COMMAND);
92 reg32 &= ~PCI_COMMAND_MASTER;
93 pci_write_config32(dev, PCI_COMMAND, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -050094
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020095 /* If this is a bridge, then follow it. */
96 hdr = pci_read_config8(dev, PCI_HEADER_TYPE);
97 hdr &= 0x7f;
98 if (hdr == PCI_HEADER_TYPE_BRIDGE ||
99 hdr == PCI_HEADER_TYPE_CARDBUS) {
100 unsigned int buses;
101 buses = pci_read_config32(dev, PCI_PRIMARY_BUS);
102 busmaster_disable_on_bus((buses >> 8) & 0xff);
103 }
104 }
105 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500106}
107
Duncan Laurie2d9d39a2013-05-29 15:27:55 -0700108
Aaron Durbin29ffa542012-12-21 21:21:48 -0600109static void southbridge_smi_sleep(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500110{
111 u8 reg8;
112 u32 reg32;
113 u8 slp_typ;
Nico Huber9faae2b2018-11-14 00:00:35 +0100114 u8 s5pwr = CONFIG_MAINBOARD_POWER_FAILURE_STATE;
Duncan Laurie467f31d2013-03-08 17:00:37 -0800115 u16 pmbase = get_pmbase();
Aaron Durbin76c37002012-10-30 09:03:43 -0500116
117 // save and recover RTC port values
118 u8 tmp70, tmp72;
119 tmp70 = inb(0x70);
120 tmp72 = inb(0x72);
121 get_option(&s5pwr, "power_on_after_fail");
122 outb(tmp70, 0x70);
123 outb(tmp72, 0x72);
124
Aaron Durbin76c37002012-10-30 09:03:43 -0500125 /* First, disable further SMIs */
Duncan Laurie467f31d2013-03-08 17:00:37 -0800126 disable_smi(SLP_SMI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500127
128 /* Figure out SLP_TYP */
129 reg32 = inl(pmbase + PM1_CNT);
130 printk(BIOS_SPEW, "SMI#: SLP = 0x%08x\n", reg32);
Aaron Durbinda5f5092016-07-13 23:23:16 -0500131 slp_typ = acpi_sleep_from_pm1(reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500132
133 /* Do any mainboard sleep handling */
Aaron Durbinda5f5092016-07-13 23:23:16 -0500134 mainboard_smi_sleep(slp_typ);
Aaron Durbin76c37002012-10-30 09:03:43 -0500135
Duncan Laurie2d9d39a2013-05-29 15:27:55 -0700136 /* USB sleep preparations */
Julius Wernercd49cce2019-03-05 16:53:33 -0800137#if !CONFIG(FINALIZE_USB_ROUTE_XHCI)
Duncan Laurie1f529082013-07-30 15:53:45 -0700138 usb_ehci_sleep_prepare(PCH_EHCI1_DEV, slp_typ);
139 usb_ehci_sleep_prepare(PCH_EHCI2_DEV, slp_typ);
Duncan Laurie911cedf2013-07-30 16:05:55 -0700140#endif
Duncan Laurie1f529082013-07-30 15:53:45 -0700141 usb_xhci_sleep_prepare(PCH_XHCI_DEV, slp_typ);
Duncan Laurie2d9d39a2013-05-29 15:27:55 -0700142
Aaron Durbin76c37002012-10-30 09:03:43 -0500143 /* Log S3, S4, and S5 entry */
Aaron Durbinda5f5092016-07-13 23:23:16 -0500144 if (slp_typ >= ACPI_S3)
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +0200145 elog_gsmi_add_event_byte(ELOG_TYPE_ACPI_ENTER, slp_typ);
Aaron Durbin76c37002012-10-30 09:03:43 -0500146
147 /* Next, do the deed.
148 */
149
150 switch (slp_typ) {
Aaron Durbinda5f5092016-07-13 23:23:16 -0500151 case ACPI_S0:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800152 printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n");
153 break;
Aaron Durbinda5f5092016-07-13 23:23:16 -0500154 case ACPI_S1:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800155 printk(BIOS_DEBUG, "SMI#: Entering S1 (Assert STPCLK#)\n");
156 break;
Aaron Durbinda5f5092016-07-13 23:23:16 -0500157 case ACPI_S3:
Aaron Durbin76c37002012-10-30 09:03:43 -0500158 printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n");
159
Aaron Durbin76c37002012-10-30 09:03:43 -0500160 /* Invalidate the cache before going to S3 */
161 wbinvd();
162 break;
Aaron Durbinda5f5092016-07-13 23:23:16 -0500163 case ACPI_S4:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800164 printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n");
165 break;
Aaron Durbinda5f5092016-07-13 23:23:16 -0500166 case ACPI_S5:
Aaron Durbin76c37002012-10-30 09:03:43 -0500167 printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n");
168
Duncan Laurie467f31d2013-03-08 17:00:37 -0800169 /* Disable all GPE */
170 disable_all_gpe();
Aaron Durbin76c37002012-10-30 09:03:43 -0500171
172 /* Always set the flag in case CMOS was changed on runtime. For
173 * "KEEP", switch to "OFF" - KEEP is software emulated
174 */
Aaron Durbin89f79a02012-10-31 23:05:25 -0500175 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3);
Aaron Durbin76c37002012-10-30 09:03:43 -0500176 if (s5pwr == MAINBOARD_POWER_ON) {
177 reg8 &= ~1;
178 } else {
179 reg8 |= 1;
180 }
Aaron Durbin89f79a02012-10-31 23:05:25 -0500181 pci_write_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3, reg8);
Aaron Durbin76c37002012-10-30 09:03:43 -0500182
183 /* also iterates over all bridges on bus 0 */
184 busmaster_disable_on_bus(0);
185 break;
Duncan Laurie467f31d2013-03-08 17:00:37 -0800186 default:
187 printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n");
188 break;
Aaron Durbin76c37002012-10-30 09:03:43 -0500189 }
190
191 /* Write back to the SLP register to cause the originally intended
192 * event again. We need to set BIT13 (SLP_EN) though to make the
193 * sleep happen.
194 */
Duncan Laurie467f31d2013-03-08 17:00:37 -0800195 enable_pm1_control(SLP_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500196
197 /* Make sure to stop executing code here for S3/S4/S5 */
Aaron Durbinda5f5092016-07-13 23:23:16 -0500198 if (slp_typ >= ACPI_S3)
Patrick Georgi546953c2014-11-29 10:38:17 +0100199 halt();
Aaron Durbin76c37002012-10-30 09:03:43 -0500200
201 /* In most sleep states, the code flow of this function ends at
202 * the line above. However, if we entered sleep state S1 and wake
203 * up again, we will continue to execute code in this function.
204 */
205 reg32 = inl(pmbase + PM1_CNT);
206 if (reg32 & SCI_EN) {
207 /* The OS is not an ACPI OS, so we set the state to S0 */
Duncan Laurie467f31d2013-03-08 17:00:37 -0800208 disable_pm1_control(SLP_EN | SLP_TYP);
Aaron Durbin76c37002012-10-30 09:03:43 -0500209 }
210}
211
212/*
213 * Look for Synchronous IO SMI and use save state from that
214 * core in case we are not running on the same core that
215 * initiated the IO transaction.
216 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500217static em64t101_smm_state_save_area_t *smi_apmc_find_state_save(u8 cmd)
218{
219 em64t101_smm_state_save_area_t *state;
Aaron Durbin76c37002012-10-30 09:03:43 -0500220 int node;
221
222 /* Check all nodes looking for the one that issued the IO */
223 for (node = 0; node < CONFIG_MAX_CPUS; node++) {
Aaron Durbin29ffa542012-12-21 21:21:48 -0600224 state = smm_get_save_state(node);
Aaron Durbin76c37002012-10-30 09:03:43 -0500225
Elyes HAOUAS581fe582018-04-26 09:57:07 +0200226 /* Check for Synchronous IO (bit0 == 1) */
Aaron Durbin76c37002012-10-30 09:03:43 -0500227 if (!(state->io_misc_info & (1 << 0)))
228 continue;
229
Elyes HAOUAS581fe582018-04-26 09:57:07 +0200230 /* Make sure it was a write (bit4 == 0) */
Aaron Durbin76c37002012-10-30 09:03:43 -0500231 if (state->io_misc_info & (1 << 4))
232 continue;
233
234 /* Check for APMC IO port */
235 if (((state->io_misc_info >> 16) & 0xff) != APM_CNT)
236 continue;
237
238 /* Check AX against the requested command */
239 if ((state->rax & 0xff) != cmd)
240 continue;
241
242 return state;
243 }
244
245 return NULL;
246}
247
Aaron Durbin76c37002012-10-30 09:03:43 -0500248static void southbridge_smi_gsmi(void)
249{
250 u32 *ret, *param;
251 u8 sub_command;
252 em64t101_smm_state_save_area_t *io_smi =
Patrick Georgid61839c2018-12-03 16:10:33 +0100253 smi_apmc_find_state_save(APM_CNT_ELOG_GSMI);
Aaron Durbin76c37002012-10-30 09:03:43 -0500254
255 if (!io_smi)
256 return;
257
258 /* Command and return value in EAX */
259 ret = (u32*)&io_smi->rax;
260 sub_command = (u8)(*ret >> 8);
261
262 /* Parameter buffer in EBX */
263 param = (u32*)&io_smi->rbx;
264
265 /* drivers/elog/gsmi.c */
266 *ret = gsmi_exec(sub_command, param);
267}
Aaron Durbin76c37002012-10-30 09:03:43 -0500268
Matt DeVillier8187f112018-12-24 21:46:46 -0600269static void southbridge_smi_store(void)
270{
271 u8 sub_command, ret;
272 em64t101_smm_state_save_area_t *io_smi =
273 smi_apmc_find_state_save(APM_CNT_SMMSTORE);
274 uint32_t reg_ebx;
275
276 if (!io_smi)
277 return;
278 /* Command and return value in EAX */
279 sub_command = (io_smi->rax >> 8) & 0xff;
280
281 /* Parameter buffer in EBX */
282 reg_ebx = io_smi->rbx;
283
284 /* drivers/smmstore/smi.c */
285 ret = smmstore_exec(sub_command, (void *)reg_ebx);
286 io_smi->rax = ret;
287}
288
Aaron Durbin29ffa542012-12-21 21:21:48 -0600289static void southbridge_smi_apmc(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500290{
Aaron Durbin76c37002012-10-30 09:03:43 -0500291 u8 reg8;
Aaron Durbin76c37002012-10-30 09:03:43 -0500292 em64t101_smm_state_save_area_t *state;
Tristan Corrick09fc6342018-11-30 22:53:01 +1300293 static int chipset_finalized = 0;
Aaron Durbin76c37002012-10-30 09:03:43 -0500294
295 /* Emulate B2 register as the FADT / Linux expects it */
296
297 reg8 = inb(APM_CNT);
298 switch (reg8) {
Tristan Corrick09fc6342018-11-30 22:53:01 +1300299 case APM_CNT_FINALIZE:
300 if (chipset_finalized) {
301 printk(BIOS_DEBUG, "SMI#: Already finalized\n");
302 return;
303 }
304
Tristan Corrick63626b12018-11-30 22:53:50 +1300305 intel_me_finalize_smm();
Tristan Corrick09fc6342018-11-30 22:53:01 +1300306 intel_pch_finalize_smm();
307 intel_northbridge_haswell_finalize_smm();
308 intel_cpu_haswell_finalize_smm();
309
310 chipset_finalized = 1;
311 break;
Aaron Durbin76c37002012-10-30 09:03:43 -0500312 case APM_CNT_CST_CONTROL:
313 /* Calling this function seems to cause
314 * some kind of race condition in Linux
315 * and causes a kernel oops
316 */
317 printk(BIOS_DEBUG, "C-state control\n");
318 break;
319 case APM_CNT_PST_CONTROL:
320 /* Calling this function seems to cause
321 * some kind of race condition in Linux
322 * and causes a kernel oops
323 */
324 printk(BIOS_DEBUG, "P-state control\n");
325 break;
326 case APM_CNT_ACPI_DISABLE:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800327 disable_pm1_control(SCI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500328 printk(BIOS_DEBUG, "SMI#: ACPI disabled.\n");
329 break;
330 case APM_CNT_ACPI_ENABLE:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800331 enable_pm1_control(SCI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500332 printk(BIOS_DEBUG, "SMI#: ACPI enabled.\n");
333 break;
334 case APM_CNT_GNVS_UPDATE:
335 if (smm_initialized) {
Duncan Laurie467f31d2013-03-08 17:00:37 -0800336 printk(BIOS_DEBUG,
337 "SMI#: SMM structures already initialized!\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500338 return;
339 }
340 state = smi_apmc_find_state_save(reg8);
341 if (state) {
342 /* EBX in the state save contains the GNVS pointer */
343 gnvs = (global_nvs_t *)((u32)state->rbx);
344 smm_initialized = 1;
345 printk(BIOS_DEBUG, "SMI#: Setting GNVS to %p\n", gnvs);
346 }
347 break;
Duncan Laurie78145a52013-08-21 13:16:21 -0700348 case 0xca:
Duncan Laurie911cedf2013-07-30 16:05:55 -0700349 usb_xhci_route_all();
Duncan Laurie911cedf2013-07-30 16:05:55 -0700350 break;
Patrick Georgid61839c2018-12-03 16:10:33 +0100351 case APM_CNT_ELOG_GSMI:
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +0200352 if (CONFIG(ELOG_GSMI))
353 southbridge_smi_gsmi();
Aaron Durbin76c37002012-10-30 09:03:43 -0500354 break;
Matt DeVillier8187f112018-12-24 21:46:46 -0600355 case APM_CNT_SMMSTORE:
356 if (CONFIG(SMMSTORE))
357 southbridge_smi_store();
358 break;
Aaron Durbin76c37002012-10-30 09:03:43 -0500359 }
360
Aaron Durbin29ffa542012-12-21 21:21:48 -0600361 mainboard_smi_apmc(reg8);
Aaron Durbin76c37002012-10-30 09:03:43 -0500362}
363
Aaron Durbin29ffa542012-12-21 21:21:48 -0600364static void southbridge_smi_pm1(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500365{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800366 u16 pm1_sts = clear_pm1_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500367
368 /* While OSPM is not active, poweroff immediately
369 * on a power button event.
370 */
371 if (pm1_sts & PWRBTN_STS) {
372 // power button pressed
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +0200373 elog_gsmi_add_event(ELOG_TYPE_POWER_BUTTON);
Duncan Laurie467f31d2013-03-08 17:00:37 -0800374 disable_pm1_control(-1UL);
375 enable_pm1_control(SLP_EN | (SLP_TYP_S5 << 10));
Aaron Durbin76c37002012-10-30 09:03:43 -0500376 }
377}
378
Aaron Durbin29ffa542012-12-21 21:21:48 -0600379static void southbridge_smi_gpe0(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500380{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800381 clear_gpe_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500382}
383
Aaron Durbin29ffa542012-12-21 21:21:48 -0600384static void southbridge_smi_gpi(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500385{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800386 mainboard_smi_gpi(clear_alt_smi_status());
Aaron Durbin76c37002012-10-30 09:03:43 -0500387
Duncan Laurie467f31d2013-03-08 17:00:37 -0800388 /* Clear again after mainboard handler */
389 clear_alt_smi_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500390}
391
Aaron Durbin29ffa542012-12-21 21:21:48 -0600392static void southbridge_smi_mc(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500393{
394 u32 reg32;
395
Duncan Laurie467f31d2013-03-08 17:00:37 -0800396 reg32 = inl(get_pmbase() + SMI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500397
Duncan Laurie467f31d2013-03-08 17:00:37 -0800398 /* Are microcontroller SMIs enabled? */
Aaron Durbin76c37002012-10-30 09:03:43 -0500399 if ((reg32 & MCSMI_EN) == 0)
400 return;
401
402 printk(BIOS_DEBUG, "Microcontroller SMI.\n");
403}
404
405
406
Aaron Durbin29ffa542012-12-21 21:21:48 -0600407static void southbridge_smi_tco(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500408{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800409 u32 tco_sts = clear_tco_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500410
411 /* Any TCO event? */
412 if (!tco_sts)
413 return;
414
415 if (tco_sts & (1 << 8)) { // BIOSWR
416 u8 bios_cntl;
417
Aaron Durbin89f79a02012-10-31 23:05:25 -0500418 bios_cntl = pci_read_config16(PCI_DEV(0, 0x1f, 0), 0xdc);
Aaron Durbin76c37002012-10-30 09:03:43 -0500419
420 if (bios_cntl & 1) {
421 /* BWE is RW, so the SMI was caused by a
422 * write to BWE, not by a write to the BIOS
423 */
424
425 /* This is the place where we notice someone
426 * is trying to tinker with the BIOS. We are
427 * trying to be nice and just ignore it. A more
428 * resolute answer would be to power down the
429 * box.
430 */
431 printk(BIOS_DEBUG, "Switching back to RO\n");
Duncan Laurie467f31d2013-03-08 17:00:37 -0800432 pci_write_config32(PCI_DEV(0, 0x1f, 0), 0xdc,
433 (bios_cntl & ~1));
Aaron Durbin76c37002012-10-30 09:03:43 -0500434 } /* No else for now? */
435 } else if (tco_sts & (1 << 3)) { /* TIMEOUT */
436 /* Handle TCO timeout */
437 printk(BIOS_DEBUG, "TCO Timeout.\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500438 }
439}
440
Aaron Durbin29ffa542012-12-21 21:21:48 -0600441static void southbridge_smi_periodic(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500442{
443 u32 reg32;
444
Duncan Laurie467f31d2013-03-08 17:00:37 -0800445 reg32 = inl(get_pmbase() + SMI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500446
447 /* Are periodic SMIs enabled? */
448 if ((reg32 & PERIODIC_EN) == 0)
449 return;
450
451 printk(BIOS_DEBUG, "Periodic SMI.\n");
452}
453
Aaron Durbin29ffa542012-12-21 21:21:48 -0600454static void southbridge_smi_monitor(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500455{
456#define IOTRAP(x) (trap_sts & (1 << x))
457 u32 trap_sts, trap_cycle;
458 u32 data, mask = 0;
459 int i;
460
461 trap_sts = RCBA32(0x1e00); // TRSR - Trap Status Register
462 RCBA32(0x1e00) = trap_sts; // Clear trap(s) in TRSR
463
464 trap_cycle = RCBA32(0x1e10);
465 for (i=16; i<20; i++) {
466 if (trap_cycle & (1 << i))
467 mask |= (0xff << ((i - 16) << 2));
468 }
469
470
471 /* IOTRAP(3) SMI function call */
472 if (IOTRAP(3)) {
473 if (gnvs && gnvs->smif)
474 io_trap_handler(gnvs->smif); // call function smif
475 return;
476 }
477
478 /* IOTRAP(2) currently unused
479 * IOTRAP(1) currently unused */
480
481 /* IOTRAP(0) SMIC */
482 if (IOTRAP(0)) {
483 if (!(trap_cycle & (1 << 24))) { // It's a write
484 printk(BIOS_DEBUG, "SMI1 command\n");
485 data = RCBA32(0x1e18);
486 data &= mask;
487 // if (smi1)
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200488 // southbridge_smi_command(data);
Aaron Durbin76c37002012-10-30 09:03:43 -0500489 // return;
490 }
491 // Fall through to debug
492 }
493
Duncan Laurie467f31d2013-03-08 17:00:37 -0800494 printk(BIOS_DEBUG, " trapped io address = 0x%x\n",
495 trap_cycle & 0xfffc);
496 for (i=0; i < 4; i++)
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200497 if (IOTRAP(i)) printk(BIOS_DEBUG, " TRAP = %d\n", i);
Aaron Durbin76c37002012-10-30 09:03:43 -0500498 printk(BIOS_DEBUG, " AHBE = %x\n", (trap_cycle >> 16) & 0xf);
499 printk(BIOS_DEBUG, " MASK = 0x%08x\n", mask);
Duncan Laurie467f31d2013-03-08 17:00:37 -0800500 printk(BIOS_DEBUG, " read/write: %s\n",
501 (trap_cycle & (1 << 24)) ? "read" : "write");
Aaron Durbin76c37002012-10-30 09:03:43 -0500502
503 if (!(trap_cycle & (1 << 24))) {
504 /* Write Cycle */
505 data = RCBA32(0x1e18);
506 printk(BIOS_DEBUG, " iotrap written data = 0x%08x\n", data);
507 }
508#undef IOTRAP
509}
510
Aaron Durbin29ffa542012-12-21 21:21:48 -0600511typedef void (*smi_handler_t)(void);
Aaron Durbin76c37002012-10-30 09:03:43 -0500512
513static smi_handler_t southbridge_smi[32] = {
514 NULL, // [0] reserved
515 NULL, // [1] reserved
516 NULL, // [2] BIOS_STS
517 NULL, // [3] LEGACY_USB_STS
518 southbridge_smi_sleep, // [4] SLP_SMI_STS
519 southbridge_smi_apmc, // [5] APM_STS
520 NULL, // [6] SWSMI_TMR_STS
521 NULL, // [7] reserved
522 southbridge_smi_pm1, // [8] PM1_STS
523 southbridge_smi_gpe0, // [9] GPE0_STS
524 southbridge_smi_gpi, // [10] GPI_STS
525 southbridge_smi_mc, // [11] MCSMI_STS
526 NULL, // [12] DEVMON_STS
527 southbridge_smi_tco, // [13] TCO_STS
528 southbridge_smi_periodic, // [14] PERIODIC_STS
529 NULL, // [15] SERIRQ_SMI_STS
530 NULL, // [16] SMBUS_SMI_STS
531 NULL, // [17] LEGACY_USB2_STS
532 NULL, // [18] INTEL_USB2_STS
533 NULL, // [19] reserved
534 NULL, // [20] PCI_EXP_SMI_STS
535 southbridge_smi_monitor, // [21] MONITOR_STS
536 NULL, // [22] reserved
537 NULL, // [23] reserved
538 NULL, // [24] reserved
539 NULL, // [25] EL_SMI_STS
540 NULL, // [26] SPI_STS
541 NULL, // [27] reserved
542 NULL, // [28] reserved
543 NULL, // [29] reserved
544 NULL, // [30] reserved
545 NULL // [31] reserved
546};
547
548/**
549 * @brief Interrupt handler for SMI#
Aaron Durbin76c37002012-10-30 09:03:43 -0500550 */
Aaron Durbin29ffa542012-12-21 21:21:48 -0600551void southbridge_smi_handler(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500552{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800553 int i;
Aaron Durbin76c37002012-10-30 09:03:43 -0500554 u32 smi_sts;
555
Aaron Durbin76c37002012-10-30 09:03:43 -0500556 /* We need to clear the SMI status registers, or we won't see what's
557 * happening in the following calls.
558 */
Duncan Laurie467f31d2013-03-08 17:00:37 -0800559 smi_sts = clear_smi_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500560
561 /* Call SMI sub handler for each of the status bits */
562 for (i = 0; i < 31; i++) {
563 if (smi_sts & (1 << i)) {
564 if (southbridge_smi[i]) {
Aaron Durbin29ffa542012-12-21 21:21:48 -0600565 southbridge_smi[i]();
Aaron Durbin76c37002012-10-30 09:03:43 -0500566 } else {
Duncan Laurie467f31d2013-03-08 17:00:37 -0800567 printk(BIOS_DEBUG,
Martin Roth2ed0aa22016-01-05 20:58:58 -0700568 "SMI_STS[%d] occurred, but no "
Duncan Laurie467f31d2013-03-08 17:00:37 -0800569 "handler available.\n", i);
Aaron Durbin76c37002012-10-30 09:03:43 -0500570 }
571 }
572 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500573}