diff options
Diffstat (limited to 'drivers/gpu/nvgpu/common')
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/os_fence_android.c | 14 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/os_fence_android_syncpt.c | 121 |
2 files changed, 128 insertions, 7 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/os_fence_android.c b/drivers/gpu/nvgpu/common/linux/os_fence_android.c index d689a2a8..d8f70639 100644 --- a/drivers/gpu/nvgpu/common/linux/os_fence_android.c +++ b/drivers/gpu/nvgpu/common/linux/os_fence_android.c | |||
@@ -55,15 +55,15 @@ void nvgpu_os_fence_android_drop_ref(struct nvgpu_os_fence *s) | |||
55 | int nvgpu_os_fence_fdget(struct nvgpu_os_fence *fence_out, | 55 | int nvgpu_os_fence_fdget(struct nvgpu_os_fence *fence_out, |
56 | struct channel_gk20a *c, int fd) | 56 | struct channel_gk20a *c, int fd) |
57 | { | 57 | { |
58 | int err; | 58 | int err = -ENOSYS; |
59 | 59 | ||
60 | err = nvgpu_os_fence_sema_fdget(fence_out, c, fd); | 60 | #ifdef CONFIG_TEGRA_GK20A_NVHOST |
61 | err = nvgpu_os_fence_syncpt_fdget(fence_out, c, fd); | ||
62 | #endif | ||
63 | |||
64 | if (err) | ||
65 | err = nvgpu_os_fence_sema_fdget(fence_out, c, fd); | ||
61 | 66 | ||
62 | /* TO-DO | ||
63 | * check if fence is empty and if CONFIG_TEGRA_GK20A_NVHOST | ||
64 | * is enabled, try to get a sync_fence using | ||
65 | * corresponding nvhost method. | ||
66 | */ | ||
67 | if (err) | 67 | if (err) |
68 | nvgpu_err(c->g, "error obtaining fence from fd %d", fd); | 68 | nvgpu_err(c->g, "error obtaining fence from fd %d", fd); |
69 | 69 | ||
diff --git a/drivers/gpu/nvgpu/common/linux/os_fence_android_syncpt.c b/drivers/gpu/nvgpu/common/linux/os_fence_android_syncpt.c new file mode 100644 index 00000000..76def831 --- /dev/null +++ b/drivers/gpu/nvgpu/common/linux/os_fence_android_syncpt.c | |||
@@ -0,0 +1,121 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include <nvgpu/errno.h> | ||
18 | |||
19 | #include <nvgpu/types.h> | ||
20 | #include <nvgpu/os_fence.h> | ||
21 | #include <nvgpu/linux/os_fence_android.h> | ||
22 | #include <nvgpu/nvhost.h> | ||
23 | #include <nvgpu/atomic.h> | ||
24 | |||
25 | #include "gk20a/gk20a.h" | ||
26 | #include "gk20a/channel_gk20a.h" | ||
27 | #include "gk20a/sync_gk20a.h" | ||
28 | #include "gk20a/channel_sync_gk20a.h" | ||
29 | #include "gk20a/mm_gk20a.h" | ||
30 | |||
31 | #include "../drivers/staging/android/sync.h" | ||
32 | |||
33 | int nvgpu_os_fence_syncpt_wait_gen_cmd(struct nvgpu_os_fence *s, | ||
34 | struct priv_cmd_entry *wait_cmd, | ||
35 | struct channel_gk20a *c, | ||
36 | int max_wait_cmds) | ||
37 | { | ||
38 | int err; | ||
39 | int wait_cmd_size; | ||
40 | int num_wait_cmds; | ||
41 | int i; | ||
42 | u32 wait_id; | ||
43 | struct sync_pt *pt; | ||
44 | |||
45 | struct sync_fence *sync_fence = (struct sync_fence *)s->priv; | ||
46 | |||
47 | if (max_wait_cmds && sync_fence->num_fences > max_wait_cmds) | ||
48 | return -EINVAL; | ||
49 | |||
50 | /* validate syncpt ids */ | ||
51 | for (i = 0; i < sync_fence->num_fences; i++) { | ||
52 | pt = sync_pt_from_fence(sync_fence->cbs[i].sync_pt); | ||
53 | wait_id = nvgpu_nvhost_sync_pt_id(pt); | ||
54 | if (!wait_id || !nvgpu_nvhost_syncpt_is_valid_pt_ext( | ||
55 | c->g->nvhost_dev, wait_id)) { | ||
56 | return -EINVAL; | ||
57 | } | ||
58 | } | ||
59 | |||
60 | num_wait_cmds = nvgpu_nvhost_sync_num_pts(sync_fence); | ||
61 | if (num_wait_cmds == 0) | ||
62 | return 0; | ||
63 | |||
64 | wait_cmd_size = c->g->ops.fifo.get_syncpt_wait_cmd_size(); | ||
65 | err = gk20a_channel_alloc_priv_cmdbuf(c, | ||
66 | wait_cmd_size * num_wait_cmds, wait_cmd); | ||
67 | if (err) { | ||
68 | nvgpu_err(c->g, | ||
69 | "not enough priv cmd buffer space"); | ||
70 | return err; | ||
71 | } | ||
72 | |||
73 | for (i = 0; i < sync_fence->num_fences; i++) { | ||
74 | struct fence *f = sync_fence->cbs[i].sync_pt; | ||
75 | struct sync_pt *pt = sync_pt_from_fence(f); | ||
76 | u32 wait_id = nvgpu_nvhost_sync_pt_id(pt); | ||
77 | u32 wait_value = nvgpu_nvhost_sync_pt_thresh(pt); | ||
78 | |||
79 | err = gk20a_channel_gen_syncpt_wait_cmd(c, wait_id, wait_value, | ||
80 | wait_cmd, wait_cmd_size, i, true); | ||
81 | } | ||
82 | |||
83 | WARN_ON(i != num_wait_cmds); | ||
84 | |||
85 | return 0; | ||
86 | } | ||
87 | |||
88 | static const struct nvgpu_os_fence_ops syncpt_ops = { | ||
89 | .program_waits = nvgpu_os_fence_syncpt_wait_gen_cmd, | ||
90 | .drop_ref = nvgpu_os_fence_android_drop_ref, | ||
91 | }; | ||
92 | |||
93 | int nvgpu_os_fence_syncpt_create( | ||
94 | struct nvgpu_os_fence *fence_out, struct channel_gk20a *c, | ||
95 | struct nvgpu_nvhost_dev *nvhost_dev, u32 id, u32 thresh) | ||
96 | { | ||
97 | struct sync_fence *fence = nvgpu_nvhost_sync_create_fence( | ||
98 | nvhost_dev, id, thresh, "fence"); | ||
99 | |||
100 | if (!fence) { | ||
101 | nvgpu_err(c->g, "error constructing fence %s", "fence"); | ||
102 | return -ENOMEM; | ||
103 | } | ||
104 | |||
105 | nvgpu_os_fence_init(fence_out, c->g, &syncpt_ops, fence); | ||
106 | |||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | int nvgpu_os_fence_syncpt_fdget(struct nvgpu_os_fence *fence_out, | ||
111 | struct channel_gk20a *c, int fd) | ||
112 | { | ||
113 | struct sync_fence *fence = nvgpu_nvhost_sync_fdget(fd); | ||
114 | |||
115 | if (!fence) | ||
116 | return -ENOMEM; | ||
117 | |||
118 | nvgpu_os_fence_init(fence_out, c->g, &syncpt_ops, fence); | ||
119 | |||
120 | return 0; | ||
121 | } \ No newline at end of file | ||