excreate.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /******************************************************************************
  2. *
  3. * Module Name: excreate - Named object creation
  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/acinterp.h>
  44. #include <acpi/amlcode.h>
  45. #include <acpi/acnamesp.h>
  46. #include <acpi/acevents.h>
  47. #include <acpi/actables.h>
  48. #define _COMPONENT ACPI_EXECUTER
  49. ACPI_MODULE_NAME ("excreate")
  50. #ifndef ACPI_NO_METHOD_EXECUTION
  51. /*****************************************************************************
  52. *
  53. * FUNCTION: acpi_ex_create_alias
  54. *
  55. * PARAMETERS: walk_state - Current state, contains operands
  56. *
  57. * RETURN: Status
  58. *
  59. * DESCRIPTION: Create a new named alias
  60. *
  61. ****************************************************************************/
  62. acpi_status
  63. acpi_ex_create_alias (
  64. struct acpi_walk_state *walk_state)
  65. {
  66. struct acpi_namespace_node *target_node;
  67. struct acpi_namespace_node *alias_node;
  68. acpi_status status = AE_OK;
  69. ACPI_FUNCTION_TRACE ("ex_create_alias");
  70. /* Get the source/alias operands (both namespace nodes) */
  71. alias_node = (struct acpi_namespace_node *) walk_state->operands[0];
  72. target_node = (struct acpi_namespace_node *) walk_state->operands[1];
  73. if ((target_node->type == ACPI_TYPE_LOCAL_ALIAS) ||
  74. (target_node->type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
  75. /*
  76. * Dereference an existing alias so that we don't create a chain
  77. * of aliases. With this code, we guarantee that an alias is
  78. * always exactly one level of indirection away from the
  79. * actual aliased name.
  80. */
  81. target_node = ACPI_CAST_PTR (struct acpi_namespace_node, target_node->object);
  82. }
  83. /*
  84. * For objects that can never change (i.e., the NS node will
  85. * permanently point to the same object), we can simply attach
  86. * the object to the new NS node. For other objects (such as
  87. * Integers, buffers, etc.), we have to point the Alias node
  88. * to the original Node.
  89. */
  90. switch (target_node->type) {
  91. case ACPI_TYPE_INTEGER:
  92. case ACPI_TYPE_STRING:
  93. case ACPI_TYPE_BUFFER:
  94. case ACPI_TYPE_PACKAGE:
  95. case ACPI_TYPE_BUFFER_FIELD:
  96. /*
  97. * The new alias has the type ALIAS and points to the original
  98. * NS node, not the object itself. This is because for these
  99. * types, the object can change dynamically via a Store.
  100. */
  101. alias_node->type = ACPI_TYPE_LOCAL_ALIAS;
  102. alias_node->object = ACPI_CAST_PTR (union acpi_operand_object, target_node);
  103. break;
  104. case ACPI_TYPE_METHOD:
  105. /*
  106. * The new alias has the type ALIAS and points to the original
  107. * NS node, not the object itself. This is because for these
  108. * types, the object can change dynamically via a Store.
  109. */
  110. alias_node->type = ACPI_TYPE_LOCAL_METHOD_ALIAS;
  111. alias_node->object = ACPI_CAST_PTR (union acpi_operand_object, target_node);
  112. break;
  113. default:
  114. /* Attach the original source object to the new Alias Node */
  115. /*
  116. * The new alias assumes the type of the target, and it points
  117. * to the same object. The reference count of the object has an
  118. * additional reference to prevent deletion out from under either the
  119. * target node or the alias Node
  120. */
  121. status = acpi_ns_attach_object (alias_node,
  122. acpi_ns_get_attached_object (target_node),
  123. target_node->type);
  124. break;
  125. }
  126. /* Since both operands are Nodes, we don't need to delete them */
  127. return_ACPI_STATUS (status);
  128. }
  129. /*****************************************************************************
  130. *
  131. * FUNCTION: acpi_ex_create_event
  132. *
  133. * PARAMETERS: walk_state - Current state
  134. *
  135. * RETURN: Status
  136. *
  137. * DESCRIPTION: Create a new event object
  138. *
  139. ****************************************************************************/
  140. acpi_status
  141. acpi_ex_create_event (
  142. struct acpi_walk_state *walk_state)
  143. {
  144. acpi_status status;
  145. union acpi_operand_object *obj_desc;
  146. ACPI_FUNCTION_TRACE ("ex_create_event");
  147. obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_EVENT);
  148. if (!obj_desc) {
  149. status = AE_NO_MEMORY;
  150. goto cleanup;
  151. }
  152. /*
  153. * Create the actual OS semaphore, with zero initial units -- meaning
  154. * that the event is created in an unsignalled state
  155. */
  156. status = acpi_os_create_semaphore (ACPI_NO_UNIT_LIMIT, 0,
  157. &obj_desc->event.semaphore);
  158. if (ACPI_FAILURE (status)) {
  159. goto cleanup;
  160. }
  161. /* Attach object to the Node */
  162. status = acpi_ns_attach_object ((struct acpi_namespace_node *) walk_state->operands[0],
  163. obj_desc, ACPI_TYPE_EVENT);
  164. cleanup:
  165. /*
  166. * Remove local reference to the object (on error, will cause deletion
  167. * of both object and semaphore if present.)
  168. */
  169. acpi_ut_remove_reference (obj_desc);
  170. return_ACPI_STATUS (status);
  171. }
  172. /*****************************************************************************
  173. *
  174. * FUNCTION: acpi_ex_create_mutex
  175. *
  176. * PARAMETERS: walk_state - Current state
  177. *
  178. * RETURN: Status
  179. *
  180. * DESCRIPTION: Create a new mutex object
  181. *
  182. * Mutex (Name[0], sync_level[1])
  183. *
  184. ****************************************************************************/
  185. acpi_status
  186. acpi_ex_create_mutex (
  187. struct acpi_walk_state *walk_state)
  188. {
  189. acpi_status status = AE_OK;
  190. union acpi_operand_object *obj_desc;
  191. ACPI_FUNCTION_TRACE_PTR ("ex_create_mutex", ACPI_WALK_OPERANDS);
  192. /* Create the new mutex object */
  193. obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_MUTEX);
  194. if (!obj_desc) {
  195. status = AE_NO_MEMORY;
  196. goto cleanup;
  197. }
  198. /*
  199. * Create the actual OS semaphore.
  200. * One unit max to make it a mutex, with one initial unit to allow
  201. * the mutex to be acquired.
  202. */
  203. status = acpi_os_create_semaphore (1, 1, &obj_desc->mutex.semaphore);
  204. if (ACPI_FAILURE (status)) {
  205. goto cleanup;
  206. }
  207. /* Init object and attach to NS node */
  208. obj_desc->mutex.sync_level = (u8) walk_state->operands[1]->integer.value;
  209. obj_desc->mutex.node = (struct acpi_namespace_node *) walk_state->operands[0];
  210. status = acpi_ns_attach_object (obj_desc->mutex.node,
  211. obj_desc, ACPI_TYPE_MUTEX);
  212. cleanup:
  213. /*
  214. * Remove local reference to the object (on error, will cause deletion
  215. * of both object and semaphore if present.)
  216. */
  217. acpi_ut_remove_reference (obj_desc);
  218. return_ACPI_STATUS (status);
  219. }
  220. /*****************************************************************************
  221. *
  222. * FUNCTION: acpi_ex_create_region
  223. *
  224. * PARAMETERS: aml_start - Pointer to the region declaration AML
  225. * aml_length - Max length of the declaration AML
  226. * Operands - List of operands for the opcode
  227. * walk_state - Current state
  228. *
  229. * RETURN: Status
  230. *
  231. * DESCRIPTION: Create a new operation region object
  232. *
  233. ****************************************************************************/
  234. acpi_status
  235. acpi_ex_create_region (
  236. u8 *aml_start,
  237. u32 aml_length,
  238. u8 region_space,
  239. struct acpi_walk_state *walk_state)
  240. {
  241. acpi_status status;
  242. union acpi_operand_object *obj_desc;
  243. struct acpi_namespace_node *node;
  244. union acpi_operand_object *region_obj2;
  245. ACPI_FUNCTION_TRACE ("ex_create_region");
  246. /* Get the Namespace Node */
  247. node = walk_state->op->common.node;
  248. /*
  249. * If the region object is already attached to this node,
  250. * just return
  251. */
  252. if (acpi_ns_get_attached_object (node)) {
  253. return_ACPI_STATUS (AE_OK);
  254. }
  255. /*
  256. * Space ID must be one of the predefined IDs, or in the user-defined
  257. * range
  258. */
  259. if ((region_space >= ACPI_NUM_PREDEFINED_REGIONS) &&
  260. (region_space < ACPI_USER_REGION_BEGIN)) {
  261. ACPI_REPORT_ERROR (("Invalid address_space type %X\n", region_space));
  262. return_ACPI_STATUS (AE_AML_INVALID_SPACE_ID);
  263. }
  264. ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Region Type - %s (%X)\n",
  265. acpi_ut_get_region_name (region_space), region_space));
  266. /* Create the region descriptor */
  267. obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_REGION);
  268. if (!obj_desc) {
  269. status = AE_NO_MEMORY;
  270. goto cleanup;
  271. }
  272. /*
  273. * Remember location in AML stream of address & length
  274. * operands since they need to be evaluated at run time.
  275. */
  276. region_obj2 = obj_desc->common.next_object;
  277. region_obj2->extra.aml_start = aml_start;
  278. region_obj2->extra.aml_length = aml_length;
  279. /* Init the region from the operands */
  280. obj_desc->region.space_id = region_space;
  281. obj_desc->region.address = 0;
  282. obj_desc->region.length = 0;
  283. obj_desc->region.node = node;
  284. /* Install the new region object in the parent Node */
  285. status = acpi_ns_attach_object (node, obj_desc, ACPI_TYPE_REGION);
  286. cleanup:
  287. /* Remove local reference to the object */
  288. acpi_ut_remove_reference (obj_desc);
  289. return_ACPI_STATUS (status);
  290. }
  291. /*****************************************************************************
  292. *
  293. * FUNCTION: acpi_ex_create_table_region
  294. *
  295. * PARAMETERS: walk_state - Current state
  296. *
  297. * RETURN: Status
  298. *
  299. * DESCRIPTION: Create a new data_table_region object
  300. *
  301. ****************************************************************************/
  302. acpi_status
  303. acpi_ex_create_table_region (
  304. struct acpi_walk_state *walk_state)
  305. {
  306. acpi_status status;
  307. union acpi_operand_object **operand = &walk_state->operands[0];
  308. union acpi_operand_object *obj_desc;
  309. struct acpi_namespace_node *node;
  310. struct acpi_table_header *table;
  311. union acpi_operand_object *region_obj2;
  312. ACPI_FUNCTION_TRACE ("ex_create_table_region");
  313. /* Get the Node from the object stack */
  314. node = walk_state->op->common.node;
  315. /*
  316. * If the region object is already attached to this node,
  317. * just return
  318. */
  319. if (acpi_ns_get_attached_object (node)) {
  320. return_ACPI_STATUS (AE_OK);
  321. }
  322. /* Find the ACPI table */
  323. status = acpi_tb_find_table (operand[1]->string.pointer,
  324. operand[2]->string.pointer,
  325. operand[3]->string.pointer, &table);
  326. if (ACPI_FAILURE (status)) {
  327. return_ACPI_STATUS (status);
  328. }
  329. /* Create the region descriptor */
  330. obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_REGION);
  331. if (!obj_desc) {
  332. return_ACPI_STATUS (AE_NO_MEMORY);
  333. }
  334. region_obj2 = obj_desc->common.next_object;
  335. region_obj2->extra.region_context = NULL;
  336. /* Init the region from the operands */
  337. obj_desc->region.space_id = REGION_DATA_TABLE;
  338. obj_desc->region.address = (acpi_physical_address) ACPI_TO_INTEGER (table);
  339. obj_desc->region.length = table->length;
  340. obj_desc->region.node = node;
  341. obj_desc->region.flags = AOPOBJ_DATA_VALID;
  342. /* Install the new region object in the parent Node */
  343. status = acpi_ns_attach_object (node, obj_desc, ACPI_TYPE_REGION);
  344. if (ACPI_FAILURE (status)) {
  345. goto cleanup;
  346. }
  347. status = acpi_ev_initialize_region (obj_desc, FALSE);
  348. if (ACPI_FAILURE (status)) {
  349. if (status == AE_NOT_EXIST) {
  350. status = AE_OK;
  351. }
  352. else {
  353. goto cleanup;
  354. }
  355. }
  356. obj_desc->region.flags |= AOPOBJ_SETUP_COMPLETE;
  357. cleanup:
  358. /* Remove local reference to the object */
  359. acpi_ut_remove_reference (obj_desc);
  360. return_ACPI_STATUS (status);
  361. }
  362. /*****************************************************************************
  363. *
  364. * FUNCTION: acpi_ex_create_processor
  365. *
  366. * PARAMETERS: walk_state - Current state
  367. *
  368. * RETURN: Status
  369. *
  370. * DESCRIPTION: Create a new processor object and populate the fields
  371. *
  372. * Processor (Name[0], cpu_iD[1], pblock_addr[2], pblock_length[3])
  373. *
  374. ****************************************************************************/
  375. acpi_status
  376. acpi_ex_create_processor (
  377. struct acpi_walk_state *walk_state)
  378. {
  379. union acpi_operand_object **operand = &walk_state->operands[0];
  380. union acpi_operand_object *obj_desc;
  381. acpi_status status;
  382. ACPI_FUNCTION_TRACE_PTR ("ex_create_processor", walk_state);
  383. /* Create the processor object */
  384. obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_PROCESSOR);
  385. if (!obj_desc) {
  386. return_ACPI_STATUS (AE_NO_MEMORY);
  387. }
  388. /*
  389. * Initialize the processor object from the operands
  390. */
  391. obj_desc->processor.proc_id = (u8) operand[1]->integer.value;
  392. obj_desc->processor.address = (acpi_io_address) operand[2]->integer.value;
  393. obj_desc->processor.length = (u8) operand[3]->integer.value;
  394. /* Install the processor object in the parent Node */
  395. status = acpi_ns_attach_object ((struct acpi_namespace_node *) operand[0],
  396. obj_desc, ACPI_TYPE_PROCESSOR);
  397. /* Remove local reference to the object */
  398. acpi_ut_remove_reference (obj_desc);
  399. return_ACPI_STATUS (status);
  400. }
  401. /*****************************************************************************
  402. *
  403. * FUNCTION: acpi_ex_create_power_resource
  404. *
  405. * PARAMETERS: walk_state - Current state
  406. *
  407. * RETURN: Status
  408. *
  409. * DESCRIPTION: Create a new power_resource object and populate the fields
  410. *
  411. * power_resource (Name[0], system_level[1], resource_order[2])
  412. *
  413. ****************************************************************************/
  414. acpi_status
  415. acpi_ex_create_power_resource (
  416. struct acpi_walk_state *walk_state)
  417. {
  418. union acpi_operand_object **operand = &walk_state->operands[0];
  419. acpi_status status;
  420. union acpi_operand_object *obj_desc;
  421. ACPI_FUNCTION_TRACE_PTR ("ex_create_power_resource", walk_state);
  422. /* Create the power resource object */
  423. obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_POWER);
  424. if (!obj_desc) {
  425. return_ACPI_STATUS (AE_NO_MEMORY);
  426. }
  427. /* Initialize the power object from the operands */
  428. obj_desc->power_resource.system_level = (u8) operand[1]->integer.value;
  429. obj_desc->power_resource.resource_order = (u16) operand[2]->integer.value;
  430. /* Install the power resource object in the parent Node */
  431. status = acpi_ns_attach_object ((struct acpi_namespace_node *) operand[0],
  432. obj_desc, ACPI_TYPE_POWER);
  433. /* Remove local reference to the object */
  434. acpi_ut_remove_reference (obj_desc);
  435. return_ACPI_STATUS (status);
  436. }
  437. #endif
  438. /*****************************************************************************
  439. *
  440. * FUNCTION: acpi_ex_create_method
  441. *
  442. * PARAMETERS: aml_start - First byte of the method's AML
  443. * aml_length - AML byte count for this method
  444. * walk_state - Current state
  445. *
  446. * RETURN: Status
  447. *
  448. * DESCRIPTION: Create a new method object
  449. *
  450. ****************************************************************************/
  451. acpi_status
  452. acpi_ex_create_method (
  453. u8 *aml_start,
  454. u32 aml_length,
  455. struct acpi_walk_state *walk_state)
  456. {
  457. union acpi_operand_object **operand = &walk_state->operands[0];
  458. union acpi_operand_object *obj_desc;
  459. acpi_status status;
  460. u8 method_flags;
  461. ACPI_FUNCTION_TRACE_PTR ("ex_create_method", walk_state);
  462. /* Create a new method object */
  463. obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_METHOD);
  464. if (!obj_desc) {
  465. return_ACPI_STATUS (AE_NO_MEMORY);
  466. }
  467. /* Save the method's AML pointer and length */
  468. obj_desc->method.aml_start = aml_start;
  469. obj_desc->method.aml_length = aml_length;
  470. /*
  471. * Disassemble the method flags. Split off the Arg Count
  472. * for efficiency
  473. */
  474. method_flags = (u8) operand[1]->integer.value;
  475. obj_desc->method.method_flags = (u8) (method_flags & ~AML_METHOD_ARG_COUNT);
  476. obj_desc->method.param_count = (u8) (method_flags & AML_METHOD_ARG_COUNT);
  477. /*
  478. * Get the concurrency count. If required, a semaphore will be
  479. * created for this method when it is parsed.
  480. */
  481. if (acpi_gbl_all_methods_serialized) {
  482. obj_desc->method.concurrency = 1;
  483. obj_desc->method.method_flags |= AML_METHOD_SERIALIZED;
  484. }
  485. else if (method_flags & AML_METHOD_SERIALIZED) {
  486. /*
  487. * ACPI 1.0: Concurrency = 1
  488. * ACPI 2.0: Concurrency = (sync_level (in method declaration) + 1)
  489. */
  490. obj_desc->method.concurrency = (u8)
  491. (((method_flags & AML_METHOD_SYNCH_LEVEL) >> 4) + 1);
  492. }
  493. else {
  494. obj_desc->method.concurrency = ACPI_INFINITE_CONCURRENCY;
  495. }
  496. /* Attach the new object to the method Node */
  497. status = acpi_ns_attach_object ((struct acpi_namespace_node *) operand[0],
  498. obj_desc, ACPI_TYPE_METHOD);
  499. /* Remove local reference to the object */
  500. acpi_ut_remove_reference (obj_desc);
  501. /* Remove a reference to the operand */
  502. acpi_ut_remove_reference (operand[1]);
  503. return_ACPI_STATUS (status);
  504. }