From: Mario Limonciello <mario.limonciello@amd.com>
To: Bjorn Helgaas <bhelgaas@google.com>,
"Rafael J . Wysocki" <rjw@rjwysocki.net>
Cc: "open list:PCI SUBSYSTEM" <linux-pci@vger.kernel.org>,
<linux-acpi@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
"Mario Limonciello" <mario.limonciello@amd.com>
Subject: [PATCH 2/3] PCI/ACPI: Add API for specifying aux power in D3cold
Date: Fri, 10 Nov 2023 12:55:02 -0600 [thread overview]
Message-ID: <20231110185503.46117-3-mario.limonciello@amd.com> (raw)
In-Reply-To: <20231110185503.46117-1-mario.limonciello@amd.com>
The PCI firmware specification includes support for a _DSM function
to negotiate aux power to be provided to the device while it is in
D3cold.
"The Request D3cold Aux Power Limit function describes how a device
driver conveys its auxiliary power requirements to the host platform
when the device is in D3cold. The system firmware responds with a value
indicating whether the request can be supported. The power request is
specific to the Auxiliary power supply; main power may be removed while
in D3cold. A device must not draw any more power than what has been
negotiated via this mechanism after entering D3cold"
Add API for callers to utilize this _DSM.
Link: https://members.pcisig.com/wg/PCI-SIG/document/15350
PCI Firmware specification 3.3, section 4.6.10
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
drivers/pci/pci-acpi.c | 54 ++++++++++++++++++++++++++++++++++++++++
include/linux/pci-acpi.h | 7 ++++++
2 files changed, 61 insertions(+)
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index bea72e807817..257858a6719e 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -1348,6 +1348,60 @@ static struct acpi_device *acpi_pci_find_companion(struct device *dev)
return adev;
}
+/**
+ * pci_acpi_request_aux_power_for_d3cold - Request auxiliary power for D3cold
+ * @pdev: PCI device to request power for
+ * @arg: mW requested
+ *
+ * This function requests auxiliary power for a PCI device in D3cold state
+ * when main power is removed above the value guaranteed by PCI specification.
+ *
+ * Return:
+ * 0 on success
+ * -ENODEV when the device does not support the _DSM
+ * -EIO on ACPI call failure
+ * -EACCESS when the request was denied
+ * Positive value corresponding to platform requested retry interval in seconds
+ */
+int pci_acpi_request_aux_power_for_d3cold(struct pci_dev *pdev, int arg)
+{
+ struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
+ union acpi_object *obj;
+ union acpi_object argv4 = {
+ .integer.type = ACPI_TYPE_INTEGER,
+ .integer.value = arg,
+ };
+ int val;
+
+ if (!acpi_check_dsm(adev->handle, &pci_acpi_dsm_guid,
+ pci_acpi_dsm_rev,
+ 1 << DSM_PCI_REQUEST_D3COLD_AUX_POWER))
+ return -ENODEV;
+
+ obj = acpi_evaluate_dsm_typed(adev->handle, &pci_acpi_dsm_guid,
+ pci_acpi_dsm_rev,
+ DSM_PCI_REQUEST_D3COLD_AUX_POWER,
+ &argv4, ACPI_TYPE_INTEGER);
+ if (!obj)
+ return -EIO;
+
+ val = obj->integer.value;
+ ACPI_FREE(obj);
+
+ switch (val) {
+ case PCI_D3COLD_AUX_DENIED:
+ return -EACCES;
+ case PCI_D3COLD_AUX_GRANTED:
+ case PCI_D3COLD_AUX_NO_MAIN_POWER_REMOVAL:
+ return 0;
+ default:
+ break;
+ }
+
+ return val;
+}
+EXPORT_SYMBOL_GPL(pci_acpi_request_aux_power_for_d3cold);
+
/**
* pci_acpi_optimize_delay - optimize PCI D3 and D3cold delay from ACPI
* @pdev: the PCI device whose delay is to be updated
diff --git a/include/linux/pci-acpi.h b/include/linux/pci-acpi.h
index 7966ef8f14b3..bc6372bcb7d6 100644
--- a/include/linux/pci-acpi.h
+++ b/include/linux/pci-acpi.h
@@ -122,6 +122,13 @@ extern const int pci_acpi_dsm_rev;
#define DSM_PCI_DEVICE_NAME 0x07
#define DSM_PCI_POWER_ON_RESET_DELAY 0x08
#define DSM_PCI_DEVICE_READINESS_DURATIONS 0x09
+#define DSM_PCI_REQUEST_D3COLD_AUX_POWER 0x0A
+
+#define PCI_D3COLD_AUX_DENIED 0
+#define PCI_D3COLD_AUX_GRANTED 1
+#define PCI_D3COLD_AUX_NO_MAIN_POWER_REMOVAL 2
+
+int pci_acpi_request_aux_power_for_d3cold(struct pci_dev *pdev, int arg);
#ifdef CONFIG_PCIE_EDR
void pci_acpi_add_edr_notifier(struct pci_dev *pdev);
--
2.34.1
next prev parent reply other threads:[~2023-11-10 20:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-10 18:55 [PATCH 0/3] Add API for missing PCI firmware specification funcs Mario Limonciello
2023-11-10 18:55 ` [PATCH 1/3] PCI: Call PCI ACPI _DSM with consistent revision argument Mario Limonciello
2023-11-30 13:34 ` Rafael J. Wysocki
2023-11-30 19:30 ` Mario Limonciello
2023-11-30 22:29 ` Bjorn Helgaas
2023-12-05 20:12 ` Mario Limonciello
2023-12-06 23:04 ` Bjorn Helgaas
2023-12-07 2:02 ` Mario Limonciello
2023-11-10 18:55 ` Mario Limonciello [this message]
2023-11-10 18:55 ` [PATCH 3/3] PCI/ACPI: Add API for specifying a PERST# assertion delay Mario Limonciello
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231110185503.46117-3-mario.limonciello@amd.com \
--to=mario.limonciello@amd.com \
--cc=bhelgaas@google.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=rjw@rjwysocki.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox