summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/mm
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/common/mm')
-rw-r--r--drivers/gpu/nvgpu/common/mm/bitmap_allocator.c24
-rw-r--r--drivers/gpu/nvgpu/common/mm/buddy_allocator.c15
-rw-r--r--drivers/gpu/nvgpu/common/mm/buddy_allocator_priv.h3
-rw-r--r--drivers/gpu/nvgpu/common/mm/lockless_allocator.c11
-rw-r--r--drivers/gpu/nvgpu/common/mm/nvgpu_allocator.c3
-rw-r--r--drivers/gpu/nvgpu/common/mm/page_allocator.c15
6 files changed, 37 insertions, 34 deletions
diff --git a/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c b/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c
index 6fc508d6..6e3bad6f 100644
--- a/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c
+++ b/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c
@@ -19,6 +19,7 @@
19#include <linux/bitops.h> 19#include <linux/bitops.h>
20 20
21#include <nvgpu/allocator.h> 21#include <nvgpu/allocator.h>
22#include <nvgpu/kmem.h>
22 23
23#include "bitmap_allocator_priv.h" 24#include "bitmap_allocator_priv.h"
24 25
@@ -248,12 +249,11 @@ static u64 nvgpu_bitmap_alloc(struct nvgpu_allocator *__a, u64 len)
248 249
249 /* 250 /*
250 * Only do meta-data storage if we are allowed to allocate storage for 251 * Only do meta-data storage if we are allowed to allocate storage for
251 * that meta-data. The issue with using kmalloc() and friends is that 252 * that meta-data. The issue with using malloc and friends is that
252 * in latency and success critical paths an alloc_page() call can either 253 * in latency and success critical paths an alloc_page() call can either
253 * sleep for potentially a long time or, assuming GFP_ATOMIC, fail. 254 * sleep for potentially a long time or fail. Since we might not want
254 * Since we might not want either of these possibilities assume that the 255 * either of these possibilities assume that the caller will keep what
255 * caller will keep what data it needs around to successfully free this 256 * data it needs around to successfully free this allocation.
256 * allocation.
257 */ 257 */
258 if (!(a->flags & GPU_ALLOC_NO_ALLOC_PAGE) && 258 if (!(a->flags & GPU_ALLOC_NO_ALLOC_PAGE) &&
259 __nvgpu_bitmap_store_alloc(a, addr, blks * a->blk_size)) 259 __nvgpu_bitmap_store_alloc(a, addr, blks * a->blk_size))
@@ -332,8 +332,8 @@ static void nvgpu_bitmap_alloc_destroy(struct nvgpu_allocator *__a)
332 } 332 }
333 333
334 nvgpu_kmem_cache_destroy(a->meta_data_cache); 334 nvgpu_kmem_cache_destroy(a->meta_data_cache);
335 kfree(a->bitmap); 335 nvgpu_kfree(nvgpu_alloc_to_gpu(__a), a->bitmap);
336 kfree(a); 336 nvgpu_kfree(nvgpu_alloc_to_gpu(__a), a);
337} 337}
338 338
339static void nvgpu_bitmap_print_stats(struct nvgpu_allocator *__a, 339static void nvgpu_bitmap_print_stats(struct nvgpu_allocator *__a,
@@ -397,11 +397,11 @@ int nvgpu_bitmap_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a,
397 length -= blk_size; 397 length -= blk_size;
398 } 398 }
399 399
400 a = kzalloc(sizeof(struct nvgpu_bitmap_allocator), GFP_KERNEL); 400 a = nvgpu_kzalloc(g, sizeof(struct nvgpu_bitmap_allocator));
401 if (!a) 401 if (!a)
402 return -ENOMEM; 402 return -ENOMEM;
403 403
404 err = __nvgpu_alloc_common_init(__a, name, a, false, &bitmap_ops); 404 err = __nvgpu_alloc_common_init(__a, g, name, a, false, &bitmap_ops);
405 if (err) 405 if (err)
406 goto fail; 406 goto fail;
407 407
@@ -422,8 +422,8 @@ int nvgpu_bitmap_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a,
422 a->bit_offs = a->base >> a->blk_shift; 422 a->bit_offs = a->base >> a->blk_shift;
423 a->flags = flags; 423 a->flags = flags;
424 424
425 a->bitmap = kcalloc(BITS_TO_LONGS(a->num_bits), sizeof(*a->bitmap), 425 a->bitmap = nvgpu_kcalloc(g, BITS_TO_LONGS(a->num_bits),
426 GFP_KERNEL); 426 sizeof(*a->bitmap));
427 if (!a->bitmap) { 427 if (!a->bitmap) {
428 err = -ENOMEM; 428 err = -ENOMEM;
429 goto fail; 429 goto fail;
@@ -445,6 +445,6 @@ int nvgpu_bitmap_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a,
445fail: 445fail:
446 if (a->meta_data_cache) 446 if (a->meta_data_cache)
447 nvgpu_kmem_cache_destroy(a->meta_data_cache); 447 nvgpu_kmem_cache_destroy(a->meta_data_cache);
448 kfree(a); 448 nvgpu_kfree(g, a);
449 return err; 449 return err;
450} 450}
diff --git a/drivers/gpu/nvgpu/common/mm/buddy_allocator.c b/drivers/gpu/nvgpu/common/mm/buddy_allocator.c
index 6f4c670a..246be974 100644
--- a/drivers/gpu/nvgpu/common/mm/buddy_allocator.c
+++ b/drivers/gpu/nvgpu/common/mm/buddy_allocator.c
@@ -18,6 +18,7 @@
18#include <linux/slab.h> 18#include <linux/slab.h>
19 19
20#include <nvgpu/allocator.h> 20#include <nvgpu/allocator.h>
21#include <nvgpu/kmem.h>
21 22
22#include "gk20a/mm_gk20a.h" 23#include "gk20a/mm_gk20a.h"
23#include "gk20a/platform_gk20a.h" 24#include "gk20a/platform_gk20a.h"
@@ -304,7 +305,7 @@ static void nvgpu_buddy_allocator_destroy(struct nvgpu_allocator *__a)
304 } 305 }
305 306
306 nvgpu_kmem_cache_destroy(a->buddy_cache); 307 nvgpu_kmem_cache_destroy(a->buddy_cache);
307 kfree(a); 308 nvgpu_kfree(nvgpu_alloc_to_gpu(__a), a);
308 309
309 alloc_unlock(__a); 310 alloc_unlock(__a);
310} 311}
@@ -809,7 +810,7 @@ static void __balloc_do_free_fixed(struct nvgpu_buddy_allocator *a,
809 balloc_coalesce(a, bud); 810 balloc_coalesce(a, bud);
810 } 811 }
811 812
812 kfree(falloc); 813 nvgpu_kfree(nvgpu_alloc_to_gpu(a->owner), falloc);
813} 814}
814 815
815/* 816/*
@@ -893,7 +894,7 @@ static u64 __nvgpu_balloc_fixed_buddy(struct nvgpu_allocator *__a,
893 goto fail; 894 goto fail;
894 } 895 }
895 896
896 falloc = kmalloc(sizeof(*falloc), GFP_KERNEL); 897 falloc = nvgpu_kmalloc(nvgpu_alloc_to_gpu(__a), sizeof(*falloc));
897 if (!falloc) 898 if (!falloc)
898 goto fail; 899 goto fail;
899 900
@@ -932,7 +933,7 @@ static u64 __nvgpu_balloc_fixed_buddy(struct nvgpu_allocator *__a,
932fail_unlock: 933fail_unlock:
933 alloc_unlock(__a); 934 alloc_unlock(__a);
934fail: 935fail:
935 kfree(falloc); 936 nvgpu_kfree(nvgpu_alloc_to_gpu(__a), falloc);
936 nvgpu_alloc_trace_func_done(); 937 nvgpu_alloc_trace_func_done();
937 return 0; 938 return 0;
938} 939}
@@ -1261,11 +1262,11 @@ int __nvgpu_buddy_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a,
1261 if (flags & GPU_ALLOC_GVA_SPACE && !vm) 1262 if (flags & GPU_ALLOC_GVA_SPACE && !vm)
1262 return -EINVAL; 1263 return -EINVAL;
1263 1264
1264 a = kzalloc(sizeof(struct nvgpu_buddy_allocator), GFP_KERNEL); 1265 a = nvgpu_kzalloc(g, sizeof(struct nvgpu_buddy_allocator));
1265 if (!a) 1266 if (!a)
1266 return -ENOMEM; 1267 return -ENOMEM;
1267 1268
1268 err = __nvgpu_alloc_common_init(__a, name, a, false, &buddy_ops); 1269 err = __nvgpu_alloc_common_init(__a, g, name, a, false, &buddy_ops);
1269 if (err) 1270 if (err)
1270 goto fail; 1271 goto fail;
1271 1272
@@ -1339,7 +1340,7 @@ int __nvgpu_buddy_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a,
1339fail: 1340fail:
1340 if (a->buddy_cache) 1341 if (a->buddy_cache)
1341 nvgpu_kmem_cache_destroy(a->buddy_cache); 1342 nvgpu_kmem_cache_destroy(a->buddy_cache);
1342 kfree(a); 1343 nvgpu_kfree(g, a);
1343 return err; 1344 return err;
1344} 1345}
1345 1346
diff --git a/drivers/gpu/nvgpu/common/mm/buddy_allocator_priv.h b/drivers/gpu/nvgpu/common/mm/buddy_allocator_priv.h
index 56aaea62..935b3f1c 100644
--- a/drivers/gpu/nvgpu/common/mm/buddy_allocator_priv.h
+++ b/drivers/gpu/nvgpu/common/mm/buddy_allocator_priv.h
@@ -20,8 +20,7 @@
20#include <linux/list.h> 20#include <linux/list.h>
21#include <linux/rbtree.h> 21#include <linux/rbtree.h>
22 22
23#include <nvgpu/kmem.h> 23struct nvgpu_kmem_cache;
24
25struct nvgpu_allocator; 24struct nvgpu_allocator;
26struct vm_gk20a; 25struct vm_gk20a;
27 26
diff --git a/drivers/gpu/nvgpu/common/mm/lockless_allocator.c b/drivers/gpu/nvgpu/common/mm/lockless_allocator.c
index e3063a42..6fd9bc48 100644
--- a/drivers/gpu/nvgpu/common/mm/lockless_allocator.c
+++ b/drivers/gpu/nvgpu/common/mm/lockless_allocator.c
@@ -20,6 +20,7 @@
20#include <linux/atomic.h> 20#include <linux/atomic.h>
21 21
22#include <nvgpu/allocator.h> 22#include <nvgpu/allocator.h>
23#include <nvgpu/kmem.h>
23 24
24#include "lockless_allocator_priv.h" 25#include "lockless_allocator_priv.h"
25 26
@@ -106,7 +107,7 @@ static void nvgpu_lockless_alloc_destroy(struct nvgpu_allocator *a)
106 nvgpu_fini_alloc_debug(a); 107 nvgpu_fini_alloc_debug(a);
107 108
108 vfree(pa->next); 109 vfree(pa->next);
109 kfree(pa); 110 nvgpu_kfree(nvgpu_alloc_to_gpu(a), pa);
110} 111}
111 112
112static void nvgpu_lockless_print_stats(struct nvgpu_allocator *a, 113static void nvgpu_lockless_print_stats(struct nvgpu_allocator *a,
@@ -154,7 +155,7 @@ int nvgpu_lockless_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a,
154 return -EINVAL; 155 return -EINVAL;
155 156
156 /* 157 /*
157 * Ensure we have space for atleast one node & there's no overflow. 158 * Ensure we have space for at least one node & there's no overflow.
158 * In order to control memory footprint, we require count < INT_MAX 159 * In order to control memory footprint, we require count < INT_MAX
159 */ 160 */
160 count = length; 161 count = length;
@@ -162,11 +163,11 @@ int nvgpu_lockless_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a,
162 if (!base || !count || count > INT_MAX) 163 if (!base || !count || count > INT_MAX)
163 return -EINVAL; 164 return -EINVAL;
164 165
165 a = kzalloc(sizeof(struct nvgpu_lockless_allocator), GFP_KERNEL); 166 a = nvgpu_kzalloc(g, sizeof(struct nvgpu_lockless_allocator));
166 if (!a) 167 if (!a)
167 return -ENOMEM; 168 return -ENOMEM;
168 169
169 err = __nvgpu_alloc_common_init(__a, name, a, false, &pool_ops); 170 err = __nvgpu_alloc_common_init(__a, g, name, a, false, &pool_ops);
170 if (err) 171 if (err)
171 goto fail; 172 goto fail;
172 173
@@ -202,6 +203,6 @@ int nvgpu_lockless_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a,
202 return 0; 203 return 0;
203 204
204fail: 205fail:
205 kfree(a); 206 nvgpu_kfree(g, a);
206 return err; 207 return err;
207} 208}
diff --git a/drivers/gpu/nvgpu/common/mm/nvgpu_allocator.c b/drivers/gpu/nvgpu/common/mm/nvgpu_allocator.c
index 24a76a0b..02b7b48d 100644
--- a/drivers/gpu/nvgpu/common/mm/nvgpu_allocator.c
+++ b/drivers/gpu/nvgpu/common/mm/nvgpu_allocator.c
@@ -123,7 +123,7 @@ void nvgpu_alloc_destroy(struct nvgpu_allocator *a)
123/* 123/*
124 * Handle the common init stuff for a nvgpu_allocator. 124 * Handle the common init stuff for a nvgpu_allocator.
125 */ 125 */
126int __nvgpu_alloc_common_init(struct nvgpu_allocator *a, 126int __nvgpu_alloc_common_init(struct nvgpu_allocator *a, struct gk20a *g,
127 const char *name, void *priv, bool dbg, 127 const char *name, void *priv, bool dbg,
128 const struct nvgpu_allocator_ops *ops) 128 const struct nvgpu_allocator_ops *ops)
129{ 129{
@@ -143,6 +143,7 @@ int __nvgpu_alloc_common_init(struct nvgpu_allocator *a,
143 if (err) 143 if (err)
144 return err; 144 return err;
145 145
146 a->g = g;
146 a->ops = ops; 147 a->ops = ops;
147 a->priv = priv; 148 a->priv = priv;
148 a->debug = dbg; 149 a->debug = dbg;
diff --git a/drivers/gpu/nvgpu/common/mm/page_allocator.c b/drivers/gpu/nvgpu/common/mm/page_allocator.c
index 193decc9..7d2cedc9 100644
--- a/drivers/gpu/nvgpu/common/mm/page_allocator.c
+++ b/drivers/gpu/nvgpu/common/mm/page_allocator.c
@@ -21,6 +21,7 @@
21 21
22#include <nvgpu/allocator.h> 22#include <nvgpu/allocator.h>
23#include <nvgpu/page_allocator.h> 23#include <nvgpu/page_allocator.h>
24#include <nvgpu/kmem.h>
24 25
25#include "buddy_allocator_priv.h" 26#include "buddy_allocator_priv.h"
26 27
@@ -760,7 +761,7 @@ static void nvgpu_page_allocator_destroy(struct nvgpu_allocator *__a)
760 struct nvgpu_page_allocator *a = page_allocator(__a); 761 struct nvgpu_page_allocator *a = page_allocator(__a);
761 762
762 alloc_lock(__a); 763 alloc_lock(__a);
763 kfree(a); 764 nvgpu_kfree(nvgpu_alloc_to_gpu(__a), a);
764 __a->priv = NULL; 765 __a->priv = NULL;
765 alloc_unlock(__a); 766 alloc_unlock(__a);
766} 767}
@@ -848,9 +849,9 @@ static int nvgpu_page_alloc_init_slabs(struct nvgpu_page_allocator *a)
848 size_t nr_slabs = ilog2(a->page_size >> 12); 849 size_t nr_slabs = ilog2(a->page_size >> 12);
849 unsigned int i; 850 unsigned int i;
850 851
851 a->slabs = kcalloc(nr_slabs, 852 a->slabs = nvgpu_kcalloc(nvgpu_alloc_to_gpu(a->owner),
852 sizeof(struct page_alloc_slab), 853 nr_slabs,
853 GFP_KERNEL); 854 sizeof(struct page_alloc_slab));
854 if (!a->slabs) 855 if (!a->slabs)
855 return -ENOMEM; 856 return -ENOMEM;
856 a->nr_slabs = nr_slabs; 857 a->nr_slabs = nr_slabs;
@@ -881,11 +882,11 @@ int nvgpu_page_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a,
881 if (blk_size < SZ_4K) 882 if (blk_size < SZ_4K)
882 return -EINVAL; 883 return -EINVAL;
883 884
884 a = kzalloc(sizeof(struct nvgpu_page_allocator), GFP_KERNEL); 885 a = nvgpu_kzalloc(g, sizeof(struct nvgpu_page_allocator));
885 if (!a) 886 if (!a)
886 return -ENOMEM; 887 return -ENOMEM;
887 888
888 err = __nvgpu_alloc_common_init(__a, name, a, false, &page_ops); 889 err = __nvgpu_alloc_common_init(__a, g, name, a, false, &page_ops);
889 if (err) 890 if (err)
890 goto fail; 891 goto fail;
891 892
@@ -938,6 +939,6 @@ fail:
938 nvgpu_kmem_cache_destroy(a->chunk_cache); 939 nvgpu_kmem_cache_destroy(a->chunk_cache);
939 if (a->slab_page_cache) 940 if (a->slab_page_cache)
940 nvgpu_kmem_cache_destroy(a->slab_page_cache); 941 nvgpu_kmem_cache_destroy(a->slab_page_cache);
941 kfree(a); 942 nvgpu_kfree(g, a);
942 return err; 943 return err;
943} 944}