blob: e87f6bfbfa5c9a979961f6a3e8a5c45d716829e3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: dsfield - Dispatcher field routines
4 *
5 *****************************************************************************/
6
7/*
Bob Moore6c9deb72007-02-02 19:48:24 +03008 * Copyright (C) 2000 - 2007, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/amlcode.h>
46#include <acpi/acdispat.h>
47#include <acpi/acinterp.h>
48#include <acpi/acnamesp.h>
49#include <acpi/acparser.h>
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define _COMPONENT ACPI_DISPATCHER
Len Brown4be44fc2005-08-05 00:44:28 -040052ACPI_MODULE_NAME("dsfield")
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Robert Moore44f6c012005-04-18 22:49:35 -040054/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040055static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040056acpi_ds_get_field_names(struct acpi_create_field_info *info,
57 struct acpi_walk_state *walk_state,
58 union acpi_parse_object *arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60/*******************************************************************************
61 *
62 * FUNCTION: acpi_ds_create_buffer_field
63 *
Robert Moore44f6c012005-04-18 22:49:35 -040064 * PARAMETERS: Op - Current parse op (create_xXField)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 * walk_state - Current state
66 *
67 * RETURN: Status
68 *
69 * DESCRIPTION: Execute the create_field operators:
70 * create_bit_field_op,
71 * create_byte_field_op,
72 * create_word_field_op,
73 * create_dword_field_op,
74 * create_qword_field_op,
Robert Moore44f6c012005-04-18 22:49:35 -040075 * create_field_op (all of which define a field in a buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 *
77 ******************************************************************************/
78
79acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040080acpi_ds_create_buffer_field(union acpi_parse_object *op,
81 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
Len Brown4be44fc2005-08-05 00:44:28 -040083 union acpi_parse_object *arg;
84 struct acpi_namespace_node *node;
85 acpi_status status;
86 union acpi_operand_object *obj_desc;
87 union acpi_operand_object *second_desc = NULL;
88 u32 flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Bob Mooreb229cf92006-04-21 17:15:00 -040090 ACPI_FUNCTION_TRACE(ds_create_buffer_field);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 /* Get the name_string argument */
93
94 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
Len Brown4be44fc2005-08-05 00:44:28 -040095 arg = acpi_ps_get_arg(op, 3);
96 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 /* Create Bit/Byte/Word/Dword field */
98
Len Brown4be44fc2005-08-05 00:44:28 -040099 arg = acpi_ps_get_arg(op, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 }
101
102 if (!arg) {
Len Brown4be44fc2005-08-05 00:44:28 -0400103 return_ACPI_STATUS(AE_AML_NO_OPERAND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 }
105
106 if (walk_state->deferred_node) {
107 node = walk_state->deferred_node;
108 status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400109 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 /*
111 * During the load phase, we want to enter the name of the field into
112 * the namespace. During the execute phase (when we evaluate the size
113 * operand), we want to lookup the name
114 */
115 if (walk_state->parse_flags & ACPI_PARSE_EXECUTE) {
116 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE;
Len Brown4be44fc2005-08-05 00:44:28 -0400117 } else {
Robert Moore44f6c012005-04-18 22:49:35 -0400118 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
Len Brown4be44fc2005-08-05 00:44:28 -0400119 ACPI_NS_ERROR_IF_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 }
121
122 /*
123 * Enter the name_string into the namespace
124 */
Len Brown4be44fc2005-08-05 00:44:28 -0400125 status =
126 acpi_ns_lookup(walk_state->scope_info,
127 arg->common.value.string, ACPI_TYPE_ANY,
128 ACPI_IMODE_LOAD_PASS1, flags, walk_state,
129 &(node));
130 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500131 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
Len Brown4be44fc2005-08-05 00:44:28 -0400132 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 }
134 }
135
Bob Moore9c526572007-02-02 19:48:18 +0300136 /*
137 * We could put the returned object (Node) on the object stack for later,
Robert Moore44f6c012005-04-18 22:49:35 -0400138 * but for now, we will put it in the "op" object that the parser uses,
139 * so we can get it again at the end of this scope
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 */
141 op->common.node = node;
142
143 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400144 * If there is no object attached to the node, this node was just created
145 * and we need to create the field object. Otherwise, this was a lookup
146 * of an existing node and we don't want to create the field object again.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 */
Len Brown4be44fc2005-08-05 00:44:28 -0400148 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 if (obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400150 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 }
152
153 /*
154 * The Field definition is not fully parsed at this time.
155 * (We must save the address of the AML for the buffer and index operands)
156 */
157
158 /* Create the buffer field object */
159
Len Brown4be44fc2005-08-05 00:44:28 -0400160 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER_FIELD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 if (!obj_desc) {
162 status = AE_NO_MEMORY;
163 goto cleanup;
164 }
165
166 /*
167 * Remember location in AML stream of the field unit
168 * opcode and operands -- since the buffer and index
169 * operands must be evaluated.
170 */
Len Brown4be44fc2005-08-05 00:44:28 -0400171 second_desc = obj_desc->common.next_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 second_desc->extra.aml_start = op->named.data;
173 second_desc->extra.aml_length = op->named.length;
174 obj_desc->buffer_field.node = node;
175
176 /* Attach constructed field descriptors to parent node */
177
Len Brown4be44fc2005-08-05 00:44:28 -0400178 status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_BUFFER_FIELD);
179 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 goto cleanup;
181 }
182
Len Brown4be44fc2005-08-05 00:44:28 -0400183 cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 /* Remove local reference to the object */
186
Len Brown4be44fc2005-08-05 00:44:28 -0400187 acpi_ut_remove_reference(obj_desc);
188 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189}
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191/*******************************************************************************
192 *
193 * FUNCTION: acpi_ds_get_field_names
194 *
195 * PARAMETERS: Info - create_field info structure
196 * ` walk_state - Current method state
197 * Arg - First parser arg for the field name list
198 *
199 * RETURN: Status
200 *
201 * DESCRIPTION: Process all named fields in a field declaration. Names are
202 * entered into the namespace.
203 *
204 ******************************************************************************/
205
Robert Moore44f6c012005-04-18 22:49:35 -0400206static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400207acpi_ds_get_field_names(struct acpi_create_field_info *info,
208 struct acpi_walk_state *walk_state,
209 union acpi_parse_object *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
Len Brown4be44fc2005-08-05 00:44:28 -0400211 acpi_status status;
212 acpi_integer position;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Bob Mooreb229cf92006-04-21 17:15:00 -0400214 ACPI_FUNCTION_TRACE_PTR(ds_get_field_names, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 /* First field starts at bit zero */
217
218 info->field_bit_position = 0;
219
220 /* Process all elements in the field list (of parse nodes) */
221
222 while (arg) {
223 /*
224 * Three types of field elements are handled:
225 * 1) Offset - specifies a bit offset
226 * 2) access_as - changes the access mode
227 * 3) Name - Enters a new named field into the namespace
228 */
229 switch (arg->common.aml_opcode) {
230 case AML_INT_RESERVEDFIELD_OP:
231
232 position = (acpi_integer) info->field_bit_position
Len Brown4be44fc2005-08-05 00:44:28 -0400233 + (acpi_integer) arg->common.value.size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 if (position > ACPI_UINT32_MAX) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500236 ACPI_ERROR((AE_INFO,
237 "Bit offset within field too large (> 0xFFFFFFFF)"));
Len Brown4be44fc2005-08-05 00:44:28 -0400238 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 }
240
241 info->field_bit_position = (u32) position;
242 break;
243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 case AML_INT_ACCESSFIELD_OP:
245
246 /*
247 * Get a new access_type and access_attribute -- to be used for all
Robert Moore44f6c012005-04-18 22:49:35 -0400248 * field units that follow, until field end or another access_as
249 * keyword.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 *
Robert Moore44f6c012005-04-18 22:49:35 -0400251 * In field_flags, preserve the flag bits other than the
252 * ACCESS_TYPE bits
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 */
Robert Moore44f6c012005-04-18 22:49:35 -0400254 info->field_flags = (u8)
Len Brown4be44fc2005-08-05 00:44:28 -0400255 ((info->
256 field_flags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
257 ((u8) ((u32) arg->common.value.integer >> 8)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
259 info->attribute = (u8) (arg->common.value.integer);
260 break;
261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 case AML_INT_NAMEDFIELD_OP:
263
264 /* Lookup the name */
265
Len Brown4be44fc2005-08-05 00:44:28 -0400266 status = acpi_ns_lookup(walk_state->scope_info,
267 (char *)&arg->named.name,
268 info->field_type,
269 ACPI_IMODE_EXECUTE,
270 ACPI_NS_DONT_OPEN_SCOPE,
271 walk_state, &info->field_node);
272 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500273 ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
274 status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 if (status != AE_ALREADY_EXISTS) {
Len Brown4be44fc2005-08-05 00:44:28 -0400276 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 }
278
279 /* Already exists, ignore error */
Len Brown4be44fc2005-08-05 00:44:28 -0400280 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 arg->common.node = info->field_node;
282 info->field_bit_length = arg->common.value.size;
283
Lin Mingef805d92008-04-10 19:06:41 +0400284 /*
285 * If there is no object attached to the node, this node was just created
286 * and we need to create the field object. Otherwise, this was a lookup
287 * of an existing node and we don't want to create the field object again.
288 */
289 if (!acpi_ns_get_attached_object
290 (info->field_node)) {
291 status = acpi_ex_prep_field_value(info);
292 if (ACPI_FAILURE(status)) {
293 return_ACPI_STATUS(status);
294 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 }
296 }
297
298 /* Keep track of bit position for the next field */
299
300 position = (acpi_integer) info->field_bit_position
Len Brown4be44fc2005-08-05 00:44:28 -0400301 + (acpi_integer) arg->common.value.size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303 if (position > ACPI_UINT32_MAX) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500304 ACPI_ERROR((AE_INFO,
305 "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
306 ACPI_CAST_PTR(char,
307 &info->field_node->
308 name)));
Len Brown4be44fc2005-08-05 00:44:28 -0400309 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
311
312 info->field_bit_position += info->field_bit_length;
313 break;
314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 default:
316
Bob Mooreb8e4d892006-01-27 16:43:00 -0500317 ACPI_ERROR((AE_INFO,
318 "Invalid opcode in field list: %X",
319 arg->common.aml_opcode));
Len Brown4be44fc2005-08-05 00:44:28 -0400320 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 }
322
323 arg = arg->common.next;
324 }
325
Len Brown4be44fc2005-08-05 00:44:28 -0400326 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327}
328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329/*******************************************************************************
330 *
331 * FUNCTION: acpi_ds_create_field
332 *
333 * PARAMETERS: Op - Op containing the Field definition and args
334 * region_node - Object for the containing Operation Region
335 * ` walk_state - Current method state
336 *
337 * RETURN: Status
338 *
339 * DESCRIPTION: Create a new field in the specified operation region
340 *
341 ******************************************************************************/
342
343acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400344acpi_ds_create_field(union acpi_parse_object *op,
345 struct acpi_namespace_node *region_node,
346 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
Len Brown4be44fc2005-08-05 00:44:28 -0400348 acpi_status status;
349 union acpi_parse_object *arg;
350 struct acpi_create_field_info info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Bob Mooreb229cf92006-04-21 17:15:00 -0400352 ACPI_FUNCTION_TRACE_PTR(ds_create_field, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 /* First arg is the name of the parent op_region (must already exist) */
355
356 arg = op->common.value.arg;
357 if (!region_node) {
Len Brown4be44fc2005-08-05 00:44:28 -0400358 status =
359 acpi_ns_lookup(walk_state->scope_info,
360 arg->common.value.name, ACPI_TYPE_REGION,
361 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
362 walk_state, &region_node);
363 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500364 ACPI_ERROR_NAMESPACE(arg->common.value.name, status);
Len Brown4be44fc2005-08-05 00:44:28 -0400365 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 }
367 }
368
369 /* Second arg is the field flags */
370
371 arg = arg->common.next;
372 info.field_flags = (u8) arg->common.value.integer;
373 info.attribute = 0;
374
375 /* Each remaining arg is a Named Field */
376
377 info.field_type = ACPI_TYPE_LOCAL_REGION_FIELD;
378 info.region_node = region_node;
379
Len Brown4be44fc2005-08-05 00:44:28 -0400380 status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Len Brown4be44fc2005-08-05 00:44:28 -0400382 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383}
384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385/*******************************************************************************
386 *
387 * FUNCTION: acpi_ds_init_field_objects
388 *
389 * PARAMETERS: Op - Op containing the Field definition and args
390 * ` walk_state - Current method state
391 *
392 * RETURN: Status
393 *
394 * DESCRIPTION: For each "Field Unit" name in the argument list that is
395 * part of the field declaration, enter the name into the
396 * namespace.
397 *
398 ******************************************************************************/
399
400acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400401acpi_ds_init_field_objects(union acpi_parse_object *op,
402 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Len Brown4be44fc2005-08-05 00:44:28 -0400404 acpi_status status;
405 union acpi_parse_object *arg = NULL;
406 struct acpi_namespace_node *node;
407 u8 type = 0;
Lin Mingef805d92008-04-10 19:06:41 +0400408 u32 flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Bob Mooreb229cf92006-04-21 17:15:00 -0400410 ACPI_FUNCTION_TRACE_PTR(ds_init_field_objects, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Lin Mingef805d92008-04-10 19:06:41 +0400412 /*
413 * During the load phase, we want to enter the name of the field into
414 * the namespace. During the execute phase (when we evaluate the bank_value
415 * operand), we want to lookup the name.
416 */
417 if (walk_state->deferred_node) {
418 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE;
419 } else {
420 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
421 ACPI_NS_ERROR_IF_FOUND;
422 }
423
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 switch (walk_state->opcode) {
425 case AML_FIELD_OP:
Len Brown4be44fc2005-08-05 00:44:28 -0400426 arg = acpi_ps_get_arg(op, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 type = ACPI_TYPE_LOCAL_REGION_FIELD;
428 break;
429
430 case AML_BANK_FIELD_OP:
Len Brown4be44fc2005-08-05 00:44:28 -0400431 arg = acpi_ps_get_arg(op, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 type = ACPI_TYPE_LOCAL_BANK_FIELD;
433 break;
434
435 case AML_INDEX_FIELD_OP:
Len Brown4be44fc2005-08-05 00:44:28 -0400436 arg = acpi_ps_get_arg(op, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 type = ACPI_TYPE_LOCAL_INDEX_FIELD;
438 break;
439
440 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400441 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 }
443
444 /*
445 * Walk the list of entries in the field_list
446 */
447 while (arg) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 /* Ignore OFFSET and ACCESSAS terms here */
450
451 if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
Len Brown4be44fc2005-08-05 00:44:28 -0400452 status = acpi_ns_lookup(walk_state->scope_info,
453 (char *)&arg->named.name,
454 type, ACPI_IMODE_LOAD_PASS1,
Lin Mingef805d92008-04-10 19:06:41 +0400455 flags, walk_state, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400456 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500457 ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
458 status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 if (status != AE_ALREADY_EXISTS) {
Len Brown4be44fc2005-08-05 00:44:28 -0400460 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 }
462
463 /* Name already exists, just ignore this error */
464
465 status = AE_OK;
466 }
467
468 arg->common.node = node;
469 }
470
471 /* Move to next field in the list */
472
473 arg = arg->common.next;
474 }
475
Len Brown4be44fc2005-08-05 00:44:28 -0400476 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477}
478
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479/*******************************************************************************
480 *
481 * FUNCTION: acpi_ds_create_bank_field
482 *
483 * PARAMETERS: Op - Op containing the Field definition and args
484 * region_node - Object for the containing Operation Region
Lin Mingef805d92008-04-10 19:06:41 +0400485 * walk_state - Current method state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 *
487 * RETURN: Status
488 *
489 * DESCRIPTION: Create a new bank field in the specified operation region
490 *
491 ******************************************************************************/
492
493acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400494acpi_ds_create_bank_field(union acpi_parse_object *op,
495 struct acpi_namespace_node *region_node,
496 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497{
Len Brown4be44fc2005-08-05 00:44:28 -0400498 acpi_status status;
499 union acpi_parse_object *arg;
500 struct acpi_create_field_info info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
Bob Mooreb229cf92006-04-21 17:15:00 -0400502 ACPI_FUNCTION_TRACE_PTR(ds_create_bank_field, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
504 /* First arg is the name of the parent op_region (must already exist) */
505
506 arg = op->common.value.arg;
507 if (!region_node) {
Len Brown4be44fc2005-08-05 00:44:28 -0400508 status =
509 acpi_ns_lookup(walk_state->scope_info,
510 arg->common.value.name, ACPI_TYPE_REGION,
511 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
512 walk_state, &region_node);
513 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500514 ACPI_ERROR_NAMESPACE(arg->common.value.name, status);
Len Brown4be44fc2005-08-05 00:44:28 -0400515 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 }
517 }
518
519 /* Second arg is the Bank Register (Field) (must already exist) */
520
521 arg = arg->common.next;
Len Brown4be44fc2005-08-05 00:44:28 -0400522 status =
523 acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
524 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
525 ACPI_NS_SEARCH_PARENT, walk_state,
526 &info.register_node);
527 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500528 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
Len Brown4be44fc2005-08-05 00:44:28 -0400529 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 }
531
Lin Mingef805d92008-04-10 19:06:41 +0400532 /*
533 * Third arg is the bank_value
534 * This arg is a term_arg, not a constant
535 * It will be evaluated later, by acpi_ds_eval_bank_field_operands
536 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 arg = arg->common.next;
Bob Moore9c526572007-02-02 19:48:18 +0300538
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 /* Fourth arg is the field flags */
540
541 arg = arg->common.next;
542 info.field_flags = (u8) arg->common.value.integer;
543
544 /* Each remaining arg is a Named Field */
545
546 info.field_type = ACPI_TYPE_LOCAL_BANK_FIELD;
547 info.region_node = region_node;
548
Lin Mingef805d92008-04-10 19:06:41 +0400549 /*
550 * Use Info.data_register_node to store bank_field Op
551 * It's safe because data_register_node will never be used when create bank field
552 * We store aml_start and aml_length in the bank_field Op for late evaluation
553 * Used in acpi_ex_prep_field_value(Info)
554 *
555 * TBD: Or, should we add a field in struct acpi_create_field_info, like "void *ParentOp"?
556 */
557 info.data_register_node = (struct acpi_namespace_node *)op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Lin Mingef805d92008-04-10 19:06:41 +0400559 status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
Len Brown4be44fc2005-08-05 00:44:28 -0400560 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561}
562
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563/*******************************************************************************
564 *
565 * FUNCTION: acpi_ds_create_index_field
566 *
567 * PARAMETERS: Op - Op containing the Field definition and args
568 * region_node - Object for the containing Operation Region
569 * ` walk_state - Current method state
570 *
571 * RETURN: Status
572 *
573 * DESCRIPTION: Create a new index field in the specified operation region
574 *
575 ******************************************************************************/
576
577acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400578acpi_ds_create_index_field(union acpi_parse_object *op,
579 struct acpi_namespace_node *region_node,
580 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
Len Brown4be44fc2005-08-05 00:44:28 -0400582 acpi_status status;
583 union acpi_parse_object *arg;
584 struct acpi_create_field_info info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Bob Mooreb229cf92006-04-21 17:15:00 -0400586 ACPI_FUNCTION_TRACE_PTR(ds_create_index_field, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588 /* First arg is the name of the Index register (must already exist) */
589
590 arg = op->common.value.arg;
Len Brown4be44fc2005-08-05 00:44:28 -0400591 status =
592 acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
593 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
594 ACPI_NS_SEARCH_PARENT, walk_state,
595 &info.register_node);
596 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500597 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
Len Brown4be44fc2005-08-05 00:44:28 -0400598 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 }
600
601 /* Second arg is the data register (must already exist) */
602
603 arg = arg->common.next;
Len Brown4be44fc2005-08-05 00:44:28 -0400604 status =
605 acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
606 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
607 ACPI_NS_SEARCH_PARENT, walk_state,
608 &info.data_register_node);
609 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500610 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
Len Brown4be44fc2005-08-05 00:44:28 -0400611 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 }
613
614 /* Next arg is the field flags */
615
616 arg = arg->common.next;
617 info.field_flags = (u8) arg->common.value.integer;
618
619 /* Each remaining arg is a Named Field */
620
621 info.field_type = ACPI_TYPE_LOCAL_INDEX_FIELD;
622 info.region_node = region_node;
623
Len Brown4be44fc2005-08-05 00:44:28 -0400624 status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Len Brown4be44fc2005-08-05 00:44:28 -0400626 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627}