2 * Copyright (C) 2016 Red Hat
3 * Author: Rob Clark <robdclark@gmail.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
23 msm_gem_unmap_vma(struct msm_gem_address_space *aspace,
24 struct msm_gem_vma *vma, struct sg_table *sgt)
30 unsigned size = vma->node.size << PAGE_SHIFT;
31 aspace->mmu->funcs->unmap(aspace->mmu, vma->iova, sgt, size);
34 drm_mm_remove_node(&vma->node);
40 msm_gem_map_vma(struct msm_gem_address_space *aspace,
41 struct msm_gem_vma *vma, struct sg_table *sgt, int npages)
45 if (WARN_ON(drm_mm_node_allocated(&vma->node)))
48 ret = drm_mm_insert_node(&aspace->mm, &vma->node, npages,
49 0, DRM_MM_SEARCH_DEFAULT);
53 vma->iova = vma->node.start << PAGE_SHIFT;
56 unsigned size = npages << PAGE_SHIFT;
57 ret = aspace->mmu->funcs->map(aspace->mmu, vma->iova, sgt,
58 size, IOMMU_READ | IOMMU_WRITE);
65 msm_gem_address_space_destroy(struct msm_gem_address_space *aspace)
67 drm_mm_takedown(&aspace->mm);
69 aspace->mmu->funcs->destroy(aspace->mmu);
73 struct msm_gem_address_space *
74 msm_gem_address_space_create(struct device *dev, struct iommu_domain *domain,
77 struct msm_gem_address_space *aspace;
79 aspace = kzalloc(sizeof(*aspace), GFP_KERNEL);
81 return ERR_PTR(-ENOMEM);
84 aspace->mmu = msm_iommu_new(dev, domain);
86 drm_mm_init(&aspace->mm, (domain->geometry.aperture_start >> PAGE_SHIFT),
87 (domain->geometry.aperture_end >> PAGE_SHIFT) - 1);