utxfmutex.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*******************************************************************************
  2. *
  3. * Module Name: utxfmutex - external AML mutex access functions
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2012, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acnamesp.h"
  45. #define _COMPONENT ACPI_UTILITIES
  46. ACPI_MODULE_NAME("utxfmutex")
  47. /* Local prototypes */
  48. static acpi_status
  49. acpi_ut_get_mutex_object(acpi_handle handle,
  50. acpi_string pathname,
  51. union acpi_operand_object **ret_obj);
  52. /*******************************************************************************
  53. *
  54. * FUNCTION: acpi_ut_get_mutex_object
  55. *
  56. * PARAMETERS: Handle - Mutex or prefix handle (optional)
  57. * Pathname - Mutex pathname (optional)
  58. * ret_obj - Where the mutex object is returned
  59. *
  60. * RETURN: Status
  61. *
  62. * DESCRIPTION: Get an AML mutex object. The mutex node is pointed to by
  63. * Handle:Pathname. Either Handle or Pathname can be NULL, but
  64. * not both.
  65. *
  66. ******************************************************************************/
  67. static acpi_status
  68. acpi_ut_get_mutex_object(acpi_handle handle,
  69. acpi_string pathname,
  70. union acpi_operand_object **ret_obj)
  71. {
  72. struct acpi_namespace_node *mutex_node;
  73. union acpi_operand_object *mutex_obj;
  74. acpi_status status;
  75. /* Parameter validation */
  76. if (!ret_obj || (!handle && !pathname)) {
  77. return (AE_BAD_PARAMETER);
  78. }
  79. /* Get a the namespace node for the mutex */
  80. mutex_node = handle;
  81. if (pathname != NULL) {
  82. status = acpi_get_handle(handle, pathname,
  83. ACPI_CAST_PTR(acpi_handle,
  84. &mutex_node));
  85. if (ACPI_FAILURE(status)) {
  86. return (status);
  87. }
  88. }
  89. /* Ensure that we actually have a Mutex object */
  90. if (!mutex_node || (mutex_node->type != ACPI_TYPE_MUTEX)) {
  91. return (AE_TYPE);
  92. }
  93. /* Get the low-level mutex object */
  94. mutex_obj = acpi_ns_get_attached_object(mutex_node);
  95. if (!mutex_obj) {
  96. return (AE_NULL_OBJECT);
  97. }
  98. *ret_obj = mutex_obj;
  99. return (AE_OK);
  100. }
  101. /*******************************************************************************
  102. *
  103. * FUNCTION: acpi_acquire_mutex
  104. *
  105. * PARAMETERS: Handle - Mutex or prefix handle (optional)
  106. * Pathname - Mutex pathname (optional)
  107. * Timeout - Max time to wait for the lock (millisec)
  108. *
  109. * RETURN: Status
  110. *
  111. * DESCRIPTION: Acquire an AML mutex. This is a device driver interface to
  112. * AML mutex objects, and allows for transaction locking between
  113. * drivers and AML code. The mutex node is pointed to by
  114. * Handle:Pathname. Either Handle or Pathname can be NULL, but
  115. * not both.
  116. *
  117. ******************************************************************************/
  118. acpi_status
  119. acpi_acquire_mutex(acpi_handle handle, acpi_string pathname, u16 timeout)
  120. {
  121. acpi_status status;
  122. union acpi_operand_object *mutex_obj;
  123. /* Get the low-level mutex associated with Handle:Pathname */
  124. status = acpi_ut_get_mutex_object(handle, pathname, &mutex_obj);
  125. if (ACPI_FAILURE(status)) {
  126. return (status);
  127. }
  128. /* Acquire the OS mutex */
  129. status = acpi_os_acquire_mutex(mutex_obj->mutex.os_mutex, timeout);
  130. return (status);
  131. }
  132. /*******************************************************************************
  133. *
  134. * FUNCTION: acpi_release_mutex
  135. *
  136. * PARAMETERS: Handle - Mutex or prefix handle (optional)
  137. * Pathname - Mutex pathname (optional)
  138. *
  139. * RETURN: Status
  140. *
  141. * DESCRIPTION: Release an AML mutex. This is a device driver interface to
  142. * AML mutex objects, and allows for transaction locking between
  143. * drivers and AML code. The mutex node is pointed to by
  144. * Handle:Pathname. Either Handle or Pathname can be NULL, but
  145. * not both.
  146. *
  147. ******************************************************************************/
  148. acpi_status acpi_release_mutex(acpi_handle handle, acpi_string pathname)
  149. {
  150. acpi_status status;
  151. union acpi_operand_object *mutex_obj;
  152. /* Get the low-level mutex associated with Handle:Pathname */
  153. status = acpi_ut_get_mutex_object(handle, pathname, &mutex_obj);
  154. if (ACPI_FAILURE(status)) {
  155. return (status);
  156. }
  157. /* Release the OS mutex */
  158. acpi_os_release_mutex(mutex_obj->mutex.os_mutex);
  159. return (AE_OK);
  160. }