blob: 7f986d7b8e2285d5a8fa84b4db3dc5a9c6f5d12f [file] [log] [blame]
Sascha Hauerb9d47452012-06-27 15:30:18 +02001/*
2 * drm gem CMA (contiguous memory allocator) helper functions
3 *
4 * Copyright (C) 2012 Sascha Hauer, Pengutronix
5 *
6 * Based on Samsung Exynos code
7 *
8 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
19
20#include <linux/mm.h>
21#include <linux/slab.h>
22#include <linux/mutex.h>
23#include <linux/export.h>
Laurent Pinchart71d72822013-02-17 01:57:30 +010024#include <linux/dma-buf.h>
Sascha Hauerb9d47452012-06-27 15:30:18 +020025#include <linux/dma-mapping.h>
26
27#include <drm/drmP.h>
28#include <drm/drm.h>
29#include <drm/drm_gem_cma_helper.h>
David Herrmann0de23972013-07-24 21:07:52 +020030#include <drm/drm_vma_manager.h>
Sascha Hauerb9d47452012-06-27 15:30:18 +020031
Thierry Redingd7883f82014-11-03 13:56:55 +010032/**
33 * DOC: cma helpers
34 *
35 * The Contiguous Memory Allocator reserves a pool of memory at early boot
36 * that is used to service requests for large blocks of contiguous memory.
37 *
38 * The DRM GEM/CMA helpers use this allocator as a means to provide buffer
39 * objects that are physically contiguous in memory. This is useful for
40 * display drivers that are unable to map scattered buffers via an IOMMU.
41 */
42
43/**
Laurent Pincharta5ed8942013-02-17 01:54:26 +010044 * __drm_gem_cma_create - Create a GEM CMA object without allocating memory
Thierry Redingd7883f82014-11-03 13:56:55 +010045 * @drm: DRM device
46 * @size: size of the object to allocate
Laurent Pincharta5ed8942013-02-17 01:54:26 +010047 *
Thierry Redingd7883f82014-11-03 13:56:55 +010048 * This function creates and initializes a GEM CMA object of the given size,
49 * but doesn't allocate any memory to back the object.
Laurent Pincharta5ed8942013-02-17 01:54:26 +010050 *
Thierry Redingd7883f82014-11-03 13:56:55 +010051 * Returns:
52 * A struct drm_gem_cma_object * on success or an ERR_PTR()-encoded negative
53 * error code on failure.
Laurent Pincharta5ed8942013-02-17 01:54:26 +010054 */
55static struct drm_gem_cma_object *
Thierry Redingd7883f82014-11-03 13:56:55 +010056__drm_gem_cma_create(struct drm_device *drm, size_t size)
Sascha Hauerb9d47452012-06-27 15:30:18 +020057{
Laurent Pincharta5ed8942013-02-17 01:54:26 +010058 struct drm_gem_cma_object *cma_obj;
59 struct drm_gem_object *gem_obj;
60 int ret;
61
62 cma_obj = kzalloc(sizeof(*cma_obj), GFP_KERNEL);
63 if (!cma_obj)
64 return ERR_PTR(-ENOMEM);
65
66 gem_obj = &cma_obj->base;
67
68 ret = drm_gem_object_init(drm, gem_obj, size);
69 if (ret)
70 goto error;
71
72 ret = drm_gem_create_mmap_offset(gem_obj);
73 if (ret) {
74 drm_gem_object_release(gem_obj);
75 goto error;
76 }
77
78 return cma_obj;
79
80error:
81 kfree(cma_obj);
82 return ERR_PTR(ret);
Sascha Hauerb9d47452012-06-27 15:30:18 +020083}
84
Thierry Redingd7883f82014-11-03 13:56:55 +010085/**
Sascha Hauerb9d47452012-06-27 15:30:18 +020086 * drm_gem_cma_create - allocate an object with the given size
Thierry Redingd7883f82014-11-03 13:56:55 +010087 * @drm: DRM device
88 * @size: size of the object to allocate
Sascha Hauerb9d47452012-06-27 15:30:18 +020089 *
Thierry Redingd7883f82014-11-03 13:56:55 +010090 * This function creates a CMA GEM object and allocates a contiguous chunk of
91 * memory as backing store. The backing memory has the writecombine attribute
92 * set.
93 *
94 * Returns:
95 * A struct drm_gem_cma_object * on success or an ERR_PTR()-encoded negative
96 * error code on failure.
Sascha Hauerb9d47452012-06-27 15:30:18 +020097 */
98struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm,
Thierry Redingd7883f82014-11-03 13:56:55 +010099 size_t size)
Sascha Hauerb9d47452012-06-27 15:30:18 +0200100{
101 struct drm_gem_cma_object *cma_obj;
Laurent Pinchart71d72822013-02-17 01:57:30 +0100102 int ret;
Sascha Hauerb9d47452012-06-27 15:30:18 +0200103
104 size = round_up(size, PAGE_SIZE);
105
Laurent Pincharta5ed8942013-02-17 01:54:26 +0100106 cma_obj = __drm_gem_cma_create(drm, size);
107 if (IS_ERR(cma_obj))
108 return cma_obj;
Sascha Hauerb9d47452012-06-27 15:30:18 +0200109
110 cma_obj->vaddr = dma_alloc_writecombine(drm->dev, size,
111 &cma_obj->paddr, GFP_KERNEL | __GFP_NOWARN);
112 if (!cma_obj->vaddr) {
Laurent Pincharta5ed8942013-02-17 01:54:26 +0100113 dev_err(drm->dev, "failed to allocate buffer with size %d\n",
114 size);
Laurent Pinchart71d72822013-02-17 01:57:30 +0100115 ret = -ENOMEM;
116 goto error;
Sascha Hauerb9d47452012-06-27 15:30:18 +0200117 }
118
Sascha Hauerb9d47452012-06-27 15:30:18 +0200119 return cma_obj;
Laurent Pinchart71d72822013-02-17 01:57:30 +0100120
121error:
Laurent Pinchart71d72822013-02-17 01:57:30 +0100122 drm_gem_cma_free_object(&cma_obj->base);
123 return ERR_PTR(ret);
Sascha Hauerb9d47452012-06-27 15:30:18 +0200124}
125EXPORT_SYMBOL_GPL(drm_gem_cma_create);
126
Thierry Redingd7883f82014-11-03 13:56:55 +0100127/**
128 * drm_gem_cma_create_with_handle - allocate an object with the given size and
129 * return a GEM handle to it
130 * @file_priv: DRM file-private structure to register the handle for
131 * @drm: DRM device
132 * @size: size of the object to allocate
133 * @handle: return location for the GEM handle
Sascha Hauerb9d47452012-06-27 15:30:18 +0200134 *
Thierry Redingd7883f82014-11-03 13:56:55 +0100135 * This function creates a CMA GEM object, allocating a physically contiguous
136 * chunk of memory as backing store. The GEM object is then added to the list
137 * of object associated with the given file and a handle to it is returned.
138 *
139 * Returns:
140 * A struct drm_gem_cma_object * on success or an ERR_PTR()-encoded negative
141 * error code on failure.
Sascha Hauerb9d47452012-06-27 15:30:18 +0200142 */
Thierry Redingd7883f82014-11-03 13:56:55 +0100143static struct drm_gem_cma_object *
144drm_gem_cma_create_with_handle(struct drm_file *file_priv,
145 struct drm_device *drm, size_t size,
146 uint32_t *handle)
Sascha Hauerb9d47452012-06-27 15:30:18 +0200147{
148 struct drm_gem_cma_object *cma_obj;
149 struct drm_gem_object *gem_obj;
150 int ret;
151
152 cma_obj = drm_gem_cma_create(drm, size);
153 if (IS_ERR(cma_obj))
154 return cma_obj;
155
156 gem_obj = &cma_obj->base;
157
158 /*
159 * allocate a id of idr table where the obj is registered
160 * and handle has the id what user can see.
161 */
162 ret = drm_gem_handle_create(file_priv, gem_obj, handle);
163 if (ret)
164 goto err_handle_create;
165
166 /* drop reference from allocate - handle holds it now. */
167 drm_gem_object_unreference_unlocked(gem_obj);
168
169 return cma_obj;
170
171err_handle_create:
172 drm_gem_cma_free_object(gem_obj);
173
174 return ERR_PTR(ret);
175}
176
Thierry Redingd7883f82014-11-03 13:56:55 +0100177/**
178 * drm_gem_cma_free_object - free resources associated with a CMA GEM object
179 * @gem_obj: GEM object to free
180 *
181 * This function frees the backing memory of the CMA GEM object, cleans up the
182 * GEM object state and frees the memory used to store the object itself.
183 * Drivers using the CMA helpers should set this as their DRM driver's
184 * ->gem_free_object() callback.
Sascha Hauerb9d47452012-06-27 15:30:18 +0200185 */
186void drm_gem_cma_free_object(struct drm_gem_object *gem_obj)
187{
188 struct drm_gem_cma_object *cma_obj;
189
David Herrmann0de23972013-07-24 21:07:52 +0200190 drm_gem_free_mmap_offset(gem_obj);
Sascha Hauerb9d47452012-06-27 15:30:18 +0200191
Sascha Hauerb9d47452012-06-27 15:30:18 +0200192 cma_obj = to_drm_gem_cma_obj(gem_obj);
193
Laurent Pinchart71d72822013-02-17 01:57:30 +0100194 if (cma_obj->vaddr) {
Laurent Pincharta5ed8942013-02-17 01:54:26 +0100195 dma_free_writecombine(gem_obj->dev->dev, cma_obj->base.size,
196 cma_obj->vaddr, cma_obj->paddr);
Laurent Pinchart71d72822013-02-17 01:57:30 +0100197 } else if (gem_obj->import_attach) {
198 drm_prime_gem_destroy(gem_obj, cma_obj->sgt);
199 }
Laurent Pincharta5ed8942013-02-17 01:54:26 +0100200
201 drm_gem_object_release(gem_obj);
Sascha Hauerb9d47452012-06-27 15:30:18 +0200202
203 kfree(cma_obj);
204}
205EXPORT_SYMBOL_GPL(drm_gem_cma_free_object);
206
Thierry Redingd7883f82014-11-03 13:56:55 +0100207/**
208 * drm_gem_cma_dumb_create - create a dumb buffer object
209 * @file_priv: DRM file-private structure to create the dumb buffer for
210 * @drm: DRM device
211 * @args: IOCTL data
Sascha Hauerb9d47452012-06-27 15:30:18 +0200212 *
Thierry Redingd7883f82014-11-03 13:56:55 +0100213 * This function computes the pitch of the dumb buffer and rounds it up to an
214 * integer number of bytes per pixel. Drivers for hardware that doesn't have
215 * any additional restrictions on the pitch can directly use this function as
216 * their ->dumb_create() callback.
217 *
218 * Returns:
219 * 0 on success or a negative error code on failure.
Sascha Hauerb9d47452012-06-27 15:30:18 +0200220 */
221int drm_gem_cma_dumb_create(struct drm_file *file_priv,
Thierry Redingd7883f82014-11-03 13:56:55 +0100222 struct drm_device *drm,
223 struct drm_mode_create_dumb *args)
Sascha Hauerb9d47452012-06-27 15:30:18 +0200224{
225 struct drm_gem_cma_object *cma_obj;
226 int min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
227
228 if (args->pitch < min_pitch)
229 args->pitch = min_pitch;
230
231 if (args->size < args->pitch * args->height)
232 args->size = args->pitch * args->height;
233
Thierry Redingd7883f82014-11-03 13:56:55 +0100234 cma_obj = drm_gem_cma_create_with_handle(file_priv, drm, args->size,
235 &args->handle);
Sachin Kamatb03cda52013-07-15 16:04:46 +0530236 return PTR_ERR_OR_ZERO(cma_obj);
Sascha Hauerb9d47452012-06-27 15:30:18 +0200237}
238EXPORT_SYMBOL_GPL(drm_gem_cma_dumb_create);
239
Thierry Redingd7883f82014-11-03 13:56:55 +0100240/**
241 * drm_gem_cma_dumb_map_offset - return the fake mmap offset for a CMA GEM
242 * object
243 * @file_priv: DRM file-private structure containing the GEM object
244 * @drm: DRM device
245 * @handle: GEM object handle
246 * @offset: return location for the fake mmap offset
247 *
248 * This function look up an object by its handle and returns the fake mmap
249 * offset associated with it. Drivers using the CMA helpers should set this
250 * as their DRM driver's ->dumb_map_offset() callback.
251 *
252 * Returns:
253 * 0 on success or a negative error code on failure.
Sascha Hauerb9d47452012-06-27 15:30:18 +0200254 */
255int drm_gem_cma_dumb_map_offset(struct drm_file *file_priv,
Thierry Redingd7883f82014-11-03 13:56:55 +0100256 struct drm_device *drm, u32 handle,
257 u64 *offset)
Sascha Hauerb9d47452012-06-27 15:30:18 +0200258{
259 struct drm_gem_object *gem_obj;
260
261 mutex_lock(&drm->struct_mutex);
262
263 gem_obj = drm_gem_object_lookup(drm, file_priv, handle);
264 if (!gem_obj) {
Thierry Redingd7883f82014-11-03 13:56:55 +0100265 dev_err(drm->dev, "failed to lookup GEM object\n");
Sascha Hauerb9d47452012-06-27 15:30:18 +0200266 mutex_unlock(&drm->struct_mutex);
267 return -EINVAL;
268 }
269
David Herrmann0de23972013-07-24 21:07:52 +0200270 *offset = drm_vma_node_offset_addr(&gem_obj->vma_node);
Sascha Hauerb9d47452012-06-27 15:30:18 +0200271
272 drm_gem_object_unreference(gem_obj);
273
274 mutex_unlock(&drm->struct_mutex);
275
276 return 0;
277}
278EXPORT_SYMBOL_GPL(drm_gem_cma_dumb_map_offset);
279
280const struct vm_operations_struct drm_gem_cma_vm_ops = {
281 .open = drm_gem_vm_open,
282 .close = drm_gem_vm_close,
283};
284EXPORT_SYMBOL_GPL(drm_gem_cma_vm_ops);
285
Laurent Pinchartebaf9e02013-04-16 14:32:34 +0200286static int drm_gem_cma_mmap_obj(struct drm_gem_cma_object *cma_obj,
287 struct vm_area_struct *vma)
288{
289 int ret;
290
Laurent Pinchartb65e64f2014-03-02 20:09:48 +0100291 /*
292 * Clear the VM_PFNMAP flag that was set by drm_gem_mmap(), and set the
293 * vm_pgoff (used as a fake buffer offset by DRM) to 0 as we want to map
294 * the whole buffer.
295 */
296 vma->vm_flags &= ~VM_PFNMAP;
297 vma->vm_pgoff = 0;
298
299 ret = dma_mmap_writecombine(cma_obj->base.dev->dev, vma,
300 cma_obj->vaddr, cma_obj->paddr,
301 vma->vm_end - vma->vm_start);
Laurent Pinchartebaf9e02013-04-16 14:32:34 +0200302 if (ret)
303 drm_gem_vm_close(vma);
304
305 return ret;
306}
307
Thierry Redingd7883f82014-11-03 13:56:55 +0100308/**
309 * drm_gem_cma_mmap - memory-map a CMA GEM object
310 * @filp: file object
311 * @vma: VMA for the area to be mapped
312 *
313 * This function implements an augmented version of the GEM DRM file mmap
314 * operation for CMA objects: In addition to the usual GEM VMA setup it
315 * immediately faults in the entire object instead of using on-demaind
316 * faulting. Drivers which employ the CMA helpers should use this function
317 * as their ->mmap() handler in the DRM device file's file_operations
318 * structure.
319 *
320 * Returns:
321 * 0 on success or a negative error code on failure.
Sascha Hauerb9d47452012-06-27 15:30:18 +0200322 */
323int drm_gem_cma_mmap(struct file *filp, struct vm_area_struct *vma)
324{
Sascha Hauerb9d47452012-06-27 15:30:18 +0200325 struct drm_gem_cma_object *cma_obj;
Laurent Pinchartebaf9e02013-04-16 14:32:34 +0200326 struct drm_gem_object *gem_obj;
Sascha Hauerb9d47452012-06-27 15:30:18 +0200327 int ret;
328
329 ret = drm_gem_mmap(filp, vma);
330 if (ret)
331 return ret;
332
333 gem_obj = vma->vm_private_data;
334 cma_obj = to_drm_gem_cma_obj(gem_obj);
335
Laurent Pinchartebaf9e02013-04-16 14:32:34 +0200336 return drm_gem_cma_mmap_obj(cma_obj, vma);
Sascha Hauerb9d47452012-06-27 15:30:18 +0200337}
338EXPORT_SYMBOL_GPL(drm_gem_cma_mmap);
339
Rob Clark6f646092012-12-10 10:46:43 -0600340#ifdef CONFIG_DEBUG_FS
Thierry Redingd7883f82014-11-03 13:56:55 +0100341/**
342 * drm_gem_cma_describe - describe a CMA GEM object for debugfs
343 * @cma_obj: CMA GEM object
344 * @m: debugfs file handle
345 *
346 * This function can be used to dump a human-readable representation of the
347 * CMA GEM object into a synthetic file.
348 */
349void drm_gem_cma_describe(struct drm_gem_cma_object *cma_obj,
350 struct seq_file *m)
Rob Clark6f646092012-12-10 10:46:43 -0600351{
352 struct drm_gem_object *obj = &cma_obj->base;
353 struct drm_device *dev = obj->dev;
David Herrmann0de23972013-07-24 21:07:52 +0200354 uint64_t off;
Rob Clark6f646092012-12-10 10:46:43 -0600355
356 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
357
David Herrmann0de23972013-07-24 21:07:52 +0200358 off = drm_vma_node_start(&obj->vma_node);
Rob Clark6f646092012-12-10 10:46:43 -0600359
Laurent Pinchartf4d1b022014-03-04 19:10:17 +0100360 seq_printf(m, "%2d (%2d) %08llx %pad %p %d",
Rob Clark6f646092012-12-10 10:46:43 -0600361 obj->name, obj->refcount.refcount.counter,
Laurent Pinchartf4d1b022014-03-04 19:10:17 +0100362 off, &cma_obj->paddr, cma_obj->vaddr, obj->size);
Rob Clark6f646092012-12-10 10:46:43 -0600363
364 seq_printf(m, "\n");
365}
366EXPORT_SYMBOL_GPL(drm_gem_cma_describe);
367#endif
Laurent Pinchart71d72822013-02-17 01:57:30 +0100368
Thierry Redingd7883f82014-11-03 13:56:55 +0100369/**
370 * drm_gem_cma_prime_get_sg_table - provide a scatter/gather table of pinned
371 * pages for a CMA GEM object
372 * @obj: GEM object
373 *
374 * This function exports a scatter/gather table suitable for PRIME usage by
375 * calling the standard DMA mapping API. Drivers using the CMA helpers should
376 * set this as their DRM driver's ->gem_prime_get_sg_table() callback.
377 *
378 * Returns:
379 * A pointer to the scatter/gather table of pinned pages or NULL on failure.
380 */
Joonyoung Shim78467dc2013-06-28 14:24:54 +0900381struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj)
382{
383 struct drm_gem_cma_object *cma_obj = to_drm_gem_cma_obj(obj);
384 struct sg_table *sgt;
385 int ret;
386
387 sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
388 if (!sgt)
389 return NULL;
390
391 ret = dma_get_sgtable(obj->dev->dev, sgt, cma_obj->vaddr,
392 cma_obj->paddr, obj->size);
393 if (ret < 0)
394 goto out;
395
396 return sgt;
397
398out:
399 kfree(sgt);
400 return NULL;
401}
402EXPORT_SYMBOL_GPL(drm_gem_cma_prime_get_sg_table);
403
Thierry Redingd7883f82014-11-03 13:56:55 +0100404/**
405 * drm_gem_cma_prime_import_sg_table - produce a CMA GEM object from another
406 * driver's scatter/gather table of pinned pages
407 * @dev: device to import into
408 * @attach: DMA-BUF attachment
409 * @sgt: scatter/gather table of pinned pages
410 *
411 * This function imports a scatter/gather table exported via DMA-BUF by
412 * another driver. Imported buffers must be physically contiguous in memory
413 * (i.e. the scatter/gather table must contain a single entry). Drivers that
414 * use the CMA helpers should set this as their DRM driver's
415 * ->gem_prime_import_sg_table() callback.
416 *
417 * Returns:
418 * A pointer to a newly created GEM object or an ERR_PTR-encoded negative
419 * error code on failure.
420 */
Joonyoung Shim78467dc2013-06-28 14:24:54 +0900421struct drm_gem_object *
Maarten Lankhorstb5e9c1a2014-01-09 11:03:14 +0100422drm_gem_cma_prime_import_sg_table(struct drm_device *dev,
423 struct dma_buf_attachment *attach,
Joonyoung Shim78467dc2013-06-28 14:24:54 +0900424 struct sg_table *sgt)
425{
426 struct drm_gem_cma_object *cma_obj;
427
428 if (sgt->nents != 1)
429 return ERR_PTR(-EINVAL);
430
431 /* Create a CMA GEM buffer. */
Maarten Lankhorstb5e9c1a2014-01-09 11:03:14 +0100432 cma_obj = __drm_gem_cma_create(dev, attach->dmabuf->size);
Joonyoung Shim78467dc2013-06-28 14:24:54 +0900433 if (IS_ERR(cma_obj))
Sachin Kamate7c36342014-07-03 17:33:33 +0530434 return ERR_CAST(cma_obj);
Joonyoung Shim78467dc2013-06-28 14:24:54 +0900435
436 cma_obj->paddr = sg_dma_address(sgt->sgl);
437 cma_obj->sgt = sgt;
438
Maarten Lankhorstb5e9c1a2014-01-09 11:03:14 +0100439 DRM_DEBUG_PRIME("dma_addr = %pad, size = %zu\n", &cma_obj->paddr, attach->dmabuf->size);
Joonyoung Shim78467dc2013-06-28 14:24:54 +0900440
441 return &cma_obj->base;
442}
443EXPORT_SYMBOL_GPL(drm_gem_cma_prime_import_sg_table);
444
Thierry Redingd7883f82014-11-03 13:56:55 +0100445/**
446 * drm_gem_cma_prime_mmap - memory-map an exported CMA GEM object
447 * @obj: GEM object
448 * @vma: VMA for the area to be mapped
449 *
450 * This function maps a buffer imported via DRM PRIME into a userspace
451 * process's address space. Drivers that use the CMA helpers should set this
452 * as their DRM driver's ->gem_prime_mmap() callback.
453 *
454 * Returns:
455 * 0 on success or a negative error code on failure.
456 */
Joonyoung Shim78467dc2013-06-28 14:24:54 +0900457int drm_gem_cma_prime_mmap(struct drm_gem_object *obj,
458 struct vm_area_struct *vma)
459{
460 struct drm_gem_cma_object *cma_obj;
461 struct drm_device *dev = obj->dev;
462 int ret;
463
464 mutex_lock(&dev->struct_mutex);
465 ret = drm_gem_mmap_obj(obj, obj->size, vma);
466 mutex_unlock(&dev->struct_mutex);
467 if (ret < 0)
468 return ret;
469
470 cma_obj = to_drm_gem_cma_obj(obj);
471 return drm_gem_cma_mmap_obj(cma_obj, vma);
472}
473EXPORT_SYMBOL_GPL(drm_gem_cma_prime_mmap);
474
Thierry Redingd7883f82014-11-03 13:56:55 +0100475/**
476 * drm_gem_cma_prime_vmap - map a CMA GEM object into the kernel's virtual
477 * address space
478 * @obj: GEM object
479 *
480 * This function maps a buffer exported via DRM PRIME into the kernel's
481 * virtual address space. Since the CMA buffers are already mapped into the
482 * kernel virtual address space this simply returns the cached virtual
483 * address. Drivers using the CMA helpers should set this as their DRM
484 * driver's ->gem_prime_vmap() callback.
485 *
486 * Returns:
487 * The kernel virtual address of the CMA GEM object's backing store.
488 */
Joonyoung Shim78467dc2013-06-28 14:24:54 +0900489void *drm_gem_cma_prime_vmap(struct drm_gem_object *obj)
490{
491 struct drm_gem_cma_object *cma_obj = to_drm_gem_cma_obj(obj);
492
493 return cma_obj->vaddr;
494}
495EXPORT_SYMBOL_GPL(drm_gem_cma_prime_vmap);
496
Thierry Redingd7883f82014-11-03 13:56:55 +0100497/**
498 * drm_gem_cma_prime_vunmap - unmap a CMA GEM object from the kernel's virtual
499 * address space
500 * @obj: GEM object
501 * @vaddr: kernel virtual address where the CMA GEM object was mapped
502 *
503 * This function removes a buffer exported via DRM PRIME from the kernel's
504 * virtual address space. This is a no-op because CMA buffers cannot be
505 * unmapped from kernel space. Drivers using the CMA helpers should set this
506 * as their DRM driver's ->gem_prime_vunmap() callback.
507 */
Joonyoung Shim78467dc2013-06-28 14:24:54 +0900508void drm_gem_cma_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
509{
510 /* Nothing to do */
511}
512EXPORT_SYMBOL_GPL(drm_gem_cma_prime_vunmap);