Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3993479pxb; Tue, 25 Jan 2022 00:55:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJxs730s8Ekd9FIXC7+GV0ckwFUllfuojHzvCnObCaK8ZbptfbIWKrpMzJ7zooHiTvKK2eyo X-Received: by 2002:a05:6402:175c:: with SMTP id v28mr19204342edx.279.1643100937735; Tue, 25 Jan 2022 00:55:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643100937; cv=none; d=google.com; s=arc-20160816; b=As3oe7H7Fl5ZfYPat37biEQZkzzabM7RsNFhG2DE/5rnfKteFRjT8D5aXIDV549FC+ AfrxAp3ZlH3bmGY0arxOvWt27O0LmJCZvK+WyA1ymHoYCoYs1mK55uxHExpwsUP4rGCJ NUjBN73vwpHgQYVD2II1MKCbWgMGXXRiFKxqUUYMKiKu4n5WLE6zvCRkcTDpuszwjdvb Mok/EzMOcZk8AaOCbOupnuJnjL9sP/QNxPFOHW8ZFFA2HwPQbP0oiCDvFZisjkAX9ajF PbuMCuIGZDfhIQkCHnWa4PzZB2YXaPmIWPybbh1JVVxYTDOhz7qwK9NmEVyEOWjUQLiW CjDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=P6LscLp3E2WiwXwgZ3WD+U4l8G1jH7CQCRwujnNFTjc=; b=YgSezx38A52hLuOeW9urRwjwbBT8gGsmiCXK4pbx7m61+WgHEssebI82RAUsdeX/7I bpcs5vD4FJe3F1Hb51iY0Aot4nQfv5BJ+3fNfZQMfFGOF9PnqrWhSSORML7sjj+7tTII 8bgwOWj4QuPQjAxq6dGenKmOXRRORU0Z+XScUurnyDxO0HGOYIc3/c3qrhP1DJ/q7GDA ViBeCnweskTSl2K0g5G0revKuz4nz2rd8Vfbuha+Ik/8z7dhlICJJi+J84b1iBHL7UvK o7ux9wY2Eha6tkllt2t6x0q/7y2NEmT9F7ahwZ1GKT37M+uA6Ofsy8S0/vKxLKPIl80z M/eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=C6roxTp7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o1si9814055edf.363.2022.01.25.00.55.13; Tue, 25 Jan 2022 00:55:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=C6roxTp7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1390450AbiAYEuC (ORCPT + 99 others); Mon, 24 Jan 2022 23:50:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S251072AbiAYEU1 (ORCPT ); Mon, 24 Jan 2022 23:20:27 -0500 Received: from mail-ua1-x933.google.com (mail-ua1-x933.google.com [IPv6:2607:f8b0:4864:20::933]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97EB7C061747; Mon, 24 Jan 2022 18:51:21 -0800 (PST) Received: by mail-ua1-x933.google.com with SMTP id b16so34851796uaq.4; Mon, 24 Jan 2022 18:51:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=P6LscLp3E2WiwXwgZ3WD+U4l8G1jH7CQCRwujnNFTjc=; b=C6roxTp7cIEMMOzhn5NzBDFNFNYpPNPbj+Bmw5Wm5qzD+W1emZSbnLEbF/eoHGn3hj yOeZEeKK0g45s2eepfhK/i3TjW/9/jtvnxRvUVYnIJA5fDWOoQrDFmq+nmYxCD5w68xd L/TvsEImBtY658ga1Pocieu6WwJNP5Gd0hG44lkGY9pgvKfzADfp/DIqyiJWZ2J4uK38 v6vqAWmwxzWJ+ITi/XOK3DcQ8mTIzOOtKk8xD0EB/mIaP0a3KJ3T60Gr76ojmyQ9mxES Pwu/4XbBMcuFH/oDj7sA0VO+r/XLoUM87AOPuYHSQiALZsyDD1ZCwD4+LGlrZz1ZY0jh 1nAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=P6LscLp3E2WiwXwgZ3WD+U4l8G1jH7CQCRwujnNFTjc=; b=cB82EcZ7xmlIUITyhudMVKb03D7DPp8oapAzKDa93eI97YCyvYD3+jrccfUPUEcXZG y2GwWUWhjmeRShphHcT31f6kPzxRII3gbC8mLUJZewatSYbjWjeVlWSjGXqivItFp0FC +jx3iLrCCN5w9YXS9JbamqxmxqTy1e2esrKuaMBIQY3FCqRTFBAW8Xr57Jp/jkrIc/rS kl42UgN+mxkLjuaGOUDs1FR1GroGfZinZHIBPeUq4dSfuHLRr+0/GjJCzXS7xmhB3eT6 7siWjTpw6wC4yj5QDbag8zTJfzp6yCw69gO3FZxu04aIbtZtCp9dPAJWu7eInr1DORKU jlNQ== X-Gm-Message-State: AOAM531UbvCKqXwujFhCZrwGtjyVnH4Qlh6xn2E8lAMtYZts7pr4/Kv/ GFAtfLIbugOjJyuZwhSIuT23PH9fPE5DmIkq4Rg= X-Received: by 2002:a67:b807:: with SMTP id i7mr6423171vsf.52.1643079080652; Mon, 24 Jan 2022 18:51:20 -0800 (PST) MIME-Version: 1.0 References: <20220106162058.GA284940@bhelgaas> In-Reply-To: <20220106162058.GA284940@bhelgaas> From: Huacai Chen Date: Tue, 25 Jan 2022 10:51:15 +0800 Message-ID: Subject: Re: [PATCH v8 04/10] vgaarb: Move framebuffer detection to ADD_DEVICE path To: Bjorn Helgaas Cc: David Airlie , Daniel Vetter , Xuefeng Li , Huacai Chen , linux-pci , Maling list - DRI developers , LKML , Bjorn Helgaas , =?UTF-8?Q?Bruno_Pr=C3=A9mont?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Bjorn, Why this series still missing in 5.17-rc1? :( Huacai On Fri, Jan 7, 2022 at 12:21 AM Bjorn Helgaas wrote: > > On Thu, Jan 06, 2022 at 02:44:42PM +0800, Huacai Chen wrote: > > On Thu, Jan 6, 2022 at 8:07 AM Bjorn Helgaas wrote= : > > > Previously we selected a device that owns the boot framebuffer as the > > > default device in vga_arb_select_default_device(). This was only don= e in > > > the vga_arb_device_init() subsys_initcall, so devices enumerated late= r, > > > e.g., by pcibios_init(), were not eligible. > > > > > > Fix this by moving the framebuffer device selection from > > > vga_arb_select_default_device() to vga_arbiter_add_pci_device(), whic= h is > > > called after every PCI device is enumerated, either by the > > > vga_arb_device_init() subsys_initcall or as an ADD_DEVICE notifier. > > > > > > Note that if vga_arb_select_default_device() found a device owning th= e boot > > > framebuffer, it unconditionally set it to be the default VGA device, = and no > > > subsequent device could replace it. > > > > > > Link: https://lore.kernel.org/r/20211015061512.2941859-7-chenhuacai@l= oongson.cn > > > Based-on-patch-by: Huacai Chen > > > Signed-off-by: Bjorn Helgaas > > > Cc: Bruno Pr=C3=A9mont > > > --- > > > drivers/gpu/vga/vgaarb.c | 37 +++++++++++++++++-------------------- > > > 1 file changed, 17 insertions(+), 20 deletions(-) > > > > > > diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c > > > index b0ae0f177c6f..aefa4f406f7d 100644 > > > --- a/drivers/gpu/vga/vgaarb.c > > > +++ b/drivers/gpu/vga/vgaarb.c > > > @@ -72,6 +72,7 @@ struct vga_device { > > > unsigned int io_norm_cnt; /* normal IO count */ > > > unsigned int mem_norm_cnt; /* normal MEM count */ > > > bool bridge_has_one_vga; > > > + bool is_framebuffer; /* BAR covers firmware framebuffer */ > > > unsigned int (*set_decode)(struct pci_dev *pdev, bool decode)= ; > > > }; > > > > > > @@ -565,10 +566,9 @@ void vga_put(struct pci_dev *pdev, unsigned int = rsrc) > > > } > > > EXPORT_SYMBOL(vga_put); > > > > > > -static void __init vga_select_framebuffer_device(struct pci_dev *pde= v) > > > +static bool vga_is_framebuffer_device(struct pci_dev *pdev) > > > { > > > #if defined(CONFIG_X86) || defined(CONFIG_IA64) > > > - struct device *dev =3D &pdev->dev; > > > u64 base =3D screen_info.lfb_base; > > > u64 size =3D screen_info.lfb_size; > > > u64 limit; > > > @@ -583,15 +583,6 @@ static void __init vga_select_framebuffer_device= (struct pci_dev *pdev) > > > > > > limit =3D base + size; > > > > > > - /* > > > - * Override vga_arbiter_add_pci_device()'s I/O based detectio= n > > > - * as it may take the wrong device (e.g. on Apple system unde= r > > > - * EFI). > > > - * > > > - * Select the device owning the boot framebuffer if there is > > > - * one. > > > - */ > > > - > > > /* Does firmware framebuffer belong to us? */ > > > for (i =3D 0; i < DEVICE_COUNT_RESOURCE; i++) { > > > flags =3D pci_resource_flags(pdev, i); > > > @@ -608,13 +599,10 @@ static void __init vga_select_framebuffer_devic= e(struct pci_dev *pdev) > > > if (base < start || limit >=3D end) > > > continue; > > > > > > - if (!vga_default_device()) > > > - vgaarb_info(dev, "setting as boot device\n"); > > > - else if (pdev !=3D vga_default_device()) > > > - vgaarb_info(dev, "overriding boot device\n"); > > > - vga_set_default_device(pdev); > > > + return true; > > > } > > > #endif > > > + return false; > > > } > > > > > > static bool vga_arb_integrated_gpu(struct device *dev) > > > @@ -635,6 +623,7 @@ static bool vga_arb_integrated_gpu(struct device = *dev) > > > static bool vga_is_boot_device(struct vga_device *vgadev) > > > { > > > struct vga_device *boot_vga =3D vgadev_find(vga_default_devic= e()); > > > + struct pci_dev *pdev =3D vgadev->pdev; > > > > > > /* > > > * We select the default VGA device in this order: > > > @@ -645,6 +634,18 @@ static bool vga_is_boot_device(struct vga_device= *vgadev) > > > * Other device (see vga_arb_select_default_device()) > > > */ > > > > > > + /* > > > + * We always prefer a firmware framebuffer, so if we've alrea= dy > > > + * found one, there's no need to consider vgadev. > > > + */ > > > + if (boot_vga && boot_vga->is_framebuffer) > > > + return false; > > > + > > > + if (vga_is_framebuffer_device(pdev)) { > > > + vgadev->is_framebuffer =3D true; > > > + return true; > > > + } > > Maybe it is better to rename vga_is_framebuffer_device() to > > vga_is_firmware_device() and rename is_framebuffer to > > is_fw_framebuffer? > > That's a great point, thanks! > > The "framebuffer" term is way too generic. *All* VGA devices have a > framebuffer, so it adds no information. This is really about finding > the device that was used by firmware. > > I renamed: > > vga_is_framebuffer_device() -> vga_is_firmware_default() > vga_device.is_framebuffer -> vga_device.is_firmware_default > > I updated my local branch and pushed it to: > https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git/log/?h=3D= pci/vga > with head 0f4caffa1297 ("vgaarb: Replace full MIT license text with > SPDX identifier"). > > I don't maintain drivers/gpu/vga/vgaarb.c, so this branch is just for > reference. It'll ultimately be up to the DRM folks to handle this. > > I'll wait for any other comments or testing reports before reposting. > > > > /* > > > * A legacy VGA device has MEM and IO enabled and any bridges > > > * leading to it have PCI_BRIDGE_CTL_VGA enabled so the legac= y > > > @@ -1531,10 +1532,6 @@ static void __init vga_arb_select_default_devi= ce(void) > > > struct pci_dev *pdev, *found =3D NULL; > > > struct vga_device *vgadev; > > > > > > - list_for_each_entry(vgadev, &vga_list, list) { > > > - vga_select_framebuffer_device(vgadev->pdev); > > > - } > > > - > > > if (!vga_default_device()) { > > > list_for_each_entry_reverse(vgadev, &vga_list, list) = { > > > struct device *dev =3D &vgadev->pdev->dev; > > > -- > > > 2.25.1 > > >