dsobject.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. /******************************************************************************
  2. *
  3. * Module Name: dsobject - Dispatcher object management routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  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 <acpi/acparser.h>
  44. #include <acpi/amlcode.h>
  45. #include <acpi/acdispat.h>
  46. #include <acpi/acnamesp.h>
  47. #include <acpi/acinterp.h>
  48. #define _COMPONENT ACPI_DISPATCHER
  49. ACPI_MODULE_NAME ("dsobject")
  50. #ifndef ACPI_NO_METHOD_EXECUTION
  51. /*****************************************************************************
  52. *
  53. * FUNCTION: acpi_ds_build_internal_object
  54. *
  55. * PARAMETERS: walk_state - Current walk state
  56. * Op - Parser object to be translated
  57. * obj_desc_ptr - Where the ACPI internal object is returned
  58. *
  59. * RETURN: Status
  60. *
  61. * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
  62. * Simple objects are any objects other than a package object!
  63. *
  64. ****************************************************************************/
  65. acpi_status
  66. acpi_ds_build_internal_object (
  67. struct acpi_walk_state *walk_state,
  68. union acpi_parse_object *op,
  69. union acpi_operand_object **obj_desc_ptr)
  70. {
  71. union acpi_operand_object *obj_desc;
  72. acpi_status status;
  73. ACPI_FUNCTION_TRACE ("ds_build_internal_object");
  74. *obj_desc_ptr = NULL;
  75. if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
  76. /*
  77. * This is an named object reference. If this name was
  78. * previously looked up in the namespace, it was stored in this op.
  79. * Otherwise, go ahead and look it up now
  80. */
  81. if (!op->common.node) {
  82. status = acpi_ns_lookup (walk_state->scope_info, op->common.value.string,
  83. ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
  84. ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL,
  85. (struct acpi_namespace_node **) &(op->common.node));
  86. if (ACPI_FAILURE (status)) {
  87. ACPI_REPORT_NSERROR (op->common.value.string, status);
  88. return_ACPI_STATUS (status);
  89. }
  90. }
  91. }
  92. /* Create and init the internal ACPI object */
  93. obj_desc = acpi_ut_create_internal_object ((acpi_ps_get_opcode_info (op->common.aml_opcode))->object_type);
  94. if (!obj_desc) {
  95. return_ACPI_STATUS (AE_NO_MEMORY);
  96. }
  97. status = acpi_ds_init_object_from_op (walk_state, op, op->common.aml_opcode, &obj_desc);
  98. if (ACPI_FAILURE (status)) {
  99. acpi_ut_remove_reference (obj_desc);
  100. return_ACPI_STATUS (status);
  101. }
  102. *obj_desc_ptr = obj_desc;
  103. return_ACPI_STATUS (AE_OK);
  104. }
  105. /*****************************************************************************
  106. *
  107. * FUNCTION: acpi_ds_build_internal_buffer_obj
  108. *
  109. * PARAMETERS: walk_state - Current walk state
  110. * Op - Parser object to be translated
  111. * buffer_length - Length of the buffer
  112. * obj_desc_ptr - Where the ACPI internal object is returned
  113. *
  114. * RETURN: Status
  115. *
  116. * DESCRIPTION: Translate a parser Op package object to the equivalent
  117. * namespace object
  118. *
  119. ****************************************************************************/
  120. acpi_status
  121. acpi_ds_build_internal_buffer_obj (
  122. struct acpi_walk_state *walk_state,
  123. union acpi_parse_object *op,
  124. u32 buffer_length,
  125. union acpi_operand_object **obj_desc_ptr)
  126. {
  127. union acpi_parse_object *arg;
  128. union acpi_operand_object *obj_desc;
  129. union acpi_parse_object *byte_list;
  130. u32 byte_list_length = 0;
  131. ACPI_FUNCTION_TRACE ("ds_build_internal_buffer_obj");
  132. obj_desc = *obj_desc_ptr;
  133. if (obj_desc) {
  134. /*
  135. * We are evaluating a Named buffer object "Name (xxxx, Buffer)".
  136. * The buffer object already exists (from the NS node)
  137. */
  138. }
  139. else {
  140. /* Create a new buffer object */
  141. obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_BUFFER);
  142. *obj_desc_ptr = obj_desc;
  143. if (!obj_desc) {
  144. return_ACPI_STATUS (AE_NO_MEMORY);
  145. }
  146. }
  147. /*
  148. * Second arg is the buffer data (optional) byte_list can be either
  149. * individual bytes or a string initializer. In either case, a
  150. * byte_list appears in the AML.
  151. */
  152. arg = op->common.value.arg; /* skip first arg */
  153. byte_list = arg->named.next;
  154. if (byte_list) {
  155. if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) {
  156. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  157. "Expecting bytelist, got AML opcode %X in op %p\n",
  158. byte_list->common.aml_opcode, byte_list));
  159. acpi_ut_remove_reference (obj_desc);
  160. return (AE_TYPE);
  161. }
  162. byte_list_length = (u32) byte_list->common.value.integer;
  163. }
  164. /*
  165. * The buffer length (number of bytes) will be the larger of:
  166. * 1) The specified buffer length and
  167. * 2) The length of the initializer byte list
  168. */
  169. obj_desc->buffer.length = buffer_length;
  170. if (byte_list_length > buffer_length) {
  171. obj_desc->buffer.length = byte_list_length;
  172. }
  173. /* Allocate the buffer */
  174. if (obj_desc->buffer.length == 0) {
  175. obj_desc->buffer.pointer = NULL;
  176. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
  177. "Buffer defined with zero length in AML, creating\n"));
  178. }
  179. else {
  180. obj_desc->buffer.pointer = ACPI_MEM_CALLOCATE (
  181. obj_desc->buffer.length);
  182. if (!obj_desc->buffer.pointer) {
  183. acpi_ut_delete_object_desc (obj_desc);
  184. return_ACPI_STATUS (AE_NO_MEMORY);
  185. }
  186. /* Initialize buffer from the byte_list (if present) */
  187. if (byte_list) {
  188. ACPI_MEMCPY (obj_desc->buffer.pointer, byte_list->named.data,
  189. byte_list_length);
  190. }
  191. }
  192. obj_desc->buffer.flags |= AOPOBJ_DATA_VALID;
  193. op->common.node = (struct acpi_namespace_node *) obj_desc;
  194. return_ACPI_STATUS (AE_OK);
  195. }
  196. /*****************************************************************************
  197. *
  198. * FUNCTION: acpi_ds_build_internal_package_obj
  199. *
  200. * PARAMETERS: walk_state - Current walk state
  201. * Op - Parser object to be translated
  202. * package_length - Number of elements in the package
  203. * obj_desc_ptr - Where the ACPI internal object is returned
  204. *
  205. * RETURN: Status
  206. *
  207. * DESCRIPTION: Translate a parser Op package object to the equivalent
  208. * namespace object
  209. *
  210. ****************************************************************************/
  211. acpi_status
  212. acpi_ds_build_internal_package_obj (
  213. struct acpi_walk_state *walk_state,
  214. union acpi_parse_object *op,
  215. u32 package_length,
  216. union acpi_operand_object **obj_desc_ptr)
  217. {
  218. union acpi_parse_object *arg;
  219. union acpi_parse_object *parent;
  220. union acpi_operand_object *obj_desc = NULL;
  221. u32 package_list_length;
  222. acpi_status status = AE_OK;
  223. u32 i;
  224. ACPI_FUNCTION_TRACE ("ds_build_internal_package_obj");
  225. /* Find the parent of a possibly nested package */
  226. parent = op->common.parent;
  227. while ((parent->common.aml_opcode == AML_PACKAGE_OP) ||
  228. (parent->common.aml_opcode == AML_VAR_PACKAGE_OP)) {
  229. parent = parent->common.parent;
  230. }
  231. obj_desc = *obj_desc_ptr;
  232. if (obj_desc) {
  233. /*
  234. * We are evaluating a Named package object "Name (xxxx, Package)".
  235. * Get the existing package object from the NS node
  236. */
  237. }
  238. else {
  239. obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_PACKAGE);
  240. *obj_desc_ptr = obj_desc;
  241. if (!obj_desc) {
  242. return_ACPI_STATUS (AE_NO_MEMORY);
  243. }
  244. obj_desc->package.node = parent->common.node;
  245. }
  246. obj_desc->package.count = package_length;
  247. /* Count the number of items in the package list */
  248. package_list_length = 0;
  249. arg = op->common.value.arg;
  250. arg = arg->common.next;
  251. while (arg) {
  252. package_list_length++;
  253. arg = arg->common.next;
  254. }
  255. /*
  256. * The package length (number of elements) will be the greater
  257. * of the specified length and the length of the initializer list
  258. */
  259. if (package_list_length > package_length) {
  260. obj_desc->package.count = package_list_length;
  261. }
  262. /*
  263. * Allocate the pointer array (array of pointers to the
  264. * individual objects). Add an extra pointer slot so
  265. * that the list is always null terminated.
  266. */
  267. obj_desc->package.elements = ACPI_MEM_CALLOCATE (
  268. ((acpi_size) obj_desc->package.count + 1) * sizeof (void *));
  269. if (!obj_desc->package.elements) {
  270. acpi_ut_delete_object_desc (obj_desc);
  271. return_ACPI_STATUS (AE_NO_MEMORY);
  272. }
  273. /*
  274. * Now init the elements of the package
  275. */
  276. i = 0;
  277. arg = op->common.value.arg;
  278. arg = arg->common.next;
  279. while (arg) {
  280. if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
  281. /* Object (package or buffer) is already built */
  282. obj_desc->package.elements[i] = ACPI_CAST_PTR (union acpi_operand_object, arg->common.node);
  283. }
  284. else {
  285. status = acpi_ds_build_internal_object (walk_state, arg,
  286. &obj_desc->package.elements[i]);
  287. }
  288. i++;
  289. arg = arg->common.next;
  290. }
  291. obj_desc->package.flags |= AOPOBJ_DATA_VALID;
  292. op->common.node = (struct acpi_namespace_node *) obj_desc;
  293. return_ACPI_STATUS (status);
  294. }
  295. /*****************************************************************************
  296. *
  297. * FUNCTION: acpi_ds_create_node
  298. *
  299. * PARAMETERS: walk_state - Current walk state
  300. * Node - NS Node to be initialized
  301. * Op - Parser object to be translated
  302. *
  303. * RETURN: Status
  304. *
  305. * DESCRIPTION: Create the object to be associated with a namespace node
  306. *
  307. ****************************************************************************/
  308. acpi_status
  309. acpi_ds_create_node (
  310. struct acpi_walk_state *walk_state,
  311. struct acpi_namespace_node *node,
  312. union acpi_parse_object *op)
  313. {
  314. acpi_status status;
  315. union acpi_operand_object *obj_desc;
  316. ACPI_FUNCTION_TRACE_PTR ("ds_create_node", op);
  317. /*
  318. * Because of the execution pass through the non-control-method
  319. * parts of the table, we can arrive here twice. Only init
  320. * the named object node the first time through
  321. */
  322. if (acpi_ns_get_attached_object (node)) {
  323. return_ACPI_STATUS (AE_OK);
  324. }
  325. if (!op->common.value.arg) {
  326. /* No arguments, there is nothing to do */
  327. return_ACPI_STATUS (AE_OK);
  328. }
  329. /* Build an internal object for the argument(s) */
  330. status = acpi_ds_build_internal_object (walk_state, op->common.value.arg, &obj_desc);
  331. if (ACPI_FAILURE (status)) {
  332. return_ACPI_STATUS (status);
  333. }
  334. /* Re-type the object according to its argument */
  335. node->type = ACPI_GET_OBJECT_TYPE (obj_desc);
  336. /* Attach obj to node */
  337. status = acpi_ns_attach_object (node, obj_desc, node->type);
  338. /* Remove local reference to the object */
  339. acpi_ut_remove_reference (obj_desc);
  340. return_ACPI_STATUS (status);
  341. }
  342. #endif /* ACPI_NO_METHOD_EXECUTION */
  343. /*****************************************************************************
  344. *
  345. * FUNCTION: acpi_ds_init_object_from_op
  346. *
  347. * PARAMETERS: walk_state - Current walk state
  348. * Op - Parser op used to init the internal object
  349. * Opcode - AML opcode associated with the object
  350. * ret_obj_desc - Namespace object to be initialized
  351. *
  352. * RETURN: Status
  353. *
  354. * DESCRIPTION: Initialize a namespace object from a parser Op and its
  355. * associated arguments. The namespace object is a more compact
  356. * representation of the Op and its arguments.
  357. *
  358. ****************************************************************************/
  359. acpi_status
  360. acpi_ds_init_object_from_op (
  361. struct acpi_walk_state *walk_state,
  362. union acpi_parse_object *op,
  363. u16 opcode,
  364. union acpi_operand_object **ret_obj_desc)
  365. {
  366. const struct acpi_opcode_info *op_info;
  367. union acpi_operand_object *obj_desc;
  368. acpi_status status = AE_OK;
  369. ACPI_FUNCTION_TRACE ("ds_init_object_from_op");
  370. obj_desc = *ret_obj_desc;
  371. op_info = acpi_ps_get_opcode_info (opcode);
  372. if (op_info->class == AML_CLASS_UNKNOWN) {
  373. /* Unknown opcode */
  374. return_ACPI_STATUS (AE_TYPE);
  375. }
  376. /* Perform per-object initialization */
  377. switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
  378. case ACPI_TYPE_BUFFER:
  379. /*
  380. * Defer evaluation of Buffer term_arg operand
  381. */
  382. obj_desc->buffer.node = (struct acpi_namespace_node *) walk_state->operands[0];
  383. obj_desc->buffer.aml_start = op->named.data;
  384. obj_desc->buffer.aml_length = op->named.length;
  385. break;
  386. case ACPI_TYPE_PACKAGE:
  387. /*
  388. * Defer evaluation of Package term_arg operand
  389. */
  390. obj_desc->package.node = (struct acpi_namespace_node *) walk_state->operands[0];
  391. obj_desc->package.aml_start = op->named.data;
  392. obj_desc->package.aml_length = op->named.length;
  393. break;
  394. case ACPI_TYPE_INTEGER:
  395. switch (op_info->type) {
  396. case AML_TYPE_CONSTANT:
  397. /*
  398. * Resolve AML Constants here - AND ONLY HERE!
  399. * All constants are integers.
  400. * We mark the integer with a flag that indicates that it started life
  401. * as a constant -- so that stores to constants will perform as expected (noop).
  402. * (zero_op is used as a placeholder for optional target operands.)
  403. */
  404. obj_desc->common.flags = AOPOBJ_AML_CONSTANT;
  405. switch (opcode) {
  406. case AML_ZERO_OP:
  407. obj_desc->integer.value = 0;
  408. break;
  409. case AML_ONE_OP:
  410. obj_desc->integer.value = 1;
  411. break;
  412. case AML_ONES_OP:
  413. obj_desc->integer.value = ACPI_INTEGER_MAX;
  414. /* Truncate value if we are executing from a 32-bit ACPI table */
  415. #ifndef ACPI_NO_METHOD_EXECUTION
  416. acpi_ex_truncate_for32bit_table (obj_desc);
  417. #endif
  418. break;
  419. case AML_REVISION_OP:
  420. obj_desc->integer.value = ACPI_CA_VERSION;
  421. break;
  422. default:
  423. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown constant opcode %X\n", opcode));
  424. status = AE_AML_OPERAND_TYPE;
  425. break;
  426. }
  427. break;
  428. case AML_TYPE_LITERAL:
  429. obj_desc->integer.value = op->common.value.integer;
  430. break;
  431. default:
  432. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Integer type %X\n", op_info->type));
  433. status = AE_AML_OPERAND_TYPE;
  434. break;
  435. }
  436. break;
  437. case ACPI_TYPE_STRING:
  438. obj_desc->string.pointer = op->common.value.string;
  439. obj_desc->string.length = (u32) ACPI_STRLEN (op->common.value.string);
  440. /*
  441. * The string is contained in the ACPI table, don't ever try
  442. * to delete it
  443. */
  444. obj_desc->common.flags |= AOPOBJ_STATIC_POINTER;
  445. break;
  446. case ACPI_TYPE_METHOD:
  447. break;
  448. case ACPI_TYPE_LOCAL_REFERENCE:
  449. switch (op_info->type) {
  450. case AML_TYPE_LOCAL_VARIABLE:
  451. /* Split the opcode into a base opcode + offset */
  452. obj_desc->reference.opcode = AML_LOCAL_OP;
  453. obj_desc->reference.offset = opcode - AML_LOCAL_OP;
  454. #ifndef ACPI_NO_METHOD_EXECUTION
  455. status = acpi_ds_method_data_get_node (AML_LOCAL_OP, obj_desc->reference.offset,
  456. walk_state, (struct acpi_namespace_node **) &obj_desc->reference.object);
  457. #endif
  458. break;
  459. case AML_TYPE_METHOD_ARGUMENT:
  460. /* Split the opcode into a base opcode + offset */
  461. obj_desc->reference.opcode = AML_ARG_OP;
  462. obj_desc->reference.offset = opcode - AML_ARG_OP;
  463. #ifndef ACPI_NO_METHOD_EXECUTION
  464. status = acpi_ds_method_data_get_node (AML_ARG_OP, obj_desc->reference.offset,
  465. walk_state, (struct acpi_namespace_node **) &obj_desc->reference.object);
  466. #endif
  467. break;
  468. default: /* Other literals, etc.. */
  469. if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
  470. /* Node was saved in Op */
  471. obj_desc->reference.node = op->common.node;
  472. }
  473. obj_desc->reference.opcode = opcode;
  474. break;
  475. }
  476. break;
  477. default:
  478. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unimplemented data type: %X\n",
  479. ACPI_GET_OBJECT_TYPE (obj_desc)));
  480. status = AE_AML_OPERAND_TYPE;
  481. break;
  482. }
  483. return_ACPI_STATUS (status);
  484. }