diff options
Diffstat (limited to 'drivers/gpu/nvgpu/common/as.c')
-rw-r--r-- | drivers/gpu/nvgpu/common/as.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/as.c b/drivers/gpu/nvgpu/common/as.c new file mode 100644 index 00000000..3182642a --- /dev/null +++ b/drivers/gpu/nvgpu/common/as.c | |||
@@ -0,0 +1,99 @@ | |||
1 | /* | ||
2 | * GK20A Address Spaces | ||
3 | * | ||
4 | * Copyright (c) 2011-2017, NVIDIA CORPORATION. All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms and conditions of the GNU General Public License, | ||
8 | * version 2, as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | * more details. | ||
14 | */ | ||
15 | |||
16 | #include <trace/events/gk20a.h> | ||
17 | |||
18 | #include <nvgpu/kmem.h> | ||
19 | |||
20 | #include "gk20a/gk20a.h" | ||
21 | |||
22 | /* dumb allocator... */ | ||
23 | static int generate_as_share_id(struct gk20a_as *as) | ||
24 | { | ||
25 | gk20a_dbg_fn(""); | ||
26 | return ++as->last_share_id; | ||
27 | } | ||
28 | /* still dumb */ | ||
29 | static void release_as_share_id(struct gk20a_as *as, int id) | ||
30 | { | ||
31 | gk20a_dbg_fn(""); | ||
32 | return; | ||
33 | } | ||
34 | |||
35 | int gk20a_as_alloc_share(struct gk20a *g, | ||
36 | u32 big_page_size, u32 flags, | ||
37 | struct gk20a_as_share **out) | ||
38 | { | ||
39 | struct gk20a_as_share *as_share; | ||
40 | int err = 0; | ||
41 | |||
42 | gk20a_dbg_fn(""); | ||
43 | g = gk20a_get(g); | ||
44 | if (!g) | ||
45 | return -ENODEV; | ||
46 | |||
47 | *out = NULL; | ||
48 | as_share = nvgpu_kzalloc(g, sizeof(*as_share)); | ||
49 | if (!as_share) | ||
50 | return -ENOMEM; | ||
51 | |||
52 | as_share->as = &g->as; | ||
53 | as_share->id = generate_as_share_id(as_share->as); | ||
54 | |||
55 | /* this will set as_share->vm. */ | ||
56 | err = gk20a_busy(g); | ||
57 | if (err) | ||
58 | goto failed; | ||
59 | err = g->ops.mm.vm_alloc_share(as_share, big_page_size, flags); | ||
60 | gk20a_idle(g); | ||
61 | |||
62 | if (err) | ||
63 | goto failed; | ||
64 | |||
65 | *out = as_share; | ||
66 | return 0; | ||
67 | |||
68 | failed: | ||
69 | nvgpu_kfree(g, as_share); | ||
70 | return err; | ||
71 | } | ||
72 | |||
73 | /* | ||
74 | * channels and the device nodes call this to release. | ||
75 | * once the ref_cnt hits zero the share is deleted. | ||
76 | */ | ||
77 | int gk20a_as_release_share(struct gk20a_as_share *as_share) | ||
78 | { | ||
79 | struct gk20a *g = as_share->vm->mm->g; | ||
80 | int err; | ||
81 | |||
82 | gk20a_dbg_fn(""); | ||
83 | |||
84 | err = gk20a_busy(g); | ||
85 | |||
86 | if (err) | ||
87 | goto release_fail; | ||
88 | |||
89 | err = gk20a_vm_release_share(as_share); | ||
90 | |||
91 | gk20a_idle(g); | ||
92 | |||
93 | release_fail: | ||
94 | release_as_share_id(as_share->as, as_share->id); | ||
95 | gk20a_put(g); | ||
96 | nvgpu_kfree(g, as_share); | ||
97 | |||
98 | return err; | ||
99 | } | ||