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> |
Raul E Rangel | 54786fe | 2022-02-25 17:12:10 -0700 | [diff] [blame] | 12 | #include <console/cbmem_console.h> |
Felix Held | 913dcf6 | 2021-03-03 19:03:37 +0100 | [diff] [blame] | 13 | #include <cpu/x86/cache.h> |
Felix Held | 3c4fd70 | 2021-02-10 03:47:38 +0100 | [diff] [blame] | 14 | #include <cpu/x86/smm.h> |
Felix Held | 3680e02 | 2021-03-09 00:08:52 +0100 | [diff] [blame] | 15 | #include <elog.h> |
Martin Roth | 8fc6881 | 2023-08-18 16:28:29 -0600 | [diff] [blame^] | 16 | #include <psp_verstage/psp_transfer.h> |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame] | 17 | #include <soc/smi.h> |
Felix Held | 913dcf6 | 2021-03-03 19:03:37 +0100 | [diff] [blame] | 18 | #include <soc/smu.h> |
| 19 | #include <soc/southbridge.h> |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame] | 20 | #include <types.h> |
| 21 | |
Felix Held | f43e0e7 | 2022-06-24 21:54:46 +0200 | [diff] [blame] | 22 | /* |
| 23 | * Both the psp_notify_sx_info and the smu_sx_entry call will clobber the SMN index register |
| 24 | * during the SMN accesses. Since the SMI handler is the last thing that gets called before |
| 25 | * entering S3, this won't interfere with any indirect SMN accesses via the same register pair. |
| 26 | */ |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame] | 27 | static void fch_slp_typ_handler(void) |
| 28 | { |
Felix Held | 3680e02 | 2021-03-09 00:08:52 +0100 | [diff] [blame] | 29 | uint32_t pci_ctrl, reg32; |
| 30 | uint16_t pm1cnt, reg16; |
Felix Held | 913dcf6 | 2021-03-03 19:03:37 +0100 | [diff] [blame] | 31 | uint8_t slp_typ, rst_ctrl; |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame] | 32 | |
| 33 | /* Figure out SLP_TYP */ |
| 34 | pm1cnt = acpi_read16(MMIO_ACPI_PM1_CNT_BLK); |
| 35 | printk(BIOS_SPEW, "SMI#: SLP = 0x%04x\n", pm1cnt); |
| 36 | slp_typ = acpi_sleep_from_pm1(pm1cnt); |
| 37 | |
| 38 | /* Do any mainboard sleep handling */ |
| 39 | mainboard_smi_sleep(slp_typ); |
| 40 | |
| 41 | switch (slp_typ) { |
| 42 | case ACPI_S0: |
| 43 | printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n"); |
| 44 | break; |
| 45 | case ACPI_S3: |
| 46 | printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n"); |
| 47 | break; |
| 48 | case ACPI_S4: |
| 49 | printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n"); |
| 50 | break; |
| 51 | case ACPI_S5: |
| 52 | printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n"); |
| 53 | break; |
| 54 | default: |
| 55 | printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n"); |
| 56 | break; |
| 57 | } |
| 58 | |
| 59 | if (slp_typ >= ACPI_S3) { |
Felix Held | 913dcf6 | 2021-03-03 19:03:37 +0100 | [diff] [blame] | 60 | wbinvd(); |
| 61 | |
| 62 | clear_all_smi_status(); |
| 63 | |
| 64 | /* Do not send SMI before AcpiPm1CntBlkx00[SlpTyp] */ |
| 65 | pci_ctrl = pm_read32(PM_PCI_CTRL); |
| 66 | pci_ctrl &= ~FORCE_SLPSTATE_RETRY; |
| 67 | pm_write32(PM_PCI_CTRL, pci_ctrl); |
| 68 | |
| 69 | /* Enable SlpTyp */ |
| 70 | rst_ctrl = pm_read8(PM_RST_CTRL1); |
| 71 | rst_ctrl |= SLPTYPE_CONTROL_EN; |
| 72 | pm_write8(PM_RST_CTRL1, rst_ctrl); |
| 73 | |
Felix Held | 3680e02 | 2021-03-09 00:08:52 +0100 | [diff] [blame] | 74 | /* |
| 75 | * Before the final command, check if there's pending wake |
| 76 | * event. Read enable first, so that reading the actual status |
| 77 | * is as close as possible to entering S3. The idea is to |
| 78 | * minimize the opportunity for a wake event to happen before |
| 79 | * actually entering S3. If there's a pending wake event, log |
| 80 | * it and continue normal path. S3 will fail and the wake event |
| 81 | * becomes a SCI. |
| 82 | */ |
| 83 | if (CONFIG(ELOG_GSMI)) { |
| 84 | reg16 = acpi_read16(MMIO_ACPI_PM1_EN); |
| 85 | reg16 &= acpi_read16(MMIO_ACPI_PM1_STS); |
| 86 | if (reg16) |
| 87 | elog_add_extended_event( |
| 88 | ELOG_SLEEP_PENDING_PM1_WAKE, |
| 89 | (u32)reg16); |
| 90 | |
| 91 | reg32 = acpi_read32(MMIO_ACPI_GPE0_EN); |
| 92 | reg32 &= acpi_read32(MMIO_ACPI_GPE0_STS); |
| 93 | if (reg32) |
| 94 | elog_add_extended_event( |
| 95 | ELOG_SLEEP_PENDING_GPE0_WAKE, |
| 96 | reg32); |
| 97 | } /* if (CONFIG(ELOG_GSMI)) */ |
| 98 | |
Felix Held | 913dcf6 | 2021-03-03 19:03:37 +0100 | [diff] [blame] | 99 | if (slp_typ == ACPI_S3) |
| 100 | psp_notify_sx_info(ACPI_S3); |
| 101 | |
| 102 | smu_sx_entry(); /* Leave SlpTypeEn clear, SMU will set */ |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 103 | printk(BIOS_ERR, "System did not go to sleep\n"); |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame] | 104 | hlt(); |
| 105 | } |
| 106 | } |
Felix Held | 3c4fd70 | 2021-02-10 03:47:38 +0100 | [diff] [blame] | 107 | |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame] | 108 | /* |
| 109 | * Table of functions supported in the SMI handler. Note that SMI source setup |
| 110 | * in fch.c is unrelated to this list. |
| 111 | */ |
| 112 | static const struct smi_sources_t smi_sources[] = { |
| 113 | { .type = SMITYPE_SMI_CMD_PORT, .handler = fch_apmc_smi_handler }, |
| 114 | { .type = SMITYPE_SLP_TYP, .handler = fch_slp_typ_handler}, |
| 115 | }; |
| 116 | |
Felix Held | a3a66b6 | 2021-02-10 03:29:48 +0100 | [diff] [blame] | 117 | void *get_smi_source_handler(int source) |
Felix Held | ee2a365 | 2021-02-09 23:43:17 +0100 | [diff] [blame] | 118 | { |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame] | 119 | size_t i; |
| 120 | |
| 121 | for (i = 0 ; i < ARRAY_SIZE(smi_sources) ; i++) |
| 122 | if (smi_sources[i].type == source) |
| 123 | return smi_sources[i].handler; |
| 124 | |
Felix Held | a3a66b6 | 2021-02-10 03:29:48 +0100 | [diff] [blame] | 125 | return NULL; |
Felix Held | ee2a365 | 2021-02-09 23:43:17 +0100 | [diff] [blame] | 126 | } |
Raul E Rangel | 54786fe | 2022-02-25 17:12:10 -0700 | [diff] [blame] | 127 | |
| 128 | void smm_soc_early_init(void) |
| 129 | { |
| 130 | if (CONFIG(VBOOT_STARTS_BEFORE_BOOTBLOCK) && __CBMEM_CONSOLE_ENABLE__) |
| 131 | replay_transfer_buffer_cbmemc(); |
| 132 | } |