• Home
  • Raw
  • Download

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>
51 kref_init(&job->ref); in host1x_job_alloc()
52 job->channel = ch; in host1x_job_alloc()
56 job->relocs = num_relocs ? mem : NULL; in host1x_job_alloc()
58 job->unpins = num_unpins ? mem : NULL; in host1x_job_alloc()
60 job->gathers = num_cmdbufs ? mem : NULL; in host1x_job_alloc()
62 job->addr_phys = num_unpins ? mem : NULL; in host1x_job_alloc()
64 job->reloc_addr_phys = job->addr_phys; in host1x_job_alloc()
65 job->gather_addr_phys = &job->addr_phys[num_relocs]; in host1x_job_alloc()
73 kref_get(&job->ref); in host1x_job_get()
87 kref_put(&job->ref, job_free); in host1x_job_put()
94 struct host1x_job_gather *gather = &job->gathers[job->num_gathers]; in host1x_job_add_gather()
96 gather->words = words; in host1x_job_add_gather()
97 gather->bo = bo; in host1x_job_add_gather()
98 gather->offset = offset; in host1x_job_add_gather()
100 job->num_gathers++; in host1x_job_add_gather()
104 static unsigned int pin_job(struct host1x *host, struct host1x_job *job) in pin_job()
106 struct host1x_client *client = job->client; in pin_job()
107 struct device *dev = client->dev; in pin_job()
114 job->num_unpins = 0; in pin_job()
116 for (i = 0; i < job->num_relocs; i++) { in pin_job()
117 struct host1x_reloc *reloc = &job->relocs[i]; in pin_job()
121 reloc->target.bo = host1x_bo_get(reloc->target.bo); in pin_job()
122 if (!reloc->target.bo) { in pin_job()
123 err = -EINVAL; in pin_job()
132 * host1x clients, the IOVA is already available, so no in pin_job()
139 if (!domain || client->group) in pin_job()
144 sgt = host1x_bo_pin(dev, reloc->target.bo, phys); in pin_job()
155 switch (reloc->flags & mask) { in pin_job()
169 err = -EINVAL; in pin_job()
177 job->unpins[job->num_unpins].dev = dev; in pin_job()
178 job->unpins[job->num_unpins].dir = dir; in pin_job()
179 phys_addr = sg_dma_address(sgt->sgl); in pin_job()
182 job->addr_phys[job->num_unpins] = phys_addr; in pin_job()
183 job->unpins[job->num_unpins].bo = reloc->target.bo; in pin_job()
184 job->unpins[job->num_unpins].sgt = sgt; in pin_job()
185 job->num_unpins++; in pin_job()
195 for (i = 0; i < job->num_gathers; i++) { in pin_job()
205 g = &job->gathers[i]; in pin_job()
206 g->bo = host1x_bo_get(g->bo); in pin_job()
207 if (!g->bo) { in pin_job()
208 err = -EINVAL; in pin_job()
213 * If the host1x is not attached to an IOMMU, there is no need in pin_job()
214 * to map the buffer object for the host1x, since the physical in pin_job()
217 if (!iommu_get_domain_for_dev(host->dev)) in pin_job()
222 sgt = host1x_bo_pin(host->dev, g->bo, phys); in pin_job()
228 if (host->domain) { in pin_job()
230 gather_size += sg->length; in pin_job()
231 gather_size = iova_align(&host->iova, gather_size); in pin_job()
233 shift = iova_shift(&host->iova); in pin_job()
234 alloc = alloc_iova(&host->iova, gather_size >> shift, in pin_job()
235 host->iova_end >> shift, true); in pin_job()
237 err = -ENOMEM; in pin_job()
241 err = iommu_map_sgtable(host->domain, in pin_job()
242 iova_dma_addr(&host->iova, alloc), in pin_job()
245 __free_iova(&host->iova, alloc); in pin_job()
246 err = -EINVAL; in pin_job()
250 job->unpins[job->num_unpins].size = gather_size; in pin_job()
251 phys_addr = iova_dma_addr(&host->iova, alloc); in pin_job()
253 err = dma_map_sgtable(host->dev, sgt, DMA_TO_DEVICE, 0); in pin_job()
257 job->unpins[job->num_unpins].dir = DMA_TO_DEVICE; in pin_job()
258 job->unpins[job->num_unpins].dev = host->dev; in pin_job()
259 phys_addr = sg_dma_address(sgt->sgl); in pin_job()
262 job->addr_phys[job->num_unpins] = phys_addr; in pin_job()
263 job->gather_addr_phys[i] = phys_addr; in pin_job()
265 job->unpins[job->num_unpins].bo = g->bo; in pin_job()
266 job->unpins[job->num_unpins].sgt = sgt; in pin_job()
267 job->num_unpins++; in pin_job()
273 host1x_bo_put(g->bo); in pin_job()
282 struct host1x_bo *cmdbuf = g->bo; in do_relocs()
286 for (i = 0; i < job->num_relocs; i++) { in do_relocs()
287 struct host1x_reloc *reloc = &job->relocs[i]; in do_relocs()
288 u32 reloc_addr = (job->reloc_addr_phys[i] + in do_relocs()
289 reloc->target.offset) >> reloc->shift; in do_relocs()
293 if (cmdbuf != reloc->cmdbuf.bo) in do_relocs()
297 target = (u32 *)job->gather_copy_mapped + in do_relocs()
298 reloc->cmdbuf.offset / sizeof(u32) + in do_relocs()
299 g->offset / sizeof(u32); in do_relocs()
308 return -ENOMEM; in do_relocs()
312 target = cmdbuf_addr + reloc->cmdbuf.offset; in do_relocs()
328 if (reloc->cmdbuf.bo != cmdbuf || reloc->cmdbuf.offset != offset) in check_reloc()
332 if (reloc->shift) in check_reloc()
349 u32 class; member
357 if (!fw->job->is_addr_reg) in check_register()
360 if (fw->job->is_addr_reg(fw->dev, fw->class, offset)) { in check_register()
361 if (!fw->num_relocs) in check_register()
362 return -EINVAL; in check_register()
364 if (!check_reloc(fw->reloc, fw->cmdbuf, fw->offset)) in check_register()
365 return -EINVAL; in check_register()
367 fw->num_relocs--; in check_register()
368 fw->reloc++; in check_register()
374 static int check_class(struct host1x_firewall *fw, u32 class) in check_class() argument
376 if (!fw->job->is_valid_class) { in check_class()
377 if (fw->class != class) in check_class()
378 return -EINVAL; in check_class()
380 if (!fw->job->is_valid_class(fw->class)) in check_class()
381 return -EINVAL; in check_class()
389 u32 mask = fw->mask; in check_mask()
390 u32 reg = fw->reg; in check_mask()
394 if (fw->words == 0) in check_mask()
395 return -EINVAL; in check_mask()
402 fw->words--; in check_mask()
403 fw->offset++; in check_mask()
414 u32 count = fw->count; in check_incr()
415 u32 reg = fw->reg; in check_incr()
419 if (fw->words == 0) in check_incr()
420 return -EINVAL; in check_incr()
427 fw->words--; in check_incr()
428 fw->offset++; in check_incr()
429 count--; in check_incr()
437 u32 count = fw->count; in check_nonincr()
441 if (fw->words == 0) in check_nonincr()
442 return -EINVAL; in check_nonincr()
444 ret = check_register(fw, fw->reg); in check_nonincr()
448 fw->words--; in check_nonincr()
449 fw->offset++; in check_nonincr()
450 count--; in check_nonincr()
458 u32 *cmdbuf_base = (u32 *)fw->job->gather_copy_mapped + in validate()
459 (g->offset / sizeof(u32)); in validate()
460 u32 job_class = fw->class; in validate()
463 fw->words = g->words; in validate()
464 fw->cmdbuf = g->bo; in validate()
465 fw->offset = 0; in validate()
467 while (fw->words && !err) { in validate()
468 u32 word = cmdbuf_base[fw->offset]; in validate()
471 fw->mask = 0; in validate()
472 fw->reg = 0; in validate()
473 fw->count = 0; in validate()
474 fw->words--; in validate()
475 fw->offset++; in validate()
479 fw->class = word >> 6 & 0x3ff; in validate()
480 fw->mask = word & 0x3f; in validate()
481 fw->reg = word >> 16 & 0xfff; in validate()
489 fw->reg = word >> 16 & 0xfff; in validate()
490 fw->count = word & 0xffff; in validate()
497 fw->reg = word >> 16 & 0xfff; in validate()
498 fw->count = word & 0xffff; in validate()
505 fw->mask = word & 0xffff; in validate()
506 fw->reg = word >> 16 & 0xfff; in validate()
515 err = -EINVAL; in validate()
534 fw.reloc = job->relocs; in copy_gathers()
535 fw.num_relocs = job->num_relocs; in copy_gathers()
536 fw.class = job->class; in copy_gathers()
538 for (i = 0; i < job->num_gathers; i++) { in copy_gathers()
539 struct host1x_job_gather *g = &job->gathers[i]; in copy_gathers()
541 size += g->words * sizeof(u32); in copy_gathers()
545 * Try a non-blocking allocation from a higher priority pools first, in copy_gathers()
548 job->gather_copy_mapped = dma_alloc_wc(host, size, &job->gather_copy, in copy_gathers()
551 /* the higher priority allocation failed, try the generic-blocking */ in copy_gathers()
552 if (!job->gather_copy_mapped) in copy_gathers()
553 job->gather_copy_mapped = dma_alloc_wc(host, size, in copy_gathers()
554 &job->gather_copy, in copy_gathers()
556 if (!job->gather_copy_mapped) in copy_gathers()
557 return -ENOMEM; in copy_gathers()
559 job->gather_copy_size = size; in copy_gathers()
561 for (i = 0; i < job->num_gathers; i++) { in copy_gathers()
562 struct host1x_job_gather *g = &job->gathers[i]; in copy_gathers()
566 gather = host1x_bo_mmap(g->bo); in copy_gathers()
567 memcpy(job->gather_copy_mapped + offset, gather + g->offset, in copy_gathers()
568 g->words * sizeof(u32)); in copy_gathers()
569 host1x_bo_munmap(g->bo, gather); in copy_gathers()
572 g->base = job->gather_copy; in copy_gathers()
573 g->offset = offset; in copy_gathers()
577 return -EINVAL; in copy_gathers()
579 offset += g->words * sizeof(u32); in copy_gathers()
584 return -EINVAL; in copy_gathers()
593 struct host1x *host = dev_get_drvdata(dev->parent); in host1x_job_pin()
601 err = copy_gathers(host->dev, job, dev); in host1x_job_pin()
607 for (i = 0; i < job->num_gathers; i++) { in host1x_job_pin()
608 struct host1x_job_gather *g = &job->gathers[i]; in host1x_job_pin()
611 if (g->handled) in host1x_job_pin()
616 g->base = job->gather_addr_phys[i]; in host1x_job_pin()
618 for (j = i + 1; j < job->num_gathers; j++) { in host1x_job_pin()
619 if (job->gathers[j].bo == g->bo) { in host1x_job_pin()
620 job->gathers[j].handled = true; in host1x_job_pin()
621 job->gathers[j].base = g->base; in host1x_job_pin()
641 struct host1x *host = dev_get_drvdata(job->channel->dev->parent); in host1x_job_unpin()
644 for (i = 0; i < job->num_unpins; i++) { in host1x_job_unpin()
645 struct host1x_job_unpin_data *unpin = &job->unpins[i]; in host1x_job_unpin()
646 struct device *dev = unpin->dev ?: host->dev; in host1x_job_unpin()
647 struct sg_table *sgt = unpin->sgt; in host1x_job_unpin()
650 unpin->size && host->domain) { in host1x_job_unpin()
651 iommu_unmap(host->domain, job->addr_phys[i], in host1x_job_unpin()
652 unpin->size); in host1x_job_unpin()
653 free_iova(&host->iova, in host1x_job_unpin()
654 iova_pfn(&host->iova, job->addr_phys[i])); in host1x_job_unpin()
657 if (unpin->dev && sgt) in host1x_job_unpin()
658 dma_unmap_sgtable(unpin->dev, sgt, unpin->dir, 0); in host1x_job_unpin()
660 host1x_bo_unpin(dev, unpin->bo, sgt); in host1x_job_unpin()
661 host1x_bo_put(unpin->bo); in host1x_job_unpin()
664 job->num_unpins = 0; in host1x_job_unpin()
666 if (job->gather_copy_size) in host1x_job_unpin()
667 dma_free_wc(host->dev, job->gather_copy_size, in host1x_job_unpin()
668 job->gather_copy_mapped, job->gather_copy); in host1x_job_unpin()
677 dev_dbg(dev, " SYNCPT_ID %d\n", job->syncpt_id); in host1x_job_dump()
678 dev_dbg(dev, " SYNCPT_VAL %d\n", job->syncpt_end); in host1x_job_dump()
679 dev_dbg(dev, " FIRST_GET 0x%x\n", job->first_get); in host1x_job_dump()
680 dev_dbg(dev, " TIMEOUT %d\n", job->timeout); in host1x_job_dump()
681 dev_dbg(dev, " NUM_SLOTS %d\n", job->num_slots); in host1x_job_dump()
682 dev_dbg(dev, " NUM_HANDLES %d\n", job->num_unpins); in host1x_job_dump()