From patchwork Thu Jun 19 19:06:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 4385781 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 49A2C9F1D6 for ; Thu, 19 Jun 2014 19:06:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6F1EC201C8 for ; Thu, 19 Jun 2014 19:06:26 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 70537202FE for ; Thu, 19 Jun 2014 19:06:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8B2057204D; Thu, 19 Jun 2014 12:06:24 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [143.182.124.21]) by gabe.freedesktop.org (Postfix) with ESMTP id C69046E919 for ; Thu, 19 Jun 2014 12:06:22 -0700 (PDT) Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga101.ch.intel.com with ESMTP; 19 Jun 2014 12:06:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,508,1400050800"; d="scan'208";a="447654110" Received: from unknown (HELO ironside.intel.com) ([10.255.13.2]) by azsmga001.ch.intel.com with ESMTP; 19 Jun 2014 12:06:16 -0700 From: Ben Widawsky To: Intel GFX Date: Thu, 19 Jun 2014 12:06:13 -0700 Message-Id: <1403204773-7112-4-git-send-email-benjamin.widawsky@intel.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1403204773-7112-1-git-send-email-benjamin.widawsky@intel.com> References: <1403204773-7112-1-git-send-email-benjamin.widawsky@intel.com> Cc: Ben Widawsky , Ben Widawsky Subject: [Intel-gfx] [PATCH 4/4] drm/i915: Reserve space for FBC (fbcon) X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 is one part in a few fixes needed to make FBC work with limited stolen memory and large resolution displays. It is not the full solution, but one (easy) step. The patch is straight-forward, it attempts to check there will be room for FBC before trying to "reclaim" This modifies behavior originally introduced: commit 0ffb0ff283cca16f72caf29c44496d83b0c291fb Author: Chris Wilson Date: Thu Nov 15 11:32:27 2012 +0000 drm/i915: Allocate fbcon from stolen memory Cc: Chris Wilson Cc: Jesse Barnes Signed-off-by: Ben Widawsky --- drivers/gpu/drm/i915/intel_fbdev.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_fbdev.c b/drivers/gpu/drm/i915/intel_fbdev.c index 27975c3..ca83af8 100644 --- a/drivers/gpu/drm/i915/intel_fbdev.c +++ b/drivers/gpu/drm/i915/intel_fbdev.c @@ -57,6 +57,36 @@ static struct fb_ops intelfb_ops = { .fb_debug_leave = drm_fb_helper_debug_leave, }; +static bool intelfb_use_stolen(struct drm_device *dev, struct drm_mm *mm, + int size) +{ + struct drm_mm_node *entry; + unsigned long adj_start; + unsigned long adj_end; + + if (!drm_mm_initialized(mm)) + return false; + + if (!HAS_FBC(dev)) + return true; + + /* It is more desirable to use FBC (if enabled) than to allocate the + * framebuffer from stolen. We can cheat this by rounding up the size by + * 2 (and hope to get lucky with alignment). The other options are more + * invasive, and arguably not any more effective. + */ + size *= 2; + __drm_mm_for_each_hole(entry, mm, adj_start, adj_end, + DRM_MM_SEARCH_DEFAULT) { + if (adj_end - adj_start < size) + continue; + + if (adj_end >= adj_start + size) + return true; + } + + return false; +} static int intelfb_alloc(struct drm_fb_helper *helper, struct drm_fb_helper_surface_size *sizes) { @@ -64,8 +94,9 @@ static int intelfb_alloc(struct drm_fb_helper *helper, container_of(helper, struct intel_fbdev, helper); struct drm_framebuffer *fb; struct drm_device *dev = helper->dev; + struct drm_i915_private *dev_priv = dev->dev_private; struct drm_mode_fb_cmd2 mode_cmd = {}; - struct drm_i915_gem_object *obj; + struct drm_i915_gem_object *obj = NULL; int size, ret; /* we don't do packed 24bpp */ @@ -82,7 +113,9 @@ static int intelfb_alloc(struct drm_fb_helper *helper, size = mode_cmd.pitches[0] * mode_cmd.height; size = ALIGN(size, PAGE_SIZE); - obj = i915_gem_object_create_stolen(dev, size); + + if (intelfb_use_stolen(dev, &dev_priv->mm.stolen, size)) + obj = i915_gem_object_create_stolen(dev, size); if (obj == NULL) obj = i915_gem_alloc_object(dev, size); if (!obj) {