Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: psxface - Parser external interfaces |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
| 8 | * Copyright (C) 2000 - 2005, R. Byron Moore |
| 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> |
| 45 | #include <acpi/acparser.h> |
| 46 | #include <acpi/acdispat.h> |
| 47 | #include <acpi/acinterp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #define _COMPONENT ACPI_PARSER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 50 | ACPI_MODULE_NAME("psxface") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 52 | /* Local Prototypes */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 53 | static acpi_status acpi_ps_execute_pass(struct acpi_parameter_info *info); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 54 | |
| 55 | static void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 56 | acpi_ps_update_parameter_list(struct acpi_parameter_info *info, u16 action); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | /******************************************************************************* |
| 59 | * |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 60 | * FUNCTION: acpi_ps_execute_method |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 62 | * PARAMETERS: Info - Method info block, contains: |
| 63 | * Node - Method Node to execute |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 64 | * obj_desc - Method object |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 65 | * Parameters - List of parameters to pass to the method, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | * terminated by NULL. Params itself may be |
| 67 | * NULL if no parameters are being passed. |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 68 | * return_object - Where to put method's return value (if |
| 69 | * any). If NULL, no value is returned. |
| 70 | * parameter_type - Type of Parameter list |
| 71 | * return_object - Where to put method's return value (if |
| 72 | * any). If NULL, no value is returned. |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 73 | * pass_number - Parse or execute pass |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | * |
| 75 | * RETURN: Status |
| 76 | * |
| 77 | * DESCRIPTION: Execute a control method |
| 78 | * |
| 79 | ******************************************************************************/ |
| 80 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 81 | acpi_status acpi_ps_execute_method(struct acpi_parameter_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 83 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 85 | ACPI_FUNCTION_TRACE("ps_execute_method"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 87 | /* Validate the Info and method Node */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | if (!info || !info->node) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 90 | return_ACPI_STATUS(AE_NULL_ENTRY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | /* Init for new method, wait on concurrency semaphore */ |
| 94 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 95 | status = |
| 96 | acpi_ds_begin_method_execution(info->node, info->obj_desc, NULL); |
| 97 | if (ACPI_FAILURE(status)) { |
| 98 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | /* |
| 102 | * Get a new owner_id for objects created by this method. Namespace |
| 103 | * objects (such as Operation Regions) can be created during the |
| 104 | * first pass parse. |
| 105 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 106 | status = acpi_ut_allocate_owner_id(&info->obj_desc->method.owner_id); |
| 107 | if (ACPI_FAILURE(status)) { |
| 108 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /* |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 112 | * The caller "owns" the parameters, so give each one an extra |
| 113 | * reference |
| 114 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 115 | acpi_ps_update_parameter_list(info, REF_INCREMENT); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 116 | |
| 117 | /* |
| 118 | * 1) Perform the first pass parse of the method to enter any |
| 119 | * named objects that it creates into the namespace |
| 120 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 121 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, |
| 122 | "**** Begin Method Parse **** Entry=%p obj=%p\n", |
| 123 | info->node, info->obj_desc)); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 124 | |
| 125 | info->pass_number = 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 126 | status = acpi_ps_execute_pass(info); |
| 127 | if (ACPI_FAILURE(status)) { |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 128 | goto cleanup; |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * 2) Execute the method. Performs second pass parse simultaneously |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 134 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, |
| 135 | "**** Begin Method Execution **** Entry=%p obj=%p\n", |
| 136 | info->node, info->obj_desc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 138 | info->pass_number = 3; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 139 | status = acpi_ps_execute_pass(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 141 | cleanup: |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 142 | if (info->obj_desc->method.owner_id) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 143 | acpi_ut_release_owner_id(&info->obj_desc->method.owner_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 146 | /* Take away the extra reference that we gave the parameters above */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 148 | acpi_ps_update_parameter_list(info, REF_DECREMENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 150 | /* Exit now if error above */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 152 | if (ACPI_FAILURE(status)) { |
| 153 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | /* |
| 157 | * If the method has returned an object, signal this to the caller with |
| 158 | * a control exception code |
| 159 | */ |
| 160 | if (info->return_object) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 161 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, |
| 162 | "Method returned obj_desc=%p\n", |
| 163 | info->return_object)); |
| 164 | ACPI_DUMP_STACK_ENTRY(info->return_object); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
| 166 | status = AE_CTRL_RETURN_VALUE; |
| 167 | } |
| 168 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 169 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 172 | /******************************************************************************* |
| 173 | * |
| 174 | * FUNCTION: acpi_ps_update_parameter_list |
| 175 | * |
| 176 | * PARAMETERS: Info - See struct acpi_parameter_info |
| 177 | * (Used: parameter_type and Parameters) |
| 178 | * Action - Add or Remove reference |
| 179 | * |
| 180 | * RETURN: Status |
| 181 | * |
| 182 | * DESCRIPTION: Update reference count on all method parameter objects |
| 183 | * |
| 184 | ******************************************************************************/ |
| 185 | |
| 186 | static void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 187 | acpi_ps_update_parameter_list(struct acpi_parameter_info *info, u16 action) |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 188 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 189 | acpi_native_uint i; |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 190 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 191 | if ((info->parameter_type == ACPI_PARAM_ARGS) && (info->parameters)) { |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 192 | /* Update reference count for each parameter */ |
| 193 | |
| 194 | for (i = 0; info->parameters[i]; i++) { |
| 195 | /* Ignore errors, just do them all */ |
| 196 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 197 | (void)acpi_ut_update_object_reference(info-> |
| 198 | parameters[i], |
| 199 | action); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 204 | /******************************************************************************* |
| 205 | * |
| 206 | * FUNCTION: acpi_ps_execute_pass |
| 207 | * |
| 208 | * PARAMETERS: Info - See struct acpi_parameter_info |
| 209 | * (Used: pass_number, Node, and obj_desc) |
| 210 | * |
| 211 | * RETURN: Status |
| 212 | * |
| 213 | * DESCRIPTION: Single AML pass: Parse or Execute a control method |
| 214 | * |
| 215 | ******************************************************************************/ |
| 216 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 217 | static acpi_status acpi_ps_execute_pass(struct acpi_parameter_info *info) |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 218 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 219 | acpi_status status; |
| 220 | union acpi_parse_object *op; |
| 221 | struct acpi_walk_state *walk_state; |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 222 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 223 | ACPI_FUNCTION_TRACE("ps_execute_pass"); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 224 | |
| 225 | /* Create and init a Root Node */ |
| 226 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 227 | op = acpi_ps_create_scope_op(); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 228 | if (!op) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 229 | return_ACPI_STATUS(AE_NO_MEMORY); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /* Create and initialize a new walk state */ |
| 233 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 234 | walk_state = |
| 235 | acpi_ds_create_walk_state(info->obj_desc->method.owner_id, NULL, |
| 236 | NULL, NULL); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 237 | if (!walk_state) { |
| 238 | status = AE_NO_MEMORY; |
| 239 | goto cleanup; |
| 240 | } |
| 241 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 242 | status = acpi_ds_init_aml_walk(walk_state, op, info->node, |
| 243 | info->obj_desc->method.aml_start, |
| 244 | info->obj_desc->method.aml_length, |
| 245 | info->pass_number == 1 ? NULL : info, |
| 246 | info->pass_number); |
| 247 | if (ACPI_FAILURE(status)) { |
| 248 | acpi_ds_delete_walk_state(walk_state); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 249 | goto cleanup; |
| 250 | } |
| 251 | |
| 252 | /* Parse the AML */ |
| 253 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 254 | status = acpi_ps_parse_aml(walk_state); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 255 | |
| 256 | /* Walk state was deleted by parse_aml */ |
| 257 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 258 | cleanup: |
| 259 | acpi_ps_delete_parse_tree(op); |
| 260 | return_ACPI_STATUS(status); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 261 | } |