Print this page
acpica-unix2-20130823
PANKOVs restructure
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/io/acpica/utilities/utmutex.c
+++ new/usr/src/common/acpica/components/utilities/utmutex.c
1 1 /*******************************************************************************
2 2 *
3 3 * Module Name: utmutex - local mutex support
4 4 *
5 5 ******************************************************************************/
6 6
7 7 /*
8 - * Copyright (C) 2000 - 2011, Intel Corp.
8 + * Copyright (C) 2000 - 2013, Intel Corp.
9 9 * All rights reserved.
10 10 *
11 11 * Redistribution and use in source and binary forms, with or without
12 12 * modification, are permitted provided that the following conditions
13 13 * are met:
14 14 * 1. Redistributions of source code must retain the above copyright
15 15 * notice, this list of conditions, and the following disclaimer,
16 16 * without modification.
17 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 18 * substantially similar to the "NO WARRANTY" disclaimer below
19 19 * ("Disclaimer") and any redistribution must be conditioned upon
20 20 * including a substantially similar Disclaimer requirement for further
21 21 * binary redistribution.
22 22 * 3. Neither the names of the above-listed copyright holders nor the names
23 23 * of any contributors may be used to endorse or promote products derived
24 24 * from this software without specific prior written permission.
25 25 *
26 26 * Alternatively, this software may be distributed under the terms of the
27 27 * GNU General Public License ("GPL") version 2 as published by the Free
28 28 * Software Foundation.
29 29 *
30 30 * NO WARRANTY
31 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 41 * POSSIBILITY OF SUCH DAMAGES.
42 42 */
43 43
44 44
45 45 #define __UTMUTEX_C__
46 46
47 47 #include "acpi.h"
48 48 #include "accommon.h"
49 49
50 50 #define _COMPONENT ACPI_UTILITIES
51 51 ACPI_MODULE_NAME ("utmutex")
52 52
53 53 /* Local prototypes */
54 54
55 55 static ACPI_STATUS
56 56 AcpiUtCreateMutex (
57 57 ACPI_MUTEX_HANDLE MutexId);
58 58
59 59 static void
60 60 AcpiUtDeleteMutex (
61 61 ACPI_MUTEX_HANDLE MutexId);
62 62
63 63
64 64 /*******************************************************************************
65 65 *
66 66 * FUNCTION: AcpiUtMutexInitialize
67 67 *
68 68 * PARAMETERS: None.
69 69 *
70 70 * RETURN: Status
71 71 *
72 72 * DESCRIPTION: Create the system mutex objects. This includes mutexes,
73 73 * spin locks, and reader/writer locks.
74 74 *
75 75 ******************************************************************************/
76 76
77 77 ACPI_STATUS
78 78 AcpiUtMutexInitialize (
79 79 void)
80 80 {
81 81 UINT32 i;
82 82 ACPI_STATUS Status;
83 83
84 84
85 85 ACPI_FUNCTION_TRACE (UtMutexInitialize);
86 86
87 87
88 88 /* Create each of the predefined mutex objects */
↓ open down ↓ |
70 lines elided |
↑ open up ↑ |
89 89
90 90 for (i = 0; i < ACPI_NUM_MUTEX; i++)
91 91 {
92 92 Status = AcpiUtCreateMutex (i);
93 93 if (ACPI_FAILURE (Status))
94 94 {
95 95 return_ACPI_STATUS (Status);
96 96 }
97 97 }
98 98
99 - /* Create the spinlocks for use at interrupt level */
99 + /* Create the spinlocks for use at interrupt level or for speed */
100 100
101 101 Status = AcpiOsCreateLock (&AcpiGbl_GpeLock);
102 102 if (ACPI_FAILURE (Status))
103 103 {
104 104 return_ACPI_STATUS (Status);
105 105 }
106 106
107 107 Status = AcpiOsCreateLock (&AcpiGbl_HardwareLock);
108 108 if (ACPI_FAILURE (Status))
109 109 {
110 110 return_ACPI_STATUS (Status);
111 111 }
112 112
113 + Status = AcpiOsCreateLock (&AcpiGbl_ReferenceCountLock);
114 + if (ACPI_FAILURE (Status))
115 + {
116 + return_ACPI_STATUS (Status);
117 + }
118 +
113 119 /* Mutex for _OSI support */
120 +
114 121 Status = AcpiOsCreateMutex (&AcpiGbl_OsiMutex);
115 122 if (ACPI_FAILURE (Status))
116 123 {
117 124 return_ACPI_STATUS (Status);
118 125 }
119 126
120 127 /* Create the reader/writer lock for namespace access */
121 128
122 129 Status = AcpiUtCreateRwLock (&AcpiGbl_NamespaceRwLock);
123 130 return_ACPI_STATUS (Status);
124 131 }
125 132
126 133
127 134 /*******************************************************************************
128 135 *
129 136 * FUNCTION: AcpiUtMutexTerminate
130 137 *
131 138 * PARAMETERS: None.
132 139 *
133 140 * RETURN: None.
134 141 *
135 142 * DESCRIPTION: Delete all of the system mutex objects. This includes mutexes,
136 143 * spin locks, and reader/writer locks.
137 144 *
138 145 ******************************************************************************/
139 146
140 147 void
141 148 AcpiUtMutexTerminate (
142 149 void)
143 150 {
144 151 UINT32 i;
145 152
146 153
147 154 ACPI_FUNCTION_TRACE (UtMutexTerminate);
148 155
149 156
150 157 /* Delete each predefined mutex object */
151 158
152 159 for (i = 0; i < ACPI_NUM_MUTEX; i++)
↓ open down ↓ |
29 lines elided |
↑ open up ↑ |
153 160 {
154 161 AcpiUtDeleteMutex (i);
155 162 }
156 163
157 164 AcpiOsDeleteMutex (AcpiGbl_OsiMutex);
158 165
159 166 /* Delete the spinlocks */
160 167
161 168 AcpiOsDeleteLock (AcpiGbl_GpeLock);
162 169 AcpiOsDeleteLock (AcpiGbl_HardwareLock);
170 + AcpiOsDeleteLock (AcpiGbl_ReferenceCountLock);
163 171
164 172 /* Delete the reader/writer lock */
165 173
166 174 AcpiUtDeleteRwLock (&AcpiGbl_NamespaceRwLock);
167 175 return_VOID;
168 176 }
169 177
170 178
171 179 /*******************************************************************************
172 180 *
173 181 * FUNCTION: AcpiUtCreateMutex
174 182 *
175 183 * PARAMETERS: MutexID - ID of the mutex to be created
176 184 *
177 185 * RETURN: Status
178 186 *
179 187 * DESCRIPTION: Create a mutex object.
180 188 *
181 189 ******************************************************************************/
182 190
183 191 static ACPI_STATUS
184 192 AcpiUtCreateMutex (
185 193 ACPI_MUTEX_HANDLE MutexId)
186 194 {
187 195 ACPI_STATUS Status = AE_OK;
188 196
189 197
190 198 ACPI_FUNCTION_TRACE_U32 (UtCreateMutex, MutexId);
191 199
192 200
193 201 if (!AcpiGbl_MutexInfo[MutexId].Mutex)
194 202 {
195 203 Status = AcpiOsCreateMutex (&AcpiGbl_MutexInfo[MutexId].Mutex);
196 204 AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;
197 205 AcpiGbl_MutexInfo[MutexId].UseCount = 0;
198 206 }
199 207
200 208 return_ACPI_STATUS (Status);
201 209 }
202 210
203 211
204 212 /*******************************************************************************
205 213 *
206 214 * FUNCTION: AcpiUtDeleteMutex
207 215 *
208 216 * PARAMETERS: MutexID - ID of the mutex to be deleted
209 217 *
210 218 * RETURN: Status
211 219 *
212 220 * DESCRIPTION: Delete a mutex object.
213 221 *
214 222 ******************************************************************************/
215 223
216 224 static void
217 225 AcpiUtDeleteMutex (
↓ open down ↓ |
45 lines elided |
↑ open up ↑ |
218 226 ACPI_MUTEX_HANDLE MutexId)
219 227 {
220 228
221 229 ACPI_FUNCTION_TRACE_U32 (UtDeleteMutex, MutexId);
222 230
223 231
224 232 AcpiOsDeleteMutex (AcpiGbl_MutexInfo[MutexId].Mutex);
225 233
226 234 AcpiGbl_MutexInfo[MutexId].Mutex = NULL;
227 235 AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;
236 +
237 + return_VOID;
228 238 }
229 239
230 240
231 241 /*******************************************************************************
232 242 *
233 243 * FUNCTION: AcpiUtAcquireMutex
234 244 *
235 245 * PARAMETERS: MutexID - ID of the mutex to be acquired
236 246 *
237 247 * RETURN: Status
238 248 *
239 249 * DESCRIPTION: Acquire a mutex object.
240 250 *
241 251 ******************************************************************************/
242 252
243 253 ACPI_STATUS
244 254 AcpiUtAcquireMutex (
245 255 ACPI_MUTEX_HANDLE MutexId)
246 256 {
247 257 ACPI_STATUS Status;
248 258 ACPI_THREAD_ID ThisThreadId;
249 259
250 260
251 261 ACPI_FUNCTION_NAME (UtAcquireMutex);
252 262
253 263
254 264 if (MutexId > ACPI_MAX_MUTEX)
255 265 {
256 266 return (AE_BAD_PARAMETER);
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
257 267 }
258 268
259 269 ThisThreadId = AcpiOsGetThreadId ();
260 270
261 271 #ifdef ACPI_MUTEX_DEBUG
262 272 {
263 273 UINT32 i;
264 274 /*
265 275 * Mutex debug code, for internal debugging only.
266 276 *
267 - * Deadlock prevention. Check if this thread owns any mutexes of value
268 - * greater than or equal to this one. If so, the thread has violated
269 - * the mutex ordering rule. This indicates a coding error somewhere in
277 + * Deadlock prevention. Check if this thread owns any mutexes of value
278 + * greater than or equal to this one. If so, the thread has violated
279 + * the mutex ordering rule. This indicates a coding error somewhere in
270 280 * the ACPI subsystem code.
271 281 */
272 282 for (i = MutexId; i < ACPI_NUM_MUTEX; i++)
273 283 {
274 284 if (AcpiGbl_MutexInfo[i].ThreadId == ThisThreadId)
275 285 {
276 286 if (i == MutexId)
277 287 {
278 288 ACPI_ERROR ((AE_INFO,
279 289 "Mutex [%s] already acquired by this thread [%u]",
280 290 AcpiUtGetMutexName (MutexId),
281 291 (UINT32) ThisThreadId));
282 292
283 293 return (AE_ALREADY_ACQUIRED);
284 294 }
285 295
286 296 ACPI_ERROR ((AE_INFO,
287 297 "Invalid acquire order: Thread %u owns [%s], wants [%s]",
288 298 (UINT32) ThisThreadId, AcpiUtGetMutexName (i),
289 299 AcpiUtGetMutexName (MutexId)));
290 300
291 301 return (AE_ACQUIRE_DEADLOCK);
292 302 }
293 303 }
294 304 }
295 305 #endif
296 306
297 307 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
298 308 "Thread %u attempting to acquire Mutex [%s]\n",
299 309 (UINT32) ThisThreadId, AcpiUtGetMutexName (MutexId)));
300 310
301 311 Status = AcpiOsAcquireMutex (AcpiGbl_MutexInfo[MutexId].Mutex,
302 312 ACPI_WAIT_FOREVER);
303 313 if (ACPI_SUCCESS (Status))
304 314 {
305 315 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %u acquired Mutex [%s]\n",
306 316 (UINT32) ThisThreadId, AcpiUtGetMutexName (MutexId)));
307 317
308 318 AcpiGbl_MutexInfo[MutexId].UseCount++;
309 319 AcpiGbl_MutexInfo[MutexId].ThreadId = ThisThreadId;
310 320 }
311 321 else
312 322 {
313 323 ACPI_EXCEPTION ((AE_INFO, Status,
314 324 "Thread %u could not acquire Mutex [0x%X]",
315 325 (UINT32) ThisThreadId, MutexId));
316 326 }
317 327
318 328 return (Status);
319 329 }
320 330
321 331
322 332 /*******************************************************************************
323 333 *
324 334 * FUNCTION: AcpiUtReleaseMutex
325 335 *
326 336 * PARAMETERS: MutexID - ID of the mutex to be released
327 337 *
↓ open down ↓ |
48 lines elided |
↑ open up ↑ |
328 338 * RETURN: Status
329 339 *
330 340 * DESCRIPTION: Release a mutex object.
331 341 *
332 342 ******************************************************************************/
333 343
334 344 ACPI_STATUS
335 345 AcpiUtReleaseMutex (
336 346 ACPI_MUTEX_HANDLE MutexId)
337 347 {
338 - ACPI_THREAD_ID ThisThreadId;
339 -
340 -
341 348 ACPI_FUNCTION_NAME (UtReleaseMutex);
342 349
343 350
344 - ThisThreadId = AcpiOsGetThreadId ();
345 351 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %u releasing Mutex [%s]\n",
346 - (UINT32) ThisThreadId, AcpiUtGetMutexName (MutexId)));
352 + (UINT32) AcpiOsGetThreadId (), AcpiUtGetMutexName (MutexId)));
347 353
348 354 if (MutexId > ACPI_MAX_MUTEX)
349 355 {
350 356 return (AE_BAD_PARAMETER);
351 357 }
352 358
353 359 /*
354 360 * Mutex must be acquired in order to release it!
355 361 */
356 362 if (AcpiGbl_MutexInfo[MutexId].ThreadId == ACPI_MUTEX_NOT_ACQUIRED)
357 363 {
358 364 ACPI_ERROR ((AE_INFO,
359 365 "Mutex [0x%X] is not acquired, cannot release", MutexId));
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
360 366
361 367 return (AE_NOT_ACQUIRED);
362 368 }
363 369
364 370 #ifdef ACPI_MUTEX_DEBUG
365 371 {
366 372 UINT32 i;
367 373 /*
368 374 * Mutex debug code, for internal debugging only.
369 375 *
370 - * Deadlock prevention. Check if this thread owns any mutexes of value
371 - * greater than this one. If so, the thread has violated the mutex
372 - * ordering rule. This indicates a coding error somewhere in
376 + * Deadlock prevention. Check if this thread owns any mutexes of value
377 + * greater than this one. If so, the thread has violated the mutex
378 + * ordering rule. This indicates a coding error somewhere in
373 379 * the ACPI subsystem code.
374 380 */
375 381 for (i = MutexId; i < ACPI_NUM_MUTEX; i++)
376 382 {
377 - if (AcpiGbl_MutexInfo[i].ThreadId == ThisThreadId)
383 + if (AcpiGbl_MutexInfo[i].ThreadId == AcpiOsGetThreadId ())
378 384 {
379 385 if (i == MutexId)
380 386 {
381 387 continue;
382 388 }
383 389
384 390 ACPI_ERROR ((AE_INFO,
385 391 "Invalid release order: owns [%s], releasing [%s]",
386 392 AcpiUtGetMutexName (i), AcpiUtGetMutexName (MutexId)));
387 393
388 394 return (AE_RELEASE_DEADLOCK);
389 395 }
390 396 }
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
391 397 }
392 398 #endif
393 399
394 400 /* Mark unlocked FIRST */
395 401
396 402 AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;
397 403
398 404 AcpiOsReleaseMutex (AcpiGbl_MutexInfo[MutexId].Mutex);
399 405 return (AE_OK);
400 406 }
401 -
402 -
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX