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> |
| 6 | #include <amdblocks/smi.h> |
Felix Held | a3a66b6 | 2021-02-10 03:29:48 +0100 | [diff] [blame] | 7 | #include <amdblocks/smm.h> |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame^] | 8 | #include <arch/hlt.h> |
| 9 | #include <arch/io.h> |
| 10 | #include <console/console.h> |
Felix Held | 3c4fd70 | 2021-02-10 03:47:38 +0100 | [diff] [blame] | 11 | #include <cpu/x86/smm.h> |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame^] | 12 | #include <soc/smi.h> |
| 13 | #include <types.h> |
| 14 | |
| 15 | static void fch_apmc_smi_handler(void) |
| 16 | { |
| 17 | const uint8_t cmd = inb(pm_acpi_smi_cmd_port()); |
| 18 | |
| 19 | switch (cmd) { |
| 20 | case APM_CNT_ACPI_ENABLE: |
| 21 | acpi_enable_sci(); |
| 22 | break; |
| 23 | case APM_CNT_ACPI_DISABLE: |
| 24 | acpi_disable_sci(); |
| 25 | } |
| 26 | |
| 27 | mainboard_smi_apmc(cmd); |
| 28 | } |
| 29 | |
| 30 | static void fch_slp_typ_handler(void) |
| 31 | { |
| 32 | uint16_t pm1cnt; |
| 33 | uint8_t slp_typ; |
| 34 | |
| 35 | /* Figure out SLP_TYP */ |
| 36 | pm1cnt = acpi_read16(MMIO_ACPI_PM1_CNT_BLK); |
| 37 | printk(BIOS_SPEW, "SMI#: SLP = 0x%04x\n", pm1cnt); |
| 38 | slp_typ = acpi_sleep_from_pm1(pm1cnt); |
| 39 | |
| 40 | /* Do any mainboard sleep handling */ |
| 41 | mainboard_smi_sleep(slp_typ); |
| 42 | |
| 43 | switch (slp_typ) { |
| 44 | case ACPI_S0: |
| 45 | printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n"); |
| 46 | break; |
| 47 | case ACPI_S3: |
| 48 | printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n"); |
| 49 | break; |
| 50 | case ACPI_S4: |
| 51 | printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n"); |
| 52 | break; |
| 53 | case ACPI_S5: |
| 54 | printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n"); |
| 55 | break; |
| 56 | default: |
| 57 | printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n"); |
| 58 | break; |
| 59 | } |
| 60 | |
| 61 | if (slp_typ >= ACPI_S3) { |
| 62 | printk(BIOS_ERR, "Error: System did not go to sleep\n"); |
| 63 | hlt(); |
| 64 | } |
| 65 | } |
Felix Held | 3c4fd70 | 2021-02-10 03:47:38 +0100 | [diff] [blame] | 66 | |
| 67 | int southbridge_io_trap_handler(int smif) |
| 68 | { |
| 69 | return 0; |
| 70 | } |
Felix Held | ee2a365 | 2021-02-09 23:43:17 +0100 | [diff] [blame] | 71 | |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame^] | 72 | /* |
| 73 | * Table of functions supported in the SMI handler. Note that SMI source setup |
| 74 | * in fch.c is unrelated to this list. |
| 75 | */ |
| 76 | static const struct smi_sources_t smi_sources[] = { |
| 77 | { .type = SMITYPE_SMI_CMD_PORT, .handler = fch_apmc_smi_handler }, |
| 78 | { .type = SMITYPE_SLP_TYP, .handler = fch_slp_typ_handler}, |
| 79 | }; |
| 80 | |
Felix Held | a3a66b6 | 2021-02-10 03:29:48 +0100 | [diff] [blame] | 81 | void *get_smi_source_handler(int source) |
Felix Held | ee2a365 | 2021-02-09 23:43:17 +0100 | [diff] [blame] | 82 | { |
Felix Held | be35a3a | 2021-02-10 16:34:31 +0100 | [diff] [blame^] | 83 | size_t i; |
| 84 | |
| 85 | for (i = 0 ; i < ARRAY_SIZE(smi_sources) ; i++) |
| 86 | if (smi_sources[i].type == source) |
| 87 | return smi_sources[i].handler; |
| 88 | |
Felix Held | a3a66b6 | 2021-02-10 03:29:48 +0100 | [diff] [blame] | 89 | return NULL; |
Felix Held | ee2a365 | 2021-02-09 23:43:17 +0100 | [diff] [blame] | 90 | } |