xref: /OK3568_Linux_fs/kernel/include/linux/rk-dma-heap.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * DMABUF Heaps Allocation Infrastructure
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2011 Google, Inc.
6*4882a593Smuzhiyun  * Copyright (C) 2019 Linaro Ltd.
7*4882a593Smuzhiyun  * Copyright (C) 2022 Rockchip Electronics Co. Ltd.
8*4882a593Smuzhiyun  * Author: Simon Xue <xxm@rock-chips.com>
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #ifndef _RK_DMA_HEAPS_H_
12*4882a593Smuzhiyun #define _RK_DMA_HEAPS_H_
13*4882a593Smuzhiyun #include <linux/dma-buf.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun struct rk_dma_heap;
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #if defined(CONFIG_DMABUF_HEAPS_ROCKCHIP)
18*4882a593Smuzhiyun int rk_dma_heap_cma_setup(void);
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun /**
21*4882a593Smuzhiyun  * rk_dma_heap_set_dev - set heap dev dma param
22*4882a593Smuzhiyun  * @heap: DMA-Heap to retrieve private data for
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  * Returns:
25*4882a593Smuzhiyun  * Zero on success, ERR_PTR(-errno) on error
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun int rk_dma_heap_set_dev(struct device *heap_dev);
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun /**
30*4882a593Smuzhiyun  * rk_dma_heap_find - Returns the registered dma_heap with the specified name
31*4882a593Smuzhiyun  * @name: Name of the heap to find
32*4882a593Smuzhiyun  *
33*4882a593Smuzhiyun  * NOTE: dma_heaps returned from this function MUST be released
34*4882a593Smuzhiyun  * using rk_dma_heap_put() when the user is done.
35*4882a593Smuzhiyun  */
36*4882a593Smuzhiyun struct rk_dma_heap *rk_dma_heap_find(const char *name);
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun /** rk_dma_heap_buffer_free - Free dma_buf allocated by rk_dma_heap_buffer_alloc
39*4882a593Smuzhiyun  * @dma_buf:	dma_buf to free
40*4882a593Smuzhiyun  *
41*4882a593Smuzhiyun  * This is really only a simple wrapper to dma_buf_put()
42*4882a593Smuzhiyun  */
43*4882a593Smuzhiyun void rk_dma_heap_buffer_free(struct dma_buf *dmabuf);
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun /**
46*4882a593Smuzhiyun  * rk_dma_heap_buffer_alloc - Allocate dma-buf from a dma_heap
47*4882a593Smuzhiyun  * @heap:	dma_heap to allocate from
48*4882a593Smuzhiyun  * @len:	size to allocate
49*4882a593Smuzhiyun  * @fd_flags:	flags to set on returned dma-buf fd
50*4882a593Smuzhiyun  * @heap_flags:	flags to pass to the dma heap
51*4882a593Smuzhiyun  *
52*4882a593Smuzhiyun  * This is for internal dma-buf allocations only.
53*4882a593Smuzhiyun  */
54*4882a593Smuzhiyun struct dma_buf *rk_dma_heap_buffer_alloc(struct rk_dma_heap *heap, size_t len,
55*4882a593Smuzhiyun 					 unsigned int fd_flags,
56*4882a593Smuzhiyun 					 unsigned int heap_flags,
57*4882a593Smuzhiyun 					 const char *name);
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun /**
60*4882a593Smuzhiyun  * rk_dma_heap_bufferfd_alloc - Allocate dma-buf fd from a dma_heap
61*4882a593Smuzhiyun  * @heap:	dma_heap to allocate from
62*4882a593Smuzhiyun  * @len:	size to allocate
63*4882a593Smuzhiyun  * @fd_flags:	flags to set on returned dma-buf fd
64*4882a593Smuzhiyun  * @heap_flags:	flags to pass to the dma heap
65*4882a593Smuzhiyun  */
66*4882a593Smuzhiyun int rk_dma_heap_bufferfd_alloc(struct rk_dma_heap *heap, size_t len,
67*4882a593Smuzhiyun 			       unsigned int fd_flags,
68*4882a593Smuzhiyun 			       unsigned int heap_flags,
69*4882a593Smuzhiyun 			       const char *name);
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun /**
72*4882a593Smuzhiyun  * rk_dma_heap_alloc_contig_pages - Allocate contiguous pages from a dma_heap
73*4882a593Smuzhiyun  * @heap:	dma_heap to allocate from
74*4882a593Smuzhiyun  * @len:	size to allocate
75*4882a593Smuzhiyun  * @name:	the name who allocate
76*4882a593Smuzhiyun  */
77*4882a593Smuzhiyun struct page *rk_dma_heap_alloc_contig_pages(struct rk_dma_heap *heap,
78*4882a593Smuzhiyun 					    size_t len, const char *name);
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun /**
81*4882a593Smuzhiyun  * rk_dma_heap_free_contig_pages - Free contiguous pages to a dma_heap
82*4882a593Smuzhiyun  * @heap:	dma_heap to free to
83*4882a593Smuzhiyun  * @pages:	pages to free to
84*4882a593Smuzhiyun  * @len:	size to free
85*4882a593Smuzhiyun  * @name:	the name who allocate
86*4882a593Smuzhiyun  */
87*4882a593Smuzhiyun void rk_dma_heap_free_contig_pages(struct rk_dma_heap *heap, struct page *pages,
88*4882a593Smuzhiyun 				   size_t len, const char *name);
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun #else
rk_dma_heap_cma_setup(void)91*4882a593Smuzhiyun static inline int rk_dma_heap_cma_setup(void)
92*4882a593Smuzhiyun {
93*4882a593Smuzhiyun 	return -ENODEV;
94*4882a593Smuzhiyun }
95*4882a593Smuzhiyun 
rk_dma_heap_set_dev(struct device * heap_dev)96*4882a593Smuzhiyun static inline int rk_dma_heap_set_dev(struct device *heap_dev)
97*4882a593Smuzhiyun {
98*4882a593Smuzhiyun 	return -ENODEV;
99*4882a593Smuzhiyun }
100*4882a593Smuzhiyun 
rk_dma_heap_find(const char * name)101*4882a593Smuzhiyun static inline struct rk_dma_heap *rk_dma_heap_find(const char *name)
102*4882a593Smuzhiyun {
103*4882a593Smuzhiyun 	return NULL;
104*4882a593Smuzhiyun }
105*4882a593Smuzhiyun 
rk_dma_heap_buffer_free(struct dma_buf * dmabuf)106*4882a593Smuzhiyun static inline void rk_dma_heap_buffer_free(struct dma_buf *dmabuf)
107*4882a593Smuzhiyun {
108*4882a593Smuzhiyun }
109*4882a593Smuzhiyun 
rk_dma_heap_buffer_alloc(struct rk_dma_heap * heap,size_t len,unsigned int fd_flags,unsigned int heap_flags,const char * name)110*4882a593Smuzhiyun static inline struct dma_buf *rk_dma_heap_buffer_alloc(struct rk_dma_heap *heap, size_t len,
111*4882a593Smuzhiyun 						       unsigned int fd_flags,
112*4882a593Smuzhiyun 						       unsigned int heap_flags,
113*4882a593Smuzhiyun 						       const char *name)
114*4882a593Smuzhiyun {
115*4882a593Smuzhiyun 	return NULL;
116*4882a593Smuzhiyun }
117*4882a593Smuzhiyun 
rk_dma_heap_bufferfd_alloc(struct rk_dma_heap * heap,size_t len,unsigned int fd_flags,unsigned int heap_flags,const char * name)118*4882a593Smuzhiyun static inline int rk_dma_heap_bufferfd_alloc(struct rk_dma_heap *heap, size_t len,
119*4882a593Smuzhiyun 					     unsigned int fd_flags,
120*4882a593Smuzhiyun 					     unsigned int heap_flags,
121*4882a593Smuzhiyun 					     const char *name)
122*4882a593Smuzhiyun {
123*4882a593Smuzhiyun 	return -ENODEV;
124*4882a593Smuzhiyun }
125*4882a593Smuzhiyun 
rk_dma_heap_alloc_contig_pages(struct rk_dma_heap * heap,size_t len,const char * name)126*4882a593Smuzhiyun static inline struct page *rk_dma_heap_alloc_contig_pages(struct rk_dma_heap *heap,
127*4882a593Smuzhiyun 							  size_t len, const char *name)
128*4882a593Smuzhiyun {
129*4882a593Smuzhiyun 	return NULL;
130*4882a593Smuzhiyun }
131*4882a593Smuzhiyun 
rk_dma_heap_free_contig_pages(struct rk_dma_heap * heap,struct page * pages,size_t len,const char * name)132*4882a593Smuzhiyun static inline void rk_dma_heap_free_contig_pages(struct rk_dma_heap *heap, struct page *pages,
133*4882a593Smuzhiyun 						 size_t len, const char *name)
134*4882a593Smuzhiyun {
135*4882a593Smuzhiyun }
136*4882a593Smuzhiyun #endif
137*4882a593Smuzhiyun #endif /* _DMA_HEAPS_H */
138