63f5f29e17176556c98c481d9209e20919f332ae
[dragonfly.git] / sys / contrib / dev / acpica-unix / tables / tbinstal.c
1 /******************************************************************************
2  *
3  * Module Name: tbinstal - ACPI table installation and removal
4  *
5  *****************************************************************************/
6
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
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
19  * property rights.
20  *
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
27  *
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;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
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.
53  *
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
64  * make.
65  *
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
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
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.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
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
88  * PARTICULAR PURPOSE.
89  *
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
97  * LIMITED REMEDY.
98  *
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.
113  *
114  *****************************************************************************/
115
116
117 #define __TBINSTAL_C__
118
119 #include "acpi.h"
120 #include "accommon.h"
121 #include "acnamesp.h"
122 #include "actables.h"
123
124
125 #define _COMPONENT          ACPI_TABLES
126         ACPI_MODULE_NAME    ("tbinstal")
127
128
129 /******************************************************************************
130  *
131  * FUNCTION:    AcpiTbVerifyTable
132  *
133  * PARAMETERS:  TableDesc           - table
134  *
135  * RETURN:      Status
136  *
137  * DESCRIPTION: this function is called to verify and map table
138  *
139  *****************************************************************************/
140
141 ACPI_STATUS
142 AcpiTbVerifyTable (
143     ACPI_TABLE_DESC         *TableDesc)
144 {
145     ACPI_STATUS             Status = AE_OK;
146
147
148     ACPI_FUNCTION_TRACE (TbVerifyTable);
149
150
151     /* Map the table if necessary */
152
153     if (!TableDesc->Pointer)
154     {
155         if ((TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK) ==
156             ACPI_TABLE_ORIGIN_MAPPED)
157         {
158             TableDesc->Pointer = AcpiOsMapMemory (
159                 TableDesc->Address, TableDesc->Length);
160         }
161
162         if (!TableDesc->Pointer)
163         {
164             return_ACPI_STATUS (AE_NO_MEMORY);
165         }
166     }
167
168     /* FACS is the odd table, has no standard ACPI header and no checksum */
169
170     if (!ACPI_COMPARE_NAME (&TableDesc->Signature, ACPI_SIG_FACS))
171     {
172         /* Always calculate checksum, ignore bad checksum if requested */
173
174         Status = AcpiTbVerifyChecksum (TableDesc->Pointer, TableDesc->Length);
175     }
176
177     return_ACPI_STATUS (Status);
178 }
179
180
181 /*******************************************************************************
182  *
183  * FUNCTION:    AcpiTbAddTable
184  *
185  * PARAMETERS:  TableDesc           - Table descriptor
186  *              TableIndex          - Where the table index is returned
187  *
188  * RETURN:      Status
189  *
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
192  *              operators.
193  *
194  ******************************************************************************/
195
196 ACPI_STATUS
197 AcpiTbAddTable (
198     ACPI_TABLE_DESC         *TableDesc,
199     UINT32                  *TableIndex)
200 {
201     UINT32                  i;
202     ACPI_STATUS             Status = AE_OK;
203     ACPI_TABLE_HEADER       *OverrideTable = NULL;
204
205
206     ACPI_FUNCTION_TRACE (TbAddTable);
207
208
209     if (!TableDesc->Pointer)
210     {
211         Status = AcpiTbVerifyTable (TableDesc);
212         if (ACPI_FAILURE (Status) || !TableDesc->Pointer)
213         {
214             return_ACPI_STATUS (Status);
215         }
216     }
217
218     /*
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).
224      */
225
226     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
227
228     /* Check if table is already registered */
229
230     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
231     {
232         if (!AcpiGbl_RootTableList.Tables[i].Pointer)
233         {
234             Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[i]);
235             if (ACPI_FAILURE (Status) ||
236                 !AcpiGbl_RootTableList.Tables[i].Pointer)
237             {
238                 continue;
239             }
240         }
241
242         /*
243          * Check for a table match on the entire table length,
244          * not just the header.
245          */
246         if (TableDesc->Length != AcpiGbl_RootTableList.Tables[i].Length)
247         {
248             continue;
249         }
250
251         if (ACPI_MEMCMP (TableDesc->Pointer,
252                 AcpiGbl_RootTableList.Tables[i].Pointer,
253                 AcpiGbl_RootTableList.Tables[i].Length))
254         {
255             continue;
256         }
257
258         /*
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.
262          *
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.
266          *
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.
271          */
272
273         /*
274          * Table is already registered.
275          * We can delete the table that was passed as a parameter.
276          */
277         AcpiTbDeleteTable (TableDesc);
278         *TableIndex = i;
279
280         if (AcpiGbl_RootTableList.Tables[i].Flags & ACPI_TABLE_IS_LOADED)
281         {
282             /* Table is still loaded, this is an error */
283
284             Status = AE_ALREADY_EXISTS;
285             goto Release;
286         }
287         else
288         {
289             /* Table was unloaded, allow it to be reloaded */
290
291             TableDesc->Pointer = AcpiGbl_RootTableList.Tables[i].Pointer;
292             TableDesc->Address = AcpiGbl_RootTableList.Tables[i].Address;
293             Status = AE_OK;
294             goto PrintHeader;
295         }
296     }
297
298     /*
299      * ACPI Table Override:
300      * Allow the host to override dynamically loaded tables.
301      */
302     Status = AcpiOsTableOverride (TableDesc->Pointer, &OverrideTable);
303     if (ACPI_SUCCESS (Status) && OverrideTable)
304     {
305         ACPI_INFO ((AE_INFO,
306             "%4.4s @ 0x%p Table override, replaced with:",
307             TableDesc->Pointer->Signature,
308             ACPI_CAST_PTR (void, TableDesc->Address)));
309
310         /* We can delete the table that was passed as a parameter */
311
312         AcpiTbDeleteTable (TableDesc);
313
314         /* Setup descriptor for the new table */
315
316         TableDesc->Address = ACPI_PTR_TO_PHYSADDR (OverrideTable);
317         TableDesc->Pointer = OverrideTable;
318         TableDesc->Length = OverrideTable->Length;
319         TableDesc->Flags = ACPI_TABLE_ORIGIN_OVERRIDE;
320     }
321
322     /* Add the table to the global root table list */
323
324     Status = AcpiTbStoreTable (TableDesc->Address, TableDesc->Pointer,
325                 TableDesc->Length, TableDesc->Flags, TableIndex);
326     if (ACPI_FAILURE (Status))
327     {
328         goto Release;
329     }
330
331 PrintHeader:
332     AcpiTbPrintTableHeader (TableDesc->Address, TableDesc->Pointer);
333
334 Release:
335     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
336     return_ACPI_STATUS (Status);
337 }
338
339
340 /*******************************************************************************
341  *
342  * FUNCTION:    AcpiTbResizeRootTableList
343  *
344  * PARAMETERS:  None
345  *
346  * RETURN:      Status
347  *
348  * DESCRIPTION: Expand the size of global table array
349  *
350  ******************************************************************************/
351
352 ACPI_STATUS
353 AcpiTbResizeRootTableList (
354     void)
355 {
356     ACPI_TABLE_DESC         *Tables;
357
358
359     ACPI_FUNCTION_TRACE (TbResizeRootTableList);
360
361
362     /* AllowResize flag is a parameter to AcpiInitializeTables */
363
364     if (!(AcpiGbl_RootTableList.Flags & ACPI_ROOT_ALLOW_RESIZE))
365     {
366         ACPI_ERROR ((AE_INFO, "Resize of Root Table Array is not allowed"));
367         return_ACPI_STATUS (AE_SUPPORT);
368     }
369
370     /* Increase the Table Array size */
371
372     Tables = ACPI_ALLOCATE_ZEROED (
373         ((ACPI_SIZE) AcpiGbl_RootTableList.MaxTableCount +
374             ACPI_ROOT_TABLE_SIZE_INCREMENT) *
375         sizeof (ACPI_TABLE_DESC));
376     if (!Tables)
377     {
378         ACPI_ERROR ((AE_INFO, "Could not allocate new root table array"));
379         return_ACPI_STATUS (AE_NO_MEMORY);
380     }
381
382     /* Copy and free the previous table array */
383
384     if (AcpiGbl_RootTableList.Tables)
385     {
386         ACPI_MEMCPY (Tables, AcpiGbl_RootTableList.Tables,
387             (ACPI_SIZE) AcpiGbl_RootTableList.MaxTableCount * sizeof (ACPI_TABLE_DESC));
388
389         if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
390         {
391             ACPI_FREE (AcpiGbl_RootTableList.Tables);
392         }
393     }
394
395     AcpiGbl_RootTableList.Tables = Tables;
396     AcpiGbl_RootTableList.MaxTableCount += ACPI_ROOT_TABLE_SIZE_INCREMENT;
397     AcpiGbl_RootTableList.Flags |= (UINT8) ACPI_ROOT_ORIGIN_ALLOCATED;
398
399     return_ACPI_STATUS (AE_OK);
400 }
401
402
403 /*******************************************************************************
404  *
405  * FUNCTION:    AcpiTbStoreTable
406  *
407  * PARAMETERS:  Address             - Table address
408  *              Table               - Table header
409  *              Length              - Table length
410  *              Flags               - flags
411  *
412  * RETURN:      Status and table index.
413  *
414  * DESCRIPTION: Add an ACPI table to the global table list
415  *
416  ******************************************************************************/
417
418 ACPI_STATUS
419 AcpiTbStoreTable (
420     ACPI_PHYSICAL_ADDRESS   Address,
421     ACPI_TABLE_HEADER       *Table,
422     UINT32                  Length,
423     UINT8                   Flags,
424     UINT32                  *TableIndex)
425 {
426     ACPI_STATUS             Status;
427     ACPI_TABLE_DESC         *NewTable;
428
429
430     /* Ensure that there is room for the table in the Root Table List */
431
432     if (AcpiGbl_RootTableList.CurrentTableCount >=
433         AcpiGbl_RootTableList.MaxTableCount)
434     {
435         Status = AcpiTbResizeRootTableList();
436         if (ACPI_FAILURE (Status))
437         {
438             return (Status);
439         }
440     }
441
442     NewTable = &AcpiGbl_RootTableList.Tables[AcpiGbl_RootTableList.CurrentTableCount];
443
444     /* Initialize added table */
445
446     NewTable->Address = Address;
447     NewTable->Pointer = Table;
448     NewTable->Length = Length;
449     NewTable->OwnerId = 0;
450     NewTable->Flags = Flags;
451
452     ACPI_MOVE_32_TO_32 (&NewTable->Signature, Table->Signature);
453
454     *TableIndex = AcpiGbl_RootTableList.CurrentTableCount;
455     AcpiGbl_RootTableList.CurrentTableCount++;
456     return (AE_OK);
457 }
458
459
460 /*******************************************************************************
461  *
462  * FUNCTION:    AcpiTbDeleteTable
463  *
464  * PARAMETERS:  TableIndex          - Table index
465  *
466  * RETURN:      None
467  *
468  * DESCRIPTION: Delete one internal ACPI table
469  *
470  ******************************************************************************/
471
472 void
473 AcpiTbDeleteTable (
474     ACPI_TABLE_DESC         *TableDesc)
475 {
476
477     /* Table must be mapped or allocated */
478
479     if (!TableDesc->Pointer)
480     {
481         return;
482     }
483
484     switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)
485     {
486     case ACPI_TABLE_ORIGIN_MAPPED:
487         AcpiOsUnmapMemory (TableDesc->Pointer, TableDesc->Length);
488         break;
489
490     case ACPI_TABLE_ORIGIN_ALLOCATED:
491         ACPI_FREE (TableDesc->Pointer);
492         break;
493
494     default:
495         break;
496     }
497
498     TableDesc->Pointer = NULL;
499 }
500
501
502 /*******************************************************************************
503  *
504  * FUNCTION:    AcpiTbTerminate
505  *
506  * PARAMETERS:  None
507  *
508  * RETURN:      None
509  *
510  * DESCRIPTION: Delete all internal ACPI tables
511  *
512  ******************************************************************************/
513
514 void
515 AcpiTbTerminate (
516     void)
517 {
518     UINT32                  i;
519
520
521     ACPI_FUNCTION_TRACE (TbTerminate);
522
523
524     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
525
526     /* Delete the individual tables */
527
528     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
529     {
530         AcpiTbDeleteTable (&AcpiGbl_RootTableList.Tables[i]);
531     }
532
533     /*
534      * Delete the root table array if allocated locally. Array cannot be
535      * mapped, so we don't need to check for that flag.
536      */
537     if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
538     {
539         ACPI_FREE (AcpiGbl_RootTableList.Tables);
540     }
541
542     AcpiGbl_RootTableList.Tables = NULL;
543     AcpiGbl_RootTableList.Flags = 0;
544     AcpiGbl_RootTableList.CurrentTableCount = 0;
545
546     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));
547     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
548 }
549
550
551 /*******************************************************************************
552  *
553  * FUNCTION:    AcpiTbDeleteNamespaceByOwner
554  *
555  * PARAMETERS:  TableIndex          - Table index
556  *
557  * RETURN:      Status
558  *
559  * DESCRIPTION: Delete all namespace objects created when this table was loaded.
560  *
561  ******************************************************************************/
562
563 ACPI_STATUS
564 AcpiTbDeleteNamespaceByOwner (
565     UINT32                  TableIndex)
566 {
567     ACPI_OWNER_ID           OwnerId;
568     ACPI_STATUS             Status;
569
570
571     ACPI_FUNCTION_TRACE (TbDeleteNamespaceByOwner);
572
573
574     Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES);
575     if (ACPI_FAILURE (Status))
576     {
577         return_ACPI_STATUS (Status);
578     }
579
580     if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
581     {
582         /* The table index does not exist */
583
584         (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
585         return_ACPI_STATUS (AE_NOT_EXIST);
586     }
587
588     /* Get the owner ID for this table, used to delete namespace nodes */
589
590     OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
591     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
592
593     /*
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.
599      */
600     (void) AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);
601     Status = AcpiUtAcquireWriteLock (&AcpiGbl_NamespaceRwLock);
602
603     AcpiNsDeleteNamespaceByOwner (OwnerId);
604     if (ACPI_FAILURE (Status))
605     {
606         return_ACPI_STATUS (Status);
607     }
608
609     AcpiUtReleaseWriteLock (&AcpiGbl_NamespaceRwLock);
610
611     Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);
612     return_ACPI_STATUS (Status);
613 }
614
615
616 /*******************************************************************************
617  *
618  * FUNCTION:    AcpiTbAllocateOwnerId
619  *
620  * PARAMETERS:  TableIndex          - Table index
621  *
622  * RETURN:      Status
623  *
624  * DESCRIPTION: Allocates OwnerId in TableDesc
625  *
626  ******************************************************************************/
627
628 ACPI_STATUS
629 AcpiTbAllocateOwnerId (
630     UINT32                  TableIndex)
631 {
632     ACPI_STATUS             Status = AE_BAD_PARAMETER;
633
634
635     ACPI_FUNCTION_TRACE (TbAllocateOwnerId);
636
637
638     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
639     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
640     {
641         Status = AcpiUtAllocateOwnerId
642                     (&(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
643     }
644
645     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
646     return_ACPI_STATUS (Status);
647 }
648
649
650 /*******************************************************************************
651  *
652  * FUNCTION:    AcpiTbReleaseOwnerId
653  *
654  * PARAMETERS:  TableIndex          - Table index
655  *
656  * RETURN:      Status
657  *
658  * DESCRIPTION: Releases OwnerId in TableDesc
659  *
660  ******************************************************************************/
661
662 ACPI_STATUS
663 AcpiTbReleaseOwnerId (
664     UINT32                  TableIndex)
665 {
666     ACPI_STATUS             Status = AE_BAD_PARAMETER;
667
668
669     ACPI_FUNCTION_TRACE (TbReleaseOwnerId);
670
671
672     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
673     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
674     {
675         AcpiUtReleaseOwnerId (
676             &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
677         Status = AE_OK;
678     }
679
680     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
681     return_ACPI_STATUS (Status);
682 }
683
684
685 /*******************************************************************************
686  *
687  * FUNCTION:    AcpiTbGetOwnerId
688  *
689  * PARAMETERS:  TableIndex          - Table index
690  *              OwnerId             - Where the table OwnerId is returned
691  *
692  * RETURN:      Status
693  *
694  * DESCRIPTION: returns OwnerId for the ACPI table
695  *
696  ******************************************************************************/
697
698 ACPI_STATUS
699 AcpiTbGetOwnerId (
700     UINT32                  TableIndex,
701     ACPI_OWNER_ID           *OwnerId)
702 {
703     ACPI_STATUS             Status = AE_BAD_PARAMETER;
704
705
706     ACPI_FUNCTION_TRACE (TbGetOwnerId);
707
708
709     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
710     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
711     {
712         *OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
713         Status = AE_OK;
714     }
715
716     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
717     return_ACPI_STATUS (Status);
718 }
719
720
721 /*******************************************************************************
722  *
723  * FUNCTION:    AcpiTbIsTableLoaded
724  *
725  * PARAMETERS:  TableIndex          - Table index
726  *
727  * RETURN:      Table Loaded Flag
728  *
729  ******************************************************************************/
730
731 BOOLEAN
732 AcpiTbIsTableLoaded (
733     UINT32                  TableIndex)
734 {
735     BOOLEAN                 IsLoaded = FALSE;
736
737
738     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
739     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
740     {
741         IsLoaded = (BOOLEAN)
742             (AcpiGbl_RootTableList.Tables[TableIndex].Flags &
743             ACPI_TABLE_IS_LOADED);
744     }
745
746     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
747     return (IsLoaded);
748 }
749
750
751 /*******************************************************************************
752  *
753  * FUNCTION:    AcpiTbSetTableLoadedFlag
754  *
755  * PARAMETERS:  TableIndex          - Table index
756  *              IsLoaded            - TRUE if table is loaded, FALSE otherwise
757  *
758  * RETURN:      None
759  *
760  * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
761  *
762  ******************************************************************************/
763
764 void
765 AcpiTbSetTableLoadedFlag (
766     UINT32                  TableIndex,
767     BOOLEAN                 IsLoaded)
768 {
769
770     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
771     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
772     {
773         if (IsLoaded)
774         {
775             AcpiGbl_RootTableList.Tables[TableIndex].Flags |=
776                 ACPI_TABLE_IS_LOADED;
777         }
778         else
779         {
780             AcpiGbl_RootTableList.Tables[TableIndex].Flags &=
781                 ~ACPI_TABLE_IS_LOADED;
782         }
783     }
784
785     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
786 }
787