Angel Pons | c3f58f6 | 2020-04-05 15:46:41 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 7837be6 | 2013-10-21 22:32:00 -0500 | [diff] [blame] | 2 | |
Aaron Durbin | 7837be6 | 2013-10-21 22:32:00 -0500 | [diff] [blame] | 3 | #include <arch/io.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 4 | #include <device/mmio.h> |
Angel Pons | c5bcd28 | 2020-07-07 18:16:35 +0200 | [diff] [blame] | 5 | #include <console/console.h> |
Aaron Durbin | 7837be6 | 2013-10-21 22:32:00 -0500 | [diff] [blame] | 6 | #include <cpu/x86/smm.h> |
Kyösti Mälkki | faf20d3 | 2019-08-14 05:41:41 +0300 | [diff] [blame] | 7 | #include <cpu/intel/smm_reloc.h> |
Angel Pons | c5bcd28 | 2020-07-07 18:16:35 +0200 | [diff] [blame] | 8 | #include <device/device.h> |
| 9 | #include <device/pci.h> |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 10 | #include <soc/iomap.h> |
Angel Pons | b5320b2 | 2020-07-07 18:27:30 +0200 | [diff] [blame] | 11 | #include <soc/pm.h> |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 12 | #include <soc/smm.h> |
Aaron Durbin | 7837be6 | 2013-10-21 22:32:00 -0500 | [diff] [blame] | 13 | |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 14 | /* Save settings which will be committed in SMI functions. */ |
| 15 | static uint32_t smm_save_params[SMM_SAVE_PARAM_COUNT]; |
Aaron Durbin | 59a4cd5 | 2013-11-11 12:09:28 -0600 | [diff] [blame] | 16 | |
Kyösti Mälkki | faf20d3 | 2019-08-14 05:41:41 +0300 | [diff] [blame] | 17 | void smm_southcluster_save_param(int param, uint32_t data) |
Aaron Durbin | 59a4cd5 | 2013-11-11 12:09:28 -0600 | [diff] [blame] | 18 | { |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 19 | smm_save_params[param] = data; |
Aaron Durbin | 59a4cd5 | 2013-11-11 12:09:28 -0600 | [diff] [blame] | 20 | } |
| 21 | |
Kyösti Mälkki | faf20d3 | 2019-08-14 05:41:41 +0300 | [diff] [blame] | 22 | void smm_southbridge_clear_state(void) |
Aaron Durbin | 7837be6 | 2013-10-21 22:32:00 -0500 | [diff] [blame] | 23 | { |
| 24 | uint32_t smi_en; |
| 25 | |
| 26 | /* Log events from chipset before clearing */ |
Kyösti Mälkki | 056fbe4 | 2019-11-06 12:07:05 +0200 | [diff] [blame] | 27 | if (CONFIG(ELOG)) |
| 28 | southcluster_log_state(); |
Aaron Durbin | 7837be6 | 2013-10-21 22:32:00 -0500 | [diff] [blame] | 29 | |
| 30 | printk(BIOS_DEBUG, "Initializing Southbridge SMI..."); |
| 31 | printk(BIOS_SPEW, " pmbase = 0x%04x\n", get_pmbase()); |
| 32 | |
| 33 | smi_en = inl(get_pmbase() + SMI_EN); |
| 34 | if (smi_en & APMC_EN) { |
| 35 | printk(BIOS_INFO, "SMI# handler already enabled?\n"); |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | /* Dump and clear status registers */ |
| 40 | clear_smi_status(); |
| 41 | clear_pm1_status(); |
| 42 | clear_tco_status(); |
| 43 | clear_gpe_status(); |
Aaron Durbin | 9f83e87 | 2013-11-11 14:45:27 -0600 | [diff] [blame] | 44 | clear_alt_status(); |
Aaron Durbin | 19edc3a | 2014-01-09 11:17:37 -0600 | [diff] [blame] | 45 | clear_pmc_status(); |
Aaron Durbin | 7837be6 | 2013-10-21 22:32:00 -0500 | [diff] [blame] | 46 | } |
| 47 | |
Kyösti Mälkki | faf20d3 | 2019-08-14 05:41:41 +0300 | [diff] [blame] | 48 | static void smm_southcluster_route_gpios(void) |
Aaron Durbin | 59a4cd5 | 2013-11-11 12:09:28 -0600 | [diff] [blame] | 49 | { |
Angel Pons | e80d17f | 2020-07-07 17:25:38 +0200 | [diff] [blame] | 50 | void *gpio_rout = (void *)(PMC_BASE_ADDRESS + GPIO_ROUT); |
Aaron Durbin | 59a4cd5 | 2013-11-11 12:09:28 -0600 | [diff] [blame] | 51 | const unsigned short alt_gpio_smi = ACPI_BASE_ADDRESS + ALT_GPIO_SMI; |
| 52 | uint32_t alt_gpio_reg = 0; |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 53 | uint32_t route_reg = smm_save_params[SMM_SAVE_PARAM_GPIO_ROUTE]; |
Aaron Durbin | 59a4cd5 | 2013-11-11 12:09:28 -0600 | [diff] [blame] | 54 | int i; |
| 55 | |
| 56 | printk(BIOS_DEBUG, "GPIO_ROUT = %08x\n", route_reg); |
| 57 | |
| 58 | /* Start the routing for the specific gpios. */ |
| 59 | write32(gpio_rout, route_reg); |
| 60 | |
| 61 | /* Enable SMIs for the gpios that are set to trigger the SMI. */ |
| 62 | for (i = 0; i < 16; i++) { |
Angel Pons | c5bcd28 | 2020-07-07 18:16:35 +0200 | [diff] [blame] | 63 | if ((route_reg & ROUTE_MASK) == ROUTE_SMI) |
Aaron Durbin | 59a4cd5 | 2013-11-11 12:09:28 -0600 | [diff] [blame] | 64 | alt_gpio_reg |= (1 << i); |
Angel Pons | c5bcd28 | 2020-07-07 18:16:35 +0200 | [diff] [blame] | 65 | |
Aaron Durbin | 59a4cd5 | 2013-11-11 12:09:28 -0600 | [diff] [blame] | 66 | route_reg >>= 2; |
| 67 | } |
| 68 | printk(BIOS_DEBUG, "ALT_GPIO_SMI = %08x\n", alt_gpio_reg); |
| 69 | |
| 70 | outl(alt_gpio_reg, alt_gpio_smi); |
| 71 | } |
| 72 | |
Kyösti Mälkki | 0778c86 | 2020-06-10 12:44:03 +0300 | [diff] [blame] | 73 | static void smm_southbridge_enable(uint16_t pm1_events) |
Aaron Durbin | 7837be6 | 2013-10-21 22:32:00 -0500 | [diff] [blame] | 74 | { |
Aaron Durbin | 59a4cd5 | 2013-11-11 12:09:28 -0600 | [diff] [blame] | 75 | |
Aaron Durbin | 7837be6 | 2013-10-21 22:32:00 -0500 | [diff] [blame] | 76 | printk(BIOS_DEBUG, "Enabling SMIs.\n"); |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 77 | if (!smm_save_params[SMM_SAVE_PARAM_PCIE_WAKE_ENABLE]) |
| 78 | pm1_events |= PCIEXPWAK_DIS; |
Angel Pons | 26b49cc | 2020-07-07 17:17:51 +0200 | [diff] [blame] | 79 | |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 80 | enable_pm1(pm1_events); |
Aaron Durbin | 7837be6 | 2013-10-21 22:32:00 -0500 | [diff] [blame] | 81 | disable_gpe(PME_B0_EN); |
| 82 | |
Aaron Durbin | 59a4cd5 | 2013-11-11 12:09:28 -0600 | [diff] [blame] | 83 | /* Set up the GPIO route. */ |
Kyösti Mälkki | faf20d3 | 2019-08-14 05:41:41 +0300 | [diff] [blame] | 84 | smm_southcluster_route_gpios(); |
Aaron Durbin | 59a4cd5 | 2013-11-11 12:09:28 -0600 | [diff] [blame] | 85 | |
Angel Pons | 26b49cc | 2020-07-07 17:17:51 +0200 | [diff] [blame] | 86 | /* |
| 87 | * Enable SMI generation: |
Aaron Durbin | 7837be6 | 2013-10-21 22:32:00 -0500 | [diff] [blame] | 88 | * - on APMC writes (io 0xb2) |
| 89 | * - on writes to SLP_EN (sleep states) |
| 90 | * - on writes to GBL_RLS (bios commands) |
| 91 | * No SMIs: |
Aaron Durbin | 766482d | 2014-01-09 10:44:06 -0600 | [diff] [blame] | 92 | * - on TCO events |
Aaron Durbin | 7837be6 | 2013-10-21 22:32:00 -0500 | [diff] [blame] | 93 | * - on microcontroller writes (io 0x62/0x66) |
| 94 | */ |
Aaron Durbin | 766482d | 2014-01-09 10:44:06 -0600 | [diff] [blame] | 95 | enable_smi(APMC_EN | SLP_SMI_EN | GBL_SMI_EN | EOS); |
Aaron Durbin | 7837be6 | 2013-10-21 22:32:00 -0500 | [diff] [blame] | 96 | } |
| 97 | |
Kyösti Mälkki | 0778c86 | 2020-06-10 12:44:03 +0300 | [diff] [blame] | 98 | void global_smi_enable(void) |
| 99 | { |
| 100 | smm_southbridge_enable(PWRBTN_EN | GBL_EN); |
| 101 | } |