Sync ACPICA with Intel's version 20161117.
[dragonfly.git] / sys / contrib / dev / acpica / source / components / tables / tbdata.c
blob95b5b2672cd2723578ef7262838708af84d3b47e
1 /******************************************************************************
3 * Module Name: tbdata - Table manager data structure functions
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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 #include "acpi.h"
45 #include "accommon.h"
46 #include "acnamesp.h"
47 #include "actables.h"
48 #include "acevents.h"
50 #define _COMPONENT ACPI_TABLES
51 ACPI_MODULE_NAME ("tbdata")
54 /*******************************************************************************
56 * FUNCTION: AcpiTbInitTableDescriptor
58 * PARAMETERS: TableDesc - Table descriptor
59 * Address - Physical address of the table
60 * Flags - Allocation flags of the table
61 * Table - Pointer to the table
63 * RETURN: None
65 * DESCRIPTION: Initialize a new table descriptor
67 ******************************************************************************/
69 void
70 AcpiTbInitTableDescriptor (
71 ACPI_TABLE_DESC *TableDesc,
72 ACPI_PHYSICAL_ADDRESS Address,
73 UINT8 Flags,
74 ACPI_TABLE_HEADER *Table)
78 * Initialize the table descriptor. Set the pointer to NULL, since the
79 * table is not fully mapped at this time.
81 memset (TableDesc, 0, sizeof (ACPI_TABLE_DESC));
82 TableDesc->Address = Address;
83 TableDesc->Length = Table->Length;
84 TableDesc->Flags = Flags;
85 ACPI_MOVE_32_TO_32 (TableDesc->Signature.Ascii, Table->Signature);
89 /*******************************************************************************
91 * FUNCTION: AcpiTbAcquireTable
93 * PARAMETERS: TableDesc - Table descriptor
94 * TablePtr - Where table is returned
95 * TableLength - Where table length is returned
96 * TableFlags - Where table allocation flags are returned
98 * RETURN: Status
100 * DESCRIPTION: Acquire an ACPI table. It can be used for tables not
101 * maintained in the AcpiGbl_RootTableList.
103 ******************************************************************************/
105 ACPI_STATUS
106 AcpiTbAcquireTable (
107 ACPI_TABLE_DESC *TableDesc,
108 ACPI_TABLE_HEADER **TablePtr,
109 UINT32 *TableLength,
110 UINT8 *TableFlags)
112 ACPI_TABLE_HEADER *Table = NULL;
115 switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)
117 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
119 Table = AcpiOsMapMemory (TableDesc->Address, TableDesc->Length);
120 break;
122 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
123 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
125 Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
126 ACPI_PHYSADDR_TO_PTR (TableDesc->Address));
127 break;
129 default:
131 break;
134 /* Table is not valid yet */
136 if (!Table)
138 return (AE_NO_MEMORY);
141 /* Fill the return values */
143 *TablePtr = Table;
144 *TableLength = TableDesc->Length;
145 *TableFlags = TableDesc->Flags;
146 return (AE_OK);
150 /*******************************************************************************
152 * FUNCTION: AcpiTbReleaseTable
154 * PARAMETERS: Table - Pointer for the table
155 * TableLength - Length for the table
156 * TableFlags - Allocation flags for the table
158 * RETURN: None
160 * DESCRIPTION: Release a table. The inverse of AcpiTbAcquireTable().
162 ******************************************************************************/
164 void
165 AcpiTbReleaseTable (
166 ACPI_TABLE_HEADER *Table,
167 UINT32 TableLength,
168 UINT8 TableFlags)
171 switch (TableFlags & ACPI_TABLE_ORIGIN_MASK)
173 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
175 AcpiOsUnmapMemory (Table, TableLength);
176 break;
178 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
179 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
180 default:
182 break;
187 /*******************************************************************************
189 * FUNCTION: AcpiTbAcquireTempTable
191 * PARAMETERS: TableDesc - Table descriptor to be acquired
192 * Address - Address of the table
193 * Flags - Allocation flags of the table
195 * RETURN: Status
197 * DESCRIPTION: This function validates the table header to obtain the length
198 * of a table and fills the table descriptor to make its state as
199 * "INSTALLED". Such a table descriptor is only used for verified
200 * installation.
202 ******************************************************************************/
204 ACPI_STATUS
205 AcpiTbAcquireTempTable (
206 ACPI_TABLE_DESC *TableDesc,
207 ACPI_PHYSICAL_ADDRESS Address,
208 UINT8 Flags)
210 ACPI_TABLE_HEADER *TableHeader;
213 switch (Flags & ACPI_TABLE_ORIGIN_MASK)
215 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
217 /* Get the length of the full table from the header */
219 TableHeader = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
220 if (!TableHeader)
222 return (AE_NO_MEMORY);
225 AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
226 AcpiOsUnmapMemory (TableHeader, sizeof (ACPI_TABLE_HEADER));
227 return (AE_OK);
229 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
230 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
232 TableHeader = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
233 ACPI_PHYSADDR_TO_PTR (Address));
234 if (!TableHeader)
236 return (AE_NO_MEMORY);
239 AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
240 return (AE_OK);
242 default:
244 break;
247 /* Table is not valid yet */
249 return (AE_NO_MEMORY);
253 /*******************************************************************************
255 * FUNCTION: AcpiTbReleaseTempTable
257 * PARAMETERS: TableDesc - Table descriptor to be released
259 * RETURN: Status
261 * DESCRIPTION: The inverse of AcpiTbAcquireTempTable().
263 *****************************************************************************/
265 void
266 AcpiTbReleaseTempTable (
267 ACPI_TABLE_DESC *TableDesc)
271 * Note that the .Address is maintained by the callers of
272 * AcpiTbAcquireTempTable(), thus do not invoke AcpiTbUninstallTable()
273 * where .Address will be freed.
275 AcpiTbInvalidateTable (TableDesc);
279 /******************************************************************************
281 * FUNCTION: AcpiTbValidateTable
283 * PARAMETERS: TableDesc - Table descriptor
285 * RETURN: Status
287 * DESCRIPTION: This function is called to validate the table, the returned
288 * table descriptor is in "VALIDATED" state.
290 *****************************************************************************/
292 ACPI_STATUS
293 AcpiTbValidateTable (
294 ACPI_TABLE_DESC *TableDesc)
296 ACPI_STATUS Status = AE_OK;
299 ACPI_FUNCTION_TRACE (TbValidateTable);
302 /* Validate the table if necessary */
304 if (!TableDesc->Pointer)
306 Status = AcpiTbAcquireTable (TableDesc, &TableDesc->Pointer,
307 &TableDesc->Length, &TableDesc->Flags);
308 if (!TableDesc->Pointer)
310 Status = AE_NO_MEMORY;
314 return_ACPI_STATUS (Status);
318 /*******************************************************************************
320 * FUNCTION: AcpiTbInvalidateTable
322 * PARAMETERS: TableDesc - Table descriptor
324 * RETURN: None
326 * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of
327 * AcpiTbValidateTable().
329 ******************************************************************************/
331 void
332 AcpiTbInvalidateTable (
333 ACPI_TABLE_DESC *TableDesc)
336 ACPI_FUNCTION_TRACE (TbInvalidateTable);
339 /* Table must be validated */
341 if (!TableDesc->Pointer)
343 return_VOID;
346 AcpiTbReleaseTable (TableDesc->Pointer, TableDesc->Length,
347 TableDesc->Flags);
348 TableDesc->Pointer = NULL;
350 return_VOID;
354 /******************************************************************************
356 * FUNCTION: AcpiTbValidateTempTable
358 * PARAMETERS: TableDesc - Table descriptor
360 * RETURN: Status
362 * DESCRIPTION: This function is called to validate the table, the returned
363 * table descriptor is in "VALIDATED" state.
365 *****************************************************************************/
367 ACPI_STATUS
368 AcpiTbValidateTempTable (
369 ACPI_TABLE_DESC *TableDesc)
372 if (!TableDesc->Pointer && !AcpiGbl_VerifyTableChecksum)
375 * Only validates the header of the table.
376 * Note that Length contains the size of the mapping after invoking
377 * this work around, this value is required by
378 * AcpiTbReleaseTempTable().
379 * We can do this because in AcpiInitTableDescriptor(), the Length
380 * field of the installed descriptor is filled with the actual
381 * table length obtaining from the table header.
383 TableDesc->Length = sizeof (ACPI_TABLE_HEADER);
386 return (AcpiTbValidateTable (TableDesc));
390 /******************************************************************************
392 * FUNCTION: AcpiTbVerifyTempTable
394 * PARAMETERS: TableDesc - Table descriptor
395 * Signature - Table signature to verify
397 * RETURN: Status
399 * DESCRIPTION: This function is called to validate and verify the table, the
400 * returned table descriptor is in "VALIDATED" state.
402 *****************************************************************************/
404 ACPI_STATUS
405 AcpiTbVerifyTempTable (
406 ACPI_TABLE_DESC *TableDesc,
407 char *Signature)
409 ACPI_STATUS Status = AE_OK;
412 ACPI_FUNCTION_TRACE (TbVerifyTempTable);
415 /* Validate the table */
417 Status = AcpiTbValidateTempTable (TableDesc);
418 if (ACPI_FAILURE (Status))
420 return_ACPI_STATUS (AE_NO_MEMORY);
423 /* If a particular signature is expected (DSDT/FACS), it must match */
425 if (Signature &&
426 !ACPI_COMPARE_NAME (&TableDesc->Signature, Signature))
428 ACPI_BIOS_ERROR ((AE_INFO,
429 "Invalid signature 0x%X for ACPI table, expected [%s]",
430 TableDesc->Signature.Integer, Signature));
431 Status = AE_BAD_SIGNATURE;
432 goto InvalidateAndExit;
435 /* Verify the checksum */
437 if (AcpiGbl_VerifyTableChecksum)
439 Status = AcpiTbVerifyChecksum (TableDesc->Pointer, TableDesc->Length);
440 if (ACPI_FAILURE (Status))
442 ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY,
443 "%4.4s 0x%8.8X%8.8X"
444 " Attempted table install failed",
445 AcpiUtValidNameseg (TableDesc->Signature.Ascii) ?
446 TableDesc->Signature.Ascii : "????",
447 ACPI_FORMAT_UINT64 (TableDesc->Address)));
449 goto InvalidateAndExit;
453 return_ACPI_STATUS (AE_OK);
455 InvalidateAndExit:
456 AcpiTbInvalidateTable (TableDesc);
457 return_ACPI_STATUS (Status);
461 /*******************************************************************************
463 * FUNCTION: AcpiTbResizeRootTableList
465 * PARAMETERS: None
467 * RETURN: Status
469 * DESCRIPTION: Expand the size of global table array
471 ******************************************************************************/
473 ACPI_STATUS
474 AcpiTbResizeRootTableList (
475 void)
477 ACPI_TABLE_DESC *Tables;
478 UINT32 TableCount;
481 ACPI_FUNCTION_TRACE (TbResizeRootTableList);
484 /* AllowResize flag is a parameter to AcpiInitializeTables */
486 if (!(AcpiGbl_RootTableList.Flags & ACPI_ROOT_ALLOW_RESIZE))
488 ACPI_ERROR ((AE_INFO, "Resize of Root Table Array is not allowed"));
489 return_ACPI_STATUS (AE_SUPPORT);
492 /* Increase the Table Array size */
494 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
496 TableCount = AcpiGbl_RootTableList.MaxTableCount;
498 else
500 TableCount = AcpiGbl_RootTableList.CurrentTableCount;
503 Tables = ACPI_ALLOCATE_ZEROED (
504 ((ACPI_SIZE) TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT) *
505 sizeof (ACPI_TABLE_DESC));
506 if (!Tables)
508 ACPI_ERROR ((AE_INFO, "Could not allocate new root table array"));
509 return_ACPI_STATUS (AE_NO_MEMORY);
512 /* Copy and free the previous table array */
514 if (AcpiGbl_RootTableList.Tables)
516 memcpy (Tables, AcpiGbl_RootTableList.Tables,
517 (ACPI_SIZE) TableCount * sizeof (ACPI_TABLE_DESC));
519 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
521 ACPI_FREE (AcpiGbl_RootTableList.Tables);
525 AcpiGbl_RootTableList.Tables = Tables;
526 AcpiGbl_RootTableList.MaxTableCount =
527 TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT;
528 AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
530 return_ACPI_STATUS (AE_OK);
534 /*******************************************************************************
536 * FUNCTION: AcpiTbGetNextTableDescriptor
538 * PARAMETERS: TableIndex - Where table index is returned
539 * TableDesc - Where table descriptor is returned
541 * RETURN: Status and table index/descriptor.
543 * DESCRIPTION: Allocate a new ACPI table entry to the global table list
545 ******************************************************************************/
547 ACPI_STATUS
548 AcpiTbGetNextTableDescriptor (
549 UINT32 *TableIndex,
550 ACPI_TABLE_DESC **TableDesc)
552 ACPI_STATUS Status;
553 UINT32 i;
556 /* Ensure that there is room for the table in the Root Table List */
558 if (AcpiGbl_RootTableList.CurrentTableCount >=
559 AcpiGbl_RootTableList.MaxTableCount)
561 Status = AcpiTbResizeRootTableList();
562 if (ACPI_FAILURE (Status))
564 return (Status);
568 i = AcpiGbl_RootTableList.CurrentTableCount;
569 AcpiGbl_RootTableList.CurrentTableCount++;
571 if (TableIndex)
573 *TableIndex = i;
575 if (TableDesc)
577 *TableDesc = &AcpiGbl_RootTableList.Tables[i];
580 return (AE_OK);
584 /*******************************************************************************
586 * FUNCTION: AcpiTbTerminate
588 * PARAMETERS: None
590 * RETURN: None
592 * DESCRIPTION: Delete all internal ACPI tables
594 ******************************************************************************/
596 void
597 AcpiTbTerminate (
598 void)
600 UINT32 i;
603 ACPI_FUNCTION_TRACE (TbTerminate);
606 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
608 /* Delete the individual tables */
610 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
612 AcpiTbUninstallTable (&AcpiGbl_RootTableList.Tables[i]);
616 * Delete the root table array if allocated locally. Array cannot be
617 * mapped, so we don't need to check for that flag.
619 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
621 ACPI_FREE (AcpiGbl_RootTableList.Tables);
624 AcpiGbl_RootTableList.Tables = NULL;
625 AcpiGbl_RootTableList.Flags = 0;
626 AcpiGbl_RootTableList.CurrentTableCount = 0;
628 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));
630 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
631 return_VOID;
635 /*******************************************************************************
637 * FUNCTION: AcpiTbDeleteNamespaceByOwner
639 * PARAMETERS: TableIndex - Table index
641 * RETURN: Status
643 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
645 ******************************************************************************/
647 ACPI_STATUS
648 AcpiTbDeleteNamespaceByOwner (
649 UINT32 TableIndex)
651 ACPI_OWNER_ID OwnerId;
652 ACPI_STATUS Status;
655 ACPI_FUNCTION_TRACE (TbDeleteNamespaceByOwner);
658 Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES);
659 if (ACPI_FAILURE (Status))
661 return_ACPI_STATUS (Status);
664 if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
666 /* The table index does not exist */
668 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
669 return_ACPI_STATUS (AE_NOT_EXIST);
672 /* Get the owner ID for this table, used to delete namespace nodes */
674 OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
675 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
678 * Need to acquire the namespace writer lock to prevent interference
679 * with any concurrent namespace walks. The interpreter must be
680 * released during the deletion since the acquisition of the deletion
681 * lock may block, and also since the execution of a namespace walk
682 * must be allowed to use the interpreter.
684 Status = AcpiUtAcquireWriteLock (&AcpiGbl_NamespaceRwLock);
685 if (ACPI_FAILURE (Status))
687 return_ACPI_STATUS (Status);
689 AcpiNsDeleteNamespaceByOwner (OwnerId);
690 AcpiUtReleaseWriteLock (&AcpiGbl_NamespaceRwLock);
691 return_ACPI_STATUS (Status);
695 /*******************************************************************************
697 * FUNCTION: AcpiTbAllocateOwnerId
699 * PARAMETERS: TableIndex - Table index
701 * RETURN: Status
703 * DESCRIPTION: Allocates OwnerId in TableDesc
705 ******************************************************************************/
707 ACPI_STATUS
708 AcpiTbAllocateOwnerId (
709 UINT32 TableIndex)
711 ACPI_STATUS Status = AE_BAD_PARAMETER;
714 ACPI_FUNCTION_TRACE (TbAllocateOwnerId);
717 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
718 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
720 Status = AcpiUtAllocateOwnerId (
721 &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
724 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
725 return_ACPI_STATUS (Status);
729 /*******************************************************************************
731 * FUNCTION: AcpiTbReleaseOwnerId
733 * PARAMETERS: TableIndex - Table index
735 * RETURN: Status
737 * DESCRIPTION: Releases OwnerId in TableDesc
739 ******************************************************************************/
741 ACPI_STATUS
742 AcpiTbReleaseOwnerId (
743 UINT32 TableIndex)
745 ACPI_STATUS Status = AE_BAD_PARAMETER;
748 ACPI_FUNCTION_TRACE (TbReleaseOwnerId);
751 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
752 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
754 AcpiUtReleaseOwnerId (
755 &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
756 Status = AE_OK;
759 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
760 return_ACPI_STATUS (Status);
764 /*******************************************************************************
766 * FUNCTION: AcpiTbGetOwnerId
768 * PARAMETERS: TableIndex - Table index
769 * OwnerId - Where the table OwnerId is returned
771 * RETURN: Status
773 * DESCRIPTION: returns OwnerId for the ACPI table
775 ******************************************************************************/
777 ACPI_STATUS
778 AcpiTbGetOwnerId (
779 UINT32 TableIndex,
780 ACPI_OWNER_ID *OwnerId)
782 ACPI_STATUS Status = AE_BAD_PARAMETER;
785 ACPI_FUNCTION_TRACE (TbGetOwnerId);
788 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
789 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
791 *OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
792 Status = AE_OK;
795 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
796 return_ACPI_STATUS (Status);
800 /*******************************************************************************
802 * FUNCTION: AcpiTbIsTableLoaded
804 * PARAMETERS: TableIndex - Index into the root table
806 * RETURN: Table Loaded Flag
808 ******************************************************************************/
810 BOOLEAN
811 AcpiTbIsTableLoaded (
812 UINT32 TableIndex)
814 BOOLEAN IsLoaded = FALSE;
817 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
818 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
820 IsLoaded = (BOOLEAN)
821 (AcpiGbl_RootTableList.Tables[TableIndex].Flags &
822 ACPI_TABLE_IS_LOADED);
825 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
826 return (IsLoaded);
830 /*******************************************************************************
832 * FUNCTION: AcpiTbSetTableLoadedFlag
834 * PARAMETERS: TableIndex - Table index
835 * IsLoaded - TRUE if table is loaded, FALSE otherwise
837 * RETURN: None
839 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
841 ******************************************************************************/
843 void
844 AcpiTbSetTableLoadedFlag (
845 UINT32 TableIndex,
846 BOOLEAN IsLoaded)
849 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
850 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
852 if (IsLoaded)
854 AcpiGbl_RootTableList.Tables[TableIndex].Flags |=
855 ACPI_TABLE_IS_LOADED;
857 else
859 AcpiGbl_RootTableList.Tables[TableIndex].Flags &=
860 ~ACPI_TABLE_IS_LOADED;
864 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
868 /*******************************************************************************
870 * FUNCTION: AcpiTbLoadTable
872 * PARAMETERS: TableIndex - Table index
873 * ParentNode - Where table index is returned
875 * RETURN: Status
877 * DESCRIPTION: Load an ACPI table
879 ******************************************************************************/
881 ACPI_STATUS
882 AcpiTbLoadTable (
883 UINT32 TableIndex,
884 ACPI_NAMESPACE_NODE *ParentNode)
886 ACPI_TABLE_HEADER *Table;
887 ACPI_STATUS Status;
888 ACPI_OWNER_ID OwnerId;
891 ACPI_FUNCTION_TRACE (TbLoadTable);
895 * Note: Now table is "INSTALLED", it must be validated before
896 * using.
898 Status = AcpiGetTableByIndex (TableIndex, &Table);
899 if (ACPI_FAILURE (Status))
901 return_ACPI_STATUS (Status);
904 Status = AcpiNsLoadTable (TableIndex, ParentNode);
906 /* Execute any module-level code that was found in the table */
908 if (!AcpiGbl_ParseTableAsTermList && AcpiGbl_GroupModuleLevelCode)
910 AcpiNsExecModuleCodeList ();
914 * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
915 * responsible for discovering any new wake GPEs by running _PRW methods
916 * that may have been loaded by this table.
918 Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
919 if (ACPI_SUCCESS (Status))
921 AcpiEvUpdateGpes (OwnerId);
924 /* Invoke table handler if present */
926 if (AcpiGbl_TableHandler)
928 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table,
929 AcpiGbl_TableHandlerContext);
932 return_ACPI_STATUS (Status);
936 /*******************************************************************************
938 * FUNCTION: AcpiTbInstallAndLoadTable
940 * PARAMETERS: Address - Physical address of the table
941 * Flags - Allocation flags of the table
942 * Override - Whether override should be performed
943 * TableIndex - Where table index is returned
945 * RETURN: Status
947 * DESCRIPTION: Install and load an ACPI table
949 ******************************************************************************/
951 ACPI_STATUS
952 AcpiTbInstallAndLoadTable (
953 ACPI_PHYSICAL_ADDRESS Address,
954 UINT8 Flags,
955 BOOLEAN Override,
956 UINT32 *TableIndex)
958 ACPI_STATUS Status;
959 UINT32 i;
962 ACPI_FUNCTION_TRACE (TbInstallAndLoadTable);
965 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
967 /* Install the table and load it into the namespace */
969 Status = AcpiTbInstallStandardTable (Address, Flags, TRUE,
970 Override, &i);
971 if (ACPI_FAILURE (Status))
973 goto UnlockAndExit;
976 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
977 Status = AcpiTbLoadTable (i, AcpiGbl_RootNode);
978 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
980 UnlockAndExit:
981 *TableIndex = i;
982 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
983 return_ACPI_STATUS (Status);
987 /*******************************************************************************
989 * FUNCTION: AcpiTbUnloadTable
991 * PARAMETERS: TableIndex - Table index
993 * RETURN: Status
995 * DESCRIPTION: Unload an ACPI table
997 ******************************************************************************/
999 ACPI_STATUS
1000 AcpiTbUnloadTable (
1001 UINT32 TableIndex)
1003 ACPI_STATUS Status = AE_OK;
1004 ACPI_TABLE_HEADER *Table;
1007 ACPI_FUNCTION_TRACE (TbUnloadTable);
1010 /* Ensure the table is still loaded */
1012 if (!AcpiTbIsTableLoaded (TableIndex))
1014 return_ACPI_STATUS (AE_NOT_EXIST);
1017 /* Invoke table handler if present */
1019 if (AcpiGbl_TableHandler)
1021 Status = AcpiGetTableByIndex (TableIndex, &Table);
1022 if (ACPI_SUCCESS (Status))
1024 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_UNLOAD, Table,
1025 AcpiGbl_TableHandlerContext);
1029 /* Delete the portion of the namespace owned by this table */
1031 Status = AcpiTbDeleteNamespaceByOwner (TableIndex);
1032 if (ACPI_FAILURE (Status))
1034 return_ACPI_STATUS (Status);
1037 (void) AcpiTbReleaseOwnerId (TableIndex);
1038 AcpiTbSetTableLoadedFlag (TableIndex, FALSE);
1039 return_ACPI_STATUS (Status);