mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-26 05:50:53 +07:00
drm/msm: convert to iommu_map_sg
Significantly simplifies things. Also iommu_unmap() can unmap an entire iova range. (If backporting to downstream kernel you might need to revert this. Or at least double check older iommu implementation.) Signed-off-by: Rob Clark <robdclark@gmail.com>
This commit is contained in:
parent
de098e5fb1
commit
f90000492e
@ -52,64 +52,20 @@ static int msm_iommu_map(struct msm_mmu *mmu, uint64_t iova,
|
|||||||
struct sg_table *sgt, unsigned len, int prot)
|
struct sg_table *sgt, unsigned len, int prot)
|
||||||
{
|
{
|
||||||
struct msm_iommu *iommu = to_msm_iommu(mmu);
|
struct msm_iommu *iommu = to_msm_iommu(mmu);
|
||||||
struct iommu_domain *domain = iommu->domain;
|
size_t ret;
|
||||||
struct scatterlist *sg;
|
|
||||||
unsigned long da = iova;
|
|
||||||
unsigned int i, j;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (!domain || !sgt)
|
ret = iommu_map_sg(iommu->domain, iova, sgt->sgl, sgt->nents, prot);
|
||||||
return -EINVAL;
|
WARN_ON(ret < 0);
|
||||||
|
|
||||||
for_each_sg(sgt->sgl, sg, sgt->nents, i) {
|
return (ret == len) ? 0 : -EINVAL;
|
||||||
dma_addr_t pa = sg_phys(sg) - sg->offset;
|
|
||||||
size_t bytes = sg->length + sg->offset;
|
|
||||||
|
|
||||||
VERB("map[%d]: %08lx %08lx(%zx)", i, da, (unsigned long)pa, bytes);
|
|
||||||
|
|
||||||
ret = iommu_map(domain, da, pa, bytes, prot);
|
|
||||||
if (ret)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
da += bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
da = iova;
|
|
||||||
|
|
||||||
for_each_sg(sgt->sgl, sg, i, j) {
|
|
||||||
size_t bytes = sg->length + sg->offset;
|
|
||||||
iommu_unmap(domain, da, bytes);
|
|
||||||
da += bytes;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int msm_iommu_unmap(struct msm_mmu *mmu, uint64_t iova,
|
static int msm_iommu_unmap(struct msm_mmu *mmu, uint64_t iova,
|
||||||
struct sg_table *sgt, unsigned len)
|
struct sg_table *sgt, unsigned len)
|
||||||
{
|
{
|
||||||
struct msm_iommu *iommu = to_msm_iommu(mmu);
|
struct msm_iommu *iommu = to_msm_iommu(mmu);
|
||||||
struct iommu_domain *domain = iommu->domain;
|
|
||||||
struct scatterlist *sg;
|
|
||||||
unsigned long da = iova;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for_each_sg(sgt->sgl, sg, sgt->nents, i) {
|
iommu_unmap(iommu->domain, iova, len);
|
||||||
size_t bytes = sg->length + sg->offset;
|
|
||||||
size_t unmapped;
|
|
||||||
|
|
||||||
unmapped = iommu_unmap(domain, da, bytes);
|
|
||||||
if (unmapped < bytes)
|
|
||||||
return unmapped;
|
|
||||||
|
|
||||||
VERB("unmap[%d]: %08lx(%zx)", i, da, bytes);
|
|
||||||
|
|
||||||
BUG_ON(!PAGE_ALIGNED(bytes));
|
|
||||||
|
|
||||||
da += bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user