From nobody Fri Apr 10 23:23:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52C8AC00140 for ; Thu, 18 Aug 2022 14:25:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343529AbiHROZb (ORCPT ); Thu, 18 Aug 2022 10:25:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343514AbiHROZV (ORCPT ); Thu, 18 Aug 2022 10:25:21 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 905ABB2DB5 for ; Thu, 18 Aug 2022 07:25:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660832719; 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=jIDqzcZGlp+4QMAFK7ua+1esufE/cwW7LaxUX2qJezI=; b=HF2sHS2QB7trB1W9DP4fZoIPU49d3Mhj/F+O+O6lkr2k9lWJ1Eq6mC/+47scqFBaWR20Q2 kKBk0arMdJs79RrmR+fjv+v341agEQW7OngyeLDRs1ejlglIYGaDjC2XnPelyej02zRQoN +KTUIaO5uwVP1EWaHRAM41LFRgEl1og= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-448-Vd7tPDnuO9-Q7pC41Cs1Pg-1; Thu, 18 Aug 2022 10:25:18 -0400 X-MC-Unique: Vd7tPDnuO9-Q7pC41Cs1Pg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C7DD51C05132; Thu, 18 Aug 2022 14:25:17 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.194.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id D99D5C15BB8; Thu, 18 Aug 2022 14:25:15 +0000 (UTC) From: Vitaly Kuznetsov To: linux-hyperv@vger.kernel.org Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Wei Liu , Deepak Rawat , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Dexuan Cui , Michael Kelley Subject: [PATCH v1 3/4] Drivers: hv: Always reserve framebuffer region for Gen1 VMs Date: Thu, 18 Aug 2022 16:25:07 +0200 Message-Id: <20220818142508.402273-4-vkuznets@redhat.com> In-Reply-To: <20220818142508.402273-1-vkuznets@redhat.com> References: <20220818142508.402273-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" vmbus_reserve_fb() tries reserving framebuffer region iff screen_info.lfb_base is set. Gen2 VMs seem to have it set by EFI fb but on Gen1 VM it is observed to be zero. In fact, we do not need to rely on some other video driver setting it correctly as Gen1 VMs have a dedicated PCI device to look at. Both Hyper-V DRM and Hyper-V FB drivers get framebuffer base from this PCI device already so Vmbus driver can do the same trick. Check for legacy PCI video device presence and reserve the whole region for framebuffer. Signed-off-by: Vitaly Kuznetsov --- drivers/hv/vmbus_drv.c | 47 +++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 547ae334e5cd..6edaeefa2c3c 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include "hyperv_vmbus.h" =20 @@ -2258,26 +2259,44 @@ static int vmbus_acpi_remove(struct acpi_device *de= vice) =20 static void vmbus_reserve_fb(void) { - int size; + resource_size_t start =3D 0, size; + struct pci_dev *pdev; + + if (efi_enabled(EFI_BOOT)) { + /* Gen2 VM: get FB base from EFI framebuffer */ + start =3D screen_info.lfb_base; + size =3D max_t(__u32, screen_info.lfb_size, 0x800000); + } else { + /* Gen1 VM: get FB base from PCI */ + pdev =3D pci_get_device(PCI_VENDOR_ID_MICROSOFT, + PCI_DEVICE_ID_HYPERV_VIDEO, NULL); + if (!pdev) + return; + + if (!(pdev->resource[0].flags & IORESOURCE_MEM)) + return; + + start =3D pci_resource_start(pdev, 0); + size =3D pci_resource_len(pdev, 0); + + /* + * Release the PCI device so hyperv_drm or hyperv_fb driver can + * grab it later. + */ + pci_dev_put(pdev); + } + + if (!start) + return; + /* * Make a claim for the frame buffer in the resource tree under the * first node, which will be the one below 4GB. The length seems to * be underreported, particularly in a Generation 1 VM. So start out * reserving a larger area and make it smaller until it succeeds. */ - - if (screen_info.lfb_base) { - if (efi_enabled(EFI_BOOT)) - size =3D max_t(__u32, screen_info.lfb_size, 0x800000); - else - size =3D max_t(__u32, screen_info.lfb_size, 0x4000000); - - for (; !fb_mmio && (size >=3D 0x100000); size >>=3D 1) { - fb_mmio =3D __request_region(hyperv_mmio, - screen_info.lfb_base, size, - fb_mmio_name, 0); - } - } + for (; !fb_mmio && (size >=3D 0x100000); size >>=3D 1) + fb_mmio =3D __request_region(hyperv_mmio, start, size, fb_mmio_name, 0); } =20 /** --=20 2.37.1