All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Widawsky <benjamin.widawsky@intel.com>
To: Intel GFX <intel-gfx@lists.freedesktop.org>
Subject: [PATCH 26/26] FOR REFERENCE ONLY
Date: Mon, 17 Mar 2014 22:48:58 -0700	[thread overview]
Message-ID: <1395121738-29126-27-git-send-email-benjamin.widawsky@intel.com> (raw)
In-Reply-To: <1395121738-29126-1-git-send-email-benjamin.widawsky@intel.com>

Start using size/length through the GEN8 code. The same approach was
taken for gen7. The difference with gen8 to this point is we need to
take care to the do the page directory allocations, as well as the page
tables.

This patch is meant to show how things will look (more or less) if I
keep up in the same direction.
---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 104 +++++++++++++++++++++++++++---------
 drivers/gpu/drm/i915/i915_gem_gtt.h |  37 +++++++++++++
 2 files changed, 115 insertions(+), 26 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 846a5b5..1348d48 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -488,29 +488,50 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm,
 		kunmap_atomic(pt_vaddr);
 }
 
-static void gen8_free_page_tables(struct i915_pagedir *pd, struct drm_device *dev)
+static void gen8_free_page_tables(struct i915_pagedir *pd,
+				  uint64_t start, uint64_t length,
+				  struct drm_device *dev)
 {
 	int i;
 
 	if (!pd->page)
 		return;
 
-	for (i = 0; i < I915_PDES_PER_PD; i++) {
+	for (i = gen8_pte_index(start);
+	     length && i < GEN8_PTES_PER_PT; i++, length -= PAGE_SIZE) {
+		if (!pd->page_tables[i])
+			continue;
+
 		free_pt_single(pd->page_tables[i], dev);
 		pd->page_tables[i] = NULL;
 	}
 }
 
-static void gen8_ppgtt_free(struct i915_hw_ppgtt *ppgtt)
+static void gen8_teardown_va_range(struct i915_hw_ppgtt *ppgtt,
+				   uint64_t start, uint64_t length)
 {
-	int i;
+	struct drm_device *dev = ppgtt->base.dev;
+	struct i915_pagedir *pd;
+	struct i915_pagetab *pt;
+	uint64_t temp, temp2;
+	uint32_t pdpe, pde;
+
+	gen8_for_each_pdpe(pd, &ppgtt->pdp, start, length, temp, pdpe) {
+		uint64_t pd_start = start;
+		uint64_t pd_len = gen8_bound_pt(start, length);
+		gen8_for_each_pde(pt, pd, pd_start, pd_len, temp2, pde) {
+			gen8_free_page_tables(pd, pd_start, pd_len, dev);
+		}
 
-	for (i = 0; i < ppgtt->num_pd_pages; i++) {
-		gen8_free_page_tables(ppgtt->pdp.pagedir[i], ppgtt->base.dev);
-		free_pd_single(ppgtt->pdp.pagedir[i], ppgtt->base.dev);
+		free_pd_single(pd, dev);
 	}
 }
 
+static void gen8_ppgtt_free(struct i915_hw_ppgtt *ppgtt)
+{
+	gen8_teardown_va_range(ppgtt, ppgtt->base.start, ppgtt->base.total);
+}
+
 static void gen8_ppgtt_cleanup(struct i915_address_space *vm)
 {
 	struct i915_hw_ppgtt *ppgtt =
@@ -537,41 +558,75 @@ static int gen8_ppgtt_allocate_page_tables(struct i915_hw_ppgtt *ppgtt)
 
 unwind_out:
 	while (i--)
-		gen8_free_page_tables(ppgtt->pdp.pagedir[i], ppgtt->base.dev);
+		gen8_free_page_tables(ppgtt->pdp.pagedir[i],
+				      i * I915_PDES_PER_PD * GEN8_PTES_PER_PT,
+				      (i + 1)* I915_PDES_PER_PD * GEN8_PTES_PER_PT,
+				      ppgtt->base.dev);
 
 	return -ENOMEM;
 }
 
 static int gen8_ppgtt_allocate_page_directories(struct i915_hw_ppgtt *ppgtt,
-						const int max_pdp)
+						uint64_t start, uint64_t length)
 {
-	int i;
+	struct i915_pagedir *unused;
+	uint64_t temp;
+	uint32_t pdpe;
 
-	for (i = 0; i < max_pdp; i++) {
-		ppgtt->pdp.pagedir[i] = alloc_pd_single(ppgtt->base.dev);
-		if (IS_ERR(ppgtt->pdp.pagedir[i]))
-			goto unwind_out;
+	gen8_for_each_pdpe(unused, &ppgtt->pdp, start, length, temp, pdpe) {
+		struct i915_pagedir *pd;
+
+		BUG_ON(unused);
+		pd = alloc_pd_single(ppgtt->base.dev);
+		if (!pd)
+			goto pd_fail;
+
+		ppgtt->pdp.pagedir[pdpe] = pd;
+		ppgtt->num_pd_pages++;
 	}
 
-	ppgtt->num_pd_pages = max_pdp;
 	BUG_ON(ppgtt->num_pd_pages > GEN8_LEGACY_PDPS);
 
 	return 0;
 
-unwind_out:
-	while (i--)
-		free_pd_single(ppgtt->pdp.pagedir[i],
-			       ppgtt->base.dev);
+pd_fail:
+	while (pdpe--)
+		free_pd_single(ppgtt->pdp.pagedir[pdpe], ppgtt->base.dev);
 
 	return -ENOMEM;
 }
 
+static void gen8_alloc_va_range(struct i915_hw_ppgtt *ppgtt,
+				uint64_t start, uint64_t length)
+{
+	struct i915_pagedir *pd;
+	struct i915_pagetab *pt;
+	uint64_t temp, temp2;
+	uint32_t pdpe, pde;
+
+	gen8_for_each_pdpe(pd, &ppgtt->pdp, start, length, temp, pdpe) {
+		uint64_t pd_start = start;
+		uint64_t pd_len = gen8_bound_pt(start, length);
+		gen8_for_each_pde(pt, pd, pd_start, pd_len, temp2, pde) {
+			uint64_t bound = gen8_bound_pt(pd_start, pd_len);
+			int ret = alloc_pt_range(pd,
+						 gen8_pde_index(pd_start),
+						 gen8_pde_index(bound),
+						 ppgtt->base.dev);
+			if (ret) {
+				//gen8_free_page_tables(pd, pd_start, pd_len, dev);
+			}
+
+		}
+	}
+}
+
 static int gen8_ppgtt_alloc(struct i915_hw_ppgtt *ppgtt,
-			    const int max_pdp)
+			    uint64_t start, uint64_t length)
 {
 	int ret;
 
-	ret = gen8_ppgtt_allocate_page_directories(ppgtt, max_pdp);
+	ret = gen8_ppgtt_allocate_page_directories(ppgtt, start, length);
 	if (ret)
 		return ret;
 
@@ -579,7 +634,7 @@ static int gen8_ppgtt_alloc(struct i915_hw_ppgtt *ppgtt,
 	if (ret)
 		goto err_out;
 
-	ppgtt->num_pd_entries = max_pdp * I915_PDES_PER_PD;
+	ppgtt->num_pd_entries = length >> GEN8_PDE_SHIFT;
 
 	return 0;
 
@@ -605,11 +660,8 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt, uint64_t size)
 	const int min_pt_pages = I915_PDES_PER_PD * max_pdp;
 	int i, j, ret;
 
-	if (size % (1<<30))
-		DRM_INFO("Pages will be wasted unless GTT size (%llu) is divisible by 1GB\n", size);
-
 	/* 1. Do all our allocations for page directories and page tables. */
-	ret = gen8_ppgtt_alloc(ppgtt, max_pdp);
+	ret = gen8_ppgtt_alloc(ppgtt, 0, size);
 	if (ret)
 		return ret;
 
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h
index 6130f3d..91f8a36 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.h
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
@@ -192,6 +192,43 @@ static inline uint32_t gen8_pml4e_index(uint64_t address)
 	BUG();
 }
 
+/* Either rounds down length to the nearest page table VA boundary, or returns
+ * length
+ */
+static inline uint64_t gen8_bound_pt(uint64_t start, uint64_t length)
+{
+	uint64_t next_pt = ALIGN(start + 1, 1 << GEN8_PDE_SHIFT);
+	if (next_pt > (start + length))
+		return length;
+
+	return next_pt - start;
+}
+
+static inline uint64_t gen8_bound_pd(uint64_t start, uint64_t length)
+{
+	uint64_t next_pt = ALIGN(start + 1, 1 << GEN8_PDPE_SHIFT);
+	if (next_pt > (start + length))
+		return length;
+
+	return next_pt - start;
+}
+
+#define gen8_for_each_pde(pt, pd, start, length, temp, iter) \
+	for (iter = gen8_pde_index(start), pt = (pd)->page_tables[iter]; \
+	     length > 0 && iter < I915_PDES_PER_PD; \
+	     pt = (pd)->page_tables[++iter], \
+	     temp = ALIGN(start+1, 1 << GEN8_PDE_SHIFT) - start, \
+	     temp = min(temp, length), \
+	     start += temp, length -= temp)
+
+#define gen8_for_each_pdpe(pd, pdp, start, length, temp, iter) \
+	for (iter = gen8_pdpe_index(start), pd = (pdp)->pagedir[iter]; \
+	     length > 0 && iter < GEN8_LEGACY_PDPS; \
+	     pd = (pdp)->pagedir[iter++], \
+	     temp = ALIGN(start+1, 1 << GEN8_PDPE_SHIFT) - start, \
+	     temp = min(temp, length), \
+	     start += temp, length -= temp)
+
 enum i915_cache_level;
 /**
  * A VMA represents a GEM BO that is bound into an address space. Therefore, a
-- 
1.9.0

  parent reply	other threads:[~2014-03-18  5:49 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-18  5:48 [PATCH 00/26] [RFCish] GEN7 dynamic page tables Ben Widawsky
2014-03-18  5:48 ` [PATCH 01/26] drm/i915: Split out verbose PPGTT dumping Ben Widawsky
2014-03-20 11:57   ` Chris Wilson
2014-03-20 12:08     ` Chris Wilson
2014-03-22 18:13       ` Ben Widawsky
2014-03-22 20:59         ` Chris Wilson
2014-03-18  5:48 ` [PATCH 02/26] drm/i915: Extract switch to default context Ben Widawsky
2014-03-18  8:38   ` Chris Wilson
2014-03-18  5:48 ` [PATCH 03/26] drm/i915: s/pd/pdpe, s/pt/pde Ben Widawsky
2014-03-18  5:48 ` [PATCH 04/26] drm/i915: rename map/unmap to dma_map/unmap Ben Widawsky
2014-03-18  8:40   ` Chris Wilson
2014-03-18  5:48 ` [PATCH 05/26] drm/i915: Setup less PPGTT on failed pagedir Ben Widawsky
2014-03-18  5:48 ` [PATCH 06/26] drm/i915: Wrap VMA binding Ben Widawsky
2014-03-18  8:42   ` Chris Wilson
2014-03-18  5:48 ` [PATCH 07/26] drm/i915: clean up PPGTT init error path Ben Widawsky
2014-03-18  8:44   ` Chris Wilson
2014-03-22 19:43     ` Ben Widawsky
2014-03-22 20:58       ` Chris Wilson
2014-03-23 17:27         ` Ben Widawsky
2014-03-18  5:48 ` [PATCH 08/26] drm/i915: Un-hardcode number of page directories Ben Widawsky
2014-03-18  5:48 ` [PATCH 09/26] drm/i915: Split out gtt specific header file Ben Widawsky
2014-03-18  8:46   ` Chris Wilson
2014-03-18  9:15   ` Daniel Vetter
2014-03-22 19:44     ` Ben Widawsky
2014-03-23  0:46       ` Daniel Vetter
2014-03-18  5:48 ` [PATCH 10/26] drm/i915: Make gen6_write_pdes gen6_map_page_tables Ben Widawsky
2014-03-18  8:48   ` Chris Wilson
2014-03-18  5:48 ` [PATCH 11/26] drm/i915: Range clearing is PPGTT agnostic Ben Widawsky
2014-03-18  8:50   ` Chris Wilson
2014-03-18  5:48 ` [PATCH 12/26] drm/i915: Page table helpers, and define renames Ben Widawsky
2014-03-18  9:05   ` Chris Wilson
2014-03-18 18:29     ` Jesse Barnes
2014-03-19  0:58       ` Ben Widawsky
2014-03-18  5:48 ` [PATCH 13/26] drm/i915: construct page table abstractions Ben Widawsky
2014-03-18  5:48 ` [PATCH 14/26] drm/i915: Complete page table structures Ben Widawsky
2014-03-18  9:09   ` Chris Wilson
2014-03-22 20:10     ` Ben Widawsky
2014-03-22 21:14       ` Chris Wilson
2014-03-18  5:48 ` [PATCH 15/26] drm/i915: Create page table allocators Ben Widawsky
2014-03-18  9:14   ` Chris Wilson
2014-03-22 20:21     ` Ben Widawsky
2014-03-22 21:10       ` Chris Wilson
2014-03-18  5:48 ` [PATCH 16/26] drm/i915: Generalize GEN6 mapping Ben Widawsky
2014-03-18  9:22   ` Chris Wilson
2014-03-18  5:48 ` [PATCH 17/26] drm/i915: Clean up pagetable DMA map & unmap Ben Widawsky
2014-03-18  9:24   ` Chris Wilson
2014-03-18  5:48 ` [PATCH 18/26] drm/i915: Always dma map page table allocations Ben Widawsky
2014-03-18  9:25   ` Chris Wilson
2014-03-18  5:48 ` [PATCH 19/26] drm/i915: Consolidate dma mappings Ben Widawsky
2014-03-18  9:28   ` Chris Wilson
2014-03-18  5:48 ` [PATCH 20/26] drm/i915: Always dma map page directory allocations Ben Widawsky
2014-03-18  9:29   ` Chris Wilson
2014-03-18  5:48 ` [PATCH 21/26] drm/i915: Track GEN6 page table usage Ben Widawsky
2014-03-18  5:48 ` [PATCH 22/26] drm/i915: Extract context switch skip logic Ben Widawsky
2014-03-18  5:48 ` [PATCH 23/26] drm/i915: Force pd restore when PDEs change, gen6-7 Ben Widawsky
2014-03-18  5:48 ` [PATCH 24/26] drm/i915: Finish gen6/7 dynamic page table allocation Ben Widawsky
2014-03-20 12:15   ` Chris Wilson
2014-03-18  5:48 ` [PATCH 25/26] drm/i915: Print used ppgtt pages for gen6 in debugfs Ben Widawsky
2014-03-20 10:09   ` Chris Wilson
2014-03-20 10:17   ` Chris Wilson
2014-03-18  5:48 ` Ben Widawsky [this message]
2014-03-20 12:17 ` [PATCH 00/26] [RFCish] GEN7 dynamic page tables Chris Wilson

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=1395121738-29126-27-git-send-email-benjamin.widawsky@intel.com \
    --to=benjamin.widawsky@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /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.