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