From nobody Mon Nov 25 19:32:59 2024 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 C48B9193089; Fri, 25 Oct 2024 07:55: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=1729842902; cv=none; b=uzkZw0RbJw4CDixAgXPeJgyCitCB58gGw9AthOfuMzXSNFkFV+kPbk9SAVzpzYgt8MT41cjxO7H5dJZHGbFN/hN/iqIxm7rIiBCvnUcfXhmbnkQxZXiHsvTEBngAFpzS3Sd9V4P73O+2Sq/qNB5cBuS5rfee6CtFjgcJka2fTuM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729842902; c=relaxed/simple; bh=ZPXEmnQxffSGRrG7FdHYnp1Yr705CCZ2f1l4xDtJb14=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=d3TY9Y2c+jUvya59dovGWBXkgOGiYJe5HbuCquwQzW7ucQI6XyhyAkETMIwbF35fVSCKc/Ttjwj6H2nSh1mgZ/MU3oM3ZSOXCtzLP+sPImesE5C1Zt/n/74v5QYasgtyNY/yGknhaN62xxO7YB257bizqRyymDOBoZ31KquADWY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O/6DztWd; 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="O/6DztWd" Received: by smtp.kernel.org (Postfix) with ESMTPS id 6D0A2C4CEE4; Fri, 25 Oct 2024 07:55:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729842902; bh=ZPXEmnQxffSGRrG7FdHYnp1Yr705CCZ2f1l4xDtJb14=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=O/6DztWdB0v0irAzlEJqmkge89LDV3w8j0lPl+aRskLVCE6SaNG46TAonsJD5uMCi shXJHYQP9TeC+xnBTC0u1VClkbMreEE7KiAg1ij0Z+4/BE10I78Mx9mm8HW/FSjiug gpY5LBtQ4QpILdASKACbqGsLVES4IUKZ5FyWMUN46WzSTH/+qNbvdL7GI9PW/0TPw8 kON0ZghiXInaQ4KOQPR0jM3pbApbdNI9+1OfLt5hBs1yqZpzmlcp3l46tyda2AaszT +DBOMus4xy8vjvvfUy420yo1V/c6GTz8BAVqBQRbO0RGjkNXwja3dT/Hf336RVJemV QPz25QywzWlNA== 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 59F35D11717; Fri, 25 Oct 2024 07:55:02 +0000 (UTC) From: Manivannan Sadhasivam via B4 Relay Date: Fri, 25 Oct 2024 13:24:51 +0530 Subject: [PATCH v2 1/5] PCI/pwrctl: Use of_platform_device_create() to create pwrctl devices Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241025-pci-pwrctl-rework-v2-1-568756156cbe@linaro.org> References: <20241025-pci-pwrctl-rework-v2-0-568756156cbe@linaro.org> In-Reply-To: <20241025-pci-pwrctl-rework-v2-0-568756156cbe@linaro.org> To: Bjorn Helgaas , Bartosz Golaszewski , 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 , Krishna chaitanya chundru X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1911; i=manivannan.sadhasivam@linaro.org; h=from:subject:message-id; bh=bQwt/wTH5U7vcbRycg6o15FZXsFwt0f+Sqj6aoPRom4=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBnG07TaqMG39ouPhAtQ/1hfbOR1a1q9jrf2+EHO qn1DwnNI5aJATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCZxtO0wAKCRBVnxHm/pHO 9ZekB/9MkgETc9QdhjILs7JgkZY5fUcLEiB5I3JJ+b4pnCyel9S3vgWZMEAyT0X9TKU2B9oaT+y BV8/dxvPqyiElIAcPsg+PGpRICrJczC2ZiCej0znaTj1bWZLpzNGiZGNiba98B74NAS2n0vO7c1 LNvoKZjqIpAfcJH/e09p5q6u+e0ujrfw6il1ALsv/cD5pSJkKTCGMWcBbK/VIrz8q3GAxNSmsus uXQiZg2LsDKb8ZLC6i8o3I6ylTCEA/ajJRqEIX5onH8w3O1R9EUaaB7K037jUYz/HgvBDk3lMS2 cOXDjQOhsmcJA1f/mkl6dTh1AJm2CzEjwbctRa5ASY4w14vR 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. Tested-by: Krishna chaitanya chundru Tested-by: Bartosz Golaszewski Signed-off-by: Manivannan Sadhasivam Reviewed-by: Bartosz Golaszewski --- 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..9d278d3a19ff 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include =20 @@ -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 =3D dev->dev.of_node; + struct platform_device *pdev; int retval; =20 /* @@ -351,11 +353,11 @@ void pci_bus_add_device(struct pci_dev *dev) pci_dev_assign_added(dev, true); =20 if (dev_of_node(&dev->dev) && pci_is_bridge(dev)) { - retval =3D 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_available_child_of_node_scoped(dn, child) { + pdev =3D 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); --=20 2.25.1 From nobody Mon Nov 25 19:32:59 2024 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 DDB941C07DA; Fri, 25 Oct 2024 07:55: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=1729842903; cv=none; b=MWvyLUonFWJN1tG53d0/FSkRz9eUEKwDm7EcFPKLoobI/OQwBP3fVMzf3tcHX8ECvgCVx1JPYgCQvtSz/nu54uG7nK1WwEtn1uEie3SRX4whInC2gG0uSJgz4vPHPhsYA7NLdmY64U00n2xvPjyBB2YVQe5Vjkf8+YvgrtqypIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729842903; c=relaxed/simple; bh=NQ0rYXvCzXCekz1zJkqr8dXaO2BDwBfsvs5WWor/i3c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YKaXc+QHNSOj84hSTJDT+LR8FlO/7ZTFJAWUwcY48It31jcRW5U7XNNlvqZpUSbxIVkNuLIQs29iv8VI0Zx5nu97onHrrzwAjgMRFIadb8PaNwB6Cye9prWycGMlwGTDeUc0Jg7eArKjXKUnhdAdoq1XmdG+ZAr2bbas9PY2ods= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=haN3NeWk; 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="haN3NeWk" Received: by smtp.kernel.org (Postfix) with ESMTPS id 804BBC4CECC; Fri, 25 Oct 2024 07:55:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729842902; bh=NQ0rYXvCzXCekz1zJkqr8dXaO2BDwBfsvs5WWor/i3c=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=haN3NeWkxQXnd5zuCrz3Tc7Wl+AbRT99BBZYH2r3mwOjRhLB1sM9akvxgbf06hMmI OxYV4nfBJ3o3DQ31LOY0CQoJm/9oP0axIUbvkwt0o1O1ChU+jxGplf0P6LCklGN61q 4Vdr+Q601MEdlZxESdhM5ZVWQAePhIQgfc6rh1rUfY38BppAvAGdP3LxoRaNWCYw5h cvv+cfL9sKLXx8VkgC/O3rbL/uUblBCAF2RFzZsHONRo4XYGzyQZ7njzO68Ev+SCjW /8YxdiyfGVD8/qkB02sSJIsjG7+NqVTIE9w4LdpNKUZwbgqIRoz+E6u4AHYaLqUOPm R3vL83fV4fdpQ== 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 6EBBBD11718; Fri, 25 Oct 2024 07:55:02 +0000 (UTC) From: Manivannan Sadhasivam via B4 Relay Date: Fri, 25 Oct 2024 13:24:52 +0530 Subject: [PATCH v2 2/5] PCI/pwrctl: Create pwrctl devices only if at least one power supply is present Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241025-pci-pwrctl-rework-v2-2-568756156cbe@linaro.org> References: <20241025-pci-pwrctl-rework-v2-0-568756156cbe@linaro.org> In-Reply-To: <20241025-pci-pwrctl-rework-v2-0-568756156cbe@linaro.org> To: Bjorn Helgaas , Bartosz Golaszewski , 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, Krishna chaitanya chundru X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=3752; i=manivannan.sadhasivam@linaro.org; h=from:subject:message-id; bh=0FY5vkiC5PpJEJdcjgkvaOcvdHuhyY/wQ5scqIVPEeI=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBnG07TayXM1r3dwqeQe2GSxL/SytuTklHNyH5pt 7HB3USY6AyJATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCZxtO0wAKCRBVnxHm/pHO 9Y88B/497DHOm4It5o4WYHFiLBngDSxzYRtGuIsLZVRYRMesmVZ7k0bDjGTfZXXgUh6/g7/7n3D 6pF1bfl7YhKap9GGdHg9pYOwXWOr/LdSlIlqZvrZkqvv9/Fq9ZS/sw+rNGY95KwRVxMJOjna1FB aQV2oJiBRtSEwZ320MRM4tUtun1tvoc3069jLRxc3yk18R+8EbBAhYNrho9lR14QYJZ1TDteqgv Y+7rPkAPJg1gMchKQHKYPesRBlBK/dF/5HLxTalhJSw1UgyvInX2J2nuvSSQ/LwmHA3zFDYI6oe OBvS7S7/rezgxFKOtnuuMIK0wXUEGpaiB6yrEtvRCiiT+stG 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() re= work Fixes: 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF node= s of the port node") Suggested-by: Dmitry Baryshkov Reviewed-by: Bartosz Golaszewski Tested-by: Krishna chaitanya chundru Tested-by: Bartosz Golaszewski Signed-off-by: Manivannan Sadhasivam --- 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 9d278d3a19ff..02a492aa5f17 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -354,6 +354,17 @@ void pci_bus_add_device(struct pci_dev *dev) =20 if (dev_of_node(&dev->dev) && pci_is_bridge(dev)) { for_each_available_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 =3D 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 =20 +/** + * of_pci_is_supply_present() - Check if the power supply is present for t= he PCI + * device + * @np: Device tree node + * + * Check if the power supply for the PCI device is present in the device t= ree + * 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 =3D strrchr(prop->name, '-'); + if (supply && !strcmp(supply, "-supply")) + return true; + } + + return false; +} + #endif /* CONFIG_PCI */ =20 /** 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); =20 int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *br= idge); +bool of_pci_is_supply_present(struct device_node *np); =20 #else static inline int @@ -793,6 +794,10 @@ static inline int devm_of_pci_bridge_init(struct devic= e *dev, struct pci_host_br return 0; } =20 +static inline bool of_pci_is_supply_present(struct device_node *np); +{ + return false; +} #endif /* CONFIG_OF */ =20 struct of_changeset; --=20 2.25.1 From nobody Mon Nov 25 19:32:59 2024 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 DDB3E1B6CFE; Fri, 25 Oct 2024 07:55: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=1729842903; cv=none; b=or8NnwriOZpp4WkTjGNnhNLc0Vu2j8KLceSCcCFQ71d3D6faD6x2wdJFpU4/tOsk76eFDfNIJERcUKnkwrOrIlfmgIstiOQHNL8IiQnpQzVqah9nyOkXYNGsR/+jDdt5RS2yJsgcHubysBR0iMDJq84lfOotnzdAQvNz8utlxzQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729842903; c=relaxed/simple; bh=6Zz1+8UQ+gRQtPQcE4dfRWTCnVCr+rCSzukMsoj9POE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U70uvcBOzIk3n7U8uhcmFS4q108iwwAW2zcD86ebjVMxVopygEvYqa4Geo4QOEaDHlgrzZmUbIQGYruKmzU4nNbhWiK8WoeRPbUIQw64KeUQxKSMT4euXBmO+s7D4USs7xqkQD4Z9G5CgRJ5rf1/o6Uxv8jW1J4Hjh5OCmhgAEk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SQ0RqoOI; 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="SQ0RqoOI" Received: by smtp.kernel.org (Postfix) with ESMTPS id 90C4AC4CEE7; Fri, 25 Oct 2024 07:55:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729842902; bh=6Zz1+8UQ+gRQtPQcE4dfRWTCnVCr+rCSzukMsoj9POE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=SQ0RqoOIr87KvANry/zUAp9ZA6OkgbDppGDtluRjzfx2t/P3KTEycgK8AMo7JSI37 Puj4ZkQmltU/BogYSD72vY3C8kFNCK6poLvZgc4SmDVJ4gJBvhEdPR9HkhuNJhsAMf ga43RXhRR7CeRdwm3D8NXuzyTVDQwe+krCbX7YJjhTyBIEYoLqnfFzQbymRZpFWaX6 2KFg+Yq3aajQk1oUPlmTzkewFBjfLaEBv0rfAptBTDYyVHF08p8tHZq2OYC2jHIMd6 YffKmtxrXDpb++j+zZ0fEGccI1x0/UUN/H2wFKhZ+L5Mf4chRDqpKAJrsroeM/hcuQ 9zIb6EJvCYBIw== 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 86B34D1171E; Fri, 25 Oct 2024 07:55:02 +0000 (UTC) From: Manivannan Sadhasivam via B4 Relay Date: Fri, 25 Oct 2024 13:24:53 +0530 Subject: [PATCH v2 3/5] PCI/pwrctl: Ensure that the pwrctl drivers are probed before the PCI client drivers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241025-pci-pwrctl-rework-v2-3-568756156cbe@linaro.org> References: <20241025-pci-pwrctl-rework-v2-0-568756156cbe@linaro.org> In-Reply-To: <20241025-pci-pwrctl-rework-v2-0-568756156cbe@linaro.org> To: Bjorn Helgaas , Bartosz Golaszewski , 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, Krishna chaitanya chundru X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4495; i=manivannan.sadhasivam@linaro.org; h=from:subject:message-id; bh=EJwi7MnIXTiK0r2tSMkrSv6SfPORpF4ib++0r7C5Cos=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBnG07TEwDFEenaEuGI5bs1sqUfLij27545ROkPN 0E7ShticvaJATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCZxtO0wAKCRBVnxHm/pHO 9fATB/96vzhoyKSQV7mMp+b6r2+6EacrN1wXaVge7+aNs0+A7bbfPVzO+IU80zvzW+qh+9m0DPC Zz/FRJ1zkI+l8fysyN+FyB6V3aQE2z+aW+P4RvtBK6uWn70g2qA6vCZxmzkWzAizweqv6Hd6vtZ VgviJIj9jPUCrrwV8l5on/HTHnZdpem2MOP/lvsAgsQ6xQynvjsGFKn7t9rGumgGXMWmsVcgy0w xJB446sqaGIbcoSgvrblmzRVaxB0nU8PWb5Rqsn5q6u9fkAK+CKzJGPmLvNm1r+uy+Kajqdu/gN uuoiiISy+yzFjbC7oA+ufMV+g9aMqjwQpwVzXXF2TTefYEw3 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 node= s of the port node") Reviewed-by: Bartosz Golaszewski Tested-by: Krishna chaitanya chundru Tested-by: Bartosz Golaszewski Signed-off-by: Manivannan Sadhasivam --- 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 02a492aa5f17..645bbb75f8f9 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); =20 - dev->match_driver =3D !dn || of_device_is_available(dn); - retval =3D device_attach(&dev->dev); - if (retval < 0 && retval !=3D -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_available_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 =3D 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 =3D !dn || of_device_is_available(dn); + retval =3D device_attach(&dev->dev); + if (retval < 0 && retval !=3D -EPROBE_DEFER) + pci_warn(dev, "device attach failed (%d)\n", retval); + + pci_dev_assign_added(dev, true); } EXPORT_SYMBOL_GPL(pci_bus_add_device); =20 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 =3D true; break; - case BUS_NOTIFY_BOUND_DRIVER: - pwrctl->link =3D 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; } =20 return NOTIFY_DONE; --=20 2.25.1 From nobody Mon Nov 25 19:32:59 2024 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 DDAD8199237; Fri, 25 Oct 2024 07:55: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=1729842903; cv=none; b=eDzRdNuBFZvVhMqDWco2avZ4Bj+1vGeY7xDCYa1QLRUwxt5rVS9i3gThvtV6kO+5ZjXd71sZyHxgzU3Z45zzGv4ASNVB8k7jb4GfqTwPHGCqXhjNAiaz/OgtiBy4pnW9Sa2AH88+7wjbh7SaPHuUyomxElc4QJLOGVdZ9Lat/N8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729842903; c=relaxed/simple; bh=xsioCY39TMmED4dmq57286M326Pu5X0lo5xq75LORhM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jpbgIwGsBdbgjRwsxCRbNrgh4QQhKXD4boo4hLwpfCq/W64nPx8FYzU3+LF6J2XQClfoW0SBd1ie4LNxQ2MZzUGi8oaAFQu4p5GKQcEwmxRBbX0q4E3AcAkVfN4sxZzfuniIJSyr/b+pW1yyREmrRsDPaNKYfHpcLStrWxYhgS8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hFPTLDMB; 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="hFPTLDMB" Received: by smtp.kernel.org (Postfix) with ESMTPS id 9E914C4CEE8; Fri, 25 Oct 2024 07:55:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729842902; bh=xsioCY39TMmED4dmq57286M326Pu5X0lo5xq75LORhM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=hFPTLDMB2EIwbwnDV5uPvFVg4rp4l7feinLaAWUrv5XcTxwnKL2PRQ8Rglf3o6p+u TmbOt1fomWK9Cg+zg/d+LjEWH47ILV3Xy3RfdWKsEo1LBS93Mpof9lBMhEA/QFO0l1 LqRQyaVhsAoRYXa0TjGjaAMskalBts3c5VwpnTrdYoyp0/iDJGfG0bMI3S+BdbGbQ5 5fCJPjbFxWBSBAMUVQB6MHuAq5njovLFW80TyTwbk/1KvOi5QmF/Iyxwq3iztQLkjj ChgyciUrLQoh8o6uib+vuJkiq2CM1U+Pux3NBsLo3FTpLBa0sTb89ZgS68dR/DFkVI GrXyzv1u7NBMw== 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 94A63D1171C; Fri, 25 Oct 2024 07:55:02 +0000 (UTC) From: Manivannan Sadhasivam via B4 Relay Date: Fri, 25 Oct 2024 13:24:54 +0530 Subject: [PATCH v2 4/5] PCI/pwrctl: Move pwrctl device creation to its own helper function Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241025-pci-pwrctl-rework-v2-4-568756156cbe@linaro.org> References: <20241025-pci-pwrctl-rework-v2-0-568756156cbe@linaro.org> In-Reply-To: <20241025-pci-pwrctl-rework-v2-0-568756156cbe@linaro.org> To: Bjorn Helgaas , Bartosz Golaszewski , 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 , Krishna chaitanya chundru X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=3016; i=manivannan.sadhasivam@linaro.org; h=from:subject:message-id; bh=umde/gEf3xryIYWhEQXTOZb+OYyr+RucmbbfjNEuNcQ=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBnG07UGAg9nkrolL4cB2g9Lnx0saPQGfzOUZKEF 4f39fULM7uJATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCZxtO1AAKCRBVnxHm/pHO 9XIyCACmIiZaGcBALCNfIceqSQuEMavLpnbUGB4PRhmxgVrRK3KsjTE3altX3gKuayVDbA6MR3Z YiUMRxKobB14WbeJfc/fRDsre7fZ2+azeqIhWHn+u8UYO7SH7+jOE+hh+9jmwrebUljwPUfz8JH +8vK8++I8r4WniCN1YNdSVFJHIIhhG1UAbNsC+1wnoFEuM03eV6J0EQ9+4TB68NzIe2r0laSe0h 1THtkvz3FZ7xxNR3pX5foODZnCS6KsBzIagXJ2Woiv+gNZ1nkt6A0bFU20MFJj+r+In1XBy79lE Ysj3gxw/BxiBmLvcIRKdN9h8CNds8DilRH01bXxFviD4AVYd 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. Tested-by: Krishna chaitanya chundru Tested-by: Bartosz Golaszewski Signed-off-by: Manivannan Sadhasivam Reviewed-by: Bartosz Golaszewski --- 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 645bbb75f8f9..6e38984e576d 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) { } =20 void __weak pcibios_bus_add_device(struct pci_dev *pdev) { } =20 +/* + * Create pwrctl devices (if required) for the PCI devices to handle the p= ower + * state. + */ +static void pci_pwrctl_create_devices(struct pci_dev *dev) +{ + struct device_node *np =3D dev_of_node(&dev->dev); + struct device *parent =3D &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_available_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 =3D 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); =20 - if (dev_of_node(&dev->dev) && pci_is_bridge(dev)) { - for_each_available_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 =3D 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); =20 /* * Create a device link between the PCI device and pwrctl device (if --=20 2.25.1 From nobody Mon Nov 25 19:32:59 2024 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 472521C4622; Fri, 25 Oct 2024 07:55: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=1729842903; cv=none; b=BbKxldvZ2uVfv/2QPu8sCqs5ubwy11mEOdxRfJIKBxbaJ5U12RNQATSsB9Molkvs+BvxpO4FkHuW3P/de8aRS7f0LWHR5uutLLSfjzzE7eV26hrQVehCdgtmIjtILvBCZWOFL1ctG7rlB2FyxH8WnPAM2N5bT3cTQtlWh9m4cGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729842903; c=relaxed/simple; bh=oQKJemLv+DazWWrWtxj8bo8GJRraMiPexo9TrSDVMUw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ADUNO1fR3fwRD1oCOI4WNlOdnUTw7wzZYGAtHqk8/AJE/mT8IoeM7Uv1b/O4T7xebvTQ2kd9+urTgI7aA+iHjz6zYw+qJ0PHm6zn/U2/fw/RpwzJkp+zVOnAHc7QfR5VWFevicNHMEidj+/V8FFM8Z7mewY5F78SvWBDtjNoTjs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X7ra5R3S; 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="X7ra5R3S" Received: by smtp.kernel.org (Postfix) with ESMTPS id ABD3AC4CEEB; Fri, 25 Oct 2024 07:55:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729842902; bh=oQKJemLv+DazWWrWtxj8bo8GJRraMiPexo9TrSDVMUw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=X7ra5R3SxN/kvMECqGOUhOGf5mwqrNhRmBJAWYAmPMZKSGQ49Hr3QSX0QOXS9Fuft xzjUJSotuqXmXcoLJoS2A7yMayCa+VAHLbEGe/n0EzwUTdB14RvmzkNjFBK6if0aV0 pWE9Qvi0Fjh1qy+TwC/+UQPXP1uA591FLbpzmqO1c7qY/L+YeTeBwj/V1+SBPdoZbn IBtOPr3cns8vdLiH50NRKcj9X61S6D4vHviVV6gg10Oax9D44fPgskp4ceVvzTMErA Cec/RifNnTPnQVk5n2hOBQ4vTiTd3a9Byq1UygcZk54h391toN8a0B1AJVtUVcU87i JoXJpBaeb4VVg== 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 A1AF2D1171F; Fri, 25 Oct 2024 07:55:02 +0000 (UTC) From: Manivannan Sadhasivam via B4 Relay Date: Fri, 25 Oct 2024 13:24:55 +0530 Subject: [PATCH v2 5/5] PCI/pwrctl: Remove pwrctl device without iterating over all children of pwrctl parent Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241025-pci-pwrctl-rework-v2-5-568756156cbe@linaro.org> References: <20241025-pci-pwrctl-rework-v2-0-568756156cbe@linaro.org> In-Reply-To: <20241025-pci-pwrctl-rework-v2-0-568756156cbe@linaro.org> To: Bjorn Helgaas , Bartosz Golaszewski , 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 , Krishna chaitanya chundru X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2043; i=manivannan.sadhasivam@linaro.org; h=from:subject:message-id; bh=ZMmwlwCRSzjhOUE5z4PNfZQoS9fl60qTZUGrmIa0oTI=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBnG07UrEI+ygFFYRiJquOhxF3/HIbsroWH7tQhL aK5AVibzrqJATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCZxtO1AAKCRBVnxHm/pHO 9RnwB/0Wzu1JRJdjBTy8WSMsnT+5odUgmGM2uRrgVJHOE75GND9wNiKEqdu3tffLo3uQIe4l+QN q2huoKlgRmUe88U77wsCXrHnZBdLjwByElTa4uP1CoSJfC7RJvx9a+2+BtWVezy4ufj0FYN/Ca/ kC75FJPe4y8bCWDgA20i2nbRfZ1kUi56iOGrhN9QOUg4UHPaa7bewh0WAyDGsp5TcIE/Bz8gg41 PbB0Q+ucWngtUGqsttOdjhn+CMjo+udGDfJgdC+aI2VdRbd1OYdgUe4xbMSuKwgkd65wmEXq1g2 V+n8/BxngjXH+alX4zivvBwsnFiU42THzJRmBsptvG0Dk3b9 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. Reviewed-by: Bartosz Golaszewski Tested-by: Krishna chaitanya chundru Tested-by: Bartosz Golaszewski Signed-off-by: Manivannan Sadhasivam --- 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) } } =20 -static int pci_pwrctl_unregister(struct device *dev, void *data) +static void pci_pwrctl_unregister(struct device *dev) { - struct device_node *pci_node =3D data, *plat_node =3D dev_of_node(dev); + struct platform_device *pdev; =20 - if (dev_is_platform(dev) && plat_node && plat_node =3D=3D pci_node) { - of_device_unregister(to_platform_device(dev)); - of_node_clear_flag(plat_node, OF_POPULATED); - } + pdev =3D of_find_device_by_node(dev_of_node(dev)); + if (!pdev) + return; =20 - return 0; + of_device_unregister(pdev); + of_node_clear_flag(dev_of_node(dev), OF_POPULATED); } =20 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); =20 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); --=20 2.25.1