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