On Tegra234, engines that are programmed through Host1x channels can
be attached to either the NISO0 or NISO1 SMMU. Because of that, when
selecting a context device to use with an engine, we need to select
one that is also attached to the same SMMU.
Add a parameter to host1x_memory_context_alloc to specify which device
we are allocating a context for, and use it to pick an appropriate
context device.
Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
[treding@nvidia.com: update !IOMMU_API stub signature]
Signed-off-by: Thierry Reding <treding@nvidia.com>
 
                if (supported)
                        context->memory_context = host1x_memory_context_alloc(
-                               host, get_task_pid(current, PIDTYPE_TGID));
+                               host, client->base.dev, get_task_pid(current, PIDTYPE_TGID));
 
                if (IS_ERR(context->memory_context)) {
                        if (PTR_ERR(context->memory_context) != -EOPNOTSUPP) {
 
 }
 
 struct host1x_memory_context *host1x_memory_context_alloc(struct host1x *host1x,
+                                                         struct device *dev,
                                                          struct pid *pid)
 {
        struct host1x_memory_context_list *cdl = &host1x->context_list;
        for (i = 0; i < cdl->len; i++) {
                struct host1x_memory_context *cd = &cdl->devs[i];
 
+               if (cd->dev.iommu->iommu_dev != dev->iommu->iommu_dev)
+                       continue;
+
                if (cd->owner == pid) {
                        refcount_inc(&cd->ref);
                        mutex_unlock(&cdl->lock);
 
 
 #ifdef CONFIG_IOMMU_API
 struct host1x_memory_context *host1x_memory_context_alloc(struct host1x *host1x,
+                                                         struct device *dev,
                                                          struct pid *pid);
 void host1x_memory_context_get(struct host1x_memory_context *cd);
 void host1x_memory_context_put(struct host1x_memory_context *cd);
 #else
 static inline struct host1x_memory_context *host1x_memory_context_alloc(struct host1x *host1x,
+                                                                       struct device *dev,
                                                                        struct pid *pid)
 {
        return NULL;