Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2006017rwd; Fri, 9 Jun 2023 05:31:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7eWz8Mvl97yfbXzHKKUhjCr09eek7L5A5oGDz0IXPNUOOyxyLSu52ODAsCtH8RqraI8dTT X-Received: by 2002:a05:6a20:a108:b0:10a:99a9:cb4b with SMTP id q8-20020a056a20a10800b0010a99a9cb4bmr1464941pzk.12.1686313916364; Fri, 09 Jun 2023 05:31:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686313916; cv=none; d=google.com; s=arc-20160816; b=f20D/9NWdd709zELrLUPI4UAQRZql2saV8oB+e/eW8UXFL0+Yhfa4BPFrFcJnhAcsT sXZhJhl4i1teVA81Np9c8dqu9KaXH9X0zbiPPNuBncwqSE0MMWW9BPQVLc86KtB5vV8A /JGzP1tlmf+cNuUl5O2P+dmW6QCHpi1O1uOFm5kE5EDPvyL76fC6Vky2MZHWxo1DPku5 8Us2lzTkyDv8XTBvKBHahnCTedbu+1OQpaN586LEGq+Qr48jaB2oq7jDGuuGbjk1Iri7 ELunjrvo0kTYjpKA7JmkZGLFsAulFSFRHepIUKFPcHYVVTtQNwF3wtLtUJDJ1g8Kfa+3 3qMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id; bh=AMNDs11+Utb69UJFl3nThHF4C5pWDReu4JSvY0RlIpw=; b=AVqdIaOQirQrTUgLipW4FFUTsFXZmS5Q3KvXf/So9MO0HnaTbVPj72KKL52wXtoz2W snis9DPWw95H7s0+/SWuUmYyWzn77pxoJa6Ncw0EFO9ZYarKXrYl4fF2TnWr+yQpz3hS B08medh8ypH1JEFJcOMxKySHJllaIEktArAcYvk3WQV2iqVqDNY3h4TFbrS4QLiBgkSU WAp1nvDSVTTLnDl0TsXiXIdzMtu1vzI3MFaIHxvw1mA94Et/TZgzwSpBEB0yU4cO4FtS sw47/Sv03BnxKmzYqIKBNGCyg15W9VpcuL51dWXVlUMxRqLdXFo38rmKJC6gNBKnv5d9 Komg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i14-20020a633c4e000000b00543fcc59429si2734523pgn.60.2023.06.09.05.31.40; Fri, 09 Jun 2023 05:31:56 -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 S240697AbjFIMXQ (ORCPT + 99 others); Fri, 9 Jun 2023 08:23:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240535AbjFIMW6 (ORCPT ); Fri, 9 Jun 2023 08:22:58 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E8FE23AA2; Fri, 9 Jun 2023 05:22:22 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8AxEel9GYNkBRYBAA--.1313S3; Fri, 09 Jun 2023 20:22:21 +0800 (CST) Received: from [10.20.42.43] (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxReR6GYNkDyELAA--.33801S3; Fri, 09 Jun 2023 20:22:18 +0800 (CST) Message-ID: <8e7fe36d-0d0d-bab4-9ace-a738d7a48111@loongson.cn> Date: Fri, 9 Jun 2023 20:22:18 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [Intel-gfx] [PATCH v3 3/4] PCI/VGA: only deal with VGA class devices To: Bjorn Helgaas , Sui Jingfeng <15330273260@189.cn> Cc: 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 , Jason Gunthorpe , Kevin Tian , Cornelia Huck , Yishai Hadas , Abhishek Sahu , Yi Liu , kvm@vger.kernel.org, nouveau@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn, amd-gfx@lists.freedesktop.org, linux-pci@vger.kernel.org References: <20230608191221.GA1209912@bhelgaas> Content-Language: en-US From: Sui Jingfeng Organization: Loongson In-Reply-To: <20230608191221.GA1209912@bhelgaas> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8CxReR6GYNkDyELAA--.33801S3 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBj93XoWxtFyUWw4rAr48JFykGFykZwc_yoW7ZF4Dpa yrGayfKrWkWF17Cryav3WUZFy5u39Yya4fKr4Ykw1YkanxCryFqFyrKrW5A3W7JrZrGF10 vFWUt3W7Wa1qqagCm3ZEXasCq-sJn29KB7ZKAUJUUUUd529EdanIXcx71UUUUU7KY7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XT_LINE 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-kernel@vger.kernel.org Hi, On 2023/6/9 03:12, Bjorn Helgaas wrote: > Start with verb and capitalize to match ("Deal only with ...") > > On Thu, Jun 08, 2023 at 07:43:21PM +0800, Sui Jingfeng wrote: >> From: Sui Jingfeng >> >> vgaarb only deal with the VGA devcie(pdev->class == 0x0300), so replace the >> pci_get_subsys() function with pci_get_class(). Filter the non pci display >> device out. There no need to process the non display PCI device. > s/non pci/non-PCI/ > s/non display/non-display/ > > This is fine, and I'll merge this, but someday I would like to get rid > of the bus_register_notifier() and call vga_arbiter_add_pci_device() > and vga_arbiter_del_pci_device() directly from the PCI core. Nice idea! But I'm wondering there are traps in this. The pci_notifier in vgaarb.c is still need on Mips platform. Because of loading order problems. On MIPS system, PCI devices are enumerated by pcibios_init(), which runs after vga_arb_device_init(). This is true until now. When vga_arb_device_init() function get called, it will capture nothing. On that time, the system have no PCI device enumerated. Because of this, there are various problems in the past. This is the reason we still need the notifier, we need a way to capture the PCI display device after vgaarb already loaded(finished). On complex case, there are ASpeed BMC, loongson integrated display controller, and radeon discrete video card co-exist on Loongson 3B4000 server. I have fixed various bug at our downstream(linux-4.19) environment. I have fixed a bug on downstream involved with aspeed bmc, by workaround[1]. Chen Huacai grabbing my patch[1] and rewrite it, submit together with him-self's. Its fine,  but those patch still look paleness in the front of Loongson integrated display controller. Loongson integrated display controller don't has a dedicated VRAM bar. vga_is_firmware_default() will lose its effectiveness then. This is the reason we reveal our patch(0004 in this series) to face upstream. Its not only for loongson integrated display controller through. Its not uncommon that ARM servers have A aspeed BMC and discrete amdgpu or old radeon card. Let the device drivers gave us a hint probably can help to resolve multi-video card co-exist problem. Consider that sometime user want to use integrate gpu, sometime user want to use discrete gpu. Also, during driver developing(or debugging), driver writer may want override the default boot device. vgaarb probable shouldn't make the decision without giving the device driver a chance to override. Beside,  vga_is_firmware_default() only apply for PCI display device. On ARM64 system, there are a lot of platform device. If we move this function back to the device driver, it probably applicable for a platform display controller + one/two PCI display devices case. We find a method at downstream during we get efifb works LoongArch platform. We can utilize the screen_info, screen_info say where's the firmware framebuffer is located at. Drivers for specific hardware platform perhaps know more clearly than vgaarb. if it is the default boot device. [1] https://lore.kernel.org/all/20210514080025.1828197-6-chenhuacai@loongson.cn/ > Or if you wanted to do that now, that would be even better :) > > Bjorn > >> Signed-off-by: Sui Jingfeng >> --- >> drivers/pci/vgaarb.c | 22 ++++++++++++---------- >> 1 file changed, 12 insertions(+), 10 deletions(-) >> >> diff --git a/drivers/pci/vgaarb.c b/drivers/pci/vgaarb.c >> index 7f0347f4f6fd..b0bf4952a95d 100644 >> --- a/drivers/pci/vgaarb.c >> +++ b/drivers/pci/vgaarb.c >> @@ -756,10 +756,6 @@ static bool vga_arbiter_add_pci_device(struct pci_dev *pdev) >> struct pci_dev *bridge; >> u16 cmd; >> >> - /* Only deal with VGA class devices */ >> - if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA) >> - return false; >> - >> /* Allocate structure */ >> vgadev = kzalloc(sizeof(struct vga_device), GFP_KERNEL); >> if (vgadev == NULL) { >> @@ -1499,7 +1495,9 @@ static int pci_notify(struct notifier_block *nb, unsigned long action, >> struct pci_dev *pdev = to_pci_dev(dev); >> bool notify = false; >> >> - vgaarb_dbg(dev, "%s\n", __func__); >> + /* Only deal with VGA class devices */ >> + if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA) >> + return 0; >> >> /* 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 >> @@ -1509,6 +1507,8 @@ static int pci_notify(struct notifier_block *nb, unsigned long action, >> else if (action == BUS_NOTIFY_DEL_DEVICE) >> notify = vga_arbiter_del_pci_device(pdev); >> >> + vgaarb_dbg(dev, "%s: action = %lu\n", __func__, action); >> + >> if (notify) >> vga_arbiter_notify_clients(); >> return 0; >> @@ -1533,8 +1533,8 @@ static struct miscdevice vga_arb_device = { >> >> static int __init vga_arb_device_init(void) >> { >> + struct pci_dev *pdev = NULL; >> int rc; >> - struct pci_dev *pdev; >> >> rc = misc_register(&vga_arb_device); >> if (rc < 0) >> @@ -1545,11 +1545,13 @@ static int __init vga_arb_device_init(void) >> /* We add all PCI devices satisfying VGA class in the arbiter by >> * default >> */ >> - pdev = NULL; >> - while ((pdev = >> - pci_get_subsys(PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, >> - PCI_ANY_ID, pdev)) != NULL) >> + while (1) { >> + pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev); >> + if (!pdev) >> + break; >> + >> vga_arbiter_add_pci_device(pdev); >> + }; >> >> pr_info("loaded\n"); >> return rc; >> -- >> 2.25.1 >> -- Jingfeng