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 --- drivers/gpu/nvgpu/common/linux/os_fence_android.c | 71 +++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 drivers/gpu/nvgpu/common/linux/os_fence_android.c (limited to 'drivers/gpu/nvgpu/common/linux/os_fence_android.c') 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 @@ +/* + * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include +#include + +#include "gk20a/gk20a.h" + +#include "../drivers/staging/android/sync.h" + +inline struct sync_fence *nvgpu_get_sync_fence(struct nvgpu_os_fence *s) +{ + struct sync_fence *fence = (struct sync_fence *)s->priv; + return fence; +} + +static void nvgpu_os_fence_clear(struct nvgpu_os_fence *fence_out) +{ + fence_out->priv = NULL; + fence_out->g = NULL; + fence_out->ops = NULL; +} + +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) +{ + fence_out->g = g; + fence_out->ops = fops; + fence_out->priv = (void *)fence; +} + +void nvgpu_os_fence_android_drop_ref(struct nvgpu_os_fence *s) +{ + struct sync_fence *fence = nvgpu_get_sync_fence(s); + + sync_fence_put(fence); + + nvgpu_os_fence_clear(s); +} + +int nvgpu_os_fence_fdget(struct nvgpu_os_fence *fence_out, + struct channel_gk20a *c, int fd) +{ + int err; + + err = nvgpu_os_fence_sema_fdget(fence_out, c, fd); + + /* TO-DO + * check if fence is empty and if CONFIG_TEGRA_GK20A_NVHOST + * is enabled, try to get a sync_fence using + * corresponding nvhost method. + */ + if (err) + nvgpu_err(c->g, "error obtaining fence from fd %d", fd); + + return err; +} -- cgit v1.2.2