1e3adcf8fSFrançois Tigeot /*
2e3adcf8fSFrançois Tigeot * Copyright © 2011 Intel Corporation
3e3adcf8fSFrançois Tigeot *
4e3adcf8fSFrançois Tigeot * Permission is hereby granted, free of charge, to any person obtaining a
5e3adcf8fSFrançois Tigeot * copy of this software and associated documentation files (the "Software"),
6e3adcf8fSFrançois Tigeot * to deal in the Software without restriction, including without limitation
7e3adcf8fSFrançois Tigeot * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8e3adcf8fSFrançois Tigeot * and/or sell copies of the Software, and to permit persons to whom the
9e3adcf8fSFrançois Tigeot * Software is furnished to do so, subject to the following conditions:
10e3adcf8fSFrançois Tigeot *
11e3adcf8fSFrançois Tigeot * The above copyright notice and this permission notice (including the next
12e3adcf8fSFrançois Tigeot * paragraph) shall be included in all copies or substantial portions of the
13e3adcf8fSFrançois Tigeot * Software.
14e3adcf8fSFrançois Tigeot *
15e3adcf8fSFrançois Tigeot * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16e3adcf8fSFrançois Tigeot * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17e3adcf8fSFrançois Tigeot * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18e3adcf8fSFrançois Tigeot * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19e3adcf8fSFrançois Tigeot * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20e3adcf8fSFrançois Tigeot * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21e3adcf8fSFrançois Tigeot * SOFTWARE.
22e3adcf8fSFrançois Tigeot *
23e3adcf8fSFrançois Tigeot * Authors:
24e3adcf8fSFrançois Tigeot * Jesse Barnes <jbarnes@virtuousgeek.org>
25e3adcf8fSFrançois Tigeot *
26e3adcf8fSFrançois Tigeot * New plane/sprite handling.
27e3adcf8fSFrançois Tigeot *
28e3adcf8fSFrançois Tigeot * The older chips had a separate interface for programming plane related
29e3adcf8fSFrançois Tigeot * registers; newer ones are much simpler and we can use the new DRM plane
30e3adcf8fSFrançois Tigeot * support.
31e3adcf8fSFrançois Tigeot */
3218e26a6dSFrançois Tigeot #include <drm/drmP.h>
33*3f2dd94aSFrançois Tigeot #include <drm/drm_atomic_helper.h>
3418e26a6dSFrançois Tigeot #include <drm/drm_crtc.h>
3583b4b9b9SFrançois Tigeot #include <drm/drm_fourcc.h>
365d0b1887SFrançois Tigeot #include <drm/drm_rect.h>
3719c468b4SFrançois Tigeot #include <drm/drm_atomic.h>
382c9916cdSFrançois Tigeot #include <drm/drm_plane_helper.h>
3918e26a6dSFrançois Tigeot #include "intel_drv.h"
4071f41f3eSFrançois Tigeot #include "intel_frontbuffer.h"
415c6c6f23SFrançois Tigeot #include <drm/i915_drm.h>
42e3adcf8fSFrançois Tigeot #include "i915_drv.h"
43e3adcf8fSFrançois Tigeot
442c9916cdSFrançois Tigeot static bool
format_is_yuv(uint32_t format)452c9916cdSFrançois Tigeot format_is_yuv(uint32_t format)
462c9916cdSFrançois Tigeot {
472c9916cdSFrançois Tigeot switch (format) {
482c9916cdSFrançois Tigeot case DRM_FORMAT_YUYV:
492c9916cdSFrançois Tigeot case DRM_FORMAT_UYVY:
502c9916cdSFrançois Tigeot case DRM_FORMAT_VYUY:
512c9916cdSFrançois Tigeot case DRM_FORMAT_YVYU:
522c9916cdSFrançois Tigeot return true;
532c9916cdSFrançois Tigeot default:
542c9916cdSFrançois Tigeot return false;
552c9916cdSFrançois Tigeot }
562c9916cdSFrançois Tigeot }
572c9916cdSFrançois Tigeot
intel_usecs_to_scanlines(const struct drm_display_mode * adjusted_mode,int usecs)581e12ee3bSFrançois Tigeot int intel_usecs_to_scanlines(const struct drm_display_mode *adjusted_mode,
59352ff8bdSFrançois Tigeot int usecs)
60ba55f2f5SFrançois Tigeot {
61ba55f2f5SFrançois Tigeot /* paranoia */
62352ff8bdSFrançois Tigeot if (!adjusted_mode->crtc_htotal)
63ba55f2f5SFrançois Tigeot return 1;
64ba55f2f5SFrançois Tigeot
65352ff8bdSFrançois Tigeot return DIV_ROUND_UP(usecs * adjusted_mode->crtc_clock,
66352ff8bdSFrançois Tigeot 1000 * adjusted_mode->crtc_htotal);
67ba55f2f5SFrançois Tigeot }
68ba55f2f5SFrançois Tigeot
69*3f2dd94aSFrançois Tigeot /* FIXME: We should instead only take spinlocks once for the entire update
70*3f2dd94aSFrançois Tigeot * instead of once per mmio. */
71*3f2dd94aSFrançois Tigeot #if IS_ENABLED(CONFIG_PROVE_LOCKING)
72*3f2dd94aSFrançois Tigeot #define VBLANK_EVASION_TIME_US 250
73*3f2dd94aSFrançois Tigeot #else
74a85cb24fSFrançois Tigeot #define VBLANK_EVASION_TIME_US 100
75*3f2dd94aSFrançois Tigeot #endif
76a85cb24fSFrançois Tigeot
772c9916cdSFrançois Tigeot /**
782c9916cdSFrançois Tigeot * intel_pipe_update_start() - start update of a set of display registers
79*3f2dd94aSFrançois Tigeot * @new_crtc_state: the new crtc state
802c9916cdSFrançois Tigeot *
812c9916cdSFrançois Tigeot * Mark the start of an update to pipe registers that should be updated
822c9916cdSFrançois Tigeot * atomically regarding vblank. If the next vblank will happens within
832c9916cdSFrançois Tigeot * the next 100 us, this function waits until the vblank passes.
842c9916cdSFrançois Tigeot *
852c9916cdSFrançois Tigeot * After a successful call to this function, interrupts will be disabled
862c9916cdSFrançois Tigeot * until a subsequent call to intel_pipe_update_end(). That is done to
87*3f2dd94aSFrançois Tigeot * avoid random delays.
882c9916cdSFrançois Tigeot */
intel_pipe_update_start(const struct intel_crtc_state * new_crtc_state)89*3f2dd94aSFrançois Tigeot void intel_pipe_update_start(const struct intel_crtc_state *new_crtc_state)
90ba55f2f5SFrançois Tigeot {
91*3f2dd94aSFrançois Tigeot struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
92a85cb24fSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
93*3f2dd94aSFrançois Tigeot const struct drm_display_mode *adjusted_mode = &new_crtc_state->base.adjusted_mode;
94ba55f2f5SFrançois Tigeot long timeout = msecs_to_jiffies_timeout(1);
95ba55f2f5SFrançois Tigeot int scanline, min, max, vblank_start;
961b13d190SFrançois Tigeot wait_queue_head_t *wq = drm_crtc_vblank_waitqueue(&crtc->base);
97a85cb24fSFrançois Tigeot bool need_vlv_dsi_wa = (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
98*3f2dd94aSFrançois Tigeot intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI);
99ba55f2f5SFrançois Tigeot DEFINE_WAIT(wait);
100ba55f2f5SFrançois Tigeot
101352ff8bdSFrançois Tigeot vblank_start = adjusted_mode->crtc_vblank_start;
102352ff8bdSFrançois Tigeot if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
103ba55f2f5SFrançois Tigeot vblank_start = DIV_ROUND_UP(vblank_start, 2);
104ba55f2f5SFrançois Tigeot
105ba55f2f5SFrançois Tigeot /* FIXME needs to be calibrated sensibly */
106a85cb24fSFrançois Tigeot min = vblank_start - intel_usecs_to_scanlines(adjusted_mode,
107a85cb24fSFrançois Tigeot VBLANK_EVASION_TIME_US);
108ba55f2f5SFrançois Tigeot max = vblank_start - 1;
109ba55f2f5SFrançois Tigeot
110a05eeebfSFrançois Tigeot local_irq_disable();
111a05eeebfSFrançois Tigeot
112ba55f2f5SFrançois Tigeot if (min <= 0 || max <= 0)
113a05eeebfSFrançois Tigeot return;
114ba55f2f5SFrançois Tigeot
115477eb7f9SFrançois Tigeot if (WARN_ON(drm_crtc_vblank_get(&crtc->base)))
116a05eeebfSFrançois Tigeot return;
117ba55f2f5SFrançois Tigeot
118352ff8bdSFrançois Tigeot crtc->debug.min_vbl = min;
119352ff8bdSFrançois Tigeot crtc->debug.max_vbl = max;
120352ff8bdSFrançois Tigeot trace_i915_pipe_update_start(crtc);
121ba55f2f5SFrançois Tigeot
122ba55f2f5SFrançois Tigeot for (;;) {
123ba55f2f5SFrançois Tigeot /*
124ba55f2f5SFrançois Tigeot * prepare_to_wait() has a memory barrier, which guarantees
125ba55f2f5SFrançois Tigeot * other CPUs can see the task state update by the time we
126ba55f2f5SFrançois Tigeot * read the scanline.
127ba55f2f5SFrançois Tigeot */
1281b13d190SFrançois Tigeot prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
129ba55f2f5SFrançois Tigeot
130ba55f2f5SFrançois Tigeot scanline = intel_get_crtc_scanline(crtc);
131ba55f2f5SFrançois Tigeot if (scanline < min || scanline > max)
132ba55f2f5SFrançois Tigeot break;
133ba55f2f5SFrançois Tigeot
134ba55f2f5SFrançois Tigeot if (timeout <= 0) {
135ba55f2f5SFrançois Tigeot DRM_ERROR("Potential atomic update failure on pipe %c\n",
136ba55f2f5SFrançois Tigeot pipe_name(crtc->pipe));
137ba55f2f5SFrançois Tigeot break;
138ba55f2f5SFrançois Tigeot }
139ba55f2f5SFrançois Tigeot
140ba55f2f5SFrançois Tigeot local_irq_enable();
141ba55f2f5SFrançois Tigeot
142ba55f2f5SFrançois Tigeot timeout = schedule_timeout(timeout);
143ba55f2f5SFrançois Tigeot
144ba55f2f5SFrançois Tigeot local_irq_disable();
145ba55f2f5SFrançois Tigeot }
146ba55f2f5SFrançois Tigeot
1471b13d190SFrançois Tigeot finish_wait(wq, &wait);
148ba55f2f5SFrançois Tigeot
149477eb7f9SFrançois Tigeot drm_crtc_vblank_put(&crtc->base);
150ba55f2f5SFrançois Tigeot
151a85cb24fSFrançois Tigeot /*
152a85cb24fSFrançois Tigeot * On VLV/CHV DSI the scanline counter would appear to
153a85cb24fSFrançois Tigeot * increment approx. 1/3 of a scanline before start of vblank.
154a85cb24fSFrançois Tigeot * The registers still get latched at start of vblank however.
155a85cb24fSFrançois Tigeot * This means we must not write any registers on the first
156a85cb24fSFrançois Tigeot * line of vblank (since not the whole line is actually in
157a85cb24fSFrançois Tigeot * vblank). And unfortunately we can't use the interrupt to
158a85cb24fSFrançois Tigeot * wait here since it will fire too soon. We could use the
159a85cb24fSFrançois Tigeot * frame start interrupt instead since it will fire after the
160a85cb24fSFrançois Tigeot * critical scanline, but that would require more changes
161a85cb24fSFrançois Tigeot * in the interrupt code. So for now we'll just do the nasty
162a85cb24fSFrançois Tigeot * thing and poll for the bad scanline to pass us by.
163a85cb24fSFrançois Tigeot *
164a85cb24fSFrançois Tigeot * FIXME figure out if BXT+ DSI suffers from this as well
165a85cb24fSFrançois Tigeot */
166a85cb24fSFrançois Tigeot while (need_vlv_dsi_wa && scanline == vblank_start)
167a85cb24fSFrançois Tigeot scanline = intel_get_crtc_scanline(crtc);
168a85cb24fSFrançois Tigeot
169352ff8bdSFrançois Tigeot crtc->debug.scanline_start = scanline;
170352ff8bdSFrançois Tigeot crtc->debug.start_vbl_time = ktime_get();
1711487f786SFrançois Tigeot crtc->debug.start_vbl_count = intel_crtc_get_vblank_counter(crtc);
172ba55f2f5SFrançois Tigeot
173352ff8bdSFrançois Tigeot trace_i915_pipe_update_vblank_evaded(crtc);
174ba55f2f5SFrançois Tigeot }
175ba55f2f5SFrançois Tigeot
1762c9916cdSFrançois Tigeot /**
1772c9916cdSFrançois Tigeot * intel_pipe_update_end() - end update of a set of display registers
178*3f2dd94aSFrançois Tigeot * @new_crtc_state: the new crtc state
1792c9916cdSFrançois Tigeot *
1802c9916cdSFrançois Tigeot * Mark the end of an update started with intel_pipe_update_start(). This
1812c9916cdSFrançois Tigeot * re-enables interrupts and verifies the update was actually completed
182*3f2dd94aSFrançois Tigeot * before a vblank.
1832c9916cdSFrançois Tigeot */
intel_pipe_update_end(struct intel_crtc_state * new_crtc_state)184*3f2dd94aSFrançois Tigeot void intel_pipe_update_end(struct intel_crtc_state *new_crtc_state)
185ba55f2f5SFrançois Tigeot {
186*3f2dd94aSFrançois Tigeot struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
187ba55f2f5SFrançois Tigeot enum i915_pipe pipe = crtc->pipe;
188352ff8bdSFrançois Tigeot int scanline_end = intel_get_crtc_scanline(crtc);
1891487f786SFrançois Tigeot u32 end_vbl_count = intel_crtc_get_vblank_counter(crtc);
190352ff8bdSFrançois Tigeot ktime_t end_vbl_time = ktime_get();
191a85cb24fSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
192ba55f2f5SFrançois Tigeot
193352ff8bdSFrançois Tigeot trace_i915_pipe_update_end(crtc, end_vbl_count, scanline_end);
194ba55f2f5SFrançois Tigeot
1951487f786SFrançois Tigeot /* We're still in the vblank-evade critical section, this can't race.
1961487f786SFrançois Tigeot * Would be slightly nice to just grab the vblank count and arm the
1971487f786SFrançois Tigeot * event outside of the critical section - the spinlock might spin for a
1981487f786SFrançois Tigeot * while ... */
199*3f2dd94aSFrançois Tigeot if (new_crtc_state->base.event) {
2001487f786SFrançois Tigeot WARN_ON(drm_crtc_vblank_get(&crtc->base) != 0);
2011487f786SFrançois Tigeot
2021487f786SFrançois Tigeot lockmgr(&crtc->base.dev->event_lock, LK_EXCLUSIVE);
203*3f2dd94aSFrançois Tigeot drm_crtc_arm_vblank_event(&crtc->base, new_crtc_state->base.event);
2041487f786SFrançois Tigeot lockmgr(&crtc->base.dev->event_lock, LK_RELEASE);
2051487f786SFrançois Tigeot
206*3f2dd94aSFrançois Tigeot new_crtc_state->base.event = NULL;
2071487f786SFrançois Tigeot }
2081487f786SFrançois Tigeot
209ba55f2f5SFrançois Tigeot local_irq_enable();
210ba55f2f5SFrançois Tigeot
211a85cb24fSFrançois Tigeot if (intel_vgpu_active(dev_priv))
212a85cb24fSFrançois Tigeot return;
213a85cb24fSFrançois Tigeot
214352ff8bdSFrançois Tigeot if (crtc->debug.start_vbl_count &&
215352ff8bdSFrançois Tigeot crtc->debug.start_vbl_count != end_vbl_count) {
216352ff8bdSFrançois Tigeot 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",
217352ff8bdSFrançois Tigeot pipe_name(pipe), crtc->debug.start_vbl_count,
218352ff8bdSFrançois Tigeot end_vbl_count,
219352ff8bdSFrançois Tigeot ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time),
220352ff8bdSFrançois Tigeot crtc->debug.min_vbl, crtc->debug.max_vbl,
221352ff8bdSFrançois Tigeot crtc->debug.scanline_start, scanline_end);
222352ff8bdSFrançois Tigeot }
223a85cb24fSFrançois Tigeot #ifdef CONFIG_DRM_I915_DEBUG_VBLANK_EVADE
224a85cb24fSFrançois Tigeot else if (ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time) >
225a85cb24fSFrançois Tigeot VBLANK_EVASION_TIME_US)
226a85cb24fSFrançois Tigeot DRM_WARN("Atomic update on pipe (%c) took %lld us, max time under evasion is %u us\n",
227a85cb24fSFrançois Tigeot pipe_name(pipe),
228a85cb24fSFrançois Tigeot ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time),
229a85cb24fSFrançois Tigeot VBLANK_EVASION_TIME_US);
230a85cb24fSFrançois Tigeot #endif
231ba55f2f5SFrançois Tigeot }
232ba55f2f5SFrançois Tigeot
233*3f2dd94aSFrançois Tigeot void
skl_update_plane(struct intel_plane * plane,const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state)234*3f2dd94aSFrançois Tigeot skl_update_plane(struct intel_plane *plane,
235c0e85e96SFrançois Tigeot const struct intel_crtc_state *crtc_state,
236c0e85e96SFrançois Tigeot const struct intel_plane_state *plane_state)
2372c9916cdSFrançois Tigeot {
238*3f2dd94aSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
239*3f2dd94aSFrançois Tigeot const struct drm_framebuffer *fb = plane_state->base.fb;
240*3f2dd94aSFrançois Tigeot enum plane_id plane_id = plane->id;
241*3f2dd94aSFrançois Tigeot enum i915_pipe pipe = plane->pipe;
242a85cb24fSFrançois Tigeot u32 plane_ctl = plane_state->ctl;
243c0e85e96SFrançois Tigeot const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
2441e12ee3bSFrançois Tigeot u32 surf_addr = plane_state->main.offset;
2458621f407SFrançois Tigeot unsigned int rotation = plane_state->base.rotation;
2461e12ee3bSFrançois Tigeot u32 stride = skl_plane_stride(fb, 0, rotation);
247*3f2dd94aSFrançois Tigeot u32 aux_stride = skl_plane_stride(fb, 1, rotation);
2481e12ee3bSFrançois Tigeot int crtc_x = plane_state->base.dst.x1;
2491e12ee3bSFrançois Tigeot int crtc_y = plane_state->base.dst.y1;
2501e12ee3bSFrançois Tigeot uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
2511e12ee3bSFrançois Tigeot uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
2521e12ee3bSFrançois Tigeot uint32_t x = plane_state->main.x;
2531e12ee3bSFrançois Tigeot uint32_t y = plane_state->main.y;
2541e12ee3bSFrançois Tigeot uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
2551e12ee3bSFrançois Tigeot uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
256a85cb24fSFrançois Tigeot unsigned long irqflags;
257477eb7f9SFrançois Tigeot
2581e12ee3bSFrançois Tigeot /* Sizes are 0 based */
2591e12ee3bSFrançois Tigeot src_w--;
2601e12ee3bSFrançois Tigeot src_h--;
2611e12ee3bSFrançois Tigeot crtc_w--;
2621e12ee3bSFrançois Tigeot crtc_h--;
263477eb7f9SFrançois Tigeot
264a85cb24fSFrançois Tigeot spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
265a85cb24fSFrançois Tigeot
266*3f2dd94aSFrançois Tigeot if (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) {
267a85cb24fSFrançois Tigeot I915_WRITE_FW(PLANE_COLOR_CTL(pipe, plane_id),
268a85cb24fSFrançois Tigeot PLANE_COLOR_PIPE_GAMMA_ENABLE |
269a85cb24fSFrançois Tigeot PLANE_COLOR_PIPE_CSC_ENABLE |
270a85cb24fSFrançois Tigeot PLANE_COLOR_PLANE_GAMMA_DISABLE);
271a85cb24fSFrançois Tigeot }
272a85cb24fSFrançois Tigeot
273a85cb24fSFrançois Tigeot if (key->flags) {
274a85cb24fSFrançois Tigeot I915_WRITE_FW(PLANE_KEYVAL(pipe, plane_id), key->min_value);
275a85cb24fSFrançois Tigeot I915_WRITE_FW(PLANE_KEYMAX(pipe, plane_id), key->max_value);
276a85cb24fSFrançois Tigeot I915_WRITE_FW(PLANE_KEYMSK(pipe, plane_id), key->channel_mask);
277a85cb24fSFrançois Tigeot }
278a85cb24fSFrançois Tigeot
279a85cb24fSFrançois Tigeot I915_WRITE_FW(PLANE_OFFSET(pipe, plane_id), (y << 16) | x);
280a85cb24fSFrançois Tigeot I915_WRITE_FW(PLANE_STRIDE(pipe, plane_id), stride);
281a85cb24fSFrançois Tigeot I915_WRITE_FW(PLANE_SIZE(pipe, plane_id), (src_h << 16) | src_w);
282*3f2dd94aSFrançois Tigeot I915_WRITE_FW(PLANE_AUX_DIST(pipe, plane_id),
283*3f2dd94aSFrançois Tigeot (plane_state->aux.offset - surf_addr) | aux_stride);
284*3f2dd94aSFrançois Tigeot I915_WRITE_FW(PLANE_AUX_OFFSET(pipe, plane_id),
285*3f2dd94aSFrançois Tigeot (plane_state->aux.y << 16) | plane_state->aux.x);
28619c468b4SFrançois Tigeot
28719c468b4SFrançois Tigeot /* program plane scaler */
288c0e85e96SFrançois Tigeot if (plane_state->scaler_id >= 0) {
289c0e85e96SFrançois Tigeot int scaler_id = plane_state->scaler_id;
2901487f786SFrançois Tigeot const struct intel_scaler *scaler;
29119c468b4SFrançois Tigeot
2921487f786SFrançois Tigeot scaler = &crtc_state->scaler_state.scalers[scaler_id];
2931487f786SFrançois Tigeot
294a85cb24fSFrançois Tigeot I915_WRITE_FW(SKL_PS_CTRL(pipe, scaler_id),
295a85cb24fSFrançois Tigeot PS_SCALER_EN | PS_PLANE_SEL(plane_id) | scaler->mode);
296a85cb24fSFrançois Tigeot I915_WRITE_FW(SKL_PS_PWR_GATE(pipe, scaler_id), 0);
297a85cb24fSFrançois Tigeot I915_WRITE_FW(SKL_PS_WIN_POS(pipe, scaler_id), (crtc_x << 16) | crtc_y);
298a85cb24fSFrançois Tigeot I915_WRITE_FW(SKL_PS_WIN_SZ(pipe, scaler_id),
29919c468b4SFrançois Tigeot ((crtc_w + 1) << 16)|(crtc_h + 1));
30019c468b4SFrançois Tigeot
301a85cb24fSFrançois Tigeot I915_WRITE_FW(PLANE_POS(pipe, plane_id), 0);
30219c468b4SFrançois Tigeot } else {
303a85cb24fSFrançois Tigeot I915_WRITE_FW(PLANE_POS(pipe, plane_id), (crtc_y << 16) | crtc_x);
30419c468b4SFrançois Tigeot }
30519c468b4SFrançois Tigeot
306a85cb24fSFrançois Tigeot I915_WRITE_FW(PLANE_CTL(pipe, plane_id), plane_ctl);
307a85cb24fSFrançois Tigeot I915_WRITE_FW(PLANE_SURF(pipe, plane_id),
3084be47400SFrançois Tigeot intel_plane_ggtt_offset(plane_state) + surf_addr);
309a85cb24fSFrançois Tigeot POSTING_READ_FW(PLANE_SURF(pipe, plane_id));
310a85cb24fSFrançois Tigeot
311a85cb24fSFrançois Tigeot spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3122c9916cdSFrançois Tigeot }
3132c9916cdSFrançois Tigeot
314*3f2dd94aSFrançois Tigeot void
skl_disable_plane(struct intel_plane * plane,struct intel_crtc * crtc)315*3f2dd94aSFrançois Tigeot skl_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
3162c9916cdSFrançois Tigeot {
317*3f2dd94aSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
318*3f2dd94aSFrançois Tigeot enum plane_id plane_id = plane->id;
319*3f2dd94aSFrançois Tigeot enum i915_pipe pipe = plane->pipe;
320a85cb24fSFrançois Tigeot unsigned long irqflags;
3212c9916cdSFrançois Tigeot
322a85cb24fSFrançois Tigeot spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3232c9916cdSFrançois Tigeot
324a85cb24fSFrançois Tigeot I915_WRITE_FW(PLANE_CTL(pipe, plane_id), 0);
325a85cb24fSFrançois Tigeot
326a85cb24fSFrançois Tigeot I915_WRITE_FW(PLANE_SURF(pipe, plane_id), 0);
327a85cb24fSFrançois Tigeot POSTING_READ_FW(PLANE_SURF(pipe, plane_id));
328a85cb24fSFrançois Tigeot
329a85cb24fSFrançois Tigeot spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3302c9916cdSFrançois Tigeot }
3312c9916cdSFrançois Tigeot
332*3f2dd94aSFrançois Tigeot bool
skl_plane_get_hw_state(struct intel_plane * plane)333*3f2dd94aSFrançois Tigeot skl_plane_get_hw_state(struct intel_plane *plane)
3342c9916cdSFrançois Tigeot {
335*3f2dd94aSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
336*3f2dd94aSFrançois Tigeot enum intel_display_power_domain power_domain;
337*3f2dd94aSFrançois Tigeot enum plane_id plane_id = plane->id;
338*3f2dd94aSFrançois Tigeot enum i915_pipe pipe = plane->pipe;
339*3f2dd94aSFrançois Tigeot bool ret;
340*3f2dd94aSFrançois Tigeot
341*3f2dd94aSFrançois Tigeot power_domain = POWER_DOMAIN_PIPE(pipe);
342*3f2dd94aSFrançois Tigeot if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
343*3f2dd94aSFrançois Tigeot return false;
344*3f2dd94aSFrançois Tigeot
345*3f2dd94aSFrançois Tigeot ret = I915_READ(PLANE_CTL(pipe, plane_id)) & PLANE_CTL_ENABLE;
346*3f2dd94aSFrançois Tigeot
347*3f2dd94aSFrançois Tigeot intel_display_power_put(dev_priv, power_domain);
348*3f2dd94aSFrançois Tigeot
349*3f2dd94aSFrançois Tigeot return ret;
350*3f2dd94aSFrançois Tigeot }
351*3f2dd94aSFrançois Tigeot
352*3f2dd94aSFrançois Tigeot static void
chv_update_csc(struct intel_plane * plane,uint32_t format)353*3f2dd94aSFrançois Tigeot chv_update_csc(struct intel_plane *plane, uint32_t format)
354*3f2dd94aSFrançois Tigeot {
355*3f2dd94aSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
356*3f2dd94aSFrançois Tigeot enum plane_id plane_id = plane->id;
3572c9916cdSFrançois Tigeot
3582c9916cdSFrançois Tigeot /* Seems RGB data bypasses the CSC always */
3592c9916cdSFrançois Tigeot if (!format_is_yuv(format))
3602c9916cdSFrançois Tigeot return;
3612c9916cdSFrançois Tigeot
3622c9916cdSFrançois Tigeot /*
3632c9916cdSFrançois Tigeot * BT.601 limited range YCbCr -> full range RGB
3642c9916cdSFrançois Tigeot *
3652c9916cdSFrançois Tigeot * |r| | 6537 4769 0| |cr |
3662c9916cdSFrançois Tigeot * |g| = |-3330 4769 -1605| x |y-64|
3672c9916cdSFrançois Tigeot * |b| | 0 4769 8263| |cb |
3682c9916cdSFrançois Tigeot *
3692c9916cdSFrançois Tigeot * Cb and Cr apparently come in as signed already, so no
3702c9916cdSFrançois Tigeot * need for any offset. For Y we need to remove the offset.
3712c9916cdSFrançois Tigeot */
372a85cb24fSFrançois Tigeot I915_WRITE_FW(SPCSCYGOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(-64));
373a85cb24fSFrançois Tigeot I915_WRITE_FW(SPCSCCBOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
374a85cb24fSFrançois Tigeot I915_WRITE_FW(SPCSCCROFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
3752c9916cdSFrançois Tigeot
376a85cb24fSFrançois Tigeot I915_WRITE_FW(SPCSCC01(plane_id), SPCSC_C1(4769) | SPCSC_C0(6537));
377a85cb24fSFrançois Tigeot I915_WRITE_FW(SPCSCC23(plane_id), SPCSC_C1(-3330) | SPCSC_C0(0));
378a85cb24fSFrançois Tigeot I915_WRITE_FW(SPCSCC45(plane_id), SPCSC_C1(-1605) | SPCSC_C0(4769));
379a85cb24fSFrançois Tigeot I915_WRITE_FW(SPCSCC67(plane_id), SPCSC_C1(4769) | SPCSC_C0(0));
380a85cb24fSFrançois Tigeot I915_WRITE_FW(SPCSCC8(plane_id), SPCSC_C0(8263));
3812c9916cdSFrançois Tigeot
382a85cb24fSFrançois Tigeot I915_WRITE_FW(SPCSCYGICLAMP(plane_id), SPCSC_IMAX(940) | SPCSC_IMIN(64));
383a85cb24fSFrançois Tigeot I915_WRITE_FW(SPCSCCBICLAMP(plane_id), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
384a85cb24fSFrançois Tigeot I915_WRITE_FW(SPCSCCRICLAMP(plane_id), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
3852c9916cdSFrançois Tigeot
386a85cb24fSFrançois Tigeot I915_WRITE_FW(SPCSCYGOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
387a85cb24fSFrançois Tigeot I915_WRITE_FW(SPCSCCBOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
388a85cb24fSFrançois Tigeot I915_WRITE_FW(SPCSCCROCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
3892c9916cdSFrançois Tigeot }
3902c9916cdSFrançois Tigeot
vlv_sprite_ctl(const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state)391a85cb24fSFrançois Tigeot static u32 vlv_sprite_ctl(const struct intel_crtc_state *crtc_state,
392c0e85e96SFrançois Tigeot const struct intel_plane_state *plane_state)
3938e26cdf6SFrançois Tigeot {
394a85cb24fSFrançois Tigeot const struct drm_framebuffer *fb = plane_state->base.fb;
395a85cb24fSFrançois Tigeot unsigned int rotation = plane_state->base.rotation;
396c0e85e96SFrançois Tigeot const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
397a85cb24fSFrançois Tigeot u32 sprctl;
3988e26cdf6SFrançois Tigeot
399a85cb24fSFrançois Tigeot sprctl = SP_ENABLE | SP_GAMMA_ENABLE;
4008e26cdf6SFrançois Tigeot
401a85cb24fSFrançois Tigeot switch (fb->format->format) {
4028e26cdf6SFrançois Tigeot case DRM_FORMAT_YUYV:
4038e26cdf6SFrançois Tigeot sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
4048e26cdf6SFrançois Tigeot break;
4058e26cdf6SFrançois Tigeot case DRM_FORMAT_YVYU:
4068e26cdf6SFrançois Tigeot sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
4078e26cdf6SFrançois Tigeot break;
4088e26cdf6SFrançois Tigeot case DRM_FORMAT_UYVY:
4098e26cdf6SFrançois Tigeot sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
4108e26cdf6SFrançois Tigeot break;
4118e26cdf6SFrançois Tigeot case DRM_FORMAT_VYUY:
4128e26cdf6SFrançois Tigeot sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
4138e26cdf6SFrançois Tigeot break;
4148e26cdf6SFrançois Tigeot case DRM_FORMAT_RGB565:
4158e26cdf6SFrançois Tigeot sprctl |= SP_FORMAT_BGR565;
4168e26cdf6SFrançois Tigeot break;
4178e26cdf6SFrançois Tigeot case DRM_FORMAT_XRGB8888:
4188e26cdf6SFrançois Tigeot sprctl |= SP_FORMAT_BGRX8888;
4198e26cdf6SFrançois Tigeot break;
4208e26cdf6SFrançois Tigeot case DRM_FORMAT_ARGB8888:
4218e26cdf6SFrançois Tigeot sprctl |= SP_FORMAT_BGRA8888;
4228e26cdf6SFrançois Tigeot break;
4238e26cdf6SFrançois Tigeot case DRM_FORMAT_XBGR2101010:
4248e26cdf6SFrançois Tigeot sprctl |= SP_FORMAT_RGBX1010102;
4258e26cdf6SFrançois Tigeot break;
4268e26cdf6SFrançois Tigeot case DRM_FORMAT_ABGR2101010:
4278e26cdf6SFrançois Tigeot sprctl |= SP_FORMAT_RGBA1010102;
4288e26cdf6SFrançois Tigeot break;
4298e26cdf6SFrançois Tigeot case DRM_FORMAT_XBGR8888:
4308e26cdf6SFrançois Tigeot sprctl |= SP_FORMAT_RGBX8888;
4318e26cdf6SFrançois Tigeot break;
4328e26cdf6SFrançois Tigeot case DRM_FORMAT_ABGR8888:
4338e26cdf6SFrançois Tigeot sprctl |= SP_FORMAT_RGBA8888;
4348e26cdf6SFrançois Tigeot break;
4358e26cdf6SFrançois Tigeot default:
436a85cb24fSFrançois Tigeot MISSING_CASE(fb->format->format);
437a85cb24fSFrançois Tigeot return 0;
4388e26cdf6SFrançois Tigeot }
4398e26cdf6SFrançois Tigeot
4404be47400SFrançois Tigeot if (fb->modifier == I915_FORMAT_MOD_X_TILED)
4418e26cdf6SFrançois Tigeot sprctl |= SP_TILED;
4428e26cdf6SFrançois Tigeot
443*3f2dd94aSFrançois Tigeot if (rotation & DRM_MODE_ROTATE_180)
4444be47400SFrançois Tigeot sprctl |= SP_ROTATE_180;
4454be47400SFrançois Tigeot
446*3f2dd94aSFrançois Tigeot if (rotation & DRM_MODE_REFLECT_X)
4474be47400SFrançois Tigeot sprctl |= SP_MIRROR;
4484be47400SFrançois Tigeot
449477eb7f9SFrançois Tigeot if (key->flags & I915_SET_COLORKEY_SOURCE)
450477eb7f9SFrançois Tigeot sprctl |= SP_SOURCE_KEY;
451477eb7f9SFrançois Tigeot
452a85cb24fSFrançois Tigeot return sprctl;
453a85cb24fSFrançois Tigeot }
4542c9916cdSFrançois Tigeot
455a85cb24fSFrançois Tigeot static void
vlv_update_plane(struct intel_plane * plane,const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state)456*3f2dd94aSFrançois Tigeot vlv_update_plane(struct intel_plane *plane,
457a85cb24fSFrançois Tigeot const struct intel_crtc_state *crtc_state,
458a85cb24fSFrançois Tigeot const struct intel_plane_state *plane_state)
459a85cb24fSFrançois Tigeot {
460*3f2dd94aSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
461*3f2dd94aSFrançois Tigeot const struct drm_framebuffer *fb = plane_state->base.fb;
462*3f2dd94aSFrançois Tigeot enum i915_pipe pipe = plane->pipe;
463*3f2dd94aSFrançois Tigeot enum plane_id plane_id = plane->id;
464a85cb24fSFrançois Tigeot u32 sprctl = plane_state->ctl;
465a85cb24fSFrançois Tigeot u32 sprsurf_offset = plane_state->main.offset;
466a85cb24fSFrançois Tigeot u32 linear_offset;
467a85cb24fSFrançois Tigeot const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
468a85cb24fSFrançois Tigeot int crtc_x = plane_state->base.dst.x1;
469a85cb24fSFrançois Tigeot int crtc_y = plane_state->base.dst.y1;
470a85cb24fSFrançois Tigeot uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
471a85cb24fSFrançois Tigeot uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
472a85cb24fSFrançois Tigeot uint32_t x = plane_state->main.x;
473a85cb24fSFrançois Tigeot uint32_t y = plane_state->main.y;
474a85cb24fSFrançois Tigeot unsigned long irqflags;
475a85cb24fSFrançois Tigeot
476a85cb24fSFrançois Tigeot /* Sizes are 0 based */
477a85cb24fSFrançois Tigeot crtc_w--;
478a85cb24fSFrançois Tigeot crtc_h--;
479a85cb24fSFrançois Tigeot
480a85cb24fSFrançois Tigeot linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
481a85cb24fSFrançois Tigeot
482a85cb24fSFrançois Tigeot spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
483a85cb24fSFrançois Tigeot
484a85cb24fSFrançois Tigeot if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B)
485*3f2dd94aSFrançois Tigeot chv_update_csc(plane, fb->format->format);
486a85cb24fSFrançois Tigeot
487a85cb24fSFrançois Tigeot if (key->flags) {
488a85cb24fSFrançois Tigeot I915_WRITE_FW(SPKEYMINVAL(pipe, plane_id), key->min_value);
489a85cb24fSFrançois Tigeot I915_WRITE_FW(SPKEYMAXVAL(pipe, plane_id), key->max_value);
490a85cb24fSFrançois Tigeot I915_WRITE_FW(SPKEYMSK(pipe, plane_id), key->channel_mask);
491a85cb24fSFrançois Tigeot }
492a85cb24fSFrançois Tigeot I915_WRITE_FW(SPSTRIDE(pipe, plane_id), fb->pitches[0]);
493a85cb24fSFrançois Tigeot I915_WRITE_FW(SPPOS(pipe, plane_id), (crtc_y << 16) | crtc_x);
494ba55f2f5SFrançois Tigeot
4954be47400SFrançois Tigeot if (fb->modifier == I915_FORMAT_MOD_X_TILED)
496a85cb24fSFrançois Tigeot I915_WRITE_FW(SPTILEOFF(pipe, plane_id), (y << 16) | x);
4978e26cdf6SFrançois Tigeot else
498a85cb24fSFrançois Tigeot I915_WRITE_FW(SPLINOFF(pipe, plane_id), linear_offset);
4998e26cdf6SFrançois Tigeot
500a85cb24fSFrançois Tigeot I915_WRITE_FW(SPCONSTALPHA(pipe, plane_id), 0);
5012c9916cdSFrançois Tigeot
502a85cb24fSFrançois Tigeot I915_WRITE_FW(SPSIZE(pipe, plane_id), (crtc_h << 16) | crtc_w);
503a85cb24fSFrançois Tigeot I915_WRITE_FW(SPCNTR(pipe, plane_id), sprctl);
504a85cb24fSFrançois Tigeot I915_WRITE_FW(SPSURF(pipe, plane_id),
5054be47400SFrançois Tigeot intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
506a85cb24fSFrançois Tigeot POSTING_READ_FW(SPSURF(pipe, plane_id));
507a85cb24fSFrançois Tigeot
508a85cb24fSFrançois Tigeot spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
5098e26cdf6SFrançois Tigeot }
5108e26cdf6SFrançois Tigeot
5118e26cdf6SFrançois Tigeot static void
vlv_disable_plane(struct intel_plane * plane,struct intel_crtc * crtc)512*3f2dd94aSFrançois Tigeot vlv_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
5138e26cdf6SFrançois Tigeot {
514*3f2dd94aSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
515*3f2dd94aSFrançois Tigeot enum i915_pipe pipe = plane->pipe;
516*3f2dd94aSFrançois Tigeot enum plane_id plane_id = plane->id;
517a85cb24fSFrançois Tigeot unsigned long irqflags;
518ba55f2f5SFrançois Tigeot
519a85cb24fSFrançois Tigeot spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
520477eb7f9SFrançois Tigeot
521a85cb24fSFrançois Tigeot I915_WRITE_FW(SPCNTR(pipe, plane_id), 0);
522a85cb24fSFrançois Tigeot
523a85cb24fSFrançois Tigeot I915_WRITE_FW(SPSURF(pipe, plane_id), 0);
524a85cb24fSFrançois Tigeot POSTING_READ_FW(SPSURF(pipe, plane_id));
525a85cb24fSFrançois Tigeot
526a85cb24fSFrançois Tigeot spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
5278e26cdf6SFrançois Tigeot }
5288e26cdf6SFrançois Tigeot
529*3f2dd94aSFrançois Tigeot static bool
vlv_plane_get_hw_state(struct intel_plane * plane)530*3f2dd94aSFrançois Tigeot vlv_plane_get_hw_state(struct intel_plane *plane)
531*3f2dd94aSFrançois Tigeot {
532*3f2dd94aSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
533*3f2dd94aSFrançois Tigeot enum intel_display_power_domain power_domain;
534*3f2dd94aSFrançois Tigeot enum plane_id plane_id = plane->id;
535*3f2dd94aSFrançois Tigeot enum i915_pipe pipe = plane->pipe;
536*3f2dd94aSFrançois Tigeot bool ret;
537*3f2dd94aSFrançois Tigeot
538*3f2dd94aSFrançois Tigeot power_domain = POWER_DOMAIN_PIPE(pipe);
539*3f2dd94aSFrançois Tigeot if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
540*3f2dd94aSFrançois Tigeot return false;
541*3f2dd94aSFrançois Tigeot
542*3f2dd94aSFrançois Tigeot ret = I915_READ(SPCNTR(pipe, plane_id)) & SP_ENABLE;
543*3f2dd94aSFrançois Tigeot
544*3f2dd94aSFrançois Tigeot intel_display_power_put(dev_priv, power_domain);
545*3f2dd94aSFrançois Tigeot
546*3f2dd94aSFrançois Tigeot return ret;
547*3f2dd94aSFrançois Tigeot }
548*3f2dd94aSFrançois Tigeot
ivb_sprite_ctl(const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state)549a85cb24fSFrançois Tigeot static u32 ivb_sprite_ctl(const struct intel_crtc_state *crtc_state,
550c0e85e96SFrançois Tigeot const struct intel_plane_state *plane_state)
551e3adcf8fSFrançois Tigeot {
552a85cb24fSFrançois Tigeot struct drm_i915_private *dev_priv =
553a85cb24fSFrançois Tigeot to_i915(plane_state->base.plane->dev);
554a85cb24fSFrançois Tigeot const struct drm_framebuffer *fb = plane_state->base.fb;
5558621f407SFrançois Tigeot unsigned int rotation = plane_state->base.rotation;
556c0e85e96SFrançois Tigeot const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
557a85cb24fSFrançois Tigeot u32 sprctl;
558e3adcf8fSFrançois Tigeot
559a85cb24fSFrançois Tigeot sprctl = SPRITE_ENABLE | SPRITE_GAMMA_ENABLE;
560e3adcf8fSFrançois Tigeot
561a85cb24fSFrançois Tigeot if (IS_IVYBRIDGE(dev_priv))
562a85cb24fSFrançois Tigeot sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
563a85cb24fSFrançois Tigeot
564a85cb24fSFrançois Tigeot if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
565a85cb24fSFrançois Tigeot sprctl |= SPRITE_PIPE_CSC_ENABLE;
566a85cb24fSFrançois Tigeot
567a85cb24fSFrançois Tigeot switch (fb->format->format) {
568e3adcf8fSFrançois Tigeot case DRM_FORMAT_XBGR8888:
5692c84b0b6SFrançois Tigeot sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
570e3adcf8fSFrançois Tigeot break;
571e3adcf8fSFrançois Tigeot case DRM_FORMAT_XRGB8888:
5722c84b0b6SFrançois Tigeot sprctl |= SPRITE_FORMAT_RGBX888;
573e3adcf8fSFrançois Tigeot break;
574e3adcf8fSFrançois Tigeot case DRM_FORMAT_YUYV:
575e3adcf8fSFrançois Tigeot sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
576e3adcf8fSFrançois Tigeot break;
577e3adcf8fSFrançois Tigeot case DRM_FORMAT_YVYU:
578e3adcf8fSFrançois Tigeot sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
579e3adcf8fSFrançois Tigeot break;
580e3adcf8fSFrançois Tigeot case DRM_FORMAT_UYVY:
581e3adcf8fSFrançois Tigeot sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
582e3adcf8fSFrançois Tigeot break;
583e3adcf8fSFrançois Tigeot case DRM_FORMAT_VYUY:
584e3adcf8fSFrançois Tigeot sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
585e3adcf8fSFrançois Tigeot break;
586e3adcf8fSFrançois Tigeot default:
587a85cb24fSFrançois Tigeot MISSING_CASE(fb->format->format);
588a85cb24fSFrançois Tigeot return 0;
589e3adcf8fSFrançois Tigeot }
590e3adcf8fSFrançois Tigeot
5914be47400SFrançois Tigeot if (fb->modifier == I915_FORMAT_MOD_X_TILED)
592e3adcf8fSFrançois Tigeot sprctl |= SPRITE_TILED;
593e3adcf8fSFrançois Tigeot
594*3f2dd94aSFrançois Tigeot if (rotation & DRM_MODE_ROTATE_180)
5954be47400SFrançois Tigeot sprctl |= SPRITE_ROTATE_180;
5964be47400SFrançois Tigeot
597a85cb24fSFrançois Tigeot if (key->flags & I915_SET_COLORKEY_DESTINATION)
598a85cb24fSFrançois Tigeot sprctl |= SPRITE_DEST_KEY;
599a85cb24fSFrançois Tigeot else if (key->flags & I915_SET_COLORKEY_SOURCE)
600a85cb24fSFrançois Tigeot sprctl |= SPRITE_SOURCE_KEY;
6019edbd4a0SFrançois Tigeot
602a85cb24fSFrançois Tigeot return sprctl;
603a85cb24fSFrançois Tigeot }
604a85cb24fSFrançois Tigeot
605a85cb24fSFrançois Tigeot static void
ivb_update_plane(struct intel_plane * plane,const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state)606*3f2dd94aSFrançois Tigeot ivb_update_plane(struct intel_plane *plane,
607a85cb24fSFrançois Tigeot const struct intel_crtc_state *crtc_state,
608a85cb24fSFrançois Tigeot const struct intel_plane_state *plane_state)
609a85cb24fSFrançois Tigeot {
610*3f2dd94aSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
611*3f2dd94aSFrançois Tigeot const struct drm_framebuffer *fb = plane_state->base.fb;
612*3f2dd94aSFrançois Tigeot enum i915_pipe pipe = plane->pipe;
613a85cb24fSFrançois Tigeot u32 sprctl = plane_state->ctl, sprscale = 0;
614a85cb24fSFrançois Tigeot u32 sprsurf_offset = plane_state->main.offset;
615a85cb24fSFrançois Tigeot u32 linear_offset;
616a85cb24fSFrançois Tigeot const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
617a85cb24fSFrançois Tigeot int crtc_x = plane_state->base.dst.x1;
618a85cb24fSFrançois Tigeot int crtc_y = plane_state->base.dst.y1;
619a85cb24fSFrançois Tigeot uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
620a85cb24fSFrançois Tigeot uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
621a85cb24fSFrançois Tigeot uint32_t x = plane_state->main.x;
622a85cb24fSFrançois Tigeot uint32_t y = plane_state->main.y;
623a85cb24fSFrançois Tigeot uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
624a85cb24fSFrançois Tigeot uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
625a85cb24fSFrançois Tigeot unsigned long irqflags;
626a2fdbec6SFrançois Tigeot
627e3adcf8fSFrançois Tigeot /* Sizes are 0 based */
628e3adcf8fSFrançois Tigeot src_w--;
629e3adcf8fSFrançois Tigeot src_h--;
630e3adcf8fSFrançois Tigeot crtc_w--;
631e3adcf8fSFrançois Tigeot crtc_h--;
632e3adcf8fSFrançois Tigeot
6339edbd4a0SFrançois Tigeot if (crtc_w != src_w || crtc_h != src_h)
634e3adcf8fSFrançois Tigeot sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
635e3adcf8fSFrançois Tigeot
6361e12ee3bSFrançois Tigeot linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
6371e12ee3bSFrançois Tigeot
638a85cb24fSFrançois Tigeot spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
639a85cb24fSFrançois Tigeot
640477eb7f9SFrançois Tigeot if (key->flags) {
641a85cb24fSFrançois Tigeot I915_WRITE_FW(SPRKEYVAL(pipe), key->min_value);
642a85cb24fSFrançois Tigeot I915_WRITE_FW(SPRKEYMAX(pipe), key->max_value);
643a85cb24fSFrançois Tigeot I915_WRITE_FW(SPRKEYMSK(pipe), key->channel_mask);
644477eb7f9SFrançois Tigeot }
645477eb7f9SFrançois Tigeot
646a85cb24fSFrançois Tigeot I915_WRITE_FW(SPRSTRIDE(pipe), fb->pitches[0]);
647a85cb24fSFrançois Tigeot I915_WRITE_FW(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
648ba55f2f5SFrançois Tigeot
6492c84b0b6SFrançois Tigeot /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
6502c84b0b6SFrançois Tigeot * register */
6511e12ee3bSFrançois Tigeot if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
652a85cb24fSFrançois Tigeot I915_WRITE_FW(SPROFFSET(pipe), (y << 16) | x);
6534be47400SFrançois Tigeot else if (fb->modifier == I915_FORMAT_MOD_X_TILED)
654a85cb24fSFrançois Tigeot I915_WRITE_FW(SPRTILEOFF(pipe), (y << 16) | x);
6552c84b0b6SFrançois Tigeot else
656a85cb24fSFrançois Tigeot I915_WRITE_FW(SPRLINOFF(pipe), linear_offset);
6572c84b0b6SFrançois Tigeot
658a85cb24fSFrançois Tigeot I915_WRITE_FW(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
659*3f2dd94aSFrançois Tigeot if (plane->can_scale)
660a85cb24fSFrançois Tigeot I915_WRITE_FW(SPRSCALE(pipe), sprscale);
661a85cb24fSFrançois Tigeot I915_WRITE_FW(SPRCTL(pipe), sprctl);
662a85cb24fSFrançois Tigeot I915_WRITE_FW(SPRSURF(pipe),
6634be47400SFrançois Tigeot intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
664a85cb24fSFrançois Tigeot POSTING_READ_FW(SPRSURF(pipe));
665a85cb24fSFrançois Tigeot
666a85cb24fSFrançois Tigeot spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
667e3adcf8fSFrançois Tigeot }
668e3adcf8fSFrançois Tigeot
669e3adcf8fSFrançois Tigeot static void
ivb_disable_plane(struct intel_plane * plane,struct intel_crtc * crtc)670*3f2dd94aSFrançois Tigeot ivb_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
671e3adcf8fSFrançois Tigeot {
672*3f2dd94aSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
673*3f2dd94aSFrançois Tigeot enum i915_pipe pipe = plane->pipe;
674a85cb24fSFrançois Tigeot unsigned long irqflags;
675ba55f2f5SFrançois Tigeot
676a85cb24fSFrançois Tigeot spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
677a85cb24fSFrançois Tigeot
678a85cb24fSFrançois Tigeot I915_WRITE_FW(SPRCTL(pipe), 0);
679e3adcf8fSFrançois Tigeot /* Can't leave the scaler enabled... */
680*3f2dd94aSFrançois Tigeot if (plane->can_scale)
681a85cb24fSFrançois Tigeot I915_WRITE_FW(SPRSCALE(pipe), 0);
682ba55f2f5SFrançois Tigeot
683a85cb24fSFrançois Tigeot I915_WRITE_FW(SPRSURF(pipe), 0);
684a85cb24fSFrançois Tigeot POSTING_READ_FW(SPRSURF(pipe));
685a85cb24fSFrançois Tigeot
686a85cb24fSFrançois Tigeot spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
687e3adcf8fSFrançois Tigeot }
688e3adcf8fSFrançois Tigeot
689*3f2dd94aSFrançois Tigeot static bool
ivb_plane_get_hw_state(struct intel_plane * plane)690*3f2dd94aSFrançois Tigeot ivb_plane_get_hw_state(struct intel_plane *plane)
691*3f2dd94aSFrançois Tigeot {
692*3f2dd94aSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
693*3f2dd94aSFrançois Tigeot enum intel_display_power_domain power_domain;
694*3f2dd94aSFrançois Tigeot enum i915_pipe pipe = plane->pipe;
695*3f2dd94aSFrançois Tigeot bool ret;
696*3f2dd94aSFrançois Tigeot
697*3f2dd94aSFrançois Tigeot power_domain = POWER_DOMAIN_PIPE(pipe);
698*3f2dd94aSFrançois Tigeot if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
699*3f2dd94aSFrançois Tigeot return false;
700*3f2dd94aSFrançois Tigeot
701*3f2dd94aSFrançois Tigeot ret = I915_READ(SPRCTL(pipe)) & SPRITE_ENABLE;
702*3f2dd94aSFrançois Tigeot
703*3f2dd94aSFrançois Tigeot intel_display_power_put(dev_priv, power_domain);
704*3f2dd94aSFrançois Tigeot
705*3f2dd94aSFrançois Tigeot return ret;
706*3f2dd94aSFrançois Tigeot }
707*3f2dd94aSFrançois Tigeot
g4x_sprite_ctl(const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state)708*3f2dd94aSFrançois Tigeot static u32 g4x_sprite_ctl(const struct intel_crtc_state *crtc_state,
709c0e85e96SFrançois Tigeot const struct intel_plane_state *plane_state)
710e3adcf8fSFrançois Tigeot {
711a85cb24fSFrançois Tigeot struct drm_i915_private *dev_priv =
712a85cb24fSFrançois Tigeot to_i915(plane_state->base.plane->dev);
713a85cb24fSFrançois Tigeot const struct drm_framebuffer *fb = plane_state->base.fb;
7148621f407SFrançois Tigeot unsigned int rotation = plane_state->base.rotation;
715c0e85e96SFrançois Tigeot const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
716a85cb24fSFrançois Tigeot u32 dvscntr;
717e3adcf8fSFrançois Tigeot
718a85cb24fSFrançois Tigeot dvscntr = DVS_ENABLE | DVS_GAMMA_ENABLE;
719e3adcf8fSFrançois Tigeot
720a85cb24fSFrançois Tigeot if (IS_GEN6(dev_priv))
721a85cb24fSFrançois Tigeot dvscntr |= DVS_TRICKLE_FEED_DISABLE;
722a85cb24fSFrançois Tigeot
723a85cb24fSFrançois Tigeot switch (fb->format->format) {
724e3adcf8fSFrançois Tigeot case DRM_FORMAT_XBGR8888:
725e3adcf8fSFrançois Tigeot dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
726e3adcf8fSFrançois Tigeot break;
727e3adcf8fSFrançois Tigeot case DRM_FORMAT_XRGB8888:
728e3adcf8fSFrançois Tigeot dvscntr |= DVS_FORMAT_RGBX888;
729e3adcf8fSFrançois Tigeot break;
730e3adcf8fSFrançois Tigeot case DRM_FORMAT_YUYV:
731e3adcf8fSFrançois Tigeot dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
732e3adcf8fSFrançois Tigeot break;
733e3adcf8fSFrançois Tigeot case DRM_FORMAT_YVYU:
734e3adcf8fSFrançois Tigeot dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
735e3adcf8fSFrançois Tigeot break;
736e3adcf8fSFrançois Tigeot case DRM_FORMAT_UYVY:
737e3adcf8fSFrançois Tigeot dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
738e3adcf8fSFrançois Tigeot break;
739e3adcf8fSFrançois Tigeot case DRM_FORMAT_VYUY:
740e3adcf8fSFrançois Tigeot dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
741e3adcf8fSFrançois Tigeot break;
742e3adcf8fSFrançois Tigeot default:
743a85cb24fSFrançois Tigeot MISSING_CASE(fb->format->format);
744a85cb24fSFrançois Tigeot return 0;
745e3adcf8fSFrançois Tigeot }
746e3adcf8fSFrançois Tigeot
7474be47400SFrançois Tigeot if (fb->modifier == I915_FORMAT_MOD_X_TILED)
748e3adcf8fSFrançois Tigeot dvscntr |= DVS_TILED;
749e3adcf8fSFrançois Tigeot
750*3f2dd94aSFrançois Tigeot if (rotation & DRM_MODE_ROTATE_180)
7514be47400SFrançois Tigeot dvscntr |= DVS_ROTATE_180;
7524be47400SFrançois Tigeot
753a85cb24fSFrançois Tigeot if (key->flags & I915_SET_COLORKEY_DESTINATION)
754a85cb24fSFrançois Tigeot dvscntr |= DVS_DEST_KEY;
755a85cb24fSFrançois Tigeot else if (key->flags & I915_SET_COLORKEY_SOURCE)
756a85cb24fSFrançois Tigeot dvscntr |= DVS_SOURCE_KEY;
757a85cb24fSFrançois Tigeot
758a85cb24fSFrançois Tigeot return dvscntr;
759a85cb24fSFrançois Tigeot }
760a85cb24fSFrançois Tigeot
761a85cb24fSFrançois Tigeot static void
g4x_update_plane(struct intel_plane * plane,const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state)762*3f2dd94aSFrançois Tigeot g4x_update_plane(struct intel_plane *plane,
763a85cb24fSFrançois Tigeot const struct intel_crtc_state *crtc_state,
764a85cb24fSFrançois Tigeot const struct intel_plane_state *plane_state)
765a85cb24fSFrançois Tigeot {
766*3f2dd94aSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
767*3f2dd94aSFrançois Tigeot const struct drm_framebuffer *fb = plane_state->base.fb;
768*3f2dd94aSFrançois Tigeot enum i915_pipe pipe = plane->pipe;
769a85cb24fSFrançois Tigeot u32 dvscntr = plane_state->ctl, dvsscale = 0;
770a85cb24fSFrançois Tigeot u32 dvssurf_offset = plane_state->main.offset;
771a85cb24fSFrançois Tigeot u32 linear_offset;
772a85cb24fSFrançois Tigeot const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
773a85cb24fSFrançois Tigeot int crtc_x = plane_state->base.dst.x1;
774a85cb24fSFrançois Tigeot int crtc_y = plane_state->base.dst.y1;
775a85cb24fSFrançois Tigeot uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
776a85cb24fSFrançois Tigeot uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
777a85cb24fSFrançois Tigeot uint32_t x = plane_state->main.x;
778a85cb24fSFrançois Tigeot uint32_t y = plane_state->main.y;
779a85cb24fSFrançois Tigeot uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
780a85cb24fSFrançois Tigeot uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
781a85cb24fSFrançois Tigeot unsigned long irqflags;
782e3adcf8fSFrançois Tigeot
783e3adcf8fSFrançois Tigeot /* Sizes are 0 based */
784e3adcf8fSFrançois Tigeot src_w--;
785e3adcf8fSFrançois Tigeot src_h--;
786e3adcf8fSFrançois Tigeot crtc_w--;
787e3adcf8fSFrançois Tigeot crtc_h--;
788e3adcf8fSFrançois Tigeot
7899edbd4a0SFrançois Tigeot if (crtc_w != src_w || crtc_h != src_h)
790e3adcf8fSFrançois Tigeot dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
791e3adcf8fSFrançois Tigeot
7921e12ee3bSFrançois Tigeot linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
7931e12ee3bSFrançois Tigeot
794a85cb24fSFrançois Tigeot spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
795a85cb24fSFrançois Tigeot
796477eb7f9SFrançois Tigeot if (key->flags) {
797a85cb24fSFrançois Tigeot I915_WRITE_FW(DVSKEYVAL(pipe), key->min_value);
798a85cb24fSFrançois Tigeot I915_WRITE_FW(DVSKEYMAX(pipe), key->max_value);
799a85cb24fSFrançois Tigeot I915_WRITE_FW(DVSKEYMSK(pipe), key->channel_mask);
800477eb7f9SFrançois Tigeot }
801477eb7f9SFrançois Tigeot
802a85cb24fSFrançois Tigeot I915_WRITE_FW(DVSSTRIDE(pipe), fb->pitches[0]);
803a85cb24fSFrançois Tigeot I915_WRITE_FW(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
804ba55f2f5SFrançois Tigeot
8054be47400SFrançois Tigeot if (fb->modifier == I915_FORMAT_MOD_X_TILED)
806a85cb24fSFrançois Tigeot I915_WRITE_FW(DVSTILEOFF(pipe), (y << 16) | x);
8072c84b0b6SFrançois Tigeot else
808a85cb24fSFrançois Tigeot I915_WRITE_FW(DVSLINOFF(pipe), linear_offset);
8092c84b0b6SFrançois Tigeot
810a85cb24fSFrançois Tigeot I915_WRITE_FW(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
811a85cb24fSFrançois Tigeot I915_WRITE_FW(DVSSCALE(pipe), dvsscale);
812a85cb24fSFrançois Tigeot I915_WRITE_FW(DVSCNTR(pipe), dvscntr);
813a85cb24fSFrançois Tigeot I915_WRITE_FW(DVSSURF(pipe),
8144be47400SFrançois Tigeot intel_plane_ggtt_offset(plane_state) + dvssurf_offset);
815a85cb24fSFrançois Tigeot POSTING_READ_FW(DVSSURF(pipe));
816a85cb24fSFrançois Tigeot
817a85cb24fSFrançois Tigeot spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
818e3adcf8fSFrançois Tigeot }
819e3adcf8fSFrançois Tigeot
820e3adcf8fSFrançois Tigeot static void
g4x_disable_plane(struct intel_plane * plane,struct intel_crtc * crtc)821*3f2dd94aSFrançois Tigeot g4x_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
822e3adcf8fSFrançois Tigeot {
823*3f2dd94aSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
824*3f2dd94aSFrançois Tigeot enum i915_pipe pipe = plane->pipe;
825a85cb24fSFrançois Tigeot unsigned long irqflags;
826ba55f2f5SFrançois Tigeot
827a85cb24fSFrançois Tigeot spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
828a85cb24fSFrançois Tigeot
829a85cb24fSFrançois Tigeot I915_WRITE_FW(DVSCNTR(pipe), 0);
830e3adcf8fSFrançois Tigeot /* Disable the scaler */
831a85cb24fSFrançois Tigeot I915_WRITE_FW(DVSSCALE(pipe), 0);
832477eb7f9SFrançois Tigeot
833a85cb24fSFrançois Tigeot I915_WRITE_FW(DVSSURF(pipe), 0);
834a85cb24fSFrançois Tigeot POSTING_READ_FW(DVSSURF(pipe));
835a85cb24fSFrançois Tigeot
836a85cb24fSFrançois Tigeot spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
8379edbd4a0SFrançois Tigeot }
8389edbd4a0SFrançois Tigeot
839*3f2dd94aSFrançois Tigeot static bool
g4x_plane_get_hw_state(struct intel_plane * plane)840*3f2dd94aSFrançois Tigeot g4x_plane_get_hw_state(struct intel_plane *plane)
841*3f2dd94aSFrançois Tigeot {
842*3f2dd94aSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
843*3f2dd94aSFrançois Tigeot enum intel_display_power_domain power_domain;
844*3f2dd94aSFrançois Tigeot enum i915_pipe pipe = plane->pipe;
845*3f2dd94aSFrançois Tigeot bool ret;
846*3f2dd94aSFrançois Tigeot
847*3f2dd94aSFrançois Tigeot power_domain = POWER_DOMAIN_PIPE(pipe);
848*3f2dd94aSFrançois Tigeot if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
849*3f2dd94aSFrançois Tigeot return false;
850*3f2dd94aSFrançois Tigeot
851*3f2dd94aSFrançois Tigeot ret = I915_READ(DVSCNTR(pipe)) & DVS_ENABLE;
852*3f2dd94aSFrançois Tigeot
853*3f2dd94aSFrançois Tigeot intel_display_power_put(dev_priv, power_domain);
854*3f2dd94aSFrançois Tigeot
855*3f2dd94aSFrançois Tigeot return ret;
856*3f2dd94aSFrançois Tigeot }
857*3f2dd94aSFrançois Tigeot
858e3adcf8fSFrançois Tigeot static int
intel_check_sprite_plane(struct intel_plane * plane,struct intel_crtc_state * crtc_state,struct intel_plane_state * state)859*3f2dd94aSFrançois Tigeot intel_check_sprite_plane(struct intel_plane *plane,
860a05eeebfSFrançois Tigeot struct intel_crtc_state *crtc_state,
8612c9916cdSFrançois Tigeot struct intel_plane_state *state)
862e3adcf8fSFrançois Tigeot {
863*3f2dd94aSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
864*3f2dd94aSFrançois Tigeot struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8652c9916cdSFrançois Tigeot struct drm_framebuffer *fb = state->base.fb;
8669edbd4a0SFrançois Tigeot int crtc_x, crtc_y;
8679edbd4a0SFrançois Tigeot unsigned int crtc_w, crtc_h;
8689edbd4a0SFrançois Tigeot uint32_t src_x, src_y, src_w, src_h;
8691e12ee3bSFrançois Tigeot struct drm_rect *src = &state->base.src;
8701e12ee3bSFrançois Tigeot struct drm_rect *dst = &state->base.dst;
8712c9916cdSFrançois Tigeot const struct drm_rect *clip = &state->clip;
8722c9916cdSFrançois Tigeot int hscale, vscale;
8732c9916cdSFrançois Tigeot int max_scale, min_scale;
87419c468b4SFrançois Tigeot bool can_scale;
8751e12ee3bSFrançois Tigeot int ret;
8761e12ee3bSFrançois Tigeot
8774be47400SFrançois Tigeot *src = drm_plane_state_src(&state->base);
8784be47400SFrançois Tigeot *dst = drm_plane_state_dest(&state->base);
8792c9916cdSFrançois Tigeot
8802c9916cdSFrançois Tigeot if (!fb) {
8811e12ee3bSFrançois Tigeot state->base.visible = false;
882a05eeebfSFrançois Tigeot return 0;
8832c9916cdSFrançois Tigeot }
884e3adcf8fSFrançois Tigeot
885e3adcf8fSFrançois Tigeot /* Don't modify another pipe's plane */
886*3f2dd94aSFrançois Tigeot if (plane->pipe != crtc->pipe) {
8875d0b1887SFrançois Tigeot DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
888e3adcf8fSFrançois Tigeot return -EINVAL;
8895d0b1887SFrançois Tigeot }
8905d0b1887SFrançois Tigeot
8915d0b1887SFrançois Tigeot /* FIXME check all gen limits */
8925d0b1887SFrançois Tigeot if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
8935d0b1887SFrançois Tigeot DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
8945d0b1887SFrançois Tigeot return -EINVAL;
8955d0b1887SFrançois Tigeot }
896e3adcf8fSFrançois Tigeot
89719c468b4SFrançois Tigeot /* setup can_scale, min_scale, max_scale */
8981e12ee3bSFrançois Tigeot if (INTEL_GEN(dev_priv) >= 9) {
89919c468b4SFrançois Tigeot /* use scaler when colorkey is not required */
900a05eeebfSFrançois Tigeot if (state->ckey.flags == I915_SET_COLORKEY_NONE) {
90119c468b4SFrançois Tigeot can_scale = 1;
90219c468b4SFrançois Tigeot min_scale = 1;
903*3f2dd94aSFrançois Tigeot max_scale = skl_max_scale(crtc, crtc_state);
90419c468b4SFrançois Tigeot } else {
90519c468b4SFrançois Tigeot can_scale = 0;
90619c468b4SFrançois Tigeot min_scale = DRM_PLANE_HELPER_NO_SCALING;
90719c468b4SFrançois Tigeot max_scale = DRM_PLANE_HELPER_NO_SCALING;
90819c468b4SFrançois Tigeot }
90919c468b4SFrançois Tigeot } else {
910*3f2dd94aSFrançois Tigeot can_scale = plane->can_scale;
911*3f2dd94aSFrançois Tigeot max_scale = plane->max_downscale << 16;
912*3f2dd94aSFrançois Tigeot min_scale = plane->can_scale ? 1 : (1 << 16);
91319c468b4SFrançois Tigeot }
91419c468b4SFrançois Tigeot
915e3adcf8fSFrançois Tigeot /*
9165d0b1887SFrançois Tigeot * FIXME the following code does a bunch of fuzzy adjustments to the
9175d0b1887SFrançois Tigeot * coordinates and sizes. We probably need some way to decide whether
9185d0b1887SFrançois Tigeot * more strict checking should be done instead.
919e3adcf8fSFrançois Tigeot */
9202c9916cdSFrançois Tigeot drm_rect_rotate(src, fb->width << 16, fb->height << 16,
9212c9916cdSFrançois Tigeot state->base.rotation);
9221b13d190SFrançois Tigeot
9232c9916cdSFrançois Tigeot hscale = drm_rect_calc_hscale_relaxed(src, dst, min_scale, max_scale);
9245d0b1887SFrançois Tigeot BUG_ON(hscale < 0);
925e3adcf8fSFrançois Tigeot
9262c9916cdSFrançois Tigeot vscale = drm_rect_calc_vscale_relaxed(src, dst, min_scale, max_scale);
9275d0b1887SFrançois Tigeot BUG_ON(vscale < 0);
9285d0b1887SFrançois Tigeot
9291e12ee3bSFrançois Tigeot state->base.visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale);
9305d0b1887SFrançois Tigeot
9312c9916cdSFrançois Tigeot crtc_x = dst->x1;
9322c9916cdSFrançois Tigeot crtc_y = dst->y1;
9332c9916cdSFrançois Tigeot crtc_w = drm_rect_width(dst);
9342c9916cdSFrançois Tigeot crtc_h = drm_rect_height(dst);
9355d0b1887SFrançois Tigeot
9361e12ee3bSFrançois Tigeot if (state->base.visible) {
9375d0b1887SFrançois Tigeot /* check again in case clipping clamped the results */
9382c9916cdSFrançois Tigeot hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
9395d0b1887SFrançois Tigeot if (hscale < 0) {
9405d0b1887SFrançois Tigeot DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
941aee94f86SFrançois Tigeot drm_rect_debug_print("src: ", src, true);
942aee94f86SFrançois Tigeot drm_rect_debug_print("dst: ", dst, false);
9435d0b1887SFrançois Tigeot
9445d0b1887SFrançois Tigeot return hscale;
9455d0b1887SFrançois Tigeot }
9465d0b1887SFrançois Tigeot
9472c9916cdSFrançois Tigeot vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
9485d0b1887SFrançois Tigeot if (vscale < 0) {
9495d0b1887SFrançois Tigeot DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
950aee94f86SFrançois Tigeot drm_rect_debug_print("src: ", src, true);
951aee94f86SFrançois Tigeot drm_rect_debug_print("dst: ", dst, false);
9525d0b1887SFrançois Tigeot
9535d0b1887SFrançois Tigeot return vscale;
9545d0b1887SFrançois Tigeot }
9555d0b1887SFrançois Tigeot
9565d0b1887SFrançois Tigeot /* Make the source viewport size an exact multiple of the scaling factors. */
9572c9916cdSFrançois Tigeot drm_rect_adjust_size(src,
9582c9916cdSFrançois Tigeot drm_rect_width(dst) * hscale - drm_rect_width(src),
9592c9916cdSFrançois Tigeot drm_rect_height(dst) * vscale - drm_rect_height(src));
9605d0b1887SFrançois Tigeot
9612c9916cdSFrançois Tigeot drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16,
9622c9916cdSFrançois Tigeot state->base.rotation);
9631b13d190SFrançois Tigeot
9645d0b1887SFrançois Tigeot /* sanity check to make sure the src viewport wasn't enlarged */
9652c9916cdSFrançois Tigeot WARN_ON(src->x1 < (int) state->base.src_x ||
9662c9916cdSFrançois Tigeot src->y1 < (int) state->base.src_y ||
9672c9916cdSFrançois Tigeot src->x2 > (int) state->base.src_x + state->base.src_w ||
9682c9916cdSFrançois Tigeot src->y2 > (int) state->base.src_y + state->base.src_h);
969e3adcf8fSFrançois Tigeot
970e3adcf8fSFrançois Tigeot /*
9715d0b1887SFrançois Tigeot * Hardware doesn't handle subpixel coordinates.
9725d0b1887SFrançois Tigeot * Adjust to (macro)pixel boundary, but be careful not to
9735d0b1887SFrançois Tigeot * increase the source viewport size, because that could
9745d0b1887SFrançois Tigeot * push the downscaling factor out of bounds.
9752c84b0b6SFrançois Tigeot */
9762c9916cdSFrançois Tigeot src_x = src->x1 >> 16;
9772c9916cdSFrançois Tigeot src_w = drm_rect_width(src) >> 16;
9782c9916cdSFrançois Tigeot src_y = src->y1 >> 16;
9792c9916cdSFrançois Tigeot src_h = drm_rect_height(src) >> 16;
9805d0b1887SFrançois Tigeot
981a85cb24fSFrançois Tigeot if (format_is_yuv(fb->format->format)) {
9825d0b1887SFrançois Tigeot src_x &= ~1;
9835d0b1887SFrançois Tigeot src_w &= ~1;
9842c84b0b6SFrançois Tigeot
9852c84b0b6SFrançois Tigeot /*
9865d0b1887SFrançois Tigeot * Must keep src and dst the
9875d0b1887SFrançois Tigeot * same if we can't scale.
988e3adcf8fSFrançois Tigeot */
98919c468b4SFrançois Tigeot if (!can_scale)
9905d0b1887SFrançois Tigeot crtc_w &= ~1;
9915d0b1887SFrançois Tigeot
9925d0b1887SFrançois Tigeot if (crtc_w == 0)
9931e12ee3bSFrançois Tigeot state->base.visible = false;
9945d0b1887SFrançois Tigeot }
9955d0b1887SFrançois Tigeot }
9965d0b1887SFrançois Tigeot
9975d0b1887SFrançois Tigeot /* Check size restrictions when scaling */
9981e12ee3bSFrançois Tigeot if (state->base.visible && (src_w != crtc_w || src_h != crtc_h)) {
9995d0b1887SFrançois Tigeot unsigned int width_bytes;
1000a85cb24fSFrançois Tigeot int cpp = fb->format->cpp[0];
10015d0b1887SFrançois Tigeot
100219c468b4SFrançois Tigeot WARN_ON(!can_scale);
10035d0b1887SFrançois Tigeot
10045d0b1887SFrançois Tigeot /* FIXME interlacing min height is 6 */
10055d0b1887SFrançois Tigeot
10065d0b1887SFrançois Tigeot if (crtc_w < 3 || crtc_h < 3)
10071e12ee3bSFrançois Tigeot state->base.visible = false;
10085d0b1887SFrançois Tigeot
10095d0b1887SFrançois Tigeot if (src_w < 3 || src_h < 3)
10101e12ee3bSFrançois Tigeot state->base.visible = false;
10115d0b1887SFrançois Tigeot
1012c0e85e96SFrançois Tigeot width_bytes = ((src_x * cpp) & 63) + src_w * cpp;
10135d0b1887SFrançois Tigeot
10141e12ee3bSFrançois Tigeot if (INTEL_GEN(dev_priv) < 9 && (src_w > 2048 || src_h > 2048 ||
101519c468b4SFrançois Tigeot width_bytes > 4096 || fb->pitches[0] > 4096)) {
10165d0b1887SFrançois Tigeot DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
1017e3adcf8fSFrançois Tigeot return -EINVAL;
10185d0b1887SFrançois Tigeot }
10195d0b1887SFrançois Tigeot }
10205d0b1887SFrançois Tigeot
10211e12ee3bSFrançois Tigeot if (state->base.visible) {
102219c468b4SFrançois Tigeot src->x1 = src_x << 16;
102319c468b4SFrançois Tigeot src->x2 = (src_x + src_w) << 16;
102419c468b4SFrançois Tigeot src->y1 = src_y << 16;
102519c468b4SFrançois Tigeot src->y2 = (src_y + src_h) << 16;
10262c9916cdSFrançois Tigeot }
1027e3adcf8fSFrançois Tigeot
10282c9916cdSFrançois Tigeot dst->x1 = crtc_x;
10292c9916cdSFrançois Tigeot dst->x2 = crtc_x + crtc_w;
10302c9916cdSFrançois Tigeot dst->y1 = crtc_y;
10312c9916cdSFrançois Tigeot dst->y2 = crtc_y + crtc_h;
10322c9916cdSFrançois Tigeot
10331e12ee3bSFrançois Tigeot if (INTEL_GEN(dev_priv) >= 9) {
10341e12ee3bSFrançois Tigeot ret = skl_check_plane_surface(state);
10351e12ee3bSFrançois Tigeot if (ret)
10361e12ee3bSFrançois Tigeot return ret;
1037a85cb24fSFrançois Tigeot
1038a85cb24fSFrançois Tigeot state->ctl = skl_plane_ctl(crtc_state, state);
1039a85cb24fSFrançois Tigeot } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1040a85cb24fSFrançois Tigeot ret = i9xx_check_plane_surface(state);
1041a85cb24fSFrançois Tigeot if (ret)
1042a85cb24fSFrançois Tigeot return ret;
1043a85cb24fSFrançois Tigeot
1044a85cb24fSFrançois Tigeot state->ctl = vlv_sprite_ctl(crtc_state, state);
1045a85cb24fSFrançois Tigeot } else if (INTEL_GEN(dev_priv) >= 7) {
1046a85cb24fSFrançois Tigeot ret = i9xx_check_plane_surface(state);
1047a85cb24fSFrançois Tigeot if (ret)
1048a85cb24fSFrançois Tigeot return ret;
1049a85cb24fSFrançois Tigeot
1050a85cb24fSFrançois Tigeot state->ctl = ivb_sprite_ctl(crtc_state, state);
1051a85cb24fSFrançois Tigeot } else {
1052a85cb24fSFrançois Tigeot ret = i9xx_check_plane_surface(state);
1053a85cb24fSFrançois Tigeot if (ret)
1054a85cb24fSFrançois Tigeot return ret;
1055a85cb24fSFrançois Tigeot
1056*3f2dd94aSFrançois Tigeot state->ctl = g4x_sprite_ctl(crtc_state, state);
10571e12ee3bSFrançois Tigeot }
10581e12ee3bSFrançois Tigeot
10592c9916cdSFrançois Tigeot return 0;
10602c9916cdSFrançois Tigeot }
10612c9916cdSFrançois Tigeot
intel_sprite_set_colorkey(struct drm_device * dev,void * data,struct drm_file * file_priv)1062e3adcf8fSFrançois Tigeot int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
1063e3adcf8fSFrançois Tigeot struct drm_file *file_priv)
1064e3adcf8fSFrançois Tigeot {
10651e12ee3bSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(dev);
1066e3adcf8fSFrançois Tigeot struct drm_intel_sprite_colorkey *set = data;
1067e3adcf8fSFrançois Tigeot struct drm_plane *plane;
1068a05eeebfSFrançois Tigeot struct drm_plane_state *plane_state;
1069a05eeebfSFrançois Tigeot struct drm_atomic_state *state;
1070a05eeebfSFrançois Tigeot struct drm_modeset_acquire_ctx ctx;
1071e3adcf8fSFrançois Tigeot int ret = 0;
1072e3adcf8fSFrançois Tigeot
1073e3adcf8fSFrançois Tigeot /* Make sure we don't try to enable both src & dest simultaneously */
1074e3adcf8fSFrançois Tigeot if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
1075e3adcf8fSFrançois Tigeot return -EINVAL;
1076e3adcf8fSFrançois Tigeot
10771e12ee3bSFrançois Tigeot if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1078477eb7f9SFrançois Tigeot set->flags & I915_SET_COLORKEY_DESTINATION)
1079477eb7f9SFrançois Tigeot return -EINVAL;
1080477eb7f9SFrançois Tigeot
1081*3f2dd94aSFrançois Tigeot plane = drm_plane_find(dev, file_priv, set->plane_id);
1082a05eeebfSFrançois Tigeot if (!plane || plane->type != DRM_PLANE_TYPE_OVERLAY)
1083a05eeebfSFrançois Tigeot return -ENOENT;
1084a05eeebfSFrançois Tigeot
1085a05eeebfSFrançois Tigeot drm_modeset_acquire_init(&ctx, 0);
1086a05eeebfSFrançois Tigeot
1087a05eeebfSFrançois Tigeot state = drm_atomic_state_alloc(plane->dev);
1088a05eeebfSFrançois Tigeot if (!state) {
1089a05eeebfSFrançois Tigeot ret = -ENOMEM;
1090a05eeebfSFrançois Tigeot goto out;
1091a05eeebfSFrançois Tigeot }
1092a05eeebfSFrançois Tigeot state->acquire_ctx = &ctx;
1093a05eeebfSFrançois Tigeot
1094a05eeebfSFrançois Tigeot while (1) {
1095a05eeebfSFrançois Tigeot plane_state = drm_atomic_get_plane_state(state, plane);
1096a05eeebfSFrançois Tigeot ret = PTR_ERR_OR_ZERO(plane_state);
1097a05eeebfSFrançois Tigeot if (!ret) {
1098a05eeebfSFrançois Tigeot to_intel_plane_state(plane_state)->ckey = *set;
1099a05eeebfSFrançois Tigeot ret = drm_atomic_commit(state);
1100e3adcf8fSFrançois Tigeot }
1101e3adcf8fSFrançois Tigeot
1102a05eeebfSFrançois Tigeot if (ret != -EDEADLK)
1103a05eeebfSFrançois Tigeot break;
110419c468b4SFrançois Tigeot
1105a05eeebfSFrançois Tigeot drm_atomic_state_clear(state);
1106a05eeebfSFrançois Tigeot drm_modeset_backoff(&ctx);
110719c468b4SFrançois Tigeot }
110819c468b4SFrançois Tigeot
11094be47400SFrançois Tigeot drm_atomic_state_put(state);
1110a05eeebfSFrançois Tigeot out:
1111a05eeebfSFrançois Tigeot drm_modeset_drop_locks(&ctx);
1112a05eeebfSFrançois Tigeot drm_modeset_acquire_fini(&ctx);
1113e3adcf8fSFrançois Tigeot return ret;
1114e3adcf8fSFrançois Tigeot }
1115e3adcf8fSFrançois Tigeot
1116*3f2dd94aSFrançois Tigeot static const uint32_t g4x_plane_formats[] = {
11172c84b0b6SFrançois Tigeot DRM_FORMAT_XRGB8888,
11182c84b0b6SFrançois Tigeot DRM_FORMAT_YUYV,
11192c84b0b6SFrançois Tigeot DRM_FORMAT_YVYU,
11202c84b0b6SFrançois Tigeot DRM_FORMAT_UYVY,
11212c84b0b6SFrançois Tigeot DRM_FORMAT_VYUY,
11222c84b0b6SFrançois Tigeot };
11232c84b0b6SFrançois Tigeot
1124*3f2dd94aSFrançois Tigeot static const uint64_t i9xx_plane_format_modifiers[] = {
1125*3f2dd94aSFrançois Tigeot I915_FORMAT_MOD_X_TILED,
1126*3f2dd94aSFrançois Tigeot DRM_FORMAT_MOD_LINEAR,
1127*3f2dd94aSFrançois Tigeot DRM_FORMAT_MOD_INVALID
1128*3f2dd94aSFrançois Tigeot };
1129*3f2dd94aSFrançois Tigeot
113019c468b4SFrançois Tigeot static const uint32_t snb_plane_formats[] = {
1131e3adcf8fSFrançois Tigeot DRM_FORMAT_XBGR8888,
1132e3adcf8fSFrançois Tigeot DRM_FORMAT_XRGB8888,
1133e3adcf8fSFrançois Tigeot DRM_FORMAT_YUYV,
1134e3adcf8fSFrançois Tigeot DRM_FORMAT_YVYU,
1135e3adcf8fSFrançois Tigeot DRM_FORMAT_UYVY,
1136e3adcf8fSFrançois Tigeot DRM_FORMAT_VYUY,
1137e3adcf8fSFrançois Tigeot };
1138e3adcf8fSFrançois Tigeot
113919c468b4SFrançois Tigeot static const uint32_t vlv_plane_formats[] = {
11408e26cdf6SFrançois Tigeot DRM_FORMAT_RGB565,
11418e26cdf6SFrançois Tigeot DRM_FORMAT_ABGR8888,
11428e26cdf6SFrançois Tigeot DRM_FORMAT_ARGB8888,
11438e26cdf6SFrançois Tigeot DRM_FORMAT_XBGR8888,
11448e26cdf6SFrançois Tigeot DRM_FORMAT_XRGB8888,
11458e26cdf6SFrançois Tigeot DRM_FORMAT_XBGR2101010,
11468e26cdf6SFrançois Tigeot DRM_FORMAT_ABGR2101010,
11478e26cdf6SFrançois Tigeot DRM_FORMAT_YUYV,
11488e26cdf6SFrançois Tigeot DRM_FORMAT_YVYU,
11498e26cdf6SFrançois Tigeot DRM_FORMAT_UYVY,
11508e26cdf6SFrançois Tigeot DRM_FORMAT_VYUY,
11518e26cdf6SFrançois Tigeot };
11528e26cdf6SFrançois Tigeot
11532c9916cdSFrançois Tigeot static uint32_t skl_plane_formats[] = {
11542c9916cdSFrançois Tigeot DRM_FORMAT_RGB565,
11552c9916cdSFrançois Tigeot DRM_FORMAT_ABGR8888,
11562c9916cdSFrançois Tigeot DRM_FORMAT_ARGB8888,
11572c9916cdSFrançois Tigeot DRM_FORMAT_XBGR8888,
11582c9916cdSFrançois Tigeot DRM_FORMAT_XRGB8888,
11592c9916cdSFrançois Tigeot DRM_FORMAT_YUYV,
11602c9916cdSFrançois Tigeot DRM_FORMAT_YVYU,
11612c9916cdSFrançois Tigeot DRM_FORMAT_UYVY,
11622c9916cdSFrançois Tigeot DRM_FORMAT_VYUY,
11632c9916cdSFrançois Tigeot };
11642c9916cdSFrançois Tigeot
1165*3f2dd94aSFrançois Tigeot static const uint64_t skl_plane_format_modifiers[] = {
1166*3f2dd94aSFrançois Tigeot I915_FORMAT_MOD_X_TILED,
1167*3f2dd94aSFrançois Tigeot DRM_FORMAT_MOD_LINEAR,
1168*3f2dd94aSFrançois Tigeot DRM_FORMAT_MOD_INVALID
1169*3f2dd94aSFrançois Tigeot };
1170*3f2dd94aSFrançois Tigeot
g4x_sprite_plane_format_mod_supported(struct drm_plane * plane,uint32_t format,uint64_t modifier)1171*3f2dd94aSFrançois Tigeot static bool g4x_sprite_plane_format_mod_supported(struct drm_plane *plane,
1172*3f2dd94aSFrançois Tigeot uint32_t format,
1173*3f2dd94aSFrançois Tigeot uint64_t modifier)
1174*3f2dd94aSFrançois Tigeot {
1175*3f2dd94aSFrançois Tigeot switch (format) {
1176*3f2dd94aSFrançois Tigeot case DRM_FORMAT_XBGR8888:
1177*3f2dd94aSFrançois Tigeot case DRM_FORMAT_XRGB8888:
1178*3f2dd94aSFrançois Tigeot case DRM_FORMAT_YUYV:
1179*3f2dd94aSFrançois Tigeot case DRM_FORMAT_YVYU:
1180*3f2dd94aSFrançois Tigeot case DRM_FORMAT_UYVY:
1181*3f2dd94aSFrançois Tigeot case DRM_FORMAT_VYUY:
1182*3f2dd94aSFrançois Tigeot if (modifier == DRM_FORMAT_MOD_LINEAR ||
1183*3f2dd94aSFrançois Tigeot modifier == I915_FORMAT_MOD_X_TILED)
1184*3f2dd94aSFrançois Tigeot return true;
1185*3f2dd94aSFrançois Tigeot /* fall through */
1186*3f2dd94aSFrançois Tigeot default:
1187*3f2dd94aSFrançois Tigeot return false;
1188*3f2dd94aSFrançois Tigeot }
1189*3f2dd94aSFrançois Tigeot }
1190*3f2dd94aSFrançois Tigeot
vlv_sprite_plane_format_mod_supported(struct drm_plane * plane,uint32_t format,uint64_t modifier)1191*3f2dd94aSFrançois Tigeot static bool vlv_sprite_plane_format_mod_supported(struct drm_plane *plane,
1192*3f2dd94aSFrançois Tigeot uint32_t format,
1193*3f2dd94aSFrançois Tigeot uint64_t modifier)
1194*3f2dd94aSFrançois Tigeot {
1195*3f2dd94aSFrançois Tigeot switch (format) {
1196*3f2dd94aSFrançois Tigeot case DRM_FORMAT_YUYV:
1197*3f2dd94aSFrançois Tigeot case DRM_FORMAT_YVYU:
1198*3f2dd94aSFrançois Tigeot case DRM_FORMAT_UYVY:
1199*3f2dd94aSFrançois Tigeot case DRM_FORMAT_VYUY:
1200*3f2dd94aSFrançois Tigeot case DRM_FORMAT_RGB565:
1201*3f2dd94aSFrançois Tigeot case DRM_FORMAT_XRGB8888:
1202*3f2dd94aSFrançois Tigeot case DRM_FORMAT_ARGB8888:
1203*3f2dd94aSFrançois Tigeot case DRM_FORMAT_XBGR2101010:
1204*3f2dd94aSFrançois Tigeot case DRM_FORMAT_ABGR2101010:
1205*3f2dd94aSFrançois Tigeot case DRM_FORMAT_XBGR8888:
1206*3f2dd94aSFrançois Tigeot case DRM_FORMAT_ABGR8888:
1207*3f2dd94aSFrançois Tigeot if (modifier == DRM_FORMAT_MOD_LINEAR ||
1208*3f2dd94aSFrançois Tigeot modifier == I915_FORMAT_MOD_X_TILED)
1209*3f2dd94aSFrançois Tigeot return true;
1210*3f2dd94aSFrançois Tigeot /* fall through */
1211*3f2dd94aSFrançois Tigeot default:
1212*3f2dd94aSFrançois Tigeot return false;
1213*3f2dd94aSFrançois Tigeot }
1214*3f2dd94aSFrançois Tigeot }
1215*3f2dd94aSFrançois Tigeot
skl_sprite_plane_format_mod_supported(struct drm_plane * plane,uint32_t format,uint64_t modifier)1216*3f2dd94aSFrançois Tigeot static bool skl_sprite_plane_format_mod_supported(struct drm_plane *plane,
1217*3f2dd94aSFrançois Tigeot uint32_t format,
1218*3f2dd94aSFrançois Tigeot uint64_t modifier)
1219*3f2dd94aSFrançois Tigeot {
1220*3f2dd94aSFrançois Tigeot /* This is the same as primary plane since SKL has universal planes */
1221*3f2dd94aSFrançois Tigeot switch (format) {
1222*3f2dd94aSFrançois Tigeot case DRM_FORMAT_XRGB8888:
1223*3f2dd94aSFrançois Tigeot case DRM_FORMAT_XBGR8888:
1224*3f2dd94aSFrançois Tigeot case DRM_FORMAT_ARGB8888:
1225*3f2dd94aSFrançois Tigeot case DRM_FORMAT_ABGR8888:
1226*3f2dd94aSFrançois Tigeot case DRM_FORMAT_RGB565:
1227*3f2dd94aSFrançois Tigeot case DRM_FORMAT_XRGB2101010:
1228*3f2dd94aSFrançois Tigeot case DRM_FORMAT_XBGR2101010:
1229*3f2dd94aSFrançois Tigeot case DRM_FORMAT_YUYV:
1230*3f2dd94aSFrançois Tigeot case DRM_FORMAT_YVYU:
1231*3f2dd94aSFrançois Tigeot case DRM_FORMAT_UYVY:
1232*3f2dd94aSFrançois Tigeot case DRM_FORMAT_VYUY:
1233*3f2dd94aSFrançois Tigeot if (modifier == I915_FORMAT_MOD_Yf_TILED)
1234*3f2dd94aSFrançois Tigeot return true;
1235*3f2dd94aSFrançois Tigeot /* fall through */
1236*3f2dd94aSFrançois Tigeot case DRM_FORMAT_C8:
1237*3f2dd94aSFrançois Tigeot if (modifier == DRM_FORMAT_MOD_LINEAR ||
1238*3f2dd94aSFrançois Tigeot modifier == I915_FORMAT_MOD_X_TILED ||
1239*3f2dd94aSFrançois Tigeot modifier == I915_FORMAT_MOD_Y_TILED)
1240*3f2dd94aSFrançois Tigeot return true;
1241*3f2dd94aSFrançois Tigeot /* fall through */
1242*3f2dd94aSFrançois Tigeot default:
1243*3f2dd94aSFrançois Tigeot return false;
1244*3f2dd94aSFrançois Tigeot }
1245*3f2dd94aSFrançois Tigeot }
1246*3f2dd94aSFrançois Tigeot
intel_sprite_plane_format_mod_supported(struct drm_plane * plane,uint32_t format,uint64_t modifier)1247*3f2dd94aSFrançois Tigeot static bool intel_sprite_plane_format_mod_supported(struct drm_plane *plane,
1248*3f2dd94aSFrançois Tigeot uint32_t format,
1249*3f2dd94aSFrançois Tigeot uint64_t modifier)
1250*3f2dd94aSFrançois Tigeot {
1251*3f2dd94aSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(plane->dev);
1252*3f2dd94aSFrançois Tigeot
1253*3f2dd94aSFrançois Tigeot if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID))
1254*3f2dd94aSFrançois Tigeot return false;
1255*3f2dd94aSFrançois Tigeot
1256*3f2dd94aSFrançois Tigeot if ((modifier >> 56) != DRM_FORMAT_MOD_VENDOR_INTEL &&
1257*3f2dd94aSFrançois Tigeot modifier != DRM_FORMAT_MOD_LINEAR)
1258*3f2dd94aSFrançois Tigeot return false;
1259*3f2dd94aSFrançois Tigeot
1260*3f2dd94aSFrançois Tigeot if (INTEL_GEN(dev_priv) >= 9)
1261*3f2dd94aSFrançois Tigeot return skl_sprite_plane_format_mod_supported(plane, format, modifier);
1262*3f2dd94aSFrançois Tigeot else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
1263*3f2dd94aSFrançois Tigeot return vlv_sprite_plane_format_mod_supported(plane, format, modifier);
1264*3f2dd94aSFrançois Tigeot else
1265*3f2dd94aSFrançois Tigeot return g4x_sprite_plane_format_mod_supported(plane, format, modifier);
1266*3f2dd94aSFrançois Tigeot
1267*3f2dd94aSFrançois Tigeot unreachable();
1268*3f2dd94aSFrançois Tigeot }
1269*3f2dd94aSFrançois Tigeot
1270*3f2dd94aSFrançois Tigeot static const struct drm_plane_funcs intel_sprite_plane_funcs = {
1271*3f2dd94aSFrançois Tigeot .update_plane = drm_atomic_helper_update_plane,
1272*3f2dd94aSFrançois Tigeot .disable_plane = drm_atomic_helper_disable_plane,
1273*3f2dd94aSFrançois Tigeot .destroy = intel_plane_destroy,
1274*3f2dd94aSFrançois Tigeot .atomic_get_property = intel_plane_atomic_get_property,
1275*3f2dd94aSFrançois Tigeot .atomic_set_property = intel_plane_atomic_set_property,
1276*3f2dd94aSFrançois Tigeot .atomic_duplicate_state = intel_plane_duplicate_state,
1277*3f2dd94aSFrançois Tigeot .atomic_destroy_state = intel_plane_destroy_state,
1278*3f2dd94aSFrançois Tigeot .format_mod_supported = intel_sprite_plane_format_mod_supported,
1279*3f2dd94aSFrançois Tigeot };
1280*3f2dd94aSFrançois Tigeot
12814be47400SFrançois Tigeot struct intel_plane *
intel_sprite_plane_create(struct drm_i915_private * dev_priv,enum i915_pipe pipe,int plane)12824be47400SFrançois Tigeot intel_sprite_plane_create(struct drm_i915_private *dev_priv,
12834be47400SFrançois Tigeot enum i915_pipe pipe, int plane)
1284e3adcf8fSFrançois Tigeot {
12858621f407SFrançois Tigeot struct intel_plane *intel_plane = NULL;
12868621f407SFrançois Tigeot struct intel_plane_state *state = NULL;
1287e3adcf8fSFrançois Tigeot unsigned long possible_crtcs;
12882c84b0b6SFrançois Tigeot const uint32_t *plane_formats;
1289*3f2dd94aSFrançois Tigeot const uint64_t *modifiers;
12904be47400SFrançois Tigeot unsigned int supported_rotations;
12912c84b0b6SFrançois Tigeot int num_plane_formats;
1292e3adcf8fSFrançois Tigeot int ret;
1293e3adcf8fSFrançois Tigeot
12949edbd4a0SFrançois Tigeot intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
12958621f407SFrançois Tigeot if (!intel_plane) {
12968621f407SFrançois Tigeot ret = -ENOMEM;
12978621f407SFrançois Tigeot goto fail;
12988621f407SFrançois Tigeot }
12992c84b0b6SFrançois Tigeot
13002c9916cdSFrançois Tigeot state = intel_create_plane_state(&intel_plane->base);
13012c9916cdSFrançois Tigeot if (!state) {
13028621f407SFrançois Tigeot ret = -ENOMEM;
13038621f407SFrançois Tigeot goto fail;
13042c9916cdSFrançois Tigeot }
13052c9916cdSFrançois Tigeot intel_plane->base.state = &state->base;
13062c9916cdSFrançois Tigeot
1307*3f2dd94aSFrançois Tigeot if (INTEL_GEN(dev_priv) >= 10) {
13084be47400SFrançois Tigeot intel_plane->can_scale = true;
13094be47400SFrançois Tigeot state->scaler_id = -1;
13104be47400SFrançois Tigeot
13114be47400SFrançois Tigeot intel_plane->update_plane = skl_update_plane;
13124be47400SFrançois Tigeot intel_plane->disable_plane = skl_disable_plane;
1313*3f2dd94aSFrançois Tigeot intel_plane->get_hw_state = skl_plane_get_hw_state;
13144be47400SFrançois Tigeot
13154be47400SFrançois Tigeot plane_formats = skl_plane_formats;
13164be47400SFrançois Tigeot num_plane_formats = ARRAY_SIZE(skl_plane_formats);
1317*3f2dd94aSFrançois Tigeot modifiers = skl_plane_format_modifiers;
1318*3f2dd94aSFrançois Tigeot } else if (INTEL_GEN(dev_priv) >= 9) {
1319*3f2dd94aSFrançois Tigeot intel_plane->can_scale = true;
1320*3f2dd94aSFrançois Tigeot state->scaler_id = -1;
1321*3f2dd94aSFrançois Tigeot
1322*3f2dd94aSFrançois Tigeot intel_plane->update_plane = skl_update_plane;
1323*3f2dd94aSFrançois Tigeot intel_plane->disable_plane = skl_disable_plane;
1324*3f2dd94aSFrançois Tigeot intel_plane->get_hw_state = skl_plane_get_hw_state;
1325*3f2dd94aSFrançois Tigeot
1326*3f2dd94aSFrançois Tigeot plane_formats = skl_plane_formats;
1327*3f2dd94aSFrançois Tigeot num_plane_formats = ARRAY_SIZE(skl_plane_formats);
1328*3f2dd94aSFrançois Tigeot modifiers = skl_plane_format_modifiers;
13294be47400SFrançois Tigeot } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
13304be47400SFrançois Tigeot intel_plane->can_scale = false;
13314be47400SFrançois Tigeot intel_plane->max_downscale = 1;
13324be47400SFrançois Tigeot
13334be47400SFrançois Tigeot intel_plane->update_plane = vlv_update_plane;
13344be47400SFrançois Tigeot intel_plane->disable_plane = vlv_disable_plane;
1335*3f2dd94aSFrançois Tigeot intel_plane->get_hw_state = vlv_plane_get_hw_state;
13364be47400SFrançois Tigeot
13374be47400SFrançois Tigeot plane_formats = vlv_plane_formats;
13384be47400SFrançois Tigeot num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
1339*3f2dd94aSFrançois Tigeot modifiers = i9xx_plane_format_modifiers;
13404be47400SFrançois Tigeot } else if (INTEL_GEN(dev_priv) >= 7) {
13414be47400SFrançois Tigeot if (IS_IVYBRIDGE(dev_priv)) {
13424be47400SFrançois Tigeot intel_plane->can_scale = true;
13434be47400SFrançois Tigeot intel_plane->max_downscale = 2;
13444be47400SFrançois Tigeot } else {
13454be47400SFrançois Tigeot intel_plane->can_scale = false;
13464be47400SFrançois Tigeot intel_plane->max_downscale = 1;
13474be47400SFrançois Tigeot }
13484be47400SFrançois Tigeot
13494be47400SFrançois Tigeot intel_plane->update_plane = ivb_update_plane;
13504be47400SFrançois Tigeot intel_plane->disable_plane = ivb_disable_plane;
1351*3f2dd94aSFrançois Tigeot intel_plane->get_hw_state = ivb_plane_get_hw_state;
13524be47400SFrançois Tigeot
13534be47400SFrançois Tigeot plane_formats = snb_plane_formats;
13544be47400SFrançois Tigeot num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1355*3f2dd94aSFrançois Tigeot modifiers = i9xx_plane_format_modifiers;
13564be47400SFrançois Tigeot } else {
13572c84b0b6SFrançois Tigeot intel_plane->can_scale = true;
13582c84b0b6SFrançois Tigeot intel_plane->max_downscale = 16;
13594be47400SFrançois Tigeot
1360*3f2dd94aSFrançois Tigeot intel_plane->update_plane = g4x_update_plane;
1361*3f2dd94aSFrançois Tigeot intel_plane->disable_plane = g4x_disable_plane;
1362*3f2dd94aSFrançois Tigeot intel_plane->get_hw_state = g4x_plane_get_hw_state;
1363e3adcf8fSFrançois Tigeot
1364*3f2dd94aSFrançois Tigeot modifiers = i9xx_plane_format_modifiers;
13651e12ee3bSFrançois Tigeot if (IS_GEN6(dev_priv)) {
13662c84b0b6SFrançois Tigeot plane_formats = snb_plane_formats;
13672c84b0b6SFrançois Tigeot num_plane_formats = ARRAY_SIZE(snb_plane_formats);
13682c84b0b6SFrançois Tigeot } else {
1369*3f2dd94aSFrançois Tigeot plane_formats = g4x_plane_formats;
1370*3f2dd94aSFrançois Tigeot num_plane_formats = ARRAY_SIZE(g4x_plane_formats);
13712c84b0b6SFrançois Tigeot }
13725d0b1887SFrançois Tigeot }
13738e26cdf6SFrançois Tigeot
13744be47400SFrançois Tigeot if (INTEL_GEN(dev_priv) >= 9) {
13754be47400SFrançois Tigeot supported_rotations =
1376*3f2dd94aSFrançois Tigeot DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
1377*3f2dd94aSFrançois Tigeot DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
13784be47400SFrançois Tigeot } else if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
13794be47400SFrançois Tigeot supported_rotations =
1380*3f2dd94aSFrançois Tigeot DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
1381*3f2dd94aSFrançois Tigeot DRM_MODE_REFLECT_X;
13828e26cdf6SFrançois Tigeot } else {
13834be47400SFrançois Tigeot supported_rotations =
1384*3f2dd94aSFrançois Tigeot DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
1385e3adcf8fSFrançois Tigeot }
1386e3adcf8fSFrançois Tigeot
1387e3adcf8fSFrançois Tigeot intel_plane->pipe = pipe;
13888e26cdf6SFrançois Tigeot intel_plane->plane = plane;
1389a85cb24fSFrançois Tigeot intel_plane->id = PLANE_SPRITE0 + plane;
1390352ff8bdSFrançois Tigeot intel_plane->frontbuffer_bit = INTEL_FRONTBUFFER_SPRITE(pipe, plane);
13912c9916cdSFrançois Tigeot intel_plane->check_plane = intel_check_sprite_plane;
13928621f407SFrançois Tigeot
1393e3adcf8fSFrançois Tigeot possible_crtcs = (1 << pipe);
13948621f407SFrançois Tigeot
13954be47400SFrançois Tigeot if (INTEL_GEN(dev_priv) >= 9)
13964be47400SFrançois Tigeot ret = drm_universal_plane_init(&dev_priv->drm, &intel_plane->base,
1397*3f2dd94aSFrançois Tigeot possible_crtcs, &intel_sprite_plane_funcs,
13982c84b0b6SFrançois Tigeot plane_formats, num_plane_formats,
1399*3f2dd94aSFrançois Tigeot modifiers,
14001487f786SFrançois Tigeot DRM_PLANE_TYPE_OVERLAY,
14011487f786SFrançois Tigeot "plane %d%c", plane + 2, pipe_name(pipe));
14021487f786SFrançois Tigeot else
14034be47400SFrançois Tigeot ret = drm_universal_plane_init(&dev_priv->drm, &intel_plane->base,
1404*3f2dd94aSFrançois Tigeot possible_crtcs, &intel_sprite_plane_funcs,
14051487f786SFrançois Tigeot plane_formats, num_plane_formats,
1406*3f2dd94aSFrançois Tigeot modifiers,
14071487f786SFrançois Tigeot DRM_PLANE_TYPE_OVERLAY,
14081487f786SFrançois Tigeot "sprite %c", sprite_name(pipe, plane));
14098621f407SFrançois Tigeot if (ret)
14108621f407SFrançois Tigeot goto fail;
1411e3adcf8fSFrançois Tigeot
14124be47400SFrançois Tigeot drm_plane_create_rotation_property(&intel_plane->base,
1413*3f2dd94aSFrançois Tigeot DRM_MODE_ROTATE_0,
14144be47400SFrançois Tigeot supported_rotations);
14152c9916cdSFrançois Tigeot
14162c9916cdSFrançois Tigeot drm_plane_helper_add(&intel_plane->base, &intel_plane_helper_funcs);
14171b13d190SFrançois Tigeot
14184be47400SFrançois Tigeot return intel_plane;
14198621f407SFrançois Tigeot
14208621f407SFrançois Tigeot fail:
14218621f407SFrançois Tigeot kfree(state);
14228621f407SFrançois Tigeot kfree(intel_plane);
14238621f407SFrançois Tigeot
14244be47400SFrançois Tigeot return ERR_PTR(ret);
1425e3adcf8fSFrançois Tigeot }
1426