excreate.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: excreate - Named object creation
  5. *
  6. * Copyright (C) 2000 - 2018, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #include "acinterp.h"
  12. #include "amlcode.h"
  13. #include "acnamesp.h"
  14. #define _COMPONENT ACPI_EXECUTER
  15. ACPI_MODULE_NAME("excreate")
  16. #ifndef ACPI_NO_METHOD_EXECUTION
  17. /*******************************************************************************
  18. *
  19. * FUNCTION: acpi_ex_create_alias
  20. *
  21. * PARAMETERS: walk_state - Current state, contains operands
  22. *
  23. * RETURN: Status
  24. *
  25. * DESCRIPTION: Create a new named alias
  26. *
  27. ******************************************************************************/
  28. acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state)
  29. {
  30. struct acpi_namespace_node *target_node;
  31. struct acpi_namespace_node *alias_node;
  32. acpi_status status = AE_OK;
  33. ACPI_FUNCTION_TRACE(ex_create_alias);
  34. /* Get the source/alias operands (both namespace nodes) */
  35. alias_node = (struct acpi_namespace_node *)walk_state->operands[0];
  36. target_node = (struct acpi_namespace_node *)walk_state->operands[1];
  37. if ((target_node->type == ACPI_TYPE_LOCAL_ALIAS) ||
  38. (target_node->type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
  39. /*
  40. * Dereference an existing alias so that we don't create a chain
  41. * of aliases. With this code, we guarantee that an alias is
  42. * always exactly one level of indirection away from the
  43. * actual aliased name.
  44. */
  45. target_node =
  46. ACPI_CAST_PTR(struct acpi_namespace_node,
  47. target_node->object);
  48. }
  49. /* Ensure that the target node is valid */
  50. if (!target_node) {
  51. return_ACPI_STATUS(AE_NULL_OBJECT);
  52. }
  53. /* Construct the alias object (a namespace node) */
  54. switch (target_node->type) {
  55. case ACPI_TYPE_METHOD:
  56. /*
  57. * Control method aliases need to be differentiated with
  58. * a special type
  59. */
  60. alias_node->type = ACPI_TYPE_LOCAL_METHOD_ALIAS;
  61. break;
  62. default:
  63. /*
  64. * All other object types.
  65. *
  66. * The new alias has the type ALIAS and points to the original
  67. * NS node, not the object itself.
  68. */
  69. alias_node->type = ACPI_TYPE_LOCAL_ALIAS;
  70. alias_node->object =
  71. ACPI_CAST_PTR(union acpi_operand_object, target_node);
  72. break;
  73. }
  74. /* Since both operands are Nodes, we don't need to delete them */
  75. alias_node->object =
  76. ACPI_CAST_PTR(union acpi_operand_object, target_node);
  77. return_ACPI_STATUS(status);
  78. }
  79. /*******************************************************************************
  80. *
  81. * FUNCTION: acpi_ex_create_event
  82. *
  83. * PARAMETERS: walk_state - Current state
  84. *
  85. * RETURN: Status
  86. *
  87. * DESCRIPTION: Create a new event object
  88. *
  89. ******************************************************************************/
  90. acpi_status acpi_ex_create_event(struct acpi_walk_state *walk_state)
  91. {
  92. acpi_status status;
  93. union acpi_operand_object *obj_desc;
  94. ACPI_FUNCTION_TRACE(ex_create_event);
  95. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_EVENT);
  96. if (!obj_desc) {
  97. status = AE_NO_MEMORY;
  98. goto cleanup;
  99. }
  100. /*
  101. * Create the actual OS semaphore, with zero initial units -- meaning
  102. * that the event is created in an unsignalled state
  103. */
  104. status = acpi_os_create_semaphore(ACPI_NO_UNIT_LIMIT, 0,
  105. &obj_desc->event.os_semaphore);
  106. if (ACPI_FAILURE(status)) {
  107. goto cleanup;
  108. }
  109. /* Attach object to the Node */
  110. status = acpi_ns_attach_object((struct acpi_namespace_node *)
  111. walk_state->operands[0], obj_desc,
  112. ACPI_TYPE_EVENT);
  113. cleanup:
  114. /*
  115. * Remove local reference to the object (on error, will cause deletion
  116. * of both object and semaphore if present.)
  117. */
  118. acpi_ut_remove_reference(obj_desc);
  119. return_ACPI_STATUS(status);
  120. }
  121. /*******************************************************************************
  122. *
  123. * FUNCTION: acpi_ex_create_mutex
  124. *
  125. * PARAMETERS: walk_state - Current state
  126. *
  127. * RETURN: Status
  128. *
  129. * DESCRIPTION: Create a new mutex object
  130. *
  131. * Mutex (Name[0], sync_level[1])
  132. *
  133. ******************************************************************************/
  134. acpi_status acpi_ex_create_mutex(struct acpi_walk_state *walk_state)
  135. {
  136. acpi_status status = AE_OK;
  137. union acpi_operand_object *obj_desc;
  138. ACPI_FUNCTION_TRACE_PTR(ex_create_mutex, ACPI_WALK_OPERANDS);
  139. /* Create the new mutex object */
  140. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_MUTEX);
  141. if (!obj_desc) {
  142. status = AE_NO_MEMORY;
  143. goto cleanup;
  144. }
  145. /* Create the actual OS Mutex */
  146. status = acpi_os_create_mutex(&obj_desc->mutex.os_mutex);
  147. if (ACPI_FAILURE(status)) {
  148. goto cleanup;
  149. }
  150. /* Init object and attach to NS node */
  151. obj_desc->mutex.sync_level = (u8)walk_state->operands[1]->integer.value;
  152. obj_desc->mutex.node =
  153. (struct acpi_namespace_node *)walk_state->operands[0];
  154. status =
  155. acpi_ns_attach_object(obj_desc->mutex.node, obj_desc,
  156. ACPI_TYPE_MUTEX);
  157. cleanup:
  158. /*
  159. * Remove local reference to the object (on error, will cause deletion
  160. * of both object and semaphore if present.)
  161. */
  162. acpi_ut_remove_reference(obj_desc);
  163. return_ACPI_STATUS(status);
  164. }
  165. /*******************************************************************************
  166. *
  167. * FUNCTION: acpi_ex_create_region
  168. *
  169. * PARAMETERS: aml_start - Pointer to the region declaration AML
  170. * aml_length - Max length of the declaration AML
  171. * space_id - Address space ID for the region
  172. * walk_state - Current state
  173. *
  174. * RETURN: Status
  175. *
  176. * DESCRIPTION: Create a new operation region object
  177. *
  178. ******************************************************************************/
  179. acpi_status
  180. acpi_ex_create_region(u8 * aml_start,
  181. u32 aml_length,
  182. u8 space_id, struct acpi_walk_state *walk_state)
  183. {
  184. acpi_status status;
  185. union acpi_operand_object *obj_desc;
  186. struct acpi_namespace_node *node;
  187. union acpi_operand_object *region_obj2;
  188. ACPI_FUNCTION_TRACE(ex_create_region);
  189. /* Get the Namespace Node */
  190. node = walk_state->op->common.node;
  191. /*
  192. * If the region object is already attached to this node,
  193. * just return
  194. */
  195. if (acpi_ns_get_attached_object(node)) {
  196. return_ACPI_STATUS(AE_OK);
  197. }
  198. /*
  199. * Space ID must be one of the predefined IDs, or in the user-defined
  200. * range
  201. */
  202. if (!acpi_is_valid_space_id(space_id)) {
  203. /*
  204. * Print an error message, but continue. We don't want to abort
  205. * a table load for this exception. Instead, if the region is
  206. * actually used at runtime, abort the executing method.
  207. */
  208. ACPI_ERROR((AE_INFO,
  209. "Invalid/unknown Address Space ID: 0x%2.2X",
  210. space_id));
  211. }
  212. ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "Region Type - %s (0x%X)\n",
  213. acpi_ut_get_region_name(space_id), space_id));
  214. /* Create the region descriptor */
  215. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_REGION);
  216. if (!obj_desc) {
  217. status = AE_NO_MEMORY;
  218. goto cleanup;
  219. }
  220. /*
  221. * Remember location in AML stream of address & length
  222. * operands since they need to be evaluated at run time.
  223. */
  224. region_obj2 = acpi_ns_get_secondary_object(obj_desc);
  225. region_obj2->extra.aml_start = aml_start;
  226. region_obj2->extra.aml_length = aml_length;
  227. region_obj2->extra.method_REG = NULL;
  228. if (walk_state->scope_info) {
  229. region_obj2->extra.scope_node =
  230. walk_state->scope_info->scope.node;
  231. } else {
  232. region_obj2->extra.scope_node = node;
  233. }
  234. /* Init the region from the operands */
  235. obj_desc->region.space_id = space_id;
  236. obj_desc->region.address = 0;
  237. obj_desc->region.length = 0;
  238. obj_desc->region.node = node;
  239. obj_desc->region.handler = NULL;
  240. obj_desc->common.flags &=
  241. ~(AOPOBJ_SETUP_COMPLETE | AOPOBJ_REG_CONNECTED |
  242. AOPOBJ_OBJECT_INITIALIZED);
  243. /* Install the new region object in the parent Node */
  244. status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_REGION);
  245. cleanup:
  246. /* Remove local reference to the object */
  247. acpi_ut_remove_reference(obj_desc);
  248. return_ACPI_STATUS(status);
  249. }
  250. /*******************************************************************************
  251. *
  252. * FUNCTION: acpi_ex_create_processor
  253. *
  254. * PARAMETERS: walk_state - Current state
  255. *
  256. * RETURN: Status
  257. *
  258. * DESCRIPTION: Create a new processor object and populate the fields
  259. *
  260. * Processor (Name[0], cpu_ID[1], pblock_addr[2], pblock_length[3])
  261. *
  262. ******************************************************************************/
  263. acpi_status acpi_ex_create_processor(struct acpi_walk_state *walk_state)
  264. {
  265. union acpi_operand_object **operand = &walk_state->operands[0];
  266. union acpi_operand_object *obj_desc;
  267. acpi_status status;
  268. ACPI_FUNCTION_TRACE_PTR(ex_create_processor, walk_state);
  269. /* Create the processor object */
  270. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PROCESSOR);
  271. if (!obj_desc) {
  272. return_ACPI_STATUS(AE_NO_MEMORY);
  273. }
  274. /* Initialize the processor object from the operands */
  275. obj_desc->processor.proc_id = (u8) operand[1]->integer.value;
  276. obj_desc->processor.length = (u8) operand[3]->integer.value;
  277. obj_desc->processor.address =
  278. (acpi_io_address)operand[2]->integer.value;
  279. /* Install the processor object in the parent Node */
  280. status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0],
  281. obj_desc, ACPI_TYPE_PROCESSOR);
  282. /* Remove local reference to the object */
  283. acpi_ut_remove_reference(obj_desc);
  284. return_ACPI_STATUS(status);
  285. }
  286. /*******************************************************************************
  287. *
  288. * FUNCTION: acpi_ex_create_power_resource
  289. *
  290. * PARAMETERS: walk_state - Current state
  291. *
  292. * RETURN: Status
  293. *
  294. * DESCRIPTION: Create a new power_resource object and populate the fields
  295. *
  296. * power_resource (Name[0], system_level[1], resource_order[2])
  297. *
  298. ******************************************************************************/
  299. acpi_status acpi_ex_create_power_resource(struct acpi_walk_state *walk_state)
  300. {
  301. union acpi_operand_object **operand = &walk_state->operands[0];
  302. acpi_status status;
  303. union acpi_operand_object *obj_desc;
  304. ACPI_FUNCTION_TRACE_PTR(ex_create_power_resource, walk_state);
  305. /* Create the power resource object */
  306. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_POWER);
  307. if (!obj_desc) {
  308. return_ACPI_STATUS(AE_NO_MEMORY);
  309. }
  310. /* Initialize the power object from the operands */
  311. obj_desc->power_resource.system_level = (u8) operand[1]->integer.value;
  312. obj_desc->power_resource.resource_order =
  313. (u16) operand[2]->integer.value;
  314. /* Install the power resource object in the parent Node */
  315. status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0],
  316. obj_desc, ACPI_TYPE_POWER);
  317. /* Remove local reference to the object */
  318. acpi_ut_remove_reference(obj_desc);
  319. return_ACPI_STATUS(status);
  320. }
  321. #endif
  322. /*******************************************************************************
  323. *
  324. * FUNCTION: acpi_ex_create_method
  325. *
  326. * PARAMETERS: aml_start - First byte of the method's AML
  327. * aml_length - AML byte count for this method
  328. * walk_state - Current state
  329. *
  330. * RETURN: Status
  331. *
  332. * DESCRIPTION: Create a new method object
  333. *
  334. ******************************************************************************/
  335. acpi_status
  336. acpi_ex_create_method(u8 * aml_start,
  337. u32 aml_length, struct acpi_walk_state *walk_state)
  338. {
  339. union acpi_operand_object **operand = &walk_state->operands[0];
  340. union acpi_operand_object *obj_desc;
  341. acpi_status status;
  342. u8 method_flags;
  343. ACPI_FUNCTION_TRACE_PTR(ex_create_method, walk_state);
  344. /* Create a new method object */
  345. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
  346. if (!obj_desc) {
  347. status = AE_NO_MEMORY;
  348. goto exit;
  349. }
  350. /* Save the method's AML pointer and length */
  351. obj_desc->method.aml_start = aml_start;
  352. obj_desc->method.aml_length = aml_length;
  353. obj_desc->method.node = operand[0];
  354. /*
  355. * Disassemble the method flags. Split off the arg_count, Serialized
  356. * flag, and sync_level for efficiency.
  357. */
  358. method_flags = (u8)operand[1]->integer.value;
  359. obj_desc->method.param_count = (u8)
  360. (method_flags & AML_METHOD_ARG_COUNT);
  361. /*
  362. * Get the sync_level. If method is serialized, a mutex will be
  363. * created for this method when it is parsed.
  364. */
  365. if (method_flags & AML_METHOD_SERIALIZED) {
  366. obj_desc->method.info_flags = ACPI_METHOD_SERIALIZED;
  367. /*
  368. * ACPI 1.0: sync_level = 0
  369. * ACPI 2.0: sync_level = sync_level in method declaration
  370. */
  371. obj_desc->method.sync_level = (u8)
  372. ((method_flags & AML_METHOD_SYNC_LEVEL) >> 4);
  373. }
  374. /* Attach the new object to the method Node */
  375. status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0],
  376. obj_desc, ACPI_TYPE_METHOD);
  377. /* Remove local reference to the object */
  378. acpi_ut_remove_reference(obj_desc);
  379. exit:
  380. /* Remove a reference to the operand */
  381. acpi_ut_remove_reference(operand[1]);
  382. return_ACPI_STATUS(status);
  383. }