blob: be842c57206e4e0a6b4f697ea6b734c21954ff5e [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>
Matt DeVillier8187f112018-12-24 21:46:46 -060017#include <smmstore.h>
Tristan Corrick63626b12018-11-30 22:53:50 +130018#include "me.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050019#include "pch.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050020#include "nvs.h"
21
Aaron Durbin76c37002012-10-30 09:03:43 -050022static u8 smm_initialized = 0;
23
24/* GNVS needs to be updated by an 0xEA PM Trap (B2) after it has been located
25 * by coreboot.
26 */
Aaron Durbin29ffa542012-12-21 21:21:48 -060027static global_nvs_t *gnvs;
Aaron Durbin76c37002012-10-30 09:03:43 -050028global_nvs_t *smm_get_gnvs(void)
29{
30 return gnvs;
31}
32
Aaron Durbin76c37002012-10-30 09:03:43 -050033int southbridge_io_trap_handler(int smif)
34{
35 switch (smif) {
36 case 0x32:
37 printk(BIOS_DEBUG, "OS Init\n");
38 /* gnvs->smif:
39 * On success, the IO Trap Handler returns 0
40 * On failure, the IO Trap Handler returns a value != 0
41 */
42 gnvs->smif = 0;
43 return 1; /* IO trap handled */
44 }
45
46 /* Not handled */
47 return 0;
48}
49
50/**
51 * @brief Set the EOS bit
52 */
53void southbridge_smi_set_eos(void)
54{
Duncan Laurie467f31d2013-03-08 17:00:37 -080055 enable_smi(EOS);
Aaron Durbin76c37002012-10-30 09:03:43 -050056}
57
58static void busmaster_disable_on_bus(int bus)
59{
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020060 int slot, func;
61 unsigned int val;
62 unsigned char hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -050063
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020064 for (slot = 0; slot < 0x20; slot++) {
65 for (func = 0; func < 8; func++) {
Elyes HAOUAS73ae0762020-04-28 10:13:05 +020066 u16 reg16;
Elyes HAOUAS68c851b2018-06-12 22:06:09 +020067 pci_devfn_t dev = PCI_DEV(bus, slot, func);
Aaron Durbin76c37002012-10-30 09:03:43 -050068
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020069 val = pci_read_config32(dev, PCI_VENDOR_ID);
Aaron Durbin76c37002012-10-30 09:03:43 -050070
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020071 if (val == 0xffffffff || val == 0x00000000 ||
72 val == 0x0000ffff || val == 0xffff0000)
73 continue;
Aaron Durbin76c37002012-10-30 09:03:43 -050074
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020075 /* Disable Bus Mastering for this one device */
Elyes HAOUAS73ae0762020-04-28 10:13:05 +020076 reg16 = pci_read_config16(dev, PCI_COMMAND);
77 reg16 &= ~PCI_COMMAND_MASTER;
78 pci_write_config16(dev, PCI_COMMAND, reg16);
Aaron Durbin76c37002012-10-30 09:03:43 -050079
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020080 /* If this is a bridge, then follow it. */
81 hdr = pci_read_config8(dev, PCI_HEADER_TYPE);
82 hdr &= 0x7f;
83 if (hdr == PCI_HEADER_TYPE_BRIDGE ||
84 hdr == PCI_HEADER_TYPE_CARDBUS) {
85 unsigned int buses;
86 buses = pci_read_config32(dev, PCI_PRIMARY_BUS);
87 busmaster_disable_on_bus((buses >> 8) & 0xff);
88 }
89 }
90 }
Aaron Durbin76c37002012-10-30 09:03:43 -050091}
92
Duncan Laurie2d9d39a2013-05-29 15:27:55 -070093
Aaron Durbin29ffa542012-12-21 21:21:48 -060094static void southbridge_smi_sleep(void)
Aaron Durbin76c37002012-10-30 09:03:43 -050095{
96 u8 reg8;
97 u32 reg32;
98 u8 slp_typ;
Nico Huber9faae2b2018-11-14 00:00:35 +010099 u8 s5pwr = CONFIG_MAINBOARD_POWER_FAILURE_STATE;
Duncan Laurie467f31d2013-03-08 17:00:37 -0800100 u16 pmbase = get_pmbase();
Aaron Durbin76c37002012-10-30 09:03:43 -0500101
102 // save and recover RTC port values
103 u8 tmp70, tmp72;
104 tmp70 = inb(0x70);
105 tmp72 = inb(0x72);
106 get_option(&s5pwr, "power_on_after_fail");
107 outb(tmp70, 0x70);
108 outb(tmp72, 0x72);
109
Aaron Durbin76c37002012-10-30 09:03:43 -0500110 /* First, disable further SMIs */
Duncan Laurie467f31d2013-03-08 17:00:37 -0800111 disable_smi(SLP_SMI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500112
113 /* Figure out SLP_TYP */
114 reg32 = inl(pmbase + PM1_CNT);
115 printk(BIOS_SPEW, "SMI#: SLP = 0x%08x\n", reg32);
Aaron Durbinda5f5092016-07-13 23:23:16 -0500116 slp_typ = acpi_sleep_from_pm1(reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500117
118 /* Do any mainboard sleep handling */
Aaron Durbinda5f5092016-07-13 23:23:16 -0500119 mainboard_smi_sleep(slp_typ);
Aaron Durbin76c37002012-10-30 09:03:43 -0500120
Duncan Laurie2d9d39a2013-05-29 15:27:55 -0700121 /* USB sleep preparations */
Julius Wernercd49cce2019-03-05 16:53:33 -0800122#if !CONFIG(FINALIZE_USB_ROUTE_XHCI)
Duncan Laurie1f529082013-07-30 15:53:45 -0700123 usb_ehci_sleep_prepare(PCH_EHCI1_DEV, slp_typ);
124 usb_ehci_sleep_prepare(PCH_EHCI2_DEV, slp_typ);
Duncan Laurie911cedf2013-07-30 16:05:55 -0700125#endif
Duncan Laurie1f529082013-07-30 15:53:45 -0700126 usb_xhci_sleep_prepare(PCH_XHCI_DEV, slp_typ);
Duncan Laurie2d9d39a2013-05-29 15:27:55 -0700127
Aaron Durbin76c37002012-10-30 09:03:43 -0500128 /* Log S3, S4, and S5 entry */
Aaron Durbinda5f5092016-07-13 23:23:16 -0500129 if (slp_typ >= ACPI_S3)
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +0200130 elog_gsmi_add_event_byte(ELOG_TYPE_ACPI_ENTER, slp_typ);
Aaron Durbin76c37002012-10-30 09:03:43 -0500131
132 /* Next, do the deed.
133 */
134
135 switch (slp_typ) {
Aaron Durbinda5f5092016-07-13 23:23:16 -0500136 case ACPI_S0:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800137 printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n");
138 break;
Aaron Durbinda5f5092016-07-13 23:23:16 -0500139 case ACPI_S1:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800140 printk(BIOS_DEBUG, "SMI#: Entering S1 (Assert STPCLK#)\n");
141 break;
Aaron Durbinda5f5092016-07-13 23:23:16 -0500142 case ACPI_S3:
Aaron Durbin76c37002012-10-30 09:03:43 -0500143 printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n");
144
Aaron Durbin76c37002012-10-30 09:03:43 -0500145 /* Invalidate the cache before going to S3 */
146 wbinvd();
147 break;
Aaron Durbinda5f5092016-07-13 23:23:16 -0500148 case ACPI_S4:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800149 printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n");
150 break;
Aaron Durbinda5f5092016-07-13 23:23:16 -0500151 case ACPI_S5:
Aaron Durbin76c37002012-10-30 09:03:43 -0500152 printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n");
153
Duncan Laurie467f31d2013-03-08 17:00:37 -0800154 /* Disable all GPE */
155 disable_all_gpe();
Aaron Durbin76c37002012-10-30 09:03:43 -0500156
157 /* Always set the flag in case CMOS was changed on runtime. For
158 * "KEEP", switch to "OFF" - KEEP is software emulated
159 */
Aaron Durbin89f79a02012-10-31 23:05:25 -0500160 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3);
Aaron Durbin76c37002012-10-30 09:03:43 -0500161 if (s5pwr == MAINBOARD_POWER_ON) {
162 reg8 &= ~1;
163 } else {
164 reg8 |= 1;
165 }
Aaron Durbin89f79a02012-10-31 23:05:25 -0500166 pci_write_config8(PCI_DEV(0, 0x1f, 0), GEN_PMCON_3, reg8);
Aaron Durbin76c37002012-10-30 09:03:43 -0500167
168 /* also iterates over all bridges on bus 0 */
169 busmaster_disable_on_bus(0);
170 break;
Duncan Laurie467f31d2013-03-08 17:00:37 -0800171 default:
172 printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n");
173 break;
Aaron Durbin76c37002012-10-30 09:03:43 -0500174 }
175
176 /* Write back to the SLP register to cause the originally intended
177 * event again. We need to set BIT13 (SLP_EN) though to make the
178 * sleep happen.
179 */
Duncan Laurie467f31d2013-03-08 17:00:37 -0800180 enable_pm1_control(SLP_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500181
182 /* Make sure to stop executing code here for S3/S4/S5 */
Aaron Durbinda5f5092016-07-13 23:23:16 -0500183 if (slp_typ >= ACPI_S3)
Patrick Georgi546953c2014-11-29 10:38:17 +0100184 halt();
Aaron Durbin76c37002012-10-30 09:03:43 -0500185
186 /* In most sleep states, the code flow of this function ends at
187 * the line above. However, if we entered sleep state S1 and wake
188 * up again, we will continue to execute code in this function.
189 */
190 reg32 = inl(pmbase + PM1_CNT);
191 if (reg32 & SCI_EN) {
192 /* The OS is not an ACPI OS, so we set the state to S0 */
Duncan Laurie467f31d2013-03-08 17:00:37 -0800193 disable_pm1_control(SLP_EN | SLP_TYP);
Aaron Durbin76c37002012-10-30 09:03:43 -0500194 }
195}
196
197/*
198 * Look for Synchronous IO SMI and use save state from that
199 * core in case we are not running on the same core that
200 * initiated the IO transaction.
201 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500202static em64t101_smm_state_save_area_t *smi_apmc_find_state_save(u8 cmd)
203{
204 em64t101_smm_state_save_area_t *state;
Aaron Durbin76c37002012-10-30 09:03:43 -0500205 int node;
206
207 /* Check all nodes looking for the one that issued the IO */
208 for (node = 0; node < CONFIG_MAX_CPUS; node++) {
Aaron Durbin29ffa542012-12-21 21:21:48 -0600209 state = smm_get_save_state(node);
Aaron Durbin76c37002012-10-30 09:03:43 -0500210
Elyes HAOUAS581fe582018-04-26 09:57:07 +0200211 /* Check for Synchronous IO (bit0 == 1) */
Aaron Durbin76c37002012-10-30 09:03:43 -0500212 if (!(state->io_misc_info & (1 << 0)))
213 continue;
214
Elyes HAOUAS581fe582018-04-26 09:57:07 +0200215 /* Make sure it was a write (bit4 == 0) */
Aaron Durbin76c37002012-10-30 09:03:43 -0500216 if (state->io_misc_info & (1 << 4))
217 continue;
218
219 /* Check for APMC IO port */
220 if (((state->io_misc_info >> 16) & 0xff) != APM_CNT)
221 continue;
222
223 /* Check AX against the requested command */
224 if ((state->rax & 0xff) != cmd)
225 continue;
226
227 return state;
228 }
229
230 return NULL;
231}
232
Aaron Durbin76c37002012-10-30 09:03:43 -0500233static void southbridge_smi_gsmi(void)
234{
235 u32 *ret, *param;
236 u8 sub_command;
237 em64t101_smm_state_save_area_t *io_smi =
Patrick Georgid61839c2018-12-03 16:10:33 +0100238 smi_apmc_find_state_save(APM_CNT_ELOG_GSMI);
Aaron Durbin76c37002012-10-30 09:03:43 -0500239
240 if (!io_smi)
241 return;
242
243 /* Command and return value in EAX */
244 ret = (u32*)&io_smi->rax;
245 sub_command = (u8)(*ret >> 8);
246
247 /* Parameter buffer in EBX */
248 param = (u32*)&io_smi->rbx;
249
250 /* drivers/elog/gsmi.c */
251 *ret = gsmi_exec(sub_command, param);
252}
Aaron Durbin76c37002012-10-30 09:03:43 -0500253
Matt DeVillier8187f112018-12-24 21:46:46 -0600254static void southbridge_smi_store(void)
255{
256 u8 sub_command, ret;
257 em64t101_smm_state_save_area_t *io_smi =
258 smi_apmc_find_state_save(APM_CNT_SMMSTORE);
259 uint32_t reg_ebx;
260
261 if (!io_smi)
262 return;
263 /* Command and return value in EAX */
264 sub_command = (io_smi->rax >> 8) & 0xff;
265
266 /* Parameter buffer in EBX */
267 reg_ebx = io_smi->rbx;
268
269 /* drivers/smmstore/smi.c */
270 ret = smmstore_exec(sub_command, (void *)reg_ebx);
271 io_smi->rax = ret;
272}
273
Aaron Durbin29ffa542012-12-21 21:21:48 -0600274static void southbridge_smi_apmc(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500275{
Aaron Durbin76c37002012-10-30 09:03:43 -0500276 u8 reg8;
Aaron Durbin76c37002012-10-30 09:03:43 -0500277 em64t101_smm_state_save_area_t *state;
Tristan Corrick09fc6342018-11-30 22:53:01 +1300278 static int chipset_finalized = 0;
Aaron Durbin76c37002012-10-30 09:03:43 -0500279
280 /* Emulate B2 register as the FADT / Linux expects it */
281
282 reg8 = inb(APM_CNT);
283 switch (reg8) {
Tristan Corrick09fc6342018-11-30 22:53:01 +1300284 case APM_CNT_FINALIZE:
285 if (chipset_finalized) {
286 printk(BIOS_DEBUG, "SMI#: Already finalized\n");
287 return;
288 }
289
Tristan Corrick63626b12018-11-30 22:53:50 +1300290 intel_me_finalize_smm();
Tristan Corrick09fc6342018-11-30 22:53:01 +1300291 intel_pch_finalize_smm();
292 intel_northbridge_haswell_finalize_smm();
293 intel_cpu_haswell_finalize_smm();
294
295 chipset_finalized = 1;
296 break;
Aaron Durbin76c37002012-10-30 09:03:43 -0500297 case APM_CNT_CST_CONTROL:
298 /* Calling this function seems to cause
299 * some kind of race condition in Linux
300 * and causes a kernel oops
301 */
302 printk(BIOS_DEBUG, "C-state control\n");
303 break;
304 case APM_CNT_PST_CONTROL:
305 /* Calling this function seems to cause
306 * some kind of race condition in Linux
307 * and causes a kernel oops
308 */
309 printk(BIOS_DEBUG, "P-state control\n");
310 break;
311 case APM_CNT_ACPI_DISABLE:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800312 disable_pm1_control(SCI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500313 printk(BIOS_DEBUG, "SMI#: ACPI disabled.\n");
314 break;
315 case APM_CNT_ACPI_ENABLE:
Duncan Laurie467f31d2013-03-08 17:00:37 -0800316 enable_pm1_control(SCI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500317 printk(BIOS_DEBUG, "SMI#: ACPI enabled.\n");
318 break;
319 case APM_CNT_GNVS_UPDATE:
320 if (smm_initialized) {
Duncan Laurie467f31d2013-03-08 17:00:37 -0800321 printk(BIOS_DEBUG,
322 "SMI#: SMM structures already initialized!\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500323 return;
324 }
325 state = smi_apmc_find_state_save(reg8);
326 if (state) {
327 /* EBX in the state save contains the GNVS pointer */
328 gnvs = (global_nvs_t *)((u32)state->rbx);
329 smm_initialized = 1;
330 printk(BIOS_DEBUG, "SMI#: Setting GNVS to %p\n", gnvs);
331 }
332 break;
Kyösti Mälkkib486f292020-06-18 14:05:35 +0300333 case APM_CNT_ROUTE_ALL_XHCI:
Duncan Laurie911cedf2013-07-30 16:05:55 -0700334 usb_xhci_route_all();
Duncan Laurie911cedf2013-07-30 16:05:55 -0700335 break;
Patrick Georgid61839c2018-12-03 16:10:33 +0100336 case APM_CNT_ELOG_GSMI:
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +0200337 if (CONFIG(ELOG_GSMI))
338 southbridge_smi_gsmi();
Aaron Durbin76c37002012-10-30 09:03:43 -0500339 break;
Matt DeVillier8187f112018-12-24 21:46:46 -0600340 case APM_CNT_SMMSTORE:
341 if (CONFIG(SMMSTORE))
342 southbridge_smi_store();
343 break;
Aaron Durbin76c37002012-10-30 09:03:43 -0500344 }
345
Aaron Durbin29ffa542012-12-21 21:21:48 -0600346 mainboard_smi_apmc(reg8);
Aaron Durbin76c37002012-10-30 09:03:43 -0500347}
348
Aaron Durbin29ffa542012-12-21 21:21:48 -0600349static void southbridge_smi_pm1(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500350{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800351 u16 pm1_sts = clear_pm1_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500352
353 /* While OSPM is not active, poweroff immediately
354 * on a power button event.
355 */
356 if (pm1_sts & PWRBTN_STS) {
357 // power button pressed
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +0200358 elog_gsmi_add_event(ELOG_TYPE_POWER_BUTTON);
Duncan Laurie467f31d2013-03-08 17:00:37 -0800359 disable_pm1_control(-1UL);
360 enable_pm1_control(SLP_EN | (SLP_TYP_S5 << 10));
Aaron Durbin76c37002012-10-30 09:03:43 -0500361 }
362}
363
Aaron Durbin29ffa542012-12-21 21:21:48 -0600364static void southbridge_smi_gpe0(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500365{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800366 clear_gpe_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500367}
368
Aaron Durbin29ffa542012-12-21 21:21:48 -0600369static void southbridge_smi_gpi(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500370{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800371 mainboard_smi_gpi(clear_alt_smi_status());
Aaron Durbin76c37002012-10-30 09:03:43 -0500372
Duncan Laurie467f31d2013-03-08 17:00:37 -0800373 /* Clear again after mainboard handler */
374 clear_alt_smi_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500375}
376
Aaron Durbin29ffa542012-12-21 21:21:48 -0600377static void southbridge_smi_mc(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500378{
379 u32 reg32;
380
Duncan Laurie467f31d2013-03-08 17:00:37 -0800381 reg32 = inl(get_pmbase() + SMI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500382
Duncan Laurie467f31d2013-03-08 17:00:37 -0800383 /* Are microcontroller SMIs enabled? */
Aaron Durbin76c37002012-10-30 09:03:43 -0500384 if ((reg32 & MCSMI_EN) == 0)
385 return;
386
387 printk(BIOS_DEBUG, "Microcontroller SMI.\n");
388}
389
390
391
Aaron Durbin29ffa542012-12-21 21:21:48 -0600392static void southbridge_smi_tco(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500393{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800394 u32 tco_sts = clear_tco_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500395
396 /* Any TCO event? */
397 if (!tco_sts)
398 return;
399
400 if (tco_sts & (1 << 8)) { // BIOSWR
401 u8 bios_cntl;
402
Aaron Durbin89f79a02012-10-31 23:05:25 -0500403 bios_cntl = pci_read_config16(PCI_DEV(0, 0x1f, 0), 0xdc);
Aaron Durbin76c37002012-10-30 09:03:43 -0500404
405 if (bios_cntl & 1) {
406 /* BWE is RW, so the SMI was caused by a
407 * write to BWE, not by a write to the BIOS
408 */
409
410 /* This is the place where we notice someone
411 * is trying to tinker with the BIOS. We are
412 * trying to be nice and just ignore it. A more
413 * resolute answer would be to power down the
414 * box.
415 */
416 printk(BIOS_DEBUG, "Switching back to RO\n");
Duncan Laurie467f31d2013-03-08 17:00:37 -0800417 pci_write_config32(PCI_DEV(0, 0x1f, 0), 0xdc,
418 (bios_cntl & ~1));
Aaron Durbin76c37002012-10-30 09:03:43 -0500419 } /* No else for now? */
420 } else if (tco_sts & (1 << 3)) { /* TIMEOUT */
421 /* Handle TCO timeout */
422 printk(BIOS_DEBUG, "TCO Timeout.\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500423 }
424}
425
Aaron Durbin29ffa542012-12-21 21:21:48 -0600426static void southbridge_smi_periodic(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500427{
428 u32 reg32;
429
Duncan Laurie467f31d2013-03-08 17:00:37 -0800430 reg32 = inl(get_pmbase() + SMI_EN);
Aaron Durbin76c37002012-10-30 09:03:43 -0500431
432 /* Are periodic SMIs enabled? */
433 if ((reg32 & PERIODIC_EN) == 0)
434 return;
435
436 printk(BIOS_DEBUG, "Periodic SMI.\n");
437}
438
Aaron Durbin29ffa542012-12-21 21:21:48 -0600439static void southbridge_smi_monitor(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500440{
441#define IOTRAP(x) (trap_sts & (1 << x))
442 u32 trap_sts, trap_cycle;
443 u32 data, mask = 0;
444 int i;
445
446 trap_sts = RCBA32(0x1e00); // TRSR - Trap Status Register
447 RCBA32(0x1e00) = trap_sts; // Clear trap(s) in TRSR
448
449 trap_cycle = RCBA32(0x1e10);
450 for (i=16; i<20; i++) {
451 if (trap_cycle & (1 << i))
452 mask |= (0xff << ((i - 16) << 2));
453 }
454
455
456 /* IOTRAP(3) SMI function call */
457 if (IOTRAP(3)) {
458 if (gnvs && gnvs->smif)
459 io_trap_handler(gnvs->smif); // call function smif
460 return;
461 }
462
463 /* IOTRAP(2) currently unused
464 * IOTRAP(1) currently unused */
465
466 /* IOTRAP(0) SMIC */
467 if (IOTRAP(0)) {
468 if (!(trap_cycle & (1 << 24))) { // It's a write
469 printk(BIOS_DEBUG, "SMI1 command\n");
470 data = RCBA32(0x1e18);
471 data &= mask;
472 // if (smi1)
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200473 // southbridge_smi_command(data);
Aaron Durbin76c37002012-10-30 09:03:43 -0500474 // return;
475 }
476 // Fall through to debug
477 }
478
Duncan Laurie467f31d2013-03-08 17:00:37 -0800479 printk(BIOS_DEBUG, " trapped io address = 0x%x\n",
480 trap_cycle & 0xfffc);
481 for (i=0; i < 4; i++)
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200482 if (IOTRAP(i)) printk(BIOS_DEBUG, " TRAP = %d\n", i);
Aaron Durbin76c37002012-10-30 09:03:43 -0500483 printk(BIOS_DEBUG, " AHBE = %x\n", (trap_cycle >> 16) & 0xf);
484 printk(BIOS_DEBUG, " MASK = 0x%08x\n", mask);
Duncan Laurie467f31d2013-03-08 17:00:37 -0800485 printk(BIOS_DEBUG, " read/write: %s\n",
486 (trap_cycle & (1 << 24)) ? "read" : "write");
Aaron Durbin76c37002012-10-30 09:03:43 -0500487
488 if (!(trap_cycle & (1 << 24))) {
489 /* Write Cycle */
490 data = RCBA32(0x1e18);
491 printk(BIOS_DEBUG, " iotrap written data = 0x%08x\n", data);
492 }
493#undef IOTRAP
494}
495
Aaron Durbin29ffa542012-12-21 21:21:48 -0600496typedef void (*smi_handler_t)(void);
Aaron Durbin76c37002012-10-30 09:03:43 -0500497
498static smi_handler_t southbridge_smi[32] = {
499 NULL, // [0] reserved
500 NULL, // [1] reserved
501 NULL, // [2] BIOS_STS
502 NULL, // [3] LEGACY_USB_STS
503 southbridge_smi_sleep, // [4] SLP_SMI_STS
504 southbridge_smi_apmc, // [5] APM_STS
505 NULL, // [6] SWSMI_TMR_STS
506 NULL, // [7] reserved
507 southbridge_smi_pm1, // [8] PM1_STS
508 southbridge_smi_gpe0, // [9] GPE0_STS
509 southbridge_smi_gpi, // [10] GPI_STS
510 southbridge_smi_mc, // [11] MCSMI_STS
511 NULL, // [12] DEVMON_STS
512 southbridge_smi_tco, // [13] TCO_STS
513 southbridge_smi_periodic, // [14] PERIODIC_STS
514 NULL, // [15] SERIRQ_SMI_STS
515 NULL, // [16] SMBUS_SMI_STS
516 NULL, // [17] LEGACY_USB2_STS
517 NULL, // [18] INTEL_USB2_STS
518 NULL, // [19] reserved
519 NULL, // [20] PCI_EXP_SMI_STS
520 southbridge_smi_monitor, // [21] MONITOR_STS
521 NULL, // [22] reserved
522 NULL, // [23] reserved
523 NULL, // [24] reserved
524 NULL, // [25] EL_SMI_STS
525 NULL, // [26] SPI_STS
526 NULL, // [27] reserved
527 NULL, // [28] reserved
528 NULL, // [29] reserved
529 NULL, // [30] reserved
530 NULL // [31] reserved
531};
532
533/**
534 * @brief Interrupt handler for SMI#
Aaron Durbin76c37002012-10-30 09:03:43 -0500535 */
Aaron Durbin29ffa542012-12-21 21:21:48 -0600536void southbridge_smi_handler(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500537{
Duncan Laurie467f31d2013-03-08 17:00:37 -0800538 int i;
Aaron Durbin76c37002012-10-30 09:03:43 -0500539 u32 smi_sts;
540
Aaron Durbin76c37002012-10-30 09:03:43 -0500541 /* We need to clear the SMI status registers, or we won't see what's
542 * happening in the following calls.
543 */
Duncan Laurie467f31d2013-03-08 17:00:37 -0800544 smi_sts = clear_smi_status();
Aaron Durbin76c37002012-10-30 09:03:43 -0500545
546 /* Call SMI sub handler for each of the status bits */
547 for (i = 0; i < 31; i++) {
548 if (smi_sts & (1 << i)) {
549 if (southbridge_smi[i]) {
Aaron Durbin29ffa542012-12-21 21:21:48 -0600550 southbridge_smi[i]();
Aaron Durbin76c37002012-10-30 09:03:43 -0500551 } else {
Duncan Laurie467f31d2013-03-08 17:00:37 -0800552 printk(BIOS_DEBUG,
Martin Roth2ed0aa22016-01-05 20:58:58 -0700553 "SMI_STS[%d] occurred, but no "
Duncan Laurie467f31d2013-03-08 17:00:37 -0800554 "handler available.\n", i);
Aaron Durbin76c37002012-10-30 09:03:43 -0500555 }
556 }
557 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500558}