Commit e4b87d22 authored by Rob Clark's avatar Rob Clark

drm/msm/gem: Add some _locked() helpers

When we cut-over to using dma_resv_lock/etc instead of msm_obj->lock,
we'll need these for the submit path (where resv->lock is already held).
Signed-off-by: default avatarRob Clark <robdclark@chromium.org>
Reviewed-by: default avatarKristian H. Kristensen <hoegsberg@google.com>
Signed-off-by: default avatarRob Clark <robdclark@chromium.org>
parent 8f642378
...@@ -434,18 +434,14 @@ static int msm_gem_pin_iova(struct drm_gem_object *obj, ...@@ -434,18 +434,14 @@ static int msm_gem_pin_iova(struct drm_gem_object *obj,
msm_obj->sgt, obj->size >> PAGE_SHIFT); msm_obj->sgt, obj->size >> PAGE_SHIFT);
} }
/* static int get_and_pin_iova_range_locked(struct drm_gem_object *obj,
* get iova and pin it. Should have a matching put
* limits iova to specified range (in pages)
*/
int msm_gem_get_and_pin_iova_range(struct drm_gem_object *obj,
struct msm_gem_address_space *aspace, uint64_t *iova, struct msm_gem_address_space *aspace, uint64_t *iova,
u64 range_start, u64 range_end) u64 range_start, u64 range_end)
{ {
u64 local; u64 local;
int ret; int ret;
msm_gem_lock(obj); WARN_ON(!msm_gem_is_locked(obj));
ret = get_iova_locked(obj, aspace, &local, ret = get_iova_locked(obj, aspace, &local,
range_start, range_end); range_start, range_end);
...@@ -456,10 +452,32 @@ int msm_gem_get_and_pin_iova_range(struct drm_gem_object *obj, ...@@ -456,10 +452,32 @@ int msm_gem_get_and_pin_iova_range(struct drm_gem_object *obj,
if (!ret) if (!ret)
*iova = local; *iova = local;
return ret;
}
/*
* get iova and pin it. Should have a matching put
* limits iova to specified range (in pages)
*/
int msm_gem_get_and_pin_iova_range(struct drm_gem_object *obj,
struct msm_gem_address_space *aspace, uint64_t *iova,
u64 range_start, u64 range_end)
{
int ret;
msm_gem_lock(obj);
ret = get_and_pin_iova_range_locked(obj, aspace, iova, range_start, range_end);
msm_gem_unlock(obj); msm_gem_unlock(obj);
return ret; return ret;
} }
int msm_gem_get_and_pin_iova_locked(struct drm_gem_object *obj,
struct msm_gem_address_space *aspace, uint64_t *iova)
{
return get_and_pin_iova_range_locked(obj, aspace, iova, 0, U64_MAX);
}
/* get iova and pin it. Should have a matching put */ /* get iova and pin it. Should have a matching put */
int msm_gem_get_and_pin_iova(struct drm_gem_object *obj, int msm_gem_get_and_pin_iova(struct drm_gem_object *obj,
struct msm_gem_address_space *aspace, uint64_t *iova) struct msm_gem_address_space *aspace, uint64_t *iova)
...@@ -500,21 +518,31 @@ uint64_t msm_gem_iova(struct drm_gem_object *obj, ...@@ -500,21 +518,31 @@ uint64_t msm_gem_iova(struct drm_gem_object *obj,
} }
/* /*
* Unpin a iova by updating the reference counts. The memory isn't actually * Locked variant of msm_gem_unpin_iova()
* purged until something else (shrinker, mm_notifier, destroy, etc) decides
* to get rid of it
*/ */
void msm_gem_unpin_iova(struct drm_gem_object *obj, void msm_gem_unpin_iova_locked(struct drm_gem_object *obj,
struct msm_gem_address_space *aspace) struct msm_gem_address_space *aspace)
{ {
struct msm_gem_vma *vma; struct msm_gem_vma *vma;
msm_gem_lock(obj); WARN_ON(!msm_gem_is_locked(obj));
vma = lookup_vma(obj, aspace); vma = lookup_vma(obj, aspace);
if (!WARN_ON(!vma)) if (!WARN_ON(!vma))
msm_gem_unmap_vma(aspace, vma); msm_gem_unmap_vma(aspace, vma);
}
/*
* Unpin a iova by updating the reference counts. The memory isn't actually
* purged until something else (shrinker, mm_notifier, destroy, etc) decides
* to get rid of it
*/
void msm_gem_unpin_iova(struct drm_gem_object *obj,
struct msm_gem_address_space *aspace)
{
msm_gem_lock(obj);
msm_gem_unpin_iova_locked(obj, aspace);
msm_gem_unlock(obj); msm_gem_unlock(obj);
} }
...@@ -553,15 +581,14 @@ static void *get_vaddr(struct drm_gem_object *obj, unsigned madv) ...@@ -553,15 +581,14 @@ static void *get_vaddr(struct drm_gem_object *obj, unsigned madv)
struct msm_gem_object *msm_obj = to_msm_bo(obj); struct msm_gem_object *msm_obj = to_msm_bo(obj);
int ret = 0; int ret = 0;
WARN_ON(!msm_gem_is_locked(obj));
if (obj->import_attach) if (obj->import_attach)
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
msm_gem_lock(obj);
if (WARN_ON(msm_obj->madv > madv)) { if (WARN_ON(msm_obj->madv > madv)) {
DRM_DEV_ERROR(obj->dev->dev, "Invalid madv state: %u vs %u\n", DRM_DEV_ERROR(obj->dev->dev, "Invalid madv state: %u vs %u\n",
msm_obj->madv, madv); msm_obj->madv, madv);
msm_gem_unlock(obj);
return ERR_PTR(-EBUSY); return ERR_PTR(-EBUSY);
} }
...@@ -587,20 +614,29 @@ static void *get_vaddr(struct drm_gem_object *obj, unsigned madv) ...@@ -587,20 +614,29 @@ static void *get_vaddr(struct drm_gem_object *obj, unsigned madv)
} }
} }
msm_gem_unlock(obj);
return msm_obj->vaddr; return msm_obj->vaddr;
fail: fail:
msm_obj->vmap_count--; msm_obj->vmap_count--;
msm_gem_unlock(obj);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
void *msm_gem_get_vaddr(struct drm_gem_object *obj) void *msm_gem_get_vaddr_locked(struct drm_gem_object *obj)
{ {
return get_vaddr(obj, MSM_MADV_WILLNEED); return get_vaddr(obj, MSM_MADV_WILLNEED);
} }
void *msm_gem_get_vaddr(struct drm_gem_object *obj)
{
void *ret;
msm_gem_lock(obj);
ret = msm_gem_get_vaddr_locked(obj);
msm_gem_unlock(obj);
return ret;
}
/* /*
* Don't use this! It is for the very special case of dumping * Don't use this! It is for the very special case of dumping
* submits from GPU hangs or faults, were the bo may already * submits from GPU hangs or faults, were the bo may already
...@@ -609,16 +645,29 @@ void *msm_gem_get_vaddr(struct drm_gem_object *obj) ...@@ -609,16 +645,29 @@ void *msm_gem_get_vaddr(struct drm_gem_object *obj)
*/ */
void *msm_gem_get_vaddr_active(struct drm_gem_object *obj) void *msm_gem_get_vaddr_active(struct drm_gem_object *obj)
{ {
return get_vaddr(obj, __MSM_MADV_PURGED); void *ret;
msm_gem_lock(obj);
ret = get_vaddr(obj, __MSM_MADV_PURGED);
msm_gem_unlock(obj);
return ret;
} }
void msm_gem_put_vaddr(struct drm_gem_object *obj) void msm_gem_put_vaddr_locked(struct drm_gem_object *obj)
{ {
struct msm_gem_object *msm_obj = to_msm_bo(obj); struct msm_gem_object *msm_obj = to_msm_bo(obj);
msm_gem_lock(obj); WARN_ON(!msm_gem_is_locked(obj));
WARN_ON(msm_obj->vmap_count < 1); WARN_ON(msm_obj->vmap_count < 1);
msm_obj->vmap_count--; msm_obj->vmap_count--;
}
void msm_gem_put_vaddr(struct drm_gem_object *obj)
{
msm_gem_lock(obj);
msm_gem_put_vaddr_locked(obj);
msm_gem_unlock(obj); msm_gem_unlock(obj);
} }
......
...@@ -103,10 +103,14 @@ int msm_gem_get_iova(struct drm_gem_object *obj, ...@@ -103,10 +103,14 @@ int msm_gem_get_iova(struct drm_gem_object *obj,
int msm_gem_get_and_pin_iova_range(struct drm_gem_object *obj, int msm_gem_get_and_pin_iova_range(struct drm_gem_object *obj,
struct msm_gem_address_space *aspace, uint64_t *iova, struct msm_gem_address_space *aspace, uint64_t *iova,
u64 range_start, u64 range_end); u64 range_start, u64 range_end);
int msm_gem_get_and_pin_iova_locked(struct drm_gem_object *obj,
struct msm_gem_address_space *aspace, uint64_t *iova);
int msm_gem_get_and_pin_iova(struct drm_gem_object *obj, int msm_gem_get_and_pin_iova(struct drm_gem_object *obj,
struct msm_gem_address_space *aspace, uint64_t *iova); struct msm_gem_address_space *aspace, uint64_t *iova);
uint64_t msm_gem_iova(struct drm_gem_object *obj, uint64_t msm_gem_iova(struct drm_gem_object *obj,
struct msm_gem_address_space *aspace); struct msm_gem_address_space *aspace);
void msm_gem_unpin_iova_locked(struct drm_gem_object *obj,
struct msm_gem_address_space *aspace);
void msm_gem_unpin_iova(struct drm_gem_object *obj, void msm_gem_unpin_iova(struct drm_gem_object *obj,
struct msm_gem_address_space *aspace); struct msm_gem_address_space *aspace);
struct page **msm_gem_get_pages(struct drm_gem_object *obj); struct page **msm_gem_get_pages(struct drm_gem_object *obj);
...@@ -115,8 +119,10 @@ int msm_gem_dumb_create(struct drm_file *file, struct drm_device *dev, ...@@ -115,8 +119,10 @@ int msm_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
struct drm_mode_create_dumb *args); struct drm_mode_create_dumb *args);
int msm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev, int msm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,
uint32_t handle, uint64_t *offset); uint32_t handle, uint64_t *offset);
void *msm_gem_get_vaddr_locked(struct drm_gem_object *obj);
void *msm_gem_get_vaddr(struct drm_gem_object *obj); void *msm_gem_get_vaddr(struct drm_gem_object *obj);
void *msm_gem_get_vaddr_active(struct drm_gem_object *obj); void *msm_gem_get_vaddr_active(struct drm_gem_object *obj);
void msm_gem_put_vaddr_locked(struct drm_gem_object *obj);
void msm_gem_put_vaddr(struct drm_gem_object *obj); void msm_gem_put_vaddr(struct drm_gem_object *obj);
int msm_gem_madvise(struct drm_gem_object *obj, unsigned madv); int msm_gem_madvise(struct drm_gem_object *obj, unsigned madv);
int msm_gem_sync_object(struct drm_gem_object *obj, int msm_gem_sync_object(struct drm_gem_object *obj,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment