blob: e40fbad8b70552abf83d2cf86ccd2cd4e10a5630 [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
32/*
Inki Dae2c871122011-11-12 15:23:32 +090033 * exynos drm gem buffer structure.
34 *
35 * @kvaddr: kernel virtual address to allocated memory region.
36 * @dma_addr: bus address(accessed by dma) to allocated memory region.
37 * - this address could be physical address without IOMMU and
38 * device address with IOMMU.
Inki Dae2b358922012-03-16 18:47:05 +090039 * @sgt: sg table to transfer page data.
40 * @pages: contain all pages to allocated memory region.
Inki Dae2c871122011-11-12 15:23:32 +090041 * @size: size of allocated memory region.
42 */
43struct exynos_drm_gem_buf {
44 void __iomem *kvaddr;
45 dma_addr_t dma_addr;
Inki Dae2b358922012-03-16 18:47:05 +090046 struct sg_table *sgt;
47 struct page **pages;
Inki Dae2c871122011-11-12 15:23:32 +090048 unsigned long size;
49};
50
51/*
Inki Dae1c248b72011-10-04 19:19:01 +090052 * exynos drm buffer structure.
53 *
54 * @base: a gem object.
55 * - a new handle to this gem object would be created
56 * by drm_gem_handle_create().
Inki Dae2c871122011-11-12 15:23:32 +090057 * @buffer: a pointer to exynos_drm_gem_buffer object.
58 * - contain the information to memory region allocated
59 * by user request or at framebuffer creation.
Inki Dae1c248b72011-10-04 19:19:01 +090060 * continuous memory region allocated by user request
61 * or at framebuffer creation.
Inki Dae2b358922012-03-16 18:47:05 +090062 * @size: total memory size to physically non-continuous memory region.
63 * @flags: indicate memory type to allocated buffer and cache attruibute.
Inki Dae1c248b72011-10-04 19:19:01 +090064 *
65 * P.S. this object would be transfered to user as kms_bo.handle so
66 * user can access the buffer through kms_bo.handle.
67 */
68struct exynos_drm_gem_obj {
Joonyoung Shimee5e7702011-12-13 14:20:23 +090069 struct drm_gem_object base;
70 struct exynos_drm_gem_buf *buffer;
Inki Dae2b358922012-03-16 18:47:05 +090071 unsigned long size;
72 unsigned int flags;
Inki Dae1c248b72011-10-04 19:19:01 +090073};
74
Joonyoung Shim23648392011-12-13 14:39:13 +090075/* destroy a buffer with gem object */
76void exynos_drm_gem_destroy(struct exynos_drm_gem_obj *exynos_gem_obj);
77
78/* create a new buffer with gem object */
Inki Daef088d5a2011-11-12 14:51:23 +090079struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
Inki Dae2b358922012-03-16 18:47:05 +090080 unsigned int flags,
81 unsigned long size);
Inki Dae1c248b72011-10-04 19:19:01 +090082
83/*
84 * request gem object creation and buffer allocation as the size
85 * that it is calculated with framebuffer information such as width,
86 * height and bpp.
87 */
88int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
Joonyoung Shimee5e7702011-12-13 14:20:23 +090089 struct drm_file *file_priv);
Inki Dae1c248b72011-10-04 19:19:01 +090090
Inki Daef0b1bda2012-03-16 18:47:06 +090091/*
92 * get dma address from gem handle and this function could be used for
93 * other drivers such as 2d/3d acceleration drivers.
94 * with this function call, gem object reference count would be increased.
95 */
96void *exynos_drm_gem_get_dma_addr(struct drm_device *dev,
97 unsigned int gem_handle,
98 struct drm_file *file_priv);
99
100/*
101 * put dma address from gem handle and this function could be used for
102 * other drivers such as 2d/3d acceleration drivers.
103 * with this function call, gem object reference count would be decreased.
104 */
105void exynos_drm_gem_put_dma_addr(struct drm_device *dev,
106 unsigned int gem_handle,
107 struct drm_file *file_priv);
108
Inki Dae1c248b72011-10-04 19:19:01 +0900109/* get buffer offset to map to user space. */
110int exynos_drm_gem_map_offset_ioctl(struct drm_device *dev, void *data,
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900111 struct drm_file *file_priv);
Inki Dae1c248b72011-10-04 19:19:01 +0900112
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900113/*
114 * mmap the physically continuous memory that a gem object contains
115 * to user space.
116 */
117int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
118 struct drm_file *file_priv);
Inki Dae1c248b72011-10-04 19:19:01 +0900119
120/* initialize gem object. */
121int exynos_drm_gem_init_object(struct drm_gem_object *obj);
122
123/* free gem object. */
124void exynos_drm_gem_free_object(struct drm_gem_object *gem_obj);
125
126/* create memory region for drm framebuffer. */
127int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900128 struct drm_device *dev,
129 struct drm_mode_create_dumb *args);
Inki Dae1c248b72011-10-04 19:19:01 +0900130
131/* map memory region for drm framebuffer to user space. */
132int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv,
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900133 struct drm_device *dev, uint32_t handle,
134 uint64_t *offset);
Inki Dae1c248b72011-10-04 19:19:01 +0900135
136/*
137 * destroy memory region allocated.
138 * - a gem handle and physical memory region pointed by a gem object
139 * would be released by drm_gem_handle_delete().
140 */
141int exynos_drm_gem_dumb_destroy(struct drm_file *file_priv,
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900142 struct drm_device *dev,
143 unsigned int handle);
144
145/* page fault handler and mmap fault address(virtual) to physical memory. */
146int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
147
148/* set vm_flags and we can change the vm attribute to other one at here. */
149int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
Inki Dae1c248b72011-10-04 19:19:01 +0900150
151#endif