PCI/ASPM: Add support for LTR _DSM
PATCH v6 1/1 PCI/ASPM: Add support for LTR _DSM
Latency Tolerance Reporting (LTR) is required for the ASPM L1.2 PM substate. Devices with Upstream Ports (Endpoints and Switches) may support the optional LTR Capability. When LTR is enabled, devices transmit LTR messages containing Snoop and No-Snoop Latencies upstream. The L1.2 substate may be entered if the most recent LTR values are greater than or equal to the LTR_L1.2_THRESHOLD from the L1 PM Substates Control 1 register.
Add a new function pci_ltr_init() which will be called from pci_configure_ltr() to initialize every PCIe device's LTR values. Add code in probe.c to evaluate LTR _DSM and save the latencies in pci_dev.
---
v6 - Change the order of the function calls so, the messages are
enabled only after the LTR registers have been initialized.
v5 - Add static keyword with pci_ltr_encode() and pci_ltr_decode() v4 - remove pci_upstream_bridge and use acpi_pci_find_companion()
to get the handle for evaluating _DSM.
Add acpi_check_dsm()
Change the logging mechanism.
v3 - change the algorithm to add latencies, add helper funtions for
encoding and decoding the latencies.
v2 - add an #ifdefin pci-acpi.c to fix the bug reported by test bot. v1 - based the patch on v5.9-rc1 so it applies correctly.
--- drivers/pci/pci-acpi.c | 37 +++++++++++++++++++++ drivers/pci/pci.h | 4 +++ drivers/pci/pcie/aspm.c | 71 ++++++++++++++++++++++++++++++++++++++++ drivers/pci/probe.c | 6 ++++ include/linux/pci-acpi.h | 1 + include/linux/pci.h | 2 ++ 6 files changed, 121 insertions(+)
drivers/pci/pci-acpi.c +37 -0
@@ -1213,6 +1213,43 @@ static void pci_acpi_optimize_delay(struct pci_dev *pdev,ACPI_FREE (obj); } +/* pci_acpi_evaluate_ltr_latency +* +* @dev - the pci_dev to evaluate and save latencies +*/ +void pci_acpi_evaluate_ltr_latency (struct pci_dev *dev) +{ +#ifdef CONFIG_PCIEASPM +struct acpi_device *adev; +union acpi_object *obj, *elements; + + adev =ACPI_COMPANION (&dev->dev); +if (!adev && !pci_dev_is_added (dev)) + adev =acpi_pci_find_companion (&dev->dev); +if (!adev) +return ; + +if (!acpi_check_dsm (adev->handle, &pci_acpi_dsm_guid,2 , +1ULL <<DSM_PCI_LTR_MAX_LATENCY )) +return ; + obj =acpi_evaluate_dsm (adev->handle, &pci_acpi_dsm_guid,2 , +DSM_PCI_LTR_MAX_LATENCY ,NULL ); +if (!obj) +return ; + +if (obj->type ==ACPI_TYPE_PACKAGE && obj->package.count ==4 ) { + elements = obj->package.elements; + dev->max_snoop_latency = (u16 )elements[1 ].integer.value | + ((u16 )elements[0 ].integer.value << +PCI_LTR_SCALE_SHIFT ); + dev->max_nosnoop_latency = (u16 )elements[3 ].integer.value | + ((u16 )elements[2 ].integer.value << +PCI_LTR_SCALE_SHIFT ); + } +ACPI_FREE (obj); +#endif +} +static void pci_acpi_set_external_facing (struct pci_dev *dev) {u8 val;
drivers/pci/pci.h +4 -0
@@ -561,11 +561,13 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,bool pcie_wait_for_link (struct pci_dev *pdev,bool active);#ifdef CONFIG_PCIEASPM +void pci_ltr_init (struct pci_dev *dev);void pcie_aspm_init_link_state (struct pci_dev *pdev);void pcie_aspm_exit_link_state (struct pci_dev *pdev);void pcie_aspm_pm_state_change (struct pci_dev *pdev);void pcie_aspm_powersave_config_link (struct pci_dev *pdev);#else +static inline void pci_ltr_init (struct pci_dev *pdev) { }static inline void pcie_aspm_init_link_state (struct pci_dev *pdev) { }static inline void pcie_aspm_exit_link_state (struct pci_dev *pdev) { }static inline void pcie_aspm_pm_state_change (struct pci_dev *pdev) { }
@@ -680,11 +682,13 @@ static inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVAL#ifdef CONFIG_ACPI int pci_acpi_program_hp_params (struct pci_dev *dev); +void pci_acpi_evaluate_ltr_latency (struct pci_dev *dev);#else static inline int pci_acpi_program_hp_params (struct pci_dev *dev) {return -ENODEV ; } +static inline void pci_acpi_evaluate_ltr_latency (struct pci_dev *dev) { }#endif #ifdef CONFIG_PCIEASPM
drivers/pci/pcie/aspm.c +71 -0
77 lines not on this page · raw message
drivers/pci/probe.c +6 -0
@@ -2106,6 +2106,12 @@ static void pci_configure_ltr(struct pci_dev *dev)if (!pci_is_pcie (dev))return ; +/* Read latency values (if any) from platform */ +pci_acpi_evaluate_ltr_latency (dev); + +/* Initialize the Latency Tolerance Reporting (LTR) Extended Capability */ +pci_ltr_init (dev); +pcie_capability_read_dword (dev,PCI_EXP_DEVCAP2 , &cap);if (!(cap &PCI_EXP_DEVCAP2_LTR ))return ;
include/linux/pci-acpi.h +1 -0
@@ -110,6 +110,7 @@ extern const guid_t pci_acpi_dsm_guid;/* _DSM Definitions for PCI */ #define DSM_PCI_PRESERVE_BOOT_CONFIG 0x05 +#define DSM_PCI_LTR_MAX_LATENCY 0x06#define DSM_PCI_DEVICE_NAME 0x07#define DSM_PCI_POWER_ON_RESET_DELAY 0x08#define DSM_PCI_DEVICE_READINESS_DURATIONS 0x09
include/linux/pci.h +2 -0
@@ -380,6 +380,8 @@ struct pci_dev {struct pcie_link_state *link_state;/* ASPM link state */ unsigned int ltr_path:1; /* Latency Tolerance Reportingsupported from root to here */ +u16 max_snoop_latency;/* LTR Max Snoop latency */ +u16 max_nosnoop_latency;/* LTR Max No-Snoop latency */ #endif unsigned int eetlp_prefix_path:1; /* End-to-End TLP Prefix */
Signature · 1 line
2.27.0