Skip to content

Commit

Permalink
drm/msm/gem: Rework vma lookup and pin
Browse files Browse the repository at this point in the history
Combines duplicate vma lookup in the get_and_pin path.

Signed-off-by: Rob Clark <[email protected]>
Reviewed-by: Dmitry Osipenko <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Rob Clark <[email protected]>
  • Loading branch information
robclark committed Apr 21, 2022
1 parent d413e6f commit 522f1ab
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions drivers/gpu/drm/msm/msm_gem.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,39 +376,40 @@ put_iova_vmas(struct drm_gem_object *obj)
}
}

static int get_iova_locked(struct drm_gem_object *obj,
struct msm_gem_address_space *aspace, uint64_t *iova,
static struct msm_gem_vma *get_vma_locked(struct drm_gem_object *obj,
struct msm_gem_address_space *aspace,
u64 range_start, u64 range_end)
{
struct msm_gem_vma *vma;
int ret = 0;

GEM_WARN_ON(!msm_gem_is_locked(obj));

vma = lookup_vma(obj, aspace);

if (!vma) {
int ret;

vma = add_vma(obj, aspace);
if (IS_ERR(vma))
return PTR_ERR(vma);
return vma;

ret = msm_gem_init_vma(aspace, vma, obj->size,
range_start, range_end);
if (ret) {
del_vma(vma);
return ret;
return ERR_PTR(ret);
}
} else {
GEM_WARN_ON(vma->iova < range_start);
GEM_WARN_ON((vma->iova + obj->size) > range_end);
}

*iova = vma->iova;
return 0;
return vma;
}

static int msm_gem_pin_iova(struct drm_gem_object *obj,
struct msm_gem_address_space *aspace)
static int msm_gem_pin_iova(struct drm_gem_object *obj, struct msm_gem_vma *vma)
{
struct msm_gem_object *msm_obj = to_msm_bo(obj);
struct msm_gem_vma *vma;
struct page **pages;
int ret, prot = IOMMU_READ;

Expand All @@ -426,15 +427,11 @@ static int msm_gem_pin_iova(struct drm_gem_object *obj,
if (GEM_WARN_ON(msm_obj->madv != MSM_MADV_WILLNEED))
return -EBUSY;

vma = lookup_vma(obj, aspace);
if (GEM_WARN_ON(!vma))
return -EINVAL;

pages = get_pages(obj);
if (IS_ERR(pages))
return PTR_ERR(pages);

ret = msm_gem_map_vma(aspace, vma, prot, msm_obj->sgt, obj->size);
ret = msm_gem_map_vma(vma->aspace, vma, prot, msm_obj->sgt, obj->size);

if (!ret)
msm_obj->pin_count++;
Expand All @@ -446,19 +443,18 @@ static int get_and_pin_iova_range_locked(struct drm_gem_object *obj,
struct msm_gem_address_space *aspace, uint64_t *iova,
u64 range_start, u64 range_end)
{
u64 local;
struct msm_gem_vma *vma;
int ret;

GEM_WARN_ON(!msm_gem_is_locked(obj));

ret = get_iova_locked(obj, aspace, &local,
range_start, range_end);

if (!ret)
ret = msm_gem_pin_iova(obj, aspace);
vma = get_vma_locked(obj, aspace, range_start, range_end);
if (IS_ERR(vma))
return PTR_ERR(vma);

ret = msm_gem_pin_iova(obj, vma);
if (!ret)
*iova = local;
*iova = vma->iova;

return ret;
}
Expand Down Expand Up @@ -500,10 +496,16 @@ int msm_gem_get_and_pin_iova(struct drm_gem_object *obj,
int msm_gem_get_iova(struct drm_gem_object *obj,
struct msm_gem_address_space *aspace, uint64_t *iova)
{
int ret;
struct msm_gem_vma *vma;
int ret = 0;

msm_gem_lock(obj);
ret = get_iova_locked(obj, aspace, iova, 0, U64_MAX);
vma = get_vma_locked(obj, aspace, 0, U64_MAX);
if (IS_ERR(vma)) {
ret = PTR_ERR(vma);
} else {
*iova = vma->iova;
}
msm_gem_unlock(obj);

return ret;
Expand Down

0 comments on commit 522f1ab

Please sign in to comment.