From 21594fd161957920a0bce94e24a52e9cab7f5397 Mon Sep 17 00:00:00 2001 From: Felix Held Date: Tue, 9 May 2023 16:39:57 +0200 Subject: [PATCH] acpi/acpigen: add acpigen_resource_mmio to generate MMIO resource MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add the acpigen_resource_mmio helper function to generate an MMIO range resource. Signed-off-by: Felix Held Signed-off-by: Arthur Heymans Change-Id: I38d55dfcc2892bcb5d253a3aef6ed993cfdba0a5 Reviewed-on: https://review.coreboot.org/c/coreboot/+/75045 Tested-by: build bot (Jenkins) Reviewed-by: Kyösti Mälkki --- src/acpi/acpigen.c | 36 ++++++++++++++++++++++++++++++++++++ src/include/acpi/acpigen.h | 1 + 2 files changed, 37 insertions(+) diff --git a/src/acpi/acpigen.c b/src/acpi/acpigen.c index fb84cd18a3..7118d1ceec 100644 --- a/src/acpi/acpigen.c +++ b/src/acpi/acpigen.c @@ -2254,6 +2254,42 @@ void acpigen_resource_io(u16 io_base, u16 io_limit) io_limit - io_base + 1); /* length */ } +static void acpigen_resource_mmio32(u32 mmio_base, u32 mmio_limit, u16 type_flags) +{ + acpigen_resource_dword(RSRC_TYPE_MEM, /* res_type */ + ADDR_SPACE_GENERAL_FLAG_MAX_FIXED + | ADDR_SPACE_GENERAL_FLAG_MIN_FIXED + | ADDR_SPACE_GENERAL_FLAG_DEC_POS, /* gen_flags */ + type_flags, /* type_flags */ + 0, /* gran */ + mmio_base, /* range_min */ + mmio_limit, /* range_max */ + 0x0, /* translation */ + mmio_limit - mmio_base + 1); /* length */ +} + +static void acpigen_resource_mmio64(u64 mmio_base, u64 mmio_limit, u16 type_flags) +{ + acpigen_resource_qword(RSRC_TYPE_MEM, /* res_type */ + ADDR_SPACE_GENERAL_FLAG_MAX_FIXED + | ADDR_SPACE_GENERAL_FLAG_MIN_FIXED + | ADDR_SPACE_GENERAL_FLAG_DEC_POS, /* gen_flags */ + type_flags, /* type_flags */ + 0, /* gran */ + mmio_base, /* range_min */ + mmio_limit, /* range_max */ + 0x0, /* translation */ + mmio_limit - mmio_base + 1); /* length */ +} + +void acpigen_resource_mmio(u64 mmio_base, u64 mmio_limit, u16 type_flags) +{ + if (mmio_base < 4ULL * GiB && mmio_limit < 4ULL * GiB) + acpigen_resource_mmio32(mmio_base, mmio_limit, type_flags); + else + acpigen_resource_mmio64(mmio_base, mmio_limit, type_flags); +} + void acpigen_write_ADR(uint64_t adr) { acpigen_write_name_qword("_ADR", adr); diff --git a/src/include/acpi/acpigen.h b/src/include/acpi/acpigen.h index 614cd6e713..2147990944 100644 --- a/src/include/acpi/acpigen.h +++ b/src/include/acpi/acpigen.h @@ -690,6 +690,7 @@ void acpigen_resource_qword(u16 res_type, u16 gen_flags, u16 type_flags, void acpigen_resource_bus_number(u16 bus_base, u16 bus_limit); void acpigen_resource_io(u16 io_base, u16 io_limit); +void acpigen_resource_mmio(u64 mmio_base, u64 mmio_limit, u16 type_flags); /* Emits Notify(namestr, value) */ void acpigen_notify(const char *namestr, int value);