nsxfeval.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. /*******************************************************************************
  2. *
  3. * Module Name: nsxfeval - Public interfaces to the ACPI subsystem
  4. * ACPI Object evaluation interfaces
  5. *
  6. ******************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2005, R. Byron Moore
  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 <linux/module.h>
  44. #include <acpi/acpi.h>
  45. #include <acpi/acnamesp.h>
  46. #include <acpi/acinterp.h>
  47. #define _COMPONENT ACPI_NAMESPACE
  48. ACPI_MODULE_NAME("nsxfeval")
  49. /*******************************************************************************
  50. *
  51. * FUNCTION: acpi_evaluate_object_typed
  52. *
  53. * PARAMETERS: Handle - Object handle (optional)
  54. * Pathname - Object pathname (optional)
  55. * external_params - List of parameters to pass to method,
  56. * terminated by NULL. May be NULL
  57. * if no parameters are being passed.
  58. * return_buffer - Where to put method's return value (if
  59. * any). If NULL, no value is returned.
  60. * return_type - Expected type of return object
  61. *
  62. * RETURN: Status
  63. *
  64. * DESCRIPTION: Find and evaluate the given object, passing the given
  65. * parameters if necessary. One of "Handle" or "Pathname" must
  66. * be valid (non-null)
  67. *
  68. ******************************************************************************/
  69. #ifdef ACPI_FUTURE_USAGE
  70. acpi_status
  71. acpi_evaluate_object_typed(acpi_handle handle,
  72. acpi_string pathname,
  73. struct acpi_object_list *external_params,
  74. struct acpi_buffer *return_buffer,
  75. acpi_object_type return_type)
  76. {
  77. acpi_status status;
  78. u8 must_free = FALSE;
  79. ACPI_FUNCTION_TRACE("acpi_evaluate_object_typed");
  80. /* Return buffer must be valid */
  81. if (!return_buffer) {
  82. return_ACPI_STATUS(AE_BAD_PARAMETER);
  83. }
  84. if (return_buffer->length == ACPI_ALLOCATE_BUFFER) {
  85. must_free = TRUE;
  86. }
  87. /* Evaluate the object */
  88. status =
  89. acpi_evaluate_object(handle, pathname, external_params,
  90. return_buffer);
  91. if (ACPI_FAILURE(status)) {
  92. return_ACPI_STATUS(status);
  93. }
  94. /* Type ANY means "don't care" */
  95. if (return_type == ACPI_TYPE_ANY) {
  96. return_ACPI_STATUS(AE_OK);
  97. }
  98. if (return_buffer->length == 0) {
  99. /* Error because caller specifically asked for a return value */
  100. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "No return value\n"));
  101. return_ACPI_STATUS(AE_NULL_OBJECT);
  102. }
  103. /* Examine the object type returned from evaluate_object */
  104. if (((union acpi_object *)return_buffer->pointer)->type == return_type) {
  105. return_ACPI_STATUS(AE_OK);
  106. }
  107. /* Return object type does not match requested type */
  108. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  109. "Incorrect return type [%s] requested [%s]\n",
  110. acpi_ut_get_type_name(((union acpi_object *)
  111. return_buffer->pointer)->type),
  112. acpi_ut_get_type_name(return_type)));
  113. if (must_free) {
  114. /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
  115. acpi_os_free(return_buffer->pointer);
  116. return_buffer->pointer = NULL;
  117. }
  118. return_buffer->length = 0;
  119. return_ACPI_STATUS(AE_TYPE);
  120. }
  121. #endif /* ACPI_FUTURE_USAGE */
  122. /*******************************************************************************
  123. *
  124. * FUNCTION: acpi_evaluate_object
  125. *
  126. * PARAMETERS: Handle - Object handle (optional)
  127. * Pathname - Object pathname (optional)
  128. * external_params - List of parameters to pass to method,
  129. * terminated by NULL. May be NULL
  130. * if no parameters are being passed.
  131. * return_buffer - Where to put method's return value (if
  132. * any). If NULL, no value is returned.
  133. *
  134. * RETURN: Status
  135. *
  136. * DESCRIPTION: Find and evaluate the given object, passing the given
  137. * parameters if necessary. One of "Handle" or "Pathname" must
  138. * be valid (non-null)
  139. *
  140. ******************************************************************************/
  141. acpi_status
  142. acpi_evaluate_object(acpi_handle handle,
  143. acpi_string pathname,
  144. struct acpi_object_list *external_params,
  145. struct acpi_buffer *return_buffer)
  146. {
  147. acpi_status status;
  148. acpi_status status2;
  149. struct acpi_parameter_info info;
  150. acpi_size buffer_space_needed;
  151. u32 i;
  152. ACPI_FUNCTION_TRACE("acpi_evaluate_object");
  153. info.node = handle;
  154. info.parameters = NULL;
  155. info.return_object = NULL;
  156. info.parameter_type = ACPI_PARAM_ARGS;
  157. /*
  158. * If there are parameters to be passed to the object
  159. * (which must be a control method), the external objects
  160. * must be converted to internal objects
  161. */
  162. if (external_params && external_params->count) {
  163. /*
  164. * Allocate a new parameter block for the internal objects
  165. * Add 1 to count to allow for null terminated internal list
  166. */
  167. info.parameters = ACPI_MEM_CALLOCATE(((acpi_size)
  168. external_params->count +
  169. 1) * sizeof(void *));
  170. if (!info.parameters) {
  171. return_ACPI_STATUS(AE_NO_MEMORY);
  172. }
  173. /*
  174. * Convert each external object in the list to an
  175. * internal object
  176. */
  177. for (i = 0; i < external_params->count; i++) {
  178. status =
  179. acpi_ut_copy_eobject_to_iobject(&external_params->
  180. pointer[i],
  181. &info.
  182. parameters[i]);
  183. if (ACPI_FAILURE(status)) {
  184. acpi_ut_delete_internal_object_list(info.
  185. parameters);
  186. return_ACPI_STATUS(status);
  187. }
  188. }
  189. info.parameters[external_params->count] = NULL;
  190. }
  191. /*
  192. * Three major cases:
  193. * 1) Fully qualified pathname
  194. * 2) No handle, not fully qualified pathname (error)
  195. * 3) Valid handle
  196. */
  197. if ((pathname) && (acpi_ns_valid_root_prefix(pathname[0]))) {
  198. /*
  199. * The path is fully qualified, just evaluate by name
  200. */
  201. status = acpi_ns_evaluate_by_name(pathname, &info);
  202. } else if (!handle) {
  203. /*
  204. * A handle is optional iff a fully qualified pathname
  205. * is specified. Since we've already handled fully
  206. * qualified names above, this is an error
  207. */
  208. if (!pathname) {
  209. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  210. "Both Handle and Pathname are NULL\n"));
  211. } else {
  212. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  213. "Handle is NULL and Pathname is relative\n"));
  214. }
  215. status = AE_BAD_PARAMETER;
  216. } else {
  217. /*
  218. * We get here if we have a handle -- and if we have a
  219. * pathname it is relative. The handle will be validated
  220. * in the lower procedures
  221. */
  222. if (!pathname) {
  223. /*
  224. * The null pathname case means the handle is for
  225. * the actual object to be evaluated
  226. */
  227. status = acpi_ns_evaluate_by_handle(&info);
  228. } else {
  229. /*
  230. * Both a Handle and a relative Pathname
  231. */
  232. status = acpi_ns_evaluate_relative(pathname, &info);
  233. }
  234. }
  235. /*
  236. * If we are expecting a return value, and all went well above,
  237. * copy the return value to an external object.
  238. */
  239. if (return_buffer) {
  240. if (!info.return_object) {
  241. return_buffer->length = 0;
  242. } else {
  243. if (ACPI_GET_DESCRIPTOR_TYPE(info.return_object) ==
  244. ACPI_DESC_TYPE_NAMED) {
  245. /*
  246. * If we received a NS Node as a return object, this means that
  247. * the object we are evaluating has nothing interesting to
  248. * return (such as a mutex, etc.) We return an error because
  249. * these types are essentially unsupported by this interface.
  250. * We don't check up front because this makes it easier to add
  251. * support for various types at a later date if necessary.
  252. */
  253. status = AE_TYPE;
  254. info.return_object = NULL; /* No need to delete a NS Node */
  255. return_buffer->length = 0;
  256. }
  257. if (ACPI_SUCCESS(status)) {
  258. /*
  259. * Find out how large a buffer is needed
  260. * to contain the returned object
  261. */
  262. status =
  263. acpi_ut_get_object_size(info.return_object,
  264. &buffer_space_needed);
  265. if (ACPI_SUCCESS(status)) {
  266. /* Validate/Allocate/Clear caller buffer */
  267. status =
  268. acpi_ut_initialize_buffer
  269. (return_buffer,
  270. buffer_space_needed);
  271. if (ACPI_FAILURE(status)) {
  272. /*
  273. * Caller's buffer is too small or a new one can't be allocated
  274. */
  275. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  276. "Needed buffer size %X, %s\n",
  277. (u32)
  278. buffer_space_needed,
  279. acpi_format_exception
  280. (status)));
  281. } else {
  282. /*
  283. * We have enough space for the object, build it
  284. */
  285. status =
  286. acpi_ut_copy_iobject_to_eobject
  287. (info.return_object,
  288. return_buffer);
  289. }
  290. }
  291. }
  292. }
  293. }
  294. if (info.return_object) {
  295. /*
  296. * Delete the internal return object. NOTE: Interpreter
  297. * must be locked to avoid race condition.
  298. */
  299. status2 = acpi_ex_enter_interpreter();
  300. if (ACPI_SUCCESS(status2)) {
  301. /*
  302. * Delete the internal return object. (Or at least
  303. * decrement the reference count by one)
  304. */
  305. acpi_ut_remove_reference(info.return_object);
  306. acpi_ex_exit_interpreter();
  307. }
  308. }
  309. /*
  310. * Free the input parameter list (if we created one),
  311. */
  312. if (info.parameters) {
  313. /* Free the allocated parameter block */
  314. acpi_ut_delete_internal_object_list(info.parameters);
  315. }
  316. return_ACPI_STATUS(status);
  317. }
  318. EXPORT_SYMBOL(acpi_evaluate_object);
  319. /*******************************************************************************
  320. *
  321. * FUNCTION: acpi_walk_namespace
  322. *
  323. * PARAMETERS: Type - acpi_object_type to search for
  324. * start_object - Handle in namespace where search begins
  325. * max_depth - Depth to which search is to reach
  326. * user_function - Called when an object of "Type" is found
  327. * Context - Passed to user function
  328. * return_value - Location where return value of
  329. * user_function is put if terminated early
  330. *
  331. * RETURNS Return value from the user_function if terminated early.
  332. * Otherwise, returns NULL.
  333. *
  334. * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
  335. * starting (and ending) at the object specified by start_handle.
  336. * The user_function is called whenever an object that matches
  337. * the type parameter is found. If the user function returns
  338. * a non-zero value, the search is terminated immediately and this
  339. * value is returned to the caller.
  340. *
  341. * The point of this procedure is to provide a generic namespace
  342. * walk routine that can be called from multiple places to
  343. * provide multiple services; the User Function can be tailored
  344. * to each task, whether it is a print function, a compare
  345. * function, etc.
  346. *
  347. ******************************************************************************/
  348. acpi_status
  349. acpi_walk_namespace(acpi_object_type type,
  350. acpi_handle start_object,
  351. u32 max_depth,
  352. acpi_walk_callback user_function,
  353. void *context, void **return_value)
  354. {
  355. acpi_status status;
  356. ACPI_FUNCTION_TRACE("acpi_walk_namespace");
  357. /* Parameter validation */
  358. if ((type > ACPI_TYPE_EXTERNAL_MAX) || (!max_depth) || (!user_function)) {
  359. return_ACPI_STATUS(AE_BAD_PARAMETER);
  360. }
  361. /*
  362. * Lock the namespace around the walk.
  363. * The namespace will be unlocked/locked around each call
  364. * to the user function - since this function
  365. * must be allowed to make Acpi calls itself.
  366. */
  367. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  368. if (ACPI_FAILURE(status)) {
  369. return_ACPI_STATUS(status);
  370. }
  371. status = acpi_ns_walk_namespace(type, start_object, max_depth,
  372. ACPI_NS_WALK_UNLOCK,
  373. user_function, context, return_value);
  374. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  375. return_ACPI_STATUS(status);
  376. }
  377. EXPORT_SYMBOL(acpi_walk_namespace);
  378. /*******************************************************************************
  379. *
  380. * FUNCTION: acpi_ns_get_device_callback
  381. *
  382. * PARAMETERS: Callback from acpi_get_device
  383. *
  384. * RETURN: Status
  385. *
  386. * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non-
  387. * present devices, or if they specified a HID, it filters based
  388. * on that.
  389. *
  390. ******************************************************************************/
  391. static acpi_status
  392. acpi_ns_get_device_callback(acpi_handle obj_handle,
  393. u32 nesting_level,
  394. void *context, void **return_value)
  395. {
  396. struct acpi_get_devices_info *info = context;
  397. acpi_status status;
  398. struct acpi_namespace_node *node;
  399. u32 flags;
  400. struct acpi_device_id hid;
  401. struct acpi_compatible_id_list *cid;
  402. acpi_native_uint i;
  403. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  404. if (ACPI_FAILURE(status)) {
  405. return (status);
  406. }
  407. node = acpi_ns_map_handle_to_node(obj_handle);
  408. status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  409. if (ACPI_FAILURE(status)) {
  410. return (status);
  411. }
  412. if (!node) {
  413. return (AE_BAD_PARAMETER);
  414. }
  415. /* Run _STA to determine if device is present */
  416. status = acpi_ut_execute_STA(node, &flags);
  417. if (ACPI_FAILURE(status)) {
  418. return (AE_CTRL_DEPTH);
  419. }
  420. if (!(flags & 0x01)) {
  421. /* Don't return at the device or children of the device if not there */
  422. return (AE_CTRL_DEPTH);
  423. }
  424. /* Filter based on device HID & CID */
  425. if (info->hid != NULL) {
  426. status = acpi_ut_execute_HID(node, &hid);
  427. if (status == AE_NOT_FOUND) {
  428. return (AE_OK);
  429. } else if (ACPI_FAILURE(status)) {
  430. return (AE_CTRL_DEPTH);
  431. }
  432. if (ACPI_STRNCMP(hid.value, info->hid, sizeof(hid.value)) != 0) {
  433. /* Get the list of Compatible IDs */
  434. status = acpi_ut_execute_CID(node, &cid);
  435. if (status == AE_NOT_FOUND) {
  436. return (AE_OK);
  437. } else if (ACPI_FAILURE(status)) {
  438. return (AE_CTRL_DEPTH);
  439. }
  440. /* Walk the CID list */
  441. for (i = 0; i < cid->count; i++) {
  442. if (ACPI_STRNCMP(cid->id[i].value, info->hid,
  443. sizeof(struct
  444. acpi_compatible_id)) !=
  445. 0) {
  446. ACPI_MEM_FREE(cid);
  447. return (AE_OK);
  448. }
  449. }
  450. ACPI_MEM_FREE(cid);
  451. }
  452. }
  453. status = info->user_function(obj_handle, nesting_level, info->context,
  454. return_value);
  455. return (status);
  456. }
  457. /*******************************************************************************
  458. *
  459. * FUNCTION: acpi_get_devices
  460. *
  461. * PARAMETERS: HID - HID to search for. Can be NULL.
  462. * user_function - Called when a matching object is found
  463. * Context - Passed to user function
  464. * return_value - Location where return value of
  465. * user_function is put if terminated early
  466. *
  467. * RETURNS Return value from the user_function if terminated early.
  468. * Otherwise, returns NULL.
  469. *
  470. * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
  471. * starting (and ending) at the object specified by start_handle.
  472. * The user_function is called whenever an object of type
  473. * Device is found. If the user function returns
  474. * a non-zero value, the search is terminated immediately and this
  475. * value is returned to the caller.
  476. *
  477. * This is a wrapper for walk_namespace, but the callback performs
  478. * additional filtering. Please see acpi_get_device_callback.
  479. *
  480. ******************************************************************************/
  481. acpi_status
  482. acpi_get_devices(char *HID,
  483. acpi_walk_callback user_function,
  484. void *context, void **return_value)
  485. {
  486. acpi_status status;
  487. struct acpi_get_devices_info info;
  488. ACPI_FUNCTION_TRACE("acpi_get_devices");
  489. /* Parameter validation */
  490. if (!user_function) {
  491. return_ACPI_STATUS(AE_BAD_PARAMETER);
  492. }
  493. /*
  494. * We're going to call their callback from OUR callback, so we need
  495. * to know what it is, and their context parameter.
  496. */
  497. info.context = context;
  498. info.user_function = user_function;
  499. info.hid = HID;
  500. /*
  501. * Lock the namespace around the walk.
  502. * The namespace will be unlocked/locked around each call
  503. * to the user function - since this function
  504. * must be allowed to make Acpi calls itself.
  505. */
  506. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  507. if (ACPI_FAILURE(status)) {
  508. return_ACPI_STATUS(status);
  509. }
  510. status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE,
  511. ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
  512. ACPI_NS_WALK_UNLOCK,
  513. acpi_ns_get_device_callback, &info,
  514. return_value);
  515. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  516. return_ACPI_STATUS(status);
  517. }
  518. EXPORT_SYMBOL(acpi_get_devices);
  519. /*******************************************************************************
  520. *
  521. * FUNCTION: acpi_attach_data
  522. *
  523. * PARAMETERS: obj_handle - Namespace node
  524. * Handler - Handler for this attachment
  525. * Data - Pointer to data to be attached
  526. *
  527. * RETURN: Status
  528. *
  529. * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
  530. *
  531. ******************************************************************************/
  532. acpi_status
  533. acpi_attach_data(acpi_handle obj_handle,
  534. acpi_object_handler handler, void *data)
  535. {
  536. struct acpi_namespace_node *node;
  537. acpi_status status;
  538. /* Parameter validation */
  539. if (!obj_handle || !handler || !data) {
  540. return (AE_BAD_PARAMETER);
  541. }
  542. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  543. if (ACPI_FAILURE(status)) {
  544. return (status);
  545. }
  546. /* Convert and validate the handle */
  547. node = acpi_ns_map_handle_to_node(obj_handle);
  548. if (!node) {
  549. status = AE_BAD_PARAMETER;
  550. goto unlock_and_exit;
  551. }
  552. status = acpi_ns_attach_data(node, handler, data);
  553. unlock_and_exit:
  554. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  555. return (status);
  556. }
  557. /*******************************************************************************
  558. *
  559. * FUNCTION: acpi_detach_data
  560. *
  561. * PARAMETERS: obj_handle - Namespace node handle
  562. * Handler - Handler used in call to acpi_attach_data
  563. *
  564. * RETURN: Status
  565. *
  566. * DESCRIPTION: Remove data that was previously attached to a node.
  567. *
  568. ******************************************************************************/
  569. acpi_status
  570. acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler)
  571. {
  572. struct acpi_namespace_node *node;
  573. acpi_status status;
  574. /* Parameter validation */
  575. if (!obj_handle || !handler) {
  576. return (AE_BAD_PARAMETER);
  577. }
  578. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  579. if (ACPI_FAILURE(status)) {
  580. return (status);
  581. }
  582. /* Convert and validate the handle */
  583. node = acpi_ns_map_handle_to_node(obj_handle);
  584. if (!node) {
  585. status = AE_BAD_PARAMETER;
  586. goto unlock_and_exit;
  587. }
  588. status = acpi_ns_detach_data(node, handler);
  589. unlock_and_exit:
  590. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  591. return (status);
  592. }
  593. /*******************************************************************************
  594. *
  595. * FUNCTION: acpi_get_data
  596. *
  597. * PARAMETERS: obj_handle - Namespace node
  598. * Handler - Handler used in call to attach_data
  599. * Data - Where the data is returned
  600. *
  601. * RETURN: Status
  602. *
  603. * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
  604. *
  605. ******************************************************************************/
  606. acpi_status
  607. acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data)
  608. {
  609. struct acpi_namespace_node *node;
  610. acpi_status status;
  611. /* Parameter validation */
  612. if (!obj_handle || !handler || !data) {
  613. return (AE_BAD_PARAMETER);
  614. }
  615. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  616. if (ACPI_FAILURE(status)) {
  617. return (status);
  618. }
  619. /* Convert and validate the handle */
  620. node = acpi_ns_map_handle_to_node(obj_handle);
  621. if (!node) {
  622. status = AE_BAD_PARAMETER;
  623. goto unlock_and_exit;
  624. }
  625. status = acpi_ns_get_attached_data(node, handler, data);
  626. unlock_and_exit:
  627. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  628. return (status);
  629. }