From patchwork Thu Jan 6 00:06:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 12704886 X-Patchwork-Delegate: bhelgaas@google.com 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 B6580C433FE for ; Thu, 6 Jan 2022 00:07:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245753AbiAFAHQ (ORCPT ); Wed, 5 Jan 2022 19:07:16 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:41578 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245751AbiAFAHP (ORCPT ); Wed, 5 Jan 2022 19:07:15 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 83A3061987; Thu, 6 Jan 2022 00:07:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEEA7C36AE9; Thu, 6 Jan 2022 00:07:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641427634; bh=K0y7QggNHlzbzB8D6oSqovym2Z+AebEc1LqQytG+NKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DPJltldSQV1luY4tZPLwFyFKmDwk/dGZma6fTZ8EaszahfFDvJv2v2Z666/XNLHSi TIWCrQvwTx6IZ6lRT7E9EfviNxVp2+9KYAIyGEIctlE37Vvqkoxf1QBx84pMP+8Idt MWgN1I571Xmv0d9K6Lox4/BGriQk7Vw0/uO/uBTQu0K1hwI+i1I2gJRMZdEZlh8fqq P5pkvSAXxiynATy/mb7UePFT54T5lB4UA1zNsrCAuFS9CtmwgP9es+yCUL5e58sqHN Hs/KaYJUSXEOxTgN1+pXplNnVTHC10xztiPq+83qR8Bk9CKsYgLVqmzuKNrixIJ7vP WhTtmJe67ZKdA== From: Bjorn Helgaas To: David Airlie , Daniel Vetter Cc: Xuefeng Li , Huacai Chen , Huacai Chen , linux-pci@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Bjorn Helgaas Subject: [PATCH v8 01/10] vgaarb: Move vga_arb_integrated_gpu() earlier in file Date: Wed, 5 Jan 2022 18:06:49 -0600 Message-Id: <20220106000658.243509-2-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220106000658.243509-1-helgaas@kernel.org> References: <20220106000658.243509-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Huacai Chen Move vga_arb_integrated_gpu() earlier in file to prepare for future patch. No functional change intended. [bhelgaas: pull #ifdefs inside function] Link: https://lore.kernel.org/r/20211015061512.2941859-3-chenhuacai@loongson.cn Signed-off-by: Huacai Chen Signed-off-by: Bjorn Helgaas --- drivers/gpu/vga/vgaarb.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c index 569930552957..ef5ad4c432f5 100644 --- a/drivers/gpu/vga/vgaarb.c +++ b/drivers/gpu/vga/vgaarb.c @@ -565,6 +565,17 @@ void vga_put(struct pci_dev *pdev, unsigned int rsrc) } EXPORT_SYMBOL(vga_put); +static bool vga_arb_integrated_gpu(struct device *dev) +{ +#if defined(CONFIG_ACPI) + struct acpi_device *adev = ACPI_COMPANION(dev); + + return adev && !strcmp(acpi_device_hid(adev), ACPI_VIDEO_HID); +#else + return false; +#endif +} + /* * Rules for using a bridge to control a VGA descendant decoding: if a bridge * has only one VGA descendant then it can be used to control the VGA routing @@ -1430,20 +1441,6 @@ static struct miscdevice vga_arb_device = { MISC_DYNAMIC_MINOR, "vga_arbiter", &vga_arb_device_fops }; -#if defined(CONFIG_ACPI) -static bool vga_arb_integrated_gpu(struct device *dev) -{ - struct acpi_device *adev = ACPI_COMPANION(dev); - - return adev && !strcmp(acpi_device_hid(adev), ACPI_VIDEO_HID); -} -#else -static bool vga_arb_integrated_gpu(struct device *dev) -{ - return false; -} -#endif - static void __init vga_arb_select_default_device(void) { struct pci_dev *pdev, *found = NULL; From patchwork Thu Jan 6 00:06:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 12704887 X-Patchwork-Delegate: bhelgaas@google.com 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 8A9D2C433EF for ; Thu, 6 Jan 2022 00:07:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343492AbiAFAHT (ORCPT ); Wed, 5 Jan 2022 19:07:19 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:41610 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245760AbiAFAHR (ORCPT ); Wed, 5 Jan 2022 19:07:17 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8C2A1619AC; Thu, 6 Jan 2022 00:07:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CE0AC36AE9; Thu, 6 Jan 2022 00:07:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641427636; bh=C6KG2kcCxpsFyVSNmALMR/2GCwyeWTKSnI/4BGoxUoE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f457AHD9FVJHYzosV38scmZKeO3EPaPaj/f8uNRwf3lXL3ox3vEH6dh8XN7RZhNSc 9cfFdOyJXgEJaUkAvKspqSHC7gPtd7DJs3Ak4egJ9H3ybTJeIusxXwY/nY31JzKiGF +g6Eihpecee3KsXv5sn5ilR4rWjY2DAQQPOg2xUeARwXDkYMrwhxZ1Bmz/ATUrsdYZ fxmrjrKKrZBgsOb++gyLpjQJR2grraeKofaijrDn4DfE67Wfq9E+m7qfZ5sg4KnSXi MTJlNJLG2UkUb0IRPnoW9ILp0NMrTRWwZQOsCkyskM7Zex3ImNfV0FslqGx/rDNIw/ 9EVgv1m7w7hNw== From: Bjorn Helgaas To: David Airlie , Daniel Vetter Cc: Xuefeng Li , Huacai Chen , Huacai Chen , linux-pci@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Bjorn Helgaas , =?utf-8?q?Bruno_Pr=C3=A9mont?= Subject: [PATCH v8 02/10] vgaarb: Factor out vga_select_framebuffer_device() Date: Wed, 5 Jan 2022 18:06:50 -0600 Message-Id: <20220106000658.243509-3-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220106000658.243509-1-helgaas@kernel.org> References: <20220106000658.243509-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas On x86 and ia64, if a VGA device BARs include a framebuffer reported by platform firmware, we select the device as the default VGA device. Factor this code to a separate function. No functional change intended. Signed-off-by: Bjorn Helgaas Cc: Bruno Prémont --- drivers/gpu/vga/vgaarb.c | 99 +++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 46 deletions(-) diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c index ef5ad4c432f5..36d9140c64f6 100644 --- a/drivers/gpu/vga/vgaarb.c +++ b/drivers/gpu/vga/vgaarb.c @@ -565,6 +565,58 @@ void vga_put(struct pci_dev *pdev, unsigned int rsrc) } EXPORT_SYMBOL(vga_put); +static void __init vga_select_framebuffer_device(struct pci_dev *pdev) +{ +#if defined(CONFIG_X86) || defined(CONFIG_IA64) + struct device *dev = &pdev->dev; + u64 base = screen_info.lfb_base; + u64 size = screen_info.lfb_size; + u64 limit; + resource_size_t start, end; + unsigned long flags; + int i; + + /* Select the device owning the boot framebuffer if there is one */ + + if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE) + base |= (u64)screen_info.ext_lfb_base << 32; + + limit = base + size; + + /* + * Override vga_arbiter_add_pci_device()'s I/O based detection + * as it may take the wrong device (e.g. on Apple system under + * EFI). + * + * Select the device owning the boot framebuffer if there is + * one. + */ + + /* Does firmware framebuffer belong to us? */ + for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { + flags = pci_resource_flags(pdev, i); + + if ((flags & IORESOURCE_MEM) == 0) + continue; + + start = pci_resource_start(pdev, i); + end = pci_resource_end(pdev, i); + + if (!start || !end) + continue; + + if (base < start || limit >= end) + continue; + + if (!vga_default_device()) + vgaarb_info(dev, "setting as boot device\n"); + else if (pdev != vga_default_device()) + vgaarb_info(dev, "overriding boot device\n"); + vga_set_default_device(pdev); + } +#endif +} + static bool vga_arb_integrated_gpu(struct device *dev) { #if defined(CONFIG_ACPI) @@ -1446,54 +1498,9 @@ static void __init vga_arb_select_default_device(void) struct pci_dev *pdev, *found = NULL; struct vga_device *vgadev; -#if defined(CONFIG_X86) || defined(CONFIG_IA64) - u64 base = screen_info.lfb_base; - u64 size = screen_info.lfb_size; - u64 limit; - resource_size_t start, end; - unsigned long flags; - int i; - - if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE) - base |= (u64)screen_info.ext_lfb_base << 32; - - limit = base + size; - list_for_each_entry(vgadev, &vga_list, list) { - struct device *dev = &vgadev->pdev->dev; - /* - * Override vga_arbiter_add_pci_device()'s I/O based detection - * as it may take the wrong device (e.g. on Apple system under - * EFI). - * - * Select the device owning the boot framebuffer if there is - * one. - */ - - /* Does firmware framebuffer belong to us? */ - for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { - flags = pci_resource_flags(vgadev->pdev, i); - - if ((flags & IORESOURCE_MEM) == 0) - continue; - - start = pci_resource_start(vgadev->pdev, i); - end = pci_resource_end(vgadev->pdev, i); - - if (!start || !end) - continue; - - if (base < start || limit >= end) - continue; - - if (!vga_default_device()) - vgaarb_info(dev, "setting as boot device\n"); - else if (vgadev->pdev != vga_default_device()) - vgaarb_info(dev, "overriding boot device\n"); - vga_set_default_device(vgadev->pdev); - } + vga_select_framebuffer_device(vgadev->pdev); } -#endif if (!vga_default_device()) { list_for_each_entry_reverse(vgadev, &vga_list, list) { From patchwork Thu Jan 6 00:06:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 12704892 X-Patchwork-Delegate: bhelgaas@google.com 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 6624BC4332F for ; Thu, 6 Jan 2022 00:07:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343502AbiAFAHe (ORCPT ); Wed, 5 Jan 2022 19:07:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343507AbiAFAHU (ORCPT ); Wed, 5 Jan 2022 19:07:20 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 308ABC061201; Wed, 5 Jan 2022 16:07:20 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id ED14AB81D63; Thu, 6 Jan 2022 00:07:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A712C36AEB; Thu, 6 Jan 2022 00:07:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641427637; bh=aAX5O9erMFRMC7V8Z9IDXdvpUyWpIonKB/j9UgUHLrs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qTCyLrbP20GIQ9387MqiZJ/V8QM+SM2acNJj21BDtDdgyqe40HO16u3x5zvqzDGHO WTqK3Fid28PhjDtSYT7FM5KmhWNQ0ugi0UkU2gCJbZZ661wjPQGn5SrvMjJF1Xm1DA GZ6f2H+pqdqD3Q0Hbj0XMZ1ak7z7UrjVBBYlZGOLHLC2TO7Keju01mZ6QfpWZkYB1S geylwFYcX6s6U/A1nU51NWsCLuHe5f+CQr+wd0oqjFyqaizRJGlb0t3mqSxuf+yYJ8 FIrKfJx6TPoJwwXcObJKDv4tI6OMUJihAtbEtUShCOHS65A1j3gqsdT0DDuEzDNIjp BRYaPZixMkIYg== From: Bjorn Helgaas To: David Airlie , Daniel Vetter Cc: Xuefeng Li , Huacai Chen , Huacai Chen , linux-pci@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Bjorn Helgaas , Huacai Chen Subject: [PATCH v8 03/10] vgaarb: Factor out default VGA device selection Date: Wed, 5 Jan 2022 18:06:51 -0600 Message-Id: <20220106000658.243509-4-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220106000658.243509-1-helgaas@kernel.org> References: <20220106000658.243509-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas Default VGA device selection fails when PCI devices are enumerated after the vga_arb_device_init() subsys_initcall. vga_arbiter_add_pci_device() selects the first fully enabled device to which legacy VGA resources are routed as the default VGA device. This is an ADD_DEVICE notifier, so it runs after every PCI device is enumerated. vga_arb_select_default_device() may select framebuffer devices, partially enabled GPUs, or non-legacy devices that don't have legacy VGA resources routed to them as the default VGA device. But this only happens once, from the vga_arb_device_init() subsys_initcall, so it doesn't consider devices enumerated after that: acpi_init acpi_scan_init acpi_pci_root_init # PCI device enumeration (ACPI systems) vga_arb_device_init for_each_pci_device vga_arbiter_add_pci_device # ADD_DEVICE notifier if (VGA-owner) vga_set_default_device <-- set default VGA vga_arb_select_default_device # only called ONCE for_each_vga_device if (framebuffer) vga_set_default_device <-- set default VGA to framebuffer if (!vga_default_device()) if (non-legacy, integrated GPU, etc) vga_set_default_device <-- set default VGA if (!vga_default_device()) vga_set_default_device <-- set default VGA pcibios_init pcibios_scanbus # PCI device enumeration (non-ACPI systems) ... vga_arbiter_add_pci_device # ADD_DEVICE notification if (VGA-owner) vga_set_default_device <-- set default VGA Note that on non-ACPI systems, vga_arb_select_default_device() runs before pcibios_init(), so it sees no VGA devices and can never set a framebuffer device, a non-legacy integrated GPU, etc., as the default device. Factor out the default VGA device selection to vga_is_boot_device(), called from vga_arbiter_add_pci_device(). Then we can migrate the default device selection from vga_arb_select_default_device() to the vga_arbiter_add_pci_device() path. Link: https://lore.kernel.org/r/20211015061512.2941859-4-chenhuacai@loongson.cn Based-on-patch-by: Huacai Chen Signed-off-by: Bjorn Helgaas --- drivers/gpu/vga/vgaarb.c | 45 ++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c index 36d9140c64f6..b0ae0f177c6f 100644 --- a/drivers/gpu/vga/vgaarb.c +++ b/drivers/gpu/vga/vgaarb.c @@ -628,6 +628,41 @@ static bool vga_arb_integrated_gpu(struct device *dev) #endif } +/* + * Return true if vgadev is a better default VGA device than the best one + * we've seen so far. + */ +static bool vga_is_boot_device(struct vga_device *vgadev) +{ + struct vga_device *boot_vga = vgadev_find(vga_default_device()); + + /* + * We select the default VGA device in this order: + * Firmware framebuffer (see vga_arb_select_default_device()) + * Legacy VGA device (owns VGA_RSRC_LEGACY_MASK) + * Non-legacy integrated device (see vga_arb_select_default_device()) + * Non-legacy discrete device (see vga_arb_select_default_device()) + * Other device (see vga_arb_select_default_device()) + */ + + /* + * A legacy VGA device has MEM and IO enabled and any bridges + * leading to it have PCI_BRIDGE_CTL_VGA enabled so the legacy + * resources ([mem 0xa0000-0xbffff], [io 0x3b0-0x3bb], etc) are + * routed to it. + * + * We use the first one we find, so if we've already found one, + * vgadev is no better. + */ + if (boot_vga) + return false; + + if ((vgadev->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK) + return true; + + return false; +} + /* * Rules for using a bridge to control a VGA descendant decoding: if a bridge * has only one VGA descendant then it can be used to control the VGA routing @@ -755,12 +790,10 @@ static bool vga_arbiter_add_pci_device(struct pci_dev *pdev) bus = bus->parent; } - /* Deal with VGA default device. Use first enabled one - * by default if arch doesn't have it's own hook - */ - if (vga_default == NULL && - ((vgadev->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK)) { - vgaarb_info(&pdev->dev, "setting as boot VGA device\n"); + if (vga_is_boot_device(vgadev)) { + vgaarb_info(&pdev->dev, "setting as boot VGA device%s\n", + vga_default_device() ? + " (overriding previous)" : ""); vga_set_default_device(pdev); } From patchwork Thu Jan 6 00:06:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 12704890 X-Patchwork-Delegate: bhelgaas@google.com 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 CAF7AC4332F for ; Thu, 6 Jan 2022 00:07:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343532AbiAFAHY (ORCPT ); Wed, 5 Jan 2022 19:07:24 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:41672 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343504AbiAFAHU (ORCPT ); Wed, 5 Jan 2022 19:07:20 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 25468619B5; Thu, 6 Jan 2022 00:07:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41F8FC36AE9; Thu, 6 Jan 2022 00:07:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641427639; bh=ahBRjiBAtZjsrnVkGxGvahvqf+RlJsegpSQPBitCsSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R8JbJjFKqNqaQ00xJIjSgzYZplM1A4rAjqJ8f1oWsaMZ+yfuIHuV8LFXHgsexXhm3 mqhwRgxJa0k4nM8ppDLmWf5kMdthsC+8LAxn6iB58NXbs0/35OMqI0oxwOolz2ZC3T kSfA9lwDetJJ9jSgi7WEWJTtV/mdWP6MBfe2zA4p77xcQ5J/QgpR3TBlA35BlGbTd7 t8BUSOyc8D9XscY1jr8CKF5dCrposvKRgGnWzJ/PnYW2ZsTAu4pi0ELQgePKuL00RJ 3sP1g9aPwdYn/ZDsoUFWKWBNLtnaYQ9TT3nosYOqslBTiZOB64PgQHWZ6lZ5Fn8cCO lupW1b7MxOwKg== From: Bjorn Helgaas To: David Airlie , Daniel Vetter Cc: Xuefeng Li , Huacai Chen , Huacai Chen , linux-pci@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Bjorn Helgaas , =?utf-8?q?Bruno_Pr=C3=A9mont?= Subject: [PATCH v8 04/10] vgaarb: Move framebuffer detection to ADD_DEVICE path Date: Wed, 5 Jan 2022 18:06:52 -0600 Message-Id: <20220106000658.243509-5-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220106000658.243509-1-helgaas@kernel.org> References: <20220106000658.243509-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas Previously we selected a device that owns the boot framebuffer as the default device in vga_arb_select_default_device(). This was only done in the vga_arb_device_init() subsys_initcall, so devices enumerated later, e.g., by pcibios_init(), were not eligible. Fix this by moving the framebuffer device selection from vga_arb_select_default_device() to vga_arbiter_add_pci_device(), which is called after every PCI device is enumerated, either by the vga_arb_device_init() subsys_initcall or as an ADD_DEVICE notifier. Note that if vga_arb_select_default_device() found a device owning the boot framebuffer, it unconditionally set it to be the default VGA device, and no subsequent device could replace it. Link: https://lore.kernel.org/r/20211015061512.2941859-7-chenhuacai@loongson.cn Based-on-patch-by: Huacai Chen Signed-off-by: Bjorn Helgaas Cc: Bruno Prémont --- drivers/gpu/vga/vgaarb.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c index b0ae0f177c6f..aefa4f406f7d 100644 --- a/drivers/gpu/vga/vgaarb.c +++ b/drivers/gpu/vga/vgaarb.c @@ -72,6 +72,7 @@ struct vga_device { unsigned int io_norm_cnt; /* normal IO count */ unsigned int mem_norm_cnt; /* normal MEM count */ bool bridge_has_one_vga; + bool is_framebuffer; /* BAR covers firmware framebuffer */ unsigned int (*set_decode)(struct pci_dev *pdev, bool decode); }; @@ -565,10 +566,9 @@ void vga_put(struct pci_dev *pdev, unsigned int rsrc) } EXPORT_SYMBOL(vga_put); -static void __init vga_select_framebuffer_device(struct pci_dev *pdev) +static bool vga_is_framebuffer_device(struct pci_dev *pdev) { #if defined(CONFIG_X86) || defined(CONFIG_IA64) - struct device *dev = &pdev->dev; u64 base = screen_info.lfb_base; u64 size = screen_info.lfb_size; u64 limit; @@ -583,15 +583,6 @@ static void __init vga_select_framebuffer_device(struct pci_dev *pdev) limit = base + size; - /* - * Override vga_arbiter_add_pci_device()'s I/O based detection - * as it may take the wrong device (e.g. on Apple system under - * EFI). - * - * Select the device owning the boot framebuffer if there is - * one. - */ - /* Does firmware framebuffer belong to us? */ for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { flags = pci_resource_flags(pdev, i); @@ -608,13 +599,10 @@ static void __init vga_select_framebuffer_device(struct pci_dev *pdev) if (base < start || limit >= end) continue; - if (!vga_default_device()) - vgaarb_info(dev, "setting as boot device\n"); - else if (pdev != vga_default_device()) - vgaarb_info(dev, "overriding boot device\n"); - vga_set_default_device(pdev); + return true; } #endif + return false; } static bool vga_arb_integrated_gpu(struct device *dev) @@ -635,6 +623,7 @@ static bool vga_arb_integrated_gpu(struct device *dev) static bool vga_is_boot_device(struct vga_device *vgadev) { struct vga_device *boot_vga = vgadev_find(vga_default_device()); + struct pci_dev *pdev = vgadev->pdev; /* * We select the default VGA device in this order: @@ -645,6 +634,18 @@ static bool vga_is_boot_device(struct vga_device *vgadev) * Other device (see vga_arb_select_default_device()) */ + /* + * We always prefer a firmware framebuffer, so if we've already + * found one, there's no need to consider vgadev. + */ + if (boot_vga && boot_vga->is_framebuffer) + return false; + + if (vga_is_framebuffer_device(pdev)) { + vgadev->is_framebuffer = true; + return true; + } + /* * A legacy VGA device has MEM and IO enabled and any bridges * leading to it have PCI_BRIDGE_CTL_VGA enabled so the legacy @@ -1531,10 +1532,6 @@ static void __init vga_arb_select_default_device(void) struct pci_dev *pdev, *found = NULL; struct vga_device *vgadev; - list_for_each_entry(vgadev, &vga_list, list) { - vga_select_framebuffer_device(vgadev->pdev); - } - if (!vga_default_device()) { list_for_each_entry_reverse(vgadev, &vga_list, list) { struct device *dev = &vgadev->pdev->dev; From patchwork Thu Jan 6 00:06:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 12704891 X-Patchwork-Delegate: bhelgaas@google.com 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 E8AC5C43217 for ; Thu, 6 Jan 2022 00:07:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343548AbiAFAH3 (ORCPT ); Wed, 5 Jan 2022 19:07:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343519AbiAFAHW (ORCPT ); Wed, 5 Jan 2022 19:07:22 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40AB1C06118A; Wed, 5 Jan 2022 16:07:22 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C67136199B; Thu, 6 Jan 2022 00:07:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9B32C36AED; Thu, 6 Jan 2022 00:07:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641427641; bh=FzOZFXfRW7iKLHtKUv+FE2m7xC0KfPGeO0MaK0M98W4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o0qhmJ3j/G2mtIHKxxqDDBK1w8cAKjIiIDTOyQxWV9nWlovR9m7yu+gurMc+WaHLx Gr00tvZAi7o51MYsw0ADN20Em4bZxOutyOV0QG+B+mKt3DLmn1yAnTQpD8DF0NChbU KGY+fDB8UbgkxgAasbJj05PMqIDilNVE29GmnyRz1AlXgI6YxbcYifjba7dimxKo8j IpuEM2z4nEHSQvFts9jJt0jpbPPZyFsFejCnCoYXG8BTm/nZtoo7jnTgM4GB4/HvDf HODbQ8iOYMBq8St2dhxt/PR8TSLdP5TSFyozomgJrQ22prL7gFYb71IAHmqnX/JTmS e1WFrCEPqvLOQ== From: Bjorn Helgaas To: David Airlie , Daniel Vetter Cc: Xuefeng Li , Huacai Chen , Huacai Chen , linux-pci@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Bjorn Helgaas , Huacai Chen , Daniel Axtens , Zhou Wang Subject: [PATCH v8 05/10] vgaarb: Move non-legacy VGA detection to ADD_DEVICE path Date: Wed, 5 Jan 2022 18:06:53 -0600 Message-Id: <20220106000658.243509-6-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220106000658.243509-1-helgaas@kernel.org> References: <20220106000658.243509-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas a37c0f48950b ("vgaarb: Select a default VGA device even if there's no legacy VGA") extended the vga_arb_device_init() subsys_initcall so it could select a non-legacy VGA device as the default. That failed to consider that PCI devices may be enumerated after vga_arb_device_init(), e.g., hot-added devices or non-ACPI systems that do PCI enumeration in pcibios_init(). Devices found then could never be selected as the default. One system where this is a problem is the MIPS-based Loongson where an ASpeed AST2500 VGA device is behind a bridge that doesn't implement the VGA Enable bit, so legacy resources are not routed to the VGA device. [1] Fix this by moving the non-legacy VGA device selection from vga_arb_select_default_device() to vga_arbiter_add_pci_device(), which is called after every PCI device is enumerated, either by the vga_arb_device_init() subsys_initcall or as an ADD_DEVICE notifier. [1] https://lore.kernel.org/r/20210514080025.1828197-6-chenhuacai@loongson.cn Link: https://lore.kernel.org/r/20211015061512.2941859-5-chenhuacai@loongson.cn Link: https://lore.kernel.org/r/20211015061512.2941859-7-chenhuacai@loongson.cn Based-on-patch-by: Huacai Chen Signed-off-by: Bjorn Helgaas Cc: Daniel Axtens Cc: Zhou Wang --- drivers/gpu/vga/vgaarb.c | 54 ++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c index aefa4f406f7d..123b81628061 100644 --- a/drivers/gpu/vga/vgaarb.c +++ b/drivers/gpu/vga/vgaarb.c @@ -624,6 +624,7 @@ static bool vga_is_boot_device(struct vga_device *vgadev) { struct vga_device *boot_vga = vgadev_find(vga_default_device()); struct pci_dev *pdev = vgadev->pdev; + u16 cmd, boot_cmd; /* * We select the default VGA device in this order: @@ -661,6 +662,37 @@ static bool vga_is_boot_device(struct vga_device *vgadev) if ((vgadev->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK) return true; + /* + * If we haven't found a legacy VGA device, accept a non-legacy + * device. It may have either IO or MEM enabled, and bridges may + * not have PCI_BRIDGE_CTL_VGA enabled, so it may not be able to + * use legacy VGA resources. Prefer an integrated GPU over others. + */ + pci_read_config_word(pdev, PCI_COMMAND, &cmd); + if (cmd & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) { + + /* + * An integrated GPU overrides a previous non-legacy + * device. We expect only a single integrated GPU, but if + * there are more, we use the *last* because that was the + * previous behavior. + */ + if (vga_arb_integrated_gpu(&pdev->dev)) + return true; + + /* + * We prefer the first non-legacy discrete device we find. + * If we already found one, vgadev is no better. + */ + if (boot_vga) { + pci_read_config_word(boot_vga->pdev, PCI_COMMAND, + &boot_cmd); + if (boot_cmd & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) + return false; + } + return true; + } + return false; } @@ -1529,30 +1561,8 @@ static struct miscdevice vga_arb_device = { static void __init vga_arb_select_default_device(void) { - struct pci_dev *pdev, *found = NULL; struct vga_device *vgadev; - if (!vga_default_device()) { - list_for_each_entry_reverse(vgadev, &vga_list, list) { - struct device *dev = &vgadev->pdev->dev; - u16 cmd; - - pdev = vgadev->pdev; - pci_read_config_word(pdev, PCI_COMMAND, &cmd); - if (cmd & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) { - found = pdev; - if (vga_arb_integrated_gpu(dev)) - break; - } - } - } - - if (found) { - vgaarb_info(&found->dev, "setting as boot device (VGA legacy resources not available)\n"); - vga_set_default_device(found); - return; - } - if (!vga_default_device()) { vgadev = list_first_entry_or_null(&vga_list, struct vga_device, list); From patchwork Thu Jan 6 00:06:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 12704888 X-Patchwork-Delegate: bhelgaas@google.com 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 14AE6C433F5 for ; Thu, 6 Jan 2022 00:07:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343503AbiAFAH0 (ORCPT ); Wed, 5 Jan 2022 19:07:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245760AbiAFAHY (ORCPT ); Wed, 5 Jan 2022 19:07:24 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25181C061212; Wed, 5 Jan 2022 16:07:24 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B7D436199B; Thu, 6 Jan 2022 00:07:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8AA8C36AEB; Thu, 6 Jan 2022 00:07:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641427643; bh=QvBYfgQFxgIJLEsygEejf0q/8P2zDm4EbtVDmjAMLW4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LlUfS4cfTK2DaHGYqFx6o8so6vN+0fRCV5y4uLSZ8ipPoWXwIHfT6g2Uq/Aa7JI3N ckeVQHF3Kp/alUYxddkIvdl3CctNqrOS3RN0Z6AnelJGaDOnG1Tgg4LaHUzjL3FTfK 3uED0M4WulPkCegDsEvFSN/whg8m/dj2srcZSXXCBsLBLWOBoUw+Uicd/ukQa71EJQ cCQZVtZ8KTXGS2rLFxETKWGB+gxq/Kkh7ASJclhl/a1xBrFhjIxej11+b9eTKD+0R+ u35LpEaNXaKyGezkwnw1SQAeymPHeoIIxNdC55Tdr8S4IDonSupOp+Xx6kIbZygQ0z yZK17rcvPi4+w== From: Bjorn Helgaas To: David Airlie , Daniel Vetter Cc: Xuefeng Li , Huacai Chen , Huacai Chen , linux-pci@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Bjorn Helgaas , Huacai Chen , Daniel Axtens , Zhou Wang Subject: [PATCH v8 06/10] vgaarb: Move disabled VGA device detection to ADD_DEVICE path Date: Wed, 5 Jan 2022 18:06:54 -0600 Message-Id: <20220106000658.243509-7-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220106000658.243509-1-helgaas@kernel.org> References: <20220106000658.243509-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas a37c0f48950b ("vgaarb: Select a default VGA device even if there's no legacy VGA") extended the vga_arb_device_init() subsys_initcall so that if there are no other eligible devices, it could select a disabled VGA device as the default. Move this detection from vga_arb_select_default_device() to vga_arbiter_add_pci_device() so every device, even those hot-added or enumerated after vga_arb_device_init() is eligible for selection as the default VGA device. Link: https://lore.kernel.org/r/20211015061512.2941859-5-chenhuacai@loongson.cn Based-on-patch-by: Huacai Chen Signed-off-by: Bjorn Helgaas Cc: Daniel Axtens Cc: Zhou Wang --- drivers/gpu/vga/vgaarb.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c index 123b81628061..ad548917e602 100644 --- a/drivers/gpu/vga/vgaarb.c +++ b/drivers/gpu/vga/vgaarb.c @@ -656,7 +656,8 @@ static bool vga_is_boot_device(struct vga_device *vgadev) * We use the first one we find, so if we've already found one, * vgadev is no better. */ - if (boot_vga) + if (boot_vga && + (boot_vga->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK) return false; if ((vgadev->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK) @@ -693,6 +694,13 @@ static bool vga_is_boot_device(struct vga_device *vgadev) return true; } + /* + * vgadev has neither IO nor MEM enabled. If we haven't found any + * other VGA devices, it is the best candidate so far. + */ + if (!boot_vga) + return true; + return false; } @@ -1559,21 +1567,6 @@ static struct miscdevice vga_arb_device = { MISC_DYNAMIC_MINOR, "vga_arbiter", &vga_arb_device_fops }; -static void __init vga_arb_select_default_device(void) -{ - struct vga_device *vgadev; - - if (!vga_default_device()) { - vgadev = list_first_entry_or_null(&vga_list, - struct vga_device, list); - if (vgadev) { - struct device *dev = &vgadev->pdev->dev; - vgaarb_info(dev, "setting as boot device (VGA legacy resources not available)\n"); - vga_set_default_device(vgadev->pdev); - } - } -} - static int __init vga_arb_device_init(void) { int rc; @@ -1603,8 +1596,6 @@ static int __init vga_arb_device_init(void) vgaarb_info(dev, "no bridge control possible\n"); } - vga_arb_select_default_device(); - pr_info("loaded\n"); return rc; } From patchwork Thu Jan 6 00:06:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 12704889 X-Patchwork-Delegate: bhelgaas@google.com 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 6629AC43217 for ; Thu, 6 Jan 2022 00:07:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343543AbiAFAH2 (ORCPT ); Wed, 5 Jan 2022 19:07:28 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:41796 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343511AbiAFAHZ (ORCPT ); Wed, 5 Jan 2022 19:07:25 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8884E619AC; Thu, 6 Jan 2022 00:07:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8B53C36AE9; Thu, 6 Jan 2022 00:07:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641427645; bh=55uUY3DU+Al2f4mzQBUIMkBQgWRIn5Cls1b0nr4Zsds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cpr/yrL99ZdYakbjuuIPqsR7VcfQEPTQh03YhFahW91+yhZvch6yhAcXwyNS4tJw9 oek6bTZG8KniYzf8v7ojV3Uf5lOnDAYxpbW5YA/poUJHRIK9hTFDUomzdgYyWC6xsg OjSrLXfpwx8e2qJQc8p8QgkVLuHv6+kU+3gngKsbBTqu0lA7ukvBoTbFvayflfEe97 AiBSSURXAcoesWGbHdvYoGu0/rVP2cHt6E7m7TaR4XHj/FlQUsojRjE2dS6YP94/WA cKtjj92wliHJCDmi6DSTEDo2lP+dZDDUqaGLLWQic0VUvt1LHwTPf5CC/uW3HXLFuU xzij/ieJE0/6A== From: Bjorn Helgaas To: David Airlie , Daniel Vetter Cc: Xuefeng Li , Huacai Chen , Huacai Chen , linux-pci@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Bjorn Helgaas Subject: [PATCH v8 07/10] vgaarb: Remove empty vga_arb_device_card_gone() Date: Wed, 5 Jan 2022 18:06:55 -0600 Message-Id: <20220106000658.243509-8-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220106000658.243509-1-helgaas@kernel.org> References: <20220106000658.243509-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas vga_arb_device_card_gone() has always been empty. Remove it. Signed-off-by: Bjorn Helgaas --- drivers/gpu/vga/vgaarb.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c index ad548917e602..455cf048fae8 100644 --- a/drivers/gpu/vga/vgaarb.c +++ b/drivers/gpu/vga/vgaarb.c @@ -123,8 +123,6 @@ static int vga_str_to_iostate(char *buf, int str_size, int *io_state) /* this is only used a cookie - it should not be dereferenced */ static struct pci_dev *vga_default; -static void vga_arb_device_card_gone(struct pci_dev *pdev); - /* Find somebody in our list */ static struct vga_device *vgadev_find(struct pci_dev *pdev) { @@ -878,10 +876,6 @@ static bool vga_arbiter_del_pci_device(struct pci_dev *pdev) /* Remove entry from list */ list_del(&vgadev->list); vga_count--; - /* Notify userland driver that the device is gone so it discards - * it's copies of the pci_dev pointer - */ - vga_arb_device_card_gone(pdev); /* Wake up all possible waiters */ wake_up_all(&vga_wait_queue); @@ -1131,9 +1125,7 @@ static ssize_t vga_arb_read(struct file *file, char __user *buf, if (lbuf == NULL) return -ENOMEM; - /* Shields against vga_arb_device_card_gone (pci_dev going - * away), and allows access to vga list - */ + /* Protects vga_list */ spin_lock_irqsave(&vga_lock, flags); /* If we are targeting the default, use it */ @@ -1150,8 +1142,6 @@ static ssize_t vga_arb_read(struct file *file, char __user *buf, /* Wow, it's not in the list, that shouldn't happen, * let's fix us up and return invalid card */ - if (pdev == priv->target) - vga_arb_device_card_gone(pdev); spin_unlock_irqrestore(&vga_lock, flags); len = sprintf(lbuf, "invalid"); goto done; @@ -1495,10 +1485,6 @@ static int vga_arb_release(struct inode *inode, struct file *file) return 0; } -static void vga_arb_device_card_gone(struct pci_dev *pdev) -{ -} - /* * callback any registered clients to let them know we have a * change in VGA cards From patchwork Thu Jan 6 00:06:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 12704893 X-Patchwork-Delegate: bhelgaas@google.com 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 B32BBC433EF for ; Thu, 6 Jan 2022 00:07:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343549AbiAFAHi (ORCPT ); Wed, 5 Jan 2022 19:07:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343530AbiAFAH3 (ORCPT ); Wed, 5 Jan 2022 19:07:29 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 516ACC061212; Wed, 5 Jan 2022 16:07:29 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0285CB81158; Thu, 6 Jan 2022 00:07:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EAF8C36AE9; Thu, 6 Jan 2022 00:07:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641427646; bh=S7SdNo1VNpzaamjfYJNlC8obavkWhiss2wA+rwzSTJE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FwA7kPtNWW6ggve83Ha+lSthggzduAq7XxntpXOko/s5wSZJr8CDdt6/taui9lum7 o15P90zbodX93EDa7o+Hnaoj+nCeRO9LqNbNK0nOdkLKQKZZWuITF6jZ+50mza80tf IWHlGRnfPZCloT2wcRc5i3dIBRfQF7T4jIF/Ol7egm9o812vkScv1E5MCP54WXni9i b787dZ+6HTop4qy6LZGc9avWuWmwGCvQa6cExRaWNZQUMTByqDDk5CUfLCGltstC6t HBDzshv1Bot9bS/TUDhxg3qf0v0w83fKiFFmJSm+ljOMqgnR44J6ra1XueAlS7Gv+W Wg5ot5rLJ9m9g== From: Bjorn Helgaas To: David Airlie , Daniel Vetter Cc: Xuefeng Li , Huacai Chen , Huacai Chen , linux-pci@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Bjorn Helgaas Subject: [PATCH v8 08/10] vgaarb: Log bridge control messages when adding devices Date: Wed, 5 Jan 2022 18:06:56 -0600 Message-Id: <20220106000658.243509-9-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220106000658.243509-1-helgaas@kernel.org> References: <20220106000658.243509-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Huacai Chen Previously vga_arb_device_init() iterated through all VGA devices and indicated whether legacy VGA routing to each could be controlled by an upstream bridge. But we determine that information in vga_arbiter_add_pci_device(), which we call for every device, so we can log it there without iterating through the VGA devices again. Note that we call vga_arbiter_check_bridge_sharing() before adding the device to vga_list, so we have to handle the very first device separately. Signed-off-by: Huacai Chen Signed-off-by: Bjorn Helgaas --- drivers/gpu/vga/vgaarb.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c index 455cf048fae8..b7e6c1228fff 100644 --- a/drivers/gpu/vga/vgaarb.c +++ b/drivers/gpu/vga/vgaarb.c @@ -719,8 +719,10 @@ static void vga_arbiter_check_bridge_sharing(struct vga_device *vgadev) vgadev->bridge_has_one_vga = true; - if (list_empty(&vga_list)) + if (list_empty(&vga_list)) { + vgaarb_info(&vgadev->pdev->dev, "bridge control possible\n"); return; + } /* okay iterate the new devices bridge hierarachy */ new_bus = vgadev->pdev->bus; @@ -759,6 +761,11 @@ static void vga_arbiter_check_bridge_sharing(struct vga_device *vgadev) } new_bus = new_bus->parent; } + + if (vgadev->bridge_has_one_vga) + vgaarb_info(&vgadev->pdev->dev, "bridge control possible\n"); + else + vgaarb_info(&vgadev->pdev->dev, "no bridge control possible\n"); } /* @@ -1557,7 +1564,6 @@ static int __init vga_arb_device_init(void) { int rc; struct pci_dev *pdev; - struct vga_device *vgadev; rc = misc_register(&vga_arb_device); if (rc < 0) @@ -1573,15 +1579,6 @@ static int __init vga_arb_device_init(void) PCI_ANY_ID, pdev)) != NULL) vga_arbiter_add_pci_device(pdev); - list_for_each_entry(vgadev, &vga_list, list) { - struct device *dev = &vgadev->pdev->dev; - - if (vgadev->bridge_has_one_vga) - vgaarb_info(dev, "bridge control possible\n"); - else - vgaarb_info(dev, "no bridge control possible\n"); - } - pr_info("loaded\n"); return rc; } From patchwork Thu Jan 6 00:06:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 12704894 X-Patchwork-Delegate: bhelgaas@google.com 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 1DFADC433EF for ; Thu, 6 Jan 2022 00:07:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343583AbiAFAH4 (ORCPT ); Wed, 5 Jan 2022 19:07:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343603AbiAFAHh (ORCPT ); Wed, 5 Jan 2022 19:07:37 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0074C06118A; Wed, 5 Jan 2022 16:07:30 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AA60AB81E5E; Thu, 6 Jan 2022 00:07:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DA08C36AEB; Thu, 6 Jan 2022 00:07:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641427648; bh=7e7h7G+8Us/sLyTD6q0Hif8nF7Obr/tfz8j1T8HZEsY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=doFh3KTAdOd5jn+Jvk+pzEuWyAOL1Yljo/Vh7gIdONaFL39/5LbRzNUCbkX84Acei wEOfSkWls7+rv2IyhAVIMGuolNkX+rMxFYlU6UIe/pOjjYJyyqKpcnsr7duiz2P+sn qfBOU0QyO3zizcwV/wfLhdON2AezyOaoppAGTB7gdG5FXMfUv5cIDIhFvOxzOGFDQQ yvpPNxJsFeibTXQPF99RFXQ5zsUd3pPZJKEaWw01qXvAmJqNdvRp9Wd0Hnb4ezUZqY +tGGdK5NThKQVR8pivTFmk0cIJXnFo3vRlgKXCYjbf9UBaq+3GTGNcwYg8tUXDOy1+ KucPswP+8lHqQ== From: Bjorn Helgaas To: David Airlie , Daniel Vetter Cc: Xuefeng Li , Huacai Chen , Huacai Chen , linux-pci@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Bjorn Helgaas Subject: [PATCH v8 09/10] vgaarb: Use unsigned format string to print lock counts Date: Wed, 5 Jan 2022 18:06:57 -0600 Message-Id: <20220106000658.243509-10-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220106000658.243509-1-helgaas@kernel.org> References: <20220106000658.243509-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas In struct vga_device, io_lock_cnt and mem_lock_cnt are unsigned, but we previously printed them with "%d", the signed decimal format. Print them with the unsigned format "%u" instead. Signed-off-by: Bjorn Helgaas --- drivers/gpu/vga/vgaarb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c index b7e6c1228fff..95e37817074e 100644 --- a/drivers/gpu/vga/vgaarb.c +++ b/drivers/gpu/vga/vgaarb.c @@ -1156,7 +1156,7 @@ static ssize_t vga_arb_read(struct file *file, char __user *buf, /* Fill the buffer with infos */ len = snprintf(lbuf, 1024, - "count:%d,PCI:%s,decodes=%s,owns=%s,locks=%s(%d:%d)\n", + "count:%d,PCI:%s,decodes=%s,owns=%s,locks=%s(%u:%u)\n", vga_decode_count, pci_name(pdev), vga_iostate_to_str(vgadev->decodes), vga_iostate_to_str(vgadev->owns), From patchwork Thu Jan 6 00:06:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 12704895 X-Patchwork-Delegate: bhelgaas@google.com 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 84B82C433F5 for ; Thu, 6 Jan 2022 00:07:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343598AbiAFAH4 (ORCPT ); Wed, 5 Jan 2022 19:07:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343608AbiAFAHh (ORCPT ); Wed, 5 Jan 2022 19:07:37 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C610FC034000; Wed, 5 Jan 2022 16:07:32 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 81396B81158; Thu, 6 Jan 2022 00:07:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E150EC36AE9; Thu, 6 Jan 2022 00:07:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641427650; bh=eFcCVHcUE6n7df4Kn5y8+cMmoJO4JQ61k+0y6bgAZDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mbgEtgn+e0KfN0BG3pU8Iwcm/xG0tecdedyOmJD/FhvnqcK+bxasDIyNF3yFqw+Sm 89hSAp2YfNsOkC8foYJgLhst5+T549saf2ZBRV5p7fMqI1p6fj2ueh6uKOZM09oPZx E/HEscPKi0vPOZHA7C6NuePakWu6cdJBS98uGOGWjok7Ul25spcWWT7gIxnjVD4EvJ AsUfKGU1mvTg+tOkbk9nQuWNq7rufjoKH3pmVkA28mZALeAvHzS3YxHqKSkGcUYNOH TIpwj+ZKTxCkQf6EaQ9jCl/ULBIOUFSSvEcmeWue6HPA+E0NgFxj1bhWpJs6Ussgk3 Z+0RrANPlYpcQ== From: Bjorn Helgaas To: David Airlie , Daniel Vetter Cc: Xuefeng Li , Huacai Chen , Huacai Chen , linux-pci@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Bjorn Helgaas Subject: [PATCH v8 10/10] vgaarb: Replace full MIT license text with SPDX identifier Date: Wed, 5 Jan 2022 18:06:58 -0600 Message-Id: <20220106000658.243509-11-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220106000658.243509-1-helgaas@kernel.org> References: <20220106000658.243509-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas Per Documentation/process/license-rules.rst, the SPDX MIT identifier is equivalent to including the entire MIT license text from LICENSES/preferred/MIT. Replace the MIT license text with the equivalent SPDX identifier. Signed-off-by: Bjorn Helgaas --- drivers/gpu/vga/vgaarb.c | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c index 95e37817074e..17e9d2536430 100644 --- a/drivers/gpu/vga/vgaarb.c +++ b/drivers/gpu/vga/vgaarb.c @@ -1,32 +1,11 @@ +// SPDX-License-Identifier: MIT /* * vgaarb.c: Implements the VGA arbitration. For details refer to * Documentation/gpu/vgaarbiter.rst * - * * (C) Copyright 2005 Benjamin Herrenschmidt * (C) Copyright 2007 Paulo R. Zanoni * (C) Copyright 2007, 2009 Tiago Vignatti - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS - * IN THE SOFTWARE. - * */ #define pr_fmt(fmt) "vgaarb: " fmt