Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 2 | |
| 3 | |
| 4 | #include <device/device.h> |
| 5 | #include <device/pci.h> |
| 6 | #include <console/console.h> |
| 7 | #include <arch/io.h> |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 8 | #include <cpu/x86/smm.h> |
Kyösti Mälkki | f091f4d | 2019-08-14 03:49:21 +0300 | [diff] [blame] | 9 | #include <cpu/intel/smm_reloc.h> |
Patrick Rudolph | ed3242e | 2018-06-29 10:34:37 +0200 | [diff] [blame] | 10 | #include <southbridge/intel/common/pmbase.h> |
Arthur Heymans | f0a017f | 2018-12-25 15:26:58 +0100 | [diff] [blame] | 11 | #include <southbridge/intel/common/pmutil.h> |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 12 | |
| 13 | #include "pmutil.h" |
| 14 | |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 15 | u16 get_pmbase(void) |
| 16 | { |
Patrick Rudolph | ed3242e | 2018-06-29 10:34:37 +0200 | [diff] [blame] | 17 | return lpc_get_pmbase(); |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 18 | } |
| 19 | |
Kyösti Mälkki | 7e75f33 | 2020-06-14 12:23:04 +0300 | [diff] [blame^] | 20 | static int smi_enabled(void) |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 21 | { |
| 22 | u32 smi_en; |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 23 | |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 24 | /* Log events from chipset before clearing */ |
Kyösti Mälkki | 7e75f33 | 2020-06-14 12:23:04 +0300 | [diff] [blame^] | 25 | if (CONFIG(ELOG)) |
Arthur Heymans | f0a017f | 2018-12-25 15:26:58 +0100 | [diff] [blame] | 26 | pch_log_state(); |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 27 | |
| 28 | printk(BIOS_DEBUG, "Initializing southbridge SMI..."); |
Patrick Rudolph | ed3242e | 2018-06-29 10:34:37 +0200 | [diff] [blame] | 29 | printk(BIOS_SPEW, " ... pmbase = 0x%04x\n", lpc_get_pmbase()); |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 30 | |
Patrick Rudolph | ed3242e | 2018-06-29 10:34:37 +0200 | [diff] [blame] | 31 | smi_en = read_pmbase32(SMI_EN); |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 32 | if (smi_en & APMC_EN) { |
| 33 | printk(BIOS_INFO, "SMI# handler already enabled?\n"); |
Kyösti Mälkki | 7e75f33 | 2020-06-14 12:23:04 +0300 | [diff] [blame^] | 34 | return 1; |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 35 | } |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 36 | printk(BIOS_DEBUG, "\n"); |
Kyösti Mälkki | 7e75f33 | 2020-06-14 12:23:04 +0300 | [diff] [blame^] | 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | static void smm_southbridge_enable(uint16_t pm1_events) |
| 41 | { |
| 42 | u32 smi_en; |
| 43 | u32 gpe0_en; |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 44 | |
| 45 | /* Disable GPE0 PME_B0 */ |
Patrick Rudolph | ed3242e | 2018-06-29 10:34:37 +0200 | [diff] [blame] | 46 | gpe0_en = read_pmbase32(GPE0_EN); |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 47 | gpe0_en &= ~PME_B0_EN; |
Patrick Rudolph | ed3242e | 2018-06-29 10:34:37 +0200 | [diff] [blame] | 48 | write_pmbase32(GPE0_EN, gpe0_en); |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 49 | |
Kyösti Mälkki | 0778c86 | 2020-06-10 12:44:03 +0300 | [diff] [blame] | 50 | write_pmbase16(PM1_EN, pm1_events); |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 51 | |
| 52 | /* Enable SMI generation: |
| 53 | * - on TCO events |
| 54 | * - on APMC writes (io 0xb2) |
| 55 | * - on writes to SLP_EN (sleep states) |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 56 | * No SMIs: |
| 57 | * - on microcontroller writes (io 0x62/0x66) |
| 58 | */ |
| 59 | |
| 60 | smi_en = 0; /* reset SMI enables */ |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 61 | smi_en |= TCO_EN; |
| 62 | smi_en |= APMC_EN; |
Kyösti Mälkki | 9446447 | 2020-06-13 13:45:42 +0300 | [diff] [blame] | 63 | if (CONFIG(DEBUG_PERIODIC_SMI)) |
| 64 | smi_en |= PERIODIC_EN; |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 65 | smi_en |= SLP_SMI_EN; |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 66 | |
| 67 | /* The following need to be on for SMIs to happen */ |
| 68 | smi_en |= EOS | GBL_SMI_EN; |
| 69 | |
Patrick Rudolph | ed3242e | 2018-06-29 10:34:37 +0200 | [diff] [blame] | 70 | write_pmbase32(SMI_EN, smi_en); |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 71 | } |
| 72 | |
Kyösti Mälkki | 0778c86 | 2020-06-10 12:44:03 +0300 | [diff] [blame] | 73 | void global_smi_enable(void) |
| 74 | { |
Kyösti Mälkki | 7e75f33 | 2020-06-14 12:23:04 +0300 | [diff] [blame^] | 75 | if (smi_enabled()) |
| 76 | return; |
| 77 | |
| 78 | dump_all_status(); |
Kyösti Mälkki | 0778c86 | 2020-06-10 12:44:03 +0300 | [diff] [blame] | 79 | smm_southbridge_enable(PWRBTN_EN | GBL_EN); |
| 80 | } |
| 81 | |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 82 | void smm_setup_structures(void *gnvs, void *tcg, void *smi1) |
| 83 | { |
| 84 | /* |
| 85 | * Issue SMI to set the gnvs pointer in SMM. |
| 86 | * tcg and smi1 are unused. |
| 87 | * |
| 88 | * EAX = APM_CNT_GNVS_UPDATE |
| 89 | * EBX = gnvs pointer |
| 90 | * EDX = APM_CNT |
| 91 | */ |
| 92 | asm volatile ( |
| 93 | "outb %%al, %%dx\n\t" |
| 94 | : /* ignore result */ |
| 95 | : "a" (APM_CNT_GNVS_UPDATE), |
Patrick Rudolph | 4af2add | 2018-11-26 15:56:11 +0100 | [diff] [blame] | 96 | "b" ((uintptr_t)gnvs), |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 97 | "d" (APM_CNT) |
| 98 | ); |
| 99 | } |
Arthur Heymans | edbf5d9 | 2018-01-25 20:03:42 +0100 | [diff] [blame] | 100 | |
Kyösti Mälkki | faf20d3 | 2019-08-14 05:41:41 +0300 | [diff] [blame] | 101 | void smm_southbridge_clear_state(void) |
Arthur Heymans | edbf5d9 | 2018-01-25 20:03:42 +0100 | [diff] [blame] | 102 | { |
Kyösti Mälkki | 7e75f33 | 2020-06-14 12:23:04 +0300 | [diff] [blame^] | 103 | if (smi_enabled()) |
Arthur Heymans | edbf5d9 | 2018-01-25 20:03:42 +0100 | [diff] [blame] | 104 | return; |
Arthur Heymans | edbf5d9 | 2018-01-25 20:03:42 +0100 | [diff] [blame] | 105 | |
| 106 | /* Dump and clear status registers */ |
| 107 | reset_smi_status(); |
| 108 | reset_pm1_status(); |
| 109 | reset_tco_status(); |
| 110 | reset_gpe0_status(); |
| 111 | } |