coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
smi_util.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /*
4  * SMM utilities used in both SMM and normal mode
5  */
6 
7 #include <amdblocks/acpimmio.h>
8 #include <console/console.h>
9 
10 #include "smi.h"
11 
12 #define HUDSON_SMI_ACPI_COMMAND 75
13 
14 static void configure_smi(uint8_t smi_num, uint8_t mode)
15 {
16  uint8_t reg32_offset, bit_offset;
17  uint32_t reg32;
18 
19  /* SMI sources range from [0:149] */
20  if (smi_num > 149) {
21  printk(BIOS_WARNING, "BUG: Invalid SMI: %u\n", smi_num);
22  return;
23  }
24 
25  /* 16 sources per register, 2 bits per source; registers are 4 bytes */
26  reg32_offset = (smi_num / 16) * 4;
27  bit_offset = (smi_num % 16) * 2;
28 
29  reg32 = smi_read32(SMI_REG_CONTROL0 + reg32_offset);
30  reg32 &= ~(0x3 << (bit_offset));
31  reg32 |= (mode & 0x3) << bit_offset;
32  smi_write32(SMI_REG_CONTROL0 + reg32_offset, reg32);
33 }
34 
35 /**
36  * Configure generation of interrupts for given GEVENT pin
37  *
38  * @param gevent The GEVENT pin number. Valid values are 0 thru 23
39  * @param mode The type of event this pin should generate. Note that only
40  * SMI_MODE_SMI generates an SMI. SMI_MODE_DISABLE disables events.
41  * @param level SMI_LVL_LOW or SMI_LVL_HIGH
42  */
44 {
45  uint32_t reg32;
46  /* GEVENT pins range from [0:23] */
47  if (gevent > 23) {
48  printk(BIOS_WARNING, "BUG: Invalid GEVENT: %u\n", gevent);
49  return;
50  }
51 
52  /* SMI0 source is GEVENT0 and so on */
53  configure_smi(gevent, mode);
54 
55  /* And set the trigger level */
57  reg32 &= ~(1 << gevent);
58  reg32 |= (level & 0x1) << gevent;
60 }
61 
62 /** Disable events from given GEVENT pin */
64 {
65  /* GEVENT pins range from [0:23] */
66  if (gevent > 23) {
67  printk(BIOS_WARNING, "BUG: Invalid GEVENT: %u\n", gevent);
68  return;
69  }
70 
71  /* SMI0 source is GEVENT0 and so on */
73 }
74 
75 /** Enable SMIs on writes to ACPI SMI command port */
77 {
79 }
static void smi_write32(uint8_t reg, uint32_t value)
Definition: acpimmio.h:161
static uint32_t smi_read32(uint8_t reg)
Definition: acpimmio.h:146
#define printk(level,...)
Definition: stdlib.h:16
#define BIOS_WARNING
BIOS_WARNING - Bad configuration.
Definition: loglevel.h:86
#define SMI_REG_CONTROL0
Definition: smi.h:169
#define SMI_REG_SMITRIG0
Definition: smi.h:163
@ SMI_MODE_SMI
Definition: smi.h:10
@ SMI_MODE_DISABLE
Definition: smi.h:9
void configure_smi(uint8_t smi_num, uint8_t mode)
Definition: smi_util.c:12
void hudson_disable_gevent_smi(uint8_t gevent)
Disable events from given GEVENT pin.
Definition: smi_util.c:63
#define HUDSON_SMI_ACPI_COMMAND
Definition: smi_util.c:12
void hudson_enable_acpi_cmd_smi(void)
Enable SMIs on writes to ACPI SMI command port.
Definition: smi_util.c:76
void hudson_configure_gevent_smi(uint8_t gevent, uint8_t mode, uint8_t level)
Configure generation of interrupts for given GEVENT pin.
Definition: smi_util.c:43
unsigned int uint32_t
Definition: stdint.h:14
unsigned char uint8_t
Definition: stdint.h:8