psargs.c 22 KB

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