hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/gpu/arm/bifrost/mali_kbase_kinstr_jm.c
....@@ -1,7 +1,7 @@
11 // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
22 /*
33 *
4
- * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved.
4
+ * (C) COPYRIGHT 2019-2022 ARM Limited. All rights reserved.
55 *
66 * This program is free software and is provided to you under the terms of the
77 * GNU General Public License version 2 as published by the Free Software
....@@ -45,22 +45,25 @@
4545 #include <linux/slab.h>
4646 #include <linux/spinlock.h>
4747 #include <linux/version.h>
48
+#include <linux/version_compat_defs.h>
4849 #include <linux/wait.h>
4950
51
+/* Explicitly include epoll header for old kernels. Not required from 4.16. */
52
+#if KERNEL_VERSION(4, 16, 0) > LINUX_VERSION_CODE
53
+#include <uapi/linux/eventpoll.h>
54
+#endif
55
+
56
+/* Define static_assert().
57
+ *
58
+ * The macro was introduced in kernel 5.1. But older vendor kernels may define
59
+ * it too.
60
+ */
5061 #if KERNEL_VERSION(5, 1, 0) <= LINUX_VERSION_CODE
5162 #include <linux/build_bug.h>
52
-#else
63
+#elif !defined(static_assert)
5364 // Stringify the expression if no message is given.
5465 #define static_assert(e, ...) __static_assert(e, #__VA_ARGS__, #e)
5566 #define __static_assert(e, msg, ...) _Static_assert(e, msg)
56
-#endif
57
-
58
-#if KERNEL_VERSION(4, 16, 0) >= LINUX_VERSION_CODE
59
-typedef unsigned int __poll_t;
60
-#endif
61
-
62
-#ifndef ENOTSUP
63
-#define ENOTSUP EOPNOTSUPP
6467 #endif
6568
6669 /* The module printing prefix */
....@@ -204,9 +207,8 @@
204207 */
205208 static inline bool reader_changes_is_valid_size(const size_t size)
206209 {
207
- typedef struct reader_changes changes_t;
208
- const size_t elem_size = sizeof(*((changes_t *)0)->data);
209
- const size_t size_size = sizeof(((changes_t *)0)->size);
210
+ const size_t elem_size = sizeof(*((struct reader_changes *)0)->data);
211
+ const size_t size_size = sizeof(((struct reader_changes *)0)->size);
210212 const size_t size_max = (1ull << (size_size * 8)) - 1;
211213
212214 return is_power_of_2(size) && /* Is a power of two */
....@@ -223,11 +225,8 @@
223225 *
224226 * Return:
225227 * (0, U16_MAX] - the number of data elements allocated
226
- * -EINVAL - a pointer was invalid
227
- * -ENOTSUP - we do not support allocation of the context
228228 * -ERANGE - the requested memory size was invalid
229229 * -ENOMEM - could not allocate the memory
230
- * -EADDRINUSE - the buffer memory was already allocated
231230 */
232231 static int reader_changes_init(struct reader_changes *const changes,
233232 const size_t size)
....@@ -622,31 +621,34 @@
622621 *
623622 * Return:
624623 * * 0 - no data ready
625
- * * POLLIN - state changes have been buffered
626
- * * -EBADF - the file descriptor did not have an attached reader
627
- * * -EINVAL - the IO control arguments were invalid
624
+ * * EPOLLIN | EPOLLRDNORM - state changes have been buffered
625
+ * * EPOLLHUP | EPOLLERR - IO control arguments were invalid or the file
626
+ * descriptor did not have an attached reader.
628627 */
629628 static __poll_t reader_poll(struct file *const file,
630629 struct poll_table_struct *const wait)
631630 {
632631 struct reader *reader;
633632 struct reader_changes *changes;
633
+ __poll_t mask = 0;
634634
635635 if (unlikely(!file || !wait))
636
- return -EINVAL;
636
+ return EPOLLHUP | EPOLLERR;
637637
638638 reader = file->private_data;
639639 if (unlikely(!reader))
640
- return -EBADF;
640
+ return EPOLLHUP | EPOLLERR;
641641
642642 changes = &reader->changes;
643
-
644643 if (reader_changes_count(changes) >= changes->threshold)
645
- return POLLIN;
644
+ return EPOLLIN | EPOLLRDNORM;
646645
647646 poll_wait(file, &reader->wait_queue, wait);
648647
649
- return (reader_changes_count(changes) > 0) ? POLLIN : 0;
648
+ if (reader_changes_count(changes) > 0)
649
+ mask |= EPOLLIN | EPOLLRDNORM;
650
+
651
+ return mask;
650652 }
651653
652654 /* The file operations virtual function table */
....@@ -662,7 +664,7 @@
662664 static const size_t kbase_kinstr_jm_readers_max = 16;
663665
664666 /**
665
- * kbasep_kinstr_jm_release() - Invoked when the reference count is dropped
667
+ * kbase_kinstr_jm_release() - Invoked when the reference count is dropped
666668 * @ref: the context reference count
667669 */
668670 static void kbase_kinstr_jm_release(struct kref *const ref)
....@@ -733,7 +735,7 @@
733735 }
734736
735737 /**
736
- * readers_del() - Deletes a reader from the list of readers
738
+ * kbase_kinstr_jm_readers_del() - Deletes a reader from the list of readers
737739 * @ctx: the instrumentation context
738740 * @reader: the reader to delete
739741 */
....@@ -812,22 +814,6 @@
812814 kbase_kinstr_jm_ref_put(ctx);
813815 }
814816
815
-/**
816
- * timestamp() - Retrieves the current monotonic nanoseconds
817
- * Return: monotonic nanoseconds timestamp.
818
- */
819
-static u64 timestamp(void)
820
-{
821
- struct timespec ts;
822
- long ns;
823
-
824
- getrawmonotonic(&ts);
825
- ns = ((long)(ts.tv_sec) * NSEC_PER_SEC) + ts.tv_nsec;
826
- if (unlikely(ns < 0))
827
- return 0;
828
- return ((u64)(ns));
829
-}
830
-
831817 void kbasep_kinstr_jm_atom_state(
832818 struct kbase_jd_atom *const katom,
833819 const enum kbase_kinstr_jm_reader_atom_state state)
....@@ -836,7 +822,7 @@
836822 struct kbase_kinstr_jm *const ctx = kctx->kinstr_jm;
837823 const u8 id = kbase_jd_atom_id(kctx, katom);
838824 struct kbase_kinstr_jm_atom_state_change change = {
839
- .timestamp = timestamp(), .atom = id, .state = state
825
+ .timestamp = ktime_get_raw_ns(), .atom = id, .state = state
840826 };
841827 struct reader *reader;
842828 struct hlist_bl_node *node;