From patchwork Tue Oct 7 19:49:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zach Reizner X-Patchwork-Id: 5050841 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EE622C11AC for ; Wed, 8 Oct 2014 01:56:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 21FCA20220 for ; Wed, 8 Oct 2014 01:56:45 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 5358E201BC for ; Wed, 8 Oct 2014 01:56:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 21F976E088; Tue, 7 Oct 2014 18:56:41 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pa0-f47.google.com (mail-pa0-f47.google.com [209.85.220.47]) by gabe.freedesktop.org (Postfix) with ESMTP id BEF1B89CB2 for ; Tue, 7 Oct 2014 12:51:29 -0700 (PDT) Received: by mail-pa0-f47.google.com with SMTP id rd3so7735793pab.20 for ; Tue, 07 Oct 2014 12:51:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=EpegG0m3DZDRD7txbsjV12xHG4851oZ0u61MNxRi1kc=; b=cqpWFqBRVI2VEokP+bLinm/U0UVgI9JKs+drPV9d85QsqihBrntAEnHO7d3uql6e8N Ba+Jo7iLYADKDjHr1OWCszLqipDzt33EAHFD1898ijQmqu6Ihjz6gtLRKnSVvsjJPbTg aL5hD3v6Yp3W4Uh9s58wI5ZYuTvFhFHkww5vR9e2u922wvnqIDWtWwacv0wx5EYMg4S0 8/me5qgqBWbswAyLPHEFWOVFr/tWuo/boI44I9qkaseJLnktgt07K0vr9GaUeyDBsXKE SmH/MdqK/8GQpehdKZGrScbPDqJx+J9uEfLInVjWUTpjXYKSAJ50Eqbx0hjXBgyTMiEU QmHA== 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; bh=EpegG0m3DZDRD7txbsjV12xHG4851oZ0u61MNxRi1kc=; b=C+6btTfsI5c2tv+GPtQF7idZVDMCCO4v/opBtT9UtME9zaAsv8q9JSg/IQtqNGgVLd RUCkFdZGsG2oRyZl8AS1FVzT4AqKArM1yR9FBbdIlQhDnYHgdIpUdxu/nsX6/PJXMz8Y pIrNGGec9ujEvHrbdYqUe2+qrwBxGmZmpaq2T+e1Ja8pMPrO7FwdyX+wNZ348j2uAZVX kJxyOoG/kWdRVvDa2ToW4WmWgH1c7ylVfOBSzILeqb2U1f2zxy/rIAP4p5MqwqQlU7gY 6zrDj3IFk5tqMj6bFCOnOMUb7VWsulpIXKY/ro9zyP7ZghATsqizK0SQPTro9BatFFwa x8HQ== X-Gm-Message-State: ALoCoQnz+BmKrhx9pzktUV2qDVLU5QmorVjpg8LUe5RaMx2Ms75zAJRkP7v1UeU8zXopb4mxCSgL X-Received: by 10.68.132.105 with SMTP id ot9mr5644218pbb.76.1412711489185; Tue, 07 Oct 2014 12:51:29 -0700 (PDT) Received: from aluna.mtv.corp.google.com (aluna.mtv.corp.google.com [172.22.65.150]) by mx.google.com with ESMTPSA id fg1sm10502377pdb.91.2014.10.07.12.51.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Oct 2014 12:51:28 -0700 (PDT) From: Zach Reizner To: dri-devel@lists.freedesktop.org Subject: [PATCH] allow 32bpp framebuffers for cirrus drm Date: Tue, 7 Oct 2014 12:49:17 -0700 Message-Id: <1412711357-23299-1-git-send-email-zachr@google.com> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 X-Mailman-Approved-At: Tue, 07 Oct 2014 18:56:36 -0700 Cc: Zach Reizner X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 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-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,RCVD_IN_DNSWL_MED,T_DKIM_INVALID,T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch allows framebuffers for cirrus to be created with 32bpp pixel formats provided that they do not violate certain restrictions of the cirrus hardware. Signed-off-by: Zach Reizner Reviewed-by: Stéphane Marchesin --- drivers/gpu/drm/cirrus/cirrus_drv.h | 2 ++ drivers/gpu/drm/cirrus/cirrus_fbdev.c | 4 +++- drivers/gpu/drm/cirrus/cirrus_main.c | 22 ++++++++++++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/cirrus/cirrus_drv.h b/drivers/gpu/drm/cirrus/cirrus_drv.h index 401c890..fac475c 100644 --- a/drivers/gpu/drm/cirrus/cirrus_drv.h +++ b/drivers/gpu/drm/cirrus/cirrus_drv.h @@ -208,6 +208,8 @@ int cirrus_framebuffer_init(struct drm_device *dev, struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object *obj); +bool cirrus_check_framebuffer(int width, int height, int bpp, int pitch); + /* cirrus_display.c */ int cirrus_modeset_init(struct cirrus_device *cdev); void cirrus_modeset_fini(struct cirrus_device *cdev); diff --git a/drivers/gpu/drm/cirrus/cirrus_fbdev.c b/drivers/gpu/drm/cirrus/cirrus_fbdev.c index 2a135f2..4a0756c 100644 --- a/drivers/gpu/drm/cirrus/cirrus_fbdev.c +++ b/drivers/gpu/drm/cirrus/cirrus_fbdev.c @@ -146,8 +146,10 @@ static int cirrusfb_create_object(struct cirrus_fbdev *afbdev, int ret = 0; drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp); - if (bpp > 24) + if (!cirrus_check_framebuffer(mode_cmd->width, mode_cmd->height, bpp, + mode_cmd->pitches[0])) return -EINVAL; + size = mode_cmd->pitches[0] * mode_cmd->height; ret = cirrus_gem_create(dev, size, true, &gobj); if (ret) diff --git a/drivers/gpu/drm/cirrus/cirrus_main.c b/drivers/gpu/drm/cirrus/cirrus_main.c index 99c1983..029f9e9 100644 --- a/drivers/gpu/drm/cirrus/cirrus_main.c +++ b/drivers/gpu/drm/cirrus/cirrus_main.c @@ -55,8 +55,9 @@ cirrus_user_framebuffer_create(struct drm_device *dev, u32 bpp, depth; drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp); - /* cirrus can't handle > 24bpp framebuffers at all */ - if (bpp > 24) + + if (!cirrus_check_framebuffer(mode_cmd->width, mode_cmd->height, + bpp, mode_cmd->pitches[0])) return ERR_PTR(-EINVAL); obj = drm_gem_object_lookup(dev, filp, mode_cmd->handles[0]); @@ -307,3 +308,20 @@ out_unlock: return ret; } + +bool cirrus_check_framebuffer(int width, int height, int bpp, int pitch) +{ + const int max_pitch = 0x1FF << 3; /* (4096 - 1) & ~111b bytes */ + const int max_size = 0x400000; /* 4MB */ + + if (bpp > 32) + return false; + + if (pitch > max_pitch) + return false; + + if (pitch * height > max_size) + return false; + + return true; +}