From patchwork Tue Oct 22 10:27:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam via B4 Relay X-Patchwork-Id: 13845496 X-Patchwork-Delegate: bhelgaas@google.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9437619A292; Tue, 22 Oct 2024 10:28:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729592882; cv=none; b=B0MqT85F90GXyyNPj9UbxNkD7Pf53WTOS9PKJnWKGzyTXSJY2zYP9ZJKLMVeDS2ihkLXNq5oZnVG6YcXO1iDHT0iqkEtioNXzvM6ZQO1TGozLAvX3NIypRoDGjojskVIw7Y4yfJiMYSdr/V4+Au0IgAg6iBCggDkEMAxvdDgk04= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729592882; c=relaxed/simple; bh=01Nb+7M5sXaBv6N3XSYUTbtuO/IWYV2WZrjBElXovog=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=URHgQYBXM0lUWmGHopJrJXj0TDlyC+PizrHJBKdprwaBQ4YuURQuK8vMkqXQIzNKvFZHWzHy3DdJXgZq6f5MZ9a7heva8muQAwtdYIJoTbb/xQSW6l8VKjL+zzdrWK4a2gjTwR423EacC+Bj46/jf8SFRgYEfarQyk28dsxIdjQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SToYvcxf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SToYvcxf" Received: by smtp.kernel.org (Postfix) with ESMTPS id 429B8C4CECD; Tue, 22 Oct 2024 10:28:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729592882; bh=01Nb+7M5sXaBv6N3XSYUTbtuO/IWYV2WZrjBElXovog=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=SToYvcxfwiEItYylBc0eRpMY68AjUVRz1ZzVG2ztnqFckJgO3nqQrwsESkPpaNDGr Smta6BFCb2d8svnwWFkQogc/6YzZ3cRaaMqC0cs4DetzwlD4nn8tS96N8WopJ9iHnI Tj+s4qa1j9FzF2Gha8g9mt6ZJ+l0HbRS6/m8eESVTgTlRkqULTl47s2Z5Ox8QxvWFG qIC9qPLYxM0FSlrAAcPjYld68NHJu9zevtNDX4uSaVvNzGQb/Z2qezu3DCvb+AdMK+ 5qSyATemVws3CXizr1Z5V1pmNL1GV+2EVq93t7z4VGBjKiNlvjmSxHoZrQtX5GLNQF ikCOhD/ovOcug== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31F86D1CDD4; Tue, 22 Oct 2024 10:28:02 +0000 (UTC) From: Manivannan Sadhasivam via B4 Relay Date: Tue, 22 Oct 2024 15:57:29 +0530 Subject: [PATCH 1/5] PCI/pwrctl: Use of_platform_device_create() to create pwrctl devices Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241022-pci-pwrctl-rework-v1-1-94a7e90f58c5@linaro.org> References: <20241022-pci-pwrctl-rework-v1-0-94a7e90f58c5@linaro.org> In-Reply-To: <20241022-pci-pwrctl-rework-v1-0-94a7e90f58c5@linaro.org> To: Bjorn Helgaas , Bartosz Golaszewski Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Baryshkov , Johan Hovold , Abel Vesa , Stephan Gerhold , Srinivas Kandagatla , Bjorn Andersson , Manivannan Sadhasivam X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1771; i=manivannan.sadhasivam@linaro.org; h=from:subject:message-id; bh=MGzatbYJniVLg7BZgRAG2FQoP+AtAWyuUZzih9eO9g4=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBnF34utpei03sy9L2UxAgWs45Ed1FfiX7hVSSOx Q7B8FKTJnCJATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCZxd+LgAKCRBVnxHm/pHO 9WgbB/9jmbynDRZTrQAupCu4BsISZu3OHHosTFflg8Ss3KvfJ86aP1cHNuegSpYBtwXYNIfSHu+ 8+LYfuz9Hot9J+WUzvFtpAi8g8o+tKnOlGhayndJneAInm04GhZRP5elSCtzVObI/c5iKPgk8SC /PVJUq+PKZRBxRE62p5IbnY3L1NW+doZ6QXSEtBrEDM5pfhOughejsMbCyNVRdrOBzDyyFigGCS mY0ZzLYne//VJ75TLQsdKrZUDvxHwlsg2PEfpaaqUX7q7DgCpqIbPhvKiZzphGS7+8cbm3Ev+vR y7OVOizOhxGfe7LKXAZjxaYRSIYwyhgjTDaDkW6mV2IF211A X-Developer-Key: i=manivannan.sadhasivam@linaro.org; a=openpgp; fpr=C668AEC3C3188E4C611465E7488550E901166008 X-Endpoint-Received: by B4 Relay for manivannan.sadhasivam@linaro.org/default with auth_id=185 X-Original-From: Manivannan Sadhasivam Reply-To: manivannan.sadhasivam@linaro.org From: Manivannan Sadhasivam of_platform_populate() API creates platform devices by descending through the children of the parent node. But it provides no control over the child nodes, which makes it difficult to add checks for the child nodes in the future. So use of_platform_device_create() API together with for_each_child_of_node_scoped() so that it is possible to add checks for each node before creating the platform device. Signed-off-by: Manivannan Sadhasivam --- drivers/pci/bus.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 55c853686051..959044b059b5 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -329,6 +330,7 @@ void __weak pcibios_bus_add_device(struct pci_dev *pdev) { } void pci_bus_add_device(struct pci_dev *dev) { struct device_node *dn = dev->dev.of_node; + struct platform_device *pdev; int retval; /* @@ -351,11 +353,11 @@ void pci_bus_add_device(struct pci_dev *dev) pci_dev_assign_added(dev, true); if (dev_of_node(&dev->dev) && pci_is_bridge(dev)) { - retval = of_platform_populate(dev_of_node(&dev->dev), NULL, NULL, - &dev->dev); - if (retval) - pci_err(dev, "failed to populate child OF nodes (%d)\n", - retval); + for_each_child_of_node_scoped(dn, child) { + pdev = of_platform_device_create(child, NULL, &dev->dev); + if (!pdev) + pci_err(dev, "failed to create OF node: %s\n", child->name); + } } } EXPORT_SYMBOL_GPL(pci_bus_add_device); From patchwork Tue Oct 22 10:27:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam via B4 Relay X-Patchwork-Id: 13845499 X-Patchwork-Delegate: bhelgaas@google.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6B3819AA72; Tue, 22 Oct 2024 10:28:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729592882; cv=none; b=eYg/SMTawTgYN0a/F7Utm7Kc9QRQqcs9TKEEdkGrlR6tDyWr4YlEkzZP/A+wjRNKxn/W+EhKXZWrRy4CY9TZtoddEZa5a856fu3QM3BwQejBWjrF+o3/Nern99Sk6blb5y31a6Ds2RoU0qeFRSIWssT7Tv6jsfd5WmFwQWeq1kw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729592882; c=relaxed/simple; bh=o3IZO0OTXROleL/1SbqdS0nrBWIejoK+UE07q4umg6c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=N5DykM5FjR6wSySg1skuVUsVMoIofIp3HSwwGAngjSUDNQ3GzXzp2yt+RBXNo5JNpVgyC4D5ICEhrj+VdW81Coikld0WUnDqZ7Tt98k4vwM44HXipkaRr17NUdk8MKIh7+j8CZwc4HURJa3yJpdz8+2bxUwXroHzB69sB95Y3BU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fd42zyw6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fd42zyw6" Received: by smtp.kernel.org (Postfix) with ESMTPS id 57673C4CEE7; Tue, 22 Oct 2024 10:28:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729592882; bh=o3IZO0OTXROleL/1SbqdS0nrBWIejoK+UE07q4umg6c=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=fd42zyw6s67xQ4Wt9wJdAZjbepFC0AAJthXVvSQRdDXwdrWd7RZdqD1Pi1lrunKzv CrtzuxEalm6SGRILvcu7k7UjDYEGtbefqQy9tvG9T8ttnaZoL0GsTG+h5sn1TXFRJF bi9WsapAPVHrjOEyNwxBnE5fNARTDrqReh8xdB8L0QQ3OId1qliv96tVieKu6htWv2 dAMWOIbHsSpe3TMo72wmfV9v52u/RNCeERrOr2YCF96AQqoGgMYCT1kgk00gmQqsUQ 8o6Aegej+OTSarTCcSr+laL5Zkw+9ZkV+ol3QpLvdDOdEke5USegBVzrzDQJB7+atO jG0bYrPcFJzRg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 443B2D1CDD7; Tue, 22 Oct 2024 10:28:02 +0000 (UTC) From: Manivannan Sadhasivam via B4 Relay Date: Tue, 22 Oct 2024 15:57:30 +0530 Subject: [PATCH 2/5] PCI/pwrctl: Create pwrctl devices only if at least one power supply is present Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241022-pci-pwrctl-rework-v1-2-94a7e90f58c5@linaro.org> References: <20241022-pci-pwrctl-rework-v1-0-94a7e90f58c5@linaro.org> In-Reply-To: <20241022-pci-pwrctl-rework-v1-0-94a7e90f58c5@linaro.org> To: Bjorn Helgaas , Bartosz Golaszewski Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Baryshkov , Johan Hovold , Abel Vesa , Stephan Gerhold , Srinivas Kandagatla , Bjorn Andersson , Manivannan Sadhasivam , stable+noautosel@kernel.org X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=3545; i=manivannan.sadhasivam@linaro.org; h=from:subject:message-id; bh=oJ/OQynblPqFLnYyBuZFpwZHxzKNTbVvMhdHbuUg+mY=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBnF34u3E/YNcybcWcET91/0zg1s6CUet/6wi8CR JW3UcOvPZyJATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCZxd+LgAKCRBVnxHm/pHO 9UcbB/4yGoMHkD92oNUaj+8WGeH746ttw23Q7vNQytniw26Mb69OFcezMMNT3JkpJY2EWD/UbD/ K+PDVrZzh8BcIEhwtrnLjDJTqDOKlyRpx55VsuPEUhMTpLTAP0EUQVQSvL2C7g2yMM77D3BE5Ey TufCOoBlv5L6MkXJNymktzhuKZgddElRRTaWCRW38PQg5jCNReQw8E7At2nJufuBhfiSIABQEaI yHmDKr0Ajx1brh+KXfOGBRTj/UBnPyRtUB4kXaERCzYNITzIQncSyxOckpPpsxiBulW5XZRMrZN GrqlkfA7majXF1wBmU9sBCczx5Wxhd7KUCJmyaxJ8R7PB93Z X-Developer-Key: i=manivannan.sadhasivam@linaro.org; a=openpgp; fpr=C668AEC3C3188E4C611465E7488550E901166008 X-Endpoint-Received: by B4 Relay for manivannan.sadhasivam@linaro.org/default with auth_id=185 X-Original-From: Manivannan Sadhasivam Reply-To: manivannan.sadhasivam@linaro.org From: Manivannan Sadhasivam Currently, pwrctl devices are created if the corresponding PCI nodes are defined in devicetree. But this is not correct, because not all PCI nodes defined in devicetree require pwrctl support. Pwrctl comes into picture only when the device requires kernel to manage its power state. This can be determined using the power supply properties present in the devicetree node of the device. So add a new API, of_pci_is_supply_present() that checks the devicetree node if at least one power supply property is present or not. If present, then the pwrctl device will be created for that PCI node. Otherwise, it will be skipped. Cc: stable+noautosel@kernel.org # Depends on of_platform_device_create() rework Fixes: 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF nodes of the port node") Suggested-by: Dmitry Baryshkov Signed-off-by: Manivannan Sadhasivam Reviewed-by: Bartosz Golaszewski --- drivers/pci/bus.c | 11 +++++++++++ drivers/pci/of.c | 27 +++++++++++++++++++++++++++ drivers/pci/pci.h | 5 +++++ 3 files changed, 43 insertions(+) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 959044b059b5..698ec98b9388 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -354,6 +354,17 @@ void pci_bus_add_device(struct pci_dev *dev) if (dev_of_node(&dev->dev) && pci_is_bridge(dev)) { for_each_child_of_node_scoped(dn, child) { + /* + * First check whether the pwrctl device needs to be + * created or not. This is decided based on at least + * one of the power supplies being defined in the + * devicetree node of the device. + */ + if (!of_pci_is_supply_present(child)) { + pci_dbg(dev, "skipping OF node: %s\n", child->name); + continue; + } + pdev = of_platform_device_create(child, NULL, &dev->dev); if (!pdev) pci_err(dev, "failed to create OF node: %s\n", child->name); diff --git a/drivers/pci/of.c b/drivers/pci/of.c index dacea3fc5128..1f6a15a35a82 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -728,6 +728,33 @@ void of_pci_make_dev_node(struct pci_dev *pdev) } #endif +/** + * of_pci_is_supply_present() - Check if the power supply is present for the PCI + * device + * @np: Device tree node + * + * Check if the power supply for the PCI device is present in the device tree + * node or not. + * + * Return: true if at least one power supply exists; false otherwise. + */ +bool of_pci_is_supply_present(struct device_node *np) +{ + struct property *prop; + char *supply; + + if (!np) + return false; + + for_each_property_of_node(np, prop) { + supply = strrchr(prop->name, '-'); + if (supply && !strcmp(supply, "-supply")) + return true; + } + + return false; +} + #endif /* CONFIG_PCI */ /** diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 14d00ce45bfa..c8081b427267 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -746,6 +746,7 @@ void pci_set_bus_of_node(struct pci_bus *bus); void pci_release_bus_of_node(struct pci_bus *bus); int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge); +bool of_pci_is_supply_present(struct device_node *np); #else static inline int @@ -793,6 +794,10 @@ static inline int devm_of_pci_bridge_init(struct device *dev, struct pci_host_br return 0; } +static inline bool of_pci_is_supply_present(struct device_node *np); +{ + return false; +} #endif /* CONFIG_OF */ struct of_changeset; From patchwork Tue Oct 22 10:27:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam via B4 Relay X-Patchwork-Id: 13845498 X-Patchwork-Delegate: bhelgaas@google.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6ADE19AA5F; Tue, 22 Oct 2024 10:28:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729592882; cv=none; b=D9mXWuyQxCFfN3I7MuiEqUXaA81YlXbRY0s42EzbMsONuYXe91kECiwzOWGH2w5XevtDCdXNi6RliJy/Xa9I1WzpDd+jUiWPQ3ERArg4wa8jELx5+QxYgZ8Xj9qs9Rz+XJpkLBdlOFPCz7C6LzX/Qz03+1l4F1UWXvkwZiczU6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729592882; c=relaxed/simple; bh=nXrMDv4DLCwTKntmPRrNHTshkE35Wn5xllkAYNU1RPw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DPZvKefjgXOJ0F7xRwsGnxok5Q5mbH4Wm783AyCYmonVfl2QEfIhLHnWcE7Vxq2+7qPtePzyhRz+6ovLTSR9w8eM18ldcYI8xIFH7mld5tBPKXpgeCORWDlvsR9ag/T2HaUiD5Szif/nlx1HRQuy6Pnr2ZCynAdnP2dY+1qXHWA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lvroHRQg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lvroHRQg" Received: by smtp.kernel.org (Postfix) with ESMTPS id 62FB5C4CEE8; Tue, 22 Oct 2024 10:28:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729592882; bh=nXrMDv4DLCwTKntmPRrNHTshkE35Wn5xllkAYNU1RPw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=lvroHRQg197E6Fra1WlW2UtEZMMl9OI1bxoAE+0NCsIqQz98bviNqxpj6xxlLpCsl DIbf31lZN8F8H171fYOgxCKgPnhVbb3uQA8Ujf6NQEavRbaXQbEuvVy08kmnZYFBF3 2aS5/7a6d5PW2i7fR6Zv7ZWAyYLJKJdst/yDTygiZvVdLfUerzNIwWBJWcAqy1qSYk J7QEp4SHez/IeRaeIFZWrTmaB63sABbXs+85vAijC8rKrVbGNzIOxl/gmaDTmaGoMN iHjYnEgn2qNVm7zXPpkAMDHXl+oHinRxCo1UT4t05bS4NbF67Q61bVdbtQBYKi9z7N xRj10Fgl55MfA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54E0AD1CDD3; Tue, 22 Oct 2024 10:28:02 +0000 (UTC) From: Manivannan Sadhasivam via B4 Relay Date: Tue, 22 Oct 2024 15:57:31 +0530 Subject: [PATCH 3/5] PCI/pwrctl: Ensure that the pwrctl drivers are probed before the PCI client drivers Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241022-pci-pwrctl-rework-v1-3-94a7e90f58c5@linaro.org> References: <20241022-pci-pwrctl-rework-v1-0-94a7e90f58c5@linaro.org> In-Reply-To: <20241022-pci-pwrctl-rework-v1-0-94a7e90f58c5@linaro.org> To: Bjorn Helgaas , Bartosz Golaszewski Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Baryshkov , Johan Hovold , Abel Vesa , Stephan Gerhold , Srinivas Kandagatla , Bjorn Andersson , Manivannan Sadhasivam , stable+noautosel@kernel.org X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4288; i=manivannan.sadhasivam@linaro.org; h=from:subject:message-id; bh=CMCJAN6TTXnp4YKoD/4sES4pW+pXB0JA5zNXiTbypoQ=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBnF34v3ndtipqnqpjL/0m97CWLr9o+/oUmMsTPG u+5FqUYSkqJATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCZxd+LwAKCRBVnxHm/pHO 9dB+B/9qx4jfhTowszqW04+QkzMLfxp8hx92XArz8U00OJ0j5rh3toSkNbf2LCcnHnM8xpE4Mmh vxxBbBeMsDmb+ABqG2LenkJMN/dvmCtpaClRuaeCu5cZvhGqZYZ+i9z18mLxxgzYT45gqoomNYe Ks+8BlyOWldFEO3SxR+PjcavhQro1wNeTEAJKTW01NwSvnFpNqD7uA0xS/8ls6QXfyknU899U8M 6pzHXYznFKavGEsFSMiZv6U85kmW8bGIdfploIDzuKoSKcPT2+grkxGKQn4sktyC1B6Y1+SiiXx ib9z+m7Jhls+Z61zGyE/PtIvFANAug+vtLGWHvvGAWfinjha X-Developer-Key: i=manivannan.sadhasivam@linaro.org; a=openpgp; fpr=C668AEC3C3188E4C611465E7488550E901166008 X-Endpoint-Received: by B4 Relay for manivannan.sadhasivam@linaro.org/default with auth_id=185 X-Original-From: Manivannan Sadhasivam Reply-To: manivannan.sadhasivam@linaro.org From: Manivannan Sadhasivam As per the kernel device driver model, pwrctl device is the supplier for the PCI device. But the device link that enforces the supplier-consumer relationship is created inside the pwrctl driver currently. Due to this, the driver model doesn't prevent probing of the PCI client drivers before probing the corresponding pwrctl drivers. This may lead to a race condition if the PCI device was already powered on by the bootloader (before the pwrctl driver). If the bootloader did not power on the PCI device, this wouldn't create any problem as the pwrctl driver will be the one powering on the device, so the PCI client driver always gets probed afterward. But if the device was already powered on, then the device will be seen by the PCI core and the PCI client driver may get probed before its pwrctl driver. This creates a race condition as the pwrctl driver may change the device power state while the device is being accessed by the client driver. One such issue was already reported on the Qcom X13s platform with the WLAN device and fixed with a hack in the WCN pwrseq driver by the 'commit a9aaf1ff88a8 ("power: sequencing: request the WLAN enable GPIO as-is")'. But a cleaner way to fix the above mentioned race condition would be to ensure that the pwrctl drivers are always probed before the client drivers. This is achieved by creating the device link between pwrctl device and PCI device before device_attach() in pci_bus_add_device(). Note that there is no need to explicitly remove the device link as that will be taken care by the driver core when the PCI device gets removed. Cc: stable+noautosel@kernel.org # Depends on power supply check Fixes: 4565d2652a37 ("PCI/pwrctl: Add PCI power control core code") Fixes: 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF nodes of the port node") Signed-off-by: Manivannan Sadhasivam Reviewed-by: Bartosz Golaszewski --- drivers/pci/bus.c | 26 +++++++++++++++++++------- drivers/pci/pwrctl/core.c | 10 ---------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 698ec98b9388..351af581904f 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -345,13 +345,6 @@ void pci_bus_add_device(struct pci_dev *dev) pci_proc_attach_device(dev); pci_bridge_d3_update(dev); - dev->match_driver = !dn || of_device_is_available(dn); - retval = device_attach(&dev->dev); - if (retval < 0 && retval != -EPROBE_DEFER) - pci_warn(dev, "device attach failed (%d)\n", retval); - - pci_dev_assign_added(dev, true); - if (dev_of_node(&dev->dev) && pci_is_bridge(dev)) { for_each_child_of_node_scoped(dn, child) { /* @@ -370,6 +363,25 @@ void pci_bus_add_device(struct pci_dev *dev) pci_err(dev, "failed to create OF node: %s\n", child->name); } } + + /* + * Create a device link between the PCI device and pwrctl device (if + * exists). This ensures that the pwrctl drivers are probed before the + * PCI client drivers. + */ + pdev = of_find_device_by_node(dn); + if (pdev) { + if (!device_link_add(&dev->dev, &pdev->dev, DL_FLAG_AUTOREMOVE_CONSUMER)) + pci_err(dev, "failed to add device link between %s and %s\n", + dev_name(&dev->dev), pdev->name); + } + + dev->match_driver = !dn || of_device_is_available(dn); + retval = device_attach(&dev->dev); + if (retval < 0 && retval != -EPROBE_DEFER) + pci_warn(dev, "device attach failed (%d)\n", retval); + + pci_dev_assign_added(dev, true); } EXPORT_SYMBOL_GPL(pci_bus_add_device); diff --git a/drivers/pci/pwrctl/core.c b/drivers/pci/pwrctl/core.c index 01d913b60316..bb5a23712434 100644 --- a/drivers/pci/pwrctl/core.c +++ b/drivers/pci/pwrctl/core.c @@ -33,16 +33,6 @@ static int pci_pwrctl_notify(struct notifier_block *nb, unsigned long action, */ dev->of_node_reused = true; break; - case BUS_NOTIFY_BOUND_DRIVER: - pwrctl->link = device_link_add(dev, pwrctl->dev, - DL_FLAG_AUTOREMOVE_CONSUMER); - if (!pwrctl->link) - dev_err(pwrctl->dev, "Failed to add device link\n"); - break; - case BUS_NOTIFY_UNBOUND_DRIVER: - if (pwrctl->link) - device_link_remove(dev, pwrctl->dev); - break; } return NOTIFY_DONE; From patchwork Tue Oct 22 10:27:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam via B4 Relay X-Patchwork-Id: 13845501 X-Patchwork-Delegate: bhelgaas@google.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED2B219C556; Tue, 22 Oct 2024 10:28:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729592884; cv=none; b=LaHSkVIHTkPAdeFJqoddboBlY0EvX3I1DMq1VZHR5NgPhgGZO9ov5w0Qip0kv54O+ipQSUWe/2ajKRt7M6zbmt9Y1KRv6ahtuN6FrArhfzdnHyhezTZlOdK2DwhrMAWrtOb1Eq0f1IM8Rlo60OBbsAE3j0cwGB/jfDgHrjeesSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729592884; c=relaxed/simple; bh=iDI1BQiua45IUMp/ZWP+8paKKCC+IFjowSEqYFTeTFw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Azb9UeLbH9rJ4oFhPm6qqIbbdbeNyPZvotUgb0w5SfauvXLJOVT7uz6z6sl6zqHcyXP0rKYLeF46t0WJJfhYj0HtOncnD/GlIWDp8pNfuJ2tXGokI41xsnoa9qZes+mmHg+0FbwZbdF8GVyGkm/1P9Wqq/ft08Dyapl1d/EVsII= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FWGng+KD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FWGng+KD" Received: by smtp.kernel.org (Postfix) with ESMTPS id 72D42C4CEE7; Tue, 22 Oct 2024 10:28:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729592883; bh=iDI1BQiua45IUMp/ZWP+8paKKCC+IFjowSEqYFTeTFw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=FWGng+KDqH8huUQF9VFFp44Xz8Rxi9Tpq+eXsoHWU4W19sqAnvjSZ9IPmSk72eDsb gKAqyer04Rlgl2TbsgclYZcLuK+VeQ8R1m4Xtf7XjLHgCcimSM31vUHEbq77nsCT+V kEKV7b3WiV5zc9lSvL6/fv4hwEHpgoEG6V2NxNgH3q9ftpBTodLXn6GLx0Qo7Gbqp6 DBzX5/WO1RaOOrGrXA/qb8W+F05+Hk3r6oSMNMQ4jyDZ+MyICpmDlzSSMimCHUuPsS hr3BkznjcXBPh6TX0NRDvMmMu9OKLCo6rSg0lyUMPYtW5h9ge/KalOF3bpGBZCRLBJ sbJZ0VprT2nPw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67C1CD1CDD8; Tue, 22 Oct 2024 10:28:02 +0000 (UTC) From: Manivannan Sadhasivam via B4 Relay Date: Tue, 22 Oct 2024 15:57:32 +0530 Subject: [PATCH 4/5] PCI/pwrctl: Move pwrctl device creation to its own helper function Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241022-pci-pwrctl-rework-v1-4-94a7e90f58c5@linaro.org> References: <20241022-pci-pwrctl-rework-v1-0-94a7e90f58c5@linaro.org> In-Reply-To: <20241022-pci-pwrctl-rework-v1-0-94a7e90f58c5@linaro.org> To: Bjorn Helgaas , Bartosz Golaszewski Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Baryshkov , Johan Hovold , Abel Vesa , Stephan Gerhold , Srinivas Kandagatla , Bjorn Andersson , Manivannan Sadhasivam X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2866; i=manivannan.sadhasivam@linaro.org; h=from:subject:message-id; bh=ysOLKy+185AD3GOipcG2TEA807qZUk22GeUQ5Y6pe4o=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBnF34vmsof+M+5wL5XmngmSZCCByb+moVH/g2gE BwhvmPs2BiJATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCZxd+LwAKCRBVnxHm/pHO 9RUxB/9DKZS3wBi+FU7eP7EVhMTHc/nh9MECM0XNE1queAtb+/Si7BtnEdjcqvRwamCngW/kN0R q8U9RflthcVPaEor0YjkTnlPMM49we3BVurBjFoZp833MNguajLNFZJlC5308PwNEuxBfPfkRny jjZACCHEWlxya5zXo5YjqbQpsp71GtpuqqlQbU9bAUFwAdd0Pk8ygGygSZ47awBmhuyUGLUsm0Z 2qwuluPr00FNCLDRqtBbw4p6EnlJztA9DX1EdeXj7oYXa30GA+1gKUEk1MBcYmQyFm+mC7OhJRz ZPdOVSoenL2EiN2B2i9vDphxWm3XFnVHb2L1RZm011JfFtnY X-Developer-Key: i=manivannan.sadhasivam@linaro.org; a=openpgp; fpr=C668AEC3C3188E4C611465E7488550E901166008 X-Endpoint-Received: by B4 Relay for manivannan.sadhasivam@linaro.org/default with auth_id=185 X-Original-From: Manivannan Sadhasivam Reply-To: manivannan.sadhasivam@linaro.org From: Manivannan Sadhasivam This makes the pci_bus_add_device() API easier to maintain. Also add more comments to the helper to describe how the devices are created. Signed-off-by: Manivannan Sadhasivam --- drivers/pci/bus.c | 59 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 351af581904f..c4cae1775c9e 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -321,6 +321,46 @@ void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { } void __weak pcibios_bus_add_device(struct pci_dev *pdev) { } +/* + * Create pwrctl devices (if required) for the PCI devices to handle the power + * state. + */ +static void pci_pwrctl_create_devices(struct pci_dev *dev) +{ + struct device_node *np = dev_of_node(&dev->dev); + struct device *parent = &dev->dev; + struct platform_device *pdev; + + /* + * First ensure that we are starting from a PCI bridge and it has a + * corresponding devicetree node. + */ + if (np && pci_is_bridge(dev)) { + /* + * Now look for the child PCI device nodes and create pwrctl + * devices for them. The pwrctl device drivers will manage the + * power state of the devices. + */ + for_each_child_of_node_scoped(np, child) { + /* + * First check whether the pwrctl device really needs to + * be created or not. This is decided based on at least + * one of the power supplies being defined in the + * devicetree node of the device. + */ + if (!of_pci_is_supply_present(child)) { + pci_dbg(dev, "skipping OF node: %s\n", child->name); + return; + } + + /* Now create the pwrctl device */ + pdev = of_platform_device_create(child, NULL, parent); + if (!pdev) + pci_err(dev, "failed to create OF node: %s\n", child->name); + } + } +} + /** * pci_bus_add_device - start driver for a single device * @dev: device to add @@ -345,24 +385,7 @@ void pci_bus_add_device(struct pci_dev *dev) pci_proc_attach_device(dev); pci_bridge_d3_update(dev); - if (dev_of_node(&dev->dev) && pci_is_bridge(dev)) { - for_each_child_of_node_scoped(dn, child) { - /* - * First check whether the pwrctl device needs to be - * created or not. This is decided based on at least - * one of the power supplies being defined in the - * devicetree node of the device. - */ - if (!of_pci_is_supply_present(child)) { - pci_dbg(dev, "skipping OF node: %s\n", child->name); - continue; - } - - pdev = of_platform_device_create(child, NULL, &dev->dev); - if (!pdev) - pci_err(dev, "failed to create OF node: %s\n", child->name); - } - } + pci_pwrctl_create_devices(dev); /* * Create a device link between the PCI device and pwrctl device (if From patchwork Tue Oct 22 10:27:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam via B4 Relay X-Patchwork-Id: 13845500 X-Patchwork-Delegate: bhelgaas@google.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE56019C543; Tue, 22 Oct 2024 10:28:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729592883; cv=none; b=TUBljE1w1IKa7ysAK0fD8xfsXuvhDAN8ZmosRNBBcffsi3S9ieVLOQZ+7r3e8y92zBNFaIMenMnp4K9+UhP3UqzJEnZv3KdJrhsTJnMjWI+nrXbxoL7cIuK+G0v55DZCtV93NYq4icVow/pVSgsirx2gUZzbziPaunYCXFu+MJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729592883; c=relaxed/simple; bh=jPx+IRUONoAgH3KFjgYaCrDCw64YdeqQ3+EqFJXljGQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SywjKgeS4IKZbL8jtYafaTu2+z48v2mj7f0Am0hTfh7GTHTrQac9ycpn+fhylotmITk9hu/MRjB26a/VdCz6vcQtH9pRsejmKC1xklg/lV653LeI8tRvR3uncliJC2u0VVewm29eOm6UJmJBeXP1wHb0hGtY6k62E/NMku1hMJg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iyPlxy5c; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iyPlxy5c" Received: by smtp.kernel.org (Postfix) with ESMTPS id 82BFAC4CEEB; Tue, 22 Oct 2024 10:28:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729592883; bh=jPx+IRUONoAgH3KFjgYaCrDCw64YdeqQ3+EqFJXljGQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=iyPlxy5cEym5z4dc5fuFg0Hs1iBgHTGF+Mzq7b7hxHgnmiWLEDpaDwcKmqkxIRF0v 3glK1uFH24QFWFpU3stuYIGPyrVVrkOXgsZ3PHLjXCdjCBKIj9ZOha8WdKEpP8Y06F /3vSajHOZ9Lu2z9WbM7YDohEVZHQjbZ9pI5sVtI5syUPE1wsGDpaWMIe63XIsfKLjm Sa4q/mVXsckKYKtxbBex8tAUBFHnUpF9MTge8S8itJbLsPECkVNufGLpjOc9FRRKQU D2slIuLxUe/URAVFj6w4ZTYF7CF14CYnEC97Nm3/mxVZ+GRUPyXQdISU+Zdj6M3Zmf CATtDb6UpHlpQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A9F9D1CDD7; Tue, 22 Oct 2024 10:28:02 +0000 (UTC) From: Manivannan Sadhasivam via B4 Relay Date: Tue, 22 Oct 2024 15:57:33 +0530 Subject: [PATCH 5/5] PCI/pwrctl: Remove pwrctl device without iterating over all children of pwrctl parent Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241022-pci-pwrctl-rework-v1-5-94a7e90f58c5@linaro.org> References: <20241022-pci-pwrctl-rework-v1-0-94a7e90f58c5@linaro.org> In-Reply-To: <20241022-pci-pwrctl-rework-v1-0-94a7e90f58c5@linaro.org> To: Bjorn Helgaas , Bartosz Golaszewski Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Baryshkov , Johan Hovold , Abel Vesa , Stephan Gerhold , Srinivas Kandagatla , Bjorn Andersson , Manivannan Sadhasivam X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1846; i=manivannan.sadhasivam@linaro.org; h=from:subject:message-id; bh=Fx4nsEA2QZpP1ERShZZ8bZw3IQBN6+Um75DdA2nrjyg=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBnF34v/nlnaSD9lCRQmkUSbC0gN51VH+Ya8loNI VZhLq3xK7eJATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCZxd+LwAKCRBVnxHm/pHO 9WpUCACKafJIXVlw/tZAI/sQS1x6dJE+i6hX9zJsxTo/DczSyuwA6FHOswiX8NHCLJZyYTyspGt rFNtE5+WOuWGABNRXUvTZLGAOJZljL1UHYFJMkPRzuLUfFhTPjuEJ2aXkYTFz6tJaaAoah74P8r hUrkZve4eH0d3qRD3NDeZuwBIhT0ZyGPN9j32ESnqYhBhyuY6vxemjBM38NAWSDFc5gUdSBufzA Lwa8k652Feas0X9FUPl+RrPjjq/Yot8oDfpSiKhAnPQNYLinqbLfb6vrAbphM9VMDRv35P01xNY lgPl05mHeyzVat+aw1w4oGVinO277ji4pUNpIEanlGGfbcHs X-Developer-Key: i=manivannan.sadhasivam@linaro.org; a=openpgp; fpr=C668AEC3C3188E4C611465E7488550E901166008 X-Endpoint-Received: by B4 Relay for manivannan.sadhasivam@linaro.org/default with auth_id=185 X-Original-From: Manivannan Sadhasivam Reply-To: manivannan.sadhasivam@linaro.org From: Manivannan Sadhasivam There is no need to iterate over all children of the pwrctl device parent to remove the pwrctl device. Since the pwrctl device associated with the PCI device can be found using of_find_device_by_node() API, use it directly instead. If any pwrctl devices lying around without getting associated with the PCI devices, then those will be removed once their parent device gets removed. Signed-off-by: Manivannan Sadhasivam Reviewed-by: Bartosz Golaszewski --- drivers/pci/remove.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index e4ce1145aa3e..3dd9b3024956 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -17,16 +17,16 @@ static void pci_free_resources(struct pci_dev *dev) } } -static int pci_pwrctl_unregister(struct device *dev, void *data) +static void pci_pwrctl_unregister(struct device *dev) { - struct device_node *pci_node = data, *plat_node = dev_of_node(dev); + struct platform_device *pdev; - if (dev_is_platform(dev) && plat_node && plat_node == pci_node) { - of_device_unregister(to_platform_device(dev)); - of_node_clear_flag(plat_node, OF_POPULATED); - } + pdev = of_find_device_by_node(dev_of_node(dev)); + if (!pdev) + return; - return 0; + of_device_unregister(pdev); + of_node_clear_flag(dev_of_node(dev), OF_POPULATED); } static void pci_stop_dev(struct pci_dev *dev) @@ -34,8 +34,7 @@ static void pci_stop_dev(struct pci_dev *dev) pci_pme_active(dev, false); if (pci_dev_is_added(dev)) { - device_for_each_child(dev->dev.parent, dev_of_node(&dev->dev), - pci_pwrctl_unregister); + pci_pwrctl_unregister(&dev->dev); device_release_driver(&dev->dev); pci_proc_detach_device(dev); pci_remove_sysfs_dev_files(dev);