nsxfobj.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /*******************************************************************************
  3. *
  4. * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
  5. * ACPI Object oriented interfaces
  6. *
  7. ******************************************************************************/
  8. #define EXPORT_ACPI_INTERFACES
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #include "acnamesp.h"
  12. #define _COMPONENT ACPI_NAMESPACE
  13. ACPI_MODULE_NAME("nsxfobj")
  14. /*******************************************************************************
  15. *
  16. * FUNCTION: acpi_get_type
  17. *
  18. * PARAMETERS: handle - Handle of object whose type is desired
  19. * ret_type - Where the type will be placed
  20. *
  21. * RETURN: Status
  22. *
  23. * DESCRIPTION: This routine returns the type associated with a particular
  24. * handle
  25. *
  26. ******************************************************************************/
  27. acpi_status acpi_get_type(acpi_handle handle, acpi_object_type *ret_type)
  28. {
  29. struct acpi_namespace_node *node;
  30. acpi_status status;
  31. /* Parameter Validation */
  32. if (!ret_type) {
  33. return (AE_BAD_PARAMETER);
  34. }
  35. /* Special case for the predefined Root Node (return type ANY) */
  36. if (handle == ACPI_ROOT_OBJECT) {
  37. *ret_type = ACPI_TYPE_ANY;
  38. return (AE_OK);
  39. }
  40. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  41. if (ACPI_FAILURE(status)) {
  42. return (status);
  43. }
  44. /* Convert and validate the handle */
  45. node = acpi_ns_validate_handle(handle);
  46. if (!node) {
  47. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  48. return (AE_BAD_PARAMETER);
  49. }
  50. *ret_type = node->type;
  51. status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  52. return (status);
  53. }
  54. ACPI_EXPORT_SYMBOL(acpi_get_type)
  55. /*******************************************************************************
  56. *
  57. * FUNCTION: acpi_get_parent
  58. *
  59. * PARAMETERS: handle - Handle of object whose parent is desired
  60. * ret_handle - Where the parent handle will be placed
  61. *
  62. * RETURN: Status
  63. *
  64. * DESCRIPTION: Returns a handle to the parent of the object represented by
  65. * Handle.
  66. *
  67. ******************************************************************************/
  68. acpi_status acpi_get_parent(acpi_handle handle, acpi_handle *ret_handle)
  69. {
  70. struct acpi_namespace_node *node;
  71. struct acpi_namespace_node *parent_node;
  72. acpi_status status;
  73. if (!ret_handle) {
  74. return (AE_BAD_PARAMETER);
  75. }
  76. /* Special case for the predefined Root Node (no parent) */
  77. if (handle == ACPI_ROOT_OBJECT) {
  78. return (AE_NULL_ENTRY);
  79. }
  80. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  81. if (ACPI_FAILURE(status)) {
  82. return (status);
  83. }
  84. /* Convert and validate the handle */
  85. node = acpi_ns_validate_handle(handle);
  86. if (!node) {
  87. status = AE_BAD_PARAMETER;
  88. goto unlock_and_exit;
  89. }
  90. /* Get the parent entry */
  91. parent_node = node->parent;
  92. *ret_handle = ACPI_CAST_PTR(acpi_handle, parent_node);
  93. /* Return exception if parent is null */
  94. if (!parent_node) {
  95. status = AE_NULL_ENTRY;
  96. }
  97. unlock_and_exit:
  98. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  99. return (status);
  100. }
  101. ACPI_EXPORT_SYMBOL(acpi_get_parent)
  102. /*******************************************************************************
  103. *
  104. * FUNCTION: acpi_get_next_object
  105. *
  106. * PARAMETERS: type - Type of object to be searched for
  107. * parent - Parent object whose children we are getting
  108. * last_child - Previous child that was found.
  109. * The NEXT child will be returned
  110. * ret_handle - Where handle to the next object is placed
  111. *
  112. * RETURN: Status
  113. *
  114. * DESCRIPTION: Return the next peer object within the namespace. If Handle is
  115. * valid, Scope is ignored. Otherwise, the first object within
  116. * Scope is returned.
  117. *
  118. ******************************************************************************/
  119. acpi_status
  120. acpi_get_next_object(acpi_object_type type,
  121. acpi_handle parent,
  122. acpi_handle child, acpi_handle *ret_handle)
  123. {
  124. acpi_status status;
  125. struct acpi_namespace_node *node;
  126. struct acpi_namespace_node *parent_node = NULL;
  127. struct acpi_namespace_node *child_node = NULL;
  128. /* Parameter validation */
  129. if (type > ACPI_TYPE_EXTERNAL_MAX) {
  130. return (AE_BAD_PARAMETER);
  131. }
  132. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  133. if (ACPI_FAILURE(status)) {
  134. return (status);
  135. }
  136. /* If null handle, use the parent */
  137. if (!child) {
  138. /* Start search at the beginning of the specified scope */
  139. parent_node = acpi_ns_validate_handle(parent);
  140. if (!parent_node) {
  141. status = AE_BAD_PARAMETER;
  142. goto unlock_and_exit;
  143. }
  144. } else {
  145. /* Non-null handle, ignore the parent */
  146. /* Convert and validate the handle */
  147. child_node = acpi_ns_validate_handle(child);
  148. if (!child_node) {
  149. status = AE_BAD_PARAMETER;
  150. goto unlock_and_exit;
  151. }
  152. }
  153. /* Internal function does the real work */
  154. node = acpi_ns_get_next_node_typed(type, parent_node, child_node);
  155. if (!node) {
  156. status = AE_NOT_FOUND;
  157. goto unlock_and_exit;
  158. }
  159. if (ret_handle) {
  160. *ret_handle = ACPI_CAST_PTR(acpi_handle, node);
  161. }
  162. unlock_and_exit:
  163. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  164. return (status);
  165. }
  166. ACPI_EXPORT_SYMBOL(acpi_get_next_object)