Debian Codegraph @

src/southbridge/amd/pi/hudson/smi_util.c

raw symbols SCIP
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 #include <cpu/x86/smm.h>
10
11 #include "hudson.h"
12 #include "smi.h"
13
14 #define HUDSON_SMI_ACPI_COMMAND 75
15
16 static void configure_smi(uint8_t smi_num, uint8_t mode)
17 {
18 uint8_t reg32_offset, bit_offset;
19 uint32_t reg32;
20
21 /* SMI sources range from [0:149] */
22 if (smi_num > 149) {
23 printk(BIOS_WARNING, "BUG: Invalid SMI: %u\n", smi_num);
24 return;
25 }
26
27 /* 16 sources per register, 2 bits per source; registers are 4 bytes */
28 reg32_offset = (smi_num / 16) * 4;
29 bit_offset = (smi_num % 16) * 2;
30
31 reg32 = smi_read32(SMI_REG_CONTROL0 + reg32_offset);
32 reg32 &= ~(0x3 << (bit_offset));
33 reg32 |= (mode & 0x3) << bit_offset;
34 smi_write32(SMI_REG_CONTROL0 + reg32_offset, reg32);
35 }
36
37 /**
38 * Configure generation of interrupts for given GEVENT pin
39 *
40 * @param gevent The GEVENT pin number. Valid values are 0 thru 23
41 * @param mode The type of event this pin should generate. Note that only
42 * SMI_MODE_SMI generates an SMI. SMI_MODE_DISABLE disables events.
43 * @param level SMI_LVL_LOW or SMI_LVL_HIGH
44 */
45 void hudson_configure_gevent_smi(uint8_t gevent, uint8_t mode, uint8_t level)
46 {
47 uint32_t reg32;
48 /* GEVENT pins range from [0:23] */
49 if (gevent > 23) {
50 printk(BIOS_WARNING, "BUG: Invalid GEVENT: %u\n", gevent);
51 return;
52 }
53
54 /* SMI0 source is GEVENT0 and so on */
55 configure_smi(gevent, mode);
56
57 /* And set the trigger level */
58 reg32 = smi_read32(SMI_REG_SMITRIG0);
59 reg32 &= ~(1 << gevent);
60 reg32 |= (level & 0x1) << gevent;
61 smi_write32(SMI_REG_SMITRIG0, reg32);
62 }
63
64 /** Disable events from given GEVENT pin */
65 void hudson_disable_gevent_smi(uint8_t gevent)
66 {
67 /* GEVENT pins range from [0:23] */
68 if (gevent > 23) {
69 printk(BIOS_WARNING, "BUG: Invalid GEVENT: %u\n", gevent);
70 return;
71 }
72
73 /* SMI0 source is GEVENT0 and so on */
74 configure_smi(gevent, SMI_MODE_DISABLE);
75 }
76
77 /** Enable SMIs on writes to ACPI SMI command port */
78 void hudson_enable_acpi_cmd_smi(void)
79 {
80 configure_smi(HUDSON_SMI_ACPI_COMMAND, SMI_MODE_SMI);
81 }
82
83 uint16_t pm_acpi_smi_cmd_port(void)
84 {
85 return pm_read16(PM_ACPI_SMI_CMD);
86 }