Home | History | Annotate | Line # | Download | only in dispatcher
dsinit.c revision 1.1.1.9
      1      1.1    jruoho /******************************************************************************
      2      1.1    jruoho  *
      3      1.1    jruoho  * Module Name: dsinit - Object initialization namespace walk
      4      1.1    jruoho  *
      5      1.1    jruoho  *****************************************************************************/
      6      1.1    jruoho 
      7  1.1.1.2    jruoho /*
      8  1.1.1.9  christos  * Copyright (C) 2000 - 2018, Intel Corp.
      9      1.1    jruoho  * All rights reserved.
     10      1.1    jruoho  *
     11  1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13  1.1.1.2    jruoho  * are met:
     14  1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.2    jruoho  *    without modification.
     17  1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.2    jruoho  *    binary redistribution.
     22  1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25  1.1.1.2    jruoho  *
     26  1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.2    jruoho  * Software Foundation.
     29  1.1.1.2    jruoho  *
     30  1.1.1.2    jruoho  * NO WARRANTY
     31  1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.2    jruoho  */
     43      1.1    jruoho 
     44      1.1    jruoho #include "acpi.h"
     45      1.1    jruoho #include "accommon.h"
     46      1.1    jruoho #include "acdispat.h"
     47      1.1    jruoho #include "acnamesp.h"
     48      1.1    jruoho #include "actables.h"
     49  1.1.1.8  christos #include "acinterp.h"
     50      1.1    jruoho 
     51      1.1    jruoho #define _COMPONENT          ACPI_DISPATCHER
     52      1.1    jruoho         ACPI_MODULE_NAME    ("dsinit")
     53      1.1    jruoho 
     54  1.1.1.4  christos 
     55      1.1    jruoho /* Local prototypes */
     56      1.1    jruoho 
     57      1.1    jruoho static ACPI_STATUS
     58      1.1    jruoho AcpiDsInitOneObject (
     59      1.1    jruoho     ACPI_HANDLE             ObjHandle,
     60      1.1    jruoho     UINT32                  Level,
     61      1.1    jruoho     void                    *Context,
     62      1.1    jruoho     void                    **ReturnValue);
     63      1.1    jruoho 
     64      1.1    jruoho 
     65      1.1    jruoho /*******************************************************************************
     66      1.1    jruoho  *
     67      1.1    jruoho  * FUNCTION:    AcpiDsInitOneObject
     68      1.1    jruoho  *
     69      1.1    jruoho  * PARAMETERS:  ObjHandle       - Node for the object
     70      1.1    jruoho  *              Level           - Current nesting level
     71      1.1    jruoho  *              Context         - Points to a init info struct
     72      1.1    jruoho  *              ReturnValue     - Not used
     73      1.1    jruoho  *
     74      1.1    jruoho  * RETURN:      Status
     75      1.1    jruoho  *
     76  1.1.1.3  christos  * DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every object
     77      1.1    jruoho  *              within the namespace.
     78      1.1    jruoho  *
     79      1.1    jruoho  *              Currently, the only objects that require initialization are:
     80      1.1    jruoho  *              1) Methods
     81      1.1    jruoho  *              2) Operation Regions
     82      1.1    jruoho  *
     83      1.1    jruoho  ******************************************************************************/
     84      1.1    jruoho 
     85      1.1    jruoho static ACPI_STATUS
     86      1.1    jruoho AcpiDsInitOneObject (
     87      1.1    jruoho     ACPI_HANDLE             ObjHandle,
     88      1.1    jruoho     UINT32                  Level,
     89      1.1    jruoho     void                    *Context,
     90      1.1    jruoho     void                    **ReturnValue)
     91      1.1    jruoho {
     92      1.1    jruoho     ACPI_INIT_WALK_INFO     *Info = (ACPI_INIT_WALK_INFO *) Context;
     93      1.1    jruoho     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
     94      1.1    jruoho     ACPI_STATUS             Status;
     95  1.1.1.4  christos     ACPI_OPERAND_OBJECT     *ObjDesc;
     96      1.1    jruoho 
     97      1.1    jruoho 
     98      1.1    jruoho     ACPI_FUNCTION_ENTRY ();
     99      1.1    jruoho 
    100      1.1    jruoho 
    101      1.1    jruoho     /*
    102      1.1    jruoho      * We are only interested in NS nodes owned by the table that
    103      1.1    jruoho      * was just loaded
    104      1.1    jruoho      */
    105      1.1    jruoho     if (Node->OwnerId != Info->OwnerId)
    106      1.1    jruoho     {
    107      1.1    jruoho         return (AE_OK);
    108      1.1    jruoho     }
    109      1.1    jruoho 
    110      1.1    jruoho     Info->ObjectCount++;
    111      1.1    jruoho 
    112      1.1    jruoho     /* And even then, we are only interested in a few object types */
    113      1.1    jruoho 
    114  1.1.1.4  christos     switch (AcpiNsGetType (ObjHandle))
    115      1.1    jruoho     {
    116      1.1    jruoho     case ACPI_TYPE_REGION:
    117      1.1    jruoho 
    118      1.1    jruoho         Status = AcpiDsInitializeRegion (ObjHandle);
    119      1.1    jruoho         if (ACPI_FAILURE (Status))
    120      1.1    jruoho         {
    121      1.1    jruoho             ACPI_EXCEPTION ((AE_INFO, Status,
    122      1.1    jruoho                 "During Region initialization %p [%4.4s]",
    123      1.1    jruoho                 ObjHandle, AcpiUtGetNodeName (ObjHandle)));
    124      1.1    jruoho         }
    125      1.1    jruoho 
    126      1.1    jruoho         Info->OpRegionCount++;
    127      1.1    jruoho         break;
    128      1.1    jruoho 
    129      1.1    jruoho     case ACPI_TYPE_METHOD:
    130  1.1.1.4  christos         /*
    131  1.1.1.4  christos          * Auto-serialization support. We will examine each method that is
    132  1.1.1.4  christos          * NotSerialized to determine if it creates any Named objects. If
    133  1.1.1.4  christos          * it does, it will be marked serialized to prevent problems if
    134  1.1.1.4  christos          * the method is entered by two or more threads and an attempt is
    135  1.1.1.4  christos          * made to create the same named object twice -- which results in
    136  1.1.1.4  christos          * an AE_ALREADY_EXISTS exception and method abort.
    137  1.1.1.4  christos          */
    138      1.1    jruoho         Info->MethodCount++;
    139  1.1.1.4  christos         ObjDesc = AcpiNsGetAttachedObject (Node);
    140  1.1.1.4  christos         if (!ObjDesc)
    141  1.1.1.4  christos         {
    142  1.1.1.4  christos             break;
    143  1.1.1.4  christos         }
    144  1.1.1.4  christos 
    145  1.1.1.4  christos         /* Ignore if already serialized */
    146  1.1.1.4  christos 
    147  1.1.1.4  christos         if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)
    148  1.1.1.4  christos         {
    149  1.1.1.4  christos             Info->SerialMethodCount++;
    150  1.1.1.4  christos             break;
    151  1.1.1.4  christos         }
    152  1.1.1.4  christos 
    153  1.1.1.4  christos         if (AcpiGbl_AutoSerializeMethods)
    154  1.1.1.4  christos         {
    155  1.1.1.4  christos             /* Parse/scan method and serialize it if necessary */
    156  1.1.1.4  christos 
    157  1.1.1.4  christos             AcpiDsAutoSerializeMethod (Node, ObjDesc);
    158  1.1.1.4  christos             if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)
    159  1.1.1.4  christos             {
    160  1.1.1.4  christos                 /* Method was just converted to Serialized */
    161  1.1.1.4  christos 
    162  1.1.1.4  christos                 Info->SerialMethodCount++;
    163  1.1.1.4  christos                 Info->SerializedMethodCount++;
    164  1.1.1.4  christos                 break;
    165  1.1.1.4  christos             }
    166  1.1.1.4  christos         }
    167  1.1.1.4  christos 
    168  1.1.1.4  christos         Info->NonSerialMethodCount++;
    169      1.1    jruoho         break;
    170      1.1    jruoho 
    171      1.1    jruoho     case ACPI_TYPE_DEVICE:
    172      1.1    jruoho 
    173      1.1    jruoho         Info->DeviceCount++;
    174      1.1    jruoho         break;
    175      1.1    jruoho 
    176      1.1    jruoho     default:
    177  1.1.1.3  christos 
    178      1.1    jruoho         break;
    179      1.1    jruoho     }
    180      1.1    jruoho 
    181      1.1    jruoho     /*
    182      1.1    jruoho      * We ignore errors from above, and always return OK, since
    183      1.1    jruoho      * we don't want to abort the walk on a single error.
    184      1.1    jruoho      */
    185      1.1    jruoho     return (AE_OK);
    186      1.1    jruoho }
    187      1.1    jruoho 
    188      1.1    jruoho 
    189      1.1    jruoho /*******************************************************************************
    190      1.1    jruoho  *
    191      1.1    jruoho  * FUNCTION:    AcpiDsInitializeObjects
    192      1.1    jruoho  *
    193      1.1    jruoho  * PARAMETERS:  TableDesc       - Descriptor for parent ACPI table
    194      1.1    jruoho  *              StartNode       - Root of subtree to be initialized.
    195      1.1    jruoho  *
    196      1.1    jruoho  * RETURN:      Status
    197      1.1    jruoho  *
    198      1.1    jruoho  * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any
    199      1.1    jruoho  *              necessary initialization on the objects found therein
    200      1.1    jruoho  *
    201      1.1    jruoho  ******************************************************************************/
    202      1.1    jruoho 
    203      1.1    jruoho ACPI_STATUS
    204      1.1    jruoho AcpiDsInitializeObjects (
    205      1.1    jruoho     UINT32                  TableIndex,
    206      1.1    jruoho     ACPI_NAMESPACE_NODE     *StartNode)
    207      1.1    jruoho {
    208      1.1    jruoho     ACPI_STATUS             Status;
    209      1.1    jruoho     ACPI_INIT_WALK_INFO     Info;
    210      1.1    jruoho     ACPI_TABLE_HEADER       *Table;
    211      1.1    jruoho     ACPI_OWNER_ID           OwnerId;
    212      1.1    jruoho 
    213      1.1    jruoho 
    214      1.1    jruoho     ACPI_FUNCTION_TRACE (DsInitializeObjects);
    215      1.1    jruoho 
    216      1.1    jruoho 
    217      1.1    jruoho     Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
    218      1.1    jruoho     if (ACPI_FAILURE (Status))
    219      1.1    jruoho     {
    220      1.1    jruoho         return_ACPI_STATUS (Status);
    221      1.1    jruoho     }
    222      1.1    jruoho 
    223      1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    224      1.1    jruoho         "**** Starting initialization of namespace objects ****\n"));
    225      1.1    jruoho 
    226      1.1    jruoho     /* Set all init info to zero */
    227      1.1    jruoho 
    228  1.1.1.6  christos     memset (&Info, 0, sizeof (ACPI_INIT_WALK_INFO));
    229      1.1    jruoho 
    230      1.1    jruoho     Info.OwnerId = OwnerId;
    231      1.1    jruoho     Info.TableIndex = TableIndex;
    232      1.1    jruoho 
    233      1.1    jruoho     /* Walk entire namespace from the supplied root */
    234      1.1    jruoho 
    235      1.1    jruoho     /*
    236      1.1    jruoho      * We don't use AcpiWalkNamespace since we do not want to acquire
    237      1.1    jruoho      * the namespace reader lock.
    238      1.1    jruoho      */
    239      1.1    jruoho     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, StartNode, ACPI_UINT32_MAX,
    240  1.1.1.8  christos         ACPI_NS_WALK_NO_UNLOCK, AcpiDsInitOneObject, NULL, &Info, NULL);
    241      1.1    jruoho     if (ACPI_FAILURE (Status))
    242      1.1    jruoho     {
    243      1.1    jruoho         ACPI_EXCEPTION ((AE_INFO, Status, "During WalkNamespace"));
    244      1.1    jruoho     }
    245      1.1    jruoho 
    246      1.1    jruoho     Status = AcpiGetTableByIndex (TableIndex, &Table);
    247      1.1    jruoho     if (ACPI_FAILURE (Status))
    248      1.1    jruoho     {
    249      1.1    jruoho         return_ACPI_STATUS (Status);
    250      1.1    jruoho     }
    251      1.1    jruoho 
    252  1.1.1.7  christos     /* DSDT is always the first AML table */
    253  1.1.1.7  christos 
    254  1.1.1.7  christos     if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
    255  1.1.1.7  christos     {
    256  1.1.1.7  christos         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
    257  1.1.1.7  christos             "\nInitializing Namespace objects:\n"));
    258  1.1.1.7  christos     }
    259  1.1.1.7  christos 
    260  1.1.1.7  christos     /* Summary of objects initialized */
    261  1.1.1.7  christos 
    262      1.1    jruoho     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
    263  1.1.1.7  christos         "Table [%4.4s: %-8.8s] (id %.2X) - %4u Objects with %3u Devices, "
    264  1.1.1.7  christos         "%3u Regions, %4u Methods (%u/%u/%u Serial/Non/Cvt)\n",
    265  1.1.1.7  christos         Table->Signature, Table->OemTableId, OwnerId, Info.ObjectCount,
    266  1.1.1.7  christos         Info.DeviceCount,Info.OpRegionCount, Info.MethodCount,
    267  1.1.1.7  christos         Info.SerialMethodCount, Info.NonSerialMethodCount,
    268  1.1.1.7  christos         Info.SerializedMethodCount));
    269      1.1    jruoho 
    270  1.1.1.4  christos     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "%u Methods, %u Regions\n",
    271  1.1.1.4  christos         Info.MethodCount, Info.OpRegionCount));
    272      1.1    jruoho 
    273      1.1    jruoho     return_ACPI_STATUS (AE_OK);
    274      1.1    jruoho }
    275