1 /******************************************************************************
3 * Module Name: tbinstal - ACPI table installation and removal
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2009, 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
.Count
; ++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
.Size
+
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
.Size
* 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
.Size
+= 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
,
426 ACPI_STATUS Status
= AE_OK
;
429 /* Ensure that there is room for the table in the Root Table List */
431 if (AcpiGbl_RootTableList
.Count
>= AcpiGbl_RootTableList
.Size
)
433 Status
= AcpiTbResizeRootTableList();
434 if (ACPI_FAILURE (Status
))
440 /* Initialize added table */
442 AcpiGbl_RootTableList
.Tables
[AcpiGbl_RootTableList
.Count
].Address
= Address
;
443 AcpiGbl_RootTableList
.Tables
[AcpiGbl_RootTableList
.Count
].Pointer
= Table
;
444 AcpiGbl_RootTableList
.Tables
[AcpiGbl_RootTableList
.Count
].Length
= Length
;
445 AcpiGbl_RootTableList
.Tables
[AcpiGbl_RootTableList
.Count
].OwnerId
= 0;
446 AcpiGbl_RootTableList
.Tables
[AcpiGbl_RootTableList
.Count
].Flags
= Flags
;
449 &(AcpiGbl_RootTableList
.Tables
[AcpiGbl_RootTableList
.Count
].Signature
),
452 *TableIndex
= AcpiGbl_RootTableList
.Count
;
453 AcpiGbl_RootTableList
.Count
++;
458 /*******************************************************************************
460 * FUNCTION: AcpiTbDeleteTable
462 * PARAMETERS: TableIndex - Table index
466 * DESCRIPTION: Delete one internal ACPI table
468 ******************************************************************************/
472 ACPI_TABLE_DESC
*TableDesc
)
475 /* Table must be mapped or allocated */
477 if (!TableDesc
->Pointer
)
482 switch (TableDesc
->Flags
& ACPI_TABLE_ORIGIN_MASK
)
484 case ACPI_TABLE_ORIGIN_MAPPED
:
485 AcpiOsUnmapMemory (TableDesc
->Pointer
, TableDesc
->Length
);
488 case ACPI_TABLE_ORIGIN_ALLOCATED
:
489 ACPI_FREE (TableDesc
->Pointer
);
496 TableDesc
->Pointer
= NULL
;
500 /*******************************************************************************
502 * FUNCTION: AcpiTbTerminate
508 * DESCRIPTION: Delete all internal ACPI tables
510 ******************************************************************************/
519 ACPI_FUNCTION_TRACE (TbTerminate
);
522 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
524 /* Delete the individual tables */
526 for (i
= 0; i
< AcpiGbl_RootTableList
.Count
; i
++)
528 AcpiTbDeleteTable (&AcpiGbl_RootTableList
.Tables
[i
]);
532 * Delete the root table array if allocated locally. Array cannot be
533 * mapped, so we don't need to check for that flag.
535 if (AcpiGbl_RootTableList
.Flags
& ACPI_ROOT_ORIGIN_ALLOCATED
)
537 ACPI_FREE (AcpiGbl_RootTableList
.Tables
);
540 AcpiGbl_RootTableList
.Tables
= NULL
;
541 AcpiGbl_RootTableList
.Flags
= 0;
542 AcpiGbl_RootTableList
.Count
= 0;
544 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "ACPI Tables freed\n"));
545 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
549 /*******************************************************************************
551 * FUNCTION: AcpiTbDeleteNamespaceByOwner
553 * PARAMETERS: TableIndex - Table index
557 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
559 ******************************************************************************/
562 AcpiTbDeleteNamespaceByOwner (
565 ACPI_OWNER_ID OwnerId
;
569 ACPI_FUNCTION_TRACE (TbDeleteNamespaceByOwner
);
572 Status
= AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
573 if (ACPI_FAILURE (Status
))
575 return_ACPI_STATUS (Status
);
578 if (TableIndex
>= AcpiGbl_RootTableList
.Count
)
580 /* The table index does not exist */
582 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
583 return_ACPI_STATUS (AE_NOT_EXIST
);
586 /* Get the owner ID for this table, used to delete namespace nodes */
588 OwnerId
= AcpiGbl_RootTableList
.Tables
[TableIndex
].OwnerId
;
589 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
592 * Need to acquire the namespace writer lock to prevent interference
593 * with any concurrent namespace walks. The interpreter must be
594 * released during the deletion since the acquisition of the deletion
595 * lock may block, and also since the execution of a namespace walk
596 * must be allowed to use the interpreter.
598 (void) AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER
);
599 Status
= AcpiUtAcquireWriteLock (&AcpiGbl_NamespaceRwLock
);
601 AcpiNsDeleteNamespaceByOwner (OwnerId
);
602 if (ACPI_FAILURE (Status
))
604 return_ACPI_STATUS (Status
);
607 AcpiUtReleaseWriteLock (&AcpiGbl_NamespaceRwLock
);
609 Status
= AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER
);
610 return_ACPI_STATUS (Status
);
614 /*******************************************************************************
616 * FUNCTION: AcpiTbAllocateOwnerId
618 * PARAMETERS: TableIndex - Table index
622 * DESCRIPTION: Allocates OwnerId in TableDesc
624 ******************************************************************************/
627 AcpiTbAllocateOwnerId (
630 ACPI_STATUS Status
= AE_BAD_PARAMETER
;
633 ACPI_FUNCTION_TRACE (TbAllocateOwnerId
);
636 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
637 if (TableIndex
< AcpiGbl_RootTableList
.Count
)
639 Status
= AcpiUtAllocateOwnerId
640 (&(AcpiGbl_RootTableList
.Tables
[TableIndex
].OwnerId
));
643 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
644 return_ACPI_STATUS (Status
);
648 /*******************************************************************************
650 * FUNCTION: AcpiTbReleaseOwnerId
652 * PARAMETERS: TableIndex - Table index
656 * DESCRIPTION: Releases OwnerId in TableDesc
658 ******************************************************************************/
661 AcpiTbReleaseOwnerId (
664 ACPI_STATUS Status
= AE_BAD_PARAMETER
;
667 ACPI_FUNCTION_TRACE (TbReleaseOwnerId
);
670 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
671 if (TableIndex
< AcpiGbl_RootTableList
.Count
)
673 AcpiUtReleaseOwnerId (
674 &(AcpiGbl_RootTableList
.Tables
[TableIndex
].OwnerId
));
678 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
679 return_ACPI_STATUS (Status
);
683 /*******************************************************************************
685 * FUNCTION: AcpiTbGetOwnerId
687 * PARAMETERS: TableIndex - Table index
688 * OwnerId - Where the table OwnerId is returned
692 * DESCRIPTION: returns OwnerId for the ACPI table
694 ******************************************************************************/
699 ACPI_OWNER_ID
*OwnerId
)
701 ACPI_STATUS Status
= AE_BAD_PARAMETER
;
704 ACPI_FUNCTION_TRACE (TbGetOwnerId
);
707 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
708 if (TableIndex
< AcpiGbl_RootTableList
.Count
)
710 *OwnerId
= AcpiGbl_RootTableList
.Tables
[TableIndex
].OwnerId
;
714 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
715 return_ACPI_STATUS (Status
);
719 /*******************************************************************************
721 * FUNCTION: AcpiTbIsTableLoaded
723 * PARAMETERS: TableIndex - Table index
725 * RETURN: Table Loaded Flag
727 ******************************************************************************/
730 AcpiTbIsTableLoaded (
733 BOOLEAN IsLoaded
= FALSE
;
736 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
737 if (TableIndex
< AcpiGbl_RootTableList
.Count
)
740 (AcpiGbl_RootTableList
.Tables
[TableIndex
].Flags
&
741 ACPI_TABLE_IS_LOADED
);
744 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
749 /*******************************************************************************
751 * FUNCTION: AcpiTbSetTableLoadedFlag
753 * PARAMETERS: TableIndex - Table index
754 * IsLoaded - TRUE if table is loaded, FALSE otherwise
758 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
760 ******************************************************************************/
763 AcpiTbSetTableLoadedFlag (
768 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
769 if (TableIndex
< AcpiGbl_RootTableList
.Count
)
773 AcpiGbl_RootTableList
.Tables
[TableIndex
].Flags
|=
774 ACPI_TABLE_IS_LOADED
;
778 AcpiGbl_RootTableList
.Tables
[TableIndex
].Flags
&=
779 ~ACPI_TABLE_IS_LOADED
;
783 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);