summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/os/linux/os_fence_android_sema.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/os/linux/os_fence_android_sema.c')
-rw-r--r--drivers/gpu/nvgpu/os/linux/os_fence_android_sema.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/os/linux/os_fence_android_sema.c b/drivers/gpu/nvgpu/os/linux/os_fence_android_sema.c
new file mode 100644
index 00000000..25832417
--- /dev/null
+++ b/drivers/gpu/nvgpu/os/linux/os_fence_android_sema.c
@@ -0,0 +1,111 @@
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/semaphore.h>
23
24#include "gk20a/channel_sync_gk20a.h"
25#include "gk20a/mm_gk20a.h"
26
27#include "sync_sema_android.h"
28
29#include "../drivers/staging/android/sync.h"
30
31int nvgpu_os_fence_sema_wait_gen_cmd(struct nvgpu_os_fence *s,
32 struct priv_cmd_entry *wait_cmd,
33 struct channel_gk20a *c,
34 int max_wait_cmds)
35{
36 int err;
37 int wait_cmd_size;
38 int num_wait_cmds;
39 int i;
40 struct nvgpu_semaphore *sema;
41 struct sync_fence *sync_fence = nvgpu_get_sync_fence(s);
42
43 wait_cmd_size = c->g->ops.fifo.get_sema_wait_cmd_size();
44
45 num_wait_cmds = sync_fence->num_fences;
46 if (num_wait_cmds == 0)
47 return 0;
48
49 if (max_wait_cmds && num_wait_cmds > max_wait_cmds)
50 return -EINVAL;
51
52 err = gk20a_channel_alloc_priv_cmdbuf(c,
53 wait_cmd_size * num_wait_cmds,
54 wait_cmd);
55 if (err) {
56 nvgpu_err(c->g, "not enough priv cmd buffer space");
57 return err;
58 }
59
60 for (i = 0; i < num_wait_cmds; i++) {
61 struct fence *f = sync_fence->cbs[i].sync_pt;
62 struct sync_pt *pt = sync_pt_from_fence(f);
63
64 sema = gk20a_sync_pt_sema(pt);
65 gk20a_channel_gen_sema_wait_cmd(c, sema, wait_cmd,
66 wait_cmd_size, i);
67 }
68
69 return 0;
70}
71
72static const struct nvgpu_os_fence_ops sema_ops = {
73 .program_waits = nvgpu_os_fence_sema_wait_gen_cmd,
74 .drop_ref = nvgpu_os_fence_android_drop_ref,
75 .install_fence = nvgpu_os_fence_android_install_fd,
76};
77
78int nvgpu_os_fence_sema_create(
79 struct nvgpu_os_fence *fence_out,
80 struct channel_gk20a *c,
81 struct nvgpu_semaphore *sema)
82{
83 struct sync_fence *fence;
84
85 fence = gk20a_sync_fence_create(c, sema, "f-gk20a-0x%04x",
86 nvgpu_semaphore_gpu_ro_va(sema));
87
88 if (!fence) {
89 nvgpu_err(c->g, "error constructing new fence: f-gk20a-0x%04x",
90 (u32)nvgpu_semaphore_gpu_ro_va(sema));
91
92 return -ENOMEM;
93 }
94
95 nvgpu_os_fence_init(fence_out, c->g, &sema_ops, fence);
96
97 return 0;
98}
99
100int nvgpu_os_fence_sema_fdget(struct nvgpu_os_fence *fence_out,
101 struct channel_gk20a *c, int fd)
102{
103 struct sync_fence *fence = gk20a_sync_fence_fdget(fd);
104
105 if (!fence)
106 return -EINVAL;
107
108 nvgpu_os_fence_init(fence_out, c->g, &sema_ops, fence);
109
110 return 0;
111}