From patchwork Tue Mar 26 10:48:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 13603898 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D931D17C6B for ; Tue, 26 Mar 2024 10:49:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711450143; cv=none; b=Y2QKYS6lowQzB+Xq/frJsvAMMoT4EG7w4SMjLtzYC1wUz1m/duqhNVsmZJEFfa4tXVIKxAD8ZHBk/6hFKug2f5XTMtntMCalkcExJsCGV6QHxEHBa0WmpOBud2jSKihHe2gMUMXtT+EvacRcvWins4ULdIGW+W8ZOOYw4ZYcU38= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711450143; c=relaxed/simple; bh=a9jhEQgepLFu1V/9oFFkAbVrqrZxzbztMATHDJFc3OU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WhA1Cu62BIvGIxjWXf7So9JYquXxvXuYyrSP0K9BsyGiMfz2DuoVM3h2k3g52eQZoWlYuFbzgTh8PJg+wr64M+RXFUS0m9i1ZusOf2Fg6vs5v5uSjZcsXoUnrqNIieHrVeWy/uREnkjlhqB4MKitVPAlJlzpHBrG5l9p8myVtJw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=DKI9rqcO; arc=none smtp.client-ip=209.85.215.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="DKI9rqcO" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-5dcc4076c13so3347466a12.0 for ; Tue, 26 Mar 2024 03:49:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711450141; x=1712054941; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=f3SaotDWl/4tLhYj27mIQOcHctxJufPLQpgAq2r/Phs=; b=DKI9rqcOywAd/xF3C0HFG0zlBOPpf6/tdssQ9ECGiIrOYlM0+27o5d8M53lawXcz5L wEQQR80kSaPJX9H9NoAI/cyw0nnVkF1lJedokvO7BKIP0eASiioZv4zv8TpG6PL6A7tw oIyzCv32Yr/nqRn4VRUUBNrfQT6NRqDLWEN7SwKf0zwB00TP3RB49GlIBrYNn9G/0/jf PUS4IZ4ypkc/mHRJh+i9AOCvGzYpnnrqkhHgpmaR6d3Jok8tZISq4kdwhbPRzkPCYNcm ZqGT0VbrkB+yw6q1Ry2+DGb1SSf8JlIIzlhyDxvjH3OXH2vGWjWAx3NPsoZoU3ArFEiA b1mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711450141; x=1712054941; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f3SaotDWl/4tLhYj27mIQOcHctxJufPLQpgAq2r/Phs=; b=PU5ZggpFaJ2RymqpYQZ7Q3f8kATdmfS21/l64z3IVWBV2wGOacrkpfAA8XTB1CV1iv fLw/5A1OPJiWb3lnNFJFQBWAhlvSZVhZY2AWbJNd77ekyhher5nVp7NFfSxAUh6+flk9 VG5XILn0xZeti0bFtBQR3egPMc+YWs9PegHd45naaPAUIsGzLKutptFk+O5SXfrx6fm3 UI4QDKucLEkE6e04L/hIci2KZp81qrOEIuCEM9Y8ObXjbkwnthzL7SxoYKhfRagsZgtU NLxGw+fDWrnRnCO4Y+blftdFEiTyEYD3nIbevyVwU2AJmA+G1qzQAKw+glFf/xC6jgpe 8qxw== X-Forwarded-Encrypted: i=1; AJvYcCVARfnqVpeksDrj8BUq/pxVuFhmPxaVBPDjqhNtIq0jiwy9IxlnHalq8kIdRcPzqWISpg7ZJHzBXFy9aIrCjnzMZRBfRhSteFVUmA== X-Gm-Message-State: AOJu0YzMZ7mF1V+4LryVL+GJXFjriH8Sz7L75vGktyH+9EmzQ0ewQe4s NVfYwm14SNoHtuEZYpHpi9hqXVKykcmRXZO47RfBrKycN0ugDguFZC4VRjI8lQ== X-Google-Smtp-Source: AGHT+IHlO3+pLdIHsXr+Zqk4ZTZm+g6rYTdPkIaErY2qnQHcr3IGV3c/Zdyg8NfbLAv1QA3Qf4eobw== X-Received: by 2002:a17:90a:c788:b0:2a0:8eee:5603 with SMTP id gn8-20020a17090ac78800b002a08eee5603mr706623pjb.6.1711450140840; Tue, 26 Mar 2024 03:49:00 -0700 (PDT) Received: from [127.0.1.1] ([117.207.28.168]) by smtp.gmail.com with ESMTPSA id i22-20020a17090a059600b0029fc196159bsm8777218pji.30.2024.03.26.03.48.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 03:49:00 -0700 (PDT) From: Manivannan Sadhasivam Date: Tue, 26 Mar 2024 16:18:17 +0530 Subject: [PATCH v4 1/4] PCI/portdrv: Make use of pci_dev::bridge_d3 for checking the D3 possibility Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240326-pci-bridge-d3-v4-1-f1dce1d1f648@linaro.org> References: <20240326-pci-bridge-d3-v4-0-f1dce1d1f648@linaro.org> In-Reply-To: <20240326-pci-bridge-d3-v4-0-f1dce1d1f648@linaro.org> To: Bjorn Helgaas , "Rafael J. Wysocki" , Len Brown Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, lukas@wunner.de, mika.westerberg@linux.intel.com, Manivannan Sadhasivam X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=1566; i=manivannan.sadhasivam@linaro.org; h=from:subject:message-id; bh=a9jhEQgepLFu1V/9oFFkAbVrqrZxzbztMATHDJFc3OU=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBmAqgUbSOKJVFNG5vo+m1rTB5ZtU8V4c/GTGvtz SRWC0jHPCGJATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCZgKoFAAKCRBVnxHm/pHO 9X8aB/4mHeDmAABHwdZVT2KCy3Oi2k8U3Euk7a/eKi2F/KDGkvTB2juxg6mHFSYM6GAAuFUEMqv H1bqB0ctCMAnm5M9Ic8ML+rjdYiCCs9iX4FoXtSkqIyMg/Ggvcugfyq0z7cSSmSSVchACmFV1zN CxqohHwRG9XlbS9KWYTXkDRs77JklCpTdk4Yb4wTD8sxVCevT9xo0dNymysXSEwDVr8c7oNTTX3 EVeeOnwqSgTgtNxsxVLVRlme4T+xTuZVYT9IXPrPtq0KWXk29YZZ3RvD8R96F3tVWLjByX3oFh9 fmHw26ZXd7Fl0Ca0GWeUwfyszN1gouLii9fer4v1Hb2tPDra X-Developer-Key: i=manivannan.sadhasivam@linaro.org; a=openpgp; fpr=C668AEC3C3188E4C611465E7488550E901166008 PCI core is already caching the value of pci_bridge_d3_possible() in pci_dev::bridge_d3 during pci_pm_init(). Since the value is not going to change, let's make use of the cached value. Signed-off-by: Manivannan Sadhasivam --- drivers/pci/pcie/portdrv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/pci/pcie/portdrv.c b/drivers/pci/pcie/portdrv.c index 14a4b89a3b83..1f02e5d7b2e9 100644 --- a/drivers/pci/pcie/portdrv.c +++ b/drivers/pci/pcie/portdrv.c @@ -702,7 +702,7 @@ static int pcie_portdrv_probe(struct pci_dev *dev, dev_pm_set_driver_flags(&dev->dev, DPM_FLAG_NO_DIRECT_COMPLETE | DPM_FLAG_SMART_SUSPEND); - if (pci_bridge_d3_possible(dev)) { + if (dev->bridge_d3) { /* * Keep the port resumed 100ms to make sure things like * config space accesses from userspace (lspci) will not @@ -720,7 +720,7 @@ static int pcie_portdrv_probe(struct pci_dev *dev, static void pcie_portdrv_remove(struct pci_dev *dev) { - if (pci_bridge_d3_possible(dev)) { + if (dev->bridge_d3) { pm_runtime_forbid(&dev->dev); pm_runtime_get_noresume(&dev->dev); pm_runtime_dont_use_autosuspend(&dev->dev); @@ -733,7 +733,7 @@ static void pcie_portdrv_remove(struct pci_dev *dev) static void pcie_portdrv_shutdown(struct pci_dev *dev) { - if (pci_bridge_d3_possible(dev)) { + if (dev->bridge_d3) { pm_runtime_forbid(&dev->dev); pm_runtime_get_noresume(&dev->dev); pm_runtime_dont_use_autosuspend(&dev->dev); From patchwork Tue Mar 26 10:48:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 13603899 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2964E4C618 for ; Tue, 26 Mar 2024 10:49:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711450148; cv=none; b=ttCEuT7+TzTrSH8iJvonrhovP98Du70heChtkrn88wbzjJdb3JgfmYI1bcr7FXAde4BmhugN2XeJFpg22g8CBuLye/OitHR36zjxjkky/ZKiR5ny1XW6iM+Qdnwsffa9FrKqhd4nGSkoJrLcTCqUW24Xu1KTXw7LB0vbycfOPnU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711450148; c=relaxed/simple; bh=2C+v6Wm3sjfQZlJTnA10pqcNYIb7iWI0WDKQl60uU8A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YHQEh8/Eh+Za+j2e/At9sIZ2+GdUymob7iYUlTYAKL1fFfxQuILrTUZDYkuKQerh5CPN7mbyQdBxLYZKNRv8t+agHH+9CMl9o3WjMSfxY3y4MKPP21DGtk1j9A3l76Bu4Cy6oXsqc7Xcrs3DnCxgRWp5XwDVdeNJZdfXUIHaVJo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=vymFVDka; arc=none smtp.client-ip=209.85.215.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="vymFVDka" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-5d4d15ec7c5so3738363a12.1 for ; Tue, 26 Mar 2024 03:49:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711450145; x=1712054945; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=M0SMBhJid5kSy8nYHMJnAIAjjlVqaxbVM8G3mLgiceQ=; b=vymFVDkawMA31cBV5rEmOmgRs1NwMVdtPdU0ufsGnE0z5TEowtixUnfIA9Bo+FzHjU mslrROMng4wlwIUgsTjbNz/64CYMs33sDfFnY4OG+CDszQkQo6AT8YMfliPYipFBcO0H sO0/rcw8fG75LKkh1Gqxh4nR/UY2bQX1Hm6AMYQond5OCbXWOInG+vgsn+J/5tMYfwxE OB+2vGwfWhAPucmNC4qYmRYjY5lb6yyp/uoU8wY86ECuU6xjwtP4sbgfviZ2TSK5AM9C ER3NeYYPiZAM6ip4cbY7L1987UrqMrX5BKd/dR45K00iOQ4MNwyvZ8KCrHqRUY1WRKDW /prA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711450145; x=1712054945; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M0SMBhJid5kSy8nYHMJnAIAjjlVqaxbVM8G3mLgiceQ=; b=nPaZPCcq7/oKgnUR8G84G94ZYlGgOSrQNY1k/Hz1A2Xy/GzWKPXkVw4xZ6GQuJ11uU dmoC3+xzcBouo0RKqERUFgNVd3HCLGeN9y/Z19n5WuzDytX3KveQAnHDnqNA9t9rRijS d1X9RD4LGkXEYEhD/MLR/8XhCZ4ZgrFMiyIBGeNkJrzCDOBfgiDqAWihCZMZ8wSLH33o LxznHD4jL8KAQCzHAsAnBQ/8iRnHQ39Lh8naV1yGLcKxOHDpDzubQeTbr8s2JCVSI5ro 8Dn6J/LUQfFEWNT8HIr++v4yUL7/nHyOc3lrsQwdk73euuIpTrmrMzgVF6QdextRVdns y+uA== X-Forwarded-Encrypted: i=1; AJvYcCV3aPXhueFwsXat5sBGprtauEpTIOXkSxF3y+7nzj/atrhIS/ZI/XTRcsVI3ChYFgL9RyJWaKMHOTnWdx/cVWWRnp1Ytg4cIC8EYA== X-Gm-Message-State: AOJu0YzFf8+XnxzA9eiTNzy+3/Erff2PDqNBNrRq/3aDthfpMEObk02V i+1QuI9PWcIpJwu0PzSijB2wmmm/vj+ulqtqCMYg8siXptptf/LmU+n8PIZ7Tg== X-Google-Smtp-Source: AGHT+IHAftgjEZWHlDTh3ETzNXkoUDSq1fobXK/j1pHm/3OYwfeTvWUyP6CBV1UN3R769tCbCiu7WA== X-Received: by 2002:a17:90a:d517:b0:29e:d30:5b2c with SMTP id t23-20020a17090ad51700b0029e0d305b2cmr8699221pju.18.1711450145228; Tue, 26 Mar 2024 03:49:05 -0700 (PDT) Received: from [127.0.1.1] ([117.207.28.168]) by smtp.gmail.com with ESMTPSA id i22-20020a17090a059600b0029fc196159bsm8777218pji.30.2024.03.26.03.49.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 03:49:04 -0700 (PDT) From: Manivannan Sadhasivam Date: Tue, 26 Mar 2024 16:18:18 +0530 Subject: [PATCH v4 2/4] PCI: Rename pci_bridge_d3_possible() to pci_bridge_d3_allowed() Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240326-pci-bridge-d3-v4-2-f1dce1d1f648@linaro.org> References: <20240326-pci-bridge-d3-v4-0-f1dce1d1f648@linaro.org> In-Reply-To: <20240326-pci-bridge-d3-v4-0-f1dce1d1f648@linaro.org> To: Bjorn Helgaas , "Rafael J. Wysocki" , Len Brown Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, lukas@wunner.de, mika.westerberg@linux.intel.com, Manivannan Sadhasivam , Bjorn Helgaas X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=8265; i=manivannan.sadhasivam@linaro.org; h=from:subject:message-id; bh=2C+v6Wm3sjfQZlJTnA10pqcNYIb7iWI0WDKQl60uU8A=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBmAqgUPyirfQ7e4W3oQM7fjbqh0BJDFKv0WBsQT r6gQ6En/c+JATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCZgKoFAAKCRBVnxHm/pHO 9dpFCACZIJLlmPE1Lh039AAQKRYeTV75R8+K1zgyIoFMW2CJXZY6/ZQjx4WWg9BEKW1PxAlCQfB Mb0G3Oi3zuT+1MzSq7kAoVWfpuNDt6Vp9oBZH5hXdD5VjbmGudBc+b4T1yE/0R1D/soN+lqoFFW EmZJZrsSjHdEWcz2GBOl7JVeDi8jkTA/7udDaQxtPx1XFYLnu5sHW761nhONEd3LGMT6vMVA8M+ eEE0VFAcQYvLw5rGdiQKplXfMT+GmgOyc5fYgSNwOKvizysKBiSgYJHm+pxEJi30wuMwcopXLuN b1YIpO5DzTjPZiy+QAwK+kMOgrt0eLIwK1BPGatF20PhDtsq X-Developer-Key: i=manivannan.sadhasivam@linaro.org; a=openpgp; fpr=C668AEC3C3188E4C611465E7488550E901166008 As per the 'PCI Bus Power Management Interface Specification' v1.2, all devices should support D3 states (both D3Hot and D3Cold). So the term 'possible' doesn't make sense for the bridge devices, since D3 states should be possible as per the design. But due to various circumstances, D3 states might not be allowed for the bridges. In those cases, the API should be called 'pci_bridge_d3_allowed()' to reflect the actual behavior. So let's rename it. This also warrants renaming the variable 'bridge_d3' in 'struct pci_dev' to 'bridge_d3_allowed' for the reason cited above. No functional change. Reported-by: Bjorn Helgaas Closes: https://lore.kernel.org/linux-pci/20240305175107.GA539676@bhelgaas/ Signed-off-by: Manivannan Sadhasivam --- drivers/pci/pci-acpi.c | 8 ++++---- drivers/pci/pci.c | 18 +++++++++--------- drivers/pci/pci.h | 4 ++-- drivers/pci/pcie/portdrv.c | 14 +++++++------- include/linux/pci.h | 2 +- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index 004575091596..0f260cdc4592 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c @@ -1429,12 +1429,12 @@ void pci_acpi_setup(struct device *dev, struct acpi_device *adev) device_set_wakeup_capable(dev, true); /* - * For bridges that can do D3 we enable wake automatically (as - * we do for the power management itself in that case). The + * For bridges that are allowed to do D3, we enable wake automatically + * (as we do for the power management itself in that case). The * reason is that the bridge may have additional methods such as * _DSW that need to be called. */ - if (pci_dev->bridge_d3) + if (pci_dev->bridge_d3_allowed) device_wakeup_enable(dev); acpi_pci_wakeup(pci_dev, false); @@ -1452,7 +1452,7 @@ void pci_acpi_cleanup(struct device *dev, struct acpi_device *adev) pci_acpi_remove_pm_notifier(adev); if (adev->wakeup.flags.valid) { acpi_device_power_remove_dependent(adev, dev); - if (pci_dev->bridge_d3) + if (pci_dev->bridge_d3_allowed) device_wakeup_disable(dev); device_set_wakeup_capable(dev, false); diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index e5f243dd4288..0edc4e448c2d 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2967,13 +2967,13 @@ static const struct dmi_system_id bridge_d3_blacklist[] = { }; /** - * pci_bridge_d3_possible - Is it possible to put the bridge into D3 + * pci_bridge_d3_allowed - Is it allowed to put the bridge into D3 * @bridge: Bridge to check * - * This function checks if it is possible to move the bridge to D3. + * This function checks if the bridge is allowed to move to D3. * Currently we only allow D3 for recent enough PCIe ports and Thunderbolt. */ -bool pci_bridge_d3_possible(struct pci_dev *bridge) +bool pci_bridge_d3_allowed(struct pci_dev *bridge) { if (!pci_is_pcie(bridge)) return false; @@ -3060,14 +3060,14 @@ void pci_bridge_d3_update(struct pci_dev *dev) bool d3cold_ok = true; bridge = pci_upstream_bridge(dev); - if (!bridge || !pci_bridge_d3_possible(bridge)) + if (!bridge || !pci_bridge_d3_allowed(bridge)) return; /* * If D3 is currently allowed for the bridge, removing one of its * children won't change that. */ - if (remove && bridge->bridge_d3) + if (remove && bridge->bridge_d3_allowed) return; /* @@ -3087,12 +3087,12 @@ void pci_bridge_d3_update(struct pci_dev *dev) * so we need to go through all children to find out if one of them * continues to block D3. */ - if (d3cold_ok && !bridge->bridge_d3) + if (d3cold_ok && !bridge->bridge_d3_allowed) pci_walk_bus(bridge->subordinate, pci_dev_check_d3cold, &d3cold_ok); - if (bridge->bridge_d3 != d3cold_ok) { - bridge->bridge_d3 = d3cold_ok; + if (bridge->bridge_d3_allowed != d3cold_ok) { + bridge->bridge_d3_allowed = d3cold_ok; /* Propagate change to upstream bridges */ pci_bridge_d3_update(bridge); } @@ -3167,7 +3167,7 @@ void pci_pm_init(struct pci_dev *dev) dev->pm_cap = pm; dev->d3hot_delay = PCI_PM_D3HOT_WAIT; dev->d3cold_delay = PCI_PM_D3COLD_WAIT; - dev->bridge_d3 = pci_bridge_d3_possible(dev); + dev->bridge_d3_allowed = pci_bridge_d3_allowed(dev); dev->d3cold_allowed = true; dev->d1_support = false; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 17fed1846847..53ca75639201 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -92,7 +92,7 @@ void pci_pm_init(struct pci_dev *dev); void pci_ea_init(struct pci_dev *dev); void pci_msi_init(struct pci_dev *dev); void pci_msix_init(struct pci_dev *dev); -bool pci_bridge_d3_possible(struct pci_dev *dev); +bool pci_bridge_d3_allowed(struct pci_dev *dev); void pci_bridge_d3_update(struct pci_dev *dev); int pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, char *reset_type); @@ -113,7 +113,7 @@ static inline bool pci_power_manageable(struct pci_dev *pci_dev) * Currently we allow normal PCI devices and PCI bridges transition * into D3 if their bridge_d3 is set. */ - return !pci_has_subordinate(pci_dev) || pci_dev->bridge_d3; + return !pci_has_subordinate(pci_dev) || pci_dev->bridge_d3_allowed; } static inline bool pcie_downstream_port(const struct pci_dev *dev) diff --git a/drivers/pci/pcie/portdrv.c b/drivers/pci/pcie/portdrv.c index 1f02e5d7b2e9..8401a0f7b394 100644 --- a/drivers/pci/pcie/portdrv.c +++ b/drivers/pci/pcie/portdrv.c @@ -632,7 +632,7 @@ __setup("pcie_ports=", pcie_port_setup); #ifdef CONFIG_PM static int pcie_port_runtime_suspend(struct device *dev) { - if (!to_pci_dev(dev)->bridge_d3) + if (!to_pci_dev(dev)->bridge_d3_allowed) return -EBUSY; return pcie_port_device_runtime_suspend(dev); @@ -641,11 +641,11 @@ static int pcie_port_runtime_suspend(struct device *dev) static int pcie_port_runtime_idle(struct device *dev) { /* - * Assume the PCI core has set bridge_d3 whenever it thinks the port - * should be good to go to D3. Everything else, including moving + * Assume the PCI core has set bridge_d3_allowed whenever it thinks the + * port should be good to go to D3. Everything else, including moving * the port to D3, is handled by the PCI core. */ - return to_pci_dev(dev)->bridge_d3 ? 0 : -EBUSY; + return to_pci_dev(dev)->bridge_d3_allowed ? 0 : -EBUSY; } static const struct dev_pm_ops pcie_portdrv_pm_ops = { @@ -702,7 +702,7 @@ static int pcie_portdrv_probe(struct pci_dev *dev, dev_pm_set_driver_flags(&dev->dev, DPM_FLAG_NO_DIRECT_COMPLETE | DPM_FLAG_SMART_SUSPEND); - if (dev->bridge_d3) { + if (dev->bridge_d3_allowed) { /* * Keep the port resumed 100ms to make sure things like * config space accesses from userspace (lspci) will not @@ -720,7 +720,7 @@ static int pcie_portdrv_probe(struct pci_dev *dev, static void pcie_portdrv_remove(struct pci_dev *dev) { - if (dev->bridge_d3) { + if (dev->bridge_d3_allowed) { pm_runtime_forbid(&dev->dev); pm_runtime_get_noresume(&dev->dev); pm_runtime_dont_use_autosuspend(&dev->dev); @@ -733,7 +733,7 @@ static void pcie_portdrv_remove(struct pci_dev *dev) static void pcie_portdrv_shutdown(struct pci_dev *dev) { - if (dev->bridge_d3) { + if (dev->bridge_d3_allowed) { pm_runtime_forbid(&dev->dev); pm_runtime_get_noresume(&dev->dev); pm_runtime_dont_use_autosuspend(&dev->dev); diff --git a/include/linux/pci.h b/include/linux/pci.h index 16493426a04f..2a48c88512e1 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -375,7 +375,7 @@ struct pci_dev { unsigned int d2_support:1; /* Low power state D2 is supported */ unsigned int no_d1d2:1; /* D1 and D2 are forbidden */ unsigned int no_d3cold:1; /* D3cold is forbidden */ - unsigned int bridge_d3:1; /* Allow D3 for bridge */ + unsigned int bridge_d3_allowed:1; /* Allow D3 for bridge */ unsigned int d3cold_allowed:1; /* D3cold is allowed by user */ unsigned int mmio_always_on:1; /* Disallow turning off io/mem decoding during BAR sizing */ From patchwork Tue Mar 26 10:48:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 13603900 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 460724F1E2 for ; Tue, 26 Mar 2024 10:49:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711450151; cv=none; b=Jmnbv41wsbRUIFsK+NkG82poedyM7rOb1reYwu79G++5+doKSDZmAMZLwTCuektH+9wmxYpdtPOvvzwlXYceiFOMNs/MyLCHGfSRajSV8BXXlAKMqG58XdbVF9M3SJkAwZesMlinn+xprigM88btLSPUjR+S9ZJJAc5TyBw9qvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711450151; c=relaxed/simple; bh=bF/HcvO7foa6FK6PVUQ7xHq4JKqGIBDDGhSwfre7E3U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=s5hFF5rHMJJrchMOyC/CP7Y71dSuPR/DaW9C3A12tnYIavqXU1/jqONQPYfJnUb6WELW4dYi/egRALXtKyh/+wrRHH1M69S4Rqy/oAFdcUAe+eav8ffRQWRZuoGwJ7Qhfa4UVLAFAb6kmP1UNitFo9lrl+XffrUEX4Yy68/fv4U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=dtE7Jz7X; arc=none smtp.client-ip=209.85.216.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="dtE7Jz7X" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-29de4e12d12so3741047a91.3 for ; Tue, 26 Mar 2024 03:49:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711450148; x=1712054948; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=W+4mr/LaSu8VrSg/TvK0Tq+DsBpYP0fJ/Xusk8aMb0Y=; b=dtE7Jz7X06rlmocHqnJUvUC9k9kfJZpb0bnRdfRuT1089WL6c49pk+uQiL8DHKK8Po Sau8D/9W784UiBOzcb/l/RIhu0LLpjgEiX0EREE4gbbMtb2p/4teW7yBMeeMHxDz6tyu dKkRSpYmGXvj3dxIeJu0PQ2SclU8uqsTqh6DiO0Y4wnnJD6TdOsQlNsn+9bGFbBIrPo6 HQCLiK2CGNUR1Z5Xg2U1i2tM9NEjivBfbGIWGunvvHIBW9NF+gJjXz63+77JNuppeHZO H0iuMySTwO8DlZ00aEKzePoLgvg6eExYbTOEw8oHAMca50tmFFm+XtpaXAOLCD+zVmQE clSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711450148; x=1712054948; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W+4mr/LaSu8VrSg/TvK0Tq+DsBpYP0fJ/Xusk8aMb0Y=; b=IFhVjlA5BY/Yn02VlBTZ1qjFYB59PcpaYM5W4yGkX7/WcSodRjl6RVbQmcckCR5wZI Gx+n5oF6A0s7RQhxxVCyimatY+kY9jbLLFt9L+RXMSd46CFk/LWPBwX33LiG3P+tVTA8 p3wVwZJ7VpfmFWTYCqDoTaAtH5lEkNEUGHRyuUOfA/d62qS/AjWK9WPodvU7PNkRCjXF 2/WjYKTlGxQugpue0yzBoG75JoGGfKLfjZNHMchEZBjxGaKyjk+g4lvNrb0JIwgPlzoM EvS3Si1NyKkoggapOYUkj44syj0S0C6BF9RWwgeDfCPh7QeVKFnVYmuTQUft82fiSG2y Z/ag== X-Forwarded-Encrypted: i=1; AJvYcCU3l2gZ37OdBsB3k2dpibNwYDVR1O3u1BeCZ3mMpv76+XZLg2v5+GAWWlItOkt9wL/3Gl14wHq24MbqGdc9VkVeL+/HfvGyOhIP6A== X-Gm-Message-State: AOJu0Yy2fDP575Fkb4gYmdZ71cx2JVJszHGPbncIe/2Cc8p6wBEEbwWw NmTYZThPtvl6HwlCDDMWrz9GYBYLxFAygm6zCF5FEDNdtyqCV07N2kRyoaWJxg== X-Google-Smtp-Source: AGHT+IGFgqH9fW74hni3EIrs9KNn0YtpEuU8cHXDKX0Z6LTgKUu33Et6V4oRxLUUlNpE9+VZBH2Pow== X-Received: by 2002:a17:90a:bd81:b0:29c:1eb6:7347 with SMTP id z1-20020a17090abd8100b0029c1eb67347mr7269546pjr.6.1711450148467; Tue, 26 Mar 2024 03:49:08 -0700 (PDT) Received: from [127.0.1.1] ([117.207.28.168]) by smtp.gmail.com with ESMTPSA id i22-20020a17090a059600b0029fc196159bsm8777218pji.30.2024.03.26.03.49.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 03:49:08 -0700 (PDT) From: Manivannan Sadhasivam Date: Tue, 26 Mar 2024 16:18:19 +0530 Subject: [PATCH v4 3/4] PCI: Decouple D3Hot and D3Cold handling for bridges Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240326-pci-bridge-d3-v4-3-f1dce1d1f648@linaro.org> References: <20240326-pci-bridge-d3-v4-0-f1dce1d1f648@linaro.org> In-Reply-To: <20240326-pci-bridge-d3-v4-0-f1dce1d1f648@linaro.org> To: Bjorn Helgaas , "Rafael J. Wysocki" , Len Brown Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, lukas@wunner.de, mika.westerberg@linux.intel.com, Manivannan Sadhasivam X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=14019; i=manivannan.sadhasivam@linaro.org; h=from:subject:message-id; bh=bF/HcvO7foa6FK6PVUQ7xHq4JKqGIBDDGhSwfre7E3U=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBmAqgVDUDmtlSozShEyuB/I4ssS2mtzag9TSu7v G4Kav+rIDCJATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCZgKoFQAKCRBVnxHm/pHO 9dA0CACPRcceG6iLUeio+34GVIDQMtnyuY8aRYhlHS3tfAE/ra1oh8Ieeeq48378KPDVrUSbVHS 4eJxeG2tDt7HKGe/dSOfstXYJGzrF0pM8EeSS8lXztccZVE7jWSaGcc+jCTf8mYcIyTgrV4CMHM kXLfnkiLS4lzInB68odhwu3hlP788/KDn90RuJmwkMmM4wcAz3GaTAok8rCjb6fdF/jCa6y+D6i 085iATZHjLjDneCbj86IJy/wYxikrx6aHGBWfF5Y5dn12L/uzVuVl7rRyaPyFCAZs2TVWfj0VwO m1jjXFXfvwa1LHrZvonFhMYnYjye/yTCMsaflbEp/yf0DtbE X-Developer-Key: i=manivannan.sadhasivam@linaro.org; a=openpgp; fpr=C668AEC3C3188E4C611465E7488550E901166008 Currently, there is no proper distinction between D3Hot and D3Cold while handling the power management for PCI bridges. For instance, pci_bridge_d3_allowed() API decides whether it is allowed to put the bridge in D3, but it doesn't explicitly specify whether D3Hot or D3Cold is allowed in a scenario. This often leads to confusion and may be prone to errors. So let's split the D3Hot and D3Cold handling where possible. The current pci_bridge_d3_allowed() API is now split into pci_bridge_d3hot_allowed() and pci_bridge_d3cold_allowed() APIs and used in relevant places. Also, pci_bridge_d3_update() API is now renamed to pci_bridge_d3cold_update() since it was only used to check the possibility of D3Cold. Note that it is assumed that only D3Hot needs to be checked while transitioning the bridge during runtime PM and D3Cold in other places. In the ACPI case, wakeup is now only enabled if both D3Hot and D3Cold are allowed for the bridge. Still, there are places where just 'd3' is used opaquely, but those are hard to distinguish, hence left for future cleanups. Signed-off-by: Manivannan Sadhasivam --- drivers/pci/bus.c | 2 +- drivers/pci/pci-acpi.c | 5 +-- drivers/pci/pci-sysfs.c | 2 +- drivers/pci/pci.c | 78 ++++++++++++++++++++++++++++++---------------- drivers/pci/pci.h | 12 ++++--- drivers/pci/pcie/portdrv.c | 16 +++++----- drivers/pci/remove.c | 2 +- include/linux/pci.h | 3 +- 8 files changed, 75 insertions(+), 45 deletions(-) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 826b5016a101..cb1a1aaefa90 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -346,7 +346,7 @@ void pci_bus_add_device(struct pci_dev *dev) of_pci_make_dev_node(dev); pci_create_sysfs_dev_files(dev); pci_proc_attach_device(dev); - pci_bridge_d3_update(dev); + pci_bridge_d3cold_update(dev); dev->match_driver = !dn || of_device_is_available(dn); retval = device_attach(&dev->dev); diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index 0f260cdc4592..aaf5a68e7984 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c @@ -1434,7 +1434,7 @@ void pci_acpi_setup(struct device *dev, struct acpi_device *adev) * reason is that the bridge may have additional methods such as * _DSW that need to be called. */ - if (pci_dev->bridge_d3_allowed) + if (pci_dev->bridge_d3cold_allowed && pci_dev->bridge_d3hot_allowed) device_wakeup_enable(dev); acpi_pci_wakeup(pci_dev, false); @@ -1452,7 +1452,8 @@ void pci_acpi_cleanup(struct device *dev, struct acpi_device *adev) pci_acpi_remove_pm_notifier(adev); if (adev->wakeup.flags.valid) { acpi_device_power_remove_dependent(adev, dev); - if (pci_dev->bridge_d3_allowed) + if (pci_dev->bridge_d3cold_allowed && + pci_dev->bridge_d3hot_allowed) device_wakeup_disable(dev); device_set_wakeup_capable(dev, false); diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 40cfa716392f..45628b0dd116 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -529,7 +529,7 @@ static ssize_t d3cold_allowed_store(struct device *dev, return -EINVAL; pdev->d3cold_allowed = !!val; - pci_bridge_d3_update(pdev); + pci_bridge_d3cold_update(pdev); pm_runtime_resume(dev); diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 0edc4e448c2d..48e2ca0cd8a0 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -166,9 +166,9 @@ bool pci_ats_disabled(void) } EXPORT_SYMBOL_GPL(pci_ats_disabled); -/* Disable bridge_d3 for all PCIe ports */ +/* Disable both D3Hot and D3Cold for all PCIe ports */ static bool pci_bridge_d3_disable; -/* Force bridge_d3 for all PCIe ports */ +/* Force both D3Hot and D3Cold for all PCIe ports */ static bool pci_bridge_d3_force; static int __init pcie_port_pm_setup(char *str) @@ -2966,14 +2966,11 @@ static const struct dmi_system_id bridge_d3_blacklist[] = { { } }; -/** - * pci_bridge_d3_allowed - Is it allowed to put the bridge into D3 - * @bridge: Bridge to check - * - * This function checks if the bridge is allowed to move to D3. - * Currently we only allow D3 for recent enough PCIe ports and Thunderbolt. +/* + * Helper function to check whether it is allowed to put the bridge into D3 + * states (D3Hot and D3Cold). */ -bool pci_bridge_d3_allowed(struct pci_dev *bridge) +static bool pci_bridge_d3_allowed(struct pci_dev *bridge, pci_power_t state) { if (!pci_is_pcie(bridge)) return false; @@ -3026,6 +3023,32 @@ bool pci_bridge_d3_allowed(struct pci_dev *bridge) return false; } +/** + * pci_bridge_d3cold_allowed - Is it allowed to put the bridge into D3Cold + * @bridge: Bridge to check + * + * This function checks if the bridge is allowed to move to D3Cold. + * Currently we only allow D3Cold for recent enough PCIe ports on ACPI based + * platforms and Thunderbolt. + */ +bool pci_bridge_d3cold_allowed(struct pci_dev *bridge) +{ + return pci_bridge_d3_allowed(bridge, PCI_D3cold); +} + +/** + * pci_bridge_d3cold_allowed - Is it allowed to put the bridge into D3Hot + * @bridge: Bridge to check + * + * This function checks if the bridge is allowed to move to D3Hot. + * Currently we only allow D3Hot for recent enough PCIe ports on ACPI based + * platforms and Thunderbolt. + */ +bool pci_bridge_d3hot_allowed(struct pci_dev *bridge) +{ + return pci_bridge_d3_allowed(bridge, PCI_D3hot); +} + static int pci_dev_check_d3cold(struct pci_dev *dev, void *data) { bool *d3cold_ok = data; @@ -3046,55 +3069,55 @@ static int pci_dev_check_d3cold(struct pci_dev *dev, void *data) } /* - * pci_bridge_d3_update - Update bridge D3 capabilities + * pci_bridge_d3cold_update - Update bridge D3Cold capabilities * @dev: PCI device which is changed * * Update upstream bridge PM capabilities accordingly depending on if the * device PM configuration was changed or the device is being removed. The * change is also propagated upstream. */ -void pci_bridge_d3_update(struct pci_dev *dev) +void pci_bridge_d3cold_update(struct pci_dev *dev) { bool remove = !device_is_registered(&dev->dev); struct pci_dev *bridge; bool d3cold_ok = true; bridge = pci_upstream_bridge(dev); - if (!bridge || !pci_bridge_d3_allowed(bridge)) + if (!bridge || !pci_bridge_d3cold_allowed(bridge)) return; /* - * If D3 is currently allowed for the bridge, removing one of its + * If D3Cold is currently allowed for the bridge, removing one of its * children won't change that. */ - if (remove && bridge->bridge_d3_allowed) + if (remove && bridge->bridge_d3cold_allowed) return; /* - * If D3 is currently allowed for the bridge and a child is added or - * changed, disallowance of D3 can only be caused by that child, so + * If D3Cold is currently allowed for the bridge and a child is added or + * changed, disallowance of D3Cold can only be caused by that child, so * we only need to check that single device, not any of its siblings. * - * If D3 is currently not allowed for the bridge, checking the device - * first may allow us to skip checking its siblings. + * If D3Cold is currently not allowed for the bridge, checking the + * device first may allow us to skip checking its siblings. */ if (!remove) pci_dev_check_d3cold(dev, &d3cold_ok); /* - * If D3 is currently not allowed for the bridge, this may be caused + * If D3Cold is currently not allowed for the bridge, this may be caused * either by the device being changed/removed or any of its siblings, * so we need to go through all children to find out if one of them - * continues to block D3. + * continues to block D3Cold. */ - if (d3cold_ok && !bridge->bridge_d3_allowed) + if (d3cold_ok && !bridge->bridge_d3cold_allowed) pci_walk_bus(bridge->subordinate, pci_dev_check_d3cold, &d3cold_ok); - if (bridge->bridge_d3_allowed != d3cold_ok) { - bridge->bridge_d3_allowed = d3cold_ok; + if (bridge->bridge_d3cold_allowed != d3cold_ok) { + bridge->bridge_d3cold_allowed = d3cold_ok; /* Propagate change to upstream bridges */ - pci_bridge_d3_update(bridge); + pci_bridge_d3cold_update(bridge); } } @@ -3110,7 +3133,7 @@ void pci_d3cold_enable(struct pci_dev *dev) { if (dev->no_d3cold) { dev->no_d3cold = false; - pci_bridge_d3_update(dev); + pci_bridge_d3cold_update(dev); } } EXPORT_SYMBOL_GPL(pci_d3cold_enable); @@ -3127,7 +3150,7 @@ void pci_d3cold_disable(struct pci_dev *dev) { if (!dev->no_d3cold) { dev->no_d3cold = true; - pci_bridge_d3_update(dev); + pci_bridge_d3cold_update(dev); } } EXPORT_SYMBOL_GPL(pci_d3cold_disable); @@ -3167,7 +3190,8 @@ void pci_pm_init(struct pci_dev *dev) dev->pm_cap = pm; dev->d3hot_delay = PCI_PM_D3HOT_WAIT; dev->d3cold_delay = PCI_PM_D3COLD_WAIT; - dev->bridge_d3_allowed = pci_bridge_d3_allowed(dev); + dev->bridge_d3cold_allowed = pci_bridge_d3cold_allowed(dev); + dev->bridge_d3hot_allowed = pci_bridge_d3hot_allowed(dev); dev->d3cold_allowed = true; dev->d1_support = false; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 53ca75639201..f819eab793fc 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -92,8 +92,9 @@ void pci_pm_init(struct pci_dev *dev); void pci_ea_init(struct pci_dev *dev); void pci_msi_init(struct pci_dev *dev); void pci_msix_init(struct pci_dev *dev); -bool pci_bridge_d3_allowed(struct pci_dev *dev); -void pci_bridge_d3_update(struct pci_dev *dev); +bool pci_bridge_d3cold_allowed(struct pci_dev *dev); +bool pci_bridge_d3hot_allowed(struct pci_dev *dev); +void pci_bridge_d3cold_update(struct pci_dev *dev); int pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, char *reset_type); static inline void pci_wakeup_event(struct pci_dev *dev) @@ -111,9 +112,12 @@ static inline bool pci_power_manageable(struct pci_dev *pci_dev) { /* * Currently we allow normal PCI devices and PCI bridges transition - * into D3 if their bridge_d3 is set. + * into D3 states if both bridge_d3cold_allowed and bridge_d3hot_allowed + * are set. */ - return !pci_has_subordinate(pci_dev) || pci_dev->bridge_d3_allowed; + return !pci_has_subordinate(pci_dev) || + (pci_dev->bridge_d3cold_allowed && + pci_dev->bridge_d3hot_allowed); } static inline bool pcie_downstream_port(const struct pci_dev *dev) diff --git a/drivers/pci/pcie/portdrv.c b/drivers/pci/pcie/portdrv.c index 8401a0f7b394..655754b9f06a 100644 --- a/drivers/pci/pcie/portdrv.c +++ b/drivers/pci/pcie/portdrv.c @@ -632,7 +632,7 @@ __setup("pcie_ports=", pcie_port_setup); #ifdef CONFIG_PM static int pcie_port_runtime_suspend(struct device *dev) { - if (!to_pci_dev(dev)->bridge_d3_allowed) + if (!to_pci_dev(dev)->bridge_d3hot_allowed) return -EBUSY; return pcie_port_device_runtime_suspend(dev); @@ -641,11 +641,11 @@ static int pcie_port_runtime_suspend(struct device *dev) static int pcie_port_runtime_idle(struct device *dev) { /* - * Assume the PCI core has set bridge_d3_allowed whenever it thinks the - * port should be good to go to D3. Everything else, including moving - * the port to D3, is handled by the PCI core. + * Assume the PCI core has set bridge_d3hot_allowed whenever it thinks + * the port should be good to go to D3Hot. Everything else, including + * moving the port to D3Hot, is handled by the PCI core. */ - return to_pci_dev(dev)->bridge_d3_allowed ? 0 : -EBUSY; + return to_pci_dev(dev)->bridge_d3hot_allowed ? 0 : -EBUSY; } static const struct dev_pm_ops pcie_portdrv_pm_ops = { @@ -702,7 +702,7 @@ static int pcie_portdrv_probe(struct pci_dev *dev, dev_pm_set_driver_flags(&dev->dev, DPM_FLAG_NO_DIRECT_COMPLETE | DPM_FLAG_SMART_SUSPEND); - if (dev->bridge_d3_allowed) { + if (dev->bridge_d3hot_allowed) { /* * Keep the port resumed 100ms to make sure things like * config space accesses from userspace (lspci) will not @@ -720,7 +720,7 @@ static int pcie_portdrv_probe(struct pci_dev *dev, static void pcie_portdrv_remove(struct pci_dev *dev) { - if (dev->bridge_d3_allowed) { + if (dev->bridge_d3hot_allowed) { pm_runtime_forbid(&dev->dev); pm_runtime_get_noresume(&dev->dev); pm_runtime_dont_use_autosuspend(&dev->dev); @@ -733,7 +733,7 @@ static void pcie_portdrv_remove(struct pci_dev *dev) static void pcie_portdrv_shutdown(struct pci_dev *dev) { - if (dev->bridge_d3_allowed) { + if (dev->bridge_d3hot_allowed) { pm_runtime_forbid(&dev->dev); pm_runtime_get_noresume(&dev->dev); pm_runtime_dont_use_autosuspend(&dev->dev); diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index d749ea8250d6..36d8cb50b582 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -41,7 +41,7 @@ static void pci_destroy_dev(struct pci_dev *dev) pci_doe_destroy(dev); pcie_aspm_exit_link_state(dev); - pci_bridge_d3_update(dev); + pci_bridge_d3cold_update(dev); pci_free_resources(dev); put_device(&dev->dev); } diff --git a/include/linux/pci.h b/include/linux/pci.h index 2a48c88512e1..d0947f932b9a 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -375,7 +375,8 @@ struct pci_dev { unsigned int d2_support:1; /* Low power state D2 is supported */ unsigned int no_d1d2:1; /* D1 and D2 are forbidden */ unsigned int no_d3cold:1; /* D3cold is forbidden */ - unsigned int bridge_d3_allowed:1; /* Allow D3 for bridge */ + unsigned int bridge_d3cold_allowed:1; /* Allow D3Cold for bridge */ + unsigned int bridge_d3hot_allowed:1; /* Allow D3Hot for bridge */ unsigned int d3cold_allowed:1; /* D3cold is allowed by user */ unsigned int mmio_always_on:1; /* Disallow turning off io/mem decoding during BAR sizing */ From patchwork Tue Mar 26 10:48:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 13603901 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E933548F7 for ; Tue, 26 Mar 2024 10:49:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711450153; cv=none; b=CjvvtuJ5fGAnHHO3U91qDQ1wSE98bqyD5u5f329KJt7GWnlo31eWTtU0UED2IsnPvjdPcaGlIqQhHHf7BNw7uAYl56iM1a2Ve6e7f0dPXszSjtiUibeY1iAf/C8AjwUUhgnwLbMNGO/iQs/W7eq5pqkyfkiEcrIIn2aT9anUGsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711450153; c=relaxed/simple; bh=FdIlecklqovWUvrpfyhP9M3zVKU0Sq4nhdASMDLOLeM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=F9NyKabRJbe7y2cN5gyf/U0fy/J56QZZXaOBfUdBGfr6ZSw9Nw4KlOxa0oqP+czTrb/4ut/wQMbOA2d6GTo/b0x3kTtaSQJ5tHUzD13uFG0zuGI4HoYMoUN/pcToG/Dizab47E66oiNbJPQ7I9LEOGh63rLEmjV+5GP5LCY53hA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Nmb3ZbAU; arc=none smtp.client-ip=209.85.215.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Nmb3ZbAU" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-5bdbe2de25fso3690201a12.3 for ; Tue, 26 Mar 2024 03:49:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711450151; x=1712054951; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=vFbJYhdYGvuoH/oaiD2HBWtmIM7M07m8HS3m2IPBo/Q=; b=Nmb3ZbAUW1UmI1tzHyg8ILf73dPZJO2fjLqRqpUsnT3d933tWOFlP8PdT/oql1qla7 xmN7olPIjJOMbH7nTulCCwJm9GBq//U1i7fBFMFnEBaUwqUt7KOetgEltqQG5NP3v6n8 gcNRzaXkDDvulv7Er/7uJd9hnqX/40sds7fKgbS3nPXNkUFNerE7zPfXrAfYG6sW3uOj jH2J1Lel1bYEee+47BhEN6fjyu0wC6XyqUZe9Uca291+K3bCZBInZ6Uff/L84QxjACkS sC9iKsvwmFaBSW5VVLypGRThfRQqgti5/PxSdFgv+0Wv4FPXws9DZg7hpNp/3fpQINMt U+Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711450151; x=1712054951; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vFbJYhdYGvuoH/oaiD2HBWtmIM7M07m8HS3m2IPBo/Q=; b=kb0iMKuZlNraBT+MDxpH2zkxALNdafkcK6ekILlGP7FUtJdHdsHSt8u2fXG6rZAKCV x56+vAfxgbtfLWbY4fnUXkc2xH4+BW2e8uBbBfDI7q+tBOBgFqPTAXeliF0SsMzgPiKO wd0wxfX/4XujMrUuVdEW3iCgw2eSuULoWwg4L98O+w2sAwF2gVGPw5Zi0BSB6k5e1yks cyihzLZaEXf8xXernNNNcFsg1ZGGxzZL4FglLPCVLn964lT8pVZOtfZh/FIskWs8N7TJ BX8LOsmWzHYO+QzQqs68MP3Z8I6xlmKgGUIOoUPv3T5q4r36BXtxhfPSBDwW32zwgS0k FNhw== X-Forwarded-Encrypted: i=1; AJvYcCUeyK+9TSeljSvfHZr+xvKFHatyB0wTIurNAIaQGy6LzU51YBy+1LidvhQScdSnTEN4/cKpTd1B7ZsSb/I5tP0pAE1hJORPRMQ8nA== X-Gm-Message-State: AOJu0YzHtAjZ26wKq6BJNYky11UbtyECVwZx0B+Ap8q19rskOoltX/Tn x+7FpYGqpCqFnZCowLmJ3vtRUAlC7dld+N1v2sOER/ALcM37seB1Qpz3rC23gw== X-Google-Smtp-Source: AGHT+IGxQHf1BymA0HBDL7TqSsjS+f9g8ewlhc49CHvhJdNFTTeKuQxe+y2yjxy3ofTQUrQg7LmtBQ== X-Received: by 2002:a17:90a:1305:b0:2a0:4c3b:3454 with SMTP id h5-20020a17090a130500b002a04c3b3454mr7137289pja.47.1711450151523; Tue, 26 Mar 2024 03:49:11 -0700 (PDT) Received: from [127.0.1.1] ([117.207.28.168]) by smtp.gmail.com with ESMTPSA id i22-20020a17090a059600b0029fc196159bsm8777218pji.30.2024.03.26.03.49.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 03:49:11 -0700 (PDT) From: Manivannan Sadhasivam Date: Tue, 26 Mar 2024 16:18:20 +0530 Subject: [PATCH v4 4/4] PCI: Allow PCI bridges to go to D3Hot on all Devicetree based platforms Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240326-pci-bridge-d3-v4-4-f1dce1d1f648@linaro.org> References: <20240326-pci-bridge-d3-v4-0-f1dce1d1f648@linaro.org> In-Reply-To: <20240326-pci-bridge-d3-v4-0-f1dce1d1f648@linaro.org> To: Bjorn Helgaas , "Rafael J. Wysocki" , Len Brown Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, lukas@wunner.de, mika.westerberg@linux.intel.com, Manivannan Sadhasivam X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=1862; i=manivannan.sadhasivam@linaro.org; h=from:subject:message-id; bh=FdIlecklqovWUvrpfyhP9M3zVKU0Sq4nhdASMDLOLeM=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBmAqgV8B1oRhS/KEisLhilKgX2Z9YTFnu8il8dh f9ajS7O2tWJATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCZgKoFQAKCRBVnxHm/pHO 9eXUB/9NbhfHS2KhKNmrNgI0BRCyWwQs5Z61KL+HT/cENsQwy5+PBFop3vvKi5jAjCjl2F2llnV azk7wpPnz6M+RGS/kui+2NwlCPvmI2RSGReR8pmDUlW7dUL1MURBFvS9BrbA2GweE46rGR3GwCn zd6e4YlTwdT1bawePXF0Ovy39OdzdchHvn6R9RSCqaMulgoYAPPgdZACD1yY0TZh1bk4AbzGLTI V905mcjIEhpdM0/BDSMVr8EQDY+x6xFxuouAXOFl8RutypXrd6J459cVerSyAICab9gWMzhvoUf JJR1oISium2mQig51ikU2pslp2AlKXazrJbOLS7KrgkQcA3d X-Developer-Key: i=manivannan.sadhasivam@linaro.org; a=openpgp; fpr=C668AEC3C3188E4C611465E7488550E901166008 Unlike ACPI based platforms, there are no known issues with D3Hot for the PCI bridges in the Devicetree based platforms. So let's allow the PCI bridges to go to D3Hot during runtime. It should be noted that the bridges need to be defined in Devicetree for this to work. Currently, D3Cold is not allowed since Vcc supply which is required for transitioning the device to D3Cold is not exposed on all Devicetree based platforms. Signed-off-by: Manivannan Sadhasivam --- drivers/pci/pci.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 48e2ca0cd8a0..2fe9defa69e3 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2992,6 +2992,18 @@ static bool pci_bridge_d3_allowed(struct pci_dev *bridge, pci_power_t state) if (pci_bridge_d3_force) return true; + /* + * Allow D3Hot for all Devicetree based platforms having a + * separate node for the bridge. We don't allow D3Cold for now + * since not all platforms are exposing the Vcc supply in + * Devicetree which is required for transitioning the bridge to + * D3Cold. + * + * NOTE: The bridge is expected to be defined in Devicetree. + */ + if (state == PCI_D3hot && dev_of_node(&bridge->dev)) + return true; + /* Even the oldest 2010 Thunderbolt controller supports D3. */ if (bridge->is_thunderbolt) return true; @@ -3042,7 +3054,7 @@ bool pci_bridge_d3cold_allowed(struct pci_dev *bridge) * * This function checks if the bridge is allowed to move to D3Hot. * Currently we only allow D3Hot for recent enough PCIe ports on ACPI based - * platforms and Thunderbolt. + * platforms, Thunderbolt and Devicetree based platforms. */ bool pci_bridge_d3hot_allowed(struct pci_dev *bridge) {