3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * Authoer: Inki Dae <inki.dae@samsung.com>
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:
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
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.
26 #ifndef _EXYNOS_DRM_GEM_H_
27 #define _EXYNOS_DRM_GEM_H_
29 #define to_exynos_gem_obj(x) container_of(x,\
30 struct exynos_drm_gem_obj, base)
32 #define IS_NONCONTIG_BUFFER(f) (f & EXYNOS_BO_NONCONTIG)
35 * exynos drm gem buffer structure.
37 * @kvaddr: kernel virtual address to allocated memory region.
38 * @dma_addr: bus address(accessed by dma) to allocated memory region.
39 * - this address could be physical address without IOMMU and
40 * device address with IOMMU.
41 * @sgt: sg table to transfer page data.
42 * @pages: contain all pages to allocated memory region.
43 * @page_size: could be 4K, 64K or 1MB.
44 * @size: size of allocated memory region.
46 struct exynos_drm_gem_buf
{
51 unsigned long page_size
;
56 * exynos drm buffer structure.
58 * @base: a gem object.
59 * - a new handle to this gem object would be created
60 * by drm_gem_handle_create().
61 * @buffer: a pointer to exynos_drm_gem_buffer object.
62 * - contain the information to memory region allocated
63 * by user request or at framebuffer creation.
64 * continuous memory region allocated by user request
65 * or at framebuffer creation.
66 * @size: total memory size to physically non-continuous memory region.
67 * @flags: indicate memory type to allocated buffer and cache attruibute.
69 * P.S. this object would be transfered to user as kms_bo.handle so
70 * user can access the buffer through kms_bo.handle.
72 struct exynos_drm_gem_obj
{
73 struct drm_gem_object base
;
74 struct exynos_drm_gem_buf
*buffer
;
79 struct page
**exynos_gem_get_pages(struct drm_gem_object
*obj
, gfp_t gfpmask
);
81 /* destroy a buffer with gem object */
82 void exynos_drm_gem_destroy(struct exynos_drm_gem_obj
*exynos_gem_obj
);
84 /* create a private gem object and initialize it. */
85 struct exynos_drm_gem_obj
*exynos_drm_gem_init(struct drm_device
*dev
,
88 /* create a new buffer with gem object */
89 struct exynos_drm_gem_obj
*exynos_drm_gem_create(struct drm_device
*dev
,
94 * request gem object creation and buffer allocation as the size
95 * that it is calculated with framebuffer information such as width,
98 int exynos_drm_gem_create_ioctl(struct drm_device
*dev
, void *data
,
99 struct drm_file
*file_priv
);
102 * get dma address from gem handle and this function could be used for
103 * other drivers such as 2d/3d acceleration drivers.
104 * with this function call, gem object reference count would be increased.
106 void *exynos_drm_gem_get_dma_addr(struct drm_device
*dev
,
107 unsigned int gem_handle
,
108 struct drm_file
*file_priv
);
111 * put dma address from gem handle and this function could be used for
112 * other drivers such as 2d/3d acceleration drivers.
113 * with this function call, gem object reference count would be decreased.
115 void exynos_drm_gem_put_dma_addr(struct drm_device
*dev
,
116 unsigned int gem_handle
,
117 struct drm_file
*file_priv
);
119 /* get buffer offset to map to user space. */
120 int exynos_drm_gem_map_offset_ioctl(struct drm_device
*dev
, void *data
,
121 struct drm_file
*file_priv
);
124 * mmap the physically continuous memory that a gem object contains
127 int exynos_drm_gem_mmap_ioctl(struct drm_device
*dev
, void *data
,
128 struct drm_file
*file_priv
);
130 /* get buffer information to memory region allocated by gem. */
131 int exynos_drm_gem_get_ioctl(struct drm_device
*dev
, void *data
,
132 struct drm_file
*file_priv
);
134 /* initialize gem object. */
135 int exynos_drm_gem_init_object(struct drm_gem_object
*obj
);
137 /* free gem object. */
138 void exynos_drm_gem_free_object(struct drm_gem_object
*gem_obj
);
140 /* create memory region for drm framebuffer. */
141 int exynos_drm_gem_dumb_create(struct drm_file
*file_priv
,
142 struct drm_device
*dev
,
143 struct drm_mode_create_dumb
*args
);
145 /* map memory region for drm framebuffer to user space. */
146 int exynos_drm_gem_dumb_map_offset(struct drm_file
*file_priv
,
147 struct drm_device
*dev
, uint32_t handle
,
151 * destroy memory region allocated.
152 * - a gem handle and physical memory region pointed by a gem object
153 * would be released by drm_gem_handle_delete().
155 int exynos_drm_gem_dumb_destroy(struct drm_file
*file_priv
,
156 struct drm_device
*dev
,
157 unsigned int handle
);
159 /* page fault handler and mmap fault address(virtual) to physical memory. */
160 int exynos_drm_gem_fault(struct vm_area_struct
*vma
, struct vm_fault
*vmf
);
162 /* set vm_flags and we can change the vm attribute to other one at here. */
163 int exynos_drm_gem_mmap(struct file
*filp
, struct vm_area_struct
*vma
);