]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/intel: add pick.h for the various "picker" helpers
authorJani Nikula <jani.nikula@intel.com>
Wed, 25 Feb 2026 17:57:09 +0000 (19:57 +0200)
committerJani Nikula <jani.nikula@intel.com>
Wed, 4 Mar 2026 11:04:29 +0000 (13:04 +0200)
Add a shared header that's used by i915, xe, and i915 display.

This allows us to drop the compat-i915-headers/i915_reg_defs.h include
from xe_reg_defs.h. All the register macro helpers were subtly pulled in
from i915 to all of xe through this.

Reviewed-by: Michał Grzelak <michal.grzelak@intel.com>
Acked-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Link: https://patch.msgid.link/fcd70f3317755bf98a6e7ae88974aa8ba06efd1e.1772042022.git.jani.nikula@intel.com
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
drivers/gpu/drm/i915/i915_reg_defs.h
drivers/gpu/drm/xe/compat-i915-headers/intel_uncore.h
drivers/gpu/drm/xe/regs/xe_reg_defs.h
include/drm/intel/pick.h [new file with mode: 0644]

index a1dc7ff2bef7967a38156a635dd95eb7107bc9ca..e897d3ccbf9e56eb9878a5382b15900feb057a40 100644 (file)
@@ -6,52 +6,9 @@
 #ifndef __I915_REG_DEFS__
 #define __I915_REG_DEFS__
 
+#include <drm/intel/pick.h>
 #include <drm/intel/reg_bits.h>
 
-/*
- * Given the first two numbers __a and __b of arbitrarily many evenly spaced
- * numbers, pick the 0-based __index'th value.
- *
- * Always prefer this over _PICK() if the numbers are evenly spaced.
- */
-#define _PICK_EVEN(__index, __a, __b) ((__a) + (__index) * ((__b) - (__a)))
-
-/*
- * Like _PICK_EVEN(), but supports 2 ranges of evenly spaced address offsets.
- * @__c_index corresponds to the index in which the second range starts to be
- * used. Using math interval notation, the first range is used for indexes [ 0,
- * @__c_index), while the second range is used for [ @__c_index, ... ). Example:
- *
- * #define _FOO_A                      0xf000
- * #define _FOO_B                      0xf004
- * #define _FOO_C                      0xf008
- * #define _SUPER_FOO_A                        0xa000
- * #define _SUPER_FOO_B                        0xa100
- * #define FOO(x)                      _MMIO(_PICK_EVEN_2RANGES(x, 3,          \
- *                                           _FOO_A, _FOO_B,                   \
- *                                           _SUPER_FOO_A, _SUPER_FOO_B))
- *
- * This expands to:
- *     0: 0xf000,
- *     1: 0xf004,
- *     2: 0xf008,
- *     3: 0xa000,
- *     4: 0xa100,
- *     5: 0xa200,
- *     ...
- */
-#define _PICK_EVEN_2RANGES(__index, __c_index, __a, __b, __c, __d)             \
-       (BUILD_BUG_ON_ZERO(!__is_constexpr(__c_index)) +                        \
-        ((__index) < (__c_index) ? _PICK_EVEN(__index, __a, __b) :             \
-                                  _PICK_EVEN((__index) - (__c_index), __c, __d)))
-
-/*
- * Given the arbitrary numbers in varargs, pick the 0-based __index'th number.
- *
- * Always prefer _PICK_EVEN() over this if the numbers are evenly spaced.
- */
-#define _PICK(__index, ...) (((const u32 []){ __VA_ARGS__ })[__index])
-
 typedef struct {
        u32 reg;
 } i915_reg_t;
index c5e198ace7bce172ab59846c0216edab4e15c27f..a8cfd65119e091024ffaa0d1c4521227db76f633 100644 (file)
@@ -6,6 +6,7 @@
 #ifndef __INTEL_UNCORE_H__
 #define __INTEL_UNCORE_H__
 
+#include "i915_reg_defs.h"
 #include "xe_device.h"
 #include "xe_device_types.h"
 #include "xe_mmio.h"
index c39aab843e357573ba696fbcb55291c3c4f6e7c6..27ac0bf1f6cda7df0331fd12da5634f7f457a156 100644 (file)
@@ -6,12 +6,13 @@
 #ifndef _XE_REG_DEFS_H_
 #define _XE_REG_DEFS_H_
 
+#include <drm/intel/pick.h>
+#include <drm/intel/reg_bits.h>
+
 #include <linux/build_bug.h>
 #include <linux/log2.h>
 #include <linux/sizes.h>
 
-#include "compat-i915-headers/i915_reg_defs.h"
-
 /**
  * XE_REG_ADDR_MAX - The upper limit on MMIO register address
  *
diff --git a/include/drm/intel/pick.h b/include/drm/intel/pick.h
new file mode 100644 (file)
index 0000000..d976fab
--- /dev/null
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: MIT */
+/* Copyright © 2026 Intel Corporation */
+
+#ifndef _PICK_H_
+#define _PICK_H_
+
+/*
+ * Given the first two numbers __a and __b of arbitrarily many evenly spaced
+ * numbers, pick the 0-based __index'th value.
+ *
+ * Always prefer this over _PICK() if the numbers are evenly spaced.
+ */
+#define _PICK_EVEN(__index, __a, __b) ((__a) + (__index) * ((__b) - (__a)))
+
+/*
+ * Like _PICK_EVEN(), but supports 2 ranges of evenly spaced address offsets.
+ * @__c_index corresponds to the index in which the second range starts to be
+ * used. Using math interval notation, the first range is used for indexes [ 0,
+ * @__c_index), while the second range is used for [ @__c_index, ... ). Example:
+ *
+ * #define _FOO_A                      0xf000
+ * #define _FOO_B                      0xf004
+ * #define _FOO_C                      0xf008
+ * #define _SUPER_FOO_A                        0xa000
+ * #define _SUPER_FOO_B                        0xa100
+ * #define FOO(x)                      _MMIO(_PICK_EVEN_2RANGES(x, 3,          \
+ *                                           _FOO_A, _FOO_B,                   \
+ *                                           _SUPER_FOO_A, _SUPER_FOO_B))
+ *
+ * This expands to:
+ *     0: 0xf000,
+ *     1: 0xf004,
+ *     2: 0xf008,
+ *     3: 0xa000,
+ *     4: 0xa100,
+ *     5: 0xa200,
+ *     ...
+ */
+#define _PICK_EVEN_2RANGES(__index, __c_index, __a, __b, __c, __d)             \
+       (BUILD_BUG_ON_ZERO(!__is_constexpr(__c_index)) +                        \
+        ((__index) < (__c_index) ? _PICK_EVEN(__index, __a, __b) :             \
+                                  _PICK_EVEN((__index) - (__c_index), __c, __d)))
+
+/*
+ * Given the arbitrary numbers in varargs, pick the 0-based __index'th number.
+ *
+ * Always prefer _PICK_EVEN() over this if the numbers are evenly spaced.
+ */
+#define _PICK(__index, ...) (((const u32 []){ __VA_ARGS__ })[__index])
+
+#endif