nsxfobj.c 7.0 KB

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