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