]> git.karo-electronics.de Git - linux-beck.git/commitdiff
PCI: Add pci_enable_ptm() for drivers to enable PTM on endpoints
authorBjorn Helgaas <bhelgaas@google.com>
Mon, 13 Jun 2016 16:01:51 +0000 (11:01 -0500)
committerBjorn Helgaas <bhelgaas@google.com>
Thu, 18 Aug 2016 21:04:57 +0000 (16:04 -0500)
Add an pci_enable_ptm() interface so drivers can enable PTM.

The PCI core enables PTM on PTM Roots and switches automatically, but we
don't enable PTM on endpoints unless a driver requests it.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/pcie/ptm.c
include/linux/pci.h
include/uapi/linux/pci_regs.h

index 48eea4e65247a13bf7b16772471882fcc18692d6..a14ac94b96dcdb190ff3af8a572c989e2f940764 100644 (file)
@@ -68,3 +68,48 @@ void pci_ptm_init(struct pci_dev *dev)
 
        pci_ptm_info(dev);
 }
+
+int pci_enable_ptm(struct pci_dev *dev, u8 *granularity)
+{
+       int pos;
+       u32 cap, ctrl;
+       struct pci_dev *ups;
+
+       if (!pci_is_pcie(dev))
+               return -EINVAL;
+
+       pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_PTM);
+       if (!pos)
+               return -EINVAL;
+
+       pci_read_config_dword(dev, pos + PCI_PTM_CAP, &cap);
+       if (!(cap & PCI_PTM_CAP_REQ))
+               return -EINVAL;
+
+       /*
+        * For a PCIe Endpoint, PTM is only useful if the endpoint can
+        * issue PTM requests to upstream devices that have PTM enabled.
+        *
+        * For Root Complex Integrated Endpoints, there is no upstream
+        * device, so there must be some implementation-specific way to
+        * associate the endpoint with a time source.
+        */
+       if (pci_pcie_type(dev) == PCI_EXP_TYPE_ENDPOINT) {
+               ups = pci_upstream_bridge(dev);
+               if (!ups || !ups->ptm_enabled)
+                       return -EINVAL;
+       } else if (pci_pcie_type(dev) == PCI_EXP_TYPE_RC_END) {
+       } else
+               return -EINVAL;
+
+       ctrl = PCI_PTM_CTRL_ENABLE;
+       pci_write_config_dword(dev, pos + PCI_PTM_CTRL, ctrl);
+       dev->ptm_enabled = 1;
+
+       pci_ptm_info(dev);
+
+       if (granularity)
+               *granularity = 0;
+       return 0;
+}
+EXPORT_SYMBOL(pci_enable_ptm);
index 96c509fa9d46d6cc851bd396767679619906bf37..9e4b6d6f3c8d4ffbb57aea7c1018be94aba808bd 100644 (file)
@@ -1407,6 +1407,13 @@ static inline void pci_disable_ats(struct pci_dev *d) { }
 static inline int pci_ats_queue_depth(struct pci_dev *d) { return -ENODEV; }
 #endif
 
+#ifdef CONFIG_PCIE_PTM
+int pci_enable_ptm(struct pci_dev *dev, u8 *granularity);
+#else
+static inline int pci_enable_ptm(struct pci_dev *dev, u8 *granularity)
+{ return -EINVAL; }
+#endif
+
 void pci_cfg_access_lock(struct pci_dev *dev);
 bool pci_cfg_access_trylock(struct pci_dev *dev);
 void pci_cfg_access_unlock(struct pci_dev *dev);
index 926fff41b417f42248f2aa98180762940c815249..72bbe1491cbf3de1a2c966d95562c34d781d360f 100644 (file)
 
 /* Precision Time Measurement */
 #define PCI_PTM_CAP                    0x04        /* PTM Capability */
+#define  PCI_PTM_CAP_REQ               0x00000001  /* Requester capable */
 #define  PCI_PTM_CAP_ROOT              0x00000004  /* Root capable */
 #define PCI_PTM_CTRL                   0x08        /* PTM Control */
 #define  PCI_PTM_CTRL_ENABLE           0x00000001  /* PTM enable */