1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* exynos_drm_gem.h
3 *
4 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
5 * Authoer: Inki Dae <inki.dae@samsung.com>
6 */
7
8 #ifndef _EXYNOS_DRM_GEM_H_
9 #define _EXYNOS_DRM_GEM_H_
10
11 #include <drm/drm_gem.h>
12 #include <linux/mm_types.h>
13
14 #define to_exynos_gem(x) container_of(x, struct exynos_drm_gem, base)
15
16 #define IS_NONCONTIG_BUFFER(f) (f & EXYNOS_BO_NONCONTIG)
17
18 /*
19 * exynos drm buffer structure.
20 *
21 * @base: a gem object.
22 * - a new handle to this gem object would be created
23 * by drm_gem_handle_create().
24 * @flags: indicate memory type to allocated buffer and cache attruibute.
25 * @size: size requested from user, in bytes and this size is aligned
26 * in page unit.
27 * @cookie: cookie returned by dma_alloc_attrs
28 * @kvaddr: kernel virtual address to allocated memory region (for fbdev)
29 * @dma_addr: bus address(accessed by dma) to allocated memory region.
30 * - this address could be physical address without IOMMU and
31 * device address with IOMMU.
32 * @dma_attrs: attrs passed dma mapping framework
33 * @sgt: Imported sg_table.
34 *
35 * P.S. this object would be transferred to user as kms_bo.handle so
36 * user can access the buffer through kms_bo.handle.
37 */
38 struct exynos_drm_gem {
39 struct drm_gem_object base;
40 unsigned int flags;
41 unsigned long size;
42 void *cookie;
43 void *kvaddr;
44 dma_addr_t dma_addr;
45 unsigned long dma_attrs;
46 struct sg_table *sgt;
47 };
48
49 /* destroy a buffer with gem object */
50 void exynos_drm_gem_destroy(struct exynos_drm_gem *exynos_gem);
51
52 /* create a new buffer with gem object */
53 struct exynos_drm_gem *exynos_drm_gem_create(struct drm_device *dev,
54 unsigned int flags,
55 unsigned long size,
56 bool kvmap);
57
58 /*
59 * request gem object creation and buffer allocation as the size
60 * that it is calculated with framebuffer information such as width,
61 * height and bpp.
62 */
63 int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
64 struct drm_file *file_priv);
65
66 /* get fake-offset of gem object that can be used with mmap. */
67 int exynos_drm_gem_map_ioctl(struct drm_device *dev, void *data,
68 struct drm_file *file_priv);
69
70 /*
71 * get exynos drm object from gem handle, this function could be used for
72 * other drivers such as 2d/3d acceleration drivers.
73 * with this function call, gem object reference count would be increased.
74 */
75 struct exynos_drm_gem *exynos_drm_gem_get(struct drm_file *filp,
76 unsigned int gem_handle);
77
78 /*
79 * put exynos drm object acquired from exynos_drm_gem_get(),
80 * gem object reference count would be decreased.
81 */
exynos_drm_gem_put(struct exynos_drm_gem * exynos_gem)82 static inline void exynos_drm_gem_put(struct exynos_drm_gem *exynos_gem)
83 {
84 drm_gem_object_put(&exynos_gem->base);
85 }
86
87 /* get buffer information to memory region allocated by gem. */
88 int exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data,
89 struct drm_file *file_priv);
90
91 /* free gem object. */
92 void exynos_drm_gem_free_object(struct drm_gem_object *obj);
93
94 /* create memory region for drm framebuffer. */
95 int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
96 struct drm_device *dev,
97 struct drm_mode_create_dumb *args);
98
99 /* low-level interface prime helpers */
100 struct drm_gem_object *exynos_drm_gem_prime_import(struct drm_device *dev,
101 struct dma_buf *dma_buf);
102 struct sg_table *exynos_drm_gem_prime_get_sg_table(struct drm_gem_object *obj);
103 struct drm_gem_object *
104 exynos_drm_gem_prime_import_sg_table(struct drm_device *dev,
105 struct dma_buf_attachment *attach,
106 struct sg_table *sgt);
107
108 #endif
109