blob: 8c660abb0e6624f0a441c0014d2f51c7ba10df3c [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
Chris Wilson8d74f652010-08-12 10:35:26 +0100173static struct overlay_registers *
174intel_overlay_map_regs_atomic(struct intel_overlay *overlay,
175 int slot)
Daniel Vetter02e792f2009-09-15 22:57:34 +0200176{
177 drm_i915_private_t *dev_priv = overlay->dev->dev_private;
178 struct overlay_registers *regs;
179
Chris Wilson9bb2ff72010-08-12 12:02:11 +0100180 if (OVERLAY_NEEDS_PHYSICAL(overlay->dev))
Chris Wilson315781482010-08-12 09:42:51 +0100181 regs = overlay->reg_bo->phys_obj->handle->vaddr;
Chris Wilson9bb2ff72010-08-12 12:02:11 +0100182 else
Daniel Vetter02e792f2009-09-15 22:57:34 +0200183 regs = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping,
Chris Wilsonfca3ec02010-08-04 14:34:24 +0100184 overlay->reg_bo->gtt_offset,
Chris Wilson8d74f652010-08-12 10:35:26 +0100185 slot);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200186
Chris Wilson9bb2ff72010-08-12 12:02:11 +0100187 return regs;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200188}
189
Chris Wilson8d74f652010-08-12 10:35:26 +0100190static void intel_overlay_unmap_regs_atomic(struct intel_overlay *overlay,
Chris Wilson9bb2ff72010-08-12 12:02:11 +0100191 int slot,
192 struct overlay_registers *regs)
Daniel Vetter02e792f2009-09-15 22:57:34 +0200193{
Chris Wilson315781482010-08-12 09:42:51 +0100194 if (!OVERLAY_NEEDS_PHYSICAL(overlay->dev))
Chris Wilson9bb2ff72010-08-12 12:02:11 +0100195 io_mapping_unmap_atomic(regs, slot);
Chris Wilson8d74f652010-08-12 10:35:26 +0100196}
197
198static struct overlay_registers *
199intel_overlay_map_regs(struct intel_overlay *overlay)
200{
201 drm_i915_private_t *dev_priv = overlay->dev->dev_private;
202 struct overlay_registers *regs;
203
Chris Wilson9bb2ff72010-08-12 12:02:11 +0100204 if (OVERLAY_NEEDS_PHYSICAL(overlay->dev))
Chris Wilson8d74f652010-08-12 10:35:26 +0100205 regs = overlay->reg_bo->phys_obj->handle->vaddr;
Chris Wilson9bb2ff72010-08-12 12:02:11 +0100206 else
Chris Wilson8d74f652010-08-12 10:35:26 +0100207 regs = io_mapping_map_wc(dev_priv->mm.gtt_mapping,
208 overlay->reg_bo->gtt_offset);
209
Chris Wilson9bb2ff72010-08-12 12:02:11 +0100210 return regs;
Chris Wilson8d74f652010-08-12 10:35:26 +0100211}
212
Chris Wilson9bb2ff72010-08-12 12:02:11 +0100213static void intel_overlay_unmap_regs(struct intel_overlay *overlay,
214 struct overlay_registers *regs)
Chris Wilson8d74f652010-08-12 10:35:26 +0100215{
216 if (!OVERLAY_NEEDS_PHYSICAL(overlay->dev))
Chris Wilson9bb2ff72010-08-12 12:02:11 +0100217 io_mapping_unmap(regs);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200218}
219
Chris Wilsonb6c028e2010-08-12 11:55:08 +0100220static int intel_overlay_do_wait_request(struct intel_overlay *overlay,
221 bool interruptible,
222 int stage)
223{
224 struct drm_device *dev = overlay->dev;
225 drm_i915_private_t *dev_priv = dev->dev_private;
226 int ret;
227
228 overlay->last_flip_req =
229 i915_add_request(dev, NULL, &dev_priv->render_ring);
230 if (overlay->last_flip_req == 0)
231 return -ENOMEM;
232
233 overlay->hw_wedged = stage;
234 ret = i915_do_wait_request(dev,
235 overlay->last_flip_req, true,
236 &dev_priv->render_ring);
237 if (ret)
238 return ret;
239
240 overlay->hw_wedged = 0;
241 overlay->last_flip_req = 0;
242 return 0;
243}
244
Daniel Vetter02e792f2009-09-15 22:57:34 +0200245/* overlay needs to be disable in OCMD reg */
246static int intel_overlay_on(struct intel_overlay *overlay)
247{
248 struct drm_device *dev = overlay->dev;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200249
250 BUG_ON(overlay->active);
251
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200252 overlay->active = 1;
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200253
Daniel Vetter4f8a5672010-02-11 14:14:43 +0100254 BEGIN_LP_RING(4);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200255 OUT_RING(MI_OVERLAY_FLIP | MI_OVERLAY_ON);
256 OUT_RING(overlay->flip_addr | OFC_UPDATE);
257 OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP);
258 OUT_RING(MI_NOOP);
259 ADVANCE_LP_RING();
260
Chris Wilsonb6c028e2010-08-12 11:55:08 +0100261 return intel_overlay_do_wait_request(overlay, true,
262 NEEDS_WAIT_FOR_FLIP);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200263}
264
265/* overlay needs to be enabled in OCMD reg */
266static void intel_overlay_continue(struct intel_overlay *overlay,
Chris Wilson722506f2010-08-12 09:28:50 +0100267 bool load_polyphase_filter)
Daniel Vetter02e792f2009-09-15 22:57:34 +0200268{
269 struct drm_device *dev = overlay->dev;
270 drm_i915_private_t *dev_priv = dev->dev_private;
271 u32 flip_addr = overlay->flip_addr;
272 u32 tmp;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200273
274 BUG_ON(!overlay->active);
275
276 if (load_polyphase_filter)
277 flip_addr |= OFC_UPDATE;
278
279 /* check for underruns */
280 tmp = I915_READ(DOVSTA);
281 if (tmp & (1 << 17))
282 DRM_DEBUG("overlay underrun, DOVSTA: %x\n", tmp);
283
Daniel Vetter4f8a5672010-02-11 14:14:43 +0100284 BEGIN_LP_RING(2);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200285 OUT_RING(MI_OVERLAY_FLIP | MI_OVERLAY_CONTINUE);
286 OUT_RING(flip_addr);
Daniel Vetter5a5a0c62009-09-15 22:57:36 +0200287 ADVANCE_LP_RING();
288
Zou Nan hai852835f2010-05-21 09:08:56 +0800289 overlay->last_flip_req =
Daniel Vetter8a1a49f2010-02-11 22:29:04 +0100290 i915_add_request(dev, NULL, &dev_priv->render_ring);
Daniel Vetter5a5a0c62009-09-15 22:57:36 +0200291}
292
Daniel Vetter02e792f2009-09-15 22:57:34 +0200293/* overlay needs to be disabled in OCMD reg */
294static int intel_overlay_off(struct intel_overlay *overlay)
295{
296 u32 flip_addr = overlay->flip_addr;
297 struct drm_device *dev = overlay->dev;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200298
299 BUG_ON(!overlay->active);
300
301 /* According to intel docs the overlay hw may hang (when switching
302 * off) without loading the filter coeffs. It is however unclear whether
303 * this applies to the disabling of the overlay or to the switching off
304 * of the hw. Do it in both cases */
305 flip_addr |= OFC_UPDATE;
306
Chris Wilson8dfbc342010-08-12 12:07:32 +0100307 BEGIN_LP_RING(6);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200308 /* wait for overlay to go idle */
Daniel Vetter02e792f2009-09-15 22:57:34 +0200309 OUT_RING(MI_OVERLAY_FLIP | MI_OVERLAY_CONTINUE);
310 OUT_RING(flip_addr);
Chris Wilson722506f2010-08-12 09:28:50 +0100311 OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP);
Chris Wilson722506f2010-08-12 09:28:50 +0100312 /* turn overlay off */
Chris Wilson722506f2010-08-12 09:28:50 +0100313 OUT_RING(MI_OVERLAY_FLIP | MI_OVERLAY_OFF);
314 OUT_RING(flip_addr);
315 OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP);
Chris Wilson722506f2010-08-12 09:28:50 +0100316 ADVANCE_LP_RING();
317
Chris Wilson8dfbc342010-08-12 12:07:32 +0100318 return intel_overlay_do_wait_request(overlay, true, SWITCH_OFF);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200319}
320
Chris Wilson5cd68c92010-08-12 12:21:54 +0100321static void intel_overlay_release_old_vid_tail(struct intel_overlay *overlay)
322{
323 struct drm_gem_object *obj = &overlay->old_vid_bo->base;
324
325 i915_gem_object_unpin(obj);
326 drm_gem_object_unreference(obj);
327
328 overlay->old_vid_bo = NULL;
329}
330
Daniel Vetter12ca45f2037-04-25 10:08:26 +0200331static void intel_overlay_off_tail(struct intel_overlay *overlay)
332{
333 struct drm_gem_object *obj;
334
335 /* never have the overlay hw on without showing a frame */
336 BUG_ON(!overlay->vid_bo);
Daniel Vettera8089e82010-04-09 19:05:09 +0000337 obj = &overlay->vid_bo->base;
Daniel Vetter12ca45f2037-04-25 10:08:26 +0200338
339 i915_gem_object_unpin(obj);
340 drm_gem_object_unreference(obj);
341 overlay->vid_bo = NULL;
342
343 overlay->crtc->overlay = NULL;
344 overlay->crtc = NULL;
345 overlay->active = 0;
346}
347
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200348/* recover from an interruption due to a signal
349 * We have to be careful not to repeat work forever an make forward progess. */
350int intel_overlay_recover_from_interrupt(struct intel_overlay *overlay,
Chris Wilson722506f2010-08-12 09:28:50 +0100351 bool interruptible)
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200352{
353 struct drm_device *dev = overlay->dev;
Zou Nan hai852835f2010-05-21 09:08:56 +0800354 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200355 int ret;
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200356
357 if (overlay->hw_wedged == HW_WEDGED)
358 return -EIO;
359
Zou Nan hai852835f2010-05-21 09:08:56 +0800360 ret = i915_do_wait_request(dev, overlay->last_flip_req,
Chris Wilson722506f2010-08-12 09:28:50 +0100361 interruptible, &dev_priv->render_ring);
Chris Wilsonb6c028e2010-08-12 11:55:08 +0100362 if (ret)
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200363 return ret;
364
365 switch (overlay->hw_wedged) {
Chris Wilson722506f2010-08-12 09:28:50 +0100366 case RELEASE_OLD_VID:
Chris Wilson5cd68c92010-08-12 12:21:54 +0100367 intel_overlay_release_old_vid_tail(overlay);
Chris Wilson722506f2010-08-12 09:28:50 +0100368 break;
Chris Wilsonb6c028e2010-08-12 11:55:08 +0100369
Chris Wilson8dfbc342010-08-12 12:07:32 +0100370 case SWITCH_OFF:
Chris Wilson722506f2010-08-12 09:28:50 +0100371 intel_overlay_off_tail(overlay);
372 break;
Chris Wilson8dfbc342010-08-12 12:07:32 +0100373
Chris Wilson722506f2010-08-12 09:28:50 +0100374 default:
375 BUG_ON(overlay->hw_wedged != NEEDS_WAIT_FOR_FLIP);
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200376 }
377
378 overlay->hw_wedged = 0;
379 overlay->last_flip_req = 0;
380 return 0;
381}
382
Daniel Vetter5a5a0c62009-09-15 22:57:36 +0200383/* Wait for pending overlay flip and release old frame.
384 * Needs to be called before the overlay register are changed
Chris Wilson8d74f652010-08-12 10:35:26 +0100385 * via intel_overlay_(un)map_regs
386 */
Daniel Vetter02e792f2009-09-15 22:57:34 +0200387static int intel_overlay_release_old_vid(struct intel_overlay *overlay)
388{
Chris Wilson5cd68c92010-08-12 12:21:54 +0100389 struct drm_device *dev = overlay->dev;
390 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200391 int ret;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200392
Chris Wilson5cd68c92010-08-12 12:21:54 +0100393 /* Only wait if there is actually an old frame to release to
394 * guarantee forward progress.
395 */
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200396 if (!overlay->old_vid_bo)
397 return 0;
398
Chris Wilson5cd68c92010-08-12 12:21:54 +0100399 if (I915_READ(ISR) & I915_OVERLAY_PLANE_FLIP_PENDING_INTERRUPT) {
400 /* synchronous slowpath */
401 BEGIN_LP_RING(2);
402 OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP);
403 OUT_RING(MI_NOOP);
404 ADVANCE_LP_RING();
Daniel Vetter02e792f2009-09-15 22:57:34 +0200405
Chris Wilson5cd68c92010-08-12 12:21:54 +0100406 ret = intel_overlay_do_wait_request(overlay, true,
407 RELEASE_OLD_VID);
408 if (ret)
409 return ret;
410 }
Daniel Vetter02e792f2009-09-15 22:57:34 +0200411
Chris Wilson5cd68c92010-08-12 12:21:54 +0100412 intel_overlay_release_old_vid_tail(overlay);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200413 return 0;
414}
415
416struct put_image_params {
417 int format;
418 short dst_x;
419 short dst_y;
420 short dst_w;
421 short dst_h;
422 short src_w;
423 short src_scan_h;
424 short src_scan_w;
425 short src_h;
426 short stride_Y;
427 short stride_UV;
428 int offset_Y;
429 int offset_U;
430 int offset_V;
431};
432
433static int packed_depth_bytes(u32 format)
434{
435 switch (format & I915_OVERLAY_DEPTH_MASK) {
Chris Wilson722506f2010-08-12 09:28:50 +0100436 case I915_OVERLAY_YUV422:
437 return 4;
438 case I915_OVERLAY_YUV411:
439 /* return 6; not implemented */
440 default:
441 return -EINVAL;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200442 }
443}
444
445static int packed_width_bytes(u32 format, short width)
446{
447 switch (format & I915_OVERLAY_DEPTH_MASK) {
Chris Wilson722506f2010-08-12 09:28:50 +0100448 case I915_OVERLAY_YUV422:
449 return width << 1;
450 default:
451 return -EINVAL;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200452 }
453}
454
455static int uv_hsubsampling(u32 format)
456{
457 switch (format & I915_OVERLAY_DEPTH_MASK) {
Chris Wilson722506f2010-08-12 09:28:50 +0100458 case I915_OVERLAY_YUV422:
459 case I915_OVERLAY_YUV420:
460 return 2;
461 case I915_OVERLAY_YUV411:
462 case I915_OVERLAY_YUV410:
463 return 4;
464 default:
465 return -EINVAL;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200466 }
467}
468
469static int uv_vsubsampling(u32 format)
470{
471 switch (format & I915_OVERLAY_DEPTH_MASK) {
Chris Wilson722506f2010-08-12 09:28:50 +0100472 case I915_OVERLAY_YUV420:
473 case I915_OVERLAY_YUV410:
474 return 2;
475 case I915_OVERLAY_YUV422:
476 case I915_OVERLAY_YUV411:
477 return 1;
478 default:
479 return -EINVAL;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200480 }
481}
482
483static u32 calc_swidthsw(struct drm_device *dev, u32 offset, u32 width)
484{
485 u32 mask, shift, ret;
486 if (IS_I9XX(dev)) {
487 mask = 0x3f;
488 shift = 6;
489 } else {
490 mask = 0x1f;
491 shift = 5;
492 }
493 ret = ((offset + width + mask) >> shift) - (offset >> shift);
494 if (IS_I9XX(dev))
495 ret <<= 1;
496 ret -=1;
497 return ret << 2;
498}
499
500static const u16 y_static_hcoeffs[N_HORIZ_Y_TAPS * N_PHASES] = {
501 0x3000, 0xb4a0, 0x1930, 0x1920, 0xb4a0,
502 0x3000, 0xb500, 0x19d0, 0x1880, 0xb440,
503 0x3000, 0xb540, 0x1a88, 0x2f80, 0xb3e0,
504 0x3000, 0xb580, 0x1b30, 0x2e20, 0xb380,
505 0x3000, 0xb5c0, 0x1bd8, 0x2cc0, 0xb320,
506 0x3020, 0xb5e0, 0x1c60, 0x2b80, 0xb2c0,
507 0x3020, 0xb5e0, 0x1cf8, 0x2a20, 0xb260,
508 0x3020, 0xb5e0, 0x1d80, 0x28e0, 0xb200,
509 0x3020, 0xb5c0, 0x1e08, 0x3f40, 0xb1c0,
510 0x3020, 0xb580, 0x1e78, 0x3ce0, 0xb160,
511 0x3040, 0xb520, 0x1ed8, 0x3aa0, 0xb120,
512 0x3040, 0xb4a0, 0x1f30, 0x3880, 0xb0e0,
513 0x3040, 0xb400, 0x1f78, 0x3680, 0xb0a0,
514 0x3020, 0xb340, 0x1fb8, 0x34a0, 0xb060,
515 0x3020, 0xb240, 0x1fe0, 0x32e0, 0xb040,
516 0x3020, 0xb140, 0x1ff8, 0x3160, 0xb020,
Chris Wilson722506f2010-08-12 09:28:50 +0100517 0xb000, 0x3000, 0x0800, 0x3000, 0xb000
518};
519
Daniel Vetter02e792f2009-09-15 22:57:34 +0200520static const u16 uv_static_hcoeffs[N_HORIZ_UV_TAPS * N_PHASES] = {
521 0x3000, 0x1800, 0x1800, 0xb000, 0x18d0, 0x2e60,
522 0xb000, 0x1990, 0x2ce0, 0xb020, 0x1a68, 0x2b40,
523 0xb040, 0x1b20, 0x29e0, 0xb060, 0x1bd8, 0x2880,
524 0xb080, 0x1c88, 0x3e60, 0xb0a0, 0x1d28, 0x3c00,
525 0xb0c0, 0x1db8, 0x39e0, 0xb0e0, 0x1e40, 0x37e0,
526 0xb100, 0x1eb8, 0x3620, 0xb100, 0x1f18, 0x34a0,
527 0xb100, 0x1f68, 0x3360, 0xb0e0, 0x1fa8, 0x3240,
528 0xb0c0, 0x1fe0, 0x3140, 0xb060, 0x1ff0, 0x30a0,
Chris Wilson722506f2010-08-12 09:28:50 +0100529 0x3000, 0x0800, 0x3000
530};
Daniel Vetter02e792f2009-09-15 22:57:34 +0200531
532static void update_polyphase_filter(struct overlay_registers *regs)
533{
534 memcpy(regs->Y_HCOEFS, y_static_hcoeffs, sizeof(y_static_hcoeffs));
535 memcpy(regs->UV_HCOEFS, uv_static_hcoeffs, sizeof(uv_static_hcoeffs));
536}
537
538static bool update_scaling_factors(struct intel_overlay *overlay,
539 struct overlay_registers *regs,
540 struct put_image_params *params)
541{
542 /* fixed point with a 12 bit shift */
543 u32 xscale, yscale, xscale_UV, yscale_UV;
544#define FP_SHIFT 12
545#define FRACT_MASK 0xfff
546 bool scale_changed = false;
547 int uv_hscale = uv_hsubsampling(params->format);
548 int uv_vscale = uv_vsubsampling(params->format);
549
550 if (params->dst_w > 1)
551 xscale = ((params->src_scan_w - 1) << FP_SHIFT)
552 /(params->dst_w);
553 else
554 xscale = 1 << FP_SHIFT;
555
556 if (params->dst_h > 1)
557 yscale = ((params->src_scan_h - 1) << FP_SHIFT)
558 /(params->dst_h);
559 else
560 yscale = 1 << FP_SHIFT;
561
562 /*if (params->format & I915_OVERLAY_YUV_PLANAR) {*/
Chris Wilson722506f2010-08-12 09:28:50 +0100563 xscale_UV = xscale/uv_hscale;
564 yscale_UV = yscale/uv_vscale;
565 /* make the Y scale to UV scale ratio an exact multiply */
566 xscale = xscale_UV * uv_hscale;
567 yscale = yscale_UV * uv_vscale;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200568 /*} else {
Chris Wilson722506f2010-08-12 09:28:50 +0100569 xscale_UV = 0;
570 yscale_UV = 0;
571 }*/
Daniel Vetter02e792f2009-09-15 22:57:34 +0200572
573 if (xscale != overlay->old_xscale || yscale != overlay->old_yscale)
574 scale_changed = true;
575 overlay->old_xscale = xscale;
576 overlay->old_yscale = yscale;
577
Chris Wilson722506f2010-08-12 09:28:50 +0100578 regs->YRGBSCALE = (((yscale & FRACT_MASK) << 20) |
579 ((xscale >> FP_SHIFT) << 16) |
580 ((xscale & FRACT_MASK) << 3));
581
582 regs->UVSCALE = (((yscale_UV & FRACT_MASK) << 20) |
583 ((xscale_UV >> FP_SHIFT) << 16) |
584 ((xscale_UV & FRACT_MASK) << 3));
585
586 regs->UVSCALEV = ((((yscale >> FP_SHIFT) << 16) |
587 ((yscale_UV >> FP_SHIFT) << 0)));
Daniel Vetter02e792f2009-09-15 22:57:34 +0200588
589 if (scale_changed)
590 update_polyphase_filter(regs);
591
592 return scale_changed;
593}
594
595static void update_colorkey(struct intel_overlay *overlay,
596 struct overlay_registers *regs)
597{
598 u32 key = overlay->color_key;
Chris Wilson6ba3ddd2010-08-12 09:30:58 +0100599
Daniel Vetter02e792f2009-09-15 22:57:34 +0200600 switch (overlay->crtc->base.fb->bits_per_pixel) {
Chris Wilson722506f2010-08-12 09:28:50 +0100601 case 8:
602 regs->DCLRKV = 0;
603 regs->DCLRKM = CLK_RGB8I_MASK | DST_KEY_ENABLE;
Chris Wilson6ba3ddd2010-08-12 09:30:58 +0100604 break;
605
Chris Wilson722506f2010-08-12 09:28:50 +0100606 case 16:
607 if (overlay->crtc->base.fb->depth == 15) {
608 regs->DCLRKV = RGB15_TO_COLORKEY(key);
609 regs->DCLRKM = CLK_RGB15_MASK | DST_KEY_ENABLE;
610 } else {
611 regs->DCLRKV = RGB16_TO_COLORKEY(key);
612 regs->DCLRKM = CLK_RGB16_MASK | DST_KEY_ENABLE;
613 }
Chris Wilson6ba3ddd2010-08-12 09:30:58 +0100614 break;
615
Chris Wilson722506f2010-08-12 09:28:50 +0100616 case 24:
617 case 32:
618 regs->DCLRKV = key;
619 regs->DCLRKM = CLK_RGB24_MASK | DST_KEY_ENABLE;
Chris Wilson6ba3ddd2010-08-12 09:30:58 +0100620 break;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200621 }
622}
623
624static u32 overlay_cmd_reg(struct put_image_params *params)
625{
626 u32 cmd = OCMD_ENABLE | OCMD_BUF_TYPE_FRAME | OCMD_BUFFER0;
627
628 if (params->format & I915_OVERLAY_YUV_PLANAR) {
629 switch (params->format & I915_OVERLAY_DEPTH_MASK) {
Chris Wilson722506f2010-08-12 09:28:50 +0100630 case I915_OVERLAY_YUV422:
631 cmd |= OCMD_YUV_422_PLANAR;
632 break;
633 case I915_OVERLAY_YUV420:
634 cmd |= OCMD_YUV_420_PLANAR;
635 break;
636 case I915_OVERLAY_YUV411:
637 case I915_OVERLAY_YUV410:
638 cmd |= OCMD_YUV_410_PLANAR;
639 break;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200640 }
641 } else { /* YUV packed */
642 switch (params->format & I915_OVERLAY_DEPTH_MASK) {
Chris Wilson722506f2010-08-12 09:28:50 +0100643 case I915_OVERLAY_YUV422:
644 cmd |= OCMD_YUV_422_PACKED;
645 break;
646 case I915_OVERLAY_YUV411:
647 cmd |= OCMD_YUV_411_PACKED;
648 break;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200649 }
650
651 switch (params->format & I915_OVERLAY_SWAP_MASK) {
Chris Wilson722506f2010-08-12 09:28:50 +0100652 case I915_OVERLAY_NO_SWAP:
653 break;
654 case I915_OVERLAY_UV_SWAP:
655 cmd |= OCMD_UV_SWAP;
656 break;
657 case I915_OVERLAY_Y_SWAP:
658 cmd |= OCMD_Y_SWAP;
659 break;
660 case I915_OVERLAY_Y_AND_UV_SWAP:
661 cmd |= OCMD_Y_AND_UV_SWAP;
662 break;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200663 }
664 }
665
666 return cmd;
667}
668
669int intel_overlay_do_put_image(struct intel_overlay *overlay,
670 struct drm_gem_object *new_bo,
671 struct put_image_params *params)
672{
673 int ret, tmp_width;
674 struct overlay_registers *regs;
675 bool scale_changed = false;
Daniel Vetter23010e42010-03-08 13:35:02 +0100676 struct drm_i915_gem_object *bo_priv = to_intel_bo(new_bo);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200677 struct drm_device *dev = overlay->dev;
678
679 BUG_ON(!mutex_is_locked(&dev->struct_mutex));
680 BUG_ON(!mutex_is_locked(&dev->mode_config.mutex));
681 BUG_ON(!overlay);
682
Daniel Vetter02e792f2009-09-15 22:57:34 +0200683 ret = intel_overlay_release_old_vid(overlay);
684 if (ret != 0)
685 return ret;
686
687 ret = i915_gem_object_pin(new_bo, PAGE_SIZE);
688 if (ret != 0)
689 return ret;
690
691 ret = i915_gem_object_set_to_gtt_domain(new_bo, 0);
692 if (ret != 0)
693 goto out_unpin;
694
695 if (!overlay->active) {
Chris Wilson8d74f652010-08-12 10:35:26 +0100696 regs = intel_overlay_map_regs(overlay);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200697 if (!regs) {
698 ret = -ENOMEM;
699 goto out_unpin;
700 }
701 regs->OCONFIG = OCONF_CC_OUT_8BIT;
702 if (IS_I965GM(overlay->dev))
703 regs->OCONFIG |= OCONF_CSC_MODE_BT709;
704 regs->OCONFIG |= overlay->crtc->pipe == 0 ?
705 OCONF_PIPE_A : OCONF_PIPE_B;
Chris Wilson9bb2ff72010-08-12 12:02:11 +0100706 intel_overlay_unmap_regs(overlay, regs);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200707
708 ret = intel_overlay_on(overlay);
709 if (ret != 0)
710 goto out_unpin;
711 }
712
Chris Wilson8d74f652010-08-12 10:35:26 +0100713 regs = intel_overlay_map_regs(overlay);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200714 if (!regs) {
715 ret = -ENOMEM;
716 goto out_unpin;
717 }
718
719 regs->DWINPOS = (params->dst_y << 16) | params->dst_x;
720 regs->DWINSZ = (params->dst_h << 16) | params->dst_w;
721
722 if (params->format & I915_OVERLAY_YUV_PACKED)
723 tmp_width = packed_width_bytes(params->format, params->src_w);
724 else
725 tmp_width = params->src_w;
726
727 regs->SWIDTH = params->src_w;
728 regs->SWIDTHSW = calc_swidthsw(overlay->dev,
Chris Wilson722506f2010-08-12 09:28:50 +0100729 params->offset_Y, tmp_width);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200730 regs->SHEIGHT = params->src_h;
731 regs->OBUF_0Y = bo_priv->gtt_offset + params-> offset_Y;
732 regs->OSTRIDE = params->stride_Y;
733
734 if (params->format & I915_OVERLAY_YUV_PLANAR) {
735 int uv_hscale = uv_hsubsampling(params->format);
736 int uv_vscale = uv_vsubsampling(params->format);
737 u32 tmp_U, tmp_V;
738 regs->SWIDTH |= (params->src_w/uv_hscale) << 16;
739 tmp_U = calc_swidthsw(overlay->dev, params->offset_U,
Chris Wilson722506f2010-08-12 09:28:50 +0100740 params->src_w/uv_hscale);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200741 tmp_V = calc_swidthsw(overlay->dev, params->offset_V,
Chris Wilson722506f2010-08-12 09:28:50 +0100742 params->src_w/uv_hscale);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200743 regs->SWIDTHSW |= max_t(u32, tmp_U, tmp_V) << 16;
744 regs->SHEIGHT |= (params->src_h/uv_vscale) << 16;
745 regs->OBUF_0U = bo_priv->gtt_offset + params->offset_U;
746 regs->OBUF_0V = bo_priv->gtt_offset + params->offset_V;
747 regs->OSTRIDE |= params->stride_UV << 16;
748 }
749
750 scale_changed = update_scaling_factors(overlay, regs, params);
751
752 update_colorkey(overlay, regs);
753
754 regs->OCMD = overlay_cmd_reg(params);
755
Chris Wilson9bb2ff72010-08-12 12:02:11 +0100756 intel_overlay_unmap_regs(overlay, regs);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200757
758 intel_overlay_continue(overlay, scale_changed);
759
760 overlay->old_vid_bo = overlay->vid_bo;
Daniel Vetter23010e42010-03-08 13:35:02 +0100761 overlay->vid_bo = to_intel_bo(new_bo);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200762
763 return 0;
764
765out_unpin:
766 i915_gem_object_unpin(new_bo);
767 return ret;
768}
769
770int intel_overlay_switch_off(struct intel_overlay *overlay)
771{
772 int ret;
773 struct overlay_registers *regs;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200774 struct drm_device *dev = overlay->dev;
775
776 BUG_ON(!mutex_is_locked(&dev->struct_mutex));
777 BUG_ON(!mutex_is_locked(&dev->mode_config.mutex));
778
Daniel Vetter9bedb972009-11-30 15:55:49 +0100779 if (overlay->hw_wedged) {
780 ret = intel_overlay_recover_from_interrupt(overlay, 1);
781 if (ret != 0)
782 return ret;
783 }
784
Daniel Vetter02e792f2009-09-15 22:57:34 +0200785 if (!overlay->active)
786 return 0;
787
Daniel Vetter02e792f2009-09-15 22:57:34 +0200788 ret = intel_overlay_release_old_vid(overlay);
789 if (ret != 0)
790 return ret;
791
Chris Wilson8d74f652010-08-12 10:35:26 +0100792 regs = intel_overlay_map_regs(overlay);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200793 regs->OCMD = 0;
Chris Wilson9bb2ff72010-08-12 12:02:11 +0100794 intel_overlay_unmap_regs(overlay, regs);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200795
796 ret = intel_overlay_off(overlay);
Daniel Vetter03f77ea2009-09-15 22:57:37 +0200797 if (ret != 0)
798 return ret;
799
Daniel Vetter12ca45f2037-04-25 10:08:26 +0200800 intel_overlay_off_tail(overlay);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200801
802 return 0;
803}
804
805static int check_overlay_possible_on_crtc(struct intel_overlay *overlay,
806 struct intel_crtc *crtc)
807{
Chris Wilson722506f2010-08-12 09:28:50 +0100808 drm_i915_private_t *dev_priv = overlay->dev->dev_private;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200809 u32 pipeconf;
810 int pipeconf_reg = (crtc->pipe == 0) ? PIPEACONF : PIPEBCONF;
811
812 if (!crtc->base.enabled || crtc->dpms_mode != DRM_MODE_DPMS_ON)
813 return -EINVAL;
814
815 pipeconf = I915_READ(pipeconf_reg);
816
817 /* can't use the overlay with double wide pipe */
818 if (!IS_I965G(overlay->dev) && pipeconf & PIPEACONF_DOUBLE_WIDE)
819 return -EINVAL;
820
821 return 0;
822}
823
824static void update_pfit_vscale_ratio(struct intel_overlay *overlay)
825{
826 struct drm_device *dev = overlay->dev;
Chris Wilson722506f2010-08-12 09:28:50 +0100827 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200828 u32 pfit_control = I915_READ(PFIT_CONTROL);
Chris Wilson446d2182010-08-12 11:15:58 +0100829 u32 ratio;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200830
831 /* XXX: This is not the same logic as in the xorg driver, but more in
Chris Wilson446d2182010-08-12 11:15:58 +0100832 * line with the intel documentation for the i965
833 */
834 if (!IS_I965G(dev)) {
835 if (pfit_control & VERT_AUTO_SCALE)
836 ratio = I915_READ(PFIT_AUTO_RATIOS);
Daniel Vetter02e792f2009-09-15 22:57:34 +0200837 else
Chris Wilson446d2182010-08-12 11:15:58 +0100838 ratio = I915_READ(PFIT_PGM_RATIOS);
839 ratio >>= PFIT_VERT_SCALE_SHIFT;
840 } else { /* on i965 use the PGM reg to read out the autoscaler values */
841 ratio = I915_READ(PFIT_PGM_RATIOS) >> PFIT_VERT_SCALE_SHIFT_965;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200842 }
843
844 overlay->pfit_vscale_ratio = ratio;
845}
846
847static int check_overlay_dst(struct intel_overlay *overlay,
848 struct drm_intel_overlay_put_image *rec)
849{
850 struct drm_display_mode *mode = &overlay->crtc->base.mode;
851
Chris Wilson722506f2010-08-12 09:28:50 +0100852 if (rec->dst_x < mode->crtc_hdisplay &&
853 rec->dst_x + rec->dst_width <= mode->crtc_hdisplay &&
854 rec->dst_y < mode->crtc_vdisplay &&
855 rec->dst_y + rec->dst_height <= mode->crtc_vdisplay)
Daniel Vetter02e792f2009-09-15 22:57:34 +0200856 return 0;
857 else
858 return -EINVAL;
859}
860
861static int check_overlay_scaling(struct put_image_params *rec)
862{
863 u32 tmp;
864
865 /* downscaling limit is 8.0 */
866 tmp = ((rec->src_scan_h << 16) / rec->dst_h) >> 16;
867 if (tmp > 7)
868 return -EINVAL;
869 tmp = ((rec->src_scan_w << 16) / rec->dst_w) >> 16;
870 if (tmp > 7)
871 return -EINVAL;
872
873 return 0;
874}
875
876static int check_overlay_src(struct drm_device *dev,
877 struct drm_intel_overlay_put_image *rec,
878 struct drm_gem_object *new_bo)
879{
Daniel Vetter02e792f2009-09-15 22:57:34 +0200880 int uv_hscale = uv_hsubsampling(rec->flags);
881 int uv_vscale = uv_vsubsampling(rec->flags);
Chris Wilson9f7c3f42010-08-12 11:29:34 +0100882 u32 stride_mask, depth, tmp;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200883
884 /* check src dimensions */
885 if (IS_845G(dev) || IS_I830(dev)) {
Chris Wilson722506f2010-08-12 09:28:50 +0100886 if (rec->src_height > IMAGE_MAX_HEIGHT_LEGACY ||
Chris Wilson9f7c3f42010-08-12 11:29:34 +0100887 rec->src_width > IMAGE_MAX_WIDTH_LEGACY)
Daniel Vetter02e792f2009-09-15 22:57:34 +0200888 return -EINVAL;
889 } else {
Chris Wilson722506f2010-08-12 09:28:50 +0100890 if (rec->src_height > IMAGE_MAX_HEIGHT ||
Chris Wilson9f7c3f42010-08-12 11:29:34 +0100891 rec->src_width > IMAGE_MAX_WIDTH)
Daniel Vetter02e792f2009-09-15 22:57:34 +0200892 return -EINVAL;
893 }
Chris Wilson9f7c3f42010-08-12 11:29:34 +0100894
Daniel Vetter02e792f2009-09-15 22:57:34 +0200895 /* better safe than sorry, use 4 as the maximal subsampling ratio */
Chris Wilson722506f2010-08-12 09:28:50 +0100896 if (rec->src_height < N_VERT_Y_TAPS*4 ||
Chris Wilson9f7c3f42010-08-12 11:29:34 +0100897 rec->src_width < N_HORIZ_Y_TAPS*4)
Daniel Vetter02e792f2009-09-15 22:57:34 +0200898 return -EINVAL;
899
Chris Wilsona1efd142010-07-12 19:35:38 +0100900 /* check alignment constraints */
Daniel Vetter02e792f2009-09-15 22:57:34 +0200901 switch (rec->flags & I915_OVERLAY_TYPE_MASK) {
Chris Wilson722506f2010-08-12 09:28:50 +0100902 case I915_OVERLAY_RGB:
903 /* not implemented */
904 return -EINVAL;
Chris Wilson9f7c3f42010-08-12 11:29:34 +0100905
Chris Wilson722506f2010-08-12 09:28:50 +0100906 case I915_OVERLAY_YUV_PACKED:
Chris Wilson722506f2010-08-12 09:28:50 +0100907 if (uv_vscale != 1)
Daniel Vetter02e792f2009-09-15 22:57:34 +0200908 return -EINVAL;
Chris Wilson9f7c3f42010-08-12 11:29:34 +0100909
910 depth = packed_depth_bytes(rec->flags);
Chris Wilson722506f2010-08-12 09:28:50 +0100911 if (depth < 0)
912 return depth;
Chris Wilson9f7c3f42010-08-12 11:29:34 +0100913
Chris Wilson722506f2010-08-12 09:28:50 +0100914 /* ignore UV planes */
915 rec->stride_UV = 0;
916 rec->offset_U = 0;
917 rec->offset_V = 0;
918 /* check pixel alignment */
919 if (rec->offset_Y % depth)
Daniel Vetter02e792f2009-09-15 22:57:34 +0200920 return -EINVAL;
Chris Wilson722506f2010-08-12 09:28:50 +0100921 break;
Chris Wilson9f7c3f42010-08-12 11:29:34 +0100922
Chris Wilson722506f2010-08-12 09:28:50 +0100923 case I915_OVERLAY_YUV_PLANAR:
924 if (uv_vscale < 0 || uv_hscale < 0)
925 return -EINVAL;
926 /* no offset restrictions for planar formats */
927 break;
Chris Wilson9f7c3f42010-08-12 11:29:34 +0100928
Chris Wilson722506f2010-08-12 09:28:50 +0100929 default:
930 return -EINVAL;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200931 }
932
933 if (rec->src_width % uv_hscale)
934 return -EINVAL;
935
936 /* stride checking */
Chris Wilsona1efd142010-07-12 19:35:38 +0100937 if (IS_I830(dev) || IS_845G(dev))
938 stride_mask = 255;
939 else
940 stride_mask = 63;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200941
942 if (rec->stride_Y & stride_mask || rec->stride_UV & stride_mask)
943 return -EINVAL;
944 if (IS_I965G(dev) && rec->stride_Y < 512)
945 return -EINVAL;
946
947 tmp = (rec->flags & I915_OVERLAY_TYPE_MASK) == I915_OVERLAY_YUV_PLANAR ?
Chris Wilson9f7c3f42010-08-12 11:29:34 +0100948 4096 : 8192;
949 if (rec->stride_Y > tmp || rec->stride_UV > 2*1024)
Daniel Vetter02e792f2009-09-15 22:57:34 +0200950 return -EINVAL;
951
952 /* check buffer dimensions */
953 switch (rec->flags & I915_OVERLAY_TYPE_MASK) {
Chris Wilson722506f2010-08-12 09:28:50 +0100954 case I915_OVERLAY_RGB:
955 case I915_OVERLAY_YUV_PACKED:
956 /* always 4 Y values per depth pixels */
957 if (packed_width_bytes(rec->flags, rec->src_width) > rec->stride_Y)
958 return -EINVAL;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200959
Chris Wilson722506f2010-08-12 09:28:50 +0100960 tmp = rec->stride_Y*rec->src_height;
961 if (rec->offset_Y + tmp > new_bo->size)
962 return -EINVAL;
963 break;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200964
Chris Wilson722506f2010-08-12 09:28:50 +0100965 case I915_OVERLAY_YUV_PLANAR:
966 if (rec->src_width > rec->stride_Y)
967 return -EINVAL;
968 if (rec->src_width/uv_hscale > rec->stride_UV)
969 return -EINVAL;
970
Chris Wilson9f7c3f42010-08-12 11:29:34 +0100971 tmp = rec->stride_Y * rec->src_height;
Chris Wilson722506f2010-08-12 09:28:50 +0100972 if (rec->offset_Y + tmp > new_bo->size)
973 return -EINVAL;
Chris Wilson9f7c3f42010-08-12 11:29:34 +0100974
975 tmp = rec->stride_UV * (rec->src_height / uv_vscale);
Chris Wilson722506f2010-08-12 09:28:50 +0100976 if (rec->offset_U + tmp > new_bo->size ||
977 rec->offset_V + tmp > new_bo->size)
978 return -EINVAL;
979 break;
Daniel Vetter02e792f2009-09-15 22:57:34 +0200980 }
981
982 return 0;
983}
984
985int intel_overlay_put_image(struct drm_device *dev, void *data,
986 struct drm_file *file_priv)
987{
988 struct drm_intel_overlay_put_image *put_image_rec = data;
989 drm_i915_private_t *dev_priv = dev->dev_private;
990 struct intel_overlay *overlay;
991 struct drm_mode_object *drmmode_obj;
992 struct intel_crtc *crtc;
993 struct drm_gem_object *new_bo;
994 struct put_image_params *params;
995 int ret;
996
997 if (!dev_priv) {
998 DRM_ERROR("called with no initialization\n");
999 return -EINVAL;
1000 }
1001
1002 overlay = dev_priv->overlay;
1003 if (!overlay) {
1004 DRM_DEBUG("userspace bug: no overlay\n");
1005 return -ENODEV;
1006 }
1007
1008 if (!(put_image_rec->flags & I915_OVERLAY_ENABLE)) {
1009 mutex_lock(&dev->mode_config.mutex);
1010 mutex_lock(&dev->struct_mutex);
1011
1012 ret = intel_overlay_switch_off(overlay);
1013
1014 mutex_unlock(&dev->struct_mutex);
1015 mutex_unlock(&dev->mode_config.mutex);
1016
1017 return ret;
1018 }
1019
1020 params = kmalloc(sizeof(struct put_image_params), GFP_KERNEL);
1021 if (!params)
1022 return -ENOMEM;
1023
1024 drmmode_obj = drm_mode_object_find(dev, put_image_rec->crtc_id,
Chris Wilson722506f2010-08-12 09:28:50 +01001025 DRM_MODE_OBJECT_CRTC);
Dan Carpenter915a4282010-03-06 14:05:39 +03001026 if (!drmmode_obj) {
1027 ret = -ENOENT;
1028 goto out_free;
1029 }
Daniel Vetter02e792f2009-09-15 22:57:34 +02001030 crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
1031
1032 new_bo = drm_gem_object_lookup(dev, file_priv,
Chris Wilson722506f2010-08-12 09:28:50 +01001033 put_image_rec->bo_handle);
Dan Carpenter915a4282010-03-06 14:05:39 +03001034 if (!new_bo) {
1035 ret = -ENOENT;
1036 goto out_free;
1037 }
Daniel Vetter02e792f2009-09-15 22:57:34 +02001038
1039 mutex_lock(&dev->mode_config.mutex);
1040 mutex_lock(&dev->struct_mutex);
1041
Daniel Vetter03f77ea2009-09-15 22:57:37 +02001042 if (overlay->hw_wedged) {
1043 ret = intel_overlay_recover_from_interrupt(overlay, 1);
1044 if (ret != 0)
1045 goto out_unlock;
1046 }
1047
Daniel Vetter02e792f2009-09-15 22:57:34 +02001048 if (overlay->crtc != crtc) {
1049 struct drm_display_mode *mode = &crtc->base.mode;
1050 ret = intel_overlay_switch_off(overlay);
1051 if (ret != 0)
1052 goto out_unlock;
1053
1054 ret = check_overlay_possible_on_crtc(overlay, crtc);
1055 if (ret != 0)
1056 goto out_unlock;
1057
1058 overlay->crtc = crtc;
1059 crtc->overlay = overlay;
1060
1061 if (intel_panel_fitter_pipe(dev) == crtc->pipe
1062 /* and line to wide, i.e. one-line-mode */
1063 && mode->hdisplay > 1024) {
1064 overlay->pfit_active = 1;
1065 update_pfit_vscale_ratio(overlay);
1066 } else
1067 overlay->pfit_active = 0;
1068 }
1069
1070 ret = check_overlay_dst(overlay, put_image_rec);
1071 if (ret != 0)
1072 goto out_unlock;
1073
1074 if (overlay->pfit_active) {
1075 params->dst_y = ((((u32)put_image_rec->dst_y) << 12) /
Chris Wilson722506f2010-08-12 09:28:50 +01001076 overlay->pfit_vscale_ratio);
Daniel Vetter02e792f2009-09-15 22:57:34 +02001077 /* shifting right rounds downwards, so add 1 */
1078 params->dst_h = ((((u32)put_image_rec->dst_height) << 12) /
Chris Wilson722506f2010-08-12 09:28:50 +01001079 overlay->pfit_vscale_ratio) + 1;
Daniel Vetter02e792f2009-09-15 22:57:34 +02001080 } else {
1081 params->dst_y = put_image_rec->dst_y;
1082 params->dst_h = put_image_rec->dst_height;
1083 }
1084 params->dst_x = put_image_rec->dst_x;
1085 params->dst_w = put_image_rec->dst_width;
1086
1087 params->src_w = put_image_rec->src_width;
1088 params->src_h = put_image_rec->src_height;
1089 params->src_scan_w = put_image_rec->src_scan_width;
1090 params->src_scan_h = put_image_rec->src_scan_height;
Chris Wilson722506f2010-08-12 09:28:50 +01001091 if (params->src_scan_h > params->src_h ||
1092 params->src_scan_w > params->src_w) {
Daniel Vetter02e792f2009-09-15 22:57:34 +02001093 ret = -EINVAL;
1094 goto out_unlock;
1095 }
1096
1097 ret = check_overlay_src(dev, put_image_rec, new_bo);
1098 if (ret != 0)
1099 goto out_unlock;
1100 params->format = put_image_rec->flags & ~I915_OVERLAY_FLAGS_MASK;
1101 params->stride_Y = put_image_rec->stride_Y;
1102 params->stride_UV = put_image_rec->stride_UV;
1103 params->offset_Y = put_image_rec->offset_Y;
1104 params->offset_U = put_image_rec->offset_U;
1105 params->offset_V = put_image_rec->offset_V;
1106
1107 /* Check scaling after src size to prevent a divide-by-zero. */
1108 ret = check_overlay_scaling(params);
1109 if (ret != 0)
1110 goto out_unlock;
1111
1112 ret = intel_overlay_do_put_image(overlay, new_bo, params);
1113 if (ret != 0)
1114 goto out_unlock;
1115
1116 mutex_unlock(&dev->struct_mutex);
1117 mutex_unlock(&dev->mode_config.mutex);
1118
1119 kfree(params);
1120
1121 return 0;
1122
1123out_unlock:
1124 mutex_unlock(&dev->struct_mutex);
1125 mutex_unlock(&dev->mode_config.mutex);
Luca Barbieribc9025b2010-02-09 05:49:12 +00001126 drm_gem_object_unreference_unlocked(new_bo);
Dan Carpenter915a4282010-03-06 14:05:39 +03001127out_free:
Daniel Vetter02e792f2009-09-15 22:57:34 +02001128 kfree(params);
1129
1130 return ret;
1131}
1132
1133static void update_reg_attrs(struct intel_overlay *overlay,
1134 struct overlay_registers *regs)
1135{
1136 regs->OCLRC0 = (overlay->contrast << 18) | (overlay->brightness & 0xff);
1137 regs->OCLRC1 = overlay->saturation;
1138}
1139
1140static bool check_gamma_bounds(u32 gamma1, u32 gamma2)
1141{
1142 int i;
1143
1144 if (gamma1 & 0xff000000 || gamma2 & 0xff000000)
1145 return false;
1146
1147 for (i = 0; i < 3; i++) {
Chris Wilson722506f2010-08-12 09:28:50 +01001148 if (((gamma1 >> i*8) & 0xff) >= ((gamma2 >> i*8) & 0xff))
Daniel Vetter02e792f2009-09-15 22:57:34 +02001149 return false;
1150 }
1151
1152 return true;
1153}
1154
1155static bool check_gamma5_errata(u32 gamma5)
1156{
1157 int i;
1158
1159 for (i = 0; i < 3; i++) {
1160 if (((gamma5 >> i*8) & 0xff) == 0x80)
1161 return false;
1162 }
1163
1164 return true;
1165}
1166
1167static int check_gamma(struct drm_intel_overlay_attrs *attrs)
1168{
Chris Wilson722506f2010-08-12 09:28:50 +01001169 if (!check_gamma_bounds(0, attrs->gamma0) ||
1170 !check_gamma_bounds(attrs->gamma0, attrs->gamma1) ||
1171 !check_gamma_bounds(attrs->gamma1, attrs->gamma2) ||
1172 !check_gamma_bounds(attrs->gamma2, attrs->gamma3) ||
1173 !check_gamma_bounds(attrs->gamma3, attrs->gamma4) ||
1174 !check_gamma_bounds(attrs->gamma4, attrs->gamma5) ||
1175 !check_gamma_bounds(attrs->gamma5, 0x00ffffff))
Daniel Vetter02e792f2009-09-15 22:57:34 +02001176 return -EINVAL;
Chris Wilson722506f2010-08-12 09:28:50 +01001177
Daniel Vetter02e792f2009-09-15 22:57:34 +02001178 if (!check_gamma5_errata(attrs->gamma5))
1179 return -EINVAL;
Chris Wilson722506f2010-08-12 09:28:50 +01001180
Daniel Vetter02e792f2009-09-15 22:57:34 +02001181 return 0;
1182}
1183
1184int intel_overlay_attrs(struct drm_device *dev, void *data,
1185 struct drm_file *file_priv)
1186{
1187 struct drm_intel_overlay_attrs *attrs = data;
1188 drm_i915_private_t *dev_priv = dev->dev_private;
1189 struct intel_overlay *overlay;
1190 struct overlay_registers *regs;
1191 int ret;
1192
1193 if (!dev_priv) {
1194 DRM_ERROR("called with no initialization\n");
1195 return -EINVAL;
1196 }
1197
1198 overlay = dev_priv->overlay;
1199 if (!overlay) {
1200 DRM_DEBUG("userspace bug: no overlay\n");
1201 return -ENODEV;
1202 }
1203
1204 mutex_lock(&dev->mode_config.mutex);
1205 mutex_lock(&dev->struct_mutex);
1206
Chris Wilson60fc3322010-08-12 10:44:45 +01001207 ret = -EINVAL;
Daniel Vetter02e792f2009-09-15 22:57:34 +02001208 if (!(attrs->flags & I915_OVERLAY_UPDATE_ATTRS)) {
Chris Wilson60fc3322010-08-12 10:44:45 +01001209 attrs->color_key = overlay->color_key;
Daniel Vetter02e792f2009-09-15 22:57:34 +02001210 attrs->brightness = overlay->brightness;
Chris Wilson60fc3322010-08-12 10:44:45 +01001211 attrs->contrast = overlay->contrast;
Daniel Vetter02e792f2009-09-15 22:57:34 +02001212 attrs->saturation = overlay->saturation;
1213
1214 if (IS_I9XX(dev)) {
1215 attrs->gamma0 = I915_READ(OGAMC0);
1216 attrs->gamma1 = I915_READ(OGAMC1);
1217 attrs->gamma2 = I915_READ(OGAMC2);
1218 attrs->gamma3 = I915_READ(OGAMC3);
1219 attrs->gamma4 = I915_READ(OGAMC4);
1220 attrs->gamma5 = I915_READ(OGAMC5);
1221 }
Daniel Vetter02e792f2009-09-15 22:57:34 +02001222 } else {
Chris Wilson60fc3322010-08-12 10:44:45 +01001223 if (attrs->brightness < -128 || attrs->brightness > 127)
Daniel Vetter02e792f2009-09-15 22:57:34 +02001224 goto out_unlock;
Chris Wilson60fc3322010-08-12 10:44:45 +01001225 if (attrs->contrast > 255)
1226 goto out_unlock;
1227 if (attrs->saturation > 1023)
1228 goto out_unlock;
Chris Wilson722506f2010-08-12 09:28:50 +01001229
Chris Wilson60fc3322010-08-12 10:44:45 +01001230 overlay->color_key = attrs->color_key;
1231 overlay->brightness = attrs->brightness;
1232 overlay->contrast = attrs->contrast;
1233 overlay->saturation = attrs->saturation;
Daniel Vetter02e792f2009-09-15 22:57:34 +02001234
Chris Wilson8d74f652010-08-12 10:35:26 +01001235 regs = intel_overlay_map_regs(overlay);
Daniel Vetter02e792f2009-09-15 22:57:34 +02001236 if (!regs) {
1237 ret = -ENOMEM;
1238 goto out_unlock;
1239 }
1240
1241 update_reg_attrs(overlay, regs);
1242
Chris Wilson9bb2ff72010-08-12 12:02:11 +01001243 intel_overlay_unmap_regs(overlay, regs);
Daniel Vetter02e792f2009-09-15 22:57:34 +02001244
1245 if (attrs->flags & I915_OVERLAY_UPDATE_GAMMA) {
Chris Wilson60fc3322010-08-12 10:44:45 +01001246 if (!IS_I9XX(dev))
Daniel Vetter02e792f2009-09-15 22:57:34 +02001247 goto out_unlock;
Daniel Vetter02e792f2009-09-15 22:57:34 +02001248
1249 if (overlay->active) {
1250 ret = -EBUSY;
1251 goto out_unlock;
1252 }
1253
1254 ret = check_gamma(attrs);
Chris Wilson60fc3322010-08-12 10:44:45 +01001255 if (ret)
Daniel Vetter02e792f2009-09-15 22:57:34 +02001256 goto out_unlock;
1257
1258 I915_WRITE(OGAMC0, attrs->gamma0);
1259 I915_WRITE(OGAMC1, attrs->gamma1);
1260 I915_WRITE(OGAMC2, attrs->gamma2);
1261 I915_WRITE(OGAMC3, attrs->gamma3);
1262 I915_WRITE(OGAMC4, attrs->gamma4);
1263 I915_WRITE(OGAMC5, attrs->gamma5);
1264 }
Daniel Vetter02e792f2009-09-15 22:57:34 +02001265 }
1266
Chris Wilson60fc3322010-08-12 10:44:45 +01001267 ret = 0;
Daniel Vetter02e792f2009-09-15 22:57:34 +02001268out_unlock:
1269 mutex_unlock(&dev->struct_mutex);
1270 mutex_unlock(&dev->mode_config.mutex);
1271
1272 return ret;
1273}
1274
1275void intel_setup_overlay(struct drm_device *dev)
1276{
1277 drm_i915_private_t *dev_priv = dev->dev_private;
1278 struct intel_overlay *overlay;
1279 struct drm_gem_object *reg_bo;
1280 struct overlay_registers *regs;
1281 int ret;
1282
Chris Wilson315781482010-08-12 09:42:51 +01001283 if (!HAS_OVERLAY(dev))
Daniel Vetter02e792f2009-09-15 22:57:34 +02001284 return;
1285
1286 overlay = kzalloc(sizeof(struct intel_overlay), GFP_KERNEL);
1287 if (!overlay)
1288 return;
1289 overlay->dev = dev;
1290
Daniel Vetterac52bc52010-04-09 19:05:06 +00001291 reg_bo = i915_gem_alloc_object(dev, PAGE_SIZE);
Daniel Vetter02e792f2009-09-15 22:57:34 +02001292 if (!reg_bo)
1293 goto out_free;
Daniel Vetter23010e42010-03-08 13:35:02 +01001294 overlay->reg_bo = to_intel_bo(reg_bo);
Daniel Vetter02e792f2009-09-15 22:57:34 +02001295
Chris Wilson315781482010-08-12 09:42:51 +01001296 if (OVERLAY_NEEDS_PHYSICAL(dev)) {
1297 ret = i915_gem_attach_phys_object(dev, reg_bo,
1298 I915_GEM_PHYS_OVERLAY_REGS,
Chris Wilsona2930122010-08-12 10:47:56 +01001299 PAGE_SIZE);
Chris Wilson315781482010-08-12 09:42:51 +01001300 if (ret) {
1301 DRM_ERROR("failed to attach phys overlay regs\n");
1302 goto out_free_bo;
1303 }
1304 overlay->flip_addr = overlay->reg_bo->phys_obj->handle->busaddr;
1305 } else {
Daniel Vetter02e792f2009-09-15 22:57:34 +02001306 ret = i915_gem_object_pin(reg_bo, PAGE_SIZE);
1307 if (ret) {
1308 DRM_ERROR("failed to pin overlay register bo\n");
1309 goto out_free_bo;
1310 }
1311 overlay->flip_addr = overlay->reg_bo->gtt_offset;
Chris Wilson0ddc1282010-08-12 09:35:00 +01001312
1313 ret = i915_gem_object_set_to_gtt_domain(reg_bo, true);
1314 if (ret) {
1315 DRM_ERROR("failed to move overlay register bo into the GTT\n");
1316 goto out_unpin_bo;
1317 }
Daniel Vetter02e792f2009-09-15 22:57:34 +02001318 }
1319
1320 /* init all values */
1321 overlay->color_key = 0x0101fe;
1322 overlay->brightness = -19;
1323 overlay->contrast = 75;
1324 overlay->saturation = 146;
1325
Chris Wilson8d74f652010-08-12 10:35:26 +01001326 regs = intel_overlay_map_regs(overlay);
Daniel Vetter02e792f2009-09-15 22:57:34 +02001327 if (!regs)
1328 goto out_free_bo;
1329
1330 memset(regs, 0, sizeof(struct overlay_registers));
1331 update_polyphase_filter(regs);
Daniel Vetter02e792f2009-09-15 22:57:34 +02001332 update_reg_attrs(overlay, regs);
1333
Chris Wilson9bb2ff72010-08-12 12:02:11 +01001334 intel_overlay_unmap_regs(overlay, regs);
Daniel Vetter02e792f2009-09-15 22:57:34 +02001335
1336 dev_priv->overlay = overlay;
1337 DRM_INFO("initialized overlay support\n");
1338 return;
1339
Chris Wilson0ddc1282010-08-12 09:35:00 +01001340out_unpin_bo:
1341 i915_gem_object_unpin(reg_bo);
Daniel Vetter02e792f2009-09-15 22:57:34 +02001342out_free_bo:
1343 drm_gem_object_unreference(reg_bo);
1344out_free:
1345 kfree(overlay);
1346 return;
1347}
1348
1349void intel_cleanup_overlay(struct drm_device *dev)
1350{
Chris Wilson722506f2010-08-12 09:28:50 +01001351 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetter02e792f2009-09-15 22:57:34 +02001352
Chris Wilson62cf4e62010-08-12 10:50:36 +01001353 if (!dev_priv->overlay)
1354 return;
Daniel Vetter02e792f2009-09-15 22:57:34 +02001355
Chris Wilson62cf4e62010-08-12 10:50:36 +01001356 /* The bo's should be free'd by the generic code already.
1357 * Furthermore modesetting teardown happens beforehand so the
1358 * hardware should be off already */
1359 BUG_ON(dev_priv->overlay->active);
1360
1361 drm_gem_object_unreference_unlocked(&dev_priv->overlay->reg_bo->base);
1362 kfree(dev_priv->overlay);
Daniel Vetter02e792f2009-09-15 22:57:34 +02001363}
Chris Wilson6ef3d422010-08-04 20:26:07 +01001364
1365struct intel_overlay_error_state {
1366 struct overlay_registers regs;
1367 unsigned long base;
1368 u32 dovsta;
1369 u32 isr;
1370};
1371
1372struct intel_overlay_error_state *
1373intel_overlay_capture_error_state(struct drm_device *dev)
1374{
1375 drm_i915_private_t *dev_priv = dev->dev_private;
1376 struct intel_overlay *overlay = dev_priv->overlay;
1377 struct intel_overlay_error_state *error;
1378 struct overlay_registers __iomem *regs;
1379
1380 if (!overlay || !overlay->active)
1381 return NULL;
1382
1383 error = kmalloc(sizeof(*error), GFP_ATOMIC);
1384 if (error == NULL)
1385 return NULL;
1386
1387 error->dovsta = I915_READ(DOVSTA);
1388 error->isr = I915_READ(ISR);
Chris Wilson315781482010-08-12 09:42:51 +01001389 if (OVERLAY_NEEDS_PHYSICAL(overlay->dev))
Chris Wilson6ef3d422010-08-04 20:26:07 +01001390 error->base = (long) overlay->reg_bo->phys_obj->handle->vaddr;
Chris Wilson315781482010-08-12 09:42:51 +01001391 else
1392 error->base = (long) overlay->reg_bo->gtt_offset;
Chris Wilson6ef3d422010-08-04 20:26:07 +01001393
Chris Wilson8d74f652010-08-12 10:35:26 +01001394 regs = intel_overlay_map_regs_atomic(overlay, KM_IRQ0);
Chris Wilson6ef3d422010-08-04 20:26:07 +01001395 if (!regs)
1396 goto err;
1397
1398 memcpy_fromio(&error->regs, regs, sizeof(struct overlay_registers));
Chris Wilson9bb2ff72010-08-12 12:02:11 +01001399 intel_overlay_unmap_regs_atomic(overlay, KM_IRQ0, regs);
Chris Wilson6ef3d422010-08-04 20:26:07 +01001400
1401 return error;
1402
1403err:
1404 kfree(error);
1405 return NULL;
1406}
1407
1408void
1409intel_overlay_print_error_state(struct seq_file *m, struct intel_overlay_error_state *error)
1410{
1411 seq_printf(m, "Overlay, status: 0x%08x, interrupt: 0x%08x\n",
1412 error->dovsta, error->isr);
1413 seq_printf(m, " Register file at 0x%08lx:\n",
1414 error->base);
1415
1416#define P(x) seq_printf(m, " " #x ": 0x%08x\n", error->regs.x)
1417 P(OBUF_0Y);
1418 P(OBUF_1Y);
1419 P(OBUF_0U);
1420 P(OBUF_0V);
1421 P(OBUF_1U);
1422 P(OBUF_1V);
1423 P(OSTRIDE);
1424 P(YRGB_VPH);
1425 P(UV_VPH);
1426 P(HORZ_PH);
1427 P(INIT_PHS);
1428 P(DWINPOS);
1429 P(DWINSZ);
1430 P(SWIDTH);
1431 P(SWIDTHSW);
1432 P(SHEIGHT);
1433 P(YRGBSCALE);
1434 P(UVSCALE);
1435 P(OCLRC0);
1436 P(OCLRC1);
1437 P(DCLRKV);
1438 P(DCLRKM);
1439 P(SCLRKVH);
1440 P(SCLRKVL);
1441 P(SCLRKEN);
1442 P(OCONFIG);
1443 P(OCMD);
1444 P(OSTART_0Y);
1445 P(OSTART_1Y);
1446 P(OSTART_0U);
1447 P(OSTART_0V);
1448 P(OSTART_1U);
1449 P(OSTART_1V);
1450 P(OTILEOFF_0Y);
1451 P(OTILEOFF_1Y);
1452 P(OTILEOFF_0U);
1453 P(OTILEOFF_0V);
1454 P(OTILEOFF_1U);
1455 P(OTILEOFF_1V);
1456 P(FASTHSCALE);
1457 P(UVSCALEV);
1458#undef P
1459}