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

drm: init TTM dev_mapping in ttm_bo_device_init()

With dev->anon_inode we have a global address_space ready for operation
right from the beginning. Therefore, there is no need to do a delayed
setup with TTM. Instead, set dev_mapping during initialization in
ttm_bo_device_init() and remove any "if (dev_mapping)" conditions.

Cc: Dave Airlie <airlied@redhat.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Cc: Alex Deucher <alexdeucher@gmail.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>

+31 -22
+3 -2
drivers/gpu/drm/ast/ast_ttm.c
··· 259 259 260 260 ret = ttm_bo_device_init(&ast->ttm.bdev, 261 261 ast->ttm.bo_global_ref.ref.object, 262 - &ast_bo_driver, DRM_FILE_PAGE_OFFSET, 262 + &ast_bo_driver, 263 + dev->anon_inode->i_mapping, 264 + DRM_FILE_PAGE_OFFSET, 263 265 true); 264 266 if (ret) { 265 267 DRM_ERROR("Error initialising bo driver; %d\n", ret); ··· 326 324 } 327 325 328 326 astbo->bo.bdev = &ast->ttm.bdev; 329 - astbo->bo.bdev->dev_mapping = dev->anon_inode->i_mapping; 330 327 331 328 ast_ttm_placement(astbo, TTM_PL_FLAG_VRAM | TTM_PL_FLAG_SYSTEM); 332 329
+3 -1
drivers/gpu/drm/bochs/bochs_mm.c
··· 225 225 226 226 ret = ttm_bo_device_init(&bochs->ttm.bdev, 227 227 bochs->ttm.bo_global_ref.ref.object, 228 - &bochs_bo_driver, DRM_FILE_PAGE_OFFSET, 228 + &bochs_bo_driver, 229 + bochs->dev->anon_inode->i_mapping, 230 + DRM_FILE_PAGE_OFFSET, 229 231 true); 230 232 if (ret) { 231 233 DRM_ERROR("Error initialising bo driver; %d\n", ret);
+3 -2
drivers/gpu/drm/cirrus/cirrus_ttm.c
··· 259 259 260 260 ret = ttm_bo_device_init(&cirrus->ttm.bdev, 261 261 cirrus->ttm.bo_global_ref.ref.object, 262 - &cirrus_bo_driver, DRM_FILE_PAGE_OFFSET, 262 + &cirrus_bo_driver, 263 + dev->anon_inode->i_mapping, 264 + DRM_FILE_PAGE_OFFSET, 263 265 true); 264 266 if (ret) { 265 267 DRM_ERROR("Error initialising bo driver; %d\n", ret); ··· 331 329 } 332 330 333 331 cirrusbo->bo.bdev = &cirrus->ttm.bdev; 334 - cirrusbo->bo.bdev->dev_mapping = dev->anon_inode->i_mapping; 335 332 336 333 cirrus_ttm_placement(cirrusbo, TTM_PL_FLAG_VRAM | TTM_PL_FLAG_SYSTEM); 337 334
+3 -2
drivers/gpu/drm/mgag200/mgag200_ttm.c
··· 259 259 260 260 ret = ttm_bo_device_init(&mdev->ttm.bdev, 261 261 mdev->ttm.bo_global_ref.ref.object, 262 - &mgag200_bo_driver, DRM_FILE_PAGE_OFFSET, 262 + &mgag200_bo_driver, 263 + dev->anon_inode->i_mapping, 264 + DRM_FILE_PAGE_OFFSET, 263 265 true); 264 266 if (ret) { 265 267 DRM_ERROR("Error initialising bo driver; %d\n", ret); ··· 326 324 } 327 325 328 326 mgabo->bo.bdev = &mdev->ttm.bdev; 329 - mgabo->bo.bdev->dev_mapping = dev->anon_inode->i_mapping; 330 327 331 328 mgag200_ttm_placement(mgabo, TTM_PL_FLAG_VRAM | TTM_PL_FLAG_SYSTEM); 332 329
-2
drivers/gpu/drm/nouveau/nouveau_gem.c
··· 228 228 struct nouveau_bo *nvbo = NULL; 229 229 int ret = 0; 230 230 231 - drm->ttm.bdev.dev_mapping = drm->dev->anon_inode->i_mapping; 232 - 233 231 if (!pfb->memtype_valid(pfb, req->info.tile_flags)) { 234 232 NV_ERROR(cli, "bad page flags: 0x%08x\n", req->info.tile_flags); 235 233 return -EINVAL;
+3 -1
drivers/gpu/drm/nouveau/nouveau_ttm.c
··· 376 376 377 377 ret = ttm_bo_device_init(&drm->ttm.bdev, 378 378 drm->ttm.bo_global_ref.ref.object, 379 - &nouveau_bo_driver, DRM_FILE_PAGE_OFFSET, 379 + &nouveau_bo_driver, 380 + dev->anon_inode->i_mapping, 381 + DRM_FILE_PAGE_OFFSET, 380 382 bits <= 32 ? true : false); 381 383 if (ret) { 382 384 NV_ERROR(drm, "error initialising bo driver, %d\n", ret);
-1
drivers/gpu/drm/qxl/qxl_object.c
··· 82 82 enum ttm_bo_type type; 83 83 int r; 84 84 85 - qdev->mman.bdev.dev_mapping = qdev->ddev->anon_inode->i_mapping; 86 85 if (kernel) 87 86 type = ttm_bo_type_kernel; 88 87 else
+3 -2
drivers/gpu/drm/qxl/qxl_ttm.c
··· 493 493 /* No others user of address space so set it to 0 */ 494 494 r = ttm_bo_device_init(&qdev->mman.bdev, 495 495 qdev->mman.bo_global_ref.ref.object, 496 - &qxl_bo_driver, DRM_FILE_PAGE_OFFSET, 0); 496 + &qxl_bo_driver, 497 + qdev->ddev->anon_inode->i_mapping, 498 + DRM_FILE_PAGE_OFFSET, 0); 497 499 if (r) { 498 500 DRM_ERROR("failed initializing buffer object driver(%d).\n", r); 499 501 return r; ··· 520 518 ((unsigned)num_io_pages * PAGE_SIZE) / (1024 * 1024)); 521 519 DRM_INFO("qxl: %uM of Surface memory size\n", 522 520 (unsigned)qdev->surfaceram_size / (1024 * 1024)); 523 - qdev->mman.bdev.dev_mapping = qdev->ddev->anon_inode->i_mapping; 524 521 r = qxl_ttm_debugfs_init(qdev); 525 522 if (r) { 526 523 DRM_ERROR("Failed to init debugfs\n");
-1
drivers/gpu/drm/radeon/radeon_object.c
··· 145 145 146 146 size = ALIGN(size, PAGE_SIZE); 147 147 148 - rdev->mman.bdev.dev_mapping = rdev->ddev->anon_inode->i_mapping; 149 148 if (kernel) { 150 149 type = ttm_bo_type_kernel; 151 150 } else if (sg) {
+3 -2
drivers/gpu/drm/radeon/radeon_ttm.c
··· 707 707 /* No others user of address space so set it to 0 */ 708 708 r = ttm_bo_device_init(&rdev->mman.bdev, 709 709 rdev->mman.bo_global_ref.ref.object, 710 - &radeon_bo_driver, DRM_FILE_PAGE_OFFSET, 710 + &radeon_bo_driver, 711 + rdev->ddev->anon_inode->i_mapping, 712 + DRM_FILE_PAGE_OFFSET, 711 713 rdev->need_dma32); 712 714 if (r) { 713 715 DRM_ERROR("failed initializing buffer object driver(%d).\n", r); ··· 747 745 } 748 746 DRM_INFO("radeon: %uM of GTT memory ready.\n", 749 747 (unsigned)(rdev->mc.gtt_size / (1024 * 1024))); 750 - rdev->mman.bdev.dev_mapping = rdev->ddev->anon_inode->i_mapping; 751 748 752 749 r = radeon_ttm_debugfs_init(rdev); 753 750 if (r) {
+2 -1
drivers/gpu/drm/ttm/ttm_bo.c
··· 1449 1449 int ttm_bo_device_init(struct ttm_bo_device *bdev, 1450 1450 struct ttm_bo_global *glob, 1451 1451 struct ttm_bo_driver *driver, 1452 + struct address_space *mapping, 1452 1453 uint64_t file_page_offset, 1453 1454 bool need_dma32) 1454 1455 { ··· 1471 1470 0x10000000); 1472 1471 INIT_DELAYED_WORK(&bdev->wq, ttm_bo_delayed_workqueue); 1473 1472 INIT_LIST_HEAD(&bdev->ddestroy); 1474 - bdev->dev_mapping = NULL; 1473 + bdev->dev_mapping = mapping; 1475 1474 bdev->glob = glob; 1476 1475 bdev->need_dma32 = need_dma32; 1477 1476 bdev->val_seq = 0;
+3 -2
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
··· 722 722 723 723 ret = ttm_bo_device_init(&dev_priv->bdev, 724 724 dev_priv->bo_global_ref.ref.object, 725 - &vmw_bo_driver, VMWGFX_FILE_PAGE_OFFSET, 725 + &vmw_bo_driver, 726 + dev->anon_inode->i_mapping, 727 + VMWGFX_FILE_PAGE_OFFSET, 726 728 false); 727 729 if (unlikely(ret != 0)) { 728 730 DRM_ERROR("Failed initializing TTM buffer object driver.\n"); ··· 971 969 goto out_no_shman; 972 970 973 971 file_priv->driver_priv = vmw_fp; 974 - dev_priv->bdev.dev_mapping = dev->anon_inode->i_mapping; 975 972 976 973 return 0; 977 974
+3 -3
include/drm/drm_vma_manager.h
··· 221 221 * @file_mapping: Address space to unmap @node from 222 222 * 223 223 * Unmap all userspace mappings for a given offset node. The mappings must be 224 - * associated with the @file_mapping address-space. If no offset exists or 225 - * the address-space is invalid, nothing is done. 224 + * associated with the @file_mapping address-space. If no offset exists 225 + * nothing is done. 226 226 * 227 227 * This call is unlocked. The caller must guarantee that drm_vma_offset_remove() 228 228 * is not called on this node concurrently. ··· 230 230 static inline void drm_vma_node_unmap(struct drm_vma_offset_node *node, 231 231 struct address_space *file_mapping) 232 232 { 233 - if (file_mapping && drm_vma_node_has_offset(node)) 233 + if (drm_vma_node_has_offset(node)) 234 234 unmap_mapping_range(file_mapping, 235 235 drm_vma_node_offset_addr(node), 236 236 drm_vma_node_size(node) << PAGE_SHIFT, 1);
+2
include/drm/ttm/ttm_bo_driver.h
··· 747 747 * @bdev: A pointer to a struct ttm_bo_device to initialize. 748 748 * @glob: A pointer to an initialized struct ttm_bo_global. 749 749 * @driver: A pointer to a struct ttm_bo_driver set up by the caller. 750 + * @mapping: The address space to use for this bo. 750 751 * @file_page_offset: Offset into the device address space that is available 751 752 * for buffer data. This ensures compatibility with other users of the 752 753 * address space. ··· 759 758 extern int ttm_bo_device_init(struct ttm_bo_device *bdev, 760 759 struct ttm_bo_global *glob, 761 760 struct ttm_bo_driver *driver, 761 + struct address_space *mapping, 762 762 uint64_t file_page_offset, bool need_dma32); 763 763 764 764 /**