Commit 19880c4a authored by Chris Wilson's avatar Chris Wilson

drm/i915: Consolidate i915_vma_unpin_and_release()

In a few places, we repeat a call to clear a pointer to a vma whilst
unpinning and releasing a reference to its owner. Refactor those into a
common function.
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: default avatarJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1471254551-25805-26-git-send-email-chris@chris-wilson.co.uk
parent 48bb74e4
...@@ -3674,3 +3674,15 @@ void __iomem *i915_vma_pin_iomap(struct i915_vma *vma) ...@@ -3674,3 +3674,15 @@ void __iomem *i915_vma_pin_iomap(struct i915_vma *vma)
__i915_vma_pin(vma); __i915_vma_pin(vma);
return ptr; return ptr;
} }
void i915_vma_unpin_and_release(struct i915_vma **p_vma)
{
struct i915_vma *vma;
vma = fetch_and_zero(p_vma);
if (!vma)
return;
i915_vma_unpin(vma);
i915_vma_put(vma);
}
...@@ -232,6 +232,7 @@ struct i915_vma * ...@@ -232,6 +232,7 @@ struct i915_vma *
i915_vma_create(struct drm_i915_gem_object *obj, i915_vma_create(struct drm_i915_gem_object *obj,
struct i915_address_space *vm, struct i915_address_space *vm,
const struct i915_ggtt_view *view); const struct i915_ggtt_view *view);
void i915_vma_unpin_and_release(struct i915_vma **p_vma);
static inline bool i915_vma_is_ggtt(const struct i915_vma *vma) static inline bool i915_vma_is_ggtt(const struct i915_vma *vma)
{ {
......
...@@ -653,19 +653,6 @@ static struct i915_vma *guc_allocate_vma(struct intel_guc *guc, u32 size) ...@@ -653,19 +653,6 @@ static struct i915_vma *guc_allocate_vma(struct intel_guc *guc, u32 size)
return vma; return vma;
} }
/**
* guc_release_vma() - Release gem object allocated for GuC usage
* @vma: gem obj to be released
*/
static void guc_release_vma(struct i915_vma *vma)
{
if (!vma)
return;
i915_vma_unpin(vma);
i915_vma_put(vma);
}
static void static void
guc_client_free(struct drm_i915_private *dev_priv, guc_client_free(struct drm_i915_private *dev_priv,
struct i915_guc_client *client) struct i915_guc_client *client)
...@@ -690,7 +677,7 @@ guc_client_free(struct drm_i915_private *dev_priv, ...@@ -690,7 +677,7 @@ guc_client_free(struct drm_i915_private *dev_priv,
kunmap(kmap_to_page(client->client_base)); kunmap(kmap_to_page(client->client_base));
} }
guc_release_vma(client->vma); i915_vma_unpin_and_release(&client->vma);
if (client->ctx_index != GUC_INVALID_CTX_ID) { if (client->ctx_index != GUC_INVALID_CTX_ID) {
guc_fini_ctx_desc(guc, client); guc_fini_ctx_desc(guc, client);
...@@ -1048,12 +1035,12 @@ void i915_guc_submission_fini(struct drm_i915_private *dev_priv) ...@@ -1048,12 +1035,12 @@ void i915_guc_submission_fini(struct drm_i915_private *dev_priv)
{ {
struct intel_guc *guc = &dev_priv->guc; struct intel_guc *guc = &dev_priv->guc;
guc_release_vma(fetch_and_zero(&guc->ads_vma)); i915_vma_unpin_and_release(&guc->ads_vma);
guc_release_vma(fetch_and_zero(&guc->log_vma)); i915_vma_unpin_and_release(&guc->log_vma);
if (guc->ctx_pool_vma) if (guc->ctx_pool_vma)
ida_destroy(&guc->ctx_ids); ida_destroy(&guc->ctx_ids);
guc_release_vma(fetch_and_zero(&guc->ctx_pool_vma)); i915_vma_unpin_and_release(&guc->ctx_pool_vma);
} }
/** /**
......
...@@ -279,14 +279,7 @@ int intel_engine_create_scratch(struct intel_engine_cs *engine, int size) ...@@ -279,14 +279,7 @@ int intel_engine_create_scratch(struct intel_engine_cs *engine, int size)
static void intel_engine_cleanup_scratch(struct intel_engine_cs *engine) static void intel_engine_cleanup_scratch(struct intel_engine_cs *engine)
{ {
struct i915_vma *vma; i915_vma_unpin_and_release(&engine->scratch);
vma = fetch_and_zero(&engine->scratch);
if (!vma)
return;
i915_vma_unpin(vma);
i915_vma_put(vma);
} }
/** /**
......
...@@ -1193,14 +1193,7 @@ static int lrc_setup_wa_ctx_obj(struct intel_engine_cs *engine, u32 size) ...@@ -1193,14 +1193,7 @@ static int lrc_setup_wa_ctx_obj(struct intel_engine_cs *engine, u32 size)
static void lrc_destroy_wa_ctx_obj(struct intel_engine_cs *engine) static void lrc_destroy_wa_ctx_obj(struct intel_engine_cs *engine)
{ {
struct i915_vma *vma; i915_vma_unpin_and_release(&engine->wa_ctx.vma);
vma = fetch_and_zero(&engine->wa_ctx.vma);
if (!vma)
return;
i915_vma_unpin(vma);
i915_vma_put(vma);
} }
static int intel_init_workaround_bb(struct intel_engine_cs *engine) static int intel_init_workaround_bb(struct intel_engine_cs *engine)
......
...@@ -1257,14 +1257,8 @@ static int init_render_ring(struct intel_engine_cs *engine) ...@@ -1257,14 +1257,8 @@ static int init_render_ring(struct intel_engine_cs *engine)
static void render_ring_cleanup(struct intel_engine_cs *engine) static void render_ring_cleanup(struct intel_engine_cs *engine)
{ {
struct drm_i915_private *dev_priv = engine->i915; struct drm_i915_private *dev_priv = engine->i915;
struct i915_vma *vma;
vma = fetch_and_zero(&dev_priv->semaphore);
if (!vma)
return;
i915_vma_unpin(vma); i915_vma_unpin_and_release(&dev_priv->semaphore);
i915_vma_put(vma);
} }
static int gen8_rcs_signal(struct drm_i915_gem_request *req) static int gen8_rcs_signal(struct drm_i915_gem_request *req)
......
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