summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2018-08-20 17:32:51 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2018-08-22 20:33:26 -0400
commit54b11a456cc5d9a13633b50c2bf167e0d5dafef5 (patch)
tree517c565784775ad71072d07c626a3d248dcda215 /drivers/gpu/nvgpu/common/mm/bitmap_allocator.c
parent67e4f728eae290896ff69991e743328fc67b56e5 (diff)
gpu: nvgpu: Fix MISRA 21.2 violations [1/3]
MISRA 21.2 states that we may not use reserved identifiers; since all identifiers beginning with '_' are reserved by libc, the usage of '__' as a prefix is disallowed. This change removes the usage of the '__a' argument scattered throughout the nvgpu allocator code. JIRA NVGPU-1029 Change-Id: I5a9b8a3e0602ba4d519ca19080951402b6f3287d Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1803351 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common/mm/bitmap_allocator.c')
-rw-r--r--drivers/gpu/nvgpu/common/mm/bitmap_allocator.c98
1 files changed, 49 insertions, 49 deletions
diff --git a/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c b/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c
index 6cdb8f3b..5316783d 100644
--- a/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c
+++ b/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c
@@ -61,10 +61,10 @@ static u64 nvgpu_bitmap_alloc_end(struct nvgpu_allocator *a)
61/* 61/*
62 * @page_size is ignored. 62 * @page_size is ignored.
63 */ 63 */
64static u64 nvgpu_bitmap_alloc_fixed(struct nvgpu_allocator *__a, 64static u64 nvgpu_bitmap_alloc_fixed(struct nvgpu_allocator *na,
65 u64 base, u64 len, u32 page_size) 65 u64 base, u64 len, u32 page_size)
66{ 66{
67 struct nvgpu_bitmap_allocator *a = bitmap_allocator(__a); 67 struct nvgpu_bitmap_allocator *a = bitmap_allocator(na);
68 u64 blks, offs, ret; 68 u64 blks, offs, ret;
69 69
70 /* Compute the bit offset and make sure it's aligned to a block. */ 70 /* Compute the bit offset and make sure it's aligned to a block. */
@@ -80,7 +80,7 @@ static u64 nvgpu_bitmap_alloc_fixed(struct nvgpu_allocator *__a,
80 blks++; 80 blks++;
81 } 81 }
82 82
83 alloc_lock(__a); 83 alloc_lock(na);
84 84
85 /* Check if the space requested is already occupied. */ 85 /* Check if the space requested is already occupied. */
86 ret = bitmap_find_next_zero_area(a->bitmap, a->num_bits, offs, blks, 0); 86 ret = bitmap_find_next_zero_area(a->bitmap, a->num_bits, offs, blks, 0);
@@ -92,15 +92,15 @@ static u64 nvgpu_bitmap_alloc_fixed(struct nvgpu_allocator *__a,
92 92
93 a->bytes_alloced += blks * a->blk_size; 93 a->bytes_alloced += blks * a->blk_size;
94 a->nr_fixed_allocs++; 94 a->nr_fixed_allocs++;
95 alloc_unlock(__a); 95 alloc_unlock(na);
96 96
97 alloc_dbg(__a, "Alloc-fixed 0x%-10llx 0x%-5llx [bits=0x%llx (%llu)]", 97 alloc_dbg(na, "Alloc-fixed 0x%-10llx 0x%-5llx [bits=0x%llx (%llu)]",
98 base, len, blks, blks); 98 base, len, blks, blks);
99 return base; 99 return base;
100 100
101fail: 101fail:
102 alloc_unlock(__a); 102 alloc_unlock(na);
103 alloc_dbg(__a, "Alloc-fixed failed! (0x%llx)", base); 103 alloc_dbg(na, "Alloc-fixed failed! (0x%llx)", base);
104 return 0; 104 return 0;
105} 105}
106 106
@@ -111,10 +111,10 @@ fail:
111 * Note: this function won't do much error checking. Thus you could really 111 * Note: this function won't do much error checking. Thus you could really
112 * confuse the allocator if you misuse this function. 112 * confuse the allocator if you misuse this function.
113 */ 113 */
114static void nvgpu_bitmap_free_fixed(struct nvgpu_allocator *__a, 114static void nvgpu_bitmap_free_fixed(struct nvgpu_allocator *na,
115 u64 base, u64 len) 115 u64 base, u64 len)
116{ 116{
117 struct nvgpu_bitmap_allocator *a = bitmap_allocator(__a); 117 struct nvgpu_bitmap_allocator *a = bitmap_allocator(na);
118 u64 blks, offs; 118 u64 blks, offs;
119 119
120 offs = base >> a->blk_shift; 120 offs = base >> a->blk_shift;
@@ -129,12 +129,12 @@ static void nvgpu_bitmap_free_fixed(struct nvgpu_allocator *__a,
129 blks++; 129 blks++;
130 } 130 }
131 131
132 alloc_lock(__a); 132 alloc_lock(na);
133 bitmap_clear(a->bitmap, offs, blks); 133 bitmap_clear(a->bitmap, offs, blks);
134 a->bytes_freed += blks * a->blk_size; 134 a->bytes_freed += blks * a->blk_size;
135 alloc_unlock(__a); 135 alloc_unlock(na);
136 136
137 alloc_dbg(__a, "Free-fixed 0x%-10llx 0x%-5llx [bits=0x%llx (%llu)]", 137 alloc_dbg(na, "Free-fixed 0x%-10llx 0x%-5llx [bits=0x%llx (%llu)]",
138 base, len, blks, blks); 138 base, len, blks, blks);
139} 139}
140 140
@@ -196,11 +196,11 @@ static int __nvgpu_bitmap_store_alloc(struct nvgpu_bitmap_allocator *a,
196 * @len is in bytes. This routine will figure out the right number of bits to 196 * @len is in bytes. This routine will figure out the right number of bits to
197 * actually allocate. The return is the address in bytes as well. 197 * actually allocate. The return is the address in bytes as well.
198 */ 198 */
199static u64 nvgpu_bitmap_alloc(struct nvgpu_allocator *__a, u64 len) 199static u64 nvgpu_bitmap_alloc(struct nvgpu_allocator *na, u64 len)
200{ 200{
201 u64 blks, addr; 201 u64 blks, addr;
202 unsigned long offs, adjusted_offs, limit; 202 unsigned long offs, adjusted_offs, limit;
203 struct nvgpu_bitmap_allocator *a = bitmap_allocator(__a); 203 struct nvgpu_bitmap_allocator *a = bitmap_allocator(na);
204 204
205 blks = len >> a->blk_shift; 205 blks = len >> a->blk_shift;
206 206
@@ -208,7 +208,7 @@ static u64 nvgpu_bitmap_alloc(struct nvgpu_allocator *__a, u64 len)
208 blks++; 208 blks++;
209 } 209 }
210 210
211 alloc_lock(__a); 211 alloc_lock(na);
212 212
213 /* 213 /*
214 * First look from next_blk and onwards... 214 * First look from next_blk and onwards...
@@ -248,12 +248,12 @@ static u64 nvgpu_bitmap_alloc(struct nvgpu_allocator *__a, u64 len)
248 goto fail_reset_bitmap; 248 goto fail_reset_bitmap;
249 } 249 }
250 250
251 alloc_dbg(__a, "Alloc 0x%-10llx 0x%-5llx [bits=0x%llx (%llu)]", 251 alloc_dbg(na, "Alloc 0x%-10llx 0x%-5llx [bits=0x%llx (%llu)]",
252 addr, len, blks, blks); 252 addr, len, blks, blks);
253 253
254 a->nr_allocs++; 254 a->nr_allocs++;
255 a->bytes_alloced += (blks * a->blk_size); 255 a->bytes_alloced += (blks * a->blk_size);
256 alloc_unlock(__a); 256 alloc_unlock(na);
257 257
258 return addr; 258 return addr;
259 259
@@ -261,18 +261,18 @@ fail_reset_bitmap:
261 bitmap_clear(a->bitmap, offs, blks); 261 bitmap_clear(a->bitmap, offs, blks);
262fail: 262fail:
263 a->next_blk = 0; 263 a->next_blk = 0;
264 alloc_unlock(__a); 264 alloc_unlock(na);
265 alloc_dbg(__a, "Alloc failed!"); 265 alloc_dbg(na, "Alloc failed!");
266 return 0; 266 return 0;
267} 267}
268 268
269static void nvgpu_bitmap_free(struct nvgpu_allocator *__a, u64 addr) 269static void nvgpu_bitmap_free(struct nvgpu_allocator *na, u64 addr)
270{ 270{
271 struct nvgpu_bitmap_allocator *a = bitmap_allocator(__a); 271 struct nvgpu_bitmap_allocator *a = bitmap_allocator(na);
272 struct nvgpu_bitmap_alloc *alloc = NULL; 272 struct nvgpu_bitmap_alloc *alloc = NULL;
273 u64 offs, adjusted_offs, blks; 273 u64 offs, adjusted_offs, blks;
274 274
275 alloc_lock(__a); 275 alloc_lock(na);
276 276
277 if (a->flags & GPU_ALLOC_NO_ALLOC_PAGE) { 277 if (a->flags & GPU_ALLOC_NO_ALLOC_PAGE) {
278 WARN(1, "Using wrong free for NO_ALLOC_PAGE bitmap allocator"); 278 WARN(1, "Using wrong free for NO_ALLOC_PAGE bitmap allocator");
@@ -294,7 +294,7 @@ static void nvgpu_bitmap_free(struct nvgpu_allocator *__a, u64 addr)
294 blks = alloc->length >> a->blk_shift; 294 blks = alloc->length >> a->blk_shift;
295 295
296 bitmap_clear(a->bitmap, offs, blks); 296 bitmap_clear(a->bitmap, offs, blks);
297 alloc_dbg(__a, "Free 0x%-10llx", addr); 297 alloc_dbg(na, "Free 0x%-10llx", addr);
298 298
299 a->bytes_freed += alloc->length; 299 a->bytes_freed += alloc->length;
300 300
@@ -302,12 +302,12 @@ done:
302 if (a->meta_data_cache && alloc) { 302 if (a->meta_data_cache && alloc) {
303 nvgpu_kmem_cache_free(a->meta_data_cache, alloc); 303 nvgpu_kmem_cache_free(a->meta_data_cache, alloc);
304 } 304 }
305 alloc_unlock(__a); 305 alloc_unlock(na);
306} 306}
307 307
308static void nvgpu_bitmap_alloc_destroy(struct nvgpu_allocator *__a) 308static void nvgpu_bitmap_alloc_destroy(struct nvgpu_allocator *na)
309{ 309{
310 struct nvgpu_bitmap_allocator *a = bitmap_allocator(__a); 310 struct nvgpu_bitmap_allocator *a = bitmap_allocator(na);
311 struct nvgpu_bitmap_alloc *alloc; 311 struct nvgpu_bitmap_alloc *alloc;
312 struct nvgpu_rbtree_node *node; 312 struct nvgpu_rbtree_node *node;
313 313
@@ -325,28 +325,28 @@ static void nvgpu_bitmap_alloc_destroy(struct nvgpu_allocator *__a)
325 } 325 }
326 326
327 nvgpu_kmem_cache_destroy(a->meta_data_cache); 327 nvgpu_kmem_cache_destroy(a->meta_data_cache);
328 nvgpu_kfree(nvgpu_alloc_to_gpu(__a), a->bitmap); 328 nvgpu_kfree(nvgpu_alloc_to_gpu(na), a->bitmap);
329 nvgpu_kfree(nvgpu_alloc_to_gpu(__a), a); 329 nvgpu_kfree(nvgpu_alloc_to_gpu(na), a);
330} 330}
331 331
332#ifdef __KERNEL__ 332#ifdef __KERNEL__
333static void nvgpu_bitmap_print_stats(struct nvgpu_allocator *__a, 333static void nvgpu_bitmap_print_stats(struct nvgpu_allocator *na,
334 struct seq_file *s, int lock) 334 struct seq_file *s, int lock)
335{ 335{
336 struct nvgpu_bitmap_allocator *a = bitmap_allocator(__a); 336 struct nvgpu_bitmap_allocator *a = bitmap_allocator(na);
337 337
338 __alloc_pstat(s, __a, "Bitmap allocator params:"); 338 __alloc_pstat(s, na, "Bitmap allocator params:");
339 __alloc_pstat(s, __a, " start = 0x%llx", a->base); 339 __alloc_pstat(s, na, " start = 0x%llx", a->base);
340 __alloc_pstat(s, __a, " end = 0x%llx", a->base + a->length); 340 __alloc_pstat(s, na, " end = 0x%llx", a->base + a->length);
341 __alloc_pstat(s, __a, " blks = 0x%llx", a->num_bits); 341 __alloc_pstat(s, na, " blks = 0x%llx", a->num_bits);
342 342
343 /* Actual stats. */ 343 /* Actual stats. */
344 __alloc_pstat(s, __a, "Stats:"); 344 __alloc_pstat(s, na, "Stats:");
345 __alloc_pstat(s, __a, " Number allocs = 0x%llx", a->nr_allocs); 345 __alloc_pstat(s, na, " Number allocs = 0x%llx", a->nr_allocs);
346 __alloc_pstat(s, __a, " Number fixed = 0x%llx", a->nr_fixed_allocs); 346 __alloc_pstat(s, na, " Number fixed = 0x%llx", a->nr_fixed_allocs);
347 __alloc_pstat(s, __a, " Bytes alloced = 0x%llx", a->bytes_alloced); 347 __alloc_pstat(s, na, " Bytes alloced = 0x%llx", a->bytes_alloced);
348 __alloc_pstat(s, __a, " Bytes freed = 0x%llx", a->bytes_freed); 348 __alloc_pstat(s, na, " Bytes freed = 0x%llx", a->bytes_freed);
349 __alloc_pstat(s, __a, " Outstanding = 0x%llx", 349 __alloc_pstat(s, na, " Outstanding = 0x%llx",
350 a->bytes_alloced - a->bytes_freed); 350 a->bytes_alloced - a->bytes_freed);
351} 351}
352#endif 352#endif
@@ -371,7 +371,7 @@ static const struct nvgpu_allocator_ops bitmap_ops = {
371}; 371};
372 372
373 373
374int nvgpu_bitmap_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a, 374int nvgpu_bitmap_allocator_init(struct gk20a *g, struct nvgpu_allocator *na,
375 const char *name, u64 base, u64 length, 375 const char *name, u64 base, u64 length,
376 u64 blk_size, u64 flags) 376 u64 blk_size, u64 flags)
377{ 377{
@@ -401,7 +401,7 @@ int nvgpu_bitmap_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a,
401 return -ENOMEM; 401 return -ENOMEM;
402 } 402 }
403 403
404 err = __nvgpu_alloc_common_init(__a, g, name, a, false, &bitmap_ops); 404 err = __nvgpu_alloc_common_init(na, g, name, a, false, &bitmap_ops);
405 if (err) { 405 if (err) {
406 goto fail; 406 goto fail;
407 } 407 }
@@ -435,14 +435,14 @@ int nvgpu_bitmap_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a,
435 a->inited = true; 435 a->inited = true;
436 436
437#ifdef CONFIG_DEBUG_FS 437#ifdef CONFIG_DEBUG_FS
438 nvgpu_init_alloc_debug(g, __a); 438 nvgpu_init_alloc_debug(g, na);
439#endif 439#endif
440 alloc_dbg(__a, "New allocator: type bitmap"); 440 alloc_dbg(na, "New allocator: type bitmap");
441 alloc_dbg(__a, " base 0x%llx", a->base); 441 alloc_dbg(na, " base 0x%llx", a->base);
442 alloc_dbg(__a, " bit_offs 0x%llx", a->bit_offs); 442 alloc_dbg(na, " bit_offs 0x%llx", a->bit_offs);
443 alloc_dbg(__a, " size 0x%llx", a->length); 443 alloc_dbg(na, " size 0x%llx", a->length);
444 alloc_dbg(__a, " blk_size 0x%llx", a->blk_size); 444 alloc_dbg(na, " blk_size 0x%llx", a->blk_size);
445 alloc_dbg(__a, " flags 0x%llx", a->flags); 445 alloc_dbg(na, " flags 0x%llx", a->flags);
446 446
447 return 0; 447 return 0;
448 448