Lines Matching +full:iommu +full:- +full:ctx

1 // SPDX-License-Identifier: GPL-2.0-only
23 struct host1x_memory_context_list *cdl = &host1x->context_list; in host1x_memory_context_list_init()
24 struct device_node *node = host1x->dev->of_node; in host1x_memory_context_list_init()
25 struct host1x_memory_context *ctx; in host1x_memory_context_list_init() local
29 cdl->devs = NULL; in host1x_memory_context_list_init()
30 cdl->len = 0; in host1x_memory_context_list_init()
31 mutex_init(&cdl->lock); in host1x_memory_context_list_init()
33 err = of_property_count_u32_elems(node, "iommu-map"); in host1x_memory_context_list_init()
37 cdl->len = err / 4; in host1x_memory_context_list_init()
38 cdl->devs = kcalloc(cdl->len, sizeof(*cdl->devs), GFP_KERNEL); in host1x_memory_context_list_init()
39 if (!cdl->devs) in host1x_memory_context_list_init()
40 return -ENOMEM; in host1x_memory_context_list_init()
42 for (i = 0; i < cdl->len; i++) { in host1x_memory_context_list_init()
43 ctx = &cdl->devs[i]; in host1x_memory_context_list_init()
45 ctx->host = host1x; in host1x_memory_context_list_init()
47 device_initialize(&ctx->dev); in host1x_memory_context_list_init()
53 ctx->dma_mask = DMA_BIT_MASK(38); in host1x_memory_context_list_init()
54 ctx->dev.dma_mask = &ctx->dma_mask; in host1x_memory_context_list_init()
55 ctx->dev.coherent_dma_mask = ctx->dma_mask; in host1x_memory_context_list_init()
56 dev_set_name(&ctx->dev, "host1x-ctx.%d", i); in host1x_memory_context_list_init()
57 ctx->dev.bus = &host1x_context_device_bus_type; in host1x_memory_context_list_init()
58 ctx->dev.parent = host1x->dev; in host1x_memory_context_list_init()
59 ctx->dev.release = host1x_memory_context_release; in host1x_memory_context_list_init()
61 ctx->dev.dma_parms = &ctx->dma_parms; in host1x_memory_context_list_init()
62 dma_set_max_seg_size(&ctx->dev, UINT_MAX); in host1x_memory_context_list_init()
64 err = device_add(&ctx->dev); in host1x_memory_context_list_init()
66 dev_err(host1x->dev, "could not add context device %d: %d\n", i, err); in host1x_memory_context_list_init()
67 put_device(&ctx->dev); in host1x_memory_context_list_init()
71 err = of_dma_configure_id(&ctx->dev, node, true, &i); in host1x_memory_context_list_init()
73 dev_err(host1x->dev, "IOMMU configuration failed for context device %d: %d\n", in host1x_memory_context_list_init()
75 device_unregister(&ctx->dev); in host1x_memory_context_list_init()
79 if (!tegra_dev_iommu_get_stream_id(&ctx->dev, &ctx->stream_id) || in host1x_memory_context_list_init()
80 !device_iommu_mapped(&ctx->dev)) { in host1x_memory_context_list_init()
81 dev_err(host1x->dev, "Context device %d has no IOMMU!\n", i); in host1x_memory_context_list_init()
82 device_unregister(&ctx->dev); in host1x_memory_context_list_init()
85 * This means that if IOMMU is disabled but context devices in host1x_memory_context_list_init()
89 err = -EINVAL; in host1x_memory_context_list_init()
98 while (i--) in host1x_memory_context_list_init()
99 device_unregister(&cdl->devs[i].dev); in host1x_memory_context_list_init()
101 kfree(cdl->devs); in host1x_memory_context_list_init()
102 cdl->devs = NULL; in host1x_memory_context_list_init()
103 cdl->len = 0; in host1x_memory_context_list_init()
112 for (i = 0; i < cdl->len; i++) in host1x_memory_context_list_free()
113 device_unregister(&cdl->devs[i].dev); in host1x_memory_context_list_free()
115 kfree(cdl->devs); in host1x_memory_context_list_free()
116 cdl->len = 0; in host1x_memory_context_list_free()
123 struct host1x_memory_context_list *cdl = &host1x->context_list; in host1x_memory_context_alloc()
127 if (!cdl->len) in host1x_memory_context_alloc()
128 return ERR_PTR(-EOPNOTSUPP); in host1x_memory_context_alloc()
130 mutex_lock(&cdl->lock); in host1x_memory_context_alloc()
132 for (i = 0; i < cdl->len; i++) { in host1x_memory_context_alloc()
133 struct host1x_memory_context *cd = &cdl->devs[i]; in host1x_memory_context_alloc()
135 if (cd->dev.iommu->iommu_dev != dev->iommu->iommu_dev) in host1x_memory_context_alloc()
138 if (cd->owner == pid) { in host1x_memory_context_alloc()
139 refcount_inc(&cd->ref); in host1x_memory_context_alloc()
140 mutex_unlock(&cdl->lock); in host1x_memory_context_alloc()
142 } else if (!cd->owner && !free) { in host1x_memory_context_alloc()
148 mutex_unlock(&cdl->lock); in host1x_memory_context_alloc()
149 return ERR_PTR(-EBUSY); in host1x_memory_context_alloc()
152 refcount_set(&free->ref, 1); in host1x_memory_context_alloc()
153 free->owner = get_pid(pid); in host1x_memory_context_alloc()
155 mutex_unlock(&cdl->lock); in host1x_memory_context_alloc()
163 refcount_inc(&cd->ref); in host1x_memory_context_get()
169 struct host1x_memory_context_list *cdl = &cd->host->context_list; in host1x_memory_context_put()
171 if (refcount_dec_and_mutex_lock(&cd->ref, &cdl->lock)) { in host1x_memory_context_put()
172 put_pid(cd->owner); in host1x_memory_context_put()
173 cd->owner = NULL; in host1x_memory_context_put()
174 mutex_unlock(&cdl->lock); in host1x_memory_context_put()