blob: df5277aaa98b53918baef649250ee87cc46cdf23 [file] [log] [blame]
Daniel Vetter02e792f2009-09-15 22:57:34 +02001/*
2 * Copyright © 2009
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors:
24 * Daniel Vetter <daniel@ffwll.ch>
25 *
26 * Derived from Xorg ddx, xf86-video-intel, src/i830_video.c
27 */
Andrew Mortone1679762010-08-24 16:35:52 -070028
29#include <linux/seq_file.h>
Daniel Vetter02e792f2009-09-15 22:57:34 +020030#include "drmP.h"
31#include "drm.h"
32#include "i915_drm.h"
33#include "i915_drv.h"
34#include "i915_reg.h"
35#include "intel_drv.h"
36
37/* Limits for overlay size. According to intel doc, the real limits are:
38 * Y width: 4095, UV width (planar): 2047, Y height: 2047,
39 * UV width (planar): * 1023. But the xorg thinks 2048 for height and width. Use
40 * the mininum of both. */
41#define IMAGE_MAX_WIDTH 2048
42#define IMAGE_MAX_HEIGHT 2046 /* 2 * 1023 */
43/* on 830 and 845 these large limits result in the card hanging */
44#define IMAGE_MAX_WIDTH_LEGACY 1024
45#define IMAGE_MAX_HEIGHT_LEGACY 1088
46
47/* overlay register definitions */
48/* OCMD register */
49#define OCMD_TILED_SURFACE (0x1<<19)
50#define OCMD_MIRROR_MASK (0x3<<17)
51#define OCMD_MIRROR_MODE (0x3<<17)
52#define OCMD_MIRROR_HORIZONTAL (0x1<<17)
53#define OCMD_MIRROR_VERTICAL (0x2<<17)
54#define OCMD_MIRROR_BOTH (0x3<<17)
55#define OCMD_BYTEORDER_MASK (0x3<<14) /* zero for YUYV or FOURCC YUY2 */
56#define OCMD_UV_SWAP (0x1<<14) /* YVYU */
57#define OCMD_Y_SWAP (0x2<<14) /* UYVY or FOURCC UYVY */
58#define OCMD_Y_AND_UV_SWAP (0x3<<14) /* VYUY */
59#define OCMD_SOURCE_FORMAT_MASK (0xf<<10)
60#define OCMD_RGB_888 (0x1<<10) /* not in i965 Intel docs */
61#define OCMD_RGB_555 (0x2<<10) /* not in i965 Intel docs */
62#define OCMD_RGB_565 (0x3<<10) /* not in i965 Intel docs */
63#define OCMD_YUV_422_PACKED (0x8<<10)
64#define OCMD_YUV_411_PACKED (0x9<<10) /* not in i965 Intel docs */
65#define OCMD_YUV_420_PLANAR (0xc<<10)
66#define OCMD_YUV_422_PLANAR (0xd<<10)
67#define OCMD_YUV_410_PLANAR (0xe<<10) /* also 411 */
68#define OCMD_TVSYNCFLIP_PARITY (0x1<<9)
69#define OCMD_TVSYNCFLIP_ENABLE (0x1<<7)
Chris Wilsond7961362010-07-13 13:52:17 +010070#define OCMD_BUF_TYPE_MASK (0x1<<5)
Daniel Vetter02e792f2009-09-15 22:57:34 +020071#define OCMD_BUF_TYPE_FRAME (0x0<<5)
72#define OCMD_BUF_TYPE_FIELD (0x1<<5)
73#define OCMD_TEST_MODE (0x1<<4)
74#define OCMD_BUFFER_SELECT (0x3<<2)
75#define OCMD_BUFFER0 (0x0<<2)
76#define OCMD_BUFFER1 (0x1<<2)
77#define OCMD_FIELD_SELECT (0x1<<2)
78#define OCMD_FIELD0 (0x0<<1)
79#define OCMD_FIELD1 (0x1<<1)
80#define OCMD_ENABLE (0x1<<0)
81
82/* OCONFIG register */
83#define OCONF_PIPE_MASK (0x1<<18)
84#define OCONF_PIPE_A (0x0<<18)
85#define OCONF_PIPE_B (0x1<<18)
86#define OCONF_GAMMA2_ENABLE (0x1<<16)
87#define OCONF_CSC_MODE_BT601 (0x0<<5)
88#define OCONF_CSC_MODE_BT709 (0x1<<5)
89#define OCONF_CSC_BYPASS (0x1<<4)
90#define OCONF_CC_OUT_8BIT (0x1<<3)
91#define OCONF_TEST_MODE (0x1<<2)
92#define OCONF_THREE_LINE_BUFFER (0x1<<0)
93#define OCONF_TWO_LINE_BUFFER (0x0<<0)
94
95/* DCLRKM (dst-key) register */
96#define DST_KEY_ENABLE (0x1<<31)
97#define CLK_RGB24_MASK 0x0
98#define CLK_RGB16_MASK 0x070307
99#define CLK_RGB15_MASK 0x070707
100#define CLK_RGB8I_MASK 0xffffff
101
102#define RGB16_TO_COLORKEY(c) \
103 (((c & 0xF800) << 8) | ((c & 0x07E0) << 5) | ((c & 0x001F) << 3))
104#define RGB15_TO_COLORKEY(c) \
105 (((c & 0x7c00) << 9) | ((c & 0x03E0) << 6) | ((c & 0x001F) << 3))
106
107/* overlay flip addr flag */
108#define OFC_UPDATE 0x1
109
110/* polyphase filter coefficients */
111#define N_HORIZ_Y_TAPS 5
112#define N_VERT_Y_TAPS 3
113#define N_HORIZ_UV_TAPS 3
114#define N_VERT_UV_TAPS 3
115#define N_PHASES 17
116#define MAX_TAPS 5
117
118/* memory bufferd overlay registers */
119struct overlay_registers {
120 u32 OBUF_0Y;
121 u32 OBUF_1Y;
122 u32 OBUF_0U;
123 u32 OBUF_0V;
124 u32 OBUF_1U;
125 u32 OBUF_1V;
126 u32 OSTRIDE;
127 u32 YRGB_VPH;
128 u32 UV_VPH;
129 u32 HORZ_PH;
130 u32 INIT_PHS;
131 u32 DWINPOS;
132 u32 DWINSZ;
133 u32 SWIDTH;
134 u32 SWIDTHSW;
135 u32 SHEIGHT;
136 u32 YRGBSCALE;
137 u32 UVSCALE;
138 u32 OCLRC0;
139 u32 OCLRC1;
140 u32 DCLRKV;
141 u32 DCLRKM;
142 u32 SCLRKVH;
143 u32 SCLRKVL;
144 u32 SCLRKEN;
145 u32 OCONFIG;
146 u32 OCMD;
147 u32 RESERVED1; /* 0x6C */
148 u32 OSTART_0Y;
149 u32 OSTART_1Y;
150 u32 OSTART_0U;
151 u32 OSTART_0V;
152 u32 OSTART_1U;
153 u32 OSTART_1V;
154 u32 OTILEOFF_0Y;
155 u32 OTILEOFF_1Y;
156 u32 OTILEOFF_0U;
157 u32 OTILEOFF_0V;
158 u32 OTILEOFF_1U;
159 u32 OTILEOFF_1V;
160 u32 FASTHSCALE; /* 0xA0 */
161 u32 UVSCALEV; /* 0xA4 */
162 u32 RESERVEDC[(0x200 - 0xA8) / 4]; /* 0xA8 - 0x1FC */
163 u16 Y_VCOEFS[N_VERT_Y_TAPS * N_PHASES]; /* 0x200 */
164 u16 RESERVEDD[0x100 / 2 - N_VERT_Y_TAPS * N_PHASES];
165 u16 Y_HCOEFS[N_HORIZ_Y_TAPS * N_PHASES]; /* 0x300 */
166 u16 RESERVEDE[0x200 / 2 - N_HORIZ_Y_TAPS * N_PHASES];
167 u16 UV_VCOEFS[N_VERT_UV_TAPS * N_PHASES]; /* 0x500 */
168 u16 RESERVEDF[0x100 / 2 - N_VERT_UV_TAPS * N_PHASES];
169 u16 UV_HCOEFS[N_HORIZ_UV_TAPS * N_PHASES]; /* 0x600 */
170 u16 RESERVEDG[0x100 / 2 - N_HORIZ_UV_TAPS * N_PHASES];
171};
172
173/* overlay flip addr flag */
174#define OFC_UPDATE 0x1
175
Daniel Vetter02e792f2009-09-15 22:57:34 +0200176static struct overlay_registers *intel_overlay_map_regs_atomic(struct intel_overlay *overlay)
177{
178 drm_i915_private_t *dev_priv = overlay->dev->dev_private;
179 struct overlay_registers *regs;
180
181 /* no recursive mappings */
182 BUG_ON(overlay->virt_addr);
183
Chris Wilson315781482010-08-12 09:42:51 +0100184 if (OVERLAY_NEEDS_PHYSICAL(overlay->dev)) {
185 regs = overlay->reg_bo->phys_obj->handle->vaddr;
186 } else {
Daniel Vetter02e792f2009-09-15 22:57:34 +0200187 regs = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping,
Chris Wilsonfca3ec02010-08-04 14:34:24 +0100188 overlay->reg_bo->gtt_offset,
189 KM_USER0);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200190
191 if (!regs) {
192 DRM_ERROR("failed to map overlay regs in GTT\n");
193 return NULL;
194 }
Chris Wilson315781482010-08-12 09:42:51 +0100195 }
Daniel Vetter02e792f2009-09-15 22:57:34 +0200196
197 return overlay->virt_addr = regs;
198}
199
200static void intel_overlay_unmap_regs_atomic(struct intel_overlay *overlay)
201{
Chris Wilson315781482010-08-12 09:42:51 +0100202 if (!OVERLAY_NEEDS_PHYSICAL(overlay->dev))
Chris Wilsonfca3ec02010-08-04 14:34:24 +0100203 io_mapping_unmap_atomic(overlay->virt_addr, KM_USER0);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200204
205 overlay->virt_addr = NULL;
206
Daniel Vetter02e792f2009-09-15 22:57:34 +0200207 return;
208}
209
210/* overlay needs to be disable in OCMD reg */
211static int intel_overlay_on(struct intel_overlay *overlay)
212{
213 struct drm_device *dev = overlay->dev;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200214 int ret;
Zou Nan hai852835f2010-05-21 09:08:56 +0800215 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200216
217 BUG_ON(overlay->active);
218
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200219 overlay->active = 1;
220 overlay->hw_wedged = NEEDS_WAIT_FOR_FLIP;
221
Daniel Vetter4f8a5672010-02-11 14:14:43 +0100222 BEGIN_LP_RING(4);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200223 OUT_RING(MI_OVERLAY_FLIP | MI_OVERLAY_ON);
224 OUT_RING(overlay->flip_addr | OFC_UPDATE);
225 OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP);
226 OUT_RING(MI_NOOP);
227 ADVANCE_LP_RING();
228
Zou Nan hai852835f2010-05-21 09:08:56 +0800229 overlay->last_flip_req =
Daniel Vetter8a1a49f2010-02-11 22:29:04 +0100230 i915_add_request(dev, NULL, &dev_priv->render_ring);
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200231 if (overlay->last_flip_req == 0)
232 return -ENOMEM;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200233
Zou Nan hai852835f2010-05-21 09:08:56 +0800234 ret = i915_do_wait_request(dev,
Chris Wilson722506f2010-08-12 09:28:50 +0100235 overlay->last_flip_req, true,
236 &dev_priv->render_ring);
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200237 if (ret != 0)
238 return ret;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200239
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200240 overlay->hw_wedged = 0;
241 overlay->last_flip_req = 0;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200242 return 0;
243}
244
245/* overlay needs to be enabled in OCMD reg */
246static void intel_overlay_continue(struct intel_overlay *overlay,
Chris Wilson722506f2010-08-12 09:28:50 +0100247 bool load_polyphase_filter)
Daniel Vetter02e792f2009-09-15 22:57:34 +0200248{
249 struct drm_device *dev = overlay->dev;
250 drm_i915_private_t *dev_priv = dev->dev_private;
251 u32 flip_addr = overlay->flip_addr;
252 u32 tmp;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200253
254 BUG_ON(!overlay->active);
255
256 if (load_polyphase_filter)
257 flip_addr |= OFC_UPDATE;
258
259 /* check for underruns */
260 tmp = I915_READ(DOVSTA);
261 if (tmp & (1 << 17))
262 DRM_DEBUG("overlay underrun, DOVSTA: %x\n", tmp);
263
Daniel Vetter4f8a5672010-02-11 14:14:43 +0100264 BEGIN_LP_RING(2);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200265 OUT_RING(MI_OVERLAY_FLIP | MI_OVERLAY_CONTINUE);
266 OUT_RING(flip_addr);
Daniel Vetter5a5a0c62009-09-15 22:57:36 +0200267 ADVANCE_LP_RING();
268
Zou Nan hai852835f2010-05-21 09:08:56 +0800269 overlay->last_flip_req =
Daniel Vetter8a1a49f2010-02-11 22:29:04 +0100270 i915_add_request(dev, NULL, &dev_priv->render_ring);
Daniel Vetter5a5a0c62009-09-15 22:57:36 +0200271}
272
273static int intel_overlay_wait_flip(struct intel_overlay *overlay)
274{
275 struct drm_device *dev = overlay->dev;
Chris Wilson722506f2010-08-12 09:28:50 +0100276 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetter5a5a0c62009-09-15 22:57:36 +0200277 int ret;
278 u32 tmp;
Daniel Vetter5a5a0c62009-09-15 22:57:36 +0200279
280 if (overlay->last_flip_req != 0) {
Chris Wilson722506f2010-08-12 09:28:50 +0100281 ret = i915_do_wait_request(dev,
282 overlay->last_flip_req, true,
283 &dev_priv->render_ring);
Daniel Vetter5c5a4352009-10-04 15:00:36 +0200284 if (ret == 0) {
285 overlay->last_flip_req = 0;
Daniel Vetter5a5a0c62009-09-15 22:57:36 +0200286
Daniel Vetter5c5a4352009-10-04 15:00:36 +0200287 tmp = I915_READ(ISR);
Daniel Vetter5a5a0c62009-09-15 22:57:36 +0200288
Daniel Vetter5c5a4352009-10-04 15:00:36 +0200289 if (!(tmp & I915_OVERLAY_PLANE_FLIP_PENDING_INTERRUPT))
290 return 0;
291 }
Daniel Vetter5a5a0c62009-09-15 22:57:36 +0200292 }
293
294 /* synchronous slowpath */
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200295 overlay->hw_wedged = RELEASE_OLD_VID;
296
Daniel Vetter5a5a0c62009-09-15 22:57:36 +0200297 BEGIN_LP_RING(2);
Chris Wilson722506f2010-08-12 09:28:50 +0100298 OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP);
299 OUT_RING(MI_NOOP);
300 ADVANCE_LP_RING();
Daniel Vetter02e792f2009-09-15 22:57:34 +0200301
Zou Nan hai852835f2010-05-21 09:08:56 +0800302 overlay->last_flip_req =
Daniel Vetter8a1a49f2010-02-11 22:29:04 +0100303 i915_add_request(dev, NULL, &dev_priv->render_ring);
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200304 if (overlay->last_flip_req == 0)
305 return -ENOMEM;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200306
Chris Wilson722506f2010-08-12 09:28:50 +0100307 ret = i915_do_wait_request(dev,
308 overlay->last_flip_req, true,
309 &dev_priv->render_ring);
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200310 if (ret != 0)
311 return ret;
312
313 overlay->hw_wedged = 0;
314 overlay->last_flip_req = 0;
315 return 0;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200316}
317
318/* overlay needs to be disabled in OCMD reg */
319static int intel_overlay_off(struct intel_overlay *overlay)
320{
321 u32 flip_addr = overlay->flip_addr;
322 struct drm_device *dev = overlay->dev;
Zou Nan hai852835f2010-05-21 09:08:56 +0800323 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200324 int ret;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200325
326 BUG_ON(!overlay->active);
327
328 /* According to intel docs the overlay hw may hang (when switching
329 * off) without loading the filter coeffs. It is however unclear whether
330 * this applies to the disabling of the overlay or to the switching off
331 * of the hw. Do it in both cases */
332 flip_addr |= OFC_UPDATE;
333
334 /* wait for overlay to go idle */
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200335 overlay->hw_wedged = SWITCH_OFF_STAGE_1;
336
Daniel Vetter4f8a5672010-02-11 14:14:43 +0100337 BEGIN_LP_RING(4);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200338 OUT_RING(MI_OVERLAY_FLIP | MI_OVERLAY_CONTINUE);
339 OUT_RING(flip_addr);
Chris Wilson722506f2010-08-12 09:28:50 +0100340 OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP);
341 OUT_RING(MI_NOOP);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200342 ADVANCE_LP_RING();
343
Zou Nan hai852835f2010-05-21 09:08:56 +0800344 overlay->last_flip_req =
Daniel Vetter8a1a49f2010-02-11 22:29:04 +0100345 i915_add_request(dev, NULL, &dev_priv->render_ring);
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200346 if (overlay->last_flip_req == 0)
347 return -ENOMEM;
348
Chris Wilson722506f2010-08-12 09:28:50 +0100349 ret = i915_do_wait_request(dev,
350 overlay->last_flip_req, true,
351 &dev_priv->render_ring);
352 if (ret != 0)
353 return ret;
354
355 /* turn overlay off */
356 overlay->hw_wedged = SWITCH_OFF_STAGE_2;
357
358 BEGIN_LP_RING(4);
359 OUT_RING(MI_OVERLAY_FLIP | MI_OVERLAY_OFF);
360 OUT_RING(flip_addr);
361 OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP);
362 OUT_RING(MI_NOOP);
363 ADVANCE_LP_RING();
364
365 overlay->last_flip_req =
366 i915_add_request(dev, NULL, &dev_priv->render_ring);
367 if (overlay->last_flip_req == 0)
368 return -ENOMEM;
369
370 ret = i915_do_wait_request(dev,
371 overlay->last_flip_req, true,
372 &dev_priv->render_ring);
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200373 if (ret != 0)
Daniel Vetter02e792f2009-09-15 22:57:34 +0200374 return ret;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200375
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200376 overlay->hw_wedged = 0;
377 overlay->last_flip_req = 0;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200378 return ret;
379}
380
Daniel Vetter12ca45f2037-04-25 10:08:26 +0200381static void intel_overlay_off_tail(struct intel_overlay *overlay)
382{
383 struct drm_gem_object *obj;
384
385 /* never have the overlay hw on without showing a frame */
386 BUG_ON(!overlay->vid_bo);
Daniel Vettera8089e82010-04-09 19:05:09 +0000387 obj = &overlay->vid_bo->base;
Daniel Vetter12ca45f2037-04-25 10:08:26 +0200388
389 i915_gem_object_unpin(obj);
390 drm_gem_object_unreference(obj);
391 overlay->vid_bo = NULL;
392
393 overlay->crtc->overlay = NULL;
394 overlay->crtc = NULL;
395 overlay->active = 0;
396}
397
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200398/* recover from an interruption due to a signal
399 * We have to be careful not to repeat work forever an make forward progess. */
400int intel_overlay_recover_from_interrupt(struct intel_overlay *overlay,
Chris Wilson722506f2010-08-12 09:28:50 +0100401 bool interruptible)
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200402{
403 struct drm_device *dev = overlay->dev;
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200404 struct drm_gem_object *obj;
Zou Nan hai852835f2010-05-21 09:08:56 +0800405 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200406 u32 flip_addr;
407 int ret;
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200408
409 if (overlay->hw_wedged == HW_WEDGED)
410 return -EIO;
411
412 if (overlay->last_flip_req == 0) {
Zou Nan hai852835f2010-05-21 09:08:56 +0800413 overlay->last_flip_req =
Daniel Vetter8a1a49f2010-02-11 22:29:04 +0100414 i915_add_request(dev, NULL, &dev_priv->render_ring);
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200415 if (overlay->last_flip_req == 0)
416 return -ENOMEM;
417 }
418
Zou Nan hai852835f2010-05-21 09:08:56 +0800419 ret = i915_do_wait_request(dev, overlay->last_flip_req,
Chris Wilson722506f2010-08-12 09:28:50 +0100420 interruptible, &dev_priv->render_ring);
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200421 if (ret != 0)
422 return ret;
423
424 switch (overlay->hw_wedged) {
Chris Wilson722506f2010-08-12 09:28:50 +0100425 case RELEASE_OLD_VID:
426 obj = &overlay->old_vid_bo->base;
427 i915_gem_object_unpin(obj);
428 drm_gem_object_unreference(obj);
429 overlay->old_vid_bo = NULL;
430 break;
431 case SWITCH_OFF_STAGE_1:
432 flip_addr = overlay->flip_addr;
433 flip_addr |= OFC_UPDATE;
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200434
Chris Wilson722506f2010-08-12 09:28:50 +0100435 overlay->hw_wedged = SWITCH_OFF_STAGE_2;
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200436
Chris Wilson722506f2010-08-12 09:28:50 +0100437 BEGIN_LP_RING(4);
438 OUT_RING(MI_OVERLAY_FLIP | MI_OVERLAY_OFF);
439 OUT_RING(flip_addr);
440 OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP);
441 OUT_RING(MI_NOOP);
442 ADVANCE_LP_RING();
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200443
Chris Wilson722506f2010-08-12 09:28:50 +0100444 overlay->last_flip_req =
445 i915_add_request(dev, NULL,
446 &dev_priv->render_ring);
447 if (overlay->last_flip_req == 0)
448 return -ENOMEM;
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200449
Chris Wilson722506f2010-08-12 09:28:50 +0100450 ret = i915_do_wait_request(dev, overlay->last_flip_req,
451 interruptible,
452 &dev_priv->render_ring);
453 if (ret != 0)
454 return ret;
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200455
Chris Wilson722506f2010-08-12 09:28:50 +0100456 case SWITCH_OFF_STAGE_2:
457 intel_overlay_off_tail(overlay);
458 break;
459 default:
460 BUG_ON(overlay->hw_wedged != NEEDS_WAIT_FOR_FLIP);
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200461 }
462
463 overlay->hw_wedged = 0;
464 overlay->last_flip_req = 0;
465 return 0;
466}
467
Daniel Vetter5a5a0c62009-09-15 22:57:36 +0200468/* Wait for pending overlay flip and release old frame.
469 * Needs to be called before the overlay register are changed
470 * via intel_overlay_(un)map_regs_atomic */
Daniel Vetter02e792f2009-09-15 22:57:34 +0200471static int intel_overlay_release_old_vid(struct intel_overlay *overlay)
472{
473 int ret;
474 struct drm_gem_object *obj;
475
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200476 /* only wait if there is actually an old frame to release to
477 * guarantee forward progress */
478 if (!overlay->old_vid_bo)
479 return 0;
480
Daniel Vetter02e792f2009-09-15 22:57:34 +0200481 ret = intel_overlay_wait_flip(overlay);
482 if (ret != 0)
483 return ret;
484
Daniel Vettera8089e82010-04-09 19:05:09 +0000485 obj = &overlay->old_vid_bo->base;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200486 i915_gem_object_unpin(obj);
487 drm_gem_object_unreference(obj);
488 overlay->old_vid_bo = NULL;
489
490 return 0;
491}
492
493struct put_image_params {
494 int format;
495 short dst_x;
496 short dst_y;
497 short dst_w;
498 short dst_h;
499 short src_w;
500 short src_scan_h;
501 short src_scan_w;
502 short src_h;
503 short stride_Y;
504 short stride_UV;
505 int offset_Y;
506 int offset_U;
507 int offset_V;
508};
509
510static int packed_depth_bytes(u32 format)
511{
512 switch (format & I915_OVERLAY_DEPTH_MASK) {
Chris Wilson722506f2010-08-12 09:28:50 +0100513 case I915_OVERLAY_YUV422:
514 return 4;
515 case I915_OVERLAY_YUV411:
516 /* return 6; not implemented */
517 default:
518 return -EINVAL;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200519 }
520}
521
522static int packed_width_bytes(u32 format, short width)
523{
524 switch (format & I915_OVERLAY_DEPTH_MASK) {
Chris Wilson722506f2010-08-12 09:28:50 +0100525 case I915_OVERLAY_YUV422:
526 return width << 1;
527 default:
528 return -EINVAL;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200529 }
530}
531
532static int uv_hsubsampling(u32 format)
533{
534 switch (format & I915_OVERLAY_DEPTH_MASK) {
Chris Wilson722506f2010-08-12 09:28:50 +0100535 case I915_OVERLAY_YUV422:
536 case I915_OVERLAY_YUV420:
537 return 2;
538 case I915_OVERLAY_YUV411:
539 case I915_OVERLAY_YUV410:
540 return 4;
541 default:
542 return -EINVAL;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200543 }
544}
545
546static int uv_vsubsampling(u32 format)
547{
548 switch (format & I915_OVERLAY_DEPTH_MASK) {
Chris Wilson722506f2010-08-12 09:28:50 +0100549 case I915_OVERLAY_YUV420:
550 case I915_OVERLAY_YUV410:
551 return 2;
552 case I915_OVERLAY_YUV422:
553 case I915_OVERLAY_YUV411:
554 return 1;
555 default:
556 return -EINVAL;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200557 }
558}
559
560static u32 calc_swidthsw(struct drm_device *dev, u32 offset, u32 width)
561{
562 u32 mask, shift, ret;
563 if (IS_I9XX(dev)) {
564 mask = 0x3f;
565 shift = 6;
566 } else {
567 mask = 0x1f;
568 shift = 5;
569 }
570 ret = ((offset + width + mask) >> shift) - (offset >> shift);
571 if (IS_I9XX(dev))
572 ret <<= 1;
573 ret -=1;
574 return ret << 2;
575}
576
577static const u16 y_static_hcoeffs[N_HORIZ_Y_TAPS * N_PHASES] = {
578 0x3000, 0xb4a0, 0x1930, 0x1920, 0xb4a0,
579 0x3000, 0xb500, 0x19d0, 0x1880, 0xb440,
580 0x3000, 0xb540, 0x1a88, 0x2f80, 0xb3e0,
581 0x3000, 0xb580, 0x1b30, 0x2e20, 0xb380,
582 0x3000, 0xb5c0, 0x1bd8, 0x2cc0, 0xb320,
583 0x3020, 0xb5e0, 0x1c60, 0x2b80, 0xb2c0,
584 0x3020, 0xb5e0, 0x1cf8, 0x2a20, 0xb260,
585 0x3020, 0xb5e0, 0x1d80, 0x28e0, 0xb200,
586 0x3020, 0xb5c0, 0x1e08, 0x3f40, 0xb1c0,
587 0x3020, 0xb580, 0x1e78, 0x3ce0, 0xb160,
588 0x3040, 0xb520, 0x1ed8, 0x3aa0, 0xb120,
589 0x3040, 0xb4a0, 0x1f30, 0x3880, 0xb0e0,
590 0x3040, 0xb400, 0x1f78, 0x3680, 0xb0a0,
591 0x3020, 0xb340, 0x1fb8, 0x34a0, 0xb060,
592 0x3020, 0xb240, 0x1fe0, 0x32e0, 0xb040,
593 0x3020, 0xb140, 0x1ff8, 0x3160, 0xb020,
Chris Wilson722506f2010-08-12 09:28:50 +0100594 0xb000, 0x3000, 0x0800, 0x3000, 0xb000
595};
596
Daniel Vetter02e792f2009-09-15 22:57:34 +0200597static const u16 uv_static_hcoeffs[N_HORIZ_UV_TAPS * N_PHASES] = {
598 0x3000, 0x1800, 0x1800, 0xb000, 0x18d0, 0x2e60,
599 0xb000, 0x1990, 0x2ce0, 0xb020, 0x1a68, 0x2b40,
600 0xb040, 0x1b20, 0x29e0, 0xb060, 0x1bd8, 0x2880,
601 0xb080, 0x1c88, 0x3e60, 0xb0a0, 0x1d28, 0x3c00,
602 0xb0c0, 0x1db8, 0x39e0, 0xb0e0, 0x1e40, 0x37e0,
603 0xb100, 0x1eb8, 0x3620, 0xb100, 0x1f18, 0x34a0,
604 0xb100, 0x1f68, 0x3360, 0xb0e0, 0x1fa8, 0x3240,
605 0xb0c0, 0x1fe0, 0x3140, 0xb060, 0x1ff0, 0x30a0,
Chris Wilson722506f2010-08-12 09:28:50 +0100606 0x3000, 0x0800, 0x3000
607};
Daniel Vetter02e792f2009-09-15 22:57:34 +0200608
609static void update_polyphase_filter(struct overlay_registers *regs)
610{
611 memcpy(regs->Y_HCOEFS, y_static_hcoeffs, sizeof(y_static_hcoeffs));
612 memcpy(regs->UV_HCOEFS, uv_static_hcoeffs, sizeof(uv_static_hcoeffs));
613}
614
615static bool update_scaling_factors(struct intel_overlay *overlay,
616 struct overlay_registers *regs,
617 struct put_image_params *params)
618{
619 /* fixed point with a 12 bit shift */
620 u32 xscale, yscale, xscale_UV, yscale_UV;
621#define FP_SHIFT 12
622#define FRACT_MASK 0xfff
623 bool scale_changed = false;
624 int uv_hscale = uv_hsubsampling(params->format);
625 int uv_vscale = uv_vsubsampling(params->format);
626
627 if (params->dst_w > 1)
628 xscale = ((params->src_scan_w - 1) << FP_SHIFT)
629 /(params->dst_w);
630 else
631 xscale = 1 << FP_SHIFT;
632
633 if (params->dst_h > 1)
634 yscale = ((params->src_scan_h - 1) << FP_SHIFT)
635 /(params->dst_h);
636 else
637 yscale = 1 << FP_SHIFT;
638
639 /*if (params->format & I915_OVERLAY_YUV_PLANAR) {*/
Chris Wilson722506f2010-08-12 09:28:50 +0100640 xscale_UV = xscale/uv_hscale;
641 yscale_UV = yscale/uv_vscale;
642 /* make the Y scale to UV scale ratio an exact multiply */
643 xscale = xscale_UV * uv_hscale;
644 yscale = yscale_UV * uv_vscale;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200645 /*} else {
Chris Wilson722506f2010-08-12 09:28:50 +0100646 xscale_UV = 0;
647 yscale_UV = 0;
648 }*/
Daniel Vetter02e792f2009-09-15 22:57:34 +0200649
650 if (xscale != overlay->old_xscale || yscale != overlay->old_yscale)
651 scale_changed = true;
652 overlay->old_xscale = xscale;
653 overlay->old_yscale = yscale;
654
Chris Wilson722506f2010-08-12 09:28:50 +0100655 regs->YRGBSCALE = (((yscale & FRACT_MASK) << 20) |
656 ((xscale >> FP_SHIFT) << 16) |
657 ((xscale & FRACT_MASK) << 3));
658
659 regs->UVSCALE = (((yscale_UV & FRACT_MASK) << 20) |
660 ((xscale_UV >> FP_SHIFT) << 16) |
661 ((xscale_UV & FRACT_MASK) << 3));
662
663 regs->UVSCALEV = ((((yscale >> FP_SHIFT) << 16) |
664 ((yscale_UV >> FP_SHIFT) << 0)));
Daniel Vetter02e792f2009-09-15 22:57:34 +0200665
666 if (scale_changed)
667 update_polyphase_filter(regs);
668
669 return scale_changed;
670}
671
672static void update_colorkey(struct intel_overlay *overlay,
673 struct overlay_registers *regs)
674{
675 u32 key = overlay->color_key;
Chris Wilson6ba3ddd2010-08-12 09:30:58 +0100676
Daniel Vetter02e792f2009-09-15 22:57:34 +0200677 switch (overlay->crtc->base.fb->bits_per_pixel) {
Chris Wilson722506f2010-08-12 09:28:50 +0100678 case 8:
679 regs->DCLRKV = 0;
680 regs->DCLRKM = CLK_RGB8I_MASK | DST_KEY_ENABLE;
Chris Wilson6ba3ddd2010-08-12 09:30:58 +0100681 break;
682
Chris Wilson722506f2010-08-12 09:28:50 +0100683 case 16:
684 if (overlay->crtc->base.fb->depth == 15) {
685 regs->DCLRKV = RGB15_TO_COLORKEY(key);
686 regs->DCLRKM = CLK_RGB15_MASK | DST_KEY_ENABLE;
687 } else {
688 regs->DCLRKV = RGB16_TO_COLORKEY(key);
689 regs->DCLRKM = CLK_RGB16_MASK | DST_KEY_ENABLE;
690 }
Chris Wilson6ba3ddd2010-08-12 09:30:58 +0100691 break;
692
Chris Wilson722506f2010-08-12 09:28:50 +0100693 case 24:
694 case 32:
695 regs->DCLRKV = key;
696 regs->DCLRKM = CLK_RGB24_MASK | DST_KEY_ENABLE;
Chris Wilson6ba3ddd2010-08-12 09:30:58 +0100697 break;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200698 }
699}
700
701static u32 overlay_cmd_reg(struct put_image_params *params)
702{
703 u32 cmd = OCMD_ENABLE | OCMD_BUF_TYPE_FRAME | OCMD_BUFFER0;
704
705 if (params->format & I915_OVERLAY_YUV_PLANAR) {
706 switch (params->format & I915_OVERLAY_DEPTH_MASK) {
Chris Wilson722506f2010-08-12 09:28:50 +0100707 case I915_OVERLAY_YUV422:
708 cmd |= OCMD_YUV_422_PLANAR;
709 break;
710 case I915_OVERLAY_YUV420:
711 cmd |= OCMD_YUV_420_PLANAR;
712 break;
713 case I915_OVERLAY_YUV411:
714 case I915_OVERLAY_YUV410:
715 cmd |= OCMD_YUV_410_PLANAR;
716 break;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200717 }
718 } else { /* YUV packed */
719 switch (params->format & I915_OVERLAY_DEPTH_MASK) {
Chris Wilson722506f2010-08-12 09:28:50 +0100720 case I915_OVERLAY_YUV422:
721 cmd |= OCMD_YUV_422_PACKED;
722 break;
723 case I915_OVERLAY_YUV411:
724 cmd |= OCMD_YUV_411_PACKED;
725 break;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200726 }
727
728 switch (params->format & I915_OVERLAY_SWAP_MASK) {
Chris Wilson722506f2010-08-12 09:28:50 +0100729 case I915_OVERLAY_NO_SWAP:
730 break;
731 case I915_OVERLAY_UV_SWAP:
732 cmd |= OCMD_UV_SWAP;
733 break;
734 case I915_OVERLAY_Y_SWAP:
735 cmd |= OCMD_Y_SWAP;
736 break;
737 case I915_OVERLAY_Y_AND_UV_SWAP:
738 cmd |= OCMD_Y_AND_UV_SWAP;
739 break;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200740 }
741 }
742
743 return cmd;
744}
745
746int intel_overlay_do_put_image(struct intel_overlay *overlay,
747 struct drm_gem_object *new_bo,
748 struct put_image_params *params)
749{
750 int ret, tmp_width;
751 struct overlay_registers *regs;
752 bool scale_changed = false;
Daniel Vetter23010e42010-03-08 13:35:02 +0100753 struct drm_i915_gem_object *bo_priv = to_intel_bo(new_bo);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200754 struct drm_device *dev = overlay->dev;
755
756 BUG_ON(!mutex_is_locked(&dev->struct_mutex));
757 BUG_ON(!mutex_is_locked(&dev->mode_config.mutex));
758 BUG_ON(!overlay);
759
Daniel Vetter02e792f2009-09-15 22:57:34 +0200760 ret = intel_overlay_release_old_vid(overlay);
761 if (ret != 0)
762 return ret;
763
764 ret = i915_gem_object_pin(new_bo, PAGE_SIZE);
765 if (ret != 0)
766 return ret;
767
768 ret = i915_gem_object_set_to_gtt_domain(new_bo, 0);
769 if (ret != 0)
770 goto out_unpin;
771
772 if (!overlay->active) {
773 regs = intel_overlay_map_regs_atomic(overlay);
774 if (!regs) {
775 ret = -ENOMEM;
776 goto out_unpin;
777 }
778 regs->OCONFIG = OCONF_CC_OUT_8BIT;
779 if (IS_I965GM(overlay->dev))
780 regs->OCONFIG |= OCONF_CSC_MODE_BT709;
781 regs->OCONFIG |= overlay->crtc->pipe == 0 ?
782 OCONF_PIPE_A : OCONF_PIPE_B;
783 intel_overlay_unmap_regs_atomic(overlay);
784
785 ret = intel_overlay_on(overlay);
786 if (ret != 0)
787 goto out_unpin;
788 }
789
790 regs = intel_overlay_map_regs_atomic(overlay);
791 if (!regs) {
792 ret = -ENOMEM;
793 goto out_unpin;
794 }
795
796 regs->DWINPOS = (params->dst_y << 16) | params->dst_x;
797 regs->DWINSZ = (params->dst_h << 16) | params->dst_w;
798
799 if (params->format & I915_OVERLAY_YUV_PACKED)
800 tmp_width = packed_width_bytes(params->format, params->src_w);
801 else
802 tmp_width = params->src_w;
803
804 regs->SWIDTH = params->src_w;
805 regs->SWIDTHSW = calc_swidthsw(overlay->dev,
Chris Wilson722506f2010-08-12 09:28:50 +0100806 params->offset_Y, tmp_width);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200807 regs->SHEIGHT = params->src_h;
808 regs->OBUF_0Y = bo_priv->gtt_offset + params-> offset_Y;
809 regs->OSTRIDE = params->stride_Y;
810
811 if (params->format & I915_OVERLAY_YUV_PLANAR) {
812 int uv_hscale = uv_hsubsampling(params->format);
813 int uv_vscale = uv_vsubsampling(params->format);
814 u32 tmp_U, tmp_V;
815 regs->SWIDTH |= (params->src_w/uv_hscale) << 16;
816 tmp_U = calc_swidthsw(overlay->dev, params->offset_U,
Chris Wilson722506f2010-08-12 09:28:50 +0100817 params->src_w/uv_hscale);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200818 tmp_V = calc_swidthsw(overlay->dev, params->offset_V,
Chris Wilson722506f2010-08-12 09:28:50 +0100819 params->src_w/uv_hscale);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200820 regs->SWIDTHSW |= max_t(u32, tmp_U, tmp_V) << 16;
821 regs->SHEIGHT |= (params->src_h/uv_vscale) << 16;
822 regs->OBUF_0U = bo_priv->gtt_offset + params->offset_U;
823 regs->OBUF_0V = bo_priv->gtt_offset + params->offset_V;
824 regs->OSTRIDE |= params->stride_UV << 16;
825 }
826
827 scale_changed = update_scaling_factors(overlay, regs, params);
828
829 update_colorkey(overlay, regs);
830
831 regs->OCMD = overlay_cmd_reg(params);
832
833 intel_overlay_unmap_regs_atomic(overlay);
834
835 intel_overlay_continue(overlay, scale_changed);
836
837 overlay->old_vid_bo = overlay->vid_bo;
Daniel Vetter23010e42010-03-08 13:35:02 +0100838 overlay->vid_bo = to_intel_bo(new_bo);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200839
840 return 0;
841
842out_unpin:
843 i915_gem_object_unpin(new_bo);
844 return ret;
845}
846
847int intel_overlay_switch_off(struct intel_overlay *overlay)
848{
849 int ret;
850 struct overlay_registers *regs;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200851 struct drm_device *dev = overlay->dev;
852
853 BUG_ON(!mutex_is_locked(&dev->struct_mutex));
854 BUG_ON(!mutex_is_locked(&dev->mode_config.mutex));
855
Daniel Vetter9bedb972009-11-30 15:55:49 +0100856 if (overlay->hw_wedged) {
857 ret = intel_overlay_recover_from_interrupt(overlay, 1);
858 if (ret != 0)
859 return ret;
860 }
861
Daniel Vetter02e792f2009-09-15 22:57:34 +0200862 if (!overlay->active)
863 return 0;
864
Daniel Vetter02e792f2009-09-15 22:57:34 +0200865 ret = intel_overlay_release_old_vid(overlay);
866 if (ret != 0)
867 return ret;
868
869 regs = intel_overlay_map_regs_atomic(overlay);
870 regs->OCMD = 0;
871 intel_overlay_unmap_regs_atomic(overlay);
872
873 ret = intel_overlay_off(overlay);
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200874 if (ret != 0)
875 return ret;
876
Daniel Vetter12ca45f2037-04-25 10:08:26 +0200877 intel_overlay_off_tail(overlay);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200878
879 return 0;
880}
881
882static int check_overlay_possible_on_crtc(struct intel_overlay *overlay,
883 struct intel_crtc *crtc)
884{
Chris Wilson722506f2010-08-12 09:28:50 +0100885 drm_i915_private_t *dev_priv = overlay->dev->dev_private;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200886 u32 pipeconf;
887 int pipeconf_reg = (crtc->pipe == 0) ? PIPEACONF : PIPEBCONF;
888
889 if (!crtc->base.enabled || crtc->dpms_mode != DRM_MODE_DPMS_ON)
890 return -EINVAL;
891
892 pipeconf = I915_READ(pipeconf_reg);
893
894 /* can't use the overlay with double wide pipe */
895 if (!IS_I965G(overlay->dev) && pipeconf & PIPEACONF_DOUBLE_WIDE)
896 return -EINVAL;
897
898 return 0;
899}
900
901static void update_pfit_vscale_ratio(struct intel_overlay *overlay)
902{
903 struct drm_device *dev = overlay->dev;
Chris Wilson722506f2010-08-12 09:28:50 +0100904 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200905 u32 ratio;
906 u32 pfit_control = I915_READ(PFIT_CONTROL);
907
908 /* XXX: This is not the same logic as in the xorg driver, but more in
909 * line with the intel documentation for the i965 */
910 if (!IS_I965G(dev) && (pfit_control & VERT_AUTO_SCALE)) {
911 ratio = I915_READ(PFIT_AUTO_RATIOS) >> PFIT_VERT_SCALE_SHIFT;
912 } else { /* on i965 use the PGM reg to read out the autoscaler values */
913 ratio = I915_READ(PFIT_PGM_RATIOS);
914 if (IS_I965G(dev))
915 ratio >>= PFIT_VERT_SCALE_SHIFT_965;
916 else
917 ratio >>= PFIT_VERT_SCALE_SHIFT;
918 }
919
920 overlay->pfit_vscale_ratio = ratio;
921}
922
923static int check_overlay_dst(struct intel_overlay *overlay,
924 struct drm_intel_overlay_put_image *rec)
925{
926 struct drm_display_mode *mode = &overlay->crtc->base.mode;
927
Chris Wilson722506f2010-08-12 09:28:50 +0100928 if (rec->dst_x < mode->crtc_hdisplay &&
929 rec->dst_x + rec->dst_width <= mode->crtc_hdisplay &&
930 rec->dst_y < mode->crtc_vdisplay &&
931 rec->dst_y + rec->dst_height <= mode->crtc_vdisplay)
Daniel Vetter02e792f2009-09-15 22:57:34 +0200932 return 0;
933 else
934 return -EINVAL;
935}
936
937static int check_overlay_scaling(struct put_image_params *rec)
938{
939 u32 tmp;
940
941 /* downscaling limit is 8.0 */
942 tmp = ((rec->src_scan_h << 16) / rec->dst_h) >> 16;
943 if (tmp > 7)
944 return -EINVAL;
945 tmp = ((rec->src_scan_w << 16) / rec->dst_w) >> 16;
946 if (tmp > 7)
947 return -EINVAL;
948
949 return 0;
950}
951
952static int check_overlay_src(struct drm_device *dev,
953 struct drm_intel_overlay_put_image *rec,
954 struct drm_gem_object *new_bo)
955{
956 u32 stride_mask;
957 int depth;
958 int uv_hscale = uv_hsubsampling(rec->flags);
959 int uv_vscale = uv_vsubsampling(rec->flags);
960 size_t tmp;
961
962 /* check src dimensions */
963 if (IS_845G(dev) || IS_I830(dev)) {
Chris Wilson722506f2010-08-12 09:28:50 +0100964 if (rec->src_height > IMAGE_MAX_HEIGHT_LEGACY ||
965 rec->src_width > IMAGE_MAX_WIDTH_LEGACY)
Daniel Vetter02e792f2009-09-15 22:57:34 +0200966 return -EINVAL;
967 } else {
Chris Wilson722506f2010-08-12 09:28:50 +0100968 if (rec->src_height > IMAGE_MAX_HEIGHT ||
969 rec->src_width > IMAGE_MAX_WIDTH)
Daniel Vetter02e792f2009-09-15 22:57:34 +0200970 return -EINVAL;
971 }
972 /* better safe than sorry, use 4 as the maximal subsampling ratio */
Chris Wilson722506f2010-08-12 09:28:50 +0100973 if (rec->src_height < N_VERT_Y_TAPS*4 ||
974 rec->src_width < N_HORIZ_Y_TAPS*4)
Daniel Vetter02e792f2009-09-15 22:57:34 +0200975 return -EINVAL;
976
Chris Wilsona1efd142010-07-12 19:35:38 +0100977 /* check alignment constraints */
Daniel Vetter02e792f2009-09-15 22:57:34 +0200978 switch (rec->flags & I915_OVERLAY_TYPE_MASK) {
Chris Wilson722506f2010-08-12 09:28:50 +0100979 case I915_OVERLAY_RGB:
980 /* not implemented */
981 return -EINVAL;
982 case I915_OVERLAY_YUV_PACKED:
983 depth = packed_depth_bytes(rec->flags);
984 if (uv_vscale != 1)
Daniel Vetter02e792f2009-09-15 22:57:34 +0200985 return -EINVAL;
Chris Wilson722506f2010-08-12 09:28:50 +0100986 if (depth < 0)
987 return depth;
988 /* ignore UV planes */
989 rec->stride_UV = 0;
990 rec->offset_U = 0;
991 rec->offset_V = 0;
992 /* check pixel alignment */
993 if (rec->offset_Y % depth)
Daniel Vetter02e792f2009-09-15 22:57:34 +0200994 return -EINVAL;
Chris Wilson722506f2010-08-12 09:28:50 +0100995 break;
996 case I915_OVERLAY_YUV_PLANAR:
997 if (uv_vscale < 0 || uv_hscale < 0)
998 return -EINVAL;
999 /* no offset restrictions for planar formats */
1000 break;
1001 default:
1002 return -EINVAL;
Daniel Vetter02e792f2009-09-15 22:57:34 +02001003 }
1004
1005 if (rec->src_width % uv_hscale)
1006 return -EINVAL;
1007
1008 /* stride checking */
Chris Wilsona1efd142010-07-12 19:35:38 +01001009 if (IS_I830(dev) || IS_845G(dev))
1010 stride_mask = 255;
1011 else
1012 stride_mask = 63;
Daniel Vetter02e792f2009-09-15 22:57:34 +02001013
1014 if (rec->stride_Y & stride_mask || rec->stride_UV & stride_mask)
1015 return -EINVAL;
1016 if (IS_I965G(dev) && rec->stride_Y < 512)
1017 return -EINVAL;
1018
1019 tmp = (rec->flags & I915_OVERLAY_TYPE_MASK) == I915_OVERLAY_YUV_PLANAR ?
1020 4 : 8;
1021 if (rec->stride_Y > tmp*1024 || rec->stride_UV > 2*1024)
1022 return -EINVAL;
1023
1024 /* check buffer dimensions */
1025 switch (rec->flags & I915_OVERLAY_TYPE_MASK) {
Chris Wilson722506f2010-08-12 09:28:50 +01001026 case I915_OVERLAY_RGB:
1027 case I915_OVERLAY_YUV_PACKED:
1028 /* always 4 Y values per depth pixels */
1029 if (packed_width_bytes(rec->flags, rec->src_width) > rec->stride_Y)
1030 return -EINVAL;
Daniel Vetter02e792f2009-09-15 22:57:34 +02001031
Chris Wilson722506f2010-08-12 09:28:50 +01001032 tmp = rec->stride_Y*rec->src_height;
1033 if (rec->offset_Y + tmp > new_bo->size)
1034 return -EINVAL;
1035 break;
Daniel Vetter02e792f2009-09-15 22:57:34 +02001036
Chris Wilson722506f2010-08-12 09:28:50 +01001037 case I915_OVERLAY_YUV_PLANAR:
1038 if (rec->src_width > rec->stride_Y)
1039 return -EINVAL;
1040 if (rec->src_width/uv_hscale > rec->stride_UV)
1041 return -EINVAL;
1042
1043 tmp = rec->stride_Y*rec->src_height;
1044 if (rec->offset_Y + tmp > new_bo->size)
1045 return -EINVAL;
1046 tmp = rec->stride_UV*rec->src_height;
1047 tmp /= uv_vscale;
1048 if (rec->offset_U + tmp > new_bo->size ||
1049 rec->offset_V + tmp > new_bo->size)
1050 return -EINVAL;
1051 break;
Daniel Vetter02e792f2009-09-15 22:57:34 +02001052 }
1053
1054 return 0;
1055}
1056
1057int intel_overlay_put_image(struct drm_device *dev, void *data,
1058 struct drm_file *file_priv)
1059{
1060 struct drm_intel_overlay_put_image *put_image_rec = data;
1061 drm_i915_private_t *dev_priv = dev->dev_private;
1062 struct intel_overlay *overlay;
1063 struct drm_mode_object *drmmode_obj;
1064 struct intel_crtc *crtc;
1065 struct drm_gem_object *new_bo;
1066 struct put_image_params *params;
1067 int ret;
1068
1069 if (!dev_priv) {
1070 DRM_ERROR("called with no initialization\n");
1071 return -EINVAL;
1072 }
1073
1074 overlay = dev_priv->overlay;
1075 if (!overlay) {
1076 DRM_DEBUG("userspace bug: no overlay\n");
1077 return -ENODEV;
1078 }
1079
1080 if (!(put_image_rec->flags & I915_OVERLAY_ENABLE)) {
1081 mutex_lock(&dev->mode_config.mutex);
1082 mutex_lock(&dev->struct_mutex);
1083
1084 ret = intel_overlay_switch_off(overlay);
1085
1086 mutex_unlock(&dev->struct_mutex);
1087 mutex_unlock(&dev->mode_config.mutex);
1088
1089 return ret;
1090 }
1091
1092 params = kmalloc(sizeof(struct put_image_params), GFP_KERNEL);
1093 if (!params)
1094 return -ENOMEM;
1095
1096 drmmode_obj = drm_mode_object_find(dev, put_image_rec->crtc_id,
Chris Wilson722506f2010-08-12 09:28:50 +01001097 DRM_MODE_OBJECT_CRTC);
Dan Carpenter915a4282010-03-06 14:05:39 +03001098 if (!drmmode_obj) {
1099 ret = -ENOENT;
1100 goto out_free;
1101 }
Daniel Vetter02e792f2009-09-15 22:57:34 +02001102 crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
1103
1104 new_bo = drm_gem_object_lookup(dev, file_priv,
Chris Wilson722506f2010-08-12 09:28:50 +01001105 put_image_rec->bo_handle);
Dan Carpenter915a4282010-03-06 14:05:39 +03001106 if (!new_bo) {
1107 ret = -ENOENT;
1108 goto out_free;
1109 }
Daniel Vetter02e792f2009-09-15 22:57:34 +02001110
1111 mutex_lock(&dev->mode_config.mutex);
1112 mutex_lock(&dev->struct_mutex);
1113
Daniel Vetter03f77ea2009-09-15 22:57:37 +02001114 if (overlay->hw_wedged) {
1115 ret = intel_overlay_recover_from_interrupt(overlay, 1);
1116 if (ret != 0)
1117 goto out_unlock;
1118 }
1119
Daniel Vetter02e792f2009-09-15 22:57:34 +02001120 if (overlay->crtc != crtc) {
1121 struct drm_display_mode *mode = &crtc->base.mode;
1122 ret = intel_overlay_switch_off(overlay);
1123 if (ret != 0)
1124 goto out_unlock;
1125
1126 ret = check_overlay_possible_on_crtc(overlay, crtc);
1127 if (ret != 0)
1128 goto out_unlock;
1129
1130 overlay->crtc = crtc;
1131 crtc->overlay = overlay;
1132
1133 if (intel_panel_fitter_pipe(dev) == crtc->pipe
1134 /* and line to wide, i.e. one-line-mode */
1135 && mode->hdisplay > 1024) {
1136 overlay->pfit_active = 1;
1137 update_pfit_vscale_ratio(overlay);
1138 } else
1139 overlay->pfit_active = 0;
1140 }
1141
1142 ret = check_overlay_dst(overlay, put_image_rec);
1143 if (ret != 0)
1144 goto out_unlock;
1145
1146 if (overlay->pfit_active) {
1147 params->dst_y = ((((u32)put_image_rec->dst_y) << 12) /
Chris Wilson722506f2010-08-12 09:28:50 +01001148 overlay->pfit_vscale_ratio);
Daniel Vetter02e792f2009-09-15 22:57:34 +02001149 /* shifting right rounds downwards, so add 1 */
1150 params->dst_h = ((((u32)put_image_rec->dst_height) << 12) /
Chris Wilson722506f2010-08-12 09:28:50 +01001151 overlay->pfit_vscale_ratio) + 1;
Daniel Vetter02e792f2009-09-15 22:57:34 +02001152 } else {
1153 params->dst_y = put_image_rec->dst_y;
1154 params->dst_h = put_image_rec->dst_height;
1155 }
1156 params->dst_x = put_image_rec->dst_x;
1157 params->dst_w = put_image_rec->dst_width;
1158
1159 params->src_w = put_image_rec->src_width;
1160 params->src_h = put_image_rec->src_height;
1161 params->src_scan_w = put_image_rec->src_scan_width;
1162 params->src_scan_h = put_image_rec->src_scan_height;
Chris Wilson722506f2010-08-12 09:28:50 +01001163 if (params->src_scan_h > params->src_h ||
1164 params->src_scan_w > params->src_w) {
Daniel Vetter02e792f2009-09-15 22:57:34 +02001165 ret = -EINVAL;
1166 goto out_unlock;
1167 }
1168
1169 ret = check_overlay_src(dev, put_image_rec, new_bo);
1170 if (ret != 0)
1171 goto out_unlock;
1172 params->format = put_image_rec->flags & ~I915_OVERLAY_FLAGS_MASK;
1173 params->stride_Y = put_image_rec->stride_Y;
1174 params->stride_UV = put_image_rec->stride_UV;
1175 params->offset_Y = put_image_rec->offset_Y;
1176 params->offset_U = put_image_rec->offset_U;
1177 params->offset_V = put_image_rec->offset_V;
1178
1179 /* Check scaling after src size to prevent a divide-by-zero. */
1180 ret = check_overlay_scaling(params);
1181 if (ret != 0)
1182 goto out_unlock;
1183
1184 ret = intel_overlay_do_put_image(overlay, new_bo, params);
1185 if (ret != 0)
1186 goto out_unlock;
1187
1188 mutex_unlock(&dev->struct_mutex);
1189 mutex_unlock(&dev->mode_config.mutex);
1190
1191 kfree(params);
1192
1193 return 0;
1194
1195out_unlock:
1196 mutex_unlock(&dev->struct_mutex);
1197 mutex_unlock(&dev->mode_config.mutex);
Luca Barbieribc9025b2010-02-09 05:49:12 +00001198 drm_gem_object_unreference_unlocked(new_bo);
Dan Carpenter915a4282010-03-06 14:05:39 +03001199out_free:
Daniel Vetter02e792f2009-09-15 22:57:34 +02001200 kfree(params);
1201
1202 return ret;
1203}
1204
1205static void update_reg_attrs(struct intel_overlay *overlay,
1206 struct overlay_registers *regs)
1207{
1208 regs->OCLRC0 = (overlay->contrast << 18) | (overlay->brightness & 0xff);
1209 regs->OCLRC1 = overlay->saturation;
1210}
1211
1212static bool check_gamma_bounds(u32 gamma1, u32 gamma2)
1213{
1214 int i;
1215
1216 if (gamma1 & 0xff000000 || gamma2 & 0xff000000)
1217 return false;
1218
1219 for (i = 0; i < 3; i++) {
Chris Wilson722506f2010-08-12 09:28:50 +01001220 if (((gamma1 >> i*8) & 0xff) >= ((gamma2 >> i*8) & 0xff))
Daniel Vetter02e792f2009-09-15 22:57:34 +02001221 return false;
1222 }
1223
1224 return true;
1225}
1226
1227static bool check_gamma5_errata(u32 gamma5)
1228{
1229 int i;
1230
1231 for (i = 0; i < 3; i++) {
1232 if (((gamma5 >> i*8) & 0xff) == 0x80)
1233 return false;
1234 }
1235
1236 return true;
1237}
1238
1239static int check_gamma(struct drm_intel_overlay_attrs *attrs)
1240{
Chris Wilson722506f2010-08-12 09:28:50 +01001241 if (!check_gamma_bounds(0, attrs->gamma0) ||
1242 !check_gamma_bounds(attrs->gamma0, attrs->gamma1) ||
1243 !check_gamma_bounds(attrs->gamma1, attrs->gamma2) ||
1244 !check_gamma_bounds(attrs->gamma2, attrs->gamma3) ||
1245 !check_gamma_bounds(attrs->gamma3, attrs->gamma4) ||
1246 !check_gamma_bounds(attrs->gamma4, attrs->gamma5) ||
1247 !check_gamma_bounds(attrs->gamma5, 0x00ffffff))
Daniel Vetter02e792f2009-09-15 22:57:34 +02001248 return -EINVAL;
Chris Wilson722506f2010-08-12 09:28:50 +01001249
Daniel Vetter02e792f2009-09-15 22:57:34 +02001250 if (!check_gamma5_errata(attrs->gamma5))
1251 return -EINVAL;
Chris Wilson722506f2010-08-12 09:28:50 +01001252
Daniel Vetter02e792f2009-09-15 22:57:34 +02001253 return 0;
1254}
1255
1256int intel_overlay_attrs(struct drm_device *dev, void *data,
1257 struct drm_file *file_priv)
1258{
1259 struct drm_intel_overlay_attrs *attrs = data;
1260 drm_i915_private_t *dev_priv = dev->dev_private;
1261 struct intel_overlay *overlay;
1262 struct overlay_registers *regs;
1263 int ret;
1264
1265 if (!dev_priv) {
1266 DRM_ERROR("called with no initialization\n");
1267 return -EINVAL;
1268 }
1269
1270 overlay = dev_priv->overlay;
1271 if (!overlay) {
1272 DRM_DEBUG("userspace bug: no overlay\n");
1273 return -ENODEV;
1274 }
1275
1276 mutex_lock(&dev->mode_config.mutex);
1277 mutex_lock(&dev->struct_mutex);
1278
1279 if (!(attrs->flags & I915_OVERLAY_UPDATE_ATTRS)) {
1280 attrs->color_key = overlay->color_key;
1281 attrs->brightness = overlay->brightness;
1282 attrs->contrast = overlay->contrast;
1283 attrs->saturation = overlay->saturation;
1284
1285 if (IS_I9XX(dev)) {
1286 attrs->gamma0 = I915_READ(OGAMC0);
1287 attrs->gamma1 = I915_READ(OGAMC1);
1288 attrs->gamma2 = I915_READ(OGAMC2);
1289 attrs->gamma3 = I915_READ(OGAMC3);
1290 attrs->gamma4 = I915_READ(OGAMC4);
1291 attrs->gamma5 = I915_READ(OGAMC5);
1292 }
1293 ret = 0;
1294 } else {
1295 overlay->color_key = attrs->color_key;
1296 if (attrs->brightness >= -128 && attrs->brightness <= 127) {
1297 overlay->brightness = attrs->brightness;
1298 } else {
1299 ret = -EINVAL;
1300 goto out_unlock;
1301 }
Chris Wilson722506f2010-08-12 09:28:50 +01001302
Daniel Vetter02e792f2009-09-15 22:57:34 +02001303 if (attrs->contrast <= 255) {
1304 overlay->contrast = attrs->contrast;
1305 } else {
1306 ret = -EINVAL;
1307 goto out_unlock;
1308 }
Chris Wilson722506f2010-08-12 09:28:50 +01001309
Daniel Vetter02e792f2009-09-15 22:57:34 +02001310 if (attrs->saturation <= 1023) {
1311 overlay->saturation = attrs->saturation;
1312 } else {
1313 ret = -EINVAL;
1314 goto out_unlock;
1315 }
1316
1317 regs = intel_overlay_map_regs_atomic(overlay);
1318 if (!regs) {
1319 ret = -ENOMEM;
1320 goto out_unlock;
1321 }
1322
1323 update_reg_attrs(overlay, regs);
1324
1325 intel_overlay_unmap_regs_atomic(overlay);
1326
1327 if (attrs->flags & I915_OVERLAY_UPDATE_GAMMA) {
1328 if (!IS_I9XX(dev)) {
1329 ret = -EINVAL;
1330 goto out_unlock;
1331 }
1332
1333 if (overlay->active) {
1334 ret = -EBUSY;
1335 goto out_unlock;
1336 }
1337
1338 ret = check_gamma(attrs);
1339 if (ret != 0)
1340 goto out_unlock;
1341
1342 I915_WRITE(OGAMC0, attrs->gamma0);
1343 I915_WRITE(OGAMC1, attrs->gamma1);
1344 I915_WRITE(OGAMC2, attrs->gamma2);
1345 I915_WRITE(OGAMC3, attrs->gamma3);
1346 I915_WRITE(OGAMC4, attrs->gamma4);
1347 I915_WRITE(OGAMC5, attrs->gamma5);
1348 }
1349 ret = 0;
1350 }
1351
1352out_unlock:
1353 mutex_unlock(&dev->struct_mutex);
1354 mutex_unlock(&dev->mode_config.mutex);
1355
1356 return ret;
1357}
1358
1359void intel_setup_overlay(struct drm_device *dev)
1360{
1361 drm_i915_private_t *dev_priv = dev->dev_private;
1362 struct intel_overlay *overlay;
1363 struct drm_gem_object *reg_bo;
1364 struct overlay_registers *regs;
1365 int ret;
1366
Chris Wilson315781482010-08-12 09:42:51 +01001367 if (!HAS_OVERLAY(dev))
Daniel Vetter02e792f2009-09-15 22:57:34 +02001368 return;
1369
1370 overlay = kzalloc(sizeof(struct intel_overlay), GFP_KERNEL);
1371 if (!overlay)
1372 return;
1373 overlay->dev = dev;
1374
Daniel Vetterac52bc52010-04-09 19:05:06 +00001375 reg_bo = i915_gem_alloc_object(dev, PAGE_SIZE);
Daniel Vetter02e792f2009-09-15 22:57:34 +02001376 if (!reg_bo)
1377 goto out_free;
Daniel Vetter23010e42010-03-08 13:35:02 +01001378 overlay->reg_bo = to_intel_bo(reg_bo);
Daniel Vetter02e792f2009-09-15 22:57:34 +02001379
Chris Wilson315781482010-08-12 09:42:51 +01001380 if (OVERLAY_NEEDS_PHYSICAL(dev)) {
1381 ret = i915_gem_attach_phys_object(dev, reg_bo,
1382 I915_GEM_PHYS_OVERLAY_REGS,
1383 0);
1384 if (ret) {
1385 DRM_ERROR("failed to attach phys overlay regs\n");
1386 goto out_free_bo;
1387 }
1388 overlay->flip_addr = overlay->reg_bo->phys_obj->handle->busaddr;
1389 } else {
Daniel Vetter02e792f2009-09-15 22:57:34 +02001390 ret = i915_gem_object_pin(reg_bo, PAGE_SIZE);
1391 if (ret) {
1392 DRM_ERROR("failed to pin overlay register bo\n");
1393 goto out_free_bo;
1394 }
1395 overlay->flip_addr = overlay->reg_bo->gtt_offset;
Chris Wilson0ddc1282010-08-12 09:35:00 +01001396
1397 ret = i915_gem_object_set_to_gtt_domain(reg_bo, true);
1398 if (ret) {
1399 DRM_ERROR("failed to move overlay register bo into the GTT\n");
1400 goto out_unpin_bo;
1401 }
Daniel Vetter02e792f2009-09-15 22:57:34 +02001402 }
1403
1404 /* init all values */
1405 overlay->color_key = 0x0101fe;
1406 overlay->brightness = -19;
1407 overlay->contrast = 75;
1408 overlay->saturation = 146;
1409
1410 regs = intel_overlay_map_regs_atomic(overlay);
1411 if (!regs)
1412 goto out_free_bo;
1413
1414 memset(regs, 0, sizeof(struct overlay_registers));
1415 update_polyphase_filter(regs);
1416
1417 update_reg_attrs(overlay, regs);
1418
1419 intel_overlay_unmap_regs_atomic(overlay);
1420
1421 dev_priv->overlay = overlay;
1422 DRM_INFO("initialized overlay support\n");
1423 return;
1424
Chris Wilson0ddc1282010-08-12 09:35:00 +01001425out_unpin_bo:
1426 i915_gem_object_unpin(reg_bo);
Daniel Vetter02e792f2009-09-15 22:57:34 +02001427out_free_bo:
1428 drm_gem_object_unreference(reg_bo);
1429out_free:
1430 kfree(overlay);
1431 return;
1432}
1433
1434void intel_cleanup_overlay(struct drm_device *dev)
1435{
Chris Wilson722506f2010-08-12 09:28:50 +01001436 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetter02e792f2009-09-15 22:57:34 +02001437
1438 if (dev_priv->overlay) {
1439 /* The bo's should be free'd by the generic code already.
1440 * Furthermore modesetting teardown happens beforehand so the
1441 * hardware should be off already */
1442 BUG_ON(dev_priv->overlay->active);
1443
1444 kfree(dev_priv->overlay);
1445 }
1446}
Chris Wilson6ef3d422010-08-04 20:26:07 +01001447
1448struct intel_overlay_error_state {
1449 struct overlay_registers regs;
1450 unsigned long base;
1451 u32 dovsta;
1452 u32 isr;
1453};
1454
1455struct intel_overlay_error_state *
1456intel_overlay_capture_error_state(struct drm_device *dev)
1457{
1458 drm_i915_private_t *dev_priv = dev->dev_private;
1459 struct intel_overlay *overlay = dev_priv->overlay;
1460 struct intel_overlay_error_state *error;
1461 struct overlay_registers __iomem *regs;
1462
1463 if (!overlay || !overlay->active)
1464 return NULL;
1465
1466 error = kmalloc(sizeof(*error), GFP_ATOMIC);
1467 if (error == NULL)
1468 return NULL;
1469
1470 error->dovsta = I915_READ(DOVSTA);
1471 error->isr = I915_READ(ISR);
Chris Wilson315781482010-08-12 09:42:51 +01001472 if (OVERLAY_NEEDS_PHYSICAL(overlay->dev))
Chris Wilson6ef3d422010-08-04 20:26:07 +01001473 error->base = (long) overlay->reg_bo->phys_obj->handle->vaddr;
Chris Wilson315781482010-08-12 09:42:51 +01001474 else
1475 error->base = (long) overlay->reg_bo->gtt_offset;
Chris Wilson6ef3d422010-08-04 20:26:07 +01001476
1477 regs = intel_overlay_map_regs_atomic(overlay);
1478 if (!regs)
1479 goto err;
1480
1481 memcpy_fromio(&error->regs, regs, sizeof(struct overlay_registers));
1482 intel_overlay_unmap_regs_atomic(overlay);
1483
1484 return error;
1485
1486err:
1487 kfree(error);
1488 return NULL;
1489}
1490
1491void
1492intel_overlay_print_error_state(struct seq_file *m, struct intel_overlay_error_state *error)
1493{
1494 seq_printf(m, "Overlay, status: 0x%08x, interrupt: 0x%08x\n",
1495 error->dovsta, error->isr);
1496 seq_printf(m, " Register file at 0x%08lx:\n",
1497 error->base);
1498
1499#define P(x) seq_printf(m, " " #x ": 0x%08x\n", error->regs.x)
1500 P(OBUF_0Y);
1501 P(OBUF_1Y);
1502 P(OBUF_0U);
1503 P(OBUF_0V);
1504 P(OBUF_1U);
1505 P(OBUF_1V);
1506 P(OSTRIDE);
1507 P(YRGB_VPH);
1508 P(UV_VPH);
1509 P(HORZ_PH);
1510 P(INIT_PHS);
1511 P(DWINPOS);
1512 P(DWINSZ);
1513 P(SWIDTH);
1514 P(SWIDTHSW);
1515 P(SHEIGHT);
1516 P(YRGBSCALE);
1517 P(UVSCALE);
1518 P(OCLRC0);
1519 P(OCLRC1);
1520 P(DCLRKV);
1521 P(DCLRKM);
1522 P(SCLRKVH);
1523 P(SCLRKVL);
1524 P(SCLRKEN);
1525 P(OCONFIG);
1526 P(OCMD);
1527 P(OSTART_0Y);
1528 P(OSTART_1Y);
1529 P(OSTART_0U);
1530 P(OSTART_0V);
1531 P(OSTART_1U);
1532 P(OSTART_1V);
1533 P(OTILEOFF_0Y);
1534 P(OTILEOFF_1Y);
1535 P(OTILEOFF_0U);
1536 P(OTILEOFF_0V);
1537 P(OTILEOFF_1U);
1538 P(OTILEOFF_1V);
1539 P(FASTHSCALE);
1540 P(UVSCALEV);
1541#undef P
1542}