^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Module Name: dsinit - Object initialization namespace walk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2000 - 2020, Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <acpi/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "accommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "acdispat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "acnamesp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "actables.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "acinterp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define _COMPONENT ACPI_DISPATCHER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) ACPI_MODULE_NAME("dsinit")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /* Local prototypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) acpi_ds_init_one_object(acpi_handle obj_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) u32 level, void *context, void **return_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * FUNCTION: acpi_ds_init_one_object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * PARAMETERS: obj_handle - Node for the object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * level - Current nesting level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * context - Points to a init info struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * return_value - Not used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * within the namespace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * Currently, the only objects that require initialization are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * 1) Methods
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * 2) Operation Regions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) acpi_ds_init_one_object(acpi_handle obj_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) u32 level, void *context, void **return_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct acpi_init_walk_info *info =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) (struct acpi_init_walk_info *)context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct acpi_namespace_node *node =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) (struct acpi_namespace_node *)obj_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) union acpi_operand_object *obj_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) ACPI_FUNCTION_ENTRY();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * We are only interested in NS nodes owned by the table that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * was just loaded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (node->owner_id != info->owner_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) info->object_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* And even then, we are only interested in a few object types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) switch (acpi_ns_get_type(obj_handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) case ACPI_TYPE_REGION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) status = acpi_ds_initialize_region(obj_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) ACPI_EXCEPTION((AE_INFO, status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) "During Region initialization %p [%4.4s]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) obj_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) acpi_ut_get_node_name(obj_handle)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) info->op_region_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) case ACPI_TYPE_METHOD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * Auto-serialization support. We will examine each method that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * not_serialized to determine if it creates any Named objects. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * it does, it will be marked serialized to prevent problems if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * the method is entered by two or more threads and an attempt is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * made to create the same named object twice -- which results in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * an AE_ALREADY_EXISTS exception and method abort.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) info->method_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) obj_desc = acpi_ns_get_attached_object(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (!obj_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* Ignore if already serialized */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (obj_desc->method.info_flags & ACPI_METHOD_SERIALIZED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) info->serial_method_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (acpi_gbl_auto_serialize_methods) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* Parse/scan method and serialize it if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) acpi_ds_auto_serialize_method(node, obj_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (obj_desc->method.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) info_flags & ACPI_METHOD_SERIALIZED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /* Method was just converted to Serialized */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) info->serial_method_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) info->serialized_method_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) info->non_serial_method_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) case ACPI_TYPE_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) info->device_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * We ignore errors from above, and always return OK, since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * we don't want to abort the walk on a single error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * FUNCTION: acpi_ds_initialize_objects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * PARAMETERS: table_desc - Descriptor for parent ACPI table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * start_node - Root of subtree to be initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * necessary initialization on the objects found therein
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) acpi_ds_initialize_objects(u32 table_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct acpi_namespace_node *start_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct acpi_init_walk_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct acpi_table_header *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) acpi_owner_id owner_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) ACPI_FUNCTION_TRACE(ds_initialize_objects);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) status = acpi_tb_get_owner_id(table_index, &owner_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) "**** Starting initialization of namespace objects ****\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /* Set all init info to zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) memset(&info, 0, sizeof(struct acpi_init_walk_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) info.owner_id = owner_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) info.table_index = table_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* Walk entire namespace from the supplied root */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * We don't use acpi_walk_namespace since we do not want to acquire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * the namespace reader lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) acpi_ns_walk_namespace(ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) ACPI_NS_WALK_NO_UNLOCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) acpi_ds_init_one_object, NULL, &info, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) status = acpi_get_table_by_index(table_index, &table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /* DSDT is always the first AML table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_DSDT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) "\nACPI table initialization:\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /* Summary of objects initialized */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) "Table [%4.4s: %-8.8s] (id %.2X) - %4u Objects with %3u Devices, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) "%3u Regions, %4u Methods (%u/%u/%u Serial/Non/Cvt)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) table->signature, table->oem_table_id, owner_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) info.object_count, info.device_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) info.op_region_count, info.method_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) info.serial_method_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) info.non_serial_method_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) info.serialized_method_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "%u Methods, %u Regions\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) info.method_count, info.op_region_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }