2 * Copyright 2015 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
28 /* DC interface (public) */
29 #include "dm_services.h"
32 /* DC core (private) */
33 #include "core_types.h"
34 #include "transform.h"
37 /*******************************************************************************
39 ******************************************************************************/
40 static void construct(struct dc_context *ctx, struct dc_plane_state *plane_state)
42 plane_state->ctx = ctx;
44 plane_state->gamma_correction = dc_create_gamma();
45 if (plane_state->gamma_correction != NULL)
46 plane_state->gamma_correction->is_identity = true;
48 plane_state->in_transfer_func = dc_create_transfer_func();
49 if (plane_state->in_transfer_func != NULL) {
50 plane_state->in_transfer_func->type = TF_TYPE_BYPASS;
51 plane_state->in_transfer_func->ctx = ctx;
53 #if defined(CONFIG_DRM_AMD_DC_DCN2_0)
54 plane_state->in_shaper_func = dc_create_transfer_func();
55 if (plane_state->in_shaper_func != NULL) {
56 plane_state->in_shaper_func->type = TF_TYPE_BYPASS;
57 plane_state->in_shaper_func->ctx = ctx;
60 plane_state->lut3d_func = dc_create_3dlut_func();
61 if (plane_state->lut3d_func != NULL) {
62 plane_state->lut3d_func->ctx = ctx;
64 plane_state->blend_tf = dc_create_transfer_func();
65 if (plane_state->blend_tf != NULL) {
66 plane_state->blend_tf->type = TF_TYPE_BYPASS;
67 plane_state->blend_tf->ctx = ctx;
73 static void destruct(struct dc_plane_state *plane_state)
75 if (plane_state->gamma_correction != NULL) {
76 dc_gamma_release(&plane_state->gamma_correction);
78 if (plane_state->in_transfer_func != NULL) {
79 dc_transfer_func_release(
80 plane_state->in_transfer_func);
81 plane_state->in_transfer_func = NULL;
83 #if defined(CONFIG_DRM_AMD_DC_DCN2_0)
84 if (plane_state->in_shaper_func != NULL) {
85 dc_transfer_func_release(
86 plane_state->in_shaper_func);
87 plane_state->in_shaper_func = NULL;
89 if (plane_state->lut3d_func != NULL) {
90 dc_3dlut_func_release(
91 plane_state->lut3d_func);
92 plane_state->lut3d_func = NULL;
94 if (plane_state->blend_tf != NULL) {
95 dc_transfer_func_release(
96 plane_state->blend_tf);
97 plane_state->blend_tf = NULL;
103 /*******************************************************************************
105 ******************************************************************************/
106 void enable_surface_flip_reporting(struct dc_plane_state *plane_state,
107 uint32_t controller_id)
109 plane_state->irq_source = controller_id + DC_IRQ_SOURCE_PFLIP1 - 1;
110 /*register_flip_interrupt(surface);*/
113 struct dc_plane_state *dc_create_plane_state(struct dc *dc)
115 struct dc *core_dc = dc;
117 struct dc_plane_state *plane_state = kvzalloc(sizeof(*plane_state),
120 if (NULL == plane_state)
123 kref_init(&plane_state->refcount);
124 construct(core_dc->ctx, plane_state);
130 *****************************************************************************
131 * Function: dc_plane_get_status
134 * Looks up the pipe context of plane_state and updates the pending status
135 * of the pipe context. Then returns plane_state->status
137 * @param [in] plane_state: pointer to the plane_state to get the status of
138 *****************************************************************************
140 const struct dc_plane_status *dc_plane_get_status(
141 const struct dc_plane_state *plane_state)
143 const struct dc_plane_status *plane_status;
149 !plane_state->ctx->dc) {
151 return NULL; /* remove this if above assert never hit */
154 plane_status = &plane_state->status;
155 core_dc = plane_state->ctx->dc;
157 if (core_dc->current_state == NULL)
160 /* Find the current plane state and set its pending bit to false */
161 for (i = 0; i < core_dc->res_pool->pipe_count; i++) {
162 struct pipe_ctx *pipe_ctx =
163 &core_dc->current_state->res_ctx.pipe_ctx[i];
165 if (pipe_ctx->plane_state != plane_state)
168 pipe_ctx->plane_state->status.is_flip_pending = false;
173 for (i = 0; i < core_dc->res_pool->pipe_count; i++) {
174 struct pipe_ctx *pipe_ctx =
175 &core_dc->current_state->res_ctx.pipe_ctx[i];
177 if (pipe_ctx->plane_state != plane_state)
180 core_dc->hwss.update_pending_status(pipe_ctx);
186 void dc_plane_state_retain(struct dc_plane_state *plane_state)
188 kref_get(&plane_state->refcount);
191 static void dc_plane_state_free(struct kref *kref)
193 struct dc_plane_state *plane_state = container_of(kref, struct dc_plane_state, refcount);
194 destruct(plane_state);
198 void dc_plane_state_release(struct dc_plane_state *plane_state)
200 kref_put(&plane_state->refcount, dc_plane_state_free);
203 void dc_gamma_retain(struct dc_gamma *gamma)
205 kref_get(&gamma->refcount);
208 static void dc_gamma_free(struct kref *kref)
210 struct dc_gamma *gamma = container_of(kref, struct dc_gamma, refcount);
214 void dc_gamma_release(struct dc_gamma **gamma)
216 kref_put(&(*gamma)->refcount, dc_gamma_free);
220 struct dc_gamma *dc_create_gamma(void)
222 struct dc_gamma *gamma = kvzalloc(sizeof(*gamma), GFP_KERNEL);
227 kref_init(&gamma->refcount);
234 void dc_transfer_func_retain(struct dc_transfer_func *tf)
236 kref_get(&tf->refcount);
239 static void dc_transfer_func_free(struct kref *kref)
241 struct dc_transfer_func *tf = container_of(kref, struct dc_transfer_func, refcount);
245 void dc_transfer_func_release(struct dc_transfer_func *tf)
247 kref_put(&tf->refcount, dc_transfer_func_free);
250 struct dc_transfer_func *dc_create_transfer_func(void)
252 struct dc_transfer_func *tf = kvzalloc(sizeof(*tf), GFP_KERNEL);
257 kref_init(&tf->refcount);
265 #if defined(CONFIG_DRM_AMD_DC_DCN2_0)
266 static void dc_3dlut_func_free(struct kref *kref)
268 struct dc_3dlut *lut = container_of(kref, struct dc_3dlut, refcount);
273 struct dc_3dlut *dc_create_3dlut_func(void)
275 struct dc_3dlut *lut = kvzalloc(sizeof(*lut), GFP_KERNEL);
280 kref_init(&lut->refcount);
290 void dc_3dlut_func_release(struct dc_3dlut *lut)
292 kref_put(&lut->refcount, dc_3dlut_func_free);
295 void dc_3dlut_func_retain(struct dc_3dlut *lut)
297 kref_get(&lut->refcount);