event.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. ASSERT (!EFI_ERROR(Status));
  33. //
  34. // Register for protocol notifactions on this event
  35. //
  36. Status = uefi_call_wrapper(
  37. BS->RegisterProtocolNotify,
  38. 3,
  39. ProtocolGuid,
  40. Event,
  41. Registration
  42. );
  43. ASSERT (!EFI_ERROR(Status));
  44. //
  45. // Kick the event so we will perform an initial pass of
  46. // current installed drivers
  47. //
  48. uefi_call_wrapper(BS->SignalEvent, 1, Event);
  49. return Event;
  50. }
  51. EFI_STATUS
  52. WaitForSingleEvent (
  53. IN EFI_EVENT Event,
  54. IN UINT64 Timeout OPTIONAL
  55. )
  56. {
  57. EFI_STATUS Status;
  58. UINTN Index;
  59. EFI_EVENT TimerEvent;
  60. EFI_EVENT WaitList[2];
  61. if (Timeout) {
  62. //
  63. // Create a timer event
  64. //
  65. Status = uefi_call_wrapper(BS->CreateEvent, 5, EVT_TIMER, 0, NULL, NULL, &TimerEvent);
  66. if (!EFI_ERROR(Status)) {
  67. //
  68. // Set the timer event
  69. //
  70. uefi_call_wrapper(BS->SetTimer, 3, TimerEvent, TimerRelative, Timeout);
  71. //
  72. // Wait for the original event or the timer
  73. //
  74. WaitList[0] = Event;
  75. WaitList[1] = TimerEvent;
  76. Status = uefi_call_wrapper(BS->WaitForEvent, 3, 2, WaitList, &Index);
  77. uefi_call_wrapper(BS->CloseEvent, 1, TimerEvent);
  78. //
  79. // If the timer expired, change the return to timed out
  80. //
  81. if (!EFI_ERROR(Status) && Index == 1) {
  82. Status = EFI_TIMEOUT;
  83. }
  84. }
  85. } else {
  86. //
  87. // No timeout... just wait on the event
  88. //
  89. Status = uefi_call_wrapper(BS->WaitForEvent, 3, 1, &Event, &Index);
  90. ASSERT (!EFI_ERROR(Status));
  91. ASSERT (Index == 0);
  92. }
  93. return Status;
  94. }
  95. VOID
  96. WaitForEventWithTimeout (
  97. IN EFI_EVENT Event,
  98. IN UINTN Timeout,
  99. IN UINTN Row,
  100. IN UINTN Column,
  101. IN CHAR16 *String,
  102. IN EFI_INPUT_KEY TimeoutKey,
  103. OUT EFI_INPUT_KEY *Key
  104. )
  105. {
  106. EFI_STATUS Status;
  107. do {
  108. PrintAt (Column, Row, String, Timeout);
  109. Status = WaitForSingleEvent (Event, 10000000);
  110. if (Status == EFI_SUCCESS) {
  111. if (!EFI_ERROR(uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, ST->ConIn, Key))) {
  112. return;
  113. }
  114. }
  115. } while (Timeout > 0);
  116. *Key = TimeoutKey;
  117. }