1 /******************************************************************************
3 * Module Name: dsfield - Dispatcher field routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2006, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #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>
51 #define _COMPONENT ACPI_DISPATCHER
52 ACPI_MODULE_NAME("dsfield")
54 /* Local prototypes */
56 acpi_ds_get_field_names(struct acpi_create_field_info *info,
57 struct acpi_walk_state *walk_state,
58 union acpi_parse_object *arg);
60 /*******************************************************************************
62 * FUNCTION: acpi_ds_create_buffer_field
64 * PARAMETERS: Op - Current parse op (create_xXField)
65 * walk_state - Current state
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,
75 * create_field_op (all of which define a field in a buffer)
77 ******************************************************************************/
80 acpi_ds_create_buffer_field(union acpi_parse_object *op,
81 struct acpi_walk_state *walk_state)
83 union acpi_parse_object *arg;
84 struct acpi_namespace_node *node;
86 union acpi_operand_object *obj_desc;
87 union acpi_operand_object *second_desc = NULL;
90 ACPI_FUNCTION_TRACE(ds_create_buffer_field);
92 /* Get the name_string argument */
94 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
95 arg = acpi_ps_get_arg(op, 3);
97 /* Create Bit/Byte/Word/Dword field */
99 arg = acpi_ps_get_arg(op, 2);
103 return_ACPI_STATUS(AE_AML_NO_OPERAND);
106 if (walk_state->deferred_node) {
107 node = walk_state->deferred_node;
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
115 if (walk_state->parse_flags & ACPI_PARSE_EXECUTE) {
116 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE;
118 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
119 ACPI_NS_ERROR_IF_FOUND;
123 * Enter the name_string into the namespace
126 acpi_ns_lookup(walk_state->scope_info,
127 arg->common.value.string, ACPI_TYPE_ANY,
128 ACPI_IMODE_LOAD_PASS1, flags, walk_state,
130 if (ACPI_FAILURE(status)) {
131 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
132 return_ACPI_STATUS(status);
136 /* We could put the returned object (Node) on the object stack for later,
137 * but for now, we will put it in the "op" object that the parser uses,
138 * so we can get it again at the end of this scope
140 op->common.node = node;
143 * If there is no object attached to the node, this node was just created
144 * and we need to create the field object. Otherwise, this was a lookup
145 * of an existing node and we don't want to create the field object again.
147 obj_desc = acpi_ns_get_attached_object(node);
149 return_ACPI_STATUS(AE_OK);
153 * The Field definition is not fully parsed at this time.
154 * (We must save the address of the AML for the buffer and index operands)
157 /* Create the buffer field object */
159 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER_FIELD);
161 status = AE_NO_MEMORY;
166 * Remember location in AML stream of the field unit
167 * opcode and operands -- since the buffer and index
168 * operands must be evaluated.
170 second_desc = obj_desc->common.next_object;
171 second_desc->extra.aml_start = op->named.data;
172 second_desc->extra.aml_length = op->named.length;
173 obj_desc->buffer_field.node = node;
175 /* Attach constructed field descriptors to parent node */
177 status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_BUFFER_FIELD);
178 if (ACPI_FAILURE(status)) {
184 /* Remove local reference to the object */
186 acpi_ut_remove_reference(obj_desc);
187 return_ACPI_STATUS(status);
190 /*******************************************************************************
192 * FUNCTION: acpi_ds_get_field_names
194 * PARAMETERS: Info - create_field info structure
195 * ` walk_state - Current method state
196 * Arg - First parser arg for the field name list
200 * DESCRIPTION: Process all named fields in a field declaration. Names are
201 * entered into the namespace.
203 ******************************************************************************/
206 acpi_ds_get_field_names(struct acpi_create_field_info *info,
207 struct acpi_walk_state *walk_state,
208 union acpi_parse_object *arg)
211 acpi_integer position;
213 ACPI_FUNCTION_TRACE_PTR(ds_get_field_names, info);
215 /* First field starts at bit zero */
217 info->field_bit_position = 0;
219 /* Process all elements in the field list (of parse nodes) */
223 * Three types of field elements are handled:
224 * 1) Offset - specifies a bit offset
225 * 2) access_as - changes the access mode
226 * 3) Name - Enters a new named field into the namespace
228 switch (arg->common.aml_opcode) {
229 case AML_INT_RESERVEDFIELD_OP:
231 position = (acpi_integer) info->field_bit_position
232 + (acpi_integer) arg->common.value.size;
234 if (position > ACPI_UINT32_MAX) {
236 "Bit offset within field too large (> 0xFFFFFFFF)"));
237 return_ACPI_STATUS(AE_SUPPORT);
240 info->field_bit_position = (u32) position;
243 case AML_INT_ACCESSFIELD_OP:
246 * Get a new access_type and access_attribute -- to be used for all
247 * field units that follow, until field end or another access_as
250 * In field_flags, preserve the flag bits other than the
253 info->field_flags = (u8)
255 field_flags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
256 ((u8) ((u32) arg->common.value.integer >> 8)));
258 info->attribute = (u8) (arg->common.value.integer);
261 case AML_INT_NAMEDFIELD_OP:
263 /* Lookup the name */
265 status = acpi_ns_lookup(walk_state->scope_info,
266 (char *)&arg->named.name,
269 ACPI_NS_DONT_OPEN_SCOPE,
270 walk_state, &info->field_node);
271 if (ACPI_FAILURE(status)) {
272 ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
274 if (status != AE_ALREADY_EXISTS) {
275 return_ACPI_STATUS(status);
278 /* Already exists, ignore error */
280 arg->common.node = info->field_node;
281 info->field_bit_length = arg->common.value.size;
283 /* Create and initialize an object for the new Field Node */
285 status = acpi_ex_prep_field_value(info);
286 if (ACPI_FAILURE(status)) {
287 return_ACPI_STATUS(status);
291 /* Keep track of bit position for the next field */
293 position = (acpi_integer) info->field_bit_position
294 + (acpi_integer) arg->common.value.size;
296 if (position > ACPI_UINT32_MAX) {
298 "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
302 return_ACPI_STATUS(AE_SUPPORT);
305 info->field_bit_position += info->field_bit_length;
311 "Invalid opcode in field list: %X",
312 arg->common.aml_opcode));
313 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
316 arg = arg->common.next;
319 return_ACPI_STATUS(AE_OK);
322 /*******************************************************************************
324 * FUNCTION: acpi_ds_create_field
326 * PARAMETERS: Op - Op containing the Field definition and args
327 * region_node - Object for the containing Operation Region
328 * ` walk_state - Current method state
332 * DESCRIPTION: Create a new field in the specified operation region
334 ******************************************************************************/
337 acpi_ds_create_field(union acpi_parse_object *op,
338 struct acpi_namespace_node *region_node,
339 struct acpi_walk_state *walk_state)
342 union acpi_parse_object *arg;
343 struct acpi_create_field_info info;
345 ACPI_FUNCTION_TRACE_PTR(ds_create_field, op);
347 /* First arg is the name of the parent op_region (must already exist) */
349 arg = op->common.value.arg;
352 acpi_ns_lookup(walk_state->scope_info,
353 arg->common.value.name, ACPI_TYPE_REGION,
354 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
355 walk_state, ®ion_node);
356 if (ACPI_FAILURE(status)) {
357 ACPI_ERROR_NAMESPACE(arg->common.value.name, status);
358 return_ACPI_STATUS(status);
362 /* Second arg is the field flags */
364 arg = arg->common.next;
365 info.field_flags = (u8) arg->common.value.integer;
368 /* Each remaining arg is a Named Field */
370 info.field_type = ACPI_TYPE_LOCAL_REGION_FIELD;
371 info.region_node = region_node;
373 status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
375 return_ACPI_STATUS(status);
378 /*******************************************************************************
380 * FUNCTION: acpi_ds_init_field_objects
382 * PARAMETERS: Op - Op containing the Field definition and args
383 * ` walk_state - Current method state
387 * DESCRIPTION: For each "Field Unit" name in the argument list that is
388 * part of the field declaration, enter the name into the
391 ******************************************************************************/
394 acpi_ds_init_field_objects(union acpi_parse_object *op,
395 struct acpi_walk_state *walk_state)
398 union acpi_parse_object *arg = NULL;
399 struct acpi_namespace_node *node;
402 ACPI_FUNCTION_TRACE_PTR(ds_init_field_objects, op);
404 switch (walk_state->opcode) {
406 arg = acpi_ps_get_arg(op, 2);
407 type = ACPI_TYPE_LOCAL_REGION_FIELD;
410 case AML_BANK_FIELD_OP:
411 arg = acpi_ps_get_arg(op, 4);
412 type = ACPI_TYPE_LOCAL_BANK_FIELD;
415 case AML_INDEX_FIELD_OP:
416 arg = acpi_ps_get_arg(op, 3);
417 type = ACPI_TYPE_LOCAL_INDEX_FIELD;
421 return_ACPI_STATUS(AE_BAD_PARAMETER);
425 * Walk the list of entries in the field_list
429 /* Ignore OFFSET and ACCESSAS terms here */
431 if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
432 status = acpi_ns_lookup(walk_state->scope_info,
433 (char *)&arg->named.name,
434 type, ACPI_IMODE_LOAD_PASS1,
435 ACPI_NS_NO_UPSEARCH |
436 ACPI_NS_DONT_OPEN_SCOPE |
437 ACPI_NS_ERROR_IF_FOUND,
439 if (ACPI_FAILURE(status)) {
440 ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
442 if (status != AE_ALREADY_EXISTS) {
443 return_ACPI_STATUS(status);
446 /* Name already exists, just ignore this error */
451 arg->common.node = node;
454 /* Move to next field in the list */
456 arg = arg->common.next;
459 return_ACPI_STATUS(AE_OK);
462 /*******************************************************************************
464 * FUNCTION: acpi_ds_create_bank_field
466 * PARAMETERS: Op - Op containing the Field definition and args
467 * region_node - Object for the containing Operation Region
468 * ` walk_state - Current method state
472 * DESCRIPTION: Create a new bank field in the specified operation region
474 ******************************************************************************/
477 acpi_ds_create_bank_field(union acpi_parse_object *op,
478 struct acpi_namespace_node *region_node,
479 struct acpi_walk_state *walk_state)
482 union acpi_parse_object *arg;
483 struct acpi_create_field_info info;
485 ACPI_FUNCTION_TRACE_PTR(ds_create_bank_field, op);
487 /* First arg is the name of the parent op_region (must already exist) */
489 arg = op->common.value.arg;
492 acpi_ns_lookup(walk_state->scope_info,
493 arg->common.value.name, ACPI_TYPE_REGION,
494 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
495 walk_state, ®ion_node);
496 if (ACPI_FAILURE(status)) {
497 ACPI_ERROR_NAMESPACE(arg->common.value.name, status);
498 return_ACPI_STATUS(status);
502 /* Second arg is the Bank Register (Field) (must already exist) */
504 arg = arg->common.next;
506 acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
507 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
508 ACPI_NS_SEARCH_PARENT, walk_state,
509 &info.register_node);
510 if (ACPI_FAILURE(status)) {
511 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
512 return_ACPI_STATUS(status);
515 /* Third arg is the bank_value */
517 arg = arg->common.next;
518 info.bank_value = (u32) arg->common.value.integer;
520 /* Fourth arg is the field flags */
522 arg = arg->common.next;
523 info.field_flags = (u8) arg->common.value.integer;
525 /* Each remaining arg is a Named Field */
527 info.field_type = ACPI_TYPE_LOCAL_BANK_FIELD;
528 info.region_node = region_node;
530 status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
532 return_ACPI_STATUS(status);
535 /*******************************************************************************
537 * FUNCTION: acpi_ds_create_index_field
539 * PARAMETERS: Op - Op containing the Field definition and args
540 * region_node - Object for the containing Operation Region
541 * ` walk_state - Current method state
545 * DESCRIPTION: Create a new index field in the specified operation region
547 ******************************************************************************/
550 acpi_ds_create_index_field(union acpi_parse_object *op,
551 struct acpi_namespace_node *region_node,
552 struct acpi_walk_state *walk_state)
555 union acpi_parse_object *arg;
556 struct acpi_create_field_info info;
558 ACPI_FUNCTION_TRACE_PTR(ds_create_index_field, op);
560 /* First arg is the name of the Index register (must already exist) */
562 arg = op->common.value.arg;
564 acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
565 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
566 ACPI_NS_SEARCH_PARENT, walk_state,
567 &info.register_node);
568 if (ACPI_FAILURE(status)) {
569 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
570 return_ACPI_STATUS(status);
573 /* Second arg is the data register (must already exist) */
575 arg = arg->common.next;
577 acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
578 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
579 ACPI_NS_SEARCH_PARENT, walk_state,
580 &info.data_register_node);
581 if (ACPI_FAILURE(status)) {
582 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
583 return_ACPI_STATUS(status);
586 /* Next arg is the field flags */
588 arg = arg->common.next;
589 info.field_flags = (u8) arg->common.value.integer;
591 /* Each remaining arg is a Named Field */
593 info.field_type = ACPI_TYPE_LOCAL_INDEX_FIELD;
594 info.region_node = region_node;
596 status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
598 return_ACPI_STATUS(status);