aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOhad Ben-Cohen <ohad@wizery.com>2012-05-21 13:20:05 -0400
committerJoerg Roedel <joerg.roedel@amd.com>2012-05-22 12:08:08 -0400
commit77ca23323594589ac8cba1c8d59bfe7e85d3cb8b (patch)
tree7b2f6e2c95e799084043e36266cecdc0a6198e01
parent76e10d158efb6d4516018846f60c2ab5501900bc (diff)
iommu/core: pass a user-provided token to fault handlers
Sometimes a single IOMMU user may have to deal with several different IOMMU devices (e.g. remoteproc). When an IOMMU fault happens, such users have to regain their context in order to deal with the fault. Users can't use the private fields of neither the iommu_domain nor the IOMMU device, because those are already used by the IOMMU core and low level driver (respectively). This patch just simply allows users to pass a private token (most notably their own context pointer) to iommu_set_fault_handler(), and then makes sure it is provided back to the users whenever an IOMMU fault happens. The patch also adopts remoteproc to the new fault handling interface, but the real functionality using this (recovery of remote processors) will only be added later in a subsequent patch set. Cc: Fernando Guzman Lugo <fernando.lugo@ti.com> Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com> Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
-rw-r--r--drivers/iommu/iommu.c5
-rw-r--r--drivers/remoteproc/remoteproc_core.c4
-rw-r--r--include/linux/iommu.h10
3 files changed, 12 insertions, 7 deletions
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 2198b2dbbcd3..8b9ded88e6f5 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -119,6 +119,7 @@ EXPORT_SYMBOL_GPL(iommu_present);
119 * iommu_set_fault_handler() - set a fault handler for an iommu domain 119 * iommu_set_fault_handler() - set a fault handler for an iommu domain
120 * @domain: iommu domain 120 * @domain: iommu domain
121 * @handler: fault handler 121 * @handler: fault handler
122 * @token: user data, will be passed back to the fault handler
122 * 123 *
123 * This function should be used by IOMMU users which want to be notified 124 * This function should be used by IOMMU users which want to be notified
124 * whenever an IOMMU fault happens. 125 * whenever an IOMMU fault happens.
@@ -127,11 +128,13 @@ EXPORT_SYMBOL_GPL(iommu_present);
127 * error code otherwise. 128 * error code otherwise.
128 */ 129 */
129void iommu_set_fault_handler(struct iommu_domain *domain, 130void iommu_set_fault_handler(struct iommu_domain *domain,
130 iommu_fault_handler_t handler) 131 iommu_fault_handler_t handler,
132 void *token)
131{ 133{
132 BUG_ON(!domain); 134 BUG_ON(!domain);
133 135
134 domain->handler = handler; 136 domain->handler = handler;
137 domain->handler_token = token;
135} 138}
136EXPORT_SYMBOL_GPL(iommu_set_fault_handler); 139EXPORT_SYMBOL_GPL(iommu_set_fault_handler);
137 140
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index e756a0df3664..289293a5cbb0 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -78,7 +78,7 @@ typedef int (*rproc_handle_resource_t)(struct rproc *rproc, void *, int avail);
78 * the recovery of the remote processor. 78 * the recovery of the remote processor.
79 */ 79 */
80static int rproc_iommu_fault(struct iommu_domain *domain, struct device *dev, 80static int rproc_iommu_fault(struct iommu_domain *domain, struct device *dev,
81 unsigned long iova, int flags) 81 unsigned long iova, int flags, void *token)
82{ 82{
83 dev_err(dev, "iommu fault: da 0x%lx flags 0x%x\n", iova, flags); 83 dev_err(dev, "iommu fault: da 0x%lx flags 0x%x\n", iova, flags);
84 84
@@ -117,7 +117,7 @@ static int rproc_enable_iommu(struct rproc *rproc)
117 return -ENOMEM; 117 return -ENOMEM;
118 } 118 }
119 119
120 iommu_set_fault_handler(domain, rproc_iommu_fault); 120 iommu_set_fault_handler(domain, rproc_iommu_fault, rproc);
121 121
122 ret = iommu_attach_device(domain, dev); 122 ret = iommu_attach_device(domain, dev);
123 if (ret) { 123 if (ret) {
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index d937580417ba..450293f6d68b 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -35,12 +35,13 @@ struct iommu_domain;
35#define IOMMU_FAULT_WRITE 0x1 35#define IOMMU_FAULT_WRITE 0x1
36 36
37typedef int (*iommu_fault_handler_t)(struct iommu_domain *, 37typedef int (*iommu_fault_handler_t)(struct iommu_domain *,
38 struct device *, unsigned long, int); 38 struct device *, unsigned long, int, void *);
39 39
40struct iommu_domain { 40struct iommu_domain {
41 struct iommu_ops *ops; 41 struct iommu_ops *ops;
42 void *priv; 42 void *priv;
43 iommu_fault_handler_t handler; 43 iommu_fault_handler_t handler;
44 void *handler_token;
44}; 45};
45 46
46#define IOMMU_CAP_CACHE_COHERENCY 0x1 47#define IOMMU_CAP_CACHE_COHERENCY 0x1
@@ -95,7 +96,7 @@ extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
95extern int iommu_domain_has_cap(struct iommu_domain *domain, 96extern int iommu_domain_has_cap(struct iommu_domain *domain,
96 unsigned long cap); 97 unsigned long cap);
97extern void iommu_set_fault_handler(struct iommu_domain *domain, 98extern void iommu_set_fault_handler(struct iommu_domain *domain,
98 iommu_fault_handler_t handler); 99 iommu_fault_handler_t handler, void *token);
99extern int iommu_device_group(struct device *dev, unsigned int *groupid); 100extern int iommu_device_group(struct device *dev, unsigned int *groupid);
100 101
101/** 102/**
@@ -132,7 +133,8 @@ static inline int report_iommu_fault(struct iommu_domain *domain,
132 * invoke it. 133 * invoke it.
133 */ 134 */
134 if (domain->handler) 135 if (domain->handler)
135 ret = domain->handler(domain, dev, iova, flags); 136 ret = domain->handler(domain, dev, iova, flags,
137 domain->handler_token);
136 138
137 return ret; 139 return ret;
138} 140}
@@ -191,7 +193,7 @@ static inline int domain_has_cap(struct iommu_domain *domain,
191} 193}
192 194
193static inline void iommu_set_fault_handler(struct iommu_domain *domain, 195static inline void iommu_set_fault_handler(struct iommu_domain *domain,
194 iommu_fault_handler_t handler) 196 iommu_fault_handler_t handler, void *token)
195{ 197{
196} 198}
197 199