diff --git a/drivers/gpu/nvgpu/common/linux/os_fence_android.c b/drivers/gpu/nvgpu/common/linux/os_fence_android.c index d8f706391..9be8c6c0f 100644 --- a/drivers/gpu/nvgpu/common/linux/os_fence_android.c +++ b/drivers/gpu/nvgpu/common/linux/os_fence_android.c @@ -52,6 +52,14 @@ void nvgpu_os_fence_android_drop_ref(struct nvgpu_os_fence *s) nvgpu_os_fence_clear(s); } +void nvgpu_os_fence_android_install_fd(struct nvgpu_os_fence *s, int fd) +{ + struct sync_fence *fence = nvgpu_get_sync_fence(s); + + sync_fence_get(fence); + sync_fence_install(fence, fd); +} + int nvgpu_os_fence_fdget(struct nvgpu_os_fence *fence_out, struct channel_gk20a *c, int fd) { diff --git a/drivers/gpu/nvgpu/common/linux/os_fence_android_sema.c b/drivers/gpu/nvgpu/common/linux/os_fence_android_sema.c index b61bd893c..d4aeb6ede 100644 --- a/drivers/gpu/nvgpu/common/linux/os_fence_android_sema.c +++ b/drivers/gpu/nvgpu/common/linux/os_fence_android_sema.c @@ -69,6 +69,7 @@ int nvgpu_os_fence_sema_wait_gen_cmd(struct nvgpu_os_fence *s, static const struct nvgpu_os_fence_ops sema_ops = { .program_waits = nvgpu_os_fence_sema_wait_gen_cmd, .drop_ref = nvgpu_os_fence_android_drop_ref, + .install_fence = nvgpu_os_fence_android_install_fd, }; int nvgpu_os_fence_sema_create( diff --git a/drivers/gpu/nvgpu/common/linux/os_fence_android_syncpt.c b/drivers/gpu/nvgpu/common/linux/os_fence_android_syncpt.c index 76def831b..b3712011c 100644 --- a/drivers/gpu/nvgpu/common/linux/os_fence_android_syncpt.c +++ b/drivers/gpu/nvgpu/common/linux/os_fence_android_syncpt.c @@ -88,6 +88,7 @@ int nvgpu_os_fence_syncpt_wait_gen_cmd(struct nvgpu_os_fence *s, static const struct nvgpu_os_fence_ops syncpt_ops = { .program_waits = nvgpu_os_fence_syncpt_wait_gen_cmd, .drop_ref = nvgpu_os_fence_android_drop_ref, + .install_fence = nvgpu_os_fence_android_install_fd, }; int nvgpu_os_fence_syncpt_create( diff --git a/drivers/gpu/nvgpu/gk20a/channel_sync_gk20a.c b/drivers/gpu/nvgpu/gk20a/channel_sync_gk20a.c index 168985933..a20474442 100644 --- a/drivers/gpu/nvgpu/gk20a/channel_sync_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/channel_sync_gk20a.c @@ -37,10 +37,6 @@ #include "sync_gk20a.h" #include "mm_gk20a.h" -#ifdef CONFIG_SYNC -#include "../drivers/staging/android/sync.h" -#endif - #ifdef CONFIG_TEGRA_GK20A_NVHOST struct gk20a_channel_syncpt { @@ -145,7 +141,6 @@ static int __gk20a_channel_syncpt_incr(struct gk20a_channel_sync *s, struct gk20a_channel_syncpt *sp = container_of(s, struct gk20a_channel_syncpt, ops); struct channel_gk20a *c = sp->c; - struct sync_fence *sync_fence = NULL; struct nvgpu_os_fence os_fence = {0}; err = gk20a_channel_alloc_priv_cmdbuf(c, @@ -194,12 +189,10 @@ static int __gk20a_channel_syncpt_incr(struct gk20a_channel_sync *s, if (err) goto clean_up_priv_cmd; - - sync_fence = (struct sync_fence *)os_fence.priv; } err = gk20a_fence_from_syncpt(fence, sp->nvhost_dev, - sp->id, thresh, sync_fence); + sp->id, thresh, os_fence); if (err) { if (nvgpu_os_fence_is_initialized(&os_fence)) @@ -494,7 +487,6 @@ static int __gk20a_channel_semaphore_incr( struct channel_gk20a *c = sp->c; struct nvgpu_semaphore *semaphore; int err = 0; - struct sync_fence *sync_fence = NULL; struct nvgpu_os_fence os_fence = {0}; semaphore = nvgpu_semaphore_alloc(c); @@ -521,14 +513,12 @@ static int __gk20a_channel_semaphore_incr( if (err) goto clean_up_sema; - - sync_fence = (struct sync_fence *)os_fence.priv; } err = gk20a_fence_from_semaphore(fence, semaphore, &c->semaphore_wq, - sync_fence); + os_fence); if (err) { if (nvgpu_os_fence_is_initialized(&os_fence)) diff --git a/drivers/gpu/nvgpu/gk20a/fence_gk20a.c b/drivers/gpu/nvgpu/gk20a/fence_gk20a.c index f0ad773fa..0f7f3ea17 100644 --- a/drivers/gpu/nvgpu/gk20a/fence_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/fence_gk20a.c @@ -22,25 +22,17 @@ #include "fence_gk20a.h" -#ifdef CONFIG_SYNC -#include -#include -#endif - #include #include #include #include #include +#include #include "gk20a.h" #include "channel_gk20a.h" #include "sync_gk20a.h" -#ifdef CONFIG_SYNC -#include "../drivers/staging/android/sync.h" -#endif - struct gk20a_fence_ops { int (*wait)(struct gk20a_fence *, long timeout); bool (*is_expired)(struct gk20a_fence *); @@ -53,10 +45,8 @@ static void gk20a_fence_free(struct nvgpu_ref *ref) container_of(ref, struct gk20a_fence, ref); struct gk20a *g = f->g; -#ifdef CONFIG_SYNC - if (f->os_fence) - sync_fence_put(f->os_fence); -#endif + if (nvgpu_os_fence_is_initialized(&f->os_fence)) + f->os_fence.ops->drop_ref(&f->os_fence); if (f->semaphore) nvgpu_semaphore_put(f->semaphore); @@ -91,17 +81,13 @@ inline bool gk20a_fence_is_valid(struct gk20a_fence *f) int gk20a_fence_install_fd(struct gk20a_fence *f, int fd) { -#ifdef CONFIG_SYNC - if (!f || !gk20a_fence_is_valid(f) || !f->os_fence) - return -EINVAL; + if (!f || !gk20a_fence_is_valid(f) || + !nvgpu_os_fence_is_initialized(&f->os_fence)) + return -EINVAL; - sync_fence_get(f->os_fence); - sync_fence_install(f->os_fence, fd); + f->os_fence.ops->install_fence(&f->os_fence, fd); return 0; -#else - return -ENODEV; -#endif } int gk20a_fence_wait(struct gk20a *g, struct gk20a_fence *f, @@ -191,7 +177,7 @@ struct gk20a_fence *gk20a_alloc_fence(struct channel_gk20a *c) void gk20a_init_fence(struct gk20a_fence *f, const struct gk20a_fence_ops *ops, - struct sync_fence *os_fence) + struct nvgpu_os_fence os_fence) { if (!f) return; @@ -229,7 +215,7 @@ int gk20a_fence_from_semaphore( struct gk20a_fence *fence_out, struct nvgpu_semaphore *semaphore, struct nvgpu_cond *semaphore_wq, - struct sync_fence *os_fence) + struct nvgpu_os_fence os_fence) { struct gk20a_fence *f = fence_out; @@ -290,7 +276,7 @@ static const struct gk20a_fence_ops gk20a_syncpt_fence_ops = { int gk20a_fence_from_syncpt( struct gk20a_fence *fence_out, struct nvgpu_nvhost_dev *nvhost_dev, - u32 id, u32 value, struct sync_fence *os_fence) + u32 id, u32 value, struct nvgpu_os_fence os_fence) { struct gk20a_fence *f = fence_out; @@ -312,7 +298,7 @@ int gk20a_fence_from_syncpt( int gk20a_fence_from_syncpt( struct gk20a_fence *fence_out, struct nvgpu_nvhost_dev *nvhost_dev, - u32 id, u32 value, struct sync_fence *os_fence) + u32 id, u32 value, struct nvgpu_os_fence os_fence) { return -EINVAL; } diff --git a/drivers/gpu/nvgpu/gk20a/fence_gk20a.h b/drivers/gpu/nvgpu/gk20a/fence_gk20a.h index 6a28e657e..271b2a184 100644 --- a/drivers/gpu/nvgpu/gk20a/fence_gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/fence_gk20a.h @@ -28,13 +28,13 @@ #include #include +#include struct platform_device; -struct sync_timeline; -struct sync_fence; struct nvgpu_semaphore; struct channel_gk20a; struct gk20a; +struct nvgpu_os_fence; struct gk20a_fence_ops; @@ -46,7 +46,7 @@ struct gk20a_fence { struct nvgpu_ref ref; const struct gk20a_fence_ops *ops; - struct sync_fence *os_fence; + struct nvgpu_os_fence os_fence; /* Valid for fences created from semaphores: */ struct nvgpu_semaphore *semaphore; @@ -66,13 +66,13 @@ int gk20a_fence_from_semaphore( struct gk20a_fence *fence_out, struct nvgpu_semaphore *semaphore, struct nvgpu_cond *semaphore_wq, - struct sync_fence *os_fence); + struct nvgpu_os_fence os_fence); int gk20a_fence_from_syncpt( struct gk20a_fence *fence_out, struct nvgpu_nvhost_dev *nvhost_dev, u32 id, u32 value, - struct sync_fence *os_fence); + struct nvgpu_os_fence os_fence); int gk20a_alloc_fence_pool( struct channel_gk20a *c, @@ -86,7 +86,7 @@ struct gk20a_fence *gk20a_alloc_fence( void gk20a_init_fence(struct gk20a_fence *f, const struct gk20a_fence_ops *ops, - struct sync_fence *os_fence); + struct nvgpu_os_fence os_fence); /* Fence operations */ void gk20a_fence_put(struct gk20a_fence *f); 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 39d083398..201b53069 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/linux/os_fence_android.h +++ b/drivers/gpu/nvgpu/include/nvgpu/linux/os_fence_android.h @@ -39,6 +39,8 @@ 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); +void nvgpu_os_fence_android_install_fd(struct nvgpu_os_fence *s, int fd); + int nvgpu_os_fence_syncpt_fdget( struct nvgpu_os_fence *fence_out, struct channel_gk20a *c, int fd); diff --git a/drivers/gpu/nvgpu/include/nvgpu/os_fence.h b/drivers/gpu/nvgpu/include/nvgpu/os_fence.h index a22140da1..4713ed3ef 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/os_fence.h +++ b/drivers/gpu/nvgpu/include/nvgpu/os_fence.h @@ -60,6 +60,12 @@ struct nvgpu_os_fence_ops { * for the underlying sync_fence. */ void (*drop_ref)(struct nvgpu_os_fence *s); + + /* + * Used to install the fd in the corresponding OS. The underlying + * implementation varies from OS to OS. + */ + void (*install_fence)(struct nvgpu_os_fence *s, int fd); }; /*