Events.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /** @file
  2. Implements
  3. - the SNM.WaitForPacket EVT_NOTIFY_WAIT event,
  4. - the EVT_SIGNAL_EXIT_BOOT_SERVICES event
  5. for the virtio-net driver.
  6. Copyright (C) 2013, Red Hat, Inc.
  7. Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
  8. SPDX-License-Identifier: BSD-2-Clause-Patent
  9. **/
  10. #include <Library/BaseLib.h>
  11. #include <Library/UefiBootServicesTableLib.h>
  12. #include "VirtioNet.h"
  13. /**
  14. Invoke a notification event
  15. @param Event Event whose notification function is being
  16. invoked.
  17. @param Context The pointer to the notification function's
  18. context, which is implementation-dependent.
  19. **/
  20. VOID
  21. EFIAPI
  22. VirtioNetIsPacketAvailable (
  23. IN EFI_EVENT Event,
  24. IN VOID *Context
  25. )
  26. {
  27. //
  28. // This callback has been enqueued by an external application and is
  29. // running at TPL_CALLBACK already.
  30. //
  31. // The WaitForPacket logic is similar to that of WaitForKey. The former has
  32. // almost no documentation in either the UEFI-2.3.1+errC spec or the
  33. // DWG-2.3.1, but WaitForKey does have some.
  34. //
  35. VNET_DEV *Dev;
  36. UINT16 RxCurUsed;
  37. Dev = Context;
  38. if (Dev->Snm.State != EfiSimpleNetworkInitialized) {
  39. return;
  40. }
  41. //
  42. // virtio-0.9.5, 2.4.2 Receiving Used Buffers From the Device
  43. //
  44. MemoryFence ();
  45. RxCurUsed = *Dev->RxRing.Used.Idx;
  46. MemoryFence ();
  47. if (Dev->RxLastUsed != RxCurUsed) {
  48. gBS->SignalEvent (Dev->Snp.WaitForPacket);
  49. }
  50. }
  51. VOID
  52. EFIAPI
  53. VirtioNetExitBoot (
  54. IN EFI_EVENT Event,
  55. IN VOID *Context
  56. )
  57. {
  58. //
  59. // This callback has been enqueued by ExitBootServices() and is running at
  60. // TPL_CALLBACK already.
  61. //
  62. // Shut down pending transfers according to DWG-2.3.1, "25.5.1 Exit Boot
  63. // Services Event".
  64. //
  65. VNET_DEV *Dev;
  66. DEBUG ((DEBUG_VERBOSE, "%a: Context=0x%p\n", __FUNCTION__, Context));
  67. Dev = Context;
  68. if (Dev->Snm.State == EfiSimpleNetworkInitialized) {
  69. Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
  70. }
  71. }