From 338500c8e2ee342612d7bc4eb1cd87850228d4e2 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Wed, 5 Sep 2018 15:28:05 -0700 Subject: gpu: nvgpu: Fix MISRA 21.2 violations (public allocator APIs) 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 fixes places in the public allocator APIs. This consists of the various init routines which are used to create an allocator and the debug macro used within the allocator code. The buddy allocator was handled by collapsing the internal '__' prepended version with the non-prefixed version. The only required change was in the page_allocator code which now had to pass in a NULL vm pointer (since the VM is not needed for managing VIDMEM). JIRA NVGPU-1029 Change-Id: I484a144e61789bf594c525c1ca307b96d120830f Signed-off-by: Alex Waterman Reviewed-on: https://git-master.nvidia.com/r/1813578 Reviewed-by: svc-misra-checker Reviewed-by: Terje Bergstrom GVS: Gerrit_Virtual_Submit Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/mm/bitmap_allocator.c | 6 ++-- drivers/gpu/nvgpu/common/mm/buddy_allocator.c | 18 +++------- drivers/gpu/nvgpu/common/mm/lockless_allocator.c | 2 +- drivers/gpu/nvgpu/common/mm/nvgpu_allocator.c | 6 ++-- drivers/gpu/nvgpu/common/mm/page_allocator.c | 7 ++-- drivers/gpu/nvgpu/common/mm/vm.c | 46 ++++++++++++------------ drivers/gpu/nvgpu/include/nvgpu/allocator.h | 33 ++++++++--------- 7 files changed, 54 insertions(+), 64 deletions(-) diff --git a/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c b/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c index 1edfda51..6b9db23c 100644 --- a/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c +++ b/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c @@ -174,7 +174,7 @@ static struct nvgpu_bitmap_alloc *find_alloc_metadata( /* * Tree of alloc meta data stores the address of the alloc not the bit offset. */ -static int __nvgpu_bitmap_store_alloc(struct nvgpu_bitmap_allocator *a, +static int nvgpu_bitmap_store_alloc(struct nvgpu_bitmap_allocator *a, u64 addr, u64 len) { struct nvgpu_bitmap_alloc *alloc = @@ -244,7 +244,7 @@ static u64 nvgpu_bitmap_alloc(struct nvgpu_allocator *na, u64 len) * data it needs around to successfully free this allocation. */ if (!(a->flags & GPU_ALLOC_NO_ALLOC_PAGE) && - __nvgpu_bitmap_store_alloc(a, addr, blks * a->blk_size)) { + nvgpu_bitmap_store_alloc(a, addr, blks * a->blk_size)) { goto fail_reset_bitmap; } @@ -401,7 +401,7 @@ int nvgpu_bitmap_allocator_init(struct gk20a *g, struct nvgpu_allocator *na, return -ENOMEM; } - err = __nvgpu_alloc_common_init(na, g, name, a, false, &bitmap_ops); + err = nvgpu_alloc_common_init(na, g, name, a, false, &bitmap_ops); if (err) { goto fail; } diff --git a/drivers/gpu/nvgpu/common/mm/buddy_allocator.c b/drivers/gpu/nvgpu/common/mm/buddy_allocator.c index b29045ba..3b8d9939 100644 --- a/drivers/gpu/nvgpu/common/mm/buddy_allocator.c +++ b/drivers/gpu/nvgpu/common/mm/buddy_allocator.c @@ -1281,10 +1281,10 @@ static const struct nvgpu_allocator_ops buddy_ops = { * will try and pick a reasonable max order. * @flags: Extra flags necessary. See GPU_BALLOC_*. */ -int __nvgpu_buddy_allocator_init(struct gk20a *g, struct nvgpu_allocator *na, - struct vm_gk20a *vm, const char *name, - u64 base, u64 size, u64 blk_size, - u64 max_order, u64 flags) +int nvgpu_buddy_allocator_init(struct gk20a *g, struct nvgpu_allocator *na, + struct vm_gk20a *vm, const char *name, + u64 base, u64 size, u64 blk_size, + u64 max_order, u64 flags) { int err; u64 pde_size; @@ -1312,7 +1312,7 @@ int __nvgpu_buddy_allocator_init(struct gk20a *g, struct nvgpu_allocator *na, return -ENOMEM; } - err = __nvgpu_alloc_common_init(na, g, name, a, false, &buddy_ops); + err = nvgpu_alloc_common_init(na, g, name, a, false, &buddy_ops); if (err) { goto fail; } @@ -1396,11 +1396,3 @@ fail: nvgpu_kfree(g, a); return err; } - -int nvgpu_buddy_allocator_init(struct gk20a *g, struct nvgpu_allocator *na, - const char *name, u64 base, u64 size, - u64 blk_size, u64 flags) -{ - return __nvgpu_buddy_allocator_init(g, na, NULL, name, - base, size, blk_size, 0, 0); -} diff --git a/drivers/gpu/nvgpu/common/mm/lockless_allocator.c b/drivers/gpu/nvgpu/common/mm/lockless_allocator.c index eec661bc..79bf4cd6 100644 --- a/drivers/gpu/nvgpu/common/mm/lockless_allocator.c +++ b/drivers/gpu/nvgpu/common/mm/lockless_allocator.c @@ -187,7 +187,7 @@ int nvgpu_lockless_allocator_init(struct gk20a *g, struct nvgpu_allocator *na, return -ENOMEM; } - err = __nvgpu_alloc_common_init(na, g, name, a, false, &pool_ops); + err = nvgpu_alloc_common_init(na, g, name, a, false, &pool_ops); if (err) { goto fail; } diff --git a/drivers/gpu/nvgpu/common/mm/nvgpu_allocator.c b/drivers/gpu/nvgpu/common/mm/nvgpu_allocator.c index ec0aa888..bf624162 100644 --- a/drivers/gpu/nvgpu/common/mm/nvgpu_allocator.c +++ b/drivers/gpu/nvgpu/common/mm/nvgpu_allocator.c @@ -145,9 +145,9 @@ void nvgpu_alloc_print_stats(struct nvgpu_allocator *na, /* * Handle the common init stuff for a nvgpu_allocator. */ -int __nvgpu_alloc_common_init(struct nvgpu_allocator *a, struct gk20a *g, - const char *name, void *priv, bool dbg, - const struct nvgpu_allocator_ops *ops) +int nvgpu_alloc_common_init(struct nvgpu_allocator *a, struct gk20a *g, + const char *name, void *priv, bool dbg, + const struct nvgpu_allocator_ops *ops) { int err; diff --git a/drivers/gpu/nvgpu/common/mm/page_allocator.c b/drivers/gpu/nvgpu/common/mm/page_allocator.c index e559cb60..c8bc17c7 100644 --- a/drivers/gpu/nvgpu/common/mm/page_allocator.c +++ b/drivers/gpu/nvgpu/common/mm/page_allocator.c @@ -1022,7 +1022,7 @@ int nvgpu_page_allocator_init(struct gk20a *g, struct nvgpu_allocator *na, return -ENOMEM; } - err = __nvgpu_alloc_common_init(na, g, name, a, false, &page_ops); + err = nvgpu_alloc_common_init(na, g, name, a, false, &page_ops); if (err) { goto fail; } @@ -1053,8 +1053,9 @@ int nvgpu_page_allocator_init(struct gk20a *g, struct nvgpu_allocator *na, snprintf(buddy_name, sizeof(buddy_name), "%s-src", name); - err = nvgpu_buddy_allocator_init(g, &a->source_allocator, buddy_name, - base, length, blk_size, 0); + err = nvgpu_buddy_allocator_init(g, &a->source_allocator, NULL, + buddy_name, base, length, blk_size, + 0ULL, 0ULL); if (err) { goto fail; } diff --git a/drivers/gpu/nvgpu/common/mm/vm.c b/drivers/gpu/nvgpu/common/mm/vm.c index 57d9afb5..b2b83767 100644 --- a/drivers/gpu/nvgpu/common/mm/vm.c +++ b/drivers/gpu/nvgpu/common/mm/vm.c @@ -420,14 +420,14 @@ int __nvgpu_vm_init(struct mm_gk20a *mm, */ if (user_vma_start < user_vma_limit) { snprintf(alloc_name, sizeof(alloc_name), "gk20a_%s", name); - err = __nvgpu_buddy_allocator_init(g, &vm->user, - vm, alloc_name, - user_vma_start, - user_vma_limit - - user_vma_start, - SZ_4K, - GPU_BALLOC_MAX_ORDER, - GPU_ALLOC_GVA_SPACE); + err = nvgpu_buddy_allocator_init(g, &vm->user, + vm, alloc_name, + user_vma_start, + user_vma_limit - + user_vma_start, + SZ_4K, + GPU_BALLOC_MAX_ORDER, + GPU_ALLOC_GVA_SPACE); if (err) { goto clean_up_page_tables; } @@ -446,14 +446,14 @@ int __nvgpu_vm_init(struct mm_gk20a *mm, */ if (user_lp_vma_start < user_lp_vma_limit) { snprintf(alloc_name, sizeof(alloc_name), "gk20a_%s_lp", name); - err = __nvgpu_buddy_allocator_init(g, &vm->user_lp, - vm, alloc_name, - user_lp_vma_start, - user_lp_vma_limit - - user_lp_vma_start, - vm->big_page_size, - GPU_BALLOC_MAX_ORDER, - GPU_ALLOC_GVA_SPACE); + err = nvgpu_buddy_allocator_init(g, &vm->user_lp, + vm, alloc_name, + user_lp_vma_start, + user_lp_vma_limit - + user_lp_vma_start, + vm->big_page_size, + GPU_BALLOC_MAX_ORDER, + GPU_ALLOC_GVA_SPACE); if (err) { goto clean_up_allocators; } @@ -463,13 +463,13 @@ int __nvgpu_vm_init(struct mm_gk20a *mm, * Kernel VMA. Must always exist for an address space. */ snprintf(alloc_name, sizeof(alloc_name), "gk20a_%s-sys", name); - err = __nvgpu_buddy_allocator_init(g, &vm->kernel, - vm, alloc_name, - kernel_vma_start, - kernel_vma_limit - kernel_vma_start, - SZ_4K, - GPU_BALLOC_MAX_ORDER, - kernel_vma_flags); + err = nvgpu_buddy_allocator_init(g, &vm->kernel, + vm, alloc_name, + kernel_vma_start, + kernel_vma_limit - kernel_vma_start, + SZ_4K, + GPU_BALLOC_MAX_ORDER, + kernel_vma_flags); if (err) { goto clean_up_allocators; } diff --git a/drivers/gpu/nvgpu/include/nvgpu/allocator.h b/drivers/gpu/nvgpu/include/nvgpu/allocator.h index 2d9b3d32..2bff0efd 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/allocator.h +++ b/drivers/gpu/nvgpu/include/nvgpu/allocator.h @@ -129,11 +129,11 @@ nvgpu_alloc_carveout_from_co_entry(struct nvgpu_list_node *node) ((uintptr_t)node - offsetof(struct nvgpu_alloc_carveout, co_entry)); }; -#define NVGPU_CARVEOUT(__name, __base, __length) \ - { \ - .name = (__name), \ - .base = (__base), \ - .length = (__length) \ +#define NVGPU_CARVEOUT(local_name, local_base, local_length) \ + { \ + .name = (local_name), \ + .base = (local_base), \ + .length = (local_length) \ } /* @@ -207,13 +207,10 @@ static inline void alloc_unlock(struct nvgpu_allocator *a) /* * Buddy allocator specific initializers. */ -int __nvgpu_buddy_allocator_init(struct gk20a *g, struct nvgpu_allocator *na, - struct vm_gk20a *vm, const char *name, - u64 base, u64 size, u64 blk_size, - u64 max_order, u64 flags); -int nvgpu_buddy_allocator_init(struct gk20a *g, struct nvgpu_allocator *na, - const char *name, u64 base, u64 size, - u64 blk_size, u64 flags); +int nvgpu_buddy_allocator_init(struct gk20a *g, struct nvgpu_allocator *na, + struct vm_gk20a *vm, const char *name, + u64 base, u64 size, u64 blk_size, + u64 max_order, u64 flags); /* * Bitmap initializers. @@ -282,9 +279,9 @@ void nvgpu_init_alloc_debug(struct gk20a *g, struct nvgpu_allocator *a); void nvgpu_fini_alloc_debug(struct nvgpu_allocator *a); #endif -int __nvgpu_alloc_common_init(struct nvgpu_allocator *a, struct gk20a *g, - const char *name, void *priv, bool dbg, - const struct nvgpu_allocator_ops *ops); +int nvgpu_alloc_common_init(struct nvgpu_allocator *a, struct gk20a *g, + const char *name, void *priv, bool dbg, + const struct nvgpu_allocator_ops *ops); static inline void nvgpu_alloc_enable_dbg(struct nvgpu_allocator *a) { @@ -309,7 +306,7 @@ static inline void nvgpu_alloc_disable_dbg(struct nvgpu_allocator *a) } while (0) #endif -#define __alloc_dbg(a, fmt, arg...) \ +#define do_alloc_dbg(a, fmt, arg...) \ nvgpu_log((a)->g, gpu_dbg_alloc, "%25s " fmt, (a)->name, ##arg) /* @@ -325,10 +322,10 @@ static inline void nvgpu_alloc_disable_dbg(struct nvgpu_allocator *a) #define alloc_dbg(a, fmt, arg...) \ do { \ if ((a)->debug) \ - __alloc_dbg((a), fmt, ##arg); \ + do_alloc_dbg((a), fmt, ##arg); \ } while (0) #else -#define alloc_dbg(a, fmt, arg...) __alloc_dbg(a, fmt, ##arg) +#define alloc_dbg(a, fmt, arg...) do_alloc_dbg(a, fmt, ##arg) #endif #endif /* NVGPU_ALLOCATOR_H */ -- cgit v1.2.2