From: Tomi Valkeinen Subject: Re: [PATCH] drm/omap: fix tiled buffer stride calculations Date: Thu, 18 May 2017 14:34:09 +0300 Message-ID: References: <1495103306-7041-1-git-send-email-tomi.valkeinen@ti.com> <1779275.QoS2HsWmdB@avalon> <7c0b4d6f-c5f8-718a-36c3-7aea832cccf2@ti.com> <2015275.D39OfZYjN5@avalon> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1102361640==" Return-path: Received: from fllnx210.ext.ti.com (fllnx210.ext.ti.com [198.47.19.17]) by gabe.freedesktop.org (Postfix) with ESMTPS id 24CFD6E157 for ; Thu, 18 May 2017 11:34:15 +0000 (UTC) In-Reply-To: <2015275.D39OfZYjN5@avalon> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To: Laurent Pinchart Cc: Jyri Sarha , dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org --===============1102361640== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="3iIGcfVMJcQKD8mKaiek5lW5UsD2mPCeh" --3iIGcfVMJcQKD8mKaiek5lW5UsD2mPCeh Content-Type: multipart/mixed; boundary="0D3jWeS7IGNcsTGtkwiRi2BMwGP3LfoGm"; protected-headers="v1" From: Tomi Valkeinen To: Laurent Pinchart Cc: dri-devel@lists.freedesktop.org, Jyri Sarha Message-ID: Subject: Re: [PATCH] drm/omap: fix tiled buffer stride calculations References: <1495103306-7041-1-git-send-email-tomi.valkeinen@ti.com> <1779275.QoS2HsWmdB@avalon> <7c0b4d6f-c5f8-718a-36c3-7aea832cccf2@ti.com> <2015275.D39OfZYjN5@avalon> In-Reply-To: <2015275.D39OfZYjN5@avalon> --0D3jWeS7IGNcsTGtkwiRi2BMwGP3LfoGm Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 18/05/17 14:25, Laurent Pinchart wrote: > Hi Tomi, >=20 > On Thursday 18 May 2017 14:14:35 Tomi Valkeinen wrote: >> On 18/05/17 13:59, Laurent Pinchart wrote: >>> On Thursday 18 May 2017 13:28:26 Tomi Valkeinen wrote: >>>> omap_gem uses page alignment for buffer stride. The related calculat= ions >>>> are a bit off, though, as byte stride of 4096 gets aligned to 8192, >>>> instead of 4096. This patch fixes those calculations. >>>> >>>> Signed-off-by: Tomi Valkeinen >>>> --- >>>> >>>> drivers/gpu/drm/omapdrm/omap_gem.c | 4 ++-- >>>> 1 file changed, 2 insertions(+), 2 deletions(-) >>>> >>>> diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c >>>> b/drivers/gpu/drm/omapdrm/omap_gem.c index 13abf221d153..4c41000ff4c= 4 >>>> 100644 >>>> --- a/drivers/gpu/drm/omapdrm/omap_gem.c >>>> +++ b/drivers/gpu/drm/omapdrm/omap_gem.c >>>> @@ -182,7 +182,7 @@ static void evict_entry(struct drm_gem_object *o= bj, >>>> size_t size =3D PAGE_SIZE * n; >>>> loff_t off =3D mmap_offset(obj) + >>>> (entry->obj_pgoff << PAGE_SHIFT); >>>> - const int m =3D 1 + ((omap_obj->width << fmt) / PAGE_SIZE); >>>> + const int m =3D 1 + (((omap_obj->width - 1) << fmt) / PAGE_SIZE); >>> >>> How about >>> >>> int m =3D round_up(omap_obj->width << fmt, PAGE_SIZE); >>> >>> instead of open-coding it ? I find that a bit easier to understand. >> >> That should be: >> >> round_up(omap_obj->width << fmt, PAGE_SIZE) / PAGE_SIZE; >=20 > Sorry, I meant DIV_ROUND_UP, not round_up. Ah, of course. Not my day... =3D) From: Tomi Valkeinen Date: Thu, 18 May 2017 11:51:51 +0300 Subject: [PATCH] drm/omap: fix tiled buffer stride calculations omap_gem uses page alignment for buffer stride. The related calculations are a bit off, though, as byte stride of 4096 gets aligned to 8192, instead of 4096. This patch changes the code to use DIV_ROUND_UP(), which fixes those calculations and makes them more readable. Signed-off-by: Tomi Valkeinen diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c b/drivers/gpu/drm/omapdrm= /omap_gem.c index 13abf221d153..5c5c86ddd6f4 100644 --- a/drivers/gpu/drm/omapdrm/omap_gem.c +++ b/drivers/gpu/drm/omapdrm/omap_gem.c @@ -182,7 +182,7 @@ static void evict_entry(struct drm_gem_object *obj, size_t size =3D PAGE_SIZE * n; loff_t off =3D mmap_offset(obj) + (entry->obj_pgoff << PAGE_SHIFT); - const int m =3D 1 + ((omap_obj->width << fmt) / PAGE_SIZE); + const int m =3D DIV_ROUND_UP(omap_obj->width << fmt, PAGE_SIZE); =20 if (m > 1) { int i; @@ -424,7 +424,7 @@ static int fault_2d(struct drm_gem_object *obj, * into account in some of the math, so figure out virtual stride * in pages */ - const int m =3D 1 + ((omap_obj->width << fmt) / PAGE_SIZE); + const int m =3D DIV_ROUND_UP(omap_obj->width << fmt, PAGE_SIZE); =20 /* We don't use vmf->pgoff since that has the fake offset: */ pgoff =3D (vmf->address - vma->vm_start) >> PAGE_SHIFT; --0D3jWeS7IGNcsTGtkwiRi2BMwGP3LfoGm-- --3iIGcfVMJcQKD8mKaiek5lW5UsD2mPCeh Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJZHYayAAoJEPo9qoy8lh71jSIP/i4cJPVF2adfH70k8ZprryDe VNIGkLqhJ6aqRyVhQSWOfHkcDmiyVevIRrygQziPuhDdxZUZMUQivYisnRQ70lkw TAh0rkG1piEf/XlLMv0yOvoqBBXIwzMz9PoyriWmtp0/9PZtPtscjPR14X9yCrgW 5jAm4Y91X7m+oiZjB/blLrA46tEv+9DEDCOEmiQk/3ZH8EnxHeWER8D5YH/R4p/K 0UdDODFAjYd0Nh5dsQIPFbZ+v5tep3QIeU8z1hVLla8HkQNdXiPod2Zj7mFMI/Ic 8lNXckSL5HHf0lvIcYloE2ZkZ0W3Yw6JbGJI9dO4fW6S2qzxn4u933Ep1nL/lic7 dfX9Df6gYlnIOMumJUJmDsNQ1WBNQVCl7OtAUwk4B5TKpzwU09LUpIJRK0PJm71U CCA5OlhWCimaJAbQEfH2wkEgiZrxPl7UTQiOeISoBJJJi6oOAu/ktKczpzm2K8Ve i+4heO4RnOLDrR6B915cSJ+zvyQyEF7ExURjt8VSV2bwZ+lp+SfWo8DNDwKwilIe qzgWkWvn3SNs2kW0wJoFGx7ot04ZF6k7pUiL4Eds5MmBOX71H4d08uEizt+TsLEE h9OZa87ISXAA3JiPGFFbYErhST6460vPr/zFHMLFNDsH/MuP0zPgTsk7PAcBy/LO Lj2d9x/5Jn/hZaDv56X/ =jzon -----END PGP SIGNATURE----- --3iIGcfVMJcQKD8mKaiek5lW5UsD2mPCeh-- --===============1102361640== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KZHJpLWRldmVs IG1haWxpbmcgbGlzdApkcmktZGV2ZWxAbGlzdHMuZnJlZWRlc2t0b3Aub3JnCmh0dHBzOi8vbGlz dHMuZnJlZWRlc2t0b3Aub3JnL21haWxtYW4vbGlzdGluZm8vZHJpLWRldmVsCg== --===============1102361640==--