psargs.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. /******************************************************************************
  2. *
  3. * Module Name: psargs - Parse AML opcode arguments
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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_IS_ROOT_PREFIX(*end) || ACPI_IS_PARENT_PREFIX(*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, start);
  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. u8 *aml;
  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 = parser_state->aml;
  402. /* Determine field type */
  403. switch (ACPI_GET8(parser_state->aml)) {
  404. case AML_FIELD_OFFSET_OP:
  405. opcode = AML_INT_RESERVEDFIELD_OP;
  406. parser_state->aml++;
  407. break;
  408. case AML_FIELD_ACCESS_OP:
  409. opcode = AML_INT_ACCESSFIELD_OP;
  410. parser_state->aml++;
  411. break;
  412. case AML_FIELD_CONNECTION_OP:
  413. opcode = AML_INT_CONNECTION_OP;
  414. parser_state->aml++;
  415. break;
  416. case AML_FIELD_EXT_ACCESS_OP:
  417. opcode = AML_INT_EXTACCESSFIELD_OP;
  418. parser_state->aml++;
  419. break;
  420. default:
  421. opcode = AML_INT_NAMEDFIELD_OP;
  422. break;
  423. }
  424. /* Allocate a new field op */
  425. field = acpi_ps_alloc_op(opcode, aml);
  426. if (!field) {
  427. return_PTR(NULL);
  428. }
  429. /* Decode the field type */
  430. switch (opcode) {
  431. case AML_INT_NAMEDFIELD_OP:
  432. /* Get the 4-character name */
  433. ACPI_MOVE_32_TO_32(&name, parser_state->aml);
  434. acpi_ps_set_name(field, name);
  435. parser_state->aml += ACPI_NAME_SIZE;
  436. /* Get the length which is encoded as a package length */
  437. field->common.value.size =
  438. acpi_ps_get_next_package_length(parser_state);
  439. break;
  440. case AML_INT_RESERVEDFIELD_OP:
  441. /* Get the length which is encoded as a package length */
  442. field->common.value.size =
  443. acpi_ps_get_next_package_length(parser_state);
  444. break;
  445. case AML_INT_ACCESSFIELD_OP:
  446. case AML_INT_EXTACCESSFIELD_OP:
  447. /*
  448. * Get access_type and access_attrib and merge into the field Op
  449. * access_type is first operand, access_attribute is second. stuff
  450. * these bytes into the node integer value for convenience.
  451. */
  452. /* Get the two bytes (Type/Attribute) */
  453. access_type = ACPI_GET8(parser_state->aml);
  454. parser_state->aml++;
  455. access_attribute = ACPI_GET8(parser_state->aml);
  456. parser_state->aml++;
  457. field->common.value.integer = (u8)access_type;
  458. field->common.value.integer |= (u16)(access_attribute << 8);
  459. /* This opcode has a third byte, access_length */
  460. if (opcode == AML_INT_EXTACCESSFIELD_OP) {
  461. access_length = ACPI_GET8(parser_state->aml);
  462. parser_state->aml++;
  463. field->common.value.integer |=
  464. (u32)(access_length << 16);
  465. }
  466. break;
  467. case AML_INT_CONNECTION_OP:
  468. /*
  469. * Argument for Connection operator can be either a Buffer
  470. * (resource descriptor), or a name_string.
  471. */
  472. aml = parser_state->aml;
  473. if (ACPI_GET8(parser_state->aml) == AML_BUFFER_OP) {
  474. parser_state->aml++;
  475. pkg_end = parser_state->aml;
  476. pkg_length =
  477. acpi_ps_get_next_package_length(parser_state);
  478. pkg_end += pkg_length;
  479. if (parser_state->aml < pkg_end) {
  480. /* Non-empty list */
  481. arg =
  482. acpi_ps_alloc_op(AML_INT_BYTELIST_OP, aml);
  483. if (!arg) {
  484. acpi_ps_free_op(field);
  485. return_PTR(NULL);
  486. }
  487. /* Get the actual buffer length argument */
  488. opcode = ACPI_GET8(parser_state->aml);
  489. parser_state->aml++;
  490. switch (opcode) {
  491. case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
  492. buffer_length =
  493. ACPI_GET8(parser_state->aml);
  494. parser_state->aml += 1;
  495. break;
  496. case AML_WORD_OP: /* AML_WORDDATA_ARG */
  497. buffer_length =
  498. ACPI_GET16(parser_state->aml);
  499. parser_state->aml += 2;
  500. break;
  501. case AML_DWORD_OP: /* AML_DWORDATA_ARG */
  502. buffer_length =
  503. ACPI_GET32(parser_state->aml);
  504. parser_state->aml += 4;
  505. break;
  506. default:
  507. buffer_length = 0;
  508. break;
  509. }
  510. /* Fill in bytelist data */
  511. arg->named.value.size = buffer_length;
  512. arg->named.data = parser_state->aml;
  513. }
  514. /* Skip to End of byte data */
  515. parser_state->aml = pkg_end;
  516. } else {
  517. arg = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, aml);
  518. if (!arg) {
  519. acpi_ps_free_op(field);
  520. return_PTR(NULL);
  521. }
  522. /* Get the Namestring argument */
  523. arg->common.value.name =
  524. acpi_ps_get_next_namestring(parser_state);
  525. }
  526. /* Link the buffer/namestring to parent (CONNECTION_OP) */
  527. acpi_ps_append_arg(field, arg);
  528. break;
  529. default:
  530. /* Opcode was set in previous switch */
  531. break;
  532. }
  533. return_PTR(field);
  534. }
  535. /*******************************************************************************
  536. *
  537. * FUNCTION: acpi_ps_get_next_arg
  538. *
  539. * PARAMETERS: walk_state - Current state
  540. * parser_state - Current parser state object
  541. * arg_type - The argument type (AML_*_ARG)
  542. * return_arg - Where the next arg is returned
  543. *
  544. * RETURN: Status, and an op object containing the next argument.
  545. *
  546. * DESCRIPTION: Get next argument (including complex list arguments that require
  547. * pushing the parser stack)
  548. *
  549. ******************************************************************************/
  550. acpi_status
  551. acpi_ps_get_next_arg(struct acpi_walk_state *walk_state,
  552. struct acpi_parse_state *parser_state,
  553. u32 arg_type, union acpi_parse_object **return_arg)
  554. {
  555. union acpi_parse_object *arg = NULL;
  556. union acpi_parse_object *prev = NULL;
  557. union acpi_parse_object *field;
  558. u32 subop;
  559. acpi_status status = AE_OK;
  560. ACPI_FUNCTION_TRACE_PTR(ps_get_next_arg, parser_state);
  561. switch (arg_type) {
  562. case ARGP_BYTEDATA:
  563. case ARGP_WORDDATA:
  564. case ARGP_DWORDDATA:
  565. case ARGP_CHARLIST:
  566. case ARGP_NAME:
  567. case ARGP_NAMESTRING:
  568. /* Constants, strings, and namestrings are all the same size */
  569. arg = acpi_ps_alloc_op(AML_BYTE_OP, parser_state->aml);
  570. if (!arg) {
  571. return_ACPI_STATUS(AE_NO_MEMORY);
  572. }
  573. acpi_ps_get_next_simple_arg(parser_state, arg_type, arg);
  574. break;
  575. case ARGP_PKGLENGTH:
  576. /* Package length, nothing returned */
  577. parser_state->pkg_end =
  578. acpi_ps_get_next_package_end(parser_state);
  579. break;
  580. case ARGP_FIELDLIST:
  581. if (parser_state->aml < parser_state->pkg_end) {
  582. /* Non-empty list */
  583. while (parser_state->aml < parser_state->pkg_end) {
  584. field = acpi_ps_get_next_field(parser_state);
  585. if (!field) {
  586. return_ACPI_STATUS(AE_NO_MEMORY);
  587. }
  588. if (prev) {
  589. prev->common.next = field;
  590. } else {
  591. arg = field;
  592. }
  593. prev = field;
  594. }
  595. /* Skip to End of byte data */
  596. parser_state->aml = parser_state->pkg_end;
  597. }
  598. break;
  599. case ARGP_BYTELIST:
  600. if (parser_state->aml < parser_state->pkg_end) {
  601. /* Non-empty list */
  602. arg = acpi_ps_alloc_op(AML_INT_BYTELIST_OP,
  603. parser_state->aml);
  604. if (!arg) {
  605. return_ACPI_STATUS(AE_NO_MEMORY);
  606. }
  607. /* Fill in bytelist data */
  608. arg->common.value.size = (u32)
  609. ACPI_PTR_DIFF(parser_state->pkg_end,
  610. parser_state->aml);
  611. arg->named.data = parser_state->aml;
  612. /* Skip to End of byte data */
  613. parser_state->aml = parser_state->pkg_end;
  614. }
  615. break;
  616. case ARGP_TARGET:
  617. case ARGP_SUPERNAME:
  618. case ARGP_SIMPLENAME:
  619. subop = acpi_ps_peek_opcode(parser_state);
  620. if (subop == 0 ||
  621. acpi_ps_is_leading_char(subop) ||
  622. ACPI_IS_ROOT_PREFIX(subop) ||
  623. ACPI_IS_PARENT_PREFIX(subop)) {
  624. /* null_name or name_string */
  625. arg =
  626. acpi_ps_alloc_op(AML_INT_NAMEPATH_OP,
  627. parser_state->aml);
  628. if (!arg) {
  629. return_ACPI_STATUS(AE_NO_MEMORY);
  630. }
  631. /* To support super_name arg of Unload */
  632. if (walk_state->opcode == AML_UNLOAD_OP) {
  633. status =
  634. acpi_ps_get_next_namepath(walk_state,
  635. parser_state, arg,
  636. 1);
  637. /*
  638. * If the super_name arg of Unload is a method call,
  639. * we have restored the AML pointer, just free this Arg
  640. */
  641. if (arg->common.aml_opcode ==
  642. AML_INT_METHODCALL_OP) {
  643. acpi_ps_free_op(arg);
  644. arg = NULL;
  645. }
  646. } else {
  647. status =
  648. acpi_ps_get_next_namepath(walk_state,
  649. parser_state, arg,
  650. 0);
  651. }
  652. } else {
  653. /* Single complex argument, nothing returned */
  654. walk_state->arg_count = 1;
  655. }
  656. break;
  657. case ARGP_DATAOBJ:
  658. case ARGP_TERMARG:
  659. /* Single complex argument, nothing returned */
  660. walk_state->arg_count = 1;
  661. break;
  662. case ARGP_DATAOBJLIST:
  663. case ARGP_TERMLIST:
  664. case ARGP_OBJLIST:
  665. if (parser_state->aml < parser_state->pkg_end) {
  666. /* Non-empty list of variable arguments, nothing returned */
  667. walk_state->arg_count = ACPI_VAR_ARGS;
  668. }
  669. break;
  670. default:
  671. ACPI_ERROR((AE_INFO, "Invalid ArgType: 0x%X", arg_type));
  672. status = AE_AML_OPERAND_TYPE;
  673. break;
  674. }
  675. *return_arg = arg;
  676. return_ACPI_STATUS(status);
  677. }