--- /dev/null
+From aa9323dd49b23932a09023012f050556de64f118 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= <ville.syrjala@linux.intel.com>
+Date: Wed, 8 Feb 2017 19:52:54 +0200
+Subject: drm/i915: Avoid spurious WARNs about the wrong pipe in the PPS code
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+From: Ville Syrjälä <ville.syrjala@linux.intel.com>
+
+commit aa9323dd49b23932a09023012f050556de64f118 upstream.
+
+Until recently vlv_steal_power_sequencer() wasn't being called for
+normal DP ports, and hence it could assert that it should only be
+called for pipe A and B (since pipe C doesn't support eDP). However
+that changed when we started to consider normal DP ports as well when
+choosing a PPS. So we will now get spurious warnings when
+vlv_steal_power_sequencer() does get called for pipe C. Avoid this by
+moving the WARN down into vlv_detach_power_sequencer() where this
+assertion should still hold.
+
+Cc: Imre Deak <imre.deak@intel.com>
+Fixes: 9f2bdb006a7e ("drm/i915: Prevent PPS stealing from a normal DP port on VLV/CHV")
+References: https://bugs.freedesktop.org/show_bug.cgi?id=95287
+Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
+Link: http://patchwork.freedesktop.org/patch/msgid/20170208175254.10958-1-ville.syrjala@linux.intel.com
+Reviewed-by: Imre Deak <imre.deak@intel.com>
+(cherry picked from commit d158694f452252d0fef335a775aeb3eb74fe7af0)
+Signed-off-by: Jani Nikula <jani.nikula@intel.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/gpu/drm/i915/intel_dp.c | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+--- a/drivers/gpu/drm/i915/intel_dp.c
++++ b/drivers/gpu/drm/i915/intel_dp.c
+@@ -2820,6 +2820,9 @@ static void vlv_detach_power_sequencer(s
+ enum pipe pipe = intel_dp->pps_pipe;
+ i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
+
++ if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
++ return;
++
+ edp_panel_vdd_off_sync(intel_dp);
+
+ /*
+@@ -2847,9 +2850,6 @@ static void vlv_steal_power_sequencer(st
+
+ lockdep_assert_held(&dev_priv->pps_mutex);
+
+- if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
+- return;
+-
+ for_each_intel_encoder(dev, encoder) {
+ struct intel_dp *intel_dp;
+ enum port port;
--- /dev/null
+From 44a027058b24541cc7ec499e6fb91db4b130648a Mon Sep 17 00:00:00 2001
+From: Chris Wilson <chris@chris-wilson.co.uk>
+Date: Wed, 8 Feb 2017 18:12:38 +0000
+Subject: drm/i915: Check for timeout completion when waiting for the rq to submitted
+
+From: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 44a027058b24541cc7ec499e6fb91db4b130648a upstream.
+
+We first wait for a request to be submitted to hw and assigned a seqno,
+before we can wait for the hw to signal completion (otherwise we don't
+know the hw id we need to wait upon). Whilst waiting for the request to
+be submitted, we may exceed the user's timeout and need to propagate the
+error back.
+
+v2: Make ETIME into an error from wait_for_execute for consistent exit
+handling.
+
+Reported-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
+Fixes: 4680816be336 ("drm/i915: Wait first for submission, before waiting for request completion")
+Testcase: igt/gem_wait/basic-await
+Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
+Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
+Cc: <drm-intel-fixes@lists.freedesktop.org> # v4.10-rc1+
+Link: http://patchwork.freedesktop.org/patch/msgid/20170208181238.7232-1-chris@chris-wilson.co.uk
+Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
+(cherry picked from commit 969bb72cbfd906d347cf76dc9b8c8dbaf83ba27a)
+Signed-off-by: Jani Nikula <jani.nikula@intel.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/gpu/drm/i915/i915_gem_request.c | 7 ++++++-
+ 1 file changed, 6 insertions(+), 1 deletion(-)
+
+--- a/drivers/gpu/drm/i915/i915_gem_request.c
++++ b/drivers/gpu/drm/i915/i915_gem_request.c
+@@ -1011,8 +1011,13 @@ __i915_request_wait_for_execute(struct d
+ break;
+ }
+
++ if (!timeout) {
++ timeout = -ETIME;
++ break;
++ }
++
+ timeout = io_schedule_timeout(timeout);
+- } while (timeout);
++ } while (1);
+ finish_wait(&request->execute.wait, &wait);
+
+ if (flags & I915_WAIT_LOCKED)
--- /dev/null
+From 998d75730b40afc218c059d811869abe9676b305 Mon Sep 17 00:00:00 2001
+From: Hans de Goede <hdegoede@redhat.com>
+Date: Tue, 14 Feb 2017 18:12:38 +0200
+Subject: drm/i915: Fix not finding the VBT when it overlaps with OPREGION_ASLE_EXT
+
+From: Hans de Goede <hdegoede@redhat.com>
+
+commit 998d75730b40afc218c059d811869abe9676b305 upstream.
+
+If there is no OPREGION_ASLE_EXT then a VBT stored in mailbox #4 may
+use the ASLE_EXT parts of the opregion. Adjust the vbt_size calculation
+for a vbt in mailbox #4 for this.
+
+This fixes the driver not finding the VBT on a jumper ezpad mini3
+cherrytrail tablet and on a ACER SW5_017 machine.
+
+Signed-off-by: Hans de Goede <hdegoede@redhat.com>
+Signed-off-by: Jani Nikula <jani.nikula@intel.com>
+Link: http://patchwork.freedesktop.org/patch/msgid/1487088758-30050-1-git-send-email-jani.nikula@intel.com
+(cherry picked from commit dfb65e71ea2c1d97ac373cc0587dc60b3307581a)
+Signed-off-by: Jani Nikula <jani.nikula@intel.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/gpu/drm/i915/intel_opregion.c | 13 ++++++++++++-
+ 1 file changed, 12 insertions(+), 1 deletion(-)
+
+--- a/drivers/gpu/drm/i915/intel_opregion.c
++++ b/drivers/gpu/drm/i915/intel_opregion.c
+@@ -982,7 +982,18 @@ int intel_opregion_setup(struct drm_i915
+ opregion->vbt_size = vbt_size;
+ } else {
+ vbt = base + OPREGION_VBT_OFFSET;
+- vbt_size = OPREGION_ASLE_EXT_OFFSET - OPREGION_VBT_OFFSET;
++ /*
++ * The VBT specification says that if the ASLE ext
++ * mailbox is not used its area is reserved, but
++ * on some CHT boards the VBT extends into the
++ * ASLE ext area. Allow this even though it is
++ * against the spec, so we do not end up rejecting
++ * the VBT on those boards (and end up not finding the
++ * LCD panel because of this).
++ */
++ vbt_size = (mboxes & MBOX_ASLE_EXT) ?
++ OPREGION_ASLE_EXT_OFFSET : OPREGION_SIZE;
++ vbt_size -= OPREGION_VBT_OFFSET;
+ if (intel_bios_is_valid_vbt(vbt, vbt_size)) {
+ DRM_DEBUG_KMS("Found valid VBT in ACPI OpRegion (Mailbox #4)\n");
+ opregion->vbt = vbt;
--- /dev/null
+From 636deb5b2277cf57bb0f5e00fc9687de9a96061e Mon Sep 17 00:00:00 2001
+From: Chris Wilson <chris@chris-wilson.co.uk>
+Date: Sun, 12 Feb 2017 21:53:43 +0000
+Subject: drm/i915: Pass timeout==0 on to i915_gem_object_wait_fence()
+
+From: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 636deb5b2277cf57bb0f5e00fc9687de9a96061e upstream.
+
+The i915_gem_object_wait_fence() uses an incoming timeout=0 to query
+whether the current fence is busy or idle, without waiting. This can be
+used by the wait-ioctl to implement a busy query.
+
+Fixes: e95433c73a11 ("drm/i915: Rearrange i915_wait_request() accounting with callers")
+Testcase: igt/gem_wait/basic-busy-write-all
+Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+Cc: Matthew Auld <matthew.william.auld@gmail.com>
+Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
+Cc: <drm-intel-fixes@lists.freedesktop.org> # v4.10-rc1+
+Link: http://patchwork.freedesktop.org/patch/msgid/20170212215344.16600-1-chris@chris-wilson.co.uk
+Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
+(cherry picked from commit d892e9398ecf6defc7972a62227b77dad6be20bd)
+Signed-off-by: Jani Nikula <jani.nikula@intel.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/gpu/drm/i915/i915_gem.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+--- a/drivers/gpu/drm/i915/i915_gem.c
++++ b/drivers/gpu/drm/i915/i915_gem.c
+@@ -440,7 +440,7 @@ i915_gem_object_wait_reservation(struct
+ timeout = i915_gem_object_wait_fence(shared[i],
+ flags, timeout,
+ rps);
+- if (timeout <= 0)
++ if (timeout < 0)
+ break;
+
+ dma_fence_put(shared[i]);
+@@ -453,7 +453,7 @@ i915_gem_object_wait_reservation(struct
+ excl = reservation_object_get_excl_rcu(resv);
+ }
+
+- if (excl && timeout > 0)
++ if (excl && timeout >= 0)
+ timeout = i915_gem_object_wait_fence(excl, flags, timeout, rps);
+
+ dma_fence_put(excl);
--- /dev/null
+From 2d2cfc12b1270c8451edc7d2dd5f79097b3a17d8 Mon Sep 17 00:00:00 2001
+From: Chris Wilson <chris@chris-wilson.co.uk>
+Date: Thu, 2 Feb 2017 13:27:21 +0000
+Subject: drm/i915: Recreate internal objects with single page segments if dmar fails
+
+From: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2d2cfc12b1270c8451edc7d2dd5f79097b3a17d8 upstream.
+
+If we fail to dma-map the object, the most common cause is lack of space
+inside the SW-IOTLB due to fragmentation. If we recreate the_sg_table
+using segments of PAGE_SIZE (and single page allocations), we may succeed
+in remapping the scatterlist.
+
+First became a significant problem for the mock selftests after commit
+5584f1b1d73e ("drm/i915: fix i915 running as dom0 under Xen") increased
+the max_order.
+
+Fixes: 920cf4194954 ("drm/i915: Introduce an internal allocator for disposable private objects")
+Fixes: 5584f1b1d73e ("drm/i915: fix i915 running as dom0 under Xen")
+Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
+Link: http://patchwork.freedesktop.org/patch/msgid/20170202132721.12711-1-chris@chris-wilson.co.uk
+Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
+(cherry picked from commit bb96dcf5830e5d81a1da2e2a14e6c0f7dfc64348)
+Signed-off-by: Jani Nikula <jani.nikula@intel.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/gpu/drm/i915/i915_gem_internal.c | 37 +++++++++++++++++++------------
+ 1 file changed, 23 insertions(+), 14 deletions(-)
+
+--- a/drivers/gpu/drm/i915/i915_gem_internal.c
++++ b/drivers/gpu/drm/i915/i915_gem_internal.c
+@@ -46,24 +46,12 @@ static struct sg_table *
+ i915_gem_object_get_pages_internal(struct drm_i915_gem_object *obj)
+ {
+ struct drm_i915_private *i915 = to_i915(obj->base.dev);
+- unsigned int npages = obj->base.size / PAGE_SIZE;
+ struct sg_table *st;
+ struct scatterlist *sg;
++ unsigned int npages;
+ int max_order;
+ gfp_t gfp;
+
+- st = kmalloc(sizeof(*st), GFP_KERNEL);
+- if (!st)
+- return ERR_PTR(-ENOMEM);
+-
+- if (sg_alloc_table(st, npages, GFP_KERNEL)) {
+- kfree(st);
+- return ERR_PTR(-ENOMEM);
+- }
+-
+- sg = st->sgl;
+- st->nents = 0;
+-
+ max_order = MAX_ORDER;
+ #ifdef CONFIG_SWIOTLB
+ if (swiotlb_nr_tbl()) {
+@@ -85,6 +73,20 @@ i915_gem_object_get_pages_internal(struc
+ gfp |= __GFP_DMA32;
+ }
+
++create_st:
++ st = kmalloc(sizeof(*st), GFP_KERNEL);
++ if (!st)
++ return ERR_PTR(-ENOMEM);
++
++ npages = obj->base.size / PAGE_SIZE;
++ if (sg_alloc_table(st, npages, GFP_KERNEL)) {
++ kfree(st);
++ return ERR_PTR(-ENOMEM);
++ }
++
++ sg = st->sgl;
++ st->nents = 0;
++
+ do {
+ int order = min(fls(npages) - 1, max_order);
+ struct page *page;
+@@ -112,8 +114,15 @@ i915_gem_object_get_pages_internal(struc
+ sg = __sg_next(sg);
+ } while (1);
+
+- if (i915_gem_gtt_prepare_pages(obj, st))
++ if (i915_gem_gtt_prepare_pages(obj, st)) {
++ /* Failed to dma-map try again with single page sg segments */
++ if (get_order(st->sgl->length)) {
++ internal_free_pages(st);
++ max_order = 0;
++ goto create_st;
++ }
+ goto err;
++ }
+
+ /* Mark the pages as dontneed whilst they are still pinned. As soon
+ * as they are unpinned they are allowed to be reaped by the shrinker,
drm-i915-gvt-disable-access-to-stolen-memory-as-a-guest.patch
drm-cancel-drm_fb_helper_dirty_work-on-unload.patch
drm-cancel-drm_fb_helper_resume_work-on-unload.patch
+drm-i915-recreate-internal-objects-with-single-page-segments-if-dmar-fails.patch
+drm-i915-avoid-spurious-warns-about-the-wrong-pipe-in-the-pps-code.patch
+drm-i915-check-for-timeout-completion-when-waiting-for-the-rq-to-submitted.patch
+drm-i915-pass-timeout-0-on-to-i915_gem_object_wait_fence.patch
+drm-i915-fix-not-finding-the-vbt-when-it-overlaps-with-opregion_asle_ext.patch