xref: /haiku/src/add-ons/kernel/bus_managers/acpi/acpica/components/tables/tbdata.c (revision d64b771b96050fca8ff1859daa5ec44ff3493af7)
1 /******************************************************************************
2  *
3  * Module Name: tbdata - Table manager data structure functions
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2014, 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 #define __TBDATA_C__
117 
118 #include "acpi.h"
119 #include "accommon.h"
120 #include "acnamesp.h"
121 #include "actables.h"
122 
123 #define _COMPONENT          ACPI_TABLES
124         ACPI_MODULE_NAME    ("tbdata")
125 
126 
127 /*******************************************************************************
128  *
129  * FUNCTION:    AcpiTbInitTableDescriptor
130  *
131  * PARAMETERS:  TableDesc               - Table descriptor
132  *              Address                 - Physical address of the table
133  *              Flags                   - Allocation flags of the table
134  *              Table                   - Pointer to the table
135  *
136  * RETURN:      None
137  *
138  * DESCRIPTION: Initialize a new table descriptor
139  *
140  ******************************************************************************/
141 
142 void
143 AcpiTbInitTableDescriptor (
144     ACPI_TABLE_DESC         *TableDesc,
145     ACPI_PHYSICAL_ADDRESS   Address,
146     UINT8                   Flags,
147     ACPI_TABLE_HEADER       *Table)
148 {
149 
150     /*
151      * Initialize the table descriptor. Set the pointer to NULL, since the
152      * table is not fully mapped at this time.
153      */
154     ACPI_MEMSET (TableDesc, 0, sizeof (ACPI_TABLE_DESC));
155     TableDesc->Address = Address;
156     TableDesc->Length = Table->Length;
157     TableDesc->Flags = Flags;
158     ACPI_MOVE_32_TO_32 (TableDesc->Signature.Ascii, Table->Signature);
159 }
160 
161 
162 /*******************************************************************************
163  *
164  * FUNCTION:    AcpiTbAcquireTable
165  *
166  * PARAMETERS:  TableDesc           - Table descriptor
167  *              TablePtr            - Where table is returned
168  *              TableLength         - Where table length is returned
169  *              TableFlags          - Where table allocation flags are returned
170  *
171  * RETURN:      Status
172  *
173  * DESCRIPTION: Acquire an ACPI table. It can be used for tables not
174  *              maintained in the AcpiGbl_RootTableList.
175  *
176  ******************************************************************************/
177 
178 ACPI_STATUS
179 AcpiTbAcquireTable (
180     ACPI_TABLE_DESC         *TableDesc,
181     ACPI_TABLE_HEADER       **TablePtr,
182     UINT32                  *TableLength,
183     UINT8                   *TableFlags)
184 {
185     ACPI_TABLE_HEADER       *Table = NULL;
186 
187 
188     switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)
189     {
190     case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
191 
192         Table = AcpiOsMapMemory (TableDesc->Address, TableDesc->Length);
193         break;
194 
195     case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
196     case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
197 
198         Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, TableDesc->Address);
199         break;
200 
201     default:
202 
203         break;
204     }
205 
206     /* Table is not valid yet */
207 
208     if (!Table)
209     {
210         return (AE_NO_MEMORY);
211     }
212 
213     /* Fill the return values */
214 
215     *TablePtr = Table;
216     *TableLength = TableDesc->Length;
217     *TableFlags = TableDesc->Flags;
218     return (AE_OK);
219 }
220 
221 
222 /*******************************************************************************
223  *
224  * FUNCTION:    AcpiTbReleaseTable
225  *
226  * PARAMETERS:  Table               - Pointer for the table
227  *              TableLength         - Length for the table
228  *              TableFlags          - Allocation flags for the table
229  *
230  * RETURN:      None
231  *
232  * DESCRIPTION: Release a table. The inverse of AcpiTbAcquireTable().
233  *
234  ******************************************************************************/
235 
236 void
237 AcpiTbReleaseTable (
238     ACPI_TABLE_HEADER       *Table,
239     UINT32                  TableLength,
240     UINT8                   TableFlags)
241 {
242 
243     switch (TableFlags & ACPI_TABLE_ORIGIN_MASK)
244     {
245     case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
246 
247         AcpiOsUnmapMemory (Table, TableLength);
248         break;
249 
250     case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
251     case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
252     default:
253 
254         break;
255     }
256 }
257 
258 
259 /*******************************************************************************
260  *
261  * FUNCTION:    AcpiTbAcquireTempTable
262  *
263  * PARAMETERS:  TableDesc           - Table descriptor to be acquired
264  *              Address             - Address of the table
265  *              Flags               - Allocation flags of the table
266  *
267  * RETURN:      Status
268  *
269  * DESCRIPTION: This function validates the table header to obtain the length
270  *              of a table and fills the table descriptor to make its state as
271  *              "INSTALLED". Such a table descriptor is only used for verified
272  *              installation.
273  *
274  ******************************************************************************/
275 
276 ACPI_STATUS
277 AcpiTbAcquireTempTable (
278     ACPI_TABLE_DESC         *TableDesc,
279     ACPI_PHYSICAL_ADDRESS   Address,
280     UINT8                   Flags)
281 {
282     ACPI_TABLE_HEADER       *TableHeader;
283 
284 
285     switch (Flags & ACPI_TABLE_ORIGIN_MASK)
286     {
287     case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
288 
289         /* Get the length of the full table from the header */
290 
291         TableHeader = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
292         if (!TableHeader)
293         {
294             return (AE_NO_MEMORY);
295         }
296 
297         AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
298         AcpiOsUnmapMemory (TableHeader, sizeof (ACPI_TABLE_HEADER));
299         return (AE_OK);
300 
301     case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
302     case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
303 
304         TableHeader = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Address);
305         if (!TableHeader)
306         {
307             return (AE_NO_MEMORY);
308         }
309 
310         AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
311         return (AE_OK);
312 
313     default:
314 
315         break;
316     }
317 
318     /* Table is not valid yet */
319 
320     return (AE_NO_MEMORY);
321 }
322 
323 
324 /*******************************************************************************
325  *
326  * FUNCTION:    AcpiTbReleaseTempTable
327  *
328  * PARAMETERS:  TableDesc           - Table descriptor to be released
329  *
330  * RETURN:      Status
331  *
332  * DESCRIPTION: The inverse of AcpiTbAcquireTempTable().
333  *
334  *****************************************************************************/
335 
336 void
337 AcpiTbReleaseTempTable (
338     ACPI_TABLE_DESC         *TableDesc)
339 {
340 
341     /*
342      * Note that the .Address is maintained by the callers of
343      * AcpiTbAcquireTempTable(), thus do not invoke AcpiTbUninstallTable()
344      * where .Address will be freed.
345      */
346     AcpiTbInvalidateTable (TableDesc);
347 }
348 
349 
350 /******************************************************************************
351  *
352  * FUNCTION:    AcpiTbValidateTable
353  *
354  * PARAMETERS:  TableDesc           - Table descriptor
355  *
356  * RETURN:      Status
357  *
358  * DESCRIPTION: This function is called to validate the table, the returned
359  *              table descriptor is in "VALIDATED" state.
360  *
361  *****************************************************************************/
362 
363 ACPI_STATUS
364 AcpiTbValidateTable (
365     ACPI_TABLE_DESC         *TableDesc)
366 {
367     ACPI_STATUS             Status = AE_OK;
368 
369 
370     ACPI_FUNCTION_TRACE (TbValidateTable);
371 
372 
373     /* Validate the table if necessary */
374 
375     if (!TableDesc->Pointer)
376     {
377         Status = AcpiTbAcquireTable (TableDesc, &TableDesc->Pointer,
378                     &TableDesc->Length, &TableDesc->Flags);
379         if (!TableDesc->Pointer)
380         {
381             Status = AE_NO_MEMORY;
382         }
383     }
384 
385     return_ACPI_STATUS (Status);
386 }
387 
388 
389 /*******************************************************************************
390  *
391  * FUNCTION:    AcpiTbInvalidateTable
392  *
393  * PARAMETERS:  TableDesc           - Table descriptor
394  *
395  * RETURN:      None
396  *
397  * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of
398  *              AcpiTbValidateTable().
399  *
400  ******************************************************************************/
401 
402 void
403 AcpiTbInvalidateTable (
404     ACPI_TABLE_DESC         *TableDesc)
405 {
406 
407     ACPI_FUNCTION_TRACE (TbInvalidateTable);
408 
409 
410     /* Table must be validated */
411 
412     if (!TableDesc->Pointer)
413     {
414         return_VOID;
415     }
416 
417     AcpiTbReleaseTable (TableDesc->Pointer, TableDesc->Length,
418         TableDesc->Flags);
419     TableDesc->Pointer = NULL;
420 
421     return_VOID;
422 }
423 
424 
425 /******************************************************************************
426  *
427  * FUNCTION:    AcpiTbValidateTempTable
428  *
429  * PARAMETERS:  TableDesc           - Table descriptor
430  *
431  * RETURN:      Status
432  *
433  * DESCRIPTION: This function is called to validate the table, the returned
434  *              table descriptor is in "VALIDATED" state.
435  *
436  *****************************************************************************/
437 
438 ACPI_STATUS
439 AcpiTbValidateTempTable (
440     ACPI_TABLE_DESC         *TableDesc)
441 {
442 
443     if (!TableDesc->Pointer && !AcpiGbl_VerifyTableChecksum)
444     {
445         /*
446          * Only validates the header of the table.
447          * Note that Length contains the size of the mapping after invoking
448          * this work around, this value is required by
449          * AcpiTbReleaseTempTable().
450          * We can do this because in AcpiInitTableDescriptor(), the Length
451          * field of the installed descriptor is filled with the actual
452          * table length obtaining from the table header.
453          */
454         TableDesc->Length = sizeof (ACPI_TABLE_HEADER);
455     }
456 
457     return (AcpiTbValidateTable (TableDesc));
458 }
459 
460 
461 /******************************************************************************
462  *
463  * FUNCTION:    AcpiTbVerifyTempTable
464  *
465  * PARAMETERS:  TableDesc           - Table descriptor
466  *              Signature           - Table signature to verify
467  *
468  * RETURN:      Status
469  *
470  * DESCRIPTION: This function is called to validate and verify the table, the
471  *              returned table descriptor is in "VALIDATED" state.
472  *
473  *****************************************************************************/
474 
475 ACPI_STATUS
476 AcpiTbVerifyTempTable (
477     ACPI_TABLE_DESC         *TableDesc,
478     char                    *Signature)
479 {
480     ACPI_STATUS             Status = AE_OK;
481 
482 
483     ACPI_FUNCTION_TRACE (TbVerifyTempTable);
484 
485 
486     /* Validate the table */
487 
488     Status = AcpiTbValidateTempTable (TableDesc);
489     if (ACPI_FAILURE (Status))
490     {
491         return_ACPI_STATUS (AE_NO_MEMORY);
492     }
493 
494     /* If a particular signature is expected (DSDT/FACS), it must match */
495 
496     if (Signature &&
497         !ACPI_COMPARE_NAME (&TableDesc->Signature, Signature))
498     {
499         ACPI_BIOS_ERROR ((AE_INFO,
500             "Invalid signature 0x%X for ACPI table, expected [%s]",
501             TableDesc->Signature.Integer, Signature));
502         Status = AE_BAD_SIGNATURE;
503         goto InvalidateAndExit;
504     }
505 
506     /* Verify the checksum */
507 
508     if (AcpiGbl_VerifyTableChecksum)
509     {
510         Status = AcpiTbVerifyChecksum (TableDesc->Pointer, TableDesc->Length);
511         if (ACPI_FAILURE (Status))
512         {
513             ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY,
514                 "%4.4s " ACPI_PRINTF_UINT
515                 " Attempted table install failed",
516                 AcpiUtValidAcpiName (TableDesc->Signature.Ascii) ?
517                     TableDesc->Signature.Ascii : "????",
518                 ACPI_FORMAT_TO_UINT (TableDesc->Address)));
519             goto InvalidateAndExit;
520         }
521     }
522 
523     return_ACPI_STATUS (AE_OK);
524 
525 InvalidateAndExit:
526     AcpiTbInvalidateTable (TableDesc);
527     return_ACPI_STATUS (Status);
528 }
529 
530 
531 /*******************************************************************************
532  *
533  * FUNCTION:    AcpiTbResizeRootTableList
534  *
535  * PARAMETERS:  None
536  *
537  * RETURN:      Status
538  *
539  * DESCRIPTION: Expand the size of global table array
540  *
541  ******************************************************************************/
542 
543 ACPI_STATUS
544 AcpiTbResizeRootTableList (
545     void)
546 {
547     ACPI_TABLE_DESC         *Tables;
548     UINT32                  TableCount;
549 
550 
551     ACPI_FUNCTION_TRACE (TbResizeRootTableList);
552 
553 
554     /* AllowResize flag is a parameter to AcpiInitializeTables */
555 
556     if (!(AcpiGbl_RootTableList.Flags & ACPI_ROOT_ALLOW_RESIZE))
557     {
558         ACPI_ERROR ((AE_INFO, "Resize of Root Table Array is not allowed"));
559         return_ACPI_STATUS (AE_SUPPORT);
560     }
561 
562     /* Increase the Table Array size */
563 
564     if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
565     {
566         TableCount = AcpiGbl_RootTableList.MaxTableCount;
567     }
568     else
569     {
570         TableCount = AcpiGbl_RootTableList.CurrentTableCount;
571     }
572 
573     Tables = ACPI_ALLOCATE_ZEROED (
574         ((ACPI_SIZE) TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT) *
575         sizeof (ACPI_TABLE_DESC));
576     if (!Tables)
577     {
578         ACPI_ERROR ((AE_INFO, "Could not allocate new root table array"));
579         return_ACPI_STATUS (AE_NO_MEMORY);
580     }
581 
582     /* Copy and free the previous table array */
583 
584     if (AcpiGbl_RootTableList.Tables)
585     {
586         ACPI_MEMCPY (Tables, AcpiGbl_RootTableList.Tables,
587             (ACPI_SIZE) TableCount * sizeof (ACPI_TABLE_DESC));
588 
589         if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
590         {
591             ACPI_FREE (AcpiGbl_RootTableList.Tables);
592         }
593     }
594 
595     AcpiGbl_RootTableList.Tables = Tables;
596     AcpiGbl_RootTableList.MaxTableCount =
597         TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT;
598     AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
599 
600     return_ACPI_STATUS (AE_OK);
601 }
602 
603 
604 /*******************************************************************************
605  *
606  * FUNCTION:    AcpiTbGetNextRootIndex
607  *
608  * PARAMETERS:  TableIndex          - Where table index is returned
609  *
610  * RETURN:      Status and table index.
611  *
612  * DESCRIPTION: Allocate a new ACPI table entry to the global table list
613  *
614  ******************************************************************************/
615 
616 ACPI_STATUS
617 AcpiTbGetNextRootIndex (
618     UINT32                  *TableIndex)
619 {
620     ACPI_STATUS             Status;
621 
622 
623     /* Ensure that there is room for the table in the Root Table List */
624 
625     if (AcpiGbl_RootTableList.CurrentTableCount >=
626         AcpiGbl_RootTableList.MaxTableCount)
627     {
628         Status = AcpiTbResizeRootTableList();
629         if (ACPI_FAILURE (Status))
630         {
631             return (Status);
632         }
633     }
634 
635     *TableIndex = AcpiGbl_RootTableList.CurrentTableCount;
636     AcpiGbl_RootTableList.CurrentTableCount++;
637     return (AE_OK);
638 }
639 
640 
641 /*******************************************************************************
642  *
643  * FUNCTION:    AcpiTbTerminate
644  *
645  * PARAMETERS:  None
646  *
647  * RETURN:      None
648  *
649  * DESCRIPTION: Delete all internal ACPI tables
650  *
651  ******************************************************************************/
652 
653 void
654 AcpiTbTerminate (
655     void)
656 {
657     UINT32                  i;
658 
659 
660     ACPI_FUNCTION_TRACE (TbTerminate);
661 
662 
663     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
664 
665     /* Delete the individual tables */
666 
667     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
668     {
669         AcpiTbUninstallTable (&AcpiGbl_RootTableList.Tables[i]);
670     }
671 
672     /*
673      * Delete the root table array if allocated locally. Array cannot be
674      * mapped, so we don't need to check for that flag.
675      */
676     if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
677     {
678         ACPI_FREE (AcpiGbl_RootTableList.Tables);
679     }
680 
681     AcpiGbl_RootTableList.Tables = NULL;
682     AcpiGbl_RootTableList.Flags = 0;
683     AcpiGbl_RootTableList.CurrentTableCount = 0;
684 
685     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));
686 
687     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
688     return_VOID;
689 }
690 
691 
692 /*******************************************************************************
693  *
694  * FUNCTION:    AcpiTbDeleteNamespaceByOwner
695  *
696  * PARAMETERS:  TableIndex          - Table index
697  *
698  * RETURN:      Status
699  *
700  * DESCRIPTION: Delete all namespace objects created when this table was loaded.
701  *
702  ******************************************************************************/
703 
704 ACPI_STATUS
705 AcpiTbDeleteNamespaceByOwner (
706     UINT32                  TableIndex)
707 {
708     ACPI_OWNER_ID           OwnerId;
709     ACPI_STATUS             Status;
710 
711 
712     ACPI_FUNCTION_TRACE (TbDeleteNamespaceByOwner);
713 
714 
715     Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES);
716     if (ACPI_FAILURE (Status))
717     {
718         return_ACPI_STATUS (Status);
719     }
720 
721     if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
722     {
723         /* The table index does not exist */
724 
725         (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
726         return_ACPI_STATUS (AE_NOT_EXIST);
727     }
728 
729     /* Get the owner ID for this table, used to delete namespace nodes */
730 
731     OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
732     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
733 
734     /*
735      * Need to acquire the namespace writer lock to prevent interference
736      * with any concurrent namespace walks. The interpreter must be
737      * released during the deletion since the acquisition of the deletion
738      * lock may block, and also since the execution of a namespace walk
739      * must be allowed to use the interpreter.
740      */
741     (void) AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);
742     Status = AcpiUtAcquireWriteLock (&AcpiGbl_NamespaceRwLock);
743 
744     AcpiNsDeleteNamespaceByOwner (OwnerId);
745     if (ACPI_FAILURE (Status))
746     {
747         return_ACPI_STATUS (Status);
748     }
749 
750     AcpiUtReleaseWriteLock (&AcpiGbl_NamespaceRwLock);
751 
752     Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);
753     return_ACPI_STATUS (Status);
754 }
755 
756 
757 /*******************************************************************************
758  *
759  * FUNCTION:    AcpiTbAllocateOwnerId
760  *
761  * PARAMETERS:  TableIndex          - Table index
762  *
763  * RETURN:      Status
764  *
765  * DESCRIPTION: Allocates OwnerId in TableDesc
766  *
767  ******************************************************************************/
768 
769 ACPI_STATUS
770 AcpiTbAllocateOwnerId (
771     UINT32                  TableIndex)
772 {
773     ACPI_STATUS             Status = AE_BAD_PARAMETER;
774 
775 
776     ACPI_FUNCTION_TRACE (TbAllocateOwnerId);
777 
778 
779     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
780     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
781     {
782         Status = AcpiUtAllocateOwnerId (
783                     &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
784     }
785 
786     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
787     return_ACPI_STATUS (Status);
788 }
789 
790 
791 /*******************************************************************************
792  *
793  * FUNCTION:    AcpiTbReleaseOwnerId
794  *
795  * PARAMETERS:  TableIndex          - Table index
796  *
797  * RETURN:      Status
798  *
799  * DESCRIPTION: Releases OwnerId in TableDesc
800  *
801  ******************************************************************************/
802 
803 ACPI_STATUS
804 AcpiTbReleaseOwnerId (
805     UINT32                  TableIndex)
806 {
807     ACPI_STATUS             Status = AE_BAD_PARAMETER;
808 
809 
810     ACPI_FUNCTION_TRACE (TbReleaseOwnerId);
811 
812 
813     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
814     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
815     {
816         AcpiUtReleaseOwnerId (
817             &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
818         Status = AE_OK;
819     }
820 
821     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
822     return_ACPI_STATUS (Status);
823 }
824 
825 
826 /*******************************************************************************
827  *
828  * FUNCTION:    AcpiTbGetOwnerId
829  *
830  * PARAMETERS:  TableIndex          - Table index
831  *              OwnerId             - Where the table OwnerId is returned
832  *
833  * RETURN:      Status
834  *
835  * DESCRIPTION: returns OwnerId for the ACPI table
836  *
837  ******************************************************************************/
838 
839 ACPI_STATUS
840 AcpiTbGetOwnerId (
841     UINT32                  TableIndex,
842     ACPI_OWNER_ID           *OwnerId)
843 {
844     ACPI_STATUS             Status = AE_BAD_PARAMETER;
845 
846 
847     ACPI_FUNCTION_TRACE (TbGetOwnerId);
848 
849 
850     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
851     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
852     {
853         *OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
854         Status = AE_OK;
855     }
856 
857     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
858     return_ACPI_STATUS (Status);
859 }
860 
861 
862 /*******************************************************************************
863  *
864  * FUNCTION:    AcpiTbIsTableLoaded
865  *
866  * PARAMETERS:  TableIndex          - Index into the root table
867  *
868  * RETURN:      Table Loaded Flag
869  *
870  ******************************************************************************/
871 
872 BOOLEAN
873 AcpiTbIsTableLoaded (
874     UINT32                  TableIndex)
875 {
876     BOOLEAN                 IsLoaded = FALSE;
877 
878 
879     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
880     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
881     {
882         IsLoaded = (BOOLEAN)
883             (AcpiGbl_RootTableList.Tables[TableIndex].Flags &
884             ACPI_TABLE_IS_LOADED);
885     }
886 
887     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
888     return (IsLoaded);
889 }
890 
891 
892 /*******************************************************************************
893  *
894  * FUNCTION:    AcpiTbSetTableLoadedFlag
895  *
896  * PARAMETERS:  TableIndex          - Table index
897  *              IsLoaded            - TRUE if table is loaded, FALSE otherwise
898  *
899  * RETURN:      None
900  *
901  * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
902  *
903  ******************************************************************************/
904 
905 void
906 AcpiTbSetTableLoadedFlag (
907     UINT32                  TableIndex,
908     BOOLEAN                 IsLoaded)
909 {
910 
911     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
912     if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
913     {
914         if (IsLoaded)
915         {
916             AcpiGbl_RootTableList.Tables[TableIndex].Flags |=
917                 ACPI_TABLE_IS_LOADED;
918         }
919         else
920         {
921             AcpiGbl_RootTableList.Tables[TableIndex].Flags &=
922                 ~ACPI_TABLE_IS_LOADED;
923         }
924     }
925 
926     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
927 }
928