1 /*
2 * Copyright 2015 Advanced Micro Devices, Inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
22 * Authors: AMD
23 *
24 */
25
26 /* DC interface (public) */
27 #include "dm_services.h"
28 #include "dc.h"
29
30 /* DC core (private) */
31 #include "core_types.h"
32 #include "transform.h"
33 #include "dpp.h"
34
35 /*******************************************************************************
36 * Private functions
37 ******************************************************************************/
dc_plane_construct(struct dc_context * ctx,struct dc_plane_state * plane_state)38 static void dc_plane_construct(struct dc_context *ctx, struct dc_plane_state *plane_state)
39 {
40 plane_state->ctx = ctx;
41
42 plane_state->gamma_correction = dc_create_gamma();
43 if (plane_state->gamma_correction != NULL)
44 plane_state->gamma_correction->is_identity = true;
45
46 plane_state->in_transfer_func = dc_create_transfer_func();
47 if (plane_state->in_transfer_func != NULL) {
48 plane_state->in_transfer_func->type = TF_TYPE_BYPASS;
49 }
50 plane_state->in_shaper_func = dc_create_transfer_func();
51 if (plane_state->in_shaper_func != NULL) {
52 plane_state->in_shaper_func->type = TF_TYPE_BYPASS;
53 }
54
55 plane_state->lut3d_func = dc_create_3dlut_func();
56
57 plane_state->blend_tf = dc_create_transfer_func();
58 if (plane_state->blend_tf != NULL) {
59 plane_state->blend_tf->type = TF_TYPE_BYPASS;
60 }
61
62 plane_state->pre_multiplied_alpha = true;
63
64 }
65
dc_plane_destruct(struct dc_plane_state * plane_state)66 static void dc_plane_destruct(struct dc_plane_state *plane_state)
67 {
68 if (plane_state->gamma_correction != NULL) {
69 dc_gamma_release(&plane_state->gamma_correction);
70 }
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;
75 }
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;
80 }
81 if (plane_state->lut3d_func != NULL) {
82 dc_3dlut_func_release(
83 plane_state->lut3d_func);
84 plane_state->lut3d_func = NULL;
85 }
86 if (plane_state->blend_tf != NULL) {
87 dc_transfer_func_release(
88 plane_state->blend_tf);
89 plane_state->blend_tf = NULL;
90 }
91
92 }
93
94 /*******************************************************************************
95 * Public functions
96 ******************************************************************************/
enable_surface_flip_reporting(struct dc_plane_state * plane_state,uint32_t controller_id)97 void enable_surface_flip_reporting(struct dc_plane_state *plane_state,
98 uint32_t controller_id)
99 {
100 plane_state->irq_source = controller_id + DC_IRQ_SOURCE_PFLIP1 - 1;
101 /*register_flip_interrupt(surface);*/
102 }
103
dc_create_plane_state(struct dc * dc)104 struct dc_plane_state *dc_create_plane_state(struct dc *dc)
105 {
106 struct dc_plane_state *plane_state = kvzalloc(sizeof(*plane_state),
107 GFP_KERNEL);
108
109 if (NULL == plane_state)
110 return NULL;
111
112 kref_init(&plane_state->refcount);
113 dc_plane_construct(dc->ctx, plane_state);
114
115 return plane_state;
116 }
117
118 /*
119 *****************************************************************************
120 * Function: dc_plane_get_status
121 *
122 * @brief
123 * Looks up the pipe context of plane_state and updates the pending status
124 * of the pipe context. Then returns plane_state->status
125 *
126 * @param [in] plane_state: pointer to the plane_state to get the status of
127 *****************************************************************************
128 */
dc_plane_get_status(const struct dc_plane_state * plane_state)129 const struct dc_plane_status *dc_plane_get_status(
130 const struct dc_plane_state *plane_state)
131 {
132 const struct dc_plane_status *plane_status;
133 struct dc *dc;
134 int i;
135
136 if (!plane_state ||
137 !plane_state->ctx ||
138 !plane_state->ctx->dc) {
139 ASSERT(0);
140 return NULL; /* remove this if above assert never hit */
141 }
142
143 plane_status = &plane_state->status;
144 dc = plane_state->ctx->dc;
145
146 if (dc->current_state == NULL)
147 return NULL;
148
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];
153
154 if (pipe_ctx->plane_state != plane_state)
155 continue;
156
157 if (pipe_ctx->plane_state)
158 pipe_ctx->plane_state->status.is_flip_pending = false;
159
160 break;
161 }
162
163 for (i = 0; i < dc->res_pool->pipe_count; i++) {
164 struct pipe_ctx *pipe_ctx =
165 &dc->current_state->res_ctx.pipe_ctx[i];
166
167 if (pipe_ctx->plane_state != plane_state)
168 continue;
169
170 dc->hwss.update_pending_status(pipe_ctx);
171 }
172
173 return plane_status;
174 }
175
dc_plane_state_retain(struct dc_plane_state * plane_state)176 void dc_plane_state_retain(struct dc_plane_state *plane_state)
177 {
178 kref_get(&plane_state->refcount);
179 }
180
dc_plane_state_free(struct kref * kref)181 static void dc_plane_state_free(struct kref *kref)
182 {
183 struct dc_plane_state *plane_state = container_of(kref, struct dc_plane_state, refcount);
184 dc_plane_destruct(plane_state);
185 kvfree(plane_state);
186 }
187
dc_plane_state_release(struct dc_plane_state * plane_state)188 void dc_plane_state_release(struct dc_plane_state *plane_state)
189 {
190 kref_put(&plane_state->refcount, dc_plane_state_free);
191 }
192
dc_gamma_retain(struct dc_gamma * gamma)193 void dc_gamma_retain(struct dc_gamma *gamma)
194 {
195 kref_get(&gamma->refcount);
196 }
197
dc_gamma_free(struct kref * kref)198 static void dc_gamma_free(struct kref *kref)
199 {
200 struct dc_gamma *gamma = container_of(kref, struct dc_gamma, refcount);
201 kvfree(gamma);
202 }
203
dc_gamma_release(struct dc_gamma ** gamma)204 void dc_gamma_release(struct dc_gamma **gamma)
205 {
206 kref_put(&(*gamma)->refcount, dc_gamma_free);
207 *gamma = NULL;
208 }
209
dc_create_gamma(void)210 struct dc_gamma *dc_create_gamma(void)
211 {
212 struct dc_gamma *gamma = kvzalloc(sizeof(*gamma), GFP_KERNEL);
213
214 if (gamma == NULL)
215 goto alloc_fail;
216
217 kref_init(&gamma->refcount);
218 return gamma;
219
220 alloc_fail:
221 return NULL;
222 }
223
dc_transfer_func_retain(struct dc_transfer_func * tf)224 void dc_transfer_func_retain(struct dc_transfer_func *tf)
225 {
226 kref_get(&tf->refcount);
227 }
228
dc_transfer_func_free(struct kref * kref)229 static void dc_transfer_func_free(struct kref *kref)
230 {
231 struct dc_transfer_func *tf = container_of(kref, struct dc_transfer_func, refcount);
232 kvfree(tf);
233 }
234
dc_transfer_func_release(struct dc_transfer_func * tf)235 void dc_transfer_func_release(struct dc_transfer_func *tf)
236 {
237 kref_put(&tf->refcount, dc_transfer_func_free);
238 }
239
dc_create_transfer_func(void)240 struct dc_transfer_func *dc_create_transfer_func(void)
241 {
242 struct dc_transfer_func *tf = kvzalloc(sizeof(*tf), GFP_KERNEL);
243
244 if (tf == NULL)
245 goto alloc_fail;
246
247 kref_init(&tf->refcount);
248
249 return tf;
250
251 alloc_fail:
252 return NULL;
253 }
254
dc_3dlut_func_free(struct kref * kref)255 static void dc_3dlut_func_free(struct kref *kref)
256 {
257 struct dc_3dlut *lut = container_of(kref, struct dc_3dlut, refcount);
258
259 kvfree(lut);
260 }
261
dc_create_3dlut_func(void)262 struct dc_3dlut *dc_create_3dlut_func(void)
263 {
264 struct dc_3dlut *lut = kvzalloc(sizeof(*lut), GFP_KERNEL);
265
266 if (lut == NULL)
267 goto alloc_fail;
268
269 kref_init(&lut->refcount);
270 lut->state.raw = 0;
271
272 return lut;
273
274 alloc_fail:
275 return NULL;
276
277 }
278
dc_3dlut_func_release(struct dc_3dlut * lut)279 void dc_3dlut_func_release(struct dc_3dlut *lut)
280 {
281 kref_put(&lut->refcount, dc_3dlut_func_free);
282 }
283
dc_3dlut_func_retain(struct dc_3dlut * lut)284 void dc_3dlut_func_retain(struct dc_3dlut *lut)
285 {
286 kref_get(&lut->refcount);
287 }
288
289
290