Felix Held | 4a8cd72 | 2020-04-18 22:26:39 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 4 | #include <amdblocks/acpi.h> |
Felix Held | 15c4345 | 2021-03-09 00:14:48 +0100 | [diff] [blame] | 5 | #include <amdblocks/acpimmio.h> |
Marshall Dawson | e8ffa9f | 2020-03-16 19:20:20 -0600 | [diff] [blame] | 6 | #include <amdblocks/psp.h> |
Felix Held | a5a5295 | 2020-12-01 18:14:01 +0100 | [diff] [blame] | 7 | #include <amdblocks/smi.h> |
Felix Held | a3a66b6 | 2021-02-10 03:29:48 +0100 | [diff] [blame] | 8 | #include <amdblocks/smm.h> |
Felix Held | 15c4345 | 2021-03-09 00:14:48 +0100 | [diff] [blame] | 9 | #include <arch/hlt.h> |
| 10 | #include <arch/io.h> |
| 11 | #include <console/console.h> |
| 12 | #include <cpu/x86/cache.h> |
| 13 | #include <cpu/x86/smm.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 14 | #include <elog.h> |
Felix Held | 15c4345 | 2021-03-09 00:14:48 +0100 | [diff] [blame] | 15 | #include <soc/smi.h> |
Marshall Dawson | 4dc4cb6 | 2020-04-03 12:07:00 -0600 | [diff] [blame] | 16 | #include <soc/smu.h> |
Felix Held | 15c4345 | 2021-03-09 00:14:48 +0100 | [diff] [blame] | 17 | #include <soc/southbridge.h> |
Felix Held | 2e97897 | 2021-02-10 16:48:23 +0100 | [diff] [blame] | 18 | #include <types.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 19 | |
Felix Held | a2db88e | 2021-02-10 16:46:11 +0100 | [diff] [blame] | 20 | static void fch_apmc_smi_handler(void) |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 21 | { |
| 22 | const uint8_t cmd = inb(pm_acpi_smi_cmd_port()); |
| 23 | |
| 24 | switch (cmd) { |
| 25 | case APM_CNT_ACPI_ENABLE: |
| 26 | acpi_enable_sci(); |
| 27 | break; |
| 28 | case APM_CNT_ACPI_DISABLE: |
| 29 | acpi_disable_sci(); |
| 30 | break; |
| 31 | case APM_CNT_ELOG_GSMI: |
| 32 | if (CONFIG(ELOG_GSMI)) |
Felix Held | 90bcdb4 | 2021-03-08 23:54:18 +0100 | [diff] [blame] | 33 | handle_smi_gsmi(); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 34 | break; |
Marshall Dawson | d125593 | 2020-01-19 10:22:43 -0700 | [diff] [blame] | 35 | case APM_CNT_SMMSTORE: |
| 36 | if (CONFIG(SMMSTORE)) |
Felix Held | 90bcdb4 | 2021-03-08 23:54:18 +0100 | [diff] [blame] | 37 | handle_smi_store(); |
Marshall Dawson | d125593 | 2020-01-19 10:22:43 -0700 | [diff] [blame] | 38 | break; |
Marshall Dawson | e8ffa9f | 2020-03-16 19:20:20 -0600 | [diff] [blame] | 39 | case APM_CNT_SMMINFO: |
| 40 | psp_notify_smm(); |
| 41 | break; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | mainboard_smi_apmc(cmd); |
| 45 | } |
| 46 | |
Felix Held | a2db88e | 2021-02-10 16:46:11 +0100 | [diff] [blame] | 47 | static void fch_slp_typ_handler(void) |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 48 | { |
| 49 | uint32_t pci_ctrl, reg32; |
| 50 | uint16_t pm1cnt, reg16; |
| 51 | uint8_t slp_typ, rst_ctrl; |
| 52 | |
| 53 | /* Figure out SLP_TYP */ |
| 54 | pm1cnt = acpi_read16(MMIO_ACPI_PM1_CNT_BLK); |
| 55 | printk(BIOS_SPEW, "SMI#: SLP = 0x%04x\n", pm1cnt); |
| 56 | slp_typ = acpi_sleep_from_pm1(pm1cnt); |
| 57 | |
| 58 | /* Do any mainboard sleep handling */ |
| 59 | mainboard_smi_sleep(slp_typ); |
| 60 | |
| 61 | switch (slp_typ) { |
| 62 | case ACPI_S0: |
| 63 | printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n"); |
| 64 | break; |
| 65 | case ACPI_S3: |
| 66 | printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n"); |
| 67 | break; |
| 68 | case ACPI_S4: |
| 69 | printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n"); |
| 70 | break; |
| 71 | case ACPI_S5: |
| 72 | printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n"); |
| 73 | break; |
| 74 | default: |
| 75 | printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n"); |
| 76 | break; |
| 77 | } |
| 78 | |
| 79 | if (slp_typ >= ACPI_S3) { |
| 80 | /* Sleep Type Elog S3, S4, and S5 entry */ |
Kyösti Mälkki | 9dd1a12 | 2019-11-06 11:04:27 +0200 | [diff] [blame] | 81 | elog_gsmi_add_event_byte(ELOG_TYPE_ACPI_ENTER, slp_typ); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 82 | |
| 83 | wbinvd(); |
| 84 | |
Felix Held | 4f69ab7 | 2021-02-10 01:26:07 +0100 | [diff] [blame] | 85 | clear_all_smi_status(); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 86 | |
| 87 | /* Do not send SMI before AcpiPm1CntBlkx00[SlpTyp] */ |
| 88 | pci_ctrl = pm_read32(PM_PCI_CTRL); |
| 89 | pci_ctrl &= ~FORCE_SLPSTATE_RETRY; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 90 | pm_write32(PM_PCI_CTRL, pci_ctrl); |
| 91 | |
| 92 | /* Enable SlpTyp */ |
| 93 | rst_ctrl = pm_read8(PM_RST_CTRL1); |
| 94 | rst_ctrl |= SLPTYPE_CONTROL_EN; |
| 95 | pm_write8(PM_RST_CTRL1, rst_ctrl); |
| 96 | |
| 97 | /* |
| 98 | * Before the final command, check if there's pending wake |
| 99 | * event. Read enable first, so that reading the actual status |
| 100 | * is as close as possible to entering S3. The idea is to |
| 101 | * minimize the opportunity for a wake event to happen before |
| 102 | * actually entering S3. If there's a pending wake event, log |
| 103 | * it and continue normal path. S3 will fail and the wake event |
| 104 | * becomes a SCI. |
| 105 | */ |
| 106 | if (CONFIG(ELOG_GSMI)) { |
| 107 | reg16 = acpi_read16(MMIO_ACPI_PM1_EN); |
| 108 | reg16 &= acpi_read16(MMIO_ACPI_PM1_STS); |
| 109 | if (reg16) |
| 110 | elog_add_extended_event( |
| 111 | ELOG_SLEEP_PENDING_PM1_WAKE, |
| 112 | (u32)reg16); |
| 113 | |
| 114 | reg32 = acpi_read32(MMIO_ACPI_GPE0_EN); |
| 115 | reg32 &= acpi_read32(MMIO_ACPI_GPE0_STS); |
| 116 | if (reg32) |
| 117 | elog_add_extended_event( |
| 118 | ELOG_SLEEP_PENDING_GPE0_WAKE, |
| 119 | reg32); |
| 120 | } /* if (CONFIG(ELOG_GSMI)) */ |
| 121 | |
Marshall Dawson | 4d38c75 | 2020-07-01 17:04:03 -0600 | [diff] [blame] | 122 | if (slp_typ == ACPI_S3) |
| 123 | psp_notify_sx_info(ACPI_S3); |
Marshall Dawson | 90b8339 | 2020-03-19 15:08:01 -0600 | [diff] [blame] | 124 | |
Marshall Dawson | 4dc4cb6 | 2020-04-03 12:07:00 -0600 | [diff] [blame] | 125 | smu_sx_entry(); /* Leave SlpTypeEn clear, SMU will set */ |
| 126 | printk(BIOS_ERR, "Error: System did not go to sleep\n"); |
| 127 | |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 128 | hlt(); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | int southbridge_io_trap_handler(int smif) |
| 133 | { |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | * Table of functions supported in the SMI handler. Note that SMI source setup |
Felix Held | 37fbbfd | 2021-02-10 00:48:33 +0100 | [diff] [blame] | 139 | * in fch.c is unrelated to this list. |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 140 | */ |
| 141 | static const struct smi_sources_t smi_sources[] = { |
Felix Held | a2db88e | 2021-02-10 16:46:11 +0100 | [diff] [blame] | 142 | { .type = SMITYPE_SMI_CMD_PORT, .handler = fch_apmc_smi_handler }, |
| 143 | { .type = SMITYPE_SLP_TYP, .handler = fch_slp_typ_handler}, |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 144 | }; |
| 145 | |
Felix Held | a3a66b6 | 2021-02-10 03:29:48 +0100 | [diff] [blame] | 146 | void *get_smi_source_handler(int source) |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 147 | { |
Felix Held | 2e97897 | 2021-02-10 16:48:23 +0100 | [diff] [blame] | 148 | size_t i; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 149 | |
| 150 | for (i = 0 ; i < ARRAY_SIZE(smi_sources) ; i++) |
| 151 | if (smi_sources[i].type == source) |
| 152 | return smi_sources[i].handler; |
| 153 | |
| 154 | return NULL; |
| 155 | } |