Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: psargs - Parse AML opcode arguments |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | c8100dc | 2016-01-15 08:17:03 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2016, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 45 | #include "accommon.h" |
| 46 | #include "acparser.h" |
| 47 | #include "amlcode.h" |
| 48 | #include "acnamesp.h" |
| 49 | #include "acdispat.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | #define _COMPONENT ACPI_PARSER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | ACPI_MODULE_NAME("psargs") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 54 | /* Local prototypes */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 55 | static u32 |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 56 | acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 57 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 58 | static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state |
| 59 | *parser_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
| 61 | /******************************************************************************* |
| 62 | * |
| 63 | * FUNCTION: acpi_ps_get_next_package_length |
| 64 | * |
| 65 | * PARAMETERS: parser_state - Current parser state object |
| 66 | * |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 67 | * RETURN: Decoded package length. On completion, the AML pointer points |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | * past the length byte or bytes. |
| 69 | * |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 70 | * DESCRIPTION: Decode and return a package length field. |
| 71 | * Note: Largest package length is 28 bits, from ACPI specification |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | * |
| 73 | ******************************************************************************/ |
| 74 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 75 | static u32 |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 76 | acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 78 | u8 *aml = parser_state->aml; |
| 79 | u32 package_length = 0; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 80 | u32 byte_count; |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 81 | u8 byte_zero_mask = 0x3F; /* Default [0:5] */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 83 | ACPI_FUNCTION_TRACE(ps_get_next_package_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 85 | /* |
| 86 | * Byte 0 bits [6:7] contain the number of additional bytes |
| 87 | * used to encode the package length, either 0,1,2, or 3 |
| 88 | */ |
| 89 | byte_count = (aml[0] >> 6); |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 90 | parser_state->aml += ((acpi_size) byte_count + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 92 | /* Get bytes 3, 2, 1 as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 94 | while (byte_count) { |
| 95 | /* |
| 96 | * Final bit positions for the package length bytes: |
| 97 | * Byte3->[20:27] |
| 98 | * Byte2->[12:19] |
| 99 | * Byte1->[04:11] |
| 100 | * Byte0->[00:03] |
| 101 | */ |
| 102 | package_length |= (aml[byte_count] << ((byte_count << 3) - 4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 104 | byte_zero_mask = 0x0F; /* Use bits [0:3] of byte 0 */ |
| 105 | byte_count--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 108 | /* Byte 0 is a special case, either bits [0:3] or [0:5] are used */ |
| 109 | |
| 110 | package_length |= (aml[0] & byte_zero_mask); |
Bob Moore | fd1af71 | 2013-03-08 09:22:23 +0000 | [diff] [blame] | 111 | return_UINT32(package_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | /******************************************************************************* |
| 115 | * |
| 116 | * FUNCTION: acpi_ps_get_next_package_end |
| 117 | * |
| 118 | * PARAMETERS: parser_state - Current parser state object |
| 119 | * |
| 120 | * RETURN: Pointer to end-of-package +1 |
| 121 | * |
| 122 | * DESCRIPTION: Get next package length and return a pointer past the end of |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 123 | * the package. Consumes the package length field |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | * |
| 125 | ******************************************************************************/ |
| 126 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 127 | u8 *acpi_ps_get_next_package_end(struct acpi_parse_state *parser_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 129 | u8 *start = parser_state->aml; |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 130 | u32 package_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 132 | ACPI_FUNCTION_TRACE(ps_get_next_package_end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 134 | /* Function below updates parser_state->Aml */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 136 | package_length = acpi_ps_get_next_package_length(parser_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 138 | return_PTR(start + package_length); /* end of package */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | /******************************************************************************* |
| 142 | * |
| 143 | * FUNCTION: acpi_ps_get_next_namestring |
| 144 | * |
| 145 | * PARAMETERS: parser_state - Current parser state object |
| 146 | * |
| 147 | * RETURN: Pointer to the start of the name string (pointer points into |
| 148 | * the AML. |
| 149 | * |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 150 | * DESCRIPTION: Get next raw namestring within the AML stream. Handles all name |
| 151 | * prefix characters. Set parser state to point past the string. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | * (Name is consumed from the AML.) |
| 153 | * |
| 154 | ******************************************************************************/ |
| 155 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | char *acpi_ps_get_next_namestring(struct acpi_parse_state *parser_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 158 | u8 *start = parser_state->aml; |
| 159 | u8 *end = parser_state->aml; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 161 | ACPI_FUNCTION_TRACE(ps_get_next_namestring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 163 | /* Point past any namestring prefix characters (backslash or carat) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
Bob Moore | 04a81dc | 2012-12-31 00:05:17 +0000 | [diff] [blame] | 165 | while (ACPI_IS_ROOT_PREFIX(*end) || ACPI_IS_PARENT_PREFIX(*end)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | end++; |
| 167 | } |
| 168 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 169 | /* Decode the path prefix character */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 171 | switch (*end) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | case 0: |
| 173 | |
| 174 | /* null_name */ |
| 175 | |
| 176 | if (end == start) { |
| 177 | start = NULL; |
| 178 | } |
| 179 | end++; |
| 180 | break; |
| 181 | |
| 182 | case AML_DUAL_NAME_PREFIX: |
| 183 | |
| 184 | /* Two name segments */ |
| 185 | |
| 186 | end += 1 + (2 * ACPI_NAME_SIZE); |
| 187 | break; |
| 188 | |
| 189 | case AML_MULTI_NAME_PREFIX_OP: |
| 190 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 191 | /* Multiple name segments, 4 chars each, count in next byte */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 193 | end += 2 + (*(end + 1) * ACPI_NAME_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | break; |
| 195 | |
| 196 | default: |
| 197 | |
| 198 | /* Single name segment */ |
| 199 | |
| 200 | end += ACPI_NAME_SIZE; |
| 201 | break; |
| 202 | } |
| 203 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 204 | parser_state->aml = end; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 205 | return_PTR((char *)start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | /******************************************************************************* |
| 209 | * |
| 210 | * FUNCTION: acpi_ps_get_next_namepath |
| 211 | * |
| 212 | * PARAMETERS: parser_state - Current parser state object |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 213 | * arg - Where the namepath will be stored |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | * arg_count - If the namepath points to a control method |
| 215 | * the method's argument is returned here. |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 216 | * possible_method_call - Whether the namepath can possibly be the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | * start of a method call |
| 218 | * |
| 219 | * RETURN: Status |
| 220 | * |
| 221 | * DESCRIPTION: Get next name (if method call, return # of required args). |
| 222 | * Names are looked up in the internal namespace to determine |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 223 | * if the name represents a control method. If a method |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | * is found, the number of arguments to the method is returned. |
| 225 | * This information is critical for parsing to continue correctly. |
| 226 | * |
| 227 | ******************************************************************************/ |
| 228 | |
| 229 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 230 | acpi_ps_get_next_namepath(struct acpi_walk_state *walk_state, |
| 231 | struct acpi_parse_state *parser_state, |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 232 | union acpi_parse_object *arg, u8 possible_method_call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { |
Lin Ming | 1480882 | 2008-04-10 19:06:38 +0400 | [diff] [blame] | 234 | acpi_status status; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 235 | char *path; |
| 236 | union acpi_parse_object *name_op; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 237 | union acpi_operand_object *method_desc; |
| 238 | struct acpi_namespace_node *node; |
Lin Ming | bc7a36a | 2008-04-10 19:06:42 +0400 | [diff] [blame] | 239 | u8 *start = parser_state->aml; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 241 | ACPI_FUNCTION_TRACE(ps_get_next_namepath); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 243 | path = acpi_ps_get_next_namestring(parser_state); |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 244 | acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 246 | /* Null path case is allowed, just exit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 248 | if (!path) { |
| 249 | arg->common.value.name = path; |
| 250 | return_ACPI_STATUS(AE_OK); |
| 251 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | /* |
Lin Ming | 1480882 | 2008-04-10 19:06:38 +0400 | [diff] [blame] | 254 | * Lookup the name in the internal namespace, starting with the current |
| 255 | * scope. We don't want to add anything new to the namespace here, |
| 256 | * however, so we use MODE_EXECUTE. |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 257 | * Allow searching of the parent tree, but don't open a new scope - |
| 258 | * we just want to lookup the object (must be mode EXECUTE to perform |
| 259 | * the upsearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | */ |
Lin Ming | 1480882 | 2008-04-10 19:06:38 +0400 | [diff] [blame] | 261 | status = acpi_ns_lookup(walk_state->scope_info, path, |
| 262 | ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, |
| 263 | ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, |
| 264 | NULL, &node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 266 | /* |
| 267 | * If this name is a control method invocation, we must |
| 268 | * setup the method call |
| 269 | */ |
| 270 | if (ACPI_SUCCESS(status) && |
| 271 | possible_method_call && (node->type == ACPI_TYPE_METHOD)) { |
Bob Moore | ae90fbf | 2015-12-29 14:00:14 +0800 | [diff] [blame] | 272 | if (GET_CURRENT_ARG_TYPE(walk_state->arg_types) == |
| 273 | ARGP_SUPERNAME) { |
Lin Ming | bc7a36a | 2008-04-10 19:06:42 +0400 | [diff] [blame] | 274 | /* |
| 275 | * acpi_ps_get_next_namestring has increased the AML pointer, |
| 276 | * so we need to restore the saved AML pointer for method call. |
| 277 | */ |
| 278 | walk_state->parser_state.aml = start; |
| 279 | walk_state->arg_count = 1; |
| 280 | acpi_ps_init_op(arg, AML_INT_METHODCALL_OP); |
| 281 | return_ACPI_STATUS(AE_OK); |
| 282 | } |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 283 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 284 | /* This name is actually a control method invocation */ |
| 285 | |
| 286 | method_desc = acpi_ns_get_attached_object(node); |
| 287 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, |
| 288 | "Control Method - %p Desc %p Path=%p\n", node, |
| 289 | method_desc, path)); |
| 290 | |
Lv Zheng | 62eb935 | 2015-07-23 12:52:24 +0800 | [diff] [blame] | 291 | name_op = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, start); |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 292 | if (!name_op) { |
| 293 | return_ACPI_STATUS(AE_NO_MEMORY); |
| 294 | } |
| 295 | |
| 296 | /* Change Arg into a METHOD CALL and attach name to it */ |
| 297 | |
| 298 | acpi_ps_init_op(arg, AML_INT_METHODCALL_OP); |
| 299 | name_op->common.value.name = path; |
| 300 | |
| 301 | /* Point METHODCALL/NAME to the METHOD Node */ |
| 302 | |
| 303 | name_op->common.node = node; |
| 304 | acpi_ps_append_arg(arg, name_op); |
| 305 | |
| 306 | if (!method_desc) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 307 | ACPI_ERROR((AE_INFO, |
| 308 | "Control Method %p has no attached object", |
| 309 | node)); |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 310 | return_ACPI_STATUS(AE_AML_INTERNAL); |
| 311 | } |
| 312 | |
| 313 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, |
| 314 | "Control Method - %p Args %X\n", |
| 315 | node, method_desc->method.param_count)); |
| 316 | |
| 317 | /* Get the number of arguments to expect */ |
| 318 | |
| 319 | walk_state->arg_count = method_desc->method.param_count; |
| 320 | return_ACPI_STATUS(AE_OK); |
| 321 | } |
| 322 | |
| 323 | /* |
| 324 | * Special handling if the name was not found during the lookup - |
| 325 | * some not_found cases are allowed |
| 326 | */ |
| 327 | if (status == AE_NOT_FOUND) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 328 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 329 | /* 1) not_found is ok during load pass 1/2 (allow forward references) */ |
| 330 | |
| 331 | if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) != |
| 332 | ACPI_PARSE_EXECUTE) { |
| 333 | status = AE_OK; |
| 334 | } |
| 335 | |
| 336 | /* 2) not_found during a cond_ref_of(x) is ok by definition */ |
| 337 | |
| 338 | else if (walk_state->op->common.aml_opcode == |
| 339 | AML_COND_REF_OF_OP) { |
| 340 | status = AE_OK; |
| 341 | } |
| 342 | |
| 343 | /* |
| 344 | * 3) not_found while building a Package is ok at this point, we |
| 345 | * may flag as an error later if slack mode is not enabled. |
| 346 | * (Some ASL code depends on allowing this behavior) |
| 347 | */ |
| 348 | else if ((arg->common.parent) && |
| 349 | ((arg->common.parent->common.aml_opcode == |
| 350 | AML_PACKAGE_OP) |
| 351 | || (arg->common.parent->common.aml_opcode == |
| 352 | AML_VAR_PACKAGE_OP))) { |
| 353 | status = AE_OK; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | /* Final exception check (may have been changed from code above) */ |
| 358 | |
| 359 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 360 | ACPI_ERROR_NAMESPACE(path, status); |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 361 | |
| 362 | if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) == |
| 363 | ACPI_PARSE_EXECUTE) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 364 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 365 | /* Report a control method execution error */ |
| 366 | |
| 367 | status = acpi_ds_method_error(status, walk_state); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | /* Save the namepath */ |
| 372 | |
| 373 | arg->common.value.name = path; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 374 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | /******************************************************************************* |
| 378 | * |
| 379 | * FUNCTION: acpi_ps_get_next_simple_arg |
| 380 | * |
| 381 | * PARAMETERS: parser_state - Current parser state object |
| 382 | * arg_type - The argument type (AML_*_ARG) |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 383 | * arg - Where the argument is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | * |
| 385 | * RETURN: None |
| 386 | * |
| 387 | * DESCRIPTION: Get the next simple argument (constant, string, or namestring) |
| 388 | * |
| 389 | ******************************************************************************/ |
| 390 | |
| 391 | void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 392 | acpi_ps_get_next_simple_arg(struct acpi_parse_state *parser_state, |
| 393 | u32 arg_type, union acpi_parse_object *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | { |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 395 | u32 length; |
| 396 | u16 opcode; |
| 397 | u8 *aml = parser_state->aml; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 399 | ACPI_FUNCTION_TRACE_U32(ps_get_next_simple_arg, arg_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
| 401 | switch (arg_type) { |
| 402 | case ARGP_BYTEDATA: |
| 403 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 404 | /* Get 1 byte from the AML stream */ |
| 405 | |
| 406 | opcode = AML_BYTE_OP; |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 407 | arg->common.value.integer = (u64) *aml; |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 408 | length = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | break; |
| 410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | case ARGP_WORDDATA: |
| 412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | /* Get 2 bytes from the AML stream */ |
| 414 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 415 | opcode = AML_WORD_OP; |
| 416 | ACPI_MOVE_16_TO_64(&arg->common.value.integer, aml); |
| 417 | length = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | break; |
| 419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | case ARGP_DWORDDATA: |
| 421 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | /* Get 4 bytes from the AML stream */ |
| 423 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 424 | opcode = AML_DWORD_OP; |
| 425 | ACPI_MOVE_32_TO_64(&arg->common.value.integer, aml); |
| 426 | length = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | break; |
| 428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | case ARGP_QWORDDATA: |
| 430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | /* Get 8 bytes from the AML stream */ |
| 432 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 433 | opcode = AML_QWORD_OP; |
| 434 | ACPI_MOVE_64_TO_64(&arg->common.value.integer, aml); |
| 435 | length = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | break; |
| 437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | case ARGP_CHARLIST: |
| 439 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 440 | /* Get a pointer to the string, point past the string */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 442 | opcode = AML_STRING_OP; |
| 443 | arg->common.value.string = ACPI_CAST_PTR(char, aml); |
| 444 | |
| 445 | /* Find the null terminator */ |
| 446 | |
| 447 | length = 0; |
| 448 | while (aml[length]) { |
| 449 | length++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | } |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 451 | length++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | break; |
| 453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | case ARGP_NAME: |
| 455 | case ARGP_NAMESTRING: |
| 456 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 457 | acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP); |
| 458 | arg->common.value.name = |
| 459 | acpi_ps_get_next_namestring(parser_state); |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 460 | return_VOID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | default: |
| 463 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 464 | ACPI_ERROR((AE_INFO, "Invalid ArgType 0x%X", arg_type)); |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 465 | return_VOID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 468 | acpi_ps_init_op(arg, opcode); |
| 469 | parser_state->aml += length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | return_VOID; |
| 471 | } |
| 472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | /******************************************************************************* |
| 474 | * |
| 475 | * FUNCTION: acpi_ps_get_next_field |
| 476 | * |
| 477 | * PARAMETERS: parser_state - Current parser state object |
| 478 | * |
| 479 | * RETURN: A newly allocated FIELD op |
| 480 | * |
| 481 | * DESCRIPTION: Get next field (named_field, reserved_field, or access_field) |
| 482 | * |
| 483 | ******************************************************************************/ |
| 484 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 485 | static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state |
| 486 | *parser_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | { |
Lv Zheng | 950a429 | 2015-07-23 12:52:18 +0800 | [diff] [blame] | 488 | u8 *aml; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 489 | union acpi_parse_object *field; |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 490 | union acpi_parse_object *arg = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 491 | u16 opcode; |
| 492 | u32 name; |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 493 | u8 access_type; |
| 494 | u8 access_attribute; |
| 495 | u8 access_length; |
| 496 | u32 pkg_length; |
| 497 | u8 *pkg_end; |
| 498 | u32 buffer_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 500 | ACPI_FUNCTION_TRACE(ps_get_next_field); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
Lv Zheng | 950a429 | 2015-07-23 12:52:18 +0800 | [diff] [blame] | 502 | aml = parser_state->aml; |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 503 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 504 | /* Determine field type */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 506 | switch (ACPI_GET8(parser_state->aml)) { |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 507 | case AML_FIELD_OFFSET_OP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
| 509 | opcode = AML_INT_RESERVEDFIELD_OP; |
| 510 | parser_state->aml++; |
| 511 | break; |
| 512 | |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 513 | case AML_FIELD_ACCESS_OP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
| 515 | opcode = AML_INT_ACCESSFIELD_OP; |
| 516 | parser_state->aml++; |
| 517 | break; |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 518 | |
| 519 | case AML_FIELD_CONNECTION_OP: |
| 520 | |
| 521 | opcode = AML_INT_CONNECTION_OP; |
| 522 | parser_state->aml++; |
| 523 | break; |
| 524 | |
| 525 | case AML_FIELD_EXT_ACCESS_OP: |
| 526 | |
| 527 | opcode = AML_INT_EXTACCESSFIELD_OP; |
| 528 | parser_state->aml++; |
| 529 | break; |
| 530 | |
| 531 | default: |
| 532 | |
| 533 | opcode = AML_INT_NAMEDFIELD_OP; |
| 534 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | /* Allocate a new field op */ |
| 538 | |
Lv Zheng | 62eb935 | 2015-07-23 12:52:24 +0800 | [diff] [blame] | 539 | field = acpi_ps_alloc_op(opcode, aml); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | if (!field) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 541 | return_PTR(NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | /* Decode the field type */ |
| 545 | |
| 546 | switch (opcode) { |
| 547 | case AML_INT_NAMEDFIELD_OP: |
| 548 | |
| 549 | /* Get the 4-character name */ |
| 550 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 551 | ACPI_MOVE_32_TO_32(&name, parser_state->aml); |
| 552 | acpi_ps_set_name(field, name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | parser_state->aml += ACPI_NAME_SIZE; |
| 554 | |
| 555 | /* Get the length which is encoded as a package length */ |
| 556 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 557 | field->common.value.size = |
| 558 | acpi_ps_get_next_package_length(parser_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | break; |
| 560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | case AML_INT_RESERVEDFIELD_OP: |
| 562 | |
| 563 | /* Get the length which is encoded as a package length */ |
| 564 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 565 | field->common.value.size = |
| 566 | acpi_ps_get_next_package_length(parser_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | break; |
| 568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | case AML_INT_ACCESSFIELD_OP: |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 570 | case AML_INT_EXTACCESSFIELD_OP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
| 572 | /* |
| 573 | * Get access_type and access_attrib and merge into the field Op |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 574 | * access_type is first operand, access_attribute is second. stuff |
| 575 | * these bytes into the node integer value for convenience. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | */ |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 577 | |
| 578 | /* Get the two bytes (Type/Attribute) */ |
| 579 | |
| 580 | access_type = ACPI_GET8(parser_state->aml); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | parser_state->aml++; |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 582 | access_attribute = ACPI_GET8(parser_state->aml); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | parser_state->aml++; |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 584 | |
| 585 | field->common.value.integer = (u8)access_type; |
| 586 | field->common.value.integer |= (u16)(access_attribute << 8); |
| 587 | |
| 588 | /* This opcode has a third byte, access_length */ |
| 589 | |
| 590 | if (opcode == AML_INT_EXTACCESSFIELD_OP) { |
| 591 | access_length = ACPI_GET8(parser_state->aml); |
| 592 | parser_state->aml++; |
| 593 | |
| 594 | field->common.value.integer |= |
| 595 | (u32)(access_length << 16); |
| 596 | } |
| 597 | break; |
| 598 | |
| 599 | case AML_INT_CONNECTION_OP: |
| 600 | |
| 601 | /* |
| 602 | * Argument for Connection operator can be either a Buffer |
| 603 | * (resource descriptor), or a name_string. |
| 604 | */ |
Lv Zheng | 62eb935 | 2015-07-23 12:52:24 +0800 | [diff] [blame] | 605 | aml = parser_state->aml; |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 606 | if (ACPI_GET8(parser_state->aml) == AML_BUFFER_OP) { |
| 607 | parser_state->aml++; |
| 608 | |
| 609 | pkg_end = parser_state->aml; |
| 610 | pkg_length = |
| 611 | acpi_ps_get_next_package_length(parser_state); |
| 612 | pkg_end += pkg_length; |
| 613 | |
| 614 | if (parser_state->aml < pkg_end) { |
| 615 | |
| 616 | /* Non-empty list */ |
| 617 | |
Lv Zheng | 62eb935 | 2015-07-23 12:52:24 +0800 | [diff] [blame] | 618 | arg = |
| 619 | acpi_ps_alloc_op(AML_INT_BYTELIST_OP, aml); |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 620 | if (!arg) { |
Jesper Juhl | 6af1c4f | 2012-05-03 09:38:10 +0800 | [diff] [blame] | 621 | acpi_ps_free_op(field); |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 622 | return_PTR(NULL); |
| 623 | } |
| 624 | |
| 625 | /* Get the actual buffer length argument */ |
| 626 | |
| 627 | opcode = ACPI_GET8(parser_state->aml); |
| 628 | parser_state->aml++; |
| 629 | |
| 630 | switch (opcode) { |
| 631 | case AML_BYTE_OP: /* AML_BYTEDATA_ARG */ |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 632 | |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 633 | buffer_length = |
| 634 | ACPI_GET8(parser_state->aml); |
| 635 | parser_state->aml += 1; |
| 636 | break; |
| 637 | |
| 638 | case AML_WORD_OP: /* AML_WORDDATA_ARG */ |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 639 | |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 640 | buffer_length = |
| 641 | ACPI_GET16(parser_state->aml); |
| 642 | parser_state->aml += 2; |
| 643 | break; |
| 644 | |
| 645 | case AML_DWORD_OP: /* AML_DWORDATA_ARG */ |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 646 | |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 647 | buffer_length = |
| 648 | ACPI_GET32(parser_state->aml); |
| 649 | parser_state->aml += 4; |
| 650 | break; |
| 651 | |
| 652 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 653 | |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 654 | buffer_length = 0; |
| 655 | break; |
| 656 | } |
| 657 | |
| 658 | /* Fill in bytelist data */ |
| 659 | |
| 660 | arg->named.value.size = buffer_length; |
| 661 | arg->named.data = parser_state->aml; |
| 662 | } |
| 663 | |
| 664 | /* Skip to End of byte data */ |
| 665 | |
| 666 | parser_state->aml = pkg_end; |
| 667 | } else { |
Lv Zheng | 62eb935 | 2015-07-23 12:52:24 +0800 | [diff] [blame] | 668 | arg = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, aml); |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 669 | if (!arg) { |
Jesper Juhl | 6af1c4f | 2012-05-03 09:38:10 +0800 | [diff] [blame] | 670 | acpi_ps_free_op(field); |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 671 | return_PTR(NULL); |
| 672 | } |
| 673 | |
| 674 | /* Get the Namestring argument */ |
| 675 | |
| 676 | arg->common.value.name = |
| 677 | acpi_ps_get_next_namestring(parser_state); |
| 678 | } |
| 679 | |
| 680 | /* Link the buffer/namestring to parent (CONNECTION_OP) */ |
| 681 | |
| 682 | acpi_ps_append_arg(field, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | break; |
| 684 | |
| 685 | default: |
| 686 | |
| 687 | /* Opcode was set in previous switch */ |
| 688 | break; |
| 689 | } |
| 690 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 691 | return_PTR(field); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | /******************************************************************************* |
| 695 | * |
| 696 | * FUNCTION: acpi_ps_get_next_arg |
| 697 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 698 | * PARAMETERS: walk_state - Current state |
| 699 | * parser_state - Current parser state object |
Bob Moore | ae90fbf | 2015-12-29 14:00:14 +0800 | [diff] [blame] | 700 | * arg_type - The parser argument type (ARGP_*) |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 701 | * return_arg - Where the next arg is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | * |
| 703 | * RETURN: Status, and an op object containing the next argument. |
| 704 | * |
| 705 | * DESCRIPTION: Get next argument (including complex list arguments that require |
| 706 | * pushing the parser stack) |
| 707 | * |
| 708 | ******************************************************************************/ |
| 709 | |
| 710 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 711 | acpi_ps_get_next_arg(struct acpi_walk_state *walk_state, |
| 712 | struct acpi_parse_state *parser_state, |
| 713 | u32 arg_type, union acpi_parse_object **return_arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 715 | union acpi_parse_object *arg = NULL; |
| 716 | union acpi_parse_object *prev = NULL; |
| 717 | union acpi_parse_object *field; |
| 718 | u32 subop; |
| 719 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 721 | ACPI_FUNCTION_TRACE_PTR(ps_get_next_arg, parser_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
| 723 | switch (arg_type) { |
| 724 | case ARGP_BYTEDATA: |
| 725 | case ARGP_WORDDATA: |
| 726 | case ARGP_DWORDDATA: |
| 727 | case ARGP_CHARLIST: |
| 728 | case ARGP_NAME: |
| 729 | case ARGP_NAMESTRING: |
| 730 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 731 | /* Constants, strings, and namestrings are all the same size */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
Lv Zheng | 62eb935 | 2015-07-23 12:52:24 +0800 | [diff] [blame] | 733 | arg = acpi_ps_alloc_op(AML_BYTE_OP, parser_state->aml); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | if (!arg) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 735 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | } |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 737 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 738 | acpi_ps_get_next_simple_arg(parser_state, arg_type, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | break; |
| 740 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | case ARGP_PKGLENGTH: |
| 742 | |
| 743 | /* Package length, nothing returned */ |
| 744 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 745 | parser_state->pkg_end = |
| 746 | acpi_ps_get_next_package_end(parser_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | break; |
| 748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | case ARGP_FIELDLIST: |
| 750 | |
| 751 | if (parser_state->aml < parser_state->pkg_end) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 752 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | /* Non-empty list */ |
| 754 | |
| 755 | while (parser_state->aml < parser_state->pkg_end) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 756 | field = acpi_ps_get_next_field(parser_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | if (!field) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 758 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | if (prev) { |
| 762 | prev->common.next = field; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 763 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | arg = field; |
| 765 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | prev = field; |
| 767 | } |
| 768 | |
| 769 | /* Skip to End of byte data */ |
| 770 | |
| 771 | parser_state->aml = parser_state->pkg_end; |
| 772 | } |
| 773 | break; |
| 774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | case ARGP_BYTELIST: |
| 776 | |
| 777 | if (parser_state->aml < parser_state->pkg_end) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 778 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | /* Non-empty list */ |
| 780 | |
Lv Zheng | 62eb935 | 2015-07-23 12:52:24 +0800 | [diff] [blame] | 781 | arg = acpi_ps_alloc_op(AML_INT_BYTELIST_OP, |
| 782 | parser_state->aml); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | if (!arg) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 784 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | /* Fill in bytelist data */ |
| 788 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 789 | arg->common.value.size = (u32) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 790 | ACPI_PTR_DIFF(parser_state->pkg_end, |
| 791 | parser_state->aml); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | arg->named.data = parser_state->aml; |
| 793 | |
| 794 | /* Skip to End of byte data */ |
| 795 | |
| 796 | parser_state->aml = parser_state->pkg_end; |
| 797 | } |
| 798 | break; |
| 799 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | case ARGP_TARGET: |
| 801 | case ARGP_SUPERNAME: |
| 802 | case ARGP_SIMPLENAME: |
Bob Moore | cca7a6e | 2015-12-29 14:00:21 +0800 | [diff] [blame] | 803 | case ARGP_NAME_OR_REF: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 805 | subop = acpi_ps_peek_opcode(parser_state); |
| 806 | if (subop == 0 || |
| 807 | acpi_ps_is_leading_char(subop) || |
Bob Moore | 04a81dc | 2012-12-31 00:05:17 +0000 | [diff] [blame] | 808 | ACPI_IS_ROOT_PREFIX(subop) || |
| 809 | ACPI_IS_PARENT_PREFIX(subop)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | /* null_name or name_string */ |
| 812 | |
Lv Zheng | 62eb935 | 2015-07-23 12:52:24 +0800 | [diff] [blame] | 813 | arg = |
| 814 | acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, |
| 815 | parser_state->aml); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | if (!arg) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 817 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | } |
| 819 | |
Bob Moore | ae90fbf | 2015-12-29 14:00:14 +0800 | [diff] [blame] | 820 | /* super_name allows argument to be a method call */ |
Lin Ming | bc7a36a | 2008-04-10 19:06:42 +0400 | [diff] [blame] | 821 | |
Bob Moore | ae90fbf | 2015-12-29 14:00:14 +0800 | [diff] [blame] | 822 | if (arg_type == ARGP_SUPERNAME) { |
Lin Ming | bc7a36a | 2008-04-10 19:06:42 +0400 | [diff] [blame] | 823 | status = |
| 824 | acpi_ps_get_next_namepath(walk_state, |
| 825 | parser_state, arg, |
Bob Moore | 89438f9 | 2015-12-29 14:00:07 +0800 | [diff] [blame] | 826 | ACPI_POSSIBLE_METHOD_CALL); |
Lin Ming | bc7a36a | 2008-04-10 19:06:42 +0400 | [diff] [blame] | 827 | |
| 828 | /* |
Bob Moore | cca7a6e | 2015-12-29 14:00:21 +0800 | [diff] [blame] | 829 | * If the super_name argument is a method call, we have |
| 830 | * already restored the AML pointer, just free this Arg |
Lin Ming | bc7a36a | 2008-04-10 19:06:42 +0400 | [diff] [blame] | 831 | */ |
| 832 | if (arg->common.aml_opcode == |
| 833 | AML_INT_METHODCALL_OP) { |
| 834 | acpi_ps_free_op(arg); |
| 835 | arg = NULL; |
| 836 | } |
| 837 | } else { |
| 838 | status = |
| 839 | acpi_ps_get_next_namepath(walk_state, |
| 840 | parser_state, arg, |
Bob Moore | 89438f9 | 2015-12-29 14:00:07 +0800 | [diff] [blame] | 841 | ACPI_NOT_METHOD_CALL); |
Lin Ming | bc7a36a | 2008-04-10 19:06:42 +0400 | [diff] [blame] | 842 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 843 | } else { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 844 | /* Single complex argument, nothing returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | |
| 846 | walk_state->arg_count = 1; |
| 847 | } |
| 848 | break; |
| 849 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | case ARGP_DATAOBJ: |
| 851 | case ARGP_TERMARG: |
| 852 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 853 | /* Single complex argument, nothing returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | |
| 855 | walk_state->arg_count = 1; |
| 856 | break; |
| 857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | case ARGP_DATAOBJLIST: |
| 859 | case ARGP_TERMLIST: |
| 860 | case ARGP_OBJLIST: |
| 861 | |
| 862 | if (parser_state->aml < parser_state->pkg_end) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 863 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 864 | /* Non-empty list of variable arguments, nothing returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
| 866 | walk_state->arg_count = ACPI_VAR_ARGS; |
| 867 | } |
| 868 | break; |
| 869 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | default: |
| 871 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 872 | ACPI_ERROR((AE_INFO, "Invalid ArgType: 0x%X", arg_type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | status = AE_AML_OPERAND_TYPE; |
| 874 | break; |
| 875 | } |
| 876 | |
| 877 | *return_arg = arg; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 878 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | } |