From 88decca14f84184e95482d6b16c0791a70eae9ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ky=C3=B6sti=20M=C3=A4lkki?= Date: Fri, 28 Apr 2023 07:04:34 +0300 Subject: ACPI: Add helper fill_fadt_extended_pm_io() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Once platform code has filled in the (legacy) ACPI PM register map, added function will fill in the extended entries in FADT. TEST=samsung/lumpy and amd/mandolin FADT stays unchanged. Change-Id: I90925fce35458cf5480bfefc7cdddebd41b42058 Signed-off-by: Kyösti Mälkki Reviewed-on: https://review.coreboot.org/c/coreboot/+/74913 Tested-by: build bot (Jenkins) Reviewed-by: Martin L Roth --- src/acpi/fadt_filler.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/acpi/fadt_filler.c (limited to 'src/acpi/fadt_filler.c') diff --git a/src/acpi/fadt_filler.c b/src/acpi/fadt_filler.c new file mode 100644 index 0000000000..af65dbbadf --- /dev/null +++ b/src/acpi/fadt_filler.c @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include + +static void fill_x_pm_io(acpi_addr_t *x_pm_blk, int access_size, uint16_t ioport, uint8_t len) +{ + x_pm_blk->space_id = ACPI_ADDRESS_SPACE_IO; + x_pm_blk->bit_width = len * 8; + x_pm_blk->bit_offset = 0; + x_pm_blk->access_size = access_size; + x_pm_blk->addrl = ioport; + x_pm_blk->addrh = 0x0; +} + +static void do_sanity_error(const char *func, const int line) +{ + printk(BIOS_ERR, "ACPI: FADT error detected, %s line %d.\n", func, line); +} + +#define fadt_sanity(x) do { if (!(x)) do_sanity_error(__func__, __LINE__); } while (0) + +void fill_fadt_extended_pm_io(acpi_fadt_t *fadt) +{ + fadt_sanity(fadt->pm1a_evt_blk && (fadt->pm1_evt_len >= 4)); + + /* Upper word is reserved and Linux complains about 32 bit. */ + fadt_sanity(fadt->pm1a_cnt_blk && (fadt->pm1_cnt_len == 2)); + + fill_x_pm_io(&fadt->x_pm1a_evt_blk, ACPI_ACCESS_SIZE_WORD_ACCESS, + fadt->pm1a_evt_blk, fadt->pm1_evt_len); + + fill_x_pm_io(&fadt->x_pm1a_cnt_blk, ACPI_ACCESS_SIZE_WORD_ACCESS, + fadt->pm1a_cnt_blk, fadt->pm1_cnt_len); + + if (fadt->pm1b_evt_blk) + fill_x_pm_io(&fadt->x_pm1b_evt_blk, ACPI_ACCESS_SIZE_WORD_ACCESS, + fadt->pm1b_evt_blk, fadt->pm1_evt_len); + + if (fadt->pm1b_cnt_blk) + fill_x_pm_io(&fadt->x_pm1b_cnt_blk, ACPI_ACCESS_SIZE_WORD_ACCESS, + fadt->pm1b_cnt_blk, fadt->pm1_cnt_len); + + if (fadt->pm_tmr_blk) { + fadt_sanity(fadt->pm_tmr_len == 4); + fill_x_pm_io(&fadt->x_pm_tmr_blk, ACPI_ACCESS_SIZE_DWORD_ACCESS, + fadt->pm_tmr_blk, fadt->pm_tmr_len); + } + + if (fadt->pm2_cnt_blk) + fill_x_pm_io(&fadt->x_pm2_cnt_blk, ACPI_ACCESS_SIZE_BYTE_ACCESS, + fadt->pm2_cnt_blk, fadt->pm2_cnt_len); + + /* + * Windows 10 requires x_gpe0_blk to be set starting with FADT revision 5. + * The bit_width field intentionally overflows here. + * The OSPM can instead use the values in `fadt->gpe0_blk{,_len}`, which + * seems to work fine on Linux 5.0 and Windows 10. + * + * FIXME: GPE1_BASE is not initialised. + * + */ + + if (fadt->gpe0_blk) + fill_x_pm_io(&fadt->x_gpe0_blk, ACPI_ACCESS_SIZE_BYTE_ACCESS, + fadt->gpe0_blk, fadt->gpe0_blk_len); + + if (fadt->gpe1_blk) + fill_x_pm_io(&fadt->x_gpe1_blk, ACPI_ACCESS_SIZE_BYTE_ACCESS, + fadt->gpe1_blk, fadt->gpe1_blk_len); +} -- cgit v1.2.3