coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
smihandler.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <types.h>
4 #include <console/console.h>
5 #include <cpu/x86/smm.h>
6 #include <device/pci_def.h>
8 #include "i82801ix.h"
9 
10 #include <soc/nvs.h>
11 
12 #if CONFIG(SMM_LEGACY_ASEG)
13 /* For qemu/x86-q35 to build properly. */
14 struct global_nvs *gnvs;
15 #endif
16 
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 
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 
88 {
89 }
#define printk(level,...)
Definition: stdlib.h:16
void io_trap_handler(int smif)
Definition: smihandler.c:58
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
struct global_nvs * gnvs
int southbridge_io_trap_handler(int smif)
Definition: smihandler.c:131
static const int mask[4]
Definition: gpio.c:308
void southbridge_finalize_all(void)
Definition: smihandler.c:215
void southbridge_smi_monitor(void)
Definition: smihandler.c:89
#define RCBA32(x)
Definition: rcba.h:14
#define IOTRAP(x)
uint32_t u32
Definition: stdint.h:51
Definition: nvs.h:14
u8 smif
Definition: nvs.h:11