1 /******************************************************************************
3 * Module Name: dsfield - Dispatcher field routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2005, 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.
45 #include <acpi/acpi.h>
46 #include <acpi/amlcode.h>
47 #include <acpi/acdispat.h>
48 #include <acpi/acinterp.h>
49 #include <acpi/acnamesp.h>
50 #include <acpi/acparser.h>
53 #define _COMPONENT ACPI_DISPATCHER
54 ACPI_MODULE_NAME ("dsfield")
57 /*******************************************************************************
59 * FUNCTION: acpi_ds_create_buffer_field
61 * PARAMETERS: Opcode - The opcode to be executed
62 * Operands - List of operands for the opcode
63 * walk_state - Current state
67 * DESCRIPTION: Execute the create_field operators:
68 * create_bit_field_op,
69 * create_byte_field_op,
70 * create_word_field_op,
71 * create_dword_field_op,
72 * create_qword_field_op,
73 * create_field_op (all of which define fields in buffers)
75 ******************************************************************************/
78 acpi_ds_create_buffer_field (
79 union acpi_parse_object
*op
,
80 struct acpi_walk_state
*walk_state
)
82 union acpi_parse_object
*arg
;
83 struct acpi_namespace_node
*node
;
85 union acpi_operand_object
*obj_desc
;
86 union acpi_operand_object
*second_desc
= NULL
;
90 ACPI_FUNCTION_TRACE ("ds_create_buffer_field");
93 /* Get the name_string argument */
95 if (op
->common
.aml_opcode
== AML_CREATE_FIELD_OP
) {
96 arg
= acpi_ps_get_arg (op
, 3);
99 /* Create Bit/Byte/Word/Dword field */
101 arg
= acpi_ps_get_arg (op
, 2);
105 return_ACPI_STATUS (AE_AML_NO_OPERAND
);
108 if (walk_state
->deferred_node
) {
109 node
= walk_state
->deferred_node
;
114 * During the load phase, we want to enter the name of the field into
115 * the namespace. During the execute phase (when we evaluate the size
116 * operand), we want to lookup the name
118 if (walk_state
->parse_flags
& ACPI_PARSE_EXECUTE
) {
119 flags
= ACPI_NS_NO_UPSEARCH
| ACPI_NS_DONT_OPEN_SCOPE
;
122 flags
= ACPI_NS_NO_UPSEARCH
| ACPI_NS_DONT_OPEN_SCOPE
| ACPI_NS_ERROR_IF_FOUND
;
126 * Enter the name_string into the namespace
128 status
= acpi_ns_lookup (walk_state
->scope_info
, arg
->common
.value
.string
,
129 ACPI_TYPE_ANY
, ACPI_IMODE_LOAD_PASS1
,
130 flags
, walk_state
, &(node
));
131 if (ACPI_FAILURE (status
)) {
132 ACPI_REPORT_NSERROR (arg
->common
.value
.string
, status
);
133 return_ACPI_STATUS (status
);
137 /* We could put the returned object (Node) on the object stack for later, but
138 * for now, we will put it in the "op" object that the parser uses, so we
139 * can get it again at the end of this scope
141 op
->common
.node
= node
;
144 * If there is no object attached to the node, this node was just created and
145 * we need to create the field object. Otherwise, this was a lookup of an
146 * existing node and we don't want to create the field object again.
148 obj_desc
= acpi_ns_get_attached_object (node
);
150 return_ACPI_STATUS (AE_OK
);
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)
158 /* Create the buffer field object */
160 obj_desc
= acpi_ut_create_internal_object (ACPI_TYPE_BUFFER_FIELD
);
162 status
= AE_NO_MEMORY
;
167 * Remember location in AML stream of the field unit
168 * opcode and operands -- since the buffer and index
169 * operands must be evaluated.
171 second_desc
= obj_desc
->common
.next_object
;
172 second_desc
->extra
.aml_start
= op
->named
.data
;
173 second_desc
->extra
.aml_length
= op
->named
.length
;
174 obj_desc
->buffer_field
.node
= node
;
176 /* Attach constructed field descriptors to parent node */
178 status
= acpi_ns_attach_object (node
, obj_desc
, ACPI_TYPE_BUFFER_FIELD
);
179 if (ACPI_FAILURE (status
)) {
186 /* Remove local reference to the object */
188 acpi_ut_remove_reference (obj_desc
);
189 return_ACPI_STATUS (status
);
193 /*******************************************************************************
195 * FUNCTION: acpi_ds_get_field_names
197 * PARAMETERS: Info - create_field info structure
198 * ` walk_state - Current method state
199 * Arg - First parser arg for the field name list
203 * DESCRIPTION: Process all named fields in a field declaration. Names are
204 * entered into the namespace.
206 ******************************************************************************/
209 acpi_ds_get_field_names (
210 struct acpi_create_field_info
*info
,
211 struct acpi_walk_state
*walk_state
,
212 union acpi_parse_object
*arg
)
215 acpi_integer position
;
218 ACPI_FUNCTION_TRACE_PTR ("ds_get_field_names", info
);
221 /* First field starts at bit zero */
223 info
->field_bit_position
= 0;
225 /* Process all elements in the field list (of parse nodes) */
229 * Three types of field elements are handled:
230 * 1) Offset - specifies a bit offset
231 * 2) access_as - changes the access mode
232 * 3) Name - Enters a new named field into the namespace
234 switch (arg
->common
.aml_opcode
) {
235 case AML_INT_RESERVEDFIELD_OP
:
237 position
= (acpi_integer
) info
->field_bit_position
238 + (acpi_integer
) arg
->common
.value
.size
;
240 if (position
> ACPI_UINT32_MAX
) {
241 ACPI_REPORT_ERROR (("Bit offset within field too large (> 0xFFFFFFFF)\n"));
242 return_ACPI_STATUS (AE_SUPPORT
);
245 info
->field_bit_position
= (u32
) position
;
249 case AML_INT_ACCESSFIELD_OP
:
252 * Get a new access_type and access_attribute -- to be used for all
253 * field units that follow, until field end or another access_as keyword.
255 * In field_flags, preserve the flag bits other than the ACCESS_TYPE bits
257 info
->field_flags
= (u8
) ((info
->field_flags
& ~(AML_FIELD_ACCESS_TYPE_MASK
)) |
258 ((u8
) ((u32
) arg
->common
.value
.integer
>> 8)));
260 info
->attribute
= (u8
) (arg
->common
.value
.integer
);
264 case AML_INT_NAMEDFIELD_OP
:
266 /* Lookup the name */
268 status
= acpi_ns_lookup (walk_state
->scope_info
,
269 (char *) &arg
->named
.name
,
270 info
->field_type
, ACPI_IMODE_EXECUTE
, ACPI_NS_DONT_OPEN_SCOPE
,
271 walk_state
, &info
->field_node
);
272 if (ACPI_FAILURE (status
)) {
273 ACPI_REPORT_NSERROR ((char *) &arg
->named
.name
, status
);
274 if (status
!= AE_ALREADY_EXISTS
) {
275 return_ACPI_STATUS (status
);
278 /* Already exists, ignore error */
281 arg
->common
.node
= info
->field_node
;
282 info
->field_bit_length
= arg
->common
.value
.size
;
284 /* Create and initialize an object for the new Field Node */
286 status
= acpi_ex_prep_field_value (info
);
287 if (ACPI_FAILURE (status
)) {
288 return_ACPI_STATUS (status
);
292 /* Keep track of bit position for the next field */
294 position
= (acpi_integer
) info
->field_bit_position
295 + (acpi_integer
) arg
->common
.value
.size
;
297 if (position
> ACPI_UINT32_MAX
) {
298 ACPI_REPORT_ERROR (("Field [%4.4s] bit offset too large (> 0xFFFFFFFF)\n",
299 (char *) &info
->field_node
->name
));
300 return_ACPI_STATUS (AE_SUPPORT
);
303 info
->field_bit_position
+= info
->field_bit_length
;
309 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Invalid opcode in field list: %X\n",
310 arg
->common
.aml_opcode
));
311 return_ACPI_STATUS (AE_AML_BAD_OPCODE
);
314 arg
= arg
->common
.next
;
317 return_ACPI_STATUS (AE_OK
);
321 /*******************************************************************************
323 * FUNCTION: acpi_ds_create_field
325 * PARAMETERS: Op - Op containing the Field definition and args
326 * region_node - Object for the containing Operation Region
327 * ` walk_state - Current method state
331 * DESCRIPTION: Create a new field in the specified operation region
333 ******************************************************************************/
336 acpi_ds_create_field (
337 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
;
346 ACPI_FUNCTION_TRACE_PTR ("ds_create_field", op
);
349 /* First arg is the name of the parent op_region (must already exist) */
351 arg
= op
->common
.value
.arg
;
353 status
= acpi_ns_lookup (walk_state
->scope_info
, arg
->common
.value
.name
,
354 ACPI_TYPE_REGION
, ACPI_IMODE_EXECUTE
,
355 ACPI_NS_SEARCH_PARENT
, walk_state
, ®ion_node
);
356 if (ACPI_FAILURE (status
)) {
357 ACPI_REPORT_NSERROR (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
);
379 /*******************************************************************************
381 * FUNCTION: acpi_ds_init_field_objects
383 * PARAMETERS: Op - Op containing the Field definition and args
384 * ` walk_state - Current method state
388 * DESCRIPTION: For each "Field Unit" name in the argument list that is
389 * part of the field declaration, enter the name into the
392 ******************************************************************************/
395 acpi_ds_init_field_objects (
396 union acpi_parse_object
*op
,
397 struct acpi_walk_state
*walk_state
)
400 union acpi_parse_object
*arg
= NULL
;
401 struct acpi_namespace_node
*node
;
405 ACPI_FUNCTION_TRACE_PTR ("ds_init_field_objects", op
);
408 switch (walk_state
->opcode
) {
410 arg
= acpi_ps_get_arg (op
, 2);
411 type
= ACPI_TYPE_LOCAL_REGION_FIELD
;
414 case AML_BANK_FIELD_OP
:
415 arg
= acpi_ps_get_arg (op
, 4);
416 type
= ACPI_TYPE_LOCAL_BANK_FIELD
;
419 case AML_INDEX_FIELD_OP
:
420 arg
= acpi_ps_get_arg (op
, 3);
421 type
= ACPI_TYPE_LOCAL_INDEX_FIELD
;
425 return_ACPI_STATUS (AE_BAD_PARAMETER
);
429 * Walk the list of entries in the field_list
432 /* Ignore OFFSET and ACCESSAS terms here */
434 if (arg
->common
.aml_opcode
== AML_INT_NAMEDFIELD_OP
) {
435 status
= acpi_ns_lookup (walk_state
->scope_info
,
436 (char *) &arg
->named
.name
,
437 type
, ACPI_IMODE_LOAD_PASS1
,
438 ACPI_NS_NO_UPSEARCH
| ACPI_NS_DONT_OPEN_SCOPE
| ACPI_NS_ERROR_IF_FOUND
,
440 if (ACPI_FAILURE (status
)) {
441 ACPI_REPORT_NSERROR ((char *) &arg
->named
.name
, status
);
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
);
463 /*******************************************************************************
465 * FUNCTION: acpi_ds_create_bank_field
467 * PARAMETERS: Op - Op containing the Field definition and args
468 * region_node - Object for the containing Operation Region
469 * ` walk_state - Current method state
473 * DESCRIPTION: Create a new bank field in the specified operation region
475 ******************************************************************************/
478 acpi_ds_create_bank_field (
479 union acpi_parse_object
*op
,
480 struct acpi_namespace_node
*region_node
,
481 struct acpi_walk_state
*walk_state
)
484 union acpi_parse_object
*arg
;
485 struct acpi_create_field_info info
;
488 ACPI_FUNCTION_TRACE_PTR ("ds_create_bank_field", op
);
491 /* First arg is the name of the parent op_region (must already exist) */
493 arg
= op
->common
.value
.arg
;
495 status
= acpi_ns_lookup (walk_state
->scope_info
, arg
->common
.value
.name
,
496 ACPI_TYPE_REGION
, ACPI_IMODE_EXECUTE
,
497 ACPI_NS_SEARCH_PARENT
, walk_state
, ®ion_node
);
498 if (ACPI_FAILURE (status
)) {
499 ACPI_REPORT_NSERROR (arg
->common
.value
.name
, status
);
500 return_ACPI_STATUS (status
);
504 /* Second arg is the Bank Register (Field) (must already exist) */
506 arg
= arg
->common
.next
;
507 status
= acpi_ns_lookup (walk_state
->scope_info
, arg
->common
.value
.string
,
508 ACPI_TYPE_ANY
, ACPI_IMODE_EXECUTE
,
509 ACPI_NS_SEARCH_PARENT
, walk_state
, &info
.register_node
);
510 if (ACPI_FAILURE (status
)) {
511 ACPI_REPORT_NSERROR (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
);
536 /*******************************************************************************
538 * FUNCTION: acpi_ds_create_index_field
540 * PARAMETERS: Op - Op containing the Field definition and args
541 * region_node - Object for the containing Operation Region
542 * ` walk_state - Current method state
546 * DESCRIPTION: Create a new index field in the specified operation region
548 ******************************************************************************/
551 acpi_ds_create_index_field (
552 union acpi_parse_object
*op
,
553 struct acpi_namespace_node
*region_node
,
554 struct acpi_walk_state
*walk_state
)
557 union acpi_parse_object
*arg
;
558 struct acpi_create_field_info info
;
561 ACPI_FUNCTION_TRACE_PTR ("ds_create_index_field", op
);
564 /* First arg is the name of the Index register (must already exist) */
566 arg
= op
->common
.value
.arg
;
567 status
= acpi_ns_lookup (walk_state
->scope_info
, arg
->common
.value
.string
,
568 ACPI_TYPE_ANY
, ACPI_IMODE_EXECUTE
,
569 ACPI_NS_SEARCH_PARENT
, walk_state
, &info
.register_node
);
570 if (ACPI_FAILURE (status
)) {
571 ACPI_REPORT_NSERROR (arg
->common
.value
.string
, status
);
572 return_ACPI_STATUS (status
);
575 /* Second arg is the data register (must already exist) */
577 arg
= arg
->common
.next
;
578 status
= acpi_ns_lookup (walk_state
->scope_info
, arg
->common
.value
.string
,
579 ACPI_TYPE_ANY
, ACPI_IMODE_EXECUTE
,
580 ACPI_NS_SEARCH_PARENT
, walk_state
, &info
.data_register_node
);
581 if (ACPI_FAILURE (status
)) {
582 ACPI_REPORT_NSERROR (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
);