Print this page
acpica-unix2-20130823
PANKOVs restructure
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/io/acpica/events/evglock.c
+++ new/usr/src/common/acpica/components/events/evglock.c
1 1 /******************************************************************************
2 2 *
3 3 * Module Name: evglock - Global Lock 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.
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
42 42 */
43 43
44 44 #include "acpi.h"
45 45 #include "accommon.h"
46 46 #include "acevents.h"
47 47 #include "acinterp.h"
48 48
49 49 #define _COMPONENT ACPI_EVENTS
50 50 ACPI_MODULE_NAME ("evglock")
51 51
52 +#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
52 53
53 54 /* Local prototypes */
54 55
55 56 static UINT32
56 57 AcpiEvGlobalLockHandler (
57 58 void *Context);
58 59
59 60
60 61 /*******************************************************************************
61 62 *
62 63 * FUNCTION: AcpiEvInitGlobalLockHandler
63 64 *
64 65 * PARAMETERS: None
65 66 *
66 67 * RETURN: Status
67 68 *
68 69 * DESCRIPTION: Install a handler for the global lock release event
69 70 *
70 71 ******************************************************************************/
71 72
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
72 73 ACPI_STATUS
73 74 AcpiEvInitGlobalLockHandler (
74 75 void)
75 76 {
76 77 ACPI_STATUS Status;
77 78
78 79
79 80 ACPI_FUNCTION_TRACE (EvInitGlobalLockHandler);
80 81
81 82
83 + /* If Hardware Reduced flag is set, there is no global lock */
84 +
85 + if (AcpiGbl_ReducedHardware)
86 + {
87 + return_ACPI_STATUS (AE_OK);
88 + }
89 +
82 90 /* Attempt installation of the global lock handler */
83 91
84 92 Status = AcpiInstallFixedEventHandler (ACPI_EVENT_GLOBAL,
85 93 AcpiEvGlobalLockHandler, NULL);
86 94
87 95 /*
88 96 * If the global lock does not exist on this platform, the attempt to
89 97 * enable GBL_STATUS will fail (the GBL_ENABLE bit will not stick).
90 98 * Map to AE_OK, but mark global lock as not present. Any attempt to
91 99 * actually use the global lock will be flagged with an error.
92 100 */
93 101 AcpiGbl_GlobalLockPresent = FALSE;
94 102 if (Status == AE_NO_HARDWARE_RESPONSE)
95 103 {
96 104 ACPI_ERROR ((AE_INFO,
97 105 "No response from Global Lock hardware, disabling lock"));
98 106
99 107 return_ACPI_STATUS (AE_OK);
100 108 }
101 109
102 110 Status = AcpiOsCreateLock (&AcpiGbl_GlobalLockPendingLock);
103 111 if (ACPI_FAILURE (Status))
104 112 {
105 113 return_ACPI_STATUS (Status);
106 114 }
107 115
108 116 AcpiGbl_GlobalLockPending = FALSE;
109 117 AcpiGbl_GlobalLockPresent = TRUE;
110 118 return_ACPI_STATUS (Status);
111 119 }
112 120
113 121
114 122 /*******************************************************************************
115 123 *
116 124 * FUNCTION: AcpiEvRemoveGlobalLockHandler
117 125 *
118 126 * PARAMETERS: None
119 127 *
120 128 * RETURN: Status
121 129 *
122 130 * DESCRIPTION: Remove the handler for the Global Lock
123 131 *
124 132 ******************************************************************************/
125 133
126 134 ACPI_STATUS
127 135 AcpiEvRemoveGlobalLockHandler (
128 136 void)
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
129 137 {
130 138 ACPI_STATUS Status;
131 139
132 140
133 141 ACPI_FUNCTION_TRACE (EvRemoveGlobalLockHandler);
134 142
135 143 AcpiGbl_GlobalLockPresent = FALSE;
136 144 Status = AcpiRemoveFixedEventHandler (ACPI_EVENT_GLOBAL,
137 145 AcpiEvGlobalLockHandler);
138 146
147 + AcpiOsDeleteLock (AcpiGbl_GlobalLockPendingLock);
139 148 return_ACPI_STATUS (Status);
140 149 }
141 150
142 151
143 152 /*******************************************************************************
144 153 *
145 154 * FUNCTION: AcpiEvGlobalLockHandler
146 155 *
147 156 * PARAMETERS: Context - From thread interface, not used
148 157 *
149 158 * RETURN: ACPI_INTERRUPT_HANDLED
150 159 *
151 160 * DESCRIPTION: Invoked directly from the SCI handler when a global lock
152 161 * release interrupt occurs. If there is actually a pending
153 162 * request for the lock, signal the waiting thread.
154 163 *
155 164 ******************************************************************************/
156 165
157 166 static UINT32
158 167 AcpiEvGlobalLockHandler (
159 168 void *Context)
160 169 {
161 170 ACPI_STATUS Status;
162 171 ACPI_CPU_FLAGS Flags;
163 172
164 173
165 174 Flags = AcpiOsAcquireLock (AcpiGbl_GlobalLockPendingLock);
166 175
167 176 /*
168 177 * If a request for the global lock is not actually pending,
169 178 * we are done. This handles "spurious" global lock interrupts
170 179 * which are possible (and have been seen) with bad BIOSs.
171 180 */
172 181 if (!AcpiGbl_GlobalLockPending)
173 182 {
174 183 goto CleanupAndExit;
175 184 }
176 185
177 186 /*
178 187 * Send a unit to the global lock semaphore. The actual acquisition
179 188 * of the global lock will be performed by the waiting thread.
180 189 */
181 190 Status = AcpiOsSignalSemaphore (AcpiGbl_GlobalLockSemaphore, 1);
182 191 if (ACPI_FAILURE (Status))
183 192 {
184 193 ACPI_ERROR ((AE_INFO, "Could not signal Global Lock semaphore"));
185 194 }
186 195
187 196 AcpiGbl_GlobalLockPending = FALSE;
188 197
189 198
190 199 CleanupAndExit:
191 200
192 201 AcpiOsReleaseLock (AcpiGbl_GlobalLockPendingLock, Flags);
193 202 return (ACPI_INTERRUPT_HANDLED);
194 203 }
195 204
196 205
197 206 /******************************************************************************
198 207 *
199 208 * FUNCTION: AcpiEvAcquireGlobalLock
200 209 *
201 210 * PARAMETERS: Timeout - Max time to wait for the lock, in millisec.
202 211 *
203 212 * RETURN: Status
204 213 *
205 214 * DESCRIPTION: Attempt to gain ownership of the Global Lock.
206 215 *
207 216 * MUTEX: Interpreter must be locked
208 217 *
209 218 * Note: The original implementation allowed multiple threads to "acquire" the
210 219 * Global Lock, and the OS would hold the lock until the last thread had
211 220 * released it. However, this could potentially starve the BIOS out of the
212 221 * lock, especially in the case where there is a tight handshake between the
213 222 * Embedded Controller driver and the BIOS. Therefore, this implementation
214 223 * allows only one thread to acquire the HW Global Lock at a time, and makes
215 224 * the global lock appear as a standard mutex on the OS side.
216 225 *
217 226 *****************************************************************************/
218 227
219 228 ACPI_STATUS
220 229 AcpiEvAcquireGlobalLock (
221 230 UINT16 Timeout)
222 231 {
223 232 ACPI_CPU_FLAGS Flags;
224 233 ACPI_STATUS Status;
225 234 BOOLEAN Acquired = FALSE;
226 235
227 236
228 237 ACPI_FUNCTION_TRACE (EvAcquireGlobalLock);
229 238
230 239
231 240 /*
232 241 * Only one thread can acquire the GL at a time, the GlobalLockMutex
233 242 * enforces this. This interface releases the interpreter if we must wait.
234 243 */
235 244 Status = AcpiExSystemWaitMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex,
236 245 Timeout);
237 246 if (ACPI_FAILURE (Status))
238 247 {
239 248 return_ACPI_STATUS (Status);
240 249 }
241 250
242 251 /*
243 252 * Update the global lock handle and check for wraparound. The handle is
244 253 * only used for the external global lock interfaces, but it is updated
245 254 * here to properly handle the case where a single thread may acquire the
246 255 * lock via both the AML and the AcpiAcquireGlobalLock interfaces. The
247 256 * handle is therefore updated on the first acquire from a given thread
248 257 * regardless of where the acquisition request originated.
249 258 */
250 259 AcpiGbl_GlobalLockHandle++;
251 260 if (AcpiGbl_GlobalLockHandle == 0)
252 261 {
253 262 AcpiGbl_GlobalLockHandle = 1;
254 263 }
255 264
256 265 /*
257 266 * Make sure that a global lock actually exists. If not, just
258 267 * treat the lock as a standard mutex.
259 268 */
260 269 if (!AcpiGbl_GlobalLockPresent)
261 270 {
262 271 AcpiGbl_GlobalLockAcquired = TRUE;
263 272 return_ACPI_STATUS (AE_OK);
264 273 }
265 274
266 275 Flags = AcpiOsAcquireLock (AcpiGbl_GlobalLockPendingLock);
267 276
268 277 do
269 278 {
270 279 /* Attempt to acquire the actual hardware lock */
271 280
272 281 ACPI_ACQUIRE_GLOBAL_LOCK (AcpiGbl_FACS, Acquired);
273 282 if (Acquired)
274 283 {
275 284 AcpiGbl_GlobalLockAcquired = TRUE;
276 285 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
277 286 "Acquired hardware Global Lock\n"));
278 287 break;
279 288 }
280 289
281 290 /*
282 291 * Did not get the lock. The pending bit was set above, and
283 292 * we must now wait until we receive the global lock
284 293 * released interrupt.
285 294 */
286 295 AcpiGbl_GlobalLockPending = TRUE;
287 296 AcpiOsReleaseLock (AcpiGbl_GlobalLockPendingLock, Flags);
288 297
289 298 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
290 299 "Waiting for hardware Global Lock\n"));
291 300
292 301 /*
293 302 * Wait for handshake with the global lock interrupt handler.
294 303 * This interface releases the interpreter if we must wait.
295 304 */
296 305 Status = AcpiExSystemWaitSemaphore (AcpiGbl_GlobalLockSemaphore,
297 306 ACPI_WAIT_FOREVER);
298 307
299 308 Flags = AcpiOsAcquireLock (AcpiGbl_GlobalLockPendingLock);
300 309
301 310 } while (ACPI_SUCCESS (Status));
302 311
303 312 AcpiGbl_GlobalLockPending = FALSE;
304 313 AcpiOsReleaseLock (AcpiGbl_GlobalLockPendingLock, Flags);
305 314
306 315 return_ACPI_STATUS (Status);
307 316 }
308 317
309 318
310 319 /*******************************************************************************
311 320 *
312 321 * FUNCTION: AcpiEvReleaseGlobalLock
313 322 *
314 323 * PARAMETERS: None
315 324 *
316 325 * RETURN: Status
317 326 *
318 327 * DESCRIPTION: Releases ownership of the Global Lock.
319 328 *
320 329 ******************************************************************************/
321 330
322 331 ACPI_STATUS
323 332 AcpiEvReleaseGlobalLock (
324 333 void)
325 334 {
326 335 BOOLEAN Pending = FALSE;
327 336 ACPI_STATUS Status = AE_OK;
328 337
329 338
330 339 ACPI_FUNCTION_TRACE (EvReleaseGlobalLock);
331 340
332 341
333 342 /* Lock must be already acquired */
334 343
335 344 if (!AcpiGbl_GlobalLockAcquired)
336 345 {
337 346 ACPI_WARNING ((AE_INFO,
338 347 "Cannot release the ACPI Global Lock, it has not been acquired"));
339 348 return_ACPI_STATUS (AE_NOT_ACQUIRED);
340 349 }
341 350
342 351 if (AcpiGbl_GlobalLockPresent)
343 352 {
344 353 /* Allow any thread to release the lock */
345 354
346 355 ACPI_RELEASE_GLOBAL_LOCK (AcpiGbl_FACS, Pending);
347 356
348 357 /*
349 358 * If the pending bit was set, we must write GBL_RLS to the control
350 359 * register
351 360 */
352 361 if (Pending)
353 362 {
354 363 Status = AcpiWriteBitRegister (
355 364 ACPI_BITREG_GLOBAL_LOCK_RELEASE, ACPI_ENABLE_EVENT);
356 365 }
357 366
↓ open down ↓ |
209 lines elided |
↑ open up ↑ |
358 367 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Released hardware Global Lock\n"));
359 368 }
360 369
361 370 AcpiGbl_GlobalLockAcquired = FALSE;
362 371
363 372 /* Release the local GL mutex */
364 373
365 374 AcpiOsReleaseMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex);
366 375 return_ACPI_STATUS (Status);
367 376 }
377 +
378 +#endif /* !ACPI_REDUCED_HARDWARE */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX