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