All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: patrik.r.jakobsson@gmail.com, airlied@linux.ie, daniel@ffwll.ch
Cc: dri-devel@lists.freedesktop.org, Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH 06/10] drm/gma500: Inline psb_gtt_attach_pages() and psb_gtt_detach_pages()
Date: Tue, 28 Sep 2021 10:44:42 +0200	[thread overview]
Message-ID: <20210928084446.22580-7-tzimmermann@suse.de> (raw)
In-Reply-To: <20210928084446.22580-1-tzimmermann@suse.de>

psb_gtt_attach_pages() are not GTT functions but deal with the GEM
object's SHMEM pages. The only callers of psb_gtt_attach_pages() and
psb_gtt_detach_pages() are the GEM pin helpers. Inline the calls and
cleanup the resulting code.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/gma500/gem.c | 75 +++++++++++++++++-------------------
 1 file changed, 36 insertions(+), 39 deletions(-)

diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
index 369910d0091e..a48d7d5ed026 100644
--- a/drivers/gpu/drm/gma500/gem.c
+++ b/drivers/gpu/drm/gma500/gem.c
@@ -19,53 +19,45 @@
 #include "gem.h"
 #include "psb_drv.h"
 
-static int psb_gtt_attach_pages(struct gtt_range *gt)
+int psb_gem_pin(struct gtt_range *gt)
 {
+	int ret = 0;
+	struct drm_device *dev = gt->gem.dev;
+	struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
+	u32 gpu_base = dev_priv->gtt.gatt_start;
 	struct page **pages;
+	unsigned int npages;
 
-	WARN_ON(gt->pages);
+	mutex_lock(&dev_priv->gtt_mutex);
+
+	if (gt->in_gart || gt->stolen)
+		goto out; /* already mapped */
 
 	pages = drm_gem_get_pages(&gt->gem);
 	if (IS_ERR(pages))
 		return PTR_ERR(pages);
 
-	gt->npage = gt->gem.size / PAGE_SIZE;
-	gt->pages = pages;
-
-	return 0;
-}
+	npages = gt->gem.size / PAGE_SIZE;
 
-static void psb_gtt_detach_pages(struct gtt_range *gt)
-{
-	drm_gem_put_pages(&gt->gem, gt->pages, true, false);
-	gt->pages = NULL;
-}
+	ret = psb_gtt_insert(dev, gt, 0);
+	if (ret)
+		goto err_drm_gem_put_pages;
 
-int psb_gem_pin(struct gtt_range *gt)
-{
-	int ret = 0;
-	struct drm_device *dev = gt->gem.dev;
-	struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
-	u32 gpu_base = dev_priv->gtt.gatt_start;
+	psb_mmu_insert_pages(psb_mmu_get_default_pd(dev_priv->mmu), pages,
+			     (gpu_base + gt->offset), npages, 0, 0,
+			     PSB_MMU_CACHED_MEMORY);
 
-	mutex_lock(&dev_priv->gtt_mutex);
+	gt->npage = npages;
+	gt->pages = pages;
 
-	if (gt->in_gart == 0 && gt->stolen == 0) {
-		ret = psb_gtt_attach_pages(gt);
-		if (ret < 0)
-			goto out;
-		ret = psb_gtt_insert(dev, gt, 0);
-		if (ret < 0) {
-			psb_gtt_detach_pages(gt);
-			goto out;
-		}
-		psb_mmu_insert_pages(psb_mmu_get_default_pd(dev_priv->mmu),
-				     gt->pages, (gpu_base + gt->offset),
-				     gt->npage, 0, 0, PSB_MMU_CACHED_MEMORY);
-	}
-	gt->in_gart++;
 out:
+	++gt->in_gart;
 	mutex_unlock(&dev_priv->gtt_mutex);
+
+	return 0;
+
+err_drm_gem_put_pages:
+	drm_gem_put_pages(&gt->gem, pages, true, false);
 	return ret;
 }
 
@@ -79,14 +71,19 @@ void psb_gem_unpin(struct gtt_range *gt)
 
 	WARN_ON(!gt->in_gart);
 
-	gt->in_gart--;
-	if (gt->in_gart == 0 && gt->stolen == 0) {
-		psb_mmu_remove_pages(psb_mmu_get_default_pd(dev_priv->mmu),
+	--gt->in_gart;
+
+	if (gt->in_gart || gt->stolen)
+		goto out;
+
+	psb_mmu_remove_pages(psb_mmu_get_default_pd(dev_priv->mmu),
 				     (gpu_base + gt->offset), gt->npage, 0, 0);
-		psb_gtt_remove(dev, gt);
-		psb_gtt_detach_pages(gt);
-	}
+	psb_gtt_remove(dev, gt);
 
+	drm_gem_put_pages(&gt->gem, gt->pages, true, false);
+	gt->pages = NULL;
+
+out:
 	mutex_unlock(&dev_priv->gtt_mutex);
 }
 
-- 
2.33.0


  parent reply	other threads:[~2021-09-28  8:45 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-28  8:44 [PATCH 00/10] drm/gma500: Refactor GEM code Thomas Zimmermann
2021-09-28  8:44 ` [PATCH 01/10] drm/gma500: Move helpers for struct gtt_range from gtt.c to gem.c Thomas Zimmermann
2021-10-02 22:13   ` Patrik Jakobsson
2021-10-04  6:11     ` Thomas Zimmermann
2021-09-28  8:44 ` [PATCH 02/10] drm/gma500: Use to_gtt_range() everywhere Thomas Zimmermann
2021-10-02 22:13   ` Patrik Jakobsson
2021-09-28  8:44 ` [PATCH 03/10] drm/gma500: Reimplement psb_gem_create() Thomas Zimmermann
2021-10-02 22:13   ` Patrik Jakobsson
2021-09-28  8:44 ` [PATCH 04/10] drm/gma500: Allocate GTT ranges in stolen memory with psb_gem_create() Thomas Zimmermann
2021-10-02 22:13   ` Patrik Jakobsson
2021-09-28  8:44 ` [PATCH 05/10] drm/gma500: Rename psb_gtt_{pin, unpin}() to psb_gem_{pin, unpin}() Thomas Zimmermann
2021-10-02 22:14   ` Patrik Jakobsson
2021-09-28  8:44 ` Thomas Zimmermann [this message]
2021-10-02 22:14   ` [PATCH 06/10] drm/gma500: Inline psb_gtt_attach_pages() and psb_gtt_detach_pages() Patrik Jakobsson
2021-09-28  8:44 ` [PATCH 07/10] drm/gma500: Inline psb_gtt_{alloc, free}_range() into rsp callers Thomas Zimmermann
2021-10-02 22:14   ` [PATCH 07/10] drm/gma500: Inline psb_gtt_{alloc,free}_range() " Patrik Jakobsson
2021-10-04  6:23     ` Thomas Zimmermann
2021-09-28  8:44 ` [PATCH 08/10] drm/gma500: Set page-caching flags in GEM pin/unpin Thomas Zimmermann
2021-10-02 22:15   ` Patrik Jakobsson
2021-10-04  6:25     ` Thomas Zimmermann
2021-09-28  8:44 ` [PATCH 09/10] drm/gma500: Rewrite GTT page insert/remove without struct gtt_range Thomas Zimmermann
2021-10-02 22:15   ` Patrik Jakobsson
2021-10-04  6:31     ` Thomas Zimmermann
2021-09-28  8:44 ` [PATCH 10/10] drm/gma500: Rename struct gtt_range to struct psb_gem_object Thomas Zimmermann
2021-10-02 22:15   ` Patrik Jakobsson

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=20210928084446.22580-7-tzimmermann@suse.de \
    --to=tzimmermann@suse.de \
    --cc=airlied@linux.ie \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=patrik.r.jakobsson@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.