Blame view
drivers/acpi/acpica/utmutex.c
9.83 KB
73459f73e ACPICA 20050617-0... |
1 2 3 4 5 6 7 |
/******************************************************************************* * * Module Name: utmutex - local mutex support * ******************************************************************************/ /* |
75a44ce00 ACPICA: update In... |
8 |
* Copyright (C) 2000 - 2008, Intel Corp. |
73459f73e ACPICA 20050617-0... |
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
* All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * substantially similar to the "NO WARRANTY" disclaimer below * ("Disclaimer") and any redistribution must be conditioned upon * including a substantially similar Disclaimer requirement for further * binary redistribution. * 3. Neither the names of the above-listed copyright holders nor the names * of any contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. */ |
73459f73e ACPICA 20050617-0... |
43 |
#include <acpi/acpi.h> |
e2f7a7772 ACPICA: hide priv... |
44 |
#include "accommon.h" |
73459f73e ACPICA 20050617-0... |
45 46 |
#define _COMPONENT ACPI_UTILITIES |
4be44fcd3 [ACPI] Lindent al... |
47 |
ACPI_MODULE_NAME("utmutex") |
73459f73e ACPICA 20050617-0... |
48 49 |
/* Local prototypes */ |
4be44fcd3 [ACPI] Lindent al... |
50 |
static acpi_status acpi_ut_create_mutex(acpi_mutex_handle mutex_id); |
73459f73e ACPICA 20050617-0... |
51 |
|
4be44fcd3 [ACPI] Lindent al... |
52 |
static acpi_status acpi_ut_delete_mutex(acpi_mutex_handle mutex_id); |
73459f73e ACPICA 20050617-0... |
53 54 55 56 57 58 59 60 61 |
/******************************************************************************* * * FUNCTION: acpi_ut_mutex_initialize * * PARAMETERS: None. * * RETURN: Status * |
8a335a233 ACPICA: Fix AcpiW... |
62 63 |
* DESCRIPTION: Create the system mutex objects. This includes mutexes, * spin locks, and reader/writer locks. |
73459f73e ACPICA 20050617-0... |
64 65 |
* ******************************************************************************/ |
4be44fcd3 [ACPI] Lindent al... |
66 |
acpi_status acpi_ut_mutex_initialize(void) |
73459f73e ACPICA 20050617-0... |
67 |
{ |
4be44fcd3 [ACPI] Lindent al... |
68 69 |
u32 i; acpi_status status; |
73459f73e ACPICA 20050617-0... |
70 |
|
b229cf92e ACPI: ACPICA 2006... |
71 |
ACPI_FUNCTION_TRACE(ut_mutex_initialize); |
73459f73e ACPICA 20050617-0... |
72 |
|
8a335a233 ACPICA: Fix AcpiW... |
73 |
/* Create each of the predefined mutex objects */ |
4c90ece24 ACPI: ACPICA 2006... |
74 |
for (i = 0; i < ACPI_NUM_MUTEX; i++) { |
4be44fcd3 [ACPI] Lindent al... |
75 76 77 |
status = acpi_ut_create_mutex(i); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); |
73459f73e ACPICA 20050617-0... |
78 79 |
} } |
4c90ece24 ACPI: ACPICA 2006... |
80 |
/* Create the spinlocks for use at interrupt level */ |
967440e3b ACPI: ACPICA 2006... |
81 82 |
spin_lock_init(acpi_gbl_gpe_lock); spin_lock_init(acpi_gbl_hardware_lock); |
4c90ece24 ACPI: ACPICA 2006... |
83 |
|
8a335a233 ACPICA: Fix AcpiW... |
84 85 86 |
/* Create the reader/writer lock for namespace access */ status = acpi_ut_create_rw_lock(&acpi_gbl_namespace_rw_lock); |
4be44fcd3 [ACPI] Lindent al... |
87 |
return_ACPI_STATUS(status); |
73459f73e ACPICA 20050617-0... |
88 |
} |
73459f73e ACPICA 20050617-0... |
89 90 91 92 93 94 95 96 |
/******************************************************************************* * * FUNCTION: acpi_ut_mutex_terminate * * PARAMETERS: None. * * RETURN: None. * |
8a335a233 ACPICA: Fix AcpiW... |
97 98 |
* DESCRIPTION: Delete all of the system mutex objects. This includes mutexes, * spin locks, and reader/writer locks. |
73459f73e ACPICA 20050617-0... |
99 100 |
* ******************************************************************************/ |
4be44fcd3 [ACPI] Lindent al... |
101 |
void acpi_ut_mutex_terminate(void) |
73459f73e ACPICA 20050617-0... |
102 |
{ |
4be44fcd3 [ACPI] Lindent al... |
103 |
u32 i; |
73459f73e ACPICA 20050617-0... |
104 |
|
b229cf92e ACPI: ACPICA 2006... |
105 |
ACPI_FUNCTION_TRACE(ut_mutex_terminate); |
73459f73e ACPICA 20050617-0... |
106 |
|
8a335a233 ACPICA: Fix AcpiW... |
107 |
/* Delete each predefined mutex object */ |
4c90ece24 ACPI: ACPICA 2006... |
108 |
for (i = 0; i < ACPI_NUM_MUTEX; i++) { |
4be44fcd3 [ACPI] Lindent al... |
109 |
(void)acpi_ut_delete_mutex(i); |
73459f73e ACPICA 20050617-0... |
110 |
} |
4c90ece24 ACPI: ACPICA 2006... |
111 |
/* Delete the spinlocks */ |
4be44fcd3 [ACPI] Lindent al... |
112 |
acpi_os_delete_lock(acpi_gbl_gpe_lock); |
4c90ece24 ACPI: ACPICA 2006... |
113 |
acpi_os_delete_lock(acpi_gbl_hardware_lock); |
8a335a233 ACPICA: Fix AcpiW... |
114 115 116 117 |
/* Delete the reader/writer lock */ acpi_ut_delete_rw_lock(&acpi_gbl_namespace_rw_lock); |
73459f73e ACPICA 20050617-0... |
118 119 |
return_VOID; } |
73459f73e ACPICA 20050617-0... |
120 121 122 123 124 125 126 127 128 129 130 |
/******************************************************************************* * * FUNCTION: acpi_ut_create_mutex * * PARAMETERS: mutex_iD - ID of the mutex to be created * * RETURN: Status * * DESCRIPTION: Create a mutex object. * ******************************************************************************/ |
4be44fcd3 [ACPI] Lindent al... |
131 |
static acpi_status acpi_ut_create_mutex(acpi_mutex_handle mutex_id) |
73459f73e ACPICA 20050617-0... |
132 |
{ |
4be44fcd3 [ACPI] Lindent al... |
133 |
acpi_status status = AE_OK; |
73459f73e ACPICA 20050617-0... |
134 |
|
b229cf92e ACPI: ACPICA 2006... |
135 |
ACPI_FUNCTION_TRACE_U32(ut_create_mutex, mutex_id); |
73459f73e ACPICA 20050617-0... |
136 |
|
4c90ece24 ACPI: ACPICA 2006... |
137 |
if (mutex_id > ACPI_MAX_MUTEX) { |
4be44fcd3 [ACPI] Lindent al... |
138 |
return_ACPI_STATUS(AE_BAD_PARAMETER); |
73459f73e ACPICA 20050617-0... |
139 140 141 |
} if (!acpi_gbl_mutex_info[mutex_id].mutex) { |
967440e3b ACPI: ACPICA 2006... |
142 143 |
status = acpi_os_create_mutex(&acpi_gbl_mutex_info[mutex_id].mutex); |
4be44fcd3 [ACPI] Lindent al... |
144 145 |
acpi_gbl_mutex_info[mutex_id].thread_id = ACPI_MUTEX_NOT_ACQUIRED; |
73459f73e ACPICA 20050617-0... |
146 147 |
acpi_gbl_mutex_info[mutex_id].use_count = 0; } |
4be44fcd3 [ACPI] Lindent al... |
148 |
return_ACPI_STATUS(status); |
73459f73e ACPICA 20050617-0... |
149 |
} |
73459f73e ACPICA 20050617-0... |
150 151 152 153 154 155 156 157 158 159 160 |
/******************************************************************************* * * FUNCTION: acpi_ut_delete_mutex * * PARAMETERS: mutex_iD - ID of the mutex to be deleted * * RETURN: Status * * DESCRIPTION: Delete a mutex object. * ******************************************************************************/ |
4be44fcd3 [ACPI] Lindent al... |
161 |
static acpi_status acpi_ut_delete_mutex(acpi_mutex_handle mutex_id) |
73459f73e ACPICA 20050617-0... |
162 |
{ |
73459f73e ACPICA 20050617-0... |
163 |
|
b229cf92e ACPI: ACPICA 2006... |
164 |
ACPI_FUNCTION_TRACE_U32(ut_delete_mutex, mutex_id); |
73459f73e ACPICA 20050617-0... |
165 |
|
4c90ece24 ACPI: ACPICA 2006... |
166 |
if (mutex_id > ACPI_MAX_MUTEX) { |
4be44fcd3 [ACPI] Lindent al... |
167 |
return_ACPI_STATUS(AE_BAD_PARAMETER); |
73459f73e ACPICA 20050617-0... |
168 |
} |
967440e3b ACPI: ACPICA 2006... |
169 |
acpi_os_delete_mutex(acpi_gbl_mutex_info[mutex_id].mutex); |
73459f73e ACPICA 20050617-0... |
170 171 |
acpi_gbl_mutex_info[mutex_id].mutex = NULL; |
f9f4601f3 ACPICA 20050708 f... |
172 |
acpi_gbl_mutex_info[mutex_id].thread_id = ACPI_MUTEX_NOT_ACQUIRED; |
73459f73e ACPICA 20050617-0... |
173 |
|
967440e3b ACPI: ACPICA 2006... |
174 |
return_ACPI_STATUS(AE_OK); |
73459f73e ACPICA 20050617-0... |
175 |
} |
73459f73e ACPICA 20050617-0... |
176 177 178 179 180 181 182 183 184 185 186 |
/******************************************************************************* * * FUNCTION: acpi_ut_acquire_mutex * * PARAMETERS: mutex_iD - ID of the mutex to be acquired * * RETURN: Status * * DESCRIPTION: Acquire a mutex object. * ******************************************************************************/ |
4be44fcd3 [ACPI] Lindent al... |
187 |
acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id) |
73459f73e ACPICA 20050617-0... |
188 |
{ |
4be44fcd3 [ACPI] Lindent al... |
189 |
acpi_status status; |
8313524a0 ACPI: ACPICA 2006... |
190 |
acpi_thread_id this_thread_id; |
73459f73e ACPICA 20050617-0... |
191 |
|
b229cf92e ACPI: ACPICA 2006... |
192 |
ACPI_FUNCTION_NAME(ut_acquire_mutex); |
73459f73e ACPICA 20050617-0... |
193 |
|
4c90ece24 ACPI: ACPICA 2006... |
194 |
if (mutex_id > ACPI_MAX_MUTEX) { |
73459f73e ACPICA 20050617-0... |
195 196 |
return (AE_BAD_PARAMETER); } |
4be44fcd3 [ACPI] Lindent al... |
197 |
this_thread_id = acpi_os_get_thread_id(); |
73459f73e ACPICA 20050617-0... |
198 199 200 |
#ifdef ACPI_MUTEX_DEBUG { |
4be44fcd3 [ACPI] Lindent al... |
201 |
u32 i; |
73459f73e ACPICA 20050617-0... |
202 203 204 205 206 207 208 209 |
/* * Mutex debug code, for internal debugging only. * * Deadlock prevention. Check if this thread owns any mutexes of value * greater than or equal to this one. If so, the thread has violated * the mutex ordering rule. This indicates a coding error somewhere in * the ACPI subsystem code. */ |
b53ce3f71 ACPICA: Fix mutex... |
210 |
for (i = mutex_id; i < ACPI_NUM_MUTEX; i++) { |
bda663d36 [ACPI] ACPICA 200... |
211 |
if (acpi_gbl_mutex_info[i].thread_id == this_thread_id) { |
73459f73e ACPICA 20050617-0... |
212 |
if (i == mutex_id) { |
b8e4d8935 [ACPI] ACPICA 200... |
213 |
ACPI_ERROR((AE_INFO, |
10b6575b5 ACPICA: Fix possi... |
214 |
"Mutex [%s] already acquired by this thread [%p]", |
b8e4d8935 [ACPI] ACPICA 200... |
215 216 |
acpi_ut_get_mutex_name (mutex_id), |
10b6575b5 ACPICA: Fix possi... |
217 218 |
ACPI_CAST_PTR(void, this_thread_id))); |
73459f73e ACPICA 20050617-0... |
219 220 221 |
return (AE_ALREADY_ACQUIRED); } |
b8e4d8935 [ACPI] ACPICA 200... |
222 |
ACPI_ERROR((AE_INFO, |
10b6575b5 ACPICA: Fix possi... |
223 224 |
"Invalid acquire order: Thread %p owns [%s], wants [%s]", ACPI_CAST_PTR(void, this_thread_id), |
b8e4d8935 [ACPI] ACPICA 200... |
225 226 |
acpi_ut_get_mutex_name(i), acpi_ut_get_mutex_name(mutex_id))); |
73459f73e ACPICA 20050617-0... |
227 228 229 230 231 232 |
return (AE_ACQUIRE_DEADLOCK); } } } #endif |
4be44fcd3 [ACPI] Lindent al... |
233 |
ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, |
10b6575b5 ACPICA: Fix possi... |
234 235 236 |
"Thread %p attempting to acquire Mutex [%s] ", ACPI_CAST_PTR(void, this_thread_id), |
965a3d447 ACPI: avoid gcc w... |
237 |
acpi_ut_get_mutex_name(mutex_id))); |
73459f73e ACPICA 20050617-0... |
238 |
|
967440e3b ACPI: ACPICA 2006... |
239 240 |
status = acpi_os_acquire_mutex(acpi_gbl_mutex_info[mutex_id].mutex, ACPI_WAIT_FOREVER); |
4be44fcd3 [ACPI] Lindent al... |
241 242 |
if (ACPI_SUCCESS(status)) { ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, |
10b6575b5 ACPICA: Fix possi... |
243 244 245 |
"Thread %p acquired Mutex [%s] ", ACPI_CAST_PTR(void, this_thread_id), |
4be44fcd3 [ACPI] Lindent al... |
246 |
acpi_ut_get_mutex_name(mutex_id))); |
73459f73e ACPICA 20050617-0... |
247 248 |
acpi_gbl_mutex_info[mutex_id].use_count++; |
f9f4601f3 ACPICA 20050708 f... |
249 |
acpi_gbl_mutex_info[mutex_id].thread_id = this_thread_id; |
4be44fcd3 [ACPI] Lindent al... |
250 |
} else { |
b8e4d8935 [ACPI] ACPICA 200... |
251 |
ACPI_EXCEPTION((AE_INFO, status, |
10b6575b5 ACPICA: Fix possi... |
252 253 |
"Thread %p could not acquire Mutex [%X]", ACPI_CAST_PTR(void, this_thread_id), mutex_id)); |
73459f73e ACPICA 20050617-0... |
254 255 256 257 |
} return (status); } |
73459f73e ACPICA 20050617-0... |
258 259 260 261 262 263 264 265 266 267 268 |
/******************************************************************************* * * FUNCTION: acpi_ut_release_mutex * * PARAMETERS: mutex_iD - ID of the mutex to be released * * RETURN: Status * * DESCRIPTION: Release a mutex object. * ******************************************************************************/ |
4be44fcd3 [ACPI] Lindent al... |
269 |
acpi_status acpi_ut_release_mutex(acpi_mutex_handle mutex_id) |
73459f73e ACPICA 20050617-0... |
270 |
{ |
8313524a0 ACPI: ACPICA 2006... |
271 |
acpi_thread_id this_thread_id; |
73459f73e ACPICA 20050617-0... |
272 |
|
b229cf92e ACPI: ACPICA 2006... |
273 |
ACPI_FUNCTION_NAME(ut_release_mutex); |
73459f73e ACPICA 20050617-0... |
274 |
|
4be44fcd3 [ACPI] Lindent al... |
275 |
this_thread_id = acpi_os_get_thread_id(); |
10b6575b5 ACPICA: Fix possi... |
276 277 278 |
ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Thread %p releasing Mutex [%s] ", ACPI_CAST_PTR(void, this_thread_id), |
4be44fcd3 [ACPI] Lindent al... |
279 |
acpi_ut_get_mutex_name(mutex_id))); |
73459f73e ACPICA 20050617-0... |
280 |
|
4c90ece24 ACPI: ACPICA 2006... |
281 |
if (mutex_id > ACPI_MAX_MUTEX) { |
73459f73e ACPICA 20050617-0... |
282 283 284 285 286 287 |
return (AE_BAD_PARAMETER); } /* * Mutex must be acquired in order to release it! */ |
f9f4601f3 ACPICA 20050708 f... |
288 |
if (acpi_gbl_mutex_info[mutex_id].thread_id == ACPI_MUTEX_NOT_ACQUIRED) { |
b8e4d8935 [ACPI] ACPICA 200... |
289 290 291 |
ACPI_ERROR((AE_INFO, "Mutex [%X] is not acquired, cannot release", mutex_id)); |
73459f73e ACPICA 20050617-0... |
292 293 294 |
return (AE_NOT_ACQUIRED); } |
73459f73e ACPICA 20050617-0... |
295 296 |
#ifdef ACPI_MUTEX_DEBUG { |
4be44fcd3 [ACPI] Lindent al... |
297 |
u32 i; |
73459f73e ACPICA 20050617-0... |
298 299 300 301 302 303 304 305 |
/* * Mutex debug code, for internal debugging only. * * Deadlock prevention. Check if this thread owns any mutexes of value * greater than this one. If so, the thread has violated the mutex * ordering rule. This indicates a coding error somewhere in * the ACPI subsystem code. */ |
b53ce3f71 ACPICA: Fix mutex... |
306 |
for (i = mutex_id; i < ACPI_NUM_MUTEX; i++) { |
bda663d36 [ACPI] ACPICA 200... |
307 |
if (acpi_gbl_mutex_info[i].thread_id == this_thread_id) { |
73459f73e ACPICA 20050617-0... |
308 309 310 |
if (i == mutex_id) { continue; } |
b8e4d8935 [ACPI] ACPICA 200... |
311 312 313 314 |
ACPI_ERROR((AE_INFO, "Invalid release order: owns [%s], releasing [%s]", acpi_ut_get_mutex_name(i), acpi_ut_get_mutex_name(mutex_id))); |
73459f73e ACPICA 20050617-0... |
315 316 317 318 319 320 321 322 |
return (AE_RELEASE_DEADLOCK); } } } #endif /* Mark unlocked FIRST */ |
f9f4601f3 ACPICA 20050708 f... |
323 |
acpi_gbl_mutex_info[mutex_id].thread_id = ACPI_MUTEX_NOT_ACQUIRED; |
73459f73e ACPICA 20050617-0... |
324 |
|
967440e3b ACPI: ACPICA 2006... |
325 326 |
acpi_os_release_mutex(acpi_gbl_mutex_info[mutex_id].mutex); return (AE_OK); |
73459f73e ACPICA 20050617-0... |
327 |
} |