18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* exynos_drm_gem.h 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (c) 2011 Samsung Electronics Co., Ltd. 58c2ecf20Sopenharmony_ci * Authoer: Inki Dae <inki.dae@samsung.com> 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef _EXYNOS_DRM_GEM_H_ 98c2ecf20Sopenharmony_ci#define _EXYNOS_DRM_GEM_H_ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <drm/drm_gem.h> 128c2ecf20Sopenharmony_ci#include <linux/mm_types.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#define to_exynos_gem(x) container_of(x, struct exynos_drm_gem, base) 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#define IS_NONCONTIG_BUFFER(f) (f & EXYNOS_BO_NONCONTIG) 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci/* 198c2ecf20Sopenharmony_ci * exynos drm buffer structure. 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * @base: a gem object. 228c2ecf20Sopenharmony_ci * - a new handle to this gem object would be created 238c2ecf20Sopenharmony_ci * by drm_gem_handle_create(). 248c2ecf20Sopenharmony_ci * @flags: indicate memory type to allocated buffer and cache attruibute. 258c2ecf20Sopenharmony_ci * @size: size requested from user, in bytes and this size is aligned 268c2ecf20Sopenharmony_ci * in page unit. 278c2ecf20Sopenharmony_ci * @cookie: cookie returned by dma_alloc_attrs 288c2ecf20Sopenharmony_ci * @kvaddr: kernel virtual address to allocated memory region (for fbdev) 298c2ecf20Sopenharmony_ci * @dma_addr: bus address(accessed by dma) to allocated memory region. 308c2ecf20Sopenharmony_ci * - this address could be physical address without IOMMU and 318c2ecf20Sopenharmony_ci * device address with IOMMU. 328c2ecf20Sopenharmony_ci * @dma_attrs: attrs passed dma mapping framework 338c2ecf20Sopenharmony_ci * @sgt: Imported sg_table. 348c2ecf20Sopenharmony_ci * 358c2ecf20Sopenharmony_ci * P.S. this object would be transferred to user as kms_bo.handle so 368c2ecf20Sopenharmony_ci * user can access the buffer through kms_bo.handle. 378c2ecf20Sopenharmony_ci */ 388c2ecf20Sopenharmony_cistruct exynos_drm_gem { 398c2ecf20Sopenharmony_ci struct drm_gem_object base; 408c2ecf20Sopenharmony_ci unsigned int flags; 418c2ecf20Sopenharmony_ci unsigned long size; 428c2ecf20Sopenharmony_ci void *cookie; 438c2ecf20Sopenharmony_ci void *kvaddr; 448c2ecf20Sopenharmony_ci dma_addr_t dma_addr; 458c2ecf20Sopenharmony_ci unsigned long dma_attrs; 468c2ecf20Sopenharmony_ci struct sg_table *sgt; 478c2ecf20Sopenharmony_ci}; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci/* destroy a buffer with gem object */ 508c2ecf20Sopenharmony_civoid exynos_drm_gem_destroy(struct exynos_drm_gem *exynos_gem); 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci/* create a new buffer with gem object */ 538c2ecf20Sopenharmony_cistruct exynos_drm_gem *exynos_drm_gem_create(struct drm_device *dev, 548c2ecf20Sopenharmony_ci unsigned int flags, 558c2ecf20Sopenharmony_ci unsigned long size, 568c2ecf20Sopenharmony_ci bool kvmap); 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci/* 598c2ecf20Sopenharmony_ci * request gem object creation and buffer allocation as the size 608c2ecf20Sopenharmony_ci * that it is calculated with framebuffer information such as width, 618c2ecf20Sopenharmony_ci * height and bpp. 628c2ecf20Sopenharmony_ci */ 638c2ecf20Sopenharmony_ciint exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data, 648c2ecf20Sopenharmony_ci struct drm_file *file_priv); 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/* get fake-offset of gem object that can be used with mmap. */ 678c2ecf20Sopenharmony_ciint exynos_drm_gem_map_ioctl(struct drm_device *dev, void *data, 688c2ecf20Sopenharmony_ci struct drm_file *file_priv); 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/* 718c2ecf20Sopenharmony_ci * get exynos drm object from gem handle, this function could be used for 728c2ecf20Sopenharmony_ci * other drivers such as 2d/3d acceleration drivers. 738c2ecf20Sopenharmony_ci * with this function call, gem object reference count would be increased. 748c2ecf20Sopenharmony_ci */ 758c2ecf20Sopenharmony_cistruct exynos_drm_gem *exynos_drm_gem_get(struct drm_file *filp, 768c2ecf20Sopenharmony_ci unsigned int gem_handle); 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci/* 798c2ecf20Sopenharmony_ci * put exynos drm object acquired from exynos_drm_gem_get(), 808c2ecf20Sopenharmony_ci * gem object reference count would be decreased. 818c2ecf20Sopenharmony_ci */ 828c2ecf20Sopenharmony_cistatic inline void exynos_drm_gem_put(struct exynos_drm_gem *exynos_gem) 838c2ecf20Sopenharmony_ci{ 848c2ecf20Sopenharmony_ci drm_gem_object_put(&exynos_gem->base); 858c2ecf20Sopenharmony_ci} 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci/* get buffer information to memory region allocated by gem. */ 888c2ecf20Sopenharmony_ciint exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data, 898c2ecf20Sopenharmony_ci struct drm_file *file_priv); 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci/* free gem object. */ 928c2ecf20Sopenharmony_civoid exynos_drm_gem_free_object(struct drm_gem_object *obj); 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci/* create memory region for drm framebuffer. */ 958c2ecf20Sopenharmony_ciint exynos_drm_gem_dumb_create(struct drm_file *file_priv, 968c2ecf20Sopenharmony_ci struct drm_device *dev, 978c2ecf20Sopenharmony_ci struct drm_mode_create_dumb *args); 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/* set vm_flags and we can change the vm attribute to other one at here. */ 1008c2ecf20Sopenharmony_ciint exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci/* low-level interface prime helpers */ 1038c2ecf20Sopenharmony_cistruct drm_gem_object *exynos_drm_gem_prime_import(struct drm_device *dev, 1048c2ecf20Sopenharmony_ci struct dma_buf *dma_buf); 1058c2ecf20Sopenharmony_cistruct sg_table *exynos_drm_gem_prime_get_sg_table(struct drm_gem_object *obj); 1068c2ecf20Sopenharmony_cistruct drm_gem_object * 1078c2ecf20Sopenharmony_ciexynos_drm_gem_prime_import_sg_table(struct drm_device *dev, 1088c2ecf20Sopenharmony_ci struct dma_buf_attachment *attach, 1098c2ecf20Sopenharmony_ci struct sg_table *sgt); 1108c2ecf20Sopenharmony_civoid *exynos_drm_gem_prime_vmap(struct drm_gem_object *obj); 1118c2ecf20Sopenharmony_civoid exynos_drm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr); 1128c2ecf20Sopenharmony_ciint exynos_drm_gem_prime_mmap(struct drm_gem_object *obj, 1138c2ecf20Sopenharmony_ci struct vm_area_struct *vma); 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci#endif 116