summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/gk20a/gk20a_allocator.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/gk20a/gk20a_allocator.c')
-rw-r--r--drivers/gpu/nvgpu/gk20a/gk20a_allocator.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/gk20a_allocator.c b/drivers/gpu/nvgpu/gk20a/gk20a_allocator.c
index 25d15d0f..d9e38200 100644
--- a/drivers/gpu/nvgpu/gk20a/gk20a_allocator.c
+++ b/drivers/gpu/nvgpu/gk20a/gk20a_allocator.c
@@ -29,17 +29,23 @@ static struct dentry *gk20a_alloc_debugfs_root;
29 29
30u64 gk20a_alloc_length(struct gk20a_allocator *a) 30u64 gk20a_alloc_length(struct gk20a_allocator *a)
31{ 31{
32 return a->ops->length(a); 32 if (a->ops->length)
33 return a->ops->length(a);
34
35 return 0;
33} 36}
34 37
35u64 gk20a_alloc_base(struct gk20a_allocator *a) 38u64 gk20a_alloc_base(struct gk20a_allocator *a)
36{ 39{
37 return a->ops->base(a); 40 if (a->ops->base)
41 return a->ops->base(a);
42
43 return 0;
38} 44}
39 45
40u64 gk20a_alloc_initialized(struct gk20a_allocator *a) 46u64 gk20a_alloc_initialized(struct gk20a_allocator *a)
41{ 47{
42 if (!a->ops) 48 if (!a->ops || !a->ops->inited)
43 return 0; 49 return 0;
44 50
45 return a->ops->inited(a); 51 return a->ops->inited(a);
@@ -47,7 +53,10 @@ u64 gk20a_alloc_initialized(struct gk20a_allocator *a)
47 53
48u64 gk20a_alloc_end(struct gk20a_allocator *a) 54u64 gk20a_alloc_end(struct gk20a_allocator *a)
49{ 55{
50 return a->ops->end(a); 56 if (a->ops->end)
57 return a->ops->end(a);
58
59 return 0;
51} 60}
52 61
53u64 gk20a_alloc(struct gk20a_allocator *a, u64 len) 62u64 gk20a_alloc(struct gk20a_allocator *a, u64 len)
@@ -62,7 +71,10 @@ void gk20a_free(struct gk20a_allocator *a, u64 addr)
62 71
63u64 gk20a_alloc_fixed(struct gk20a_allocator *a, u64 base, u64 len) 72u64 gk20a_alloc_fixed(struct gk20a_allocator *a, u64 base, u64 len)
64{ 73{
65 return a->ops->alloc_fixed(a, base, len); 74 if (a->ops->alloc_fixed)
75 return a->ops->alloc_fixed(a, base, len);
76
77 return 0;
66} 78}
67 79
68void gk20a_free_fixed(struct gk20a_allocator *a, u64 base, u64 len) 80void gk20a_free_fixed(struct gk20a_allocator *a, u64 base, u64 len)
@@ -92,6 +104,13 @@ int __gk20a_alloc_common_init(struct gk20a_allocator *a,
92 if (!ops) 104 if (!ops)
93 return -EINVAL; 105 return -EINVAL;
94 106
107 /*
108 * This is the bare minimum operations required for a sensible
109 * allocator.
110 */
111 if (!ops->alloc || !ops->free || !ops->fini)
112 return -EINVAL;
113
95 a->ops = ops; 114 a->ops = ops;
96 a->priv = priv; 115 a->priv = priv;
97 a->debug = dbg; 116 a->debug = dbg;