From 98335c29b22a36ead7f581f4435bbd966707852d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konsta=20H=C3=B6ltt=C3=A4?= Date: Fri, 5 Jun 2020 09:44:59 +0300 Subject: [PATCH] gpu: nvgpu: make os_fence_android_syncpt common MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The differences between sync_fence ("android sync") and dma_fence are abstracted away by nvhost in the nvhost_fence interface. There is no need to have separate android and dma os fences for syncpoints; unify the general implementation so that it's always used when requested for the build. Jira NVGPU-5386 Change-Id: Ia829e93e18d03064ff46ab1271547de2d1fb1cae Signed-off-by: Konsta Hölttä Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2356158 Tested-by: mobile promotions Reviewed-by: mobile promotions --- arch/nvgpu-linux.yaml | 4 +- drivers/gpu/nvgpu/Makefile | 11 ++- .../include/nvgpu/linux/os_fence_android.h | 4 -- .../nvgpu/include/nvgpu/linux/os_fence_dma.h | 4 -- drivers/gpu/nvgpu/os/linux/os_fence_android.c | 18 +---- .../nvgpu/os/linux/os_fence_android_sema.c | 1 + drivers/gpu/nvgpu/os/linux/os_fence_dma.c | 18 +---- .../gpu/nvgpu/os/linux/os_fence_dma_sema.c | 1 + .../gpu/nvgpu/os/linux/os_fence_dma_syncpt.c | 70 ------------------- drivers/gpu/nvgpu/os/linux/os_fence_priv.h | 38 ++++++++++ ...nce_android_syncpt.c => os_fence_syncpt.c} | 11 +-- 11 files changed, 57 insertions(+), 123 deletions(-) delete mode 100644 drivers/gpu/nvgpu/os/linux/os_fence_dma_syncpt.c create mode 100644 drivers/gpu/nvgpu/os/linux/os_fence_priv.h rename drivers/gpu/nvgpu/os/linux/{os_fence_android_syncpt.c => os_fence_syncpt.c} (89%) diff --git a/arch/nvgpu-linux.yaml b/arch/nvgpu-linux.yaml index bea0afccf..b647215de 100644 --- a/arch/nvgpu-linux.yaml +++ b/arch/nvgpu-linux.yaml @@ -142,10 +142,10 @@ nvlink: fence: sources: [ os/linux/os_fence_android.c, os/linux/os_fence_android_sema.c, - os/linux/os_fence_android_syncpt.c, os/linux/os_fence_dma.c, os/linux/os_fence_dma_sema.c, - os/linux/os_fence_dma_syncpt.c, + os/linux/os_fence_syncpt.c, + os/linux/os_fence_priv.h, os/linux/sync_sema_android.c, os/linux/sync_sema_android.h, os/linux/sync_sema_dma.c, diff --git a/drivers/gpu/nvgpu/Makefile b/drivers/gpu/nvgpu/Makefile index 609401b3d..28ea1cab0 100644 --- a/drivers/gpu/nvgpu/Makefile +++ b/drivers/gpu/nvgpu/Makefile @@ -449,12 +449,11 @@ nvgpu-$(CONFIG_NVGPU_SYNCFD_STABLE) += \ os/linux/os_fence_dma.o \ os/linux/os_fence_dma_sema.o -ifeq ($(CONFIG_TEGRA_GK20A_NVHOST), y) -nvgpu-$(CONFIG_NVGPU_SYNCFD_ANDROID) += \ - os/linux/os_fence_android_syncpt.o -nvgpu-$(CONFIG_NVGPU_SYNCFD_STABLE) += \ - os/linux/os_fence_dma_syncpt.o -nvgpu-y += common/sync/channel_sync_syncpt.o +nvgpu-$(CONFIG_TEGRA_GK20A_NVHOST) += \ + common/sync/channel_sync_syncpt.o +ifneq ($(CONFIG_NVGPU_SYNCFD_NONE),y) +nvgpu-$(CONFIG_TEGRA_GK20A_NVHOST) += \ + os/linux/os_fence_syncpt.o endif nvgpu-$(CONFIG_TEGRA_GK20A_NVHOST) += \ diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/os_fence_android.h b/drivers/gpu/nvgpu/include/nvgpu/linux/os_fence_android.h index 3dc032923..55a7b9689 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/linux/os_fence_android.h +++ b/drivers/gpu/nvgpu/include/nvgpu/linux/os_fence_android.h @@ -29,10 +29,6 @@ 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 nvgpu_channel *c, int fd); -void nvgpu_os_fence_init(struct nvgpu_os_fence *fence_out, - struct gk20a *g, const struct nvgpu_os_fence_ops *fops, - void *fence); - int nvgpu_os_fence_android_install_fd(struct nvgpu_os_fence *s, int fd); int nvgpu_os_fence_syncpt_fdget( diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/os_fence_dma.h b/drivers/gpu/nvgpu/include/nvgpu/linux/os_fence_dma.h index 7c57486d6..87bd3b507 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/linux/os_fence_dma.h +++ b/drivers/gpu/nvgpu/include/nvgpu/linux/os_fence_dma.h @@ -29,10 +29,6 @@ void nvgpu_os_fence_dma_drop_ref(struct nvgpu_os_fence *s); int nvgpu_os_fence_sema_fdget(struct nvgpu_os_fence *fence_out, struct nvgpu_channel *c, int fd); -void nvgpu_os_fence_init(struct nvgpu_os_fence *fence_out, - struct gk20a *g, const struct nvgpu_os_fence_ops *fops, - void *fence); - int nvgpu_os_fence_dma_install_fd(struct nvgpu_os_fence *s, int fd); int nvgpu_os_fence_syncpt_fdget(struct nvgpu_os_fence *fence_out, diff --git a/drivers/gpu/nvgpu/os/linux/os_fence_android.c b/drivers/gpu/nvgpu/os/linux/os_fence_android.c index 7bbb3dd95..b8be84b38 100644 --- a/drivers/gpu/nvgpu/os/linux/os_fence_android.c +++ b/drivers/gpu/nvgpu/os/linux/os_fence_android.c @@ -20,6 +20,8 @@ #include #include +#include "os_fence_priv.h" + #include "../drivers/staging/android/sync.h" inline struct sync_fence *nvgpu_get_sync_fence(struct nvgpu_os_fence *s) @@ -28,22 +30,6 @@ inline struct sync_fence *nvgpu_get_sync_fence(struct nvgpu_os_fence *s) 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, - void *fence) -{ - fence_out->g = g; - fence_out->ops = fops; - fence_out->priv = fence; -} - void nvgpu_os_fence_android_drop_ref(struct nvgpu_os_fence *s) { struct sync_fence *fence = nvgpu_get_sync_fence(s); diff --git a/drivers/gpu/nvgpu/os/linux/os_fence_android_sema.c b/drivers/gpu/nvgpu/os/linux/os_fence_android_sema.c index dc346d0f5..7e943e733 100644 --- a/drivers/gpu/nvgpu/os/linux/os_fence_android_sema.c +++ b/drivers/gpu/nvgpu/os/linux/os_fence_android_sema.c @@ -26,6 +26,7 @@ #include #include "sync_sema_android.h" +#include "os_fence_priv.h" #include "../drivers/staging/android/sync.h" diff --git a/drivers/gpu/nvgpu/os/linux/os_fence_dma.c b/drivers/gpu/nvgpu/os/linux/os_fence_dma.c index 28c4bf450..17f9fe3d9 100644 --- a/drivers/gpu/nvgpu/os/linux/os_fence_dma.c +++ b/drivers/gpu/nvgpu/os/linux/os_fence_dma.c @@ -23,28 +23,14 @@ #include #include +#include "os_fence_priv.h" + inline struct dma_fence *nvgpu_get_dma_fence(struct nvgpu_os_fence *s) { struct dma_fence *fence = (struct dma_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, - void *fence) -{ - fence_out->g = g; - fence_out->ops = fops; - fence_out->priv = fence; -} - void nvgpu_os_fence_dma_drop_ref(struct nvgpu_os_fence *s) { struct dma_fence *fence = nvgpu_get_dma_fence(s); diff --git a/drivers/gpu/nvgpu/os/linux/os_fence_dma_sema.c b/drivers/gpu/nvgpu/os/linux/os_fence_dma_sema.c index 12e84a6ae..71c86f3c5 100644 --- a/drivers/gpu/nvgpu/os/linux/os_fence_dma_sema.c +++ b/drivers/gpu/nvgpu/os/linux/os_fence_dma_sema.c @@ -23,6 +23,7 @@ #include #include +#include "os_fence_priv.h" #include "sync_sema_dma.h" static const struct nvgpu_os_fence_ops sema_ops = { diff --git a/drivers/gpu/nvgpu/os/linux/os_fence_dma_syncpt.c b/drivers/gpu/nvgpu/os/linux/os_fence_dma_syncpt.c deleted file mode 100644 index a917428b9..000000000 --- a/drivers/gpu/nvgpu/os/linux/os_fence_dma_syncpt.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2020, 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 -#include -#include -#include -#include - -static const struct nvgpu_os_fence_ops syncpt_ops = { - .drop_ref = nvgpu_os_fence_dma_drop_ref, - .install_fence = nvgpu_os_fence_dma_install_fd, -}; - -int nvgpu_os_fence_syncpt_create(struct nvgpu_os_fence *fence_out, - struct nvgpu_channel *c, struct nvgpu_nvhost_dev *nvhost_dev, - u32 id, u32 thresh) -{ - return -ENOSYS; -} - -int nvgpu_os_fence_syncpt_fdget(struct nvgpu_os_fence *fence_out, - struct nvgpu_channel *c, int fd) -{ - return -ENOSYS; -} - -int nvgpu_os_fence_get_syncpts(struct nvgpu_os_fence_syncpt *fence_syncpt_out, - struct nvgpu_os_fence *fence_in) -{ - if (fence_in->ops != &syncpt_ops) { - return -EINVAL; - } - - fence_syncpt_out->fence = fence_in; - - return 0; -} - -u32 nvgpu_os_fence_syncpt_get_num_syncpoints( - struct nvgpu_os_fence_syncpt *fence) -{ - WARN(1, "can't get here until nvhost support exists"); - return -EINVAL; -} - -int nvgpu_os_fence_syncpt_foreach_pt( - struct nvgpu_os_fence_syncpt *fence, - int (*iter)(struct nvhost_ctrl_sync_fence_info, void *), - void *data) -{ - WARN(1, "can't get here until nvhost support exists"); - return -EINVAL; -} diff --git a/drivers/gpu/nvgpu/os/linux/os_fence_priv.h b/drivers/gpu/nvgpu/os/linux/os_fence_priv.h new file mode 100644 index 000000000..38243d688 --- /dev/null +++ b/drivers/gpu/nvgpu/os/linux/os_fence_priv.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018-2020, 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 . + */ + +#ifndef NVGPU_OS_FENCE_PRIV_H +#define NVGPU_OS_FENCE_PRIV_H + +#include + +static inline void nvgpu_os_fence_clear(struct nvgpu_os_fence *fence_out) +{ + fence_out->priv = NULL; + fence_out->g = NULL; + fence_out->ops = NULL; +} + +static inline void nvgpu_os_fence_init(struct nvgpu_os_fence *fence_out, + struct gk20a *g, const struct nvgpu_os_fence_ops *fops, + void *fence) +{ + fence_out->g = g; + fence_out->ops = fops; + fence_out->priv = fence; +} + +#endif /* NVGPU_OS_FENCE_PRIV_H */ diff --git a/drivers/gpu/nvgpu/os/linux/os_fence_android_syncpt.c b/drivers/gpu/nvgpu/os/linux/os_fence_syncpt.c similarity index 89% rename from drivers/gpu/nvgpu/os/linux/os_fence_android_syncpt.c rename to drivers/gpu/nvgpu/os/linux/os_fence_syncpt.c index 7143fa99e..2bac0b200 100644 --- a/drivers/gpu/nvgpu/os/linux/os_fence_android_syncpt.c +++ b/drivers/gpu/nvgpu/os/linux/os_fence_syncpt.c @@ -23,29 +23,30 @@ #include #include #include -#include #include #include #include #include #include +#include "os_fence_priv.h" #include "nvhost_priv.h" -static int nvgpu_os_fence_android_syncpt_install_fd(struct nvgpu_os_fence *s, +static int nvgpu_os_fence_syncpt_install_fd(struct nvgpu_os_fence *s, int fd) { return nvhost_fence_install(s->priv, fd); } -static void nvgpu_os_fence_android_syncpt_drop_ref(struct nvgpu_os_fence *s) +static void nvgpu_os_fence_syncpt_drop_ref(struct nvgpu_os_fence *s) { nvhost_fence_put(s->priv); + nvgpu_os_fence_clear(s); } static const struct nvgpu_os_fence_ops syncpt_ops = { - .drop_ref = nvgpu_os_fence_android_syncpt_drop_ref, - .install_fence = nvgpu_os_fence_android_syncpt_install_fd, + .drop_ref = nvgpu_os_fence_syncpt_drop_ref, + .install_fence = nvgpu_os_fence_syncpt_install_fd, }; int nvgpu_os_fence_syncpt_create(struct nvgpu_os_fence *fence_out,