Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'vmwgfx-next-4.19-2' of git://people.freedesktop.org/~thomash/linux into drm-next

A series of cleanups / reorganizations and modesetting changes that
mostly target atomic state validation.

[airlied: conflicts with SPDX stuff in amdgpu tree]
Signed-off-by: Dave Airlie <airlied@redhat.com>

Link: https://patchwork.freedesktop.org/patch/msgid/1a88485e-e509-b00e-8485-19194f074115@vmware.com

+2014 -1647
+2 -2
drivers/gpu/drm/vmwgfx/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 vmwgfx-y := vmwgfx_execbuf.o vmwgfx_gmr.o vmwgfx_kms.o vmwgfx_drv.o \ 3 - vmwgfx_fb.o vmwgfx_ioctl.o vmwgfx_resource.o vmwgfx_buffer.o \ 3 + vmwgfx_fb.o vmwgfx_ioctl.o vmwgfx_resource.o vmwgfx_ttm_buffer.o \ 4 4 vmwgfx_fifo.o vmwgfx_irq.o vmwgfx_ldu.o vmwgfx_ttm_glue.o \ 5 5 vmwgfx_overlay.o vmwgfx_marker.o vmwgfx_gmrid_manager.o \ 6 - vmwgfx_fence.o vmwgfx_dmabuf.o vmwgfx_scrn.o vmwgfx_context.o \ 6 + vmwgfx_fence.o vmwgfx_bo.o vmwgfx_scrn.o vmwgfx_context.o \ 7 7 vmwgfx_surface.o vmwgfx_prime.o vmwgfx_mob.o vmwgfx_shader.o \ 8 8 vmwgfx_cmdbuf_res.o vmwgfx_cmdbuf.o vmwgfx_stdu.o \ 9 9 vmwgfx_cotable.o vmwgfx_so.o vmwgfx_binding.o vmwgfx_msg.o \
+29 -2
drivers/gpu/drm/vmwgfx/device_include/svga_reg.h
··· 673 673 * SVGA_CAP_GBOBJECTS -- 674 674 * Enable guest-backed objects and surfaces. 675 675 * 676 - * SVGA_CAP_CMD_BUFFERS_3 -- 677 - * Enable support for command buffers in a mob. 676 + * SVGA_CAP_DX -- 677 + * Enable support for DX commands, and command buffers in a mob. 678 + * 679 + * SVGA_CAP_HP_CMD_QUEUE -- 680 + * Enable support for the high priority command queue, and the 681 + * ScreenCopy command. 682 + * 683 + * SVGA_CAP_NO_BB_RESTRICTION -- 684 + * Allow ScreenTargets to be defined without regard to the 32-bpp 685 + * bounding-box memory restrictions. ie: 686 + * 687 + * The summed memory usage of all screens (assuming they were defined as 688 + * 32-bpp) must always be less than the value of the 689 + * SVGA_REG_MAX_PRIMARY_MEM register. 690 + * 691 + * If this cap is not present, the 32-bpp bounding box around all screens 692 + * must additionally be under the value of the SVGA_REG_MAX_PRIMARY_MEM 693 + * register. 694 + * 695 + * If the cap is present, the bounding box restriction is lifted (and only 696 + * the screen-sum limit applies). 697 + * 698 + * (Note that this is a slight lie... there is still a sanity limit on any 699 + * dimension of the topology to be less than SVGA_SCREEN_ROOT_LIMIT, even 700 + * when SVGA_CAP_NO_BB_RESTRICTION is present, but that should be 701 + * large enough to express any possible topology without holes between 702 + * monitors.) 703 + * 678 704 */ 679 705 680 706 #define SVGA_CAP_NONE 0x00000000 ··· 726 700 #define SVGA_CAP_GBOBJECTS 0x08000000 727 701 #define SVGA_CAP_DX 0x10000000 728 702 #define SVGA_CAP_HP_CMD_QUEUE 0x20000000 703 + #define SVGA_CAP_NO_BB_RESTRICTION 0x40000000 729 704 730 705 #define SVGA_CAP_CMD_RESERVED 0x80000000 731 706
+1123
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 OR MIT 2 + /************************************************************************** 3 + * 4 + * Copyright © 2011-2018 VMware, Inc., Palo Alto, CA., USA 5 + * All Rights Reserved. 6 + * 7 + * Permission is hereby granted, free of charge, to any person obtaining a 8 + * copy of this software and associated documentation files (the 9 + * "Software"), to deal in the Software without restriction, including 10 + * without limitation the rights to use, copy, modify, merge, publish, 11 + * distribute, sub license, and/or sell copies of the Software, and to 12 + * permit persons to whom the Software is furnished to do so, subject to 13 + * the following conditions: 14 + * 15 + * The above copyright notice and this permission notice (including the 16 + * next paragraph) shall be included in all copies or substantial portions 17 + * of the Software. 18 + * 19 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 22 + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 23 + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 24 + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 25 + * USE OR OTHER DEALINGS IN THE SOFTWARE. 26 + * 27 + **************************************************************************/ 28 + 29 + #include <drm/ttm/ttm_placement.h> 30 + 31 + #include <drm/drmP.h> 32 + #include "vmwgfx_drv.h" 33 + #include "drm/ttm/ttm_object.h" 34 + 35 + 36 + /** 37 + * struct vmw_user_buffer_object - User-space-visible buffer object 38 + * 39 + * @prime: The prime object providing user visibility. 40 + * @vbo: The struct vmw_buffer_object 41 + */ 42 + struct vmw_user_buffer_object { 43 + struct ttm_prime_object prime; 44 + struct vmw_buffer_object vbo; 45 + }; 46 + 47 + 48 + /** 49 + * vmw_buffer_object - Convert a struct ttm_buffer_object to a struct 50 + * vmw_buffer_object. 51 + * 52 + * @bo: Pointer to the TTM buffer object. 53 + * Return: Pointer to the struct vmw_buffer_object embedding the 54 + * TTM buffer object. 55 + */ 56 + static struct vmw_buffer_object * 57 + vmw_buffer_object(struct ttm_buffer_object *bo) 58 + { 59 + return container_of(bo, struct vmw_buffer_object, base); 60 + } 61 + 62 + 63 + /** 64 + * vmw_user_buffer_object - Convert a struct ttm_buffer_object to a struct 65 + * vmw_user_buffer_object. 66 + * 67 + * @bo: Pointer to the TTM buffer object. 68 + * Return: Pointer to the struct vmw_buffer_object embedding the TTM buffer 69 + * object. 70 + */ 71 + static struct vmw_user_buffer_object * 72 + vmw_user_buffer_object(struct ttm_buffer_object *bo) 73 + { 74 + struct vmw_buffer_object *vmw_bo = vmw_buffer_object(bo); 75 + 76 + return container_of(vmw_bo, struct vmw_user_buffer_object, vbo); 77 + } 78 + 79 + 80 + /** 81 + * vmw_bo_pin_in_placement - Validate a buffer to placement. 82 + * 83 + * @dev_priv: Driver private. 84 + * @buf: DMA buffer to move. 85 + * @placement: The placement to pin it. 86 + * @interruptible: Use interruptible wait. 87 + * Return: Zero on success, Negative error code on failure. In particular 88 + * -ERESTARTSYS if interrupted by a signal 89 + */ 90 + int vmw_bo_pin_in_placement(struct vmw_private *dev_priv, 91 + struct vmw_buffer_object *buf, 92 + struct ttm_placement *placement, 93 + bool interruptible) 94 + { 95 + struct ttm_operation_ctx ctx = {interruptible, false }; 96 + struct ttm_buffer_object *bo = &buf->base; 97 + int ret; 98 + uint32_t new_flags; 99 + 100 + ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible); 101 + if (unlikely(ret != 0)) 102 + return ret; 103 + 104 + vmw_execbuf_release_pinned_bo(dev_priv); 105 + 106 + ret = ttm_bo_reserve(bo, interruptible, false, NULL); 107 + if (unlikely(ret != 0)) 108 + goto err; 109 + 110 + if (buf->pin_count > 0) 111 + ret = ttm_bo_mem_compat(placement, &bo->mem, 112 + &new_flags) == true ? 0 : -EINVAL; 113 + else 114 + ret = ttm_bo_validate(bo, placement, &ctx); 115 + 116 + if (!ret) 117 + vmw_bo_pin_reserved(buf, true); 118 + 119 + ttm_bo_unreserve(bo); 120 + 121 + err: 122 + ttm_write_unlock(&dev_priv->reservation_sem); 123 + return ret; 124 + } 125 + 126 + 127 + /** 128 + * vmw_bo_pin_in_vram_or_gmr - Move a buffer to vram or gmr. 129 + * 130 + * This function takes the reservation_sem in write mode. 131 + * Flushes and unpins the query bo to avoid failures. 132 + * 133 + * @dev_priv: Driver private. 134 + * @buf: DMA buffer to move. 135 + * @pin: Pin buffer if true. 136 + * @interruptible: Use interruptible wait. 137 + * Return: Zero on success, Negative error code on failure. In particular 138 + * -ERESTARTSYS if interrupted by a signal 139 + */ 140 + int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv, 141 + struct vmw_buffer_object *buf, 142 + bool interruptible) 143 + { 144 + struct ttm_operation_ctx ctx = {interruptible, false }; 145 + struct ttm_buffer_object *bo = &buf->base; 146 + int ret; 147 + uint32_t new_flags; 148 + 149 + ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible); 150 + if (unlikely(ret != 0)) 151 + return ret; 152 + 153 + vmw_execbuf_release_pinned_bo(dev_priv); 154 + 155 + ret = ttm_bo_reserve(bo, interruptible, false, NULL); 156 + if (unlikely(ret != 0)) 157 + goto err; 158 + 159 + if (buf->pin_count > 0) { 160 + ret = ttm_bo_mem_compat(&vmw_vram_gmr_placement, &bo->mem, 161 + &new_flags) == true ? 0 : -EINVAL; 162 + goto out_unreserve; 163 + } 164 + 165 + ret = ttm_bo_validate(bo, &vmw_vram_gmr_placement, &ctx); 166 + if (likely(ret == 0) || ret == -ERESTARTSYS) 167 + goto out_unreserve; 168 + 169 + ret = ttm_bo_validate(bo, &vmw_vram_placement, &ctx); 170 + 171 + out_unreserve: 172 + if (!ret) 173 + vmw_bo_pin_reserved(buf, true); 174 + 175 + ttm_bo_unreserve(bo); 176 + err: 177 + ttm_write_unlock(&dev_priv->reservation_sem); 178 + return ret; 179 + } 180 + 181 + 182 + /** 183 + * vmw_bo_pin_in_vram - Move a buffer to vram. 184 + * 185 + * This function takes the reservation_sem in write mode. 186 + * Flushes and unpins the query bo to avoid failures. 187 + * 188 + * @dev_priv: Driver private. 189 + * @buf: DMA buffer to move. 190 + * @interruptible: Use interruptible wait. 191 + * Return: Zero on success, Negative error code on failure. In particular 192 + * -ERESTARTSYS if interrupted by a signal 193 + */ 194 + int vmw_bo_pin_in_vram(struct vmw_private *dev_priv, 195 + struct vmw_buffer_object *buf, 196 + bool interruptible) 197 + { 198 + return vmw_bo_pin_in_placement(dev_priv, buf, &vmw_vram_placement, 199 + interruptible); 200 + } 201 + 202 + 203 + /** 204 + * vmw_bo_pin_in_start_of_vram - Move a buffer to start of vram. 205 + * 206 + * This function takes the reservation_sem in write mode. 207 + * Flushes and unpins the query bo to avoid failures. 208 + * 209 + * @dev_priv: Driver private. 210 + * @buf: DMA buffer to pin. 211 + * @interruptible: Use interruptible wait. 212 + * Return: Zero on success, Negative error code on failure. In particular 213 + * -ERESTARTSYS if interrupted by a signal 214 + */ 215 + int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv, 216 + struct vmw_buffer_object *buf, 217 + bool interruptible) 218 + { 219 + struct ttm_operation_ctx ctx = {interruptible, false }; 220 + struct ttm_buffer_object *bo = &buf->base; 221 + struct ttm_placement placement; 222 + struct ttm_place place; 223 + int ret = 0; 224 + uint32_t new_flags; 225 + 226 + place = vmw_vram_placement.placement[0]; 227 + place.lpfn = bo->num_pages; 228 + placement.num_placement = 1; 229 + placement.placement = &place; 230 + placement.num_busy_placement = 1; 231 + placement.busy_placement = &place; 232 + 233 + ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible); 234 + if (unlikely(ret != 0)) 235 + return ret; 236 + 237 + vmw_execbuf_release_pinned_bo(dev_priv); 238 + ret = ttm_bo_reserve(bo, interruptible, false, NULL); 239 + if (unlikely(ret != 0)) 240 + goto err_unlock; 241 + 242 + /* 243 + * Is this buffer already in vram but not at the start of it? 244 + * In that case, evict it first because TTM isn't good at handling 245 + * that situation. 246 + */ 247 + if (bo->mem.mem_type == TTM_PL_VRAM && 248 + bo->mem.start < bo->num_pages && 249 + bo->mem.start > 0 && 250 + buf->pin_count == 0) { 251 + ctx.interruptible = false; 252 + (void) ttm_bo_validate(bo, &vmw_sys_placement, &ctx); 253 + } 254 + 255 + if (buf->pin_count > 0) 256 + ret = ttm_bo_mem_compat(&placement, &bo->mem, 257 + &new_flags) == true ? 0 : -EINVAL; 258 + else 259 + ret = ttm_bo_validate(bo, &placement, &ctx); 260 + 261 + /* For some reason we didn't end up at the start of vram */ 262 + WARN_ON(ret == 0 && bo->offset != 0); 263 + if (!ret) 264 + vmw_bo_pin_reserved(buf, true); 265 + 266 + ttm_bo_unreserve(bo); 267 + err_unlock: 268 + ttm_write_unlock(&dev_priv->reservation_sem); 269 + 270 + return ret; 271 + } 272 + 273 + 274 + /** 275 + * vmw_bo_unpin - Unpin the buffer given buffer, does not move the buffer. 276 + * 277 + * This function takes the reservation_sem in write mode. 278 + * 279 + * @dev_priv: Driver private. 280 + * @buf: DMA buffer to unpin. 281 + * @interruptible: Use interruptible wait. 282 + * Return: Zero on success, Negative error code on failure. In particular 283 + * -ERESTARTSYS if interrupted by a signal 284 + */ 285 + int vmw_bo_unpin(struct vmw_private *dev_priv, 286 + struct vmw_buffer_object *buf, 287 + bool interruptible) 288 + { 289 + struct ttm_buffer_object *bo = &buf->base; 290 + int ret; 291 + 292 + ret = ttm_read_lock(&dev_priv->reservation_sem, interruptible); 293 + if (unlikely(ret != 0)) 294 + return ret; 295 + 296 + ret = ttm_bo_reserve(bo, interruptible, false, NULL); 297 + if (unlikely(ret != 0)) 298 + goto err; 299 + 300 + vmw_bo_pin_reserved(buf, false); 301 + 302 + ttm_bo_unreserve(bo); 303 + 304 + err: 305 + ttm_read_unlock(&dev_priv->reservation_sem); 306 + return ret; 307 + } 308 + 309 + /** 310 + * vmw_bo_get_guest_ptr - Get the guest ptr representing the current placement 311 + * of a buffer. 312 + * 313 + * @bo: Pointer to a struct ttm_buffer_object. Must be pinned or reserved. 314 + * @ptr: SVGAGuestPtr returning the result. 315 + */ 316 + void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *bo, 317 + SVGAGuestPtr *ptr) 318 + { 319 + if (bo->mem.mem_type == TTM_PL_VRAM) { 320 + ptr->gmrId = SVGA_GMR_FRAMEBUFFER; 321 + ptr->offset = bo->offset; 322 + } else { 323 + ptr->gmrId = bo->mem.start; 324 + ptr->offset = 0; 325 + } 326 + } 327 + 328 + 329 + /** 330 + * vmw_bo_pin_reserved - Pin or unpin a buffer object without moving it. 331 + * 332 + * @vbo: The buffer object. Must be reserved. 333 + * @pin: Whether to pin or unpin. 334 + * 335 + */ 336 + void vmw_bo_pin_reserved(struct vmw_buffer_object *vbo, bool pin) 337 + { 338 + struct ttm_operation_ctx ctx = { false, true }; 339 + struct ttm_place pl; 340 + struct ttm_placement placement; 341 + struct ttm_buffer_object *bo = &vbo->base; 342 + uint32_t old_mem_type = bo->mem.mem_type; 343 + int ret; 344 + 345 + lockdep_assert_held(&bo->resv->lock.base); 346 + 347 + if (pin) { 348 + if (vbo->pin_count++ > 0) 349 + return; 350 + } else { 351 + WARN_ON(vbo->pin_count <= 0); 352 + if (--vbo->pin_count > 0) 353 + return; 354 + } 355 + 356 + pl.fpfn = 0; 357 + pl.lpfn = 0; 358 + pl.flags = TTM_PL_FLAG_VRAM | VMW_PL_FLAG_GMR | VMW_PL_FLAG_MOB 359 + | TTM_PL_FLAG_SYSTEM | TTM_PL_FLAG_CACHED; 360 + if (pin) 361 + pl.flags |= TTM_PL_FLAG_NO_EVICT; 362 + 363 + memset(&placement, 0, sizeof(placement)); 364 + placement.num_placement = 1; 365 + placement.placement = &pl; 366 + 367 + ret = ttm_bo_validate(bo, &placement, &ctx); 368 + 369 + BUG_ON(ret != 0 || bo->mem.mem_type != old_mem_type); 370 + } 371 + 372 + 373 + /** 374 + * vmw_bo_map_and_cache - Map a buffer object and cache the map 375 + * 376 + * @vbo: The buffer object to map 377 + * Return: A kernel virtual address or NULL if mapping failed. 378 + * 379 + * This function maps a buffer object into the kernel address space, or 380 + * returns the virtual kernel address of an already existing map. The virtual 381 + * address remains valid as long as the buffer object is pinned or reserved. 382 + * The cached map is torn down on either 383 + * 1) Buffer object move 384 + * 2) Buffer object swapout 385 + * 3) Buffer object destruction 386 + * 387 + */ 388 + void *vmw_bo_map_and_cache(struct vmw_buffer_object *vbo) 389 + { 390 + struct ttm_buffer_object *bo = &vbo->base; 391 + bool not_used; 392 + void *virtual; 393 + int ret; 394 + 395 + virtual = ttm_kmap_obj_virtual(&vbo->map, &not_used); 396 + if (virtual) 397 + return virtual; 398 + 399 + ret = ttm_bo_kmap(bo, 0, bo->num_pages, &vbo->map); 400 + if (ret) 401 + DRM_ERROR("Buffer object map failed: %d.\n", ret); 402 + 403 + return ttm_kmap_obj_virtual(&vbo->map, &not_used); 404 + } 405 + 406 + 407 + /** 408 + * vmw_bo_unmap - Tear down a cached buffer object map. 409 + * 410 + * @vbo: The buffer object whose map we are tearing down. 411 + * 412 + * This function tears down a cached map set up using 413 + * vmw_buffer_object_map_and_cache(). 414 + */ 415 + void vmw_bo_unmap(struct vmw_buffer_object *vbo) 416 + { 417 + if (vbo->map.bo == NULL) 418 + return; 419 + 420 + ttm_bo_kunmap(&vbo->map); 421 + } 422 + 423 + 424 + /** 425 + * vmw_bo_acc_size - Calculate the pinned memory usage of buffers 426 + * 427 + * @dev_priv: Pointer to a struct vmw_private identifying the device. 428 + * @size: The requested buffer size. 429 + * @user: Whether this is an ordinary dma buffer or a user dma buffer. 430 + */ 431 + static size_t vmw_bo_acc_size(struct vmw_private *dev_priv, size_t size, 432 + bool user) 433 + { 434 + static size_t struct_size, user_struct_size; 435 + size_t num_pages = PAGE_ALIGN(size) >> PAGE_SHIFT; 436 + size_t page_array_size = ttm_round_pot(num_pages * sizeof(void *)); 437 + 438 + if (unlikely(struct_size == 0)) { 439 + size_t backend_size = ttm_round_pot(vmw_tt_size); 440 + 441 + struct_size = backend_size + 442 + ttm_round_pot(sizeof(struct vmw_buffer_object)); 443 + user_struct_size = backend_size + 444 + ttm_round_pot(sizeof(struct vmw_user_buffer_object)); 445 + } 446 + 447 + if (dev_priv->map_mode == vmw_dma_alloc_coherent) 448 + page_array_size += 449 + ttm_round_pot(num_pages * sizeof(dma_addr_t)); 450 + 451 + return ((user) ? user_struct_size : struct_size) + 452 + page_array_size; 453 + } 454 + 455 + 456 + /** 457 + * vmw_bo_bo_free - vmw buffer object destructor 458 + * 459 + * @bo: Pointer to the embedded struct ttm_buffer_object 460 + */ 461 + void vmw_bo_bo_free(struct ttm_buffer_object *bo) 462 + { 463 + struct vmw_buffer_object *vmw_bo = vmw_buffer_object(bo); 464 + 465 + vmw_bo_unmap(vmw_bo); 466 + kfree(vmw_bo); 467 + } 468 + 469 + 470 + /** 471 + * vmw_user_bo_destroy - vmw buffer object destructor 472 + * 473 + * @bo: Pointer to the embedded struct ttm_buffer_object 474 + */ 475 + static void vmw_user_bo_destroy(struct ttm_buffer_object *bo) 476 + { 477 + struct vmw_user_buffer_object *vmw_user_bo = vmw_user_buffer_object(bo); 478 + 479 + vmw_bo_unmap(&vmw_user_bo->vbo); 480 + ttm_prime_object_kfree(vmw_user_bo, prime); 481 + } 482 + 483 + 484 + /** 485 + * vmw_bo_init - Initialize a vmw buffer object 486 + * 487 + * @dev_priv: Pointer to the device private struct 488 + * @vmw_bo: Pointer to the struct vmw_buffer_object to initialize. 489 + * @size: Buffer object size in bytes. 490 + * @placement: Initial placement. 491 + * @interruptible: Whether waits should be performed interruptible. 492 + * @bo_free: The buffer object destructor. 493 + * Returns: Zero on success, negative error code on error. 494 + * 495 + * Note that on error, the code will free the buffer object. 496 + */ 497 + int vmw_bo_init(struct vmw_private *dev_priv, 498 + struct vmw_buffer_object *vmw_bo, 499 + size_t size, struct ttm_placement *placement, 500 + bool interruptible, 501 + void (*bo_free)(struct ttm_buffer_object *bo)) 502 + { 503 + struct ttm_bo_device *bdev = &dev_priv->bdev; 504 + size_t acc_size; 505 + int ret; 506 + bool user = (bo_free == &vmw_user_bo_destroy); 507 + 508 + WARN_ON_ONCE(!bo_free && (!user && (bo_free != vmw_bo_bo_free))); 509 + 510 + acc_size = vmw_bo_acc_size(dev_priv, size, user); 511 + memset(vmw_bo, 0, sizeof(*vmw_bo)); 512 + 513 + INIT_LIST_HEAD(&vmw_bo->res_list); 514 + 515 + ret = ttm_bo_init(bdev, &vmw_bo->base, size, 516 + ttm_bo_type_device, placement, 517 + 0, interruptible, acc_size, 518 + NULL, NULL, bo_free); 519 + return ret; 520 + } 521 + 522 + 523 + /** 524 + * vmw_user_bo_release - TTM reference base object release callback for 525 + * vmw user buffer objects 526 + * 527 + * @p_base: The TTM base object pointer about to be unreferenced. 528 + * 529 + * Clears the TTM base object pointer and drops the reference the 530 + * base object has on the underlying struct vmw_buffer_object. 531 + */ 532 + static void vmw_user_bo_release(struct ttm_base_object **p_base) 533 + { 534 + struct vmw_user_buffer_object *vmw_user_bo; 535 + struct ttm_base_object *base = *p_base; 536 + struct ttm_buffer_object *bo; 537 + 538 + *p_base = NULL; 539 + 540 + if (unlikely(base == NULL)) 541 + return; 542 + 543 + vmw_user_bo = container_of(base, struct vmw_user_buffer_object, 544 + prime.base); 545 + bo = &vmw_user_bo->vbo.base; 546 + ttm_bo_unref(&bo); 547 + } 548 + 549 + 550 + /** 551 + * vmw_user_bo_ref_obj-release - TTM synccpu reference object release callback 552 + * for vmw user buffer objects 553 + * 554 + * @base: Pointer to the TTM base object 555 + * @ref_type: Reference type of the reference reaching zero. 556 + * 557 + * Called when user-space drops its last synccpu reference on the buffer 558 + * object, Either explicitly or as part of a cleanup file close. 559 + */ 560 + static void vmw_user_bo_ref_obj_release(struct ttm_base_object *base, 561 + enum ttm_ref_type ref_type) 562 + { 563 + struct vmw_user_buffer_object *user_bo; 564 + 565 + user_bo = container_of(base, struct vmw_user_buffer_object, prime.base); 566 + 567 + switch (ref_type) { 568 + case TTM_REF_SYNCCPU_WRITE: 569 + ttm_bo_synccpu_write_release(&user_bo->vbo.base); 570 + break; 571 + default: 572 + WARN_ONCE(true, "Undefined buffer object reference release.\n"); 573 + } 574 + } 575 + 576 + 577 + /** 578 + * vmw_user_bo_alloc - Allocate a user buffer object 579 + * 580 + * @dev_priv: Pointer to a struct device private. 581 + * @tfile: Pointer to a struct ttm_object_file on which to register the user 582 + * object. 583 + * @size: Size of the buffer object. 584 + * @shareable: Boolean whether the buffer is shareable with other open files. 585 + * @handle: Pointer to where the handle value should be assigned. 586 + * @p_vbo: Pointer to where the refcounted struct vmw_buffer_object pointer 587 + * should be assigned. 588 + * Return: Zero on success, negative error code on error. 589 + */ 590 + int vmw_user_bo_alloc(struct vmw_private *dev_priv, 591 + struct ttm_object_file *tfile, 592 + uint32_t size, 593 + bool shareable, 594 + uint32_t *handle, 595 + struct vmw_buffer_object **p_vbo, 596 + struct ttm_base_object **p_base) 597 + { 598 + struct vmw_user_buffer_object *user_bo; 599 + struct ttm_buffer_object *tmp; 600 + int ret; 601 + 602 + user_bo = kzalloc(sizeof(*user_bo), GFP_KERNEL); 603 + if (unlikely(!user_bo)) { 604 + DRM_ERROR("Failed to allocate a buffer.\n"); 605 + return -ENOMEM; 606 + } 607 + 608 + ret = vmw_bo_init(dev_priv, &user_bo->vbo, size, 609 + (dev_priv->has_mob) ? 610 + &vmw_sys_placement : 611 + &vmw_vram_sys_placement, true, 612 + &vmw_user_bo_destroy); 613 + if (unlikely(ret != 0)) 614 + return ret; 615 + 616 + tmp = ttm_bo_reference(&user_bo->vbo.base); 617 + ret = ttm_prime_object_init(tfile, 618 + size, 619 + &user_bo->prime, 620 + shareable, 621 + ttm_buffer_type, 622 + &vmw_user_bo_release, 623 + &vmw_user_bo_ref_obj_release); 624 + if (unlikely(ret != 0)) { 625 + ttm_bo_unref(&tmp); 626 + goto out_no_base_object; 627 + } 628 + 629 + *p_vbo = &user_bo->vbo; 630 + if (p_base) { 631 + *p_base = &user_bo->prime.base; 632 + kref_get(&(*p_base)->refcount); 633 + } 634 + *handle = user_bo->prime.base.hash.key; 635 + 636 + out_no_base_object: 637 + return ret; 638 + } 639 + 640 + 641 + /** 642 + * vmw_user_bo_verify_access - verify access permissions on this 643 + * buffer object. 644 + * 645 + * @bo: Pointer to the buffer object being accessed 646 + * @tfile: Identifying the caller. 647 + */ 648 + int vmw_user_bo_verify_access(struct ttm_buffer_object *bo, 649 + struct ttm_object_file *tfile) 650 + { 651 + struct vmw_user_buffer_object *vmw_user_bo; 652 + 653 + if (unlikely(bo->destroy != vmw_user_bo_destroy)) 654 + return -EPERM; 655 + 656 + vmw_user_bo = vmw_user_buffer_object(bo); 657 + 658 + /* Check that the caller has opened the object. */ 659 + if (likely(ttm_ref_object_exists(tfile, &vmw_user_bo->prime.base))) 660 + return 0; 661 + 662 + DRM_ERROR("Could not grant buffer access.\n"); 663 + return -EPERM; 664 + } 665 + 666 + 667 + /** 668 + * vmw_user_bo_synccpu_grab - Grab a struct vmw_user_buffer_object for cpu 669 + * access, idling previous GPU operations on the buffer and optionally 670 + * blocking it for further command submissions. 671 + * 672 + * @user_bo: Pointer to the buffer object being grabbed for CPU access 673 + * @tfile: Identifying the caller. 674 + * @flags: Flags indicating how the grab should be performed. 675 + * Return: Zero on success, Negative error code on error. In particular, 676 + * -EBUSY will be returned if a dontblock operation is requested and the 677 + * buffer object is busy, and -ERESTARTSYS will be returned if a wait is 678 + * interrupted by a signal. 679 + * 680 + * A blocking grab will be automatically released when @tfile is closed. 681 + */ 682 + static int vmw_user_bo_synccpu_grab(struct vmw_user_buffer_object *user_bo, 683 + struct ttm_object_file *tfile, 684 + uint32_t flags) 685 + { 686 + struct ttm_buffer_object *bo = &user_bo->vbo.base; 687 + bool existed; 688 + int ret; 689 + 690 + if (flags & drm_vmw_synccpu_allow_cs) { 691 + bool nonblock = !!(flags & drm_vmw_synccpu_dontblock); 692 + long lret; 693 + 694 + lret = reservation_object_wait_timeout_rcu 695 + (bo->resv, true, true, 696 + nonblock ? 0 : MAX_SCHEDULE_TIMEOUT); 697 + if (!lret) 698 + return -EBUSY; 699 + else if (lret < 0) 700 + return lret; 701 + return 0; 702 + } 703 + 704 + ret = ttm_bo_synccpu_write_grab 705 + (bo, !!(flags & drm_vmw_synccpu_dontblock)); 706 + if (unlikely(ret != 0)) 707 + return ret; 708 + 709 + ret = ttm_ref_object_add(tfile, &user_bo->prime.base, 710 + TTM_REF_SYNCCPU_WRITE, &existed, false); 711 + if (ret != 0 || existed) 712 + ttm_bo_synccpu_write_release(&user_bo->vbo.base); 713 + 714 + return ret; 715 + } 716 + 717 + /** 718 + * vmw_user_bo_synccpu_release - Release a previous grab for CPU access, 719 + * and unblock command submission on the buffer if blocked. 720 + * 721 + * @handle: Handle identifying the buffer object. 722 + * @tfile: Identifying the caller. 723 + * @flags: Flags indicating the type of release. 724 + */ 725 + static int vmw_user_bo_synccpu_release(uint32_t handle, 726 + struct ttm_object_file *tfile, 727 + uint32_t flags) 728 + { 729 + if (!(flags & drm_vmw_synccpu_allow_cs)) 730 + return ttm_ref_object_base_unref(tfile, handle, 731 + TTM_REF_SYNCCPU_WRITE); 732 + 733 + return 0; 734 + } 735 + 736 + 737 + /** 738 + * vmw_user_bo_synccpu_ioctl - ioctl function implementing the synccpu 739 + * functionality. 740 + * 741 + * @dev: Identifies the drm device. 742 + * @data: Pointer to the ioctl argument. 743 + * @file_priv: Identifies the caller. 744 + * Return: Zero on success, negative error code on error. 745 + * 746 + * This function checks the ioctl arguments for validity and calls the 747 + * relevant synccpu functions. 748 + */ 749 + int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data, 750 + struct drm_file *file_priv) 751 + { 752 + struct drm_vmw_synccpu_arg *arg = 753 + (struct drm_vmw_synccpu_arg *) data; 754 + struct vmw_buffer_object *vbo; 755 + struct vmw_user_buffer_object *user_bo; 756 + struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; 757 + struct ttm_base_object *buffer_base; 758 + int ret; 759 + 760 + if ((arg->flags & (drm_vmw_synccpu_read | drm_vmw_synccpu_write)) == 0 761 + || (arg->flags & ~(drm_vmw_synccpu_read | drm_vmw_synccpu_write | 762 + drm_vmw_synccpu_dontblock | 763 + drm_vmw_synccpu_allow_cs)) != 0) { 764 + DRM_ERROR("Illegal synccpu flags.\n"); 765 + return -EINVAL; 766 + } 767 + 768 + switch (arg->op) { 769 + case drm_vmw_synccpu_grab: 770 + ret = vmw_user_bo_lookup(tfile, arg->handle, &vbo, 771 + &buffer_base); 772 + if (unlikely(ret != 0)) 773 + return ret; 774 + 775 + user_bo = container_of(vbo, struct vmw_user_buffer_object, 776 + vbo); 777 + ret = vmw_user_bo_synccpu_grab(user_bo, tfile, arg->flags); 778 + vmw_bo_unreference(&vbo); 779 + ttm_base_object_unref(&buffer_base); 780 + if (unlikely(ret != 0 && ret != -ERESTARTSYS && 781 + ret != -EBUSY)) { 782 + DRM_ERROR("Failed synccpu grab on handle 0x%08x.\n", 783 + (unsigned int) arg->handle); 784 + return ret; 785 + } 786 + break; 787 + case drm_vmw_synccpu_release: 788 + ret = vmw_user_bo_synccpu_release(arg->handle, tfile, 789 + arg->flags); 790 + if (unlikely(ret != 0)) { 791 + DRM_ERROR("Failed synccpu release on handle 0x%08x.\n", 792 + (unsigned int) arg->handle); 793 + return ret; 794 + } 795 + break; 796 + default: 797 + DRM_ERROR("Invalid synccpu operation.\n"); 798 + return -EINVAL; 799 + } 800 + 801 + return 0; 802 + } 803 + 804 + 805 + /** 806 + * vmw_bo_alloc_ioctl - ioctl function implementing the buffer object 807 + * allocation functionality. 808 + * 809 + * @dev: Identifies the drm device. 810 + * @data: Pointer to the ioctl argument. 811 + * @file_priv: Identifies the caller. 812 + * Return: Zero on success, negative error code on error. 813 + * 814 + * This function checks the ioctl arguments for validity and allocates a 815 + * struct vmw_user_buffer_object bo. 816 + */ 817 + int vmw_bo_alloc_ioctl(struct drm_device *dev, void *data, 818 + struct drm_file *file_priv) 819 + { 820 + struct vmw_private *dev_priv = vmw_priv(dev); 821 + union drm_vmw_alloc_dmabuf_arg *arg = 822 + (union drm_vmw_alloc_dmabuf_arg *)data; 823 + struct drm_vmw_alloc_dmabuf_req *req = &arg->req; 824 + struct drm_vmw_dmabuf_rep *rep = &arg->rep; 825 + struct vmw_buffer_object *vbo; 826 + uint32_t handle; 827 + int ret; 828 + 829 + ret = ttm_read_lock(&dev_priv->reservation_sem, true); 830 + if (unlikely(ret != 0)) 831 + return ret; 832 + 833 + ret = vmw_user_bo_alloc(dev_priv, vmw_fpriv(file_priv)->tfile, 834 + req->size, false, &handle, &vbo, 835 + NULL); 836 + if (unlikely(ret != 0)) 837 + goto out_no_bo; 838 + 839 + rep->handle = handle; 840 + rep->map_handle = drm_vma_node_offset_addr(&vbo->base.vma_node); 841 + rep->cur_gmr_id = handle; 842 + rep->cur_gmr_offset = 0; 843 + 844 + vmw_bo_unreference(&vbo); 845 + 846 + out_no_bo: 847 + ttm_read_unlock(&dev_priv->reservation_sem); 848 + 849 + return ret; 850 + } 851 + 852 + 853 + /** 854 + * vmw_bo_unref_ioctl - Generic handle close ioctl. 855 + * 856 + * @dev: Identifies the drm device. 857 + * @data: Pointer to the ioctl argument. 858 + * @file_priv: Identifies the caller. 859 + * Return: Zero on success, negative error code on error. 860 + * 861 + * This function checks the ioctl arguments for validity and closes a 862 + * handle to a TTM base object, optionally freeing the object. 863 + */ 864 + int vmw_bo_unref_ioctl(struct drm_device *dev, void *data, 865 + struct drm_file *file_priv) 866 + { 867 + struct drm_vmw_unref_dmabuf_arg *arg = 868 + (struct drm_vmw_unref_dmabuf_arg *)data; 869 + 870 + return ttm_ref_object_base_unref(vmw_fpriv(file_priv)->tfile, 871 + arg->handle, 872 + TTM_REF_USAGE); 873 + } 874 + 875 + 876 + /** 877 + * vmw_user_bo_lookup - Look up a vmw user buffer object from a handle. 878 + * 879 + * @tfile: The TTM object file the handle is registered with. 880 + * @handle: The user buffer object handle 881 + * @out: Pointer to a where a pointer to the embedded 882 + * struct vmw_buffer_object should be placed. 883 + * @p_base: Pointer to where a pointer to the TTM base object should be 884 + * placed, or NULL if no such pointer is required. 885 + * Return: Zero on success, Negative error code on error. 886 + * 887 + * Both the output base object pointer and the vmw buffer object pointer 888 + * will be refcounted. 889 + */ 890 + int vmw_user_bo_lookup(struct ttm_object_file *tfile, 891 + uint32_t handle, struct vmw_buffer_object **out, 892 + struct ttm_base_object **p_base) 893 + { 894 + struct vmw_user_buffer_object *vmw_user_bo; 895 + struct ttm_base_object *base; 896 + 897 + base = ttm_base_object_lookup(tfile, handle); 898 + if (unlikely(base == NULL)) { 899 + DRM_ERROR("Invalid buffer object handle 0x%08lx.\n", 900 + (unsigned long)handle); 901 + return -ESRCH; 902 + } 903 + 904 + if (unlikely(ttm_base_object_type(base) != ttm_buffer_type)) { 905 + ttm_base_object_unref(&base); 906 + DRM_ERROR("Invalid buffer object handle 0x%08lx.\n", 907 + (unsigned long)handle); 908 + return -EINVAL; 909 + } 910 + 911 + vmw_user_bo = container_of(base, struct vmw_user_buffer_object, 912 + prime.base); 913 + (void)ttm_bo_reference(&vmw_user_bo->vbo.base); 914 + if (p_base) 915 + *p_base = base; 916 + else 917 + ttm_base_object_unref(&base); 918 + *out = &vmw_user_bo->vbo; 919 + 920 + return 0; 921 + } 922 + 923 + 924 + /** 925 + * vmw_user_bo_reference - Open a handle to a vmw user buffer object. 926 + * 927 + * @tfile: The TTM object file to register the handle with. 928 + * @vbo: The embedded vmw buffer object. 929 + * @handle: Pointer to where the new handle should be placed. 930 + * Return: Zero on success, Negative error code on error. 931 + */ 932 + int vmw_user_bo_reference(struct ttm_object_file *tfile, 933 + struct vmw_buffer_object *vbo, 934 + uint32_t *handle) 935 + { 936 + struct vmw_user_buffer_object *user_bo; 937 + 938 + if (vbo->base.destroy != vmw_user_bo_destroy) 939 + return -EINVAL; 940 + 941 + user_bo = container_of(vbo, struct vmw_user_buffer_object, vbo); 942 + 943 + *handle = user_bo->prime.base.hash.key; 944 + return ttm_ref_object_add(tfile, &user_bo->prime.base, 945 + TTM_REF_USAGE, NULL, false); 946 + } 947 + 948 + 949 + /** 950 + * vmw_bo_fence_single - Utility function to fence a single TTM buffer 951 + * object without unreserving it. 952 + * 953 + * @bo: Pointer to the struct ttm_buffer_object to fence. 954 + * @fence: Pointer to the fence. If NULL, this function will 955 + * insert a fence into the command stream.. 956 + * 957 + * Contrary to the ttm_eu version of this function, it takes only 958 + * a single buffer object instead of a list, and it also doesn't 959 + * unreserve the buffer object, which needs to be done separately. 960 + */ 961 + void vmw_bo_fence_single(struct ttm_buffer_object *bo, 962 + struct vmw_fence_obj *fence) 963 + { 964 + struct ttm_bo_device *bdev = bo->bdev; 965 + 966 + struct vmw_private *dev_priv = 967 + container_of(bdev, struct vmw_private, bdev); 968 + 969 + if (fence == NULL) { 970 + vmw_execbuf_fence_commands(NULL, dev_priv, &fence, NULL); 971 + reservation_object_add_excl_fence(bo->resv, &fence->base); 972 + dma_fence_put(&fence->base); 973 + } else 974 + reservation_object_add_excl_fence(bo->resv, &fence->base); 975 + } 976 + 977 + 978 + /** 979 + * vmw_dumb_create - Create a dumb kms buffer 980 + * 981 + * @file_priv: Pointer to a struct drm_file identifying the caller. 982 + * @dev: Pointer to the drm device. 983 + * @args: Pointer to a struct drm_mode_create_dumb structure 984 + * Return: Zero on success, negative error code on failure. 985 + * 986 + * This is a driver callback for the core drm create_dumb functionality. 987 + * Note that this is very similar to the vmw_bo_alloc ioctl, except 988 + * that the arguments have a different format. 989 + */ 990 + int vmw_dumb_create(struct drm_file *file_priv, 991 + struct drm_device *dev, 992 + struct drm_mode_create_dumb *args) 993 + { 994 + struct vmw_private *dev_priv = vmw_priv(dev); 995 + struct vmw_buffer_object *vbo; 996 + int ret; 997 + 998 + args->pitch = args->width * ((args->bpp + 7) / 8); 999 + args->size = args->pitch * args->height; 1000 + 1001 + ret = ttm_read_lock(&dev_priv->reservation_sem, true); 1002 + if (unlikely(ret != 0)) 1003 + return ret; 1004 + 1005 + ret = vmw_user_bo_alloc(dev_priv, vmw_fpriv(file_priv)->tfile, 1006 + args->size, false, &args->handle, 1007 + &vbo, NULL); 1008 + if (unlikely(ret != 0)) 1009 + goto out_no_bo; 1010 + 1011 + vmw_bo_unreference(&vbo); 1012 + out_no_bo: 1013 + ttm_read_unlock(&dev_priv->reservation_sem); 1014 + return ret; 1015 + } 1016 + 1017 + 1018 + /** 1019 + * vmw_dumb_map_offset - Return the address space offset of a dumb buffer 1020 + * 1021 + * @file_priv: Pointer to a struct drm_file identifying the caller. 1022 + * @dev: Pointer to the drm device. 1023 + * @handle: Handle identifying the dumb buffer. 1024 + * @offset: The address space offset returned. 1025 + * Return: Zero on success, negative error code on failure. 1026 + * 1027 + * This is a driver callback for the core drm dumb_map_offset functionality. 1028 + */ 1029 + int vmw_dumb_map_offset(struct drm_file *file_priv, 1030 + struct drm_device *dev, uint32_t handle, 1031 + uint64_t *offset) 1032 + { 1033 + struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; 1034 + struct vmw_buffer_object *out_buf; 1035 + int ret; 1036 + 1037 + ret = vmw_user_bo_lookup(tfile, handle, &out_buf, NULL); 1038 + if (ret != 0) 1039 + return -EINVAL; 1040 + 1041 + *offset = drm_vma_node_offset_addr(&out_buf->base.vma_node); 1042 + vmw_bo_unreference(&out_buf); 1043 + return 0; 1044 + } 1045 + 1046 + 1047 + /** 1048 + * vmw_dumb_destroy - Destroy a dumb boffer 1049 + * 1050 + * @file_priv: Pointer to a struct drm_file identifying the caller. 1051 + * @dev: Pointer to the drm device. 1052 + * @handle: Handle identifying the dumb buffer. 1053 + * Return: Zero on success, negative error code on failure. 1054 + * 1055 + * This is a driver callback for the core drm dumb_destroy functionality. 1056 + */ 1057 + int vmw_dumb_destroy(struct drm_file *file_priv, 1058 + struct drm_device *dev, 1059 + uint32_t handle) 1060 + { 1061 + return ttm_ref_object_base_unref(vmw_fpriv(file_priv)->tfile, 1062 + handle, TTM_REF_USAGE); 1063 + } 1064 + 1065 + 1066 + /** 1067 + * vmw_bo_swap_notify - swapout notify callback. 1068 + * 1069 + * @bo: The buffer object to be swapped out. 1070 + */ 1071 + void vmw_bo_swap_notify(struct ttm_buffer_object *bo) 1072 + { 1073 + /* Is @bo embedded in a struct vmw_buffer_object? */ 1074 + if (bo->destroy != vmw_bo_bo_free && 1075 + bo->destroy != vmw_user_bo_destroy) 1076 + return; 1077 + 1078 + /* Kill any cached kernel maps before swapout */ 1079 + vmw_bo_unmap(vmw_buffer_object(bo)); 1080 + } 1081 + 1082 + 1083 + /** 1084 + * vmw_bo_move_notify - TTM move_notify_callback 1085 + * 1086 + * @bo: The TTM buffer object about to move. 1087 + * @mem: The struct ttm_mem_reg indicating to what memory 1088 + * region the move is taking place. 1089 + * 1090 + * Detaches cached maps and device bindings that require that the 1091 + * buffer doesn't move. 1092 + */ 1093 + void vmw_bo_move_notify(struct ttm_buffer_object *bo, 1094 + struct ttm_mem_reg *mem) 1095 + { 1096 + struct vmw_buffer_object *vbo; 1097 + 1098 + if (mem == NULL) 1099 + return; 1100 + 1101 + /* Make sure @bo is embedded in a struct vmw_buffer_object? */ 1102 + if (bo->destroy != vmw_bo_bo_free && 1103 + bo->destroy != vmw_user_bo_destroy) 1104 + return; 1105 + 1106 + vbo = container_of(bo, struct vmw_buffer_object, base); 1107 + 1108 + /* 1109 + * Kill any cached kernel maps before move to or from VRAM. 1110 + * With other types of moves, the underlying pages stay the same, 1111 + * and the map can be kept. 1112 + */ 1113 + if (mem->mem_type == TTM_PL_VRAM || bo->mem.mem_type == TTM_PL_VRAM) 1114 + vmw_bo_unmap(vbo); 1115 + 1116 + /* 1117 + * If we're moving a backup MOB out of MOB placement, then make sure we 1118 + * read back all resource content first, and unbind the MOB from 1119 + * the resource. 1120 + */ 1121 + if (mem->mem_type != VMW_PL_MOB && bo->mem.mem_type == VMW_PL_MOB) 1122 + vmw_resource_unbind_list(vbo); 1123 + }
+3 -3
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
··· 798 798 struct ttm_object_file *tfile = 799 799 vmw_fpriv((struct drm_file *)filp->private_data)->tfile; 800 800 801 - return vmw_user_dmabuf_verify_access(bo, tfile); 801 + return vmw_user_bo_verify_access(bo, tfile); 802 802 } 803 803 804 804 static int vmw_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem) ··· 852 852 bool evict, 853 853 struct ttm_mem_reg *mem) 854 854 { 855 - vmw_resource_move_notify(bo, mem); 855 + vmw_bo_move_notify(bo, mem); 856 856 vmw_query_move_notify(bo, mem); 857 857 } 858 858 ··· 864 864 */ 865 865 static void vmw_swap_notify(struct ttm_buffer_object *bo) 866 866 { 867 - vmw_resource_swap_notify(bo); 867 + vmw_bo_swap_notify(bo); 868 868 (void) ttm_bo_wait(bo, false, false); 869 869 } 870 870
+7 -7
drivers/gpu/drm/vmwgfx/vmwgfx_context.c
··· 38 38 struct vmw_cmdbuf_res_manager *man; 39 39 struct vmw_resource *cotables[SVGA_COTABLE_DX10_MAX]; 40 40 spinlock_t cotable_lock; 41 - struct vmw_dma_buffer *dx_query_mob; 41 + struct vmw_buffer_object *dx_query_mob; 42 42 }; 43 43 44 44 static void vmw_user_context_free(struct vmw_resource *res); ··· 424 424 (void) vmw_execbuf_fence_commands(NULL, dev_priv, 425 425 &fence, NULL); 426 426 427 - vmw_fence_single_bo(bo, fence); 427 + vmw_bo_fence_single(bo, fence); 428 428 429 429 if (likely(fence != NULL)) 430 430 vmw_fence_obj_unreference(&fence); ··· 648 648 (void) vmw_execbuf_fence_commands(NULL, dev_priv, 649 649 &fence, NULL); 650 650 651 - vmw_fence_single_bo(bo, fence); 651 + vmw_bo_fence_single(bo, fence); 652 652 653 653 if (likely(fence != NULL)) 654 654 vmw_fence_obj_unreference(&fence); ··· 900 900 * specified in the parameter. 0 otherwise. 901 901 */ 902 902 int vmw_context_bind_dx_query(struct vmw_resource *ctx_res, 903 - struct vmw_dma_buffer *mob) 903 + struct vmw_buffer_object *mob) 904 904 { 905 905 struct vmw_user_context *uctx = 906 906 container_of(ctx_res, struct vmw_user_context, res); ··· 908 908 if (mob == NULL) { 909 909 if (uctx->dx_query_mob) { 910 910 uctx->dx_query_mob->dx_query_ctx = NULL; 911 - vmw_dmabuf_unreference(&uctx->dx_query_mob); 911 + vmw_bo_unreference(&uctx->dx_query_mob); 912 912 uctx->dx_query_mob = NULL; 913 913 } 914 914 ··· 922 922 mob->dx_query_ctx = ctx_res; 923 923 924 924 if (!uctx->dx_query_mob) 925 - uctx->dx_query_mob = vmw_dmabuf_reference(mob); 925 + uctx->dx_query_mob = vmw_bo_reference(mob); 926 926 927 927 return 0; 928 928 } ··· 932 932 * 933 933 * @ctx_res: The context resource 934 934 */ 935 - struct vmw_dma_buffer * 935 + struct vmw_buffer_object * 936 936 vmw_context_get_dx_query_mob(struct vmw_resource *ctx_res) 937 937 { 938 938 struct vmw_user_context *uctx =
+7 -7
drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c
··· 324 324 vmw_dx_context_scrub_cotables(vcotbl->ctx, readback); 325 325 mutex_unlock(&dev_priv->binding_mutex); 326 326 (void) vmw_execbuf_fence_commands(NULL, dev_priv, &fence, NULL); 327 - vmw_fence_single_bo(bo, fence); 327 + vmw_bo_fence_single(bo, fence); 328 328 if (likely(fence != NULL)) 329 329 vmw_fence_obj_unreference(&fence); 330 330 ··· 367 367 } 368 368 369 369 (void) vmw_execbuf_fence_commands(NULL, dev_priv, &fence, NULL); 370 - vmw_fence_single_bo(&res->backup->base, fence); 370 + vmw_bo_fence_single(&res->backup->base, fence); 371 371 vmw_fence_obj_unreference(&fence); 372 372 373 373 return 0; ··· 390 390 struct ttm_operation_ctx ctx = { false, false }; 391 391 struct vmw_private *dev_priv = res->dev_priv; 392 392 struct vmw_cotable *vcotbl = vmw_cotable(res); 393 - struct vmw_dma_buffer *buf, *old_buf = res->backup; 393 + struct vmw_buffer_object *buf, *old_buf = res->backup; 394 394 struct ttm_buffer_object *bo, *old_bo = &res->backup->base; 395 395 size_t old_size = res->backup_size; 396 396 size_t old_size_read_back = vcotbl->size_read_back; ··· 415 415 if (!buf) 416 416 return -ENOMEM; 417 417 418 - ret = vmw_dmabuf_init(dev_priv, buf, new_size, &vmw_mob_ne_placement, 419 - true, vmw_dmabuf_bo_free); 418 + ret = vmw_bo_init(dev_priv, buf, new_size, &vmw_mob_ne_placement, 419 + true, vmw_bo_bo_free); 420 420 if (ret) { 421 421 DRM_ERROR("Failed initializing new cotable MOB.\n"); 422 422 return ret; ··· 482 482 /* Let go of the old mob. */ 483 483 list_del(&res->mob_head); 484 484 list_add_tail(&res->mob_head, &buf->res_list); 485 - vmw_dmabuf_unreference(&old_buf); 485 + vmw_bo_unreference(&old_buf); 486 486 res->id = vcotbl->type; 487 487 488 488 return 0; ··· 491 491 ttm_bo_kunmap(&old_map); 492 492 out_wait: 493 493 ttm_bo_unreserve(bo); 494 - vmw_dmabuf_unreference(&buf); 494 + vmw_bo_unreference(&buf); 495 495 496 496 return ret; 497 497 }
-376
drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 OR MIT 2 - /************************************************************************** 3 - * 4 - * Copyright 2011-2015 VMware, Inc., Palo Alto, CA., USA 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 <drm/ttm/ttm_placement.h> 29 - 30 - #include <drm/drmP.h> 31 - #include "vmwgfx_drv.h" 32 - 33 - 34 - /** 35 - * vmw_dmabuf_pin_in_placement - Validate a buffer to placement. 36 - * 37 - * @dev_priv: Driver private. 38 - * @buf: DMA buffer to move. 39 - * @placement: The placement to pin it. 40 - * @interruptible: Use interruptible wait. 41 - * 42 - * Returns 43 - * -ERESTARTSYS if interrupted by a signal. 44 - */ 45 - int vmw_dmabuf_pin_in_placement(struct vmw_private *dev_priv, 46 - struct vmw_dma_buffer *buf, 47 - struct ttm_placement *placement, 48 - bool interruptible) 49 - { 50 - struct ttm_operation_ctx ctx = {interruptible, false }; 51 - struct ttm_buffer_object *bo = &buf->base; 52 - int ret; 53 - uint32_t new_flags; 54 - 55 - ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible); 56 - if (unlikely(ret != 0)) 57 - return ret; 58 - 59 - vmw_execbuf_release_pinned_bo(dev_priv); 60 - 61 - ret = ttm_bo_reserve(bo, interruptible, false, NULL); 62 - if (unlikely(ret != 0)) 63 - goto err; 64 - 65 - if (buf->pin_count > 0) 66 - ret = ttm_bo_mem_compat(placement, &bo->mem, 67 - &new_flags) == true ? 0 : -EINVAL; 68 - else 69 - ret = ttm_bo_validate(bo, placement, &ctx); 70 - 71 - if (!ret) 72 - vmw_bo_pin_reserved(buf, true); 73 - 74 - ttm_bo_unreserve(bo); 75 - 76 - err: 77 - ttm_write_unlock(&dev_priv->reservation_sem); 78 - return ret; 79 - } 80 - 81 - /** 82 - * vmw_dmabuf_pin_in_vram_or_gmr - Move a buffer to vram or gmr. 83 - * 84 - * This function takes the reservation_sem in write mode. 85 - * Flushes and unpins the query bo to avoid failures. 86 - * 87 - * @dev_priv: Driver private. 88 - * @buf: DMA buffer to move. 89 - * @pin: Pin buffer if true. 90 - * @interruptible: Use interruptible wait. 91 - * 92 - * Returns 93 - * -ERESTARTSYS if interrupted by a signal. 94 - */ 95 - int vmw_dmabuf_pin_in_vram_or_gmr(struct vmw_private *dev_priv, 96 - struct vmw_dma_buffer *buf, 97 - bool interruptible) 98 - { 99 - struct ttm_operation_ctx ctx = {interruptible, false }; 100 - struct ttm_buffer_object *bo = &buf->base; 101 - int ret; 102 - uint32_t new_flags; 103 - 104 - ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible); 105 - if (unlikely(ret != 0)) 106 - return ret; 107 - 108 - vmw_execbuf_release_pinned_bo(dev_priv); 109 - 110 - ret = ttm_bo_reserve(bo, interruptible, false, NULL); 111 - if (unlikely(ret != 0)) 112 - goto err; 113 - 114 - if (buf->pin_count > 0) { 115 - ret = ttm_bo_mem_compat(&vmw_vram_gmr_placement, &bo->mem, 116 - &new_flags) == true ? 0 : -EINVAL; 117 - goto out_unreserve; 118 - } 119 - 120 - ret = ttm_bo_validate(bo, &vmw_vram_gmr_placement, &ctx); 121 - if (likely(ret == 0) || ret == -ERESTARTSYS) 122 - goto out_unreserve; 123 - 124 - ret = ttm_bo_validate(bo, &vmw_vram_placement, &ctx); 125 - 126 - out_unreserve: 127 - if (!ret) 128 - vmw_bo_pin_reserved(buf, true); 129 - 130 - ttm_bo_unreserve(bo); 131 - err: 132 - ttm_write_unlock(&dev_priv->reservation_sem); 133 - return ret; 134 - } 135 - 136 - /** 137 - * vmw_dmabuf_pin_in_vram - Move a buffer to vram. 138 - * 139 - * This function takes the reservation_sem in write mode. 140 - * Flushes and unpins the query bo to avoid failures. 141 - * 142 - * @dev_priv: Driver private. 143 - * @buf: DMA buffer to move. 144 - * @interruptible: Use interruptible wait. 145 - * 146 - * Returns 147 - * -ERESTARTSYS if interrupted by a signal. 148 - */ 149 - int vmw_dmabuf_pin_in_vram(struct vmw_private *dev_priv, 150 - struct vmw_dma_buffer *buf, 151 - bool interruptible) 152 - { 153 - return vmw_dmabuf_pin_in_placement(dev_priv, buf, &vmw_vram_placement, 154 - interruptible); 155 - } 156 - 157 - /** 158 - * vmw_dmabuf_pin_in_start_of_vram - Move a buffer to start of vram. 159 - * 160 - * This function takes the reservation_sem in write mode. 161 - * Flushes and unpins the query bo to avoid failures. 162 - * 163 - * @dev_priv: Driver private. 164 - * @buf: DMA buffer to pin. 165 - * @interruptible: Use interruptible wait. 166 - * 167 - * Returns 168 - * -ERESTARTSYS if interrupted by a signal. 169 - */ 170 - int vmw_dmabuf_pin_in_start_of_vram(struct vmw_private *dev_priv, 171 - struct vmw_dma_buffer *buf, 172 - bool interruptible) 173 - { 174 - struct ttm_operation_ctx ctx = {interruptible, false }; 175 - struct ttm_buffer_object *bo = &buf->base; 176 - struct ttm_placement placement; 177 - struct ttm_place place; 178 - int ret = 0; 179 - uint32_t new_flags; 180 - 181 - place = vmw_vram_placement.placement[0]; 182 - place.lpfn = bo->num_pages; 183 - placement.num_placement = 1; 184 - placement.placement = &place; 185 - placement.num_busy_placement = 1; 186 - placement.busy_placement = &place; 187 - 188 - ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible); 189 - if (unlikely(ret != 0)) 190 - return ret; 191 - 192 - vmw_execbuf_release_pinned_bo(dev_priv); 193 - ret = ttm_bo_reserve(bo, interruptible, false, NULL); 194 - if (unlikely(ret != 0)) 195 - goto err_unlock; 196 - 197 - /* 198 - * Is this buffer already in vram but not at the start of it? 199 - * In that case, evict it first because TTM isn't good at handling 200 - * that situation. 201 - */ 202 - if (bo->mem.mem_type == TTM_PL_VRAM && 203 - bo->mem.start < bo->num_pages && 204 - bo->mem.start > 0 && 205 - buf->pin_count == 0) { 206 - ctx.interruptible = false; 207 - (void) ttm_bo_validate(bo, &vmw_sys_placement, &ctx); 208 - } 209 - 210 - if (buf->pin_count > 0) 211 - ret = ttm_bo_mem_compat(&placement, &bo->mem, 212 - &new_flags) == true ? 0 : -EINVAL; 213 - else 214 - ret = ttm_bo_validate(bo, &placement, &ctx); 215 - 216 - /* For some reason we didn't end up at the start of vram */ 217 - WARN_ON(ret == 0 && bo->offset != 0); 218 - if (!ret) 219 - vmw_bo_pin_reserved(buf, true); 220 - 221 - ttm_bo_unreserve(bo); 222 - err_unlock: 223 - ttm_write_unlock(&dev_priv->reservation_sem); 224 - 225 - return ret; 226 - } 227 - 228 - /** 229 - * vmw_dmabuf_unpin - Unpin the buffer given buffer, does not move the buffer. 230 - * 231 - * This function takes the reservation_sem in write mode. 232 - * 233 - * @dev_priv: Driver private. 234 - * @buf: DMA buffer to unpin. 235 - * @interruptible: Use interruptible wait. 236 - * 237 - * Returns 238 - * -ERESTARTSYS if interrupted by a signal. 239 - */ 240 - int vmw_dmabuf_unpin(struct vmw_private *dev_priv, 241 - struct vmw_dma_buffer *buf, 242 - bool interruptible) 243 - { 244 - struct ttm_buffer_object *bo = &buf->base; 245 - int ret; 246 - 247 - ret = ttm_read_lock(&dev_priv->reservation_sem, interruptible); 248 - if (unlikely(ret != 0)) 249 - return ret; 250 - 251 - ret = ttm_bo_reserve(bo, interruptible, false, NULL); 252 - if (unlikely(ret != 0)) 253 - goto err; 254 - 255 - vmw_bo_pin_reserved(buf, false); 256 - 257 - ttm_bo_unreserve(bo); 258 - 259 - err: 260 - ttm_read_unlock(&dev_priv->reservation_sem); 261 - return ret; 262 - } 263 - 264 - /** 265 - * vmw_bo_get_guest_ptr - Get the guest ptr representing the current placement 266 - * of a buffer. 267 - * 268 - * @bo: Pointer to a struct ttm_buffer_object. Must be pinned or reserved. 269 - * @ptr: SVGAGuestPtr returning the result. 270 - */ 271 - void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *bo, 272 - SVGAGuestPtr *ptr) 273 - { 274 - if (bo->mem.mem_type == TTM_PL_VRAM) { 275 - ptr->gmrId = SVGA_GMR_FRAMEBUFFER; 276 - ptr->offset = bo->offset; 277 - } else { 278 - ptr->gmrId = bo->mem.start; 279 - ptr->offset = 0; 280 - } 281 - } 282 - 283 - 284 - /** 285 - * vmw_bo_pin_reserved - Pin or unpin a buffer object without moving it. 286 - * 287 - * @vbo: The buffer object. Must be reserved. 288 - * @pin: Whether to pin or unpin. 289 - * 290 - */ 291 - void vmw_bo_pin_reserved(struct vmw_dma_buffer *vbo, bool pin) 292 - { 293 - struct ttm_operation_ctx ctx = { false, true }; 294 - struct ttm_place pl; 295 - struct ttm_placement placement; 296 - struct ttm_buffer_object *bo = &vbo->base; 297 - uint32_t old_mem_type = bo->mem.mem_type; 298 - int ret; 299 - 300 - lockdep_assert_held(&bo->resv->lock.base); 301 - 302 - if (pin) { 303 - if (vbo->pin_count++ > 0) 304 - return; 305 - } else { 306 - WARN_ON(vbo->pin_count <= 0); 307 - if (--vbo->pin_count > 0) 308 - return; 309 - } 310 - 311 - pl.fpfn = 0; 312 - pl.lpfn = 0; 313 - pl.flags = TTM_PL_FLAG_VRAM | VMW_PL_FLAG_GMR | VMW_PL_FLAG_MOB 314 - | TTM_PL_FLAG_SYSTEM | TTM_PL_FLAG_CACHED; 315 - if (pin) 316 - pl.flags |= TTM_PL_FLAG_NO_EVICT; 317 - 318 - memset(&placement, 0, sizeof(placement)); 319 - placement.num_placement = 1; 320 - placement.placement = &pl; 321 - 322 - ret = ttm_bo_validate(bo, &placement, &ctx); 323 - 324 - BUG_ON(ret != 0 || bo->mem.mem_type != old_mem_type); 325 - } 326 - 327 - 328 - /* 329 - * vmw_dma_buffer_unmap - Tear down a cached buffer object map. 330 - * 331 - * @vbo: The buffer object whose map we are tearing down. 332 - * 333 - * This function tears down a cached map set up using 334 - * vmw_dma_buffer_map_and_cache(). 335 - */ 336 - void vmw_dma_buffer_unmap(struct vmw_dma_buffer *vbo) 337 - { 338 - if (vbo->map.bo == NULL) 339 - return; 340 - 341 - ttm_bo_kunmap(&vbo->map); 342 - } 343 - 344 - 345 - /* 346 - * vmw_dma_buffer_map_and_cache - Map a buffer object and cache the map 347 - * 348 - * @vbo: The buffer object to map 349 - * Return: A kernel virtual address or NULL if mapping failed. 350 - * 351 - * This function maps a buffer object into the kernel address space, or 352 - * returns the virtual kernel address of an already existing map. The virtual 353 - * address remains valid as long as the buffer object is pinned or reserved. 354 - * The cached map is torn down on either 355 - * 1) Buffer object move 356 - * 2) Buffer object swapout 357 - * 3) Buffer object destruction 358 - * 359 - */ 360 - void *vmw_dma_buffer_map_and_cache(struct vmw_dma_buffer *vbo) 361 - { 362 - struct ttm_buffer_object *bo = &vbo->base; 363 - bool not_used; 364 - void *virtual; 365 - int ret; 366 - 367 - virtual = ttm_kmap_obj_virtual(&vbo->map, &not_used); 368 - if (virtual) 369 - return virtual; 370 - 371 - ret = ttm_bo_kmap(bo, 0, bo->num_pages, &vbo->map); 372 - if (ret) 373 - DRM_ERROR("Buffer object map failed: %d.\n", ret); 374 - 375 - return ttm_kmap_obj_virtual(&vbo->map, &not_used); 376 - }
+10 -9
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
··· 153 153 static const struct drm_ioctl_desc vmw_ioctls[] = { 154 154 VMW_IOCTL_DEF(VMW_GET_PARAM, vmw_getparam_ioctl, 155 155 DRM_AUTH | DRM_RENDER_ALLOW), 156 - VMW_IOCTL_DEF(VMW_ALLOC_DMABUF, vmw_dmabuf_alloc_ioctl, 156 + VMW_IOCTL_DEF(VMW_ALLOC_DMABUF, vmw_bo_alloc_ioctl, 157 157 DRM_AUTH | DRM_RENDER_ALLOW), 158 - VMW_IOCTL_DEF(VMW_UNREF_DMABUF, vmw_dmabuf_unref_ioctl, 158 + VMW_IOCTL_DEF(VMW_UNREF_DMABUF, vmw_bo_unref_ioctl, 159 159 DRM_RENDER_ALLOW), 160 160 VMW_IOCTL_DEF(VMW_CURSOR_BYPASS, 161 161 vmw_kms_cursor_bypass_ioctl, ··· 219 219 vmw_gb_surface_reference_ioctl, 220 220 DRM_AUTH | DRM_RENDER_ALLOW), 221 221 VMW_IOCTL_DEF(VMW_SYNCCPU, 222 - vmw_user_dmabuf_synccpu_ioctl, 222 + vmw_user_bo_synccpu_ioctl, 223 223 DRM_RENDER_ALLOW), 224 224 VMW_IOCTL_DEF(VMW_CREATE_EXTENDED_CONTEXT, 225 225 vmw_extended_context_define_ioctl, ··· 321 321 static int vmw_dummy_query_bo_create(struct vmw_private *dev_priv) 322 322 { 323 323 int ret; 324 - struct vmw_dma_buffer *vbo; 324 + struct vmw_buffer_object *vbo; 325 325 struct ttm_bo_kmap_obj map; 326 326 volatile SVGA3dQueryResult *result; 327 327 bool dummy; ··· 335 335 if (!vbo) 336 336 return -ENOMEM; 337 337 338 - ret = vmw_dmabuf_init(dev_priv, vbo, PAGE_SIZE, 339 - &vmw_sys_ne_placement, false, 340 - &vmw_dmabuf_bo_free); 338 + ret = vmw_bo_init(dev_priv, vbo, PAGE_SIZE, 339 + &vmw_sys_ne_placement, false, 340 + &vmw_bo_bo_free); 341 341 if (unlikely(ret != 0)) 342 342 return ret; 343 343 ··· 358 358 359 359 if (unlikely(ret != 0)) { 360 360 DRM_ERROR("Dummy query buffer map failed.\n"); 361 - vmw_dmabuf_unreference(&vbo); 361 + vmw_bo_unreference(&vbo); 362 362 } else 363 363 dev_priv->dummy_query_bo = vbo; 364 364 ··· 460 460 461 461 BUG_ON(dev_priv->pinned_bo != NULL); 462 462 463 - vmw_dmabuf_unreference(&dev_priv->dummy_query_bo); 463 + vmw_bo_unreference(&dev_priv->dummy_query_bo); 464 464 if (dev_priv->cman) 465 465 vmw_cmdbuf_remove_pool(dev_priv->cman); 466 466 ··· 644 644 mutex_init(&dev_priv->cmdbuf_mutex); 645 645 mutex_init(&dev_priv->release_mutex); 646 646 mutex_init(&dev_priv->binding_mutex); 647 + mutex_init(&dev_priv->requested_layout_mutex); 647 648 mutex_init(&dev_priv->global_kms_state_mutex); 648 649 rwlock_init(&dev_priv->resource_lock); 649 650 ttm_lock_init(&dev_priv->reservation_sem);
+82 -76
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
··· 86 86 bool gb_aware; 87 87 }; 88 88 89 - struct vmw_dma_buffer { 89 + struct vmw_buffer_object { 90 90 struct ttm_buffer_object base; 91 91 struct list_head res_list; 92 92 s32 pin_count; ··· 120 120 unsigned long backup_size; 121 121 bool res_dirty; /* Protected by backup buffer reserved */ 122 122 bool backup_dirty; /* Protected by backup buffer reserved */ 123 - struct vmw_dma_buffer *backup; 123 + struct vmw_buffer_object *backup; 124 124 unsigned long backup_offset; 125 125 unsigned long pin_count; /* Protected by resource reserved */ 126 126 const struct vmw_res_func *func; ··· 304 304 uint32_t cmd_bounce_size; 305 305 struct list_head resource_list; 306 306 struct list_head ctx_resource_list; /* For contexts and cotables */ 307 - struct vmw_dma_buffer *cur_query_bo; 307 + struct vmw_buffer_object *cur_query_bo; 308 308 struct list_head res_relocations; 309 309 uint32_t *buf_start; 310 310 struct vmw_res_cache_entry res_cache[vmw_res_max]; ··· 315 315 bool staged_bindings_inuse; 316 316 struct list_head staged_cmd_res; 317 317 struct vmw_resource_val_node *dx_ctx_node; 318 - struct vmw_dma_buffer *dx_query_mob; 318 + struct vmw_buffer_object *dx_query_mob; 319 319 struct vmw_resource *dx_query_ctx; 320 320 struct vmw_cmdbuf_res_manager *man; 321 321 }; ··· 410 410 uint32_t vga_pitchlock; 411 411 412 412 uint32_t num_displays; 413 + 414 + /* 415 + * Currently requested_layout_mutex is used to protect the gui 416 + * positionig state in display unit. With that use case currently this 417 + * mutex is only taken during layout ioctl and atomic check_modeset. 418 + * Other display unit state can be protected with this mutex but that 419 + * needs careful consideration. 420 + */ 421 + struct mutex requested_layout_mutex; 413 422 414 423 /* 415 424 * Framebuffer info. ··· 522 513 * are protected by the cmdbuf mutex. 523 514 */ 524 515 525 - struct vmw_dma_buffer *dummy_query_bo; 526 - struct vmw_dma_buffer *pinned_bo; 516 + struct vmw_buffer_object *dummy_query_bo; 517 + struct vmw_buffer_object *pinned_bo; 527 518 uint32_t query_cid; 528 519 uint32_t query_cid_valid; 529 520 bool dummy_query_bo_pinned; ··· 632 623 struct ttm_object_file *tfile, 633 624 uint32_t handle, 634 625 struct vmw_surface **out_surf, 635 - struct vmw_dma_buffer **out_buf); 626 + struct vmw_buffer_object **out_buf); 636 627 extern int vmw_user_resource_lookup_handle( 637 628 struct vmw_private *dev_priv, 638 629 struct ttm_object_file *tfile, 639 630 uint32_t handle, 640 631 const struct vmw_user_resource_conv *converter, 641 632 struct vmw_resource **p_res); 642 - extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo); 643 - extern int vmw_dmabuf_init(struct vmw_private *dev_priv, 644 - struct vmw_dma_buffer *vmw_bo, 645 - size_t size, struct ttm_placement *placement, 646 - bool interuptable, 647 - void (*bo_free) (struct ttm_buffer_object *bo)); 648 - extern int vmw_user_dmabuf_verify_access(struct ttm_buffer_object *bo, 649 - struct ttm_object_file *tfile); 650 - extern int vmw_user_dmabuf_alloc(struct vmw_private *dev_priv, 651 - struct ttm_object_file *tfile, 652 - uint32_t size, 653 - bool shareable, 654 - uint32_t *handle, 655 - struct vmw_dma_buffer **p_dma_buf, 656 - struct ttm_base_object **p_base); 657 - extern int vmw_user_dmabuf_reference(struct ttm_object_file *tfile, 658 - struct vmw_dma_buffer *dma_buf, 659 - uint32_t *handle); 660 - extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data, 661 - struct drm_file *file_priv); 662 - extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data, 663 - struct drm_file *file_priv); 664 - extern int vmw_user_dmabuf_synccpu_ioctl(struct drm_device *dev, void *data, 665 - struct drm_file *file_priv); 666 - extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo, 667 - uint32_t cur_validate_node); 668 - extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo); 669 - extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile, 670 - uint32_t id, struct vmw_dma_buffer **out, 671 - struct ttm_base_object **base); 672 633 extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data, 673 634 struct drm_file *file_priv); 674 635 extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data, ··· 649 670 struct vmw_resource **out); 650 671 extern void vmw_resource_unreserve(struct vmw_resource *res, 651 672 bool switch_backup, 652 - struct vmw_dma_buffer *new_backup, 673 + struct vmw_buffer_object *new_backup, 653 674 unsigned long new_backup_offset); 654 - extern void vmw_resource_move_notify(struct ttm_buffer_object *bo, 655 - struct ttm_mem_reg *mem); 656 675 extern void vmw_query_move_notify(struct ttm_buffer_object *bo, 657 676 struct ttm_mem_reg *mem); 658 - extern void vmw_resource_swap_notify(struct ttm_buffer_object *bo); 659 - extern int vmw_query_readback_all(struct vmw_dma_buffer *dx_query_mob); 660 - extern void vmw_fence_single_bo(struct ttm_buffer_object *bo, 661 - struct vmw_fence_obj *fence); 677 + extern int vmw_query_readback_all(struct vmw_buffer_object *dx_query_mob); 662 678 extern void vmw_resource_evict_all(struct vmw_private *dev_priv); 663 - 679 + extern void vmw_resource_unbind_list(struct vmw_buffer_object *vbo); 664 680 665 681 /** 666 - * DMA buffer helper routines - vmwgfx_dmabuf.c 682 + * Buffer object helper functions - vmwgfx_bo.c 667 683 */ 668 - extern int vmw_dmabuf_pin_in_placement(struct vmw_private *vmw_priv, 669 - struct vmw_dma_buffer *bo, 670 - struct ttm_placement *placement, 684 + extern int vmw_bo_pin_in_placement(struct vmw_private *vmw_priv, 685 + struct vmw_buffer_object *bo, 686 + struct ttm_placement *placement, 687 + bool interruptible); 688 + extern int vmw_bo_pin_in_vram(struct vmw_private *dev_priv, 689 + struct vmw_buffer_object *buf, 690 + bool interruptible); 691 + extern int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv, 692 + struct vmw_buffer_object *buf, 693 + bool interruptible); 694 + extern int vmw_bo_pin_in_start_of_vram(struct vmw_private *vmw_priv, 695 + struct vmw_buffer_object *bo, 671 696 bool interruptible); 672 - extern int vmw_dmabuf_pin_in_vram(struct vmw_private *dev_priv, 673 - struct vmw_dma_buffer *buf, 674 - bool interruptible); 675 - extern int vmw_dmabuf_pin_in_vram_or_gmr(struct vmw_private *dev_priv, 676 - struct vmw_dma_buffer *buf, 677 - bool interruptible); 678 - extern int vmw_dmabuf_pin_in_start_of_vram(struct vmw_private *vmw_priv, 679 - struct vmw_dma_buffer *bo, 680 - bool interruptible); 681 - extern int vmw_dmabuf_unpin(struct vmw_private *vmw_priv, 682 - struct vmw_dma_buffer *bo, 683 - bool interruptible); 697 + extern int vmw_bo_unpin(struct vmw_private *vmw_priv, 698 + struct vmw_buffer_object *bo, 699 + bool interruptible); 684 700 extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf, 685 701 SVGAGuestPtr *ptr); 686 - extern void vmw_bo_pin_reserved(struct vmw_dma_buffer *bo, bool pin); 687 - extern void *vmw_dma_buffer_map_and_cache(struct vmw_dma_buffer *vbo); 688 - extern void vmw_dma_buffer_unmap(struct vmw_dma_buffer *vbo); 702 + extern void vmw_bo_pin_reserved(struct vmw_buffer_object *bo, bool pin); 703 + extern void vmw_bo_bo_free(struct ttm_buffer_object *bo); 704 + extern int vmw_bo_init(struct vmw_private *dev_priv, 705 + struct vmw_buffer_object *vmw_bo, 706 + size_t size, struct ttm_placement *placement, 707 + bool interuptable, 708 + void (*bo_free)(struct ttm_buffer_object *bo)); 709 + extern int vmw_user_bo_verify_access(struct ttm_buffer_object *bo, 710 + struct ttm_object_file *tfile); 711 + extern int vmw_user_bo_alloc(struct vmw_private *dev_priv, 712 + struct ttm_object_file *tfile, 713 + uint32_t size, 714 + bool shareable, 715 + uint32_t *handle, 716 + struct vmw_buffer_object **p_dma_buf, 717 + struct ttm_base_object **p_base); 718 + extern int vmw_user_bo_reference(struct ttm_object_file *tfile, 719 + struct vmw_buffer_object *dma_buf, 720 + uint32_t *handle); 721 + extern int vmw_bo_alloc_ioctl(struct drm_device *dev, void *data, 722 + struct drm_file *file_priv); 723 + extern int vmw_bo_unref_ioctl(struct drm_device *dev, void *data, 724 + struct drm_file *file_priv); 725 + extern int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data, 726 + struct drm_file *file_priv); 727 + extern int vmw_user_bo_lookup(struct ttm_object_file *tfile, 728 + uint32_t id, struct vmw_buffer_object **out, 729 + struct ttm_base_object **base); 730 + extern void vmw_bo_fence_single(struct ttm_buffer_object *bo, 731 + struct vmw_fence_obj *fence); 732 + extern void *vmw_bo_map_and_cache(struct vmw_buffer_object *vbo); 733 + extern void vmw_bo_unmap(struct vmw_buffer_object *vbo); 734 + extern void vmw_bo_move_notify(struct ttm_buffer_object *bo, 735 + struct ttm_mem_reg *mem); 736 + extern void vmw_bo_swap_notify(struct ttm_buffer_object *bo); 689 737 690 738 /** 691 739 * Misc Ioctl functionality - vmwgfx_ioctl.c ··· 764 758 extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma); 765 759 766 760 /** 767 - * TTM buffer object driver - vmwgfx_buffer.c 761 + * TTM buffer object driver - vmwgfx_ttm_buffer.c 768 762 */ 769 763 770 764 extern const size_t vmw_tt_size; ··· 1047 1041 extern void vmw_dx_context_scrub_cotables(struct vmw_resource *ctx, 1048 1042 bool readback); 1049 1043 extern int vmw_context_bind_dx_query(struct vmw_resource *ctx_res, 1050 - struct vmw_dma_buffer *mob); 1051 - extern struct vmw_dma_buffer * 1044 + struct vmw_buffer_object *mob); 1045 + extern struct vmw_buffer_object * 1052 1046 vmw_context_get_dx_query_mob(struct vmw_resource *ctx_res); 1053 1047 1054 1048 ··· 1230 1224 u32 w, u32 h, 1231 1225 struct vmw_diff_cpy *diff); 1232 1226 1227 + /* Host messaging -vmwgfx_msg.c: */ 1228 + int vmw_host_get_guestinfo(const char *guest_info_param, 1229 + char *buffer, size_t *length); 1230 + int vmw_host_log(const char *log); 1231 + 1233 1232 /** 1234 1233 * Inline helper functions 1235 1234 */ ··· 1254 1243 return srf; 1255 1244 } 1256 1245 1257 - static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf) 1246 + static inline void vmw_bo_unreference(struct vmw_buffer_object **buf) 1258 1247 { 1259 - struct vmw_dma_buffer *tmp_buf = *buf; 1248 + struct vmw_buffer_object *tmp_buf = *buf; 1260 1249 1261 1250 *buf = NULL; 1262 1251 if (tmp_buf != NULL) { ··· 1266 1255 } 1267 1256 } 1268 1257 1269 - static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf) 1258 + static inline struct vmw_buffer_object * 1259 + vmw_bo_reference(struct vmw_buffer_object *buf) 1270 1260 { 1271 1261 if (ttm_bo_reference(&buf->base)) 1272 1262 return buf; ··· 1314 1302 { 1315 1303 WRITE_ONCE(*addr, value); 1316 1304 } 1317 - 1318 - /** 1319 - * Add vmw_msg module function 1320 - */ 1321 - extern int vmw_host_log(const char *log); 1322 - 1323 1305 #endif
+42 -44
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
··· 92 92 struct list_head head; 93 93 struct drm_hash_item hash; 94 94 struct vmw_resource *res; 95 - struct vmw_dma_buffer *new_backup; 95 + struct vmw_buffer_object *new_backup; 96 96 struct vmw_ctx_binding_state *staged_bindings; 97 97 unsigned long new_backup_offset; 98 98 u32 first_usage : 1; ··· 126 126 static int vmw_translate_mob_ptr(struct vmw_private *dev_priv, 127 127 struct vmw_sw_context *sw_context, 128 128 SVGAMobId *id, 129 - struct vmw_dma_buffer **vmw_bo_p); 129 + struct vmw_buffer_object **vmw_bo_p); 130 130 static int vmw_bo_to_validate_list(struct vmw_sw_context *sw_context, 131 - struct vmw_dma_buffer *vbo, 131 + struct vmw_buffer_object *vbo, 132 132 bool validate_as_mob, 133 133 uint32_t *p_val_node); 134 134 /** ··· 185 185 } 186 186 vmw_resource_unreserve(res, switch_backup, val->new_backup, 187 187 val->new_backup_offset); 188 - vmw_dmabuf_unreference(&val->new_backup); 188 + vmw_bo_unreference(&val->new_backup); 189 189 } 190 190 } 191 191 ··· 423 423 } 424 424 425 425 if (dev_priv->has_dx && vmw_res_type(ctx) == vmw_res_dx_context) { 426 - struct vmw_dma_buffer *dx_query_mob; 426 + struct vmw_buffer_object *dx_query_mob; 427 427 428 428 dx_query_mob = vmw_context_get_dx_query_mob(ctx); 429 429 if (dx_query_mob) ··· 544 544 * submission is reached. 545 545 */ 546 546 static int vmw_bo_to_validate_list(struct vmw_sw_context *sw_context, 547 - struct vmw_dma_buffer *vbo, 547 + struct vmw_buffer_object *vbo, 548 548 bool validate_as_mob, 549 549 uint32_t *p_val_node) 550 550 { ··· 616 616 return ret; 617 617 618 618 if (res->backup) { 619 - struct vmw_dma_buffer *vbo = res->backup; 619 + struct vmw_buffer_object *vbo = res->backup; 620 620 621 621 ret = vmw_bo_to_validate_list 622 622 (sw_context, vbo, ··· 628 628 } 629 629 630 630 if (sw_context->dx_query_mob) { 631 - struct vmw_dma_buffer *expected_dx_query_mob; 631 + struct vmw_buffer_object *expected_dx_query_mob; 632 632 633 633 expected_dx_query_mob = 634 634 vmw_context_get_dx_query_mob(sw_context->dx_query_ctx); ··· 657 657 658 658 list_for_each_entry(val, &sw_context->resource_list, head) { 659 659 struct vmw_resource *res = val->res; 660 - struct vmw_dma_buffer *backup = res->backup; 660 + struct vmw_buffer_object *backup = res->backup; 661 661 662 662 ret = vmw_resource_validate(res); 663 663 if (unlikely(ret != 0)) { ··· 668 668 669 669 /* Check if the resource switched backup buffer */ 670 670 if (backup && res->backup && (backup != res->backup)) { 671 - struct vmw_dma_buffer *vbo = res->backup; 671 + struct vmw_buffer_object *vbo = res->backup; 672 672 673 673 ret = vmw_bo_to_validate_list 674 674 (sw_context, vbo, ··· 821 821 static int vmw_rebind_all_dx_query(struct vmw_resource *ctx_res) 822 822 { 823 823 struct vmw_private *dev_priv = ctx_res->dev_priv; 824 - struct vmw_dma_buffer *dx_query_mob; 824 + struct vmw_buffer_object *dx_query_mob; 825 825 struct { 826 826 SVGA3dCmdHeader header; 827 827 SVGA3dCmdDXBindAllQuery body; ··· 1152 1152 * command batch. 1153 1153 */ 1154 1154 static int vmw_query_bo_switch_prepare(struct vmw_private *dev_priv, 1155 - struct vmw_dma_buffer *new_query_bo, 1155 + struct vmw_buffer_object *new_query_bo, 1156 1156 struct vmw_sw_context *sw_context) 1157 1157 { 1158 1158 struct vmw_res_cache_entry *ctx_entry = ··· 1234 1234 if (dev_priv->pinned_bo != sw_context->cur_query_bo) { 1235 1235 if (dev_priv->pinned_bo) { 1236 1236 vmw_bo_pin_reserved(dev_priv->pinned_bo, false); 1237 - vmw_dmabuf_unreference(&dev_priv->pinned_bo); 1237 + vmw_bo_unreference(&dev_priv->pinned_bo); 1238 1238 } 1239 1239 1240 1240 if (!sw_context->needs_post_query_barrier) { ··· 1256 1256 dev_priv->query_cid = sw_context->last_query_ctx->id; 1257 1257 dev_priv->query_cid_valid = true; 1258 1258 dev_priv->pinned_bo = 1259 - vmw_dmabuf_reference(sw_context->cur_query_bo); 1259 + vmw_bo_reference(sw_context->cur_query_bo); 1260 1260 } 1261 1261 } 1262 1262 } ··· 1282 1282 static int vmw_translate_mob_ptr(struct vmw_private *dev_priv, 1283 1283 struct vmw_sw_context *sw_context, 1284 1284 SVGAMobId *id, 1285 - struct vmw_dma_buffer **vmw_bo_p) 1285 + struct vmw_buffer_object **vmw_bo_p) 1286 1286 { 1287 - struct vmw_dma_buffer *vmw_bo = NULL; 1287 + struct vmw_buffer_object *vmw_bo = NULL; 1288 1288 uint32_t handle = *id; 1289 1289 struct vmw_relocation *reloc; 1290 1290 int ret; 1291 1291 1292 - ret = vmw_user_dmabuf_lookup(sw_context->fp->tfile, handle, &vmw_bo, 1293 - NULL); 1292 + ret = vmw_user_bo_lookup(sw_context->fp->tfile, handle, &vmw_bo, NULL); 1294 1293 if (unlikely(ret != 0)) { 1295 1294 DRM_ERROR("Could not find or use MOB buffer.\n"); 1296 1295 ret = -EINVAL; ··· 1315 1316 return 0; 1316 1317 1317 1318 out_no_reloc: 1318 - vmw_dmabuf_unreference(&vmw_bo); 1319 + vmw_bo_unreference(&vmw_bo); 1319 1320 *vmw_bo_p = NULL; 1320 1321 return ret; 1321 1322 } ··· 1342 1343 static int vmw_translate_guest_ptr(struct vmw_private *dev_priv, 1343 1344 struct vmw_sw_context *sw_context, 1344 1345 SVGAGuestPtr *ptr, 1345 - struct vmw_dma_buffer **vmw_bo_p) 1346 + struct vmw_buffer_object **vmw_bo_p) 1346 1347 { 1347 - struct vmw_dma_buffer *vmw_bo = NULL; 1348 + struct vmw_buffer_object *vmw_bo = NULL; 1348 1349 uint32_t handle = ptr->gmrId; 1349 1350 struct vmw_relocation *reloc; 1350 1351 int ret; 1351 1352 1352 - ret = vmw_user_dmabuf_lookup(sw_context->fp->tfile, handle, &vmw_bo, 1353 - NULL); 1353 + ret = vmw_user_bo_lookup(sw_context->fp->tfile, handle, &vmw_bo, NULL); 1354 1354 if (unlikely(ret != 0)) { 1355 1355 DRM_ERROR("Could not find or use GMR region.\n"); 1356 1356 ret = -EINVAL; ··· 1374 1376 return 0; 1375 1377 1376 1378 out_no_reloc: 1377 - vmw_dmabuf_unreference(&vmw_bo); 1379 + vmw_bo_unreference(&vmw_bo); 1378 1380 *vmw_bo_p = NULL; 1379 1381 return ret; 1380 1382 } ··· 1445 1447 SVGA3dCmdDXBindQuery q; 1446 1448 } *cmd; 1447 1449 1448 - struct vmw_dma_buffer *vmw_bo; 1450 + struct vmw_buffer_object *vmw_bo; 1449 1451 int ret; 1450 1452 1451 1453 ··· 1464 1466 sw_context->dx_query_mob = vmw_bo; 1465 1467 sw_context->dx_query_ctx = sw_context->dx_ctx_node->res; 1466 1468 1467 - vmw_dmabuf_unreference(&vmw_bo); 1469 + vmw_bo_unreference(&vmw_bo); 1468 1470 1469 1471 return ret; 1470 1472 } ··· 1547 1549 struct vmw_sw_context *sw_context, 1548 1550 SVGA3dCmdHeader *header) 1549 1551 { 1550 - struct vmw_dma_buffer *vmw_bo; 1552 + struct vmw_buffer_object *vmw_bo; 1551 1553 struct vmw_query_cmd { 1552 1554 SVGA3dCmdHeader header; 1553 1555 SVGA3dCmdEndGBQuery q; ··· 1567 1569 1568 1570 ret = vmw_query_bo_switch_prepare(dev_priv, vmw_bo, sw_context); 1569 1571 1570 - vmw_dmabuf_unreference(&vmw_bo); 1572 + vmw_bo_unreference(&vmw_bo); 1571 1573 return ret; 1572 1574 } 1573 1575 ··· 1582 1584 struct vmw_sw_context *sw_context, 1583 1585 SVGA3dCmdHeader *header) 1584 1586 { 1585 - struct vmw_dma_buffer *vmw_bo; 1587 + struct vmw_buffer_object *vmw_bo; 1586 1588 struct vmw_query_cmd { 1587 1589 SVGA3dCmdHeader header; 1588 1590 SVGA3dCmdEndQuery q; ··· 1621 1623 1622 1624 ret = vmw_query_bo_switch_prepare(dev_priv, vmw_bo, sw_context); 1623 1625 1624 - vmw_dmabuf_unreference(&vmw_bo); 1626 + vmw_bo_unreference(&vmw_bo); 1625 1627 return ret; 1626 1628 } 1627 1629 ··· 1636 1638 struct vmw_sw_context *sw_context, 1637 1639 SVGA3dCmdHeader *header) 1638 1640 { 1639 - struct vmw_dma_buffer *vmw_bo; 1641 + struct vmw_buffer_object *vmw_bo; 1640 1642 struct vmw_query_cmd { 1641 1643 SVGA3dCmdHeader header; 1642 1644 SVGA3dCmdWaitForGBQuery q; ··· 1654 1656 if (unlikely(ret != 0)) 1655 1657 return ret; 1656 1658 1657 - vmw_dmabuf_unreference(&vmw_bo); 1659 + vmw_bo_unreference(&vmw_bo); 1658 1660 return 0; 1659 1661 } 1660 1662 ··· 1669 1671 struct vmw_sw_context *sw_context, 1670 1672 SVGA3dCmdHeader *header) 1671 1673 { 1672 - struct vmw_dma_buffer *vmw_bo; 1674 + struct vmw_buffer_object *vmw_bo; 1673 1675 struct vmw_query_cmd { 1674 1676 SVGA3dCmdHeader header; 1675 1677 SVGA3dCmdWaitForQuery q; ··· 1706 1708 if (unlikely(ret != 0)) 1707 1709 return ret; 1708 1710 1709 - vmw_dmabuf_unreference(&vmw_bo); 1711 + vmw_bo_unreference(&vmw_bo); 1710 1712 return 0; 1711 1713 } 1712 1714 ··· 1714 1716 struct vmw_sw_context *sw_context, 1715 1717 SVGA3dCmdHeader *header) 1716 1718 { 1717 - struct vmw_dma_buffer *vmw_bo = NULL; 1719 + struct vmw_buffer_object *vmw_bo = NULL; 1718 1720 struct vmw_surface *srf = NULL; 1719 1721 struct vmw_dma_cmd { 1720 1722 SVGA3dCmdHeader header; ··· 1766 1768 header); 1767 1769 1768 1770 out_no_surface: 1769 - vmw_dmabuf_unreference(&vmw_bo); 1771 + vmw_bo_unreference(&vmw_bo); 1770 1772 return ret; 1771 1773 } 1772 1774 ··· 1885 1887 struct vmw_sw_context *sw_context, 1886 1888 void *buf) 1887 1889 { 1888 - struct vmw_dma_buffer *vmw_bo; 1890 + struct vmw_buffer_object *vmw_bo; 1889 1891 int ret; 1890 1892 1891 1893 struct { ··· 1899 1901 if (unlikely(ret != 0)) 1900 1902 return ret; 1901 1903 1902 - vmw_dmabuf_unreference(&vmw_bo); 1904 + vmw_bo_unreference(&vmw_bo); 1903 1905 1904 1906 return ret; 1905 1907 } ··· 1926 1928 uint32_t *buf_id, 1927 1929 unsigned long backup_offset) 1928 1930 { 1929 - struct vmw_dma_buffer *dma_buf; 1931 + struct vmw_buffer_object *dma_buf; 1930 1932 int ret; 1931 1933 1932 1934 ret = vmw_translate_mob_ptr(dev_priv, sw_context, buf_id, &dma_buf); ··· 1937 1939 if (val_node->first_usage) 1938 1940 val_node->no_buffer_needed = true; 1939 1941 1940 - vmw_dmabuf_unreference(&val_node->new_backup); 1942 + vmw_bo_unreference(&val_node->new_backup); 1941 1943 val_node->new_backup = dma_buf; 1942 1944 val_node->new_backup_offset = backup_offset; 1943 1945 ··· 3699 3701 bool interruptible, 3700 3702 bool validate_as_mob) 3701 3703 { 3702 - struct vmw_dma_buffer *vbo = container_of(bo, struct vmw_dma_buffer, 3703 - base); 3704 + struct vmw_buffer_object *vbo = 3705 + container_of(bo, struct vmw_buffer_object, base); 3704 3706 struct ttm_operation_ctx ctx = { interruptible, true }; 3705 3707 int ret; 3706 3708 ··· 4421 4423 4422 4424 ttm_bo_unref(&query_val.bo); 4423 4425 ttm_bo_unref(&pinned_val.bo); 4424 - vmw_dmabuf_unreference(&dev_priv->pinned_bo); 4426 + vmw_bo_unreference(&dev_priv->pinned_bo); 4425 4427 out_unlock: 4426 4428 return; 4427 4429 ··· 4430 4432 out_no_reserve: 4431 4433 ttm_bo_unref(&query_val.bo); 4432 4434 ttm_bo_unref(&pinned_val.bo); 4433 - vmw_dmabuf_unreference(&dev_priv->pinned_bo); 4435 + vmw_bo_unreference(&dev_priv->pinned_bo); 4434 4436 } 4435 4437 4436 4438 /**
+8 -8
drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
··· 42 42 void *vmalloc; 43 43 44 44 struct mutex bo_mutex; 45 - struct vmw_dma_buffer *vmw_bo; 45 + struct vmw_buffer_object *vmw_bo; 46 46 unsigned bo_size; 47 47 struct drm_framebuffer *set_fb; 48 48 struct drm_display_mode *set_mode; ··· 184 184 struct drm_clip_rect clip; 185 185 struct drm_framebuffer *cur_fb; 186 186 u8 *src_ptr, *dst_ptr; 187 - struct vmw_dma_buffer *vbo = par->vmw_bo; 187 + struct vmw_buffer_object *vbo = par->vmw_bo; 188 188 void *virtual; 189 189 190 190 if (!READ_ONCE(par->dirty.active)) ··· 197 197 198 198 (void) ttm_read_lock(&vmw_priv->reservation_sem, false); 199 199 (void) ttm_bo_reserve(&vbo->base, false, false, NULL); 200 - virtual = vmw_dma_buffer_map_and_cache(vbo); 200 + virtual = vmw_bo_map_and_cache(vbo); 201 201 if (!virtual) 202 202 goto out_unreserve; 203 203 ··· 391 391 */ 392 392 393 393 static int vmw_fb_create_bo(struct vmw_private *vmw_priv, 394 - size_t size, struct vmw_dma_buffer **out) 394 + size_t size, struct vmw_buffer_object **out) 395 395 { 396 - struct vmw_dma_buffer *vmw_bo; 396 + struct vmw_buffer_object *vmw_bo; 397 397 int ret; 398 398 399 399 (void) ttm_write_lock(&vmw_priv->reservation_sem, false); ··· 404 404 goto err_unlock; 405 405 } 406 406 407 - ret = vmw_dmabuf_init(vmw_priv, vmw_bo, size, 407 + ret = vmw_bo_init(vmw_priv, vmw_bo, size, 408 408 &vmw_sys_placement, 409 409 false, 410 - &vmw_dmabuf_bo_free); 410 + &vmw_bo_bo_free); 411 411 if (unlikely(ret != 0)) 412 412 goto err_unlock; /* init frees the buffer on failure */ 413 413 ··· 491 491 } 492 492 493 493 if (par->vmw_bo && detach_bo && unref_bo) 494 - vmw_dmabuf_unreference(&par->vmw_bo); 494 + vmw_bo_unreference(&par->vmw_bo); 495 495 496 496 return 0; 497 497 }
+26 -12
drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
··· 175 175 struct vmw_private *dev_priv = fman->dev_priv; 176 176 struct vmwgfx_wait_cb cb; 177 177 long ret = timeout; 178 - unsigned long irq_flags; 179 178 180 179 if (likely(vmw_fence_obj_signaled(fence))) 181 180 return timeout; ··· 182 183 vmw_fifo_ping_host(dev_priv, SVGA_SYNC_GENERIC); 183 184 vmw_seqno_waiter_add(dev_priv); 184 185 185 - spin_lock_irqsave(f->lock, irq_flags); 186 + spin_lock(f->lock); 186 187 187 188 if (intr && signal_pending(current)) { 188 189 ret = -ERESTARTSYS; ··· 193 194 cb.task = current; 194 195 list_add(&cb.base.node, &f->cb_list); 195 196 196 - while (ret > 0) { 197 + for (;;) { 197 198 __vmw_fences_update(fman); 198 - if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &f->flags)) 199 - break; 200 199 200 + /* 201 + * We can use the barrier free __set_current_state() since 202 + * DMA_FENCE_FLAG_SIGNALED_BIT + wakeup is protected by the 203 + * fence spinlock. 204 + */ 201 205 if (intr) 202 206 __set_current_state(TASK_INTERRUPTIBLE); 203 207 else 204 208 __set_current_state(TASK_UNINTERRUPTIBLE); 205 - spin_unlock_irqrestore(f->lock, irq_flags); 209 + 210 + if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &f->flags)) { 211 + if (ret == 0 && timeout > 0) 212 + ret = 1; 213 + break; 214 + } 215 + 216 + if (intr && signal_pending(current)) { 217 + ret = -ERESTARTSYS; 218 + break; 219 + } 220 + 221 + if (ret == 0) 222 + break; 223 + 224 + spin_unlock(f->lock); 206 225 207 226 ret = schedule_timeout(ret); 208 227 209 - spin_lock_irqsave(f->lock, irq_flags); 210 - if (ret > 0 && intr && signal_pending(current)) 211 - ret = -ERESTARTSYS; 228 + spin_lock(f->lock); 212 229 } 213 - 230 + __set_current_state(TASK_RUNNING); 214 231 if (!list_empty(&cb.base.node)) 215 232 list_del(&cb.base.node); 216 - __set_current_state(TASK_RUNNING); 217 233 218 234 out: 219 - spin_unlock_irqrestore(f->lock, irq_flags); 235 + spin_unlock(f->lock); 220 236 221 237 vmw_seqno_waiter_remove(dev_priv); 222 238
+2 -2
drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
··· 377 377 } 378 378 379 379 vfb = vmw_framebuffer_to_vfb(fb); 380 - if (!vfb->dmabuf) { 381 - DRM_ERROR("Framebuffer not dmabuf backed.\n"); 380 + if (!vfb->bo) { 381 + DRM_ERROR("Framebuffer not buffer backed.\n"); 382 382 ret = -EINVAL; 383 383 goto out_no_ttm_lock; 384 384 }
+359 -215
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
··· 85 85 return 0; 86 86 } 87 87 88 - static int vmw_cursor_update_dmabuf(struct vmw_private *dev_priv, 89 - struct vmw_dma_buffer *dmabuf, 90 - u32 width, u32 height, 91 - u32 hotspotX, u32 hotspotY) 88 + static int vmw_cursor_update_bo(struct vmw_private *dev_priv, 89 + struct vmw_buffer_object *bo, 90 + u32 width, u32 height, 91 + u32 hotspotX, u32 hotspotY) 92 92 { 93 93 struct ttm_bo_kmap_obj map; 94 94 unsigned long kmap_offset; ··· 100 100 kmap_offset = 0; 101 101 kmap_num = (width*height*4 + PAGE_SIZE - 1) >> PAGE_SHIFT; 102 102 103 - ret = ttm_bo_reserve(&dmabuf->base, true, false, NULL); 103 + ret = ttm_bo_reserve(&bo->base, true, false, NULL); 104 104 if (unlikely(ret != 0)) { 105 105 DRM_ERROR("reserve failed\n"); 106 106 return -EINVAL; 107 107 } 108 108 109 - ret = ttm_bo_kmap(&dmabuf->base, kmap_offset, kmap_num, &map); 109 + ret = ttm_bo_kmap(&bo->base, kmap_offset, kmap_num, &map); 110 110 if (unlikely(ret != 0)) 111 111 goto err_unreserve; 112 112 ··· 116 116 117 117 ttm_bo_kunmap(&map); 118 118 err_unreserve: 119 - ttm_bo_unreserve(&dmabuf->base); 119 + ttm_bo_unreserve(&bo->base); 120 120 121 121 return ret; 122 122 } ··· 352 352 if (vps->surf) 353 353 vmw_surface_unreference(&vps->surf); 354 354 355 - if (vps->dmabuf) 356 - vmw_dmabuf_unreference(&vps->dmabuf); 355 + if (vps->bo) 356 + vmw_bo_unreference(&vps->bo); 357 357 358 358 if (fb) { 359 - if (vmw_framebuffer_to_vfb(fb)->dmabuf) { 360 - vps->dmabuf = vmw_framebuffer_to_vfbd(fb)->buffer; 361 - vmw_dmabuf_reference(vps->dmabuf); 359 + if (vmw_framebuffer_to_vfb(fb)->bo) { 360 + vps->bo = vmw_framebuffer_to_vfbd(fb)->buffer; 361 + vmw_bo_reference(vps->bo); 362 362 } else { 363 363 vps->surf = vmw_framebuffer_to_vfbs(fb)->surface; 364 364 vmw_surface_reference(vps->surf); ··· 390 390 } 391 391 392 392 du->cursor_surface = vps->surf; 393 - du->cursor_dmabuf = vps->dmabuf; 393 + du->cursor_bo = vps->bo; 394 394 395 395 if (vps->surf) { 396 396 du->cursor_age = du->cursor_surface->snooper.age; ··· 399 399 vps->surf->snooper.image, 400 400 64, 64, hotspot_x, 401 401 hotspot_y); 402 - } else if (vps->dmabuf) { 403 - ret = vmw_cursor_update_dmabuf(dev_priv, vps->dmabuf, 404 - plane->state->crtc_w, 405 - plane->state->crtc_h, 406 - hotspot_x, hotspot_y); 402 + } else if (vps->bo) { 403 + ret = vmw_cursor_update_bo(dev_priv, vps->bo, 404 + plane->state->crtc_w, 405 + plane->state->crtc_h, 406 + hotspot_x, hotspot_y); 407 407 } else { 408 408 vmw_cursor_update_position(dev_priv, false, 0, 0); 409 409 return; ··· 519 519 ret = -EINVAL; 520 520 } 521 521 522 - if (!vmw_framebuffer_to_vfb(fb)->dmabuf) 522 + if (!vmw_framebuffer_to_vfb(fb)->bo) 523 523 surface = vmw_framebuffer_to_vfbs(fb)->surface; 524 524 525 525 if (surface && !surface->snooper.image) { ··· 687 687 if (vps->surf) 688 688 (void) vmw_surface_reference(vps->surf); 689 689 690 - if (vps->dmabuf) 691 - (void) vmw_dmabuf_reference(vps->dmabuf); 690 + if (vps->bo) 691 + (void) vmw_bo_reference(vps->bo); 692 692 693 693 state = &vps->base; 694 694 ··· 745 745 if (vps->surf) 746 746 vmw_surface_unreference(&vps->surf); 747 747 748 - if (vps->dmabuf) 749 - vmw_dmabuf_unreference(&vps->dmabuf); 748 + if (vps->bo) 749 + vmw_bo_unreference(&vps->bo); 750 750 751 751 drm_atomic_helper_plane_destroy_state(plane, state); 752 752 } ··· 902 902 903 903 /** 904 904 * vmw_kms_readback - Perform a readback from the screen system to 905 - * a dma-buffer backed framebuffer. 905 + * a buffer-object backed framebuffer. 906 906 * 907 907 * @dev_priv: Pointer to the device private structure. 908 908 * @file_priv: Pointer to a struct drm_file identifying the caller. 909 909 * Must be set to NULL if @user_fence_rep is NULL. 910 - * @vfb: Pointer to the dma-buffer backed framebuffer. 910 + * @vfb: Pointer to the buffer-object backed framebuffer. 911 911 * @user_fence_rep: User-space provided structure for fence information. 912 912 * Must be set to non-NULL if @file_priv is non-NULL. 913 913 * @vclips: Array of clip rects. ··· 951 951 struct vmw_framebuffer **out, 952 952 const struct drm_mode_fb_cmd2 953 953 *mode_cmd, 954 - bool is_dmabuf_proxy) 954 + bool is_bo_proxy) 955 955 956 956 { 957 957 struct drm_device *dev = dev_priv->dev; ··· 1019 1019 drm_helper_mode_fill_fb_struct(dev, &vfbs->base.base, mode_cmd); 1020 1020 vfbs->surface = vmw_surface_reference(surface); 1021 1021 vfbs->base.user_handle = mode_cmd->handles[0]; 1022 - vfbs->is_dmabuf_proxy = is_dmabuf_proxy; 1022 + vfbs->is_bo_proxy = is_bo_proxy; 1023 1023 1024 1024 *out = &vfbs->base; 1025 1025 ··· 1038 1038 } 1039 1039 1040 1040 /* 1041 - * Dmabuf framebuffer code 1041 + * Buffer-object framebuffer code 1042 1042 */ 1043 1043 1044 - static void vmw_framebuffer_dmabuf_destroy(struct drm_framebuffer *framebuffer) 1044 + static void vmw_framebuffer_bo_destroy(struct drm_framebuffer *framebuffer) 1045 1045 { 1046 - struct vmw_framebuffer_dmabuf *vfbd = 1046 + struct vmw_framebuffer_bo *vfbd = 1047 1047 vmw_framebuffer_to_vfbd(framebuffer); 1048 1048 1049 1049 drm_framebuffer_cleanup(framebuffer); 1050 - vmw_dmabuf_unreference(&vfbd->buffer); 1050 + vmw_bo_unreference(&vfbd->buffer); 1051 1051 if (vfbd->base.user_obj) 1052 1052 ttm_base_object_unref(&vfbd->base.user_obj); 1053 1053 1054 1054 kfree(vfbd); 1055 1055 } 1056 1056 1057 - static int vmw_framebuffer_dmabuf_dirty(struct drm_framebuffer *framebuffer, 1058 - struct drm_file *file_priv, 1059 - unsigned flags, unsigned color, 1060 - struct drm_clip_rect *clips, 1061 - unsigned num_clips) 1057 + static int vmw_framebuffer_bo_dirty(struct drm_framebuffer *framebuffer, 1058 + struct drm_file *file_priv, 1059 + unsigned int flags, unsigned int color, 1060 + struct drm_clip_rect *clips, 1061 + unsigned int num_clips) 1062 1062 { 1063 1063 struct vmw_private *dev_priv = vmw_priv(framebuffer->dev); 1064 - struct vmw_framebuffer_dmabuf *vfbd = 1064 + struct vmw_framebuffer_bo *vfbd = 1065 1065 vmw_framebuffer_to_vfbd(framebuffer); 1066 1066 struct drm_clip_rect norect; 1067 1067 int ret, increment = 1; ··· 1092 1092 true, true, NULL); 1093 1093 break; 1094 1094 case vmw_du_screen_object: 1095 - ret = vmw_kms_sou_do_dmabuf_dirty(dev_priv, &vfbd->base, 1096 - clips, NULL, num_clips, 1097 - increment, true, NULL, NULL); 1095 + ret = vmw_kms_sou_do_bo_dirty(dev_priv, &vfbd->base, 1096 + clips, NULL, num_clips, 1097 + increment, true, NULL, NULL); 1098 1098 break; 1099 1099 case vmw_du_legacy: 1100 - ret = vmw_kms_ldu_do_dmabuf_dirty(dev_priv, &vfbd->base, 0, 0, 1101 - clips, num_clips, increment); 1100 + ret = vmw_kms_ldu_do_bo_dirty(dev_priv, &vfbd->base, 0, 0, 1101 + clips, num_clips, increment); 1102 1102 break; 1103 1103 default: 1104 1104 ret = -EINVAL; ··· 1114 1114 return ret; 1115 1115 } 1116 1116 1117 - static const struct drm_framebuffer_funcs vmw_framebuffer_dmabuf_funcs = { 1118 - .destroy = vmw_framebuffer_dmabuf_destroy, 1119 - .dirty = vmw_framebuffer_dmabuf_dirty, 1117 + static const struct drm_framebuffer_funcs vmw_framebuffer_bo_funcs = { 1118 + .destroy = vmw_framebuffer_bo_destroy, 1119 + .dirty = vmw_framebuffer_bo_dirty, 1120 1120 }; 1121 1121 1122 1122 /** 1123 - * Pin the dmabuffer in a location suitable for access by the 1123 + * Pin the bofer in a location suitable for access by the 1124 1124 * display system. 1125 1125 */ 1126 1126 static int vmw_framebuffer_pin(struct vmw_framebuffer *vfb) 1127 1127 { 1128 1128 struct vmw_private *dev_priv = vmw_priv(vfb->base.dev); 1129 - struct vmw_dma_buffer *buf; 1129 + struct vmw_buffer_object *buf; 1130 1130 struct ttm_placement *placement; 1131 1131 int ret; 1132 1132 1133 - buf = vfb->dmabuf ? vmw_framebuffer_to_vfbd(&vfb->base)->buffer : 1133 + buf = vfb->bo ? vmw_framebuffer_to_vfbd(&vfb->base)->buffer : 1134 1134 vmw_framebuffer_to_vfbs(&vfb->base)->surface->res.backup; 1135 1135 1136 1136 if (!buf) ··· 1139 1139 switch (dev_priv->active_display_unit) { 1140 1140 case vmw_du_legacy: 1141 1141 vmw_overlay_pause_all(dev_priv); 1142 - ret = vmw_dmabuf_pin_in_start_of_vram(dev_priv, buf, false); 1142 + ret = vmw_bo_pin_in_start_of_vram(dev_priv, buf, false); 1143 1143 vmw_overlay_resume_all(dev_priv); 1144 1144 break; 1145 1145 case vmw_du_screen_object: 1146 1146 case vmw_du_screen_target: 1147 - if (vfb->dmabuf) { 1147 + if (vfb->bo) { 1148 1148 if (dev_priv->capabilities & SVGA_CAP_3D) { 1149 1149 /* 1150 1150 * Use surface DMA to get content to ··· 1160 1160 placement = &vmw_mob_placement; 1161 1161 } 1162 1162 1163 - return vmw_dmabuf_pin_in_placement(dev_priv, buf, placement, 1164 - false); 1163 + return vmw_bo_pin_in_placement(dev_priv, buf, placement, false); 1165 1164 default: 1166 1165 return -EINVAL; 1167 1166 } ··· 1171 1172 static int vmw_framebuffer_unpin(struct vmw_framebuffer *vfb) 1172 1173 { 1173 1174 struct vmw_private *dev_priv = vmw_priv(vfb->base.dev); 1174 - struct vmw_dma_buffer *buf; 1175 + struct vmw_buffer_object *buf; 1175 1176 1176 - buf = vfb->dmabuf ? vmw_framebuffer_to_vfbd(&vfb->base)->buffer : 1177 + buf = vfb->bo ? vmw_framebuffer_to_vfbd(&vfb->base)->buffer : 1177 1178 vmw_framebuffer_to_vfbs(&vfb->base)->surface->res.backup; 1178 1179 1179 1180 if (WARN_ON(!buf)) 1180 1181 return 0; 1181 1182 1182 - return vmw_dmabuf_unpin(dev_priv, buf, false); 1183 + return vmw_bo_unpin(dev_priv, buf, false); 1183 1184 } 1184 1185 1185 1186 /** 1186 - * vmw_create_dmabuf_proxy - create a proxy surface for the DMA buf 1187 + * vmw_create_bo_proxy - create a proxy surface for the buffer object 1187 1188 * 1188 1189 * @dev: DRM device 1189 1190 * @mode_cmd: parameters for the new surface 1190 - * @dmabuf_mob: MOB backing the DMA buf 1191 + * @bo_mob: MOB backing the buffer object 1191 1192 * @srf_out: newly created surface 1192 1193 * 1193 - * When the content FB is a DMA buf, we create a surface as a proxy to the 1194 + * When the content FB is a buffer object, we create a surface as a proxy to the 1194 1195 * same buffer. This way we can do a surface copy rather than a surface DMA. 1195 1196 * This is a more efficient approach 1196 1197 * 1197 1198 * RETURNS: 1198 1199 * 0 on success, error code otherwise 1199 1200 */ 1200 - static int vmw_create_dmabuf_proxy(struct drm_device *dev, 1201 - const struct drm_mode_fb_cmd2 *mode_cmd, 1202 - struct vmw_dma_buffer *dmabuf_mob, 1203 - struct vmw_surface **srf_out) 1201 + static int vmw_create_bo_proxy(struct drm_device *dev, 1202 + const struct drm_mode_fb_cmd2 *mode_cmd, 1203 + struct vmw_buffer_object *bo_mob, 1204 + struct vmw_surface **srf_out) 1204 1205 { 1205 1206 uint32_t format; 1206 1207 struct drm_vmw_size content_base_size = {0}; ··· 1257 1258 /* Reserve and switch the backing mob. */ 1258 1259 mutex_lock(&res->dev_priv->cmdbuf_mutex); 1259 1260 (void) vmw_resource_reserve(res, false, true); 1260 - vmw_dmabuf_unreference(&res->backup); 1261 - res->backup = vmw_dmabuf_reference(dmabuf_mob); 1261 + vmw_bo_unreference(&res->backup); 1262 + res->backup = vmw_bo_reference(bo_mob); 1262 1263 res->backup_offset = 0; 1263 1264 vmw_resource_unreserve(res, false, NULL, 0); 1264 1265 mutex_unlock(&res->dev_priv->cmdbuf_mutex); ··· 1268 1269 1269 1270 1270 1271 1271 - static int vmw_kms_new_framebuffer_dmabuf(struct vmw_private *dev_priv, 1272 - struct vmw_dma_buffer *dmabuf, 1273 - struct vmw_framebuffer **out, 1274 - const struct drm_mode_fb_cmd2 1275 - *mode_cmd) 1272 + static int vmw_kms_new_framebuffer_bo(struct vmw_private *dev_priv, 1273 + struct vmw_buffer_object *bo, 1274 + struct vmw_framebuffer **out, 1275 + const struct drm_mode_fb_cmd2 1276 + *mode_cmd) 1276 1277 1277 1278 { 1278 1279 struct drm_device *dev = dev_priv->dev; 1279 - struct vmw_framebuffer_dmabuf *vfbd; 1280 + struct vmw_framebuffer_bo *vfbd; 1280 1281 unsigned int requested_size; 1281 1282 struct drm_format_name_buf format_name; 1282 1283 int ret; 1283 1284 1284 1285 requested_size = mode_cmd->height * mode_cmd->pitches[0]; 1285 - if (unlikely(requested_size > dmabuf->base.num_pages * PAGE_SIZE)) { 1286 + if (unlikely(requested_size > bo->base.num_pages * PAGE_SIZE)) { 1286 1287 DRM_ERROR("Screen buffer object size is too small " 1287 1288 "for requested mode.\n"); 1288 1289 return -EINVAL; ··· 1311 1312 } 1312 1313 1313 1314 drm_helper_mode_fill_fb_struct(dev, &vfbd->base.base, mode_cmd); 1314 - vfbd->base.dmabuf = true; 1315 - vfbd->buffer = vmw_dmabuf_reference(dmabuf); 1315 + vfbd->base.bo = true; 1316 + vfbd->buffer = vmw_bo_reference(bo); 1316 1317 vfbd->base.user_handle = mode_cmd->handles[0]; 1317 1318 *out = &vfbd->base; 1318 1319 1319 1320 ret = drm_framebuffer_init(dev, &vfbd->base.base, 1320 - &vmw_framebuffer_dmabuf_funcs); 1321 + &vmw_framebuffer_bo_funcs); 1321 1322 if (ret) 1322 1323 goto out_err2; 1323 1324 1324 1325 return 0; 1325 1326 1326 1327 out_err2: 1327 - vmw_dmabuf_unreference(&dmabuf); 1328 + vmw_bo_unreference(&bo); 1328 1329 kfree(vfbd); 1329 1330 out_err1: 1330 1331 return ret; ··· 1353 1354 * vmw_kms_new_framebuffer - Create a new framebuffer. 1354 1355 * 1355 1356 * @dev_priv: Pointer to device private struct. 1356 - * @dmabuf: Pointer to dma buffer to wrap the kms framebuffer around. 1357 - * Either @dmabuf or @surface must be NULL. 1357 + * @bo: Pointer to buffer object to wrap the kms framebuffer around. 1358 + * Either @bo or @surface must be NULL. 1358 1359 * @surface: Pointer to a surface to wrap the kms framebuffer around. 1359 - * Either @dmabuf or @surface must be NULL. 1360 - * @only_2d: No presents will occur to this dma buffer based framebuffer. This 1361 - * Helps the code to do some important optimizations. 1360 + * Either @bo or @surface must be NULL. 1361 + * @only_2d: No presents will occur to this buffer object based framebuffer. 1362 + * This helps the code to do some important optimizations. 1362 1363 * @mode_cmd: Frame-buffer metadata. 1363 1364 */ 1364 1365 struct vmw_framebuffer * 1365 1366 vmw_kms_new_framebuffer(struct vmw_private *dev_priv, 1366 - struct vmw_dma_buffer *dmabuf, 1367 + struct vmw_buffer_object *bo, 1367 1368 struct vmw_surface *surface, 1368 1369 bool only_2d, 1369 1370 const struct drm_mode_fb_cmd2 *mode_cmd) 1370 1371 { 1371 1372 struct vmw_framebuffer *vfb = NULL; 1372 - bool is_dmabuf_proxy = false; 1373 + bool is_bo_proxy = false; 1373 1374 int ret; 1374 1375 1375 1376 /* 1376 1377 * We cannot use the SurfaceDMA command in an non-accelerated VM, 1377 - * therefore, wrap the DMA buf in a surface so we can use the 1378 + * therefore, wrap the buffer object in a surface so we can use the 1378 1379 * SurfaceCopy command. 1379 1380 */ 1380 1381 if (vmw_kms_srf_ok(dev_priv, mode_cmd->width, mode_cmd->height) && 1381 - dmabuf && only_2d && 1382 + bo && only_2d && 1382 1383 mode_cmd->width > 64 && /* Don't create a proxy for cursor */ 1383 1384 dev_priv->active_display_unit == vmw_du_screen_target) { 1384 - ret = vmw_create_dmabuf_proxy(dev_priv->dev, mode_cmd, 1385 - dmabuf, &surface); 1385 + ret = vmw_create_bo_proxy(dev_priv->dev, mode_cmd, 1386 + bo, &surface); 1386 1387 if (ret) 1387 1388 return ERR_PTR(ret); 1388 1389 1389 - is_dmabuf_proxy = true; 1390 + is_bo_proxy = true; 1390 1391 } 1391 1392 1392 1393 /* Create the new framebuffer depending one what we have */ 1393 1394 if (surface) { 1394 1395 ret = vmw_kms_new_framebuffer_surface(dev_priv, surface, &vfb, 1395 1396 mode_cmd, 1396 - is_dmabuf_proxy); 1397 + is_bo_proxy); 1397 1398 1398 1399 /* 1399 - * vmw_create_dmabuf_proxy() adds a reference that is no longer 1400 + * vmw_create_bo_proxy() adds a reference that is no longer 1400 1401 * needed 1401 1402 */ 1402 - if (is_dmabuf_proxy) 1403 + if (is_bo_proxy) 1403 1404 vmw_surface_unreference(&surface); 1404 - } else if (dmabuf) { 1405 - ret = vmw_kms_new_framebuffer_dmabuf(dev_priv, dmabuf, &vfb, 1406 - mode_cmd); 1405 + } else if (bo) { 1406 + ret = vmw_kms_new_framebuffer_bo(dev_priv, bo, &vfb, 1407 + mode_cmd); 1407 1408 } else { 1408 1409 BUG(); 1409 1410 } ··· 1429 1430 struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; 1430 1431 struct vmw_framebuffer *vfb = NULL; 1431 1432 struct vmw_surface *surface = NULL; 1432 - struct vmw_dma_buffer *bo = NULL; 1433 + struct vmw_buffer_object *bo = NULL; 1433 1434 struct ttm_base_object *user_obj; 1434 1435 int ret; 1435 - 1436 - /** 1437 - * This code should be conditioned on Screen Objects not being used. 1438 - * If screen objects are used, we can allocate a GMR to hold the 1439 - * requested framebuffer. 1440 - */ 1441 - 1442 - if (!vmw_kms_validate_mode_vram(dev_priv, 1443 - mode_cmd->pitches[0], 1444 - mode_cmd->height)) { 1445 - DRM_ERROR("Requested mode exceed bounding box limit.\n"); 1446 - return ERR_PTR(-ENOMEM); 1447 - } 1448 1436 1449 1437 /* 1450 1438 * Take a reference on the user object of the resource ··· 1452 1466 * End conditioned code. 1453 1467 */ 1454 1468 1455 - /* returns either a dmabuf or surface */ 1469 + /* returns either a bo or surface */ 1456 1470 ret = vmw_user_lookup_handle(dev_priv, tfile, 1457 1471 mode_cmd->handles[0], 1458 1472 &surface, &bo); ··· 1480 1494 err_out: 1481 1495 /* vmw_user_lookup_handle takes one ref so does new_fb */ 1482 1496 if (bo) 1483 - vmw_dmabuf_unreference(&bo); 1497 + vmw_bo_unreference(&bo); 1484 1498 if (surface) 1485 1499 vmw_surface_unreference(&surface); 1486 1500 ··· 1494 1508 return &vfb->base; 1495 1509 } 1496 1510 1511 + /** 1512 + * vmw_kms_check_display_memory - Validates display memory required for a 1513 + * topology 1514 + * @dev: DRM device 1515 + * @num_rects: number of drm_rect in rects 1516 + * @rects: array of drm_rect representing the topology to validate indexed by 1517 + * crtc index. 1518 + * 1519 + * Returns: 1520 + * 0 on success otherwise negative error code 1521 + */ 1522 + static int vmw_kms_check_display_memory(struct drm_device *dev, 1523 + uint32_t num_rects, 1524 + struct drm_rect *rects) 1525 + { 1526 + struct vmw_private *dev_priv = vmw_priv(dev); 1527 + struct drm_mode_config *mode_config = &dev->mode_config; 1528 + struct drm_rect bounding_box = {0}; 1529 + u64 total_pixels = 0, pixel_mem, bb_mem; 1530 + int i; 1497 1531 1532 + for (i = 0; i < num_rects; i++) { 1533 + /* 1534 + * Currently this check is limiting the topology within max 1535 + * texture/screentarget size. This should change in future when 1536 + * user-space support multiple fb with topology. 1537 + */ 1538 + if (rects[i].x1 < 0 || rects[i].y1 < 0 || 1539 + rects[i].x2 > mode_config->max_width || 1540 + rects[i].y2 > mode_config->max_height) { 1541 + DRM_ERROR("Invalid GUI layout.\n"); 1542 + return -EINVAL; 1543 + } 1544 + 1545 + /* Bounding box upper left is at (0,0). */ 1546 + if (rects[i].x2 > bounding_box.x2) 1547 + bounding_box.x2 = rects[i].x2; 1548 + 1549 + if (rects[i].y2 > bounding_box.y2) 1550 + bounding_box.y2 = rects[i].y2; 1551 + 1552 + total_pixels += (u64) drm_rect_width(&rects[i]) * 1553 + (u64) drm_rect_height(&rects[i]); 1554 + } 1555 + 1556 + /* Virtual svga device primary limits are always in 32-bpp. */ 1557 + pixel_mem = total_pixels * 4; 1558 + 1559 + /* 1560 + * For HV10 and below prim_bb_mem is vram size. When 1561 + * SVGA_REG_MAX_PRIMARY_BOUNDING_BOX_MEM is not present vram size is 1562 + * limit on primary bounding box 1563 + */ 1564 + if (pixel_mem > dev_priv->prim_bb_mem) { 1565 + DRM_ERROR("Combined output size too large.\n"); 1566 + return -EINVAL; 1567 + } 1568 + 1569 + /* SVGA_CAP_NO_BB_RESTRICTION is available for STDU only. */ 1570 + if (dev_priv->active_display_unit != vmw_du_screen_target || 1571 + !(dev_priv->capabilities & SVGA_CAP_NO_BB_RESTRICTION)) { 1572 + bb_mem = (u64) bounding_box.x2 * bounding_box.y2 * 4; 1573 + 1574 + if (bb_mem > dev_priv->prim_bb_mem) { 1575 + DRM_ERROR("Topology is beyond supported limits.\n"); 1576 + return -EINVAL; 1577 + } 1578 + } 1579 + 1580 + return 0; 1581 + } 1582 + 1583 + /** 1584 + * vmw_kms_check_topology - Validates topology in drm_atomic_state 1585 + * @dev: DRM device 1586 + * @state: the driver state object 1587 + * 1588 + * Returns: 1589 + * 0 on success otherwise negative error code 1590 + */ 1591 + static int vmw_kms_check_topology(struct drm_device *dev, 1592 + struct drm_atomic_state *state) 1593 + { 1594 + struct vmw_private *dev_priv = vmw_priv(dev); 1595 + struct drm_crtc_state *old_crtc_state, *new_crtc_state; 1596 + struct drm_rect *rects; 1597 + struct drm_crtc *crtc; 1598 + uint32_t i; 1599 + int ret = 0; 1600 + 1601 + rects = kcalloc(dev->mode_config.num_crtc, sizeof(struct drm_rect), 1602 + GFP_KERNEL); 1603 + if (!rects) 1604 + return -ENOMEM; 1605 + 1606 + mutex_lock(&dev_priv->requested_layout_mutex); 1607 + 1608 + drm_for_each_crtc(crtc, dev) { 1609 + struct vmw_display_unit *du = vmw_crtc_to_du(crtc); 1610 + struct drm_crtc_state *crtc_state = crtc->state; 1611 + 1612 + i = drm_crtc_index(crtc); 1613 + 1614 + if (crtc_state && crtc_state->enable) { 1615 + rects[i].x1 = du->gui_x; 1616 + rects[i].y1 = du->gui_y; 1617 + rects[i].x2 = du->gui_x + crtc_state->mode.hdisplay; 1618 + rects[i].y2 = du->gui_y + crtc_state->mode.vdisplay; 1619 + } 1620 + } 1621 + 1622 + /* Determine change to topology due to new atomic state */ 1623 + for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, 1624 + new_crtc_state, i) { 1625 + struct vmw_display_unit *du = vmw_crtc_to_du(crtc); 1626 + struct drm_connector *connector; 1627 + struct drm_connector_state *conn_state; 1628 + struct vmw_connector_state *vmw_conn_state; 1629 + 1630 + if (!new_crtc_state->enable && old_crtc_state->enable) { 1631 + rects[i].x1 = 0; 1632 + rects[i].y1 = 0; 1633 + rects[i].x2 = 0; 1634 + rects[i].y2 = 0; 1635 + continue; 1636 + } 1637 + 1638 + if (!du->pref_active) { 1639 + ret = -EINVAL; 1640 + goto clean; 1641 + } 1642 + 1643 + /* 1644 + * For vmwgfx each crtc has only one connector attached and it 1645 + * is not changed so don't really need to check the 1646 + * crtc->connector_mask and iterate over it. 1647 + */ 1648 + connector = &du->connector; 1649 + conn_state = drm_atomic_get_connector_state(state, connector); 1650 + if (IS_ERR(conn_state)) { 1651 + ret = PTR_ERR(conn_state); 1652 + goto clean; 1653 + } 1654 + 1655 + vmw_conn_state = vmw_connector_state_to_vcs(conn_state); 1656 + vmw_conn_state->gui_x = du->gui_x; 1657 + vmw_conn_state->gui_y = du->gui_y; 1658 + 1659 + rects[i].x1 = du->gui_x; 1660 + rects[i].y1 = du->gui_y; 1661 + rects[i].x2 = du->gui_x + new_crtc_state->mode.hdisplay; 1662 + rects[i].y2 = du->gui_y + new_crtc_state->mode.vdisplay; 1663 + } 1664 + 1665 + ret = vmw_kms_check_display_memory(dev, dev->mode_config.num_crtc, 1666 + rects); 1667 + 1668 + clean: 1669 + mutex_unlock(&dev_priv->requested_layout_mutex); 1670 + kfree(rects); 1671 + return ret; 1672 + } 1498 1673 1499 1674 /** 1500 1675 * vmw_kms_atomic_check_modeset- validate state object for modeset changes ··· 1667 1520 * us to assign a value to mode->crtc_clock so that 1668 1521 * drm_calc_timestamping_constants() won't throw an error message 1669 1522 * 1670 - * RETURNS 1523 + * Returns: 1671 1524 * Zero for success or -errno 1672 1525 */ 1673 1526 static int 1674 1527 vmw_kms_atomic_check_modeset(struct drm_device *dev, 1675 1528 struct drm_atomic_state *state) 1676 1529 { 1677 - struct drm_crtc_state *crtc_state; 1678 1530 struct drm_crtc *crtc; 1679 - struct vmw_private *dev_priv = vmw_priv(dev); 1680 - int i; 1531 + struct drm_crtc_state *crtc_state; 1532 + bool need_modeset = false; 1533 + int i, ret; 1681 1534 1535 + ret = drm_atomic_helper_check(dev, state); 1536 + if (ret) 1537 + return ret; 1538 + 1539 + if (!state->allow_modeset) 1540 + return ret; 1541 + 1542 + /* 1543 + * Legacy path do not set allow_modeset properly like 1544 + * @drm_atomic_helper_update_plane, This will result in unnecessary call 1545 + * to vmw_kms_check_topology. So extra set of check. 1546 + */ 1682 1547 for_each_new_crtc_in_state(state, crtc, crtc_state, i) { 1683 - unsigned long requested_bb_mem = 0; 1684 - 1685 - if (dev_priv->active_display_unit == vmw_du_screen_target) { 1686 - struct drm_plane *plane = crtc->primary; 1687 - struct drm_plane_state *plane_state; 1688 - 1689 - plane_state = drm_atomic_get_new_plane_state(state, plane); 1690 - 1691 - if (plane_state && plane_state->fb) { 1692 - int cpp = plane_state->fb->format->cpp[0]; 1693 - 1694 - requested_bb_mem += crtc->mode.hdisplay * cpp * 1695 - crtc->mode.vdisplay; 1696 - } 1697 - 1698 - if (requested_bb_mem > dev_priv->prim_bb_mem) 1699 - return -EINVAL; 1700 - } 1548 + if (drm_atomic_crtc_needs_modeset(crtc_state)) 1549 + need_modeset = true; 1701 1550 } 1702 1551 1703 - return drm_atomic_helper_check(dev, state); 1552 + if (need_modeset) 1553 + return vmw_kms_check_topology(dev, state); 1554 + 1555 + return ret; 1704 1556 } 1705 1557 1706 1558 static const struct drm_mode_config_funcs vmw_kms_funcs = { ··· 1991 1845 { 1992 1846 } 1993 1847 1994 - 1995 - /* 1996 - * Small shared kms functions. 1848 + /** 1849 + * vmw_du_update_layout - Update the display unit with topology from resolution 1850 + * plugin and generate DRM uevent 1851 + * @dev_priv: device private 1852 + * @num_rects: number of drm_rect in rects 1853 + * @rects: toplogy to update 1997 1854 */ 1998 - 1999 - static int vmw_du_update_layout(struct vmw_private *dev_priv, unsigned num, 2000 - struct drm_vmw_rect *rects) 1855 + static int vmw_du_update_layout(struct vmw_private *dev_priv, 1856 + unsigned int num_rects, struct drm_rect *rects) 2001 1857 { 2002 1858 struct drm_device *dev = dev_priv->dev; 2003 1859 struct vmw_display_unit *du; 2004 1860 struct drm_connector *con; 1861 + struct drm_connector_list_iter conn_iter; 1862 + 1863 + /* 1864 + * Currently only gui_x/y is protected with requested_layout_mutex. 1865 + */ 1866 + mutex_lock(&dev_priv->requested_layout_mutex); 1867 + drm_connector_list_iter_begin(dev, &conn_iter); 1868 + drm_for_each_connector_iter(con, &conn_iter) { 1869 + du = vmw_connector_to_du(con); 1870 + if (num_rects > du->unit) { 1871 + du->pref_width = drm_rect_width(&rects[du->unit]); 1872 + du->pref_height = drm_rect_height(&rects[du->unit]); 1873 + du->pref_active = true; 1874 + du->gui_x = rects[du->unit].x1; 1875 + du->gui_y = rects[du->unit].y1; 1876 + } else { 1877 + du->pref_width = 800; 1878 + du->pref_height = 600; 1879 + du->pref_active = false; 1880 + du->gui_x = 0; 1881 + du->gui_y = 0; 1882 + } 1883 + } 1884 + drm_connector_list_iter_end(&conn_iter); 1885 + mutex_unlock(&dev_priv->requested_layout_mutex); 2005 1886 2006 1887 mutex_lock(&dev->mode_config.mutex); 2007 - 2008 - #if 0 2009 - { 2010 - unsigned int i; 2011 - 2012 - DRM_INFO("%s: new layout ", __func__); 2013 - for (i = 0; i < num; i++) 2014 - DRM_INFO("(%i, %i %ux%u) ", rects[i].x, rects[i].y, 2015 - rects[i].w, rects[i].h); 2016 - DRM_INFO("\n"); 2017 - } 2018 - #endif 2019 - 2020 1888 list_for_each_entry(con, &dev->mode_config.connector_list, head) { 2021 1889 du = vmw_connector_to_du(con); 2022 - if (num > du->unit) { 2023 - du->pref_width = rects[du->unit].w; 2024 - du->pref_height = rects[du->unit].h; 2025 - du->pref_active = true; 2026 - du->gui_x = rects[du->unit].x; 2027 - du->gui_y = rects[du->unit].y; 1890 + if (num_rects > du->unit) { 2028 1891 drm_object_property_set_value 2029 1892 (&con->base, dev->mode_config.suggested_x_property, 2030 1893 du->gui_x); ··· 2041 1886 (&con->base, dev->mode_config.suggested_y_property, 2042 1887 du->gui_y); 2043 1888 } else { 2044 - du->pref_width = 800; 2045 - du->pref_height = 600; 2046 - du->pref_active = false; 2047 1889 drm_object_property_set_value 2048 1890 (&con->base, dev->mode_config.suggested_x_property, 2049 1891 0); ··· 2050 1898 } 2051 1899 con->status = vmw_du_connector_detect(con, true); 2052 1900 } 2053 - 2054 1901 mutex_unlock(&dev->mode_config.mutex); 1902 + 2055 1903 drm_sysfs_hotplug_event(dev); 2056 1904 2057 1905 return 0; ··· 2351 2199 return 0; 2352 2200 } 2353 2201 2354 - 2202 + /** 2203 + * vmw_kms_update_layout_ioctl - Handler for DRM_VMW_UPDATE_LAYOUT ioctl 2204 + * @dev: drm device for the ioctl 2205 + * @data: data pointer for the ioctl 2206 + * @file_priv: drm file for the ioctl call 2207 + * 2208 + * Update preferred topology of display unit as per ioctl request. The topology 2209 + * is expressed as array of drm_vmw_rect. 2210 + * e.g. 2211 + * [0 0 640 480] [640 0 800 600] [0 480 640 480] 2212 + * 2213 + * NOTE: 2214 + * The x and y offset (upper left) in drm_vmw_rect cannot be less than 0. Beside 2215 + * device limit on topology, x + w and y + h (lower right) cannot be greater 2216 + * than INT_MAX. So topology beyond these limits will return with error. 2217 + * 2218 + * Returns: 2219 + * Zero on success, negative errno on failure. 2220 + */ 2355 2221 int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data, 2356 2222 struct drm_file *file_priv) 2357 2223 { ··· 2378 2208 (struct drm_vmw_update_layout_arg *)data; 2379 2209 void __user *user_rects; 2380 2210 struct drm_vmw_rect *rects; 2211 + struct drm_rect *drm_rects; 2381 2212 unsigned rects_size; 2382 - int ret; 2383 - int i; 2384 - u64 total_pixels = 0; 2385 - struct drm_mode_config *mode_config = &dev->mode_config; 2386 - struct drm_vmw_rect bounding_box = {0}; 2213 + int ret, i; 2387 2214 2388 2215 if (!arg->num_outputs) { 2389 - struct drm_vmw_rect def_rect = {0, 0, 800, 600}; 2216 + struct drm_rect def_rect = {0, 0, 800, 600}; 2390 2217 vmw_du_update_layout(dev_priv, 1, &def_rect); 2391 2218 return 0; 2392 2219 } ··· 2402 2235 goto out_free; 2403 2236 } 2404 2237 2405 - for (i = 0; i < arg->num_outputs; ++i) { 2406 - if (rects[i].x < 0 || 2407 - rects[i].y < 0 || 2408 - rects[i].x + rects[i].w > mode_config->max_width || 2409 - rects[i].y + rects[i].h > mode_config->max_height) { 2410 - DRM_ERROR("Invalid GUI layout.\n"); 2411 - ret = -EINVAL; 2238 + drm_rects = (struct drm_rect *)rects; 2239 + 2240 + for (i = 0; i < arg->num_outputs; i++) { 2241 + struct drm_vmw_rect curr_rect; 2242 + 2243 + /* Verify user-space for overflow as kernel use drm_rect */ 2244 + if ((rects[i].x + rects[i].w > INT_MAX) || 2245 + (rects[i].y + rects[i].h > INT_MAX)) { 2246 + ret = -ERANGE; 2412 2247 goto out_free; 2413 2248 } 2414 2249 2415 - /* 2416 - * bounding_box.w and bunding_box.h are used as 2417 - * lower-right coordinates 2418 - */ 2419 - if (rects[i].x + rects[i].w > bounding_box.w) 2420 - bounding_box.w = rects[i].x + rects[i].w; 2421 - 2422 - if (rects[i].y + rects[i].h > bounding_box.h) 2423 - bounding_box.h = rects[i].y + rects[i].h; 2424 - 2425 - total_pixels += (u64) rects[i].w * (u64) rects[i].h; 2250 + curr_rect = rects[i]; 2251 + drm_rects[i].x1 = curr_rect.x; 2252 + drm_rects[i].y1 = curr_rect.y; 2253 + drm_rects[i].x2 = curr_rect.x + curr_rect.w; 2254 + drm_rects[i].y2 = curr_rect.y + curr_rect.h; 2426 2255 } 2427 2256 2428 - if (dev_priv->active_display_unit == vmw_du_screen_target) { 2429 - /* 2430 - * For Screen Targets, the limits for a toplogy are: 2431 - * 1. Bounding box (assuming 32bpp) must be < prim_bb_mem 2432 - * 2. Total pixels (assuming 32bpp) must be < prim_bb_mem 2433 - */ 2434 - u64 bb_mem = (u64) bounding_box.w * bounding_box.h * 4; 2435 - u64 pixel_mem = total_pixels * 4; 2257 + ret = vmw_kms_check_display_memory(dev, arg->num_outputs, drm_rects); 2436 2258 2437 - if (bb_mem > dev_priv->prim_bb_mem) { 2438 - DRM_ERROR("Topology is beyond supported limits.\n"); 2439 - ret = -EINVAL; 2440 - goto out_free; 2441 - } 2442 - 2443 - if (pixel_mem > dev_priv->prim_bb_mem) { 2444 - DRM_ERROR("Combined output size too large\n"); 2445 - ret = -EINVAL; 2446 - goto out_free; 2447 - } 2448 - } 2449 - 2450 - vmw_du_update_layout(dev_priv, arg->num_outputs, rects); 2259 + if (ret == 0) 2260 + vmw_du_update_layout(dev_priv, arg->num_outputs, drm_rects); 2451 2261 2452 2262 out_free: 2453 2263 kfree(rects); ··· 2571 2427 * interrupted by a signal. 2572 2428 */ 2573 2429 int vmw_kms_helper_buffer_prepare(struct vmw_private *dev_priv, 2574 - struct vmw_dma_buffer *buf, 2430 + struct vmw_buffer_object *buf, 2575 2431 bool interruptible, 2576 2432 bool validate_as_mob, 2577 2433 bool for_cpu_blit) ··· 2603 2459 * Helper to be used if an error forces the caller to undo the actions of 2604 2460 * vmw_kms_helper_buffer_prepare. 2605 2461 */ 2606 - void vmw_kms_helper_buffer_revert(struct vmw_dma_buffer *buf) 2462 + void vmw_kms_helper_buffer_revert(struct vmw_buffer_object *buf) 2607 2463 { 2608 2464 if (buf) 2609 2465 ttm_bo_unreserve(&buf->base); ··· 2626 2482 */ 2627 2483 void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv, 2628 2484 struct drm_file *file_priv, 2629 - struct vmw_dma_buffer *buf, 2485 + struct vmw_buffer_object *buf, 2630 2486 struct vmw_fence_obj **out_fence, 2631 2487 struct drm_vmw_fence_rep __user * 2632 2488 user_fence_rep) ··· 2638 2494 ret = vmw_execbuf_fence_commands(file_priv, dev_priv, &fence, 2639 2495 file_priv ? &handle : NULL); 2640 2496 if (buf) 2641 - vmw_fence_single_bo(&buf->base, fence); 2497 + vmw_bo_fence_single(&buf->base, fence); 2642 2498 if (file_priv) 2643 2499 vmw_execbuf_copy_fence_user(dev_priv, vmw_fpriv(file_priv), 2644 2500 ret, user_fence_rep, fence, ··· 2666 2522 struct vmw_resource *res = ctx->res; 2667 2523 2668 2524 vmw_kms_helper_buffer_revert(ctx->buf); 2669 - vmw_dmabuf_unreference(&ctx->buf); 2525 + vmw_bo_unreference(&ctx->buf); 2670 2526 vmw_resource_unreserve(res, false, NULL, 0); 2671 2527 mutex_unlock(&res->dev_priv->cmdbuf_mutex); 2672 2528 } ··· 2711 2567 if (ret) 2712 2568 goto out_unreserve; 2713 2569 2714 - ctx->buf = vmw_dmabuf_reference(res->backup); 2570 + ctx->buf = vmw_bo_reference(res->backup); 2715 2571 } 2716 2572 ret = vmw_resource_validate(res); 2717 2573 if (ret) ··· 2744 2600 vmw_kms_helper_buffer_finish(res->dev_priv, NULL, ctx->buf, 2745 2601 out_fence, NULL); 2746 2602 2747 - vmw_dmabuf_unreference(&ctx->buf); 2603 + vmw_bo_unreference(&ctx->buf); 2748 2604 vmw_resource_unreserve(res, false, NULL, 0); 2749 2605 mutex_unlock(&res->dev_priv->cmdbuf_mutex); 2750 2606 }
+47 -29
drivers/gpu/drm/vmwgfx/vmwgfx_kms.h
··· 90 90 #define vmw_framebuffer_to_vfbs(x) \ 91 91 container_of(x, struct vmw_framebuffer_surface, base.base) 92 92 #define vmw_framebuffer_to_vfbd(x) \ 93 - container_of(x, struct vmw_framebuffer_dmabuf, base.base) 93 + container_of(x, struct vmw_framebuffer_bo, base.base) 94 94 95 95 /** 96 96 * Base class for framebuffers ··· 102 102 struct drm_framebuffer base; 103 103 int (*pin)(struct vmw_framebuffer *fb); 104 104 int (*unpin)(struct vmw_framebuffer *fb); 105 - bool dmabuf; 105 + bool bo; 106 106 struct ttm_base_object *user_obj; 107 107 uint32_t user_handle; 108 108 }; ··· 117 117 struct vmw_framebuffer_surface { 118 118 struct vmw_framebuffer base; 119 119 struct vmw_surface *surface; 120 - struct vmw_dma_buffer *buffer; 120 + struct vmw_buffer_object *buffer; 121 121 struct list_head head; 122 - bool is_dmabuf_proxy; /* true if this is proxy surface for DMA buf */ 122 + bool is_bo_proxy; /* true if this is proxy surface for DMA buf */ 123 123 }; 124 124 125 125 126 - struct vmw_framebuffer_dmabuf { 126 + struct vmw_framebuffer_bo { 127 127 struct vmw_framebuffer base; 128 - struct vmw_dma_buffer *buffer; 128 + struct vmw_buffer_object *buffer; 129 129 }; 130 130 131 131 ··· 161 161 * 162 162 * @base DRM plane object 163 163 * @surf Display surface for STDU 164 - * @dmabuf display dmabuf for SOU 164 + * @bo display bo for SOU 165 165 * @content_fb_type Used by STDU. 166 - * @dmabuf_size Size of the dmabuf, used by Screen Object Display Unit 166 + * @bo_size Size of the bo, used by Screen Object Display Unit 167 167 * @pinned pin count for STDU display surface 168 168 */ 169 169 struct vmw_plane_state { 170 170 struct drm_plane_state base; 171 171 struct vmw_surface *surf; 172 - struct vmw_dma_buffer *dmabuf; 172 + struct vmw_buffer_object *bo; 173 173 174 174 int content_fb_type; 175 - unsigned long dmabuf_size; 175 + unsigned long bo_size; 176 176 177 177 int pinned; 178 178 ··· 192 192 struct drm_connector_state base; 193 193 194 194 bool is_implicit; 195 + 196 + /** 197 + * @gui_x: 198 + * 199 + * vmwgfx connector property representing the x position of this display 200 + * unit (connector is synonymous to display unit) in overall topology. 201 + * This is what the device expect as xRoot while creating screen. 202 + */ 203 + int gui_x; 204 + 205 + /** 206 + * @gui_y: 207 + * 208 + * vmwgfx connector property representing the y position of this display 209 + * unit (connector is synonymous to display unit) in overall topology. 210 + * This is what the device expect as yRoot while creating screen. 211 + */ 212 + int gui_y; 195 213 }; 196 214 197 215 /** ··· 227 209 struct drm_plane cursor; 228 210 229 211 struct vmw_surface *cursor_surface; 230 - struct vmw_dma_buffer *cursor_dmabuf; 212 + struct vmw_buffer_object *cursor_bo; 231 213 size_t cursor_age; 232 214 233 215 int cursor_x; ··· 261 243 262 244 struct vmw_validation_ctx { 263 245 struct vmw_resource *res; 264 - struct vmw_dma_buffer *buf; 246 + struct vmw_buffer_object *buf; 265 247 }; 266 248 267 249 #define vmw_crtc_to_du(x) \ ··· 309 291 struct vmw_kms_dirty *dirty); 310 292 311 293 int vmw_kms_helper_buffer_prepare(struct vmw_private *dev_priv, 312 - struct vmw_dma_buffer *buf, 294 + struct vmw_buffer_object *buf, 313 295 bool interruptible, 314 296 bool validate_as_mob, 315 297 bool for_cpu_blit); 316 - void vmw_kms_helper_buffer_revert(struct vmw_dma_buffer *buf); 298 + void vmw_kms_helper_buffer_revert(struct vmw_buffer_object *buf); 317 299 void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv, 318 300 struct drm_file *file_priv, 319 - struct vmw_dma_buffer *buf, 301 + struct vmw_buffer_object *buf, 320 302 struct vmw_fence_obj **out_fence, 321 303 struct drm_vmw_fence_rep __user * 322 304 user_fence_rep); ··· 334 316 uint32_t num_clips); 335 317 struct vmw_framebuffer * 336 318 vmw_kms_new_framebuffer(struct vmw_private *dev_priv, 337 - struct vmw_dma_buffer *dmabuf, 319 + struct vmw_buffer_object *bo, 338 320 struct vmw_surface *surface, 339 321 bool only_2d, 340 322 const struct drm_mode_fb_cmd2 *mode_cmd); ··· 402 384 */ 403 385 int vmw_kms_ldu_init_display(struct vmw_private *dev_priv); 404 386 int vmw_kms_ldu_close_display(struct vmw_private *dev_priv); 405 - int vmw_kms_ldu_do_dmabuf_dirty(struct vmw_private *dev_priv, 406 - struct vmw_framebuffer *framebuffer, 407 - unsigned flags, unsigned color, 408 - struct drm_clip_rect *clips, 409 - unsigned num_clips, int increment); 387 + int vmw_kms_ldu_do_bo_dirty(struct vmw_private *dev_priv, 388 + struct vmw_framebuffer *framebuffer, 389 + unsigned int flags, unsigned int color, 390 + struct drm_clip_rect *clips, 391 + unsigned int num_clips, int increment); 410 392 int vmw_kms_update_proxy(struct vmw_resource *res, 411 393 const struct drm_clip_rect *clips, 412 394 unsigned num_clips, ··· 426 408 unsigned num_clips, int inc, 427 409 struct vmw_fence_obj **out_fence, 428 410 struct drm_crtc *crtc); 429 - int vmw_kms_sou_do_dmabuf_dirty(struct vmw_private *dev_priv, 430 - struct vmw_framebuffer *framebuffer, 431 - struct drm_clip_rect *clips, 432 - struct drm_vmw_rect *vclips, 433 - unsigned num_clips, int increment, 434 - bool interruptible, 435 - struct vmw_fence_obj **out_fence, 436 - struct drm_crtc *crtc); 411 + int vmw_kms_sou_do_bo_dirty(struct vmw_private *dev_priv, 412 + struct vmw_framebuffer *framebuffer, 413 + struct drm_clip_rect *clips, 414 + struct drm_vmw_rect *vclips, 415 + unsigned int num_clips, int increment, 416 + bool interruptible, 417 + struct vmw_fence_obj **out_fence, 418 + struct drm_crtc *crtc); 437 419 int vmw_kms_sou_readback(struct vmw_private *dev_priv, 438 420 struct drm_file *file_priv, 439 421 struct vmw_framebuffer *vfb,
+5 -5
drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
··· 547 547 } 548 548 549 549 550 - int vmw_kms_ldu_do_dmabuf_dirty(struct vmw_private *dev_priv, 551 - struct vmw_framebuffer *framebuffer, 552 - unsigned flags, unsigned color, 553 - struct drm_clip_rect *clips, 554 - unsigned num_clips, int increment) 550 + int vmw_kms_ldu_do_bo_dirty(struct vmw_private *dev_priv, 551 + struct vmw_framebuffer *framebuffer, 552 + unsigned int flags, unsigned int color, 553 + struct drm_clip_rect *clips, 554 + unsigned int num_clips, int increment) 555 555 { 556 556 size_t fifo_size; 557 557 int i;
+3 -3
drivers/gpu/drm/vmwgfx/vmwgfx_mob.c
··· 225 225 ret = ttm_bo_reserve(bo, false, true, NULL); 226 226 BUG_ON(ret != 0); 227 227 228 - vmw_fence_single_bo(bo, NULL); 228 + vmw_bo_fence_single(bo, NULL); 229 229 ttm_bo_unreserve(bo); 230 230 } 231 231 ··· 362 362 ret = ttm_bo_reserve(bo, false, true, NULL); 363 363 BUG_ON(ret != 0); 364 364 365 - vmw_fence_single_bo(bo, NULL); 365 + vmw_bo_fence_single(bo, NULL); 366 366 ttm_bo_unreserve(bo); 367 367 368 368 ttm_bo_unref(&batch->otable_bo); ··· 620 620 vmw_fifo_commit(dev_priv, sizeof(*cmd)); 621 621 } 622 622 if (bo) { 623 - vmw_fence_single_bo(bo, NULL); 623 + vmw_bo_fence_single(bo, NULL); 624 624 ttm_bo_unreserve(bo); 625 625 } 626 626 vmw_fifo_resource_dec(dev_priv);
+8 -6
drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
··· 31 31 #include <linux/frame.h> 32 32 #include <asm/hypervisor.h> 33 33 #include <drm/drmP.h> 34 + #include "vmwgfx_drv.h" 34 35 #include "vmwgfx_msg.h" 35 36 36 37 ··· 235 234 236 235 if ((HIGH_WORD(ecx) & MESSAGE_STATUS_SUCCESS) == 0 || 237 236 (HIGH_WORD(ecx) & MESSAGE_STATUS_HB) == 0) { 238 - DRM_ERROR("Failed to get reply size\n"); 237 + DRM_ERROR("Failed to get reply size for host message.\n"); 239 238 return -EINVAL; 240 239 } 241 240 ··· 246 245 reply_len = ebx; 247 246 reply = kzalloc(reply_len + 1, GFP_KERNEL); 248 247 if (!reply) { 249 - DRM_ERROR("Cannot allocate memory for reply\n"); 248 + DRM_ERROR("Cannot allocate memory for host message reply.\n"); 250 249 return -ENOMEM; 251 250 } 252 251 ··· 339 338 340 339 msg = kasprintf(GFP_KERNEL, "info-get %s", guest_info_param); 341 340 if (!msg) { 342 - DRM_ERROR("Cannot allocate memory to get %s", guest_info_param); 341 + DRM_ERROR("Cannot allocate memory to get guest info \"%s\".", 342 + guest_info_param); 343 343 return -ENOMEM; 344 344 } 345 345 ··· 376 374 out_open: 377 375 *length = 0; 378 376 kfree(msg); 379 - DRM_ERROR("Failed to get %s", guest_info_param); 377 + DRM_ERROR("Failed to get guest info \"%s\".", guest_info_param); 380 378 381 379 return -EINVAL; 382 380 } ··· 405 403 406 404 msg = kasprintf(GFP_KERNEL, "log %s", log); 407 405 if (!msg) { 408 - DRM_ERROR("Cannot allocate memory for log message\n"); 406 + DRM_ERROR("Cannot allocate memory for host log message.\n"); 409 407 return -ENOMEM; 410 408 } 411 409 ··· 424 422 vmw_close_channel(&channel); 425 423 out_open: 426 424 kfree(msg); 427 - DRM_ERROR("Failed to send log\n"); 425 + DRM_ERROR("Failed to send host log message.\n"); 428 426 429 427 return -EINVAL; 430 428 }
+12 -12
drivers/gpu/drm/vmwgfx/vmwgfx_overlay.c
··· 38 38 #define VMW_OVERLAY_CAP_MASK (SVGA_FIFO_CAP_VIDEO | SVGA_FIFO_CAP_ESCAPE) 39 39 40 40 struct vmw_stream { 41 - struct vmw_dma_buffer *buf; 41 + struct vmw_buffer_object *buf; 42 42 bool claimed; 43 43 bool paused; 44 44 struct drm_vmw_control_stream_arg saved; ··· 94 94 * -ERESTARTSYS if interrupted by a signal. 95 95 */ 96 96 static int vmw_overlay_send_put(struct vmw_private *dev_priv, 97 - struct vmw_dma_buffer *buf, 97 + struct vmw_buffer_object *buf, 98 98 struct drm_vmw_control_stream_arg *arg, 99 99 bool interruptible) 100 100 { ··· 225 225 * used with GMRs instead of being locked to vram. 226 226 */ 227 227 static int vmw_overlay_move_buffer(struct vmw_private *dev_priv, 228 - struct vmw_dma_buffer *buf, 228 + struct vmw_buffer_object *buf, 229 229 bool pin, bool inter) 230 230 { 231 231 if (!pin) 232 - return vmw_dmabuf_unpin(dev_priv, buf, inter); 232 + return vmw_bo_unpin(dev_priv, buf, inter); 233 233 234 234 if (dev_priv->active_display_unit == vmw_du_legacy) 235 - return vmw_dmabuf_pin_in_vram(dev_priv, buf, inter); 235 + return vmw_bo_pin_in_vram(dev_priv, buf, inter); 236 236 237 - return vmw_dmabuf_pin_in_vram_or_gmr(dev_priv, buf, inter); 237 + return vmw_bo_pin_in_vram_or_gmr(dev_priv, buf, inter); 238 238 } 239 239 240 240 /** ··· 278 278 } 279 279 280 280 if (!pause) { 281 - vmw_dmabuf_unreference(&stream->buf); 281 + vmw_bo_unreference(&stream->buf); 282 282 stream->paused = false; 283 283 } else { 284 284 stream->paused = true; ··· 297 297 * -ERESTARTSYS if interrupted. 298 298 */ 299 299 static int vmw_overlay_update_stream(struct vmw_private *dev_priv, 300 - struct vmw_dma_buffer *buf, 300 + struct vmw_buffer_object *buf, 301 301 struct drm_vmw_control_stream_arg *arg, 302 302 bool interruptible) 303 303 { ··· 347 347 } 348 348 349 349 if (stream->buf != buf) 350 - stream->buf = vmw_dmabuf_reference(buf); 350 + stream->buf = vmw_bo_reference(buf); 351 351 stream->saved = *arg; 352 352 /* stream is no longer stopped/paused */ 353 353 stream->paused = false; ··· 466 466 struct vmw_overlay *overlay = dev_priv->overlay_priv; 467 467 struct drm_vmw_control_stream_arg *arg = 468 468 (struct drm_vmw_control_stream_arg *)data; 469 - struct vmw_dma_buffer *buf; 469 + struct vmw_buffer_object *buf; 470 470 struct vmw_resource *res; 471 471 int ret; 472 472 ··· 484 484 goto out_unlock; 485 485 } 486 486 487 - ret = vmw_user_dmabuf_lookup(tfile, arg->handle, &buf, NULL); 487 + ret = vmw_user_bo_lookup(tfile, arg->handle, &buf, NULL); 488 488 if (ret) 489 489 goto out_unlock; 490 490 491 491 ret = vmw_overlay_update_stream(dev_priv, buf, arg, true); 492 492 493 - vmw_dmabuf_unreference(&buf); 493 + vmw_bo_unreference(&buf); 494 494 495 495 out_unlock: 496 496 mutex_unlock(&overlay->mutex);
+59 -646
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
··· 27 27 28 28 #include "vmwgfx_drv.h" 29 29 #include <drm/vmwgfx_drm.h> 30 - #include <drm/ttm/ttm_object.h> 31 30 #include <drm/ttm/ttm_placement.h> 32 31 #include <drm/drmP.h> 33 32 #include "vmwgfx_resource_priv.h" 34 33 #include "vmwgfx_binding.h" 35 34 36 35 #define VMW_RES_EVICT_ERR_COUNT 10 37 - 38 - struct vmw_user_dma_buffer { 39 - struct ttm_prime_object prime; 40 - struct vmw_dma_buffer dma; 41 - }; 42 - 43 - struct vmw_bo_user_rep { 44 - uint32_t handle; 45 - uint64_t map_handle; 46 - }; 47 - 48 - static inline struct vmw_dma_buffer * 49 - vmw_dma_buffer(struct ttm_buffer_object *bo) 50 - { 51 - return container_of(bo, struct vmw_dma_buffer, base); 52 - } 53 - 54 - static inline struct vmw_user_dma_buffer * 55 - vmw_user_dma_buffer(struct ttm_buffer_object *bo) 56 - { 57 - struct vmw_dma_buffer *vmw_bo = vmw_dma_buffer(bo); 58 - return container_of(vmw_bo, struct vmw_user_dma_buffer, dma); 59 - } 60 36 61 37 struct vmw_resource *vmw_resource_reference(struct vmw_resource *res) 62 38 { ··· 92 116 res->backup_dirty = false; 93 117 list_del_init(&res->mob_head); 94 118 ttm_bo_unreserve(bo); 95 - vmw_dmabuf_unreference(&res->backup); 119 + vmw_bo_unreference(&res->backup); 96 120 } 97 121 98 122 if (likely(res->hw_destroy != NULL)) { ··· 263 287 } 264 288 265 289 /** 266 - * Helper function that looks either a surface or dmabuf. 290 + * Helper function that looks either a surface or bo. 267 291 * 268 292 * The pointer this pointed at by out_surf and out_buf needs to be null. 269 293 */ ··· 271 295 struct ttm_object_file *tfile, 272 296 uint32_t handle, 273 297 struct vmw_surface **out_surf, 274 - struct vmw_dma_buffer **out_buf) 298 + struct vmw_buffer_object **out_buf) 275 299 { 276 300 struct vmw_resource *res; 277 301 int ret; ··· 287 311 } 288 312 289 313 *out_surf = NULL; 290 - ret = vmw_user_dmabuf_lookup(tfile, handle, out_buf, NULL); 314 + ret = vmw_user_bo_lookup(tfile, handle, out_buf, NULL); 291 315 return ret; 292 - } 293 - 294 - /** 295 - * Buffer management. 296 - */ 297 - 298 - /** 299 - * vmw_dmabuf_acc_size - Calculate the pinned memory usage of buffers 300 - * 301 - * @dev_priv: Pointer to a struct vmw_private identifying the device. 302 - * @size: The requested buffer size. 303 - * @user: Whether this is an ordinary dma buffer or a user dma buffer. 304 - */ 305 - static size_t vmw_dmabuf_acc_size(struct vmw_private *dev_priv, size_t size, 306 - bool user) 307 - { 308 - static size_t struct_size, user_struct_size; 309 - size_t num_pages = PAGE_ALIGN(size) >> PAGE_SHIFT; 310 - size_t page_array_size = ttm_round_pot(num_pages * sizeof(void *)); 311 - 312 - if (unlikely(struct_size == 0)) { 313 - size_t backend_size = ttm_round_pot(vmw_tt_size); 314 - 315 - struct_size = backend_size + 316 - ttm_round_pot(sizeof(struct vmw_dma_buffer)); 317 - user_struct_size = backend_size + 318 - ttm_round_pot(sizeof(struct vmw_user_dma_buffer)); 319 - } 320 - 321 - if (dev_priv->map_mode == vmw_dma_alloc_coherent) 322 - page_array_size += 323 - ttm_round_pot(num_pages * sizeof(dma_addr_t)); 324 - 325 - return ((user) ? user_struct_size : struct_size) + 326 - page_array_size; 327 - } 328 - 329 - void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo) 330 - { 331 - struct vmw_dma_buffer *vmw_bo = vmw_dma_buffer(bo); 332 - 333 - vmw_dma_buffer_unmap(vmw_bo); 334 - kfree(vmw_bo); 335 - } 336 - 337 - static void vmw_user_dmabuf_destroy(struct ttm_buffer_object *bo) 338 - { 339 - struct vmw_user_dma_buffer *vmw_user_bo = vmw_user_dma_buffer(bo); 340 - 341 - vmw_dma_buffer_unmap(&vmw_user_bo->dma); 342 - ttm_prime_object_kfree(vmw_user_bo, prime); 343 - } 344 - 345 - int vmw_dmabuf_init(struct vmw_private *dev_priv, 346 - struct vmw_dma_buffer *vmw_bo, 347 - size_t size, struct ttm_placement *placement, 348 - bool interruptible, 349 - void (*bo_free) (struct ttm_buffer_object *bo)) 350 - { 351 - struct ttm_bo_device *bdev = &dev_priv->bdev; 352 - size_t acc_size; 353 - int ret; 354 - bool user = (bo_free == &vmw_user_dmabuf_destroy); 355 - 356 - BUG_ON(!bo_free && (!user && (bo_free != vmw_dmabuf_bo_free))); 357 - 358 - acc_size = vmw_dmabuf_acc_size(dev_priv, size, user); 359 - memset(vmw_bo, 0, sizeof(*vmw_bo)); 360 - 361 - INIT_LIST_HEAD(&vmw_bo->res_list); 362 - 363 - ret = ttm_bo_init(bdev, &vmw_bo->base, size, 364 - ttm_bo_type_device, placement, 365 - 0, interruptible, acc_size, 366 - NULL, NULL, bo_free); 367 - return ret; 368 - } 369 - 370 - static void vmw_user_dmabuf_release(struct ttm_base_object **p_base) 371 - { 372 - struct vmw_user_dma_buffer *vmw_user_bo; 373 - struct ttm_base_object *base = *p_base; 374 - struct ttm_buffer_object *bo; 375 - 376 - *p_base = NULL; 377 - 378 - if (unlikely(base == NULL)) 379 - return; 380 - 381 - vmw_user_bo = container_of(base, struct vmw_user_dma_buffer, 382 - prime.base); 383 - bo = &vmw_user_bo->dma.base; 384 - ttm_bo_unref(&bo); 385 - } 386 - 387 - static void vmw_user_dmabuf_ref_obj_release(struct ttm_base_object *base, 388 - enum ttm_ref_type ref_type) 389 - { 390 - struct vmw_user_dma_buffer *user_bo; 391 - user_bo = container_of(base, struct vmw_user_dma_buffer, prime.base); 392 - 393 - switch (ref_type) { 394 - case TTM_REF_SYNCCPU_WRITE: 395 - ttm_bo_synccpu_write_release(&user_bo->dma.base); 396 - break; 397 - default: 398 - BUG(); 399 - } 400 - } 401 - 402 - /** 403 - * vmw_user_dmabuf_alloc - Allocate a user dma buffer 404 - * 405 - * @dev_priv: Pointer to a struct device private. 406 - * @tfile: Pointer to a struct ttm_object_file on which to register the user 407 - * object. 408 - * @size: Size of the dma buffer. 409 - * @shareable: Boolean whether the buffer is shareable with other open files. 410 - * @handle: Pointer to where the handle value should be assigned. 411 - * @p_dma_buf: Pointer to where the refcounted struct vmw_dma_buffer pointer 412 - * should be assigned. 413 - */ 414 - int vmw_user_dmabuf_alloc(struct vmw_private *dev_priv, 415 - struct ttm_object_file *tfile, 416 - uint32_t size, 417 - bool shareable, 418 - uint32_t *handle, 419 - struct vmw_dma_buffer **p_dma_buf, 420 - struct ttm_base_object **p_base) 421 - { 422 - struct vmw_user_dma_buffer *user_bo; 423 - struct ttm_buffer_object *tmp; 424 - int ret; 425 - 426 - user_bo = kzalloc(sizeof(*user_bo), GFP_KERNEL); 427 - if (unlikely(!user_bo)) { 428 - DRM_ERROR("Failed to allocate a buffer.\n"); 429 - return -ENOMEM; 430 - } 431 - 432 - ret = vmw_dmabuf_init(dev_priv, &user_bo->dma, size, 433 - (dev_priv->has_mob) ? 434 - &vmw_sys_placement : 435 - &vmw_vram_sys_placement, true, 436 - &vmw_user_dmabuf_destroy); 437 - if (unlikely(ret != 0)) 438 - return ret; 439 - 440 - tmp = ttm_bo_reference(&user_bo->dma.base); 441 - ret = ttm_prime_object_init(tfile, 442 - size, 443 - &user_bo->prime, 444 - shareable, 445 - ttm_buffer_type, 446 - &vmw_user_dmabuf_release, 447 - &vmw_user_dmabuf_ref_obj_release); 448 - if (unlikely(ret != 0)) { 449 - ttm_bo_unref(&tmp); 450 - goto out_no_base_object; 451 - } 452 - 453 - *p_dma_buf = &user_bo->dma; 454 - if (p_base) { 455 - *p_base = &user_bo->prime.base; 456 - kref_get(&(*p_base)->refcount); 457 - } 458 - *handle = user_bo->prime.base.hash.key; 459 - 460 - out_no_base_object: 461 - return ret; 462 - } 463 - 464 - /** 465 - * vmw_user_dmabuf_verify_access - verify access permissions on this 466 - * buffer object. 467 - * 468 - * @bo: Pointer to the buffer object being accessed 469 - * @tfile: Identifying the caller. 470 - */ 471 - int vmw_user_dmabuf_verify_access(struct ttm_buffer_object *bo, 472 - struct ttm_object_file *tfile) 473 - { 474 - struct vmw_user_dma_buffer *vmw_user_bo; 475 - 476 - if (unlikely(bo->destroy != vmw_user_dmabuf_destroy)) 477 - return -EPERM; 478 - 479 - vmw_user_bo = vmw_user_dma_buffer(bo); 480 - 481 - /* Check that the caller has opened the object. */ 482 - if (likely(ttm_ref_object_exists(tfile, &vmw_user_bo->prime.base))) 483 - return 0; 484 - 485 - DRM_ERROR("Could not grant buffer access.\n"); 486 - return -EPERM; 487 - } 488 - 489 - /** 490 - * vmw_user_dmabuf_synccpu_grab - Grab a struct vmw_user_dma_buffer for cpu 491 - * access, idling previous GPU operations on the buffer and optionally 492 - * blocking it for further command submissions. 493 - * 494 - * @user_bo: Pointer to the buffer object being grabbed for CPU access 495 - * @tfile: Identifying the caller. 496 - * @flags: Flags indicating how the grab should be performed. 497 - * 498 - * A blocking grab will be automatically released when @tfile is closed. 499 - */ 500 - static int vmw_user_dmabuf_synccpu_grab(struct vmw_user_dma_buffer *user_bo, 501 - struct ttm_object_file *tfile, 502 - uint32_t flags) 503 - { 504 - struct ttm_buffer_object *bo = &user_bo->dma.base; 505 - bool existed; 506 - int ret; 507 - 508 - if (flags & drm_vmw_synccpu_allow_cs) { 509 - bool nonblock = !!(flags & drm_vmw_synccpu_dontblock); 510 - long lret; 511 - 512 - lret = reservation_object_wait_timeout_rcu(bo->resv, true, true, 513 - nonblock ? 0 : MAX_SCHEDULE_TIMEOUT); 514 - if (!lret) 515 - return -EBUSY; 516 - else if (lret < 0) 517 - return lret; 518 - return 0; 519 - } 520 - 521 - ret = ttm_bo_synccpu_write_grab 522 - (bo, !!(flags & drm_vmw_synccpu_dontblock)); 523 - if (unlikely(ret != 0)) 524 - return ret; 525 - 526 - ret = ttm_ref_object_add(tfile, &user_bo->prime.base, 527 - TTM_REF_SYNCCPU_WRITE, &existed, false); 528 - if (ret != 0 || existed) 529 - ttm_bo_synccpu_write_release(&user_bo->dma.base); 530 - 531 - return ret; 532 - } 533 - 534 - /** 535 - * vmw_user_dmabuf_synccpu_release - Release a previous grab for CPU access, 536 - * and unblock command submission on the buffer if blocked. 537 - * 538 - * @handle: Handle identifying the buffer object. 539 - * @tfile: Identifying the caller. 540 - * @flags: Flags indicating the type of release. 541 - */ 542 - static int vmw_user_dmabuf_synccpu_release(uint32_t handle, 543 - struct ttm_object_file *tfile, 544 - uint32_t flags) 545 - { 546 - if (!(flags & drm_vmw_synccpu_allow_cs)) 547 - return ttm_ref_object_base_unref(tfile, handle, 548 - TTM_REF_SYNCCPU_WRITE); 549 - 550 - return 0; 551 - } 552 - 553 - /** 554 - * vmw_user_dmabuf_synccpu_release - ioctl function implementing the synccpu 555 - * functionality. 556 - * 557 - * @dev: Identifies the drm device. 558 - * @data: Pointer to the ioctl argument. 559 - * @file_priv: Identifies the caller. 560 - * 561 - * This function checks the ioctl arguments for validity and calls the 562 - * relevant synccpu functions. 563 - */ 564 - int vmw_user_dmabuf_synccpu_ioctl(struct drm_device *dev, void *data, 565 - struct drm_file *file_priv) 566 - { 567 - struct drm_vmw_synccpu_arg *arg = 568 - (struct drm_vmw_synccpu_arg *) data; 569 - struct vmw_dma_buffer *dma_buf; 570 - struct vmw_user_dma_buffer *user_bo; 571 - struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; 572 - struct ttm_base_object *buffer_base; 573 - int ret; 574 - 575 - if ((arg->flags & (drm_vmw_synccpu_read | drm_vmw_synccpu_write)) == 0 576 - || (arg->flags & ~(drm_vmw_synccpu_read | drm_vmw_synccpu_write | 577 - drm_vmw_synccpu_dontblock | 578 - drm_vmw_synccpu_allow_cs)) != 0) { 579 - DRM_ERROR("Illegal synccpu flags.\n"); 580 - return -EINVAL; 581 - } 582 - 583 - switch (arg->op) { 584 - case drm_vmw_synccpu_grab: 585 - ret = vmw_user_dmabuf_lookup(tfile, arg->handle, &dma_buf, 586 - &buffer_base); 587 - if (unlikely(ret != 0)) 588 - return ret; 589 - 590 - user_bo = container_of(dma_buf, struct vmw_user_dma_buffer, 591 - dma); 592 - ret = vmw_user_dmabuf_synccpu_grab(user_bo, tfile, arg->flags); 593 - vmw_dmabuf_unreference(&dma_buf); 594 - ttm_base_object_unref(&buffer_base); 595 - if (unlikely(ret != 0 && ret != -ERESTARTSYS && 596 - ret != -EBUSY)) { 597 - DRM_ERROR("Failed synccpu grab on handle 0x%08x.\n", 598 - (unsigned int) arg->handle); 599 - return ret; 600 - } 601 - break; 602 - case drm_vmw_synccpu_release: 603 - ret = vmw_user_dmabuf_synccpu_release(arg->handle, tfile, 604 - arg->flags); 605 - if (unlikely(ret != 0)) { 606 - DRM_ERROR("Failed synccpu release on handle 0x%08x.\n", 607 - (unsigned int) arg->handle); 608 - return ret; 609 - } 610 - break; 611 - default: 612 - DRM_ERROR("Invalid synccpu operation.\n"); 613 - return -EINVAL; 614 - } 615 - 616 - return 0; 617 - } 618 - 619 - int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data, 620 - struct drm_file *file_priv) 621 - { 622 - struct vmw_private *dev_priv = vmw_priv(dev); 623 - union drm_vmw_alloc_dmabuf_arg *arg = 624 - (union drm_vmw_alloc_dmabuf_arg *)data; 625 - struct drm_vmw_alloc_dmabuf_req *req = &arg->req; 626 - struct drm_vmw_dmabuf_rep *rep = &arg->rep; 627 - struct vmw_dma_buffer *dma_buf; 628 - uint32_t handle; 629 - int ret; 630 - 631 - ret = ttm_read_lock(&dev_priv->reservation_sem, true); 632 - if (unlikely(ret != 0)) 633 - return ret; 634 - 635 - ret = vmw_user_dmabuf_alloc(dev_priv, vmw_fpriv(file_priv)->tfile, 636 - req->size, false, &handle, &dma_buf, 637 - NULL); 638 - if (unlikely(ret != 0)) 639 - goto out_no_dmabuf; 640 - 641 - rep->handle = handle; 642 - rep->map_handle = drm_vma_node_offset_addr(&dma_buf->base.vma_node); 643 - rep->cur_gmr_id = handle; 644 - rep->cur_gmr_offset = 0; 645 - 646 - vmw_dmabuf_unreference(&dma_buf); 647 - 648 - out_no_dmabuf: 649 - ttm_read_unlock(&dev_priv->reservation_sem); 650 - 651 - return ret; 652 - } 653 - 654 - int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data, 655 - struct drm_file *file_priv) 656 - { 657 - struct drm_vmw_unref_dmabuf_arg *arg = 658 - (struct drm_vmw_unref_dmabuf_arg *)data; 659 - 660 - return ttm_ref_object_base_unref(vmw_fpriv(file_priv)->tfile, 661 - arg->handle, 662 - TTM_REF_USAGE); 663 - } 664 - 665 - int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile, 666 - uint32_t handle, struct vmw_dma_buffer **out, 667 - struct ttm_base_object **p_base) 668 - { 669 - struct vmw_user_dma_buffer *vmw_user_bo; 670 - struct ttm_base_object *base; 671 - 672 - base = ttm_base_object_lookup(tfile, handle); 673 - if (unlikely(base == NULL)) { 674 - pr_err("Invalid buffer object handle 0x%08lx\n", 675 - (unsigned long)handle); 676 - return -ESRCH; 677 - } 678 - 679 - if (unlikely(ttm_base_object_type(base) != ttm_buffer_type)) { 680 - ttm_base_object_unref(&base); 681 - pr_err("Invalid buffer object handle 0x%08lx\n", 682 - (unsigned long)handle); 683 - return -EINVAL; 684 - } 685 - 686 - vmw_user_bo = container_of(base, struct vmw_user_dma_buffer, 687 - prime.base); 688 - (void)ttm_bo_reference(&vmw_user_bo->dma.base); 689 - if (p_base) 690 - *p_base = base; 691 - else 692 - ttm_base_object_unref(&base); 693 - *out = &vmw_user_bo->dma; 694 - 695 - return 0; 696 - } 697 - 698 - int vmw_user_dmabuf_reference(struct ttm_object_file *tfile, 699 - struct vmw_dma_buffer *dma_buf, 700 - uint32_t *handle) 701 - { 702 - struct vmw_user_dma_buffer *user_bo; 703 - 704 - if (dma_buf->base.destroy != vmw_user_dmabuf_destroy) 705 - return -EINVAL; 706 - 707 - user_bo = container_of(dma_buf, struct vmw_user_dma_buffer, dma); 708 - 709 - *handle = user_bo->prime.base.hash.key; 710 - return ttm_ref_object_add(tfile, &user_bo->prime.base, 711 - TTM_REF_USAGE, NULL, false); 712 - } 713 - 714 - /** 715 - * vmw_dumb_create - Create a dumb kms buffer 716 - * 717 - * @file_priv: Pointer to a struct drm_file identifying the caller. 718 - * @dev: Pointer to the drm device. 719 - * @args: Pointer to a struct drm_mode_create_dumb structure 720 - * 721 - * This is a driver callback for the core drm create_dumb functionality. 722 - * Note that this is very similar to the vmw_dmabuf_alloc ioctl, except 723 - * that the arguments have a different format. 724 - */ 725 - int vmw_dumb_create(struct drm_file *file_priv, 726 - struct drm_device *dev, 727 - struct drm_mode_create_dumb *args) 728 - { 729 - struct vmw_private *dev_priv = vmw_priv(dev); 730 - struct vmw_dma_buffer *dma_buf; 731 - int ret; 732 - 733 - args->pitch = args->width * ((args->bpp + 7) / 8); 734 - args->size = args->pitch * args->height; 735 - 736 - ret = ttm_read_lock(&dev_priv->reservation_sem, true); 737 - if (unlikely(ret != 0)) 738 - return ret; 739 - 740 - ret = vmw_user_dmabuf_alloc(dev_priv, vmw_fpriv(file_priv)->tfile, 741 - args->size, false, &args->handle, 742 - &dma_buf, NULL); 743 - if (unlikely(ret != 0)) 744 - goto out_no_dmabuf; 745 - 746 - vmw_dmabuf_unreference(&dma_buf); 747 - out_no_dmabuf: 748 - ttm_read_unlock(&dev_priv->reservation_sem); 749 - return ret; 750 - } 751 - 752 - /** 753 - * vmw_dumb_map_offset - Return the address space offset of a dumb buffer 754 - * 755 - * @file_priv: Pointer to a struct drm_file identifying the caller. 756 - * @dev: Pointer to the drm device. 757 - * @handle: Handle identifying the dumb buffer. 758 - * @offset: The address space offset returned. 759 - * 760 - * This is a driver callback for the core drm dumb_map_offset functionality. 761 - */ 762 - int vmw_dumb_map_offset(struct drm_file *file_priv, 763 - struct drm_device *dev, uint32_t handle, 764 - uint64_t *offset) 765 - { 766 - struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; 767 - struct vmw_dma_buffer *out_buf; 768 - int ret; 769 - 770 - ret = vmw_user_dmabuf_lookup(tfile, handle, &out_buf, NULL); 771 - if (ret != 0) 772 - return -EINVAL; 773 - 774 - *offset = drm_vma_node_offset_addr(&out_buf->base.vma_node); 775 - vmw_dmabuf_unreference(&out_buf); 776 - return 0; 777 - } 778 - 779 - /** 780 - * vmw_dumb_destroy - Destroy a dumb boffer 781 - * 782 - * @file_priv: Pointer to a struct drm_file identifying the caller. 783 - * @dev: Pointer to the drm device. 784 - * @handle: Handle identifying the dumb buffer. 785 - * 786 - * This is a driver callback for the core drm dumb_destroy functionality. 787 - */ 788 - int vmw_dumb_destroy(struct drm_file *file_priv, 789 - struct drm_device *dev, 790 - uint32_t handle) 791 - { 792 - return ttm_ref_object_base_unref(vmw_fpriv(file_priv)->tfile, 793 - handle, TTM_REF_USAGE); 794 316 } 795 317 796 318 /** ··· 303 829 { 304 830 unsigned long size = 305 831 (res->backup_size + PAGE_SIZE - 1) & PAGE_MASK; 306 - struct vmw_dma_buffer *backup; 832 + struct vmw_buffer_object *backup; 307 833 int ret; 308 834 309 835 if (likely(res->backup)) { ··· 315 841 if (unlikely(!backup)) 316 842 return -ENOMEM; 317 843 318 - ret = vmw_dmabuf_init(res->dev_priv, backup, res->backup_size, 844 + ret = vmw_bo_init(res->dev_priv, backup, res->backup_size, 319 845 res->func->backup_placement, 320 846 interruptible, 321 - &vmw_dmabuf_bo_free); 847 + &vmw_bo_bo_free); 322 848 if (unlikely(ret != 0)) 323 - goto out_no_dmabuf; 849 + goto out_no_bo; 324 850 325 851 res->backup = backup; 326 852 327 - out_no_dmabuf: 853 + out_no_bo: 328 854 return ret; 329 855 } 330 856 ··· 393 919 */ 394 920 void vmw_resource_unreserve(struct vmw_resource *res, 395 921 bool switch_backup, 396 - struct vmw_dma_buffer *new_backup, 922 + struct vmw_buffer_object *new_backup, 397 923 unsigned long new_backup_offset) 398 924 { 399 925 struct vmw_private *dev_priv = res->dev_priv; ··· 405 931 if (res->backup) { 406 932 lockdep_assert_held(&res->backup->base.resv->lock.base); 407 933 list_del_init(&res->mob_head); 408 - vmw_dmabuf_unreference(&res->backup); 934 + vmw_bo_unreference(&res->backup); 409 935 } 410 936 411 937 if (new_backup) { 412 - res->backup = vmw_dmabuf_reference(new_backup); 938 + res->backup = vmw_bo_reference(new_backup); 413 939 lockdep_assert_held(&new_backup->base.resv->lock.base); 414 940 list_add_tail(&res->mob_head, &new_backup->res_list); 415 941 } else { ··· 433 959 * for a resource and in that case, allocate 434 960 * one, reserve and validate it. 435 961 * 962 + * @ticket: The ww aqcquire context to use, or NULL if trylocking. 436 963 * @res: The resource for which to allocate a backup buffer. 437 964 * @interruptible: Whether any sleeps during allocation should be 438 965 * performed while interruptible. ··· 441 966 * reserved and validated backup buffer. 442 967 */ 443 968 static int 444 - vmw_resource_check_buffer(struct vmw_resource *res, 969 + vmw_resource_check_buffer(struct ww_acquire_ctx *ticket, 970 + struct vmw_resource *res, 445 971 bool interruptible, 446 972 struct ttm_validate_buffer *val_buf) 447 973 { ··· 461 985 val_buf->bo = ttm_bo_reference(&res->backup->base); 462 986 val_buf->shared = false; 463 987 list_add_tail(&val_buf->head, &val_list); 464 - ret = ttm_eu_reserve_buffers(NULL, &val_list, interruptible, NULL); 988 + ret = ttm_eu_reserve_buffers(ticket, &val_list, interruptible, NULL); 465 989 if (unlikely(ret != 0)) 466 990 goto out_no_reserve; 467 991 ··· 479 1003 return 0; 480 1004 481 1005 out_no_validate: 482 - ttm_eu_backoff_reservation(NULL, &val_list); 1006 + ttm_eu_backoff_reservation(ticket, &val_list); 483 1007 out_no_reserve: 484 1008 ttm_bo_unref(&val_buf->bo); 485 1009 if (backup_dirty) 486 - vmw_dmabuf_unreference(&res->backup); 1010 + vmw_bo_unreference(&res->backup); 487 1011 488 1012 return ret; 489 1013 } ··· 526 1050 * vmw_resource_backoff_reservation - Unreserve and unreference a 527 1051 * backup buffer 528 1052 *. 1053 + * @ticket: The ww acquire ctx used for reservation. 529 1054 * @val_buf: Backup buffer information. 530 1055 */ 531 1056 static void 532 - vmw_resource_backoff_reservation(struct ttm_validate_buffer *val_buf) 1057 + vmw_resource_backoff_reservation(struct ww_acquire_ctx *ticket, 1058 + struct ttm_validate_buffer *val_buf) 533 1059 { 534 1060 struct list_head val_list; 535 1061 ··· 540 1062 541 1063 INIT_LIST_HEAD(&val_list); 542 1064 list_add_tail(&val_buf->head, &val_list); 543 - ttm_eu_backoff_reservation(NULL, &val_list); 1065 + ttm_eu_backoff_reservation(ticket, &val_list); 544 1066 ttm_bo_unref(&val_buf->bo); 545 1067 } 546 1068 ··· 548 1070 * vmw_resource_do_evict - Evict a resource, and transfer its data 549 1071 * to a backup buffer. 550 1072 * 1073 + * @ticket: The ww acquire ticket to use, or NULL if trylocking. 551 1074 * @res: The resource to evict. 552 1075 * @interruptible: Whether to wait interruptible. 553 1076 */ 554 - static int vmw_resource_do_evict(struct vmw_resource *res, bool interruptible) 1077 + static int vmw_resource_do_evict(struct ww_acquire_ctx *ticket, 1078 + struct vmw_resource *res, bool interruptible) 555 1079 { 556 1080 struct ttm_validate_buffer val_buf; 557 1081 const struct vmw_res_func *func = res->func; ··· 563 1083 564 1084 val_buf.bo = NULL; 565 1085 val_buf.shared = false; 566 - ret = vmw_resource_check_buffer(res, interruptible, &val_buf); 1086 + ret = vmw_resource_check_buffer(ticket, res, interruptible, &val_buf); 567 1087 if (unlikely(ret != 0)) 568 1088 return ret; 569 1089 ··· 578 1098 res->backup_dirty = true; 579 1099 res->res_dirty = false; 580 1100 out_no_unbind: 581 - vmw_resource_backoff_reservation(&val_buf); 1101 + vmw_resource_backoff_reservation(ticket, &val_buf); 582 1102 583 1103 return ret; 584 1104 } ··· 632 1152 633 1153 write_unlock(&dev_priv->resource_lock); 634 1154 635 - ret = vmw_resource_do_evict(evict_res, true); 1155 + /* Trylock backup buffers with a NULL ticket. */ 1156 + ret = vmw_resource_do_evict(NULL, evict_res, true); 636 1157 if (unlikely(ret != 0)) { 637 1158 write_lock(&dev_priv->resource_lock); 638 1159 list_add_tail(&evict_res->lru_head, lru_list); ··· 652 1171 goto out_no_validate; 653 1172 else if (!res->func->needs_backup && res->backup) { 654 1173 list_del_init(&res->mob_head); 655 - vmw_dmabuf_unreference(&res->backup); 1174 + vmw_bo_unreference(&res->backup); 656 1175 } 657 1176 658 1177 return 0; ··· 661 1180 return ret; 662 1181 } 663 1182 664 - /** 665 - * vmw_fence_single_bo - Utility function to fence a single TTM buffer 666 - * object without unreserving it. 667 - * 668 - * @bo: Pointer to the struct ttm_buffer_object to fence. 669 - * @fence: Pointer to the fence. If NULL, this function will 670 - * insert a fence into the command stream.. 671 - * 672 - * Contrary to the ttm_eu version of this function, it takes only 673 - * a single buffer object instead of a list, and it also doesn't 674 - * unreserve the buffer object, which needs to be done separately. 675 - */ 676 - void vmw_fence_single_bo(struct ttm_buffer_object *bo, 677 - struct vmw_fence_obj *fence) 678 - { 679 - struct ttm_bo_device *bdev = bo->bdev; 680 - 681 - struct vmw_private *dev_priv = 682 - container_of(bdev, struct vmw_private, bdev); 683 - 684 - if (fence == NULL) { 685 - vmw_execbuf_fence_commands(NULL, dev_priv, &fence, NULL); 686 - reservation_object_add_excl_fence(bo->resv, &fence->base); 687 - dma_fence_put(&fence->base); 688 - } else 689 - reservation_object_add_excl_fence(bo->resv, &fence->base); 690 - } 691 1183 692 1184 /** 693 - * vmw_resource_move_notify - TTM move_notify_callback 1185 + * vmw_resource_unbind_list 694 1186 * 695 - * @bo: The TTM buffer object about to move. 696 - * @mem: The struct ttm_mem_reg indicating to what memory 697 - * region the move is taking place. 1187 + * @vbo: Pointer to the current backing MOB. 698 1188 * 699 1189 * Evicts the Guest Backed hardware resource if the backup 700 1190 * buffer is being moved out of MOB memory. 701 - * Note that this function should not race with the resource 702 - * validation code as long as it accesses only members of struct 703 - * resource that remain static while bo::res is !NULL and 704 - * while we have @bo reserved. struct resource::backup is *not* a 705 - * static member. The resource validation code will take care 706 - * to set @bo::res to NULL, while having @bo reserved when the 707 - * buffer is no longer bound to the resource, so @bo:res can be 708 - * used to determine whether there is a need to unbind and whether 709 - * it is safe to unbind. 1191 + * Note that this function will not race with the resource 1192 + * validation code, since resource validation and eviction 1193 + * both require the backup buffer to be reserved. 710 1194 */ 711 - void vmw_resource_move_notify(struct ttm_buffer_object *bo, 712 - struct ttm_mem_reg *mem) 1195 + void vmw_resource_unbind_list(struct vmw_buffer_object *vbo) 713 1196 { 714 - struct vmw_dma_buffer *dma_buf; 715 1197 716 - if (mem == NULL) 717 - return; 1198 + struct vmw_resource *res, *next; 1199 + struct ttm_validate_buffer val_buf = { 1200 + .bo = &vbo->base, 1201 + .shared = false 1202 + }; 718 1203 719 - if (bo->destroy != vmw_dmabuf_bo_free && 720 - bo->destroy != vmw_user_dmabuf_destroy) 721 - return; 1204 + lockdep_assert_held(&vbo->base.resv->lock.base); 1205 + list_for_each_entry_safe(res, next, &vbo->res_list, mob_head) { 1206 + if (!res->func->unbind) 1207 + continue; 722 1208 723 - dma_buf = container_of(bo, struct vmw_dma_buffer, base); 724 - 725 - /* 726 - * Kill any cached kernel maps before move. An optimization could 727 - * be to do this iff source or destination memory type is VRAM. 728 - */ 729 - vmw_dma_buffer_unmap(dma_buf); 730 - 731 - if (mem->mem_type != VMW_PL_MOB) { 732 - struct vmw_resource *res, *n; 733 - struct ttm_validate_buffer val_buf; 734 - 735 - val_buf.bo = bo; 736 - val_buf.shared = false; 737 - 738 - list_for_each_entry_safe(res, n, &dma_buf->res_list, mob_head) { 739 - 740 - if (unlikely(res->func->unbind == NULL)) 741 - continue; 742 - 743 - (void) res->func->unbind(res, true, &val_buf); 744 - res->backup_dirty = true; 745 - res->res_dirty = false; 746 - list_del_init(&res->mob_head); 747 - } 748 - 749 - (void) ttm_bo_wait(bo, false, false); 1209 + (void) res->func->unbind(res, true, &val_buf); 1210 + res->backup_dirty = true; 1211 + res->res_dirty = false; 1212 + list_del_init(&res->mob_head); 750 1213 } 751 - } 752 1214 753 - 754 - /** 755 - * vmw_resource_swap_notify - swapout notify callback. 756 - * 757 - * @bo: The buffer object to be swapped out. 758 - */ 759 - void vmw_resource_swap_notify(struct ttm_buffer_object *bo) 760 - { 761 - if (bo->destroy != vmw_dmabuf_bo_free && 762 - bo->destroy != vmw_user_dmabuf_destroy) 763 - return; 764 - 765 - /* Kill any cached kernel maps before swapout */ 766 - vmw_dma_buffer_unmap(vmw_dma_buffer(bo)); 1215 + (void) ttm_bo_wait(&vbo->base, false, false); 767 1216 } 768 1217 769 1218 ··· 705 1294 * Read back cached states from the device if they exist. This function 706 1295 * assumings binding_mutex is held. 707 1296 */ 708 - int vmw_query_readback_all(struct vmw_dma_buffer *dx_query_mob) 1297 + int vmw_query_readback_all(struct vmw_buffer_object *dx_query_mob) 709 1298 { 710 1299 struct vmw_resource *dx_query_ctx; 711 1300 struct vmw_private *dev_priv; ··· 755 1344 void vmw_query_move_notify(struct ttm_buffer_object *bo, 756 1345 struct ttm_mem_reg *mem) 757 1346 { 758 - struct vmw_dma_buffer *dx_query_mob; 1347 + struct vmw_buffer_object *dx_query_mob; 759 1348 struct ttm_bo_device *bdev = bo->bdev; 760 1349 struct vmw_private *dev_priv; 761 1350 ··· 764 1353 765 1354 mutex_lock(&dev_priv->binding_mutex); 766 1355 767 - dx_query_mob = container_of(bo, struct vmw_dma_buffer, base); 1356 + dx_query_mob = container_of(bo, struct vmw_buffer_object, base); 768 1357 if (mem == NULL || !dx_query_mob || !dx_query_mob->dx_query_ctx) { 769 1358 mutex_unlock(&dev_priv->binding_mutex); 770 1359 return; ··· 779 1368 780 1369 /* Create a fence and attach the BO to it */ 781 1370 (void) vmw_execbuf_fence_commands(NULL, dev_priv, &fence, NULL); 782 - vmw_fence_single_bo(bo, fence); 1371 + vmw_bo_fence_single(bo, fence); 783 1372 784 1373 if (fence != NULL) 785 1374 vmw_fence_obj_unreference(&fence); ··· 816 1405 struct vmw_resource *evict_res; 817 1406 unsigned err_count = 0; 818 1407 int ret; 1408 + struct ww_acquire_ctx ticket; 819 1409 820 1410 do { 821 1411 write_lock(&dev_priv->resource_lock); ··· 830 1418 list_del_init(&evict_res->lru_head); 831 1419 write_unlock(&dev_priv->resource_lock); 832 1420 833 - ret = vmw_resource_do_evict(evict_res, false); 1421 + /* Wait lock backup buffers with a ticket. */ 1422 + ret = vmw_resource_do_evict(&ticket, evict_res, false); 834 1423 if (unlikely(ret != 0)) { 835 1424 write_lock(&dev_priv->resource_lock); 836 1425 list_add_tail(&evict_res->lru_head, lru_list); ··· 894 1481 goto out_no_reserve; 895 1482 896 1483 if (res->pin_count == 0) { 897 - struct vmw_dma_buffer *vbo = NULL; 1484 + struct vmw_buffer_object *vbo = NULL; 898 1485 899 1486 if (res->backup) { 900 1487 vbo = res->backup; ··· 952 1539 953 1540 WARN_ON(res->pin_count == 0); 954 1541 if (--res->pin_count == 0 && res->backup) { 955 - struct vmw_dma_buffer *vbo = res->backup; 1542 + struct vmw_buffer_object *vbo = res->backup; 956 1543 957 1544 (void) ttm_bo_reserve(&vbo->base, false, false, NULL); 958 1545 vmw_bo_pin_reserved(vbo, false);
+73 -65
drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c
··· 66 66 SVGAFifoCmdBlitScreenToGMRFB body; 67 67 }; 68 68 69 - struct vmw_kms_sou_dmabuf_blit { 69 + struct vmw_kms_sou_bo_blit { 70 70 uint32 header; 71 71 SVGAFifoCmdBlitGMRFBToScreen body; 72 72 }; ··· 83 83 struct vmw_display_unit base; 84 84 85 85 unsigned long buffer_size; /**< Size of allocated buffer */ 86 - struct vmw_dma_buffer *buffer; /**< Backing store buffer */ 86 + struct vmw_buffer_object *buffer; /**< Backing store buffer */ 87 87 88 88 bool defined; 89 89 }; ··· 109 109 */ 110 110 static int vmw_sou_fifo_create(struct vmw_private *dev_priv, 111 111 struct vmw_screen_object_unit *sou, 112 - uint32_t x, uint32_t y, 112 + int x, int y, 113 113 struct drm_display_mode *mode) 114 114 { 115 115 size_t fifo_size; ··· 139 139 (sou->base.unit == 0 ? SVGA_SCREEN_IS_PRIMARY : 0); 140 140 cmd->obj.size.width = mode->hdisplay; 141 141 cmd->obj.size.height = mode->vdisplay; 142 - if (sou->base.is_implicit) { 143 - cmd->obj.root.x = x; 144 - cmd->obj.root.y = y; 145 - } else { 146 - cmd->obj.root.x = sou->base.gui_x; 147 - cmd->obj.root.y = sou->base.gui_y; 148 - } 142 + cmd->obj.root.x = x; 143 + cmd->obj.root.y = y; 149 144 sou->base.set_gui_x = cmd->obj.root.x; 150 145 sou->base.set_gui_y = cmd->obj.root.y; 151 146 ··· 217 222 struct vmw_plane_state *vps; 218 223 int ret; 219 224 220 - 221 - sou = vmw_crtc_to_sou(crtc); 225 + sou = vmw_crtc_to_sou(crtc); 222 226 dev_priv = vmw_priv(crtc->dev); 223 - ps = crtc->primary->state; 224 - fb = ps->fb; 225 - vps = vmw_plane_state_to_vps(ps); 227 + ps = crtc->primary->state; 228 + fb = ps->fb; 229 + vps = vmw_plane_state_to_vps(ps); 226 230 227 231 vfb = (fb) ? vmw_framebuffer_to_vfb(fb) : NULL; 228 232 ··· 234 240 } 235 241 236 242 if (vfb) { 237 - sou->buffer = vps->dmabuf; 238 - sou->buffer_size = vps->dmabuf_size; 243 + struct drm_connector_state *conn_state; 244 + struct vmw_connector_state *vmw_conn_state; 245 + int x, y; 239 246 240 - ret = vmw_sou_fifo_create(dev_priv, sou, crtc->x, crtc->y, 241 - &crtc->mode); 247 + sou->buffer = vps->bo; 248 + sou->buffer_size = vps->bo_size; 249 + 250 + if (sou->base.is_implicit) { 251 + x = crtc->x; 252 + y = crtc->y; 253 + } else { 254 + conn_state = sou->base.connector.state; 255 + vmw_conn_state = vmw_connector_state_to_vcs(conn_state); 256 + 257 + x = vmw_conn_state->gui_x; 258 + y = vmw_conn_state->gui_y; 259 + } 260 + 261 + ret = vmw_sou_fifo_create(dev_priv, sou, x, y, &crtc->mode); 242 262 if (ret) 243 263 DRM_ERROR("Failed to define Screen Object %dx%d\n", 244 264 crtc->x, crtc->y); ··· 416 408 struct drm_crtc *crtc = plane->state->crtc ? 417 409 plane->state->crtc : old_state->crtc; 418 410 419 - if (vps->dmabuf) 420 - vmw_dmabuf_unpin(vmw_priv(crtc->dev), vps->dmabuf, false); 421 - vmw_dmabuf_unreference(&vps->dmabuf); 422 - vps->dmabuf_size = 0; 411 + if (vps->bo) 412 + vmw_bo_unpin(vmw_priv(crtc->dev), vps->bo, false); 413 + vmw_bo_unreference(&vps->bo); 414 + vps->bo_size = 0; 423 415 424 416 vmw_du_plane_cleanup_fb(plane, old_state); 425 417 } ··· 448 440 449 441 450 442 if (!new_fb) { 451 - vmw_dmabuf_unreference(&vps->dmabuf); 452 - vps->dmabuf_size = 0; 443 + vmw_bo_unreference(&vps->bo); 444 + vps->bo_size = 0; 453 445 454 446 return 0; 455 447 } ··· 457 449 size = new_state->crtc_w * new_state->crtc_h * 4; 458 450 dev_priv = vmw_priv(crtc->dev); 459 451 460 - if (vps->dmabuf) { 461 - if (vps->dmabuf_size == size) { 452 + if (vps->bo) { 453 + if (vps->bo_size == size) { 462 454 /* 463 455 * Note that this might temporarily up the pin-count 464 456 * to 2, until cleanup_fb() is called. 465 457 */ 466 - return vmw_dmabuf_pin_in_vram(dev_priv, vps->dmabuf, 458 + return vmw_bo_pin_in_vram(dev_priv, vps->bo, 467 459 true); 468 460 } 469 461 470 - vmw_dmabuf_unreference(&vps->dmabuf); 471 - vps->dmabuf_size = 0; 462 + vmw_bo_unreference(&vps->bo); 463 + vps->bo_size = 0; 472 464 } 473 465 474 - vps->dmabuf = kzalloc(sizeof(*vps->dmabuf), GFP_KERNEL); 475 - if (!vps->dmabuf) 466 + vps->bo = kzalloc(sizeof(*vps->bo), GFP_KERNEL); 467 + if (!vps->bo) 476 468 return -ENOMEM; 477 469 478 470 vmw_svga_enable(dev_priv); ··· 481 473 * resume the overlays, this is preferred to failing to alloc. 482 474 */ 483 475 vmw_overlay_pause_all(dev_priv); 484 - ret = vmw_dmabuf_init(dev_priv, vps->dmabuf, size, 476 + ret = vmw_bo_init(dev_priv, vps->bo, size, 485 477 &vmw_vram_ne_placement, 486 - false, &vmw_dmabuf_bo_free); 478 + false, &vmw_bo_bo_free); 487 479 vmw_overlay_resume_all(dev_priv); 488 480 if (ret) { 489 - vps->dmabuf = NULL; /* vmw_dmabuf_init frees on error */ 481 + vps->bo = NULL; /* vmw_bo_init frees on error */ 490 482 return ret; 491 483 } 492 484 493 - vps->dmabuf_size = size; 485 + vps->bo_size = size; 494 486 495 487 /* 496 488 * TTM already thinks the buffer is pinned, but make sure the 497 489 * pin_count is upped. 498 490 */ 499 - return vmw_dmabuf_pin_in_vram(dev_priv, vps->dmabuf, true); 491 + return vmw_bo_pin_in_vram(dev_priv, vps->bo, true); 500 492 } 501 493 502 494 ··· 520 512 vclips.w = crtc->mode.hdisplay; 521 513 vclips.h = crtc->mode.vdisplay; 522 514 523 - if (vfb->dmabuf) 524 - ret = vmw_kms_sou_do_dmabuf_dirty(dev_priv, vfb, NULL, 525 - &vclips, 1, 1, true, 526 - &fence, crtc); 515 + if (vfb->bo) 516 + ret = vmw_kms_sou_do_bo_dirty(dev_priv, vfb, NULL, 517 + &vclips, 1, 1, true, 518 + &fence, crtc); 527 519 else 528 520 ret = vmw_kms_sou_do_surface_dirty(dev_priv, vfb, NULL, 529 521 &vclips, NULL, 0, 0, ··· 783 775 return 0; 784 776 } 785 777 786 - static int do_dmabuf_define_gmrfb(struct vmw_private *dev_priv, 778 + static int do_bo_define_gmrfb(struct vmw_private *dev_priv, 787 779 struct vmw_framebuffer *framebuffer) 788 780 { 789 - struct vmw_dma_buffer *buf = 790 - container_of(framebuffer, struct vmw_framebuffer_dmabuf, 781 + struct vmw_buffer_object *buf = 782 + container_of(framebuffer, struct vmw_framebuffer_bo, 791 783 base)->buffer; 792 784 int depth = framebuffer->base.format->depth; 793 785 struct { ··· 978 970 } 979 971 980 972 /** 981 - * vmw_sou_dmabuf_fifo_commit - Callback to submit a set of readback clips. 973 + * vmw_sou_bo_fifo_commit - Callback to submit a set of readback clips. 982 974 * 983 975 * @dirty: The closure structure. 984 976 * 985 977 * Commits a previously built command buffer of readback clips. 986 978 */ 987 - static void vmw_sou_dmabuf_fifo_commit(struct vmw_kms_dirty *dirty) 979 + static void vmw_sou_bo_fifo_commit(struct vmw_kms_dirty *dirty) 988 980 { 989 981 if (!dirty->num_hits) { 990 982 vmw_fifo_commit(dirty->dev_priv, 0); ··· 992 984 } 993 985 994 986 vmw_fifo_commit(dirty->dev_priv, 995 - sizeof(struct vmw_kms_sou_dmabuf_blit) * 987 + sizeof(struct vmw_kms_sou_bo_blit) * 996 988 dirty->num_hits); 997 989 } 998 990 999 991 /** 1000 - * vmw_sou_dmabuf_clip - Callback to encode a readback cliprect. 992 + * vmw_sou_bo_clip - Callback to encode a readback cliprect. 1001 993 * 1002 994 * @dirty: The closure structure 1003 995 * 1004 996 * Encodes a BLIT_GMRFB_TO_SCREEN cliprect. 1005 997 */ 1006 - static void vmw_sou_dmabuf_clip(struct vmw_kms_dirty *dirty) 998 + static void vmw_sou_bo_clip(struct vmw_kms_dirty *dirty) 1007 999 { 1008 - struct vmw_kms_sou_dmabuf_blit *blit = dirty->cmd; 1000 + struct vmw_kms_sou_bo_blit *blit = dirty->cmd; 1009 1001 1010 1002 blit += dirty->num_hits; 1011 1003 blit->header = SVGA_CMD_BLIT_GMRFB_TO_SCREEN; ··· 1020 1012 } 1021 1013 1022 1014 /** 1023 - * vmw_kms_do_dmabuf_dirty - Dirty part of a dma-buffer backed framebuffer 1015 + * vmw_kms_do_bo_dirty - Dirty part of a buffer-object backed framebuffer 1024 1016 * 1025 1017 * @dev_priv: Pointer to the device private structure. 1026 - * @framebuffer: Pointer to the dma-buffer backed framebuffer. 1018 + * @framebuffer: Pointer to the buffer-object backed framebuffer. 1027 1019 * @clips: Array of clip rects. 1028 1020 * @vclips: Alternate array of clip rects. Either @clips or @vclips must 1029 1021 * be NULL. ··· 1033 1025 * @out_fence: If non-NULL, will return a ref-counted pointer to a 1034 1026 * struct vmw_fence_obj. The returned fence pointer may be NULL in which 1035 1027 * case the device has already synchronized. 1036 - * @crtc: If crtc is passed, perform dmabuf dirty on that crtc only. 1028 + * @crtc: If crtc is passed, perform bo dirty on that crtc only. 1037 1029 * 1038 1030 * Returns 0 on success, negative error code on failure. -ERESTARTSYS if 1039 1031 * interrupted. 1040 1032 */ 1041 - int vmw_kms_sou_do_dmabuf_dirty(struct vmw_private *dev_priv, 1033 + int vmw_kms_sou_do_bo_dirty(struct vmw_private *dev_priv, 1042 1034 struct vmw_framebuffer *framebuffer, 1043 1035 struct drm_clip_rect *clips, 1044 1036 struct drm_vmw_rect *vclips, ··· 1047 1039 struct vmw_fence_obj **out_fence, 1048 1040 struct drm_crtc *crtc) 1049 1041 { 1050 - struct vmw_dma_buffer *buf = 1051 - container_of(framebuffer, struct vmw_framebuffer_dmabuf, 1042 + struct vmw_buffer_object *buf = 1043 + container_of(framebuffer, struct vmw_framebuffer_bo, 1052 1044 base)->buffer; 1053 1045 struct vmw_kms_dirty dirty; 1054 1046 int ret; ··· 1058 1050 if (ret) 1059 1051 return ret; 1060 1052 1061 - ret = do_dmabuf_define_gmrfb(dev_priv, framebuffer); 1053 + ret = do_bo_define_gmrfb(dev_priv, framebuffer); 1062 1054 if (unlikely(ret != 0)) 1063 1055 goto out_revert; 1064 1056 1065 1057 dirty.crtc = crtc; 1066 - dirty.fifo_commit = vmw_sou_dmabuf_fifo_commit; 1067 - dirty.clip = vmw_sou_dmabuf_clip; 1068 - dirty.fifo_reserve_size = sizeof(struct vmw_kms_sou_dmabuf_blit) * 1058 + dirty.fifo_commit = vmw_sou_bo_fifo_commit; 1059 + dirty.clip = vmw_sou_bo_clip; 1060 + dirty.fifo_reserve_size = sizeof(struct vmw_kms_sou_bo_blit) * 1069 1061 num_clips; 1070 1062 ret = vmw_kms_helper_dirty(dev_priv, framebuffer, clips, vclips, 1071 1063 0, 0, num_clips, increment, &dirty); ··· 1124 1116 1125 1117 /** 1126 1118 * vmw_kms_sou_readback - Perform a readback from the screen object system to 1127 - * a dma-buffer backed framebuffer. 1119 + * a buffer-object backed framebuffer. 1128 1120 * 1129 1121 * @dev_priv: Pointer to the device private structure. 1130 1122 * @file_priv: Pointer to a struct drm_file identifying the caller. 1131 1123 * Must be set to NULL if @user_fence_rep is NULL. 1132 - * @vfb: Pointer to the dma-buffer backed framebuffer. 1124 + * @vfb: Pointer to the buffer-object backed framebuffer. 1133 1125 * @user_fence_rep: User-space provided structure for fence information. 1134 1126 * Must be set to non-NULL if @file_priv is non-NULL. 1135 1127 * @vclips: Array of clip rects. ··· 1147 1139 uint32_t num_clips, 1148 1140 struct drm_crtc *crtc) 1149 1141 { 1150 - struct vmw_dma_buffer *buf = 1151 - container_of(vfb, struct vmw_framebuffer_dmabuf, base)->buffer; 1142 + struct vmw_buffer_object *buf = 1143 + container_of(vfb, struct vmw_framebuffer_bo, base)->buffer; 1152 1144 struct vmw_kms_dirty dirty; 1153 1145 int ret; 1154 1146 ··· 1157 1149 if (ret) 1158 1150 return ret; 1159 1151 1160 - ret = do_dmabuf_define_gmrfb(dev_priv, vfb); 1152 + ret = do_bo_define_gmrfb(dev_priv, vfb); 1161 1153 if (unlikely(ret != 0)) 1162 1154 goto out_revert; 1163 1155
+13 -13
drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
··· 159 159 SVGA3dShaderType type, 160 160 uint8_t num_input_sig, 161 161 uint8_t num_output_sig, 162 - struct vmw_dma_buffer *byte_code, 162 + struct vmw_buffer_object *byte_code, 163 163 void (*res_free) (struct vmw_resource *res)) 164 164 { 165 165 struct vmw_shader *shader = vmw_res_to_shader(res); ··· 178 178 179 179 res->backup_size = size; 180 180 if (byte_code) { 181 - res->backup = vmw_dmabuf_reference(byte_code); 181 + res->backup = vmw_bo_reference(byte_code); 182 182 res->backup_offset = offset; 183 183 } 184 184 shader->size = size; ··· 306 306 (void) vmw_execbuf_fence_commands(NULL, dev_priv, 307 307 &fence, NULL); 308 308 309 - vmw_fence_single_bo(val_buf->bo, fence); 309 + vmw_bo_fence_single(val_buf->bo, fence); 310 310 311 311 if (likely(fence != NULL)) 312 312 vmw_fence_obj_unreference(&fence); ··· 537 537 538 538 (void) vmw_execbuf_fence_commands(NULL, dev_priv, 539 539 &fence, NULL); 540 - vmw_fence_single_bo(val_buf->bo, fence); 540 + vmw_bo_fence_single(val_buf->bo, fence); 541 541 542 542 if (likely(fence != NULL)) 543 543 vmw_fence_obj_unreference(&fence); ··· 723 723 } 724 724 725 725 static int vmw_user_shader_alloc(struct vmw_private *dev_priv, 726 - struct vmw_dma_buffer *buffer, 726 + struct vmw_buffer_object *buffer, 727 727 size_t shader_size, 728 728 size_t offset, 729 729 SVGA3dShaderType shader_type, ··· 801 801 802 802 803 803 static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv, 804 - struct vmw_dma_buffer *buffer, 804 + struct vmw_buffer_object *buffer, 805 805 size_t shader_size, 806 806 size_t offset, 807 807 SVGA3dShaderType shader_type) ··· 862 862 { 863 863 struct vmw_private *dev_priv = vmw_priv(dev); 864 864 struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; 865 - struct vmw_dma_buffer *buffer = NULL; 865 + struct vmw_buffer_object *buffer = NULL; 866 866 SVGA3dShaderType shader_type; 867 867 int ret; 868 868 869 869 if (buffer_handle != SVGA3D_INVALID_ID) { 870 - ret = vmw_user_dmabuf_lookup(tfile, buffer_handle, 870 + ret = vmw_user_bo_lookup(tfile, buffer_handle, 871 871 &buffer, NULL); 872 872 if (unlikely(ret != 0)) { 873 873 DRM_ERROR("Could not find buffer for shader " ··· 906 906 907 907 ttm_read_unlock(&dev_priv->reservation_sem); 908 908 out_bad_arg: 909 - vmw_dmabuf_unreference(&buffer); 909 + vmw_bo_unreference(&buffer); 910 910 return ret; 911 911 } 912 912 ··· 983 983 struct list_head *list) 984 984 { 985 985 struct ttm_operation_ctx ctx = { false, true }; 986 - struct vmw_dma_buffer *buf; 986 + struct vmw_buffer_object *buf; 987 987 struct ttm_bo_kmap_obj map; 988 988 bool is_iomem; 989 989 int ret; ··· 997 997 if (unlikely(!buf)) 998 998 return -ENOMEM; 999 999 1000 - ret = vmw_dmabuf_init(dev_priv, buf, size, &vmw_sys_ne_placement, 1001 - true, vmw_dmabuf_bo_free); 1000 + ret = vmw_bo_init(dev_priv, buf, size, &vmw_sys_ne_placement, 1001 + true, vmw_bo_bo_free); 1002 1002 if (unlikely(ret != 0)) 1003 1003 goto out; 1004 1004 ··· 1031 1031 res, list); 1032 1032 vmw_resource_unreference(&res); 1033 1033 no_reserve: 1034 - vmw_dmabuf_unreference(&buf); 1034 + vmw_bo_unreference(&buf); 1035 1035 out: 1036 1036 return ret; 1037 1037 }
+50 -43
drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c
··· 44 44 enum stdu_content_type { 45 45 SAME_AS_DISPLAY = 0, 46 46 SEPARATE_SURFACE, 47 - SEPARATE_DMA 47 + SEPARATE_BO 48 48 }; 49 49 50 50 /** ··· 58 58 * @bottom: Bottom side of bounding box. 59 59 * @fb_left: Left side of the framebuffer/content bounding box 60 60 * @fb_top: Top of the framebuffer/content bounding box 61 - * @buf: DMA buffer when DMA-ing between buffer and screen targets. 61 + * @buf: buffer object when DMA-ing between buffer and screen targets. 62 62 * @sid: Surface ID when copying between surface and screen targets. 63 63 */ 64 64 struct vmw_stdu_dirty { ··· 68 68 s32 fb_left, fb_top; 69 69 u32 pitch; 70 70 union { 71 - struct vmw_dma_buffer *buf; 71 + struct vmw_buffer_object *buf; 72 72 u32 sid; 73 73 }; 74 74 }; ··· 178 178 cmd->body.height = mode->vdisplay; 179 179 cmd->body.flags = (0 == cmd->body.stid) ? SVGA_STFLAG_PRIMARY : 0; 180 180 cmd->body.dpi = 0; 181 - if (stdu->base.is_implicit) { 182 - cmd->body.xRoot = crtc_x; 183 - cmd->body.yRoot = crtc_y; 184 - } else { 185 - cmd->body.xRoot = stdu->base.gui_x; 186 - cmd->body.yRoot = stdu->base.gui_y; 187 - } 181 + cmd->body.xRoot = crtc_x; 182 + cmd->body.yRoot = crtc_y; 183 + 188 184 stdu->base.set_gui_x = cmd->body.xRoot; 189 185 stdu->base.set_gui_y = cmd->body.yRoot; 190 186 ··· 370 374 { 371 375 struct vmw_private *dev_priv; 372 376 struct vmw_screen_target_display_unit *stdu; 373 - int ret; 377 + struct drm_connector_state *conn_state; 378 + struct vmw_connector_state *vmw_conn_state; 379 + int x, y, ret; 374 380 375 - 376 - stdu = vmw_crtc_to_stdu(crtc); 381 + stdu = vmw_crtc_to_stdu(crtc); 377 382 dev_priv = vmw_priv(crtc->dev); 383 + conn_state = stdu->base.connector.state; 384 + vmw_conn_state = vmw_connector_state_to_vcs(conn_state); 378 385 379 386 if (stdu->defined) { 380 387 ret = vmw_stdu_bind_st(dev_priv, stdu, NULL); ··· 396 397 if (!crtc->state->enable) 397 398 return; 398 399 400 + if (stdu->base.is_implicit) { 401 + x = crtc->x; 402 + y = crtc->y; 403 + } else { 404 + x = vmw_conn_state->gui_x; 405 + y = vmw_conn_state->gui_y; 406 + } 407 + 399 408 vmw_svga_enable(dev_priv); 400 - ret = vmw_stdu_define_st(dev_priv, stdu, &crtc->mode, crtc->x, crtc->y); 409 + ret = vmw_stdu_define_st(dev_priv, stdu, &crtc->mode, x, y); 401 410 402 411 if (ret) 403 412 DRM_ERROR("Failed to define Screen Target of size %dx%d\n", ··· 515 508 516 509 517 510 /** 518 - * vmw_stdu_dmabuf_clip - Callback to encode a suface DMA command cliprect 511 + * vmw_stdu_bo_clip - Callback to encode a suface DMA command cliprect 519 512 * 520 513 * @dirty: The closure structure. 521 514 * 522 515 * Encodes a surface DMA command cliprect and updates the bounding box 523 516 * for the DMA. 524 517 */ 525 - static void vmw_stdu_dmabuf_clip(struct vmw_kms_dirty *dirty) 518 + static void vmw_stdu_bo_clip(struct vmw_kms_dirty *dirty) 526 519 { 527 520 struct vmw_stdu_dirty *ddirty = 528 521 container_of(dirty, struct vmw_stdu_dirty, base); ··· 550 543 } 551 544 552 545 /** 553 - * vmw_stdu_dmabuf_fifo_commit - Callback to fill in and submit a DMA command. 546 + * vmw_stdu_bo_fifo_commit - Callback to fill in and submit a DMA command. 554 547 * 555 548 * @dirty: The closure structure. 556 549 * 557 550 * Fills in the missing fields in a DMA command, and optionally encodes 558 551 * a screen target update command, depending on transfer direction. 559 552 */ 560 - static void vmw_stdu_dmabuf_fifo_commit(struct vmw_kms_dirty *dirty) 553 + static void vmw_stdu_bo_fifo_commit(struct vmw_kms_dirty *dirty) 561 554 { 562 555 struct vmw_stdu_dirty *ddirty = 563 556 container_of(dirty, struct vmw_stdu_dirty, base); ··· 601 594 602 595 603 596 /** 604 - * vmw_stdu_dmabuf_cpu_clip - Callback to encode a CPU blit 597 + * vmw_stdu_bo_cpu_clip - Callback to encode a CPU blit 605 598 * 606 599 * @dirty: The closure structure. 607 600 * 608 601 * This function calculates the bounding box for all the incoming clips. 609 602 */ 610 - static void vmw_stdu_dmabuf_cpu_clip(struct vmw_kms_dirty *dirty) 603 + static void vmw_stdu_bo_cpu_clip(struct vmw_kms_dirty *dirty) 611 604 { 612 605 struct vmw_stdu_dirty *ddirty = 613 606 container_of(dirty, struct vmw_stdu_dirty, base); ··· 631 624 632 625 633 626 /** 634 - * vmw_stdu_dmabuf_cpu_commit - Callback to do a CPU blit from DMAbuf 627 + * vmw_stdu_bo_cpu_commit - Callback to do a CPU blit from buffer object 635 628 * 636 629 * @dirty: The closure structure. 637 630 * 638 631 * For the special case when we cannot create a proxy surface in a 639 632 * 2D VM, we have to do a CPU blit ourselves. 640 633 */ 641 - static void vmw_stdu_dmabuf_cpu_commit(struct vmw_kms_dirty *dirty) 634 + static void vmw_stdu_bo_cpu_commit(struct vmw_kms_dirty *dirty) 642 635 { 643 636 struct vmw_stdu_dirty *ddirty = 644 637 container_of(dirty, struct vmw_stdu_dirty, base); ··· 659 652 if (width == 0 || height == 0) 660 653 return; 661 654 662 - /* Assume we are blitting from Guest (dmabuf) to Host (display_srf) */ 655 + /* Assume we are blitting from Guest (bo) to Host (display_srf) */ 663 656 dst_pitch = stdu->display_srf->base_size.width * stdu->cpp; 664 657 dst_bo = &stdu->display_srf->res.backup->base; 665 658 dst_offset = ddirty->top * dst_pitch + ddirty->left * stdu->cpp; ··· 719 712 } 720 713 721 714 /** 722 - * vmw_kms_stdu_dma - Perform a DMA transfer between a dma-buffer backed 715 + * vmw_kms_stdu_dma - Perform a DMA transfer between a buffer-object backed 723 716 * framebuffer and the screen target system. 724 717 * 725 718 * @dev_priv: Pointer to the device private structure. 726 719 * @file_priv: Pointer to a struct drm-file identifying the caller. May be 727 720 * set to NULL, but then @user_fence_rep must also be set to NULL. 728 - * @vfb: Pointer to the dma-buffer backed framebuffer. 721 + * @vfb: Pointer to the buffer-object backed framebuffer. 729 722 * @clips: Array of clip rects. Either @clips or @vclips must be NULL. 730 723 * @vclips: Alternate array of clip rects. Either @clips or @vclips must 731 724 * be NULL. ··· 754 747 bool interruptible, 755 748 struct drm_crtc *crtc) 756 749 { 757 - struct vmw_dma_buffer *buf = 758 - container_of(vfb, struct vmw_framebuffer_dmabuf, base)->buffer; 750 + struct vmw_buffer_object *buf = 751 + container_of(vfb, struct vmw_framebuffer_bo, base)->buffer; 759 752 struct vmw_stdu_dirty ddirty; 760 753 int ret; 761 754 bool cpu_blit = !(dev_priv->capabilities & SVGA_CAP_3D); ··· 777 770 ddirty.fb_left = ddirty.fb_top = S32_MAX; 778 771 ddirty.pitch = vfb->base.pitches[0]; 779 772 ddirty.buf = buf; 780 - ddirty.base.fifo_commit = vmw_stdu_dmabuf_fifo_commit; 781 - ddirty.base.clip = vmw_stdu_dmabuf_clip; 773 + ddirty.base.fifo_commit = vmw_stdu_bo_fifo_commit; 774 + ddirty.base.clip = vmw_stdu_bo_clip; 782 775 ddirty.base.fifo_reserve_size = sizeof(struct vmw_stdu_dma) + 783 776 num_clips * sizeof(SVGA3dCopyBox) + 784 777 sizeof(SVGA3dCmdSurfaceDMASuffix); ··· 787 780 788 781 789 782 if (cpu_blit) { 790 - ddirty.base.fifo_commit = vmw_stdu_dmabuf_cpu_commit; 791 - ddirty.base.clip = vmw_stdu_dmabuf_cpu_clip; 783 + ddirty.base.fifo_commit = vmw_stdu_bo_cpu_commit; 784 + ddirty.base.clip = vmw_stdu_bo_cpu_clip; 792 785 ddirty.base.fifo_reserve_size = 0; 793 786 } 794 787 ··· 934 927 if (ret) 935 928 return ret; 936 929 937 - if (vfbs->is_dmabuf_proxy) { 930 + if (vfbs->is_bo_proxy) { 938 931 ret = vmw_kms_update_proxy(srf, clips, num_clips, inc); 939 932 if (ret) 940 933 goto out_finish; ··· 1082 1075 * @new_state: info on the new plane state, including the FB 1083 1076 * 1084 1077 * This function allocates a new display surface if the content is 1085 - * backed by a DMA. The display surface is pinned here, and it'll 1078 + * backed by a buffer object. The display surface is pinned here, and it'll 1086 1079 * be unpinned in .cleanup_fb() 1087 1080 * 1088 1081 * Returns 0 on success ··· 1112 1105 } 1113 1106 1114 1107 vfb = vmw_framebuffer_to_vfb(new_fb); 1115 - new_vfbs = (vfb->dmabuf) ? NULL : vmw_framebuffer_to_vfbs(new_fb); 1108 + new_vfbs = (vfb->bo) ? NULL : vmw_framebuffer_to_vfbs(new_fb); 1116 1109 1117 1110 if (new_vfbs && new_vfbs->surface->base_size.width == hdisplay && 1118 1111 new_vfbs->surface->base_size.height == vdisplay) 1119 1112 new_content_type = SAME_AS_DISPLAY; 1120 - else if (vfb->dmabuf) 1121 - new_content_type = SEPARATE_DMA; 1113 + else if (vfb->bo) 1114 + new_content_type = SEPARATE_BO; 1122 1115 else 1123 1116 new_content_type = SEPARATE_SURFACE; 1124 1117 ··· 1131 1124 display_base_size.depth = 1; 1132 1125 1133 1126 /* 1134 - * If content buffer is a DMA buf, then we have to construct 1135 - * surface info 1127 + * If content buffer is a buffer object, then we have to 1128 + * construct surface info 1136 1129 */ 1137 - if (new_content_type == SEPARATE_DMA) { 1130 + if (new_content_type == SEPARATE_BO) { 1138 1131 1139 1132 switch (new_fb->format->cpp[0]*8) { 1140 1133 case 32: ··· 1219 1212 vps->content_fb_type = new_content_type; 1220 1213 1221 1214 /* 1222 - * This should only happen if the DMA buf is too large to create a 1215 + * This should only happen if the buffer object is too large to create a 1223 1216 * proxy surface for. 1224 - * If we are a 2D VM with a DMA buffer then we have to use CPU blit 1217 + * If we are a 2D VM with a buffer object then we have to use CPU blit 1225 1218 * so cache these mappings 1226 1219 */ 1227 - if (vps->content_fb_type == SEPARATE_DMA && 1220 + if (vps->content_fb_type == SEPARATE_BO && 1228 1221 !(dev_priv->capabilities & SVGA_CAP_3D)) 1229 1222 vps->cpp = new_fb->pitches[0] / new_fb->width; 1230 1223 ··· 1283 1276 if (ret) 1284 1277 DRM_ERROR("Failed to bind surface to STDU.\n"); 1285 1278 1286 - if (vfb->dmabuf) 1279 + if (vfb->bo) 1287 1280 ret = vmw_kms_stdu_dma(dev_priv, NULL, vfb, NULL, NULL, 1288 1281 &vclips, 1, 1, true, false, 1289 1282 crtc);
+22 -23
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
··· 468 468 (void) vmw_execbuf_fence_commands(NULL, dev_priv, 469 469 &fence, NULL); 470 470 471 - vmw_fence_single_bo(val_buf->bo, fence); 471 + vmw_bo_fence_single(val_buf->bo, fence); 472 472 473 473 if (likely(fence != NULL)) 474 474 vmw_fence_obj_unreference(&fence); ··· 842 842 if (dev_priv->has_mob && req->shareable) { 843 843 uint32_t backup_handle; 844 844 845 - ret = vmw_user_dmabuf_alloc(dev_priv, tfile, 846 - res->backup_size, 847 - true, 848 - &backup_handle, 849 - &res->backup, 850 - &user_srf->backup_base); 845 + ret = vmw_user_bo_alloc(dev_priv, tfile, 846 + res->backup_size, 847 + true, 848 + &backup_handle, 849 + &res->backup, 850 + &user_srf->backup_base); 851 851 if (unlikely(ret != 0)) { 852 852 vmw_resource_unreference(&res); 853 853 goto out_unlock; ··· 1072 1072 cmd2->header.size = cmd_len; 1073 1073 cmd2->body.sid = srf->res.id; 1074 1074 cmd2->body.surfaceFlags = srf->flags; 1075 - cmd2->body.format = cpu_to_le32(srf->format); 1075 + cmd2->body.format = srf->format; 1076 1076 cmd2->body.numMipLevels = srf->mip_levels[0]; 1077 1077 cmd2->body.multisampleCount = srf->multisample_count; 1078 1078 cmd2->body.autogenFilter = srf->autogen_filter; ··· 1085 1085 cmd->header.size = cmd_len; 1086 1086 cmd->body.sid = srf->res.id; 1087 1087 cmd->body.surfaceFlags = srf->flags; 1088 - cmd->body.format = cpu_to_le32(srf->format); 1088 + cmd->body.format = srf->format; 1089 1089 cmd->body.numMipLevels = srf->mip_levels[0]; 1090 1090 cmd->body.multisampleCount = srf->multisample_count; 1091 1091 cmd->body.autogenFilter = srf->autogen_filter; ··· 1210 1210 (void) vmw_execbuf_fence_commands(NULL, dev_priv, 1211 1211 &fence, NULL); 1212 1212 1213 - vmw_fence_single_bo(val_buf->bo, fence); 1213 + vmw_bo_fence_single(val_buf->bo, fence); 1214 1214 1215 1215 if (likely(fence != NULL)) 1216 1216 vmw_fence_obj_unreference(&fence); ··· 1317 1317 1318 1318 1319 1319 if (req->buffer_handle != SVGA3D_INVALID_ID) { 1320 - ret = vmw_user_dmabuf_lookup(tfile, req->buffer_handle, 1321 - &res->backup, 1322 - &user_srf->backup_base); 1320 + ret = vmw_user_bo_lookup(tfile, req->buffer_handle, 1321 + &res->backup, 1322 + &user_srf->backup_base); 1323 1323 if (ret == 0) { 1324 1324 if (res->backup->base.num_pages * PAGE_SIZE < 1325 1325 res->backup_size) { 1326 1326 DRM_ERROR("Surface backup buffer is too small.\n"); 1327 - vmw_dmabuf_unreference(&res->backup); 1327 + vmw_bo_unreference(&res->backup); 1328 1328 ret = -EINVAL; 1329 1329 goto out_unlock; 1330 1330 } else { ··· 1332 1332 } 1333 1333 } 1334 1334 } else if (req->drm_surface_flags & drm_vmw_surface_flag_create_buffer) 1335 - ret = vmw_user_dmabuf_alloc(dev_priv, tfile, 1336 - res->backup_size, 1337 - req->drm_surface_flags & 1338 - drm_vmw_surface_flag_shareable, 1339 - &backup_handle, 1340 - &res->backup, 1341 - &user_srf->backup_base); 1335 + ret = vmw_user_bo_alloc(dev_priv, tfile, 1336 + res->backup_size, 1337 + req->drm_surface_flags & 1338 + drm_vmw_surface_flag_shareable, 1339 + &backup_handle, 1340 + &res->backup, 1341 + &user_srf->backup_base); 1342 1342 1343 1343 if (unlikely(ret != 0)) { 1344 1344 vmw_resource_unreference(&res); ··· 1414 1414 } 1415 1415 1416 1416 mutex_lock(&dev_priv->cmdbuf_mutex); /* Protect res->backup */ 1417 - ret = vmw_user_dmabuf_reference(tfile, srf->res.backup, 1418 - &backup_handle); 1417 + ret = vmw_user_bo_reference(tfile, srf->res.backup, &backup_handle); 1419 1418 mutex_unlock(&dev_priv->cmdbuf_mutex); 1420 1419 1421 1420 if (unlikely(ret != 0)) {
+22 -39
include/uapi/drm/vmwgfx_drm.h
··· 40 40 41 41 #define DRM_VMW_GET_PARAM 0 42 42 #define DRM_VMW_ALLOC_DMABUF 1 43 + #define DRM_VMW_ALLOC_BO 1 43 44 #define DRM_VMW_UNREF_DMABUF 2 44 45 #define DRM_VMW_HANDLE_CLOSE 2 45 46 #define DRM_VMW_CURSOR_BYPASS 3 ··· 357 356 358 357 /*************************************************************************/ 359 358 /** 360 - * DRM_VMW_ALLOC_DMABUF 359 + * DRM_VMW_ALLOC_BO 361 360 * 362 - * Allocate a DMA buffer that is visible also to the host. 361 + * Allocate a buffer object that is visible also to the host. 363 362 * NOTE: The buffer is 364 363 * identified by a handle and an offset, which are private to the guest, but 365 364 * useable in the command stream. The guest kernel may translate these ··· 367 366 * be zero at all times, or it may disappear from the interface before it is 368 367 * fixed. 369 368 * 370 - * The DMA buffer may stay user-space mapped in the guest at all times, 369 + * The buffer object may stay user-space mapped in the guest at all times, 371 370 * and is thus suitable for sub-allocation. 372 371 * 373 - * DMA buffers are mapped using the mmap() syscall on the drm device. 372 + * Buffer objects are mapped using the mmap() syscall on the drm device. 374 373 */ 375 374 376 375 /** 377 - * struct drm_vmw_alloc_dmabuf_req 376 + * struct drm_vmw_alloc_bo_req 378 377 * 379 378 * @size: Required minimum size of the buffer. 380 379 * 381 - * Input data to the DRM_VMW_ALLOC_DMABUF Ioctl. 380 + * Input data to the DRM_VMW_ALLOC_BO Ioctl. 382 381 */ 383 382 384 - struct drm_vmw_alloc_dmabuf_req { 383 + struct drm_vmw_alloc_bo_req { 385 384 __u32 size; 386 385 __u32 pad64; 387 386 }; 387 + #define drm_vmw_alloc_dmabuf_req drm_vmw_alloc_bo_req 388 388 389 389 /** 390 - * struct drm_vmw_dmabuf_rep 390 + * struct drm_vmw_bo_rep 391 391 * 392 392 * @map_handle: Offset to use in the mmap() call used to map the buffer. 393 393 * @handle: Handle unique to this buffer. Used for unreferencing. ··· 397 395 * @cur_gmr_offset: Offset to use in the command stream when this buffer is 398 396 * referenced. See note above. 399 397 * 400 - * Output data from the DRM_VMW_ALLOC_DMABUF Ioctl. 398 + * Output data from the DRM_VMW_ALLOC_BO Ioctl. 401 399 */ 402 400 403 - struct drm_vmw_dmabuf_rep { 401 + struct drm_vmw_bo_rep { 404 402 __u64 map_handle; 405 403 __u32 handle; 406 404 __u32 cur_gmr_id; 407 405 __u32 cur_gmr_offset; 408 406 __u32 pad64; 409 407 }; 408 + #define drm_vmw_dmabuf_rep drm_vmw_bo_rep 410 409 411 410 /** 412 - * union drm_vmw_dmabuf_arg 411 + * union drm_vmw_alloc_bo_arg 413 412 * 414 413 * @req: Input data as described above. 415 414 * @rep: Output data as described above. 416 415 * 417 - * Argument to the DRM_VMW_ALLOC_DMABUF Ioctl. 416 + * Argument to the DRM_VMW_ALLOC_BO Ioctl. 418 417 */ 419 418 420 - union drm_vmw_alloc_dmabuf_arg { 421 - struct drm_vmw_alloc_dmabuf_req req; 422 - struct drm_vmw_dmabuf_rep rep; 419 + union drm_vmw_alloc_bo_arg { 420 + struct drm_vmw_alloc_bo_req req; 421 + struct drm_vmw_bo_rep rep; 423 422 }; 424 - 425 - /*************************************************************************/ 426 - /** 427 - * DRM_VMW_UNREF_DMABUF - Free a DMA buffer. 428 - * 429 - */ 430 - 431 - /** 432 - * struct drm_vmw_unref_dmabuf_arg 433 - * 434 - * @handle: Handle indicating what buffer to free. Obtained from the 435 - * DRM_VMW_ALLOC_DMABUF Ioctl. 436 - * 437 - * Argument to the DRM_VMW_UNREF_DMABUF Ioctl. 438 - */ 439 - 440 - struct drm_vmw_unref_dmabuf_arg { 441 - __u32 handle; 442 - __u32 pad64; 443 - }; 423 + #define drm_vmw_alloc_dmabuf_arg drm_vmw_alloc_bo_arg 444 424 445 425 /*************************************************************************/ 446 426 /** ··· 1087 1103 * DRM_VMW_HANDLE_CLOSE - Close a user-space handle and release its 1088 1104 * underlying resource. 1089 1105 * 1090 - * Note that this ioctl is overlaid on the DRM_VMW_UNREF_DMABUF Ioctl. 1091 - * The ioctl arguments therefore need to be identical in layout. 1092 - * 1106 + * Note that this ioctl is overlaid on the deprecated DRM_VMW_UNREF_DMABUF 1107 + * Ioctl. 1093 1108 */ 1094 1109 1095 1110 /** ··· 1102 1119 __u32 handle; 1103 1120 __u32 pad64; 1104 1121 }; 1105 - 1122 + #define drm_vmw_unref_dmabuf_arg drm_vmw_handle_close_arg 1106 1123 1107 1124 #if defined(__cplusplus) 1108 1125 }