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 <arch/io.h>
5 #include <device/pci_ops.h>
6 #include <console/console.h>
7 #include <device/pci_def.h>
8 #include <cpu/x86/smm.h>
14 #include "pch.h"
15 
16 /* We are using PCIe accesses for now
17  * 1. the chipset can do it
18  * 2. we don't need to worry about how we leave 0xcf8/0xcfc behind
19  */
23 
25  u16 use, u16 io, u16 lvl)
26 {
27  u32 reg32;
28 
29  /* Make sure it is set as GPIO */
30  reg32 = inl(use);
31  if (!(reg32 & (1 << offset))) {
32  reg32 |= (1 << offset);
33  outl(reg32, use);
34  }
35 
36  /* Make sure it is set as output */
37  reg32 = inl(io);
38  if (reg32 & (1 << offset)) {
39  reg32 &= ~(1 << offset);
40  outl(reg32, io);
41  }
42 
43  /* Drive the output low */
44  reg32 = inl(lvl);
45  reg32 &= ~(1 << offset);
46  outl(reg32, lvl);
47 }
48 
49 /*
50  * Drive GPIO 60 low to gate memory reset in S3.
51  *
52  * Intel reference designs all use GPIO 60 but it is
53  * not a requirement and boards could use a different pin.
54  */
56 {
57  u16 gpiobase;
58 
59  gpiobase = pci_read_config16(PCI_DEV(0, 0x1f, 0), GPIOBASE) & 0xfffc;
60  if (!gpiobase)
61  return;
62 
63  if (CONFIG_DRAM_RESET_GATE_GPIO >= 32)
64  southbridge_gate_memory_reset_real(CONFIG_DRAM_RESET_GATE_GPIO - 32,
65  gpiobase + GPIO_USE_SEL2,
66  gpiobase + GP_IO_SEL2,
67  gpiobase + GP_LVL2);
68  else
69  southbridge_gate_memory_reset_real(CONFIG_DRAM_RESET_GATE_GPIO,
70  gpiobase + GPIO_USE_SEL,
71  gpiobase + GP_IO_SEL,
72  gpiobase + GP_LVL);
73 }
74 
76 {
77 #define IOTRAP(x) (trap_sts & (1 << x))
78  u32 trap_sts, trap_cycle;
79  u32 data, mask = 0;
80  int i;
81 
82  trap_sts = RCBA32(0x1e00); // TRSR - Trap Status Register
83  RCBA32(0x1e00) = trap_sts; // Clear trap(s) in TRSR
84 
85  trap_cycle = RCBA32(0x1e10);
86  for (i = 16; i < 20; i++) {
87  if (trap_cycle & (1 << i))
88  mask |= (0xff << ((i - 16) << 2));
89  }
90 
91  /* IOTRAP(3) SMI function call */
92  if (IOTRAP(3)) {
93  return;
94  }
95 
96  /* IOTRAP(2) currently unused
97  * IOTRAP(1) currently unused */
98 
99  /* IOTRAP(0) SMIC */
100  if (IOTRAP(0)) {
101  if (!(trap_cycle & (1 << 24))) { // It's a write
102  printk(BIOS_DEBUG, "SMI1 command\n");
103  data = RCBA32(0x1e18);
104  data &= mask;
105  // if (smi1)
106  // southbridge_smi_command(data);
107  // return;
108  }
109  // Fall through to debug
110  }
111 
112  printk(BIOS_DEBUG, " trapped io address = 0x%x\n", trap_cycle & 0xfffc);
113  for (i = 0; i < 4; i++) {
114  if (IOTRAP(i))
115  printk(BIOS_DEBUG, " TRAP = %d\n", i);
116  }
117  printk(BIOS_DEBUG, " AHBE = %x\n", (trap_cycle >> 16) & 0xf);
118  printk(BIOS_DEBUG, " MASK = 0x%08x\n", mask);
119  printk(BIOS_DEBUG, " read/write: %s\n", (trap_cycle & (1 << 24)) ? "read" : "write");
120 
121  if (!(trap_cycle & (1 << 24))) {
122  /* Write Cycle */
123  data = RCBA32(0x1e18);
124  printk(BIOS_DEBUG, " iotrap written data = 0x%08x\n", data);
125  }
126 #undef IOTRAP
127 }
128 
130 {
131  /* TODO: Finalize ME */
135 }
#define printk(level,...)
Definition: stdlib.h:16
void intel_model_2065x_finalize_smm(void)
Definition: finalize.c:14
u32 inl(u16 port)
void outl(u32 val, u16 port)
static size_t offset
Definition: flashconsole.c:16
static __always_inline u16 pci_read_config16(const struct device *dev, u16 reg)
Definition: pci_ops.h:52
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
void intel_ironlake_finalize_smm(void)
Definition: finalize.c:5
#define PCI_DEV(SEGBUS, DEV, FN)
Definition: pci_type.h:14
#define GPIOBASE
Definition: lpc.h:19
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
void southbridge_gate_memory_reset(void)
Definition: smihandler.c:69
void intel_pch_finalize_smm(void)
Definition: finalize.c:12
#define GP_LVL
Definition: gpio.h:11
#define GP_IO_SEL
Definition: gpio.h:10
#define GP_LVL2
Definition: gpio.h:16
#define GPIO_USE_SEL
Definition: gpio.h:9
#define GPIO_USE_SEL2
Definition: gpio.h:14
#define GP_IO_SEL2
Definition: gpio.h:15
#define RCBA32(x)
Definition: rcba.h:14
#define IOTRAP(x)
static void southbridge_gate_memory_reset_real(int offset, u16 use, u16 io, u16 lvl)
Definition: smihandler.c:24
uint32_t u32
Definition: stdint.h:51
uint16_t u16
Definition: stdint.h:48