diff options
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux')
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/os_fence_android.c | 71 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/os_fence_android_sema.c | 107 |
2 files changed, 178 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/os_fence_android.c b/drivers/gpu/nvgpu/common/linux/os_fence_android.c new file mode 100644 index 00000000..d689a2a8 --- /dev/null +++ b/drivers/gpu/nvgpu/common/linux/os_fence_android.c | |||
@@ -0,0 +1,71 @@ | |||
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 | #include <nvgpu/types.h> | ||
17 | #include <nvgpu/os_fence.h> | ||
18 | #include <nvgpu/linux/os_fence_android.h> | ||
19 | |||
20 | #include "gk20a/gk20a.h" | ||
21 | |||
22 | #include "../drivers/staging/android/sync.h" | ||
23 | |||
24 | inline struct sync_fence *nvgpu_get_sync_fence(struct nvgpu_os_fence *s) | ||
25 | { | ||
26 | struct sync_fence *fence = (struct sync_fence *)s->priv; | ||
27 | return fence; | ||
28 | } | ||
29 | |||
30 | static void nvgpu_os_fence_clear(struct nvgpu_os_fence *fence_out) | ||
31 | { | ||
32 | fence_out->priv = NULL; | ||
33 | fence_out->g = NULL; | ||
34 | fence_out->ops = NULL; | ||
35 | } | ||
36 | |||
37 | void nvgpu_os_fence_init(struct nvgpu_os_fence *fence_out, | ||
38 | struct gk20a *g, const struct nvgpu_os_fence_ops *fops, | ||
39 | struct sync_fence *fence) | ||
40 | { | ||
41 | fence_out->g = g; | ||
42 | fence_out->ops = fops; | ||
43 | fence_out->priv = (void *)fence; | ||
44 | } | ||
45 | |||
46 | void nvgpu_os_fence_android_drop_ref(struct nvgpu_os_fence *s) | ||
47 | { | ||
48 | struct sync_fence *fence = nvgpu_get_sync_fence(s); | ||
49 | |||
50 | sync_fence_put(fence); | ||
51 | |||
52 | nvgpu_os_fence_clear(s); | ||
53 | } | ||
54 | |||
55 | int nvgpu_os_fence_fdget(struct nvgpu_os_fence *fence_out, | ||
56 | struct channel_gk20a *c, int fd) | ||
57 | { | ||
58 | int err; | ||
59 | |||
60 | err = nvgpu_os_fence_sema_fdget(fence_out, c, fd); | ||
61 | |||
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) | ||
68 | nvgpu_err(c->g, "error obtaining fence from fd %d", fd); | ||
69 | |||
70 | return err; | ||
71 | } | ||
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 | |||
30 | int 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 | |||
69 | static 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 | |||
74 | int 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 | |||
96 | int 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 | } | ||