psargs.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  1. /******************************************************************************
  2. *
  3. * Module Name: psargs - Parse AML opcode arguments
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2017, 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 ((GET_CURRENT_ARG_TYPE(walk_state->arg_types) ==
  226. ARGP_SUPERNAME)
  227. || (GET_CURRENT_ARG_TYPE(walk_state->arg_types) ==
  228. ARGP_TARGET)) {
  229. /*
  230. * acpi_ps_get_next_namestring has increased the AML pointer past
  231. * the method invocation namestring, so we need to restore the
  232. * saved AML pointer back to the original method invocation
  233. * namestring.
  234. */
  235. walk_state->parser_state.aml = start;
  236. walk_state->arg_count = 1;
  237. acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
  238. }
  239. /* This name is actually a control method invocation */
  240. method_desc = acpi_ns_get_attached_object(node);
  241. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  242. "Control Method invocation %4.4s - %p Desc %p Path=%p\n",
  243. node->name.ascii, node, method_desc, path));
  244. name_op = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, start);
  245. if (!name_op) {
  246. return_ACPI_STATUS(AE_NO_MEMORY);
  247. }
  248. /* Change Arg into a METHOD CALL and attach name to it */
  249. acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
  250. name_op->common.value.name = path;
  251. /* Point METHODCALL/NAME to the METHOD Node */
  252. name_op->common.node = node;
  253. acpi_ps_append_arg(arg, name_op);
  254. if (!method_desc) {
  255. ACPI_ERROR((AE_INFO,
  256. "Control Method %p has no attached object",
  257. node));
  258. return_ACPI_STATUS(AE_AML_INTERNAL);
  259. }
  260. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  261. "Control Method - %p Args %X\n",
  262. node, method_desc->method.param_count));
  263. /* Get the number of arguments to expect */
  264. walk_state->arg_count = method_desc->method.param_count;
  265. return_ACPI_STATUS(AE_OK);
  266. }
  267. /*
  268. * Special handling if the name was not found during the lookup -
  269. * some not_found cases are allowed
  270. */
  271. if (status == AE_NOT_FOUND) {
  272. /* 1) not_found is ok during load pass 1/2 (allow forward references) */
  273. if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) !=
  274. ACPI_PARSE_EXECUTE) {
  275. status = AE_OK;
  276. }
  277. /* 2) not_found during a cond_ref_of(x) is ok by definition */
  278. else if (walk_state->op->common.aml_opcode ==
  279. AML_COND_REF_OF_OP) {
  280. status = AE_OK;
  281. }
  282. /*
  283. * 3) not_found while building a Package is ok at this point, we
  284. * may flag as an error later if slack mode is not enabled.
  285. * (Some ASL code depends on allowing this behavior)
  286. */
  287. else if ((arg->common.parent) &&
  288. ((arg->common.parent->common.aml_opcode ==
  289. AML_PACKAGE_OP)
  290. || (arg->common.parent->common.aml_opcode ==
  291. AML_VAR_PACKAGE_OP))) {
  292. status = AE_OK;
  293. }
  294. }
  295. /* Final exception check (may have been changed from code above) */
  296. if (ACPI_FAILURE(status)) {
  297. ACPI_ERROR_NAMESPACE(path, status);
  298. if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) ==
  299. ACPI_PARSE_EXECUTE) {
  300. /* Report a control method execution error */
  301. status = acpi_ds_method_error(status, walk_state);
  302. }
  303. }
  304. /* Save the namepath */
  305. arg->common.value.name = path;
  306. return_ACPI_STATUS(status);
  307. }
  308. /*******************************************************************************
  309. *
  310. * FUNCTION: acpi_ps_get_next_simple_arg
  311. *
  312. * PARAMETERS: parser_state - Current parser state object
  313. * arg_type - The argument type (AML_*_ARG)
  314. * arg - Where the argument is returned
  315. *
  316. * RETURN: None
  317. *
  318. * DESCRIPTION: Get the next simple argument (constant, string, or namestring)
  319. *
  320. ******************************************************************************/
  321. void
  322. acpi_ps_get_next_simple_arg(struct acpi_parse_state *parser_state,
  323. u32 arg_type, union acpi_parse_object *arg)
  324. {
  325. u32 length;
  326. u16 opcode;
  327. u8 *aml = parser_state->aml;
  328. ACPI_FUNCTION_TRACE_U32(ps_get_next_simple_arg, arg_type);
  329. switch (arg_type) {
  330. case ARGP_BYTEDATA:
  331. /* Get 1 byte from the AML stream */
  332. opcode = AML_BYTE_OP;
  333. arg->common.value.integer = (u64) *aml;
  334. length = 1;
  335. break;
  336. case ARGP_WORDDATA:
  337. /* Get 2 bytes from the AML stream */
  338. opcode = AML_WORD_OP;
  339. ACPI_MOVE_16_TO_64(&arg->common.value.integer, aml);
  340. length = 2;
  341. break;
  342. case ARGP_DWORDDATA:
  343. /* Get 4 bytes from the AML stream */
  344. opcode = AML_DWORD_OP;
  345. ACPI_MOVE_32_TO_64(&arg->common.value.integer, aml);
  346. length = 4;
  347. break;
  348. case ARGP_QWORDDATA:
  349. /* Get 8 bytes from the AML stream */
  350. opcode = AML_QWORD_OP;
  351. ACPI_MOVE_64_TO_64(&arg->common.value.integer, aml);
  352. length = 8;
  353. break;
  354. case ARGP_CHARLIST:
  355. /* Get a pointer to the string, point past the string */
  356. opcode = AML_STRING_OP;
  357. arg->common.value.string = ACPI_CAST_PTR(char, aml);
  358. /* Find the null terminator */
  359. length = 0;
  360. while (aml[length]) {
  361. length++;
  362. }
  363. length++;
  364. break;
  365. case ARGP_NAME:
  366. case ARGP_NAMESTRING:
  367. acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
  368. arg->common.value.name =
  369. acpi_ps_get_next_namestring(parser_state);
  370. return_VOID;
  371. default:
  372. ACPI_ERROR((AE_INFO, "Invalid ArgType 0x%X", arg_type));
  373. return_VOID;
  374. }
  375. acpi_ps_init_op(arg, opcode);
  376. parser_state->aml += length;
  377. return_VOID;
  378. }
  379. /*******************************************************************************
  380. *
  381. * FUNCTION: acpi_ps_get_next_field
  382. *
  383. * PARAMETERS: parser_state - Current parser state object
  384. *
  385. * RETURN: A newly allocated FIELD op
  386. *
  387. * DESCRIPTION: Get next field (named_field, reserved_field, or access_field)
  388. *
  389. ******************************************************************************/
  390. static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
  391. *parser_state)
  392. {
  393. u8 *aml;
  394. union acpi_parse_object *field;
  395. union acpi_parse_object *arg = NULL;
  396. u16 opcode;
  397. u32 name;
  398. u8 access_type;
  399. u8 access_attribute;
  400. u8 access_length;
  401. u32 pkg_length;
  402. u8 *pkg_end;
  403. u32 buffer_length;
  404. ACPI_FUNCTION_TRACE(ps_get_next_field);
  405. aml = parser_state->aml;
  406. /* Determine field type */
  407. switch (ACPI_GET8(parser_state->aml)) {
  408. case AML_FIELD_OFFSET_OP:
  409. opcode = AML_INT_RESERVEDFIELD_OP;
  410. parser_state->aml++;
  411. break;
  412. case AML_FIELD_ACCESS_OP:
  413. opcode = AML_INT_ACCESSFIELD_OP;
  414. parser_state->aml++;
  415. break;
  416. case AML_FIELD_CONNECTION_OP:
  417. opcode = AML_INT_CONNECTION_OP;
  418. parser_state->aml++;
  419. break;
  420. case AML_FIELD_EXT_ACCESS_OP:
  421. opcode = AML_INT_EXTACCESSFIELD_OP;
  422. parser_state->aml++;
  423. break;
  424. default:
  425. opcode = AML_INT_NAMEDFIELD_OP;
  426. break;
  427. }
  428. /* Allocate a new field op */
  429. field = acpi_ps_alloc_op(opcode, aml);
  430. if (!field) {
  431. return_PTR(NULL);
  432. }
  433. /* Decode the field type */
  434. switch (opcode) {
  435. case AML_INT_NAMEDFIELD_OP:
  436. /* Get the 4-character name */
  437. ACPI_MOVE_32_TO_32(&name, parser_state->aml);
  438. acpi_ps_set_name(field, name);
  439. parser_state->aml += ACPI_NAME_SIZE;
  440. /* Get the length which is encoded as a package length */
  441. field->common.value.size =
  442. acpi_ps_get_next_package_length(parser_state);
  443. break;
  444. case AML_INT_RESERVEDFIELD_OP:
  445. /* Get the length which is encoded as a package length */
  446. field->common.value.size =
  447. acpi_ps_get_next_package_length(parser_state);
  448. break;
  449. case AML_INT_ACCESSFIELD_OP:
  450. case AML_INT_EXTACCESSFIELD_OP:
  451. /*
  452. * Get access_type and access_attrib and merge into the field Op
  453. * access_type is first operand, access_attribute is second. stuff
  454. * these bytes into the node integer value for convenience.
  455. */
  456. /* Get the two bytes (Type/Attribute) */
  457. access_type = ACPI_GET8(parser_state->aml);
  458. parser_state->aml++;
  459. access_attribute = ACPI_GET8(parser_state->aml);
  460. parser_state->aml++;
  461. field->common.value.integer = (u8)access_type;
  462. field->common.value.integer |= (u16)(access_attribute << 8);
  463. /* This opcode has a third byte, access_length */
  464. if (opcode == AML_INT_EXTACCESSFIELD_OP) {
  465. access_length = ACPI_GET8(parser_state->aml);
  466. parser_state->aml++;
  467. field->common.value.integer |=
  468. (u32)(access_length << 16);
  469. }
  470. break;
  471. case AML_INT_CONNECTION_OP:
  472. /*
  473. * Argument for Connection operator can be either a Buffer
  474. * (resource descriptor), or a name_string.
  475. */
  476. aml = parser_state->aml;
  477. if (ACPI_GET8(parser_state->aml) == AML_BUFFER_OP) {
  478. parser_state->aml++;
  479. pkg_end = parser_state->aml;
  480. pkg_length =
  481. acpi_ps_get_next_package_length(parser_state);
  482. pkg_end += pkg_length;
  483. if (parser_state->aml < pkg_end) {
  484. /* Non-empty list */
  485. arg =
  486. acpi_ps_alloc_op(AML_INT_BYTELIST_OP, aml);
  487. if (!arg) {
  488. acpi_ps_free_op(field);
  489. return_PTR(NULL);
  490. }
  491. /* Get the actual buffer length argument */
  492. opcode = ACPI_GET8(parser_state->aml);
  493. parser_state->aml++;
  494. switch (opcode) {
  495. case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
  496. buffer_length =
  497. ACPI_GET8(parser_state->aml);
  498. parser_state->aml += 1;
  499. break;
  500. case AML_WORD_OP: /* AML_WORDDATA_ARG */
  501. buffer_length =
  502. ACPI_GET16(parser_state->aml);
  503. parser_state->aml += 2;
  504. break;
  505. case AML_DWORD_OP: /* AML_DWORDATA_ARG */
  506. buffer_length =
  507. ACPI_GET32(parser_state->aml);
  508. parser_state->aml += 4;
  509. break;
  510. default:
  511. buffer_length = 0;
  512. break;
  513. }
  514. /* Fill in bytelist data */
  515. arg->named.value.size = buffer_length;
  516. arg->named.data = parser_state->aml;
  517. }
  518. /* Skip to End of byte data */
  519. parser_state->aml = pkg_end;
  520. } else {
  521. arg = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, aml);
  522. if (!arg) {
  523. acpi_ps_free_op(field);
  524. return_PTR(NULL);
  525. }
  526. /* Get the Namestring argument */
  527. arg->common.value.name =
  528. acpi_ps_get_next_namestring(parser_state);
  529. }
  530. /* Link the buffer/namestring to parent (CONNECTION_OP) */
  531. acpi_ps_append_arg(field, arg);
  532. break;
  533. default:
  534. /* Opcode was set in previous switch */
  535. break;
  536. }
  537. return_PTR(field);
  538. }
  539. /*******************************************************************************
  540. *
  541. * FUNCTION: acpi_ps_get_next_arg
  542. *
  543. * PARAMETERS: walk_state - Current state
  544. * parser_state - Current parser state object
  545. * arg_type - The argument type (AML_*_ARG)
  546. * return_arg - Where the next arg is returned
  547. *
  548. * RETURN: Status, and an op object containing the next argument.
  549. *
  550. * DESCRIPTION: Get next argument (including complex list arguments that require
  551. * pushing the parser stack)
  552. *
  553. ******************************************************************************/
  554. acpi_status
  555. acpi_ps_get_next_arg(struct acpi_walk_state *walk_state,
  556. struct acpi_parse_state *parser_state,
  557. u32 arg_type, union acpi_parse_object **return_arg)
  558. {
  559. union acpi_parse_object *arg = NULL;
  560. union acpi_parse_object *prev = NULL;
  561. union acpi_parse_object *field;
  562. u32 subop;
  563. acpi_status status = AE_OK;
  564. ACPI_FUNCTION_TRACE_PTR(ps_get_next_arg, parser_state);
  565. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  566. "Expected argument type ARGP: %s (%2.2X)\n",
  567. acpi_ut_get_argument_type_name(arg_type), arg_type));
  568. switch (arg_type) {
  569. case ARGP_BYTEDATA:
  570. case ARGP_WORDDATA:
  571. case ARGP_DWORDDATA:
  572. case ARGP_CHARLIST:
  573. case ARGP_NAME:
  574. case ARGP_NAMESTRING:
  575. /* Constants, strings, and namestrings are all the same size */
  576. arg = acpi_ps_alloc_op(AML_BYTE_OP, parser_state->aml);
  577. if (!arg) {
  578. return_ACPI_STATUS(AE_NO_MEMORY);
  579. }
  580. acpi_ps_get_next_simple_arg(parser_state, arg_type, arg);
  581. break;
  582. case ARGP_PKGLENGTH:
  583. /* Package length, nothing returned */
  584. parser_state->pkg_end =
  585. acpi_ps_get_next_package_end(parser_state);
  586. break;
  587. case ARGP_FIELDLIST:
  588. if (parser_state->aml < parser_state->pkg_end) {
  589. /* Non-empty list */
  590. while (parser_state->aml < parser_state->pkg_end) {
  591. field = acpi_ps_get_next_field(parser_state);
  592. if (!field) {
  593. return_ACPI_STATUS(AE_NO_MEMORY);
  594. }
  595. if (prev) {
  596. prev->common.next = field;
  597. } else {
  598. arg = field;
  599. }
  600. prev = field;
  601. }
  602. /* Skip to End of byte data */
  603. parser_state->aml = parser_state->pkg_end;
  604. }
  605. break;
  606. case ARGP_BYTELIST:
  607. if (parser_state->aml < parser_state->pkg_end) {
  608. /* Non-empty list */
  609. arg = acpi_ps_alloc_op(AML_INT_BYTELIST_OP,
  610. parser_state->aml);
  611. if (!arg) {
  612. return_ACPI_STATUS(AE_NO_MEMORY);
  613. }
  614. /* Fill in bytelist data */
  615. arg->common.value.size = (u32)
  616. ACPI_PTR_DIFF(parser_state->pkg_end,
  617. parser_state->aml);
  618. arg->named.data = parser_state->aml;
  619. /* Skip to End of byte data */
  620. parser_state->aml = parser_state->pkg_end;
  621. }
  622. break;
  623. case ARGP_SIMPLENAME:
  624. case ARGP_NAME_OR_REF:
  625. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  626. "**** SimpleName/NameOrRef: %s (%2.2X)\n",
  627. acpi_ut_get_argument_type_name(arg_type),
  628. arg_type));
  629. subop = acpi_ps_peek_opcode(parser_state);
  630. if (subop == 0 ||
  631. acpi_ps_is_leading_char(subop) ||
  632. ACPI_IS_ROOT_PREFIX(subop) ||
  633. ACPI_IS_PARENT_PREFIX(subop)) {
  634. /* null_name or name_string */
  635. arg =
  636. acpi_ps_alloc_op(AML_INT_NAMEPATH_OP,
  637. parser_state->aml);
  638. if (!arg) {
  639. return_ACPI_STATUS(AE_NO_MEMORY);
  640. }
  641. status =
  642. acpi_ps_get_next_namepath(walk_state, parser_state,
  643. arg,
  644. ACPI_NOT_METHOD_CALL);
  645. } else {
  646. /* Single complex argument, nothing returned */
  647. walk_state->arg_count = 1;
  648. }
  649. break;
  650. case ARGP_TARGET:
  651. case ARGP_SUPERNAME:
  652. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  653. "**** Target/Supername: %s (%2.2X)\n",
  654. acpi_ut_get_argument_type_name(arg_type),
  655. arg_type));
  656. subop = acpi_ps_peek_opcode(parser_state);
  657. if (subop == 0 ||
  658. acpi_ps_is_leading_char(subop) ||
  659. ACPI_IS_ROOT_PREFIX(subop) ||
  660. ACPI_IS_PARENT_PREFIX(subop)) {
  661. /* NULL target (zero). Convert to a NULL namepath */
  662. arg =
  663. acpi_ps_alloc_op(AML_INT_NAMEPATH_OP,
  664. parser_state->aml);
  665. if (!arg) {
  666. return_ACPI_STATUS(AE_NO_MEMORY);
  667. }
  668. status =
  669. acpi_ps_get_next_namepath(walk_state, parser_state,
  670. arg,
  671. ACPI_POSSIBLE_METHOD_CALL);
  672. if (arg->common.aml_opcode == AML_INT_METHODCALL_OP) {
  673. acpi_ps_free_op(arg);
  674. arg = NULL;
  675. walk_state->arg_count = 1;
  676. }
  677. } else {
  678. /* Single complex argument, nothing returned */
  679. walk_state->arg_count = 1;
  680. }
  681. break;
  682. case ARGP_DATAOBJ:
  683. case ARGP_TERMARG:
  684. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  685. "**** TermArg/DataObj: %s (%2.2X)\n",
  686. acpi_ut_get_argument_type_name(arg_type),
  687. arg_type));
  688. /* Single complex argument, nothing returned */
  689. walk_state->arg_count = 1;
  690. break;
  691. case ARGP_DATAOBJLIST:
  692. case ARGP_TERMLIST:
  693. case ARGP_OBJLIST:
  694. if (parser_state->aml < parser_state->pkg_end) {
  695. /* Non-empty list of variable arguments, nothing returned */
  696. walk_state->arg_count = ACPI_VAR_ARGS;
  697. }
  698. break;
  699. default:
  700. ACPI_ERROR((AE_INFO, "Invalid ArgType: 0x%X", arg_type));
  701. status = AE_AML_OPERAND_TYPE;
  702. break;
  703. }
  704. *return_arg = arg;
  705. return_ACPI_STATUS(status);
  706. }