nsxfobj.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 associatd with a particular handle
  24. *
  25. ******************************************************************************/
  26. acpi_status acpi_get_type(acpi_handle handle, acpi_object_type *ret_type)
  27. {
  28. struct acpi_namespace_node *node;
  29. acpi_status status;
  30. /* Parameter Validation */
  31. if (!ret_type) {
  32. return (AE_BAD_PARAMETER);
  33. }
  34. /* Special case for the predefined Root Node (return type ANY) */
  35. if (handle == ACPI_ROOT_OBJECT) {
  36. *ret_type = ACPI_TYPE_ANY;
  37. return (AE_OK);
  38. }
  39. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  40. if (ACPI_FAILURE(status)) {
  41. return (status);
  42. }
  43. /* Convert and validate the handle */
  44. node = acpi_ns_validate_handle(handle);
  45. if (!node) {
  46. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  47. return (AE_BAD_PARAMETER);
  48. }
  49. *ret_type = node->type;
  50. status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  51. return (status);
  52. }
  53. ACPI_EXPORT_SYMBOL(acpi_get_type)
  54. /*******************************************************************************
  55. *
  56. * FUNCTION: acpi_get_parent
  57. *
  58. * PARAMETERS: handle - Handle of object whose parent is desired
  59. * ret_handle - Where the parent handle will be placed
  60. *
  61. * RETURN: Status
  62. *
  63. * DESCRIPTION: Returns a handle to the parent of the object represented by
  64. * Handle.
  65. *
  66. ******************************************************************************/
  67. acpi_status acpi_get_parent(acpi_handle handle, acpi_handle *ret_handle)
  68. {
  69. struct acpi_namespace_node *node;
  70. struct acpi_namespace_node *parent_node;
  71. acpi_status status;
  72. if (!ret_handle) {
  73. return (AE_BAD_PARAMETER);
  74. }
  75. /* Special case for the predefined Root Node (no parent) */
  76. if (handle == ACPI_ROOT_OBJECT) {
  77. return (AE_NULL_ENTRY);
  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_validate_handle(handle);
  85. if (!node) {
  86. status = AE_BAD_PARAMETER;
  87. goto unlock_and_exit;
  88. }
  89. /* Get the parent entry */
  90. parent_node = node->parent;
  91. *ret_handle = ACPI_CAST_PTR(acpi_handle, parent_node);
  92. /* Return exception if parent is null */
  93. if (!parent_node) {
  94. status = AE_NULL_ENTRY;
  95. }
  96. unlock_and_exit:
  97. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  98. return (status);
  99. }
  100. ACPI_EXPORT_SYMBOL(acpi_get_parent)
  101. /*******************************************************************************
  102. *
  103. * FUNCTION: acpi_get_next_object
  104. *
  105. * PARAMETERS: type - Type of object to be searched for
  106. * parent - Parent object whose children we are getting
  107. * last_child - Previous child that was found.
  108. * The NEXT child will be returned
  109. * ret_handle - Where handle to the next object is placed
  110. *
  111. * RETURN: Status
  112. *
  113. * DESCRIPTION: Return the next peer object within the namespace. If Handle is
  114. * valid, Scope is ignored. Otherwise, the first object within
  115. * Scope is returned.
  116. *
  117. ******************************************************************************/
  118. acpi_status
  119. acpi_get_next_object(acpi_object_type type,
  120. acpi_handle parent,
  121. acpi_handle child, acpi_handle *ret_handle)
  122. {
  123. acpi_status status;
  124. struct acpi_namespace_node *node;
  125. struct acpi_namespace_node *parent_node = NULL;
  126. struct acpi_namespace_node *child_node = NULL;
  127. /* Parameter validation */
  128. if (type > ACPI_TYPE_EXTERNAL_MAX) {
  129. return (AE_BAD_PARAMETER);
  130. }
  131. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  132. if (ACPI_FAILURE(status)) {
  133. return (status);
  134. }
  135. /* If null handle, use the parent */
  136. if (!child) {
  137. /* Start search at the beginning of the specified scope */
  138. parent_node = acpi_ns_validate_handle(parent);
  139. if (!parent_node) {
  140. status = AE_BAD_PARAMETER;
  141. goto unlock_and_exit;
  142. }
  143. } else {
  144. /* Non-null handle, ignore the parent */
  145. /* Convert and validate the handle */
  146. child_node = acpi_ns_validate_handle(child);
  147. if (!child_node) {
  148. status = AE_BAD_PARAMETER;
  149. goto unlock_and_exit;
  150. }
  151. }
  152. /* Internal function does the real work */
  153. node = acpi_ns_get_next_node_typed(type, parent_node, child_node);
  154. if (!node) {
  155. status = AE_NOT_FOUND;
  156. goto unlock_and_exit;
  157. }
  158. if (ret_handle) {
  159. *ret_handle = ACPI_CAST_PTR(acpi_handle, node);
  160. }
  161. unlock_and_exit:
  162. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  163. return (status);
  164. }
  165. ACPI_EXPORT_SYMBOL(acpi_get_next_object)