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