Felix Held | ee2a365 | 2021-02-09 23:43:17 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
| 4 | #include <amdblocks/acpi.h> |
| 5 | #include <amdblocks/acpimmio.h> |
Felix Held | d51fd30 | 2021-02-11 05:02:27 +0100 | [diff] [blame] | 6 | #include <amdblocks/psp.h> |
Felix Held | be35a3a | 2021-02-10 16:34:31 +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 | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame] | 9 | #include <arch/hlt.h> |
| 10 | #include <arch/io.h> |
| 11 | #include <console/console.h> |
Felix Held | 913dcf6 | 2021-03-03 19:03:37 +0100 | [diff] [blame] | 12 | #include <cpu/x86/cache.h> |
Felix Held | 3c4fd70 | 2021-02-10 03:47:38 +0100 | [diff] [blame] | 13 | #include <cpu/x86/smm.h> |
Felix Held | 3680e02 | 2021-03-09 00:08:52 +0100 | [diff] [blame] | 14 | #include <elog.h> |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame] | 15 | #include <soc/smi.h> |
Felix Held | 913dcf6 | 2021-03-03 19:03:37 +0100 | [diff] [blame] | 16 | #include <soc/smu.h> |
| 17 | #include <soc/southbridge.h> |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame] | 18 | #include <types.h> |
| 19 | |
| 20 | static void fch_apmc_smi_handler(void) |
| 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(); |
Felix Held | d51fd30 | 2021-02-11 05:02:27 +0100 | [diff] [blame] | 30 | break; |
Felix Held | 3680e02 | 2021-03-09 00:08:52 +0100 | [diff] [blame] | 31 | case APM_CNT_ELOG_GSMI: |
| 32 | if (CONFIG(ELOG_GSMI)) |
| 33 | handle_smi_gsmi(); |
| 34 | break; |
| 35 | case APM_CNT_SMMSTORE: |
| 36 | if (CONFIG(SMMSTORE)) |
| 37 | handle_smi_store(); |
| 38 | break; |
Felix Held | d51fd30 | 2021-02-11 05:02:27 +0100 | [diff] [blame] | 39 | case APM_CNT_SMMINFO: |
| 40 | psp_notify_smm(); |
| 41 | break; |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | mainboard_smi_apmc(cmd); |
| 45 | } |
| 46 | |
| 47 | static void fch_slp_typ_handler(void) |
| 48 | { |
Felix Held | 3680e02 | 2021-03-09 00:08:52 +0100 | [diff] [blame] | 49 | uint32_t pci_ctrl, reg32; |
| 50 | uint16_t pm1cnt, reg16; |
Felix Held | 913dcf6 | 2021-03-03 19:03:37 +0100 | [diff] [blame] | 51 | uint8_t slp_typ, rst_ctrl; |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame] | 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) { |
Felix Held | 913dcf6 | 2021-03-03 19:03:37 +0100 | [diff] [blame] | 80 | wbinvd(); |
| 81 | |
| 82 | clear_all_smi_status(); |
| 83 | |
| 84 | /* Do not send SMI before AcpiPm1CntBlkx00[SlpTyp] */ |
| 85 | pci_ctrl = pm_read32(PM_PCI_CTRL); |
| 86 | pci_ctrl &= ~FORCE_SLPSTATE_RETRY; |
| 87 | pm_write32(PM_PCI_CTRL, pci_ctrl); |
| 88 | |
| 89 | /* Enable SlpTyp */ |
| 90 | rst_ctrl = pm_read8(PM_RST_CTRL1); |
| 91 | rst_ctrl |= SLPTYPE_CONTROL_EN; |
| 92 | pm_write8(PM_RST_CTRL1, rst_ctrl); |
| 93 | |
Felix Held | 3680e02 | 2021-03-09 00:08:52 +0100 | [diff] [blame] | 94 | /* |
| 95 | * Before the final command, check if there's pending wake |
| 96 | * event. Read enable first, so that reading the actual status |
| 97 | * is as close as possible to entering S3. The idea is to |
| 98 | * minimize the opportunity for a wake event to happen before |
| 99 | * actually entering S3. If there's a pending wake event, log |
| 100 | * it and continue normal path. S3 will fail and the wake event |
| 101 | * becomes a SCI. |
| 102 | */ |
| 103 | if (CONFIG(ELOG_GSMI)) { |
| 104 | reg16 = acpi_read16(MMIO_ACPI_PM1_EN); |
| 105 | reg16 &= acpi_read16(MMIO_ACPI_PM1_STS); |
| 106 | if (reg16) |
| 107 | elog_add_extended_event( |
| 108 | ELOG_SLEEP_PENDING_PM1_WAKE, |
| 109 | (u32)reg16); |
| 110 | |
| 111 | reg32 = acpi_read32(MMIO_ACPI_GPE0_EN); |
| 112 | reg32 &= acpi_read32(MMIO_ACPI_GPE0_STS); |
| 113 | if (reg32) |
| 114 | elog_add_extended_event( |
| 115 | ELOG_SLEEP_PENDING_GPE0_WAKE, |
| 116 | reg32); |
| 117 | } /* if (CONFIG(ELOG_GSMI)) */ |
| 118 | |
Felix Held | 913dcf6 | 2021-03-03 19:03:37 +0100 | [diff] [blame] | 119 | if (slp_typ == ACPI_S3) |
| 120 | psp_notify_sx_info(ACPI_S3); |
| 121 | |
| 122 | smu_sx_entry(); /* Leave SlpTypeEn clear, SMU will set */ |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame] | 123 | printk(BIOS_ERR, "Error: System did not go to sleep\n"); |
| 124 | hlt(); |
| 125 | } |
| 126 | } |
Felix Held | 3c4fd70 | 2021-02-10 03:47:38 +0100 | [diff] [blame] | 127 | |
| 128 | int southbridge_io_trap_handler(int smif) |
| 129 | { |
| 130 | return 0; |
| 131 | } |
Felix Held | ee2a365 | 2021-02-09 23:43:17 +0100 | [diff] [blame] | 132 | |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame] | 133 | /* |
| 134 | * Table of functions supported in the SMI handler. Note that SMI source setup |
| 135 | * in fch.c is unrelated to this list. |
| 136 | */ |
| 137 | static const struct smi_sources_t smi_sources[] = { |
| 138 | { .type = SMITYPE_SMI_CMD_PORT, .handler = fch_apmc_smi_handler }, |
| 139 | { .type = SMITYPE_SLP_TYP, .handler = fch_slp_typ_handler}, |
| 140 | }; |
| 141 | |
Felix Held | a3a66b6 | 2021-02-10 03:29:48 +0100 | [diff] [blame] | 142 | void *get_smi_source_handler(int source) |
Felix Held | ee2a365 | 2021-02-09 23:43:17 +0100 | [diff] [blame] | 143 | { |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame] | 144 | size_t i; |
| 145 | |
| 146 | for (i = 0 ; i < ARRAY_SIZE(smi_sources) ; i++) |
| 147 | if (smi_sources[i].type == source) |
| 148 | return smi_sources[i].handler; |
| 149 | |
Felix Held | a3a66b6 | 2021-02-10 03:29:48 +0100 | [diff] [blame] | 150 | return NULL; |
Felix Held | ee2a365 | 2021-02-09 23:43:17 +0100 | [diff] [blame] | 151 | } |