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 dc_plane_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;
52 plane_state->in_shaper_func = dc_create_transfer_func();
53 if (plane_state->in_shaper_func != NULL) {
54 plane_state->in_shaper_func->type = TF_TYPE_BYPASS;
57 plane_state->lut3d_func = dc_create_3dlut_func();
59 plane_state->blend_tf = dc_create_transfer_func();
60 if (plane_state->blend_tf != NULL) {
61 plane_state->blend_tf->type = TF_TYPE_BYPASS;
66 static void dc_plane_destruct(struct dc_plane_state *plane_state)
68 if (plane_state->gamma_correction != NULL) {
69 dc_gamma_release(&plane_state->gamma_correction);
71 if (plane_state->in_transfer_func != NULL) {
72 dc_transfer_func_release(
73 plane_state->in_transfer_func);
74 plane_state->in_transfer_func = NULL;
76 if (plane_state->in_shaper_func != NULL) {
77 dc_transfer_func_release(
78 plane_state->in_shaper_func);
79 plane_state->in_shaper_func = NULL;
81 if (plane_state->lut3d_func != NULL) {
82 dc_3dlut_func_release(
83 plane_state->lut3d_func);
84 plane_state->lut3d_func = NULL;
86 if (plane_state->blend_tf != NULL) {
87 dc_transfer_func_release(
88 plane_state->blend_tf);
89 plane_state->blend_tf = NULL;
94 /*******************************************************************************
96 ******************************************************************************/
97 void enable_surface_flip_reporting(struct dc_plane_state *plane_state,
98 uint32_t controller_id)
100 plane_state->irq_source = controller_id + DC_IRQ_SOURCE_PFLIP1 - 1;
101 /*register_flip_interrupt(surface);*/
104 struct dc_plane_state *dc_create_plane_state(struct dc *dc)
106 struct dc_plane_state *plane_state = kvzalloc(sizeof(*plane_state),
109 if (NULL == plane_state)
112 kref_init(&plane_state->refcount);
113 dc_plane_construct(dc->ctx, plane_state);
119 *****************************************************************************
120 * Function: dc_plane_get_status
123 * Looks up the pipe context of plane_state and updates the pending status
124 * of the pipe context. Then returns plane_state->status
126 * @param [in] plane_state: pointer to the plane_state to get the status of
127 *****************************************************************************
129 const struct dc_plane_status *dc_plane_get_status(
130 const struct dc_plane_state *plane_state)
132 const struct dc_plane_status *plane_status;
138 !plane_state->ctx->dc) {
140 return NULL; /* remove this if above assert never hit */
143 plane_status = &plane_state->status;
144 dc = plane_state->ctx->dc;
146 if (dc->current_state == NULL)
149 /* Find the current plane state and set its pending bit to false */
150 for (i = 0; i < dc->res_pool->pipe_count; i++) {
151 struct pipe_ctx *pipe_ctx =
152 &dc->current_state->res_ctx.pipe_ctx[i];
154 if (pipe_ctx->plane_state != plane_state)
157 pipe_ctx->plane_state->status.is_flip_pending = false;
162 for (i = 0; i < dc->res_pool->pipe_count; i++) {
163 struct pipe_ctx *pipe_ctx =
164 &dc->current_state->res_ctx.pipe_ctx[i];
166 if (pipe_ctx->plane_state != plane_state)
169 dc->hwss.update_pending_status(pipe_ctx);
175 void dc_plane_state_retain(struct dc_plane_state *plane_state)
177 kref_get(&plane_state->refcount);
180 static void dc_plane_state_free(struct kref *kref)
182 struct dc_plane_state *plane_state = container_of(kref, struct dc_plane_state, refcount);
183 dc_plane_destruct(plane_state);
187 void dc_plane_state_release(struct dc_plane_state *plane_state)
189 kref_put(&plane_state->refcount, dc_plane_state_free);
192 void dc_gamma_retain(struct dc_gamma *gamma)
194 kref_get(&gamma->refcount);
197 static void dc_gamma_free(struct kref *kref)
199 struct dc_gamma *gamma = container_of(kref, struct dc_gamma, refcount);
203 void dc_gamma_release(struct dc_gamma **gamma)
205 kref_put(&(*gamma)->refcount, dc_gamma_free);
209 struct dc_gamma *dc_create_gamma(void)
211 struct dc_gamma *gamma = kvzalloc(sizeof(*gamma), GFP_KERNEL);
216 kref_init(&gamma->refcount);
223 void dc_transfer_func_retain(struct dc_transfer_func *tf)
225 kref_get(&tf->refcount);
228 static void dc_transfer_func_free(struct kref *kref)
230 struct dc_transfer_func *tf = container_of(kref, struct dc_transfer_func, refcount);
234 void dc_transfer_func_release(struct dc_transfer_func *tf)
236 kref_put(&tf->refcount, dc_transfer_func_free);
239 struct dc_transfer_func *dc_create_transfer_func(void)
241 struct dc_transfer_func *tf = kvzalloc(sizeof(*tf), GFP_KERNEL);
246 kref_init(&tf->refcount);
254 static void dc_3dlut_func_free(struct kref *kref)
256 struct dc_3dlut *lut = container_of(kref, struct dc_3dlut, refcount);
261 struct dc_3dlut *dc_create_3dlut_func(void)
263 struct dc_3dlut *lut = kvzalloc(sizeof(*lut), GFP_KERNEL);
268 kref_init(&lut->refcount);
278 void dc_3dlut_func_release(struct dc_3dlut *lut)
280 kref_put(&lut->refcount, dc_3dlut_func_free);
283 void dc_3dlut_func_retain(struct dc_3dlut *lut)
285 kref_get(&lut->refcount);