linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rob Clark <robdclark@gmail.com>
To: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org
Cc: linux-arm-msm@vger.kernel.org,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Subject: [PATCH 3/3] drm/msm: hijack firmware fb's memory
Date: Tue, 11 Jul 2017 13:38:22 +0000	[thread overview]
Message-ID: <20170711133822.31978-4-robdclark@gmail.com> (raw)
In-Reply-To: <20170711133822.31978-1-robdclark@gmail.com>

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 <robdclark@gmail.com>
---
 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",
-- 
2.13.0


  parent reply	other threads:[~2017-07-11 13:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-11 13:38 [PATCH 0/3] drm/msm: hijack firmware fb's memory Rob Clark
2017-07-11 13:38 ` [PATCH 1/3] drm/msm: kick out firmware framebuffer Rob Clark
2017-07-11 13:38 ` [PATCH 2/3] fbdev: fbmem: export get/put_fb_info() Rob Clark
2017-07-12  9:54   ` Bartlomiej Zolnierkiewicz
2017-07-11 13:38 ` Rob Clark [this message]
2017-07-11 14:03   ` [PATCH 3/3] drm/msm: hijack firmware fb's memory Daniel Vetter
2017-07-11 14:31     ` Rob Clark
2017-07-11 14:42       ` Daniel Vetter
2017-07-11 19:53         ` Rob Clark
2017-07-11 20:37           ` Daniel Vetter
2017-07-11 14:17   ` Chris Wilson
2017-07-11 14:34     ` Rob Clark

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170711133822.31978-4-robdclark@gmail.com \
    --to=robdclark@gmail.com \
    --cc=b.zolnierkie@samsung.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-fbdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).