drm: Extract <drm/drm_gem.h>
[deliverable/linux.git] / drivers / gpu / drm / exynos / exynos_drm_gem.h
CommitLineData
1c248b7d
ID
1/* exynos_drm_gem.h
2 *
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * Authoer: Inki Dae <inki.dae@samsung.com>
5 *
d81aecb5
ID
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
1c248b7d
ID
10 */
11
12#ifndef _EXYNOS_DRM_GEM_H_
13#define _EXYNOS_DRM_GEM_H_
14
d9fc9413
DV
15#include <drm/drm_gem.h>
16
1c248b7d
ID
17#define to_exynos_gem_obj(x) container_of(x,\
18 struct exynos_drm_gem_obj, base)
19
dcf9af82
ID
20#define IS_NONCONTIG_BUFFER(f) (f & EXYNOS_BO_NONCONTIG)
21
2c871127
ID
22/*
23 * exynos drm gem buffer structure.
24 *
25 * @kvaddr: kernel virtual address to allocated memory region.
2a3098ff 26 * *userptr: user space address.
2c871127
ID
27 * @dma_addr: bus address(accessed by dma) to allocated memory region.
28 * - this address could be physical address without IOMMU and
29 * device address with IOMMU.
2a3098ff 30 * @write: whether pages will be written to by the caller.
4744ad24 31 * @pages: Array of backing pages.
2b35892e 32 * @sgt: sg table to transfer page data.
2c871127 33 * @size: size of allocated memory region.
2a3098ff
ID
34 * @pfnmap: indicate whether memory region from userptr is mmaped with
35 * VM_PFNMAP or not.
2c871127
ID
36 */
37struct exynos_drm_gem_buf {
38 void __iomem *kvaddr;
2a3098ff 39 unsigned long userptr;
2c871127 40 dma_addr_t dma_addr;
0519f9a1 41 struct dma_attrs dma_attrs;
2a3098ff 42 unsigned int write;
4744ad24 43 struct page **pages;
2b35892e 44 struct sg_table *sgt;
2c871127 45 unsigned long size;
2a3098ff 46 bool pfnmap;
2c871127
ID
47};
48
1c248b7d
ID
49/*
50 * exynos drm buffer structure.
51 *
52 * @base: a gem object.
53 * - a new handle to this gem object would be created
54 * by drm_gem_handle_create().
2c871127
ID
55 * @buffer: a pointer to exynos_drm_gem_buffer object.
56 * - contain the information to memory region allocated
57 * by user request or at framebuffer creation.
1c248b7d
ID
58 * continuous memory region allocated by user request
59 * or at framebuffer creation.
3c52b880
ID
60 * @size: size requested from user, in bytes and this size is aligned
61 * in page unit.
2a3098ff 62 * @vma: a pointer to vm_area.
2b35892e 63 * @flags: indicate memory type to allocated buffer and cache attruibute.
1c248b7d 64 *
c6b78bc8 65 * P.S. this object would be transferred to user as kms_bo.handle so
1c248b7d
ID
66 * user can access the buffer through kms_bo.handle.
67 */
68struct exynos_drm_gem_obj {
ee5e770e
JS
69 struct drm_gem_object base;
70 struct exynos_drm_gem_buf *buffer;
2b35892e 71 unsigned long size;
2a3098ff 72 struct vm_area_struct *vma;
2b35892e 73 unsigned int flags;
1c248b7d
ID
74};
75
b2df26c1
ID
76struct page **exynos_gem_get_pages(struct drm_gem_object *obj, gfp_t gfpmask);
77
2364839a
JS
78/* destroy a buffer with gem object */
79void exynos_drm_gem_destroy(struct exynos_drm_gem_obj *exynos_gem_obj);
80
b2df26c1
ID
81/* create a private gem object and initialize it. */
82struct exynos_drm_gem_obj *exynos_drm_gem_init(struct drm_device *dev,
83 unsigned long size);
84
2364839a 85/* create a new buffer with gem object */
f088d5a9 86struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
2b35892e
ID
87 unsigned int flags,
88 unsigned long size);
1c248b7d
ID
89
90/*
91 * request gem object creation and buffer allocation as the size
92 * that it is calculated with framebuffer information such as width,
93 * height and bpp.
94 */
95int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
ee5e770e 96 struct drm_file *file_priv);
1c248b7d 97
f0b1bda7
ID
98/*
99 * get dma address from gem handle and this function could be used for
100 * other drivers such as 2d/3d acceleration drivers.
101 * with this function call, gem object reference count would be increased.
102 */
d87342c1 103dma_addr_t *exynos_drm_gem_get_dma_addr(struct drm_device *dev,
f0b1bda7 104 unsigned int gem_handle,
d87342c1 105 struct drm_file *filp);
f0b1bda7
ID
106
107/*
108 * put dma address from gem handle and this function could be used for
109 * other drivers such as 2d/3d acceleration drivers.
110 * with this function call, gem object reference count would be decreased.
111 */
112void exynos_drm_gem_put_dma_addr(struct drm_device *dev,
113 unsigned int gem_handle,
d87342c1 114 struct drm_file *filp);
f0b1bda7 115
2a3098ff
ID
116/* map user space allocated by malloc to pages. */
117int exynos_drm_gem_userptr_ioctl(struct drm_device *dev, void *data,
118 struct drm_file *file_priv);
119
40cd7e0c
ID
120/* get buffer information to memory region allocated by gem. */
121int exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data,
122 struct drm_file *file_priv);
123
a4f19aaa
ID
124/* get buffer size to gem handle. */
125unsigned long exynos_drm_gem_get_size(struct drm_device *dev,
126 unsigned int gem_handle,
127 struct drm_file *file_priv);
128
1c248b7d
ID
129/* free gem object. */
130void exynos_drm_gem_free_object(struct drm_gem_object *gem_obj);
131
132/* create memory region for drm framebuffer. */
133int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
ee5e770e
JS
134 struct drm_device *dev,
135 struct drm_mode_create_dumb *args);
1c248b7d
ID
136
137/* map memory region for drm framebuffer to user space. */
138int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv,
ee5e770e
JS
139 struct drm_device *dev, uint32_t handle,
140 uint64_t *offset);
1c248b7d 141
ee5e770e
JS
142/* page fault handler and mmap fault address(virtual) to physical memory. */
143int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
144
145/* set vm_flags and we can change the vm attribute to other one at here. */
146int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
1c248b7d 147
2a3098ff
ID
148static inline int vma_is_io(struct vm_area_struct *vma)
149{
150 return !!(vma->vm_flags & (VM_IO | VM_PFNMAP));
151}
152
153/* get a copy of a virtual memory region. */
154struct vm_area_struct *exynos_gem_get_vma(struct vm_area_struct *vma);
155
156/* release a userspace virtual memory area. */
157void exynos_gem_put_vma(struct vm_area_struct *vma);
158
159/* get pages from user space. */
160int exynos_gem_get_pages_from_userptr(unsigned long start,
161 unsigned int npages,
162 struct page **pages,
163 struct vm_area_struct *vma);
164
165/* drop the reference to pages. */
166void exynos_gem_put_pages_to_userptr(struct page **pages,
167 unsigned int npages,
168 struct vm_area_struct *vma);
169
170/* map sgt with dma region. */
171int exynos_gem_map_sgt_with_dma(struct drm_device *drm_dev,
172 struct sg_table *sgt,
173 enum dma_data_direction dir);
174
175/* unmap sgt from dma region. */
176void exynos_gem_unmap_sgt_from_dma(struct drm_device *drm_dev,
177 struct sg_table *sgt,
178 enum dma_data_direction dir);
179
1c248b7d 180#endif
This page took 0.179593 seconds and 5 git commands to generate.