public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: edk2-devel-01 <edk2-devel@lists.01.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Brijesh Singh <brijesh.singh@amd.com>,
	Jordan Justen <jordan.l.justen@intel.com>,
	Tom Lendacky <thomas.lendacky@amd.com>
Subject: [PATCH 3/6] OvmfPkg/VirtioGpuDxe: take EFI_PHYSICAL_ADDRESS in ResourceAttachBacking()
Date: Mon, 28 Aug 2017 15:24:33 +0200	[thread overview]
Message-ID: <20170828132436.15933-4-lersek@redhat.com> (raw)
In-Reply-To: <20170828132436.15933-1-lersek@redhat.com>

The RESOURCE_ATTACH_BACKING virtio GPU command assigns guest-side backing
pages to a host-side resource that was created earlier with the
RESOURCE_CREATE_2D command.

We compose the RESOURCE_ATTACH_BACKING command in the
VirtioGpuResourceAttachBacking() function. Currently this function takes
the parameter

  IN VOID *FirstBackingPage

This is only appropriate as long as we pass a (guest-phys) system memory
address to the device. In preparation for a mapped bus master device
address, change the above parameter to

  IN EFI_PHYSICAL_ADDRESS BackingStoreDeviceAddress

In order to keep the current call site functional, move the (VOID*) to
(UINTN) conversion out of the function, to the call site.

The "Request.Entry.Addr" field already has type UINT64.

This patch is similar to commit 4b725858de68 ("OvmfPkg/VirtioLib: change
the parameter of VirtioAppendDesc() to UINT64", 2017-08-23).

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 OvmfPkg/VirtioGpuDxe/VirtioGpu.h |  8 ++++----
 OvmfPkg/VirtioGpuDxe/Commands.c  | 10 +++++-----
 OvmfPkg/VirtioGpuDxe/Gop.c       |  8 ++++----
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/OvmfPkg/VirtioGpuDxe/VirtioGpu.h b/OvmfPkg/VirtioGpuDxe/VirtioGpu.h
index 193e932e1430..cf2a63accd72 100644
--- a/OvmfPkg/VirtioGpuDxe/VirtioGpu.h
+++ b/OvmfPkg/VirtioGpuDxe/VirtioGpu.h
@@ -252,10 +252,10 @@ VirtioGpuResourceUnref (
 
 EFI_STATUS
 VirtioGpuResourceAttachBacking (
-  IN OUT VGPU_DEV *VgpuDev,
-  IN     UINT32   ResourceId,
-  IN     VOID     *FirstBackingPage,
-  IN     UINTN    NumberOfPages
+  IN OUT VGPU_DEV             *VgpuDev,
+  IN     UINT32               ResourceId,
+  IN     EFI_PHYSICAL_ADDRESS BackingStoreDeviceAddress,
+  IN     UINTN                NumberOfPages
   );
 
 EFI_STATUS
diff --git a/OvmfPkg/VirtioGpuDxe/Commands.c b/OvmfPkg/VirtioGpuDxe/Commands.c
index bdedea1df6a7..c1951a807e98 100644
--- a/OvmfPkg/VirtioGpuDxe/Commands.c
+++ b/OvmfPkg/VirtioGpuDxe/Commands.c
@@ -496,29 +496,29 @@ VirtioGpuResourceUnref (
 
 EFI_STATUS
 VirtioGpuResourceAttachBacking (
-  IN OUT VGPU_DEV *VgpuDev,
-  IN     UINT32   ResourceId,
-  IN     VOID     *FirstBackingPage,
-  IN     UINTN    NumberOfPages
+  IN OUT VGPU_DEV             *VgpuDev,
+  IN     UINT32               ResourceId,
+  IN     EFI_PHYSICAL_ADDRESS BackingStoreDeviceAddress,
+  IN     UINTN                NumberOfPages
   )
 {
   volatile VIRTIO_GPU_RESOURCE_ATTACH_BACKING Request;
 
   if (ResourceId == 0) {
     return EFI_INVALID_PARAMETER;
   }
 
   Request.ResourceId    = ResourceId;
   Request.NrEntries     = 1;
-  Request.Entry.Addr    = (UINTN)FirstBackingPage;
+  Request.Entry.Addr    = BackingStoreDeviceAddress;
   Request.Entry.Length  = (UINT32)EFI_PAGES_TO_SIZE (NumberOfPages);
   Request.Entry.Padding = 0;
 
   return VirtioGpuSendCommand (
            VgpuDev,
            VirtioGpuCmdResourceAttachBacking,
            FALSE,                             // Fence
            &Request.Header,
            sizeof Request
            );
 }
diff --git a/OvmfPkg/VirtioGpuDxe/Gop.c b/OvmfPkg/VirtioGpuDxe/Gop.c
index 3438bd03224e..b3c5dae74d0e 100644
--- a/OvmfPkg/VirtioGpuDxe/Gop.c
+++ b/OvmfPkg/VirtioGpuDxe/Gop.c
@@ -229,176 +229,176 @@ EFIAPI
 GopSetMode (
   IN  EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
   IN  UINT32                       ModeNumber
   )
 {
   VGPU_GOP   *VgpuGop;
   UINT32     NewResourceId;
   UINTN      NewNumberOfBytes;
   UINTN      NewNumberOfPages;
   VOID       *NewBackingStore;
   EFI_STATUS Status;
   EFI_STATUS Status2;
 
   if (ModeNumber >= ARRAY_SIZE (mGopResolutions)) {
     return EFI_UNSUPPORTED;
   }
 
   VgpuGop = VGPU_GOP_FROM_GOP (This);
 
   //
   // Distinguish the first (internal) call from the other (protocol consumer)
   // calls.
   //
   if (VgpuGop->ResourceId == 0) {
     //
     // Set up the Gop -> GopMode -> GopModeInfo pointer chain, and the other
     // (nonzero) constant fields.
     //
     // No direct framebuffer access is supported, only Blt() is.
     //
     VgpuGop->Gop.Mode = &VgpuGop->GopMode;
 
     VgpuGop->GopMode.MaxMode         = (UINT32)(ARRAY_SIZE (mGopResolutions));
     VgpuGop->GopMode.Info            = &VgpuGop->GopModeInfo;
     VgpuGop->GopMode.SizeOfInfo      = sizeof VgpuGop->GopModeInfo;
 
     VgpuGop->GopModeInfo.PixelFormat = PixelBltOnly;
 
     //
     // This is the first time we create a host side resource.
     //
     NewResourceId = 1;
   } else {
     //
     // We already have an active host side resource. Create the new one without
     // interfering with the current one, so that we can cleanly bail out on
     // error, without disturbing the current graphics mode.
     //
     // The formula below will alternate between IDs 1 and 2.
     //
     NewResourceId = 3 - VgpuGop->ResourceId;
   }
 
   //
   // Create the 2D host resource.
   //
   Status = VirtioGpuResourceCreate2d (
              VgpuGop->ParentBus,                // VgpuDev
              NewResourceId,                     // ResourceId
              VirtioGpuFormatB8G8R8X8Unorm,      // Format
              mGopResolutions[ModeNumber].Width, // Width
              mGopResolutions[ModeNumber].Height // Height
              );
   if (EFI_ERROR (Status)) {
     return Status;
   }
 
   //
   // Allocate guest backing store.
   //
   NewNumberOfBytes = mGopResolutions[ModeNumber].Width *
                      mGopResolutions[ModeNumber].Height * sizeof (UINT32);
   NewNumberOfPages = EFI_SIZE_TO_PAGES (NewNumberOfBytes);
   NewBackingStore = AllocatePages (NewNumberOfPages);
   if (NewBackingStore == NULL) {
     Status = EFI_OUT_OF_RESOURCES;
     goto DestroyHostResource;
   }
   //
   // Fill visible part of backing store with black.
   //
   ZeroMem (NewBackingStore, NewNumberOfBytes);
 
   //
   // Attach backing store to the host resource.
   //
   Status = VirtioGpuResourceAttachBacking (
-             VgpuGop->ParentBus, // VgpuDev
-             NewResourceId,      // ResourceId
-             NewBackingStore,    // FirstBackingPage
-             NewNumberOfPages    // NumberOfPages
+             VgpuGop->ParentBus,           // VgpuDev
+             NewResourceId,                // ResourceId
+             (UINTN)NewBackingStore,       // BackingStoreDeviceAddress
+             NewNumberOfPages              // NumberOfPages
              );
   if (EFI_ERROR (Status)) {
     goto FreeBackingStore;
   }
 
   //
   // Point head (scanout) #0 to the host resource.
   //
   Status = VirtioGpuSetScanout (
              VgpuGop->ParentBus,                 // VgpuDev
              0,                                  // X
              0,                                  // Y
              mGopResolutions[ModeNumber].Width,  // Width
              mGopResolutions[ModeNumber].Height, // Height
              0,                                  // ScanoutId
              NewResourceId                       // ResourceId
              );
   if (EFI_ERROR (Status)) {
     goto DetachBackingStore;
   }
 
   //
   // If this is not the first (i.e., internal) call, then we have to (a) flush
   // the new resource to head (scanout) #0, after having flipped the latter to
   // the former above, plus (b) release the old resources.
   //
   if (VgpuGop->ResourceId != 0) {
     Status = VirtioGpuResourceFlush (
                VgpuGop->ParentBus,                 // VgpuDev
                0,                                  // X
                0,                                  // Y
                mGopResolutions[ModeNumber].Width,  // Width
                mGopResolutions[ModeNumber].Height, // Height
                NewResourceId                       // ResourceId
                );
     if (EFI_ERROR (Status)) {
       //
       // Flip head (scanout) #0 back to the current resource. If this fails, we
       // cannot continue, as this error occurs on the error path and is
       // therefore non-recoverable.
       //
       Status2 = VirtioGpuSetScanout (
                   VgpuGop->ParentBus,                       // VgpuDev
                   0,                                        // X
                   0,                                        // Y
                   mGopResolutions[This->Mode->Mode].Width,  // Width
                   mGopResolutions[This->Mode->Mode].Height, // Height
                   0,                                        // ScanoutId
                   VgpuGop->ResourceId                       // ResourceId
                   );
       ASSERT_EFI_ERROR (Status2);
       if (EFI_ERROR (Status2)) {
         CpuDeadLoop ();
       }
       goto DetachBackingStore;
     }
 
     //
     // Flush successful; release the old resources (without disabling head
     // (scanout) #0).
     //
     ReleaseGopResources (VgpuGop, FALSE /* DisableHead */);
   }
 
   //
   // This is either the first (internal) call when we have no old resources
   // yet, or we've changed the mode successfully and released the old
   // resources.
   //
   ASSERT (VgpuGop->ResourceId == 0);
   ASSERT (VgpuGop->BackingStore == NULL);
 
   VgpuGop->ResourceId = NewResourceId;
   VgpuGop->BackingStore = NewBackingStore;
   VgpuGop->NumberOfPages = NewNumberOfPages;
 
   //
   // Populate Mode and ModeInfo (mutable fields only).
   //
   VgpuGop->GopMode.Mode = ModeNumber;
   VgpuGop->GopModeInfo.HorizontalResolution =
                                              mGopResolutions[ModeNumber].Width;
   VgpuGop->GopModeInfo.VerticalResolution = mGopResolutions[ModeNumber].Height;
   VgpuGop->GopModeInfo.PixelsPerScanLine = mGopResolutions[ModeNumber].Width;
   return EFI_SUCCESS;
-- 
2.14.1.3.gb7cf6e02401b




  parent reply	other threads:[~2017-08-28 13:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-28 13:24 [PATCH 0/6] OvmfPkg/VirtioGpuDxe: map system memory addresses to device addresses Laszlo Ersek
2017-08-28 13:24 ` [PATCH 1/6] OvmfPkg/VirtioGpuDxe: map VRING for bus master common buffer operation Laszlo Ersek
2017-08-28 13:24 ` [PATCH 2/6] OvmfPkg/VirtioGpuDxe: map virtio GPU command objects to device addresses Laszlo Ersek
2017-08-28 13:24 ` Laszlo Ersek [this message]
2017-08-28 13:24 ` [PATCH 4/6] OvmfPkg/VirtioGpuDxe: helpers for backing store (de)allocation+(un)mapping Laszlo Ersek
2017-08-28 13:24 ` [PATCH 5/6] OvmfPkg/VirtioGpuDxe: map backing store to bus master device address Laszlo Ersek
2017-08-28 13:24 ` [PATCH 6/6] OvmfPkg/VirtioGpuDxe: negotiate VIRTIO_F_IOMMU_PLATFORM Laszlo Ersek
2017-08-29 23:02 ` [PATCH 0/6] OvmfPkg/VirtioGpuDxe: map system memory addresses to device addresses Laszlo Ersek
2017-08-30 15:47   ` Brijesh Singh
2017-08-30 16:15     ` Laszlo Ersek
2017-09-01 12:31     ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170828132436.15933-4-lersek@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox