Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Martin Roth | ebace9f | 2018-05-26 18:56:17 -0600 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * SMM utilities used in both SMM and normal mode |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 5 | */ |
| 6 | |
Michał Żygowski | f3db2ae | 2019-11-24 13:26:10 +0100 | [diff] [blame] | 7 | #include <amdblocks/acpimmio.h> |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 8 | #include <console/console.h> |
Felix Held | 78113d4 | 2024-01-08 17:09:09 +0100 | [diff] [blame] | 9 | #include <cpu/x86/smm.h> |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 10 | |
Felix Held | 78113d4 | 2024-01-08 17:09:09 +0100 | [diff] [blame] | 11 | #include "hudson.h" |
Michał Żygowski | f3db2ae | 2019-11-24 13:26:10 +0100 | [diff] [blame] | 12 | #include "smi.h" |
| 13 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 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 | |
Elyes HAOUAS | 44d1035 | 2022-01-07 18:23:43 +0100 | [diff] [blame] | 57 | /* And set the trigger level */ |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 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 | } |
Felix Held | 78113d4 | 2024-01-08 17:09:09 +0100 | [diff] [blame] | 82 | |
| 83 | uint16_t pm_acpi_smi_cmd_port(void) |
| 84 | { |
| 85 | return pm_read16(PM_ACPI_SMI_CMD); |
| 86 | } |