nsxfeval.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. /*******************************************************************************
  2. *
  3. * Module Name: nsxfeval - Public interfaces to the ACPI subsystem
  4. * ACPI Object evaluation interfaces
  5. *
  6. ******************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2008, Intel Corp.
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions, and the following disclaimer,
  16. * without modification.
  17. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18. * substantially similar to the "NO WARRANTY" disclaimer below
  19. * ("Disclaimer") and any redistribution must be conditioned upon
  20. * including a substantially similar Disclaimer requirement for further
  21. * binary redistribution.
  22. * 3. Neither the names of the above-listed copyright holders nor the names
  23. * of any contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * Alternatively, this software may be distributed under the terms of the
  27. * GNU General Public License ("GPL") version 2 as published by the Free
  28. * Software Foundation.
  29. *
  30. * NO WARRANTY
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  34. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  35. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  40. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. * POSSIBILITY OF SUCH DAMAGES.
  42. */
  43. #include <acpi/acpi.h>
  44. #include "accommon.h"
  45. #include "acnamesp.h"
  46. #include "acinterp.h"
  47. #define _COMPONENT ACPI_NAMESPACE
  48. ACPI_MODULE_NAME("nsxfeval")
  49. /* Local prototypes */
  50. static void acpi_ns_resolve_references(struct acpi_evaluate_info *info);
  51. #ifdef ACPI_FUTURE_USAGE
  52. /*******************************************************************************
  53. *
  54. * FUNCTION: acpi_evaluate_object_typed
  55. *
  56. * PARAMETERS: Handle - Object handle (optional)
  57. * Pathname - Object pathname (optional)
  58. * external_params - List of parameters to pass to method,
  59. * terminated by NULL. May be NULL
  60. * if no parameters are being passed.
  61. * return_buffer - Where to put method's return value (if
  62. * any). If NULL, no value is returned.
  63. * return_type - Expected type of return object
  64. *
  65. * RETURN: Status
  66. *
  67. * DESCRIPTION: Find and evaluate the given object, passing the given
  68. * parameters if necessary. One of "Handle" or "Pathname" must
  69. * be valid (non-null)
  70. *
  71. ******************************************************************************/
  72. acpi_status
  73. acpi_evaluate_object_typed(acpi_handle handle,
  74. acpi_string pathname,
  75. struct acpi_object_list *external_params,
  76. struct acpi_buffer *return_buffer,
  77. acpi_object_type return_type)
  78. {
  79. acpi_status status;
  80. u8 must_free = FALSE;
  81. ACPI_FUNCTION_TRACE(acpi_evaluate_object_typed);
  82. /* Return buffer must be valid */
  83. if (!return_buffer) {
  84. return_ACPI_STATUS(AE_BAD_PARAMETER);
  85. }
  86. if (return_buffer->length == ACPI_ALLOCATE_BUFFER) {
  87. must_free = TRUE;
  88. }
  89. /* Evaluate the object */
  90. status =
  91. acpi_evaluate_object(handle, pathname, external_params,
  92. return_buffer);
  93. if (ACPI_FAILURE(status)) {
  94. return_ACPI_STATUS(status);
  95. }
  96. /* Type ANY means "don't care" */
  97. if (return_type == ACPI_TYPE_ANY) {
  98. return_ACPI_STATUS(AE_OK);
  99. }
  100. if (return_buffer->length == 0) {
  101. /* Error because caller specifically asked for a return value */
  102. ACPI_ERROR((AE_INFO, "No return value"));
  103. return_ACPI_STATUS(AE_NULL_OBJECT);
  104. }
  105. /* Examine the object type returned from evaluate_object */
  106. if (((union acpi_object *)return_buffer->pointer)->type == return_type) {
  107. return_ACPI_STATUS(AE_OK);
  108. }
  109. /* Return object type does not match requested type */
  110. ACPI_ERROR((AE_INFO,
  111. "Incorrect return type [%s] requested [%s]",
  112. acpi_ut_get_type_name(((union acpi_object *)return_buffer->
  113. pointer)->type),
  114. acpi_ut_get_type_name(return_type)));
  115. if (must_free) {
  116. /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
  117. ACPI_FREE(return_buffer->pointer);
  118. return_buffer->pointer = NULL;
  119. }
  120. return_buffer->length = 0;
  121. return_ACPI_STATUS(AE_TYPE);
  122. }
  123. ACPI_EXPORT_SYMBOL(acpi_evaluate_object_typed)
  124. #endif /* ACPI_FUTURE_USAGE */
  125. /*******************************************************************************
  126. *
  127. * FUNCTION: acpi_evaluate_object
  128. *
  129. * PARAMETERS: Handle - Object handle (optional)
  130. * Pathname - Object pathname (optional)
  131. * external_params - List of parameters to pass to method,
  132. * terminated by NULL. May be NULL
  133. * if no parameters are being passed.
  134. * return_buffer - Where to put method's return value (if
  135. * any). If NULL, no value is returned.
  136. *
  137. * RETURN: Status
  138. *
  139. * DESCRIPTION: Find and evaluate the given object, passing the given
  140. * parameters if necessary. One of "Handle" or "Pathname" must
  141. * be valid (non-null)
  142. *
  143. ******************************************************************************/
  144. acpi_status
  145. acpi_evaluate_object(acpi_handle handle,
  146. acpi_string pathname,
  147. struct acpi_object_list *external_params,
  148. struct acpi_buffer *return_buffer)
  149. {
  150. acpi_status status;
  151. struct acpi_evaluate_info *info;
  152. acpi_size buffer_space_needed;
  153. u32 i;
  154. ACPI_FUNCTION_TRACE(acpi_evaluate_object);
  155. /* Allocate and initialize the evaluation information block */
  156. info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
  157. if (!info) {
  158. return_ACPI_STATUS(AE_NO_MEMORY);
  159. }
  160. info->pathname = pathname;
  161. /* Convert and validate the device handle */
  162. info->prefix_node = acpi_ns_map_handle_to_node(handle);
  163. if (!info->prefix_node) {
  164. status = AE_BAD_PARAMETER;
  165. goto cleanup;
  166. }
  167. /*
  168. * If there are parameters to be passed to a control method, the external
  169. * objects must all be converted to internal objects
  170. */
  171. if (external_params && external_params->count) {
  172. /*
  173. * Allocate a new parameter block for the internal objects
  174. * Add 1 to count to allow for null terminated internal list
  175. */
  176. info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size)
  177. external_params->
  178. count +
  179. 1) * sizeof(void *));
  180. if (!info->parameters) {
  181. status = AE_NO_MEMORY;
  182. goto cleanup;
  183. }
  184. /* Convert each external object in the list to an internal object */
  185. for (i = 0; i < external_params->count; i++) {
  186. status =
  187. acpi_ut_copy_eobject_to_iobject(&external_params->
  188. pointer[i],
  189. &info->
  190. parameters[i]);
  191. if (ACPI_FAILURE(status)) {
  192. goto cleanup;
  193. }
  194. }
  195. info->parameters[external_params->count] = NULL;
  196. }
  197. /*
  198. * Three major cases:
  199. * 1) Fully qualified pathname
  200. * 2) No handle, not fully qualified pathname (error)
  201. * 3) Valid handle
  202. */
  203. if ((pathname) && (acpi_ns_valid_root_prefix(pathname[0]))) {
  204. /* The path is fully qualified, just evaluate by name */
  205. info->prefix_node = NULL;
  206. status = acpi_ns_evaluate(info);
  207. } else if (!handle) {
  208. /*
  209. * A handle is optional iff a fully qualified pathname is specified.
  210. * Since we've already handled fully qualified names above, this is
  211. * an error
  212. */
  213. if (!pathname) {
  214. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  215. "Both Handle and Pathname are NULL"));
  216. } else {
  217. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  218. "Null Handle with relative pathname [%s]",
  219. pathname));
  220. }
  221. status = AE_BAD_PARAMETER;
  222. } else {
  223. /* We have a namespace a node and a possible relative path */
  224. status = acpi_ns_evaluate(info);
  225. }
  226. /*
  227. * If we are expecting a return value, and all went well above,
  228. * copy the return value to an external object.
  229. */
  230. if (return_buffer) {
  231. if (!info->return_object) {
  232. return_buffer->length = 0;
  233. } else {
  234. if (ACPI_GET_DESCRIPTOR_TYPE(info->return_object) ==
  235. ACPI_DESC_TYPE_NAMED) {
  236. /*
  237. * If we received a NS Node as a return object, this means that
  238. * the object we are evaluating has nothing interesting to
  239. * return (such as a mutex, etc.) We return an error because
  240. * these types are essentially unsupported by this interface.
  241. * We don't check up front because this makes it easier to add
  242. * support for various types at a later date if necessary.
  243. */
  244. status = AE_TYPE;
  245. info->return_object = NULL; /* No need to delete a NS Node */
  246. return_buffer->length = 0;
  247. }
  248. if (ACPI_SUCCESS(status)) {
  249. /* Dereference Index and ref_of references */
  250. acpi_ns_resolve_references(info);
  251. /* Get the size of the returned object */
  252. status =
  253. acpi_ut_get_object_size(info->return_object,
  254. &buffer_space_needed);
  255. if (ACPI_SUCCESS(status)) {
  256. /* Validate/Allocate/Clear caller buffer */
  257. status =
  258. acpi_ut_initialize_buffer
  259. (return_buffer,
  260. buffer_space_needed);
  261. if (ACPI_FAILURE(status)) {
  262. /*
  263. * Caller's buffer is too small or a new one can't
  264. * be allocated
  265. */
  266. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  267. "Needed buffer size %X, %s\n",
  268. (u32)
  269. buffer_space_needed,
  270. acpi_format_exception
  271. (status)));
  272. } else {
  273. /* We have enough space for the object, build it */
  274. status =
  275. acpi_ut_copy_iobject_to_eobject
  276. (info->return_object,
  277. return_buffer);
  278. }
  279. }
  280. }
  281. }
  282. }
  283. if (info->return_object) {
  284. /*
  285. * Delete the internal return object. NOTE: Interpreter must be
  286. * locked to avoid race condition.
  287. */
  288. acpi_ex_enter_interpreter();
  289. /* Remove one reference on the return object (should delete it) */
  290. acpi_ut_remove_reference(info->return_object);
  291. acpi_ex_exit_interpreter();
  292. }
  293. cleanup:
  294. /* Free the input parameter list (if we created one) */
  295. if (info->parameters) {
  296. /* Free the allocated parameter block */
  297. acpi_ut_delete_internal_object_list(info->parameters);
  298. }
  299. ACPI_FREE(info);
  300. return_ACPI_STATUS(status);
  301. }
  302. ACPI_EXPORT_SYMBOL(acpi_evaluate_object)
  303. /*******************************************************************************
  304. *
  305. * FUNCTION: acpi_ns_resolve_references
  306. *
  307. * PARAMETERS: Info - Evaluation info block
  308. *
  309. * RETURN: Info->return_object is replaced with the dereferenced object
  310. *
  311. * DESCRIPTION: Dereference certain reference objects. Called before an
  312. * internal return object is converted to an external union acpi_object.
  313. *
  314. * Performs an automatic dereference of Index and ref_of reference objects.
  315. * These reference objects are not supported by the union acpi_object, so this is a
  316. * last resort effort to return something useful. Also, provides compatibility
  317. * with other ACPI implementations.
  318. *
  319. * NOTE: does not handle references within returned package objects or nested
  320. * references, but this support could be added later if found to be necessary.
  321. *
  322. ******************************************************************************/
  323. static void acpi_ns_resolve_references(struct acpi_evaluate_info *info)
  324. {
  325. union acpi_operand_object *obj_desc = NULL;
  326. struct acpi_namespace_node *node;
  327. /* We are interested in reference objects only */
  328. if (ACPI_GET_OBJECT_TYPE(info->return_object) !=
  329. ACPI_TYPE_LOCAL_REFERENCE) {
  330. return;
  331. }
  332. /*
  333. * Two types of references are supported - those created by Index and
  334. * ref_of operators. A name reference (AML_NAMEPATH_OP) can be converted
  335. * to an union acpi_object, so it is not dereferenced here. A ddb_handle
  336. * (AML_LOAD_OP) cannot be dereferenced, nor can it be converted to
  337. * an union acpi_object.
  338. */
  339. switch (info->return_object->reference.class) {
  340. case ACPI_REFCLASS_INDEX:
  341. obj_desc = *(info->return_object->reference.where);
  342. break;
  343. case ACPI_REFCLASS_REFOF:
  344. node = info->return_object->reference.object;
  345. if (node) {
  346. obj_desc = node->object;
  347. }
  348. break;
  349. default:
  350. return;
  351. }
  352. /* Replace the existing reference object */
  353. if (obj_desc) {
  354. acpi_ut_add_reference(obj_desc);
  355. acpi_ut_remove_reference(info->return_object);
  356. info->return_object = obj_desc;
  357. }
  358. return;
  359. }
  360. /*******************************************************************************
  361. *
  362. * FUNCTION: acpi_walk_namespace
  363. *
  364. * PARAMETERS: Type - acpi_object_type to search for
  365. * start_object - Handle in namespace where search begins
  366. * max_depth - Depth to which search is to reach
  367. * user_function - Called when an object of "Type" is found
  368. * Context - Passed to user function
  369. * return_value - Location where return value of
  370. * user_function is put if terminated early
  371. *
  372. * RETURNS Return value from the user_function if terminated early.
  373. * Otherwise, returns NULL.
  374. *
  375. * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
  376. * starting (and ending) at the object specified by start_handle.
  377. * The user_function is called whenever an object that matches
  378. * the type parameter is found. If the user function returns
  379. * a non-zero value, the search is terminated immediately and this
  380. * value is returned to the caller.
  381. *
  382. * The point of this procedure is to provide a generic namespace
  383. * walk routine that can be called from multiple places to
  384. * provide multiple services; the User Function can be tailored
  385. * to each task, whether it is a print function, a compare
  386. * function, etc.
  387. *
  388. ******************************************************************************/
  389. acpi_status
  390. acpi_walk_namespace(acpi_object_type type,
  391. acpi_handle start_object,
  392. u32 max_depth,
  393. acpi_walk_callback user_function,
  394. void *context, void **return_value)
  395. {
  396. acpi_status status;
  397. ACPI_FUNCTION_TRACE(acpi_walk_namespace);
  398. /* Parameter validation */
  399. if ((type > ACPI_TYPE_LOCAL_MAX) || (!max_depth) || (!user_function)) {
  400. return_ACPI_STATUS(AE_BAD_PARAMETER);
  401. }
  402. /*
  403. * Lock the namespace around the walk.
  404. * The namespace will be unlocked/locked around each call
  405. * to the user function - since this function
  406. * must be allowed to make Acpi calls itself.
  407. */
  408. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  409. if (ACPI_FAILURE(status)) {
  410. return_ACPI_STATUS(status);
  411. }
  412. status = acpi_ns_walk_namespace(type, start_object, max_depth,
  413. ACPI_NS_WALK_UNLOCK,
  414. user_function, context, return_value);
  415. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  416. return_ACPI_STATUS(status);
  417. }
  418. ACPI_EXPORT_SYMBOL(acpi_walk_namespace)
  419. /*******************************************************************************
  420. *
  421. * FUNCTION: acpi_ns_get_device_callback
  422. *
  423. * PARAMETERS: Callback from acpi_get_device
  424. *
  425. * RETURN: Status
  426. *
  427. * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non-
  428. * present devices, or if they specified a HID, it filters based
  429. * on that.
  430. *
  431. ******************************************************************************/
  432. static acpi_status
  433. acpi_ns_get_device_callback(acpi_handle obj_handle,
  434. u32 nesting_level,
  435. void *context, void **return_value)
  436. {
  437. struct acpi_get_devices_info *info = context;
  438. acpi_status status;
  439. struct acpi_namespace_node *node;
  440. u32 flags;
  441. struct acpica_device_id hid;
  442. struct acpi_compatible_id_list *cid;
  443. u32 i;
  444. int found;
  445. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  446. if (ACPI_FAILURE(status)) {
  447. return (status);
  448. }
  449. node = acpi_ns_map_handle_to_node(obj_handle);
  450. status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  451. if (ACPI_FAILURE(status)) {
  452. return (status);
  453. }
  454. if (!node) {
  455. return (AE_BAD_PARAMETER);
  456. }
  457. /* Run _STA to determine if device is present */
  458. status = acpi_ut_execute_STA(node, &flags);
  459. if (ACPI_FAILURE(status)) {
  460. return (AE_CTRL_DEPTH);
  461. }
  462. if (!(flags & ACPI_STA_DEVICE_PRESENT) &&
  463. !(flags & ACPI_STA_DEVICE_FUNCTIONING)) {
  464. /*
  465. * Don't examine the children of the device only when the
  466. * device is neither present nor functional. See ACPI spec,
  467. * description of _STA for more information.
  468. */
  469. return (AE_CTRL_DEPTH);
  470. }
  471. /* Filter based on device HID & CID */
  472. if (info->hid != NULL) {
  473. status = acpi_ut_execute_HID(node, &hid);
  474. if (status == AE_NOT_FOUND) {
  475. return (AE_OK);
  476. } else if (ACPI_FAILURE(status)) {
  477. return (AE_CTRL_DEPTH);
  478. }
  479. if (ACPI_STRNCMP(hid.value, info->hid, sizeof(hid.value)) != 0) {
  480. /* Get the list of Compatible IDs */
  481. status = acpi_ut_execute_CID(node, &cid);
  482. if (status == AE_NOT_FOUND) {
  483. return (AE_OK);
  484. } else if (ACPI_FAILURE(status)) {
  485. return (AE_CTRL_DEPTH);
  486. }
  487. /* Walk the CID list */
  488. found = 0;
  489. for (i = 0; i < cid->count; i++) {
  490. if (ACPI_STRNCMP(cid->id[i].value, info->hid,
  491. sizeof(struct
  492. acpi_compatible_id)) ==
  493. 0) {
  494. found = 1;
  495. break;
  496. }
  497. }
  498. ACPI_FREE(cid);
  499. if (!found)
  500. return (AE_OK);
  501. }
  502. }
  503. status = info->user_function(obj_handle, nesting_level, info->context,
  504. return_value);
  505. return (status);
  506. }
  507. /*******************************************************************************
  508. *
  509. * FUNCTION: acpi_get_devices
  510. *
  511. * PARAMETERS: HID - HID to search for. Can be NULL.
  512. * user_function - Called when a matching object is found
  513. * Context - Passed to user function
  514. * return_value - Location where return value of
  515. * user_function is put if terminated early
  516. *
  517. * RETURNS Return value from the user_function if terminated early.
  518. * Otherwise, returns NULL.
  519. *
  520. * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
  521. * starting (and ending) at the object specified by start_handle.
  522. * The user_function is called whenever an object of type
  523. * Device is found. If the user function returns
  524. * a non-zero value, the search is terminated immediately and this
  525. * value is returned to the caller.
  526. *
  527. * This is a wrapper for walk_namespace, but the callback performs
  528. * additional filtering. Please see acpi_ns_get_device_callback.
  529. *
  530. ******************************************************************************/
  531. acpi_status
  532. acpi_get_devices(const char *HID,
  533. acpi_walk_callback user_function,
  534. void *context, void **return_value)
  535. {
  536. acpi_status status;
  537. struct acpi_get_devices_info info;
  538. ACPI_FUNCTION_TRACE(acpi_get_devices);
  539. /* Parameter validation */
  540. if (!user_function) {
  541. return_ACPI_STATUS(AE_BAD_PARAMETER);
  542. }
  543. /*
  544. * We're going to call their callback from OUR callback, so we need
  545. * to know what it is, and their context parameter.
  546. */
  547. info.hid = HID;
  548. info.context = context;
  549. info.user_function = user_function;
  550. /*
  551. * Lock the namespace around the walk.
  552. * The namespace will be unlocked/locked around each call
  553. * to the user function - since this function
  554. * must be allowed to make Acpi calls itself.
  555. */
  556. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  557. if (ACPI_FAILURE(status)) {
  558. return_ACPI_STATUS(status);
  559. }
  560. status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
  561. ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
  562. acpi_ns_get_device_callback, &info,
  563. return_value);
  564. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  565. return_ACPI_STATUS(status);
  566. }
  567. ACPI_EXPORT_SYMBOL(acpi_get_devices)
  568. /*******************************************************************************
  569. *
  570. * FUNCTION: acpi_attach_data
  571. *
  572. * PARAMETERS: obj_handle - Namespace node
  573. * Handler - Handler for this attachment
  574. * Data - Pointer to data to be attached
  575. *
  576. * RETURN: Status
  577. *
  578. * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
  579. *
  580. ******************************************************************************/
  581. acpi_status
  582. acpi_attach_data(acpi_handle obj_handle,
  583. acpi_object_handler handler, void *data)
  584. {
  585. struct acpi_namespace_node *node;
  586. acpi_status status;
  587. /* Parameter validation */
  588. if (!obj_handle || !handler || !data) {
  589. return (AE_BAD_PARAMETER);
  590. }
  591. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  592. if (ACPI_FAILURE(status)) {
  593. return (status);
  594. }
  595. /* Convert and validate the handle */
  596. node = acpi_ns_map_handle_to_node(obj_handle);
  597. if (!node) {
  598. status = AE_BAD_PARAMETER;
  599. goto unlock_and_exit;
  600. }
  601. status = acpi_ns_attach_data(node, handler, data);
  602. unlock_and_exit:
  603. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  604. return (status);
  605. }
  606. ACPI_EXPORT_SYMBOL(acpi_attach_data)
  607. /*******************************************************************************
  608. *
  609. * FUNCTION: acpi_detach_data
  610. *
  611. * PARAMETERS: obj_handle - Namespace node handle
  612. * Handler - Handler used in call to acpi_attach_data
  613. *
  614. * RETURN: Status
  615. *
  616. * DESCRIPTION: Remove data that was previously attached to a node.
  617. *
  618. ******************************************************************************/
  619. acpi_status
  620. acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler)
  621. {
  622. struct acpi_namespace_node *node;
  623. acpi_status status;
  624. /* Parameter validation */
  625. if (!obj_handle || !handler) {
  626. return (AE_BAD_PARAMETER);
  627. }
  628. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  629. if (ACPI_FAILURE(status)) {
  630. return (status);
  631. }
  632. /* Convert and validate the handle */
  633. node = acpi_ns_map_handle_to_node(obj_handle);
  634. if (!node) {
  635. status = AE_BAD_PARAMETER;
  636. goto unlock_and_exit;
  637. }
  638. status = acpi_ns_detach_data(node, handler);
  639. unlock_and_exit:
  640. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  641. return (status);
  642. }
  643. ACPI_EXPORT_SYMBOL(acpi_detach_data)
  644. /*******************************************************************************
  645. *
  646. * FUNCTION: acpi_get_data
  647. *
  648. * PARAMETERS: obj_handle - Namespace node
  649. * Handler - Handler used in call to attach_data
  650. * Data - Where the data is returned
  651. *
  652. * RETURN: Status
  653. *
  654. * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
  655. *
  656. ******************************************************************************/
  657. acpi_status
  658. acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data)
  659. {
  660. struct acpi_namespace_node *node;
  661. acpi_status status;
  662. /* Parameter validation */
  663. if (!obj_handle || !handler || !data) {
  664. return (AE_BAD_PARAMETER);
  665. }
  666. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  667. if (ACPI_FAILURE(status)) {
  668. return (status);
  669. }
  670. /* Convert and validate the handle */
  671. node = acpi_ns_map_handle_to_node(obj_handle);
  672. if (!node) {
  673. status = AE_BAD_PARAMETER;
  674. goto unlock_and_exit;
  675. }
  676. status = acpi_ns_get_attached_data(node, handler, data);
  677. unlock_and_exit:
  678. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  679. return (status);
  680. }
  681. ACPI_EXPORT_SYMBOL(acpi_get_data)