[PATCH 09/15] PCI/PTM: Save PTM state in the saved capability store
From: David Matlack
Date: Thu Sep 24 2026 - 13:50:59 EST
Save and restore the PTM Control register through the per-device saved
capability store instead of a private pci_cap_saved_state buffer.
Report a reservation failure. pci_ptm_init() ignored the return value of
pci_add_ext_cap_save_buffer() entirely, so a failed allocation was only
noticed later as silently missing PTM state.
No functional change intended.
Assisted-by: LLM
Signed-off-by: David Matlack <dmatlack@xxxxxxxxxx>
---
drivers/pci/pcie/ptm.c | 29 ++++++-----------------------
1 file changed, 6 insertions(+), 23 deletions(-)
diff --git a/drivers/pci/pcie/ptm.c b/drivers/pci/pcie/ptm.c
index bd3bd39f6372..a9e29e19b0f9 100644
--- a/drivers/pci/pcie/ptm.c
+++ b/drivers/pci/pcie/ptm.c
@@ -53,7 +53,8 @@ void pci_ptm_init(struct pci_dev *dev)
dev->ptm_cap = ptm;
atomic_set(&dev->ptm_enable_cnt, 0);
- pci_add_ext_cap_save_buffer(dev, PCI_EXT_CAP_ID_PTM, sizeof(u32));
+ if (pci_reserve_saved_cap(dev, ptm + PCI_PTM_CTRL, sizeof(u32)))
+ pci_err(dev, "unable to reserve PTM save state\n");
pci_read_config_dword(dev, ptm + PCI_PTM_CAP, &cap);
dev->ptm_granularity = FIELD_GET(PCI_PTM_GRANULARITY_MASK, cap);
@@ -90,36 +91,18 @@ void pci_ptm_init(struct pci_dev *dev)
void pci_save_ptm_state(struct pci_dev *dev)
{
- u16 ptm = dev->ptm_cap;
- struct pci_cap_saved_state *save_state;
- u32 *cap;
-
- if (!ptm)
- return;
-
- save_state = pci_find_saved_ext_cap(dev, PCI_EXT_CAP_ID_PTM);
- if (!save_state)
+ if (!dev->ptm_cap)
return;
- cap = (u32 *)&save_state->cap.data[0];
- pci_read_config_dword(dev, ptm + PCI_PTM_CTRL, cap);
+ pci_save_cap_dword(dev, dev->ptm_cap + PCI_PTM_CTRL);
}
void pci_restore_ptm_state(struct pci_dev *dev)
{
- u16 ptm = dev->ptm_cap;
- struct pci_cap_saved_state *save_state;
- u32 *cap;
-
- if (!ptm)
- return;
-
- save_state = pci_find_saved_ext_cap(dev, PCI_EXT_CAP_ID_PTM);
- if (!save_state)
+ if (!dev->ptm_cap)
return;
- cap = (u32 *)&save_state->cap.data[0];
- pci_write_config_dword(dev, ptm + PCI_PTM_CTRL, *cap);
+ pci_restore_cap_dword(dev, dev->ptm_cap + PCI_PTM_CTRL);
}
/* Enable PTM in the Control register if possible */
--
2.56.0.rc1.315.gc6ed9934b7-goog