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 #include "dc_plane_priv.h"
36
37 /*******************************************************************************
38 * Private functions
39 ******************************************************************************/
dc_plane_construct(struct dc_context * ctx,struct dc_plane_state * plane_state)40 void dc_plane_construct(struct dc_context *ctx, struct dc_plane_state *plane_state)
41 {
42 plane_state->ctx = ctx;
43
44 plane_state->gamma_correction.is_identity = true;
45
46 plane_state->in_transfer_func.type = TF_TYPE_BYPASS;
47
48 plane_state->in_shaper_func.type = TF_TYPE_BYPASS;
49
50 plane_state->lut3d_func.state.raw = 0;
51
52 plane_state->blend_tf.type = TF_TYPE_BYPASS;
53
54 plane_state->pre_multiplied_alpha = true;
55
56 }
57
dc_plane_destruct(struct dc_plane_state * plane_state)58 void dc_plane_destruct(struct dc_plane_state *plane_state)
59 {
60 // no more pointers to free within dc_plane_state
61 }
62
63
64 /* dc_state is passed in separately since it may differ from the current dc state accessible from plane_state e.g.
65 * if the driver is doing an update from an old context to a new one and the caller wants the pipe mask for the new
66 * context rather than the existing one
67 */
dc_plane_get_pipe_mask(struct dc_state * dc_state,const struct dc_plane_state * plane_state)68 uint8_t dc_plane_get_pipe_mask(struct dc_state *dc_state, const struct dc_plane_state *plane_state)
69 {
70 uint8_t pipe_mask = 0;
71 int i;
72
73 for (i = 0; i < plane_state->ctx->dc->res_pool->pipe_count; i++) {
74 struct pipe_ctx *pipe_ctx = &dc_state->res_ctx.pipe_ctx[i];
75
76 if (pipe_ctx->plane_state == plane_state && pipe_ctx->plane_res.hubp)
77 pipe_mask |= 1 << pipe_ctx->plane_res.hubp->inst;
78 }
79
80 return pipe_mask;
81 }
82
83 /*******************************************************************************
84 * Public functions
85 ******************************************************************************/
dc_create_plane_state(const struct dc * dc)86 struct dc_plane_state *dc_create_plane_state(const struct dc *dc)
87 {
88 struct dc_plane_state *plane_state = kvzalloc(sizeof(*plane_state),
89 GFP_KERNEL);
90
91 if (NULL == plane_state)
92 return NULL;
93
94 kref_init(&plane_state->refcount);
95 dc_plane_construct(dc->ctx, plane_state);
96
97 return plane_state;
98 }
99
100 /*
101 *****************************************************************************
102 * Function: dc_plane_get_status
103 *
104 * @brief
105 * Looks up the pipe context of plane_state and updates the pending status
106 * of the pipe context. Then returns plane_state->status
107 *
108 * @param [in] plane_state: pointer to the plane_state to get the status of
109 *****************************************************************************
110 */
dc_plane_get_status(const struct dc_plane_state * plane_state)111 const struct dc_plane_status *dc_plane_get_status(
112 const struct dc_plane_state *plane_state)
113 {
114 const struct dc_plane_status *plane_status;
115 struct dc *dc;
116 int i;
117
118 if (!plane_state ||
119 !plane_state->ctx ||
120 !plane_state->ctx->dc) {
121 ASSERT(0);
122 return NULL; /* remove this if above assert never hit */
123 }
124
125 plane_status = &plane_state->status;
126 dc = plane_state->ctx->dc;
127
128 if (dc->current_state == NULL)
129 return NULL;
130
131 /* Find the current plane state and set its pending bit to false */
132 for (i = 0; i < dc->res_pool->pipe_count; i++) {
133 struct pipe_ctx *pipe_ctx =
134 &dc->current_state->res_ctx.pipe_ctx[i];
135
136 if (pipe_ctx->plane_state != plane_state)
137 continue;
138
139 if (pipe_ctx->plane_state)
140 pipe_ctx->plane_state->status.is_flip_pending = false;
141
142 break;
143 }
144
145 dc_exit_ips_for_hw_access(dc);
146
147 for (i = 0; i < dc->res_pool->pipe_count; i++) {
148 struct pipe_ctx *pipe_ctx =
149 &dc->current_state->res_ctx.pipe_ctx[i];
150
151 if (pipe_ctx->plane_state != plane_state)
152 continue;
153
154 dc->hwss.update_pending_status(pipe_ctx);
155 }
156
157 return plane_status;
158 }
159
dc_plane_state_retain(struct dc_plane_state * plane_state)160 void dc_plane_state_retain(struct dc_plane_state *plane_state)
161 {
162 kref_get(&plane_state->refcount);
163 }
164
dc_plane_state_free(struct kref * kref)165 static void dc_plane_state_free(struct kref *kref)
166 {
167 struct dc_plane_state *plane_state = container_of(kref, struct dc_plane_state, refcount);
168 dc_plane_destruct(plane_state);
169 kvfree(plane_state);
170 }
171
dc_plane_state_release(struct dc_plane_state * plane_state)172 void dc_plane_state_release(struct dc_plane_state *plane_state)
173 {
174 kref_put(&plane_state->refcount, dc_plane_state_free);
175 }
176
dc_gamma_retain(struct dc_gamma * gamma)177 void dc_gamma_retain(struct dc_gamma *gamma)
178 {
179 kref_get(&gamma->refcount);
180 }
181
dc_gamma_free(struct kref * kref)182 static void dc_gamma_free(struct kref *kref)
183 {
184 struct dc_gamma *gamma = container_of(kref, struct dc_gamma, refcount);
185 kvfree(gamma);
186 }
187
dc_gamma_release(struct dc_gamma ** gamma)188 void dc_gamma_release(struct dc_gamma **gamma)
189 {
190 kref_put(&(*gamma)->refcount, dc_gamma_free);
191 *gamma = NULL;
192 }
193
dc_create_gamma(void)194 struct dc_gamma *dc_create_gamma(void)
195 {
196 struct dc_gamma *gamma = kvzalloc(sizeof(*gamma), GFP_KERNEL);
197
198 if (gamma == NULL)
199 goto alloc_fail;
200
201 kref_init(&gamma->refcount);
202 return gamma;
203
204 alloc_fail:
205 return NULL;
206 }
207
dc_transfer_func_retain(struct dc_transfer_func * tf)208 void dc_transfer_func_retain(struct dc_transfer_func *tf)
209 {
210 kref_get(&tf->refcount);
211 }
212
dc_transfer_func_free(struct kref * kref)213 static void dc_transfer_func_free(struct kref *kref)
214 {
215 struct dc_transfer_func *tf = container_of(kref, struct dc_transfer_func, refcount);
216 kvfree(tf);
217 }
218
dc_transfer_func_release(struct dc_transfer_func * tf)219 void dc_transfer_func_release(struct dc_transfer_func *tf)
220 {
221 kref_put(&tf->refcount, dc_transfer_func_free);
222 }
223
dc_create_transfer_func(void)224 struct dc_transfer_func *dc_create_transfer_func(void)
225 {
226 struct dc_transfer_func *tf = kvzalloc(sizeof(*tf), GFP_KERNEL);
227
228 if (tf == NULL)
229 goto alloc_fail;
230
231 kref_init(&tf->refcount);
232
233 return tf;
234
235 alloc_fail:
236 return NULL;
237 }
238
dc_3dlut_func_free(struct kref * kref)239 static void dc_3dlut_func_free(struct kref *kref)
240 {
241 struct dc_3dlut *lut = container_of(kref, struct dc_3dlut, refcount);
242
243 kvfree(lut);
244 }
245
dc_create_3dlut_func(void)246 struct dc_3dlut *dc_create_3dlut_func(void)
247 {
248 struct dc_3dlut *lut = kvzalloc(sizeof(*lut), GFP_KERNEL);
249
250 if (lut == NULL)
251 goto alloc_fail;
252
253 kref_init(&lut->refcount);
254 lut->state.raw = 0;
255
256 return lut;
257
258 alloc_fail:
259 return NULL;
260
261 }
262
dc_3dlut_func_release(struct dc_3dlut * lut)263 void dc_3dlut_func_release(struct dc_3dlut *lut)
264 {
265 kref_put(&lut->refcount, dc_3dlut_func_free);
266 }
267
dc_3dlut_func_retain(struct dc_3dlut * lut)268 void dc_3dlut_func_retain(struct dc_3dlut *lut)
269 {
270 kref_get(&lut->refcount);
271 }
272
dc_plane_force_update_for_panic(struct dc_plane_state * plane_state,bool clear_tiling)273 void dc_plane_force_update_for_panic(struct dc_plane_state *plane_state,
274 bool clear_tiling)
275 {
276 struct dc *dc;
277 int i;
278
279 if (!plane_state)
280 return;
281
282 dc = plane_state->ctx->dc;
283
284 if (!dc || !dc->current_state)
285 return;
286
287 for (i = 0; i < dc->res_pool->pipe_count; i++) {
288 struct pipe_ctx *pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
289
290 if (!pipe_ctx)
291 continue;
292
293 if (dc->ctx->dce_version >= DCE_VERSION_MAX) {
294 struct hubp *hubp = pipe_ctx->plane_res.hubp;
295 if (!hubp)
296 continue;
297 /* if framebuffer is tiled, disable tiling */
298 if (clear_tiling && hubp->funcs->hubp_clear_tiling)
299 hubp->funcs->hubp_clear_tiling(hubp);
300
301 /* force page flip to see the new content of the framebuffer */
302 hubp->funcs->hubp_program_surface_flip_and_addr(hubp,
303 &plane_state->address,
304 true);
305 } else {
306 struct mem_input *mi = pipe_ctx->plane_res.mi;
307 if (!mi)
308 continue;
309 /* if framebuffer is tiled, disable tiling */
310 if (clear_tiling && mi->funcs->mem_input_clear_tiling)
311 mi->funcs->mem_input_clear_tiling(mi);
312
313 /* force page flip to see the new content of the framebuffer */
314 mi->funcs->mem_input_program_surface_flip_and_addr(mi,
315 &plane_state->address,
316 true);
317 }
318 }
319 }
320