intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] drm/i915: clean up i915_utils.h
@ 2025-09-08 14:11 Jani Nikula
  2025-09-08 14:11 ` [PATCH 1/5] drm/i915: redundant i915_utils.h includes Jani Nikula
                   ` (5 more replies)
  0 siblings, 6 replies; 14+ messages in thread
From: Jani Nikula @ 2025-09-08 14:11 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Split out functionality from i915_utils.h to not make it such a
catch-all header that all files depend on. The end goal is to eventually
remove the dependency on i915_utils.h from display/, but make the task
easier by chopping up i915_utils.h and reducing the dependencies on it
in core i915 first.

Whenever include lists need to be touched, group and sort them in a
uniform manner instead of doing that in separate patches.

BR,
Jani.


Jani Nikula (5):
  drm/i915: redundant i915_utils.h includes
  drm/i915: split out i915_ptr_util.h
  drm/i915: split out i915_timer_util.[ch]
  drm/i915: split out i915_list_util.h
  drm/i915: split out i915_wait_util.h

 drivers/gpu/drm/i915/Makefile                 |   1 +
 drivers/gpu/drm/i915/gt/intel_context_types.h |   1 -
 .../drm/i915/gt/intel_execlists_submission.c  |   6 +-
 .../gpu/drm/i915/gt/intel_gt_buffer_pool.c    |   1 +
 drivers/gpu/drm/i915/gt/intel_gt_mcr.c        |   1 +
 drivers/gpu/drm/i915/gt/intel_reset.c         |   7 +-
 .../gpu/drm/i915/gt/intel_ring_submission.c   |   7 +-
 drivers/gpu/drm/i915/gt/intel_rps.c           |   2 +
 drivers/gpu/drm/i915/gt/intel_timeline.h      |   1 +
 drivers/gpu/drm/i915/gt/selftest_tlb.c        |   6 +-
 drivers/gpu/drm/i915/gt/sysfs_engines.c       |   1 +
 drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c  |   6 +-
 .../i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c |   2 +
 drivers/gpu/drm/i915/gt/uc/intel_guc.c        |   8 +-
 drivers/gpu/drm/i915/gt/uc/intel_guc.h        |   1 -
 drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c     |   3 +-
 drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c     |   4 +-
 drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c   |  13 +-
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c |  10 +-
 drivers/gpu/drm/i915/gvt/mmio_context.c       |   6 +-
 drivers/gpu/drm/i915/i915_debugfs.c           |   3 +-
 drivers/gpu/drm/i915/i915_gem.h               |   2 -
 drivers/gpu/drm/i915/i915_list_util.h         |  23 +++
 drivers/gpu/drm/i915/i915_ptr_util.h          |  66 ++++++
 drivers/gpu/drm/i915/i915_request.h           |   5 +-
 drivers/gpu/drm/i915/i915_timer_util.c        |  36 ++++
 drivers/gpu/drm/i915/i915_timer_util.h        |  23 +++
 drivers/gpu/drm/i915/i915_utils.c             |  30 ---
 drivers/gpu/drm/i915/i915_utils.h             | 191 ------------------
 drivers/gpu/drm/i915/i915_vma.h               |   6 +-
 drivers/gpu/drm/i915/i915_wait_util.h         | 119 +++++++++++
 drivers/gpu/drm/i915/intel_pcode.c            |   1 +
 drivers/gpu/drm/i915/intel_uncore.c           |   7 +-
 drivers/gpu/drm/i915/pxp/intel_pxp.c          |   4 +-
 drivers/gpu/drm/i915/selftests/i915_request.c |   5 +-
 .../gpu/drm/i915/selftests/i915_selftest.c    |   2 +-
 drivers/gpu/drm/i915/selftests/igt_spinner.c  |   5 +-
 drivers/gpu/drm/i915/vlv_suspend.c            |   5 +-
 38 files changed, 345 insertions(+), 275 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/i915_list_util.h
 create mode 100644 drivers/gpu/drm/i915/i915_ptr_util.h
 create mode 100644 drivers/gpu/drm/i915/i915_timer_util.c
 create mode 100644 drivers/gpu/drm/i915/i915_timer_util.h
 create mode 100644 drivers/gpu/drm/i915/i915_wait_util.h

-- 
2.47.3


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 1/5] drm/i915: redundant i915_utils.h includes
  2025-09-08 14:11 [PATCH 0/5] drm/i915: clean up i915_utils.h Jani Nikula
@ 2025-09-08 14:11 ` Jani Nikula
  2025-09-09 13:36   ` Rodrigo Vivi
  2025-09-08 14:11 ` [PATCH 2/5] drm/i915: split out i915_ptr_util.h Jani Nikula
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 14+ messages in thread
From: Jani Nikula @ 2025-09-08 14:11 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Neither intel_guc.h nor i915_gem.h need i915_utils.h anymore. Just drop
the includes.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 drivers/gpu/drm/i915/gt/uc/intel_guc.h | 1 -
 drivers/gpu/drm/i915/i915_gem.h        | 2 --
 2 files changed, 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc.h b/drivers/gpu/drm/i915/gt/uc/intel_guc.h
index 053780f562c1..ce766f558ce5 100644
--- a/drivers/gpu/drm/i915/gt/uc/intel_guc.h
+++ b/drivers/gpu/drm/i915/gt/uc/intel_guc.h
@@ -18,7 +18,6 @@
 #include "intel_guc_slpc_types.h"
 #include "intel_uc_fw.h"
 #include "intel_uncore.h"
-#include "i915_utils.h"
 #include "i915_vma.h"
 
 struct __guc_ads_blob;
diff --git a/drivers/gpu/drm/i915/i915_gem.h b/drivers/gpu/drm/i915/i915_gem.h
index 20b3cb29cfff..cd7114002944 100644
--- a/drivers/gpu/drm/i915/i915_gem.h
+++ b/drivers/gpu/drm/i915/i915_gem.h
@@ -30,8 +30,6 @@
 
 #include <drm/drm_drv.h>
 
-#include "i915_utils.h"
-
 struct drm_file;
 struct drm_i915_gem_object;
 struct drm_i915_private;
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/5] drm/i915: split out i915_ptr_util.h
  2025-09-08 14:11 [PATCH 0/5] drm/i915: clean up i915_utils.h Jani Nikula
  2025-09-08 14:11 ` [PATCH 1/5] drm/i915: redundant i915_utils.h includes Jani Nikula
@ 2025-09-08 14:11 ` Jani Nikula
  2025-09-09 13:37   ` Rodrigo Vivi
  2025-09-08 14:11 ` [PATCH 3/5] drm/i915: split out i915_timer_util.[ch] Jani Nikula
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 14+ messages in thread
From: Jani Nikula @ 2025-09-08 14:11 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Move pointer related utilities from i915_utils.h to a separate new
i915_ptr_util.h header. Clean up related includes.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 drivers/gpu/drm/i915/gt/intel_context_types.h |  1 -
 drivers/gpu/drm/i915/gt/intel_timeline.h      |  1 +
 drivers/gpu/drm/i915/i915_ptr_util.h          | 66 +++++++++++++++++++
 drivers/gpu/drm/i915/i915_request.h           |  5 +-
 drivers/gpu/drm/i915/i915_utils.h             | 57 ----------------
 drivers/gpu/drm/i915/i915_vma.h               |  6 +-
 6 files changed, 73 insertions(+), 63 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/i915_ptr_util.h

diff --git a/drivers/gpu/drm/i915/gt/intel_context_types.h b/drivers/gpu/drm/i915/gt/intel_context_types.h
index 98c7f6052069..10070ee4d74c 100644
--- a/drivers/gpu/drm/i915/gt/intel_context_types.h
+++ b/drivers/gpu/drm/i915/gt/intel_context_types.h
@@ -14,7 +14,6 @@
 
 #include "i915_active_types.h"
 #include "i915_sw_fence.h"
-#include "i915_utils.h"
 #include "intel_engine_types.h"
 #include "intel_sseu.h"
 #include "intel_wakeref.h"
diff --git a/drivers/gpu/drm/i915/gt/intel_timeline.h b/drivers/gpu/drm/i915/gt/intel_timeline.h
index 57308c4d664a..5f8c8f79714e 100644
--- a/drivers/gpu/drm/i915/gt/intel_timeline.h
+++ b/drivers/gpu/drm/i915/gt/intel_timeline.h
@@ -10,6 +10,7 @@
 
 #include "i915_active.h"
 #include "i915_syncmap.h"
+#include "i915_utils.h"
 #include "intel_timeline_types.h"
 
 struct drm_printer;
diff --git a/drivers/gpu/drm/i915/i915_ptr_util.h b/drivers/gpu/drm/i915/i915_ptr_util.h
new file mode 100644
index 000000000000..9f8931d7d99b
--- /dev/null
+++ b/drivers/gpu/drm/i915/i915_ptr_util.h
@@ -0,0 +1,66 @@
+/* SPDX-License-Identifier: MIT */
+/* Copyright © 2025 Intel Corporation */
+
+#ifndef __I915_PTR_UTIL_H__
+#define __I915_PTR_UTIL_H__
+
+#include <linux/types.h>
+
+#define ptr_mask_bits(ptr, n) ({					\
+	unsigned long __v = (unsigned long)(ptr);			\
+	(typeof(ptr))(__v & -BIT(n));					\
+})
+
+#define ptr_unmask_bits(ptr, n) ((unsigned long)(ptr) & (BIT(n) - 1))
+
+#define ptr_unpack_bits(ptr, bits, n) ({				\
+	unsigned long __v = (unsigned long)(ptr);			\
+	*(bits) = __v & (BIT(n) - 1);					\
+	(typeof(ptr))(__v & -BIT(n));					\
+})
+
+#define ptr_pack_bits(ptr, bits, n) ({					\
+	unsigned long __bits = (bits);					\
+	GEM_BUG_ON(__bits & -BIT(n));					\
+	((typeof(ptr))((unsigned long)(ptr) | __bits));			\
+})
+
+#define ptr_dec(ptr) ({							\
+	unsigned long __v = (unsigned long)(ptr);			\
+	(typeof(ptr))(__v - 1);						\
+})
+
+#define ptr_inc(ptr) ({							\
+	unsigned long __v = (unsigned long)(ptr);			\
+	(typeof(ptr))(__v + 1);						\
+})
+
+#define page_mask_bits(ptr) ptr_mask_bits(ptr, PAGE_SHIFT)
+#define page_unmask_bits(ptr) ptr_unmask_bits(ptr, PAGE_SHIFT)
+#define page_pack_bits(ptr, bits) ptr_pack_bits(ptr, bits, PAGE_SHIFT)
+#define page_unpack_bits(ptr, bits) ptr_unpack_bits(ptr, bits, PAGE_SHIFT)
+
+static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b)
+{
+	return a - b;
+}
+
+#define u64_to_ptr(T, x) ({						\
+	typecheck(u64, x);						\
+	(T *)(uintptr_t)(x);						\
+})
+
+/*
+ * container_of_user: Extract the superclass from a pointer to a member.
+ *
+ * Exactly like container_of() with the exception that it plays nicely
+ * with sparse for __user @ptr.
+ */
+#define container_of_user(ptr, type, member) ({				\
+	void __user *__mptr = (void __user *)(ptr);			\
+	BUILD_BUG_ON_MSG(!__same_type(*(ptr), typeof_member(type, member)) && \
+			 !__same_type(*(ptr), void),			\
+			 "pointer type mismatch in container_of()");	\
+	((type __user *)(__mptr - offsetof(type, member))); })
+
+#endif /* __I915_PTR_UTIL_H__ */
diff --git a/drivers/gpu/drm/i915/i915_request.h b/drivers/gpu/drm/i915/i915_request.h
index 5f7e8138ec14..b09135301f39 100644
--- a/drivers/gpu/drm/i915/i915_request.h
+++ b/drivers/gpu/drm/i915/i915_request.h
@@ -31,19 +31,20 @@
 #include <linux/llist.h>
 #include <linux/lockdep.h>
 
+#include <uapi/drm/i915_drm.h>
+
 #include "gem/i915_gem_context_types.h"
 #include "gt/intel_context_types.h"
 #include "gt/intel_engine_types.h"
 #include "gt/intel_timeline_types.h"
 
 #include "i915_gem.h"
+#include "i915_ptr_util.h"
 #include "i915_scheduler.h"
 #include "i915_selftest.h"
 #include "i915_sw_fence.h"
 #include "i915_vma_resource.h"
 
-#include <uapi/drm/i915_drm.h>
-
 struct drm_file;
 struct drm_i915_gem_object;
 struct drm_printer;
diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
index eb4d43c40009..dff02a944a57 100644
--- a/drivers/gpu/drm/i915/i915_utils.h
+++ b/drivers/gpu/drm/i915/i915_utils.h
@@ -67,64 +67,12 @@ bool i915_error_injected(void);
 		drm_err(&(i915)->drm, fmt, ##__VA_ARGS__); \
 })
 
-#define ptr_mask_bits(ptr, n) ({					\
-	unsigned long __v = (unsigned long)(ptr);			\
-	(typeof(ptr))(__v & -BIT(n));					\
-})
-
-#define ptr_unmask_bits(ptr, n) ((unsigned long)(ptr) & (BIT(n) - 1))
-
-#define ptr_unpack_bits(ptr, bits, n) ({				\
-	unsigned long __v = (unsigned long)(ptr);			\
-	*(bits) = __v & (BIT(n) - 1);					\
-	(typeof(ptr))(__v & -BIT(n));					\
-})
-
-#define ptr_pack_bits(ptr, bits, n) ({					\
-	unsigned long __bits = (bits);					\
-	GEM_BUG_ON(__bits & -BIT(n));					\
-	((typeof(ptr))((unsigned long)(ptr) | __bits));			\
-})
-
-#define ptr_dec(ptr) ({							\
-	unsigned long __v = (unsigned long)(ptr);			\
-	(typeof(ptr))(__v - 1);						\
-})
-
-#define ptr_inc(ptr) ({							\
-	unsigned long __v = (unsigned long)(ptr);			\
-	(typeof(ptr))(__v + 1);						\
-})
-
-#define page_mask_bits(ptr) ptr_mask_bits(ptr, PAGE_SHIFT)
-#define page_unmask_bits(ptr) ptr_unmask_bits(ptr, PAGE_SHIFT)
-#define page_pack_bits(ptr, bits) ptr_pack_bits(ptr, bits, PAGE_SHIFT)
-#define page_unpack_bits(ptr, bits) ptr_unpack_bits(ptr, bits, PAGE_SHIFT)
-
 #define fetch_and_zero(ptr) ({						\
 	typeof(*ptr) __T = *(ptr);					\
 	*(ptr) = (typeof(*ptr))0;					\
 	__T;								\
 })
 
-static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b)
-{
-	return a - b;
-}
-
-/*
- * container_of_user: Extract the superclass from a pointer to a member.
- *
- * Exactly like container_of() with the exception that it plays nicely
- * with sparse for __user @ptr.
- */
-#define container_of_user(ptr, type, member) ({				\
-	void __user *__mptr = (void __user *)(ptr);			\
-	BUILD_BUG_ON_MSG(!__same_type(*(ptr), typeof_member(type, member)) && \
-			 !__same_type(*(ptr), void),			\
-			 "pointer type mismatch in container_of()");	\
-	((type __user *)(__mptr - offsetof(type, member))); })
-
 /*
  * check_user_mbz: Check that a user value exists and is zero
  *
@@ -143,11 +91,6 @@ static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b)
 	get_user(mbz__, (U)) ? -EFAULT : mbz__ ? -EINVAL : 0;		\
 })
 
-#define u64_to_ptr(T, x) ({						\
-	typecheck(u64, x);						\
-	(T *)(uintptr_t)(x);						\
-})
-
 #define __mask_next_bit(mask) ({					\
 	int __idx = ffs(mask) - 1;					\
 	mask &= ~BIT(__idx);						\
diff --git a/drivers/gpu/drm/i915/i915_vma.h b/drivers/gpu/drm/i915/i915_vma.h
index 0f9eee6d18d2..8054047840aa 100644
--- a/drivers/gpu/drm/i915/i915_vma.h
+++ b/drivers/gpu/drm/i915/i915_vma.h
@@ -30,12 +30,12 @@
 
 #include <drm/drm_mm.h>
 
-#include "gt/intel_ggtt_fencing.h"
 #include "gem/i915_gem_object.h"
-
-#include "i915_gem_gtt.h"
+#include "gt/intel_ggtt_fencing.h"
 
 #include "i915_active.h"
+#include "i915_gem_gtt.h"
+#include "i915_ptr_util.h"
 #include "i915_request.h"
 #include "i915_vma_resource.h"
 #include "i915_vma_types.h"
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 3/5] drm/i915: split out i915_timer_util.[ch]
  2025-09-08 14:11 [PATCH 0/5] drm/i915: clean up i915_utils.h Jani Nikula
  2025-09-08 14:11 ` [PATCH 1/5] drm/i915: redundant i915_utils.h includes Jani Nikula
  2025-09-08 14:11 ` [PATCH 2/5] drm/i915: split out i915_ptr_util.h Jani Nikula
@ 2025-09-08 14:11 ` Jani Nikula
  2025-09-09 13:38   ` Rodrigo Vivi
  2025-09-08 14:11 ` [PATCH 4/5] drm/i915: split out i915_list_util.h Jani Nikula
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 14+ messages in thread
From: Jani Nikula @ 2025-09-08 14:11 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Move timer related utilities from i915_utils.[ch] to separate new files
i915_timer_util.[ch]. Clean up related includes.

Note: Arguably none of this should exist in i915 in the first place. At
least isolate it better.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 drivers/gpu/drm/i915/Makefile                 |  1 +
 .../drm/i915/gt/intel_execlists_submission.c  |  4 ++-
 drivers/gpu/drm/i915/gt/sysfs_engines.c       |  1 +
 drivers/gpu/drm/i915/i915_timer_util.c        | 36 +++++++++++++++++++
 drivers/gpu/drm/i915/i915_timer_util.h        | 23 ++++++++++++
 drivers/gpu/drm/i915/i915_utils.c             | 30 ----------------
 drivers/gpu/drm/i915/i915_utils.h             | 14 --------
 7 files changed, 64 insertions(+), 45 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/i915_timer_util.c
 create mode 100644 drivers/gpu/drm/i915/i915_timer_util.h

diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
index db150a0c33ce..e58c0c158b3a 100644
--- a/drivers/gpu/drm/i915/Makefile
+++ b/drivers/gpu/drm/i915/Makefile
@@ -32,6 +32,7 @@ i915-y += \
 	i915_scatterlist.o \
 	i915_switcheroo.o \
 	i915_sysfs.o \
+	i915_timer_util.o \
 	i915_utils.o \
 	intel_clock_gating.o \
 	intel_cpu_info.o \
diff --git a/drivers/gpu/drm/i915/gt/intel_execlists_submission.c b/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
index 03baa7fa0a27..52c8fddedfce 100644
--- a/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
+++ b/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
@@ -106,14 +106,16 @@
  * preemption, but just sampling the new tail pointer).
  *
  */
+
 #include <linux/interrupt.h>
 #include <linux/string_helpers.h>
 
+#include "gen8_engine_cs.h"
 #include "i915_drv.h"
 #include "i915_reg.h"
+#include "i915_timer_util.h"
 #include "i915_trace.h"
 #include "i915_vgpu.h"
-#include "gen8_engine_cs.h"
 #include "intel_breadcrumbs.h"
 #include "intel_context.h"
 #include "intel_engine_heartbeat.h"
diff --git a/drivers/gpu/drm/i915/gt/sysfs_engines.c b/drivers/gpu/drm/i915/gt/sysfs_engines.c
index aab2759067d2..4a81bc396b21 100644
--- a/drivers/gpu/drm/i915/gt/sysfs_engines.c
+++ b/drivers/gpu/drm/i915/gt/sysfs_engines.c
@@ -7,6 +7,7 @@
 #include <linux/sysfs.h>
 
 #include "i915_drv.h"
+#include "i915_timer_util.h"
 #include "intel_engine.h"
 #include "intel_engine_heartbeat.h"
 #include "sysfs_engines.h"
diff --git a/drivers/gpu/drm/i915/i915_timer_util.c b/drivers/gpu/drm/i915/i915_timer_util.c
new file mode 100644
index 000000000000..ee4cfd8b3c07
--- /dev/null
+++ b/drivers/gpu/drm/i915/i915_timer_util.c
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: MIT
+/* Copyright © 2025 Intel Corporation */
+
+#include <linux/jiffies.h>
+
+#include "i915_timer_util.h"
+
+void cancel_timer(struct timer_list *t)
+{
+	if (!timer_active(t))
+		return;
+
+	timer_delete(t);
+	WRITE_ONCE(t->expires, 0);
+}
+
+void set_timer_ms(struct timer_list *t, unsigned long timeout)
+{
+	if (!timeout) {
+		cancel_timer(t);
+		return;
+	}
+
+	timeout = msecs_to_jiffies(timeout);
+
+	/*
+	 * Paranoia to make sure the compiler computes the timeout before
+	 * loading 'jiffies' as jiffies is volatile and may be updated in
+	 * the background by a timer tick. All to reduce the complexity
+	 * of the addition and reduce the risk of losing a jiffy.
+	 */
+	barrier();
+
+	/* Keep t->expires = 0 reserved to indicate a canceled timer. */
+	mod_timer(t, jiffies + timeout ?: 1);
+}
diff --git a/drivers/gpu/drm/i915/i915_timer_util.h b/drivers/gpu/drm/i915/i915_timer_util.h
new file mode 100644
index 000000000000..f35ad730820c
--- /dev/null
+++ b/drivers/gpu/drm/i915/i915_timer_util.h
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: MIT */
+/* Copyright © 2025 Intel Corporation */
+
+#ifndef __I915_TIMER_UTIL_H__
+#define __I915_TIMER_UTIL_H__
+
+#include <linux/timer.h>
+#include <asm/rwonce.h>
+
+void cancel_timer(struct timer_list *t);
+void set_timer_ms(struct timer_list *t, unsigned long timeout);
+
+static inline bool timer_active(const struct timer_list *t)
+{
+	return READ_ONCE(t->expires);
+}
+
+static inline bool timer_expired(const struct timer_list *t)
+{
+	return timer_active(t) && !timer_pending(t);
+}
+
+#endif /* __I915_TIMER_UTIL_H__ */
diff --git a/drivers/gpu/drm/i915/i915_utils.c b/drivers/gpu/drm/i915/i915_utils.c
index b60c28fbd207..49f7ed413132 100644
--- a/drivers/gpu/drm/i915/i915_utils.c
+++ b/drivers/gpu/drm/i915/i915_utils.c
@@ -47,36 +47,6 @@ bool i915_error_injected(void)
 
 #endif
 
-void cancel_timer(struct timer_list *t)
-{
-	if (!timer_active(t))
-		return;
-
-	timer_delete(t);
-	WRITE_ONCE(t->expires, 0);
-}
-
-void set_timer_ms(struct timer_list *t, unsigned long timeout)
-{
-	if (!timeout) {
-		cancel_timer(t);
-		return;
-	}
-
-	timeout = msecs_to_jiffies(timeout);
-
-	/*
-	 * Paranoia to make sure the compiler computes the timeout before
-	 * loading 'jiffies' as jiffies is volatile and may be updated in
-	 * the background by a timer tick. All to reduce the complexity
-	 * of the addition and reduce the risk of losing a jiffy.
-	 */
-	barrier();
-
-	/* Keep t->expires = 0 reserved to indicate a canceled timer. */
-	mod_timer(t, jiffies + timeout ?: 1);
-}
-
 bool i915_vtd_active(struct drm_i915_private *i915)
 {
 	if (device_iommu_mapped(i915->drm.dev))
diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
index dff02a944a57..6278a74d08c2 100644
--- a/drivers/gpu/drm/i915/i915_utils.h
+++ b/drivers/gpu/drm/i915/i915_utils.h
@@ -38,7 +38,6 @@
 #endif
 
 struct drm_i915_private;
-struct timer_list;
 
 #define MISSING_CASE(x) WARN(1, "Missing case (%s == %ld)\n", \
 			     __stringify(x), (long)(x))
@@ -270,19 +269,6 @@ static inline void __add_taint_for_CI(unsigned int taint)
 	add_taint(taint, LOCKDEP_STILL_OK);
 }
 
-void cancel_timer(struct timer_list *t);
-void set_timer_ms(struct timer_list *t, unsigned long timeout);
-
-static inline bool timer_active(const struct timer_list *t)
-{
-	return READ_ONCE(t->expires);
-}
-
-static inline bool timer_expired(const struct timer_list *t)
-{
-	return timer_active(t) && !timer_pending(t);
-}
-
 static inline bool i915_run_as_guest(void)
 {
 #if IS_ENABLED(CONFIG_X86)
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 4/5] drm/i915: split out i915_list_util.h
  2025-09-08 14:11 [PATCH 0/5] drm/i915: clean up i915_utils.h Jani Nikula
                   ` (2 preceding siblings ...)
  2025-09-08 14:11 ` [PATCH 3/5] drm/i915: split out i915_timer_util.[ch] Jani Nikula
@ 2025-09-08 14:11 ` Jani Nikula
  2025-09-09 13:39   ` Rodrigo Vivi
  2025-09-08 14:11 ` [PATCH 5/5] drm/i915: split out i915_wait_util.h Jani Nikula
  2025-09-08 19:07 ` ✗ Fi.CI.BUILD: failure for drm/i915: clean up i915_utils.h Patchwork
  5 siblings, 1 reply; 14+ messages in thread
From: Jani Nikula @ 2025-09-08 14:11 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Move list related utilities from i915_utils.h to separate new file
i915_list_util.h. Clean up related includes.

Note: Arguably none of this should exist in i915 in the first place. At
least isolate it better.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 .../drm/i915/gt/intel_execlists_submission.c  |  1 +
 .../gpu/drm/i915/gt/intel_gt_buffer_pool.c    |  1 +
 drivers/gpu/drm/i915/gt/intel_timeline.h      |  2 +-
 drivers/gpu/drm/i915/i915_list_util.h         | 23 +++++++++++++++++++
 drivers/gpu/drm/i915/i915_utils.h             | 14 -----------
 5 files changed, 26 insertions(+), 15 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/i915_list_util.h

diff --git a/drivers/gpu/drm/i915/gt/intel_execlists_submission.c b/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
index 52c8fddedfce..0c1b2df02d26 100644
--- a/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
+++ b/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
@@ -112,6 +112,7 @@
 
 #include "gen8_engine_cs.h"
 #include "i915_drv.h"
+#include "i915_list_util.h"
 #include "i915_reg.h"
 #include "i915_timer_util.h"
 #include "i915_trace.h"
diff --git a/drivers/gpu/drm/i915/gt/intel_gt_buffer_pool.c b/drivers/gpu/drm/i915/gt/intel_gt_buffer_pool.c
index 86b5a9ba323d..c7befc5c20d0 100644
--- a/drivers/gpu/drm/i915/gt/intel_gt_buffer_pool.c
+++ b/drivers/gpu/drm/i915/gt/intel_gt_buffer_pool.c
@@ -7,6 +7,7 @@
 #include "gem/i915_gem_object.h"
 
 #include "i915_drv.h"
+#include "i915_list_util.h"
 #include "intel_engine_pm.h"
 #include "intel_gt_buffer_pool.h"
 
diff --git a/drivers/gpu/drm/i915/gt/intel_timeline.h b/drivers/gpu/drm/i915/gt/intel_timeline.h
index 5f8c8f79714e..85b43f9b9d95 100644
--- a/drivers/gpu/drm/i915/gt/intel_timeline.h
+++ b/drivers/gpu/drm/i915/gt/intel_timeline.h
@@ -9,8 +9,8 @@
 #include <linux/lockdep.h>
 
 #include "i915_active.h"
+#include "i915_list_util.h"
 #include "i915_syncmap.h"
-#include "i915_utils.h"
 #include "intel_timeline_types.h"
 
 struct drm_printer;
diff --git a/drivers/gpu/drm/i915/i915_list_util.h b/drivers/gpu/drm/i915/i915_list_util.h
new file mode 100644
index 000000000000..4e515dc8a3e0
--- /dev/null
+++ b/drivers/gpu/drm/i915/i915_list_util.h
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: MIT */
+/* Copyright © 2025 Intel Corporation */
+
+#ifndef __I915_LIST_UTIL_H__
+#define __I915_LIST_UTIL_H__
+
+#include <linux/list.h>
+#include <asm/rwonce.h>
+
+static inline void __list_del_many(struct list_head *head,
+				   struct list_head *first)
+{
+	first->prev = head;
+	WRITE_ONCE(head->next, first);
+}
+
+static inline int list_is_last_rcu(const struct list_head *list,
+				   const struct list_head *head)
+{
+	return READ_ONCE(list->next) == head;
+}
+
+#endif /* __I915_LIST_UTIL_H__ */
diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
index 6278a74d08c2..4a6437d6e00e 100644
--- a/drivers/gpu/drm/i915/i915_utils.h
+++ b/drivers/gpu/drm/i915/i915_utils.h
@@ -25,7 +25,6 @@
 #ifndef __I915_UTILS_H
 #define __I915_UTILS_H
 
-#include <linux/list.h>
 #include <linux/overflow.h>
 #include <linux/sched.h>
 #include <linux/string_helpers.h>
@@ -101,19 +100,6 @@ static inline bool is_power_of_2_u64(u64 n)
 	return (n != 0 && ((n & (n - 1)) == 0));
 }
 
-static inline void __list_del_many(struct list_head *head,
-				   struct list_head *first)
-{
-	first->prev = head;
-	WRITE_ONCE(head->next, first);
-}
-
-static inline int list_is_last_rcu(const struct list_head *list,
-				   const struct list_head *head)
-{
-	return READ_ONCE(list->next) == head;
-}
-
 static inline unsigned long msecs_to_jiffies_timeout(const unsigned int m)
 {
 	unsigned long j = msecs_to_jiffies(m);
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 5/5] drm/i915: split out i915_wait_util.h
  2025-09-08 14:11 [PATCH 0/5] drm/i915: clean up i915_utils.h Jani Nikula
                   ` (3 preceding siblings ...)
  2025-09-08 14:11 ` [PATCH 4/5] drm/i915: split out i915_list_util.h Jani Nikula
@ 2025-09-08 14:11 ` Jani Nikula
  2025-09-09 13:40   ` Rodrigo Vivi
  2025-09-08 19:07 ` ✗ Fi.CI.BUILD: failure for drm/i915: clean up i915_utils.h Patchwork
  5 siblings, 1 reply; 14+ messages in thread
From: Jani Nikula @ 2025-09-08 14:11 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Move waiting related utilities from i915_utils.h to separate new file
i915_wait_util.h. Clean up related includes.

Note: Many of the various wait macro usages could likely be refactored
to use poll_timeout_us().

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 .../drm/i915/gt/intel_execlists_submission.c  |   1 +
 drivers/gpu/drm/i915/gt/intel_gt_mcr.c        |   1 +
 drivers/gpu/drm/i915/gt/intel_reset.c         |   7 +-
 .../gpu/drm/i915/gt/intel_ring_submission.c   |   7 +-
 drivers/gpu/drm/i915/gt/intel_rps.c           |   2 +
 drivers/gpu/drm/i915/gt/selftest_tlb.c        |   6 +-
 drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c  |   6 +-
 .../i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c |   2 +
 drivers/gpu/drm/i915/gt/uc/intel_guc.c        |   8 +-
 drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c     |   3 +-
 drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c     |   4 +-
 drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c   |  13 +-
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c |  10 +-
 drivers/gpu/drm/i915/gvt/mmio_context.c       |   6 +-
 drivers/gpu/drm/i915/i915_debugfs.c           |   3 +-
 drivers/gpu/drm/i915/i915_utils.h             | 106 ----------------
 drivers/gpu/drm/i915/i915_wait_util.h         | 119 ++++++++++++++++++
 drivers/gpu/drm/i915/intel_pcode.c            |   1 +
 drivers/gpu/drm/i915/intel_uncore.c           |   7 +-
 drivers/gpu/drm/i915/pxp/intel_pxp.c          |   4 +-
 drivers/gpu/drm/i915/selftests/i915_request.c |   5 +-
 .../gpu/drm/i915/selftests/i915_selftest.c    |   2 +-
 drivers/gpu/drm/i915/selftests/igt_spinner.c  |   5 +-
 drivers/gpu/drm/i915/vlv_suspend.c            |   5 +-
 24 files changed, 183 insertions(+), 150 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/i915_wait_util.h

diff --git a/drivers/gpu/drm/i915/gt/intel_execlists_submission.c b/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
index 0c1b2df02d26..7f389cb0bde4 100644
--- a/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
+++ b/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
@@ -117,6 +117,7 @@
 #include "i915_timer_util.h"
 #include "i915_trace.h"
 #include "i915_vgpu.h"
+#include "i915_wait_util.h"
 #include "intel_breadcrumbs.h"
 #include "intel_context.h"
 #include "intel_engine_heartbeat.h"
diff --git a/drivers/gpu/drm/i915/gt/intel_gt_mcr.c b/drivers/gpu/drm/i915/gt/intel_gt_mcr.c
index a60822e2b5d4..c3afa321fe30 100644
--- a/drivers/gpu/drm/i915/gt/intel_gt_mcr.c
+++ b/drivers/gpu/drm/i915/gt/intel_gt_mcr.c
@@ -4,6 +4,7 @@
  */
 
 #include "i915_drv.h"
+#include "i915_wait_util.h"
 #include "intel_gt.h"
 #include "intel_gt_mcr.h"
 #include "intel_gt_print.h"
diff --git a/drivers/gpu/drm/i915/gt/intel_reset.c b/drivers/gpu/drm/i915/gt/intel_reset.c
index 4a1675dea1c7..41b5036dc538 100644
--- a/drivers/gpu/drm/i915/gt/intel_reset.c
+++ b/drivers/gpu/drm/i915/gt/intel_reset.c
@@ -9,18 +9,17 @@
 
 #include "display/intel_display_reset.h"
 #include "display/intel_overlay.h"
-
 #include "gem/i915_gem_context.h"
-
 #include "gt/intel_gt_regs.h"
-
 #include "gt/uc/intel_gsc_fw.h"
+#include "uc/intel_guc.h"
 
 #include "i915_drv.h"
 #include "i915_file_private.h"
 #include "i915_gpu_error.h"
 #include "i915_irq.h"
 #include "i915_reg.h"
+#include "i915_wait_util.h"
 #include "intel_breadcrumbs.h"
 #include "intel_engine_pm.h"
 #include "intel_engine_regs.h"
@@ -32,8 +31,6 @@
 #include "intel_pci_config.h"
 #include "intel_reset.h"
 
-#include "uc/intel_guc.h"
-
 #define RESET_MAX_RETRIES 3
 
 static void client_mark_guilty(struct i915_gem_context *ctx, bool banned)
diff --git a/drivers/gpu/drm/i915/gt/intel_ring_submission.c b/drivers/gpu/drm/i915/gt/intel_ring_submission.c
index 2a6d79abf25b..8314a4b0505e 100644
--- a/drivers/gpu/drm/i915/gt/intel_ring_submission.c
+++ b/drivers/gpu/drm/i915/gt/intel_ring_submission.c
@@ -15,18 +15,19 @@
 #include "i915_irq.h"
 #include "i915_mitigations.h"
 #include "i915_reg.h"
+#include "i915_wait_util.h"
 #include "intel_breadcrumbs.h"
 #include "intel_context.h"
+#include "intel_engine_heartbeat.h"
+#include "intel_engine_pm.h"
 #include "intel_engine_regs.h"
 #include "intel_gt.h"
 #include "intel_gt_irq.h"
+#include "intel_gt_print.h"
 #include "intel_gt_regs.h"
 #include "intel_reset.h"
 #include "intel_ring.h"
 #include "shmem_utils.h"
-#include "intel_engine_heartbeat.h"
-#include "intel_engine_pm.h"
-#include "intel_gt_print.h"
 
 /* Rough estimate of the typical request size, performing a flush,
  * set-context and then emitting the batch.
diff --git a/drivers/gpu/drm/i915/gt/intel_rps.c b/drivers/gpu/drm/i915/gt/intel_rps.c
index 006042e0b229..4da94098bd3e 100644
--- a/drivers/gpu/drm/i915/gt/intel_rps.c
+++ b/drivers/gpu/drm/i915/gt/intel_rps.c
@@ -10,9 +10,11 @@
 #include "display/intel_display.h"
 #include "display/intel_display_rps.h"
 #include "soc/intel_dram.h"
+
 #include "i915_drv.h"
 #include "i915_irq.h"
 #include "i915_reg.h"
+#include "i915_wait_util.h"
 #include "intel_breadcrumbs.h"
 #include "intel_gt.h"
 #include "intel_gt_clock_utils.h"
diff --git a/drivers/gpu/drm/i915/gt/selftest_tlb.c b/drivers/gpu/drm/i915/gt/selftest_tlb.c
index 69ed946a39e5..a5184f09d1de 100644
--- a/drivers/gpu/drm/i915/gt/selftest_tlb.c
+++ b/drivers/gpu/drm/i915/gt/selftest_tlb.c
@@ -3,17 +3,17 @@
  * Copyright © 2022 Intel Corporation
  */
 
-#include "i915_selftest.h"
-
 #include "gem/i915_gem_internal.h"
 #include "gem/i915_gem_lmem.h"
 #include "gem/i915_gem_region.h"
 
 #include "gen8_engine_cs.h"
 #include "i915_gem_ww.h"
+#include "i915_selftest.h"
+#include "i915_wait_util.h"
+#include "intel_context.h"
 #include "intel_engine_regs.h"
 #include "intel_gpu_commands.h"
-#include "intel_context.h"
 #include "intel_gt.h"
 #include "intel_ring.h"
 
diff --git a/drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c b/drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c
index d8edd7c054c8..e7444ebc373e 100644
--- a/drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c
+++ b/drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c
@@ -10,11 +10,13 @@
 
 #include "gt/intel_gt.h"
 #include "gt/intel_gt_print.h"
+
+#include "i915_drv.h"
+#include "i915_reg.h"
+#include "i915_wait_util.h"
 #include "intel_gsc_proxy.h"
 #include "intel_gsc_uc.h"
 #include "intel_gsc_uc_heci_cmd_submit.h"
-#include "i915_drv.h"
-#include "i915_reg.h"
 
 /*
  * GSC proxy:
diff --git a/drivers/gpu/drm/i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c b/drivers/gpu/drm/i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c
index 2fde5c360cff..9bd29be7656f 100644
--- a/drivers/gpu/drm/i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c
+++ b/drivers/gpu/drm/i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c
@@ -8,6 +8,8 @@
 #include "gt/intel_gpu_commands.h"
 #include "gt/intel_gt.h"
 #include "gt/intel_ring.h"
+
+#include "i915_wait_util.h"
 #include "intel_gsc_uc_heci_cmd_submit.h"
 
 struct gsc_heci_pkt {
diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc.c b/drivers/gpu/drm/i915/gt/uc/intel_guc.c
index f360f020d8f1..52ec4421a211 100644
--- a/drivers/gpu/drm/i915/gt/uc/intel_guc.c
+++ b/drivers/gpu/drm/i915/gt/uc/intel_guc.c
@@ -8,15 +8,17 @@
 #include "gt/intel_gt_irq.h"
 #include "gt/intel_gt_pm_irq.h"
 #include "gt/intel_gt_regs.h"
+
+#include "i915_drv.h"
+#include "i915_irq.h"
+#include "i915_reg.h"
+#include "i915_wait_util.h"
 #include "intel_guc.h"
 #include "intel_guc_ads.h"
 #include "intel_guc_capture.h"
 #include "intel_guc_print.h"
 #include "intel_guc_slpc.h"
 #include "intel_guc_submission.h"
-#include "i915_drv.h"
-#include "i915_irq.h"
-#include "i915_reg.h"
 
 /**
  * DOC: GuC
diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c
index 380a11c92d63..3e7e5badcc2b 100644
--- a/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c
+++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c
@@ -5,11 +5,12 @@
 
 #include <linux/circ_buf.h>
 #include <linux/ktime.h>
-#include <linux/time64.h>
 #include <linux/string_helpers.h>
+#include <linux/time64.h>
 #include <linux/timekeeping.h>
 
 #include "i915_drv.h"
+#include "i915_wait_util.h"
 #include "intel_guc_ct.h"
 #include "intel_guc_print.h"
 
diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c
index e7ccfa520df3..1bb1491f90fc 100644
--- a/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c
+++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c
@@ -13,9 +13,11 @@
 #include "gt/intel_gt_mcr.h"
 #include "gt/intel_gt_regs.h"
 #include "gt/intel_rps.h"
+
+#include "i915_drv.h"
+#include "i915_wait_util.h"
 #include "intel_guc_fw.h"
 #include "intel_guc_print.h"
-#include "i915_drv.h"
 
 static void guc_prepare_xfer(struct intel_gt *gt)
 {
diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c
index d5ee6e5e1443..fa9af08f9708 100644
--- a/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c
+++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c
@@ -3,17 +3,20 @@
  * Copyright © 2021 Intel Corporation
  */
 
-#include <drm/drm_cache.h>
 #include <linux/string_helpers.h>
 
+#include <drm/drm_cache.h>
+
+#include "gt/intel_gt.h"
+#include "gt/intel_gt_regs.h"
+#include "gt/intel_rps.h"
+
 #include "i915_drv.h"
 #include "i915_reg.h"
-#include "intel_guc_slpc.h"
+#include "i915_wait_util.h"
 #include "intel_guc_print.h"
+#include "intel_guc_slpc.h"
 #include "intel_mchbar_regs.h"
-#include "gt/intel_gt.h"
-#include "gt/intel_gt_regs.h"
-#include "gt/intel_rps.h"
 
 /**
  * DOC: SLPC - Dynamic Frequency management
diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
index 127316d2c8aa..68f2b8d363ac 100644
--- a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
+++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
@@ -25,16 +25,16 @@
 #include "gt/intel_mocs.h"
 #include "gt/intel_ring.h"
 
+#include "i915_drv.h"
+#include "i915_irq.h"
+#include "i915_reg.h"
+#include "i915_trace.h"
+#include "i915_wait_util.h"
 #include "intel_guc_ads.h"
 #include "intel_guc_capture.h"
 #include "intel_guc_print.h"
 #include "intel_guc_submission.h"
 
-#include "i915_drv.h"
-#include "i915_reg.h"
-#include "i915_irq.h"
-#include "i915_trace.h"
-
 /**
  * DOC: GuC-based command submission
  *
diff --git a/drivers/gpu/drm/i915/gvt/mmio_context.c b/drivers/gpu/drm/i915/gvt/mmio_context.c
index 2f7208843367..0b810baad20a 100644
--- a/drivers/gpu/drm/i915/gvt/mmio_context.c
+++ b/drivers/gpu/drm/i915/gvt/mmio_context.c
@@ -33,14 +33,16 @@
  *
  */
 
-#include "i915_drv.h"
-#include "i915_reg.h"
 #include "gt/intel_context.h"
 #include "gt/intel_engine_regs.h"
 #include "gt/intel_gpu_commands.h"
 #include "gt/intel_gt_regs.h"
 #include "gt/intel_ring.h"
+
 #include "gvt.h"
+#include "i915_drv.h"
+#include "i915_reg.h"
+#include "i915_wait_util.h"
 #include "trace.h"
 
 #define GEN9_MOCS_SIZE		64
diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 23fa098c4479..c2e38d4bcd01 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -26,11 +26,11 @@
  *
  */
 
+#include <linux/debugfs.h>
 #include <linux/sched/mm.h>
 #include <linux/sort.h>
 #include <linux/string_helpers.h>
 
-#include <linux/debugfs.h>
 #include <drm/drm_debugfs.h>
 
 #include "gem/i915_gem_context.h"
@@ -54,6 +54,7 @@
 #include "i915_irq.h"
 #include "i915_reg.h"
 #include "i915_scheduler.h"
+#include "i915_wait_util.h"
 #include "intel_mchbar_regs.h"
 
 static inline struct drm_i915_private *node_to_i915(struct drm_info_node *node)
diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
index 4a6437d6e00e..a0c892e4c40d 100644
--- a/drivers/gpu/drm/i915/i915_utils.h
+++ b/drivers/gpu/drm/i915/i915_utils.h
@@ -134,112 +134,6 @@ wait_remaining_ms_from_jiffies(unsigned long timestamp_jiffies, int to_wait_ms)
 	}
 }
 
-/*
- * __wait_for - magic wait macro
- *
- * Macro to help avoid open coding check/wait/timeout patterns. Note that it's
- * important that we check the condition again after having timed out, since the
- * timeout could be due to preemption or similar and we've never had a chance to
- * check the condition before the timeout.
- */
-#define __wait_for(OP, COND, US, Wmin, Wmax) ({ \
-	const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \
-	long wait__ = (Wmin); /* recommended min for usleep is 10 us */	\
-	int ret__;							\
-	might_sleep();							\
-	for (;;) {							\
-		const bool expired__ = ktime_after(ktime_get_raw(), end__); \
-		OP;							\
-		/* Guarantee COND check prior to timeout */		\
-		barrier();						\
-		if (COND) {						\
-			ret__ = 0;					\
-			break;						\
-		}							\
-		if (expired__) {					\
-			ret__ = -ETIMEDOUT;				\
-			break;						\
-		}							\
-		usleep_range(wait__, wait__ * 2);			\
-		if (wait__ < (Wmax))					\
-			wait__ <<= 1;					\
-	}								\
-	ret__;								\
-})
-
-#define _wait_for(COND, US, Wmin, Wmax)	__wait_for(, (COND), (US), (Wmin), \
-						   (Wmax))
-#define wait_for(COND, MS)		_wait_for((COND), (MS) * 1000, 10, 1000)
-
-/*
- * If CONFIG_PREEMPT_COUNT is disabled, in_atomic() always reports false.
- * On PREEMPT_RT the context isn't becoming atomic because it is used in an
- * interrupt handler or because a spinlock_t is acquired. This leads to
- * warnings which don't occur otherwise and therefore the check is disabled.
- */
-#if IS_ENABLED(CONFIG_DRM_I915_DEBUG) && IS_ENABLED(CONFIG_PREEMPT_COUNT) && !defined(CONFIG_PREEMPT_RT)
-# define _WAIT_FOR_ATOMIC_CHECK(ATOMIC) WARN_ON_ONCE((ATOMIC) && !in_atomic())
-#else
-# define _WAIT_FOR_ATOMIC_CHECK(ATOMIC) do { } while (0)
-#endif
-
-#define _wait_for_atomic(COND, US, ATOMIC) \
-({ \
-	int cpu, ret, timeout = (US) * 1000; \
-	u64 base; \
-	_WAIT_FOR_ATOMIC_CHECK(ATOMIC); \
-	if (!(ATOMIC)) { \
-		preempt_disable(); \
-		cpu = smp_processor_id(); \
-	} \
-	base = local_clock(); \
-	for (;;) { \
-		u64 now = local_clock(); \
-		if (!(ATOMIC)) \
-			preempt_enable(); \
-		/* Guarantee COND check prior to timeout */ \
-		barrier(); \
-		if (COND) { \
-			ret = 0; \
-			break; \
-		} \
-		if (now - base >= timeout) { \
-			ret = -ETIMEDOUT; \
-			break; \
-		} \
-		cpu_relax(); \
-		if (!(ATOMIC)) { \
-			preempt_disable(); \
-			if (unlikely(cpu != smp_processor_id())) { \
-				timeout -= now - base; \
-				cpu = smp_processor_id(); \
-				base = local_clock(); \
-			} \
-		} \
-	} \
-	ret; \
-})
-
-#define wait_for_us(COND, US) \
-({ \
-	int ret__; \
-	BUILD_BUG_ON(!__builtin_constant_p(US)); \
-	if ((US) > 10) \
-		ret__ = _wait_for((COND), (US), 10, 10); \
-	else \
-		ret__ = _wait_for_atomic((COND), (US), 0); \
-	ret__; \
-})
-
-#define wait_for_atomic_us(COND, US) \
-({ \
-	BUILD_BUG_ON(!__builtin_constant_p(US)); \
-	BUILD_BUG_ON((US) > 50000); \
-	_wait_for_atomic((COND), (US), 1); \
-})
-
-#define wait_for_atomic(COND, MS) wait_for_atomic_us((COND), (MS) * 1000)
-
 #define KHz(x) (1000 * (x))
 #define MHz(x) KHz(1000 * (x))
 
diff --git a/drivers/gpu/drm/i915/i915_wait_util.h b/drivers/gpu/drm/i915/i915_wait_util.h
new file mode 100644
index 000000000000..7376898e3bf8
--- /dev/null
+++ b/drivers/gpu/drm/i915/i915_wait_util.h
@@ -0,0 +1,119 @@
+/* SPDX-License-Identifier: MIT */
+/* Copyright © 2025 Intel Corporation */
+
+#ifndef __I915_WAIT_UTIL_H__
+#define __I915_WAIT_UTIL_H__
+
+#include <linux/compiler.h>
+#include <linux/delay.h>
+#include <linux/ktime.h>
+#include <linux/sched/clock.h>
+#include <linux/smp.h>
+
+/*
+ * __wait_for - magic wait macro
+ *
+ * Macro to help avoid open coding check/wait/timeout patterns. Note that it's
+ * important that we check the condition again after having timed out, since the
+ * timeout could be due to preemption or similar and we've never had a chance to
+ * check the condition before the timeout.
+ */
+#define __wait_for(OP, COND, US, Wmin, Wmax) ({ \
+	const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \
+	long wait__ = (Wmin); /* recommended min for usleep is 10 us */	\
+	int ret__;							\
+	might_sleep();							\
+	for (;;) {							\
+		const bool expired__ = ktime_after(ktime_get_raw(), end__); \
+		OP;							\
+		/* Guarantee COND check prior to timeout */		\
+		barrier();						\
+		if (COND) {						\
+			ret__ = 0;					\
+			break;						\
+		}							\
+		if (expired__) {					\
+			ret__ = -ETIMEDOUT;				\
+			break;						\
+		}							\
+		usleep_range(wait__, wait__ * 2);			\
+		if (wait__ < (Wmax))					\
+			wait__ <<= 1;					\
+	}								\
+	ret__;								\
+})
+
+#define _wait_for(COND, US, Wmin, Wmax)	__wait_for(, (COND), (US), (Wmin), \
+						   (Wmax))
+#define wait_for(COND, MS)		_wait_for((COND), (MS) * 1000, 10, 1000)
+
+/*
+ * If CONFIG_PREEMPT_COUNT is disabled, in_atomic() always reports false.
+ * On PREEMPT_RT the context isn't becoming atomic because it is used in an
+ * interrupt handler or because a spinlock_t is acquired. This leads to
+ * warnings which don't occur otherwise and therefore the check is disabled.
+ */
+#if IS_ENABLED(CONFIG_DRM_I915_DEBUG) && IS_ENABLED(CONFIG_PREEMPT_COUNT) && !defined(CONFIG_PREEMPT_RT)
+# define _WAIT_FOR_ATOMIC_CHECK(ATOMIC) WARN_ON_ONCE((ATOMIC) && !in_atomic())
+#else
+# define _WAIT_FOR_ATOMIC_CHECK(ATOMIC) do { } while (0)
+#endif
+
+#define _wait_for_atomic(COND, US, ATOMIC) \
+({ \
+	int cpu, ret, timeout = (US) * 1000; \
+	u64 base; \
+	_WAIT_FOR_ATOMIC_CHECK(ATOMIC); \
+	if (!(ATOMIC)) { \
+		preempt_disable(); \
+		cpu = smp_processor_id(); \
+	} \
+	base = local_clock(); \
+	for (;;) { \
+		u64 now = local_clock(); \
+		if (!(ATOMIC)) \
+			preempt_enable(); \
+		/* Guarantee COND check prior to timeout */ \
+		barrier(); \
+		if (COND) { \
+			ret = 0; \
+			break; \
+		} \
+		if (now - base >= timeout) { \
+			ret = -ETIMEDOUT; \
+			break; \
+		} \
+		cpu_relax(); \
+		if (!(ATOMIC)) { \
+			preempt_disable(); \
+			if (unlikely(cpu != smp_processor_id())) { \
+				timeout -= now - base; \
+				cpu = smp_processor_id(); \
+				base = local_clock(); \
+			} \
+		} \
+	} \
+	ret; \
+})
+
+#define wait_for_us(COND, US) \
+({ \
+	int ret__; \
+	BUILD_BUG_ON(!__builtin_constant_p(US)); \
+	if ((US) > 10) \
+		ret__ = _wait_for((COND), (US), 10, 10); \
+	else \
+		ret__ = _wait_for_atomic((COND), (US), 0); \
+	ret__; \
+})
+
+#define wait_for_atomic_us(COND, US) \
+({ \
+	BUILD_BUG_ON(!__builtin_constant_p(US)); \
+	BUILD_BUG_ON((US) > 50000); \
+	_wait_for_atomic((COND), (US), 1); \
+})
+
+#define wait_for_atomic(COND, MS) wait_for_atomic_us((COND), (MS) * 1000)
+
+#endif /* __I915_WAIT_UTIL_H__ */
diff --git a/drivers/gpu/drm/i915/intel_pcode.c b/drivers/gpu/drm/i915/intel_pcode.c
index 81da75108c60..55ffedad2490 100644
--- a/drivers/gpu/drm/i915/intel_pcode.c
+++ b/drivers/gpu/drm/i915/intel_pcode.c
@@ -5,6 +5,7 @@
 
 #include "i915_drv.h"
 #include "i915_reg.h"
+#include "i915_wait_util.h"
 #include "intel_pcode.h"
 
 static int gen6_check_mailbox_status(u32 mbox)
diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c
index 4ccba7c8ffb3..8cb59f8d1f4c 100644
--- a/drivers/gpu/drm/i915/intel_uncore.c
+++ b/drivers/gpu/drm/i915/intel_uncore.c
@@ -21,19 +21,20 @@
  * IN THE SOFTWARE.
  */
 
-#include <drm/drm_managed.h>
 #include <linux/pm_runtime.h>
 
-#include "display/intel_display_core.h"
+#include <drm/drm_managed.h>
 
-#include "gt/intel_gt.h"
+#include "display/intel_display_core.h"
 #include "gt/intel_engine_regs.h"
+#include "gt/intel_gt.h"
 #include "gt/intel_gt_regs.h"
 
 #include "i915_drv.h"
 #include "i915_iosf_mbi.h"
 #include "i915_reg.h"
 #include "i915_vgpu.h"
+#include "i915_wait_util.h"
 #include "intel_uncore_trace.h"
 
 #define FORCEWAKE_ACK_TIMEOUT_MS 50
diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp.c b/drivers/gpu/drm/i915/pxp/intel_pxp.c
index f8da693ad3ce..27d545c4e6a5 100644
--- a/drivers/gpu/drm/i915/pxp/intel_pxp.c
+++ b/drivers/gpu/drm/i915/pxp/intel_pxp.c
@@ -2,15 +2,15 @@
 /*
  * Copyright(c) 2020 Intel Corporation.
  */
+
 #include <linux/workqueue.h>
 
 #include "gem/i915_gem_context.h"
-
 #include "gt/intel_context.h"
 #include "gt/intel_gt.h"
 
 #include "i915_drv.h"
-
+#include "i915_wait_util.h"
 #include "intel_pxp.h"
 #include "intel_pxp_gsccs.h"
 #include "intel_pxp_irq.h"
diff --git a/drivers/gpu/drm/i915/selftests/i915_request.c b/drivers/gpu/drm/i915/selftests/i915_request.c
index 2fb7a9e7efec..48cd617247d1 100644
--- a/drivers/gpu/drm/i915/selftests/i915_request.c
+++ b/drivers/gpu/drm/i915/selftests/i915_request.c
@@ -22,14 +22,13 @@
  *
  */
 
-#include <linux/prime_numbers.h>
 #include <linux/pm_qos.h>
+#include <linux/prime_numbers.h>
 #include <linux/sort.h>
 
 #include "gem/i915_gem_internal.h"
 #include "gem/i915_gem_pm.h"
 #include "gem/selftests/mock_context.h"
-
 #include "gt/intel_engine_heartbeat.h"
 #include "gt/intel_engine_pm.h"
 #include "gt/intel_engine_user.h"
@@ -40,11 +39,11 @@
 
 #include "i915_random.h"
 #include "i915_selftest.h"
+#include "i915_wait_util.h"
 #include "igt_flush_test.h"
 #include "igt_live_test.h"
 #include "igt_spinner.h"
 #include "lib_sw_fence.h"
-
 #include "mock_drm.h"
 #include "mock_gem_device.h"
 
diff --git a/drivers/gpu/drm/i915/selftests/i915_selftest.c b/drivers/gpu/drm/i915/selftests/i915_selftest.c
index 889281819c5b..9c276c9d0a75 100644
--- a/drivers/gpu/drm/i915/selftests/i915_selftest.c
+++ b/drivers/gpu/drm/i915/selftests/i915_selftest.c
@@ -31,7 +31,7 @@
 #include "i915_driver.h"
 #include "i915_drv.h"
 #include "i915_selftest.h"
-
+#include "i915_wait_util.h"
 #include "igt_flush_test.h"
 
 struct i915_selftest i915_selftest __read_mostly = {
diff --git a/drivers/gpu/drm/i915/selftests/igt_spinner.c b/drivers/gpu/drm/i915/selftests/igt_spinner.c
index 8c3e1f20e5a1..820364171ebe 100644
--- a/drivers/gpu/drm/i915/selftests/igt_spinner.c
+++ b/drivers/gpu/drm/i915/selftests/igt_spinner.c
@@ -3,12 +3,13 @@
  *
  * Copyright © 2018 Intel Corporation
  */
-#include "gt/intel_gpu_commands.h"
-#include "gt/intel_gt.h"
 
 #include "gem/i915_gem_internal.h"
 #include "gem/selftests/igt_gem_utils.h"
+#include "gt/intel_gpu_commands.h"
+#include "gt/intel_gt.h"
 
+#include "i915_wait_util.h"
 #include "igt_spinner.h"
 
 int igt_spinner_init(struct igt_spinner *spin, struct intel_gt *gt)
diff --git a/drivers/gpu/drm/i915/vlv_suspend.c b/drivers/gpu/drm/i915/vlv_suspend.c
index fc9f311ea1db..221e4c0b2c58 100644
--- a/drivers/gpu/drm/i915/vlv_suspend.c
+++ b/drivers/gpu/drm/i915/vlv_suspend.c
@@ -8,16 +8,17 @@
 
 #include <drm/drm_print.h>
 
+#include "gt/intel_gt_regs.h"
+
 #include "i915_drv.h"
 #include "i915_reg.h"
 #include "i915_trace.h"
 #include "i915_utils.h"
+#include "i915_wait_util.h"
 #include "intel_clock_gating.h"
 #include "intel_uncore_trace.h"
 #include "vlv_suspend.h"
 
-#include "gt/intel_gt_regs.h"
-
 struct vlv_s0ix_state {
 	/* GAM */
 	u32 wr_watermark;
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* ✗ Fi.CI.BUILD: failure for drm/i915: clean up i915_utils.h
  2025-09-08 14:11 [PATCH 0/5] drm/i915: clean up i915_utils.h Jani Nikula
                   ` (4 preceding siblings ...)
  2025-09-08 14:11 ` [PATCH 5/5] drm/i915: split out i915_wait_util.h Jani Nikula
@ 2025-09-08 19:07 ` Patchwork
  5 siblings, 0 replies; 14+ messages in thread
From: Patchwork @ 2025-09-08 19:07 UTC (permalink / raw)
  To: Jani Nikula; +Cc: intel-gfx

== Series Details ==

Series: drm/i915: clean up i915_utils.h
URL   : https://patchwork.freedesktop.org/series/154194/
State : failure

== Summary ==

Error: make failed
  CALL    scripts/checksyscalls.sh
  DESCEND objtool
  INSTALL libsubcmd_headers
  CC [M]  drivers/gpu/drm/i915/i915_driver.o
In file included from ./drivers/gpu/drm/i915/gt/intel_engine_types.h:20,
                 from ./drivers/gpu/drm/i915/gt/intel_context_types.h:17,
                 from drivers/gpu/drm/i915/gem/i915_gem_context_types.h:19,
                 from drivers/gpu/drm/i915/gem/i915_gem_context.h:9,
                 from drivers/gpu/drm/i915/i915_driver.c:70:
./drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h: In function ‘engine_class_to_guc_class’:
./drivers/gpu/drm/i915/i915_gem.h:123:37: error: implicit declaration of function ‘__add_taint_for_CI’ [-Werror=implicit-function-declaration]
  123 |         do { ftrace_dump(DUMP_ALL); __add_taint_for_CI(TAINT_WARN); } while (0)
      |                                     ^~~~~~~~~~~~~~~~~~
./drivers/gpu/drm/i915/i915_gem.h:98:17: note: in expansion of macro ‘GEM_TRACE_DUMP’
   98 |                 GEM_TRACE_DUMP(); \
      |                 ^~~~~~~~~~~~~~
./drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h:186:9: note: in expansion of macro ‘GEM_BUG_ON’
  186 |         GEM_BUG_ON(class > MAX_ENGINE_CLASS);
      |         ^~~~~~~~~~
In file included from ./drivers/gpu/drm/i915/i915_drv.h:56,
                 from ./drivers/gpu/drm/i915/gt/intel_context.h:14,
                 from drivers/gpu/drm/i915/gem/i915_gem_context.h:11:
./drivers/gpu/drm/i915/i915_utils.h: At top level:
./drivers/gpu/drm/i915/i915_utils.h:141:20: error: conflicting types for ‘__add_taint_for_CI’; have ‘void(unsigned int)’ [-Werror]
  141 | static inline void __add_taint_for_CI(unsigned int taint)
      |                    ^~~~~~~~~~~~~~~~~~
./drivers/gpu/drm/i915/i915_utils.h:141:20: error: static declaration of ‘__add_taint_for_CI’ follows non-static declaration
./drivers/gpu/drm/i915/i915_gem.h:123:37: note: previous implicit declaration of ‘__add_taint_for_CI’ with type ‘void(unsigned int)’
  123 |         do { ftrace_dump(DUMP_ALL); __add_taint_for_CI(TAINT_WARN); } while (0)
      |                                     ^~~~~~~~~~~~~~~~~~
./drivers/gpu/drm/i915/i915_gem.h:98:17: note: in expansion of macro ‘GEM_TRACE_DUMP’
   98 |                 GEM_TRACE_DUMP(); \
      |                 ^~~~~~~~~~~~~~
./drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h:186:9: note: in expansion of macro ‘GEM_BUG_ON’
  186 |         GEM_BUG_ON(class > MAX_ENGINE_CLASS);
      |         ^~~~~~~~~~
cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:287: drivers/gpu/drm/i915/i915_driver.o] Error 1
make[5]: *** [scripts/Makefile.build:556: drivers/gpu/drm/i915] Error 2
make[4]: *** [scripts/Makefile.build:556: drivers/gpu/drm] Error 2
make[3]: *** [scripts/Makefile.build:556: drivers/gpu] Error 2
make[2]: *** [scripts/Makefile.build:556: drivers] Error 2
make[1]: *** [/home/kbuild2/kernel/Makefile:2011: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2
Build failed, no error log produced



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/5] drm/i915: redundant i915_utils.h includes
  2025-09-08 14:11 ` [PATCH 1/5] drm/i915: redundant i915_utils.h includes Jani Nikula
@ 2025-09-09 13:36   ` Rodrigo Vivi
  0 siblings, 0 replies; 14+ messages in thread
From: Rodrigo Vivi @ 2025-09-09 13:36 UTC (permalink / raw)
  To: Jani Nikula; +Cc: intel-gfx

On Mon, Sep 08, 2025 at 05:11:45PM +0300, Jani Nikula wrote:
> Neither intel_guc.h nor i915_gem.h need i915_utils.h anymore. Just drop
> the includes.
> 
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

> ---
>  drivers/gpu/drm/i915/gt/uc/intel_guc.h | 1 -
>  drivers/gpu/drm/i915/i915_gem.h        | 2 --
>  2 files changed, 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc.h b/drivers/gpu/drm/i915/gt/uc/intel_guc.h
> index 053780f562c1..ce766f558ce5 100644
> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc.h
> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc.h
> @@ -18,7 +18,6 @@
>  #include "intel_guc_slpc_types.h"
>  #include "intel_uc_fw.h"
>  #include "intel_uncore.h"
> -#include "i915_utils.h"
>  #include "i915_vma.h"
>  
>  struct __guc_ads_blob;
> diff --git a/drivers/gpu/drm/i915/i915_gem.h b/drivers/gpu/drm/i915/i915_gem.h
> index 20b3cb29cfff..cd7114002944 100644
> --- a/drivers/gpu/drm/i915/i915_gem.h
> +++ b/drivers/gpu/drm/i915/i915_gem.h
> @@ -30,8 +30,6 @@
>  
>  #include <drm/drm_drv.h>
>  
> -#include "i915_utils.h"
> -
>  struct drm_file;
>  struct drm_i915_gem_object;
>  struct drm_i915_private;
> -- 
> 2.47.3
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/5] drm/i915: split out i915_ptr_util.h
  2025-09-08 14:11 ` [PATCH 2/5] drm/i915: split out i915_ptr_util.h Jani Nikula
@ 2025-09-09 13:37   ` Rodrigo Vivi
  0 siblings, 0 replies; 14+ messages in thread
From: Rodrigo Vivi @ 2025-09-09 13:37 UTC (permalink / raw)
  To: Jani Nikula; +Cc: intel-gfx

On Mon, Sep 08, 2025 at 05:11:46PM +0300, Jani Nikula wrote:
> Move pointer related utilities from i915_utils.h to a separate new
> i915_ptr_util.h header. Clean up related includes.
> 
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>

I wonder if we should add some 'i915_' prefix in them
to avoid pretending they are a global kernel thing...

but the spin off is already a good clean-up start point...

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

> ---
>  drivers/gpu/drm/i915/gt/intel_context_types.h |  1 -
>  drivers/gpu/drm/i915/gt/intel_timeline.h      |  1 +
>  drivers/gpu/drm/i915/i915_ptr_util.h          | 66 +++++++++++++++++++
>  drivers/gpu/drm/i915/i915_request.h           |  5 +-
>  drivers/gpu/drm/i915/i915_utils.h             | 57 ----------------
>  drivers/gpu/drm/i915/i915_vma.h               |  6 +-
>  6 files changed, 73 insertions(+), 63 deletions(-)
>  create mode 100644 drivers/gpu/drm/i915/i915_ptr_util.h
> 
> diff --git a/drivers/gpu/drm/i915/gt/intel_context_types.h b/drivers/gpu/drm/i915/gt/intel_context_types.h
> index 98c7f6052069..10070ee4d74c 100644
> --- a/drivers/gpu/drm/i915/gt/intel_context_types.h
> +++ b/drivers/gpu/drm/i915/gt/intel_context_types.h
> @@ -14,7 +14,6 @@
>  
>  #include "i915_active_types.h"
>  #include "i915_sw_fence.h"
> -#include "i915_utils.h"
>  #include "intel_engine_types.h"
>  #include "intel_sseu.h"
>  #include "intel_wakeref.h"
> diff --git a/drivers/gpu/drm/i915/gt/intel_timeline.h b/drivers/gpu/drm/i915/gt/intel_timeline.h
> index 57308c4d664a..5f8c8f79714e 100644
> --- a/drivers/gpu/drm/i915/gt/intel_timeline.h
> +++ b/drivers/gpu/drm/i915/gt/intel_timeline.h
> @@ -10,6 +10,7 @@
>  
>  #include "i915_active.h"
>  #include "i915_syncmap.h"
> +#include "i915_utils.h"
>  #include "intel_timeline_types.h"
>  
>  struct drm_printer;
> diff --git a/drivers/gpu/drm/i915/i915_ptr_util.h b/drivers/gpu/drm/i915/i915_ptr_util.h
> new file mode 100644
> index 000000000000..9f8931d7d99b
> --- /dev/null
> +++ b/drivers/gpu/drm/i915/i915_ptr_util.h
> @@ -0,0 +1,66 @@
> +/* SPDX-License-Identifier: MIT */
> +/* Copyright © 2025 Intel Corporation */
> +
> +#ifndef __I915_PTR_UTIL_H__
> +#define __I915_PTR_UTIL_H__
> +
> +#include <linux/types.h>
> +
> +#define ptr_mask_bits(ptr, n) ({					\
> +	unsigned long __v = (unsigned long)(ptr);			\
> +	(typeof(ptr))(__v & -BIT(n));					\
> +})
> +
> +#define ptr_unmask_bits(ptr, n) ((unsigned long)(ptr) & (BIT(n) - 1))
> +
> +#define ptr_unpack_bits(ptr, bits, n) ({				\
> +	unsigned long __v = (unsigned long)(ptr);			\
> +	*(bits) = __v & (BIT(n) - 1);					\
> +	(typeof(ptr))(__v & -BIT(n));					\
> +})
> +
> +#define ptr_pack_bits(ptr, bits, n) ({					\
> +	unsigned long __bits = (bits);					\
> +	GEM_BUG_ON(__bits & -BIT(n));					\
> +	((typeof(ptr))((unsigned long)(ptr) | __bits));			\
> +})
> +
> +#define ptr_dec(ptr) ({							\
> +	unsigned long __v = (unsigned long)(ptr);			\
> +	(typeof(ptr))(__v - 1);						\
> +})
> +
> +#define ptr_inc(ptr) ({							\
> +	unsigned long __v = (unsigned long)(ptr);			\
> +	(typeof(ptr))(__v + 1);						\
> +})
> +
> +#define page_mask_bits(ptr) ptr_mask_bits(ptr, PAGE_SHIFT)
> +#define page_unmask_bits(ptr) ptr_unmask_bits(ptr, PAGE_SHIFT)
> +#define page_pack_bits(ptr, bits) ptr_pack_bits(ptr, bits, PAGE_SHIFT)
> +#define page_unpack_bits(ptr, bits) ptr_unpack_bits(ptr, bits, PAGE_SHIFT)
> +
> +static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b)
> +{
> +	return a - b;
> +}
> +
> +#define u64_to_ptr(T, x) ({						\
> +	typecheck(u64, x);						\
> +	(T *)(uintptr_t)(x);						\
> +})
> +
> +/*
> + * container_of_user: Extract the superclass from a pointer to a member.
> + *
> + * Exactly like container_of() with the exception that it plays nicely
> + * with sparse for __user @ptr.
> + */
> +#define container_of_user(ptr, type, member) ({				\
> +	void __user *__mptr = (void __user *)(ptr);			\
> +	BUILD_BUG_ON_MSG(!__same_type(*(ptr), typeof_member(type, member)) && \
> +			 !__same_type(*(ptr), void),			\
> +			 "pointer type mismatch in container_of()");	\
> +	((type __user *)(__mptr - offsetof(type, member))); })
> +
> +#endif /* __I915_PTR_UTIL_H__ */
> diff --git a/drivers/gpu/drm/i915/i915_request.h b/drivers/gpu/drm/i915/i915_request.h
> index 5f7e8138ec14..b09135301f39 100644
> --- a/drivers/gpu/drm/i915/i915_request.h
> +++ b/drivers/gpu/drm/i915/i915_request.h
> @@ -31,19 +31,20 @@
>  #include <linux/llist.h>
>  #include <linux/lockdep.h>
>  
> +#include <uapi/drm/i915_drm.h>
> +
>  #include "gem/i915_gem_context_types.h"
>  #include "gt/intel_context_types.h"
>  #include "gt/intel_engine_types.h"
>  #include "gt/intel_timeline_types.h"
>  
>  #include "i915_gem.h"
> +#include "i915_ptr_util.h"
>  #include "i915_scheduler.h"
>  #include "i915_selftest.h"
>  #include "i915_sw_fence.h"
>  #include "i915_vma_resource.h"
>  
> -#include <uapi/drm/i915_drm.h>
> -
>  struct drm_file;
>  struct drm_i915_gem_object;
>  struct drm_printer;
> diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
> index eb4d43c40009..dff02a944a57 100644
> --- a/drivers/gpu/drm/i915/i915_utils.h
> +++ b/drivers/gpu/drm/i915/i915_utils.h
> @@ -67,64 +67,12 @@ bool i915_error_injected(void);
>  		drm_err(&(i915)->drm, fmt, ##__VA_ARGS__); \
>  })
>  
> -#define ptr_mask_bits(ptr, n) ({					\
> -	unsigned long __v = (unsigned long)(ptr);			\
> -	(typeof(ptr))(__v & -BIT(n));					\
> -})
> -
> -#define ptr_unmask_bits(ptr, n) ((unsigned long)(ptr) & (BIT(n) - 1))
> -
> -#define ptr_unpack_bits(ptr, bits, n) ({				\
> -	unsigned long __v = (unsigned long)(ptr);			\
> -	*(bits) = __v & (BIT(n) - 1);					\
> -	(typeof(ptr))(__v & -BIT(n));					\
> -})
> -
> -#define ptr_pack_bits(ptr, bits, n) ({					\
> -	unsigned long __bits = (bits);					\
> -	GEM_BUG_ON(__bits & -BIT(n));					\
> -	((typeof(ptr))((unsigned long)(ptr) | __bits));			\
> -})
> -
> -#define ptr_dec(ptr) ({							\
> -	unsigned long __v = (unsigned long)(ptr);			\
> -	(typeof(ptr))(__v - 1);						\
> -})
> -
> -#define ptr_inc(ptr) ({							\
> -	unsigned long __v = (unsigned long)(ptr);			\
> -	(typeof(ptr))(__v + 1);						\
> -})
> -
> -#define page_mask_bits(ptr) ptr_mask_bits(ptr, PAGE_SHIFT)
> -#define page_unmask_bits(ptr) ptr_unmask_bits(ptr, PAGE_SHIFT)
> -#define page_pack_bits(ptr, bits) ptr_pack_bits(ptr, bits, PAGE_SHIFT)
> -#define page_unpack_bits(ptr, bits) ptr_unpack_bits(ptr, bits, PAGE_SHIFT)
> -
>  #define fetch_and_zero(ptr) ({						\
>  	typeof(*ptr) __T = *(ptr);					\
>  	*(ptr) = (typeof(*ptr))0;					\
>  	__T;								\
>  })
>  
> -static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b)
> -{
> -	return a - b;
> -}
> -
> -/*
> - * container_of_user: Extract the superclass from a pointer to a member.
> - *
> - * Exactly like container_of() with the exception that it plays nicely
> - * with sparse for __user @ptr.
> - */
> -#define container_of_user(ptr, type, member) ({				\
> -	void __user *__mptr = (void __user *)(ptr);			\
> -	BUILD_BUG_ON_MSG(!__same_type(*(ptr), typeof_member(type, member)) && \
> -			 !__same_type(*(ptr), void),			\
> -			 "pointer type mismatch in container_of()");	\
> -	((type __user *)(__mptr - offsetof(type, member))); })
> -
>  /*
>   * check_user_mbz: Check that a user value exists and is zero
>   *
> @@ -143,11 +91,6 @@ static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b)
>  	get_user(mbz__, (U)) ? -EFAULT : mbz__ ? -EINVAL : 0;		\
>  })
>  
> -#define u64_to_ptr(T, x) ({						\
> -	typecheck(u64, x);						\
> -	(T *)(uintptr_t)(x);						\
> -})
> -
>  #define __mask_next_bit(mask) ({					\
>  	int __idx = ffs(mask) - 1;					\
>  	mask &= ~BIT(__idx);						\
> diff --git a/drivers/gpu/drm/i915/i915_vma.h b/drivers/gpu/drm/i915/i915_vma.h
> index 0f9eee6d18d2..8054047840aa 100644
> --- a/drivers/gpu/drm/i915/i915_vma.h
> +++ b/drivers/gpu/drm/i915/i915_vma.h
> @@ -30,12 +30,12 @@
>  
>  #include <drm/drm_mm.h>
>  
> -#include "gt/intel_ggtt_fencing.h"
>  #include "gem/i915_gem_object.h"
> -
> -#include "i915_gem_gtt.h"
> +#include "gt/intel_ggtt_fencing.h"
>  
>  #include "i915_active.h"
> +#include "i915_gem_gtt.h"
> +#include "i915_ptr_util.h"
>  #include "i915_request.h"
>  #include "i915_vma_resource.h"
>  #include "i915_vma_types.h"
> -- 
> 2.47.3
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/5] drm/i915: split out i915_timer_util.[ch]
  2025-09-08 14:11 ` [PATCH 3/5] drm/i915: split out i915_timer_util.[ch] Jani Nikula
@ 2025-09-09 13:38   ` Rodrigo Vivi
  0 siblings, 0 replies; 14+ messages in thread
From: Rodrigo Vivi @ 2025-09-09 13:38 UTC (permalink / raw)
  To: Jani Nikula; +Cc: intel-gfx

On Mon, Sep 08, 2025 at 05:11:47PM +0300, Jani Nikula wrote:
> Move timer related utilities from i915_utils.[ch] to separate new files
> i915_timer_util.[ch]. Clean up related includes.
> 
> Note: Arguably none of this should exist in i915 in the first place. At
> least isolate it better.
> 
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

> ---
>  drivers/gpu/drm/i915/Makefile                 |  1 +
>  .../drm/i915/gt/intel_execlists_submission.c  |  4 ++-
>  drivers/gpu/drm/i915/gt/sysfs_engines.c       |  1 +
>  drivers/gpu/drm/i915/i915_timer_util.c        | 36 +++++++++++++++++++
>  drivers/gpu/drm/i915/i915_timer_util.h        | 23 ++++++++++++
>  drivers/gpu/drm/i915/i915_utils.c             | 30 ----------------
>  drivers/gpu/drm/i915/i915_utils.h             | 14 --------
>  7 files changed, 64 insertions(+), 45 deletions(-)
>  create mode 100644 drivers/gpu/drm/i915/i915_timer_util.c
>  create mode 100644 drivers/gpu/drm/i915/i915_timer_util.h
> 
> diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
> index db150a0c33ce..e58c0c158b3a 100644
> --- a/drivers/gpu/drm/i915/Makefile
> +++ b/drivers/gpu/drm/i915/Makefile
> @@ -32,6 +32,7 @@ i915-y += \
>  	i915_scatterlist.o \
>  	i915_switcheroo.o \
>  	i915_sysfs.o \
> +	i915_timer_util.o \
>  	i915_utils.o \
>  	intel_clock_gating.o \
>  	intel_cpu_info.o \
> diff --git a/drivers/gpu/drm/i915/gt/intel_execlists_submission.c b/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
> index 03baa7fa0a27..52c8fddedfce 100644
> --- a/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
> +++ b/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
> @@ -106,14 +106,16 @@
>   * preemption, but just sampling the new tail pointer).
>   *
>   */
> +
>  #include <linux/interrupt.h>
>  #include <linux/string_helpers.h>
>  
> +#include "gen8_engine_cs.h"
>  #include "i915_drv.h"
>  #include "i915_reg.h"
> +#include "i915_timer_util.h"
>  #include "i915_trace.h"
>  #include "i915_vgpu.h"
> -#include "gen8_engine_cs.h"
>  #include "intel_breadcrumbs.h"
>  #include "intel_context.h"
>  #include "intel_engine_heartbeat.h"
> diff --git a/drivers/gpu/drm/i915/gt/sysfs_engines.c b/drivers/gpu/drm/i915/gt/sysfs_engines.c
> index aab2759067d2..4a81bc396b21 100644
> --- a/drivers/gpu/drm/i915/gt/sysfs_engines.c
> +++ b/drivers/gpu/drm/i915/gt/sysfs_engines.c
> @@ -7,6 +7,7 @@
>  #include <linux/sysfs.h>
>  
>  #include "i915_drv.h"
> +#include "i915_timer_util.h"
>  #include "intel_engine.h"
>  #include "intel_engine_heartbeat.h"
>  #include "sysfs_engines.h"
> diff --git a/drivers/gpu/drm/i915/i915_timer_util.c b/drivers/gpu/drm/i915/i915_timer_util.c
> new file mode 100644
> index 000000000000..ee4cfd8b3c07
> --- /dev/null
> +++ b/drivers/gpu/drm/i915/i915_timer_util.c
> @@ -0,0 +1,36 @@
> +// SPDX-License-Identifier: MIT
> +/* Copyright © 2025 Intel Corporation */
> +
> +#include <linux/jiffies.h>
> +
> +#include "i915_timer_util.h"
> +
> +void cancel_timer(struct timer_list *t)
> +{
> +	if (!timer_active(t))
> +		return;
> +
> +	timer_delete(t);
> +	WRITE_ONCE(t->expires, 0);
> +}
> +
> +void set_timer_ms(struct timer_list *t, unsigned long timeout)
> +{
> +	if (!timeout) {
> +		cancel_timer(t);
> +		return;
> +	}
> +
> +	timeout = msecs_to_jiffies(timeout);
> +
> +	/*
> +	 * Paranoia to make sure the compiler computes the timeout before
> +	 * loading 'jiffies' as jiffies is volatile and may be updated in
> +	 * the background by a timer tick. All to reduce the complexity
> +	 * of the addition and reduce the risk of losing a jiffy.
> +	 */
> +	barrier();
> +
> +	/* Keep t->expires = 0 reserved to indicate a canceled timer. */
> +	mod_timer(t, jiffies + timeout ?: 1);
> +}
> diff --git a/drivers/gpu/drm/i915/i915_timer_util.h b/drivers/gpu/drm/i915/i915_timer_util.h
> new file mode 100644
> index 000000000000..f35ad730820c
> --- /dev/null
> +++ b/drivers/gpu/drm/i915/i915_timer_util.h
> @@ -0,0 +1,23 @@
> +/* SPDX-License-Identifier: MIT */
> +/* Copyright © 2025 Intel Corporation */
> +
> +#ifndef __I915_TIMER_UTIL_H__
> +#define __I915_TIMER_UTIL_H__
> +
> +#include <linux/timer.h>
> +#include <asm/rwonce.h>
> +
> +void cancel_timer(struct timer_list *t);
> +void set_timer_ms(struct timer_list *t, unsigned long timeout);
> +
> +static inline bool timer_active(const struct timer_list *t)
> +{
> +	return READ_ONCE(t->expires);
> +}
> +
> +static inline bool timer_expired(const struct timer_list *t)
> +{
> +	return timer_active(t) && !timer_pending(t);
> +}
> +
> +#endif /* __I915_TIMER_UTIL_H__ */
> diff --git a/drivers/gpu/drm/i915/i915_utils.c b/drivers/gpu/drm/i915/i915_utils.c
> index b60c28fbd207..49f7ed413132 100644
> --- a/drivers/gpu/drm/i915/i915_utils.c
> +++ b/drivers/gpu/drm/i915/i915_utils.c
> @@ -47,36 +47,6 @@ bool i915_error_injected(void)
>  
>  #endif
>  
> -void cancel_timer(struct timer_list *t)
> -{
> -	if (!timer_active(t))
> -		return;
> -
> -	timer_delete(t);
> -	WRITE_ONCE(t->expires, 0);
> -}
> -
> -void set_timer_ms(struct timer_list *t, unsigned long timeout)
> -{
> -	if (!timeout) {
> -		cancel_timer(t);
> -		return;
> -	}
> -
> -	timeout = msecs_to_jiffies(timeout);
> -
> -	/*
> -	 * Paranoia to make sure the compiler computes the timeout before
> -	 * loading 'jiffies' as jiffies is volatile and may be updated in
> -	 * the background by a timer tick. All to reduce the complexity
> -	 * of the addition and reduce the risk of losing a jiffy.
> -	 */
> -	barrier();
> -
> -	/* Keep t->expires = 0 reserved to indicate a canceled timer. */
> -	mod_timer(t, jiffies + timeout ?: 1);
> -}
> -
>  bool i915_vtd_active(struct drm_i915_private *i915)
>  {
>  	if (device_iommu_mapped(i915->drm.dev))
> diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
> index dff02a944a57..6278a74d08c2 100644
> --- a/drivers/gpu/drm/i915/i915_utils.h
> +++ b/drivers/gpu/drm/i915/i915_utils.h
> @@ -38,7 +38,6 @@
>  #endif
>  
>  struct drm_i915_private;
> -struct timer_list;
>  
>  #define MISSING_CASE(x) WARN(1, "Missing case (%s == %ld)\n", \
>  			     __stringify(x), (long)(x))
> @@ -270,19 +269,6 @@ static inline void __add_taint_for_CI(unsigned int taint)
>  	add_taint(taint, LOCKDEP_STILL_OK);
>  }
>  
> -void cancel_timer(struct timer_list *t);
> -void set_timer_ms(struct timer_list *t, unsigned long timeout);
> -
> -static inline bool timer_active(const struct timer_list *t)
> -{
> -	return READ_ONCE(t->expires);
> -}
> -
> -static inline bool timer_expired(const struct timer_list *t)
> -{
> -	return timer_active(t) && !timer_pending(t);
> -}
> -
>  static inline bool i915_run_as_guest(void)
>  {
>  #if IS_ENABLED(CONFIG_X86)
> -- 
> 2.47.3
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 4/5] drm/i915: split out i915_list_util.h
  2025-09-08 14:11 ` [PATCH 4/5] drm/i915: split out i915_list_util.h Jani Nikula
@ 2025-09-09 13:39   ` Rodrigo Vivi
  0 siblings, 0 replies; 14+ messages in thread
From: Rodrigo Vivi @ 2025-09-09 13:39 UTC (permalink / raw)
  To: Jani Nikula; +Cc: intel-gfx

On Mon, Sep 08, 2025 at 05:11:48PM +0300, Jani Nikula wrote:
> Move list related utilities from i915_utils.h to separate new file
> i915_list_util.h. Clean up related includes.
> 

here as well I believe it would be better to have an i915_ prefix.

but up to you

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>


> Note: Arguably none of this should exist in i915 in the first place. At
> least isolate it better.
> 
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> ---
>  .../drm/i915/gt/intel_execlists_submission.c  |  1 +
>  .../gpu/drm/i915/gt/intel_gt_buffer_pool.c    |  1 +
>  drivers/gpu/drm/i915/gt/intel_timeline.h      |  2 +-
>  drivers/gpu/drm/i915/i915_list_util.h         | 23 +++++++++++++++++++
>  drivers/gpu/drm/i915/i915_utils.h             | 14 -----------
>  5 files changed, 26 insertions(+), 15 deletions(-)
>  create mode 100644 drivers/gpu/drm/i915/i915_list_util.h
> 
> diff --git a/drivers/gpu/drm/i915/gt/intel_execlists_submission.c b/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
> index 52c8fddedfce..0c1b2df02d26 100644
> --- a/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
> +++ b/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
> @@ -112,6 +112,7 @@
>  
>  #include "gen8_engine_cs.h"
>  #include "i915_drv.h"
> +#include "i915_list_util.h"
>  #include "i915_reg.h"
>  #include "i915_timer_util.h"
>  #include "i915_trace.h"
> diff --git a/drivers/gpu/drm/i915/gt/intel_gt_buffer_pool.c b/drivers/gpu/drm/i915/gt/intel_gt_buffer_pool.c
> index 86b5a9ba323d..c7befc5c20d0 100644
> --- a/drivers/gpu/drm/i915/gt/intel_gt_buffer_pool.c
> +++ b/drivers/gpu/drm/i915/gt/intel_gt_buffer_pool.c
> @@ -7,6 +7,7 @@
>  #include "gem/i915_gem_object.h"
>  
>  #include "i915_drv.h"
> +#include "i915_list_util.h"
>  #include "intel_engine_pm.h"
>  #include "intel_gt_buffer_pool.h"
>  
> diff --git a/drivers/gpu/drm/i915/gt/intel_timeline.h b/drivers/gpu/drm/i915/gt/intel_timeline.h
> index 5f8c8f79714e..85b43f9b9d95 100644
> --- a/drivers/gpu/drm/i915/gt/intel_timeline.h
> +++ b/drivers/gpu/drm/i915/gt/intel_timeline.h
> @@ -9,8 +9,8 @@
>  #include <linux/lockdep.h>
>  
>  #include "i915_active.h"
> +#include "i915_list_util.h"
>  #include "i915_syncmap.h"
> -#include "i915_utils.h"
>  #include "intel_timeline_types.h"
>  
>  struct drm_printer;
> diff --git a/drivers/gpu/drm/i915/i915_list_util.h b/drivers/gpu/drm/i915/i915_list_util.h
> new file mode 100644
> index 000000000000..4e515dc8a3e0
> --- /dev/null
> +++ b/drivers/gpu/drm/i915/i915_list_util.h
> @@ -0,0 +1,23 @@
> +/* SPDX-License-Identifier: MIT */
> +/* Copyright © 2025 Intel Corporation */
> +
> +#ifndef __I915_LIST_UTIL_H__
> +#define __I915_LIST_UTIL_H__
> +
> +#include <linux/list.h>
> +#include <asm/rwonce.h>
> +
> +static inline void __list_del_many(struct list_head *head,
> +				   struct list_head *first)
> +{
> +	first->prev = head;
> +	WRITE_ONCE(head->next, first);
> +}
> +
> +static inline int list_is_last_rcu(const struct list_head *list,
> +				   const struct list_head *head)
> +{
> +	return READ_ONCE(list->next) == head;
> +}
> +
> +#endif /* __I915_LIST_UTIL_H__ */
> diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
> index 6278a74d08c2..4a6437d6e00e 100644
> --- a/drivers/gpu/drm/i915/i915_utils.h
> +++ b/drivers/gpu/drm/i915/i915_utils.h
> @@ -25,7 +25,6 @@
>  #ifndef __I915_UTILS_H
>  #define __I915_UTILS_H
>  
> -#include <linux/list.h>
>  #include <linux/overflow.h>
>  #include <linux/sched.h>
>  #include <linux/string_helpers.h>
> @@ -101,19 +100,6 @@ static inline bool is_power_of_2_u64(u64 n)
>  	return (n != 0 && ((n & (n - 1)) == 0));
>  }
>  
> -static inline void __list_del_many(struct list_head *head,
> -				   struct list_head *first)
> -{
> -	first->prev = head;
> -	WRITE_ONCE(head->next, first);
> -}
> -
> -static inline int list_is_last_rcu(const struct list_head *list,
> -				   const struct list_head *head)
> -{
> -	return READ_ONCE(list->next) == head;
> -}
> -
>  static inline unsigned long msecs_to_jiffies_timeout(const unsigned int m)
>  {
>  	unsigned long j = msecs_to_jiffies(m);
> -- 
> 2.47.3
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 5/5] drm/i915: split out i915_wait_util.h
  2025-09-08 14:11 ` [PATCH 5/5] drm/i915: split out i915_wait_util.h Jani Nikula
@ 2025-09-09 13:40   ` Rodrigo Vivi
  2025-09-10 12:06     ` Jani Nikula
  0 siblings, 1 reply; 14+ messages in thread
From: Rodrigo Vivi @ 2025-09-09 13:40 UTC (permalink / raw)
  To: Jani Nikula; +Cc: intel-gfx

On Mon, Sep 08, 2025 at 05:11:49PM +0300, Jani Nikula wrote:
> Move waiting related utilities from i915_utils.h to separate new file
> i915_wait_util.h. Clean up related includes.
> 
> Note: Many of the various wait macro usages could likely be refactored
> to use poll_timeout_us().

I hope so! :)

nice clean up overall, although my dream is that we
could get rid entirely of these utils that pretend
they are core kernel.

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>


> 
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> ---
>  .../drm/i915/gt/intel_execlists_submission.c  |   1 +
>  drivers/gpu/drm/i915/gt/intel_gt_mcr.c        |   1 +
>  drivers/gpu/drm/i915/gt/intel_reset.c         |   7 +-
>  .../gpu/drm/i915/gt/intel_ring_submission.c   |   7 +-
>  drivers/gpu/drm/i915/gt/intel_rps.c           |   2 +
>  drivers/gpu/drm/i915/gt/selftest_tlb.c        |   6 +-
>  drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c  |   6 +-
>  .../i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c |   2 +
>  drivers/gpu/drm/i915/gt/uc/intel_guc.c        |   8 +-
>  drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c     |   3 +-
>  drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c     |   4 +-
>  drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c   |  13 +-
>  .../gpu/drm/i915/gt/uc/intel_guc_submission.c |  10 +-
>  drivers/gpu/drm/i915/gvt/mmio_context.c       |   6 +-
>  drivers/gpu/drm/i915/i915_debugfs.c           |   3 +-
>  drivers/gpu/drm/i915/i915_utils.h             | 106 ----------------
>  drivers/gpu/drm/i915/i915_wait_util.h         | 119 ++++++++++++++++++
>  drivers/gpu/drm/i915/intel_pcode.c            |   1 +
>  drivers/gpu/drm/i915/intel_uncore.c           |   7 +-
>  drivers/gpu/drm/i915/pxp/intel_pxp.c          |   4 +-
>  drivers/gpu/drm/i915/selftests/i915_request.c |   5 +-
>  .../gpu/drm/i915/selftests/i915_selftest.c    |   2 +-
>  drivers/gpu/drm/i915/selftests/igt_spinner.c  |   5 +-
>  drivers/gpu/drm/i915/vlv_suspend.c            |   5 +-
>  24 files changed, 183 insertions(+), 150 deletions(-)
>  create mode 100644 drivers/gpu/drm/i915/i915_wait_util.h
> 
> diff --git a/drivers/gpu/drm/i915/gt/intel_execlists_submission.c b/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
> index 0c1b2df02d26..7f389cb0bde4 100644
> --- a/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
> +++ b/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
> @@ -117,6 +117,7 @@
>  #include "i915_timer_util.h"
>  #include "i915_trace.h"
>  #include "i915_vgpu.h"
> +#include "i915_wait_util.h"
>  #include "intel_breadcrumbs.h"
>  #include "intel_context.h"
>  #include "intel_engine_heartbeat.h"
> diff --git a/drivers/gpu/drm/i915/gt/intel_gt_mcr.c b/drivers/gpu/drm/i915/gt/intel_gt_mcr.c
> index a60822e2b5d4..c3afa321fe30 100644
> --- a/drivers/gpu/drm/i915/gt/intel_gt_mcr.c
> +++ b/drivers/gpu/drm/i915/gt/intel_gt_mcr.c
> @@ -4,6 +4,7 @@
>   */
>  
>  #include "i915_drv.h"
> +#include "i915_wait_util.h"
>  #include "intel_gt.h"
>  #include "intel_gt_mcr.h"
>  #include "intel_gt_print.h"
> diff --git a/drivers/gpu/drm/i915/gt/intel_reset.c b/drivers/gpu/drm/i915/gt/intel_reset.c
> index 4a1675dea1c7..41b5036dc538 100644
> --- a/drivers/gpu/drm/i915/gt/intel_reset.c
> +++ b/drivers/gpu/drm/i915/gt/intel_reset.c
> @@ -9,18 +9,17 @@
>  
>  #include "display/intel_display_reset.h"
>  #include "display/intel_overlay.h"
> -
>  #include "gem/i915_gem_context.h"
> -
>  #include "gt/intel_gt_regs.h"
> -
>  #include "gt/uc/intel_gsc_fw.h"
> +#include "uc/intel_guc.h"
>  
>  #include "i915_drv.h"
>  #include "i915_file_private.h"
>  #include "i915_gpu_error.h"
>  #include "i915_irq.h"
>  #include "i915_reg.h"
> +#include "i915_wait_util.h"
>  #include "intel_breadcrumbs.h"
>  #include "intel_engine_pm.h"
>  #include "intel_engine_regs.h"
> @@ -32,8 +31,6 @@
>  #include "intel_pci_config.h"
>  #include "intel_reset.h"
>  
> -#include "uc/intel_guc.h"
> -
>  #define RESET_MAX_RETRIES 3
>  
>  static void client_mark_guilty(struct i915_gem_context *ctx, bool banned)
> diff --git a/drivers/gpu/drm/i915/gt/intel_ring_submission.c b/drivers/gpu/drm/i915/gt/intel_ring_submission.c
> index 2a6d79abf25b..8314a4b0505e 100644
> --- a/drivers/gpu/drm/i915/gt/intel_ring_submission.c
> +++ b/drivers/gpu/drm/i915/gt/intel_ring_submission.c
> @@ -15,18 +15,19 @@
>  #include "i915_irq.h"
>  #include "i915_mitigations.h"
>  #include "i915_reg.h"
> +#include "i915_wait_util.h"
>  #include "intel_breadcrumbs.h"
>  #include "intel_context.h"
> +#include "intel_engine_heartbeat.h"
> +#include "intel_engine_pm.h"
>  #include "intel_engine_regs.h"
>  #include "intel_gt.h"
>  #include "intel_gt_irq.h"
> +#include "intel_gt_print.h"
>  #include "intel_gt_regs.h"
>  #include "intel_reset.h"
>  #include "intel_ring.h"
>  #include "shmem_utils.h"
> -#include "intel_engine_heartbeat.h"
> -#include "intel_engine_pm.h"
> -#include "intel_gt_print.h"
>  
>  /* Rough estimate of the typical request size, performing a flush,
>   * set-context and then emitting the batch.
> diff --git a/drivers/gpu/drm/i915/gt/intel_rps.c b/drivers/gpu/drm/i915/gt/intel_rps.c
> index 006042e0b229..4da94098bd3e 100644
> --- a/drivers/gpu/drm/i915/gt/intel_rps.c
> +++ b/drivers/gpu/drm/i915/gt/intel_rps.c
> @@ -10,9 +10,11 @@
>  #include "display/intel_display.h"
>  #include "display/intel_display_rps.h"
>  #include "soc/intel_dram.h"
> +
>  #include "i915_drv.h"
>  #include "i915_irq.h"
>  #include "i915_reg.h"
> +#include "i915_wait_util.h"
>  #include "intel_breadcrumbs.h"
>  #include "intel_gt.h"
>  #include "intel_gt_clock_utils.h"
> diff --git a/drivers/gpu/drm/i915/gt/selftest_tlb.c b/drivers/gpu/drm/i915/gt/selftest_tlb.c
> index 69ed946a39e5..a5184f09d1de 100644
> --- a/drivers/gpu/drm/i915/gt/selftest_tlb.c
> +++ b/drivers/gpu/drm/i915/gt/selftest_tlb.c
> @@ -3,17 +3,17 @@
>   * Copyright © 2022 Intel Corporation
>   */
>  
> -#include "i915_selftest.h"
> -
>  #include "gem/i915_gem_internal.h"
>  #include "gem/i915_gem_lmem.h"
>  #include "gem/i915_gem_region.h"
>  
>  #include "gen8_engine_cs.h"
>  #include "i915_gem_ww.h"
> +#include "i915_selftest.h"
> +#include "i915_wait_util.h"
> +#include "intel_context.h"
>  #include "intel_engine_regs.h"
>  #include "intel_gpu_commands.h"
> -#include "intel_context.h"
>  #include "intel_gt.h"
>  #include "intel_ring.h"
>  
> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c b/drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c
> index d8edd7c054c8..e7444ebc373e 100644
> --- a/drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c
> +++ b/drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c
> @@ -10,11 +10,13 @@
>  
>  #include "gt/intel_gt.h"
>  #include "gt/intel_gt_print.h"
> +
> +#include "i915_drv.h"
> +#include "i915_reg.h"
> +#include "i915_wait_util.h"
>  #include "intel_gsc_proxy.h"
>  #include "intel_gsc_uc.h"
>  #include "intel_gsc_uc_heci_cmd_submit.h"
> -#include "i915_drv.h"
> -#include "i915_reg.h"
>  
>  /*
>   * GSC proxy:
> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c b/drivers/gpu/drm/i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c
> index 2fde5c360cff..9bd29be7656f 100644
> --- a/drivers/gpu/drm/i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c
> +++ b/drivers/gpu/drm/i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c
> @@ -8,6 +8,8 @@
>  #include "gt/intel_gpu_commands.h"
>  #include "gt/intel_gt.h"
>  #include "gt/intel_ring.h"
> +
> +#include "i915_wait_util.h"
>  #include "intel_gsc_uc_heci_cmd_submit.h"
>  
>  struct gsc_heci_pkt {
> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc.c b/drivers/gpu/drm/i915/gt/uc/intel_guc.c
> index f360f020d8f1..52ec4421a211 100644
> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc.c
> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc.c
> @@ -8,15 +8,17 @@
>  #include "gt/intel_gt_irq.h"
>  #include "gt/intel_gt_pm_irq.h"
>  #include "gt/intel_gt_regs.h"
> +
> +#include "i915_drv.h"
> +#include "i915_irq.h"
> +#include "i915_reg.h"
> +#include "i915_wait_util.h"
>  #include "intel_guc.h"
>  #include "intel_guc_ads.h"
>  #include "intel_guc_capture.h"
>  #include "intel_guc_print.h"
>  #include "intel_guc_slpc.h"
>  #include "intel_guc_submission.h"
> -#include "i915_drv.h"
> -#include "i915_irq.h"
> -#include "i915_reg.h"
>  
>  /**
>   * DOC: GuC
> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c
> index 380a11c92d63..3e7e5badcc2b 100644
> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c
> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c
> @@ -5,11 +5,12 @@
>  
>  #include <linux/circ_buf.h>
>  #include <linux/ktime.h>
> -#include <linux/time64.h>
>  #include <linux/string_helpers.h>
> +#include <linux/time64.h>
>  #include <linux/timekeeping.h>
>  
>  #include "i915_drv.h"
> +#include "i915_wait_util.h"
>  #include "intel_guc_ct.h"
>  #include "intel_guc_print.h"
>  
> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c
> index e7ccfa520df3..1bb1491f90fc 100644
> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c
> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c
> @@ -13,9 +13,11 @@
>  #include "gt/intel_gt_mcr.h"
>  #include "gt/intel_gt_regs.h"
>  #include "gt/intel_rps.h"
> +
> +#include "i915_drv.h"
> +#include "i915_wait_util.h"
>  #include "intel_guc_fw.h"
>  #include "intel_guc_print.h"
> -#include "i915_drv.h"
>  
>  static void guc_prepare_xfer(struct intel_gt *gt)
>  {
> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c
> index d5ee6e5e1443..fa9af08f9708 100644
> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c
> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c
> @@ -3,17 +3,20 @@
>   * Copyright © 2021 Intel Corporation
>   */
>  
> -#include <drm/drm_cache.h>
>  #include <linux/string_helpers.h>
>  
> +#include <drm/drm_cache.h>
> +
> +#include "gt/intel_gt.h"
> +#include "gt/intel_gt_regs.h"
> +#include "gt/intel_rps.h"
> +
>  #include "i915_drv.h"
>  #include "i915_reg.h"
> -#include "intel_guc_slpc.h"
> +#include "i915_wait_util.h"
>  #include "intel_guc_print.h"
> +#include "intel_guc_slpc.h"
>  #include "intel_mchbar_regs.h"
> -#include "gt/intel_gt.h"
> -#include "gt/intel_gt_regs.h"
> -#include "gt/intel_rps.h"
>  
>  /**
>   * DOC: SLPC - Dynamic Frequency management
> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
> index 127316d2c8aa..68f2b8d363ac 100644
> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
> @@ -25,16 +25,16 @@
>  #include "gt/intel_mocs.h"
>  #include "gt/intel_ring.h"
>  
> +#include "i915_drv.h"
> +#include "i915_irq.h"
> +#include "i915_reg.h"
> +#include "i915_trace.h"
> +#include "i915_wait_util.h"
>  #include "intel_guc_ads.h"
>  #include "intel_guc_capture.h"
>  #include "intel_guc_print.h"
>  #include "intel_guc_submission.h"
>  
> -#include "i915_drv.h"
> -#include "i915_reg.h"
> -#include "i915_irq.h"
> -#include "i915_trace.h"
> -
>  /**
>   * DOC: GuC-based command submission
>   *
> diff --git a/drivers/gpu/drm/i915/gvt/mmio_context.c b/drivers/gpu/drm/i915/gvt/mmio_context.c
> index 2f7208843367..0b810baad20a 100644
> --- a/drivers/gpu/drm/i915/gvt/mmio_context.c
> +++ b/drivers/gpu/drm/i915/gvt/mmio_context.c
> @@ -33,14 +33,16 @@
>   *
>   */
>  
> -#include "i915_drv.h"
> -#include "i915_reg.h"
>  #include "gt/intel_context.h"
>  #include "gt/intel_engine_regs.h"
>  #include "gt/intel_gpu_commands.h"
>  #include "gt/intel_gt_regs.h"
>  #include "gt/intel_ring.h"
> +
>  #include "gvt.h"
> +#include "i915_drv.h"
> +#include "i915_reg.h"
> +#include "i915_wait_util.h"
>  #include "trace.h"
>  
>  #define GEN9_MOCS_SIZE		64
> diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> index 23fa098c4479..c2e38d4bcd01 100644
> --- a/drivers/gpu/drm/i915/i915_debugfs.c
> +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> @@ -26,11 +26,11 @@
>   *
>   */
>  
> +#include <linux/debugfs.h>
>  #include <linux/sched/mm.h>
>  #include <linux/sort.h>
>  #include <linux/string_helpers.h>
>  
> -#include <linux/debugfs.h>
>  #include <drm/drm_debugfs.h>
>  
>  #include "gem/i915_gem_context.h"
> @@ -54,6 +54,7 @@
>  #include "i915_irq.h"
>  #include "i915_reg.h"
>  #include "i915_scheduler.h"
> +#include "i915_wait_util.h"
>  #include "intel_mchbar_regs.h"
>  
>  static inline struct drm_i915_private *node_to_i915(struct drm_info_node *node)
> diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
> index 4a6437d6e00e..a0c892e4c40d 100644
> --- a/drivers/gpu/drm/i915/i915_utils.h
> +++ b/drivers/gpu/drm/i915/i915_utils.h
> @@ -134,112 +134,6 @@ wait_remaining_ms_from_jiffies(unsigned long timestamp_jiffies, int to_wait_ms)
>  	}
>  }
>  
> -/*
> - * __wait_for - magic wait macro
> - *
> - * Macro to help avoid open coding check/wait/timeout patterns. Note that it's
> - * important that we check the condition again after having timed out, since the
> - * timeout could be due to preemption or similar and we've never had a chance to
> - * check the condition before the timeout.
> - */
> -#define __wait_for(OP, COND, US, Wmin, Wmax) ({ \
> -	const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \
> -	long wait__ = (Wmin); /* recommended min for usleep is 10 us */	\
> -	int ret__;							\
> -	might_sleep();							\
> -	for (;;) {							\
> -		const bool expired__ = ktime_after(ktime_get_raw(), end__); \
> -		OP;							\
> -		/* Guarantee COND check prior to timeout */		\
> -		barrier();						\
> -		if (COND) {						\
> -			ret__ = 0;					\
> -			break;						\
> -		}							\
> -		if (expired__) {					\
> -			ret__ = -ETIMEDOUT;				\
> -			break;						\
> -		}							\
> -		usleep_range(wait__, wait__ * 2);			\
> -		if (wait__ < (Wmax))					\
> -			wait__ <<= 1;					\
> -	}								\
> -	ret__;								\
> -})
> -
> -#define _wait_for(COND, US, Wmin, Wmax)	__wait_for(, (COND), (US), (Wmin), \
> -						   (Wmax))
> -#define wait_for(COND, MS)		_wait_for((COND), (MS) * 1000, 10, 1000)
> -
> -/*
> - * If CONFIG_PREEMPT_COUNT is disabled, in_atomic() always reports false.
> - * On PREEMPT_RT the context isn't becoming atomic because it is used in an
> - * interrupt handler or because a spinlock_t is acquired. This leads to
> - * warnings which don't occur otherwise and therefore the check is disabled.
> - */
> -#if IS_ENABLED(CONFIG_DRM_I915_DEBUG) && IS_ENABLED(CONFIG_PREEMPT_COUNT) && !defined(CONFIG_PREEMPT_RT)
> -# define _WAIT_FOR_ATOMIC_CHECK(ATOMIC) WARN_ON_ONCE((ATOMIC) && !in_atomic())
> -#else
> -# define _WAIT_FOR_ATOMIC_CHECK(ATOMIC) do { } while (0)
> -#endif
> -
> -#define _wait_for_atomic(COND, US, ATOMIC) \
> -({ \
> -	int cpu, ret, timeout = (US) * 1000; \
> -	u64 base; \
> -	_WAIT_FOR_ATOMIC_CHECK(ATOMIC); \
> -	if (!(ATOMIC)) { \
> -		preempt_disable(); \
> -		cpu = smp_processor_id(); \
> -	} \
> -	base = local_clock(); \
> -	for (;;) { \
> -		u64 now = local_clock(); \
> -		if (!(ATOMIC)) \
> -			preempt_enable(); \
> -		/* Guarantee COND check prior to timeout */ \
> -		barrier(); \
> -		if (COND) { \
> -			ret = 0; \
> -			break; \
> -		} \
> -		if (now - base >= timeout) { \
> -			ret = -ETIMEDOUT; \
> -			break; \
> -		} \
> -		cpu_relax(); \
> -		if (!(ATOMIC)) { \
> -			preempt_disable(); \
> -			if (unlikely(cpu != smp_processor_id())) { \
> -				timeout -= now - base; \
> -				cpu = smp_processor_id(); \
> -				base = local_clock(); \
> -			} \
> -		} \
> -	} \
> -	ret; \
> -})
> -
> -#define wait_for_us(COND, US) \
> -({ \
> -	int ret__; \
> -	BUILD_BUG_ON(!__builtin_constant_p(US)); \
> -	if ((US) > 10) \
> -		ret__ = _wait_for((COND), (US), 10, 10); \
> -	else \
> -		ret__ = _wait_for_atomic((COND), (US), 0); \
> -	ret__; \
> -})
> -
> -#define wait_for_atomic_us(COND, US) \
> -({ \
> -	BUILD_BUG_ON(!__builtin_constant_p(US)); \
> -	BUILD_BUG_ON((US) > 50000); \
> -	_wait_for_atomic((COND), (US), 1); \
> -})
> -
> -#define wait_for_atomic(COND, MS) wait_for_atomic_us((COND), (MS) * 1000)
> -
>  #define KHz(x) (1000 * (x))
>  #define MHz(x) KHz(1000 * (x))
>  
> diff --git a/drivers/gpu/drm/i915/i915_wait_util.h b/drivers/gpu/drm/i915/i915_wait_util.h
> new file mode 100644
> index 000000000000..7376898e3bf8
> --- /dev/null
> +++ b/drivers/gpu/drm/i915/i915_wait_util.h
> @@ -0,0 +1,119 @@
> +/* SPDX-License-Identifier: MIT */
> +/* Copyright © 2025 Intel Corporation */
> +
> +#ifndef __I915_WAIT_UTIL_H__
> +#define __I915_WAIT_UTIL_H__
> +
> +#include <linux/compiler.h>
> +#include <linux/delay.h>
> +#include <linux/ktime.h>
> +#include <linux/sched/clock.h>
> +#include <linux/smp.h>
> +
> +/*
> + * __wait_for - magic wait macro
> + *
> + * Macro to help avoid open coding check/wait/timeout patterns. Note that it's
> + * important that we check the condition again after having timed out, since the
> + * timeout could be due to preemption or similar and we've never had a chance to
> + * check the condition before the timeout.
> + */
> +#define __wait_for(OP, COND, US, Wmin, Wmax) ({ \
> +	const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \
> +	long wait__ = (Wmin); /* recommended min for usleep is 10 us */	\
> +	int ret__;							\
> +	might_sleep();							\
> +	for (;;) {							\
> +		const bool expired__ = ktime_after(ktime_get_raw(), end__); \
> +		OP;							\
> +		/* Guarantee COND check prior to timeout */		\
> +		barrier();						\
> +		if (COND) {						\
> +			ret__ = 0;					\
> +			break;						\
> +		}							\
> +		if (expired__) {					\
> +			ret__ = -ETIMEDOUT;				\
> +			break;						\
> +		}							\
> +		usleep_range(wait__, wait__ * 2);			\
> +		if (wait__ < (Wmax))					\
> +			wait__ <<= 1;					\
> +	}								\
> +	ret__;								\
> +})
> +
> +#define _wait_for(COND, US, Wmin, Wmax)	__wait_for(, (COND), (US), (Wmin), \
> +						   (Wmax))
> +#define wait_for(COND, MS)		_wait_for((COND), (MS) * 1000, 10, 1000)
> +
> +/*
> + * If CONFIG_PREEMPT_COUNT is disabled, in_atomic() always reports false.
> + * On PREEMPT_RT the context isn't becoming atomic because it is used in an
> + * interrupt handler or because a spinlock_t is acquired. This leads to
> + * warnings which don't occur otherwise and therefore the check is disabled.
> + */
> +#if IS_ENABLED(CONFIG_DRM_I915_DEBUG) && IS_ENABLED(CONFIG_PREEMPT_COUNT) && !defined(CONFIG_PREEMPT_RT)
> +# define _WAIT_FOR_ATOMIC_CHECK(ATOMIC) WARN_ON_ONCE((ATOMIC) && !in_atomic())
> +#else
> +# define _WAIT_FOR_ATOMIC_CHECK(ATOMIC) do { } while (0)
> +#endif
> +
> +#define _wait_for_atomic(COND, US, ATOMIC) \
> +({ \
> +	int cpu, ret, timeout = (US) * 1000; \
> +	u64 base; \
> +	_WAIT_FOR_ATOMIC_CHECK(ATOMIC); \
> +	if (!(ATOMIC)) { \
> +		preempt_disable(); \
> +		cpu = smp_processor_id(); \
> +	} \
> +	base = local_clock(); \
> +	for (;;) { \
> +		u64 now = local_clock(); \
> +		if (!(ATOMIC)) \
> +			preempt_enable(); \
> +		/* Guarantee COND check prior to timeout */ \
> +		barrier(); \
> +		if (COND) { \
> +			ret = 0; \
> +			break; \
> +		} \
> +		if (now - base >= timeout) { \
> +			ret = -ETIMEDOUT; \
> +			break; \
> +		} \
> +		cpu_relax(); \
> +		if (!(ATOMIC)) { \
> +			preempt_disable(); \
> +			if (unlikely(cpu != smp_processor_id())) { \
> +				timeout -= now - base; \
> +				cpu = smp_processor_id(); \
> +				base = local_clock(); \
> +			} \
> +		} \
> +	} \
> +	ret; \
> +})
> +
> +#define wait_for_us(COND, US) \
> +({ \
> +	int ret__; \
> +	BUILD_BUG_ON(!__builtin_constant_p(US)); \
> +	if ((US) > 10) \
> +		ret__ = _wait_for((COND), (US), 10, 10); \
> +	else \
> +		ret__ = _wait_for_atomic((COND), (US), 0); \
> +	ret__; \
> +})
> +
> +#define wait_for_atomic_us(COND, US) \
> +({ \
> +	BUILD_BUG_ON(!__builtin_constant_p(US)); \
> +	BUILD_BUG_ON((US) > 50000); \
> +	_wait_for_atomic((COND), (US), 1); \
> +})
> +
> +#define wait_for_atomic(COND, MS) wait_for_atomic_us((COND), (MS) * 1000)
> +
> +#endif /* __I915_WAIT_UTIL_H__ */
> diff --git a/drivers/gpu/drm/i915/intel_pcode.c b/drivers/gpu/drm/i915/intel_pcode.c
> index 81da75108c60..55ffedad2490 100644
> --- a/drivers/gpu/drm/i915/intel_pcode.c
> +++ b/drivers/gpu/drm/i915/intel_pcode.c
> @@ -5,6 +5,7 @@
>  
>  #include "i915_drv.h"
>  #include "i915_reg.h"
> +#include "i915_wait_util.h"
>  #include "intel_pcode.h"
>  
>  static int gen6_check_mailbox_status(u32 mbox)
> diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c
> index 4ccba7c8ffb3..8cb59f8d1f4c 100644
> --- a/drivers/gpu/drm/i915/intel_uncore.c
> +++ b/drivers/gpu/drm/i915/intel_uncore.c
> @@ -21,19 +21,20 @@
>   * IN THE SOFTWARE.
>   */
>  
> -#include <drm/drm_managed.h>
>  #include <linux/pm_runtime.h>
>  
> -#include "display/intel_display_core.h"
> +#include <drm/drm_managed.h>
>  
> -#include "gt/intel_gt.h"
> +#include "display/intel_display_core.h"
>  #include "gt/intel_engine_regs.h"
> +#include "gt/intel_gt.h"
>  #include "gt/intel_gt_regs.h"
>  
>  #include "i915_drv.h"
>  #include "i915_iosf_mbi.h"
>  #include "i915_reg.h"
>  #include "i915_vgpu.h"
> +#include "i915_wait_util.h"
>  #include "intel_uncore_trace.h"
>  
>  #define FORCEWAKE_ACK_TIMEOUT_MS 50
> diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp.c b/drivers/gpu/drm/i915/pxp/intel_pxp.c
> index f8da693ad3ce..27d545c4e6a5 100644
> --- a/drivers/gpu/drm/i915/pxp/intel_pxp.c
> +++ b/drivers/gpu/drm/i915/pxp/intel_pxp.c
> @@ -2,15 +2,15 @@
>  /*
>   * Copyright(c) 2020 Intel Corporation.
>   */
> +
>  #include <linux/workqueue.h>
>  
>  #include "gem/i915_gem_context.h"
> -
>  #include "gt/intel_context.h"
>  #include "gt/intel_gt.h"
>  
>  #include "i915_drv.h"
> -
> +#include "i915_wait_util.h"
>  #include "intel_pxp.h"
>  #include "intel_pxp_gsccs.h"
>  #include "intel_pxp_irq.h"
> diff --git a/drivers/gpu/drm/i915/selftests/i915_request.c b/drivers/gpu/drm/i915/selftests/i915_request.c
> index 2fb7a9e7efec..48cd617247d1 100644
> --- a/drivers/gpu/drm/i915/selftests/i915_request.c
> +++ b/drivers/gpu/drm/i915/selftests/i915_request.c
> @@ -22,14 +22,13 @@
>   *
>   */
>  
> -#include <linux/prime_numbers.h>
>  #include <linux/pm_qos.h>
> +#include <linux/prime_numbers.h>
>  #include <linux/sort.h>
>  
>  #include "gem/i915_gem_internal.h"
>  #include "gem/i915_gem_pm.h"
>  #include "gem/selftests/mock_context.h"
> -
>  #include "gt/intel_engine_heartbeat.h"
>  #include "gt/intel_engine_pm.h"
>  #include "gt/intel_engine_user.h"
> @@ -40,11 +39,11 @@
>  
>  #include "i915_random.h"
>  #include "i915_selftest.h"
> +#include "i915_wait_util.h"
>  #include "igt_flush_test.h"
>  #include "igt_live_test.h"
>  #include "igt_spinner.h"
>  #include "lib_sw_fence.h"
> -
>  #include "mock_drm.h"
>  #include "mock_gem_device.h"
>  
> diff --git a/drivers/gpu/drm/i915/selftests/i915_selftest.c b/drivers/gpu/drm/i915/selftests/i915_selftest.c
> index 889281819c5b..9c276c9d0a75 100644
> --- a/drivers/gpu/drm/i915/selftests/i915_selftest.c
> +++ b/drivers/gpu/drm/i915/selftests/i915_selftest.c
> @@ -31,7 +31,7 @@
>  #include "i915_driver.h"
>  #include "i915_drv.h"
>  #include "i915_selftest.h"
> -
> +#include "i915_wait_util.h"
>  #include "igt_flush_test.h"
>  
>  struct i915_selftest i915_selftest __read_mostly = {
> diff --git a/drivers/gpu/drm/i915/selftests/igt_spinner.c b/drivers/gpu/drm/i915/selftests/igt_spinner.c
> index 8c3e1f20e5a1..820364171ebe 100644
> --- a/drivers/gpu/drm/i915/selftests/igt_spinner.c
> +++ b/drivers/gpu/drm/i915/selftests/igt_spinner.c
> @@ -3,12 +3,13 @@
>   *
>   * Copyright © 2018 Intel Corporation
>   */
> -#include "gt/intel_gpu_commands.h"
> -#include "gt/intel_gt.h"
>  
>  #include "gem/i915_gem_internal.h"
>  #include "gem/selftests/igt_gem_utils.h"
> +#include "gt/intel_gpu_commands.h"
> +#include "gt/intel_gt.h"
>  
> +#include "i915_wait_util.h"
>  #include "igt_spinner.h"
>  
>  int igt_spinner_init(struct igt_spinner *spin, struct intel_gt *gt)
> diff --git a/drivers/gpu/drm/i915/vlv_suspend.c b/drivers/gpu/drm/i915/vlv_suspend.c
> index fc9f311ea1db..221e4c0b2c58 100644
> --- a/drivers/gpu/drm/i915/vlv_suspend.c
> +++ b/drivers/gpu/drm/i915/vlv_suspend.c
> @@ -8,16 +8,17 @@
>  
>  #include <drm/drm_print.h>
>  
> +#include "gt/intel_gt_regs.h"
> +
>  #include "i915_drv.h"
>  #include "i915_reg.h"
>  #include "i915_trace.h"
>  #include "i915_utils.h"
> +#include "i915_wait_util.h"
>  #include "intel_clock_gating.h"
>  #include "intel_uncore_trace.h"
>  #include "vlv_suspend.h"
>  
> -#include "gt/intel_gt_regs.h"
> -
>  struct vlv_s0ix_state {
>  	/* GAM */
>  	u32 wr_watermark;
> -- 
> 2.47.3
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 5/5] drm/i915: split out i915_wait_util.h
  2025-09-09 13:40   ` Rodrigo Vivi
@ 2025-09-10 12:06     ` Jani Nikula
  2025-09-10 16:45       ` Rodrigo Vivi
  0 siblings, 1 reply; 14+ messages in thread
From: Jani Nikula @ 2025-09-10 12:06 UTC (permalink / raw)
  To: Rodrigo Vivi; +Cc: intel-gfx

On Tue, 09 Sep 2025, Rodrigo Vivi <rodrigo.vivi@intel.com> wrote:
> On Mon, Sep 08, 2025 at 05:11:49PM +0300, Jani Nikula wrote:
>> Move waiting related utilities from i915_utils.h to separate new file
>> i915_wait_util.h. Clean up related includes.
>> 
>> Note: Many of the various wait macro usages could likely be refactored
>> to use poll_timeout_us().
>
> I hope so! :)
>
> nice clean up overall, although my dream is that we
> could get rid entirely of these utils that pretend
> they are core kernel.
>
> Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

Thanks, but no dice. :(

I didn't realize GEM_BUG_ON() uses GEM_TRACE_DUMP() uses
__add_taint_for_CI(), i.e. roughly everything requires i915_utils.h.

Maybe I'll post just some of these and drop patch 1.

BR,
Jani.




>
>
>> 
>> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
>> ---
>>  .../drm/i915/gt/intel_execlists_submission.c  |   1 +
>>  drivers/gpu/drm/i915/gt/intel_gt_mcr.c        |   1 +
>>  drivers/gpu/drm/i915/gt/intel_reset.c         |   7 +-
>>  .../gpu/drm/i915/gt/intel_ring_submission.c   |   7 +-
>>  drivers/gpu/drm/i915/gt/intel_rps.c           |   2 +
>>  drivers/gpu/drm/i915/gt/selftest_tlb.c        |   6 +-
>>  drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c  |   6 +-
>>  .../i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c |   2 +
>>  drivers/gpu/drm/i915/gt/uc/intel_guc.c        |   8 +-
>>  drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c     |   3 +-
>>  drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c     |   4 +-
>>  drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c   |  13 +-
>>  .../gpu/drm/i915/gt/uc/intel_guc_submission.c |  10 +-
>>  drivers/gpu/drm/i915/gvt/mmio_context.c       |   6 +-
>>  drivers/gpu/drm/i915/i915_debugfs.c           |   3 +-
>>  drivers/gpu/drm/i915/i915_utils.h             | 106 ----------------
>>  drivers/gpu/drm/i915/i915_wait_util.h         | 119 ++++++++++++++++++
>>  drivers/gpu/drm/i915/intel_pcode.c            |   1 +
>>  drivers/gpu/drm/i915/intel_uncore.c           |   7 +-
>>  drivers/gpu/drm/i915/pxp/intel_pxp.c          |   4 +-
>>  drivers/gpu/drm/i915/selftests/i915_request.c |   5 +-
>>  .../gpu/drm/i915/selftests/i915_selftest.c    |   2 +-
>>  drivers/gpu/drm/i915/selftests/igt_spinner.c  |   5 +-
>>  drivers/gpu/drm/i915/vlv_suspend.c            |   5 +-
>>  24 files changed, 183 insertions(+), 150 deletions(-)
>>  create mode 100644 drivers/gpu/drm/i915/i915_wait_util.h
>> 
>> diff --git a/drivers/gpu/drm/i915/gt/intel_execlists_submission.c b/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
>> index 0c1b2df02d26..7f389cb0bde4 100644
>> --- a/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
>> +++ b/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
>> @@ -117,6 +117,7 @@
>>  #include "i915_timer_util.h"
>>  #include "i915_trace.h"
>>  #include "i915_vgpu.h"
>> +#include "i915_wait_util.h"
>>  #include "intel_breadcrumbs.h"
>>  #include "intel_context.h"
>>  #include "intel_engine_heartbeat.h"
>> diff --git a/drivers/gpu/drm/i915/gt/intel_gt_mcr.c b/drivers/gpu/drm/i915/gt/intel_gt_mcr.c
>> index a60822e2b5d4..c3afa321fe30 100644
>> --- a/drivers/gpu/drm/i915/gt/intel_gt_mcr.c
>> +++ b/drivers/gpu/drm/i915/gt/intel_gt_mcr.c
>> @@ -4,6 +4,7 @@
>>   */
>>  
>>  #include "i915_drv.h"
>> +#include "i915_wait_util.h"
>>  #include "intel_gt.h"
>>  #include "intel_gt_mcr.h"
>>  #include "intel_gt_print.h"
>> diff --git a/drivers/gpu/drm/i915/gt/intel_reset.c b/drivers/gpu/drm/i915/gt/intel_reset.c
>> index 4a1675dea1c7..41b5036dc538 100644
>> --- a/drivers/gpu/drm/i915/gt/intel_reset.c
>> +++ b/drivers/gpu/drm/i915/gt/intel_reset.c
>> @@ -9,18 +9,17 @@
>>  
>>  #include "display/intel_display_reset.h"
>>  #include "display/intel_overlay.h"
>> -
>>  #include "gem/i915_gem_context.h"
>> -
>>  #include "gt/intel_gt_regs.h"
>> -
>>  #include "gt/uc/intel_gsc_fw.h"
>> +#include "uc/intel_guc.h"
>>  
>>  #include "i915_drv.h"
>>  #include "i915_file_private.h"
>>  #include "i915_gpu_error.h"
>>  #include "i915_irq.h"
>>  #include "i915_reg.h"
>> +#include "i915_wait_util.h"
>>  #include "intel_breadcrumbs.h"
>>  #include "intel_engine_pm.h"
>>  #include "intel_engine_regs.h"
>> @@ -32,8 +31,6 @@
>>  #include "intel_pci_config.h"
>>  #include "intel_reset.h"
>>  
>> -#include "uc/intel_guc.h"
>> -
>>  #define RESET_MAX_RETRIES 3
>>  
>>  static void client_mark_guilty(struct i915_gem_context *ctx, bool banned)
>> diff --git a/drivers/gpu/drm/i915/gt/intel_ring_submission.c b/drivers/gpu/drm/i915/gt/intel_ring_submission.c
>> index 2a6d79abf25b..8314a4b0505e 100644
>> --- a/drivers/gpu/drm/i915/gt/intel_ring_submission.c
>> +++ b/drivers/gpu/drm/i915/gt/intel_ring_submission.c
>> @@ -15,18 +15,19 @@
>>  #include "i915_irq.h"
>>  #include "i915_mitigations.h"
>>  #include "i915_reg.h"
>> +#include "i915_wait_util.h"
>>  #include "intel_breadcrumbs.h"
>>  #include "intel_context.h"
>> +#include "intel_engine_heartbeat.h"
>> +#include "intel_engine_pm.h"
>>  #include "intel_engine_regs.h"
>>  #include "intel_gt.h"
>>  #include "intel_gt_irq.h"
>> +#include "intel_gt_print.h"
>>  #include "intel_gt_regs.h"
>>  #include "intel_reset.h"
>>  #include "intel_ring.h"
>>  #include "shmem_utils.h"
>> -#include "intel_engine_heartbeat.h"
>> -#include "intel_engine_pm.h"
>> -#include "intel_gt_print.h"
>>  
>>  /* Rough estimate of the typical request size, performing a flush,
>>   * set-context and then emitting the batch.
>> diff --git a/drivers/gpu/drm/i915/gt/intel_rps.c b/drivers/gpu/drm/i915/gt/intel_rps.c
>> index 006042e0b229..4da94098bd3e 100644
>> --- a/drivers/gpu/drm/i915/gt/intel_rps.c
>> +++ b/drivers/gpu/drm/i915/gt/intel_rps.c
>> @@ -10,9 +10,11 @@
>>  #include "display/intel_display.h"
>>  #include "display/intel_display_rps.h"
>>  #include "soc/intel_dram.h"
>> +
>>  #include "i915_drv.h"
>>  #include "i915_irq.h"
>>  #include "i915_reg.h"
>> +#include "i915_wait_util.h"
>>  #include "intel_breadcrumbs.h"
>>  #include "intel_gt.h"
>>  #include "intel_gt_clock_utils.h"
>> diff --git a/drivers/gpu/drm/i915/gt/selftest_tlb.c b/drivers/gpu/drm/i915/gt/selftest_tlb.c
>> index 69ed946a39e5..a5184f09d1de 100644
>> --- a/drivers/gpu/drm/i915/gt/selftest_tlb.c
>> +++ b/drivers/gpu/drm/i915/gt/selftest_tlb.c
>> @@ -3,17 +3,17 @@
>>   * Copyright © 2022 Intel Corporation
>>   */
>>  
>> -#include "i915_selftest.h"
>> -
>>  #include "gem/i915_gem_internal.h"
>>  #include "gem/i915_gem_lmem.h"
>>  #include "gem/i915_gem_region.h"
>>  
>>  #include "gen8_engine_cs.h"
>>  #include "i915_gem_ww.h"
>> +#include "i915_selftest.h"
>> +#include "i915_wait_util.h"
>> +#include "intel_context.h"
>>  #include "intel_engine_regs.h"
>>  #include "intel_gpu_commands.h"
>> -#include "intel_context.h"
>>  #include "intel_gt.h"
>>  #include "intel_ring.h"
>>  
>> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c b/drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c
>> index d8edd7c054c8..e7444ebc373e 100644
>> --- a/drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c
>> +++ b/drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c
>> @@ -10,11 +10,13 @@
>>  
>>  #include "gt/intel_gt.h"
>>  #include "gt/intel_gt_print.h"
>> +
>> +#include "i915_drv.h"
>> +#include "i915_reg.h"
>> +#include "i915_wait_util.h"
>>  #include "intel_gsc_proxy.h"
>>  #include "intel_gsc_uc.h"
>>  #include "intel_gsc_uc_heci_cmd_submit.h"
>> -#include "i915_drv.h"
>> -#include "i915_reg.h"
>>  
>>  /*
>>   * GSC proxy:
>> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c b/drivers/gpu/drm/i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c
>> index 2fde5c360cff..9bd29be7656f 100644
>> --- a/drivers/gpu/drm/i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c
>> +++ b/drivers/gpu/drm/i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c
>> @@ -8,6 +8,8 @@
>>  #include "gt/intel_gpu_commands.h"
>>  #include "gt/intel_gt.h"
>>  #include "gt/intel_ring.h"
>> +
>> +#include "i915_wait_util.h"
>>  #include "intel_gsc_uc_heci_cmd_submit.h"
>>  
>>  struct gsc_heci_pkt {
>> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc.c b/drivers/gpu/drm/i915/gt/uc/intel_guc.c
>> index f360f020d8f1..52ec4421a211 100644
>> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc.c
>> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc.c
>> @@ -8,15 +8,17 @@
>>  #include "gt/intel_gt_irq.h"
>>  #include "gt/intel_gt_pm_irq.h"
>>  #include "gt/intel_gt_regs.h"
>> +
>> +#include "i915_drv.h"
>> +#include "i915_irq.h"
>> +#include "i915_reg.h"
>> +#include "i915_wait_util.h"
>>  #include "intel_guc.h"
>>  #include "intel_guc_ads.h"
>>  #include "intel_guc_capture.h"
>>  #include "intel_guc_print.h"
>>  #include "intel_guc_slpc.h"
>>  #include "intel_guc_submission.h"
>> -#include "i915_drv.h"
>> -#include "i915_irq.h"
>> -#include "i915_reg.h"
>>  
>>  /**
>>   * DOC: GuC
>> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c
>> index 380a11c92d63..3e7e5badcc2b 100644
>> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c
>> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c
>> @@ -5,11 +5,12 @@
>>  
>>  #include <linux/circ_buf.h>
>>  #include <linux/ktime.h>
>> -#include <linux/time64.h>
>>  #include <linux/string_helpers.h>
>> +#include <linux/time64.h>
>>  #include <linux/timekeeping.h>
>>  
>>  #include "i915_drv.h"
>> +#include "i915_wait_util.h"
>>  #include "intel_guc_ct.h"
>>  #include "intel_guc_print.h"
>>  
>> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c
>> index e7ccfa520df3..1bb1491f90fc 100644
>> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c
>> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c
>> @@ -13,9 +13,11 @@
>>  #include "gt/intel_gt_mcr.h"
>>  #include "gt/intel_gt_regs.h"
>>  #include "gt/intel_rps.h"
>> +
>> +#include "i915_drv.h"
>> +#include "i915_wait_util.h"
>>  #include "intel_guc_fw.h"
>>  #include "intel_guc_print.h"
>> -#include "i915_drv.h"
>>  
>>  static void guc_prepare_xfer(struct intel_gt *gt)
>>  {
>> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c
>> index d5ee6e5e1443..fa9af08f9708 100644
>> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c
>> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c
>> @@ -3,17 +3,20 @@
>>   * Copyright © 2021 Intel Corporation
>>   */
>>  
>> -#include <drm/drm_cache.h>
>>  #include <linux/string_helpers.h>
>>  
>> +#include <drm/drm_cache.h>
>> +
>> +#include "gt/intel_gt.h"
>> +#include "gt/intel_gt_regs.h"
>> +#include "gt/intel_rps.h"
>> +
>>  #include "i915_drv.h"
>>  #include "i915_reg.h"
>> -#include "intel_guc_slpc.h"
>> +#include "i915_wait_util.h"
>>  #include "intel_guc_print.h"
>> +#include "intel_guc_slpc.h"
>>  #include "intel_mchbar_regs.h"
>> -#include "gt/intel_gt.h"
>> -#include "gt/intel_gt_regs.h"
>> -#include "gt/intel_rps.h"
>>  
>>  /**
>>   * DOC: SLPC - Dynamic Frequency management
>> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
>> index 127316d2c8aa..68f2b8d363ac 100644
>> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
>> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
>> @@ -25,16 +25,16 @@
>>  #include "gt/intel_mocs.h"
>>  #include "gt/intel_ring.h"
>>  
>> +#include "i915_drv.h"
>> +#include "i915_irq.h"
>> +#include "i915_reg.h"
>> +#include "i915_trace.h"
>> +#include "i915_wait_util.h"
>>  #include "intel_guc_ads.h"
>>  #include "intel_guc_capture.h"
>>  #include "intel_guc_print.h"
>>  #include "intel_guc_submission.h"
>>  
>> -#include "i915_drv.h"
>> -#include "i915_reg.h"
>> -#include "i915_irq.h"
>> -#include "i915_trace.h"
>> -
>>  /**
>>   * DOC: GuC-based command submission
>>   *
>> diff --git a/drivers/gpu/drm/i915/gvt/mmio_context.c b/drivers/gpu/drm/i915/gvt/mmio_context.c
>> index 2f7208843367..0b810baad20a 100644
>> --- a/drivers/gpu/drm/i915/gvt/mmio_context.c
>> +++ b/drivers/gpu/drm/i915/gvt/mmio_context.c
>> @@ -33,14 +33,16 @@
>>   *
>>   */
>>  
>> -#include "i915_drv.h"
>> -#include "i915_reg.h"
>>  #include "gt/intel_context.h"
>>  #include "gt/intel_engine_regs.h"
>>  #include "gt/intel_gpu_commands.h"
>>  #include "gt/intel_gt_regs.h"
>>  #include "gt/intel_ring.h"
>> +
>>  #include "gvt.h"
>> +#include "i915_drv.h"
>> +#include "i915_reg.h"
>> +#include "i915_wait_util.h"
>>  #include "trace.h"
>>  
>>  #define GEN9_MOCS_SIZE		64
>> diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
>> index 23fa098c4479..c2e38d4bcd01 100644
>> --- a/drivers/gpu/drm/i915/i915_debugfs.c
>> +++ b/drivers/gpu/drm/i915/i915_debugfs.c
>> @@ -26,11 +26,11 @@
>>   *
>>   */
>>  
>> +#include <linux/debugfs.h>
>>  #include <linux/sched/mm.h>
>>  #include <linux/sort.h>
>>  #include <linux/string_helpers.h>
>>  
>> -#include <linux/debugfs.h>
>>  #include <drm/drm_debugfs.h>
>>  
>>  #include "gem/i915_gem_context.h"
>> @@ -54,6 +54,7 @@
>>  #include "i915_irq.h"
>>  #include "i915_reg.h"
>>  #include "i915_scheduler.h"
>> +#include "i915_wait_util.h"
>>  #include "intel_mchbar_regs.h"
>>  
>>  static inline struct drm_i915_private *node_to_i915(struct drm_info_node *node)
>> diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
>> index 4a6437d6e00e..a0c892e4c40d 100644
>> --- a/drivers/gpu/drm/i915/i915_utils.h
>> +++ b/drivers/gpu/drm/i915/i915_utils.h
>> @@ -134,112 +134,6 @@ wait_remaining_ms_from_jiffies(unsigned long timestamp_jiffies, int to_wait_ms)
>>  	}
>>  }
>>  
>> -/*
>> - * __wait_for - magic wait macro
>> - *
>> - * Macro to help avoid open coding check/wait/timeout patterns. Note that it's
>> - * important that we check the condition again after having timed out, since the
>> - * timeout could be due to preemption or similar and we've never had a chance to
>> - * check the condition before the timeout.
>> - */
>> -#define __wait_for(OP, COND, US, Wmin, Wmax) ({ \
>> -	const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \
>> -	long wait__ = (Wmin); /* recommended min for usleep is 10 us */	\
>> -	int ret__;							\
>> -	might_sleep();							\
>> -	for (;;) {							\
>> -		const bool expired__ = ktime_after(ktime_get_raw(), end__); \
>> -		OP;							\
>> -		/* Guarantee COND check prior to timeout */		\
>> -		barrier();						\
>> -		if (COND) {						\
>> -			ret__ = 0;					\
>> -			break;						\
>> -		}							\
>> -		if (expired__) {					\
>> -			ret__ = -ETIMEDOUT;				\
>> -			break;						\
>> -		}							\
>> -		usleep_range(wait__, wait__ * 2);			\
>> -		if (wait__ < (Wmax))					\
>> -			wait__ <<= 1;					\
>> -	}								\
>> -	ret__;								\
>> -})
>> -
>> -#define _wait_for(COND, US, Wmin, Wmax)	__wait_for(, (COND), (US), (Wmin), \
>> -						   (Wmax))
>> -#define wait_for(COND, MS)		_wait_for((COND), (MS) * 1000, 10, 1000)
>> -
>> -/*
>> - * If CONFIG_PREEMPT_COUNT is disabled, in_atomic() always reports false.
>> - * On PREEMPT_RT the context isn't becoming atomic because it is used in an
>> - * interrupt handler or because a spinlock_t is acquired. This leads to
>> - * warnings which don't occur otherwise and therefore the check is disabled.
>> - */
>> -#if IS_ENABLED(CONFIG_DRM_I915_DEBUG) && IS_ENABLED(CONFIG_PREEMPT_COUNT) && !defined(CONFIG_PREEMPT_RT)
>> -# define _WAIT_FOR_ATOMIC_CHECK(ATOMIC) WARN_ON_ONCE((ATOMIC) && !in_atomic())
>> -#else
>> -# define _WAIT_FOR_ATOMIC_CHECK(ATOMIC) do { } while (0)
>> -#endif
>> -
>> -#define _wait_for_atomic(COND, US, ATOMIC) \
>> -({ \
>> -	int cpu, ret, timeout = (US) * 1000; \
>> -	u64 base; \
>> -	_WAIT_FOR_ATOMIC_CHECK(ATOMIC); \
>> -	if (!(ATOMIC)) { \
>> -		preempt_disable(); \
>> -		cpu = smp_processor_id(); \
>> -	} \
>> -	base = local_clock(); \
>> -	for (;;) { \
>> -		u64 now = local_clock(); \
>> -		if (!(ATOMIC)) \
>> -			preempt_enable(); \
>> -		/* Guarantee COND check prior to timeout */ \
>> -		barrier(); \
>> -		if (COND) { \
>> -			ret = 0; \
>> -			break; \
>> -		} \
>> -		if (now - base >= timeout) { \
>> -			ret = -ETIMEDOUT; \
>> -			break; \
>> -		} \
>> -		cpu_relax(); \
>> -		if (!(ATOMIC)) { \
>> -			preempt_disable(); \
>> -			if (unlikely(cpu != smp_processor_id())) { \
>> -				timeout -= now - base; \
>> -				cpu = smp_processor_id(); \
>> -				base = local_clock(); \
>> -			} \
>> -		} \
>> -	} \
>> -	ret; \
>> -})
>> -
>> -#define wait_for_us(COND, US) \
>> -({ \
>> -	int ret__; \
>> -	BUILD_BUG_ON(!__builtin_constant_p(US)); \
>> -	if ((US) > 10) \
>> -		ret__ = _wait_for((COND), (US), 10, 10); \
>> -	else \
>> -		ret__ = _wait_for_atomic((COND), (US), 0); \
>> -	ret__; \
>> -})
>> -
>> -#define wait_for_atomic_us(COND, US) \
>> -({ \
>> -	BUILD_BUG_ON(!__builtin_constant_p(US)); \
>> -	BUILD_BUG_ON((US) > 50000); \
>> -	_wait_for_atomic((COND), (US), 1); \
>> -})
>> -
>> -#define wait_for_atomic(COND, MS) wait_for_atomic_us((COND), (MS) * 1000)
>> -
>>  #define KHz(x) (1000 * (x))
>>  #define MHz(x) KHz(1000 * (x))
>>  
>> diff --git a/drivers/gpu/drm/i915/i915_wait_util.h b/drivers/gpu/drm/i915/i915_wait_util.h
>> new file mode 100644
>> index 000000000000..7376898e3bf8
>> --- /dev/null
>> +++ b/drivers/gpu/drm/i915/i915_wait_util.h
>> @@ -0,0 +1,119 @@
>> +/* SPDX-License-Identifier: MIT */
>> +/* Copyright © 2025 Intel Corporation */
>> +
>> +#ifndef __I915_WAIT_UTIL_H__
>> +#define __I915_WAIT_UTIL_H__
>> +
>> +#include <linux/compiler.h>
>> +#include <linux/delay.h>
>> +#include <linux/ktime.h>
>> +#include <linux/sched/clock.h>
>> +#include <linux/smp.h>
>> +
>> +/*
>> + * __wait_for - magic wait macro
>> + *
>> + * Macro to help avoid open coding check/wait/timeout patterns. Note that it's
>> + * important that we check the condition again after having timed out, since the
>> + * timeout could be due to preemption or similar and we've never had a chance to
>> + * check the condition before the timeout.
>> + */
>> +#define __wait_for(OP, COND, US, Wmin, Wmax) ({ \
>> +	const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \
>> +	long wait__ = (Wmin); /* recommended min for usleep is 10 us */	\
>> +	int ret__;							\
>> +	might_sleep();							\
>> +	for (;;) {							\
>> +		const bool expired__ = ktime_after(ktime_get_raw(), end__); \
>> +		OP;							\
>> +		/* Guarantee COND check prior to timeout */		\
>> +		barrier();						\
>> +		if (COND) {						\
>> +			ret__ = 0;					\
>> +			break;						\
>> +		}							\
>> +		if (expired__) {					\
>> +			ret__ = -ETIMEDOUT;				\
>> +			break;						\
>> +		}							\
>> +		usleep_range(wait__, wait__ * 2);			\
>> +		if (wait__ < (Wmax))					\
>> +			wait__ <<= 1;					\
>> +	}								\
>> +	ret__;								\
>> +})
>> +
>> +#define _wait_for(COND, US, Wmin, Wmax)	__wait_for(, (COND), (US), (Wmin), \
>> +						   (Wmax))
>> +#define wait_for(COND, MS)		_wait_for((COND), (MS) * 1000, 10, 1000)
>> +
>> +/*
>> + * If CONFIG_PREEMPT_COUNT is disabled, in_atomic() always reports false.
>> + * On PREEMPT_RT the context isn't becoming atomic because it is used in an
>> + * interrupt handler or because a spinlock_t is acquired. This leads to
>> + * warnings which don't occur otherwise and therefore the check is disabled.
>> + */
>> +#if IS_ENABLED(CONFIG_DRM_I915_DEBUG) && IS_ENABLED(CONFIG_PREEMPT_COUNT) && !defined(CONFIG_PREEMPT_RT)
>> +# define _WAIT_FOR_ATOMIC_CHECK(ATOMIC) WARN_ON_ONCE((ATOMIC) && !in_atomic())
>> +#else
>> +# define _WAIT_FOR_ATOMIC_CHECK(ATOMIC) do { } while (0)
>> +#endif
>> +
>> +#define _wait_for_atomic(COND, US, ATOMIC) \
>> +({ \
>> +	int cpu, ret, timeout = (US) * 1000; \
>> +	u64 base; \
>> +	_WAIT_FOR_ATOMIC_CHECK(ATOMIC); \
>> +	if (!(ATOMIC)) { \
>> +		preempt_disable(); \
>> +		cpu = smp_processor_id(); \
>> +	} \
>> +	base = local_clock(); \
>> +	for (;;) { \
>> +		u64 now = local_clock(); \
>> +		if (!(ATOMIC)) \
>> +			preempt_enable(); \
>> +		/* Guarantee COND check prior to timeout */ \
>> +		barrier(); \
>> +		if (COND) { \
>> +			ret = 0; \
>> +			break; \
>> +		} \
>> +		if (now - base >= timeout) { \
>> +			ret = -ETIMEDOUT; \
>> +			break; \
>> +		} \
>> +		cpu_relax(); \
>> +		if (!(ATOMIC)) { \
>> +			preempt_disable(); \
>> +			if (unlikely(cpu != smp_processor_id())) { \
>> +				timeout -= now - base; \
>> +				cpu = smp_processor_id(); \
>> +				base = local_clock(); \
>> +			} \
>> +		} \
>> +	} \
>> +	ret; \
>> +})
>> +
>> +#define wait_for_us(COND, US) \
>> +({ \
>> +	int ret__; \
>> +	BUILD_BUG_ON(!__builtin_constant_p(US)); \
>> +	if ((US) > 10) \
>> +		ret__ = _wait_for((COND), (US), 10, 10); \
>> +	else \
>> +		ret__ = _wait_for_atomic((COND), (US), 0); \
>> +	ret__; \
>> +})
>> +
>> +#define wait_for_atomic_us(COND, US) \
>> +({ \
>> +	BUILD_BUG_ON(!__builtin_constant_p(US)); \
>> +	BUILD_BUG_ON((US) > 50000); \
>> +	_wait_for_atomic((COND), (US), 1); \
>> +})
>> +
>> +#define wait_for_atomic(COND, MS) wait_for_atomic_us((COND), (MS) * 1000)
>> +
>> +#endif /* __I915_WAIT_UTIL_H__ */
>> diff --git a/drivers/gpu/drm/i915/intel_pcode.c b/drivers/gpu/drm/i915/intel_pcode.c
>> index 81da75108c60..55ffedad2490 100644
>> --- a/drivers/gpu/drm/i915/intel_pcode.c
>> +++ b/drivers/gpu/drm/i915/intel_pcode.c
>> @@ -5,6 +5,7 @@
>>  
>>  #include "i915_drv.h"
>>  #include "i915_reg.h"
>> +#include "i915_wait_util.h"
>>  #include "intel_pcode.h"
>>  
>>  static int gen6_check_mailbox_status(u32 mbox)
>> diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c
>> index 4ccba7c8ffb3..8cb59f8d1f4c 100644
>> --- a/drivers/gpu/drm/i915/intel_uncore.c
>> +++ b/drivers/gpu/drm/i915/intel_uncore.c
>> @@ -21,19 +21,20 @@
>>   * IN THE SOFTWARE.
>>   */
>>  
>> -#include <drm/drm_managed.h>
>>  #include <linux/pm_runtime.h>
>>  
>> -#include "display/intel_display_core.h"
>> +#include <drm/drm_managed.h>
>>  
>> -#include "gt/intel_gt.h"
>> +#include "display/intel_display_core.h"
>>  #include "gt/intel_engine_regs.h"
>> +#include "gt/intel_gt.h"
>>  #include "gt/intel_gt_regs.h"
>>  
>>  #include "i915_drv.h"
>>  #include "i915_iosf_mbi.h"
>>  #include "i915_reg.h"
>>  #include "i915_vgpu.h"
>> +#include "i915_wait_util.h"
>>  #include "intel_uncore_trace.h"
>>  
>>  #define FORCEWAKE_ACK_TIMEOUT_MS 50
>> diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp.c b/drivers/gpu/drm/i915/pxp/intel_pxp.c
>> index f8da693ad3ce..27d545c4e6a5 100644
>> --- a/drivers/gpu/drm/i915/pxp/intel_pxp.c
>> +++ b/drivers/gpu/drm/i915/pxp/intel_pxp.c
>> @@ -2,15 +2,15 @@
>>  /*
>>   * Copyright(c) 2020 Intel Corporation.
>>   */
>> +
>>  #include <linux/workqueue.h>
>>  
>>  #include "gem/i915_gem_context.h"
>> -
>>  #include "gt/intel_context.h"
>>  #include "gt/intel_gt.h"
>>  
>>  #include "i915_drv.h"
>> -
>> +#include "i915_wait_util.h"
>>  #include "intel_pxp.h"
>>  #include "intel_pxp_gsccs.h"
>>  #include "intel_pxp_irq.h"
>> diff --git a/drivers/gpu/drm/i915/selftests/i915_request.c b/drivers/gpu/drm/i915/selftests/i915_request.c
>> index 2fb7a9e7efec..48cd617247d1 100644
>> --- a/drivers/gpu/drm/i915/selftests/i915_request.c
>> +++ b/drivers/gpu/drm/i915/selftests/i915_request.c
>> @@ -22,14 +22,13 @@
>>   *
>>   */
>>  
>> -#include <linux/prime_numbers.h>
>>  #include <linux/pm_qos.h>
>> +#include <linux/prime_numbers.h>
>>  #include <linux/sort.h>
>>  
>>  #include "gem/i915_gem_internal.h"
>>  #include "gem/i915_gem_pm.h"
>>  #include "gem/selftests/mock_context.h"
>> -
>>  #include "gt/intel_engine_heartbeat.h"
>>  #include "gt/intel_engine_pm.h"
>>  #include "gt/intel_engine_user.h"
>> @@ -40,11 +39,11 @@
>>  
>>  #include "i915_random.h"
>>  #include "i915_selftest.h"
>> +#include "i915_wait_util.h"
>>  #include "igt_flush_test.h"
>>  #include "igt_live_test.h"
>>  #include "igt_spinner.h"
>>  #include "lib_sw_fence.h"
>> -
>>  #include "mock_drm.h"
>>  #include "mock_gem_device.h"
>>  
>> diff --git a/drivers/gpu/drm/i915/selftests/i915_selftest.c b/drivers/gpu/drm/i915/selftests/i915_selftest.c
>> index 889281819c5b..9c276c9d0a75 100644
>> --- a/drivers/gpu/drm/i915/selftests/i915_selftest.c
>> +++ b/drivers/gpu/drm/i915/selftests/i915_selftest.c
>> @@ -31,7 +31,7 @@
>>  #include "i915_driver.h"
>>  #include "i915_drv.h"
>>  #include "i915_selftest.h"
>> -
>> +#include "i915_wait_util.h"
>>  #include "igt_flush_test.h"
>>  
>>  struct i915_selftest i915_selftest __read_mostly = {
>> diff --git a/drivers/gpu/drm/i915/selftests/igt_spinner.c b/drivers/gpu/drm/i915/selftests/igt_spinner.c
>> index 8c3e1f20e5a1..820364171ebe 100644
>> --- a/drivers/gpu/drm/i915/selftests/igt_spinner.c
>> +++ b/drivers/gpu/drm/i915/selftests/igt_spinner.c
>> @@ -3,12 +3,13 @@
>>   *
>>   * Copyright © 2018 Intel Corporation
>>   */
>> -#include "gt/intel_gpu_commands.h"
>> -#include "gt/intel_gt.h"
>>  
>>  #include "gem/i915_gem_internal.h"
>>  #include "gem/selftests/igt_gem_utils.h"
>> +#include "gt/intel_gpu_commands.h"
>> +#include "gt/intel_gt.h"
>>  
>> +#include "i915_wait_util.h"
>>  #include "igt_spinner.h"
>>  
>>  int igt_spinner_init(struct igt_spinner *spin, struct intel_gt *gt)
>> diff --git a/drivers/gpu/drm/i915/vlv_suspend.c b/drivers/gpu/drm/i915/vlv_suspend.c
>> index fc9f311ea1db..221e4c0b2c58 100644
>> --- a/drivers/gpu/drm/i915/vlv_suspend.c
>> +++ b/drivers/gpu/drm/i915/vlv_suspend.c
>> @@ -8,16 +8,17 @@
>>  
>>  #include <drm/drm_print.h>
>>  
>> +#include "gt/intel_gt_regs.h"
>> +
>>  #include "i915_drv.h"
>>  #include "i915_reg.h"
>>  #include "i915_trace.h"
>>  #include "i915_utils.h"
>> +#include "i915_wait_util.h"
>>  #include "intel_clock_gating.h"
>>  #include "intel_uncore_trace.h"
>>  #include "vlv_suspend.h"
>>  
>> -#include "gt/intel_gt_regs.h"
>> -
>>  struct vlv_s0ix_state {
>>  	/* GAM */
>>  	u32 wr_watermark;
>> -- 
>> 2.47.3
>> 

-- 
Jani Nikula, Intel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 5/5] drm/i915: split out i915_wait_util.h
  2025-09-10 12:06     ` Jani Nikula
@ 2025-09-10 16:45       ` Rodrigo Vivi
  0 siblings, 0 replies; 14+ messages in thread
From: Rodrigo Vivi @ 2025-09-10 16:45 UTC (permalink / raw)
  To: Jani Nikula; +Cc: intel-gfx

On Wed, Sep 10, 2025 at 03:06:56PM +0300, Jani Nikula wrote:
> On Tue, 09 Sep 2025, Rodrigo Vivi <rodrigo.vivi@intel.com> wrote:
> > On Mon, Sep 08, 2025 at 05:11:49PM +0300, Jani Nikula wrote:
> >> Move waiting related utilities from i915_utils.h to separate new file
> >> i915_wait_util.h. Clean up related includes.
> >> 
> >> Note: Many of the various wait macro usages could likely be refactored
> >> to use poll_timeout_us().
> >
> > I hope so! :)
> >
> > nice clean up overall, although my dream is that we
> > could get rid entirely of these utils that pretend
> > they are core kernel.
> >
> > Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> 
> Thanks, but no dice. :(
> 
> I didn't realize GEM_BUG_ON() uses GEM_TRACE_DUMP() uses

sorry for missing that too

> __add_taint_for_CI(), i.e. 
> roughly everything requires i915_utils.h.
> 

(facepalm)...

> Maybe I'll post just some of these and drop patch 1.

already a good start anyway ;)

> 
> BR,
> Jani.
> 
> 
> 
> 
> >
> >
> >> 
> >> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> >> ---
> >>  .../drm/i915/gt/intel_execlists_submission.c  |   1 +
> >>  drivers/gpu/drm/i915/gt/intel_gt_mcr.c        |   1 +
> >>  drivers/gpu/drm/i915/gt/intel_reset.c         |   7 +-
> >>  .../gpu/drm/i915/gt/intel_ring_submission.c   |   7 +-
> >>  drivers/gpu/drm/i915/gt/intel_rps.c           |   2 +
> >>  drivers/gpu/drm/i915/gt/selftest_tlb.c        |   6 +-
> >>  drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c  |   6 +-
> >>  .../i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c |   2 +
> >>  drivers/gpu/drm/i915/gt/uc/intel_guc.c        |   8 +-
> >>  drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c     |   3 +-
> >>  drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c     |   4 +-
> >>  drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c   |  13 +-
> >>  .../gpu/drm/i915/gt/uc/intel_guc_submission.c |  10 +-
> >>  drivers/gpu/drm/i915/gvt/mmio_context.c       |   6 +-
> >>  drivers/gpu/drm/i915/i915_debugfs.c           |   3 +-
> >>  drivers/gpu/drm/i915/i915_utils.h             | 106 ----------------
> >>  drivers/gpu/drm/i915/i915_wait_util.h         | 119 ++++++++++++++++++
> >>  drivers/gpu/drm/i915/intel_pcode.c            |   1 +
> >>  drivers/gpu/drm/i915/intel_uncore.c           |   7 +-
> >>  drivers/gpu/drm/i915/pxp/intel_pxp.c          |   4 +-
> >>  drivers/gpu/drm/i915/selftests/i915_request.c |   5 +-
> >>  .../gpu/drm/i915/selftests/i915_selftest.c    |   2 +-
> >>  drivers/gpu/drm/i915/selftests/igt_spinner.c  |   5 +-
> >>  drivers/gpu/drm/i915/vlv_suspend.c            |   5 +-
> >>  24 files changed, 183 insertions(+), 150 deletions(-)
> >>  create mode 100644 drivers/gpu/drm/i915/i915_wait_util.h
> >> 
> >> diff --git a/drivers/gpu/drm/i915/gt/intel_execlists_submission.c b/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
> >> index 0c1b2df02d26..7f389cb0bde4 100644
> >> --- a/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
> >> +++ b/drivers/gpu/drm/i915/gt/intel_execlists_submission.c
> >> @@ -117,6 +117,7 @@
> >>  #include "i915_timer_util.h"
> >>  #include "i915_trace.h"
> >>  #include "i915_vgpu.h"
> >> +#include "i915_wait_util.h"
> >>  #include "intel_breadcrumbs.h"
> >>  #include "intel_context.h"
> >>  #include "intel_engine_heartbeat.h"
> >> diff --git a/drivers/gpu/drm/i915/gt/intel_gt_mcr.c b/drivers/gpu/drm/i915/gt/intel_gt_mcr.c
> >> index a60822e2b5d4..c3afa321fe30 100644
> >> --- a/drivers/gpu/drm/i915/gt/intel_gt_mcr.c
> >> +++ b/drivers/gpu/drm/i915/gt/intel_gt_mcr.c
> >> @@ -4,6 +4,7 @@
> >>   */
> >>  
> >>  #include "i915_drv.h"
> >> +#include "i915_wait_util.h"
> >>  #include "intel_gt.h"
> >>  #include "intel_gt_mcr.h"
> >>  #include "intel_gt_print.h"
> >> diff --git a/drivers/gpu/drm/i915/gt/intel_reset.c b/drivers/gpu/drm/i915/gt/intel_reset.c
> >> index 4a1675dea1c7..41b5036dc538 100644
> >> --- a/drivers/gpu/drm/i915/gt/intel_reset.c
> >> +++ b/drivers/gpu/drm/i915/gt/intel_reset.c
> >> @@ -9,18 +9,17 @@
> >>  
> >>  #include "display/intel_display_reset.h"
> >>  #include "display/intel_overlay.h"
> >> -
> >>  #include "gem/i915_gem_context.h"
> >> -
> >>  #include "gt/intel_gt_regs.h"
> >> -
> >>  #include "gt/uc/intel_gsc_fw.h"
> >> +#include "uc/intel_guc.h"
> >>  
> >>  #include "i915_drv.h"
> >>  #include "i915_file_private.h"
> >>  #include "i915_gpu_error.h"
> >>  #include "i915_irq.h"
> >>  #include "i915_reg.h"
> >> +#include "i915_wait_util.h"
> >>  #include "intel_breadcrumbs.h"
> >>  #include "intel_engine_pm.h"
> >>  #include "intel_engine_regs.h"
> >> @@ -32,8 +31,6 @@
> >>  #include "intel_pci_config.h"
> >>  #include "intel_reset.h"
> >>  
> >> -#include "uc/intel_guc.h"
> >> -
> >>  #define RESET_MAX_RETRIES 3
> >>  
> >>  static void client_mark_guilty(struct i915_gem_context *ctx, bool banned)
> >> diff --git a/drivers/gpu/drm/i915/gt/intel_ring_submission.c b/drivers/gpu/drm/i915/gt/intel_ring_submission.c
> >> index 2a6d79abf25b..8314a4b0505e 100644
> >> --- a/drivers/gpu/drm/i915/gt/intel_ring_submission.c
> >> +++ b/drivers/gpu/drm/i915/gt/intel_ring_submission.c
> >> @@ -15,18 +15,19 @@
> >>  #include "i915_irq.h"
> >>  #include "i915_mitigations.h"
> >>  #include "i915_reg.h"
> >> +#include "i915_wait_util.h"
> >>  #include "intel_breadcrumbs.h"
> >>  #include "intel_context.h"
> >> +#include "intel_engine_heartbeat.h"
> >> +#include "intel_engine_pm.h"
> >>  #include "intel_engine_regs.h"
> >>  #include "intel_gt.h"
> >>  #include "intel_gt_irq.h"
> >> +#include "intel_gt_print.h"
> >>  #include "intel_gt_regs.h"
> >>  #include "intel_reset.h"
> >>  #include "intel_ring.h"
> >>  #include "shmem_utils.h"
> >> -#include "intel_engine_heartbeat.h"
> >> -#include "intel_engine_pm.h"
> >> -#include "intel_gt_print.h"
> >>  
> >>  /* Rough estimate of the typical request size, performing a flush,
> >>   * set-context and then emitting the batch.
> >> diff --git a/drivers/gpu/drm/i915/gt/intel_rps.c b/drivers/gpu/drm/i915/gt/intel_rps.c
> >> index 006042e0b229..4da94098bd3e 100644
> >> --- a/drivers/gpu/drm/i915/gt/intel_rps.c
> >> +++ b/drivers/gpu/drm/i915/gt/intel_rps.c
> >> @@ -10,9 +10,11 @@
> >>  #include "display/intel_display.h"
> >>  #include "display/intel_display_rps.h"
> >>  #include "soc/intel_dram.h"
> >> +
> >>  #include "i915_drv.h"
> >>  #include "i915_irq.h"
> >>  #include "i915_reg.h"
> >> +#include "i915_wait_util.h"
> >>  #include "intel_breadcrumbs.h"
> >>  #include "intel_gt.h"
> >>  #include "intel_gt_clock_utils.h"
> >> diff --git a/drivers/gpu/drm/i915/gt/selftest_tlb.c b/drivers/gpu/drm/i915/gt/selftest_tlb.c
> >> index 69ed946a39e5..a5184f09d1de 100644
> >> --- a/drivers/gpu/drm/i915/gt/selftest_tlb.c
> >> +++ b/drivers/gpu/drm/i915/gt/selftest_tlb.c
> >> @@ -3,17 +3,17 @@
> >>   * Copyright © 2022 Intel Corporation
> >>   */
> >>  
> >> -#include "i915_selftest.h"
> >> -
> >>  #include "gem/i915_gem_internal.h"
> >>  #include "gem/i915_gem_lmem.h"
> >>  #include "gem/i915_gem_region.h"
> >>  
> >>  #include "gen8_engine_cs.h"
> >>  #include "i915_gem_ww.h"
> >> +#include "i915_selftest.h"
> >> +#include "i915_wait_util.h"
> >> +#include "intel_context.h"
> >>  #include "intel_engine_regs.h"
> >>  #include "intel_gpu_commands.h"
> >> -#include "intel_context.h"
> >>  #include "intel_gt.h"
> >>  #include "intel_ring.h"
> >>  
> >> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c b/drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c
> >> index d8edd7c054c8..e7444ebc373e 100644
> >> --- a/drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c
> >> +++ b/drivers/gpu/drm/i915/gt/uc/intel_gsc_proxy.c
> >> @@ -10,11 +10,13 @@
> >>  
> >>  #include "gt/intel_gt.h"
> >>  #include "gt/intel_gt_print.h"
> >> +
> >> +#include "i915_drv.h"
> >> +#include "i915_reg.h"
> >> +#include "i915_wait_util.h"
> >>  #include "intel_gsc_proxy.h"
> >>  #include "intel_gsc_uc.h"
> >>  #include "intel_gsc_uc_heci_cmd_submit.h"
> >> -#include "i915_drv.h"
> >> -#include "i915_reg.h"
> >>  
> >>  /*
> >>   * GSC proxy:
> >> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c b/drivers/gpu/drm/i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c
> >> index 2fde5c360cff..9bd29be7656f 100644
> >> --- a/drivers/gpu/drm/i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c
> >> +++ b/drivers/gpu/drm/i915/gt/uc/intel_gsc_uc_heci_cmd_submit.c
> >> @@ -8,6 +8,8 @@
> >>  #include "gt/intel_gpu_commands.h"
> >>  #include "gt/intel_gt.h"
> >>  #include "gt/intel_ring.h"
> >> +
> >> +#include "i915_wait_util.h"
> >>  #include "intel_gsc_uc_heci_cmd_submit.h"
> >>  
> >>  struct gsc_heci_pkt {
> >> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc.c b/drivers/gpu/drm/i915/gt/uc/intel_guc.c
> >> index f360f020d8f1..52ec4421a211 100644
> >> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc.c
> >> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc.c
> >> @@ -8,15 +8,17 @@
> >>  #include "gt/intel_gt_irq.h"
> >>  #include "gt/intel_gt_pm_irq.h"
> >>  #include "gt/intel_gt_regs.h"
> >> +
> >> +#include "i915_drv.h"
> >> +#include "i915_irq.h"
> >> +#include "i915_reg.h"
> >> +#include "i915_wait_util.h"
> >>  #include "intel_guc.h"
> >>  #include "intel_guc_ads.h"
> >>  #include "intel_guc_capture.h"
> >>  #include "intel_guc_print.h"
> >>  #include "intel_guc_slpc.h"
> >>  #include "intel_guc_submission.h"
> >> -#include "i915_drv.h"
> >> -#include "i915_irq.h"
> >> -#include "i915_reg.h"
> >>  
> >>  /**
> >>   * DOC: GuC
> >> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c
> >> index 380a11c92d63..3e7e5badcc2b 100644
> >> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c
> >> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c
> >> @@ -5,11 +5,12 @@
> >>  
> >>  #include <linux/circ_buf.h>
> >>  #include <linux/ktime.h>
> >> -#include <linux/time64.h>
> >>  #include <linux/string_helpers.h>
> >> +#include <linux/time64.h>
> >>  #include <linux/timekeeping.h>
> >>  
> >>  #include "i915_drv.h"
> >> +#include "i915_wait_util.h"
> >>  #include "intel_guc_ct.h"
> >>  #include "intel_guc_print.h"
> >>  
> >> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c
> >> index e7ccfa520df3..1bb1491f90fc 100644
> >> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c
> >> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c
> >> @@ -13,9 +13,11 @@
> >>  #include "gt/intel_gt_mcr.h"
> >>  #include "gt/intel_gt_regs.h"
> >>  #include "gt/intel_rps.h"
> >> +
> >> +#include "i915_drv.h"
> >> +#include "i915_wait_util.h"
> >>  #include "intel_guc_fw.h"
> >>  #include "intel_guc_print.h"
> >> -#include "i915_drv.h"
> >>  
> >>  static void guc_prepare_xfer(struct intel_gt *gt)
> >>  {
> >> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c
> >> index d5ee6e5e1443..fa9af08f9708 100644
> >> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c
> >> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_slpc.c
> >> @@ -3,17 +3,20 @@
> >>   * Copyright © 2021 Intel Corporation
> >>   */
> >>  
> >> -#include <drm/drm_cache.h>
> >>  #include <linux/string_helpers.h>
> >>  
> >> +#include <drm/drm_cache.h>
> >> +
> >> +#include "gt/intel_gt.h"
> >> +#include "gt/intel_gt_regs.h"
> >> +#include "gt/intel_rps.h"
> >> +
> >>  #include "i915_drv.h"
> >>  #include "i915_reg.h"
> >> -#include "intel_guc_slpc.h"
> >> +#include "i915_wait_util.h"
> >>  #include "intel_guc_print.h"
> >> +#include "intel_guc_slpc.h"
> >>  #include "intel_mchbar_regs.h"
> >> -#include "gt/intel_gt.h"
> >> -#include "gt/intel_gt_regs.h"
> >> -#include "gt/intel_rps.h"
> >>  
> >>  /**
> >>   * DOC: SLPC - Dynamic Frequency management
> >> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
> >> index 127316d2c8aa..68f2b8d363ac 100644
> >> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
> >> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
> >> @@ -25,16 +25,16 @@
> >>  #include "gt/intel_mocs.h"
> >>  #include "gt/intel_ring.h"
> >>  
> >> +#include "i915_drv.h"
> >> +#include "i915_irq.h"
> >> +#include "i915_reg.h"
> >> +#include "i915_trace.h"
> >> +#include "i915_wait_util.h"
> >>  #include "intel_guc_ads.h"
> >>  #include "intel_guc_capture.h"
> >>  #include "intel_guc_print.h"
> >>  #include "intel_guc_submission.h"
> >>  
> >> -#include "i915_drv.h"
> >> -#include "i915_reg.h"
> >> -#include "i915_irq.h"
> >> -#include "i915_trace.h"
> >> -
> >>  /**
> >>   * DOC: GuC-based command submission
> >>   *
> >> diff --git a/drivers/gpu/drm/i915/gvt/mmio_context.c b/drivers/gpu/drm/i915/gvt/mmio_context.c
> >> index 2f7208843367..0b810baad20a 100644
> >> --- a/drivers/gpu/drm/i915/gvt/mmio_context.c
> >> +++ b/drivers/gpu/drm/i915/gvt/mmio_context.c
> >> @@ -33,14 +33,16 @@
> >>   *
> >>   */
> >>  
> >> -#include "i915_drv.h"
> >> -#include "i915_reg.h"
> >>  #include "gt/intel_context.h"
> >>  #include "gt/intel_engine_regs.h"
> >>  #include "gt/intel_gpu_commands.h"
> >>  #include "gt/intel_gt_regs.h"
> >>  #include "gt/intel_ring.h"
> >> +
> >>  #include "gvt.h"
> >> +#include "i915_drv.h"
> >> +#include "i915_reg.h"
> >> +#include "i915_wait_util.h"
> >>  #include "trace.h"
> >>  
> >>  #define GEN9_MOCS_SIZE		64
> >> diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> >> index 23fa098c4479..c2e38d4bcd01 100644
> >> --- a/drivers/gpu/drm/i915/i915_debugfs.c
> >> +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> >> @@ -26,11 +26,11 @@
> >>   *
> >>   */
> >>  
> >> +#include <linux/debugfs.h>
> >>  #include <linux/sched/mm.h>
> >>  #include <linux/sort.h>
> >>  #include <linux/string_helpers.h>
> >>  
> >> -#include <linux/debugfs.h>
> >>  #include <drm/drm_debugfs.h>
> >>  
> >>  #include "gem/i915_gem_context.h"
> >> @@ -54,6 +54,7 @@
> >>  #include "i915_irq.h"
> >>  #include "i915_reg.h"
> >>  #include "i915_scheduler.h"
> >> +#include "i915_wait_util.h"
> >>  #include "intel_mchbar_regs.h"
> >>  
> >>  static inline struct drm_i915_private *node_to_i915(struct drm_info_node *node)
> >> diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
> >> index 4a6437d6e00e..a0c892e4c40d 100644
> >> --- a/drivers/gpu/drm/i915/i915_utils.h
> >> +++ b/drivers/gpu/drm/i915/i915_utils.h
> >> @@ -134,112 +134,6 @@ wait_remaining_ms_from_jiffies(unsigned long timestamp_jiffies, int to_wait_ms)
> >>  	}
> >>  }
> >>  
> >> -/*
> >> - * __wait_for - magic wait macro
> >> - *
> >> - * Macro to help avoid open coding check/wait/timeout patterns. Note that it's
> >> - * important that we check the condition again after having timed out, since the
> >> - * timeout could be due to preemption or similar and we've never had a chance to
> >> - * check the condition before the timeout.
> >> - */
> >> -#define __wait_for(OP, COND, US, Wmin, Wmax) ({ \
> >> -	const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \
> >> -	long wait__ = (Wmin); /* recommended min for usleep is 10 us */	\
> >> -	int ret__;							\
> >> -	might_sleep();							\
> >> -	for (;;) {							\
> >> -		const bool expired__ = ktime_after(ktime_get_raw(), end__); \
> >> -		OP;							\
> >> -		/* Guarantee COND check prior to timeout */		\
> >> -		barrier();						\
> >> -		if (COND) {						\
> >> -			ret__ = 0;					\
> >> -			break;						\
> >> -		}							\
> >> -		if (expired__) {					\
> >> -			ret__ = -ETIMEDOUT;				\
> >> -			break;						\
> >> -		}							\
> >> -		usleep_range(wait__, wait__ * 2);			\
> >> -		if (wait__ < (Wmax))					\
> >> -			wait__ <<= 1;					\
> >> -	}								\
> >> -	ret__;								\
> >> -})
> >> -
> >> -#define _wait_for(COND, US, Wmin, Wmax)	__wait_for(, (COND), (US), (Wmin), \
> >> -						   (Wmax))
> >> -#define wait_for(COND, MS)		_wait_for((COND), (MS) * 1000, 10, 1000)
> >> -
> >> -/*
> >> - * If CONFIG_PREEMPT_COUNT is disabled, in_atomic() always reports false.
> >> - * On PREEMPT_RT the context isn't becoming atomic because it is used in an
> >> - * interrupt handler or because a spinlock_t is acquired. This leads to
> >> - * warnings which don't occur otherwise and therefore the check is disabled.
> >> - */
> >> -#if IS_ENABLED(CONFIG_DRM_I915_DEBUG) && IS_ENABLED(CONFIG_PREEMPT_COUNT) && !defined(CONFIG_PREEMPT_RT)
> >> -# define _WAIT_FOR_ATOMIC_CHECK(ATOMIC) WARN_ON_ONCE((ATOMIC) && !in_atomic())
> >> -#else
> >> -# define _WAIT_FOR_ATOMIC_CHECK(ATOMIC) do { } while (0)
> >> -#endif
> >> -
> >> -#define _wait_for_atomic(COND, US, ATOMIC) \
> >> -({ \
> >> -	int cpu, ret, timeout = (US) * 1000; \
> >> -	u64 base; \
> >> -	_WAIT_FOR_ATOMIC_CHECK(ATOMIC); \
> >> -	if (!(ATOMIC)) { \
> >> -		preempt_disable(); \
> >> -		cpu = smp_processor_id(); \
> >> -	} \
> >> -	base = local_clock(); \
> >> -	for (;;) { \
> >> -		u64 now = local_clock(); \
> >> -		if (!(ATOMIC)) \
> >> -			preempt_enable(); \
> >> -		/* Guarantee COND check prior to timeout */ \
> >> -		barrier(); \
> >> -		if (COND) { \
> >> -			ret = 0; \
> >> -			break; \
> >> -		} \
> >> -		if (now - base >= timeout) { \
> >> -			ret = -ETIMEDOUT; \
> >> -			break; \
> >> -		} \
> >> -		cpu_relax(); \
> >> -		if (!(ATOMIC)) { \
> >> -			preempt_disable(); \
> >> -			if (unlikely(cpu != smp_processor_id())) { \
> >> -				timeout -= now - base; \
> >> -				cpu = smp_processor_id(); \
> >> -				base = local_clock(); \
> >> -			} \
> >> -		} \
> >> -	} \
> >> -	ret; \
> >> -})
> >> -
> >> -#define wait_for_us(COND, US) \
> >> -({ \
> >> -	int ret__; \
> >> -	BUILD_BUG_ON(!__builtin_constant_p(US)); \
> >> -	if ((US) > 10) \
> >> -		ret__ = _wait_for((COND), (US), 10, 10); \
> >> -	else \
> >> -		ret__ = _wait_for_atomic((COND), (US), 0); \
> >> -	ret__; \
> >> -})
> >> -
> >> -#define wait_for_atomic_us(COND, US) \
> >> -({ \
> >> -	BUILD_BUG_ON(!__builtin_constant_p(US)); \
> >> -	BUILD_BUG_ON((US) > 50000); \
> >> -	_wait_for_atomic((COND), (US), 1); \
> >> -})
> >> -
> >> -#define wait_for_atomic(COND, MS) wait_for_atomic_us((COND), (MS) * 1000)
> >> -
> >>  #define KHz(x) (1000 * (x))
> >>  #define MHz(x) KHz(1000 * (x))
> >>  
> >> diff --git a/drivers/gpu/drm/i915/i915_wait_util.h b/drivers/gpu/drm/i915/i915_wait_util.h
> >> new file mode 100644
> >> index 000000000000..7376898e3bf8
> >> --- /dev/null
> >> +++ b/drivers/gpu/drm/i915/i915_wait_util.h
> >> @@ -0,0 +1,119 @@
> >> +/* SPDX-License-Identifier: MIT */
> >> +/* Copyright © 2025 Intel Corporation */
> >> +
> >> +#ifndef __I915_WAIT_UTIL_H__
> >> +#define __I915_WAIT_UTIL_H__
> >> +
> >> +#include <linux/compiler.h>
> >> +#include <linux/delay.h>
> >> +#include <linux/ktime.h>
> >> +#include <linux/sched/clock.h>
> >> +#include <linux/smp.h>
> >> +
> >> +/*
> >> + * __wait_for - magic wait macro
> >> + *
> >> + * Macro to help avoid open coding check/wait/timeout patterns. Note that it's
> >> + * important that we check the condition again after having timed out, since the
> >> + * timeout could be due to preemption or similar and we've never had a chance to
> >> + * check the condition before the timeout.
> >> + */
> >> +#define __wait_for(OP, COND, US, Wmin, Wmax) ({ \
> >> +	const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \
> >> +	long wait__ = (Wmin); /* recommended min for usleep is 10 us */	\
> >> +	int ret__;							\
> >> +	might_sleep();							\
> >> +	for (;;) {							\
> >> +		const bool expired__ = ktime_after(ktime_get_raw(), end__); \
> >> +		OP;							\
> >> +		/* Guarantee COND check prior to timeout */		\
> >> +		barrier();						\
> >> +		if (COND) {						\
> >> +			ret__ = 0;					\
> >> +			break;						\
> >> +		}							\
> >> +		if (expired__) {					\
> >> +			ret__ = -ETIMEDOUT;				\
> >> +			break;						\
> >> +		}							\
> >> +		usleep_range(wait__, wait__ * 2);			\
> >> +		if (wait__ < (Wmax))					\
> >> +			wait__ <<= 1;					\
> >> +	}								\
> >> +	ret__;								\
> >> +})
> >> +
> >> +#define _wait_for(COND, US, Wmin, Wmax)	__wait_for(, (COND), (US), (Wmin), \
> >> +						   (Wmax))
> >> +#define wait_for(COND, MS)		_wait_for((COND), (MS) * 1000, 10, 1000)
> >> +
> >> +/*
> >> + * If CONFIG_PREEMPT_COUNT is disabled, in_atomic() always reports false.
> >> + * On PREEMPT_RT the context isn't becoming atomic because it is used in an
> >> + * interrupt handler or because a spinlock_t is acquired. This leads to
> >> + * warnings which don't occur otherwise and therefore the check is disabled.
> >> + */
> >> +#if IS_ENABLED(CONFIG_DRM_I915_DEBUG) && IS_ENABLED(CONFIG_PREEMPT_COUNT) && !defined(CONFIG_PREEMPT_RT)
> >> +# define _WAIT_FOR_ATOMIC_CHECK(ATOMIC) WARN_ON_ONCE((ATOMIC) && !in_atomic())
> >> +#else
> >> +# define _WAIT_FOR_ATOMIC_CHECK(ATOMIC) do { } while (0)
> >> +#endif
> >> +
> >> +#define _wait_for_atomic(COND, US, ATOMIC) \
> >> +({ \
> >> +	int cpu, ret, timeout = (US) * 1000; \
> >> +	u64 base; \
> >> +	_WAIT_FOR_ATOMIC_CHECK(ATOMIC); \
> >> +	if (!(ATOMIC)) { \
> >> +		preempt_disable(); \
> >> +		cpu = smp_processor_id(); \
> >> +	} \
> >> +	base = local_clock(); \
> >> +	for (;;) { \
> >> +		u64 now = local_clock(); \
> >> +		if (!(ATOMIC)) \
> >> +			preempt_enable(); \
> >> +		/* Guarantee COND check prior to timeout */ \
> >> +		barrier(); \
> >> +		if (COND) { \
> >> +			ret = 0; \
> >> +			break; \
> >> +		} \
> >> +		if (now - base >= timeout) { \
> >> +			ret = -ETIMEDOUT; \
> >> +			break; \
> >> +		} \
> >> +		cpu_relax(); \
> >> +		if (!(ATOMIC)) { \
> >> +			preempt_disable(); \
> >> +			if (unlikely(cpu != smp_processor_id())) { \
> >> +				timeout -= now - base; \
> >> +				cpu = smp_processor_id(); \
> >> +				base = local_clock(); \
> >> +			} \
> >> +		} \
> >> +	} \
> >> +	ret; \
> >> +})
> >> +
> >> +#define wait_for_us(COND, US) \
> >> +({ \
> >> +	int ret__; \
> >> +	BUILD_BUG_ON(!__builtin_constant_p(US)); \
> >> +	if ((US) > 10) \
> >> +		ret__ = _wait_for((COND), (US), 10, 10); \
> >> +	else \
> >> +		ret__ = _wait_for_atomic((COND), (US), 0); \
> >> +	ret__; \
> >> +})
> >> +
> >> +#define wait_for_atomic_us(COND, US) \
> >> +({ \
> >> +	BUILD_BUG_ON(!__builtin_constant_p(US)); \
> >> +	BUILD_BUG_ON((US) > 50000); \
> >> +	_wait_for_atomic((COND), (US), 1); \
> >> +})
> >> +
> >> +#define wait_for_atomic(COND, MS) wait_for_atomic_us((COND), (MS) * 1000)
> >> +
> >> +#endif /* __I915_WAIT_UTIL_H__ */
> >> diff --git a/drivers/gpu/drm/i915/intel_pcode.c b/drivers/gpu/drm/i915/intel_pcode.c
> >> index 81da75108c60..55ffedad2490 100644
> >> --- a/drivers/gpu/drm/i915/intel_pcode.c
> >> +++ b/drivers/gpu/drm/i915/intel_pcode.c
> >> @@ -5,6 +5,7 @@
> >>  
> >>  #include "i915_drv.h"
> >>  #include "i915_reg.h"
> >> +#include "i915_wait_util.h"
> >>  #include "intel_pcode.h"
> >>  
> >>  static int gen6_check_mailbox_status(u32 mbox)
> >> diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c
> >> index 4ccba7c8ffb3..8cb59f8d1f4c 100644
> >> --- a/drivers/gpu/drm/i915/intel_uncore.c
> >> +++ b/drivers/gpu/drm/i915/intel_uncore.c
> >> @@ -21,19 +21,20 @@
> >>   * IN THE SOFTWARE.
> >>   */
> >>  
> >> -#include <drm/drm_managed.h>
> >>  #include <linux/pm_runtime.h>
> >>  
> >> -#include "display/intel_display_core.h"
> >> +#include <drm/drm_managed.h>
> >>  
> >> -#include "gt/intel_gt.h"
> >> +#include "display/intel_display_core.h"
> >>  #include "gt/intel_engine_regs.h"
> >> +#include "gt/intel_gt.h"
> >>  #include "gt/intel_gt_regs.h"
> >>  
> >>  #include "i915_drv.h"
> >>  #include "i915_iosf_mbi.h"
> >>  #include "i915_reg.h"
> >>  #include "i915_vgpu.h"
> >> +#include "i915_wait_util.h"
> >>  #include "intel_uncore_trace.h"
> >>  
> >>  #define FORCEWAKE_ACK_TIMEOUT_MS 50
> >> diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp.c b/drivers/gpu/drm/i915/pxp/intel_pxp.c
> >> index f8da693ad3ce..27d545c4e6a5 100644
> >> --- a/drivers/gpu/drm/i915/pxp/intel_pxp.c
> >> +++ b/drivers/gpu/drm/i915/pxp/intel_pxp.c
> >> @@ -2,15 +2,15 @@
> >>  /*
> >>   * Copyright(c) 2020 Intel Corporation.
> >>   */
> >> +
> >>  #include <linux/workqueue.h>
> >>  
> >>  #include "gem/i915_gem_context.h"
> >> -
> >>  #include "gt/intel_context.h"
> >>  #include "gt/intel_gt.h"
> >>  
> >>  #include "i915_drv.h"
> >> -
> >> +#include "i915_wait_util.h"
> >>  #include "intel_pxp.h"
> >>  #include "intel_pxp_gsccs.h"
> >>  #include "intel_pxp_irq.h"
> >> diff --git a/drivers/gpu/drm/i915/selftests/i915_request.c b/drivers/gpu/drm/i915/selftests/i915_request.c
> >> index 2fb7a9e7efec..48cd617247d1 100644
> >> --- a/drivers/gpu/drm/i915/selftests/i915_request.c
> >> +++ b/drivers/gpu/drm/i915/selftests/i915_request.c
> >> @@ -22,14 +22,13 @@
> >>   *
> >>   */
> >>  
> >> -#include <linux/prime_numbers.h>
> >>  #include <linux/pm_qos.h>
> >> +#include <linux/prime_numbers.h>
> >>  #include <linux/sort.h>
> >>  
> >>  #include "gem/i915_gem_internal.h"
> >>  #include "gem/i915_gem_pm.h"
> >>  #include "gem/selftests/mock_context.h"
> >> -
> >>  #include "gt/intel_engine_heartbeat.h"
> >>  #include "gt/intel_engine_pm.h"
> >>  #include "gt/intel_engine_user.h"
> >> @@ -40,11 +39,11 @@
> >>  
> >>  #include "i915_random.h"
> >>  #include "i915_selftest.h"
> >> +#include "i915_wait_util.h"
> >>  #include "igt_flush_test.h"
> >>  #include "igt_live_test.h"
> >>  #include "igt_spinner.h"
> >>  #include "lib_sw_fence.h"
> >> -
> >>  #include "mock_drm.h"
> >>  #include "mock_gem_device.h"
> >>  
> >> diff --git a/drivers/gpu/drm/i915/selftests/i915_selftest.c b/drivers/gpu/drm/i915/selftests/i915_selftest.c
> >> index 889281819c5b..9c276c9d0a75 100644
> >> --- a/drivers/gpu/drm/i915/selftests/i915_selftest.c
> >> +++ b/drivers/gpu/drm/i915/selftests/i915_selftest.c
> >> @@ -31,7 +31,7 @@
> >>  #include "i915_driver.h"
> >>  #include "i915_drv.h"
> >>  #include "i915_selftest.h"
> >> -
> >> +#include "i915_wait_util.h"
> >>  #include "igt_flush_test.h"
> >>  
> >>  struct i915_selftest i915_selftest __read_mostly = {
> >> diff --git a/drivers/gpu/drm/i915/selftests/igt_spinner.c b/drivers/gpu/drm/i915/selftests/igt_spinner.c
> >> index 8c3e1f20e5a1..820364171ebe 100644
> >> --- a/drivers/gpu/drm/i915/selftests/igt_spinner.c
> >> +++ b/drivers/gpu/drm/i915/selftests/igt_spinner.c
> >> @@ -3,12 +3,13 @@
> >>   *
> >>   * Copyright © 2018 Intel Corporation
> >>   */
> >> -#include "gt/intel_gpu_commands.h"
> >> -#include "gt/intel_gt.h"
> >>  
> >>  #include "gem/i915_gem_internal.h"
> >>  #include "gem/selftests/igt_gem_utils.h"
> >> +#include "gt/intel_gpu_commands.h"
> >> +#include "gt/intel_gt.h"
> >>  
> >> +#include "i915_wait_util.h"
> >>  #include "igt_spinner.h"
> >>  
> >>  int igt_spinner_init(struct igt_spinner *spin, struct intel_gt *gt)
> >> diff --git a/drivers/gpu/drm/i915/vlv_suspend.c b/drivers/gpu/drm/i915/vlv_suspend.c
> >> index fc9f311ea1db..221e4c0b2c58 100644
> >> --- a/drivers/gpu/drm/i915/vlv_suspend.c
> >> +++ b/drivers/gpu/drm/i915/vlv_suspend.c
> >> @@ -8,16 +8,17 @@
> >>  
> >>  #include <drm/drm_print.h>
> >>  
> >> +#include "gt/intel_gt_regs.h"
> >> +
> >>  #include "i915_drv.h"
> >>  #include "i915_reg.h"
> >>  #include "i915_trace.h"
> >>  #include "i915_utils.h"
> >> +#include "i915_wait_util.h"
> >>  #include "intel_clock_gating.h"
> >>  #include "intel_uncore_trace.h"
> >>  #include "vlv_suspend.h"
> >>  
> >> -#include "gt/intel_gt_regs.h"
> >> -
> >>  struct vlv_s0ix_state {
> >>  	/* GAM */
> >>  	u32 wr_watermark;
> >> -- 
> >> 2.47.3
> >> 
> 
> -- 
> Jani Nikula, Intel

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-09-10 16:45 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-08 14:11 [PATCH 0/5] drm/i915: clean up i915_utils.h Jani Nikula
2025-09-08 14:11 ` [PATCH 1/5] drm/i915: redundant i915_utils.h includes Jani Nikula
2025-09-09 13:36   ` Rodrigo Vivi
2025-09-08 14:11 ` [PATCH 2/5] drm/i915: split out i915_ptr_util.h Jani Nikula
2025-09-09 13:37   ` Rodrigo Vivi
2025-09-08 14:11 ` [PATCH 3/5] drm/i915: split out i915_timer_util.[ch] Jani Nikula
2025-09-09 13:38   ` Rodrigo Vivi
2025-09-08 14:11 ` [PATCH 4/5] drm/i915: split out i915_list_util.h Jani Nikula
2025-09-09 13:39   ` Rodrigo Vivi
2025-09-08 14:11 ` [PATCH 5/5] drm/i915: split out i915_wait_util.h Jani Nikula
2025-09-09 13:40   ` Rodrigo Vivi
2025-09-10 12:06     ` Jani Nikula
2025-09-10 16:45       ` Rodrigo Vivi
2025-09-08 19:07 ` ✗ Fi.CI.BUILD: failure for drm/i915: clean up i915_utils.h Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).