drm/exynos: Fix potential NULL pointer dereference
[deliverable/linux.git] / drivers / gpu / drm / exynos / exynos_drm_gem.h
CommitLineData
1c248b7d
ID
1/* 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
dcf9af82
ID
32#define IS_NONCONTIG_BUFFER(f) (f & EXYNOS_BO_NONCONTIG)
33
2c871127
ID
34/*
35 * 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.
2b35892e
ID
41 * @sgt: sg table to transfer page data.
42 * @pages: contain all pages to allocated memory region.
b2df26c1 43 * @page_size: could be 4K, 64K or 1MB.
2c871127
ID
44 * @size: size of allocated memory region.
45 */
46struct exynos_drm_gem_buf {
47 void __iomem *kvaddr;
48 dma_addr_t dma_addr;
2b35892e
ID
49 struct sg_table *sgt;
50 struct page **pages;
b2df26c1 51 unsigned long page_size;
2c871127
ID
52 unsigned long size;
53};
54
1c248b7d
ID
55/*
56 * exynos drm buffer structure.
57 *
58 * @base: a gem object.
59 * - a new handle to this gem object would be created
60 * by drm_gem_handle_create().
2c871127
ID
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.
1c248b7d
ID
64 * continuous memory region allocated by user request
65 * or at framebuffer creation.
3c52b880
ID
66 * @size: size requested from user, in bytes and this size is aligned
67 * in page unit.
2b35892e 68 * @flags: indicate memory type to allocated buffer and cache attruibute.
1c248b7d
ID
69 *
70 * P.S. this object would be transfered to user as kms_bo.handle so
71 * user can access the buffer through kms_bo.handle.
72 */
73struct exynos_drm_gem_obj {
ee5e770e
JS
74 struct drm_gem_object base;
75 struct exynos_drm_gem_buf *buffer;
2b35892e
ID
76 unsigned long size;
77 unsigned int flags;
1c248b7d
ID
78};
79
b2df26c1
ID
80struct page **exynos_gem_get_pages(struct drm_gem_object *obj, gfp_t gfpmask);
81
2364839a
JS
82/* destroy a buffer with gem object */
83void exynos_drm_gem_destroy(struct exynos_drm_gem_obj *exynos_gem_obj);
84
b2df26c1
ID
85/* create a private gem object and initialize it. */
86struct exynos_drm_gem_obj *exynos_drm_gem_init(struct drm_device *dev,
87 unsigned long size);
88
2364839a 89/* create a new buffer with gem object */
f088d5a9 90struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
2b35892e
ID
91 unsigned int flags,
92 unsigned long size);
1c248b7d
ID
93
94/*
95 * request gem object creation and buffer allocation as the size
96 * that it is calculated with framebuffer information such as width,
97 * height and bpp.
98 */
99int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
ee5e770e 100 struct drm_file *file_priv);
1c248b7d 101
f0b1bda7
ID
102/*
103 * get dma address from gem handle and this function could be used for
104 * other drivers such as 2d/3d acceleration drivers.
105 * with this function call, gem object reference count would be increased.
106 */
107void *exynos_drm_gem_get_dma_addr(struct drm_device *dev,
108 unsigned int gem_handle,
109 struct drm_file *file_priv);
110
111/*
112 * put dma address from gem handle and this function could be used for
113 * other drivers such as 2d/3d acceleration drivers.
114 * with this function call, gem object reference count would be decreased.
115 */
116void exynos_drm_gem_put_dma_addr(struct drm_device *dev,
117 unsigned int gem_handle,
118 struct drm_file *file_priv);
119
1c248b7d
ID
120/* get buffer offset to map to user space. */
121int exynos_drm_gem_map_offset_ioctl(struct drm_device *dev, void *data,
ee5e770e 122 struct drm_file *file_priv);
1c248b7d 123
ee5e770e
JS
124/*
125 * mmap the physically continuous memory that a gem object contains
126 * to user space.
127 */
128int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
129 struct drm_file *file_priv);
1c248b7d 130
40cd7e0c
ID
131/* get buffer information to memory region allocated by gem. */
132int exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data,
133 struct drm_file *file_priv);
134
1c248b7d
ID
135/* initialize gem object. */
136int exynos_drm_gem_init_object(struct drm_gem_object *obj);
137
138/* free gem object. */
139void exynos_drm_gem_free_object(struct drm_gem_object *gem_obj);
140
141/* create memory region for drm framebuffer. */
142int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
ee5e770e
JS
143 struct drm_device *dev,
144 struct drm_mode_create_dumb *args);
1c248b7d
ID
145
146/* map memory region for drm framebuffer to user space. */
147int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv,
ee5e770e
JS
148 struct drm_device *dev, uint32_t handle,
149 uint64_t *offset);
1c248b7d
ID
150
151/*
152 * destroy memory region allocated.
153 * - a gem handle and physical memory region pointed by a gem object
154 * would be released by drm_gem_handle_delete().
155 */
156int exynos_drm_gem_dumb_destroy(struct drm_file *file_priv,
ee5e770e
JS
157 struct drm_device *dev,
158 unsigned int handle);
159
160/* page fault handler and mmap fault address(virtual) to physical memory. */
161int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
162
163/* set vm_flags and we can change the vm attribute to other one at here. */
164int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
1c248b7d
ID
165
166#endif
This page took 0.078016 seconds and 5 git commands to generate.