blob: 60bb290700cef9c32fc2ca0dd2db229a6a7ffedf [file] [log] [blame]
Rob Clark05b84912013-09-28 11:28:35 -04001/*
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
Maarten Lankhorstb5e9c1a2014-01-09 11:03:14 +010021#include <linux/dma-buf.h>
Rob Clark05b84912013-09-28 11:28:35 -040022
23struct 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);
Rob Clarkac451462015-07-23 13:44:56 -040026 int npages = obj->size >> PAGE_SHIFT;
27
28 if (WARN_ON(!msm_obj->pages)) /* should have already pinned! */
29 return NULL;
30
31 return drm_prime_pages_to_sg(msm_obj->pages, npages);
Rob Clark05b84912013-09-28 11:28:35 -040032}
33
34void *msm_gem_prime_vmap(struct drm_gem_object *obj)
35{
Rob Clark18f23042016-05-26 16:24:35 -040036 return msm_gem_get_vaddr(obj);
Rob Clark05b84912013-09-28 11:28:35 -040037}
38
39void msm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
40{
Rob Clark18f23042016-05-26 16:24:35 -040041 msm_gem_put_vaddr(obj);
Rob Clark05b84912013-09-28 11:28:35 -040042}
43
Daniel Thompson77a147e2014-11-12 11:38:14 +000044int msm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
45{
46 int ret;
47
Daniel Thompson77a147e2014-11-12 11:38:14 +000048 ret = drm_gem_mmap_obj(obj, obj->size, vma);
Daniel Thompson77a147e2014-11-12 11:38:14 +000049 if (ret < 0)
50 return ret;
51
52 return msm_gem_mmap_obj(vma->vm_private_data, vma);
53}
54
Rob Clark05b84912013-09-28 11:28:35 -040055struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev,
Maarten Lankhorstb5e9c1a2014-01-09 11:03:14 +010056 struct dma_buf_attachment *attach, struct sg_table *sg)
Rob Clark05b84912013-09-28 11:28:35 -040057{
Rob Clark79f0e202016-03-16 12:40:35 -040058 return msm_gem_import(dev, attach->dmabuf, sg);
Rob Clark05b84912013-09-28 11:28:35 -040059}
60
61int msm_gem_prime_pin(struct drm_gem_object *obj)
62{
63 if (!obj->import_attach)
64 msm_gem_get_pages(obj);
65 return 0;
66}
67
68void msm_gem_prime_unpin(struct drm_gem_object *obj)
69{
70 if (!obj->import_attach)
71 msm_gem_put_pages(obj);
72}