From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web10.2676.1646977418453074874 for ; Thu, 10 Mar 2022 21:43:38 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=M5gKhYTa; spf=pass (domain: redhat.com, ip: 170.10.129.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646977417; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7h24ecr66jXkH5odT0CnEL3cSnD4mMhE2GihMLaf+T8=; b=M5gKhYTa/dQvy6xZFONyaZAHaJWO2DNaqaYPHm0hch14Gup0u8S8X+nvNkWGWge4hkHXMI 073CticjH4CJldd3WbRfWbEhfZTwFwhCUauCo1QB3A+MM7OcqM4iOg2k2GyKaqMpbm/+lQ RpazdKoumLwzAkhJYFQlLWy5LvsepIg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-333-iCu5-ifzPNSPbwFUSEbhaA-1; Fri, 11 Mar 2022 00:43:36 -0500 X-MC-Unique: iCu5-ifzPNSPbwFUSEbhaA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 70D221006AA7 for ; Fri, 11 Mar 2022 05:43:35 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.196.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E7C0E57CA4; Fri, 11 Mar 2022 05:43:34 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id BEF211800796; Fri, 11 Mar 2022 06:43:15 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Pawel Polawski , Gerd Hoffmann Subject: [PATCH v2 6/6] OvmfPkg/VirtioGpuDxe: query native display resolution from host Date: Fri, 11 Mar 2022 06:43:15 +0100 Message-Id: <20220311054315.876774-7-kraxel@redhat.com> In-Reply-To: <20220311054315.876774-1-kraxel@redhat.com> References: <20220311054315.876774-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Try query native display resolution from the host. When successfull setup PcdVideoHorizontalResolution and PcdVideoVerticalResolution accordingly and add the video mode to the GOP mode list if needed. Signed-off-by: Gerd Hoffmann --- OvmfPkg/VirtioGpuDxe/VirtioGpu.inf | 6 ++ OvmfPkg/VirtioGpuDxe/VirtioGpu.h | 6 ++ OvmfPkg/VirtioGpuDxe/Gop.c | 92 ++++++++++++++++++++++++++++-- 3 files changed, 99 insertions(+), 5 deletions(-) diff --git a/OvmfPkg/VirtioGpuDxe/VirtioGpu.inf b/OvmfPkg/VirtioGpuDxe/VirtioGpu.inf index 9e66bcd4b97f..d88c87e129f0 100644 --- a/OvmfPkg/VirtioGpuDxe/VirtioGpu.inf +++ b/OvmfPkg/VirtioGpuDxe/VirtioGpu.inf @@ -25,6 +25,7 @@ [Sources] [Packages] MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec OvmfPkg/OvmfPkg.dec [LibraryClasses] @@ -43,3 +44,8 @@ [Protocols] gEfiGraphicsOutputProtocolGuid ## BY_START gEfiPciIoProtocolGuid ## TO_START gVirtioDeviceProtocolGuid ## TO_START + +[Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdVideoResolutionSource + gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution + gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution diff --git a/OvmfPkg/VirtioGpuDxe/VirtioGpu.h b/OvmfPkg/VirtioGpuDxe/VirtioGpu.h index 1d781088bb3f..45da56415297 100644 --- a/OvmfPkg/VirtioGpuDxe/VirtioGpu.h +++ b/OvmfPkg/VirtioGpuDxe/VirtioGpu.h @@ -151,6 +151,12 @@ struct VGPU_GOP_STRUCT { // BackingStore is non-NULL. // VOID *BackingStoreMap; + + // + // native display resolution + // + UINT32 NativeXRes; + UINT32 NativeYRes; }; // diff --git a/OvmfPkg/VirtioGpuDxe/Gop.c b/OvmfPkg/VirtioGpuDxe/Gop.c index 05daefcbfbc8..70a81c10c8b5 100644 --- a/OvmfPkg/VirtioGpuDxe/Gop.c +++ b/OvmfPkg/VirtioGpuDxe/Gop.c @@ -9,6 +9,7 @@ **/ #include +#include #include "VirtioGpu.h" @@ -192,6 +193,47 @@ STATIC CONST GOP_RESOLUTION mGopResolutions[] = { #define VGPU_GOP_FROM_GOP(GopPointer) \ CR (GopPointer, VGPU_GOP, Gop, VGPU_GOP_SIG) +STATIC +VOID +EFIAPI +GopNativeResolution ( + IN VGPU_GOP *VgpuGop, + OUT UINT32 *XRes, + OUT UINT32 *YRes + ) +{ + volatile VIRTIO_GPU_RESP_DISPLAY_INFO DisplayInfo; + EFI_STATUS Status; + UINTN Index; + + Status = VirtioGpuGetDisplayInfo (VgpuGop->ParentBus, &DisplayInfo); + if (Status != EFI_SUCCESS) { + return; + } + + for (Index = 0; Index < VIRTIO_GPU_MAX_SCANOUTS; Index++) { + if (!DisplayInfo.Pmodes[Index].Enabled || + !DisplayInfo.Pmodes[Index].Rectangle.Width || + !DisplayInfo.Pmodes[Index].Rectangle.Height) + { + continue; + } + + DEBUG (( + DEBUG_INFO, + "%a: #%d: %dx%d\n", + __FUNCTION__, + Index, + DisplayInfo.Pmodes[Index].Rectangle.Width, + DisplayInfo.Pmodes[Index].Rectangle.Height + )); + if ((*XRes == 0) || (*YRes == 0)) { + *XRes = DisplayInfo.Pmodes[Index].Rectangle.Width; + *YRes = DisplayInfo.Pmodes[Index].Rectangle.Height; + } + } +} + STATIC VOID EFIAPI @@ -199,7 +241,9 @@ GopInitialize ( IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This ) { - VGPU_GOP *VgpuGop; + VGPU_GOP *VgpuGop; + EFI_STATUS Status; + UINT32 XRes = 0, YRes = 0, Index; VgpuGop = VGPU_GOP_FROM_GOP (This); @@ -216,6 +260,37 @@ GopInitialize ( VgpuGop->GopMode.SizeOfInfo = sizeof VgpuGop->GopModeInfo; VgpuGop->GopModeInfo.PixelFormat = PixelBltOnly; + + // + // query host for display resolution + // + GopNativeResolution (VgpuGop, &XRes, &YRes); + if ((XRes == 0) || (YRes == 0)) { + return; + } + + if (PcdGet8 (PcdVideoResolutionSource) == 0) { + Status = PcdSet32S (PcdVideoHorizontalResolution, XRes); + ASSERT_RETURN_ERROR (Status); + Status = PcdSet32S (PcdVideoVerticalResolution, YRes); + ASSERT_RETURN_ERROR (Status); + Status = PcdSet8S (PcdVideoResolutionSource, 2); + ASSERT_RETURN_ERROR (Status); + } + + VgpuGop->NativeXRes = XRes; + VgpuGop->NativeYRes = YRes; + for (Index = 0; Index < ARRAY_SIZE (mGopResolutions); Index++) { + if ((mGopResolutions[Index].Width == XRes) && + (mGopResolutions[Index].Height == YRes)) + { + // native resolution already is in mode list + return; + } + } + + // add to mode list + VgpuGop->GopMode.MaxMode++; } // @@ -242,10 +317,17 @@ GopQueryMode ( return EFI_OUT_OF_RESOURCES; } - GopModeInfo->HorizontalResolution = mGopResolutions[ModeNumber].Width; - GopModeInfo->VerticalResolution = mGopResolutions[ModeNumber].Height; - GopModeInfo->PixelFormat = PixelBltOnly; - GopModeInfo->PixelsPerScanLine = mGopResolutions[ModeNumber].Width; + if (ModeNumber < ARRAY_SIZE (mGopResolutions)) { + GopModeInfo->HorizontalResolution = mGopResolutions[ModeNumber].Width; + GopModeInfo->VerticalResolution = mGopResolutions[ModeNumber].Height; + } else { + VGPU_GOP *VgpuGop = VGPU_GOP_FROM_GOP (This); + GopModeInfo->HorizontalResolution = VgpuGop->NativeXRes; + GopModeInfo->VerticalResolution = VgpuGop->NativeYRes; + } + + GopModeInfo->PixelFormat = PixelBltOnly; + GopModeInfo->PixelsPerScanLine = GopModeInfo->HorizontalResolution; *SizeOfInfo = sizeof *GopModeInfo; *Info = GopModeInfo; -- 2.35.1