From 4dfd6e43cfe303c8b23421ef32738db2ee52e291 Mon Sep 17 00:00:00 2001 From: Debarshi Dutta Date: Wed, 18 Apr 2018 11:03:02 +0530 Subject: 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 Reviewed-on: https://git-master.nvidia.com/r/1667218 Reviewed-by: mobile promotions Tested-by: mobile promotions --- .../nvgpu/include/nvgpu/linux/os_fence_android.h | 42 ++++++++ drivers/gpu/nvgpu/include/nvgpu/os_fence.h | 111 +++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 drivers/gpu/nvgpu/include/nvgpu/linux/os_fence_android.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/os_fence.h (limited to 'drivers/gpu/nvgpu/include') diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/os_fence_android.h b/drivers/gpu/nvgpu/include/nvgpu/linux/os_fence_android.h new file mode 100644 index 00000000..79cc51ea --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/linux/os_fence_android.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __NVGPU_OS_FENCE_ANDROID_H__ +#define __NVGPU_OS_FENCE_ANDROID_H__ + +struct gk20a; +struct nvgpu_os_fence; +struct sync_fence; +struct channel_gk20a; + +struct sync_fence *nvgpu_get_sync_fence(struct nvgpu_os_fence *s); + +void nvgpu_os_fence_android_drop_ref(struct nvgpu_os_fence *s); + +int nvgpu_os_fence_sema_fdget(struct nvgpu_os_fence *fence_out, + struct channel_gk20a *c, int fd); + +void nvgpu_os_fence_init(struct nvgpu_os_fence *fence_out, + struct gk20a *g, const struct nvgpu_os_fence_ops *fops, + struct sync_fence *fence); + +#endif \ No newline at end of file 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 @@ +/* + * nvgpu os fence + * + * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __NVGPU_OS_FENCE__ +#define __NVGPU_OS_FENCE__ + +struct nvgpu_semaphore; +struct channel_gk20a; +struct priv_cmd_entry; + +/* + * struct nvgpu_os_fence adds an abstraction to the earlier Android Sync + * Framework, specifically the sync-fence mechanism and the newer DMA sync + * APIs from linux-4.9. This abstraction provides the high-level definition + * as well as APIs that can be used by other OSes in future to have their own + * alternatives for the sync-framework. + */ +struct nvgpu_os_fence; + +/* + * struct nvgpu_os_fence depends on the following ops structure + */ +struct nvgpu_os_fence_ops { + /* + * This API is used to iterate through multiple fence points within the + * fence and program the pushbuffer method for wait command. + */ + int (*program_waits)(struct nvgpu_os_fence *s, + struct priv_cmd_entry *wait_cmd, + struct channel_gk20a *c, + int max_wait_cmds); + + /* + * This should be the last operation on the OS fence. The + * OS fence acts as a place-holder for the underlying fence + * implementation e.g. sync_fences. For each construct/fdget call + * there needs to be a drop_ref call. This reduces a reference count + * for the underlying sync_fence. + */ + void (*drop_ref)(struct nvgpu_os_fence *s); +}; + +/* + * The priv structure here is used to contain the struct sync_fence + * for LINUX_VERSION <= 4.9 and dma_fence for LINUX_VERSION > 4.9 + */ +struct nvgpu_os_fence { + void *priv; + struct gk20a *g; + const struct nvgpu_os_fence_ops *ops; +}; + +/* + * This API is used to validate the nvgpu_os_fence + */ +static inline int nvgpu_os_fence_is_initialized(struct nvgpu_os_fence *fence) +{ + return (fence->ops != NULL); +} + +#ifdef CONFIG_SYNC + +int nvgpu_os_fence_sema_create( + struct nvgpu_os_fence *fence_out, + struct channel_gk20a *c, + struct nvgpu_semaphore *sema); + +int nvgpu_os_fence_fdget( + struct nvgpu_os_fence *fence_out, + struct channel_gk20a *c, int fd); + +#else + +static inline int nvgpu_os_fence_sema_create( + struct nvgpu_os_fence *fence_out, + struct channel_gk20a *c, + struct nvgpu_semaphore *sema) +{ + return -ENOSYS; +} +static inline int nvgpu_os_fence_fdget( + struct nvgpu_os_fence *fence_out, + struct channel_gk20a *c, int fd) +{ + return -ENOSYS; +} + +#endif /* CONFIG_SYNC */ + +#endif /* __NVGPU_OS_FENCE__ */ -- cgit v1.2.2