From patchwork Tue Jul 11 13:38:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 9834727 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 17A2B60363 for ; Tue, 11 Jul 2017 13:38:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 092EF25EA6 for ; Tue, 11 Jul 2017 13:38:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1F2A28429; Tue, 11 Jul 2017 13:38:43 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CD8925EA6 for ; Tue, 11 Jul 2017 13:38:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932486AbdGKNil (ORCPT ); Tue, 11 Jul 2017 09:38:41 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:34003 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932229AbdGKNii (ORCPT ); Tue, 11 Jul 2017 09:38:38 -0400 Received: by mail-qk0-f196.google.com with SMTP id q66so6540172qki.1; Tue, 11 Jul 2017 06:38:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WjR0iDMJ4jIcel3pkp/67TvRqCZs97LzJmD4MxLeYMA=; b=qmCW9uJsaITBrtqzE0COwJ9FjTjSUGymz5uKbx7e8sLCC5/fAdTPxM8p0s5O/CNgm+ pXaexw+mpukCYzHDjbpyuAEJg/FLMlV/sPIuEYkn8yhuzAyl+W9Mv803saFCyeMu7Kgm Z1qSmr6S4yGzajLkLxC877ybOsj3/yPyAWCLzaGM3bgeOdMW1q86THMLat2kh9E7TfkB 3qGQVFW+l0VNlthAKNLSxe1o8/jXci5DNCtB4v4+AK7A6OrpGSitkOpqHoZVpyouwlw3 CdwZl0zZ3m6XJO+Suq3y75kdrXgNW2hjwjB9N5mNfT7sLpOw33PmhCos4VniXUAkINkM LOSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WjR0iDMJ4jIcel3pkp/67TvRqCZs97LzJmD4MxLeYMA=; b=XF3k39hC7o7uzACGffn1qMMqKhM+oZSOk3zoi2+xsT/B1ZDMWWCS33H70u8EV7anfp tXbFpPLys4dDd+lj2kTNHecaEj7vf6pp/3I2yiaWZ+/IHSzgn1zEZWLp9PsF2VkwZh4X 8oEUH3GW6c6JC2MBVxJG0cNaLi6JOIAIr88MGE1gZBTQHg3mNTq77VRYUb8lLW1EifH4 z4bNDeA3buJ77I3ETHbLIR92zRf2K1dzOGqjusVoIQo3o/nyCAtAi5RSac8QMh/N2OO8 wtBe0HfIBTs5PYv3lWIpNnQRngLyCyRgRwBoyhdCqZMl3Q+oFeCNKAatcEc2/8tZy5Lm mR+A== X-Gm-Message-State: AIVw1117YY9dOWBh1TvyPUphL9oVTRnf2onF1D/nroWmGEsg55hsnHTw N9SYLrcXPPA6Iw== X-Received: by 10.200.43.58 with SMTP id 55mr11200070qtu.202.1499780317599; Tue, 11 Jul 2017 06:38:37 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id 8sm2190116qkc.30.2017.07.11.06.38.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Jul 2017 06:38:36 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org Cc: linux-arm-msm@vger.kernel.org, Archit Taneja , Bartlomiej Zolnierkiewicz , Rob Clark Subject: [PATCH 3/3] drm/msm: hijack firmware fb's memory Date: Tue, 11 Jul 2017 09:38:22 -0400 Message-Id: <20170711133822.31978-4-robdclark@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170711133822.31978-1-robdclark@gmail.com> References: <20170711133822.31978-1-robdclark@gmail.com> Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If we are kicking out efifb or simplefb then we want to hijack the outgoing fb's memory and wrap it in a gem object so that it can be allocated for use by fbdev helpers. This way we keep the same scanout buffer that the display is already using. This is prep-work for enabling drm/msm to take over a display that is enabled already by the bootloader. Signed-off-by: Rob Clark --- drivers/gpu/drm/msm/msm_drv.c | 82 +++++++++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index f487437fb9d0..7c1ff26a3c13 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -304,6 +304,45 @@ static void kick_out_firmware_fb(void) kfree(ap); } +static unsigned long hijack_firmware_fb(struct drm_device *dev) +{ + struct msm_drm_private *priv = dev->dev_private; + unsigned long size; + int i; + + /* if we have simplefb/efifb, find it's aperture and hijack + * that before we kick out the firmware fb's. + * + * TODO we probably should hold registration_lock + */ + for (i = 0; i < FB_MAX; i++) { + struct fb_info *fb = get_fb_info(i); + + if (IS_ERR_OR_NULL(fb)) + continue; + + if (!fb->apertures->count) + continue; + + /* if we find efifb or simplefb, we are about to + * kick them out, so hijack their memory: + */ + if ((strcmp(fb->fix.id, "EFI VGA") == 0) || + (strcmp(fb->fix.id, "simple") == 0)) { + + priv->vram.paddr = fb->apertures->ranges[0].base; + size = fb->apertures->ranges[0].size; + } + + put_fb_info(fb); + + if (size) + return size; + } + + return 0; +} + static int msm_init_vram(struct drm_device *dev) { struct msm_drm_private *priv = dev->dev_private; @@ -335,39 +374,46 @@ static int msm_init_vram(struct drm_device *dev) of_node_put(node); if (ret) return ret; - size = r.end - r.start; + size = r.end - r.start - 1; DRM_INFO("using VRAM carveout: %lx@%pa\n", size, &r.start); + } else if ((size = hijack_firmware_fb(dev))) { + DRM_INFO("hijacking VRAM carveout: %lx@%pa\n", + size, &priv->vram.paddr); + } else if (!iommu_present(&platform_bus_type)) { /* if we have no IOMMU, then we need to use carveout allocator. * Grab the entire CMA chunk carved out in early startup in * mach-msm: */ - } else if (!iommu_present(&platform_bus_type)) { DRM_INFO("using %s VRAM carveout\n", vram); size = memparse(vram, NULL); } if (size) { - unsigned long attrs = 0; - void *p; - priv->vram.size = size; - drm_mm_init(&priv->vram.mm, 0, (size >> PAGE_SHIFT) - 1); + drm_mm_init(&priv->vram.mm, 0, (size >> PAGE_SHIFT)); spin_lock_init(&priv->vram.lock); - attrs |= DMA_ATTR_NO_KERNEL_MAPPING; - attrs |= DMA_ATTR_WRITE_COMBINE; - - /* note that for no-kernel-mapping, the vaddr returned - * is bogus, but non-null if allocation succeeded: - */ - p = dma_alloc_attrs(dev->dev, size, - &priv->vram.paddr, GFP_KERNEL, attrs); - if (!p) { - dev_err(dev->dev, "failed to allocate VRAM\n"); - priv->vram.paddr = 0; - return -ENOMEM; + if (!priv->vram.paddr) { + unsigned long attrs = 0; + void *p; + + attrs |= DMA_ATTR_NO_KERNEL_MAPPING; + attrs |= DMA_ATTR_WRITE_COMBINE; + + /* note that for no-kernel-mapping, the vaddr returned + * is bogus, but non-null if allocation succeeded: + */ + p = dma_alloc_attrs(dev->dev, size, + &priv->vram.paddr, GFP_KERNEL, attrs); + if (!p) { + dev_err(dev->dev, "failed to allocate VRAM\n"); + priv->vram.paddr = 0; + return -ENOMEM; + } + } else { + request_region(priv->vram.paddr, size, "stolen"); } dev_info(dev->dev, "VRAM: %08x->%08x\n",