X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=OvmfPkg%2FVirtio10Dxe%2FVirtio10.c;h=ef9a00710668daf041b011224a1a9cbc1ba69e7c;hp=06f0699077535f8e8f7351d2827d2604697a5fbf;hb=53a4c6047f3ce2ece7bb8db5b9815a1c9227dddb;hpb=9399f68ae359234b142c293ad1bef75f470ced30 diff --git a/OvmfPkg/Virtio10Dxe/Virtio10.c b/OvmfPkg/Virtio10Dxe/Virtio10.c index 06f0699077..ef9a007106 100644 --- a/OvmfPkg/Virtio10Dxe/Virtio10.c +++ b/OvmfPkg/Virtio10Dxe/Virtio10.c @@ -2,6 +2,7 @@ A non-transitional driver for VirtIo 1.0 PCI devices. Copyright (C) 2016, Red Hat, Inc. + Copyright (C) 2017, AMD Inc, All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this @@ -15,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -487,7 +489,8 @@ EFI_STATUS EFIAPI Virtio10SetQueueAddress ( IN VIRTIO_DEVICE_PROTOCOL *This, - IN VRING *Ring + IN VRING *Ring, + IN UINT64 RingBaseShift ) { VIRTIO_1_0_DEV *Dev; @@ -495,6 +498,8 @@ Virtio10SetQueueAddress ( UINT64 Address; UINT16 Enable; + ASSERT (RingBaseShift == 0); + Dev = VIRTIO_1_0_FROM_VIRTIO_DEVICE (This); Address = (UINTN)Ring->Desc; @@ -772,6 +777,117 @@ Virtio10ReadDevice ( return Status; } +STATIC +EFI_STATUS +EFIAPI +Virtio10AllocateSharedPages ( + IN VIRTIO_DEVICE_PROTOCOL *This, + IN UINTN Pages, + IN OUT VOID **HostAddress + ) +{ + VIRTIO_1_0_DEV *Dev; + EFI_STATUS Status; + + Dev = VIRTIO_1_0_FROM_VIRTIO_DEVICE (This); + + Status = Dev->PciIo->AllocateBuffer ( + Dev->PciIo, + AllocateAnyPages, + EfiBootServicesData, + Pages, + HostAddress, + EFI_PCI_ATTRIBUTE_MEMORY_CACHED + ); + return Status; +} + +STATIC +VOID +EFIAPI +Virtio10FreeSharedPages ( + IN VIRTIO_DEVICE_PROTOCOL *This, + IN UINTN Pages, + IN VOID *HostAddress + ) +{ + VIRTIO_1_0_DEV *Dev; + + Dev = VIRTIO_1_0_FROM_VIRTIO_DEVICE (This); + + Dev->PciIo->FreeBuffer ( + Dev->PciIo, + Pages, + HostAddress + ); +} + +STATIC +EFI_STATUS +EFIAPI +Virtio10MapSharedBuffer ( + IN VIRTIO_DEVICE_PROTOCOL *This, + IN VIRTIO_MAP_OPERATION Operation, + IN VOID *HostAddress, + IN OUT UINTN *NumberOfBytes, + OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, + OUT VOID **Mapping + ) +{ + EFI_STATUS Status; + VIRTIO_1_0_DEV *Dev; + EFI_PCI_IO_PROTOCOL_OPERATION PciIoOperation; + + Dev = VIRTIO_1_0_FROM_VIRTIO_DEVICE (This); + + // + // Map VIRTIO_MAP_OPERATION to EFI_PCI_IO_PROTOCOL_OPERATION + // + switch (Operation) { + case VirtioOperationBusMasterRead: + PciIoOperation = EfiPciIoOperationBusMasterRead; + break; + case VirtioOperationBusMasterWrite: + PciIoOperation = EfiPciIoOperationBusMasterWrite; + break; + case VirtioOperationBusMasterCommonBuffer: + PciIoOperation = EfiPciIoOperationBusMasterCommonBuffer; + break; + default: + return EFI_INVALID_PARAMETER; + } + + Status = Dev->PciIo->Map ( + Dev->PciIo, + PciIoOperation, + HostAddress, + NumberOfBytes, + DeviceAddress, + Mapping + ); + return Status; +} + +STATIC +EFI_STATUS +EFIAPI +Virtio10UnmapSharedBuffer ( + IN VIRTIO_DEVICE_PROTOCOL *This, + IN VOID *Mapping + ) +{ + EFI_STATUS Status; + VIRTIO_1_0_DEV *Dev; + + Dev = VIRTIO_1_0_FROM_VIRTIO_DEVICE (This); + + Status = Dev->PciIo->Unmap ( + Dev->PciIo, + Mapping + ); + + return Status; +} STATIC CONST VIRTIO_DEVICE_PROTOCOL mVirtIoTemplate = { VIRTIO_SPEC_REVISION (1, 0, 0), @@ -788,7 +904,11 @@ STATIC CONST VIRTIO_DEVICE_PROTOCOL mVirtIoTemplate = { Virtio10GetDeviceStatus, Virtio10SetDeviceStatus, Virtio10WriteDevice, - Virtio10ReadDevice + Virtio10ReadDevice, + Virtio10AllocateSharedPages, + Virtio10FreeSharedPages, + Virtio10MapSharedBuffer, + Virtio10UnmapSharedBuffer }; @@ -822,6 +942,7 @@ Virtio10BindingSupported ( goto CloseProtocol; } + Status = EFI_UNSUPPORTED; // // Recognize non-transitional modern devices. Also, we'll have to parse the // PCI capability list, so make sure the CapabilityPtr field will be valid. @@ -832,9 +953,20 @@ Virtio10BindingSupported ( Pci.Hdr.RevisionID >= 0x01 && Pci.Device.SubsystemID >= 0x40 && (Pci.Hdr.Status & EFI_PCI_STATUS_CAPABILITY) != 0) { - Status = EFI_SUCCESS; - } else { - Status = EFI_UNSUPPORTED; + // + // The virtio-vga device is special. It can be driven both as a VGA device + // with a linear framebuffer, and through its underlying, modern, + // virtio-gpu-pci device, which has no linear framebuffer itself. For + // compatibility with guest OSes that insist on inheriting a linear + // framebuffer from the firmware, we should leave virtio-vga to + // QemuVideoDxe, and support only virtio-gpu-pci here. + // + // Both virtio-vga and virtio-gpu-pci have DeviceId 0x1050, but only the + // former has device class PCI_CLASS_DISPLAY_VGA. + // + if (Pci.Hdr.DeviceId != 0x1050 || !IS_PCI_VGA (&Pci)) { + Status = EFI_SUCCESS; + } } CloseProtocol: @@ -894,7 +1026,8 @@ Virtio10BindingStart ( goto ClosePciIo; } - SetAttributes = 0; + SetAttributes = (EFI_PCI_IO_ATTRIBUTE_BUS_MASTER | + EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE); UpdateAttributes (&Device->CommonConfig, &SetAttributes); UpdateAttributes (&Device->NotifyConfig, &SetAttributes); UpdateAttributes (&Device->SpecificConfig, &SetAttributes);