Linux PCI subsystem development
 help / color / mirror / Atom feed
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 3/3] PCI/ACPI: Add API for specifying a PERST# assertion delay
Date: Fri, 10 Nov 2023 12:55:03 -0600	[thread overview]
Message-ID: <20231110185503.46117-4-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 specify a PERST# assertion delay.

"The Add PERST# Assertion Delay function is used to convey the requirement
for a fixed delay in timing between the time the PME_TO_Ack message is
received at the PCI Express Downstream Port that originated the
PME_Turn_Off message, and the time the platform asserts PERST# to the slot
during the corresponding Endpoint’s or PCI Express Upstream Port’s
transition to D3cold while the system is in an ACPI operational state."

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.11
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
 drivers/pci/pci-acpi.c   | 40 ++++++++++++++++++++++++++++++++++++++++
 include/linux/pci-acpi.h |  2 ++
 2 files changed, 42 insertions(+)

diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 257858a6719e..82e04808040d 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -1402,6 +1402,46 @@ int pci_acpi_request_aux_power_for_d3cold(struct pci_dev *pdev, int arg)
 }
 EXPORT_SYMBOL_GPL(pci_acpi_request_aux_power_for_d3cold);
 
+/**
+ * pci_acpi_set_perst_delay - Set the assertion delay for the PERST# signal
+ * @pdev: PCI device to set the delay for
+ * @arg: Delay value in microseconds
+ *
+ * This function sets the delay for the PERST# signal of the given PCI device.
+ * The delay value is specified in microseconds through the @arg parameter.
+ * The maximum delay value is 10000 microseconds.
+ *
+ * Return: 0 on success, negative error code on failure
+ */
+int pci_acpi_set_perst_delay(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_ADD_PERST_DELAY))
+		return -ENODEV;
+
+	if (arg > 10000)
+		return -EINVAL;
+
+	obj = acpi_evaluate_dsm_typed(adev->handle, &pci_acpi_dsm_guid,
+				      pci_acpi_dsm_rev, DSM_PCI_ADD_PERST_DELAY,
+				      &argv4, ACPI_TYPE_INTEGER);
+	if (!obj)
+		return -EIO;
+
+	val = obj->integer.value;
+	ACPI_FREE(obj);
+	return (val == arg) ? 0 : -EINVAL;
+}
+EXPORT_SYMBOL_GPL(pci_acpi_set_perst_delay);
+
 /**
  * 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 bc6372bcb7d6..bdce83c3afbf 100644
--- a/include/linux/pci-acpi.h
+++ b/include/linux/pci-acpi.h
@@ -123,12 +123,14 @@ extern const int pci_acpi_dsm_rev;
 #define DSM_PCI_POWER_ON_RESET_DELAY		0x08
 #define DSM_PCI_DEVICE_READINESS_DURATIONS	0x09
 #define DSM_PCI_REQUEST_D3COLD_AUX_POWER	0x0A
+#define DSM_PCI_ADD_PERST_DELAY			0x0B
 
 #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);
+int pci_acpi_set_perst_delay(struct pci_dev *pdev, int arg);
 
 #ifdef CONFIG_PCIE_EDR
 void pci_acpi_add_edr_notifier(struct pci_dev *pdev);
-- 
2.34.1


      parent reply	other threads:[~2023-11-10 19:17 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 ` [PATCH 2/3] PCI/ACPI: Add API for specifying aux power in D3cold Mario Limonciello
2023-11-10 18:55 ` Mario Limonciello [this message]

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-4-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