]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: psargs - Parse AML opcode arguments | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
8 | * Copyright (C) 2000 - 2005, R. Byron Moore | |
9 | * All rights reserved. | |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | |
15 | * notice, this list of conditions, and the following disclaimer, | |
16 | * without modification. | |
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | |
18 | * substantially similar to the "NO WARRANTY" disclaimer below | |
19 | * ("Disclaimer") and any redistribution must be conditioned upon | |
20 | * including a substantially similar Disclaimer requirement for further | |
21 | * binary redistribution. | |
22 | * 3. Neither the names of the above-listed copyright holders nor the names | |
23 | * of any contributors may be used to endorse or promote products derived | |
24 | * from this software without specific prior written permission. | |
25 | * | |
26 | * Alternatively, this software may be distributed under the terms of the | |
27 | * GNU General Public License ("GPL") version 2 as published by the Free | |
28 | * Software Foundation. | |
29 | * | |
30 | * NO WARRANTY | |
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | |
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
41 | * POSSIBILITY OF SUCH DAMAGES. | |
42 | */ | |
43 | ||
1da177e4 LT |
44 | #include <acpi/acpi.h> |
45 | #include <acpi/acparser.h> | |
46 | #include <acpi/amlcode.h> | |
47 | #include <acpi/acnamesp.h> | |
48 | ||
49 | #define _COMPONENT ACPI_PARSER | |
4be44fcd | 50 | ACPI_MODULE_NAME("psargs") |
1da177e4 | 51 | |
44f6c012 | 52 | /* Local prototypes */ |
44f6c012 | 53 | static u32 |
4be44fcd | 54 | acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state); |
44f6c012 | 55 | |
4be44fcd LB |
56 | static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state |
57 | *parser_state); | |
1da177e4 LT |
58 | |
59 | /******************************************************************************* | |
60 | * | |
61 | * FUNCTION: acpi_ps_get_next_package_length | |
62 | * | |
63 | * PARAMETERS: parser_state - Current parser state object | |
64 | * | |
c51a4de8 | 65 | * RETURN: Decoded package length. On completion, the AML pointer points |
1da177e4 LT |
66 | * past the length byte or bytes. |
67 | * | |
c51a4de8 BM |
68 | * DESCRIPTION: Decode and return a package length field. |
69 | * Note: Largest package length is 28 bits, from ACPI specification | |
1da177e4 LT |
70 | * |
71 | ******************************************************************************/ | |
72 | ||
44f6c012 | 73 | static u32 |
4be44fcd | 74 | acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state) |
1da177e4 | 75 | { |
c51a4de8 BM |
76 | u8 *aml = parser_state->aml; |
77 | u32 package_length = 0; | |
78 | acpi_native_uint byte_count; | |
79 | u8 byte_zero_mask = 0x3F; /* Default [0:5] */ | |
1da177e4 | 80 | |
4be44fcd | 81 | ACPI_FUNCTION_TRACE("ps_get_next_package_length"); |
1da177e4 | 82 | |
c51a4de8 BM |
83 | /* |
84 | * Byte 0 bits [6:7] contain the number of additional bytes | |
85 | * used to encode the package length, either 0,1,2, or 3 | |
86 | */ | |
87 | byte_count = (aml[0] >> 6); | |
88 | parser_state->aml += (byte_count + 1); | |
1da177e4 | 89 | |
c51a4de8 | 90 | /* Get bytes 3, 2, 1 as needed */ |
1da177e4 | 91 | |
c51a4de8 BM |
92 | while (byte_count) { |
93 | /* | |
94 | * Final bit positions for the package length bytes: | |
95 | * Byte3->[20:27] | |
96 | * Byte2->[12:19] | |
97 | * Byte1->[04:11] | |
98 | * Byte0->[00:03] | |
99 | */ | |
100 | package_length |= (aml[byte_count] << ((byte_count << 3) - 4)); | |
1da177e4 | 101 | |
c51a4de8 BM |
102 | byte_zero_mask = 0x0F; /* Use bits [0:3] of byte 0 */ |
103 | byte_count--; | |
1da177e4 LT |
104 | } |
105 | ||
c51a4de8 BM |
106 | /* Byte 0 is a special case, either bits [0:3] or [0:5] are used */ |
107 | ||
108 | package_length |= (aml[0] & byte_zero_mask); | |
109 | return_UINT32(package_length); | |
1da177e4 LT |
110 | } |
111 | ||
1da177e4 LT |
112 | /******************************************************************************* |
113 | * | |
114 | * FUNCTION: acpi_ps_get_next_package_end | |
115 | * | |
116 | * PARAMETERS: parser_state - Current parser state object | |
117 | * | |
118 | * RETURN: Pointer to end-of-package +1 | |
119 | * | |
120 | * DESCRIPTION: Get next package length and return a pointer past the end of | |
121 | * the package. Consumes the package length field | |
122 | * | |
123 | ******************************************************************************/ | |
124 | ||
4be44fcd | 125 | u8 *acpi_ps_get_next_package_end(struct acpi_parse_state *parser_state) |
1da177e4 | 126 | { |
4be44fcd | 127 | u8 *start = parser_state->aml; |
c51a4de8 | 128 | u32 package_length; |
1da177e4 | 129 | |
4be44fcd | 130 | ACPI_FUNCTION_TRACE("ps_get_next_package_end"); |
1da177e4 | 131 | |
c51a4de8 | 132 | /* Function below updates parser_state->Aml */ |
1da177e4 | 133 | |
c51a4de8 | 134 | package_length = acpi_ps_get_next_package_length(parser_state); |
1da177e4 | 135 | |
c51a4de8 | 136 | return_PTR(start + package_length); /* end of package */ |
1da177e4 LT |
137 | } |
138 | ||
1da177e4 LT |
139 | /******************************************************************************* |
140 | * | |
141 | * FUNCTION: acpi_ps_get_next_namestring | |
142 | * | |
143 | * PARAMETERS: parser_state - Current parser state object | |
144 | * | |
145 | * RETURN: Pointer to the start of the name string (pointer points into | |
146 | * the AML. | |
147 | * | |
148 | * DESCRIPTION: Get next raw namestring within the AML stream. Handles all name | |
149 | * prefix characters. Set parser state to point past the string. | |
150 | * (Name is consumed from the AML.) | |
151 | * | |
152 | ******************************************************************************/ | |
153 | ||
4be44fcd | 154 | char *acpi_ps_get_next_namestring(struct acpi_parse_state *parser_state) |
1da177e4 | 155 | { |
4be44fcd LB |
156 | u8 *start = parser_state->aml; |
157 | u8 *end = parser_state->aml; | |
1da177e4 | 158 | |
4be44fcd | 159 | ACPI_FUNCTION_TRACE("ps_get_next_namestring"); |
1da177e4 | 160 | |
c51a4de8 | 161 | /* Point past any namestring prefix characters (backslash or carat) */ |
1da177e4 | 162 | |
c51a4de8 | 163 | while (acpi_ps_is_prefix_char(*end)) { |
1da177e4 LT |
164 | end++; |
165 | } | |
166 | ||
c51a4de8 | 167 | /* Decode the path prefix character */ |
1da177e4 | 168 | |
c51a4de8 | 169 | switch (*end) { |
1da177e4 LT |
170 | case 0: |
171 | ||
172 | /* null_name */ | |
173 | ||
174 | if (end == start) { | |
175 | start = NULL; | |
176 | } | |
177 | end++; | |
178 | break; | |
179 | ||
180 | case AML_DUAL_NAME_PREFIX: | |
181 | ||
182 | /* Two name segments */ | |
183 | ||
184 | end += 1 + (2 * ACPI_NAME_SIZE); | |
185 | break; | |
186 | ||
187 | case AML_MULTI_NAME_PREFIX_OP: | |
188 | ||
c51a4de8 | 189 | /* Multiple name segments, 4 chars each, count in next byte */ |
1da177e4 | 190 | |
c51a4de8 | 191 | end += 2 + (*(end + 1) * ACPI_NAME_SIZE); |
1da177e4 LT |
192 | break; |
193 | ||
194 | default: | |
195 | ||
196 | /* Single name segment */ | |
197 | ||
198 | end += ACPI_NAME_SIZE; | |
199 | break; | |
200 | } | |
201 | ||
c51a4de8 | 202 | parser_state->aml = end; |
4be44fcd | 203 | return_PTR((char *)start); |
1da177e4 LT |
204 | } |
205 | ||
1da177e4 LT |
206 | /******************************************************************************* |
207 | * | |
208 | * FUNCTION: acpi_ps_get_next_namepath | |
209 | * | |
210 | * PARAMETERS: parser_state - Current parser state object | |
211 | * Arg - Where the namepath will be stored | |
212 | * arg_count - If the namepath points to a control method | |
213 | * the method's argument is returned here. | |
214 | * method_call - Whether the namepath can possibly be the | |
215 | * start of a method call | |
216 | * | |
217 | * RETURN: Status | |
218 | * | |
219 | * DESCRIPTION: Get next name (if method call, return # of required args). | |
220 | * Names are looked up in the internal namespace to determine | |
221 | * if the name represents a control method. If a method | |
222 | * is found, the number of arguments to the method is returned. | |
223 | * This information is critical for parsing to continue correctly. | |
224 | * | |
225 | ******************************************************************************/ | |
226 | ||
227 | acpi_status | |
4be44fcd LB |
228 | acpi_ps_get_next_namepath(struct acpi_walk_state *walk_state, |
229 | struct acpi_parse_state *parser_state, | |
230 | union acpi_parse_object *arg, u8 method_call) | |
1da177e4 | 231 | { |
4be44fcd LB |
232 | char *path; |
233 | union acpi_parse_object *name_op; | |
234 | acpi_status status = AE_OK; | |
235 | union acpi_operand_object *method_desc; | |
236 | struct acpi_namespace_node *node; | |
237 | union acpi_generic_state scope_info; | |
1da177e4 | 238 | |
4be44fcd | 239 | ACPI_FUNCTION_TRACE("ps_get_next_namepath"); |
1da177e4 | 240 | |
4be44fcd | 241 | path = acpi_ps_get_next_namestring(parser_state); |
1da177e4 LT |
242 | |
243 | /* Null path case is allowed */ | |
244 | ||
245 | if (path) { | |
246 | /* | |
247 | * Lookup the name in the internal namespace | |
248 | */ | |
249 | scope_info.scope.node = NULL; | |
250 | node = parser_state->start_node; | |
251 | if (node) { | |
252 | scope_info.scope.node = node; | |
253 | } | |
254 | ||
255 | /* | |
256 | * Lookup object. We don't want to add anything new to the namespace | |
257 | * here, however. So we use MODE_EXECUTE. Allow searching of the | |
258 | * parent tree, but don't open a new scope -- we just want to lookup the | |
259 | * object (MUST BE mode EXECUTE to perform upsearch) | |
260 | */ | |
4be44fcd LB |
261 | status = acpi_ns_lookup(&scope_info, path, ACPI_TYPE_ANY, |
262 | ACPI_IMODE_EXECUTE, | |
263 | ACPI_NS_SEARCH_PARENT | | |
264 | ACPI_NS_DONT_OPEN_SCOPE, NULL, &node); | |
265 | if (ACPI_SUCCESS(status) && method_call) { | |
1da177e4 | 266 | if (node->type == ACPI_TYPE_METHOD) { |
44f6c012 RM |
267 | /* This name is actually a control method invocation */ |
268 | ||
4be44fcd LB |
269 | method_desc = acpi_ns_get_attached_object(node); |
270 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, | |
271 | "Control Method - %p Desc %p Path=%p\n", | |
272 | node, method_desc, path)); | |
1da177e4 | 273 | |
4be44fcd | 274 | name_op = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP); |
1da177e4 | 275 | if (!name_op) { |
4be44fcd | 276 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
277 | } |
278 | ||
279 | /* Change arg into a METHOD CALL and attach name to it */ | |
280 | ||
4be44fcd | 281 | acpi_ps_init_op(arg, AML_INT_METHODCALL_OP); |
1da177e4 LT |
282 | name_op->common.value.name = path; |
283 | ||
284 | /* Point METHODCALL/NAME to the METHOD Node */ | |
285 | ||
286 | name_op->common.node = node; | |
4be44fcd | 287 | acpi_ps_append_arg(arg, name_op); |
1da177e4 LT |
288 | |
289 | if (!method_desc) { | |
4be44fcd LB |
290 | ACPI_REPORT_ERROR(("ps_get_next_namepath: Control Method %p has no attached object\n", node)); |
291 | return_ACPI_STATUS(AE_AML_INTERNAL); | |
1da177e4 LT |
292 | } |
293 | ||
4be44fcd LB |
294 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, |
295 | "Control Method - %p Args %X\n", | |
296 | node, | |
297 | method_desc->method. | |
298 | param_count)); | |
1da177e4 LT |
299 | |
300 | /* Get the number of arguments to expect */ | |
301 | ||
4be44fcd LB |
302 | walk_state->arg_count = |
303 | method_desc->method.param_count; | |
304 | return_ACPI_STATUS(AE_OK); | |
1da177e4 LT |
305 | } |
306 | ||
307 | /* | |
308 | * Else this is normal named object reference. | |
309 | * Just init the NAMEPATH object with the pathname. | |
310 | * (See code below) | |
311 | */ | |
312 | } | |
313 | ||
4be44fcd | 314 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
315 | /* |
316 | * 1) Any error other than NOT_FOUND is always severe | |
317 | * 2) NOT_FOUND is only important if we are executing a method. | |
318 | * 3) If executing a cond_ref_of opcode, NOT_FOUND is ok. | |
319 | */ | |
4be44fcd LB |
320 | if ((((walk_state-> |
321 | parse_flags & ACPI_PARSE_MODE_MASK) == | |
322 | ACPI_PARSE_EXECUTE) && (status == AE_NOT_FOUND) | |
323 | && (walk_state->op->common.aml_opcode != | |
324 | AML_COND_REF_OF_OP)) | |
325 | || (status != AE_NOT_FOUND)) { | |
326 | ACPI_REPORT_NSERROR(path, status); | |
327 | ||
328 | acpi_os_printf | |
329 | ("search_node %p start_node %p return_node %p\n", | |
330 | scope_info.scope.node, | |
331 | parser_state->start_node, node); | |
4be44fcd | 332 | } else { |
1da177e4 LT |
333 | /* |
334 | * We got a NOT_FOUND during table load or we encountered | |
335 | * a cond_ref_of(x) where the target does not exist. | |
44f6c012 | 336 | * Either case is ok |
1da177e4 LT |
337 | */ |
338 | status = AE_OK; | |
339 | } | |
340 | } | |
341 | } | |
342 | ||
343 | /* | |
344 | * Regardless of success/failure above, | |
345 | * Just initialize the Op with the pathname. | |
346 | */ | |
4be44fcd | 347 | acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP); |
1da177e4 LT |
348 | arg->common.value.name = path; |
349 | ||
4be44fcd | 350 | return_ACPI_STATUS(status); |
1da177e4 LT |
351 | } |
352 | ||
1da177e4 LT |
353 | /******************************************************************************* |
354 | * | |
355 | * FUNCTION: acpi_ps_get_next_simple_arg | |
356 | * | |
357 | * PARAMETERS: parser_state - Current parser state object | |
358 | * arg_type - The argument type (AML_*_ARG) | |
359 | * Arg - Where the argument is returned | |
360 | * | |
361 | * RETURN: None | |
362 | * | |
363 | * DESCRIPTION: Get the next simple argument (constant, string, or namestring) | |
364 | * | |
365 | ******************************************************************************/ | |
366 | ||
367 | void | |
4be44fcd LB |
368 | acpi_ps_get_next_simple_arg(struct acpi_parse_state *parser_state, |
369 | u32 arg_type, union acpi_parse_object *arg) | |
1da177e4 | 370 | { |
c51a4de8 BM |
371 | u32 length; |
372 | u16 opcode; | |
373 | u8 *aml = parser_state->aml; | |
1da177e4 | 374 | |
4be44fcd | 375 | ACPI_FUNCTION_TRACE_U32("ps_get_next_simple_arg", arg_type); |
1da177e4 LT |
376 | |
377 | switch (arg_type) { | |
378 | case ARGP_BYTEDATA: | |
379 | ||
c51a4de8 BM |
380 | /* Get 1 byte from the AML stream */ |
381 | ||
382 | opcode = AML_BYTE_OP; | |
383 | arg->common.value.integer = (acpi_integer) * aml; | |
384 | length = 1; | |
1da177e4 LT |
385 | break; |
386 | ||
1da177e4 LT |
387 | case ARGP_WORDDATA: |
388 | ||
1da177e4 LT |
389 | /* Get 2 bytes from the AML stream */ |
390 | ||
c51a4de8 BM |
391 | opcode = AML_WORD_OP; |
392 | ACPI_MOVE_16_TO_64(&arg->common.value.integer, aml); | |
393 | length = 2; | |
1da177e4 LT |
394 | break; |
395 | ||
1da177e4 LT |
396 | case ARGP_DWORDDATA: |
397 | ||
1da177e4 LT |
398 | /* Get 4 bytes from the AML stream */ |
399 | ||
c51a4de8 BM |
400 | opcode = AML_DWORD_OP; |
401 | ACPI_MOVE_32_TO_64(&arg->common.value.integer, aml); | |
402 | length = 4; | |
1da177e4 LT |
403 | break; |
404 | ||
1da177e4 LT |
405 | case ARGP_QWORDDATA: |
406 | ||
1da177e4 LT |
407 | /* Get 8 bytes from the AML stream */ |
408 | ||
c51a4de8 BM |
409 | opcode = AML_QWORD_OP; |
410 | ACPI_MOVE_64_TO_64(&arg->common.value.integer, aml); | |
411 | length = 8; | |
1da177e4 LT |
412 | break; |
413 | ||
1da177e4 LT |
414 | case ARGP_CHARLIST: |
415 | ||
c51a4de8 BM |
416 | /* Get a pointer to the string, point past the string */ |
417 | ||
418 | opcode = AML_STRING_OP; | |
419 | arg->common.value.string = ACPI_CAST_PTR(char, aml); | |
1da177e4 | 420 | |
c51a4de8 BM |
421 | /* Find the null terminator */ |
422 | ||
423 | length = 0; | |
424 | while (aml[length]) { | |
425 | length++; | |
1da177e4 | 426 | } |
c51a4de8 | 427 | length++; |
1da177e4 LT |
428 | break; |
429 | ||
1da177e4 LT |
430 | case ARGP_NAME: |
431 | case ARGP_NAMESTRING: | |
432 | ||
4be44fcd LB |
433 | acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP); |
434 | arg->common.value.name = | |
435 | acpi_ps_get_next_namestring(parser_state); | |
c51a4de8 | 436 | return_VOID; |
1da177e4 | 437 | |
1da177e4 LT |
438 | default: |
439 | ||
4be44fcd | 440 | ACPI_REPORT_ERROR(("Invalid arg_type %X\n", arg_type)); |
c51a4de8 | 441 | return_VOID; |
1da177e4 LT |
442 | } |
443 | ||
c51a4de8 BM |
444 | acpi_ps_init_op(arg, opcode); |
445 | parser_state->aml += length; | |
1da177e4 LT |
446 | return_VOID; |
447 | } | |
448 | ||
1da177e4 LT |
449 | /******************************************************************************* |
450 | * | |
451 | * FUNCTION: acpi_ps_get_next_field | |
452 | * | |
453 | * PARAMETERS: parser_state - Current parser state object | |
454 | * | |
455 | * RETURN: A newly allocated FIELD op | |
456 | * | |
457 | * DESCRIPTION: Get next field (named_field, reserved_field, or access_field) | |
458 | * | |
459 | ******************************************************************************/ | |
460 | ||
4be44fcd LB |
461 | static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state |
462 | *parser_state) | |
1da177e4 | 463 | { |
4be44fcd LB |
464 | u32 aml_offset = (u32) |
465 | ACPI_PTR_DIFF(parser_state->aml, | |
466 | parser_state->aml_start); | |
467 | union acpi_parse_object *field; | |
468 | u16 opcode; | |
469 | u32 name; | |
1da177e4 | 470 | |
4be44fcd | 471 | ACPI_FUNCTION_TRACE("ps_get_next_field"); |
1da177e4 | 472 | |
44f6c012 | 473 | /* Determine field type */ |
1da177e4 | 474 | |
4be44fcd | 475 | switch (ACPI_GET8(parser_state->aml)) { |
1da177e4 LT |
476 | default: |
477 | ||
478 | opcode = AML_INT_NAMEDFIELD_OP; | |
479 | break; | |
480 | ||
481 | case 0x00: | |
482 | ||
483 | opcode = AML_INT_RESERVEDFIELD_OP; | |
484 | parser_state->aml++; | |
485 | break; | |
486 | ||
487 | case 0x01: | |
488 | ||
489 | opcode = AML_INT_ACCESSFIELD_OP; | |
490 | parser_state->aml++; | |
491 | break; | |
492 | } | |
493 | ||
1da177e4 LT |
494 | /* Allocate a new field op */ |
495 | ||
4be44fcd | 496 | field = acpi_ps_alloc_op(opcode); |
1da177e4 | 497 | if (!field) { |
4be44fcd | 498 | return_PTR(NULL); |
1da177e4 LT |
499 | } |
500 | ||
501 | field->common.aml_offset = aml_offset; | |
502 | ||
503 | /* Decode the field type */ | |
504 | ||
505 | switch (opcode) { | |
506 | case AML_INT_NAMEDFIELD_OP: | |
507 | ||
508 | /* Get the 4-character name */ | |
509 | ||
4be44fcd LB |
510 | ACPI_MOVE_32_TO_32(&name, parser_state->aml); |
511 | acpi_ps_set_name(field, name); | |
1da177e4 LT |
512 | parser_state->aml += ACPI_NAME_SIZE; |
513 | ||
514 | /* Get the length which is encoded as a package length */ | |
515 | ||
4be44fcd LB |
516 | field->common.value.size = |
517 | acpi_ps_get_next_package_length(parser_state); | |
1da177e4 LT |
518 | break; |
519 | ||
1da177e4 LT |
520 | case AML_INT_RESERVEDFIELD_OP: |
521 | ||
522 | /* Get the length which is encoded as a package length */ | |
523 | ||
4be44fcd LB |
524 | field->common.value.size = |
525 | acpi_ps_get_next_package_length(parser_state); | |
1da177e4 LT |
526 | break; |
527 | ||
1da177e4 LT |
528 | case AML_INT_ACCESSFIELD_OP: |
529 | ||
530 | /* | |
531 | * Get access_type and access_attrib and merge into the field Op | |
532 | * access_type is first operand, access_attribute is second | |
533 | */ | |
4be44fcd | 534 | field->common.value.integer = |
c51a4de8 | 535 | (((u32) ACPI_GET8(parser_state->aml) << 8)); |
1da177e4 | 536 | parser_state->aml++; |
4be44fcd | 537 | field->common.value.integer |= ACPI_GET8(parser_state->aml); |
1da177e4 LT |
538 | parser_state->aml++; |
539 | break; | |
540 | ||
541 | default: | |
542 | ||
543 | /* Opcode was set in previous switch */ | |
544 | break; | |
545 | } | |
546 | ||
4be44fcd | 547 | return_PTR(field); |
1da177e4 LT |
548 | } |
549 | ||
1da177e4 LT |
550 | /******************************************************************************* |
551 | * | |
552 | * FUNCTION: acpi_ps_get_next_arg | |
553 | * | |
44f6c012 RM |
554 | * PARAMETERS: walk_state - Current state |
555 | * parser_state - Current parser state object | |
1da177e4 | 556 | * arg_type - The argument type (AML_*_ARG) |
44f6c012 | 557 | * return_arg - Where the next arg is returned |
1da177e4 LT |
558 | * |
559 | * RETURN: Status, and an op object containing the next argument. | |
560 | * | |
561 | * DESCRIPTION: Get next argument (including complex list arguments that require | |
562 | * pushing the parser stack) | |
563 | * | |
564 | ******************************************************************************/ | |
565 | ||
566 | acpi_status | |
4be44fcd LB |
567 | acpi_ps_get_next_arg(struct acpi_walk_state *walk_state, |
568 | struct acpi_parse_state *parser_state, | |
569 | u32 arg_type, union acpi_parse_object **return_arg) | |
1da177e4 | 570 | { |
4be44fcd LB |
571 | union acpi_parse_object *arg = NULL; |
572 | union acpi_parse_object *prev = NULL; | |
573 | union acpi_parse_object *field; | |
574 | u32 subop; | |
575 | acpi_status status = AE_OK; | |
1da177e4 | 576 | |
4be44fcd | 577 | ACPI_FUNCTION_TRACE_PTR("ps_get_next_arg", parser_state); |
1da177e4 LT |
578 | |
579 | switch (arg_type) { | |
580 | case ARGP_BYTEDATA: | |
581 | case ARGP_WORDDATA: | |
582 | case ARGP_DWORDDATA: | |
583 | case ARGP_CHARLIST: | |
584 | case ARGP_NAME: | |
585 | case ARGP_NAMESTRING: | |
586 | ||
44f6c012 | 587 | /* Constants, strings, and namestrings are all the same size */ |
1da177e4 | 588 | |
4be44fcd | 589 | arg = acpi_ps_alloc_op(AML_BYTE_OP); |
1da177e4 | 590 | if (!arg) { |
4be44fcd | 591 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 | 592 | } |
4be44fcd | 593 | acpi_ps_get_next_simple_arg(parser_state, arg_type, arg); |
1da177e4 LT |
594 | break; |
595 | ||
1da177e4 LT |
596 | case ARGP_PKGLENGTH: |
597 | ||
598 | /* Package length, nothing returned */ | |
599 | ||
4be44fcd LB |
600 | parser_state->pkg_end = |
601 | acpi_ps_get_next_package_end(parser_state); | |
1da177e4 LT |
602 | break; |
603 | ||
1da177e4 LT |
604 | case ARGP_FIELDLIST: |
605 | ||
606 | if (parser_state->aml < parser_state->pkg_end) { | |
607 | /* Non-empty list */ | |
608 | ||
609 | while (parser_state->aml < parser_state->pkg_end) { | |
4be44fcd | 610 | field = acpi_ps_get_next_field(parser_state); |
1da177e4 | 611 | if (!field) { |
4be44fcd | 612 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
613 | } |
614 | ||
615 | if (prev) { | |
616 | prev->common.next = field; | |
4be44fcd | 617 | } else { |
1da177e4 LT |
618 | arg = field; |
619 | } | |
1da177e4 LT |
620 | prev = field; |
621 | } | |
622 | ||
623 | /* Skip to End of byte data */ | |
624 | ||
625 | parser_state->aml = parser_state->pkg_end; | |
626 | } | |
627 | break; | |
628 | ||
1da177e4 LT |
629 | case ARGP_BYTELIST: |
630 | ||
631 | if (parser_state->aml < parser_state->pkg_end) { | |
632 | /* Non-empty list */ | |
633 | ||
4be44fcd | 634 | arg = acpi_ps_alloc_op(AML_INT_BYTELIST_OP); |
1da177e4 | 635 | if (!arg) { |
4be44fcd | 636 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
637 | } |
638 | ||
639 | /* Fill in bytelist data */ | |
640 | ||
44f6c012 | 641 | arg->common.value.size = (u32) |
4be44fcd LB |
642 | ACPI_PTR_DIFF(parser_state->pkg_end, |
643 | parser_state->aml); | |
1da177e4 LT |
644 | arg->named.data = parser_state->aml; |
645 | ||
646 | /* Skip to End of byte data */ | |
647 | ||
648 | parser_state->aml = parser_state->pkg_end; | |
649 | } | |
650 | break; | |
651 | ||
1da177e4 LT |
652 | case ARGP_TARGET: |
653 | case ARGP_SUPERNAME: | |
654 | case ARGP_SIMPLENAME: | |
655 | ||
4be44fcd LB |
656 | subop = acpi_ps_peek_opcode(parser_state); |
657 | if (subop == 0 || | |
658 | acpi_ps_is_leading_char(subop) || | |
659 | acpi_ps_is_prefix_char(subop)) { | |
1da177e4 LT |
660 | /* null_name or name_string */ |
661 | ||
4be44fcd | 662 | arg = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP); |
1da177e4 | 663 | if (!arg) { |
4be44fcd | 664 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
665 | } |
666 | ||
4be44fcd LB |
667 | status = |
668 | acpi_ps_get_next_namepath(walk_state, parser_state, | |
669 | arg, 0); | |
670 | } else { | |
44f6c012 | 671 | /* Single complex argument, nothing returned */ |
1da177e4 LT |
672 | |
673 | walk_state->arg_count = 1; | |
674 | } | |
675 | break; | |
676 | ||
1da177e4 LT |
677 | case ARGP_DATAOBJ: |
678 | case ARGP_TERMARG: | |
679 | ||
44f6c012 | 680 | /* Single complex argument, nothing returned */ |
1da177e4 LT |
681 | |
682 | walk_state->arg_count = 1; | |
683 | break; | |
684 | ||
1da177e4 LT |
685 | case ARGP_DATAOBJLIST: |
686 | case ARGP_TERMLIST: | |
687 | case ARGP_OBJLIST: | |
688 | ||
689 | if (parser_state->aml < parser_state->pkg_end) { | |
44f6c012 | 690 | /* Non-empty list of variable arguments, nothing returned */ |
1da177e4 LT |
691 | |
692 | walk_state->arg_count = ACPI_VAR_ARGS; | |
693 | } | |
694 | break; | |
695 | ||
1da177e4 LT |
696 | default: |
697 | ||
4be44fcd | 698 | ACPI_REPORT_ERROR(("Invalid arg_type: %X\n", arg_type)); |
1da177e4 LT |
699 | status = AE_AML_OPERAND_TYPE; |
700 | break; | |
701 | } | |
702 | ||
703 | *return_arg = arg; | |
4be44fcd | 704 | return_ACPI_STATUS(status); |
1da177e4 | 705 | } |