nsxfobj.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*******************************************************************************
  2. *
  3. * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
  4. * ACPI Object oriented 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. #define _COMPONENT ACPI_NAMESPACE
  46. ACPI_MODULE_NAME("nsxfobj")
  47. /*******************************************************************************
  48. *
  49. * FUNCTION: acpi_get_id
  50. *
  51. * PARAMETERS: Handle - Handle of object whose id is desired
  52. * ret_id - Where the id will be placed
  53. *
  54. * RETURN: Status
  55. *
  56. * DESCRIPTION: This routine returns the owner id associated with a handle
  57. *
  58. ******************************************************************************/
  59. acpi_status acpi_get_id(acpi_handle handle, acpi_owner_id * ret_id)
  60. {
  61. struct acpi_namespace_node *node;
  62. acpi_status status;
  63. /* Parameter Validation */
  64. if (!ret_id) {
  65. return (AE_BAD_PARAMETER);
  66. }
  67. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  68. if (ACPI_FAILURE(status)) {
  69. return (status);
  70. }
  71. /* Convert and validate the handle */
  72. node = acpi_ns_map_handle_to_node(handle);
  73. if (!node) {
  74. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  75. return (AE_BAD_PARAMETER);
  76. }
  77. *ret_id = node->owner_id;
  78. status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  79. return (status);
  80. }
  81. ACPI_EXPORT_SYMBOL(acpi_get_id)
  82. /*******************************************************************************
  83. *
  84. * FUNCTION: acpi_get_type
  85. *
  86. * PARAMETERS: Handle - Handle of object whose type is desired
  87. * ret_type - Where the type will be placed
  88. *
  89. * RETURN: Status
  90. *
  91. * DESCRIPTION: This routine returns the type associatd with a particular handle
  92. *
  93. ******************************************************************************/
  94. acpi_status acpi_get_type(acpi_handle handle, acpi_object_type * ret_type)
  95. {
  96. struct acpi_namespace_node *node;
  97. acpi_status status;
  98. /* Parameter Validation */
  99. if (!ret_type) {
  100. return (AE_BAD_PARAMETER);
  101. }
  102. /*
  103. * Special case for the predefined Root Node
  104. * (return type ANY)
  105. */
  106. if (handle == ACPI_ROOT_OBJECT) {
  107. *ret_type = ACPI_TYPE_ANY;
  108. return (AE_OK);
  109. }
  110. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  111. if (ACPI_FAILURE(status)) {
  112. return (status);
  113. }
  114. /* Convert and validate the handle */
  115. node = acpi_ns_map_handle_to_node(handle);
  116. if (!node) {
  117. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  118. return (AE_BAD_PARAMETER);
  119. }
  120. *ret_type = node->type;
  121. status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  122. return (status);
  123. }
  124. ACPI_EXPORT_SYMBOL(acpi_get_type)
  125. /*******************************************************************************
  126. *
  127. * FUNCTION: acpi_get_parent
  128. *
  129. * PARAMETERS: Handle - Handle of object whose parent is desired
  130. * ret_handle - Where the parent handle will be placed
  131. *
  132. * RETURN: Status
  133. *
  134. * DESCRIPTION: Returns a handle to the parent of the object represented by
  135. * Handle.
  136. *
  137. ******************************************************************************/
  138. acpi_status acpi_get_parent(acpi_handle handle, acpi_handle * ret_handle)
  139. {
  140. struct acpi_namespace_node *node;
  141. acpi_status status;
  142. if (!ret_handle) {
  143. return (AE_BAD_PARAMETER);
  144. }
  145. /* Special case for the predefined Root Node (no parent) */
  146. if (handle == ACPI_ROOT_OBJECT) {
  147. return (AE_NULL_ENTRY);
  148. }
  149. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  150. if (ACPI_FAILURE(status)) {
  151. return (status);
  152. }
  153. /* Convert and validate the handle */
  154. node = acpi_ns_map_handle_to_node(handle);
  155. if (!node) {
  156. status = AE_BAD_PARAMETER;
  157. goto unlock_and_exit;
  158. }
  159. /* Get the parent entry */
  160. *ret_handle =
  161. acpi_ns_convert_entry_to_handle(acpi_ns_get_parent_node(node));
  162. /* Return exception if parent is null */
  163. if (!acpi_ns_get_parent_node(node)) {
  164. status = AE_NULL_ENTRY;
  165. }
  166. unlock_and_exit:
  167. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  168. return (status);
  169. }
  170. ACPI_EXPORT_SYMBOL(acpi_get_parent)
  171. /*******************************************************************************
  172. *
  173. * FUNCTION: acpi_get_next_object
  174. *
  175. * PARAMETERS: Type - Type of object to be searched for
  176. * Parent - Parent object whose children we are getting
  177. * last_child - Previous child that was found.
  178. * The NEXT child will be returned
  179. * ret_handle - Where handle to the next object is placed
  180. *
  181. * RETURN: Status
  182. *
  183. * DESCRIPTION: Return the next peer object within the namespace. If Handle is
  184. * valid, Scope is ignored. Otherwise, the first object within
  185. * Scope is returned.
  186. *
  187. ******************************************************************************/
  188. acpi_status
  189. acpi_get_next_object(acpi_object_type type,
  190. acpi_handle parent,
  191. acpi_handle child, acpi_handle * ret_handle)
  192. {
  193. acpi_status status;
  194. struct acpi_namespace_node *node;
  195. struct acpi_namespace_node *parent_node = NULL;
  196. struct acpi_namespace_node *child_node = NULL;
  197. /* Parameter validation */
  198. if (type > ACPI_TYPE_EXTERNAL_MAX) {
  199. return (AE_BAD_PARAMETER);
  200. }
  201. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  202. if (ACPI_FAILURE(status)) {
  203. return (status);
  204. }
  205. /* If null handle, use the parent */
  206. if (!child) {
  207. /* Start search at the beginning of the specified scope */
  208. parent_node = acpi_ns_map_handle_to_node(parent);
  209. if (!parent_node) {
  210. status = AE_BAD_PARAMETER;
  211. goto unlock_and_exit;
  212. }
  213. } else {
  214. /* Non-null handle, ignore the parent */
  215. /* Convert and validate the handle */
  216. child_node = acpi_ns_map_handle_to_node(child);
  217. if (!child_node) {
  218. status = AE_BAD_PARAMETER;
  219. goto unlock_and_exit;
  220. }
  221. }
  222. /* Internal function does the real work */
  223. node = acpi_ns_get_next_node(type, parent_node, child_node);
  224. if (!node) {
  225. status = AE_NOT_FOUND;
  226. goto unlock_and_exit;
  227. }
  228. if (ret_handle) {
  229. *ret_handle = acpi_ns_convert_entry_to_handle(node);
  230. }
  231. unlock_and_exit:
  232. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  233. return (status);
  234. }
  235. ACPI_EXPORT_SYMBOL(acpi_get_next_object)