]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c
OvmfPkg/VirtioNetDxe: dynamically alloc transmit header
[mirror_edk2.git] / OvmfPkg / VirtioNetDxe / SnpSharedHelpers.c
CommitLineData
12384f9b
LE
1/** @file\r
2\r
3 Helper functions used by at least two Simple Network Protocol methods.\r
4\r
5 Copyright (C) 2013, Red Hat, Inc.\r
6\r
7 This program and the accompanying materials are licensed and made available\r
8 under the terms and conditions of the BSD License which accompanies this\r
9 distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
13 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include <Library/MemoryAllocationLib.h>\r
18\r
19#include "VirtioNet.h"\r
20\r
21/**\r
22 Release RX and TX resources on the boundary of the\r
23 EfiSimpleNetworkInitialized state.\r
24\r
25 These functions contribute to rolling back a partial, failed initialization\r
26 of the virtio-net SNP driver instance, or to shutting down a fully\r
27 initialized, running instance.\r
28\r
29 They are only callable by the VirtioNetInitialize() and the\r
30 VirtioNetShutdown() SNP methods. See the state diagram in "VirtioNet.h".\r
31\r
32 @param[in,out] Dev The VNET_DEV driver instance being shut down, or whose\r
33 partial, failed initialization is being rolled back.\r
34*/\r
35\r
36VOID\r
37EFIAPI\r
38VirtioNetShutdownRx (\r
39 IN OUT VNET_DEV *Dev\r
40 )\r
41{\r
46b11f00
BS
42 Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RxBufMap);\r
43 Dev->VirtIo->FreeSharedPages (\r
44 Dev->VirtIo,\r
45 Dev->RxBufNrPages,\r
46 Dev->RxBuf\r
47 );\r
12384f9b
LE
48}\r
49\r
50\r
51VOID\r
52EFIAPI\r
53VirtioNetShutdownTx (\r
54 IN OUT VNET_DEV *Dev\r
55 )\r
56{\r
891f016c
BS
57 Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->TxSharedReqMap);\r
58 Dev->VirtIo->FreeSharedPages (\r
59 Dev->VirtIo,\r
60 EFI_SIZE_TO_PAGES (sizeof *(Dev->TxSharedReq)),\r
61 Dev->TxSharedReq\r
62 );\r
63\r
12384f9b
LE
64 FreePool (Dev->TxFreeStack);\r
65}\r
55dd5a67
BS
66\r
67/**\r
68 Release TX and RX VRING resources.\r
69\r
940baec0
BS
70 @param[in,out] Dev The VNET_DEV driver instance which was using\r
71 the ring.\r
72 @param[in,out] Ring The virtio ring to clean up.\r
73 @param[in] RingMap A token return from the VirtioRingMap()\r
55dd5a67
BS
74*/\r
75VOID\r
76EFIAPI\r
77VirtioNetUninitRing (\r
78 IN OUT VNET_DEV *Dev,\r
940baec0
BS
79 IN OUT VRING *Ring,\r
80 IN VOID *RingMap\r
55dd5a67
BS
81 )\r
82{\r
940baec0 83 Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, RingMap);\r
55dd5a67
BS
84 VirtioRingUninit (Dev->VirtIo, Ring);\r
85}\r