Message ID | 20231130152418.680966-3-herve.codina@bootlin.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp466828vqy; Thu, 30 Nov 2023 07:24:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGISS0zzBV6D5QvKezlNlcBMs3eqfqQeyFToBDHLN5+i5WtkbgcqYJGS+agix+iV36o0B0C X-Received: by 2002:a05:6a00:2410:b0:6cb:903a:b064 with SMTP id z16-20020a056a00241000b006cb903ab064mr24023005pfh.22.1701357894540; Thu, 30 Nov 2023 07:24:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701357894; cv=none; d=google.com; s=arc-20160816; b=TLGGKUC5DMapKLxq5ZEoFZvtziINXvM1fJxHGlPVOZJl8Vkc9+hIovSx00NvGKUYoK 1l0oYsWtXM6J6Q4fU5jHydYBkYYUt8e/9lbcQPzdPBP1n6GGc6vLhnSPl+xEROfze6jb Lj0CcAgXfypTn707M9bVha5zH5S9xGffyvygg9JAdGoK8YlQnikhf7d7PwoUs2wEZ0kU Cjn9b0N3HwulHPg5PJfdwFb3BU6UMFTtw+K92AB0TNQwj4ZauuyeZBTSZypuPa6kAuht 1V5B2rGiDsguS3sgA/zgjQzsOH6VgSpsj5FAoe3Iv1PGAOLGuAgwfUWHHXfyTPeO4K/T Fh6w== 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=XjanQLiV96Fread002ZWRWE0O5XHgSgVvDb1R2qXIW8=; fh=CrkNyKleBTZ6J4lnQ7K9K2ER2ksD5GIR0Di6J9w1078=; b=0eHjcayyGsj9G/6rhQ/yhHfsKrh5dWrpW2z6UhgyeqJEf/PAJXw6fahghmitxd7tIB 93d8mWR6olhpwdrmsIPGaXHWQ+dcR31Oeoz5y4bjAuaTK7VAkqOlwgDdQoeytAITt6bs 6oyUYTbGImKnj2yWKS0EV3tJsEfWJARpgqz4NzogRrtEzxzFGazgNd9wb/v5yH+CE0FE CPpEK7l+S21F19MX94TyoRiHsUlQ82LKpYjPAI0Qb0OPeTaNXJUj7CRUM/1M3gmUSTha Yr3be0x5qbo6oxHxEyhqIwXBDgn9gIs88p90fb0OPnjWjAfAhqn3K3sVek5gh81Lb3fy 8OGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=EBvGX9ZX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id n123-20020a632781000000b005b8f446408bsi1391022pgn.422.2023.11.30.07.24.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 07:24:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=EBvGX9ZX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 2A2F880CE7F9; Thu, 30 Nov 2023 07:24:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346283AbjK3PYY (ORCPT <rfc822;ruipengqi7@gmail.com> + 99 others); Thu, 30 Nov 2023 10:24:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346270AbjK3PYV (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 30 Nov 2023 10:24:21 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B0641B3; Thu, 30 Nov 2023 07:24:27 -0800 (PST) Received: by mail.gandi.net (Postfix) with ESMTPA id 4A1BBFF816; Thu, 30 Nov 2023 15:24:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1701357866; 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=XjanQLiV96Fread002ZWRWE0O5XHgSgVvDb1R2qXIW8=; b=EBvGX9ZXy3DQtGO2d7/eRwWcKL6Sfo+JOIqYIcEo/3+97xrmIbCerPNHwK1Dwg7Cugso0C 0yC0SZrS5or2CqWTZAxlat8R4nOGhLEt1EB7ne/4un/xEruvnZwAiuqBFDZA+D6Jjo1Jjp W3ZVpgnTcHW89C/7Wyiwtl6K4Ssp/Z2axUVwYrmybO2Q9dSJRgoXze9YP6k908EXlRbgzI o6KC6L8AkvSN4xBDs4THH0fkOHi9M13udqzFEWI7wbUfIALJG1a2jZ9nq78APXvq9dnGzM jSx4UTaaWymqFcMDxr6suoCEcYNRdCBY+IVxz9ZU5dvH6XOedCNwajbsDt8kKQ== From: Herve Codina <herve.codina@bootlin.com> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, "Rafael J. Wysocki" <rafael@kernel.org>, Bjorn Helgaas <bhelgaas@google.com>, Lizhi Hou <lizhi.hou@amd.com>, Rob Herring <robh@kernel.org> Cc: Max Zhen <max.zhen@amd.com>, Sonal Santan <sonal.santan@amd.com>, Stefano Stabellini <stefano.stabellini@xilinx.com>, Jonathan Cameron <Jonathan.Cameron@Huawei.com>, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Allan Nielsen <allan.nielsen@microchip.com>, Horatiu Vultur <horatiu.vultur@microchip.com>, Steen Hegelund <steen.hegelund@microchip.com>, Thomas Petazzoni <thomas.petazzoni@bootlin.com>, Herve Codina <herve.codina@bootlin.com>, stable@vger.kernel.org Subject: [PATCH 2/2] PCI: of: Attach created of_node to existing device Date: Thu, 30 Nov 2023 16:24:04 +0100 Message-ID: <20231130152418.680966-3-herve.codina@bootlin.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231130152418.680966-1-herve.codina@bootlin.com> References: <20231130152418.680966-1-herve.codina@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: herve.codina@bootlin.com X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,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 lipwig.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 30 Nov 2023 07:24:42 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784003055307755390 X-GMAIL-MSGID: 1784003055307755390 |
Series |
Attach DT nodes to existing PCI devices
|
|
Commit Message
Herve Codina
Nov. 30, 2023, 3:24 p.m. UTC
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).
Having a second struct device to represent the exact same PCI device is
not correct.
On the of_node creation, tell the of_platform that there is no need to
create a device for this node (OF_POPULATED flag), link this newly
created of_node to the already present device and tell fwnode that the
device attached to this of_node is ready (fwnode_dev_initialized()).
With this fix, the of_node are available in the sysfs device tree:
/sys/devices/platform/soc/d0070000.pcie/
+ of_node -> .../devicetree/base/soc/pcie@d0070000
+ pci0000:00
+ 0000:00:00.0
+ of_node -> .../devicetree/base/soc/pcie@d0070000/pci@0,0
+ 0000:01:00.0
+ of_node -> .../devicetree/base/soc/pcie@d0070000/pci@0,0/dev@0,0
On the of_node removal, revert the operations.
Fixes: 407d1a51921e ("PCI: Create device tree node for bridge")
Cc: stable@vger.kernel.org
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
drivers/pci/of.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
Comments
On Thu, Nov 30, 2023 at 04:24:04PM +0100, Herve Codina wrote: > 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). > Having a second struct device to represent the exact same PCI device is > not correct. > > On the of_node creation, tell the of_platform that there is no need to > create a device for this node (OF_POPULATED flag), link this newly > created of_node to the already present device and tell fwnode that the > device attached to this of_node is ready (fwnode_dev_initialized()). > > With this fix, the of_node are available in the sysfs device tree: > /sys/devices/platform/soc/d0070000.pcie/ > + of_node -> .../devicetree/base/soc/pcie@d0070000 > + pci0000:00 > + 0000:00:00.0 > + of_node -> .../devicetree/base/soc/pcie@d0070000/pci@0,0 > + 0000:01:00.0 > + of_node -> .../devicetree/base/soc/pcie@d0070000/pci@0,0/dev@0,0 > > On the of_node removal, revert the operations. > > Fixes: 407d1a51921e ("PCI: Create device tree node for bridge") > Cc: stable@vger.kernel.org How can this be cc: stable when the api it relies on is not? confused, greg k-h
Hi Greg, On Thu, 30 Nov 2023 16:18:58 +0000 Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote: > On Thu, Nov 30, 2023 at 04:24:04PM +0100, Herve Codina wrote: > > 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). > > Having a second struct device to represent the exact same PCI device is > > not correct. > > > > On the of_node creation, tell the of_platform that there is no need to > > create a device for this node (OF_POPULATED flag), link this newly > > created of_node to the already present device and tell fwnode that the > > device attached to this of_node is ready (fwnode_dev_initialized()). > > > > With this fix, the of_node are available in the sysfs device tree: > > /sys/devices/platform/soc/d0070000.pcie/ > > + of_node -> .../devicetree/base/soc/pcie@d0070000 > > + pci0000:00 > > + 0000:00:00.0 > > + of_node -> .../devicetree/base/soc/pcie@d0070000/pci@0,0 > > + 0000:01:00.0 > > + of_node -> .../devicetree/base/soc/pcie@d0070000/pci@0,0/dev@0,0 > > > > On the of_node removal, revert the operations. > > > > Fixes: 407d1a51921e ("PCI: Create device tree node for bridge") > > Cc: stable@vger.kernel.org > > How can this be cc: stable when the api it relies on is not? > > confused, My bad, I will add cc: stable in the other patch needed. Sorry about that. Hervé
diff --git a/drivers/pci/of.c b/drivers/pci/of.c index 51e3dd0ea5ab..5afd2731e876 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -615,7 +615,8 @@ void of_pci_remove_node(struct pci_dev *pdev) np = pci_device_to_OF_node(pdev); if (!np || !of_node_check_flag(np, OF_DYNAMIC)) return; - pdev->dev.of_node = NULL; + + device_remove_of_node(&pdev->dev); of_changeset_revert(np->data); of_changeset_destroy(np->data); @@ -668,12 +669,22 @@ void of_pci_make_dev_node(struct pci_dev *pdev) if (ret) goto out_free_node; + /* + * This of_node will be added to an existing device. + * Avoid any device creation and use the existing device + */ + of_node_set_flag(np, OF_POPULATED); + np->fwnode.dev = &pdev->dev; + fwnode_dev_initialized(&np->fwnode, true); + ret = of_changeset_apply(cset); if (ret) goto out_free_node; np->data = cset; - pdev->dev.of_node = np; + + /* Add the of_node to the existing device */ + device_add_of_node(&pdev->dev, np); kfree(name); return;