summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/gk20a
diff options
context:
space:
mode:
authorTerje Bergstrom <tbergstrom@nvidia.com>2015-05-18 16:37:54 -0400
committerTerje Bergstrom <tbergstrom@nvidia.com>2015-06-06 10:24:11 -0400
commit0dc66952e4df80b45c77bdbb31ce2a32f216328f (patch)
treed15940a8c50ebdb30886bcdc64155270fc0828bc /drivers/gpu/nvgpu/gk20a
parentd5fd0689c23683c161128cf9b51077d3b8c1c2bc (diff)
gpu: nvgpu: Use vmalloc only when size >4K
When allocation size is 4k or below, we should use kmalloc. vmalloc should be used only for larged allocations. Introduce nvgpu_alloc, which checks the size, and decides the API to use. Change-Id: I593110467cd319851b27e57d1bfe8d228d3f2909 Signed-off-by: Terje Bergstrom <tbergstrom@nvidia.com> Reviewed-on: http://git-master/r/743974 (cherry picked from commit 7f56aa1f0ecafbfde7286353b60e25e494674d26) Reviewed-on: http://git-master/r/753276 Reviewed-by: Automatic_Commit_Validation_User
Diffstat (limited to 'drivers/gpu/nvgpu/gk20a')
-rw-r--r--drivers/gpu/nvgpu/gk20a/channel_gk20a.c4
-rw-r--r--drivers/gpu/nvgpu/gk20a/mm_gk20a.c6
-rw-r--r--drivers/gpu/nvgpu/gk20a/mm_gk20a.h28
3 files changed, 33 insertions, 5 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c
index 643adca5..c12f196d 100644
--- a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c
+++ b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c
@@ -2155,7 +2155,7 @@ static int gk20a_ioctl_channel_submit_gpfifo(
2155 * synchronization; we might still wait and do an increment */ 2155 * synchronization; we might still wait and do an increment */
2156 size = args->num_entries * sizeof(struct nvgpu_gpfifo); 2156 size = args->num_entries * sizeof(struct nvgpu_gpfifo);
2157 if (size) { 2157 if (size) {
2158 gpfifo = vmalloc(size); 2158 gpfifo = nvgpu_alloc(size, false);
2159 if (!gpfifo) 2159 if (!gpfifo)
2160 return -ENOMEM; 2160 return -ENOMEM;
2161 2161
@@ -2190,7 +2190,7 @@ static int gk20a_ioctl_channel_submit_gpfifo(
2190 gk20a_fence_put(fence_out); 2190 gk20a_fence_put(fence_out);
2191 2191
2192clean_up: 2192clean_up:
2193 vfree(gpfifo); 2193 nvgpu_free(gpfifo);
2194 return ret; 2194 return ret;
2195} 2195}
2196 2196
diff --git a/drivers/gpu/nvgpu/gk20a/mm_gk20a.c b/drivers/gpu/nvgpu/gk20a/mm_gk20a.c
index a38db709..342d3ace 100644
--- a/drivers/gpu/nvgpu/gk20a/mm_gk20a.c
+++ b/drivers/gpu/nvgpu/gk20a/mm_gk20a.c
@@ -745,8 +745,8 @@ int gk20a_vm_get_buffers(struct vm_gk20a *vm,
745 745
746 mutex_lock(&vm->update_gmmu_lock); 746 mutex_lock(&vm->update_gmmu_lock);
747 747
748 buffer_list = kzalloc(sizeof(*buffer_list) * 748 buffer_list = nvgpu_alloc(sizeof(*buffer_list) *
749 vm->num_user_mapped_buffers, GFP_KERNEL); 749 vm->num_user_mapped_buffers, true);
750 if (!buffer_list) { 750 if (!buffer_list) {
751 mutex_unlock(&vm->update_gmmu_lock); 751 mutex_unlock(&vm->update_gmmu_lock);
752 return -ENOMEM; 752 return -ENOMEM;
@@ -795,7 +795,7 @@ void gk20a_vm_put_buffers(struct vm_gk20a *vm,
795 795
796 mutex_unlock(&vm->update_gmmu_lock); 796 mutex_unlock(&vm->update_gmmu_lock);
797 797
798 kfree(mapped_buffers); 798 nvgpu_free(mapped_buffers);
799} 799}
800 800
801static void gk20a_vm_unmap_user(struct vm_gk20a *vm, u64 offset) 801static void gk20a_vm_unmap_user(struct vm_gk20a *vm, u64 offset)
diff --git a/drivers/gpu/nvgpu/gk20a/mm_gk20a.h b/drivers/gpu/nvgpu/gk20a/mm_gk20a.h
index 82003cd0..7a627354 100644
--- a/drivers/gpu/nvgpu/gk20a/mm_gk20a.h
+++ b/drivers/gpu/nvgpu/gk20a/mm_gk20a.h
@@ -22,6 +22,7 @@
22#include <linux/dma-attrs.h> 22#include <linux/dma-attrs.h>
23#include <linux/iommu.h> 23#include <linux/iommu.h>
24#include <linux/tegra-soc.h> 24#include <linux/tegra-soc.h>
25#include <linux/vmalloc.h>
25#include <asm/dma-iommu.h> 26#include <asm/dma-iommu.h>
26#include <asm/cacheflush.h> 27#include <asm/cacheflush.h>
27#include "gk20a_allocator.h" 28#include "gk20a_allocator.h"
@@ -628,4 +629,31 @@ void gk20a_mm_init_pdb(struct gk20a *g, void *inst_ptr, u64 pdb_addr);
628extern const struct gk20a_mmu_level gk20a_mm_levels_64k[]; 629extern const struct gk20a_mmu_level gk20a_mm_levels_64k[];
629extern const struct gk20a_mmu_level gk20a_mm_levels_128k[]; 630extern const struct gk20a_mmu_level gk20a_mm_levels_128k[];
630 631
632static inline void *nvgpu_alloc(size_t size, bool clear)
633{
634 void *p;
635
636 if (size > PAGE_SIZE) {
637 if (clear)
638 p = vzalloc(size);
639 else
640 p = vmalloc(size);
641 } else {
642 if (clear)
643 p = kzalloc(size, GFP_KERNEL);
644 else
645 p = kmalloc(size, GFP_KERNEL);
646 }
647
648 return p;
649}
650
651static inline void nvgpu_free(void *p)
652{
653 if (virt_addr_valid(p))
654 kfree(p);
655 else
656 vfree(p);
657}
658
631#endif /* MM_GK20A_H */ 659#endif /* MM_GK20A_H */