nsxfobj.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 acpi_get_type(acpi_handle handle, acpi_object_type * ret_type)
  61. {
  62. struct acpi_namespace_node *node;
  63. acpi_status status;
  64. /* Parameter Validation */
  65. if (!ret_type) {
  66. return (AE_BAD_PARAMETER);
  67. }
  68. /*
  69. * Special case for the predefined Root Node
  70. * (return type ANY)
  71. */
  72. if (handle == ACPI_ROOT_OBJECT) {
  73. *ret_type = ACPI_TYPE_ANY;
  74. return (AE_OK);
  75. }
  76. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  77. if (ACPI_FAILURE(status)) {
  78. return (status);
  79. }
  80. /* Convert and validate the handle */
  81. node = acpi_ns_map_handle_to_node(handle);
  82. if (!node) {
  83. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  84. return (AE_BAD_PARAMETER);
  85. }
  86. *ret_type = node->type;
  87. status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  88. return (status);
  89. }
  90. EXPORT_SYMBOL(acpi_get_type);
  91. /*******************************************************************************
  92. *
  93. * FUNCTION: acpi_get_parent
  94. *
  95. * PARAMETERS: Handle - Handle of object whose parent is desired
  96. * ret_handle - Where the parent handle will be placed
  97. *
  98. * RETURN: Status
  99. *
  100. * DESCRIPTION: Returns a handle to the parent of the object represented by
  101. * Handle.
  102. *
  103. ******************************************************************************/
  104. acpi_status acpi_get_parent(acpi_handle handle, acpi_handle * ret_handle)
  105. {
  106. struct acpi_namespace_node *node;
  107. acpi_status status;
  108. if (!ret_handle) {
  109. return (AE_BAD_PARAMETER);
  110. }
  111. /* Special case for the predefined Root Node (no parent) */
  112. if (handle == ACPI_ROOT_OBJECT) {
  113. return (AE_NULL_ENTRY);
  114. }
  115. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  116. if (ACPI_FAILURE(status)) {
  117. return (status);
  118. }
  119. /* Convert and validate the handle */
  120. node = acpi_ns_map_handle_to_node(handle);
  121. if (!node) {
  122. status = AE_BAD_PARAMETER;
  123. goto unlock_and_exit;
  124. }
  125. /* Get the parent entry */
  126. *ret_handle =
  127. acpi_ns_convert_entry_to_handle(acpi_ns_get_parent_node(node));
  128. /* Return exception if parent is null */
  129. if (!acpi_ns_get_parent_node(node)) {
  130. status = AE_NULL_ENTRY;
  131. }
  132. unlock_and_exit:
  133. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  134. return (status);
  135. }
  136. EXPORT_SYMBOL(acpi_get_parent);
  137. /*******************************************************************************
  138. *
  139. * FUNCTION: acpi_get_next_object
  140. *
  141. * PARAMETERS: Type - Type of object to be searched for
  142. * Parent - Parent object whose children we are getting
  143. * last_child - Previous child that was found.
  144. * The NEXT child will be returned
  145. * ret_handle - Where handle to the next object is placed
  146. *
  147. * RETURN: Status
  148. *
  149. * DESCRIPTION: Return the next peer object within the namespace. If Handle is
  150. * valid, Scope is ignored. Otherwise, the first object within
  151. * Scope is returned.
  152. *
  153. ******************************************************************************/
  154. acpi_status
  155. acpi_get_next_object(acpi_object_type type,
  156. acpi_handle parent,
  157. acpi_handle child, acpi_handle * ret_handle)
  158. {
  159. acpi_status status;
  160. struct acpi_namespace_node *node;
  161. struct acpi_namespace_node *parent_node = NULL;
  162. struct acpi_namespace_node *child_node = NULL;
  163. /* Parameter validation */
  164. if (type > ACPI_TYPE_EXTERNAL_MAX) {
  165. return (AE_BAD_PARAMETER);
  166. }
  167. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  168. if (ACPI_FAILURE(status)) {
  169. return (status);
  170. }
  171. /* If null handle, use the parent */
  172. if (!child) {
  173. /* Start search at the beginning of the specified scope */
  174. parent_node = acpi_ns_map_handle_to_node(parent);
  175. if (!parent_node) {
  176. status = AE_BAD_PARAMETER;
  177. goto unlock_and_exit;
  178. }
  179. } else {
  180. /* Non-null handle, ignore the parent */
  181. /* Convert and validate the handle */
  182. child_node = acpi_ns_map_handle_to_node(child);
  183. if (!child_node) {
  184. status = AE_BAD_PARAMETER;
  185. goto unlock_and_exit;
  186. }
  187. }
  188. /* Internal function does the real work */
  189. node = acpi_ns_get_next_node(type, parent_node, child_node);
  190. if (!node) {
  191. status = AE_NOT_FOUND;
  192. goto unlock_and_exit;
  193. }
  194. if (ret_handle) {
  195. *ret_handle = acpi_ns_convert_entry_to_handle(node);
  196. }
  197. unlock_and_exit:
  198. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  199. return (status);
  200. }
  201. EXPORT_SYMBOL(acpi_get_next_object);