Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /******************************************************************************
0003  *
0004  * Module Name: dsinit - Object initialization namespace walk
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
0007  *
0008  *****************************************************************************/
0009 
0010 #include <acpi/acpi.h>
0011 #include "accommon.h"
0012 #include "acdispat.h"
0013 #include "acnamesp.h"
0014 #include "actables.h"
0015 #include "acinterp.h"
0016 
0017 #define _COMPONENT          ACPI_DISPATCHER
0018 ACPI_MODULE_NAME("dsinit")
0019 
0020 /* Local prototypes */
0021 static acpi_status
0022 acpi_ds_init_one_object(acpi_handle obj_handle,
0023             u32 level, void *context, void **return_value);
0024 
0025 /*******************************************************************************
0026  *
0027  * FUNCTION:    acpi_ds_init_one_object
0028  *
0029  * PARAMETERS:  obj_handle      - Node for the object
0030  *              level           - Current nesting level
0031  *              context         - Points to a init info struct
0032  *              return_value    - Not used
0033  *
0034  * RETURN:      Status
0035  *
0036  * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object
0037  *              within the namespace.
0038  *
0039  *              Currently, the only objects that require initialization are:
0040  *              1) Methods
0041  *              2) Operation Regions
0042  *
0043  ******************************************************************************/
0044 
0045 static acpi_status
0046 acpi_ds_init_one_object(acpi_handle obj_handle,
0047             u32 level, void *context, void **return_value)
0048 {
0049     struct acpi_init_walk_info *info =
0050         (struct acpi_init_walk_info *)context;
0051     struct acpi_namespace_node *node =
0052         (struct acpi_namespace_node *)obj_handle;
0053     acpi_status status;
0054     union acpi_operand_object *obj_desc;
0055 
0056     ACPI_FUNCTION_ENTRY();
0057 
0058     /*
0059      * We are only interested in NS nodes owned by the table that
0060      * was just loaded
0061      */
0062     if (node->owner_id != info->owner_id) {
0063         return (AE_OK);
0064     }
0065 
0066     info->object_count++;
0067 
0068     /* And even then, we are only interested in a few object types */
0069 
0070     switch (acpi_ns_get_type(obj_handle)) {
0071     case ACPI_TYPE_REGION:
0072 
0073         status = acpi_ds_initialize_region(obj_handle);
0074         if (ACPI_FAILURE(status)) {
0075             ACPI_EXCEPTION((AE_INFO, status,
0076                     "During Region initialization %p [%4.4s]",
0077                     obj_handle,
0078                     acpi_ut_get_node_name(obj_handle)));
0079         }
0080 
0081         info->op_region_count++;
0082         break;
0083 
0084     case ACPI_TYPE_METHOD:
0085         /*
0086          * Auto-serialization support. We will examine each method that is
0087          * not_serialized to determine if it creates any Named objects. If
0088          * it does, it will be marked serialized to prevent problems if
0089          * the method is entered by two or more threads and an attempt is
0090          * made to create the same named object twice -- which results in
0091          * an AE_ALREADY_EXISTS exception and method abort.
0092          */
0093         info->method_count++;
0094         obj_desc = acpi_ns_get_attached_object(node);
0095         if (!obj_desc) {
0096             break;
0097         }
0098 
0099         /* Ignore if already serialized */
0100 
0101         if (obj_desc->method.info_flags & ACPI_METHOD_SERIALIZED) {
0102             info->serial_method_count++;
0103             break;
0104         }
0105 
0106         if (acpi_gbl_auto_serialize_methods) {
0107 
0108             /* Parse/scan method and serialize it if necessary */
0109 
0110             acpi_ds_auto_serialize_method(node, obj_desc);
0111             if (obj_desc->method.
0112                 info_flags & ACPI_METHOD_SERIALIZED) {
0113 
0114                 /* Method was just converted to Serialized */
0115 
0116                 info->serial_method_count++;
0117                 info->serialized_method_count++;
0118                 break;
0119             }
0120         }
0121 
0122         info->non_serial_method_count++;
0123         break;
0124 
0125     case ACPI_TYPE_DEVICE:
0126 
0127         info->device_count++;
0128         break;
0129 
0130     default:
0131 
0132         break;
0133     }
0134 
0135     /*
0136      * We ignore errors from above, and always return OK, since
0137      * we don't want to abort the walk on a single error.
0138      */
0139     return (AE_OK);
0140 }
0141 
0142 /*******************************************************************************
0143  *
0144  * FUNCTION:    acpi_ds_initialize_objects
0145  *
0146  * PARAMETERS:  table_desc      - Descriptor for parent ACPI table
0147  *              start_node      - Root of subtree to be initialized.
0148  *
0149  * RETURN:      Status
0150  *
0151  * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any
0152  *              necessary initialization on the objects found therein
0153  *
0154  ******************************************************************************/
0155 
0156 acpi_status
0157 acpi_ds_initialize_objects(u32 table_index,
0158                struct acpi_namespace_node *start_node)
0159 {
0160     acpi_status status;
0161     struct acpi_init_walk_info info;
0162     struct acpi_table_header *table;
0163     acpi_owner_id owner_id;
0164 
0165     ACPI_FUNCTION_TRACE(ds_initialize_objects);
0166 
0167     status = acpi_tb_get_owner_id(table_index, &owner_id);
0168     if (ACPI_FAILURE(status)) {
0169         return_ACPI_STATUS(status);
0170     }
0171 
0172     ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
0173               "**** Starting initialization of namespace objects ****\n"));
0174 
0175     /* Set all init info to zero */
0176 
0177     memset(&info, 0, sizeof(struct acpi_init_walk_info));
0178 
0179     info.owner_id = owner_id;
0180     info.table_index = table_index;
0181 
0182     /* Walk entire namespace from the supplied root */
0183 
0184     /*
0185      * We don't use acpi_walk_namespace since we do not want to acquire
0186      * the namespace reader lock.
0187      */
0188     status =
0189         acpi_ns_walk_namespace(ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX,
0190                    ACPI_NS_WALK_NO_UNLOCK,
0191                    acpi_ds_init_one_object, NULL, &info, NULL);
0192     if (ACPI_FAILURE(status)) {
0193         ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));
0194     }
0195 
0196     status = acpi_get_table_by_index(table_index, &table);
0197     if (ACPI_FAILURE(status)) {
0198         return_ACPI_STATUS(status);
0199     }
0200 
0201     /* DSDT is always the first AML table */
0202 
0203     if (ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_DSDT)) {
0204         ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
0205                       "\nACPI table initialization:\n"));
0206     }
0207 
0208     /* Summary of objects initialized */
0209 
0210     ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
0211                   "Table [%4.4s: %-8.8s] (id %.2X) - %4u Objects with %3u Devices, "
0212                   "%3u Regions, %4u Methods (%u/%u/%u Serial/Non/Cvt)\n",
0213                   table->signature, table->oem_table_id, owner_id,
0214                   info.object_count, info.device_count,
0215                   info.op_region_count, info.method_count,
0216                   info.serial_method_count,
0217                   info.non_serial_method_count,
0218                   info.serialized_method_count));
0219 
0220     ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "%u Methods, %u Regions\n",
0221               info.method_count, info.op_region_count));
0222 
0223     return_ACPI_STATUS(AE_OK);
0224 }