File revert-i915-ktime_get_raw_ns.diff of Package drm

Revert 5ed0bdf21a85d78e04f89f15ccf227562177cbd9

---
 drivers/gpu/drm/i915/i915_drv.h |    2 +-
 drivers/gpu/drm/i915/i915_gem.c |   33 +++++++++++++++++++++------------
 drivers/gpu/drm/i915/intel_pm.c |   12 +++++++-----
 3 files changed, 29 insertions(+), 18 deletions(-)

--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -974,7 +974,7 @@ struct intel_ilk_power_mgmt {
 	unsigned long last_time1;
 	unsigned long chipset_power;
 	u64 last_count2;
-	u64 last_time2;
+	struct timespec last_time2;
 	unsigned long gfx_power;
 	u8 corr;
 
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1155,16 +1155,16 @@ static bool can_wait_boost(struct drm_i9
 static int __wait_seqno(struct intel_engine_cs *ring, u32 seqno,
 			unsigned reset_counter,
 			bool interruptible,
-			s64 *timeout,
+			struct timespec *timeout,
 			struct drm_i915_file_private *file_priv)
 {
 	struct drm_device *dev = ring->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	const bool irq_test_in_progress =
 		ACCESS_ONCE(dev_priv->gpu_error.test_irq_rings) & intel_ring_flag(ring);
+	struct timespec before, now;
 	DEFINE_WAIT(wait);
 	unsigned long timeout_expire;
-	s64 before, now;
 	int ret;
 
 	WARN(!intel_irqs_enabled(dev_priv), "IRQs disabled");
@@ -1172,7 +1172,7 @@ static int __wait_seqno(struct intel_eng
 	if (i915_seqno_passed(ring->get_seqno(ring, true), seqno))
 		return 0;
 
-	timeout_expire = timeout ? jiffies + nsecs_to_jiffies((u64)*timeout) : 0;
+	timeout_expire = timeout ? jiffies + timespec_to_jiffies_timeout(timeout) : 0;
 
 	if (INTEL_INFO(dev)->gen >= 6 && ring->id == RCS && can_wait_boost(file_priv)) {
 		gen6_rps_boost(dev_priv);
@@ -1187,7 +1187,7 @@ static int __wait_seqno(struct intel_eng
 
 	/* Record current time in case interrupted by signal, or wedged */
 	trace_i915_gem_request_wait_begin(ring, seqno);
-	before = ktime_get_raw_ns();
+	getrawmonotonic(&before);
 	for (;;) {
 		struct timer_list timer;
 
@@ -1236,7 +1236,7 @@ static int __wait_seqno(struct intel_eng
 			destroy_timer_on_stack(&timer);
 		}
 	}
-	now = ktime_get_raw_ns();
+	getrawmonotonic(&now);
 	trace_i915_gem_request_wait_end(ring, seqno);
 
 	if (!irq_test_in_progress)
@@ -1245,9 +1245,10 @@ static int __wait_seqno(struct intel_eng
 	finish_wait(&ring->irq_queue, &wait);
 
 	if (timeout) {
-		s64 tres = *timeout - (now - before);
-
-		*timeout = tres < 0 ? 0 : tres;
+		struct timespec sleep_time = timespec_sub(now, before);
+		*timeout = timespec_sub(*timeout, sleep_time);
+		if (!timespec_valid(timeout)) /* i.e. negative time remains */
+			set_normalized_timespec(timeout, 0, 0);
 	}
 
 	return ret;
@@ -2776,10 +2777,16 @@ i915_gem_wait_ioctl(struct drm_device *d
 	struct drm_i915_gem_wait *args = data;
 	struct drm_i915_gem_object *obj;
 	struct intel_engine_cs *ring = NULL;
+	struct timespec timeout_stack, *timeout = NULL;
 	unsigned reset_counter;
 	u32 seqno = 0;
 	int ret = 0;
 
+	if (args->timeout_ns >= 0) {
+		timeout_stack = ns_to_timespec(args->timeout_ns);
+		timeout = &timeout_stack;
+	}
+
 	ret = i915_mutex_lock_interruptible(dev);
 	if (ret)
 		return ret;
@@ -2804,9 +2811,9 @@ i915_gem_wait_ioctl(struct drm_device *d
 		 goto out;
 
 	/* Do this after OLR check to make sure we make forward progress polling
-	 * on this IOCTL with a timeout <=0 (like busy ioctl)
+	 * on this IOCTL with a 0 timeout (like busy ioctl)
 	 */
-	if (args->timeout_ns <= 0) {
+	if (!args->timeout_ns) {
 		ret = -ETIME;
 		goto out;
 	}
@@ -2815,8 +2822,10 @@ i915_gem_wait_ioctl(struct drm_device *d
 	reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
 	mutex_unlock(&dev->struct_mutex);
 
-	return __wait_seqno(ring, seqno, reset_counter, true, &args->timeout_ns,
-			    file->driver_priv);
+	ret = __wait_seqno(ring, seqno, reset_counter, true, timeout, file->driver_priv);
+	if (timeout)
+		args->timeout_ns = timespec_to_ns(timeout);
+	return ret;
 
 out:
 	drm_gem_object_unreference(&obj->base);
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -3033,7 +3033,7 @@ static void ironlake_enable_drps(struct
 		I915_READ(0x112e0);
 	dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies);
 	dev_priv->ips.last_count2 = I915_READ(0x112f4);
-	dev_priv->ips.last_time2 = ktime_get_raw_ns();
+	getrawmonotonic(&dev_priv->ips.last_time2);
 
 	spin_unlock_irq(&mchdev_lock);
 }
@@ -4598,16 +4598,18 @@ static u16 pvid_to_extvid(struct drm_i91
 
 static void __i915_update_gfx_val(struct drm_i915_private *dev_priv)
 {
-	u64 now, diff, diffms;
+	struct timespec now, diff1;
+	u64 diff;
+	unsigned long diffms;
 	u32 count;
 
 	assert_spin_locked(&mchdev_lock);
 
-	now = ktime_get_raw_ns();
-	diffms = now - dev_priv->ips.last_time2;
-	do_div(diffms, NSEC_PER_MSEC);
+	getrawmonotonic(&now);
+	diff1 = timespec_sub(now, dev_priv->ips.last_time2);
 
 	/* Don't divide by 0 */
+	diffms = diff1.tv_sec * 1000 + diff1.tv_nsec / 1000000;
 	if (!diffms)
 		return;