]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[acpi] Allow for the possibility of overriding ACPI tables at link time
authorMichael Brown <mcb30@ipxe.org>
Wed, 23 Mar 2022 14:39:11 +0000 (14:39 +0000)
committerMichael Brown <mcb30@ipxe.org>
Thu, 24 Mar 2022 12:58:52 +0000 (12:58 +0000)
Allow for linked-in code to override the mechanism used to locate an
ACPI table, thereby opening up the possibility of ACPI self-tests.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/x86/interface/pcbios/acpi_timer.c
src/arch/x86/interface/pcbios/acpipwr.c
src/core/acpi.c
src/core/acpi_settings.c
src/include/ipxe/acpi.h

index 82e85a0342315adbad6ae8163df8afd81672c378..2e4047e38ee0d2f61eff40b157859b3022213099 100644 (file)
@@ -107,7 +107,7 @@ static int acpi_timer_probe ( void ) {
        unsigned int pm_tmr_blk;
 
        /* Locate FADT */
-       fadt = acpi_find ( FADT_SIGNATURE, 0 );
+       fadt = acpi_table ( FADT_SIGNATURE, 0 );
        if ( ! fadt ) {
                DBGC ( &acpi_timer, "ACPI could not find FADT\n" );
                return -ENOENT;
index 3dac6b6051d9a543067a34e9fb7317fc37528459..f08b4af252b6af49e8f4a57b9b0a85936c5897ec 100644 (file)
@@ -123,7 +123,7 @@ int acpi_poweroff ( void ) {
        int rc;
 
        /* Locate FADT */
-       fadt = acpi_find ( FADT_SIGNATURE, 0 );
+       fadt = acpi_table ( FADT_SIGNATURE, 0 );
        if ( ! fadt ) {
                DBGC ( colour, "ACPI could not find FADT\n" );
                return -ENOENT;
index aa486da939051a55dfe13bf4294d9a2c30a42cfc..526bf855582e5896eb960d9f5b355980b2f6359a 100644 (file)
@@ -38,6 +38,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 /** Colour for debug messages */
 #define colour FADT_SIGNATURE
 
+/** ACPI table finder
+ *
+ * May be overridden at link time to inject tables for testing.
+ */
+typeof ( acpi_find ) *acpi_finder __attribute__ (( weak )) = acpi_find;
+
 /******************************************************************************
  *
  * Utility functions
@@ -82,6 +88,18 @@ void acpi_fix_checksum ( struct acpi_header *acpi ) {
        acpi->checksum -= acpi_checksum ( virt_to_user ( acpi ) );
 }
 
+/**
+ * Locate ACPI table
+ *
+ * @v signature                Requested table signature
+ * @v index            Requested index of table with this signature
+ * @ret table          Table, or UNULL if not found
+ */
+userptr_t acpi_table ( uint32_t signature, unsigned int index ) {
+
+       return ( *acpi_finder ) ( signature, index );
+}
+
 /**
  * Locate ACPI table via RSDT
  *
@@ -230,7 +248,7 @@ int acpi_extract ( uint32_t signature, void *data,
        int rc;
 
        /* Try DSDT first */
-       fadt = acpi_find ( FADT_SIGNATURE, 0 );
+       fadt = acpi_table ( FADT_SIGNATURE, 0 );
        if ( fadt ) {
                copy_from_user ( &fadtab, fadt, 0, sizeof ( fadtab ) );
                dsdt = phys_to_user ( fadtab.dsdt );
@@ -241,7 +259,7 @@ int acpi_extract ( uint32_t signature, void *data,
 
        /* Try all SSDTs */
        for ( i = 0 ; ; i++ ) {
-               ssdt = acpi_find ( SSDT_SIGNATURE, i );
+               ssdt = acpi_table ( SSDT_SIGNATURE, i );
                if ( ! ssdt )
                        break;
                if ( ( rc = acpi_zsdt ( ssdt, signature, data,
index 7ba2e979f1344c5a4d5c4363313597c9d546f26e..b9e2b7f616d005ee70005dd1594e7e6b30de9210 100644 (file)
@@ -88,7 +88,7 @@ static int acpi_settings_fetch ( struct settings *settings,
               acpi_name ( tag_signature ), tag_index, tag_offset, tag_len );
 
        /* Locate ACPI table */
-       table = acpi_find ( tag_signature, tag_index );
+       table = acpi_table ( tag_signature, tag_index );
        if ( ! table )
                return -ENOENT;
 
index 7df3ec21c60e6672e75e616209e0760151d1b335..c346812389ad96fc44d472fe8863f3df6f0cabc5 100644 (file)
@@ -386,7 +386,10 @@ acpi_describe ( struct interface *interface );
 #define acpi_describe_TYPE( object_type )                              \
        typeof ( struct acpi_descriptor * ( object_type ) )
 
+extern userptr_t ( * acpi_finder ) ( uint32_t signature, unsigned int index );
+
 extern void acpi_fix_checksum ( struct acpi_header *acpi );
+extern userptr_t acpi_table ( uint32_t signature, unsigned int index );
 extern int acpi_extract ( uint32_t signature, void *data,
                          int ( * extract ) ( userptr_t zsdt, size_t len,
                                              size_t offset, void *data ) );