freebsd-dev/sys/contrib/dev/acpica/components/tables/tbinstal.c

569 lines
18 KiB
C
Raw Normal View History

/******************************************************************************
*
* Module Name: tbinstal - ACPI table installation and removal
*
*****************************************************************************/
2011-01-13 16:12:34 +00:00
/*
2014-01-15 00:10:20 +00:00
* Copyright (C) 2000 - 2014, Intel Corp.
* All rights reserved.
*
2011-01-13 16:12:34 +00:00
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*/
#define __TBINSTAL_C__
2009-06-02 20:02:58 +00:00
#include <contrib/dev/acpica/include/acpi.h>
#include <contrib/dev/acpica/include/accommon.h>
#include <contrib/dev/acpica/include/actables.h>
#define _COMPONENT ACPI_TABLES
ACPI_MODULE_NAME ("tbinstal")
2014-03-27 23:50:54 +00:00
/* Local prototypes */
2014-03-27 23:50:54 +00:00
static BOOLEAN
AcpiTbCompareTables (
ACPI_TABLE_DESC *TableDesc,
UINT32 TableIndex);
/*******************************************************************************
*
2014-03-27 23:50:54 +00:00
* FUNCTION: AcpiTbCompareTables
*
2014-03-27 23:50:54 +00:00
* PARAMETERS: TableDesc - Table 1 descriptor to be compared
* TableIndex - Index of table 2 to be compared
*
2014-03-27 23:50:54 +00:00
* RETURN: TRUE if both tables are identical.
*
2014-03-27 23:50:54 +00:00
* DESCRIPTION: This function compares a table with another table that has
* already been installed in the root table list.
*
2014-03-27 23:50:54 +00:00
******************************************************************************/
2014-03-27 23:50:54 +00:00
static BOOLEAN
AcpiTbCompareTables (
ACPI_TABLE_DESC *TableDesc,
UINT32 TableIndex)
{
ACPI_STATUS Status = AE_OK;
2014-03-27 23:50:54 +00:00
BOOLEAN IsIdentical;
ACPI_TABLE_HEADER *Table;
UINT32 TableLength;
UINT8 TableFlags;
2014-03-27 23:50:54 +00:00
Status = AcpiTbAcquireTable (&AcpiGbl_RootTableList.Tables[TableIndex],
&Table, &TableLength, &TableFlags);
if (ACPI_FAILURE (Status))
{
2014-03-27 23:50:54 +00:00
return (FALSE);
}
2014-03-27 23:50:54 +00:00
/*
* Check for a table match on the entire table length,
* not just the header.
*/
IsIdentical = (BOOLEAN)((TableDesc->Length != TableLength ||
ACPI_MEMCMP (TableDesc->Pointer, Table, TableLength)) ?
FALSE : TRUE);
2014-03-27 23:50:54 +00:00
/* Release the acquired table */
2014-03-27 23:50:54 +00:00
AcpiTbReleaseTable (Table, TableLength, TableFlags);
return (IsIdentical);
}
/*******************************************************************************
*
2014-03-27 23:50:54 +00:00
* FUNCTION: AcpiTbInstallTableWithOverride
*
2014-03-27 23:50:54 +00:00
* PARAMETERS: TableIndex - Index into root table array
* NewTableDesc - New table descriptor to install
* Override - Whether override should be performed
*
2014-03-27 23:50:54 +00:00
* RETURN: None
*
2014-03-27 23:50:54 +00:00
* DESCRIPTION: Install an ACPI table into the global data structure. The
* table override mechanism is called to allow the host
* OS to replace any table before it is installed in the root
* table array.
*
******************************************************************************/
2014-03-27 23:50:54 +00:00
void
AcpiTbInstallTableWithOverride (
UINT32 TableIndex,
ACPI_TABLE_DESC *NewTableDesc,
BOOLEAN Override)
{
2014-03-27 23:50:54 +00:00
if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
{
2014-03-27 23:50:54 +00:00
return;
}
/*
2014-03-27 23:50:54 +00:00
* ACPI Table Override:
2011-05-31 17:33:30 +00:00
*
2014-03-27 23:50:54 +00:00
* Before we install the table, let the host OS override it with a new
* one if desired. Any table within the RSDT/XSDT can be replaced,
* including the DSDT which is pointed to by the FADT.
*/
2014-03-27 23:50:54 +00:00
if (Override)
2011-05-31 17:33:30 +00:00
{
2014-03-27 23:50:54 +00:00
AcpiTbOverrideTable (NewTableDesc);
2011-05-31 17:33:30 +00:00
}
2014-03-27 23:50:54 +00:00
AcpiTbInitTableDescriptor (&AcpiGbl_RootTableList.Tables[TableIndex],
NewTableDesc->Address, NewTableDesc->Flags, NewTableDesc->Pointer);
2014-03-27 23:50:54 +00:00
AcpiTbPrintTableHeader (NewTableDesc->Address, NewTableDesc->Pointer);
2014-03-27 23:50:54 +00:00
/* Set the global integer width (based upon revision of the DSDT) */
2014-03-27 23:50:54 +00:00
if (TableIndex == ACPI_TABLE_INDEX_DSDT)
{
2014-03-27 23:50:54 +00:00
AcpiUtSetIntegerWidth (NewTableDesc->Pointer->Revision);
}
}
2012-02-16 00:24:10 +00:00
/*******************************************************************************
*
2014-03-27 23:50:54 +00:00
* FUNCTION: AcpiTbInstallFixedTable
2012-02-16 00:24:10 +00:00
*
2014-03-27 23:50:54 +00:00
* PARAMETERS: Address - Physical address of DSDT or FACS
* Signature - Table signature, NULL if no need to
* match
* TableIndex - Index into root table array
2012-02-16 00:24:10 +00:00
*
2014-03-27 23:50:54 +00:00
* RETURN: Status
2012-02-16 00:24:10 +00:00
*
2014-03-27 23:50:54 +00:00
* DESCRIPTION: Install a fixed ACPI table (DSDT/FACS) into the global data
* structure.
2012-02-16 00:24:10 +00:00
*
******************************************************************************/
2014-03-27 23:50:54 +00:00
ACPI_STATUS
AcpiTbInstallFixedTable (
ACPI_PHYSICAL_ADDRESS Address,
char *Signature,
UINT32 TableIndex)
2012-02-16 00:24:10 +00:00
{
2014-03-27 23:50:54 +00:00
ACPI_TABLE_DESC NewTableDesc;
2012-02-16 00:24:10 +00:00
ACPI_STATUS Status;
2014-03-27 23:50:54 +00:00
ACPI_FUNCTION_TRACE (TbInstallFixedTable);
2012-02-16 00:24:10 +00:00
2014-03-27 23:50:54 +00:00
if (!Address)
2012-02-16 00:24:10 +00:00
{
2014-03-27 23:50:54 +00:00
ACPI_ERROR ((AE_INFO, "Null physical address for ACPI table [%s]",
Signature));
return (AE_NO_MEMORY);
2012-02-16 00:24:10 +00:00
}
2014-03-27 23:50:54 +00:00
/* Fill a table descriptor for validation */
2012-02-16 00:24:10 +00:00
2014-03-27 23:50:54 +00:00
Status = AcpiTbAcquireTempTable (&NewTableDesc, Address,
ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
if (ACPI_FAILURE (Status))
2012-02-16 00:24:10 +00:00
{
2014-03-27 23:50:54 +00:00
ACPI_ERROR ((AE_INFO, "Could not acquire table length at %p",
ACPI_CAST_PTR (void, Address)));
return_ACPI_STATUS (Status);
2012-02-16 00:24:10 +00:00
}
2014-03-27 23:50:54 +00:00
/* Validate and verify a table before installation */
2012-02-16 00:24:10 +00:00
2014-06-27 19:10:35 +00:00
Status = AcpiTbVerifyTempTable (&NewTableDesc, Signature);
2014-03-27 23:50:54 +00:00
if (ACPI_FAILURE (Status))
{
goto ReleaseAndExit;
}
2012-02-16 00:24:10 +00:00
2014-03-27 23:50:54 +00:00
AcpiTbInstallTableWithOverride (TableIndex, &NewTableDesc, TRUE);
2012-02-16 00:24:10 +00:00
2014-03-27 23:50:54 +00:00
ReleaseAndExit:
2012-02-16 00:24:10 +00:00
2014-03-27 23:50:54 +00:00
/* Release the temporary table descriptor */
2012-02-16 00:24:10 +00:00
2014-03-27 23:50:54 +00:00
AcpiTbReleaseTempTable (&NewTableDesc);
return_ACPI_STATUS (Status);
2012-02-16 00:24:10 +00:00
}
/*******************************************************************************
*
2014-03-27 23:50:54 +00:00
* FUNCTION: AcpiTbInstallStandardTable
*
2014-03-27 23:50:54 +00:00
* PARAMETERS: Address - Address of the table (might be a virtual
* address depending on the TableFlags)
* Flags - Flags for the table
* Reload - Whether reload should be performed
* Override - Whether override should be performed
* TableIndex - Where the table index is returned
*
* RETURN: Status
*
2014-03-27 23:50:54 +00:00
* DESCRIPTION: This function is called to install an ACPI table that is
* neither DSDT nor FACS (a "standard" table.)
* When this function is called by "Load" or "LoadTable" opcodes,
* or by AcpiLoadTable() API, the "Reload" parameter is set.
* After sucessfully returning from this function, table is
* "INSTALLED" but not "VALIDATED".
*
******************************************************************************/
ACPI_STATUS
2014-03-27 23:50:54 +00:00
AcpiTbInstallStandardTable (
ACPI_PHYSICAL_ADDRESS Address,
UINT8 Flags,
BOOLEAN Reload,
BOOLEAN Override,
UINT32 *TableIndex)
{
2014-03-27 23:50:54 +00:00
UINT32 i;
ACPI_STATUS Status = AE_OK;
ACPI_TABLE_DESC NewTableDesc;
2014-03-27 23:50:54 +00:00
ACPI_FUNCTION_TRACE (TbInstallStandardTable);
2014-03-27 23:50:54 +00:00
/* Acquire a temporary table descriptor for validation */
2014-03-27 23:50:54 +00:00
Status = AcpiTbAcquireTempTable (&NewTableDesc, Address, Flags);
if (ACPI_FAILURE (Status))
{
2014-03-27 23:50:54 +00:00
ACPI_ERROR ((AE_INFO, "Could not acquire table length at %p",
ACPI_CAST_PTR (void, Address)));
return_ACPI_STATUS (Status);
}
2014-03-27 23:50:54 +00:00
/*
* Optionally do not load any SSDTs from the RSDT/XSDT. This can
* be useful for debugging ACPI problems on some machines.
*/
if (!Reload &&
AcpiGbl_DisableSsdtTableInstall &&
ACPI_COMPARE_NAME (&NewTableDesc.Signature, ACPI_SIG_SSDT))
2012-09-14 22:53:11 +00:00
{
2014-03-27 23:50:54 +00:00
ACPI_INFO ((AE_INFO, "Ignoring installation of %4.4s at %p",
NewTableDesc.Signature.Ascii, ACPI_CAST_PTR (void, Address)));
goto ReleaseAndExit;
2012-09-14 22:53:11 +00:00
}
2014-03-27 23:50:54 +00:00
/* Validate and verify a table before installation */
2014-06-27 19:10:35 +00:00
Status = AcpiTbVerifyTempTable (&NewTableDesc, NULL);
2014-03-27 23:50:54 +00:00
if (ACPI_FAILURE (Status))
{
2014-03-27 23:50:54 +00:00
goto ReleaseAndExit;
}
2014-03-27 23:50:54 +00:00
if (Reload)
{
2014-03-27 23:50:54 +00:00
/*
* 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 ((NewTableDesc.Signature.Ascii[0] != 0x00) &&
(!ACPI_COMPARE_NAME (&NewTableDesc.Signature, ACPI_SIG_SSDT)) &&
(ACPI_STRNCMP (NewTableDesc.Signature.Ascii, "OEM", 3)))
{
2014-03-27 23:50:54 +00:00
ACPI_BIOS_ERROR ((AE_INFO,
"Table has invalid signature [%4.4s] (0x%8.8X), "
"must be SSDT or OEMx",
AcpiUtValidAcpiName (NewTableDesc.Signature.Ascii) ?
NewTableDesc.Signature.Ascii : "????",
NewTableDesc.Signature.Integer));
Status = AE_BAD_SIGNATURE;
goto ReleaseAndExit;
}
2014-03-27 23:50:54 +00:00
/* Check if table is already registered */
2014-03-27 23:50:54 +00:00
for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
{
/*
* Check for a table match on the entire table length,
* not just the header.
*/
if (!AcpiTbCompareTables (&NewTableDesc, i))
{
continue;
}
2003-07-13 22:44:13 +00:00
2014-03-27 23:50:54 +00:00
/*
* 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.
*/
if (AcpiGbl_RootTableList.Tables[i].Flags & ACPI_TABLE_IS_LOADED)
{
/* Table is still loaded, this is an error */
2003-07-13 22:44:13 +00:00
2014-03-27 23:50:54 +00:00
Status = AE_ALREADY_EXISTS;
goto ReleaseAndExit;
}
else
{
/*
* Table was unloaded, allow it to be reloaded.
* As we are going to return AE_OK to the caller, we should
* take the responsibility of freeing the input descriptor.
* Refill the input descriptor to ensure
* AcpiTbInstallTableWithOverride() can be called again to
* indicate the re-installation.
*/
AcpiTbUninstallTable (&NewTableDesc);
*TableIndex = i;
(void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
return_ACPI_STATUS (AE_OK);
}
}
2003-07-13 22:44:13 +00:00
}
2014-03-27 23:50:54 +00:00
/* Add the table to the global root table list */
2003-12-09 02:45:16 +00:00
2014-03-27 23:50:54 +00:00
Status = AcpiTbGetNextRootIndex (&i);
if (ACPI_FAILURE (Status))
{
2014-03-27 23:50:54 +00:00
goto ReleaseAndExit;
2003-12-09 02:45:16 +00:00
}
2003-07-13 22:44:13 +00:00
2014-03-27 23:50:54 +00:00
*TableIndex = i;
AcpiTbInstallTableWithOverride (i, &NewTableDesc, Override);
2013-05-17 23:13:40 +00:00
2014-03-27 23:50:54 +00:00
ReleaseAndExit:
2014-03-27 23:50:54 +00:00
/* Release the temporary table descriptor */
2012-03-20 18:17:33 +00:00
2014-03-27 23:50:54 +00:00
AcpiTbReleaseTempTable (&NewTableDesc);
return_ACPI_STATUS (Status);
}
/*******************************************************************************
*
2014-03-27 23:50:54 +00:00
* FUNCTION: AcpiTbOverrideTable
*
2014-03-27 23:50:54 +00:00
* PARAMETERS: OldTableDesc - Validated table descriptor to be
* overridden
*
* RETURN: None
*
2014-03-27 23:50:54 +00:00
* DESCRIPTION: Attempt table override by calling the OSL override functions.
* Note: If the table is overridden, then the entire new table
* is acquired and returned by this function.
* Before/after invocation, the table descriptor is in a state
* that is "VALIDATED".
*
******************************************************************************/
void
2014-03-27 23:50:54 +00:00
AcpiTbOverrideTable (
ACPI_TABLE_DESC *OldTableDesc)
{
2014-03-27 23:50:54 +00:00
ACPI_STATUS Status;
char *OverrideType;
ACPI_TABLE_DESC NewTableDesc;
ACPI_TABLE_HEADER *Table;
ACPI_PHYSICAL_ADDRESS Address;
UINT32 Length;
2014-03-27 23:50:54 +00:00
/* (1) Attempt logical override (returns a logical address) */
2014-03-27 23:50:54 +00:00
Status = AcpiOsTableOverride (OldTableDesc->Pointer, &Table);
if (ACPI_SUCCESS (Status) && Table)
{
2014-03-27 23:50:54 +00:00
AcpiTbAcquireTempTable (&NewTableDesc, ACPI_PTR_TO_PHYSADDR (Table),
ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL);
OverrideType = "Logical";
goto FinishOverride;
}
2014-03-27 23:50:54 +00:00
/* (2) Attempt physical override (returns a physical address) */
Status = AcpiOsPhysicalTableOverride (OldTableDesc->Pointer,
&Address, &Length);
if (ACPI_SUCCESS (Status) && Address && Length)
{
2014-03-27 23:50:54 +00:00
AcpiTbAcquireTempTable (&NewTableDesc, Address,
ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
OverrideType = "Physical";
goto FinishOverride;
}
2014-03-27 23:50:54 +00:00
return; /* There was no override */
2014-03-27 23:50:54 +00:00
FinishOverride:
2014-03-27 23:50:54 +00:00
/* Validate and verify a table before overriding */
2014-06-27 19:10:35 +00:00
Status = AcpiTbVerifyTempTable (&NewTableDesc, NULL);
if (ACPI_FAILURE (Status))
{
2014-03-27 23:50:54 +00:00
return;
}
2014-03-27 23:50:54 +00:00
ACPI_INFO ((AE_INFO, "%4.4s " ACPI_PRINTF_UINT
" %s table override, new table: " ACPI_PRINTF_UINT,
OldTableDesc->Signature.Ascii,
ACPI_FORMAT_TO_UINT (OldTableDesc->Address),
OverrideType, ACPI_FORMAT_TO_UINT (NewTableDesc.Address)));
2014-03-27 23:50:54 +00:00
/* We can now uninstall the original table */
2014-03-27 23:50:54 +00:00
AcpiTbUninstallTable (OldTableDesc);
/*
2014-03-27 23:50:54 +00:00
* Replace the original table descriptor and keep its state as
* "VALIDATED".
*/
2014-03-27 23:50:54 +00:00
AcpiTbInitTableDescriptor (OldTableDesc, NewTableDesc.Address,
NewTableDesc.Flags, NewTableDesc.Pointer);
2014-06-27 19:10:35 +00:00
AcpiTbValidateTempTable (OldTableDesc);
2014-03-27 23:50:54 +00:00
/* Release the temporary table descriptor */
2014-03-27 23:50:54 +00:00
AcpiTbReleaseTempTable (&NewTableDesc);
}
/*******************************************************************************
*
2014-03-27 23:50:54 +00:00
* FUNCTION: AcpiTbStoreTable
*
2014-03-27 23:50:54 +00:00
* PARAMETERS: Address - Table address
* Table - Table header
* Length - Table length
* Flags - Install flags
* TableIndex - Where the table index is returned
*
2014-03-27 23:50:54 +00:00
* RETURN: Status and table index.
*
2014-03-27 23:50:54 +00:00
* DESCRIPTION: Add an ACPI table to the global table list
*
******************************************************************************/
ACPI_STATUS
2014-03-27 23:50:54 +00:00
AcpiTbStoreTable (
ACPI_PHYSICAL_ADDRESS Address,
ACPI_TABLE_HEADER *Table,
UINT32 Length,
UINT8 Flags,
UINT32 *TableIndex)
{
2014-03-27 23:50:54 +00:00
ACPI_STATUS Status;
ACPI_TABLE_DESC *TableDesc;
2014-03-27 23:50:54 +00:00
Status = AcpiTbGetNextRootIndex (TableIndex);
if (ACPI_FAILURE (Status))
{
2014-03-27 23:50:54 +00:00
return (Status);
}
2014-03-27 23:50:54 +00:00
/* Initialize added table */
2014-03-27 23:50:54 +00:00
TableDesc = &AcpiGbl_RootTableList.Tables[*TableIndex];
AcpiTbInitTableDescriptor (TableDesc, Address, Flags, Table);
TableDesc->Pointer = Table;
return (AE_OK);
}
/*******************************************************************************
*
2014-03-27 23:50:54 +00:00
* FUNCTION: AcpiTbUninstallTable
*
2014-03-27 23:50:54 +00:00
* PARAMETERS: TableDesc - Table descriptor
*
2014-03-27 23:50:54 +00:00
* RETURN: None
*
2014-03-27 23:50:54 +00:00
* DESCRIPTION: Delete one internal ACPI table
*
******************************************************************************/
2014-03-27 23:50:54 +00:00
void
AcpiTbUninstallTable (
ACPI_TABLE_DESC *TableDesc)
{
2014-03-27 23:50:54 +00:00
ACPI_FUNCTION_TRACE (TbUninstallTable);
2014-03-27 23:50:54 +00:00
/* Table must be installed */
2014-03-27 23:50:54 +00:00
if (!TableDesc->Address)
{
2014-03-27 23:50:54 +00:00
return_VOID;
}
2014-03-27 23:50:54 +00:00
AcpiTbInvalidateTable (TableDesc);
2014-03-27 23:50:54 +00:00
if ((TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK) ==
ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL)
{
2014-03-27 23:50:54 +00:00
ACPI_FREE (ACPI_CAST_PTR (void, TableDesc->Address));
}
2014-03-27 23:50:54 +00:00
TableDesc->Address = ACPI_PTR_TO_PHYSADDR (NULL);
return_VOID;
}