From patchwork Thu Aug 24 15:03:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13364326 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EA54EC7EE2C for ; Thu, 24 Aug 2023 15:03:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 48C0810E57E; Thu, 24 Aug 2023 15:03:43 +0000 (UTC) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by gabe.freedesktop.org (Postfix) with ESMTP id C596810E57B for ; Thu, 24 Aug 2023 15:03:37 +0000 (UTC) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8Dxg_BFcedklpAbAA--.56614S3; Thu, 24 Aug 2023 23:03:33 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cx_c5EcedkEYBiAA--.42989S3; Thu, 24 Aug 2023 23:03:33 +0800 (CST) From: Sui Jingfeng To: Bjorn Helgaas Subject: [PATCH v5 1/2] PCI/VGA: Make the vga_is_firmware_default() less arch-dependent Date: Thu, 24 Aug 2023 23:03:31 +0800 Message-Id: <20230824150332.6434-2-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230824150332.6434-1-suijingfeng@loongson.cn> References: <20230824150332.6434-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Cx_c5EcedkEYBiAA--.42989S3 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/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C2KfnxnUUI43ZEXa7IU88HUDUUUUU== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: loongson-kernel@lists.loongnix.cn, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Currently, the vga_is_firmware_default() function only works on x86 and ia64, it is a no-op on the rest of the architectures. This patch completes the implementation for it, the added code tries to capture the PCI (e) VGA device that owns the firmware framebuffer, since only one GPU could own the firmware fb, things are almost done once we have determined the boot VGA device. As the PCI resource relocation do have a influence on the results of identification, we make it available on architectures where PCI resource relocation does happen at first. Because this patch is more important for those architectures(such as arm, arm64, loongarch, mips and risc-v etc). Signed-off-by: Sui Jingfeng --- drivers/pci/vgaarb.c | 76 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/drivers/pci/vgaarb.c b/drivers/pci/vgaarb.c index 5a696078b382..bc5fcc855513 100644 --- a/drivers/pci/vgaarb.c +++ b/drivers/pci/vgaarb.c @@ -60,7 +60,8 @@ static int vga_count, vga_decode_count; static bool vga_arbiter_used; static DEFINE_SPINLOCK(vga_lock); static DECLARE_WAIT_QUEUE_HEAD(vga_wait_queue); - +/* The PCI(e) device who owns the firmware framebuffer */ +static struct pci_dev *pdev_boot_vga; static const char *vga_iostate_to_str(unsigned int iostate) { @@ -571,6 +572,9 @@ static bool vga_is_firmware_default(struct pci_dev *pdev) return true; } +#else + if (pdev_boot_vga && pdev_boot_vga == pdev) + return true; #endif return false; } @@ -1555,3 +1559,73 @@ static int __init vga_arb_device_init(void) return rc; } subsys_initcall_sync(vga_arb_device_init); + +/* + * Get the physical address range that the firmware framebuffer occupies. + * + * Note that the global screen_info is arch-specific, thus CONFIG_SYSFB is + * chosen as compile-time conditional to suppress linkage problems on non-x86 + * architectures. + * + * Returns true on success, otherwise return false. + */ +static bool vga_arb_get_firmware_fb_range(u64 *start, u64 *end) +{ + u64 fb_start = 0; + u64 fb_size = 0; + u64 fb_end; + +#if defined(CONFIG_X86) || defined(CONFIG_IA64) || defined(CONFIG_SYSFB) + fb_start = screen_info.lfb_base; + if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE) + fb_start |= (u64)screen_info.ext_lfb_base << 32; + + fb_size = screen_info.lfb_size; +#endif + + /* No firmware framebuffer support */ + if (!fb_start || !fb_size) + return false; + + fb_end = fb_start + fb_size - 1; + + *start = fb_start; + *end = fb_end; + + return true; +} + +/* + * Identify the PCI VGA device that contains the firmware framebuffer + */ +static void pci_boot_vga_capturer(struct pci_dev *pdev) +{ + u64 fb_start, fb_end; + struct resource *res; + unsigned int i; + + if (pdev_boot_vga) + return; + + if (!vga_arb_get_firmware_fb_range(&fb_start, &fb_end)) + return; + + pci_dev_for_each_resource(pdev, res, i) { + if (resource_type(res) != IORESOURCE_MEM) + continue; + + if (!res->start || !res->end) + continue; + + if (res->start <= fb_start && fb_end <= res->end) { + pdev_boot_vga = pdev; + + vgaarb_info(&pdev->dev, + "BAR %u: %pR contains firmware FB [0x%llx-0x%llx]\n", + i, res, fb_start, fb_end); + break; + } + } +} +DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA, + 8, pci_boot_vga_capturer);