exresolv.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /******************************************************************************
  2. *
  3. * Module Name: exresolv - AML Interpreter object resolution
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2018, 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 "amlcode.h"
  45. #include "acdispat.h"
  46. #include "acinterp.h"
  47. #include "acnamesp.h"
  48. #define _COMPONENT ACPI_EXECUTER
  49. ACPI_MODULE_NAME("exresolv")
  50. /* Local prototypes */
  51. static acpi_status
  52. acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
  53. struct acpi_walk_state *walk_state);
  54. /*******************************************************************************
  55. *
  56. * FUNCTION: acpi_ex_resolve_to_value
  57. *
  58. * PARAMETERS: **stack_ptr - Points to entry on obj_stack, which can
  59. * be either an (union acpi_operand_object *)
  60. * or an acpi_handle.
  61. * walk_state - Current method state
  62. *
  63. * RETURN: Status
  64. *
  65. * DESCRIPTION: Convert Reference objects to values
  66. *
  67. ******************************************************************************/
  68. acpi_status
  69. acpi_ex_resolve_to_value(union acpi_operand_object **stack_ptr,
  70. struct acpi_walk_state *walk_state)
  71. {
  72. acpi_status status;
  73. ACPI_FUNCTION_TRACE_PTR(ex_resolve_to_value, stack_ptr);
  74. if (!stack_ptr || !*stack_ptr) {
  75. ACPI_ERROR((AE_INFO, "Internal - null pointer"));
  76. return_ACPI_STATUS(AE_AML_NO_OPERAND);
  77. }
  78. /*
  79. * The entity pointed to by the stack_ptr can be either
  80. * 1) A valid union acpi_operand_object, or
  81. * 2) A struct acpi_namespace_node (named_obj)
  82. */
  83. if (ACPI_GET_DESCRIPTOR_TYPE(*stack_ptr) == ACPI_DESC_TYPE_OPERAND) {
  84. status = acpi_ex_resolve_object_to_value(stack_ptr, walk_state);
  85. if (ACPI_FAILURE(status)) {
  86. return_ACPI_STATUS(status);
  87. }
  88. if (!*stack_ptr) {
  89. ACPI_ERROR((AE_INFO, "Internal - null pointer"));
  90. return_ACPI_STATUS(AE_AML_NO_OPERAND);
  91. }
  92. }
  93. /*
  94. * Object on the stack may have changed if acpi_ex_resolve_object_to_value()
  95. * was called (i.e., we can't use an _else_ here.)
  96. */
  97. if (ACPI_GET_DESCRIPTOR_TYPE(*stack_ptr) == ACPI_DESC_TYPE_NAMED) {
  98. status =
  99. acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR
  100. (struct acpi_namespace_node,
  101. stack_ptr), walk_state);
  102. if (ACPI_FAILURE(status)) {
  103. return_ACPI_STATUS(status);
  104. }
  105. }
  106. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Resolved object %p\n", *stack_ptr));
  107. return_ACPI_STATUS(AE_OK);
  108. }
  109. /*******************************************************************************
  110. *
  111. * FUNCTION: acpi_ex_resolve_object_to_value
  112. *
  113. * PARAMETERS: stack_ptr - Pointer to an internal object
  114. * walk_state - Current method state
  115. *
  116. * RETURN: Status
  117. *
  118. * DESCRIPTION: Retrieve the value from an internal object. The Reference type
  119. * uses the associated AML opcode to determine the value.
  120. *
  121. ******************************************************************************/
  122. static acpi_status
  123. acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
  124. struct acpi_walk_state *walk_state)
  125. {
  126. acpi_status status = AE_OK;
  127. union acpi_operand_object *stack_desc;
  128. union acpi_operand_object *obj_desc = NULL;
  129. u8 ref_type;
  130. ACPI_FUNCTION_TRACE(ex_resolve_object_to_value);
  131. stack_desc = *stack_ptr;
  132. /* This is an object of type union acpi_operand_object */
  133. switch (stack_desc->common.type) {
  134. case ACPI_TYPE_LOCAL_REFERENCE:
  135. ref_type = stack_desc->reference.class;
  136. switch (ref_type) {
  137. case ACPI_REFCLASS_LOCAL:
  138. case ACPI_REFCLASS_ARG:
  139. /*
  140. * Get the local from the method's state info
  141. * Note: this increments the local's object reference count
  142. */
  143. status = acpi_ds_method_data_get_value(ref_type,
  144. stack_desc->
  145. reference.value,
  146. walk_state,
  147. &obj_desc);
  148. if (ACPI_FAILURE(status)) {
  149. return_ACPI_STATUS(status);
  150. }
  151. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  152. "[Arg/Local %X] ValueObj is %p\n",
  153. stack_desc->reference.value,
  154. obj_desc));
  155. /*
  156. * Now we can delete the original Reference Object and
  157. * replace it with the resolved value
  158. */
  159. acpi_ut_remove_reference(stack_desc);
  160. *stack_ptr = obj_desc;
  161. break;
  162. case ACPI_REFCLASS_INDEX:
  163. switch (stack_desc->reference.target_type) {
  164. case ACPI_TYPE_BUFFER_FIELD:
  165. /* Just return - do not dereference */
  166. break;
  167. case ACPI_TYPE_PACKAGE:
  168. /* If method call or copy_object - do not dereference */
  169. if ((walk_state->opcode ==
  170. AML_INT_METHODCALL_OP)
  171. || (walk_state->opcode ==
  172. AML_COPY_OBJECT_OP)) {
  173. break;
  174. }
  175. /* Otherwise, dereference the package_index to a package element */
  176. obj_desc = *stack_desc->reference.where;
  177. if (obj_desc) {
  178. /*
  179. * Valid object descriptor, copy pointer to return value
  180. * (i.e., dereference the package index)
  181. * Delete the ref object, increment the returned object
  182. */
  183. acpi_ut_add_reference(obj_desc);
  184. *stack_ptr = obj_desc;
  185. } else {
  186. /*
  187. * A NULL object descriptor means an uninitialized element of
  188. * the package, can't dereference it
  189. */
  190. ACPI_ERROR((AE_INFO,
  191. "Attempt to dereference an Index to "
  192. "NULL package element Idx=%p",
  193. stack_desc));
  194. status = AE_AML_UNINITIALIZED_ELEMENT;
  195. }
  196. break;
  197. default:
  198. /* Invalid reference object */
  199. ACPI_ERROR((AE_INFO,
  200. "Unknown TargetType 0x%X in Index/Reference object %p",
  201. stack_desc->reference.target_type,
  202. stack_desc));
  203. status = AE_AML_INTERNAL;
  204. break;
  205. }
  206. break;
  207. case ACPI_REFCLASS_REFOF:
  208. case ACPI_REFCLASS_DEBUG:
  209. case ACPI_REFCLASS_TABLE:
  210. /* Just leave the object as-is, do not dereference */
  211. break;
  212. case ACPI_REFCLASS_NAME: /* Reference to a named object */
  213. /* Dereference the name */
  214. if ((stack_desc->reference.node->type ==
  215. ACPI_TYPE_DEVICE)
  216. || (stack_desc->reference.node->type ==
  217. ACPI_TYPE_THERMAL)) {
  218. /* These node types do not have 'real' subobjects */
  219. *stack_ptr = (void *)stack_desc->reference.node;
  220. } else {
  221. /* Get the object pointed to by the namespace node */
  222. *stack_ptr =
  223. (stack_desc->reference.node)->object;
  224. acpi_ut_add_reference(*stack_ptr);
  225. }
  226. acpi_ut_remove_reference(stack_desc);
  227. break;
  228. default:
  229. ACPI_ERROR((AE_INFO,
  230. "Unknown Reference type 0x%X in %p",
  231. ref_type, stack_desc));
  232. status = AE_AML_INTERNAL;
  233. break;
  234. }
  235. break;
  236. case ACPI_TYPE_BUFFER:
  237. status = acpi_ds_get_buffer_arguments(stack_desc);
  238. break;
  239. case ACPI_TYPE_PACKAGE:
  240. status = acpi_ds_get_package_arguments(stack_desc);
  241. break;
  242. case ACPI_TYPE_BUFFER_FIELD:
  243. case ACPI_TYPE_LOCAL_REGION_FIELD:
  244. case ACPI_TYPE_LOCAL_BANK_FIELD:
  245. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  246. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  247. "FieldRead SourceDesc=%p Type=%X\n",
  248. stack_desc, stack_desc->common.type));
  249. status =
  250. acpi_ex_read_data_from_field(walk_state, stack_desc,
  251. &obj_desc);
  252. /* Remove a reference to the original operand, then override */
  253. acpi_ut_remove_reference(*stack_ptr);
  254. *stack_ptr = (void *)obj_desc;
  255. break;
  256. default:
  257. break;
  258. }
  259. return_ACPI_STATUS(status);
  260. }
  261. /*******************************************************************************
  262. *
  263. * FUNCTION: acpi_ex_resolve_multiple
  264. *
  265. * PARAMETERS: walk_state - Current state (contains AML opcode)
  266. * operand - Starting point for resolution
  267. * return_type - Where the object type is returned
  268. * return_desc - Where the resolved object is returned
  269. *
  270. * RETURN: Status
  271. *
  272. * DESCRIPTION: Return the base object and type. Traverse a reference list if
  273. * necessary to get to the base object.
  274. *
  275. ******************************************************************************/
  276. acpi_status
  277. acpi_ex_resolve_multiple(struct acpi_walk_state *walk_state,
  278. union acpi_operand_object *operand,
  279. acpi_object_type *return_type,
  280. union acpi_operand_object **return_desc)
  281. {
  282. union acpi_operand_object *obj_desc = ACPI_CAST_PTR(void, operand);
  283. struct acpi_namespace_node *node =
  284. ACPI_CAST_PTR(struct acpi_namespace_node, operand);
  285. acpi_object_type type;
  286. acpi_status status;
  287. ACPI_FUNCTION_TRACE(acpi_ex_resolve_multiple);
  288. /* Operand can be either a namespace node or an operand descriptor */
  289. switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
  290. case ACPI_DESC_TYPE_OPERAND:
  291. type = obj_desc->common.type;
  292. break;
  293. case ACPI_DESC_TYPE_NAMED:
  294. type = ((struct acpi_namespace_node *)obj_desc)->type;
  295. obj_desc = acpi_ns_get_attached_object(node);
  296. /* If we had an Alias node, use the attached object for type info */
  297. if (type == ACPI_TYPE_LOCAL_ALIAS) {
  298. type = ((struct acpi_namespace_node *)obj_desc)->type;
  299. obj_desc = acpi_ns_get_attached_object((struct
  300. acpi_namespace_node
  301. *)obj_desc);
  302. }
  303. switch (type) {
  304. case ACPI_TYPE_DEVICE:
  305. case ACPI_TYPE_THERMAL:
  306. /* These types have no attached subobject */
  307. break;
  308. default:
  309. /* All other types require a subobject */
  310. if (!obj_desc) {
  311. ACPI_ERROR((AE_INFO,
  312. "[%4.4s] Node is unresolved or uninitialized",
  313. acpi_ut_get_node_name(node)));
  314. return_ACPI_STATUS(AE_AML_UNINITIALIZED_NODE);
  315. }
  316. break;
  317. }
  318. break;
  319. default:
  320. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  321. }
  322. /* If type is anything other than a reference, we are done */
  323. if (type != ACPI_TYPE_LOCAL_REFERENCE) {
  324. goto exit;
  325. }
  326. /*
  327. * For reference objects created via the ref_of, Index, or Load/load_table
  328. * operators, we need to get to the base object (as per the ACPI
  329. * specification of the object_type and size_of operators). This means
  330. * traversing the list of possibly many nested references.
  331. */
  332. while (obj_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) {
  333. switch (obj_desc->reference.class) {
  334. case ACPI_REFCLASS_REFOF:
  335. case ACPI_REFCLASS_NAME:
  336. /* Dereference the reference pointer */
  337. if (obj_desc->reference.class == ACPI_REFCLASS_REFOF) {
  338. node = obj_desc->reference.object;
  339. } else { /* AML_INT_NAMEPATH_OP */
  340. node = obj_desc->reference.node;
  341. }
  342. /* All "References" point to a NS node */
  343. if (ACPI_GET_DESCRIPTOR_TYPE(node) !=
  344. ACPI_DESC_TYPE_NAMED) {
  345. ACPI_ERROR((AE_INFO,
  346. "Not a namespace node %p [%s]",
  347. node,
  348. acpi_ut_get_descriptor_name(node)));
  349. return_ACPI_STATUS(AE_AML_INTERNAL);
  350. }
  351. /* Get the attached object */
  352. obj_desc = acpi_ns_get_attached_object(node);
  353. if (!obj_desc) {
  354. /* No object, use the NS node type */
  355. type = acpi_ns_get_type(node);
  356. goto exit;
  357. }
  358. /* Check for circular references */
  359. if (obj_desc == operand) {
  360. return_ACPI_STATUS(AE_AML_CIRCULAR_REFERENCE);
  361. }
  362. break;
  363. case ACPI_REFCLASS_INDEX:
  364. /* Get the type of this reference (index into another object) */
  365. type = obj_desc->reference.target_type;
  366. if (type != ACPI_TYPE_PACKAGE) {
  367. goto exit;
  368. }
  369. /*
  370. * The main object is a package, we want to get the type
  371. * of the individual package element that is referenced by
  372. * the index.
  373. *
  374. * This could of course in turn be another reference object.
  375. */
  376. obj_desc = *(obj_desc->reference.where);
  377. if (!obj_desc) {
  378. /* NULL package elements are allowed */
  379. type = 0; /* Uninitialized */
  380. goto exit;
  381. }
  382. break;
  383. case ACPI_REFCLASS_TABLE:
  384. type = ACPI_TYPE_DDB_HANDLE;
  385. goto exit;
  386. case ACPI_REFCLASS_LOCAL:
  387. case ACPI_REFCLASS_ARG:
  388. if (return_desc) {
  389. status =
  390. acpi_ds_method_data_get_value(obj_desc->
  391. reference.
  392. class,
  393. obj_desc->
  394. reference.
  395. value,
  396. walk_state,
  397. &obj_desc);
  398. if (ACPI_FAILURE(status)) {
  399. return_ACPI_STATUS(status);
  400. }
  401. acpi_ut_remove_reference(obj_desc);
  402. } else {
  403. status =
  404. acpi_ds_method_data_get_node(obj_desc->
  405. reference.
  406. class,
  407. obj_desc->
  408. reference.
  409. value,
  410. walk_state,
  411. &node);
  412. if (ACPI_FAILURE(status)) {
  413. return_ACPI_STATUS(status);
  414. }
  415. obj_desc = acpi_ns_get_attached_object(node);
  416. if (!obj_desc) {
  417. type = ACPI_TYPE_ANY;
  418. goto exit;
  419. }
  420. }
  421. break;
  422. case ACPI_REFCLASS_DEBUG:
  423. /* The Debug Object is of type "DebugObject" */
  424. type = ACPI_TYPE_DEBUG_OBJECT;
  425. goto exit;
  426. default:
  427. ACPI_ERROR((AE_INFO,
  428. "Unknown Reference Class 0x%2.2X",
  429. obj_desc->reference.class));
  430. return_ACPI_STATUS(AE_AML_INTERNAL);
  431. }
  432. }
  433. /*
  434. * Now we are guaranteed to have an object that has not been created
  435. * via the ref_of or Index operators.
  436. */
  437. type = obj_desc->common.type;
  438. exit:
  439. /* Convert internal types to external types */
  440. switch (type) {
  441. case ACPI_TYPE_LOCAL_REGION_FIELD:
  442. case ACPI_TYPE_LOCAL_BANK_FIELD:
  443. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  444. type = ACPI_TYPE_FIELD_UNIT;
  445. break;
  446. case ACPI_TYPE_LOCAL_SCOPE:
  447. /* Per ACPI Specification, Scope is untyped */
  448. type = ACPI_TYPE_ANY;
  449. break;
  450. default:
  451. /* No change to Type required */
  452. break;
  453. }
  454. *return_type = type;
  455. if (return_desc) {
  456. *return_desc = obj_desc;
  457. }
  458. return_ACPI_STATUS(AE_OK);
  459. }