summaryrefslogtreecommitdiff
path: root/mali_kbase/mali_kbase_sync_file.c
diff options
context:
space:
mode:
authorVamsidhar reddy Gaddam <gvamsi@google.com>2023-12-20 12:42:26 +0000
committerVamsidhar reddy Gaddam <gvamsi@google.com>2024-01-05 09:19:17 +0000
commit11473542814286e59a89a70c969fb50a25ba921f (patch)
treebd4aa60e7d3dc895d82a36fcea0026569e3a04aa /mali_kbase/mali_kbase_sync_file.c
parent8768eedce66a4373c96f35c8dfb73d4668703180 (diff)
parent049a542207ed694271316782397b78b2e202086a (diff)
downloadgpu-11473542814286e59a89a70c969fb50a25ba921f.tar.gz
Merge branch 'upstream' into HEAD
Update KMD to R47P0 Bug: 315267052 Test: Outlined in go/pixel-gpu-kmd-r47p0 Change-Id: I89454c4c862033fe330b260a9bc6cc777a3ca231 Signed-off-by: Vamsidhar reddy Gaddam <gvamsi@google.com>
Diffstat (limited to 'mali_kbase/mali_kbase_sync_file.c')
-rw-r--r--mali_kbase/mali_kbase_sync_file.c148
1 files changed, 55 insertions, 93 deletions
diff --git a/mali_kbase/mali_kbase_sync_file.c b/mali_kbase/mali_kbase_sync_file.c
index d98eba9..fa1b63e 100644
--- a/mali_kbase/mali_kbase_sync_file.c
+++ b/mali_kbase/mali_kbase_sync_file.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
/*
*
- * (C) COPYRIGHT 2012-2022 ARM Limited. All rights reserved.
+ * (C) COPYRIGHT 2012-2023 ARM Limited. All rights reserved.
*
* This program is free software and is provided to you under the terms of the
* GNU General Public License version 2 as published by the Free Software
@@ -22,6 +22,9 @@
/*
* Code for supporting explicit Linux fences (CONFIG_SYNC_FILE)
*/
+#include "mali_kbase_sync.h"
+#include "mali_kbase_fence.h"
+#include "mali_kbase.h"
#include <linux/sched.h>
#include <linux/fdtable.h>
@@ -33,22 +36,16 @@
#include <linux/uaccess.h>
#include <linux/sync_file.h>
#include <linux/slab.h>
-#include "mali_kbase_fence_defs.h"
-#include "mali_kbase_sync.h"
-#include "mali_kbase_fence.h"
-#include "mali_kbase.h"
+#include <linux/version_compat_defs.h>
-static const struct file_operations stream_fops = {
- .owner = THIS_MODULE
-};
+static const struct file_operations stream_fops = { .owner = THIS_MODULE };
int kbase_sync_fence_stream_create(const char *name, int *const out_fd)
{
if (!out_fd)
return -EINVAL;
- *out_fd = anon_inode_getfd(name, &stream_fops, NULL,
- O_RDONLY | O_CLOEXEC);
+ *out_fd = anon_inode_getfd(name, &stream_fops, NULL, O_RDONLY | O_CLOEXEC);
if (*out_fd < 0)
return -EINVAL;
@@ -56,18 +53,17 @@ int kbase_sync_fence_stream_create(const char *name, int *const out_fd)
}
#if !MALI_USE_CSF
-struct sync_file *kbase_sync_fence_out_create(struct kbase_jd_atom *katom, int stream_fd)
+int kbase_sync_fence_out_create(struct kbase_jd_atom *katom, int stream_fd)
{
-#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
- struct fence *fence;
-#else
struct dma_fence *fence;
-#endif
struct sync_file *sync_file;
+ int fd;
+
+ CSTD_UNUSED(stream_fd);
fence = kbase_fence_out_new(katom);
if (!fence)
- return NULL;
+ return -ENOMEM;
#if (KERNEL_VERSION(4, 9, 67) >= LINUX_VERSION_CODE)
/* Take an extra reference to the fence on behalf of the sync_file.
@@ -85,18 +81,24 @@ struct sync_file *kbase_sync_fence_out_create(struct kbase_jd_atom *katom, int s
dma_fence_put(fence);
#endif
kbase_fence_out_remove(katom);
- return NULL;
+ return -ENOMEM;
+ }
+
+ fd = get_unused_fd_flags(O_CLOEXEC);
+ if (fd < 0) {
+ fput(sync_file->file);
+ kbase_fence_out_remove(katom);
+ return fd;
}
- return sync_file;
+
+ fd_install((unsigned int)fd, sync_file->file);
+
+ return fd;
}
int kbase_sync_fence_in_from_fd(struct kbase_jd_atom *katom, int fd)
{
-#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
- struct fence *fence = sync_file_get_fence(fd);
-#else
struct dma_fence *fence = sync_file_get_fence(fd);
-#endif
lockdep_assert_held(&katom->kctx->jctx.lock);
@@ -112,23 +114,18 @@ int kbase_sync_fence_in_from_fd(struct kbase_jd_atom *katom, int fd)
int kbase_sync_fence_validate(int fd)
{
-#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
- struct fence *fence = sync_file_get_fence(fd);
-#else
struct dma_fence *fence = sync_file_get_fence(fd);
-#endif
if (!fence)
return -EINVAL;
dma_fence_put(fence);
- return 0; /* valid */
+ return 0;
}
#if !MALI_USE_CSF
-enum base_jd_event_code
-kbase_sync_fence_out_trigger(struct kbase_jd_atom *katom, int result)
+enum base_jd_event_code kbase_sync_fence_out_trigger(struct kbase_jd_atom *katom, int result)
{
int res;
@@ -139,8 +136,7 @@ kbase_sync_fence_out_trigger(struct kbase_jd_atom *katom, int result)
res = kbase_fence_out_signal(katom, result);
if (unlikely(res < 0)) {
- dev_warn(katom->kctx->kbdev->dev,
- "fence_signal() failed with %d\n", res);
+ dev_warn(katom->kctx->kbdev->dev, "fence_signal() failed with %d\n", res);
}
kbase_sync_fence_out_remove(katom);
@@ -148,30 +144,24 @@ kbase_sync_fence_out_trigger(struct kbase_jd_atom *katom, int result)
return (result != 0) ? BASE_JD_EVENT_JOB_CANCELLED : BASE_JD_EVENT_DONE;
}
-#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
-static void kbase_fence_wait_callback(struct fence *fence,
- struct fence_cb *cb)
-#else
-static void kbase_fence_wait_callback(struct dma_fence *fence,
- struct dma_fence_cb *cb)
-#endif
+static void kbase_fence_wait_callback(struct dma_fence *fence, struct dma_fence_cb *cb)
{
- struct kbase_jd_atom *katom = container_of(cb, struct kbase_jd_atom,
- dma_fence.fence_cb);
+ struct kbase_jd_atom *katom = container_of(cb, struct kbase_jd_atom, dma_fence.fence_cb);
struct kbase_context *kctx = katom->kctx;
+ CSTD_UNUSED(fence);
+
/* Cancel atom if fence is erroneous */
if (dma_fence_is_signaled(katom->dma_fence.fence_in) &&
#if (KERNEL_VERSION(4, 11, 0) <= LINUX_VERSION_CODE || \
- (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE && \
- KERNEL_VERSION(4, 9, 68) <= LINUX_VERSION_CODE))
+ (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE && \
+ KERNEL_VERSION(4, 9, 68) <= LINUX_VERSION_CODE))
katom->dma_fence.fence_in->error < 0)
#else
katom->dma_fence.fence_in->status < 0)
#endif
katom->event_code = BASE_JD_EVENT_JOB_CANCELLED;
-
/* To prevent a potential deadlock we schedule the work onto the
* job_done_wq workqueue
*
@@ -186,11 +176,7 @@ static void kbase_fence_wait_callback(struct dma_fence *fence,
int kbase_sync_fence_in_wait(struct kbase_jd_atom *katom)
{
int err;
-#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
- struct fence *fence;
-#else
struct dma_fence *fence;
-#endif
lockdep_assert_held(&katom->kctx->jctx.lock);
@@ -198,8 +184,7 @@ int kbase_sync_fence_in_wait(struct kbase_jd_atom *katom)
if (!fence)
return 0; /* no input fence to wait for, good to go! */
- err = dma_fence_add_callback(fence, &katom->dma_fence.fence_cb,
- kbase_fence_wait_callback);
+ err = dma_fence_add_callback(fence, &katom->dma_fence.fence_cb, kbase_fence_wait_callback);
if (err == -ENOENT) {
int fence_status = dma_fence_get_status(fence);
@@ -217,8 +202,8 @@ int kbase_sync_fence_in_wait(struct kbase_jd_atom *katom)
kbase_sync_fence_in_info_get(katom, &info);
dev_warn(katom->kctx->kbdev->dev,
- "Unexpected status for fence %s of ctx:%d_%d atom:%d",
- info.name, katom->kctx->tgid, katom->kctx->id,
+ "Unexpected status for fence %s of ctx:%d_%d atom:%d", info.name,
+ katom->kctx->tgid, katom->kctx->id,
kbase_jd_atom_id(katom->kctx, katom));
}
@@ -295,10 +280,11 @@ void kbase_sync_fence_in_remove(struct kbase_jd_atom *katom)
struct kbase_sync_fence_info info;
kbase_sync_fence_in_info_get(katom, &info);
- dev_warn(katom->kctx->kbdev->dev,
- "Callback was not removed earlier for fence %s of ctx:%d_%d atom:%d",
- info.name, katom->kctx->tgid, katom->kctx->id,
- kbase_jd_atom_id(katom->kctx, katom));
+ dev_warn(
+ katom->kctx->kbdev->dev,
+ "Callback was not removed earlier for fence %s of ctx:%d_%d atom:%d",
+ info.name, katom->kctx->tgid, katom->kctx->id,
+ kbase_jd_atom_id(katom->kctx, katom));
}
}
@@ -307,14 +293,9 @@ void kbase_sync_fence_in_remove(struct kbase_jd_atom *katom)
}
#endif /* !MALI_USE_CSF */
-#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
-void kbase_sync_fence_info_get(struct fence *fence,
- struct kbase_sync_fence_info *info)
-#else
-void kbase_sync_fence_info_get(struct dma_fence *fence,
- struct kbase_sync_fence_info *info)
-#endif
+void kbase_sync_fence_info_get(struct dma_fence *fence, struct kbase_sync_fence_info *info)
{
+ int status;
info->fence = fence;
/* Translate into the following status, with support for error handling:
@@ -322,40 +303,26 @@ void kbase_sync_fence_info_get(struct dma_fence *fence,
* 0 : active
* 1 : signaled
*/
- if (dma_fence_is_signaled(fence)) {
-#if (KERNEL_VERSION(4, 11, 0) <= LINUX_VERSION_CODE || \
- (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE && \
- KERNEL_VERSION(4, 9, 68) <= LINUX_VERSION_CODE))
- int status = fence->error;
-#else
- int status = fence->status;
-#endif
- if (status < 0)
- info->status = status; /* signaled with error */
- else
- info->status = 1; /* signaled with success */
- } else {
+ status = dma_fence_get_status(fence);
+
+ if (status < 0)
+ info->status = status; /* signaled with error */
+ else if (status > 0)
+ info->status = 1; /* signaled with success */
+ else
info->status = 0; /* still active (unsignaled) */
- }
#if (KERNEL_VERSION(5, 1, 0) > LINUX_VERSION_CODE)
- scnprintf(info->name, sizeof(info->name), "%llu#%u",
- fence->context, fence->seqno);
+ scnprintf(info->name, sizeof(info->name), "%llu#%u", fence->context, fence->seqno);
#else
- scnprintf(info->name, sizeof(info->name), "%llu#%llu",
- fence->context, fence->seqno);
+ scnprintf(info->name, sizeof(info->name), "%llu#%llu", fence->context, fence->seqno);
#endif
}
#if !MALI_USE_CSF
-int kbase_sync_fence_in_info_get(struct kbase_jd_atom *katom,
- struct kbase_sync_fence_info *info)
+int kbase_sync_fence_in_info_get(struct kbase_jd_atom *katom, struct kbase_sync_fence_info *info)
{
-#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
- struct fence *fence;
-#else
struct dma_fence *fence;
-#endif
fence = kbase_fence_in_get(katom);
if (!fence)
@@ -368,14 +335,9 @@ int kbase_sync_fence_in_info_get(struct kbase_jd_atom *katom,
return 0;
}
-int kbase_sync_fence_out_info_get(struct kbase_jd_atom *katom,
- struct kbase_sync_fence_info *info)
+int kbase_sync_fence_out_info_get(struct kbase_jd_atom *katom, struct kbase_sync_fence_info *info)
{
-#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
- struct fence *fence;
-#else
struct dma_fence *fence;
-#endif
fence = kbase_fence_out_get(katom);
if (!fence)
@@ -388,11 +350,11 @@ int kbase_sync_fence_out_info_get(struct kbase_jd_atom *katom,
return 0;
}
-
#ifdef CONFIG_MALI_FENCE_DEBUG
void kbase_sync_fence_in_dump(struct kbase_jd_atom *katom)
{
/* Not implemented */
+ CSTD_UNUSED(katom);
}
#endif
#endif /* !MALI_USE_CSF*/