nsxfeval.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  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. /*******************************************************************************
  52. *
  53. * FUNCTION: acpi_evaluate_object_typed
  54. *
  55. * PARAMETERS: Handle - Object handle (optional)
  56. * Pathname - Object pathname (optional)
  57. * external_params - List of parameters to pass to method,
  58. * terminated by NULL. May be NULL
  59. * if no parameters are being passed.
  60. * return_buffer - Where to put method's return value (if
  61. * any). If NULL, no value is returned.
  62. * return_type - Expected type of return object
  63. *
  64. * RETURN: Status
  65. *
  66. * DESCRIPTION: Find and evaluate the given object, passing the given
  67. * parameters if necessary. One of "Handle" or "Pathname" must
  68. * be valid (non-null)
  69. *
  70. ******************************************************************************/
  71. acpi_status
  72. acpi_evaluate_object_typed(acpi_handle handle,
  73. acpi_string pathname,
  74. struct acpi_object_list *external_params,
  75. struct acpi_buffer *return_buffer,
  76. acpi_object_type return_type)
  77. {
  78. acpi_status status;
  79. u8 must_free = FALSE;
  80. ACPI_FUNCTION_TRACE(acpi_evaluate_object_typed);
  81. /* Return buffer must be valid */
  82. if (!return_buffer) {
  83. return_ACPI_STATUS(AE_BAD_PARAMETER);
  84. }
  85. if (return_buffer->length == ACPI_ALLOCATE_BUFFER) {
  86. must_free = TRUE;
  87. }
  88. /* Evaluate the object */
  89. status =
  90. acpi_evaluate_object(handle, pathname, external_params,
  91. return_buffer);
  92. if (ACPI_FAILURE(status)) {
  93. return_ACPI_STATUS(status);
  94. }
  95. /* Type ANY means "don't care" */
  96. if (return_type == ACPI_TYPE_ANY) {
  97. return_ACPI_STATUS(AE_OK);
  98. }
  99. if (return_buffer->length == 0) {
  100. /* Error because caller specifically asked for a return value */
  101. ACPI_ERROR((AE_INFO, "No return value"));
  102. return_ACPI_STATUS(AE_NULL_OBJECT);
  103. }
  104. /* Examine the object type returned from evaluate_object */
  105. if (((union acpi_object *)return_buffer->pointer)->type == return_type) {
  106. return_ACPI_STATUS(AE_OK);
  107. }
  108. /* Return object type does not match requested type */
  109. ACPI_ERROR((AE_INFO,
  110. "Incorrect return type [%s] requested [%s]",
  111. acpi_ut_get_type_name(((union acpi_object *)return_buffer->
  112. pointer)->type),
  113. acpi_ut_get_type_name(return_type)));
  114. if (must_free) {
  115. /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
  116. ACPI_FREE(return_buffer->pointer);
  117. return_buffer->pointer = NULL;
  118. }
  119. return_buffer->length = 0;
  120. return_ACPI_STATUS(AE_TYPE);
  121. }
  122. ACPI_EXPORT_SYMBOL(acpi_evaluate_object_typed)
  123. /*******************************************************************************
  124. *
  125. * FUNCTION: acpi_evaluate_object
  126. *
  127. * PARAMETERS: Handle - Object handle (optional)
  128. * Pathname - Object pathname (optional)
  129. * external_params - List of parameters to pass to method,
  130. * terminated by NULL. May be NULL
  131. * if no parameters are being passed.
  132. * return_buffer - Where to put method's return value (if
  133. * any). If NULL, no value is returned.
  134. *
  135. * RETURN: Status
  136. *
  137. * DESCRIPTION: Find and evaluate the given object, passing the given
  138. * parameters if necessary. One of "Handle" or "Pathname" must
  139. * be valid (non-null)
  140. *
  141. ******************************************************************************/
  142. acpi_status
  143. acpi_evaluate_object(acpi_handle handle,
  144. acpi_string pathname,
  145. struct acpi_object_list *external_params,
  146. struct acpi_buffer *return_buffer)
  147. {
  148. acpi_status status;
  149. struct acpi_evaluate_info *info;
  150. acpi_size buffer_space_needed;
  151. u32 i;
  152. ACPI_FUNCTION_TRACE(acpi_evaluate_object);
  153. /* Allocate and initialize the evaluation information block */
  154. info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
  155. if (!info) {
  156. return_ACPI_STATUS(AE_NO_MEMORY);
  157. }
  158. info->pathname = pathname;
  159. /* Convert and validate the device handle */
  160. info->prefix_node = acpi_ns_validate_handle(handle);
  161. if (!info->prefix_node) {
  162. status = AE_BAD_PARAMETER;
  163. goto cleanup;
  164. }
  165. /*
  166. * If there are parameters to be passed to a control method, the external
  167. * objects must all be converted to internal objects
  168. */
  169. if (external_params && external_params->count) {
  170. /*
  171. * Allocate a new parameter block for the internal objects
  172. * Add 1 to count to allow for null terminated internal list
  173. */
  174. info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size)
  175. external_params->
  176. count +
  177. 1) * sizeof(void *));
  178. if (!info->parameters) {
  179. status = AE_NO_MEMORY;
  180. goto cleanup;
  181. }
  182. /* Convert each external object in the list to an internal object */
  183. for (i = 0; i < external_params->count; i++) {
  184. status =
  185. acpi_ut_copy_eobject_to_iobject(&external_params->
  186. pointer[i],
  187. &info->
  188. parameters[i]);
  189. if (ACPI_FAILURE(status)) {
  190. goto cleanup;
  191. }
  192. }
  193. info->parameters[external_params->count] = NULL;
  194. }
  195. /*
  196. * Three major cases:
  197. * 1) Fully qualified pathname
  198. * 2) No handle, not fully qualified pathname (error)
  199. * 3) Valid handle
  200. */
  201. if ((pathname) && (acpi_ns_valid_root_prefix(pathname[0]))) {
  202. /* The path is fully qualified, just evaluate by name */
  203. info->prefix_node = NULL;
  204. status = acpi_ns_evaluate(info);
  205. } else if (!handle) {
  206. /*
  207. * A handle is optional iff a fully qualified pathname is specified.
  208. * Since we've already handled fully qualified names above, this is
  209. * an error
  210. */
  211. if (!pathname) {
  212. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  213. "Both Handle and Pathname are NULL"));
  214. } else {
  215. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  216. "Null Handle with relative pathname [%s]",
  217. pathname));
  218. }
  219. status = AE_BAD_PARAMETER;
  220. } else {
  221. /* We have a namespace a node and a possible relative path */
  222. status = acpi_ns_evaluate(info);
  223. }
  224. /*
  225. * If we are expecting a return value, and all went well above,
  226. * copy the return value to an external object.
  227. */
  228. if (return_buffer) {
  229. if (!info->return_object) {
  230. return_buffer->length = 0;
  231. } else {
  232. if (ACPI_GET_DESCRIPTOR_TYPE(info->return_object) ==
  233. ACPI_DESC_TYPE_NAMED) {
  234. /*
  235. * If we received a NS Node as a return object, this means that
  236. * the object we are evaluating has nothing interesting to
  237. * return (such as a mutex, etc.) We return an error because
  238. * these types are essentially unsupported by this interface.
  239. * We don't check up front because this makes it easier to add
  240. * support for various types at a later date if necessary.
  241. */
  242. status = AE_TYPE;
  243. info->return_object = NULL; /* No need to delete a NS Node */
  244. return_buffer->length = 0;
  245. }
  246. if (ACPI_SUCCESS(status)) {
  247. /* Dereference Index and ref_of references */
  248. acpi_ns_resolve_references(info);
  249. /* Get the size of the returned object */
  250. status =
  251. acpi_ut_get_object_size(info->return_object,
  252. &buffer_space_needed);
  253. if (ACPI_SUCCESS(status)) {
  254. /* Validate/Allocate/Clear caller buffer */
  255. status =
  256. acpi_ut_initialize_buffer
  257. (return_buffer,
  258. buffer_space_needed);
  259. if (ACPI_FAILURE(status)) {
  260. /*
  261. * Caller's buffer is too small or a new one can't
  262. * be allocated
  263. */
  264. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  265. "Needed buffer size %X, %s\n",
  266. (u32)
  267. buffer_space_needed,
  268. acpi_format_exception
  269. (status)));
  270. } else {
  271. /* We have enough space for the object, build it */
  272. status =
  273. acpi_ut_copy_iobject_to_eobject
  274. (info->return_object,
  275. return_buffer);
  276. }
  277. }
  278. }
  279. }
  280. }
  281. if (info->return_object) {
  282. /*
  283. * Delete the internal return object. NOTE: Interpreter must be
  284. * locked to avoid race condition.
  285. */
  286. acpi_ex_enter_interpreter();
  287. /* Remove one reference on the return object (should delete it) */
  288. acpi_ut_remove_reference(info->return_object);
  289. acpi_ex_exit_interpreter();
  290. }
  291. cleanup:
  292. /* Free the input parameter list (if we created one) */
  293. if (info->parameters) {
  294. /* Free the allocated parameter block */
  295. acpi_ut_delete_internal_object_list(info->parameters);
  296. }
  297. ACPI_FREE(info);
  298. return_ACPI_STATUS(status);
  299. }
  300. ACPI_EXPORT_SYMBOL(acpi_evaluate_object)
  301. /*******************************************************************************
  302. *
  303. * FUNCTION: acpi_ns_resolve_references
  304. *
  305. * PARAMETERS: Info - Evaluation info block
  306. *
  307. * RETURN: Info->return_object is replaced with the dereferenced object
  308. *
  309. * DESCRIPTION: Dereference certain reference objects. Called before an
  310. * internal return object is converted to an external union acpi_object.
  311. *
  312. * Performs an automatic dereference of Index and ref_of reference objects.
  313. * These reference objects are not supported by the union acpi_object, so this is a
  314. * last resort effort to return something useful. Also, provides compatibility
  315. * with other ACPI implementations.
  316. *
  317. * NOTE: does not handle references within returned package objects or nested
  318. * references, but this support could be added later if found to be necessary.
  319. *
  320. ******************************************************************************/
  321. static void acpi_ns_resolve_references(struct acpi_evaluate_info *info)
  322. {
  323. union acpi_operand_object *obj_desc = NULL;
  324. struct acpi_namespace_node *node;
  325. /* We are interested in reference objects only */
  326. if ((info->return_object)->common.type != ACPI_TYPE_LOCAL_REFERENCE) {
  327. return;
  328. }
  329. /*
  330. * Two types of references are supported - those created by Index and
  331. * ref_of operators. A name reference (AML_NAMEPATH_OP) can be converted
  332. * to an union acpi_object, so it is not dereferenced here. A ddb_handle
  333. * (AML_LOAD_OP) cannot be dereferenced, nor can it be converted to
  334. * an union acpi_object.
  335. */
  336. switch (info->return_object->reference.class) {
  337. case ACPI_REFCLASS_INDEX:
  338. obj_desc = *(info->return_object->reference.where);
  339. break;
  340. case ACPI_REFCLASS_REFOF:
  341. node = info->return_object->reference.object;
  342. if (node) {
  343. obj_desc = node->object;
  344. }
  345. break;
  346. default:
  347. return;
  348. }
  349. /* Replace the existing reference object */
  350. if (obj_desc) {
  351. acpi_ut_add_reference(obj_desc);
  352. acpi_ut_remove_reference(info->return_object);
  353. info->return_object = obj_desc;
  354. }
  355. return;
  356. }
  357. /*******************************************************************************
  358. *
  359. * FUNCTION: acpi_walk_namespace
  360. *
  361. * PARAMETERS: Type - acpi_object_type to search for
  362. * start_object - Handle in namespace where search begins
  363. * max_depth - Depth to which search is to reach
  364. * pre_order_visit - Called during tree pre-order visit
  365. * when an object of "Type" is found
  366. * post_order_visit - Called during tree post-order visit
  367. * when an object of "Type" is found
  368. * Context - Passed to user function(s) above
  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 callback function is called whenever an object that matches
  378. * the type parameter is found. If the callback 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 callback function(s) can be
  385. * tailored to each task, whether it is a print function,
  386. * a compare 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 pre_order_visit,
  394. acpi_walk_callback post_order_visit,
  395. void *context, void **return_value)
  396. {
  397. acpi_status status;
  398. ACPI_FUNCTION_TRACE(acpi_walk_namespace);
  399. /* Parameter validation */
  400. if ((type > ACPI_TYPE_LOCAL_MAX) ||
  401. (!max_depth) || (!pre_order_visit && !post_order_visit)) {
  402. return_ACPI_STATUS(AE_BAD_PARAMETER);
  403. }
  404. /*
  405. * Need to acquire the namespace reader lock to prevent interference
  406. * with any concurrent table unloads (which causes the deletion of
  407. * namespace objects). We cannot allow the deletion of a namespace node
  408. * while the user function is using it. The exception to this are the
  409. * nodes created and deleted during control method execution -- these
  410. * nodes are marked as temporary nodes and are ignored by the namespace
  411. * walk. Thus, control methods can be executed while holding the
  412. * namespace deletion lock (and the user function can execute control
  413. * methods.)
  414. */
  415. status = acpi_ut_acquire_read_lock(&acpi_gbl_namespace_rw_lock);
  416. if (ACPI_FAILURE(status)) {
  417. return status;
  418. }
  419. /*
  420. * Lock the namespace around the walk. The namespace will be
  421. * unlocked/locked around each call to the user function - since the user
  422. * function must be allowed to make ACPICA calls itself (for example, it
  423. * will typically execute control methods during device enumeration.)
  424. */
  425. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  426. if (ACPI_FAILURE(status)) {
  427. goto unlock_and_exit;
  428. }
  429. status = acpi_ns_walk_namespace(type, start_object, max_depth,
  430. ACPI_NS_WALK_UNLOCK, pre_order_visit,
  431. post_order_visit, context,
  432. return_value);
  433. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  434. unlock_and_exit:
  435. (void)acpi_ut_release_read_lock(&acpi_gbl_namespace_rw_lock);
  436. return_ACPI_STATUS(status);
  437. }
  438. ACPI_EXPORT_SYMBOL(acpi_walk_namespace)
  439. /*******************************************************************************
  440. *
  441. * FUNCTION: acpi_ns_get_device_callback
  442. *
  443. * PARAMETERS: Callback from acpi_get_device
  444. *
  445. * RETURN: Status
  446. *
  447. * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non-
  448. * present devices, or if they specified a HID, it filters based
  449. * on that.
  450. *
  451. ******************************************************************************/
  452. static acpi_status
  453. acpi_ns_get_device_callback(acpi_handle obj_handle,
  454. u32 nesting_level,
  455. void *context, void **return_value)
  456. {
  457. struct acpi_get_devices_info *info = context;
  458. acpi_status status;
  459. struct acpi_namespace_node *node;
  460. u32 flags;
  461. struct acpica_device_id *hid;
  462. struct acpica_device_id_list *cid;
  463. u32 i;
  464. u8 found;
  465. int no_match;
  466. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  467. if (ACPI_FAILURE(status)) {
  468. return (status);
  469. }
  470. node = acpi_ns_validate_handle(obj_handle);
  471. status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  472. if (ACPI_FAILURE(status)) {
  473. return (status);
  474. }
  475. if (!node) {
  476. return (AE_BAD_PARAMETER);
  477. }
  478. /* Run _STA to determine if device is present */
  479. status = acpi_ut_execute_STA(node, &flags);
  480. if (ACPI_FAILURE(status)) {
  481. return (AE_CTRL_DEPTH);
  482. }
  483. if (!(flags & ACPI_STA_DEVICE_PRESENT) &&
  484. !(flags & ACPI_STA_DEVICE_FUNCTIONING)) {
  485. /*
  486. * Don't examine the children of the device only when the
  487. * device is neither present nor functional. See ACPI spec,
  488. * description of _STA for more information.
  489. */
  490. return (AE_CTRL_DEPTH);
  491. }
  492. /* Filter based on device HID & CID */
  493. if (info->hid != NULL) {
  494. status = acpi_ut_execute_HID(node, &hid);
  495. if (status == AE_NOT_FOUND) {
  496. return (AE_OK);
  497. } else if (ACPI_FAILURE(status)) {
  498. return (AE_CTRL_DEPTH);
  499. }
  500. no_match = ACPI_STRCMP(hid->string, info->hid);
  501. ACPI_FREE(hid);
  502. if (no_match) {
  503. /*
  504. * HID does not match, attempt match within the
  505. * list of Compatible IDs (CIDs)
  506. */
  507. status = acpi_ut_execute_CID(node, &cid);
  508. if (status == AE_NOT_FOUND) {
  509. return (AE_OK);
  510. } else if (ACPI_FAILURE(status)) {
  511. return (AE_CTRL_DEPTH);
  512. }
  513. /* Walk the CID list */
  514. found = 0;
  515. for (i = 0; i < cid->count; i++) {
  516. if (ACPI_STRCMP(cid->ids[i].string, info->hid)
  517. == 0) {
  518. found = 1;
  519. break;
  520. }
  521. }
  522. ACPI_FREE(cid);
  523. if (!found)
  524. return (AE_OK);
  525. }
  526. }
  527. status = info->user_function(obj_handle, nesting_level, info->context,
  528. return_value);
  529. return (status);
  530. }
  531. /*******************************************************************************
  532. *
  533. * FUNCTION: acpi_get_devices
  534. *
  535. * PARAMETERS: HID - HID to search for. Can be NULL.
  536. * user_function - Called when a matching object is found
  537. * Context - Passed to user function
  538. * return_value - Location where return value of
  539. * user_function is put if terminated early
  540. *
  541. * RETURNS Return value from the user_function if terminated early.
  542. * Otherwise, returns NULL.
  543. *
  544. * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
  545. * starting (and ending) at the object specified by start_handle.
  546. * The user_function is called whenever an object of type
  547. * Device is found. If the user function returns
  548. * a non-zero value, the search is terminated immediately and this
  549. * value is returned to the caller.
  550. *
  551. * This is a wrapper for walk_namespace, but the callback performs
  552. * additional filtering. Please see acpi_ns_get_device_callback.
  553. *
  554. ******************************************************************************/
  555. acpi_status
  556. acpi_get_devices(const char *HID,
  557. acpi_walk_callback user_function,
  558. void *context, void **return_value)
  559. {
  560. acpi_status status;
  561. struct acpi_get_devices_info info;
  562. ACPI_FUNCTION_TRACE(acpi_get_devices);
  563. /* Parameter validation */
  564. if (!user_function) {
  565. return_ACPI_STATUS(AE_BAD_PARAMETER);
  566. }
  567. /*
  568. * We're going to call their callback from OUR callback, so we need
  569. * to know what it is, and their context parameter.
  570. */
  571. info.hid = HID;
  572. info.context = context;
  573. info.user_function = user_function;
  574. /*
  575. * Lock the namespace around the walk.
  576. * The namespace will be unlocked/locked around each call
  577. * to the user function - since this function
  578. * must be allowed to make Acpi calls itself.
  579. */
  580. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  581. if (ACPI_FAILURE(status)) {
  582. return_ACPI_STATUS(status);
  583. }
  584. status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
  585. ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
  586. acpi_ns_get_device_callback, NULL,
  587. &info, return_value);
  588. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  589. return_ACPI_STATUS(status);
  590. }
  591. ACPI_EXPORT_SYMBOL(acpi_get_devices)
  592. /*******************************************************************************
  593. *
  594. * FUNCTION: acpi_attach_data
  595. *
  596. * PARAMETERS: obj_handle - Namespace node
  597. * Handler - Handler for this attachment
  598. * Data - Pointer to data to be attached
  599. *
  600. * RETURN: Status
  601. *
  602. * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
  603. *
  604. ******************************************************************************/
  605. acpi_status
  606. acpi_attach_data(acpi_handle obj_handle,
  607. 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_validate_handle(obj_handle);
  621. if (!node) {
  622. status = AE_BAD_PARAMETER;
  623. goto unlock_and_exit;
  624. }
  625. status = acpi_ns_attach_data(node, handler, data);
  626. unlock_and_exit:
  627. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  628. return (status);
  629. }
  630. ACPI_EXPORT_SYMBOL(acpi_attach_data)
  631. /*******************************************************************************
  632. *
  633. * FUNCTION: acpi_detach_data
  634. *
  635. * PARAMETERS: obj_handle - Namespace node handle
  636. * Handler - Handler used in call to acpi_attach_data
  637. *
  638. * RETURN: Status
  639. *
  640. * DESCRIPTION: Remove data that was previously attached to a node.
  641. *
  642. ******************************************************************************/
  643. acpi_status
  644. acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler)
  645. {
  646. struct acpi_namespace_node *node;
  647. acpi_status status;
  648. /* Parameter validation */
  649. if (!obj_handle || !handler) {
  650. return (AE_BAD_PARAMETER);
  651. }
  652. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  653. if (ACPI_FAILURE(status)) {
  654. return (status);
  655. }
  656. /* Convert and validate the handle */
  657. node = acpi_ns_validate_handle(obj_handle);
  658. if (!node) {
  659. status = AE_BAD_PARAMETER;
  660. goto unlock_and_exit;
  661. }
  662. status = acpi_ns_detach_data(node, handler);
  663. unlock_and_exit:
  664. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  665. return (status);
  666. }
  667. ACPI_EXPORT_SYMBOL(acpi_detach_data)
  668. /*******************************************************************************
  669. *
  670. * FUNCTION: acpi_get_data
  671. *
  672. * PARAMETERS: obj_handle - Namespace node
  673. * Handler - Handler used in call to attach_data
  674. * Data - Where the data is returned
  675. *
  676. * RETURN: Status
  677. *
  678. * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
  679. *
  680. ******************************************************************************/
  681. acpi_status
  682. acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data)
  683. {
  684. struct acpi_namespace_node *node;
  685. acpi_status status;
  686. /* Parameter validation */
  687. if (!obj_handle || !handler || !data) {
  688. return (AE_BAD_PARAMETER);
  689. }
  690. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  691. if (ACPI_FAILURE(status)) {
  692. return (status);
  693. }
  694. /* Convert and validate the handle */
  695. node = acpi_ns_validate_handle(obj_handle);
  696. if (!node) {
  697. status = AE_BAD_PARAMETER;
  698. goto unlock_and_exit;
  699. }
  700. status = acpi_ns_get_attached_data(node, handler, data);
  701. unlock_and_exit:
  702. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  703. return (status);
  704. }
  705. ACPI_EXPORT_SYMBOL(acpi_get_data)