linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Badal Nilawar <badal.nilawar@intel.com>
To: intel-xe@lists.freedesktop.org, linux-acpi@vger.kernel.org,
	linux-pci@vger.kernel.org
Cc: anshuman.gupta@intel.com, rafael@kernel.org, lenb@kernel.org,
	bhelgaas@google.com, ilpo.jarvinen@linux.intel.com,
	lucas.demarchi@intel.com, rodrigo.vivi@intel.com,
	varun.gupta@intel.com, ville.syrjala@linux.intel.com,
	uma.shankar@intel.com, karthik.poosa@intel.com
Subject: [PATCH v5 02/12] PCI/ACPI: Per Root/Switch Downstream Port allow one aux power limit request
Date: Wed, 15 Oct 2025 13:37:00 +0530	[thread overview]
Message-ID: <20251015080710.1468409-3-badal.nilawar@intel.com> (raw)
In-Reply-To: <20251015080710.1468409-1-badal.nilawar@intel.com>

Since aggregation of auxiliary power across multiple devices under a
Root or Switch Downstream Port is not supported, allow only one device
is to request auxiliary power

Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Anshuman Gupta <anshuman.gupta@intel.com>
Signed-off-by: Badal Nilawar <badal.nilawar@intel.com>
---
V1:
 - Use guard(mutex) for new mutex (Rafael)
 - Add mutex_detroy (Ilpo Järvinen)
 - %s/pci_warn/pci_info/ for -EAGAIN
 - Allow the same device to re-request auxiliary power if it has already been granted
---
 drivers/acpi/scan.c     |  3 +++
 drivers/pci/pci-acpi.c  | 22 ++++++++++++++++++++++
 include/acpi/acpi_bus.h |  3 +++
 3 files changed, 28 insertions(+)

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index ef16d58b2949..4573fb0f4f3e 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -518,6 +518,7 @@ static void acpi_device_release(struct device *dev)
 	acpi_free_properties(acpi_dev);
 	acpi_free_pnp_ids(&acpi_dev->pnp);
 	acpi_free_power_resources_lists(acpi_dev);
+	mutex_destroy(&acpi_dev->power.aux_pwr_lock);
 	kfree(acpi_dev);
 }
 
@@ -746,6 +747,8 @@ int acpi_device_add(struct acpi_device *device)
 	INIT_LIST_HEAD(&device->physical_node_list);
 	INIT_LIST_HEAD(&device->del_list);
 	mutex_init(&device->physical_node_lock);
+	mutex_init(&device->power.aux_pwr_lock);
+	device->power.dev = NULL;
 
 	mutex_lock(&acpi_device_lock);
 
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index c7eab1e75dd5..74f118016b1d 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -1477,6 +1477,7 @@ int pci_acpi_request_d3cold_aux_power(struct pci_dev *dev, u32 requested_mw,
 	union acpi_object *out_obj;
 	int result, ret = -EINVAL;
 	struct pci_dev *bdev;
+	struct acpi_device *adev;
 
 	if (!dev || PCI_FUNC(dev->devfn) != 0)
 		return -EINVAL;
@@ -1486,6 +1487,19 @@ int pci_acpi_request_d3cold_aux_power(struct pci_dev *dev, u32 requested_mw,
 	if (IS_ERR(bdev))
 		return PTR_ERR(bdev);
 
+	adev = ACPI_COMPANION(&bdev->dev);
+	if (!adev)
+		return -EINVAL;
+
+	guard(mutex)(&adev->power.aux_pwr_lock);
+
+	/* Check if aux power already granted to different device */
+	if (adev->power.dev && adev->power.dev != &dev->dev) {
+		pci_info(to_pci_dev(adev->power.dev), "D3cold Aux Power request already granted: %u mW\n",
+			 adev->power.aux_power_limit);
+		return -EPERM;
+	}
+
 	out_obj = acpi_evaluate_dsm_typed(ACPI_HANDLE(&bdev->dev),
 					  &pci_acpi_dsm_guid, 4,
 					  DSM_PCI_D3COLD_AUX_POWER_LIMIT,
@@ -1501,14 +1515,20 @@ int pci_acpi_request_d3cold_aux_power(struct pci_dev *dev, u32 requested_mw,
 	case AUX_PWR_REQ_DENIED:
 		pci_dbg(bdev, "D3cold Aux Power %u mW request denied\n",
 			requested_mw);
+		adev->power.aux_power_limit = 0;
+		adev->power.dev = NULL;
 		break;
 	case AUX_PWR_REQ_GRANTED:
 		pci_info(bdev, "D3cold Aux Power request granted: %u mW\n",
 			 requested_mw);
+		adev->power.aux_power_limit = requested_mw;
+		adev->power.dev = &dev->dev;
 		ret = 0;
 		break;
 	case AUX_PWR_REQ_NO_MAIN_PWR_REMOVAL:
 		pci_info(bdev, "D3cold Aux Power: Main power won't be removed\n");
+		adev->power.aux_power_limit = 0;
+		adev->power.dev = NULL;
 		ret = -EBUSY;
 		break;
 	default:
@@ -1524,6 +1544,8 @@ int pci_acpi_request_d3cold_aux_power(struct pci_dev *dev, u32 requested_mw,
 			pci_err(bdev, "D3cold Aux Power: Reserved or unsupported response: 0x%x\n",
 				result);
 		}
+		adev->power.aux_power_limit = 0;
+		adev->power.dev = NULL;
 		break;
 	}
 
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index aad1a95e6863..cfa0c7233f13 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -294,6 +294,9 @@ struct acpi_device_power {
 	struct acpi_device_power_flags flags;
 	struct acpi_device_power_state states[ACPI_D_STATE_COUNT];	/* Power states (D0-D3Cold) */
 	u8 state_for_enumeration; /* Deepest power state for enumeration */
+	u32 aux_power_limit;		/* aux power limit granted by platform firmware */
+	struct device *dev;		/* device to which aux power is granted */
+	struct mutex aux_pwr_lock;	/* prevent concurrent aux power limit requests */
 };
 
 struct acpi_dep_data {
-- 
2.34.1


  parent reply	other threads:[~2025-10-15  8:02 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-15  8:06 [PATCH v5 00/12] VRAM Self Refresh Badal Nilawar
2025-10-15  8:06 ` [PATCH v5 01/12] PCI/ACPI: Add D3cold Aux Power Limit_DSM method Badal Nilawar
2025-10-27 19:03   ` Rafael J. Wysocki
2025-10-15  8:07 ` Badal Nilawar [this message]
2025-10-27 19:11   ` [PATCH v5 02/12] PCI/ACPI: Per Root/Switch Downstream Port allow one aux power limit request Rafael J. Wysocki
2025-10-15  8:07 ` [PATCH v5 03/12] PCI/ACPI: Add PERST# Assertion Delay _DSM method Badal Nilawar
2025-10-27 19:18   ` Rafael J. Wysocki
2025-10-15  8:07 ` [PATCH v5 04/12] drm/xe/vrsr: Introduce flag has_vrsr Badal Nilawar
2025-10-15  8:07 ` [PATCH v5 05/12] drm/xe/vrsr: Detect VRSR Capability Badal Nilawar
2025-10-15  8:07 ` [PATCH v5 06/12] drm/xe/vrsr: Initialize VRSR feature Badal Nilawar
2025-10-15  8:07 ` [PATCH v5 07/12] drm/xe/vrsr: Enable VRSR on default VGA boot device Badal Nilawar
2025-10-15  8:07 ` [PATCH v5 08/12] drm/xe/vrsr: Refactor d3cold.allowed to a enum Badal Nilawar
2025-10-15  8:39   ` Raag Jadav
2025-10-15  9:04     ` Nilawar, Badal
2025-10-15  9:08       ` Nilawar, Badal
2025-10-15  9:08       ` Gupta, Anshuman
2025-10-15  8:07 ` [PATCH v5 09/12] drm/xe/pm: D3cold target state Badal Nilawar
2025-10-15  8:07 ` [PATCH v5 10/12] drm/xe/vrsr: Enable VRSR Badal Nilawar
2025-10-15  8:07 ` [PATCH v5 11/12] drm/xe/pm/s2idle: Don't evict user BOs for D3hot and D3cold-VRSR state Badal Nilawar
2025-10-17 11:00   ` Matthew Auld
2025-10-15  8:07 ` [PATCH v5 12/12] drm/xe/vrsr: Introduce a debugfs node named vrsr_capable Badal Nilawar
2025-10-15  8:43   ` Poosa, Karthik

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=20251015080710.1468409-3-badal.nilawar@intel.com \
    --to=badal.nilawar@intel.com \
    --cc=anshuman.gupta@intel.com \
    --cc=bhelgaas@google.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=karthik.poosa@intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lucas.demarchi@intel.com \
    --cc=rafael@kernel.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=uma.shankar@intel.com \
    --cc=varun.gupta@intel.com \
    --cc=ville.syrjala@linux.intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).