Message ID | 20230711164310.791756-4-sui.jingfeng@linux.dev |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp627860vqm; Tue, 11 Jul 2023 10:07:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlFczFWFKdkvEVcNvZmYCB7TfiT13rBOp+dnhrfVWGwIxmEB79moA4ULIbbw+ICo7SVkb5oI X-Received: by 2002:a17:902:c212:b0:1b8:5bb4:8230 with SMTP id 18-20020a170902c21200b001b85bb48230mr12253972pll.50.1689095245695; Tue, 11 Jul 2023 10:07:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689095245; cv=none; d=google.com; s=arc-20160816; b=yWw7YlAJ+cbldEx0LswYRXe+obSXDf6Dy9ZQmiwVjnbnhKgRn55cNsttDAEdZnqxoy 2P9eeKhFsBRIGWnigQC7cArUOBVsT0O7hdA4kkO4g5fawrAD02acds0lJKmFJuBPptBV yFzUQztCqCZgdtVEgS5iBrAI/wbd4t4te1ZXoBY2XvPmyToTQJMjd8MjQ/4h1RYd3i5z BPQWTcTPMBdQa4GzD98empxh13WUwycQiv75n4YQoJtwWyc3j/YSmJRezfQgaSZCGMEJ itykVYB6U5uUTlU+rwvPGV4qAfvvmmlgDVJafRPDZ06LHPnLkMbK64+5auBwXK9XIbx8 CTjA== 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 :dkim-signature; bh=qerYEjJsYQa89wBNUybGoMjyzLMs27H7zUPn+Dcw/G0=; fh=ygkTXrv1QW2aJHL5AkX1nEAGd3njUqmECwhnenyY9Ag=; b=dBkgS8GAViilUnLc4UUYaCDQyY+TpLaeWu4f3GWY3ffhVNa18/HosiK5ZqACbWmQj+ I/6lKLpHBilhYdYA90ZPFD/yCEKd/WzS4wicxZNb+KF3OYqsEeRO40+BpqBiePvED0FI KfoVj24TQlIiLRoZFVluzpWS1DAOaQHoDxuTaNqT1wjGANn19vlhi4LKJ7MDKwtWZbQA /oqVwRVb/l6qEEo/3Nw29z4gLGDOJ9iozXkBY4jCvowfIBemKPMyaqy6pBD2tPnzpYnV 1aKOB82hIrdrGkT2Rcn5Ib1xTQ8xp3NaeQ7WDkdKIIrZoeE/cqjXrrlKZ9kDzpyOaS+N 80Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=cLX+YcBR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p1-20020a170902c70100b001b89bfd0c34si1778731plp.18.2023.07.11.10.07.10; Tue, 11 Jul 2023 10:07:25 -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; dkim=pass header.i=@linux.dev header.s=key1 header.b=cLX+YcBR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233025AbjGKQnv (ORCPT <rfc822;gnulinuxfreebsd@gmail.com> + 99 others); Tue, 11 Jul 2023 12:43:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233074AbjGKQnl (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 11 Jul 2023 12:43:41 -0400 Received: from out-41.mta1.migadu.com (out-41.mta1.migadu.com [IPv6:2001:41d0:203:375::29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B90510D5 for <linux-kernel@vger.kernel.org>; Tue, 11 Jul 2023 09:43:35 -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=1689093812; 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=qerYEjJsYQa89wBNUybGoMjyzLMs27H7zUPn+Dcw/G0=; b=cLX+YcBRiHpKikMeKMwG3mmNyBOCt0RfzhMRCQMFVMsE5PUvN0MMXatH5virGuBPf1bPzP TlrzyZr2xWSz6KpDcpt68BaSDQcRrPHi91BQyPlN45VH8b+lOC+BzDNGujXDPizGjou5oq GspWd6OWyS+7lx+YxAilLOZFQYnLH5E= From: Sui Jingfeng <sui.jingfeng@linux.dev> To: David Airlie <airlied@gmail.com> Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, kvm@vger.kernel.org, linux-fbdev@vger.kernel.org, Sui Jingfeng <suijingfeng@loongson.cn> Subject: [PATCH v3 3/9] PCI/VGA: Switch to aperture_contain_firmware_fb_nonreloc() Date: Wed, 12 Jul 2023 00:43:04 +0800 Message-Id: <20230711164310.791756-4-sui.jingfeng@linux.dev> In-Reply-To: <20230711164310.791756-1-sui.jingfeng@linux.dev> References: <20230711164310.791756-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771144736121779250 X-GMAIL-MSGID: 1771144736121779250 |
Series |
PCI/VGA: Improve the default VGA device selection
|
|
Commit Message
Sui Jingfeng
July 11, 2023, 4:43 p.m. UTC
From: Sui Jingfeng <suijingfeng@loongson.cn> The observation behind this is that we should avoid accessing the global screen_info directly. Call the aperture_contain_firmware_fb_nonreloc() function to implement the detection of whether an aperture contains the firmware FB. This patch helps to decouple the determination from the implementation. Or, in other words, we intend to make the determination opaque to the caller. The determination may choose to be arch-dependent or arch-independent. But vgaarb, as a consumer of the determination, shouldn't care how the does determination is implemented. Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> --- drivers/pci/vgaarb.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-)
Comments
[+cc linux-pci; I don't apply or ack PCI patches unless they appear there] On Wed, Jul 12, 2023 at 12:43:04AM +0800, Sui Jingfeng wrote: > From: Sui Jingfeng <suijingfeng@loongson.cn> > > The observation behind this is that we should avoid accessing the global > screen_info directly. Call the aperture_contain_firmware_fb_nonreloc() > function to implement the detection of whether an aperture contains the > firmware FB. Because it's better to access the global screen_info from aperture_contain_firmware_fb_nonreloc()? The reasoning here is not super clear to me. > This patch helps to decouple the determination from the implementation. > Or, in other words, we intend to make the determination opaque to the > caller. The determination may choose to be arch-dependent or > arch-independent. But vgaarb, as a consumer of the determination, > shouldn't care how the does determination is implemented. "how the determination ..." (drop the "does") Are you saying that aperture_contain_firmware_fb_nonreloc() might be arch-dependent? Are there multiple callers? Or does this just move code from one place to a more appropriate place? > Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> > --- > drivers/pci/vgaarb.c | 19 ++++--------------- > 1 file changed, 4 insertions(+), 15 deletions(-) > > diff --git a/drivers/pci/vgaarb.c b/drivers/pci/vgaarb.c > index bf96e085751d..953daf731b2c 100644 > --- a/drivers/pci/vgaarb.c > +++ b/drivers/pci/vgaarb.c > @@ -14,6 +14,7 @@ > #define vgaarb_info(dev, fmt, arg...) dev_info(dev, "vgaarb: " fmt, ##arg) > #define vgaarb_err(dev, fmt, arg...) dev_err(dev, "vgaarb: " fmt, ##arg) > > +#include <linux/aperture.h> > #include <linux/module.h> > #include <linux/kernel.h> > #include <linux/pci.h> > @@ -26,7 +27,6 @@ > #include <linux/poll.h> > #include <linux/miscdevice.h> > #include <linux/slab.h> > -#include <linux/screen_info.h> > #include <linux/vt.h> > #include <linux/console.h> > #include <linux/acpi.h> > @@ -558,20 +558,11 @@ void vga_put(struct pci_dev *pdev, unsigned int rsrc) > } > EXPORT_SYMBOL(vga_put); > > +/* Select the device owning the boot framebuffer if there is one */ > static bool vga_is_firmware_default(struct pci_dev *pdev) > { > #if defined(CONFIG_X86) || defined(CONFIG_IA64) > - u64 base = screen_info.lfb_base; > - u64 size = screen_info.lfb_size; > struct resource *r; > - u64 limit; > - > - /* 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; > > /* Does firmware framebuffer belong to us? */ > pci_dev_for_each_resource(pdev, r) { > @@ -581,10 +572,8 @@ static bool vga_is_firmware_default(struct pci_dev *pdev) > if (!r->start || !r->end) > continue; > > - if (base < r->start || limit >= r->end) > - continue; > - > - return true; > + if (aperture_contain_firmware_fb_nonreloc(r->start, r->end)) > + return true; > } > #endif > return false; > -- > 2.25.1 >
Hi, On 2023/7/20 04:43, Bjorn Helgaas wrote: > [+cc linux-pci; I don't apply or ack PCI patches unless they appear there] > > On Wed, Jul 12, 2023 at 12:43:04AM +0800, Sui Jingfeng wrote: >> From: Sui Jingfeng <suijingfeng@loongson.cn> >> >> The observation behind this is that we should avoid accessing the global >> screen_info directly. Call the aperture_contain_firmware_fb_nonreloc() >> function to implement the detection of whether an aperture contains the >> firmware FB. > Because it's better to access the global screen_info from > aperture_contain_firmware_fb_nonreloc()? The reasoning here is not > super clear to me. Yes, honestly the benefits of this patch is not obvious. But I do have some (may not practical) ideas in my mind when I create this patch. See my explanation at the end. >> This patch helps to decouple the determination from the implementation. >> Or, in other words, we intend to make the determination opaque to the >> caller. The determination may choose to be arch-dependent or >> arch-independent. But vgaarb, as a consumer of the determination, >> shouldn't care how the does determination is implemented. > "how the determination ..." (drop the "does") Ok, will be fixed at the next version. > > Are you saying that aperture_contain_firmware_fb_nonreloc() might be > arch-dependent? Are there multiple callers? Or does this just move > code from one place to a more appropriate place? 1) To form a unify approach, and drop the screen_info.h header. There are similar cleanup patch at patchwork. screen_info.h is definitely arch-dependent, while vgaarb is just device-dependent. I think, they do have subtle difference. 2) Convert the *device driven* to the "driver driven". Move it from vgaarb.c to video/apperture allow code sharing. While this function are not going to be shared in vgaarb. Previous it is the device make the decision, after applied this patch it allow driver make the decision. They do have subtle difference. Emm, I will try to give some examples at the next version. 3) I was imagine to drag platform display controllers in (get platform devices involved in the arbitration). As Alex seem hint to implement something platform-independent. The aperture_contain_firmware_fb_nonreloc() actually is possible be shared. The aperture of platform device will be not moved. So it seems that platform device driver could call this function to do something else. >> Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> >> --- >> drivers/pci/vgaarb.c | 19 ++++--------------- >> 1 file changed, 4 insertions(+), 15 deletions(-) >> >> diff --git a/drivers/pci/vgaarb.c b/drivers/pci/vgaarb.c >> index bf96e085751d..953daf731b2c 100644 >> --- a/drivers/pci/vgaarb.c >> +++ b/drivers/pci/vgaarb.c >> @@ -14,6 +14,7 @@ >> #define vgaarb_info(dev, fmt, arg...) dev_info(dev, "vgaarb: " fmt, ##arg) >> #define vgaarb_err(dev, fmt, arg...) dev_err(dev, "vgaarb: " fmt, ##arg) >> >> +#include <linux/aperture.h> >> #include <linux/module.h> >> #include <linux/kernel.h> >> #include <linux/pci.h> >> @@ -26,7 +27,6 @@ >> #include <linux/poll.h> >> #include <linux/miscdevice.h> >> #include <linux/slab.h> >> -#include <linux/screen_info.h> >> #include <linux/vt.h> >> #include <linux/console.h> >> #include <linux/acpi.h> >> @@ -558,20 +558,11 @@ void vga_put(struct pci_dev *pdev, unsigned int rsrc) >> } >> EXPORT_SYMBOL(vga_put); >> >> +/* Select the device owning the boot framebuffer if there is one */ >> static bool vga_is_firmware_default(struct pci_dev *pdev) >> { >> #if defined(CONFIG_X86) || defined(CONFIG_IA64) >> - u64 base = screen_info.lfb_base; >> - u64 size = screen_info.lfb_size; >> struct resource *r; >> - u64 limit; >> - >> - /* 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; >> >> /* Does firmware framebuffer belong to us? */ >> pci_dev_for_each_resource(pdev, r) { >> @@ -581,10 +572,8 @@ static bool vga_is_firmware_default(struct pci_dev *pdev) >> if (!r->start || !r->end) >> continue; >> >> - if (base < r->start || limit >= r->end) >> - continue; >> - >> - return true; >> + if (aperture_contain_firmware_fb_nonreloc(r->start, r->end)) >> + return true; >> } >> #endif >> return false; >> -- >> 2.25.1 >>
diff --git a/drivers/pci/vgaarb.c b/drivers/pci/vgaarb.c index bf96e085751d..953daf731b2c 100644 --- a/drivers/pci/vgaarb.c +++ b/drivers/pci/vgaarb.c @@ -14,6 +14,7 @@ #define vgaarb_info(dev, fmt, arg...) dev_info(dev, "vgaarb: " fmt, ##arg) #define vgaarb_err(dev, fmt, arg...) dev_err(dev, "vgaarb: " fmt, ##arg) +#include <linux/aperture.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/pci.h> @@ -26,7 +27,6 @@ #include <linux/poll.h> #include <linux/miscdevice.h> #include <linux/slab.h> -#include <linux/screen_info.h> #include <linux/vt.h> #include <linux/console.h> #include <linux/acpi.h> @@ -558,20 +558,11 @@ void vga_put(struct pci_dev *pdev, unsigned int rsrc) } EXPORT_SYMBOL(vga_put); +/* Select the device owning the boot framebuffer if there is one */ static bool vga_is_firmware_default(struct pci_dev *pdev) { #if defined(CONFIG_X86) || defined(CONFIG_IA64) - u64 base = screen_info.lfb_base; - u64 size = screen_info.lfb_size; struct resource *r; - u64 limit; - - /* 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; /* Does firmware framebuffer belong to us? */ pci_dev_for_each_resource(pdev, r) { @@ -581,10 +572,8 @@ static bool vga_is_firmware_default(struct pci_dev *pdev) if (!r->start || !r->end) continue; - if (base < r->start || limit >= r->end) - continue; - - return true; + if (aperture_contain_firmware_fb_nonreloc(r->start, r->end)) + return true; } #endif return false;