Lines Matching +full:host1x +full:- +full:class
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Tegra host1x Job
5 * Copyright (c) 2010-2015, NVIDIA Corporation.
8 #include <linux/dma-mapping.h>
10 #include <linux/host1x.h>
17 #include <trace/events/host1x.h>
55 job->enable_firewall = enable_firewall; in host1x_job_alloc()
57 kref_init(&job->ref); in host1x_job_alloc()
58 job->channel = ch; in host1x_job_alloc()
62 job->relocs = num_relocs ? mem : NULL; in host1x_job_alloc()
64 job->unpins = num_unpins ? mem : NULL; in host1x_job_alloc()
66 job->cmds = num_cmdbufs ? mem : NULL; in host1x_job_alloc()
68 job->addr_phys = num_unpins ? mem : NULL; in host1x_job_alloc()
70 job->reloc_addr_phys = job->addr_phys; in host1x_job_alloc()
71 job->gather_addr_phys = &job->addr_phys[num_relocs]; in host1x_job_alloc()
79 kref_get(&job->ref); in host1x_job_get()
88 if (job->release) in job_free()
89 job->release(job); in job_free()
91 if (job->waiter) in job_free()
92 host1x_intr_put_ref(job->syncpt->host, job->syncpt->id, in job_free()
93 job->waiter, false); in job_free()
95 if (job->syncpt) in job_free()
96 host1x_syncpt_put(job->syncpt); in job_free()
103 kref_put(&job->ref, job_free); in host1x_job_put()
110 struct host1x_job_gather *gather = &job->cmds[job->num_cmds].gather; in host1x_job_add_gather()
112 gather->words = words; in host1x_job_add_gather()
113 gather->bo = bo; in host1x_job_add_gather()
114 gather->offset = offset; in host1x_job_add_gather()
116 job->num_cmds++; in host1x_job_add_gather()
123 struct host1x_job_cmd *cmd = &job->cmds[job->num_cmds]; in host1x_job_add_wait()
125 cmd->is_wait = true; in host1x_job_add_wait()
126 cmd->wait.id = id; in host1x_job_add_wait()
127 cmd->wait.threshold = thresh; in host1x_job_add_wait()
128 cmd->wait.next_class = next_class; in host1x_job_add_wait()
129 cmd->wait.relative = relative; in host1x_job_add_wait()
131 job->num_cmds++; in host1x_job_add_wait()
135 static unsigned int pin_job(struct host1x *host, struct host1x_job *job) in pin_job()
138 struct host1x_client *client = job->client; in pin_job()
139 struct device *dev = client->dev; in pin_job()
144 job->num_unpins = 0; in pin_job()
146 for (i = 0; i < job->num_relocs; i++) { in pin_job()
147 struct host1x_reloc *reloc = &job->relocs[i]; in pin_job()
152 reloc->target.bo = host1x_bo_get(reloc->target.bo); in pin_job()
153 if (!reloc->target.bo) { in pin_job()
154 err = -EINVAL; in pin_job()
158 bo = reloc->target.bo; in pin_job()
160 switch (reloc->flags & mask) { in pin_job()
174 err = -EINVAL; in pin_job()
185 * host1x clients are generally not able to do scatter-gather themselves, so fail in pin_job()
189 if (map->chunks > 1) { in pin_job()
190 err = -EINVAL; in pin_job()
194 job->addr_phys[job->num_unpins] = map->phys; in pin_job()
195 job->unpins[job->num_unpins].map = map; in pin_job()
196 job->num_unpins++; in pin_job()
203 if (job->enable_firewall) in pin_job()
206 for (i = 0; i < job->num_cmds; i++) { in pin_job()
214 if (job->cmds[i].is_wait) in pin_job()
217 g = &job->cmds[i].gather; in pin_job()
219 g->bo = host1x_bo_get(g->bo); in pin_job()
220 if (!g->bo) { in pin_job()
221 err = -EINVAL; in pin_job()
225 map = host1x_bo_pin(host->dev, g->bo, DMA_TO_DEVICE, NULL); in pin_job()
231 if (host->domain) { in pin_job()
232 for_each_sgtable_sg(map->sgt, sg, j) in pin_job()
233 gather_size += sg->length; in pin_job()
235 gather_size = iova_align(&host->iova, gather_size); in pin_job()
237 shift = iova_shift(&host->iova); in pin_job()
238 alloc = alloc_iova(&host->iova, gather_size >> shift, in pin_job()
239 host->iova_end >> shift, true); in pin_job()
241 err = -ENOMEM; in pin_job()
245 err = iommu_map_sgtable(host->domain, iova_dma_addr(&host->iova, alloc), in pin_job()
246 map->sgt, IOMMU_READ); in pin_job()
248 __free_iova(&host->iova, alloc); in pin_job()
249 err = -EINVAL; in pin_job()
253 map->phys = iova_dma_addr(&host->iova, alloc); in pin_job()
254 map->size = gather_size; in pin_job()
257 job->addr_phys[job->num_unpins] = map->phys; in pin_job()
258 job->unpins[job->num_unpins].map = map; in pin_job()
259 job->num_unpins++; in pin_job()
261 job->gather_addr_phys[i] = map->phys; in pin_job()
267 host1x_bo_put(g->bo); in pin_job()
276 struct host1x_bo *cmdbuf = g->bo; in do_relocs()
280 for (i = 0; i < job->num_relocs; i++) { in do_relocs()
281 struct host1x_reloc *reloc = &job->relocs[i]; in do_relocs()
282 u32 reloc_addr = (job->reloc_addr_phys[i] + in do_relocs()
283 reloc->target.offset) >> reloc->shift; in do_relocs()
287 if (cmdbuf != reloc->cmdbuf.bo) in do_relocs()
290 if (job->enable_firewall) { in do_relocs()
291 target = (u32 *)job->gather_copy_mapped + in do_relocs()
292 reloc->cmdbuf.offset / sizeof(u32) + in do_relocs()
293 g->offset / sizeof(u32); in do_relocs()
302 return -ENOMEM; in do_relocs()
306 target = cmdbuf_addr + reloc->cmdbuf.offset; in do_relocs()
322 if (reloc->cmdbuf.bo != cmdbuf || reloc->cmdbuf.offset != offset) in check_reloc()
326 if (reloc->shift) in check_reloc()
343 u32 class; member
351 if (!fw->job->is_addr_reg) in check_register()
354 if (fw->job->is_addr_reg(fw->dev, fw->class, offset)) { in check_register()
355 if (!fw->num_relocs) in check_register()
356 return -EINVAL; in check_register()
358 if (!check_reloc(fw->reloc, fw->cmdbuf, fw->offset)) in check_register()
359 return -EINVAL; in check_register()
361 fw->num_relocs--; in check_register()
362 fw->reloc++; in check_register()
368 static int check_class(struct host1x_firewall *fw, u32 class) in check_class() argument
370 if (!fw->job->is_valid_class) { in check_class()
371 if (fw->class != class) in check_class()
372 return -EINVAL; in check_class()
374 if (!fw->job->is_valid_class(fw->class)) in check_class()
375 return -EINVAL; in check_class()
383 u32 mask = fw->mask; in check_mask()
384 u32 reg = fw->reg; in check_mask()
388 if (fw->words == 0) in check_mask()
389 return -EINVAL; in check_mask()
396 fw->words--; in check_mask()
397 fw->offset++; in check_mask()
408 u32 count = fw->count; in check_incr()
409 u32 reg = fw->reg; in check_incr()
413 if (fw->words == 0) in check_incr()
414 return -EINVAL; in check_incr()
421 fw->words--; in check_incr()
422 fw->offset++; in check_incr()
423 count--; in check_incr()
431 u32 count = fw->count; in check_nonincr()
435 if (fw->words == 0) in check_nonincr()
436 return -EINVAL; in check_nonincr()
438 ret = check_register(fw, fw->reg); in check_nonincr()
442 fw->words--; in check_nonincr()
443 fw->offset++; in check_nonincr()
444 count--; in check_nonincr()
452 u32 *cmdbuf_base = (u32 *)fw->job->gather_copy_mapped + in validate()
453 (g->offset / sizeof(u32)); in validate()
454 u32 job_class = fw->class; in validate()
457 fw->words = g->words; in validate()
458 fw->cmdbuf = g->bo; in validate()
459 fw->offset = 0; in validate()
461 while (fw->words && !err) { in validate()
462 u32 word = cmdbuf_base[fw->offset]; in validate()
465 fw->mask = 0; in validate()
466 fw->reg = 0; in validate()
467 fw->count = 0; in validate()
468 fw->words--; in validate()
469 fw->offset++; in validate()
473 fw->class = word >> 6 & 0x3ff; in validate()
474 fw->mask = word & 0x3f; in validate()
475 fw->reg = word >> 16 & 0xfff; in validate()
483 fw->reg = word >> 16 & 0xfff; in validate()
484 fw->count = word & 0xffff; in validate()
491 fw->reg = word >> 16 & 0xfff; in validate()
492 fw->count = word & 0xffff; in validate()
499 fw->mask = word & 0xffff; in validate()
500 fw->reg = word >> 16 & 0xfff; in validate()
509 err = -EINVAL; in validate()
528 fw.reloc = job->relocs; in copy_gathers()
529 fw.num_relocs = job->num_relocs; in copy_gathers()
530 fw.class = job->class; in copy_gathers()
532 for (i = 0; i < job->num_cmds; i++) { in copy_gathers()
535 if (job->cmds[i].is_wait) in copy_gathers()
538 g = &job->cmds[i].gather; in copy_gathers()
540 size += g->words * sizeof(u32); in copy_gathers()
544 * Try a non-blocking allocation from a higher priority pools first, in copy_gathers()
547 job->gather_copy_mapped = dma_alloc_wc(host, size, &job->gather_copy, in copy_gathers()
550 /* the higher priority allocation failed, try the generic-blocking */ in copy_gathers()
551 if (!job->gather_copy_mapped) in copy_gathers()
552 job->gather_copy_mapped = dma_alloc_wc(host, size, in copy_gathers()
553 &job->gather_copy, in copy_gathers()
555 if (!job->gather_copy_mapped) in copy_gathers()
556 return -ENOMEM; in copy_gathers()
558 job->gather_copy_size = size; in copy_gathers()
560 for (i = 0; i < job->num_cmds; i++) { in copy_gathers()
564 if (job->cmds[i].is_wait) in copy_gathers()
566 g = &job->cmds[i].gather; in copy_gathers()
569 gather = host1x_bo_mmap(g->bo); in copy_gathers()
570 memcpy(job->gather_copy_mapped + offset, gather + g->offset, in copy_gathers()
571 g->words * sizeof(u32)); in copy_gathers()
572 host1x_bo_munmap(g->bo, gather); in copy_gathers()
575 g->base = job->gather_copy; in copy_gathers()
576 g->offset = offset; in copy_gathers()
580 return -EINVAL; in copy_gathers()
582 offset += g->words * sizeof(u32); in copy_gathers()
587 return -EINVAL; in copy_gathers()
596 struct host1x *host = dev_get_drvdata(dev->parent); in host1x_job_pin()
603 if (job->enable_firewall) { in host1x_job_pin()
604 err = copy_gathers(host->dev, job, dev); in host1x_job_pin()
610 for (i = 0; i < job->num_cmds; i++) { in host1x_job_pin()
613 if (job->cmds[i].is_wait) in host1x_job_pin()
615 g = &job->cmds[i].gather; in host1x_job_pin()
618 if (g->handled) in host1x_job_pin()
622 if (!job->enable_firewall) in host1x_job_pin()
623 g->base = job->gather_addr_phys[i]; in host1x_job_pin()
625 for (j = i + 1; j < job->num_cmds; j++) { in host1x_job_pin()
626 if (!job->cmds[j].is_wait && in host1x_job_pin()
627 job->cmds[j].gather.bo == g->bo) { in host1x_job_pin()
628 job->cmds[j].gather.handled = true; in host1x_job_pin()
629 job->cmds[j].gather.base = g->base; in host1x_job_pin()
649 struct host1x *host = dev_get_drvdata(job->channel->dev->parent); in host1x_job_unpin()
652 for (i = 0; i < job->num_unpins; i++) { in host1x_job_unpin()
653 struct host1x_bo_mapping *map = job->unpins[i].map; in host1x_job_unpin()
654 struct host1x_bo *bo = map->bo; in host1x_job_unpin()
656 if (!job->enable_firewall && map->size && host->domain) { in host1x_job_unpin()
657 iommu_unmap(host->domain, job->addr_phys[i], map->size); in host1x_job_unpin()
658 free_iova(&host->iova, iova_pfn(&host->iova, job->addr_phys[i])); in host1x_job_unpin()
665 job->num_unpins = 0; in host1x_job_unpin()
667 if (job->gather_copy_size) in host1x_job_unpin()
668 dma_free_wc(host->dev, job->gather_copy_size, in host1x_job_unpin()
669 job->gather_copy_mapped, job->gather_copy); in host1x_job_unpin()
678 dev_dbg(dev, " SYNCPT_ID %d\n", job->syncpt->id); in host1x_job_dump()
679 dev_dbg(dev, " SYNCPT_VAL %d\n", job->syncpt_end); in host1x_job_dump()
680 dev_dbg(dev, " FIRST_GET 0x%x\n", job->first_get); in host1x_job_dump()
681 dev_dbg(dev, " TIMEOUT %d\n", job->timeout); in host1x_job_dump()
682 dev_dbg(dev, " NUM_SLOTS %d\n", job->num_slots); in host1x_job_dump()
683 dev_dbg(dev, " NUM_HANDLES %d\n", job->num_unpins); in host1x_job_dump()