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")
56 /* Local prototypes */
59 acpi_ds_get_field_names (
60 struct acpi_create_field_info *info,
61 struct acpi_walk_state *walk_state,
62 union acpi_parse_object *arg);
65 /*******************************************************************************
67 * FUNCTION: acpi_ds_create_buffer_field
69 * PARAMETERS: Op - Current parse op (create_xXField)
70 * walk_state - Current state
74 * DESCRIPTION: Execute the create_field operators:
75 * create_bit_field_op,
76 * create_byte_field_op,
77 * create_word_field_op,
78 * create_dword_field_op,
79 * create_qword_field_op,
80 * create_field_op (all of which define a field in a buffer)
82 ******************************************************************************/
85 acpi_ds_create_buffer_field (
86 union acpi_parse_object *op,
87 struct acpi_walk_state *walk_state)
89 union acpi_parse_object *arg;
90 struct acpi_namespace_node *node;
92 union acpi_operand_object *obj_desc;
93 union acpi_operand_object *second_desc = NULL;
97 ACPI_FUNCTION_TRACE ("ds_create_buffer_field");
100 /* Get the name_string argument */
102 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
103 arg = acpi_ps_get_arg (op, 3);
106 /* Create Bit/Byte/Word/Dword field */
108 arg = acpi_ps_get_arg (op, 2);
112 return_ACPI_STATUS (AE_AML_NO_OPERAND);
115 if (walk_state->deferred_node) {
116 node = walk_state->deferred_node;
121 * During the load phase, we want to enter the name of the field into
122 * the namespace. During the execute phase (when we evaluate the size
123 * operand), we want to lookup the name
125 if (walk_state->parse_flags & ACPI_PARSE_EXECUTE) {
126 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE;
129 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
130 ACPI_NS_ERROR_IF_FOUND;
134 * Enter the name_string into the namespace
136 status = acpi_ns_lookup (walk_state->scope_info, arg->common.value.string,
137 ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS1,
138 flags, walk_state, &(node));
139 if (ACPI_FAILURE (status)) {
140 ACPI_REPORT_NSERROR (arg->common.value.string, status);
141 return_ACPI_STATUS (status);
145 /* We could put the returned object (Node) on the object stack for later,
146 * but for now, we will put it in the "op" object that the parser uses,
147 * so we can get it again at the end of this scope
149 op->common.node = node;
152 * If there is no object attached to the node, this node was just created
153 * and we need to create the field object. Otherwise, this was a lookup
154 * of an existing node and we don't want to create the field object again.
156 obj_desc = acpi_ns_get_attached_object (node);
158 return_ACPI_STATUS (AE_OK);
162 * The Field definition is not fully parsed at this time.
163 * (We must save the address of the AML for the buffer and index operands)
166 /* Create the buffer field object */
168 obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_BUFFER_FIELD);
170 status = AE_NO_MEMORY;
175 * Remember location in AML stream of the field unit
176 * opcode and operands -- since the buffer and index
177 * operands must be evaluated.
179 second_desc = obj_desc->common.next_object;
180 second_desc->extra.aml_start = op->named.data;
181 second_desc->extra.aml_length = op->named.length;
182 obj_desc->buffer_field.node = node;
184 /* Attach constructed field descriptors to parent node */
186 status = acpi_ns_attach_object (node, obj_desc, ACPI_TYPE_BUFFER_FIELD);
187 if (ACPI_FAILURE (status)) {
194 /* Remove local reference to the object */
196 acpi_ut_remove_reference (obj_desc);
197 return_ACPI_STATUS (status);
201 /*******************************************************************************
203 * FUNCTION: acpi_ds_get_field_names
205 * PARAMETERS: Info - create_field info structure
206 * ` walk_state - Current method state
207 * Arg - First parser arg for the field name list
211 * DESCRIPTION: Process all named fields in a field declaration. Names are
212 * entered into the namespace.
214 ******************************************************************************/
217 acpi_ds_get_field_names (
218 struct acpi_create_field_info *info,
219 struct acpi_walk_state *walk_state,
220 union acpi_parse_object *arg)
223 acpi_integer position;
226 ACPI_FUNCTION_TRACE_PTR ("ds_get_field_names", info);
229 /* First field starts at bit zero */
231 info->field_bit_position = 0;
233 /* Process all elements in the field list (of parse nodes) */
237 * Three types of field elements are handled:
238 * 1) Offset - specifies a bit offset
239 * 2) access_as - changes the access mode
240 * 3) Name - Enters a new named field into the namespace
242 switch (arg->common.aml_opcode) {
243 case AML_INT_RESERVEDFIELD_OP:
245 position = (acpi_integer) info->field_bit_position
246 + (acpi_integer) arg->common.value.size;
248 if (position > ACPI_UINT32_MAX) {
250 "Bit offset within field too large (> 0xFFFFFFFF)\n"));
251 return_ACPI_STATUS (AE_SUPPORT);
254 info->field_bit_position = (u32) position;
258 case AML_INT_ACCESSFIELD_OP:
261 * Get a new access_type and access_attribute -- to be used for all
262 * field units that follow, until field end or another access_as
265 * In field_flags, preserve the flag bits other than the
268 info->field_flags = (u8)
269 ((info->field_flags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
270 ((u8) ((u32) arg->common.value.integer >> 8)));
272 info->attribute = (u8) (arg->common.value.integer);
276 case AML_INT_NAMEDFIELD_OP:
278 /* Lookup the name */
280 status = acpi_ns_lookup (walk_state->scope_info,
281 (char *) &arg->named.name,
282 info->field_type, ACPI_IMODE_EXECUTE,
283 ACPI_NS_DONT_OPEN_SCOPE,
284 walk_state, &info->field_node);
285 if (ACPI_FAILURE (status)) {
286 ACPI_REPORT_NSERROR ((char *) &arg->named.name, status);
287 if (status != AE_ALREADY_EXISTS) {
288 return_ACPI_STATUS (status);
291 /* Already exists, ignore error */
294 arg->common.node = info->field_node;
295 info->field_bit_length = arg->common.value.size;
297 /* Create and initialize an object for the new Field Node */
299 status = acpi_ex_prep_field_value (info);
300 if (ACPI_FAILURE (status)) {
301 return_ACPI_STATUS (status);
305 /* Keep track of bit position for the next field */
307 position = (acpi_integer) info->field_bit_position
308 + (acpi_integer) arg->common.value.size;
310 if (position > ACPI_UINT32_MAX) {
312 "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)\n",
313 (char *) &info->field_node->name));
314 return_ACPI_STATUS (AE_SUPPORT);
317 info->field_bit_position += info->field_bit_length;
323 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
324 "Invalid opcode in field list: %X\n",
325 arg->common.aml_opcode));
326 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
329 arg = arg->common.next;
332 return_ACPI_STATUS (AE_OK);
336 /*******************************************************************************
338 * FUNCTION: acpi_ds_create_field
340 * PARAMETERS: Op - Op containing the Field definition and args
341 * region_node - Object for the containing Operation Region
342 * ` walk_state - Current method state
346 * DESCRIPTION: Create a new field in the specified operation region
348 ******************************************************************************/
351 acpi_ds_create_field (
352 union acpi_parse_object *op,
353 struct acpi_namespace_node *region_node,
354 struct acpi_walk_state *walk_state)
357 union acpi_parse_object *arg;
358 struct acpi_create_field_info info;
361 ACPI_FUNCTION_TRACE_PTR ("ds_create_field", op);
364 /* First arg is the name of the parent op_region (must already exist) */
366 arg = op->common.value.arg;
368 status = acpi_ns_lookup (walk_state->scope_info, arg->common.value.name,
369 ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
370 ACPI_NS_SEARCH_PARENT, walk_state, ®ion_node);
371 if (ACPI_FAILURE (status)) {
372 ACPI_REPORT_NSERROR (arg->common.value.name, status);
373 return_ACPI_STATUS (status);
377 /* Second arg is the field flags */
379 arg = arg->common.next;
380 info.field_flags = (u8) arg->common.value.integer;
383 /* Each remaining arg is a Named Field */
385 info.field_type = ACPI_TYPE_LOCAL_REGION_FIELD;
386 info.region_node = region_node;
388 status = acpi_ds_get_field_names (&info, walk_state, arg->common.next);
390 return_ACPI_STATUS (status);
394 /*******************************************************************************
396 * FUNCTION: acpi_ds_init_field_objects
398 * PARAMETERS: Op - Op containing the Field definition and args
399 * ` walk_state - Current method state
403 * DESCRIPTION: For each "Field Unit" name in the argument list that is
404 * part of the field declaration, enter the name into the
407 ******************************************************************************/
410 acpi_ds_init_field_objects (
411 union acpi_parse_object *op,
412 struct acpi_walk_state *walk_state)
415 union acpi_parse_object *arg = NULL;
416 struct acpi_namespace_node *node;
420 ACPI_FUNCTION_TRACE_PTR ("ds_init_field_objects", op);
423 switch (walk_state->opcode) {
425 arg = acpi_ps_get_arg (op, 2);
426 type = ACPI_TYPE_LOCAL_REGION_FIELD;
429 case AML_BANK_FIELD_OP:
430 arg = acpi_ps_get_arg (op, 4);
431 type = ACPI_TYPE_LOCAL_BANK_FIELD;
434 case AML_INDEX_FIELD_OP:
435 arg = acpi_ps_get_arg (op, 3);
436 type = ACPI_TYPE_LOCAL_INDEX_FIELD;
440 return_ACPI_STATUS (AE_BAD_PARAMETER);
444 * Walk the list of entries in the field_list
447 /* Ignore OFFSET and ACCESSAS terms here */
449 if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
450 status = acpi_ns_lookup (walk_state->scope_info,
451 (char *) &arg->named.name,
452 type, ACPI_IMODE_LOAD_PASS1,
453 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
454 ACPI_NS_ERROR_IF_FOUND,
456 if (ACPI_FAILURE (status)) {
457 ACPI_REPORT_NSERROR ((char *) &arg->named.name, status);
458 if (status != AE_ALREADY_EXISTS) {
459 return_ACPI_STATUS (status);
462 /* Name already exists, just ignore this error */
467 arg->common.node = node;
470 /* Move to next field in the list */
472 arg = arg->common.next;
475 return_ACPI_STATUS (AE_OK);
479 /*******************************************************************************
481 * FUNCTION: acpi_ds_create_bank_field
483 * PARAMETERS: Op - Op containing the Field definition and args
484 * region_node - Object for the containing Operation Region
485 * ` walk_state - Current method state
489 * DESCRIPTION: Create a new bank field in the specified operation region
491 ******************************************************************************/
494 acpi_ds_create_bank_field (
495 union acpi_parse_object *op,
496 struct acpi_namespace_node *region_node,
497 struct acpi_walk_state *walk_state)
500 union acpi_parse_object *arg;
501 struct acpi_create_field_info info;
504 ACPI_FUNCTION_TRACE_PTR ("ds_create_bank_field", op);
507 /* First arg is the name of the parent op_region (must already exist) */
509 arg = op->common.value.arg;
511 status = acpi_ns_lookup (walk_state->scope_info, arg->common.value.name,
512 ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
513 ACPI_NS_SEARCH_PARENT, walk_state, ®ion_node);
514 if (ACPI_FAILURE (status)) {
515 ACPI_REPORT_NSERROR (arg->common.value.name, status);
516 return_ACPI_STATUS (status);
520 /* Second arg is the Bank Register (Field) (must already exist) */
522 arg = arg->common.next;
523 status = 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, &info.register_node);
526 if (ACPI_FAILURE (status)) {
527 ACPI_REPORT_NSERROR (arg->common.value.string, status);
528 return_ACPI_STATUS (status);
531 /* Third arg is the bank_value */
533 arg = arg->common.next;
534 info.bank_value = (u32) arg->common.value.integer;
536 /* Fourth arg is the field flags */
538 arg = arg->common.next;
539 info.field_flags = (u8) arg->common.value.integer;
541 /* Each remaining arg is a Named Field */
543 info.field_type = ACPI_TYPE_LOCAL_BANK_FIELD;
544 info.region_node = region_node;
546 status = acpi_ds_get_field_names (&info, walk_state, arg->common.next);
548 return_ACPI_STATUS (status);
552 /*******************************************************************************
554 * FUNCTION: acpi_ds_create_index_field
556 * PARAMETERS: Op - Op containing the Field definition and args
557 * region_node - Object for the containing Operation Region
558 * ` walk_state - Current method state
562 * DESCRIPTION: Create a new index field in the specified operation region
564 ******************************************************************************/
567 acpi_ds_create_index_field (
568 union acpi_parse_object *op,
569 struct acpi_namespace_node *region_node,
570 struct acpi_walk_state *walk_state)
573 union acpi_parse_object *arg;
574 struct acpi_create_field_info info;
577 ACPI_FUNCTION_TRACE_PTR ("ds_create_index_field", op);
580 /* First arg is the name of the Index register (must already exist) */
582 arg = op->common.value.arg;
583 status = acpi_ns_lookup (walk_state->scope_info, arg->common.value.string,
584 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
585 ACPI_NS_SEARCH_PARENT, walk_state, &info.register_node);
586 if (ACPI_FAILURE (status)) {
587 ACPI_REPORT_NSERROR (arg->common.value.string, status);
588 return_ACPI_STATUS (status);
591 /* Second arg is the data register (must already exist) */
593 arg = arg->common.next;
594 status = acpi_ns_lookup (walk_state->scope_info, arg->common.value.string,
595 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
596 ACPI_NS_SEARCH_PARENT, walk_state, &info.data_register_node);
597 if (ACPI_FAILURE (status)) {
598 ACPI_REPORT_NSERROR (arg->common.value.string, status);
599 return_ACPI_STATUS (status);
602 /* Next arg is the field flags */
604 arg = arg->common.next;
605 info.field_flags = (u8) arg->common.value.integer;
607 /* Each remaining arg is a Named Field */
609 info.field_type = ACPI_TYPE_LOCAL_INDEX_FIELD;
610 info.region_node = region_node;
612 status = acpi_ds_get_field_names (&info, walk_state, arg->common.next);
614 return_ACPI_STATUS (status);