Lines Matching refs:mapping

754 static int extend_iommu_mapping(struct dma_iommu_mapping *mapping);
756 static inline dma_addr_t __alloc_iova(struct dma_iommu_mapping *mapping, in __alloc_iova() argument
762 size_t mapping_size = mapping->bits << PAGE_SHIFT; in __alloc_iova()
773 spin_lock_irqsave(&mapping->lock, flags); in __alloc_iova()
774 for (i = 0; i < mapping->nr_bitmaps; i++) { in __alloc_iova()
775 start = bitmap_find_next_zero_area(mapping->bitmaps[i], in __alloc_iova()
776 mapping->bits, 0, count, align); in __alloc_iova()
778 if (start > mapping->bits) in __alloc_iova()
781 bitmap_set(mapping->bitmaps[i], start, count); in __alloc_iova()
790 if (i == mapping->nr_bitmaps) { in __alloc_iova()
791 if (extend_iommu_mapping(mapping)) { in __alloc_iova()
792 spin_unlock_irqrestore(&mapping->lock, flags); in __alloc_iova()
796 start = bitmap_find_next_zero_area(mapping->bitmaps[i], in __alloc_iova()
797 mapping->bits, 0, count, align); in __alloc_iova()
799 if (start > mapping->bits) { in __alloc_iova()
800 spin_unlock_irqrestore(&mapping->lock, flags); in __alloc_iova()
804 bitmap_set(mapping->bitmaps[i], start, count); in __alloc_iova()
806 spin_unlock_irqrestore(&mapping->lock, flags); in __alloc_iova()
808 iova = mapping->base + (mapping_size * i); in __alloc_iova()
814 static inline void __free_iova(struct dma_iommu_mapping *mapping, in __free_iova() argument
818 size_t mapping_size = mapping->bits << PAGE_SHIFT; in __free_iova()
826 bitmap_index = (u32) (addr - mapping->base) / (u32) mapping_size; in __free_iova()
827 BUG_ON(addr < mapping->base || bitmap_index > mapping->extensions); in __free_iova()
829 bitmap_base = mapping->base + mapping_size * bitmap_index; in __free_iova()
844 spin_lock_irqsave(&mapping->lock, flags); in __free_iova()
845 bitmap_clear(mapping->bitmaps[bitmap_index], start, count); in __free_iova()
846 spin_unlock_irqrestore(&mapping->lock, flags); in __free_iova()
965 struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); in __iommu_create_mapping() local
970 dma_addr = __alloc_iova(mapping, size); in __iommu_create_mapping()
987 ret = iommu_map(mapping->domain, iova, phys, len, in __iommu_create_mapping()
997 iommu_unmap(mapping->domain, dma_addr, iova-dma_addr); in __iommu_create_mapping()
998 __free_iova(mapping, dma_addr, size); in __iommu_create_mapping()
1004 struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); in __iommu_remove_mapping() local
1013 iommu_unmap(mapping->domain, iova, size); in __iommu_remove_mapping()
1014 __free_iova(mapping, iova, size); in __iommu_remove_mapping()
1189 struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); in __map_sg_chunk() local
1199 iova_base = iova = __alloc_iova(mapping, size); in __map_sg_chunk()
1212 ret = iommu_map(mapping->domain, iova, phys, len, prot, in __map_sg_chunk()
1223 iommu_unmap(mapping->domain, iova_base, count * PAGE_SIZE); in __map_sg_chunk()
1224 __free_iova(mapping, iova_base, size); in __map_sg_chunk()
1372 struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); in arm_iommu_map_page() local
1379 dma_addr = __alloc_iova(mapping, len); in arm_iommu_map_page()
1385 ret = iommu_map(mapping->domain, dma_addr, page_to_phys(page), len, in arm_iommu_map_page()
1392 __free_iova(mapping, dma_addr, len); in arm_iommu_map_page()
1408 struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); in arm_iommu_unmap_page() local
1418 page = phys_to_page(iommu_iova_to_phys(mapping->domain, iova)); in arm_iommu_unmap_page()
1422 iommu_unmap(mapping->domain, iova, len); in arm_iommu_unmap_page()
1423 __free_iova(mapping, iova, len); in arm_iommu_unmap_page()
1437 struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); in arm_iommu_map_resource() local
1444 dma_addr = __alloc_iova(mapping, len); in arm_iommu_map_resource()
1450 ret = iommu_map(mapping->domain, dma_addr, addr, len, prot, GFP_KERNEL); in arm_iommu_map_resource()
1456 __free_iova(mapping, dma_addr, len); in arm_iommu_map_resource()
1471 struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); in arm_iommu_unmap_resource() local
1479 iommu_unmap(mapping->domain, iova, len); in arm_iommu_unmap_resource()
1480 __free_iova(mapping, iova, len); in arm_iommu_unmap_resource()
1486 struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); in arm_iommu_sync_single_for_cpu() local
1494 page = phys_to_page(iommu_iova_to_phys(mapping->domain, iova)); in arm_iommu_sync_single_for_cpu()
1501 struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); in arm_iommu_sync_single_for_device() local
1509 page = phys_to_page(iommu_iova_to_phys(mapping->domain, iova)); in arm_iommu_sync_single_for_device()
1551 struct dma_iommu_mapping *mapping; in arm_iommu_create_mapping() local
1567 mapping = kzalloc(sizeof(struct dma_iommu_mapping), GFP_KERNEL); in arm_iommu_create_mapping()
1568 if (!mapping) in arm_iommu_create_mapping()
1571 mapping->bitmap_size = bitmap_size; in arm_iommu_create_mapping()
1572 mapping->bitmaps = kcalloc(extensions, sizeof(unsigned long *), in arm_iommu_create_mapping()
1574 if (!mapping->bitmaps) in arm_iommu_create_mapping()
1577 mapping->bitmaps[0] = kzalloc(bitmap_size, GFP_KERNEL); in arm_iommu_create_mapping()
1578 if (!mapping->bitmaps[0]) in arm_iommu_create_mapping()
1581 mapping->nr_bitmaps = 1; in arm_iommu_create_mapping()
1582 mapping->extensions = extensions; in arm_iommu_create_mapping()
1583 mapping->base = base; in arm_iommu_create_mapping()
1584 mapping->bits = BITS_PER_BYTE * bitmap_size; in arm_iommu_create_mapping()
1586 spin_lock_init(&mapping->lock); in arm_iommu_create_mapping()
1588 mapping->domain = iommu_paging_domain_alloc(dev); in arm_iommu_create_mapping()
1589 if (IS_ERR(mapping->domain)) { in arm_iommu_create_mapping()
1590 err = PTR_ERR(mapping->domain); in arm_iommu_create_mapping()
1594 kref_init(&mapping->kref); in arm_iommu_create_mapping()
1595 return mapping; in arm_iommu_create_mapping()
1597 kfree(mapping->bitmaps[0]); in arm_iommu_create_mapping()
1599 kfree(mapping->bitmaps); in arm_iommu_create_mapping()
1601 kfree(mapping); in arm_iommu_create_mapping()
1610 struct dma_iommu_mapping *mapping = in release_iommu_mapping() local
1613 iommu_domain_free(mapping->domain); in release_iommu_mapping()
1614 for (i = 0; i < mapping->nr_bitmaps; i++) in release_iommu_mapping()
1615 kfree(mapping->bitmaps[i]); in release_iommu_mapping()
1616 kfree(mapping->bitmaps); in release_iommu_mapping()
1617 kfree(mapping); in release_iommu_mapping()
1620 static int extend_iommu_mapping(struct dma_iommu_mapping *mapping) in extend_iommu_mapping() argument
1624 if (mapping->nr_bitmaps >= mapping->extensions) in extend_iommu_mapping()
1627 next_bitmap = mapping->nr_bitmaps; in extend_iommu_mapping()
1628 mapping->bitmaps[next_bitmap] = kzalloc(mapping->bitmap_size, in extend_iommu_mapping()
1630 if (!mapping->bitmaps[next_bitmap]) in extend_iommu_mapping()
1633 mapping->nr_bitmaps++; in extend_iommu_mapping()
1638 void arm_iommu_release_mapping(struct dma_iommu_mapping *mapping) in arm_iommu_release_mapping() argument
1640 if (mapping) in arm_iommu_release_mapping()
1641 kref_put(&mapping->kref, release_iommu_mapping); in arm_iommu_release_mapping()
1646 struct dma_iommu_mapping *mapping) in __arm_iommu_attach_device() argument
1650 err = iommu_attach_device(mapping->domain, dev); in __arm_iommu_attach_device()
1654 kref_get(&mapping->kref); in __arm_iommu_attach_device()
1655 to_dma_iommu_mapping(dev) = mapping; in __arm_iommu_attach_device()
1675 struct dma_iommu_mapping *mapping) in arm_iommu_attach_device() argument
1679 err = __arm_iommu_attach_device(dev, mapping); in arm_iommu_attach_device()
1697 struct dma_iommu_mapping *mapping; in arm_iommu_detach_device() local
1699 mapping = to_dma_iommu_mapping(dev); in arm_iommu_detach_device()
1700 if (!mapping) { in arm_iommu_detach_device()
1705 iommu_detach_device(mapping->domain, dev); in arm_iommu_detach_device()
1706 kref_put(&mapping->kref, release_iommu_mapping); in arm_iommu_detach_device()
1716 struct dma_iommu_mapping *mapping; in arm_setup_iommu_dma_ops() local
1723 mapping = arm_iommu_create_mapping(dev, dma_base, size); in arm_setup_iommu_dma_ops()
1724 if (IS_ERR(mapping)) { in arm_setup_iommu_dma_ops()
1730 if (__arm_iommu_attach_device(dev, mapping)) { in arm_setup_iommu_dma_ops()
1733 arm_iommu_release_mapping(mapping); in arm_setup_iommu_dma_ops()
1742 struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); in arm_teardown_iommu_dma_ops() local
1744 if (!mapping) in arm_teardown_iommu_dma_ops()
1748 arm_iommu_release_mapping(mapping); in arm_teardown_iommu_dma_ops()