drm/rockchip: gem: add get phys ioctl
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / drm / rockchip / rockchip_drm_gem.h
1 /*
2  * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
3  * Author:Mark Yao <mark.yao@rock-chips.com>
4  *
5  * This software is licensed under the terms of the GNU General Public
6  * License version 2, as published by the Free Software Foundation, and
7  * may be copied, distributed, and modified under those terms.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14
15 #ifndef _ROCKCHIP_DRM_GEM_H
16 #define _ROCKCHIP_DRM_GEM_H
17
18 #define to_rockchip_obj(x) container_of(x, struct rockchip_gem_object, base)
19
20 enum rockchip_gem_buf_type {
21         ROCKCHIP_GEM_BUF_TYPE_CMA,
22         ROCKCHIP_GEM_BUF_TYPE_SHMEM,
23 };
24
25 struct rockchip_gem_object {
26         struct drm_gem_object base;
27         unsigned int flags;
28         enum rockchip_gem_buf_type buf_type;
29
30         void *kvaddr;
31         void *cookie;
32         dma_addr_t dma_addr;
33         dma_addr_t dma_handle;
34
35         /* Used when IOMMU is disabled */
36         struct dma_attrs dma_attrs;
37
38 #ifdef CONFIG_DRM_DMA_SYNC
39         struct fence *acquire_fence;
40         atomic_t acquire_shared_count;
41         bool acquire_exclusive;
42 #endif
43         /* Used when IOMMU is enabled */
44         struct drm_mm_node mm;
45         unsigned long num_pages;
46         struct page **pages;
47         struct sg_table *sgt;
48         size_t size;
49 };
50
51 /*
52  * rockchip drm GEM object linked list structure.
53  *
54  * @list: list link.
55  * @rockchip_gem_obj: struct rockchhip_gem_object that this entry points to.
56  */
57 struct rockchip_gem_object_node {
58         struct list_head                list;
59         struct rockchip_gem_object      *rockchip_gem_obj;
60 };
61
62 struct sg_table *rockchip_gem_prime_get_sg_table(struct drm_gem_object *obj);
63 struct drm_gem_object *
64 rockchip_gem_prime_import_sg_table(struct drm_device *dev,
65                                    struct dma_buf_attachment *attach,
66                                    struct sg_table *sg);
67 void *rockchip_gem_prime_vmap(struct drm_gem_object *obj);
68 void rockchip_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
69
70 /* drm driver mmap file operations */
71 int rockchip_gem_mmap(struct file *filp, struct vm_area_struct *vma);
72
73 /* mmap a gem object to userspace. */
74 int rockchip_gem_mmap_buf(struct drm_gem_object *obj,
75                           struct vm_area_struct *vma);
76
77 struct rockchip_gem_object *
78 rockchip_gem_create_object(struct drm_device *drm, unsigned int size,
79                            bool alloc_kmap, unsigned int flags);
80
81 void rockchip_gem_free_object(struct drm_gem_object *obj);
82
83 int rockchip_gem_dumb_create(struct drm_file *file_priv,
84                              struct drm_device *dev,
85                              struct drm_mode_create_dumb *args);
86 int rockchip_gem_dumb_map_offset(struct drm_file *file_priv,
87                                  struct drm_device *dev, uint32_t handle,
88                                  uint64_t *offset);
89 /*
90  * request gem object creation and buffer allocation as the size
91  * that it is calculated with framebuffer information such as width,
92  * height and bpp.
93  */
94 int rockchip_gem_create_ioctl(struct drm_device *dev, void *data,
95                               struct drm_file *file_priv);
96
97 /* get buffer offset to map to user space. */
98 int rockchip_gem_map_offset_ioctl(struct drm_device *dev, void *data,
99                                   struct drm_file *file_priv);
100
101 int rockchip_gem_get_phys_ioctl(struct drm_device *dev, void *data,
102                                 struct drm_file *file_priv);
103
104 /*
105  * acquire gem object for CPU access.
106  */
107 int rockchip_gem_cpu_acquire_ioctl(struct drm_device *dev, void* data,
108                                    struct drm_file *file_priv);
109 /*
110  * release gem object after CPU access.
111  */
112 int rockchip_gem_cpu_release_ioctl(struct drm_device *dev, void* data,
113                                    struct drm_file *file_priv);
114
115 int rockchip_gem_prime_begin_cpu_access(struct drm_gem_object *obj,
116                                         size_t start, size_t len,
117                                         enum dma_data_direction dir);
118
119 void rockchip_gem_prime_end_cpu_access(struct drm_gem_object *obj,
120                                        size_t start, size_t len,
121                                        enum dma_data_direction dir);
122
123 #endif /* _ROCKCHIP_DRM_GEM_H */