Rev 4560 | Rev 5354 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4560 | Rev 5060 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright © 2011 Intel Corporation |
2 | * Copyright © 2011 Intel Corporation |
3 | * |
3 | * |
4 | * Permission is hereby granted, free of charge, to any person obtaining a |
4 | * Permission is hereby granted, free of charge, to any person obtaining a |
5 | * copy of this software and associated documentation files (the "Software"), |
5 | * copy of this software and associated documentation files (the "Software"), |
6 | * to deal in the Software without restriction, including without limitation |
6 | * to deal in the Software without restriction, including without limitation |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
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 |
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: |
9 | * Software is furnished to do so, subject to the following conditions: |
10 | * |
10 | * |
11 | * The above copyright notice and this permission notice (including the next |
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 |
12 | * paragraph) shall be included in all copies or substantial portions of the |
13 | * Software. |
13 | * Software. |
14 | * |
14 | * |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
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, |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
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 |
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, |
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 |
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
21 | * SOFTWARE. |
21 | * SOFTWARE. |
22 | * |
22 | * |
23 | * Authors: |
23 | * Authors: |
24 | * Jesse Barnes |
24 | * Jesse Barnes |
25 | * |
25 | * |
26 | * New plane/sprite handling. |
26 | * New plane/sprite handling. |
27 | * |
27 | * |
28 | * The older chips had a separate interface for programming plane related |
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 |
29 | * registers; newer ones are much simpler and we can use the new DRM plane |
30 | * support. |
30 | * support. |
31 | */ |
31 | */ |
32 | #include |
32 | #include |
33 | #include |
33 | #include |
34 | #include |
34 | #include |
35 | #include |
35 | #include |
36 | #include "intel_drv.h" |
36 | #include "intel_drv.h" |
37 | #include |
37 | #include |
38 | #include "i915_drv.h" |
38 | #include "i915_drv.h" |
- | 39 | ||
- | 40 | static int usecs_to_scanlines(const struct drm_display_mode *mode, int usecs) |
|
- | 41 | { |
|
- | 42 | /* paranoia */ |
|
- | 43 | if (!mode->crtc_htotal) |
|
- | 44 | return 1; |
|
- | 45 | ||
- | 46 | return DIV_ROUND_UP(usecs * mode->crtc_clock, 1000 * mode->crtc_htotal); |
|
- | 47 | } |
|
- | 48 | ||
- | 49 | static bool intel_pipe_update_start(struct intel_crtc *crtc, uint32_t *start_vbl_count) |
|
- | 50 | { |
|
- | 51 | struct drm_device *dev = crtc->base.dev; |
|
- | 52 | const struct drm_display_mode *mode = &crtc->config.adjusted_mode; |
|
- | 53 | enum pipe pipe = crtc->pipe; |
|
- | 54 | long timeout = msecs_to_jiffies_timeout(1); |
|
- | 55 | int scanline, min, max, vblank_start; |
|
- | 56 | DEFINE_WAIT(wait); |
|
- | 57 | ||
- | 58 | WARN_ON(!drm_modeset_is_locked(&crtc->base.mutex)); |
|
- | 59 | ||
- | 60 | vblank_start = mode->crtc_vblank_start; |
|
- | 61 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
|
- | 62 | vblank_start = DIV_ROUND_UP(vblank_start, 2); |
|
- | 63 | ||
- | 64 | /* FIXME needs to be calibrated sensibly */ |
|
- | 65 | min = vblank_start - usecs_to_scanlines(mode, 100); |
|
- | 66 | max = vblank_start - 1; |
|
- | 67 | ||
- | 68 | if (min <= 0 || max <= 0) |
|
- | 69 | return false; |
|
- | 70 | ||
- | 71 | // if (WARN_ON(drm_vblank_get(dev, pipe))) |
|
- | 72 | // return false; |
|
- | 73 | ||
- | 74 | // local_irq_disable(); |
|
- | 75 | ||
- | 76 | // trace_i915_pipe_update_start(crtc, min, max); |
|
- | 77 | ||
- | 78 | for (;;) { |
|
- | 79 | /* |
|
- | 80 | * prepare_to_wait() has a memory barrier, which guarantees |
|
- | 81 | * other CPUs can see the task state update by the time we |
|
- | 82 | * read the scanline. |
|
- | 83 | */ |
|
- | 84 | prepare_to_wait(&crtc->vbl_wait, &wait, TASK_UNINTERRUPTIBLE); |
|
- | 85 | ||
- | 86 | scanline = intel_get_crtc_scanline(crtc); |
|
- | 87 | if (scanline < min || scanline > max) |
|
- | 88 | break; |
|
- | 89 | ||
- | 90 | if (timeout <= 0) { |
|
- | 91 | DRM_ERROR("Potential atomic update failure on pipe %c\n", |
|
- | 92 | pipe_name(crtc->pipe)); |
|
- | 93 | break; |
|
- | 94 | } |
|
- | 95 | ||
- | 96 | // local_irq_enable(); |
|
- | 97 | ||
- | 98 | schedule_timeout(timeout); |
|
- | 99 | timeout = 0; |
|
- | 100 | // local_irq_disable(); |
|
- | 101 | } |
|
- | 102 | ||
- | 103 | finish_wait(&crtc->vbl_wait, &wait); |
|
- | 104 | ||
- | 105 | // drm_vblank_put(dev, pipe); |
|
- | 106 | ||
- | 107 | *start_vbl_count = dev->driver->get_vblank_counter(dev, pipe); |
|
- | 108 | ||
- | 109 | // trace_i915_pipe_update_vblank_evaded(crtc, min, max, *start_vbl_count); |
|
- | 110 | ||
- | 111 | return true; |
|
- | 112 | } |
|
- | 113 | ||
- | 114 | static void intel_pipe_update_end(struct intel_crtc *crtc, u32 start_vbl_count) |
|
- | 115 | { |
|
- | 116 | struct drm_device *dev = crtc->base.dev; |
|
- | 117 | enum pipe pipe = crtc->pipe; |
|
- | 118 | u32 end_vbl_count = dev->driver->get_vblank_counter(dev, pipe); |
|
- | 119 | ||
- | 120 | // trace_i915_pipe_update_end(crtc, end_vbl_count); |
|
- | 121 | ||
- | 122 | // local_irq_enable(); |
|
- | 123 | ||
- | 124 | if (start_vbl_count != end_vbl_count) |
|
- | 125 | DRM_ERROR("Atomic update failure on pipe %c (start=%u end=%u)\n", |
|
- | 126 | pipe_name(pipe), start_vbl_count, end_vbl_count); |
|
- | 127 | } |
|
- | 128 | ||
- | 129 | static void intel_update_primary_plane(struct intel_crtc *crtc) |
|
- | 130 | { |
|
- | 131 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
|
- | 132 | int reg = DSPCNTR(crtc->plane); |
|
- | 133 | ||
- | 134 | if (crtc->primary_enabled) |
|
- | 135 | I915_WRITE(reg, I915_READ(reg) | DISPLAY_PLANE_ENABLE); |
|
- | 136 | else |
|
- | 137 | I915_WRITE(reg, I915_READ(reg) & ~DISPLAY_PLANE_ENABLE); |
|
- | 138 | } |
|
39 | 139 | ||
40 | static void |
140 | static void |
41 | vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc, |
141 | vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc, |
42 | struct drm_framebuffer *fb, |
142 | struct drm_framebuffer *fb, |
43 | struct drm_i915_gem_object *obj, int crtc_x, int crtc_y, |
143 | struct drm_i915_gem_object *obj, int crtc_x, int crtc_y, |
44 | unsigned int crtc_w, unsigned int crtc_h, |
144 | unsigned int crtc_w, unsigned int crtc_h, |
45 | uint32_t x, uint32_t y, |
145 | uint32_t x, uint32_t y, |
46 | uint32_t src_w, uint32_t src_h) |
146 | uint32_t src_w, uint32_t src_h) |
47 | { |
147 | { |
48 | struct drm_device *dev = dplane->dev; |
148 | struct drm_device *dev = dplane->dev; |
49 | struct drm_i915_private *dev_priv = dev->dev_private; |
149 | struct drm_i915_private *dev_priv = dev->dev_private; |
50 | struct intel_plane *intel_plane = to_intel_plane(dplane); |
150 | struct intel_plane *intel_plane = to_intel_plane(dplane); |
- | 151 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
|
51 | int pipe = intel_plane->pipe; |
152 | int pipe = intel_plane->pipe; |
52 | int plane = intel_plane->plane; |
153 | int plane = intel_plane->plane; |
53 | u32 sprctl; |
154 | u32 sprctl; |
54 | unsigned long sprsurf_offset, linear_offset; |
155 | unsigned long sprsurf_offset, linear_offset; |
55 | int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
156 | int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
- | 157 | u32 start_vbl_count; |
|
- | 158 | bool atomic_update; |
|
56 | 159 | ||
57 | sprctl = I915_READ(SPCNTR(pipe, plane)); |
160 | sprctl = I915_READ(SPCNTR(pipe, plane)); |
58 | 161 | ||
59 | /* Mask out pixel format bits in case we change it */ |
162 | /* Mask out pixel format bits in case we change it */ |
60 | sprctl &= ~SP_PIXFORMAT_MASK; |
163 | sprctl &= ~SP_PIXFORMAT_MASK; |
61 | sprctl &= ~SP_YUV_BYTE_ORDER_MASK; |
164 | sprctl &= ~SP_YUV_BYTE_ORDER_MASK; |
62 | sprctl &= ~SP_TILED; |
165 | sprctl &= ~SP_TILED; |
63 | 166 | ||
64 | switch (fb->pixel_format) { |
167 | switch (fb->pixel_format) { |
65 | case DRM_FORMAT_YUYV: |
168 | case DRM_FORMAT_YUYV: |
66 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV; |
169 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV; |
67 | break; |
170 | break; |
68 | case DRM_FORMAT_YVYU: |
171 | case DRM_FORMAT_YVYU: |
69 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU; |
172 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU; |
70 | break; |
173 | break; |
71 | case DRM_FORMAT_UYVY: |
174 | case DRM_FORMAT_UYVY: |
72 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY; |
175 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY; |
73 | break; |
176 | break; |
74 | case DRM_FORMAT_VYUY: |
177 | case DRM_FORMAT_VYUY: |
75 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY; |
178 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY; |
76 | break; |
179 | break; |
77 | case DRM_FORMAT_RGB565: |
180 | case DRM_FORMAT_RGB565: |
78 | sprctl |= SP_FORMAT_BGR565; |
181 | sprctl |= SP_FORMAT_BGR565; |
79 | break; |
182 | break; |
80 | case DRM_FORMAT_XRGB8888: |
183 | case DRM_FORMAT_XRGB8888: |
81 | sprctl |= SP_FORMAT_BGRX8888; |
184 | sprctl |= SP_FORMAT_BGRX8888; |
82 | break; |
185 | break; |
83 | case DRM_FORMAT_ARGB8888: |
186 | case DRM_FORMAT_ARGB8888: |
84 | sprctl |= SP_FORMAT_BGRA8888; |
187 | sprctl |= SP_FORMAT_BGRA8888; |
85 | break; |
188 | break; |
86 | case DRM_FORMAT_XBGR2101010: |
189 | case DRM_FORMAT_XBGR2101010: |
87 | sprctl |= SP_FORMAT_RGBX1010102; |
190 | sprctl |= SP_FORMAT_RGBX1010102; |
88 | break; |
191 | break; |
89 | case DRM_FORMAT_ABGR2101010: |
192 | case DRM_FORMAT_ABGR2101010: |
90 | sprctl |= SP_FORMAT_RGBA1010102; |
193 | sprctl |= SP_FORMAT_RGBA1010102; |
91 | break; |
194 | break; |
92 | case DRM_FORMAT_XBGR8888: |
195 | case DRM_FORMAT_XBGR8888: |
93 | sprctl |= SP_FORMAT_RGBX8888; |
196 | sprctl |= SP_FORMAT_RGBX8888; |
94 | break; |
197 | break; |
95 | case DRM_FORMAT_ABGR8888: |
198 | case DRM_FORMAT_ABGR8888: |
96 | sprctl |= SP_FORMAT_RGBA8888; |
199 | sprctl |= SP_FORMAT_RGBA8888; |
97 | break; |
200 | break; |
98 | default: |
201 | default: |
99 | /* |
202 | /* |
100 | * If we get here one of the upper layers failed to filter |
203 | * If we get here one of the upper layers failed to filter |
101 | * out the unsupported plane formats |
204 | * out the unsupported plane formats |
102 | */ |
205 | */ |
103 | BUG(); |
206 | BUG(); |
104 | break; |
207 | break; |
105 | } |
208 | } |
106 | 209 | ||
107 | /* |
210 | /* |
108 | * Enable gamma to match primary/cursor plane behaviour. |
211 | * Enable gamma to match primary/cursor plane behaviour. |
109 | * FIXME should be user controllable via propertiesa. |
212 | * FIXME should be user controllable via propertiesa. |
110 | */ |
213 | */ |
111 | sprctl |= SP_GAMMA_ENABLE; |
214 | sprctl |= SP_GAMMA_ENABLE; |
112 | 215 | ||
113 | if (obj->tiling_mode != I915_TILING_NONE) |
216 | if (obj->tiling_mode != I915_TILING_NONE) |
114 | sprctl |= SP_TILED; |
217 | sprctl |= SP_TILED; |
115 | 218 | ||
116 | sprctl |= SP_ENABLE; |
219 | sprctl |= SP_ENABLE; |
117 | 220 | ||
- | 221 | intel_update_sprite_watermarks(dplane, crtc, src_w, src_h, |
|
118 | intel_update_sprite_watermarks(dplane, crtc, src_w, pixel_size, true, |
222 | pixel_size, true, |
119 | src_w != crtc_w || src_h != crtc_h); |
223 | src_w != crtc_w || src_h != crtc_h); |
120 | 224 | ||
121 | /* Sizes are 0 based */ |
225 | /* Sizes are 0 based */ |
122 | src_w--; |
226 | src_w--; |
123 | src_h--; |
227 | src_h--; |
124 | crtc_w--; |
228 | crtc_w--; |
125 | crtc_h--; |
229 | crtc_h--; |
126 | - | ||
127 | I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]); |
- | |
128 | I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x); |
- | |
129 | 230 | ||
130 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
231 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
131 | sprsurf_offset = intel_gen4_compute_page_offset(&x, &y, |
232 | sprsurf_offset = intel_gen4_compute_page_offset(&x, &y, |
132 | obj->tiling_mode, |
233 | obj->tiling_mode, |
133 | pixel_size, |
234 | pixel_size, |
134 | fb->pitches[0]); |
235 | fb->pitches[0]); |
135 | linear_offset -= sprsurf_offset; |
236 | linear_offset -= sprsurf_offset; |
- | 237 | ||
- | 238 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
|
- | 239 | ||
- | 240 | intel_update_primary_plane(intel_crtc); |
|
- | 241 | ||
- | 242 | I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]); |
|
- | 243 | I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x); |
|
136 | 244 | ||
137 | if (obj->tiling_mode != I915_TILING_NONE) |
245 | if (obj->tiling_mode != I915_TILING_NONE) |
138 | I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x); |
246 | I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x); |
139 | else |
247 | else |
140 | I915_WRITE(SPLINOFF(pipe, plane), linear_offset); |
248 | I915_WRITE(SPLINOFF(pipe, plane), linear_offset); |
141 | 249 | ||
142 | I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w); |
250 | I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w); |
143 | I915_WRITE(SPCNTR(pipe, plane), sprctl); |
251 | I915_WRITE(SPCNTR(pipe, plane), sprctl); |
144 | I915_WRITE(SPSURF(pipe, plane), i915_gem_obj_ggtt_offset(obj) + |
252 | I915_WRITE(SPSURF(pipe, plane), i915_gem_obj_ggtt_offset(obj) + |
145 | sprsurf_offset); |
253 | sprsurf_offset); |
- | 254 | ||
146 | POSTING_READ(SPSURF(pipe, plane)); |
255 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
- | 256 | ||
- | 257 | if (atomic_update) |
|
- | 258 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
|
147 | } |
259 | } |
148 | 260 | ||
149 | static void |
261 | static void |
150 | vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc) |
262 | vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc) |
151 | { |
263 | { |
152 | struct drm_device *dev = dplane->dev; |
264 | struct drm_device *dev = dplane->dev; |
153 | struct drm_i915_private *dev_priv = dev->dev_private; |
265 | struct drm_i915_private *dev_priv = dev->dev_private; |
154 | struct intel_plane *intel_plane = to_intel_plane(dplane); |
266 | struct intel_plane *intel_plane = to_intel_plane(dplane); |
- | 267 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
|
155 | int pipe = intel_plane->pipe; |
268 | int pipe = intel_plane->pipe; |
156 | int plane = intel_plane->plane; |
269 | int plane = intel_plane->plane; |
- | 270 | u32 start_vbl_count; |
|
- | 271 | bool atomic_update; |
|
- | 272 | ||
- | 273 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
|
- | 274 | ||
- | 275 | intel_update_primary_plane(intel_crtc); |
|
157 | 276 | ||
158 | I915_WRITE(SPCNTR(pipe, plane), I915_READ(SPCNTR(pipe, plane)) & |
277 | I915_WRITE(SPCNTR(pipe, plane), I915_READ(SPCNTR(pipe, plane)) & |
159 | ~SP_ENABLE); |
278 | ~SP_ENABLE); |
160 | /* Activate double buffered register update */ |
279 | /* Activate double buffered register update */ |
161 | I915_WRITE(SPSURF(pipe, plane), 0); |
280 | I915_WRITE(SPSURF(pipe, plane), 0); |
162 | POSTING_READ(SPSURF(pipe, plane)); |
- | |
- | 281 | ||
- | 282 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
|
- | 283 | ||
- | 284 | if (atomic_update) |
|
- | 285 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
|
163 | 286 | ||
164 | intel_update_sprite_watermarks(dplane, crtc, 0, 0, false, false); |
287 | intel_update_sprite_watermarks(dplane, crtc, 0, 0, 0, false, false); |
165 | } |
288 | } |
166 | 289 | ||
167 | static int |
290 | static int |
168 | vlv_update_colorkey(struct drm_plane *dplane, |
291 | vlv_update_colorkey(struct drm_plane *dplane, |
169 | struct drm_intel_sprite_colorkey *key) |
292 | struct drm_intel_sprite_colorkey *key) |
170 | { |
293 | { |
171 | struct drm_device *dev = dplane->dev; |
294 | struct drm_device *dev = dplane->dev; |
172 | struct drm_i915_private *dev_priv = dev->dev_private; |
295 | struct drm_i915_private *dev_priv = dev->dev_private; |
173 | struct intel_plane *intel_plane = to_intel_plane(dplane); |
296 | struct intel_plane *intel_plane = to_intel_plane(dplane); |
174 | int pipe = intel_plane->pipe; |
297 | int pipe = intel_plane->pipe; |
175 | int plane = intel_plane->plane; |
298 | int plane = intel_plane->plane; |
176 | u32 sprctl; |
299 | u32 sprctl; |
177 | 300 | ||
178 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
301 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
179 | return -EINVAL; |
302 | return -EINVAL; |
180 | 303 | ||
181 | I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value); |
304 | I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value); |
182 | I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value); |
305 | I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value); |
183 | I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask); |
306 | I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask); |
184 | 307 | ||
185 | sprctl = I915_READ(SPCNTR(pipe, plane)); |
308 | sprctl = I915_READ(SPCNTR(pipe, plane)); |
186 | sprctl &= ~SP_SOURCE_KEY; |
309 | sprctl &= ~SP_SOURCE_KEY; |
187 | if (key->flags & I915_SET_COLORKEY_SOURCE) |
310 | if (key->flags & I915_SET_COLORKEY_SOURCE) |
188 | sprctl |= SP_SOURCE_KEY; |
311 | sprctl |= SP_SOURCE_KEY; |
189 | I915_WRITE(SPCNTR(pipe, plane), sprctl); |
312 | I915_WRITE(SPCNTR(pipe, plane), sprctl); |
190 | 313 | ||
191 | POSTING_READ(SPKEYMSK(pipe, plane)); |
314 | POSTING_READ(SPKEYMSK(pipe, plane)); |
192 | 315 | ||
193 | return 0; |
316 | return 0; |
194 | } |
317 | } |
195 | 318 | ||
196 | static void |
319 | static void |
197 | vlv_get_colorkey(struct drm_plane *dplane, |
320 | vlv_get_colorkey(struct drm_plane *dplane, |
198 | struct drm_intel_sprite_colorkey *key) |
321 | struct drm_intel_sprite_colorkey *key) |
199 | { |
322 | { |
200 | struct drm_device *dev = dplane->dev; |
323 | struct drm_device *dev = dplane->dev; |
201 | struct drm_i915_private *dev_priv = dev->dev_private; |
324 | struct drm_i915_private *dev_priv = dev->dev_private; |
202 | struct intel_plane *intel_plane = to_intel_plane(dplane); |
325 | struct intel_plane *intel_plane = to_intel_plane(dplane); |
203 | int pipe = intel_plane->pipe; |
326 | int pipe = intel_plane->pipe; |
204 | int plane = intel_plane->plane; |
327 | int plane = intel_plane->plane; |
205 | u32 sprctl; |
328 | u32 sprctl; |
206 | 329 | ||
207 | key->min_value = I915_READ(SPKEYMINVAL(pipe, plane)); |
330 | key->min_value = I915_READ(SPKEYMINVAL(pipe, plane)); |
208 | key->max_value = I915_READ(SPKEYMAXVAL(pipe, plane)); |
331 | key->max_value = I915_READ(SPKEYMAXVAL(pipe, plane)); |
209 | key->channel_mask = I915_READ(SPKEYMSK(pipe, plane)); |
332 | key->channel_mask = I915_READ(SPKEYMSK(pipe, plane)); |
210 | 333 | ||
211 | sprctl = I915_READ(SPCNTR(pipe, plane)); |
334 | sprctl = I915_READ(SPCNTR(pipe, plane)); |
212 | if (sprctl & SP_SOURCE_KEY) |
335 | if (sprctl & SP_SOURCE_KEY) |
213 | key->flags = I915_SET_COLORKEY_SOURCE; |
336 | key->flags = I915_SET_COLORKEY_SOURCE; |
214 | else |
337 | else |
215 | key->flags = I915_SET_COLORKEY_NONE; |
338 | key->flags = I915_SET_COLORKEY_NONE; |
216 | } |
339 | } |
217 | 340 | ||
218 | static void |
341 | static void |
219 | ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc, |
342 | ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc, |
220 | struct drm_framebuffer *fb, |
343 | struct drm_framebuffer *fb, |
221 | struct drm_i915_gem_object *obj, int crtc_x, int crtc_y, |
344 | struct drm_i915_gem_object *obj, int crtc_x, int crtc_y, |
222 | unsigned int crtc_w, unsigned int crtc_h, |
345 | unsigned int crtc_w, unsigned int crtc_h, |
223 | uint32_t x, uint32_t y, |
346 | uint32_t x, uint32_t y, |
224 | uint32_t src_w, uint32_t src_h) |
347 | uint32_t src_w, uint32_t src_h) |
225 | { |
348 | { |
226 | struct drm_device *dev = plane->dev; |
349 | struct drm_device *dev = plane->dev; |
227 | struct drm_i915_private *dev_priv = dev->dev_private; |
350 | struct drm_i915_private *dev_priv = dev->dev_private; |
228 | struct intel_plane *intel_plane = to_intel_plane(plane); |
351 | struct intel_plane *intel_plane = to_intel_plane(plane); |
- | 352 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
|
229 | int pipe = intel_plane->pipe; |
353 | int pipe = intel_plane->pipe; |
230 | u32 sprctl, sprscale = 0; |
354 | u32 sprctl, sprscale = 0; |
231 | unsigned long sprsurf_offset, linear_offset; |
355 | unsigned long sprsurf_offset, linear_offset; |
232 | int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
356 | int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
- | 357 | u32 start_vbl_count; |
|
- | 358 | bool atomic_update; |
|
233 | 359 | ||
234 | sprctl = I915_READ(SPRCTL(pipe)); |
360 | sprctl = I915_READ(SPRCTL(pipe)); |
235 | 361 | ||
236 | /* Mask out pixel format bits in case we change it */ |
362 | /* Mask out pixel format bits in case we change it */ |
237 | sprctl &= ~SPRITE_PIXFORMAT_MASK; |
363 | sprctl &= ~SPRITE_PIXFORMAT_MASK; |
238 | sprctl &= ~SPRITE_RGB_ORDER_RGBX; |
364 | sprctl &= ~SPRITE_RGB_ORDER_RGBX; |
239 | sprctl &= ~SPRITE_YUV_BYTE_ORDER_MASK; |
365 | sprctl &= ~SPRITE_YUV_BYTE_ORDER_MASK; |
240 | sprctl &= ~SPRITE_TILED; |
366 | sprctl &= ~SPRITE_TILED; |
241 | 367 | ||
242 | switch (fb->pixel_format) { |
368 | switch (fb->pixel_format) { |
243 | case DRM_FORMAT_XBGR8888: |
369 | case DRM_FORMAT_XBGR8888: |
244 | sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX; |
370 | sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX; |
245 | break; |
371 | break; |
246 | case DRM_FORMAT_XRGB8888: |
372 | case DRM_FORMAT_XRGB8888: |
247 | sprctl |= SPRITE_FORMAT_RGBX888; |
373 | sprctl |= SPRITE_FORMAT_RGBX888; |
248 | break; |
374 | break; |
249 | case DRM_FORMAT_YUYV: |
375 | case DRM_FORMAT_YUYV: |
250 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV; |
376 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV; |
251 | break; |
377 | break; |
252 | case DRM_FORMAT_YVYU: |
378 | case DRM_FORMAT_YVYU: |
253 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU; |
379 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU; |
254 | break; |
380 | break; |
255 | case DRM_FORMAT_UYVY: |
381 | case DRM_FORMAT_UYVY: |
256 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY; |
382 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY; |
257 | break; |
383 | break; |
258 | case DRM_FORMAT_VYUY: |
384 | case DRM_FORMAT_VYUY: |
259 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY; |
385 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY; |
260 | break; |
386 | break; |
261 | default: |
387 | default: |
262 | BUG(); |
388 | BUG(); |
263 | } |
389 | } |
264 | 390 | ||
265 | /* |
391 | /* |
266 | * Enable gamma to match primary/cursor plane behaviour. |
392 | * Enable gamma to match primary/cursor plane behaviour. |
267 | * FIXME should be user controllable via propertiesa. |
393 | * FIXME should be user controllable via propertiesa. |
268 | */ |
394 | */ |
269 | sprctl |= SPRITE_GAMMA_ENABLE; |
395 | sprctl |= SPRITE_GAMMA_ENABLE; |
270 | 396 | ||
271 | if (obj->tiling_mode != I915_TILING_NONE) |
397 | if (obj->tiling_mode != I915_TILING_NONE) |
272 | sprctl |= SPRITE_TILED; |
398 | sprctl |= SPRITE_TILED; |
273 | 399 | ||
274 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
400 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
275 | sprctl &= ~SPRITE_TRICKLE_FEED_DISABLE; |
401 | sprctl &= ~SPRITE_TRICKLE_FEED_DISABLE; |
276 | else |
402 | else |
277 | sprctl |= SPRITE_TRICKLE_FEED_DISABLE; |
403 | sprctl |= SPRITE_TRICKLE_FEED_DISABLE; |
278 | 404 | ||
279 | sprctl |= SPRITE_ENABLE; |
405 | sprctl |= SPRITE_ENABLE; |
280 | 406 | ||
281 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
407 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
282 | sprctl |= SPRITE_PIPE_CSC_ENABLE; |
408 | sprctl |= SPRITE_PIPE_CSC_ENABLE; |
283 | 409 | ||
- | 410 | intel_update_sprite_watermarks(plane, crtc, src_w, src_h, pixel_size, |
|
284 | intel_update_sprite_watermarks(plane, crtc, src_w, pixel_size, true, |
411 | true, |
285 | src_w != crtc_w || src_h != crtc_h); |
412 | src_w != crtc_w || src_h != crtc_h); |
286 | 413 | ||
287 | /* Sizes are 0 based */ |
414 | /* Sizes are 0 based */ |
288 | src_w--; |
415 | src_w--; |
289 | src_h--; |
416 | src_h--; |
290 | crtc_w--; |
417 | crtc_w--; |
291 | crtc_h--; |
418 | crtc_h--; |
292 | 419 | ||
293 | if (crtc_w != src_w || crtc_h != src_h) |
420 | if (crtc_w != src_w || crtc_h != src_h) |
294 | sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h; |
421 | sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h; |
295 | - | ||
296 | I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]); |
- | |
297 | I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x); |
- | |
298 | 422 | ||
299 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
423 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
300 | sprsurf_offset = |
424 | sprsurf_offset = |
301 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
425 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
302 | pixel_size, fb->pitches[0]); |
426 | pixel_size, fb->pitches[0]); |
303 | linear_offset -= sprsurf_offset; |
427 | linear_offset -= sprsurf_offset; |
- | 428 | ||
- | 429 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
|
- | 430 | ||
- | 431 | intel_update_primary_plane(intel_crtc); |
|
- | 432 | ||
- | 433 | I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]); |
|
- | 434 | I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x); |
|
304 | 435 | ||
305 | /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET |
436 | /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET |
306 | * register */ |
437 | * register */ |
307 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
438 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
308 | I915_WRITE(SPROFFSET(pipe), (y << 16) | x); |
439 | I915_WRITE(SPROFFSET(pipe), (y << 16) | x); |
309 | else if (obj->tiling_mode != I915_TILING_NONE) |
440 | else if (obj->tiling_mode != I915_TILING_NONE) |
310 | I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x); |
441 | I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x); |
311 | else |
442 | else |
312 | I915_WRITE(SPRLINOFF(pipe), linear_offset); |
443 | I915_WRITE(SPRLINOFF(pipe), linear_offset); |
313 | 444 | ||
314 | I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w); |
445 | I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w); |
315 | if (intel_plane->can_scale) |
446 | if (intel_plane->can_scale) |
316 | I915_WRITE(SPRSCALE(pipe), sprscale); |
447 | I915_WRITE(SPRSCALE(pipe), sprscale); |
317 | I915_WRITE(SPRCTL(pipe), sprctl); |
448 | I915_WRITE(SPRCTL(pipe), sprctl); |
318 | I915_WRITE(SPRSURF(pipe), |
449 | I915_WRITE(SPRSURF(pipe), |
319 | i915_gem_obj_ggtt_offset(obj) + sprsurf_offset); |
450 | i915_gem_obj_ggtt_offset(obj) + sprsurf_offset); |
- | 451 | ||
- | 452 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
|
- | 453 | ||
320 | POSTING_READ(SPRSURF(pipe)); |
454 | if (atomic_update) |
- | 455 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
|
321 | } |
456 | } |
322 | 457 | ||
323 | static void |
458 | static void |
324 | ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc) |
459 | ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc) |
325 | { |
460 | { |
326 | struct drm_device *dev = plane->dev; |
461 | struct drm_device *dev = plane->dev; |
327 | struct drm_i915_private *dev_priv = dev->dev_private; |
462 | struct drm_i915_private *dev_priv = dev->dev_private; |
328 | struct intel_plane *intel_plane = to_intel_plane(plane); |
463 | struct intel_plane *intel_plane = to_intel_plane(plane); |
- | 464 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
|
329 | int pipe = intel_plane->pipe; |
465 | int pipe = intel_plane->pipe; |
- | 466 | u32 start_vbl_count; |
|
- | 467 | bool atomic_update; |
|
- | 468 | ||
- | 469 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
|
- | 470 | ||
- | 471 | intel_update_primary_plane(intel_crtc); |
|
330 | 472 | ||
331 | I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE); |
473 | I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE); |
332 | /* Can't leave the scaler enabled... */ |
474 | /* Can't leave the scaler enabled... */ |
333 | if (intel_plane->can_scale) |
475 | if (intel_plane->can_scale) |
334 | I915_WRITE(SPRSCALE(pipe), 0); |
476 | I915_WRITE(SPRSCALE(pipe), 0); |
335 | /* Activate double buffered register update */ |
477 | /* Activate double buffered register update */ |
336 | I915_WRITE(SPRSURF(pipe), 0); |
478 | I915_WRITE(SPRSURF(pipe), 0); |
- | 479 | ||
- | 480 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
|
- | 481 | ||
337 | POSTING_READ(SPRSURF(pipe)); |
482 | if (atomic_update) |
- | 483 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
|
338 | 484 | ||
339 | /* |
485 | /* |
340 | * Avoid underruns when disabling the sprite. |
486 | * Avoid underruns when disabling the sprite. |
341 | * FIXME remove once watermark updates are done properly. |
487 | * FIXME remove once watermark updates are done properly. |
342 | */ |
488 | */ |
343 | intel_wait_for_vblank(dev, pipe); |
489 | intel_wait_for_vblank(dev, pipe); |
344 | 490 | ||
345 | intel_update_sprite_watermarks(plane, crtc, 0, 0, false, false); |
491 | intel_update_sprite_watermarks(plane, crtc, 0, 0, 0, false, false); |
346 | } |
492 | } |
347 | 493 | ||
348 | static int |
494 | static int |
349 | ivb_update_colorkey(struct drm_plane *plane, |
495 | ivb_update_colorkey(struct drm_plane *plane, |
350 | struct drm_intel_sprite_colorkey *key) |
496 | struct drm_intel_sprite_colorkey *key) |
351 | { |
497 | { |
352 | struct drm_device *dev = plane->dev; |
498 | struct drm_device *dev = plane->dev; |
353 | struct drm_i915_private *dev_priv = dev->dev_private; |
499 | struct drm_i915_private *dev_priv = dev->dev_private; |
354 | struct intel_plane *intel_plane; |
500 | struct intel_plane *intel_plane; |
355 | u32 sprctl; |
501 | u32 sprctl; |
356 | int ret = 0; |
502 | int ret = 0; |
357 | 503 | ||
358 | intel_plane = to_intel_plane(plane); |
504 | intel_plane = to_intel_plane(plane); |
359 | 505 | ||
360 | I915_WRITE(SPRKEYVAL(intel_plane->pipe), key->min_value); |
506 | I915_WRITE(SPRKEYVAL(intel_plane->pipe), key->min_value); |
361 | I915_WRITE(SPRKEYMAX(intel_plane->pipe), key->max_value); |
507 | I915_WRITE(SPRKEYMAX(intel_plane->pipe), key->max_value); |
362 | I915_WRITE(SPRKEYMSK(intel_plane->pipe), key->channel_mask); |
508 | I915_WRITE(SPRKEYMSK(intel_plane->pipe), key->channel_mask); |
363 | 509 | ||
364 | sprctl = I915_READ(SPRCTL(intel_plane->pipe)); |
510 | sprctl = I915_READ(SPRCTL(intel_plane->pipe)); |
365 | sprctl &= ~(SPRITE_SOURCE_KEY | SPRITE_DEST_KEY); |
511 | sprctl &= ~(SPRITE_SOURCE_KEY | SPRITE_DEST_KEY); |
366 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
512 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
367 | sprctl |= SPRITE_DEST_KEY; |
513 | sprctl |= SPRITE_DEST_KEY; |
368 | else if (key->flags & I915_SET_COLORKEY_SOURCE) |
514 | else if (key->flags & I915_SET_COLORKEY_SOURCE) |
369 | sprctl |= SPRITE_SOURCE_KEY; |
515 | sprctl |= SPRITE_SOURCE_KEY; |
370 | I915_WRITE(SPRCTL(intel_plane->pipe), sprctl); |
516 | I915_WRITE(SPRCTL(intel_plane->pipe), sprctl); |
371 | 517 | ||
372 | POSTING_READ(SPRKEYMSK(intel_plane->pipe)); |
518 | POSTING_READ(SPRKEYMSK(intel_plane->pipe)); |
373 | 519 | ||
374 | return ret; |
520 | return ret; |
375 | } |
521 | } |
376 | 522 | ||
377 | static void |
523 | static void |
378 | ivb_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key) |
524 | ivb_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key) |
379 | { |
525 | { |
380 | struct drm_device *dev = plane->dev; |
526 | struct drm_device *dev = plane->dev; |
381 | struct drm_i915_private *dev_priv = dev->dev_private; |
527 | struct drm_i915_private *dev_priv = dev->dev_private; |
382 | struct intel_plane *intel_plane; |
528 | struct intel_plane *intel_plane; |
383 | u32 sprctl; |
529 | u32 sprctl; |
384 | 530 | ||
385 | intel_plane = to_intel_plane(plane); |
531 | intel_plane = to_intel_plane(plane); |
386 | 532 | ||
387 | key->min_value = I915_READ(SPRKEYVAL(intel_plane->pipe)); |
533 | key->min_value = I915_READ(SPRKEYVAL(intel_plane->pipe)); |
388 | key->max_value = I915_READ(SPRKEYMAX(intel_plane->pipe)); |
534 | key->max_value = I915_READ(SPRKEYMAX(intel_plane->pipe)); |
389 | key->channel_mask = I915_READ(SPRKEYMSK(intel_plane->pipe)); |
535 | key->channel_mask = I915_READ(SPRKEYMSK(intel_plane->pipe)); |
390 | key->flags = 0; |
536 | key->flags = 0; |
391 | 537 | ||
392 | sprctl = I915_READ(SPRCTL(intel_plane->pipe)); |
538 | sprctl = I915_READ(SPRCTL(intel_plane->pipe)); |
393 | 539 | ||
394 | if (sprctl & SPRITE_DEST_KEY) |
540 | if (sprctl & SPRITE_DEST_KEY) |
395 | key->flags = I915_SET_COLORKEY_DESTINATION; |
541 | key->flags = I915_SET_COLORKEY_DESTINATION; |
396 | else if (sprctl & SPRITE_SOURCE_KEY) |
542 | else if (sprctl & SPRITE_SOURCE_KEY) |
397 | key->flags = I915_SET_COLORKEY_SOURCE; |
543 | key->flags = I915_SET_COLORKEY_SOURCE; |
398 | else |
544 | else |
399 | key->flags = I915_SET_COLORKEY_NONE; |
545 | key->flags = I915_SET_COLORKEY_NONE; |
400 | } |
546 | } |
401 | 547 | ||
402 | static void |
548 | static void |
403 | ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc, |
549 | ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc, |
404 | struct drm_framebuffer *fb, |
550 | struct drm_framebuffer *fb, |
405 | struct drm_i915_gem_object *obj, int crtc_x, int crtc_y, |
551 | struct drm_i915_gem_object *obj, int crtc_x, int crtc_y, |
406 | unsigned int crtc_w, unsigned int crtc_h, |
552 | unsigned int crtc_w, unsigned int crtc_h, |
407 | uint32_t x, uint32_t y, |
553 | uint32_t x, uint32_t y, |
408 | uint32_t src_w, uint32_t src_h) |
554 | uint32_t src_w, uint32_t src_h) |
409 | { |
555 | { |
410 | struct drm_device *dev = plane->dev; |
556 | struct drm_device *dev = plane->dev; |
411 | struct drm_i915_private *dev_priv = dev->dev_private; |
557 | struct drm_i915_private *dev_priv = dev->dev_private; |
412 | struct intel_plane *intel_plane = to_intel_plane(plane); |
558 | struct intel_plane *intel_plane = to_intel_plane(plane); |
- | 559 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
|
413 | int pipe = intel_plane->pipe; |
560 | int pipe = intel_plane->pipe; |
414 | unsigned long dvssurf_offset, linear_offset; |
561 | unsigned long dvssurf_offset, linear_offset; |
415 | u32 dvscntr, dvsscale; |
562 | u32 dvscntr, dvsscale; |
416 | int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
563 | int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
- | 564 | u32 start_vbl_count; |
|
- | 565 | bool atomic_update; |
|
417 | 566 | ||
418 | dvscntr = I915_READ(DVSCNTR(pipe)); |
567 | dvscntr = I915_READ(DVSCNTR(pipe)); |
419 | 568 | ||
420 | /* Mask out pixel format bits in case we change it */ |
569 | /* Mask out pixel format bits in case we change it */ |
421 | dvscntr &= ~DVS_PIXFORMAT_MASK; |
570 | dvscntr &= ~DVS_PIXFORMAT_MASK; |
422 | dvscntr &= ~DVS_RGB_ORDER_XBGR; |
571 | dvscntr &= ~DVS_RGB_ORDER_XBGR; |
423 | dvscntr &= ~DVS_YUV_BYTE_ORDER_MASK; |
572 | dvscntr &= ~DVS_YUV_BYTE_ORDER_MASK; |
424 | dvscntr &= ~DVS_TILED; |
573 | dvscntr &= ~DVS_TILED; |
425 | 574 | ||
426 | switch (fb->pixel_format) { |
575 | switch (fb->pixel_format) { |
427 | case DRM_FORMAT_XBGR8888: |
576 | case DRM_FORMAT_XBGR8888: |
428 | dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR; |
577 | dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR; |
429 | break; |
578 | break; |
430 | case DRM_FORMAT_XRGB8888: |
579 | case DRM_FORMAT_XRGB8888: |
431 | dvscntr |= DVS_FORMAT_RGBX888; |
580 | dvscntr |= DVS_FORMAT_RGBX888; |
432 | break; |
581 | break; |
433 | case DRM_FORMAT_YUYV: |
582 | case DRM_FORMAT_YUYV: |
434 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV; |
583 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV; |
435 | break; |
584 | break; |
436 | case DRM_FORMAT_YVYU: |
585 | case DRM_FORMAT_YVYU: |
437 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU; |
586 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU; |
438 | break; |
587 | break; |
439 | case DRM_FORMAT_UYVY: |
588 | case DRM_FORMAT_UYVY: |
440 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY; |
589 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY; |
441 | break; |
590 | break; |
442 | case DRM_FORMAT_VYUY: |
591 | case DRM_FORMAT_VYUY: |
443 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY; |
592 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY; |
444 | break; |
593 | break; |
445 | default: |
594 | default: |
446 | BUG(); |
595 | BUG(); |
447 | } |
596 | } |
448 | 597 | ||
449 | /* |
598 | /* |
450 | * Enable gamma to match primary/cursor plane behaviour. |
599 | * Enable gamma to match primary/cursor plane behaviour. |
451 | * FIXME should be user controllable via propertiesa. |
600 | * FIXME should be user controllable via propertiesa. |
452 | */ |
601 | */ |
453 | dvscntr |= DVS_GAMMA_ENABLE; |
602 | dvscntr |= DVS_GAMMA_ENABLE; |
454 | 603 | ||
455 | if (obj->tiling_mode != I915_TILING_NONE) |
604 | if (obj->tiling_mode != I915_TILING_NONE) |
456 | dvscntr |= DVS_TILED; |
605 | dvscntr |= DVS_TILED; |
457 | 606 | ||
458 | if (IS_GEN6(dev)) |
607 | if (IS_GEN6(dev)) |
459 | dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */ |
608 | dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */ |
460 | dvscntr |= DVS_ENABLE; |
609 | dvscntr |= DVS_ENABLE; |
461 | 610 | ||
- | 611 | intel_update_sprite_watermarks(plane, crtc, src_w, src_h, |
|
462 | intel_update_sprite_watermarks(plane, crtc, src_w, pixel_size, true, |
612 | pixel_size, true, |
463 | src_w != crtc_w || src_h != crtc_h); |
613 | src_w != crtc_w || src_h != crtc_h); |
464 | 614 | ||
465 | /* Sizes are 0 based */ |
615 | /* Sizes are 0 based */ |
466 | src_w--; |
616 | src_w--; |
467 | src_h--; |
617 | src_h--; |
468 | crtc_w--; |
618 | crtc_w--; |
469 | crtc_h--; |
619 | crtc_h--; |
470 | 620 | ||
471 | dvsscale = 0; |
621 | dvsscale = 0; |
472 | if (crtc_w != src_w || crtc_h != src_h) |
622 | if (crtc_w != src_w || crtc_h != src_h) |
473 | dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h; |
623 | dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h; |
474 | - | ||
475 | I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]); |
- | |
476 | I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x); |
- | |
477 | 624 | ||
478 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
625 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
479 | dvssurf_offset = |
626 | dvssurf_offset = |
480 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
627 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
481 | pixel_size, fb->pitches[0]); |
628 | pixel_size, fb->pitches[0]); |
482 | linear_offset -= dvssurf_offset; |
629 | linear_offset -= dvssurf_offset; |
- | 630 | ||
- | 631 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
|
- | 632 | ||
- | 633 | intel_update_primary_plane(intel_crtc); |
|
- | 634 | ||
- | 635 | I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]); |
|
- | 636 | I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x); |
|
483 | 637 | ||
484 | if (obj->tiling_mode != I915_TILING_NONE) |
638 | if (obj->tiling_mode != I915_TILING_NONE) |
485 | I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x); |
639 | I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x); |
486 | else |
640 | else |
487 | I915_WRITE(DVSLINOFF(pipe), linear_offset); |
641 | I915_WRITE(DVSLINOFF(pipe), linear_offset); |
488 | 642 | ||
489 | I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w); |
643 | I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w); |
490 | I915_WRITE(DVSSCALE(pipe), dvsscale); |
644 | I915_WRITE(DVSSCALE(pipe), dvsscale); |
491 | I915_WRITE(DVSCNTR(pipe), dvscntr); |
645 | I915_WRITE(DVSCNTR(pipe), dvscntr); |
492 | I915_WRITE(DVSSURF(pipe), |
646 | I915_WRITE(DVSSURF(pipe), |
493 | i915_gem_obj_ggtt_offset(obj) + dvssurf_offset); |
647 | i915_gem_obj_ggtt_offset(obj) + dvssurf_offset); |
- | 648 | ||
- | 649 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
|
- | 650 | ||
494 | POSTING_READ(DVSSURF(pipe)); |
651 | if (atomic_update) |
- | 652 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
|
495 | } |
653 | } |
496 | 654 | ||
497 | static void |
655 | static void |
498 | ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc) |
656 | ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc) |
499 | { |
657 | { |
500 | struct drm_device *dev = plane->dev; |
658 | struct drm_device *dev = plane->dev; |
501 | struct drm_i915_private *dev_priv = dev->dev_private; |
659 | struct drm_i915_private *dev_priv = dev->dev_private; |
502 | struct intel_plane *intel_plane = to_intel_plane(plane); |
660 | struct intel_plane *intel_plane = to_intel_plane(plane); |
- | 661 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
|
503 | int pipe = intel_plane->pipe; |
662 | int pipe = intel_plane->pipe; |
- | 663 | u32 start_vbl_count; |
|
- | 664 | bool atomic_update; |
|
- | 665 | ||
- | 666 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
|
- | 667 | ||
- | 668 | intel_update_primary_plane(intel_crtc); |
|
504 | 669 | ||
505 | I915_WRITE(DVSCNTR(pipe), I915_READ(DVSCNTR(pipe)) & ~DVS_ENABLE); |
670 | I915_WRITE(DVSCNTR(pipe), I915_READ(DVSCNTR(pipe)) & ~DVS_ENABLE); |
506 | /* Disable the scaler */ |
671 | /* Disable the scaler */ |
507 | I915_WRITE(DVSSCALE(pipe), 0); |
672 | I915_WRITE(DVSSCALE(pipe), 0); |
508 | /* Flush double buffered register updates */ |
673 | /* Flush double buffered register updates */ |
509 | I915_WRITE(DVSSURF(pipe), 0); |
674 | I915_WRITE(DVSSURF(pipe), 0); |
- | 675 | ||
- | 676 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
|
- | 677 | ||
510 | POSTING_READ(DVSSURF(pipe)); |
678 | if (atomic_update) |
- | 679 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
|
511 | 680 | ||
512 | /* |
681 | /* |
513 | * Avoid underruns when disabling the sprite. |
682 | * Avoid underruns when disabling the sprite. |
514 | * FIXME remove once watermark updates are done properly. |
683 | * FIXME remove once watermark updates are done properly. |
515 | */ |
684 | */ |
516 | intel_wait_for_vblank(dev, pipe); |
685 | intel_wait_for_vblank(dev, pipe); |
517 | 686 | ||
518 | intel_update_sprite_watermarks(plane, crtc, 0, 0, false, false); |
687 | intel_update_sprite_watermarks(plane, crtc, 0, 0, 0, false, false); |
519 | } |
688 | } |
520 | 689 | ||
521 | static void |
690 | static void |
522 | intel_enable_primary(struct drm_crtc *crtc) |
691 | intel_post_enable_primary(struct drm_crtc *crtc) |
523 | { |
692 | { |
524 | struct drm_device *dev = crtc->dev; |
693 | struct drm_device *dev = crtc->dev; |
525 | struct drm_i915_private *dev_priv = dev->dev_private; |
- | |
526 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
694 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
527 | int reg = DSPCNTR(intel_crtc->plane); |
- | |
528 | - | ||
529 | if (intel_crtc->primary_enabled) |
- | |
530 | return; |
- | |
531 | - | ||
532 | intel_crtc->primary_enabled = true; |
- | |
533 | - | ||
534 | I915_WRITE(reg, I915_READ(reg) | DISPLAY_PLANE_ENABLE); |
- | |
535 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
- | |
536 | 695 | ||
537 | /* |
696 | /* |
538 | * FIXME IPS should be fine as long as one plane is |
697 | * FIXME IPS should be fine as long as one plane is |
539 | * enabled, but in practice it seems to have problems |
698 | * enabled, but in practice it seems to have problems |
540 | * when going from primary only to sprite only and vice |
699 | * when going from primary only to sprite only and vice |
541 | * versa. |
700 | * versa. |
542 | */ |
701 | */ |
543 | if (intel_crtc->config.ips_enabled) { |
- | |
544 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
- | |
545 | hsw_enable_ips(intel_crtc); |
702 | hsw_enable_ips(intel_crtc); |
546 | } |
- | |
547 | 703 | ||
548 | mutex_lock(&dev->struct_mutex); |
704 | mutex_lock(&dev->struct_mutex); |
549 | intel_update_fbc(dev); |
705 | intel_update_fbc(dev); |
550 | mutex_unlock(&dev->struct_mutex); |
706 | mutex_unlock(&dev->struct_mutex); |
551 | } |
707 | } |
552 | 708 | ||
553 | static void |
709 | static void |
554 | intel_disable_primary(struct drm_crtc *crtc) |
710 | intel_pre_disable_primary(struct drm_crtc *crtc) |
555 | { |
711 | { |
556 | struct drm_device *dev = crtc->dev; |
712 | struct drm_device *dev = crtc->dev; |
557 | struct drm_i915_private *dev_priv = dev->dev_private; |
713 | struct drm_i915_private *dev_priv = dev->dev_private; |
558 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
714 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
559 | int reg = DSPCNTR(intel_crtc->plane); |
- | |
560 | - | ||
561 | if (!intel_crtc->primary_enabled) |
- | |
562 | return; |
- | |
563 | - | ||
564 | intel_crtc->primary_enabled = false; |
- | |
565 | 715 | ||
566 | mutex_lock(&dev->struct_mutex); |
716 | mutex_lock(&dev->struct_mutex); |
567 | if (dev_priv->fbc.plane == intel_crtc->plane) |
717 | if (dev_priv->fbc.plane == intel_crtc->plane) |
568 | intel_disable_fbc(dev); |
718 | intel_disable_fbc(dev); |
569 | mutex_unlock(&dev->struct_mutex); |
719 | mutex_unlock(&dev->struct_mutex); |
570 | 720 | ||
571 | /* |
721 | /* |
572 | * FIXME IPS should be fine as long as one plane is |
722 | * FIXME IPS should be fine as long as one plane is |
573 | * enabled, but in practice it seems to have problems |
723 | * enabled, but in practice it seems to have problems |
574 | * when going from primary only to sprite only and vice |
724 | * when going from primary only to sprite only and vice |
575 | * versa. |
725 | * versa. |
576 | */ |
726 | */ |
577 | hsw_disable_ips(intel_crtc); |
727 | hsw_disable_ips(intel_crtc); |
578 | - | ||
579 | I915_WRITE(reg, I915_READ(reg) & ~DISPLAY_PLANE_ENABLE); |
- | |
580 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
- | |
581 | } |
728 | } |
582 | 729 | ||
583 | static int |
730 | static int |
584 | ilk_update_colorkey(struct drm_plane *plane, |
731 | ilk_update_colorkey(struct drm_plane *plane, |
585 | struct drm_intel_sprite_colorkey *key) |
732 | struct drm_intel_sprite_colorkey *key) |
586 | { |
733 | { |
587 | struct drm_device *dev = plane->dev; |
734 | struct drm_device *dev = plane->dev; |
588 | struct drm_i915_private *dev_priv = dev->dev_private; |
735 | struct drm_i915_private *dev_priv = dev->dev_private; |
589 | struct intel_plane *intel_plane; |
736 | struct intel_plane *intel_plane; |
590 | u32 dvscntr; |
737 | u32 dvscntr; |
591 | int ret = 0; |
738 | int ret = 0; |
592 | 739 | ||
593 | intel_plane = to_intel_plane(plane); |
740 | intel_plane = to_intel_plane(plane); |
594 | 741 | ||
595 | I915_WRITE(DVSKEYVAL(intel_plane->pipe), key->min_value); |
742 | I915_WRITE(DVSKEYVAL(intel_plane->pipe), key->min_value); |
596 | I915_WRITE(DVSKEYMAX(intel_plane->pipe), key->max_value); |
743 | I915_WRITE(DVSKEYMAX(intel_plane->pipe), key->max_value); |
597 | I915_WRITE(DVSKEYMSK(intel_plane->pipe), key->channel_mask); |
744 | I915_WRITE(DVSKEYMSK(intel_plane->pipe), key->channel_mask); |
598 | 745 | ||
599 | dvscntr = I915_READ(DVSCNTR(intel_plane->pipe)); |
746 | dvscntr = I915_READ(DVSCNTR(intel_plane->pipe)); |
600 | dvscntr &= ~(DVS_SOURCE_KEY | DVS_DEST_KEY); |
747 | dvscntr &= ~(DVS_SOURCE_KEY | DVS_DEST_KEY); |
601 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
748 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
602 | dvscntr |= DVS_DEST_KEY; |
749 | dvscntr |= DVS_DEST_KEY; |
603 | else if (key->flags & I915_SET_COLORKEY_SOURCE) |
750 | else if (key->flags & I915_SET_COLORKEY_SOURCE) |
604 | dvscntr |= DVS_SOURCE_KEY; |
751 | dvscntr |= DVS_SOURCE_KEY; |
605 | I915_WRITE(DVSCNTR(intel_plane->pipe), dvscntr); |
752 | I915_WRITE(DVSCNTR(intel_plane->pipe), dvscntr); |
606 | 753 | ||
607 | POSTING_READ(DVSKEYMSK(intel_plane->pipe)); |
754 | POSTING_READ(DVSKEYMSK(intel_plane->pipe)); |
608 | 755 | ||
609 | return ret; |
756 | return ret; |
610 | } |
757 | } |
611 | 758 | ||
612 | static void |
759 | static void |
613 | ilk_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key) |
760 | ilk_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key) |
614 | { |
761 | { |
615 | struct drm_device *dev = plane->dev; |
762 | struct drm_device *dev = plane->dev; |
616 | struct drm_i915_private *dev_priv = dev->dev_private; |
763 | struct drm_i915_private *dev_priv = dev->dev_private; |
617 | struct intel_plane *intel_plane; |
764 | struct intel_plane *intel_plane; |
618 | u32 dvscntr; |
765 | u32 dvscntr; |
619 | 766 | ||
620 | intel_plane = to_intel_plane(plane); |
767 | intel_plane = to_intel_plane(plane); |
621 | 768 | ||
622 | key->min_value = I915_READ(DVSKEYVAL(intel_plane->pipe)); |
769 | key->min_value = I915_READ(DVSKEYVAL(intel_plane->pipe)); |
623 | key->max_value = I915_READ(DVSKEYMAX(intel_plane->pipe)); |
770 | key->max_value = I915_READ(DVSKEYMAX(intel_plane->pipe)); |
624 | key->channel_mask = I915_READ(DVSKEYMSK(intel_plane->pipe)); |
771 | key->channel_mask = I915_READ(DVSKEYMSK(intel_plane->pipe)); |
625 | key->flags = 0; |
772 | key->flags = 0; |
626 | 773 | ||
627 | dvscntr = I915_READ(DVSCNTR(intel_plane->pipe)); |
774 | dvscntr = I915_READ(DVSCNTR(intel_plane->pipe)); |
628 | 775 | ||
629 | if (dvscntr & DVS_DEST_KEY) |
776 | if (dvscntr & DVS_DEST_KEY) |
630 | key->flags = I915_SET_COLORKEY_DESTINATION; |
777 | key->flags = I915_SET_COLORKEY_DESTINATION; |
631 | else if (dvscntr & DVS_SOURCE_KEY) |
778 | else if (dvscntr & DVS_SOURCE_KEY) |
632 | key->flags = I915_SET_COLORKEY_SOURCE; |
779 | key->flags = I915_SET_COLORKEY_SOURCE; |
633 | else |
780 | else |
634 | key->flags = I915_SET_COLORKEY_NONE; |
781 | key->flags = I915_SET_COLORKEY_NONE; |
635 | } |
782 | } |
636 | 783 | ||
637 | static bool |
784 | static bool |
638 | format_is_yuv(uint32_t format) |
785 | format_is_yuv(uint32_t format) |
639 | { |
786 | { |
640 | switch (format) { |
787 | switch (format) { |
641 | case DRM_FORMAT_YUYV: |
788 | case DRM_FORMAT_YUYV: |
642 | case DRM_FORMAT_UYVY: |
789 | case DRM_FORMAT_UYVY: |
643 | case DRM_FORMAT_VYUY: |
790 | case DRM_FORMAT_VYUY: |
644 | case DRM_FORMAT_YVYU: |
791 | case DRM_FORMAT_YVYU: |
645 | return true; |
792 | return true; |
646 | default: |
793 | default: |
647 | return false; |
794 | return false; |
648 | } |
795 | } |
649 | } |
796 | } |
650 | 797 | ||
651 | static bool colorkey_enabled(struct intel_plane *intel_plane) |
798 | static bool colorkey_enabled(struct intel_plane *intel_plane) |
652 | { |
799 | { |
653 | struct drm_intel_sprite_colorkey key; |
800 | struct drm_intel_sprite_colorkey key; |
654 | 801 | ||
655 | intel_plane->get_colorkey(&intel_plane->base, &key); |
802 | intel_plane->get_colorkey(&intel_plane->base, &key); |
656 | 803 | ||
657 | return key.flags != I915_SET_COLORKEY_NONE; |
804 | return key.flags != I915_SET_COLORKEY_NONE; |
658 | } |
805 | } |
659 | 806 | ||
660 | static int |
807 | static int |
661 | intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc, |
808 | intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc, |
662 | struct drm_framebuffer *fb, int crtc_x, int crtc_y, |
809 | struct drm_framebuffer *fb, int crtc_x, int crtc_y, |
663 | unsigned int crtc_w, unsigned int crtc_h, |
810 | unsigned int crtc_w, unsigned int crtc_h, |
664 | uint32_t src_x, uint32_t src_y, |
811 | uint32_t src_x, uint32_t src_y, |
665 | uint32_t src_w, uint32_t src_h) |
812 | uint32_t src_w, uint32_t src_h) |
666 | { |
813 | { |
667 | struct drm_device *dev = plane->dev; |
814 | struct drm_device *dev = plane->dev; |
668 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
815 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
669 | struct intel_plane *intel_plane = to_intel_plane(plane); |
816 | struct intel_plane *intel_plane = to_intel_plane(plane); |
- | 817 | enum pipe pipe = intel_crtc->pipe; |
|
670 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
818 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
671 | struct drm_i915_gem_object *obj = intel_fb->obj; |
819 | struct drm_i915_gem_object *obj = intel_fb->obj; |
672 | struct drm_i915_gem_object *old_obj = intel_plane->obj; |
820 | struct drm_i915_gem_object *old_obj = intel_plane->obj; |
673 | int ret; |
821 | int ret; |
674 | bool disable_primary = false; |
822 | bool primary_enabled; |
675 | bool visible; |
823 | bool visible; |
676 | int hscale, vscale; |
824 | int hscale, vscale; |
677 | int max_scale, min_scale; |
825 | int max_scale, min_scale; |
678 | int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
826 | int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
679 | struct drm_rect src = { |
827 | struct drm_rect src = { |
680 | /* sample coordinates in 16.16 fixed point */ |
828 | /* sample coordinates in 16.16 fixed point */ |
681 | .x1 = src_x, |
829 | .x1 = src_x, |
682 | .x2 = src_x + src_w, |
830 | .x2 = src_x + src_w, |
683 | .y1 = src_y, |
831 | .y1 = src_y, |
684 | .y2 = src_y + src_h, |
832 | .y2 = src_y + src_h, |
685 | }; |
833 | }; |
686 | struct drm_rect dst = { |
834 | struct drm_rect dst = { |
687 | /* integer pixels */ |
835 | /* integer pixels */ |
688 | .x1 = crtc_x, |
836 | .x1 = crtc_x, |
689 | .x2 = crtc_x + crtc_w, |
837 | .x2 = crtc_x + crtc_w, |
690 | .y1 = crtc_y, |
838 | .y1 = crtc_y, |
691 | .y2 = crtc_y + crtc_h, |
839 | .y2 = crtc_y + crtc_h, |
692 | }; |
840 | }; |
693 | const struct drm_rect clip = { |
841 | const struct drm_rect clip = { |
694 | .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0, |
842 | .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0, |
695 | .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0, |
843 | .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0, |
696 | }; |
844 | }; |
697 | const struct { |
845 | const struct { |
698 | int crtc_x, crtc_y; |
846 | int crtc_x, crtc_y; |
699 | unsigned int crtc_w, crtc_h; |
847 | unsigned int crtc_w, crtc_h; |
700 | uint32_t src_x, src_y, src_w, src_h; |
848 | uint32_t src_x, src_y, src_w, src_h; |
701 | } orig = { |
849 | } orig = { |
702 | .crtc_x = crtc_x, |
850 | .crtc_x = crtc_x, |
703 | .crtc_y = crtc_y, |
851 | .crtc_y = crtc_y, |
704 | .crtc_w = crtc_w, |
852 | .crtc_w = crtc_w, |
705 | .crtc_h = crtc_h, |
853 | .crtc_h = crtc_h, |
706 | .src_x = src_x, |
854 | .src_x = src_x, |
707 | .src_y = src_y, |
855 | .src_y = src_y, |
708 | .src_w = src_w, |
856 | .src_w = src_w, |
709 | .src_h = src_h, |
857 | .src_h = src_h, |
710 | }; |
858 | }; |
711 | 859 | ||
712 | /* Don't modify another pipe's plane */ |
860 | /* Don't modify another pipe's plane */ |
713 | if (intel_plane->pipe != intel_crtc->pipe) { |
861 | if (intel_plane->pipe != intel_crtc->pipe) { |
714 | DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n"); |
862 | DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n"); |
715 | return -EINVAL; |
863 | return -EINVAL; |
716 | } |
864 | } |
717 | 865 | ||
718 | /* FIXME check all gen limits */ |
866 | /* FIXME check all gen limits */ |
719 | if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) { |
867 | if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) { |
720 | DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n"); |
868 | DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n"); |
721 | return -EINVAL; |
869 | return -EINVAL; |
722 | } |
870 | } |
723 | 871 | ||
724 | /* Sprite planes can be linear or x-tiled surfaces */ |
872 | /* Sprite planes can be linear or x-tiled surfaces */ |
725 | switch (obj->tiling_mode) { |
873 | switch (obj->tiling_mode) { |
726 | case I915_TILING_NONE: |
874 | case I915_TILING_NONE: |
727 | case I915_TILING_X: |
875 | case I915_TILING_X: |
728 | break; |
876 | break; |
729 | default: |
877 | default: |
730 | DRM_DEBUG_KMS("Unsupported tiling mode\n"); |
878 | DRM_DEBUG_KMS("Unsupported tiling mode\n"); |
731 | return -EINVAL; |
879 | return -EINVAL; |
732 | } |
880 | } |
733 | 881 | ||
734 | /* |
882 | /* |
735 | * FIXME the following code does a bunch of fuzzy adjustments to the |
883 | * FIXME the following code does a bunch of fuzzy adjustments to the |
736 | * coordinates and sizes. We probably need some way to decide whether |
884 | * coordinates and sizes. We probably need some way to decide whether |
737 | * more strict checking should be done instead. |
885 | * more strict checking should be done instead. |
738 | */ |
886 | */ |
739 | max_scale = intel_plane->max_downscale << 16; |
887 | max_scale = intel_plane->max_downscale << 16; |
740 | min_scale = intel_plane->can_scale ? 1 : (1 << 16); |
888 | min_scale = intel_plane->can_scale ? 1 : (1 << 16); |
741 | 889 | ||
742 | hscale = drm_rect_calc_hscale_relaxed(&src, &dst, min_scale, max_scale); |
890 | hscale = drm_rect_calc_hscale_relaxed(&src, &dst, min_scale, max_scale); |
743 | BUG_ON(hscale < 0); |
891 | BUG_ON(hscale < 0); |
744 | 892 | ||
745 | vscale = drm_rect_calc_vscale_relaxed(&src, &dst, min_scale, max_scale); |
893 | vscale = drm_rect_calc_vscale_relaxed(&src, &dst, min_scale, max_scale); |
746 | BUG_ON(vscale < 0); |
894 | BUG_ON(vscale < 0); |
747 | 895 | ||
748 | visible = drm_rect_clip_scaled(&src, &dst, &clip, hscale, vscale); |
896 | visible = drm_rect_clip_scaled(&src, &dst, &clip, hscale, vscale); |
749 | 897 | ||
750 | crtc_x = dst.x1; |
898 | crtc_x = dst.x1; |
751 | crtc_y = dst.y1; |
899 | crtc_y = dst.y1; |
752 | crtc_w = drm_rect_width(&dst); |
900 | crtc_w = drm_rect_width(&dst); |
753 | crtc_h = drm_rect_height(&dst); |
901 | crtc_h = drm_rect_height(&dst); |
754 | 902 | ||
755 | if (visible) { |
903 | if (visible) { |
756 | /* check again in case clipping clamped the results */ |
904 | /* check again in case clipping clamped the results */ |
757 | hscale = drm_rect_calc_hscale(&src, &dst, min_scale, max_scale); |
905 | hscale = drm_rect_calc_hscale(&src, &dst, min_scale, max_scale); |
758 | if (hscale < 0) { |
906 | if (hscale < 0) { |
759 | DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n"); |
907 | DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n"); |
760 | drm_rect_debug_print(&src, true); |
908 | drm_rect_debug_print(&src, true); |
761 | drm_rect_debug_print(&dst, false); |
909 | drm_rect_debug_print(&dst, false); |
762 | 910 | ||
763 | return hscale; |
911 | return hscale; |
764 | } |
912 | } |
765 | 913 | ||
766 | vscale = drm_rect_calc_vscale(&src, &dst, min_scale, max_scale); |
914 | vscale = drm_rect_calc_vscale(&src, &dst, min_scale, max_scale); |
767 | if (vscale < 0) { |
915 | if (vscale < 0) { |
768 | DRM_DEBUG_KMS("Vertical scaling factor out of limits\n"); |
916 | DRM_DEBUG_KMS("Vertical scaling factor out of limits\n"); |
769 | drm_rect_debug_print(&src, true); |
917 | drm_rect_debug_print(&src, true); |
770 | drm_rect_debug_print(&dst, false); |
918 | drm_rect_debug_print(&dst, false); |
771 | 919 | ||
772 | return vscale; |
920 | return vscale; |
773 | } |
921 | } |
774 | 922 | ||
775 | /* Make the source viewport size an exact multiple of the scaling factors. */ |
923 | /* Make the source viewport size an exact multiple of the scaling factors. */ |
776 | drm_rect_adjust_size(&src, |
924 | drm_rect_adjust_size(&src, |
777 | drm_rect_width(&dst) * hscale - drm_rect_width(&src), |
925 | drm_rect_width(&dst) * hscale - drm_rect_width(&src), |
778 | drm_rect_height(&dst) * vscale - drm_rect_height(&src)); |
926 | drm_rect_height(&dst) * vscale - drm_rect_height(&src)); |
779 | 927 | ||
780 | /* sanity check to make sure the src viewport wasn't enlarged */ |
928 | /* sanity check to make sure the src viewport wasn't enlarged */ |
781 | WARN_ON(src.x1 < (int) src_x || |
929 | WARN_ON(src.x1 < (int) src_x || |
782 | src.y1 < (int) src_y || |
930 | src.y1 < (int) src_y || |
783 | src.x2 > (int) (src_x + src_w) || |
931 | src.x2 > (int) (src_x + src_w) || |
784 | src.y2 > (int) (src_y + src_h)); |
932 | src.y2 > (int) (src_y + src_h)); |
785 | 933 | ||
786 | /* |
934 | /* |
787 | * Hardware doesn't handle subpixel coordinates. |
935 | * Hardware doesn't handle subpixel coordinates. |
788 | * Adjust to (macro)pixel boundary, but be careful not to |
936 | * Adjust to (macro)pixel boundary, but be careful not to |
789 | * increase the source viewport size, because that could |
937 | * increase the source viewport size, because that could |
790 | * push the downscaling factor out of bounds. |
938 | * push the downscaling factor out of bounds. |
791 | */ |
939 | */ |
792 | src_x = src.x1 >> 16; |
940 | src_x = src.x1 >> 16; |
793 | src_w = drm_rect_width(&src) >> 16; |
941 | src_w = drm_rect_width(&src) >> 16; |
794 | src_y = src.y1 >> 16; |
942 | src_y = src.y1 >> 16; |
795 | src_h = drm_rect_height(&src) >> 16; |
943 | src_h = drm_rect_height(&src) >> 16; |
796 | 944 | ||
797 | if (format_is_yuv(fb->pixel_format)) { |
945 | if (format_is_yuv(fb->pixel_format)) { |
798 | src_x &= ~1; |
946 | src_x &= ~1; |
799 | src_w &= ~1; |
947 | src_w &= ~1; |
800 | 948 | ||
801 | /* |
949 | /* |
802 | * Must keep src and dst the |
950 | * Must keep src and dst the |
803 | * same if we can't scale. |
951 | * same if we can't scale. |
804 | */ |
952 | */ |
805 | if (!intel_plane->can_scale) |
953 | if (!intel_plane->can_scale) |
806 | crtc_w &= ~1; |
954 | crtc_w &= ~1; |
807 | 955 | ||
808 | if (crtc_w == 0) |
956 | if (crtc_w == 0) |
809 | visible = false; |
957 | visible = false; |
810 | } |
958 | } |
811 | } |
959 | } |
812 | 960 | ||
813 | /* Check size restrictions when scaling */ |
961 | /* Check size restrictions when scaling */ |
814 | if (visible && (src_w != crtc_w || src_h != crtc_h)) { |
962 | if (visible && (src_w != crtc_w || src_h != crtc_h)) { |
815 | unsigned int width_bytes; |
963 | unsigned int width_bytes; |
816 | 964 | ||
817 | WARN_ON(!intel_plane->can_scale); |
965 | WARN_ON(!intel_plane->can_scale); |
818 | 966 | ||
819 | /* FIXME interlacing min height is 6 */ |
967 | /* FIXME interlacing min height is 6 */ |
820 | 968 | ||
821 | if (crtc_w < 3 || crtc_h < 3) |
969 | if (crtc_w < 3 || crtc_h < 3) |
822 | visible = false; |
970 | visible = false; |
823 | 971 | ||
824 | if (src_w < 3 || src_h < 3) |
972 | if (src_w < 3 || src_h < 3) |
825 | visible = false; |
973 | visible = false; |
826 | 974 | ||
827 | width_bytes = ((src_x * pixel_size) & 63) + src_w * pixel_size; |
975 | width_bytes = ((src_x * pixel_size) & 63) + src_w * pixel_size; |
828 | 976 | ||
829 | if (src_w > 2048 || src_h > 2048 || |
977 | if (src_w > 2048 || src_h > 2048 || |
830 | width_bytes > 4096 || fb->pitches[0] > 4096) { |
978 | width_bytes > 4096 || fb->pitches[0] > 4096) { |
831 | DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n"); |
979 | DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n"); |
832 | return -EINVAL; |
980 | return -EINVAL; |
833 | } |
981 | } |
834 | } |
982 | } |
835 | 983 | ||
836 | dst.x1 = crtc_x; |
984 | dst.x1 = crtc_x; |
837 | dst.x2 = crtc_x + crtc_w; |
985 | dst.x2 = crtc_x + crtc_w; |
838 | dst.y1 = crtc_y; |
986 | dst.y1 = crtc_y; |
839 | dst.y2 = crtc_y + crtc_h; |
987 | dst.y2 = crtc_y + crtc_h; |
840 | 988 | ||
841 | /* |
989 | /* |
842 | * If the sprite is completely covering the primary plane, |
990 | * If the sprite is completely covering the primary plane, |
843 | * we can disable the primary and save power. |
991 | * we can disable the primary and save power. |
844 | */ |
992 | */ |
845 | disable_primary = drm_rect_equals(&dst, &clip) && !colorkey_enabled(intel_plane); |
993 | primary_enabled = !drm_rect_equals(&dst, &clip) || colorkey_enabled(intel_plane); |
846 | WARN_ON(disable_primary && !visible && intel_crtc->active); |
994 | WARN_ON(!primary_enabled && !visible && intel_crtc->active); |
847 | 995 | ||
848 | mutex_lock(&dev->struct_mutex); |
996 | mutex_lock(&dev->struct_mutex); |
849 | 997 | ||
850 | /* Note that this will apply the VT-d workaround for scanouts, |
998 | /* Note that this will apply the VT-d workaround for scanouts, |
851 | * which is more restrictive than required for sprites. (The |
999 | * which is more restrictive than required for sprites. (The |
852 | * primary plane requires 256KiB alignment with 64 PTE padding, |
1000 | * primary plane requires 256KiB alignment with 64 PTE padding, |
853 | * the sprite planes only require 128KiB alignment and 32 PTE padding. |
1001 | * the sprite planes only require 128KiB alignment and 32 PTE padding. |
854 | */ |
1002 | */ |
855 | ret = intel_pin_and_fence_fb_obj(dev, obj, NULL); |
1003 | ret = intel_pin_and_fence_fb_obj(dev, obj, NULL); |
- | 1004 | ||
- | 1005 | i915_gem_track_fb(old_obj, obj, |
|
856 | 1006 | INTEL_FRONTBUFFER_SPRITE(pipe)); |
|
857 | mutex_unlock(&dev->struct_mutex); |
1007 | mutex_unlock(&dev->struct_mutex); |
858 | 1008 | ||
859 | if (ret) |
1009 | if (ret) |
860 | return ret; |
1010 | return ret; |
861 | 1011 | ||
862 | intel_plane->crtc_x = orig.crtc_x; |
1012 | intel_plane->crtc_x = orig.crtc_x; |
863 | intel_plane->crtc_y = orig.crtc_y; |
1013 | intel_plane->crtc_y = orig.crtc_y; |
864 | intel_plane->crtc_w = orig.crtc_w; |
1014 | intel_plane->crtc_w = orig.crtc_w; |
865 | intel_plane->crtc_h = orig.crtc_h; |
1015 | intel_plane->crtc_h = orig.crtc_h; |
866 | intel_plane->src_x = orig.src_x; |
1016 | intel_plane->src_x = orig.src_x; |
867 | intel_plane->src_y = orig.src_y; |
1017 | intel_plane->src_y = orig.src_y; |
868 | intel_plane->src_w = orig.src_w; |
1018 | intel_plane->src_w = orig.src_w; |
869 | intel_plane->src_h = orig.src_h; |
1019 | intel_plane->src_h = orig.src_h; |
870 | intel_plane->obj = obj; |
1020 | intel_plane->obj = obj; |
871 | 1021 | ||
872 | if (intel_crtc->active) { |
1022 | if (intel_crtc->active) { |
- | 1023 | bool primary_was_enabled = intel_crtc->primary_enabled; |
|
873 | /* |
1024 | |
874 | * Be sure to re-enable the primary before the sprite is no longer |
1025 | intel_crtc->primary_enabled = primary_enabled; |
- | 1026 | ||
875 | * covering it fully. |
1027 | // if (primary_was_enabled != primary_enabled) |
876 | */ |
1028 | |
877 | if (!disable_primary) |
1029 | if (primary_was_enabled && !primary_enabled) |
878 | intel_enable_primary(crtc); |
1030 | intel_pre_disable_primary(crtc); |
879 | 1031 | ||
880 | if (visible) |
1032 | if (visible) |
881 | intel_plane->update_plane(plane, crtc, fb, obj, |
1033 | intel_plane->update_plane(plane, crtc, fb, obj, |
882 | crtc_x, crtc_y, crtc_w, crtc_h, |
1034 | crtc_x, crtc_y, crtc_w, crtc_h, |
883 | src_x, src_y, src_w, src_h); |
1035 | src_x, src_y, src_w, src_h); |
884 | else |
1036 | else |
885 | intel_plane->disable_plane(plane, crtc); |
1037 | intel_plane->disable_plane(plane, crtc); |
886 | 1038 | ||
887 | if (disable_primary) |
1039 | if (!primary_was_enabled && primary_enabled) |
888 | intel_disable_primary(crtc); |
1040 | intel_post_enable_primary(crtc); |
889 | } |
1041 | } |
890 | 1042 | ||
891 | /* Unpin old obj after new one is active to avoid ugliness */ |
1043 | /* Unpin old obj after new one is active to avoid ugliness */ |
892 | if (old_obj) { |
1044 | if (old_obj) { |
893 | /* |
1045 | /* |
894 | * It's fairly common to simply update the position of |
1046 | * It's fairly common to simply update the position of |
895 | * an existing object. In that case, we don't need to |
1047 | * an existing object. In that case, we don't need to |
896 | * wait for vblank to avoid ugliness, we only need to |
1048 | * wait for vblank to avoid ugliness, we only need to |
897 | * do the pin & ref bookkeeping. |
1049 | * do the pin & ref bookkeeping. |
898 | */ |
1050 | */ |
899 | if (old_obj != obj && intel_crtc->active) |
1051 | if (old_obj != obj && intel_crtc->active) |
900 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
1052 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
901 | 1053 | ||
902 | mutex_lock(&dev->struct_mutex); |
1054 | mutex_lock(&dev->struct_mutex); |
903 | intel_unpin_fb_obj(old_obj); |
1055 | intel_unpin_fb_obj(old_obj); |
904 | mutex_unlock(&dev->struct_mutex); |
1056 | mutex_unlock(&dev->struct_mutex); |
905 | } |
1057 | } |
906 | 1058 | ||
907 | return 0; |
1059 | return 0; |
908 | } |
1060 | } |
909 | 1061 | ||
910 | static int |
1062 | static int |
911 | intel_disable_plane(struct drm_plane *plane) |
1063 | intel_disable_plane(struct drm_plane *plane) |
912 | { |
1064 | { |
913 | struct drm_device *dev = plane->dev; |
1065 | struct drm_device *dev = plane->dev; |
914 | struct intel_plane *intel_plane = to_intel_plane(plane); |
1066 | struct intel_plane *intel_plane = to_intel_plane(plane); |
915 | struct intel_crtc *intel_crtc; |
1067 | struct intel_crtc *intel_crtc; |
- | 1068 | enum pipe pipe; |
|
916 | 1069 | ||
917 | if (!plane->fb) |
1070 | if (!plane->fb) |
918 | return 0; |
1071 | return 0; |
919 | 1072 | ||
920 | if (WARN_ON(!plane->crtc)) |
1073 | if (WARN_ON(!plane->crtc)) |
921 | return -EINVAL; |
1074 | return -EINVAL; |
922 | 1075 | ||
923 | intel_crtc = to_intel_crtc(plane->crtc); |
1076 | intel_crtc = to_intel_crtc(plane->crtc); |
- | 1077 | pipe = intel_crtc->pipe; |
|
924 | 1078 | ||
- | 1079 | if (intel_crtc->active) { |
|
- | 1080 | bool primary_was_enabled = intel_crtc->primary_enabled; |
|
925 | if (intel_crtc->active) { |
1081 | |
- | 1082 | intel_crtc->primary_enabled = true; |
|
926 | intel_enable_primary(plane->crtc); |
1083 | |
- | 1084 | intel_plane->disable_plane(plane, plane->crtc); |
|
- | 1085 | ||
- | 1086 | if (!primary_was_enabled && intel_crtc->primary_enabled) |
|
927 | intel_plane->disable_plane(plane, plane->crtc); |
1087 | intel_post_enable_primary(plane->crtc); |
928 | } |
1088 | } |
929 | 1089 | ||
930 | if (intel_plane->obj) { |
1090 | if (intel_plane->obj) { |
931 | if (intel_crtc->active) |
1091 | if (intel_crtc->active) |
932 | intel_wait_for_vblank(dev, intel_plane->pipe); |
1092 | intel_wait_for_vblank(dev, intel_plane->pipe); |
933 | 1093 | ||
934 | mutex_lock(&dev->struct_mutex); |
1094 | mutex_lock(&dev->struct_mutex); |
935 | intel_unpin_fb_obj(intel_plane->obj); |
1095 | intel_unpin_fb_obj(intel_plane->obj); |
- | 1096 | i915_gem_track_fb(intel_plane->obj, NULL, |
|
- | 1097 | INTEL_FRONTBUFFER_SPRITE(pipe)); |
|
936 | mutex_unlock(&dev->struct_mutex); |
1098 | mutex_unlock(&dev->struct_mutex); |
937 | 1099 | ||
938 | intel_plane->obj = NULL; |
1100 | intel_plane->obj = NULL; |
939 | } |
1101 | } |
940 | 1102 | ||
941 | return 0; |
1103 | return 0; |
942 | } |
1104 | } |
943 | 1105 | ||
944 | static void intel_destroy_plane(struct drm_plane *plane) |
1106 | static void intel_destroy_plane(struct drm_plane *plane) |
945 | { |
1107 | { |
946 | struct intel_plane *intel_plane = to_intel_plane(plane); |
1108 | struct intel_plane *intel_plane = to_intel_plane(plane); |
947 | intel_disable_plane(plane); |
1109 | intel_disable_plane(plane); |
948 | drm_plane_cleanup(plane); |
1110 | drm_plane_cleanup(plane); |
949 | kfree(intel_plane); |
1111 | kfree(intel_plane); |
950 | } |
1112 | } |
951 | 1113 | ||
952 | int intel_sprite_set_colorkey(struct drm_device *dev, void *data, |
1114 | int intel_sprite_set_colorkey(struct drm_device *dev, void *data, |
953 | struct drm_file *file_priv) |
1115 | struct drm_file *file_priv) |
954 | { |
1116 | { |
955 | struct drm_intel_sprite_colorkey *set = data; |
1117 | struct drm_intel_sprite_colorkey *set = data; |
956 | struct drm_mode_object *obj; |
- | |
957 | struct drm_plane *plane; |
1118 | struct drm_plane *plane; |
958 | struct intel_plane *intel_plane; |
1119 | struct intel_plane *intel_plane; |
959 | int ret = 0; |
1120 | int ret = 0; |
960 | 1121 | ||
961 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
1122 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
962 | return -ENODEV; |
1123 | return -ENODEV; |
963 | 1124 | ||
964 | /* Make sure we don't try to enable both src & dest simultaneously */ |
1125 | /* Make sure we don't try to enable both src & dest simultaneously */ |
965 | if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) |
1126 | if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) |
966 | return -EINVAL; |
1127 | return -EINVAL; |
967 | 1128 | ||
968 | drm_modeset_lock_all(dev); |
1129 | drm_modeset_lock_all(dev); |
969 | 1130 | ||
970 | obj = drm_mode_object_find(dev, set->plane_id, DRM_MODE_OBJECT_PLANE); |
1131 | plane = drm_plane_find(dev, set->plane_id); |
971 | if (!obj) { |
1132 | if (!plane) { |
972 | ret = -ENOENT; |
1133 | ret = -ENOENT; |
973 | goto out_unlock; |
1134 | goto out_unlock; |
974 | } |
1135 | } |
975 | - | ||
976 | plane = obj_to_plane(obj); |
1136 | |
977 | intel_plane = to_intel_plane(plane); |
1137 | intel_plane = to_intel_plane(plane); |
978 | ret = intel_plane->update_colorkey(plane, set); |
1138 | ret = intel_plane->update_colorkey(plane, set); |
979 | 1139 | ||
980 | out_unlock: |
1140 | out_unlock: |
981 | drm_modeset_unlock_all(dev); |
1141 | drm_modeset_unlock_all(dev); |
982 | return ret; |
1142 | return ret; |
983 | } |
1143 | } |
984 | 1144 | ||
985 | int intel_sprite_get_colorkey(struct drm_device *dev, void *data, |
1145 | int intel_sprite_get_colorkey(struct drm_device *dev, void *data, |
986 | struct drm_file *file_priv) |
1146 | struct drm_file *file_priv) |
987 | { |
1147 | { |
988 | struct drm_intel_sprite_colorkey *get = data; |
1148 | struct drm_intel_sprite_colorkey *get = data; |
989 | struct drm_mode_object *obj; |
- | |
990 | struct drm_plane *plane; |
1149 | struct drm_plane *plane; |
991 | struct intel_plane *intel_plane; |
1150 | struct intel_plane *intel_plane; |
992 | int ret = 0; |
1151 | int ret = 0; |
993 | 1152 | ||
994 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
1153 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
995 | return -ENODEV; |
1154 | return -ENODEV; |
996 | 1155 | ||
997 | drm_modeset_lock_all(dev); |
1156 | drm_modeset_lock_all(dev); |
998 | 1157 | ||
999 | obj = drm_mode_object_find(dev, get->plane_id, DRM_MODE_OBJECT_PLANE); |
1158 | plane = drm_plane_find(dev, get->plane_id); |
1000 | if (!obj) { |
1159 | if (!plane) { |
1001 | ret = -ENOENT; |
1160 | ret = -ENOENT; |
1002 | goto out_unlock; |
1161 | goto out_unlock; |
1003 | } |
1162 | } |
1004 | - | ||
1005 | plane = obj_to_plane(obj); |
1163 | |
1006 | intel_plane = to_intel_plane(plane); |
1164 | intel_plane = to_intel_plane(plane); |
1007 | intel_plane->get_colorkey(plane, get); |
1165 | intel_plane->get_colorkey(plane, get); |
1008 | 1166 | ||
1009 | out_unlock: |
1167 | out_unlock: |
1010 | drm_modeset_unlock_all(dev); |
1168 | drm_modeset_unlock_all(dev); |
1011 | return ret; |
1169 | return ret; |
1012 | } |
1170 | } |
1013 | 1171 | ||
1014 | void intel_plane_restore(struct drm_plane *plane) |
1172 | void intel_plane_restore(struct drm_plane *plane) |
1015 | { |
1173 | { |
1016 | struct intel_plane *intel_plane = to_intel_plane(plane); |
1174 | struct intel_plane *intel_plane = to_intel_plane(plane); |
1017 | 1175 | ||
1018 | if (!plane->crtc || !plane->fb) |
1176 | if (!plane->crtc || !plane->fb) |
1019 | return; |
1177 | return; |
1020 | 1178 | ||
1021 | intel_update_plane(plane, plane->crtc, plane->fb, |
1179 | intel_update_plane(plane, plane->crtc, plane->fb, |
1022 | intel_plane->crtc_x, intel_plane->crtc_y, |
1180 | intel_plane->crtc_x, intel_plane->crtc_y, |
1023 | intel_plane->crtc_w, intel_plane->crtc_h, |
1181 | intel_plane->crtc_w, intel_plane->crtc_h, |
1024 | intel_plane->src_x, intel_plane->src_y, |
1182 | intel_plane->src_x, intel_plane->src_y, |
1025 | intel_plane->src_w, intel_plane->src_h); |
1183 | intel_plane->src_w, intel_plane->src_h); |
1026 | } |
1184 | } |
1027 | 1185 | ||
1028 | void intel_plane_disable(struct drm_plane *plane) |
1186 | void intel_plane_disable(struct drm_plane *plane) |
1029 | { |
1187 | { |
1030 | if (!plane->crtc || !plane->fb) |
1188 | if (!plane->crtc || !plane->fb) |
1031 | return; |
1189 | return; |
1032 | 1190 | ||
1033 | intel_disable_plane(plane); |
1191 | intel_disable_plane(plane); |
1034 | } |
1192 | } |
1035 | 1193 | ||
1036 | static const struct drm_plane_funcs intel_plane_funcs = { |
1194 | static const struct drm_plane_funcs intel_plane_funcs = { |
1037 | .update_plane = intel_update_plane, |
1195 | .update_plane = intel_update_plane, |
1038 | .disable_plane = intel_disable_plane, |
1196 | .disable_plane = intel_disable_plane, |
1039 | .destroy = intel_destroy_plane, |
1197 | .destroy = intel_destroy_plane, |
1040 | }; |
1198 | }; |
1041 | 1199 | ||
1042 | static uint32_t ilk_plane_formats[] = { |
1200 | static uint32_t ilk_plane_formats[] = { |
1043 | DRM_FORMAT_XRGB8888, |
1201 | DRM_FORMAT_XRGB8888, |
1044 | DRM_FORMAT_YUYV, |
1202 | DRM_FORMAT_YUYV, |
1045 | DRM_FORMAT_YVYU, |
1203 | DRM_FORMAT_YVYU, |
1046 | DRM_FORMAT_UYVY, |
1204 | DRM_FORMAT_UYVY, |
1047 | DRM_FORMAT_VYUY, |
1205 | DRM_FORMAT_VYUY, |
1048 | }; |
1206 | }; |
1049 | 1207 | ||
1050 | static uint32_t snb_plane_formats[] = { |
1208 | static uint32_t snb_plane_formats[] = { |
1051 | DRM_FORMAT_XBGR8888, |
1209 | DRM_FORMAT_XBGR8888, |
1052 | DRM_FORMAT_XRGB8888, |
1210 | DRM_FORMAT_XRGB8888, |
1053 | DRM_FORMAT_YUYV, |
1211 | DRM_FORMAT_YUYV, |
1054 | DRM_FORMAT_YVYU, |
1212 | DRM_FORMAT_YVYU, |
1055 | DRM_FORMAT_UYVY, |
1213 | DRM_FORMAT_UYVY, |
1056 | DRM_FORMAT_VYUY, |
1214 | DRM_FORMAT_VYUY, |
1057 | }; |
1215 | }; |
1058 | 1216 | ||
1059 | static uint32_t vlv_plane_formats[] = { |
1217 | static uint32_t vlv_plane_formats[] = { |
1060 | DRM_FORMAT_RGB565, |
1218 | DRM_FORMAT_RGB565, |
1061 | DRM_FORMAT_ABGR8888, |
1219 | DRM_FORMAT_ABGR8888, |
1062 | DRM_FORMAT_ARGB8888, |
1220 | DRM_FORMAT_ARGB8888, |
1063 | DRM_FORMAT_XBGR8888, |
1221 | DRM_FORMAT_XBGR8888, |
1064 | DRM_FORMAT_XRGB8888, |
1222 | DRM_FORMAT_XRGB8888, |
1065 | DRM_FORMAT_XBGR2101010, |
1223 | DRM_FORMAT_XBGR2101010, |
1066 | DRM_FORMAT_ABGR2101010, |
1224 | DRM_FORMAT_ABGR2101010, |
1067 | DRM_FORMAT_YUYV, |
1225 | DRM_FORMAT_YUYV, |
1068 | DRM_FORMAT_YVYU, |
1226 | DRM_FORMAT_YVYU, |
1069 | DRM_FORMAT_UYVY, |
1227 | DRM_FORMAT_UYVY, |
1070 | DRM_FORMAT_VYUY, |
1228 | DRM_FORMAT_VYUY, |
1071 | }; |
1229 | }; |
1072 | 1230 | ||
1073 | int |
1231 | int |
1074 | intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane) |
1232 | intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane) |
1075 | { |
1233 | { |
1076 | struct intel_plane *intel_plane; |
1234 | struct intel_plane *intel_plane; |
1077 | unsigned long possible_crtcs; |
1235 | unsigned long possible_crtcs; |
1078 | const uint32_t *plane_formats; |
1236 | const uint32_t *plane_formats; |
1079 | int num_plane_formats; |
1237 | int num_plane_formats; |
1080 | int ret; |
1238 | int ret; |
1081 | 1239 | ||
1082 | if (INTEL_INFO(dev)->gen < 5) |
1240 | if (INTEL_INFO(dev)->gen < 5) |
1083 | return -ENODEV; |
1241 | return -ENODEV; |
1084 | 1242 | ||
1085 | intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL); |
1243 | intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL); |
1086 | if (!intel_plane) |
1244 | if (!intel_plane) |
1087 | return -ENOMEM; |
1245 | return -ENOMEM; |
1088 | 1246 | ||
1089 | switch (INTEL_INFO(dev)->gen) { |
1247 | switch (INTEL_INFO(dev)->gen) { |
1090 | case 5: |
1248 | case 5: |
1091 | case 6: |
1249 | case 6: |
1092 | intel_plane->can_scale = true; |
1250 | intel_plane->can_scale = true; |
1093 | intel_plane->max_downscale = 16; |
1251 | intel_plane->max_downscale = 16; |
1094 | intel_plane->update_plane = ilk_update_plane; |
1252 | intel_plane->update_plane = ilk_update_plane; |
1095 | intel_plane->disable_plane = ilk_disable_plane; |
1253 | intel_plane->disable_plane = ilk_disable_plane; |
1096 | intel_plane->update_colorkey = ilk_update_colorkey; |
1254 | intel_plane->update_colorkey = ilk_update_colorkey; |
1097 | intel_plane->get_colorkey = ilk_get_colorkey; |
1255 | intel_plane->get_colorkey = ilk_get_colorkey; |
1098 | 1256 | ||
1099 | if (IS_GEN6(dev)) { |
1257 | if (IS_GEN6(dev)) { |
1100 | plane_formats = snb_plane_formats; |
1258 | plane_formats = snb_plane_formats; |
1101 | num_plane_formats = ARRAY_SIZE(snb_plane_formats); |
1259 | num_plane_formats = ARRAY_SIZE(snb_plane_formats); |
1102 | } else { |
1260 | } else { |
1103 | plane_formats = ilk_plane_formats; |
1261 | plane_formats = ilk_plane_formats; |
1104 | num_plane_formats = ARRAY_SIZE(ilk_plane_formats); |
1262 | num_plane_formats = ARRAY_SIZE(ilk_plane_formats); |
1105 | } |
1263 | } |
1106 | break; |
1264 | break; |
1107 | 1265 | ||
1108 | case 7: |
1266 | case 7: |
1109 | case 8: |
1267 | case 8: |
1110 | if (IS_IVYBRIDGE(dev)) { |
1268 | if (IS_IVYBRIDGE(dev)) { |
1111 | intel_plane->can_scale = true; |
1269 | intel_plane->can_scale = true; |
1112 | intel_plane->max_downscale = 2; |
1270 | intel_plane->max_downscale = 2; |
1113 | } else { |
1271 | } else { |
1114 | intel_plane->can_scale = false; |
1272 | intel_plane->can_scale = false; |
1115 | intel_plane->max_downscale = 1; |
1273 | intel_plane->max_downscale = 1; |
1116 | } |
1274 | } |
1117 | 1275 | ||
1118 | if (IS_VALLEYVIEW(dev)) { |
1276 | if (IS_VALLEYVIEW(dev)) { |
1119 | intel_plane->update_plane = vlv_update_plane; |
1277 | intel_plane->update_plane = vlv_update_plane; |
1120 | intel_plane->disable_plane = vlv_disable_plane; |
1278 | intel_plane->disable_plane = vlv_disable_plane; |
1121 | intel_plane->update_colorkey = vlv_update_colorkey; |
1279 | intel_plane->update_colorkey = vlv_update_colorkey; |
1122 | intel_plane->get_colorkey = vlv_get_colorkey; |
1280 | intel_plane->get_colorkey = vlv_get_colorkey; |
1123 | 1281 | ||
1124 | plane_formats = vlv_plane_formats; |
1282 | plane_formats = vlv_plane_formats; |
1125 | num_plane_formats = ARRAY_SIZE(vlv_plane_formats); |
1283 | num_plane_formats = ARRAY_SIZE(vlv_plane_formats); |
1126 | } else { |
1284 | } else { |
1127 | intel_plane->update_plane = ivb_update_plane; |
1285 | intel_plane->update_plane = ivb_update_plane; |
1128 | intel_plane->disable_plane = ivb_disable_plane; |
1286 | intel_plane->disable_plane = ivb_disable_plane; |
1129 | intel_plane->update_colorkey = ivb_update_colorkey; |
1287 | intel_plane->update_colorkey = ivb_update_colorkey; |
1130 | intel_plane->get_colorkey = ivb_get_colorkey; |
1288 | intel_plane->get_colorkey = ivb_get_colorkey; |
1131 | 1289 | ||
1132 | plane_formats = snb_plane_formats; |
1290 | plane_formats = snb_plane_formats; |
1133 | num_plane_formats = ARRAY_SIZE(snb_plane_formats); |
1291 | num_plane_formats = ARRAY_SIZE(snb_plane_formats); |
1134 | } |
1292 | } |
1135 | break; |
1293 | break; |
1136 | 1294 | ||
1137 | default: |
1295 | default: |
1138 | kfree(intel_plane); |
1296 | kfree(intel_plane); |
1139 | return -ENODEV; |
1297 | return -ENODEV; |
1140 | } |
1298 | } |
1141 | 1299 | ||
1142 | intel_plane->pipe = pipe; |
1300 | intel_plane->pipe = pipe; |
1143 | intel_plane->plane = plane; |
1301 | intel_plane->plane = plane; |
1144 | possible_crtcs = (1 << pipe); |
1302 | possible_crtcs = (1 << pipe); |
1145 | ret = drm_plane_init(dev, &intel_plane->base, possible_crtcs, |
1303 | ret = drm_plane_init(dev, &intel_plane->base, possible_crtcs, |
1146 | &intel_plane_funcs, |
1304 | &intel_plane_funcs, |
1147 | plane_formats, num_plane_formats, |
1305 | plane_formats, num_plane_formats, |
1148 | false); |
1306 | false); |
1149 | if (ret) |
1307 | if (ret) |
1150 | kfree(intel_plane); |
1308 | kfree(intel_plane); |
1151 | 1309 | ||
1152 | return ret; |
1310 | return ret; |
1153 | }><>>>>>>>>>>>>><>><>>>->><>><>><>><>><>><>><>><>><>><>><>><> |
1311 | }><>>>>>>>>>>>>><>><>>>->><>><>><>><>><>><>><>><>><>><>><>><>=>>=>=> |