From: Michael Brown Date: Wed, 5 Nov 2025 14:07:27 +0000 (+0000) Subject: [acpi] Add acpi_ioremap() to map an ACPI-described address X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8fd5e277275141866feea80870f8b94b23a0e82d;p=thirdparty%2Fipxe.git [acpi] Add acpi_ioremap() to map an ACPI-described address An ACPI Generic Address Structure (GAS) may be used to describe the location of a peripheral such as an early boot console. Add the relevant definitions and provide acpi_ioremap() as a helper function to map a region described using this structure. Signed-off-by: Michael Brown --- diff --git a/src/core/acpi.c b/src/core/acpi.c index 6c5d1e079..fa8ed34ff 100644 --- a/src/core/acpi.c +++ b/src/core/acpi.c @@ -27,6 +27,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include +#include #include #include @@ -258,6 +259,24 @@ int acpi_extract ( uint32_t signature, void *data, return -ENOENT; } +/** + * Map an ACPI generic address + * + * @v address Generic address + * @v len Length of region + * @ret io_addr I/O address, or NULL on error + */ +void * acpi_ioremap ( struct acpi_address *address, size_t len ) { + physaddr_t base = le64_to_cpu ( address->address ); + + switch ( address->type ) { + case ACPI_ADDRESS_TYPE_MEM: + return ioremap ( base, len ); + default: + return NULL; + } +} + /****************************************************************************** * * Descriptors diff --git a/src/include/ipxe/acpi.h b/src/include/ipxe/acpi.h index 40a44cffc..5e9fb5eba 100644 --- a/src/include/ipxe/acpi.h +++ b/src/include/ipxe/acpi.h @@ -18,6 +18,29 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include +/** An ACPI generic address structure */ +struct acpi_address { + /** Address space type */ + uint8_t type; + /** Register bit width */ + uint8_t width; + /** Register bit offset */ + uint8_t offset; + /** Access size */ + uint8_t access; + /** Address */ + uint64_t address; +} __attribute__ (( packed )); + +/** A memory address space type */ +#define ACPI_ADDRESS_TYPE_MEM 0x00 + +/** An I/O address space type */ +#define ACPI_ADDRESS_TYPE_IO 0x01 + +/** A bus number address space type */ +#define ACPI_ADDRESS_TYPE_BUS 0x02 + /** An ACPI small resource descriptor header */ struct acpi_small_resource { /** Tag byte */ @@ -74,12 +97,6 @@ struct acpi_qword_address_space_resource { uint64_t len; } __attribute__ (( packed )); -/** A memory address space type */ -#define ACPI_ADDRESS_TYPE_MEM 0x00 - -/** A bus number address space type */ -#define ACPI_ADDRESS_TYPE_BUS 0x02 - /** An ACPI resource descriptor */ union acpi_resource { /** Tag byte */ @@ -397,6 +414,7 @@ extern int acpi_extract ( uint32_t signature, void *data, int ( * extract ) ( const struct acpi_header *zsdt, size_t len, size_t offset, void *data ) ); +extern void * acpi_ioremap ( struct acpi_address *address, size_t len ); extern void acpi_add ( struct acpi_descriptor *desc ); extern void acpi_del ( struct acpi_descriptor *desc ); extern int acpi_install ( int ( * install ) ( struct acpi_header *acpi ) );