1 /******************************************************************************
3 * Module Name: tbinstal - ACPI table installation and removal
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, 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.
44 #define __TBINSTAL_C__
50 #define _COMPONENT ACPI_TABLES
51 ACPI_MODULE_NAME ("tbinstal")
53 /* Local prototypes */
57 ACPI_TABLE_DESC *TableDesc,
61 /*******************************************************************************
63 * FUNCTION: AcpiTbCompareTables
65 * PARAMETERS: TableDesc - Table 1 descriptor to be compared
66 * TableIndex - Index of table 2 to be compared
68 * RETURN: TRUE if both tables are identical.
70 * DESCRIPTION: This function compares a table with another table that has
71 * already been installed in the root table list.
73 ******************************************************************************/
77 ACPI_TABLE_DESC *TableDesc,
80 ACPI_STATUS Status = AE_OK;
82 ACPI_TABLE_HEADER *Table;
87 Status = AcpiTbAcquireTable (&AcpiGbl_RootTableList.Tables[TableIndex],
88 &Table, &TableLength, &TableFlags);
89 if (ACPI_FAILURE (Status))
95 * Check for a table match on the entire table length,
96 * not just the header.
98 IsIdentical = (BOOLEAN)((TableDesc->Length != TableLength ||
99 ACPI_MEMCMP (TableDesc->Pointer, Table, TableLength)) ?
102 /* Release the acquired table */
104 AcpiTbReleaseTable (Table, TableLength, TableFlags);
105 return (IsIdentical);
109 /*******************************************************************************
111 * FUNCTION: AcpiTbInstallTableWithOverride
113 * PARAMETERS: TableIndex - Index into root table array
114 * NewTableDesc - New table descriptor to install
115 * Override - Whether override should be performed
119 * DESCRIPTION: Install an ACPI table into the global data structure. The
120 * table override mechanism is called to allow the host
121 * OS to replace any table before it is installed in the root
124 ******************************************************************************/
127 AcpiTbInstallTableWithOverride (
129 ACPI_TABLE_DESC *NewTableDesc,
133 if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
139 * ACPI Table Override:
141 * Before we install the table, let the host OS override it with a new
142 * one if desired. Any table within the RSDT/XSDT can be replaced,
143 * including the DSDT which is pointed to by the FADT.
147 AcpiTbOverrideTable (NewTableDesc);
150 AcpiTbInitTableDescriptor (&AcpiGbl_RootTableList.Tables[TableIndex],
151 NewTableDesc->Address, NewTableDesc->Flags, NewTableDesc->Pointer);
153 AcpiTbPrintTableHeader (NewTableDesc->Address, NewTableDesc->Pointer);
155 /* Set the global integer width (based upon revision of the DSDT) */
157 if (TableIndex == ACPI_TABLE_INDEX_DSDT)
159 AcpiUtSetIntegerWidth (NewTableDesc->Pointer->Revision);
164 /*******************************************************************************
166 * FUNCTION: AcpiTbInstallFixedTable
168 * PARAMETERS: Address - Physical address of DSDT or FACS
169 * Signature - Table signature, NULL if no need to
171 * TableIndex - Index into root table array
175 * DESCRIPTION: Install a fixed ACPI table (DSDT/FACS) into the global data
178 ******************************************************************************/
181 AcpiTbInstallFixedTable (
182 ACPI_PHYSICAL_ADDRESS Address,
186 ACPI_TABLE_DESC NewTableDesc;
190 ACPI_FUNCTION_TRACE (TbInstallFixedTable);
195 ACPI_ERROR ((AE_INFO, "Null physical address for ACPI table [%s]",
197 return (AE_NO_MEMORY);
200 /* Fill a table descriptor for validation */
202 Status = AcpiTbAcquireTempTable (&NewTableDesc, Address,
203 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
204 if (ACPI_FAILURE (Status))
206 ACPI_ERROR ((AE_INFO, "Could not acquire table length at %p",
207 ACPI_CAST_PTR (void, Address)));
208 return_ACPI_STATUS (Status);
211 /* Validate and verify a table before installation */
213 Status = AcpiTbVerifyTable (&NewTableDesc, Signature);
214 if (ACPI_FAILURE (Status))
219 AcpiTbInstallTableWithOverride (TableIndex, &NewTableDesc, TRUE);
223 /* Release the temporary table descriptor */
225 AcpiTbReleaseTempTable (&NewTableDesc);
226 return_ACPI_STATUS (Status);
230 /*******************************************************************************
232 * FUNCTION: AcpiTbInstallStandardTable
234 * PARAMETERS: Address - Address of the table (might be a virtual
235 * address depending on the TableFlags)
236 * Flags - Flags for the table
237 * Reload - Whether reload should be performed
238 * Override - Whether override should be performed
239 * TableIndex - Where the table index is returned
243 * DESCRIPTION: This function is called to install an ACPI table that is
244 * neither DSDT nor FACS (a "standard" table.)
245 * When this function is called by "Load" or "LoadTable" opcodes,
246 * or by AcpiLoadTable() API, the "Reload" parameter is set.
247 * After sucessfully returning from this function, table is
248 * "INSTALLED" but not "VALIDATED".
250 ******************************************************************************/
253 AcpiTbInstallStandardTable (
254 ACPI_PHYSICAL_ADDRESS Address,
261 ACPI_STATUS Status = AE_OK;
262 ACPI_TABLE_DESC NewTableDesc;
265 ACPI_FUNCTION_TRACE (TbInstallStandardTable);
268 /* Acquire a temporary table descriptor for validation */
270 Status = AcpiTbAcquireTempTable (&NewTableDesc, Address, Flags);
271 if (ACPI_FAILURE (Status))
273 ACPI_ERROR ((AE_INFO, "Could not acquire table length at %p",
274 ACPI_CAST_PTR (void, Address)));
275 return_ACPI_STATUS (Status);
279 * Optionally do not load any SSDTs from the RSDT/XSDT. This can
280 * be useful for debugging ACPI problems on some machines.
283 AcpiGbl_DisableSsdtTableInstall &&
284 ACPI_COMPARE_NAME (&NewTableDesc.Signature, ACPI_SIG_SSDT))
286 ACPI_INFO ((AE_INFO, "Ignoring installation of %4.4s at %p",
287 NewTableDesc.Signature.Ascii, ACPI_CAST_PTR (void, Address)));
291 /* Validate and verify a table before installation */
293 Status = AcpiTbVerifyTable (&NewTableDesc, NULL);
294 if (ACPI_FAILURE (Status))
302 * Validate the incoming table signature.
304 * 1) Originally, we checked the table signature for "SSDT" or "PSDT".
305 * 2) We added support for OEMx tables, signature "OEM".
306 * 3) Valid tables were encountered with a null signature, so we just
307 * gave up on validating the signature, (05/2008).
308 * 4) We encountered non-AML tables such as the MADT, which caused
309 * interpreter errors and kernel faults. So now, we once again allow
310 * only "SSDT", "OEMx", and now, also a null signature. (05/2011).
312 if ((NewTableDesc.Signature.Ascii[0] != 0x00) &&
313 (!ACPI_COMPARE_NAME (&NewTableDesc.Signature, ACPI_SIG_SSDT)) &&
314 (ACPI_STRNCMP (NewTableDesc.Signature.Ascii, "OEM", 3)))
316 ACPI_BIOS_ERROR ((AE_INFO,
317 "Table has invalid signature [%4.4s] (0x%8.8X), "
318 "must be SSDT or OEMx",
319 AcpiUtValidAcpiName (NewTableDesc.Signature.Ascii) ?
320 NewTableDesc.Signature.Ascii : "????",
321 NewTableDesc.Signature.Integer));
323 Status = AE_BAD_SIGNATURE;
327 /* Check if table is already registered */
329 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
332 * Check for a table match on the entire table length,
333 * not just the header.
335 if (!AcpiTbCompareTables (&NewTableDesc, i))
341 * Note: the current mechanism does not unregister a table if it is
342 * dynamically unloaded. The related namespace entries are deleted,
343 * but the table remains in the root table list.
345 * The assumption here is that the number of different tables that
346 * will be loaded is actually small, and there is minimal overhead
347 * in just keeping the table in case it is needed again.
349 * If this assumption changes in the future (perhaps on large
350 * machines with many table load/unload operations), tables will
351 * need to be unregistered when they are unloaded, and slots in the
352 * root table list should be reused when empty.
354 if (AcpiGbl_RootTableList.Tables[i].Flags & ACPI_TABLE_IS_LOADED)
356 /* Table is still loaded, this is an error */
358 Status = AE_ALREADY_EXISTS;
364 * Table was unloaded, allow it to be reloaded.
365 * As we are going to return AE_OK to the caller, we should
366 * take the responsibility of freeing the input descriptor.
367 * Refill the input descriptor to ensure
368 * AcpiTbInstallTableWithOverride() can be called again to
369 * indicate the re-installation.
371 AcpiTbUninstallTable (&NewTableDesc);
373 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
374 return_ACPI_STATUS (AE_OK);
379 /* Add the table to the global root table list */
381 Status = AcpiTbGetNextRootIndex (&i);
382 if (ACPI_FAILURE (Status))
388 AcpiTbInstallTableWithOverride (i, &NewTableDesc, Override);
392 /* Release the temporary table descriptor */
394 AcpiTbReleaseTempTable (&NewTableDesc);
395 return_ACPI_STATUS (Status);
399 /*******************************************************************************
401 * FUNCTION: AcpiTbOverrideTable
403 * PARAMETERS: OldTableDesc - Validated table descriptor to be
408 * DESCRIPTION: Attempt table override by calling the OSL override functions.
409 * Note: If the table is overridden, then the entire new table
410 * is acquired and returned by this function.
411 * Before/after invocation, the table descriptor is in a state
412 * that is "VALIDATED".
414 ******************************************************************************/
417 AcpiTbOverrideTable (
418 ACPI_TABLE_DESC *OldTableDesc)
422 ACPI_TABLE_DESC NewTableDesc;
423 ACPI_TABLE_HEADER *Table;
424 ACPI_PHYSICAL_ADDRESS Address;
428 /* (1) Attempt logical override (returns a logical address) */
430 Status = AcpiOsTableOverride (OldTableDesc->Pointer, &Table);
431 if (ACPI_SUCCESS (Status) && Table)
433 AcpiTbAcquireTempTable (&NewTableDesc, ACPI_PTR_TO_PHYSADDR (Table),
434 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL);
435 OverrideType = "Logical";
439 /* (2) Attempt physical override (returns a physical address) */
441 Status = AcpiOsPhysicalTableOverride (OldTableDesc->Pointer,
443 if (ACPI_SUCCESS (Status) && Address && Length)
445 AcpiTbAcquireTempTable (&NewTableDesc, Address,
446 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL);
447 OverrideType = "Physical";
451 return; /* There was no override */
456 /* Validate and verify a table before overriding */
458 Status = AcpiTbVerifyTable (&NewTableDesc, NULL);
459 if (ACPI_FAILURE (Status))
464 ACPI_INFO ((AE_INFO, "%4.4s " ACPI_PRINTF_UINT
465 " %s table override, new table: " ACPI_PRINTF_UINT,
466 OldTableDesc->Signature.Ascii,
467 ACPI_FORMAT_TO_UINT (OldTableDesc->Address),
468 OverrideType, ACPI_FORMAT_TO_UINT (NewTableDesc.Address)));
470 /* We can now uninstall the original table */
472 AcpiTbUninstallTable (OldTableDesc);
475 * Replace the original table descriptor and keep its state as
478 AcpiTbInitTableDescriptor (OldTableDesc, NewTableDesc.Address,
479 NewTableDesc.Flags, NewTableDesc.Pointer);
480 AcpiTbValidateTable (OldTableDesc);
482 /* Release the temporary table descriptor */
484 AcpiTbReleaseTempTable (&NewTableDesc);
488 /*******************************************************************************
490 * FUNCTION: AcpiTbStoreTable
492 * PARAMETERS: Address - Table address
493 * Table - Table header
494 * Length - Table length
495 * Flags - Install flags
496 * TableIndex - Where the table index is returned
498 * RETURN: Status and table index.
500 * DESCRIPTION: Add an ACPI table to the global table list
502 ******************************************************************************/
506 ACPI_PHYSICAL_ADDRESS Address,
507 ACPI_TABLE_HEADER *Table,
513 ACPI_TABLE_DESC *TableDesc;
516 Status = AcpiTbGetNextRootIndex (TableIndex);
517 if (ACPI_FAILURE (Status))
522 /* Initialize added table */
524 TableDesc = &AcpiGbl_RootTableList.Tables[*TableIndex];
525 AcpiTbInitTableDescriptor (TableDesc, Address, Flags, Table);
526 TableDesc->Pointer = Table;
531 /*******************************************************************************
533 * FUNCTION: AcpiTbUninstallTable
535 * PARAMETERS: TableDesc - Table descriptor
539 * DESCRIPTION: Delete one internal ACPI table
541 ******************************************************************************/
544 AcpiTbUninstallTable (
545 ACPI_TABLE_DESC *TableDesc)
548 ACPI_FUNCTION_TRACE (TbUninstallTable);
551 /* Table must be installed */
553 if (!TableDesc->Address)
558 AcpiTbInvalidateTable (TableDesc);
560 if ((TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK) ==
561 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL)
563 ACPI_FREE (ACPI_CAST_PTR (void, TableDesc->Address));
566 TableDesc->Address = ACPI_PTR_TO_PHYSADDR (NULL);