Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 28 | #include "drmP.h" |
| 29 | #include "drm.h" |
| 30 | #include "i915_drm.h" |
| 31 | #include "i915_drv.h" |
| 32 | #include "i915_reg.h" |
| 33 | #include "intel_drv.h" |
| 34 | |
| 35 | /* Limits for overlay size. According to intel doc, the real limits are: |
| 36 | * Y width: 4095, UV width (planar): 2047, Y height: 2047, |
| 37 | * UV width (planar): * 1023. But the xorg thinks 2048 for height and width. Use |
| 38 | * the mininum of both. */ |
| 39 | #define IMAGE_MAX_WIDTH 2048 |
| 40 | #define IMAGE_MAX_HEIGHT 2046 /* 2 * 1023 */ |
| 41 | /* on 830 and 845 these large limits result in the card hanging */ |
| 42 | #define IMAGE_MAX_WIDTH_LEGACY 1024 |
| 43 | #define IMAGE_MAX_HEIGHT_LEGACY 1088 |
| 44 | |
| 45 | /* overlay register definitions */ |
| 46 | /* OCMD register */ |
| 47 | #define OCMD_TILED_SURFACE (0x1<<19) |
| 48 | #define OCMD_MIRROR_MASK (0x3<<17) |
| 49 | #define OCMD_MIRROR_MODE (0x3<<17) |
| 50 | #define OCMD_MIRROR_HORIZONTAL (0x1<<17) |
| 51 | #define OCMD_MIRROR_VERTICAL (0x2<<17) |
| 52 | #define OCMD_MIRROR_BOTH (0x3<<17) |
| 53 | #define OCMD_BYTEORDER_MASK (0x3<<14) /* zero for YUYV or FOURCC YUY2 */ |
| 54 | #define OCMD_UV_SWAP (0x1<<14) /* YVYU */ |
| 55 | #define OCMD_Y_SWAP (0x2<<14) /* UYVY or FOURCC UYVY */ |
| 56 | #define OCMD_Y_AND_UV_SWAP (0x3<<14) /* VYUY */ |
| 57 | #define OCMD_SOURCE_FORMAT_MASK (0xf<<10) |
| 58 | #define OCMD_RGB_888 (0x1<<10) /* not in i965 Intel docs */ |
| 59 | #define OCMD_RGB_555 (0x2<<10) /* not in i965 Intel docs */ |
| 60 | #define OCMD_RGB_565 (0x3<<10) /* not in i965 Intel docs */ |
| 61 | #define OCMD_YUV_422_PACKED (0x8<<10) |
| 62 | #define OCMD_YUV_411_PACKED (0x9<<10) /* not in i965 Intel docs */ |
| 63 | #define OCMD_YUV_420_PLANAR (0xc<<10) |
| 64 | #define OCMD_YUV_422_PLANAR (0xd<<10) |
| 65 | #define OCMD_YUV_410_PLANAR (0xe<<10) /* also 411 */ |
| 66 | #define OCMD_TVSYNCFLIP_PARITY (0x1<<9) |
| 67 | #define OCMD_TVSYNCFLIP_ENABLE (0x1<<7) |
Chris Wilson | d796136 | 2010-07-13 13:52:17 +0100 | [diff] [blame] | 68 | #define OCMD_BUF_TYPE_MASK (0x1<<5) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 69 | #define OCMD_BUF_TYPE_FRAME (0x0<<5) |
| 70 | #define OCMD_BUF_TYPE_FIELD (0x1<<5) |
| 71 | #define OCMD_TEST_MODE (0x1<<4) |
| 72 | #define OCMD_BUFFER_SELECT (0x3<<2) |
| 73 | #define OCMD_BUFFER0 (0x0<<2) |
| 74 | #define OCMD_BUFFER1 (0x1<<2) |
| 75 | #define OCMD_FIELD_SELECT (0x1<<2) |
| 76 | #define OCMD_FIELD0 (0x0<<1) |
| 77 | #define OCMD_FIELD1 (0x1<<1) |
| 78 | #define OCMD_ENABLE (0x1<<0) |
| 79 | |
| 80 | /* OCONFIG register */ |
| 81 | #define OCONF_PIPE_MASK (0x1<<18) |
| 82 | #define OCONF_PIPE_A (0x0<<18) |
| 83 | #define OCONF_PIPE_B (0x1<<18) |
| 84 | #define OCONF_GAMMA2_ENABLE (0x1<<16) |
| 85 | #define OCONF_CSC_MODE_BT601 (0x0<<5) |
| 86 | #define OCONF_CSC_MODE_BT709 (0x1<<5) |
| 87 | #define OCONF_CSC_BYPASS (0x1<<4) |
| 88 | #define OCONF_CC_OUT_8BIT (0x1<<3) |
| 89 | #define OCONF_TEST_MODE (0x1<<2) |
| 90 | #define OCONF_THREE_LINE_BUFFER (0x1<<0) |
| 91 | #define OCONF_TWO_LINE_BUFFER (0x0<<0) |
| 92 | |
| 93 | /* DCLRKM (dst-key) register */ |
| 94 | #define DST_KEY_ENABLE (0x1<<31) |
| 95 | #define CLK_RGB24_MASK 0x0 |
| 96 | #define CLK_RGB16_MASK 0x070307 |
| 97 | #define CLK_RGB15_MASK 0x070707 |
| 98 | #define CLK_RGB8I_MASK 0xffffff |
| 99 | |
| 100 | #define RGB16_TO_COLORKEY(c) \ |
| 101 | (((c & 0xF800) << 8) | ((c & 0x07E0) << 5) | ((c & 0x001F) << 3)) |
| 102 | #define RGB15_TO_COLORKEY(c) \ |
| 103 | (((c & 0x7c00) << 9) | ((c & 0x03E0) << 6) | ((c & 0x001F) << 3)) |
| 104 | |
| 105 | /* overlay flip addr flag */ |
| 106 | #define OFC_UPDATE 0x1 |
| 107 | |
| 108 | /* polyphase filter coefficients */ |
| 109 | #define N_HORIZ_Y_TAPS 5 |
| 110 | #define N_VERT_Y_TAPS 3 |
| 111 | #define N_HORIZ_UV_TAPS 3 |
| 112 | #define N_VERT_UV_TAPS 3 |
| 113 | #define N_PHASES 17 |
| 114 | #define MAX_TAPS 5 |
| 115 | |
| 116 | /* memory bufferd overlay registers */ |
| 117 | struct overlay_registers { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 118 | u32 OBUF_0Y; |
| 119 | u32 OBUF_1Y; |
| 120 | u32 OBUF_0U; |
| 121 | u32 OBUF_0V; |
| 122 | u32 OBUF_1U; |
| 123 | u32 OBUF_1V; |
| 124 | u32 OSTRIDE; |
| 125 | u32 YRGB_VPH; |
| 126 | u32 UV_VPH; |
| 127 | u32 HORZ_PH; |
| 128 | u32 INIT_PHS; |
| 129 | u32 DWINPOS; |
| 130 | u32 DWINSZ; |
| 131 | u32 SWIDTH; |
| 132 | u32 SWIDTHSW; |
| 133 | u32 SHEIGHT; |
| 134 | u32 YRGBSCALE; |
| 135 | u32 UVSCALE; |
| 136 | u32 OCLRC0; |
| 137 | u32 OCLRC1; |
| 138 | u32 DCLRKV; |
| 139 | u32 DCLRKM; |
| 140 | u32 SCLRKVH; |
| 141 | u32 SCLRKVL; |
| 142 | u32 SCLRKEN; |
| 143 | u32 OCONFIG; |
| 144 | u32 OCMD; |
| 145 | u32 RESERVED1; /* 0x6C */ |
| 146 | u32 OSTART_0Y; |
| 147 | u32 OSTART_1Y; |
| 148 | u32 OSTART_0U; |
| 149 | u32 OSTART_0V; |
| 150 | u32 OSTART_1U; |
| 151 | u32 OSTART_1V; |
| 152 | u32 OTILEOFF_0Y; |
| 153 | u32 OTILEOFF_1Y; |
| 154 | u32 OTILEOFF_0U; |
| 155 | u32 OTILEOFF_0V; |
| 156 | u32 OTILEOFF_1U; |
| 157 | u32 OTILEOFF_1V; |
| 158 | u32 FASTHSCALE; /* 0xA0 */ |
| 159 | u32 UVSCALEV; /* 0xA4 */ |
| 160 | u32 RESERVEDC[(0x200 - 0xA8) / 4]; /* 0xA8 - 0x1FC */ |
| 161 | u16 Y_VCOEFS[N_VERT_Y_TAPS * N_PHASES]; /* 0x200 */ |
| 162 | u16 RESERVEDD[0x100 / 2 - N_VERT_Y_TAPS * N_PHASES]; |
| 163 | u16 Y_HCOEFS[N_HORIZ_Y_TAPS * N_PHASES]; /* 0x300 */ |
| 164 | u16 RESERVEDE[0x200 / 2 - N_HORIZ_Y_TAPS * N_PHASES]; |
| 165 | u16 UV_VCOEFS[N_VERT_UV_TAPS * N_PHASES]; /* 0x500 */ |
| 166 | u16 RESERVEDF[0x100 / 2 - N_VERT_UV_TAPS * N_PHASES]; |
| 167 | u16 UV_HCOEFS[N_HORIZ_UV_TAPS * N_PHASES]; /* 0x600 */ |
| 168 | u16 RESERVEDG[0x100 / 2 - N_HORIZ_UV_TAPS * N_PHASES]; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 169 | }; |
| 170 | |
Chris Wilson | 23f09ce | 2010-08-12 13:53:37 +0100 | [diff] [blame] | 171 | struct intel_overlay { |
| 172 | struct drm_device *dev; |
| 173 | struct intel_crtc *crtc; |
| 174 | struct drm_i915_gem_object *vid_bo; |
| 175 | struct drm_i915_gem_object *old_vid_bo; |
| 176 | int active; |
| 177 | int pfit_active; |
| 178 | u32 pfit_vscale_ratio; /* shifted-point number, (1<<12) == 1.0 */ |
| 179 | u32 color_key; |
| 180 | u32 brightness, contrast, saturation; |
| 181 | u32 old_xscale, old_yscale; |
| 182 | /* register access */ |
| 183 | u32 flip_addr; |
| 184 | struct drm_i915_gem_object *reg_bo; |
| 185 | /* flip handling */ |
| 186 | uint32_t last_flip_req; |
Chris Wilson | b303cf9 | 2010-08-12 14:03:48 +0100 | [diff] [blame] | 187 | void (*flip_tail)(struct intel_overlay *); |
Chris Wilson | 23f09ce | 2010-08-12 13:53:37 +0100 | [diff] [blame] | 188 | }; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 189 | |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 190 | static struct overlay_registers __iomem * |
Chris Wilson | 8d74f65 | 2010-08-12 10:35:26 +0100 | [diff] [blame] | 191 | intel_overlay_map_regs(struct intel_overlay *overlay) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 192 | { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 193 | drm_i915_private_t *dev_priv = overlay->dev->dev_private; |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 194 | struct overlay_registers __iomem *regs; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 195 | |
Chris Wilson | 9bb2ff7 | 2010-08-12 12:02:11 +0100 | [diff] [blame] | 196 | if (OVERLAY_NEEDS_PHYSICAL(overlay->dev)) |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 197 | regs = (struct overlay_registers __iomem *)overlay->reg_bo->phys_obj->handle->vaddr; |
Chris Wilson | 9bb2ff7 | 2010-08-12 12:02:11 +0100 | [diff] [blame] | 198 | else |
Chris Wilson | 8d74f65 | 2010-08-12 10:35:26 +0100 | [diff] [blame] | 199 | regs = io_mapping_map_wc(dev_priv->mm.gtt_mapping, |
| 200 | overlay->reg_bo->gtt_offset); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 201 | |
Chris Wilson | 9bb2ff7 | 2010-08-12 12:02:11 +0100 | [diff] [blame] | 202 | return regs; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 203 | } |
| 204 | |
Chris Wilson | 9bb2ff7 | 2010-08-12 12:02:11 +0100 | [diff] [blame] | 205 | static void intel_overlay_unmap_regs(struct intel_overlay *overlay, |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 206 | struct overlay_registers __iomem *regs) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 207 | { |
Chris Wilson | 8d74f65 | 2010-08-12 10:35:26 +0100 | [diff] [blame] | 208 | if (!OVERLAY_NEEDS_PHYSICAL(overlay->dev)) |
Chris Wilson | 9bb2ff7 | 2010-08-12 12:02:11 +0100 | [diff] [blame] | 209 | io_mapping_unmap(regs); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 210 | } |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 211 | |
Chris Wilson | b6c028e | 2010-08-12 11:55:08 +0100 | [diff] [blame] | 212 | static int intel_overlay_do_wait_request(struct intel_overlay *overlay, |
Chris Wilson | 8dc5d14 | 2010-08-12 12:36:12 +0100 | [diff] [blame] | 213 | struct drm_i915_gem_request *request, |
Chris Wilson | b303cf9 | 2010-08-12 14:03:48 +0100 | [diff] [blame] | 214 | void (*tail)(struct intel_overlay *)) |
Chris Wilson | b6c028e | 2010-08-12 11:55:08 +0100 | [diff] [blame] | 215 | { |
| 216 | struct drm_device *dev = overlay->dev; |
| 217 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 218 | int ret; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 219 | |
Chris Wilson | b303cf9 | 2010-08-12 14:03:48 +0100 | [diff] [blame] | 220 | BUG_ON(overlay->last_flip_req); |
Chris Wilson | db53a30 | 2011-02-03 11:57:46 +0000 | [diff] [blame] | 221 | ret = i915_add_request(LP_RING(dev_priv), NULL, request); |
Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 222 | if (ret) { |
| 223 | kfree(request); |
| 224 | return ret; |
| 225 | } |
| 226 | overlay->last_flip_req = request->seqno; |
Chris Wilson | b303cf9 | 2010-08-12 14:03:48 +0100 | [diff] [blame] | 227 | overlay->flip_tail = tail; |
Ben Widawsky | b93f9cf | 2012-01-25 15:39:34 -0800 | [diff] [blame] | 228 | ret = i915_wait_request(LP_RING(dev_priv), overlay->last_flip_req, |
| 229 | true); |
Chris Wilson | b6c028e | 2010-08-12 11:55:08 +0100 | [diff] [blame] | 230 | if (ret) |
| 231 | return ret; |
| 232 | |
Chris Wilson | b6c028e | 2010-08-12 11:55:08 +0100 | [diff] [blame] | 233 | overlay->last_flip_req = 0; |
| 234 | return 0; |
| 235 | } |
| 236 | |
Chris Wilson | 106dada | 2010-07-16 17:13:01 +0100 | [diff] [blame] | 237 | /* Workaround for i830 bug where pipe a must be enable to change control regs */ |
| 238 | static int |
| 239 | i830_activate_pipe_a(struct drm_device *dev) |
| 240 | { |
| 241 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 242 | struct intel_crtc *crtc; |
| 243 | struct drm_crtc_helper_funcs *crtc_funcs; |
| 244 | struct drm_display_mode vesa_640x480 = { |
| 245 | DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656, |
| 246 | 752, 800, 0, 480, 489, 492, 525, 0, |
| 247 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) |
| 248 | }, *mode; |
| 249 | |
| 250 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[0]); |
| 251 | if (crtc->dpms_mode == DRM_MODE_DPMS_ON) |
| 252 | return 0; |
| 253 | |
| 254 | /* most i8xx have pipe a forced on, so don't trust dpms mode */ |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 255 | if (I915_READ(_PIPEACONF) & PIPECONF_ENABLE) |
Chris Wilson | 106dada | 2010-07-16 17:13:01 +0100 | [diff] [blame] | 256 | return 0; |
| 257 | |
| 258 | crtc_funcs = crtc->base.helper_private; |
| 259 | if (crtc_funcs->dpms == NULL) |
| 260 | return 0; |
| 261 | |
| 262 | DRM_DEBUG_DRIVER("Enabling pipe A in order to enable overlay\n"); |
| 263 | |
| 264 | mode = drm_mode_duplicate(dev, &vesa_640x480); |
Daniel Vetter | ca9bfa7 | 2012-01-28 14:49:20 +0100 | [diff] [blame] | 265 | drm_mode_set_crtcinfo(mode, 0); |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 266 | if (!drm_crtc_helper_set_mode(&crtc->base, mode, |
Chris Wilson | 106dada | 2010-07-16 17:13:01 +0100 | [diff] [blame] | 267 | crtc->base.x, crtc->base.y, |
| 268 | crtc->base.fb)) |
| 269 | return 0; |
| 270 | |
| 271 | crtc_funcs->dpms(&crtc->base, DRM_MODE_DPMS_ON); |
| 272 | return 1; |
| 273 | } |
| 274 | |
| 275 | static void |
| 276 | i830_deactivate_pipe_a(struct drm_device *dev) |
| 277 | { |
| 278 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 279 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[0]; |
| 280 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; |
| 281 | |
| 282 | crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | /* overlay needs to be disable in OCMD reg */ |
| 286 | static int intel_overlay_on(struct intel_overlay *overlay) |
| 287 | { |
| 288 | struct drm_device *dev = overlay->dev; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 289 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 8dc5d14 | 2010-08-12 12:36:12 +0100 | [diff] [blame] | 290 | struct drm_i915_gem_request *request; |
Chris Wilson | 106dada | 2010-07-16 17:13:01 +0100 | [diff] [blame] | 291 | int pipe_a_quirk = 0; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 292 | int ret; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 293 | |
| 294 | BUG_ON(overlay->active); |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 295 | overlay->active = 1; |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 296 | |
Chris Wilson | 106dada | 2010-07-16 17:13:01 +0100 | [diff] [blame] | 297 | if (IS_I830(dev)) { |
| 298 | pipe_a_quirk = i830_activate_pipe_a(dev); |
| 299 | if (pipe_a_quirk < 0) |
| 300 | return pipe_a_quirk; |
| 301 | } |
| 302 | |
Chris Wilson | 8dc5d14 | 2010-08-12 12:36:12 +0100 | [diff] [blame] | 303 | request = kzalloc(sizeof(*request), GFP_KERNEL); |
Chris Wilson | 106dada | 2010-07-16 17:13:01 +0100 | [diff] [blame] | 304 | if (request == NULL) { |
| 305 | ret = -ENOMEM; |
| 306 | goto out; |
| 307 | } |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 308 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 309 | ret = BEGIN_LP_RING(4); |
| 310 | if (ret) { |
| 311 | kfree(request); |
| 312 | goto out; |
| 313 | } |
| 314 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 315 | OUT_RING(MI_OVERLAY_FLIP | MI_OVERLAY_ON); |
| 316 | OUT_RING(overlay->flip_addr | OFC_UPDATE); |
| 317 | OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP); |
| 318 | OUT_RING(MI_NOOP); |
| 319 | ADVANCE_LP_RING(); |
| 320 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 321 | ret = intel_overlay_do_wait_request(overlay, request, NULL); |
Chris Wilson | 106dada | 2010-07-16 17:13:01 +0100 | [diff] [blame] | 322 | out: |
| 323 | if (pipe_a_quirk) |
| 324 | i830_deactivate_pipe_a(dev); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 325 | |
Chris Wilson | 106dada | 2010-07-16 17:13:01 +0100 | [diff] [blame] | 326 | return ret; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /* overlay needs to be enabled in OCMD reg */ |
Chris Wilson | 8dc5d14 | 2010-08-12 12:36:12 +0100 | [diff] [blame] | 330 | static int intel_overlay_continue(struct intel_overlay *overlay, |
| 331 | bool load_polyphase_filter) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 332 | { |
| 333 | struct drm_device *dev = overlay->dev; |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 334 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 8dc5d14 | 2010-08-12 12:36:12 +0100 | [diff] [blame] | 335 | struct drm_i915_gem_request *request; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 336 | u32 flip_addr = overlay->flip_addr; |
| 337 | u32 tmp; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 338 | int ret; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 339 | |
| 340 | BUG_ON(!overlay->active); |
| 341 | |
Chris Wilson | 8dc5d14 | 2010-08-12 12:36:12 +0100 | [diff] [blame] | 342 | request = kzalloc(sizeof(*request), GFP_KERNEL); |
| 343 | if (request == NULL) |
| 344 | return -ENOMEM; |
| 345 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 346 | if (load_polyphase_filter) |
| 347 | flip_addr |= OFC_UPDATE; |
| 348 | |
| 349 | /* check for underruns */ |
| 350 | tmp = I915_READ(DOVSTA); |
| 351 | if (tmp & (1 << 17)) |
| 352 | DRM_DEBUG("overlay underrun, DOVSTA: %x\n", tmp); |
| 353 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 354 | ret = BEGIN_LP_RING(2); |
| 355 | if (ret) { |
| 356 | kfree(request); |
| 357 | return ret; |
| 358 | } |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 359 | OUT_RING(MI_OVERLAY_FLIP | MI_OVERLAY_CONTINUE); |
| 360 | OUT_RING(flip_addr); |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 361 | ADVANCE_LP_RING(); |
Daniel Vetter | 5a5a0c6 | 2009-09-15 22:57:36 +0200 | [diff] [blame] | 362 | |
Chris Wilson | db53a30 | 2011-02-03 11:57:46 +0000 | [diff] [blame] | 363 | ret = i915_add_request(LP_RING(dev_priv), NULL, request); |
Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 364 | if (ret) { |
| 365 | kfree(request); |
| 366 | return ret; |
| 367 | } |
| 368 | |
| 369 | overlay->last_flip_req = request->seqno; |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 370 | return 0; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 371 | } |
| 372 | |
Chris Wilson | b303cf9 | 2010-08-12 14:03:48 +0100 | [diff] [blame] | 373 | static void intel_overlay_release_old_vid_tail(struct intel_overlay *overlay) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 374 | { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 375 | struct drm_i915_gem_object *obj = overlay->old_vid_bo; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 376 | |
Chris Wilson | b303cf9 | 2010-08-12 14:03:48 +0100 | [diff] [blame] | 377 | i915_gem_object_unpin(obj); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 378 | drm_gem_object_unreference(&obj->base); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 379 | |
Chris Wilson | b303cf9 | 2010-08-12 14:03:48 +0100 | [diff] [blame] | 380 | overlay->old_vid_bo = NULL; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 381 | } |
| 382 | |
Daniel Vetter | 12ca45f | 2037-04-25 10:08:26 +0200 | [diff] [blame] | 383 | static void intel_overlay_off_tail(struct intel_overlay *overlay) |
| 384 | { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 385 | struct drm_i915_gem_object *obj = overlay->vid_bo; |
Daniel Vetter | 12ca45f | 2037-04-25 10:08:26 +0200 | [diff] [blame] | 386 | |
| 387 | /* never have the overlay hw on without showing a frame */ |
| 388 | BUG_ON(!overlay->vid_bo); |
Daniel Vetter | 12ca45f | 2037-04-25 10:08:26 +0200 | [diff] [blame] | 389 | |
| 390 | i915_gem_object_unpin(obj); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 391 | drm_gem_object_unreference(&obj->base); |
Daniel Vetter | 12ca45f | 2037-04-25 10:08:26 +0200 | [diff] [blame] | 392 | overlay->vid_bo = NULL; |
| 393 | |
| 394 | overlay->crtc->overlay = NULL; |
| 395 | overlay->crtc = NULL; |
| 396 | overlay->active = 0; |
| 397 | } |
| 398 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 399 | /* overlay needs to be disabled in OCMD reg */ |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 400 | static int intel_overlay_off(struct intel_overlay *overlay) |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 401 | { |
| 402 | struct drm_device *dev = overlay->dev; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 403 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 8dc5d14 | 2010-08-12 12:36:12 +0100 | [diff] [blame] | 404 | u32 flip_addr = overlay->flip_addr; |
| 405 | struct drm_i915_gem_request *request; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 406 | int ret; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 407 | |
| 408 | BUG_ON(!overlay->active); |
| 409 | |
Chris Wilson | 8dc5d14 | 2010-08-12 12:36:12 +0100 | [diff] [blame] | 410 | request = kzalloc(sizeof(*request), GFP_KERNEL); |
| 411 | if (request == NULL) |
| 412 | return -ENOMEM; |
| 413 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 414 | /* According to intel docs the overlay hw may hang (when switching |
| 415 | * off) without loading the filter coeffs. It is however unclear whether |
| 416 | * this applies to the disabling of the overlay or to the switching off |
| 417 | * of the hw. Do it in both cases */ |
| 418 | flip_addr |= OFC_UPDATE; |
| 419 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 420 | ret = BEGIN_LP_RING(6); |
| 421 | if (ret) { |
| 422 | kfree(request); |
| 423 | return ret; |
| 424 | } |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 425 | /* wait for overlay to go idle */ |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 426 | OUT_RING(MI_OVERLAY_FLIP | MI_OVERLAY_CONTINUE); |
| 427 | OUT_RING(flip_addr); |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 428 | OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP); |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 429 | /* turn overlay off */ |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 430 | OUT_RING(MI_OVERLAY_FLIP | MI_OVERLAY_OFF); |
| 431 | OUT_RING(flip_addr); |
| 432 | OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP); |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 433 | ADVANCE_LP_RING(); |
| 434 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 435 | return intel_overlay_do_wait_request(overlay, request, |
Chris Wilson | b303cf9 | 2010-08-12 14:03:48 +0100 | [diff] [blame] | 436 | intel_overlay_off_tail); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 437 | } |
| 438 | |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 439 | /* recover from an interruption due to a signal |
| 440 | * We have to be careful not to repeat work forever an make forward progess. */ |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 441 | static int intel_overlay_recover_from_interrupt(struct intel_overlay *overlay) |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 442 | { |
| 443 | struct drm_device *dev = overlay->dev; |
Zou Nan hai | 852835f | 2010-05-21 09:08:56 +0800 | [diff] [blame] | 444 | drm_i915_private_t *dev_priv = dev->dev_private; |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 445 | int ret; |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 446 | |
Chris Wilson | b303cf9 | 2010-08-12 14:03:48 +0100 | [diff] [blame] | 447 | if (overlay->last_flip_req == 0) |
| 448 | return 0; |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 449 | |
Ben Widawsky | b93f9cf | 2012-01-25 15:39:34 -0800 | [diff] [blame] | 450 | ret = i915_wait_request(LP_RING(dev_priv), overlay->last_flip_req, |
| 451 | true); |
Chris Wilson | b6c028e | 2010-08-12 11:55:08 +0100 | [diff] [blame] | 452 | if (ret) |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 453 | return ret; |
| 454 | |
Chris Wilson | b303cf9 | 2010-08-12 14:03:48 +0100 | [diff] [blame] | 455 | if (overlay->flip_tail) |
| 456 | overlay->flip_tail(overlay); |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 457 | |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 458 | overlay->last_flip_req = 0; |
| 459 | return 0; |
| 460 | } |
| 461 | |
Daniel Vetter | 5a5a0c6 | 2009-09-15 22:57:36 +0200 | [diff] [blame] | 462 | /* Wait for pending overlay flip and release old frame. |
| 463 | * Needs to be called before the overlay register are changed |
Chris Wilson | 8d74f65 | 2010-08-12 10:35:26 +0100 | [diff] [blame] | 464 | * via intel_overlay_(un)map_regs |
| 465 | */ |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 466 | static int intel_overlay_release_old_vid(struct intel_overlay *overlay) |
| 467 | { |
Chris Wilson | 5cd68c9 | 2010-08-12 12:21:54 +0100 | [diff] [blame] | 468 | struct drm_device *dev = overlay->dev; |
| 469 | drm_i915_private_t *dev_priv = dev->dev_private; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 470 | int ret; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 471 | |
Chris Wilson | 5cd68c9 | 2010-08-12 12:21:54 +0100 | [diff] [blame] | 472 | /* Only wait if there is actually an old frame to release to |
| 473 | * guarantee forward progress. |
| 474 | */ |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 475 | if (!overlay->old_vid_bo) |
| 476 | return 0; |
| 477 | |
Chris Wilson | 5cd68c9 | 2010-08-12 12:21:54 +0100 | [diff] [blame] | 478 | if (I915_READ(ISR) & I915_OVERLAY_PLANE_FLIP_PENDING_INTERRUPT) { |
Chris Wilson | 8dc5d14 | 2010-08-12 12:36:12 +0100 | [diff] [blame] | 479 | struct drm_i915_gem_request *request; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 480 | |
Chris Wilson | 5cd68c9 | 2010-08-12 12:21:54 +0100 | [diff] [blame] | 481 | /* synchronous slowpath */ |
Chris Wilson | 8dc5d14 | 2010-08-12 12:36:12 +0100 | [diff] [blame] | 482 | request = kzalloc(sizeof(*request), GFP_KERNEL); |
| 483 | if (request == NULL) |
| 484 | return -ENOMEM; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 485 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 486 | ret = BEGIN_LP_RING(2); |
| 487 | if (ret) { |
| 488 | kfree(request); |
| 489 | return ret; |
| 490 | } |
| 491 | |
Chris Wilson | 5cd68c9 | 2010-08-12 12:21:54 +0100 | [diff] [blame] | 492 | OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP); |
| 493 | OUT_RING(MI_NOOP); |
| 494 | ADVANCE_LP_RING(); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 495 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 496 | ret = intel_overlay_do_wait_request(overlay, request, |
Chris Wilson | b303cf9 | 2010-08-12 14:03:48 +0100 | [diff] [blame] | 497 | intel_overlay_release_old_vid_tail); |
Chris Wilson | 5cd68c9 | 2010-08-12 12:21:54 +0100 | [diff] [blame] | 498 | if (ret) |
| 499 | return ret; |
| 500 | } |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 501 | |
Chris Wilson | 5cd68c9 | 2010-08-12 12:21:54 +0100 | [diff] [blame] | 502 | intel_overlay_release_old_vid_tail(overlay); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | struct put_image_params { |
| 507 | int format; |
| 508 | short dst_x; |
| 509 | short dst_y; |
| 510 | short dst_w; |
| 511 | short dst_h; |
| 512 | short src_w; |
| 513 | short src_scan_h; |
| 514 | short src_scan_w; |
| 515 | short src_h; |
| 516 | short stride_Y; |
| 517 | short stride_UV; |
| 518 | int offset_Y; |
| 519 | int offset_U; |
| 520 | int offset_V; |
| 521 | }; |
| 522 | |
| 523 | static int packed_depth_bytes(u32 format) |
| 524 | { |
| 525 | switch (format & I915_OVERLAY_DEPTH_MASK) { |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 526 | case I915_OVERLAY_YUV422: |
| 527 | return 4; |
| 528 | case I915_OVERLAY_YUV411: |
| 529 | /* return 6; not implemented */ |
| 530 | default: |
| 531 | return -EINVAL; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 532 | } |
| 533 | } |
| 534 | |
| 535 | static int packed_width_bytes(u32 format, short width) |
| 536 | { |
| 537 | switch (format & I915_OVERLAY_DEPTH_MASK) { |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 538 | case I915_OVERLAY_YUV422: |
| 539 | return width << 1; |
| 540 | default: |
| 541 | return -EINVAL; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | |
| 545 | static int uv_hsubsampling(u32 format) |
| 546 | { |
| 547 | switch (format & I915_OVERLAY_DEPTH_MASK) { |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 548 | case I915_OVERLAY_YUV422: |
| 549 | case I915_OVERLAY_YUV420: |
| 550 | return 2; |
| 551 | case I915_OVERLAY_YUV411: |
| 552 | case I915_OVERLAY_YUV410: |
| 553 | return 4; |
| 554 | default: |
| 555 | return -EINVAL; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 556 | } |
| 557 | } |
| 558 | |
| 559 | static int uv_vsubsampling(u32 format) |
| 560 | { |
| 561 | switch (format & I915_OVERLAY_DEPTH_MASK) { |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 562 | case I915_OVERLAY_YUV420: |
| 563 | case I915_OVERLAY_YUV410: |
| 564 | return 2; |
| 565 | case I915_OVERLAY_YUV422: |
| 566 | case I915_OVERLAY_YUV411: |
| 567 | return 1; |
| 568 | default: |
| 569 | return -EINVAL; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 570 | } |
| 571 | } |
| 572 | |
| 573 | static u32 calc_swidthsw(struct drm_device *dev, u32 offset, u32 width) |
| 574 | { |
| 575 | u32 mask, shift, ret; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 576 | if (IS_GEN2(dev)) { |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 577 | mask = 0x1f; |
| 578 | shift = 5; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 579 | } else { |
| 580 | mask = 0x3f; |
| 581 | shift = 6; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 582 | } |
| 583 | ret = ((offset + width + mask) >> shift) - (offset >> shift); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 584 | if (!IS_GEN2(dev)) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 585 | ret <<= 1; |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 586 | ret -= 1; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 587 | return ret << 2; |
| 588 | } |
| 589 | |
| 590 | static const u16 y_static_hcoeffs[N_HORIZ_Y_TAPS * N_PHASES] = { |
| 591 | 0x3000, 0xb4a0, 0x1930, 0x1920, 0xb4a0, |
| 592 | 0x3000, 0xb500, 0x19d0, 0x1880, 0xb440, |
| 593 | 0x3000, 0xb540, 0x1a88, 0x2f80, 0xb3e0, |
| 594 | 0x3000, 0xb580, 0x1b30, 0x2e20, 0xb380, |
| 595 | 0x3000, 0xb5c0, 0x1bd8, 0x2cc0, 0xb320, |
| 596 | 0x3020, 0xb5e0, 0x1c60, 0x2b80, 0xb2c0, |
| 597 | 0x3020, 0xb5e0, 0x1cf8, 0x2a20, 0xb260, |
| 598 | 0x3020, 0xb5e0, 0x1d80, 0x28e0, 0xb200, |
| 599 | 0x3020, 0xb5c0, 0x1e08, 0x3f40, 0xb1c0, |
| 600 | 0x3020, 0xb580, 0x1e78, 0x3ce0, 0xb160, |
| 601 | 0x3040, 0xb520, 0x1ed8, 0x3aa0, 0xb120, |
| 602 | 0x3040, 0xb4a0, 0x1f30, 0x3880, 0xb0e0, |
| 603 | 0x3040, 0xb400, 0x1f78, 0x3680, 0xb0a0, |
| 604 | 0x3020, 0xb340, 0x1fb8, 0x34a0, 0xb060, |
| 605 | 0x3020, 0xb240, 0x1fe0, 0x32e0, 0xb040, |
| 606 | 0x3020, 0xb140, 0x1ff8, 0x3160, 0xb020, |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 607 | 0xb000, 0x3000, 0x0800, 0x3000, 0xb000 |
| 608 | }; |
| 609 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 610 | static const u16 uv_static_hcoeffs[N_HORIZ_UV_TAPS * N_PHASES] = { |
| 611 | 0x3000, 0x1800, 0x1800, 0xb000, 0x18d0, 0x2e60, |
| 612 | 0xb000, 0x1990, 0x2ce0, 0xb020, 0x1a68, 0x2b40, |
| 613 | 0xb040, 0x1b20, 0x29e0, 0xb060, 0x1bd8, 0x2880, |
| 614 | 0xb080, 0x1c88, 0x3e60, 0xb0a0, 0x1d28, 0x3c00, |
| 615 | 0xb0c0, 0x1db8, 0x39e0, 0xb0e0, 0x1e40, 0x37e0, |
| 616 | 0xb100, 0x1eb8, 0x3620, 0xb100, 0x1f18, 0x34a0, |
| 617 | 0xb100, 0x1f68, 0x3360, 0xb0e0, 0x1fa8, 0x3240, |
| 618 | 0xb0c0, 0x1fe0, 0x3140, 0xb060, 0x1ff0, 0x30a0, |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 619 | 0x3000, 0x0800, 0x3000 |
| 620 | }; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 621 | |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 622 | static void update_polyphase_filter(struct overlay_registers __iomem *regs) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 623 | { |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 624 | memcpy_toio(regs->Y_HCOEFS, y_static_hcoeffs, sizeof(y_static_hcoeffs)); |
| 625 | memcpy_toio(regs->UV_HCOEFS, uv_static_hcoeffs, |
| 626 | sizeof(uv_static_hcoeffs)); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | static bool update_scaling_factors(struct intel_overlay *overlay, |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 630 | struct overlay_registers __iomem *regs, |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 631 | struct put_image_params *params) |
| 632 | { |
| 633 | /* fixed point with a 12 bit shift */ |
| 634 | u32 xscale, yscale, xscale_UV, yscale_UV; |
| 635 | #define FP_SHIFT 12 |
| 636 | #define FRACT_MASK 0xfff |
| 637 | bool scale_changed = false; |
| 638 | int uv_hscale = uv_hsubsampling(params->format); |
| 639 | int uv_vscale = uv_vsubsampling(params->format); |
| 640 | |
| 641 | if (params->dst_w > 1) |
| 642 | xscale = ((params->src_scan_w - 1) << FP_SHIFT) |
| 643 | /(params->dst_w); |
| 644 | else |
| 645 | xscale = 1 << FP_SHIFT; |
| 646 | |
| 647 | if (params->dst_h > 1) |
| 648 | yscale = ((params->src_scan_h - 1) << FP_SHIFT) |
| 649 | /(params->dst_h); |
| 650 | else |
| 651 | yscale = 1 << FP_SHIFT; |
| 652 | |
| 653 | /*if (params->format & I915_OVERLAY_YUV_PLANAR) {*/ |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 654 | xscale_UV = xscale/uv_hscale; |
| 655 | yscale_UV = yscale/uv_vscale; |
| 656 | /* make the Y scale to UV scale ratio an exact multiply */ |
| 657 | xscale = xscale_UV * uv_hscale; |
| 658 | yscale = yscale_UV * uv_vscale; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 659 | /*} else { |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 660 | xscale_UV = 0; |
| 661 | yscale_UV = 0; |
| 662 | }*/ |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 663 | |
| 664 | if (xscale != overlay->old_xscale || yscale != overlay->old_yscale) |
| 665 | scale_changed = true; |
| 666 | overlay->old_xscale = xscale; |
| 667 | overlay->old_yscale = yscale; |
| 668 | |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 669 | iowrite32(((yscale & FRACT_MASK) << 20) | |
| 670 | ((xscale >> FP_SHIFT) << 16) | |
| 671 | ((xscale & FRACT_MASK) << 3), |
| 672 | ®s->YRGBSCALE); |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 673 | |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 674 | iowrite32(((yscale_UV & FRACT_MASK) << 20) | |
| 675 | ((xscale_UV >> FP_SHIFT) << 16) | |
| 676 | ((xscale_UV & FRACT_MASK) << 3), |
| 677 | ®s->UVSCALE); |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 678 | |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 679 | iowrite32((((yscale >> FP_SHIFT) << 16) | |
| 680 | ((yscale_UV >> FP_SHIFT) << 0)), |
| 681 | ®s->UVSCALEV); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 682 | |
| 683 | if (scale_changed) |
| 684 | update_polyphase_filter(regs); |
| 685 | |
| 686 | return scale_changed; |
| 687 | } |
| 688 | |
| 689 | static void update_colorkey(struct intel_overlay *overlay, |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 690 | struct overlay_registers __iomem *regs) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 691 | { |
| 692 | u32 key = overlay->color_key; |
Chris Wilson | 6ba3ddd | 2010-08-12 09:30:58 +0100 | [diff] [blame] | 693 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 694 | switch (overlay->crtc->base.fb->bits_per_pixel) { |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 695 | case 8: |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 696 | iowrite32(0, ®s->DCLRKV); |
| 697 | iowrite32(CLK_RGB8I_MASK | DST_KEY_ENABLE, ®s->DCLRKM); |
Chris Wilson | 6ba3ddd | 2010-08-12 09:30:58 +0100 | [diff] [blame] | 698 | break; |
| 699 | |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 700 | case 16: |
| 701 | if (overlay->crtc->base.fb->depth == 15) { |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 702 | iowrite32(RGB15_TO_COLORKEY(key), ®s->DCLRKV); |
| 703 | iowrite32(CLK_RGB15_MASK | DST_KEY_ENABLE, |
| 704 | ®s->DCLRKM); |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 705 | } else { |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 706 | iowrite32(RGB16_TO_COLORKEY(key), ®s->DCLRKV); |
| 707 | iowrite32(CLK_RGB16_MASK | DST_KEY_ENABLE, |
| 708 | ®s->DCLRKM); |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 709 | } |
Chris Wilson | 6ba3ddd | 2010-08-12 09:30:58 +0100 | [diff] [blame] | 710 | break; |
| 711 | |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 712 | case 24: |
| 713 | case 32: |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 714 | iowrite32(key, ®s->DCLRKV); |
| 715 | iowrite32(CLK_RGB24_MASK | DST_KEY_ENABLE, ®s->DCLRKM); |
Chris Wilson | 6ba3ddd | 2010-08-12 09:30:58 +0100 | [diff] [blame] | 716 | break; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 717 | } |
| 718 | } |
| 719 | |
| 720 | static u32 overlay_cmd_reg(struct put_image_params *params) |
| 721 | { |
| 722 | u32 cmd = OCMD_ENABLE | OCMD_BUF_TYPE_FRAME | OCMD_BUFFER0; |
| 723 | |
| 724 | if (params->format & I915_OVERLAY_YUV_PLANAR) { |
| 725 | switch (params->format & I915_OVERLAY_DEPTH_MASK) { |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 726 | case I915_OVERLAY_YUV422: |
| 727 | cmd |= OCMD_YUV_422_PLANAR; |
| 728 | break; |
| 729 | case I915_OVERLAY_YUV420: |
| 730 | cmd |= OCMD_YUV_420_PLANAR; |
| 731 | break; |
| 732 | case I915_OVERLAY_YUV411: |
| 733 | case I915_OVERLAY_YUV410: |
| 734 | cmd |= OCMD_YUV_410_PLANAR; |
| 735 | break; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 736 | } |
| 737 | } else { /* YUV packed */ |
| 738 | switch (params->format & I915_OVERLAY_DEPTH_MASK) { |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 739 | case I915_OVERLAY_YUV422: |
| 740 | cmd |= OCMD_YUV_422_PACKED; |
| 741 | break; |
| 742 | case I915_OVERLAY_YUV411: |
| 743 | cmd |= OCMD_YUV_411_PACKED; |
| 744 | break; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | switch (params->format & I915_OVERLAY_SWAP_MASK) { |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 748 | case I915_OVERLAY_NO_SWAP: |
| 749 | break; |
| 750 | case I915_OVERLAY_UV_SWAP: |
| 751 | cmd |= OCMD_UV_SWAP; |
| 752 | break; |
| 753 | case I915_OVERLAY_Y_SWAP: |
| 754 | cmd |= OCMD_Y_SWAP; |
| 755 | break; |
| 756 | case I915_OVERLAY_Y_AND_UV_SWAP: |
| 757 | cmd |= OCMD_Y_AND_UV_SWAP; |
| 758 | break; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 759 | } |
| 760 | } |
| 761 | |
| 762 | return cmd; |
| 763 | } |
| 764 | |
Chris Wilson | 5fe82c5 | 2010-08-12 12:38:21 +0100 | [diff] [blame] | 765 | static int intel_overlay_do_put_image(struct intel_overlay *overlay, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 766 | struct drm_i915_gem_object *new_bo, |
Chris Wilson | 5fe82c5 | 2010-08-12 12:38:21 +0100 | [diff] [blame] | 767 | struct put_image_params *params) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 768 | { |
| 769 | int ret, tmp_width; |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 770 | struct overlay_registers __iomem *regs; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 771 | bool scale_changed = false; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 772 | struct drm_device *dev = overlay->dev; |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 773 | u32 swidth, swidthsw, sheight, ostride; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 774 | |
| 775 | BUG_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 776 | BUG_ON(!mutex_is_locked(&dev->mode_config.mutex)); |
| 777 | BUG_ON(!overlay); |
| 778 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 779 | ret = intel_overlay_release_old_vid(overlay); |
| 780 | if (ret != 0) |
| 781 | return ret; |
| 782 | |
Chris Wilson | 2da3b9b | 2011-04-14 09:41:17 +0100 | [diff] [blame] | 783 | ret = i915_gem_object_pin_to_display_plane(new_bo, 0, NULL); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 784 | if (ret != 0) |
| 785 | return ret; |
| 786 | |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 787 | ret = i915_gem_object_put_fence(new_bo); |
| 788 | if (ret) |
| 789 | goto out_unpin; |
| 790 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 791 | if (!overlay->active) { |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 792 | u32 oconfig; |
Chris Wilson | 8d74f65 | 2010-08-12 10:35:26 +0100 | [diff] [blame] | 793 | regs = intel_overlay_map_regs(overlay); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 794 | if (!regs) { |
| 795 | ret = -ENOMEM; |
| 796 | goto out_unpin; |
| 797 | } |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 798 | oconfig = OCONF_CC_OUT_8BIT; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 799 | if (IS_GEN4(overlay->dev)) |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 800 | oconfig |= OCONF_CSC_MODE_BT709; |
| 801 | oconfig |= overlay->crtc->pipe == 0 ? |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 802 | OCONF_PIPE_A : OCONF_PIPE_B; |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 803 | iowrite32(oconfig, ®s->OCONFIG); |
Chris Wilson | 9bb2ff7 | 2010-08-12 12:02:11 +0100 | [diff] [blame] | 804 | intel_overlay_unmap_regs(overlay, regs); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 805 | |
| 806 | ret = intel_overlay_on(overlay); |
| 807 | if (ret != 0) |
| 808 | goto out_unpin; |
| 809 | } |
| 810 | |
Chris Wilson | 8d74f65 | 2010-08-12 10:35:26 +0100 | [diff] [blame] | 811 | regs = intel_overlay_map_regs(overlay); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 812 | if (!regs) { |
| 813 | ret = -ENOMEM; |
| 814 | goto out_unpin; |
| 815 | } |
| 816 | |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 817 | iowrite32((params->dst_y << 16) | params->dst_x, ®s->DWINPOS); |
| 818 | iowrite32((params->dst_h << 16) | params->dst_w, ®s->DWINSZ); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 819 | |
| 820 | if (params->format & I915_OVERLAY_YUV_PACKED) |
| 821 | tmp_width = packed_width_bytes(params->format, params->src_w); |
| 822 | else |
| 823 | tmp_width = params->src_w; |
| 824 | |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 825 | swidth = params->src_w; |
| 826 | swidthsw = calc_swidthsw(overlay->dev, params->offset_Y, tmp_width); |
| 827 | sheight = params->src_h; |
| 828 | iowrite32(new_bo->gtt_offset + params->offset_Y, ®s->OBUF_0Y); |
| 829 | ostride = params->stride_Y; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 830 | |
| 831 | if (params->format & I915_OVERLAY_YUV_PLANAR) { |
| 832 | int uv_hscale = uv_hsubsampling(params->format); |
| 833 | int uv_vscale = uv_vsubsampling(params->format); |
| 834 | u32 tmp_U, tmp_V; |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 835 | swidth |= (params->src_w/uv_hscale) << 16; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 836 | tmp_U = calc_swidthsw(overlay->dev, params->offset_U, |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 837 | params->src_w/uv_hscale); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 838 | tmp_V = calc_swidthsw(overlay->dev, params->offset_V, |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 839 | params->src_w/uv_hscale); |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 840 | swidthsw |= max_t(u32, tmp_U, tmp_V) << 16; |
| 841 | sheight |= (params->src_h/uv_vscale) << 16; |
| 842 | iowrite32(new_bo->gtt_offset + params->offset_U, ®s->OBUF_0U); |
| 843 | iowrite32(new_bo->gtt_offset + params->offset_V, ®s->OBUF_0V); |
| 844 | ostride |= params->stride_UV << 16; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 845 | } |
| 846 | |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 847 | iowrite32(swidth, ®s->SWIDTH); |
| 848 | iowrite32(swidthsw, ®s->SWIDTHSW); |
| 849 | iowrite32(sheight, ®s->SHEIGHT); |
| 850 | iowrite32(ostride, ®s->OSTRIDE); |
| 851 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 852 | scale_changed = update_scaling_factors(overlay, regs, params); |
| 853 | |
| 854 | update_colorkey(overlay, regs); |
| 855 | |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 856 | iowrite32(overlay_cmd_reg(params), ®s->OCMD); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 857 | |
Chris Wilson | 9bb2ff7 | 2010-08-12 12:02:11 +0100 | [diff] [blame] | 858 | intel_overlay_unmap_regs(overlay, regs); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 859 | |
Chris Wilson | 8dc5d14 | 2010-08-12 12:36:12 +0100 | [diff] [blame] | 860 | ret = intel_overlay_continue(overlay, scale_changed); |
| 861 | if (ret) |
| 862 | goto out_unpin; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 863 | |
| 864 | overlay->old_vid_bo = overlay->vid_bo; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 865 | overlay->vid_bo = new_bo; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 866 | |
| 867 | return 0; |
| 868 | |
| 869 | out_unpin: |
| 870 | i915_gem_object_unpin(new_bo); |
| 871 | return ret; |
| 872 | } |
| 873 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 874 | int intel_overlay_switch_off(struct intel_overlay *overlay) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 875 | { |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 876 | struct overlay_registers __iomem *regs; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 877 | struct drm_device *dev = overlay->dev; |
Chris Wilson | 5dcdbcb | 2010-08-12 13:50:28 +0100 | [diff] [blame] | 878 | int ret; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 879 | |
| 880 | BUG_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 881 | BUG_ON(!mutex_is_locked(&dev->mode_config.mutex)); |
| 882 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 883 | ret = intel_overlay_recover_from_interrupt(overlay); |
Chris Wilson | b303cf9 | 2010-08-12 14:03:48 +0100 | [diff] [blame] | 884 | if (ret != 0) |
| 885 | return ret; |
Daniel Vetter | 9bedb97 | 2009-11-30 15:55:49 +0100 | [diff] [blame] | 886 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 887 | if (!overlay->active) |
| 888 | return 0; |
| 889 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 890 | ret = intel_overlay_release_old_vid(overlay); |
| 891 | if (ret != 0) |
| 892 | return ret; |
| 893 | |
Chris Wilson | 8d74f65 | 2010-08-12 10:35:26 +0100 | [diff] [blame] | 894 | regs = intel_overlay_map_regs(overlay); |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 895 | iowrite32(0, ®s->OCMD); |
Chris Wilson | 9bb2ff7 | 2010-08-12 12:02:11 +0100 | [diff] [blame] | 896 | intel_overlay_unmap_regs(overlay, regs); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 897 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 898 | ret = intel_overlay_off(overlay); |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 899 | if (ret != 0) |
| 900 | return ret; |
| 901 | |
Daniel Vetter | 12ca45f | 2037-04-25 10:08:26 +0200 | [diff] [blame] | 902 | intel_overlay_off_tail(overlay); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 903 | return 0; |
| 904 | } |
| 905 | |
| 906 | static int check_overlay_possible_on_crtc(struct intel_overlay *overlay, |
| 907 | struct intel_crtc *crtc) |
| 908 | { |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 909 | drm_i915_private_t *dev_priv = overlay->dev->dev_private; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 910 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 911 | if (!crtc->active) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 912 | return -EINVAL; |
| 913 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 914 | /* can't use the overlay with double wide pipe */ |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 915 | if (INTEL_INFO(overlay->dev)->gen < 4 && |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 916 | (I915_READ(PIPECONF(crtc->pipe)) & (PIPECONF_DOUBLE_WIDE | PIPECONF_ENABLE)) != PIPECONF_ENABLE) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 917 | return -EINVAL; |
| 918 | |
| 919 | return 0; |
| 920 | } |
| 921 | |
| 922 | static void update_pfit_vscale_ratio(struct intel_overlay *overlay) |
| 923 | { |
| 924 | struct drm_device *dev = overlay->dev; |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 925 | drm_i915_private_t *dev_priv = dev->dev_private; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 926 | u32 pfit_control = I915_READ(PFIT_CONTROL); |
Chris Wilson | 446d218 | 2010-08-12 11:15:58 +0100 | [diff] [blame] | 927 | u32 ratio; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 928 | |
| 929 | /* XXX: This is not the same logic as in the xorg driver, but more in |
Chris Wilson | 446d218 | 2010-08-12 11:15:58 +0100 | [diff] [blame] | 930 | * line with the intel documentation for the i965 |
| 931 | */ |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 932 | if (INTEL_INFO(dev)->gen >= 4) { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 933 | /* on i965 use the PGM reg to read out the autoscaler values */ |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 934 | ratio = I915_READ(PFIT_PGM_RATIOS) >> PFIT_VERT_SCALE_SHIFT_965; |
| 935 | } else { |
Chris Wilson | 446d218 | 2010-08-12 11:15:58 +0100 | [diff] [blame] | 936 | if (pfit_control & VERT_AUTO_SCALE) |
| 937 | ratio = I915_READ(PFIT_AUTO_RATIOS); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 938 | else |
Chris Wilson | 446d218 | 2010-08-12 11:15:58 +0100 | [diff] [blame] | 939 | ratio = I915_READ(PFIT_PGM_RATIOS); |
| 940 | ratio >>= PFIT_VERT_SCALE_SHIFT; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | overlay->pfit_vscale_ratio = ratio; |
| 944 | } |
| 945 | |
| 946 | static int check_overlay_dst(struct intel_overlay *overlay, |
| 947 | struct drm_intel_overlay_put_image *rec) |
| 948 | { |
| 949 | struct drm_display_mode *mode = &overlay->crtc->base.mode; |
| 950 | |
Daniel Vetter | 75c1399 | 2012-01-28 23:48:46 +0100 | [diff] [blame] | 951 | if (rec->dst_x < mode->hdisplay && |
| 952 | rec->dst_x + rec->dst_width <= mode->hdisplay && |
| 953 | rec->dst_y < mode->vdisplay && |
| 954 | rec->dst_y + rec->dst_height <= mode->vdisplay) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 955 | return 0; |
| 956 | else |
| 957 | return -EINVAL; |
| 958 | } |
| 959 | |
| 960 | static int check_overlay_scaling(struct put_image_params *rec) |
| 961 | { |
| 962 | u32 tmp; |
| 963 | |
| 964 | /* downscaling limit is 8.0 */ |
| 965 | tmp = ((rec->src_scan_h << 16) / rec->dst_h) >> 16; |
| 966 | if (tmp > 7) |
| 967 | return -EINVAL; |
| 968 | tmp = ((rec->src_scan_w << 16) / rec->dst_w) >> 16; |
| 969 | if (tmp > 7) |
| 970 | return -EINVAL; |
| 971 | |
| 972 | return 0; |
| 973 | } |
| 974 | |
| 975 | static int check_overlay_src(struct drm_device *dev, |
| 976 | struct drm_intel_overlay_put_image *rec, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 977 | struct drm_i915_gem_object *new_bo) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 978 | { |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 979 | int uv_hscale = uv_hsubsampling(rec->flags); |
| 980 | int uv_vscale = uv_vsubsampling(rec->flags); |
Dan Carpenter | 8f28f54 | 2010-10-27 23:17:25 +0200 | [diff] [blame] | 981 | u32 stride_mask; |
| 982 | int depth; |
| 983 | u32 tmp; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 984 | |
| 985 | /* check src dimensions */ |
| 986 | if (IS_845G(dev) || IS_I830(dev)) { |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 987 | if (rec->src_height > IMAGE_MAX_HEIGHT_LEGACY || |
Chris Wilson | 9f7c3f4 | 2010-08-12 11:29:34 +0100 | [diff] [blame] | 988 | rec->src_width > IMAGE_MAX_WIDTH_LEGACY) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 989 | return -EINVAL; |
| 990 | } else { |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 991 | if (rec->src_height > IMAGE_MAX_HEIGHT || |
Chris Wilson | 9f7c3f4 | 2010-08-12 11:29:34 +0100 | [diff] [blame] | 992 | rec->src_width > IMAGE_MAX_WIDTH) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 993 | return -EINVAL; |
| 994 | } |
Chris Wilson | 9f7c3f4 | 2010-08-12 11:29:34 +0100 | [diff] [blame] | 995 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 996 | /* better safe than sorry, use 4 as the maximal subsampling ratio */ |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 997 | if (rec->src_height < N_VERT_Y_TAPS*4 || |
Chris Wilson | 9f7c3f4 | 2010-08-12 11:29:34 +0100 | [diff] [blame] | 998 | rec->src_width < N_HORIZ_Y_TAPS*4) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 999 | return -EINVAL; |
| 1000 | |
Chris Wilson | a1efd14 | 2010-07-12 19:35:38 +0100 | [diff] [blame] | 1001 | /* check alignment constraints */ |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1002 | switch (rec->flags & I915_OVERLAY_TYPE_MASK) { |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1003 | case I915_OVERLAY_RGB: |
| 1004 | /* not implemented */ |
| 1005 | return -EINVAL; |
Chris Wilson | 9f7c3f4 | 2010-08-12 11:29:34 +0100 | [diff] [blame] | 1006 | |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1007 | case I915_OVERLAY_YUV_PACKED: |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1008 | if (uv_vscale != 1) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1009 | return -EINVAL; |
Chris Wilson | 9f7c3f4 | 2010-08-12 11:29:34 +0100 | [diff] [blame] | 1010 | |
| 1011 | depth = packed_depth_bytes(rec->flags); |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1012 | if (depth < 0) |
| 1013 | return depth; |
Chris Wilson | 9f7c3f4 | 2010-08-12 11:29:34 +0100 | [diff] [blame] | 1014 | |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1015 | /* ignore UV planes */ |
| 1016 | rec->stride_UV = 0; |
| 1017 | rec->offset_U = 0; |
| 1018 | rec->offset_V = 0; |
| 1019 | /* check pixel alignment */ |
| 1020 | if (rec->offset_Y % depth) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1021 | return -EINVAL; |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1022 | break; |
Chris Wilson | 9f7c3f4 | 2010-08-12 11:29:34 +0100 | [diff] [blame] | 1023 | |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1024 | case I915_OVERLAY_YUV_PLANAR: |
| 1025 | if (uv_vscale < 0 || uv_hscale < 0) |
| 1026 | return -EINVAL; |
| 1027 | /* no offset restrictions for planar formats */ |
| 1028 | break; |
Chris Wilson | 9f7c3f4 | 2010-08-12 11:29:34 +0100 | [diff] [blame] | 1029 | |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1030 | default: |
| 1031 | return -EINVAL; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | if (rec->src_width % uv_hscale) |
| 1035 | return -EINVAL; |
| 1036 | |
| 1037 | /* stride checking */ |
Chris Wilson | a1efd14 | 2010-07-12 19:35:38 +0100 | [diff] [blame] | 1038 | if (IS_I830(dev) || IS_845G(dev)) |
| 1039 | stride_mask = 255; |
| 1040 | else |
| 1041 | stride_mask = 63; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1042 | |
| 1043 | if (rec->stride_Y & stride_mask || rec->stride_UV & stride_mask) |
| 1044 | return -EINVAL; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1045 | if (IS_GEN4(dev) && rec->stride_Y < 512) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1046 | return -EINVAL; |
| 1047 | |
| 1048 | tmp = (rec->flags & I915_OVERLAY_TYPE_MASK) == I915_OVERLAY_YUV_PLANAR ? |
Chris Wilson | 9f7c3f4 | 2010-08-12 11:29:34 +0100 | [diff] [blame] | 1049 | 4096 : 8192; |
| 1050 | if (rec->stride_Y > tmp || rec->stride_UV > 2*1024) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1051 | return -EINVAL; |
| 1052 | |
| 1053 | /* check buffer dimensions */ |
| 1054 | switch (rec->flags & I915_OVERLAY_TYPE_MASK) { |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1055 | case I915_OVERLAY_RGB: |
| 1056 | case I915_OVERLAY_YUV_PACKED: |
| 1057 | /* always 4 Y values per depth pixels */ |
| 1058 | if (packed_width_bytes(rec->flags, rec->src_width) > rec->stride_Y) |
| 1059 | return -EINVAL; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1060 | |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1061 | tmp = rec->stride_Y*rec->src_height; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1062 | if (rec->offset_Y + tmp > new_bo->base.size) |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1063 | return -EINVAL; |
| 1064 | break; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1065 | |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1066 | case I915_OVERLAY_YUV_PLANAR: |
| 1067 | if (rec->src_width > rec->stride_Y) |
| 1068 | return -EINVAL; |
| 1069 | if (rec->src_width/uv_hscale > rec->stride_UV) |
| 1070 | return -EINVAL; |
| 1071 | |
Chris Wilson | 9f7c3f4 | 2010-08-12 11:29:34 +0100 | [diff] [blame] | 1072 | tmp = rec->stride_Y * rec->src_height; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1073 | if (rec->offset_Y + tmp > new_bo->base.size) |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1074 | return -EINVAL; |
Chris Wilson | 9f7c3f4 | 2010-08-12 11:29:34 +0100 | [diff] [blame] | 1075 | |
| 1076 | tmp = rec->stride_UV * (rec->src_height / uv_vscale); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1077 | if (rec->offset_U + tmp > new_bo->base.size || |
| 1078 | rec->offset_V + tmp > new_bo->base.size) |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1079 | return -EINVAL; |
| 1080 | break; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | return 0; |
| 1084 | } |
| 1085 | |
Chris Wilson | e9e331a | 2010-09-13 01:16:10 +0100 | [diff] [blame] | 1086 | /** |
| 1087 | * Return the pipe currently connected to the panel fitter, |
| 1088 | * or -1 if the panel fitter is not present or not in use |
| 1089 | */ |
| 1090 | static int intel_panel_fitter_pipe(struct drm_device *dev) |
| 1091 | { |
| 1092 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1093 | u32 pfit_control; |
| 1094 | |
| 1095 | /* i830 doesn't have a panel fitter */ |
| 1096 | if (IS_I830(dev)) |
| 1097 | return -1; |
| 1098 | |
| 1099 | pfit_control = I915_READ(PFIT_CONTROL); |
| 1100 | |
| 1101 | /* See if the panel fitter is in use */ |
| 1102 | if ((pfit_control & PFIT_ENABLE) == 0) |
| 1103 | return -1; |
| 1104 | |
| 1105 | /* 965 can place panel fitter on either pipe */ |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1106 | if (IS_GEN4(dev)) |
Chris Wilson | e9e331a | 2010-09-13 01:16:10 +0100 | [diff] [blame] | 1107 | return (pfit_control >> 29) & 0x3; |
| 1108 | |
| 1109 | /* older chips can only use pipe 1 */ |
| 1110 | return 1; |
| 1111 | } |
| 1112 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1113 | int intel_overlay_put_image(struct drm_device *dev, void *data, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1114 | struct drm_file *file_priv) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1115 | { |
| 1116 | struct drm_intel_overlay_put_image *put_image_rec = data; |
| 1117 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 1118 | struct intel_overlay *overlay; |
| 1119 | struct drm_mode_object *drmmode_obj; |
| 1120 | struct intel_crtc *crtc; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1121 | struct drm_i915_gem_object *new_bo; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1122 | struct put_image_params *params; |
| 1123 | int ret; |
| 1124 | |
| 1125 | if (!dev_priv) { |
| 1126 | DRM_ERROR("called with no initialization\n"); |
| 1127 | return -EINVAL; |
| 1128 | } |
| 1129 | |
| 1130 | overlay = dev_priv->overlay; |
| 1131 | if (!overlay) { |
| 1132 | DRM_DEBUG("userspace bug: no overlay\n"); |
| 1133 | return -ENODEV; |
| 1134 | } |
| 1135 | |
| 1136 | if (!(put_image_rec->flags & I915_OVERLAY_ENABLE)) { |
| 1137 | mutex_lock(&dev->mode_config.mutex); |
| 1138 | mutex_lock(&dev->struct_mutex); |
| 1139 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 1140 | ret = intel_overlay_switch_off(overlay); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1141 | |
| 1142 | mutex_unlock(&dev->struct_mutex); |
| 1143 | mutex_unlock(&dev->mode_config.mutex); |
| 1144 | |
| 1145 | return ret; |
| 1146 | } |
| 1147 | |
| 1148 | params = kmalloc(sizeof(struct put_image_params), GFP_KERNEL); |
| 1149 | if (!params) |
| 1150 | return -ENOMEM; |
| 1151 | |
| 1152 | drmmode_obj = drm_mode_object_find(dev, put_image_rec->crtc_id, |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1153 | DRM_MODE_OBJECT_CRTC); |
Dan Carpenter | 915a428 | 2010-03-06 14:05:39 +0300 | [diff] [blame] | 1154 | if (!drmmode_obj) { |
| 1155 | ret = -ENOENT; |
| 1156 | goto out_free; |
| 1157 | } |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1158 | crtc = to_intel_crtc(obj_to_crtc(drmmode_obj)); |
| 1159 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1160 | new_bo = to_intel_bo(drm_gem_object_lookup(dev, file_priv, |
| 1161 | put_image_rec->bo_handle)); |
Chris Wilson | c872522 | 2011-02-19 11:31:06 +0000 | [diff] [blame] | 1162 | if (&new_bo->base == NULL) { |
Dan Carpenter | 915a428 | 2010-03-06 14:05:39 +0300 | [diff] [blame] | 1163 | ret = -ENOENT; |
| 1164 | goto out_free; |
| 1165 | } |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1166 | |
| 1167 | mutex_lock(&dev->mode_config.mutex); |
| 1168 | mutex_lock(&dev->struct_mutex); |
| 1169 | |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 1170 | if (new_bo->tiling_mode) { |
| 1171 | DRM_ERROR("buffer used for overlay image can not be tiled\n"); |
| 1172 | ret = -EINVAL; |
| 1173 | goto out_unlock; |
| 1174 | } |
| 1175 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 1176 | ret = intel_overlay_recover_from_interrupt(overlay); |
Chris Wilson | b303cf9 | 2010-08-12 14:03:48 +0100 | [diff] [blame] | 1177 | if (ret != 0) |
| 1178 | goto out_unlock; |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 1179 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1180 | if (overlay->crtc != crtc) { |
| 1181 | struct drm_display_mode *mode = &crtc->base.mode; |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 1182 | ret = intel_overlay_switch_off(overlay); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1183 | if (ret != 0) |
| 1184 | goto out_unlock; |
| 1185 | |
| 1186 | ret = check_overlay_possible_on_crtc(overlay, crtc); |
| 1187 | if (ret != 0) |
| 1188 | goto out_unlock; |
| 1189 | |
| 1190 | overlay->crtc = crtc; |
| 1191 | crtc->overlay = overlay; |
| 1192 | |
Chris Wilson | e9e331a | 2010-09-13 01:16:10 +0100 | [diff] [blame] | 1193 | /* line too wide, i.e. one-line-mode */ |
| 1194 | if (mode->hdisplay > 1024 && |
| 1195 | intel_panel_fitter_pipe(dev) == crtc->pipe) { |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1196 | overlay->pfit_active = 1; |
| 1197 | update_pfit_vscale_ratio(overlay); |
| 1198 | } else |
| 1199 | overlay->pfit_active = 0; |
| 1200 | } |
| 1201 | |
| 1202 | ret = check_overlay_dst(overlay, put_image_rec); |
| 1203 | if (ret != 0) |
| 1204 | goto out_unlock; |
| 1205 | |
| 1206 | if (overlay->pfit_active) { |
| 1207 | params->dst_y = ((((u32)put_image_rec->dst_y) << 12) / |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1208 | overlay->pfit_vscale_ratio); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1209 | /* shifting right rounds downwards, so add 1 */ |
| 1210 | params->dst_h = ((((u32)put_image_rec->dst_height) << 12) / |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1211 | overlay->pfit_vscale_ratio) + 1; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1212 | } else { |
| 1213 | params->dst_y = put_image_rec->dst_y; |
| 1214 | params->dst_h = put_image_rec->dst_height; |
| 1215 | } |
| 1216 | params->dst_x = put_image_rec->dst_x; |
| 1217 | params->dst_w = put_image_rec->dst_width; |
| 1218 | |
| 1219 | params->src_w = put_image_rec->src_width; |
| 1220 | params->src_h = put_image_rec->src_height; |
| 1221 | params->src_scan_w = put_image_rec->src_scan_width; |
| 1222 | params->src_scan_h = put_image_rec->src_scan_height; |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1223 | if (params->src_scan_h > params->src_h || |
| 1224 | params->src_scan_w > params->src_w) { |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1225 | ret = -EINVAL; |
| 1226 | goto out_unlock; |
| 1227 | } |
| 1228 | |
| 1229 | ret = check_overlay_src(dev, put_image_rec, new_bo); |
| 1230 | if (ret != 0) |
| 1231 | goto out_unlock; |
| 1232 | params->format = put_image_rec->flags & ~I915_OVERLAY_FLAGS_MASK; |
| 1233 | params->stride_Y = put_image_rec->stride_Y; |
| 1234 | params->stride_UV = put_image_rec->stride_UV; |
| 1235 | params->offset_Y = put_image_rec->offset_Y; |
| 1236 | params->offset_U = put_image_rec->offset_U; |
| 1237 | params->offset_V = put_image_rec->offset_V; |
| 1238 | |
| 1239 | /* Check scaling after src size to prevent a divide-by-zero. */ |
| 1240 | ret = check_overlay_scaling(params); |
| 1241 | if (ret != 0) |
| 1242 | goto out_unlock; |
| 1243 | |
| 1244 | ret = intel_overlay_do_put_image(overlay, new_bo, params); |
| 1245 | if (ret != 0) |
| 1246 | goto out_unlock; |
| 1247 | |
| 1248 | mutex_unlock(&dev->struct_mutex); |
| 1249 | mutex_unlock(&dev->mode_config.mutex); |
| 1250 | |
| 1251 | kfree(params); |
| 1252 | |
| 1253 | return 0; |
| 1254 | |
| 1255 | out_unlock: |
| 1256 | mutex_unlock(&dev->struct_mutex); |
| 1257 | mutex_unlock(&dev->mode_config.mutex); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1258 | drm_gem_object_unreference_unlocked(&new_bo->base); |
Dan Carpenter | 915a428 | 2010-03-06 14:05:39 +0300 | [diff] [blame] | 1259 | out_free: |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1260 | kfree(params); |
| 1261 | |
| 1262 | return ret; |
| 1263 | } |
| 1264 | |
| 1265 | static void update_reg_attrs(struct intel_overlay *overlay, |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 1266 | struct overlay_registers __iomem *regs) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1267 | { |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 1268 | iowrite32((overlay->contrast << 18) | (overlay->brightness & 0xff), |
| 1269 | ®s->OCLRC0); |
| 1270 | iowrite32(overlay->saturation, ®s->OCLRC1); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | static bool check_gamma_bounds(u32 gamma1, u32 gamma2) |
| 1274 | { |
| 1275 | int i; |
| 1276 | |
| 1277 | if (gamma1 & 0xff000000 || gamma2 & 0xff000000) |
| 1278 | return false; |
| 1279 | |
| 1280 | for (i = 0; i < 3; i++) { |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1281 | if (((gamma1 >> i*8) & 0xff) >= ((gamma2 >> i*8) & 0xff)) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1282 | return false; |
| 1283 | } |
| 1284 | |
| 1285 | return true; |
| 1286 | } |
| 1287 | |
| 1288 | static bool check_gamma5_errata(u32 gamma5) |
| 1289 | { |
| 1290 | int i; |
| 1291 | |
| 1292 | for (i = 0; i < 3; i++) { |
| 1293 | if (((gamma5 >> i*8) & 0xff) == 0x80) |
| 1294 | return false; |
| 1295 | } |
| 1296 | |
| 1297 | return true; |
| 1298 | } |
| 1299 | |
| 1300 | static int check_gamma(struct drm_intel_overlay_attrs *attrs) |
| 1301 | { |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1302 | if (!check_gamma_bounds(0, attrs->gamma0) || |
| 1303 | !check_gamma_bounds(attrs->gamma0, attrs->gamma1) || |
| 1304 | !check_gamma_bounds(attrs->gamma1, attrs->gamma2) || |
| 1305 | !check_gamma_bounds(attrs->gamma2, attrs->gamma3) || |
| 1306 | !check_gamma_bounds(attrs->gamma3, attrs->gamma4) || |
| 1307 | !check_gamma_bounds(attrs->gamma4, attrs->gamma5) || |
| 1308 | !check_gamma_bounds(attrs->gamma5, 0x00ffffff)) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1309 | return -EINVAL; |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1310 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1311 | if (!check_gamma5_errata(attrs->gamma5)) |
| 1312 | return -EINVAL; |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1313 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1314 | return 0; |
| 1315 | } |
| 1316 | |
| 1317 | int intel_overlay_attrs(struct drm_device *dev, void *data, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1318 | struct drm_file *file_priv) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1319 | { |
| 1320 | struct drm_intel_overlay_attrs *attrs = data; |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1321 | drm_i915_private_t *dev_priv = dev->dev_private; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1322 | struct intel_overlay *overlay; |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 1323 | struct overlay_registers __iomem *regs; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1324 | int ret; |
| 1325 | |
| 1326 | if (!dev_priv) { |
| 1327 | DRM_ERROR("called with no initialization\n"); |
| 1328 | return -EINVAL; |
| 1329 | } |
| 1330 | |
| 1331 | overlay = dev_priv->overlay; |
| 1332 | if (!overlay) { |
| 1333 | DRM_DEBUG("userspace bug: no overlay\n"); |
| 1334 | return -ENODEV; |
| 1335 | } |
| 1336 | |
| 1337 | mutex_lock(&dev->mode_config.mutex); |
| 1338 | mutex_lock(&dev->struct_mutex); |
| 1339 | |
Chris Wilson | 60fc332 | 2010-08-12 10:44:45 +0100 | [diff] [blame] | 1340 | ret = -EINVAL; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1341 | if (!(attrs->flags & I915_OVERLAY_UPDATE_ATTRS)) { |
Chris Wilson | 60fc332 | 2010-08-12 10:44:45 +0100 | [diff] [blame] | 1342 | attrs->color_key = overlay->color_key; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1343 | attrs->brightness = overlay->brightness; |
Chris Wilson | 60fc332 | 2010-08-12 10:44:45 +0100 | [diff] [blame] | 1344 | attrs->contrast = overlay->contrast; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1345 | attrs->saturation = overlay->saturation; |
| 1346 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1347 | if (!IS_GEN2(dev)) { |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1348 | attrs->gamma0 = I915_READ(OGAMC0); |
| 1349 | attrs->gamma1 = I915_READ(OGAMC1); |
| 1350 | attrs->gamma2 = I915_READ(OGAMC2); |
| 1351 | attrs->gamma3 = I915_READ(OGAMC3); |
| 1352 | attrs->gamma4 = I915_READ(OGAMC4); |
| 1353 | attrs->gamma5 = I915_READ(OGAMC5); |
| 1354 | } |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1355 | } else { |
Chris Wilson | 60fc332 | 2010-08-12 10:44:45 +0100 | [diff] [blame] | 1356 | if (attrs->brightness < -128 || attrs->brightness > 127) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1357 | goto out_unlock; |
Chris Wilson | 60fc332 | 2010-08-12 10:44:45 +0100 | [diff] [blame] | 1358 | if (attrs->contrast > 255) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1359 | goto out_unlock; |
Chris Wilson | 60fc332 | 2010-08-12 10:44:45 +0100 | [diff] [blame] | 1360 | if (attrs->saturation > 1023) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1361 | goto out_unlock; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1362 | |
Chris Wilson | 60fc332 | 2010-08-12 10:44:45 +0100 | [diff] [blame] | 1363 | overlay->color_key = attrs->color_key; |
| 1364 | overlay->brightness = attrs->brightness; |
| 1365 | overlay->contrast = attrs->contrast; |
| 1366 | overlay->saturation = attrs->saturation; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1367 | |
Chris Wilson | 8d74f65 | 2010-08-12 10:35:26 +0100 | [diff] [blame] | 1368 | regs = intel_overlay_map_regs(overlay); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1369 | if (!regs) { |
| 1370 | ret = -ENOMEM; |
| 1371 | goto out_unlock; |
| 1372 | } |
| 1373 | |
| 1374 | update_reg_attrs(overlay, regs); |
| 1375 | |
Chris Wilson | 9bb2ff7 | 2010-08-12 12:02:11 +0100 | [diff] [blame] | 1376 | intel_overlay_unmap_regs(overlay, regs); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1377 | |
| 1378 | if (attrs->flags & I915_OVERLAY_UPDATE_GAMMA) { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1379 | if (IS_GEN2(dev)) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1380 | goto out_unlock; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1381 | |
| 1382 | if (overlay->active) { |
| 1383 | ret = -EBUSY; |
| 1384 | goto out_unlock; |
| 1385 | } |
| 1386 | |
| 1387 | ret = check_gamma(attrs); |
Chris Wilson | 60fc332 | 2010-08-12 10:44:45 +0100 | [diff] [blame] | 1388 | if (ret) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1389 | goto out_unlock; |
| 1390 | |
| 1391 | I915_WRITE(OGAMC0, attrs->gamma0); |
| 1392 | I915_WRITE(OGAMC1, attrs->gamma1); |
| 1393 | I915_WRITE(OGAMC2, attrs->gamma2); |
| 1394 | I915_WRITE(OGAMC3, attrs->gamma3); |
| 1395 | I915_WRITE(OGAMC4, attrs->gamma4); |
| 1396 | I915_WRITE(OGAMC5, attrs->gamma5); |
| 1397 | } |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1398 | } |
| 1399 | |
Chris Wilson | 60fc332 | 2010-08-12 10:44:45 +0100 | [diff] [blame] | 1400 | ret = 0; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1401 | out_unlock: |
| 1402 | mutex_unlock(&dev->struct_mutex); |
| 1403 | mutex_unlock(&dev->mode_config.mutex); |
| 1404 | |
| 1405 | return ret; |
| 1406 | } |
| 1407 | |
| 1408 | void intel_setup_overlay(struct drm_device *dev) |
| 1409 | { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1410 | drm_i915_private_t *dev_priv = dev->dev_private; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1411 | struct intel_overlay *overlay; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1412 | struct drm_i915_gem_object *reg_bo; |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 1413 | struct overlay_registers __iomem *regs; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1414 | int ret; |
| 1415 | |
Chris Wilson | 31578148 | 2010-08-12 09:42:51 +0100 | [diff] [blame] | 1416 | if (!HAS_OVERLAY(dev)) |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1417 | return; |
| 1418 | |
| 1419 | overlay = kzalloc(sizeof(struct intel_overlay), GFP_KERNEL); |
| 1420 | if (!overlay) |
| 1421 | return; |
Chris Wilson | 79d2427 | 2011-06-28 11:27:47 +0100 | [diff] [blame] | 1422 | |
| 1423 | mutex_lock(&dev->struct_mutex); |
| 1424 | if (WARN_ON(dev_priv->overlay)) |
| 1425 | goto out_free; |
| 1426 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1427 | overlay->dev = dev; |
| 1428 | |
Daniel Vetter | ac52bc5 | 2010-04-09 19:05:06 +0000 | [diff] [blame] | 1429 | reg_bo = i915_gem_alloc_object(dev, PAGE_SIZE); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1430 | if (!reg_bo) |
| 1431 | goto out_free; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1432 | overlay->reg_bo = reg_bo; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1433 | |
Chris Wilson | 31578148 | 2010-08-12 09:42:51 +0100 | [diff] [blame] | 1434 | if (OVERLAY_NEEDS_PHYSICAL(dev)) { |
| 1435 | ret = i915_gem_attach_phys_object(dev, reg_bo, |
| 1436 | I915_GEM_PHYS_OVERLAY_REGS, |
Chris Wilson | a293012 | 2010-08-12 10:47:56 +0100 | [diff] [blame] | 1437 | PAGE_SIZE); |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1438 | if (ret) { |
| 1439 | DRM_ERROR("failed to attach phys overlay regs\n"); |
| 1440 | goto out_free_bo; |
| 1441 | } |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1442 | overlay->flip_addr = reg_bo->phys_obj->handle->busaddr; |
Chris Wilson | 31578148 | 2010-08-12 09:42:51 +0100 | [diff] [blame] | 1443 | } else { |
Daniel Vetter | 75e9e91 | 2010-11-04 17:11:09 +0100 | [diff] [blame] | 1444 | ret = i915_gem_object_pin(reg_bo, PAGE_SIZE, true); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1445 | if (ret) { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1446 | DRM_ERROR("failed to pin overlay register bo\n"); |
| 1447 | goto out_free_bo; |
| 1448 | } |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1449 | overlay->flip_addr = reg_bo->gtt_offset; |
Chris Wilson | 0ddc128 | 2010-08-12 09:35:00 +0100 | [diff] [blame] | 1450 | |
| 1451 | ret = i915_gem_object_set_to_gtt_domain(reg_bo, true); |
| 1452 | if (ret) { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1453 | DRM_ERROR("failed to move overlay register bo into the GTT\n"); |
| 1454 | goto out_unpin_bo; |
| 1455 | } |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | /* init all values */ |
| 1459 | overlay->color_key = 0x0101fe; |
| 1460 | overlay->brightness = -19; |
| 1461 | overlay->contrast = 75; |
| 1462 | overlay->saturation = 146; |
| 1463 | |
Chris Wilson | 8d74f65 | 2010-08-12 10:35:26 +0100 | [diff] [blame] | 1464 | regs = intel_overlay_map_regs(overlay); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1465 | if (!regs) |
Chris Wilson | 79d2427 | 2011-06-28 11:27:47 +0100 | [diff] [blame] | 1466 | goto out_unpin_bo; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1467 | |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 1468 | memset_io(regs, 0, sizeof(struct overlay_registers)); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1469 | update_polyphase_filter(regs); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1470 | update_reg_attrs(overlay, regs); |
| 1471 | |
Chris Wilson | 9bb2ff7 | 2010-08-12 12:02:11 +0100 | [diff] [blame] | 1472 | intel_overlay_unmap_regs(overlay, regs); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1473 | |
| 1474 | dev_priv->overlay = overlay; |
Chris Wilson | 79d2427 | 2011-06-28 11:27:47 +0100 | [diff] [blame] | 1475 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1476 | DRM_INFO("initialized overlay support\n"); |
| 1477 | return; |
| 1478 | |
Chris Wilson | 0ddc128 | 2010-08-12 09:35:00 +0100 | [diff] [blame] | 1479 | out_unpin_bo: |
Chris Wilson | 79d2427 | 2011-06-28 11:27:47 +0100 | [diff] [blame] | 1480 | if (!OVERLAY_NEEDS_PHYSICAL(dev)) |
| 1481 | i915_gem_object_unpin(reg_bo); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1482 | out_free_bo: |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1483 | drm_gem_object_unreference(®_bo->base); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1484 | out_free: |
Chris Wilson | 79d2427 | 2011-06-28 11:27:47 +0100 | [diff] [blame] | 1485 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1486 | kfree(overlay); |
| 1487 | return; |
| 1488 | } |
| 1489 | |
| 1490 | void intel_cleanup_overlay(struct drm_device *dev) |
| 1491 | { |
Chris Wilson | 722506f | 2010-08-12 09:28:50 +0100 | [diff] [blame] | 1492 | drm_i915_private_t *dev_priv = dev->dev_private; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1493 | |
Chris Wilson | 62cf4e6 | 2010-08-12 10:50:36 +0100 | [diff] [blame] | 1494 | if (!dev_priv->overlay) |
| 1495 | return; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1496 | |
Chris Wilson | 62cf4e6 | 2010-08-12 10:50:36 +0100 | [diff] [blame] | 1497 | /* The bo's should be free'd by the generic code already. |
| 1498 | * Furthermore modesetting teardown happens beforehand so the |
| 1499 | * hardware should be off already */ |
| 1500 | BUG_ON(dev_priv->overlay->active); |
| 1501 | |
| 1502 | drm_gem_object_unreference_unlocked(&dev_priv->overlay->reg_bo->base); |
| 1503 | kfree(dev_priv->overlay); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1504 | } |
Chris Wilson | 6ef3d42 | 2010-08-04 20:26:07 +0100 | [diff] [blame] | 1505 | |
Chris Wilson | 3bd3c93 | 2010-08-19 08:19:30 +0100 | [diff] [blame] | 1506 | #ifdef CONFIG_DEBUG_FS |
| 1507 | #include <linux/seq_file.h> |
| 1508 | |
Chris Wilson | 6ef3d42 | 2010-08-04 20:26:07 +0100 | [diff] [blame] | 1509 | struct intel_overlay_error_state { |
| 1510 | struct overlay_registers regs; |
| 1511 | unsigned long base; |
| 1512 | u32 dovsta; |
| 1513 | u32 isr; |
| 1514 | }; |
| 1515 | |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 1516 | static struct overlay_registers __iomem * |
Linus Torvalds | c48c43e | 2010-10-26 18:57:59 -0700 | [diff] [blame] | 1517 | intel_overlay_map_regs_atomic(struct intel_overlay *overlay) |
Chris Wilson | 3bd3c93 | 2010-08-19 08:19:30 +0100 | [diff] [blame] | 1518 | { |
Linus Torvalds | c48c43e | 2010-10-26 18:57:59 -0700 | [diff] [blame] | 1519 | drm_i915_private_t *dev_priv = overlay->dev->dev_private; |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 1520 | struct overlay_registers __iomem *regs; |
Chris Wilson | 3bd3c93 | 2010-08-19 08:19:30 +0100 | [diff] [blame] | 1521 | |
| 1522 | if (OVERLAY_NEEDS_PHYSICAL(overlay->dev)) |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 1523 | /* Cast to make sparse happy, but it's wc memory anyway, so |
| 1524 | * equivalent to the wc io mapping on X86. */ |
| 1525 | regs = (struct overlay_registers __iomem *) |
| 1526 | overlay->reg_bo->phys_obj->handle->vaddr; |
Chris Wilson | 3bd3c93 | 2010-08-19 08:19:30 +0100 | [diff] [blame] | 1527 | else |
| 1528 | regs = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping, |
Linus Torvalds | c48c43e | 2010-10-26 18:57:59 -0700 | [diff] [blame] | 1529 | overlay->reg_bo->gtt_offset); |
Chris Wilson | 3bd3c93 | 2010-08-19 08:19:30 +0100 | [diff] [blame] | 1530 | |
| 1531 | return regs; |
| 1532 | } |
| 1533 | |
| 1534 | static void intel_overlay_unmap_regs_atomic(struct intel_overlay *overlay, |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 1535 | struct overlay_registers __iomem *regs) |
Chris Wilson | 3bd3c93 | 2010-08-19 08:19:30 +0100 | [diff] [blame] | 1536 | { |
| 1537 | if (!OVERLAY_NEEDS_PHYSICAL(overlay->dev)) |
Linus Torvalds | c48c43e | 2010-10-26 18:57:59 -0700 | [diff] [blame] | 1538 | io_mapping_unmap_atomic(regs); |
Chris Wilson | 3bd3c93 | 2010-08-19 08:19:30 +0100 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | |
Chris Wilson | 6ef3d42 | 2010-08-04 20:26:07 +0100 | [diff] [blame] | 1542 | struct intel_overlay_error_state * |
| 1543 | intel_overlay_capture_error_state(struct drm_device *dev) |
| 1544 | { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1545 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 6ef3d42 | 2010-08-04 20:26:07 +0100 | [diff] [blame] | 1546 | struct intel_overlay *overlay = dev_priv->overlay; |
| 1547 | struct intel_overlay_error_state *error; |
| 1548 | struct overlay_registers __iomem *regs; |
| 1549 | |
| 1550 | if (!overlay || !overlay->active) |
| 1551 | return NULL; |
| 1552 | |
| 1553 | error = kmalloc(sizeof(*error), GFP_ATOMIC); |
| 1554 | if (error == NULL) |
| 1555 | return NULL; |
| 1556 | |
| 1557 | error->dovsta = I915_READ(DOVSTA); |
| 1558 | error->isr = I915_READ(ISR); |
Chris Wilson | 31578148 | 2010-08-12 09:42:51 +0100 | [diff] [blame] | 1559 | if (OVERLAY_NEEDS_PHYSICAL(overlay->dev)) |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 1560 | error->base = (__force long)overlay->reg_bo->phys_obj->handle->vaddr; |
Chris Wilson | 31578148 | 2010-08-12 09:42:51 +0100 | [diff] [blame] | 1561 | else |
Ben Widawsky | 75020bc | 2012-04-16 14:07:43 -0700 | [diff] [blame] | 1562 | error->base = overlay->reg_bo->gtt_offset; |
Chris Wilson | 6ef3d42 | 2010-08-04 20:26:07 +0100 | [diff] [blame] | 1563 | |
| 1564 | regs = intel_overlay_map_regs_atomic(overlay); |
| 1565 | if (!regs) |
| 1566 | goto err; |
| 1567 | |
| 1568 | memcpy_fromio(&error->regs, regs, sizeof(struct overlay_registers)); |
Linus Torvalds | c48c43e | 2010-10-26 18:57:59 -0700 | [diff] [blame] | 1569 | intel_overlay_unmap_regs_atomic(overlay, regs); |
Chris Wilson | 6ef3d42 | 2010-08-04 20:26:07 +0100 | [diff] [blame] | 1570 | |
| 1571 | return error; |
| 1572 | |
| 1573 | err: |
| 1574 | kfree(error); |
| 1575 | return NULL; |
| 1576 | } |
| 1577 | |
| 1578 | void |
| 1579 | intel_overlay_print_error_state(struct seq_file *m, struct intel_overlay_error_state *error) |
| 1580 | { |
| 1581 | seq_printf(m, "Overlay, status: 0x%08x, interrupt: 0x%08x\n", |
| 1582 | error->dovsta, error->isr); |
| 1583 | seq_printf(m, " Register file at 0x%08lx:\n", |
| 1584 | error->base); |
| 1585 | |
| 1586 | #define P(x) seq_printf(m, " " #x ": 0x%08x\n", error->regs.x) |
| 1587 | P(OBUF_0Y); |
| 1588 | P(OBUF_1Y); |
| 1589 | P(OBUF_0U); |
| 1590 | P(OBUF_0V); |
| 1591 | P(OBUF_1U); |
| 1592 | P(OBUF_1V); |
| 1593 | P(OSTRIDE); |
| 1594 | P(YRGB_VPH); |
| 1595 | P(UV_VPH); |
| 1596 | P(HORZ_PH); |
| 1597 | P(INIT_PHS); |
| 1598 | P(DWINPOS); |
| 1599 | P(DWINSZ); |
| 1600 | P(SWIDTH); |
| 1601 | P(SWIDTHSW); |
| 1602 | P(SHEIGHT); |
| 1603 | P(YRGBSCALE); |
| 1604 | P(UVSCALE); |
| 1605 | P(OCLRC0); |
| 1606 | P(OCLRC1); |
| 1607 | P(DCLRKV); |
| 1608 | P(DCLRKM); |
| 1609 | P(SCLRKVH); |
| 1610 | P(SCLRKVL); |
| 1611 | P(SCLRKEN); |
| 1612 | P(OCONFIG); |
| 1613 | P(OCMD); |
| 1614 | P(OSTART_0Y); |
| 1615 | P(OSTART_1Y); |
| 1616 | P(OSTART_0U); |
| 1617 | P(OSTART_0V); |
| 1618 | P(OSTART_1U); |
| 1619 | P(OSTART_1V); |
| 1620 | P(OTILEOFF_0Y); |
| 1621 | P(OTILEOFF_1Y); |
| 1622 | P(OTILEOFF_0U); |
| 1623 | P(OTILEOFF_0V); |
| 1624 | P(OTILEOFF_1U); |
| 1625 | P(OTILEOFF_1V); |
| 1626 | P(FASTHSCALE); |
| 1627 | P(UVSCALEV); |
| 1628 | #undef P |
| 1629 | } |
Chris Wilson | 3bd3c93 | 2010-08-19 08:19:30 +0100 | [diff] [blame] | 1630 | #endif |