Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
Sinclair Yeh | 54fbde8 | 2015-07-29 12:38:02 -0700 | [diff] [blame] | 3 | * Copyright © 2009-2015 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" |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 29 | #include <drm/drm_plane_helper.h> |
Sinclair Yeh | 9c2542a | 2017-03-23 11:33:39 -0700 | [diff] [blame] | 30 | #include <drm/drm_atomic.h> |
| 31 | #include <drm/drm_atomic_helper.h> |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 32 | #include <drm/drm_rect.h> |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 33 | |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 34 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 35 | /* Might need a hrtimer here? */ |
| 36 | #define VMWGFX_PRESENT_RATE ((HZ / 60 > 0) ? HZ / 60 : 1) |
| 37 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 38 | void vmw_du_cleanup(struct vmw_display_unit *du) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 39 | { |
Sinclair Yeh | 36cc79b | 2017-03-23 11:28:11 -0700 | [diff] [blame] | 40 | drm_plane_cleanup(&du->primary); |
| 41 | drm_plane_cleanup(&du->cursor); |
| 42 | |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 43 | drm_connector_unregister(&du->connector); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 44 | drm_crtc_cleanup(&du->crtc); |
| 45 | drm_encoder_cleanup(&du->encoder); |
| 46 | drm_connector_cleanup(&du->connector); |
| 47 | } |
| 48 | |
| 49 | /* |
| 50 | * Display Unit Cursor functions |
| 51 | */ |
| 52 | |
Sinclair Yeh | 36cc79b | 2017-03-23 11:28:11 -0700 | [diff] [blame] | 53 | static int vmw_cursor_update_image(struct vmw_private *dev_priv, |
| 54 | u32 *image, u32 width, u32 height, |
| 55 | u32 hotspotX, u32 hotspotY) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 56 | { |
| 57 | struct { |
| 58 | u32 cmd; |
| 59 | SVGAFifoCmdDefineAlphaCursor cursor; |
| 60 | } *cmd; |
| 61 | u32 image_size = width * height * 4; |
| 62 | u32 cmd_size = sizeof(*cmd) + image_size; |
| 63 | |
| 64 | if (!image) |
| 65 | return -EINVAL; |
| 66 | |
| 67 | cmd = vmw_fifo_reserve(dev_priv, cmd_size); |
| 68 | if (unlikely(cmd == NULL)) { |
| 69 | DRM_ERROR("Fifo reserve failed.\n"); |
| 70 | return -ENOMEM; |
| 71 | } |
| 72 | |
| 73 | memset(cmd, 0, sizeof(*cmd)); |
| 74 | |
| 75 | memcpy(&cmd[1], image, image_size); |
| 76 | |
Thomas Hellstrom | b9eb1a6 | 2015-04-02 02:39:45 -0700 | [diff] [blame] | 77 | cmd->cmd = SVGA_CMD_DEFINE_ALPHA_CURSOR; |
| 78 | cmd->cursor.id = 0; |
| 79 | cmd->cursor.width = width; |
| 80 | cmd->cursor.height = height; |
| 81 | cmd->cursor.hotspotX = hotspotX; |
| 82 | cmd->cursor.hotspotY = hotspotY; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 83 | |
Thomas Hellstrom | 4e0858a | 2015-11-05 02:18:55 -0800 | [diff] [blame] | 84 | vmw_fifo_commit_flush(dev_priv, cmd_size); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
Sinclair Yeh | 36cc79b | 2017-03-23 11:28:11 -0700 | [diff] [blame] | 89 | static int vmw_cursor_update_dmabuf(struct vmw_private *dev_priv, |
| 90 | struct vmw_dma_buffer *dmabuf, |
| 91 | u32 width, u32 height, |
| 92 | u32 hotspotX, u32 hotspotY) |
Jakob Bornecrantz | 6a91d97 | 2011-11-28 13:19:10 +0100 | [diff] [blame] | 93 | { |
| 94 | struct ttm_bo_kmap_obj map; |
| 95 | unsigned long kmap_offset; |
| 96 | unsigned long kmap_num; |
| 97 | void *virtual; |
| 98 | bool dummy; |
| 99 | int ret; |
| 100 | |
| 101 | kmap_offset = 0; |
| 102 | kmap_num = (width*height*4 + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 103 | |
Christian König | dfd5e50 | 2016-04-06 11:12:03 +0200 | [diff] [blame] | 104 | ret = ttm_bo_reserve(&dmabuf->base, true, false, NULL); |
Jakob Bornecrantz | 6a91d97 | 2011-11-28 13:19:10 +0100 | [diff] [blame] | 105 | if (unlikely(ret != 0)) { |
| 106 | DRM_ERROR("reserve failed\n"); |
| 107 | return -EINVAL; |
| 108 | } |
| 109 | |
| 110 | ret = ttm_bo_kmap(&dmabuf->base, kmap_offset, kmap_num, &map); |
| 111 | if (unlikely(ret != 0)) |
| 112 | goto err_unreserve; |
| 113 | |
| 114 | virtual = ttm_kmap_obj_virtual(&map, &dummy); |
| 115 | ret = vmw_cursor_update_image(dev_priv, virtual, width, height, |
| 116 | hotspotX, hotspotY); |
| 117 | |
| 118 | ttm_bo_kunmap(&map); |
| 119 | err_unreserve: |
| 120 | ttm_bo_unreserve(&dmabuf->base); |
| 121 | |
| 122 | return ret; |
| 123 | } |
| 124 | |
| 125 | |
Sinclair Yeh | 36cc79b | 2017-03-23 11:28:11 -0700 | [diff] [blame] | 126 | static void vmw_cursor_update_position(struct vmw_private *dev_priv, |
| 127 | bool show, int x, int y) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 128 | { |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 129 | u32 *fifo_mem = dev_priv->mmio_virt; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 130 | uint32_t count; |
| 131 | |
Sinclair Yeh | 36cc79b | 2017-03-23 11:28:11 -0700 | [diff] [blame] | 132 | spin_lock(&dev_priv->cursor_lock); |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 133 | vmw_mmio_write(show ? 1 : 0, fifo_mem + SVGA_FIFO_CURSOR_ON); |
| 134 | vmw_mmio_write(x, fifo_mem + SVGA_FIFO_CURSOR_X); |
| 135 | vmw_mmio_write(y, fifo_mem + SVGA_FIFO_CURSOR_Y); |
| 136 | count = vmw_mmio_read(fifo_mem + SVGA_FIFO_CURSOR_COUNT); |
| 137 | vmw_mmio_write(++count, fifo_mem + SVGA_FIFO_CURSOR_COUNT); |
Sinclair Yeh | 36cc79b | 2017-03-23 11:28:11 -0700 | [diff] [blame] | 138 | spin_unlock(&dev_priv->cursor_lock); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Thomas Hellstrom | 8fbf9d9 | 2015-11-26 19:45:16 +0100 | [diff] [blame] | 141 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 142 | void vmw_kms_cursor_snoop(struct vmw_surface *srf, |
| 143 | struct ttm_object_file *tfile, |
| 144 | struct ttm_buffer_object *bo, |
| 145 | SVGA3dCmdHeader *header) |
| 146 | { |
| 147 | struct ttm_bo_kmap_obj map; |
| 148 | unsigned long kmap_offset; |
| 149 | unsigned long kmap_num; |
| 150 | SVGA3dCopyBox *box; |
| 151 | unsigned box_count; |
| 152 | void *virtual; |
| 153 | bool dummy; |
| 154 | struct vmw_dma_cmd { |
| 155 | SVGA3dCmdHeader header; |
| 156 | SVGA3dCmdSurfaceDMA dma; |
| 157 | } *cmd; |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 158 | int i, ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 159 | |
| 160 | cmd = container_of(header, struct vmw_dma_cmd, header); |
| 161 | |
| 162 | /* No snooper installed */ |
| 163 | if (!srf->snooper.image) |
| 164 | return; |
| 165 | |
| 166 | if (cmd->dma.host.face != 0 || cmd->dma.host.mipmap != 0) { |
| 167 | DRM_ERROR("face and mipmap for cursors should never != 0\n"); |
| 168 | return; |
| 169 | } |
| 170 | |
| 171 | if (cmd->header.size < 64) { |
| 172 | DRM_ERROR("at least one full copy box must be given\n"); |
| 173 | return; |
| 174 | } |
| 175 | |
| 176 | box = (SVGA3dCopyBox *)&cmd[1]; |
| 177 | box_count = (cmd->header.size - sizeof(SVGA3dCmdSurfaceDMA)) / |
| 178 | sizeof(SVGA3dCopyBox); |
| 179 | |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 180 | if (cmd->dma.guest.ptr.offset % PAGE_SIZE || |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 181 | box->x != 0 || box->y != 0 || box->z != 0 || |
| 182 | box->srcx != 0 || box->srcy != 0 || box->srcz != 0 || |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 183 | box->d != 1 || box_count != 1) { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 184 | /* TODO handle none page aligned offsets */ |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 185 | /* TODO handle more dst & src != 0 */ |
| 186 | /* TODO handle more then one copy */ |
| 187 | DRM_ERROR("Cant snoop dma request for cursor!\n"); |
| 188 | DRM_ERROR("(%u, %u, %u) (%u, %u, %u) (%ux%ux%u) %u %u\n", |
| 189 | box->srcx, box->srcy, box->srcz, |
| 190 | box->x, box->y, box->z, |
| 191 | box->w, box->h, box->d, box_count, |
| 192 | cmd->dma.guest.ptr.offset); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 193 | return; |
| 194 | } |
| 195 | |
| 196 | kmap_offset = cmd->dma.guest.ptr.offset >> PAGE_SHIFT; |
| 197 | kmap_num = (64*64*4) >> PAGE_SHIFT; |
| 198 | |
Christian König | dfd5e50 | 2016-04-06 11:12:03 +0200 | [diff] [blame] | 199 | ret = ttm_bo_reserve(bo, true, false, NULL); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 200 | if (unlikely(ret != 0)) { |
| 201 | DRM_ERROR("reserve failed\n"); |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | ret = ttm_bo_kmap(bo, kmap_offset, kmap_num, &map); |
| 206 | if (unlikely(ret != 0)) |
| 207 | goto err_unreserve; |
| 208 | |
| 209 | virtual = ttm_kmap_obj_virtual(&map, &dummy); |
| 210 | |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 211 | if (box->w == 64 && cmd->dma.guest.pitch == 64*4) { |
| 212 | memcpy(srf->snooper.image, virtual, 64*64*4); |
| 213 | } else { |
| 214 | /* Image is unsigned pointer. */ |
| 215 | for (i = 0; i < box->h; i++) |
| 216 | memcpy(srf->snooper.image + i * 64, |
| 217 | virtual + i * cmd->dma.guest.pitch, |
| 218 | box->w * 4); |
| 219 | } |
| 220 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 221 | srf->snooper.age++; |
| 222 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 223 | ttm_bo_kunmap(&map); |
| 224 | err_unreserve: |
| 225 | ttm_bo_unreserve(bo); |
| 226 | } |
| 227 | |
Thomas Hellstrom | 8fbf9d9 | 2015-11-26 19:45:16 +0100 | [diff] [blame] | 228 | /** |
| 229 | * vmw_kms_legacy_hotspot_clear - Clear legacy hotspots |
| 230 | * |
| 231 | * @dev_priv: Pointer to the device private struct. |
| 232 | * |
| 233 | * Clears all legacy hotspots. |
| 234 | */ |
| 235 | void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv) |
| 236 | { |
| 237 | struct drm_device *dev = dev_priv->dev; |
| 238 | struct vmw_display_unit *du; |
| 239 | struct drm_crtc *crtc; |
| 240 | |
| 241 | drm_modeset_lock_all(dev); |
| 242 | drm_for_each_crtc(crtc, dev) { |
| 243 | du = vmw_crtc_to_du(crtc); |
| 244 | |
| 245 | du->hotspot_x = 0; |
| 246 | du->hotspot_y = 0; |
| 247 | } |
| 248 | drm_modeset_unlock_all(dev); |
| 249 | } |
| 250 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 251 | void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv) |
| 252 | { |
| 253 | struct drm_device *dev = dev_priv->dev; |
| 254 | struct vmw_display_unit *du; |
| 255 | struct drm_crtc *crtc; |
| 256 | |
| 257 | mutex_lock(&dev->mode_config.mutex); |
| 258 | |
| 259 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 260 | du = vmw_crtc_to_du(crtc); |
| 261 | if (!du->cursor_surface || |
| 262 | du->cursor_age == du->cursor_surface->snooper.age) |
| 263 | continue; |
| 264 | |
| 265 | du->cursor_age = du->cursor_surface->snooper.age; |
| 266 | vmw_cursor_update_image(dev_priv, |
| 267 | du->cursor_surface->snooper.image, |
Thomas Hellstrom | 8fbf9d9 | 2015-11-26 19:45:16 +0100 | [diff] [blame] | 268 | 64, 64, |
| 269 | du->hotspot_x + du->core_hotspot_x, |
| 270 | du->hotspot_y + du->core_hotspot_y); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | mutex_unlock(&dev->mode_config.mutex); |
| 274 | } |
| 275 | |
Sinclair Yeh | 36cc79b | 2017-03-23 11:28:11 -0700 | [diff] [blame] | 276 | |
| 277 | |
| 278 | /** |
| 279 | * vmw_du_cursor_plane_update() - Update cursor image and location |
| 280 | * |
| 281 | * @plane: plane object to update |
| 282 | * @crtc: owning CRTC of @plane |
| 283 | * @fb: framebuffer to flip onto plane |
| 284 | * @crtc_x: x offset of plane on crtc |
| 285 | * @crtc_y: y offset of plane on crtc |
| 286 | * @crtc_w: width of plane rectangle on crtc |
| 287 | * @crtc_h: height of plane rectangle on crtc |
| 288 | * @src_x: Not used |
| 289 | * @src_y: Not used |
| 290 | * @src_w: Not used |
| 291 | * @src_h: Not used |
| 292 | * |
| 293 | * |
| 294 | * RETURNS: |
| 295 | * Zero on success, error code on failure |
| 296 | */ |
| 297 | int vmw_du_cursor_plane_update(struct drm_plane *plane, |
| 298 | struct drm_crtc *crtc, |
| 299 | struct drm_framebuffer *fb, |
| 300 | int crtc_x, int crtc_y, |
| 301 | unsigned int crtc_w, |
| 302 | unsigned int crtc_h, |
| 303 | uint32_t src_x, uint32_t src_y, |
| 304 | uint32_t src_w, uint32_t src_h) |
| 305 | { |
| 306 | struct vmw_private *dev_priv = vmw_priv(crtc->dev); |
| 307 | struct vmw_display_unit *du = vmw_crtc_to_du(crtc); |
| 308 | struct vmw_surface *surface = NULL; |
| 309 | struct vmw_dma_buffer *dmabuf = NULL; |
| 310 | s32 hotspot_x, hotspot_y; |
| 311 | int ret; |
| 312 | |
| 313 | hotspot_x = du->hotspot_x + fb->hot_x; |
| 314 | hotspot_y = du->hotspot_y + fb->hot_y; |
| 315 | |
| 316 | /* A lot of the code assumes this */ |
| 317 | if (crtc_w != 64 || crtc_h != 64) { |
| 318 | ret = -EINVAL; |
| 319 | goto out; |
| 320 | } |
| 321 | |
| 322 | if (vmw_framebuffer_to_vfb(fb)->dmabuf) |
| 323 | dmabuf = vmw_framebuffer_to_vfbd(fb)->buffer; |
| 324 | else |
| 325 | surface = vmw_framebuffer_to_vfbs(fb)->surface; |
| 326 | |
| 327 | if (surface && !surface->snooper.image) { |
| 328 | DRM_ERROR("surface not suitable for cursor\n"); |
| 329 | ret = -EINVAL; |
| 330 | goto out; |
| 331 | } |
| 332 | |
| 333 | /* setup new image */ |
| 334 | ret = 0; |
| 335 | if (surface) { |
| 336 | /* vmw_user_surface_lookup takes one reference */ |
| 337 | du->cursor_surface = surface; |
| 338 | |
| 339 | du->cursor_age = du->cursor_surface->snooper.age; |
| 340 | |
| 341 | ret = vmw_cursor_update_image(dev_priv, surface->snooper.image, |
| 342 | 64, 64, hotspot_x, hotspot_y); |
| 343 | } else if (dmabuf) { |
| 344 | /* vmw_user_surface_lookup takes one reference */ |
| 345 | du->cursor_dmabuf = dmabuf; |
| 346 | |
| 347 | ret = vmw_cursor_update_dmabuf(dev_priv, dmabuf, crtc_w, crtc_h, |
| 348 | hotspot_x, hotspot_y); |
| 349 | } else { |
| 350 | vmw_cursor_update_position(dev_priv, false, 0, 0); |
| 351 | goto out; |
| 352 | } |
| 353 | |
| 354 | if (!ret) { |
| 355 | du->cursor_x = crtc_x + du->set_gui_x; |
| 356 | du->cursor_y = crtc_y + du->set_gui_y; |
| 357 | |
| 358 | vmw_cursor_update_position(dev_priv, true, |
| 359 | du->cursor_x + hotspot_x, |
| 360 | du->cursor_y + hotspot_y); |
| 361 | } |
| 362 | |
| 363 | out: |
| 364 | return ret; |
| 365 | } |
| 366 | |
| 367 | |
| 368 | int vmw_du_cursor_plane_disable(struct drm_plane *plane) |
| 369 | { |
| 370 | if (plane->fb) { |
| 371 | drm_framebuffer_unreference(plane->fb); |
| 372 | plane->fb = NULL; |
| 373 | } |
| 374 | |
| 375 | return -EINVAL; |
| 376 | } |
| 377 | |
| 378 | |
| 379 | void vmw_du_cursor_plane_destroy(struct drm_plane *plane) |
| 380 | { |
| 381 | vmw_cursor_update_position(plane->dev->dev_private, false, 0, 0); |
| 382 | |
| 383 | drm_plane_cleanup(plane); |
| 384 | } |
| 385 | |
| 386 | |
| 387 | void vmw_du_primary_plane_destroy(struct drm_plane *plane) |
| 388 | { |
| 389 | drm_plane_cleanup(plane); |
| 390 | |
| 391 | /* Planes are static in our case so we don't free it */ |
| 392 | } |
| 393 | |
| 394 | |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 395 | /** |
| 396 | * vmw_du_vps_unpin_surf - unpins resource associated with a framebuffer surface |
| 397 | * |
| 398 | * @vps: plane state associated with the display surface |
| 399 | * @unreference: true if we also want to unreference the display. |
| 400 | */ |
| 401 | void vmw_du_plane_unpin_surf(struct vmw_plane_state *vps, |
| 402 | bool unreference) |
| 403 | { |
| 404 | if (vps->surf) { |
| 405 | if (vps->pinned) { |
| 406 | vmw_resource_unpin(&vps->surf->res); |
| 407 | vps->pinned--; |
| 408 | } |
| 409 | |
| 410 | if (unreference) { |
| 411 | if (vps->pinned) |
| 412 | DRM_ERROR("Surface still pinned\n"); |
| 413 | vmw_surface_unreference(&vps->surf); |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | |
| 419 | /** |
| 420 | * vmw_du_plane_cleanup_fb - Unpins the cursor |
| 421 | * |
| 422 | * @plane: display plane |
| 423 | * @old_state: Contains the FB to clean up |
| 424 | * |
| 425 | * Unpins the framebuffer surface |
| 426 | * |
| 427 | * Returns 0 on success |
| 428 | */ |
| 429 | void |
| 430 | vmw_du_plane_cleanup_fb(struct drm_plane *plane, |
| 431 | struct drm_plane_state *old_state) |
| 432 | { |
| 433 | struct vmw_plane_state *vps = vmw_plane_state_to_vps(old_state); |
| 434 | |
| 435 | vmw_du_plane_unpin_surf(vps, false); |
| 436 | } |
| 437 | |
| 438 | |
| 439 | /** |
| 440 | * vmw_du_cursor_plane_prepare_fb - Readies the cursor by referencing it |
| 441 | * |
| 442 | * @plane: display plane |
| 443 | * @new_state: info on the new plane state, including the FB |
| 444 | * |
| 445 | * Returns 0 on success |
| 446 | */ |
| 447 | int |
| 448 | vmw_du_cursor_plane_prepare_fb(struct drm_plane *plane, |
| 449 | struct drm_plane_state *new_state) |
| 450 | { |
| 451 | struct drm_framebuffer *fb = new_state->fb; |
| 452 | struct vmw_plane_state *vps = vmw_plane_state_to_vps(new_state); |
| 453 | |
| 454 | |
| 455 | if (vps->surf) |
| 456 | vmw_surface_unreference(&vps->surf); |
| 457 | |
| 458 | if (vps->dmabuf) |
| 459 | vmw_dmabuf_unreference(&vps->dmabuf); |
| 460 | |
| 461 | if (fb) { |
| 462 | if (vmw_framebuffer_to_vfb(fb)->dmabuf) { |
| 463 | vps->dmabuf = vmw_framebuffer_to_vfbd(fb)->buffer; |
| 464 | vmw_dmabuf_reference(vps->dmabuf); |
| 465 | } else { |
| 466 | vps->surf = vmw_framebuffer_to_vfbs(fb)->surface; |
| 467 | vmw_surface_reference(vps->surf); |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | return 0; |
| 472 | } |
| 473 | |
| 474 | |
| 475 | void |
| 476 | vmw_du_cursor_plane_atomic_disable(struct drm_plane *plane, |
| 477 | struct drm_plane_state *old_state) |
| 478 | { |
| 479 | struct drm_crtc *crtc = plane->state->crtc ?: old_state->crtc; |
| 480 | struct vmw_private *dev_priv = vmw_priv(crtc->dev); |
| 481 | |
| 482 | drm_atomic_set_fb_for_plane(plane->state, NULL); |
| 483 | vmw_cursor_update_position(dev_priv, false, 0, 0); |
| 484 | } |
| 485 | |
| 486 | |
| 487 | void |
| 488 | vmw_du_cursor_plane_atomic_update(struct drm_plane *plane, |
| 489 | struct drm_plane_state *old_state) |
| 490 | { |
| 491 | struct drm_crtc *crtc = plane->state->crtc ?: old_state->crtc; |
| 492 | struct vmw_private *dev_priv = vmw_priv(crtc->dev); |
| 493 | struct vmw_display_unit *du = vmw_crtc_to_du(crtc); |
| 494 | struct vmw_plane_state *vps = vmw_plane_state_to_vps(plane->state); |
| 495 | s32 hotspot_x, hotspot_y; |
| 496 | int ret = 0; |
| 497 | |
| 498 | |
| 499 | hotspot_x = du->hotspot_x; |
| 500 | hotspot_y = du->hotspot_y; |
| 501 | du->cursor_surface = vps->surf; |
| 502 | du->cursor_dmabuf = vps->dmabuf; |
| 503 | |
| 504 | /* setup new image */ |
| 505 | if (vps->surf) { |
| 506 | du->cursor_age = du->cursor_surface->snooper.age; |
| 507 | |
| 508 | ret = vmw_cursor_update_image(dev_priv, |
| 509 | vps->surf->snooper.image, |
| 510 | 64, 64, hotspot_x, hotspot_y); |
| 511 | } else if (vps->dmabuf) { |
| 512 | ret = vmw_cursor_update_dmabuf(dev_priv, vps->dmabuf, |
| 513 | plane->state->crtc_w, |
| 514 | plane->state->crtc_h, |
| 515 | hotspot_x, hotspot_y); |
| 516 | } else { |
| 517 | vmw_cursor_update_position(dev_priv, false, 0, 0); |
| 518 | return; |
| 519 | } |
| 520 | |
| 521 | if (!ret) { |
| 522 | du->cursor_x = plane->state->crtc_x + du->set_gui_x; |
| 523 | du->cursor_y = plane->state->crtc_y + du->set_gui_y; |
| 524 | |
| 525 | vmw_cursor_update_position(dev_priv, true, |
| 526 | du->cursor_x + hotspot_x, |
| 527 | du->cursor_y + hotspot_y); |
| 528 | } else { |
| 529 | DRM_ERROR("Failed to update cursor image\n"); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | |
| 534 | /** |
| 535 | * vmw_du_primary_plane_atomic_check - check if the new state is okay |
| 536 | * |
| 537 | * @plane: display plane |
| 538 | * @state: info on the new plane state, including the FB |
| 539 | * |
| 540 | * Check if the new state is settable given the current state. Other |
| 541 | * than what the atomic helper checks, we care about crtc fitting |
| 542 | * the FB and maintaining one active framebuffer. |
| 543 | * |
| 544 | * Returns 0 on success |
| 545 | */ |
| 546 | int vmw_du_primary_plane_atomic_check(struct drm_plane *plane, |
| 547 | struct drm_plane_state *state) |
| 548 | { |
| 549 | struct drm_framebuffer *new_fb = state->fb; |
| 550 | bool visible; |
| 551 | |
| 552 | struct drm_rect src = { |
| 553 | .x1 = state->src_x, |
| 554 | .y1 = state->src_y, |
| 555 | .x2 = state->src_x + state->src_w, |
| 556 | .y2 = state->src_y + state->src_h, |
| 557 | }; |
| 558 | struct drm_rect dest = { |
| 559 | .x1 = state->crtc_x, |
| 560 | .y1 = state->crtc_y, |
| 561 | .x2 = state->crtc_x + state->crtc_w, |
| 562 | .y2 = state->crtc_y + state->crtc_h, |
| 563 | }; |
| 564 | struct drm_rect clip = dest; |
| 565 | int ret; |
| 566 | |
| 567 | ret = drm_plane_helper_check_update(plane, state->crtc, new_fb, |
| 568 | &src, &dest, &clip, |
| 569 | DRM_ROTATE_0, |
| 570 | DRM_PLANE_HELPER_NO_SCALING, |
| 571 | DRM_PLANE_HELPER_NO_SCALING, |
| 572 | false, true, &visible); |
| 573 | |
| 574 | |
| 575 | if (!ret && new_fb) { |
| 576 | struct drm_crtc *crtc = state->crtc; |
| 577 | struct vmw_connector_state *vcs; |
| 578 | struct vmw_display_unit *du = vmw_crtc_to_du(crtc); |
| 579 | struct vmw_private *dev_priv = vmw_priv(crtc->dev); |
| 580 | struct vmw_framebuffer *vfb = vmw_framebuffer_to_vfb(new_fb); |
| 581 | |
| 582 | vcs = vmw_connector_state_to_vcs(du->connector.state); |
| 583 | |
| 584 | if ((dest.x2 > new_fb->width || |
| 585 | dest.y2 > new_fb->height)) { |
| 586 | DRM_ERROR("CRTC area outside of framebuffer\n"); |
| 587 | return -EINVAL; |
| 588 | } |
| 589 | |
| 590 | /* Only one active implicit framebuffer at a time. */ |
| 591 | mutex_lock(&dev_priv->global_kms_state_mutex); |
| 592 | if (vcs->is_implicit && dev_priv->implicit_fb && |
| 593 | !(dev_priv->num_implicit == 1 && du->active_implicit) |
| 594 | && dev_priv->implicit_fb != vfb) { |
| 595 | DRM_ERROR("Multiple implicit framebuffers " |
| 596 | "not supported.\n"); |
| 597 | ret = -EINVAL; |
| 598 | } |
| 599 | mutex_unlock(&dev_priv->global_kms_state_mutex); |
| 600 | } |
| 601 | |
| 602 | |
| 603 | return ret; |
| 604 | } |
| 605 | |
| 606 | |
| 607 | /** |
| 608 | * vmw_du_cursor_plane_atomic_check - check if the new state is okay |
| 609 | * |
| 610 | * @plane: cursor plane |
| 611 | * @state: info on the new plane state |
| 612 | * |
| 613 | * This is a chance to fail if the new cursor state does not fit |
| 614 | * our requirements. |
| 615 | * |
| 616 | * Returns 0 on success |
| 617 | */ |
| 618 | int vmw_du_cursor_plane_atomic_check(struct drm_plane *plane, |
| 619 | struct drm_plane_state *new_state) |
| 620 | { |
| 621 | int ret = 0; |
| 622 | struct vmw_surface *surface = NULL; |
| 623 | struct drm_framebuffer *fb = new_state->fb; |
| 624 | |
| 625 | |
| 626 | /* Turning off */ |
| 627 | if (!fb) |
| 628 | return ret; |
| 629 | |
| 630 | /* A lot of the code assumes this */ |
| 631 | if (new_state->crtc_w != 64 || new_state->crtc_h != 64) { |
| 632 | DRM_ERROR("Invalid cursor dimensions (%d, %d)\n", |
| 633 | new_state->crtc_w, new_state->crtc_h); |
| 634 | ret = -EINVAL; |
| 635 | } |
| 636 | |
| 637 | if (!vmw_framebuffer_to_vfb(fb)->dmabuf) |
| 638 | surface = vmw_framebuffer_to_vfbs(fb)->surface; |
| 639 | |
| 640 | if (surface && !surface->snooper.image) { |
| 641 | DRM_ERROR("surface not suitable for cursor\n"); |
| 642 | ret = -EINVAL; |
| 643 | } |
| 644 | |
| 645 | return ret; |
| 646 | } |
| 647 | |
| 648 | |
Sinclair Yeh | 06ec419 | 2017-03-23 13:14:54 -0700 | [diff] [blame] | 649 | int vmw_du_crtc_atomic_check(struct drm_crtc *crtc, |
| 650 | struct drm_crtc_state *new_state) |
| 651 | { |
| 652 | struct vmw_display_unit *du = vmw_crtc_to_du(new_state->crtc); |
| 653 | int connector_mask = 1 << drm_connector_index(&du->connector); |
| 654 | bool has_primary = new_state->plane_mask & |
| 655 | BIT(drm_plane_index(crtc->primary)); |
| 656 | |
| 657 | /* We always want to have an active plane with an active CRTC */ |
| 658 | if (has_primary != new_state->enable) |
| 659 | return -EINVAL; |
| 660 | |
| 661 | |
| 662 | if (new_state->connector_mask != connector_mask && |
| 663 | new_state->connector_mask != 0) { |
| 664 | DRM_ERROR("Invalid connectors configuration\n"); |
| 665 | return -EINVAL; |
| 666 | } |
| 667 | |
| 668 | /* |
| 669 | * Our virtual device does not have a dot clock, so use the logical |
| 670 | * clock value as the dot clock. |
| 671 | */ |
| 672 | if (new_state->mode.crtc_clock == 0) |
| 673 | new_state->adjusted_mode.crtc_clock = new_state->mode.clock; |
| 674 | |
| 675 | return 0; |
| 676 | } |
| 677 | |
| 678 | |
| 679 | void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc, |
| 680 | struct drm_crtc_state *old_crtc_state) |
| 681 | { |
| 682 | } |
| 683 | |
| 684 | |
| 685 | void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc, |
| 686 | struct drm_crtc_state *old_crtc_state) |
| 687 | { |
| 688 | struct drm_pending_vblank_event *event = crtc->state->event; |
| 689 | |
| 690 | if (event) { |
| 691 | crtc->state->event = NULL; |
| 692 | |
| 693 | spin_lock_irq(&crtc->dev->event_lock); |
| 694 | if (drm_crtc_vblank_get(crtc) == 0) |
| 695 | drm_crtc_arm_vblank_event(crtc, event); |
| 696 | else |
| 697 | drm_crtc_send_vblank_event(crtc, event); |
| 698 | spin_unlock_irq(&crtc->dev->event_lock); |
| 699 | } |
| 700 | |
| 701 | } |
| 702 | |
| 703 | |
Sinclair Yeh | 9c2542a | 2017-03-23 11:33:39 -0700 | [diff] [blame] | 704 | /** |
| 705 | * vmw_du_crtc_duplicate_state - duplicate crtc state |
| 706 | * @crtc: DRM crtc |
| 707 | * |
| 708 | * Allocates and returns a copy of the crtc state (both common and |
| 709 | * vmw-specific) for the specified crtc. |
| 710 | * |
| 711 | * Returns: The newly allocated crtc state, or NULL on failure. |
| 712 | */ |
| 713 | struct drm_crtc_state * |
| 714 | vmw_du_crtc_duplicate_state(struct drm_crtc *crtc) |
| 715 | { |
| 716 | struct drm_crtc_state *state; |
| 717 | struct vmw_crtc_state *vcs; |
| 718 | |
| 719 | if (WARN_ON(!crtc->state)) |
| 720 | return NULL; |
| 721 | |
| 722 | vcs = kmemdup(crtc->state, sizeof(*vcs), GFP_KERNEL); |
| 723 | |
| 724 | if (!vcs) |
| 725 | return NULL; |
| 726 | |
| 727 | state = &vcs->base; |
| 728 | |
| 729 | __drm_atomic_helper_crtc_duplicate_state(crtc, state); |
| 730 | |
| 731 | return state; |
| 732 | } |
| 733 | |
| 734 | |
| 735 | /** |
| 736 | * vmw_du_crtc_reset - creates a blank vmw crtc state |
| 737 | * @crtc: DRM crtc |
| 738 | * |
| 739 | * Resets the atomic state for @crtc by freeing the state pointer (which |
| 740 | * might be NULL, e.g. at driver load time) and allocating a new empty state |
| 741 | * object. |
| 742 | */ |
| 743 | void vmw_du_crtc_reset(struct drm_crtc *crtc) |
| 744 | { |
| 745 | struct vmw_crtc_state *vcs; |
| 746 | |
| 747 | |
| 748 | if (crtc->state) { |
| 749 | __drm_atomic_helper_crtc_destroy_state(crtc->state); |
| 750 | |
| 751 | kfree(vmw_crtc_state_to_vcs(crtc->state)); |
| 752 | } |
| 753 | |
| 754 | vcs = kzalloc(sizeof(*vcs), GFP_KERNEL); |
| 755 | |
| 756 | if (!vcs) { |
| 757 | DRM_ERROR("Cannot allocate vmw_crtc_state\n"); |
| 758 | return; |
| 759 | } |
| 760 | |
| 761 | crtc->state = &vcs->base; |
| 762 | crtc->state->crtc = crtc; |
| 763 | } |
| 764 | |
| 765 | |
| 766 | /** |
| 767 | * vmw_du_crtc_destroy_state - destroy crtc state |
| 768 | * @crtc: DRM crtc |
| 769 | * @state: state object to destroy |
| 770 | * |
| 771 | * Destroys the crtc state (both common and vmw-specific) for the |
| 772 | * specified plane. |
| 773 | */ |
| 774 | void |
| 775 | vmw_du_crtc_destroy_state(struct drm_crtc *crtc, |
| 776 | struct drm_crtc_state *state) |
| 777 | { |
| 778 | drm_atomic_helper_crtc_destroy_state(crtc, state); |
| 779 | } |
| 780 | |
| 781 | |
Sinclair Yeh | cc5ec45 | 2017-03-23 11:36:05 -0700 | [diff] [blame] | 782 | /** |
| 783 | * vmw_du_plane_duplicate_state - duplicate plane state |
| 784 | * @plane: drm plane |
| 785 | * |
| 786 | * Allocates and returns a copy of the plane state (both common and |
| 787 | * vmw-specific) for the specified plane. |
| 788 | * |
| 789 | * Returns: The newly allocated plane state, or NULL on failure. |
| 790 | */ |
| 791 | struct drm_plane_state * |
| 792 | vmw_du_plane_duplicate_state(struct drm_plane *plane) |
| 793 | { |
| 794 | struct drm_plane_state *state; |
| 795 | struct vmw_plane_state *vps; |
| 796 | |
| 797 | vps = kmemdup(plane->state, sizeof(*vps), GFP_KERNEL); |
| 798 | |
| 799 | if (!vps) |
| 800 | return NULL; |
| 801 | |
| 802 | vps->pinned = 0; |
| 803 | |
Sinclair Yeh | 810b3e16 | 2017-03-23 15:39:16 -0700 | [diff] [blame] | 804 | /* Mapping is managed by prepare_fb/cleanup_fb */ |
| 805 | memset(&vps->guest_map, 0, sizeof(vps->guest_map)); |
| 806 | memset(&vps->host_map, 0, sizeof(vps->host_map)); |
| 807 | vps->cpp = 0; |
| 808 | |
Sinclair Yeh | cc5ec45 | 2017-03-23 11:36:05 -0700 | [diff] [blame] | 809 | /* Each ref counted resource needs to be acquired again */ |
| 810 | if (vps->surf) |
| 811 | (void) vmw_surface_reference(vps->surf); |
| 812 | |
| 813 | if (vps->dmabuf) |
| 814 | (void) vmw_dmabuf_reference(vps->dmabuf); |
| 815 | |
| 816 | state = &vps->base; |
| 817 | |
| 818 | __drm_atomic_helper_plane_duplicate_state(plane, state); |
| 819 | |
| 820 | return state; |
| 821 | } |
| 822 | |
| 823 | |
| 824 | /** |
| 825 | * vmw_du_plane_reset - creates a blank vmw plane state |
| 826 | * @plane: drm plane |
| 827 | * |
| 828 | * Resets the atomic state for @plane by freeing the state pointer (which might |
| 829 | * be NULL, e.g. at driver load time) and allocating a new empty state object. |
| 830 | */ |
| 831 | void vmw_du_plane_reset(struct drm_plane *plane) |
| 832 | { |
| 833 | struct vmw_plane_state *vps; |
| 834 | |
| 835 | |
| 836 | if (plane->state) |
| 837 | vmw_du_plane_destroy_state(plane, plane->state); |
| 838 | |
| 839 | vps = kzalloc(sizeof(*vps), GFP_KERNEL); |
| 840 | |
| 841 | if (!vps) { |
| 842 | DRM_ERROR("Cannot allocate vmw_plane_state\n"); |
| 843 | return; |
| 844 | } |
| 845 | |
| 846 | plane->state = &vps->base; |
| 847 | plane->state->plane = plane; |
| 848 | plane->state->rotation = DRM_ROTATE_0; |
| 849 | } |
| 850 | |
| 851 | |
| 852 | /** |
| 853 | * vmw_du_plane_destroy_state - destroy plane state |
| 854 | * @plane: DRM plane |
| 855 | * @state: state object to destroy |
| 856 | * |
| 857 | * Destroys the plane state (both common and vmw-specific) for the |
| 858 | * specified plane. |
| 859 | */ |
| 860 | void |
| 861 | vmw_du_plane_destroy_state(struct drm_plane *plane, |
| 862 | struct drm_plane_state *state) |
| 863 | { |
| 864 | struct vmw_plane_state *vps = vmw_plane_state_to_vps(state); |
| 865 | |
| 866 | |
Sinclair Yeh | 810b3e16 | 2017-03-23 15:39:16 -0700 | [diff] [blame] | 867 | /* Should have been freed by cleanup_fb */ |
| 868 | if (vps->guest_map.virtual) { |
| 869 | DRM_ERROR("Guest mapping not freed\n"); |
| 870 | ttm_bo_kunmap(&vps->guest_map); |
| 871 | } |
| 872 | |
| 873 | if (vps->host_map.virtual) { |
| 874 | DRM_ERROR("Host mapping not freed\n"); |
| 875 | ttm_bo_kunmap(&vps->host_map); |
| 876 | } |
| 877 | |
Sinclair Yeh | cc5ec45 | 2017-03-23 11:36:05 -0700 | [diff] [blame] | 878 | if (vps->surf) |
| 879 | vmw_surface_unreference(&vps->surf); |
| 880 | |
| 881 | if (vps->dmabuf) |
| 882 | vmw_dmabuf_unreference(&vps->dmabuf); |
| 883 | |
| 884 | drm_atomic_helper_plane_destroy_state(plane, state); |
| 885 | } |
| 886 | |
| 887 | |
Sinclair Yeh | d7721ca | 2017-03-23 11:48:44 -0700 | [diff] [blame] | 888 | /** |
| 889 | * vmw_du_connector_duplicate_state - duplicate connector state |
| 890 | * @connector: DRM connector |
| 891 | * |
| 892 | * Allocates and returns a copy of the connector state (both common and |
| 893 | * vmw-specific) for the specified connector. |
| 894 | * |
| 895 | * Returns: The newly allocated connector state, or NULL on failure. |
| 896 | */ |
| 897 | struct drm_connector_state * |
| 898 | vmw_du_connector_duplicate_state(struct drm_connector *connector) |
| 899 | { |
| 900 | struct drm_connector_state *state; |
| 901 | struct vmw_connector_state *vcs; |
| 902 | |
| 903 | if (WARN_ON(!connector->state)) |
| 904 | return NULL; |
| 905 | |
| 906 | vcs = kmemdup(connector->state, sizeof(*vcs), GFP_KERNEL); |
| 907 | |
| 908 | if (!vcs) |
| 909 | return NULL; |
| 910 | |
| 911 | state = &vcs->base; |
| 912 | |
| 913 | __drm_atomic_helper_connector_duplicate_state(connector, state); |
| 914 | |
| 915 | return state; |
| 916 | } |
| 917 | |
| 918 | |
| 919 | /** |
| 920 | * vmw_du_connector_reset - creates a blank vmw connector state |
| 921 | * @connector: DRM connector |
| 922 | * |
| 923 | * Resets the atomic state for @connector by freeing the state pointer (which |
| 924 | * might be NULL, e.g. at driver load time) and allocating a new empty state |
| 925 | * object. |
| 926 | */ |
| 927 | void vmw_du_connector_reset(struct drm_connector *connector) |
| 928 | { |
| 929 | struct vmw_connector_state *vcs; |
| 930 | |
| 931 | |
| 932 | if (connector->state) { |
| 933 | __drm_atomic_helper_connector_destroy_state(connector->state); |
| 934 | |
| 935 | kfree(vmw_connector_state_to_vcs(connector->state)); |
| 936 | } |
| 937 | |
| 938 | vcs = kzalloc(sizeof(*vcs), GFP_KERNEL); |
| 939 | |
| 940 | if (!vcs) { |
| 941 | DRM_ERROR("Cannot allocate vmw_connector_state\n"); |
| 942 | return; |
| 943 | } |
| 944 | |
| 945 | __drm_atomic_helper_connector_reset(connector, &vcs->base); |
| 946 | } |
| 947 | |
| 948 | |
| 949 | /** |
| 950 | * vmw_du_connector_destroy_state - destroy connector state |
| 951 | * @connector: DRM connector |
| 952 | * @state: state object to destroy |
| 953 | * |
| 954 | * Destroys the connector state (both common and vmw-specific) for the |
| 955 | * specified plane. |
| 956 | */ |
| 957 | void |
| 958 | vmw_du_connector_destroy_state(struct drm_connector *connector, |
| 959 | struct drm_connector_state *state) |
| 960 | { |
| 961 | drm_atomic_helper_connector_destroy_state(connector, state); |
| 962 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 963 | /* |
| 964 | * Generic framebuffer code |
| 965 | */ |
| 966 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 967 | /* |
| 968 | * Surface framebuffer code |
| 969 | */ |
| 970 | |
Rashika Kheria | 847c596 | 2014-01-06 22:18:10 +0530 | [diff] [blame] | 971 | static void vmw_framebuffer_surface_destroy(struct drm_framebuffer *framebuffer) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 972 | { |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 973 | struct vmw_framebuffer_surface *vfbs = |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 974 | vmw_framebuffer_to_vfbs(framebuffer); |
| 975 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 976 | drm_framebuffer_cleanup(framebuffer); |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 977 | vmw_surface_unreference(&vfbs->surface); |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 978 | if (vfbs->base.user_obj) |
| 979 | ttm_base_object_unref(&vfbs->base.user_obj); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 980 | |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 981 | kfree(vfbs); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 982 | } |
| 983 | |
Rashika Kheria | 847c596 | 2014-01-06 22:18:10 +0530 | [diff] [blame] | 984 | static int vmw_framebuffer_surface_dirty(struct drm_framebuffer *framebuffer, |
Thomas Hellstrom | 02b0016 | 2010-10-05 12:43:02 +0200 | [diff] [blame] | 985 | struct drm_file *file_priv, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 986 | unsigned flags, unsigned color, |
| 987 | struct drm_clip_rect *clips, |
| 988 | unsigned num_clips) |
| 989 | { |
| 990 | struct vmw_private *dev_priv = vmw_priv(framebuffer->dev); |
| 991 | struct vmw_framebuffer_surface *vfbs = |
| 992 | vmw_framebuffer_to_vfbs(framebuffer); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 993 | struct drm_clip_rect norect; |
Jakob Bornecrantz | 5deb65c | 2011-10-04 20:13:18 +0200 | [diff] [blame] | 994 | int ret, inc = 1; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 995 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 996 | /* Legacy Display Unit does not support 3D */ |
| 997 | if (dev_priv->active_display_unit == vmw_du_legacy) |
Jakob Bornecrantz | 01e8141 | 2011-10-04 20:13:24 +0200 | [diff] [blame] | 998 | return -EINVAL; |
| 999 | |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 1000 | drm_modeset_lock_all(dev_priv->dev); |
| 1001 | |
Thomas Hellstrom | 294adf7 | 2014-02-27 12:34:51 +0100 | [diff] [blame] | 1002 | ret = ttm_read_lock(&dev_priv->reservation_sem, true); |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 1003 | if (unlikely(ret != 0)) { |
| 1004 | drm_modeset_unlock_all(dev_priv->dev); |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 1005 | return ret; |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 1006 | } |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 1007 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1008 | if (!num_clips) { |
| 1009 | num_clips = 1; |
| 1010 | clips = &norect; |
| 1011 | norect.x1 = norect.y1 = 0; |
| 1012 | norect.x2 = framebuffer->width; |
| 1013 | norect.y2 = framebuffer->height; |
| 1014 | } else if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY) { |
| 1015 | num_clips /= 2; |
| 1016 | inc = 2; /* skip source rects */ |
| 1017 | } |
| 1018 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1019 | if (dev_priv->active_display_unit == vmw_du_screen_object) |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 1020 | ret = vmw_kms_sou_do_surface_dirty(dev_priv, &vfbs->base, |
| 1021 | clips, NULL, NULL, 0, 0, |
| 1022 | num_clips, inc, NULL); |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1023 | else |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1024 | ret = vmw_kms_stdu_surface_dirty(dev_priv, &vfbs->base, |
| 1025 | clips, NULL, NULL, 0, 0, |
| 1026 | num_clips, inc, NULL); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1027 | |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 1028 | vmw_fifo_flush(dev_priv, false); |
Thomas Hellstrom | 294adf7 | 2014-02-27 12:34:51 +0100 | [diff] [blame] | 1029 | ttm_read_unlock(&dev_priv->reservation_sem); |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 1030 | |
| 1031 | drm_modeset_unlock_all(dev_priv->dev); |
| 1032 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1033 | return 0; |
| 1034 | } |
| 1035 | |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 1036 | /** |
| 1037 | * vmw_kms_readback - Perform a readback from the screen system to |
| 1038 | * a dma-buffer backed framebuffer. |
| 1039 | * |
| 1040 | * @dev_priv: Pointer to the device private structure. |
| 1041 | * @file_priv: Pointer to a struct drm_file identifying the caller. |
| 1042 | * Must be set to NULL if @user_fence_rep is NULL. |
| 1043 | * @vfb: Pointer to the dma-buffer backed framebuffer. |
| 1044 | * @user_fence_rep: User-space provided structure for fence information. |
| 1045 | * Must be set to non-NULL if @file_priv is non-NULL. |
| 1046 | * @vclips: Array of clip rects. |
| 1047 | * @num_clips: Number of clip rects in @vclips. |
| 1048 | * |
| 1049 | * Returns 0 on success, negative error code on failure. -ERESTARTSYS if |
| 1050 | * interrupted. |
| 1051 | */ |
| 1052 | int vmw_kms_readback(struct vmw_private *dev_priv, |
| 1053 | struct drm_file *file_priv, |
| 1054 | struct vmw_framebuffer *vfb, |
| 1055 | struct drm_vmw_fence_rep __user *user_fence_rep, |
| 1056 | struct drm_vmw_rect *vclips, |
| 1057 | uint32_t num_clips) |
| 1058 | { |
| 1059 | switch (dev_priv->active_display_unit) { |
| 1060 | case vmw_du_screen_object: |
| 1061 | return vmw_kms_sou_readback(dev_priv, file_priv, vfb, |
| 1062 | user_fence_rep, vclips, num_clips); |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1063 | case vmw_du_screen_target: |
| 1064 | return vmw_kms_stdu_dma(dev_priv, file_priv, vfb, |
| 1065 | user_fence_rep, NULL, vclips, num_clips, |
| 1066 | 1, false, true); |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 1067 | default: |
| 1068 | WARN_ONCE(true, |
| 1069 | "Readback called with invalid display system.\n"); |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1070 | } |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 1071 | |
| 1072 | return -ENOSYS; |
| 1073 | } |
| 1074 | |
| 1075 | |
Ville Syrjälä | d7955fc | 2015-12-15 12:21:15 +0100 | [diff] [blame] | 1076 | static const struct drm_framebuffer_funcs vmw_framebuffer_surface_funcs = { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1077 | .destroy = vmw_framebuffer_surface_destroy, |
| 1078 | .dirty = vmw_framebuffer_surface_dirty, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1079 | }; |
| 1080 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1081 | static int vmw_kms_new_framebuffer_surface(struct vmw_private *dev_priv, |
| 1082 | struct vmw_surface *surface, |
| 1083 | struct vmw_framebuffer **out, |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1084 | const struct drm_mode_fb_cmd2 |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1085 | *mode_cmd, |
| 1086 | bool is_dmabuf_proxy) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1087 | |
| 1088 | { |
| 1089 | struct drm_device *dev = dev_priv->dev; |
| 1090 | struct vmw_framebuffer_surface *vfbs; |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1091 | enum SVGA3dSurfaceFormat format; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1092 | int ret; |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1093 | struct drm_format_name_buf format_name; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1094 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1095 | /* 3D is only supported on HWv8 and newer hosts */ |
| 1096 | if (dev_priv->active_display_unit == vmw_du_legacy) |
Jakob Bornecrantz | 01e8141 | 2011-10-04 20:13:24 +0200 | [diff] [blame] | 1097 | return -ENOSYS; |
| 1098 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1099 | /* |
| 1100 | * Sanity checks. |
| 1101 | */ |
| 1102 | |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 1103 | /* Surface must be marked as a scanout. */ |
| 1104 | if (unlikely(!surface->scanout)) |
| 1105 | return -EINVAL; |
| 1106 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1107 | if (unlikely(surface->mip_levels[0] != 1 || |
| 1108 | surface->num_sizes != 1 || |
Thomas Hellstrom | b360a3c | 2014-01-15 08:51:36 +0100 | [diff] [blame] | 1109 | surface->base_size.width < mode_cmd->width || |
| 1110 | surface->base_size.height < mode_cmd->height || |
| 1111 | surface->base_size.depth != 1)) { |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1112 | DRM_ERROR("Incompatible surface dimensions " |
| 1113 | "for requested mode.\n"); |
| 1114 | return -EINVAL; |
| 1115 | } |
| 1116 | |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1117 | switch (mode_cmd->pixel_format) { |
| 1118 | case DRM_FORMAT_ARGB8888: |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1119 | format = SVGA3D_A8R8G8B8; |
| 1120 | break; |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1121 | case DRM_FORMAT_XRGB8888: |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1122 | format = SVGA3D_X8R8G8B8; |
| 1123 | break; |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1124 | case DRM_FORMAT_RGB565: |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1125 | format = SVGA3D_R5G6B5; |
| 1126 | break; |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1127 | case DRM_FORMAT_XRGB1555: |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1128 | format = SVGA3D_A1R5G5B5; |
| 1129 | break; |
| 1130 | default: |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1131 | DRM_ERROR("Invalid pixel format: %s\n", |
| 1132 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1133 | return -EINVAL; |
| 1134 | } |
| 1135 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1136 | /* |
| 1137 | * For DX, surface format validation is done when surface->scanout |
| 1138 | * is set. |
| 1139 | */ |
| 1140 | if (!dev_priv->has_dx && format != surface->format) { |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1141 | DRM_ERROR("Invalid surface format for requested mode.\n"); |
| 1142 | return -EINVAL; |
| 1143 | } |
| 1144 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1145 | vfbs = kzalloc(sizeof(*vfbs), GFP_KERNEL); |
| 1146 | if (!vfbs) { |
| 1147 | ret = -ENOMEM; |
| 1148 | goto out_err1; |
| 1149 | } |
| 1150 | |
Ville Syrjälä | a3f913c | 2016-12-14 22:48:59 +0200 | [diff] [blame] | 1151 | drm_helper_mode_fill_fb_struct(dev, &vfbs->base.base, mode_cmd); |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1152 | vfbs->surface = vmw_surface_reference(surface); |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1153 | vfbs->base.user_handle = mode_cmd->handles[0]; |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1154 | vfbs->is_dmabuf_proxy = is_dmabuf_proxy; |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 1155 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1156 | *out = &vfbs->base; |
| 1157 | |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame] | 1158 | ret = drm_framebuffer_init(dev, &vfbs->base.base, |
| 1159 | &vmw_framebuffer_surface_funcs); |
| 1160 | if (ret) |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1161 | goto out_err2; |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame] | 1162 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1163 | return 0; |
| 1164 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1165 | out_err2: |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1166 | vmw_surface_unreference(&surface); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1167 | kfree(vfbs); |
| 1168 | out_err1: |
| 1169 | return ret; |
| 1170 | } |
| 1171 | |
| 1172 | /* |
| 1173 | * Dmabuf framebuffer code |
| 1174 | */ |
| 1175 | |
Rashika Kheria | 847c596 | 2014-01-06 22:18:10 +0530 | [diff] [blame] | 1176 | static void vmw_framebuffer_dmabuf_destroy(struct drm_framebuffer *framebuffer) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1177 | { |
| 1178 | struct vmw_framebuffer_dmabuf *vfbd = |
| 1179 | vmw_framebuffer_to_vfbd(framebuffer); |
| 1180 | |
| 1181 | drm_framebuffer_cleanup(framebuffer); |
| 1182 | vmw_dmabuf_unreference(&vfbd->buffer); |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 1183 | if (vfbd->base.user_obj) |
| 1184 | ttm_base_object_unref(&vfbd->base.user_obj); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1185 | |
| 1186 | kfree(vfbd); |
| 1187 | } |
| 1188 | |
Rashika Kheria | 847c596 | 2014-01-06 22:18:10 +0530 | [diff] [blame] | 1189 | static int vmw_framebuffer_dmabuf_dirty(struct drm_framebuffer *framebuffer, |
Thomas Hellstrom | 02b0016 | 2010-10-05 12:43:02 +0200 | [diff] [blame] | 1190 | struct drm_file *file_priv, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1191 | unsigned flags, unsigned color, |
| 1192 | struct drm_clip_rect *clips, |
| 1193 | unsigned num_clips) |
| 1194 | { |
| 1195 | struct vmw_private *dev_priv = vmw_priv(framebuffer->dev); |
Jakob Bornecrantz | 5deb65c | 2011-10-04 20:13:18 +0200 | [diff] [blame] | 1196 | struct vmw_framebuffer_dmabuf *vfbd = |
| 1197 | vmw_framebuffer_to_vfbd(framebuffer); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1198 | struct drm_clip_rect norect; |
Jakob Bornecrantz | 5deb65c | 2011-10-04 20:13:18 +0200 | [diff] [blame] | 1199 | int ret, increment = 1; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1200 | |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 1201 | drm_modeset_lock_all(dev_priv->dev); |
| 1202 | |
Thomas Hellstrom | 294adf7 | 2014-02-27 12:34:51 +0100 | [diff] [blame] | 1203 | ret = ttm_read_lock(&dev_priv->reservation_sem, true); |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 1204 | if (unlikely(ret != 0)) { |
| 1205 | drm_modeset_unlock_all(dev_priv->dev); |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 1206 | return ret; |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 1207 | } |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 1208 | |
Thomas Hellstrom | df1c93b | 2010-01-13 22:28:36 +0100 | [diff] [blame] | 1209 | if (!num_clips) { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1210 | num_clips = 1; |
| 1211 | clips = &norect; |
| 1212 | norect.x1 = norect.y1 = 0; |
| 1213 | norect.x2 = framebuffer->width; |
| 1214 | norect.y2 = framebuffer->height; |
| 1215 | } else if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY) { |
| 1216 | num_clips /= 2; |
| 1217 | increment = 2; |
| 1218 | } |
| 1219 | |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1220 | switch (dev_priv->active_display_unit) { |
| 1221 | case vmw_du_screen_target: |
| 1222 | ret = vmw_kms_stdu_dma(dev_priv, NULL, &vfbd->base, NULL, |
| 1223 | clips, NULL, num_clips, increment, |
| 1224 | true, true); |
| 1225 | break; |
| 1226 | case vmw_du_screen_object: |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 1227 | ret = vmw_kms_sou_do_dmabuf_dirty(dev_priv, &vfbd->base, |
Thomas Hellstrom | 897b818 | 2016-02-12 08:32:08 +0100 | [diff] [blame] | 1228 | clips, NULL, num_clips, |
| 1229 | increment, true, NULL); |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1230 | break; |
Thomas Hellstrom | 352b20dc | 2015-06-29 12:57:37 -0700 | [diff] [blame] | 1231 | case vmw_du_legacy: |
| 1232 | ret = vmw_kms_ldu_do_dmabuf_dirty(dev_priv, &vfbd->base, 0, 0, |
| 1233 | clips, num_clips, increment); |
| 1234 | break; |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1235 | default: |
Thomas Hellstrom | 352b20dc | 2015-06-29 12:57:37 -0700 | [diff] [blame] | 1236 | ret = -EINVAL; |
| 1237 | WARN_ONCE(true, "Dirty called with invalid display system.\n"); |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1238 | break; |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 1239 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1240 | |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 1241 | vmw_fifo_flush(dev_priv, false); |
Thomas Hellstrom | 294adf7 | 2014-02-27 12:34:51 +0100 | [diff] [blame] | 1242 | ttm_read_unlock(&dev_priv->reservation_sem); |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 1243 | |
| 1244 | drm_modeset_unlock_all(dev_priv->dev); |
| 1245 | |
Jakob Bornecrantz | 5deb65c | 2011-10-04 20:13:18 +0200 | [diff] [blame] | 1246 | return ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1247 | } |
| 1248 | |
Ville Syrjälä | d7955fc | 2015-12-15 12:21:15 +0100 | [diff] [blame] | 1249 | static const struct drm_framebuffer_funcs vmw_framebuffer_dmabuf_funcs = { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1250 | .destroy = vmw_framebuffer_dmabuf_destroy, |
| 1251 | .dirty = vmw_framebuffer_dmabuf_dirty, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1252 | }; |
| 1253 | |
Jakob Bornecrantz | 497a3ff | 2011-10-04 20:13:14 +0200 | [diff] [blame] | 1254 | /** |
Jakob Bornecrantz | 497a3ff | 2011-10-04 20:13:14 +0200 | [diff] [blame] | 1255 | * Pin the dmabuffer to the start of vram. |
| 1256 | */ |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1257 | static int vmw_framebuffer_pin(struct vmw_framebuffer *vfb) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1258 | { |
| 1259 | struct vmw_private *dev_priv = vmw_priv(vfb->base.dev); |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1260 | struct vmw_dma_buffer *buf; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1261 | int ret; |
| 1262 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1263 | buf = vfb->dmabuf ? vmw_framebuffer_to_vfbd(&vfb->base)->buffer : |
| 1264 | vmw_framebuffer_to_vfbs(&vfb->base)->surface->res.backup; |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 1265 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1266 | if (!buf) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1267 | return 0; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1268 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1269 | switch (dev_priv->active_display_unit) { |
| 1270 | case vmw_du_legacy: |
| 1271 | vmw_overlay_pause_all(dev_priv); |
| 1272 | ret = vmw_dmabuf_pin_in_start_of_vram(dev_priv, buf, false); |
| 1273 | vmw_overlay_resume_all(dev_priv); |
| 1274 | break; |
| 1275 | case vmw_du_screen_object: |
| 1276 | case vmw_du_screen_target: |
| 1277 | if (vfb->dmabuf) |
| 1278 | return vmw_dmabuf_pin_in_vram_or_gmr(dev_priv, buf, |
| 1279 | false); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1280 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1281 | return vmw_dmabuf_pin_in_placement(dev_priv, buf, |
| 1282 | &vmw_mob_placement, false); |
| 1283 | default: |
| 1284 | return -EINVAL; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1285 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1286 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1287 | return ret; |
| 1288 | } |
| 1289 | |
| 1290 | static int vmw_framebuffer_unpin(struct vmw_framebuffer *vfb) |
| 1291 | { |
| 1292 | struct vmw_private *dev_priv = vmw_priv(vfb->base.dev); |
| 1293 | struct vmw_dma_buffer *buf; |
| 1294 | |
| 1295 | buf = vfb->dmabuf ? vmw_framebuffer_to_vfbd(&vfb->base)->buffer : |
| 1296 | vmw_framebuffer_to_vfbs(&vfb->base)->surface->res.backup; |
| 1297 | |
| 1298 | if (WARN_ON(!buf)) |
| 1299 | return 0; |
| 1300 | |
| 1301 | return vmw_dmabuf_unpin(dev_priv, buf, false); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1302 | } |
| 1303 | |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1304 | /** |
| 1305 | * vmw_create_dmabuf_proxy - create a proxy surface for the DMA buf |
| 1306 | * |
| 1307 | * @dev: DRM device |
| 1308 | * @mode_cmd: parameters for the new surface |
| 1309 | * @dmabuf_mob: MOB backing the DMA buf |
| 1310 | * @srf_out: newly created surface |
| 1311 | * |
| 1312 | * When the content FB is a DMA buf, we create a surface as a proxy to the |
| 1313 | * same buffer. This way we can do a surface copy rather than a surface DMA. |
| 1314 | * This is a more efficient approach |
| 1315 | * |
| 1316 | * RETURNS: |
| 1317 | * 0 on success, error code otherwise |
| 1318 | */ |
| 1319 | static int vmw_create_dmabuf_proxy(struct drm_device *dev, |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1320 | const struct drm_mode_fb_cmd2 *mode_cmd, |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1321 | struct vmw_dma_buffer *dmabuf_mob, |
| 1322 | struct vmw_surface **srf_out) |
| 1323 | { |
| 1324 | uint32_t format; |
Thomas Hellstrom | 8cd9f25 | 2017-01-19 10:53:02 -0800 | [diff] [blame] | 1325 | struct drm_vmw_size content_base_size = {0}; |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1326 | struct vmw_resource *res; |
Thomas Hellstrom | a50e2bf | 2016-01-08 20:29:40 +0100 | [diff] [blame] | 1327 | unsigned int bytes_pp; |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1328 | struct drm_format_name_buf format_name; |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1329 | int ret; |
| 1330 | |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1331 | switch (mode_cmd->pixel_format) { |
| 1332 | case DRM_FORMAT_ARGB8888: |
| 1333 | case DRM_FORMAT_XRGB8888: |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1334 | format = SVGA3D_X8R8G8B8; |
Thomas Hellstrom | a50e2bf | 2016-01-08 20:29:40 +0100 | [diff] [blame] | 1335 | bytes_pp = 4; |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1336 | break; |
| 1337 | |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1338 | case DRM_FORMAT_RGB565: |
| 1339 | case DRM_FORMAT_XRGB1555: |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1340 | format = SVGA3D_R5G6B5; |
Thomas Hellstrom | a50e2bf | 2016-01-08 20:29:40 +0100 | [diff] [blame] | 1341 | bytes_pp = 2; |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1342 | break; |
| 1343 | |
| 1344 | case 8: |
| 1345 | format = SVGA3D_P8; |
Thomas Hellstrom | a50e2bf | 2016-01-08 20:29:40 +0100 | [diff] [blame] | 1346 | bytes_pp = 1; |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1347 | break; |
| 1348 | |
| 1349 | default: |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1350 | DRM_ERROR("Invalid framebuffer format %s\n", |
| 1351 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1352 | return -EINVAL; |
| 1353 | } |
| 1354 | |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1355 | content_base_size.width = mode_cmd->pitches[0] / bytes_pp; |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1356 | content_base_size.height = mode_cmd->height; |
| 1357 | content_base_size.depth = 1; |
| 1358 | |
| 1359 | ret = vmw_surface_gb_priv_define(dev, |
| 1360 | 0, /* kernel visible only */ |
| 1361 | 0, /* flags */ |
| 1362 | format, |
| 1363 | true, /* can be a scanout buffer */ |
| 1364 | 1, /* num of mip levels */ |
| 1365 | 0, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1366 | 0, |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1367 | content_base_size, |
| 1368 | srf_out); |
| 1369 | if (ret) { |
| 1370 | DRM_ERROR("Failed to allocate proxy content buffer\n"); |
| 1371 | return ret; |
| 1372 | } |
| 1373 | |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1374 | res = &(*srf_out)->res; |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1375 | |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1376 | /* Reserve and switch the backing mob. */ |
| 1377 | mutex_lock(&res->dev_priv->cmdbuf_mutex); |
| 1378 | (void) vmw_resource_reserve(res, false, true); |
| 1379 | vmw_dmabuf_unreference(&res->backup); |
| 1380 | res->backup = vmw_dmabuf_reference(dmabuf_mob); |
| 1381 | res->backup_offset = 0; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1382 | vmw_resource_unreserve(res, false, NULL, 0); |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1383 | mutex_unlock(&res->dev_priv->cmdbuf_mutex); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1384 | |
| 1385 | return 0; |
| 1386 | } |
| 1387 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1388 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1389 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1390 | static int vmw_kms_new_framebuffer_dmabuf(struct vmw_private *dev_priv, |
| 1391 | struct vmw_dma_buffer *dmabuf, |
| 1392 | struct vmw_framebuffer **out, |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1393 | const struct drm_mode_fb_cmd2 |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1394 | *mode_cmd) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1395 | |
| 1396 | { |
| 1397 | struct drm_device *dev = dev_priv->dev; |
| 1398 | struct vmw_framebuffer_dmabuf *vfbd; |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1399 | unsigned int requested_size; |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1400 | struct drm_format_name_buf format_name; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1401 | int ret; |
| 1402 | |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1403 | requested_size = mode_cmd->height * mode_cmd->pitches[0]; |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1404 | if (unlikely(requested_size > dmabuf->base.num_pages * PAGE_SIZE)) { |
| 1405 | DRM_ERROR("Screen buffer object size is too small " |
| 1406 | "for requested mode.\n"); |
| 1407 | return -EINVAL; |
| 1408 | } |
| 1409 | |
Jakob Bornecrantz | c337ada | 2011-10-04 20:13:34 +0200 | [diff] [blame] | 1410 | /* Limited framebuffer color depth support for screen objects */ |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1411 | if (dev_priv->active_display_unit == vmw_du_screen_object) { |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1412 | switch (mode_cmd->pixel_format) { |
| 1413 | case DRM_FORMAT_XRGB8888: |
| 1414 | case DRM_FORMAT_ARGB8888: |
| 1415 | break; |
| 1416 | case DRM_FORMAT_XRGB1555: |
| 1417 | case DRM_FORMAT_RGB565: |
| 1418 | break; |
Jakob Bornecrantz | c337ada | 2011-10-04 20:13:34 +0200 | [diff] [blame] | 1419 | default: |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1420 | DRM_ERROR("Invalid pixel format: %s\n", |
| 1421 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Jakob Bornecrantz | c337ada | 2011-10-04 20:13:34 +0200 | [diff] [blame] | 1422 | return -EINVAL; |
| 1423 | } |
| 1424 | } |
| 1425 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1426 | vfbd = kzalloc(sizeof(*vfbd), GFP_KERNEL); |
| 1427 | if (!vfbd) { |
| 1428 | ret = -ENOMEM; |
| 1429 | goto out_err1; |
| 1430 | } |
| 1431 | |
Ville Syrjälä | a3f913c | 2016-12-14 22:48:59 +0200 | [diff] [blame] | 1432 | drm_helper_mode_fill_fb_struct(dev, &vfbd->base.base, mode_cmd); |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1433 | vfbd->base.dmabuf = true; |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1434 | vfbd->buffer = vmw_dmabuf_reference(dmabuf); |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1435 | vfbd->base.user_handle = mode_cmd->handles[0]; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1436 | *out = &vfbd->base; |
| 1437 | |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame] | 1438 | ret = drm_framebuffer_init(dev, &vfbd->base.base, |
| 1439 | &vmw_framebuffer_dmabuf_funcs); |
| 1440 | if (ret) |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1441 | goto out_err2; |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame] | 1442 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1443 | return 0; |
| 1444 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1445 | out_err2: |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1446 | vmw_dmabuf_unreference(&dmabuf); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1447 | kfree(vfbd); |
| 1448 | out_err1: |
| 1449 | return ret; |
| 1450 | } |
| 1451 | |
Sinclair Yeh | 810b3e16 | 2017-03-23 15:39:16 -0700 | [diff] [blame] | 1452 | |
| 1453 | /** |
| 1454 | * vmw_kms_srf_ok - check if a surface can be created |
| 1455 | * |
| 1456 | * @width: requested width |
| 1457 | * @height: requested height |
| 1458 | * |
| 1459 | * Surfaces need to be less than texture size |
| 1460 | */ |
| 1461 | static bool |
| 1462 | vmw_kms_srf_ok(struct vmw_private *dev_priv, uint32_t width, uint32_t height) |
| 1463 | { |
| 1464 | if (width > dev_priv->texture_max_width || |
| 1465 | height > dev_priv->texture_max_height) |
| 1466 | return false; |
| 1467 | |
| 1468 | return true; |
| 1469 | } |
| 1470 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1471 | /** |
| 1472 | * vmw_kms_new_framebuffer - Create a new framebuffer. |
| 1473 | * |
| 1474 | * @dev_priv: Pointer to device private struct. |
| 1475 | * @dmabuf: Pointer to dma buffer to wrap the kms framebuffer around. |
| 1476 | * Either @dmabuf or @surface must be NULL. |
| 1477 | * @surface: Pointer to a surface to wrap the kms framebuffer around. |
| 1478 | * Either @dmabuf or @surface must be NULL. |
| 1479 | * @only_2d: No presents will occur to this dma buffer based framebuffer. This |
| 1480 | * Helps the code to do some important optimizations. |
| 1481 | * @mode_cmd: Frame-buffer metadata. |
| 1482 | */ |
| 1483 | struct vmw_framebuffer * |
| 1484 | vmw_kms_new_framebuffer(struct vmw_private *dev_priv, |
| 1485 | struct vmw_dma_buffer *dmabuf, |
| 1486 | struct vmw_surface *surface, |
| 1487 | bool only_2d, |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1488 | const struct drm_mode_fb_cmd2 *mode_cmd) |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1489 | { |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1490 | struct vmw_framebuffer *vfb = NULL; |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1491 | bool is_dmabuf_proxy = false; |
| 1492 | int ret; |
| 1493 | |
| 1494 | /* |
| 1495 | * We cannot use the SurfaceDMA command in an non-accelerated VM, |
| 1496 | * therefore, wrap the DMA buf in a surface so we can use the |
| 1497 | * SurfaceCopy command. |
| 1498 | */ |
Sinclair Yeh | 810b3e16 | 2017-03-23 15:39:16 -0700 | [diff] [blame] | 1499 | if (vmw_kms_srf_ok(dev_priv, mode_cmd->width, mode_cmd->height) && |
| 1500 | dmabuf && only_2d && |
Sinclair Yeh | bbd5fef | 2017-06-02 07:44:53 +0200 | [diff] [blame^] | 1501 | mode_cmd->width > 64 && /* Don't create a proxy for cursor */ |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1502 | dev_priv->active_display_unit == vmw_du_screen_target) { |
| 1503 | ret = vmw_create_dmabuf_proxy(dev_priv->dev, mode_cmd, |
| 1504 | dmabuf, &surface); |
| 1505 | if (ret) |
| 1506 | return ERR_PTR(ret); |
| 1507 | |
| 1508 | is_dmabuf_proxy = true; |
| 1509 | } |
| 1510 | |
| 1511 | /* Create the new framebuffer depending one what we have */ |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1512 | if (surface) { |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1513 | ret = vmw_kms_new_framebuffer_surface(dev_priv, surface, &vfb, |
| 1514 | mode_cmd, |
| 1515 | is_dmabuf_proxy); |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1516 | |
| 1517 | /* |
| 1518 | * vmw_create_dmabuf_proxy() adds a reference that is no longer |
| 1519 | * needed |
| 1520 | */ |
| 1521 | if (is_dmabuf_proxy) |
| 1522 | vmw_surface_unreference(&surface); |
| 1523 | } else if (dmabuf) { |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1524 | ret = vmw_kms_new_framebuffer_dmabuf(dev_priv, dmabuf, &vfb, |
| 1525 | mode_cmd); |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1526 | } else { |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1527 | BUG(); |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1528 | } |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1529 | |
| 1530 | if (ret) |
| 1531 | return ERR_PTR(ret); |
| 1532 | |
| 1533 | vfb->pin = vmw_framebuffer_pin; |
| 1534 | vfb->unpin = vmw_framebuffer_unpin; |
| 1535 | |
| 1536 | return vfb; |
| 1537 | } |
| 1538 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1539 | /* |
| 1540 | * Generic Kernel modesetting functions |
| 1541 | */ |
| 1542 | |
| 1543 | static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev, |
| 1544 | struct drm_file *file_priv, |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1545 | const struct drm_mode_fb_cmd2 *mode_cmd) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1546 | { |
| 1547 | struct vmw_private *dev_priv = vmw_priv(dev); |
| 1548 | struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; |
| 1549 | struct vmw_framebuffer *vfb = NULL; |
| 1550 | struct vmw_surface *surface = NULL; |
| 1551 | struct vmw_dma_buffer *bo = NULL; |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1552 | struct ttm_base_object *user_obj; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1553 | int ret; |
| 1554 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1555 | /** |
| 1556 | * This code should be conditioned on Screen Objects not being used. |
| 1557 | * If screen objects are used, we can allocate a GMR to hold the |
| 1558 | * requested framebuffer. |
| 1559 | */ |
| 1560 | |
Xi Wang | 8a78389 | 2011-12-21 05:18:33 -0500 | [diff] [blame] | 1561 | if (!vmw_kms_validate_mode_vram(dev_priv, |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1562 | mode_cmd->pitches[0], |
| 1563 | mode_cmd->height)) { |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1564 | DRM_ERROR("Requested mode exceed bounding box limit.\n"); |
Jakob Bornecrantz | d982640 | 2011-11-03 21:03:04 +0100 | [diff] [blame] | 1565 | return ERR_PTR(-ENOMEM); |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1566 | } |
| 1567 | |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1568 | /* |
| 1569 | * Take a reference on the user object of the resource |
| 1570 | * backing the kms fb. This ensures that user-space handle |
| 1571 | * lookups on that resource will always work as long as |
| 1572 | * it's registered with a kms framebuffer. This is important, |
| 1573 | * since vmw_execbuf_process identifies resources in the |
| 1574 | * command stream using user-space handles. |
| 1575 | */ |
| 1576 | |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1577 | user_obj = ttm_base_object_lookup(tfile, mode_cmd->handles[0]); |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1578 | if (unlikely(user_obj == NULL)) { |
| 1579 | DRM_ERROR("Could not locate requested kms frame buffer.\n"); |
| 1580 | return ERR_PTR(-ENOENT); |
| 1581 | } |
| 1582 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1583 | /** |
| 1584 | * End conditioned code. |
| 1585 | */ |
| 1586 | |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 1587 | /* returns either a dmabuf or surface */ |
| 1588 | ret = vmw_user_lookup_handle(dev_priv, tfile, |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1589 | mode_cmd->handles[0], |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 1590 | &surface, &bo); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1591 | if (ret) |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 1592 | goto err_out; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1593 | |
Sinclair Yeh | 810b3e16 | 2017-03-23 15:39:16 -0700 | [diff] [blame] | 1594 | |
| 1595 | if (!bo && |
| 1596 | !vmw_kms_srf_ok(dev_priv, mode_cmd->width, mode_cmd->height)) { |
| 1597 | DRM_ERROR("Surface size cannot exceed %dx%d", |
| 1598 | dev_priv->texture_max_width, |
| 1599 | dev_priv->texture_max_height); |
| 1600 | goto err_out; |
| 1601 | } |
| 1602 | |
| 1603 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1604 | vfb = vmw_kms_new_framebuffer(dev_priv, bo, surface, |
| 1605 | !(dev_priv->capabilities & SVGA_CAP_3D), |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1606 | mode_cmd); |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1607 | if (IS_ERR(vfb)) { |
| 1608 | ret = PTR_ERR(vfb); |
| 1609 | goto err_out; |
| 1610 | } |
Jakob Bornecrantz | 5ffdb65 | 2010-01-30 03:38:08 +0000 | [diff] [blame] | 1611 | |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 1612 | err_out: |
| 1613 | /* vmw_user_lookup_handle takes one ref so does new_fb */ |
| 1614 | if (bo) |
| 1615 | vmw_dmabuf_unreference(&bo); |
| 1616 | if (surface) |
| 1617 | vmw_surface_unreference(&surface); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1618 | |
| 1619 | if (ret) { |
| 1620 | DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret); |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1621 | ttm_base_object_unref(&user_obj); |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 1622 | return ERR_PTR(ret); |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1623 | } else |
| 1624 | vfb->user_obj = user_obj; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1625 | |
| 1626 | return &vfb->base; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1627 | } |
| 1628 | |
Sinclair Yeh | c46a306 | 2017-03-23 14:24:53 -0700 | [diff] [blame] | 1629 | |
| 1630 | |
| 1631 | /** |
| 1632 | * vmw_kms_atomic_check_modeset- validate state object for modeset changes |
| 1633 | * |
| 1634 | * @dev: DRM device |
| 1635 | * @state: the driver state object |
| 1636 | * |
| 1637 | * This is a simple wrapper around drm_atomic_helper_check_modeset() for |
| 1638 | * us to assign a value to mode->crtc_clock so that |
| 1639 | * drm_calc_timestamping_constants() won't throw an error message |
| 1640 | * |
| 1641 | * RETURNS |
| 1642 | * Zero for success or -errno |
| 1643 | */ |
| 1644 | int |
| 1645 | vmw_kms_atomic_check_modeset(struct drm_device *dev, |
| 1646 | struct drm_atomic_state *state) |
| 1647 | { |
| 1648 | struct drm_crtc_state *crtc_state; |
| 1649 | struct drm_crtc *crtc; |
| 1650 | struct vmw_private *dev_priv = vmw_priv(dev); |
| 1651 | int i; |
| 1652 | |
| 1653 | |
| 1654 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 1655 | unsigned long requested_bb_mem = 0; |
| 1656 | |
| 1657 | if (dev_priv->active_display_unit == vmw_du_screen_target) { |
| 1658 | if (crtc->primary->fb) { |
| 1659 | int cpp = crtc->primary->fb->pitches[0] / |
| 1660 | crtc->primary->fb->width; |
| 1661 | |
| 1662 | requested_bb_mem += crtc->mode.hdisplay * cpp * |
| 1663 | crtc->mode.vdisplay; |
| 1664 | } |
| 1665 | |
| 1666 | if (requested_bb_mem > dev_priv->prim_bb_mem) |
| 1667 | return -EINVAL; |
| 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | return drm_atomic_helper_check(dev, state); |
| 1672 | } |
| 1673 | |
| 1674 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 1675 | static const struct drm_mode_config_funcs vmw_kms_funcs = { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1676 | .fb_create = vmw_kms_fb_create, |
Sinclair Yeh | c46a306 | 2017-03-23 14:24:53 -0700 | [diff] [blame] | 1677 | .atomic_check = vmw_kms_atomic_check_modeset, |
| 1678 | .atomic_commit = drm_atomic_helper_commit, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1679 | }; |
| 1680 | |
Thomas Hellstrom | b9eb1a6 | 2015-04-02 02:39:45 -0700 | [diff] [blame] | 1681 | static int vmw_kms_generic_present(struct vmw_private *dev_priv, |
| 1682 | struct drm_file *file_priv, |
| 1683 | struct vmw_framebuffer *vfb, |
| 1684 | struct vmw_surface *surface, |
| 1685 | uint32_t sid, |
| 1686 | int32_t destX, int32_t destY, |
| 1687 | struct drm_vmw_rect *clips, |
| 1688 | uint32_t num_clips) |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1689 | { |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 1690 | return vmw_kms_sou_do_surface_dirty(dev_priv, vfb, NULL, clips, |
| 1691 | &surface->res, destX, destY, |
| 1692 | num_clips, 1, NULL); |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1693 | } |
| 1694 | |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1695 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1696 | int vmw_kms_present(struct vmw_private *dev_priv, |
| 1697 | struct drm_file *file_priv, |
| 1698 | struct vmw_framebuffer *vfb, |
| 1699 | struct vmw_surface *surface, |
| 1700 | uint32_t sid, |
| 1701 | int32_t destX, int32_t destY, |
| 1702 | struct drm_vmw_rect *clips, |
| 1703 | uint32_t num_clips) |
| 1704 | { |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1705 | int ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1706 | |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1707 | switch (dev_priv->active_display_unit) { |
| 1708 | case vmw_du_screen_target: |
| 1709 | ret = vmw_kms_stdu_surface_dirty(dev_priv, vfb, NULL, clips, |
| 1710 | &surface->res, destX, destY, |
| 1711 | num_clips, 1, NULL); |
| 1712 | break; |
| 1713 | case vmw_du_screen_object: |
| 1714 | ret = vmw_kms_generic_present(dev_priv, file_priv, vfb, surface, |
| 1715 | sid, destX, destY, clips, |
| 1716 | num_clips); |
| 1717 | break; |
| 1718 | default: |
| 1719 | WARN_ONCE(true, |
| 1720 | "Present called with invalid display system.\n"); |
| 1721 | ret = -ENOSYS; |
| 1722 | break; |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 1723 | } |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1724 | if (ret) |
| 1725 | return ret; |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 1726 | |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1727 | vmw_fifo_flush(dev_priv, false); |
Michel Dänzer | 0bef23f | 2011-08-31 07:42:50 +0000 | [diff] [blame] | 1728 | |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1729 | return 0; |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 1730 | } |
| 1731 | |
Thomas Hellstrom | 578e609 | 2016-02-12 09:45:42 +0100 | [diff] [blame] | 1732 | static void |
| 1733 | vmw_kms_create_hotplug_mode_update_property(struct vmw_private *dev_priv) |
| 1734 | { |
| 1735 | if (dev_priv->hotplug_mode_update_property) |
| 1736 | return; |
| 1737 | |
| 1738 | dev_priv->hotplug_mode_update_property = |
| 1739 | drm_property_create_range(dev_priv->dev, |
| 1740 | DRM_MODE_PROP_IMMUTABLE, |
| 1741 | "hotplug_mode_update", 0, 1); |
| 1742 | |
| 1743 | if (!dev_priv->hotplug_mode_update_property) |
| 1744 | return; |
| 1745 | |
| 1746 | } |
| 1747 | |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 1748 | int vmw_kms_init(struct vmw_private *dev_priv) |
| 1749 | { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1750 | struct drm_device *dev = dev_priv->dev; |
| 1751 | int ret; |
| 1752 | |
| 1753 | drm_mode_config_init(dev); |
| 1754 | dev->mode_config.funcs = &vmw_kms_funcs; |
| 1755 | dev->mode_config.min_width = 1; |
| 1756 | dev->mode_config.min_height = 1; |
Sinclair Yeh | 65ade7d | 2015-07-16 10:49:13 -0700 | [diff] [blame] | 1757 | dev->mode_config.max_width = dev_priv->texture_max_width; |
| 1758 | dev->mode_config.max_height = dev_priv->texture_max_height; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1759 | |
Thomas Hellstrom | 578e609 | 2016-02-12 09:45:42 +0100 | [diff] [blame] | 1760 | drm_mode_create_suggested_offset_properties(dev); |
| 1761 | vmw_kms_create_hotplug_mode_update_property(dev_priv); |
| 1762 | |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1763 | ret = vmw_kms_stdu_init_display(dev_priv); |
| 1764 | if (ret) { |
| 1765 | ret = vmw_kms_sou_init_display(dev_priv); |
| 1766 | if (ret) /* Fallback */ |
| 1767 | ret = vmw_kms_ldu_init_display(dev_priv); |
| 1768 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1769 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1770 | return ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | int vmw_kms_close(struct vmw_private *dev_priv) |
| 1774 | { |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1775 | int ret; |
| 1776 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1777 | /* |
| 1778 | * Docs says we should take the lock before calling this function |
| 1779 | * but since it destroys encoders and our destructor calls |
| 1780 | * drm_encoder_cleanup which takes the lock we deadlock. |
| 1781 | */ |
| 1782 | drm_mode_config_cleanup(dev_priv->dev); |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1783 | if (dev_priv->active_display_unit == vmw_du_screen_object) |
| 1784 | ret = vmw_kms_sou_close_display(dev_priv); |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1785 | else if (dev_priv->active_display_unit == vmw_du_screen_target) |
| 1786 | ret = vmw_kms_stdu_close_display(dev_priv); |
Jakob Bornecrantz | c0d1831 | 2011-11-09 10:25:26 +0100 | [diff] [blame] | 1787 | else |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1788 | ret = vmw_kms_ldu_close_display(dev_priv); |
| 1789 | |
| 1790 | return ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data, |
| 1794 | struct drm_file *file_priv) |
| 1795 | { |
| 1796 | struct drm_vmw_cursor_bypass_arg *arg = data; |
| 1797 | struct vmw_display_unit *du; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1798 | struct drm_crtc *crtc; |
| 1799 | int ret = 0; |
| 1800 | |
| 1801 | |
| 1802 | mutex_lock(&dev->mode_config.mutex); |
| 1803 | if (arg->flags & DRM_VMW_CURSOR_BYPASS_ALL) { |
| 1804 | |
| 1805 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 1806 | du = vmw_crtc_to_du(crtc); |
| 1807 | du->hotspot_x = arg->xhot; |
| 1808 | du->hotspot_y = arg->yhot; |
| 1809 | } |
| 1810 | |
| 1811 | mutex_unlock(&dev->mode_config.mutex); |
| 1812 | return 0; |
| 1813 | } |
| 1814 | |
Rob Clark | a4cd5d6 | 2014-07-17 23:30:02 -0400 | [diff] [blame] | 1815 | crtc = drm_crtc_find(dev, arg->crtc_id); |
| 1816 | if (!crtc) { |
Ville Syrjälä | 4ae87ff | 2013-10-17 13:35:05 +0300 | [diff] [blame] | 1817 | ret = -ENOENT; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1818 | goto out; |
| 1819 | } |
| 1820 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1821 | du = vmw_crtc_to_du(crtc); |
| 1822 | |
| 1823 | du->hotspot_x = arg->xhot; |
| 1824 | du->hotspot_y = arg->yhot; |
| 1825 | |
| 1826 | out: |
| 1827 | mutex_unlock(&dev->mode_config.mutex); |
| 1828 | |
| 1829 | return ret; |
| 1830 | } |
| 1831 | |
| 1832 | int vmw_kms_write_svga(struct vmw_private *vmw_priv, |
| 1833 | unsigned width, unsigned height, unsigned pitch, |
| 1834 | unsigned bpp, unsigned depth) |
| 1835 | { |
| 1836 | if (vmw_priv->capabilities & SVGA_CAP_PITCHLOCK) |
| 1837 | vmw_write(vmw_priv, SVGA_REG_PITCHLOCK, pitch); |
| 1838 | else if (vmw_fifo_have_pitchlock(vmw_priv)) |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 1839 | vmw_mmio_write(pitch, vmw_priv->mmio_virt + |
| 1840 | SVGA_FIFO_PITCHLOCK); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1841 | vmw_write(vmw_priv, SVGA_REG_WIDTH, width); |
| 1842 | vmw_write(vmw_priv, SVGA_REG_HEIGHT, height); |
| 1843 | vmw_write(vmw_priv, SVGA_REG_BITS_PER_PIXEL, bpp); |
| 1844 | |
| 1845 | if (vmw_read(vmw_priv, SVGA_REG_DEPTH) != depth) { |
| 1846 | DRM_ERROR("Invalid depth %u for %u bpp, host expects %u\n", |
| 1847 | depth, bpp, vmw_read(vmw_priv, SVGA_REG_DEPTH)); |
| 1848 | return -EINVAL; |
| 1849 | } |
| 1850 | |
| 1851 | return 0; |
| 1852 | } |
| 1853 | |
| 1854 | int vmw_kms_save_vga(struct vmw_private *vmw_priv) |
| 1855 | { |
| 1856 | struct vmw_vga_topology_state *save; |
| 1857 | uint32_t i; |
| 1858 | |
| 1859 | vmw_priv->vga_width = vmw_read(vmw_priv, SVGA_REG_WIDTH); |
| 1860 | vmw_priv->vga_height = vmw_read(vmw_priv, SVGA_REG_HEIGHT); |
| 1861 | vmw_priv->vga_bpp = vmw_read(vmw_priv, SVGA_REG_BITS_PER_PIXEL); |
| 1862 | if (vmw_priv->capabilities & SVGA_CAP_PITCHLOCK) |
| 1863 | vmw_priv->vga_pitchlock = |
| 1864 | vmw_read(vmw_priv, SVGA_REG_PITCHLOCK); |
| 1865 | else if (vmw_fifo_have_pitchlock(vmw_priv)) |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 1866 | vmw_priv->vga_pitchlock = vmw_mmio_read(vmw_priv->mmio_virt + |
| 1867 | SVGA_FIFO_PITCHLOCK); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1868 | |
| 1869 | if (!(vmw_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY)) |
| 1870 | return 0; |
| 1871 | |
| 1872 | vmw_priv->num_displays = vmw_read(vmw_priv, |
| 1873 | SVGA_REG_NUM_GUEST_DISPLAYS); |
| 1874 | |
| 1875 | if (vmw_priv->num_displays == 0) |
| 1876 | vmw_priv->num_displays = 1; |
| 1877 | |
| 1878 | for (i = 0; i < vmw_priv->num_displays; ++i) { |
| 1879 | save = &vmw_priv->vga_save[i]; |
| 1880 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, i); |
| 1881 | save->primary = vmw_read(vmw_priv, SVGA_REG_DISPLAY_IS_PRIMARY); |
| 1882 | save->pos_x = vmw_read(vmw_priv, SVGA_REG_DISPLAY_POSITION_X); |
| 1883 | save->pos_y = vmw_read(vmw_priv, SVGA_REG_DISPLAY_POSITION_Y); |
| 1884 | save->width = vmw_read(vmw_priv, SVGA_REG_DISPLAY_WIDTH); |
| 1885 | save->height = vmw_read(vmw_priv, SVGA_REG_DISPLAY_HEIGHT); |
| 1886 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, SVGA_ID_INVALID); |
| 1887 | if (i == 0 && vmw_priv->num_displays == 1 && |
| 1888 | save->width == 0 && save->height == 0) { |
| 1889 | |
| 1890 | /* |
| 1891 | * It should be fairly safe to assume that these |
| 1892 | * values are uninitialized. |
| 1893 | */ |
| 1894 | |
| 1895 | save->width = vmw_priv->vga_width - save->pos_x; |
| 1896 | save->height = vmw_priv->vga_height - save->pos_y; |
| 1897 | } |
| 1898 | } |
| 1899 | |
| 1900 | return 0; |
| 1901 | } |
| 1902 | |
| 1903 | int vmw_kms_restore_vga(struct vmw_private *vmw_priv) |
| 1904 | { |
| 1905 | struct vmw_vga_topology_state *save; |
| 1906 | uint32_t i; |
| 1907 | |
| 1908 | vmw_write(vmw_priv, SVGA_REG_WIDTH, vmw_priv->vga_width); |
| 1909 | vmw_write(vmw_priv, SVGA_REG_HEIGHT, vmw_priv->vga_height); |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 1910 | vmw_write(vmw_priv, SVGA_REG_BITS_PER_PIXEL, vmw_priv->vga_bpp); |
| 1911 | if (vmw_priv->capabilities & SVGA_CAP_PITCHLOCK) |
| 1912 | vmw_write(vmw_priv, SVGA_REG_PITCHLOCK, |
| 1913 | vmw_priv->vga_pitchlock); |
| 1914 | else if (vmw_fifo_have_pitchlock(vmw_priv)) |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 1915 | vmw_mmio_write(vmw_priv->vga_pitchlock, |
| 1916 | vmw_priv->mmio_virt + SVGA_FIFO_PITCHLOCK); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1917 | |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 1918 | if (!(vmw_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY)) |
| 1919 | return 0; |
| 1920 | |
| 1921 | for (i = 0; i < vmw_priv->num_displays; ++i) { |
| 1922 | save = &vmw_priv->vga_save[i]; |
| 1923 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, i); |
| 1924 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_IS_PRIMARY, save->primary); |
| 1925 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_POSITION_X, save->pos_x); |
| 1926 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_POSITION_Y, save->pos_y); |
| 1927 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_WIDTH, save->width); |
| 1928 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_HEIGHT, save->height); |
| 1929 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, SVGA_ID_INVALID); |
| 1930 | } |
| 1931 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1932 | return 0; |
| 1933 | } |
Jakob Bornecrantz | d8bd19d | 2010-06-01 11:54:20 +0200 | [diff] [blame] | 1934 | |
Thomas Hellstrom | e133e737 | 2010-10-05 12:43:04 +0200 | [diff] [blame] | 1935 | bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv, |
| 1936 | uint32_t pitch, |
| 1937 | uint32_t height) |
| 1938 | { |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1939 | return ((u64) pitch * (u64) height) < (u64) |
| 1940 | ((dev_priv->active_display_unit == vmw_du_screen_target) ? |
| 1941 | dev_priv->prim_bb_mem : dev_priv->vram_size); |
Thomas Hellstrom | e133e737 | 2010-10-05 12:43:04 +0200 | [diff] [blame] | 1942 | } |
| 1943 | |
Jakob Bornecrantz | 1c482ab | 2011-10-17 11:59:45 +0200 | [diff] [blame] | 1944 | |
| 1945 | /** |
| 1946 | * Function called by DRM code called with vbl_lock held. |
| 1947 | */ |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 1948 | u32 vmw_get_vblank_counter(struct drm_device *dev, unsigned int pipe) |
Thomas Hellstrom | 7a1c2f6 | 2010-10-01 10:21:49 +0200 | [diff] [blame] | 1949 | { |
| 1950 | return 0; |
| 1951 | } |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1952 | |
Jakob Bornecrantz | 1c482ab | 2011-10-17 11:59:45 +0200 | [diff] [blame] | 1953 | /** |
| 1954 | * Function called by DRM code called with vbl_lock held. |
| 1955 | */ |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 1956 | int vmw_enable_vblank(struct drm_device *dev, unsigned int pipe) |
Jakob Bornecrantz | 1c482ab | 2011-10-17 11:59:45 +0200 | [diff] [blame] | 1957 | { |
| 1958 | return -ENOSYS; |
| 1959 | } |
| 1960 | |
| 1961 | /** |
| 1962 | * Function called by DRM code called with vbl_lock held. |
| 1963 | */ |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 1964 | void vmw_disable_vblank(struct drm_device *dev, unsigned int pipe) |
Jakob Bornecrantz | 1c482ab | 2011-10-17 11:59:45 +0200 | [diff] [blame] | 1965 | { |
| 1966 | } |
| 1967 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1968 | |
| 1969 | /* |
| 1970 | * Small shared kms functions. |
| 1971 | */ |
| 1972 | |
Rashika Kheria | 847c596 | 2014-01-06 22:18:10 +0530 | [diff] [blame] | 1973 | 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] | 1974 | struct drm_vmw_rect *rects) |
| 1975 | { |
| 1976 | struct drm_device *dev = dev_priv->dev; |
| 1977 | struct vmw_display_unit *du; |
| 1978 | struct drm_connector *con; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1979 | |
| 1980 | mutex_lock(&dev->mode_config.mutex); |
| 1981 | |
| 1982 | #if 0 |
Thomas Hellstrom | 6ea77d1 | 2011-10-04 20:13:36 +0200 | [diff] [blame] | 1983 | { |
| 1984 | unsigned int i; |
| 1985 | |
| 1986 | DRM_INFO("%s: new layout ", __func__); |
| 1987 | for (i = 0; i < num; i++) |
| 1988 | DRM_INFO("(%i, %i %ux%u) ", rects[i].x, rects[i].y, |
| 1989 | rects[i].w, rects[i].h); |
| 1990 | DRM_INFO("\n"); |
| 1991 | } |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1992 | #endif |
| 1993 | |
| 1994 | list_for_each_entry(con, &dev->mode_config.connector_list, head) { |
| 1995 | du = vmw_connector_to_du(con); |
| 1996 | if (num > du->unit) { |
| 1997 | du->pref_width = rects[du->unit].w; |
| 1998 | du->pref_height = rects[du->unit].h; |
| 1999 | du->pref_active = true; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2000 | du->gui_x = rects[du->unit].x; |
| 2001 | du->gui_y = rects[du->unit].y; |
Thomas Hellstrom | 578e609 | 2016-02-12 09:45:42 +0100 | [diff] [blame] | 2002 | drm_object_property_set_value |
| 2003 | (&con->base, dev->mode_config.suggested_x_property, |
| 2004 | du->gui_x); |
| 2005 | drm_object_property_set_value |
| 2006 | (&con->base, dev->mode_config.suggested_y_property, |
| 2007 | du->gui_y); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2008 | } else { |
| 2009 | du->pref_width = 800; |
| 2010 | du->pref_height = 600; |
| 2011 | du->pref_active = false; |
Thomas Hellstrom | 578e609 | 2016-02-12 09:45:42 +0100 | [diff] [blame] | 2012 | drm_object_property_set_value |
| 2013 | (&con->base, dev->mode_config.suggested_x_property, |
| 2014 | 0); |
| 2015 | drm_object_property_set_value |
| 2016 | (&con->base, dev->mode_config.suggested_y_property, |
| 2017 | 0); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2018 | } |
| 2019 | con->status = vmw_du_connector_detect(con, true); |
| 2020 | } |
| 2021 | |
| 2022 | mutex_unlock(&dev->mode_config.mutex); |
Thomas Hellstrom | 578e609 | 2016-02-12 09:45:42 +0100 | [diff] [blame] | 2023 | drm_sysfs_hotplug_event(dev); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2024 | |
| 2025 | return 0; |
| 2026 | } |
| 2027 | |
Maarten Lankhorst | 7ea7728 | 2016-06-07 12:49:30 +0200 | [diff] [blame] | 2028 | int vmw_du_crtc_gamma_set(struct drm_crtc *crtc, |
| 2029 | u16 *r, u16 *g, u16 *b, |
Daniel Vetter | 6d124ff | 2017-04-03 10:33:01 +0200 | [diff] [blame] | 2030 | uint32_t size, |
| 2031 | struct drm_modeset_acquire_ctx *ctx) |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2032 | { |
| 2033 | struct vmw_private *dev_priv = vmw_priv(crtc->dev); |
| 2034 | int i; |
| 2035 | |
| 2036 | for (i = 0; i < size; i++) { |
| 2037 | DRM_DEBUG("%d r/g/b = 0x%04x / 0x%04x / 0x%04x\n", i, |
| 2038 | r[i], g[i], b[i]); |
| 2039 | vmw_write(dev_priv, SVGA_PALETTE_BASE + i * 3 + 0, r[i] >> 8); |
| 2040 | vmw_write(dev_priv, SVGA_PALETTE_BASE + i * 3 + 1, g[i] >> 8); |
| 2041 | vmw_write(dev_priv, SVGA_PALETTE_BASE + i * 3 + 2, b[i] >> 8); |
| 2042 | } |
Maarten Lankhorst | 7ea7728 | 2016-06-07 12:49:30 +0200 | [diff] [blame] | 2043 | |
| 2044 | return 0; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2045 | } |
| 2046 | |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2047 | int vmw_du_connector_dpms(struct drm_connector *connector, int mode) |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2048 | { |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2049 | return 0; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2050 | } |
| 2051 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2052 | enum drm_connector_status |
| 2053 | vmw_du_connector_detect(struct drm_connector *connector, bool force) |
| 2054 | { |
| 2055 | uint32_t num_displays; |
| 2056 | struct drm_device *dev = connector->dev; |
| 2057 | struct vmw_private *dev_priv = vmw_priv(dev); |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2058 | struct vmw_display_unit *du = vmw_connector_to_du(connector); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2059 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2060 | num_displays = vmw_read(dev_priv, SVGA_REG_NUM_DISPLAYS); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2061 | |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2062 | return ((vmw_connector_to_du(connector)->unit < num_displays && |
| 2063 | du->pref_active) ? |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2064 | connector_status_connected : connector_status_disconnected); |
| 2065 | } |
| 2066 | |
| 2067 | static struct drm_display_mode vmw_kms_connector_builtin[] = { |
| 2068 | /* 640x480@60Hz */ |
| 2069 | { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656, |
| 2070 | 752, 800, 0, 480, 489, 492, 525, 0, |
| 2071 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
| 2072 | /* 800x600@60Hz */ |
| 2073 | { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840, |
| 2074 | 968, 1056, 0, 600, 601, 605, 628, 0, |
| 2075 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2076 | /* 1024x768@60Hz */ |
| 2077 | { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048, |
| 2078 | 1184, 1344, 0, 768, 771, 777, 806, 0, |
| 2079 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
| 2080 | /* 1152x864@75Hz */ |
| 2081 | { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216, |
| 2082 | 1344, 1600, 0, 864, 865, 868, 900, 0, |
| 2083 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2084 | /* 1280x768@60Hz */ |
| 2085 | { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344, |
| 2086 | 1472, 1664, 0, 768, 771, 778, 798, 0, |
| 2087 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2088 | /* 1280x800@60Hz */ |
| 2089 | { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352, |
| 2090 | 1480, 1680, 0, 800, 803, 809, 831, 0, |
| 2091 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
| 2092 | /* 1280x960@60Hz */ |
| 2093 | { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376, |
| 2094 | 1488, 1800, 0, 960, 961, 964, 1000, 0, |
| 2095 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2096 | /* 1280x1024@60Hz */ |
| 2097 | { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328, |
| 2098 | 1440, 1688, 0, 1024, 1025, 1028, 1066, 0, |
| 2099 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2100 | /* 1360x768@60Hz */ |
| 2101 | { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424, |
| 2102 | 1536, 1792, 0, 768, 771, 777, 795, 0, |
| 2103 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2104 | /* 1440x1050@60Hz */ |
| 2105 | { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488, |
| 2106 | 1632, 1864, 0, 1050, 1053, 1057, 1089, 0, |
| 2107 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2108 | /* 1440x900@60Hz */ |
| 2109 | { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520, |
| 2110 | 1672, 1904, 0, 900, 903, 909, 934, 0, |
| 2111 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2112 | /* 1600x1200@60Hz */ |
| 2113 | { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664, |
| 2114 | 1856, 2160, 0, 1200, 1201, 1204, 1250, 0, |
| 2115 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2116 | /* 1680x1050@60Hz */ |
| 2117 | { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784, |
| 2118 | 1960, 2240, 0, 1050, 1053, 1059, 1089, 0, |
| 2119 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2120 | /* 1792x1344@60Hz */ |
| 2121 | { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920, |
| 2122 | 2120, 2448, 0, 1344, 1345, 1348, 1394, 0, |
| 2123 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2124 | /* 1853x1392@60Hz */ |
| 2125 | { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952, |
| 2126 | 2176, 2528, 0, 1392, 1393, 1396, 1439, 0, |
| 2127 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2128 | /* 1920x1200@60Hz */ |
| 2129 | { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056, |
| 2130 | 2256, 2592, 0, 1200, 1203, 1209, 1245, 0, |
| 2131 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2132 | /* 1920x1440@60Hz */ |
| 2133 | { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048, |
| 2134 | 2256, 2600, 0, 1440, 1441, 1444, 1500, 0, |
| 2135 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2136 | /* 2560x1600@60Hz */ |
| 2137 | { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752, |
| 2138 | 3032, 3504, 0, 1600, 1603, 1609, 1658, 0, |
| 2139 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2140 | /* Terminate */ |
| 2141 | { DRM_MODE("", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) }, |
| 2142 | }; |
| 2143 | |
Thomas Hellstrom | 1543b4dd | 2011-11-02 09:43:10 +0100 | [diff] [blame] | 2144 | /** |
| 2145 | * vmw_guess_mode_timing - Provide fake timings for a |
| 2146 | * 60Hz vrefresh mode. |
| 2147 | * |
| 2148 | * @mode - Pointer to a struct drm_display_mode with hdisplay and vdisplay |
| 2149 | * members filled in. |
| 2150 | */ |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 2151 | void vmw_guess_mode_timing(struct drm_display_mode *mode) |
Thomas Hellstrom | 1543b4dd | 2011-11-02 09:43:10 +0100 | [diff] [blame] | 2152 | { |
| 2153 | mode->hsync_start = mode->hdisplay + 50; |
| 2154 | mode->hsync_end = mode->hsync_start + 50; |
| 2155 | mode->htotal = mode->hsync_end + 50; |
| 2156 | |
| 2157 | mode->vsync_start = mode->vdisplay + 50; |
| 2158 | mode->vsync_end = mode->vsync_start + 50; |
| 2159 | mode->vtotal = mode->vsync_end + 50; |
| 2160 | |
| 2161 | mode->clock = (u32)mode->htotal * (u32)mode->vtotal / 100 * 6; |
| 2162 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 2163 | } |
| 2164 | |
| 2165 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2166 | int vmw_du_connector_fill_modes(struct drm_connector *connector, |
| 2167 | uint32_t max_width, uint32_t max_height) |
| 2168 | { |
| 2169 | struct vmw_display_unit *du = vmw_connector_to_du(connector); |
| 2170 | struct drm_device *dev = connector->dev; |
| 2171 | struct vmw_private *dev_priv = vmw_priv(dev); |
| 2172 | struct drm_display_mode *mode = NULL; |
| 2173 | struct drm_display_mode *bmode; |
| 2174 | struct drm_display_mode prefmode = { DRM_MODE("preferred", |
| 2175 | DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED, |
| 2176 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 2177 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) |
| 2178 | }; |
| 2179 | int i; |
Sinclair Yeh | 7c20d21 | 2016-06-29 11:29:47 -0700 | [diff] [blame] | 2180 | u32 assumed_bpp = 4; |
Sinclair Yeh | 9a72384 | 2014-10-31 09:58:06 +0100 | [diff] [blame] | 2181 | |
Sinclair Yeh | 04319d8 | 2016-06-29 12:15:48 -0700 | [diff] [blame] | 2182 | if (dev_priv->assume_16bpp) |
| 2183 | assumed_bpp = 2; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2184 | |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 2185 | if (dev_priv->active_display_unit == vmw_du_screen_target) { |
| 2186 | max_width = min(max_width, dev_priv->stdu_max_width); |
Sinclair Yeh | 28c9542 | 2017-03-27 11:12:27 -0700 | [diff] [blame] | 2187 | max_width = min(max_width, dev_priv->texture_max_width); |
| 2188 | |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 2189 | max_height = min(max_height, dev_priv->stdu_max_height); |
Sinclair Yeh | 28c9542 | 2017-03-27 11:12:27 -0700 | [diff] [blame] | 2190 | max_height = min(max_height, dev_priv->texture_max_height); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2191 | } |
| 2192 | |
| 2193 | /* Add preferred mode */ |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 2194 | mode = drm_mode_duplicate(dev, &prefmode); |
| 2195 | if (!mode) |
| 2196 | return 0; |
| 2197 | mode->hdisplay = du->pref_width; |
| 2198 | mode->vdisplay = du->pref_height; |
| 2199 | vmw_guess_mode_timing(mode); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2200 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 2201 | if (vmw_kms_validate_mode_vram(dev_priv, |
| 2202 | mode->hdisplay * assumed_bpp, |
| 2203 | mode->vdisplay)) { |
| 2204 | drm_mode_probed_add(connector, mode); |
| 2205 | } else { |
| 2206 | drm_mode_destroy(dev, mode); |
| 2207 | mode = NULL; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2208 | } |
| 2209 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 2210 | if (du->pref_mode) { |
| 2211 | list_del_init(&du->pref_mode->head); |
| 2212 | drm_mode_destroy(dev, du->pref_mode); |
| 2213 | } |
| 2214 | |
| 2215 | /* mode might be null here, this is intended */ |
| 2216 | du->pref_mode = mode; |
| 2217 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2218 | for (i = 0; vmw_kms_connector_builtin[i].type != 0; i++) { |
| 2219 | bmode = &vmw_kms_connector_builtin[i]; |
| 2220 | if (bmode->hdisplay > max_width || |
| 2221 | bmode->vdisplay > max_height) |
| 2222 | continue; |
| 2223 | |
Sinclair Yeh | 9a72384 | 2014-10-31 09:58:06 +0100 | [diff] [blame] | 2224 | if (!vmw_kms_validate_mode_vram(dev_priv, |
| 2225 | bmode->hdisplay * assumed_bpp, |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2226 | bmode->vdisplay)) |
| 2227 | continue; |
| 2228 | |
| 2229 | mode = drm_mode_duplicate(dev, bmode); |
| 2230 | if (!mode) |
| 2231 | return 0; |
| 2232 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 2233 | |
| 2234 | drm_mode_probed_add(connector, mode); |
| 2235 | } |
| 2236 | |
Ville Syrjälä | 6af3e65 | 2015-12-03 23:14:14 +0200 | [diff] [blame] | 2237 | drm_mode_connector_list_update(connector); |
Thomas Hellstrom | f6b0500 | 2015-06-29 12:59:58 -0700 | [diff] [blame] | 2238 | /* Move the prefered mode first, help apps pick the right mode. */ |
| 2239 | drm_mode_sort(&connector->modes); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2240 | |
| 2241 | return 1; |
| 2242 | } |
| 2243 | |
| 2244 | int vmw_du_connector_set_property(struct drm_connector *connector, |
| 2245 | struct drm_property *property, |
| 2246 | uint64_t val) |
| 2247 | { |
Thomas Hellstrom | 76404ac | 2016-02-12 09:55:45 +0100 | [diff] [blame] | 2248 | struct vmw_display_unit *du = vmw_connector_to_du(connector); |
| 2249 | struct vmw_private *dev_priv = vmw_priv(connector->dev); |
| 2250 | |
| 2251 | if (property == dev_priv->implicit_placement_property) |
| 2252 | du->is_implicit = val; |
| 2253 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2254 | return 0; |
| 2255 | } |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2256 | |
| 2257 | |
Sinclair Yeh | 9c2542a | 2017-03-23 11:33:39 -0700 | [diff] [blame] | 2258 | |
Sinclair Yeh | d7721ca | 2017-03-23 11:48:44 -0700 | [diff] [blame] | 2259 | /** |
| 2260 | * vmw_du_connector_atomic_set_property - Atomic version of get property |
| 2261 | * |
| 2262 | * @crtc - crtc the property is associated with |
| 2263 | * |
| 2264 | * Returns: |
| 2265 | * Zero on success, negative errno on failure. |
| 2266 | */ |
| 2267 | int |
| 2268 | vmw_du_connector_atomic_set_property(struct drm_connector *connector, |
| 2269 | struct drm_connector_state *state, |
| 2270 | struct drm_property *property, |
| 2271 | uint64_t val) |
| 2272 | { |
| 2273 | struct vmw_private *dev_priv = vmw_priv(connector->dev); |
| 2274 | struct vmw_connector_state *vcs = vmw_connector_state_to_vcs(state); |
| 2275 | struct vmw_display_unit *du = vmw_connector_to_du(connector); |
| 2276 | |
| 2277 | |
| 2278 | if (property == dev_priv->implicit_placement_property) { |
| 2279 | vcs->is_implicit = val; |
| 2280 | |
| 2281 | /* |
| 2282 | * We should really be doing a drm_atomic_commit() to |
| 2283 | * commit the new state, but since this doesn't cause |
| 2284 | * an immedate state change, this is probably ok |
| 2285 | */ |
| 2286 | du->is_implicit = vcs->is_implicit; |
| 2287 | } else { |
| 2288 | return -EINVAL; |
| 2289 | } |
| 2290 | |
| 2291 | return 0; |
| 2292 | } |
| 2293 | |
| 2294 | |
| 2295 | /** |
| 2296 | * vmw_du_connector_atomic_get_property - Atomic version of get property |
| 2297 | * |
| 2298 | * @connector - connector the property is associated with |
| 2299 | * |
| 2300 | * Returns: |
| 2301 | * Zero on success, negative errno on failure. |
| 2302 | */ |
| 2303 | int |
| 2304 | vmw_du_connector_atomic_get_property(struct drm_connector *connector, |
| 2305 | const struct drm_connector_state *state, |
| 2306 | struct drm_property *property, |
| 2307 | uint64_t *val) |
| 2308 | { |
| 2309 | struct vmw_private *dev_priv = vmw_priv(connector->dev); |
| 2310 | struct vmw_connector_state *vcs = vmw_connector_state_to_vcs(state); |
| 2311 | |
| 2312 | if (property == dev_priv->implicit_placement_property) |
| 2313 | *val = vcs->is_implicit; |
| 2314 | else { |
| 2315 | DRM_ERROR("Invalid Property %s\n", property->name); |
| 2316 | return -EINVAL; |
| 2317 | } |
| 2318 | |
| 2319 | return 0; |
| 2320 | } |
| 2321 | |
| 2322 | |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2323 | int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data, |
| 2324 | struct drm_file *file_priv) |
| 2325 | { |
| 2326 | struct vmw_private *dev_priv = vmw_priv(dev); |
| 2327 | struct drm_vmw_update_layout_arg *arg = |
| 2328 | (struct drm_vmw_update_layout_arg *)data; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2329 | void __user *user_rects; |
| 2330 | struct drm_vmw_rect *rects; |
| 2331 | unsigned rects_size; |
| 2332 | int ret; |
| 2333 | int i; |
Sinclair Yeh | 65ade7d | 2015-07-16 10:49:13 -0700 | [diff] [blame] | 2334 | u64 total_pixels = 0; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2335 | struct drm_mode_config *mode_config = &dev->mode_config; |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 2336 | struct drm_vmw_rect bounding_box = {0}; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2337 | |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2338 | if (!arg->num_outputs) { |
| 2339 | struct drm_vmw_rect def_rect = {0, 0, 800, 600}; |
| 2340 | vmw_du_update_layout(dev_priv, 1, &def_rect); |
Thomas Hellstrom | 5151adb | 2015-03-09 01:56:21 -0700 | [diff] [blame] | 2341 | return 0; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | rects_size = arg->num_outputs * sizeof(struct drm_vmw_rect); |
Xi Wang | bab9efc | 2011-11-28 12:25:43 +0100 | [diff] [blame] | 2345 | rects = kcalloc(arg->num_outputs, sizeof(struct drm_vmw_rect), |
| 2346 | GFP_KERNEL); |
Thomas Hellstrom | 5151adb | 2015-03-09 01:56:21 -0700 | [diff] [blame] | 2347 | if (unlikely(!rects)) |
| 2348 | return -ENOMEM; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2349 | |
| 2350 | user_rects = (void __user *)(unsigned long)arg->rects; |
| 2351 | ret = copy_from_user(rects, user_rects, rects_size); |
| 2352 | if (unlikely(ret != 0)) { |
| 2353 | DRM_ERROR("Failed to get rects.\n"); |
| 2354 | ret = -EFAULT; |
| 2355 | goto out_free; |
| 2356 | } |
| 2357 | |
| 2358 | for (i = 0; i < arg->num_outputs; ++i) { |
Xi Wang | bab9efc | 2011-11-28 12:25:43 +0100 | [diff] [blame] | 2359 | if (rects[i].x < 0 || |
| 2360 | rects[i].y < 0 || |
| 2361 | rects[i].x + rects[i].w > mode_config->max_width || |
| 2362 | rects[i].y + rects[i].h > mode_config->max_height) { |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2363 | DRM_ERROR("Invalid GUI layout.\n"); |
| 2364 | ret = -EINVAL; |
| 2365 | goto out_free; |
| 2366 | } |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 2367 | |
| 2368 | /* |
| 2369 | * bounding_box.w and bunding_box.h are used as |
| 2370 | * lower-right coordinates |
| 2371 | */ |
| 2372 | if (rects[i].x + rects[i].w > bounding_box.w) |
| 2373 | bounding_box.w = rects[i].x + rects[i].w; |
| 2374 | |
| 2375 | if (rects[i].y + rects[i].h > bounding_box.h) |
| 2376 | bounding_box.h = rects[i].y + rects[i].h; |
Sinclair Yeh | 65ade7d | 2015-07-16 10:49:13 -0700 | [diff] [blame] | 2377 | |
| 2378 | total_pixels += (u64) rects[i].w * (u64) rects[i].h; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2379 | } |
| 2380 | |
Sinclair Yeh | 65ade7d | 2015-07-16 10:49:13 -0700 | [diff] [blame] | 2381 | if (dev_priv->active_display_unit == vmw_du_screen_target) { |
| 2382 | /* |
| 2383 | * For Screen Targets, the limits for a toplogy are: |
| 2384 | * 1. Bounding box (assuming 32bpp) must be < prim_bb_mem |
| 2385 | * 2. Total pixels (assuming 32bpp) must be < prim_bb_mem |
| 2386 | */ |
Thomas Hellstrom | 0f58038 | 2017-01-19 11:01:04 -0800 | [diff] [blame] | 2387 | u64 bb_mem = (u64) bounding_box.w * bounding_box.h * 4; |
Sinclair Yeh | 65ade7d | 2015-07-16 10:49:13 -0700 | [diff] [blame] | 2388 | u64 pixel_mem = total_pixels * 4; |
| 2389 | |
| 2390 | if (bb_mem > dev_priv->prim_bb_mem) { |
| 2391 | DRM_ERROR("Topology is beyond supported limits.\n"); |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 2392 | ret = -EINVAL; |
| 2393 | goto out_free; |
| 2394 | } |
| 2395 | |
Sinclair Yeh | 65ade7d | 2015-07-16 10:49:13 -0700 | [diff] [blame] | 2396 | if (pixel_mem > dev_priv->prim_bb_mem) { |
| 2397 | DRM_ERROR("Combined output size too large\n"); |
| 2398 | ret = -EINVAL; |
| 2399 | goto out_free; |
| 2400 | } |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2401 | } |
| 2402 | |
| 2403 | vmw_du_update_layout(dev_priv, arg->num_outputs, rects); |
| 2404 | |
| 2405 | out_free: |
| 2406 | kfree(rects); |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2407 | return ret; |
| 2408 | } |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 2409 | |
| 2410 | /** |
| 2411 | * vmw_kms_helper_dirty - Helper to build commands and perform actions based |
| 2412 | * on a set of cliprects and a set of display units. |
| 2413 | * |
| 2414 | * @dev_priv: Pointer to a device private structure. |
| 2415 | * @framebuffer: Pointer to the framebuffer on which to perform the actions. |
| 2416 | * @clips: A set of struct drm_clip_rect. Either this os @vclips must be NULL. |
| 2417 | * Cliprects are given in framebuffer coordinates. |
| 2418 | * @vclips: A set of struct drm_vmw_rect cliprects. Either this or @clips must |
| 2419 | * be NULL. Cliprects are given in source coordinates. |
| 2420 | * @dest_x: X coordinate offset for the crtc / destination clip rects. |
| 2421 | * @dest_y: Y coordinate offset for the crtc / destination clip rects. |
| 2422 | * @num_clips: Number of cliprects in the @clips or @vclips array. |
| 2423 | * @increment: Integer with which to increment the clip counter when looping. |
| 2424 | * Used to skip a predetermined number of clip rects. |
| 2425 | * @dirty: Closure structure. See the description of struct vmw_kms_dirty. |
| 2426 | */ |
| 2427 | int vmw_kms_helper_dirty(struct vmw_private *dev_priv, |
| 2428 | struct vmw_framebuffer *framebuffer, |
| 2429 | const struct drm_clip_rect *clips, |
| 2430 | const struct drm_vmw_rect *vclips, |
| 2431 | s32 dest_x, s32 dest_y, |
| 2432 | int num_clips, |
| 2433 | int increment, |
| 2434 | struct vmw_kms_dirty *dirty) |
| 2435 | { |
| 2436 | struct vmw_display_unit *units[VMWGFX_NUM_DISPLAY_UNITS]; |
| 2437 | struct drm_crtc *crtc; |
| 2438 | u32 num_units = 0; |
| 2439 | u32 i, k; |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 2440 | |
| 2441 | dirty->dev_priv = dev_priv; |
| 2442 | |
| 2443 | list_for_each_entry(crtc, &dev_priv->dev->mode_config.crtc_list, head) { |
| 2444 | if (crtc->primary->fb != &framebuffer->base) |
| 2445 | continue; |
| 2446 | units[num_units++] = vmw_crtc_to_du(crtc); |
| 2447 | } |
| 2448 | |
| 2449 | for (k = 0; k < num_units; k++) { |
| 2450 | struct vmw_display_unit *unit = units[k]; |
| 2451 | s32 crtc_x = unit->crtc.x; |
| 2452 | s32 crtc_y = unit->crtc.y; |
| 2453 | s32 crtc_width = unit->crtc.mode.hdisplay; |
| 2454 | s32 crtc_height = unit->crtc.mode.vdisplay; |
| 2455 | const struct drm_clip_rect *clips_ptr = clips; |
| 2456 | const struct drm_vmw_rect *vclips_ptr = vclips; |
| 2457 | |
| 2458 | dirty->unit = unit; |
| 2459 | if (dirty->fifo_reserve_size > 0) { |
| 2460 | dirty->cmd = vmw_fifo_reserve(dev_priv, |
| 2461 | dirty->fifo_reserve_size); |
| 2462 | if (!dirty->cmd) { |
| 2463 | DRM_ERROR("Couldn't reserve fifo space " |
| 2464 | "for dirty blits.\n"); |
Christian Engelmayer | f3b8c0c | 2015-09-19 00:32:24 +0200 | [diff] [blame] | 2465 | return -ENOMEM; |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 2466 | } |
| 2467 | memset(dirty->cmd, 0, dirty->fifo_reserve_size); |
| 2468 | } |
| 2469 | dirty->num_hits = 0; |
| 2470 | for (i = 0; i < num_clips; i++, clips_ptr += increment, |
| 2471 | vclips_ptr += increment) { |
| 2472 | s32 clip_left; |
| 2473 | s32 clip_top; |
| 2474 | |
| 2475 | /* |
| 2476 | * Select clip array type. Note that integer type |
| 2477 | * in @clips is unsigned short, whereas in @vclips |
| 2478 | * it's 32-bit. |
| 2479 | */ |
| 2480 | if (clips) { |
| 2481 | dirty->fb_x = (s32) clips_ptr->x1; |
| 2482 | dirty->fb_y = (s32) clips_ptr->y1; |
| 2483 | dirty->unit_x2 = (s32) clips_ptr->x2 + dest_x - |
| 2484 | crtc_x; |
| 2485 | dirty->unit_y2 = (s32) clips_ptr->y2 + dest_y - |
| 2486 | crtc_y; |
| 2487 | } else { |
| 2488 | dirty->fb_x = vclips_ptr->x; |
| 2489 | dirty->fb_y = vclips_ptr->y; |
| 2490 | dirty->unit_x2 = dirty->fb_x + vclips_ptr->w + |
| 2491 | dest_x - crtc_x; |
| 2492 | dirty->unit_y2 = dirty->fb_y + vclips_ptr->h + |
| 2493 | dest_y - crtc_y; |
| 2494 | } |
| 2495 | |
| 2496 | dirty->unit_x1 = dirty->fb_x + dest_x - crtc_x; |
| 2497 | dirty->unit_y1 = dirty->fb_y + dest_y - crtc_y; |
| 2498 | |
| 2499 | /* Skip this clip if it's outside the crtc region */ |
| 2500 | if (dirty->unit_x1 >= crtc_width || |
| 2501 | dirty->unit_y1 >= crtc_height || |
| 2502 | dirty->unit_x2 <= 0 || dirty->unit_y2 <= 0) |
| 2503 | continue; |
| 2504 | |
| 2505 | /* Clip right and bottom to crtc limits */ |
| 2506 | dirty->unit_x2 = min_t(s32, dirty->unit_x2, |
| 2507 | crtc_width); |
| 2508 | dirty->unit_y2 = min_t(s32, dirty->unit_y2, |
| 2509 | crtc_height); |
| 2510 | |
| 2511 | /* Clip left and top to crtc limits */ |
| 2512 | clip_left = min_t(s32, dirty->unit_x1, 0); |
| 2513 | clip_top = min_t(s32, dirty->unit_y1, 0); |
| 2514 | dirty->unit_x1 -= clip_left; |
| 2515 | dirty->unit_y1 -= clip_top; |
| 2516 | dirty->fb_x -= clip_left; |
| 2517 | dirty->fb_y -= clip_top; |
| 2518 | |
| 2519 | dirty->clip(dirty); |
| 2520 | } |
| 2521 | |
| 2522 | dirty->fifo_commit(dirty); |
| 2523 | } |
| 2524 | |
| 2525 | return 0; |
| 2526 | } |
| 2527 | |
| 2528 | /** |
| 2529 | * vmw_kms_helper_buffer_prepare - Reserve and validate a buffer object before |
| 2530 | * command submission. |
| 2531 | * |
| 2532 | * @dev_priv. Pointer to a device private structure. |
| 2533 | * @buf: The buffer object |
| 2534 | * @interruptible: Whether to perform waits as interruptible. |
| 2535 | * @validate_as_mob: Whether the buffer should be validated as a MOB. If false, |
| 2536 | * The buffer will be validated as a GMR. Already pinned buffers will not be |
| 2537 | * validated. |
| 2538 | * |
| 2539 | * Returns 0 on success, negative error code on failure, -ERESTARTSYS if |
| 2540 | * interrupted by a signal. |
| 2541 | */ |
| 2542 | int vmw_kms_helper_buffer_prepare(struct vmw_private *dev_priv, |
| 2543 | struct vmw_dma_buffer *buf, |
| 2544 | bool interruptible, |
| 2545 | bool validate_as_mob) |
| 2546 | { |
| 2547 | struct ttm_buffer_object *bo = &buf->base; |
| 2548 | int ret; |
| 2549 | |
Christian König | dfd5e50 | 2016-04-06 11:12:03 +0200 | [diff] [blame] | 2550 | ttm_bo_reserve(bo, false, false, NULL); |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 2551 | ret = vmw_validate_single_buffer(dev_priv, bo, interruptible, |
| 2552 | validate_as_mob); |
| 2553 | if (ret) |
| 2554 | ttm_bo_unreserve(bo); |
| 2555 | |
| 2556 | return ret; |
| 2557 | } |
| 2558 | |
| 2559 | /** |
| 2560 | * vmw_kms_helper_buffer_revert - Undo the actions of |
| 2561 | * vmw_kms_helper_buffer_prepare. |
| 2562 | * |
| 2563 | * @res: Pointer to the buffer object. |
| 2564 | * |
| 2565 | * Helper to be used if an error forces the caller to undo the actions of |
| 2566 | * vmw_kms_helper_buffer_prepare. |
| 2567 | */ |
| 2568 | void vmw_kms_helper_buffer_revert(struct vmw_dma_buffer *buf) |
| 2569 | { |
| 2570 | if (buf) |
| 2571 | ttm_bo_unreserve(&buf->base); |
| 2572 | } |
| 2573 | |
| 2574 | /** |
| 2575 | * vmw_kms_helper_buffer_finish - Unreserve and fence a buffer object after |
| 2576 | * kms command submission. |
| 2577 | * |
| 2578 | * @dev_priv: Pointer to a device private structure. |
| 2579 | * @file_priv: Pointer to a struct drm_file representing the caller's |
| 2580 | * connection. Must be set to NULL if @user_fence_rep is NULL, and conversely |
| 2581 | * if non-NULL, @user_fence_rep must be non-NULL. |
| 2582 | * @buf: The buffer object. |
| 2583 | * @out_fence: Optional pointer to a fence pointer. If non-NULL, a |
| 2584 | * ref-counted fence pointer is returned here. |
| 2585 | * @user_fence_rep: Optional pointer to a user-space provided struct |
| 2586 | * drm_vmw_fence_rep. If provided, @file_priv must also be provided and the |
| 2587 | * function copies fence data to user-space in a fail-safe manner. |
| 2588 | */ |
| 2589 | void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv, |
| 2590 | struct drm_file *file_priv, |
| 2591 | struct vmw_dma_buffer *buf, |
| 2592 | struct vmw_fence_obj **out_fence, |
| 2593 | struct drm_vmw_fence_rep __user * |
| 2594 | user_fence_rep) |
| 2595 | { |
| 2596 | struct vmw_fence_obj *fence; |
| 2597 | uint32_t handle; |
| 2598 | int ret; |
| 2599 | |
| 2600 | ret = vmw_execbuf_fence_commands(file_priv, dev_priv, &fence, |
| 2601 | file_priv ? &handle : NULL); |
| 2602 | if (buf) |
| 2603 | vmw_fence_single_bo(&buf->base, fence); |
| 2604 | if (file_priv) |
| 2605 | vmw_execbuf_copy_fence_user(dev_priv, vmw_fpriv(file_priv), |
| 2606 | ret, user_fence_rep, fence, |
| 2607 | handle); |
| 2608 | if (out_fence) |
| 2609 | *out_fence = fence; |
| 2610 | else |
| 2611 | vmw_fence_obj_unreference(&fence); |
| 2612 | |
| 2613 | vmw_kms_helper_buffer_revert(buf); |
| 2614 | } |
| 2615 | |
| 2616 | |
| 2617 | /** |
| 2618 | * vmw_kms_helper_resource_revert - Undo the actions of |
| 2619 | * vmw_kms_helper_resource_prepare. |
| 2620 | * |
| 2621 | * @res: Pointer to the resource. Typically a surface. |
| 2622 | * |
| 2623 | * Helper to be used if an error forces the caller to undo the actions of |
| 2624 | * vmw_kms_helper_resource_prepare. |
| 2625 | */ |
| 2626 | void vmw_kms_helper_resource_revert(struct vmw_resource *res) |
| 2627 | { |
| 2628 | vmw_kms_helper_buffer_revert(res->backup); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2629 | vmw_resource_unreserve(res, false, NULL, 0); |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 2630 | mutex_unlock(&res->dev_priv->cmdbuf_mutex); |
| 2631 | } |
| 2632 | |
| 2633 | /** |
| 2634 | * vmw_kms_helper_resource_prepare - Reserve and validate a resource before |
| 2635 | * command submission. |
| 2636 | * |
| 2637 | * @res: Pointer to the resource. Typically a surface. |
| 2638 | * @interruptible: Whether to perform waits as interruptible. |
| 2639 | * |
| 2640 | * Reserves and validates also the backup buffer if a guest-backed resource. |
| 2641 | * Returns 0 on success, negative error code on failure. -ERESTARTSYS if |
| 2642 | * interrupted by a signal. |
| 2643 | */ |
| 2644 | int vmw_kms_helper_resource_prepare(struct vmw_resource *res, |
| 2645 | bool interruptible) |
| 2646 | { |
| 2647 | int ret = 0; |
| 2648 | |
| 2649 | if (interruptible) |
| 2650 | ret = mutex_lock_interruptible(&res->dev_priv->cmdbuf_mutex); |
| 2651 | else |
| 2652 | mutex_lock(&res->dev_priv->cmdbuf_mutex); |
| 2653 | |
| 2654 | if (unlikely(ret != 0)) |
| 2655 | return -ERESTARTSYS; |
| 2656 | |
| 2657 | ret = vmw_resource_reserve(res, interruptible, false); |
| 2658 | if (ret) |
| 2659 | goto out_unlock; |
| 2660 | |
| 2661 | if (res->backup) { |
| 2662 | ret = vmw_kms_helper_buffer_prepare(res->dev_priv, res->backup, |
| 2663 | interruptible, |
| 2664 | res->dev_priv->has_mob); |
| 2665 | if (ret) |
| 2666 | goto out_unreserve; |
| 2667 | } |
| 2668 | ret = vmw_resource_validate(res); |
| 2669 | if (ret) |
| 2670 | goto out_revert; |
| 2671 | return 0; |
| 2672 | |
| 2673 | out_revert: |
| 2674 | vmw_kms_helper_buffer_revert(res->backup); |
| 2675 | out_unreserve: |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2676 | vmw_resource_unreserve(res, false, NULL, 0); |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 2677 | out_unlock: |
| 2678 | mutex_unlock(&res->dev_priv->cmdbuf_mutex); |
| 2679 | return ret; |
| 2680 | } |
| 2681 | |
| 2682 | /** |
| 2683 | * vmw_kms_helper_resource_finish - Unreserve and fence a resource after |
| 2684 | * kms command submission. |
| 2685 | * |
| 2686 | * @res: Pointer to the resource. Typically a surface. |
| 2687 | * @out_fence: Optional pointer to a fence pointer. If non-NULL, a |
| 2688 | * ref-counted fence pointer is returned here. |
| 2689 | */ |
| 2690 | void vmw_kms_helper_resource_finish(struct vmw_resource *res, |
| 2691 | struct vmw_fence_obj **out_fence) |
| 2692 | { |
| 2693 | if (res->backup || out_fence) |
| 2694 | vmw_kms_helper_buffer_finish(res->dev_priv, NULL, res->backup, |
| 2695 | out_fence, NULL); |
| 2696 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2697 | vmw_resource_unreserve(res, false, NULL, 0); |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 2698 | mutex_unlock(&res->dev_priv->cmdbuf_mutex); |
| 2699 | } |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 2700 | |
| 2701 | /** |
| 2702 | * vmw_kms_update_proxy - Helper function to update a proxy surface from |
| 2703 | * its backing MOB. |
| 2704 | * |
| 2705 | * @res: Pointer to the surface resource |
| 2706 | * @clips: Clip rects in framebuffer (surface) space. |
| 2707 | * @num_clips: Number of clips in @clips. |
| 2708 | * @increment: Integer with which to increment the clip counter when looping. |
| 2709 | * Used to skip a predetermined number of clip rects. |
| 2710 | * |
| 2711 | * This function makes sure the proxy surface is updated from its backing MOB |
| 2712 | * using the region given by @clips. The surface resource @res and its backing |
| 2713 | * MOB needs to be reserved and validated on call. |
| 2714 | */ |
| 2715 | int vmw_kms_update_proxy(struct vmw_resource *res, |
| 2716 | const struct drm_clip_rect *clips, |
| 2717 | unsigned num_clips, |
| 2718 | int increment) |
| 2719 | { |
| 2720 | struct vmw_private *dev_priv = res->dev_priv; |
| 2721 | struct drm_vmw_size *size = &vmw_res_to_srf(res)->base_size; |
| 2722 | struct { |
| 2723 | SVGA3dCmdHeader header; |
| 2724 | SVGA3dCmdUpdateGBImage body; |
| 2725 | } *cmd; |
| 2726 | SVGA3dBox *box; |
| 2727 | size_t copy_size = 0; |
| 2728 | int i; |
| 2729 | |
| 2730 | if (!clips) |
| 2731 | return 0; |
| 2732 | |
| 2733 | cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd) * num_clips); |
| 2734 | if (!cmd) { |
| 2735 | DRM_ERROR("Couldn't reserve fifo space for proxy surface " |
| 2736 | "update.\n"); |
| 2737 | return -ENOMEM; |
| 2738 | } |
| 2739 | |
| 2740 | for (i = 0; i < num_clips; ++i, clips += increment, ++cmd) { |
| 2741 | box = &cmd->body.box; |
| 2742 | |
| 2743 | cmd->header.id = SVGA_3D_CMD_UPDATE_GB_IMAGE; |
| 2744 | cmd->header.size = sizeof(cmd->body); |
| 2745 | cmd->body.image.sid = res->id; |
| 2746 | cmd->body.image.face = 0; |
| 2747 | cmd->body.image.mipmap = 0; |
| 2748 | |
| 2749 | if (clips->x1 > size->width || clips->x2 > size->width || |
| 2750 | clips->y1 > size->height || clips->y2 > size->height) { |
| 2751 | DRM_ERROR("Invalid clips outsize of framebuffer.\n"); |
| 2752 | return -EINVAL; |
| 2753 | } |
| 2754 | |
| 2755 | box->x = clips->x1; |
| 2756 | box->y = clips->y1; |
| 2757 | box->z = 0; |
| 2758 | box->w = clips->x2 - clips->x1; |
| 2759 | box->h = clips->y2 - clips->y1; |
| 2760 | box->d = 1; |
| 2761 | |
| 2762 | copy_size += sizeof(*cmd); |
| 2763 | } |
| 2764 | |
| 2765 | vmw_fifo_commit(dev_priv, copy_size); |
| 2766 | |
| 2767 | return 0; |
| 2768 | } |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 2769 | |
| 2770 | int vmw_kms_fbdev_init_data(struct vmw_private *dev_priv, |
| 2771 | unsigned unit, |
| 2772 | u32 max_width, |
| 2773 | u32 max_height, |
| 2774 | struct drm_connector **p_con, |
| 2775 | struct drm_crtc **p_crtc, |
| 2776 | struct drm_display_mode **p_mode) |
| 2777 | { |
| 2778 | struct drm_connector *con; |
| 2779 | struct vmw_display_unit *du; |
| 2780 | struct drm_display_mode *mode; |
| 2781 | int i = 0; |
| 2782 | |
| 2783 | list_for_each_entry(con, &dev_priv->dev->mode_config.connector_list, |
| 2784 | head) { |
| 2785 | if (i == unit) |
| 2786 | break; |
| 2787 | |
| 2788 | ++i; |
| 2789 | } |
| 2790 | |
| 2791 | if (i != unit) { |
| 2792 | DRM_ERROR("Could not find initial display unit.\n"); |
| 2793 | return -EINVAL; |
| 2794 | } |
| 2795 | |
| 2796 | if (list_empty(&con->modes)) |
| 2797 | (void) vmw_du_connector_fill_modes(con, max_width, max_height); |
| 2798 | |
| 2799 | if (list_empty(&con->modes)) { |
| 2800 | DRM_ERROR("Could not find initial display mode.\n"); |
| 2801 | return -EINVAL; |
| 2802 | } |
| 2803 | |
| 2804 | du = vmw_connector_to_du(con); |
| 2805 | *p_con = con; |
| 2806 | *p_crtc = &du->crtc; |
| 2807 | |
| 2808 | list_for_each_entry(mode, &con->modes, head) { |
| 2809 | if (mode->type & DRM_MODE_TYPE_PREFERRED) |
| 2810 | break; |
| 2811 | } |
| 2812 | |
| 2813 | if (mode->type & DRM_MODE_TYPE_PREFERRED) |
| 2814 | *p_mode = mode; |
| 2815 | else { |
| 2816 | WARN_ONCE(true, "Could not find initial preferred mode.\n"); |
| 2817 | *p_mode = list_first_entry(&con->modes, |
| 2818 | struct drm_display_mode, |
| 2819 | head); |
| 2820 | } |
| 2821 | |
| 2822 | return 0; |
| 2823 | } |
Thomas Hellstrom | 75c0685 | 2016-02-12 09:00:26 +0100 | [diff] [blame] | 2824 | |
| 2825 | /** |
| 2826 | * vmw_kms_del_active - unregister a crtc binding to the implicit framebuffer |
| 2827 | * |
| 2828 | * @dev_priv: Pointer to a device private struct. |
| 2829 | * @du: The display unit of the crtc. |
| 2830 | */ |
| 2831 | void vmw_kms_del_active(struct vmw_private *dev_priv, |
| 2832 | struct vmw_display_unit *du) |
| 2833 | { |
Thomas Hellstrom | 93cd168 | 2016-05-03 11:24:35 +0200 | [diff] [blame] | 2834 | mutex_lock(&dev_priv->global_kms_state_mutex); |
Thomas Hellstrom | 75c0685 | 2016-02-12 09:00:26 +0100 | [diff] [blame] | 2835 | if (du->active_implicit) { |
| 2836 | if (--(dev_priv->num_implicit) == 0) |
| 2837 | dev_priv->implicit_fb = NULL; |
| 2838 | du->active_implicit = false; |
| 2839 | } |
Thomas Hellstrom | 93cd168 | 2016-05-03 11:24:35 +0200 | [diff] [blame] | 2840 | mutex_unlock(&dev_priv->global_kms_state_mutex); |
Thomas Hellstrom | 75c0685 | 2016-02-12 09:00:26 +0100 | [diff] [blame] | 2841 | } |
| 2842 | |
| 2843 | /** |
| 2844 | * vmw_kms_add_active - register a crtc binding to an implicit framebuffer |
| 2845 | * |
| 2846 | * @vmw_priv: Pointer to a device private struct. |
| 2847 | * @du: The display unit of the crtc. |
| 2848 | * @vfb: The implicit framebuffer |
| 2849 | * |
| 2850 | * Registers a binding to an implicit framebuffer. |
| 2851 | */ |
| 2852 | void vmw_kms_add_active(struct vmw_private *dev_priv, |
| 2853 | struct vmw_display_unit *du, |
| 2854 | struct vmw_framebuffer *vfb) |
| 2855 | { |
Thomas Hellstrom | 93cd168 | 2016-05-03 11:24:35 +0200 | [diff] [blame] | 2856 | mutex_lock(&dev_priv->global_kms_state_mutex); |
Thomas Hellstrom | 75c0685 | 2016-02-12 09:00:26 +0100 | [diff] [blame] | 2857 | WARN_ON_ONCE(!dev_priv->num_implicit && dev_priv->implicit_fb); |
| 2858 | |
| 2859 | if (!du->active_implicit && du->is_implicit) { |
| 2860 | dev_priv->implicit_fb = vfb; |
| 2861 | du->active_implicit = true; |
| 2862 | dev_priv->num_implicit++; |
| 2863 | } |
Thomas Hellstrom | 93cd168 | 2016-05-03 11:24:35 +0200 | [diff] [blame] | 2864 | mutex_unlock(&dev_priv->global_kms_state_mutex); |
Thomas Hellstrom | 75c0685 | 2016-02-12 09:00:26 +0100 | [diff] [blame] | 2865 | } |
| 2866 | |
| 2867 | /** |
| 2868 | * vmw_kms_screen_object_flippable - Check whether we can page-flip a crtc. |
| 2869 | * |
| 2870 | * @dev_priv: Pointer to device-private struct. |
| 2871 | * @crtc: The crtc we want to flip. |
| 2872 | * |
| 2873 | * Returns true or false depending whether it's OK to flip this crtc |
| 2874 | * based on the criterion that we must not have more than one implicit |
| 2875 | * frame-buffer at any one time. |
| 2876 | */ |
| 2877 | bool vmw_kms_crtc_flippable(struct vmw_private *dev_priv, |
| 2878 | struct drm_crtc *crtc) |
| 2879 | { |
| 2880 | struct vmw_display_unit *du = vmw_crtc_to_du(crtc); |
Thomas Hellstrom | 93cd168 | 2016-05-03 11:24:35 +0200 | [diff] [blame] | 2881 | bool ret; |
Thomas Hellstrom | 75c0685 | 2016-02-12 09:00:26 +0100 | [diff] [blame] | 2882 | |
Thomas Hellstrom | 93cd168 | 2016-05-03 11:24:35 +0200 | [diff] [blame] | 2883 | mutex_lock(&dev_priv->global_kms_state_mutex); |
| 2884 | ret = !du->is_implicit || dev_priv->num_implicit == 1; |
| 2885 | mutex_unlock(&dev_priv->global_kms_state_mutex); |
Thomas Hellstrom | 75c0685 | 2016-02-12 09:00:26 +0100 | [diff] [blame] | 2886 | |
Thomas Hellstrom | 93cd168 | 2016-05-03 11:24:35 +0200 | [diff] [blame] | 2887 | return ret; |
Thomas Hellstrom | 75c0685 | 2016-02-12 09:00:26 +0100 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | /** |
| 2891 | * vmw_kms_update_implicit_fb - Update the implicit fb. |
| 2892 | * |
| 2893 | * @dev_priv: Pointer to device-private struct. |
| 2894 | * @crtc: The crtc the new implicit frame-buffer is bound to. |
| 2895 | */ |
| 2896 | void vmw_kms_update_implicit_fb(struct vmw_private *dev_priv, |
| 2897 | struct drm_crtc *crtc) |
| 2898 | { |
| 2899 | struct vmw_display_unit *du = vmw_crtc_to_du(crtc); |
| 2900 | struct vmw_framebuffer *vfb; |
| 2901 | |
Thomas Hellstrom | 93cd168 | 2016-05-03 11:24:35 +0200 | [diff] [blame] | 2902 | mutex_lock(&dev_priv->global_kms_state_mutex); |
Thomas Hellstrom | 75c0685 | 2016-02-12 09:00:26 +0100 | [diff] [blame] | 2903 | |
| 2904 | if (!du->is_implicit) |
Thomas Hellstrom | 93cd168 | 2016-05-03 11:24:35 +0200 | [diff] [blame] | 2905 | goto out_unlock; |
Thomas Hellstrom | 75c0685 | 2016-02-12 09:00:26 +0100 | [diff] [blame] | 2906 | |
| 2907 | vfb = vmw_framebuffer_to_vfb(crtc->primary->fb); |
| 2908 | WARN_ON_ONCE(dev_priv->num_implicit != 1 && |
| 2909 | dev_priv->implicit_fb != vfb); |
| 2910 | |
| 2911 | dev_priv->implicit_fb = vfb; |
Thomas Hellstrom | 93cd168 | 2016-05-03 11:24:35 +0200 | [diff] [blame] | 2912 | out_unlock: |
| 2913 | mutex_unlock(&dev_priv->global_kms_state_mutex); |
Thomas Hellstrom | 75c0685 | 2016-02-12 09:00:26 +0100 | [diff] [blame] | 2914 | } |
Thomas Hellstrom | 76404ac | 2016-02-12 09:55:45 +0100 | [diff] [blame] | 2915 | |
| 2916 | /** |
| 2917 | * vmw_kms_create_implicit_placement_proparty - Set up the implicit placement |
| 2918 | * property. |
| 2919 | * |
| 2920 | * @dev_priv: Pointer to a device private struct. |
| 2921 | * @immutable: Whether the property is immutable. |
| 2922 | * |
| 2923 | * Sets up the implicit placement property unless it's already set up. |
| 2924 | */ |
| 2925 | void |
| 2926 | vmw_kms_create_implicit_placement_property(struct vmw_private *dev_priv, |
| 2927 | bool immutable) |
| 2928 | { |
| 2929 | if (dev_priv->implicit_placement_property) |
| 2930 | return; |
| 2931 | |
| 2932 | dev_priv->implicit_placement_property = |
| 2933 | drm_property_create_range(dev_priv->dev, |
| 2934 | immutable ? |
| 2935 | DRM_MODE_PROP_IMMUTABLE : 0, |
| 2936 | "implicit_placement", 0, 1); |
| 2937 | |
| 2938 | } |
Sinclair Yeh | 904bb5e | 2017-03-23 14:29:22 -0700 | [diff] [blame] | 2939 | |
| 2940 | |
| 2941 | /** |
| 2942 | * vmw_kms_set_config - Wrapper around drm_atomic_helper_set_config |
| 2943 | * |
| 2944 | * @set: The configuration to set. |
| 2945 | * |
| 2946 | * The vmwgfx Xorg driver doesn't assign the mode::type member, which |
| 2947 | * when drm_mode_set_crtcinfo is called as part of the configuration setting |
| 2948 | * causes it to return incorrect crtc dimensions causing severe problems in |
| 2949 | * the vmwgfx modesetting. So explicitly clear that member before calling |
| 2950 | * into drm_atomic_helper_set_config. |
| 2951 | */ |
Dave Airlie | 320d8c3 | 2017-04-03 16:30:24 +1000 | [diff] [blame] | 2952 | int vmw_kms_set_config(struct drm_mode_set *set, |
| 2953 | struct drm_modeset_acquire_ctx *ctx) |
Sinclair Yeh | 904bb5e | 2017-03-23 14:29:22 -0700 | [diff] [blame] | 2954 | { |
| 2955 | if (set && set->mode) |
| 2956 | set->mode->type = 0; |
| 2957 | |
Dave Airlie | 320d8c3 | 2017-04-03 16:30:24 +1000 | [diff] [blame] | 2958 | return drm_atomic_helper_set_config(set, ctx); |
Sinclair Yeh | 904bb5e | 2017-03-23 14:29:22 -0700 | [diff] [blame] | 2959 | } |