blob: 70b35850d6e02875359dceaf97901029d609e6a1 [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Martin Rothebace9f2018-05-26 18:56:17 -06002
3/*
4 * SMM utilities used in both SMM and normal mode
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03005 */
6
Michał Żygowskif3db2ae2019-11-24 13:26:10 +01007#include <amdblocks/acpimmio.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03008#include <console/console.h>
Felix Held78113d42024-01-08 17:09:09 +01009#include <cpu/x86/smm.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030010
Felix Held78113d42024-01-08 17:09:09 +010011#include "hudson.h"
Michał Żygowskif3db2ae2019-11-24 13:26:10 +010012#include "smi.h"
13
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030014#define HUDSON_SMI_ACPI_COMMAND 75
15
16static 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 */
45void 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
Elyes HAOUAS44d10352022-01-07 18:23:43 +010057 /* And set the trigger level */
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030058 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 */
65void 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 */
78void hudson_enable_acpi_cmd_smi(void)
79{
80 configure_smi(HUDSON_SMI_ACPI_COMMAND, SMI_MODE_SMI);
81}
Felix Held78113d42024-01-08 17:09:09 +010082
83uint16_t pm_acpi_smi_cmd_port(void)
84{
85 return pm_read16(PM_ACPI_SMI_CMD);
86}