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