Skip to content

Commit 2b89c22

Browse files
committed
PCI/PTM: Preserve RsvdP bits in PTM Control register
Even though only the low 16 bits of PTM Control are currently defined, the register is 32 bits wide and the unused bits are RsvdP ("Reserved and Preserved"), so software must preserve the values of those bits when writing the register. Update PTM Control reads and writes to use 32-bit accesses and preserve the reserved bits on writes. Link: https://lore.kernel.org/r/[email protected] Tested-by: Rajvi Jingar <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Kuppuswamy Sathyanarayanan <[email protected]> Reviewed-by: Mika Westerberg <[email protected]>
1 parent 91b12b2 commit 2b89c22

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

drivers/pci/pcie/ptm.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
static void __pci_disable_ptm(struct pci_dev *dev)
1313
{
1414
u16 ptm = dev->ptm_cap;
15-
u16 ctrl;
15+
u32 ctrl;
1616

1717
if (!ptm)
1818
return;
1919

20-
pci_read_config_word(dev, ptm + PCI_PTM_CTRL, &ctrl);
20+
pci_read_config_dword(dev, ptm + PCI_PTM_CTRL, &ctrl);
2121
ctrl &= ~(PCI_PTM_CTRL_ENABLE | PCI_PTM_CTRL_ROOT);
22-
pci_write_config_word(dev, ptm + PCI_PTM_CTRL, ctrl);
22+
pci_write_config_dword(dev, ptm + PCI_PTM_CTRL, ctrl);
2323
}
2424

2525
/**
@@ -41,7 +41,7 @@ void pci_save_ptm_state(struct pci_dev *dev)
4141
{
4242
u16 ptm = dev->ptm_cap;
4343
struct pci_cap_saved_state *save_state;
44-
u16 *cap;
44+
u32 *cap;
4545

4646
if (!ptm)
4747
return;
@@ -50,15 +50,15 @@ void pci_save_ptm_state(struct pci_dev *dev)
5050
if (!save_state)
5151
return;
5252

53-
cap = (u16 *)&save_state->cap.data[0];
54-
pci_read_config_word(dev, ptm + PCI_PTM_CTRL, cap);
53+
cap = (u32 *)&save_state->cap.data[0];
54+
pci_read_config_dword(dev, ptm + PCI_PTM_CTRL, cap);
5555
}
5656

5757
void pci_restore_ptm_state(struct pci_dev *dev)
5858
{
5959
u16 ptm = dev->ptm_cap;
6060
struct pci_cap_saved_state *save_state;
61-
u16 *cap;
61+
u32 *cap;
6262

6363
if (!ptm)
6464
return;
@@ -67,8 +67,8 @@ void pci_restore_ptm_state(struct pci_dev *dev)
6767
if (!save_state)
6868
return;
6969

70-
cap = (u16 *)&save_state->cap.data[0];
71-
pci_write_config_word(dev, ptm + PCI_PTM_CTRL, *cap);
70+
cap = (u32 *)&save_state->cap.data[0];
71+
pci_write_config_dword(dev, ptm + PCI_PTM_CTRL, *cap);
7272
}
7373

7474
/*
@@ -112,7 +112,7 @@ void pci_ptm_init(struct pci_dev *dev)
112112
return;
113113

114114
dev->ptm_cap = ptm;
115-
pci_add_ext_cap_save_buffer(dev, PCI_EXT_CAP_ID_PTM, sizeof(u16));
115+
pci_add_ext_cap_save_buffer(dev, PCI_EXT_CAP_ID_PTM, sizeof(u32));
116116

117117
pci_read_config_dword(dev, ptm + PCI_PTM_CAP, &cap);
118118
dev->ptm_granularity = (cap & PCI_PTM_GRANULARITY_MASK) >> 8;
@@ -170,7 +170,10 @@ static int __pci_enable_ptm(struct pci_dev *dev)
170170
return -EINVAL;
171171
}
172172

173-
ctrl = PCI_PTM_CTRL_ENABLE;
173+
pci_read_config_dword(dev, ptm + PCI_PTM_CTRL, &ctrl);
174+
175+
ctrl |= PCI_PTM_CTRL_ENABLE;
176+
ctrl &= ~PCI_PTM_GRANULARITY_MASK;
174177
ctrl |= dev->ptm_granularity << 8;
175178
if (dev->ptm_root)
176179
ctrl |= PCI_PTM_CTRL_ROOT;

0 commit comments

Comments
 (0)