blob: f376fc00064e0c8cfa6f961da08906e225f19b63 [file] [log] [blame]
Erik Schmauss95857632018-03-14 16:13:07 -07001// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/******************************************************************************
3 *
4 * Module Name: excreate - Named object creation
5 *
Bob Moore840c02c2019-01-14 09:55:25 -08006 * Copyright (C) 2000 - 2019, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
Erik Schmauss95857632018-03-14 16:13:07 -07008 *****************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050011#include "accommon.h"
12#include "acinterp.h"
13#include "amlcode.h"
14#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#define _COMPONENT ACPI_EXECUTER
Len Brown4be44fc2005-08-05 00:44:28 -040017ACPI_MODULE_NAME("excreate")
Robert Moore44f6c012005-04-18 22:49:35 -040018/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 *
20 * FUNCTION: acpi_ex_create_alias
21 *
22 * PARAMETERS: walk_state - Current state, contains operands
23 *
24 * RETURN: Status
25 *
26 * DESCRIPTION: Create a new named alias
27 *
Robert Moore44f6c012005-04-18 22:49:35 -040028 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040029acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
Len Brown4be44fc2005-08-05 00:44:28 -040031 struct acpi_namespace_node *target_node;
32 struct acpi_namespace_node *alias_node;
33 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Bob Mooreb229cf92006-04-21 17:15:00 -040035 ACPI_FUNCTION_TRACE(ex_create_alias);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37 /* Get the source/alias operands (both namespace nodes) */
38
Len Brown4be44fc2005-08-05 00:44:28 -040039 alias_node = (struct acpi_namespace_node *)walk_state->operands[0];
40 target_node = (struct acpi_namespace_node *)walk_state->operands[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42 if ((target_node->type == ACPI_TYPE_LOCAL_ALIAS) ||
Len Brown4be44fc2005-08-05 00:44:28 -040043 (target_node->type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 /*
45 * Dereference an existing alias so that we don't create a chain
Bob Moore73a30902012-10-31 02:26:55 +000046 * of aliases. With this code, we guarantee that an alias is
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 * always exactly one level of indirection away from the
48 * actual aliased name.
49 */
Len Brown4be44fc2005-08-05 00:44:28 -040050 target_node =
51 ACPI_CAST_PTR(struct acpi_namespace_node,
52 target_node->object);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 }
54
Alex James4e6cbe52017-07-10 15:24:02 +080055 /* Ensure that the target node is valid */
Bob Moorea5b6e982017-08-03 14:27:09 +080056
Alex James4e6cbe52017-07-10 15:24:02 +080057 if (!target_node) {
58 return_ACPI_STATUS(AE_NULL_OBJECT);
59 }
60
Bob Moorea5b6e982017-08-03 14:27:09 +080061 /* Construct the alias object (a namespace node) */
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 switch (target_node->type) {
Bob Moorea5b6e982017-08-03 14:27:09 +080064 case ACPI_TYPE_METHOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 /*
Bob Moorea5b6e982017-08-03 14:27:09 +080066 * Control method aliases need to be differentiated with
67 * a special type
Bob Moore53cf1742008-04-10 19:06:39 +040068 */
Bob Moorea5b6e982017-08-03 14:27:09 +080069 alias_node->type = ACPI_TYPE_LOCAL_METHOD_ALIAS;
70 break;
71
72 default:
Bob Moore53cf1742008-04-10 19:06:39 +040073 /*
Bob Moorea5b6e982017-08-03 14:27:09 +080074 * All other object types.
75 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 * The new alias has the type ALIAS and points to the original
Bob Moore53cf1742008-04-10 19:06:39 +040077 * NS node, not the object itself.
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 */
79 alias_node->type = ACPI_TYPE_LOCAL_ALIAS;
Len Brown4be44fc2005-08-05 00:44:28 -040080 alias_node->object =
81 ACPI_CAST_PTR(union acpi_operand_object, target_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 }
84
85 /* Since both operands are Nodes, we don't need to delete them */
86
Bob Moorea5b6e982017-08-03 14:27:09 +080087 alias_node->object =
88 ACPI_CAST_PTR(union acpi_operand_object, target_node);
Len Brown4be44fc2005-08-05 00:44:28 -040089 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
Robert Moore44f6c012005-04-18 22:49:35 -040092/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 *
94 * FUNCTION: acpi_ex_create_event
95 *
96 * PARAMETERS: walk_state - Current state
97 *
98 * RETURN: Status
99 *
100 * DESCRIPTION: Create a new event object
101 *
Robert Moore44f6c012005-04-18 22:49:35 -0400102 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Len Brown4be44fc2005-08-05 00:44:28 -0400104acpi_status acpi_ex_create_event(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
Len Brown4be44fc2005-08-05 00:44:28 -0400106 acpi_status status;
107 union acpi_operand_object *obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Bob Mooreb229cf92006-04-21 17:15:00 -0400109 ACPI_FUNCTION_TRACE(ex_create_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Len Brown4be44fc2005-08-05 00:44:28 -0400111 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_EVENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 if (!obj_desc) {
113 status = AE_NO_MEMORY;
114 goto cleanup;
115 }
116
117 /*
118 * Create the actual OS semaphore, with zero initial units -- meaning
119 * that the event is created in an unsignalled state
120 */
Len Brown4be44fc2005-08-05 00:44:28 -0400121 status = acpi_os_create_semaphore(ACPI_NO_UNIT_LIMIT, 0,
Bob Moore967440e32006-06-23 17:04:00 -0400122 &obj_desc->event.os_semaphore);
Len Brown4be44fc2005-08-05 00:44:28 -0400123 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 goto cleanup;
125 }
126
127 /* Attach object to the Node */
128
Bob Moore1fad8732015-12-29 13:54:36 +0800129 status = acpi_ns_attach_object((struct acpi_namespace_node *)
130 walk_state->operands[0], obj_desc,
131 ACPI_TYPE_EVENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Lv Zheng10622bf2013-10-29 09:30:02 +0800133cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 /*
135 * Remove local reference to the object (on error, will cause deletion
136 * of both object and semaphore if present.)
137 */
Len Brown4be44fc2005-08-05 00:44:28 -0400138 acpi_ut_remove_reference(obj_desc);
139 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}
141
Robert Moore44f6c012005-04-18 22:49:35 -0400142/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 *
144 * FUNCTION: acpi_ex_create_mutex
145 *
146 * PARAMETERS: walk_state - Current state
147 *
148 * RETURN: Status
149 *
150 * DESCRIPTION: Create a new mutex object
151 *
152 * Mutex (Name[0], sync_level[1])
153 *
Robert Moore44f6c012005-04-18 22:49:35 -0400154 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Len Brown4be44fc2005-08-05 00:44:28 -0400156acpi_status acpi_ex_create_mutex(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
Len Brown4be44fc2005-08-05 00:44:28 -0400158 acpi_status status = AE_OK;
159 union acpi_operand_object *obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Bob Mooreb229cf92006-04-21 17:15:00 -0400161 ACPI_FUNCTION_TRACE_PTR(ex_create_mutex, ACPI_WALK_OPERANDS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 /* Create the new mutex object */
164
Len Brown4be44fc2005-08-05 00:44:28 -0400165 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_MUTEX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 if (!obj_desc) {
167 status = AE_NO_MEMORY;
168 goto cleanup;
169 }
170
Bob Moore967440e32006-06-23 17:04:00 -0400171 /* Create the actual OS Mutex */
172
173 status = acpi_os_create_mutex(&obj_desc->mutex.os_mutex);
Len Brown4be44fc2005-08-05 00:44:28 -0400174 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 goto cleanup;
176 }
177
178 /* Init object and attach to NS node */
179
Lv Zheng1f86e8c2012-10-31 02:25:45 +0000180 obj_desc->mutex.sync_level = (u8)walk_state->operands[1]->integer.value;
Len Brown4be44fc2005-08-05 00:44:28 -0400181 obj_desc->mutex.node =
182 (struct acpi_namespace_node *)walk_state->operands[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Bob Moore616861242006-03-17 16:44:00 -0500184 status =
185 acpi_ns_attach_object(obj_desc->mutex.node, obj_desc,
186 ACPI_TYPE_MUTEX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Lv Zheng10622bf2013-10-29 09:30:02 +0800188cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 /*
190 * Remove local reference to the object (on error, will cause deletion
191 * of both object and semaphore if present.)
192 */
Len Brown4be44fc2005-08-05 00:44:28 -0400193 acpi_ut_remove_reference(obj_desc);
194 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195}
196
Robert Moore44f6c012005-04-18 22:49:35 -0400197/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 *
199 * FUNCTION: acpi_ex_create_region
200 *
201 * PARAMETERS: aml_start - Pointer to the region declaration AML
202 * aml_length - Max length of the declaration AML
Bob Mooreec463662011-11-30 09:35:05 +0800203 * space_id - Address space ID for the region
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 * walk_state - Current state
205 *
206 * RETURN: Status
207 *
208 * DESCRIPTION: Create a new operation region object
209 *
Robert Moore44f6c012005-04-18 22:49:35 -0400210 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400213acpi_ex_create_region(u8 * aml_start,
214 u32 aml_length,
Bob Mooreec463662011-11-30 09:35:05 +0800215 u8 space_id, struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216{
Len Brown4be44fc2005-08-05 00:44:28 -0400217 acpi_status status;
218 union acpi_operand_object *obj_desc;
219 struct acpi_namespace_node *node;
220 union acpi_operand_object *region_obj2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Bob Mooreb229cf92006-04-21 17:15:00 -0400222 ACPI_FUNCTION_TRACE(ex_create_region);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
224 /* Get the Namespace Node */
225
226 node = walk_state->op->common.node;
227
228 /*
229 * If the region object is already attached to this node,
230 * just return
231 */
Len Brown4be44fc2005-08-05 00:44:28 -0400232 if (acpi_ns_get_attached_object(node)) {
233 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 }
235
236 /*
237 * Space ID must be one of the predefined IDs, or in the user-defined
238 * range
239 */
Bob Mooreec463662011-11-30 09:35:05 +0800240 if (!acpi_is_valid_space_id(space_id)) {
241 /*
242 * Print an error message, but continue. We don't want to abort
243 * a table load for this exception. Instead, if the region is
244 * actually used at runtime, abort the executing method.
245 */
246 ACPI_ERROR((AE_INFO,
247 "Invalid/unknown Address Space ID: 0x%2.2X",
248 space_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 }
250
Bob Mooref6a22b02010-03-05 17:56:40 +0800251 ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "Region Type - %s (0x%X)\n",
Bob Mooreec463662011-11-30 09:35:05 +0800252 acpi_ut_get_region_name(space_id), space_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254 /* Create the region descriptor */
255
Len Brown4be44fc2005-08-05 00:44:28 -0400256 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_REGION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 if (!obj_desc) {
258 status = AE_NO_MEMORY;
259 goto cleanup;
260 }
261
262 /*
263 * Remember location in AML stream of address & length
264 * operands since they need to be evaluated at run time.
265 */
Lv Zheng849c2572015-12-29 14:02:58 +0800266 region_obj2 = acpi_ns_get_secondary_object(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 region_obj2->extra.aml_start = aml_start;
268 region_obj2->extra.aml_length = aml_length;
Lv Zheng849c2572015-12-29 14:02:58 +0800269 region_obj2->extra.method_REG = NULL;
Lin Ming8931d9e2011-11-28 09:46:02 +0800270 if (walk_state->scope_info) {
271 region_obj2->extra.scope_node =
272 walk_state->scope_info->scope.node;
273 } else {
274 region_obj2->extra.scope_node = node;
275 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277 /* Init the region from the operands */
278
Bob Mooreec463662011-11-30 09:35:05 +0800279 obj_desc->region.space_id = space_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 obj_desc->region.address = 0;
281 obj_desc->region.length = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400282 obj_desc->region.node = node;
Lv Zheng849c2572015-12-29 14:02:58 +0800283 obj_desc->region.handler = NULL;
284 obj_desc->common.flags &=
Lv Zhengefaed9b2015-12-29 14:03:08 +0800285 ~(AOPOBJ_SETUP_COMPLETE | AOPOBJ_REG_CONNECTED |
286 AOPOBJ_OBJECT_INITIALIZED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288 /* Install the new region object in the parent Node */
289
Len Brown4be44fc2005-08-05 00:44:28 -0400290 status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_REGION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Lv Zheng10622bf2013-10-29 09:30:02 +0800292cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294 /* Remove local reference to the object */
295
Len Brown4be44fc2005-08-05 00:44:28 -0400296 acpi_ut_remove_reference(obj_desc);
297 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
299
Robert Moore44f6c012005-04-18 22:49:35 -0400300/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 * FUNCTION: acpi_ex_create_processor
303 *
304 * PARAMETERS: walk_state - Current state
305 *
306 * RETURN: Status
307 *
308 * DESCRIPTION: Create a new processor object and populate the fields
309 *
Bob Mooreba494be2012-07-12 09:40:10 +0800310 * Processor (Name[0], cpu_ID[1], pblock_addr[2], pblock_length[3])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 *
Robert Moore44f6c012005-04-18 22:49:35 -0400312 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Len Brown4be44fc2005-08-05 00:44:28 -0400314acpi_status acpi_ex_create_processor(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
Len Brown4be44fc2005-08-05 00:44:28 -0400316 union acpi_operand_object **operand = &walk_state->operands[0];
317 union acpi_operand_object *obj_desc;
318 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Bob Mooreb229cf92006-04-21 17:15:00 -0400320 ACPI_FUNCTION_TRACE_PTR(ex_create_processor, walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322 /* Create the processor object */
323
Len Brown4be44fc2005-08-05 00:44:28 -0400324 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PROCESSOR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400326 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 }
328
Robert Moore44f6c012005-04-18 22:49:35 -0400329 /* Initialize the processor object from the operands */
330
Len Brown4be44fc2005-08-05 00:44:28 -0400331 obj_desc->processor.proc_id = (u8) operand[1]->integer.value;
Bob Moore616861242006-03-17 16:44:00 -0500332 obj_desc->processor.length = (u8) operand[3]->integer.value;
Len Brown4be44fc2005-08-05 00:44:28 -0400333 obj_desc->processor.address =
Lv Zhengf5c1e1c2016-05-05 12:57:53 +0800334 (acpi_io_address)operand[2]->integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336 /* Install the processor object in the parent Node */
337
Len Brown4be44fc2005-08-05 00:44:28 -0400338 status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0],
339 obj_desc, ACPI_TYPE_PROCESSOR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
341 /* Remove local reference to the object */
342
Len Brown4be44fc2005-08-05 00:44:28 -0400343 acpi_ut_remove_reference(obj_desc);
344 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345}
346
Robert Moore44f6c012005-04-18 22:49:35 -0400347/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 *
349 * FUNCTION: acpi_ex_create_power_resource
350 *
351 * PARAMETERS: walk_state - Current state
352 *
353 * RETURN: Status
354 *
355 * DESCRIPTION: Create a new power_resource object and populate the fields
356 *
357 * power_resource (Name[0], system_level[1], resource_order[2])
358 *
Robert Moore44f6c012005-04-18 22:49:35 -0400359 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Len Brown4be44fc2005-08-05 00:44:28 -0400361acpi_status acpi_ex_create_power_resource(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
Len Brown4be44fc2005-08-05 00:44:28 -0400363 union acpi_operand_object **operand = &walk_state->operands[0];
364 acpi_status status;
365 union acpi_operand_object *obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Bob Mooreb229cf92006-04-21 17:15:00 -0400367 ACPI_FUNCTION_TRACE_PTR(ex_create_power_resource, walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
369 /* Create the power resource object */
370
Len Brown4be44fc2005-08-05 00:44:28 -0400371 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_POWER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400373 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 }
375
376 /* Initialize the power object from the operands */
377
378 obj_desc->power_resource.system_level = (u8) operand[1]->integer.value;
Len Brown4be44fc2005-08-05 00:44:28 -0400379 obj_desc->power_resource.resource_order =
380 (u16) operand[2]->integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
382 /* Install the power resource object in the parent Node */
383
Len Brown4be44fc2005-08-05 00:44:28 -0400384 status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0],
385 obj_desc, ACPI_TYPE_POWER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
387 /* Remove local reference to the object */
388
Len Brown4be44fc2005-08-05 00:44:28 -0400389 acpi_ut_remove_reference(obj_desc);
390 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Robert Moore44f6c012005-04-18 22:49:35 -0400393/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 *
395 * FUNCTION: acpi_ex_create_method
396 *
397 * PARAMETERS: aml_start - First byte of the method's AML
398 * aml_length - AML byte count for this method
399 * walk_state - Current state
400 *
401 * RETURN: Status
402 *
403 * DESCRIPTION: Create a new method object
404 *
Robert Moore44f6c012005-04-18 22:49:35 -0400405 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
407acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400408acpi_ex_create_method(u8 * aml_start,
409 u32 aml_length, struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
Len Brown4be44fc2005-08-05 00:44:28 -0400411 union acpi_operand_object **operand = &walk_state->operands[0];
412 union acpi_operand_object *obj_desc;
413 acpi_status status;
414 u8 method_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Bob Mooreb229cf92006-04-21 17:15:00 -0400416 ACPI_FUNCTION_TRACE_PTR(ex_create_method, walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418 /* Create a new method object */
419
Len Brown4be44fc2005-08-05 00:44:28 -0400420 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 if (!obj_desc) {
Bob Mooref3d2e782007-02-02 19:48:18 +0300422 status = AE_NO_MEMORY;
423 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 }
425
426 /* Save the method's AML pointer and length */
427
428 obj_desc->method.aml_start = aml_start;
429 obj_desc->method.aml_length = aml_length;
Lv Zheng07b9c912015-07-23 12:52:31 +0800430 obj_desc->method.node = operand[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432 /*
Lin Ming26294842011-01-12 09:19:43 +0800433 * Disassemble the method flags. Split off the arg_count, Serialized
434 * flag, and sync_level for efficiency.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 */
Lv Zheng5431b652015-12-29 13:52:32 +0800436 method_flags = (u8)operand[1]->integer.value;
Bob Moore1fad8732015-12-29 13:54:36 +0800437 obj_desc->method.param_count = (u8)
438 (method_flags & AML_METHOD_ARG_COUNT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440 /*
Bob Moore967440e32006-06-23 17:04:00 -0400441 * Get the sync_level. If method is serialized, a mutex will be
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 * created for this method when it is parsed.
443 */
Len Brown4d2acd92007-05-09 22:56:38 -0400444 if (method_flags & AML_METHOD_SERIALIZED) {
Lin Ming26294842011-01-12 09:19:43 +0800445 obj_desc->method.info_flags = ACPI_METHOD_SERIALIZED;
446
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 /*
Bob Moore967440e32006-06-23 17:04:00 -0400448 * ACPI 1.0: sync_level = 0
449 * ACPI 2.0: sync_level = sync_level in method declaration
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 */
Bob Moore967440e32006-06-23 17:04:00 -0400451 obj_desc->method.sync_level = (u8)
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800452 ((method_flags & AML_METHOD_SYNC_LEVEL) >> 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 }
454
455 /* Attach the new object to the method Node */
456
Len Brown4be44fc2005-08-05 00:44:28 -0400457 status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0],
458 obj_desc, ACPI_TYPE_METHOD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460 /* Remove local reference to the object */
461
Len Brown4be44fc2005-08-05 00:44:28 -0400462 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Lv Zheng10622bf2013-10-29 09:30:02 +0800464exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 /* Remove a reference to the operand */
466
Len Brown4be44fc2005-08-05 00:44:28 -0400467 acpi_ut_remove_reference(operand[1]);
468 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469}