summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/linux/os_fence_android_syncpt.c
diff options
context:
space:
mode:
authorDebarshi Dutta <ddutta@nvidia.com>2018-04-23 07:56:51 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2018-05-10 11:40:11 -0400
commit70e69e2686527990865b221a60e0ec1e9a53d316 (patch)
tree623d0c2612162227370f7b6eb5388fc5b0e11326 /drivers/gpu/nvgpu/common/linux/os_fence_android_syncpt.c
parent4dfd6e43cfe303c8b23421ef32738db2ee52e291 (diff)
gpu: nvgpu: adapt gk20a_channel_syncpt to use os_fence
This patch adapts gk20a_channel_syncpt to use os_fence for post fence as well as pre-fence(wait) use cases. Jira NVGPU-66 Change-Id: I49627d1f88d52a53511a02f5de60fed6df8350de Signed-off-by: Debarshi Dutta <ddutta@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1676631 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux/os_fence_android_syncpt.c')
-rw-r--r--drivers/gpu/nvgpu/common/linux/os_fence_android_syncpt.c121
1 files changed, 121 insertions, 0 deletions
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
33int 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
88static 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
93int 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
110int 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