1 /** @file 2 3 Implements 4 - the SNM.WaitForPacket EVT_NOTIFY_WAIT event, 5 - the EVT_SIGNAL_EXIT_BOOT_SERVICES event 6 for the virtio-net driver. 7 8 Copyright (C) 2013, Red Hat, Inc. 9 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR> 10 11 This program and the accompanying materials are licensed and made available 12 under the terms and conditions of the BSD License which accompanies this 13 distribution. The full text of the license may be found at 14 http://opensource.org/licenses/bsd-license.php 15 16 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT 17 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 18 19 **/ 20 21 #include <Library/BaseLib.h> 22 #include <Library/UefiBootServicesTableLib.h> 23 24 #include "VirtioNet.h" 25 26 /** 27 Invoke a notification event 28 29 @param Event Event whose notification function is being 30 invoked. 31 @param Context The pointer to the notification function's 32 context, which is implementation-dependent. 33 34 **/ 35 36 VOID 37 EFIAPI 38 VirtioNetIsPacketAvailable ( 39 IN EFI_EVENT Event, 40 IN VOID *Context 41 ) 42 { 43 // 44 // This callback has been enqueued by an external application and is 45 // running at TPL_CALLBACK already. 46 // 47 // The WaitForPacket logic is similar to that of WaitForKey. The former has 48 // almost no documentation in either the UEFI-2.3.1+errC spec or the 49 // DWG-2.3.1, but WaitForKey does have some. 50 // 51 VNET_DEV *Dev; 52 UINT16 RxCurUsed; 53 54 Dev = Context; 55 if (Dev->Snm.State != EfiSimpleNetworkInitialized) { 56 return; 57 } 58 59 // 60 // virtio-0.9.5, 2.4.2 Receiving Used Buffers From the Device 61 // 62 MemoryFence (); 63 RxCurUsed = *Dev->RxRing.Used.Idx; 64 MemoryFence (); 65 66 if (Dev->RxLastUsed != RxCurUsed) { 67 gBS->SignalEvent (&Dev->Snp.WaitForPacket); 68 } 69 } 70 71 VOID 72 EFIAPI 73 VirtioNetExitBoot ( 74 IN EFI_EVENT Event, 75 IN VOID *Context 76 ) 77 { 78 // 79 // This callback has been enqueued by ExitBootServices() and is running at 80 // TPL_CALLBACK already. 81 // 82 // Shut down pending transfers according to DWG-2.3.1, "25.5.1 Exit Boot 83 // Services Event". 84 // 85 VNET_DEV *Dev; 86 87 Dev = Context; 88 if (Dev->Snm.State == EfiSimpleNetworkInitialized) { 89 Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); 90 } 91 } 92