summaryrefslogtreecommitdiffstats
path: root/drivers/gpu
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
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')
-rw-r--r--drivers/gpu/nvgpu/Makefile.nvgpu3
-rw-r--r--drivers/gpu/nvgpu/common/as.c99
-rw-r--r--drivers/gpu/nvgpu/common/linux/ioctl.c10
-rw-r--r--drivers/gpu/nvgpu/common/linux/ioctl_as.c (renamed from drivers/gpu/nvgpu/gk20a/as_gk20a.c)90
-rw-r--r--drivers/gpu/nvgpu/common/linux/ioctl_as.h26
-rw-r--r--drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c4
-rw-r--r--drivers/gpu/nvgpu/gk20a/gk20a.h8
-rw-r--r--drivers/gpu/nvgpu/include/nvgpu/as.h (renamed from drivers/gpu/nvgpu/gk20a/as_gk20a.h)21
8 files changed, 148 insertions, 113 deletions
diff --git a/drivers/gpu/nvgpu/Makefile.nvgpu b/drivers/gpu/nvgpu/Makefile.nvgpu
index 9186bcc7..e9e7581a 100644
--- a/drivers/gpu/nvgpu/Makefile.nvgpu
+++ b/drivers/gpu/nvgpu/Makefile.nvgpu
@@ -27,6 +27,7 @@ nvgpu-y := \
27 common/linux/timers.o \ 27 common/linux/timers.o \
28 common/linux/ioctl.o \ 28 common/linux/ioctl.o \
29 common/linux/ioctl_ctrl.o \ 29 common/linux/ioctl_ctrl.o \
30 common/linux/ioctl_as.o \
30 common/mm/nvgpu_allocator.o \ 31 common/mm/nvgpu_allocator.o \
31 common/mm/bitmap_allocator.o \ 32 common/mm/bitmap_allocator.o \
32 common/mm/buddy_allocator.o \ 33 common/mm/buddy_allocator.o \
@@ -35,12 +36,12 @@ nvgpu-y := \
35 common/pramin.o \ 36 common/pramin.o \
36 common/nvgpu_common.o \ 37 common/nvgpu_common.o \
37 common/semaphore.o \ 38 common/semaphore.o \
39 common/as.o \
38 common/vbios/bios.o \ 40 common/vbios/bios.o \
39 gk20a/gk20a.o \ 41 gk20a/gk20a.o \
40 gk20a/bus_gk20a.o \ 42 gk20a/bus_gk20a.o \
41 gk20a/pramin_gk20a.o \ 43 gk20a/pramin_gk20a.o \
42 gk20a/sched_gk20a.o \ 44 gk20a/sched_gk20a.o \
43 gk20a/as_gk20a.o \
44 gk20a/ce2_gk20a.o \ 45 gk20a/ce2_gk20a.o \
45 gk20a/fifo_gk20a.o \ 46 gk20a/fifo_gk20a.o \
46 gk20a/channel_gk20a.o \ 47 gk20a/channel_gk20a.o \
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}
diff --git a/drivers/gpu/nvgpu/common/linux/ioctl.c b/drivers/gpu/nvgpu/common/linux/ioctl.c
index 202ea0ef..53b9476e 100644
--- a/drivers/gpu/nvgpu/common/linux/ioctl.c
+++ b/drivers/gpu/nvgpu/common/linux/ioctl.c
@@ -24,9 +24,9 @@
24#include "gk20a/dbg_gpu_gk20a.h" 24#include "gk20a/dbg_gpu_gk20a.h"
25#include "gk20a/ctxsw_trace_gk20a.h" 25#include "gk20a/ctxsw_trace_gk20a.h"
26#include "gk20a/channel_gk20a.h" 26#include "gk20a/channel_gk20a.h"
27#include "gk20a/as_gk20a.h"
28#include "gk20a/tsg_gk20a.h" 27#include "gk20a/tsg_gk20a.h"
29#include "ioctl_ctrl.h" 28#include "ioctl_ctrl.h"
29#include "ioctl_as.h"
30 30
31#define GK20A_NUM_CDEVS 7 31#define GK20A_NUM_CDEVS 7
32 32
@@ -167,9 +167,9 @@ void gk20a_user_deinit(struct device *dev, struct class *class)
167 cdev_del(&g->channel.cdev); 167 cdev_del(&g->channel.cdev);
168 } 168 }
169 169
170 if (g->as.node) { 170 if (g->as_dev.node) {
171 device_destroy(class, g->as.cdev.dev); 171 device_destroy(class, g->as_dev.cdev.dev);
172 cdev_del(&g->as.cdev); 172 cdev_del(&g->as_dev.cdev);
173 } 173 }
174 174
175 if (g->ctrl.node) { 175 if (g->ctrl.node) {
@@ -228,7 +228,7 @@ int gk20a_user_init(struct device *dev, const char *interface_name,
228 goto fail; 228 goto fail;
229 229
230 err = gk20a_create_device(dev, devno++, interface_name, "-as", 230 err = gk20a_create_device(dev, devno++, interface_name, "-as",
231 &g->as.cdev, &g->as.node, 231 &g->as_dev.cdev, &g->as_dev.node,
232 &gk20a_as_ops, 232 &gk20a_as_ops,
233 class); 233 class);
234 if (err) 234 if (err)
diff --git a/drivers/gpu/nvgpu/gk20a/as_gk20a.c b/drivers/gpu/nvgpu/common/linux/ioctl_as.c
index 5acc626b..ff9787db 100644
--- a/drivers/gpu/nvgpu/gk20a/as_gk20a.c
+++ b/drivers/gpu/nvgpu/common/linux/ioctl_as.c
@@ -13,8 +13,6 @@
13 * more details. 13 * more details.
14 */ 14 */
15 15
16#include <linux/slab.h>
17#include <linux/fs.h>
18#include <linux/cdev.h> 16#include <linux/cdev.h>
19#include <linux/uaccess.h> 17#include <linux/uaccess.h>
20 18
@@ -22,89 +20,7 @@
22 20
23#include <uapi/linux/nvgpu.h> 21#include <uapi/linux/nvgpu.h>
24 22
25#include <nvgpu/kmem.h> 23#include "gk20a/gk20a.h"
26
27#include "gk20a.h"
28
29/* dumb allocator... */
30static int generate_as_share_id(struct gk20a_as *as)
31{
32 gk20a_dbg_fn("");
33 return ++as->last_share_id;
34}
35/* still dumb */
36static void release_as_share_id(struct gk20a_as *as, int id)
37{
38 gk20a_dbg_fn("");
39 return;
40}
41
42int gk20a_as_alloc_share(struct gk20a_as *as,
43 u32 big_page_size, u32 flags,
44 struct gk20a_as_share **out)
45{
46 struct gk20a *g = gk20a_from_as(as);
47 struct gk20a_as_share *as_share;
48 int err = 0;
49
50 gk20a_dbg_fn("");
51 g = gk20a_get(g);
52 if (!g)
53 return -ENODEV;
54
55 *out = NULL;
56 as_share = nvgpu_kzalloc(g, sizeof(*as_share));
57 if (!as_share)
58 return -ENOMEM;
59
60 as_share->as = as;
61 as_share->id = generate_as_share_id(as_share->as);
62
63 /* this will set as_share->vm. */
64 err = gk20a_busy(g);
65 if (err)
66 goto failed;
67 err = g->ops.mm.vm_alloc_share(as_share, big_page_size, flags);
68 gk20a_idle(g);
69
70 if (err)
71 goto failed;
72
73 *out = as_share;
74 return 0;
75
76failed:
77 nvgpu_kfree(g, as_share);
78 return err;
79}
80
81/*
82 * channels and the device nodes call this to release.
83 * once the ref_cnt hits zero the share is deleted.
84 */
85int gk20a_as_release_share(struct gk20a_as_share *as_share)
86{
87 struct gk20a *g = as_share->vm->mm->g;
88 int err;
89
90 gk20a_dbg_fn("");
91
92 err = gk20a_busy(g);
93
94 if (err)
95 goto release_fail;
96
97 err = gk20a_vm_release_share(as_share);
98
99 gk20a_idle(g);
100
101release_fail:
102 release_as_share_id(as_share->as, as_share->id);
103 nvgpu_kfree(g, as_share);
104 gk20a_put(g);
105
106 return err;
107}
108 24
109static int gk20a_as_ioctl_bind_channel( 25static int gk20a_as_ioctl_bind_channel(
110 struct gk20a_as_share *as_share, 26 struct gk20a_as_share *as_share,
@@ -333,9 +249,9 @@ int gk20a_as_dev_open(struct inode *inode, struct file *filp)
333 249
334 gk20a_dbg_fn(""); 250 gk20a_dbg_fn("");
335 251
336 g = container_of(inode->i_cdev, struct gk20a, as.cdev); 252 g = container_of(inode->i_cdev, struct gk20a, as_dev.cdev);
337 253
338 err = gk20a_as_alloc_share(&g->as, 0, 0, &as_share); 254 err = gk20a_as_alloc_share(g, 0, 0, &as_share);
339 if (err) { 255 if (err) {
340 gk20a_dbg_fn("failed to alloc share"); 256 gk20a_dbg_fn("failed to alloc share");
341 return err; 257 return err;
diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_as.h b/drivers/gpu/nvgpu/common/linux/ioctl_as.h
new file mode 100644
index 00000000..ae6690a1
--- /dev/null
+++ b/drivers/gpu/nvgpu/common/linux/ioctl_as.h
@@ -0,0 +1,26 @@
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#ifndef __NVGPU_COMMON_LINUX_AS_H__
16#define __NVGPU_COMMON_LINUX_AS_H__
17
18struct inode;
19struct file;
20
21/* struct file_operations driver interface */
22int gk20a_as_dev_open(struct inode *inode, struct file *filp);
23int gk20a_as_dev_release(struct inode *inode, struct file *filp);
24long gk20a_as_dev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
25
26#endif
diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c b/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c
index fa05deb9..6aa376ea 100644
--- a/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c
+++ b/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c
@@ -205,13 +205,13 @@ static int gk20a_ctrl_alloc_as(
205 205
206 snprintf(name, sizeof(name), "nvhost-%s-fd%d", g->name, fd); 206 snprintf(name, sizeof(name), "nvhost-%s-fd%d", g->name, fd);
207 207
208 file = anon_inode_getfile(name, g->as.cdev.ops, NULL, O_RDWR); 208 file = anon_inode_getfile(name, g->as_dev.cdev.ops, NULL, O_RDWR);
209 if (IS_ERR(file)) { 209 if (IS_ERR(file)) {
210 err = PTR_ERR(file); 210 err = PTR_ERR(file);
211 goto clean_up; 211 goto clean_up;
212 } 212 }
213 213
214 err = gk20a_as_alloc_share(&g->as, args->big_page_size, args->flags, 214 err = gk20a_as_alloc_share(g, args->big_page_size, args->flags,
215 &as_share); 215 &as_share);
216 if (err) 216 if (err)
217 goto clean_up_file; 217 goto clean_up_file;
diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.h b/drivers/gpu/nvgpu/gk20a/gk20a.h
index 451e32ca..1158add1 100644
--- a/drivers/gpu/nvgpu/gk20a/gk20a.h
+++ b/drivers/gpu/nvgpu/gk20a/gk20a.h
@@ -37,13 +37,14 @@ struct dbg_profiler_object_data;
37#include <soc/tegra/chip-id.h> 37#include <soc/tegra/chip-id.h>
38#include <linux/version.h> 38#include <linux/version.h>
39#include <linux/atomic.h> 39#include <linux/atomic.h>
40#include <linux/cdev.h>
40 41
41#include "../../../arch/arm/mach-tegra/iomap.h" 42#include "../../../arch/arm/mach-tegra/iomap.h"
42 43
43#include <nvgpu/pramin.h> 44#include <nvgpu/pramin.h>
44#include <nvgpu/acr/nvgpu_acr.h> 45#include <nvgpu/acr/nvgpu_acr.h>
46#include <nvgpu/as.h>
45 47
46#include "as_gk20a.h"
47#include "clk_gk20a.h" 48#include "clk_gk20a.h"
48#include "ce2_gk20a.h" 49#include "ce2_gk20a.h"
49#include "fifo_gk20a.h" 50#include "fifo_gk20a.h"
@@ -1044,6 +1045,11 @@ struct gk20a {
1044 struct { 1045 struct {
1045 struct cdev cdev; 1046 struct cdev cdev;
1046 struct device *node; 1047 struct device *node;
1048 } as_dev;
1049
1050 struct {
1051 struct cdev cdev;
1052 struct device *node;
1047 } dbg; 1053 } dbg;
1048 1054
1049 struct { 1055 struct {
diff --git a/drivers/gpu/nvgpu/gk20a/as_gk20a.h b/drivers/gpu/nvgpu/include/nvgpu/as.h
index 9b0c6e14..0e784396 100644
--- a/drivers/gpu/nvgpu/gk20a/as_gk20a.h
+++ b/drivers/gpu/nvgpu/include/nvgpu/as.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * GK20A Address Spaces 2 * GK20A Address Spaces
3 * 3 *
4 * Copyright (c) 2011-2015, NVIDIA CORPORATION. All rights reserved. 4 * Copyright (c) 2011-2017, NVIDIA CORPORATION. All rights reserved.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify it 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, 7 * under the terms and conditions of the GNU General Public License,
@@ -12,15 +12,9 @@
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details. 13 * more details.
14 */ 14 */
15#ifndef AS_GK20A_H 15#ifndef __NVGPU_AS_H__
16#define AS_GK20A_H 16#define __NVGPU_AS_H__
17 17
18#include <linux/atomic.h>
19#include <linux/cdev.h>
20#include <linux/fs.h>
21
22struct gk20a_as;
23struct gk20a_as_share;
24struct vm_gk20a; 18struct vm_gk20a;
25 19
26struct gk20a_as_share { 20struct gk20a_as_share {
@@ -31,19 +25,12 @@ struct gk20a_as_share {
31 25
32struct gk20a_as { 26struct gk20a_as {
33 int last_share_id; /* dummy allocator for now */ 27 int last_share_id; /* dummy allocator for now */
34 struct cdev cdev;
35 struct device *node;
36}; 28};
37 29
38int gk20a_as_release_share(struct gk20a_as_share *as_share); 30int gk20a_as_release_share(struct gk20a_as_share *as_share);
39 31
40/* struct file_operations driver interface */
41int gk20a_as_dev_open(struct inode *inode, struct file *filp);
42int gk20a_as_dev_release(struct inode *inode, struct file *filp);
43long gk20a_as_dev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
44
45/* if big_page_size == 0, the default big page size is used */ 32/* if big_page_size == 0, the default big page size is used */
46int gk20a_as_alloc_share(struct gk20a_as *as, u32 big_page_size, 33int gk20a_as_alloc_share(struct gk20a *g, u32 big_page_size,
47 u32 flags, struct gk20a_as_share **out); 34 u32 flags, struct gk20a_as_share **out);
48 35
49#endif 36#endif