162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* exynos_drm_gem.h 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright (c) 2011 Samsung Electronics Co., Ltd. 562306a36Sopenharmony_ci * Authoer: Inki Dae <inki.dae@samsung.com> 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#ifndef _EXYNOS_DRM_GEM_H_ 962306a36Sopenharmony_ci#define _EXYNOS_DRM_GEM_H_ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include <drm/drm_gem.h> 1262306a36Sopenharmony_ci#include <linux/mm_types.h> 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#define to_exynos_gem(x) container_of(x, struct exynos_drm_gem, base) 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#define IS_NONCONTIG_BUFFER(f) (f & EXYNOS_BO_NONCONTIG) 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci/* 1962306a36Sopenharmony_ci * exynos drm buffer structure. 2062306a36Sopenharmony_ci * 2162306a36Sopenharmony_ci * @base: a gem object. 2262306a36Sopenharmony_ci * - a new handle to this gem object would be created 2362306a36Sopenharmony_ci * by drm_gem_handle_create(). 2462306a36Sopenharmony_ci * @flags: indicate memory type to allocated buffer and cache attruibute. 2562306a36Sopenharmony_ci * @size: size requested from user, in bytes and this size is aligned 2662306a36Sopenharmony_ci * in page unit. 2762306a36Sopenharmony_ci * @cookie: cookie returned by dma_alloc_attrs 2862306a36Sopenharmony_ci * @kvaddr: kernel virtual address to allocated memory region (for fbdev) 2962306a36Sopenharmony_ci * @dma_addr: bus address(accessed by dma) to allocated memory region. 3062306a36Sopenharmony_ci * - this address could be physical address without IOMMU and 3162306a36Sopenharmony_ci * device address with IOMMU. 3262306a36Sopenharmony_ci * @dma_attrs: attrs passed dma mapping framework 3362306a36Sopenharmony_ci * @sgt: Imported sg_table. 3462306a36Sopenharmony_ci * 3562306a36Sopenharmony_ci * P.S. this object would be transferred to user as kms_bo.handle so 3662306a36Sopenharmony_ci * user can access the buffer through kms_bo.handle. 3762306a36Sopenharmony_ci */ 3862306a36Sopenharmony_cistruct exynos_drm_gem { 3962306a36Sopenharmony_ci struct drm_gem_object base; 4062306a36Sopenharmony_ci unsigned int flags; 4162306a36Sopenharmony_ci unsigned long size; 4262306a36Sopenharmony_ci void *cookie; 4362306a36Sopenharmony_ci void *kvaddr; 4462306a36Sopenharmony_ci dma_addr_t dma_addr; 4562306a36Sopenharmony_ci unsigned long dma_attrs; 4662306a36Sopenharmony_ci struct sg_table *sgt; 4762306a36Sopenharmony_ci}; 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci/* destroy a buffer with gem object */ 5062306a36Sopenharmony_civoid exynos_drm_gem_destroy(struct exynos_drm_gem *exynos_gem); 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci/* create a new buffer with gem object */ 5362306a36Sopenharmony_cistruct exynos_drm_gem *exynos_drm_gem_create(struct drm_device *dev, 5462306a36Sopenharmony_ci unsigned int flags, 5562306a36Sopenharmony_ci unsigned long size, 5662306a36Sopenharmony_ci bool kvmap); 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci/* 5962306a36Sopenharmony_ci * request gem object creation and buffer allocation as the size 6062306a36Sopenharmony_ci * that it is calculated with framebuffer information such as width, 6162306a36Sopenharmony_ci * height and bpp. 6262306a36Sopenharmony_ci */ 6362306a36Sopenharmony_ciint exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data, 6462306a36Sopenharmony_ci struct drm_file *file_priv); 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci/* get fake-offset of gem object that can be used with mmap. */ 6762306a36Sopenharmony_ciint exynos_drm_gem_map_ioctl(struct drm_device *dev, void *data, 6862306a36Sopenharmony_ci struct drm_file *file_priv); 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci/* 7162306a36Sopenharmony_ci * get exynos drm object from gem handle, this function could be used for 7262306a36Sopenharmony_ci * other drivers such as 2d/3d acceleration drivers. 7362306a36Sopenharmony_ci * with this function call, gem object reference count would be increased. 7462306a36Sopenharmony_ci */ 7562306a36Sopenharmony_cistruct exynos_drm_gem *exynos_drm_gem_get(struct drm_file *filp, 7662306a36Sopenharmony_ci unsigned int gem_handle); 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci/* 7962306a36Sopenharmony_ci * put exynos drm object acquired from exynos_drm_gem_get(), 8062306a36Sopenharmony_ci * gem object reference count would be decreased. 8162306a36Sopenharmony_ci */ 8262306a36Sopenharmony_cistatic inline void exynos_drm_gem_put(struct exynos_drm_gem *exynos_gem) 8362306a36Sopenharmony_ci{ 8462306a36Sopenharmony_ci drm_gem_object_put(&exynos_gem->base); 8562306a36Sopenharmony_ci} 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci/* get buffer information to memory region allocated by gem. */ 8862306a36Sopenharmony_ciint exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data, 8962306a36Sopenharmony_ci struct drm_file *file_priv); 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci/* free gem object. */ 9262306a36Sopenharmony_civoid exynos_drm_gem_free_object(struct drm_gem_object *obj); 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci/* create memory region for drm framebuffer. */ 9562306a36Sopenharmony_ciint exynos_drm_gem_dumb_create(struct drm_file *file_priv, 9662306a36Sopenharmony_ci struct drm_device *dev, 9762306a36Sopenharmony_ci struct drm_mode_create_dumb *args); 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ci/* low-level interface prime helpers */ 10062306a36Sopenharmony_cistruct drm_gem_object *exynos_drm_gem_prime_import(struct drm_device *dev, 10162306a36Sopenharmony_ci struct dma_buf *dma_buf); 10262306a36Sopenharmony_cistruct sg_table *exynos_drm_gem_prime_get_sg_table(struct drm_gem_object *obj); 10362306a36Sopenharmony_cistruct drm_gem_object * 10462306a36Sopenharmony_ciexynos_drm_gem_prime_import_sg_table(struct drm_device *dev, 10562306a36Sopenharmony_ci struct dma_buf_attachment *attach, 10662306a36Sopenharmony_ci struct sg_table *sgt); 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci#endif 109