OvmfPkg/VirtioLib: take VirtIo instance in VirtioRingInit/VirtioRingUninit
[mirror_edk2.git] / OvmfPkg / Library / VirtioMmioDeviceLib / VirtioMmioDevice.h
1 /** @file
2
3 Internal definitions for the VirtIo MMIO Device driver
4
5 Copyright (C) 2013, ARM Ltd
6 Copyright (C) 2017, AMD Inc. All rights reserved.<BR>
7
8 This program and the accompanying materials are licensed and made available
9 under the terms and conditions of the BSD License which accompanies this
10 distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
14 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18 #ifndef _VIRTIO_MMIO_DEVICE_INTERNAL_H_
19 #define _VIRTIO_MMIO_DEVICE_INTERNAL_H_
20
21 #include <Protocol/VirtioDevice.h>
22
23 #include <IndustryStandard/Virtio.h>
24
25 #include <Library/DebugLib.h>
26 #include <Library/IoLib.h>
27 #include <Library/UefiLib.h>
28 #include <Library/VirtioMmioDeviceLib.h>
29 #include <Library/MemoryAllocationLib.h>
30
31 #define VIRTIO_MMIO_DEVICE_SIGNATURE SIGNATURE_32 ('V', 'M', 'I', 'O')
32
33 typedef struct {
34 UINT32 Signature;
35 VIRTIO_DEVICE_PROTOCOL VirtioDevice;
36 PHYSICAL_ADDRESS BaseAddress;
37 } VIRTIO_MMIO_DEVICE;
38
39 #define VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE(Device) \
40 CR (Device, VIRTIO_MMIO_DEVICE, VirtioDevice, VIRTIO_MMIO_DEVICE_SIGNATURE)
41
42 #define VIRTIO_CFG_WRITE(Device, Offset, Val) \
43 (MmioWrite32 (Device->BaseAddress + (Offset), Val))
44 #define VIRTIO_CFG_READ(Device, Offset) \
45 (MmioRead32 (Device->BaseAddress + (Offset)))
46
47 EFI_STATUS
48 EFIAPI
49 VirtioMmioDeviceRead (
50 IN VIRTIO_DEVICE_PROTOCOL *This,
51 IN UINTN FieldOFfset,
52 IN UINTN FieldSize,
53 IN UINTN BufferSize,
54 OUT VOID* Buffer
55 );
56
57 EFI_STATUS
58 EFIAPI
59 VirtioMmioDeviceWrite (
60 IN VIRTIO_DEVICE_PROTOCOL *This,
61 IN UINTN FieldOffset,
62 IN UINTN FieldSize,
63 IN UINT64 Value
64 );
65
66 EFI_STATUS
67 EFIAPI
68 VirtioMmioGetDeviceFeatures (
69 IN VIRTIO_DEVICE_PROTOCOL *This,
70 OUT UINT64 *DeviceFeatures
71 );
72
73 EFI_STATUS
74 EFIAPI
75 VirtioMmioGetQueueSize (
76 IN VIRTIO_DEVICE_PROTOCOL *This,
77 OUT UINT16 *QueueNumMax
78 );
79
80 EFI_STATUS
81 EFIAPI
82 VirtioMmioGetDeviceStatus (
83 IN VIRTIO_DEVICE_PROTOCOL *This,
84 OUT UINT8 *DeviceStatus
85 );
86
87 EFI_STATUS
88 EFIAPI
89 VirtioMmioSetQueueSize (
90 IN VIRTIO_DEVICE_PROTOCOL *This,
91 IN UINT16 QueueSize
92 );
93
94 EFI_STATUS
95 EFIAPI
96 VirtioMmioSetDeviceStatus (
97 IN VIRTIO_DEVICE_PROTOCOL *This,
98 IN UINT8 DeviceStatus
99 );
100
101 EFI_STATUS
102 EFIAPI
103 VirtioMmioSetQueueNotify (
104 IN VIRTIO_DEVICE_PROTOCOL *This,
105 IN UINT16 QueueNotify
106 );
107
108 EFI_STATUS
109 EFIAPI
110 VirtioMmioSetQueueSel (
111 IN VIRTIO_DEVICE_PROTOCOL *This,
112 IN UINT16 Sel
113 );
114
115 EFI_STATUS
116 VirtioMmioSetQueueAddress (
117 IN VIRTIO_DEVICE_PROTOCOL *This,
118 IN VRING *Ring
119 );
120
121 EFI_STATUS
122 EFIAPI
123 VirtioMmioSetQueueAlignment (
124 IN VIRTIO_DEVICE_PROTOCOL *This,
125 IN UINT32 Alignment
126 );
127
128 EFI_STATUS
129 EFIAPI
130 VirtioMmioSetPageSize (
131 IN VIRTIO_DEVICE_PROTOCOL *This,
132 IN UINT32 PageSize
133 );
134
135 EFI_STATUS
136 EFIAPI
137 VirtioMmioSetGuestFeatures (
138 IN VIRTIO_DEVICE_PROTOCOL *This,
139 IN UINT64 Features
140 );
141
142 EFI_STATUS
143 EFIAPI
144 VirtioMmioAllocateSharedPages (
145 IN VIRTIO_DEVICE_PROTOCOL *This,
146 IN UINTN NumPages,
147 OUT VOID **HostAddress
148 );
149
150 VOID
151 EFIAPI
152 VirtioMmioFreeSharedPages (
153 IN VIRTIO_DEVICE_PROTOCOL *This,
154 IN UINTN NumPages,
155 IN VOID *HostAddress
156 );
157
158 EFI_STATUS
159 EFIAPI
160 VirtioMmioMapSharedBuffer (
161 IN VIRTIO_DEVICE_PROTOCOL *This,
162 IN VIRTIO_MAP_OPERATION Operation,
163 IN VOID *HostAddress,
164 IN OUT UINTN *NumberOfBytes,
165 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
166 OUT VOID **Mapping
167 );
168
169 EFI_STATUS
170 EFIAPI
171 VirtioMmioUnmapSharedBuffer (
172 IN VIRTIO_DEVICE_PROTOCOL *This,
173 IN VOID *Mapping
174 );
175
176 #endif // _VIRTIO_MMIO_DEVICE_INTERNAL_H_