From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Vetter Subject: Re: [PATCH v2 5/6] drm/i915: Don't clobber the GTT when it's within stolen memory Date: Mon, 7 Jul 2014 11:02:10 +0200 Message-ID: <20140707090210.GI5821@phenom.ffwll.local> References: <1386085793-317-6-git-send-email-ville.syrjala@linux.intel.com> <1401987779-6372-1-git-send-email-ville.syrjala@linux.intel.com> <87bntaitie.fsf@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Received: from mail-wg0-f49.google.com (mail-wg0-f49.google.com [74.125.82.49]) by gabe.freedesktop.org (Postfix) with ESMTP id 4DEBB6E295 for ; Mon, 7 Jul 2014 02:02:00 -0700 (PDT) Received: by mail-wg0-f49.google.com with SMTP id a1so649852wgh.20 for ; Mon, 07 Jul 2014 02:01:59 -0700 (PDT) Content-Disposition: inline In-Reply-To: <87bntaitie.fsf@intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" To: Jani Nikula Cc: intel-gfx@lists.freedesktop.org List-Id: intel-gfx@lists.freedesktop.org On Mon, Jun 30, 2014 at 01:25:29PM +0300, Jani Nikula wrote: > On Thu, 05 Jun 2014, ville.syrjala@linux.intel.com wrote: > > From: Ville Syrj=E4l=E4 > > > > On most gen2-4 platforms the GTT can be (or maybe always is?) > > inside the stolen memory region. If that's the case, reduce the > > size of the stolen memory appropriately to make make sure we > > don't clobber the GTT. > > > > v2: Deal with gen4 36 bit physical address > = > Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=3D80151 Picked up for -fixes (with Chris' irc-ack and cc: stable), thanks for the patch. -Daniel > = > > Signed-off-by: Ville Syrj=E4l=E4 > > --- > > drivers/gpu/drm/i915/i915_gem_stolen.c | 44 ++++++++++++++++++++++++++= ++++++++ > > drivers/gpu/drm/i915/i915_reg.h | 3 +++ > > 2 files changed, 47 insertions(+) > > > > diff --git a/drivers/gpu/drm/i915/i915_gem_stolen.c b/drivers/gpu/drm/i= 915/i915_gem_stolen.c > > index 62ef55b..7465ab0 100644 > > --- a/drivers/gpu/drm/i915/i915_gem_stolen.c > > +++ b/drivers/gpu/drm/i915/i915_gem_stolen.c > > @@ -74,6 +74,50 @@ static unsigned long i915_stolen_to_physical(struct = drm_device *dev) > > if (base =3D=3D 0) > > return 0; > > = > > + /* make sure we don't clobber the GTT if it's within stolen memory */ > > + if (INTEL_INFO(dev)->gen <=3D 4 && !IS_G33(dev) && !IS_G4X(dev)) { > > + struct { > > + u32 start, end; > > + } stolen[2] =3D { > > + { .start =3D base, .end =3D base + dev_priv->gtt.stolen_size, }, > > + { .start =3D base, .end =3D base + dev_priv->gtt.stolen_size, }, > > + }; > > + u64 gtt_start, gtt_end; > > + > > + gtt_start =3D I915_READ(PGTBL_CTL); > > + if (IS_GEN4(dev)) > > + gtt_start =3D (gtt_start & PGTBL_ADDRESS_LO_MASK) | > > + (gtt_start & PGTBL_ADDRESS_HI_MASK) << 28; > > + else > > + gtt_start &=3D PGTBL_ADDRESS_LO_MASK; > > + gtt_end =3D gtt_start + gtt_total_entries(dev_priv->gtt) * 4; > > + > > + if (gtt_start >=3D stolen[0].start && gtt_start < stolen[0].end) > > + stolen[0].end =3D gtt_start; > > + if (gtt_end > stolen[1].start && gtt_end <=3D stolen[1].end) > > + stolen[1].start =3D gtt_end; > > + > > + /* pick the larger of the two chunks */ > > + if (stolen[0].end - stolen[0].start > > > + stolen[1].end - stolen[1].start) { > > + base =3D stolen[0].start; > > + dev_priv->gtt.stolen_size =3D stolen[0].end - stolen[0].start; > > + } else { > > + base =3D stolen[1].start; > > + dev_priv->gtt.stolen_size =3D stolen[1].end - stolen[1].start; > > + } > > + > > + if (stolen[0].start !=3D stolen[1].start || > > + stolen[0].end !=3D stolen[1].end) { > > + DRM_DEBUG_KMS("GTT within stolen memory at 0x%llx-0x%llx\n", > > + (unsigned long long) gtt_start, > > + (unsigned long long) gtt_end - 1); > > + DRM_DEBUG_KMS("Stolen memory adjusted to 0x%x-0x%x\n", > > + base, base + (u32) dev_priv->gtt.stolen_size - 1); > > + } > > + } > > + > > + > > /* Verify that nothing else uses this physical address. Stolen > > * memory should be reserved by the BIOS and hidden from the > > * kernel. So if the region is already marked as busy, something > > diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i91= 5_reg.h > > index 247be2a..619924b 100644 > > --- a/drivers/gpu/drm/i915/i915_reg.h > > +++ b/drivers/gpu/drm/i915/i915_reg.h > > @@ -978,6 +978,9 @@ enum punit_power_well { > > /* > > * Instruction and interrupt control regs > > */ > > +#define PGTBL_CTL 0x02020 > > +#define PGTBL_ADDRESS_LO_MASK 0xfffff000 /* bits [31:12] */ > > +#define PGTBL_ADDRESS_HI_MASK 0x000000f0 /* bits [35:32] (gen4) */ > > #define PGTBL_ER 0x02024 > > #define RENDER_RING_BASE 0x02000 > > #define BSD_RING_BASE 0x04000 > > -- = > > 1.8.5.5 > > > > _______________________________________________ > > Intel-gfx mailing list > > Intel-gfx@lists.freedesktop.org > > http://lists.freedesktop.org/mailman/listinfo/intel-gfx > = > -- = > Jani Nikula, Intel Open Source Technology Center > _______________________________________________ > Intel-gfx mailing list > Intel-gfx@lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/intel-gfx -- = Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch