summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/gpu/nvgpu/common/linux/kmem.c96
-rw-r--r--drivers/gpu/nvgpu/include/nvgpu/kmem.h43
-rw-r--r--drivers/gpu/nvgpu/include/nvgpu/linux/kmem.h81
3 files changed, 112 insertions, 108 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/kmem.c b/drivers/gpu/nvgpu/common/linux/kmem.c
index f38a5e78..0d185e56 100644
--- a/drivers/gpu/nvgpu/common/linux/kmem.c
+++ b/drivers/gpu/nvgpu/common/linux/kmem.c
@@ -14,6 +14,7 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */ 15 */
16 16
17#include <linux/mm.h>
17#include <linux/mutex.h> 18#include <linux/mutex.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
19#include <linux/debugfs.h> 20#include <linux/debugfs.h>
@@ -37,6 +38,101 @@
37 */ 38 */
38static atomic_t kmem_cache_id; 39static atomic_t kmem_cache_id;
39 40
41void *__nvgpu_big_alloc(struct gk20a *g, size_t size, bool clear)
42{
43 void *p;
44
45 if (size > PAGE_SIZE) {
46 if (clear)
47 p = nvgpu_vzalloc(g, size);
48 else
49 p = nvgpu_vmalloc(g, size);
50 } else {
51 if (clear)
52 p = nvgpu_kzalloc(g, size);
53 else
54 p = nvgpu_kmalloc(g, size);
55 }
56
57 return p;
58}
59
60void nvgpu_big_free(struct gk20a *g, void *p)
61{
62 /*
63 * This will have to be fixed eventually. Allocs that use
64 * nvgpu_big_[mz]alloc() will need to remember the size of the alloc
65 * when freeing.
66 */
67 if (virt_addr_valid(p))
68 nvgpu_kfree(g, p);
69 else
70 nvgpu_vfree(g, p);
71}
72
73void *__nvgpu_kmalloc(struct gk20a *g, size_t size, unsigned long ip)
74{
75#ifdef CONFIG_NVGPU_TRACK_MEM_USAGE
76 return __nvgpu_track_kmalloc(g, size, ip);
77#else
78 return kmalloc(size, GFP_KERNEL);
79#endif
80}
81
82void *__nvgpu_kzalloc(struct gk20a *g, size_t size, unsigned long ip)
83{
84#ifdef CONFIG_NVGPU_TRACK_MEM_USAGE
85 return __nvgpu_track_kzalloc(g, size, ip);
86#else
87 return kzalloc(size, GFP_KERNEL);
88#endif
89}
90
91void *__nvgpu_kcalloc(struct gk20a *g, size_t n, size_t size, unsigned long ip)
92{
93#ifdef CONFIG_NVGPU_TRACK_MEM_USAGE
94 return __nvgpu_track_kcalloc(g, n, size, ip);
95#else
96 return kcalloc(n, size, GFP_KERNEL);
97#endif
98}
99
100void *__nvgpu_vmalloc(struct gk20a *g, unsigned long size, unsigned long ip)
101{
102#ifdef CONFIG_NVGPU_TRACK_MEM_USAGE
103 return __nvgpu_track_vmalloc(g, size, ip);
104#else
105 return vmalloc(size);
106#endif
107}
108
109void *__nvgpu_vzalloc(struct gk20a *g, unsigned long size, unsigned long ip)
110{
111#ifdef CONFIG_NVGPU_TRACK_MEM_USAGE
112 return __nvgpu_track_vzalloc(g, size, ip);
113#else
114 return vzalloc(size);
115#endif
116}
117
118void __nvgpu_kfree(struct gk20a *g, void *addr)
119{
120#ifdef CONFIG_NVGPU_TRACK_MEM_USAGE
121 __nvgpu_track_kfree(g, addr);
122#else
123 kfree(addr);
124#endif
125}
126
127void __nvgpu_vfree(struct gk20a *g, void *addr)
128{
129#ifdef CONFIG_NVGPU_TRACK_MEM_USAGE
130 __nvgpu_track_vfree(g, addr);
131#else
132 vfree(addr);
133#endif
134}
135
40#ifdef CONFIG_NVGPU_TRACK_MEM_USAGE 136#ifdef CONFIG_NVGPU_TRACK_MEM_USAGE
41 137
42static void lock_tracker(struct nvgpu_mem_alloc_tracker *tracker) 138static void lock_tracker(struct nvgpu_mem_alloc_tracker *tracker)
diff --git a/drivers/gpu/nvgpu/include/nvgpu/kmem.h b/drivers/gpu/nvgpu/include/nvgpu/kmem.h
index cfbc0da5..5bda2f3a 100644
--- a/drivers/gpu/nvgpu/include/nvgpu/kmem.h
+++ b/drivers/gpu/nvgpu/include/nvgpu/kmem.h
@@ -17,6 +17,8 @@
17#ifndef __NVGPU_KMEM_H__ 17#ifndef __NVGPU_KMEM_H__
18#define __NVGPU_KMEM_H__ 18#define __NVGPU_KMEM_H__
19 19
20#include <nvgpu/types.h>
21
20/* 22/*
21 * Incase this isn't defined already. 23 * Incase this isn't defined already.
22 */ 24 */
@@ -29,12 +31,10 @@ struct gk20a;
29/* 31/*
30 * When there's other implementations make sure they are included instead of 32 * When there's other implementations make sure they are included instead of
31 * Linux when not compiling on Linux! 33 * Linux when not compiling on Linux!
32 *
33 * Also note this is above any usage of size_t. At the moment we don't have a
34 * cross OS way of defining the necessary types used by these APIs. Eventually
35 * we will need a <nvgpu/types.h> include to handle this.
36 */ 34 */
35#ifdef __KERNEL__
37#include <nvgpu/linux/kmem.h> 36#include <nvgpu/linux/kmem.h>
37#endif
38 38
39/** 39/**
40 * DOC: Kmem cache support 40 * DOC: Kmem cache support
@@ -224,24 +224,10 @@ void nvgpu_kmem_fini(struct gk20a *g, int flags);
224#define NVGPU_KMEM_FINI_WARN (1 << 2) 224#define NVGPU_KMEM_FINI_WARN (1 << 2)
225#define NVGPU_KMEM_FINI_BUG (1 << 3) 225#define NVGPU_KMEM_FINI_BUG (1 << 3)
226 226
227static inline void *__nvgpu_big_alloc(struct gk20a *g, size_t size, bool clear) 227/*
228{ 228 * Implemented by the OS interface.
229 void *p; 229 */
230 230void *__nvgpu_big_alloc(struct gk20a *g, size_t size, bool clear);
231 if (size > PAGE_SIZE) {
232 if (clear)
233 p = nvgpu_vzalloc(g, size);
234 else
235 p = nvgpu_vmalloc(g, size);
236 } else {
237 if (clear)
238 p = nvgpu_kzalloc(g, size);
239 else
240 p = nvgpu_kmalloc(g, size);
241 }
242
243 return p;
244}
245 231
246/** 232/**
247 * nvgpu_big_malloc - Pick virtual or physical alloc based on @size 233 * nvgpu_big_malloc - Pick virtual or physical alloc based on @size
@@ -289,17 +275,6 @@ static inline void *nvgpu_big_zalloc(struct gk20a *g, size_t size)
289 * @g - The GPU. 275 * @g - The GPU.
290 * @p - A pointer allocated by nvgpu_big_zalloc() or nvgpu_big_malloc(). 276 * @p - A pointer allocated by nvgpu_big_zalloc() or nvgpu_big_malloc().
291 */ 277 */
292static inline void nvgpu_big_free(struct gk20a *g, void *p) 278void nvgpu_big_free(struct gk20a *g, void *p);
293{
294 /*
295 * This will have to be fixed eventually. Allocs that use
296 * nvgpu_big_[mz]alloc() will need to remember the size of the alloc
297 * when freeing.
298 */
299 if (virt_addr_valid(p))
300 nvgpu_kfree(g, p);
301 else
302 nvgpu_vfree(g, p);
303}
304 279
305#endif /* __NVGPU_KMEM_H__ */ 280#endif /* __NVGPU_KMEM_H__ */
diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/kmem.h b/drivers/gpu/nvgpu/include/nvgpu/linux/kmem.h
index dbafc0ce..dc198a04 100644
--- a/drivers/gpu/nvgpu/include/nvgpu/linux/kmem.h
+++ b/drivers/gpu/nvgpu/include/nvgpu/linux/kmem.h
@@ -17,12 +17,6 @@
17#ifndef __NVGPU_KMEM_LINUX_H__ 17#ifndef __NVGPU_KMEM_LINUX_H__
18#define __NVGPU_KMEM_LINUX_H__ 18#define __NVGPU_KMEM_LINUX_H__
19 19
20#include <linux/mm.h>
21#include <linux/slab.h>
22#include <linux/vmalloc.h>
23
24#include <asm/page.h>
25
26struct gk20a; 20struct gk20a;
27struct device; 21struct device;
28 22
@@ -51,73 +45,12 @@ static inline void nvgpu_kmem_debugfs_init(struct device *dev)
51 * These are the Linux implementations of the various kmem functions defined by 45 * These are the Linux implementations of the various kmem functions defined by
52 * nvgpu. This should not be included directly - instead include <nvgpu/kmem.h>. 46 * nvgpu. This should not be included directly - instead include <nvgpu/kmem.h>.
53 */ 47 */
54 48void *__nvgpu_kmalloc(struct gk20a *g, size_t size, unsigned long ip);
55static inline void *__nvgpu_kmalloc(struct gk20a *g, size_t size, 49void *__nvgpu_kzalloc(struct gk20a *g, size_t size, unsigned long ip);
56 unsigned long ip) 50void *__nvgpu_kcalloc(struct gk20a *g, size_t n, size_t size, unsigned long ip);
57{ 51void *__nvgpu_vmalloc(struct gk20a *g, unsigned long size, unsigned long ip);
58#ifdef CONFIG_NVGPU_TRACK_MEM_USAGE 52void *__nvgpu_vzalloc(struct gk20a *g, unsigned long size, unsigned long ip);
59 return __nvgpu_track_vmalloc(g, size, ip); 53void __nvgpu_kfree(struct gk20a *g, void *addr);
60#else 54void __nvgpu_vfree(struct gk20a *g, void *addr);
61 return kmalloc(size, GFP_KERNEL);
62#endif
63}
64
65static inline void *__nvgpu_kzalloc(struct gk20a *g, size_t size,
66 unsigned long ip)
67{
68#ifdef CONFIG_NVGPU_TRACK_MEM_USAGE
69 return __nvgpu_track_kzalloc(g, size, ip);
70#else
71 return kzalloc(size, GFP_KERNEL);
72#endif
73}
74
75static inline void *__nvgpu_kcalloc(struct gk20a *g, size_t n, size_t size,
76 unsigned long ip)
77{
78#ifdef CONFIG_NVGPU_TRACK_MEM_USAGE
79 return __nvgpu_track_kcalloc(g, n, size, ip);
80#else
81 return kcalloc(n, size, GFP_KERNEL);
82#endif
83}
84
85static inline void *__nvgpu_vmalloc(struct gk20a *g, unsigned long size,
86 unsigned long ip)
87{
88#ifdef CONFIG_NVGPU_TRACK_MEM_USAGE
89 return __nvgpu_track_vmalloc(g, size, ip);
90#else
91 return vmalloc(size);
92#endif
93}
94
95static inline void *__nvgpu_vzalloc(struct gk20a *g, unsigned long size,
96 unsigned long ip)
97{
98#ifdef CONFIG_NVGPU_TRACK_MEM_USAGE
99 return __nvgpu_track_vzalloc(g, size, ip);
100#else
101 return vzalloc(size);
102#endif
103}
104
105static inline void __nvgpu_kfree(struct gk20a *g, void *addr)
106{
107#ifdef CONFIG_NVGPU_TRACK_MEM_USAGE
108 __nvgpu_track_kfree(g, addr);
109#else
110 kfree(addr);
111#endif
112}
113
114static inline void __nvgpu_vfree(struct gk20a *g, void *addr)
115{
116#ifdef CONFIG_NVGPU_TRACK_MEM_USAGE
117 __nvgpu_track_vfree(g, addr);
118#else
119 vfree(addr);
120#endif
121}
122 55
123#endif 56#endif