1433d6423SLionel Sambuc /*******************************************************************************
2433d6423SLionel Sambuc *
3433d6423SLionel Sambuc * Module Name: utmutex - local mutex support
4433d6423SLionel Sambuc *
5433d6423SLionel Sambuc ******************************************************************************/
6433d6423SLionel Sambuc
7*29492bb7SDavid van Moolenbroek /*
8*29492bb7SDavid van Moolenbroek * Copyright (C) 2000 - 2014, Intel Corp.
9433d6423SLionel Sambuc * All rights reserved.
10433d6423SLionel Sambuc *
11*29492bb7SDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without
12*29492bb7SDavid van Moolenbroek * modification, are permitted provided that the following conditions
13*29492bb7SDavid van Moolenbroek * are met:
14*29492bb7SDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright
15*29492bb7SDavid van Moolenbroek * notice, this list of conditions, and the following disclaimer,
16*29492bb7SDavid van Moolenbroek * without modification.
17*29492bb7SDavid van Moolenbroek * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*29492bb7SDavid van Moolenbroek * substantially similar to the "NO WARRANTY" disclaimer below
19*29492bb7SDavid van Moolenbroek * ("Disclaimer") and any redistribution must be conditioned upon
20*29492bb7SDavid van Moolenbroek * including a substantially similar Disclaimer requirement for further
21*29492bb7SDavid van Moolenbroek * binary redistribution.
22*29492bb7SDavid van Moolenbroek * 3. Neither the names of the above-listed copyright holders nor the names
23*29492bb7SDavid van Moolenbroek * of any contributors may be used to endorse or promote products derived
24*29492bb7SDavid van Moolenbroek * from this software without specific prior written permission.
25433d6423SLionel Sambuc *
26*29492bb7SDavid van Moolenbroek * Alternatively, this software may be distributed under the terms of the
27*29492bb7SDavid van Moolenbroek * GNU General Public License ("GPL") version 2 as published by the Free
28*29492bb7SDavid van Moolenbroek * Software Foundation.
29433d6423SLionel Sambuc *
30*29492bb7SDavid van Moolenbroek * NO WARRANTY
31*29492bb7SDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*29492bb7SDavid van Moolenbroek * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*29492bb7SDavid van Moolenbroek * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*29492bb7SDavid van Moolenbroek * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*29492bb7SDavid van Moolenbroek * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*29492bb7SDavid van Moolenbroek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*29492bb7SDavid van Moolenbroek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*29492bb7SDavid van Moolenbroek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*29492bb7SDavid van Moolenbroek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*29492bb7SDavid van Moolenbroek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*29492bb7SDavid van Moolenbroek * POSSIBILITY OF SUCH DAMAGES.
42*29492bb7SDavid van Moolenbroek */
43433d6423SLionel Sambuc
44433d6423SLionel Sambuc #include "acpi.h"
45433d6423SLionel Sambuc #include "accommon.h"
46433d6423SLionel Sambuc
47433d6423SLionel Sambuc #define _COMPONENT ACPI_UTILITIES
48433d6423SLionel Sambuc ACPI_MODULE_NAME ("utmutex")
49433d6423SLionel Sambuc
50433d6423SLionel Sambuc /* Local prototypes */
51433d6423SLionel Sambuc
52433d6423SLionel Sambuc static ACPI_STATUS
53433d6423SLionel Sambuc AcpiUtCreateMutex (
54433d6423SLionel Sambuc ACPI_MUTEX_HANDLE MutexId);
55433d6423SLionel Sambuc
56433d6423SLionel Sambuc static void
57433d6423SLionel Sambuc AcpiUtDeleteMutex (
58433d6423SLionel Sambuc ACPI_MUTEX_HANDLE MutexId);
59433d6423SLionel Sambuc
60433d6423SLionel Sambuc
61433d6423SLionel Sambuc /*******************************************************************************
62433d6423SLionel Sambuc *
63433d6423SLionel Sambuc * FUNCTION: AcpiUtMutexInitialize
64433d6423SLionel Sambuc *
65433d6423SLionel Sambuc * PARAMETERS: None.
66433d6423SLionel Sambuc *
67433d6423SLionel Sambuc * RETURN: Status
68433d6423SLionel Sambuc *
69433d6423SLionel Sambuc * DESCRIPTION: Create the system mutex objects. This includes mutexes,
70433d6423SLionel Sambuc * spin locks, and reader/writer locks.
71433d6423SLionel Sambuc *
72433d6423SLionel Sambuc ******************************************************************************/
73433d6423SLionel Sambuc
74433d6423SLionel Sambuc ACPI_STATUS
AcpiUtMutexInitialize(void)75433d6423SLionel Sambuc AcpiUtMutexInitialize (
76433d6423SLionel Sambuc void)
77433d6423SLionel Sambuc {
78433d6423SLionel Sambuc UINT32 i;
79433d6423SLionel Sambuc ACPI_STATUS Status;
80433d6423SLionel Sambuc
81433d6423SLionel Sambuc
82433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (UtMutexInitialize);
83433d6423SLionel Sambuc
84433d6423SLionel Sambuc
85433d6423SLionel Sambuc /* Create each of the predefined mutex objects */
86433d6423SLionel Sambuc
87433d6423SLionel Sambuc for (i = 0; i < ACPI_NUM_MUTEX; i++)
88433d6423SLionel Sambuc {
89433d6423SLionel Sambuc Status = AcpiUtCreateMutex (i);
90433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
91433d6423SLionel Sambuc {
92433d6423SLionel Sambuc return_ACPI_STATUS (Status);
93433d6423SLionel Sambuc }
94433d6423SLionel Sambuc }
95433d6423SLionel Sambuc
96*29492bb7SDavid van Moolenbroek /* Create the spinlocks for use at interrupt level or for speed */
97433d6423SLionel Sambuc
98433d6423SLionel Sambuc Status = AcpiOsCreateLock (&AcpiGbl_GpeLock);
99433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
100433d6423SLionel Sambuc {
101433d6423SLionel Sambuc return_ACPI_STATUS (Status);
102433d6423SLionel Sambuc }
103433d6423SLionel Sambuc
104433d6423SLionel Sambuc Status = AcpiOsCreateLock (&AcpiGbl_HardwareLock);
105433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
106433d6423SLionel Sambuc {
107433d6423SLionel Sambuc return_ACPI_STATUS (Status);
108433d6423SLionel Sambuc }
109433d6423SLionel Sambuc
110*29492bb7SDavid van Moolenbroek Status = AcpiOsCreateLock (&AcpiGbl_ReferenceCountLock);
111*29492bb7SDavid van Moolenbroek if (ACPI_FAILURE (Status))
112*29492bb7SDavid van Moolenbroek {
113*29492bb7SDavid van Moolenbroek return_ACPI_STATUS (Status);
114*29492bb7SDavid van Moolenbroek }
115*29492bb7SDavid van Moolenbroek
116*29492bb7SDavid van Moolenbroek /* Mutex for _OSI support */
117*29492bb7SDavid van Moolenbroek
118*29492bb7SDavid van Moolenbroek Status = AcpiOsCreateMutex (&AcpiGbl_OsiMutex);
119*29492bb7SDavid van Moolenbroek if (ACPI_FAILURE (Status))
120*29492bb7SDavid van Moolenbroek {
121*29492bb7SDavid van Moolenbroek return_ACPI_STATUS (Status);
122*29492bb7SDavid van Moolenbroek }
123*29492bb7SDavid van Moolenbroek
124433d6423SLionel Sambuc /* Create the reader/writer lock for namespace access */
125433d6423SLionel Sambuc
126433d6423SLionel Sambuc Status = AcpiUtCreateRwLock (&AcpiGbl_NamespaceRwLock);
127433d6423SLionel Sambuc return_ACPI_STATUS (Status);
128433d6423SLionel Sambuc }
129433d6423SLionel Sambuc
130433d6423SLionel Sambuc
131433d6423SLionel Sambuc /*******************************************************************************
132433d6423SLionel Sambuc *
133433d6423SLionel Sambuc * FUNCTION: AcpiUtMutexTerminate
134433d6423SLionel Sambuc *
135433d6423SLionel Sambuc * PARAMETERS: None.
136433d6423SLionel Sambuc *
137433d6423SLionel Sambuc * RETURN: None.
138433d6423SLionel Sambuc *
139433d6423SLionel Sambuc * DESCRIPTION: Delete all of the system mutex objects. This includes mutexes,
140433d6423SLionel Sambuc * spin locks, and reader/writer locks.
141433d6423SLionel Sambuc *
142433d6423SLionel Sambuc ******************************************************************************/
143433d6423SLionel Sambuc
144433d6423SLionel Sambuc void
AcpiUtMutexTerminate(void)145433d6423SLionel Sambuc AcpiUtMutexTerminate (
146433d6423SLionel Sambuc void)
147433d6423SLionel Sambuc {
148433d6423SLionel Sambuc UINT32 i;
149433d6423SLionel Sambuc
150433d6423SLionel Sambuc
151433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (UtMutexTerminate);
152433d6423SLionel Sambuc
153433d6423SLionel Sambuc
154433d6423SLionel Sambuc /* Delete each predefined mutex object */
155433d6423SLionel Sambuc
156433d6423SLionel Sambuc for (i = 0; i < ACPI_NUM_MUTEX; i++)
157433d6423SLionel Sambuc {
158433d6423SLionel Sambuc AcpiUtDeleteMutex (i);
159433d6423SLionel Sambuc }
160433d6423SLionel Sambuc
161*29492bb7SDavid van Moolenbroek AcpiOsDeleteMutex (AcpiGbl_OsiMutex);
162*29492bb7SDavid van Moolenbroek
163433d6423SLionel Sambuc /* Delete the spinlocks */
164433d6423SLionel Sambuc
165433d6423SLionel Sambuc AcpiOsDeleteLock (AcpiGbl_GpeLock);
166433d6423SLionel Sambuc AcpiOsDeleteLock (AcpiGbl_HardwareLock);
167*29492bb7SDavid van Moolenbroek AcpiOsDeleteLock (AcpiGbl_ReferenceCountLock);
168433d6423SLionel Sambuc
169433d6423SLionel Sambuc /* Delete the reader/writer lock */
170433d6423SLionel Sambuc
171433d6423SLionel Sambuc AcpiUtDeleteRwLock (&AcpiGbl_NamespaceRwLock);
172433d6423SLionel Sambuc return_VOID;
173433d6423SLionel Sambuc }
174433d6423SLionel Sambuc
175433d6423SLionel Sambuc
176433d6423SLionel Sambuc /*******************************************************************************
177433d6423SLionel Sambuc *
178433d6423SLionel Sambuc * FUNCTION: AcpiUtCreateMutex
179433d6423SLionel Sambuc *
180433d6423SLionel Sambuc * PARAMETERS: MutexID - ID of the mutex to be created
181433d6423SLionel Sambuc *
182433d6423SLionel Sambuc * RETURN: Status
183433d6423SLionel Sambuc *
184433d6423SLionel Sambuc * DESCRIPTION: Create a mutex object.
185433d6423SLionel Sambuc *
186433d6423SLionel Sambuc ******************************************************************************/
187433d6423SLionel Sambuc
188433d6423SLionel Sambuc static ACPI_STATUS
AcpiUtCreateMutex(ACPI_MUTEX_HANDLE MutexId)189433d6423SLionel Sambuc AcpiUtCreateMutex (
190433d6423SLionel Sambuc ACPI_MUTEX_HANDLE MutexId)
191433d6423SLionel Sambuc {
192433d6423SLionel Sambuc ACPI_STATUS Status = AE_OK;
193433d6423SLionel Sambuc
194433d6423SLionel Sambuc
195433d6423SLionel Sambuc ACPI_FUNCTION_TRACE_U32 (UtCreateMutex, MutexId);
196433d6423SLionel Sambuc
197433d6423SLionel Sambuc
198433d6423SLionel Sambuc if (!AcpiGbl_MutexInfo[MutexId].Mutex)
199433d6423SLionel Sambuc {
200433d6423SLionel Sambuc Status = AcpiOsCreateMutex (&AcpiGbl_MutexInfo[MutexId].Mutex);
201433d6423SLionel Sambuc AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;
202433d6423SLionel Sambuc AcpiGbl_MutexInfo[MutexId].UseCount = 0;
203433d6423SLionel Sambuc }
204433d6423SLionel Sambuc
205433d6423SLionel Sambuc return_ACPI_STATUS (Status);
206433d6423SLionel Sambuc }
207433d6423SLionel Sambuc
208433d6423SLionel Sambuc
209433d6423SLionel Sambuc /*******************************************************************************
210433d6423SLionel Sambuc *
211433d6423SLionel Sambuc * FUNCTION: AcpiUtDeleteMutex
212433d6423SLionel Sambuc *
213433d6423SLionel Sambuc * PARAMETERS: MutexID - ID of the mutex to be deleted
214433d6423SLionel Sambuc *
215433d6423SLionel Sambuc * RETURN: Status
216433d6423SLionel Sambuc *
217433d6423SLionel Sambuc * DESCRIPTION: Delete a mutex object.
218433d6423SLionel Sambuc *
219433d6423SLionel Sambuc ******************************************************************************/
220433d6423SLionel Sambuc
221433d6423SLionel Sambuc static void
AcpiUtDeleteMutex(ACPI_MUTEX_HANDLE MutexId)222433d6423SLionel Sambuc AcpiUtDeleteMutex (
223433d6423SLionel Sambuc ACPI_MUTEX_HANDLE MutexId)
224433d6423SLionel Sambuc {
225433d6423SLionel Sambuc
226433d6423SLionel Sambuc ACPI_FUNCTION_TRACE_U32 (UtDeleteMutex, MutexId);
227433d6423SLionel Sambuc
228433d6423SLionel Sambuc
229433d6423SLionel Sambuc AcpiOsDeleteMutex (AcpiGbl_MutexInfo[MutexId].Mutex);
230433d6423SLionel Sambuc
231433d6423SLionel Sambuc AcpiGbl_MutexInfo[MutexId].Mutex = NULL;
232433d6423SLionel Sambuc AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;
233*29492bb7SDavid van Moolenbroek
234*29492bb7SDavid van Moolenbroek return_VOID;
235433d6423SLionel Sambuc }
236433d6423SLionel Sambuc
237433d6423SLionel Sambuc
238433d6423SLionel Sambuc /*******************************************************************************
239433d6423SLionel Sambuc *
240433d6423SLionel Sambuc * FUNCTION: AcpiUtAcquireMutex
241433d6423SLionel Sambuc *
242433d6423SLionel Sambuc * PARAMETERS: MutexID - ID of the mutex to be acquired
243433d6423SLionel Sambuc *
244433d6423SLionel Sambuc * RETURN: Status
245433d6423SLionel Sambuc *
246433d6423SLionel Sambuc * DESCRIPTION: Acquire a mutex object.
247433d6423SLionel Sambuc *
248433d6423SLionel Sambuc ******************************************************************************/
249433d6423SLionel Sambuc
250433d6423SLionel Sambuc ACPI_STATUS
AcpiUtAcquireMutex(ACPI_MUTEX_HANDLE MutexId)251433d6423SLionel Sambuc AcpiUtAcquireMutex (
252433d6423SLionel Sambuc ACPI_MUTEX_HANDLE MutexId)
253433d6423SLionel Sambuc {
254433d6423SLionel Sambuc ACPI_STATUS Status;
255433d6423SLionel Sambuc ACPI_THREAD_ID ThisThreadId;
256433d6423SLionel Sambuc
257433d6423SLionel Sambuc
258433d6423SLionel Sambuc ACPI_FUNCTION_NAME (UtAcquireMutex);
259433d6423SLionel Sambuc
260433d6423SLionel Sambuc
261433d6423SLionel Sambuc if (MutexId > ACPI_MAX_MUTEX)
262433d6423SLionel Sambuc {
263433d6423SLionel Sambuc return (AE_BAD_PARAMETER);
264433d6423SLionel Sambuc }
265433d6423SLionel Sambuc
266433d6423SLionel Sambuc ThisThreadId = AcpiOsGetThreadId ();
267433d6423SLionel Sambuc
268433d6423SLionel Sambuc #ifdef ACPI_MUTEX_DEBUG
269433d6423SLionel Sambuc {
270433d6423SLionel Sambuc UINT32 i;
271433d6423SLionel Sambuc /*
272433d6423SLionel Sambuc * Mutex debug code, for internal debugging only.
273433d6423SLionel Sambuc *
274433d6423SLionel Sambuc * Deadlock prevention. Check if this thread owns any mutexes of value
275433d6423SLionel Sambuc * greater than or equal to this one. If so, the thread has violated
276433d6423SLionel Sambuc * the mutex ordering rule. This indicates a coding error somewhere in
277433d6423SLionel Sambuc * the ACPI subsystem code.
278433d6423SLionel Sambuc */
279433d6423SLionel Sambuc for (i = MutexId; i < ACPI_NUM_MUTEX; i++)
280433d6423SLionel Sambuc {
281433d6423SLionel Sambuc if (AcpiGbl_MutexInfo[i].ThreadId == ThisThreadId)
282433d6423SLionel Sambuc {
283433d6423SLionel Sambuc if (i == MutexId)
284433d6423SLionel Sambuc {
285433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO,
286*29492bb7SDavid van Moolenbroek "Mutex [%s] already acquired by this thread [%u]",
287433d6423SLionel Sambuc AcpiUtGetMutexName (MutexId),
288*29492bb7SDavid van Moolenbroek (UINT32) ThisThreadId));
289433d6423SLionel Sambuc
290433d6423SLionel Sambuc return (AE_ALREADY_ACQUIRED);
291433d6423SLionel Sambuc }
292433d6423SLionel Sambuc
293433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO,
294*29492bb7SDavid van Moolenbroek "Invalid acquire order: Thread %u owns [%s], wants [%s]",
295*29492bb7SDavid van Moolenbroek (UINT32) ThisThreadId, AcpiUtGetMutexName (i),
296433d6423SLionel Sambuc AcpiUtGetMutexName (MutexId)));
297433d6423SLionel Sambuc
298433d6423SLionel Sambuc return (AE_ACQUIRE_DEADLOCK);
299433d6423SLionel Sambuc }
300433d6423SLionel Sambuc }
301433d6423SLionel Sambuc }
302433d6423SLionel Sambuc #endif
303433d6423SLionel Sambuc
304433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
305*29492bb7SDavid van Moolenbroek "Thread %u attempting to acquire Mutex [%s]\n",
306*29492bb7SDavid van Moolenbroek (UINT32) ThisThreadId, AcpiUtGetMutexName (MutexId)));
307433d6423SLionel Sambuc
308433d6423SLionel Sambuc Status = AcpiOsAcquireMutex (AcpiGbl_MutexInfo[MutexId].Mutex,
309433d6423SLionel Sambuc ACPI_WAIT_FOREVER);
310433d6423SLionel Sambuc if (ACPI_SUCCESS (Status))
311433d6423SLionel Sambuc {
312*29492bb7SDavid van Moolenbroek ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %u acquired Mutex [%s]\n",
313*29492bb7SDavid van Moolenbroek (UINT32) ThisThreadId, AcpiUtGetMutexName (MutexId)));
314433d6423SLionel Sambuc
315433d6423SLionel Sambuc AcpiGbl_MutexInfo[MutexId].UseCount++;
316433d6423SLionel Sambuc AcpiGbl_MutexInfo[MutexId].ThreadId = ThisThreadId;
317433d6423SLionel Sambuc }
318433d6423SLionel Sambuc else
319433d6423SLionel Sambuc {
320433d6423SLionel Sambuc ACPI_EXCEPTION ((AE_INFO, Status,
321*29492bb7SDavid van Moolenbroek "Thread %u could not acquire Mutex [0x%X]",
322*29492bb7SDavid van Moolenbroek (UINT32) ThisThreadId, MutexId));
323433d6423SLionel Sambuc }
324433d6423SLionel Sambuc
325433d6423SLionel Sambuc return (Status);
326433d6423SLionel Sambuc }
327433d6423SLionel Sambuc
328433d6423SLionel Sambuc
329433d6423SLionel Sambuc /*******************************************************************************
330433d6423SLionel Sambuc *
331433d6423SLionel Sambuc * FUNCTION: AcpiUtReleaseMutex
332433d6423SLionel Sambuc *
333433d6423SLionel Sambuc * PARAMETERS: MutexID - ID of the mutex to be released
334433d6423SLionel Sambuc *
335433d6423SLionel Sambuc * RETURN: Status
336433d6423SLionel Sambuc *
337433d6423SLionel Sambuc * DESCRIPTION: Release a mutex object.
338433d6423SLionel Sambuc *
339433d6423SLionel Sambuc ******************************************************************************/
340433d6423SLionel Sambuc
341433d6423SLionel Sambuc ACPI_STATUS
AcpiUtReleaseMutex(ACPI_MUTEX_HANDLE MutexId)342433d6423SLionel Sambuc AcpiUtReleaseMutex (
343433d6423SLionel Sambuc ACPI_MUTEX_HANDLE MutexId)
344433d6423SLionel Sambuc {
345433d6423SLionel Sambuc ACPI_FUNCTION_NAME (UtReleaseMutex);
346433d6423SLionel Sambuc
347433d6423SLionel Sambuc
348*29492bb7SDavid van Moolenbroek ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %u releasing Mutex [%s]\n",
349*29492bb7SDavid van Moolenbroek (UINT32) AcpiOsGetThreadId (), AcpiUtGetMutexName (MutexId)));
350433d6423SLionel Sambuc
351433d6423SLionel Sambuc if (MutexId > ACPI_MAX_MUTEX)
352433d6423SLionel Sambuc {
353433d6423SLionel Sambuc return (AE_BAD_PARAMETER);
354433d6423SLionel Sambuc }
355433d6423SLionel Sambuc
356433d6423SLionel Sambuc /*
357433d6423SLionel Sambuc * Mutex must be acquired in order to release it!
358433d6423SLionel Sambuc */
359433d6423SLionel Sambuc if (AcpiGbl_MutexInfo[MutexId].ThreadId == ACPI_MUTEX_NOT_ACQUIRED)
360433d6423SLionel Sambuc {
361433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO,
362433d6423SLionel Sambuc "Mutex [0x%X] is not acquired, cannot release", MutexId));
363433d6423SLionel Sambuc
364433d6423SLionel Sambuc return (AE_NOT_ACQUIRED);
365433d6423SLionel Sambuc }
366433d6423SLionel Sambuc
367433d6423SLionel Sambuc #ifdef ACPI_MUTEX_DEBUG
368433d6423SLionel Sambuc {
369433d6423SLionel Sambuc UINT32 i;
370433d6423SLionel Sambuc /*
371433d6423SLionel Sambuc * Mutex debug code, for internal debugging only.
372433d6423SLionel Sambuc *
373433d6423SLionel Sambuc * Deadlock prevention. Check if this thread owns any mutexes of value
374433d6423SLionel Sambuc * greater than this one. If so, the thread has violated the mutex
375433d6423SLionel Sambuc * ordering rule. This indicates a coding error somewhere in
376433d6423SLionel Sambuc * the ACPI subsystem code.
377433d6423SLionel Sambuc */
378433d6423SLionel Sambuc for (i = MutexId; i < ACPI_NUM_MUTEX; i++)
379433d6423SLionel Sambuc {
380*29492bb7SDavid van Moolenbroek if (AcpiGbl_MutexInfo[i].ThreadId == AcpiOsGetThreadId ())
381433d6423SLionel Sambuc {
382433d6423SLionel Sambuc if (i == MutexId)
383433d6423SLionel Sambuc {
384433d6423SLionel Sambuc continue;
385433d6423SLionel Sambuc }
386433d6423SLionel Sambuc
387433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO,
388433d6423SLionel Sambuc "Invalid release order: owns [%s], releasing [%s]",
389433d6423SLionel Sambuc AcpiUtGetMutexName (i), AcpiUtGetMutexName (MutexId)));
390433d6423SLionel Sambuc
391433d6423SLionel Sambuc return (AE_RELEASE_DEADLOCK);
392433d6423SLionel Sambuc }
393433d6423SLionel Sambuc }
394433d6423SLionel Sambuc }
395433d6423SLionel Sambuc #endif
396433d6423SLionel Sambuc
397433d6423SLionel Sambuc /* Mark unlocked FIRST */
398433d6423SLionel Sambuc
399433d6423SLionel Sambuc AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;
400433d6423SLionel Sambuc
401433d6423SLionel Sambuc AcpiOsReleaseMutex (AcpiGbl_MutexInfo[MutexId].Mutex);
402433d6423SLionel Sambuc return (AE_OK);
403433d6423SLionel Sambuc }
404