ReactOS  0.4.15-dev-439-g292f67a
evglock.c File Reference
#include "acpi.h"
#include "accommon.h"
#include "acevents.h"
#include "acinterp.h"
Include dependency graph for evglock.c:

Go to the source code of this file.

Macros

#define _COMPONENT   ACPI_EVENTS
 

Functions

static UINT32 AcpiEvGlobalLockHandler (void *Context)
 
ACPI_STATUS AcpiEvInitGlobalLockHandler (void)
 
ACPI_STATUS AcpiEvRemoveGlobalLockHandler (void)
 
ACPI_STATUS AcpiEvAcquireGlobalLock (UINT16 Timeout)
 
ACPI_STATUS AcpiEvReleaseGlobalLock (void)
 

Macro Definition Documentation

◆ _COMPONENT

#define _COMPONENT   ACPI_EVENTS

Definition at line 49 of file evglock.c.

Function Documentation

◆ AcpiEvAcquireGlobalLock()

ACPI_STATUS AcpiEvAcquireGlobalLock ( UINT16  Timeout)

Definition at line 230 of file evglock.c.

232 {
235  BOOLEAN Acquired = FALSE;
236 
237 
238  ACPI_FUNCTION_TRACE (EvAcquireGlobalLock);
239 
240 
241  /*
242  * Only one thread can acquire the GL at a time, the GlobalLockMutex
243  * enforces this. This interface releases the interpreter if we must wait.
244  */
245  Status = AcpiExSystemWaitMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex,
246  Timeout);
247  if (ACPI_FAILURE (Status))
248  {
250  }
251 
252  /*
253  * Update the global lock handle and check for wraparound. The handle is
254  * only used for the external global lock interfaces, but it is updated
255  * here to properly handle the case where a single thread may acquire the
256  * lock via both the AML and the AcpiAcquireGlobalLock interfaces. The
257  * handle is therefore updated on the first acquire from a given thread
258  * regardless of where the acquisition request originated.
259  */
260  AcpiGbl_GlobalLockHandle++;
261  if (AcpiGbl_GlobalLockHandle == 0)
262  {
263  AcpiGbl_GlobalLockHandle = 1;
264  }
265 
266  /*
267  * Make sure that a global lock actually exists. If not, just
268  * treat the lock as a standard mutex.
269  */
270  if (!AcpiGbl_GlobalLockPresent)
271  {
272  AcpiGbl_GlobalLockAcquired = TRUE;
274  }
275 
276  Flags = AcpiOsAcquireLock (AcpiGbl_GlobalLockPendingLock);
277 
278  do
279  {
280  /* Attempt to acquire the actual hardware lock */
281 
282  ACPI_ACQUIRE_GLOBAL_LOCK (AcpiGbl_FACS, Acquired);
283  if (Acquired)
284  {
285  AcpiGbl_GlobalLockAcquired = TRUE;
287  "Acquired hardware Global Lock\n"));
288  break;
289  }
290 
291  /*
292  * Did not get the lock. The pending bit was set above, and
293  * we must now wait until we receive the global lock
294  * released interrupt.
295  */
296  AcpiGbl_GlobalLockPending = TRUE;
297  AcpiOsReleaseLock (AcpiGbl_GlobalLockPendingLock, Flags);
298 
300  "Waiting for hardware Global Lock\n"));
301 
302  /*
303  * Wait for handshake with the global lock interrupt handler.
304  * This interface releases the interpreter if we must wait.
305  */
307  AcpiGbl_GlobalLockSemaphore, ACPI_WAIT_FOREVER);
308 
309  Flags = AcpiOsAcquireLock (AcpiGbl_GlobalLockPendingLock);
310 
311  } while (ACPI_SUCCESS (Status));
312 
313  AcpiGbl_GlobalLockPending = FALSE;
314  AcpiOsReleaseLock (AcpiGbl_GlobalLockPendingLock, Flags);
315 
317 }
#define TRUE
Definition: types.h:120
ACPI_CPU_FLAGS AcpiOsAcquireLock(ACPI_SPINLOCK Handle)
Definition: osl.c:498
#define ACPI_SUCCESS(a)
Definition: acexcep.h:94
#define ACPI_CPU_FLAGS
Definition: actypes.h:252
UINT32 ACPI_STATUS
Definition: actypes.h:460
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq)
Definition: accygwin.h:82
ACPI_STATUS AcpiExSystemWaitMutex(ACPI_MUTEX Mutex, UINT16 Timeout)
Definition: exsystem.c:120
unsigned char BOOLEAN
ACPI_STATUS AcpiExSystemWaitSemaphore(ACPI_SEMAPHORE Semaphore, UINT16 Timeout)
Definition: exsystem.c:68
#define ACPI_WAIT_FOREVER
Definition: actypes.h:501
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
Status
Definition: gdiplustypes.h:24
#define ACPI_DB_EXEC
Definition: acoutput.h:165
static ULONG Timeout
Definition: ping.c:61
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
void AcpiOsReleaseLock(ACPI_SPINLOCK Handle, ACPI_CPU_FLAGS Flags)
Definition: osl.c:516
#define AE_OK
Definition: acexcep.h:97

Referenced by AcpiExAcquireMutexObject().

◆ AcpiEvGlobalLockHandler()

static UINT32 AcpiEvGlobalLockHandler ( void Context)
static

Definition at line 168 of file evglock.c.

170 {
173 
174 
175  Flags = AcpiOsAcquireLock (AcpiGbl_GlobalLockPendingLock);
176 
177  /*
178  * If a request for the global lock is not actually pending,
179  * we are done. This handles "spurious" global lock interrupts
180  * which are possible (and have been seen) with bad BIOSs.
181  */
182  if (!AcpiGbl_GlobalLockPending)
183  {
184  goto CleanupAndExit;
185  }
186 
187  /*
188  * Send a unit to the global lock semaphore. The actual acquisition
189  * of the global lock will be performed by the waiting thread.
190  */
191  Status = AcpiOsSignalSemaphore (AcpiGbl_GlobalLockSemaphore, 1);
192  if (ACPI_FAILURE (Status))
193  {
194  ACPI_ERROR ((AE_INFO, "Could not signal Global Lock semaphore"));
195  }
196 
197  AcpiGbl_GlobalLockPending = FALSE;
198 
199 
200 CleanupAndExit:
201 
202  AcpiOsReleaseLock (AcpiGbl_GlobalLockPendingLock, Flags);
203  return (ACPI_INTERRUPT_HANDLED);
204 }
ACPI_CPU_FLAGS AcpiOsAcquireLock(ACPI_SPINLOCK Handle)
Definition: osl.c:498
ACPI_STATUS AcpiOsSignalSemaphore(ACPI_SEMAPHORE Handle, UINT32 Units)
Definition: osl.c:439
#define ACPI_CPU_FLAGS
Definition: actypes.h:252
UINT32 ACPI_STATUS
Definition: actypes.h:460
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define AE_INFO
Definition: acoutput.h:230
#define ACPI_INTERRUPT_HANDLED
Definition: actypes.h:1241
Status
Definition: gdiplustypes.h:24
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
void AcpiOsReleaseLock(ACPI_SPINLOCK Handle, ACPI_CPU_FLAGS Flags)
Definition: osl.c:516

Referenced by AcpiEvInitGlobalLockHandler(), and AcpiEvRemoveGlobalLockHandler().

◆ AcpiEvInitGlobalLockHandler()

ACPI_STATUS AcpiEvInitGlobalLockHandler ( void  )

Definition at line 74 of file evglock.c.

76 {
78 
79 
80  ACPI_FUNCTION_TRACE (EvInitGlobalLockHandler);
81 
82 
83  /* If Hardware Reduced flag is set, there is no global lock */
84 
85  if (AcpiGbl_ReducedHardware)
86  {
88  }
89 
90  /* Attempt installation of the global lock handler */
91 
94 
95  /*
96  * If the global lock does not exist on this platform, the attempt to
97  * enable GBL_STATUS will fail (the GBL_ENABLE bit will not stick).
98  * Map to AE_OK, but mark global lock as not present. Any attempt to
99  * actually use the global lock will be flagged with an error.
100  */
101  AcpiGbl_GlobalLockPresent = FALSE;
103  {
105  "No response from Global Lock hardware, disabling lock"));
106 
108  }
109 
110  Status = AcpiOsCreateLock (&AcpiGbl_GlobalLockPendingLock);
111  if (ACPI_FAILURE (Status))
112  {
114  }
115 
116  AcpiGbl_GlobalLockPending = FALSE;
117  AcpiGbl_GlobalLockPresent = TRUE;
119 }
#define TRUE
Definition: types.h:120
#define ACPI_EVENT_GLOBAL
Definition: actypes.h:756
ACPI_STATUS AcpiInstallFixedEventHandler(UINT32 Event, ACPI_EVENT_HANDLER Handler, void *Context)
Definition: evxface.c:707
UINT32 ACPI_STATUS
Definition: actypes.h:460
ACPI_STATUS AcpiOsCreateLock(ACPI_SPINLOCK *OutHandle)
Definition: osl.c:463
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define AE_INFO
Definition: acoutput.h:230
smooth NULL
Definition: ftsmooth.c:416
#define AE_NO_HARDWARE_RESPONSE
Definition: acexcep.h:130
static UINT32 AcpiEvGlobalLockHandler(void *Context)
Definition: evglock.c:168
Status
Definition: gdiplustypes.h:24
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
#define AE_OK
Definition: acexcep.h:97

Referenced by AcpiEvInstallXruptHandlers().

◆ AcpiEvReleaseGlobalLock()

ACPI_STATUS AcpiEvReleaseGlobalLock ( void  )

Definition at line 333 of file evglock.c.

335 {
338 
339 
340  ACPI_FUNCTION_TRACE (EvReleaseGlobalLock);
341 
342 
343  /* Lock must be already acquired */
344 
345  if (!AcpiGbl_GlobalLockAcquired)
346  {
348  "Cannot release the ACPI Global Lock, it has not been acquired"));
350  }
351 
352  if (AcpiGbl_GlobalLockPresent)
353  {
354  /* Allow any thread to release the lock */
355 
356  ACPI_RELEASE_GLOBAL_LOCK (AcpiGbl_FACS, Pending);
357 
358  /*
359  * If the pending bit was set, we must write GBL_RLS to the control
360  * register
361  */
362  if (Pending)
363  {
366  }
367 
368  ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Released hardware Global Lock\n"));
369  }
370 
371  AcpiGbl_GlobalLockAcquired = FALSE;
372 
373  /* Release the local GL mutex */
374 
375  AcpiOsReleaseMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex);
377 }
#define AE_NOT_ACQUIRED
Definition: acexcep.h:128
ACPI_STATUS AcpiWriteBitRegister(UINT32 RegisterId, UINT32 Value)
Definition: hwxface.c:282
#define ACPI_WARNING(plist)
Definition: acoutput.h:238
#define ACPI_BITREG_GLOBAL_LOCK_RELEASE
Definition: actypes.h:916
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_ENABLE_EVENT
Definition: actypes.h:934
unsigned char BOOLEAN
#define AE_INFO
Definition: acoutput.h:230
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
Status
Definition: gdiplustypes.h:24
#define ACPI_DB_EXEC
Definition: acoutput.h:165
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
#define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Pending)
Definition: accygwin.h:83
void AcpiOsReleaseMutex(ACPI_MUTEX Handle)
Definition: osl.c:333
#define AE_OK
Definition: acexcep.h:97

Referenced by AcpiExReleaseAllMutexes(), and AcpiExReleaseMutexObject().

◆ AcpiEvRemoveGlobalLockHandler()

ACPI_STATUS AcpiEvRemoveGlobalLockHandler ( void  )

Definition at line 135 of file evglock.c.

137 {
139 
140 
141  ACPI_FUNCTION_TRACE (EvRemoveGlobalLockHandler);
142 
143 
144  AcpiGbl_GlobalLockPresent = FALSE;
147 
148  AcpiOsDeleteLock (AcpiGbl_GlobalLockPendingLock);
150 }
#define ACPI_EVENT_GLOBAL
Definition: actypes.h:756
UINT32 ACPI_STATUS
Definition: actypes.h:460
ACPI_STATUS AcpiRemoveFixedEventHandler(UINT32 Event, ACPI_EVENT_HANDLER Handler)
Definition: evxface.c:786
void AcpiOsDeleteLock(ACPI_SPINLOCK Handle)
Definition: osl.c:485
static UINT32 AcpiEvGlobalLockHandler(void *Context)
Definition: evglock.c:168
Status
Definition: gdiplustypes.h:24
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480

Referenced by AcpiEvTerminate().