excreate.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. /******************************************************************************
  2. *
  3. * Module Name: excreate - Named object creation
  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 "acinterp.h"
  45. #include "amlcode.h"
  46. #include "acnamesp.h"
  47. #define _COMPONENT ACPI_EXECUTER
  48. ACPI_MODULE_NAME("excreate")
  49. #ifndef ACPI_NO_METHOD_EXECUTION
  50. /*******************************************************************************
  51. *
  52. * FUNCTION: acpi_ex_create_alias
  53. *
  54. * PARAMETERS: walk_state - Current state, contains operands
  55. *
  56. * RETURN: Status
  57. *
  58. * DESCRIPTION: Create a new named alias
  59. *
  60. ******************************************************************************/
  61. acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state)
  62. {
  63. struct acpi_namespace_node *target_node;
  64. struct acpi_namespace_node *alias_node;
  65. acpi_status status = AE_OK;
  66. ACPI_FUNCTION_TRACE(ex_create_alias);
  67. /* Get the source/alias operands (both namespace nodes) */
  68. alias_node = (struct acpi_namespace_node *)walk_state->operands[0];
  69. target_node = (struct acpi_namespace_node *)walk_state->operands[1];
  70. if ((target_node->type == ACPI_TYPE_LOCAL_ALIAS) ||
  71. (target_node->type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
  72. /*
  73. * Dereference an existing alias so that we don't create a chain
  74. * of aliases. With this code, we guarantee that an alias is
  75. * always exactly one level of indirection away from the
  76. * actual aliased name.
  77. */
  78. target_node =
  79. ACPI_CAST_PTR(struct acpi_namespace_node,
  80. target_node->object);
  81. }
  82. /*
  83. * For objects that can never change (i.e., the NS node will
  84. * permanently point to the same object), we can simply attach
  85. * the object to the new NS node. For other objects (such as
  86. * Integers, buffers, etc.), we have to point the Alias node
  87. * to the original Node.
  88. */
  89. switch (target_node->type) {
  90. /* For these types, the sub-object can change dynamically via a Store */
  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. * These types open a new scope, so we need the NS node in order to access
  98. * any children.
  99. */
  100. case ACPI_TYPE_DEVICE:
  101. case ACPI_TYPE_POWER:
  102. case ACPI_TYPE_PROCESSOR:
  103. case ACPI_TYPE_THERMAL:
  104. case ACPI_TYPE_LOCAL_SCOPE:
  105. /*
  106. * The new alias has the type ALIAS and points to the original
  107. * NS node, not the object itself.
  108. */
  109. alias_node->type = ACPI_TYPE_LOCAL_ALIAS;
  110. alias_node->object =
  111. ACPI_CAST_PTR(union acpi_operand_object, target_node);
  112. break;
  113. case ACPI_TYPE_METHOD:
  114. /*
  115. * Control method aliases need to be differentiated
  116. */
  117. alias_node->type = ACPI_TYPE_LOCAL_METHOD_ALIAS;
  118. alias_node->object =
  119. ACPI_CAST_PTR(union acpi_operand_object, target_node);
  120. break;
  121. default:
  122. /* Attach the original source object to the new Alias Node */
  123. /*
  124. * The new alias assumes the type of the target, and it points
  125. * to the same object. The reference count of the object has an
  126. * additional reference to prevent deletion out from under either the
  127. * target node or the alias Node
  128. */
  129. status = acpi_ns_attach_object(alias_node,
  130. acpi_ns_get_attached_object
  131. (target_node),
  132. target_node->type);
  133. break;
  134. }
  135. /* Since both operands are Nodes, we don't need to delete them */
  136. return_ACPI_STATUS(status);
  137. }
  138. /*******************************************************************************
  139. *
  140. * FUNCTION: acpi_ex_create_event
  141. *
  142. * PARAMETERS: walk_state - Current state
  143. *
  144. * RETURN: Status
  145. *
  146. * DESCRIPTION: Create a new event object
  147. *
  148. ******************************************************************************/
  149. acpi_status acpi_ex_create_event(struct acpi_walk_state *walk_state)
  150. {
  151. acpi_status status;
  152. union acpi_operand_object *obj_desc;
  153. ACPI_FUNCTION_TRACE(ex_create_event);
  154. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_EVENT);
  155. if (!obj_desc) {
  156. status = AE_NO_MEMORY;
  157. goto cleanup;
  158. }
  159. /*
  160. * Create the actual OS semaphore, with zero initial units -- meaning
  161. * that the event is created in an unsignalled state
  162. */
  163. status = acpi_os_create_semaphore(ACPI_NO_UNIT_LIMIT, 0,
  164. &obj_desc->event.os_semaphore);
  165. if (ACPI_FAILURE(status)) {
  166. goto cleanup;
  167. }
  168. /* Attach object to the Node */
  169. status =
  170. acpi_ns_attach_object((struct acpi_namespace_node *)walk_state->
  171. operands[0], obj_desc, ACPI_TYPE_EVENT);
  172. cleanup:
  173. /*
  174. * Remove local reference to the object (on error, will cause deletion
  175. * of both object and semaphore if present.)
  176. */
  177. acpi_ut_remove_reference(obj_desc);
  178. return_ACPI_STATUS(status);
  179. }
  180. /*******************************************************************************
  181. *
  182. * FUNCTION: acpi_ex_create_mutex
  183. *
  184. * PARAMETERS: walk_state - Current state
  185. *
  186. * RETURN: Status
  187. *
  188. * DESCRIPTION: Create a new mutex object
  189. *
  190. * Mutex (Name[0], sync_level[1])
  191. *
  192. ******************************************************************************/
  193. acpi_status acpi_ex_create_mutex(struct acpi_walk_state *walk_state)
  194. {
  195. acpi_status status = AE_OK;
  196. union acpi_operand_object *obj_desc;
  197. ACPI_FUNCTION_TRACE_PTR(ex_create_mutex, ACPI_WALK_OPERANDS);
  198. /* Create the new mutex object */
  199. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_MUTEX);
  200. if (!obj_desc) {
  201. status = AE_NO_MEMORY;
  202. goto cleanup;
  203. }
  204. /* Create the actual OS Mutex */
  205. status = acpi_os_create_mutex(&obj_desc->mutex.os_mutex);
  206. if (ACPI_FAILURE(status)) {
  207. goto cleanup;
  208. }
  209. /* Init object and attach to NS node */
  210. obj_desc->mutex.sync_level = (u8)walk_state->operands[1]->integer.value;
  211. obj_desc->mutex.node =
  212. (struct acpi_namespace_node *)walk_state->operands[0];
  213. status =
  214. acpi_ns_attach_object(obj_desc->mutex.node, obj_desc,
  215. ACPI_TYPE_MUTEX);
  216. cleanup:
  217. /*
  218. * Remove local reference to the object (on error, will cause deletion
  219. * of both object and semaphore if present.)
  220. */
  221. acpi_ut_remove_reference(obj_desc);
  222. return_ACPI_STATUS(status);
  223. }
  224. /*******************************************************************************
  225. *
  226. * FUNCTION: acpi_ex_create_region
  227. *
  228. * PARAMETERS: aml_start - Pointer to the region declaration AML
  229. * aml_length - Max length of the declaration AML
  230. * space_id - Address space ID for the region
  231. * walk_state - Current state
  232. *
  233. * RETURN: Status
  234. *
  235. * DESCRIPTION: Create a new operation region object
  236. *
  237. ******************************************************************************/
  238. acpi_status
  239. acpi_ex_create_region(u8 * aml_start,
  240. u32 aml_length,
  241. u8 space_id, struct acpi_walk_state *walk_state)
  242. {
  243. acpi_status status;
  244. union acpi_operand_object *obj_desc;
  245. struct acpi_namespace_node *node;
  246. union acpi_operand_object *region_obj2;
  247. ACPI_FUNCTION_TRACE(ex_create_region);
  248. /* Get the Namespace Node */
  249. node = walk_state->op->common.node;
  250. /*
  251. * If the region object is already attached to this node,
  252. * just return
  253. */
  254. if (acpi_ns_get_attached_object(node)) {
  255. return_ACPI_STATUS(AE_OK);
  256. }
  257. /*
  258. * Space ID must be one of the predefined IDs, or in the user-defined
  259. * range
  260. */
  261. if (!acpi_is_valid_space_id(space_id)) {
  262. /*
  263. * Print an error message, but continue. We don't want to abort
  264. * a table load for this exception. Instead, if the region is
  265. * actually used at runtime, abort the executing method.
  266. */
  267. ACPI_ERROR((AE_INFO,
  268. "Invalid/unknown Address Space ID: 0x%2.2X",
  269. space_id));
  270. }
  271. ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "Region Type - %s (0x%X)\n",
  272. acpi_ut_get_region_name(space_id), space_id));
  273. /* Create the region descriptor */
  274. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_REGION);
  275. if (!obj_desc) {
  276. status = AE_NO_MEMORY;
  277. goto cleanup;
  278. }
  279. /*
  280. * Remember location in AML stream of address & length
  281. * operands since they need to be evaluated at run time.
  282. */
  283. region_obj2 = obj_desc->common.next_object;
  284. region_obj2->extra.aml_start = aml_start;
  285. region_obj2->extra.aml_length = aml_length;
  286. if (walk_state->scope_info) {
  287. region_obj2->extra.scope_node =
  288. walk_state->scope_info->scope.node;
  289. } else {
  290. region_obj2->extra.scope_node = node;
  291. }
  292. /* Init the region from the operands */
  293. obj_desc->region.space_id = space_id;
  294. obj_desc->region.address = 0;
  295. obj_desc->region.length = 0;
  296. obj_desc->region.node = node;
  297. /* Install the new region object in the parent Node */
  298. status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_REGION);
  299. cleanup:
  300. /* Remove local reference to the object */
  301. acpi_ut_remove_reference(obj_desc);
  302. return_ACPI_STATUS(status);
  303. }
  304. /*******************************************************************************
  305. *
  306. * FUNCTION: acpi_ex_create_processor
  307. *
  308. * PARAMETERS: walk_state - Current state
  309. *
  310. * RETURN: Status
  311. *
  312. * DESCRIPTION: Create a new processor object and populate the fields
  313. *
  314. * Processor (Name[0], cpu_ID[1], pblock_addr[2], pblock_length[3])
  315. *
  316. ******************************************************************************/
  317. acpi_status acpi_ex_create_processor(struct acpi_walk_state *walk_state)
  318. {
  319. union acpi_operand_object **operand = &walk_state->operands[0];
  320. union acpi_operand_object *obj_desc;
  321. acpi_status status;
  322. ACPI_FUNCTION_TRACE_PTR(ex_create_processor, walk_state);
  323. /* Create the processor object */
  324. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PROCESSOR);
  325. if (!obj_desc) {
  326. return_ACPI_STATUS(AE_NO_MEMORY);
  327. }
  328. /* Initialize the processor object from the operands */
  329. obj_desc->processor.proc_id = (u8) operand[1]->integer.value;
  330. obj_desc->processor.length = (u8) operand[3]->integer.value;
  331. obj_desc->processor.address =
  332. (acpi_io_address) operand[2]->integer.value;
  333. /* Install the processor object in the parent Node */
  334. status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0],
  335. obj_desc, ACPI_TYPE_PROCESSOR);
  336. /* Remove local reference to the object */
  337. acpi_ut_remove_reference(obj_desc);
  338. return_ACPI_STATUS(status);
  339. }
  340. /*******************************************************************************
  341. *
  342. * FUNCTION: acpi_ex_create_power_resource
  343. *
  344. * PARAMETERS: walk_state - Current state
  345. *
  346. * RETURN: Status
  347. *
  348. * DESCRIPTION: Create a new power_resource object and populate the fields
  349. *
  350. * power_resource (Name[0], system_level[1], resource_order[2])
  351. *
  352. ******************************************************************************/
  353. acpi_status acpi_ex_create_power_resource(struct acpi_walk_state *walk_state)
  354. {
  355. union acpi_operand_object **operand = &walk_state->operands[0];
  356. acpi_status status;
  357. union acpi_operand_object *obj_desc;
  358. ACPI_FUNCTION_TRACE_PTR(ex_create_power_resource, walk_state);
  359. /* Create the power resource object */
  360. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_POWER);
  361. if (!obj_desc) {
  362. return_ACPI_STATUS(AE_NO_MEMORY);
  363. }
  364. /* Initialize the power object from the operands */
  365. obj_desc->power_resource.system_level = (u8) operand[1]->integer.value;
  366. obj_desc->power_resource.resource_order =
  367. (u16) operand[2]->integer.value;
  368. /* Install the power resource object in the parent Node */
  369. status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0],
  370. obj_desc, ACPI_TYPE_POWER);
  371. /* Remove local reference to the object */
  372. acpi_ut_remove_reference(obj_desc);
  373. return_ACPI_STATUS(status);
  374. }
  375. #endif
  376. /*******************************************************************************
  377. *
  378. * FUNCTION: acpi_ex_create_method
  379. *
  380. * PARAMETERS: aml_start - First byte of the method's AML
  381. * aml_length - AML byte count for this method
  382. * walk_state - Current state
  383. *
  384. * RETURN: Status
  385. *
  386. * DESCRIPTION: Create a new method object
  387. *
  388. ******************************************************************************/
  389. acpi_status
  390. acpi_ex_create_method(u8 * aml_start,
  391. u32 aml_length, struct acpi_walk_state *walk_state)
  392. {
  393. union acpi_operand_object **operand = &walk_state->operands[0];
  394. union acpi_operand_object *obj_desc;
  395. acpi_status status;
  396. u8 method_flags;
  397. ACPI_FUNCTION_TRACE_PTR(ex_create_method, walk_state);
  398. /* Create a new method object */
  399. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
  400. if (!obj_desc) {
  401. status = AE_NO_MEMORY;
  402. goto exit;
  403. }
  404. /* Save the method's AML pointer and length */
  405. obj_desc->method.aml_start = aml_start;
  406. obj_desc->method.aml_length = aml_length;
  407. obj_desc->method.node = operand[0];
  408. /*
  409. * Disassemble the method flags. Split off the arg_count, Serialized
  410. * flag, and sync_level for efficiency.
  411. */
  412. method_flags = (u8) operand[1]->integer.value;
  413. obj_desc->method.param_count =
  414. (u8) (method_flags & AML_METHOD_ARG_COUNT);
  415. /*
  416. * Get the sync_level. If method is serialized, a mutex will be
  417. * created for this method when it is parsed.
  418. */
  419. if (method_flags & AML_METHOD_SERIALIZED) {
  420. obj_desc->method.info_flags = ACPI_METHOD_SERIALIZED;
  421. /*
  422. * ACPI 1.0: sync_level = 0
  423. * ACPI 2.0: sync_level = sync_level in method declaration
  424. */
  425. obj_desc->method.sync_level = (u8)
  426. ((method_flags & AML_METHOD_SYNC_LEVEL) >> 4);
  427. }
  428. /* Attach the new object to the method Node */
  429. status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0],
  430. obj_desc, ACPI_TYPE_METHOD);
  431. /* Remove local reference to the object */
  432. acpi_ut_remove_reference(obj_desc);
  433. exit:
  434. /* Remove a reference to the operand */
  435. acpi_ut_remove_reference(operand[1]);
  436. return_ACPI_STATUS(status);
  437. }