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 * @flags: indicate memory type to allocated buffer and cache attruibute.
25 * @size: size requested from user, in bytes and this size is aligned
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.
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.
38 struct exynos_drm_gem
{
39 struct drm_gem_object base
;
45 unsigned long dma_attrs
;
49 /* destroy a buffer with gem object */
50 void exynos_drm_gem_destroy(struct exynos_drm_gem
*exynos_gem
);
52 /* create a new buffer with gem object */
53 struct exynos_drm_gem
*exynos_drm_gem_create(struct drm_device
*dev
,
59 * request gem object creation and buffer allocation as the size
60 * that it is calculated with framebuffer information such as width,
63 int exynos_drm_gem_create_ioctl(struct drm_device
*dev
, void *data
,
64 struct drm_file
*file_priv
);
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
);
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.
75 struct exynos_drm_gem
*exynos_drm_gem_get(struct drm_file
*filp
,
76 unsigned int gem_handle
);
79 * put exynos drm object acquired from exynos_drm_gem_get(),
80 * gem object reference count would be decreased.
82 static inline void exynos_drm_gem_put(struct exynos_drm_gem
*exynos_gem
)
84 drm_gem_object_put(&exynos_gem
->base
);
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
);
91 /* free gem object. */
92 void exynos_drm_gem_free_object(struct drm_gem_object
*obj
);
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
);
99 /* set vm_flags and we can change the vm attribute to other one at here. */
100 int exynos_drm_gem_mmap(struct file
*filp
, struct vm_area_struct
*vma
);
102 /* low-level interface prime helpers */
103 struct drm_gem_object
*exynos_drm_gem_prime_import(struct drm_device
*dev
,
104 struct dma_buf
*dma_buf
);
105 struct sg_table
*exynos_drm_gem_prime_get_sg_table(struct drm_gem_object
*obj
);
106 struct drm_gem_object
*
107 exynos_drm_gem_prime_import_sg_table(struct drm_device
*dev
,
108 struct dma_buf_attachment
*attach
,
109 struct sg_table
*sgt
);
110 int exynos_drm_gem_prime_mmap(struct drm_gem_object
*obj
,
111 struct vm_area_struct
*vma
);