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 v3 06/10] drm/gma500: Inline psb_gtt_attach_pages() and psb_gtt_detach_pages()
Date: Fri, 15 Oct 2021 10:40:49 +0200 [thread overview]
Message-ID: <20211015084053.13708-7-tzimmermann@suse.de> (raw)
In-Reply-To: <20211015084053.13708-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.
v2:
* unlock gtt_mutex in pin-error handling (Patrik)
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Acked-by: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>
---
drivers/gpu/drm/gma500/gem.c | 94 ++++++++++++++++--------------------
1 file changed, 42 insertions(+), 52 deletions(-)
diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
index 1905468924ca..37b61334ade2 100644
--- a/drivers/gpu/drm/gma500/gem.c
+++ b/drivers/gpu/drm/gma500/gem.c
@@ -19,63 +19,48 @@
#include "gem.h"
#include "psb_drv.h"
-/*
- * Pin and build an in-kernel list of the pages that back our GEM object.
- * While we hold this the pages cannot be swapped out. This is protected
- * via the gtt mutex which the caller must hold.
- */
-static int psb_gtt_attach_pages(struct gtt_range *gt)
-{
- struct page **pages;
-
- WARN_ON(gt->pages);
-
- pages = drm_gem_get_pages(>->gem);
- if (IS_ERR(pages))
- return PTR_ERR(pages);
-
- gt->npage = gt->gem.size / PAGE_SIZE;
- gt->pages = pages;
-
- return 0;
-}
-
-/*
- * Undo the effect of psb_gtt_attach_pages. At this point the pages
- * must have been removed from the GTT as they could now be paged out
- * and move bus address. This is protected via the gtt mutex which the
- * caller must hold.
- */
-static void psb_gtt_detach_pages(struct gtt_range *gt)
-{
- drm_gem_put_pages(>->gem, gt->pages, true, false);
- gt->pages = NULL;
-}
-
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;
mutex_lock(&dev_priv->gtt_mutex);
- 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);
+ if (gt->in_gart || gt->stolen)
+ goto out; /* already mapped */
+
+ pages = drm_gem_get_pages(>->gem);
+ if (IS_ERR(pages)) {
+ ret = PTR_ERR(pages);
+ goto err_mutex_unlock;
}
- gt->in_gart++;
+
+ npages = gt->gem.size / PAGE_SIZE;
+
+ ret = psb_gtt_insert(dev, gt, 0);
+ if (ret)
+ goto err_drm_gem_put_pages;
+
+ psb_mmu_insert_pages(psb_mmu_get_default_pd(dev_priv->mmu), pages,
+ (gpu_base + gt->offset), npages, 0, 0,
+ PSB_MMU_CACHED_MEMORY);
+
+ gt->npage = npages;
+ gt->pages = pages;
+
out:
+ ++gt->in_gart;
+ mutex_unlock(&dev_priv->gtt_mutex);
+
+ return 0;
+
+err_drm_gem_put_pages:
+ drm_gem_put_pages(>->gem, pages, true, false);
+err_mutex_unlock:
mutex_unlock(&dev_priv->gtt_mutex);
return ret;
}
@@ -90,14 +75,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(>->gem, gt->pages, true, false);
+ gt->pages = NULL;
+
+out:
mutex_unlock(&dev_priv->gtt_mutex);
}
--
2.33.0
next prev parent reply other threads:[~2021-10-15 8:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-15 8:40 [PATCH v3 00/10] drm/gma500: Refactor GEM code Thomas Zimmermann
2021-10-15 8:40 ` [PATCH v3 01/10] drm/gma500: Move helpers for struct gtt_range from gtt.c to gem.c Thomas Zimmermann
2021-10-15 8:40 ` [PATCH v3 02/10] drm/gma500: Use to_gtt_range() everywhere Thomas Zimmermann
2021-10-15 8:40 ` [PATCH v3 03/10] drm/gma500: Reimplement psb_gem_create() Thomas Zimmermann
2021-10-15 8:40 ` [PATCH v3 04/10] drm/gma500: Allocate GTT ranges in stolen memory with psb_gem_create() Thomas Zimmermann
2021-10-15 8:40 ` [PATCH v3 05/10] drm/gma500: Rename psb_gtt_{pin, unpin}() to psb_gem_{pin, unpin}() Thomas Zimmermann
2021-10-15 8:40 ` Thomas Zimmermann [this message]
2021-10-15 8:40 ` [PATCH v3 07/10] drm/gma500: Inline psb_gtt_{alloc, free}_range() into rsp callers Thomas Zimmermann
2021-10-18 12:27 ` Patrik Jakobsson
2021-10-15 8:40 ` [PATCH v3 08/10] drm/gma500: Set page-caching flags in GEM pin/unpin Thomas Zimmermann
2021-10-15 8:40 ` [PATCH v3 09/10] drm/gma500: Rewrite GTT page insert/remove without struct gtt_range Thomas Zimmermann
2021-10-18 12:27 ` Patrik Jakobsson
2021-10-15 8:40 ` [PATCH v3 10/10] drm/gma500: Rename struct gtt_range to struct psb_gem_object Thomas Zimmermann
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=20211015084053.13708-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 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).