20 VirtioMmioGetDeviceFeatures,
21 VirtioMmioSetGuestFeatures,
22 VirtioMmioSetQueueAddress,
23 VirtioMmioSetQueueSel,
24 VirtioMmioSetQueueNotify,
25 VirtioMmioSetQueueAlignment,
26 VirtioMmioSetPageSize,
27 VirtioMmioGetQueueSize,
28 VirtioMmioSetQueueSize,
29 VirtioMmioGetDeviceStatus,
30 VirtioMmioSetDeviceStatus,
31 VirtioMmioDeviceWrite,
33 VirtioMmioAllocateSharedPages,
34 VirtioMmioFreeSharedPages,
35 VirtioMmioMapSharedBuffer,
36 VirtioMmioUnmapSharedBuffer
56 IN PHYSICAL_ADDRESS BaseAddress,
66 &Device->VirtioDevice,
67 &mMmioDeviceProtocolTemplate,
70 Device->BaseAddress = BaseAddress;
71 Device->VirtioDevice.SubSystemDeviceId =
72 MmioRead32 (BaseAddress + VIRTIO_MMIO_OFFSET_DEVICE_ID);
77 MagicValue = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_MAGIC);
78 if (MagicValue != VIRTIO_MMIO_MAGIC) {
79 return EFI_UNSUPPORTED;
82 Device->Version = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_VERSION);
83 switch (Device->Version) {
84 case VIRTIO_MMIO_DEVICE_VERSION_0_95:
87 "%a virtio 0.9.5, id %d\n",
89 Device->VirtioDevice.SubSystemDeviceId
91 Device->VirtioDevice.Revision = VIRTIO_SPEC_REVISION (0, 9, 5);
93 case VIRTIO_MMIO_DEVICE_VERSION_1_00:
96 "%a virtio 1.0, id %d\n",
98 Device->VirtioDevice.SubSystemDeviceId
100 Device->VirtioDevice.Revision = VIRTIO_SPEC_REVISION (1, 0, 0);
103 return EFI_UNSUPPORTED;
132 IN PHYSICAL_ADDRESS BaseAddress,
140 return EFI_INVALID_PARAMETER;
143 if (Handle ==
NULL) {
144 return EFI_INVALID_PARAMETER;
151 if (VirtIo ==
NULL) {
152 return EFI_OUT_OF_RESOURCES;
155 VirtIo->Signature = VIRTIO_MMIO_DEVICE_SIGNATURE;
158 if (EFI_ERROR (Status)) {
165 Status =
gBS->InstallProtocolInterface (
167 &gVirtioDeviceProtocolGuid,
169 &VirtIo->VirtioDevice
171 if (EFI_ERROR (Status)) {
194 Status =
gBS->OpenProtocol (
196 &gVirtioDeviceProtocolGuid,
197 (VOID **)&VirtioDevice,
200 EFI_OPEN_PROTOCOL_GET_PROTOCOL
202 if (EFI_ERROR (Status)) {
209 MmioDevice = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (VirtioDevice);
214 Status =
gBS->UninstallProtocolInterface (
216 &gVirtioDeviceProtocolGuid,
217 &MmioDevice->VirtioDevice
219 if (EFI_ERROR (Status)) {
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
UINT32 EFIAPI MmioRead32(IN UINTN Address)
#define DEBUG(Expression)
EFI_STATUS VirtioMmioInstallDevice(IN PHYSICAL_ADDRESS BaseAddress, IN EFI_HANDLE Handle)
EFI_STATUS VirtioMmioUninstallDevice(IN EFI_HANDLE DeviceHandle)
STATIC VOID EFIAPI VirtioMmioUninit(IN VIRTIO_MMIO_DEVICE *Device)
STATIC EFI_STATUS EFIAPI VirtioMmioInit(IN PHYSICAL_ADDRESS BaseAddress, IN OUT VIRTIO_MMIO_DEVICE *Device)