psargs.c 22 KB

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