From patchwork Sun Jun 4 20:58:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 103045 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2316331vqr; Sun, 4 Jun 2023 14:10:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7EiOc/n/fNEQJ1gn0nzSSXn4LlIv+EJdDu6F42TmOXjbaPwaqyEiIpPnXyZvnPFZ3dbOMm X-Received: by 2002:a17:902:e845:b0:1ac:820e:c34a with SMTP id t5-20020a170902e84500b001ac820ec34amr6824907plg.0.1685912999906; Sun, 04 Jun 2023 14:09:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685912999; cv=none; d=google.com; s=arc-20160816; b=hE3aJuGs764v+lId/TK/1CVHJS6mmcufCcP907sjT4jojJJo07oBZHXMjkrsOzJiFe D+5tk9KemnavUoPqzmIAFPLUCbeKMK//0tvL66qSXgA5BIlcXAIXAYuwFJQkpDYbXAbw NfVh1784xtabY8F0Fk+nFwh630SrE6R5kKw/02f/IC/0a6x86LeGzNAZ6zVHsBQLjvF0 5EGFfBDjNtnci2jvDd4cmmHzaKRvJzQtH9E23cEpDABSkPBfDzDtJ19BGixQA75zp8sy OblbAmg04YhWwN8S49w67vjPFh8S/U2EqQPLQ24xkHgu7mEu9roI5F+UBCi2hCuKQnb6 y3uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:sender:hmm_source_type :hmm_attache_num:hmm_source_ip; bh=r09Ph6kjGpLvQeo4iUoaLgeTCAcydOjddY0ifrDVCFk=; b=eYnDm3IJtTAPyK+9nEIJOkekMUKesZvHpaFgTCVqsZVmCJ2EgLIoJ78bEYSuv8/VZE 3eCa+BJDeYJLI0SYBMyXcz82q6r1+AX7Jf2C1JO0ua18eCNnCctjCXT3w1KfNRLqPQR4 XZbF9A3cbk/dp8eOvNMDFH2uvkG415Bhy5tm6YShBe+3wFGdkaJKSAfkdY83g6DD5TGk GxhXEYPRPqD97l+BqhqvFEUr5JoQ5Y4BFytFK4O4j+l73/sNXvxRqGAi+j9rE00vMAhG Jdp+7Td4dMxd4uANOGM1bjsFp1jHsAlcDLuvn9cgpTlIFIXFRY+XwBlmixAkomH/2UOs 3lcw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s18-20020a632c12000000b0053fc2857c09si4558568pgs.652.2023.06.04.14.09.46; Sun, 04 Jun 2023 14:09:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232234AbjFDU6r (ORCPT + 99 others); Sun, 4 Jun 2023 16:58:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232269AbjFDU6n (ORCPT ); Sun, 4 Jun 2023 16:58:43 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.103]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ADF75DE; Sun, 4 Jun 2023 13:58:38 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.43:47878.118806016 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.43]) by 189.cn (HERMES) with SMTP id A5DA710029A; Mon, 5 Jun 2023 04:58:33 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-7vx9t with ESMTP id 7eb87e86c4c04d1db87dbc5c9319b4e0 for alexander.deucher@amd.com; Mon, 05 Jun 2023 04:58:36 CST X-Transaction-ID: 7eb87e86c4c04d1db87dbc5c9319b4e0 X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Alex Deucher , Christian Konig , Pan Xinhui , David Airlie , Daniel Vetter , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Ben Skeggs , Karol Herbst , Lyude Paul , Bjorn Helgaas , Alex Williamson , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Hawking Zhang , Mario Limonciello , Lijo Lazar , YiPeng Chai , Andrey Grodzovsky , Somalapuram Amaranath , Bokun Zhang , Ville Syrjala , Li Yi , Sui Jingfeng , Jason Gunthorpe , Kevin Tian , Cornelia Huck , Yishai Hadas , Abhishek Sahu , Yi Liu Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, loongson-kernel@lists.loongnix.cn Subject: [PATCH v2 1/2] vgaarb: various coding style and comments fix Date: Mon, 5 Jun 2023 04:58:30 +0800 Message-Id: <20230604205831.3357596-1-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,FROM_LOCAL_DIGITS, FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767807909527472154?= X-GMAIL-MSGID: =?utf-8?q?1767807909527472154?= From: Sui Jingfeng To keep consistent with vga_iostate_to_str() function, the third argument of vga_str_to_iostate() function should be 'unsigned int *'. Signed-off-by: Sui Jingfeng --- drivers/pci/vgaarb.c | 29 +++++++++++++++-------------- include/linux/vgaarb.h | 8 +++----- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/drivers/pci/vgaarb.c b/drivers/pci/vgaarb.c index 5a696078b382..e40e6e5e5f03 100644 --- a/drivers/pci/vgaarb.c +++ b/drivers/pci/vgaarb.c @@ -61,7 +61,6 @@ static bool vga_arbiter_used; static DEFINE_SPINLOCK(vga_lock); static DECLARE_WAIT_QUEUE_HEAD(vga_wait_queue); - static const char *vga_iostate_to_str(unsigned int iostate) { /* Ignore VGA_RSRC_IO and VGA_RSRC_MEM */ @@ -77,10 +76,12 @@ static const char *vga_iostate_to_str(unsigned int iostate) return "none"; } -static int vga_str_to_iostate(char *buf, int str_size, int *io_state) +static int vga_str_to_iostate(char *buf, int str_size, unsigned int *io_state) { - /* we could in theory hand out locks on IO and mem - * separately to userspace but it can cause deadlocks */ + /* + * we could in theory hand out locks on IO and mem + * separately to userspace but it can cause deadlocks + */ if (strncmp(buf, "none", 4) == 0) { *io_state = VGA_RSRC_NONE; return 1; @@ -99,7 +100,7 @@ static int vga_str_to_iostate(char *buf, int str_size, int *io_state) return 1; } -/* this is only used a cookie - it should not be dereferenced */ +/* This is only used as cookie, it should not be dereferenced */ static struct pci_dev *vga_default; /* Find somebody in our list */ @@ -194,13 +195,15 @@ int vga_remove_vgacon(struct pci_dev *pdev) EXPORT_SYMBOL(vga_remove_vgacon); /* If we don't ever use VGA arb we should avoid - turning off anything anywhere due to old X servers getting - confused about the boot device not being VGA */ + * turning off anything anywhere due to old X servers getting + * confused about the boot device not being VGA + */ static void vga_check_first_use(void) { /* we should inform all GPUs in the system that * VGA arb has occurred and to try and disable resources - * if they can */ + * if they can + */ if (!vga_arbiter_used) { vga_arbiter_used = true; vga_arbiter_notify_clients(); @@ -865,8 +868,7 @@ static bool vga_arbiter_del_pci_device(struct pci_dev *pdev) } /* this is called with the lock */ -static inline void vga_update_device_decodes(struct vga_device *vgadev, - int new_decodes) +static void vga_update_device_decodes(struct vga_device *vgadev, int new_decodes) { struct device *dev = &vgadev->pdev->dev; int old_decodes, decodes_removed, decodes_unlocked; @@ -956,9 +958,9 @@ EXPORT_SYMBOL(vga_set_legacy_decoding); * @set_decode callback: If a client can disable its GPU VGA resource, it * will get a callback from this to set the encode/decode state. * - * Rationale: we cannot disable VGA decode resources unconditionally some single - * GPU laptops seem to require ACPI or BIOS access to the VGA registers to - * control things like backlights etc. Hopefully newer multi-GPU laptops do + * Rationale: we cannot disable VGA decode resources unconditionally, some + * single GPU laptops seem to require ACPI or BIOS access to the VGA registers + * to control things like backlights etc. Hopefully newer multi-GPU laptops do * something saner, and desktops won't have any special ACPI for this. The * driver will get a callback when VGA arbitration is first used by userspace * since some older X servers have issues. @@ -988,7 +990,6 @@ int vga_client_register(struct pci_dev *pdev, bail: spin_unlock_irqrestore(&vga_lock, flags); return ret; - } EXPORT_SYMBOL(vga_client_register); diff --git a/include/linux/vgaarb.h b/include/linux/vgaarb.h index b4b9137f9792..d36225c582ee 100644 --- a/include/linux/vgaarb.h +++ b/include/linux/vgaarb.h @@ -23,9 +23,7 @@ * 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. - * + * DEALINGS IN THE SOFTWARE. */ #ifndef LINUX_VGA_H @@ -96,7 +94,7 @@ static inline int vga_client_register(struct pci_dev *pdev, static inline int vga_get_interruptible(struct pci_dev *pdev, unsigned int rsrc) { - return vga_get(pdev, rsrc, 1); + return vga_get(pdev, rsrc, 1); } /** @@ -111,7 +109,7 @@ static inline int vga_get_interruptible(struct pci_dev *pdev, static inline int vga_get_uninterruptible(struct pci_dev *pdev, unsigned int rsrc) { - return vga_get(pdev, rsrc, 0); + return vga_get(pdev, rsrc, 0); } static inline void vga_client_unregister(struct pci_dev *pdev) From patchwork Sun Jun 4 20:58:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 103044 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2316283vqr; Sun, 4 Jun 2023 14:09:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6X4KHRB324AW9UrB0wkBD0s1sq+hZt4CyY6hgtf95Rb6FkR9/VHmbgOqPOnwxWr2o9t2Du X-Received: by 2002:a17:902:e88f:b0:1b0:6361:a1b3 with SMTP id w15-20020a170902e88f00b001b06361a1b3mr7371427plg.53.1685912993050; Sun, 04 Jun 2023 14:09:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685912993; cv=none; d=google.com; s=arc-20160816; b=BkLwPzJLz7kpEuNfV7kdexM4DUt3S2yVb9KMDgHMgCn82hCvSxssksGK7cwvJEmo8F mRy2llfG9FiVR428cEcsaL/WkfGPo/bjw6DKesV8Jp+ePnkrl4ujYBjtlm1M/86x7lfh lGlY+SyuZ8Xa0/JZHx0H/O2LCTcK4cIa5dioSp83p/7V9HZAK8I60YF2wFLGPATrY/mZ sJBYrG8wHURnkPVz/M0PxLcNO+hpF8g9tJXto6n2PmMLuabeW5JXy9QidOFQJKoQzrGy eHl3gxm6qMgrc1iXywqher4Kr2kPwluY0WaY8RLzP57jwMSR+nWDZX2BeRtaBg73dONO Gxlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=bHVYlHtsP9CMQ0q8IBMvlWjbZuO6Ax/DoXrWufHSjCc=; b=vX8QJXia/+U7rKi25WyaMPE0tbZQv4S393AR95FJnn1jklRHx1SLAQB15RYLFSBN1d JpH41KThJclslzUxN4Enrw9OeuLl9plAXmUm/z2cQNL3rntSyo8dfBBEM/PijW4jeO7F j9P3YI5T4ljBUwqfIZsImZTq2b8ivb3cSKvugABQgPh4Z6aa9xCcJCB1cRMAYD+EfFUB 5UAmrP01h5AQUHwUcqLBF4PzaxQk2w9UJf+PyoWtRxQYA/uwhk7dcMk1QWqIRb+2Ufiu qLzhqvWdkSBRqFX+uUDqt3E32drbdb9yq/dGai1qPjpi7pjok6RJ7tixaFT6nN8h/QSp n06A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i12-20020a17090332cc00b001b03fc03accsi4540443plr.351.2023.06.04.14.09.40; Sun, 04 Jun 2023 14:09:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230378AbjFDU6u (ORCPT + 99 others); Sun, 4 Jun 2023 16:58:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231754AbjFDU6r (ORCPT ); Sun, 4 Jun 2023 16:58:47 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.103]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 763FAD2; Sun, 4 Jun 2023 13:58:40 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.43:47878.118806016 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.43]) by 189.cn (HERMES) with SMTP id B96AD10029F; Mon, 5 Jun 2023 04:58:36 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-7vx9t with ESMTP id b5b118ae41ab49e0a154bdb74caa128c for alexander.deucher@amd.com; Mon, 05 Jun 2023 04:58:39 CST X-Transaction-ID: b5b118ae41ab49e0a154bdb74caa128c X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Alex Deucher , Christian Konig , Pan Xinhui , David Airlie , Daniel Vetter , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Ben Skeggs , Karol Herbst , Lyude Paul , Bjorn Helgaas , Alex Williamson , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Hawking Zhang , Mario Limonciello , Lijo Lazar , YiPeng Chai , Andrey Grodzovsky , Somalapuram Amaranath , Bokun Zhang , Ville Syrjala , Li Yi , Sui Jingfeng , Jason Gunthorpe , Kevin Tian , Cornelia Huck , Yishai Hadas , Abhishek Sahu , Yi Liu Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, loongson-kernel@lists.loongnix.cn Subject: [PATCH v2 2/2] vgaarb: introduce is_boot_device callback function to vga_client_register Date: Mon, 5 Jun 2023 04:58:31 +0800 Message-Id: <20230604205831.3357596-2-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230604205831.3357596-1-15330273260@189.cn> References: <20230604205831.3357596-1-15330273260@189.cn> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,FROM_LOCAL_DIGITS, FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767807902689434014?= X-GMAIL-MSGID: =?utf-8?q?1767807902689434014?= From: Sui Jingfeng The vga_is_firmware_default() function is arch-dependent, which dosen't sound right. At least, It also works on Mips and LoongArch platform with the drm/AMDGPU and drm/radeon driver. However, it's difficult to enumerate all Arch-driver combination. I'm wrong if there are only one exception. With the observation that device drivers typically has better knowledge about which PCI bar contains the firmware framebuffer, Which could helps to avoids the need to iterate all of the PCI BARs. But As a PCI core function at pci/vgaarb.c, vga_is_firmware_default funciton is embarrasing to make optimization for a specific device. There also has PCI display controller don't has a dedicated VRAM bar in the world, this function will lost the effectiveness on such a case. Luckily, device driver can do the accurate workaround. We add a callback then, to let the device driver make the decision. Device drivers know what archs it could works, device driver also can shipping this decision to whatever arch its device can reach, not only the X86 and IA64. Also honor the comment: "Clients have two callback mechanisms they can use" Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- drivers/gpu/drm/i915/display/intel_vga.c | 3 +-- drivers/gpu/drm/nouveau/nouveau_vga.c | 2 +- drivers/gpu/drm/radeon/radeon_device.c | 2 +- drivers/pci/vgaarb.c | 22 ++++++++++++++++++---- drivers/vfio/pci/vfio_pci_core.c | 2 +- include/linux/vgaarb.h | 8 +++++--- 7 files changed, 28 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index 5c7d40873ee2..7a096f2d5c16 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -3960,7 +3960,7 @@ int amdgpu_device_init(struct amdgpu_device *adev, /* this will fail for cards that aren't VGA class devices, just * ignore it */ if ((adev->pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA) - vga_client_register(adev->pdev, amdgpu_device_vga_set_decode); + vga_client_register(adev->pdev, amdgpu_device_vga_set_decode, NULL); px = amdgpu_device_supports_px(ddev); diff --git a/drivers/gpu/drm/i915/display/intel_vga.c b/drivers/gpu/drm/i915/display/intel_vga.c index 286a0bdd28c6..98d7d4dffe9f 100644 --- a/drivers/gpu/drm/i915/display/intel_vga.c +++ b/drivers/gpu/drm/i915/display/intel_vga.c @@ -115,7 +115,6 @@ intel_vga_set_decode(struct pci_dev *pdev, bool enable_decode) int intel_vga_register(struct drm_i915_private *i915) { - struct pci_dev *pdev = to_pci_dev(i915->drm.dev); int ret; @@ -127,7 +126,7 @@ int intel_vga_register(struct drm_i915_private *i915) * then we do not take part in VGA arbitration and the * vga_client_register() fails with -ENODEV. */ - ret = vga_client_register(pdev, intel_vga_set_decode); + ret = vga_client_register(pdev, intel_vga_set_decode, NULL); if (ret && ret != -ENODEV) return ret; diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c index f8bf0ec26844..162b4f4676c7 100644 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c @@ -92,7 +92,7 @@ nouveau_vga_init(struct nouveau_drm *drm) return; pdev = to_pci_dev(dev->dev); - vga_client_register(pdev, nouveau_vga_set_decode); + vga_client_register(pdev, nouveau_vga_set_decode, NULL); /* don't register Thunderbolt eGPU with vga_switcheroo */ if (pci_is_thunderbolt_attached(pdev)) diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c index afbb3a80c0c6..71f2ff39d6a1 100644 --- a/drivers/gpu/drm/radeon/radeon_device.c +++ b/drivers/gpu/drm/radeon/radeon_device.c @@ -1425,7 +1425,7 @@ int radeon_device_init(struct radeon_device *rdev, /* if we have > 1 VGA cards, then disable the radeon VGA resources */ /* this will fail for cards that aren't VGA class devices, just * ignore it */ - vga_client_register(rdev->pdev, radeon_vga_set_decode); + vga_client_register(rdev->pdev, radeon_vga_set_decode, NULL); if (rdev->flags & RADEON_IS_PX) runtime = true; diff --git a/drivers/pci/vgaarb.c b/drivers/pci/vgaarb.c index e40e6e5e5f03..4576c4197551 100644 --- a/drivers/pci/vgaarb.c +++ b/drivers/pci/vgaarb.c @@ -53,6 +53,7 @@ struct vga_device { bool bridge_has_one_vga; bool is_firmware_default; /* device selected by firmware */ unsigned int (*set_decode)(struct pci_dev *pdev, bool decode); + bool (*is_boot_device)(struct pci_dev *pdev); }; static LIST_HEAD(vga_list); @@ -615,10 +616,17 @@ static bool vga_is_boot_device(struct vga_device *vgadev) if (boot_vga && boot_vga->is_firmware_default) return false; - if (vga_is_firmware_default(pdev)) { - vgadev->is_firmware_default = true; + /* + * Ask the device driver first, if registered. Fallback to the + * default implement if the callback is non-exist. + */ + if (vgadev->is_boot_device) + vgadev->is_firmware_default = vgadev->is_boot_device(pdev); + else + vgadev->is_firmware_default = vga_is_firmware_default(pdev); + + if (vgadev->is_firmware_default) return true; - } /* * A legacy VGA device has MEM and IO enabled and any bridges @@ -958,6 +966,10 @@ EXPORT_SYMBOL(vga_set_legacy_decoding); * @set_decode callback: If a client can disable its GPU VGA resource, it * will get a callback from this to set the encode/decode state. * + * @is_boot_device: callback to the device driver, query if a client is the + * default boot device, as the device driver typically has better knowledge + * if specific device is the boot device. But this callback is optional. + * * Rationale: we cannot disable VGA decode resources unconditionally, some * single GPU laptops seem to require ACPI or BIOS access to the VGA registers * to control things like backlights etc. Hopefully newer multi-GPU laptops do @@ -973,7 +985,8 @@ EXPORT_SYMBOL(vga_set_legacy_decoding); * Returns: 0 on success, -1 on failure */ int vga_client_register(struct pci_dev *pdev, - unsigned int (*set_decode)(struct pci_dev *pdev, bool decode)) + unsigned int (*set_decode)(struct pci_dev *pdev, bool decode), + bool (*is_boot_device)(struct pci_dev *pdev)) { int ret = -ENODEV; struct vga_device *vgadev; @@ -985,6 +998,7 @@ int vga_client_register(struct pci_dev *pdev, goto bail; vgadev->set_decode = set_decode; + vgadev->is_boot_device = is_boot_device; ret = 0; bail: diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index a5ab416cf476..2a8873a330ba 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -2067,7 +2067,7 @@ static int vfio_pci_vga_init(struct vfio_pci_core_device *vdev) if (ret) return ret; - ret = vga_client_register(pdev, vfio_pci_set_decode); + ret = vga_client_register(pdev, vfio_pci_set_decode, NULL); if (ret) return ret; vga_set_legacy_decoding(pdev, vfio_pci_set_decode(pdev, false)); diff --git a/include/linux/vgaarb.h b/include/linux/vgaarb.h index d36225c582ee..66fe80ffad76 100644 --- a/include/linux/vgaarb.h +++ b/include/linux/vgaarb.h @@ -50,7 +50,8 @@ struct pci_dev *vga_default_device(void); void vga_set_default_device(struct pci_dev *pdev); int vga_remove_vgacon(struct pci_dev *pdev); int vga_client_register(struct pci_dev *pdev, - unsigned int (*set_decode)(struct pci_dev *pdev, bool state)); + unsigned int (*set_decode)(struct pci_dev *pdev, bool state), + bool (*is_boot_device)(struct pci_dev *pdev)); #else /* CONFIG_VGA_ARB */ static inline void vga_set_legacy_decoding(struct pci_dev *pdev, unsigned int decodes) @@ -76,7 +77,8 @@ static inline int vga_remove_vgacon(struct pci_dev *pdev) return 0; } static inline int vga_client_register(struct pci_dev *pdev, - unsigned int (*set_decode)(struct pci_dev *pdev, bool state)) + unsigned int (*set_decode)(struct pci_dev *pdev, bool state), + bool (*is_boot_device)(struct pci_dev *pdev)) { return 0; } @@ -114,7 +116,7 @@ static inline int vga_get_uninterruptible(struct pci_dev *pdev, static inline void vga_client_unregister(struct pci_dev *pdev) { - vga_client_register(pdev, NULL); + vga_client_register(pdev, NULL, NULL); } #endif /* LINUX_VGA_H */