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