50 Status = VgpuDev->VirtIo->SetDeviceStatus (VgpuDev->VirtIo, NextDevStat);
51 if (EFI_ERROR (Status)) {
58 NextDevStat |= VSTAT_ACK;
59 Status = VgpuDev->VirtIo->SetDeviceStatus (VgpuDev->VirtIo, NextDevStat);
60 if (EFI_ERROR (Status)) {
67 NextDevStat |= VSTAT_DRIVER;
68 Status = VgpuDev->VirtIo->SetDeviceStatus (VgpuDev->VirtIo, NextDevStat);
69 if (EFI_ERROR (Status)) {
76 Status = VgpuDev->VirtIo->GetDeviceFeatures (VgpuDev->VirtIo, &Features);
77 if (EFI_ERROR (Status)) {
81 if ((Features & VIRTIO_F_VERSION_1) == 0) {
82 Status = EFI_UNSUPPORTED;
89 Features &= VIRTIO_F_VERSION_1 | VIRTIO_F_IOMMU_PLATFORM;
98 if (EFI_ERROR (Status)) {
106 Status = VgpuDev->VirtIo->SetQueueSel (
108 VIRTIO_GPU_CONTROL_QUEUE
110 if (EFI_ERROR (Status)) {
114 Status = VgpuDev->VirtIo->GetQueueNumMax (VgpuDev->VirtIo, &QueueSize);
115 if (EFI_ERROR (Status)) {
124 Status = EFI_UNSUPPORTED;
131 Status =
VirtioRingInit (VgpuDev->VirtIo, QueueSize, &VgpuDev->Ring);
132 if (EFI_ERROR (Status)) {
145 if (EFI_ERROR (Status)) {
152 Status = VgpuDev->VirtIo->SetQueueAddress (
157 if (EFI_ERROR (Status)) {
164 NextDevStat |= VSTAT_DRIVER_OK;
165 Status = VgpuDev->VirtIo->SetDeviceStatus (VgpuDev->VirtIo, NextDevStat);
166 if (EFI_ERROR (Status)) {
173 VgpuDev->VirtIo->UnmapSharedBuffer (VgpuDev->VirtIo, VgpuDev->RingMap);
186 NextDevStat |= VSTAT_FAILED;
187 VgpuDev->VirtIo->SetDeviceStatus (VgpuDev->VirtIo, NextDevStat);
210 VgpuDev->VirtIo->SetDeviceStatus (VgpuDev->VirtIo, 0);
211 VgpuDev->VirtIo->UnmapSharedBuffer (VgpuDev->VirtIo, VgpuDev->RingMap);
247 OUT VOID **HostAddress,
253 VOID *NewHostAddress;
255 Status = VgpuDev->VirtIo->AllocateSharedPages (
260 if (EFI_ERROR (Status)) {
272 VirtioOperationBusMasterCommonBuffer,
278 if (EFI_ERROR (Status)) {
279 goto FreeSharedPages;
282 *HostAddress = NewHostAddress;
286 VgpuDev->VirtIo->FreeSharedPages (
320 IN VOID *HostAddress,
324 VgpuDev->VirtIo->UnmapSharedBuffer (
328 VgpuDev->VirtIo->FreeSharedPages (
357 DEBUG ((DEBUG_VERBOSE,
"%a: Context=0x%p\n", __func__, Context));
359 VgpuDev->VirtIo->SetDeviceStatus (VgpuDev->VirtIo, 0);
417 IN VIRTIO_GPU_CONTROL_TYPE RequestType,
421 IN VIRTIO_GPU_CONTROL_TYPE ResponseType,
428 UINT32 ResponseSizeRet;
437 Header->Type = RequestType;
439 Header->Flags = VIRTIO_GPU_FLAG_FENCE;
440 Header->FenceId = VgpuDev->FenceId++;
449 ASSERT (RequestSize >=
sizeof *Header);
450 ASSERT (RequestSize <= MAX_UINT32);
457 VirtioOperationBusMasterRead,
460 &RequestDeviceAddress,
463 if (EFI_ERROR (Status)) {
469 VirtioOperationBusMasterWrite,
472 &ResponseDeviceAddress,
475 if (EFI_ERROR (Status)) {
485 RequestDeviceAddress,
492 ResponseDeviceAddress,
493 (UINT32)ResponseSize,
503 VIRTIO_GPU_CONTROL_QUEUE,
508 if (EFI_ERROR (Status)) {
515 if (ResponseSize != ResponseSizeRet) {
518 "%a: malformed response to Request=0x%x\n",
522 Status = EFI_PROTOCOL_ERROR;
531 Status = VgpuDev->VirtIo->UnmapSharedBuffer (VgpuDev->VirtIo, ResponseMap);
532 if (EFI_ERROR (Status)) {
536 Status = VgpuDev->VirtIo->UnmapSharedBuffer (VgpuDev->VirtIo, RequestMap);
537 if (EFI_ERROR (Status)) {
544 if (Response->Type == (UINT32)ResponseType) {
550 "%a: Request=0x%x Response=0x%x (expected 0x%x)\n",
556 return EFI_DEVICE_ERROR;
559 VgpuDev->VirtIo->UnmapSharedBuffer (VgpuDev->VirtIo, ResponseMap);
562 VgpuDev->VirtIo->UnmapSharedBuffer (VgpuDev->VirtIo, RequestMap);
575 IN VIRTIO_GPU_CONTROL_TYPE RequestType,
589 VirtioGpuRespOkNodata,
624 IN UINT32 ResourceId,
625 IN VIRTIO_GPU_FORMATS Format,
632 if (ResourceId == 0) {
633 return EFI_INVALID_PARAMETER;
636 Request.ResourceId = ResourceId;
637 Request.Format = (UINT32)Format;
638 Request.Width = Width;
639 Request.Height = Height;
643 VirtioGpuCmdResourceCreate2d,
651VirtioGpuResourceUnref (
658 if (ResourceId == 0) {
659 return EFI_INVALID_PARAMETER;
662 Request.ResourceId = ResourceId;
667 VirtioGpuCmdResourceUnref,
675VirtioGpuResourceAttachBacking (
677 IN UINT32 ResourceId,
684 if (ResourceId == 0) {
685 return EFI_INVALID_PARAMETER;
688 Request.ResourceId = ResourceId;
689 Request.NrEntries = 1;
690 Request.Entry.Addr = BackingStoreDeviceAddress;
692 Request.Entry.Padding = 0;
696 VirtioGpuCmdResourceAttachBacking,
704VirtioGpuResourceDetachBacking (
711 if (ResourceId == 0) {
712 return EFI_INVALID_PARAMETER;
715 Request.ResourceId = ResourceId;
726 VirtioGpuCmdResourceDetachBacking,
750 Request.Rectangle.X = X;
751 Request.Rectangle.Y = Y;
752 Request.Rectangle.Width = Width;
753 Request.Rectangle.Height = Height;
754 Request.ScanoutId = ScanoutId;
755 Request.ResourceId = ResourceId;
759 VirtioGpuCmdSetScanout,
767VirtioGpuTransferToHost2d (
779 if (ResourceId == 0) {
780 return EFI_INVALID_PARAMETER;
783 Request.Rectangle.X = X;
784 Request.Rectangle.Y = Y;
785 Request.Rectangle.Width = Width;
786 Request.Rectangle.Height = Height;
787 Request.Offset = Offset;
788 Request.ResourceId = ResourceId;
793 VirtioGpuCmdTransferToHost2d,
801VirtioGpuResourceFlush (
812 if (ResourceId == 0) {
813 return EFI_INVALID_PARAMETER;
816 Request.Rectangle.X = X;
817 Request.Rectangle.Y = Y;
818 Request.Rectangle.Width = Width;
819 Request.Rectangle.Height = Height;
820 Request.ResourceId = ResourceId;
825 VirtioGpuCmdResourceFlush,
833VirtioGpuGetDisplayInfo (
842 VirtioGpuCmdGetDisplayInfo,
846 VirtioGpuRespOkDisplayInfo,
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
STATIC EFI_STATUS VirtioGpuSendCommand(IN OUT VGPU_DEV *VgpuDev, IN VIRTIO_GPU_CONTROL_TYPE RequestType, IN BOOLEAN Fence, IN OUT volatile VIRTIO_GPU_CONTROL_HEADER *Header, IN UINTN RequestSize)
VOID VirtioGpuUninit(IN OUT VGPU_DEV *VgpuDev)
VOID EFIAPI VirtioGpuExitBoot(IN EFI_EVENT Event, IN VOID *Context)
VOID VirtioGpuUnmapAndFreeBackingStore(IN VGPU_DEV *VgpuDev, IN UINTN NumberOfPages, IN VOID *HostAddress, IN VOID *Mapping)
STATIC EFI_STATUS VirtioGpuSendCommandWithReply(IN OUT VGPU_DEV *VgpuDev, IN VIRTIO_GPU_CONTROL_TYPE RequestType, IN BOOLEAN Fence, IN OUT volatile VIRTIO_GPU_CONTROL_HEADER *Header, IN UINTN RequestSize, IN VIRTIO_GPU_CONTROL_TYPE ResponseType, IN OUT volatile VIRTIO_GPU_CONTROL_HEADER *Response, IN UINTN ResponseSize)
EFI_STATUS VirtioGpuAllocateZeroAndMapBackingStore(IN VGPU_DEV *VgpuDev, IN UINTN NumberOfPages, OUT VOID **HostAddress, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
EFI_STATUS VirtioGpuResourceCreate2d(IN OUT VGPU_DEV *VgpuDev, IN UINT32 ResourceId, IN VIRTIO_GPU_FORMATS Format, IN UINT32 Width, IN UINT32 Height)
EFI_STATUS VirtioGpuInit(IN OUT VGPU_DEV *VgpuDev)
#define DEBUG(Expression)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_PAGES_TO_SIZE(Pages)
EFI_STATUS EFIAPI VirtioMapAllBytesInSharedBuffer(IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN VIRTIO_MAP_OPERATION Operation, IN VOID *HostAddress, IN UINTN NumberOfBytes, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
VOID EFIAPI VirtioAppendDesc(IN OUT VRING *Ring, IN UINT64 BufferDeviceAddress, IN UINT32 BufferSize, IN UINT16 Flags, IN OUT DESC_INDICES *Indices)
EFI_STATUS EFIAPI VirtioFlush(IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN UINT16 VirtQueueId, IN OUT VRING *Ring, IN DESC_INDICES *Indices, OUT UINT32 *UsedLen OPTIONAL)
EFI_STATUS EFIAPI VirtioRingMap(IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN VRING *Ring, OUT UINT64 *RingBaseShift, OUT VOID **Mapping)
EFI_STATUS EFIAPI Virtio10WriteFeatures(IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN UINT64 Features, IN OUT UINT8 *DeviceStatus)
VOID EFIAPI VirtioPrepare(IN OUT VRING *Ring, OUT DESC_INDICES *Indices)
EFI_STATUS EFIAPI VirtioRingInit(IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN UINT16 QueueSize, OUT VRING *Ring)
VOID EFIAPI VirtioRingUninit(IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN OUT VRING *Ring)