xref: /linux/drivers/gpu/drm/msm/msm_gem_prime.c (revision e0bf6c5ca2d3281f231c5f0c9bf145e9513644de)
1 /*
2  * Copyright (C) 2013 Red Hat
3  * Author: Rob Clark <robdclark@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published by
7  * the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "msm_drv.h"
19 #include "msm_gem.h"
20 
21 #include <linux/dma-buf.h>
22 
23 struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj)
24 {
25 	struct msm_gem_object *msm_obj = to_msm_bo(obj);
26 	BUG_ON(!msm_obj->sgt);  /* should have already pinned! */
27 	return msm_obj->sgt;
28 }
29 
30 void *msm_gem_prime_vmap(struct drm_gem_object *obj)
31 {
32 	return msm_gem_vaddr(obj);
33 }
34 
35 void msm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
36 {
37 	/* TODO msm_gem_vunmap() */
38 }
39 
40 int msm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
41 {
42 	int ret;
43 
44 	mutex_lock(&obj->dev->struct_mutex);
45 	ret = drm_gem_mmap_obj(obj, obj->size, vma);
46 	mutex_unlock(&obj->dev->struct_mutex);
47 	if (ret < 0)
48 		return ret;
49 
50 	return msm_gem_mmap_obj(vma->vm_private_data, vma);
51 }
52 
53 struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev,
54 		struct dma_buf_attachment *attach, struct sg_table *sg)
55 {
56 	return msm_gem_import(dev, attach->dmabuf->size, sg);
57 }
58 
59 int msm_gem_prime_pin(struct drm_gem_object *obj)
60 {
61 	if (!obj->import_attach)
62 		msm_gem_get_pages(obj);
63 	return 0;
64 }
65 
66 void msm_gem_prime_unpin(struct drm_gem_object *obj)
67 {
68 	if (!obj->import_attach)
69 		msm_gem_put_pages(obj);
70 }
71