diff options
author | Maarten Lankhorst <maarten.lankhorst@canonical.com> | 2013-04-09 03:52:54 -0400 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2013-06-10 17:54:21 -0400 |
commit | ca793f75d91d61fd0009c4179eb88aac54a74239 (patch) | |
tree | de3b46699dbc6e7481bc1103204c8618769b196e /drivers/gpu/drm/drm_prime.c | |
parent | 102d6dba306c825cd5c310f73868b130931f47aa (diff) |
drm: move pinning/unpinning to buffer attach
This allows importing bo's to own device to work without requiring that the buffer is pinned in GART.
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'drivers/gpu/drm/drm_prime.c')
-rw-r--r-- | drivers/gpu/drm/drm_prime.c | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 1a36b0c22732..58ac6770a8c6 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c | |||
@@ -64,6 +64,29 @@ struct drm_prime_member { | |||
64 | }; | 64 | }; |
65 | static int drm_prime_add_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t handle); | 65 | static int drm_prime_add_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t handle); |
66 | 66 | ||
67 | static int drm_gem_map_attach(struct dma_buf *dma_buf, | ||
68 | struct device *target_dev, | ||
69 | struct dma_buf_attachment *attach) | ||
70 | { | ||
71 | struct drm_gem_object *obj = dma_buf->priv; | ||
72 | struct drm_device *dev = obj->dev; | ||
73 | |||
74 | if (!dev->driver->gem_prime_pin) | ||
75 | return 0; | ||
76 | |||
77 | return dev->driver->gem_prime_pin(obj); | ||
78 | } | ||
79 | |||
80 | static void drm_gem_map_detach(struct dma_buf *dma_buf, | ||
81 | struct dma_buf_attachment *attach) | ||
82 | { | ||
83 | struct drm_gem_object *obj = dma_buf->priv; | ||
84 | struct drm_device *dev = obj->dev; | ||
85 | |||
86 | if (dev->driver->gem_prime_unpin) | ||
87 | dev->driver->gem_prime_unpin(obj); | ||
88 | } | ||
89 | |||
67 | static struct sg_table *drm_gem_map_dma_buf(struct dma_buf_attachment *attach, | 90 | static struct sg_table *drm_gem_map_dma_buf(struct dma_buf_attachment *attach, |
68 | enum dma_data_direction dir) | 91 | enum dma_data_direction dir) |
69 | { | 92 | { |
@@ -92,13 +115,10 @@ static void drm_gem_unmap_dma_buf(struct dma_buf_attachment *attach, | |||
92 | static void drm_gem_dmabuf_release(struct dma_buf *dma_buf) | 115 | static void drm_gem_dmabuf_release(struct dma_buf *dma_buf) |
93 | { | 116 | { |
94 | struct drm_gem_object *obj = dma_buf->priv; | 117 | struct drm_gem_object *obj = dma_buf->priv; |
95 | struct drm_device *dev = obj->dev; | ||
96 | 118 | ||
97 | if (obj->export_dma_buf == dma_buf) { | 119 | if (obj->export_dma_buf == dma_buf) { |
98 | /* drop the reference on the export fd holds */ | 120 | /* drop the reference on the export fd holds */ |
99 | obj->export_dma_buf = NULL; | 121 | obj->export_dma_buf = NULL; |
100 | if (dev->driver->gem_prime_unpin) | ||
101 | dev->driver->gem_prime_unpin(obj); | ||
102 | drm_gem_object_unreference_unlocked(obj); | 122 | drm_gem_object_unreference_unlocked(obj); |
103 | } | 123 | } |
104 | } | 124 | } |
@@ -149,6 +169,8 @@ static int drm_gem_dmabuf_mmap(struct dma_buf *dma_buf, | |||
149 | } | 169 | } |
150 | 170 | ||
151 | static const struct dma_buf_ops drm_gem_prime_dmabuf_ops = { | 171 | static const struct dma_buf_ops drm_gem_prime_dmabuf_ops = { |
172 | .attach = drm_gem_map_attach, | ||
173 | .detach = drm_gem_map_detach, | ||
152 | .map_dma_buf = drm_gem_map_dma_buf, | 174 | .map_dma_buf = drm_gem_map_dma_buf, |
153 | .unmap_dma_buf = drm_gem_unmap_dma_buf, | 175 | .unmap_dma_buf = drm_gem_unmap_dma_buf, |
154 | .release = drm_gem_dmabuf_release, | 176 | .release = drm_gem_dmabuf_release, |
@@ -188,19 +210,8 @@ static const struct dma_buf_ops drm_gem_prime_dmabuf_ops = { | |||
188 | struct dma_buf *drm_gem_prime_export(struct drm_device *dev, | 210 | struct dma_buf *drm_gem_prime_export(struct drm_device *dev, |
189 | struct drm_gem_object *obj, int flags) | 211 | struct drm_gem_object *obj, int flags) |
190 | { | 212 | { |
191 | struct dma_buf *buf; | 213 | return dma_buf_export(obj, &drm_gem_prime_dmabuf_ops, obj->size, |
192 | |||
193 | if (dev->driver->gem_prime_pin) { | ||
194 | int ret = dev->driver->gem_prime_pin(obj); | ||
195 | if (ret) | ||
196 | return ERR_PTR(ret); | ||
197 | } | ||
198 | buf = dma_buf_export(obj, &drm_gem_prime_dmabuf_ops, obj->size, | ||
199 | 0600); | 214 | 0600); |
200 | |||
201 | if (IS_ERR(buf) && dev->driver->gem_prime_unpin) | ||
202 | dev->driver->gem_prime_unpin(obj); | ||
203 | return buf; | ||
204 | } | 215 | } |
205 | EXPORT_SYMBOL(drm_gem_prime_export); | 216 | EXPORT_SYMBOL(drm_gem_prime_export); |
206 | 217 | ||