]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/VirtioNetDxe/Events.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / OvmfPkg / VirtioNetDxe / Events.c
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 SPDX-License-Identifier: BSD-2-Clause-Patent
12
13 **/
14
15 #include <Library/BaseLib.h>
16 #include <Library/UefiBootServicesTableLib.h>
17
18 #include "VirtioNet.h"
19
20 /**
21 Invoke a notification event
22
23 @param Event Event whose notification function is being
24 invoked.
25 @param Context The pointer to the notification function's
26 context, which is implementation-dependent.
27
28 **/
29 VOID
30 EFIAPI
31 VirtioNetIsPacketAvailable (
32 IN EFI_EVENT Event,
33 IN VOID *Context
34 )
35 {
36 //
37 // This callback has been enqueued by an external application and is
38 // running at TPL_CALLBACK already.
39 //
40 // The WaitForPacket logic is similar to that of WaitForKey. The former has
41 // almost no documentation in either the UEFI-2.3.1+errC spec or the
42 // DWG-2.3.1, but WaitForKey does have some.
43 //
44 VNET_DEV *Dev;
45 UINT16 RxCurUsed;
46
47 Dev = Context;
48 if (Dev->Snm.State != EfiSimpleNetworkInitialized) {
49 return;
50 }
51
52 //
53 // virtio-0.9.5, 2.4.2 Receiving Used Buffers From the Device
54 //
55 MemoryFence ();
56 RxCurUsed = *Dev->RxRing.Used.Idx;
57 MemoryFence ();
58
59 if (Dev->RxLastUsed != RxCurUsed) {
60 gBS->SignalEvent (Dev->Snp.WaitForPacket);
61 }
62 }
63
64 VOID
65 EFIAPI
66 VirtioNetExitBoot (
67 IN EFI_EVENT Event,
68 IN VOID *Context
69 )
70 {
71 //
72 // This callback has been enqueued by ExitBootServices() and is running at
73 // TPL_CALLBACK already.
74 //
75 // Shut down pending transfers according to DWG-2.3.1, "25.5.1 Exit Boot
76 // Services Event".
77 //
78 VNET_DEV *Dev;
79
80 DEBUG ((DEBUG_VERBOSE, "%a: Context=0x%p\n", __FUNCTION__, Context));
81 Dev = Context;
82 if (Dev->Snm.State == EfiSimpleNetworkInitialized) {
83 Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
84 }
85 }