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