// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.01/******************************************************************************2*3* Module Name: dsinit - Object initialization namespace walk4*5* Copyright (C) 2000 - 2025, Intel Corp.6*7*****************************************************************************/89#include <acpi/acpi.h>10#include "accommon.h"11#include "acdispat.h"12#include "acnamesp.h"13#include "actables.h"14#include "acinterp.h"1516#define _COMPONENT ACPI_DISPATCHER17ACPI_MODULE_NAME("dsinit")1819/* Local prototypes */20static acpi_status21acpi_ds_init_one_object(acpi_handle obj_handle,22u32 level, void *context, void **return_value);2324/*******************************************************************************25*26* FUNCTION: acpi_ds_init_one_object27*28* PARAMETERS: obj_handle - Node for the object29* level - Current nesting level30* context - Points to a init info struct31* return_value - Not used32*33* RETURN: Status34*35* DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object36* within the namespace.37*38* Currently, the only objects that require initialization are:39* 1) Methods40* 2) Operation Regions41*42******************************************************************************/4344static acpi_status45acpi_ds_init_one_object(acpi_handle obj_handle,46u32 level, void *context, void **return_value)47{48struct acpi_init_walk_info *info =49(struct acpi_init_walk_info *)context;50struct acpi_namespace_node *node =51(struct acpi_namespace_node *)obj_handle;52acpi_status status;53union acpi_operand_object *obj_desc;5455ACPI_FUNCTION_ENTRY();5657/*58* We are only interested in NS nodes owned by the table that59* was just loaded60*/61if (node->owner_id != info->owner_id) {62return (AE_OK);63}6465info->object_count++;6667/* And even then, we are only interested in a few object types */6869switch (acpi_ns_get_type(obj_handle)) {70case ACPI_TYPE_REGION:7172status = acpi_ds_initialize_region(obj_handle);73if (ACPI_FAILURE(status)) {74ACPI_EXCEPTION((AE_INFO, status,75"During Region initialization %p [%4.4s]",76obj_handle,77acpi_ut_get_node_name(obj_handle)));78}7980info->op_region_count++;81break;8283case ACPI_TYPE_METHOD:84/*85* Auto-serialization support. We will examine each method that is86* not_serialized to determine if it creates any Named objects. If87* it does, it will be marked serialized to prevent problems if88* the method is entered by two or more threads and an attempt is89* made to create the same named object twice -- which results in90* an AE_ALREADY_EXISTS exception and method abort.91*/92info->method_count++;93obj_desc = acpi_ns_get_attached_object(node);94if (!obj_desc) {95break;96}9798/* Ignore if already serialized */99100if (obj_desc->method.info_flags & ACPI_METHOD_SERIALIZED) {101info->serial_method_count++;102break;103}104105if (acpi_gbl_auto_serialize_methods) {106107/* Parse/scan method and serialize it if necessary */108109acpi_ds_auto_serialize_method(node, obj_desc);110if (obj_desc->method.111info_flags & ACPI_METHOD_SERIALIZED) {112113/* Method was just converted to Serialized */114115info->serial_method_count++;116info->serialized_method_count++;117break;118}119}120121info->non_serial_method_count++;122break;123124case ACPI_TYPE_DEVICE:125126info->device_count++;127break;128129default:130131break;132}133134/*135* We ignore errors from above, and always return OK, since136* we don't want to abort the walk on a single error.137*/138return (AE_OK);139}140141/*******************************************************************************142*143* FUNCTION: acpi_ds_initialize_objects144*145* PARAMETERS: table_desc - Descriptor for parent ACPI table146* start_node - Root of subtree to be initialized.147*148* RETURN: Status149*150* DESCRIPTION: Walk the namespace starting at "StartNode" and perform any151* necessary initialization on the objects found therein152*153******************************************************************************/154155acpi_status156acpi_ds_initialize_objects(u32 table_index,157struct acpi_namespace_node *start_node)158{159acpi_status status;160struct acpi_init_walk_info info;161struct acpi_table_header *table;162acpi_owner_id owner_id;163164ACPI_FUNCTION_TRACE(ds_initialize_objects);165166status = acpi_tb_get_owner_id(table_index, &owner_id);167if (ACPI_FAILURE(status)) {168return_ACPI_STATUS(status);169}170171ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,172"**** Starting initialization of namespace objects ****\n"));173174/* Set all init info to zero */175176memset(&info, 0, sizeof(struct acpi_init_walk_info));177178info.owner_id = owner_id;179info.table_index = table_index;180181/* Walk entire namespace from the supplied root */182183/*184* We don't use acpi_walk_namespace since we do not want to acquire185* the namespace reader lock.186*/187status =188acpi_ns_walk_namespace(ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX,189ACPI_NS_WALK_NO_UNLOCK,190acpi_ds_init_one_object, NULL, &info, NULL);191if (ACPI_FAILURE(status)) {192ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));193}194195status = acpi_get_table_by_index(table_index, &table);196if (ACPI_FAILURE(status)) {197return_ACPI_STATUS(status);198}199200/* DSDT is always the first AML table */201202if (ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_DSDT)) {203ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,204"\nACPI table initialization:\n"));205}206207/* Summary of objects initialized */208209ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,210"Table [%4.4s: %-8.8s] (id %.2X) - %4u Objects with %3u Devices, "211"%3u Regions, %4u Methods (%u/%u/%u Serial/Non/Cvt)\n",212table->signature, table->oem_table_id, owner_id,213info.object_count, info.device_count,214info.op_region_count, info.method_count,215info.serial_method_count,216info.non_serial_method_count,217info.serialized_method_count));218219ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "%u Methods, %u Regions\n",220info.method_count, info.op_region_count));221222return_ACPI_STATUS(AE_OK);223}224225226