b43/b43legacy: use RFKILL_STATE_UNBLOCKED instead of RFKILL_STATE_ON
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / acpi / dispatcher / dsfield.c
blobf988a5e7d2b4f504b62214260788ee28afefa367
1 /******************************************************************************
3 * Module Name: dsfield - Dispatcher field routines
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved.
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.
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.
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.
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 */
55 static acpi_status
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
67 * RETURN: Status
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 ******************************************************************************/
79 acpi_status
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;
85 acpi_status status;
86 union acpi_operand_object *obj_desc;
87 union acpi_operand_object *second_desc = NULL;
88 u32 flags;
90 ACPI_FUNCTION_TRACE(ds_create_buffer_field);
93 * Get the name_string argument (name of the new buffer_field)
95 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
97 /* For create_field, name is the 4th argument */
99 arg = acpi_ps_get_arg(op, 3);
100 } else {
101 /* For all other create_xXXField operators, name is the 3rd argument */
103 arg = acpi_ps_get_arg(op, 2);
106 if (!arg) {
107 return_ACPI_STATUS(AE_AML_NO_OPERAND);
110 if (walk_state->deferred_node) {
111 node = walk_state->deferred_node;
112 status = AE_OK;
113 } else {
114 /* Execute flag should always be set when this function is entered */
116 if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) {
117 return_ACPI_STATUS(AE_AML_INTERNAL);
120 /* Creating new namespace node, should not already exist */
122 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
123 ACPI_NS_ERROR_IF_FOUND;
125 /* Mark node temporary if we are executing a method */
127 if (walk_state->method_node) {
128 flags |= ACPI_NS_TEMPORARY;
131 /* Enter the name_string into the namespace */
133 status =
134 acpi_ns_lookup(walk_state->scope_info,
135 arg->common.value.string, ACPI_TYPE_ANY,
136 ACPI_IMODE_LOAD_PASS1, flags, walk_state,
137 &node);
138 if (ACPI_FAILURE(status)) {
139 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
140 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);
157 if (obj_desc) {
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);
169 if (!obj_desc) {
170 status = AE_NO_MEMORY;
171 goto cleanup;
175 * Remember location in AML stream of the field unit opcode and operands --
176 * since the buffer and index operands must be evaluated.
178 second_desc = obj_desc->common.next_object;
179 second_desc->extra.aml_start = op->named.data;
180 second_desc->extra.aml_length = op->named.length;
181 obj_desc->buffer_field.node = node;
183 /* Attach constructed field descriptors to parent node */
185 status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_BUFFER_FIELD);
186 if (ACPI_FAILURE(status)) {
187 goto cleanup;
190 cleanup:
192 /* Remove local reference to the object */
194 acpi_ut_remove_reference(obj_desc);
195 return_ACPI_STATUS(status);
198 /*******************************************************************************
200 * FUNCTION: acpi_ds_get_field_names
202 * PARAMETERS: Info - create_field info structure
203 * ` walk_state - Current method state
204 * Arg - First parser arg for the field name list
206 * RETURN: Status
208 * DESCRIPTION: Process all named fields in a field declaration. Names are
209 * entered into the namespace.
211 ******************************************************************************/
213 static acpi_status
214 acpi_ds_get_field_names(struct acpi_create_field_info *info,
215 struct acpi_walk_state *walk_state,
216 union acpi_parse_object *arg)
218 acpi_status status;
219 acpi_integer position;
221 ACPI_FUNCTION_TRACE_PTR(ds_get_field_names, info);
223 /* First field starts at bit zero */
225 info->field_bit_position = 0;
227 /* Process all elements in the field list (of parse nodes) */
229 while (arg) {
231 * Three types of field elements are handled:
232 * 1) Offset - specifies a bit offset
233 * 2) access_as - changes the access mode
234 * 3) Name - Enters a new named field into the namespace
236 switch (arg->common.aml_opcode) {
237 case AML_INT_RESERVEDFIELD_OP:
239 position = (acpi_integer) info->field_bit_position
240 + (acpi_integer) arg->common.value.size;
242 if (position > ACPI_UINT32_MAX) {
243 ACPI_ERROR((AE_INFO,
244 "Bit offset within field too large (> 0xFFFFFFFF)"));
245 return_ACPI_STATUS(AE_SUPPORT);
248 info->field_bit_position = (u32) position;
249 break;
251 case AML_INT_ACCESSFIELD_OP:
254 * Get a new access_type and access_attribute -- to be used for all
255 * field units that follow, until field end or another access_as
256 * keyword.
258 * In field_flags, preserve the flag bits other than the
259 * ACCESS_TYPE bits
261 info->field_flags = (u8)
262 ((info->
263 field_flags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
264 ((u8) ((u32) arg->common.value.integer >> 8)));
266 info->attribute = (u8) (arg->common.value.integer);
267 break;
269 case AML_INT_NAMEDFIELD_OP:
271 /* Lookup the name, it should already exist */
273 status = acpi_ns_lookup(walk_state->scope_info,
274 (char *)&arg->named.name,
275 info->field_type,
276 ACPI_IMODE_EXECUTE,
277 ACPI_NS_DONT_OPEN_SCOPE,
278 walk_state, &info->field_node);
279 if (ACPI_FAILURE(status)) {
280 ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
281 status);
282 return_ACPI_STATUS(status);
283 } else {
284 arg->common.node = info->field_node;
285 info->field_bit_length = arg->common.value.size;
288 * If there is no object attached to the node, this node was
289 * just created and we need to create the field object.
290 * Otherwise, this was a lookup of an existing node and we
291 * don't want to create the field object again.
293 if (!acpi_ns_get_attached_object
294 (info->field_node)) {
295 status = acpi_ex_prep_field_value(info);
296 if (ACPI_FAILURE(status)) {
297 return_ACPI_STATUS(status);
302 /* Keep track of bit position for the next field */
304 position = (acpi_integer) info->field_bit_position
305 + (acpi_integer) arg->common.value.size;
307 if (position > ACPI_UINT32_MAX) {
308 ACPI_ERROR((AE_INFO,
309 "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
310 ACPI_CAST_PTR(char,
311 &info->field_node->
312 name)));
313 return_ACPI_STATUS(AE_SUPPORT);
316 info->field_bit_position += info->field_bit_length;
317 break;
319 default:
321 ACPI_ERROR((AE_INFO,
322 "Invalid opcode in field list: %X",
323 arg->common.aml_opcode));
324 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
327 arg = arg->common.next;
330 return_ACPI_STATUS(AE_OK);
333 /*******************************************************************************
335 * FUNCTION: acpi_ds_create_field
337 * PARAMETERS: Op - Op containing the Field definition and args
338 * region_node - Object for the containing Operation Region
339 * ` walk_state - Current method state
341 * RETURN: Status
343 * DESCRIPTION: Create a new field in the specified operation region
345 ******************************************************************************/
347 acpi_status
348 acpi_ds_create_field(union acpi_parse_object *op,
349 struct acpi_namespace_node *region_node,
350 struct acpi_walk_state *walk_state)
352 acpi_status status;
353 union acpi_parse_object *arg;
354 struct acpi_create_field_info info;
356 ACPI_FUNCTION_TRACE_PTR(ds_create_field, op);
358 /* First arg is the name of the parent op_region (must already exist) */
360 arg = op->common.value.arg;
361 if (!region_node) {
362 status =
363 acpi_ns_lookup(walk_state->scope_info,
364 arg->common.value.name, ACPI_TYPE_REGION,
365 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
366 walk_state, &region_node);
367 if (ACPI_FAILURE(status)) {
368 ACPI_ERROR_NAMESPACE(arg->common.value.name, status);
369 return_ACPI_STATUS(status);
373 /* Second arg is the field flags */
375 arg = arg->common.next;
376 info.field_flags = (u8) arg->common.value.integer;
377 info.attribute = 0;
379 /* Each remaining arg is a Named Field */
381 info.field_type = ACPI_TYPE_LOCAL_REGION_FIELD;
382 info.region_node = region_node;
384 status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
386 return_ACPI_STATUS(status);
389 /*******************************************************************************
391 * FUNCTION: acpi_ds_init_field_objects
393 * PARAMETERS: Op - Op containing the Field definition and args
394 * ` walk_state - Current method state
396 * RETURN: Status
398 * DESCRIPTION: For each "Field Unit" name in the argument list that is
399 * part of the field declaration, enter the name into the
400 * namespace.
402 ******************************************************************************/
404 acpi_status
405 acpi_ds_init_field_objects(union acpi_parse_object *op,
406 struct acpi_walk_state *walk_state)
408 acpi_status status;
409 union acpi_parse_object *arg = NULL;
410 struct acpi_namespace_node *node;
411 u8 type = 0;
412 u32 flags;
414 ACPI_FUNCTION_TRACE_PTR(ds_init_field_objects, op);
416 /* Execute flag should always be set when this function is entered */
418 if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) {
419 if (walk_state->parse_flags & ACPI_PARSE_DEFERRED_OP) {
421 /* bank_field Op is deferred, just return OK */
423 return_ACPI_STATUS(AE_OK);
426 return_ACPI_STATUS(AE_AML_INTERNAL);
430 * Get the field_list argument for this opcode. This is the start of the
431 * list of field elements.
433 switch (walk_state->opcode) {
434 case AML_FIELD_OP:
435 arg = acpi_ps_get_arg(op, 2);
436 type = ACPI_TYPE_LOCAL_REGION_FIELD;
437 break;
439 case AML_BANK_FIELD_OP:
440 arg = acpi_ps_get_arg(op, 4);
441 type = ACPI_TYPE_LOCAL_BANK_FIELD;
442 break;
444 case AML_INDEX_FIELD_OP:
445 arg = acpi_ps_get_arg(op, 3);
446 type = ACPI_TYPE_LOCAL_INDEX_FIELD;
447 break;
449 default:
450 return_ACPI_STATUS(AE_BAD_PARAMETER);
453 /* Creating new namespace node(s), should not already exist */
455 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
456 ACPI_NS_ERROR_IF_FOUND;
458 /* Mark node(s) temporary if we are executing a method */
460 if (walk_state->method_node) {
461 flags |= ACPI_NS_TEMPORARY;
465 * Walk the list of entries in the field_list
466 * Note: field_list can be of zero length. In this case, Arg will be NULL.
468 while (arg) {
470 * Ignore OFFSET and ACCESSAS terms here; we are only interested in the
471 * field names in order to enter them into the namespace.
473 if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
474 status = acpi_ns_lookup(walk_state->scope_info,
475 (char *)&arg->named.name, type,
476 ACPI_IMODE_LOAD_PASS1, flags,
477 walk_state, &node);
478 if (ACPI_FAILURE(status)) {
479 ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
480 status);
481 if (status != AE_ALREADY_EXISTS) {
482 return_ACPI_STATUS(status);
485 /* Name already exists, just ignore this error */
487 status = AE_OK;
490 arg->common.node = node;
493 /* Get the next field element in the list */
495 arg = arg->common.next;
498 return_ACPI_STATUS(AE_OK);
501 /*******************************************************************************
503 * FUNCTION: acpi_ds_create_bank_field
505 * PARAMETERS: Op - Op containing the Field definition and args
506 * region_node - Object for the containing Operation Region
507 * walk_state - Current method state
509 * RETURN: Status
511 * DESCRIPTION: Create a new bank field in the specified operation region
513 ******************************************************************************/
515 acpi_status
516 acpi_ds_create_bank_field(union acpi_parse_object *op,
517 struct acpi_namespace_node *region_node,
518 struct acpi_walk_state *walk_state)
520 acpi_status status;
521 union acpi_parse_object *arg;
522 struct acpi_create_field_info info;
524 ACPI_FUNCTION_TRACE_PTR(ds_create_bank_field, op);
526 /* First arg is the name of the parent op_region (must already exist) */
528 arg = op->common.value.arg;
529 if (!region_node) {
530 status =
531 acpi_ns_lookup(walk_state->scope_info,
532 arg->common.value.name, ACPI_TYPE_REGION,
533 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
534 walk_state, &region_node);
535 if (ACPI_FAILURE(status)) {
536 ACPI_ERROR_NAMESPACE(arg->common.value.name, status);
537 return_ACPI_STATUS(status);
541 /* Second arg is the Bank Register (Field) (must already exist) */
543 arg = arg->common.next;
544 status =
545 acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
546 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
547 ACPI_NS_SEARCH_PARENT, walk_state,
548 &info.register_node);
549 if (ACPI_FAILURE(status)) {
550 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
551 return_ACPI_STATUS(status);
555 * Third arg is the bank_value
556 * This arg is a term_arg, not a constant
557 * It will be evaluated later, by acpi_ds_eval_bank_field_operands
559 arg = arg->common.next;
561 /* Fourth arg is the field flags */
563 arg = arg->common.next;
564 info.field_flags = (u8) arg->common.value.integer;
566 /* Each remaining arg is a Named Field */
568 info.field_type = ACPI_TYPE_LOCAL_BANK_FIELD;
569 info.region_node = region_node;
572 * Use Info.data_register_node to store bank_field Op
573 * It's safe because data_register_node will never be used when create bank field
574 * We store aml_start and aml_length in the bank_field Op for late evaluation
575 * Used in acpi_ex_prep_field_value(Info)
577 * TBD: Or, should we add a field in struct acpi_create_field_info, like "void *ParentOp"?
579 info.data_register_node = (struct acpi_namespace_node *)op;
581 status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
582 return_ACPI_STATUS(status);
585 /*******************************************************************************
587 * FUNCTION: acpi_ds_create_index_field
589 * PARAMETERS: Op - Op containing the Field definition and args
590 * region_node - Object for the containing Operation Region
591 * ` walk_state - Current method state
593 * RETURN: Status
595 * DESCRIPTION: Create a new index field in the specified operation region
597 ******************************************************************************/
599 acpi_status
600 acpi_ds_create_index_field(union acpi_parse_object *op,
601 struct acpi_namespace_node *region_node,
602 struct acpi_walk_state *walk_state)
604 acpi_status status;
605 union acpi_parse_object *arg;
606 struct acpi_create_field_info info;
608 ACPI_FUNCTION_TRACE_PTR(ds_create_index_field, op);
610 /* First arg is the name of the Index register (must already exist) */
612 arg = op->common.value.arg;
613 status =
614 acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
615 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
616 ACPI_NS_SEARCH_PARENT, walk_state,
617 &info.register_node);
618 if (ACPI_FAILURE(status)) {
619 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
620 return_ACPI_STATUS(status);
623 /* Second arg is the data register (must already exist) */
625 arg = arg->common.next;
626 status =
627 acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
628 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
629 ACPI_NS_SEARCH_PARENT, walk_state,
630 &info.data_register_node);
631 if (ACPI_FAILURE(status)) {
632 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
633 return_ACPI_STATUS(status);
636 /* Next arg is the field flags */
638 arg = arg->common.next;
639 info.field_flags = (u8) arg->common.value.integer;
641 /* Each remaining arg is a Named Field */
643 info.field_type = ACPI_TYPE_LOCAL_INDEX_FIELD;
644 info.region_node = region_node;
646 status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
648 return_ACPI_STATUS(status);