-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Jonathan Yong
authored and
Bjorn Helgaas
committed
Aug 15, 2016
1 parent
29b4817
commit 9bb04a0
Showing
7 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* PCI Express Precision Time Measurement | ||
* Copyright (c) 2016, Intel Corporation. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms and conditions of the GNU General Public License, | ||
* version 2, as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
*/ | ||
|
||
#include <linux/module.h> | ||
#include <linux/init.h> | ||
#include <linux/pci.h> | ||
#include "../pci.h" | ||
|
||
static void pci_ptm_info(struct pci_dev *dev) | ||
{ | ||
dev_info(&dev->dev, "PTM enabled%s\n", dev->ptm_root ? " (root)" : ""); | ||
} | ||
|
||
void pci_ptm_init(struct pci_dev *dev) | ||
{ | ||
int pos; | ||
u32 cap, ctrl; | ||
struct pci_dev *ups; | ||
|
||
if (!pci_is_pcie(dev)) | ||
return; | ||
|
||
pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_PTM); | ||
if (!pos) | ||
return; | ||
|
||
/* | ||
* Enable PTM only on interior devices (root ports, switch ports, | ||
* etc.) on the assumption that it causes no link traffic until an | ||
* endpoint enables it. | ||
*/ | ||
if ((pci_pcie_type(dev) == PCI_EXP_TYPE_ENDPOINT || | ||
pci_pcie_type(dev) == PCI_EXP_TYPE_RC_END)) | ||
return; | ||
|
||
pci_read_config_dword(dev, pos + PCI_PTM_CAP, &cap); | ||
|
||
/* | ||
* There's no point in enabling PTM unless it's enabled in the | ||
* upstream device or this device can be a PTM Root itself. Per | ||
* the spec recommendation (PCIe r3.1, sec 7.32.3), select the | ||
* furthest upstream Time Source as the PTM Root. | ||
*/ | ||
ups = pci_upstream_bridge(dev); | ||
if (ups && ups->ptm_enabled) { | ||
ctrl = PCI_PTM_CTRL_ENABLE; | ||
} else { | ||
if (cap & PCI_PTM_CAP_ROOT) { | ||
ctrl = PCI_PTM_CTRL_ENABLE | PCI_PTM_CTRL_ROOT; | ||
dev->ptm_root = 1; | ||
} else | ||
return; | ||
} | ||
|
||
pci_write_config_dword(dev, pos + PCI_PTM_CTRL, ctrl); | ||
dev->ptm_enabled = 1; | ||
|
||
pci_ptm_info(dev); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters