Skip to content

Commit 8c938dd

Browse files
Kuppuswamy Sathyanarayananjoergroedel
authored andcommitted
PCI/ATS: Add pci_ats_page_aligned() interface
Return the Page Aligned Request bit in the ATS Capability Register. As per PCIe spec r4.0, sec 10.5.1.2, if the Page Aligned Request bit is set, it indicates the Untranslated Addresses generated by the device are always aligned to a 4096 byte boundary. An IOMMU that can only translate page-aligned addresses can only be used with devices that always produce aligned Untranslated Addresses. This interface will be used by drivers for such IOMMUs to determine whether devices can use the ATS service. Cc: Ashok Raj <ashok.raj@intel.com> Cc: Jacob Pan <jacob.jun.pan@linux.intel.com> Cc: Keith Busch <keith.busch@intel.com> Suggested-by: Ashok Raj <ashok.raj@intel.com> Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Acked-by: Bjorn Helgaas <bhelgaas@google.com> Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 1b84778 commit 8c938dd

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

drivers/pci/ats.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,33 @@ int pci_ats_queue_depth(struct pci_dev *dev)
142142
}
143143
EXPORT_SYMBOL_GPL(pci_ats_queue_depth);
144144

145+
/**
146+
* pci_ats_page_aligned - Return Page Aligned Request bit status.
147+
* @pdev: the PCI device
148+
*
149+
* Returns 1, if the Untranslated Addresses generated by the device
150+
* are always aligned or 0 otherwise.
151+
*
152+
* Per PCIe spec r4.0, sec 10.5.1.2, if the Page Aligned Request bit
153+
* is set, it indicates the Untranslated Addresses generated by the
154+
* device are always aligned to a 4096 byte boundary.
155+
*/
156+
int pci_ats_page_aligned(struct pci_dev *pdev)
157+
{
158+
u16 cap;
159+
160+
if (!pdev->ats_cap)
161+
return 0;
162+
163+
pci_read_config_word(pdev, pdev->ats_cap + PCI_ATS_CAP, &cap);
164+
165+
if (cap & PCI_ATS_CAP_PAGE_ALIGNED)
166+
return 1;
167+
168+
return 0;
169+
}
170+
EXPORT_SYMBOL_GPL(pci_ats_page_aligned);
171+
145172
#ifdef CONFIG_PCI_PRI
146173
/**
147174
* pci_enable_pri - Enable PRI capability

include/linux/pci.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,11 +1524,13 @@ void pci_ats_init(struct pci_dev *dev);
15241524
int pci_enable_ats(struct pci_dev *dev, int ps);
15251525
void pci_disable_ats(struct pci_dev *dev);
15261526
int pci_ats_queue_depth(struct pci_dev *dev);
1527+
int pci_ats_page_aligned(struct pci_dev *dev);
15271528
#else
15281529
static inline void pci_ats_init(struct pci_dev *d) { }
15291530
static inline int pci_enable_ats(struct pci_dev *d, int ps) { return -ENODEV; }
15301531
static inline void pci_disable_ats(struct pci_dev *d) { }
15311532
static inline int pci_ats_queue_depth(struct pci_dev *d) { return -ENODEV; }
1533+
static inline int pci_ats_page_aligned(struct pci_dev *dev) { return 0; }
15321534
#endif
15331535

15341536
#ifdef CONFIG_PCIE_PTM

include/uapi/linux/pci_regs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,7 @@
866866
#define PCI_ATS_CAP 0x04 /* ATS Capability Register */
867867
#define PCI_ATS_CAP_QDEP(x) ((x) & 0x1f) /* Invalidate Queue Depth */
868868
#define PCI_ATS_MAX_QDEP 32 /* Max Invalidate Queue Depth */
869+
#define PCI_ATS_CAP_PAGE_ALIGNED 0x0020 /* Page Aligned Request */
869870
#define PCI_ATS_CTRL 0x06 /* ATS Control Register */
870871
#define PCI_ATS_CTRL_ENABLE 0x8000 /* ATS Enable */
871872
#define PCI_ATS_CTRL_STU(x) ((x) & 0x1f) /* Smallest Translation Unit */

0 commit comments

Comments
 (0)