History

PCI: Add Precision Time Measurement (PTM) support

Add Precision Time Measurement (PTM) support (see PCIe r3.1, sec 6.22). Enable PTM on PTM Root devices and switch ports. This does not enable PTM on endpoints. There currently are no PTM-capable devices on the market, but it is expected to be supported by the Intel Apollo Lake platform. [bhelgaas: complete rework] Signed-off-by: Jonathan Yong <jonathan.yong@intel.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

Jonathan Yong committed 10 years ago

Commit 9bb04a01 parent 29b48177 files · +105 −1Browse files

Unified · Split

7 files
  1. drivers/pci/pci.h +6 −0
  2. drivers/pci/pcie/Kconfig +11 −0
  3. drivers/pci/pcie/Makefile +1 −0
  4. drivers/pci/pcie/ptm.c +70 −0
  5. drivers/pci/probe.c +3 −0
  6. include/linux/pci.h +5 −0
  7. include/uapi/linux/pci_regs.h +9 −1
drivers/pci/pci.h+6−0
@@ -332,6 +332,12 @@ static inline resource_size_t pci_resource_alignment(struct pci_dev *dev, · 331 unmodified lines
332332
333333 void pci_enable_acs(struct pci_dev *dev);
334334
335+#ifdef CONFIG_PCIE_PTM
336+void pci_ptm_init(struct pci_dev *dev);
337+#else
338+static inline void pci_ptm_init(struct pci_dev *dev) { }
339+#endif
340+
335341 struct pci_dev_reset_methods {
336342 u16 vendor;
337343 u16 device;
drivers/pci/pcie/Kconfig+11−0
@@ -92,3 +92,14 @@ config PCIE_DPC · 91 unmodified lines
9292 will be handled by the DPC driver. If your system doesn't
9393 have this capability or you do not want to use this feature,
9494 it is safe to answer N.
95+
96+config PCIE_PTM
97+ bool "PCIe Precision Time Measurement support"
98+ default n
99+ depends on PCIEPORTBUS
100+ help
101+ This enables PCI Express Precision Time Measurement (PTM)
102+ support.
103+
104+ This is only useful if you have devices that support PTM, but it
105+ is safe to enable even if you don't.
drivers/pci/pcie/Makefile+1−0
@@ -16,3 +16,4 @@ obj-$(CONFIG_PCIEAER) += aer/ · 15 unmodified lines
1616 obj-$(CONFIG_PCIE_PME) += pme.o
1717
1818 obj-$(CONFIG_PCIE_DPC) += pcie-dpc.o
19+obj-$(CONFIG_PCIE_PTM) += ptm.o
drivers/pci/pcie/ptm.c+70−0
@@ -0,0 +1,70 @@
1+/*
2+ * PCI Express Precision Time Measurement
3+ * Copyright (c) 2016, Intel Corporation.
4+ *
5+ * This program is free software; you can redistribute it and/or modify it
6+ * under the terms and conditions of the GNU General Public License,
7+ * version 2, as published by the Free Software Foundation.
8+ *
9+ * This program is distributed in the hope it will be useful, but WITHOUT
10+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12+ * more details.
13+ */
14+
15+#include <linux/module.h>
16+#include <linux/init.h>
17+#include <linux/pci.h>
18+#include "../pci.h"
19+
20+static void pci_ptm_info(struct pci_dev *dev)
21+{
22+ dev_info(&dev->dev, "PTM enabled%s\n", dev->ptm_root ? " (root)" : "");
23+}
24+
25+void pci_ptm_init(struct pci_dev *dev)
26+{
27+ int pos;
28+ u32 cap, ctrl;
29+ struct pci_dev *ups;
30+
31+ if (!pci_is_pcie(dev))
32+ return;
33+
34+ pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_PTM);
35+ if (!pos)
36+ return;
37+
38+ /*
39+ * Enable PTM only on interior devices (root ports, switch ports,
40+ * etc.) on the assumption that it causes no link traffic until an
41+ * endpoint enables it.
42+ */
43+ if ((pci_pcie_type(dev) == PCI_EXP_TYPE_ENDPOINT ||
44+ pci_pcie_type(dev) == PCI_EXP_TYPE_RC_END))
45+ return;
46+
47+ pci_read_config_dword(dev, pos + PCI_PTM_CAP, &cap);
48+
49+ /*
50+ * There's no point in enabling PTM unless it's enabled in the
51+ * upstream device or this device can be a PTM Root itself. Per
52+ * the spec recommendation (PCIe r3.1, sec 7.32.3), select the
53+ * furthest upstream Time Source as the PTM Root.
54+ */
55+ ups = pci_upstream_bridge(dev);
56+ if (ups && ups->ptm_enabled) {
57+ ctrl = PCI_PTM_CTRL_ENABLE;
58+ } else {
59+ if (cap & PCI_PTM_CAP_ROOT) {
60+ ctrl = PCI_PTM_CTRL_ENABLE | PCI_PTM_CTRL_ROOT;
61+ dev->ptm_root = 1;
62+ } else
63+ return;
64+ }
65+
66+ pci_write_config_dword(dev, pos + PCI_PTM_CTRL, ctrl);
67+ dev->ptm_enabled = 1;
68+
69+ pci_ptm_info(dev);
70+}
drivers/pci/probe.c+3−0
@@ -1667,6 +1667,9 @@ static void pci_init_capabilities(struct pci_dev *dev) · 1666 unmodified lines
16671667 pci_enable_acs(dev);
16681668
16691669 pci_cleanup_aer_error_status_regs(dev);
1670+
1671+ /* Precision Time Measurement */
1672+ pci_ptm_init(dev);
16701673 }
16711674
16721675 /*
include/linux/pci.h+5−0
@@ -367,6 +367,11 @@ struct pci_dev { · 366 unmodified lines
367367 int rom_attr_enabled; /* has display of the rom attribute been enabled? */
368368 struct bin_attribute *res_attr[DEVICE_COUNT_RESOURCE]; /* sysfs file for resources */
369369 struct bin_attribute *res_attr_wc[DEVICE_COUNT_RESOURCE]; /* sysfs file for WC mapping of resources */
370+
371+#ifdef CONFIG_PCIE_PTM
372+ unsigned int ptm_root:1;
373+ unsigned int ptm_enabled:1;
374+#endif
370375 #ifdef CONFIG_PCI_MSI
371376 const struct attribute_group **msi_irq_groups;
372377 #endif
include/uapi/linux/pci_regs.h+9−1
@@ -671,7 +671,8 @@ · 670 unmodified lines
671671 #define PCI_EXT_CAP_ID_PMUX 0x1A /* Protocol Multiplexing */
672672 #define PCI_EXT_CAP_ID_PASID 0x1B /* Process Address Space ID */
673673 #define PCI_EXT_CAP_ID_DPC 0x1D /* Downstream Port Containment */
674−#define PCI_EXT_CAP_ID_MAX PCI_EXT_CAP_ID_DPC
674+#define PCI_EXT_CAP_ID_PTM 0x1F /* Precision Time Measurement */
675+#define PCI_EXT_CAP_ID_MAX PCI_EXT_CAP_ID_PTM
675676
676677 #define PCI_EXT_CAP_DSN_SIZEOF 12
677678 #define PCI_EXT_CAP_MCAST_ENDPOINT_SIZEOF 40
@@ -964,4 +965,11 @@ · 286 unmodified lines
964965
965966 #define PCI_EXP_DPC_SOURCE_ID 10 /* DPC Source Identifier */
966967
968+/* Precision Time Measurement */
969+#define PCI_PTM_CAP 0x04 /* PTM Capability */
970+#define PCI_PTM_CAP_ROOT 0x00000004 /* Root capable */
971+#define PCI_PTM_CTRL 0x08 /* PTM Control */
972+#define PCI_PTM_CTRL_ENABLE 0x00000001 /* PTM enable */
973+#define PCI_PTM_CTRL_ROOT 0x00000002 /* Root select */
974+
967975 #endif /* LINUX_PCI_REGS_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t