aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/pcie/ptm.c
diff options
context:
space:
mode:
authorBjorn Helgaas <bhelgaas@google.com>2016-06-12 17:26:40 -0400
committerBjorn Helgaas <bhelgaas@google.com>2016-08-25 09:32:34 -0400
commit8b2ec318eece89be5e33d5313a25461a55a3177a (patch)
tree96adee8ae73a95035e7d523214c8674b026377ee /drivers/pci/pcie/ptm.c
parenteec097d43100a8195fd4f678671ecd5d986dd675 (diff)
PCI: Add PTM clock granularity information
The PTM Control register (PCIe r3.1, sec 7.32.3) contains an Effective Granularity field: This provides information relating to the expected accuracy of the PTM clock, but does not otherwise affect the PTM mechanism. Set the Effective Granularity based on the PTM Root and any intervening PTM Time Sources. This does not set Effective Granularity for Root Complex Integrated Endpoints because I don't know how to figure out clock granularity for them. The spec says: ... system software must set [Effective Granularity] to the value reported in the Local Clock Granularity field by the associated PTM Time Source. but I don't know how to identify the associated PTM Time Source. Normally it's the upstream bridge, but an integrated endpoint has no upstream bridge. Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'drivers/pci/pcie/ptm.c')
-rw-r--r--drivers/pci/pcie/ptm.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/drivers/pci/pcie/ptm.c b/drivers/pci/pcie/ptm.c
index a14ac94b96dc..bab8ac63c4f3 100644
--- a/drivers/pci/pcie/ptm.c
+++ b/drivers/pci/pcie/ptm.c
@@ -19,13 +19,29 @@
19 19
20static void pci_ptm_info(struct pci_dev *dev) 20static void pci_ptm_info(struct pci_dev *dev)
21{ 21{
22 dev_info(&dev->dev, "PTM enabled%s\n", dev->ptm_root ? " (root)" : ""); 22 char clock_desc[8];
23
24 switch (dev->ptm_granularity) {
25 case 0:
26 snprintf(clock_desc, sizeof(clock_desc), "unknown");
27 break;
28 case 255:
29 snprintf(clock_desc, sizeof(clock_desc), ">254ns");
30 break;
31 default:
32 snprintf(clock_desc, sizeof(clock_desc), "%udns",
33 dev->ptm_granularity);
34 break;
35 }
36 dev_info(&dev->dev, "PTM enabled%s, %s granularity\n",
37 dev->ptm_root ? " (root)" : "", clock_desc);
23} 38}
24 39
25void pci_ptm_init(struct pci_dev *dev) 40void pci_ptm_init(struct pci_dev *dev)
26{ 41{
27 int pos; 42 int pos;
28 u32 cap, ctrl; 43 u32 cap, ctrl;
44 u8 local_clock;
29 struct pci_dev *ups; 45 struct pci_dev *ups;
30 46
31 if (!pci_is_pcie(dev)) 47 if (!pci_is_pcie(dev))
@@ -45,6 +61,7 @@ void pci_ptm_init(struct pci_dev *dev)
45 return; 61 return;
46 62
47 pci_read_config_dword(dev, pos + PCI_PTM_CAP, &cap); 63 pci_read_config_dword(dev, pos + PCI_PTM_CAP, &cap);
64 local_clock = (cap & PCI_PTM_GRANULARITY_MASK) >> 8;
48 65
49 /* 66 /*
50 * There's no point in enabling PTM unless it's enabled in the 67 * There's no point in enabling PTM unless it's enabled in the
@@ -55,14 +72,20 @@ void pci_ptm_init(struct pci_dev *dev)
55 ups = pci_upstream_bridge(dev); 72 ups = pci_upstream_bridge(dev);
56 if (ups && ups->ptm_enabled) { 73 if (ups && ups->ptm_enabled) {
57 ctrl = PCI_PTM_CTRL_ENABLE; 74 ctrl = PCI_PTM_CTRL_ENABLE;
75 if (ups->ptm_granularity == 0)
76 dev->ptm_granularity = 0;
77 else if (ups->ptm_granularity > local_clock)
78 dev->ptm_granularity = ups->ptm_granularity;
58 } else { 79 } else {
59 if (cap & PCI_PTM_CAP_ROOT) { 80 if (cap & PCI_PTM_CAP_ROOT) {
60 ctrl = PCI_PTM_CTRL_ENABLE | PCI_PTM_CTRL_ROOT; 81 ctrl = PCI_PTM_CTRL_ENABLE | PCI_PTM_CTRL_ROOT;
61 dev->ptm_root = 1; 82 dev->ptm_root = 1;
83 dev->ptm_granularity = local_clock;
62 } else 84 } else
63 return; 85 return;
64 } 86 }
65 87
88 ctrl |= dev->ptm_granularity << 8;
66 pci_write_config_dword(dev, pos + PCI_PTM_CTRL, ctrl); 89 pci_write_config_dword(dev, pos + PCI_PTM_CTRL, ctrl);
67 dev->ptm_enabled = 1; 90 dev->ptm_enabled = 1;
68 91
@@ -98,18 +121,22 @@ int pci_enable_ptm(struct pci_dev *dev, u8 *granularity)
98 ups = pci_upstream_bridge(dev); 121 ups = pci_upstream_bridge(dev);
99 if (!ups || !ups->ptm_enabled) 122 if (!ups || !ups->ptm_enabled)
100 return -EINVAL; 123 return -EINVAL;
124
125 dev->ptm_granularity = ups->ptm_granularity;
101 } else if (pci_pcie_type(dev) == PCI_EXP_TYPE_RC_END) { 126 } else if (pci_pcie_type(dev) == PCI_EXP_TYPE_RC_END) {
127 dev->ptm_granularity = 0;
102 } else 128 } else
103 return -EINVAL; 129 return -EINVAL;
104 130
105 ctrl = PCI_PTM_CTRL_ENABLE; 131 ctrl = PCI_PTM_CTRL_ENABLE;
132 ctrl |= dev->ptm_granularity << 8;
106 pci_write_config_dword(dev, pos + PCI_PTM_CTRL, ctrl); 133 pci_write_config_dword(dev, pos + PCI_PTM_CTRL, ctrl);
107 dev->ptm_enabled = 1; 134 dev->ptm_enabled = 1;
108 135
109 pci_ptm_info(dev); 136 pci_ptm_info(dev);
110 137
111 if (granularity) 138 if (granularity)
112 *granularity = 0; 139 *granularity = dev->ptm_granularity;
113 return 0; 140 return 0;
114} 141}
115EXPORT_SYMBOL(pci_enable_ptm); 142EXPORT_SYMBOL(pci_enable_ptm);