summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/gk20a/gk20a_allocator.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/gk20a/gk20a_allocator.h')
-rw-r--r--drivers/gpu/nvgpu/gk20a/gk20a_allocator.h302
1 files changed, 0 insertions, 302 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/gk20a_allocator.h b/drivers/gpu/nvgpu/gk20a/gk20a_allocator.h
deleted file mode 100644
index b12926b3..00000000
--- a/drivers/gpu/nvgpu/gk20a/gk20a_allocator.h
+++ /dev/null
@@ -1,302 +0,0 @@
1/*
2 * Copyright (c) 2011-2016, NVIDIA CORPORATION. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef GK20A_ALLOCATOR_H
18#define GK20A_ALLOCATOR_H
19
20#include <linux/debugfs.h>
21#include <linux/seq_file.h>
22#include <linux/platform_device.h>
23
24/* #define ALLOCATOR_DEBUG */
25
26struct gk20a_allocator;
27struct gk20a_alloc_carveout;
28struct vm_gk20a;
29struct gk20a;
30
31/*
32 * Operations for an allocator to implement.
33 */
34struct gk20a_allocator_ops {
35 u64 (*alloc)(struct gk20a_allocator *allocator, u64 len);
36 void (*free)(struct gk20a_allocator *allocator, u64 addr);
37
38 /*
39 * Special interface to allocate a memory region with a specific
40 * starting address. Yikes. Note: if free() works for freeing both
41 * regular and fixed allocations then free_fixed() does not need to
42 * be implemented. This behavior exists for legacy reasons and should
43 * not be propagated to new allocators.
44 */
45 u64 (*alloc_fixed)(struct gk20a_allocator *allocator,
46 u64 base, u64 len);
47 void (*free_fixed)(struct gk20a_allocator *allocator,
48 u64 base, u64 len);
49
50 /*
51 * Allow allocators to reserve space for carveouts.
52 */
53 int (*reserve_carveout)(struct gk20a_allocator *allocator,
54 struct gk20a_alloc_carveout *co);
55 void (*release_carveout)(struct gk20a_allocator *allocator,
56 struct gk20a_alloc_carveout *co);
57
58 /*
59 * Returns info about the allocator.
60 */
61 u64 (*base)(struct gk20a_allocator *allocator);
62 u64 (*length)(struct gk20a_allocator *allocator);
63 u64 (*end)(struct gk20a_allocator *allocator);
64 int (*inited)(struct gk20a_allocator *allocator);
65 u64 (*space)(struct gk20a_allocator *allocator);
66
67 /* Destructor. */
68 void (*fini)(struct gk20a_allocator *allocator);
69
70 /* Debugging. */
71 void (*print_stats)(struct gk20a_allocator *allocator,
72 struct seq_file *s, int lock);
73};
74
75struct gk20a_allocator {
76 char name[32];
77 struct mutex lock;
78
79 void *priv;
80 const struct gk20a_allocator_ops *ops;
81
82 struct dentry *debugfs_entry;
83 bool debug; /* Control for debug msgs. */
84};
85
86struct gk20a_alloc_carveout {
87 const char *name;
88 u64 base;
89 u64 length;
90
91 struct gk20a_allocator *allocator;
92
93 /*
94 * For usage by the allocator implementation.
95 */
96 struct list_head co_entry;
97};
98
99#define GK20A_CARVEOUT(__name, __base, __length) \
100 { \
101 .name = (__name), \
102 .base = (__base), \
103 .length = (__length) \
104 }
105
106/*
107 * These are the available allocator flags.
108 *
109 * GPU_ALLOC_GVA_SPACE
110 *
111 * This flag makes sense for the buddy allocator only. It specifies that the
112 * allocator will be used for managing a GVA space. When managing GVA spaces
113 * special care has to be taken to ensure that allocations of similar PTE
114 * sizes are placed in the same PDE block. This allows the higher level
115 * code to skip defining both small and large PTE tables for every PDE. That
116 * can save considerable memory for address spaces that have a lot of
117 * allocations.
118 *
119 * GPU_ALLOC_NO_ALLOC_PAGE
120 *
121 * For any allocator that needs to manage a resource in a latency critical
122 * path this flag specifies that the allocator should not use any kmalloc()
123 * or similar functions during normal operation. Initialization routines
124 * may still use kmalloc(). This prevents the possibility of long waits for
125 * pages when using alloc_page(). Currently only the bitmap allocator
126 * implements this functionality.
127 *
128 * Also note that if you accept this flag then you must also define the
129 * free_fixed() function. Since no meta-data is allocated to help free
130 * allocations you need to keep track of the meta-data yourself (in this
131 * case the base and length of the allocation as opposed to just the base
132 * of the allocation).
133 *
134 * GPU_ALLOC_4K_VIDMEM_PAGES
135 *
136 * We manage vidmem pages at a large page granularity for performance
137 * reasons; however, this can lead to wasting memory. For page allocators
138 * setting this flag will tell the allocator to manage pools of 4K pages
139 * inside internally allocated large pages.
140 *
141 * Currently this flag is ignored since the only usage of the page allocator
142 * uses a 4K block size already. However, this flag has been reserved since
143 * it will be necessary in the future.
144 *
145 * GPU_ALLOC_FORCE_CONTIG
146 *
147 * Force allocations to be contiguous. Currently only relevant for page
148 * allocators since all other allocators are naturally contiguous.
149 *
150 * GPU_ALLOC_NO_SCATTER_GATHER
151 *
152 * The page allocator normally returns a scatter gather data structure for
153 * allocations (to handle discontiguous pages). However, at times that can
154 * be annoying so this flag forces the page allocator to return a u64
155 * pointing to the allocation base (requires GPU_ALLOC_FORCE_CONTIG to be
156 * set as well).
157 */
158#define GPU_ALLOC_GVA_SPACE 0x1
159#define GPU_ALLOC_NO_ALLOC_PAGE 0x2
160#define GPU_ALLOC_4K_VIDMEM_PAGES 0x4
161#define GPU_ALLOC_FORCE_CONTIG 0x8
162#define GPU_ALLOC_NO_SCATTER_GATHER 0x10
163
164static inline void alloc_lock(struct gk20a_allocator *a)
165{
166 mutex_lock(&a->lock);
167}
168
169static inline void alloc_unlock(struct gk20a_allocator *a)
170{
171 mutex_unlock(&a->lock);
172}
173
174/*
175 * Buddy allocator specific initializers.
176 */
177int __gk20a_buddy_allocator_init(struct gk20a *g, struct gk20a_allocator *a,
178 struct vm_gk20a *vm, const char *name,
179 u64 base, u64 size, u64 blk_size,
180 u64 max_order, u64 flags);
181int gk20a_buddy_allocator_init(struct gk20a *g, struct gk20a_allocator *a,
182 const char *name, u64 base, u64 size,
183 u64 blk_size, u64 flags);
184
185/*
186 * Bitmap initializers.
187 */
188int gk20a_bitmap_allocator_init(struct gk20a *g, struct gk20a_allocator *a,
189 const char *name, u64 base, u64 length,
190 u64 blk_size, u64 flags);
191
192/*
193 * Page allocator initializers.
194 */
195int gk20a_page_allocator_init(struct gk20a *g, struct gk20a_allocator *a,
196 const char *name, u64 base, u64 length,
197 u64 blk_size, u64 flags);
198
199/*
200 * Lockless allocatior initializers.
201 * Note: This allocator can only allocate fixed-size structures of a
202 * pre-defined size.
203 */
204int gk20a_lockless_allocator_init(struct gk20a *g, struct gk20a_allocator *a,
205 const char *name, u64 base, u64 length,
206 u64 struct_size, u64 flags);
207
208#define GPU_BALLOC_MAX_ORDER 31
209
210/*
211 * Allocator APIs.
212 */
213u64 gk20a_alloc(struct gk20a_allocator *allocator, u64 len);
214void gk20a_free(struct gk20a_allocator *allocator, u64 addr);
215
216u64 gk20a_alloc_fixed(struct gk20a_allocator *allocator, u64 base, u64 len);
217void gk20a_free_fixed(struct gk20a_allocator *allocator, u64 base, u64 len);
218
219int gk20a_alloc_reserve_carveout(struct gk20a_allocator *a,
220 struct gk20a_alloc_carveout *co);
221void gk20a_alloc_release_carveout(struct gk20a_allocator *a,
222 struct gk20a_alloc_carveout *co);
223
224u64 gk20a_alloc_base(struct gk20a_allocator *a);
225u64 gk20a_alloc_length(struct gk20a_allocator *a);
226u64 gk20a_alloc_end(struct gk20a_allocator *a);
227u64 gk20a_alloc_initialized(struct gk20a_allocator *a);
228u64 gk20a_alloc_space(struct gk20a_allocator *a);
229
230void gk20a_alloc_destroy(struct gk20a_allocator *allocator);
231
232void gk20a_alloc_print_stats(struct gk20a_allocator *a,
233 struct seq_file *s, int lock);
234
235/*
236 * Common functionality for the internals of the allocators.
237 */
238void gk20a_init_alloc_debug(struct gk20a *g, struct gk20a_allocator *a);
239void gk20a_fini_alloc_debug(struct gk20a_allocator *a);
240
241int __gk20a_alloc_common_init(struct gk20a_allocator *a,
242 const char *name, void *priv, bool dbg,
243 const struct gk20a_allocator_ops *ops);
244
245static inline void gk20a_alloc_enable_dbg(struct gk20a_allocator *a)
246{
247 a->debug = true;
248}
249
250static inline void gk20a_alloc_disable_dbg(struct gk20a_allocator *a)
251{
252 a->debug = false;
253}
254
255/*
256 * Debug stuff.
257 */
258extern u32 gk20a_alloc_tracing_on;
259
260void gk20a_alloc_debugfs_init(struct device *dev);
261
262#define gk20a_alloc_trace_func() \
263 do { \
264 if (gk20a_alloc_tracing_on) \
265 trace_printk("%s\n", __func__); \
266 } while (0)
267
268#define gk20a_alloc_trace_func_done() \
269 do { \
270 if (gk20a_alloc_tracing_on) \
271 trace_printk("%s_done\n", __func__); \
272 } while (0)
273
274#define __alloc_pstat(seq, allocator, fmt, arg...) \
275 do { \
276 if (s) \
277 seq_printf(seq, fmt, ##arg); \
278 else \
279 alloc_dbg(allocator, fmt, ##arg); \
280 } while (0)
281
282#define __alloc_dbg(a, fmt, arg...) \
283 pr_info("%-25s %25s() " fmt, (a)->name, __func__, ##arg)
284
285#if defined(ALLOCATOR_DEBUG)
286/*
287 * Always print the debug messages...
288 */
289#define alloc_dbg(a, fmt, arg...) __alloc_dbg(a, fmt, ##arg)
290#else
291/*
292 * Only print debug messages if debug is enabled for a given allocator.
293 */
294#define alloc_dbg(a, fmt, arg...) \
295 do { \
296 if ((a)->debug) \
297 __alloc_dbg((a), fmt, ##arg); \
298 } while (0)
299
300#endif
301
302#endif /* GK20A_ALLOCATOR_H */