3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * Authoer: Inki Dae <inki.dae@samsung.com>
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.
12 #ifndef _EXYNOS_DRM_GEM_H_
13 #define _EXYNOS_DRM_GEM_H_
15 #include <drm/drm_gem.h>
17 #define to_exynos_gem(x) container_of(x, struct exynos_drm_gem, base)
19 #define IS_NONCONTIG_BUFFER(f) (f & EXYNOS_BO_NONCONTIG)
22 * exynos drm buffer structure.
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
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.
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.
46 struct exynos_drm_gem
{
47 struct drm_gem_object base
;
53 unsigned long dma_attrs
;
58 /* destroy a buffer with gem object */
59 void exynos_drm_gem_destroy(struct exynos_drm_gem
*exynos_gem
);
61 /* create a new buffer with gem object */
62 struct exynos_drm_gem
*exynos_drm_gem_create(struct drm_device
*dev
,
67 * request gem object creation and buffer allocation as the size
68 * that it is calculated with framebuffer information such as width,
71 int exynos_drm_gem_create_ioctl(struct drm_device
*dev
, void *data
,
72 struct drm_file
*file_priv
);
74 /* get fake-offset of gem object that can be used with mmap. */
75 int exynos_drm_gem_map_ioctl(struct drm_device
*dev
, void *data
,
76 struct drm_file
*file_priv
);
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.
83 dma_addr_t
*exynos_drm_gem_get_dma_addr(struct drm_device
*dev
,
84 unsigned int gem_handle
,
85 struct drm_file
*filp
);
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.
92 void exynos_drm_gem_put_dma_addr(struct drm_device
*dev
,
93 unsigned int gem_handle
,
94 struct drm_file
*filp
);
96 /* get buffer information to memory region allocated by gem. */
97 int exynos_drm_gem_get_ioctl(struct drm_device
*dev
, void *data
,
98 struct drm_file
*file_priv
);
100 /* get buffer size to gem handle. */
101 unsigned long exynos_drm_gem_get_size(struct drm_device
*dev
,
102 unsigned int gem_handle
,
103 struct drm_file
*file_priv
);
105 /* free gem object. */
106 void exynos_drm_gem_free_object(struct drm_gem_object
*obj
);
108 /* create memory region for drm framebuffer. */
109 int exynos_drm_gem_dumb_create(struct drm_file
*file_priv
,
110 struct drm_device
*dev
,
111 struct drm_mode_create_dumb
*args
);
113 /* map memory region for drm framebuffer to user space. */
114 int exynos_drm_gem_dumb_map_offset(struct drm_file
*file_priv
,
115 struct drm_device
*dev
, uint32_t handle
,
118 /* page fault handler and mmap fault address(virtual) to physical memory. */
119 int exynos_drm_gem_fault(struct vm_area_struct
*vma
, struct vm_fault
*vmf
);
121 /* set vm_flags and we can change the vm attribute to other one at here. */
122 int exynos_drm_gem_mmap(struct file
*filp
, struct vm_area_struct
*vma
);
124 /* low-level interface prime helpers */
125 struct sg_table
*exynos_drm_gem_prime_get_sg_table(struct drm_gem_object
*obj
);
126 struct drm_gem_object
*
127 exynos_drm_gem_prime_import_sg_table(struct drm_device
*dev
,
128 struct dma_buf_attachment
*attach
,
129 struct sg_table
*sgt
);
130 void *exynos_drm_gem_prime_vmap(struct drm_gem_object
*obj
);
131 void exynos_drm_gem_prime_vunmap(struct drm_gem_object
*obj
, void *vaddr
);
132 int exynos_drm_gem_prime_mmap(struct drm_gem_object
*obj
,
133 struct vm_area_struct
*vma
);