1 /* SPDX-License-Identifier: GPL-2.0-or-later */
4 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
5 * Authoer: Inki Dae <inki.dae@samsung.com>
8 #ifndef _EXYNOS_DRM_GEM_H_
9 #define _EXYNOS_DRM_GEM_H_
11 #include <drm/drm_gem.h>
12 #include <linux/mm_types.h>
14 #define to_exynos_gem(x) container_of(x, struct exynos_drm_gem, base)
16 #define IS_NONCONTIG_BUFFER(f) (f & EXYNOS_BO_NONCONTIG)
19 * exynos drm buffer structure.
21 * @base: a gem object.
22 * - a new handle to this gem object would be created
23 * by drm_gem_handle_create().
24 * @buffer: a pointer to exynos_drm_gem_buffer object.
25 * - contain the information to memory region allocated
26 * by user request or at framebuffer creation.
27 * continuous memory region allocated by user request
28 * or at framebuffer creation.
29 * @flags: indicate memory type to allocated buffer and cache attruibute.
30 * @size: size requested from user, in bytes and this size is aligned
32 * @cookie: cookie returned by dma_alloc_attrs
33 * @kvaddr: kernel virtual address to allocated memory region.
34 * @dma_addr: bus address(accessed by dma) to allocated memory region.
35 * - this address could be physical address without IOMMU and
36 * device address with IOMMU.
37 * @pages: Array of backing pages.
38 * @sgt: Imported sg_table.
40 * P.S. this object would be transferred to user as kms_bo.handle so
41 * user can access the buffer through kms_bo.handle.
43 struct exynos_drm_gem
{
44 struct drm_gem_object base
;
50 unsigned long dma_attrs
;
55 /* destroy a buffer with gem object */
56 void exynos_drm_gem_destroy(struct exynos_drm_gem
*exynos_gem
);
58 /* create a new buffer with gem object */
59 struct exynos_drm_gem
*exynos_drm_gem_create(struct drm_device
*dev
,
64 * request gem object creation and buffer allocation as the size
65 * that it is calculated with framebuffer information such as width,
68 int exynos_drm_gem_create_ioctl(struct drm_device
*dev
, void *data
,
69 struct drm_file
*file_priv
);
71 /* get fake-offset of gem object that can be used with mmap. */
72 int exynos_drm_gem_map_ioctl(struct drm_device
*dev
, void *data
,
73 struct drm_file
*file_priv
);
76 * get exynos drm object from gem handle, this function could be used for
77 * other drivers such as 2d/3d acceleration drivers.
78 * with this function call, gem object reference count would be increased.
80 struct exynos_drm_gem
*exynos_drm_gem_get(struct drm_file
*filp
,
81 unsigned int gem_handle
);
84 * put exynos drm object acquired from exynos_drm_gem_get(),
85 * gem object reference count would be decreased.
87 static inline void exynos_drm_gem_put(struct exynos_drm_gem
*exynos_gem
)
89 drm_gem_object_put_unlocked(&exynos_gem
->base
);
92 /* get buffer information to memory region allocated by gem. */
93 int exynos_drm_gem_get_ioctl(struct drm_device
*dev
, void *data
,
94 struct drm_file
*file_priv
);
96 /* free gem object. */
97 void exynos_drm_gem_free_object(struct drm_gem_object
*obj
);
99 /* create memory region for drm framebuffer. */
100 int exynos_drm_gem_dumb_create(struct drm_file
*file_priv
,
101 struct drm_device
*dev
,
102 struct drm_mode_create_dumb
*args
);
104 /* page fault handler and mmap fault address(virtual) to physical memory. */
105 vm_fault_t
exynos_drm_gem_fault(struct vm_fault
*vmf
);
107 /* set vm_flags and we can change the vm attribute to other one at here. */
108 int exynos_drm_gem_mmap(struct file
*filp
, struct vm_area_struct
*vma
);
110 /* low-level interface prime helpers */
111 struct drm_gem_object
*exynos_drm_gem_prime_import(struct drm_device
*dev
,
112 struct dma_buf
*dma_buf
);
113 struct sg_table
*exynos_drm_gem_prime_get_sg_table(struct drm_gem_object
*obj
);
114 struct drm_gem_object
*
115 exynos_drm_gem_prime_import_sg_table(struct drm_device
*dev
,
116 struct dma_buf_attachment
*attach
,
117 struct sg_table
*sgt
);
118 void *exynos_drm_gem_prime_vmap(struct drm_gem_object
*obj
);
119 void exynos_drm_gem_prime_vunmap(struct drm_gem_object
*obj
, void *vaddr
);
120 int exynos_drm_gem_prime_mmap(struct drm_gem_object
*obj
,
121 struct vm_area_struct
*vma
);