^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: utmutex - local mutex support
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define _COMPONENT ACPI_UTILITIES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) ACPI_MODULE_NAME("utmutex")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) /* Local prototypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) static acpi_status acpi_ut_create_mutex(acpi_mutex_handle mutex_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) static void acpi_ut_delete_mutex(acpi_mutex_handle mutex_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * FUNCTION: acpi_ut_mutex_initialize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * PARAMETERS: None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * DESCRIPTION: Create the system mutex objects. This includes mutexes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * spin locks, and reader/writer locks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) acpi_status acpi_ut_mutex_initialize(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) ACPI_FUNCTION_TRACE(ut_mutex_initialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* Create each of the predefined mutex objects */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) for (i = 0; i < ACPI_NUM_MUTEX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) status = acpi_ut_create_mutex(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /* Create the spinlocks for use at interrupt level or for speed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) status = acpi_os_create_lock (&acpi_gbl_gpe_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if (ACPI_FAILURE (status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return_ACPI_STATUS (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) status = acpi_os_create_raw_lock(&acpi_gbl_hardware_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) if (ACPI_FAILURE (status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return_ACPI_STATUS (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) status = acpi_os_create_lock(&acpi_gbl_reference_count_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /* Mutex for _OSI support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) status = acpi_os_create_mutex(&acpi_gbl_osi_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* Create the reader/writer lock for namespace access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) status = acpi_ut_create_rw_lock(&acpi_gbl_namespace_rw_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return_ACPI_STATUS(status);
^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) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * FUNCTION: acpi_ut_mutex_terminate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * PARAMETERS: None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * RETURN: None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * DESCRIPTION: Delete all of the system mutex objects. This includes mutexes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * spin locks, and reader/writer locks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) void acpi_ut_mutex_terminate(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) ACPI_FUNCTION_TRACE(ut_mutex_terminate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /* Delete each predefined mutex object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) for (i = 0; i < ACPI_NUM_MUTEX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) acpi_ut_delete_mutex(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) acpi_os_delete_mutex(acpi_gbl_osi_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /* Delete the spinlocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) acpi_os_delete_lock(acpi_gbl_gpe_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) acpi_os_delete_raw_lock(acpi_gbl_hardware_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) acpi_os_delete_lock(acpi_gbl_reference_count_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /* Delete the reader/writer lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) acpi_ut_delete_rw_lock(&acpi_gbl_namespace_rw_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return_VOID;
^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) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * FUNCTION: acpi_ut_create_mutex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * PARAMETERS: mutex_ID - ID of the mutex to be created
^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: Create a mutex object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static acpi_status acpi_ut_create_mutex(acpi_mutex_handle mutex_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) acpi_status status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ACPI_FUNCTION_TRACE_U32(ut_create_mutex, mutex_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (!acpi_gbl_mutex_info[mutex_id].mutex) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) acpi_os_create_mutex(&acpi_gbl_mutex_info[mutex_id].mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) acpi_gbl_mutex_info[mutex_id].thread_id =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) ACPI_MUTEX_NOT_ACQUIRED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) acpi_gbl_mutex_info[mutex_id].use_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * FUNCTION: acpi_ut_delete_mutex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * PARAMETERS: mutex_ID - ID of the mutex to be deleted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * DESCRIPTION: Delete a mutex object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static void acpi_ut_delete_mutex(acpi_mutex_handle mutex_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) ACPI_FUNCTION_TRACE_U32(ut_delete_mutex, mutex_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) acpi_os_delete_mutex(acpi_gbl_mutex_info[mutex_id].mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) acpi_gbl_mutex_info[mutex_id].mutex = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) acpi_gbl_mutex_info[mutex_id].thread_id = ACPI_MUTEX_NOT_ACQUIRED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return_VOID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * FUNCTION: acpi_ut_acquire_mutex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * PARAMETERS: mutex_ID - ID of the mutex to be acquired
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * DESCRIPTION: Acquire a mutex object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) acpi_thread_id this_thread_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) ACPI_FUNCTION_NAME(ut_acquire_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (mutex_id > ACPI_MAX_MUTEX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) return (AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) this_thread_id = acpi_os_get_thread_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #ifdef ACPI_MUTEX_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * Mutex debug code, for internal debugging only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * Deadlock prevention. Check if this thread owns any mutexes of value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * greater than or equal to this one. If so, the thread has violated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * the mutex ordering rule. This indicates a coding error somewhere in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * the ACPI subsystem code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) for (i = mutex_id; i < ACPI_NUM_MUTEX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (acpi_gbl_mutex_info[i].thread_id == this_thread_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (i == mutex_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) "Mutex [%s] already acquired by this thread [%u]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) acpi_ut_get_mutex_name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) (mutex_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) (u32)this_thread_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return (AE_ALREADY_ACQUIRED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) "Invalid acquire order: Thread %u owns [%s], wants [%s]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) (u32)this_thread_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) acpi_ut_get_mutex_name(i),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) acpi_ut_get_mutex_name(mutex_id)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return (AE_ACQUIRE_DEADLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) "Thread %u attempting to acquire Mutex [%s]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) (u32)this_thread_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) acpi_ut_get_mutex_name(mutex_id)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) acpi_os_acquire_mutex(acpi_gbl_mutex_info[mutex_id].mutex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) ACPI_WAIT_FOREVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (ACPI_SUCCESS(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) "Thread %u acquired Mutex [%s]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) (u32)this_thread_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) acpi_ut_get_mutex_name(mutex_id)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) acpi_gbl_mutex_info[mutex_id].use_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) acpi_gbl_mutex_info[mutex_id].thread_id = this_thread_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) ACPI_EXCEPTION((AE_INFO, status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) "Thread %u could not acquire Mutex [%s] (0x%X)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) (u32)this_thread_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) acpi_ut_get_mutex_name(mutex_id), mutex_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * FUNCTION: acpi_ut_release_mutex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * PARAMETERS: mutex_ID - ID of the mutex to be released
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * DESCRIPTION: Release a mutex object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) acpi_status acpi_ut_release_mutex(acpi_mutex_handle mutex_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) ACPI_FUNCTION_NAME(ut_release_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Thread %u releasing Mutex [%s]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) (u32)acpi_os_get_thread_id(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) acpi_ut_get_mutex_name(mutex_id)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (mutex_id > ACPI_MAX_MUTEX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) return (AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * Mutex must be acquired in order to release it!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) if (acpi_gbl_mutex_info[mutex_id].thread_id == ACPI_MUTEX_NOT_ACQUIRED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) "Mutex [%s] (0x%X) is not acquired, cannot release",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) acpi_ut_get_mutex_name(mutex_id), mutex_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return (AE_NOT_ACQUIRED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) #ifdef ACPI_MUTEX_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * Mutex debug code, for internal debugging only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * Deadlock prevention. Check if this thread owns any mutexes of value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * greater than this one. If so, the thread has violated the mutex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * ordering rule. This indicates a coding error somewhere in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * the ACPI subsystem code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) for (i = mutex_id; i < ACPI_NUM_MUTEX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (acpi_gbl_mutex_info[i].thread_id ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) acpi_os_get_thread_id()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (i == mutex_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) "Invalid release order: owns [%s], releasing [%s]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) acpi_ut_get_mutex_name(i),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) acpi_ut_get_mutex_name(mutex_id)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) return (AE_RELEASE_DEADLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /* Mark unlocked FIRST */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) acpi_gbl_mutex_info[mutex_id].thread_id = ACPI_MUTEX_NOT_ACQUIRED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) acpi_os_release_mutex(acpi_gbl_mutex_info[mutex_id].mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }