diff mbox

[3/5] drm/i915: Extract gen6 aliasing ppgtt code

Message ID 1359160867-780-4-git-send-email-ben@bwidawsk.net (mailing list archive)
State New, archived
Headers show

Commit Message

Ben Widawsky Jan. 26, 2013, 12:41 a.m. UTC
This refactor clearly identifies the GEN specific portion of the aliased
ppgtt code. Aside from some of the gen specific parts being extracted,
it also preps us for an upcoming patch that pulls out the size, which
has some nice benefits.

v2: Fix wonky error handling (Chris)

Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 42 ++++++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 14 deletions(-)

Comments

Daniel Vetter Jan. 29, 2013, 12:55 p.m. UTC | #1
On Fri, Jan 25, 2013 at 04:41:05PM -0800, Ben Widawsky wrote:
> This refactor clearly identifies the GEN specific portion of the aliased
> ppgtt code. Aside from some of the gen specific parts being extracted,
> it also preps us for an upcoming patch that pulls out the size, which
> has some nice benefits.
> 
> v2: Fix wonky error handling (Chris)
> 
> Signed-off-by: Ben Widawsky <ben@bwidawsk.net>

Functionally we seem to have this patch already with

commit e9ccfd7b94f1ca9b46b992a19d2e8c5af70e4c69
Author: Daniel Vetter <daniel.vetter@ffwll.ch>
Date:   Thu Jan 24 13:49:56 2013 -0800

    drm/i915: extract hw ppgtt setup/cleanup code

Yeah, you're allowed to hate me with the heat of a thousand suns now ;-)
-Daniel
Ben Widawsky Jan. 29, 2013, 7 p.m. UTC | #2
On Tue, Jan 29, 2013 at 01:55:46PM +0100, Daniel Vetter wrote:
> On Fri, Jan 25, 2013 at 04:41:05PM -0800, Ben Widawsky wrote:
> > This refactor clearly identifies the GEN specific portion of the aliased
> > ppgtt code. Aside from some of the gen specific parts being extracted,
> > it also preps us for an upcoming patch that pulls out the size, which
> > has some nice benefits.
> > 
> > v2: Fix wonky error handling (Chris)
> > 
> > Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
> 
> Functionally we seem to have this patch already with
> 
> commit e9ccfd7b94f1ca9b46b992a19d2e8c5af70e4c69
> Author: Daniel Vetter <daniel.vetter@ffwll.ch>
> Date:   Thu Jan 24 13:49:56 2013 -0800
> 
>     drm/i915: extract hw ppgtt setup/cleanup code
> 
> Yeah, you're allowed to hate me with the heat of a thousand suns now ;-)
> -Daniel

I already did. I guess when I rebased the series, you hadn't merged
those yet.
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 31c490e..f79f427 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -108,10 +108,10 @@  static void i915_ppgtt_clear_range(struct i915_hw_ppgtt *ppgtt,
 	}
 }
 
-static int i915_gem_init_aliasing_ppgtt(struct drm_device *dev)
+static int gen6_init_aliasing_ppgtt(struct i915_hw_ppgtt *ppgtt)
 {
+	struct drm_device *dev = ppgtt->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
-	struct i915_hw_ppgtt *ppgtt;
 	unsigned first_pd_entry_in_global_pt;
 	int i;
 	int ret = -ENOMEM;
@@ -121,16 +121,12 @@  static int i915_gem_init_aliasing_ppgtt(struct drm_device *dev)
 	 * now. */
 	first_pd_entry_in_global_pt = dev_priv->mm.gtt->gtt_total_entries - I915_PPGTT_PD_ENTRIES;
 
-	ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL);
-	if (!ppgtt)
-		return ret;
-
-	ppgtt->dev = dev;
 	ppgtt->num_pd_entries = I915_PPGTT_PD_ENTRIES;
 	ppgtt->pt_pages = kzalloc(sizeof(struct page *)*ppgtt->num_pd_entries,
 				  GFP_KERNEL);
+
 	if (!ppgtt->pt_pages)
-		goto err_ppgtt;
+		return -ENOMEM;
 
 	for (i = 0; i < ppgtt->num_pd_entries; i++) {
 		ppgtt->pt_pages[i] = alloc_page(GFP_KERNEL);
@@ -157,15 +153,11 @@  static int i915_gem_init_aliasing_ppgtt(struct drm_device *dev)
 		ppgtt->pt_dma_addr[i] = pt_addr;
 	}
 
-	ppgtt->scratch_page_dma_addr = dev_priv->gtt.scratch_page_dma;
-
 	i915_ppgtt_clear_range(ppgtt, 0,
 			       ppgtt->num_pd_entries*I915_PPGTT_PT_ENTRIES);
 
 	ppgtt->pd_offset = (first_pd_entry_in_global_pt)*sizeof(gtt_pte_t);
 
-	dev_priv->mm.aliasing_ppgtt = ppgtt;
-
 	return 0;
 
 err_pd_pin:
@@ -180,9 +172,31 @@  err_pt_alloc:
 		if (ppgtt->pt_pages[i])
 			__free_page(ppgtt->pt_pages[i]);
 	}
+
 	kfree(ppgtt->pt_pages);
-err_ppgtt:
-	kfree(ppgtt);
+
+	return ret;
+}
+
+
+static int i915_gem_init_aliasing_ppgtt(struct drm_device *dev)
+{
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct i915_hw_ppgtt *ppgtt;
+	int ret = -ENOMEM;
+
+	ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL);
+	if (!ppgtt)
+		return ret;
+
+	ppgtt->dev = dev;
+	ppgtt->scratch_page_dma_addr = dev_priv->gtt.scratch_page_dma;
+
+	ret = gen6_init_aliasing_ppgtt(ppgtt);
+	if (ret)
+		kfree(ppgtt);
+	else
+		dev_priv->mm.aliasing_ppgtt = ppgtt;
 
 	return ret;
 }