blob: 0236321521a1295881acb6b18b70505065fa7929 [file] [log] [blame]
Inki Dae1c248b72011-10-04 19:19:01 +09001/* exynos_drm_gem.h
2 *
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * Authoer: Inki Dae <inki.dae@samsung.com>
5 *
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:
12 *
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
15 * Software.
16 *
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.
24 */
25
26#ifndef _EXYNOS_DRM_GEM_H_
27#define _EXYNOS_DRM_GEM_H_
28
29#define to_exynos_gem_obj(x) container_of(x,\
30 struct exynos_drm_gem_obj, base)
31
Inki Daedcf9af82012-04-03 21:27:58 +090032#define IS_NONCONTIG_BUFFER(f) (f & EXYNOS_BO_NONCONTIG)
33
Inki Dae1c248b72011-10-04 19:19:01 +090034/*
Inki Dae2c871122011-11-12 15:23:32 +090035 * exynos drm gem buffer structure.
36 *
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.
Inki Dae2b358922012-03-16 18:47:05 +090041 * @sgt: sg table to transfer page data.
42 * @pages: contain all pages to allocated memory region.
Inki Daeb2df26c2012-04-23 21:01:28 +090043 * @page_size: could be 4K, 64K or 1MB.
Inki Dae2c871122011-11-12 15:23:32 +090044 * @size: size of allocated memory region.
45 */
46struct exynos_drm_gem_buf {
47 void __iomem *kvaddr;
48 dma_addr_t dma_addr;
Inki Dae0519f9a2012-10-20 07:53:42 -070049 struct dma_attrs dma_attrs;
Inki Dae2b358922012-03-16 18:47:05 +090050 struct sg_table *sgt;
51 struct page **pages;
Inki Daeb2df26c2012-04-23 21:01:28 +090052 unsigned long page_size;
Inki Dae2c871122011-11-12 15:23:32 +090053 unsigned long size;
54};
55
56/*
Inki Dae1c248b72011-10-04 19:19:01 +090057 * exynos drm buffer structure.
58 *
59 * @base: a gem object.
60 * - a new handle to this gem object would be created
61 * by drm_gem_handle_create().
Inki Dae2c871122011-11-12 15:23:32 +090062 * @buffer: a pointer to exynos_drm_gem_buffer object.
63 * - contain the information to memory region allocated
64 * by user request or at framebuffer creation.
Inki Dae1c248b72011-10-04 19:19:01 +090065 * continuous memory region allocated by user request
66 * or at framebuffer creation.
Inki Dae3c52b882012-06-29 16:28:17 +090067 * @size: size requested from user, in bytes and this size is aligned
68 * in page unit.
Inki Dae2b358922012-03-16 18:47:05 +090069 * @flags: indicate memory type to allocated buffer and cache attruibute.
Inki Dae1c248b72011-10-04 19:19:01 +090070 *
71 * P.S. this object would be transfered to user as kms_bo.handle so
72 * user can access the buffer through kms_bo.handle.
73 */
74struct exynos_drm_gem_obj {
Joonyoung Shimee5e7702011-12-13 14:20:23 +090075 struct drm_gem_object base;
76 struct exynos_drm_gem_buf *buffer;
Inki Dae2b358922012-03-16 18:47:05 +090077 unsigned long size;
78 unsigned int flags;
Inki Dae1c248b72011-10-04 19:19:01 +090079};
80
Inki Daeb2df26c2012-04-23 21:01:28 +090081struct page **exynos_gem_get_pages(struct drm_gem_object *obj, gfp_t gfpmask);
82
Joonyoung Shim23648392011-12-13 14:39:13 +090083/* destroy a buffer with gem object */
84void exynos_drm_gem_destroy(struct exynos_drm_gem_obj *exynos_gem_obj);
85
Inki Daeb2df26c2012-04-23 21:01:28 +090086/* create a private gem object and initialize it. */
87struct exynos_drm_gem_obj *exynos_drm_gem_init(struct drm_device *dev,
88 unsigned long size);
89
Joonyoung Shim23648392011-12-13 14:39:13 +090090/* create a new buffer with gem object */
Inki Daef088d5a2011-11-12 14:51:23 +090091struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
Inki Dae2b358922012-03-16 18:47:05 +090092 unsigned int flags,
93 unsigned long size);
Inki Dae1c248b72011-10-04 19:19:01 +090094
95/*
96 * request gem object creation and buffer allocation as the size
97 * that it is calculated with framebuffer information such as width,
98 * height and bpp.
99 */
100int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900101 struct drm_file *file_priv);
Inki Dae1c248b72011-10-04 19:19:01 +0900102
Inki Daef0b1bda2012-03-16 18:47:06 +0900103/*
104 * get dma address from gem handle and this function could be used for
105 * other drivers such as 2d/3d acceleration drivers.
106 * with this function call, gem object reference count would be increased.
107 */
108void *exynos_drm_gem_get_dma_addr(struct drm_device *dev,
109 unsigned int gem_handle,
110 struct drm_file *file_priv);
111
112/*
113 * put dma address from gem handle and this function could be used for
114 * other drivers such as 2d/3d acceleration drivers.
115 * with this function call, gem object reference count would be decreased.
116 */
117void exynos_drm_gem_put_dma_addr(struct drm_device *dev,
118 unsigned int gem_handle,
119 struct drm_file *file_priv);
120
Inki Dae1c248b72011-10-04 19:19:01 +0900121/* get buffer offset to map to user space. */
122int exynos_drm_gem_map_offset_ioctl(struct drm_device *dev, void *data,
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900123 struct drm_file *file_priv);
Inki Dae1c248b72011-10-04 19:19:01 +0900124
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900125/*
126 * mmap the physically continuous memory that a gem object contains
127 * to user space.
128 */
129int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
130 struct drm_file *file_priv);
Inki Dae1c248b72011-10-04 19:19:01 +0900131
Inki Dae40cd7e02012-05-04 15:51:17 +0900132/* get buffer information to memory region allocated by gem. */
133int exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data,
134 struct drm_file *file_priv);
135
Inki Dae1c248b72011-10-04 19:19:01 +0900136/* initialize gem object. */
137int exynos_drm_gem_init_object(struct drm_gem_object *obj);
138
139/* free gem object. */
140void exynos_drm_gem_free_object(struct drm_gem_object *gem_obj);
141
142/* create memory region for drm framebuffer. */
143int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900144 struct drm_device *dev,
145 struct drm_mode_create_dumb *args);
Inki Dae1c248b72011-10-04 19:19:01 +0900146
147/* map memory region for drm framebuffer to user space. */
148int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv,
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900149 struct drm_device *dev, uint32_t handle,
150 uint64_t *offset);
Inki Dae1c248b72011-10-04 19:19:01 +0900151
152/*
153 * destroy memory region allocated.
154 * - a gem handle and physical memory region pointed by a gem object
155 * would be released by drm_gem_handle_delete().
156 */
157int exynos_drm_gem_dumb_destroy(struct drm_file *file_priv,
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900158 struct drm_device *dev,
159 unsigned int handle);
160
161/* page fault handler and mmap fault address(virtual) to physical memory. */
162int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
163
164/* set vm_flags and we can change the vm attribute to other one at here. */
165int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
Inki Dae1c248b72011-10-04 19:19:01 +0900166
167#endif