3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * Authoer: Inki Dae <inki.dae@samsung.com>
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.
12 #ifndef _EXYNOS_DRM_GEM_H_
13 #define _EXYNOS_DRM_GEM_H_
15 #define to_exynos_gem_obj(x) container_of(x,\
16 struct exynos_drm_gem_obj, base)
18 #define IS_NONCONTIG_BUFFER(f) (f & EXYNOS_BO_NONCONTIG)
21 * exynos drm gem buffer structure.
23 * @kvaddr: kernel virtual address to allocated memory region.
24 * *userptr: user space address.
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.
28 * @write: whether pages will be written to by the caller.
29 * @pages: Array of backing pages.
30 * @sgt: sg table to transfer page data.
31 * @size: size of allocated memory region.
32 * @pfnmap: indicate whether memory region from userptr is mmaped with
35 struct exynos_drm_gem_buf
{
37 unsigned long userptr
;
39 struct dma_attrs dma_attrs
;
48 * exynos drm buffer structure.
50 * @base: a gem object.
51 * - a new handle to this gem object would be created
52 * by drm_gem_handle_create().
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.
56 * continuous memory region allocated by user request
57 * or at framebuffer creation.
58 * @size: size requested from user, in bytes and this size is aligned
60 * @vma: a pointer to vm_area.
61 * @flags: indicate memory type to allocated buffer and cache attruibute.
63 * P.S. this object would be transferred to user as kms_bo.handle so
64 * user can access the buffer through kms_bo.handle.
66 struct exynos_drm_gem_obj
{
67 struct drm_gem_object base
;
68 struct exynos_drm_gem_buf
*buffer
;
70 struct vm_area_struct
*vma
;
74 struct page
**exynos_gem_get_pages(struct drm_gem_object
*obj
, gfp_t gfpmask
);
76 /* destroy a buffer with gem object */
77 void exynos_drm_gem_destroy(struct exynos_drm_gem_obj
*exynos_gem_obj
);
79 /* create a private gem object and initialize it. */
80 struct exynos_drm_gem_obj
*exynos_drm_gem_init(struct drm_device
*dev
,
83 /* create a new buffer with gem object */
84 struct exynos_drm_gem_obj
*exynos_drm_gem_create(struct drm_device
*dev
,
89 * request gem object creation and buffer allocation as the size
90 * that it is calculated with framebuffer information such as width,
93 int exynos_drm_gem_create_ioctl(struct drm_device
*dev
, void *data
,
94 struct drm_file
*file_priv
);
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.
101 dma_addr_t
*exynos_drm_gem_get_dma_addr(struct drm_device
*dev
,
102 unsigned int gem_handle
,
103 struct drm_file
*filp
);
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.
110 void exynos_drm_gem_put_dma_addr(struct drm_device
*dev
,
111 unsigned int gem_handle
,
112 struct drm_file
*filp
);
114 /* get buffer offset to map to user space. */
115 int exynos_drm_gem_map_offset_ioctl(struct drm_device
*dev
, void *data
,
116 struct drm_file
*file_priv
);
119 * mmap the physically continuous memory that a gem object contains
122 int exynos_drm_gem_mmap_ioctl(struct drm_device
*dev
, void *data
,
123 struct drm_file
*file_priv
);
125 int exynos_drm_gem_mmap_buffer(struct file
*filp
,
126 struct vm_area_struct
*vma
);
128 /* map user space allocated by malloc to pages. */
129 int exynos_drm_gem_userptr_ioctl(struct drm_device
*dev
, void *data
,
130 struct drm_file
*file_priv
);
132 /* get buffer information to memory region allocated by gem. */
133 int exynos_drm_gem_get_ioctl(struct drm_device
*dev
, void *data
,
134 struct drm_file
*file_priv
);
136 /* get buffer size to gem handle. */
137 unsigned long exynos_drm_gem_get_size(struct drm_device
*dev
,
138 unsigned int gem_handle
,
139 struct drm_file
*file_priv
);
141 /* free gem object. */
142 void exynos_drm_gem_free_object(struct drm_gem_object
*gem_obj
);
144 /* create memory region for drm framebuffer. */
145 int exynos_drm_gem_dumb_create(struct drm_file
*file_priv
,
146 struct drm_device
*dev
,
147 struct drm_mode_create_dumb
*args
);
149 /* map memory region for drm framebuffer to user space. */
150 int exynos_drm_gem_dumb_map_offset(struct drm_file
*file_priv
,
151 struct drm_device
*dev
, uint32_t handle
,
154 /* page fault handler and mmap fault address(virtual) to physical memory. */
155 int exynos_drm_gem_fault(struct vm_area_struct
*vma
, struct vm_fault
*vmf
);
157 /* set vm_flags and we can change the vm attribute to other one at here. */
158 int exynos_drm_gem_mmap(struct file
*filp
, struct vm_area_struct
*vma
);
160 static inline int vma_is_io(struct vm_area_struct
*vma
)
162 return !!(vma
->vm_flags
& (VM_IO
| VM_PFNMAP
));
165 /* get a copy of a virtual memory region. */
166 struct vm_area_struct
*exynos_gem_get_vma(struct vm_area_struct
*vma
);
168 /* release a userspace virtual memory area. */
169 void exynos_gem_put_vma(struct vm_area_struct
*vma
);
171 /* get pages from user space. */
172 int exynos_gem_get_pages_from_userptr(unsigned long start
,
175 struct vm_area_struct
*vma
);
177 /* drop the reference to pages. */
178 void exynos_gem_put_pages_to_userptr(struct page
**pages
,
180 struct vm_area_struct
*vma
);
182 /* map sgt with dma region. */
183 int exynos_gem_map_sgt_with_dma(struct drm_device
*drm_dev
,
184 struct sg_table
*sgt
,
185 enum dma_data_direction dir
);
187 /* unmap sgt from dma region. */
188 void exynos_gem_unmap_sgt_from_dma(struct drm_device
*drm_dev
,
189 struct sg_table
*sgt
,
190 enum dma_data_direction dir
);