diff options
-rw-r--r-- | drivers/gpu/drm/radeon/radeon.h | 3 | ||||
-rw-r--r-- | drivers/gpu/drm/radeon/radeon_prime.c | 38 |
2 files changed, 41 insertions, 0 deletions
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h index 492654f8ee74..2e24022b389a 100644 --- a/drivers/gpu/drm/radeon/radeon.h +++ b/drivers/gpu/drm/radeon/radeon.h | |||
@@ -346,6 +346,9 @@ struct radeon_bo { | |||
346 | /* Constant after initialization */ | 346 | /* Constant after initialization */ |
347 | struct radeon_device *rdev; | 347 | struct radeon_device *rdev; |
348 | struct drm_gem_object gem_base; | 348 | struct drm_gem_object gem_base; |
349 | |||
350 | struct ttm_bo_kmap_obj dma_buf_vmap; | ||
351 | int vmapping_count; | ||
349 | }; | 352 | }; |
350 | #define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base) | 353 | #define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base) |
351 | 354 | ||
diff --git a/drivers/gpu/drm/radeon/radeon_prime.c b/drivers/gpu/drm/radeon/radeon_prime.c index 37ff6bfb8c72..8ddab4c76710 100644 --- a/drivers/gpu/drm/radeon/radeon_prime.c +++ b/drivers/gpu/drm/radeon/radeon_prime.c | |||
@@ -90,6 +90,42 @@ static int radeon_gem_prime_mmap(struct dma_buf *dma_buf, struct vm_area_struct | |||
90 | return -EINVAL; | 90 | return -EINVAL; |
91 | } | 91 | } |
92 | 92 | ||
93 | static void *radeon_gem_prime_vmap(struct dma_buf *dma_buf) | ||
94 | { | ||
95 | struct radeon_bo *bo = dma_buf->priv; | ||
96 | struct drm_device *dev = bo->rdev->ddev; | ||
97 | int ret; | ||
98 | |||
99 | mutex_lock(&dev->struct_mutex); | ||
100 | if (bo->vmapping_count) { | ||
101 | bo->vmapping_count++; | ||
102 | goto out_unlock; | ||
103 | } | ||
104 | |||
105 | ret = ttm_bo_kmap(&bo->tbo, 0, bo->tbo.num_pages, | ||
106 | &bo->dma_buf_vmap); | ||
107 | if (ret) { | ||
108 | mutex_unlock(&dev->struct_mutex); | ||
109 | return ERR_PTR(ret); | ||
110 | } | ||
111 | bo->vmapping_count = 1; | ||
112 | out_unlock: | ||
113 | mutex_unlock(&dev->struct_mutex); | ||
114 | return bo->dma_buf_vmap.virtual; | ||
115 | } | ||
116 | |||
117 | static void radeon_gem_prime_vunmap(struct dma_buf *dma_buf, void *vaddr) | ||
118 | { | ||
119 | struct radeon_bo *bo = dma_buf->priv; | ||
120 | struct drm_device *dev = bo->rdev->ddev; | ||
121 | |||
122 | mutex_lock(&dev->struct_mutex); | ||
123 | bo->vmapping_count--; | ||
124 | if (bo->vmapping_count == 0) { | ||
125 | ttm_bo_kunmap(&bo->dma_buf_vmap); | ||
126 | } | ||
127 | mutex_unlock(&dev->struct_mutex); | ||
128 | } | ||
93 | const static struct dma_buf_ops radeon_dmabuf_ops = { | 129 | const static struct dma_buf_ops radeon_dmabuf_ops = { |
94 | .map_dma_buf = radeon_gem_map_dma_buf, | 130 | .map_dma_buf = radeon_gem_map_dma_buf, |
95 | .unmap_dma_buf = radeon_gem_unmap_dma_buf, | 131 | .unmap_dma_buf = radeon_gem_unmap_dma_buf, |
@@ -99,6 +135,8 @@ const static struct dma_buf_ops radeon_dmabuf_ops = { | |||
99 | .kunmap = radeon_gem_kunmap, | 135 | .kunmap = radeon_gem_kunmap, |
100 | .kunmap_atomic = radeon_gem_kunmap_atomic, | 136 | .kunmap_atomic = radeon_gem_kunmap_atomic, |
101 | .mmap = radeon_gem_prime_mmap, | 137 | .mmap = radeon_gem_prime_mmap, |
138 | .vmap = radeon_gem_prime_vmap, | ||
139 | .vunmap = radeon_gem_prime_vunmap, | ||
102 | }; | 140 | }; |
103 | 141 | ||
104 | static int radeon_prime_create(struct drm_device *dev, | 142 | static int radeon_prime_create(struct drm_device *dev, |