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 * @cookie: cookie returned by dma_alloc_attrs 26 * @kvaddr: kernel virtual address to allocated memory region (for fbdev) 27 * @dma_addr: bus address(accessed by dma) to allocated memory region. 28 * - this address could be physical address without IOMMU and 29 * device address with IOMMU. 30 * @dma_attrs: attrs passed dma mapping framework 31 * @sgt: Imported sg_table. 32 * 33 * P.S. this object would be transferred to user as kms_bo.handle so 34 * user can access the buffer through kms_bo.handle. 35 */ 36 struct exynos_drm_gem { 37 struct drm_gem_object base; 38 unsigned int flags; 39 void *cookie; 40 void *kvaddr; 41 dma_addr_t dma_addr; 42 unsigned long dma_attrs; 43 struct sg_table *sgt; 44 }; 45 46 /* destroy a buffer with gem object */ 47 void exynos_drm_gem_destroy(struct exynos_drm_gem *exynos_gem); 48 49 /* create a new buffer with gem object */ 50 struct exynos_drm_gem *exynos_drm_gem_create(struct drm_device *dev, 51 unsigned int flags, 52 unsigned long size, 53 bool kvmap); 54 55 /* 56 * request gem object creation and buffer allocation as the size 57 * that it is calculated with framebuffer information such as width, 58 * height and bpp. 59 */ 60 int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data, 61 struct drm_file *file_priv); 62 63 /* get fake-offset of gem object that can be used with mmap. */ 64 int exynos_drm_gem_map_ioctl(struct drm_device *dev, void *data, 65 struct drm_file *file_priv); 66 67 /* 68 * get exynos drm object from gem handle, this function could be used for 69 * other drivers such as 2d/3d acceleration drivers. 70 * with this function call, gem object reference count would be increased. 71 */ 72 struct exynos_drm_gem *exynos_drm_gem_get(struct drm_file *filp, 73 unsigned int gem_handle); 74 75 /* 76 * put exynos drm object acquired from exynos_drm_gem_get(), 77 * gem object reference count would be decreased. 78 */ 79 static inline void exynos_drm_gem_put(struct exynos_drm_gem *exynos_gem) 80 { 81 drm_gem_object_put(&exynos_gem->base); 82 } 83 84 /* get buffer information to memory region allocated by gem. */ 85 int exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data, 86 struct drm_file *file_priv); 87 88 /* create memory region for drm framebuffer. */ 89 int exynos_drm_gem_dumb_create(struct drm_file *file_priv, 90 struct drm_device *dev, 91 struct drm_mode_create_dumb *args); 92 93 /* low-level interface prime helpers */ 94 struct sg_table *exynos_drm_gem_prime_get_sg_table(struct drm_gem_object *obj); 95 struct drm_gem_object * 96 exynos_drm_gem_prime_import_sg_table(struct drm_device *dev, 97 struct dma_buf_attachment *attach, 98 struct sg_table *sgt); 99 100 #endif 101