diff options
Diffstat (limited to 'drivers/gpu/nvgpu/gk20a/gk20a_allocator.c')
-rw-r--r-- | drivers/gpu/nvgpu/gk20a/gk20a_allocator.c | 211 |
1 files changed, 0 insertions, 211 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/gk20a_allocator.c b/drivers/gpu/nvgpu/gk20a/gk20a_allocator.c deleted file mode 100644 index 3129b07c..00000000 --- a/drivers/gpu/nvgpu/gk20a/gk20a_allocator.c +++ /dev/null | |||
@@ -1,211 +0,0 @@ | |||
1 | /* | ||
2 | * gk20a allocator | ||
3 | * | ||
4 | * Copyright (c) 2011-2016, NVIDIA CORPORATION. All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms and conditions of the GNU General Public License, | ||
8 | * version 2, as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | * more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/slab.h> | ||
21 | |||
22 | #include "gk20a.h" | ||
23 | #include "mm_gk20a.h" | ||
24 | #include "platform_gk20a.h" | ||
25 | #include "gk20a_allocator.h" | ||
26 | |||
27 | u32 gk20a_alloc_tracing_on; | ||
28 | |||
29 | u64 gk20a_alloc_length(struct gk20a_allocator *a) | ||
30 | { | ||
31 | if (a->ops->length) | ||
32 | return a->ops->length(a); | ||
33 | |||
34 | return 0; | ||
35 | } | ||
36 | |||
37 | u64 gk20a_alloc_base(struct gk20a_allocator *a) | ||
38 | { | ||
39 | if (a->ops->base) | ||
40 | return a->ops->base(a); | ||
41 | |||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | u64 gk20a_alloc_initialized(struct gk20a_allocator *a) | ||
46 | { | ||
47 | if (!a->ops || !a->ops->inited) | ||
48 | return 0; | ||
49 | |||
50 | return a->ops->inited(a); | ||
51 | } | ||
52 | |||
53 | u64 gk20a_alloc_end(struct gk20a_allocator *a) | ||
54 | { | ||
55 | if (a->ops->end) | ||
56 | return a->ops->end(a); | ||
57 | |||
58 | return 0; | ||
59 | } | ||
60 | |||
61 | u64 gk20a_alloc_space(struct gk20a_allocator *a) | ||
62 | { | ||
63 | if (a->ops->space) | ||
64 | return a->ops->space(a); | ||
65 | |||
66 | return 0; | ||
67 | } | ||
68 | |||
69 | u64 gk20a_alloc(struct gk20a_allocator *a, u64 len) | ||
70 | { | ||
71 | return a->ops->alloc(a, len); | ||
72 | } | ||
73 | |||
74 | void gk20a_free(struct gk20a_allocator *a, u64 addr) | ||
75 | { | ||
76 | a->ops->free(a, addr); | ||
77 | } | ||
78 | |||
79 | u64 gk20a_alloc_fixed(struct gk20a_allocator *a, u64 base, u64 len) | ||
80 | { | ||
81 | if (a->ops->alloc_fixed) | ||
82 | return a->ops->alloc_fixed(a, base, len); | ||
83 | |||
84 | return 0; | ||
85 | } | ||
86 | |||
87 | void gk20a_free_fixed(struct gk20a_allocator *a, u64 base, u64 len) | ||
88 | { | ||
89 | /* | ||
90 | * If this operation is not defined for the allocator then just do | ||
91 | * nothing. The alternative would be to fall back on the regular | ||
92 | * free but that may be harmful in unexpected ways. | ||
93 | */ | ||
94 | if (a->ops->free_fixed) | ||
95 | a->ops->free_fixed(a, base, len); | ||
96 | } | ||
97 | |||
98 | int gk20a_alloc_reserve_carveout(struct gk20a_allocator *a, | ||
99 | struct gk20a_alloc_carveout *co) | ||
100 | { | ||
101 | if (a->ops->reserve_carveout) | ||
102 | return a->ops->reserve_carveout(a, co); | ||
103 | |||
104 | return -ENODEV; | ||
105 | } | ||
106 | |||
107 | void gk20a_alloc_release_carveout(struct gk20a_allocator *a, | ||
108 | struct gk20a_alloc_carveout *co) | ||
109 | { | ||
110 | if (a->ops->release_carveout) | ||
111 | a->ops->release_carveout(a, co); | ||
112 | } | ||
113 | |||
114 | void gk20a_alloc_destroy(struct gk20a_allocator *a) | ||
115 | { | ||
116 | a->ops->fini(a); | ||
117 | memset(a, 0, sizeof(*a)); | ||
118 | } | ||
119 | |||
120 | /* | ||
121 | * Handle the common init stuff for a gk20a_allocator. | ||
122 | */ | ||
123 | int __gk20a_alloc_common_init(struct gk20a_allocator *a, | ||
124 | const char *name, void *priv, bool dbg, | ||
125 | const struct gk20a_allocator_ops *ops) | ||
126 | { | ||
127 | if (!ops) | ||
128 | return -EINVAL; | ||
129 | |||
130 | /* | ||
131 | * This is the bare minimum operations required for a sensible | ||
132 | * allocator. | ||
133 | */ | ||
134 | if (!ops->alloc || !ops->free || !ops->fini) | ||
135 | return -EINVAL; | ||
136 | |||
137 | a->ops = ops; | ||
138 | a->priv = priv; | ||
139 | a->debug = dbg; | ||
140 | |||
141 | mutex_init(&a->lock); | ||
142 | |||
143 | strlcpy(a->name, name, sizeof(a->name)); | ||
144 | |||
145 | return 0; | ||
146 | } | ||
147 | |||
148 | void gk20a_alloc_print_stats(struct gk20a_allocator *__a, | ||
149 | struct seq_file *s, int lock) | ||
150 | { | ||
151 | __a->ops->print_stats(__a, s, lock); | ||
152 | } | ||
153 | |||
154 | #ifdef CONFIG_DEBUG_FS | ||
155 | static int __alloc_show(struct seq_file *s, void *unused) | ||
156 | { | ||
157 | struct gk20a_allocator *a = s->private; | ||
158 | |||
159 | gk20a_alloc_print_stats(a, s, 1); | ||
160 | |||
161 | return 0; | ||
162 | } | ||
163 | |||
164 | static int __alloc_open(struct inode *inode, struct file *file) | ||
165 | { | ||
166 | return single_open(file, __alloc_show, inode->i_private); | ||
167 | } | ||
168 | |||
169 | static const struct file_operations __alloc_fops = { | ||
170 | .open = __alloc_open, | ||
171 | .read = seq_read, | ||
172 | .llseek = seq_lseek, | ||
173 | .release = single_release, | ||
174 | }; | ||
175 | #endif | ||
176 | |||
177 | void gk20a_init_alloc_debug(struct gk20a *g, struct gk20a_allocator *a) | ||
178 | { | ||
179 | #ifdef CONFIG_DEBUG_FS | ||
180 | if (!g->debugfs_allocators) | ||
181 | return; | ||
182 | |||
183 | a->debugfs_entry = debugfs_create_file(a->name, S_IRUGO, | ||
184 | g->debugfs_allocators, | ||
185 | a, &__alloc_fops); | ||
186 | #endif | ||
187 | } | ||
188 | |||
189 | void gk20a_fini_alloc_debug(struct gk20a_allocator *a) | ||
190 | { | ||
191 | #ifdef CONFIG_DEBUG_FS | ||
192 | if (!IS_ERR_OR_NULL(a->debugfs_entry)) | ||
193 | debugfs_remove(a->debugfs_entry); | ||
194 | #endif | ||
195 | } | ||
196 | |||
197 | void gk20a_alloc_debugfs_init(struct device *dev) | ||
198 | { | ||
199 | #ifdef CONFIG_DEBUG_FS | ||
200 | struct gk20a_platform *platform = dev_get_drvdata(dev); | ||
201 | struct dentry *gpu_root = platform->debugfs; | ||
202 | struct gk20a *g = get_gk20a(dev); | ||
203 | |||
204 | g->debugfs_allocators = debugfs_create_dir("allocators", gpu_root); | ||
205 | if (IS_ERR_OR_NULL(g->debugfs_allocators)) | ||
206 | return; | ||
207 | |||
208 | debugfs_create_u32("tracing", 0664, g->debugfs_allocators, | ||
209 | &gk20a_alloc_tracing_on); | ||
210 | #endif | ||
211 | } | ||