ttm_bo_util.c (247835) | ttm_bo_util.c (262988) |
---|---|
1/************************************************************************** 2 * 3 * Copyright (c) 2007-2009 VMware, Inc., Palo Alto, CA., USA 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including --- 15 unchanged lines hidden (view full) --- 24 * USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27/* 28 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com> 29 */ 30 31#include <sys/cdefs.h> | 1/************************************************************************** 2 * 3 * Copyright (c) 2007-2009 VMware, Inc., Palo Alto, CA., USA 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including --- 15 unchanged lines hidden (view full) --- 24 * USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27/* 28 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com> 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/sys/dev/drm2/ttm/ttm_bo_util.c 247835 2013-03-05 09:49:34Z kib $"); | 32__FBSDID("$FreeBSD: stable/9/sys/dev/drm2/ttm/ttm_bo_util.c 262988 2014-03-10 23:16:19Z dumbbell $"); |
33 34#include <dev/drm2/drmP.h> 35#include <dev/drm2/ttm/ttm_bo_driver.h> 36#include <dev/drm2/ttm/ttm_placement.h> 37#include <sys/sf_buf.h> 38 39void ttm_bo_free_old_node(struct ttm_buffer_object *bo) 40{ --- 275 unchanged lines hidden (view full) --- 316 317 if (old_iomap == NULL && new_iomap == NULL) 318 goto out2; 319 if (old_iomap == NULL && ttm == NULL) 320 goto out2; 321 322 if (ttm->state == tt_unpopulated) { 323 ret = ttm->bdev->driver->ttm_tt_populate(ttm); | 33 34#include <dev/drm2/drmP.h> 35#include <dev/drm2/ttm/ttm_bo_driver.h> 36#include <dev/drm2/ttm/ttm_placement.h> 37#include <sys/sf_buf.h> 38 39void ttm_bo_free_old_node(struct ttm_buffer_object *bo) 40{ --- 275 unchanged lines hidden (view full) --- 316 317 if (old_iomap == NULL && new_iomap == NULL) 318 goto out2; 319 if (old_iomap == NULL && ttm == NULL) 320 goto out2; 321 322 if (ttm->state == tt_unpopulated) { 323 ret = ttm->bdev->driver->ttm_tt_populate(ttm); |
324 if (ret) | 324 if (ret) { 325 /* if we fail here don't nuke the mm node 326 * as the bo still owns it */ 327 old_copy.mm_node = NULL; |
325 goto out1; | 328 goto out1; |
329 } |
|
326 } 327 328 add = 0; 329 dir = 1; 330 331 if ((old_mem->mem_type == new_mem->mem_type) && 332 (new_mem->start < old_mem->start + old_mem->size)) { 333 dir = -1; --- 7 unchanged lines hidden (view full) --- 341 ret = ttm_copy_ttm_io_page(ttm, new_iomap, page, 342 prot); 343 } else if (new_iomap == NULL) { 344 vm_memattr_t prot = ttm_io_prot(new_mem->placement); 345 ret = ttm_copy_io_ttm_page(ttm, old_iomap, page, 346 prot); 347 } else 348 ret = ttm_copy_io_page(new_iomap, old_iomap, page); | 330 } 331 332 add = 0; 333 dir = 1; 334 335 if ((old_mem->mem_type == new_mem->mem_type) && 336 (new_mem->start < old_mem->start + old_mem->size)) { 337 dir = -1; --- 7 unchanged lines hidden (view full) --- 345 ret = ttm_copy_ttm_io_page(ttm, new_iomap, page, 346 prot); 347 } else if (new_iomap == NULL) { 348 vm_memattr_t prot = ttm_io_prot(new_mem->placement); 349 ret = ttm_copy_io_ttm_page(ttm, old_iomap, page, 350 prot); 351 } else 352 ret = ttm_copy_io_page(new_iomap, old_iomap, page); |
349 if (ret) | 353 if (ret) { 354 /* failing here, means keep old copy as-is */ 355 old_copy.mm_node = NULL; |
350 goto out1; | 356 goto out1; |
357 } |
|
351 } 352 mb(); 353out2: 354 old_copy = *old_mem; 355 *old_mem = *new_mem; 356 new_mem->mm_node = NULL; 357 358 if ((man->flags & TTM_MEMTYPE_FLAG_FIXED) && (ttm != NULL)) { --- 27 unchanged lines hidden (view full) --- 386 * This is a utility function that may be called after an accelerated move 387 * has been scheduled. A new buffer object is created as a placeholder for 388 * the old data while it's being copied. When that buffer object is idle, 389 * it can be destroyed, releasing the space of the old placement. 390 * Returns: 391 * !0: Failure. 392 */ 393 | 358 } 359 mb(); 360out2: 361 old_copy = *old_mem; 362 *old_mem = *new_mem; 363 new_mem->mm_node = NULL; 364 365 if ((man->flags & TTM_MEMTYPE_FLAG_FIXED) && (ttm != NULL)) { --- 27 unchanged lines hidden (view full) --- 393 * This is a utility function that may be called after an accelerated move 394 * has been scheduled. A new buffer object is created as a placeholder for 395 * the old data while it's being copied. When that buffer object is idle, 396 * it can be destroyed, releasing the space of the old placement. 397 * Returns: 398 * !0: Failure. 399 */ 400 |
394static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo, 395 struct ttm_buffer_object **new_obj) | 401static int 402ttm_buffer_object_transfer(struct ttm_buffer_object *bo, 403 struct ttm_buffer_object **new_obj) |
396{ 397 struct ttm_buffer_object *fbo; 398 struct ttm_bo_device *bdev = bo->bdev; 399 struct ttm_bo_driver *driver = bdev->driver; 400 | 404{ 405 struct ttm_buffer_object *fbo; 406 struct ttm_bo_device *bdev = bo->bdev; 407 struct ttm_bo_driver *driver = bdev->driver; 408 |
401 fbo = malloc(sizeof(*fbo), M_TTM_TRANSF_OBJ, M_ZERO | M_WAITOK); | 409 fbo = malloc(sizeof(*fbo), M_TTM_TRANSF_OBJ, M_WAITOK); |
402 *fbo = *bo; 403 404 /** 405 * Fix up members that we shouldn't copy directly: 406 * TODO: Explicit member copy would probably be better here. 407 */ 408 409 INIT_LIST_HEAD(&fbo->ddestroy); 410 INIT_LIST_HEAD(&fbo->lru); 411 INIT_LIST_HEAD(&fbo->swap); 412 INIT_LIST_HEAD(&fbo->io_reserve_lru); 413 fbo->vm_node = NULL; 414 atomic_set(&fbo->cpu_writers, 0); 415 | 410 *fbo = *bo; 411 412 /** 413 * Fix up members that we shouldn't copy directly: 414 * TODO: Explicit member copy would probably be better here. 415 */ 416 417 INIT_LIST_HEAD(&fbo->ddestroy); 418 INIT_LIST_HEAD(&fbo->lru); 419 INIT_LIST_HEAD(&fbo->swap); 420 INIT_LIST_HEAD(&fbo->io_reserve_lru); 421 fbo->vm_node = NULL; 422 atomic_set(&fbo->cpu_writers, 0); 423 |
416 fbo->sync_obj = driver->sync_obj_ref(bo->sync_obj); | 424 mtx_lock(&bdev->fence_lock); 425 if (bo->sync_obj) 426 fbo->sync_obj = driver->sync_obj_ref(bo->sync_obj); 427 else 428 fbo->sync_obj = NULL; 429 mtx_unlock(&bdev->fence_lock); |
417 refcount_init(&fbo->list_kref, 1); 418 refcount_init(&fbo->kref, 1); 419 fbo->destroy = &ttm_transfered_destroy; 420 fbo->acc_size = 0; 421 422 *new_obj = fbo; 423 return 0; 424} --- 195 unchanged lines hidden (view full) --- 620 /** 621 * This should help pipeline ordinary buffer moves. 622 * 623 * Hang old buffer memory on a new buffer object, 624 * and leave it to be released when the GPU 625 * operation has completed. 626 */ 627 | 430 refcount_init(&fbo->list_kref, 1); 431 refcount_init(&fbo->kref, 1); 432 fbo->destroy = &ttm_transfered_destroy; 433 fbo->acc_size = 0; 434 435 *new_obj = fbo; 436 return 0; 437} --- 195 unchanged lines hidden (view full) --- 633 /** 634 * This should help pipeline ordinary buffer moves. 635 * 636 * Hang old buffer memory on a new buffer object, 637 * and leave it to be released when the GPU 638 * operation has completed. 639 */ 640 |
628 set_bit(TTM_BO_PRIV_FLAG_MOVING, &bo->priv_flags); 629 630 /* ttm_buffer_object_transfer accesses bo->sync_obj */ 631 ret = ttm_buffer_object_transfer(bo, &ghost_obj); | 641 atomic_set_long(&bo->priv_flags, 642 1UL << TTM_BO_PRIV_FLAG_MOVING); |
632 mtx_unlock(&bdev->fence_lock); 633 if (tmp_obj) 634 driver->sync_obj_unref(&tmp_obj); 635 | 643 mtx_unlock(&bdev->fence_lock); 644 if (tmp_obj) 645 driver->sync_obj_unref(&tmp_obj); 646 |
647 ret = ttm_buffer_object_transfer(bo, &ghost_obj); |
|
636 if (ret) 637 return ret; 638 639 /** 640 * If we're not moving to fixed memory, the TTM object 641 * needs to stay alive. Otherwhise hang it on the ghost 642 * bo to be unbound and destroyed. 643 */ --- 15 unchanged lines hidden --- | 648 if (ret) 649 return ret; 650 651 /** 652 * If we're not moving to fixed memory, the TTM object 653 * needs to stay alive. Otherwhise hang it on the ghost 654 * bo to be unbound and destroyed. 655 */ --- 15 unchanged lines hidden --- |