Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / acpi / acpica / utxfmutex.c
blobbe24db2544ce1f6cc934ec980f53a63b61459cfd
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
4 * Module Name: utxfmutex - external AML mutex access functions
6 ******************************************************************************/
8 #include <acpi/acpi.h>
9 #include "accommon.h"
10 #include "acnamesp.h"
12 #define _COMPONENT ACPI_UTILITIES
13 ACPI_MODULE_NAME("utxfmutex")
15 /* Local prototypes */
16 static acpi_status
17 acpi_ut_get_mutex_object(acpi_handle handle,
18 acpi_string pathname,
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
29 * RETURN: Status
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
33 * not both.
35 ******************************************************************************/
37 static acpi_status
38 acpi_ut_get_mutex_object(acpi_handle handle,
39 acpi_string pathname,
40 union acpi_operand_object **ret_obj)
42 struct acpi_namespace_node *mutex_node;
43 union acpi_operand_object *mutex_obj;
44 acpi_status status;
46 /* Parameter validation */
48 if (!ret_obj || (!handle && !pathname)) {
49 return (AE_BAD_PARAMETER);
52 /* Get a the namespace node for the mutex */
54 mutex_node = handle;
55 if (pathname != NULL) {
56 status =
57 acpi_get_handle(handle, pathname,
58 ACPI_CAST_PTR(acpi_handle, &mutex_node));
59 if (ACPI_FAILURE(status)) {
60 return (status);
64 /* Ensure that we actually have a Mutex object */
66 if (!mutex_node || (mutex_node->type != ACPI_TYPE_MUTEX)) {
67 return (AE_TYPE);
70 /* Get the low-level mutex object */
72 mutex_obj = acpi_ns_get_attached_object(mutex_node);
73 if (!mutex_obj) {
74 return (AE_NULL_OBJECT);
77 *ret_obj = mutex_obj;
78 return (AE_OK);
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)
89 * RETURN: Status
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
95 * not both.
97 ******************************************************************************/
99 acpi_status
100 acpi_acquire_mutex(acpi_handle handle, acpi_string pathname, u16 timeout)
102 acpi_status status;
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)) {
109 return (status);
112 /* Acquire the OS mutex */
114 status = acpi_os_acquire_mutex(mutex_obj->mutex.os_mutex, timeout);
115 return (status);
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)
127 * RETURN: Status
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
133 * not both.
135 ******************************************************************************/
136 acpi_status acpi_release_mutex(acpi_handle handle, acpi_string pathname)
138 acpi_status status;
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)) {
145 return (status);
148 /* Release the OS mutex */
150 acpi_os_release_mutex(mutex_obj->mutex.os_mutex);
151 return (AE_OK);
154 ACPI_EXPORT_SYMBOL(acpi_release_mutex)