dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: David Herrmann <dh.herrmann@gmail.com>
To: dri-devel@lists.freedesktop.org
Subject: [PATCH v5 2/7] x86/sysfb: fix lfb_size calculation
Date: Fri,  2 Sep 2016 10:22:40 +0200	[thread overview]
Message-ID: <20160902082245.7119-3-dh.herrmann@gmail.com> (raw)
In-Reply-To: <20160902082245.7119-1-dh.herrmann@gmail.com>

The screen_info.lfb_size field is shifted by 16 bits *only* in case of
VBE. This has historical reasons since VBE advertised it similarly.
However, in case of EFI framebuffers, the size is no longer shifted. Fix
the x86 simple-framebuffer setup code to use the correct size in the
non-VBE case.

While at it, avoid variable abbreviations and rename 'len' to 'length',
and use the correct types matching the screen_info definition.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
---
 arch/x86/kernel/sysfb_simplefb.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kernel/sysfb_simplefb.c b/arch/x86/kernel/sysfb_simplefb.c
index 35b8641..85195d4 100644
--- a/arch/x86/kernel/sysfb_simplefb.c
+++ b/arch/x86/kernel/sysfb_simplefb.c
@@ -66,8 +66,8 @@ __init int create_simplefb(const struct screen_info *si,
 {
 	struct platform_device *pd;
 	struct resource res;
-	unsigned long len;
-	u64 base;
+	u64 base, size;
+	u32 length;
 
 	/*
 	 * If the 64BIT_BASE capability is set, ext_lfb_base will contain the
@@ -82,11 +82,20 @@ __init int create_simplefb(const struct screen_info *si,
 		return -EINVAL;
 	}
 
-	/* don't use lfb_size as it may contain the whole VMEM instead of only
-	 * the part that is occupied by the framebuffer */
-	len = mode->height * mode->stride;
-	len = PAGE_ALIGN(len);
-	if (len > (u64)si->lfb_size << 16) {
+	/*
+	 * Don't use lfb_size as IORESOURCE size, since it may contain the
+	 * entire VMEM, and thus require huge mappings. Use just the part we
+	 * need, that is, the part where the framebuffer is located. But verify
+	 * that it does not exceed the advertised VMEM.
+	 * Note that in case of VBE, the lfb_size is shifted by 16 bits for
+	 * historical reasons.
+	 */
+	size = si->lfb_size;
+	if (si->orig_video_isVGA == VIDEO_TYPE_VLFB)
+		size <<= 16;
+	length = mode->height * mode->stride;
+	length = PAGE_ALIGN(length);
+	if (length > size) {
 		printk(KERN_WARNING "sysfb: VRAM smaller than advertised\n");
 		return -EINVAL;
 	}
@@ -96,7 +105,7 @@ __init int create_simplefb(const struct screen_info *si,
 	res.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
 	res.name = simplefb_resname;
 	res.start = base;
-	res.end = res.start + len - 1;
+	res.end = res.start + length - 1;
 	if (res.end <= res.start)
 		return -EINVAL;
 
-- 
2.9.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2016-09-02  8:23 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-02  8:22 [PATCH v5 0/7] drm: add simpledrm driver David Herrmann
2016-09-02  8:22 ` [PATCH v5 1/7] x86/sysfb: add support for 64bit EFI lfb_base David Herrmann
2016-09-02 10:20   ` Tom Gundersen
2016-09-02  8:22 ` David Herrmann [this message]
2016-09-02 10:20   ` [PATCH v5 2/7] x86/sysfb: fix lfb_size calculation Tom Gundersen
2016-09-02  8:22 ` [PATCH v5 3/7] of/platform: expose of_platform_device_destroy() David Herrmann
2016-09-02 10:21   ` Tom Gundersen
2016-09-02  8:22 ` [PATCH v5 4/7] video: add generic framebuffer eviction David Herrmann
2016-09-02 10:21   ` Tom Gundersen
2016-09-03 12:06   ` Noralf Trønnes
2016-09-05 11:19     ` David Herrmann
2016-09-05 16:36       ` Noralf Trønnes
2016-09-02  8:22 ` [PATCH v5 5/7] drm: switch to sysfb_evict_conflicts() David Herrmann
2016-09-03 12:13   ` Noralf Trønnes
2016-09-02  8:22 ` [PATCH v5 6/7] drm: add SimpleDRM driver David Herrmann
2016-09-02 12:45   ` Tom Gundersen
2016-09-03 12:01   ` Noralf Trønnes
2016-09-03 12:05     ` David Herrmann
2016-09-05 16:39   ` Noralf Trønnes
2016-09-02  8:22 ` [PATCH v5 7/7] drm/simpledrm: add fbdev fallback support David Herrmann
2016-09-03 12:04   ` Noralf Trønnes
2016-09-03 17:15     ` Noralf Trønnes
2016-09-05 11:21       ` David Herrmann
2021-03-10  2:50 ` [PATCH v5 0/7] drm: add simpledrm driver nerdopolis
2021-03-10  9:10   ` Thomas Zimmermann
2021-03-10 13:52     ` nerdopolis
2021-03-12  3:49     ` nerdopolis
2021-03-12  8:03       ` Thomas Zimmermann
2021-03-12 13:25         ` nerdopolis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160902082245.7119-3-dh.herrmann@gmail.com \
    --to=dh.herrmann@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).