nsxfeval.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. /*******************************************************************************
  2. *
  3. * Module Name: nsxfeval - Public interfaces to the ACPI subsystem
  4. * ACPI Object evaluation interfaces
  5. *
  6. ******************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2012, 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 <linux/export.h>
  44. #include <acpi/acpi.h>
  45. #include "accommon.h"
  46. #include "acnamesp.h"
  47. #include "acinterp.h"
  48. #define _COMPONENT ACPI_NAMESPACE
  49. ACPI_MODULE_NAME("nsxfeval")
  50. /* Local prototypes */
  51. static void acpi_ns_resolve_references(struct acpi_evaluate_info *info);
  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. /*******************************************************************************
  125. *
  126. * FUNCTION: acpi_evaluate_object
  127. *
  128. * PARAMETERS: Handle - Object handle (optional)
  129. * Pathname - Object pathname (optional)
  130. * external_params - List of parameters to pass to method,
  131. * terminated by NULL. May be NULL
  132. * if no parameters are being passed.
  133. * return_buffer - Where to put method's return value (if
  134. * any). If NULL, no value is returned.
  135. *
  136. * RETURN: Status
  137. *
  138. * DESCRIPTION: Find and evaluate the given object, passing the given
  139. * parameters if necessary. One of "Handle" or "Pathname" must
  140. * be valid (non-null)
  141. *
  142. ******************************************************************************/
  143. acpi_status
  144. acpi_evaluate_object(acpi_handle handle,
  145. acpi_string pathname,
  146. struct acpi_object_list *external_params,
  147. struct acpi_buffer *return_buffer)
  148. {
  149. acpi_status status;
  150. struct acpi_evaluate_info *info;
  151. acpi_size buffer_space_needed;
  152. u32 i;
  153. ACPI_FUNCTION_TRACE(acpi_evaluate_object);
  154. /* Allocate and initialize the evaluation information block */
  155. info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
  156. if (!info) {
  157. return_ACPI_STATUS(AE_NO_MEMORY);
  158. }
  159. info->pathname = pathname;
  160. /* Convert and validate the device handle */
  161. info->prefix_node = acpi_ns_validate_handle(handle);
  162. if (!info->prefix_node) {
  163. status = AE_BAD_PARAMETER;
  164. goto cleanup;
  165. }
  166. /*
  167. * If there are parameters to be passed to a control method, the external
  168. * objects must all be converted to internal objects
  169. */
  170. if (external_params && external_params->count) {
  171. /*
  172. * Allocate a new parameter block for the internal objects
  173. * Add 1 to count to allow for null terminated internal list
  174. */
  175. info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size)
  176. external_params->
  177. count +
  178. 1) * sizeof(void *));
  179. if (!info->parameters) {
  180. status = AE_NO_MEMORY;
  181. goto cleanup;
  182. }
  183. /* Convert each external object in the list to an internal object */
  184. for (i = 0; i < external_params->count; i++) {
  185. status =
  186. acpi_ut_copy_eobject_to_iobject(&external_params->
  187. pointer[i],
  188. &info->
  189. parameters[i]);
  190. if (ACPI_FAILURE(status)) {
  191. goto cleanup;
  192. }
  193. }
  194. info->parameters[external_params->count] = NULL;
  195. }
  196. /*
  197. * Three major cases:
  198. * 1) Fully qualified pathname
  199. * 2) No handle, not fully qualified pathname (error)
  200. * 3) Valid handle
  201. */
  202. if ((pathname) && (acpi_ns_valid_root_prefix(pathname[0]))) {
  203. /* The path is fully qualified, just evaluate by name */
  204. info->prefix_node = NULL;
  205. status = acpi_ns_evaluate(info);
  206. } else if (!handle) {
  207. /*
  208. * A handle is optional iff a fully qualified pathname is specified.
  209. * Since we've already handled fully qualified names above, this is
  210. * an error
  211. */
  212. if (!pathname) {
  213. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  214. "Both Handle and Pathname are NULL"));
  215. } else {
  216. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  217. "Null Handle with relative pathname [%s]",
  218. pathname));
  219. }
  220. status = AE_BAD_PARAMETER;
  221. } else {
  222. /* We have a namespace a node and a possible relative path */
  223. status = acpi_ns_evaluate(info);
  224. }
  225. /*
  226. * If we are expecting a return value, and all went well above,
  227. * copy the return value to an external object.
  228. */
  229. if (return_buffer) {
  230. if (!info->return_object) {
  231. return_buffer->length = 0;
  232. } else {
  233. if (ACPI_GET_DESCRIPTOR_TYPE(info->return_object) ==
  234. ACPI_DESC_TYPE_NAMED) {
  235. /*
  236. * If we received a NS Node as a return object, this means that
  237. * the object we are evaluating has nothing interesting to
  238. * return (such as a mutex, etc.) We return an error because
  239. * these types are essentially unsupported by this interface.
  240. * We don't check up front because this makes it easier to add
  241. * support for various types at a later date if necessary.
  242. */
  243. status = AE_TYPE;
  244. info->return_object = NULL; /* No need to delete a NS Node */
  245. return_buffer->length = 0;
  246. }
  247. if (ACPI_SUCCESS(status)) {
  248. /* Dereference Index and ref_of references */
  249. acpi_ns_resolve_references(info);
  250. /* Get the size of the returned object */
  251. status =
  252. acpi_ut_get_object_size(info->return_object,
  253. &buffer_space_needed);
  254. if (ACPI_SUCCESS(status)) {
  255. /* Validate/Allocate/Clear caller buffer */
  256. status =
  257. acpi_ut_initialize_buffer
  258. (return_buffer,
  259. buffer_space_needed);
  260. if (ACPI_FAILURE(status)) {
  261. /*
  262. * Caller's buffer is too small or a new one can't
  263. * be allocated
  264. */
  265. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  266. "Needed buffer size %X, %s\n",
  267. (u32)
  268. buffer_space_needed,
  269. acpi_format_exception
  270. (status)));
  271. } else {
  272. /* We have enough space for the object, build it */
  273. status =
  274. acpi_ut_copy_iobject_to_eobject
  275. (info->return_object,
  276. return_buffer);
  277. }
  278. }
  279. }
  280. }
  281. }
  282. if (info->return_object) {
  283. /*
  284. * Delete the internal return object. NOTE: Interpreter must be
  285. * locked to avoid race condition.
  286. */
  287. acpi_ex_enter_interpreter();
  288. /* Remove one reference on the return object (should delete it) */
  289. acpi_ut_remove_reference(info->return_object);
  290. acpi_ex_exit_interpreter();
  291. }
  292. cleanup:
  293. /* Free the input parameter list (if we created one) */
  294. if (info->parameters) {
  295. /* Free the allocated parameter block */
  296. acpi_ut_delete_internal_object_list(info->parameters);
  297. }
  298. ACPI_FREE(info);
  299. return_ACPI_STATUS(status);
  300. }
  301. ACPI_EXPORT_SYMBOL(acpi_evaluate_object)
  302. /*******************************************************************************
  303. *
  304. * FUNCTION: acpi_ns_resolve_references
  305. *
  306. * PARAMETERS: Info - Evaluation info block
  307. *
  308. * RETURN: Info->return_object is replaced with the dereferenced object
  309. *
  310. * DESCRIPTION: Dereference certain reference objects. Called before an
  311. * internal return object is converted to an external union acpi_object.
  312. *
  313. * Performs an automatic dereference of Index and ref_of reference objects.
  314. * These reference objects are not supported by the union acpi_object, so this is a
  315. * last resort effort to return something useful. Also, provides compatibility
  316. * with other ACPI implementations.
  317. *
  318. * NOTE: does not handle references within returned package objects or nested
  319. * references, but this support could be added later if found to be necessary.
  320. *
  321. ******************************************************************************/
  322. static void acpi_ns_resolve_references(struct acpi_evaluate_info *info)
  323. {
  324. union acpi_operand_object *obj_desc = NULL;
  325. struct acpi_namespace_node *node;
  326. /* We are interested in reference objects only */
  327. if ((info->return_object)->common.type != ACPI_TYPE_LOCAL_REFERENCE) {
  328. return;
  329. }
  330. /*
  331. * Two types of references are supported - those created by Index and
  332. * ref_of operators. A name reference (AML_NAMEPATH_OP) can be converted
  333. * to an union acpi_object, so it is not dereferenced here. A ddb_handle
  334. * (AML_LOAD_OP) cannot be dereferenced, nor can it be converted to
  335. * an union acpi_object.
  336. */
  337. switch (info->return_object->reference.class) {
  338. case ACPI_REFCLASS_INDEX:
  339. obj_desc = *(info->return_object->reference.where);
  340. break;
  341. case ACPI_REFCLASS_REFOF:
  342. node = info->return_object->reference.object;
  343. if (node) {
  344. obj_desc = node->object;
  345. }
  346. break;
  347. default:
  348. return;
  349. }
  350. /* Replace the existing reference object */
  351. if (obj_desc) {
  352. acpi_ut_add_reference(obj_desc);
  353. acpi_ut_remove_reference(info->return_object);
  354. info->return_object = obj_desc;
  355. }
  356. return;
  357. }
  358. /*******************************************************************************
  359. *
  360. * FUNCTION: acpi_walk_namespace
  361. *
  362. * PARAMETERS: Type - acpi_object_type to search for
  363. * start_object - Handle in namespace where search begins
  364. * max_depth - Depth to which search is to reach
  365. * pre_order_visit - Called during tree pre-order visit
  366. * when an object of "Type" is found
  367. * post_order_visit - Called during tree post-order visit
  368. * when an object of "Type" is found
  369. * Context - Passed to user function(s) above
  370. * return_value - Location where return value of
  371. * user_function is put if terminated early
  372. *
  373. * RETURNS Return value from the user_function if terminated early.
  374. * Otherwise, returns NULL.
  375. *
  376. * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
  377. * starting (and ending) at the object specified by start_handle.
  378. * The callback function is called whenever an object that matches
  379. * the type parameter is found. If the callback function returns
  380. * a non-zero value, the search is terminated immediately and this
  381. * value is returned to the caller.
  382. *
  383. * The point of this procedure is to provide a generic namespace
  384. * walk routine that can be called from multiple places to
  385. * provide multiple services; the callback function(s) can be
  386. * tailored to each task, whether it is a print function,
  387. * a compare function, etc.
  388. *
  389. ******************************************************************************/
  390. acpi_status
  391. acpi_walk_namespace(acpi_object_type type,
  392. acpi_handle start_object,
  393. u32 max_depth,
  394. acpi_walk_callback pre_order_visit,
  395. acpi_walk_callback post_order_visit,
  396. void *context, void **return_value)
  397. {
  398. acpi_status status;
  399. ACPI_FUNCTION_TRACE(acpi_walk_namespace);
  400. /* Parameter validation */
  401. if ((type > ACPI_TYPE_LOCAL_MAX) ||
  402. (!max_depth) || (!pre_order_visit && !post_order_visit)) {
  403. return_ACPI_STATUS(AE_BAD_PARAMETER);
  404. }
  405. /*
  406. * Need to acquire the namespace reader lock to prevent interference
  407. * with any concurrent table unloads (which causes the deletion of
  408. * namespace objects). We cannot allow the deletion of a namespace node
  409. * while the user function is using it. The exception to this are the
  410. * nodes created and deleted during control method execution -- these
  411. * nodes are marked as temporary nodes and are ignored by the namespace
  412. * walk. Thus, control methods can be executed while holding the
  413. * namespace deletion lock (and the user function can execute control
  414. * methods.)
  415. */
  416. status = acpi_ut_acquire_read_lock(&acpi_gbl_namespace_rw_lock);
  417. if (ACPI_FAILURE(status)) {
  418. return status;
  419. }
  420. /*
  421. * Lock the namespace around the walk. The namespace will be
  422. * unlocked/locked around each call to the user function - since the user
  423. * function must be allowed to make ACPICA calls itself (for example, it
  424. * will typically execute control methods during device enumeration.)
  425. */
  426. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  427. if (ACPI_FAILURE(status)) {
  428. goto unlock_and_exit;
  429. }
  430. status = acpi_ns_walk_namespace(type, start_object, max_depth,
  431. ACPI_NS_WALK_UNLOCK, pre_order_visit,
  432. post_order_visit, context,
  433. return_value);
  434. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  435. unlock_and_exit:
  436. (void)acpi_ut_release_read_lock(&acpi_gbl_namespace_rw_lock);
  437. return_ACPI_STATUS(status);
  438. }
  439. ACPI_EXPORT_SYMBOL(acpi_walk_namespace)
  440. /*******************************************************************************
  441. *
  442. * FUNCTION: acpi_ns_get_device_callback
  443. *
  444. * PARAMETERS: Callback from acpi_get_device
  445. *
  446. * RETURN: Status
  447. *
  448. * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non-
  449. * present devices, or if they specified a HID, it filters based
  450. * on that.
  451. *
  452. ******************************************************************************/
  453. static acpi_status
  454. acpi_ns_get_device_callback(acpi_handle obj_handle,
  455. u32 nesting_level,
  456. void *context, void **return_value)
  457. {
  458. struct acpi_get_devices_info *info = context;
  459. acpi_status status;
  460. struct acpi_namespace_node *node;
  461. u32 flags;
  462. struct acpica_device_id *hid;
  463. struct acpica_device_id_list *cid;
  464. u32 i;
  465. u8 found;
  466. int no_match;
  467. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  468. if (ACPI_FAILURE(status)) {
  469. return (status);
  470. }
  471. node = acpi_ns_validate_handle(obj_handle);
  472. status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  473. if (ACPI_FAILURE(status)) {
  474. return (status);
  475. }
  476. if (!node) {
  477. return (AE_BAD_PARAMETER);
  478. }
  479. /*
  480. * First, filter based on the device HID and CID.
  481. *
  482. * 01/2010: For this case where a specific HID is requested, we don't
  483. * want to run _STA until we have an actual HID match. Thus, we will
  484. * not unnecessarily execute _STA on devices for which the caller
  485. * doesn't care about. Previously, _STA was executed unconditionally
  486. * on all devices found here.
  487. *
  488. * A side-effect of this change is that now we will continue to search
  489. * for a matching HID even under device trees where the parent device
  490. * would have returned a _STA that indicates it is not present or
  491. * not functioning (thus aborting the search on that branch).
  492. */
  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. /* Run _STA to determine if device is present */
  528. status = acpi_ut_execute_STA(node, &flags);
  529. if (ACPI_FAILURE(status)) {
  530. return (AE_CTRL_DEPTH);
  531. }
  532. if (!(flags & ACPI_STA_DEVICE_PRESENT) &&
  533. !(flags & ACPI_STA_DEVICE_FUNCTIONING)) {
  534. /*
  535. * Don't examine the children of the device only when the
  536. * device is neither present nor functional. See ACPI spec,
  537. * description of _STA for more information.
  538. */
  539. return (AE_CTRL_DEPTH);
  540. }
  541. /* We have a valid device, invoke the user function */
  542. status = info->user_function(obj_handle, nesting_level, info->context,
  543. return_value);
  544. return (status);
  545. }
  546. /*******************************************************************************
  547. *
  548. * FUNCTION: acpi_get_devices
  549. *
  550. * PARAMETERS: HID - HID to search for. Can be NULL.
  551. * user_function - Called when a matching object is found
  552. * Context - Passed to user function
  553. * return_value - Location where return value of
  554. * user_function is put if terminated early
  555. *
  556. * RETURNS Return value from the user_function if terminated early.
  557. * Otherwise, returns NULL.
  558. *
  559. * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
  560. * starting (and ending) at the object specified by start_handle.
  561. * The user_function is called whenever an object of type
  562. * Device is found. If the user function returns
  563. * a non-zero value, the search is terminated immediately and this
  564. * value is returned to the caller.
  565. *
  566. * This is a wrapper for walk_namespace, but the callback performs
  567. * additional filtering. Please see acpi_ns_get_device_callback.
  568. *
  569. ******************************************************************************/
  570. acpi_status
  571. acpi_get_devices(const char *HID,
  572. acpi_walk_callback user_function,
  573. void *context, void **return_value)
  574. {
  575. acpi_status status;
  576. struct acpi_get_devices_info info;
  577. ACPI_FUNCTION_TRACE(acpi_get_devices);
  578. /* Parameter validation */
  579. if (!user_function) {
  580. return_ACPI_STATUS(AE_BAD_PARAMETER);
  581. }
  582. /*
  583. * We're going to call their callback from OUR callback, so we need
  584. * to know what it is, and their context parameter.
  585. */
  586. info.hid = HID;
  587. info.context = context;
  588. info.user_function = user_function;
  589. /*
  590. * Lock the namespace around the walk.
  591. * The namespace will be unlocked/locked around each call
  592. * to the user function - since this function
  593. * must be allowed to make Acpi calls itself.
  594. */
  595. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  596. if (ACPI_FAILURE(status)) {
  597. return_ACPI_STATUS(status);
  598. }
  599. status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
  600. ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
  601. acpi_ns_get_device_callback, NULL,
  602. &info, return_value);
  603. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  604. return_ACPI_STATUS(status);
  605. }
  606. ACPI_EXPORT_SYMBOL(acpi_get_devices)
  607. /*******************************************************************************
  608. *
  609. * FUNCTION: acpi_attach_data
  610. *
  611. * PARAMETERS: obj_handle - Namespace node
  612. * Handler - Handler for this attachment
  613. * Data - Pointer to data to be attached
  614. *
  615. * RETURN: Status
  616. *
  617. * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
  618. *
  619. ******************************************************************************/
  620. acpi_status
  621. acpi_attach_data(acpi_handle obj_handle,
  622. acpi_object_handler handler, void *data)
  623. {
  624. struct acpi_namespace_node *node;
  625. acpi_status status;
  626. /* Parameter validation */
  627. if (!obj_handle || !handler || !data) {
  628. return (AE_BAD_PARAMETER);
  629. }
  630. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  631. if (ACPI_FAILURE(status)) {
  632. return (status);
  633. }
  634. /* Convert and validate the handle */
  635. node = acpi_ns_validate_handle(obj_handle);
  636. if (!node) {
  637. status = AE_BAD_PARAMETER;
  638. goto unlock_and_exit;
  639. }
  640. status = acpi_ns_attach_data(node, handler, data);
  641. unlock_and_exit:
  642. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  643. return (status);
  644. }
  645. ACPI_EXPORT_SYMBOL(acpi_attach_data)
  646. /*******************************************************************************
  647. *
  648. * FUNCTION: acpi_detach_data
  649. *
  650. * PARAMETERS: obj_handle - Namespace node handle
  651. * Handler - Handler used in call to acpi_attach_data
  652. *
  653. * RETURN: Status
  654. *
  655. * DESCRIPTION: Remove data that was previously attached to a node.
  656. *
  657. ******************************************************************************/
  658. acpi_status
  659. acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler)
  660. {
  661. struct acpi_namespace_node *node;
  662. acpi_status status;
  663. /* Parameter validation */
  664. if (!obj_handle || !handler) {
  665. return (AE_BAD_PARAMETER);
  666. }
  667. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  668. if (ACPI_FAILURE(status)) {
  669. return (status);
  670. }
  671. /* Convert and validate the handle */
  672. node = acpi_ns_validate_handle(obj_handle);
  673. if (!node) {
  674. status = AE_BAD_PARAMETER;
  675. goto unlock_and_exit;
  676. }
  677. status = acpi_ns_detach_data(node, handler);
  678. unlock_and_exit:
  679. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  680. return (status);
  681. }
  682. ACPI_EXPORT_SYMBOL(acpi_detach_data)
  683. /*******************************************************************************
  684. *
  685. * FUNCTION: acpi_get_data
  686. *
  687. * PARAMETERS: obj_handle - Namespace node
  688. * Handler - Handler used in call to attach_data
  689. * Data - Where the data is returned
  690. *
  691. * RETURN: Status
  692. *
  693. * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
  694. *
  695. ******************************************************************************/
  696. acpi_status
  697. acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data)
  698. {
  699. struct acpi_namespace_node *node;
  700. acpi_status status;
  701. /* Parameter validation */
  702. if (!obj_handle || !handler || !data) {
  703. return (AE_BAD_PARAMETER);
  704. }
  705. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  706. if (ACPI_FAILURE(status)) {
  707. return (status);
  708. }
  709. /* Convert and validate the handle */
  710. node = acpi_ns_validate_handle(obj_handle);
  711. if (!node) {
  712. status = AE_BAD_PARAMETER;
  713. goto unlock_and_exit;
  714. }
  715. status = acpi_ns_get_attached_data(node, handler, data);
  716. unlock_and_exit:
  717. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  718. return (status);
  719. }
  720. ACPI_EXPORT_SYMBOL(acpi_get_data)