1 /******************************************************************************
3 * Module Name: tbinstal - ACPI table installation and removal
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
48 #define _COMPONENT ACPI_TABLES
49 ACPI_MODULE_NAME ("tbinstal")
51 /* Local prototypes */
55 ACPI_TABLE_DESC *TableDesc,
59 /*******************************************************************************
61 * FUNCTION: AcpiTbCompareTables
63 * PARAMETERS: TableDesc - Table 1 descriptor to be compared
64 * TableIndex - Index of table 2 to be compared
66 * RETURN: TRUE if both tables are identical.
68 * DESCRIPTION: This function compares a table with another table that has
69 * already been installed in the root table list.
71 ******************************************************************************/
75 ACPI_TABLE_DESC *TableDesc,
78 ACPI_STATUS Status = AE_OK;
80 ACPI_TABLE_HEADER *Table;
85 Status = AcpiTbAcquireTable (&AcpiGbl_RootTableList.Tables[TableIndex],
86 &Table, &TableLength, &TableFlags);
87 if (ACPI_FAILURE (Status))
93 * Check for a table match on the entire table length,
94 * not just the header.
96 IsIdentical = (BOOLEAN)((TableDesc->Length != TableLength ||
97 ACPI_MEMCMP (TableDesc->Pointer, Table, TableLength)) ?
100 /* Release the acquired table */
102 AcpiTbReleaseTable (Table, TableLength, TableFlags);
103 return (IsIdentical);
107 /*******************************************************************************
109 * FUNCTION: AcpiTbInstallTableWithOverride
111 * PARAMETERS: TableIndex - Index into root table array
112 * NewTableDesc - New table descriptor to install
113 * Override - Whether override should be performed
117 * DESCRIPTION: Install an ACPI table into the global data structure. The
118 * table override mechanism is called to allow the host
119 * OS to replace any table before it is installed in the root
122 ******************************************************************************/
125 AcpiTbInstallTableWithOverride (
127 ACPI_TABLE_DESC *NewTableDesc,
131 if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
137 * ACPI Table Override:
139 * Before we install the table, let the host OS override it with a new
140 * one if desired. Any table within the RSDT/XSDT can be replaced,
141 * including the DSDT which is pointed to by the FADT.
145 AcpiTbOverrideTable (NewTableDesc);
148 AcpiTbInitTableDescriptor (&AcpiGbl_RootTableList.Tables[TableIndex],
149 NewTableDesc->Address, NewTableDesc->Flags, NewTableDesc->Pointer);
151 AcpiTbPrintTableHeader (NewTableDesc->Address, NewTableDesc->Pointer);
153 /* Set the global integer width (based upon revision of the DSDT) */
155 if (TableIndex == ACPI_TABLE_INDEX_DSDT)
157 AcpiUtSetIntegerWidth (NewTableDesc->Pointer->Revision);
162 /*******************************************************************************
164 * FUNCTION: AcpiTbInstallFixedTable
166 * PARAMETERS: Address - Physical address of DSDT or FACS
167 * Signature - Table signature, NULL if no need to
169 * TableIndex - Index into root table array
173 * DESCRIPTION: Install a fixed ACPI table (DSDT/FACS) into the global data
176 ******************************************************************************/
179 AcpiTbInstallFixedTable (
180 ACPI_PHYSICAL_ADDRESS Address,
184 ACPI_TABLE_DESC NewTableDesc;
188 ACPI_FUNCTION_TRACE (TbInstallFixedTable);
193 ACPI_ERROR ((AE_INFO, "Null physical address for ACPI table [%s]",
195 return (AE_NO_MEMORY);
198 /* Fill a table descriptor for validation */
200 Status = AcpiTbAcquireTempTable (&NewTableDesc, Address,
201 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
202 if (ACPI_FAILURE (Status))
204 ACPI_ERROR ((AE_INFO, "Could not acquire table length at %8.8X%8.8X",
205 ACPI_FORMAT_UINT64 (Address)));
206 return_ACPI_STATUS (Status);
209 /* Validate and verify a table before installation */
211 Status = AcpiTbVerifyTempTable (&NewTableDesc, Signature);
212 if (ACPI_FAILURE (Status))
217 AcpiTbInstallTableWithOverride (TableIndex, &NewTableDesc, TRUE);
221 /* Release the temporary table descriptor */
223 AcpiTbReleaseTempTable (&NewTableDesc);
224 return_ACPI_STATUS (Status);
228 /*******************************************************************************
230 * FUNCTION: AcpiTbInstallStandardTable
232 * PARAMETERS: Address - Address of the table (might be a virtual
233 * address depending on the TableFlags)
234 * Flags - Flags for the table
235 * Reload - Whether reload should be performed
236 * Override - Whether override should be performed
237 * TableIndex - Where the table index is returned
241 * DESCRIPTION: This function is called to install an ACPI table that is
242 * neither DSDT nor FACS (a "standard" table.)
243 * When this function is called by "Load" or "LoadTable" opcodes,
244 * or by AcpiLoadTable() API, the "Reload" parameter is set.
245 * After sucessfully returning from this function, table is
246 * "INSTALLED" but not "VALIDATED".
248 ******************************************************************************/
251 AcpiTbInstallStandardTable (
252 ACPI_PHYSICAL_ADDRESS Address,
259 ACPI_STATUS Status = AE_OK;
260 ACPI_TABLE_DESC NewTableDesc;
263 ACPI_FUNCTION_TRACE (TbInstallStandardTable);
266 /* Acquire a temporary table descriptor for validation */
268 Status = AcpiTbAcquireTempTable (&NewTableDesc, Address, Flags);
269 if (ACPI_FAILURE (Status))
271 ACPI_ERROR ((AE_INFO, "Could not acquire table length at %8.8X%8.8X",
272 ACPI_FORMAT_UINT64 (Address)));
273 return_ACPI_STATUS (Status);
277 * Optionally do not load any SSDTs from the RSDT/XSDT. This can
278 * be useful for debugging ACPI problems on some machines.
281 AcpiGbl_DisableSsdtTableInstall &&
282 ACPI_COMPARE_NAME (&NewTableDesc.Signature, ACPI_SIG_SSDT))
284 ACPI_INFO ((AE_INFO, "Ignoring installation of %4.4s at %8.8X%8.8X",
285 NewTableDesc.Signature.Ascii, ACPI_FORMAT_UINT64 (Address)));
289 /* Validate and verify a table before installation */
291 Status = AcpiTbVerifyTempTable (&NewTableDesc, NULL);
292 if (ACPI_FAILURE (Status))
300 * Validate the incoming table signature.
302 * 1) Originally, we checked the table signature for "SSDT" or "PSDT".
303 * 2) We added support for OEMx tables, signature "OEM".
304 * 3) Valid tables were encountered with a null signature, so we just
305 * gave up on validating the signature, (05/2008).
306 * 4) We encountered non-AML tables such as the MADT, which caused
307 * interpreter errors and kernel faults. So now, we once again allow
308 * only "SSDT", "OEMx", and now, also a null signature. (05/2011).
310 if ((NewTableDesc.Signature.Ascii[0] != 0x00) &&
311 (!ACPI_COMPARE_NAME (&NewTableDesc.Signature, ACPI_SIG_SSDT)) &&
312 (ACPI_STRNCMP (NewTableDesc.Signature.Ascii, "OEM", 3)))
314 ACPI_BIOS_ERROR ((AE_INFO,
315 "Table has invalid signature [%4.4s] (0x%8.8X), "
316 "must be SSDT or OEMx",
317 AcpiUtValidAcpiName (NewTableDesc.Signature.Ascii) ?
318 NewTableDesc.Signature.Ascii : "????",
319 NewTableDesc.Signature.Integer));
321 Status = AE_BAD_SIGNATURE;
325 /* Check if table is already registered */
327 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
330 * Check for a table match on the entire table length,
331 * not just the header.
333 if (!AcpiTbCompareTables (&NewTableDesc, i))
339 * Note: the current mechanism does not unregister a table if it is
340 * dynamically unloaded. The related namespace entries are deleted,
341 * but the table remains in the root table list.
343 * The assumption here is that the number of different tables that
344 * will be loaded is actually small, and there is minimal overhead
345 * in just keeping the table in case it is needed again.
347 * If this assumption changes in the future (perhaps on large
348 * machines with many table load/unload operations), tables will
349 * need to be unregistered when they are unloaded, and slots in the
350 * root table list should be reused when empty.
352 if (AcpiGbl_RootTableList.Tables[i].Flags & ACPI_TABLE_IS_LOADED)
354 /* Table is still loaded, this is an error */
356 Status = AE_ALREADY_EXISTS;
362 * Table was unloaded, allow it to be reloaded.
363 * As we are going to return AE_OK to the caller, we should
364 * take the responsibility of freeing the input descriptor.
365 * Refill the input descriptor to ensure
366 * AcpiTbInstallTableWithOverride() can be called again to
367 * indicate the re-installation.
369 AcpiTbUninstallTable (&NewTableDesc);
371 return_ACPI_STATUS (AE_OK);
376 /* Add the table to the global root table list */
378 Status = AcpiTbGetNextTableDescriptor (&i, NULL);
379 if (ACPI_FAILURE (Status))
385 AcpiTbInstallTableWithOverride (i, &NewTableDesc, Override);
389 /* Release the temporary table descriptor */
391 AcpiTbReleaseTempTable (&NewTableDesc);
392 return_ACPI_STATUS (Status);
396 /*******************************************************************************
398 * FUNCTION: AcpiTbOverrideTable
400 * PARAMETERS: OldTableDesc - Validated table descriptor to be
405 * DESCRIPTION: Attempt table override by calling the OSL override functions.
406 * Note: If the table is overridden, then the entire new table
407 * is acquired and returned by this function.
408 * Before/after invocation, the table descriptor is in a state
409 * that is "VALIDATED".
411 ******************************************************************************/
414 AcpiTbOverrideTable (
415 ACPI_TABLE_DESC *OldTableDesc)
419 ACPI_TABLE_DESC NewTableDesc;
420 ACPI_TABLE_HEADER *Table;
421 ACPI_PHYSICAL_ADDRESS Address;
425 /* (1) Attempt logical override (returns a logical address) */
427 Status = AcpiOsTableOverride (OldTableDesc->Pointer, &Table);
428 if (ACPI_SUCCESS (Status) && Table)
430 AcpiTbAcquireTempTable (&NewTableDesc, ACPI_PTR_TO_PHYSADDR (Table),
431 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL);
432 OverrideType = "Logical";
436 /* (2) Attempt physical override (returns a physical address) */
438 Status = AcpiOsPhysicalTableOverride (OldTableDesc->Pointer,
440 if (ACPI_SUCCESS (Status) && Address && Length)
442 AcpiTbAcquireTempTable (&NewTableDesc, Address,
443 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
444 OverrideType = "Physical";
448 return; /* There was no override */
453 /* Validate and verify a table before overriding */
455 Status = AcpiTbVerifyTempTable (&NewTableDesc, NULL);
456 if (ACPI_FAILURE (Status))
461 ACPI_INFO ((AE_INFO, "%4.4s 0x%8.8X%8.8X"
462 " %s table override, new table: 0x%8.8X%8.8X",
463 OldTableDesc->Signature.Ascii,
464 ACPI_FORMAT_UINT64 (OldTableDesc->Address),
465 OverrideType, ACPI_FORMAT_UINT64 (NewTableDesc.Address)));
467 /* We can now uninstall the original table */
469 AcpiTbUninstallTable (OldTableDesc);
472 * Replace the original table descriptor and keep its state as
475 AcpiTbInitTableDescriptor (OldTableDesc, NewTableDesc.Address,
476 NewTableDesc.Flags, NewTableDesc.Pointer);
477 AcpiTbValidateTempTable (OldTableDesc);
479 /* Release the temporary table descriptor */
481 AcpiTbReleaseTempTable (&NewTableDesc);
485 /*******************************************************************************
487 * FUNCTION: AcpiTbUninstallTable
489 * PARAMETERS: TableDesc - Table descriptor
493 * DESCRIPTION: Delete one internal ACPI table
495 ******************************************************************************/
498 AcpiTbUninstallTable (
499 ACPI_TABLE_DESC *TableDesc)
502 ACPI_FUNCTION_TRACE (TbUninstallTable);
505 /* Table must be installed */
507 if (!TableDesc->Address)
512 AcpiTbInvalidateTable (TableDesc);
514 if ((TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK) ==
515 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL)
517 ACPI_FREE (ACPI_PHYSADDR_TO_PTR (TableDesc->Address));
520 TableDesc->Address = ACPI_PTR_TO_PHYSADDR (NULL);