Merge remote-tracking branch 'asoc/topic/core' into asoc-next
[linux-2.6-block.git] / drivers / gpu / drm / msm / msm_gem_prime.c
CommitLineData
05b84911
RC
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
b5e9c1a2 21#include <linux/dma-buf.h>
05b84911
RC
22
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);
ac451467
RC
26 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);
05b84911
RC
32}
33
34void *msm_gem_prime_vmap(struct drm_gem_object *obj)
35{
36 return msm_gem_vaddr(obj);
37}
38
39void msm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
40{
41 /* TODO msm_gem_vunmap() */
42}
43
77a147e7
DT
44int msm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
45{
46 int ret;
47
48 mutex_lock(&obj->dev->struct_mutex);
49 ret = drm_gem_mmap_obj(obj, obj->size, vma);
50 mutex_unlock(&obj->dev->struct_mutex);
51 if (ret < 0)
52 return ret;
53
54 return msm_gem_mmap_obj(vma->vm_private_data, vma);
55}
56
05b84911 57struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev,
b5e9c1a2 58 struct dma_buf_attachment *attach, struct sg_table *sg)
05b84911 59{
b5e9c1a2 60 return msm_gem_import(dev, attach->dmabuf->size, sg);
05b84911
RC
61}
62
63int msm_gem_prime_pin(struct drm_gem_object *obj)
64{
65 if (!obj->import_attach)
66 msm_gem_get_pages(obj);
67 return 0;
68}
69
70void msm_gem_prime_unpin(struct drm_gem_object *obj)
71{
72 if (!obj->import_attach)
73 msm_gem_put_pages(obj);
74}