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