1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2015 MediaTek Inc.
4  */
5 
6 #ifndef _MTK_DRM_GEM_H_
7 #define _MTK_DRM_GEM_H_
8 
9 #include <drm/drm_gem.h>
10 
11 /*
12  * mtk drm buffer structure.
13  *
14  * @base: a gem object.
15  *	- a new handle to this gem object would be created
16  *	by drm_gem_handle_create().
17  * @cookie: the return value of dma_alloc_attrs(), keep it for dma_free_attrs()
18  * @kvaddr: kernel virtual address of gem buffer.
19  * @dma_addr: dma address of gem buffer.
20  * @dma_attrs: dma attributes of gem buffer.
21  *
22  * P.S. this object would be transferred to user as kms_bo.handle so
23  *	user can access the buffer through kms_bo.handle.
24  */
25 struct mtk_drm_gem_obj {
26 	struct drm_gem_object	base;
27 	void			*cookie;
28 	void			*kvaddr;
29 	dma_addr_t		dma_addr;
30 	unsigned long		dma_attrs;
31 	struct sg_table		*sg;
32 	struct page		**pages;
33 };
34 
35 #define to_mtk_gem_obj(x)	container_of(x, struct mtk_drm_gem_obj, base)
36 
37 void mtk_drm_gem_free_object(struct drm_gem_object *gem);
38 struct mtk_drm_gem_obj *mtk_drm_gem_create(struct drm_device *dev, size_t size,
39 					   bool alloc_kmap);
40 int mtk_drm_gem_dumb_create(struct drm_file *file_priv, struct drm_device *dev,
41 			    struct drm_mode_create_dumb *args);
42 int mtk_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
43 int mtk_drm_gem_mmap_buf(struct drm_gem_object *obj,
44 			 struct vm_area_struct *vma);
45 struct sg_table *mtk_gem_prime_get_sg_table(struct drm_gem_object *obj);
46 struct drm_gem_object *mtk_gem_prime_import_sg_table(struct drm_device *dev,
47 			struct dma_buf_attachment *attach, struct sg_table *sg);
48 int mtk_drm_gem_prime_vmap(struct drm_gem_object *obj, struct dma_buf_map *map);
49 void mtk_drm_gem_prime_vunmap(struct drm_gem_object *obj, struct dma_buf_map *map);
50 
51 #endif
52