tbdata.c revision 281687
1139825Simp/******************************************************************************
284192Sjake *
384192Sjake * Module Name: tbdata - Table manager data structure functions
484192Sjake *
584192Sjake *****************************************************************************/
684192Sjake
784192Sjake/*
884192Sjake * Copyright (C) 2000 - 2015, Intel Corp.
9169795Smarius * All rights reserved.
10169795Smarius *
11169795Smarius * Redistribution and use in source and binary forms, with or without
12169795Smarius * modification, are permitted provided that the following conditions
1384192Sjake * are met:
1484192Sjake * 1. Redistributions of source code must retain the above copyright
1586522Sjake *    notice, this list of conditions, and the following disclaimer,
1686522Sjake *    without modification.
1784192Sjake * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1884848Stmm *    substantially similar to the "NO WARRANTY" disclaimer below
1984192Sjake *    ("Disclaimer") and any redistribution must be conditioned upon
2084192Sjake *    including a substantially similar Disclaimer requirement for further
21164372Skmacy *    binary redistribution.
2286522Sjake * 3. Neither the names of the above-listed copyright holders nor the names
2386522Sjake *    of any contributors may be used to endorse or promote products derived
2486522Sjake *    from this software without specific prior written permission.
2586522Sjake *
2686522Sjake * Alternatively, this software may be distributed under the terms of the
2786522Sjake * GNU General Public License ("GPL") version 2 as published by the Free
2886522Sjake * Software Foundation.
29227309Sed *
30200891Smarcel * NO WARRANTY
31200891Smarcel * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32200891Smarcel * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33200891Smarcel * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34200891Smarcel * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35200891Smarcel * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3684192Sjake * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3791359Sjake * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3884192Sjake * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3984192Sjake * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4084192Sjake * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4184192Sjake * POSSIBILITY OF SUCH DAMAGES.
4284192Sjake */
4384192Sjake
44207537Smarius#include <contrib/dev/acpica/include/acpi.h>
4584192Sjake#include <contrib/dev/acpica/include/accommon.h>
4684192Sjake#include <contrib/dev/acpica/include/acnamesp.h>
4784192Sjake#include <contrib/dev/acpica/include/actables.h>
4888791Sjake
4999896Sjake#define _COMPONENT          ACPI_TABLES
5084192Sjake        ACPI_MODULE_NAME    ("tbdata")
5184192Sjake
5299896Sjake
5399896Sjake/*******************************************************************************
5499896Sjake *
5584192Sjake * FUNCTION:    AcpiTbInitTableDescriptor
56112398Sjake *
5790614Stmm * PARAMETERS:  TableDesc               - Table descriptor
5884192Sjake *              Address                 - Physical address of the table
5984192Sjake *              Flags                   - Allocation flags of the table
60207537Smarius *              Table                   - Pointer to the table
61207537Smarius *
62207537Smarius * RETURN:      None
63207537Smarius *
64207537Smarius * DESCRIPTION: Initialize a new table descriptor
65207537Smarius *
66207537Smarius ******************************************************************************/
67207537Smarius
68207537Smariusvoid
69207537SmariusAcpiTbInitTableDescriptor (
70207537Smarius    ACPI_TABLE_DESC         *TableDesc,
71207537Smarius    ACPI_PHYSICAL_ADDRESS   Address,
72207537Smarius    UINT8                   Flags,
73207537Smarius    ACPI_TABLE_HEADER       *Table)
74207537Smarius{
75207537Smarius
76207537Smarius    /*
77207537Smarius     * Initialize the table descriptor. Set the pointer to NULL, since the
78207537Smarius     * table is not fully mapped at this time.
79207537Smarius     */
80207537Smarius    ACPI_MEMSET (TableDesc, 0, sizeof (ACPI_TABLE_DESC));
8190614Stmm    TableDesc->Address = Address;
8284192Sjake    TableDesc->Length = Table->Length;
8384192Sjake    TableDesc->Flags = Flags;
8490614Stmm    ACPI_MOVE_32_TO_32 (TableDesc->Signature.Ascii, Table->Signature);
8584192Sjake}
8684192Sjake
8790614Stmm
8884192Sjake/*******************************************************************************
8984192Sjake *
9090614Stmm * FUNCTION:    AcpiTbAcquireTable
9184192Sjake *
9284192Sjake * PARAMETERS:  TableDesc           - Table descriptor
9399896Sjake *              TablePtr            - Where table is returned
9499896Sjake *              TableLength         - Where table length is returned
9599896Sjake *              TableFlags          - Where table allocation flags are returned
9699896Sjake *
9799896Sjake * RETURN:      Status
9899896Sjake *
99139264Sscottl * DESCRIPTION: Acquire an ACPI table. It can be used for tables not
100139264Sscottl *              maintained in the AcpiGbl_RootTableList.
101139264Sscottl *
102169795Smarius ******************************************************************************/
103169795Smarius
104169795SmariusACPI_STATUS
105169795SmariusAcpiTbAcquireTable (
106169795Smarius    ACPI_TABLE_DESC         *TableDesc,
107169795Smarius    ACPI_TABLE_HEADER       **TablePtr,
108169795Smarius    UINT32                  *TableLength,
109169795Smarius    UINT8                   *TableFlags)
110169795Smarius{
11199896Sjake    ACPI_TABLE_HEADER       *Table = NULL;
11299896Sjake
11399896Sjake
11484192Sjake    switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)
11584192Sjake    {
11684192Sjake    case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
11784192Sjake
11884192Sjake        Table = AcpiOsMapMemory (TableDesc->Address, TableDesc->Length);
119128756Smarius        break;
12084192Sjake
12184192Sjake    case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
12284192Sjake    case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
12384192Sjake
12486522Sjake        Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
125106541Smux                    ACPI_PHYSADDR_TO_PTR (TableDesc->Address));
12684192Sjake        break;
12784192Sjake
12884848Stmm    default:
12984192Sjake
13084192Sjake        break;
131200891Smarcel    }
132200891Smarcel
133200891Smarcel    /* Table is not valid yet */
134200891Smarcel
135200891Smarcel    if (!Table)
136200891Smarcel    {
137200891Smarcel        return (AE_NO_MEMORY);
13884192Sjake    }
139
140    /* Fill the return values */
141
142    *TablePtr = Table;
143    *TableLength = TableDesc->Length;
144    *TableFlags = TableDesc->Flags;
145    return (AE_OK);
146}
147
148
149/*******************************************************************************
150 *
151 * FUNCTION:    AcpiTbReleaseTable
152 *
153 * PARAMETERS:  Table               - Pointer for the table
154 *              TableLength         - Length for the table
155 *              TableFlags          - Allocation flags for the table
156 *
157 * RETURN:      None
158 *
159 * DESCRIPTION: Release a table. The inverse of AcpiTbAcquireTable().
160 *
161 ******************************************************************************/
162
163void
164AcpiTbReleaseTable (
165    ACPI_TABLE_HEADER       *Table,
166    UINT32                  TableLength,
167    UINT8                   TableFlags)
168{
169
170    switch (TableFlags & ACPI_TABLE_ORIGIN_MASK)
171    {
172    case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
173
174        AcpiOsUnmapMemory (Table, TableLength);
175        break;
176
177    case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
178    case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
179    default:
180
181        break;
182    }
183}
184
185
186/*******************************************************************************
187 *
188 * FUNCTION:    AcpiTbAcquireTempTable
189 *
190 * PARAMETERS:  TableDesc           - Table descriptor to be acquired
191 *              Address             - Address of the table
192 *              Flags               - Allocation flags of the table
193 *
194 * RETURN:      Status
195 *
196 * DESCRIPTION: This function validates the table header to obtain the length
197 *              of a table and fills the table descriptor to make its state as
198 *              "INSTALLED". Such a table descriptor is only used for verified
199 *              installation.
200 *
201 ******************************************************************************/
202
203ACPI_STATUS
204AcpiTbAcquireTempTable (
205    ACPI_TABLE_DESC         *TableDesc,
206    ACPI_PHYSICAL_ADDRESS   Address,
207    UINT8                   Flags)
208{
209    ACPI_TABLE_HEADER       *TableHeader;
210
211
212    switch (Flags & ACPI_TABLE_ORIGIN_MASK)
213    {
214    case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
215
216        /* Get the length of the full table from the header */
217
218        TableHeader = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
219        if (!TableHeader)
220        {
221            return (AE_NO_MEMORY);
222        }
223
224        AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
225        AcpiOsUnmapMemory (TableHeader, sizeof (ACPI_TABLE_HEADER));
226        return (AE_OK);
227
228    case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
229    case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
230
231        TableHeader = ACPI_CAST_PTR (ACPI_TABLE_HEADER,
232                        ACPI_PHYSADDR_TO_PTR (Address));
233        if (!TableHeader)
234        {
235            return (AE_NO_MEMORY);
236        }
237
238        AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader);
239        return (AE_OK);
240
241    default:
242
243        break;
244    }
245
246    /* Table is not valid yet */
247
248    return (AE_NO_MEMORY);
249}
250
251
252/*******************************************************************************
253 *
254 * FUNCTION:    AcpiTbReleaseTempTable
255 *
256 * PARAMETERS:  TableDesc           - Table descriptor to be released
257 *
258 * RETURN:      Status
259 *
260 * DESCRIPTION: The inverse of AcpiTbAcquireTempTable().
261 *
262 *****************************************************************************/
263
264void
265AcpiTbReleaseTempTable (
266    ACPI_TABLE_DESC         *TableDesc)
267{
268
269    /*
270     * Note that the .Address is maintained by the callers of
271     * AcpiTbAcquireTempTable(), thus do not invoke AcpiTbUninstallTable()
272     * where .Address will be freed.
273     */
274    AcpiTbInvalidateTable (TableDesc);
275}
276
277
278/******************************************************************************
279 *
280 * FUNCTION:    AcpiTbValidateTable
281 *
282 * PARAMETERS:  TableDesc           - Table descriptor
283 *
284 * RETURN:      Status
285 *
286 * DESCRIPTION: This function is called to validate the table, the returned
287 *              table descriptor is in "VALIDATED" state.
288 *
289 *****************************************************************************/
290
291ACPI_STATUS
292AcpiTbValidateTable (
293    ACPI_TABLE_DESC         *TableDesc)
294{
295    ACPI_STATUS             Status = AE_OK;
296
297
298    ACPI_FUNCTION_TRACE (TbValidateTable);
299
300
301    /* Validate the table if necessary */
302
303    if (!TableDesc->Pointer)
304    {
305        Status = AcpiTbAcquireTable (TableDesc, &TableDesc->Pointer,
306                    &TableDesc->Length, &TableDesc->Flags);
307        if (!TableDesc->Pointer)
308        {
309            Status = AE_NO_MEMORY;
310        }
311    }
312
313    return_ACPI_STATUS (Status);
314}
315
316
317/*******************************************************************************
318 *
319 * FUNCTION:    AcpiTbInvalidateTable
320 *
321 * PARAMETERS:  TableDesc           - Table descriptor
322 *
323 * RETURN:      None
324 *
325 * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of
326 *              AcpiTbValidateTable().
327 *
328 ******************************************************************************/
329
330void
331AcpiTbInvalidateTable (
332    ACPI_TABLE_DESC         *TableDesc)
333{
334
335    ACPI_FUNCTION_TRACE (TbInvalidateTable);
336
337
338    /* Table must be validated */
339
340    if (!TableDesc->Pointer)
341    {
342        return_VOID;
343    }
344
345    AcpiTbReleaseTable (TableDesc->Pointer, TableDesc->Length,
346        TableDesc->Flags);
347    TableDesc->Pointer = NULL;
348
349    return_VOID;
350}
351
352
353/******************************************************************************
354 *
355 * FUNCTION:    AcpiTbValidateTempTable
356 *
357 * PARAMETERS:  TableDesc           - Table descriptor
358 *
359 * RETURN:      Status
360 *
361 * DESCRIPTION: This function is called to validate the table, the returned
362 *              table descriptor is in "VALIDATED" state.
363 *
364 *****************************************************************************/
365
366ACPI_STATUS
367AcpiTbValidateTempTable (
368    ACPI_TABLE_DESC         *TableDesc)
369{
370
371    if (!TableDesc->Pointer && !AcpiGbl_VerifyTableChecksum)
372    {
373        /*
374         * Only validates the header of the table.
375         * Note that Length contains the size of the mapping after invoking
376         * this work around, this value is required by
377         * AcpiTbReleaseTempTable().
378         * We can do this because in AcpiInitTableDescriptor(), the Length
379         * field of the installed descriptor is filled with the actual
380         * table length obtaining from the table header.
381         */
382        TableDesc->Length = sizeof (ACPI_TABLE_HEADER);
383    }
384
385    return (AcpiTbValidateTable (TableDesc));
386}
387
388
389/******************************************************************************
390 *
391 * FUNCTION:    AcpiTbVerifyTempTable
392 *
393 * PARAMETERS:  TableDesc           - Table descriptor
394 *              Signature           - Table signature to verify
395 *
396 * RETURN:      Status
397 *
398 * DESCRIPTION: This function is called to validate and verify the table, the
399 *              returned table descriptor is in "VALIDATED" state.
400 *
401 *****************************************************************************/
402
403ACPI_STATUS
404AcpiTbVerifyTempTable (
405    ACPI_TABLE_DESC         *TableDesc,
406    char                    *Signature)
407{
408    ACPI_STATUS             Status = AE_OK;
409
410
411    ACPI_FUNCTION_TRACE (TbVerifyTempTable);
412
413
414    /* Validate the table */
415
416    Status = AcpiTbValidateTempTable (TableDesc);
417    if (ACPI_FAILURE (Status))
418    {
419        return_ACPI_STATUS (AE_NO_MEMORY);
420    }
421
422    /* If a particular signature is expected (DSDT/FACS), it must match */
423
424    if (Signature &&
425        !ACPI_COMPARE_NAME (&TableDesc->Signature, Signature))
426    {
427        ACPI_BIOS_ERROR ((AE_INFO,
428            "Invalid signature 0x%X for ACPI table, expected [%s]",
429            TableDesc->Signature.Integer, Signature));
430        Status = AE_BAD_SIGNATURE;
431        goto InvalidateAndExit;
432    }
433
434    /* Verify the checksum */
435
436    if (AcpiGbl_VerifyTableChecksum)
437    {
438        Status = AcpiTbVerifyChecksum (TableDesc->Pointer, TableDesc->Length);
439        if (ACPI_FAILURE (Status))
440        {
441            ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY,
442                "%4.4s 0x%8.8X%8.8X"
443                " Attempted table install failed",
444                AcpiUtValidAcpiName (TableDesc->Signature.Ascii) ?
445                    TableDesc->Signature.Ascii : "????",
446                ACPI_FORMAT_UINT64 (TableDesc->Address)));
447            goto InvalidateAndExit;
448        }
449    }
450
451    return_ACPI_STATUS (AE_OK);
452
453InvalidateAndExit:
454    AcpiTbInvalidateTable (TableDesc);
455    return_ACPI_STATUS (Status);
456}
457
458
459/*******************************************************************************
460 *
461 * FUNCTION:    AcpiTbResizeRootTableList
462 *
463 * PARAMETERS:  None
464 *
465 * RETURN:      Status
466 *
467 * DESCRIPTION: Expand the size of global table array
468 *
469 ******************************************************************************/
470
471ACPI_STATUS
472AcpiTbResizeRootTableList (
473    void)
474{
475    ACPI_TABLE_DESC         *Tables;
476    UINT32                  TableCount;
477
478
479    ACPI_FUNCTION_TRACE (TbResizeRootTableList);
480
481
482    /* AllowResize flag is a parameter to AcpiInitializeTables */
483
484    if (!(AcpiGbl_RootTableList.Flags & ACPI_ROOT_ALLOW_RESIZE))
485    {
486        ACPI_ERROR ((AE_INFO, "Resize of Root Table Array is not allowed"));
487        return_ACPI_STATUS (AE_SUPPORT);
488    }
489
490    /* Increase the Table Array size */
491
492    if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
493    {
494        TableCount = AcpiGbl_RootTableList.MaxTableCount;
495    }
496    else
497    {
498        TableCount = AcpiGbl_RootTableList.CurrentTableCount;
499    }
500
501    Tables = ACPI_ALLOCATE_ZEROED (
502        ((ACPI_SIZE) TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT) *
503        sizeof (ACPI_TABLE_DESC));
504    if (!Tables)
505    {
506        ACPI_ERROR ((AE_INFO, "Could not allocate new root table array"));
507        return_ACPI_STATUS (AE_NO_MEMORY);
508    }
509
510    /* Copy and free the previous table array */
511
512    if (AcpiGbl_RootTableList.Tables)
513    {
514        ACPI_MEMCPY (Tables, AcpiGbl_RootTableList.Tables,
515            (ACPI_SIZE) TableCount * sizeof (ACPI_TABLE_DESC));
516
517        if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
518        {
519            ACPI_FREE (AcpiGbl_RootTableList.Tables);
520        }
521    }
522
523    AcpiGbl_RootTableList.Tables = Tables;
524    AcpiGbl_RootTableList.MaxTableCount =
525        TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT;
526    AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
527
528    return_ACPI_STATUS (AE_OK);
529}
530
531
532/*******************************************************************************
533 *
534 * FUNCTION:    AcpiTbGetNextTableDescriptor
535 *
536 * PARAMETERS:  TableIndex          - Where table index is returned
537 *              TableDesc           - Where table descriptor is returned
538 *
539 * RETURN:      Status and table index/descriptor.
540 *
541 * DESCRIPTION: Allocate a new ACPI table entry to the global table list
542 *
543 ******************************************************************************/
544
545ACPI_STATUS
546AcpiTbGetNextTableDescriptor (
547    UINT32                  *TableIndex,
548    ACPI_TABLE_DESC         **TableDesc)
549{
550    ACPI_STATUS             Status;
551    UINT32                  i;
552
553
554    /* Ensure that there is room for the table in the Root Table List */
555
556    if (AcpiGbl_RootTableList.CurrentTableCount >=
557        AcpiGbl_RootTableList.MaxTableCount)
558    {
559        Status = AcpiTbResizeRootTableList();
560        if (ACPI_FAILURE (Status))
561        {
562            return (Status);
563        }
564    }
565
566    i = AcpiGbl_RootTableList.CurrentTableCount;
567    AcpiGbl_RootTableList.CurrentTableCount++;
568
569    if (TableIndex)
570    {
571        *TableIndex = i;
572    }
573    if (TableDesc)
574    {
575        *TableDesc = &AcpiGbl_RootTableList.Tables[i];
576    }
577
578    return (AE_OK);
579}
580
581
582/*******************************************************************************
583 *
584 * FUNCTION:    AcpiTbTerminate
585 *
586 * PARAMETERS:  None
587 *
588 * RETURN:      None
589 *
590 * DESCRIPTION: Delete all internal ACPI tables
591 *
592 ******************************************************************************/
593
594void
595AcpiTbTerminate (
596    void)
597{
598    UINT32                  i;
599
600
601    ACPI_FUNCTION_TRACE (TbTerminate);
602
603
604    (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
605
606    /* Delete the individual tables */
607
608    for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
609    {
610        AcpiTbUninstallTable (&AcpiGbl_RootTableList.Tables[i]);
611    }
612
613    /*
614     * Delete the root table array if allocated locally. Array cannot be
615     * mapped, so we don't need to check for that flag.
616     */
617    if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED)
618    {
619        ACPI_FREE (AcpiGbl_RootTableList.Tables);
620    }
621
622    AcpiGbl_RootTableList.Tables = NULL;
623    AcpiGbl_RootTableList.Flags = 0;
624    AcpiGbl_RootTableList.CurrentTableCount = 0;
625
626    ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));
627
628    (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
629    return_VOID;
630}
631
632
633/*******************************************************************************
634 *
635 * FUNCTION:    AcpiTbDeleteNamespaceByOwner
636 *
637 * PARAMETERS:  TableIndex          - Table index
638 *
639 * RETURN:      Status
640 *
641 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
642 *
643 ******************************************************************************/
644
645ACPI_STATUS
646AcpiTbDeleteNamespaceByOwner (
647    UINT32                  TableIndex)
648{
649    ACPI_OWNER_ID           OwnerId;
650    ACPI_STATUS             Status;
651
652
653    ACPI_FUNCTION_TRACE (TbDeleteNamespaceByOwner);
654
655
656    Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES);
657    if (ACPI_FAILURE (Status))
658    {
659        return_ACPI_STATUS (Status);
660    }
661
662    if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount)
663    {
664        /* The table index does not exist */
665
666        (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
667        return_ACPI_STATUS (AE_NOT_EXIST);
668    }
669
670    /* Get the owner ID for this table, used to delete namespace nodes */
671
672    OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
673    (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
674
675    /*
676     * Need to acquire the namespace writer lock to prevent interference
677     * with any concurrent namespace walks. The interpreter must be
678     * released during the deletion since the acquisition of the deletion
679     * lock may block, and also since the execution of a namespace walk
680     * must be allowed to use the interpreter.
681     */
682    (void) AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);
683    Status = AcpiUtAcquireWriteLock (&AcpiGbl_NamespaceRwLock);
684
685    AcpiNsDeleteNamespaceByOwner (OwnerId);
686    if (ACPI_FAILURE (Status))
687    {
688        return_ACPI_STATUS (Status);
689    }
690
691    AcpiUtReleaseWriteLock (&AcpiGbl_NamespaceRwLock);
692
693    Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);
694    return_ACPI_STATUS (Status);
695}
696
697
698/*******************************************************************************
699 *
700 * FUNCTION:    AcpiTbAllocateOwnerId
701 *
702 * PARAMETERS:  TableIndex          - Table index
703 *
704 * RETURN:      Status
705 *
706 * DESCRIPTION: Allocates OwnerId in TableDesc
707 *
708 ******************************************************************************/
709
710ACPI_STATUS
711AcpiTbAllocateOwnerId (
712    UINT32                  TableIndex)
713{
714    ACPI_STATUS             Status = AE_BAD_PARAMETER;
715
716
717    ACPI_FUNCTION_TRACE (TbAllocateOwnerId);
718
719
720    (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
721    if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
722    {
723        Status = AcpiUtAllocateOwnerId (
724                    &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
725    }
726
727    (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
728    return_ACPI_STATUS (Status);
729}
730
731
732/*******************************************************************************
733 *
734 * FUNCTION:    AcpiTbReleaseOwnerId
735 *
736 * PARAMETERS:  TableIndex          - Table index
737 *
738 * RETURN:      Status
739 *
740 * DESCRIPTION: Releases OwnerId in TableDesc
741 *
742 ******************************************************************************/
743
744ACPI_STATUS
745AcpiTbReleaseOwnerId (
746    UINT32                  TableIndex)
747{
748    ACPI_STATUS             Status = AE_BAD_PARAMETER;
749
750
751    ACPI_FUNCTION_TRACE (TbReleaseOwnerId);
752
753
754    (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
755    if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
756    {
757        AcpiUtReleaseOwnerId (
758            &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId));
759        Status = AE_OK;
760    }
761
762    (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
763    return_ACPI_STATUS (Status);
764}
765
766
767/*******************************************************************************
768 *
769 * FUNCTION:    AcpiTbGetOwnerId
770 *
771 * PARAMETERS:  TableIndex          - Table index
772 *              OwnerId             - Where the table OwnerId is returned
773 *
774 * RETURN:      Status
775 *
776 * DESCRIPTION: returns OwnerId for the ACPI table
777 *
778 ******************************************************************************/
779
780ACPI_STATUS
781AcpiTbGetOwnerId (
782    UINT32                  TableIndex,
783    ACPI_OWNER_ID           *OwnerId)
784{
785    ACPI_STATUS             Status = AE_BAD_PARAMETER;
786
787
788    ACPI_FUNCTION_TRACE (TbGetOwnerId);
789
790
791    (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
792    if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
793    {
794        *OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId;
795        Status = AE_OK;
796    }
797
798    (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
799    return_ACPI_STATUS (Status);
800}
801
802
803/*******************************************************************************
804 *
805 * FUNCTION:    AcpiTbIsTableLoaded
806 *
807 * PARAMETERS:  TableIndex          - Index into the root table
808 *
809 * RETURN:      Table Loaded Flag
810 *
811 ******************************************************************************/
812
813BOOLEAN
814AcpiTbIsTableLoaded (
815    UINT32                  TableIndex)
816{
817    BOOLEAN                 IsLoaded = FALSE;
818
819
820    (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
821    if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
822    {
823        IsLoaded = (BOOLEAN)
824            (AcpiGbl_RootTableList.Tables[TableIndex].Flags &
825            ACPI_TABLE_IS_LOADED);
826    }
827
828    (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
829    return (IsLoaded);
830}
831
832
833/*******************************************************************************
834 *
835 * FUNCTION:    AcpiTbSetTableLoadedFlag
836 *
837 * PARAMETERS:  TableIndex          - Table index
838 *              IsLoaded            - TRUE if table is loaded, FALSE otherwise
839 *
840 * RETURN:      None
841 *
842 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
843 *
844 ******************************************************************************/
845
846void
847AcpiTbSetTableLoadedFlag (
848    UINT32                  TableIndex,
849    BOOLEAN                 IsLoaded)
850{
851
852    (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
853    if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount)
854    {
855        if (IsLoaded)
856        {
857            AcpiGbl_RootTableList.Tables[TableIndex].Flags |=
858                ACPI_TABLE_IS_LOADED;
859        }
860        else
861        {
862            AcpiGbl_RootTableList.Tables[TableIndex].Flags &=
863                ~ACPI_TABLE_IS_LOADED;
864        }
865    }
866
867    (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
868}
869