event.c 3.2 KB

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