utxfmutex.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /*******************************************************************************
  3. *
  4. * Module Name: utxfmutex - external AML mutex access functions
  5. *
  6. ******************************************************************************/
  7. #include <acpi/acpi.h>
  8. #include "accommon.h"
  9. #include "acnamesp.h"
  10. #define _COMPONENT ACPI_UTILITIES
  11. ACPI_MODULE_NAME("utxfmutex")
  12. /* Local prototypes */
  13. static acpi_status
  14. acpi_ut_get_mutex_object(acpi_handle handle,
  15. acpi_string pathname,
  16. union acpi_operand_object **ret_obj);
  17. /*******************************************************************************
  18. *
  19. * FUNCTION: acpi_ut_get_mutex_object
  20. *
  21. * PARAMETERS: handle - Mutex or prefix handle (optional)
  22. * pathname - Mutex pathname (optional)
  23. * ret_obj - Where the mutex object is returned
  24. *
  25. * RETURN: Status
  26. *
  27. * DESCRIPTION: Get an AML mutex object. The mutex node is pointed to by
  28. * Handle:Pathname. Either Handle or Pathname can be NULL, but
  29. * not both.
  30. *
  31. ******************************************************************************/
  32. static acpi_status
  33. acpi_ut_get_mutex_object(acpi_handle handle,
  34. acpi_string pathname,
  35. union acpi_operand_object **ret_obj)
  36. {
  37. struct acpi_namespace_node *mutex_node;
  38. union acpi_operand_object *mutex_obj;
  39. acpi_status status;
  40. /* Parameter validation */
  41. if (!ret_obj || (!handle && !pathname)) {
  42. return (AE_BAD_PARAMETER);
  43. }
  44. /* Get a the namespace node for the mutex */
  45. mutex_node = handle;
  46. if (pathname != NULL) {
  47. status =
  48. acpi_get_handle(handle, pathname,
  49. ACPI_CAST_PTR(acpi_handle, &mutex_node));
  50. if (ACPI_FAILURE(status)) {
  51. return (status);
  52. }
  53. }
  54. /* Ensure that we actually have a Mutex object */
  55. if (!mutex_node || (mutex_node->type != ACPI_TYPE_MUTEX)) {
  56. return (AE_TYPE);
  57. }
  58. /* Get the low-level mutex object */
  59. mutex_obj = acpi_ns_get_attached_object(mutex_node);
  60. if (!mutex_obj) {
  61. return (AE_NULL_OBJECT);
  62. }
  63. *ret_obj = mutex_obj;
  64. return (AE_OK);
  65. }
  66. /*******************************************************************************
  67. *
  68. * FUNCTION: acpi_acquire_mutex
  69. *
  70. * PARAMETERS: handle - Mutex or prefix handle (optional)
  71. * pathname - Mutex pathname (optional)
  72. * timeout - Max time to wait for the lock (millisec)
  73. *
  74. * RETURN: Status
  75. *
  76. * DESCRIPTION: Acquire an AML mutex. This is a device driver interface to
  77. * AML mutex objects, and allows for transaction locking between
  78. * drivers and AML code. The mutex node is pointed to by
  79. * Handle:Pathname. Either Handle or Pathname can be NULL, but
  80. * not both.
  81. *
  82. ******************************************************************************/
  83. acpi_status
  84. acpi_acquire_mutex(acpi_handle handle, acpi_string pathname, u16 timeout)
  85. {
  86. acpi_status status;
  87. union acpi_operand_object *mutex_obj;
  88. /* Get the low-level mutex associated with Handle:Pathname */
  89. status = acpi_ut_get_mutex_object(handle, pathname, &mutex_obj);
  90. if (ACPI_FAILURE(status)) {
  91. return (status);
  92. }
  93. /* Acquire the OS mutex */
  94. status = acpi_os_acquire_mutex(mutex_obj->mutex.os_mutex, timeout);
  95. return (status);
  96. }
  97. ACPI_EXPORT_SYMBOL(acpi_acquire_mutex)
  98. /*******************************************************************************
  99. *
  100. * FUNCTION: acpi_release_mutex
  101. *
  102. * PARAMETERS: handle - Mutex or prefix handle (optional)
  103. * pathname - Mutex pathname (optional)
  104. *
  105. * RETURN: Status
  106. *
  107. * DESCRIPTION: Release an AML mutex. This is a device driver interface to
  108. * AML mutex objects, and allows for transaction locking between
  109. * drivers and AML code. The mutex node is pointed to by
  110. * Handle:Pathname. Either Handle or Pathname can be NULL, but
  111. * not both.
  112. *
  113. ******************************************************************************/
  114. acpi_status acpi_release_mutex(acpi_handle handle, acpi_string pathname)
  115. {
  116. acpi_status status;
  117. union acpi_operand_object *mutex_obj;
  118. /* Get the low-level mutex associated with Handle:Pathname */
  119. status = acpi_ut_get_mutex_object(handle, pathname, &mutex_obj);
  120. if (ACPI_FAILURE(status)) {
  121. return (status);
  122. }
  123. /* Release the OS mutex */
  124. acpi_os_release_mutex(mutex_obj->mutex.os_mutex);
  125. return (AE_OK);
  126. }
  127. ACPI_EXPORT_SYMBOL(acpi_release_mutex)