• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * DMABUF Heaps Allocation Infrastructure
4  *
5  * Copyright (C) 2011 Google, Inc.
6  * Copyright (C) 2019 Linaro Ltd.
7  */
8 
9 #ifndef _DMA_HEAPS_H
10 #define _DMA_HEAPS_H
11 
12 #include <linux/types.h>
13 
14 struct dma_heap;
15 
16 /**
17  * struct dma_heap_ops - ops to operate on a given heap
18  * @allocate:	allocate dmabuf and return struct dma_buf ptr
19  * @get_pool_size:	if heap maintains memory pools, get pool size in bytes
20  *
21  * allocate returns dmabuf on success, ERR_PTR(-errno) on error.
22  */
23 struct dma_heap_ops {
24 	struct dma_buf *(*allocate)(struct dma_heap *heap,
25 				    unsigned long len,
26 				    u32 fd_flags,
27 				    u64 heap_flags);
28 	long (*get_pool_size)(struct dma_heap *heap);
29 };
30 
31 /**
32  * struct dma_heap_export_info - information needed to export a new dmabuf heap
33  * @name:	used for debugging/device-node name
34  * @ops:	ops struct for this heap
35  * @priv:	heap exporter private data
36  *
37  * Information needed to export a new dmabuf heap.
38  */
39 struct dma_heap_export_info {
40 	const char *name;
41 	const struct dma_heap_ops *ops;
42 	void *priv;
43 };
44 
45 void *dma_heap_get_drvdata(struct dma_heap *heap);
46 
47 /**
48  * dma_heap_get_dev() - get device struct for the heap
49  * @heap: DMA-Heap to retrieve device struct from
50  *
51  * Returns:
52  * The device struct for the heap.
53  */
54 struct device *dma_heap_get_dev(struct dma_heap *heap);
55 
56 /**
57  * dma_heap_get_name() - get heap name
58  * @heap: DMA-Heap to retrieve private data for
59  *
60  * Returns:
61  * The char* for the heap name.
62  */
63 const char *dma_heap_get_name(struct dma_heap *heap);
64 
65 struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info);
66 
67 /**
68  * dma_heap_put - drops a reference to a dmabuf heaps, potentially freeing it
69  * @heap:		heap pointer
70  */
71 void dma_heap_put(struct dma_heap *heap);
72 
73 /**
74  * dma_heap_find - Returns the registered dma_heap with the specified name
75  * @name: Name of the heap to find
76  *
77  * NOTE: dma_heaps returned from this function MUST be released
78  * using dma_heap_put() when the user is done.
79  */
80 struct dma_heap *dma_heap_find(const char *name);
81 
82 /**
83  * dma_heap_buffer_alloc - Allocate dma-buf from a dma_heap
84  * @heap:	dma_heap to allocate from
85  * @len:	size to allocate
86  * @fd_flags:	flags to set on returned dma-buf fd
87  * @heap_flags:	flags to pass to the dma heap
88  *
89  * This is for internal dma-buf allocations only.
90  */
91 struct dma_buf *dma_heap_buffer_alloc(struct dma_heap *heap, size_t len,
92 				      u32 fd_flags,
93 				      u64 heap_flags);
94 
95 /** dma_heap_buffer_free - Free dma_buf allocated by dma_heap_buffer_alloc
96  * @dma_buf:	dma_buf to free
97  *
98  * This is really only a simple wrapper to dma_buf_put()
99  */
100 void dma_heap_buffer_free(struct dma_buf *);
101 
102 /**
103  * dma_heap_bufferfd_alloc - Allocate dma-buf fd from a dma_heap
104  * @heap:	dma_heap to allocate from
105  * @len:	size to allocate
106  * @fd_flags:	flags to set on returned dma-buf fd
107  * @heap_flags:	flags to pass to the dma heap
108  */
109 int dma_heap_bufferfd_alloc(struct dma_heap *heap, size_t len,
110 			    u32 fd_flags,
111 			    u64 heap_flags);
112 
113 /**
114  * dma_heap_try_get_pool_size_kb - Returns total dma-heap pool size in kb
115  * if there is no lock contention. The pool size will always be 0 if no heaps
116  * use pools, or do not implement get_pool_size.
117  **/
118 long dma_heap_try_get_pool_size_kb(void);
119 #endif /* _DMA_HEAPS_H */
120