1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
/*++
Copyright (c) 1998 Intel Corporation
Module Name:
event.c
Abstract:
Revision History
--*/
#include "lib.h"
EFI_EVENT
LibCreateProtocolNotifyEvent (
IN EFI_GUID *ProtocolGuid,
IN EFI_TPL NotifyTpl,
IN EFI_EVENT_NOTIFY NotifyFunction,
IN VOID *NotifyContext,
OUT VOID *Registration
)
{
EFI_STATUS Status;
EFI_EVENT Event;
//
// Create the event
//
Status = uefi_call_wrapper(
BS->CreateEvent,
5,
EVT_NOTIFY_SIGNAL,
NotifyTpl,
NotifyFunction,
NotifyContext,
&Event
);
ASSERT (!EFI_ERROR(Status));
//
// Register for protocol notifactions on this event
//
Status = uefi_call_wrapper(
BS->RegisterProtocolNotify,
3,
ProtocolGuid,
Event,
Registration
);
ASSERT (!EFI_ERROR(Status));
//
// Kick the event so we will perform an initial pass of
// current installed drivers
//
uefi_call_wrapper(BS->SignalEvent, 1, Event);
return Event;
}
EFI_STATUS
WaitForSingleEvent (
IN EFI_EVENT Event,
IN UINT64 Timeout OPTIONAL
)
{
EFI_STATUS Status;
UINTN Index;
EFI_EVENT TimerEvent;
EFI_EVENT WaitList[2];
if (Timeout) {
//
// Create a timer event
//
Status = uefi_call_wrapper(BS->CreateEvent, 5, EVT_TIMER, 0, NULL, NULL, &TimerEvent);
if (!EFI_ERROR(Status)) {
//
// Set the timer event
//
uefi_call_wrapper(BS->SetTimer, 3, TimerEvent, TimerRelative, Timeout);
//
// Wait for the original event or the timer
//
WaitList[0] = Event;
WaitList[1] = TimerEvent;
Status = uefi_call_wrapper(BS->WaitForEvent, 3, 2, WaitList, &Index);
uefi_call_wrapper(BS->CloseEvent, 1, TimerEvent);
//
// If the timer expired, change the return to timed out
//
if (!EFI_ERROR(Status) && Index == 1) {
Status = EFI_TIMEOUT;
}
}
} else {
//
// No timeout... just wait on the event
//
Status = uefi_call_wrapper(BS->WaitForEvent, 3, 1, &Event, &Index);
ASSERT (!EFI_ERROR(Status));
ASSERT (Index == 0);
}
return Status;
}
VOID
WaitForEventWithTimeout (
IN EFI_EVENT Event,
IN UINTN Timeout,
IN UINTN Row,
IN UINTN Column,
IN CHAR16 *String,
IN EFI_INPUT_KEY TimeoutKey,
OUT EFI_INPUT_KEY *Key
)
{
EFI_STATUS Status;
do {
PrintAt (Column, Row, String, Timeout);
Status = WaitForSingleEvent (Event, 10000000);
if (Status == EFI_SUCCESS) {
if (!EFI_ERROR(uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, ST->ConIn, Key))) {
return;
}
}
} while (Timeout > 0);
*Key = TimeoutKey;
}
|