drm/xe: Implement a local xe_mmio_wait32
authorRodrigo Vivi <rodrigo.vivi@intel.com>
Thu, 12 Jan 2023 22:25:03 +0000 (17:25 -0500)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Tue, 12 Dec 2023 19:05:59 +0000 (14:05 -0500)
Then, move the i915_utils.h include to its user.

The overall goal is to kill all the usages of the i915_utils
stuff.

Yes, wait_for also depends on <linux/delay.h>, so they go
together to where it is needed. It will be likely needed
anyway directly for udelay or usleep_range.

Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
drivers/gpu/drm/xe/xe_force_wake.c
drivers/gpu/drm/xe/xe_gt_mcr.c
drivers/gpu/drm/xe/xe_guc.c
drivers/gpu/drm/xe/xe_guc_pc.c
drivers/gpu/drm/xe/xe_mmio.h
drivers/gpu/drm/xe/xe_pcode.c

index 0320ce7ba3d19bc52d6110be144326274825eba1..31a33ee9ccb6c6a4d9823a213738c8825ecd7806 100644 (file)
 #include "xe_mmio.h"
 #include "gt/intel_gt_regs.h"
 
+/*
+ * FIXME: This header has been deemed evil and we need to kill it. Temporarily
+ * including so we can use '__mask_next_bit'.
+ */
+#include "i915_utils.h"
+
 #define XE_FORCE_WAKE_ACK_TIMEOUT_MS   50
 
 static struct xe_gt *
index b69c0d6c6b2f921dcd638c29b5719602b0aa9d19..8add5ec9a30772d737de76ad1fa8e142d405f7d2 100644 (file)
 
 #include "gt/intel_gt_regs.h"
 
+#include <linux/delay.h>
+/*
+ * FIXME: This header has been deemed evil and we need to kill it. Temporar
+ * including so we can use 'wait_for'.
+ */
+#include "i915_utils.h"
+
 /**
  * DOC: GT Multicast/Replicated (MCR) Register Support
  *
index 3c285d849ef65443b407450d3ae7f7ea1827479d..969a2427b1f260b7372b5a829db6074c55fb082b 100644 (file)
 #include "i915_reg_defs.h"
 #include "gt/intel_gt_regs.h"
 
+#include <linux/delay.h>
+/*
+ * FIXME: This header has been deemed evil and we need to kill it. Temporarily
+ * including so we can use 'wait_for' and range_overflow_t.
+ */
+#include "i915_utils.h"
+
 /* TODO: move to common file */
 #define GUC_PVC_MOCS_INDEX_MASK                REG_GENMASK(25, 24)
 #define PVC_MOCS_UC_INDEX              1
index 227e30a482e3b34d215923b7174d1855bb4b1ec2..260ccf3fe215abe2255b461b04afc5dc7654af8d 100644 (file)
 #include "i915_reg_defs.h"
 #include "i915_reg.h"
 
+#include <linux/delay.h>
+/*
+ * FIXME: This header has been deemed evil and we need to kill it. Temporarily
+ * including so we can use 'wait_for'.
+ */
+#include "i915_utils.h"
+
 #include "intel_mchbar_regs.h"
 
 /* For GEN6_RP_STATE_CAP.reg to be merged when the definition moves to Xe */
index 09d24467096fb178dd2c3a06d2cb89a8a968c89a..7352b622ca87a34f70df93dc8d72f6c97d2f2a3b 100644 (file)
 
 #include "xe_gt_types.h"
 
-/*
- * FIXME: This header has been deemed evil and we need to kill it. Temporarily
- * including so we can use 'wait_for' and unblock initial development. A follow
- * should replace 'wait_for' with a sane version and drop including this header.
- */
-#include "i915_utils.h"
-
 struct drm_device;
 struct drm_file;
 struct xe_device;
@@ -93,8 +86,26 @@ static inline int xe_mmio_wait32(struct xe_gt *gt,
                                 u32 reg, u32 val,
                                 u32 mask, u32 timeout_ms)
 {
-       return wait_for((xe_mmio_read32(gt, reg) & mask) == val,
-                       timeout_ms);
+       ktime_t cur = ktime_get_raw();
+       const ktime_t end = ktime_add_ms(cur, timeout_ms);
+       s64 wait = 10;
+
+       for (;;) {
+               if ((xe_mmio_read32(gt, reg) & mask) == val)
+                       return 0;
+
+               cur = ktime_get_raw();
+               if (!ktime_before(cur, end))
+                       return -ETIMEDOUT;
+
+               if (ktime_after(ktime_add_us(cur, wait), end))
+                       wait = ktime_us_delta(end, cur);
+
+               usleep_range(wait, wait << 1);
+               wait <<= 1;
+       }
+
+       return -ETIMEDOUT;
 }
 
 int xe_mmio_ioctl(struct drm_device *dev, void *data,
index 236159c8a6c0e4d42bae25e47e2e837d94cb1175..313ccd70d1a988d7f52950706498b8495f7bae68 100644 (file)
 
 #include <linux/errno.h>
 
+#include <linux/delay.h>
+/*
+ * FIXME: This header has been deemed evil and we need to kill it. Temporarily
+ * including so we can use 'wait_for'.
+ */
+#include "i915_utils.h"
+
 /**
  * DOC: PCODE
  *