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