Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1364223rdb; Fri, 1 Dec 2023 14:27:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXthkMRu1o33h1/czkdrqyGoQ0vyIudpmEHloWRWhuh/ExFfdoTs6UVNyxIsXa4QlvpFyf X-Received: by 2002:a17:902:bf09:b0:1cf:fca9:80b3 with SMTP id bi9-20020a170902bf0900b001cffca980b3mr216992plb.33.1701469657839; Fri, 01 Dec 2023 14:27:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701469657; cv=none; d=google.com; s=arc-20160816; b=bhJKpRw2ljEjaoZTHMdxal/C9idFM5wZJnUT8M+Ygf54BPduaumx2xnwrm2A+c0M3B 5HYEzyMP3X8M9acV27lNq0cmaigoxrLKMM45Q+2Wabuc7f7N5UDWdv64+NPju/2VohBI KkikgeBK1v7YDFmwHwz2fnGCxh7U53OiBlr2nkzWzLzUJj5bgF7XFXSEU6ABc0jI3IJr dFrXqvhbxFw+I5WOVC3TJeTlrZxV+RnYIJwdevfh3Gq92POhfP8eNXzjiObRIEi1P1Kf Kh9fllgtrtDww9FWxXG2SvFPUoIHZfSshK3eU0PWNENfhL1Bon5GL9H9zhnPxKLgUWwk D/gg== 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=N6g1UpLrQZauX9GAeXjRhhQNaLfznfOwHxbXM89ERvk=; fh=dKD0V+qARsvbtedAJivV5fCwUL1NkvPJzUfFW07lA2k=; b=gHucrJaruOExgeIdSJx6foOuC7TXveHVL3GKI36eil+RGNYORDwoRpUN+9hPGow3zH oIByLIIfSJoVDMwl3pqE8jsfxScIigbnpRTXwzbGyVLxpRS0AuavYa371tL0ckGqbZr9 /VDxOrdAE8cJJ9Fm9jHt4nVO5bfd4KTWx9XVKzzu92KrPuM2Iji0TmAMPl7dzapvS8Vk f11BRpw29y05orQMjCrGVi7DWlfhlkrzAnCshKv3H1ryC9UXPUjGOFMgZMu6K6pxqBx7 LiHDutdFO7XUhitEITLbqXrtvr/C4IJDc/DMZ7neBVBr/u6t65pfIRN8CBwDL8cLQ1k/ 989w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mzYWVxI0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id k10-20020a170902d58a00b001cf91d42939si4031514plh.443.2023.12.01.14.27.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 14:27:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mzYWVxI0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 2D83A85CAAA0; Fri, 1 Dec 2023 14:27:35 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231181AbjLAW1V (ORCPT + 99 others); Fri, 1 Dec 2023 17:27:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229597AbjLAW1R (ORCPT ); Fri, 1 Dec 2023 17:27:17 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D33021BE8 for ; Fri, 1 Dec 2023 14:26:59 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06812C433CA; Fri, 1 Dec 2023 22:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701469619; bh=sXzWevrTmFEZUP1GjYu+eWjRhWPfbGw0G7P/NwqYxcs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=mzYWVxI02WJPUypFGMvBAIJHVKWjsofkMH50162ajTM4uoW48JXcJqUqqzKRZh4Od X0W3naiHw5TIbIMjzygGx9kCbP/xMb/7AovCGqL5i7fjRnlycfrrJgPQ44gmXMoAEH OzfVShXaeA1WvbNcVulxbjrfm6pZW+ry4/rN9SNSCGj0mVNRcdwXXn+AiAqm3fHKMa W2h9G4elUNMuR8XNU6drZG0b3ApuwvEU3I4tzC32fssfYvba0ujWxSg+VeDTNBXKbn Jk+pfIgVWLKG5ZIMZxFuimK2ruad9L/IYdn+e+Htypiwv8qmcmRvmrdsnb+gMYxMQ6 JSCB8kBJ8yiCw== Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-50abbb23122so3788612e87.3; Fri, 01 Dec 2023 14:26:58 -0800 (PST) X-Gm-Message-State: AOJu0YxWq7CpgEK/5FX1rDPjqQbJ/3ErlPIdN5tw2zFsAAIv6NXH1GV4 g9zZXrae7MczU7/2IPlvjUBGYlu6o8CV4XQwDQ== X-Received: by 2002:a05:6512:203b:b0:50b:d1af:8ce6 with SMTP id s27-20020a056512203b00b0050bd1af8ce6mr1096529lfs.60.1701469617211; Fri, 01 Dec 2023 14:26:57 -0800 (PST) MIME-Version: 1.0 References: <20231130165700.685764-1-herve.codina@bootlin.com> In-Reply-To: <20231130165700.685764-1-herve.codina@bootlin.com> From: Rob Herring Date: Fri, 1 Dec 2023 16:26:45 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 0/2] Attach DT nodes to existing PCI devices To: Herve Codina Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Bjorn Helgaas , Lizhi Hou , Max Zhen , Sonal Santan , Stefano Stabellini , Jonathan Cameron , "linux-kernel@vger.kernel.org" , PCI , Allan Nielsen , Horatiu Vultur , Steen Hegelund , Thomas Petazzoni Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 01 Dec 2023 14:27:35 -0800 (PST) On Thu, Nov 30, 2023 at 10:57=E2=80=AFAM Herve Codina wrote: > > Hi, > > The commit 407d1a51921e ("PCI: Create device tree node for bridge") > creates of_node for PCI devices. > During the insertion handling of these new DT nodes done by of_platform, > new devices (struct device) are created. > For each PCI devices a struct device is already present (created and > handled by the PCI core). > Creating a new device from a DT node leads to some kind of wrong struct > device duplication to represent the exact same PCI device. > > This patch series first introduces device_{add,remove}_of_node() in > order to add or remove a newly created of_node to an already existing > device. > Then it fixes the DT node creation for PCI devices to add or remove the > created node to the existing PCI device without any new device creation. I think the simpler solution is to get the DT node created earlier. We are just asking for pain if the DT node is set for the device at different times compared to static DT nodes. The following fixes the lack of of_node link. The DT unittest fails with the change though and I don't see why. Also, no idea if the bridge part works because my qemu setup doesn't create bridges (anyone got a magic cmdline to create them?). diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 9c2137dae429..46b252bbe500 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -342,8 +342,6 @@ void pci_bus_add_device(struct pci_dev *dev) */ pcibios_bus_add_device(dev); pci_fixup_device(pci_fixup_final, dev); - if (pci_is_bridge(dev)) - of_pci_make_dev_node(dev); pci_create_sysfs_dev_files(dev); pci_proc_attach_device(dev); pci_bridge_d3_update(dev); diff --git a/drivers/pci/of.c b/drivers/pci/of.c index 51e3dd0ea5ab..e15eaf0127fc 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -31,6 +31,8 @@ int pci_set_of_node(struct pci_dev *dev) return 0; node =3D of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn= ); + if (!node && pci_is_bridge(dev)) + of_pci_make_dev_node(dev); if (!node) return 0; diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index ea476252280a..e50b07fe5a63 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -6208,9 +6208,9 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); * before driver probing, it might need to add a device tree node as the f= inal * fixup. */ -DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_XILINX, 0x5020, of_pci_make_dev_node= ); -DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_XILINX, 0x5021, of_pci_make_dev_node= ); -DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REDHAT, 0x0005, of_pci_make_dev_node= ); +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_XILINX, 0x5020, of_pci_make_dev_node= ); +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_XILINX, 0x5021, of_pci_make_dev_node= ); +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_REDHAT, 0x0005, of_pci_make_dev_node= ); /* * Devices known to require a longer delay before first config space acces= s