blob: 3aca8749ef3537a84a452a17e33bcb7d09a079d8 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Georgie72a8a32012-11-06 11:05:09 +01002
3#include <types.h>
Patrick Georgie72a8a32012-11-06 11:05:09 +01004#include <console/console.h>
Patrick Georgie72a8a32012-11-06 11:05:09 +01005#include <cpu/x86/smm.h>
6#include <device/pci_def.h>
Arthur Heymansaade90e2018-01-25 00:33:45 +01007#include <southbridge/intel/common/pmutil.h>
Patrick Georgie72a8a32012-11-06 11:05:09 +01008#include "i82801ix.h"
9
Kyösti Mälkki661ad462020-12-29 06:26:21 +020010#include <soc/nvs.h>
Patrick Georgie72a8a32012-11-06 11:05:09 +010011
Kyösti Mälkki894f6f82022-01-29 14:05:58 +020012#if CONFIG(SMM_LEGACY_ASEG)
Kyösti Mälkki239abaf2020-06-28 12:12:01 +030013/* For qemu/x86-q35 to build properly. */
14struct global_nvs *gnvs;
15#endif
16
Patrick Georgie72a8a32012-11-06 11:05:09 +010017int southbridge_io_trap_handler(int smif)
18{
19 switch (smif) {
20 case 0x32:
21 printk(BIOS_DEBUG, "OS Init\n");
22 /* gnvs->smif:
23 * On success, the IO Trap Handler returns 0
24 * On failure, the IO Trap Handler returns a value != 0
25 */
26 gnvs->smif = 0;
27 return 1; /* IO trap handled */
28 }
29
30 /* Not handled */
31 return 0;
32}
33
Arthur Heymansaade90e2018-01-25 00:33:45 +010034void southbridge_smi_monitor(void)
Patrick Georgie72a8a32012-11-06 11:05:09 +010035{
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
Patrick Georgie72a8a32012-11-06 11:05:09 +010050 /* 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);
Patrick Georgie72a8a32012-11-06 11:05:09 +010065 }
66 // Fall through to debug
67 }
68
69 printk(BIOS_DEBUG, " trapped io address = 0x%x\n", trap_cycle & 0xfffc);
Elyes HAOUAS70d79a42016-08-21 18:36:06 +020070 for (i=0; i < 4; i++) if (IOTRAP(i)) printk(BIOS_DEBUG, " TRAP = %d\n", i);
Patrick Georgie72a8a32012-11-06 11:05:09 +010071 printk(BIOS_DEBUG, " AHBE = %x\n", (trap_cycle >> 16) & 0xf);
72 printk(BIOS_DEBUG, " MASK = 0x%08x\n", mask);
73 printk(BIOS_DEBUG, " read/write: %s\n", (trap_cycle & (1 << 24)) ? "read" : "write");
74
75 if (!(trap_cycle & (1 << 24))) {
76 /* Write Cycle */
77 data = RCBA32(0x1e18);
78 printk(BIOS_DEBUG, " iotrap written data = 0x%08x\n", data);
79 }
80#undef IOTRAP
81}
82
Arthur Heymansaade90e2018-01-25 00:33:45 +010083void southbridge_finalize_all(void)
Patrick Georgie72a8a32012-11-06 11:05:09 +010084{
Patrick Georgie72a8a32012-11-06 11:05:09 +010085}