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