TianoCore EDK2 master
Loading...
Searching...
No Matches
VirtioPciFunctions.c
Go to the documentation of this file.
1
14#include <Library/DebugLib.h>
17#include <Library/UefiLib.h>
18#include "VirtioPciDevice.h"
19
43EFIAPI
46 IN UINTN FieldOffset,
47 IN UINTN FieldSize,
48 IN UINTN BufferSize,
49 OUT VOID *Buffer
50 )
51{
53
54 Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
55
56 return VirtioPciIoRead (
57 Dev,
58 Dev->DeviceSpecificConfigurationOffset + FieldOffset,
59 FieldSize,
60 BufferSize,
61 Buffer
62 );
63}
64
83EFIAPI
86 IN UINTN FieldOffset,
87 IN UINTN FieldSize,
88 IN UINT64 Value
89 )
90{
92
93 Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
94
95 return VirtioPciIoWrite (
96 Dev,
97 Dev->DeviceSpecificConfigurationOffset + FieldOffset,
98 FieldSize,
99 Value
100 );
101}
102
104EFIAPI
105VirtioPciGetDeviceFeatures (
107 OUT UINT64 *DeviceFeatures
108 )
109{
111 EFI_STATUS Status;
112 UINT32 Features32;
113
114 if (DeviceFeatures == NULL) {
115 return EFI_INVALID_PARAMETER;
116 }
117
118 Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
119
120 Status = VirtioPciIoRead (
121 Dev,
122 VIRTIO_PCI_OFFSET_DEVICE_FEATURES,
123 sizeof (UINT32),
124 sizeof (UINT32),
125 &Features32
126 );
127 if (!EFI_ERROR (Status)) {
128 *DeviceFeatures = Features32;
129 }
130
131 return Status;
132}
133
135EFIAPI
136VirtioPciGetQueueSize (
138 OUT UINT16 *QueueNumMax
139 )
140{
142
143 if (QueueNumMax == NULL) {
144 return EFI_INVALID_PARAMETER;
145 }
146
147 Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
148
149 return VirtioPciIoRead (
150 Dev,
151 VIRTIO_PCI_OFFSET_QUEUE_SIZE,
152 sizeof (UINT16),
153 sizeof (UINT16),
154 QueueNumMax
155 );
156}
157
159EFIAPI
160VirtioPciGetDeviceStatus (
162 OUT UINT8 *DeviceStatus
163 )
164{
166
167 if (DeviceStatus == NULL) {
168 return EFI_INVALID_PARAMETER;
169 }
170
171 Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
172
173 return VirtioPciIoRead (
174 Dev,
175 VIRTIO_PCI_OFFSET_QUEUE_DEVICE_STATUS,
176 sizeof (UINT8),
177 sizeof (UINT8),
178 DeviceStatus
179 );
180}
181
183EFIAPI
184VirtioPciSetGuestFeatures (
186 IN UINT64 Features
187 )
188{
190
191 Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
192
193 if (Features > MAX_UINT32) {
194 return EFI_UNSUPPORTED;
195 }
196
197 return VirtioPciIoWrite (
198 Dev,
199 VIRTIO_PCI_OFFSET_GUEST_FEATURES,
200 sizeof (UINT32),
201 Features
202 );
203}
204
206EFIAPI
207VirtioPciSetQueueAddress (
209 IN VRING *Ring,
210 IN UINT64 RingBaseShift
211 )
212{
214
215 ASSERT (RingBaseShift == 0);
216
217 Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
218
219 return VirtioPciIoWrite (
220 Dev,
221 VIRTIO_PCI_OFFSET_QUEUE_ADDRESS,
222 sizeof (UINT32),
223 (UINT32)((UINTN)Ring->Base >> EFI_PAGE_SHIFT)
224 );
225}
226
228EFIAPI
229VirtioPciSetQueueSel (
231 IN UINT16 Sel
232 )
233{
235
236 Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
237
238 return VirtioPciIoWrite (
239 Dev,
240 VIRTIO_PCI_OFFSET_QUEUE_SELECT,
241 sizeof (UINT16),
242 Sel
243 );
244}
245
247EFIAPI
248VirtioPciSetQueueAlignment (
250 IN UINT32 Alignment
251 )
252{
253 return EFI_SUCCESS;
254}
255
257EFIAPI
258VirtioPciSetPageSize (
260 IN UINT32 PageSize
261 )
262{
263 return (PageSize == EFI_PAGE_SIZE) ? EFI_SUCCESS : EFI_UNSUPPORTED;
264}
265
267EFIAPI
268VirtioPciSetQueueNotify (
270 IN UINT16 Index
271 )
272{
274
275 Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
276
277 return VirtioPciIoWrite (
278 Dev,
279 VIRTIO_PCI_OFFSET_QUEUE_NOTIFY,
280 sizeof (UINT16),
281 Index
282 );
283}
284
286EFIAPI
287VirtioPciSetQueueSize (
289 IN UINT16 Size
290 )
291{
292 //
293 // This function is only applicable in Virtio-MMIO.
294 // (The QueueSize field is read-only in Virtio proper (PCI))
295 //
296 return EFI_SUCCESS;
297}
298
300EFIAPI
301VirtioPciSetDeviceStatus (
303 IN UINT8 DeviceStatus
304 )
305{
307
308 Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
309
310 return VirtioPciIoWrite (
311 Dev,
312 VIRTIO_PCI_OFFSET_QUEUE_DEVICE_STATUS,
313 sizeof (UINT8),
314 DeviceStatus
315 );
316}
317
319EFIAPI
320VirtioPciAllocateSharedPages (
322 IN UINTN NumPages,
323 OUT VOID **HostAddress
324 )
325{
326 VOID *Buffer;
327
328 Buffer = AllocatePages (NumPages);
329 if (Buffer == NULL) {
330 return EFI_OUT_OF_RESOURCES;
331 }
332
333 *HostAddress = Buffer;
334 return EFI_SUCCESS;
335}
336
337VOID
338EFIAPI
339VirtioPciFreeSharedPages (
341 IN UINTN NumPages,
342 IN VOID *HostAddress
343 )
344{
345 FreePages (HostAddress, NumPages);
346}
347
349EFIAPI
350VirtioPciMapSharedBuffer (
352 IN VIRTIO_MAP_OPERATION Operation,
353 IN VOID *HostAddress,
354 IN OUT UINTN *NumberOfBytes,
355 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
356 OUT VOID **Mapping
357 )
358{
359 *DeviceAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress;
360 *Mapping = NULL;
361
362 return EFI_SUCCESS;
363}
364
366EFIAPI
367VirtioPciUnmapSharedBuffer (
369 IN VOID *Mapping
370 )
371{
372 return EFI_SUCCESS;
373}
UINT64 UINTN
VOID EFIAPI FreePages(IN VOID *Buffer, IN UINTN Pages)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
VOID *EFIAPI AllocatePages(IN UINTN Pages)
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS EFIAPI VirtioPciIoRead(IN VIRTIO_PCI_DEVICE *Dev, IN UINTN FieldOffset, IN UINTN FieldSize, IN UINTN BufferSize, OUT VOID *Buffer)
EFI_STATUS EFIAPI VirtioPciIoWrite(IN VIRTIO_PCI_DEVICE *Dev, IN UINTN FieldOffset, IN UINTN FieldSize, IN UINT64 Value)
EFI_STATUS EFIAPI VirtioPciDeviceWrite(IN VIRTIO_DEVICE_PROTOCOL *This, IN UINTN FieldOffset, IN UINTN FieldSize, IN UINT64 Value)
EFI_STATUS EFIAPI VirtioPciDeviceRead(IN VIRTIO_DEVICE_PROTOCOL *This, IN UINTN FieldOffset, IN UINTN FieldSize, IN UINTN BufferSize, OUT VOID *Buffer)