2008-05-21 03:40:12 +02:00
|
|
|
/** @file
|
2008-04-09 09:07:50 +02:00
|
|
|
UEFI Event support functions implemented in this file.
|
|
|
|
|
2011-06-17 01:28:02 +02:00
|
|
|
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
|
2010-04-24 11:49:11 +02:00
|
|
|
This program and the accompanying materials
|
2007-07-04 12:51:54 +02:00
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
2008-04-09 09:07:50 +02:00
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
|
2008-08-27 16:29:23 +02:00
|
|
|
#include "DxeMain.h"
|
2008-09-23 09:35:34 +02:00
|
|
|
#include "Event.h"
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-09-16 09:53:15 +02:00
|
|
|
///
|
|
|
|
/// gEfiCurrentTpl - Current Task priority level
|
|
|
|
///
|
|
|
|
EFI_TPL gEfiCurrentTpl = TPL_APPLICATION;
|
|
|
|
|
|
|
|
///
|
2011-02-12 02:34:05 +01:00
|
|
|
/// gEventQueueLock - Protects the event queues
|
2008-09-16 09:53:15 +02:00
|
|
|
///
|
|
|
|
EFI_LOCK gEventQueueLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// gEventQueue - A list of event's to notify for each priority level
|
|
|
|
///
|
|
|
|
LIST_ENTRY gEventQueue[TPL_HIGH_LEVEL + 1];
|
|
|
|
|
|
|
|
///
|
|
|
|
/// gEventPending - A bitmask of the EventQueues that are pending
|
|
|
|
///
|
|
|
|
UINTN gEventPending = 0;
|
|
|
|
|
|
|
|
///
|
|
|
|
/// gEventSignalQueue - A list of events to signal based on EventGroup type
|
|
|
|
///
|
|
|
|
LIST_ENTRY gEventSignalQueue = INITIALIZE_LIST_HEAD_VARIABLE (gEventSignalQueue);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Enumerate the valid types
|
|
|
|
///
|
2007-07-04 12:51:54 +02:00
|
|
|
UINT32 mEventTable[] = {
|
2008-09-16 09:53:15 +02:00
|
|
|
///
|
|
|
|
/// 0x80000200 Timer event with a notification function that is
|
|
|
|
/// queue when the event is signaled with SignalEvent()
|
|
|
|
///
|
2007-07-04 12:51:54 +02:00
|
|
|
EVT_TIMER | EVT_NOTIFY_SIGNAL,
|
2008-09-16 09:53:15 +02:00
|
|
|
///
|
|
|
|
/// 0x80000000 Timer event without a notification function. It can be
|
|
|
|
/// signaled with SignalEvent() and checked with CheckEvent() or WaitForEvent().
|
|
|
|
///
|
2007-07-04 12:51:54 +02:00
|
|
|
EVT_TIMER,
|
2008-09-16 09:53:15 +02:00
|
|
|
///
|
|
|
|
/// 0x00000100 Generic event with a notification function that
|
|
|
|
/// can be waited on with CheckEvent() or WaitForEvent()
|
|
|
|
///
|
2007-07-04 12:51:54 +02:00
|
|
|
EVT_NOTIFY_WAIT,
|
2008-09-16 09:53:15 +02:00
|
|
|
///
|
|
|
|
/// 0x00000200 Generic event with a notification function that
|
|
|
|
/// is queue when the event is signaled with SignalEvent()
|
|
|
|
///
|
2007-07-04 12:51:54 +02:00
|
|
|
EVT_NOTIFY_SIGNAL,
|
2008-09-16 09:53:15 +02:00
|
|
|
///
|
|
|
|
/// 0x00000201 ExitBootServicesEvent.
|
|
|
|
///
|
2007-07-04 12:51:54 +02:00
|
|
|
EVT_SIGNAL_EXIT_BOOT_SERVICES,
|
2008-09-16 09:53:15 +02:00
|
|
|
///
|
|
|
|
/// 0x60000202 SetVirtualAddressMapEvent.
|
|
|
|
///
|
2007-07-04 12:51:54 +02:00
|
|
|
EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
|
|
|
|
|
2008-09-16 09:53:15 +02:00
|
|
|
///
|
|
|
|
/// 0x00000000 Generic event without a notification function.
|
|
|
|
/// It can be signaled with SignalEvent() and checked with CheckEvent()
|
|
|
|
/// or WaitForEvent().
|
|
|
|
///
|
2007-07-04 12:51:54 +02:00
|
|
|
0x00000000,
|
2008-09-16 09:53:15 +02:00
|
|
|
///
|
|
|
|
/// 0x80000100 Timer event with a notification function that can be
|
|
|
|
/// waited on with CheckEvent() or WaitForEvent()
|
|
|
|
///
|
2007-07-04 12:51:54 +02:00
|
|
|
EVT_TIMER | EVT_NOTIFY_WAIT,
|
|
|
|
};
|
|
|
|
|
2011-06-17 01:28:02 +02:00
|
|
|
///
|
|
|
|
/// gIdleLoopEvent - Event which is signalled when the core is idle
|
|
|
|
///
|
|
|
|
EFI_EVENT gIdleLoopEvent = NULL;
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Enter critical section by acquiring the lock on gEventQueueLock.
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
VOID
|
|
|
|
CoreAcquireEventLock (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CoreAcquireLock (&gEventQueueLock);
|
|
|
|
}
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Exit critical section by releasing the lock on gEventQueueLock.
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
VOID
|
|
|
|
CoreReleaseEventLock (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CoreReleaseLock (&gEventQueueLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
2008-09-16 09:35:17 +02:00
|
|
|
Initializes "event" support.
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
@retval EFI_SUCCESS Always return success
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
CoreInitializeEventServices (
|
|
|
|
VOID
|
|
|
|
)
|
2007-07-04 12:51:54 +02:00
|
|
|
{
|
|
|
|
UINTN Index;
|
|
|
|
|
|
|
|
for (Index=0; Index <= TPL_HIGH_LEVEL; Index++) {
|
|
|
|
InitializeListHead (&gEventQueue[Index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoreInitializeTimer ();
|
|
|
|
|
2011-06-17 01:28:02 +02:00
|
|
|
CoreCreateEventEx (
|
|
|
|
EVT_NOTIFY_SIGNAL,
|
|
|
|
TPL_NOTIFY,
|
|
|
|
CoreEmptyCallbackFunction,
|
|
|
|
NULL,
|
|
|
|
&gIdleLoopEventGuid,
|
|
|
|
&gIdleLoopEvent
|
|
|
|
);
|
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
2007-07-04 12:51:54 +02:00
|
|
|
Dispatches all pending events.
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@param Priority The task priority level of event notifications
|
2008-05-09 09:08:30 +02:00
|
|
|
to dispatch
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
CoreDispatchEventNotifies (
|
|
|
|
IN EFI_TPL Priority
|
|
|
|
)
|
2007-07-04 12:51:54 +02:00
|
|
|
{
|
|
|
|
IEVENT *Event;
|
|
|
|
LIST_ENTRY *Head;
|
|
|
|
|
|
|
|
CoreAcquireEventLock ();
|
|
|
|
ASSERT (gEventQueueLock.OwnerTpl == Priority);
|
|
|
|
Head = &gEventQueue[Priority];
|
|
|
|
|
|
|
|
//
|
|
|
|
// Dispatch all the pending notifications
|
|
|
|
//
|
|
|
|
while (!IsListEmpty (Head)) {
|
|
|
|
|
|
|
|
Event = CR (Head->ForwardLink, IEVENT, NotifyLink, EVENT_SIGNATURE);
|
|
|
|
RemoveEntryList (&Event->NotifyLink);
|
|
|
|
|
|
|
|
Event->NotifyLink.ForwardLink = NULL;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Only clear the SIGNAL status if it is a SIGNAL type event.
|
|
|
|
// WAIT type events are only cleared in CheckEvent()
|
|
|
|
//
|
2008-10-21 05:11:47 +02:00
|
|
|
if ((Event->Type & EVT_NOTIFY_SIGNAL) != 0) {
|
2007-07-04 12:51:54 +02:00
|
|
|
Event->SignalCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoreReleaseEventLock ();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Notify this event
|
|
|
|
//
|
|
|
|
ASSERT (Event->NotifyFunction != NULL);
|
|
|
|
Event->NotifyFunction (Event, Event->NotifyContext);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check for next pending event
|
|
|
|
//
|
|
|
|
CoreAcquireEventLock ();
|
|
|
|
}
|
|
|
|
|
|
|
|
gEventPending &= ~(1 << Priority);
|
|
|
|
CoreReleaseEventLock ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Queues the event's notification function to fire.
|
|
|
|
|
|
|
|
@param Event The Event to notify
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
VOID
|
|
|
|
CoreNotifyEvent (
|
|
|
|
IN IEVENT *Event
|
|
|
|
)
|
|
|
|
{
|
|
|
|
|
|
|
|
//
|
|
|
|
// Event database must be locked
|
|
|
|
//
|
|
|
|
ASSERT_LOCKED (&gEventQueueLock);
|
|
|
|
|
|
|
|
//
|
|
|
|
// If the event is queued somewhere, remove it
|
|
|
|
//
|
|
|
|
|
|
|
|
if (Event->NotifyLink.ForwardLink != NULL) {
|
|
|
|
RemoveEntryList (&Event->NotifyLink);
|
|
|
|
Event->NotifyLink.ForwardLink = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Queue the event to the pending notification list
|
|
|
|
//
|
|
|
|
|
|
|
|
InsertTailList (&gEventQueue[Event->NotifyTpl], &Event->NotifyLink);
|
|
|
|
gEventPending |= (UINTN)(1 << Event->NotifyTpl);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Signals all events in the EventGroup.
|
|
|
|
|
|
|
|
@param EventGroup The list to signal
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
VOID
|
|
|
|
CoreNotifySignalList (
|
|
|
|
IN EFI_GUID *EventGroup
|
|
|
|
)
|
|
|
|
{
|
|
|
|
LIST_ENTRY *Link;
|
|
|
|
LIST_ENTRY *Head;
|
|
|
|
IEVENT *Event;
|
|
|
|
|
|
|
|
CoreAcquireEventLock ();
|
|
|
|
|
|
|
|
Head = &gEventSignalQueue;
|
|
|
|
for (Link = Head->ForwardLink; Link != Head; Link = Link->ForwardLink) {
|
|
|
|
Event = CR (Link, IEVENT, SignalLink, EVENT_SIGNATURE);
|
|
|
|
if (CompareGuid (&Event->EventGroup, EventGroup)) {
|
|
|
|
CoreNotifyEvent (Event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CoreReleaseEventLock ();
|
|
|
|
}
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Creates a general-purpose event structure.
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@param Type The type of event to create and its mode and
|
|
|
|
attributes
|
|
|
|
@param NotifyTpl The task priority level of event notifications
|
|
|
|
@param NotifyFunction Pointer to the events notification function
|
|
|
|
@param NotifyContext Pointer to the notification functions context;
|
|
|
|
corresponds to parameter "Context" in the
|
|
|
|
notification function
|
|
|
|
@param Event Pointer to the newly created event if the call
|
|
|
|
succeeds; undefined otherwise
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The event structure was created
|
|
|
|
@retval EFI_INVALID_PARAMETER One of the parameters has an invalid value
|
2008-05-09 09:08:30 +02:00
|
|
|
@retval EFI_OUT_OF_RESOURCES The event could not be allocated
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
CoreCreateEvent (
|
|
|
|
IN UINT32 Type,
|
|
|
|
IN EFI_TPL NotifyTpl,
|
|
|
|
IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL
|
|
|
|
IN VOID *NotifyContext, OPTIONAL
|
|
|
|
OUT EFI_EVENT *Event
|
|
|
|
)
|
|
|
|
{
|
2008-02-14 03:47:49 +01:00
|
|
|
return CoreCreateEventEx (Type, NotifyTpl, NotifyFunction, NotifyContext, NULL, Event);
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Creates a general-purpose event structure
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@param Type The type of event to create and its mode and
|
|
|
|
attributes
|
|
|
|
@param NotifyTpl The task priority level of event notifications
|
|
|
|
@param NotifyFunction Pointer to the events notification function
|
|
|
|
@param NotifyContext Pointer to the notification functions context;
|
|
|
|
corresponds to parameter "Context" in the
|
|
|
|
notification function
|
|
|
|
@param EventGroup GUID for EventGroup if NULL act the same as
|
|
|
|
gBS->CreateEvent().
|
|
|
|
@param Event Pointer to the newly created event if the call
|
|
|
|
succeeds; undefined otherwise
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The event structure was created
|
|
|
|
@retval EFI_INVALID_PARAMETER One of the parameters has an invalid value
|
2008-05-09 09:08:30 +02:00
|
|
|
@retval EFI_OUT_OF_RESOURCES The event could not be allocated
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
CoreCreateEventEx (
|
|
|
|
IN UINT32 Type,
|
|
|
|
IN EFI_TPL NotifyTpl,
|
|
|
|
IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL
|
|
|
|
IN CONST VOID *NotifyContext, OPTIONAL
|
|
|
|
IN CONST EFI_GUID *EventGroup, OPTIONAL
|
|
|
|
OUT EFI_EVENT *Event
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
IEVENT *IEvent;
|
|
|
|
INTN Index;
|
|
|
|
|
|
|
|
|
2008-08-02 01:54:52 +02:00
|
|
|
if (Event == NULL) {
|
2007-07-04 12:51:54 +02:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check to make sure no reserved flags are set
|
|
|
|
//
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
for (Index = 0; Index < (sizeof (mEventTable) / sizeof (UINT32)); Index++) {
|
|
|
|
if (Type == mEventTable[Index]) {
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(EFI_ERROR (Status)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2008-02-14 03:47:49 +01:00
|
|
|
//
|
|
|
|
// Convert Event type for pre-defined Event groups
|
|
|
|
//
|
|
|
|
if (EventGroup != NULL) {
|
|
|
|
//
|
|
|
|
// For event group, type EVT_SIGNAL_EXIT_BOOT_SERVICES and EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE
|
|
|
|
// are not valid
|
|
|
|
//
|
|
|
|
if ((Type == EVT_SIGNAL_EXIT_BOOT_SERVICES) || (Type == EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
if (CompareGuid (EventGroup, &gEfiEventExitBootServicesGuid)) {
|
|
|
|
Type = EVT_SIGNAL_EXIT_BOOT_SERVICES;
|
|
|
|
} else if (CompareGuid (EventGroup, &gEfiEventVirtualAddressChangeGuid)) {
|
|
|
|
Type = EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Convert EFI 1.10 Events to their UEFI 2.0 CreateEventEx mapping
|
|
|
|
//
|
|
|
|
if (Type == EVT_SIGNAL_EXIT_BOOT_SERVICES) {
|
|
|
|
EventGroup = &gEfiEventExitBootServicesGuid;
|
|
|
|
} else if (Type == EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE) {
|
|
|
|
EventGroup = &gEfiEventVirtualAddressChangeGuid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// If it's a notify type of event, check its parameters
|
|
|
|
//
|
2008-05-09 09:52:58 +02:00
|
|
|
if ((Type & (EVT_NOTIFY_WAIT | EVT_NOTIFY_SIGNAL)) != 0) {
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Check for an invalid NotifyFunction or NotifyTpl
|
|
|
|
//
|
|
|
|
if ((NotifyFunction == NULL) ||
|
2008-08-02 01:54:52 +02:00
|
|
|
(NotifyTpl <= TPL_APPLICATION) ||
|
2007-07-04 12:51:54 +02:00
|
|
|
(NotifyTpl >= TPL_HIGH_LEVEL)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// No notification needed, zero ignored values
|
|
|
|
//
|
|
|
|
NotifyTpl = 0;
|
|
|
|
NotifyFunction = NULL;
|
|
|
|
NotifyContext = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2009-01-15 04:00:00 +01:00
|
|
|
// Allocate and initialize a new event structure.
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2009-01-15 04:00:00 +01:00
|
|
|
if ((Type & EVT_RUNTIME) != 0) {
|
|
|
|
IEvent = AllocateRuntimeZeroPool (sizeof (IEVENT));
|
|
|
|
} else {
|
|
|
|
IEvent = AllocateZeroPool (sizeof (IEVENT));
|
|
|
|
}
|
|
|
|
if (IEvent == NULL) {
|
2007-07-04 12:51:54 +02:00
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
IEvent->Signature = EVENT_SIGNATURE;
|
|
|
|
IEvent->Type = Type;
|
|
|
|
|
|
|
|
IEvent->NotifyTpl = NotifyTpl;
|
|
|
|
IEvent->NotifyFunction = NotifyFunction;
|
|
|
|
IEvent->NotifyContext = (VOID *)NotifyContext;
|
|
|
|
if (EventGroup != NULL) {
|
|
|
|
CopyGuid (&IEvent->EventGroup, EventGroup);
|
|
|
|
IEvent->ExFlag = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*Event = IEvent;
|
|
|
|
|
2008-05-09 09:52:58 +02:00
|
|
|
if ((Type & EVT_RUNTIME) != 0) {
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Keep a list of all RT events so we can tell the RT AP.
|
|
|
|
//
|
|
|
|
IEvent->RuntimeData.Type = Type;
|
|
|
|
IEvent->RuntimeData.NotifyTpl = NotifyTpl;
|
|
|
|
IEvent->RuntimeData.NotifyFunction = NotifyFunction;
|
|
|
|
IEvent->RuntimeData.NotifyContext = (VOID *) NotifyContext;
|
|
|
|
IEvent->RuntimeData.Event = (EFI_EVENT *) IEvent;
|
|
|
|
InsertTailList (&gRuntime->EventHead, &IEvent->RuntimeData.Link);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoreAcquireEventLock ();
|
|
|
|
|
|
|
|
if ((Type & EVT_NOTIFY_SIGNAL) != 0x00000000) {
|
|
|
|
//
|
|
|
|
// The Event's NotifyFunction must be queued whenever the event is signaled
|
|
|
|
//
|
|
|
|
InsertHeadList (&gEventSignalQueue, &IEvent->SignalLink);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoreReleaseEventLock ();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Done
|
|
|
|
//
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
2008-07-18 11:50:09 +02:00
|
|
|
Signals the event. Queues the event to be notified if needed.
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-07-18 11:50:09 +02:00
|
|
|
@param UserEvent The event to signal .
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@retval EFI_INVALID_PARAMETER Parameters are not valid.
|
2008-05-09 09:08:30 +02:00
|
|
|
@retval EFI_SUCCESS The event was signaled.
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
CoreSignalEvent (
|
|
|
|
IN EFI_EVENT UserEvent
|
|
|
|
)
|
2007-07-04 12:51:54 +02:00
|
|
|
{
|
|
|
|
IEVENT *Event;
|
|
|
|
|
|
|
|
Event = UserEvent;
|
|
|
|
|
|
|
|
if (Event == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Event->Signature != EVENT_SIGNATURE) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoreAcquireEventLock ();
|
|
|
|
|
|
|
|
//
|
|
|
|
// If the event is not already signalled, do so
|
|
|
|
//
|
|
|
|
|
|
|
|
if (Event->SignalCount == 0x00000000) {
|
|
|
|
Event->SignalCount++;
|
|
|
|
|
|
|
|
//
|
|
|
|
// If signalling type is a notify function, queue it
|
|
|
|
//
|
2008-10-21 05:11:47 +02:00
|
|
|
if ((Event->Type & EVT_NOTIFY_SIGNAL) != 0) {
|
2007-07-04 12:51:54 +02:00
|
|
|
if (Event->ExFlag) {
|
|
|
|
//
|
|
|
|
// The CreateEventEx() style requires all members of the Event Group
|
|
|
|
// to be signaled.
|
|
|
|
//
|
|
|
|
CoreReleaseEventLock ();
|
|
|
|
CoreNotifySignalList (&Event->EventGroup);
|
|
|
|
CoreAcquireEventLock ();
|
|
|
|
} else {
|
|
|
|
CoreNotifyEvent (Event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CoreReleaseEventLock ();
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Check the status of an event.
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@param UserEvent The event to check
|
2008-05-09 09:08:30 +02:00
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@retval EFI_SUCCESS The event is in the signaled state
|
|
|
|
@retval EFI_NOT_READY The event is not in the signaled state
|
2008-05-09 09:08:30 +02:00
|
|
|
@retval EFI_INVALID_PARAMETER Event is of type EVT_NOTIFY_SIGNAL
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
CoreCheckEvent (
|
|
|
|
IN EFI_EVENT UserEvent
|
|
|
|
)
|
|
|
|
{
|
|
|
|
IEVENT *Event;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
Event = UserEvent;
|
|
|
|
|
|
|
|
if (Event == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Event->Signature != EVENT_SIGNATURE) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2008-07-18 11:50:09 +02:00
|
|
|
if ((Event->Type & EVT_NOTIFY_SIGNAL) != 0) {
|
2007-07-04 12:51:54 +02:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = EFI_NOT_READY;
|
|
|
|
|
2008-10-21 05:11:47 +02:00
|
|
|
if ((Event->SignalCount == 0) && ((Event->Type & EVT_NOTIFY_WAIT) != 0)) {
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Queue the wait notify function
|
|
|
|
//
|
|
|
|
CoreAcquireEventLock ();
|
2008-10-21 05:11:47 +02:00
|
|
|
if (Event->SignalCount == 0) {
|
2007-07-04 12:51:54 +02:00
|
|
|
CoreNotifyEvent (Event);
|
|
|
|
}
|
|
|
|
CoreReleaseEventLock ();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// If the even looks signalled, get the lock and clear it
|
|
|
|
//
|
|
|
|
|
2008-10-21 05:11:47 +02:00
|
|
|
if (Event->SignalCount != 0) {
|
2007-07-04 12:51:54 +02:00
|
|
|
CoreAcquireEventLock ();
|
|
|
|
|
2008-10-21 05:11:47 +02:00
|
|
|
if (Event->SignalCount != 0) {
|
2007-07-04 12:51:54 +02:00
|
|
|
Event->SignalCount = 0;
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoreReleaseEventLock ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
|
|
|
Stops execution until an event is signaled.
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@param NumberOfEvents The number of events in the UserEvents array
|
|
|
|
@param UserEvents An array of EFI_EVENT
|
|
|
|
@param UserIndex Pointer to the index of the event which
|
|
|
|
satisfied the wait condition
|
2008-05-09 09:08:30 +02:00
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@retval EFI_SUCCESS The event indicated by Index was signaled.
|
|
|
|
@retval EFI_INVALID_PARAMETER The event indicated by Index has a notification
|
|
|
|
function or Event was not a valid type
|
2008-05-09 09:08:30 +02:00
|
|
|
@retval EFI_UNSUPPORTED The current TPL is not TPL_APPLICATION
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
CoreWaitForEvent (
|
|
|
|
IN UINTN NumberOfEvents,
|
|
|
|
IN EFI_EVENT *UserEvents,
|
|
|
|
OUT UINTN *UserIndex
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN Index;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Can only WaitForEvent at TPL_APPLICATION
|
|
|
|
//
|
|
|
|
if (gEfiCurrentTpl != TPL_APPLICATION) {
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
|
|
|
|
for(Index = 0; Index < NumberOfEvents; Index++) {
|
|
|
|
|
|
|
|
Status = CoreCheckEvent (UserEvents[Index]);
|
|
|
|
|
|
|
|
//
|
|
|
|
// provide index of event that caused problem
|
|
|
|
//
|
|
|
|
if (Status != EFI_NOT_READY) {
|
|
|
|
*UserIndex = Index;
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2011-06-17 01:28:02 +02:00
|
|
|
// Signal the Idle event
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2011-06-17 01:28:02 +02:00
|
|
|
CoreSignalEvent (gIdleLoopEvent);
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
2007-07-04 12:51:54 +02:00
|
|
|
Closes an event and frees the event structure.
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@param UserEvent Event to close
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@retval EFI_INVALID_PARAMETER Parameters are not valid.
|
2008-05-09 09:08:30 +02:00
|
|
|
@retval EFI_SUCCESS The event has been closed
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
CoreCloseEvent (
|
|
|
|
IN EFI_EVENT UserEvent
|
|
|
|
)
|
2007-07-04 12:51:54 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
IEVENT *Event;
|
|
|
|
|
|
|
|
Event = UserEvent;
|
|
|
|
|
|
|
|
if (Event == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Event->Signature != EVENT_SIGNATURE) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// If it's a timer event, make sure it's not pending
|
|
|
|
//
|
2008-07-18 11:50:09 +02:00
|
|
|
if ((Event->Type & EVT_TIMER) != 0) {
|
2007-07-04 12:51:54 +02:00
|
|
|
CoreSetTimer (Event, TimerCancel, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoreAcquireEventLock ();
|
|
|
|
|
|
|
|
//
|
|
|
|
// If the event is queued somewhere, remove it
|
|
|
|
//
|
|
|
|
|
|
|
|
if (Event->RuntimeData.Link.ForwardLink != NULL) {
|
|
|
|
RemoveEntryList (&Event->RuntimeData.Link);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Event->NotifyLink.ForwardLink != NULL) {
|
|
|
|
RemoveEntryList (&Event->NotifyLink);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Event->SignalLink.ForwardLink != NULL) {
|
|
|
|
RemoveEntryList (&Event->SignalLink);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoreReleaseEventLock ();
|
|
|
|
|
|
|
|
//
|
|
|
|
// If the event is registered on a protocol notify, then remove it from the protocol database
|
|
|
|
//
|
|
|
|
CoreUnregisterProtocolNotify (Event);
|
|
|
|
|
|
|
|
Status = CoreFreePool (Event);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
2011-06-17 01:28:02 +02:00
|
|
|
|