Save and restore the PTM Control register through the per-device saved
capability store instead of a private pci_cap_saved_state buffer.

Reserve the register in pci_reserve_ptm_state(), called from
pci_ptm_init(), and report a refused reservation. pci_ptm_init() ignored
the return value of pci_add_ext_cap_save_buffer(), so a failed
allocation left PTM state unsaved without any message. An allocation
failure is now reported once by pci_saved_caps_finalize().

No other functional change intended.

Signed-off-by: David Matlack <[email protected]>
---
 drivers/pci/pcie/ptm.c | 38 +++++++++++++++-----------------------
 1 file changed, 15 insertions(+), 23 deletions(-)

diff --git a/drivers/pci/pcie/ptm.c b/drivers/pci/pcie/ptm.c
index bd3bd39f6372..fc653d2d1ec5 100644
--- a/drivers/pci/pcie/ptm.c
+++ b/drivers/pci/pcie/ptm.c
@@ -34,6 +34,16 @@ static struct pci_dev *pci_upstream_ptm(struct pci_dev *dev)
        return NULL;
 }
 
+static void pci_reserve_ptm_state(struct pci_dev *dev)
+{
+       int rc;
+
+       rc = pci_reserve_saved_cap(dev, dev->ptm_cap + PCI_PTM_CTRL, 
sizeof(u32));
+       if (rc)
+               pci_err(dev, "unable to reserve PTM save state (%pe)\n",
+                       ERR_PTR(rc));
+}
+
 /*
  * Find the PTM Capability (if present) and extract the information we need
  * to use it.
@@ -53,7 +63,7 @@ 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));
+       pci_reserve_ptm_state(dev);
 
        pci_read_config_dword(dev, ptm + PCI_PTM_CAP, &cap);
        dev->ptm_granularity = FIELD_GET(PCI_PTM_GRANULARITY_MASK, cap);
@@ -90,36 +100,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)
+       if (!dev->ptm_cap)
                return;
 
-       save_state = pci_find_saved_ext_cap(dev, PCI_EXT_CAP_ID_PTM);
-       if (!save_state)
-               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.455.g6c5a503b38-goog


Reply via email to