diff options
author | Dave Airlie <airlied@redhat.com> | 2012-04-02 06:46:06 -0400 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2012-05-23 05:46:27 -0400 |
commit | 129b78bfca591e736e56a294f0e357d73d938f7e (patch) | |
tree | b5754d4b12346b67077ac3b2239c04bda37bf6a0 | |
parent | 96503f592fd729f296f5870a57be0417eeffc92a (diff) |
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>
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_bo.c | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/radeon/radeon_object.c | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/ttm/ttm_bo.c | 17 | ||||
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 2 | ||||
-rw-r--r-- | include/drm/ttm/ttm_bo_api.h | 9 | ||||
-rw-r--r-- | include/drm/ttm/ttm_bo_driver.h | 2 |
6 files changed, 28 insertions, 6 deletions
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c index 12ce044f12f5..81599d6e636b 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bo.c +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c | |||
@@ -121,7 +121,7 @@ nouveau_bo_new(struct drm_device *dev, int size, int align, | |||
121 | 121 | ||
122 | ret = ttm_bo_init(&dev_priv->ttm.bdev, &nvbo->bo, size, | 122 | ret = ttm_bo_init(&dev_priv->ttm.bdev, &nvbo->bo, size, |
123 | ttm_bo_type_device, &nvbo->placement, | 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 | nouveau_bo_del_ttm); | 125 | nouveau_bo_del_ttm); |
126 | if (ret) { | 126 | if (ret) { |
127 | /* ttm will call nouveau_bo_del_ttm if it fails.. */ | 127 | /* ttm will call nouveau_bo_del_ttm if it fails.. */ |
diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c index df6a4dbd93f8..1affbc954c56 100644 --- a/drivers/gpu/drm/radeon/radeon_object.c +++ b/drivers/gpu/drm/radeon/radeon_object.c | |||
@@ -155,7 +155,7 @@ retry: | |||
155 | mutex_lock(&rdev->vram_mutex); | 155 | mutex_lock(&rdev->vram_mutex); |
156 | r = ttm_bo_init(&rdev->mman.bdev, &bo->tbo, size, type, | 156 | r = ttm_bo_init(&rdev->mman.bdev, &bo->tbo, size, type, |
157 | &bo->placement, page_align, 0, !kernel, NULL, | 157 | &bo->placement, page_align, 0, !kernel, NULL, |
158 | acc_size, &radeon_ttm_bo_destroy); | 158 | acc_size, NULL, &radeon_ttm_bo_destroy); |
159 | mutex_unlock(&rdev->vram_mutex); | 159 | mutex_unlock(&rdev->vram_mutex); |
160 | if (unlikely(r != 0)) { | 160 | if (unlikely(r != 0)) { |
161 | if (r != -ERESTARTSYS) { | 161 | if (r != -ERESTARTSYS) { |
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 1f5c67c579cf..36792bd4da77 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c | |||
@@ -343,6 +343,16 @@ static int ttm_bo_add_ttm(struct ttm_buffer_object *bo, bool zero_alloc) | |||
343 | if (unlikely(bo->ttm == NULL)) | 343 | if (unlikely(bo->ttm == NULL)) |
344 | ret = -ENOMEM; | 344 | ret = -ENOMEM; |
345 | break; | 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 | default: | 356 | default: |
347 | pr_err("Illegal buffer object type\n"); | 357 | pr_err("Illegal buffer object type\n"); |
348 | ret = -EINVAL; | 358 | ret = -EINVAL; |
@@ -1169,6 +1179,7 @@ int ttm_bo_init(struct ttm_bo_device *bdev, | |||
1169 | bool interruptible, | 1179 | bool interruptible, |
1170 | struct file *persistent_swap_storage, | 1180 | struct file *persistent_swap_storage, |
1171 | size_t acc_size, | 1181 | size_t acc_size, |
1182 | struct sg_table *sg, | ||
1172 | void (*destroy) (struct ttm_buffer_object *)) | 1183 | void (*destroy) (struct ttm_buffer_object *)) |
1173 | { | 1184 | { |
1174 | int ret = 0; | 1185 | int ret = 0; |
@@ -1223,6 +1234,7 @@ int ttm_bo_init(struct ttm_bo_device *bdev, | |||
1223 | bo->seq_valid = false; | 1234 | bo->seq_valid = false; |
1224 | bo->persistent_swap_storage = persistent_swap_storage; | 1235 | bo->persistent_swap_storage = persistent_swap_storage; |
1225 | bo->acc_size = acc_size; | 1236 | bo->acc_size = acc_size; |
1237 | bo->sg = sg; | ||
1226 | atomic_inc(&bo->glob->bo_count); | 1238 | atomic_inc(&bo->glob->bo_count); |
1227 | 1239 | ||
1228 | ret = ttm_bo_check_placement(bo, placement); | 1240 | ret = ttm_bo_check_placement(bo, placement); |
@@ -1233,7 +1245,8 @@ int ttm_bo_init(struct ttm_bo_device *bdev, | |||
1233 | * For ttm_bo_type_device buffers, allocate | 1245 | * For ttm_bo_type_device buffers, allocate |
1234 | * address space from the device. | 1246 | * address space from the device. |
1235 | */ | 1247 | */ |
1236 | if (bo->type == ttm_bo_type_device) { | 1248 | if (bo->type == ttm_bo_type_device || |
1249 | bo->type == ttm_bo_type_sg) { | ||
1237 | ret = ttm_bo_setup_vm(bo); | 1250 | ret = ttm_bo_setup_vm(bo); |
1238 | if (ret) | 1251 | if (ret) |
1239 | goto out_err; | 1252 | goto out_err; |
@@ -1312,7 +1325,7 @@ int ttm_bo_create(struct ttm_bo_device *bdev, | |||
1312 | 1325 | ||
1313 | ret = ttm_bo_init(bdev, bo, size, type, placement, page_alignment, | 1326 | ret = ttm_bo_init(bdev, bo, size, type, placement, page_alignment, |
1314 | buffer_start, interruptible, | 1327 | buffer_start, interruptible, |
1315 | persistent_swap_storage, acc_size, NULL); | 1328 | persistent_swap_storage, acc_size, NULL, NULL); |
1316 | if (likely(ret == 0)) | 1329 | if (likely(ret == 0)) |
1317 | *p_bo = bo; | 1330 | *p_bo = bo; |
1318 | 1331 | ||
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c index a37abb581cbb..22bf9a21ec71 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | |||
@@ -1567,7 +1567,7 @@ int vmw_dmabuf_init(struct vmw_private *dev_priv, | |||
1567 | ret = ttm_bo_init(bdev, &vmw_bo->base, size, | 1567 | ret = ttm_bo_init(bdev, &vmw_bo->base, size, |
1568 | ttm_bo_type_device, placement, | 1568 | ttm_bo_type_device, placement, |
1569 | 0, 0, interruptible, | 1569 | 0, 0, interruptible, |
1570 | NULL, acc_size, bo_free); | 1570 | NULL, acc_size, NULL, bo_free); |
1571 | return ret; | 1571 | return ret; |
1572 | } | 1572 | } |
1573 | 1573 | ||
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h index 974c8f801c39..e15f2a89a270 100644 --- a/include/drm/ttm/ttm_bo_api.h +++ b/include/drm/ttm/ttm_bo_api.h | |||
@@ -124,11 +124,15 @@ struct ttm_mem_reg { | |||
124 | * | 124 | * |
125 | * @ttm_bo_type_kernel: These buffers are like ttm_bo_type_device buffers, | 125 | * @ttm_bo_type_kernel: These buffers are like ttm_bo_type_device buffers, |
126 | * but they cannot be accessed from user-space. For kernel-only use. | 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 | enum ttm_bo_type { | 132 | enum ttm_bo_type { |
130 | ttm_bo_type_device, | 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 | struct ttm_tt; | 138 | struct ttm_tt; |
@@ -271,6 +275,8 @@ struct ttm_buffer_object { | |||
271 | 275 | ||
272 | unsigned long offset; | 276 | unsigned long offset; |
273 | uint32_t cur_placement; | 277 | uint32_t cur_placement; |
278 | |||
279 | struct sg_table *sg; | ||
274 | }; | 280 | }; |
275 | 281 | ||
276 | /** | 282 | /** |
@@ -503,6 +509,7 @@ extern int ttm_bo_init(struct ttm_bo_device *bdev, | |||
503 | bool interrubtible, | 509 | bool interrubtible, |
504 | struct file *persistent_swap_storage, | 510 | struct file *persistent_swap_storage, |
505 | size_t acc_size, | 511 | size_t acc_size, |
512 | struct sg_table *sg, | ||
506 | void (*destroy) (struct ttm_buffer_object *)); | 513 | void (*destroy) (struct ttm_buffer_object *)); |
507 | 514 | ||
508 | /** | 515 | /** |
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h index d43e892307ff..a05f1b55714d 100644 --- a/include/drm/ttm/ttm_bo_driver.h +++ b/include/drm/ttm/ttm_bo_driver.h | |||
@@ -81,6 +81,7 @@ struct ttm_backend_func { | |||
81 | #define TTM_PAGE_FLAG_PERSISTENT_SWAP (1 << 5) | 81 | #define TTM_PAGE_FLAG_PERSISTENT_SWAP (1 << 5) |
82 | #define TTM_PAGE_FLAG_ZERO_ALLOC (1 << 6) | 82 | #define TTM_PAGE_FLAG_ZERO_ALLOC (1 << 6) |
83 | #define TTM_PAGE_FLAG_DMA32 (1 << 7) | 83 | #define TTM_PAGE_FLAG_DMA32 (1 << 7) |
84 | #define TTM_PAGE_FLAG_SG (1 << 8) | ||
84 | 85 | ||
85 | enum ttm_caching_state { | 86 | enum ttm_caching_state { |
86 | tt_uncached, | 87 | tt_uncached, |
@@ -116,6 +117,7 @@ struct ttm_tt { | |||
116 | struct page **pages; | 117 | struct page **pages; |
117 | uint32_t page_flags; | 118 | uint32_t page_flags; |
118 | unsigned long num_pages; | 119 | unsigned long num_pages; |
120 | struct sg_table *sg; /* for SG objects via dma-buf */ | ||
119 | struct ttm_bo_global *glob; | 121 | struct ttm_bo_global *glob; |
120 | struct ttm_backend *be; | 122 | struct ttm_backend *be; |
121 | struct file *swap_storage; | 123 | struct file *swap_storage; |