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 | ******************************************************************************/ |
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 = dc_create_gamma(); |
45 | if (plane_state->gamma_correction != NULL) |
46 | plane_state->gamma_correction->is_identity = true; |
47 | |
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 | } |
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; |
55 | } |
56 | |
57 | plane_state->lut3d_func = dc_create_3dlut_func(); |
58 | |
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; |
62 | } |
63 | |
64 | plane_state->pre_multiplied_alpha = true; |
65 | |
66 | } |
67 | |
68 | void dc_plane_destruct(struct dc_plane_state *plane_state) |
69 | { |
70 | if (plane_state->gamma_correction != NULL) { |
71 | dc_gamma_release(dc_gamma: &plane_state->gamma_correction); |
72 | } |
73 | if (plane_state->in_transfer_func != NULL) { |
74 | dc_transfer_func_release( |
75 | dc_tf: plane_state->in_transfer_func); |
76 | plane_state->in_transfer_func = NULL; |
77 | } |
78 | if (plane_state->in_shaper_func != NULL) { |
79 | dc_transfer_func_release( |
80 | dc_tf: plane_state->in_shaper_func); |
81 | plane_state->in_shaper_func = NULL; |
82 | } |
83 | if (plane_state->lut3d_func != NULL) { |
84 | dc_3dlut_func_release( |
85 | lut: plane_state->lut3d_func); |
86 | plane_state->lut3d_func = NULL; |
87 | } |
88 | if (plane_state->blend_tf != NULL) { |
89 | dc_transfer_func_release( |
90 | dc_tf: plane_state->blend_tf); |
91 | plane_state->blend_tf = NULL; |
92 | } |
93 | |
94 | } |
95 | |
96 | /******************************************************************************* |
97 | * Public functions |
98 | ******************************************************************************/ |
99 | void enable_surface_flip_reporting(struct dc_plane_state *plane_state, |
100 | uint32_t controller_id) |
101 | { |
102 | plane_state->irq_source = controller_id + DC_IRQ_SOURCE_PFLIP1 - 1; |
103 | /*register_flip_interrupt(surface);*/ |
104 | } |
105 | |
106 | struct dc_plane_state *dc_create_plane_state(struct dc *dc) |
107 | { |
108 | struct dc_plane_state *plane_state = kvzalloc(size: sizeof(*plane_state), |
109 | GFP_KERNEL); |
110 | |
111 | if (NULL == plane_state) |
112 | return NULL; |
113 | |
114 | kref_init(kref: &plane_state->refcount); |
115 | dc_plane_construct(ctx: dc->ctx, plane_state); |
116 | |
117 | return plane_state; |
118 | } |
119 | |
120 | /* |
121 | ***************************************************************************** |
122 | * Function: dc_plane_get_status |
123 | * |
124 | * @brief |
125 | * Looks up the pipe context of plane_state and updates the pending status |
126 | * of the pipe context. Then returns plane_state->status |
127 | * |
128 | * @param [in] plane_state: pointer to the plane_state to get the status of |
129 | ***************************************************************************** |
130 | */ |
131 | const struct dc_plane_status *dc_plane_get_status( |
132 | const struct dc_plane_state *plane_state) |
133 | { |
134 | const struct dc_plane_status *plane_status; |
135 | struct dc *dc; |
136 | int i; |
137 | |
138 | if (!plane_state || |
139 | !plane_state->ctx || |
140 | !plane_state->ctx->dc) { |
141 | ASSERT(0); |
142 | return NULL; /* remove this if above assert never hit */ |
143 | } |
144 | |
145 | plane_status = &plane_state->status; |
146 | dc = plane_state->ctx->dc; |
147 | |
148 | if (dc->current_state == NULL) |
149 | return NULL; |
150 | |
151 | /* Find the current plane state and set its pending bit to false */ |
152 | for (i = 0; i < dc->res_pool->pipe_count; i++) { |
153 | struct pipe_ctx *pipe_ctx = |
154 | &dc->current_state->res_ctx.pipe_ctx[i]; |
155 | |
156 | if (pipe_ctx->plane_state != plane_state) |
157 | continue; |
158 | |
159 | pipe_ctx->plane_state->status.is_flip_pending = false; |
160 | |
161 | break; |
162 | } |
163 | |
164 | dc_exit_ips_for_hw_access(dc); |
165 | |
166 | for (i = 0; i < dc->res_pool->pipe_count; i++) { |
167 | struct pipe_ctx *pipe_ctx = |
168 | &dc->current_state->res_ctx.pipe_ctx[i]; |
169 | |
170 | if (pipe_ctx->plane_state != plane_state) |
171 | continue; |
172 | |
173 | dc->hwss.update_pending_status(pipe_ctx); |
174 | } |
175 | |
176 | return plane_status; |
177 | } |
178 | |
179 | void dc_plane_state_retain(struct dc_plane_state *plane_state) |
180 | { |
181 | kref_get(kref: &plane_state->refcount); |
182 | } |
183 | |
184 | static void dc_plane_state_free(struct kref *kref) |
185 | { |
186 | struct dc_plane_state *plane_state = container_of(kref, struct dc_plane_state, refcount); |
187 | dc_plane_destruct(plane_state); |
188 | kvfree(addr: plane_state); |
189 | } |
190 | |
191 | void dc_plane_state_release(struct dc_plane_state *plane_state) |
192 | { |
193 | kref_put(kref: &plane_state->refcount, release: dc_plane_state_free); |
194 | } |
195 | |
196 | void dc_gamma_retain(struct dc_gamma *gamma) |
197 | { |
198 | kref_get(kref: &gamma->refcount); |
199 | } |
200 | |
201 | static void dc_gamma_free(struct kref *kref) |
202 | { |
203 | struct dc_gamma *gamma = container_of(kref, struct dc_gamma, refcount); |
204 | kvfree(addr: gamma); |
205 | } |
206 | |
207 | void dc_gamma_release(struct dc_gamma **gamma) |
208 | { |
209 | kref_put(kref: &(*gamma)->refcount, release: dc_gamma_free); |
210 | *gamma = NULL; |
211 | } |
212 | |
213 | struct dc_gamma *dc_create_gamma(void) |
214 | { |
215 | struct dc_gamma *gamma = kvzalloc(size: sizeof(*gamma), GFP_KERNEL); |
216 | |
217 | if (gamma == NULL) |
218 | goto alloc_fail; |
219 | |
220 | kref_init(kref: &gamma->refcount); |
221 | return gamma; |
222 | |
223 | alloc_fail: |
224 | return NULL; |
225 | } |
226 | |
227 | void dc_transfer_func_retain(struct dc_transfer_func *tf) |
228 | { |
229 | kref_get(kref: &tf->refcount); |
230 | } |
231 | |
232 | static void dc_transfer_func_free(struct kref *kref) |
233 | { |
234 | struct dc_transfer_func *tf = container_of(kref, struct dc_transfer_func, refcount); |
235 | kvfree(addr: tf); |
236 | } |
237 | |
238 | void dc_transfer_func_release(struct dc_transfer_func *tf) |
239 | { |
240 | kref_put(kref: &tf->refcount, release: dc_transfer_func_free); |
241 | } |
242 | |
243 | struct dc_transfer_func *dc_create_transfer_func(void) |
244 | { |
245 | struct dc_transfer_func *tf = kvzalloc(size: sizeof(*tf), GFP_KERNEL); |
246 | |
247 | if (tf == NULL) |
248 | goto alloc_fail; |
249 | |
250 | kref_init(kref: &tf->refcount); |
251 | |
252 | return tf; |
253 | |
254 | alloc_fail: |
255 | return NULL; |
256 | } |
257 | |
258 | static void dc_3dlut_func_free(struct kref *kref) |
259 | { |
260 | struct dc_3dlut *lut = container_of(kref, struct dc_3dlut, refcount); |
261 | |
262 | kvfree(addr: lut); |
263 | } |
264 | |
265 | struct dc_3dlut *dc_create_3dlut_func(void) |
266 | { |
267 | struct dc_3dlut *lut = kvzalloc(size: sizeof(*lut), GFP_KERNEL); |
268 | |
269 | if (lut == NULL) |
270 | goto alloc_fail; |
271 | |
272 | kref_init(kref: &lut->refcount); |
273 | lut->state.raw = 0; |
274 | |
275 | return lut; |
276 | |
277 | alloc_fail: |
278 | return NULL; |
279 | |
280 | } |
281 | |
282 | void dc_3dlut_func_release(struct dc_3dlut *lut) |
283 | { |
284 | kref_put(kref: &lut->refcount, release: dc_3dlut_func_free); |
285 | } |
286 | |
287 | void dc_3dlut_func_retain(struct dc_3dlut *lut) |
288 | { |
289 | kref_get(kref: &lut->refcount); |
290 | } |
291 | |
292 | |
293 | |