ACPI_STATUS AdGetLocalTables ( void) { ACPI_STATUS Status; ACPI_TABLE_HEADER TableHeader; ACPI_TABLE_HEADER *NewTable; UINT32 TableIndex; /* Get the DSDT via table override */ ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT); AcpiOsTableOverride (&TableHeader, &NewTable); if (!NewTable) { fprintf (stderr, "Could not obtain DSDT\n"); return (AE_NO_ACPI_TABLES); } AdWriteTable (NewTable, NewTable->Length, ACPI_SIG_DSDT, NewTable->OemTableId); /* Store DSDT in the Table Manager */ Status = AdStoreTable (NewTable, &TableIndex); if (ACPI_FAILURE (Status)) { fprintf (stderr, "Could not store DSDT\n"); return (AE_NO_ACPI_TABLES); } return (AE_OK); }
ACPI_TABLE_HEADER * AcpiTbTableOverride ( ACPI_TABLE_HEADER *TableHeader, ACPI_TABLE_DESC *TableDesc) { ACPI_STATUS Status; ACPI_TABLE_HEADER *NewTable = NULL; ACPI_PHYSICAL_ADDRESS NewAddress = 0; UINT32 NewTableLength = 0; UINT8 NewFlags; char *OverrideType; /* (1) Attempt logical override (returns a logical address) */ Status = AcpiOsTableOverride (TableHeader, &NewTable); if (ACPI_SUCCESS (Status) && NewTable) { NewAddress = ACPI_PTR_TO_PHYSADDR (NewTable); NewTableLength = NewTable->Length; NewFlags = ACPI_TABLE_ORIGIN_OVERRIDE; OverrideType = "Logical"; goto FinishOverride; } /* (2) Attempt physical override (returns a physical address) */ Status = AcpiOsPhysicalTableOverride (TableHeader, &NewAddress, &NewTableLength); if (ACPI_SUCCESS (Status) && NewAddress && NewTableLength) { /* Map the entire new table */ NewTable = AcpiOsMapMemory (NewAddress, NewTableLength); if (!NewTable) { ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY, "%4.4s %p Attempted physical table override failed", TableHeader->Signature, ACPI_CAST_PTR (void, TableDesc->Address))); return (NULL); }
ACPI_STATUS AdGetLocalTables ( char *Filename, BOOLEAN GetAllTables) { ACPI_STATUS Status; ACPI_TABLE_HEADER TableHeader; ACPI_TABLE_HEADER *NewTable; UINT32 NumTables; UINT32 PointerSize; UINT32 TableIndex; if (GetAllTables) { ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_RSDT); AcpiOsTableOverride (&TableHeader, &NewTable); if (!NewTable) { fprintf (stderr, "Could not obtain RSDT\n"); return (AE_NO_ACPI_TABLES); } else { AdWriteTable (NewTable, NewTable->Length, ACPI_SIG_RSDT, NewTable->OemTableId); } if (ACPI_COMPARE_NAME (NewTable->Signature, ACPI_SIG_RSDT)) { PointerSize = sizeof (UINT32); } else { PointerSize = sizeof (UINT64); } /* * Determine the number of tables pointed to by the RSDT/XSDT. * This is defined by the ACPI Specification to be the number of * pointers contained within the RSDT/XSDT. The size of the pointers * is architecture-dependent. */ NumTables = (NewTable->Length - sizeof (ACPI_TABLE_HEADER)) / PointerSize; AcpiOsPrintf ("There are %u tables defined in the %4.4s\n\n", NumTables, NewTable->Signature); /* Get the FADT */ ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_FADT); AcpiOsTableOverride (&TableHeader, &NewTable); if (NewTable) { AdWriteTable (NewTable, NewTable->Length, ACPI_SIG_FADT, NewTable->OemTableId); } AcpiOsPrintf ("\n"); /* Don't bother with FACS, it is usually all zeros */ } /* Always get the DSDT */ ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT); AcpiOsTableOverride (&TableHeader, &NewTable); if (NewTable) { AdWriteTable (NewTable, NewTable->Length, ACPI_SIG_DSDT, NewTable->OemTableId); /* Store DSDT in the Table Manager */ Status = AcpiTbStoreTable (0, NewTable, NewTable->Length, 0, &TableIndex); if (ACPI_FAILURE (Status)) { fprintf (stderr, "Could not store DSDT\n"); return (AE_NO_ACPI_TABLES); } } else { fprintf (stderr, "Could not obtain DSDT\n"); return (AE_NO_ACPI_TABLES); } #if 0 /* TBD: Future implementation */ AcpiOsPrintf ("\n"); /* Get all SSDTs */ ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_SSDT); do { NewTable = NULL; Status = AcpiOsTableOverride (&TableHeader, &NewTable); } while (NewTable); #endif return (AE_OK); }
ACPI_STATUS AcpiTbAddTable ( ACPI_TABLE_DESC *TableDesc, UINT32 *TableIndex) { UINT32 i; ACPI_STATUS Status = AE_OK; ACPI_TABLE_HEADER *OverrideTable = NULL; ACPI_FUNCTION_TRACE (TbAddTable); if (!TableDesc->Pointer) { Status = AcpiTbVerifyTable (TableDesc); if (ACPI_FAILURE (Status) || !TableDesc->Pointer) { return_ACPI_STATUS (Status); } } /* * Validate the incoming table signature. * * 1) Originally, we checked the table signature for "SSDT" or "PSDT". * 2) We added support for OEMx tables, signature "OEM". * 3) Valid tables were encountered with a null signature, so we just * gave up on validating the signature, (05/2008). * 4) We encountered non-AML tables such as the MADT, which caused * interpreter errors and kernel faults. So now, we once again allow * only "SSDT", "OEMx", and now, also a null signature. (05/2011). */ if ((TableDesc->Pointer->Signature[0] != 0x00) && (!ACPI_COMPARE_NAME (TableDesc->Pointer->Signature, ACPI_SIG_SSDT)) && (ACPI_STRNCMP (TableDesc->Pointer->Signature, "OEM", 3))) { ACPI_ERROR ((AE_INFO, "Table has invalid signature [%4.4s] (0x%8.8X), must be SSDT or OEMx", AcpiUtValidAcpiName (*(UINT32 *) TableDesc->Pointer->Signature) ? TableDesc->Pointer->Signature : "????", *(UINT32 *) TableDesc->Pointer->Signature)); return_ACPI_STATUS (AE_BAD_SIGNATURE); } (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); /* Check if table is already registered */ for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i) { if (!AcpiGbl_RootTableList.Tables[i].Pointer) { Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[i]); if (ACPI_FAILURE (Status) || !AcpiGbl_RootTableList.Tables[i].Pointer) { continue; } } /* * Check for a table match on the entire table length, * not just the header. */ if (TableDesc->Length != AcpiGbl_RootTableList.Tables[i].Length) { continue; } if (ACPI_MEMCMP (TableDesc->Pointer, AcpiGbl_RootTableList.Tables[i].Pointer, AcpiGbl_RootTableList.Tables[i].Length)) { continue; } /* * Note: the current mechanism does not unregister a table if it is * dynamically unloaded. The related namespace entries are deleted, * but the table remains in the root table list. * * The assumption here is that the number of different tables that * will be loaded is actually small, and there is minimal overhead * in just keeping the table in case it is needed again. * * If this assumption changes in the future (perhaps on large * machines with many table load/unload operations), tables will * need to be unregistered when they are unloaded, and slots in the * root table list should be reused when empty. */ /* * Table is already registered. * We can delete the table that was passed as a parameter. */ AcpiTbDeleteTable (TableDesc); *TableIndex = i; if (AcpiGbl_RootTableList.Tables[i].Flags & ACPI_TABLE_IS_LOADED) { /* Table is still loaded, this is an error */ Status = AE_ALREADY_EXISTS; goto Release; } else { /* Table was unloaded, allow it to be reloaded */ TableDesc->Pointer = AcpiGbl_RootTableList.Tables[i].Pointer; TableDesc->Address = AcpiGbl_RootTableList.Tables[i].Address; Status = AE_OK; goto PrintHeader; } } /* * ACPI Table Override: * Allow the host to override dynamically loaded tables. */ Status = AcpiOsTableOverride (TableDesc->Pointer, &OverrideTable); if (ACPI_SUCCESS (Status) && OverrideTable) { ACPI_INFO ((AE_INFO, "%4.4s @ 0x%p Table override, replaced with:", TableDesc->Pointer->Signature, ACPI_CAST_PTR (void, TableDesc->Address))); /* We can delete the table that was passed as a parameter */ AcpiTbDeleteTable (TableDesc); /* Setup descriptor for the new table */ TableDesc->Address = ACPI_PTR_TO_PHYSADDR (OverrideTable); TableDesc->Pointer = OverrideTable; TableDesc->Length = OverrideTable->Length; TableDesc->Flags = ACPI_TABLE_ORIGIN_OVERRIDE; }
void AcpiTbOverrideTable ( ACPI_TABLE_DESC *OldTableDesc) { ACPI_STATUS Status; char *OverrideType; ACPI_TABLE_DESC NewTableDesc; ACPI_TABLE_HEADER *Table; ACPI_PHYSICAL_ADDRESS Address; UINT32 Length; /* (1) Attempt logical override (returns a logical address) */ Status = AcpiOsTableOverride (OldTableDesc->Pointer, &Table); if (ACPI_SUCCESS (Status) && Table) { AcpiTbAcquireTempTable (&NewTableDesc, ACPI_PTR_TO_PHYSADDR (Table), ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL); OverrideType = "Logical"; goto FinishOverride; } /* (2) Attempt physical override (returns a physical address) */ Status = AcpiOsPhysicalTableOverride (OldTableDesc->Pointer, &Address, &Length); if (ACPI_SUCCESS (Status) && Address && Length) { AcpiTbAcquireTempTable (&NewTableDesc, Address, ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL); OverrideType = "Physical"; goto FinishOverride; } return; /* There was no override */ FinishOverride: /* Validate and verify a table before overriding */ Status = AcpiTbVerifyTempTable (&NewTableDesc, NULL); if (ACPI_FAILURE (Status)) { return; } ACPI_INFO ((AE_INFO, "%4.4s 0x%8.8X%8.8X" " %s table override, new table: 0x%8.8X%8.8X", OldTableDesc->Signature.Ascii, ACPI_FORMAT_UINT64 (OldTableDesc->Address), OverrideType, ACPI_FORMAT_UINT64 (NewTableDesc.Address))); /* We can now uninstall the original table */ AcpiTbUninstallTable (OldTableDesc); /* * Replace the original table descriptor and keep its state as * "VALIDATED". */ AcpiTbInitTableDescriptor (OldTableDesc, NewTableDesc.Address, NewTableDesc.Flags, NewTableDesc.Pointer); AcpiTbValidateTempTable (OldTableDesc); /* Release the temporary table descriptor */ AcpiTbReleaseTempTable (&NewTableDesc); }
ACPI_STATUS AcpiTbAddTable ( ACPI_TABLE_DESC *TableDesc, UINT32 *TableIndex) { UINT32 i; ACPI_STATUS Status = AE_OK; ACPI_TABLE_HEADER *OverrideTable = NULL; ACPI_FUNCTION_TRACE (TbAddTable); if (!TableDesc->Pointer) { Status = AcpiTbVerifyTable (TableDesc); if (ACPI_FAILURE (Status) || !TableDesc->Pointer) { return_ACPI_STATUS (Status); } } /* * Originally, we checked the table signature for "SSDT" or "PSDT" here. * Next, we added support for OEMx tables, signature "OEM". * Valid tables were encountered with a null signature, so we've just * given up on validating the signature, since it seems to be a waste * of code. The original code was removed (05/2008). */ (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); /* Check if table is already registered */ for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i) { if (!AcpiGbl_RootTableList.Tables[i].Pointer) { Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[i]); if (ACPI_FAILURE (Status) || !AcpiGbl_RootTableList.Tables[i].Pointer) { continue; } } /* * Check for a table match on the entire table length, * not just the header. */ if (TableDesc->Length != AcpiGbl_RootTableList.Tables[i].Length) { continue; } if (ACPI_MEMCMP (TableDesc->Pointer, AcpiGbl_RootTableList.Tables[i].Pointer, AcpiGbl_RootTableList.Tables[i].Length)) { continue; } /* * Note: the current mechanism does not unregister a table if it is * dynamically unloaded. The related namespace entries are deleted, * but the table remains in the root table list. * * The assumption here is that the number of different tables that * will be loaded is actually small, and there is minimal overhead * in just keeping the table in case it is needed again. * * If this assumption changes in the future (perhaps on large * machines with many table load/unload operations), tables will * need to be unregistered when they are unloaded, and slots in the * root table list should be reused when empty. */ /* * Table is already registered. * We can delete the table that was passed as a parameter. */ AcpiTbDeleteTable (TableDesc); *TableIndex = i; if (AcpiGbl_RootTableList.Tables[i].Flags & ACPI_TABLE_IS_LOADED) { /* Table is still loaded, this is an error */ Status = AE_ALREADY_EXISTS; goto Release; } else { /* Table was unloaded, allow it to be reloaded */ TableDesc->Pointer = AcpiGbl_RootTableList.Tables[i].Pointer; TableDesc->Address = AcpiGbl_RootTableList.Tables[i].Address; Status = AE_OK; goto PrintHeader; } } /* * ACPI Table Override: * Allow the host to override dynamically loaded tables. */ Status = AcpiOsTableOverride (TableDesc->Pointer, &OverrideTable); if (ACPI_SUCCESS (Status) && OverrideTable) { ACPI_INFO ((AE_INFO, "%4.4s @ 0x%p Table override, replaced with:", TableDesc->Pointer->Signature, ACPI_CAST_PTR (void, TableDesc->Address))); /* We can delete the table that was passed as a parameter */ AcpiTbDeleteTable (TableDesc); /* Setup descriptor for the new table */ TableDesc->Address = ACPI_PTR_TO_PHYSADDR (OverrideTable); TableDesc->Pointer = OverrideTable; TableDesc->Length = OverrideTable->Length; TableDesc->Flags = ACPI_TABLE_ORIGIN_OVERRIDE; }