Loading...
1/* exynos_drm_gem.h
2 *
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * Authoer: Inki Dae <inki.dae@samsung.com>
5 *
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.
10 */
11
12#ifndef _EXYNOS_DRM_GEM_H_
13#define _EXYNOS_DRM_GEM_H_
14
15#include <drm/drm_gem.h>
16
17#define to_exynos_gem(x) container_of(x, struct exynos_drm_gem, base)
18
19#define IS_NONCONTIG_BUFFER(f) (f & EXYNOS_BO_NONCONTIG)
20
21/*
22 * exynos drm buffer structure.
23 *
24 * @base: a gem object.
25 * - a new handle to this gem object would be created
26 * by drm_gem_handle_create().
27 * @buffer: a pointer to exynos_drm_gem_buffer object.
28 * - contain the information to memory region allocated
29 * by user request or at framebuffer creation.
30 * continuous memory region allocated by user request
31 * or at framebuffer creation.
32 * @flags: indicate memory type to allocated buffer and cache attruibute.
33 * @size: size requested from user, in bytes and this size is aligned
34 * in page unit.
35 * @cookie: cookie returned by dma_alloc_attrs
36 * @kvaddr: kernel virtual address to allocated memory region.
37 * @dma_addr: bus address(accessed by dma) to allocated memory region.
38 * - this address could be physical address without IOMMU and
39 * device address with IOMMU.
40 * @pages: Array of backing pages.
41 * @sgt: Imported sg_table.
42 *
43 * P.S. this object would be transferred to user as kms_bo.handle so
44 * user can access the buffer through kms_bo.handle.
45 */
46struct exynos_drm_gem {
47 struct drm_gem_object base;
48 unsigned int flags;
49 unsigned long size;
50 void *cookie;
51 void __iomem *kvaddr;
52 dma_addr_t dma_addr;
53 struct dma_attrs dma_attrs;
54 struct page **pages;
55 struct sg_table *sgt;
56};
57
58/* destroy a buffer with gem object */
59void exynos_drm_gem_destroy(struct exynos_drm_gem *exynos_gem);
60
61/* create a new buffer with gem object */
62struct exynos_drm_gem *exynos_drm_gem_create(struct drm_device *dev,
63 unsigned int flags,
64 unsigned long size);
65
66/*
67 * request gem object creation and buffer allocation as the size
68 * that it is calculated with framebuffer information such as width,
69 * height and bpp.
70 */
71int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
72 struct drm_file *file_priv);
73
74/* get fake-offset of gem object that can be used with mmap. */
75int exynos_drm_gem_map_ioctl(struct drm_device *dev, void *data,
76 struct drm_file *file_priv);
77
78/*
79 * get dma address from gem handle and this function could be used for
80 * other drivers such as 2d/3d acceleration drivers.
81 * with this function call, gem object reference count would be increased.
82 */
83dma_addr_t *exynos_drm_gem_get_dma_addr(struct drm_device *dev,
84 unsigned int gem_handle,
85 struct drm_file *filp);
86
87/*
88 * put dma address from gem handle and this function could be used for
89 * other drivers such as 2d/3d acceleration drivers.
90 * with this function call, gem object reference count would be decreased.
91 */
92void exynos_drm_gem_put_dma_addr(struct drm_device *dev,
93 unsigned int gem_handle,
94 struct drm_file *filp);
95
96/* get buffer information to memory region allocated by gem. */
97int exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data,
98 struct drm_file *file_priv);
99
100/* get buffer size to gem handle. */
101unsigned long exynos_drm_gem_get_size(struct drm_device *dev,
102 unsigned int gem_handle,
103 struct drm_file *file_priv);
104
105/* free gem object. */
106void exynos_drm_gem_free_object(struct drm_gem_object *obj);
107
108/* create memory region for drm framebuffer. */
109int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
110 struct drm_device *dev,
111 struct drm_mode_create_dumb *args);
112
113/* map memory region for drm framebuffer to user space. */
114int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv,
115 struct drm_device *dev, uint32_t handle,
116 uint64_t *offset);
117
118/* page fault handler and mmap fault address(virtual) to physical memory. */
119int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
120
121/* set vm_flags and we can change the vm attribute to other one at here. */
122int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
123
124/* map sgt with dma region. */
125int exynos_gem_map_sgt_with_dma(struct drm_device *drm_dev,
126 struct sg_table *sgt,
127 enum dma_data_direction dir);
128
129/* unmap sgt from dma region. */
130void exynos_gem_unmap_sgt_from_dma(struct drm_device *drm_dev,
131 struct sg_table *sgt,
132 enum dma_data_direction dir);
133
134/* low-level interface prime helpers */
135struct sg_table *exynos_drm_gem_prime_get_sg_table(struct drm_gem_object *obj);
136struct drm_gem_object *
137exynos_drm_gem_prime_import_sg_table(struct drm_device *dev,
138 struct dma_buf_attachment *attach,
139 struct sg_table *sgt);
140void *exynos_drm_gem_prime_vmap(struct drm_gem_object *obj);
141void exynos_drm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
142
143#endif
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
32#define IS_NONCONTIG_BUFFER(f) (f & EXYNOS_BO_NONCONTIG)
33
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.
41 * @sgt: sg table to transfer page data.
42 * @pages: contain all pages to allocated memory region.
43 * @page_size: could be 4K, 64K or 1MB.
44 * @size: size of allocated memory region.
45 */
46struct exynos_drm_gem_buf {
47 void __iomem *kvaddr;
48 dma_addr_t dma_addr;
49 struct sg_table *sgt;
50 struct page **pages;
51 unsigned long page_size;
52 unsigned long size;
53};
54
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().
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.
64 * continuous memory region allocated by user request
65 * or at framebuffer creation.
66 * @size: total memory size to physically non-continuous memory region.
67 * @flags: indicate memory type to allocated buffer and cache attruibute.
68 *
69 * P.S. this object would be transfered to user as kms_bo.handle so
70 * user can access the buffer through kms_bo.handle.
71 */
72struct exynos_drm_gem_obj {
73 struct drm_gem_object base;
74 struct exynos_drm_gem_buf *buffer;
75 unsigned long size;
76 unsigned int flags;
77};
78
79struct page **exynos_gem_get_pages(struct drm_gem_object *obj, gfp_t gfpmask);
80
81/* destroy a buffer with gem object */
82void exynos_drm_gem_destroy(struct exynos_drm_gem_obj *exynos_gem_obj);
83
84/* create a private gem object and initialize it. */
85struct exynos_drm_gem_obj *exynos_drm_gem_init(struct drm_device *dev,
86 unsigned long size);
87
88/* create a new buffer with gem object */
89struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
90 unsigned int flags,
91 unsigned long size);
92
93/*
94 * request gem object creation and buffer allocation as the size
95 * that it is calculated with framebuffer information such as width,
96 * height and bpp.
97 */
98int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
99 struct drm_file *file_priv);
100
101/*
102 * get dma address from gem handle and this function could be used for
103 * other drivers such as 2d/3d acceleration drivers.
104 * with this function call, gem object reference count would be increased.
105 */
106void *exynos_drm_gem_get_dma_addr(struct drm_device *dev,
107 unsigned int gem_handle,
108 struct drm_file *file_priv);
109
110/*
111 * put dma address from gem handle and this function could be used for
112 * other drivers such as 2d/3d acceleration drivers.
113 * with this function call, gem object reference count would be decreased.
114 */
115void exynos_drm_gem_put_dma_addr(struct drm_device *dev,
116 unsigned int gem_handle,
117 struct drm_file *file_priv);
118
119/* get buffer offset to map to user space. */
120int exynos_drm_gem_map_offset_ioctl(struct drm_device *dev, void *data,
121 struct drm_file *file_priv);
122
123/*
124 * mmap the physically continuous memory that a gem object contains
125 * to user space.
126 */
127int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
128 struct drm_file *file_priv);
129
130/* get buffer information to memory region allocated by gem. */
131int exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data,
132 struct drm_file *file_priv);
133
134/* initialize gem object. */
135int exynos_drm_gem_init_object(struct drm_gem_object *obj);
136
137/* free gem object. */
138void exynos_drm_gem_free_object(struct drm_gem_object *gem_obj);
139
140/* create memory region for drm framebuffer. */
141int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
142 struct drm_device *dev,
143 struct drm_mode_create_dumb *args);
144
145/* map memory region for drm framebuffer to user space. */
146int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv,
147 struct drm_device *dev, uint32_t handle,
148 uint64_t *offset);
149
150/*
151 * destroy memory region allocated.
152 * - a gem handle and physical memory region pointed by a gem object
153 * would be released by drm_gem_handle_delete().
154 */
155int exynos_drm_gem_dumb_destroy(struct drm_file *file_priv,
156 struct drm_device *dev,
157 unsigned int handle);
158
159/* page fault handler and mmap fault address(virtual) to physical memory. */
160int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
161
162/* set vm_flags and we can change the vm attribute to other one at here. */
163int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
164
165#endif