1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
4 * Module Name: utxfmutex - external AML mutex access functions
6 ******************************************************************************/
12 #define _COMPONENT ACPI_UTILITIES
13 ACPI_MODULE_NAME("utxfmutex")
15 /* Local prototypes */
17 acpi_ut_get_mutex_object(acpi_handle handle
,
19 union acpi_operand_object
**ret_obj
);
21 /*******************************************************************************
23 * FUNCTION: acpi_ut_get_mutex_object
25 * PARAMETERS: handle - Mutex or prefix handle (optional)
26 * pathname - Mutex pathname (optional)
27 * ret_obj - Where the mutex object is returned
31 * DESCRIPTION: Get an AML mutex object. The mutex node is pointed to by
32 * Handle:Pathname. Either Handle or Pathname can be NULL, but
35 ******************************************************************************/
38 acpi_ut_get_mutex_object(acpi_handle handle
,
40 union acpi_operand_object
**ret_obj
)
42 struct acpi_namespace_node
*mutex_node
;
43 union acpi_operand_object
*mutex_obj
;
46 /* Parameter validation */
48 if (!ret_obj
|| (!handle
&& !pathname
)) {
49 return (AE_BAD_PARAMETER
);
52 /* Get a the namespace node for the mutex */
55 if (pathname
!= NULL
) {
57 acpi_get_handle(handle
, pathname
,
58 ACPI_CAST_PTR(acpi_handle
, &mutex_node
));
59 if (ACPI_FAILURE(status
)) {
64 /* Ensure that we actually have a Mutex object */
66 if (!mutex_node
|| (mutex_node
->type
!= ACPI_TYPE_MUTEX
)) {
70 /* Get the low-level mutex object */
72 mutex_obj
= acpi_ns_get_attached_object(mutex_node
);
74 return (AE_NULL_OBJECT
);
81 /*******************************************************************************
83 * FUNCTION: acpi_acquire_mutex
85 * PARAMETERS: handle - Mutex or prefix handle (optional)
86 * pathname - Mutex pathname (optional)
87 * timeout - Max time to wait for the lock (millisec)
91 * DESCRIPTION: Acquire an AML mutex. This is a device driver interface to
92 * AML mutex objects, and allows for transaction locking between
93 * drivers and AML code. The mutex node is pointed to by
94 * Handle:Pathname. Either Handle or Pathname can be NULL, but
97 ******************************************************************************/
100 acpi_acquire_mutex(acpi_handle handle
, acpi_string pathname
, u16 timeout
)
103 union acpi_operand_object
*mutex_obj
;
105 /* Get the low-level mutex associated with Handle:Pathname */
107 status
= acpi_ut_get_mutex_object(handle
, pathname
, &mutex_obj
);
108 if (ACPI_FAILURE(status
)) {
112 /* Acquire the OS mutex */
114 status
= acpi_os_acquire_mutex(mutex_obj
->mutex
.os_mutex
, timeout
);
118 ACPI_EXPORT_SYMBOL(acpi_acquire_mutex
)
120 /*******************************************************************************
122 * FUNCTION: acpi_release_mutex
124 * PARAMETERS: handle - Mutex or prefix handle (optional)
125 * pathname - Mutex pathname (optional)
129 * DESCRIPTION: Release an AML mutex. This is a device driver interface to
130 * AML mutex objects, and allows for transaction locking between
131 * drivers and AML code. The mutex node is pointed to by
132 * Handle:Pathname. Either Handle or Pathname can be NULL, but
135 ******************************************************************************/
136 acpi_status
acpi_release_mutex(acpi_handle handle
, acpi_string pathname
)
139 union acpi_operand_object
*mutex_obj
;
141 /* Get the low-level mutex associated with Handle:Pathname */
143 status
= acpi_ut_get_mutex_object(handle
, pathname
, &mutex_obj
);
144 if (ACPI_FAILURE(status
)) {
148 /* Release the OS mutex */
150 acpi_os_release_mutex(mutex_obj
->mutex
.os_mutex
);
154 ACPI_EXPORT_SYMBOL(acpi_release_mutex
)