3 * Copyright (c) 2014 Spreadtrum Communications, Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #ifndef _SPRD_DRM_GEM_H_
17 #define _SPRD_DRM_GEM_H_
19 #define to_sprd_gem_obj(x) container_of(x,\
20 struct sprd_drm_gem_obj, base)
22 #define IS_NONCONTIG_BUFFER(f) (f & SPRD_BO_NONCONTIG)
23 #define IS_CACHABLE_BUFFER(f) (f & SPRD_BO_CACHABLE)
24 #define IS_NONCACHABLE_BUFFER(f) (f & SPRD_BO_NONCACHABLE)
26 #define IS_DEV_SYSTEM_BUFFER(f) (f & SPRD_BO_DEV_SYSTEM)
27 #define IS_DEV_MM_BUFFER(f) (f & SPRD_BO_DEV_MM)
28 #define IS_DEV_OVERLAY_BUFFER(f) (f & SPRD_BO_DEV_OVERLAY)
29 #define IS_DEV_GSP_BUFFER(f) (f & SPRD_BO_DEV_GSP)
31 #define ENTRY_EMPTY -1
32 #define DRM_SPRD_HANDLE_WAIT_ENTRIES 10
33 #define SPRD_DRM_GEM_MAX_INDEX_ADDR 3
35 extern struct drm_device *sprd_drm_dev;
38 * sprd drm gem buffer structure.
40 * @dma_addr: bus address(accessed by dma) to allocated memory region.
41 * - this address could be physical address without IOMMU and
42 * device address with IOMMU.
43 * @sgt: sg table to transfer page data.
44 * @pages: contain all pages to allocated memory region.
45 * @page_size: could be 4K, 64K or 1MB.
46 * @size: size of allocated memory region.
48 struct sprd_drm_gem_buf {
52 unsigned long page_size;
54 struct ion_handle *ion_handle;
56 unsigned int bufcount;
57 dma_addr_t idx_addr[SPRD_DRM_GEM_MAX_INDEX_ADDR];
59 struct drm_gem_object *obj;
62 struct drm_sprd_gem_object_wait_list_entry {
63 struct list_head list;
66 wait_queue_head_t process_wait_q;
70 * sprd drm buffer structure.
72 * @base: a gem object.
73 * - a new handle to this gem object would be created
74 * by drm_gem_handle_create().
75 * @buffer: a pointer to sprd_drm_gem_buffer object.
76 * - contain the information to memory region allocated
77 * by user request or at framebuffer creation.
78 * continuous memory region allocated by user request
79 * or at framebuffer creation.
80 * @size: total memory size to physically non-continuous memory region.
81 * @flags: indicate memory type to allocated buffer and cache attruibute.
83 * P.S. this object would be transfered to user as kms_bo.handle so
84 * user can access the buffer through kms_bo.handle.
86 struct sprd_drm_gem_obj {
87 struct drm_gem_object base;
88 struct sprd_drm_gem_buf *buffer;
94 struct drm_sprd_gem_object_wait_list_entry
95 wait_entries[DRM_SPRD_HANDLE_WAIT_ENTRIES];
97 struct list_head wait_list;
100 struct page **sprd_gem_get_pages(struct drm_gem_object *obj, gfp_t gfpmask);
102 /* destroy a buffer with gem object */
103 void sprd_drm_gem_destroy(struct sprd_drm_gem_obj *sprd_gem_obj);
105 /* create a private gem object and initialize it. */
106 struct sprd_drm_gem_obj *sprd_drm_gem_init(struct drm_device *dev,
109 /* create a new buffer with gem object */
110 struct sprd_drm_gem_obj *sprd_drm_gem_create(struct drm_device *dev,
111 struct sprd_drm_gem_index *args);
114 * request gem object creation and buffer allocation as the size
115 * that it is calculated with framebuffer information such as width,
118 int sprd_drm_gem_create_ioctl(struct drm_device *dev, void *data,
119 struct drm_file *file_priv);
120 int sprd_drm_gem_create_index_ioctl(struct drm_device *dev, void *data,
121 struct drm_file *file_priv);
123 struct dma_buf *sprd_prime_export(struct drm_device *dev,
124 struct drm_gem_object *obj, int flags);
126 struct drm_gem_object *sprd_prime_import(struct drm_device *dev,
127 struct dma_buf *dma_buf);
129 int sprd_drm_gem_prime_fd_to_handle(struct drm_device *dev,
130 struct drm_file *file_priv, int prime_fd, uint32_t *handle);
133 * get dma address from gem handle and this function could be used for
134 * other drivers such as 2d/3d acceleration drivers.
135 * with this function call, gem object reference count would be increased.
137 void *sprd_drm_gem_get_dma_addr(struct drm_device *dev,
138 unsigned int gem_handle,
139 struct drm_file *file_priv);
142 * put dma address from gem handle and this function could be used for
143 * other drivers such as 2d/3d acceleration drivers.
144 * with this function call, gem object reference count would be decreased.
146 void sprd_drm_gem_put_dma_addr(struct drm_device *dev,
147 unsigned int gem_handle,
148 struct drm_file *file_priv);
150 unsigned long sprd_drm_gem_get_size(struct drm_device *dev,
151 unsigned int gem_handle,
152 struct drm_file *file_priv);
154 void *sprd_drm_gem_get_obj_addr(unsigned int name, unsigned int index);
156 /* get buffer offset to map to user space. */
157 int sprd_drm_gem_map_offset_ioctl(struct drm_device *dev, void *data,
158 struct drm_file *file_priv);
161 * mmap the physically continuous memory that a gem object contains
164 int sprd_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
165 struct drm_file *file_priv);
167 /* get buffer information to memory region allocated by gem. */
168 int sprd_drm_gem_get_ioctl(struct drm_device *dev, void *data,
169 struct drm_file *file_priv);
171 /* initialize gem object. */
172 int sprd_drm_gem_init_object(struct drm_gem_object *obj);
174 /* free gem object. */
175 void sprd_drm_gem_free_object(struct drm_gem_object *gem_obj);
177 /* create memory region for drm framebuffer. */
178 int sprd_drm_gem_dumb_create(struct drm_file *file_priv,
179 struct drm_device *dev,
180 struct drm_mode_create_dumb *args);
182 /* map memory region for drm framebuffer to user space. */
183 int sprd_drm_gem_dumb_map_offset(struct drm_file *file_priv,
184 struct drm_device *dev, uint32_t handle,
188 * destroy memory region allocated.
189 * - a gem handle and physical memory region pointed by a gem object
190 * would be released by drm_gem_handle_delete().
192 int sprd_drm_gem_dumb_destroy(struct drm_file *file_priv,
193 struct drm_device *dev,
194 unsigned int handle);
196 /* page fault handler and mmap fault address(virtual) to physical memory. */
197 int sprd_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
199 /* set vm_flags and we can change the vm attribute to other one at here. */
200 int sprd_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
202 void init_fence(void);
204 int sprd_gem_lock_handle_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
206 int sprd_gem_unlock_handle_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
208 int sprd_gem_cache_op_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
210 int sprd_drm_gem_mmap_iommu_ioctl(struct drm_device *dev, void *data,
211 struct drm_file *file_priv);
213 int sprd_drm_gem_unmap_iommu_ioctl(struct drm_device *dev, void *data,
214 struct drm_file *file_priv);