Angel Pons | ba38f37 | 2020-04-05 15:46:45 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 2 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [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> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 5 | #include <console/console.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [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> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 8 | #include <device/device.h> |
| 9 | #include <device/pci.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 10 | #include <soc/iomap.h> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 11 | #include <soc/pm.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 12 | #include <soc/smm.h> |
| 13 | |
| 14 | /* Save settings which will be committed in SMI functions. */ |
| 15 | static uint32_t smm_save_params[SMM_SAVE_PARAM_COUNT]; |
| 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) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 18 | { |
| 19 | smm_save_params[param] = data; |
| 20 | } |
| 21 | |
Kyösti Mälkki | faf20d3 | 2019-08-14 05:41:41 +0300 | [diff] [blame] | 22 | void smm_southbridge_clear_state(void) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [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(); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 29 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 30 | smi_en = inl(get_pmbase() + SMI_EN); |
| 31 | if (smi_en & APMC_EN) { |
| 32 | printk(BIOS_INFO, "SMI# handler already enabled?\n"); |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | /* Dump and clear status registers */ |
| 37 | clear_smi_status(); |
| 38 | clear_pm1_status(); |
| 39 | clear_tco_status(); |
| 40 | clear_gpe_status(); |
| 41 | clear_alt_status(); |
| 42 | clear_pmc_status(); |
| 43 | } |
| 44 | |
Kyösti Mälkki | faf20d3 | 2019-08-14 05:41:41 +0300 | [diff] [blame] | 45 | static void smm_southcluster_route_gpios(void) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 46 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 47 | void *gpio_rout = (void *)(PMC_BASE_ADDRESS + GPIO_ROUT); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 48 | const unsigned short alt_gpio_smi = ACPI_BASE_ADDRESS + ALT_GPIO_SMI; |
| 49 | uint32_t alt_gpio_reg = 0; |
| 50 | uint32_t route_reg = smm_save_params[SMM_SAVE_PARAM_GPIO_ROUTE]; |
| 51 | int i; |
| 52 | |
| 53 | printk(BIOS_DEBUG, "GPIO_ROUT = %08x\n", route_reg); |
| 54 | |
| 55 | /* Start the routing for the specific gpios. */ |
| 56 | write32(gpio_rout, route_reg); |
| 57 | |
| 58 | /* Enable SMIs for the gpios that are set to trigger the SMI. */ |
| 59 | for (i = 0; i < 16; i++) { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 60 | if ((route_reg & ROUTE_MASK) == ROUTE_SMI) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 61 | alt_gpio_reg |= (1 << i); |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 62 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 63 | route_reg >>= 2; |
| 64 | } |
| 65 | printk(BIOS_DEBUG, "ALT_GPIO_SMI = %08x\n", alt_gpio_reg); |
| 66 | |
| 67 | outl(alt_gpio_reg, alt_gpio_smi); |
| 68 | } |
| 69 | |
Kyösti Mälkki | 0778c86 | 2020-06-10 12:44:03 +0300 | [diff] [blame] | 70 | static void smm_southbridge_enable(uint16_t pm1_events) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 71 | { |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 72 | |
| 73 | printk(BIOS_DEBUG, "Enabling SMIs.\n"); |
| 74 | if (!smm_save_params[SMM_SAVE_PARAM_PCIE_WAKE_ENABLE]) |
| 75 | pm1_events |= PCIEXPWAK_DIS; |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 76 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 77 | enable_pm1(pm1_events); |
| 78 | disable_gpe(PME_B0_EN); |
| 79 | |
| 80 | /* Set up the GPIO route. */ |
Kyösti Mälkki | faf20d3 | 2019-08-14 05:41:41 +0300 | [diff] [blame] | 81 | smm_southcluster_route_gpios(); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 82 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 83 | /* |
| 84 | * Enable SMI generation: |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 85 | * - on APMC writes (io 0xb2) |
| 86 | * - on writes to SLP_EN (sleep states) |
| 87 | * - on writes to GBL_RLS (bios commands) |
| 88 | * No SMIs: |
| 89 | * - on TCO events |
| 90 | * - on microcontroller writes (io 0x62/0x66) |
| 91 | */ |
| 92 | enable_smi(APMC_EN | SLP_SMI_EN | GBL_SMI_EN | EOS); |
| 93 | } |
| 94 | |
Kyösti Mälkki | 0778c86 | 2020-06-10 12:44:03 +0300 | [diff] [blame] | 95 | void global_smi_enable(void) |
| 96 | { |
| 97 | smm_southbridge_enable(PWRBTN_EN | GBL_EN); |
| 98 | } |