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

ttm: add prime sharing support to TTM (v2)

This adds the ability for ttm common code to take an SG table
and use it as the backing for a slave TTM object.

The drivers can then populate their GTT tables using the SG object.

v2: make sure to setup VM for sg bos as well.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Jerome Glisse <jglisse@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>

+28 -6
+1 -1
drivers/gpu/drm/nouveau/nouveau_bo.c
··· 121 121 122 122 ret = ttm_bo_init(&dev_priv->ttm.bdev, &nvbo->bo, size, 123 123 ttm_bo_type_device, &nvbo->placement, 124 - align >> PAGE_SHIFT, 0, false, NULL, acc_size, 124 + align >> PAGE_SHIFT, 0, false, NULL, acc_size, NULL, 125 125 nouveau_bo_del_ttm); 126 126 if (ret) { 127 127 /* ttm will call nouveau_bo_del_ttm if it fails.. */
+1 -1
drivers/gpu/drm/radeon/radeon_object.c
··· 155 155 mutex_lock(&rdev->vram_mutex); 156 156 r = ttm_bo_init(&rdev->mman.bdev, &bo->tbo, size, type, 157 157 &bo->placement, page_align, 0, !kernel, NULL, 158 - acc_size, &radeon_ttm_bo_destroy); 158 + acc_size, NULL, &radeon_ttm_bo_destroy); 159 159 mutex_unlock(&rdev->vram_mutex); 160 160 if (unlikely(r != 0)) { 161 161 if (r != -ERESTARTSYS) {
+15 -2
drivers/gpu/drm/ttm/ttm_bo.c
··· 343 343 if (unlikely(bo->ttm == NULL)) 344 344 ret = -ENOMEM; 345 345 break; 346 + case ttm_bo_type_sg: 347 + bo->ttm = bdev->driver->ttm_tt_create(bdev, bo->num_pages << PAGE_SHIFT, 348 + page_flags | TTM_PAGE_FLAG_SG, 349 + glob->dummy_read_page); 350 + if (unlikely(bo->ttm == NULL)) { 351 + ret = -ENOMEM; 352 + break; 353 + } 354 + bo->ttm->sg = bo->sg; 355 + break; 346 356 default: 347 357 pr_err("Illegal buffer object type\n"); 348 358 ret = -EINVAL; ··· 1179 1169 bool interruptible, 1180 1170 struct file *persistent_swap_storage, 1181 1171 size_t acc_size, 1172 + struct sg_table *sg, 1182 1173 void (*destroy) (struct ttm_buffer_object *)) 1183 1174 { 1184 1175 int ret = 0; ··· 1234 1223 bo->seq_valid = false; 1235 1224 bo->persistent_swap_storage = persistent_swap_storage; 1236 1225 bo->acc_size = acc_size; 1226 + bo->sg = sg; 1237 1227 atomic_inc(&bo->glob->bo_count); 1238 1228 1239 1229 ret = ttm_bo_check_placement(bo, placement); ··· 1245 1233 * For ttm_bo_type_device buffers, allocate 1246 1234 * address space from the device. 1247 1235 */ 1248 - if (bo->type == ttm_bo_type_device) { 1236 + if (bo->type == ttm_bo_type_device || 1237 + bo->type == ttm_bo_type_sg) { 1249 1238 ret = ttm_bo_setup_vm(bo); 1250 1239 if (ret) 1251 1240 goto out_err; ··· 1325 1312 1326 1313 ret = ttm_bo_init(bdev, bo, size, type, placement, page_alignment, 1327 1314 buffer_start, interruptible, 1328 - persistent_swap_storage, acc_size, NULL); 1315 + persistent_swap_storage, acc_size, NULL, NULL); 1329 1316 if (likely(ret == 0)) 1330 1317 *p_bo = bo; 1331 1318
+1 -1
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
··· 1567 1567 ret = ttm_bo_init(bdev, &vmw_bo->base, size, 1568 1568 ttm_bo_type_device, placement, 1569 1569 0, 0, interruptible, 1570 - NULL, acc_size, bo_free); 1570 + NULL, acc_size, NULL, bo_free); 1571 1571 return ret; 1572 1572 } 1573 1573
+8 -1
include/drm/ttm/ttm_bo_api.h
··· 124 124 * 125 125 * @ttm_bo_type_kernel: These buffers are like ttm_bo_type_device buffers, 126 126 * but they cannot be accessed from user-space. For kernel-only use. 127 + * 128 + * @ttm_bo_type_sg: Buffer made from dmabuf sg table shared with another 129 + * driver. 127 130 */ 128 131 129 132 enum ttm_bo_type { 130 133 ttm_bo_type_device, 131 - ttm_bo_type_kernel 134 + ttm_bo_type_kernel, 135 + ttm_bo_type_sg 132 136 }; 133 137 134 138 struct ttm_tt; ··· 275 271 276 272 unsigned long offset; 277 273 uint32_t cur_placement; 274 + 275 + struct sg_table *sg; 278 276 }; 279 277 280 278 /** ··· 509 503 bool interrubtible, 510 504 struct file *persistent_swap_storage, 511 505 size_t acc_size, 506 + struct sg_table *sg, 512 507 void (*destroy) (struct ttm_buffer_object *)); 513 508 514 509 /**
+2
include/drm/ttm/ttm_bo_driver.h
··· 81 81 #define TTM_PAGE_FLAG_PERSISTENT_SWAP (1 << 5) 82 82 #define TTM_PAGE_FLAG_ZERO_ALLOC (1 << 6) 83 83 #define TTM_PAGE_FLAG_DMA32 (1 << 7) 84 + #define TTM_PAGE_FLAG_SG (1 << 8) 84 85 85 86 enum ttm_caching_state { 86 87 tt_uncached, ··· 117 116 struct page **pages; 118 117 uint32_t page_flags; 119 118 unsigned long num_pages; 119 + struct sg_table *sg; /* for SG objects via dma-buf */ 120 120 struct ttm_bo_global *glob; 121 121 struct ttm_backend *be; 122 122 struct file *swap_storage;