Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
| 3 | * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA |
| 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sub license, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial portions |
| 16 | * of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 21 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, |
| 22 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 23 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 24 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | **************************************************************************/ |
| 27 | |
| 28 | #include "vmwgfx_kms.h" |
| 29 | |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 30 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 31 | /* Might need a hrtimer here? */ |
| 32 | #define VMWGFX_PRESENT_RATE ((HZ / 60 > 0) ? HZ / 60 : 1) |
| 33 | |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 34 | |
| 35 | struct vmw_clip_rect { |
| 36 | int x1, x2, y1, y2; |
| 37 | }; |
| 38 | |
| 39 | /** |
| 40 | * Clip @num_rects number of @rects against @clip storing the |
| 41 | * results in @out_rects and the number of passed rects in @out_num. |
| 42 | */ |
| 43 | void vmw_clip_cliprects(struct drm_clip_rect *rects, |
| 44 | int num_rects, |
| 45 | struct vmw_clip_rect clip, |
| 46 | SVGASignedRect *out_rects, |
| 47 | int *out_num) |
| 48 | { |
| 49 | int i, k; |
| 50 | |
| 51 | for (i = 0, k = 0; i < num_rects; i++) { |
| 52 | int x1 = max_t(int, clip.x1, rects[i].x1); |
| 53 | int y1 = max_t(int, clip.y1, rects[i].y1); |
| 54 | int x2 = min_t(int, clip.x2, rects[i].x2); |
| 55 | int y2 = min_t(int, clip.y2, rects[i].y2); |
| 56 | |
| 57 | if (x1 >= x2) |
| 58 | continue; |
| 59 | if (y1 >= y2) |
| 60 | continue; |
| 61 | |
| 62 | out_rects[k].left = x1; |
| 63 | out_rects[k].top = y1; |
| 64 | out_rects[k].right = x2; |
| 65 | out_rects[k].bottom = y2; |
| 66 | k++; |
| 67 | } |
| 68 | |
| 69 | *out_num = k; |
| 70 | } |
| 71 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 72 | void vmw_display_unit_cleanup(struct vmw_display_unit *du) |
| 73 | { |
| 74 | if (du->cursor_surface) |
| 75 | vmw_surface_unreference(&du->cursor_surface); |
| 76 | if (du->cursor_dmabuf) |
| 77 | vmw_dmabuf_unreference(&du->cursor_dmabuf); |
| 78 | drm_crtc_cleanup(&du->crtc); |
| 79 | drm_encoder_cleanup(&du->encoder); |
| 80 | drm_connector_cleanup(&du->connector); |
| 81 | } |
| 82 | |
| 83 | /* |
| 84 | * Display Unit Cursor functions |
| 85 | */ |
| 86 | |
| 87 | int vmw_cursor_update_image(struct vmw_private *dev_priv, |
| 88 | u32 *image, u32 width, u32 height, |
| 89 | u32 hotspotX, u32 hotspotY) |
| 90 | { |
| 91 | struct { |
| 92 | u32 cmd; |
| 93 | SVGAFifoCmdDefineAlphaCursor cursor; |
| 94 | } *cmd; |
| 95 | u32 image_size = width * height * 4; |
| 96 | u32 cmd_size = sizeof(*cmd) + image_size; |
| 97 | |
| 98 | if (!image) |
| 99 | return -EINVAL; |
| 100 | |
| 101 | cmd = vmw_fifo_reserve(dev_priv, cmd_size); |
| 102 | if (unlikely(cmd == NULL)) { |
| 103 | DRM_ERROR("Fifo reserve failed.\n"); |
| 104 | return -ENOMEM; |
| 105 | } |
| 106 | |
| 107 | memset(cmd, 0, sizeof(*cmd)); |
| 108 | |
| 109 | memcpy(&cmd[1], image, image_size); |
| 110 | |
| 111 | cmd->cmd = cpu_to_le32(SVGA_CMD_DEFINE_ALPHA_CURSOR); |
| 112 | cmd->cursor.id = cpu_to_le32(0); |
| 113 | cmd->cursor.width = cpu_to_le32(width); |
| 114 | cmd->cursor.height = cpu_to_le32(height); |
| 115 | cmd->cursor.hotspotX = cpu_to_le32(hotspotX); |
| 116 | cmd->cursor.hotspotY = cpu_to_le32(hotspotY); |
| 117 | |
| 118 | vmw_fifo_commit(dev_priv, cmd_size); |
| 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | |
Jakob Bornecrantz | 6a91d97 | 2011-11-28 13:19:10 +0100 | [diff] [blame] | 123 | int vmw_cursor_update_dmabuf(struct vmw_private *dev_priv, |
| 124 | struct vmw_dma_buffer *dmabuf, |
| 125 | u32 width, u32 height, |
| 126 | u32 hotspotX, u32 hotspotY) |
| 127 | { |
| 128 | struct ttm_bo_kmap_obj map; |
| 129 | unsigned long kmap_offset; |
| 130 | unsigned long kmap_num; |
| 131 | void *virtual; |
| 132 | bool dummy; |
| 133 | int ret; |
| 134 | |
| 135 | kmap_offset = 0; |
| 136 | kmap_num = (width*height*4 + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 137 | |
| 138 | ret = ttm_bo_reserve(&dmabuf->base, true, false, false, 0); |
| 139 | if (unlikely(ret != 0)) { |
| 140 | DRM_ERROR("reserve failed\n"); |
| 141 | return -EINVAL; |
| 142 | } |
| 143 | |
| 144 | ret = ttm_bo_kmap(&dmabuf->base, kmap_offset, kmap_num, &map); |
| 145 | if (unlikely(ret != 0)) |
| 146 | goto err_unreserve; |
| 147 | |
| 148 | virtual = ttm_kmap_obj_virtual(&map, &dummy); |
| 149 | ret = vmw_cursor_update_image(dev_priv, virtual, width, height, |
| 150 | hotspotX, hotspotY); |
| 151 | |
| 152 | ttm_bo_kunmap(&map); |
| 153 | err_unreserve: |
| 154 | ttm_bo_unreserve(&dmabuf->base); |
| 155 | |
| 156 | return ret; |
| 157 | } |
| 158 | |
| 159 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 160 | void vmw_cursor_update_position(struct vmw_private *dev_priv, |
| 161 | bool show, int x, int y) |
| 162 | { |
| 163 | __le32 __iomem *fifo_mem = dev_priv->mmio_virt; |
| 164 | uint32_t count; |
| 165 | |
| 166 | iowrite32(show ? 1 : 0, fifo_mem + SVGA_FIFO_CURSOR_ON); |
| 167 | iowrite32(x, fifo_mem + SVGA_FIFO_CURSOR_X); |
| 168 | iowrite32(y, fifo_mem + SVGA_FIFO_CURSOR_Y); |
| 169 | count = ioread32(fifo_mem + SVGA_FIFO_CURSOR_COUNT); |
| 170 | iowrite32(++count, fifo_mem + SVGA_FIFO_CURSOR_COUNT); |
| 171 | } |
| 172 | |
| 173 | int vmw_du_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv, |
| 174 | uint32_t handle, uint32_t width, uint32_t height) |
| 175 | { |
| 176 | struct vmw_private *dev_priv = vmw_priv(crtc->dev); |
| 177 | struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; |
| 178 | struct vmw_display_unit *du = vmw_crtc_to_du(crtc); |
| 179 | struct vmw_surface *surface = NULL; |
| 180 | struct vmw_dma_buffer *dmabuf = NULL; |
| 181 | int ret; |
| 182 | |
Jakob Bornecrantz | baa91d64 | 2011-11-09 10:25:28 +0100 | [diff] [blame] | 183 | /* A lot of the code assumes this */ |
| 184 | if (handle && (width != 64 || height != 64)) |
| 185 | return -EINVAL; |
| 186 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 187 | if (handle) { |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 188 | ret = vmw_user_lookup_handle(dev_priv, tfile, |
| 189 | handle, &surface, &dmabuf); |
| 190 | if (ret) { |
| 191 | DRM_ERROR("failed to find surface or dmabuf: %i\n", ret); |
| 192 | return -EINVAL; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 196 | /* need to do this before taking down old image */ |
| 197 | if (surface && !surface->snooper.image) { |
| 198 | DRM_ERROR("surface not suitable for cursor\n"); |
| 199 | vmw_surface_unreference(&surface); |
| 200 | return -EINVAL; |
| 201 | } |
| 202 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 203 | /* takedown old cursor */ |
| 204 | if (du->cursor_surface) { |
| 205 | du->cursor_surface->snooper.crtc = NULL; |
| 206 | vmw_surface_unreference(&du->cursor_surface); |
| 207 | } |
| 208 | if (du->cursor_dmabuf) |
| 209 | vmw_dmabuf_unreference(&du->cursor_dmabuf); |
| 210 | |
| 211 | /* setup new image */ |
| 212 | if (surface) { |
| 213 | /* vmw_user_surface_lookup takes one reference */ |
| 214 | du->cursor_surface = surface; |
| 215 | |
| 216 | du->cursor_surface->snooper.crtc = crtc; |
| 217 | du->cursor_age = du->cursor_surface->snooper.age; |
| 218 | vmw_cursor_update_image(dev_priv, surface->snooper.image, |
| 219 | 64, 64, du->hotspot_x, du->hotspot_y); |
| 220 | } else if (dmabuf) { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 221 | /* vmw_user_surface_lookup takes one reference */ |
| 222 | du->cursor_dmabuf = dmabuf; |
| 223 | |
Jakob Bornecrantz | 6a91d97 | 2011-11-28 13:19:10 +0100 | [diff] [blame] | 224 | ret = vmw_cursor_update_dmabuf(dev_priv, dmabuf, width, height, |
| 225 | du->hotspot_x, du->hotspot_y); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 226 | } else { |
| 227 | vmw_cursor_update_position(dev_priv, false, 0, 0); |
| 228 | return 0; |
| 229 | } |
| 230 | |
Thomas Hellstrom | da7653d | 2011-11-02 09:43:12 +0100 | [diff] [blame] | 231 | vmw_cursor_update_position(dev_priv, true, |
| 232 | du->cursor_x + du->hotspot_x, |
| 233 | du->cursor_y + du->hotspot_y); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | int vmw_du_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) |
| 239 | { |
| 240 | struct vmw_private *dev_priv = vmw_priv(crtc->dev); |
| 241 | struct vmw_display_unit *du = vmw_crtc_to_du(crtc); |
| 242 | bool shown = du->cursor_surface || du->cursor_dmabuf ? true : false; |
| 243 | |
| 244 | du->cursor_x = x + crtc->x; |
| 245 | du->cursor_y = y + crtc->y; |
| 246 | |
| 247 | vmw_cursor_update_position(dev_priv, shown, |
Thomas Hellstrom | da7653d | 2011-11-02 09:43:12 +0100 | [diff] [blame] | 248 | du->cursor_x + du->hotspot_x, |
| 249 | du->cursor_y + du->hotspot_y); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | void vmw_kms_cursor_snoop(struct vmw_surface *srf, |
| 255 | struct ttm_object_file *tfile, |
| 256 | struct ttm_buffer_object *bo, |
| 257 | SVGA3dCmdHeader *header) |
| 258 | { |
| 259 | struct ttm_bo_kmap_obj map; |
| 260 | unsigned long kmap_offset; |
| 261 | unsigned long kmap_num; |
| 262 | SVGA3dCopyBox *box; |
| 263 | unsigned box_count; |
| 264 | void *virtual; |
| 265 | bool dummy; |
| 266 | struct vmw_dma_cmd { |
| 267 | SVGA3dCmdHeader header; |
| 268 | SVGA3dCmdSurfaceDMA dma; |
| 269 | } *cmd; |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 270 | int i, ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 271 | |
| 272 | cmd = container_of(header, struct vmw_dma_cmd, header); |
| 273 | |
| 274 | /* No snooper installed */ |
| 275 | if (!srf->snooper.image) |
| 276 | return; |
| 277 | |
| 278 | if (cmd->dma.host.face != 0 || cmd->dma.host.mipmap != 0) { |
| 279 | DRM_ERROR("face and mipmap for cursors should never != 0\n"); |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | if (cmd->header.size < 64) { |
| 284 | DRM_ERROR("at least one full copy box must be given\n"); |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | box = (SVGA3dCopyBox *)&cmd[1]; |
| 289 | box_count = (cmd->header.size - sizeof(SVGA3dCmdSurfaceDMA)) / |
| 290 | sizeof(SVGA3dCopyBox); |
| 291 | |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 292 | if (cmd->dma.guest.ptr.offset % PAGE_SIZE || |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 293 | box->x != 0 || box->y != 0 || box->z != 0 || |
| 294 | box->srcx != 0 || box->srcy != 0 || box->srcz != 0 || |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 295 | box->d != 1 || box_count != 1) { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 296 | /* TODO handle none page aligned offsets */ |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 297 | /* TODO handle more dst & src != 0 */ |
| 298 | /* TODO handle more then one copy */ |
| 299 | DRM_ERROR("Cant snoop dma request for cursor!\n"); |
| 300 | DRM_ERROR("(%u, %u, %u) (%u, %u, %u) (%ux%ux%u) %u %u\n", |
| 301 | box->srcx, box->srcy, box->srcz, |
| 302 | box->x, box->y, box->z, |
| 303 | box->w, box->h, box->d, box_count, |
| 304 | cmd->dma.guest.ptr.offset); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 305 | return; |
| 306 | } |
| 307 | |
| 308 | kmap_offset = cmd->dma.guest.ptr.offset >> PAGE_SHIFT; |
| 309 | kmap_num = (64*64*4) >> PAGE_SHIFT; |
| 310 | |
| 311 | ret = ttm_bo_reserve(bo, true, false, false, 0); |
| 312 | if (unlikely(ret != 0)) { |
| 313 | DRM_ERROR("reserve failed\n"); |
| 314 | return; |
| 315 | } |
| 316 | |
| 317 | ret = ttm_bo_kmap(bo, kmap_offset, kmap_num, &map); |
| 318 | if (unlikely(ret != 0)) |
| 319 | goto err_unreserve; |
| 320 | |
| 321 | virtual = ttm_kmap_obj_virtual(&map, &dummy); |
| 322 | |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 323 | if (box->w == 64 && cmd->dma.guest.pitch == 64*4) { |
| 324 | memcpy(srf->snooper.image, virtual, 64*64*4); |
| 325 | } else { |
| 326 | /* Image is unsigned pointer. */ |
| 327 | for (i = 0; i < box->h; i++) |
| 328 | memcpy(srf->snooper.image + i * 64, |
| 329 | virtual + i * cmd->dma.guest.pitch, |
| 330 | box->w * 4); |
| 331 | } |
| 332 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 333 | srf->snooper.age++; |
| 334 | |
| 335 | /* we can't call this function from this function since execbuf has |
| 336 | * reserved fifo space. |
| 337 | * |
| 338 | * if (srf->snooper.crtc) |
| 339 | * vmw_ldu_crtc_cursor_update_image(dev_priv, |
| 340 | * srf->snooper.image, 64, 64, |
| 341 | * du->hotspot_x, du->hotspot_y); |
| 342 | */ |
| 343 | |
| 344 | ttm_bo_kunmap(&map); |
| 345 | err_unreserve: |
| 346 | ttm_bo_unreserve(bo); |
| 347 | } |
| 348 | |
| 349 | void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv) |
| 350 | { |
| 351 | struct drm_device *dev = dev_priv->dev; |
| 352 | struct vmw_display_unit *du; |
| 353 | struct drm_crtc *crtc; |
| 354 | |
| 355 | mutex_lock(&dev->mode_config.mutex); |
| 356 | |
| 357 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 358 | du = vmw_crtc_to_du(crtc); |
| 359 | if (!du->cursor_surface || |
| 360 | du->cursor_age == du->cursor_surface->snooper.age) |
| 361 | continue; |
| 362 | |
| 363 | du->cursor_age = du->cursor_surface->snooper.age; |
| 364 | vmw_cursor_update_image(dev_priv, |
| 365 | du->cursor_surface->snooper.image, |
| 366 | 64, 64, du->hotspot_x, du->hotspot_y); |
| 367 | } |
| 368 | |
| 369 | mutex_unlock(&dev->mode_config.mutex); |
| 370 | } |
| 371 | |
| 372 | /* |
| 373 | * Generic framebuffer code |
| 374 | */ |
| 375 | |
| 376 | int vmw_framebuffer_create_handle(struct drm_framebuffer *fb, |
| 377 | struct drm_file *file_priv, |
| 378 | unsigned int *handle) |
| 379 | { |
| 380 | if (handle) |
Ryan Mallon | bf9c05d | 2012-01-28 08:51:40 +1100 | [diff] [blame] | 381 | *handle = 0; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | /* |
| 387 | * Surface framebuffer code |
| 388 | */ |
| 389 | |
| 390 | #define vmw_framebuffer_to_vfbs(x) \ |
| 391 | container_of(x, struct vmw_framebuffer_surface, base.base) |
| 392 | |
| 393 | struct vmw_framebuffer_surface { |
| 394 | struct vmw_framebuffer base; |
| 395 | struct vmw_surface *surface; |
Thomas Hellstrom | 22ee861 | 2010-05-28 11:22:00 +0200 | [diff] [blame] | 396 | struct vmw_dma_buffer *buffer; |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 397 | struct list_head head; |
| 398 | struct drm_master *master; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 399 | }; |
| 400 | |
| 401 | void vmw_framebuffer_surface_destroy(struct drm_framebuffer *framebuffer) |
| 402 | { |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 403 | struct vmw_framebuffer_surface *vfbs = |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 404 | vmw_framebuffer_to_vfbs(framebuffer); |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 405 | struct vmw_master *vmaster = vmw_master(vfbs->master); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 406 | |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 407 | |
| 408 | mutex_lock(&vmaster->fb_surf_mutex); |
| 409 | list_del(&vfbs->head); |
| 410 | mutex_unlock(&vmaster->fb_surf_mutex); |
| 411 | |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 412 | drm_master_put(&vfbs->master); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 413 | drm_framebuffer_cleanup(framebuffer); |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 414 | vmw_surface_unreference(&vfbs->surface); |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 415 | ttm_base_object_unref(&vfbs->base.user_obj); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 416 | |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 417 | kfree(vfbs); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 420 | static int do_surface_dirty_sou(struct vmw_private *dev_priv, |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 421 | struct drm_file *file_priv, |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 422 | struct vmw_framebuffer *framebuffer, |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 423 | unsigned flags, unsigned color, |
| 424 | struct drm_clip_rect *clips, |
Jakob Bornecrantz | bd49ae4 | 2012-02-09 16:56:44 +0100 | [diff] [blame] | 425 | unsigned num_clips, int inc, |
| 426 | struct vmw_fence_obj **out_fence) |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 427 | { |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 428 | struct vmw_display_unit *units[VMWGFX_NUM_DISPLAY_UNITS]; |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 429 | struct drm_clip_rect *clips_ptr; |
| 430 | struct drm_clip_rect *tmp; |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 431 | struct drm_crtc *crtc; |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 432 | size_t fifo_size; |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 433 | int i, num_units; |
| 434 | int ret = 0; /* silence warning */ |
| 435 | int left, right, top, bottom; |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 436 | |
| 437 | struct { |
| 438 | SVGA3dCmdHeader header; |
| 439 | SVGA3dCmdBlitSurfaceToScreen body; |
| 440 | } *cmd; |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 441 | SVGASignedRect *blits; |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 442 | |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 443 | num_units = 0; |
| 444 | list_for_each_entry(crtc, &dev_priv->dev->mode_config.crtc_list, |
| 445 | head) { |
| 446 | if (crtc->fb != &framebuffer->base) |
| 447 | continue; |
| 448 | units[num_units++] = vmw_crtc_to_du(crtc); |
| 449 | } |
| 450 | |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 451 | BUG_ON(!clips || !num_clips); |
| 452 | |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 453 | tmp = kzalloc(sizeof(*tmp) * num_clips, GFP_KERNEL); |
| 454 | if (unlikely(tmp == NULL)) { |
| 455 | DRM_ERROR("Temporary cliprect memory alloc failed.\n"); |
| 456 | return -ENOMEM; |
| 457 | } |
| 458 | |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 459 | fifo_size = sizeof(*cmd) + sizeof(SVGASignedRect) * num_clips; |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 460 | cmd = kzalloc(fifo_size, GFP_KERNEL); |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 461 | if (unlikely(cmd == NULL)) { |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 462 | DRM_ERROR("Temporary fifo memory alloc failed.\n"); |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 463 | ret = -ENOMEM; |
| 464 | goto out_free_tmp; |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 465 | } |
| 466 | |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 467 | /* setup blits pointer */ |
| 468 | blits = (SVGASignedRect *)&cmd[1]; |
| 469 | |
| 470 | /* initial clip region */ |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 471 | left = clips->x1; |
| 472 | right = clips->x2; |
| 473 | top = clips->y1; |
| 474 | bottom = clips->y2; |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 475 | |
Jakob Bornecrantz | f0c8a65 | 2011-11-09 10:25:27 +0100 | [diff] [blame] | 476 | /* skip the first clip rect */ |
| 477 | for (i = 1, clips_ptr = clips + inc; |
| 478 | i < num_clips; i++, clips_ptr += inc) { |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 479 | left = min_t(int, left, (int)clips_ptr->x1); |
| 480 | right = max_t(int, right, (int)clips_ptr->x2); |
| 481 | top = min_t(int, top, (int)clips_ptr->y1); |
| 482 | bottom = max_t(int, bottom, (int)clips_ptr->y2); |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 483 | } |
| 484 | |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 485 | /* only need to do this once */ |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 486 | cmd->header.id = cpu_to_le32(SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN); |
| 487 | cmd->header.size = cpu_to_le32(fifo_size - sizeof(cmd->header)); |
| 488 | |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 489 | cmd->body.srcRect.left = left; |
| 490 | cmd->body.srcRect.right = right; |
| 491 | cmd->body.srcRect.top = top; |
| 492 | cmd->body.srcRect.bottom = bottom; |
| 493 | |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 494 | clips_ptr = clips; |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 495 | for (i = 0; i < num_clips; i++, clips_ptr += inc) { |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 496 | tmp[i].x1 = clips_ptr->x1 - left; |
| 497 | tmp[i].x2 = clips_ptr->x2 - left; |
| 498 | tmp[i].y1 = clips_ptr->y1 - top; |
| 499 | tmp[i].y2 = clips_ptr->y2 - top; |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 500 | } |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 501 | |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 502 | /* do per unit writing, reuse fifo for each */ |
| 503 | for (i = 0; i < num_units; i++) { |
| 504 | struct vmw_display_unit *unit = units[i]; |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 505 | struct vmw_clip_rect clip; |
| 506 | int num; |
| 507 | |
| 508 | clip.x1 = left - unit->crtc.x; |
| 509 | clip.y1 = top - unit->crtc.y; |
| 510 | clip.x2 = right - unit->crtc.x; |
| 511 | clip.y2 = bottom - unit->crtc.y; |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 512 | |
| 513 | /* skip any crtcs that misses the clip region */ |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 514 | if (clip.x1 >= unit->crtc.mode.hdisplay || |
| 515 | clip.y1 >= unit->crtc.mode.vdisplay || |
| 516 | clip.x2 <= 0 || clip.y2 <= 0) |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 517 | continue; |
| 518 | |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 519 | /* |
| 520 | * In order for the clip rects to be correctly scaled |
| 521 | * the src and dest rects needs to be the same size. |
| 522 | */ |
| 523 | cmd->body.destRect.left = clip.x1; |
| 524 | cmd->body.destRect.right = clip.x2; |
| 525 | cmd->body.destRect.top = clip.y1; |
| 526 | cmd->body.destRect.bottom = clip.y2; |
| 527 | |
| 528 | /* create a clip rect of the crtc in dest coords */ |
| 529 | clip.x2 = unit->crtc.mode.hdisplay - clip.x1; |
| 530 | clip.y2 = unit->crtc.mode.vdisplay - clip.y1; |
| 531 | clip.x1 = 0 - clip.x1; |
| 532 | clip.y1 = 0 - clip.y1; |
| 533 | |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 534 | /* need to reset sid as it is changed by execbuf */ |
| 535 | cmd->body.srcImage.sid = cpu_to_le32(framebuffer->user_handle); |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 536 | cmd->body.destScreenId = unit->unit; |
| 537 | |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 538 | /* clip and write blits to cmd stream */ |
| 539 | vmw_clip_cliprects(tmp, num_clips, clip, blits, &num); |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 540 | |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 541 | /* if no cliprects hit skip this */ |
| 542 | if (num == 0) |
| 543 | continue; |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 544 | |
Jakob Bornecrantz | bd49ae4 | 2012-02-09 16:56:44 +0100 | [diff] [blame] | 545 | /* only return the last fence */ |
| 546 | if (out_fence && *out_fence) |
| 547 | vmw_fence_obj_unreference(out_fence); |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 548 | |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 549 | /* recalculate package length */ |
| 550 | fifo_size = sizeof(*cmd) + sizeof(SVGASignedRect) * num; |
| 551 | cmd->header.size = cpu_to_le32(fifo_size - sizeof(cmd->header)); |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 552 | ret = vmw_execbuf_process(file_priv, dev_priv, NULL, cmd, |
Jakob Bornecrantz | bd49ae4 | 2012-02-09 16:56:44 +0100 | [diff] [blame] | 553 | fifo_size, 0, NULL, out_fence); |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 554 | |
| 555 | if (unlikely(ret != 0)) |
| 556 | break; |
| 557 | } |
| 558 | |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 559 | |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 560 | kfree(cmd); |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 561 | out_free_tmp: |
| 562 | kfree(tmp); |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 563 | |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 564 | return ret; |
Jakob Bornecrantz | 5deb65c | 2011-10-04 20:13:18 +0200 | [diff] [blame] | 565 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 566 | |
| 567 | int vmw_framebuffer_surface_dirty(struct drm_framebuffer *framebuffer, |
Thomas Hellstrom | 02b0016 | 2010-10-05 12:43:02 +0200 | [diff] [blame] | 568 | struct drm_file *file_priv, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 569 | unsigned flags, unsigned color, |
| 570 | struct drm_clip_rect *clips, |
| 571 | unsigned num_clips) |
| 572 | { |
| 573 | struct vmw_private *dev_priv = vmw_priv(framebuffer->dev); |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 574 | struct vmw_master *vmaster = vmw_master(file_priv->master); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 575 | struct vmw_framebuffer_surface *vfbs = |
| 576 | vmw_framebuffer_to_vfbs(framebuffer); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 577 | struct drm_clip_rect norect; |
Jakob Bornecrantz | 5deb65c | 2011-10-04 20:13:18 +0200 | [diff] [blame] | 578 | int ret, inc = 1; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 579 | |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 580 | if (unlikely(vfbs->master != file_priv->master)) |
| 581 | return -EINVAL; |
| 582 | |
Jakob Bornecrantz | 01e8141 | 2011-10-04 20:13:24 +0200 | [diff] [blame] | 583 | /* Require ScreenObject support for 3D */ |
| 584 | if (!dev_priv->sou_priv) |
| 585 | return -EINVAL; |
| 586 | |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 587 | ret = ttm_read_lock(&vmaster->lock, true); |
| 588 | if (unlikely(ret != 0)) |
| 589 | return ret; |
| 590 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 591 | if (!num_clips) { |
| 592 | num_clips = 1; |
| 593 | clips = &norect; |
| 594 | norect.x1 = norect.y1 = 0; |
| 595 | norect.x2 = framebuffer->width; |
| 596 | norect.y2 = framebuffer->height; |
| 597 | } else if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY) { |
| 598 | num_clips /= 2; |
| 599 | inc = 2; /* skip source rects */ |
| 600 | } |
| 601 | |
Jakob Bornecrantz | c5c4236 | 2011-10-22 10:29:34 +0200 | [diff] [blame] | 602 | ret = do_surface_dirty_sou(dev_priv, file_priv, &vfbs->base, |
Jakob Bornecrantz | 01e8141 | 2011-10-04 20:13:24 +0200 | [diff] [blame] | 603 | flags, color, |
Jakob Bornecrantz | bd49ae4 | 2012-02-09 16:56:44 +0100 | [diff] [blame] | 604 | clips, num_clips, inc, NULL); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 605 | |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 606 | ttm_read_unlock(&vmaster->lock); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 607 | return 0; |
| 608 | } |
| 609 | |
| 610 | static struct drm_framebuffer_funcs vmw_framebuffer_surface_funcs = { |
| 611 | .destroy = vmw_framebuffer_surface_destroy, |
| 612 | .dirty = vmw_framebuffer_surface_dirty, |
| 613 | .create_handle = vmw_framebuffer_create_handle, |
| 614 | }; |
| 615 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 616 | static int vmw_kms_new_framebuffer_surface(struct vmw_private *dev_priv, |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 617 | struct drm_file *file_priv, |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 618 | struct vmw_surface *surface, |
| 619 | struct vmw_framebuffer **out, |
| 620 | const struct drm_mode_fb_cmd |
| 621 | *mode_cmd) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 622 | |
| 623 | { |
| 624 | struct drm_device *dev = dev_priv->dev; |
| 625 | struct vmw_framebuffer_surface *vfbs; |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 626 | enum SVGA3dSurfaceFormat format; |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 627 | struct vmw_master *vmaster = vmw_master(file_priv->master); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 628 | int ret; |
| 629 | |
Jakob Bornecrantz | 01e8141 | 2011-10-04 20:13:24 +0200 | [diff] [blame] | 630 | /* 3D is only supported on HWv8 hosts which supports screen objects */ |
| 631 | if (!dev_priv->sou_priv) |
| 632 | return -ENOSYS; |
| 633 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 634 | /* |
| 635 | * Sanity checks. |
| 636 | */ |
| 637 | |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 638 | /* Surface must be marked as a scanout. */ |
| 639 | if (unlikely(!surface->scanout)) |
| 640 | return -EINVAL; |
| 641 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 642 | if (unlikely(surface->mip_levels[0] != 1 || |
| 643 | surface->num_sizes != 1 || |
| 644 | surface->sizes[0].width < mode_cmd->width || |
| 645 | surface->sizes[0].height < mode_cmd->height || |
| 646 | surface->sizes[0].depth != 1)) { |
| 647 | DRM_ERROR("Incompatible surface dimensions " |
| 648 | "for requested mode.\n"); |
| 649 | return -EINVAL; |
| 650 | } |
| 651 | |
| 652 | switch (mode_cmd->depth) { |
| 653 | case 32: |
| 654 | format = SVGA3D_A8R8G8B8; |
| 655 | break; |
| 656 | case 24: |
| 657 | format = SVGA3D_X8R8G8B8; |
| 658 | break; |
| 659 | case 16: |
| 660 | format = SVGA3D_R5G6B5; |
| 661 | break; |
| 662 | case 15: |
| 663 | format = SVGA3D_A1R5G5B5; |
| 664 | break; |
Michel Dänzer | f01b7ba | 2011-08-31 07:42:47 +0000 | [diff] [blame] | 665 | case 8: |
| 666 | format = SVGA3D_LUMINANCE8; |
| 667 | break; |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 668 | default: |
| 669 | DRM_ERROR("Invalid color depth: %d\n", mode_cmd->depth); |
| 670 | return -EINVAL; |
| 671 | } |
| 672 | |
| 673 | if (unlikely(format != surface->format)) { |
| 674 | DRM_ERROR("Invalid surface format for requested mode.\n"); |
| 675 | return -EINVAL; |
| 676 | } |
| 677 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 678 | vfbs = kzalloc(sizeof(*vfbs), GFP_KERNEL); |
| 679 | if (!vfbs) { |
| 680 | ret = -ENOMEM; |
| 681 | goto out_err1; |
| 682 | } |
| 683 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 684 | if (!vmw_surface_reference(surface)) { |
| 685 | DRM_ERROR("failed to reference surface %p\n", surface); |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame^] | 686 | ret = -EINVAL; |
| 687 | goto out_err2; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | /* XXX get the first 3 from the surface info */ |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 691 | vfbs->base.base.bits_per_pixel = mode_cmd->bpp; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 692 | vfbs->base.base.pitches[0] = mode_cmd->pitch; |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 693 | vfbs->base.base.depth = mode_cmd->depth; |
| 694 | vfbs->base.base.width = mode_cmd->width; |
| 695 | vfbs->base.base.height = mode_cmd->height; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 696 | vfbs->surface = surface; |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 697 | vfbs->base.user_handle = mode_cmd->handle; |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 698 | vfbs->master = drm_master_get(file_priv->master); |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 699 | |
| 700 | mutex_lock(&vmaster->fb_surf_mutex); |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 701 | list_add_tail(&vfbs->head, &vmaster->fb_surf); |
| 702 | mutex_unlock(&vmaster->fb_surf_mutex); |
| 703 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 704 | *out = &vfbs->base; |
| 705 | |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame^] | 706 | ret = drm_framebuffer_init(dev, &vfbs->base.base, |
| 707 | &vmw_framebuffer_surface_funcs); |
| 708 | if (ret) |
| 709 | goto out_err3; |
| 710 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 711 | return 0; |
| 712 | |
| 713 | out_err3: |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame^] | 714 | vmw_surface_unreference(&surface); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 715 | out_err2: |
| 716 | kfree(vfbs); |
| 717 | out_err1: |
| 718 | return ret; |
| 719 | } |
| 720 | |
| 721 | /* |
| 722 | * Dmabuf framebuffer code |
| 723 | */ |
| 724 | |
| 725 | #define vmw_framebuffer_to_vfbd(x) \ |
| 726 | container_of(x, struct vmw_framebuffer_dmabuf, base.base) |
| 727 | |
| 728 | struct vmw_framebuffer_dmabuf { |
| 729 | struct vmw_framebuffer base; |
| 730 | struct vmw_dma_buffer *buffer; |
| 731 | }; |
| 732 | |
| 733 | void vmw_framebuffer_dmabuf_destroy(struct drm_framebuffer *framebuffer) |
| 734 | { |
| 735 | struct vmw_framebuffer_dmabuf *vfbd = |
| 736 | vmw_framebuffer_to_vfbd(framebuffer); |
| 737 | |
| 738 | drm_framebuffer_cleanup(framebuffer); |
| 739 | vmw_dmabuf_unreference(&vfbd->buffer); |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 740 | ttm_base_object_unref(&vfbd->base.user_obj); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 741 | |
| 742 | kfree(vfbd); |
| 743 | } |
| 744 | |
Jakob Bornecrantz | 5deb65c | 2011-10-04 20:13:18 +0200 | [diff] [blame] | 745 | static int do_dmabuf_dirty_ldu(struct vmw_private *dev_priv, |
| 746 | struct vmw_framebuffer *framebuffer, |
Jakob Bornecrantz | 5deb65c | 2011-10-04 20:13:18 +0200 | [diff] [blame] | 747 | unsigned flags, unsigned color, |
| 748 | struct drm_clip_rect *clips, |
| 749 | unsigned num_clips, int increment) |
| 750 | { |
| 751 | size_t fifo_size; |
| 752 | int i; |
| 753 | |
| 754 | struct { |
| 755 | uint32_t header; |
| 756 | SVGAFifoCmdUpdate body; |
| 757 | } *cmd; |
| 758 | |
| 759 | fifo_size = sizeof(*cmd) * num_clips; |
| 760 | cmd = vmw_fifo_reserve(dev_priv, fifo_size); |
| 761 | if (unlikely(cmd == NULL)) { |
| 762 | DRM_ERROR("Fifo reserve failed.\n"); |
| 763 | return -ENOMEM; |
| 764 | } |
| 765 | |
| 766 | memset(cmd, 0, fifo_size); |
| 767 | for (i = 0; i < num_clips; i++, clips += increment) { |
| 768 | cmd[i].header = cpu_to_le32(SVGA_CMD_UPDATE); |
| 769 | cmd[i].body.x = cpu_to_le32(clips->x1); |
| 770 | cmd[i].body.y = cpu_to_le32(clips->y1); |
| 771 | cmd[i].body.width = cpu_to_le32(clips->x2 - clips->x1); |
| 772 | cmd[i].body.height = cpu_to_le32(clips->y2 - clips->y1); |
| 773 | } |
| 774 | |
| 775 | vmw_fifo_commit(dev_priv, fifo_size); |
| 776 | return 0; |
| 777 | } |
| 778 | |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 779 | static int do_dmabuf_define_gmrfb(struct drm_file *file_priv, |
| 780 | struct vmw_private *dev_priv, |
| 781 | struct vmw_framebuffer *framebuffer) |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 782 | { |
Jakob Bornecrantz | 64fc994 | 2011-10-22 10:29:33 +0200 | [diff] [blame] | 783 | int depth = framebuffer->base.depth; |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 784 | size_t fifo_size; |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 785 | int ret; |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 786 | |
| 787 | struct { |
| 788 | uint32_t header; |
| 789 | SVGAFifoCmdDefineGMRFB body; |
| 790 | } *cmd; |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 791 | |
Jakob Bornecrantz | 64fc994 | 2011-10-22 10:29:33 +0200 | [diff] [blame] | 792 | /* Emulate RGBA support, contrary to svga_reg.h this is not |
| 793 | * supported by hosts. This is only a problem if we are reading |
| 794 | * this value later and expecting what we uploaded back. |
| 795 | */ |
| 796 | if (depth == 32) |
| 797 | depth = 24; |
| 798 | |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 799 | fifo_size = sizeof(*cmd); |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 800 | cmd = kmalloc(fifo_size, GFP_KERNEL); |
| 801 | if (unlikely(cmd == NULL)) { |
| 802 | DRM_ERROR("Failed to allocate temporary cmd buffer.\n"); |
| 803 | return -ENOMEM; |
| 804 | } |
| 805 | |
| 806 | memset(cmd, 0, fifo_size); |
| 807 | cmd->header = SVGA_CMD_DEFINE_GMRFB; |
| 808 | cmd->body.format.bitsPerPixel = framebuffer->base.bits_per_pixel; |
Jakob Bornecrantz | 64fc994 | 2011-10-22 10:29:33 +0200 | [diff] [blame] | 809 | cmd->body.format.colorDepth = depth; |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 810 | cmd->body.format.reserved = 0; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 811 | cmd->body.bytesPerLine = framebuffer->base.pitches[0]; |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 812 | cmd->body.ptr.gmrId = framebuffer->user_handle; |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 813 | cmd->body.ptr.offset = 0; |
| 814 | |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 815 | ret = vmw_execbuf_process(file_priv, dev_priv, NULL, cmd, |
Jakob Bornecrantz | bb1bd2f | 2012-02-09 16:56:43 +0100 | [diff] [blame] | 816 | fifo_size, 0, NULL, NULL); |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 817 | |
| 818 | kfree(cmd); |
| 819 | |
| 820 | return ret; |
| 821 | } |
| 822 | |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 823 | static int do_dmabuf_dirty_sou(struct drm_file *file_priv, |
| 824 | struct vmw_private *dev_priv, |
| 825 | struct vmw_framebuffer *framebuffer, |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 826 | unsigned flags, unsigned color, |
| 827 | struct drm_clip_rect *clips, |
Jakob Bornecrantz | bd49ae4 | 2012-02-09 16:56:44 +0100 | [diff] [blame] | 828 | unsigned num_clips, int increment, |
| 829 | struct vmw_fence_obj **out_fence) |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 830 | { |
| 831 | struct vmw_display_unit *units[VMWGFX_NUM_DISPLAY_UNITS]; |
| 832 | struct drm_clip_rect *clips_ptr; |
| 833 | int i, k, num_units, ret; |
| 834 | struct drm_crtc *crtc; |
| 835 | size_t fifo_size; |
| 836 | |
| 837 | struct { |
| 838 | uint32_t header; |
| 839 | SVGAFifoCmdBlitGMRFBToScreen body; |
| 840 | } *blits; |
| 841 | |
| 842 | ret = do_dmabuf_define_gmrfb(file_priv, dev_priv, framebuffer); |
| 843 | if (unlikely(ret != 0)) |
| 844 | return ret; /* define_gmrfb prints warnings */ |
| 845 | |
| 846 | fifo_size = sizeof(*blits) * num_clips; |
| 847 | blits = kmalloc(fifo_size, GFP_KERNEL); |
| 848 | if (unlikely(blits == NULL)) { |
| 849 | DRM_ERROR("Failed to allocate temporary cmd buffer.\n"); |
| 850 | return -ENOMEM; |
| 851 | } |
| 852 | |
| 853 | num_units = 0; |
| 854 | list_for_each_entry(crtc, &dev_priv->dev->mode_config.crtc_list, head) { |
| 855 | if (crtc->fb != &framebuffer->base) |
| 856 | continue; |
| 857 | units[num_units++] = vmw_crtc_to_du(crtc); |
| 858 | } |
| 859 | |
| 860 | for (k = 0; k < num_units; k++) { |
| 861 | struct vmw_display_unit *unit = units[k]; |
| 862 | int hit_num = 0; |
| 863 | |
| 864 | clips_ptr = clips; |
| 865 | for (i = 0; i < num_clips; i++, clips_ptr += increment) { |
| 866 | int clip_x1 = clips_ptr->x1 - unit->crtc.x; |
| 867 | int clip_y1 = clips_ptr->y1 - unit->crtc.y; |
| 868 | int clip_x2 = clips_ptr->x2 - unit->crtc.x; |
| 869 | int clip_y2 = clips_ptr->y2 - unit->crtc.y; |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 870 | int move_x, move_y; |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 871 | |
| 872 | /* skip any crtcs that misses the clip region */ |
| 873 | if (clip_x1 >= unit->crtc.mode.hdisplay || |
| 874 | clip_y1 >= unit->crtc.mode.vdisplay || |
| 875 | clip_x2 <= 0 || clip_y2 <= 0) |
| 876 | continue; |
| 877 | |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 878 | /* clip size to crtc size */ |
| 879 | clip_x2 = min_t(int, clip_x2, unit->crtc.mode.hdisplay); |
| 880 | clip_y2 = min_t(int, clip_y2, unit->crtc.mode.vdisplay); |
| 881 | |
| 882 | /* translate both src and dest to bring clip into screen */ |
| 883 | move_x = min_t(int, clip_x1, 0); |
| 884 | move_y = min_t(int, clip_y1, 0); |
| 885 | |
| 886 | /* actual translate done here */ |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 887 | blits[hit_num].header = SVGA_CMD_BLIT_GMRFB_TO_SCREEN; |
| 888 | blits[hit_num].body.destScreenId = unit->unit; |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 889 | blits[hit_num].body.srcOrigin.x = clips_ptr->x1 - move_x; |
| 890 | blits[hit_num].body.srcOrigin.y = clips_ptr->y1 - move_y; |
| 891 | blits[hit_num].body.destRect.left = clip_x1 - move_x; |
| 892 | blits[hit_num].body.destRect.top = clip_y1 - move_y; |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 893 | blits[hit_num].body.destRect.right = clip_x2; |
| 894 | blits[hit_num].body.destRect.bottom = clip_y2; |
| 895 | hit_num++; |
| 896 | } |
| 897 | |
| 898 | /* no clips hit the crtc */ |
| 899 | if (hit_num == 0) |
| 900 | continue; |
| 901 | |
Jakob Bornecrantz | bd49ae4 | 2012-02-09 16:56:44 +0100 | [diff] [blame] | 902 | /* only return the last fence */ |
| 903 | if (out_fence && *out_fence) |
| 904 | vmw_fence_obj_unreference(out_fence); |
| 905 | |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 906 | fifo_size = sizeof(*blits) * hit_num; |
| 907 | ret = vmw_execbuf_process(file_priv, dev_priv, NULL, blits, |
Jakob Bornecrantz | bd49ae4 | 2012-02-09 16:56:44 +0100 | [diff] [blame] | 908 | fifo_size, 0, NULL, out_fence); |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 909 | |
| 910 | if (unlikely(ret != 0)) |
| 911 | break; |
| 912 | } |
| 913 | |
| 914 | kfree(blits); |
| 915 | |
| 916 | return ret; |
| 917 | } |
| 918 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 919 | int vmw_framebuffer_dmabuf_dirty(struct drm_framebuffer *framebuffer, |
Thomas Hellstrom | 02b0016 | 2010-10-05 12:43:02 +0200 | [diff] [blame] | 920 | struct drm_file *file_priv, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 921 | unsigned flags, unsigned color, |
| 922 | struct drm_clip_rect *clips, |
| 923 | unsigned num_clips) |
| 924 | { |
| 925 | struct vmw_private *dev_priv = vmw_priv(framebuffer->dev); |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 926 | struct vmw_master *vmaster = vmw_master(file_priv->master); |
Jakob Bornecrantz | 5deb65c | 2011-10-04 20:13:18 +0200 | [diff] [blame] | 927 | struct vmw_framebuffer_dmabuf *vfbd = |
| 928 | vmw_framebuffer_to_vfbd(framebuffer); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 929 | struct drm_clip_rect norect; |
Jakob Bornecrantz | 5deb65c | 2011-10-04 20:13:18 +0200 | [diff] [blame] | 930 | int ret, increment = 1; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 931 | |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 932 | ret = ttm_read_lock(&vmaster->lock, true); |
| 933 | if (unlikely(ret != 0)) |
| 934 | return ret; |
| 935 | |
Thomas Hellstrom | df1c93b | 2010-01-13 22:28:36 +0100 | [diff] [blame] | 936 | if (!num_clips) { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 937 | num_clips = 1; |
| 938 | clips = &norect; |
| 939 | norect.x1 = norect.y1 = 0; |
| 940 | norect.x2 = framebuffer->width; |
| 941 | norect.y2 = framebuffer->height; |
| 942 | } else if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY) { |
| 943 | num_clips /= 2; |
| 944 | increment = 2; |
| 945 | } |
| 946 | |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 947 | if (dev_priv->ldu_priv) { |
Jakob Bornecrantz | c5c4236 | 2011-10-22 10:29:34 +0200 | [diff] [blame] | 948 | ret = do_dmabuf_dirty_ldu(dev_priv, &vfbd->base, |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 949 | flags, color, |
| 950 | clips, num_clips, increment); |
| 951 | } else { |
| 952 | ret = do_dmabuf_dirty_sou(file_priv, dev_priv, &vfbd->base, |
Jakob Bornecrantz | c5c4236 | 2011-10-22 10:29:34 +0200 | [diff] [blame] | 953 | flags, color, |
Jakob Bornecrantz | bd49ae4 | 2012-02-09 16:56:44 +0100 | [diff] [blame] | 954 | clips, num_clips, increment, NULL); |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 955 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 956 | |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 957 | ttm_read_unlock(&vmaster->lock); |
Jakob Bornecrantz | 5deb65c | 2011-10-04 20:13:18 +0200 | [diff] [blame] | 958 | return ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | static struct drm_framebuffer_funcs vmw_framebuffer_dmabuf_funcs = { |
| 962 | .destroy = vmw_framebuffer_dmabuf_destroy, |
| 963 | .dirty = vmw_framebuffer_dmabuf_dirty, |
| 964 | .create_handle = vmw_framebuffer_create_handle, |
| 965 | }; |
| 966 | |
Jakob Bornecrantz | 497a3ff | 2011-10-04 20:13:14 +0200 | [diff] [blame] | 967 | /** |
Jakob Bornecrantz | 497a3ff | 2011-10-04 20:13:14 +0200 | [diff] [blame] | 968 | * Pin the dmabuffer to the start of vram. |
| 969 | */ |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 970 | static int vmw_framebuffer_dmabuf_pin(struct vmw_framebuffer *vfb) |
| 971 | { |
| 972 | struct vmw_private *dev_priv = vmw_priv(vfb->base.dev); |
| 973 | struct vmw_framebuffer_dmabuf *vfbd = |
| 974 | vmw_framebuffer_to_vfbd(&vfb->base); |
| 975 | int ret; |
| 976 | |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 977 | /* This code should not be used with screen objects */ |
| 978 | BUG_ON(dev_priv->sou_priv); |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 979 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 980 | vmw_overlay_pause_all(dev_priv); |
| 981 | |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 982 | ret = vmw_dmabuf_to_start_of_vram(dev_priv, vfbd->buffer, true, false); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 983 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 984 | vmw_overlay_resume_all(dev_priv); |
| 985 | |
Jakob Bornecrantz | 316ab13 | 2010-05-28 11:22:05 +0200 | [diff] [blame] | 986 | WARN_ON(ret != 0); |
| 987 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 988 | return 0; |
| 989 | } |
| 990 | |
| 991 | static int vmw_framebuffer_dmabuf_unpin(struct vmw_framebuffer *vfb) |
| 992 | { |
| 993 | struct vmw_private *dev_priv = vmw_priv(vfb->base.dev); |
| 994 | struct vmw_framebuffer_dmabuf *vfbd = |
| 995 | vmw_framebuffer_to_vfbd(&vfb->base); |
| 996 | |
| 997 | if (!vfbd->buffer) { |
| 998 | WARN_ON(!vfbd->buffer); |
| 999 | return 0; |
| 1000 | } |
| 1001 | |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 1002 | return vmw_dmabuf_unpin(dev_priv, vfbd->buffer, false); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1003 | } |
| 1004 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1005 | static int vmw_kms_new_framebuffer_dmabuf(struct vmw_private *dev_priv, |
| 1006 | struct vmw_dma_buffer *dmabuf, |
| 1007 | struct vmw_framebuffer **out, |
| 1008 | const struct drm_mode_fb_cmd |
| 1009 | *mode_cmd) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1010 | |
| 1011 | { |
| 1012 | struct drm_device *dev = dev_priv->dev; |
| 1013 | struct vmw_framebuffer_dmabuf *vfbd; |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1014 | unsigned int requested_size; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1015 | int ret; |
| 1016 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1017 | requested_size = mode_cmd->height * mode_cmd->pitch; |
| 1018 | if (unlikely(requested_size > dmabuf->base.num_pages * PAGE_SIZE)) { |
| 1019 | DRM_ERROR("Screen buffer object size is too small " |
| 1020 | "for requested mode.\n"); |
| 1021 | return -EINVAL; |
| 1022 | } |
| 1023 | |
Jakob Bornecrantz | c337ada | 2011-10-04 20:13:34 +0200 | [diff] [blame] | 1024 | /* Limited framebuffer color depth support for screen objects */ |
| 1025 | if (dev_priv->sou_priv) { |
| 1026 | switch (mode_cmd->depth) { |
| 1027 | case 32: |
| 1028 | case 24: |
| 1029 | /* Only support 32 bpp for 32 and 24 depth fbs */ |
| 1030 | if (mode_cmd->bpp == 32) |
| 1031 | break; |
| 1032 | |
| 1033 | DRM_ERROR("Invalid color depth/bbp: %d %d\n", |
| 1034 | mode_cmd->depth, mode_cmd->bpp); |
| 1035 | return -EINVAL; |
| 1036 | case 16: |
| 1037 | case 15: |
| 1038 | /* Only support 16 bpp for 16 and 15 depth fbs */ |
| 1039 | if (mode_cmd->bpp == 16) |
| 1040 | break; |
| 1041 | |
| 1042 | DRM_ERROR("Invalid color depth/bbp: %d %d\n", |
| 1043 | mode_cmd->depth, mode_cmd->bpp); |
| 1044 | return -EINVAL; |
| 1045 | default: |
| 1046 | DRM_ERROR("Invalid color depth: %d\n", mode_cmd->depth); |
| 1047 | return -EINVAL; |
| 1048 | } |
| 1049 | } |
| 1050 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1051 | vfbd = kzalloc(sizeof(*vfbd), GFP_KERNEL); |
| 1052 | if (!vfbd) { |
| 1053 | ret = -ENOMEM; |
| 1054 | goto out_err1; |
| 1055 | } |
| 1056 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1057 | if (!vmw_dmabuf_reference(dmabuf)) { |
| 1058 | DRM_ERROR("failed to reference dmabuf %p\n", dmabuf); |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame^] | 1059 | ret = -EINVAL; |
| 1060 | goto out_err2; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1063 | vfbd->base.base.bits_per_pixel = mode_cmd->bpp; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 1064 | vfbd->base.base.pitches[0] = mode_cmd->pitch; |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1065 | vfbd->base.base.depth = mode_cmd->depth; |
| 1066 | vfbd->base.base.width = mode_cmd->width; |
| 1067 | vfbd->base.base.height = mode_cmd->height; |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 1068 | if (!dev_priv->sou_priv) { |
| 1069 | vfbd->base.pin = vmw_framebuffer_dmabuf_pin; |
| 1070 | vfbd->base.unpin = vmw_framebuffer_dmabuf_unpin; |
| 1071 | } |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1072 | vfbd->base.dmabuf = true; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1073 | vfbd->buffer = dmabuf; |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1074 | vfbd->base.user_handle = mode_cmd->handle; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1075 | *out = &vfbd->base; |
| 1076 | |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame^] | 1077 | ret = drm_framebuffer_init(dev, &vfbd->base.base, |
| 1078 | &vmw_framebuffer_dmabuf_funcs); |
| 1079 | if (ret) |
| 1080 | goto out_err3; |
| 1081 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1082 | return 0; |
| 1083 | |
| 1084 | out_err3: |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame^] | 1085 | vmw_dmabuf_unreference(&dmabuf); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1086 | out_err2: |
| 1087 | kfree(vfbd); |
| 1088 | out_err1: |
| 1089 | return ret; |
| 1090 | } |
| 1091 | |
| 1092 | /* |
| 1093 | * Generic Kernel modesetting functions |
| 1094 | */ |
| 1095 | |
| 1096 | static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev, |
| 1097 | struct drm_file *file_priv, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 1098 | struct drm_mode_fb_cmd2 *mode_cmd2) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1099 | { |
| 1100 | struct vmw_private *dev_priv = vmw_priv(dev); |
| 1101 | struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; |
| 1102 | struct vmw_framebuffer *vfb = NULL; |
| 1103 | struct vmw_surface *surface = NULL; |
| 1104 | struct vmw_dma_buffer *bo = NULL; |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1105 | struct ttm_base_object *user_obj; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 1106 | struct drm_mode_fb_cmd mode_cmd; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1107 | int ret; |
| 1108 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 1109 | mode_cmd.width = mode_cmd2->width; |
| 1110 | mode_cmd.height = mode_cmd2->height; |
| 1111 | mode_cmd.pitch = mode_cmd2->pitches[0]; |
| 1112 | mode_cmd.handle = mode_cmd2->handles[0]; |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 1113 | drm_fb_get_bpp_depth(mode_cmd2->pixel_format, &mode_cmd.depth, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 1114 | &mode_cmd.bpp); |
| 1115 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1116 | /** |
| 1117 | * This code should be conditioned on Screen Objects not being used. |
| 1118 | * If screen objects are used, we can allocate a GMR to hold the |
| 1119 | * requested framebuffer. |
| 1120 | */ |
| 1121 | |
Xi Wang | 8a78389 | 2011-12-21 05:18:33 -0500 | [diff] [blame] | 1122 | if (!vmw_kms_validate_mode_vram(dev_priv, |
Linus Torvalds | 1a464cb | 2012-01-10 11:04:36 -0800 | [diff] [blame] | 1123 | mode_cmd.pitch, |
| 1124 | mode_cmd.height)) { |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1125 | DRM_ERROR("VRAM size is too small for requested mode.\n"); |
Jakob Bornecrantz | d982640 | 2011-11-03 21:03:04 +0100 | [diff] [blame] | 1126 | return ERR_PTR(-ENOMEM); |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1127 | } |
| 1128 | |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1129 | /* |
| 1130 | * Take a reference on the user object of the resource |
| 1131 | * backing the kms fb. This ensures that user-space handle |
| 1132 | * lookups on that resource will always work as long as |
| 1133 | * it's registered with a kms framebuffer. This is important, |
| 1134 | * since vmw_execbuf_process identifies resources in the |
| 1135 | * command stream using user-space handles. |
| 1136 | */ |
| 1137 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 1138 | user_obj = ttm_base_object_lookup(tfile, mode_cmd.handle); |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1139 | if (unlikely(user_obj == NULL)) { |
| 1140 | DRM_ERROR("Could not locate requested kms frame buffer.\n"); |
| 1141 | return ERR_PTR(-ENOENT); |
| 1142 | } |
| 1143 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1144 | /** |
| 1145 | * End conditioned code. |
| 1146 | */ |
| 1147 | |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 1148 | /* returns either a dmabuf or surface */ |
| 1149 | ret = vmw_user_lookup_handle(dev_priv, tfile, |
Dave Airlie | 4cf7312 | 2011-12-21 09:50:56 +0000 | [diff] [blame] | 1150 | mode_cmd.handle, |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 1151 | &surface, &bo); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1152 | if (ret) |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 1153 | goto err_out; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1154 | |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 1155 | /* Create the new framebuffer depending one what we got back */ |
| 1156 | if (bo) |
| 1157 | ret = vmw_kms_new_framebuffer_dmabuf(dev_priv, bo, &vfb, |
Dave Airlie | 4cf7312 | 2011-12-21 09:50:56 +0000 | [diff] [blame] | 1158 | &mode_cmd); |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 1159 | else if (surface) |
| 1160 | ret = vmw_kms_new_framebuffer_surface(dev_priv, file_priv, |
Dave Airlie | 4cf7312 | 2011-12-21 09:50:56 +0000 | [diff] [blame] | 1161 | surface, &vfb, &mode_cmd); |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 1162 | else |
| 1163 | BUG(); |
Jakob Bornecrantz | 5ffdb65 | 2010-01-30 03:38:08 +0000 | [diff] [blame] | 1164 | |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 1165 | err_out: |
| 1166 | /* vmw_user_lookup_handle takes one ref so does new_fb */ |
| 1167 | if (bo) |
| 1168 | vmw_dmabuf_unreference(&bo); |
| 1169 | if (surface) |
| 1170 | vmw_surface_unreference(&surface); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1171 | |
| 1172 | if (ret) { |
| 1173 | DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret); |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1174 | ttm_base_object_unref(&user_obj); |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 1175 | return ERR_PTR(ret); |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1176 | } else |
| 1177 | vfb->user_obj = user_obj; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1178 | |
| 1179 | return &vfb->base; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 1182 | static const struct drm_mode_config_funcs vmw_kms_funcs = { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1183 | .fb_create = vmw_kms_fb_create, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1184 | }; |
| 1185 | |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1186 | int vmw_kms_present(struct vmw_private *dev_priv, |
| 1187 | struct drm_file *file_priv, |
| 1188 | struct vmw_framebuffer *vfb, |
| 1189 | struct vmw_surface *surface, |
| 1190 | uint32_t sid, |
| 1191 | int32_t destX, int32_t destY, |
| 1192 | struct drm_vmw_rect *clips, |
| 1193 | uint32_t num_clips) |
| 1194 | { |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 1195 | struct vmw_display_unit *units[VMWGFX_NUM_DISPLAY_UNITS]; |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 1196 | struct drm_clip_rect *tmp; |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 1197 | struct drm_crtc *crtc; |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1198 | size_t fifo_size; |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 1199 | int i, k, num_units; |
| 1200 | int ret = 0; /* silence warning */ |
Jakob Bornecrantz | 203dc22 | 2011-11-28 13:19:13 +0100 | [diff] [blame] | 1201 | int left, right, top, bottom; |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1202 | |
| 1203 | struct { |
| 1204 | SVGA3dCmdHeader header; |
| 1205 | SVGA3dCmdBlitSurfaceToScreen body; |
| 1206 | } *cmd; |
| 1207 | SVGASignedRect *blits; |
| 1208 | |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 1209 | num_units = 0; |
| 1210 | list_for_each_entry(crtc, &dev_priv->dev->mode_config.crtc_list, head) { |
| 1211 | if (crtc->fb != &vfb->base) |
| 1212 | continue; |
| 1213 | units[num_units++] = vmw_crtc_to_du(crtc); |
| 1214 | } |
| 1215 | |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1216 | BUG_ON(surface == NULL); |
| 1217 | BUG_ON(!clips || !num_clips); |
| 1218 | |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 1219 | tmp = kzalloc(sizeof(*tmp) * num_clips, GFP_KERNEL); |
| 1220 | if (unlikely(tmp == NULL)) { |
| 1221 | DRM_ERROR("Temporary cliprect memory alloc failed.\n"); |
| 1222 | return -ENOMEM; |
| 1223 | } |
| 1224 | |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1225 | fifo_size = sizeof(*cmd) + sizeof(SVGASignedRect) * num_clips; |
| 1226 | cmd = kmalloc(fifo_size, GFP_KERNEL); |
| 1227 | if (unlikely(cmd == NULL)) { |
| 1228 | DRM_ERROR("Failed to allocate temporary fifo memory.\n"); |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 1229 | ret = -ENOMEM; |
| 1230 | goto out_free_tmp; |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1231 | } |
| 1232 | |
Jakob Bornecrantz | 203dc22 | 2011-11-28 13:19:13 +0100 | [diff] [blame] | 1233 | left = clips->x; |
| 1234 | right = clips->x + clips->w; |
| 1235 | top = clips->y; |
| 1236 | bottom = clips->y + clips->h; |
| 1237 | |
| 1238 | for (i = 1; i < num_clips; i++) { |
| 1239 | left = min_t(int, left, (int)clips[i].x); |
| 1240 | right = max_t(int, right, (int)clips[i].x + clips[i].w); |
| 1241 | top = min_t(int, top, (int)clips[i].y); |
| 1242 | bottom = max_t(int, bottom, (int)clips[i].y + clips[i].h); |
| 1243 | } |
| 1244 | |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 1245 | /* only need to do this once */ |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1246 | memset(cmd, 0, fifo_size); |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1247 | cmd->header.id = cpu_to_le32(SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN); |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 1248 | |
| 1249 | blits = (SVGASignedRect *)&cmd[1]; |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1250 | |
Jakob Bornecrantz | 203dc22 | 2011-11-28 13:19:13 +0100 | [diff] [blame] | 1251 | cmd->body.srcRect.left = left; |
| 1252 | cmd->body.srcRect.right = right; |
| 1253 | cmd->body.srcRect.top = top; |
| 1254 | cmd->body.srcRect.bottom = bottom; |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1255 | |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1256 | for (i = 0; i < num_clips; i++) { |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 1257 | tmp[i].x1 = clips[i].x - left; |
| 1258 | tmp[i].x2 = clips[i].x + clips[i].w - left; |
| 1259 | tmp[i].y1 = clips[i].y - top; |
| 1260 | tmp[i].y2 = clips[i].y + clips[i].h - top; |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1261 | } |
| 1262 | |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 1263 | for (k = 0; k < num_units; k++) { |
| 1264 | struct vmw_display_unit *unit = units[k]; |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 1265 | struct vmw_clip_rect clip; |
| 1266 | int num; |
| 1267 | |
| 1268 | clip.x1 = left + destX - unit->crtc.x; |
| 1269 | clip.y1 = top + destY - unit->crtc.y; |
| 1270 | clip.x2 = right + destX - unit->crtc.x; |
| 1271 | clip.y2 = bottom + destY - unit->crtc.y; |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 1272 | |
| 1273 | /* skip any crtcs that misses the clip region */ |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 1274 | if (clip.x1 >= unit->crtc.mode.hdisplay || |
| 1275 | clip.y1 >= unit->crtc.mode.vdisplay || |
| 1276 | clip.x2 <= 0 || clip.y2 <= 0) |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 1277 | continue; |
| 1278 | |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 1279 | /* |
| 1280 | * In order for the clip rects to be correctly scaled |
| 1281 | * the src and dest rects needs to be the same size. |
| 1282 | */ |
| 1283 | cmd->body.destRect.left = clip.x1; |
| 1284 | cmd->body.destRect.right = clip.x2; |
| 1285 | cmd->body.destRect.top = clip.y1; |
| 1286 | cmd->body.destRect.bottom = clip.y2; |
| 1287 | |
| 1288 | /* create a clip rect of the crtc in dest coords */ |
| 1289 | clip.x2 = unit->crtc.mode.hdisplay - clip.x1; |
| 1290 | clip.y2 = unit->crtc.mode.vdisplay - clip.y1; |
| 1291 | clip.x1 = 0 - clip.x1; |
| 1292 | clip.y1 = 0 - clip.y1; |
| 1293 | |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 1294 | /* need to reset sid as it is changed by execbuf */ |
| 1295 | cmd->body.srcImage.sid = sid; |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 1296 | cmd->body.destScreenId = unit->unit; |
| 1297 | |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 1298 | /* clip and write blits to cmd stream */ |
| 1299 | vmw_clip_cliprects(tmp, num_clips, clip, blits, &num); |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 1300 | |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 1301 | /* if no cliprects hit skip this */ |
| 1302 | if (num == 0) |
| 1303 | continue; |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 1304 | |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 1305 | /* recalculate package length */ |
| 1306 | fifo_size = sizeof(*cmd) + sizeof(SVGASignedRect) * num; |
| 1307 | cmd->header.size = cpu_to_le32(fifo_size - sizeof(cmd->header)); |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 1308 | ret = vmw_execbuf_process(file_priv, dev_priv, NULL, cmd, |
Jakob Bornecrantz | bb1bd2f | 2012-02-09 16:56:43 +0100 | [diff] [blame] | 1309 | fifo_size, 0, NULL, NULL); |
Jakob Bornecrantz | c6ca839 | 2011-10-07 15:23:07 +0200 | [diff] [blame] | 1310 | |
| 1311 | if (unlikely(ret != 0)) |
| 1312 | break; |
| 1313 | } |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1314 | |
| 1315 | kfree(cmd); |
Jakob Bornecrantz | 6abff3c | 2011-11-28 13:19:15 +0100 | [diff] [blame] | 1316 | out_free_tmp: |
| 1317 | kfree(tmp); |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1318 | |
| 1319 | return ret; |
| 1320 | } |
| 1321 | |
| 1322 | int vmw_kms_readback(struct vmw_private *dev_priv, |
| 1323 | struct drm_file *file_priv, |
| 1324 | struct vmw_framebuffer *vfb, |
| 1325 | struct drm_vmw_fence_rep __user *user_fence_rep, |
| 1326 | struct drm_vmw_rect *clips, |
| 1327 | uint32_t num_clips) |
| 1328 | { |
| 1329 | struct vmw_framebuffer_dmabuf *vfbd = |
| 1330 | vmw_framebuffer_to_vfbd(&vfb->base); |
| 1331 | struct vmw_dma_buffer *dmabuf = vfbd->buffer; |
| 1332 | struct vmw_display_unit *units[VMWGFX_NUM_DISPLAY_UNITS]; |
| 1333 | struct drm_crtc *crtc; |
| 1334 | size_t fifo_size; |
| 1335 | int i, k, ret, num_units, blits_pos; |
| 1336 | |
| 1337 | struct { |
| 1338 | uint32_t header; |
| 1339 | SVGAFifoCmdDefineGMRFB body; |
| 1340 | } *cmd; |
| 1341 | struct { |
| 1342 | uint32_t header; |
| 1343 | SVGAFifoCmdBlitScreenToGMRFB body; |
| 1344 | } *blits; |
| 1345 | |
| 1346 | num_units = 0; |
| 1347 | list_for_each_entry(crtc, &dev_priv->dev->mode_config.crtc_list, head) { |
| 1348 | if (crtc->fb != &vfb->base) |
| 1349 | continue; |
| 1350 | units[num_units++] = vmw_crtc_to_du(crtc); |
| 1351 | } |
| 1352 | |
| 1353 | BUG_ON(dmabuf == NULL); |
| 1354 | BUG_ON(!clips || !num_clips); |
| 1355 | |
| 1356 | /* take a safe guess at fifo size */ |
| 1357 | fifo_size = sizeof(*cmd) + sizeof(*blits) * num_clips * num_units; |
| 1358 | cmd = kmalloc(fifo_size, GFP_KERNEL); |
| 1359 | if (unlikely(cmd == NULL)) { |
| 1360 | DRM_ERROR("Failed to allocate temporary fifo memory.\n"); |
| 1361 | return -ENOMEM; |
| 1362 | } |
| 1363 | |
| 1364 | memset(cmd, 0, fifo_size); |
| 1365 | cmd->header = SVGA_CMD_DEFINE_GMRFB; |
| 1366 | cmd->body.format.bitsPerPixel = vfb->base.bits_per_pixel; |
| 1367 | cmd->body.format.colorDepth = vfb->base.depth; |
| 1368 | cmd->body.format.reserved = 0; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 1369 | cmd->body.bytesPerLine = vfb->base.pitches[0]; |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1370 | cmd->body.ptr.gmrId = vfb->user_handle; |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1371 | cmd->body.ptr.offset = 0; |
| 1372 | |
| 1373 | blits = (void *)&cmd[1]; |
| 1374 | blits_pos = 0; |
| 1375 | for (i = 0; i < num_units; i++) { |
| 1376 | struct drm_vmw_rect *c = clips; |
| 1377 | for (k = 0; k < num_clips; k++, c++) { |
| 1378 | /* transform clip coords to crtc origin based coords */ |
| 1379 | int clip_x1 = c->x - units[i]->crtc.x; |
| 1380 | int clip_x2 = c->x - units[i]->crtc.x + c->w; |
| 1381 | int clip_y1 = c->y - units[i]->crtc.y; |
| 1382 | int clip_y2 = c->y - units[i]->crtc.y + c->h; |
| 1383 | int dest_x = c->x; |
| 1384 | int dest_y = c->y; |
| 1385 | |
| 1386 | /* compensate for clipping, we negate |
| 1387 | * a negative number and add that. |
| 1388 | */ |
| 1389 | if (clip_x1 < 0) |
| 1390 | dest_x += -clip_x1; |
| 1391 | if (clip_y1 < 0) |
| 1392 | dest_y += -clip_y1; |
| 1393 | |
| 1394 | /* clip */ |
| 1395 | clip_x1 = max(clip_x1, 0); |
| 1396 | clip_y1 = max(clip_y1, 0); |
| 1397 | clip_x2 = min(clip_x2, units[i]->crtc.mode.hdisplay); |
| 1398 | clip_y2 = min(clip_y2, units[i]->crtc.mode.vdisplay); |
| 1399 | |
| 1400 | /* and cull any rects that misses the crtc */ |
| 1401 | if (clip_x1 >= units[i]->crtc.mode.hdisplay || |
| 1402 | clip_y1 >= units[i]->crtc.mode.vdisplay || |
| 1403 | clip_x2 <= 0 || clip_y2 <= 0) |
| 1404 | continue; |
| 1405 | |
| 1406 | blits[blits_pos].header = SVGA_CMD_BLIT_SCREEN_TO_GMRFB; |
| 1407 | blits[blits_pos].body.srcScreenId = units[i]->unit; |
| 1408 | blits[blits_pos].body.destOrigin.x = dest_x; |
| 1409 | blits[blits_pos].body.destOrigin.y = dest_y; |
| 1410 | |
| 1411 | blits[blits_pos].body.srcRect.left = clip_x1; |
| 1412 | blits[blits_pos].body.srcRect.top = clip_y1; |
| 1413 | blits[blits_pos].body.srcRect.right = clip_x2; |
| 1414 | blits[blits_pos].body.srcRect.bottom = clip_y2; |
| 1415 | blits_pos++; |
| 1416 | } |
| 1417 | } |
| 1418 | /* reset size here and use calculated exact size from loops */ |
| 1419 | fifo_size = sizeof(*cmd) + sizeof(*blits) * blits_pos; |
| 1420 | |
| 1421 | ret = vmw_execbuf_process(file_priv, dev_priv, NULL, cmd, fifo_size, |
Jakob Bornecrantz | bb1bd2f | 2012-02-09 16:56:43 +0100 | [diff] [blame] | 1422 | 0, user_fence_rep, NULL); |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1423 | |
| 1424 | kfree(cmd); |
| 1425 | |
| 1426 | return ret; |
| 1427 | } |
| 1428 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1429 | int vmw_kms_init(struct vmw_private *dev_priv) |
| 1430 | { |
| 1431 | struct drm_device *dev = dev_priv->dev; |
| 1432 | int ret; |
| 1433 | |
| 1434 | drm_mode_config_init(dev); |
| 1435 | dev->mode_config.funcs = &vmw_kms_funcs; |
Jakob Bornecrantz | 3bef357 | 2010-02-09 19:41:57 +0000 | [diff] [blame] | 1436 | dev->mode_config.min_width = 1; |
| 1437 | dev->mode_config.min_height = 1; |
Jakob Bornecrantz | 7e71f8a | 2010-05-28 11:21:54 +0200 | [diff] [blame] | 1438 | /* assumed largest fb size */ |
| 1439 | dev->mode_config.max_width = 8192; |
| 1440 | dev->mode_config.max_height = 8192; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1441 | |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 1442 | ret = vmw_kms_init_screen_object_display(dev_priv); |
| 1443 | if (ret) /* Fallback */ |
| 1444 | (void)vmw_kms_init_legacy_display_system(dev_priv); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1445 | |
| 1446 | return 0; |
| 1447 | } |
| 1448 | |
| 1449 | int vmw_kms_close(struct vmw_private *dev_priv) |
| 1450 | { |
| 1451 | /* |
| 1452 | * Docs says we should take the lock before calling this function |
| 1453 | * but since it destroys encoders and our destructor calls |
| 1454 | * drm_encoder_cleanup which takes the lock we deadlock. |
| 1455 | */ |
| 1456 | drm_mode_config_cleanup(dev_priv->dev); |
Jakob Bornecrantz | c0d1831 | 2011-11-09 10:25:26 +0100 | [diff] [blame] | 1457 | if (dev_priv->sou_priv) |
| 1458 | vmw_kms_close_screen_object_display(dev_priv); |
| 1459 | else |
| 1460 | vmw_kms_close_legacy_display_system(dev_priv); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1461 | return 0; |
| 1462 | } |
| 1463 | |
| 1464 | int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data, |
| 1465 | struct drm_file *file_priv) |
| 1466 | { |
| 1467 | struct drm_vmw_cursor_bypass_arg *arg = data; |
| 1468 | struct vmw_display_unit *du; |
| 1469 | struct drm_mode_object *obj; |
| 1470 | struct drm_crtc *crtc; |
| 1471 | int ret = 0; |
| 1472 | |
| 1473 | |
| 1474 | mutex_lock(&dev->mode_config.mutex); |
| 1475 | if (arg->flags & DRM_VMW_CURSOR_BYPASS_ALL) { |
| 1476 | |
| 1477 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 1478 | du = vmw_crtc_to_du(crtc); |
| 1479 | du->hotspot_x = arg->xhot; |
| 1480 | du->hotspot_y = arg->yhot; |
| 1481 | } |
| 1482 | |
| 1483 | mutex_unlock(&dev->mode_config.mutex); |
| 1484 | return 0; |
| 1485 | } |
| 1486 | |
| 1487 | obj = drm_mode_object_find(dev, arg->crtc_id, DRM_MODE_OBJECT_CRTC); |
| 1488 | if (!obj) { |
| 1489 | ret = -EINVAL; |
| 1490 | goto out; |
| 1491 | } |
| 1492 | |
| 1493 | crtc = obj_to_crtc(obj); |
| 1494 | du = vmw_crtc_to_du(crtc); |
| 1495 | |
| 1496 | du->hotspot_x = arg->xhot; |
| 1497 | du->hotspot_y = arg->yhot; |
| 1498 | |
| 1499 | out: |
| 1500 | mutex_unlock(&dev->mode_config.mutex); |
| 1501 | |
| 1502 | return ret; |
| 1503 | } |
| 1504 | |
Michel Dänzer | 0bef23f | 2011-08-31 07:42:50 +0000 | [diff] [blame] | 1505 | int vmw_kms_write_svga(struct vmw_private *vmw_priv, |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 1506 | unsigned width, unsigned height, unsigned pitch, |
Michel Dänzer | 6558429b | 2011-08-31 07:42:49 +0000 | [diff] [blame] | 1507 | unsigned bpp, unsigned depth) |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 1508 | { |
| 1509 | if (vmw_priv->capabilities & SVGA_CAP_PITCHLOCK) |
| 1510 | vmw_write(vmw_priv, SVGA_REG_PITCHLOCK, pitch); |
| 1511 | else if (vmw_fifo_have_pitchlock(vmw_priv)) |
| 1512 | iowrite32(pitch, vmw_priv->mmio_virt + SVGA_FIFO_PITCHLOCK); |
| 1513 | vmw_write(vmw_priv, SVGA_REG_WIDTH, width); |
| 1514 | vmw_write(vmw_priv, SVGA_REG_HEIGHT, height); |
Michel Dänzer | 6558429b | 2011-08-31 07:42:49 +0000 | [diff] [blame] | 1515 | vmw_write(vmw_priv, SVGA_REG_BITS_PER_PIXEL, bpp); |
Michel Dänzer | 0bef23f | 2011-08-31 07:42:50 +0000 | [diff] [blame] | 1516 | |
| 1517 | if (vmw_read(vmw_priv, SVGA_REG_DEPTH) != depth) { |
| 1518 | DRM_ERROR("Invalid depth %u for %u bpp, host expects %u\n", |
| 1519 | depth, bpp, vmw_read(vmw_priv, SVGA_REG_DEPTH)); |
| 1520 | return -EINVAL; |
| 1521 | } |
| 1522 | |
| 1523 | return 0; |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 1524 | } |
| 1525 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1526 | int vmw_kms_save_vga(struct vmw_private *vmw_priv) |
| 1527 | { |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 1528 | struct vmw_vga_topology_state *save; |
| 1529 | uint32_t i; |
| 1530 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1531 | vmw_priv->vga_width = vmw_read(vmw_priv, SVGA_REG_WIDTH); |
| 1532 | vmw_priv->vga_height = vmw_read(vmw_priv, SVGA_REG_HEIGHT); |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 1533 | vmw_priv->vga_bpp = vmw_read(vmw_priv, SVGA_REG_BITS_PER_PIXEL); |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 1534 | if (vmw_priv->capabilities & SVGA_CAP_PITCHLOCK) |
| 1535 | vmw_priv->vga_pitchlock = |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 1536 | vmw_read(vmw_priv, SVGA_REG_PITCHLOCK); |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 1537 | else if (vmw_fifo_have_pitchlock(vmw_priv)) |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 1538 | vmw_priv->vga_pitchlock = ioread32(vmw_priv->mmio_virt + |
| 1539 | SVGA_FIFO_PITCHLOCK); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1540 | |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 1541 | if (!(vmw_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY)) |
| 1542 | return 0; |
| 1543 | |
| 1544 | vmw_priv->num_displays = vmw_read(vmw_priv, |
| 1545 | SVGA_REG_NUM_GUEST_DISPLAYS); |
| 1546 | |
Thomas Hellstrom | 029e50b | 2010-10-05 12:43:08 +0200 | [diff] [blame] | 1547 | if (vmw_priv->num_displays == 0) |
| 1548 | vmw_priv->num_displays = 1; |
| 1549 | |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 1550 | for (i = 0; i < vmw_priv->num_displays; ++i) { |
| 1551 | save = &vmw_priv->vga_save[i]; |
| 1552 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, i); |
| 1553 | save->primary = vmw_read(vmw_priv, SVGA_REG_DISPLAY_IS_PRIMARY); |
| 1554 | save->pos_x = vmw_read(vmw_priv, SVGA_REG_DISPLAY_POSITION_X); |
| 1555 | save->pos_y = vmw_read(vmw_priv, SVGA_REG_DISPLAY_POSITION_Y); |
| 1556 | save->width = vmw_read(vmw_priv, SVGA_REG_DISPLAY_WIDTH); |
| 1557 | save->height = vmw_read(vmw_priv, SVGA_REG_DISPLAY_HEIGHT); |
| 1558 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, SVGA_ID_INVALID); |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 1559 | if (i == 0 && vmw_priv->num_displays == 1 && |
| 1560 | save->width == 0 && save->height == 0) { |
| 1561 | |
| 1562 | /* |
| 1563 | * It should be fairly safe to assume that these |
| 1564 | * values are uninitialized. |
| 1565 | */ |
| 1566 | |
| 1567 | save->width = vmw_priv->vga_width - save->pos_x; |
| 1568 | save->height = vmw_priv->vga_height - save->pos_y; |
| 1569 | } |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 1570 | } |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 1571 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1572 | return 0; |
| 1573 | } |
| 1574 | |
| 1575 | int vmw_kms_restore_vga(struct vmw_private *vmw_priv) |
| 1576 | { |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 1577 | struct vmw_vga_topology_state *save; |
| 1578 | uint32_t i; |
| 1579 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1580 | vmw_write(vmw_priv, SVGA_REG_WIDTH, vmw_priv->vga_width); |
| 1581 | vmw_write(vmw_priv, SVGA_REG_HEIGHT, vmw_priv->vga_height); |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 1582 | vmw_write(vmw_priv, SVGA_REG_BITS_PER_PIXEL, vmw_priv->vga_bpp); |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 1583 | if (vmw_priv->capabilities & SVGA_CAP_PITCHLOCK) |
| 1584 | vmw_write(vmw_priv, SVGA_REG_PITCHLOCK, |
| 1585 | vmw_priv->vga_pitchlock); |
| 1586 | else if (vmw_fifo_have_pitchlock(vmw_priv)) |
| 1587 | iowrite32(vmw_priv->vga_pitchlock, |
| 1588 | vmw_priv->mmio_virt + SVGA_FIFO_PITCHLOCK); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1589 | |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 1590 | if (!(vmw_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY)) |
| 1591 | return 0; |
| 1592 | |
| 1593 | for (i = 0; i < vmw_priv->num_displays; ++i) { |
| 1594 | save = &vmw_priv->vga_save[i]; |
| 1595 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, i); |
| 1596 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_IS_PRIMARY, save->primary); |
| 1597 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_POSITION_X, save->pos_x); |
| 1598 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_POSITION_Y, save->pos_y); |
| 1599 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_WIDTH, save->width); |
| 1600 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_HEIGHT, save->height); |
| 1601 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, SVGA_ID_INVALID); |
| 1602 | } |
| 1603 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1604 | return 0; |
| 1605 | } |
Jakob Bornecrantz | d8bd19d | 2010-06-01 11:54:20 +0200 | [diff] [blame] | 1606 | |
Thomas Hellstrom | e133e737 | 2010-10-05 12:43:04 +0200 | [diff] [blame] | 1607 | bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv, |
| 1608 | uint32_t pitch, |
| 1609 | uint32_t height) |
| 1610 | { |
| 1611 | return ((u64) pitch * (u64) height) < (u64) dev_priv->vram_size; |
| 1612 | } |
| 1613 | |
Jakob Bornecrantz | 1c482ab | 2011-10-17 11:59:45 +0200 | [diff] [blame] | 1614 | |
| 1615 | /** |
| 1616 | * Function called by DRM code called with vbl_lock held. |
| 1617 | */ |
Thomas Hellstrom | 7a1c2f6 | 2010-10-01 10:21:49 +0200 | [diff] [blame] | 1618 | u32 vmw_get_vblank_counter(struct drm_device *dev, int crtc) |
| 1619 | { |
| 1620 | return 0; |
| 1621 | } |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1622 | |
Jakob Bornecrantz | 1c482ab | 2011-10-17 11:59:45 +0200 | [diff] [blame] | 1623 | /** |
| 1624 | * Function called by DRM code called with vbl_lock held. |
| 1625 | */ |
| 1626 | int vmw_enable_vblank(struct drm_device *dev, int crtc) |
| 1627 | { |
| 1628 | return -ENOSYS; |
| 1629 | } |
| 1630 | |
| 1631 | /** |
| 1632 | * Function called by DRM code called with vbl_lock held. |
| 1633 | */ |
| 1634 | void vmw_disable_vblank(struct drm_device *dev, int crtc) |
| 1635 | { |
| 1636 | } |
| 1637 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1638 | |
| 1639 | /* |
| 1640 | * Small shared kms functions. |
| 1641 | */ |
| 1642 | |
| 1643 | int vmw_du_update_layout(struct vmw_private *dev_priv, unsigned num, |
| 1644 | struct drm_vmw_rect *rects) |
| 1645 | { |
| 1646 | struct drm_device *dev = dev_priv->dev; |
| 1647 | struct vmw_display_unit *du; |
| 1648 | struct drm_connector *con; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1649 | |
| 1650 | mutex_lock(&dev->mode_config.mutex); |
| 1651 | |
| 1652 | #if 0 |
Thomas Hellstrom | 6ea77d1 | 2011-10-04 20:13:36 +0200 | [diff] [blame] | 1653 | { |
| 1654 | unsigned int i; |
| 1655 | |
| 1656 | DRM_INFO("%s: new layout ", __func__); |
| 1657 | for (i = 0; i < num; i++) |
| 1658 | DRM_INFO("(%i, %i %ux%u) ", rects[i].x, rects[i].y, |
| 1659 | rects[i].w, rects[i].h); |
| 1660 | DRM_INFO("\n"); |
| 1661 | } |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1662 | #endif |
| 1663 | |
| 1664 | list_for_each_entry(con, &dev->mode_config.connector_list, head) { |
| 1665 | du = vmw_connector_to_du(con); |
| 1666 | if (num > du->unit) { |
| 1667 | du->pref_width = rects[du->unit].w; |
| 1668 | du->pref_height = rects[du->unit].h; |
| 1669 | du->pref_active = true; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1670 | du->gui_x = rects[du->unit].x; |
| 1671 | du->gui_y = rects[du->unit].y; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1672 | } else { |
| 1673 | du->pref_width = 800; |
| 1674 | du->pref_height = 600; |
| 1675 | du->pref_active = false; |
| 1676 | } |
| 1677 | con->status = vmw_du_connector_detect(con, true); |
| 1678 | } |
| 1679 | |
| 1680 | mutex_unlock(&dev->mode_config.mutex); |
| 1681 | |
| 1682 | return 0; |
| 1683 | } |
| 1684 | |
Jakob Bornecrantz | b5ec427 | 2012-02-09 16:56:45 +0100 | [diff] [blame] | 1685 | int vmw_du_page_flip(struct drm_crtc *crtc, |
| 1686 | struct drm_framebuffer *fb, |
| 1687 | struct drm_pending_vblank_event *event) |
| 1688 | { |
| 1689 | struct vmw_private *dev_priv = vmw_priv(crtc->dev); |
| 1690 | struct drm_framebuffer *old_fb = crtc->fb; |
| 1691 | struct vmw_framebuffer *vfb = vmw_framebuffer_to_vfb(fb); |
Alan Cox | f5869a8 | 2012-08-20 14:44:52 +0000 | [diff] [blame] | 1692 | struct drm_file *file_priv ; |
Jakob Bornecrantz | b5ec427 | 2012-02-09 16:56:45 +0100 | [diff] [blame] | 1693 | struct vmw_fence_obj *fence = NULL; |
| 1694 | struct drm_clip_rect clips; |
| 1695 | int ret; |
| 1696 | |
Alan Cox | f5869a8 | 2012-08-20 14:44:52 +0000 | [diff] [blame] | 1697 | if (event == NULL) |
| 1698 | return -EINVAL; |
| 1699 | |
Jakob Bornecrantz | b5ec427 | 2012-02-09 16:56:45 +0100 | [diff] [blame] | 1700 | /* require ScreenObject support for page flipping */ |
| 1701 | if (!dev_priv->sou_priv) |
| 1702 | return -ENOSYS; |
| 1703 | |
Alan Cox | f5869a8 | 2012-08-20 14:44:52 +0000 | [diff] [blame] | 1704 | file_priv = event->base.file_priv; |
Jakob Bornecrantz | b5ec427 | 2012-02-09 16:56:45 +0100 | [diff] [blame] | 1705 | if (!vmw_kms_screen_object_flippable(dev_priv, crtc)) |
| 1706 | return -EINVAL; |
| 1707 | |
| 1708 | crtc->fb = fb; |
| 1709 | |
| 1710 | /* do a full screen dirty update */ |
| 1711 | clips.x1 = clips.y1 = 0; |
| 1712 | clips.x2 = fb->width; |
| 1713 | clips.y2 = fb->height; |
| 1714 | |
| 1715 | if (vfb->dmabuf) |
| 1716 | ret = do_dmabuf_dirty_sou(file_priv, dev_priv, vfb, |
| 1717 | 0, 0, &clips, 1, 1, &fence); |
| 1718 | else |
| 1719 | ret = do_surface_dirty_sou(dev_priv, file_priv, vfb, |
| 1720 | 0, 0, &clips, 1, 1, &fence); |
| 1721 | |
| 1722 | |
| 1723 | if (ret != 0) |
| 1724 | goto out_no_fence; |
| 1725 | if (!fence) { |
| 1726 | ret = -EINVAL; |
| 1727 | goto out_no_fence; |
| 1728 | } |
| 1729 | |
| 1730 | ret = vmw_event_fence_action_queue(file_priv, fence, |
| 1731 | &event->base, |
| 1732 | &event->event.tv_sec, |
| 1733 | &event->event.tv_usec, |
| 1734 | true); |
| 1735 | |
| 1736 | /* |
| 1737 | * No need to hold on to this now. The only cleanup |
| 1738 | * we need to do if we fail is unref the fence. |
| 1739 | */ |
| 1740 | vmw_fence_obj_unreference(&fence); |
| 1741 | |
| 1742 | if (vmw_crtc_to_du(crtc)->is_implicit) |
| 1743 | vmw_kms_screen_object_update_implicit_fb(dev_priv, crtc); |
| 1744 | |
| 1745 | return ret; |
| 1746 | |
| 1747 | out_no_fence: |
| 1748 | crtc->fb = old_fb; |
| 1749 | return ret; |
| 1750 | } |
| 1751 | |
| 1752 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1753 | void vmw_du_crtc_save(struct drm_crtc *crtc) |
| 1754 | { |
| 1755 | } |
| 1756 | |
| 1757 | void vmw_du_crtc_restore(struct drm_crtc *crtc) |
| 1758 | { |
| 1759 | } |
| 1760 | |
| 1761 | void vmw_du_crtc_gamma_set(struct drm_crtc *crtc, |
| 1762 | u16 *r, u16 *g, u16 *b, |
| 1763 | uint32_t start, uint32_t size) |
| 1764 | { |
| 1765 | struct vmw_private *dev_priv = vmw_priv(crtc->dev); |
| 1766 | int i; |
| 1767 | |
| 1768 | for (i = 0; i < size; i++) { |
| 1769 | DRM_DEBUG("%d r/g/b = 0x%04x / 0x%04x / 0x%04x\n", i, |
| 1770 | r[i], g[i], b[i]); |
| 1771 | vmw_write(dev_priv, SVGA_PALETTE_BASE + i * 3 + 0, r[i] >> 8); |
| 1772 | vmw_write(dev_priv, SVGA_PALETTE_BASE + i * 3 + 1, g[i] >> 8); |
| 1773 | vmw_write(dev_priv, SVGA_PALETTE_BASE + i * 3 + 2, b[i] >> 8); |
| 1774 | } |
| 1775 | } |
| 1776 | |
| 1777 | void vmw_du_connector_dpms(struct drm_connector *connector, int mode) |
| 1778 | { |
| 1779 | } |
| 1780 | |
| 1781 | void vmw_du_connector_save(struct drm_connector *connector) |
| 1782 | { |
| 1783 | } |
| 1784 | |
| 1785 | void vmw_du_connector_restore(struct drm_connector *connector) |
| 1786 | { |
| 1787 | } |
| 1788 | |
| 1789 | enum drm_connector_status |
| 1790 | vmw_du_connector_detect(struct drm_connector *connector, bool force) |
| 1791 | { |
| 1792 | uint32_t num_displays; |
| 1793 | struct drm_device *dev = connector->dev; |
| 1794 | struct vmw_private *dev_priv = vmw_priv(dev); |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1795 | struct vmw_display_unit *du = vmw_connector_to_du(connector); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1796 | |
| 1797 | mutex_lock(&dev_priv->hw_mutex); |
| 1798 | num_displays = vmw_read(dev_priv, SVGA_REG_NUM_DISPLAYS); |
| 1799 | mutex_unlock(&dev_priv->hw_mutex); |
| 1800 | |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1801 | return ((vmw_connector_to_du(connector)->unit < num_displays && |
| 1802 | du->pref_active) ? |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1803 | connector_status_connected : connector_status_disconnected); |
| 1804 | } |
| 1805 | |
| 1806 | static struct drm_display_mode vmw_kms_connector_builtin[] = { |
| 1807 | /* 640x480@60Hz */ |
| 1808 | { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656, |
| 1809 | 752, 800, 0, 480, 489, 492, 525, 0, |
| 1810 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
| 1811 | /* 800x600@60Hz */ |
| 1812 | { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840, |
| 1813 | 968, 1056, 0, 600, 601, 605, 628, 0, |
| 1814 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1815 | /* 1024x768@60Hz */ |
| 1816 | { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048, |
| 1817 | 1184, 1344, 0, 768, 771, 777, 806, 0, |
| 1818 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
| 1819 | /* 1152x864@75Hz */ |
| 1820 | { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216, |
| 1821 | 1344, 1600, 0, 864, 865, 868, 900, 0, |
| 1822 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1823 | /* 1280x768@60Hz */ |
| 1824 | { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344, |
| 1825 | 1472, 1664, 0, 768, 771, 778, 798, 0, |
| 1826 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1827 | /* 1280x800@60Hz */ |
| 1828 | { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352, |
| 1829 | 1480, 1680, 0, 800, 803, 809, 831, 0, |
| 1830 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
| 1831 | /* 1280x960@60Hz */ |
| 1832 | { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376, |
| 1833 | 1488, 1800, 0, 960, 961, 964, 1000, 0, |
| 1834 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1835 | /* 1280x1024@60Hz */ |
| 1836 | { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328, |
| 1837 | 1440, 1688, 0, 1024, 1025, 1028, 1066, 0, |
| 1838 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1839 | /* 1360x768@60Hz */ |
| 1840 | { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424, |
| 1841 | 1536, 1792, 0, 768, 771, 777, 795, 0, |
| 1842 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1843 | /* 1440x1050@60Hz */ |
| 1844 | { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488, |
| 1845 | 1632, 1864, 0, 1050, 1053, 1057, 1089, 0, |
| 1846 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1847 | /* 1440x900@60Hz */ |
| 1848 | { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520, |
| 1849 | 1672, 1904, 0, 900, 903, 909, 934, 0, |
| 1850 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1851 | /* 1600x1200@60Hz */ |
| 1852 | { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664, |
| 1853 | 1856, 2160, 0, 1200, 1201, 1204, 1250, 0, |
| 1854 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1855 | /* 1680x1050@60Hz */ |
| 1856 | { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784, |
| 1857 | 1960, 2240, 0, 1050, 1053, 1059, 1089, 0, |
| 1858 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1859 | /* 1792x1344@60Hz */ |
| 1860 | { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920, |
| 1861 | 2120, 2448, 0, 1344, 1345, 1348, 1394, 0, |
| 1862 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1863 | /* 1853x1392@60Hz */ |
| 1864 | { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952, |
| 1865 | 2176, 2528, 0, 1392, 1393, 1396, 1439, 0, |
| 1866 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1867 | /* 1920x1200@60Hz */ |
| 1868 | { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056, |
| 1869 | 2256, 2592, 0, 1200, 1203, 1209, 1245, 0, |
| 1870 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1871 | /* 1920x1440@60Hz */ |
| 1872 | { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048, |
| 1873 | 2256, 2600, 0, 1440, 1441, 1444, 1500, 0, |
| 1874 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1875 | /* 2560x1600@60Hz */ |
| 1876 | { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752, |
| 1877 | 3032, 3504, 0, 1600, 1603, 1609, 1658, 0, |
| 1878 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1879 | /* Terminate */ |
| 1880 | { DRM_MODE("", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) }, |
| 1881 | }; |
| 1882 | |
Thomas Hellstrom | 1543b4dd | 2011-11-02 09:43:10 +0100 | [diff] [blame] | 1883 | /** |
| 1884 | * vmw_guess_mode_timing - Provide fake timings for a |
| 1885 | * 60Hz vrefresh mode. |
| 1886 | * |
| 1887 | * @mode - Pointer to a struct drm_display_mode with hdisplay and vdisplay |
| 1888 | * members filled in. |
| 1889 | */ |
| 1890 | static void vmw_guess_mode_timing(struct drm_display_mode *mode) |
| 1891 | { |
| 1892 | mode->hsync_start = mode->hdisplay + 50; |
| 1893 | mode->hsync_end = mode->hsync_start + 50; |
| 1894 | mode->htotal = mode->hsync_end + 50; |
| 1895 | |
| 1896 | mode->vsync_start = mode->vdisplay + 50; |
| 1897 | mode->vsync_end = mode->vsync_start + 50; |
| 1898 | mode->vtotal = mode->vsync_end + 50; |
| 1899 | |
| 1900 | mode->clock = (u32)mode->htotal * (u32)mode->vtotal / 100 * 6; |
| 1901 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 1902 | } |
| 1903 | |
| 1904 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1905 | int vmw_du_connector_fill_modes(struct drm_connector *connector, |
| 1906 | uint32_t max_width, uint32_t max_height) |
| 1907 | { |
| 1908 | struct vmw_display_unit *du = vmw_connector_to_du(connector); |
| 1909 | struct drm_device *dev = connector->dev; |
| 1910 | struct vmw_private *dev_priv = vmw_priv(dev); |
| 1911 | struct drm_display_mode *mode = NULL; |
| 1912 | struct drm_display_mode *bmode; |
| 1913 | struct drm_display_mode prefmode = { DRM_MODE("preferred", |
| 1914 | DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED, |
| 1915 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 1916 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) |
| 1917 | }; |
| 1918 | int i; |
| 1919 | |
| 1920 | /* Add preferred mode */ |
| 1921 | { |
| 1922 | mode = drm_mode_duplicate(dev, &prefmode); |
| 1923 | if (!mode) |
| 1924 | return 0; |
| 1925 | mode->hdisplay = du->pref_width; |
| 1926 | mode->vdisplay = du->pref_height; |
Thomas Hellstrom | 1543b4dd | 2011-11-02 09:43:10 +0100 | [diff] [blame] | 1927 | vmw_guess_mode_timing(mode); |
Jakob Bornecrantz | 55bde5b | 2011-11-03 21:03:05 +0100 | [diff] [blame] | 1928 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1929 | if (vmw_kms_validate_mode_vram(dev_priv, mode->hdisplay * 2, |
| 1930 | mode->vdisplay)) { |
| 1931 | drm_mode_probed_add(connector, mode); |
Jakob Bornecrantz | 55bde5b | 2011-11-03 21:03:05 +0100 | [diff] [blame] | 1932 | } else { |
| 1933 | drm_mode_destroy(dev, mode); |
| 1934 | mode = NULL; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1935 | } |
Jakob Bornecrantz | 55bde5b | 2011-11-03 21:03:05 +0100 | [diff] [blame] | 1936 | |
| 1937 | if (du->pref_mode) { |
| 1938 | list_del_init(&du->pref_mode->head); |
| 1939 | drm_mode_destroy(dev, du->pref_mode); |
| 1940 | } |
| 1941 | |
| 1942 | /* mode might be null here, this is intended */ |
| 1943 | du->pref_mode = mode; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | for (i = 0; vmw_kms_connector_builtin[i].type != 0; i++) { |
| 1947 | bmode = &vmw_kms_connector_builtin[i]; |
| 1948 | if (bmode->hdisplay > max_width || |
| 1949 | bmode->vdisplay > max_height) |
| 1950 | continue; |
| 1951 | |
| 1952 | if (!vmw_kms_validate_mode_vram(dev_priv, bmode->hdisplay * 2, |
| 1953 | bmode->vdisplay)) |
| 1954 | continue; |
| 1955 | |
| 1956 | mode = drm_mode_duplicate(dev, bmode); |
| 1957 | if (!mode) |
| 1958 | return 0; |
| 1959 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 1960 | |
| 1961 | drm_mode_probed_add(connector, mode); |
| 1962 | } |
| 1963 | |
Jakob Bornecrantz | d41025c | 2011-11-03 21:03:07 +0100 | [diff] [blame] | 1964 | /* Move the prefered mode first, help apps pick the right mode. */ |
| 1965 | if (du->pref_mode) |
| 1966 | list_move(&du->pref_mode->head, &connector->probed_modes); |
| 1967 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1968 | drm_mode_connector_list_update(connector); |
| 1969 | |
| 1970 | return 1; |
| 1971 | } |
| 1972 | |
| 1973 | int vmw_du_connector_set_property(struct drm_connector *connector, |
| 1974 | struct drm_property *property, |
| 1975 | uint64_t val) |
| 1976 | { |
| 1977 | return 0; |
| 1978 | } |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1979 | |
| 1980 | |
| 1981 | int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data, |
| 1982 | struct drm_file *file_priv) |
| 1983 | { |
| 1984 | struct vmw_private *dev_priv = vmw_priv(dev); |
| 1985 | struct drm_vmw_update_layout_arg *arg = |
| 1986 | (struct drm_vmw_update_layout_arg *)data; |
| 1987 | struct vmw_master *vmaster = vmw_master(file_priv->master); |
| 1988 | void __user *user_rects; |
| 1989 | struct drm_vmw_rect *rects; |
| 1990 | unsigned rects_size; |
| 1991 | int ret; |
| 1992 | int i; |
| 1993 | struct drm_mode_config *mode_config = &dev->mode_config; |
| 1994 | |
| 1995 | ret = ttm_read_lock(&vmaster->lock, true); |
| 1996 | if (unlikely(ret != 0)) |
| 1997 | return ret; |
| 1998 | |
| 1999 | if (!arg->num_outputs) { |
| 2000 | struct drm_vmw_rect def_rect = {0, 0, 800, 600}; |
| 2001 | vmw_du_update_layout(dev_priv, 1, &def_rect); |
| 2002 | goto out_unlock; |
| 2003 | } |
| 2004 | |
| 2005 | rects_size = arg->num_outputs * sizeof(struct drm_vmw_rect); |
Xi Wang | bab9efc | 2011-11-28 12:25:43 +0100 | [diff] [blame] | 2006 | rects = kcalloc(arg->num_outputs, sizeof(struct drm_vmw_rect), |
| 2007 | GFP_KERNEL); |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2008 | if (unlikely(!rects)) { |
| 2009 | ret = -ENOMEM; |
| 2010 | goto out_unlock; |
| 2011 | } |
| 2012 | |
| 2013 | user_rects = (void __user *)(unsigned long)arg->rects; |
| 2014 | ret = copy_from_user(rects, user_rects, rects_size); |
| 2015 | if (unlikely(ret != 0)) { |
| 2016 | DRM_ERROR("Failed to get rects.\n"); |
| 2017 | ret = -EFAULT; |
| 2018 | goto out_free; |
| 2019 | } |
| 2020 | |
| 2021 | for (i = 0; i < arg->num_outputs; ++i) { |
Xi Wang | bab9efc | 2011-11-28 12:25:43 +0100 | [diff] [blame] | 2022 | if (rects[i].x < 0 || |
| 2023 | rects[i].y < 0 || |
| 2024 | rects[i].x + rects[i].w > mode_config->max_width || |
| 2025 | rects[i].y + rects[i].h > mode_config->max_height) { |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2026 | DRM_ERROR("Invalid GUI layout.\n"); |
| 2027 | ret = -EINVAL; |
| 2028 | goto out_free; |
| 2029 | } |
| 2030 | } |
| 2031 | |
| 2032 | vmw_du_update_layout(dev_priv, arg->num_outputs, rects); |
| 2033 | |
| 2034 | out_free: |
| 2035 | kfree(rects); |
| 2036 | out_unlock: |
| 2037 | ttm_read_unlock(&vmaster->lock); |
| 2038 | return ret; |
| 2039 | } |