]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[acpi] Add acpi_ioremap() to map an ACPI-described address
authorMichael Brown <mcb30@ipxe.org>
Wed, 5 Nov 2025 14:07:27 +0000 (14:07 +0000)
committerMichael Brown <mcb30@ipxe.org>
Wed, 5 Nov 2025 14:10:14 +0000 (14:10 +0000)
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 <mcb30@ipxe.org>
src/core/acpi.c
src/include/ipxe/acpi.h

index 6c5d1e079067d4ac664652e6ebf72993dd891d4e..fa8ed34ffda7566adafb3307137b4014197faf03 100644 (file)
@@ -27,6 +27,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <errno.h>
 #include <byteswap.h>
 #include <ipxe/uaccess.h>
+#include <ipxe/iomap.h>
 #include <ipxe/acpi.h>
 #include <ipxe/interface.h>
 
@@ -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
index 40a44cffcc8b9e505d1633610f80bf8aa55a93ed..5e9fb5ebab57daa86d931e31bc326f134da06362 100644 (file)
@@ -18,6 +18,29 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <ipxe/api.h>
 #include <config/general.h>
 
+/** 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 ) );