Commit 8ee5702a authored by Dave Airlie's avatar Dave Airlie Committed by Alex Deucher

amdgpu/dc: use kref for dc_state.

I'm not a huge fan of those copying around refcounts bits, might
want to consider alternates, but this should work for now.
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
Reviewed-by: default avatarHarry Wentland <harry.wentland@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent cb56acea
...@@ -940,25 +940,25 @@ struct dc_state *dc_create_state(void) ...@@ -940,25 +940,25 @@ struct dc_state *dc_create_state(void)
if (!context) if (!context)
return NULL; return NULL;
atomic_inc(&context->ref_count); kref_init(&context->refcount);
return context; return context;
} }
void dc_retain_state(struct dc_state *context) void dc_retain_state(struct dc_state *context)
{ {
ASSERT(atomic_read(&context->ref_count) > 0); kref_get(&context->refcount);
atomic_inc(&context->ref_count);
} }
void dc_release_state(struct dc_state *context) static void dc_state_free(struct kref *kref)
{ {
ASSERT(atomic_read(&context->ref_count) > 0); struct dc_state *context = container_of(kref, struct dc_state, refcount);
atomic_dec(&context->ref_count); dc_resource_state_destruct(context);
kfree(context);
}
if (atomic_read(&context->ref_count) == 0) { void dc_release_state(struct dc_state *context)
dc_resource_state_destruct(context); {
kfree(context); kref_put(&context->refcount, dc_state_free);
}
} }
static bool is_surface_in_context( static bool is_surface_in_context(
...@@ -1520,7 +1520,7 @@ void dc_set_power_state( ...@@ -1520,7 +1520,7 @@ void dc_set_power_state(
struct dc *dc, struct dc *dc,
enum dc_acpi_cm_power_state power_state) enum dc_acpi_cm_power_state power_state)
{ {
atomic_t ref_count; struct kref refcount;
switch (power_state) { switch (power_state) {
case DC_ACPI_CM_POWER_STATE_D0: case DC_ACPI_CM_POWER_STATE_D0:
...@@ -1538,12 +1538,12 @@ void dc_set_power_state( ...@@ -1538,12 +1538,12 @@ void dc_set_power_state(
*/ */
/* Preserve refcount */ /* Preserve refcount */
ref_count = dc->current_state->ref_count; refcount = dc->current_state->refcount;
dc_resource_state_destruct(dc->current_state); dc_resource_state_destruct(dc->current_state);
memset(dc->current_state, 0, memset(dc->current_state, 0,
sizeof(*dc->current_state)); sizeof(*dc->current_state));
dc->current_state->ref_count = ref_count; dc->current_state->refcount = refcount;
break; break;
} }
......
...@@ -2432,7 +2432,7 @@ void dc_resource_state_copy_construct( ...@@ -2432,7 +2432,7 @@ void dc_resource_state_copy_construct(
struct dc_state *dst_ctx) struct dc_state *dst_ctx)
{ {
int i, j; int i, j;
atomic_t ref_count = dst_ctx->ref_count; struct kref refcount = dst_ctx->refcount;
*dst_ctx = *src_ctx; *dst_ctx = *src_ctx;
...@@ -2455,7 +2455,7 @@ void dc_resource_state_copy_construct( ...@@ -2455,7 +2455,7 @@ void dc_resource_state_copy_construct(
} }
/* context refcount should not be overridden */ /* context refcount should not be overridden */
dst_ctx->ref_count = ref_count; dst_ctx->refcount = refcount;
} }
......
...@@ -267,7 +267,7 @@ struct dc_state { ...@@ -267,7 +267,7 @@ struct dc_state {
struct display_clock *dis_clk; struct display_clock *dis_clk;
atomic_t ref_count; struct kref refcount;
}; };
#endif /* _CORE_TYPES_H_ */ #endif /* _CORE_TYPES_H_ */
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