1 /******************************************************************************
3 * Module Name: tbinstal - ACPI table installation and removal
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
117 #define __TBINSTAL_C__
120 #include "accommon.h"
121 #include "acnamesp.h"
122 #include "actables.h"
125 #define _COMPONENT ACPI_TABLES
126 ACPI_MODULE_NAME ("tbinstal")
129 /******************************************************************************
131 * FUNCTION: AcpiTbVerifyTable
133 * PARAMETERS: TableDesc - table
137 * DESCRIPTION: this function is called to verify and map table
139 *****************************************************************************/
143 ACPI_TABLE_DESC
*TableDesc
)
145 ACPI_STATUS Status
= AE_OK
;
148 ACPI_FUNCTION_TRACE (TbVerifyTable
);
151 /* Map the table if necessary */
153 if (!TableDesc
->Pointer
)
155 if ((TableDesc
->Flags
& ACPI_TABLE_ORIGIN_MASK
) ==
156 ACPI_TABLE_ORIGIN_MAPPED
)
158 TableDesc
->Pointer
= AcpiOsMapMemory (
159 TableDesc
->Address
, TableDesc
->Length
);
162 if (!TableDesc
->Pointer
)
164 return_ACPI_STATUS (AE_NO_MEMORY
);
168 /* FACS is the odd table, has no standard ACPI header and no checksum */
170 if (!ACPI_COMPARE_NAME (&TableDesc
->Signature
, ACPI_SIG_FACS
))
172 /* Always calculate checksum, ignore bad checksum if requested */
174 Status
= AcpiTbVerifyChecksum (TableDesc
->Pointer
, TableDesc
->Length
);
177 return_ACPI_STATUS (Status
);
181 /*******************************************************************************
183 * FUNCTION: AcpiTbAddTable
185 * PARAMETERS: TableDesc - Table descriptor
186 * TableIndex - Where the table index is returned
190 * DESCRIPTION: This function is called to add an ACPI table. It is used to
191 * dynamically load tables via the Load and LoadTable AML
194 ******************************************************************************/
198 ACPI_TABLE_DESC
*TableDesc
,
202 ACPI_STATUS Status
= AE_OK
;
203 ACPI_TABLE_HEADER
*OverrideTable
= NULL
;
206 ACPI_FUNCTION_TRACE (TbAddTable
);
209 if (!TableDesc
->Pointer
)
211 Status
= AcpiTbVerifyTable (TableDesc
);
212 if (ACPI_FAILURE (Status
) || !TableDesc
->Pointer
)
214 return_ACPI_STATUS (Status
);
219 * Originally, we checked the table signature for "SSDT" or "PSDT" here.
220 * Next, we added support for OEMx tables, signature "OEM".
221 * Valid tables were encountered with a null signature, so we've just
222 * given up on validating the signature, since it seems to be a waste
223 * of code. The original code was removed (05/2008).
226 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
228 /* Check if table is already registered */
230 for (i
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; ++i
)
232 if (!AcpiGbl_RootTableList
.Tables
[i
].Pointer
)
234 Status
= AcpiTbVerifyTable (&AcpiGbl_RootTableList
.Tables
[i
]);
235 if (ACPI_FAILURE (Status
) ||
236 !AcpiGbl_RootTableList
.Tables
[i
].Pointer
)
243 * Check for a table match on the entire table length,
244 * not just the header.
246 if (TableDesc
->Length
!= AcpiGbl_RootTableList
.Tables
[i
].Length
)
251 if (ACPI_MEMCMP (TableDesc
->Pointer
,
252 AcpiGbl_RootTableList
.Tables
[i
].Pointer
,
253 AcpiGbl_RootTableList
.Tables
[i
].Length
))
259 * Note: the current mechanism does not unregister a table if it is
260 * dynamically unloaded. The related namespace entries are deleted,
261 * but the table remains in the root table list.
263 * The assumption here is that the number of different tables that
264 * will be loaded is actually small, and there is minimal overhead
265 * in just keeping the table in case it is needed again.
267 * If this assumption changes in the future (perhaps on large
268 * machines with many table load/unload operations), tables will
269 * need to be unregistered when they are unloaded, and slots in the
270 * root table list should be reused when empty.
274 * Table is already registered.
275 * We can delete the table that was passed as a parameter.
277 AcpiTbDeleteTable (TableDesc
);
280 if (AcpiGbl_RootTableList
.Tables
[i
].Flags
& ACPI_TABLE_IS_LOADED
)
282 /* Table is still loaded, this is an error */
284 Status
= AE_ALREADY_EXISTS
;
289 /* Table was unloaded, allow it to be reloaded */
291 TableDesc
->Pointer
= AcpiGbl_RootTableList
.Tables
[i
].Pointer
;
292 TableDesc
->Address
= AcpiGbl_RootTableList
.Tables
[i
].Address
;
299 * ACPI Table Override:
300 * Allow the host to override dynamically loaded tables.
302 Status
= AcpiOsTableOverride (TableDesc
->Pointer
, &OverrideTable
);
303 if (ACPI_SUCCESS (Status
) && OverrideTable
)
306 "%4.4s @ 0x%p Table override, replaced with:",
307 TableDesc
->Pointer
->Signature
,
308 ACPI_CAST_PTR (void, TableDesc
->Address
)));
310 /* We can delete the table that was passed as a parameter */
312 AcpiTbDeleteTable (TableDesc
);
314 /* Setup descriptor for the new table */
316 TableDesc
->Address
= ACPI_PTR_TO_PHYSADDR (OverrideTable
);
317 TableDesc
->Pointer
= OverrideTable
;
318 TableDesc
->Length
= OverrideTable
->Length
;
319 TableDesc
->Flags
= ACPI_TABLE_ORIGIN_OVERRIDE
;
322 /* Add the table to the global root table list */
324 Status
= AcpiTbStoreTable (TableDesc
->Address
, TableDesc
->Pointer
,
325 TableDesc
->Length
, TableDesc
->Flags
, TableIndex
);
326 if (ACPI_FAILURE (Status
))
332 AcpiTbPrintTableHeader (TableDesc
->Address
, TableDesc
->Pointer
);
335 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
336 return_ACPI_STATUS (Status
);
340 /*******************************************************************************
342 * FUNCTION: AcpiTbResizeRootTableList
348 * DESCRIPTION: Expand the size of global table array
350 ******************************************************************************/
353 AcpiTbResizeRootTableList (
356 ACPI_TABLE_DESC
*Tables
;
359 ACPI_FUNCTION_TRACE (TbResizeRootTableList
);
362 /* AllowResize flag is a parameter to AcpiInitializeTables */
364 if (!(AcpiGbl_RootTableList
.Flags
& ACPI_ROOT_ALLOW_RESIZE
))
366 ACPI_ERROR ((AE_INFO
, "Resize of Root Table Array is not allowed"));
367 return_ACPI_STATUS (AE_SUPPORT
);
370 /* Increase the Table Array size */
372 Tables
= ACPI_ALLOCATE_ZEROED (
373 ((ACPI_SIZE
) AcpiGbl_RootTableList
.MaxTableCount
+
374 ACPI_ROOT_TABLE_SIZE_INCREMENT
) *
375 sizeof (ACPI_TABLE_DESC
));
378 ACPI_ERROR ((AE_INFO
, "Could not allocate new root table array"));
379 return_ACPI_STATUS (AE_NO_MEMORY
);
382 /* Copy and free the previous table array */
384 if (AcpiGbl_RootTableList
.Tables
)
386 ACPI_MEMCPY (Tables
, AcpiGbl_RootTableList
.Tables
,
387 (ACPI_SIZE
) AcpiGbl_RootTableList
.MaxTableCount
* sizeof (ACPI_TABLE_DESC
));
389 if (AcpiGbl_RootTableList
.Flags
& ACPI_ROOT_ORIGIN_ALLOCATED
)
391 ACPI_FREE (AcpiGbl_RootTableList
.Tables
);
395 AcpiGbl_RootTableList
.Tables
= Tables
;
396 AcpiGbl_RootTableList
.MaxTableCount
+= ACPI_ROOT_TABLE_SIZE_INCREMENT
;
397 AcpiGbl_RootTableList
.Flags
|= (UINT8
) ACPI_ROOT_ORIGIN_ALLOCATED
;
399 return_ACPI_STATUS (AE_OK
);
403 /*******************************************************************************
405 * FUNCTION: AcpiTbStoreTable
407 * PARAMETERS: Address - Table address
408 * Table - Table header
409 * Length - Table length
412 * RETURN: Status and table index.
414 * DESCRIPTION: Add an ACPI table to the global table list
416 ******************************************************************************/
420 ACPI_PHYSICAL_ADDRESS Address
,
421 ACPI_TABLE_HEADER
*Table
,
427 ACPI_TABLE_DESC
*NewTable
;
430 /* Ensure that there is room for the table in the Root Table List */
432 if (AcpiGbl_RootTableList
.CurrentTableCount
>=
433 AcpiGbl_RootTableList
.MaxTableCount
)
435 Status
= AcpiTbResizeRootTableList();
436 if (ACPI_FAILURE (Status
))
442 NewTable
= &AcpiGbl_RootTableList
.Tables
[AcpiGbl_RootTableList
.CurrentTableCount
];
444 /* Initialize added table */
446 NewTable
->Address
= Address
;
447 NewTable
->Pointer
= Table
;
448 NewTable
->Length
= Length
;
449 NewTable
->OwnerId
= 0;
450 NewTable
->Flags
= Flags
;
452 ACPI_MOVE_32_TO_32 (&NewTable
->Signature
, Table
->Signature
);
454 *TableIndex
= AcpiGbl_RootTableList
.CurrentTableCount
;
455 AcpiGbl_RootTableList
.CurrentTableCount
++;
460 /*******************************************************************************
462 * FUNCTION: AcpiTbDeleteTable
464 * PARAMETERS: TableIndex - Table index
468 * DESCRIPTION: Delete one internal ACPI table
470 ******************************************************************************/
474 ACPI_TABLE_DESC
*TableDesc
)
477 /* Table must be mapped or allocated */
479 if (!TableDesc
->Pointer
)
484 switch (TableDesc
->Flags
& ACPI_TABLE_ORIGIN_MASK
)
486 case ACPI_TABLE_ORIGIN_MAPPED
:
487 AcpiOsUnmapMemory (TableDesc
->Pointer
, TableDesc
->Length
);
490 case ACPI_TABLE_ORIGIN_ALLOCATED
:
491 ACPI_FREE (TableDesc
->Pointer
);
498 TableDesc
->Pointer
= NULL
;
502 /*******************************************************************************
504 * FUNCTION: AcpiTbTerminate
510 * DESCRIPTION: Delete all internal ACPI tables
512 ******************************************************************************/
521 ACPI_FUNCTION_TRACE (TbTerminate
);
524 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
526 /* Delete the individual tables */
528 for (i
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; i
++)
530 AcpiTbDeleteTable (&AcpiGbl_RootTableList
.Tables
[i
]);
534 * Delete the root table array if allocated locally. Array cannot be
535 * mapped, so we don't need to check for that flag.
537 if (AcpiGbl_RootTableList
.Flags
& ACPI_ROOT_ORIGIN_ALLOCATED
)
539 ACPI_FREE (AcpiGbl_RootTableList
.Tables
);
542 AcpiGbl_RootTableList
.Tables
= NULL
;
543 AcpiGbl_RootTableList
.Flags
= 0;
544 AcpiGbl_RootTableList
.CurrentTableCount
= 0;
546 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "ACPI Tables freed\n"));
547 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
551 /*******************************************************************************
553 * FUNCTION: AcpiTbDeleteNamespaceByOwner
555 * PARAMETERS: TableIndex - Table index
559 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
561 ******************************************************************************/
564 AcpiTbDeleteNamespaceByOwner (
567 ACPI_OWNER_ID OwnerId
;
571 ACPI_FUNCTION_TRACE (TbDeleteNamespaceByOwner
);
574 Status
= AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
575 if (ACPI_FAILURE (Status
))
577 return_ACPI_STATUS (Status
);
580 if (TableIndex
>= AcpiGbl_RootTableList
.CurrentTableCount
)
582 /* The table index does not exist */
584 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
585 return_ACPI_STATUS (AE_NOT_EXIST
);
588 /* Get the owner ID for this table, used to delete namespace nodes */
590 OwnerId
= AcpiGbl_RootTableList
.Tables
[TableIndex
].OwnerId
;
591 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
594 * Need to acquire the namespace writer lock to prevent interference
595 * with any concurrent namespace walks. The interpreter must be
596 * released during the deletion since the acquisition of the deletion
597 * lock may block, and also since the execution of a namespace walk
598 * must be allowed to use the interpreter.
600 (void) AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER
);
601 Status
= AcpiUtAcquireWriteLock (&AcpiGbl_NamespaceRwLock
);
603 AcpiNsDeleteNamespaceByOwner (OwnerId
);
604 if (ACPI_FAILURE (Status
))
606 return_ACPI_STATUS (Status
);
609 AcpiUtReleaseWriteLock (&AcpiGbl_NamespaceRwLock
);
611 Status
= AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER
);
612 return_ACPI_STATUS (Status
);
616 /*******************************************************************************
618 * FUNCTION: AcpiTbAllocateOwnerId
620 * PARAMETERS: TableIndex - Table index
624 * DESCRIPTION: Allocates OwnerId in TableDesc
626 ******************************************************************************/
629 AcpiTbAllocateOwnerId (
632 ACPI_STATUS Status
= AE_BAD_PARAMETER
;
635 ACPI_FUNCTION_TRACE (TbAllocateOwnerId
);
638 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
639 if (TableIndex
< AcpiGbl_RootTableList
.CurrentTableCount
)
641 Status
= AcpiUtAllocateOwnerId
642 (&(AcpiGbl_RootTableList
.Tables
[TableIndex
].OwnerId
));
645 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
646 return_ACPI_STATUS (Status
);
650 /*******************************************************************************
652 * FUNCTION: AcpiTbReleaseOwnerId
654 * PARAMETERS: TableIndex - Table index
658 * DESCRIPTION: Releases OwnerId in TableDesc
660 ******************************************************************************/
663 AcpiTbReleaseOwnerId (
666 ACPI_STATUS Status
= AE_BAD_PARAMETER
;
669 ACPI_FUNCTION_TRACE (TbReleaseOwnerId
);
672 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
673 if (TableIndex
< AcpiGbl_RootTableList
.CurrentTableCount
)
675 AcpiUtReleaseOwnerId (
676 &(AcpiGbl_RootTableList
.Tables
[TableIndex
].OwnerId
));
680 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
681 return_ACPI_STATUS (Status
);
685 /*******************************************************************************
687 * FUNCTION: AcpiTbGetOwnerId
689 * PARAMETERS: TableIndex - Table index
690 * OwnerId - Where the table OwnerId is returned
694 * DESCRIPTION: returns OwnerId for the ACPI table
696 ******************************************************************************/
701 ACPI_OWNER_ID
*OwnerId
)
703 ACPI_STATUS Status
= AE_BAD_PARAMETER
;
706 ACPI_FUNCTION_TRACE (TbGetOwnerId
);
709 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
710 if (TableIndex
< AcpiGbl_RootTableList
.CurrentTableCount
)
712 *OwnerId
= AcpiGbl_RootTableList
.Tables
[TableIndex
].OwnerId
;
716 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
717 return_ACPI_STATUS (Status
);
721 /*******************************************************************************
723 * FUNCTION: AcpiTbIsTableLoaded
725 * PARAMETERS: TableIndex - Table index
727 * RETURN: Table Loaded Flag
729 ******************************************************************************/
732 AcpiTbIsTableLoaded (
735 BOOLEAN IsLoaded
= FALSE
;
738 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
739 if (TableIndex
< AcpiGbl_RootTableList
.CurrentTableCount
)
742 (AcpiGbl_RootTableList
.Tables
[TableIndex
].Flags
&
743 ACPI_TABLE_IS_LOADED
);
746 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
751 /*******************************************************************************
753 * FUNCTION: AcpiTbSetTableLoadedFlag
755 * PARAMETERS: TableIndex - Table index
756 * IsLoaded - TRUE if table is loaded, FALSE otherwise
760 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
762 ******************************************************************************/
765 AcpiTbSetTableLoadedFlag (
770 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
771 if (TableIndex
< AcpiGbl_RootTableList
.CurrentTableCount
)
775 AcpiGbl_RootTableList
.Tables
[TableIndex
].Flags
|=
776 ACPI_TABLE_IS_LOADED
;
780 AcpiGbl_RootTableList
.Tables
[TableIndex
].Flags
&=
781 ~ACPI_TABLE_IS_LOADED
;
785 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);