nsxfeval.c 21 KB

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