• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*sunxi_drm_gem.h
2  *
3  * Copyright (C) 2022 Allwinnertech Co., Ltd.
4  * Authors: zhengwanyu <zhengwanyu@allwinnertech.com>
5  * Authors: hongyaobin <hongyaobin@allwinnertech.com>
6  *
7  * This program is free software; you can redistribute  it and/or modify it
8  * under  the terms of  the GNU General  Public License as published by the
9  * Free Software Foundation;  either version 2 of the  License, or (at your
10  * option) any later version.
11  */
12 
13 #ifndef _SUNXI_DRM_GEM_H_
14 #define _SUNXI_DRM_GEM_H_
15 
16 #include <drm/drm_gem.h>
17 
18 /**
19  * struct sunxi_drm_gem_object - GEM object backed by sunxi memory allocations
20  * @base: a gem object.
21  *	- a new handle to this gem object would be created
22  *	by drm_gem_handle_create().
23  * @flags: indicate memory type to allocated buffer and cache attruibute.
24  * @size: size requested from user, in bytes and this size is aligned
25  *	in page unit.
26  * @cookie: cookie returned by dma_alloc_attrs
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: use this attribute to set the DMA mapping API.
31  * 	- this is defined at the "include/linux/dma-mapping.h".
32  * @pages: Array of backing pages.
33  * @sgt: Imported sg_table.
34  * @vaddr: kernel virtual address of the backing memory
35  *
36  */
37 struct sunxi_drm_gem_object {
38 	struct drm_gem_object base;
39 	size_t flags;
40 	size_t size;
41 	dma_addr_t dma_addr;
42 	unsigned long dma_attrs;
43 	struct page	**pages;
44 	struct sg_table *sgt;
45 
46 	/* use to store the result of dma_alloc_attrs */
47 	void *vaddr;
48 };
49 
50 extern const struct vm_operations_struct sunxi_drm_gem_vm_ops;
51 
to_sunxi_drm_gem_obj(struct drm_gem_object * gem_obj)52 static inline struct sunxi_drm_gem_object *to_sunxi_drm_gem_obj(
53 					struct drm_gem_object *gem_obj)
54 {
55 	return container_of(gem_obj, struct sunxi_drm_gem_object, base);
56 }
57 
58 void sunxi_gem_dump(struct drm_gem_object *gem_obj);
59 ssize_t sunxi_drm_gem_show(char *buf,
60 					struct sunxi_drm_gem_object *sunxi_gem_obj,
61 					unsigned int offset, unsigned int pitches);
62 
63 /* destroy a buffer with gem object */
64 void sunxi_drm_gem_destroy(struct sunxi_drm_gem_object *sunxi_gem_obj);
65 
66 /* free GEM object */
67 void sunxi_drm_gem_free_object(struct drm_gem_object *gem_obj);
68 
69 /* create memory region for DRM framebuffer */
70 int sunxi_drm_gem_dumb_create(struct drm_file *file_priv,
71 			    struct drm_device *drm,
72 			    struct drm_mode_create_dumb *args);
73 
74 /* map memory region for DRM framebuffer to user space */
75 int sunxi_drm_gem_dumb_map_offset(struct drm_file *file_priv,
76 				struct drm_device *drm, u32 handle,
77 				u64 *offset);
78 
79 /* set vm_flags and we can change the VM attribute to other one at here */
80 int sunxi_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
81 
82 /* allocate physical memory */
83 struct sunxi_drm_gem_object *sunxi_drm_gem_create(struct drm_device *drm,
84 							size_t flags,
85 							size_t size);
86 
87 /*
88  * request gem object creation and buffer allocation as the size
89  * that it is calculated with framebuffer information such as width,
90  * height and bpp.
91  */
92 int sunxi_drm_gem_create_ioctl(struct drm_device *dev, void *data,
93 			   struct drm_file *file_priv);
94 
95 /*prime*/
96 struct sg_table *sunxi_drm_gem_prime_get_sg_table(struct drm_gem_object *obj);
97 struct drm_gem_object *
98 sunxi_drm_gem_prime_import_sg_table(struct drm_device *dev,
99 				  struct dma_buf_attachment *attach,
100 				  struct sg_table *sgt);
101 int sunxi_drm_gem_prime_mmap(struct drm_gem_object *obj,
102 			   struct vm_area_struct *vma);
103 void *sunxi_drm_gem_prime_vmap(struct drm_gem_object *obj);
104 void sunxi_drm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
105 int sunxi_drm_gem_get_phyaddr_ioctl(struct drm_device *dev,
106 						void *data, struct drm_file *file);
107 #endif
108