]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/acpi/acpica/dswload2.c
UBUNTU: Ubuntu-4.13.0-45.50
[mirror_ubuntu-artful-kernel.git] / drivers / acpi / acpica / dswload2.c
1 /******************************************************************************
2 *
3 * Module Name: dswload2 - Dispatcher second pass namespace load callbacks
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2017, Intel Corp.
9 * 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
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include "acparser.h"
47 #include "amlcode.h"
48 #include "acdispat.h"
49 #include "acinterp.h"
50 #include "acnamesp.h"
51 #include "acevents.h"
52
53 #define _COMPONENT ACPI_DISPATCHER
54 ACPI_MODULE_NAME("dswload2")
55
56 /*******************************************************************************
57 *
58 * FUNCTION: acpi_ds_load2_begin_op
59 *
60 * PARAMETERS: walk_state - Current state of the parse tree walk
61 * out_op - Wher to return op if a new one is created
62 *
63 * RETURN: Status
64 *
65 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
66 *
67 ******************************************************************************/
68 acpi_status
69 acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
70 union acpi_parse_object **out_op)
71 {
72 union acpi_parse_object *op;
73 struct acpi_namespace_node *node;
74 acpi_status status;
75 acpi_object_type object_type;
76 char *buffer_ptr;
77 u32 flags;
78
79 ACPI_FUNCTION_TRACE(ds_load2_begin_op);
80
81 op = walk_state->op;
82 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op,
83 walk_state));
84
85 if (op) {
86 if ((walk_state->control_state) &&
87 (walk_state->control_state->common.state ==
88 ACPI_CONTROL_CONDITIONAL_EXECUTING)) {
89
90 /* We are executing a while loop outside of a method */
91
92 status = acpi_ds_exec_begin_op(walk_state, out_op);
93 return_ACPI_STATUS(status);
94 }
95
96 /* We only care about Namespace opcodes here */
97
98 if ((!(walk_state->op_info->flags & AML_NSOPCODE) &&
99 (walk_state->opcode != AML_INT_NAMEPATH_OP)) ||
100 (!(walk_state->op_info->flags & AML_NAMED))) {
101 return_ACPI_STATUS(AE_OK);
102 }
103
104 /* Get the name we are going to enter or lookup in the namespace */
105
106 if (walk_state->opcode == AML_INT_NAMEPATH_OP) {
107
108 /* For Namepath op, get the path string */
109
110 buffer_ptr = op->common.value.string;
111 if (!buffer_ptr) {
112
113 /* No name, just exit */
114
115 return_ACPI_STATUS(AE_OK);
116 }
117 } else {
118 /* Get name from the op */
119
120 buffer_ptr = ACPI_CAST_PTR(char, &op->named.name);
121 }
122 } else {
123 /* Get the namestring from the raw AML */
124
125 buffer_ptr =
126 acpi_ps_get_next_namestring(&walk_state->parser_state);
127 }
128
129 /* Map the opcode into an internal object type */
130
131 object_type = walk_state->op_info->object_type;
132
133 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
134 "State=%p Op=%p Type=%X\n", walk_state, op,
135 object_type));
136
137 switch (walk_state->opcode) {
138 case AML_FIELD_OP:
139 case AML_BANK_FIELD_OP:
140 case AML_INDEX_FIELD_OP:
141
142 node = NULL;
143 status = AE_OK;
144 break;
145
146 case AML_INT_NAMEPATH_OP:
147 /*
148 * The name_path is an object reference to an existing object.
149 * Don't enter the name into the namespace, but look it up
150 * for use later.
151 */
152 status =
153 acpi_ns_lookup(walk_state->scope_info, buffer_ptr,
154 object_type, ACPI_IMODE_EXECUTE,
155 ACPI_NS_SEARCH_PARENT, walk_state, &(node));
156 break;
157
158 case AML_SCOPE_OP:
159
160 /* Special case for Scope(\) -> refers to the Root node */
161
162 if (op && (op->named.node == acpi_gbl_root_node)) {
163 node = op->named.node;
164
165 status =
166 acpi_ds_scope_stack_push(node, object_type,
167 walk_state);
168 if (ACPI_FAILURE(status)) {
169 return_ACPI_STATUS(status);
170 }
171 } else {
172 /*
173 * The Path is an object reference to an existing object.
174 * Don't enter the name into the namespace, but look it up
175 * for use later.
176 */
177 status =
178 acpi_ns_lookup(walk_state->scope_info, buffer_ptr,
179 object_type, ACPI_IMODE_EXECUTE,
180 ACPI_NS_SEARCH_PARENT, walk_state,
181 &(node));
182 if (ACPI_FAILURE(status)) {
183 #ifdef ACPI_ASL_COMPILER
184 if (status == AE_NOT_FOUND) {
185 status = AE_OK;
186 } else {
187 ACPI_ERROR_NAMESPACE(buffer_ptr,
188 status);
189 }
190 #else
191 ACPI_ERROR_NAMESPACE(buffer_ptr, status);
192 #endif
193 return_ACPI_STATUS(status);
194 }
195 }
196
197 /*
198 * We must check to make sure that the target is
199 * one of the opcodes that actually opens a scope
200 */
201 switch (node->type) {
202 case ACPI_TYPE_ANY:
203 case ACPI_TYPE_LOCAL_SCOPE: /* Scope */
204 case ACPI_TYPE_DEVICE:
205 case ACPI_TYPE_POWER:
206 case ACPI_TYPE_PROCESSOR:
207 case ACPI_TYPE_THERMAL:
208
209 /* These are acceptable types */
210 break;
211
212 case ACPI_TYPE_INTEGER:
213 case ACPI_TYPE_STRING:
214 case ACPI_TYPE_BUFFER:
215
216 /*
217 * These types we will allow, but we will change the type.
218 * This enables some existing code of the form:
219 *
220 * Name (DEB, 0)
221 * Scope (DEB) { ... }
222 */
223 ACPI_WARNING((AE_INFO,
224 "Type override - [%4.4s] had invalid type (%s) "
225 "for Scope operator, changed to type ANY",
226 acpi_ut_get_node_name(node),
227 acpi_ut_get_type_name(node->type)));
228
229 node->type = ACPI_TYPE_ANY;
230 walk_state->scope_info->common.value = ACPI_TYPE_ANY;
231 break;
232
233 case ACPI_TYPE_METHOD:
234
235 /*
236 * Allow scope change to root during execution of module-level
237 * code. Root is typed METHOD during this time.
238 */
239 if ((node == acpi_gbl_root_node) &&
240 (walk_state->
241 parse_flags & ACPI_PARSE_MODULE_LEVEL)) {
242 break;
243 }
244
245 /*lint -fallthrough */
246
247 default:
248
249 /* All other types are an error */
250
251 ACPI_ERROR((AE_INFO,
252 "Invalid type (%s) for target of "
253 "Scope operator [%4.4s] (Cannot override)",
254 acpi_ut_get_type_name(node->type),
255 acpi_ut_get_node_name(node)));
256
257 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
258 }
259 break;
260
261 default:
262
263 /* All other opcodes */
264
265 if (op && op->common.node) {
266
267 /* This op/node was previously entered into the namespace */
268
269 node = op->common.node;
270
271 if (acpi_ns_opens_scope(object_type)) {
272 status =
273 acpi_ds_scope_stack_push(node, object_type,
274 walk_state);
275 if (ACPI_FAILURE(status)) {
276 return_ACPI_STATUS(status);
277 }
278 }
279
280 return_ACPI_STATUS(AE_OK);
281 }
282
283 /*
284 * Enter the named type into the internal namespace. We enter the name
285 * as we go downward in the parse tree. Any necessary subobjects that
286 * involve arguments to the opcode must be created as we go back up the
287 * parse tree later.
288 *
289 * Note: Name may already exist if we are executing a deferred opcode.
290 */
291 if (walk_state->deferred_node) {
292
293 /* This name is already in the namespace, get the node */
294
295 node = walk_state->deferred_node;
296 status = AE_OK;
297 break;
298 }
299
300 flags = ACPI_NS_NO_UPSEARCH;
301 if (walk_state->pass_number == ACPI_IMODE_EXECUTE) {
302
303 /* Execution mode, node cannot already exist, node is temporary */
304
305 flags |= ACPI_NS_ERROR_IF_FOUND;
306
307 if (!
308 (walk_state->
309 parse_flags & ACPI_PARSE_MODULE_LEVEL)) {
310 flags |= ACPI_NS_TEMPORARY;
311 }
312 }
313 #ifdef ACPI_ASL_COMPILER
314
315 /*
316 * Do not open a scope for AML_EXTERNAL_OP
317 * acpi_ns_lookup can open a new scope based on the object type
318 * of this op. AML_EXTERNAL_OP is a declaration rather than a
319 * definition. In the case that this external is a method object,
320 * acpi_ns_lookup will open a new scope. However, an AML_EXTERNAL_OP
321 * associated with the ACPI_TYPE_METHOD is a declaration, rather than
322 * a definition. Flags is set to avoid opening a scope for any
323 * AML_EXTERNAL_OP.
324 */
325 if (walk_state->opcode == AML_EXTERNAL_OP) {
326 flags |= ACPI_NS_DONT_OPEN_SCOPE;
327 }
328 #endif
329
330 /* Add new entry or lookup existing entry */
331
332 status =
333 acpi_ns_lookup(walk_state->scope_info, buffer_ptr,
334 object_type, ACPI_IMODE_LOAD_PASS2, flags,
335 walk_state, &node);
336
337 if (ACPI_SUCCESS(status) && (flags & ACPI_NS_TEMPORARY)) {
338 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
339 "***New Node [%4.4s] %p is temporary\n",
340 acpi_ut_get_node_name(node), node));
341 }
342 break;
343 }
344
345 if (ACPI_FAILURE(status)) {
346 ACPI_ERROR_NAMESPACE(buffer_ptr, status);
347 return_ACPI_STATUS(status);
348 }
349
350 if (!op) {
351
352 /* Create a new op */
353
354 op = acpi_ps_alloc_op(walk_state->opcode, walk_state->aml);
355 if (!op) {
356 return_ACPI_STATUS(AE_NO_MEMORY);
357 }
358
359 /* Initialize the new op */
360
361 if (node) {
362 op->named.name = node->name.integer;
363 }
364 *out_op = op;
365 }
366
367 /*
368 * Put the Node in the "op" object that the parser uses, so we
369 * can get it again quickly when this scope is closed
370 */
371 op->common.node = node;
372 return_ACPI_STATUS(status);
373 }
374
375 /*******************************************************************************
376 *
377 * FUNCTION: acpi_ds_load2_end_op
378 *
379 * PARAMETERS: walk_state - Current state of the parse tree walk
380 *
381 * RETURN: Status
382 *
383 * DESCRIPTION: Ascending callback used during the loading of the namespace,
384 * both control methods and everything else.
385 *
386 ******************************************************************************/
387
388 acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
389 {
390 union acpi_parse_object *op;
391 acpi_status status = AE_OK;
392 acpi_object_type object_type;
393 struct acpi_namespace_node *node;
394 union acpi_parse_object *arg;
395 struct acpi_namespace_node *new_node;
396 #ifndef ACPI_NO_METHOD_EXECUTION
397 u32 i;
398 u8 region_space;
399 #endif
400
401 ACPI_FUNCTION_TRACE(ds_load2_end_op);
402
403 op = walk_state->op;
404 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
405 walk_state->op_info->name, op, walk_state));
406
407 /* Check if opcode had an associated namespace object */
408
409 if (!(walk_state->op_info->flags & AML_NSOBJECT)) {
410 return_ACPI_STATUS(AE_OK);
411 }
412
413 if (op->common.aml_opcode == AML_SCOPE_OP) {
414 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
415 "Ending scope Op=%p State=%p\n", op,
416 walk_state));
417 }
418
419 object_type = walk_state->op_info->object_type;
420
421 /*
422 * Get the Node/name from the earlier lookup
423 * (It was saved in the *op structure)
424 */
425 node = op->common.node;
426
427 /*
428 * Put the Node on the object stack (Contains the ACPI Name of
429 * this object)
430 */
431 walk_state->operands[0] = (void *)node;
432 walk_state->num_operands = 1;
433
434 /* Pop the scope stack */
435
436 if (acpi_ns_opens_scope(object_type) &&
437 (op->common.aml_opcode != AML_INT_METHODCALL_OP)) {
438 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
439 "(%s) Popping scope for Op %p\n",
440 acpi_ut_get_type_name(object_type), op));
441
442 status = acpi_ds_scope_stack_pop(walk_state);
443 if (ACPI_FAILURE(status)) {
444 goto cleanup;
445 }
446 }
447
448 /*
449 * Named operations are as follows:
450 *
451 * AML_ALIAS
452 * AML_BANKFIELD
453 * AML_CREATEBITFIELD
454 * AML_CREATEBYTEFIELD
455 * AML_CREATEDWORDFIELD
456 * AML_CREATEFIELD
457 * AML_CREATEQWORDFIELD
458 * AML_CREATEWORDFIELD
459 * AML_DATA_REGION
460 * AML_DEVICE
461 * AML_EVENT
462 * AML_FIELD
463 * AML_INDEXFIELD
464 * AML_METHOD
465 * AML_METHODCALL
466 * AML_MUTEX
467 * AML_NAME
468 * AML_NAMEDFIELD
469 * AML_OPREGION
470 * AML_POWERRES
471 * AML_PROCESSOR
472 * AML_SCOPE
473 * AML_THERMALZONE
474 */
475
476 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
477 "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
478 acpi_ps_get_opcode_name(op->common.aml_opcode),
479 walk_state, op, node));
480
481 /* Decode the opcode */
482
483 arg = op->common.value.arg;
484
485 switch (walk_state->op_info->type) {
486 #ifndef ACPI_NO_METHOD_EXECUTION
487
488 case AML_TYPE_CREATE_FIELD:
489 /*
490 * Create the field object, but the field buffer and index must
491 * be evaluated later during the execution phase
492 */
493 status = acpi_ds_create_buffer_field(op, walk_state);
494 break;
495
496 case AML_TYPE_NAMED_FIELD:
497 /*
498 * If we are executing a method, initialize the field
499 */
500 if (walk_state->method_node) {
501 status = acpi_ds_init_field_objects(op, walk_state);
502 }
503
504 switch (op->common.aml_opcode) {
505 case AML_INDEX_FIELD_OP:
506
507 status =
508 acpi_ds_create_index_field(op,
509 (acpi_handle)arg->common.
510 node, walk_state);
511 break;
512
513 case AML_BANK_FIELD_OP:
514
515 status =
516 acpi_ds_create_bank_field(op, arg->common.node,
517 walk_state);
518 break;
519
520 case AML_FIELD_OP:
521
522 status =
523 acpi_ds_create_field(op, arg->common.node,
524 walk_state);
525 break;
526
527 default:
528
529 /* All NAMED_FIELD opcodes must be handled above */
530 break;
531 }
532 break;
533
534 case AML_TYPE_NAMED_SIMPLE:
535
536 status = acpi_ds_create_operands(walk_state, arg);
537 if (ACPI_FAILURE(status)) {
538 goto cleanup;
539 }
540
541 switch (op->common.aml_opcode) {
542 case AML_PROCESSOR_OP:
543
544 status = acpi_ex_create_processor(walk_state);
545 break;
546
547 case AML_POWER_RESOURCE_OP:
548
549 status = acpi_ex_create_power_resource(walk_state);
550 break;
551
552 case AML_MUTEX_OP:
553
554 status = acpi_ex_create_mutex(walk_state);
555 break;
556
557 case AML_EVENT_OP:
558
559 status = acpi_ex_create_event(walk_state);
560 break;
561
562 case AML_ALIAS_OP:
563
564 status = acpi_ex_create_alias(walk_state);
565 break;
566
567 default:
568
569 /* Unknown opcode */
570
571 status = AE_OK;
572 goto cleanup;
573 }
574
575 /* Delete operands */
576
577 for (i = 1; i < walk_state->num_operands; i++) {
578 acpi_ut_remove_reference(walk_state->operands[i]);
579 walk_state->operands[i] = NULL;
580 }
581
582 break;
583 #endif /* ACPI_NO_METHOD_EXECUTION */
584
585 case AML_TYPE_NAMED_COMPLEX:
586
587 switch (op->common.aml_opcode) {
588 #ifndef ACPI_NO_METHOD_EXECUTION
589 case AML_REGION_OP:
590 case AML_DATA_REGION_OP:
591
592 if (op->common.aml_opcode == AML_REGION_OP) {
593 region_space = (acpi_adr_space_type)
594 ((op->common.value.arg)->common.value.
595 integer);
596 } else {
597 region_space = ACPI_ADR_SPACE_DATA_TABLE;
598 }
599
600 /*
601 * The op_region is not fully parsed at this time. The only valid
602 * argument is the space_id. (We must save the address of the
603 * AML of the address and length operands)
604 *
605 * If we have a valid region, initialize it. The namespace is
606 * unlocked at this point.
607 *
608 * Need to unlock interpreter if it is locked (if we are running
609 * a control method), in order to allow _REG methods to be run
610 * during acpi_ev_initialize_region.
611 */
612 if (walk_state->method_node) {
613 /*
614 * Executing a method: initialize the region and unlock
615 * the interpreter
616 */
617 status = acpi_ex_create_region(op->named.data,
618 op->named.length,
619 region_space,
620 walk_state);
621 if (ACPI_FAILURE(status)) {
622 return_ACPI_STATUS(status);
623 }
624 }
625
626 status =
627 acpi_ev_initialize_region
628 (acpi_ns_get_attached_object(node));
629 break;
630
631 case AML_NAME_OP:
632
633 status = acpi_ds_create_node(walk_state, node, op);
634 break;
635
636 case AML_METHOD_OP:
637 /*
638 * method_op pkg_length name_string method_flags term_list
639 *
640 * Note: We must create the method node/object pair as soon as we
641 * see the method declaration. This allows later pass1 parsing
642 * of invocations of the method (need to know the number of
643 * arguments.)
644 */
645 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
646 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
647 walk_state, op, op->named.node));
648
649 if (!acpi_ns_get_attached_object(op->named.node)) {
650 walk_state->operands[0] =
651 ACPI_CAST_PTR(void, op->named.node);
652 walk_state->num_operands = 1;
653
654 status =
655 acpi_ds_create_operands(walk_state,
656 op->common.value.
657 arg);
658 if (ACPI_SUCCESS(status)) {
659 status =
660 acpi_ex_create_method(op->named.
661 data,
662 op->named.
663 length,
664 walk_state);
665 }
666
667 walk_state->operands[0] = NULL;
668 walk_state->num_operands = 0;
669
670 if (ACPI_FAILURE(status)) {
671 return_ACPI_STATUS(status);
672 }
673 }
674 break;
675
676 #endif /* ACPI_NO_METHOD_EXECUTION */
677
678 default:
679
680 /* All NAMED_COMPLEX opcodes must be handled above */
681 break;
682 }
683 break;
684
685 case AML_CLASS_INTERNAL:
686
687 /* case AML_INT_NAMEPATH_OP: */
688 break;
689
690 case AML_CLASS_METHOD_CALL:
691
692 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
693 "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
694 walk_state, op, node));
695
696 /*
697 * Lookup the method name and save the Node
698 */
699 status =
700 acpi_ns_lookup(walk_state->scope_info,
701 arg->common.value.string, ACPI_TYPE_ANY,
702 ACPI_IMODE_LOAD_PASS2,
703 ACPI_NS_SEARCH_PARENT |
704 ACPI_NS_DONT_OPEN_SCOPE, walk_state,
705 &(new_node));
706 if (ACPI_SUCCESS(status)) {
707 /*
708 * Make sure that what we found is indeed a method
709 * We didn't search for a method on purpose, to see if the name
710 * would resolve
711 */
712 if (new_node->type != ACPI_TYPE_METHOD) {
713 status = AE_AML_OPERAND_TYPE;
714 }
715
716 /* We could put the returned object (Node) on the object stack for
717 * later, but for now, we will put it in the "op" object that the
718 * parser uses, so we can get it again at the end of this scope
719 */
720 op->common.node = new_node;
721 } else {
722 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
723 }
724 break;
725
726 default:
727
728 break;
729 }
730
731 cleanup:
732
733 /* Remove the Node pushed at the very beginning */
734
735 walk_state->operands[0] = NULL;
736 walk_state->num_operands = 0;
737 return_ACPI_STATUS(status);
738 }