Angel Pons | c3c7ef3 | 2020-07-12 19:08:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpi.h> |
| 4 | #include <cpu/x86/smm.h> |
Angel Pons | e4844ce | 2021-04-17 12:49:08 +0200 | [diff] [blame] | 5 | #include <soc/acpi.h> |
Angel Pons | c3c7ef3 | 2020-07-12 19:08:57 +0200 | [diff] [blame] | 6 | #include <soc/iomap.h> |
| 7 | #include <soc/pm.h> |
| 8 | #include "chip.h" |
| 9 | |
| 10 | void acpi_fill_fadt(acpi_fadt_t *fadt) |
| 11 | { |
| 12 | const uint16_t pmbase = ACPI_BASE_ADDRESS; |
| 13 | config_t *config = config_of_soc(); |
| 14 | |
| 15 | fadt->header.revision = get_acpi_table_revision(FADT); |
| 16 | |
| 17 | fadt->sci_int = acpi_sci_irq(); |
| 18 | |
| 19 | if (permanent_smi_handler()) { |
| 20 | fadt->smi_cmd = APM_CNT; |
| 21 | fadt->acpi_enable = APM_CNT_ACPI_ENABLE; |
| 22 | fadt->acpi_disable = APM_CNT_ACPI_DISABLE; |
| 23 | } |
| 24 | |
| 25 | fadt->pm1a_evt_blk = pmbase + PM1_STS; |
Angel Pons | c3c7ef3 | 2020-07-12 19:08:57 +0200 | [diff] [blame] | 26 | fadt->pm1a_cnt_blk = pmbase + PM1_CNT; |
Angel Pons | c3c7ef3 | 2020-07-12 19:08:57 +0200 | [diff] [blame] | 27 | fadt->pm2_cnt_blk = pmbase + PM2_CNT; |
| 28 | fadt->pm_tmr_blk = pmbase + PM1_TMR; |
| 29 | fadt->gpe0_blk = pmbase + GPE0_STS(0); |
Angel Pons | c3c7ef3 | 2020-07-12 19:08:57 +0200 | [diff] [blame] | 30 | |
| 31 | fadt->pm1_evt_len = 4; |
| 32 | fadt->pm1_cnt_len = 2; |
| 33 | fadt->pm2_cnt_len = 1; |
| 34 | fadt->pm_tmr_len = 4; |
| 35 | /* There are 4 GPE0 STS/EN pairs each 32 bits wide. */ |
| 36 | fadt->gpe0_blk_len = 2 * GPE0_REG_MAX * sizeof(uint32_t); |
Angel Pons | c3c7ef3 | 2020-07-12 19:08:57 +0200 | [diff] [blame] | 37 | fadt->p_lvl2_lat = 1; |
| 38 | fadt->p_lvl3_lat = 87; |
Angel Pons | c3c7ef3 | 2020-07-12 19:08:57 +0200 | [diff] [blame] | 39 | fadt->duty_offset = 1; |
| 40 | fadt->duty_width = 0; |
| 41 | fadt->day_alrm = 0xd; |
| 42 | fadt->mon_alrm = 0x00; |
| 43 | fadt->century = 0x00; |
| 44 | fadt->iapc_boot_arch = ACPI_FADT_LEGACY_FREE; |
| 45 | if (!CONFIG(NO_FADT_8042)) |
| 46 | fadt->iapc_boot_arch |= ACPI_FADT_8042; |
| 47 | |
Angel Pons | a208c6c | 2020-07-13 00:02:34 +0200 | [diff] [blame] | 48 | fadt->flags |= ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED | |
Angel Pons | c3c7ef3 | 2020-07-12 19:08:57 +0200 | [diff] [blame] | 49 | ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON | |
Angel Pons | 79572e4 | 2020-07-13 00:17:43 +0200 | [diff] [blame] | 50 | ACPI_FADT_SEALED_CASE | ACPI_FADT_S4_RTC_WAKE | |
| 51 | ACPI_FADT_PLATFORM_CLOCK; |
Angel Pons | c3c7ef3 | 2020-07-12 19:08:57 +0200 | [diff] [blame] | 52 | |
| 53 | if (config->s0ix_enable) |
| 54 | fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0; |
| 55 | |
Elyes HAOUAS | 04071f4 | 2020-07-20 17:05:24 +0200 | [diff] [blame] | 56 | fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
Angel Pons | c3c7ef3 | 2020-07-12 19:08:57 +0200 | [diff] [blame] | 57 | fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8; |
| 58 | fadt->x_pm1a_evt_blk.bit_offset = 0; |
Angel Pons | 12a4d05 | 2020-07-14 01:31:27 +0200 | [diff] [blame] | 59 | fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS; |
Angel Pons | c3c7ef3 | 2020-07-12 19:08:57 +0200 | [diff] [blame] | 60 | fadt->x_pm1a_evt_blk.addrl = pmbase + PM1_STS; |
| 61 | fadt->x_pm1a_evt_blk.addrh = 0x0; |
| 62 | |
Elyes HAOUAS | 04071f4 | 2020-07-20 17:05:24 +0200 | [diff] [blame] | 63 | fadt->x_pm1a_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
Angel Pons | c3c7ef3 | 2020-07-12 19:08:57 +0200 | [diff] [blame] | 64 | fadt->x_pm1a_cnt_blk.bit_width = fadt->pm1_cnt_len * 8; |
| 65 | fadt->x_pm1a_cnt_blk.bit_offset = 0; |
| 66 | fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS; |
| 67 | fadt->x_pm1a_cnt_blk.addrl = pmbase + PM1_CNT; |
| 68 | fadt->x_pm1a_cnt_blk.addrh = 0x0; |
| 69 | |
Elyes HAOUAS | 04071f4 | 2020-07-20 17:05:24 +0200 | [diff] [blame] | 70 | fadt->x_pm2_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
Angel Pons | c3c7ef3 | 2020-07-12 19:08:57 +0200 | [diff] [blame] | 71 | fadt->x_pm2_cnt_blk.bit_width = fadt->pm2_cnt_len * 8; |
| 72 | fadt->x_pm2_cnt_blk.bit_offset = 0; |
| 73 | fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
| 74 | fadt->x_pm2_cnt_blk.addrl = pmbase + PM2_CNT; |
| 75 | fadt->x_pm2_cnt_blk.addrh = 0x0; |
| 76 | |
Elyes HAOUAS | 04071f4 | 2020-07-20 17:05:24 +0200 | [diff] [blame] | 77 | fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
Angel Pons | c3c7ef3 | 2020-07-12 19:08:57 +0200 | [diff] [blame] | 78 | fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8; |
| 79 | fadt->x_pm_tmr_blk.bit_offset = 0; |
| 80 | fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
| 81 | fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR; |
| 82 | fadt->x_pm_tmr_blk.addrh = 0x0; |
| 83 | |
| 84 | /* |
| 85 | * Windows 10 requires x_gpe0_blk to be set starting with FADT revision 5. |
| 86 | * The bit_width field intentionally overflows here. |
| 87 | * The OSPM can instead use the values in `fadt->gpe0_blk{,_len}`, which |
| 88 | * seems to work fine on Linux 5.0 and Windows 10. |
| 89 | */ |
| 90 | fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 91 | fadt->x_gpe0_blk.bit_width = fadt->gpe0_blk_len * 8; |
| 92 | fadt->x_gpe0_blk.bit_offset = 0; |
| 93 | fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
| 94 | fadt->x_gpe0_blk.addrl = fadt->gpe0_blk; |
| 95 | fadt->x_gpe0_blk.addrh = 0; |
Angel Pons | c3c7ef3 | 2020-07-12 19:08:57 +0200 | [diff] [blame] | 96 | } |