From patchwork Mon Sep 4 19:57:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 1829734 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Umc5L5nk; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pci-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4RffZ15XhBz1ynq for ; Tue, 5 Sep 2023 05:57:45 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235627AbjIDT5r (ORCPT ); Mon, 4 Sep 2023 15:57:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235288AbjIDT5p (ORCPT ); Mon, 4 Sep 2023 15:57:45 -0400 Received: from out-227.mta1.migadu.com (out-227.mta1.migadu.com [95.215.58.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFF11180 for ; Mon, 4 Sep 2023 12:57:41 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693857458; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OcmG12mmWiMHQssRNKwGSMzorFeF7+pAcaQIVBtY3KU=; b=Umc5L5nksLtIUADB5XoXaVOKwwgwfgU/GIOj+4XCQLNTz0mvoFjDIp/jmf3nc7NzaoqPb2 n2s7xkPFZx919FUwVXLGsNjMQi7OOnbsmlJ9JX9QRgvBM1COB7+xNpO8kgn51VOj6kbWzL GXfNbDGpzPsfxMmC33vtxKIDur1mSdA= From: Sui Jingfeng To: Bjorn Helgaas 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, Sui Jingfeng , Jani Nikula , Lyude Paul Subject: [RFC,drm-misc-next v4 1/9] PCI/VGA: Allowing the user to select the primary video adapter at boot time Date: Tue, 5 Sep 2023 03:57:16 +0800 Message-Id: <20230904195724.633404-2-sui.jingfeng@linux.dev> In-Reply-To: <20230904195724.633404-1-sui.jingfeng@linux.dev> References: <20230904195724.633404-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham 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-pci@vger.kernel.org From: Sui Jingfeng On a machine with multiple GPUs, a Linux user has no control over which one is primary at boot time. This series tries to solve above mentioned problem by introduced the ->be_primary() function stub. The specific device drivers can provide an implementation to hook up with this stub by calling the vga_client_register() function. Once the driver bound the device successfully, VGAARB will call back to the device driver. To query if the device drivers want to be primary or not. Device drivers can just pass NULL if have no such needs. Acked-by: Jani Nikula # i915 Reviewed-by: Lyude Paul # nouveau 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/loongson/lsdc_drv.c | 2 +- drivers/gpu/drm/nouveau/nouveau_vga.c | 2 +- drivers/gpu/drm/radeon/radeon_device.c | 2 +- drivers/pci/vgaarb.c | 43 +++++++++++++++++++--- drivers/vfio/pci/vfio_pci_core.c | 2 +- include/linux/vgaarb.h | 8 ++-- 8 files changed, 49 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index e77f048c99d8..ecc4564ceac0 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -3916,7 +3916,7 @@ int amdgpu_device_init(struct amdgpu_device *adev, * 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/loongson/lsdc_drv.c b/drivers/gpu/drm/loongson/lsdc_drv.c index 188ec82afcfb..d10a28c2c494 100644 --- a/drivers/gpu/drm/loongson/lsdc_drv.c +++ b/drivers/gpu/drm/loongson/lsdc_drv.c @@ -289,7 +289,7 @@ static int lsdc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) pci_set_drvdata(pdev, ddev); - vga_client_register(pdev, lsdc_vga_set_decode); + vga_client_register(pdev, lsdc_vga_set_decode, NULL); drm_kms_helper_poll_init(ddev); 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 5a696078b382..552ac7df10ee 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 (*be_primary)(struct pci_dev *pdev); }; static LIST_HEAD(vga_list); @@ -956,6 +957,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. * + * @be_primary callback: Callback to the device driver, query if a device + * want to be the primary display. This callback is optional, device drivers + * who have no special needs can simply pass a NULL. + * * 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 @@ -971,7 +976,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 (*be_primary)(struct pci_dev *pdev)) { int ret = -ENODEV; struct vga_device *vgadev; @@ -983,6 +989,7 @@ int vga_client_register(struct pci_dev *pdev, goto bail; vgadev->set_decode = set_decode; + vgadev->be_primary = be_primary; ret = 0; bail: @@ -1493,6 +1500,21 @@ static void vga_arbiter_notify_clients(void) spin_unlock_irqrestore(&vga_lock, flags); } +static void vga_arbiter_do_arbitration(struct pci_dev *pdev) +{ + struct vga_device *vgadev; + + if (pdev == vga_default_device()) + return; + + vgadev = vgadev_find(pdev); + if (vgadev && vgadev->be_primary && vgadev->be_primary(pdev)) { + vga_set_default_device(pdev); + + vgaarb_info(&pdev->dev, "Override as primary by driver\n"); + } +} + static int pci_notify(struct notifier_block *nb, unsigned long action, void *data) { @@ -1505,13 +1527,24 @@ static int pci_notify(struct notifier_block *nb, unsigned long action, /* For now we're only intereted in devices added and removed. I didn't * test this thing here, so someone needs to double check for the * cases of hotplugable vga cards. */ - if (action == BUS_NOTIFY_ADD_DEVICE) + switch (action) { + case BUS_NOTIFY_ADD_DEVICE: notify = vga_arbiter_add_pci_device(pdev); - else if (action == BUS_NOTIFY_DEL_DEVICE) + if (notify) + vga_arbiter_notify_clients(); + break; + case BUS_NOTIFY_DEL_DEVICE: notify = vga_arbiter_del_pci_device(pdev); + if (notify) + vga_arbiter_notify_clients(); + break; + case BUS_NOTIFY_BOUND_DRIVER: + vga_arbiter_do_arbitration(pdev); + break; + default: + break; + } - if (notify) - vga_arbiter_notify_clients(); return 0; } diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 20d7b69ea6ff..531c4d8ef26e 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -2108,7 +2108,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 b4b9137f9792..291d82b9f05a 100644 --- a/include/linux/vgaarb.h +++ b/include/linux/vgaarb.h @@ -52,7 +52,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 (*be_primary)(struct pci_dev *pdev)); #else /* CONFIG_VGA_ARB */ static inline void vga_set_legacy_decoding(struct pci_dev *pdev, unsigned int decodes) @@ -78,7 +79,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 (*be_primary)(struct pci_dev *pdev)) { return 0; } @@ -116,7 +118,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 */ From patchwork Mon Sep 4 19:57:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 1829733 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=WMS/w8Fg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pci-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4RffZ11YVbz1ynf for ; Tue, 5 Sep 2023 05:57:45 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235731AbjIDT5q (ORCPT ); Mon, 4 Sep 2023 15:57:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231920AbjIDT5o (ORCPT ); Mon, 4 Sep 2023 15:57:44 -0400 Received: from out-227.mta1.migadu.com (out-227.mta1.migadu.com [95.215.58.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE67FBD for ; Mon, 4 Sep 2023 12:57:41 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693857460; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o7qBg3iDQqf8IwXL/E4Wgz6fxfLGjyBUHVlaSKqEqM0=; b=WMS/w8FgJ79aPQ8l4g/8/d9wVJNdmJ/Trts3yfgLGchh5WoxYx1+w0H8NIuaAyS0IT5BkC Kjx20glONovJ8q2nZ9dMoVofSgZDpd/8y0klyEVggRv/eqObUf7XYTSMmhsr0xBmxPkuBC v/o6je4JekFri0ZrPJpgLowPojwWyOs= From: Sui Jingfeng To: Bjorn Helgaas 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, Sui Jingfeng Subject: [RFC,drm-misc-next v4 2/9] drm/nouveau: Implement .be_primary() callback Date: Tue, 5 Sep 2023 03:57:17 +0800 Message-Id: <20230904195724.633404-3-sui.jingfeng@linux.dev> In-Reply-To: <20230904195724.633404-1-sui.jingfeng@linux.dev> References: <20230904195724.633404-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham 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-pci@vger.kernel.org From: Sui Jingfeng On a machine with multiple GPUs, a Linux user has no control over which one is primary at boot time. This patch tries to solve the mentioned problem by implementing the .be_primary() callback. VGAARB will call back to Nouveau when the drm/nouveau gets loaded successfully. Pass nouveau.modeset=10 on the kernel cmd line if you really want the device bound by Nouveau to be the primary video adapter. This overrides whatever boot device selected by VGAARB. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/nouveau/nouveau_vga.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c index 162b4f4676c7..4242188667e2 100644 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c @@ -80,6 +80,15 @@ nouveau_switcheroo_ops = { .can_switch = nouveau_switcheroo_can_switch, }; +static bool +nouveau_want_to_be_primary(struct pci_dev *pdev) +{ + if (nouveau_modeset == 10) + return true; + + return false; +} + void nouveau_vga_init(struct nouveau_drm *drm) { @@ -92,7 +101,7 @@ nouveau_vga_init(struct nouveau_drm *drm) return; pdev = to_pci_dev(dev->dev); - vga_client_register(pdev, nouveau_vga_set_decode, NULL); + vga_client_register(pdev, nouveau_vga_set_decode, nouveau_want_to_be_primary); /* don't register Thunderbolt eGPU with vga_switcheroo */ if (pci_is_thunderbolt_attached(pdev)) From patchwork Mon Sep 4 19:57:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 1829737 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=MRbIL1ez; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pci-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4RffZG57k1z1yh1 for ; Tue, 5 Sep 2023 05:57:58 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236368AbjIDT56 (ORCPT ); Mon, 4 Sep 2023 15:57:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236321AbjIDT5x (ORCPT ); Mon, 4 Sep 2023 15:57:53 -0400 Received: from out-213.mta1.migadu.com (out-213.mta1.migadu.com [95.215.58.213]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CE08BD for ; Mon, 4 Sep 2023 12:57:43 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693857462; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kmuyy5d8TjfKPYFKMrpKxMdJxlBIiyPktdk9/3dqaTc=; b=MRbIL1ezV+MLDlrq8FrN2e2iqKWOCBSzCMXu00ItCM4BykmOR85mcBF+KstvvBGs6g1CU3 mO/B8rdGeNOFX1B78Vqej0MqiBxruE4A0+Vuxx2Pu/ErmZJgbG1UNtUYiHBqabuPRdixNg 0+mVRFLiH5Q5VIHnOltwIszhLHFeGRg= From: Sui Jingfeng To: Bjorn Helgaas 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, Sui Jingfeng , Alex Deucher , Christian Koenig Subject: [RFC,drm-misc-next v4 3/9] drm/radeon: Implement .be_primary() callback Date: Tue, 5 Sep 2023 03:57:18 +0800 Message-Id: <20230904195724.633404-4-sui.jingfeng@linux.dev> In-Reply-To: <20230904195724.633404-1-sui.jingfeng@linux.dev> References: <20230904195724.633404-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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-pci@vger.kernel.org From: Sui Jingfeng On a machine with multiple GPUs, a Linux user has no control over which one is primary at boot time. This patch tries to solve the mentioned problem by implementing the .be_primary() callback. Pass radeon.modeset=10 on the kernel cmd line if you really want the device bound by radeon to be the primary video adapter, no matter what VGAARB say. Cc: Alex Deucher Cc: Christian Koenig Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/radeon/radeon_device.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c index 71f2ff39d6a1..b661cd3a8dc2 100644 --- a/drivers/gpu/drm/radeon/radeon_device.c +++ b/drivers/gpu/drm/radeon/radeon_device.c @@ -1263,6 +1263,14 @@ static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = { .can_switch = radeon_switcheroo_can_switch, }; +static bool radeon_want_to_be_primary(struct pci_dev *pdev) +{ + if (radeon_modeset == 10) + return true; + + return false; +} + /** * radeon_device_init - initialize the driver * @@ -1425,7 +1433,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, NULL); + vga_client_register(rdev->pdev, radeon_vga_set_decode, radeon_want_to_be_primary); if (rdev->flags & RADEON_IS_PX) runtime = true; From patchwork Mon Sep 4 19:57:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 1829735 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Knc/PQa5; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pci-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4RffZC6Dmpz1yh1 for ; Tue, 5 Sep 2023 05:57:55 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234700AbjIDT54 (ORCPT ); Mon, 4 Sep 2023 15:57:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236130AbjIDT5t (ORCPT ); Mon, 4 Sep 2023 15:57:49 -0400 Received: from out-230.mta1.migadu.com (out-230.mta1.migadu.com [95.215.58.230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D86BD180 for ; Mon, 4 Sep 2023 12:57:45 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693857464; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nTyqdC4advhF1f2LWIzvXqUIn1S7wmBn4hXPYMV0KW4=; b=Knc/PQa5Wh7WbzPujlbqPJIvZyOiZUpkuNmq8G8cXeTxP9vcNZIHQiMsr4EXIJtKTFmhOY jIVySpNP8uVj4FDOPGVx/OV8DOZUz4fLOQ8ypLGh4wKVTxUTQ7YjxVOTT/SYxJtBfn72gN HeasxEJjrY21hUjU8uogIwElp3gvOuQ= From: Sui Jingfeng To: Bjorn Helgaas 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, Sui Jingfeng , Alex Deucher , Christian Konig Subject: [RFC,drm-misc-next v4 4/9] drm/amdgpu: Implement .be_primary() callback Date: Tue, 5 Sep 2023 03:57:19 +0800 Message-Id: <20230904195724.633404-5-sui.jingfeng@linux.dev> In-Reply-To: <20230904195724.633404-1-sui.jingfeng@linux.dev> References: <20230904195724.633404-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham 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-pci@vger.kernel.org From: Sui Jingfeng On a machine with multiple GPUs, a Linux user has no control over which one is primary at boot time. This patch tries to solve the mentioned problem by implementing the .be_primary() callback. Pass amdgpu.modeset=10 on the kernel cmd line if you really want the device bound by amdgpu drm driver to be the primary video adapter, no matter what VGAARB say. Cc: Alex Deucher Cc: Christian Konig Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 11 ++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 13 ++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index ecc4564ceac0..59bde6972a8b 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -3507,6 +3507,14 @@ static void amdgpu_device_set_mcbp(struct amdgpu_device *adev) DRM_INFO("MCBP is enabled\n"); } +static bool amdgpu_want_to_be_primary(struct pci_dev *pdev) +{ + if (amdgpu_modeset == 10) + return true; + + return false; +} + /** * amdgpu_device_init - initialize the driver * @@ -3916,7 +3924,8 @@ int amdgpu_device_init(struct amdgpu_device *adev, * ignore it */ if ((adev->pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA) - vga_client_register(adev->pdev, amdgpu_device_vga_set_decode, NULL); + vga_client_register(adev->pdev, amdgpu_device_vga_set_decode, + amdgpu_want_to_be_primary); px = amdgpu_device_supports_px(ddev); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index 81edf66dbea8..2592e24ce62c 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -118,6 +118,7 @@ #define KMS_DRIVER_MINOR 54 #define KMS_DRIVER_PATCHLEVEL 0 +int amdgpu_modeset = -1; unsigned int amdgpu_vram_limit = UINT_MAX; int amdgpu_vis_vram_limit; int amdgpu_gart_size = -1; /* auto */ @@ -223,6 +224,13 @@ struct amdgpu_watchdog_timer amdgpu_watchdog_timer = { .period = 0x0, /* default to 0x0 (timeout disable) */ }; +/** + * DOC: modeset (int) + * Disable/Enable kernel modesetting (1 = enable, 0 = disable, -1 = auto (default)). + */ +MODULE_PARM_DESC(modeset, "Disable/Enable kernel modesetting"); +module_param_named(modeset, amdgpu_modeset, int, 0600); + /** * DOC: vramlimit (int) * Restrict the total amount of VRAM in MiB for testing. The default is 0 (Use full VRAM). @@ -2872,7 +2880,10 @@ static int __init amdgpu_init(void) { int r; - if (drm_firmware_drivers_only()) + if (drm_firmware_drivers_only() && amdgpu_modeset == -1) + return -EINVAL; + + if (amdgpu_modeset == 0) return -EINVAL; r = amdgpu_sync_init(); From patchwork Mon Sep 4 19:57:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 1829736 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=WStnGQXe; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pci-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4RffZF2l65z1yh1 for ; Tue, 5 Sep 2023 05:57:57 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236105AbjIDT56 (ORCPT ); Mon, 4 Sep 2023 15:57:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236937AbjIDT55 (ORCPT ); Mon, 4 Sep 2023 15:57:57 -0400 Received: from out-216.mta1.migadu.com (out-216.mta1.migadu.com [95.215.58.216]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 077601715 for ; Mon, 4 Sep 2023 12:57:49 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693857466; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LqpDfy7jFw2xJEvEvsvRPCTDdY9j+2hqZZDtflMLDhg=; b=WStnGQXeW5BqIuHoiyaRzA+TJzXqxO/w6kqSS4bJpIIHA8VKpuQJC55KX3cJTyU0ojlG48 rQA4YgJna8esL75FwGA1ZCP6tfeU2Te6m7aNzn1JJt1o1j+Trw9b2ZZgImETGb439FHPM2 KY/rIaV6Z10ITNKiYHL2D3EBhLDq5cI= From: Sui Jingfeng To: Bjorn Helgaas 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, Sui Jingfeng , Jani Nikula , David Airlie , Daniel Vetter Subject: [RFC,drm-misc-next v4 5/9] drm/i915: Implement .be_primary() callback Date: Tue, 5 Sep 2023 03:57:20 +0800 Message-Id: <20230904195724.633404-6-sui.jingfeng@linux.dev> In-Reply-To: <20230904195724.633404-1-sui.jingfeng@linux.dev> References: <20230904195724.633404-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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-pci@vger.kernel.org From: Sui Jingfeng On a machine with multiple GPUs, a Linux user has no control over which one is primary at boot time. This patch tries to solve the mentioned problem by implementing the .be_primary() callback. Pass i915.modeset=10 on the kernel cmd line if you really want the device bound by i915 drm driver to be the primary video adapter, no matter what VGAARB say. Cc: Jani Nikula Cc: David Airlie Cc: Daniel Vetter Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/i915/display/intel_vga.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/display/intel_vga.c b/drivers/gpu/drm/i915/display/intel_vga.c index 98d7d4dffe9f..e3f78ba2668b 100644 --- a/drivers/gpu/drm/i915/display/intel_vga.c +++ b/drivers/gpu/drm/i915/display/intel_vga.c @@ -113,6 +113,17 @@ intel_vga_set_decode(struct pci_dev *pdev, bool enable_decode) return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; } +static bool intel_want_to_be_primary(struct pci_dev *pdev) +{ + struct drm_i915_private *i915 = pdev_to_i915(pdev); + struct i915_params *params = &i915->params; + + if (params->modeset == 10) + return true; + + return false; +} + int intel_vga_register(struct drm_i915_private *i915) { struct pci_dev *pdev = to_pci_dev(i915->drm.dev); @@ -126,7 +137,8 @@ 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, NULL); + ret = vga_client_register(pdev, intel_vga_set_decode, + intel_want_to_be_primary); if (ret && ret != -ENODEV) return ret; From patchwork Mon Sep 4 19:57:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 1829738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=rJNfpwab; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pci-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4RffZP36MZz1yh1 for ; Tue, 5 Sep 2023 05:58:05 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236291AbjIDT6H (ORCPT ); Mon, 4 Sep 2023 15:58:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236671AbjIDT6C (ORCPT ); Mon, 4 Sep 2023 15:58:02 -0400 Received: from out-218.mta1.migadu.com (out-218.mta1.migadu.com [95.215.58.218]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C964173E for ; Mon, 4 Sep 2023 12:57:51 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693857468; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=di2qHcFYE+Hq+NlRE1bj3bLblQwmCRGCImtdcZKCjUc=; b=rJNfpwab0aIQm5RePnYvbfQa2evsIovN8h4+vqXvX+exhBi1P8XMkvYUlqZh4bqcSCK8ec a6ItmnAfUtFXDK9qfWMe9SPjx/lb97SKdjyvvILTDduL6DPrrjMNVBrp5AOCHjnpFWhe/1 eW68Ko1bmHXCj0RZTYHobpMp/Uqx1oA= From: Sui Jingfeng To: Bjorn Helgaas 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, Sui Jingfeng Subject: [RFC,drm-misc-next v4 6/9] drm/loongson: Implement .be_primary() callback Date: Tue, 5 Sep 2023 03:57:21 +0800 Message-Id: <20230904195724.633404-7-sui.jingfeng@linux.dev> In-Reply-To: <20230904195724.633404-1-sui.jingfeng@linux.dev> References: <20230904195724.633404-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham 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-pci@vger.kernel.org From: Sui Jingfeng On a machine with multiple GPUs, a Linux user has no control over which one is primary at boot time. This patch tries to solve the mentioned problem by implementing the .be_primary() callback. Pass loongson.modeset=10 on the kernel cmd line if you really want the device bound by loongson drm driver to be the primary video adapter, no matter what VGAARB say. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/loongson/loongson_module.c | 2 +- drivers/gpu/drm/loongson/loongson_module.h | 1 + drivers/gpu/drm/loongson/lsdc_drv.c | 10 +++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/loongson/loongson_module.c b/drivers/gpu/drm/loongson/loongson_module.c index d2a51bd395f6..12f2a453adff 100644 --- a/drivers/gpu/drm/loongson/loongson_module.c +++ b/drivers/gpu/drm/loongson/loongson_module.c @@ -9,7 +9,7 @@ #include "loongson_module.h" -static int loongson_modeset = -1; +int loongson_modeset = -1; MODULE_PARM_DESC(modeset, "Disable/Enable modesetting"); module_param_named(modeset, loongson_modeset, int, 0400); diff --git a/drivers/gpu/drm/loongson/loongson_module.h b/drivers/gpu/drm/loongson/loongson_module.h index 931c17521bf0..afff51e7f34f 100644 --- a/drivers/gpu/drm/loongson/loongson_module.h +++ b/drivers/gpu/drm/loongson/loongson_module.h @@ -6,6 +6,7 @@ #ifndef __LOONGSON_MODULE_H__ #define __LOONGSON_MODULE_H__ +extern int loongson_modeset; extern int loongson_vblank; extern struct pci_driver lsdc_pci_driver; diff --git a/drivers/gpu/drm/loongson/lsdc_drv.c b/drivers/gpu/drm/loongson/lsdc_drv.c index d10a28c2c494..7183b0666167 100644 --- a/drivers/gpu/drm/loongson/lsdc_drv.c +++ b/drivers/gpu/drm/loongson/lsdc_drv.c @@ -257,6 +257,14 @@ static unsigned int lsdc_vga_set_decode(struct pci_dev *pdev, bool state) return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; } +static bool lsdc_want_to_be_primary(struct pci_dev *pdev) +{ + if (loongson_modeset == 10) + return true; + + return false; +} + static int lsdc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { const struct lsdc_desc *descp; @@ -289,7 +297,7 @@ static int lsdc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) pci_set_drvdata(pdev, ddev); - vga_client_register(pdev, lsdc_vga_set_decode, NULL); + vga_client_register(pdev, lsdc_vga_set_decode, lsdc_want_to_be_primary); drm_kms_helper_poll_init(ddev); From patchwork Mon Sep 4 19:57:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 1829740 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=NC2ru9MC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pci-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4RffZZ1Dw0z1ynf for ; Tue, 5 Sep 2023 05:58:14 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236462AbjIDT6P (ORCPT ); Mon, 4 Sep 2023 15:58:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237239AbjIDT6N (ORCPT ); Mon, 4 Sep 2023 15:58:13 -0400 Received: from out-228.mta1.migadu.com (out-228.mta1.migadu.com [95.215.58.228]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D8041B3 for ; Mon, 4 Sep 2023 12:57:53 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693857470; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eVLtpKZqnO0MsDqBoHAPYkiqg81D+bke81ZOJN69XK4=; b=NC2ru9MCWsAYNJ2JJcP1noCtF2zQDgPBa0LpYE2S+4M6e4i+WN2Kd9qVsYWiRslhWMrg0+ xIyJHmFr09Ash0CyTQsTafa0QY9OGLSS0SQL36tPB5E78LI0mlzwjbZA+6UeW9wJkR7mO+ OeDMb50AfrAOUBCe6WMMLaNnrkQX67s= From: Sui Jingfeng To: Bjorn Helgaas 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, Sui Jingfeng , Thomas Zimmermann , Jocelyn Falempe Subject: [RFC,drm-misc-next v4 7/9] drm/ast: Register as a VGA client by calling vga_client_register() Date: Tue, 5 Sep 2023 03:57:22 +0800 Message-Id: <20230904195724.633404-8-sui.jingfeng@linux.dev> In-Reply-To: <20230904195724.633404-1-sui.jingfeng@linux.dev> References: <20230904195724.633404-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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-pci@vger.kernel.org From: Sui Jingfeng Becasuse the display controller in the ASpeed BMC chip is a VGA-compatible device, the software programming guide of AST2400 say that it is fully IBM VGA compliant. Thus, it should also participate in the arbitration. Cc: Thomas Zimmermann Cc: Jocelyn Falempe Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/ast/ast_drv.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/gpu/drm/ast/ast_drv.c b/drivers/gpu/drm/ast/ast_drv.c index e1224ef4ad83..1349f7bb5dfb 100644 --- a/drivers/gpu/drm/ast/ast_drv.c +++ b/drivers/gpu/drm/ast/ast_drv.c @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -89,6 +90,34 @@ static const struct pci_device_id ast_pciidlist[] = { MODULE_DEVICE_TABLE(pci, ast_pciidlist); +static bool ast_want_to_be_primary(struct pci_dev *pdev) +{ + if (ast_modeset == 10) + return true; + + return false; +} + +static unsigned int ast_vga_set_decode(struct pci_dev *pdev, bool state) +{ + struct drm_device *drm = pci_get_drvdata(pdev); + struct ast_device *ast = to_ast_device(drm); + unsigned int decode; + + if (state) { + /* Enable standard VGA decode and Enable normal VGA decode */ + ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa1, 0x04); + + decode = VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM | + VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; + } else { + ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa1, 0x07); + decode = VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; + } + + return decode; +} + static int ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { struct ast_device *ast; @@ -112,6 +141,8 @@ static int ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (ret) return ret; + vga_client_register(pdev, ast_vga_set_decode, ast_want_to_be_primary); + drm_fbdev_generic_setup(dev, 32); return 0; From patchwork Mon Sep 4 19:57:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 1829739 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=GnSWs3Th; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pci-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4RffZY5XFYz1yh1 for ; Tue, 5 Sep 2023 05:58:13 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237066AbjIDT6P (ORCPT ); Mon, 4 Sep 2023 15:58:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237330AbjIDT6O (ORCPT ); Mon, 4 Sep 2023 15:58:14 -0400 Received: from out-210.mta1.migadu.com (out-210.mta1.migadu.com [95.215.58.210]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6298DE42 for ; Mon, 4 Sep 2023 12:57:54 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693857472; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F94OEAVhjRPNan81JT9jYKc/35rAAkFMKn0HnOUomvI=; b=GnSWs3Th21KoWg3GlauP3qiIOfTQOIrowoSQabwTLw+lmR60Zkz6STabaEZAnjCGxkeJj7 3JZwsA+Ed49UQWdSv8QN1222rpeBrwhEKmFkowFHEmI3Xv35ckwzuofdSFTolilLKKXFoF 0kP5vMu/6Z3tploGLiaOXmyG8Od7rYc= From: Sui Jingfeng To: Bjorn Helgaas 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, Sui Jingfeng Subject: [RFC,drm-misc-next v4 8/9] drm/hibmc: Register as a VGA client by calling vga_client_register() Date: Tue, 5 Sep 2023 03:57:23 +0800 Message-Id: <20230904195724.633404-9-sui.jingfeng@linux.dev> In-Reply-To: <20230904195724.633404-1-sui.jingfeng@linux.dev> References: <20230904195724.633404-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham 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-pci@vger.kernel.org From: Sui Jingfeng Because the display controller in the Hibmc chip is a VGA compatible display controller. Because ARM64 doesn't need the VGA console. It does not need to worry about the side effects that come with the VGA compatible. However, the real problem is that some ARM64 PCs and servers do not have good UEFI firmware support. At least, it is not as good as UEFI firmware for x86. The Huawei KunPeng 920 PC and Taishan 100 server are examples. When a discrete GPU is mounted on such machines, the UEFI firmware still selects the integrated display controller (in the BMC) as the primary GPU. It is hardcoded, no options are provided for selection. A Linux user has no control at all. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c index 8a98fa276e8a..73a3f1cb109a 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -27,6 +28,10 @@ #include "hibmc_drm_drv.h" #include "hibmc_drm_regs.h" +static int hibmc_modeset = -1; +MODULE_PARM_DESC(modeset, "Disable/Enable modesetting"); +module_param_named(modeset, hibmc_modeset, int, 0400); + DEFINE_DRM_GEM_FOPS(hibmc_fops); static irqreturn_t hibmc_interrupt(int irq, void *arg) @@ -299,6 +304,14 @@ static int hibmc_load(struct drm_device *dev) return ret; } +static bool hibmc_want_to_be_primary(struct pci_dev *pdev) +{ + if (hibmc_modeset == 10) + return true; + + return false; +} + static int hibmc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { @@ -339,6 +352,8 @@ static int hibmc_pci_probe(struct pci_dev *pdev, goto err_unload; } + vga_client_register(pdev, NULL, hibmc_want_to_be_primary); + drm_fbdev_generic_setup(dev, 32); return 0; From patchwork Mon Sep 4 19:57:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 1829741 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=MsA02426; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pci-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4RffZl2CVwz1yh1 for ; Tue, 5 Sep 2023 05:58:23 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236919AbjIDT6X (ORCPT ); Mon, 4 Sep 2023 15:58:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236870AbjIDT6W (ORCPT ); Mon, 4 Sep 2023 15:58:22 -0400 Received: from out-214.mta1.migadu.com (out-214.mta1.migadu.com [95.215.58.214]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CB64170B for ; Mon, 4 Sep 2023 12:57:56 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693857474; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fhoRcuVch+7Gf4upXx5ouxYbS2GV0Aor2KTGkzLAL+I=; b=MsA02426tkJinkpz1/CD7KSiRYKyWnFWxA5gA3o4DzZdbtVyCxWD9yLCkse2QF1pq+rwCH GgV2R6PtMuA8UlGOKYY/J4alpOdakscn17HMIelz71RXSqt63hYGHhWu34q9bHpuwiM08Z xATVnBtvw/osh/XBPWbOGOPfG3A0KXc= From: Sui Jingfeng To: Bjorn Helgaas 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, Sui Jingfeng Subject: [RFC,drm-misc-next v4 9/9] drm/gma500: Register as a VGA client by calling vga_client_register() Date: Tue, 5 Sep 2023 03:57:24 +0800 Message-Id: <20230904195724.633404-10-sui.jingfeng@linux.dev> In-Reply-To: <20230904195724.633404-1-sui.jingfeng@linux.dev> References: <20230904195724.633404-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham 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-pci@vger.kernel.org From: Sui Jingfeng Because the display controller in N2000/D2000 series can be VGA-compatible, so let's register gma500 as a VGA client, despite the firmware may alter the PCI class code of IGD on a multiple GPU co-exist configuration. But this commit no crime, because VGAARB only cares about VGA devices. Noticed that the display controller in N2000/D2000 processor don't has a valid VRAM BAR, the firmware put the EFI firmware framebuffer into the stolen memory, so the commit <86fd887b7fe3> ("vgaarb: Don't default exclusively to first video device with mem+io") is not effictive on such a case. But the benefits of the stolen memory is that it will not suffer from PCI resource relocation. Becase the stolen memory is carved out by the firmware and reside in system RAM. Therefore, while at it, provided a naive version of firmware framebuffer identification function and use the new machanism just created. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/gma500/psb_drv.c | 57 ++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/gma500/psb_drv.c b/drivers/gpu/drm/gma500/psb_drv.c index 8b64f61ffaf9..eb95d030d981 100644 --- a/drivers/gpu/drm/gma500/psb_drv.c +++ b/drivers/gpu/drm/gma500/psb_drv.c @@ -14,7 +14,7 @@ #include #include #include - +#include #include #include @@ -36,6 +36,11 @@ #include "psb_irq.h" #include "psb_reg.h" +static int gma500_modeset = -1; + +MODULE_PARM_DESC(modeset, "Disable/Enable modesetting"); +module_param_named(modeset, gma500_modeset, int, 0400); + static const struct drm_driver driver; static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent); @@ -446,6 +451,49 @@ static int gma_remove_conflicting_framebuffers(struct pci_dev *pdev, return __aperture_remove_legacy_vga_devices(pdev); } +static bool gma_contain_firmware_fb(u64 ap_start, u64 ap_end) +{ + u64 fb_start; + u64 fb_size; + u64 fb_end; + + if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE) + fb_start = (u64)screen_info.ext_lfb_base << 32 | screen_info.lfb_base; + else + fb_start = screen_info.lfb_base; + + fb_size = screen_info.lfb_size; + fb_end = fb_start + fb_size - 1; + + /* No firmware framebuffer support */ + if (!fb_start || !fb_size) + return false; + + if (fb_start >= ap_start && fb_end <= ap_end) + return true; + + return false; +} + +static bool gma_want_to_be_primary(struct pci_dev *pdev) +{ + struct drm_device *drm = pci_get_drvdata(pdev); + struct drm_psb_private *priv = to_drm_psb_private(drm); + u64 vram_base = priv->stolen_base; + u64 vram_size = priv->vram_stolen_size; + + if (gma500_modeset == 10) + return true; + + /* Stolen memory are not going to be moved */ + if (gma_contain_firmware_fb(vram_base, vram_base + vram_size)) { + drm_dbg(drm, "Contains firmware FB in the stolen memory\n"); + return true; + } + + return false; +} + static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { struct drm_psb_private *dev_priv; @@ -475,6 +523,8 @@ static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (ret) return ret; + vga_client_register(pdev, NULL, gma_want_to_be_primary); + psb_fbdev_setup(dev_priv); return 0; @@ -526,7 +576,10 @@ static struct pci_driver psb_pci_driver = { static int __init psb_init(void) { - if (drm_firmware_drivers_only()) + if (drm_firmware_drivers_only() && (gma500_modeset == -1)) + return -ENODEV; + + if (!gma500_modeset) return -ENODEV; return pci_register_driver(&psb_pci_driver);