]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/exynos/exynos_drm_gem.h
d3ea106a9a77a2bbb9f034eb6dc55d948faac1c3
[karo-tx-linux.git] / drivers / gpu / drm / exynos / exynos_drm_gem.h
1 /* exynos_drm_gem.h
2  *
3  * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4  * Authoer: Inki Dae <inki.dae@samsung.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23  * OTHER DEALINGS IN THE SOFTWARE.
24  */
25
26 #ifndef _EXYNOS_DRM_GEM_H_
27 #define _EXYNOS_DRM_GEM_H_
28
29 #define to_exynos_gem_obj(x)    container_of(x,\
30                         struct exynos_drm_gem_obj, base)
31
32 #define IS_NONCONTIG_BUFFER(f)          (f & EXYNOS_BO_NONCONTIG)
33
34 /*
35  * exynos drm gem buffer structure.
36  *
37  * @kvaddr: kernel virtual address to allocated memory region.
38  * *userptr: user space address.
39  * @dma_addr: bus address(accessed by dma) to allocated memory region.
40  *      - this address could be physical address without IOMMU and
41  *      device address with IOMMU.
42  * @write: whether pages will be written to by the caller.
43  * @sgt: sg table to transfer page data.
44  * @size: size of allocated memory region.
45  * @pfnmap: indicate whether memory region from userptr is mmaped with
46  *      VM_PFNMAP or not.
47  */
48 struct exynos_drm_gem_buf {
49         void __iomem            *kvaddr;
50         unsigned long           userptr;
51         dma_addr_t              dma_addr;
52         struct dma_attrs        dma_attrs;
53         unsigned int            write;
54         struct sg_table         *sgt;
55         unsigned long           size;
56         bool                    pfnmap;
57 };
58
59 /*
60  * exynos drm buffer structure.
61  *
62  * @base: a gem object.
63  *      - a new handle to this gem object would be created
64  *      by drm_gem_handle_create().
65  * @buffer: a pointer to exynos_drm_gem_buffer object.
66  *      - contain the information to memory region allocated
67  *      by user request or at framebuffer creation.
68  *      continuous memory region allocated by user request
69  *      or at framebuffer creation.
70  * @size: size requested from user, in bytes and this size is aligned
71  *      in page unit.
72  * @vma: a pointer to vm_area.
73  * @flags: indicate memory type to allocated buffer and cache attruibute.
74  *
75  * P.S. this object would be transfered to user as kms_bo.handle so
76  *      user can access the buffer through kms_bo.handle.
77  */
78 struct exynos_drm_gem_obj {
79         struct drm_gem_object           base;
80         struct exynos_drm_gem_buf       *buffer;
81         unsigned long                   size;
82         struct vm_area_struct           *vma;
83         unsigned int                    flags;
84 };
85
86 struct page **exynos_gem_get_pages(struct drm_gem_object *obj, gfp_t gfpmask);
87
88 /* destroy a buffer with gem object */
89 void exynos_drm_gem_destroy(struct exynos_drm_gem_obj *exynos_gem_obj);
90
91 /* create a private gem object and initialize it. */
92 struct exynos_drm_gem_obj *exynos_drm_gem_init(struct drm_device *dev,
93                                                       unsigned long size);
94
95 /* create a new buffer with gem object */
96 struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
97                                                 unsigned int flags,
98                                                 unsigned long size);
99
100 /*
101  * request gem object creation and buffer allocation as the size
102  * that it is calculated with framebuffer information such as width,
103  * height and bpp.
104  */
105 int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
106                                 struct drm_file *file_priv);
107
108 /*
109  * get dma address from gem handle and this function could be used for
110  * other drivers such as 2d/3d acceleration drivers.
111  * with this function call, gem object reference count would be increased.
112  */
113 dma_addr_t *exynos_drm_gem_get_dma_addr(struct drm_device *dev,
114                                         unsigned int gem_handle,
115                                         struct drm_file *filp);
116
117 /*
118  * put dma address from gem handle and this function could be used for
119  * other drivers such as 2d/3d acceleration drivers.
120  * with this function call, gem object reference count would be decreased.
121  */
122 void exynos_drm_gem_put_dma_addr(struct drm_device *dev,
123                                         unsigned int gem_handle,
124                                         struct drm_file *filp);
125
126 /* get buffer offset to map to user space. */
127 int exynos_drm_gem_map_offset_ioctl(struct drm_device *dev, void *data,
128                                     struct drm_file *file_priv);
129
130 /*
131  * mmap the physically continuous memory that a gem object contains
132  * to user space.
133  */
134 int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
135                               struct drm_file *file_priv);
136
137 /* map user space allocated by malloc to pages. */
138 int exynos_drm_gem_userptr_ioctl(struct drm_device *dev, void *data,
139                                       struct drm_file *file_priv);
140
141 /* get buffer information to memory region allocated by gem. */
142 int exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data,
143                                       struct drm_file *file_priv);
144
145 /* initialize gem object. */
146 int exynos_drm_gem_init_object(struct drm_gem_object *obj);
147
148 /* free gem object. */
149 void exynos_drm_gem_free_object(struct drm_gem_object *gem_obj);
150
151 /* create memory region for drm framebuffer. */
152 int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
153                                struct drm_device *dev,
154                                struct drm_mode_create_dumb *args);
155
156 /* map memory region for drm framebuffer to user space. */
157 int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv,
158                                    struct drm_device *dev, uint32_t handle,
159                                    uint64_t *offset);
160
161 /*
162  * destroy memory region allocated.
163  *      - a gem handle and physical memory region pointed by a gem object
164  *      would be released by drm_gem_handle_delete().
165  */
166 int exynos_drm_gem_dumb_destroy(struct drm_file *file_priv,
167                                 struct drm_device *dev,
168                                 unsigned int handle);
169
170 /* page fault handler and mmap fault address(virtual) to physical memory. */
171 int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
172
173 /* set vm_flags and we can change the vm attribute to other one at here. */
174 int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
175
176 static inline int vma_is_io(struct vm_area_struct *vma)
177 {
178         return !!(vma->vm_flags & (VM_IO | VM_PFNMAP));
179 }
180
181 /* get a copy of a virtual memory region. */
182 struct vm_area_struct *exynos_gem_get_vma(struct vm_area_struct *vma);
183
184 /* release a userspace virtual memory area. */
185 void exynos_gem_put_vma(struct vm_area_struct *vma);
186
187 /* get pages from user space. */
188 int exynos_gem_get_pages_from_userptr(unsigned long start,
189                                                 unsigned int npages,
190                                                 struct page **pages,
191                                                 struct vm_area_struct *vma);
192
193 /* drop the reference to pages. */
194 void exynos_gem_put_pages_to_userptr(struct page **pages,
195                                         unsigned int npages,
196                                         struct vm_area_struct *vma);
197
198 /* map sgt with dma region. */
199 int exynos_gem_map_sgt_with_dma(struct drm_device *drm_dev,
200                                 struct sg_table *sgt,
201                                 enum dma_data_direction dir);
202
203 /* unmap sgt from dma region. */
204 void exynos_gem_unmap_sgt_from_dma(struct drm_device *drm_dev,
205                                 struct sg_table *sgt,
206                                 enum dma_data_direction dir);
207
208 #endif