Lines Matching +full:iommu +full:- +full:map
1 // SPDX-License-Identifier: GPL-2.0
3 * iommu.c: IOMMU specific routines for memory management.
15 #include <linux/dma-map-ops.h>
25 #include <asm/iommu.h>
59 struct iommu_struct *iommu; in sbus_iommu_init() local
66 iommu = kmalloc(sizeof(struct iommu_struct), GFP_KERNEL); in sbus_iommu_init()
67 if (!iommu) { in sbus_iommu_init()
68 prom_printf("Unable to allocate iommu structure\n"); in sbus_iommu_init()
72 iommu->regs = of_ioremap(&op->resource[0], 0, PAGE_SIZE * 3, in sbus_iommu_init()
74 if (!iommu->regs) { in sbus_iommu_init()
75 prom_printf("Cannot map IOMMU registers\n"); in sbus_iommu_init()
79 control = sbus_readl(&iommu->regs->control); in sbus_iommu_init()
84 sbus_writel(control, &iommu->regs->control); in sbus_iommu_init()
86 iommu_invalidate(iommu->regs); in sbus_iommu_init()
87 iommu->start = IOMMU_START; in sbus_iommu_init()
88 iommu->end = 0xffffffff; in sbus_iommu_init()
90 /* Allocate IOMMU page table */ in sbus_iommu_init()
97 prom_printf("Unable to allocate iommu table [0x%lx]\n", in sbus_iommu_init()
101 iommu->page_table = (iopte_t *)tmp; in sbus_iommu_init()
104 memset(iommu->page_table, 0, IOMMU_NPTES*sizeof(iopte_t)); in sbus_iommu_init()
108 base = __pa((unsigned long)iommu->page_table) >> 4; in sbus_iommu_init()
109 sbus_writel(base, &iommu->regs->base); in sbus_iommu_init()
110 iommu_invalidate(iommu->regs); in sbus_iommu_init()
114 prom_printf("Unable to allocate iommu bitmap [%d]\n", in sbus_iommu_init()
118 bit_map_init(&iommu->usemap, bitmap, IOMMU_NPTES); in sbus_iommu_init()
123 iommu->usemap.num_colors = vac_cache_size >> PAGE_SHIFT; in sbus_iommu_init()
125 iommu->usemap.num_colors = 1; in sbus_iommu_init()
127 printk(KERN_INFO "IOMMU: impl %d vers %d table 0x%p[%d B] map [%d b]\n", in sbus_iommu_init()
128 impl, vers, iommu->page_table, in sbus_iommu_init()
131 op->dev.archdata.iommu = iommu; in sbus_iommu_init()
134 op->dev.dma_ops = &sbus_iommu_dma_gflush_ops; in sbus_iommu_init()
136 op->dev.dma_ops = &sbus_iommu_dma_pflush_ops; in sbus_iommu_init()
143 for_each_node_by_name(dp, "iommu") { in iommu_init()
186 struct iommu_struct *iommu = dev->archdata.iommu; in __sbus_iommu_map_page() local
189 unsigned long npages = (off + len + PAGE_SIZE - 1) >> PAGE_SHIFT; in __sbus_iommu_map_page()
213 ioptex = bit_map_string_get(&iommu->usemap, npages, pfn); in __sbus_iommu_map_page()
215 panic("iommu out"); in __sbus_iommu_map_page()
216 busa0 = iommu->start + (ioptex << PAGE_SHIFT); in __sbus_iommu_map_page()
217 iopte0 = &iommu->page_table[ioptex]; in __sbus_iommu_map_page()
223 iommu_invalidate_page(iommu->regs, busa); in __sbus_iommu_map_page()
256 sg->dma_address =__sbus_iommu_map_page(dev, sg_page(sg), in __sbus_iommu_map_sg()
257 sg->offset, sg->length, per_page_flush); in __sbus_iommu_map_sg()
258 if (sg->dma_address == DMA_MAPPING_ERROR) in __sbus_iommu_map_sg()
259 return -EIO; in __sbus_iommu_map_sg()
260 sg->dma_length = sg->length; in __sbus_iommu_map_sg()
282 struct iommu_struct *iommu = dev->archdata.iommu; in sbus_iommu_unmap_page() local
285 unsigned int npages = (off + len + PAGE_SIZE-1) >> PAGE_SHIFT; in sbus_iommu_unmap_page()
286 unsigned int ioptex = (busa - iommu->start) >> PAGE_SHIFT; in sbus_iommu_unmap_page()
289 BUG_ON(busa < iommu->start); in sbus_iommu_unmap_page()
291 iopte_val(iommu->page_table[ioptex + i]) = 0; in sbus_iommu_unmap_page()
292 iommu_invalidate_page(iommu->regs, busa); in sbus_iommu_unmap_page()
295 bit_map_clear(&iommu->usemap, ioptex, npages); in sbus_iommu_unmap_page()
305 sbus_iommu_unmap_page(dev, sg->dma_address, sg->length, dir, in sbus_iommu_unmap_sg()
307 sg->dma_address = 0x21212121; in sbus_iommu_unmap_sg()
315 struct iommu_struct *iommu = dev->archdata.iommu; in sbus_iommu_alloc() local
317 iopte_t *iopte = iommu->page_table; in sbus_iommu_alloc()
339 ioptex = bit_map_string_get(&iommu->usemap, len >> PAGE_SHIFT, in sbus_iommu_alloc()
342 panic("iommu out"); in sbus_iommu_alloc()
377 * IOMMU page table modifications, and usage of non-cacheable in sbus_iommu_alloc()
384 iommu_invalidate(iommu->regs); in sbus_iommu_alloc()
386 *dma_handle = iommu->start + (ioptex << PAGE_SHIFT); in sbus_iommu_alloc()
397 struct iommu_struct *iommu = dev->archdata.iommu; in sbus_iommu_free() local
398 iopte_t *iopte = iommu->page_table; in sbus_iommu_free()
400 int ioptex = (busa - iommu->start) >> PAGE_SHIFT; in sbus_iommu_free()
416 iommu_invalidate(iommu->regs); in sbus_iommu_free()
417 bit_map_clear(&iommu->usemap, ioptex, len >> PAGE_SHIFT); in sbus_iommu_free()