]>
Commit | Line | Data |
---|---|---|
b840d907 JB |
1 | /* |
2 | * Copyright © 2011 Intel Corporation | |
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 (including the next | |
12 | * paragraph) shall be included in all copies or substantial portions of the | |
13 | * Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
21 | * SOFTWARE. | |
22 | * | |
23 | * Authors: | |
24 | * Jesse Barnes <[email protected]> | |
25 | * | |
26 | * New plane/sprite handling. | |
27 | * | |
28 | * The older chips had a separate interface for programming plane related | |
29 | * registers; newer ones are much simpler and we can use the new DRM plane | |
30 | * support. | |
31 | */ | |
760285e7 | 32 | #include <drm/drmP.h> |
714244e2 | 33 | #include <drm/drm_atomic_helper.h> |
760285e7 DH |
34 | #include <drm/drm_crtc.h> |
35 | #include <drm/drm_fourcc.h> | |
1731693a | 36 | #include <drm/drm_rect.h> |
c331879c | 37 | #include <drm/drm_atomic.h> |
ea2c67bb | 38 | #include <drm/drm_plane_helper.h> |
b840d907 | 39 | #include "intel_drv.h" |
5d723d7a | 40 | #include "intel_frontbuffer.h" |
760285e7 | 41 | #include <drm/i915_drm.h> |
b840d907 JB |
42 | #include "i915_drv.h" |
43 | ||
dfd2e9ab VS |
44 | int intel_usecs_to_scanlines(const struct drm_display_mode *adjusted_mode, |
45 | int usecs) | |
8d7849db VS |
46 | { |
47 | /* paranoia */ | |
5e7234c9 | 48 | if (!adjusted_mode->crtc_htotal) |
8d7849db VS |
49 | return 1; |
50 | ||
5e7234c9 VS |
51 | return DIV_ROUND_UP(usecs * adjusted_mode->crtc_clock, |
52 | 1000 * adjusted_mode->crtc_htotal); | |
8d7849db VS |
53 | } |
54 | ||
69208c9e SV |
55 | /* FIXME: We should instead only take spinlocks once for the entire update |
56 | * instead of once per mmio. */ | |
57 | #if IS_ENABLED(CONFIG_PROVE_LOCKING) | |
58 | #define VBLANK_EVASION_TIME_US 250 | |
59 | #else | |
e1edbd44 | 60 | #define VBLANK_EVASION_TIME_US 100 |
69208c9e | 61 | #endif |
e1edbd44 | 62 | |
26ff2762 ACO |
63 | /** |
64 | * intel_pipe_update_start() - start update of a set of display registers | |
d3a8fb32 | 65 | * @new_crtc_state: the new crtc state |
26ff2762 ACO |
66 | * |
67 | * Mark the start of an update to pipe registers that should be updated | |
68 | * atomically regarding vblank. If the next vblank will happens within | |
69 | * the next 100 us, this function waits until the vblank passes. | |
70 | * | |
71 | * After a successful call to this function, interrupts will be disabled | |
72 | * until a subsequent call to intel_pipe_update_end(). That is done to | |
d3a8fb32 | 73 | * avoid random delays. |
26ff2762 | 74 | */ |
d3a8fb32 | 75 | void intel_pipe_update_start(const struct intel_crtc_state *new_crtc_state) |
8d7849db | 76 | { |
d3a8fb32 | 77 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
ec1b4ee2 | 78 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
d3a8fb32 | 79 | const struct drm_display_mode *adjusted_mode = &new_crtc_state->base.adjusted_mode; |
8d7849db VS |
80 | long timeout = msecs_to_jiffies_timeout(1); |
81 | int scanline, min, max, vblank_start; | |
210871b6 | 82 | wait_queue_head_t *wq = drm_crtc_vblank_waitqueue(&crtc->base); |
ec1b4ee2 | 83 | bool need_vlv_dsi_wa = (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
d3a8fb32 | 84 | intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI); |
8d7849db | 85 | DEFINE_WAIT(wait); |
63ec132d | 86 | u32 psr_status; |
8d7849db | 87 | |
124abe07 VS |
88 | vblank_start = adjusted_mode->crtc_vblank_start; |
89 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) | |
8d7849db VS |
90 | vblank_start = DIV_ROUND_UP(vblank_start, 2); |
91 | ||
92 | /* FIXME needs to be calibrated sensibly */ | |
e1edbd44 ML |
93 | min = vblank_start - intel_usecs_to_scanlines(adjusted_mode, |
94 | VBLANK_EVASION_TIME_US); | |
8d7849db VS |
95 | max = vblank_start - 1; |
96 | ||
97 | if (min <= 0 || max <= 0) | |
a6089879 | 98 | goto irq_disable; |
8d7849db | 99 | |
1e3feefd | 100 | if (WARN_ON(drm_crtc_vblank_get(&crtc->base))) |
a6089879 TV |
101 | goto irq_disable; |
102 | ||
103 | /* | |
104 | * Wait for psr to idle out after enabling the VBL interrupts | |
105 | * VBL interrupts will start the PSR exit and prevent a PSR | |
106 | * re-entry as well. | |
107 | */ | |
63ec132d DP |
108 | if (intel_psr_wait_for_idle(new_crtc_state, &psr_status)) |
109 | DRM_ERROR("PSR idle timed out 0x%x, atomic update may fail\n", | |
110 | psr_status); | |
a6089879 TV |
111 | |
112 | local_irq_disable(); | |
8d7849db | 113 | |
d637ce3f JB |
114 | crtc->debug.min_vbl = min; |
115 | crtc->debug.max_vbl = max; | |
116 | trace_i915_pipe_update_start(crtc); | |
25ef284a | 117 | |
8d7849db VS |
118 | for (;;) { |
119 | /* | |
120 | * prepare_to_wait() has a memory barrier, which guarantees | |
121 | * other CPUs can see the task state update by the time we | |
122 | * read the scanline. | |
123 | */ | |
210871b6 | 124 | prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE); |
8d7849db VS |
125 | |
126 | scanline = intel_get_crtc_scanline(crtc); | |
127 | if (scanline < min || scanline > max) | |
128 | break; | |
129 | ||
9ba59b79 | 130 | if (!timeout) { |
8d7849db VS |
131 | DRM_ERROR("Potential atomic update failure on pipe %c\n", |
132 | pipe_name(crtc->pipe)); | |
133 | break; | |
134 | } | |
135 | ||
136 | local_irq_enable(); | |
137 | ||
138 | timeout = schedule_timeout(timeout); | |
139 | ||
140 | local_irq_disable(); | |
141 | } | |
142 | ||
210871b6 | 143 | finish_wait(wq, &wait); |
8d7849db | 144 | |
1e3feefd | 145 | drm_crtc_vblank_put(&crtc->base); |
8d7849db | 146 | |
ec1b4ee2 VS |
147 | /* |
148 | * On VLV/CHV DSI the scanline counter would appear to | |
149 | * increment approx. 1/3 of a scanline before start of vblank. | |
150 | * The registers still get latched at start of vblank however. | |
151 | * This means we must not write any registers on the first | |
152 | * line of vblank (since not the whole line is actually in | |
153 | * vblank). And unfortunately we can't use the interrupt to | |
154 | * wait here since it will fire too soon. We could use the | |
155 | * frame start interrupt instead since it will fire after the | |
156 | * critical scanline, but that would require more changes | |
157 | * in the interrupt code. So for now we'll just do the nasty | |
158 | * thing and poll for the bad scanline to pass us by. | |
159 | * | |
160 | * FIXME figure out if BXT+ DSI suffers from this as well | |
161 | */ | |
162 | while (need_vlv_dsi_wa && scanline == vblank_start) | |
163 | scanline = intel_get_crtc_scanline(crtc); | |
164 | ||
eb120ef6 JB |
165 | crtc->debug.scanline_start = scanline; |
166 | crtc->debug.start_vbl_time = ktime_get(); | |
a2991414 | 167 | crtc->debug.start_vbl_count = intel_crtc_get_vblank_counter(crtc); |
8d7849db | 168 | |
d637ce3f | 169 | trace_i915_pipe_update_vblank_evaded(crtc); |
a6089879 TV |
170 | return; |
171 | ||
172 | irq_disable: | |
173 | local_irq_disable(); | |
8d7849db VS |
174 | } |
175 | ||
26ff2762 ACO |
176 | /** |
177 | * intel_pipe_update_end() - end update of a set of display registers | |
d3a8fb32 | 178 | * @new_crtc_state: the new crtc state |
26ff2762 ACO |
179 | * |
180 | * Mark the end of an update started with intel_pipe_update_start(). This | |
181 | * re-enables interrupts and verifies the update was actually completed | |
d3a8fb32 | 182 | * before a vblank. |
26ff2762 | 183 | */ |
d3a8fb32 | 184 | void intel_pipe_update_end(struct intel_crtc_state *new_crtc_state) |
8d7849db | 185 | { |
d3a8fb32 | 186 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
8d7849db | 187 | enum pipe pipe = crtc->pipe; |
eb120ef6 | 188 | int scanline_end = intel_get_crtc_scanline(crtc); |
a2991414 | 189 | u32 end_vbl_count = intel_crtc_get_vblank_counter(crtc); |
85a62bf9 | 190 | ktime_t end_vbl_time = ktime_get(); |
a94f2b92 | 191 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
8d7849db | 192 | |
d637ce3f | 193 | trace_i915_pipe_update_end(crtc, end_vbl_count, scanline_end); |
25ef284a | 194 | |
1f7528c4 SV |
195 | /* We're still in the vblank-evade critical section, this can't race. |
196 | * Would be slightly nice to just grab the vblank count and arm the | |
197 | * event outside of the critical section - the spinlock might spin for a | |
198 | * while ... */ | |
d3a8fb32 | 199 | if (new_crtc_state->base.event) { |
1f7528c4 SV |
200 | WARN_ON(drm_crtc_vblank_get(&crtc->base) != 0); |
201 | ||
202 | spin_lock(&crtc->base.dev->event_lock); | |
d3a8fb32 | 203 | drm_crtc_arm_vblank_event(&crtc->base, new_crtc_state->base.event); |
1f7528c4 SV |
204 | spin_unlock(&crtc->base.dev->event_lock); |
205 | ||
d3a8fb32 | 206 | new_crtc_state->base.event = NULL; |
1f7528c4 SV |
207 | } |
208 | ||
8d7849db VS |
209 | local_irq_enable(); |
210 | ||
a94f2b92 BN |
211 | if (intel_vgpu_active(dev_priv)) |
212 | return; | |
213 | ||
eb120ef6 JB |
214 | if (crtc->debug.start_vbl_count && |
215 | crtc->debug.start_vbl_count != end_vbl_count) { | |
216 | DRM_ERROR("Atomic update failure on pipe %c (start=%u end=%u) time %lld us, min %d, max %d, scanline start %d, end %d\n", | |
217 | pipe_name(pipe), crtc->debug.start_vbl_count, | |
218 | end_vbl_count, | |
219 | ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time), | |
220 | crtc->debug.min_vbl, crtc->debug.max_vbl, | |
221 | crtc->debug.scanline_start, scanline_end); | |
7b8cd336 VS |
222 | } |
223 | #ifdef CONFIG_DRM_I915_DEBUG_VBLANK_EVADE | |
224 | else if (ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time) > | |
225 | VBLANK_EVASION_TIME_US) | |
e1edbd44 ML |
226 | DRM_WARN("Atomic update on pipe (%c) took %lld us, max time under evasion is %u us\n", |
227 | pipe_name(pipe), | |
228 | ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time), | |
229 | VBLANK_EVASION_TIME_US); | |
7b8cd336 | 230 | #endif |
8d7849db VS |
231 | } |
232 | ||
3f6d5ba1 VS |
233 | int intel_plane_check_stride(const struct intel_plane_state *plane_state) |
234 | { | |
235 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); | |
236 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
237 | unsigned int rotation = plane_state->base.rotation; | |
238 | u32 stride, max_stride; | |
239 | ||
240 | /* FIXME other color planes? */ | |
241 | stride = plane_state->color_plane[0].stride; | |
242 | max_stride = plane->max_stride(plane, fb->format->format, | |
243 | fb->modifier, rotation); | |
244 | ||
245 | if (stride > max_stride) { | |
246 | DRM_DEBUG_KMS("[FB:%d] stride (%d) exceeds [PLANE:%d:%s] max stride (%d)\n", | |
247 | fb->base.id, stride, | |
248 | plane->base.base.id, plane->base.name, max_stride); | |
249 | return -EINVAL; | |
250 | } | |
251 | ||
252 | return 0; | |
253 | } | |
254 | ||
4e0b83a5 VS |
255 | int intel_plane_check_src_coordinates(struct intel_plane_state *plane_state) |
256 | { | |
257 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
258 | struct drm_rect *src = &plane_state->base.src; | |
259 | u32 src_x, src_y, src_w, src_h; | |
260 | ||
261 | /* | |
262 | * Hardware doesn't handle subpixel coordinates. | |
263 | * Adjust to (macro)pixel boundary, but be careful not to | |
264 | * increase the source viewport size, because that could | |
265 | * push the downscaling factor out of bounds. | |
266 | */ | |
267 | src_x = src->x1 >> 16; | |
268 | src_w = drm_rect_width(src) >> 16; | |
269 | src_y = src->y1 >> 16; | |
270 | src_h = drm_rect_height(src) >> 16; | |
271 | ||
272 | src->x1 = src_x << 16; | |
273 | src->x2 = (src_x + src_w) << 16; | |
274 | src->y1 = src_y << 16; | |
275 | src->y2 = (src_y + src_h) << 16; | |
276 | ||
277 | if (fb->format->is_yuv && | |
278 | fb->format->format != DRM_FORMAT_NV12 && | |
279 | (src_x & 1 || src_w & 1)) { | |
280 | DRM_DEBUG_KMS("src x/w (%u, %u) must be a multiple of 2 for YUV planes\n", | |
281 | src_x, src_w); | |
282 | return -EINVAL; | |
283 | } | |
284 | ||
285 | return 0; | |
286 | } | |
287 | ||
ddd5713d VS |
288 | unsigned int |
289 | skl_plane_max_stride(struct intel_plane *plane, | |
290 | u32 pixel_format, u64 modifier, | |
291 | unsigned int rotation) | |
292 | { | |
293 | int cpp = drm_format_plane_cpp(pixel_format, 0); | |
294 | ||
295 | /* | |
296 | * "The stride in bytes must not exceed the | |
297 | * of the size of 8K pixels and 32K bytes." | |
298 | */ | |
299 | if (drm_rotation_90_or_270(rotation)) | |
300 | return min(8192, 32768 / cpp); | |
301 | else | |
302 | return min(8192 * cpp, 32768); | |
303 | } | |
304 | ||
2a277799 | 305 | static void |
27971d61 | 306 | skl_program_scaler(struct intel_plane *plane, |
2a277799 ML |
307 | const struct intel_crtc_state *crtc_state, |
308 | const struct intel_plane_state *plane_state) | |
309 | { | |
27971d61 | 310 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
2a277799 ML |
311 | enum pipe pipe = plane->pipe; |
312 | int scaler_id = plane_state->scaler_id; | |
313 | const struct intel_scaler *scaler = | |
314 | &crtc_state->scaler_state.scalers[scaler_id]; | |
315 | int crtc_x = plane_state->base.dst.x1; | |
316 | int crtc_y = plane_state->base.dst.y1; | |
317 | uint32_t crtc_w = drm_rect_width(&plane_state->base.dst); | |
318 | uint32_t crtc_h = drm_rect_height(&plane_state->base.dst); | |
319 | u16 y_hphase, uv_rgb_hphase; | |
320 | u16 y_vphase, uv_rgb_vphase; | |
6e8adf6f VS |
321 | int hscale, vscale; |
322 | ||
323 | hscale = drm_rect_calc_hscale(&plane_state->base.src, | |
324 | &plane_state->base.dst, | |
325 | 0, INT_MAX); | |
326 | vscale = drm_rect_calc_vscale(&plane_state->base.src, | |
327 | &plane_state->base.dst, | |
328 | 0, INT_MAX); | |
2a277799 | 329 | |
2a277799 ML |
330 | /* TODO: handle sub-pixel coordinates */ |
331 | if (plane_state->base.fb->format->format == DRM_FORMAT_NV12) { | |
6e8adf6f VS |
332 | y_hphase = skl_scaler_calc_phase(1, hscale, false); |
333 | y_vphase = skl_scaler_calc_phase(1, vscale, false); | |
2a277799 ML |
334 | |
335 | /* MPEG2 chroma siting convention */ | |
6e8adf6f VS |
336 | uv_rgb_hphase = skl_scaler_calc_phase(2, hscale, true); |
337 | uv_rgb_vphase = skl_scaler_calc_phase(2, vscale, false); | |
2a277799 ML |
338 | } else { |
339 | /* not used */ | |
340 | y_hphase = 0; | |
341 | y_vphase = 0; | |
342 | ||
6e8adf6f VS |
343 | uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false); |
344 | uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false); | |
2a277799 ML |
345 | } |
346 | ||
347 | I915_WRITE_FW(SKL_PS_CTRL(pipe, scaler_id), | |
27971d61 | 348 | PS_SCALER_EN | PS_PLANE_SEL(plane->id) | scaler->mode); |
2a277799 ML |
349 | I915_WRITE_FW(SKL_PS_PWR_GATE(pipe, scaler_id), 0); |
350 | I915_WRITE_FW(SKL_PS_VPHASE(pipe, scaler_id), | |
351 | PS_Y_PHASE(y_vphase) | PS_UV_RGB_PHASE(uv_rgb_vphase)); | |
352 | I915_WRITE_FW(SKL_PS_HPHASE(pipe, scaler_id), | |
353 | PS_Y_PHASE(y_hphase) | PS_UV_RGB_PHASE(uv_rgb_hphase)); | |
354 | I915_WRITE_FW(SKL_PS_WIN_POS(pipe, scaler_id), (crtc_x << 16) | crtc_y); | |
27971d61 | 355 | I915_WRITE_FW(SKL_PS_WIN_SZ(pipe, scaler_id), (crtc_w << 16) | crtc_h); |
2a277799 ML |
356 | } |
357 | ||
9a8cc576 | 358 | void |
282dbf9b | 359 | skl_update_plane(struct intel_plane *plane, |
2fde1391 ML |
360 | const struct intel_crtc_state *crtc_state, |
361 | const struct intel_plane_state *plane_state) | |
dc2a41b4 | 362 | { |
282dbf9b | 363 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
282dbf9b VS |
364 | enum plane_id plane_id = plane->id; |
365 | enum pipe pipe = plane->pipe; | |
a0864d59 | 366 | u32 plane_ctl = plane_state->ctl; |
2fde1391 | 367 | const struct drm_intel_sprite_colorkey *key = &plane_state->ckey; |
c11ada07 | 368 | u32 surf_addr = plane_state->color_plane[0].offset; |
df79cf44 VS |
369 | u32 stride = skl_plane_stride(plane_state, 0); |
370 | u32 aux_stride = skl_plane_stride(plane_state, 1); | |
936e71e3 VS |
371 | int crtc_x = plane_state->base.dst.x1; |
372 | int crtc_y = plane_state->base.dst.y1; | |
c11ada07 VS |
373 | uint32_t x = plane_state->color_plane[0].x; |
374 | uint32_t y = plane_state->color_plane[0].y; | |
936e71e3 VS |
375 | uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16; |
376 | uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16; | |
dd584fc0 | 377 | unsigned long irqflags; |
dc2a41b4 | 378 | |
6687c906 VS |
379 | /* Sizes are 0 based */ |
380 | src_w--; | |
381 | src_h--; | |
6687c906 | 382 | |
dd584fc0 VS |
383 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
384 | ||
4036c78c | 385 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) |
dd584fc0 | 386 | I915_WRITE_FW(PLANE_COLOR_CTL(pipe, plane_id), |
4036c78c | 387 | plane_state->color_ctl); |
38f24f21 | 388 | |
78587de2 | 389 | if (key->flags) { |
dd584fc0 VS |
390 | I915_WRITE_FW(PLANE_KEYVAL(pipe, plane_id), key->min_value); |
391 | I915_WRITE_FW(PLANE_KEYMAX(pipe, plane_id), key->max_value); | |
392 | I915_WRITE_FW(PLANE_KEYMSK(pipe, plane_id), key->channel_mask); | |
78587de2 VS |
393 | } |
394 | ||
dd584fc0 VS |
395 | I915_WRITE_FW(PLANE_OFFSET(pipe, plane_id), (y << 16) | x); |
396 | I915_WRITE_FW(PLANE_STRIDE(pipe, plane_id), stride); | |
397 | I915_WRITE_FW(PLANE_SIZE(pipe, plane_id), (src_h << 16) | src_w); | |
2e2adb05 | 398 | I915_WRITE_FW(PLANE_AUX_DIST(pipe, plane_id), |
c11ada07 | 399 | (plane_state->color_plane[1].offset - surf_addr) | aux_stride); |
2e2adb05 | 400 | I915_WRITE_FW(PLANE_AUX_OFFSET(pipe, plane_id), |
c11ada07 VS |
401 | (plane_state->color_plane[1].y << 16) | |
402 | plane_state->color_plane[1].x); | |
c331879c | 403 | |
2fde1391 | 404 | if (plane_state->scaler_id >= 0) { |
27971d61 | 405 | skl_program_scaler(plane, crtc_state, plane_state); |
c331879c | 406 | |
dd584fc0 | 407 | I915_WRITE_FW(PLANE_POS(pipe, plane_id), 0); |
c331879c | 408 | } else { |
dd584fc0 | 409 | I915_WRITE_FW(PLANE_POS(pipe, plane_id), (crtc_y << 16) | crtc_x); |
c331879c CK |
410 | } |
411 | ||
dd584fc0 VS |
412 | I915_WRITE_FW(PLANE_CTL(pipe, plane_id), plane_ctl); |
413 | I915_WRITE_FW(PLANE_SURF(pipe, plane_id), | |
414 | intel_plane_ggtt_offset(plane_state) + surf_addr); | |
415 | POSTING_READ_FW(PLANE_SURF(pipe, plane_id)); | |
416 | ||
417 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); | |
dc2a41b4 DL |
418 | } |
419 | ||
779d4d8f | 420 | void |
282dbf9b | 421 | skl_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc) |
dc2a41b4 | 422 | { |
282dbf9b VS |
423 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
424 | enum plane_id plane_id = plane->id; | |
425 | enum pipe pipe = plane->pipe; | |
dd584fc0 VS |
426 | unsigned long irqflags; |
427 | ||
428 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); | |
dc2a41b4 | 429 | |
dd584fc0 | 430 | I915_WRITE_FW(PLANE_CTL(pipe, plane_id), 0); |
dc2a41b4 | 431 | |
dd584fc0 VS |
432 | I915_WRITE_FW(PLANE_SURF(pipe, plane_id), 0); |
433 | POSTING_READ_FW(PLANE_SURF(pipe, plane_id)); | |
434 | ||
435 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); | |
dc2a41b4 DL |
436 | } |
437 | ||
51f5a096 | 438 | bool |
eade6c89 VS |
439 | skl_plane_get_hw_state(struct intel_plane *plane, |
440 | enum pipe *pipe) | |
51f5a096 VS |
441 | { |
442 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); | |
443 | enum intel_display_power_domain power_domain; | |
444 | enum plane_id plane_id = plane->id; | |
51f5a096 VS |
445 | bool ret; |
446 | ||
eade6c89 | 447 | power_domain = POWER_DOMAIN_PIPE(plane->pipe); |
51f5a096 VS |
448 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
449 | return false; | |
450 | ||
eade6c89 VS |
451 | ret = I915_READ(PLANE_CTL(plane->pipe, plane_id)) & PLANE_CTL_ENABLE; |
452 | ||
453 | *pipe = plane->pipe; | |
51f5a096 VS |
454 | |
455 | intel_display_power_put(dev_priv, power_domain); | |
456 | ||
457 | return ret; | |
458 | } | |
459 | ||
6ca2aeb2 | 460 | static void |
5deae919 | 461 | chv_update_csc(const struct intel_plane_state *plane_state) |
6ca2aeb2 | 462 | { |
5deae919 | 463 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
282dbf9b | 464 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
5deae919 | 465 | const struct drm_framebuffer *fb = plane_state->base.fb; |
282dbf9b | 466 | enum plane_id plane_id = plane->id; |
6ca2aeb2 | 467 | /* |
b0f5c0ba VS |
468 | * |r| | c0 c1 c2 | |cr| |
469 | * |g| = | c3 c4 c5 | x |y | | |
470 | * |b| | c6 c7 c8 | |cb| | |
6ca2aeb2 | 471 | * |
b0f5c0ba | 472 | * Coefficients are s3.12. |
6ca2aeb2 | 473 | * |
b0f5c0ba VS |
474 | * Cb and Cr apparently come in as signed already, and |
475 | * we always get full range data in on account of CLRC0/1. | |
6ca2aeb2 | 476 | */ |
b0f5c0ba VS |
477 | static const s16 csc_matrix[][9] = { |
478 | /* BT.601 full range YCbCr -> full range RGB */ | |
479 | [DRM_COLOR_YCBCR_BT601] = { | |
480 | 5743, 4096, 0, | |
481 | -2925, 4096, -1410, | |
482 | 0, 4096, 7258, | |
483 | }, | |
484 | /* BT.709 full range YCbCr -> full range RGB */ | |
485 | [DRM_COLOR_YCBCR_BT709] = { | |
486 | 6450, 4096, 0, | |
487 | -1917, 4096, -767, | |
488 | 0, 4096, 7601, | |
489 | }, | |
490 | }; | |
491 | const s16 *csc = csc_matrix[plane_state->base.color_encoding]; | |
6ca2aeb2 VS |
492 | |
493 | /* Seems RGB data bypasses the CSC always */ | |
9bace659 | 494 | if (!fb->format->is_yuv) |
6ca2aeb2 VS |
495 | return; |
496 | ||
5deae919 | 497 | I915_WRITE_FW(SPCSCYGOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0)); |
dd584fc0 VS |
498 | I915_WRITE_FW(SPCSCCBOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0)); |
499 | I915_WRITE_FW(SPCSCCROFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0)); | |
500 | ||
b0f5c0ba VS |
501 | I915_WRITE_FW(SPCSCC01(plane_id), SPCSC_C1(csc[1]) | SPCSC_C0(csc[0])); |
502 | I915_WRITE_FW(SPCSCC23(plane_id), SPCSC_C1(csc[3]) | SPCSC_C0(csc[2])); | |
503 | I915_WRITE_FW(SPCSCC45(plane_id), SPCSC_C1(csc[5]) | SPCSC_C0(csc[4])); | |
504 | I915_WRITE_FW(SPCSCC67(plane_id), SPCSC_C1(csc[7]) | SPCSC_C0(csc[6])); | |
505 | I915_WRITE_FW(SPCSCC8(plane_id), SPCSC_C0(csc[8])); | |
dd584fc0 | 506 | |
5deae919 VS |
507 | I915_WRITE_FW(SPCSCYGICLAMP(plane_id), SPCSC_IMAX(1023) | SPCSC_IMIN(0)); |
508 | I915_WRITE_FW(SPCSCCBICLAMP(plane_id), SPCSC_IMAX(512) | SPCSC_IMIN(-512)); | |
509 | I915_WRITE_FW(SPCSCCRICLAMP(plane_id), SPCSC_IMAX(512) | SPCSC_IMIN(-512)); | |
dd584fc0 VS |
510 | |
511 | I915_WRITE_FW(SPCSCYGOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0)); | |
512 | I915_WRITE_FW(SPCSCCBOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0)); | |
513 | I915_WRITE_FW(SPCSCCROCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0)); | |
6ca2aeb2 VS |
514 | } |
515 | ||
5deae919 VS |
516 | #define SIN_0 0 |
517 | #define COS_0 1 | |
518 | ||
519 | static void | |
520 | vlv_update_clrc(const struct intel_plane_state *plane_state) | |
521 | { | |
522 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); | |
523 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); | |
524 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
525 | enum pipe pipe = plane->pipe; | |
526 | enum plane_id plane_id = plane->id; | |
527 | int contrast, brightness, sh_scale, sh_sin, sh_cos; | |
528 | ||
9bace659 | 529 | if (fb->format->is_yuv && |
c8624ede | 530 | plane_state->base.color_range == DRM_COLOR_YCBCR_LIMITED_RANGE) { |
5deae919 VS |
531 | /* |
532 | * Expand limited range to full range: | |
533 | * Contrast is applied first and is used to expand Y range. | |
534 | * Brightness is applied second and is used to remove the | |
535 | * offset from Y. Saturation/hue is used to expand CbCr range. | |
536 | */ | |
537 | contrast = DIV_ROUND_CLOSEST(255 << 6, 235 - 16); | |
538 | brightness = -DIV_ROUND_CLOSEST(16 * 255, 235 - 16); | |
539 | sh_scale = DIV_ROUND_CLOSEST(128 << 7, 240 - 128); | |
540 | sh_sin = SIN_0 * sh_scale; | |
541 | sh_cos = COS_0 * sh_scale; | |
542 | } else { | |
543 | /* Pass-through everything. */ | |
544 | contrast = 1 << 6; | |
545 | brightness = 0; | |
546 | sh_scale = 1 << 7; | |
547 | sh_sin = SIN_0 * sh_scale; | |
548 | sh_cos = COS_0 * sh_scale; | |
549 | } | |
550 | ||
551 | /* FIXME these register are single buffered :( */ | |
552 | I915_WRITE_FW(SPCLRC0(pipe, plane_id), | |
553 | SP_CONTRAST(contrast) | SP_BRIGHTNESS(brightness)); | |
554 | I915_WRITE_FW(SPCLRC1(pipe, plane_id), | |
555 | SP_SH_SIN(sh_sin) | SP_SH_COS(sh_cos)); | |
556 | } | |
557 | ||
96ef6854 VS |
558 | static u32 vlv_sprite_ctl(const struct intel_crtc_state *crtc_state, |
559 | const struct intel_plane_state *plane_state) | |
7f1f3851 | 560 | { |
96ef6854 | 561 | const struct drm_framebuffer *fb = plane_state->base.fb; |
11df4d95 | 562 | unsigned int rotation = plane_state->base.rotation; |
2fde1391 | 563 | const struct drm_intel_sprite_colorkey *key = &plane_state->ckey; |
96ef6854 | 564 | u32 sprctl; |
7f1f3851 | 565 | |
96ef6854 | 566 | sprctl = SP_ENABLE | SP_GAMMA_ENABLE; |
7f1f3851 | 567 | |
438b74a5 | 568 | switch (fb->format->format) { |
7f1f3851 JB |
569 | case DRM_FORMAT_YUYV: |
570 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV; | |
571 | break; | |
572 | case DRM_FORMAT_YVYU: | |
573 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU; | |
574 | break; | |
575 | case DRM_FORMAT_UYVY: | |
576 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY; | |
577 | break; | |
578 | case DRM_FORMAT_VYUY: | |
579 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY; | |
580 | break; | |
581 | case DRM_FORMAT_RGB565: | |
582 | sprctl |= SP_FORMAT_BGR565; | |
583 | break; | |
584 | case DRM_FORMAT_XRGB8888: | |
585 | sprctl |= SP_FORMAT_BGRX8888; | |
586 | break; | |
587 | case DRM_FORMAT_ARGB8888: | |
588 | sprctl |= SP_FORMAT_BGRA8888; | |
589 | break; | |
590 | case DRM_FORMAT_XBGR2101010: | |
591 | sprctl |= SP_FORMAT_RGBX1010102; | |
592 | break; | |
593 | case DRM_FORMAT_ABGR2101010: | |
594 | sprctl |= SP_FORMAT_RGBA1010102; | |
595 | break; | |
596 | case DRM_FORMAT_XBGR8888: | |
597 | sprctl |= SP_FORMAT_RGBX8888; | |
598 | break; | |
599 | case DRM_FORMAT_ABGR8888: | |
600 | sprctl |= SP_FORMAT_RGBA8888; | |
601 | break; | |
602 | default: | |
96ef6854 VS |
603 | MISSING_CASE(fb->format->format); |
604 | return 0; | |
7f1f3851 JB |
605 | } |
606 | ||
b0f5c0ba VS |
607 | if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709) |
608 | sprctl |= SP_YUV_FORMAT_BT709; | |
609 | ||
bae781b2 | 610 | if (fb->modifier == I915_FORMAT_MOD_X_TILED) |
7f1f3851 JB |
611 | sprctl |= SP_TILED; |
612 | ||
c2c446ad | 613 | if (rotation & DRM_MODE_ROTATE_180) |
df0cd455 VS |
614 | sprctl |= SP_ROTATE_180; |
615 | ||
c2c446ad | 616 | if (rotation & DRM_MODE_REFLECT_X) |
4ea7be2b VS |
617 | sprctl |= SP_MIRROR; |
618 | ||
78587de2 VS |
619 | if (key->flags & I915_SET_COLORKEY_SOURCE) |
620 | sprctl |= SP_SOURCE_KEY; | |
621 | ||
96ef6854 VS |
622 | return sprctl; |
623 | } | |
624 | ||
625 | static void | |
282dbf9b | 626 | vlv_update_plane(struct intel_plane *plane, |
96ef6854 VS |
627 | const struct intel_crtc_state *crtc_state, |
628 | const struct intel_plane_state *plane_state) | |
629 | { | |
282dbf9b VS |
630 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
631 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
632 | enum pipe pipe = plane->pipe; | |
633 | enum plane_id plane_id = plane->id; | |
a0864d59 | 634 | u32 sprctl = plane_state->ctl; |
c11ada07 | 635 | u32 sprsurf_offset = plane_state->color_plane[0].offset; |
f9407ae1 | 636 | u32 linear_offset; |
96ef6854 VS |
637 | const struct drm_intel_sprite_colorkey *key = &plane_state->ckey; |
638 | int crtc_x = plane_state->base.dst.x1; | |
639 | int crtc_y = plane_state->base.dst.y1; | |
640 | uint32_t crtc_w = drm_rect_width(&plane_state->base.dst); | |
641 | uint32_t crtc_h = drm_rect_height(&plane_state->base.dst); | |
c11ada07 VS |
642 | uint32_t x = plane_state->color_plane[0].x; |
643 | uint32_t y = plane_state->color_plane[0].y; | |
96ef6854 VS |
644 | unsigned long irqflags; |
645 | ||
7f1f3851 | 646 | /* Sizes are 0 based */ |
7f1f3851 JB |
647 | crtc_w--; |
648 | crtc_h--; | |
649 | ||
2949056c | 650 | linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0); |
6687c906 | 651 | |
dd584fc0 VS |
652 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
653 | ||
5deae919 VS |
654 | vlv_update_clrc(plane_state); |
655 | ||
78587de2 | 656 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) |
5deae919 | 657 | chv_update_csc(plane_state); |
78587de2 | 658 | |
47ecbb20 | 659 | if (key->flags) { |
dd584fc0 VS |
660 | I915_WRITE_FW(SPKEYMINVAL(pipe, plane_id), key->min_value); |
661 | I915_WRITE_FW(SPKEYMAXVAL(pipe, plane_id), key->max_value); | |
662 | I915_WRITE_FW(SPKEYMSK(pipe, plane_id), key->channel_mask); | |
47ecbb20 | 663 | } |
df79cf44 VS |
664 | I915_WRITE_FW(SPSTRIDE(pipe, plane_id), |
665 | plane_state->color_plane[0].stride); | |
dd584fc0 | 666 | I915_WRITE_FW(SPPOS(pipe, plane_id), (crtc_y << 16) | crtc_x); |
ca6ad025 | 667 | |
bae781b2 | 668 | if (fb->modifier == I915_FORMAT_MOD_X_TILED) |
dd584fc0 | 669 | I915_WRITE_FW(SPTILEOFF(pipe, plane_id), (y << 16) | x); |
7f1f3851 | 670 | else |
dd584fc0 | 671 | I915_WRITE_FW(SPLINOFF(pipe, plane_id), linear_offset); |
7f1f3851 | 672 | |
dd584fc0 | 673 | I915_WRITE_FW(SPCONSTALPHA(pipe, plane_id), 0); |
c14b0485 | 674 | |
dd584fc0 VS |
675 | I915_WRITE_FW(SPSIZE(pipe, plane_id), (crtc_h << 16) | crtc_w); |
676 | I915_WRITE_FW(SPCNTR(pipe, plane_id), sprctl); | |
677 | I915_WRITE_FW(SPSURF(pipe, plane_id), | |
678 | intel_plane_ggtt_offset(plane_state) + sprsurf_offset); | |
679 | POSTING_READ_FW(SPSURF(pipe, plane_id)); | |
680 | ||
681 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); | |
7f1f3851 JB |
682 | } |
683 | ||
684 | static void | |
282dbf9b | 685 | vlv_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc) |
7f1f3851 | 686 | { |
282dbf9b VS |
687 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
688 | enum pipe pipe = plane->pipe; | |
689 | enum plane_id plane_id = plane->id; | |
dd584fc0 VS |
690 | unsigned long irqflags; |
691 | ||
692 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); | |
7f1f3851 | 693 | |
dd584fc0 | 694 | I915_WRITE_FW(SPCNTR(pipe, plane_id), 0); |
48fe4691 | 695 | |
dd584fc0 VS |
696 | I915_WRITE_FW(SPSURF(pipe, plane_id), 0); |
697 | POSTING_READ_FW(SPSURF(pipe, plane_id)); | |
698 | ||
699 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); | |
7f1f3851 JB |
700 | } |
701 | ||
51f5a096 | 702 | static bool |
eade6c89 VS |
703 | vlv_plane_get_hw_state(struct intel_plane *plane, |
704 | enum pipe *pipe) | |
51f5a096 VS |
705 | { |
706 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); | |
707 | enum intel_display_power_domain power_domain; | |
708 | enum plane_id plane_id = plane->id; | |
51f5a096 VS |
709 | bool ret; |
710 | ||
eade6c89 | 711 | power_domain = POWER_DOMAIN_PIPE(plane->pipe); |
51f5a096 VS |
712 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
713 | return false; | |
714 | ||
eade6c89 VS |
715 | ret = I915_READ(SPCNTR(plane->pipe, plane_id)) & SP_ENABLE; |
716 | ||
717 | *pipe = plane->pipe; | |
51f5a096 VS |
718 | |
719 | intel_display_power_put(dev_priv, power_domain); | |
720 | ||
721 | return ret; | |
722 | } | |
723 | ||
45dea7b0 VS |
724 | static u32 ivb_sprite_ctl(const struct intel_crtc_state *crtc_state, |
725 | const struct intel_plane_state *plane_state) | |
b840d907 | 726 | { |
45dea7b0 VS |
727 | struct drm_i915_private *dev_priv = |
728 | to_i915(plane_state->base.plane->dev); | |
729 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
8d0deca8 | 730 | unsigned int rotation = plane_state->base.rotation; |
2fde1391 | 731 | const struct drm_intel_sprite_colorkey *key = &plane_state->ckey; |
45dea7b0 VS |
732 | u32 sprctl; |
733 | ||
734 | sprctl = SPRITE_ENABLE | SPRITE_GAMMA_ENABLE; | |
b840d907 | 735 | |
45dea7b0 VS |
736 | if (IS_IVYBRIDGE(dev_priv)) |
737 | sprctl |= SPRITE_TRICKLE_FEED_DISABLE; | |
738 | ||
739 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) | |
740 | sprctl |= SPRITE_PIPE_CSC_ENABLE; | |
b840d907 | 741 | |
438b74a5 | 742 | switch (fb->format->format) { |
b840d907 | 743 | case DRM_FORMAT_XBGR8888: |
5ee36913 | 744 | sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX; |
b840d907 JB |
745 | break; |
746 | case DRM_FORMAT_XRGB8888: | |
5ee36913 | 747 | sprctl |= SPRITE_FORMAT_RGBX888; |
b840d907 JB |
748 | break; |
749 | case DRM_FORMAT_YUYV: | |
750 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV; | |
b840d907 JB |
751 | break; |
752 | case DRM_FORMAT_YVYU: | |
753 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU; | |
b840d907 JB |
754 | break; |
755 | case DRM_FORMAT_UYVY: | |
756 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY; | |
b840d907 JB |
757 | break; |
758 | case DRM_FORMAT_VYUY: | |
759 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY; | |
b840d907 JB |
760 | break; |
761 | default: | |
45dea7b0 VS |
762 | MISSING_CASE(fb->format->format); |
763 | return 0; | |
b840d907 JB |
764 | } |
765 | ||
b0f5c0ba VS |
766 | if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709) |
767 | sprctl |= SPRITE_YUV_TO_RGB_CSC_FORMAT_BT709; | |
768 | ||
c8624ede VS |
769 | if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE) |
770 | sprctl |= SPRITE_YUV_RANGE_CORRECTION_DISABLE; | |
771 | ||
bae781b2 | 772 | if (fb->modifier == I915_FORMAT_MOD_X_TILED) |
b840d907 JB |
773 | sprctl |= SPRITE_TILED; |
774 | ||
c2c446ad | 775 | if (rotation & DRM_MODE_ROTATE_180) |
df0cd455 VS |
776 | sprctl |= SPRITE_ROTATE_180; |
777 | ||
78587de2 VS |
778 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
779 | sprctl |= SPRITE_DEST_KEY; | |
780 | else if (key->flags & I915_SET_COLORKEY_SOURCE) | |
781 | sprctl |= SPRITE_SOURCE_KEY; | |
782 | ||
45dea7b0 VS |
783 | return sprctl; |
784 | } | |
785 | ||
786 | static void | |
282dbf9b | 787 | ivb_update_plane(struct intel_plane *plane, |
45dea7b0 VS |
788 | const struct intel_crtc_state *crtc_state, |
789 | const struct intel_plane_state *plane_state) | |
790 | { | |
282dbf9b VS |
791 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
792 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
793 | enum pipe pipe = plane->pipe; | |
a0864d59 | 794 | u32 sprctl = plane_state->ctl, sprscale = 0; |
c11ada07 | 795 | u32 sprsurf_offset = plane_state->color_plane[0].offset; |
f9407ae1 | 796 | u32 linear_offset; |
45dea7b0 VS |
797 | const struct drm_intel_sprite_colorkey *key = &plane_state->ckey; |
798 | int crtc_x = plane_state->base.dst.x1; | |
799 | int crtc_y = plane_state->base.dst.y1; | |
800 | uint32_t crtc_w = drm_rect_width(&plane_state->base.dst); | |
801 | uint32_t crtc_h = drm_rect_height(&plane_state->base.dst); | |
c11ada07 VS |
802 | uint32_t x = plane_state->color_plane[0].x; |
803 | uint32_t y = plane_state->color_plane[0].y; | |
45dea7b0 VS |
804 | uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16; |
805 | uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16; | |
806 | unsigned long irqflags; | |
807 | ||
b840d907 JB |
808 | /* Sizes are 0 based */ |
809 | src_w--; | |
810 | src_h--; | |
811 | crtc_w--; | |
812 | crtc_h--; | |
813 | ||
8553c18e | 814 | if (crtc_w != src_w || crtc_h != src_h) |
b840d907 | 815 | sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h; |
b840d907 | 816 | |
2949056c | 817 | linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0); |
6687c906 | 818 | |
dd584fc0 VS |
819 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
820 | ||
47ecbb20 | 821 | if (key->flags) { |
dd584fc0 VS |
822 | I915_WRITE_FW(SPRKEYVAL(pipe), key->min_value); |
823 | I915_WRITE_FW(SPRKEYMAX(pipe), key->max_value); | |
824 | I915_WRITE_FW(SPRKEYMSK(pipe), key->channel_mask); | |
47ecbb20 VS |
825 | } |
826 | ||
df79cf44 | 827 | I915_WRITE_FW(SPRSTRIDE(pipe), plane_state->color_plane[0].stride); |
dd584fc0 | 828 | I915_WRITE_FW(SPRPOS(pipe), (crtc_y << 16) | crtc_x); |
ca6ad025 | 829 | |
5a35e99e DL |
830 | /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET |
831 | * register */ | |
8652744b | 832 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
dd584fc0 | 833 | I915_WRITE_FW(SPROFFSET(pipe), (y << 16) | x); |
bae781b2 | 834 | else if (fb->modifier == I915_FORMAT_MOD_X_TILED) |
dd584fc0 | 835 | I915_WRITE_FW(SPRTILEOFF(pipe), (y << 16) | x); |
5a35e99e | 836 | else |
dd584fc0 | 837 | I915_WRITE_FW(SPRLINOFF(pipe), linear_offset); |
c54173a8 | 838 | |
dd584fc0 | 839 | I915_WRITE_FW(SPRSIZE(pipe), (crtc_h << 16) | crtc_w); |
fd6e3c6c | 840 | if (IS_IVYBRIDGE(dev_priv)) |
dd584fc0 VS |
841 | I915_WRITE_FW(SPRSCALE(pipe), sprscale); |
842 | I915_WRITE_FW(SPRCTL(pipe), sprctl); | |
843 | I915_WRITE_FW(SPRSURF(pipe), | |
844 | intel_plane_ggtt_offset(plane_state) + sprsurf_offset); | |
845 | POSTING_READ_FW(SPRSURF(pipe)); | |
846 | ||
847 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); | |
b840d907 JB |
848 | } |
849 | ||
850 | static void | |
282dbf9b | 851 | ivb_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc) |
b840d907 | 852 | { |
282dbf9b VS |
853 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
854 | enum pipe pipe = plane->pipe; | |
dd584fc0 VS |
855 | unsigned long irqflags; |
856 | ||
857 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); | |
b840d907 | 858 | |
dd584fc0 | 859 | I915_WRITE_FW(SPRCTL(pipe), 0); |
b840d907 | 860 | /* Can't leave the scaler enabled... */ |
fd6e3c6c | 861 | if (IS_IVYBRIDGE(dev_priv)) |
dd584fc0 | 862 | I915_WRITE_FW(SPRSCALE(pipe), 0); |
5b633d6b | 863 | |
dd584fc0 VS |
864 | I915_WRITE_FW(SPRSURF(pipe), 0); |
865 | POSTING_READ_FW(SPRSURF(pipe)); | |
866 | ||
867 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); | |
b840d907 JB |
868 | } |
869 | ||
51f5a096 | 870 | static bool |
eade6c89 VS |
871 | ivb_plane_get_hw_state(struct intel_plane *plane, |
872 | enum pipe *pipe) | |
51f5a096 VS |
873 | { |
874 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); | |
875 | enum intel_display_power_domain power_domain; | |
51f5a096 VS |
876 | bool ret; |
877 | ||
eade6c89 | 878 | power_domain = POWER_DOMAIN_PIPE(plane->pipe); |
51f5a096 VS |
879 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
880 | return false; | |
881 | ||
eade6c89 VS |
882 | ret = I915_READ(SPRCTL(plane->pipe)) & SPRITE_ENABLE; |
883 | ||
884 | *pipe = plane->pipe; | |
51f5a096 VS |
885 | |
886 | intel_display_power_put(dev_priv, power_domain); | |
887 | ||
888 | return ret; | |
889 | } | |
890 | ||
ddd5713d VS |
891 | static unsigned int |
892 | g4x_sprite_max_stride(struct intel_plane *plane, | |
893 | u32 pixel_format, u64 modifier, | |
894 | unsigned int rotation) | |
895 | { | |
896 | return 16384; | |
897 | } | |
898 | ||
ab33081a | 899 | static u32 g4x_sprite_ctl(const struct intel_crtc_state *crtc_state, |
0a375147 | 900 | const struct intel_plane_state *plane_state) |
b840d907 | 901 | { |
0a375147 VS |
902 | struct drm_i915_private *dev_priv = |
903 | to_i915(plane_state->base.plane->dev); | |
904 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
8d0deca8 | 905 | unsigned int rotation = plane_state->base.rotation; |
2fde1391 | 906 | const struct drm_intel_sprite_colorkey *key = &plane_state->ckey; |
0a375147 VS |
907 | u32 dvscntr; |
908 | ||
909 | dvscntr = DVS_ENABLE | DVS_GAMMA_ENABLE; | |
b840d907 | 910 | |
0a375147 VS |
911 | if (IS_GEN6(dev_priv)) |
912 | dvscntr |= DVS_TRICKLE_FEED_DISABLE; | |
b840d907 | 913 | |
438b74a5 | 914 | switch (fb->format->format) { |
b840d907 | 915 | case DRM_FORMAT_XBGR8888: |
ab2f9df1 | 916 | dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR; |
b840d907 JB |
917 | break; |
918 | case DRM_FORMAT_XRGB8888: | |
ab2f9df1 | 919 | dvscntr |= DVS_FORMAT_RGBX888; |
b840d907 JB |
920 | break; |
921 | case DRM_FORMAT_YUYV: | |
922 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV; | |
b840d907 JB |
923 | break; |
924 | case DRM_FORMAT_YVYU: | |
925 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU; | |
b840d907 JB |
926 | break; |
927 | case DRM_FORMAT_UYVY: | |
928 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY; | |
b840d907 JB |
929 | break; |
930 | case DRM_FORMAT_VYUY: | |
931 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY; | |
b840d907 JB |
932 | break; |
933 | default: | |
0a375147 VS |
934 | MISSING_CASE(fb->format->format); |
935 | return 0; | |
b840d907 JB |
936 | } |
937 | ||
b0f5c0ba VS |
938 | if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709) |
939 | dvscntr |= DVS_YUV_FORMAT_BT709; | |
940 | ||
c8624ede VS |
941 | if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE) |
942 | dvscntr |= DVS_YUV_RANGE_CORRECTION_DISABLE; | |
943 | ||
bae781b2 | 944 | if (fb->modifier == I915_FORMAT_MOD_X_TILED) |
b840d907 JB |
945 | dvscntr |= DVS_TILED; |
946 | ||
c2c446ad | 947 | if (rotation & DRM_MODE_ROTATE_180) |
df0cd455 VS |
948 | dvscntr |= DVS_ROTATE_180; |
949 | ||
78587de2 VS |
950 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
951 | dvscntr |= DVS_DEST_KEY; | |
952 | else if (key->flags & I915_SET_COLORKEY_SOURCE) | |
953 | dvscntr |= DVS_SOURCE_KEY; | |
954 | ||
0a375147 VS |
955 | return dvscntr; |
956 | } | |
957 | ||
958 | static void | |
282dbf9b | 959 | g4x_update_plane(struct intel_plane *plane, |
0a375147 VS |
960 | const struct intel_crtc_state *crtc_state, |
961 | const struct intel_plane_state *plane_state) | |
962 | { | |
282dbf9b VS |
963 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
964 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
965 | enum pipe pipe = plane->pipe; | |
f9407ae1 | 966 | u32 dvscntr = plane_state->ctl, dvsscale = 0; |
c11ada07 | 967 | u32 dvssurf_offset = plane_state->color_plane[0].offset; |
f9407ae1 | 968 | u32 linear_offset; |
0a375147 VS |
969 | const struct drm_intel_sprite_colorkey *key = &plane_state->ckey; |
970 | int crtc_x = plane_state->base.dst.x1; | |
971 | int crtc_y = plane_state->base.dst.y1; | |
972 | uint32_t crtc_w = drm_rect_width(&plane_state->base.dst); | |
973 | uint32_t crtc_h = drm_rect_height(&plane_state->base.dst); | |
c11ada07 VS |
974 | uint32_t x = plane_state->color_plane[0].x; |
975 | uint32_t y = plane_state->color_plane[0].y; | |
0a375147 VS |
976 | uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16; |
977 | uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16; | |
978 | unsigned long irqflags; | |
979 | ||
b840d907 JB |
980 | /* Sizes are 0 based */ |
981 | src_w--; | |
982 | src_h--; | |
983 | crtc_w--; | |
984 | crtc_h--; | |
985 | ||
8368f014 | 986 | if (crtc_w != src_w || crtc_h != src_h) |
b840d907 JB |
987 | dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h; |
988 | ||
2949056c | 989 | linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0); |
6687c906 | 990 | |
dd584fc0 VS |
991 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
992 | ||
47ecbb20 | 993 | if (key->flags) { |
dd584fc0 VS |
994 | I915_WRITE_FW(DVSKEYVAL(pipe), key->min_value); |
995 | I915_WRITE_FW(DVSKEYMAX(pipe), key->max_value); | |
996 | I915_WRITE_FW(DVSKEYMSK(pipe), key->channel_mask); | |
47ecbb20 VS |
997 | } |
998 | ||
df79cf44 | 999 | I915_WRITE_FW(DVSSTRIDE(pipe), plane_state->color_plane[0].stride); |
dd584fc0 | 1000 | I915_WRITE_FW(DVSPOS(pipe), (crtc_y << 16) | crtc_x); |
ca6ad025 | 1001 | |
bae781b2 | 1002 | if (fb->modifier == I915_FORMAT_MOD_X_TILED) |
dd584fc0 | 1003 | I915_WRITE_FW(DVSTILEOFF(pipe), (y << 16) | x); |
5a35e99e | 1004 | else |
dd584fc0 VS |
1005 | I915_WRITE_FW(DVSLINOFF(pipe), linear_offset); |
1006 | ||
1007 | I915_WRITE_FW(DVSSIZE(pipe), (crtc_h << 16) | crtc_w); | |
1008 | I915_WRITE_FW(DVSSCALE(pipe), dvsscale); | |
1009 | I915_WRITE_FW(DVSCNTR(pipe), dvscntr); | |
1010 | I915_WRITE_FW(DVSSURF(pipe), | |
1011 | intel_plane_ggtt_offset(plane_state) + dvssurf_offset); | |
1012 | POSTING_READ_FW(DVSSURF(pipe)); | |
1013 | ||
1014 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); | |
b840d907 JB |
1015 | } |
1016 | ||
1017 | static void | |
282dbf9b | 1018 | g4x_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc) |
b840d907 | 1019 | { |
282dbf9b VS |
1020 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
1021 | enum pipe pipe = plane->pipe; | |
dd584fc0 | 1022 | unsigned long irqflags; |
b840d907 | 1023 | |
dd584fc0 VS |
1024 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
1025 | ||
1026 | I915_WRITE_FW(DVSCNTR(pipe), 0); | |
b840d907 | 1027 | /* Disable the scaler */ |
dd584fc0 VS |
1028 | I915_WRITE_FW(DVSSCALE(pipe), 0); |
1029 | ||
1030 | I915_WRITE_FW(DVSSURF(pipe), 0); | |
1031 | POSTING_READ_FW(DVSSURF(pipe)); | |
48fe4691 | 1032 | |
dd584fc0 | 1033 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
b840d907 JB |
1034 | } |
1035 | ||
51f5a096 | 1036 | static bool |
eade6c89 VS |
1037 | g4x_plane_get_hw_state(struct intel_plane *plane, |
1038 | enum pipe *pipe) | |
51f5a096 VS |
1039 | { |
1040 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); | |
1041 | enum intel_display_power_domain power_domain; | |
51f5a096 VS |
1042 | bool ret; |
1043 | ||
eade6c89 | 1044 | power_domain = POWER_DOMAIN_PIPE(plane->pipe); |
51f5a096 VS |
1045 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
1046 | return false; | |
1047 | ||
eade6c89 VS |
1048 | ret = I915_READ(DVSCNTR(plane->pipe)) & DVS_ENABLE; |
1049 | ||
1050 | *pipe = plane->pipe; | |
51f5a096 VS |
1051 | |
1052 | intel_display_power_put(dev_priv, power_domain); | |
1053 | ||
1054 | return ret; | |
1055 | } | |
1056 | ||
b840d907 | 1057 | static int |
4e0b83a5 VS |
1058 | g4x_sprite_check_scaling(struct intel_crtc_state *crtc_state, |
1059 | struct intel_plane_state *plane_state) | |
b840d907 | 1060 | { |
4e0b83a5 VS |
1061 | const struct drm_framebuffer *fb = plane_state->base.fb; |
1062 | const struct drm_rect *src = &plane_state->base.src; | |
1063 | const struct drm_rect *dst = &plane_state->base.dst; | |
1064 | int src_x, src_y, src_w, src_h, crtc_w, crtc_h; | |
1065 | const struct drm_display_mode *adjusted_mode = | |
1066 | &crtc_state->base.adjusted_mode; | |
1067 | unsigned int cpp = fb->format->cpp[0]; | |
1068 | unsigned int width_bytes; | |
1069 | int min_width, min_height; | |
1070 | ||
1071 | crtc_w = drm_rect_width(dst); | |
1072 | crtc_h = drm_rect_height(dst); | |
1073 | ||
1074 | src_x = src->x1 >> 16; | |
1075 | src_y = src->y1 >> 16; | |
1076 | src_w = drm_rect_width(src) >> 16; | |
1077 | src_h = drm_rect_height(src) >> 16; | |
1078 | ||
1079 | if (src_w == crtc_w && src_h == crtc_h) | |
da20eabd | 1080 | return 0; |
4e0b83a5 VS |
1081 | |
1082 | min_width = 3; | |
1083 | ||
1084 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { | |
1085 | if (src_h & 1) { | |
1086 | DRM_DEBUG_KMS("Source height must be even with interlaced modes\n"); | |
1087 | return -EINVAL; | |
1088 | } | |
1089 | min_height = 6; | |
1090 | } else { | |
1091 | min_height = 3; | |
cf4c7c12 | 1092 | } |
5e1bac2f | 1093 | |
4e0b83a5 VS |
1094 | width_bytes = ((src_x * cpp) & 63) + src_w * cpp; |
1095 | ||
1096 | if (src_w < min_width || src_h < min_height || | |
1097 | src_w > 2048 || src_h > 2048) { | |
1098 | DRM_DEBUG_KMS("Source dimensions (%dx%d) exceed hardware limits (%dx%d - %dx%d)\n", | |
1099 | src_w, src_h, min_width, min_height, 2048, 2048); | |
b840d907 | 1100 | return -EINVAL; |
1731693a | 1101 | } |
b840d907 | 1102 | |
4e0b83a5 VS |
1103 | if (width_bytes > 4096) { |
1104 | DRM_DEBUG_KMS("Fetch width (%d) exceeds hardware max with scaling (%u)\n", | |
1105 | width_bytes, 4096); | |
b840d907 | 1106 | return -EINVAL; |
1731693a | 1107 | } |
b840d907 | 1108 | |
4e0b83a5 VS |
1109 | if (width_bytes > 4096 || fb->pitches[0] > 4096) { |
1110 | DRM_DEBUG_KMS("Stride (%u) exceeds hardware max with scaling (%u)\n", | |
1111 | fb->pitches[0], 4096); | |
1112 | return -EINVAL; | |
1113 | } | |
1114 | ||
1115 | return 0; | |
1116 | } | |
1117 | ||
1118 | static int | |
1119 | g4x_sprite_check(struct intel_crtc_state *crtc_state, | |
1120 | struct intel_plane_state *plane_state) | |
1121 | { | |
1122 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); | |
1123 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); | |
1124 | int max_scale, min_scale; | |
1125 | int ret; | |
1126 | ||
1127 | if (INTEL_GEN(dev_priv) < 7) { | |
1128 | min_scale = 1; | |
1129 | max_scale = 16 << 16; | |
1130 | } else if (IS_IVYBRIDGE(dev_priv)) { | |
1131 | min_scale = 1; | |
1132 | max_scale = 2 << 16; | |
225c228a | 1133 | } else { |
4e0b83a5 VS |
1134 | min_scale = DRM_PLANE_HELPER_NO_SCALING; |
1135 | max_scale = DRM_PLANE_HELPER_NO_SCALING; | |
225c228a CK |
1136 | } |
1137 | ||
4e0b83a5 | 1138 | ret = drm_atomic_helper_check_plane_state(&plane_state->base, |
9c1659eb ML |
1139 | &crtc_state->base, |
1140 | min_scale, max_scale, | |
1141 | true, true); | |
1142 | if (ret) | |
1143 | return ret; | |
2d354c34 | 1144 | |
4e0b83a5 VS |
1145 | if (!plane_state->base.visible) |
1146 | return 0; | |
1731693a | 1147 | |
4e0b83a5 VS |
1148 | ret = intel_plane_check_src_coordinates(plane_state); |
1149 | if (ret) | |
1150 | return ret; | |
1731693a | 1151 | |
4e0b83a5 VS |
1152 | ret = g4x_sprite_check_scaling(crtc_state, plane_state); |
1153 | if (ret) | |
1154 | return ret; | |
1731693a | 1155 | |
4e0b83a5 VS |
1156 | ret = i9xx_check_plane_surface(plane_state); |
1157 | if (ret) | |
1158 | return ret; | |
a0864d59 | 1159 | |
4e0b83a5 VS |
1160 | if (INTEL_GEN(dev_priv) >= 7) |
1161 | plane_state->ctl = ivb_sprite_ctl(crtc_state, plane_state); | |
1162 | else | |
1163 | plane_state->ctl = g4x_sprite_ctl(crtc_state, plane_state); | |
f9407ae1 | 1164 | |
4e0b83a5 VS |
1165 | return 0; |
1166 | } | |
f9407ae1 | 1167 | |
25721f82 VS |
1168 | int chv_plane_check_rotation(const struct intel_plane_state *plane_state) |
1169 | { | |
1170 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); | |
1171 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); | |
1172 | unsigned int rotation = plane_state->base.rotation; | |
1173 | ||
1174 | /* CHV ignores the mirror bit when the rotate bit is set :( */ | |
1175 | if (IS_CHERRYVIEW(dev_priv) && | |
1176 | rotation & DRM_MODE_ROTATE_180 && | |
1177 | rotation & DRM_MODE_REFLECT_X) { | |
1178 | DRM_DEBUG_KMS("Cannot rotate and reflect at the same time\n"); | |
1179 | return -EINVAL; | |
1180 | } | |
1181 | ||
1182 | return 0; | |
1183 | } | |
1184 | ||
4e0b83a5 VS |
1185 | static int |
1186 | vlv_sprite_check(struct intel_crtc_state *crtc_state, | |
1187 | struct intel_plane_state *plane_state) | |
1188 | { | |
1189 | int ret; | |
1190 | ||
25721f82 VS |
1191 | ret = chv_plane_check_rotation(plane_state); |
1192 | if (ret) | |
1193 | return ret; | |
1194 | ||
4e0b83a5 VS |
1195 | ret = drm_atomic_helper_check_plane_state(&plane_state->base, |
1196 | &crtc_state->base, | |
1197 | DRM_PLANE_HELPER_NO_SCALING, | |
1198 | DRM_PLANE_HELPER_NO_SCALING, | |
1199 | true, true); | |
1200 | if (ret) | |
1201 | return ret; | |
1202 | ||
1203 | if (!plane_state->base.visible) | |
1204 | return 0; | |
1205 | ||
1206 | ret = intel_plane_check_src_coordinates(plane_state); | |
1207 | if (ret) | |
1208 | return ret; | |
1209 | ||
1210 | ret = i9xx_check_plane_surface(plane_state); | |
1211 | if (ret) | |
1212 | return ret; | |
1213 | ||
1214 | plane_state->ctl = vlv_sprite_ctl(crtc_state, plane_state); | |
f9407ae1 | 1215 | |
4e0b83a5 VS |
1216 | return 0; |
1217 | } | |
1218 | ||
e21c2d33 VS |
1219 | static int skl_plane_check_fb(const struct intel_crtc_state *crtc_state, |
1220 | const struct intel_plane_state *plane_state) | |
1221 | { | |
1222 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
1223 | unsigned int rotation = plane_state->base.rotation; | |
1224 | struct drm_format_name_buf format_name; | |
1225 | ||
1226 | if (!fb) | |
1227 | return 0; | |
1228 | ||
1229 | if (rotation & ~(DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180) && | |
1ee516ff | 1230 | is_ccs_modifier(fb->modifier)) { |
e21c2d33 VS |
1231 | DRM_DEBUG_KMS("RC support only with 0/180 degree rotation (%x)\n", |
1232 | rotation); | |
1233 | return -EINVAL; | |
1234 | } | |
1235 | ||
1236 | if (rotation & DRM_MODE_REFLECT_X && | |
1237 | fb->modifier == DRM_FORMAT_MOD_LINEAR) { | |
1238 | DRM_DEBUG_KMS("horizontal flip is not supported with linear surface formats\n"); | |
1239 | return -EINVAL; | |
1240 | } | |
1241 | ||
1242 | if (drm_rotation_90_or_270(rotation)) { | |
1243 | if (fb->modifier != I915_FORMAT_MOD_Y_TILED && | |
1244 | fb->modifier != I915_FORMAT_MOD_Yf_TILED) { | |
1245 | DRM_DEBUG_KMS("Y/Yf tiling required for 90/270!\n"); | |
1246 | return -EINVAL; | |
1247 | } | |
1248 | ||
1249 | /* | |
1250 | * 90/270 is not allowed with RGB64 16:16:16:16, | |
1251 | * RGB 16-bit 5:6:5, and Indexed 8-bit. | |
1252 | * TBD: Add RGB64 case once its added in supported format list. | |
1253 | */ | |
1254 | switch (fb->format->format) { | |
1255 | case DRM_FORMAT_C8: | |
1256 | case DRM_FORMAT_RGB565: | |
1257 | DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n", | |
1258 | drm_get_format_name(fb->format->format, | |
1259 | &format_name)); | |
1260 | return -EINVAL; | |
1261 | default: | |
1262 | break; | |
1263 | } | |
1264 | } | |
1265 | ||
1266 | /* Y-tiling is not supported in IF-ID Interlace mode */ | |
1267 | if (crtc_state->base.enable && | |
1268 | crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE && | |
1269 | (fb->modifier == I915_FORMAT_MOD_Y_TILED || | |
1270 | fb->modifier == I915_FORMAT_MOD_Yf_TILED || | |
1271 | fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS || | |
1272 | fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS)) { | |
1273 | DRM_DEBUG_KMS("Y/Yf tiling not supported in IF-ID mode\n"); | |
1274 | return -EINVAL; | |
1275 | } | |
1276 | ||
1277 | return 0; | |
1278 | } | |
1279 | ||
73266595 VS |
1280 | static int skl_plane_check_dst_coordinates(const struct intel_crtc_state *crtc_state, |
1281 | const struct intel_plane_state *plane_state) | |
1282 | { | |
1283 | struct drm_i915_private *dev_priv = | |
1284 | to_i915(plane_state->base.plane->dev); | |
1285 | int crtc_x = plane_state->base.dst.x1; | |
1286 | int crtc_w = drm_rect_width(&plane_state->base.dst); | |
1287 | int pipe_src_w = crtc_state->pipe_src_w; | |
1288 | ||
1289 | /* | |
1290 | * Display WA #1175: cnl,glk | |
1291 | * Planes other than the cursor may cause FIFO underflow and display | |
1292 | * corruption if starting less than 4 pixels from the right edge of | |
1293 | * the screen. | |
1294 | * Besides the above WA fix the similar problem, where planes other | |
1295 | * than the cursor ending less than 4 pixels from the left edge of the | |
1296 | * screen may cause FIFO underflow and display corruption. | |
1297 | */ | |
1298 | if ((IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) && | |
1299 | (crtc_x + crtc_w < 4 || crtc_x > pipe_src_w - 4)) { | |
1300 | DRM_DEBUG_KMS("requested plane X %s position %d invalid (valid range %d-%d)\n", | |
1301 | crtc_x + crtc_w < 4 ? "end" : "start", | |
1302 | crtc_x + crtc_w < 4 ? crtc_x + crtc_w : crtc_x, | |
1303 | 4, pipe_src_w - 4); | |
1304 | return -ERANGE; | |
1305 | } | |
1306 | ||
1307 | return 0; | |
1308 | } | |
1309 | ||
4e0b83a5 VS |
1310 | int skl_plane_check(struct intel_crtc_state *crtc_state, |
1311 | struct intel_plane_state *plane_state) | |
1312 | { | |
1313 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); | |
1314 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); | |
1315 | int max_scale, min_scale; | |
1316 | int ret; | |
1317 | ||
e21c2d33 VS |
1318 | ret = skl_plane_check_fb(crtc_state, plane_state); |
1319 | if (ret) | |
1320 | return ret; | |
1321 | ||
4e0b83a5 VS |
1322 | /* use scaler when colorkey is not required */ |
1323 | if (!plane_state->ckey.flags) { | |
1324 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
1325 | ||
1326 | min_scale = 1; | |
1327 | max_scale = skl_max_scale(crtc_state, | |
1328 | fb ? fb->format->format : 0); | |
1329 | } else { | |
1330 | min_scale = DRM_PLANE_HELPER_NO_SCALING; | |
1331 | max_scale = DRM_PLANE_HELPER_NO_SCALING; | |
b63a16f6 VS |
1332 | } |
1333 | ||
4e0b83a5 VS |
1334 | ret = drm_atomic_helper_check_plane_state(&plane_state->base, |
1335 | &crtc_state->base, | |
1336 | min_scale, max_scale, | |
1337 | true, true); | |
1338 | if (ret) | |
1339 | return ret; | |
1340 | ||
1341 | if (!plane_state->base.visible) | |
1342 | return 0; | |
1343 | ||
73266595 VS |
1344 | ret = skl_plane_check_dst_coordinates(crtc_state, plane_state); |
1345 | if (ret) | |
1346 | return ret; | |
1347 | ||
4e0b83a5 VS |
1348 | ret = intel_plane_check_src_coordinates(plane_state); |
1349 | if (ret) | |
1350 | return ret; | |
1351 | ||
73266595 | 1352 | ret = skl_check_plane_surface(plane_state); |
4e0b83a5 VS |
1353 | if (ret) |
1354 | return ret; | |
1355 | ||
1356 | plane_state->ctl = skl_plane_ctl(crtc_state, plane_state); | |
1357 | ||
4036c78c | 1358 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) |
4e0b83a5 VS |
1359 | plane_state->color_ctl = glk_plane_color_ctl(crtc_state, |
1360 | plane_state); | |
4036c78c | 1361 | |
96d61a7f GP |
1362 | return 0; |
1363 | } | |
1364 | ||
672b3c4b VS |
1365 | static bool has_dst_key_in_primary_plane(struct drm_i915_private *dev_priv) |
1366 | { | |
1367 | return INTEL_GEN(dev_priv) >= 9; | |
1368 | } | |
1369 | ||
1370 | static void intel_plane_set_ckey(struct intel_plane_state *plane_state, | |
1371 | const struct drm_intel_sprite_colorkey *set) | |
1372 | { | |
1373 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); | |
1374 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); | |
1375 | struct drm_intel_sprite_colorkey *key = &plane_state->ckey; | |
1376 | ||
1377 | *key = *set; | |
1378 | ||
1379 | /* | |
1380 | * We want src key enabled on the | |
1381 | * sprite and not on the primary. | |
1382 | */ | |
1383 | if (plane->id == PLANE_PRIMARY && | |
1384 | set->flags & I915_SET_COLORKEY_SOURCE) | |
1385 | key->flags = 0; | |
1386 | ||
1387 | /* | |
1388 | * On SKL+ we want dst key enabled on | |
1389 | * the primary and not on the sprite. | |
1390 | */ | |
1391 | if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_PRIMARY && | |
1392 | set->flags & I915_SET_COLORKEY_DESTINATION) | |
1393 | key->flags = 0; | |
1394 | } | |
1395 | ||
6a20fe7b VS |
1396 | int intel_sprite_set_colorkey_ioctl(struct drm_device *dev, void *data, |
1397 | struct drm_file *file_priv) | |
8ea30864 | 1398 | { |
920a14b2 | 1399 | struct drm_i915_private *dev_priv = to_i915(dev); |
8ea30864 | 1400 | struct drm_intel_sprite_colorkey *set = data; |
8ea30864 | 1401 | struct drm_plane *plane; |
818ed961 ML |
1402 | struct drm_plane_state *plane_state; |
1403 | struct drm_atomic_state *state; | |
1404 | struct drm_modeset_acquire_ctx ctx; | |
8ea30864 JB |
1405 | int ret = 0; |
1406 | ||
6ec5bd34 VS |
1407 | /* ignore the pointless "none" flag */ |
1408 | set->flags &= ~I915_SET_COLORKEY_NONE; | |
1409 | ||
89746e79 VS |
1410 | if (set->flags & ~(I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) |
1411 | return -EINVAL; | |
1412 | ||
8ea30864 JB |
1413 | /* Make sure we don't try to enable both src & dest simultaneously */ |
1414 | if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) | |
1415 | return -EINVAL; | |
1416 | ||
920a14b2 | 1417 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
47ecbb20 VS |
1418 | set->flags & I915_SET_COLORKEY_DESTINATION) |
1419 | return -EINVAL; | |
1420 | ||
418da172 | 1421 | plane = drm_plane_find(dev, file_priv, set->plane_id); |
818ed961 ML |
1422 | if (!plane || plane->type != DRM_PLANE_TYPE_OVERLAY) |
1423 | return -ENOENT; | |
8ea30864 | 1424 | |
672b3c4b VS |
1425 | /* |
1426 | * SKL+ only plane 2 can do destination keying against plane 1. | |
1427 | * Also multiple planes can't do destination keying on the same | |
1428 | * pipe simultaneously. | |
1429 | */ | |
1430 | if (INTEL_GEN(dev_priv) >= 9 && | |
1431 | to_intel_plane(plane)->id >= PLANE_SPRITE1 && | |
1432 | set->flags & I915_SET_COLORKEY_DESTINATION) | |
1433 | return -EINVAL; | |
1434 | ||
818ed961 | 1435 | drm_modeset_acquire_init(&ctx, 0); |
6156a456 | 1436 | |
818ed961 ML |
1437 | state = drm_atomic_state_alloc(plane->dev); |
1438 | if (!state) { | |
1439 | ret = -ENOMEM; | |
1440 | goto out; | |
6156a456 | 1441 | } |
818ed961 ML |
1442 | state->acquire_ctx = &ctx; |
1443 | ||
1444 | while (1) { | |
1445 | plane_state = drm_atomic_get_plane_state(state, plane); | |
1446 | ret = PTR_ERR_OR_ZERO(plane_state); | |
672b3c4b VS |
1447 | if (!ret) |
1448 | intel_plane_set_ckey(to_intel_plane_state(plane_state), set); | |
1449 | ||
1450 | /* | |
1451 | * On some platforms we have to configure | |
1452 | * the dst colorkey on the primary plane. | |
1453 | */ | |
1454 | if (!ret && has_dst_key_in_primary_plane(dev_priv)) { | |
1455 | struct intel_crtc *crtc = | |
1456 | intel_get_crtc_for_pipe(dev_priv, | |
1457 | to_intel_plane(plane)->pipe); | |
1458 | ||
1459 | plane_state = drm_atomic_get_plane_state(state, | |
1460 | crtc->base.primary); | |
1461 | ret = PTR_ERR_OR_ZERO(plane_state); | |
1462 | if (!ret) | |
1463 | intel_plane_set_ckey(to_intel_plane_state(plane_state), set); | |
818ed961 | 1464 | } |
6156a456 | 1465 | |
672b3c4b VS |
1466 | if (!ret) |
1467 | ret = drm_atomic_commit(state); | |
1468 | ||
818ed961 ML |
1469 | if (ret != -EDEADLK) |
1470 | break; | |
8ea30864 | 1471 | |
818ed961 ML |
1472 | drm_atomic_state_clear(state); |
1473 | drm_modeset_backoff(&ctx); | |
1474 | } | |
8ea30864 | 1475 | |
0853695c | 1476 | drm_atomic_state_put(state); |
818ed961 ML |
1477 | out: |
1478 | drm_modeset_drop_locks(&ctx); | |
1479 | drm_modeset_acquire_fini(&ctx); | |
1480 | return ret; | |
5e1bac2f JB |
1481 | } |
1482 | ||
ab33081a | 1483 | static const uint32_t g4x_plane_formats[] = { |
d1686ae3 CW |
1484 | DRM_FORMAT_XRGB8888, |
1485 | DRM_FORMAT_YUYV, | |
1486 | DRM_FORMAT_YVYU, | |
1487 | DRM_FORMAT_UYVY, | |
1488 | DRM_FORMAT_VYUY, | |
1489 | }; | |
1490 | ||
714244e2 BW |
1491 | static const uint64_t i9xx_plane_format_modifiers[] = { |
1492 | I915_FORMAT_MOD_X_TILED, | |
1493 | DRM_FORMAT_MOD_LINEAR, | |
1494 | DRM_FORMAT_MOD_INVALID | |
1495 | }; | |
1496 | ||
dada2d53 | 1497 | static const uint32_t snb_plane_formats[] = { |
b840d907 JB |
1498 | DRM_FORMAT_XBGR8888, |
1499 | DRM_FORMAT_XRGB8888, | |
1500 | DRM_FORMAT_YUYV, | |
1501 | DRM_FORMAT_YVYU, | |
1502 | DRM_FORMAT_UYVY, | |
1503 | DRM_FORMAT_VYUY, | |
1504 | }; | |
1505 | ||
dada2d53 | 1506 | static const uint32_t vlv_plane_formats[] = { |
7f1f3851 JB |
1507 | DRM_FORMAT_RGB565, |
1508 | DRM_FORMAT_ABGR8888, | |
1509 | DRM_FORMAT_ARGB8888, | |
1510 | DRM_FORMAT_XBGR8888, | |
1511 | DRM_FORMAT_XRGB8888, | |
1512 | DRM_FORMAT_XBGR2101010, | |
1513 | DRM_FORMAT_ABGR2101010, | |
1514 | DRM_FORMAT_YUYV, | |
1515 | DRM_FORMAT_YVYU, | |
1516 | DRM_FORMAT_UYVY, | |
1517 | DRM_FORMAT_VYUY, | |
1518 | }; | |
1519 | ||
dc2a41b4 DL |
1520 | static uint32_t skl_plane_formats[] = { |
1521 | DRM_FORMAT_RGB565, | |
1522 | DRM_FORMAT_ABGR8888, | |
1523 | DRM_FORMAT_ARGB8888, | |
1524 | DRM_FORMAT_XBGR8888, | |
1525 | DRM_FORMAT_XRGB8888, | |
1526 | DRM_FORMAT_YUYV, | |
1527 | DRM_FORMAT_YVYU, | |
1528 | DRM_FORMAT_UYVY, | |
1529 | DRM_FORMAT_VYUY, | |
1530 | }; | |
1531 | ||
429204f1 CK |
1532 | static uint32_t skl_planar_formats[] = { |
1533 | DRM_FORMAT_RGB565, | |
1534 | DRM_FORMAT_ABGR8888, | |
1535 | DRM_FORMAT_ARGB8888, | |
1536 | DRM_FORMAT_XBGR8888, | |
1537 | DRM_FORMAT_XRGB8888, | |
1538 | DRM_FORMAT_YUYV, | |
1539 | DRM_FORMAT_YVYU, | |
1540 | DRM_FORMAT_UYVY, | |
1541 | DRM_FORMAT_VYUY, | |
1542 | DRM_FORMAT_NV12, | |
1543 | }; | |
1544 | ||
77064e2e VS |
1545 | static const uint64_t skl_plane_format_modifiers_noccs[] = { |
1546 | I915_FORMAT_MOD_Yf_TILED, | |
1547 | I915_FORMAT_MOD_Y_TILED, | |
1548 | I915_FORMAT_MOD_X_TILED, | |
1549 | DRM_FORMAT_MOD_LINEAR, | |
1550 | DRM_FORMAT_MOD_INVALID | |
1551 | }; | |
1552 | ||
1553 | static const uint64_t skl_plane_format_modifiers_ccs[] = { | |
1554 | I915_FORMAT_MOD_Yf_TILED_CCS, | |
1555 | I915_FORMAT_MOD_Y_TILED_CCS, | |
74ac160b VS |
1556 | I915_FORMAT_MOD_Yf_TILED, |
1557 | I915_FORMAT_MOD_Y_TILED, | |
714244e2 BW |
1558 | I915_FORMAT_MOD_X_TILED, |
1559 | DRM_FORMAT_MOD_LINEAR, | |
1560 | DRM_FORMAT_MOD_INVALID | |
1561 | }; | |
1562 | ||
a38189c5 VS |
1563 | static bool g4x_sprite_format_mod_supported(struct drm_plane *_plane, |
1564 | u32 format, u64 modifier) | |
714244e2 | 1565 | { |
a38189c5 VS |
1566 | switch (modifier) { |
1567 | case DRM_FORMAT_MOD_LINEAR: | |
1568 | case I915_FORMAT_MOD_X_TILED: | |
1569 | break; | |
1570 | default: | |
1571 | return false; | |
1572 | } | |
1573 | ||
714244e2 | 1574 | switch (format) { |
714244e2 BW |
1575 | case DRM_FORMAT_XRGB8888: |
1576 | case DRM_FORMAT_YUYV: | |
1577 | case DRM_FORMAT_YVYU: | |
1578 | case DRM_FORMAT_UYVY: | |
1579 | case DRM_FORMAT_VYUY: | |
1580 | if (modifier == DRM_FORMAT_MOD_LINEAR || | |
1581 | modifier == I915_FORMAT_MOD_X_TILED) | |
1582 | return true; | |
1583 | /* fall through */ | |
1584 | default: | |
1585 | return false; | |
1586 | } | |
1587 | } | |
1588 | ||
a38189c5 VS |
1589 | static bool snb_sprite_format_mod_supported(struct drm_plane *_plane, |
1590 | u32 format, u64 modifier) | |
714244e2 | 1591 | { |
a38189c5 VS |
1592 | switch (modifier) { |
1593 | case DRM_FORMAT_MOD_LINEAR: | |
1594 | case I915_FORMAT_MOD_X_TILED: | |
1595 | break; | |
1596 | default: | |
1597 | return false; | |
1598 | } | |
1599 | ||
714244e2 | 1600 | switch (format) { |
c21f7904 VS |
1601 | case DRM_FORMAT_XRGB8888: |
1602 | case DRM_FORMAT_XBGR8888: | |
714244e2 BW |
1603 | case DRM_FORMAT_YUYV: |
1604 | case DRM_FORMAT_YVYU: | |
1605 | case DRM_FORMAT_UYVY: | |
1606 | case DRM_FORMAT_VYUY: | |
c21f7904 VS |
1607 | if (modifier == DRM_FORMAT_MOD_LINEAR || |
1608 | modifier == I915_FORMAT_MOD_X_TILED) | |
1609 | return true; | |
1610 | /* fall through */ | |
1611 | default: | |
1612 | return false; | |
1613 | } | |
1614 | } | |
1615 | ||
a38189c5 VS |
1616 | static bool vlv_sprite_format_mod_supported(struct drm_plane *_plane, |
1617 | u32 format, u64 modifier) | |
c21f7904 | 1618 | { |
a38189c5 VS |
1619 | switch (modifier) { |
1620 | case DRM_FORMAT_MOD_LINEAR: | |
1621 | case I915_FORMAT_MOD_X_TILED: | |
1622 | break; | |
1623 | default: | |
1624 | return false; | |
1625 | } | |
1626 | ||
c21f7904 | 1627 | switch (format) { |
714244e2 | 1628 | case DRM_FORMAT_RGB565: |
c21f7904 | 1629 | case DRM_FORMAT_ABGR8888: |
714244e2 | 1630 | case DRM_FORMAT_ARGB8888: |
c21f7904 VS |
1631 | case DRM_FORMAT_XBGR8888: |
1632 | case DRM_FORMAT_XRGB8888: | |
714244e2 BW |
1633 | case DRM_FORMAT_XBGR2101010: |
1634 | case DRM_FORMAT_ABGR2101010: | |
c21f7904 VS |
1635 | case DRM_FORMAT_YUYV: |
1636 | case DRM_FORMAT_YVYU: | |
1637 | case DRM_FORMAT_UYVY: | |
1638 | case DRM_FORMAT_VYUY: | |
714244e2 BW |
1639 | if (modifier == DRM_FORMAT_MOD_LINEAR || |
1640 | modifier == I915_FORMAT_MOD_X_TILED) | |
1641 | return true; | |
1642 | /* fall through */ | |
1643 | default: | |
1644 | return false; | |
1645 | } | |
1646 | } | |
1647 | ||
a38189c5 VS |
1648 | static bool skl_plane_format_mod_supported(struct drm_plane *_plane, |
1649 | u32 format, u64 modifier) | |
714244e2 | 1650 | { |
a38189c5 VS |
1651 | struct intel_plane *plane = to_intel_plane(_plane); |
1652 | ||
1653 | switch (modifier) { | |
1654 | case DRM_FORMAT_MOD_LINEAR: | |
1655 | case I915_FORMAT_MOD_X_TILED: | |
1656 | case I915_FORMAT_MOD_Y_TILED: | |
1657 | case I915_FORMAT_MOD_Yf_TILED: | |
1658 | break; | |
1659 | case I915_FORMAT_MOD_Y_TILED_CCS: | |
1660 | case I915_FORMAT_MOD_Yf_TILED_CCS: | |
1661 | if (!plane->has_ccs) | |
1662 | return false; | |
1663 | break; | |
1664 | default: | |
1665 | return false; | |
1666 | } | |
1667 | ||
714244e2 BW |
1668 | switch (format) { |
1669 | case DRM_FORMAT_XRGB8888: | |
1670 | case DRM_FORMAT_XBGR8888: | |
1671 | case DRM_FORMAT_ARGB8888: | |
1672 | case DRM_FORMAT_ABGR8888: | |
63eaf9ac | 1673 | if (is_ccs_modifier(modifier)) |
77064e2e VS |
1674 | return true; |
1675 | /* fall through */ | |
714244e2 BW |
1676 | case DRM_FORMAT_RGB565: |
1677 | case DRM_FORMAT_XRGB2101010: | |
1678 | case DRM_FORMAT_XBGR2101010: | |
1679 | case DRM_FORMAT_YUYV: | |
1680 | case DRM_FORMAT_YVYU: | |
1681 | case DRM_FORMAT_UYVY: | |
1682 | case DRM_FORMAT_VYUY: | |
429204f1 | 1683 | case DRM_FORMAT_NV12: |
714244e2 BW |
1684 | if (modifier == I915_FORMAT_MOD_Yf_TILED) |
1685 | return true; | |
1686 | /* fall through */ | |
1687 | case DRM_FORMAT_C8: | |
1688 | if (modifier == DRM_FORMAT_MOD_LINEAR || | |
1689 | modifier == I915_FORMAT_MOD_X_TILED || | |
1690 | modifier == I915_FORMAT_MOD_Y_TILED) | |
1691 | return true; | |
1692 | /* fall through */ | |
1693 | default: | |
1694 | return false; | |
1695 | } | |
1696 | } | |
1697 | ||
a38189c5 VS |
1698 | static const struct drm_plane_funcs g4x_sprite_funcs = { |
1699 | .update_plane = drm_atomic_helper_update_plane, | |
1700 | .disable_plane = drm_atomic_helper_disable_plane, | |
1701 | .destroy = intel_plane_destroy, | |
1702 | .atomic_get_property = intel_plane_atomic_get_property, | |
1703 | .atomic_set_property = intel_plane_atomic_set_property, | |
1704 | .atomic_duplicate_state = intel_plane_duplicate_state, | |
1705 | .atomic_destroy_state = intel_plane_destroy_state, | |
1706 | .format_mod_supported = g4x_sprite_format_mod_supported, | |
1707 | }; | |
714244e2 | 1708 | |
a38189c5 VS |
1709 | static const struct drm_plane_funcs snb_sprite_funcs = { |
1710 | .update_plane = drm_atomic_helper_update_plane, | |
1711 | .disable_plane = drm_atomic_helper_disable_plane, | |
1712 | .destroy = intel_plane_destroy, | |
1713 | .atomic_get_property = intel_plane_atomic_get_property, | |
1714 | .atomic_set_property = intel_plane_atomic_set_property, | |
1715 | .atomic_duplicate_state = intel_plane_duplicate_state, | |
1716 | .atomic_destroy_state = intel_plane_destroy_state, | |
1717 | .format_mod_supported = snb_sprite_format_mod_supported, | |
1718 | }; | |
714244e2 | 1719 | |
a38189c5 VS |
1720 | static const struct drm_plane_funcs vlv_sprite_funcs = { |
1721 | .update_plane = drm_atomic_helper_update_plane, | |
1722 | .disable_plane = drm_atomic_helper_disable_plane, | |
1723 | .destroy = intel_plane_destroy, | |
1724 | .atomic_get_property = intel_plane_atomic_get_property, | |
1725 | .atomic_set_property = intel_plane_atomic_set_property, | |
1726 | .atomic_duplicate_state = intel_plane_duplicate_state, | |
1727 | .atomic_destroy_state = intel_plane_destroy_state, | |
1728 | .format_mod_supported = vlv_sprite_format_mod_supported, | |
1729 | }; | |
714244e2 | 1730 | |
a38189c5 | 1731 | static const struct drm_plane_funcs skl_plane_funcs = { |
b4686c48 VS |
1732 | .update_plane = drm_atomic_helper_update_plane, |
1733 | .disable_plane = drm_atomic_helper_disable_plane, | |
1734 | .destroy = intel_plane_destroy, | |
1735 | .atomic_get_property = intel_plane_atomic_get_property, | |
1736 | .atomic_set_property = intel_plane_atomic_set_property, | |
1737 | .atomic_duplicate_state = intel_plane_duplicate_state, | |
1738 | .atomic_destroy_state = intel_plane_destroy_state, | |
a38189c5 | 1739 | .format_mod_supported = skl_plane_format_mod_supported, |
714244e2 BW |
1740 | }; |
1741 | ||
77064e2e VS |
1742 | bool skl_plane_has_ccs(struct drm_i915_private *dev_priv, |
1743 | enum pipe pipe, enum plane_id plane_id) | |
1744 | { | |
1745 | if (plane_id == PLANE_CURSOR) | |
1746 | return false; | |
1747 | ||
1748 | if (INTEL_GEN(dev_priv) >= 10) | |
1749 | return true; | |
1750 | ||
1751 | if (IS_GEMINILAKE(dev_priv)) | |
1752 | return pipe != PIPE_C; | |
1753 | ||
1754 | return pipe != PIPE_C && | |
1755 | (plane_id == PLANE_PRIMARY || | |
1756 | plane_id == PLANE_SPRITE0); | |
1757 | } | |
1758 | ||
b079bd17 | 1759 | struct intel_plane * |
580503c7 VS |
1760 | intel_sprite_plane_create(struct drm_i915_private *dev_priv, |
1761 | enum pipe pipe, int plane) | |
b840d907 | 1762 | { |
fca0ce2a VS |
1763 | struct intel_plane *intel_plane = NULL; |
1764 | struct intel_plane_state *state = NULL; | |
a38189c5 | 1765 | const struct drm_plane_funcs *plane_funcs; |
b840d907 | 1766 | unsigned long possible_crtcs; |
d1686ae3 | 1767 | const uint32_t *plane_formats; |
714244e2 | 1768 | const uint64_t *modifiers; |
93ca7e00 | 1769 | unsigned int supported_rotations; |
d1686ae3 | 1770 | int num_plane_formats; |
b840d907 JB |
1771 | int ret; |
1772 | ||
b14c5679 | 1773 | intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL); |
fca0ce2a VS |
1774 | if (!intel_plane) { |
1775 | ret = -ENOMEM; | |
1776 | goto fail; | |
1777 | } | |
b840d907 | 1778 | |
8e7d688b MR |
1779 | state = intel_create_plane_state(&intel_plane->base); |
1780 | if (!state) { | |
fca0ce2a VS |
1781 | ret = -ENOMEM; |
1782 | goto fail; | |
ea2c67bb | 1783 | } |
8e7d688b | 1784 | intel_plane->base.state = &state->base; |
ea2c67bb | 1785 | |
77064e2e | 1786 | if (INTEL_GEN(dev_priv) >= 9) { |
714244e2 BW |
1787 | state->scaler_id = -1; |
1788 | ||
a38189c5 VS |
1789 | intel_plane->has_ccs = skl_plane_has_ccs(dev_priv, pipe, |
1790 | PLANE_SPRITE0 + plane); | |
1791 | ||
ddd5713d | 1792 | intel_plane->max_stride = skl_plane_max_stride; |
714244e2 BW |
1793 | intel_plane->update_plane = skl_update_plane; |
1794 | intel_plane->disable_plane = skl_disable_plane; | |
51f5a096 | 1795 | intel_plane->get_hw_state = skl_plane_get_hw_state; |
4e0b83a5 | 1796 | intel_plane->check_plane = skl_plane_check; |
714244e2 | 1797 | |
429204f1 CK |
1798 | if (skl_plane_has_planar(dev_priv, pipe, |
1799 | PLANE_SPRITE0 + plane)) { | |
1800 | plane_formats = skl_planar_formats; | |
1801 | num_plane_formats = ARRAY_SIZE(skl_planar_formats); | |
1802 | } else { | |
1803 | plane_formats = skl_plane_formats; | |
1804 | num_plane_formats = ARRAY_SIZE(skl_plane_formats); | |
1805 | } | |
d1686ae3 | 1806 | |
a38189c5 | 1807 | if (intel_plane->has_ccs) |
77064e2e VS |
1808 | modifiers = skl_plane_format_modifiers_ccs; |
1809 | else | |
1810 | modifiers = skl_plane_format_modifiers_noccs; | |
a38189c5 VS |
1811 | |
1812 | plane_funcs = &skl_plane_funcs; | |
1890ae64 | 1813 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
ddd5713d | 1814 | intel_plane->max_stride = i9xx_plane_max_stride; |
1890ae64 VS |
1815 | intel_plane->update_plane = vlv_update_plane; |
1816 | intel_plane->disable_plane = vlv_disable_plane; | |
51f5a096 | 1817 | intel_plane->get_hw_state = vlv_plane_get_hw_state; |
4e0b83a5 | 1818 | intel_plane->check_plane = vlv_sprite_check; |
d1686ae3 | 1819 | |
1890ae64 VS |
1820 | plane_formats = vlv_plane_formats; |
1821 | num_plane_formats = ARRAY_SIZE(vlv_plane_formats); | |
714244e2 | 1822 | modifiers = i9xx_plane_format_modifiers; |
a38189c5 VS |
1823 | |
1824 | plane_funcs = &vlv_sprite_funcs; | |
1890ae64 | 1825 | } else if (INTEL_GEN(dev_priv) >= 7) { |
ddd5713d | 1826 | intel_plane->max_stride = g4x_sprite_max_stride; |
1890ae64 VS |
1827 | intel_plane->update_plane = ivb_update_plane; |
1828 | intel_plane->disable_plane = ivb_disable_plane; | |
51f5a096 | 1829 | intel_plane->get_hw_state = ivb_plane_get_hw_state; |
4e0b83a5 | 1830 | intel_plane->check_plane = g4x_sprite_check; |
7f1f3851 | 1831 | |
1890ae64 VS |
1832 | plane_formats = snb_plane_formats; |
1833 | num_plane_formats = ARRAY_SIZE(snb_plane_formats); | |
714244e2 | 1834 | modifiers = i9xx_plane_format_modifiers; |
a38189c5 VS |
1835 | |
1836 | plane_funcs = &snb_sprite_funcs; | |
1890ae64 | 1837 | } else { |
ddd5713d | 1838 | intel_plane->max_stride = g4x_sprite_max_stride; |
ab33081a VS |
1839 | intel_plane->update_plane = g4x_update_plane; |
1840 | intel_plane->disable_plane = g4x_disable_plane; | |
51f5a096 | 1841 | intel_plane->get_hw_state = g4x_plane_get_hw_state; |
4e0b83a5 | 1842 | intel_plane->check_plane = g4x_sprite_check; |
7f1f3851 | 1843 | |
714244e2 | 1844 | modifiers = i9xx_plane_format_modifiers; |
1890ae64 | 1845 | if (IS_GEN6(dev_priv)) { |
7f1f3851 JB |
1846 | plane_formats = snb_plane_formats; |
1847 | num_plane_formats = ARRAY_SIZE(snb_plane_formats); | |
a38189c5 VS |
1848 | |
1849 | plane_funcs = &snb_sprite_funcs; | |
1890ae64 | 1850 | } else { |
ab33081a VS |
1851 | plane_formats = g4x_plane_formats; |
1852 | num_plane_formats = ARRAY_SIZE(g4x_plane_formats); | |
a38189c5 VS |
1853 | |
1854 | plane_funcs = &g4x_sprite_funcs; | |
7f1f3851 | 1855 | } |
b840d907 JB |
1856 | } |
1857 | ||
5481e27f | 1858 | if (INTEL_GEN(dev_priv) >= 9) { |
93ca7e00 | 1859 | supported_rotations = |
c2c446ad RF |
1860 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 | |
1861 | DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270; | |
4ea7be2b VS |
1862 | } else if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
1863 | supported_rotations = | |
c2c446ad RF |
1864 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 | |
1865 | DRM_MODE_REFLECT_X; | |
93ca7e00 VS |
1866 | } else { |
1867 | supported_rotations = | |
c2c446ad | 1868 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180; |
93ca7e00 VS |
1869 | } |
1870 | ||
b840d907 | 1871 | intel_plane->pipe = pipe; |
ed15030d | 1872 | intel_plane->i9xx_plane = plane; |
b14e5848 | 1873 | intel_plane->id = PLANE_SPRITE0 + plane; |
c19e1124 | 1874 | intel_plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, intel_plane->id); |
fca0ce2a | 1875 | |
b840d907 | 1876 | possible_crtcs = (1 << pipe); |
fca0ce2a | 1877 | |
1890ae64 | 1878 | if (INTEL_GEN(dev_priv) >= 9) |
580503c7 | 1879 | ret = drm_universal_plane_init(&dev_priv->drm, &intel_plane->base, |
a38189c5 | 1880 | possible_crtcs, plane_funcs, |
38573dc1 | 1881 | plane_formats, num_plane_formats, |
714244e2 BW |
1882 | modifiers, |
1883 | DRM_PLANE_TYPE_OVERLAY, | |
38573dc1 VS |
1884 | "plane %d%c", plane + 2, pipe_name(pipe)); |
1885 | else | |
580503c7 | 1886 | ret = drm_universal_plane_init(&dev_priv->drm, &intel_plane->base, |
a38189c5 | 1887 | possible_crtcs, plane_funcs, |
38573dc1 | 1888 | plane_formats, num_plane_formats, |
714244e2 BW |
1889 | modifiers, |
1890 | DRM_PLANE_TYPE_OVERLAY, | |
38573dc1 | 1891 | "sprite %c", sprite_name(pipe, plane)); |
fca0ce2a VS |
1892 | if (ret) |
1893 | goto fail; | |
7ed6eeee | 1894 | |
93ca7e00 | 1895 | drm_plane_create_rotation_property(&intel_plane->base, |
c2c446ad | 1896 | DRM_MODE_ROTATE_0, |
93ca7e00 | 1897 | supported_rotations); |
b840d907 | 1898 | |
b0f5c0ba VS |
1899 | drm_plane_create_color_properties(&intel_plane->base, |
1900 | BIT(DRM_COLOR_YCBCR_BT601) | | |
1901 | BIT(DRM_COLOR_YCBCR_BT709), | |
c8624ede VS |
1902 | BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) | |
1903 | BIT(DRM_COLOR_YCBCR_FULL_RANGE), | |
23b28089 | 1904 | DRM_COLOR_YCBCR_BT709, |
b0f5c0ba VS |
1905 | DRM_COLOR_YCBCR_LIMITED_RANGE); |
1906 | ||
ea2c67bb MR |
1907 | drm_plane_helper_add(&intel_plane->base, &intel_plane_helper_funcs); |
1908 | ||
b079bd17 | 1909 | return intel_plane; |
fca0ce2a VS |
1910 | |
1911 | fail: | |
1912 | kfree(state); | |
1913 | kfree(intel_plane); | |
1914 | ||
b079bd17 | 1915 | return ERR_PTR(ret); |
b840d907 | 1916 | } |