summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/include/nvgpu/os_fence.h
diff options
context:
space:
mode:
authorDebarshi Dutta <ddutta@nvidia.com>2018-04-18 01:33:02 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2018-05-10 11:40:02 -0400
commit4dfd6e43cfe303c8b23421ef32738db2ee52e291 (patch)
tree510ce3c59745ea98e44b355d9c4c4cf101bab9c2 /drivers/gpu/nvgpu/include/nvgpu/os_fence.h
parent90b2f780d414d993571dceccafbc01b371068782 (diff)
gpu: nvgpu: create a wrapper over sync_fences
This patch constructs an abstraction to hide the sync_fence functionality from the common code. struct nvgpu_os_fence acts as an abstraction for struct sync_fence. struct nvgpu_os_fence consists of an ops structure named nvgpu_os_fence_ops which contains an API to do pushbuffer programming to generate wait commands for the fence. The current implementation of nvgpu only allows for wait method on a sync_fence which was generated using a similar backend(i.e. either Nvhost Syncpoints or Semaphores). In this patch, a generic API is introduced which will decide the type of the underlying implementation of the struct nvgpu_os_fence at runtime and run the corresponding wait implementation on it. This patch changes the channel_sync_gk20a's semaphore specific implementation to use the abstract API. A subsequent patch will make the changes for the nvhost_syncpoint based implementations as well. JIRA NVGPU-66 Change-Id: If6675bfde5885c3d15d2ca380bb6c7c0e240e734 Signed-off-by: Debarshi Dutta <ddutta@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1667218 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/include/nvgpu/os_fence.h')
-rw-r--r--drivers/gpu/nvgpu/include/nvgpu/os_fence.h111
1 files changed, 111 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/include/nvgpu/os_fence.h b/drivers/gpu/nvgpu/include/nvgpu/os_fence.h
new file mode 100644
index 00000000..c8d24fc2
--- /dev/null
+++ b/drivers/gpu/nvgpu/include/nvgpu/os_fence.h
@@ -0,0 +1,111 @@
1/*
2 * nvgpu os fence
3 *
4 * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef __NVGPU_OS_FENCE__
26#define __NVGPU_OS_FENCE__
27
28struct nvgpu_semaphore;
29struct channel_gk20a;
30struct priv_cmd_entry;
31
32/*
33 * struct nvgpu_os_fence adds an abstraction to the earlier Android Sync
34 * Framework, specifically the sync-fence mechanism and the newer DMA sync
35 * APIs from linux-4.9. This abstraction provides the high-level definition
36 * as well as APIs that can be used by other OSes in future to have their own
37 * alternatives for the sync-framework.
38 */
39struct nvgpu_os_fence;
40
41/*
42 * struct nvgpu_os_fence depends on the following ops structure
43 */
44struct nvgpu_os_fence_ops {
45 /*
46 * This API is used to iterate through multiple fence points within the
47 * fence and program the pushbuffer method for wait command.
48 */
49 int (*program_waits)(struct nvgpu_os_fence *s,
50 struct priv_cmd_entry *wait_cmd,
51 struct channel_gk20a *c,
52 int max_wait_cmds);
53
54 /*
55 * This should be the last operation on the OS fence. The
56 * OS fence acts as a place-holder for the underlying fence
57 * implementation e.g. sync_fences. For each construct/fdget call
58 * there needs to be a drop_ref call. This reduces a reference count
59 * for the underlying sync_fence.
60 */
61 void (*drop_ref)(struct nvgpu_os_fence *s);
62};
63
64/*
65 * The priv structure here is used to contain the struct sync_fence
66 * for LINUX_VERSION <= 4.9 and dma_fence for LINUX_VERSION > 4.9
67 */
68struct nvgpu_os_fence {
69 void *priv;
70 struct gk20a *g;
71 const struct nvgpu_os_fence_ops *ops;
72};
73
74/*
75 * This API is used to validate the nvgpu_os_fence
76 */
77static inline int nvgpu_os_fence_is_initialized(struct nvgpu_os_fence *fence)
78{
79 return (fence->ops != NULL);
80}
81
82#ifdef CONFIG_SYNC
83
84int nvgpu_os_fence_sema_create(
85 struct nvgpu_os_fence *fence_out,
86 struct channel_gk20a *c,
87 struct nvgpu_semaphore *sema);
88
89int nvgpu_os_fence_fdget(
90 struct nvgpu_os_fence *fence_out,
91 struct channel_gk20a *c, int fd);
92
93#else
94
95static inline int nvgpu_os_fence_sema_create(
96 struct nvgpu_os_fence *fence_out,
97 struct channel_gk20a *c,
98 struct nvgpu_semaphore *sema)
99{
100 return -ENOSYS;
101}
102static inline int nvgpu_os_fence_fdget(
103 struct nvgpu_os_fence *fence_out,
104 struct channel_gk20a *c, int fd)
105{
106 return -ENOSYS;
107}
108
109#endif /* CONFIG_SYNC */
110
111#endif /* __NVGPU_OS_FENCE__ */