dsobject.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. /******************************************************************************
  2. *
  3. * Module Name: dsobject - Dispatcher object management routines
  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 "acdispat.h"
  47. #include "acnamesp.h"
  48. #include "acinterp.h"
  49. #define _COMPONENT ACPI_DISPATCHER
  50. ACPI_MODULE_NAME("dsobject")
  51. /* Local prototypes */
  52. static acpi_status
  53. acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
  54. union acpi_parse_object *op,
  55. union acpi_operand_object **obj_desc_ptr);
  56. #ifndef ACPI_NO_METHOD_EXECUTION
  57. /*******************************************************************************
  58. *
  59. * FUNCTION: acpi_ds_build_internal_object
  60. *
  61. * PARAMETERS: walk_state - Current walk state
  62. * op - Parser object to be translated
  63. * obj_desc_ptr - Where the ACPI internal object is returned
  64. *
  65. * RETURN: Status
  66. *
  67. * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
  68. * Simple objects are any objects other than a package object!
  69. *
  70. ******************************************************************************/
  71. static acpi_status
  72. acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
  73. union acpi_parse_object *op,
  74. union acpi_operand_object **obj_desc_ptr)
  75. {
  76. union acpi_operand_object *obj_desc;
  77. acpi_status status;
  78. acpi_object_type type;
  79. ACPI_FUNCTION_TRACE(ds_build_internal_object);
  80. *obj_desc_ptr = NULL;
  81. if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
  82. /*
  83. * This is a named object reference. If this name was
  84. * previously looked up in the namespace, it was stored in this op.
  85. * Otherwise, go ahead and look it up now
  86. */
  87. if (!op->common.node) {
  88. status = acpi_ns_lookup(walk_state->scope_info,
  89. op->common.value.string,
  90. ACPI_TYPE_ANY,
  91. ACPI_IMODE_EXECUTE,
  92. ACPI_NS_SEARCH_PARENT |
  93. ACPI_NS_DONT_OPEN_SCOPE, NULL,
  94. ACPI_CAST_INDIRECT_PTR(struct
  95. acpi_namespace_node,
  96. &(op->
  97. common.
  98. node)));
  99. if (ACPI_FAILURE(status)) {
  100. /* Check if we are resolving a named reference within a package */
  101. if ((status == AE_NOT_FOUND)
  102. && (acpi_gbl_enable_interpreter_slack)
  103. &&
  104. ((op->common.parent->common.aml_opcode ==
  105. AML_PACKAGE_OP)
  106. || (op->common.parent->common.aml_opcode ==
  107. AML_VAR_PACKAGE_OP))) {
  108. /*
  109. * We didn't find the target and we are populating elements
  110. * of a package - ignore if slack enabled. Some ASL code
  111. * contains dangling invalid references in packages and
  112. * expects that no exception will be issued. Leave the
  113. * element as a null element. It cannot be used, but it
  114. * can be overwritten by subsequent ASL code - this is
  115. * typically the case.
  116. */
  117. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  118. "Ignoring unresolved reference in package [%4.4s]\n",
  119. walk_state->
  120. scope_info->scope.
  121. node->name.ascii));
  122. return_ACPI_STATUS(AE_OK);
  123. } else {
  124. ACPI_ERROR_NAMESPACE(op->common.value.
  125. string, status);
  126. }
  127. return_ACPI_STATUS(status);
  128. }
  129. }
  130. /* Special object resolution for elements of a package */
  131. if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) ||
  132. (op->common.parent->common.aml_opcode ==
  133. AML_VAR_PACKAGE_OP)) {
  134. /*
  135. * Attempt to resolve the node to a value before we insert it into
  136. * the package. If this is a reference to a common data type,
  137. * resolve it immediately. According to the ACPI spec, package
  138. * elements can only be "data objects" or method references.
  139. * Attempt to resolve to an Integer, Buffer, String or Package.
  140. * If cannot, return the named reference (for things like Devices,
  141. * Methods, etc.) Buffer Fields and Fields will resolve to simple
  142. * objects (int/buf/str/pkg).
  143. *
  144. * NOTE: References to things like Devices, Methods, Mutexes, etc.
  145. * will remain as named references. This behavior is not described
  146. * in the ACPI spec, but it appears to be an oversight.
  147. */
  148. obj_desc =
  149. ACPI_CAST_PTR(union acpi_operand_object,
  150. op->common.node);
  151. status =
  152. acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR
  153. (struct
  154. acpi_namespace_node,
  155. &obj_desc),
  156. walk_state);
  157. if (ACPI_FAILURE(status)) {
  158. return_ACPI_STATUS(status);
  159. }
  160. /*
  161. * Special handling for Alias objects. We need to setup the type
  162. * and the Op->Common.Node to point to the Alias target. Note,
  163. * Alias has at most one level of indirection internally.
  164. */
  165. type = op->common.node->type;
  166. if (type == ACPI_TYPE_LOCAL_ALIAS) {
  167. type = obj_desc->common.type;
  168. op->common.node =
  169. ACPI_CAST_PTR(struct acpi_namespace_node,
  170. op->common.node->object);
  171. }
  172. switch (type) {
  173. /*
  174. * For these types, we need the actual node, not the subobject.
  175. * However, the subobject did not get an extra reference count above.
  176. *
  177. * TBD: should ex_resolve_node_to_value be changed to fix this?
  178. */
  179. case ACPI_TYPE_DEVICE:
  180. case ACPI_TYPE_THERMAL:
  181. acpi_ut_add_reference(op->common.node->object);
  182. /*lint -fallthrough */
  183. /*
  184. * For these types, we need the actual node, not the subobject.
  185. * The subobject got an extra reference count in ex_resolve_node_to_value.
  186. */
  187. case ACPI_TYPE_MUTEX:
  188. case ACPI_TYPE_METHOD:
  189. case ACPI_TYPE_POWER:
  190. case ACPI_TYPE_PROCESSOR:
  191. case ACPI_TYPE_EVENT:
  192. case ACPI_TYPE_REGION:
  193. /* We will create a reference object for these types below */
  194. break;
  195. default:
  196. /*
  197. * All other types - the node was resolved to an actual
  198. * object, we are done.
  199. */
  200. goto exit;
  201. }
  202. }
  203. }
  204. /* Create and init a new internal ACPI object */
  205. obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info
  206. (op->common.aml_opcode))->
  207. object_type);
  208. if (!obj_desc) {
  209. return_ACPI_STATUS(AE_NO_MEMORY);
  210. }
  211. status =
  212. acpi_ds_init_object_from_op(walk_state, op, op->common.aml_opcode,
  213. &obj_desc);
  214. if (ACPI_FAILURE(status)) {
  215. acpi_ut_remove_reference(obj_desc);
  216. return_ACPI_STATUS(status);
  217. }
  218. exit:
  219. *obj_desc_ptr = obj_desc;
  220. return_ACPI_STATUS(status);
  221. }
  222. /*******************************************************************************
  223. *
  224. * FUNCTION: acpi_ds_build_internal_buffer_obj
  225. *
  226. * PARAMETERS: walk_state - Current walk state
  227. * op - Parser object to be translated
  228. * buffer_length - Length of the buffer
  229. * obj_desc_ptr - Where the ACPI internal object is returned
  230. *
  231. * RETURN: Status
  232. *
  233. * DESCRIPTION: Translate a parser Op package object to the equivalent
  234. * namespace object
  235. *
  236. ******************************************************************************/
  237. acpi_status
  238. acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
  239. union acpi_parse_object *op,
  240. u32 buffer_length,
  241. union acpi_operand_object **obj_desc_ptr)
  242. {
  243. union acpi_parse_object *arg;
  244. union acpi_operand_object *obj_desc;
  245. union acpi_parse_object *byte_list;
  246. u32 byte_list_length = 0;
  247. ACPI_FUNCTION_TRACE(ds_build_internal_buffer_obj);
  248. /*
  249. * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
  250. * The buffer object already exists (from the NS node), otherwise it must
  251. * be created.
  252. */
  253. obj_desc = *obj_desc_ptr;
  254. if (!obj_desc) {
  255. /* Create a new buffer object */
  256. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER);
  257. *obj_desc_ptr = obj_desc;
  258. if (!obj_desc) {
  259. return_ACPI_STATUS(AE_NO_MEMORY);
  260. }
  261. }
  262. /*
  263. * Second arg is the buffer data (optional) byte_list can be either
  264. * individual bytes or a string initializer. In either case, a
  265. * byte_list appears in the AML.
  266. */
  267. arg = op->common.value.arg; /* skip first arg */
  268. byte_list = arg->named.next;
  269. if (byte_list) {
  270. if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) {
  271. ACPI_ERROR((AE_INFO,
  272. "Expecting bytelist, found AML opcode 0x%X in op %p",
  273. byte_list->common.aml_opcode, byte_list));
  274. acpi_ut_remove_reference(obj_desc);
  275. return (AE_TYPE);
  276. }
  277. byte_list_length = (u32) byte_list->common.value.integer;
  278. }
  279. /*
  280. * The buffer length (number of bytes) will be the larger of:
  281. * 1) The specified buffer length and
  282. * 2) The length of the initializer byte list
  283. */
  284. obj_desc->buffer.length = buffer_length;
  285. if (byte_list_length > buffer_length) {
  286. obj_desc->buffer.length = byte_list_length;
  287. }
  288. /* Allocate the buffer */
  289. if (obj_desc->buffer.length == 0) {
  290. obj_desc->buffer.pointer = NULL;
  291. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  292. "Buffer defined with zero length in AML, creating\n"));
  293. } else {
  294. obj_desc->buffer.pointer =
  295. ACPI_ALLOCATE_ZEROED(obj_desc->buffer.length);
  296. if (!obj_desc->buffer.pointer) {
  297. acpi_ut_delete_object_desc(obj_desc);
  298. return_ACPI_STATUS(AE_NO_MEMORY);
  299. }
  300. /* Initialize buffer from the byte_list (if present) */
  301. if (byte_list) {
  302. memcpy(obj_desc->buffer.pointer, byte_list->named.data,
  303. byte_list_length);
  304. }
  305. }
  306. obj_desc->buffer.flags |= AOPOBJ_DATA_VALID;
  307. op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
  308. return_ACPI_STATUS(AE_OK);
  309. }
  310. /*******************************************************************************
  311. *
  312. * FUNCTION: acpi_ds_build_internal_package_obj
  313. *
  314. * PARAMETERS: walk_state - Current walk state
  315. * op - Parser object to be translated
  316. * element_count - Number of elements in the package - this is
  317. * the num_elements argument to Package()
  318. * obj_desc_ptr - Where the ACPI internal object is returned
  319. *
  320. * RETURN: Status
  321. *
  322. * DESCRIPTION: Translate a parser Op package object to the equivalent
  323. * namespace object
  324. *
  325. * NOTE: The number of elements in the package will be always be the num_elements
  326. * count, regardless of the number of elements in the package list. If
  327. * num_elements is smaller, only that many package list elements are used.
  328. * if num_elements is larger, the Package object is padded out with
  329. * objects of type Uninitialized (as per ACPI spec.)
  330. *
  331. * Even though the ASL compilers do not allow num_elements to be smaller
  332. * than the Package list length (for the fixed length package opcode), some
  333. * BIOS code modifies the AML on the fly to adjust the num_elements, and
  334. * this code compensates for that. This also provides compatibility with
  335. * other AML interpreters.
  336. *
  337. ******************************************************************************/
  338. acpi_status
  339. acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
  340. union acpi_parse_object *op,
  341. u32 element_count,
  342. union acpi_operand_object **obj_desc_ptr)
  343. {
  344. union acpi_parse_object *arg;
  345. union acpi_parse_object *parent;
  346. union acpi_operand_object *obj_desc = NULL;
  347. acpi_status status = AE_OK;
  348. u32 i;
  349. u16 index;
  350. u16 reference_count;
  351. ACPI_FUNCTION_TRACE(ds_build_internal_package_obj);
  352. /* Find the parent of a possibly nested package */
  353. parent = op->common.parent;
  354. while ((parent->common.aml_opcode == AML_PACKAGE_OP) ||
  355. (parent->common.aml_opcode == AML_VAR_PACKAGE_OP)) {
  356. parent = parent->common.parent;
  357. }
  358. /*
  359. * If we are evaluating a Named package object "Name (xxxx, Package)",
  360. * the package object already exists, otherwise it must be created.
  361. */
  362. obj_desc = *obj_desc_ptr;
  363. if (!obj_desc) {
  364. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE);
  365. *obj_desc_ptr = obj_desc;
  366. if (!obj_desc) {
  367. return_ACPI_STATUS(AE_NO_MEMORY);
  368. }
  369. obj_desc->package.node = parent->common.node;
  370. }
  371. /*
  372. * Allocate the element array (array of pointers to the individual
  373. * objects) based on the num_elements parameter. Add an extra pointer slot
  374. * so that the list is always null terminated.
  375. */
  376. obj_desc->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size)
  377. element_count +
  378. 1) * sizeof(void *));
  379. if (!obj_desc->package.elements) {
  380. acpi_ut_delete_object_desc(obj_desc);
  381. return_ACPI_STATUS(AE_NO_MEMORY);
  382. }
  383. obj_desc->package.count = element_count;
  384. /*
  385. * Initialize the elements of the package, up to the num_elements count.
  386. * Package is automatically padded with uninitialized (NULL) elements
  387. * if num_elements is greater than the package list length. Likewise,
  388. * Package is truncated if num_elements is less than the list length.
  389. */
  390. arg = op->common.value.arg;
  391. arg = arg->common.next;
  392. for (i = 0; arg && (i < element_count); i++) {
  393. if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
  394. if (arg->common.node->type == ACPI_TYPE_METHOD) {
  395. /*
  396. * A method reference "looks" to the parser to be a method
  397. * invocation, so we special case it here
  398. */
  399. arg->common.aml_opcode = AML_INT_NAMEPATH_OP;
  400. status =
  401. acpi_ds_build_internal_object(walk_state,
  402. arg,
  403. &obj_desc->
  404. package.
  405. elements[i]);
  406. } else {
  407. /* This package element is already built, just get it */
  408. obj_desc->package.elements[i] =
  409. ACPI_CAST_PTR(union acpi_operand_object,
  410. arg->common.node);
  411. }
  412. } else {
  413. status = acpi_ds_build_internal_object(walk_state, arg,
  414. &obj_desc->
  415. package.
  416. elements[i]);
  417. }
  418. if (*obj_desc_ptr) {
  419. /* Existing package, get existing reference count */
  420. reference_count =
  421. (*obj_desc_ptr)->common.reference_count;
  422. if (reference_count > 1) {
  423. /* Make new element ref count match original ref count */
  424. for (index = 0; index < (reference_count - 1);
  425. index++) {
  426. acpi_ut_add_reference((obj_desc->
  427. package.
  428. elements[i]));
  429. }
  430. }
  431. }
  432. arg = arg->common.next;
  433. }
  434. /* Check for match between num_elements and actual length of package_list */
  435. if (arg) {
  436. /*
  437. * num_elements was exhausted, but there are remaining elements in the
  438. * package_list. Truncate the package to num_elements.
  439. *
  440. * Note: technically, this is an error, from ACPI spec: "It is an error
  441. * for NumElements to be less than the number of elements in the
  442. * PackageList". However, we just print a message and
  443. * no exception is returned. This provides Windows compatibility. Some
  444. * BIOSs will alter the num_elements on the fly, creating this type
  445. * of ill-formed package object.
  446. */
  447. while (arg) {
  448. /*
  449. * We must delete any package elements that were created earlier
  450. * and are not going to be used because of the package truncation.
  451. */
  452. if (arg->common.node) {
  453. acpi_ut_remove_reference(ACPI_CAST_PTR
  454. (union
  455. acpi_operand_object,
  456. arg->common.node));
  457. arg->common.node = NULL;
  458. }
  459. /* Find out how many elements there really are */
  460. i++;
  461. arg = arg->common.next;
  462. }
  463. ACPI_INFO((AE_INFO,
  464. "Actual Package length (%u) is larger than NumElements field (%u), truncated",
  465. i, element_count));
  466. } else if (i < element_count) {
  467. /*
  468. * Arg list (elements) was exhausted, but we did not reach num_elements count.
  469. * Note: this is not an error, the package is padded out with NULLs.
  470. */
  471. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  472. "Package List length (%u) smaller than NumElements count (%u), padded with null elements\n",
  473. i, element_count));
  474. }
  475. obj_desc->package.flags |= AOPOBJ_DATA_VALID;
  476. op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
  477. return_ACPI_STATUS(status);
  478. }
  479. /*******************************************************************************
  480. *
  481. * FUNCTION: acpi_ds_create_node
  482. *
  483. * PARAMETERS: walk_state - Current walk state
  484. * node - NS Node to be initialized
  485. * op - Parser object to be translated
  486. *
  487. * RETURN: Status
  488. *
  489. * DESCRIPTION: Create the object to be associated with a namespace node
  490. *
  491. ******************************************************************************/
  492. acpi_status
  493. acpi_ds_create_node(struct acpi_walk_state *walk_state,
  494. struct acpi_namespace_node *node,
  495. union acpi_parse_object *op)
  496. {
  497. acpi_status status;
  498. union acpi_operand_object *obj_desc;
  499. ACPI_FUNCTION_TRACE_PTR(ds_create_node, op);
  500. /*
  501. * Because of the execution pass through the non-control-method
  502. * parts of the table, we can arrive here twice. Only init
  503. * the named object node the first time through
  504. */
  505. if (acpi_ns_get_attached_object(node)) {
  506. return_ACPI_STATUS(AE_OK);
  507. }
  508. if (!op->common.value.arg) {
  509. /* No arguments, there is nothing to do */
  510. return_ACPI_STATUS(AE_OK);
  511. }
  512. /* Build an internal object for the argument(s) */
  513. status = acpi_ds_build_internal_object(walk_state, op->common.value.arg,
  514. &obj_desc);
  515. if (ACPI_FAILURE(status)) {
  516. return_ACPI_STATUS(status);
  517. }
  518. /* Re-type the object according to its argument */
  519. node->type = obj_desc->common.type;
  520. /* Attach obj to node */
  521. status = acpi_ns_attach_object(node, obj_desc, node->type);
  522. /* Remove local reference to the object */
  523. acpi_ut_remove_reference(obj_desc);
  524. return_ACPI_STATUS(status);
  525. }
  526. #endif /* ACPI_NO_METHOD_EXECUTION */
  527. /*******************************************************************************
  528. *
  529. * FUNCTION: acpi_ds_init_object_from_op
  530. *
  531. * PARAMETERS: walk_state - Current walk state
  532. * op - Parser op used to init the internal object
  533. * opcode - AML opcode associated with the object
  534. * ret_obj_desc - Namespace object to be initialized
  535. *
  536. * RETURN: Status
  537. *
  538. * DESCRIPTION: Initialize a namespace object from a parser Op and its
  539. * associated arguments. The namespace object is a more compact
  540. * representation of the Op and its arguments.
  541. *
  542. ******************************************************************************/
  543. acpi_status
  544. acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
  545. union acpi_parse_object *op,
  546. u16 opcode,
  547. union acpi_operand_object **ret_obj_desc)
  548. {
  549. const struct acpi_opcode_info *op_info;
  550. union acpi_operand_object *obj_desc;
  551. acpi_status status = AE_OK;
  552. ACPI_FUNCTION_TRACE(ds_init_object_from_op);
  553. obj_desc = *ret_obj_desc;
  554. op_info = acpi_ps_get_opcode_info(opcode);
  555. if (op_info->class == AML_CLASS_UNKNOWN) {
  556. /* Unknown opcode */
  557. return_ACPI_STATUS(AE_TYPE);
  558. }
  559. /* Perform per-object initialization */
  560. switch (obj_desc->common.type) {
  561. case ACPI_TYPE_BUFFER:
  562. /*
  563. * Defer evaluation of Buffer term_arg operand
  564. */
  565. obj_desc->buffer.node =
  566. ACPI_CAST_PTR(struct acpi_namespace_node,
  567. walk_state->operands[0]);
  568. obj_desc->buffer.aml_start = op->named.data;
  569. obj_desc->buffer.aml_length = op->named.length;
  570. break;
  571. case ACPI_TYPE_PACKAGE:
  572. /*
  573. * Defer evaluation of Package term_arg operand
  574. */
  575. obj_desc->package.node =
  576. ACPI_CAST_PTR(struct acpi_namespace_node,
  577. walk_state->operands[0]);
  578. obj_desc->package.aml_start = op->named.data;
  579. obj_desc->package.aml_length = op->named.length;
  580. break;
  581. case ACPI_TYPE_INTEGER:
  582. switch (op_info->type) {
  583. case AML_TYPE_CONSTANT:
  584. /*
  585. * Resolve AML Constants here - AND ONLY HERE!
  586. * All constants are integers.
  587. * We mark the integer with a flag that indicates that it started
  588. * life as a constant -- so that stores to constants will perform
  589. * as expected (noop). zero_op is used as a placeholder for optional
  590. * target operands.
  591. */
  592. obj_desc->common.flags = AOPOBJ_AML_CONSTANT;
  593. switch (opcode) {
  594. case AML_ZERO_OP:
  595. obj_desc->integer.value = 0;
  596. break;
  597. case AML_ONE_OP:
  598. obj_desc->integer.value = 1;
  599. break;
  600. case AML_ONES_OP:
  601. obj_desc->integer.value = ACPI_UINT64_MAX;
  602. /* Truncate value if we are executing from a 32-bit ACPI table */
  603. #ifndef ACPI_NO_METHOD_EXECUTION
  604. (void)acpi_ex_truncate_for32bit_table(obj_desc);
  605. #endif
  606. break;
  607. case AML_REVISION_OP:
  608. obj_desc->integer.value = ACPI_CA_VERSION;
  609. break;
  610. default:
  611. ACPI_ERROR((AE_INFO,
  612. "Unknown constant opcode 0x%X",
  613. opcode));
  614. status = AE_AML_OPERAND_TYPE;
  615. break;
  616. }
  617. break;
  618. case AML_TYPE_LITERAL:
  619. obj_desc->integer.value = op->common.value.integer;
  620. #ifndef ACPI_NO_METHOD_EXECUTION
  621. if (acpi_ex_truncate_for32bit_table(obj_desc)) {
  622. /* Warn if we found a 64-bit constant in a 32-bit table */
  623. ACPI_WARNING((AE_INFO,
  624. "Truncated 64-bit constant found in 32-bit table: %8.8X%8.8X => %8.8X",
  625. ACPI_FORMAT_UINT64(op->common.
  626. value.integer),
  627. (u32)obj_desc->integer.value));
  628. }
  629. #endif
  630. break;
  631. default:
  632. ACPI_ERROR((AE_INFO, "Unknown Integer type 0x%X",
  633. op_info->type));
  634. status = AE_AML_OPERAND_TYPE;
  635. break;
  636. }
  637. break;
  638. case ACPI_TYPE_STRING:
  639. obj_desc->string.pointer = op->common.value.string;
  640. obj_desc->string.length = (u32)strlen(op->common.value.string);
  641. /*
  642. * The string is contained in the ACPI table, don't ever try
  643. * to delete it
  644. */
  645. obj_desc->common.flags |= AOPOBJ_STATIC_POINTER;
  646. break;
  647. case ACPI_TYPE_METHOD:
  648. break;
  649. case ACPI_TYPE_LOCAL_REFERENCE:
  650. switch (op_info->type) {
  651. case AML_TYPE_LOCAL_VARIABLE:
  652. /* Local ID (0-7) is (AML opcode - base AML_LOCAL_OP) */
  653. obj_desc->reference.value =
  654. ((u32)opcode) - AML_LOCAL_OP;
  655. obj_desc->reference.class = ACPI_REFCLASS_LOCAL;
  656. #ifndef ACPI_NO_METHOD_EXECUTION
  657. status =
  658. acpi_ds_method_data_get_node(ACPI_REFCLASS_LOCAL,
  659. obj_desc->reference.
  660. value, walk_state,
  661. ACPI_CAST_INDIRECT_PTR
  662. (struct
  663. acpi_namespace_node,
  664. &obj_desc->reference.
  665. object));
  666. #endif
  667. break;
  668. case AML_TYPE_METHOD_ARGUMENT:
  669. /* Arg ID (0-6) is (AML opcode - base AML_ARG_OP) */
  670. obj_desc->reference.value = ((u32)opcode) - AML_ARG_OP;
  671. obj_desc->reference.class = ACPI_REFCLASS_ARG;
  672. #ifndef ACPI_NO_METHOD_EXECUTION
  673. status = acpi_ds_method_data_get_node(ACPI_REFCLASS_ARG,
  674. obj_desc->
  675. reference.value,
  676. walk_state,
  677. ACPI_CAST_INDIRECT_PTR
  678. (struct
  679. acpi_namespace_node,
  680. &obj_desc->
  681. reference.
  682. object));
  683. #endif
  684. break;
  685. default: /* Object name or Debug object */
  686. switch (op->common.aml_opcode) {
  687. case AML_INT_NAMEPATH_OP:
  688. /* Node was saved in Op */
  689. obj_desc->reference.node = op->common.node;
  690. obj_desc->reference.object =
  691. op->common.node->object;
  692. obj_desc->reference.class = ACPI_REFCLASS_NAME;
  693. break;
  694. case AML_DEBUG_OP:
  695. obj_desc->reference.class = ACPI_REFCLASS_DEBUG;
  696. break;
  697. default:
  698. ACPI_ERROR((AE_INFO,
  699. "Unimplemented reference type for AML opcode: 0x%4.4X",
  700. opcode));
  701. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  702. }
  703. break;
  704. }
  705. break;
  706. default:
  707. ACPI_ERROR((AE_INFO, "Unimplemented data type: 0x%X",
  708. obj_desc->common.type));
  709. status = AE_AML_OPERAND_TYPE;
  710. break;
  711. }
  712. return_ACPI_STATUS(status);
  713. }