aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/iommu.h
diff options
context:
space:
mode:
authorOhad Ben-Cohen <ohad@wizery.com>2011-09-13 15:25:23 -0400
committerJoerg Roedel <joerg.roedel@amd.com>2011-09-14 09:35:36 -0400
commit4f3f8d9db359bbc780d482849f2a9c8b12f910b6 (patch)
tree4875209af7bc93421e9f7541ff0182c5aa5d97c3 /include/linux/iommu.h
parent5e1b612cb16f446996398bd23b6cd59ea0206938 (diff)
iommu/core: Add fault reporting mechanism
Add iommu fault report mechanism to the IOMMU API, so implementations could report about mmu faults (translation errors, hardware errors, etc..). Fault reports can be used in several ways: - mere logging - reset the device that accessed the faulting address (may be necessary in case the device is a remote processor for example) - implement dynamic PTE/TLB loading A dedicated iommu_set_fault_handler() API has been added to allow users, who are interested to receive such reports, to provide their handler. Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com> Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Diffstat (limited to 'include/linux/iommu.h')
-rw-r--r--include/linux/iommu.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 9940319d6f9d..d084e8777e0e 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -26,9 +26,18 @@
26#define IOMMU_CACHE (4) /* DMA cache coherency */ 26#define IOMMU_CACHE (4) /* DMA cache coherency */
27 27
28struct device; 28struct device;
29struct iommu_domain;
30
31/* iommu fault flags */
32#define IOMMU_FAULT_READ 0x0
33#define IOMMU_FAULT_WRITE 0x1
34
35typedef int (*iommu_fault_handler_t)(struct iommu_domain *,
36 struct device *, unsigned long, int);
29 37
30struct iommu_domain { 38struct iommu_domain {
31 void *priv; 39 void *priv;
40 iommu_fault_handler_t handler;
32}; 41};
33 42
34#define IOMMU_CAP_CACHE_COHERENCY 0x1 43#define IOMMU_CAP_CACHE_COHERENCY 0x1
@@ -67,6 +76,43 @@ extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
67 unsigned long iova); 76 unsigned long iova);
68extern int iommu_domain_has_cap(struct iommu_domain *domain, 77extern int iommu_domain_has_cap(struct iommu_domain *domain,
69 unsigned long cap); 78 unsigned long cap);
79extern void iommu_set_fault_handler(struct iommu_domain *domain,
80 iommu_fault_handler_t handler);
81
82/**
83 * report_iommu_fault() - report about an IOMMU fault to the IOMMU framework
84 * @domain: the iommu domain where the fault has happened
85 * @dev: the device where the fault has happened
86 * @iova: the faulting address
87 * @flags: mmu fault flags (e.g. IOMMU_FAULT_READ/IOMMU_FAULT_WRITE/...)
88 *
89 * This function should be called by the low-level IOMMU implementations
90 * whenever IOMMU faults happen, to allow high-level users, that are
91 * interested in such events, to know about them.
92 *
93 * This event may be useful for several possible use cases:
94 * - mere logging of the event
95 * - dynamic TLB/PTE loading
96 * - if restarting of the faulting device is required
97 *
98 * Returns 0 on success and an appropriate error code otherwise (if dynamic
99 * PTE/TLB loading will one day be supported, implementations will be able
100 * to tell whether it succeeded or not according to this return value).
101 */
102static inline int report_iommu_fault(struct iommu_domain *domain,
103 struct device *dev, unsigned long iova, int flags)
104{
105 int ret = 0;
106
107 /*
108 * if upper layers showed interest and installed a fault handler,
109 * invoke it.
110 */
111 if (domain->handler)
112 ret = domain->handler(domain, dev, iova, flags);
113
114 return ret;
115}
70 116
71#else /* CONFIG_IOMMU_API */ 117#else /* CONFIG_IOMMU_API */
72 118
@@ -123,6 +169,11 @@ static inline int domain_has_cap(struct iommu_domain *domain,
123 return 0; 169 return 0;
124} 170}
125 171
172static inline void iommu_set_fault_handler(struct iommu_domain *domain,
173 iommu_fault_handler_t handler)
174{
175}
176
126#endif /* CONFIG_IOMMU_API */ 177#endif /* CONFIG_IOMMU_API */
127 178
128#endif /* __LINUX_IOMMU_H */ 179#endif /* __LINUX_IOMMU_H */