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