nsxfobj.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*******************************************************************************
  2. *
  3. * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
  4. * ACPI Object oriented interfaces
  5. *
  6. ******************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2005, R. Byron Moore
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions, and the following disclaimer,
  16. * without modification.
  17. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18. * substantially similar to the "NO WARRANTY" disclaimer below
  19. * ("Disclaimer") and any redistribution must be conditioned upon
  20. * including a substantially similar Disclaimer requirement for further
  21. * binary redistribution.
  22. * 3. Neither the names of the above-listed copyright holders nor the names
  23. * of any contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * Alternatively, this software may be distributed under the terms of the
  27. * GNU General Public License ("GPL") version 2 as published by the Free
  28. * Software Foundation.
  29. *
  30. * NO WARRANTY
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  34. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  35. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  40. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. * POSSIBILITY OF SUCH DAMAGES.
  42. */
  43. #include <linux/module.h>
  44. #include <acpi/acpi.h>
  45. #include <acpi/acnamesp.h>
  46. #define _COMPONENT ACPI_NAMESPACE
  47. ACPI_MODULE_NAME ("nsxfobj")
  48. /*******************************************************************************
  49. *
  50. * FUNCTION: acpi_get_type
  51. *
  52. * PARAMETERS: Handle - Handle of object whose type is desired
  53. * *ret_type - Where the type will be placed
  54. *
  55. * RETURN: Status
  56. *
  57. * DESCRIPTION: This routine returns the type associatd with a particular handle
  58. *
  59. ******************************************************************************/
  60. acpi_status
  61. acpi_get_type (
  62. acpi_handle handle,
  63. acpi_object_type *ret_type)
  64. {
  65. struct acpi_namespace_node *node;
  66. acpi_status status;
  67. /* Parameter Validation */
  68. if (!ret_type) {
  69. return (AE_BAD_PARAMETER);
  70. }
  71. /*
  72. * Special case for the predefined Root Node
  73. * (return type ANY)
  74. */
  75. if (handle == ACPI_ROOT_OBJECT) {
  76. *ret_type = ACPI_TYPE_ANY;
  77. return (AE_OK);
  78. }
  79. status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
  80. if (ACPI_FAILURE (status)) {
  81. return (status);
  82. }
  83. /* Convert and validate the handle */
  84. node = acpi_ns_map_handle_to_node (handle);
  85. if (!node) {
  86. (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
  87. return (AE_BAD_PARAMETER);
  88. }
  89. *ret_type = node->type;
  90. status = acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
  91. return (status);
  92. }
  93. EXPORT_SYMBOL(acpi_get_type);
  94. /*******************************************************************************
  95. *
  96. * FUNCTION: acpi_get_parent
  97. *
  98. * PARAMETERS: Handle - Handle of object whose parent is desired
  99. * ret_handle - Where the parent handle will be placed
  100. *
  101. * RETURN: Status
  102. *
  103. * DESCRIPTION: Returns a handle to the parent of the object represented by
  104. * Handle.
  105. *
  106. ******************************************************************************/
  107. acpi_status
  108. acpi_get_parent (
  109. acpi_handle handle,
  110. acpi_handle *ret_handle)
  111. {
  112. struct acpi_namespace_node *node;
  113. acpi_status status;
  114. if (!ret_handle) {
  115. return (AE_BAD_PARAMETER);
  116. }
  117. /* Special case for the predefined Root Node (no parent) */
  118. if (handle == ACPI_ROOT_OBJECT) {
  119. return (AE_NULL_ENTRY);
  120. }
  121. status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
  122. if (ACPI_FAILURE (status)) {
  123. return (status);
  124. }
  125. /* Convert and validate the handle */
  126. node = acpi_ns_map_handle_to_node (handle);
  127. if (!node) {
  128. status = AE_BAD_PARAMETER;
  129. goto unlock_and_exit;
  130. }
  131. /* Get the parent entry */
  132. *ret_handle =
  133. acpi_ns_convert_entry_to_handle (acpi_ns_get_parent_node (node));
  134. /* Return exception if parent is null */
  135. if (!acpi_ns_get_parent_node (node)) {
  136. status = AE_NULL_ENTRY;
  137. }
  138. unlock_and_exit:
  139. (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
  140. return (status);
  141. }
  142. EXPORT_SYMBOL(acpi_get_parent);
  143. /*******************************************************************************
  144. *
  145. * FUNCTION: acpi_get_next_object
  146. *
  147. * PARAMETERS: Type - Type of object to be searched for
  148. * Parent - Parent object whose children we are getting
  149. * last_child - Previous child that was found.
  150. * The NEXT child will be returned
  151. * ret_handle - Where handle to the next object is placed
  152. *
  153. * RETURN: Status
  154. *
  155. * DESCRIPTION: Return the next peer object within the namespace. If Handle is
  156. * valid, Scope is ignored. Otherwise, the first object within
  157. * Scope is returned.
  158. *
  159. ******************************************************************************/
  160. acpi_status
  161. acpi_get_next_object (
  162. acpi_object_type type,
  163. acpi_handle parent,
  164. acpi_handle child,
  165. acpi_handle *ret_handle)
  166. {
  167. acpi_status status;
  168. struct acpi_namespace_node *node;
  169. struct acpi_namespace_node *parent_node = NULL;
  170. struct acpi_namespace_node *child_node = NULL;
  171. /* Parameter validation */
  172. if (type > ACPI_TYPE_EXTERNAL_MAX) {
  173. return (AE_BAD_PARAMETER);
  174. }
  175. status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
  176. if (ACPI_FAILURE (status)) {
  177. return (status);
  178. }
  179. /* If null handle, use the parent */
  180. if (!child) {
  181. /* Start search at the beginning of the specified scope */
  182. parent_node = acpi_ns_map_handle_to_node (parent);
  183. if (!parent_node) {
  184. status = AE_BAD_PARAMETER;
  185. goto unlock_and_exit;
  186. }
  187. }
  188. else {
  189. /* Non-null handle, ignore the parent */
  190. /* Convert and validate the handle */
  191. child_node = acpi_ns_map_handle_to_node (child);
  192. if (!child_node) {
  193. status = AE_BAD_PARAMETER;
  194. goto unlock_and_exit;
  195. }
  196. }
  197. /* Internal function does the real work */
  198. node = acpi_ns_get_next_node (type, parent_node, child_node);
  199. if (!node) {
  200. status = AE_NOT_FOUND;
  201. goto unlock_and_exit;
  202. }
  203. if (ret_handle) {
  204. *ret_handle = acpi_ns_convert_entry_to_handle (node);
  205. }
  206. unlock_and_exit:
  207. (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
  208. return (status);
  209. }
  210. EXPORT_SYMBOL(acpi_get_next_object);