summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/as.c
diff options
context:
space:
mode:
authorTerje Bergstrom <tbergstrom@nvidia.com>2017-03-23 15:49:58 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2017-04-02 11:28:22 -0400
commit1e355ca52e2b3ac5f4e433e1bb115f6fd8499954 (patch)
treeec1d0a9fe758c0fbf5f5c877b8d40bca9d5d5002 /drivers/gpu/nvgpu/common/as.c
parent660c9a95104b37c947e0c2f6aeda4c92698b40f4 (diff)
gpu: nvgpu: Split as code to as IOCTL and common
Split as_gk20a.c into two parts: common/linux/ioctl_as.c deals with as related devnodes and ioctls. This file contains all the Linux specific parts of as_gk20a.c. common/as.c deals with general as_gk20a maintenance and is Linux independent. JIRA NVGPU-16 Change-Id: I2d8541e0bd6ce159dc6e4de8e819dfcff0fa8f80 Signed-off-by: Terje Bergstrom <tbergstrom@nvidia.com> Reviewed-on: http://git-master/r/1330803 Reviewed-by: svccoveritychecker <svccoveritychecker@nvidia.com> GVS: Gerrit_Virtual_Submit
Diffstat (limited to 'drivers/gpu/nvgpu/common/as.c')
-rw-r--r--drivers/gpu/nvgpu/common/as.c99
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... */
23static int generate_as_share_id(struct gk20a_as *as)
24{
25 gk20a_dbg_fn("");
26 return ++as->last_share_id;
27}
28/* still dumb */
29static void release_as_share_id(struct gk20a_as *as, int id)
30{
31 gk20a_dbg_fn("");
32 return;
33}
34
35int 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
68failed:
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 */
77int 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
93release_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}