aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/dispatcher/dsmethod.c
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@pobox.com>2006-02-07 01:47:12 -0500
committerJeff Garzik <jgarzik@pobox.com>2006-02-07 01:47:12 -0500
commit3c9b3a8575b4f2551e3b5b74ffa1c3559c6338eb (patch)
tree7f8d84353852401ec74e005f6f0b1eb958b9a70d /drivers/acpi/dispatcher/dsmethod.c
parentc0d3c0c0ce94d3db893577ae98e64414d92e49d8 (diff)
parentc03296a868ae7c91aa2d8b372184763b18f16d7a (diff)
Merge branch 'master'
Diffstat (limited to 'drivers/acpi/dispatcher/dsmethod.c')
-rw-r--r--drivers/acpi/dispatcher/dsmethod.c360
1 files changed, 221 insertions, 139 deletions
diff --git a/drivers/acpi/dispatcher/dsmethod.c b/drivers/acpi/dispatcher/dsmethod.c
index 36c1ca0b9adb..c475546535b6 100644
--- a/drivers/acpi/dispatcher/dsmethod.c
+++ b/drivers/acpi/dispatcher/dsmethod.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2005, R. Byron Moore 8 * Copyright (C) 2000 - 2006, R. Byron Moore
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -47,135 +47,66 @@
47#include <acpi/acdispat.h> 47#include <acpi/acdispat.h>
48#include <acpi/acinterp.h> 48#include <acpi/acinterp.h>
49#include <acpi/acnamesp.h> 49#include <acpi/acnamesp.h>
50#include <acpi/acdisasm.h>
50 51
51#define _COMPONENT ACPI_DISPATCHER 52#define _COMPONENT ACPI_DISPATCHER
52ACPI_MODULE_NAME("dsmethod") 53ACPI_MODULE_NAME("dsmethod")
53 54
54/******************************************************************************* 55/*******************************************************************************
55 * 56 *
56 * FUNCTION: acpi_ds_parse_method 57 * FUNCTION: acpi_ds_method_error
57 * 58 *
58 * PARAMETERS: Node - Method node 59 * PARAMETERS: Status - Execution status
60 * walk_state - Current state
59 * 61 *
60 * RETURN: Status 62 * RETURN: Status
61 * 63 *
62 * DESCRIPTION: Parse the AML that is associated with the method. 64 * DESCRIPTION: Called on method error. Invoke the global exception handler if
65 * present, dump the method data if the disassembler is configured
63 * 66 *
64 * MUTEX: Assumes parser is locked 67 * Note: Allows the exception handler to change the status code
65 * 68 *
66 ******************************************************************************/ 69 ******************************************************************************/
67acpi_status acpi_ds_parse_method(struct acpi_namespace_node *node) 70acpi_status
71acpi_ds_method_error(acpi_status status, struct acpi_walk_state *walk_state)
68{ 72{
69 acpi_status status; 73 ACPI_FUNCTION_ENTRY();
70 union acpi_operand_object *obj_desc;
71 union acpi_parse_object *op;
72 struct acpi_walk_state *walk_state;
73
74 ACPI_FUNCTION_TRACE_PTR("ds_parse_method", node);
75 74
76 /* Parameter Validation */ 75 /* Ignore AE_OK and control exception codes */
77 76
78 if (!node) { 77 if (ACPI_SUCCESS(status) || (status & AE_CODE_CONTROL)) {
79 return_ACPI_STATUS(AE_NULL_ENTRY); 78 return (status);
80 } 79 }
81 80
82 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, 81 /* Invoke the global exception handler */
83 "**** Parsing [%4.4s] **** named_obj=%p\n",
84 acpi_ut_get_node_name(node), node));
85
86 /* Extract the method object from the method Node */
87 82
88 obj_desc = acpi_ns_get_attached_object(node); 83 if (acpi_gbl_exception_handler) {
89 if (!obj_desc) { 84 /* Exit the interpreter, allow handler to execute methods */
90 return_ACPI_STATUS(AE_NULL_OBJECT);
91 }
92 85
93 /* Create a mutex for the method if there is a concurrency limit */ 86 acpi_ex_exit_interpreter();
94 87
95 if ((obj_desc->method.concurrency != ACPI_INFINITE_CONCURRENCY) && 88 /*
96 (!obj_desc->method.semaphore)) { 89 * Handler can map the exception code to anything it wants, including
97 status = acpi_os_create_semaphore(obj_desc->method.concurrency, 90 * AE_OK, in which case the executing method will not be aborted.
98 obj_desc->method.concurrency, 91 */
99 &obj_desc->method.semaphore); 92 status = acpi_gbl_exception_handler(status,
100 if (ACPI_FAILURE(status)) { 93 walk_state->method_node ?
101 return_ACPI_STATUS(status); 94 walk_state->method_node->
102 } 95 name.integer : 0,
103 } 96 walk_state->opcode,
104 97 walk_state->aml_offset,
105 /* 98 NULL);
106 * Allocate a new parser op to be the root of the parsed 99 (void)acpi_ex_enter_interpreter();
107 * method tree
108 */
109 op = acpi_ps_alloc_op(AML_METHOD_OP);
110 if (!op) {
111 return_ACPI_STATUS(AE_NO_MEMORY);
112 }
113
114 /* Init new op with the method name and pointer back to the Node */
115
116 acpi_ps_set_name(op, node->name.integer);
117 op->common.node = node;
118
119 /*
120 * Get a new owner_id for objects created by this method. Namespace
121 * objects (such as Operation Regions) can be created during the
122 * first pass parse.
123 */
124 status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id);
125 if (ACPI_FAILURE(status)) {
126 goto cleanup;
127 }
128
129 /* Create and initialize a new walk state */
130
131 walk_state =
132 acpi_ds_create_walk_state(obj_desc->method.owner_id, NULL, NULL,
133 NULL);
134 if (!walk_state) {
135 status = AE_NO_MEMORY;
136 goto cleanup2;
137 } 100 }
138 101#ifdef ACPI_DISASSEMBLER
139 status = acpi_ds_init_aml_walk(walk_state, op, node,
140 obj_desc->method.aml_start,
141 obj_desc->method.aml_length, NULL, 1);
142 if (ACPI_FAILURE(status)) { 102 if (ACPI_FAILURE(status)) {
143 acpi_ds_delete_walk_state(walk_state); 103 /* Display method locals/args if disassembler is present */
144 goto cleanup2;
145 }
146 104
147 /* 105 acpi_dm_dump_method_info(status, walk_state, walk_state->op);
148 * Parse the method, first pass
149 *
150 * The first pass load is where newly declared named objects are added into
151 * the namespace. Actual evaluation of the named objects (what would be
152 * called a "second pass") happens during the actual execution of the
153 * method so that operands to the named objects can take on dynamic
154 * run-time values.
155 */
156 status = acpi_ps_parse_aml(walk_state);
157 if (ACPI_FAILURE(status)) {
158 goto cleanup2;
159 } 106 }
107#endif
160 108
161 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, 109 return (status);
162 "**** [%4.4s] Parsed **** named_obj=%p Op=%p\n",
163 acpi_ut_get_node_name(node), node, op));
164
165 /*
166 * Delete the parse tree. We simply re-parse the method for every
167 * execution since there isn't much overhead (compared to keeping lots
168 * of parse trees around)
169 */
170 acpi_ns_delete_namespace_subtree(node);
171 acpi_ns_delete_namespace_by_owner(obj_desc->method.owner_id);
172
173 cleanup2:
174 acpi_ut_release_owner_id(&obj_desc->method.owner_id);
175
176 cleanup:
177 acpi_ps_delete_parse_tree(op);
178 return_ACPI_STATUS(status);
179} 110}
180 111
181/******************************************************************************* 112/*******************************************************************************
@@ -195,9 +126,9 @@ acpi_status acpi_ds_parse_method(struct acpi_namespace_node *node)
195 ******************************************************************************/ 126 ******************************************************************************/
196 127
197acpi_status 128acpi_status
198acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node, 129acpi_ds_begin_method_execution(struct acpi_namespace_node * method_node,
199 union acpi_operand_object *obj_desc, 130 union acpi_operand_object * obj_desc,
200 struct acpi_namespace_node *calling_method_node) 131 struct acpi_namespace_node * calling_method_node)
201{ 132{
202 acpi_status status = AE_OK; 133 acpi_status status = AE_OK;
203 134
@@ -210,7 +141,8 @@ acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,
210 /* Prevent wraparound of thread count */ 141 /* Prevent wraparound of thread count */
211 142
212 if (obj_desc->method.thread_count == ACPI_UINT8_MAX) { 143 if (obj_desc->method.thread_count == ACPI_UINT8_MAX) {
213 ACPI_REPORT_ERROR(("Method reached maximum reentrancy limit (255)\n")); 144 ACPI_ERROR((AE_INFO,
145 "Method reached maximum reentrancy limit (255)"));
214 return_ACPI_STATUS(AE_AML_METHOD_LIMIT); 146 return_ACPI_STATUS(AE_AML_METHOD_LIMIT);
215 } 147 }
216 148
@@ -539,22 +471,61 @@ void acpi_ds_terminate_control_method(struct acpi_walk_state *walk_state)
539 acpi_os_signal_semaphore(walk_state->method_desc->method. 471 acpi_os_signal_semaphore(walk_state->method_desc->method.
540 semaphore, 1); 472 semaphore, 1);
541 if (ACPI_FAILURE(status)) { 473 if (ACPI_FAILURE(status)) {
542 ACPI_REPORT_ERROR(("Could not signal method semaphore\n")); 474 ACPI_ERROR((AE_INFO,
475 "Could not signal method semaphore"));
543 476
544 /* Ignore error and continue cleanup */ 477 /* Ignore error and continue cleanup */
545 } 478 }
546 } 479 }
547 480
481 /*
482 * There are no more threads executing this method. Perform
483 * additional cleanup.
484 *
485 * The method Node is stored in the walk state
486 */
487 method_node = walk_state->method_node;
488
489 /* Lock namespace for possible update */
490
491 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
492 if (ACPI_FAILURE(status)) {
493 goto exit;
494 }
495
496 /*
497 * Delete any namespace entries created immediately underneath
498 * the method
499 */
500 if (method_node->child) {
501 acpi_ns_delete_namespace_subtree(method_node);
502 }
503
504 /*
505 * Delete any namespace entries created anywhere else within
506 * the namespace by the execution of this method
507 */
508 acpi_ns_delete_namespace_by_owner(walk_state->method_desc->method.
509 owner_id);
510 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
511
512 /* Are there any other threads currently executing this method? */
513
548 if (walk_state->method_desc->method.thread_count) { 514 if (walk_state->method_desc->method.thread_count) {
515 /*
516 * Additional threads. Do not release the owner_id in this case,
517 * we immediately reuse it for the next thread executing this method
518 */
549 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, 519 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
550 "*** Not deleting method namespace, there are still %d threads\n", 520 "*** Completed execution of one thread, %d threads remaining\n",
551 walk_state->method_desc->method. 521 walk_state->method_desc->method.
552 thread_count)); 522 thread_count));
553 } else { /* This is the last executing thread */ 523 } else {
524 /* This is the only executing thread for this method */
554 525
555 /* 526 /*
556 * Support to dynamically change a method from not_serialized to 527 * Support to dynamically change a method from not_serialized to
557 * Serialized if it appears that the method is written foolishly and 528 * Serialized if it appears that the method is incorrectly written and
558 * does not support multiple thread execution. The best example of this 529 * does not support multiple thread execution. The best example of this
559 * is if such a method creates namespace objects and blocks. A second 530 * is if such a method creates namespace objects and blocks. A second
560 * thread will fail with an AE_ALREADY_EXISTS exception 531 * thread will fail with an AE_ALREADY_EXISTS exception
@@ -570,34 +541,8 @@ void acpi_ds_terminate_control_method(struct acpi_walk_state *walk_state)
570 semaphore); 541 semaphore);
571 } 542 }
572 543
573 /* 544 /* No more threads, we can free the owner_id */
574 * There are no more threads executing this method. Perform
575 * additional cleanup.
576 *
577 * The method Node is stored in the walk state
578 */
579 method_node = walk_state->method_node;
580
581 /*
582 * Delete any namespace entries created immediately underneath
583 * the method
584 */
585 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
586 if (ACPI_FAILURE(status)) {
587 goto exit;
588 }
589
590 if (method_node->child) {
591 acpi_ns_delete_namespace_subtree(method_node);
592 }
593 545
594 /*
595 * Delete any namespace entries created anywhere else within
596 * the namespace
597 */
598 acpi_ns_delete_namespace_by_owner(walk_state->method_desc->
599 method.owner_id);
600 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
601 acpi_ut_release_owner_id(&walk_state->method_desc->method. 546 acpi_ut_release_owner_id(&walk_state->method_desc->method.
602 owner_id); 547 owner_id);
603 } 548 }
@@ -606,3 +551,140 @@ void acpi_ds_terminate_control_method(struct acpi_walk_state *walk_state)
606 (void)acpi_ut_release_mutex(ACPI_MTX_PARSER); 551 (void)acpi_ut_release_mutex(ACPI_MTX_PARSER);
607 return_VOID; 552 return_VOID;
608} 553}
554
555#ifdef ACPI_INIT_PARSE_METHODS
556 /*
557 * Note 11/2005: Removed this code to parse all methods during table
558 * load because it causes problems if there are any errors during the
559 * parse. Also, it seems like overkill and we probably don't want to
560 * abort a table load because of an issue with a single method.
561 */
562
563/*******************************************************************************
564 *
565 * FUNCTION: acpi_ds_parse_method
566 *
567 * PARAMETERS: Node - Method node
568 *
569 * RETURN: Status
570 *
571 * DESCRIPTION: Parse the AML that is associated with the method.
572 *
573 * MUTEX: Assumes parser is locked
574 *
575 ******************************************************************************/
576
577acpi_status acpi_ds_parse_method(struct acpi_namespace_node *node)
578{
579 acpi_status status;
580 union acpi_operand_object *obj_desc;
581 union acpi_parse_object *op;
582 struct acpi_walk_state *walk_state;
583
584 ACPI_FUNCTION_TRACE_PTR("ds_parse_method", node);
585
586 /* Parameter Validation */
587
588 if (!node) {
589 return_ACPI_STATUS(AE_NULL_ENTRY);
590 }
591
592 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
593 "**** Parsing [%4.4s] **** named_obj=%p\n",
594 acpi_ut_get_node_name(node), node));
595
596 /* Extract the method object from the method Node */
597
598 obj_desc = acpi_ns_get_attached_object(node);
599 if (!obj_desc) {
600 return_ACPI_STATUS(AE_NULL_OBJECT);
601 }
602
603 /* Create a mutex for the method if there is a concurrency limit */
604
605 if ((obj_desc->method.concurrency != ACPI_INFINITE_CONCURRENCY) &&
606 (!obj_desc->method.semaphore)) {
607 status = acpi_os_create_semaphore(obj_desc->method.concurrency,
608 obj_desc->method.concurrency,
609 &obj_desc->method.semaphore);
610 if (ACPI_FAILURE(status)) {
611 return_ACPI_STATUS(status);
612 }
613 }
614
615 /*
616 * Allocate a new parser op to be the root of the parsed
617 * method tree
618 */
619 op = acpi_ps_alloc_op(AML_METHOD_OP);
620 if (!op) {
621 return_ACPI_STATUS(AE_NO_MEMORY);
622 }
623
624 /* Init new op with the method name and pointer back to the Node */
625
626 acpi_ps_set_name(op, node->name.integer);
627 op->common.node = node;
628
629 /*
630 * Get a new owner_id for objects created by this method. Namespace
631 * objects (such as Operation Regions) can be created during the
632 * first pass parse.
633 */
634 status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id);
635 if (ACPI_FAILURE(status)) {
636 goto cleanup;
637 }
638
639 /* Create and initialize a new walk state */
640
641 walk_state =
642 acpi_ds_create_walk_state(obj_desc->method.owner_id, NULL, NULL,
643 NULL);
644 if (!walk_state) {
645 status = AE_NO_MEMORY;
646 goto cleanup2;
647 }
648
649 status = acpi_ds_init_aml_walk(walk_state, op, node,
650 obj_desc->method.aml_start,
651 obj_desc->method.aml_length, NULL, 1);
652 if (ACPI_FAILURE(status)) {
653 acpi_ds_delete_walk_state(walk_state);
654 goto cleanup2;
655 }
656
657 /*
658 * Parse the method, first pass
659 *
660 * The first pass load is where newly declared named objects are added into
661 * the namespace. Actual evaluation of the named objects (what would be
662 * called a "second pass") happens during the actual execution of the
663 * method so that operands to the named objects can take on dynamic
664 * run-time values.
665 */
666 status = acpi_ps_parse_aml(walk_state);
667 if (ACPI_FAILURE(status)) {
668 goto cleanup2;
669 }
670
671 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
672 "**** [%4.4s] Parsed **** named_obj=%p Op=%p\n",
673 acpi_ut_get_node_name(node), node, op));
674
675 /*
676 * Delete the parse tree. We simply re-parse the method for every
677 * execution since there isn't much overhead (compared to keeping lots
678 * of parse trees around)
679 */
680 acpi_ns_delete_namespace_subtree(node);
681 acpi_ns_delete_namespace_by_owner(obj_desc->method.owner_id);
682
683 cleanup2:
684 acpi_ut_release_owner_id(&obj_desc->method.owner_id);
685
686 cleanup:
687 acpi_ps_delete_parse_tree(op);
688 return_ACPI_STATUS(status);
689}
690#endif