From patchwork Fri Sep 2 08:22:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 9310549 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7141660756 for ; Fri, 2 Sep 2016 08:23:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 638922970D for ; Fri, 2 Sep 2016 08:23:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 581532970F; Fri, 2 Sep 2016 08:23:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 11DAF2970D for ; Fri, 2 Sep 2016 08:23:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D915B6EA33; Fri, 2 Sep 2016 08:23:20 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id A36B56EA30 for ; Fri, 2 Sep 2016 08:23:19 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id v143so1840399wmv.1 for ; Fri, 02 Sep 2016 01:23:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XLldVhrZD8sz/TCxfMRF/Ib9GRj5GtiQSImgsP6UccY=; b=spIOxTm/uvXOZY4IOUm/jfqTkdoDsn2ivcSGvKBoFgZlk1BiQVtJNUHbrBsXNwguo4 f0m7OTjLpVqa6ReatSaiNR2SacAcGcJea1Xze/PApwxZV2Yc7OKFzhQ3q2YVLLhsQwyb Xxgkl2xnut+2Gyk/zHxMu2ay7W5DdIYfOyPpqVzRTs2wZ9DUBDVg3zmYjPxyt/gwWLDy kNiIwF4+4F9CiVKY8GW8mUGgKPdJLZbjNyiIDuqRlS5jqZS+oVHK+g0nCJHzF6yobbZ1 4Cb3TywNgP4AXVItqXUZ1PcjSX1ogKBMOHvVb9Y3Q8ke2Fp73ggYYLK7On40bCIozTOh KfyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XLldVhrZD8sz/TCxfMRF/Ib9GRj5GtiQSImgsP6UccY=; b=d+9uCoRomqChGfjMP/H7oxGVWhtu2Wqyr69uVYjZ9ud/j0deQkpIUC0h7P8ujGS3Re JUvdGwMzoBuxJ6b+NzkqZupMg/UP60apy0/OZHgplqKrOq8NwQMpMpCQ2Vy7hkkOtxww ML1lYrIx6coHmZWy8nTvCpig2tebct2M4iAGckDSW5NsYtPaHzgC1vqXMmKSOoMqw0rD mh/VYn5yyErvV2A4zmX3UMmzwtw1ywb2DhFYsPWWSKOVmMOO9t5QIsUlnVKh4BcVnAO3 cPjfdBmCpVA+Z1YThI6/cXYI0jxmLwoU7ezZWPutjOwsr1J3qCMOv/yC4o49a9RIKnwl ONKg== X-Gm-Message-State: AE9vXwNeqlEUIeCU1j4g2eh0mEbQlqX8+YaMLZ6937pVtlp3SVc6MxiKxD/rB7+nq0zFlQ== X-Received: by 10.194.89.9 with SMTP id bk9mr17522915wjb.181.1472804598329; Fri, 02 Sep 2016 01:23:18 -0700 (PDT) Received: from localhost.localdomain ([37.120.93.201]) by smtp.gmail.com with ESMTPSA id gg10sm9325662wjd.4.2016.09.02.01.23.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Sep 2016 01:23:17 -0700 (PDT) From: David Herrmann 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 Message-Id: <20160902082245.7119-3-dh.herrmann@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160902082245.7119-1-dh.herrmann@gmail.com> References: <20160902082245.7119-1-dh.herrmann@gmail.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Tom Gundersen --- 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;