[PATCH 6/6] drm/gma500: use common functions for get/put pages

Rob Clark rob.clark at linaro.org
Mon Sep 12 12:21:26 PDT 2011


From: Rob Clark <rob at ti.com>

Signed-off-by: Rob Clark <rob at ti.com>
---
 drivers/staging/gma500/gtt.c |   47 ++++++++++-------------------------------
 1 files changed, 12 insertions(+), 35 deletions(-)

diff --git a/drivers/staging/gma500/gtt.c b/drivers/staging/gma500/gtt.c
index 461ead2..f453321 100644
--- a/drivers/staging/gma500/gtt.c
+++ b/drivers/staging/gma500/gtt.c
@@ -140,39 +140,21 @@ static void psb_gtt_remove(struct drm_device *dev, struct gtt_range *r)
  */
 static int psb_gtt_attach_pages(struct gtt_range *gt)
 {
-	struct inode *inode;
-	struct address_space *mapping;
-	int i;
-	struct page *p;
-	int pages = gt->gem.size / PAGE_SIZE;
+	struct page **pages;
 
 	WARN_ON(gt->pages);
 
-	/* This is the shared memory object that backs the GEM resource */
-	inode = gt->gem.filp->f_path.dentry->d_inode;
-	mapping = inode->i_mapping;
-
-	gt->pages = kmalloc(pages * sizeof(struct page *), GFP_KERNEL);
-	if (gt->pages == NULL)
-		return -ENOMEM;
-	gt->npage = pages;
-
-	for (i = 0; i < pages; i++) {
-		/* FIXME: review flags later */
-		p = read_cache_page_gfp(mapping, i,
-					__GFP_COLD | GFP_KERNEL);
-		if (IS_ERR(p))
-			goto err;
-		gt->pages[i] = p;
+	/* FIXME: review flags later */
+	pages = drm_gem_get_pages(&gt->gem,
+			__GFP_DMA32 | __GFP_COLD | GFP_KERNEL);
+	if (IS_ERR(pages)) {
+		dev_err(gt->gem.dev->dev, "could not get pages: %ld\n",
+				PTR_ERR(pages));
+		return PTR_ERR(pages);
 	}
-	return 0;
 
-err:
-	while (i--)
-		page_cache_release(gt->pages[i]);
-	kfree(gt->pages);
-	gt->pages = NULL;
-	return PTR_ERR(p);
+	gt->pages = pages;
+	return 0;
 }
 
 /**
@@ -185,13 +167,8 @@ err:
  */
 static void psb_gtt_detach_pages(struct gtt_range *gt)
 {
-	int i;
-	for (i = 0; i < gt->npage; i++) {
-		/* FIXME: do we need to force dirty */
-		set_page_dirty(gt->pages[i]);
-		page_cache_release(gt->pages[i]);
-	}
-	kfree(gt->pages);
+	/* FIXME: do we need to force dirty */
+	drm_gem_put_pages(&gt->gem, gt->pages, true, false);
 	gt->pages = NULL;
 }
 
-- 
1.7.5.4



More information about the dri-devel mailing list