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@xxxxxxx> --- 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(>->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(>->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(>->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(>->gem, gt->pages, true, false); + gt->pages = NULL; + +out: mutex_unlock(&dev_priv->gtt_mutex); } -- 2.33.0