From patchwork Wed Oct 29 18:04:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zach Reizner X-Patchwork-Id: 5190821 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 DE285C11AC for ; Wed, 29 Oct 2014 18:04:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 05E53201ED for ; Wed, 29 Oct 2014 18:04:45 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 2419120179 for ; Wed, 29 Oct 2014 18:04:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 656736E5B1; Wed, 29 Oct 2014 11:04:42 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-vc0-f201.google.com (mail-vc0-f201.google.com [209.85.220.201]) by gabe.freedesktop.org (Postfix) with ESMTP id 58E276E5B1 for ; Wed, 29 Oct 2014 11:04:41 -0700 (PDT) Received: by mail-vc0-f201.google.com with SMTP id hq11so238431vcb.2 for ; Wed, 29 Oct 2014 11:04:40 -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=ZpTnRD05maIChe8yVDDcKVzTVU41jZD7yC8icYnBxeU=; b=N2WcqTPIo3KrfRIek4I1jJEnO9/rHhJ7oxmKs2KZkJCvt3Ep1Dm90qY//0q3hkgS4B Hcrq9nyOUHet0fxlMuTYn8jLMlJeqmUj5HU196O19+QWiBA7OiPpN5PLm5WlyvM+cqbd v3Xx96Ig8FBGXZulYnTctTdmgjfpsfKzOcLEg1/WB8pFYEUBymF+Ml3oIbjXGMIbtkyG z8asJNK5NmHsxaKXtwGqZuCC5P4mhArLrH8ZRm0TJ7kuHdUC3F8W0kL6qI4D3/52D7cc dlttVCRu06YPRKBwmmxsPLt922fs0pZj/hoCn96NWXFMke08qizi+j/XbTk+JzkwDTG5 tY+Q== 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=ZpTnRD05maIChe8yVDDcKVzTVU41jZD7yC8icYnBxeU=; b=JGEkHmXcdWP+BRwnGn2GRl/7zXC5bkdLd+4OFMnOUk0SEm0LEa1dqrY78gfAS21YYI AqOmsYmBwPzk8nJJeulPesvk2BChVEybB6Px/+F9W6WswHsIk0R1qq8B05ayO4iW3t5p q9xtPXZTotrO8d+rh5Lcc8o8IHchu2r3Pc8uZJ7JcNhZCVFmNx2zIdjQoiBClD73Zb9O o7uGnTJMoNosf3rvw89XxxnlTKEMt3DSmh8GHqeZ7ZrzyJlaqKv2vHLNXTwMp/fiTZEt s7z2caG/xCAr9unqpD972P/F3RuRjaRGsrrKKlk/63Tvw4pkBp/vLTW+RNuLYh/WcBcL SOEw== X-Gm-Message-State: ALoCoQndKagBK9aozLm+WL8ygQ2DC7w6VkGbBZRA6gkm0DRTv/xymfzkJtcsSOcI+I1Z9rpzjoxv X-Received: by 10.236.203.49 with SMTP id e37mr2503771yho.50.1414605880351; Wed, 29 Oct 2014 11:04:40 -0700 (PDT) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id n63si309602yho.5.2014.10.29.11.04.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Oct 2014 11:04:40 -0700 (PDT) Received: from zachr.mtv.corp.google.com ([172.22.64.53]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTP id a7FkqtTn.1; Wed, 29 Oct 2014 11:04:40 -0700 Received: by zachr.mtv.corp.google.com (Postfix, from userid 201400) id 9015F183127; Wed, 29 Oct 2014 11:04:39 -0700 (PDT) From: Zach Reizner To: dri-devel@lists.freedesktop.org Subject: [PATCH v2] allow 32bpp framebuffers for cirrus drm Date: Wed, 29 Oct 2014 11:04:24 -0700 Message-Id: <1414605864-28175-1-git-send-email-zachr@google.com> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 Cc: Zach Reizner 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-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID, 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. v2: Use pci resource length for vram size. Signed-off-by: Zach Reizner --- drivers/gpu/drm/cirrus/cirrus_drv.h | 3 +++ drivers/gpu/drm/cirrus/cirrus_fbdev.c | 5 ++++- drivers/gpu/drm/cirrus/cirrus_main.c | 27 +++++++++++++++++++++++---- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/cirrus/cirrus_drv.h b/drivers/gpu/drm/cirrus/cirrus_drv.h index d44e69d..693a456 100644 --- a/drivers/gpu/drm/cirrus/cirrus_drv.h +++ b/drivers/gpu/drm/cirrus/cirrus_drv.h @@ -210,6 +210,9 @@ int cirrus_framebuffer_init(struct drm_device *dev, struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object *obj); +bool cirrus_check_framebuffer(struct cirrus_device *cdev, 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 d231b1c..502a89e 100644 --- a/drivers/gpu/drm/cirrus/cirrus_fbdev.c +++ b/drivers/gpu/drm/cirrus/cirrus_fbdev.c @@ -139,6 +139,7 @@ static int cirrusfb_create_object(struct cirrus_fbdev *afbdev, struct drm_gem_object **gobj_p) { struct drm_device *dev = afbdev->helper.dev; + struct cirrus_device *cdev = dev->dev_private; u32 bpp, depth; u32 size; struct drm_gem_object *gobj; @@ -146,8 +147,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(cdev, 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..d9590fc 100644 --- a/drivers/gpu/drm/cirrus/cirrus_main.c +++ b/drivers/gpu/drm/cirrus/cirrus_main.c @@ -49,14 +49,16 @@ cirrus_user_framebuffer_create(struct drm_device *dev, struct drm_file *filp, struct drm_mode_fb_cmd2 *mode_cmd) { + struct cirrus_device *cdev = dev->dev_private; struct drm_gem_object *obj; struct cirrus_framebuffer *cirrus_fb; int ret; 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(cdev, 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]); @@ -96,8 +98,7 @@ static int cirrus_vram_init(struct cirrus_device *cdev) { /* BAR 0 is VRAM */ cdev->mc.vram_base = pci_resource_start(cdev->dev->pdev, 0); - /* We have 4MB of VRAM */ - cdev->mc.vram_size = 4 * 1024 * 1024; + cdev->mc.vram_size = pci_resource_len(cdev->dev->pdev, 0); if (!request_mem_region(cdev->mc.vram_base, cdev->mc.vram_size, "cirrusdrmfb_vram")) { @@ -307,3 +308,21 @@ out_unlock: return ret; } + +bool cirrus_check_framebuffer(struct cirrus_device *cdev, int width, int height, + int bpp, int pitch) +{ + const int max_pitch = 0x1FF << 3; /* (4096 - 1) & ~111b bytes */ + const int max_size = cdev->mc.vram_size; + + if (bpp > 32) + return false; + + if (pitch > max_pitch) + return false; + + if (pitch * height > max_size) + return false; + + return true; +}