[PATCH 01/12] PCI/ACPI: Add D3cold Aux Power Limit_DSM method
Anshuman Gupta
anshuman.gupta at intel.com
Tue Apr 1 15:32:14 UTC 2025
Implement _DSM method 10 and _DSM Method 11 as per PCI firmware specs
section 4.6.10 Rev 3.3.
Note that this implementation assumes only a single device below the
Downstream Port will request for Aux Power Limit under a given
Root Port because it does not track and aggregate requests
from all child devices below the Downstream Port as required
by Section 4.6.10 Rev 3.3.
One possible mitigation would be only allowing only first PCIe
Non-Bridge Endpoint Function 0 driver to call_DSM method 10.
Signed-off-by: Varun Gupta <varun.gupta at intel.com>
Signed-off-by: Badal Nilawar <badal.nilawar at intel.com>
Signed-off-by: Anshuman Gupta <anshuman.gupta at intel.com>
---
drivers/pci/pci-acpi.c | 78 ++++++++++++++++++++++++++++++++++++++++
include/linux/pci-acpi.h | 6 ++++
2 files changed, 84 insertions(+)
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index af370628e583..ebd49e43457e 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -1421,6 +1421,84 @@ static void pci_acpi_optimize_delay(struct pci_dev *pdev,
ACPI_FREE(obj);
}
+/**
+ * pci_acpi_request_d3cold_aux_power - Request D3cold aux power via ACPI DSM
+ * @dev: PCI device instance
+ * @requested_power: Requested auxiliary power in milliwatts
+ *
+ * This function sends a request to the host BIOS via ACPI _DSM Function 10
+ * to grant the required D3Cold Auxiliary power for the specified PCI device.
+ * It evaluates the _DSM (Device Specific Method) to request the Auxiliary
+ * power and handles the response accordingly.
+ *
+ * This function shall be only called by 1st non-bridge Endpoint driver
+ * on Function 0. For a Multi-Function Device, the driver for Function 0 is
+ * required to report an aggregate power requirement covering all
+ * functions contained within the device.
+ *
+ * Return: Returns 0 on success and errno on failure.
+ */
+int pci_acpi_request_d3cold_aux_power(struct pci_dev *dev, u32 requested_power)
+{
+ union acpi_object in_obj = {
+ .integer.type = ACPI_TYPE_INTEGER,
+ .integer.value = requested_power,
+ };
+
+ union acpi_object *out_obj;
+ acpi_handle handle;
+ int result, ret = -EINVAL;
+
+ if (!dev || !ACPI_HANDLE(&dev->dev))
+ return -EINVAL;
+
+ handle = ACPI_HANDLE(&dev->dev);
+
+ out_obj = acpi_evaluate_dsm_typed(handle,
+ &pci_acpi_dsm_guid,
+ 4,
+ DSM_PCI_D3COLD_AUX_POWER_LIMIT,
+ &in_obj,
+ ACPI_TYPE_INTEGER);
+ if (!out_obj)
+ return -EINVAL;
+
+ result = out_obj->integer.value;
+
+ switch (result) {
+ case 0x0:
+ dev_dbg(&dev->dev, "D3cold Aux Power %umW request denied\n",
+ requested_power);
+ break;
+ case 0x1:
+ dev_info(&dev->dev, "D3cold Aux Power request granted: %umW\n",
+ requested_power);
+ ret = 0;
+ break;
+ case 0x2:
+ dev_info(&dev->dev, "D3cold Aux Power: Main power won't be removed\n");
+ ret = -EBUSY;
+ break;
+ default:
+ if (result >= 0x11 && result <= 0x1F) {
+ int retry_interval = result & 0xF;
+
+ dev_warn(&dev->dev, "D3cold Aux Power request needs retry."
+ "Interval: %d seconds.\n", retry_interval);
+ msleep(retry_interval * 1000);
+ ret = -EAGAIN;
+ } else {
+ dev_err(&dev->dev, "D3cold Aux Power: Reserved or "
+ "unsupported response: 0x%x.\n", result);
+ }
+ break;
+ }
+
+ ACPI_FREE(out_obj);
+ return ret;
+}
+EXPORT_SYMBOL(pci_acpi_request_d3cold_aux_power);
+
static void pci_acpi_set_external_facing(struct pci_dev *dev)
{
u8 val;
diff --git a/include/linux/pci-acpi.h b/include/linux/pci-acpi.h
index 078225b514d4..dbc4b0ed433c 100644
--- a/include/linux/pci-acpi.h
+++ b/include/linux/pci-acpi.h
@@ -121,6 +121,7 @@ extern const guid_t pci_acpi_dsm_guid;
#define DSM_PCI_DEVICE_NAME 0x07
#define DSM_PCI_POWER_ON_RESET_DELAY 0x08
#define DSM_PCI_DEVICE_READINESS_DURATIONS 0x09
+#define DSM_PCI_D3COLD_AUX_POWER_LIMIT 0x0A
#ifdef CONFIG_PCIE_EDR
void pci_acpi_add_edr_notifier(struct pci_dev *pdev);
@@ -132,10 +133,15 @@ static inline void pci_acpi_remove_edr_notifier(struct pci_dev *pdev) { }
int pci_acpi_set_companion_lookup_hook(struct acpi_device *(*func)(struct pci_dev *));
void pci_acpi_clear_companion_lookup_hook(void);
+int pci_acpi_request_d3cold_aux_power(struct pci_dev *dev, u32 requested_power);
#else /* CONFIG_ACPI */
static inline void acpi_pci_add_bus(struct pci_bus *bus) { }
static inline void acpi_pci_remove_bus(struct pci_bus *bus) { }
+int pci_acpi_request_d3cold_aux_power(struct pci_dev *dev, u32 requested_power)
+{
+ return -EOPNOTSUPP;
+}
#endif /* CONFIG_ACPI */
#endif /* _PCI_ACPI_H_ */
--
2.43.0
More information about the Intel-xe
mailing list