PPGTT dynamic page allocations
Subsystems (2)
PATCH v5 5/32 drm/i915: Track GEN6 page table usage
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
Instead of implementing the full tracking + dynamic allocation, this patch does a bit less than half of the work, by tracking and warning on unexpected conditions. The tracking itself follows which PTEs within a page table are currently being used for objects. The next patch will modify this to actually allocate the page tables only when necessary.
With the current patch there isn't much in the way of making a gen agnostic range allocation function. However, in the next patch we'll add more specificity which makes having separate functions a bit easier to manage.
One important change introduced here is that DMA mappings are created/destroyed at the same page directories/tables are allocated/deallocated.
Notice that aliasing PPGTT is not managed here. The patch which actually begins dynamic allocation/teardown explains the reasoning for this.
v2: s/pdp.page_directory/pdp.page_directorys
Make a scratch page allocation helper
v3: Rebase and expand commit message.
v4: Allocate required pagetables only when it is needed, _bind_to_vm instead of bind_vma (Daniel).
v5: Rebased to remove the unnecessary noise in the diff, also:
- PDE mask is GEN agnostic, renamed GEN6_PDE_MASK to I915_PDE_MASK.
- Removed unnecessary checks in gen6_alloc_va_range.
- Changed map/unmap_px_single macros to use dma functions directly and be part of a static inline function instead.
- Moved drm_device plumbing through page tables operation to its own patch.
- Moved allocate/teardown_va_range calls until they are fully implemented (in subsequent patch).
- Merged pt and scratch_pt unmap_and_free path.
- Moved scratch page allocator helper to the patch that will use it.
v6: Reduce complexity by not tearing down pagetables dynamically, the same can be achieved while freeing empty vms. (Daniel)
v7: s/i915_dma_map_px_single/i915_dma_map_single s/gen6_write_pdes/gen6_write_pde
Prevent a NULL case when only GGTT is available. (Mika)
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 198 +++++++++++++++++++++++++----------- drivers/gpu/drm/i915/i915_gem_gtt.h | 75 ++++++++++++++ 2 files changed, 211 insertions(+), 62 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +136 -62
@@ -278,29 +278,88 @@ static gen6_gtt_pte_t iris_pte_encode(dma_addr_t addr,return pte; } -static void unmap_and_free_pt (struct i915_page_table_entry *pt,struct drm_device *dev) +#define i915_dma_unmap_single (px, dev) \ + __i915_dma_unmap_single((px)->daddr, dev) + +static inline void __i915_dma_unmap_single (dma_addr_t daddr, +struct drm_device *dev) +{ +struct device *device = &dev->pdev->dev; + +dma_unmap_page (device, daddr,4096 ,PCI_DMA_BIDIRECTIONAL ); +} + +/** +* i915_dma_map_single() - Create a dma mapping for a page table/dir/etc. +* @px: Page table/dir/etc to get a DMA map for +* @dev: drm device +* +* Page table allocations are unified across all gens. They always require a +* single 4k allocation, as well as a DMA mapping. If we keep the structs +* symmetric here, the simple macro covers us for every page table type. +* +* Return: 0 if success. +*/ +#define i915_dma_map_single (px, dev) \ + i915_dma_map_page_single((px)->page, (dev), &(px)->daddr) + +static inline int i915_dma_map_page_single (struct page *page, +struct drm_device *dev, +dma_addr_t *daddr) +{ +struct device *device = &dev->pdev->dev; + + *daddr =dma_map_page (device, page,0 ,4096 ,PCI_DMA_BIDIRECTIONAL ); +return dma_mapping_error (device, *daddr); +} + +static void unmap_and_free_pt (struct i915_page_table_entry *pt, +struct drm_device *dev) {if (WARN_ON (!pt->page))return ; + +i915_dma_unmap_single (pt, dev);__free_page (pt->page); +kfree (pt->used_ptes);kfree (pt); }static struct i915_page_table_entry *alloc_pt_single (struct drm_device *dev) {struct i915_page_table_entry *pt; +const size_t count =INTEL_INFO (dev)->gen >=8 ? +GEN8_PTES_PER_PAGE :I915_PPGTT_PT_ENTRIES ; +int ret = -ENOMEM ; pt =kzalloc (sizeof (*pt),GFP_KERNEL );if (!pt)return ERR_PTR (-ENOMEM ); + pt->used_ptes =kcalloc (BITS_TO_LONGS (count),sizeof (*pt->used_ptes), +GFP_KERNEL ); + +if (!pt->used_ptes) + goto fail_bitmap; + pt->page =alloc_page (GFP_KERNEL | __GFP_ZERO); -if (!pt->page) { -kfree (pt); -return ERR_PTR (-ENOMEM ); - } +if (!pt->page) + goto fail_page; + + ret =i915_dma_map_single (pt, dev); +if (ret) + goto fail_dma;return pt; + +fail_dma: +__free_page (pt->page); +fail_page: +kfree (pt->used_ptes); +fail_bitmap: +kfree (pt); + +return ERR_PTR (ret); }/**
@@ -838,26 +897,35 @@ static void gen6_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m) } } -static void gen6_write_pdes (struct i915_hw_ppgtt *ppgtt) +/* Write pde (index) from the page directory @pd to the page table @pt */ +static void gen6_write_pde (struct i915_page_directory_entry *pd, +const int pde,struct i915_page_table_entry *pt) { -struct drm_i915_private *dev_priv = ppgtt->base.dev->dev_private; -gen6_gtt_pte_t __iomem *pd_addr; -uint32_t pd_entry; -int i; +/* Caller needs to make sure the write completes if necessary */ +struct i915_hw_ppgtt *ppgtt = + container_of(pd, struct i915_hw_ppgtt, pd); +u32 pd_entry; -WARN_ON (ppgtt->pd.pd_offset &0x3f ); - pd_addr = (gen6_gtt_pte_t __iomem *)dev_priv->gtt.gsm + - ppgtt->pd.pd_offset /sizeof (gen6_gtt_pte_t); -for (i =0 ; i < ppgtt->num_pd_entries; i++) { -dma_addr_t pt_addr; + pd_entry =GEN6_PDE_ADDR_ENCODE (pt->daddr); + pd_entry |=GEN6_PDE_VALID ; - pt_addr = ppgtt->pd.page_tables[i]->daddr; - pd_entry =GEN6_PDE_ADDR_ENCODE (pt_addr); - pd_entry |=GEN6_PDE_VALID ; +writel (pd_entry, ppgtt->pd_addr + pde); +} -writel (pd_entry, pd_addr + i); - } -readl (pd_addr); +/* Write all the page tables found in the ppgtt structure to incrementing page +* directories. */ +static void gen6_write_page_range (struct drm_i915_private *dev_priv, +struct i915_page_directory_entry *pd,uint32_t start,uint32_t length) +{ +struct i915_page_table_entry *pt; +uint32_t pde, temp; + +gen6_for_each_pde (pt, pd, start, length, temp, pde) +gen6_write_pde (pd, pde, pt); + +/* Make sure write is complete before other code can use this page +* table. Also require for WC mapped PTEs */ +readl (dev_priv->gtt.gsm); }static uint32_t get_pd_offset (struct i915_hw_ppgtt *ppgtt)
@@ -1083,6 +1151,28 @@ static void gen6_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt) 4096, PCI_DMA_BIDIRECTIONAL); } +static int gen6_alloc_va_range (struct i915_address_space *vm, +uint64_t start,uint64_t length) +{ +struct i915_hw_ppgtt *ppgtt = + container_of(vm, struct i915_hw_ppgtt, base); +struct i915_page_table_entry *pt; +uint32_t pde, temp; + +gen6_for_each_pde (pt, &ppgtt->pd, start, length, temp, pde) { +DECLARE_BITMAP (tmp_bitmap,I915_PPGTT_PT_ENTRIES ); + +bitmap_zero (tmp_bitmap,I915_PPGTT_PT_ENTRIES ); +bitmap_set (tmp_bitmap,gen6_pte_index (start), +gen6_pte_count (start, length)); + +bitmap_or (pt->used_ptes, pt->used_ptes, tmp_bitmap, +I915_PPGTT_PT_ENTRIES ); + } + +return 0 ; +} +static void gen6_ppgtt_free (struct i915_hw_ppgtt *ppgtt) {int i;
@@ -1129,20 +1219,24 @@ alloc:0 , dev_priv->gtt.base.total, 0);if (ret) -return ret; + goto err_out; retried = true; goto alloc; }if (ret) -return ret; + goto err_out; +if (ppgtt->node.start < dev_priv->gtt.mappable_end)DRM_DEBUG ("Forced to use aperture for PDEs\n" ); ppgtt->num_pd_entries =GEN6_PPGTT_PD_ENTRIES ;return 0 ; + +err_out: +return ret; }static int gen6_ppgtt_alloc (struct i915_hw_ppgtt *ppgtt)
@@ -1164,30 +1258,6 @@ static int gen6_ppgtt_alloc(struct i915_hw_ppgtt *ppgtt)return 0 ; } -static int gen6_ppgtt_setup_page_tables (struct i915_hw_ppgtt *ppgtt) -{ -struct drm_device *dev = ppgtt->base.dev; -int i; - -for (i =0 ; i < ppgtt->num_pd_entries; i++) { -struct page *page; -dma_addr_t pt_addr; - - page = ppgtt->pd.page_tables[i]->page; - pt_addr =pci_map_page (dev->pdev, page,0 ,4096 , -PCI_DMA_BIDIRECTIONAL ); - -if (pci_dma_mapping_error (dev->pdev, pt_addr)) { -gen6_ppgtt_unmap_pages (ppgtt); -return -EIO ; - } - - ppgtt->pd.page_tables[i]->daddr = pt_addr; - } - -return 0 ; -} -static int gen6_ppgtt_init (struct i915_hw_ppgtt *ppgtt) {struct drm_device *dev = ppgtt->base.dev;
@@ -1211,12 +1281,7 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)if (ret)return ret; - ret =gen6_ppgtt_setup_page_tables (ppgtt); -if (ret) { -gen6_ppgtt_free (ppgtt); -return ret; - } - + ppgtt->base.allocate_va_range = gen6_alloc_va_range; ppgtt->base.clear_range = gen6_ppgtt_clear_range; ppgtt->base.insert_entries = gen6_ppgtt_insert_entries; ppgtt->base.cleanup = gen6_ppgtt_cleanup;
@@ -1227,13 +1292,17 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt) ppgtt->pd.pd_offset = ppgtt->node.start /PAGE_SIZE *sizeof (gen6_gtt_pte_t); + ppgtt->pd_addr = (gen6_gtt_pte_t __iomem *)dev_priv->gtt.gsm + + ppgtt->pd.pd_offset /sizeof (gen6_gtt_pte_t); + ppgtt->base.clear_range (&ppgtt->base,0 , ppgtt->base.total, true); +gen6_write_page_range (dev_priv, &ppgtt->pd,0 , ppgtt->base.total); +DRM_DEBUG_DRIVER ("Allocated pde space (%ldM) at GTT entry: %lx\n" , ppgtt->node.size >>20 , ppgtt->node.start /PAGE_SIZE ); -gen6_write_pdes (ppgtt);DRM_DEBUG ("Adding PPGTT at offset %x\n" , ppgtt->pd.pd_offset <<10 );
@@ -1504,15 +1573,20 @@ void i915_gem_restore_gtt_mappings(struct drm_device *dev)return ; } -list_for_each_entry (vm, &dev_priv->vm_list, global_link) { -/* TODO: Perhaps it shouldn't be gen6 specific */ -if (i915_is_ggtt (vm)) { -if (dev_priv->mm.aliasing_ppgtt) -gen6_write_pdes (dev_priv->mm.aliasing_ppgtt); -continue ; - } +if (USES_PPGTT (dev)) { +list_for_each_entry (vm, &dev_priv->vm_list, global_link) { +/* TODO: Perhaps it shouldn't be gen6 specific */ + +struct i915_hw_ppgtt *ppgtt = + container_of(vm, struct i915_hw_ppgtt, + base); -gen6_write_pdes (container_of(vm ,struct i915_hw_ppgtt ,base )); +if (i915_is_ggtt (vm)) + ppgtt = dev_priv->mm.aliasing_ppgtt; + +gen6_write_page_range (dev_priv, &ppgtt->pd,0 , + ppgtt->num_pd_entries); + } }i915_ggtt_flush (dev_priv);
drivers/gpu/drm/i915/i915_gem_gtt.h +75 -0
106 lines not on this page · raw message
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 6/32 drm/i915: Extract context switch skip and pd load logic
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
We have some fanciness coming up. This patch just breaks out the logic of context switch skip, pd load pre, and pd load post.
v2: Use new functions to replace the logic right away (Daniel)
--- drivers/gpu/drm/i915/i915_gem_context.c | 40 +++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +31 -9
@@ -565,6 +565,33 @@ mi_set_context(struct intel_engine_cs *ring,return ret; } +static inline bool should_skip_switch (struct intel_engine_cs *ring, +struct intel_context *from, +struct intel_context *to) +{ +if (from == to && !to->remap_slice) +return true; + +return false; +} + +static bool +needs_pd_load_pre (struct intel_engine_cs *ring,struct intel_context *to) +{ +struct drm_i915_private *dev_priv = ring->dev->dev_private; + +return ((INTEL_INFO (ring->dev)->gen <8 ) || + (ring != &dev_priv->ring[RCS ])) && to->ppgtt; +} + +static bool +needs_pd_load_post (struct intel_engine_cs *ring,struct intel_context *to) +{ +return (!to->legacy_hw_ctx.initialized || +i915_gem_context_is_default (to)) && + to->ppgtt &&IS_GEN8 (ring->dev); +} +static int do_switch (struct intel_engine_cs *ring,struct intel_context *to) {
@@ -573,9 +600,6 @@ static int do_switch(struct intel_engine_cs *ring,u32 hw_flags =0 ;bool uninitialized = false;struct i915_vma *vma; -bool needs_pd_load_pre = ((INTEL_INFO (ring->dev)->gen <8 ) || - (ring != &dev_priv->ring[RCS ])) && to->ppgtt; -bool needs_pd_load_post = false;int ret, i;if (from !=NULL && ring == &dev_priv->ring[RCS ]) {
@@ -583,7 +607,7 @@ static int do_switch(struct intel_engine_cs *ring,BUG_ON (!i915_gem_obj_is_pinned (from->legacy_hw_ctx.rcs_state)); } -if (from == to && !to->remap_slice) +if (should_skip_switch (ring, from, to))return 0 ;/* Trying to pin first makes error handling easier. */
@@ -601,7 +625,7 @@ static int do_switch(struct intel_engine_cs *ring,*/ from = ring->last_context; -if (needs_pd_load_pre) { +if (needs_pd_load_pre (ring, to)) {/* Older GENs and non render rings still want the load first, * "PP_DCLV followed by PP_DIR_BASE register through Load * Register Immediate commands in Ring Buffer before submitting
@@ -646,16 +670,14 @@ static int do_switch(struct intel_engine_cs *ring,* XXX: If we implemented page directory eviction code, this * optimization needs to be removed. */ -if (!to->legacy_hw_ctx.initialized ||i915_gem_context_is_default (to)) { +if (!to->legacy_hw_ctx.initialized ||i915_gem_context_is_default (to)) hw_flags |=MI_RESTORE_INHIBIT ; - needs_pd_load_post = to->ppgtt &&IS_GEN8 (ring->dev); - } ret =mi_set_context (ring, to, hw_flags);if (ret) goto unpin_out; -if (needs_pd_load_post) { +if (needs_pd_load_post (ring, to)) { ret = to->ppgtt->switch_mm (to->ppgtt, ring);/* The hardware context switch is emitted, but we haven't * actually changed the state - so it's probably safe to bail
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 7/32 drm/i915: Track page table reload need
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
This patch was formerly known as, "Force pd restore when PDEs change, gen6-7." I had to change the name because it is needed for GEN8 too.
The real issue this is trying to solve is when a new object is mapped into the current address space. The GPU does not snoop the new mapping so we must do the gen specific action to reload the page tables.
GEN8 and GEN7 do differ in the way they load page tables for the RCS. GEN8 does so with the context restore, while GEN7 requires the proper load commands in the command streamer. Non-render is similar for both.
Caveat for GEN7
The docs say you cannot change the PDEs of a currently running context. We never map new PDEs of a running context, and expect them to be present - so I think this is okay. (We can unmap, but this should also be okay since we only unmap unreferenced objects that the GPU shouldn't be tryingto va->pa xlate.) The MI_SET_CONTEXT command does have a flag to signal that even if the context is the same, force a reload. It's unclear exactly what this does, but I have a hunch it's the right thing to do.
The logic assumes that we always emit a context switch after mapping new PDEs, and before we submit a batch. This is the case today, and has been the case since the inception of hardware contexts. A note in the comment let's the user know.
It's not just for gen8. If the current context has mappings change, we need a context reload to switch
v2: Rebased after ppgtt clean up patches. Split the warning for aliasing and true ppgtt options. And do not break aliasing ppgtt, where to->ppgtt is always null.
v3: Invalidate PPGTT TLBs inside alloc_va_range.
v4: Rename ppgtt_invalidate_tlbs to mark_tlbs_dirty and move pd_dirty_rings from i915_address_space to i915_hw_ppgtt. Fixes when neither ctx->ppgtt and aliasing_ppgtt exist.
v5: Removed references to teardown_va_range.
--- drivers/gpu/drm/i915/i915_gem_context.c | 29 ++++++++++++++++++++++++----- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 11 +++++++++++ drivers/gpu/drm/i915/i915_gem_gtt.c | 11 +++++++++++ drivers/gpu/drm/i915/i915_gem_gtt.h | 1 + 4 files changed, 47 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +24 -5
@@ -569,8 +569,20 @@ static inline bool should_skip_switch(struct intel_engine_cs *ring,struct intel_context *from, struct intel_context *to) { -if (from == to && !to->remap_slice) -return true; + struct drm_i915_private *dev_priv = ring->dev->dev_private; + +if (to->remap_slice) +return false; + +if (to->ppgtt) { +if (from == to && !test_bit (ring->id, + &to->ppgtt->pd_dirty_rings)) +return true; + }else if (dev_priv->mm.aliasing_ppgtt) { +if (from == to && !test_bit (ring->id, + &dev_priv->mm.aliasing_ppgtt->pd_dirty_rings)) +return true; + }return false; }
@@ -587,9 +599,8 @@ needs_pd_load_pre(struct intel_engine_cs *ring, struct intel_context *to)static bool needs_pd_load_post (struct intel_engine_cs *ring,struct intel_context *to) { -return (!to->legacy_hw_ctx.initialized || -i915_gem_context_is_default (to)) && - to->ppgtt &&IS_GEN8 (ring->dev); +return IS_GEN8 (ring->dev) && + (to->ppgtt || &to->ppgtt->pd_dirty_rings); } static int do_switch(struct intel_engine_cs *ring,
@@ -634,6 +645,12 @@ static int do_switch(struct intel_engine_cs *ring, ret = to->ppgtt->switch_mm (to->ppgtt, ring);if (ret) goto unpin_out; + +/* Doing a PD load always reloads the page dirs */ +if (to->ppgtt) +clear_bit (ring->id, &to->ppgtt->pd_dirty_rings); +else +clear_bit (ring->id, &dev_priv->mm.aliasing_ppgtt->pd_dirty_rings); }if (ring != &dev_priv->ring[RCS ]) {
@@ -672,6 +689,8 @@ static int do_switch(struct intel_engine_cs *ring,*/ if (!to->legacy_hw_ctx.initialized ||i915_gem_context_is_default (to)) hw_flags |=MI_RESTORE_INHIBIT ; +else if (to->ppgtt &&test_and_clear_bit (ring->id, &to->ppgtt->pd_dirty_rings)) + hw_flags |=MI_FORCE_RESTORE ; ret =mi_set_context (ring, to, hw_flags);if (ret)
drivers/gpu/drm/i915/i915_gem_execbuffer.c +11 -0
@@ -1198,6 +1198,13 @@ i915_gem_ringbuffer_submission(struct drm_device *dev, struct drm_file *file,if (ret) goto error; +if (ctx->ppgtt) +WARN (ctx->ppgtt->pd_dirty_rings & (1 <<ring->id), +"%s didn't clear reload\n" , ring->name); +else if (dev_priv->mm.aliasing_ppgtt) +WARN (dev_priv->mm.aliasing_ppgtt->pd_dirty_rings & + (1 <<ring->id),"%s didn't clear reload\n" , ring->name); + instp_mode = args->flags &I915_EXEC_CONSTANTS_MASK ; instp_mask =I915_EXEC_CONSTANTS_MASK ;switch (instp_mode) {
@@ -1467,6 +1474,10 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,if (ret) goto err; +/* XXX: Reserve has possibly change PDEs which means we must do a +* context switch before we can coherently read some of the reserved +* VMAs. */ +/* The objects are in their final locations, apply the relocations. */ if (need_relocs) ret =i915_gem_execbuffer_relocate (eb);
drivers/gpu/drm/i915/i915_gem_gtt.c +11 -0
@@ -1151,6 +1151,16 @@ static void gen6_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt) 4096, PCI_DMA_BIDIRECTIONAL); } +/* PDE TLBs are a pain invalidate pre GEN8. It requires a context reload. If we +* are switching between contexts with the same LRCA, we also must do a force +* restore. +*/ +static inline void mark_tlbs_dirty (struct i915_hw_ppgtt *ppgtt) +{ +/* If current vm != vm, */ + ppgtt->pd_dirty_rings =INTEL_INFO (ppgtt->base.dev)->ring_mask; +} +static int gen6_alloc_va_range (struct i915_address_space *vm,uint64_t start,uint64_t length) {
@@ -1170,6 +1180,7 @@ static int gen6_alloc_va_range(struct i915_address_space *vm, I915_PPGTT_PT_ENTRIES); } +mark_tlbs_dirty (ppgtt);return 0 ; }
drivers/gpu/drm/i915/i915_gem_gtt.h +1 -0
@@ -297,6 +297,7 @@ struct i915_hw_ppgtt {struct i915_address_space base;struct kref ref;struct drm_mm_node node; +unsigned long pd_dirty_rings;unsigned num_pd_entries;unsigned num_pd_pages;/* gen8+ */ union {
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 8/32 drm/i915: Initialize all contexts
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
The problem is we're going to switch to a new context, which could be the default context. The plan was to use restore inhibit, which would be fine, except if we are using dynamic page tables (which we will). If we use dynamic page tables and we don't load new page tables, the previous page tables might go away, and future operations will fault.
CTXA runs.
switch to default, restore inhibit
CTXA dies and has its address space taken away.
Run CTXB, tries to save using the context A's address space - this fails.
The general solution is to make sure every context has it's own state, and its own address space. For cases when we must restore inhibit, first thing we do is load a valid address space. I thought this would be enough, but apparently there are references within the context itself which will refer to the old address space - therefore, we also must reinitialize.
It was tricky to track this down as we don't have much insight into what happens in a context save.
This is required for the next patch which enables dynamic page tables.
v2: to->ppgtt is only valid in full ppgtt.
--- drivers/gpu/drm/i915/i915_gem_context.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +11 -14
@@ -596,13 +596,6 @@ needs_pd_load_pre(struct intel_engine_cs *ring, struct intel_context *to) (ring != &dev_priv->ring[RCS])) && to->ppgtt; } -static bool -needs_pd_load_post (struct intel_engine_cs *ring,struct intel_context *to) -{ -return IS_GEN8 (ring->dev) && - (to->ppgtt || &to->ppgtt->pd_dirty_rings); -} -static int do_switch (struct intel_engine_cs *ring,struct intel_context *to) {
@@ -683,20 +676,24 @@ static int do_switch(struct intel_engine_cs *ring,/* GEN8 does *not* require an explicit reload if the PDPs have been * setup, and we do not wish to move them. -* -* XXX: If we implemented page directory eviction code, this -* optimization needs to be removed. */ -if (!to->legacy_hw_ctx.initialized ||i915_gem_context_is_default (to)) +if (!to->legacy_hw_ctx.initialized) { hw_flags |=MI_RESTORE_INHIBIT ; -else if (to->ppgtt &&test_and_clear_bit (ring->id, &to->ppgtt->pd_dirty_rings)) +/* NB: If we inhibit the restore, the context is not allowed to +* die because future work may end up depending on valid address +* space. This means we must enforce that a page table load +* occur when this occurs. */ + }else if (to->ppgtt &&test_and_clear_bit (ring->id, &to->ppgtt->pd_dirty_rings)) hw_flags |=MI_FORCE_RESTORE ; ret =mi_set_context (ring, to, hw_flags);if (ret) goto unpin_out; -if (needs_pd_load_post (ring, to)) { +if (IS_GEN8 (ring->dev) && to->ppgtt && (hw_flags &MI_RESTORE_INHIBIT )) { +/* We have a valid page directory (scratch) to switch to. This +* allows the old VM to be freed. Note that if anything occurs +* between the set context, and here, we are f*cked */ ret = to->ppgtt->switch_mm (to->ppgtt, ring);/* The hardware context switch is emitted, but we haven't * actually changed the state - so it's probably safe to bail
@@ -746,7 +743,7 @@ static int do_switch(struct intel_engine_cs *ring,i915_gem_context_unreference (from); } - uninitialized = !to->legacy_hw_ctx.initialized && from ==NULL ; + uninitialized = !to->legacy_hw_ctx.initialized; to->legacy_hw_ctx.initialized = true; done:
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 9/32 drm/i915: Finish gen6/7 dynamic page table allocation
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
This patch continues on the idea from the previous patch. From here on, in the steady state, PDEs are all pointing to the scratch page table (as recommended in the spec). When an object is allocated in the VA range, the code will determine if we need to allocate a page for the page table. Similarly when the object is destroyed, we will remove, and free the page table pointing the PDE back to the scratch page.
Following patches will work to unify the code a bit as we bring in GEN8 support. GEN6 and GEN8 are different enough that I had a hard time to get to this point with as much common code as I do.
The aliasing PPGTT must pre-allocate all of the page tables. There are a few reasons for this. Two trivial ones: aliasing ppgtt goes through the ggtt paths, so it's hard to maintain, we currently do not restore the default context (assuming the previous force reload is indeed necessary). Most importantly though, the only way (it seems from empirical evidence) to invalidate the CS TLBs on non-render ring is to either use ring sync (which requires actually stopping the rings in order to synchronize when the sync completes vs. where you are in execution), or to reload DCLV. Since without full PPGTT we do not ever reload the DCLV register, there is no good way to achieve this. The simplest solution is just to not support dynamic page table creation/destruction in the aliasing PPGTT.
We could always reload DCLV, but this seems like quite a bit of excess overhead only to save at most 2MB-4k of memory for the aliasing PPGTT page tables.
v2: Make the page table bitmap declared inside the function (Chris) Simplify the way scratching address space works.
Move the alloc/teardown tracepoints up a level in the call stack so that both all implementations get the trace.
v3: Updated trace event to spit out a name
v4: Aliasing ppgtt is now initialized differently (in setup global gtt)
v5: Rebase to latest code. Also removed unnecessary aliasing ppgtt check for trace, as it is no longer possible after the PPGTT cleanup patch series of a couple of months ago (Daniel).
v6: Implement changes from code review (Daniel):
- allocate/teardown_va_range calls added.
- Add a scratch page allocation helper (only need the address).
- Move trace events to a new patch.
- Use updated mark_tlbs_dirty.
- Moved pt preallocation for aliasing ppgtt into gen6_ppgtt_init.
v7: teardown_va_range removed (Daniel).
In init, gen6_ppgtt_clear_range call is only needed for aliasing ppgtt.
--- drivers/gpu/drm/i915/i915_debugfs.c | 3 +- drivers/gpu/drm/i915/i915_gem.c | 9 +++ drivers/gpu/drm/i915/i915_gem_gtt.c | 125 +++++++++++++++++++++++++++++++----- drivers/gpu/drm/i915/i915_gem_gtt.h | 3 + 4 files changed, 123 insertions(+), 17 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +2 -1
@@ -2181,6 +2181,8 @@ static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)seq_printf (m,"PP_DIR_BASE_READ: 0x%08x\n" ,I915_READ (RING_PP_DIR_BASE_READ (ring)));seq_printf (m,"PP_DIR_DCLV: 0x%08x\n" ,I915_READ (RING_PP_DIR_DCLV (ring))); } +seq_printf (m,"ECOCHK: 0x%08x\n\n" ,I915_READ (GAM_ECOCHK )); +if (dev_priv->mm.aliasing_ppgtt) {struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
@@ -2197,7 +2199,6 @@ static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev) get_pid_task(file->pid, PIDTYPE_PID)->comm);idr_for_each (&file_priv->context_idr, per_file_ctx, m); } -seq_printf (m,"ECOCHK: 0x%08x\n" ,I915_READ (GAM_ECOCHK )); }static int i915_ppgtt_info (struct seq_file *m,void *data)
drivers/gpu/drm/i915/i915_gem.c +9 -0
@@ -3599,6 +3599,15 @@ search_free:if (ret) goto err_remove_node; +/* allocate before insert / bind */ +if (vma->vm->allocate_va_range) { + ret = vma->vm->allocate_va_range (vma->vm, + vma->node.start, + vma->node.size); +if (ret) + goto err_remove_node; + } +trace_i915_vma_bind (vma, flags); ret =i915_vma_bind (vma, obj->cache_level, flags &PIN_GLOBAL ?GLOBAL_BIND :0 );
drivers/gpu/drm/i915/i915_gem_gtt.c +109 -16
217 lines not on this page · raw message
drivers/gpu/drm/i915/i915_gem_gtt.h +3 -0
@@ -195,6 +195,7 @@ struct i915_page_table_entry {dma_addr_t daddr;unsigned long *used_ptes; + unsigned int scratch:1; };struct i915_page_directory_entry {
@@ -305,6 +306,8 @@ struct i915_hw_ppgtt {struct i915_page_directory_entry pd; }; +struct i915_page_table_entry *scratch_pt; +struct drm_i915_file_private *file_priv;gen6_gtt_pte_t __iomem *pd_addr;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 10/32 drm/i915: Add dynamic page trace events
In reply to Michel ThierryTraces for page directories and tables allocation and map.
v2: Removed references to teardown.
v3: bitmap_scnprintf has been deprecated.
--- drivers/gpu/drm/i915/i915_gem.c | 2 + drivers/gpu/drm/i915/i915_gem_gtt.c | 5 ++ drivers/gpu/drm/i915/i915_trace.h | 95 +++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+)
drivers/gpu/drm/i915/i915_gem.c +2 -0
@@ -3601,6 +3601,8 @@ search_free:/* allocate before insert / bind */ if (vma->vm->allocate_va_range) { +trace_i915_va_alloc (vma->vm, vma->node.start, vma->node.size, +VM_TO_TRACE_NAME (vma->vm)); ret = vma->vm->allocate_va_range (vma->vm, vma->node.start, vma->node.size);
drivers/gpu/drm/i915/i915_gem_gtt.c +5 -0
@@ -1210,6 +1210,7 @@ static int gen6_alloc_va_range(struct i915_address_space *vm, ppgtt->pd.page_tables[pde] = pt;set_bit (pde, new_page_tables); +trace_i915_page_table_entry_alloc (vm, pde, start,GEN6_PDE_SHIFT ); } start = start_save;
@@ -1225,6 +1226,10 @@ static int gen6_alloc_va_range(struct i915_address_space *vm,if (test_and_clear_bit (pde, new_page_tables))gen6_write_pde (&ppgtt->pd, pde, pt); +trace_i915_page_table_entry_map (vm, pde, pt, +gen6_pte_index (start), +gen6_pte_count (start, length), +I915_PPGTT_PT_ENTRIES );bitmap_or (pt->used_ptes, tmp_bitmap, pt->used_ptes,I915_PPGTT_PT_ENTRIES ); }
drivers/gpu/drm/i915/i915_trace.h +95 -0
101 lines not on this page · raw message
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 11/32 drm/i915/bdw: Use dynamic allocation idioms on free
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
The page directory freer is left here for now as it's still useful given that GEN8 still preallocates. Once the allocation functions are broken up into more discrete chunks, we'll follow suit and destroy this leftover piece.
v2: Match trace_i915_va_teardown params
v3: Multiple rebases.
v4: Updated to use unmap_and_free_pt.
v5: teardown_va_range logic no longer needed.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 26 ++++++++++---------- drivers/gpu/drm/i915/i915_gem_gtt.h | 47 +++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 13 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +13 -13
@@ -607,19 +607,6 @@ static void gen8_free_page_tables(struct i915_page_directory_entry *pd, struct d } } -static void gen8_ppgtt_free (struct i915_hw_ppgtt *ppgtt) -{ -int i; - -for (i =0 ; i < ppgtt->num_pd_pages; i++) { -if (WARN_ON (!ppgtt->pdp.page_directory[i])) -continue ; - -gen8_free_page_tables (ppgtt->pdp.page_directory[i], ppgtt->base.dev); -unmap_and_free_pd (ppgtt->pdp.page_directory[i]); - } -} -static void gen8_ppgtt_unmap_pages (struct i915_hw_ppgtt *ppgtt) {struct pci_dev *hwdev = ppgtt->base.dev->pdev;
@@ -652,6 +639,19 @@ static void gen8_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt) } } +static void gen8_ppgtt_free (struct i915_hw_ppgtt *ppgtt) +{ +int i; + +for (i =0 ; i < ppgtt->num_pd_pages; i++) { +if (WARN_ON (!ppgtt->pdp.page_directory[i])) +continue ; + +gen8_free_page_tables (ppgtt->pdp.page_directory[i], ppgtt->base.dev); +unmap_and_free_pd (ppgtt->pdp.page_directory[i]); + } +} +static void gen8_ppgtt_cleanup (struct i915_address_space *vm) { struct i915_hw_ppgtt *ppgtt =
drivers/gpu/drm/i915/i915_gem_gtt.h +47 -0
53 lines not on this page · raw message
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 12/32 drm/i915/bdw: page directories rework allocation
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
Start using gen8_for_each_pdpe macro to allocate the page directories.
v2: Rebased after s/free_pt_*/unmap_and_free_pt/ change.
v3: Rebased after teardown va range logic was removed.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 43 ++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 13 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +30 -13
@@ -681,25 +681,39 @@ unwind_out:return -ENOMEM ; } -static int gen8_ppgtt_allocate_page_directories (struct i915_hw_ppgtt *ppgtt, -const int max_pdp) +static int gen8_ppgtt_alloc_page_directories (struct i915_page_directory_pointer_entry *pdp, +uint64_t start, +uint64_t length) { -int i; - -for (i =0 ; i < max_pdp; i++) { - ppgtt->pdp.page_directory[i] =alloc_pd_single (); -if (IS_ERR (ppgtt->pdp.page_directory[i])) +struct i915_hw_ppgtt *ppgtt = + container_of(pdp, struct i915_hw_ppgtt, pdp); +struct i915_page_directory_entry *unused; +uint64_t temp; +uint32_t pdpe; + +/* FIXME: PPGTT container_of won't work for 64b */ +BUG_ON ((start + length) >0x800000000ULL ); + +gen8_for_each_pdpe (unused, pdp, start, length, temp, pdpe) { +BUG_ON (unused); + pdp->page_directory[pdpe] =alloc_pd_single (); +if (IS_ERR (ppgtt->pdp.page_directory[pdpe])) goto unwind_out; + + ppgtt->num_pd_pages++; } - ppgtt->num_pd_pages = max_pdp;BUG_ON (ppgtt->num_pd_pages >GEN8_LEGACY_PDPES );return 0 ; unwind_out: -while (i--) -unmap_and_free_pd (ppgtt->pdp.page_directory[i]); +while (pdpe--) { +unmap_and_free_pd (ppgtt->pdp.page_directory[pdpe]); + ppgtt->num_pd_pages--; + } + +WARN_ON (ppgtt->num_pd_pages);return -ENOMEM ; }
@@ -709,7 +723,8 @@ static int gen8_ppgtt_alloc(struct i915_hw_ppgtt *ppgtt, {int ret; - ret =gen8_ppgtt_allocate_page_directories (ppgtt, max_pdp); + ret =gen8_ppgtt_alloc_page_directories (&ppgtt->pdp, ppgtt->base.start, + ppgtt->base.total);if (ret)return ret;
@@ -785,6 +800,10 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt, uint64_t size)if (size % (1 <<30 ))DRM_INFO ("Pages will be wasted unless GTT size (%llu) is divisible by 1GB\n" , size); + ppgtt->base.start =0 ; + ppgtt->base.total = size; +BUG_ON (ppgtt->base.total ==0 ); +/* 1. Do all our allocations for page directories and page tables. */ ret =gen8_ppgtt_alloc (ppgtt, max_pdp);if (ret)
@@ -832,8 +851,6 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt, uint64_t size) ppgtt->base.clear_range = gen8_ppgtt_clear_range; ppgtt->base.insert_entries = gen8_ppgtt_insert_entries; ppgtt->base.cleanup = gen8_ppgtt_cleanup; - ppgtt->base.start =0 ; - ppgtt->base.total = ppgtt->num_pd_entries *GEN8_PTES_PER_PAGE *PAGE_SIZE ; ppgtt->base.clear_range (&ppgtt->base,0 , ppgtt->base.total, true);
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 13/32 drm/i915/bdw: pagetable allocation rework
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
Start using gen8_for_each_pde macro to allocate page tables.
v2: teardown_va_range references removed.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 46 +++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 17 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +29 -17
@@ -661,22 +661,27 @@ static void gen8_ppgtt_cleanup(struct i915_address_space *vm)gen8_ppgtt_free (ppgtt); } -static int gen8_ppgtt_allocate_page_tables (struct i915_hw_ppgtt *ppgtt) +static int gen8_ppgtt_alloc_pagetabs (struct i915_page_directory_entry *pd, +uint64_t start, +uint64_t length, +struct drm_device *dev) { -int i, ret; +struct i915_page_table_entry *unused; +uint64_t temp; +uint32_t pde; -for (i =0 ; i < ppgtt->num_pd_pages; i++) { - ret =alloc_pt_range (ppgtt->pdp.page_directory[i], -0 ,GEN8_PDES_PER_PAGE , ppgtt->base.dev); -if (ret) +gen8_for_each_pde (unused, pd, start, length, temp, pde) { +BUG_ON (unused); + pd->page_tables[pde] =alloc_pt_single (dev); +if (IS_ERR (pd->page_tables[pde])) goto unwind_out; }return 0 ; unwind_out: -while (i--) -gen8_free_page_tables (ppgtt->pdp.page_directory[i], ppgtt->base.dev); +while (pde--) +unmap_and_free_pt (pd->page_tables[pde], dev);return -ENOMEM ; }
@@ -719,20 +724,28 @@ unwind_out: }static int gen8_ppgtt_alloc (struct i915_hw_ppgtt *ppgtt, -const int max_pdp) +uint64_t start, +uint64_t length) { +struct i915_page_directory_entry *pd; +uint64_t temp; +uint32_t pdpe;int ret; - ret =gen8_ppgtt_alloc_page_directories (&ppgtt->pdp, ppgtt->base.start, - ppgtt->base.total); + ret =gen8_ppgtt_alloc_page_directories (&ppgtt->pdp, start, length);if (ret)return ret; - ret =gen8_ppgtt_allocate_page_tables (ppgtt); -if (ret) - goto err_out; +gen8_for_each_pdpe (pd, &ppgtt->pdp, start, length, temp, pdpe) { + ret =gen8_ppgtt_alloc_pagetabs (pd, start, length, + ppgtt->base.dev); +if (ret) + goto err_out; + + ppgtt->num_pd_entries +=GEN8_PDES_PER_PAGE ; + } - ppgtt->num_pd_entries = max_pdp *GEN8_PDES_PER_PAGE ; +BUG_ON (pdpe > ppgtt->num_pd_pages);return 0 ;
@@ -802,10 +815,9 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt, uint64_t size) ppgtt->base.start =0 ; ppgtt->base.total = size; -BUG_ON (ppgtt->base.total ==0 );/* 1. Do all our allocations for page directories and page tables. */ - ret =gen8_ppgtt_alloc (ppgtt, max_pdp); + ret =gen8_ppgtt_alloc (ppgtt, ppgtt->base.start, ppgtt->base.total);if (ret)return ret;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 14/32 drm/i915/bdw: Update pdp switch and point unused PDPs to scratch page
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
One important part of this patch is we now write a scratch page directory into any unused PDP descriptors. This matters for 2 reasons, first, we're not allowed to just use 0, or an invalid pointer, and second, we must wipe out any previous contents from the last context.
The latter point only matters with full PPGTT. The former point only effect platforms with less than 4GB memory.
v2: Updated commit message to point that we must set unused PDPs to the scratch page.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 29 ++++++++++++++++++----------- drivers/gpu/drm/i915/i915_gem_gtt.h | 5 ++++- 2 files changed, 22 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +18 -11
@@ -442,8 +442,9 @@ static struct i915_page_directory_entry *alloc_pd_single(void) }/* Broadwell Page Directory Pointer Descriptors */ -static int gen8_write_pdp (struct intel_engine_cs *ring,unsigned entry, -uint64_t val) +static int gen8_write_pdp (struct intel_engine_cs *ring, +unsigned entry, +dma_addr_t addr) {int ret;
@@ -455,10 +456,10 @@ static int gen8_write_pdp(struct intel_engine_cs *ring, unsigned entry,intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 ));intel_ring_emit (ring,GEN8_RING_PDP_UDW (ring, entry)); -intel_ring_emit (ring, (u32)(val >>32 )); +intel_ring_emit (ring,upper_32_bits (addr));intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 ));intel_ring_emit (ring,GEN8_RING_PDP_LDW (ring, entry)); -intel_ring_emit (ring, (u32)(val)); +intel_ring_emit (ring,lower_32_bits (addr));intel_ring_advance (ring);return 0 ;
@@ -469,12 +470,12 @@ static int gen8_mm_switch(struct i915_hw_ppgtt *ppgtt, {int i, ret; -/* bit of a hack to find the actual last used pd */ -int used_pd = ppgtt->num_pd_entries /GEN8_PDES_PER_PAGE ; - -for (i = used_pd -1 ; i >=0 ; i--) { -dma_addr_t addr = ppgtt->pdp.page_directory[i]->daddr; - ret =gen8_write_pdp (ring, i, addr); +for (i =GEN8_LEGACY_PDPES -1 ; i >=0 ; i--) { +struct i915_page_directory_entry *pd = ppgtt->pdp.page_directory[i]; +dma_addr_t pd_daddr = pd ? pd->daddr : ppgtt->scratch_pd->daddr; +/* The page directory might be NULL, but we need to clear out +* whatever the previous context might have used. */ + ret =gen8_write_pdp (ring, i, pd_daddr);if (ret)return ret; }
@@ -816,10 +817,16 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt, uint64_t size) ppgtt->base.start =0 ; ppgtt->base.total = size; + ppgtt->scratch_pd =alloc_pt_scratch (ppgtt->base.dev); +if (IS_ERR (ppgtt->scratch_pd)) +return PTR_ERR (ppgtt->scratch_pd); +/* 1. Do all our allocations for page directories and page tables. */ ret =gen8_ppgtt_alloc (ppgtt, ppgtt->base.start, ppgtt->base.total); -if (ret) +if (ret) { +unmap_and_free_pt (ppgtt->scratch_pd, ppgtt->base.dev);return ret; + }/* * 2. Create DMA mappings for the page directories and page tables.
drivers/gpu/drm/i915/i915_gem_gtt.h +4 -1
@@ -306,7 +306,10 @@ struct i915_hw_ppgtt {struct i915_page_directory_entry pd; }; -struct i915_page_table_entry *scratch_pt; +union { +struct i915_page_table_entry *scratch_pt; +struct i915_page_table_entry *scratch_pd;/* Just need the daddr */ + };struct drm_i915_file_private *file_priv;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 15/32 drm/i915: num_pd_pages/num_pd_entries isn't useful
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
These values are never quite useful for dynamic allocations of the page tables. Getting rid of them will help prevent later confusion.
v2: Updated to use unmap_and_free_pd functions.
v3: Updated gen8_ppgtt_free after teardown logic was removed.
--- drivers/gpu/drm/i915/i915_debugfs.c | 2 -- drivers/gpu/drm/i915/i915_gem_gtt.c | 72 ++++++++++++------------------------- drivers/gpu/drm/i915/i915_gem_gtt.h | 7 ++-- 3 files changed, 28 insertions(+), 53 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +0 -2
@@ -2149,8 +2149,6 @@ static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)if (!ppgtt)return ; -seq_printf (m,"Page directories: %d\n" , ppgtt->num_pd_pages); -seq_printf (m,"Page tables: %d\n" , ppgtt->num_pd_entries);for_each_ring (ring, dev_priv, unused) {seq_printf (m,"%s\n" , ring->name);for (i =0 ; i <4 ; i++) {
drivers/gpu/drm/i915/i915_gem_gtt.c +23 -49
170 lines not on this page · raw message
drivers/gpu/drm/i915/i915_gem_gtt.h +5 -2
@@ -299,8 +299,6 @@ struct i915_hw_ppgtt {struct kref ref;struct drm_mm_node node;unsigned long pd_dirty_rings; -unsigned num_pd_entries; -unsigned num_pd_pages;/* gen8+ */ union {struct i915_page_directory_pointer_entry pdp;struct i915_page_directory_entry pd;
@@ -338,6 +336,11 @@ struct i915_hw_ppgtt { temp = min_t(unsigned, temp, length), \ start += temp, length -= temp) +#define gen6_for_all_pdes (pt, ppgtt, iter) \ + for (iter = 0, pt = ppgtt->pd.page_tables[iter]; \ + iter < gen6_pde_index(ppgtt->base.total); \ + pt = ppgtt->pd.page_tables[++iter]) +static inline uint32_t i915_pte_index (uint64_t address,uint32_t pde_shift) {const uint32_t mask =NUM_PTE (pde_shift) -1 ;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 16/32 drm/i915: Extract PPGTT param from page_directory alloc
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
Now that we don't need to trace num_pd_pages, we may as well kill all need for the PPGTT structure in the alloc_page_directorys. This is very useful for when we move to 48b addressing, and the PDP isn't the root of the page table structure.
The param is replaced with drm_device, which is an unavoidable wart throughout the series. (in other words, not extra flagrant).
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +2 -4
@@ -689,8 +689,6 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_page_directory_pointer_ uint64_t start, uint64_t length) { -struct i915_hw_ppgtt *ppgtt = - container_of(pdp, struct i915_hw_ppgtt, pdp);struct i915_page_directory_entry *unused;uint64_t temp;uint32_t pdpe;
@@ -701,7 +699,7 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_page_directory_pointer_gen8_for_each_pdpe (unused, pdp, start, length, temp, pdpe) {BUG_ON (unused); pdp->page_directory[pdpe] =alloc_pd_single (); -if (IS_ERR (ppgtt->pdp.page_directory[pdpe])) +if (IS_ERR (pdp->page_directory[pdpe])) goto unwind_out; }
@@ -709,7 +707,7 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_page_directory_pointer_ unwind_out:while (pdpe--) -unmap_and_free_pd (ppgtt->pdp.page_directory[pdpe]); +unmap_and_free_pd (pdp->page_directory[pdpe]);return -ENOMEM ; }
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 17/32 drm/i915/bdw: Split out mappings
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
When we do dynamic page table allocations for gen8, we'll need to have more control over how and when we map page tables, similar to gen6. In particular, DMA mappings for page directories/tables occur at allocation time.
This patch adds the functionality and calls it at init, which should have no functional change.
The PDPEs are still a special case for now. We'll need a function for that in the future as well.
v2: Handle renamed unmap_and_free_page functions.
v3: Updated after teardown_va logic was removed.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 176 ++++++++++++++---------------------- 1 file changed, 69 insertions(+), 107 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +69 -107
@@ -416,17 +416,20 @@ err_out:return ret; } -static void unmap_and_free_pd (struct i915_page_directory_entry *pd) +static void unmap_and_free_pd (struct i915_page_directory_entry *pd, +struct drm_device *dev) {if (pd->page) { +i915_dma_unmap_single (pd, dev);__free_page (pd->page);kfree (pd); } } -static struct i915_page_directory_entry *alloc_pd_single (void ) +static struct i915_page_directory_entry *alloc_pd_single (struct drm_device *dev) {struct i915_page_directory_entry *pd; +int ret; pd =kzalloc (sizeof (*pd),GFP_KERNEL );if (!pd)
@@ -438,6 +441,13 @@ static struct i915_page_directory_entry *alloc_pd_single(void)return ERR_PTR (-ENOMEM ); } + ret =i915_dma_map_single (pd, dev); +if (ret) { +__free_page (pd->page); +kfree (pd); +return ERR_PTR (ret); + } +return pd; }
@@ -592,6 +602,36 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm, } } +static void __gen8_do_map_pt (gen8_ppgtt_pde_t *pde, +struct i915_page_table_entry *pt, +struct drm_device *dev) +{ +gen8_ppgtt_pde_t entry = +gen8_pde_encode (dev, pt->daddr,I915_CACHE_LLC ); + *pde = entry; +} + +/* It's likely we'll map more than one pagetable at a time. This function will +* save us unnecessary kmap calls, but do no more functionally than multiple +* calls to map_pt. */ +static void gen8_map_pagetable_range (struct i915_page_directory_entry *pd, +uint64_t start, +uint64_t length, +struct drm_device *dev) +{ +gen8_ppgtt_pde_t *page_directory =kmap_atomic (pd->page); +struct i915_page_table_entry *pt; +uint64_t temp, pde; + +gen8_for_each_pde (pt, pd, start, length, temp, pde) +__gen8_do_map_pt (page_directory + pde, pt, dev); + +if (!HAS_LLC (dev)) +drm_clflush_virt_range (page_directory,PAGE_SIZE ); + +kunmap_atomic (page_directory); +} +static void gen8_free_page_tables (struct i915_page_directory_entry *pd,struct drm_device *dev) {int i;
@@ -647,7 +687,7 @@ static void gen8_ppgtt_free(struct i915_hw_ppgtt *ppgtt)continue ;gen8_free_page_tables (ppgtt->pdp.page_directory[i], ppgtt->base.dev); -unmap_and_free_pd (ppgtt->pdp.page_directory[i]); +unmap_and_free_pd (ppgtt->pdp.page_directory[i], ppgtt->base.dev); } }
@@ -687,7 +727,8 @@ unwind_out:static int gen8_ppgtt_alloc_page_directories (struct i915_page_directory_pointer_entry *pdp,uint64_t start, -uint64_t length) +uint64_t length, +struct drm_device *dev) {struct i915_page_directory_entry *unused;uint64_t temp;
@@ -698,7 +739,7 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_page_directory_pointer_gen8_for_each_pdpe (unused, pdp, start, length, temp, pdpe) {BUG_ON (unused); - pdp->page_directory[pdpe] =alloc_pd_single (); + pdp->page_directory[pdpe] =alloc_pd_single (dev);if (IS_ERR (pdp->page_directory[pdpe])) goto unwind_out; }
@@ -707,21 +748,24 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_page_directory_pointer_ unwind_out:while (pdpe--) -unmap_and_free_pd (pdp->page_directory[pdpe]); +unmap_and_free_pd (pdp->page_directory[pdpe], dev);return -ENOMEM ; } -static int gen8_ppgtt_alloc (struct i915_hw_ppgtt *ppgtt, -uint64_t start, -uint64_t length) +static int gen8_alloc_va_range (struct i915_address_space *vm, +uint64_t start, +uint64_t length) { +struct i915_hw_ppgtt *ppgtt = + container_of(vm, struct i915_hw_ppgtt, base);struct i915_page_directory_entry *pd;uint64_t temp;uint32_t pdpe;int ret; - ret =gen8_ppgtt_alloc_page_directories (&ppgtt->pdp, start, length); + ret =gen8_ppgtt_alloc_page_directories (&ppgtt->pdp, start, length, + ppgtt->base.dev);if (ret)return ret;
@@ -739,128 +783,46 @@ err_out:return ret; } -static int gen8_ppgtt_setup_page_directories (struct i915_hw_ppgtt *ppgtt, -const int pd) -{ -dma_addr_t pd_addr; -int ret; - - pd_addr =pci_map_page (ppgtt->base.dev->pdev, - ppgtt->pdp.page_directory[pd]->page,0 , -PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL ); - - ret =pci_dma_mapping_error (ppgtt->base.dev->pdev, pd_addr); -if (ret) -return ret; - - ppgtt->pdp.page_directory[pd]->daddr = pd_addr; - -return 0 ; -} - -static int gen8_ppgtt_setup_page_tables (struct i915_hw_ppgtt *ppgtt, -const int pd, -const int pt) -{ -dma_addr_t pt_addr; -struct i915_page_directory_entry *pdir = ppgtt->pdp.page_directory[pd]; -struct i915_page_table_entry *ptab = pdir->page_tables[pt]; -struct page *p = ptab->page; -int ret; - - pt_addr =pci_map_page (ppgtt->base.dev->pdev, - p,0 ,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL ); - ret =pci_dma_mapping_error (ppgtt->base.dev->pdev, pt_addr); -if (ret) -return ret; - - ptab->daddr = pt_addr; - -return 0 ; -} -/** * GEN8 legacy ppgtt programming is accomplished through a max 4 PDP registers * with a net effect resembling a 2-level page table in normal x86 terms. Each * PDP represents 1GB of memory 4 * 512 * 512 * 4096 = 4GB legacy 32b address * space. * -* FIXME: split allocation into smaller pieces. For now we only ever do this -* once, but with full PPGTT, the multiple contiguous allocations will be bad. -* TODO: Do something with the size parameter */ static int gen8_ppgtt_init (struct i915_hw_ppgtt *ppgtt,uint64_t size) { -const int max_pdp =DIV_ROUND_UP (size,1 <<30 ); -int i, j, ret; - -if (size % (1 <<30 )) -DRM_INFO ("Pages will be wasted unless GTT size (%llu) is divisible by 1GB\n" , size); +struct i915_page_directory_entry *pd; +uint64_t temp, start =0 ; +const uint64_t orig_length = size; +uint32_t pdpe; +int ret; ppgtt->base.start =0 ; ppgtt->base.total = size; + ppgtt->base.clear_range = gen8_ppgtt_clear_range; + ppgtt->base.insert_entries = gen8_ppgtt_insert_entries; + ppgtt->base.cleanup = gen8_ppgtt_cleanup; + ppgtt->switch_mm = gen8_mm_switch; ppgtt->scratch_pd =alloc_pt_scratch (ppgtt->base.dev);if (IS_ERR (ppgtt->scratch_pd))return PTR_ERR (ppgtt->scratch_pd); -/* 1. Do all our allocations for page directories and page tables. */ - ret =gen8_ppgtt_alloc (ppgtt, ppgtt->base.start, ppgtt->base.total); + ret =gen8_alloc_va_range (&ppgtt->base, start, size);if (ret) {unmap_and_free_pt (ppgtt->scratch_pd, ppgtt->base.dev);return ret; } -/* -* 2. Create DMA mappings for the page directories and page tables. -*/ -for (i =0 ; i < max_pdp; i++) { - ret =gen8_ppgtt_setup_page_directories (ppgtt, i); -if (ret) - goto bail; + start =0 ; + size = orig_length; -for (j =0 ; j <GEN8_PDES_PER_PAGE ; j++) { - ret =gen8_ppgtt_setup_page_tables (ppgtt, i, j); -if (ret) - goto bail; - } - } - -/* -* 3. Map all the page directory entires to point to the page tables -* we've allocated. -* -* For now, the PPGTT helper functions all require that the PDEs are -* plugged in correctly. So we do that now/here. For aliasing PPGTT, we -* will never need to touch the PDEs again. -*/ -for (i =0 ; i < max_pdp; i++) { -struct i915_page_directory_entry *pd = ppgtt->pdp.page_directory[i]; -gen8_ppgtt_pde_t *pd_vaddr; - pd_vaddr =kmap_atomic (ppgtt->pdp.page_directory[i]->page); -for (j =0 ; j <GEN8_PDES_PER_PAGE ; j++) { -struct i915_page_table_entry *pt = pd->page_tables[j]; -dma_addr_t addr = pt->daddr; - pd_vaddr[j] =gen8_pde_encode (ppgtt->base.dev, addr, -I915_CACHE_LLC ); - } -if (!HAS_LLC (ppgtt->base.dev)) -drm_clflush_virt_range (pd_vaddr,PAGE_SIZE ); -kunmap_atomic (pd_vaddr); - } - - ppgtt->switch_mm = gen8_mm_switch; - ppgtt->base.clear_range = gen8_ppgtt_clear_range; - ppgtt->base.insert_entries = gen8_ppgtt_insert_entries; - ppgtt->base.cleanup = gen8_ppgtt_cleanup; +gen8_for_each_pdpe (pd, &ppgtt->pdp, start, size, temp, pdpe) +gen8_map_pagetable_range (pd, start, size, ppgtt->base.dev); ppgtt->base.clear_range (&ppgtt->base,0 , ppgtt->base.total, true);return 0 ; - -bail: -gen8_ppgtt_unmap_pages (ppgtt); -gen8_ppgtt_free (ppgtt); -return ret; }static void gen6_dump_ppgtt (struct i915_hw_ppgtt *ppgtt,struct seq_file *m)
@@ -1276,7 +1238,7 @@ static void gen6_ppgtt_free(struct i915_hw_ppgtt *ppgtt) }unmap_and_free_pt (ppgtt->scratch_pt, ppgtt->base.dev); -unmap_and_free_pd (&ppgtt->pd); +unmap_and_free_pd (&ppgtt->pd, ppgtt->base.dev); }static void gen6_ppgtt_cleanup (struct i915_address_space *vm)
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 18/32 drm/i915/bdw: begin bitmap tracking
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
Like with gen6/7, we can enable bitmap tracking with all the preallocations to make sure things actually don't blow up.
v2: Rebased to match changes from previous patches.
v3: Without teardown logic, rely on used_pdpes and used_pdes when freeing page tables.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 75 ++++++++++++++++++++++++++++--------- drivers/gpu/drm/i915/i915_gem_gtt.h | 24 ++++++++++++ 2 files changed, 81 insertions(+), 18 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +57 -18
@@ -422,6 +422,7 @@ static void unmap_and_free_pd(struct i915_page_directory_entry *pd,if (pd->page) {i915_dma_unmap_single (pd, dev);__free_page (pd->page); +kfree (pd->used_pdes);kfree (pd); } }
@@ -429,26 +430,35 @@ static void unmap_and_free_pd(struct i915_page_directory_entry *pd,static struct i915_page_directory_entry *alloc_pd_single (struct drm_device *dev) {struct i915_page_directory_entry *pd; -int ret; +int ret = -ENOMEM ; pd =kzalloc (sizeof (*pd),GFP_KERNEL );if (!pd)return ERR_PTR (-ENOMEM ); + pd->used_pdes =kcalloc (BITS_TO_LONGS (GEN8_PDES_PER_PAGE ), +sizeof (*pd->used_pdes),GFP_KERNEL ); +if (!pd->used_pdes) + goto free_pd; + pd->page =alloc_page (GFP_KERNEL | __GFP_ZERO); -if (!pd->page) { -kfree (pd); -return ERR_PTR (-ENOMEM ); - } +if (!pd->page) + goto free_bitmap; ret =i915_dma_map_single (pd, dev); -if (ret) { -__free_page (pd->page); -kfree (pd); -return ERR_PTR (ret); - } +if (ret) + goto free_page;return pd; + +free_page: +__free_page (pd->page); +free_bitmap: +kfree (pd->used_pdes); +free_pd: +kfree (pd); + +return ERR_PTR (ret); }/* Broadwell Page Directory Pointer Descriptors */
@@ -639,7 +649,7 @@ static void gen8_free_page_tables(struct i915_page_directory_entry *pd, struct dif (!pd->page)return ; -for (i =0 ; i <GEN8_PDES_PER_PAGE ; i++) { +for_each_set_bit (i, pd->used_pdes,GEN8_PDES_PER_PAGE ) {if (WARN_ON (!pd->page_tables[i]))continue ;
@@ -653,15 +663,18 @@ static void gen8_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt)struct pci_dev *hwdev = ppgtt->base.dev->pdev;int i, j; -for (i =0 ; i <GEN8_LEGACY_PDPES ; i++) { -if (!ppgtt->pdp.page_directory[i]->daddr) +for_each_set_bit (i, ppgtt->pdp.used_pdpes,GEN8_LEGACY_PDPES ) { +struct i915_page_directory_entry *pd; + +if (WARN_ON (!ppgtt->pdp.page_directory[i]))continue ; -pci_unmap_page (hwdev, ppgtt->pdp.page_directory[i]->daddr,PAGE_SIZE , -PCI_DMA_BIDIRECTIONAL ); + pd = ppgtt->pdp.page_directory[i]; +if (!pd->daddr) +pci_unmap_page (hwdev, pd->daddr,PAGE_SIZE , +PCI_DMA_BIDIRECTIONAL ); -for (j =0 ; j <GEN8_PDES_PER_PAGE ; j++) { -struct i915_page_directory_entry *pd = ppgtt->pdp.page_directory[i]; +for_each_set_bit (j, pd->used_pdes,GEN8_PDES_PER_PAGE ) {struct i915_page_table_entry *pt;dma_addr_t addr;
@@ -682,7 +695,7 @@ static void gen8_ppgtt_free(struct i915_hw_ppgtt *ppgtt) {int i; -for (i =0 ; i <GEN8_LEGACY_PDPES ; i++) { +for_each_set_bit (i, ppgtt->pdp.used_pdpes,GEN8_LEGACY_PDPES ) {if (WARN_ON (!ppgtt->pdp.page_directory[i]))continue ;
@@ -725,6 +738,7 @@ unwind_out:return -ENOMEM ; } +/* bitmap of new page_directories */ static int gen8_ppgtt_alloc_page_directories(struct i915_page_directory_pointer_entry *pdp, uint64_t start, uint64_t length,
@@ -740,6 +754,7 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_page_directory_pointer_gen8_for_each_pdpe (unused, pdp, start, length, temp, pdpe) {BUG_ON (unused); pdp->page_directory[pdpe] =alloc_pd_single (dev); +if (IS_ERR (pdp->page_directory[pdpe])) goto unwind_out; }
@@ -760,10 +775,13 @@ static int gen8_alloc_va_range(struct i915_address_space *vm,struct i915_hw_ppgtt *ppgtt = container_of(vm, struct i915_hw_ppgtt, base);struct i915_page_directory_entry *pd; +const uint64_t orig_start = start; +const uint64_t orig_length = length;uint64_t temp;uint32_t pdpe;int ret; +/* Do the allocations first so we can easily bail out */ ret =gen8_ppgtt_alloc_page_directories (&ppgtt->pdp, start, length, ppgtt->base.dev);if (ret)
@@ -776,6 +794,27 @@ static int gen8_alloc_va_range(struct i915_address_space *vm, goto err_out; } +/* Now mark everything we've touched as used. This doesn't allow for +* robust error checking, but it makes the code a hell of a lot simpler. +*/ + start = orig_start; + length = orig_length; + +gen8_for_each_pdpe (pd, &ppgtt->pdp, start, length, temp, pdpe) { +struct i915_page_table_entry *pt; +uint64_t pd_len =gen8_clamp_pd (start, length); +uint64_t pd_start = start; +uint32_t pde; + +gen8_for_each_pde (pt, &ppgtt->pd, pd_start, pd_len, temp, pde) { +bitmap_set (pd->page_tables[pde]->used_ptes, +gen8_pte_index (start), +gen8_pte_count (start, length)); +set_bit (pde, pd->used_pdes); + } +set_bit (pdpe, ppgtt->pdp.used_pdpes); + } +return 0 ; err_out:
drivers/gpu/drm/i915/i915_gem_gtt.h +24 -0
@@ -205,11 +205,13 @@ struct i915_page_directory_entry {dma_addr_t daddr; }; +unsigned long *used_pdes;struct i915_page_table_entry *page_tables[GEN6_PPGTT_PD_ENTRIES ];/* PDEs */ };struct i915_page_directory_pointer_entry {/* struct page *page; */ + DECLARE_BITMAP(used_pdpes, GEN8_LEGACY_PDPES);struct i915_page_directory_entry *page_directory[GEN8_LEGACY_PDPES ]; };
@@ -436,6 +438,28 @@ static inline uint32_t gen8_pml4e_index(uint64_t address)BUG ();/* For 64B */ } +static inline size_t gen8_pte_count (uint64_t addr,uint64_t length) +{ +return i915_pte_count (addr, length,GEN8_PDE_SHIFT ); +} + +static inline size_t gen8_pde_count (uint64_t addr,uint64_t length) +{ +const uint32_t pdp_shift =GEN8_PDE_SHIFT +9 ; +const uint64_t mask = ~((1 << pdp_shift) -1 ); +uint64_t end; + +BUG_ON (length ==0 ); +BUG_ON (offset_in_page (addr|length)); + + end = addr + length; + +if ((addr & mask) != (end & mask)) +return GEN8_PDES_PER_PAGE -i915_pde_index (addr,GEN8_PDE_SHIFT ); + +return i915_pde_index (end,GEN8_PDE_SHIFT ) -i915_pde_index (addr,GEN8_PDE_SHIFT ); +} +int i915_gem_gtt_init (struct drm_device *dev);void i915_gem_init_global_gtt (struct drm_device *dev);void i915_global_gtt_cleanup (struct drm_device *dev);
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 19/32 drm/i915/bdw: Dynamic page table allocations
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
This finishes off the dynamic page tables allocations, in the legacy 3 level style that already exists. Most everything has already been setup to this point, the patch finishes off the enabling by setting the appropriate function pointers.
v2: Update aliasing/true ppgtt allocate/teardown/clear functions for gen 6 & 7.
v3: Rebase.
v4: Remove BUG() from ppgtt_unbind_vma, but keep checking that either teardown_va_range or clear_range functions exist (Daniel).
v5: Similar to gen6, in init, gen8_ppgtt_clear_range call is only needed for aliasing ppgtt. Zombie tracking was originally added for teardown function and is no longer required.
v6: Update err_out case in gen8_alloc_va_range (missed from lastest rebase).
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 300 +++++++++++++++++++++++++++++------- 1 file changed, 246 insertions(+), 54 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +246 -54
@@ -612,7 +612,7 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm, } } -static void __gen8_do_map_pt (gen8_ppgtt_pde_t *pde, +static void __gen8_do_map_pt (gen8_ppgtt_pde_t *const pde,struct i915_page_table_entry *pt,struct drm_device *dev) {
@@ -629,7 +629,7 @@ static void gen8_map_pagetable_range(struct i915_page_directory_entry *pd,uint64_t length, struct drm_device *dev) { - gen8_ppgtt_pde_t *page_directory = kmap_atomic(pd->page); + gen8_ppgtt_pde_t * const page_directory = kmap_atomic(pd->page);struct i915_page_table_entry *pt;uint64_t temp, pde;
@@ -713,58 +713,163 @@ static void gen8_ppgtt_cleanup(struct i915_address_space *vm)gen8_ppgtt_free (ppgtt); } -static int gen8_ppgtt_alloc_pagetabs (struct i915_page_directory_entry *pd, +/** +* gen8_ppgtt_alloc_pagetabs() - Allocate page tables for VA range. +* @ppgtt: Master ppgtt structure. +* @pd: Page directory for this address range. +* @start: Starting virtual address to begin allocations. +* @length Size of the allocations. +* @new_pts: Bitmap set by function with new allocations. Likely used by the +* caller to free on error. +* +* Allocate the required number of page tables. Extremely similar to +* gen8_ppgtt_alloc_page_directories(). The main difference is here we are limited by +* the page directory boundary (instead of the page directory pointer). That +* boundary is 1GB virtual. Therefore, unlike gen8_ppgtt_alloc_page_directories(), it is +* possible, and likely that the caller will need to use multiple calls of this +* function to achieve the appropriate allocation. +* +* Return: 0 if success; negative error code otherwise. +*/ +static int gen8_ppgtt_alloc_pagetabs (struct i915_hw_ppgtt *ppgtt, +struct i915_page_directory_entry *pd,uint64_t start,uint64_t length, -struct drm_device *dev) +unsigned long *new_pts) { -struct i915_page_table_entry *unused; +struct i915_page_table_entry *pt;uint64_t temp;uint32_t pde; -gen8_for_each_pde (unused, pd, start, length, temp, pde) { -BUG_ON (unused); - pd->page_tables[pde] =alloc_pt_single (dev); -if (IS_ERR (pd->page_tables[pde])) +gen8_for_each_pde (pt, pd, start, length, temp, pde) { +/* Don't reallocate page tables */ +if (pt) { +/* Scratch is never allocated this way */ +WARN_ON (pt->scratch); +continue ; + } + + pt =alloc_pt_single (ppgtt->base.dev); +if (IS_ERR (pt)) goto unwind_out; + + pd->page_tables[pde] = pt; +set_bit (pde, new_pts); }return 0 ; unwind_out: -while (pde--) -unmap_and_free_pt (pd->page_tables[pde], dev); +for_each_set_bit (pde, new_pts,GEN8_PDES_PER_PAGE ) +unmap_and_free_pt (pd->page_tables[pde], ppgtt->base.dev);return -ENOMEM ; } -/* bitmap of new page_directories */ -static int gen8_ppgtt_alloc_page_directories (struct i915_page_directory_pointer_entry *pdp, +/** +* gen8_ppgtt_alloc_page_directories() - Allocate page directories for VA range. +* @ppgtt: Master ppgtt structure. +* @pdp: Page directory pointer for this address range. +* @start: Starting virtual address to begin allocations. +* @length Size of the allocations. +* @new_pds Bitmap set by function with new allocations. Likely used by the +* caller to free on error. +* +* Allocate the required number of page directories starting at the pde index of +* @start, and ending at the pde index @start + @length. This function will skip +* over already allocated page directories within the range, and only allocate +* new ones, setting the appropriate pointer within the pdp as well as the +* correct position in the bitmap @new_pds. +* +* The function will only allocate the pages within the range for a give page +* directory pointer. In other words, if @start + @length straddles a virtually +* addressed PDP boundary (512GB for 4k pages), there will be more allocations +* required by the caller, This is not currently possible, and the BUG in the +* code will prevent it. +* +* Return: 0 if success; negative error code otherwise. +*/ +static int gen8_ppgtt_alloc_page_directories (struct i915_hw_ppgtt *ppgtt, +struct i915_page_directory_pointer_entry *pdp,uint64_t start,uint64_t length, -struct drm_device *dev) +unsigned long *new_pds) { -struct i915_page_directory_entry *unused; +struct i915_page_directory_entry *pd;uint64_t temp;uint32_t pdpe; +BUG_ON (!bitmap_empty (new_pds,GEN8_LEGACY_PDPES )); +/* FIXME: PPGTT container_of won't work for 64b */ BUG_ON ((start + length) >0x800000000ULL ); -gen8_for_each_pdpe (unused, pdp, start, length, temp, pdpe) { -BUG_ON (unused); - pdp->page_directory[pdpe] =alloc_pd_single (dev); +gen8_for_each_pdpe (pd, pdp, start, length, temp, pdpe) { +if (pd) +continue ; -if (IS_ERR (pdp->page_directory[pdpe])) + pd =alloc_pd_single (ppgtt->base.dev); +if (IS_ERR (pd)) goto unwind_out; + + pdp->page_directory[pdpe] = pd; +set_bit (pdpe, new_pds); }return 0 ; unwind_out: -while (pdpe--) -unmap_and_free_pd (pdp->page_directory[pdpe], dev); +for_each_set_bit (pdpe, new_pds,GEN8_LEGACY_PDPES ) +unmap_and_free_pd (pdp->page_directory[pdpe], ppgtt->base.dev); + +return -ENOMEM ; +} + +static inline void +free_gen8_temp_bitmaps (unsigned long *new_pds,unsigned long **new_pts) +{ +int i; + +for (i =0 ; i <GEN8_LEGACY_PDPES ; i++) +kfree (new_pts[i]); +kfree (new_pts); +kfree (new_pds); +} + +/* Fills in the page directory bitmap, ant the array of page tables bitmap. Both +* of these are based on the number of PDPEs in the system. +*/ +int __must_check alloc_gen8_temp_bitmaps (unsigned long **new_pds, +unsigned long ***new_pts) +{ +int i; +unsigned long *pds; +unsigned long **pts; + + pds =kcalloc (BITS_TO_LONGS (GEN8_LEGACY_PDPES ),sizeof (unsigned long ),GFP_KERNEL ); +if (!pds) +return -ENOMEM ; + + pts =kcalloc (GEN8_PDES_PER_PAGE ,sizeof (unsigned long *),GFP_KERNEL ); +if (!pts) { +kfree (pds); +return -ENOMEM ; + } + +for (i =0 ; i <GEN8_LEGACY_PDPES ; i++) { + pts[i] =kcalloc (BITS_TO_LONGS (GEN8_PDES_PER_PAGE ), +sizeof (unsigned long ),GFP_KERNEL ); +if (!pts[i]) + goto err_out; + } + + *new_pds = pds; + *new_pts = (unsigned long **)pts; +return 0 ; + +err_out: +free_gen8_temp_bitmaps (pds, pts);return -ENOMEM ; }
@@ -774,6 +879,7 @@ static int gen8_alloc_va_range(struct i915_address_space *vm, {struct i915_hw_ppgtt *ppgtt = container_of(vm, struct i915_hw_ppgtt, base); +unsigned long *new_page_dirs, **new_page_tables;struct i915_page_directory_entry *pd;const uint64_t orig_start = start;const uint64_t orig_length = length;
@@ -781,44 +887,99 @@ static int gen8_alloc_va_range(struct i915_address_space *vm,uint32_t pdpe;int ret; -/* Do the allocations first so we can easily bail out */ - ret =gen8_ppgtt_alloc_page_directories (&ppgtt->pdp, start, length, - ppgtt->base.dev); +#ifndef CONFIG_64BIT +/* Disallow 64b address on 32b platforms. Nothing is wrong with doing +* this in hardware, but a lot of the drm code is not prepared to handle +* 64b offset on 32b platforms. +* This will be addressed when 48b PPGTT is added */ +if (start + length >0x100000000ULL ) +return -E2BIG ; +#endif + +/* Wrap is never okay since we can only represent 48b, and we don't +* actually use the other side of the canonical address space. +*/ +if (WARN_ON (start + length < start)) +return -ERANGE ; + + ret =alloc_gen8_temp_bitmaps (&new_page_dirs, &new_page_tables);if (ret)return ret; +/* Do the allocations first so we can easily bail out */ + ret =gen8_ppgtt_alloc_page_directories (ppgtt, &ppgtt->pdp, start, length, + new_page_dirs); +if (ret) { +free_gen8_temp_bitmaps (new_page_dirs, new_page_tables); +return ret; + } + +/* For every page directory referenced, allocate page tables */ gen8_for_each_pdpe (pd, &ppgtt->pdp, start, length, temp, pdpe) { - ret =gen8_ppgtt_alloc_pagetabs (pd, start, length, - ppgtt->base.dev); +bitmap_zero (new_page_tables[pdpe],GEN8_PDES_PER_PAGE ); + ret =gen8_ppgtt_alloc_pagetabs (ppgtt, pd, start, length, + new_page_tables[pdpe]);if (ret) goto err_out; } -/* Now mark everything we've touched as used. This doesn't allow for -* robust error checking, but it makes the code a hell of a lot simpler. -*/ start = orig_start; length = orig_length; +/* Allocations have completed successfully, so set the bitmaps, and do +* the mappings. */ gen8_for_each_pdpe (pd, &ppgtt->pdp, start, length, temp, pdpe) { +gen8_ppgtt_pde_t *const page_directory =kmap_atomic (pd->page);struct i915_page_table_entry *pt;uint64_t pd_len =gen8_clamp_pd (start, length);uint64_t pd_start = start;uint32_t pde; -gen8_for_each_pde (pt, &ppgtt->pd, pd_start, pd_len, temp, pde) { -bitmap_set (pd->page_tables[pde]->used_ptes, -gen8_pte_index (start), -gen8_pte_count (start, length)); +/* Every pd should be allocated, we just did that above. */ +BUG_ON (!pd); + +gen8_for_each_pde (pt, pd, pd_start, pd_len, temp, pde) { +/* Same reasoning as pd */ +BUG_ON (!pt); +BUG_ON (!pd_len); +BUG_ON (!gen8_pte_count (pd_start, pd_len)); + +/* Set our used ptes within the page table */ +bitmap_set (pt->used_ptes, +gen8_pte_index (pd_start), +gen8_pte_count (pd_start, pd_len)); + +/* Our pde is now pointing to the pagetable, pt */ set_bit (pde, pd->used_pdes); + +/* Map the PDE to the page table */ +__gen8_do_map_pt (page_directory + pde, pt, vm->dev); + +/* NB: We haven't yet mapped ptes to pages. At this +* point we're still relying on insert_entries() */ } + +if (!HAS_LLC (vm->dev)) +drm_clflush_virt_range (page_directory,PAGE_SIZE ); + +kunmap_atomic (page_directory); +set_bit (pdpe, ppgtt->pdp.used_pdpes); } +free_gen8_temp_bitmaps (new_page_dirs, new_page_tables);return 0 ; err_out: -gen8_ppgtt_free (ppgtt); +while (pdpe--) { +for_each_set_bit (temp, new_page_tables[pdpe],GEN8_PDES_PER_PAGE ) +unmap_and_free_pt (pd->page_tables[temp], vm->dev); + } + +for_each_set_bit (pdpe, new_page_dirs,GEN8_LEGACY_PDPES ) +unmap_and_free_pd (ppgtt->pdp.page_directory[pdpe], vm->dev); + +free_gen8_temp_bitmaps (new_page_dirs, new_page_tables);return ret; }
@@ -829,38 +990,67 @@ err_out:* space. * */ -static int gen8_ppgtt_init (struct i915_hw_ppgtt *ppgtt,uint64_t size) +static int gen8_ppgtt_init_common (struct i915_hw_ppgtt *ppgtt,uint64_t size) { -struct i915_page_directory_entry *pd; -uint64_t temp, start =0 ; -const uint64_t orig_length = size; -uint32_t pdpe; -int ret; + ppgtt->scratch_pd =alloc_pt_scratch (ppgtt->base.dev); +if (IS_ERR (ppgtt->scratch_pd)) +return PTR_ERR (ppgtt->scratch_pd); ppgtt->base.start =0 ; ppgtt->base.total = size; - ppgtt->base.clear_range = gen8_ppgtt_clear_range; - ppgtt->base.insert_entries = gen8_ppgtt_insert_entries; ppgtt->base.cleanup = gen8_ppgtt_cleanup; + ppgtt->base.insert_entries = gen8_ppgtt_insert_entries; + ppgtt->switch_mm = gen8_mm_switch; - ppgtt->scratch_pd =alloc_pt_scratch (ppgtt->base.dev); -if (IS_ERR (ppgtt->scratch_pd)) -return PTR_ERR (ppgtt->scratch_pd); +return 0 ; +} + +static int gen8_aliasing_ppgtt_init (struct i915_hw_ppgtt *ppgtt) +{ +struct drm_device *dev = ppgtt->base.dev; +struct drm_i915_private *dev_priv = dev->dev_private; +struct i915_page_directory_entry *pd; +uint64_t temp, start =0 , size = dev_priv->gtt.base.total; +uint32_t pdpe; +int ret; + + ret =gen8_ppgtt_init_common (ppgtt, dev_priv->gtt.base.total); +if (ret) +return ret; +/* Aliasing PPGTT has to always work and be mapped because of the way we +* use RESTORE_INHIBIT in the context switch. This will be fixed +* eventually. */ ret =gen8_alloc_va_range (&ppgtt->base, start, size);if (ret) {unmap_and_free_pt (ppgtt->scratch_pd, ppgtt->base.dev);return ret; } - start =0 ; - size = orig_length; -gen8_for_each_pdpe (pd, &ppgtt->pdp, start, size, temp, pdpe)gen8_map_pagetable_range (pd, start, size, ppgtt->base.dev); + ppgtt->base.allocate_va_range =NULL ; + ppgtt->base.clear_range = gen8_ppgtt_clear_range; ppgtt->base.clear_range (&ppgtt->base,0 , ppgtt->base.total, true); + +return 0 ; +} + +static int gen8_ppgtt_init (struct i915_hw_ppgtt *ppgtt) +{ +struct drm_device *dev = ppgtt->base.dev; +struct drm_i915_private *dev_priv = dev->dev_private; +int ret; + + ret =gen8_ppgtt_init_common (ppgtt, dev_priv->gtt.base.total); +if (ret) +return ret; + + ppgtt->base.allocate_va_range = gen8_alloc_va_range; + ppgtt->base.clear_range = gen8_ppgtt_clear_range; +return 0 ; }
@@ -1395,7 +1585,7 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt, bool aliasing) } } - ppgtt->base.allocate_va_range = gen6_alloc_va_range; + ppgtt->base.allocate_va_range = aliasing ?NULL : gen6_alloc_va_range; ppgtt->base.clear_range = gen6_ppgtt_clear_range; ppgtt->base.insert_entries = gen6_ppgtt_insert_entries; ppgtt->base.cleanup = gen6_ppgtt_cleanup;
@@ -1436,8 +1626,10 @@ static int __hw_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt,if (INTEL_INFO (dev)->gen <8 )return gen6_ppgtt_init (ppgtt, aliasing); +else if (aliasing) +return gen8_aliasing_ppgtt_init (ppgtt);else -return gen8_ppgtt_init (ppgtt, dev_priv->gtt.base.total); +return gen8_ppgtt_init (ppgtt); }int i915_ppgtt_init (struct drm_device *dev,struct i915_hw_ppgtt *ppgtt) {
@@ -1546,10 +1738,10 @@ ppgtt_bind_vma(struct i915_vma *vma,static void ppgtt_unbind_vma (struct i915_vma *vma) { - vma->vm->clear_range (vma->vm, - vma->node.start, - vma->obj->base.size, - true); + vma->vm->clear_range (vma->vm, + vma->node.start, + vma->obj->base.size, + true); }extern int intel_iommu_gfx_mapped;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 20/32 drm/i915/bdw: Support dynamic pdp updates in lrc mode
In reply to Michel ThierryLogic ring contexts need to know the PDPs when they are populated. With dynamic page table allocations, these PDPs may not exist yet.
Check if PDPs have been allocated and use the scratch page if they do not exist yet.
Before submission, update the PDPs in the logic ring context as PDPs have been allocated.
v2: Renamed commit title (Daniel)
--- drivers/gpu/drm/i915/intel_lrc.c | 80 +++++++++++++++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/intel_lrc.c +70 -10
@@ -320,6 +320,7 @@ static void execlists_elsp_write(struct intel_engine_cs *ring,static int execlists_update_context (struct drm_i915_gem_object *ctx_obj,struct drm_i915_gem_object *ring_obj, +struct i915_hw_ppgtt *ppgtt,u32 tail) {struct page *page;
@@ -331,6 +332,40 @@ static int execlists_update_context(struct drm_i915_gem_object *ctx_obj, reg_state[CTX_RING_TAIL +1 ] = tail; reg_state[CTX_RING_BUFFER_START +1 ] =i915_gem_obj_ggtt_offset (ring_obj); +/* True PPGTT with dynamic page allocation: update PDP registers and +* point the unallocated PDPs to the scratch page +*/ +if (ppgtt) { +if (test_bit (3 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + }else { + reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (test_bit (2 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + }else { + reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (test_bit (1 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + }else { + reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (test_bit (0 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + }else { + reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + } + } +kunmap_atomic (reg_state);return 0 ;
@@ -349,7 +384,7 @@ static void execlists_submit_contexts(struct intel_engine_cs *ring,WARN_ON (!i915_gem_obj_is_pinned (ctx_obj0));WARN_ON (!i915_gem_obj_is_pinned (ringbuf0->obj)); -execlists_update_context (ctx_obj0, ringbuf0->obj, tail0); +execlists_update_context (ctx_obj0, ringbuf0->obj, to0->ppgtt, tail0);if (to1) { ringbuf1 = to1->engine[ring->id].ringbuf;
@@ -358,7 +393,7 @@ static void execlists_submit_contexts(struct intel_engine_cs *ring,WARN_ON (!i915_gem_obj_is_pinned (ctx_obj1));WARN_ON (!i915_gem_obj_is_pinned (ringbuf1->obj)); -execlists_update_context (ctx_obj1, ringbuf1->obj, tail1); +execlists_update_context (ctx_obj1, ringbuf1->obj, to1->ppgtt, tail1); }execlists_elsp_write (ring, ctx_obj0, ctx_obj1);
@@ -1735,14 +1770,39 @@ populate_lr_context(struct intel_context *ctx, struct drm_i915_gem_object *ctx_o reg_state[CTX_PDP1_LDW ] =GEN8_RING_PDP_LDW (ring,1 ); reg_state[CTX_PDP0_UDW ] =GEN8_RING_PDP_UDW (ring,0 ); reg_state[CTX_PDP0_LDW ] =GEN8_RING_PDP_LDW (ring,0 ); - reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); - reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); - reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); - reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); - reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); - reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); - reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); - reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + +/* With dynamic page allocation, PDPs may not be allocated at this point, +* Point the unallocated PDPs to the scratch page +*/ +if (test_bit (3 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + }else { + reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (test_bit (2 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + }else { + reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (test_bit (1 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + }else { + reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (test_bit (0 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + }else { + reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (ring->id ==RCS ) { reg_state[CTX_LRI_HEADER_2 ] =MI_LOAD_REGISTER_IMM (1 ); reg_state[CTX_R_PWR_CLK_STATE ] =0x20c8 ;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 21/32 drm/i915/bdw: Make pdp allocation more dynamic
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
This transitional patch doesn't do much for the existing code. However, it should make upcoming patches to use the full 48b address space a bit easier to swallow. The patch also introduces the PML4, ie. the new top level structure of the page tables.
v2: Renamed pdp_free to be similar to pd/pt (unmap_and_free_pdp), To facilitate testing, 48b mode will be available on Broadwell, when i915.enable_ppgtt = 3.
--- drivers/gpu/drm/i915/i915_drv.h | 7 ++- drivers/gpu/drm/i915/i915_gem_gtt.c | 108 +++++++++++++++++++++++++++++------- drivers/gpu/drm/i915/i915_gem_gtt.h | 41 +++++++++++--- 3 files changed, 126 insertions(+), 30 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +6 -1
@@ -2433,7 +2433,12 @@ struct drm_i915_cmd_table {#define HAS_HW_CONTEXTS (dev) (INTEL_INFO(dev)->gen >= 6)#define HAS_LOGICAL_RING_CONTEXTS (dev) (INTEL_INFO(dev)->gen >= 8)#define USES_PPGTT (dev) (i915.enable_ppgtt) -#define USES_FULL_PPGTT (dev) (i915.enable_ppgtt == 2) +#define USES_FULL_PPGTT (dev) (i915.enable_ppgtt >= 2) +#ifdef CONFIG_64BIT +# define USES_FULL_48BIT_PPGTT (dev) (i915.enable_ppgtt == 3) +#else +# define USES_FULL_48BIT_PPGTT (dev) false +#endif #define HAS_OVERLAY (dev) (INTEL_INFO(dev)->has_overlay)#define OVERLAY_NEEDS_PHYSICAL (dev) (INTEL_INFO(dev)->overlay_needs_physical)
drivers/gpu/drm/i915/i915_gem_gtt.c +88 -20
252 lines not on this page · raw message
drivers/gpu/drm/i915/i915_gem_gtt.h +32 -9
77 lines not on this page · raw message
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 22/32 drm/i915/bdw: Abstract PDP usage
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
Up until now, ppgtt->pdp has always been the root of our page tables. Legacy 32b addresses acted like it had 1 PDP with 4 PDPEs.
In preparation for 4 level page tables, we need to stop use ppgtt->pdp directly unless we know it's what we want. The future structure will use ppgtt->pml4 for the top level, and the pdp is just one of the entries being pointed to by a pml4e.
This patch addresses some carelessness done throughout development wrt assumptions made of the root page tables.
v2: Updated after dynamic page allocation changes.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 123 ++++++++++++++++++++---------------- 1 file changed, 70 insertions(+), 53 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +70 -53
@@ -559,6 +559,7 @@ static void gen8_ppgtt_clear_range(struct i915_address_space *vm, {struct i915_hw_ppgtt *ppgtt = container_of(vm, struct i915_hw_ppgtt, base); +struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ gen8_gtt_pte_t *pt_vaddr, scratch_pte;unsigned pdpe = start >>GEN8_PDPE_SHIFT &GEN8_PDPE_MASK ;unsigned pde = start >>GEN8_PDE_SHIFT &GEN8_PDE_MASK ;
@@ -574,10 +575,10 @@ static void gen8_ppgtt_clear_range(struct i915_address_space *vm,struct i915_page_table_entry *pt;struct page *page_table; -if (WARN_ON (!ppgtt->pdp.page_directory[pdpe])) +if (WARN_ON (!pdp->page_directory[pdpe]))continue ; - pd = ppgtt->pdp.page_directory[pdpe]; + pd = pdp->page_directory[pdpe];if (WARN_ON (!pd->page_tables[pde]))continue ;
@@ -619,6 +620,7 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm, {struct i915_hw_ppgtt *ppgtt = container_of(vm, struct i915_hw_ppgtt, base); +struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ gen8_gtt_pte_t *pt_vaddr;unsigned pdpe = start >>GEN8_PDPE_SHIFT &GEN8_PDPE_MASK ;unsigned pde = start >>GEN8_PDE_SHIFT &GEN8_PDE_MASK ;
@@ -629,7 +631,7 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm,for_each_sg_page (pages->sgl, &sg_iter, pages->nents,0 ) {if (pt_vaddr ==NULL ) { -struct i915_page_directory_entry *pd = ppgtt->pdp.page_directory[pdpe]; +struct i915_page_directory_entry *pd = pdp->page_directory[pdpe];struct i915_page_table_entry *pt = pd->page_tables[pde];struct page *page_table = pt->page;
@@ -707,16 +709,17 @@ static void gen8_free_page_tables(struct i915_page_directory_entry *pd, struct dstatic void gen8_ppgtt_unmap_pages (struct i915_hw_ppgtt *ppgtt) {struct pci_dev *hwdev = ppgtt->base.dev->pdev; +struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ int i, j; -for_each_set_bit (i, ppgtt->pdp.used_pdpes, +for_each_set_bit (i, pdp->used_pdpes,I915_PDPES_PER_PDP (ppgtt->base.dev)) {struct i915_page_directory_entry *pd; -if (WARN_ON (!ppgtt->pdp.page_directory[i])) +if (WARN_ON (!pdp->page_directory[i]))continue ; - pd = ppgtt->pdp.page_directory[i]; + pd = pdp->page_directory[i];if (!pd->daddr)pci_unmap_page (hwdev, pd->daddr,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL );
@@ -742,15 +745,21 @@ static void gen8_ppgtt_free(struct i915_hw_ppgtt *ppgtt) {int i; -for_each_set_bit (i, ppgtt->pdp.used_pdpes, -I915_PDPES_PER_PDP (ppgtt->base.dev)) { -if (WARN_ON (!ppgtt->pdp.page_directory[i])) -continue ; +if (!USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) { +for_each_set_bit (i, ppgtt->pdp.used_pdpes, +I915_PDPES_PER_PDP (ppgtt->base.dev)) { +if (WARN_ON (!ppgtt->pdp.page_directory[i])) +continue ; -gen8_free_page_tables (ppgtt->pdp.page_directory[i], ppgtt->base.dev); -unmap_and_free_pd (ppgtt->pdp.page_directory[i], ppgtt->base.dev); +gen8_free_page_tables (ppgtt->pdp.page_directory[i], + ppgtt->base.dev); +unmap_and_free_pd (ppgtt->pdp.page_directory[i], + ppgtt->base.dev); + } +unmap_and_free_pdp (&ppgtt->pdp, ppgtt->base.dev); + }else { +BUG ();/* to be implemented later */ } -unmap_and_free_pdp (&ppgtt->pdp, ppgtt->base.dev); }static void gen8_ppgtt_cleanup (struct i915_address_space *vm)
@@ -764,7 +773,7 @@ static void gen8_ppgtt_cleanup(struct i915_address_space *vm)/** * gen8_ppgtt_alloc_pagetabs() - Allocate page tables for VA range. -* @ppgtt: Master ppgtt structure. +* @vm: Master vm structure. * @pd: Page directory for this address range. * @start: Starting virtual address to begin allocations. * @length Size of the allocations.
@@ -780,12 +789,13 @@ static void gen8_ppgtt_cleanup(struct i915_address_space *vm)* * Return: 0 if success; negative error code otherwise. */ -static int gen8_ppgtt_alloc_pagetabs (struct i915_hw_ppgtt *ppgtt, +static int gen8_ppgtt_alloc_pagetabs (struct i915_address_space *vm,struct i915_page_directory_entry *pd,uint64_t start,uint64_t length,unsigned long *new_pts) { +struct drm_device *dev = vm->dev;struct i915_page_table_entry *pt;uint64_t temp;uint32_t pde;
@@ -798,7 +808,7 @@ static int gen8_ppgtt_alloc_pagetabs(struct i915_hw_ppgtt *ppgtt,continue ; } - pt =alloc_pt_single (ppgtt->base.dev); + pt =alloc_pt_single (dev);if (IS_ERR (pt)) goto unwind_out;
@@ -810,14 +820,14 @@ static int gen8_ppgtt_alloc_pagetabs(struct i915_hw_ppgtt *ppgtt, unwind_out:for_each_set_bit (pde, new_pts,GEN8_PDES_PER_PAGE ) -unmap_and_free_pt (pd->page_tables[pde], ppgtt->base.dev); +unmap_and_free_pt (pd->page_tables[pde], dev);return -ENOMEM ; }/** * gen8_ppgtt_alloc_page_directories() - Allocate page directories for VA range. -* @ppgtt: Master ppgtt structure. +* @vm: Master vm structure. * @pdp: Page directory pointer for this address range. * @start: Starting virtual address to begin allocations. * @length Size of the allocations.
@@ -838,16 +848,17 @@ unwind_out:* * Return: 0 if success; negative error code otherwise. */ -static int gen8_ppgtt_alloc_page_directories (struct i915_hw_ppgtt *ppgtt, +static int gen8_ppgtt_alloc_page_directories (struct i915_address_space *vm,struct i915_page_directory_pointer_entry *pdp,uint64_t start,uint64_t length,unsigned long *new_pds) { +struct drm_device *dev = vm->dev;struct i915_page_directory_entry *pd;uint64_t temp;uint32_t pdpe; -size_t pdpes =I915_PDPES_PER_PDP (ppgtt->base.dev); +size_t pdpes =I915_PDPES_PER_PDP (vm->dev);BUG_ON (!bitmap_empty (new_pds, pdpes));
@@ -858,7 +869,7 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_hw_ppgtt *ppgtt,if (pd)continue ; - pd =alloc_pd_single (ppgtt->base.dev); + pd =alloc_pd_single (dev);if (IS_ERR (pd)) goto unwind_out;
@@ -870,7 +881,7 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_hw_ppgtt *ppgtt, unwind_out:for_each_set_bit (pdpe, new_pds, pdpes) -unmap_and_free_pd (pdp->page_directory[pdpe], ppgtt->base.dev); +unmap_and_free_pd (pdp->page_directory[pdpe], dev);return -ENOMEM ; }
@@ -925,13 +936,13 @@ err_out:return -ENOMEM ; } -static int gen8_alloc_va_range (struct i915_address_space *vm, -uint64_t start, -uint64_t length) +static int gen8_alloc_va_range_3lvl (struct i915_address_space *vm, +struct i915_page_directory_pointer_entry *pdp, +uint64_t start, +uint64_t length) { -struct i915_hw_ppgtt *ppgtt = - container_of(vm, struct i915_hw_ppgtt, base);unsigned long *new_page_dirs, **new_page_tables; +struct drm_device *dev = vm->dev;struct i915_page_directory_entry *pd;const uint64_t orig_start = start;const uint64_t orig_length = length;
@@ -960,17 +971,15 @@ static int gen8_alloc_va_range(struct i915_address_space *vm,return ret;/* Do the allocations first so we can easily bail out */ - ret =gen8_ppgtt_alloc_page_directories (ppgtt, &ppgtt->pdp, start, length, - new_page_dirs); + ret =gen8_ppgtt_alloc_page_directories (vm, pdp, start, length, new_page_dirs);if (ret) {free_gen8_temp_bitmaps (new_page_dirs, new_page_tables, pdpes);return ret; } -/* For every page directory referenced, allocate page tables */ -gen8_for_each_pdpe (pd, &ppgtt->pdp, start, length, temp, pdpe) { +gen8_for_each_pdpe (pd, pdp, start, length, temp, pdpe) {bitmap_zero (new_page_tables[pdpe],GEN8_PDES_PER_PAGE ); - ret =gen8_ppgtt_alloc_pagetabs (ppgtt, pd, start, length, + ret =gen8_ppgtt_alloc_pagetabs (vm, pd, start, length, new_page_tables[pdpe]);if (ret) goto err_out;
@@ -979,10 +988,7 @@ static int gen8_alloc_va_range(struct i915_address_space *vm, start = orig_start; length = orig_length; -/* Allocations have completed successfully, so set the bitmaps, and do -* the mappings. */ -gen8_for_each_pdpe (pd, &ppgtt->pdp, start, length, temp, pdpe) { -gen8_ppgtt_pde_t *const page_directory =kmap_atomic (pd->page); +gen8_for_each_pdpe (pd, pdp, start, length, temp, pdpe) {struct i915_page_table_entry *pt;uint64_t pd_len =gen8_clamp_pd (start, length);uint64_t pd_start = start;
@@ -1004,20 +1010,10 @@ static int gen8_alloc_va_range(struct i915_address_space *vm,/* Our pde is now pointing to the pagetable, pt */ set_bit (pde, pd->used_pdes); - -/* Map the PDE to the page table */ -__gen8_do_map_pt (page_directory + pde, pt, vm->dev); - -/* NB: We haven't yet mapped ptes to pages. At this -* point we're still relying on insert_entries() */ } -if (!HAS_LLC (vm->dev)) -drm_clflush_virt_range (page_directory,PAGE_SIZE ); - -kunmap_atomic (page_directory); - -set_bit (pdpe, ppgtt->pdp.used_pdpes); +set_bit (pdpe, pdp->used_pdpes); +gen8_map_pagetable_range (pd, start, length, dev); }free_gen8_temp_bitmaps (new_page_dirs, new_page_tables, pdpes);
@@ -1026,16 +1022,36 @@ static int gen8_alloc_va_range(struct i915_address_space *vm, err_out:while (pdpe--) {for_each_set_bit (temp, new_page_tables[pdpe],GEN8_PDES_PER_PAGE ) -unmap_and_free_pt (pd->page_tables[temp], vm->dev); +unmap_and_free_pt (pd->page_tables[temp], dev); }for_each_set_bit (pdpe, new_page_dirs, pdpes) -unmap_and_free_pd (ppgtt->pdp.page_directory[pdpe], vm->dev); +unmap_and_free_pd (pdp->page_directory[pdpe], dev);free_gen8_temp_bitmaps (new_page_dirs, new_page_tables, pdpes);return ret; } +static int __noreturn gen8_alloc_va_range_4lvl (struct i915_address_space *vm, +struct i915_pml4 *pml4, +uint64_t start, +uint64_t length) +{ +BUG ();/* to be implemented later */ +} + +static int gen8_alloc_va_range (struct i915_address_space *vm, +uint64_t start,uint64_t length) +{ +struct i915_hw_ppgtt *ppgtt = + container_of(vm, struct i915_hw_ppgtt, base); + +if (!USES_FULL_48BIT_PPGTT (vm->dev)) +return gen8_alloc_va_range_3lvl (vm, &ppgtt->pdp, start, length); +else +return gen8_alloc_va_range_4lvl (vm, &ppgtt->pml4, start, length); +} +static void gen8_ppgtt_fini_common (struct i915_hw_ppgtt *ppgtt) {unmap_and_free_pt (ppgtt->scratch_pd, ppgtt->base.dev);
@@ -1078,12 +1094,13 @@ static int gen8_aliasing_ppgtt_init(struct i915_hw_ppgtt *ppgtt) {struct drm_device *dev = ppgtt->base.dev;struct drm_i915_private *dev_priv = dev->dev_private; +struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ struct i915_page_directory_entry *pd;uint64_t temp, start =0 , size = dev_priv->gtt.base.total;uint32_t pdpe;int ret; - ret =gen8_ppgtt_init_common (ppgtt, dev_priv->gtt.base.total); + ret =gen8_ppgtt_init_common (ppgtt, size);if (ret)return ret;
@@ -1096,8 +1113,8 @@ static int gen8_aliasing_ppgtt_init(struct i915_hw_ppgtt *ppgtt)return ret; } -gen8_for_each_pdpe (pd, &ppgtt->pdp, start, size, temp, pdpe) -gen8_map_pagetable_range (pd, start, size, ppgtt->base.dev); +gen8_for_each_pdpe (pd, pdp, start, size, temp, pdpe) +gen8_map_pagetable_range (pd, start, size, dev); ppgtt->base.allocate_va_range =NULL ; ppgtt->base.clear_range = gen8_ppgtt_clear_range;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 23/32 drm/i915/bdw: Add dynamic page trace events
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
The dynamic page allocation patch series added it for GEN6, this patch adds them for GEN8.
v2: Consolidate pagetable/page_directory events
v3: Multiple rebases.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 23 +++++++++++++++-------- drivers/gpu/drm/i915/i915_trace.h | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +15 -8
@@ -672,19 +672,24 @@ static void __gen8_do_map_pt(gen8_ppgtt_pde_t * const pde,/* It's likely we'll map more than one pagetable at a time. This function will * save us unnecessary kmap calls, but do no more functionally than multiple * calls to map_pt. */ -static void gen8_map_pagetable_range (struct i915_page_directory_entry *pd, +static void gen8_map_pagetable_range (struct i915_address_space *vm, +struct i915_page_directory_entry *pd,uint64_t start, -uint64_t length, -struct drm_device *dev) +uint64_t length) {gen8_ppgtt_pde_t *const page_directory =kmap_atomic (pd->page);struct i915_page_table_entry *pt;uint64_t temp, pde; -gen8_for_each_pde (pt, pd, start, length, temp, pde) -__gen8_do_map_pt (page_directory + pde, pt, dev); +gen8_for_each_pde (pt, pd, start, length, temp, pde) { +__gen8_do_map_pt (page_directory + pde, pt, vm->dev); +trace_i915_page_table_entry_map (vm, pde, pt, +gen8_pte_index (start), +gen8_pte_count (start, length), +GEN8_PTES_PER_PAGE ); + } -if (!HAS_LLC (dev)) +if (!HAS_LLC (vm->dev))drm_clflush_virt_range (page_directory,PAGE_SIZE );kunmap_atomic (page_directory);
@@ -814,6 +819,7 @@ static int gen8_ppgtt_alloc_pagetabs(struct i915_address_space *vm, pd->page_tables[pde] = pt;set_bit (pde, new_pts); +trace_i915_page_table_entry_alloc (vm, pde, start,GEN8_PDE_SHIFT ); }return 0 ;
@@ -875,6 +881,7 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_address_space *vm, pdp->page_directory[pdpe] = pd;set_bit (pdpe, new_pds); +trace_i915_page_directory_entry_alloc (vm, pdpe, start,GEN8_PDPE_SHIFT ); }return 0 ;
@@ -1013,7 +1020,7 @@ static int gen8_alloc_va_range_3lvl(struct i915_address_space *vm, }set_bit (pdpe, pdp->used_pdpes); -gen8_map_pagetable_range (pd, start, length, dev); +gen8_map_pagetable_range (vm, pd, start, length); }free_gen8_temp_bitmaps (new_page_dirs, new_page_tables, pdpes);
@@ -1114,7 +1121,7 @@ static int gen8_aliasing_ppgtt_init(struct i915_hw_ppgtt *ppgtt) }gen8_for_each_pdpe (pd, pdp, start, size, temp, pdpe) -gen8_map_pagetable_range (pd, start, size, dev); +gen8_map_pagetable_range (&ppgtt->base, pd,start, size); ppgtt->base.allocate_va_range =NULL ; ppgtt->base.clear_range = gen8_ppgtt_clear_range;
drivers/gpu/drm/i915/i915_trace.h +16 -0
@@ -214,6 +214,22 @@ DEFINE_EVENT(i915_page_table_entry, i915_page_table_entry_alloc,TP_ARGS (vm, pde, start, pde_shift) ); +DEFINE_EVENT_PRINT (i915_page_table_entry, i915_page_directory_entry_alloc, + TP_PROTO(struct i915_address_space *vm, u32 pdpe, u64 start, u64 pdpe_shift), +TP_ARGS (vm, pdpe, start, pdpe_shift), + +TP_printk ("vm=%p, pdpe=%d (0x%llx-0x%llx)" , + __entry->vm, __entry->pde, __entry->start, __entry->end) +); + +DEFINE_EVENT_PRINT (i915_page_table_entry, i915_page_directory_pointer_entry_alloc, + TP_PROTO(struct i915_address_space *vm, u32 pml4e, u64 start, u64 pml4e_shift), +TP_ARGS (vm, pml4e, start, pml4e_shift), + +TP_printk ("vm=%p, pml4e=%d (0x%llx-0x%llx)" , + __entry->vm, __entry->pde, __entry->start, __entry->end) +); +/* Avoid extra math because we only support two sizes. The format is defined by * bitmap_scnprintf. Each 32 bits is 8 HEX digits followed by comma */ #define TRACE_PT_SIZE (bits) \
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 24/32 drm/i915/bdw: Add ppgtt info for dynamic pages
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
Note that there is no gen8 ppgtt debug_dump function yet.
--- drivers/gpu/drm/i915/i915_debugfs.c | 19 ++++++++++--------- drivers/gpu/drm/i915/i915_gem_gtt.c | 32 ++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_gem_gtt.h | 9 +++++++++ 3 files changed, 51 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +10 -9
@@ -2165,7 +2165,6 @@ static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev) {struct drm_i915_private *dev_priv = dev->dev_private;struct intel_engine_cs *ring; -struct drm_file *file;int i;if (INTEL_INFO (dev)->gen ==6 )
@@ -2189,14 +2188,6 @@ static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev) ppgtt->debug_dump (ppgtt, m); } - -list_for_each_entry_reverse (file, &dev->filelist, lhead) { -struct drm_i915_file_private *file_priv = file->driver_priv; - -seq_printf (m,"proc: %s\n" , -get_pid_task (file->pid,PIDTYPE_PID )->comm); -idr_for_each (&file_priv->context_idr, per_file_ctx, m); - } }static int i915_ppgtt_info (struct seq_file *m,void *data)
@@ -2204,6 +2195,7 @@ static int i915_ppgtt_info(struct seq_file *m, void *data)struct drm_info_node *node = m->private;struct drm_device *dev = node->minor->dev;struct drm_i915_private *dev_priv = dev->dev_private; +struct drm_file *file;int ret =mutex_lock_interruptible (&dev->struct_mutex);if (ret)
@@ -2215,6 +2207,15 @@ static int i915_ppgtt_info(struct seq_file *m, void *data)else if (INTEL_INFO (dev)->gen >=6 )gen6_ppgtt_info (m, dev); +list_for_each_entry_reverse (file, &dev->filelist, lhead) { +struct drm_i915_file_private *file_priv = file->driver_priv; + +seq_printf (m,"\nproc: %s\n" , +get_pid_task (file->pid,PIDTYPE_PID )->comm); +idr_for_each (&file_priv->context_idr, per_file_ctx, + (void *)(unsigned long )m); + } +intel_runtime_pm_put (dev_priv);mutex_unlock (&dev->struct_mutex);
drivers/gpu/drm/i915/i915_gem_gtt.c +32 -0
@@ -2127,6 +2127,38 @@ static void gen8_ggtt_clear_range(struct i915_address_space *vm,readl (gtt_base); } +void gen8_for_every_pdpe_pde (struct i915_hw_ppgtt *ppgtt, +void (*callback)(struct i915_page_directory_pointer_entry *pdp, +struct i915_page_directory_entry *pd, +struct i915_page_table_entry *pt, +unsigned pdpe, +unsigned pde, +void *data), +void *data) +{ +uint64_t start = ppgtt->base.start; +uint64_t length = ppgtt->base.total; +uint64_t pdpe, pde, temp; + +struct i915_page_directory_entry *pd; +struct i915_page_table_entry *pt; + +gen8_for_each_pdpe (pd, &ppgtt->pdp, start, length, temp, pdpe) { +uint64_t pd_start = start, pd_length = length; +int i; + +if (pd ==NULL ) { +for (i =0 ; i <GEN8_PDES_PER_PAGE ; i++) +callback (&ppgtt->pdp,NULL ,NULL , pdpe, i, data); +continue ; + } + +gen8_for_each_pde (pt, pd, pd_start, pd_length, temp, pde) { +callback (&ppgtt->pdp, pd, pt, pdpe, pde, data); + } + } +} + static void gen6_ggtt_clear_range(struct i915_address_space *vm, uint64_t start, uint64_t length,
drivers/gpu/drm/i915/i915_gem_gtt.h +9 -0
@@ -483,6 +483,15 @@ static inline size_t gen8_pde_count(uint64_t addr, uint64_t length)return i915_pde_index (end,GEN8_PDE_SHIFT ) -i915_pde_index (addr,GEN8_PDE_SHIFT ); } +void gen8_for_every_pdpe_pde (struct i915_hw_ppgtt *ppgtt, +void (*callback)(struct i915_page_directory_pointer_entry *pdp, +struct i915_page_directory_entry *pd, +struct i915_page_table_entry *pt, +unsigned pdpe, +unsigned pde, +void *data), +void *data); +int i915_gem_gtt_init (struct drm_device *dev);void i915_gem_init_global_gtt (struct drm_device *dev);void i915_global_gtt_cleanup (struct drm_device *dev);
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 25/32 drm/i915/bdw: implement alloc/free for 4lvl
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
The code for 4lvl works just as one would expect, and nicely it is able to call into the existing 3lvl page table code to handle all of the lower levels.
PML4 has no special attributes, and there will always be a PML4. So simply initialize it at creation, and destroy it at the end.
v2: Return something at the end of gen8_alloc_va_range_4lvl to keep the compiler happy. And define ret only in one place.
Updated gen8_ppgtt_unmap_pages and gen8_ppgtt_free to handle 4lvl.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 240 +++++++++++++++++++++++++++++++----- drivers/gpu/drm/i915/i915_gem_gtt.h | 11 +- 2 files changed, 217 insertions(+), 34 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +207 -33
@@ -482,9 +482,12 @@ static void __pdp_fini(struct i915_page_directory_pointer_entry *pdp)static void unmap_and_free_pdp (struct i915_page_directory_pointer_entry *pdp,struct drm_device *dev) { -__pdp_fini (pdp); -if (USES_FULL_48BIT_PPGTT (dev)) +if (USES_FULL_48BIT_PPGTT (dev)) { +__pdp_fini (pdp); +i915_dma_unmap_single (pdp, dev); +__free_page (pdp->page);kfree (pdp); + } } static int __pdp_init(struct i915_page_directory_pointer_entry *pdp,
@@ -510,6 +513,60 @@ static int __pdp_init(struct i915_page_directory_pointer_entry *pdp,return 0 ; } +static struct i915_page_directory_pointer_entry *alloc_pdp_single (struct i915_hw_ppgtt *ppgtt, +struct i915_pml4 *pml4) +{ +struct drm_device *dev = ppgtt->base.dev; +struct i915_page_directory_pointer_entry *pdp; +int ret; + +BUG_ON (!USES_FULL_48BIT_PPGTT (dev)); + + pdp =kmalloc (sizeof (*pdp),GFP_KERNEL ); +if (!pdp) +return ERR_PTR (-ENOMEM ); + + pdp->page =alloc_page (GFP_KERNEL |GFP_DMA32 | __GFP_ZERO); +if (!pdp->page) { +kfree (pdp); +return ERR_PTR (-ENOMEM ); + } + + ret =__pdp_init (pdp, dev); +if (ret) { +__free_page (pdp->page); +kfree (pdp); +return ERR_PTR (ret); + } + +i915_dma_map_single (pdp, dev); + +return pdp; +} + +static void pml4_fini (struct i915_pml4 *pml4) +{ +struct i915_hw_ppgtt *ppgtt = + container_of(pml4, struct i915_hw_ppgtt, pml4); +i915_dma_unmap_single (pml4, ppgtt->base.dev); +__free_page (pml4->page); +/* HACK */ + pml4->page =NULL ; +} + +static int pml4_init (struct i915_hw_ppgtt *ppgtt) +{ +struct i915_pml4 *pml4 = &ppgtt->pml4; + + pml4->page =alloc_page (GFP_KERNEL | __GFP_ZERO); +if (!pml4->page) +return -ENOMEM ; + +i915_dma_map_single (pml4, ppgtt->base.dev); + +return 0 ; +} +/* Broadwell Page Directory Pointer Descriptors */ static int gen8_write_pdp(struct intel_engine_cs *ring, unsigned entry,
@@ -711,14 +768,13 @@ static void gen8_free_page_tables(struct i915_page_directory_entry *pd, struct d } } -static void gen8_ppgtt_unmap_pages (struct i915_hw_ppgtt *ppgtt) +static void gen8_ppgtt_unmap_pages_3lvl (struct i915_page_directory_pointer_entry *pdp, +struct drm_device *dev) { -struct pci_dev *hwdev = ppgtt->base.dev->pdev; -struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ +struct pci_dev *hwdev = dev->pdev;int i, j; -for_each_set_bit (i, pdp->used_pdpes, -I915_PDPES_PER_PDP (ppgtt->base.dev)) { +for_each_set_bit (i, pdp->used_pdpes,I915_PDPES_PER_PDP (dev)) {struct i915_page_directory_entry *pd;if (WARN_ON (!pdp->page_directory[i]))
@@ -746,27 +802,73 @@ static void gen8_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt) } } -static void gen8_ppgtt_free (struct i915_hw_ppgtt *ppgtt) +static void gen8_ppgtt_unmap_pages_4lvl (struct i915_hw_ppgtt *ppgtt) { +struct pci_dev *hwdev = ppgtt->base.dev->pdev;int i; -if (!USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) { -for_each_set_bit (i, ppgtt->pdp.used_pdpes, -I915_PDPES_PER_PDP (ppgtt->base.dev)) { -if (WARN_ON (!ppgtt->pdp.page_directory[i])) -continue ; +for_each_set_bit (i, ppgtt->pml4.used_pml4es,GEN8_PML4ES_PER_PML4 ) { +struct i915_page_directory_pointer_entry *pdp; -gen8_free_page_tables (ppgtt->pdp.page_directory[i], - ppgtt->base.dev); -unmap_and_free_pd (ppgtt->pdp.page_directory[i], - ppgtt->base.dev); - } -unmap_and_free_pdp (&ppgtt->pdp, ppgtt->base.dev); - }else { -BUG ();/* to be implemented later */ +if (WARN_ON (!ppgtt->pml4.pdps[i])) +continue ; + + pdp = ppgtt->pml4.pdps[i]; +if (!pdp->daddr) +pci_unmap_page (hwdev, pdp->daddr,PAGE_SIZE , +PCI_DMA_BIDIRECTIONAL ); + +gen8_ppgtt_unmap_pages_3lvl (ppgtt->pml4.pdps[i], + ppgtt->base.dev); } } +static void gen8_ppgtt_unmap_pages (struct i915_hw_ppgtt *ppgtt) +{ +if (!USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) +gen8_ppgtt_unmap_pages_3lvl (&ppgtt->pdp, ppgtt->base.dev); +else +gen8_ppgtt_unmap_pages_4lvl (ppgtt); +} + +static void gen8_ppgtt_free_3lvl (struct i915_page_directory_pointer_entry *pdp, +struct drm_device *dev) +{ +int i; + +for_each_set_bit (i, pdp->used_pdpes,I915_PDPES_PER_PDP (dev)) { +if (WARN_ON (!pdp->page_directory[i])) +continue ; + +gen8_free_page_tables (pdp->page_directory[i], dev); +unmap_and_free_pd (pdp->page_directory[i], dev); + } + +unmap_and_free_pdp (pdp, dev); +} + +static void gen8_ppgtt_free_4lvl (struct i915_hw_ppgtt *ppgtt) +{ +int i; + +for_each_set_bit (i, ppgtt->pml4.used_pml4es,GEN8_PML4ES_PER_PML4 ) { +if (WARN_ON (!ppgtt->pml4.pdps[i])) +continue ; + +gen8_ppgtt_free_3lvl (ppgtt->pml4.pdps[i], ppgtt->base.dev); + } + +pml4_fini (&ppgtt->pml4); +} + +static void gen8_ppgtt_free (struct i915_hw_ppgtt *ppgtt) +{ +if (!USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) +gen8_ppgtt_free_3lvl (&ppgtt->pdp, ppgtt->base.dev); +else +gen8_ppgtt_free_4lvl (ppgtt); +} +static void gen8_ppgtt_cleanup (struct i915_address_space *vm) { struct i915_hw_ppgtt *ppgtt =
@@ -1039,12 +1141,74 @@ err_out:return ret; } -static int __noreturn gen8_alloc_va_range_4lvl (struct i915_address_space *vm, -struct i915_pml4 *pml4, -uint64_t start, -uint64_t length) +static int gen8_alloc_va_range_4lvl (struct i915_address_space *vm, +struct i915_pml4 *pml4, +uint64_t start, +uint64_t length) { -BUG ();/* to be implemented later */ +DECLARE_BITMAP (new_pdps,GEN8_PML4ES_PER_PML4 ); +struct i915_hw_ppgtt *ppgtt = + container_of(vm, struct i915_hw_ppgtt, base); +struct i915_page_directory_pointer_entry *pdp; +const uint64_t orig_start = start; +const uint64_t orig_length = length; +uint64_t temp, pml4e; +int ret =0 ; + +/* Do the pml4 allocations first, so we don't need to track the newly +* allocated tables below the pdp */ +bitmap_zero (new_pdps,GEN8_PML4ES_PER_PML4 ); + +/* The page_directoryectory and pagetable allocations are done in the shared 3 +* and 4 level code. Just allocate the pdps. +*/ +gen8_for_each_pml4e (pdp, pml4, start, length, temp, pml4e) { +if (!pdp) { +WARN_ON (test_bit (pml4e, pml4->used_pml4es)); + pdp =alloc_pdp_single (ppgtt, pml4); +if (IS_ERR (pdp)) + goto err_alloc; + + pml4->pdps[pml4e] = pdp; +set_bit (pml4e, new_pdps); +trace_i915_page_directory_pointer_entry_alloc (&ppgtt->base, pml4e, + pml4e <<GEN8_PML4E_SHIFT , +GEN8_PML4E_SHIFT ); + + } + } + +WARN (bitmap_weight (new_pdps,GEN8_PML4ES_PER_PML4 ) >2 , +"The allocation has spanned more than 512GB. " +"It is highly likely this is incorrect." ); + + start = orig_start; + length = orig_length; + +gen8_for_each_pml4e (pdp, pml4, start, length, temp, pml4e) { +BUG_ON (!pdp); + + ret =gen8_alloc_va_range_3lvl (vm, pdp, start, length); +if (ret) + goto err_out; + } + +bitmap_or (pml4->used_pml4es, new_pdps, pml4->used_pml4es, +GEN8_PML4ES_PER_PML4 ); + +return 0 ; + +err_out: + start = orig_start; + length = orig_length; +gen8_for_each_pml4e (pdp, pml4, start, length, temp, pml4e) +gen8_ppgtt_free_3lvl (pdp, vm->dev); + +err_alloc: +for_each_set_bit (pml4e, new_pdps,GEN8_PML4ES_PER_PML4 ) +unmap_and_free_pdp (pdp, vm->dev); + +return ret; } static int gen8_alloc_va_range(struct i915_address_space *vm,
@@ -1053,16 +1217,19 @@ static int gen8_alloc_va_range(struct i915_address_space *vm,struct i915_hw_ppgtt *ppgtt = container_of(vm, struct i915_hw_ppgtt, base); -if (!USES_FULL_48BIT_PPGTT (vm->dev)) -return gen8_alloc_va_range_3lvl (vm, &ppgtt->pdp, start, length); -else +if (USES_FULL_48BIT_PPGTT (vm->dev))return gen8_alloc_va_range_4lvl (vm, &ppgtt->pml4, start, length); +else +return gen8_alloc_va_range_3lvl (vm, &ppgtt->pdp, start, length); }static void gen8_ppgtt_fini_common (struct i915_hw_ppgtt *ppgtt) {unmap_and_free_pt (ppgtt->scratch_pd, ppgtt->base.dev); -unmap_and_free_pdp (&ppgtt->pdp, ppgtt->base.dev); +if (USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) +pml4_fini (&ppgtt->pml4); +else +unmap_and_free_pdp (&ppgtt->pdp, ppgtt->base.dev); }/**
@@ -1085,14 +1252,21 @@ static int gen8_ppgtt_init_common(struct i915_hw_ppgtt *ppgtt, uint64_t size) ppgtt->switch_mm = gen8_mm_switch; -if (!USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) { +if (USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) { +int ret =pml4_init (ppgtt); +if (ret) { +unmap_and_free_pt (ppgtt->scratch_pd, ppgtt->base.dev); +return ret; + } + }else {int ret =__pdp_init (&ppgtt->pdp, false);if (ret) {unmap_and_free_pt (ppgtt->scratch_pd, ppgtt->base.dev);return ret; } - }else -return -EPERM ;/* Not yet implemented */ + +trace_i915_page_directory_pointer_entry_alloc (&ppgtt->base,0 ,0 ,GEN8_PML4E_SHIFT ); + }return 0 ; }
drivers/gpu/drm/i915/i915_gem_gtt.h +10 -1
@@ -87,6 +87,7 @@ typedef gen8_gtt_pte_t gen8_ppgtt_pde_t;*/ #define GEN8_PML4ES_PER_PML4 512#define GEN8_PML4E_SHIFT 39 +#define GEN8_PML4E_MASK (GEN8_PML4ES_PER_PML4 - 1)#define GEN8_PDPE_SHIFT 30/* NB: GEN8_PDPE_MASK is untrue for 32b platforms, but it has no impact on 32b page * tables */
@@ -427,6 +428,14 @@ static inline uint32_t gen6_pde_index(uint32_t addr) temp = min(temp, length), \ start += temp, length -= temp) +#define gen8_for_each_pml4e (pdp, pml4, start, length, temp, iter) \ + for (iter = gen8_pml4e_index(start), pdp = (pml4)->pdps[iter]; \ + length > 0 && iter < GEN8_PML4ES_PER_PML4; \ + pdp = (pml4)->pdps[++iter], \ + temp = ALIGN(start+1, 1ULL << GEN8_PML4E_SHIFT) - start, \ + temp = min(temp, length), \ + start += temp, length -= temp) +#define gen8_for_each_pdpe (pd, pdp, start, length, temp, iter) \ gen8_for_each_pdpe_e(pd, pdp, start, length, temp, iter, I915_PDPES_PER_PDP(dev))
@@ -458,7 +467,7 @@ static inline uint32_t gen8_pdpe_index(uint64_t address)static inline uint32_t gen8_pml4e_index (uint64_t address) { -BUG ();/* For 64B */ +return (address >>GEN8_PML4E_SHIFT ) &GEN8_PML4E_MASK ; }static inline size_t gen8_pte_count (uint64_t addr,uint64_t length)
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 26/32 drm/i915/bdw: Add 4 level switching infrastructure
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
Map is easy, it's the same register as the PDP descriptor 0, but it only has one entry.
v2: PML4 update in legacy context switch is left for historic reasons, the preferred mode of operation is with lrc context based submission.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 56 +++++++++++++++++++++++++++++++++---- drivers/gpu/drm/i915/i915_gem_gtt.h | 4 ++- drivers/gpu/drm/i915/i915_reg.h | 1 + 3 files changed, 55 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +51 -5
@@ -192,6 +192,9 @@ static inline gen8_ppgtt_pde_t gen8_pde_encode(struct drm_device *dev,return pde; } +#define gen8_pdpe_encode gen8_pde_encode +#define gen8_pml4e_encode gen8_pde_encode +static gen6_gtt_pte_t snb_pte_encode (dma_addr_t addr,enum i915_cache_level level,bool valid,u32 unused)
@@ -591,8 +594,8 @@ static int gen8_write_pdp(struct intel_engine_cs *ring,return 0 ; } -static int gen8_mm_switch (struct i915_hw_ppgtt *ppgtt, -struct intel_engine_cs *ring) +static int gen8_legacy_mm_switch (struct i915_hw_ppgtt *ppgtt, +struct intel_engine_cs *ring) {int i, ret;
@@ -609,6 +612,12 @@ static int gen8_mm_switch(struct i915_hw_ppgtt *ppgtt,return 0 ; } +static int gen8_48b_mm_switch (struct i915_hw_ppgtt *ppgtt, +struct intel_engine_cs *ring) +{ +return gen8_write_pdp (ring,0 , ppgtt->pml4.daddr); +} + static void gen8_ppgtt_clear_range(struct i915_address_space *vm, uint64_t start, uint64_t length,
@@ -752,6 +761,37 @@ static void gen8_map_pagetable_range(struct i915_address_space *vm,kunmap_atomic (page_directory); } +static void gen8_map_page_directory (struct i915_page_directory_pointer_entry *pdp, +struct i915_page_directory_entry *pd, +int index, +struct drm_device *dev) +{ +gen8_ppgtt_pdpe_t *page_directorypo; +gen8_ppgtt_pdpe_t pdpe; + +/* We do not need to clflush because no platform requiring flush +* supports 64b pagetables. */ +if (!USES_FULL_48BIT_PPGTT (dev)) +return ; + + page_directorypo =kmap_atomic (pdp->page); + pdpe =gen8_pdpe_encode (dev, pd->daddr,I915_CACHE_LLC ); + page_directorypo[index] = pdpe; +kunmap_atomic (page_directorypo); +} + +static void gen8_map_page_directory_pointer (struct i915_pml4 *pml4, +struct i915_page_directory_pointer_entry *pdp, +int index, +struct drm_device *dev) +{ +gen8_ppgtt_pml4e_t *pagemap =kmap_atomic (pml4->page); +gen8_ppgtt_pml4e_t pml4e =gen8_pml4e_encode (dev, pdp->daddr,I915_CACHE_LLC ); +BUG_ON (!USES_FULL_48BIT_PPGTT (dev)); + pagemap[index] = pml4e; +kunmap_atomic (pagemap); +} +static void gen8_free_page_tables (struct i915_page_directory_entry *pd,struct drm_device *dev) {int i;
@@ -1123,6 +1163,7 @@ static int gen8_alloc_va_range_3lvl(struct i915_address_space *vm,set_bit (pdpe, pdp->used_pdpes);gen8_map_pagetable_range (vm, pd, start, length); +gen8_map_page_directory (pdp, pd, pdpe, dev); }free_gen8_temp_bitmaps (new_page_dirs, new_page_tables, pdpes);
@@ -1191,6 +1232,8 @@ static int gen8_alloc_va_range_4lvl(struct i915_address_space *vm, ret =gen8_alloc_va_range_3lvl (vm, pdp, start, length);if (ret) goto err_out; + +gen8_map_page_directory_pointer (pml4, pdp, pml4e, vm->dev); } bitmap_or(pml4->used_pml4es, new_pdps, pml4->used_pml4es,
@@ -1250,14 +1293,14 @@ static int gen8_ppgtt_init_common(struct i915_hw_ppgtt *ppgtt, uint64_t size) ppgtt->base.cleanup = gen8_ppgtt_cleanup; ppgtt->base.insert_entries = gen8_ppgtt_insert_entries; - ppgtt->switch_mm = gen8_mm_switch; -if (USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) {int ret =pml4_init (ppgtt);if (ret) {unmap_and_free_pt (ppgtt->scratch_pd, ppgtt->base.dev);return ret; } + + ppgtt->switch_mm = gen8_48b_mm_switch; }else {int ret =__pdp_init (&ppgtt->pdp, false);if (ret) {
@@ -1265,6 +1308,7 @@ static int gen8_ppgtt_init_common(struct i915_hw_ppgtt *ppgtt, uint64_t size)return ret; } + ppgtt->switch_mm = gen8_legacy_mm_switch;trace_i915_page_directory_pointer_entry_alloc (&ppgtt->base,0 ,0 ,GEN8_PML4E_SHIFT ); }
@@ -1294,6 +1338,7 @@ static int gen8_aliasing_ppgtt_init(struct i915_hw_ppgtt *ppgtt)return ret; } +/* FIXME: PML4 */ gen8_for_each_pdpe (pd, pdp, start, size, temp, pdpe)gen8_map_pagetable_range (&ppgtt->base, pd,start, size);
@@ -1498,8 +1543,9 @@ static void gen8_ppgtt_enable(struct drm_device *dev)int j;for_each_ring (ring, dev_priv, j) { +u32 four_level =USES_FULL_48BIT_PPGTT (dev) ?GEN8_GFX_PPGTT_64B :0 ;I915_WRITE (RING_MODE_GEN7 (ring), -_MASKED_BIT_ENABLE (GFX_PPGTT_ENABLE )); +_MASKED_BIT_ENABLE (GFX_PPGTT_ENABLE | four_level)); } }
drivers/gpu/drm/i915/i915_gem_gtt.h +3 -1
@@ -38,7 +38,9 @@ struct drm_i915_file_private;typedef uint32_t gen6_gtt_pte_t ;typedef uint64_t gen8_gtt_pte_t ; -typedef gen8_gtt_pte_t gen8_ppgtt_pde_t ; +typedef gen8_gtt_pte_t gen8_ppgtt_pde_t ; +typedef gen8_ppgtt_pde_t gen8_ppgtt_pdpe_t ; +typedef gen8_ppgtt_pdpe_t gen8_ppgtt_pml4e_t ;#define gtt_total_entries (gtt) ((gtt).base.total >> PAGE_SHIFT)
drivers/gpu/drm/i915/i915_reg.h +1 -0
@@ -1338,6 +1338,7 @@ enum skl_disp_power_wells {#define GFX_REPLAY_MODE (1<<11)#define GFX_PSMI_GRANULARITY (1<<10)#define GFX_PPGTT_ENABLE (1<<9) +#define GEN8_GFX_PPGTT_64B (1<<7)#define VLV_DISPLAY_BASE 0x180000#define VLV_MIPI_BASE VLV_DISPLAY_BASE
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 27/32 drm/i915/bdw: Support 64 bit PPGTT in lrc mode
In reply to Michel ThierryIn 64b (48bit canonical) PPGTT addressing, the PDP0 register contains the base address to PML4, while the other PDP registers are ignored.
Also, the addressing mode must be specified in every context descriptor.
--- drivers/gpu/drm/i915/intel_lrc.c | 167 ++++++++++++++++++++++++++------------- 1 file changed, 114 insertions(+), 53 deletions(-)
drivers/gpu/drm/i915/intel_lrc.c +114 -53
@@ -255,7 +255,8 @@ u32 intel_execlists_ctx_id(struct drm_i915_gem_object *ctx_obj) }static uint64_t execlists_ctx_descriptor (struct intel_engine_cs *ring, -struct drm_i915_gem_object *ctx_obj) +struct drm_i915_gem_object *ctx_obj, +bool legacy_64bit_ctx) {struct drm_device *dev = ring->dev;uint64_t desc;
@@ -264,7 +265,10 @@ static uint64_t execlists_ctx_descriptor(struct intel_engine_cs *ring,WARN_ON (lrca &0xFFFFFFFF00000FFFULL ); desc =GEN8_CTX_VALID ; - desc |=LEGACY_CONTEXT <<GEN8_CTX_MODE_SHIFT ; +if (legacy_64bit_ctx) + desc |=LEGACY_64B_CONTEXT <<GEN8_CTX_MODE_SHIFT ; +else + desc |=LEGACY_CONTEXT <<GEN8_CTX_MODE_SHIFT ; desc |=GEN8_CTX_L3LLC_COHERENT ; desc |=GEN8_CTX_PRIVILEGE ; desc |= lrca;
@@ -292,16 +296,17 @@ static void execlists_elsp_write(struct intel_engine_cs *ring,struct drm_i915_private *dev_priv = dev->dev_private;uint64_t temp =0 ;uint32_t desc[4 ]; +bool legacy_64bit_ctx =USES_FULL_48BIT_PPGTT (dev);/* XXX: You must always write both descriptors in the order below. */ if (ctx_obj1) - temp =execlists_ctx_descriptor (ring, ctx_obj1); + temp =execlists_ctx_descriptor (ring, ctx_obj1, legacy_64bit_ctx);else temp =0 ; desc[1 ] = (u32)(temp >>32 ); desc[0 ] = (u32 )temp; - temp =execlists_ctx_descriptor (ring, ctx_obj0); + temp =execlists_ctx_descriptor (ring, ctx_obj0, legacy_64bit_ctx); desc[3 ] = (u32)(temp >>32 ); desc[2 ] = (u32 )temp;
@@ -332,37 +337,60 @@ static int execlists_update_context(struct drm_i915_gem_object *ctx_obj, reg_state[CTX_RING_TAIL +1 ] = tail; reg_state[CTX_RING_BUFFER_START +1 ] =i915_gem_obj_ggtt_offset (ring_obj); -/* True PPGTT with dynamic page allocation: update PDP registers and -* point the unallocated PDPs to the scratch page -*/ -if (ppgtt) { +if (ppgtt &&USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) { +/* True 64b PPGTT (48bit canonical) +* PDP0_DESCRIPTOR contains the base address to PML4 and +* other PDP Descriptors are ignored +*/ + reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pml4.daddr); + reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pml4.daddr); + }else if (ppgtt) { +/* True 32b PPGTT with dynamic page allocation: update PDP +* registers and point the unallocated PDPs to the scratch page +*/ if (test_bit (3 , ppgtt->pdp.used_pdpes)) { - reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); - reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + reg_state[CTX_PDP3_UDW +1 ] = +upper_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + reg_state[CTX_PDP3_LDW +1 ] = +lower_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); }else { - reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); - reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP3_UDW +1 ] = +upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP3_LDW +1 ] = +lower_32_bits (ppgtt->scratch_pd->daddr); }if (test_bit (2 , ppgtt->pdp.used_pdpes)) { - reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); - reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + reg_state[CTX_PDP2_UDW +1 ] = +upper_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + reg_state[CTX_PDP2_LDW +1 ] = +lower_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); }else { - reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); - reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP2_UDW +1 ] = +upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP2_LDW +1 ] = +lower_32_bits (ppgtt->scratch_pd->daddr); }if (test_bit (1 , ppgtt->pdp.used_pdpes)) { - reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); - reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + reg_state[CTX_PDP1_UDW +1 ] = +upper_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + reg_state[CTX_PDP1_LDW +1 ] = +lower_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); }else { - reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); - reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP1_UDW +1 ] = +upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP1_LDW +1 ] = +lower_32_bits (ppgtt->scratch_pd->daddr); }if (test_bit (0 , ppgtt->pdp.used_pdpes)) { - reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); - reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + reg_state[CTX_PDP0_UDW +1 ] = +upper_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + reg_state[CTX_PDP0_LDW +1 ] = +lower_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); }else { - reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); - reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP0_UDW +1 ] = +upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP0_LDW +1 ] = +lower_32_bits (ppgtt->scratch_pd->daddr); } }
@@ -1771,36 +1799,69 @@ populate_lr_context(struct intel_context *ctx, struct drm_i915_gem_object *ctx_o reg_state[CTX_PDP0_UDW ] =GEN8_RING_PDP_UDW (ring,0 ); reg_state[CTX_PDP0_LDW ] =GEN8_RING_PDP_LDW (ring,0 ); -/* With dynamic page allocation, PDPs may not be allocated at this point, -* Point the unallocated PDPs to the scratch page -*/ -if (test_bit (3 , ppgtt->pdp.used_pdpes)) { - reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); - reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); - }else { - reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); - reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); - } -if (test_bit (2 , ppgtt->pdp.used_pdpes)) { - reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); - reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); - }else { - reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); - reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); - } -if (test_bit (1 , ppgtt->pdp.used_pdpes)) { - reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); - reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); - }else { - reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); - reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); - } -if (test_bit (0 , ppgtt->pdp.used_pdpes)) { - reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); - reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); +if (USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) { +/* 64b PPGTT (48bit canonical) +* PDP0_DESCRIPTOR contains the base address to PML4 and +* other PDP Descriptors are ignored +*/ + reg_state[CTX_PDP3_UDW +1 ] =0 ; + reg_state[CTX_PDP3_LDW +1 ] =0 ; + reg_state[CTX_PDP2_UDW +1 ] =0 ; + reg_state[CTX_PDP2_LDW +1 ] =0 ; + reg_state[CTX_PDP1_UDW +1 ] =0 ; + reg_state[CTX_PDP1_LDW +1 ] =0 ; + reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pml4.daddr); + reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pml4.daddr); }else { - reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); - reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); +/* 32b PPGTT +* PDP*_DESCRIPTOR contains the base address of space supported. +* With dynamic page allocation, PDPs may not be allocated at +* this point. Point the unallocated PDPs to the scratch page +*/ +if (test_bit (3 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP3_UDW +1 ] = +upper_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + reg_state[CTX_PDP3_LDW +1 ] = +lower_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + }else { + reg_state[CTX_PDP3_UDW +1 ] = +upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP3_LDW +1 ] = +lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (test_bit (2 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP2_UDW +1 ] = +upper_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + reg_state[CTX_PDP2_LDW +1 ] = +lower_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + }else { + reg_state[CTX_PDP2_UDW +1 ] = +upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP2_LDW +1 ] = +lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (test_bit (1 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP1_UDW +1 ] = +upper_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + reg_state[CTX_PDP1_LDW +1 ] = +lower_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + }else { + reg_state[CTX_PDP1_UDW +1 ] = +upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP1_LDW +1 ] = +lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (test_bit (0 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP0_UDW +1 ] = +upper_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + reg_state[CTX_PDP0_LDW +1 ] = +lower_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + }else { + reg_state[CTX_PDP0_UDW +1 ] = +upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP0_LDW +1 ] = +lower_32_bits (ppgtt->scratch_pd->daddr); + } }if (ring->id ==RCS ) {
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 28/32 drm/i915/bdw: Generalize PTE writing for GEN8 PPGTT
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
The insert_entries function was the function used to write PTEs. For the PPGTT it was "hardcoded" to only understand two level page tables, which was the case for GEN7. We can reuse this for 4 level page tables, and remove the concept of insert_entries, which was never viable past 2 level page tables anyway, but it requires a bit of rework to make the function a bit more generic.
This patch begins the generalization work, and it will be heavily used upon when the 48b code is complete. The patch series attempts to make each function which touches a part of code specific to the page table level and here is no exception. Having extra variables (such as the PPGTT) distracts and provides room to add bugs since the function shouldn't be touching anything in the higher order page tables.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 55 +++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 17 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +38 -17
@@ -618,23 +618,19 @@ static int gen8_48b_mm_switch(struct i915_hw_ppgtt *ppgtt,return gen8_write_pdp (ring,0 , ppgtt->pml4.daddr); } -static void gen8_ppgtt_clear_range (struct i915_address_space *vm, -uint64_t start, -uint64_t length, -bool use_scratch) +static void gen8_ppgtt_clear_pte_range (struct i915_page_directory_pointer_entry *pdp, +uint64_t start, +uint64_t length, +gen8_gtt_pte_t scratch_pte, +const bool flush) { -struct i915_hw_ppgtt *ppgtt = - container_of(vm, struct i915_hw_ppgtt, base); -struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ -gen8_gtt_pte_t *pt_vaddr, scratch_pte; +gen8_gtt_pte_t *pt_vaddr;unsigned pdpe = start >>GEN8_PDPE_SHIFT &GEN8_PDPE_MASK ;unsigned pde = start >>GEN8_PDE_SHIFT &GEN8_PDE_MASK ;unsigned pte = start >>GEN8_PTE_SHIFT &GEN8_PTE_MASK ;unsigned num_entries = length >>PAGE_SHIFT ;unsigned last_pte, i; - scratch_pte =gen8_pte_encode (ppgtt->base.scratch.addr, -I915_CACHE_LLC , use_scratch);while (num_entries) {struct i915_page_directory_entry *pd;
@@ -667,7 +663,7 @@ static void gen8_ppgtt_clear_range(struct i915_address_space *vm, num_entries--; } -if (!HAS_LLC (ppgtt->base.dev)) +if (flush)drm_clflush_virt_range (pt_vaddr,PAGE_SIZE );kunmap_atomic (pt_vaddr);
@@ -679,14 +675,27 @@ static void gen8_ppgtt_clear_range(struct i915_address_space *vm, } } -static void gen8_ppgtt_insert_entries (struct i915_address_space *vm, -struct sg_table *pages, -uint64_t start, -enum i915_cache_level cache_level,u32 unused) +static void gen8_ppgtt_clear_range (struct i915_address_space *vm, +uint64_t start, +uint64_t length, +bool use_scratch) {struct i915_hw_ppgtt *ppgtt = container_of(vm, struct i915_hw_ppgtt, base);struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ + +gen8_gtt_pte_t scratch_pte =gen8_pte_encode (ppgtt->base.scratch.addr, +I915_CACHE_LLC , use_scratch); + +gen8_ppgtt_clear_pte_range (pdp, start, length, scratch_pte, !HAS_LLC (vm->dev)); +} + +static void gen8_ppgtt_insert_pte_entries (struct i915_page_directory_pointer_entry *pdp, +struct sg_table *pages, +uint64_t start, +enum i915_cache_level cache_level, +const bool flush) +{gen8_gtt_pte_t *pt_vaddr;unsigned pdpe = start >>GEN8_PDPE_SHIFT &GEN8_PDPE_MASK ;unsigned pde = start >>GEN8_PDE_SHIFT &GEN8_PDE_MASK ;
@@ -708,7 +717,7 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm,gen8_pte_encode (sg_page_iter_dma_address (&sg_iter), cache_level, true);if (++pte ==GEN8_PTES_PER_PAGE ) { -if (!HAS_LLC (ppgtt->base.dev)) +if (flush)drm_clflush_virt_range (pt_vaddr,PAGE_SIZE );kunmap_atomic (pt_vaddr); pt_vaddr =NULL ;
@@ -720,12 +729,24 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm, } }if (pt_vaddr) { -if (!HAS_LLC (ppgtt->base.dev)) +if (flush)drm_clflush_virt_range (pt_vaddr,PAGE_SIZE );kunmap_atomic (pt_vaddr); } } +static void gen8_ppgtt_insert_entries (struct i915_address_space *vm, +struct sg_table *pages, +uint64_t start, +enum i915_cache_level cache_level, +u32 unused) +{ + struct i915_hw_ppgtt *ppgtt = container_of(vm, struct i915_hw_ppgtt, base); +struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ + +gen8_ppgtt_insert_pte_entries (pdp, pages, start, cache_level, !HAS_LLC (vm->dev)); +} +static void __gen8_do_map_pt (gen8_ppgtt_pde_t *const pde,struct i915_page_table_entry *pt,struct drm_device *dev)
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 29/32 drm/i915: Plumb sg_iter through va allocation ->maps
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
As a step towards implementing 4 levels, while not discarding the existing pte map functions, we need to pass the sg_iter through. The current function understands to the page directory granularity. An object's pages may span the page directory, and so using the iter directly as we write the PTEs allows the iterator to stay coherent through a VMA mapping operation spanning multiple page table levels.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 46 +++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 17 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +29 -17
@@ -691,7 +691,7 @@ static void gen8_ppgtt_clear_range(struct i915_address_space *vm, }static void gen8_ppgtt_insert_pte_entries (struct i915_page_directory_pointer_entry *pdp, -struct sg_table *pages, +struct sg_page_iter *sg_iter,uint64_t start,enum i915_cache_level cache_level,const bool flush)
@@ -700,11 +700,10 @@ static void gen8_ppgtt_insert_pte_entries(struct i915_page_directory_pointer_entunsigned pdpe = start >>GEN8_PDPE_SHIFT &GEN8_PDPE_MASK ;unsigned pde = start >>GEN8_PDE_SHIFT &GEN8_PDE_MASK ;unsigned pte = start >>GEN8_PTE_SHIFT &GEN8_PTE_MASK ; -struct sg_page_iter sg_iter; pt_vaddr =NULL ; -for_each_sg_page (pages->sgl, &sg_iter, pages->nents,0 ) { +while (__sg_page_iter_next (sg_iter)) {if (pt_vaddr ==NULL ) {struct i915_page_directory_entry *pd = pdp->page_directory[pdpe];struct i915_page_table_entry *pt = pd->page_tables[pde];
@@ -714,7 +713,7 @@ static void gen8_ppgtt_insert_pte_entries(struct i915_page_directory_pointer_ent } pt_vaddr[pte] = -gen8_pte_encode (sg_page_iter_dma_address (&sg_iter), +gen8_pte_encode (sg_page_iter_dma_address (sg_iter), cache_level, true);if (++pte ==GEN8_PTES_PER_PAGE ) {if (flush)
@@ -743,8 +742,10 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm, { struct i915_hw_ppgtt *ppgtt = container_of(vm, struct i915_hw_ppgtt, base);struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ +struct sg_page_iter sg_iter; -gen8_ppgtt_insert_pte_entries (pdp, pages, start, cache_level, !HAS_LLC (vm->dev)); +__sg_page_iter_start (&sg_iter, pages->sgl,sg_nents (pages->sgl),0 ); +gen8_ppgtt_insert_pte_entries (pdp, &sg_iter, start, cache_level, !HAS_LLC (vm->dev)); } static void __gen8_do_map_pt(gen8_ppgtt_pde_t * const pde,
@@ -1106,10 +1107,12 @@ err_out:return -ENOMEM ; } -static int gen8_alloc_va_range_3lvl (struct i915_address_space *vm, -struct i915_page_directory_pointer_entry *pdp, -uint64_t start, -uint64_t length) +static int __gen8_alloc_vma_range_3lvl (struct i915_address_space *vm, +struct i915_page_directory_pointer_entry *pdp, +struct sg_page_iter *sg_iter, +uint64_t start, +uint64_t length, +u32 flags) {unsigned long *new_page_dirs, **new_page_tables;struct drm_device *dev = vm->dev;
@@ -1178,7 +1181,11 @@ static int gen8_alloc_va_range_3lvl(struct i915_address_space *vm,gen8_pte_index (pd_start), gen8_pte_count(pd_start, pd_len)); -/* Our pde is now pointing to the pagetable, pt */ +if (sg_iter) { +BUG_ON (!sg_iter->__nents); +gen8_ppgtt_insert_pte_entries (pdp, sg_iter, pd_start, + flags, !HAS_LLC (vm->dev)); + }set_bit (pde, pd->used_pdes); }
@@ -1203,10 +1210,12 @@ err_out:return ret; } -static int gen8_alloc_va_range_4lvl (struct i915_address_space *vm, -struct i915_pml4 *pml4, -uint64_t start, -uint64_t length) +static int __gen8_alloc_vma_range_4lvl (struct i915_address_space *vm, +struct i915_pml4 *pml4, +struct sg_page_iter *sg_iter, +uint64_t start, +uint64_t length, +u32 flags) {DECLARE_BITMAP (new_pdps,GEN8_PML4ES_PER_PML4 ); struct i915_hw_ppgtt *ppgtt =
@@ -1250,7 +1259,8 @@ static int gen8_alloc_va_range_4lvl(struct i915_address_space *vm,gen8_for_each_pml4e (pdp, pml4, start, length, temp, pml4e) {BUG_ON (!pdp); - ret =gen8_alloc_va_range_3lvl (vm, pdp, start, length); + ret =__gen8_alloc_vma_range_3lvl (vm, pdp, sg_iter, + start, length, flags);if (ret) goto err_out;
@@ -1282,9 +1292,11 @@ static int gen8_alloc_va_range(struct i915_address_space *vm, container_of(vm, struct i915_hw_ppgtt, base);if (USES_FULL_48BIT_PPGTT (vm->dev)) -return gen8_alloc_va_range_4lvl (vm, &ppgtt->pml4, start, length); +return __gen8_alloc_vma_range_4lvl (vm, &ppgtt->pml4,NULL , + start, length,0 );else -return gen8_alloc_va_range_3lvl (vm, &ppgtt->pdp, start, length); +return __gen8_alloc_vma_range_3lvl (vm, &ppgtt->pdp,NULL , + start, length,0 ); }static void gen8_ppgtt_fini_common (struct i915_hw_ppgtt *ppgtt)
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 30/32 drm/i915/bdw: Add 4 level support in insert_entries and clear_range
In reply to Michel ThierryWhen 48b is enabled, gen8_ppgtt_insert_entries needs to read the Page Map Level 4 (PML4), before it selects which Page Directory Pointer (PDP) it will write to.
Similarly, gen8_ppgtt_clear_range needs to get the correct PDP/PD range.
Also add a scratch page for PML4.
This patch was inspired by Ben's "Depend exclusively on map and unmap_vma".
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 66 ++++++++++++++++++++++++++++++------- drivers/gpu/drm/i915/i915_gem_gtt.h | 12 +++++++ 2 files changed, 67 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +55 -11
@@ -675,24 +675,52 @@ static void gen8_ppgtt_clear_pte_range(struct i915_page_directory_pointer_entry } } +static void gen8_ppgtt_clear_range_4lvl (struct i915_hw_ppgtt *ppgtt, +gen8_gtt_pte_t scratch_pte, +uint64_t start, +uint64_t length) +{ +struct i915_page_directory_pointer_entry *pdp; +uint64_t templ4, templ3, pml4e, pdpe; + +gen8_for_each_pml4e (pdp, &ppgtt->pml4, start, length, templ4, pml4e) { +struct i915_page_directory_entry *pd; +uint64_t pdp_len =gen8_clamp_pdp (start, length); +uint64_t pdp_start = start; + +gen8_for_each_pdpe (pd, pdp, pdp_start, pdp_len, templ3, pdpe) { +uint64_t pd_len =gen8_clamp_pd (pdp_start, pdp_len); +uint64_t pd_start = pdp_start; + +gen8_ppgtt_clear_pte_range (pdp, pd_start, pd_len, + scratch_pte, !HAS_LLC (ppgtt->base.dev)); + } + } +} +static void gen8_ppgtt_clear_range (struct i915_address_space *vm, -uint64_t start, -uint64_t length, +uint64_t start,uint64_t length,bool use_scratch) {struct i915_hw_ppgtt *ppgtt = - container_of(vm, struct i915_hw_ppgtt, base); -struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ - + container_of(vm, struct i915_hw_ppgtt, base);gen8_gtt_pte_t scratch_pte =gen8_pte_encode (ppgtt->base.scratch.addr,I915_CACHE_LLC , use_scratch); -gen8_ppgtt_clear_pte_range (pdp, start, length, scratch_pte, !HAS_LLC (vm->dev)); +if (!USES_FULL_48BIT_PPGTT (vm->dev)) { +struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp; + +gen8_ppgtt_clear_pte_range (pdp, start, length, scratch_pte, + !HAS_LLC (ppgtt->base.dev)); + }else { +gen8_ppgtt_clear_range_4lvl (ppgtt, scratch_pte, start, length); + } }static void gen8_ppgtt_insert_pte_entries (struct i915_page_directory_pointer_entry *pdp,struct sg_page_iter *sg_iter,uint64_t start, +size_t pages,enum i915_cache_level cache_level,const bool flush) {
@@ -703,7 +731,7 @@ static void gen8_ppgtt_insert_pte_entries(struct i915_page_directory_pointer_ent pt_vaddr =NULL ; -while (__sg_page_iter_next (sg_iter)) { +while (pages-- &&__sg_page_iter_next (sg_iter)) {if (pt_vaddr ==NULL ) {struct i915_page_directory_entry *pd = pdp->page_directory[pdpe];struct i915_page_table_entry *pt = pd->page_tables[pde];
@@ -741,11 +769,26 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm, u32 unused) { struct i915_hw_ppgtt *ppgtt = container_of(vm, struct i915_hw_ppgtt, base); -struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ +struct i915_page_directory_pointer_entry *pdp;struct sg_page_iter sg_iter;__sg_page_iter_start (&sg_iter, pages->sgl,sg_nents (pages->sgl),0 ); -gen8_ppgtt_insert_pte_entries (pdp, &sg_iter, start, cache_level, !HAS_LLC (vm->dev)); + +if (!USES_FULL_48BIT_PPGTT (vm->dev)) { + pdp = &ppgtt->pdp; +gen8_ppgtt_insert_pte_entries (pdp, &sg_iter, start, +sg_nents (pages->sgl), + cache_level, !HAS_LLC (vm->dev)); + }else { +struct i915_pml4 *pml4; +unsigned pml4e =gen8_pml4e_index (start); + + pml4 = &ppgtt->pml4; + pdp = pml4->pdps[pml4e]; +gen8_ppgtt_insert_pte_entries (pdp, &sg_iter, start, +sg_nents (pages->sgl), + cache_level, !HAS_LLC (vm->dev)); + } } static void __gen8_do_map_pt(gen8_ppgtt_pde_t * const pde,
@@ -1184,7 +1227,8 @@ static int __gen8_alloc_vma_range_3lvl(struct i915_address_space *vm,if (sg_iter) {BUG_ON (!sg_iter->__nents);gen8_ppgtt_insert_pte_entries (pdp, sg_iter, pd_start, - flags, !HAS_LLC (vm->dev)); +gen8_pte_count (pd_start, pd_len), + flags, !HAS_LLC (vm->dev)); }set_bit (pde, pd->used_pdes); }
@@ -1329,7 +1373,7 @@ static int gen8_ppgtt_init_common(struct i915_hw_ppgtt *ppgtt, uint64_t size)if (USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) {int ret =pml4_init (ppgtt);if (ret) { -unmap_and_free_pt (ppgtt->scratch_pd, ppgtt->base.dev); +unmap_and_free_pt (ppgtt->scratch_pml4, ppgtt->base.dev);return ret; }
drivers/gpu/drm/i915/i915_gem_gtt.h +12 -0
@@ -332,6 +332,7 @@ struct i915_hw_ppgtt {union {struct i915_page_table_entry *scratch_pt;struct i915_page_table_entry *scratch_pd;/* Just need the daddr */ +struct i915_page_table_entry *scratch_pml4; };struct drm_i915_file_private *file_priv;
@@ -452,6 +453,17 @@ static inline uint64_t gen8_clamp_pd(uint64_t start, uint64_t length)return next_pd - start; } +/* Clamp length to the next page_directory pointer boundary */ +static inline uint64_t gen8_clamp_pdp (uint64_t start,uint64_t length) +{ +uint64_t next_pdp =ALIGN (start +1 ,1ULL <<GEN8_PML4E_SHIFT ); + +if (next_pdp > (start + length)) +return length; + +return next_pdp - start; +} +static inline uint32_t gen8_pte_index (uint64_t address) {return i915_pte_index (address,GEN8_PDE_SHIFT );
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 31/32 drm/i915: Expand error state's address width to 64b
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
v2: 0 pad the new 8B fields or else intel_error_decode has a hard time. Note, regardless we need an igt update.
v3: Make reloc_offset 64b also.
--- drivers/gpu/drm/i915/i915_drv.h | 4 ++-- drivers/gpu/drm/i915/i915_gpu_error.c | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +2 -2
@@ -459,7 +459,7 @@ struct drm_i915_error_state {struct drm_i915_error_object {int page_count; -u32 gtt_offset; +u64 gtt_offset;u32 *pages[0 ]; } *ringbuffer, *batchbuffer, *wa_batchbuffer, *ctx, *hws_page;
@@ -485,7 +485,7 @@ struct drm_i915_error_state {u32 size;u32 name;u32 rseqno, wseqno; -u32 gtt_offset; +u64 gtt_offset;u32 read_domains;u32 write_domain; s32 fence_reg:I915_MAX_NUM_FENCE_BITS;
drivers/gpu/drm/i915/i915_gpu_error.c +9 -8
@@ -195,7 +195,7 @@ static void print_error_buffers(struct drm_i915_error_state_buf *m,err_printf (m," %s [%d]:\n" , name, count);while (count--) { - err_printf(m, " %08x %8u %02x %02x %x %x", + err_printf(m, " %016llx %8u %02x %02x %x %x", err->gtt_offset, err->size, err->read_domains,
@@ -415,7 +415,7 @@ int i915_error_state_to_str(struct drm_i915_error_state_buf *m,err_printf (m," (submitted by %s [%d])" , error->ring[i].comm, error->ring[i].pid); -err_printf (m," --- gtt_offset = 0x%08x\n" , +err_printf (m," --- gtt_offset = 0x%016llx\n" , obj->gtt_offset);print_error_obj (m, obj); }
@@ -423,7 +423,8 @@ int i915_error_state_to_str(struct drm_i915_error_state_buf *m, obj = error->ring[i].wa_batchbuffer;if (obj) {err_printf (m,"%s (w/a) --- gtt_offset = 0x%08x\n" , - dev_priv->ring[i].name, obj->gtt_offset); + dev_priv->ring[i].name, +lower_32_bits (obj->gtt_offset));print_error_obj (m, obj); }
@@ -442,14 +443,14 @@ int i915_error_state_to_str(struct drm_i915_error_state_buf *m,if ((obj = error->ring[i].ringbuffer)) {err_printf (m,"%s --- ringbuffer = 0x%08x\n" , dev_priv->ring[i].name, - obj->gtt_offset); +lower_32_bits (obj->gtt_offset));print_error_obj (m, obj); }if ((obj = error->ring[i].hws_page)) {err_printf (m,"%s --- HW Status = 0x%08x\n" , dev_priv->ring[i].name, - obj->gtt_offset); +lower_32_bits (obj->gtt_offset)); offset =0 ;for (elt =0 ; elt <PAGE_SIZE /16 ; elt +=4 ) { err_printf(m, "[%04x] %08x %08x %08x %08x\n",
@@ -465,13 +466,13 @@ int i915_error_state_to_str(struct drm_i915_error_state_buf *m,if ((obj = error->ring[i].ctx)) {err_printf (m,"%s --- HW Context = 0x%08x\n" , dev_priv->ring[i].name, - obj->gtt_offset); +lower_32_bits (obj->gtt_offset));print_error_obj (m, obj); } }if ((obj = error->semaphore_obj)) { -err_printf (m,"Semaphore page = 0x%08x\n" , obj->gtt_offset); +err_printf (m,"Semaphore page = 0x%016llx\n" , obj->gtt_offset);for (elt =0 ; elt <PAGE_SIZE /16 ; elt +=4 ) { err_printf(m, "[%04x] %08x %08x %08x %08x\n", elt * 4,
@@ -571,7 +572,7 @@ i915_error_object_create(struct drm_i915_private *dev_priv,int num_pages;bool use_ggtt;int i =0 ; -u32 reloc_offset; +u64 reloc_offset;if (src ==NULL || src->pages ==NULL )return NULL ;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 32/32 drm/i915/bdw: Flip the 48b switch
In reply to Michel ThierryUse 48b addresses if hw supports it and i915.enable_ppgtt=3.
Aliasing PPGTT remains 32b only.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 7 ++----- drivers/gpu/drm/i915/i915_params.c | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +2 -5
@@ -106,7 +106,7 @@ static int sanitize_enable_ppgtt(struct drm_device *dev, int enable_ppgtt) has_full_ppgtt =INTEL_INFO (dev)->gen >=7 ;#ifdef CONFIG_64BIT - has_full_64bit_ppgtt =IS_BROADWELL (dev) && false;/* FIXME: 64b */ + has_full_64bit_ppgtt =IS_BROADWELL (dev);#else has_full_64bit_ppgtt = false;#endif
@@ -1075,9 +1075,6 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_address_space *vm,BUG_ON (!bitmap_empty (new_pds, pdpes)); -/* FIXME: PPGTT container_of won't work for 64b */ -BUG_ON ((start + length) >0x800000000ULL ); -gen8_for_each_pdpe (pd, pdp, start, length, temp, pdpe) {if (pd)continue ;
@@ -1396,7 +1393,7 @@ static int gen8_aliasing_ppgtt_init(struct i915_hw_ppgtt *ppgtt) {struct drm_device *dev = ppgtt->base.dev;struct drm_i915_private *dev_priv = dev->dev_private; -struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ +struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b? */ struct i915_page_directory_entry *pd;uint64_t temp, start =0 , size = dev_priv->gtt.base.total;uint32_t pdpe;
drivers/gpu/drm/i915/i915_params.c +1 -1
@@ -119,7 +119,7 @@ MODULE_PARM_DESC(enable_hangcheck,module_param_named_unsafe (enable_ppgtt, i915.enable_ppgtt, int,0400 );MODULE_PARM_DESC (enable_ppgtt,"Override PPGTT usage. " -"(-1=auto [default], 0=disabled, 1=aliasing, 2=full)" ); +"(-1=auto [default], 0=disabled, 1=aliasing, 2=full, 3=full_64b)" );module_param_named (enable_execlists, i915.enable_execlists, int,0400 ); MODULE_PARM_DESC(enable_execlists,
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
v6 cover PPGTT dynamic page allocations and 48b addressing
In reply to Michel ThierryThis patchset addresses comments from v5 by Mika, specially some rename changes touched several patches.
For GEN8, it has also been extended to work in logical ring submission (lrc) mode, as it will be the preferred mode of operation.
I also tried to update the lrc code at the same time the ppgtt refactoring occurred, leaving only one patch that is exclusively for lrc.
I'm also now including the required patches for PPGTT with 48b addressing. In order expand the GPU address space, a 4th level translation is added, the Page Map Level 4 (PML4). This PML4 has 256 PML4 Entries (PML4E), PML4[0-255], each pointing to a PDP.
For now, this feature will only be available in BDW and GEN9, in LRC submission mode (execlists) and when i915.enable_ppgtt=3 is set.
Also note that this expanded address space is only available for full PPGTT, aliasing PPGTT remains 32b.
This list can be seen in 3 parts:
[01-10] Add page table allocation for GEN6/GEN7 [11-20] Enable dynamic allocation in GEN8,for both legacy and execlist submission modes.
[21-32] PML4 support in BDW and GEN9+.
Ben Widawsky (26):
drm/i915: page table abstractions
drm/i915: Complete page table structures
drm/i915: Create page table allocators
drm/i915: Track GEN6 page table usage
drm/i915: Extract context switch skip and pd load logic drm/i915: Track page table reload need
drm/i915: Initialize all contexts
drm/i915: Finish gen6/7 dynamic page table allocation drm/i915/bdw: Use dynamic allocation idioms on free drm/i915/bdw: page directories rework allocation drm/i915/bdw: pagetable allocation rework
drm/i915/bdw: Update pdp switch and point unused PDPs to scratch page drm/i915: num_pd_pages/num_pd_entries isn't useful drm/i915: Extract PPGTT param from page_directory alloc drm/i915/bdw: Split out mappings
drm/i915/bdw: begin bitmap tracking
drm/i915/bdw: Dynamic page table allocations
drm/i915/bdw: Make pdp allocation more dynamic drm/i915/bdw: Abstract PDP usage
drm/i915/bdw: Add dynamic page trace events
drm/i915/bdw: Add ppgtt info for dynamic pages drm/i915/bdw: implement alloc/free for 4lvl
drm/i915/bdw: Add 4 level switching infrastructure drm/i915/bdw: Generalize PTE writing for GEN8 PPGTT drm/i915: Plumb sg_iter through va allocation ->maps drm/i915: Expand error state's address width to 64b
Michel Thierry (6):
drm/i915: Plumb drm_device through page tables operations drm/i915: Add dynamic page trace events
drm/i915/bdw: Support dynamic pdp updates in lrc mode drm/i915/bdw: Support 64 bit PPGTT in lrc mode drm/i915/bdw: Add 4 level support in insert_entries and clear_range drm/i915/bdw: Flip the 48b switch
drivers/gpu/drm/i915/i915_debugfs.c | 26 +- drivers/gpu/drm/i915/i915_drv.h | 11 +- drivers/gpu/drm/i915/i915_gem.c | 11 + drivers/gpu/drm/i915/i915_gem_context.c | 64 +- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 11 + drivers/gpu/drm/i915/i915_gem_gtt.c | 1535 ++++++++++++++++++++++------ drivers/gpu/drm/i915/i915_gem_gtt.h | 248 ++++- drivers/gpu/drm/i915/i915_gpu_error.c | 17 +- drivers/gpu/drm/i915/i915_params.c | 2 +- drivers/gpu/drm/i915/i915_reg.h | 1 + drivers/gpu/drm/i915/i915_trace.h | 111 ++ drivers/gpu/drm/i915/intel_lrc.c | 149 ++- 12 files changed, 1787 insertions(+), 399 deletions(-)
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 1/32 drm/i915: page table abstractions
From: Ben Widawsky <[email protected]>
When we move to dynamic page allocation, keeping page_directory and pagetabs as separate structures will help to break actions into simpler tasks.
To help transition the code nicely there is some wasted space in gen6/7. This will be ameliorated shortly.
Following the x86 pagetable terminology:
PDPE = struct i915_page_directory_pointer_entry. PDE = struct i915_page_directory_entry [page_directory]. PTE = struct i915_page_table_entry [page_tables].
v2: fixed mismatches after clean-up/rebase.
v3: Clarify the names of the multiple levels of page tables (Daniel)
v4: Addressing Mika's review comments. s/gen8_free_page_directories/gen8_free_page_directory and free the page tables for the directory there.
In gen8_ppgtt_allocate_page_directories, do not leak previously allocated pt in case the page_directory alloc fails.
Update error return handling in gen8_ppgtt_alloc.
v5: Do not leak pt on error in gen6_ppgtt_allocate_page_tables. (Mika)
v6: s/page_tables/page_table/. (Mika)
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 180 +++++++++++++++++++----------------- drivers/gpu/drm/i915/i915_gem_gtt.h | 23 ++++- 2 files changed, 111 insertions(+), 92 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +93 -87
@@ -338,7 +338,8 @@ static void gen8_ppgtt_clear_range(struct i915_address_space *vm, I915_CACHE_LLC, use_scratch);while (num_entries) { -struct page *page_table = ppgtt->gen8_pt_pages[pdpe][pde]; +struct i915_page_directory_entry *pd = &ppgtt->pdp.page_directory[pdpe]; +struct page *page_table = pd->page_table[pde].page; last_pte = pte + num_entries;if (last_pte >GEN8_PTES_PER_PAGE )
@@ -382,8 +383,12 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm,if (WARN_ON (pdpe >=GEN8_LEGACY_PDPES ))break ; -if (pt_vaddr ==NULL ) - pt_vaddr =kmap_atomic (ppgtt->gen8_pt_pages[pdpe][pde]); +if (pt_vaddr ==NULL ) { +struct i915_page_directory_entry *pd = &ppgtt->pdp.page_directory[pdpe]; +struct page *page_table = pd->page_table[pde].page; + + pt_vaddr =kmap_atomic (page_table); + } pt_vaddr[pte] = gen8_pte_encode(sg_page_iter_dma_address(&sg_iter),
@@ -407,29 +412,33 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm, } } -static void gen8_free_page_tables (struct page **pt_pages) +static void gen8_free_page_tables (struct i915_page_directory_entry *pd) {int i; -if (pt_pages ==NULL ) +if (pd->page_table ==NULL )return ;for (i =0 ; i <GEN8_PDES_PER_PAGE ; i++) -if (pt_pages[i]) -__free_pages (pt_pages[i],0 ); +if (pd->page_table[i].page) +__free_page (pd->page_table[i].page); } -static void gen8_ppgtt_free (const struct i915_hw_ppgtt *ppgtt) +static void gen8_free_page_directory (struct i915_page_directory_entry *pd) +{ +gen8_free_page_tables (pd); +kfree (pd->page_table); +__free_page (pd->page); +} + +static void gen8_ppgtt_free (struct i915_hw_ppgtt *ppgtt) {int i;for (i =0 ; i < ppgtt->num_pd_pages; i++) { -gen8_free_page_tables (ppgtt->gen8_pt_pages[i]); -kfree (ppgtt->gen8_pt_pages[i]); +gen8_free_page_directory (&ppgtt->pdp.page_directory[i]);kfree (ppgtt->gen8_pt_dma_addr[i]); } - -__free_pages (ppgtt->pd_pages,get_order (ppgtt->num_pd_pages <<PAGE_SHIFT )); }static void gen8_ppgtt_unmap_pages (struct i915_hw_ppgtt *ppgtt)
@@ -464,86 +473,77 @@ static void gen8_ppgtt_cleanup(struct i915_address_space *vm)gen8_ppgtt_free (ppgtt); } -static struct page **__gen8_alloc_page_tables (void ) +static int gen8_ppgtt_allocate_dma (struct i915_hw_ppgtt *ppgtt) { -struct page **pt_pages;int i; - pt_pages =kcalloc (GEN8_PDES_PER_PAGE ,sizeof (struct page *),GFP_KERNEL ); -if (!pt_pages) -return ERR_PTR (-ENOMEM ); - -for (i =0 ; i <GEN8_PDES_PER_PAGE ; i++) { - pt_pages[i] =alloc_page (GFP_KERNEL ); -if (!pt_pages[i]) - goto bail; +for (i =0 ; i < ppgtt->num_pd_pages; i++) { + ppgtt->gen8_pt_dma_addr[i] =kcalloc (GEN8_PDES_PER_PAGE , +sizeof (dma_addr_t), +GFP_KERNEL ); +if (!ppgtt->gen8_pt_dma_addr[i]) +return -ENOMEM ; } -return pt_pages; - -bail: -gen8_free_page_tables (pt_pages); -kfree (pt_pages); -return ERR_PTR (-ENOMEM ); +return 0 ; } -static int gen8_ppgtt_allocate_page_tables (struct i915_hw_ppgtt *ppgtt, -const int max_pdp) +static int gen8_ppgtt_allocate_page_tables (struct i915_hw_ppgtt *ppgtt) { -struct page **pt_pages[GEN8_LEGACY_PDPES ]; -int i, ret; +int i, j; -for (i =0 ; i < max_pdp; i++) { - pt_pages[i] =__gen8_alloc_page_tables (); -if (IS_ERR (pt_pages[i])) { - ret =PTR_ERR (pt_pages[i]); - goto unwind_out; +for (i =0 ; i < ppgtt->num_pd_pages; i++) { +for (j =0 ; j <GEN8_PDES_PER_PAGE ; j++) { +struct i915_page_table_entry *pt = &ppgtt->pdp.page_directory[i].page_table[j]; + + pt->page =alloc_page (GFP_KERNEL | __GFP_ZERO); +if (!pt->page) + goto unwind_out; } } -/* NB: Avoid touching gen8_pt_pages until last to keep the allocation, -* "atomic" - for cleanup purposes. -*/ -for (i =0 ; i < max_pdp; i++) - ppgtt->gen8_pt_pages[i] = pt_pages[i]; -return 0 ; unwind_out: -while (i--) { -gen8_free_page_tables (pt_pages[i]); -kfree (pt_pages[i]); - } +while (i--) +gen8_free_page_tables (&ppgtt->pdp.page_directory[i]); -return ret; +return -ENOMEM ; } -static int gen8_ppgtt_allocate_dma (struct i915_hw_ppgtt *ppgtt) +static int gen8_ppgtt_allocate_page_directories (struct i915_hw_ppgtt *ppgtt, +const int max_pdp) {int i; -for (i =0 ; i < ppgtt->num_pd_pages; i++) { - ppgtt->gen8_pt_dma_addr[i] =kcalloc (GEN8_PDES_PER_PAGE , -sizeof (dma_addr_t), -GFP_KERNEL ); -if (!ppgtt->gen8_pt_dma_addr[i]) -return -ENOMEM ; - } +for (i =0 ; i < max_pdp; i++) { +struct i915_page_table_entry *pt; -return 0 ; -} + pt =kcalloc (GEN8_PDES_PER_PAGE ,sizeof (*pt),GFP_KERNEL ); +if (!pt) + goto unwind_out; -static int gen8_ppgtt_allocate_page_directories (struct i915_hw_ppgtt *ppgtt, -const int max_pdp) -{ - ppgtt->pd_pages =alloc_pages (GFP_KERNEL ,get_order (max_pdp <<PAGE_SHIFT )); -if (!ppgtt->pd_pages) -return -ENOMEM ; + ppgtt->pdp.page_directory[i].page =alloc_page (GFP_KERNEL ); +if (!ppgtt->pdp.page_directory[i].page) { +kfree (pt); + goto unwind_out; + } + + ppgtt->pdp.page_directory[i].page_table = pt; + } - ppgtt->num_pd_pages =1 <<get_order (max_pdp <<PAGE_SHIFT ); + ppgtt->num_pd_pages = max_pdp;BUG_ON (ppgtt->num_pd_pages >GEN8_LEGACY_PDPES );return 0 ; + +unwind_out: +while (i--) { +kfree (ppgtt->pdp.page_directory[i].page_table); +__free_page (ppgtt->pdp.page_directory[i].page); + } + +return -ENOMEM ; } static int gen8_ppgtt_alloc(struct i915_hw_ppgtt *ppgtt,
@@ -555,18 +555,20 @@ static int gen8_ppgtt_alloc(struct i915_hw_ppgtt *ppgtt,if (ret)return ret; - ret =gen8_ppgtt_allocate_page_tables (ppgtt, max_pdp); -if (ret) { -__free_pages (ppgtt->pd_pages,get_order (max_pdp <<PAGE_SHIFT )); -return ret; - } + ret =gen8_ppgtt_allocate_page_tables (ppgtt); +if (ret) + goto err_out; ppgtt->num_pd_entries = max_pdp *GEN8_PDES_PER_PAGE ; ret =gen8_ppgtt_allocate_dma (ppgtt);if (ret) -gen8_ppgtt_free (ppgtt); + goto err_out; + +return 0 ; +err_out: +gen8_ppgtt_free (ppgtt);return ret; }
@@ -577,7 +579,7 @@ static int gen8_ppgtt_setup_page_directories(struct i915_hw_ppgtt *ppgtt,int ret; pd_addr =pci_map_page (ppgtt->base.dev->pdev, - &ppgtt->pd_pages[pd],0 , + ppgtt->pdp.page_directory[pd].page,0 ,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL ); ret =pci_dma_mapping_error (ppgtt->base.dev->pdev, pd_addr);
@@ -597,7 +599,7 @@ static int gen8_ppgtt_setup_page_tables(struct i915_hw_ppgtt *ppgtt,struct page *p;int ret; - p = ppgtt->gen8_pt_pages[pd][pt]; + p = ppgtt->pdp.page_directory[pd].page_table[pt].page; pt_addr =pci_map_page (ppgtt->base.dev->pdev, p,0 ,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL ); ret =pci_dma_mapping_error (ppgtt->base.dev->pdev, pt_addr);
@@ -658,7 +660,7 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt, uint64_t size)*/ for (i =0 ; i < max_pdp; i++) {gen8_ppgtt_pde_t *pd_vaddr; - pd_vaddr =kmap_atomic (&ppgtt->pd_pages[i]); + pd_vaddr =kmap_atomic (ppgtt->pdp.page_directory[i].page);for (j =0 ; j <GEN8_PDES_PER_PAGE ; j++) {dma_addr_t addr = ppgtt->gen8_pt_dma_addr[i][j]; pd_vaddr[j] = gen8_pde_encode(ppgtt->base.dev, addr,
@@ -721,7 +723,7 @@ static void gen6_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m) expected);seq_printf (m,"\tPDE: %x\n" , pd_entry); - pt_vaddr =kmap_atomic (ppgtt->pt_pages[pde]); + pt_vaddr =kmap_atomic (ppgtt->pd.page_table[pde].page);for (pte =0 ; pte <I915_PPGTT_PT_ENTRIES ; pte+=4 ) {unsigned long va = (pde * PAGE_SIZE * I915_PPGTT_PT_ENTRIES) +
@@ -936,7 +938,7 @@ static void gen6_ppgtt_clear_range(struct i915_address_space *vm,if (last_pte >I915_PPGTT_PT_ENTRIES ) last_pte =I915_PPGTT_PT_ENTRIES ; - pt_vaddr =kmap_atomic (ppgtt->pt_pages[act_pt]); + pt_vaddr =kmap_atomic (ppgtt->pd.page_table[act_pt].page);for (i = first_pte; i < last_pte; i++) pt_vaddr[i] = scratch_pte;
@@ -965,7 +967,7 @@ static void gen6_ppgtt_insert_entries(struct i915_address_space *vm, pt_vaddr =NULL ;for_each_sg_page (pages->sgl, &sg_iter, pages->nents,0 ) {if (pt_vaddr ==NULL ) - pt_vaddr =kmap_atomic (ppgtt->pt_pages[act_pt]); + pt_vaddr =kmap_atomic (ppgtt->pd.page_table[act_pt].page); pt_vaddr[act_pte] = vm->pte_encode(sg_page_iter_dma_address(&sg_iter),
@@ -1000,8 +1002,9 @@ static void gen6_ppgtt_free(struct i915_hw_ppgtt *ppgtt)kfree (ppgtt->pt_dma_addr);for (i =0 ; i < ppgtt->num_pd_entries; i++) -__free_page (ppgtt->pt_pages[i]); -kfree (ppgtt->pt_pages); +if (ppgtt->pd.page_table[i].page) +__free_page (ppgtt->pd.page_table[i].page); +kfree (ppgtt->pd.page_table); }static void gen6_ppgtt_cleanup (struct i915_address_space *vm)
@@ -1058,17 +1061,18 @@ alloc:static int gen6_ppgtt_allocate_page_tables (struct i915_hw_ppgtt *ppgtt) { +struct i915_page_table_entry *pt;int i; - ppgtt->pt_pages =kcalloc (ppgtt->num_pd_entries,sizeof (struct page *), -GFP_KERNEL ); - -if (!ppgtt->pt_pages) + pt =kcalloc (ppgtt->num_pd_entries,sizeof (*pt),GFP_KERNEL ); +if (!pt)return -ENOMEM ; + ppgtt->pd.page_table = pt; +for (i =0 ; i < ppgtt->num_pd_entries; i++) { - ppgtt->pt_pages[i] =alloc_page (GFP_KERNEL ); -if (!ppgtt->pt_pages[i]) { + pt[i].page =alloc_page (GFP_KERNEL ); +if (!pt->page) {gen6_ppgtt_free (ppgtt);return -ENOMEM ; }
@@ -1108,9 +1112,11 @@ static int gen6_ppgtt_setup_page_tables(struct i915_hw_ppgtt *ppgtt)int i;for (i =0 ; i < ppgtt->num_pd_entries; i++) { +struct page *page;dma_addr_t pt_addr; - pt_addr =pci_map_page (dev->pdev, ppgtt->pt_pages[i],0 ,4096 , + page = ppgtt->pd.page_table[i].page; + pt_addr =pci_map_page (dev->pdev, page,0 ,4096 ,PCI_DMA_BIDIRECTIONAL );if (pci_dma_mapping_error (dev->pdev, pt_addr)) {
@@ -1157,7 +1163,7 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt) ppgtt->base.insert_entries = gen6_ppgtt_insert_entries; ppgtt->base.cleanup = gen6_ppgtt_cleanup; ppgtt->base.start =0 ; - ppgtt->base.total = ppgtt->num_pd_entries *I915_PPGTT_PT_ENTRIES *PAGE_SIZE ; + ppgtt->base.total = ppgtt->num_pd_entries *I915_PPGTT_PT_ENTRIES *PAGE_SIZE ; ppgtt->debug_dump = gen6_dump_ppgtt; ppgtt->pd_offset =
drivers/gpu/drm/i915/i915_gem_gtt.h +18 -5
@@ -187,6 +187,20 @@ struct i915_vma { u32 flags); }; +struct i915_page_table_entry { +struct page *page; +}; + +struct i915_page_directory_entry { +struct page *page;/* NULL for GEN6-GEN7 */ +struct i915_page_table_entry *page_table; +}; + +struct i915_page_directory_pointer_entry { +/* struct page *page; */ +struct i915_page_directory_entry page_directory[GEN8_LEGACY_PDPES ]; +}; +struct i915_address_space {struct drm_mm mm;struct drm_device *dev;
@@ -272,11 +286,6 @@ struct i915_hw_ppgtt {unsigned num_pd_entries;unsigned num_pd_pages;/* gen8+ */ union { -struct page **pt_pages; -struct page **gen8_pt_pages[GEN8_LEGACY_PDPES ]; - }; -struct page *pd_pages; -union {uint32_t pd_offset;dma_addr_t pd_dma_addr[GEN8_LEGACY_PDPES ]; };
@@ -284,6 +293,10 @@ struct i915_hw_ppgtt {dma_addr_t *pt_dma_addr;dma_addr_t *gen8_pt_dma_addr[GEN8_LEGACY_PDPES ]; }; +union { +struct i915_page_directory_pointer_entry pdp; +struct i915_page_directory_entry pd; + };struct drm_i915_file_private *file_priv;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 2/32 drm/i915: Complete page table structures
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
Move the remaining members over to the new page table structures.
This can be squashed with the previous commit if desire. The reasoning is the same as that patch. I simply felt it is easier to review if split.
v2: In lrc: s/ppgtt->pd_dma_addr[i]/ppgtt->pdp.page_directory[i].daddr/
v3: Rebase.
v4: Rebased after s/page_tables/page_table/.
--- drivers/gpu/drm/i915/i915_debugfs.c | 2 +- drivers/gpu/drm/i915/i915_gem_gtt.c | 85 +++++++++++++------------------------ drivers/gpu/drm/i915/i915_gem_gtt.h | 14 +++--- drivers/gpu/drm/i915/intel_lrc.c | 16 +++---- 4 files changed, 44 insertions(+), 73 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +1 -1
@@ -2185,7 +2185,7 @@ static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;seq_puts (m,"aliasing PPGTT:\n" ); -seq_printf (m,"pd gtt offset: 0x%08x\n" , ppgtt->pd_offset); +seq_printf (m,"pd gtt offset: 0x%08x\n" , ppgtt->pd.pd_offset); ppgtt->debug_dump (ppgtt, m); }
drivers/gpu/drm/i915/i915_gem_gtt.c +29 -56
220 lines not on this page · raw message
drivers/gpu/drm/i915/i915_gem_gtt.h +6 -8
@@ -189,10 +189,16 @@ struct i915_vma {struct i915_page_table_entry {struct page *page; +dma_addr_t daddr; };struct i915_page_directory_entry {struct page *page;/* NULL for GEN6-GEN7 */ +union { +uint32_t pd_offset; +dma_addr_t daddr; + }; +struct i915_page_table_entry *page_table; };
@@ -286,14 +292,6 @@ struct i915_hw_ppgtt {unsigned num_pd_entries;unsigned num_pd_pages;/* gen8+ */ union { -uint32_t pd_offset; -dma_addr_t pd_dma_addr[GEN8_LEGACY_PDPES ]; - }; -union { -dma_addr_t *pt_dma_addr; -dma_addr_t *gen8_pt_dma_addr[GEN8_LEGACY_PDPES ]; - }; -union {struct i915_page_directory_pointer_entry pdp;struct i915_page_directory_entry pd; };
drivers/gpu/drm/i915/intel_lrc.c +8 -8
@@ -1735,14 +1735,14 @@ populate_lr_context(struct intel_context *ctx, struct drm_i915_gem_object *ctx_o reg_state[CTX_PDP1_LDW ] =GEN8_RING_PDP_LDW (ring,1 ); reg_state[CTX_PDP0_UDW ] =GEN8_RING_PDP_UDW (ring,0 ); reg_state[CTX_PDP0_LDW ] =GEN8_RING_PDP_LDW (ring,0 ); - reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->pd_dma_addr[3 ]); - reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->pd_dma_addr[3 ]); - reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->pd_dma_addr[2 ]); - reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->pd_dma_addr[2 ]); - reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->pd_dma_addr[1 ]); - reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->pd_dma_addr[1 ]); - reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pd_dma_addr[0 ]); - reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pd_dma_addr[0 ]); + reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[3 ].daddr); + reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[3 ].daddr); + reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[2 ].daddr); + reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[2 ].daddr); + reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[1 ].daddr); + reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[1 ].daddr); + reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[0 ].daddr); + reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[0 ].daddr);if (ring->id ==RCS ) { reg_state[CTX_LRI_HEADER_2 ] =MI_LOAD_REGISTER_IMM (1 ); reg_state[CTX_R_PWR_CLK_STATE ] =0x20c8 ;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 3/32 drm/i915: Create page table allocators
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
As we move toward dynamic page table allocation, it becomes much easier to manage our data structures if break do things less coarsely by breaking up all of our actions into individual tasks. This makes the code easier to write, read, and verify.
Aside from the dissection of the allocation functions, the patch statically allocates the page table structures without a page directory. This remains the same for all platforms,
The patch itself should not have much functional difference. The primary noticeable difference is the fact that page tables are no longer allocated, but rather statically declared as part of the page directory. This has non-zero overhead, but things gain additional complexity as a result.
This patch exists for a few reasons:
1. Splitting out the functions allows easily combining GEN6 and GEN8 code. Page tables have no difference based on GEN8. As we'll see in a future patch when we add the DMA mappings to the allocations, it requires only one small change to make work, and error handling should just fall into place.
2. Unless we always want to allocate all page tables under a given PDE, we'll have to eventually break this up into an array of pointers (or pointer to pointer).
3. Having the discrete functions is easier to review, and understand. All allocations and frees now take place in just a couple of locations. Reviewing, and catching leaks should be easy.
4. Less important: the GFP flags are confined to one location, which makes playing around with such things trivial.
v2: Updated commit message to explain why this patch exists
v3: For lrc, s/pdp.page_directory[i].daddr/pdp.page_directory[i]->daddr/
v4: Renamed free_pt/pd_single functions to unmap_and_free_pt/pd (Daniel)
v5: Added additional safety checks in gen8 clear/free/unmap.
v6: Use WARN_ON and return -EINVAL in alloc_pt_range (Mika).
v7: Make err_out loop symmetrical to the way we allocate in alloc_pt_range. Also s/page_tables/page_table and correct commit message (Mika)
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 254 ++++++++++++++++++++++++------------ drivers/gpu/drm/i915/i915_gem_gtt.h | 4 +- drivers/gpu/drm/i915/intel_lrc.c | 16 +-- 3 files changed, 178 insertions(+), 96 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +168 -86
@@ -279,6 +279,98 @@ static gen6_gtt_pte_t iris_pte_encode(dma_addr_t addr,return pte; } +static void unmap_and_free_pt (struct i915_page_table_entry *pt) +{ +if (WARN_ON (!pt->page)) +return ; +__free_page (pt->page); +kfree (pt); +} + +static struct i915_page_table_entry *alloc_pt_single (void ) +{ +struct i915_page_table_entry *pt; + + pt =kzalloc (sizeof (*pt),GFP_KERNEL ); +if (!pt) +return ERR_PTR (-ENOMEM ); + + pt->page =alloc_page (GFP_KERNEL | __GFP_ZERO); +if (!pt->page) { +kfree (pt); +return ERR_PTR (-ENOMEM ); + } + +return pt; +} + +/** +* alloc_pt_range() - Allocate a multiple page tables +* @pd: The page directory which will have at least @count entries +* available to point to the allocated page tables. +* @pde: First page directory entry for which we are allocating. +* @count: Number of pages to allocate. +* +* Allocates multiple page table pages and sets the appropriate entries in the +* page table structure within the page directory. Function cleans up after +* itself on any failures. +* +* Return: 0 if allocation succeeded. +*/ +static int alloc_pt_range (struct i915_page_directory_entry *pd,uint16_t pde,size_t count) +{ +int i, ret; + +/* 512 is the max page tables per page_directory on any platform. */ +if (WARN_ON (pde + count >GEN6_PPGTT_PD_ENTRIES )) +return -EINVAL ; + +for (i = pde; i < pde + count; i++) { +struct i915_page_table_entry *pt =alloc_pt_single (); + +if (IS_ERR (pt)) { + ret =PTR_ERR (pt); + goto err_out; + } +WARN (pd->page_table[i], +"Leaking page directory entry %d (%pa)\n" , + i, pd->page_table[i]); + pd->page_table[i] = pt; + } + +return 0 ; + +err_out: +while (i-- > pde) +unmap_and_free_pt (pd->page_table[i]); +return ret; +} + +static void unmap_and_free_pd (struct i915_page_directory_entry *pd) +{ +if (pd->page) { +__free_page (pd->page); +kfree (pd); + } +} + +static struct i915_page_directory_entry *alloc_pd_single (void ) +{ +struct i915_page_directory_entry *pd; + + pd =kzalloc (sizeof (*pd),GFP_KERNEL ); +if (!pd) +return ERR_PTR (-ENOMEM ); + + pd->page =alloc_page (GFP_KERNEL | __GFP_ZERO); +if (!pd->page) { +kfree (pd); +return ERR_PTR (-ENOMEM ); + } + +return pd; +} +/* Broadwell Page Directory Pointer Descriptors */ static int gen8_write_pdp (struct intel_engine_cs *ring,unsigned entry,uint64_t val)
@@ -311,7 +403,7 @@ static int gen8_mm_switch(struct i915_hw_ppgtt *ppgtt,int used_pd = ppgtt->num_pd_entries /GEN8_PDES_PER_PAGE ;for (i = used_pd -1 ; i >=0 ; i--) { -dma_addr_t addr = ppgtt->pdp.page_directory[i].daddr; +dma_addr_t addr = ppgtt->pdp.page_directory[i]->daddr; ret =gen8_write_pdp (ring, i, addr);if (ret)return ret;
@@ -338,8 +430,24 @@ static void gen8_ppgtt_clear_range(struct i915_address_space *vm, I915_CACHE_LLC, use_scratch);while (num_entries) { -struct i915_page_directory_entry *pd = &ppgtt->pdp.page_directory[pdpe]; -struct page *page_table = pd->page_table[pde].page; +struct i915_page_directory_entry *pd; +struct i915_page_table_entry *pt; +struct page *page_table; + +if (WARN_ON (!ppgtt->pdp.page_directory[pdpe])) +continue ; + + pd = ppgtt->pdp.page_directory[pdpe]; + +if (WARN_ON (!pd->page_table[pde])) +continue ; + + pt = pd->page_table[pde]; + +if (WARN_ON (!pt->page)) +continue ; + + page_table = pt->page; last_pte = pte + num_entries;if (last_pte >GEN8_PTES_PER_PAGE )
@@ -384,8 +492,9 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm,break ;if (pt_vaddr ==NULL ) { -struct i915_page_directory_entry *pd = &ppgtt->pdp.page_directory[pdpe]; -struct page *page_table = pd->page_table[pde].page; +struct i915_page_directory_entry *pd = ppgtt->pdp.page_directory[pdpe]; +struct i915_page_table_entry *pt = pd->page_table[pde]; +struct page *page_table = pt->page; pt_vaddr =kmap_atomic (page_table); }
@@ -416,19 +525,16 @@ static void gen8_free_page_tables(struct i915_page_directory_entry *pd) {int i; -if (pd->page_table ==NULL ) +if (!pd->page)return ; -for (i =0 ; i <GEN8_PDES_PER_PAGE ; i++) -if (pd->page_table[i].page) -__free_page (pd->page_table[i].page); -} +for (i =0 ; i <GEN8_PDES_PER_PAGE ; i++) { +if (WARN_ON (!pd->page_table[i])) +continue ; -static void gen8_free_page_directory (struct i915_page_directory_entry *pd) -{ -gen8_free_page_tables (pd); -kfree (pd->page_table); -__free_page (pd->page); +unmap_and_free_pt (pd->page_table[i]); + pd->page_table[i] =NULL ; + } }static void gen8_ppgtt_free (struct i915_hw_ppgtt *ppgtt)
@@ -436,7 +542,11 @@ static void gen8_ppgtt_free(struct i915_hw_ppgtt *ppgtt)int i;for (i =0 ; i < ppgtt->num_pd_pages; i++) { -gen8_free_page_directory (&ppgtt->pdp.page_directory[i]); +if (WARN_ON (!ppgtt->pdp.page_directory[i])) +continue ; + +gen8_free_page_tables (ppgtt->pdp.page_directory[i]); +unmap_and_free_pd (ppgtt->pdp.page_directory[i]); } }
@@ -448,14 +558,23 @@ static void gen8_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt)for (i =0 ; i < ppgtt->num_pd_pages; i++) {/* TODO: In the future we'll support sparse mappings, so this * will have to change. */ -if (!ppgtt->pdp.page_directory[i].daddr) +if (!ppgtt->pdp.page_directory[i]->daddr)continue ; -pci_unmap_page (hwdev, ppgtt->pdp.page_directory[i].daddr,PAGE_SIZE , +pci_unmap_page (hwdev, ppgtt->pdp.page_directory[i]->daddr,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL );for (j =0 ; j <GEN8_PDES_PER_PAGE ; j++) { -dma_addr_t addr = ppgtt->pdp.page_directory[i].page_table[j].daddr; +struct i915_page_directory_entry *pd = ppgtt->pdp.page_directory[i]; +struct i915_page_table_entry *pt; +dma_addr_t addr; + +if (WARN_ON (!pd->page_table[j])) +continue ; + + pt = pd->page_table[j]; + addr = pt->daddr; +if (addr)pci_unmap_page (hwdev, addr,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL );
@@ -474,25 +593,20 @@ static void gen8_ppgtt_cleanup(struct i915_address_space *vm)static int gen8_ppgtt_allocate_page_tables (struct i915_hw_ppgtt *ppgtt) { -int i, j; +int i, ret;for (i =0 ; i < ppgtt->num_pd_pages; i++) { -struct i915_page_directory_entry *pd = &ppgtt->pdp.page_directory[i]; -for (j =0 ; j <GEN8_PDES_PER_PAGE ; j++) { -struct i915_page_table_entry *pt = &pd->page_table[j]; - - pt->page =alloc_page (GFP_KERNEL | __GFP_ZERO); -if (!pt->page) - goto unwind_out; - - } + ret =alloc_pt_range (ppgtt->pdp.page_directory[i], +0 ,GEN8_PDES_PER_PAGE ); +if (ret) + goto unwind_out; }return 0 ; unwind_out:while (i--) -gen8_free_page_tables (&ppgtt->pdp.page_directory[i]); +gen8_free_page_tables (ppgtt->pdp.page_directory[i]);return -ENOMEM ; }
@@ -503,19 +617,9 @@ static int gen8_ppgtt_allocate_page_directories(struct i915_hw_ppgtt *ppgtt,int i;for (i =0 ; i < max_pdp; i++) { -struct i915_page_table_entry *pt; - - pt =kcalloc (GEN8_PDES_PER_PAGE ,sizeof (*pt),GFP_KERNEL ); -if (!pt) - goto unwind_out; - - ppgtt->pdp.page_directory[i].page =alloc_page (GFP_KERNEL ); -if (!ppgtt->pdp.page_directory[i].page) { -kfree (pt); + ppgtt->pdp.page_directory[i] =alloc_pd_single (); +if (IS_ERR (ppgtt->pdp.page_directory[i])) goto unwind_out; - } - - ppgtt->pdp.page_directory[i].page_table = pt; } ppgtt->num_pd_pages = max_pdp;
@@ -524,10 +628,8 @@ static int gen8_ppgtt_allocate_page_directories(struct i915_hw_ppgtt *ppgtt,return 0 ; unwind_out: -while (i--) { -kfree (ppgtt->pdp.page_directory[i].page_table); -__free_page (ppgtt->pdp.page_directory[i].page); - } +while (i--) +unmap_and_free_pd (ppgtt->pdp.page_directory[i]);return -ENOMEM ; }
@@ -561,14 +663,14 @@ static int gen8_ppgtt_setup_page_directories(struct i915_hw_ppgtt *ppgtt,int ret; pd_addr =pci_map_page (ppgtt->base.dev->pdev, - ppgtt->pdp.page_directory[pd].page,0 , + ppgtt->pdp.page_directory[pd]->page,0 ,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL ); ret =pci_dma_mapping_error (ppgtt->base.dev->pdev, pd_addr);if (ret)return ret; - ppgtt->pdp.page_directory[pd].daddr = pd_addr; + ppgtt->pdp.page_directory[pd]->daddr = pd_addr;return 0 ; }
@@ -578,8 +680,8 @@ static int gen8_ppgtt_setup_page_tables(struct i915_hw_ppgtt *ppgtt, const int pt) {dma_addr_t pt_addr; -struct i915_page_directory_entry *pdir = &ppgtt->pdp.page_directory[pd]; -struct i915_page_table_entry *ptab = &pdir->page_table[pt]; +struct i915_page_directory_entry *pdir = ppgtt->pdp.page_directory[pd]; +struct i915_page_table_entry *ptab = pdir->page_table[pt];struct page *p = ptab->page;int ret;
@@ -642,10 +744,12 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt, uint64_t size)* will never need to touch the PDEs again. */ for (i =0 ; i < max_pdp; i++) { +struct i915_page_directory_entry *pd = ppgtt->pdp.page_directory[i];gen8_ppgtt_pde_t *pd_vaddr; - pd_vaddr =kmap_atomic (ppgtt->pdp.page_directory[i].page); + pd_vaddr =kmap_atomic (ppgtt->pdp.page_directory[i]->page);for (j =0 ; j <GEN8_PDES_PER_PAGE ; j++) { -dma_addr_t addr = ppgtt->pdp.page_directory[i].page_table[j].daddr; +struct i915_page_table_entry *pt = pd->page_table[j]; +dma_addr_t addr = pt->daddr; pd_vaddr[j] =gen8_pde_encode (ppgtt->base.dev, addr,I915_CACHE_LLC ); }
@@ -696,7 +800,7 @@ static void gen6_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m)for (pde =0 ; pde < ppgtt->num_pd_entries; pde++) {u32 expected;gen6_gtt_pte_t *pt_vaddr; -dma_addr_t pt_addr = ppgtt->pd.page_table[pde].daddr; +dma_addr_t pt_addr = ppgtt->pd.page_table[pde]->daddr; pd_entry =readl (pd_addr + pde); expected = (GEN6_PDE_ADDR_ENCODE (pt_addr) |GEN6_PDE_VALID );
@@ -707,7 +811,7 @@ static void gen6_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m) expected);seq_printf (m,"\tPDE: %x\n" , pd_entry); - pt_vaddr =kmap_atomic (ppgtt->pd.page_table[pde].page); + pt_vaddr =kmap_atomic (ppgtt->pd.page_table[pde]->page);for (pte =0 ; pte <I915_PPGTT_PT_ENTRIES ; pte+=4 ) {unsigned long va = (pde * PAGE_SIZE * I915_PPGTT_PT_ENTRIES) +
@@ -746,7 +850,7 @@ static void gen6_write_pdes(struct i915_hw_ppgtt *ppgtt)for (i =0 ; i < ppgtt->num_pd_entries; i++) {dma_addr_t pt_addr; - pt_addr = ppgtt->pd.page_table[i].daddr; + pt_addr = ppgtt->pd.page_table[i]->daddr; pd_entry =GEN6_PDE_ADDR_ENCODE (pt_addr); pd_entry |=GEN6_PDE_VALID ;
@@ -922,7 +1026,7 @@ static void gen6_ppgtt_clear_range(struct i915_address_space *vm,if (last_pte >I915_PPGTT_PT_ENTRIES ) last_pte =I915_PPGTT_PT_ENTRIES ; - pt_vaddr =kmap_atomic (ppgtt->pd.page_table[act_pt].page); + pt_vaddr =kmap_atomic (ppgtt->pd.page_table[act_pt]->page);for (i = first_pte; i < last_pte; i++) pt_vaddr[i] = scratch_pte;
@@ -951,7 +1055,7 @@ static void gen6_ppgtt_insert_entries(struct i915_address_space *vm, pt_vaddr =NULL ;for_each_sg_page (pages->sgl, &sg_iter, pages->nents,0 ) {if (pt_vaddr ==NULL ) - pt_vaddr =kmap_atomic (ppgtt->pd.page_table[act_pt].page); + pt_vaddr =kmap_atomic (ppgtt->pd.page_table[act_pt]->page); pt_vaddr[act_pte] = vm->pte_encode(sg_page_iter_dma_address(&sg_iter),
@@ -974,7 +1078,7 @@ static void gen6_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt)for (i =0 ; i < ppgtt->num_pd_entries; i++)pci_unmap_page (ppgtt->base.dev->pdev, - ppgtt->pd.page_table[i].daddr, + ppgtt->pd.page_table[i]->daddr,4096 ,PCI_DMA_BIDIRECTIONAL ); }
@@ -983,9 +1087,9 @@ static void gen6_ppgtt_free(struct i915_hw_ppgtt *ppgtt)int i;for (i =0 ; i < ppgtt->num_pd_entries; i++) -if (ppgtt->pd.page_table[i].page) -__free_page (ppgtt->pd.page_table[i].page); -kfree (ppgtt->pd.page_table); +unmap_and_free_pt (ppgtt->pd.page_table[i]); + +unmap_and_free_pd (&ppgtt->pd); }static void gen6_ppgtt_cleanup (struct i915_address_space *vm)
@@ -1040,28 +1144,6 @@ alloc:return 0 ; } -static int gen6_ppgtt_allocate_page_tables (struct i915_hw_ppgtt *ppgtt) -{ -struct i915_page_table_entry *pt; -int i; - - pt =kcalloc (ppgtt->num_pd_entries,sizeof (*pt),GFP_KERNEL ); -if (!pt) -return -ENOMEM ; - - ppgtt->pd.page_table = pt; - -for (i =0 ; i < ppgtt->num_pd_entries; i++) { - pt[i].page =alloc_page (GFP_KERNEL ); -if (!pt->page) { -gen6_ppgtt_free (ppgtt); -return -ENOMEM ; - } - } - -return 0 ; -} -static int gen6_ppgtt_alloc (struct i915_hw_ppgtt *ppgtt) {int ret;
@@ -1070,7 +1152,7 @@ static int gen6_ppgtt_alloc(struct i915_hw_ppgtt *ppgtt)if (ret)return ret; - ret =gen6_ppgtt_allocate_page_tables (ppgtt); + ret =alloc_pt_range (&ppgtt->pd,0 , ppgtt->num_pd_entries);if (ret) {drm_mm_remove_node (&ppgtt->node);return ret;
@@ -1088,7 +1170,7 @@ static int gen6_ppgtt_setup_page_tables(struct i915_hw_ppgtt *ppgtt)struct page *page;dma_addr_t pt_addr; - page = ppgtt->pd.page_table[i].page; + page = ppgtt->pd.page_table[i]->page; pt_addr =pci_map_page (dev->pdev, page,0 ,4096 ,PCI_DMA_BIDIRECTIONAL );
@@ -1097,7 +1179,7 @@ static int gen6_ppgtt_setup_page_tables(struct i915_hw_ppgtt *ppgtt)return -EIO ; } - ppgtt->pd.page_table[i].daddr = pt_addr; + ppgtt->pd.page_table[i]->daddr = pt_addr; }return 0 ;
drivers/gpu/drm/i915/i915_gem_gtt.h +2 -2
@@ -199,12 +199,12 @@ struct i915_page_directory_entry {dma_addr_t daddr; }; -struct i915_page_table_entry *page_table; +struct i915_page_table_entry *page_table[GEN6_PPGTT_PD_ENTRIES ];/* PDEs */ };struct i915_page_directory_pointer_entry {/* struct page *page; */ -struct i915_page_directory_entry page_directory[GEN8_LEGACY_PDPES ]; +struct i915_page_directory_entry *page_directory[GEN8_LEGACY_PDPES ]; };struct i915_address_space {
drivers/gpu/drm/i915/intel_lrc.c +8 -8
@@ -1735,14 +1735,14 @@ populate_lr_context(struct intel_context *ctx, struct drm_i915_gem_object *ctx_o reg_state[CTX_PDP1_LDW ] =GEN8_RING_PDP_LDW (ring,1 ); reg_state[CTX_PDP0_UDW ] =GEN8_RING_PDP_UDW (ring,0 ); reg_state[CTX_PDP0_LDW ] =GEN8_RING_PDP_LDW (ring,0 ); - reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[3 ].daddr); - reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[3 ].daddr); - reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[2 ].daddr); - reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[2 ].daddr); - reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[1 ].daddr); - reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[1 ].daddr); - reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[0 ].daddr); - reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[0 ].daddr); + reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[0 ]->daddr);if (ring->id ==RCS ) { reg_state[CTX_LRI_HEADER_2 ] =MI_LOAD_REGISTER_IMM (1 ); reg_state[CTX_R_PWR_CLK_STATE ] =0x20c8 ;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v6 03/32] drm/i915: Create page table allocators
Quoted 45 lines · Michel Thierry
From: Ben Widawsky <[email protected]>
As we move toward dynamic page table allocation, it becomes much easier to manage our data structures if break do things less coarsely by breaking up all of our actions into individual tasks. This makes the code easier to write, read, and verify.
Aside from the dissection of the allocation functions, the patch statically allocates the page table structures without a page directory. This remains the same for all platforms,
The patch itself should not have much functional difference. The primary noticeable difference is the fact that page tables are no longer allocated, but rather statically declared as part of the page directory. This has non-zero overhead, but things gain additional complexity as a result.
This patch exists for a few reasons:
1. Splitting out the functions allows easily combining GEN6 and GEN8 code. Page tables have no difference based on GEN8. As we'll see in a future patch when we add the DMA mappings to the allocations, it requires only one small change to make work, and error handling should just fall into place.2. Unless we always want to allocate all page tables under a given PDE, we'll have to eventually break this up into an array of pointers (or pointer to pointer).
3. Having the discrete functions is easier to review, and understand. All allocations and frees now take place in just a couple of locations. Reviewing, and catching leaks should be easy.
4. Less important: the GFP flags are confined to one location, which makes playing around with such things trivial.
v2: Updated commit message to explain why this patch exists
v3: For lrc, s/pdp.page_directory[i].daddr/pdp.page_directory[i]->daddr/
v4: Renamed free_pt/pd_single functions to unmap_and_free_pt/pd (Daniel)
v5: Added additional safety checks in gen8 clear/free/unmap.
v6: Use
WARN_ONand return-EINVALinalloc_pt_range(Mika).
Quoted 7 lines
v7: Make
err_outloop symmetrical to the way we allocate inalloc_pt_range. Also s/page_tables/page_table and correct commit message (Mika)Cc Mika Kuoppala <[email protected]>Signed-off-by Ben Widawsky <[email protected]>Signed-off-by Michel Thierry <[email protected]> (v3+)
Quoted 510 lines
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 254 ++++++++++++++++++++++++------------ drivers/gpu/drm/i915/i915_gem_gtt.h | 4 +- drivers/gpu/drm/i915/intel_lrc.c | 16 +-- 3 files changed, 178 insertions(+), 96 deletions(-)drivers/gpu/drm/i915/i915_gem_gtt.c +168
-86@@ -279,6 +279,98 @@ static gen6_gtt_pte_t iris_pte_encode(dma_addr_t addr,return pte; } +static void unmap_and_free_pt (struct i915_page_table_entry *pt) +{ +if (WARN_ON (!pt->page)) +return ; +__free_page (pt->page); +kfree (pt); +} + +static struct i915_page_table_entry *alloc_pt_single (void ) +{ +struct i915_page_table_entry *pt; + + pt =kzalloc (sizeof (*pt),GFP_KERNEL ); +if (!pt) +return ERR_PTR (-ENOMEM ); + + pt->page =alloc_page (GFP_KERNEL | __GFP_ZERO); +if (!pt->page) { +kfree (pt); +return ERR_PTR (-ENOMEM ); + } + +return pt; +} + +/** +* alloc_pt_range() - Allocate a multiple page tables +* @pd: The page directory which will have at least @count entries +* available to point to the allocated page tables. +* @pde: First page directory entry for which we are allocating. +* @count: Number of pages to allocate. +* +* Allocates multiple page table pages and sets the appropriate entries in the +* page table structure within the page directory. Function cleans up after +* itself on any failures. +* +* Return: 0 if allocation succeeded. +*/ +static int alloc_pt_range (struct i915_page_directory_entry *pd,uint16_t pde,size_t count) +{ +int i, ret; + +/* 512 is the max page tables per page_directory on any platform. */ +if (WARN_ON (pde + count >GEN6_PPGTT_PD_ENTRIES )) +return -EINVAL ; + +for (i = pde; i < pde + count; i++) { +struct i915_page_table_entry *pt =alloc_pt_single (); + +if (IS_ERR (pt)) { + ret =PTR_ERR (pt); + goto err_out; + } +WARN (pd->page_table[i], +"Leaking page directory entry %d (%pa)\n" , + i, pd->page_table[i]); + pd->page_table[i] = pt; + } + +return 0 ; + +err_out: +while (i-- > pde) +unmap_and_free_pt (pd->page_table[i]); +return ret; +} + +static void unmap_and_free_pd (struct i915_page_directory_entry *pd) +{ +if (pd->page) { +__free_page (pd->page); +kfree (pd); + } +} + +static struct i915_page_directory_entry *alloc_pd_single (void ) +{ +struct i915_page_directory_entry *pd; + + pd =kzalloc (sizeof (*pd),GFP_KERNEL ); +if (!pd) +return ERR_PTR (-ENOMEM ); + + pd->page =alloc_page (GFP_KERNEL | __GFP_ZERO); +if (!pd->page) { +kfree (pd); +return ERR_PTR (-ENOMEM ); + } + +return pd; +} +/* Broadwell Page Directory Pointer Descriptors */ static int gen8_write_pdp (struct intel_engine_cs *ring,unsigned entry,uint64_t val)@@ -311,7 +403,7 @@ static int gen8_mm_switch(struct i915_hw_ppgtt *ppgtt,int used_pd = ppgtt->num_pd_entries /GEN8_PDES_PER_PAGE ;for (i = used_pd -1 ; i >=0 ; i--) { -dma_addr_t addr = ppgtt->pdp.page_directory[i].daddr; +dma_addr_t addr = ppgtt->pdp.page_directory[i]->daddr; ret =gen8_write_pdp (ring, i, addr);if (ret)return ret;@@ -338,8 +430,24 @@ static void gen8_ppgtt_clear_range(struct i915_address_space *vm, I915_CACHE_LLC, use_scratch);while (num_entries) { -struct i915_page_directory_entry *pd = &ppgtt->pdp.page_directory[pdpe]; -struct page *page_table = pd->page_table[pde].page; +struct i915_page_directory_entry *pd; +struct i915_page_table_entry *pt; +struct page *page_table; + +if (WARN_ON (!ppgtt->pdp.page_directory[pdpe])) +continue ; + + pd = ppgtt->pdp.page_directory[pdpe]; + +if (WARN_ON (!pd->page_table[pde])) +continue ; + + pt = pd->page_table[pde]; + +if (WARN_ON (!pt->page)) +continue ; + + page_table = pt->page; last_pte = pte + num_entries;if (last_pte >GEN8_PTES_PER_PAGE )@@ -384,8 +492,9 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm,break ;if (pt_vaddr ==NULL ) { -struct i915_page_directory_entry *pd = &ppgtt->pdp.page_directory[pdpe]; -struct page *page_table = pd->page_table[pde].page; +struct i915_page_directory_entry *pd = ppgtt->pdp.page_directory[pdpe]; +struct i915_page_table_entry *pt = pd->page_table[pde]; +struct page *page_table = pt->page; pt_vaddr =kmap_atomic (page_table); }@@ -416,19 +525,16 @@ static void gen8_free_page_tables(struct i915_page_directory_entry *pd) {int i; -if (pd->page_table ==NULL ) +if (!pd->page)return ; -for (i =0 ; i <GEN8_PDES_PER_PAGE ; i++) -if (pd->page_table[i].page) -__free_page (pd->page_table[i].page); -} +for (i =0 ; i <GEN8_PDES_PER_PAGE ; i++) { +if (WARN_ON (!pd->page_table[i])) +continue ; -static void gen8_free_page_directory (struct i915_page_directory_entry *pd) -{ -gen8_free_page_tables (pd); -kfree (pd->page_table); -__free_page (pd->page); +unmap_and_free_pt (pd->page_table[i]); + pd->page_table[i] =NULL ; + } }static void gen8_ppgtt_free (struct i915_hw_ppgtt *ppgtt)@@ -436,7 +542,11 @@ static void gen8_ppgtt_free(struct i915_hw_ppgtt *ppgtt)int i;for (i =0 ; i < ppgtt->num_pd_pages; i++) { -gen8_free_page_directory (&ppgtt->pdp.page_directory[i]); +if (WARN_ON (!ppgtt->pdp.page_directory[i])) +continue ; + +gen8_free_page_tables (ppgtt->pdp.page_directory[i]); +unmap_and_free_pd (ppgtt->pdp.page_directory[i]); } }@@ -448,14 +558,23 @@ static void gen8_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt)for (i =0 ; i < ppgtt->num_pd_pages; i++) {/* TODO: In the future we'll support sparse mappings, so this * will have to change. */ -if (!ppgtt->pdp.page_directory[i].daddr) +if (!ppgtt->pdp.page_directory[i]->daddr)continue ; -pci_unmap_page (hwdev, ppgtt->pdp.page_directory[i].daddr,PAGE_SIZE , +pci_unmap_page (hwdev, ppgtt->pdp.page_directory[i]->daddr,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL );for (j =0 ; j <GEN8_PDES_PER_PAGE ; j++) { -dma_addr_t addr = ppgtt->pdp.page_directory[i].page_table[j].daddr; +struct i915_page_directory_entry *pd = ppgtt->pdp.page_directory[i]; +struct i915_page_table_entry *pt; +dma_addr_t addr; + +if (WARN_ON (!pd->page_table[j])) +continue ; + + pt = pd->page_table[j]; + addr = pt->daddr; +if (addr)pci_unmap_page (hwdev, addr,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL );@@ -474,25 +593,20 @@ static void gen8_ppgtt_cleanup(struct i915_address_space *vm)static int gen8_ppgtt_allocate_page_tables (struct i915_hw_ppgtt *ppgtt) { -int i, j; +int i, ret;for (i =0 ; i < ppgtt->num_pd_pages; i++) { -struct i915_page_directory_entry *pd = &ppgtt->pdp.page_directory[i]; -for (j =0 ; j <GEN8_PDES_PER_PAGE ; j++) { -struct i915_page_table_entry *pt = &pd->page_table[j]; - - pt->page =alloc_page (GFP_KERNEL | __GFP_ZERO); -if (!pt->page) - goto unwind_out; - - } + ret =alloc_pt_range (ppgtt->pdp.page_directory[i], +0 ,GEN8_PDES_PER_PAGE ); +if (ret) + goto unwind_out; }return 0 ; unwind_out:while (i--) -gen8_free_page_tables (&ppgtt->pdp.page_directory[i]); +gen8_free_page_tables (ppgtt->pdp.page_directory[i]);return -ENOMEM ; }@@ -503,19 +617,9 @@ static int gen8_ppgtt_allocate_page_directories(struct i915_hw_ppgtt *ppgtt,int i;for (i =0 ; i < max_pdp; i++) { -struct i915_page_table_entry *pt; - - pt =kcalloc (GEN8_PDES_PER_PAGE ,sizeof (*pt),GFP_KERNEL ); -if (!pt) - goto unwind_out; - - ppgtt->pdp.page_directory[i].page =alloc_page (GFP_KERNEL ); -if (!ppgtt->pdp.page_directory[i].page) { -kfree (pt); + ppgtt->pdp.page_directory[i] =alloc_pd_single (); +if (IS_ERR (ppgtt->pdp.page_directory[i])) goto unwind_out; - } - - ppgtt->pdp.page_directory[i].page_table = pt; } ppgtt->num_pd_pages = max_pdp;@@ -524,10 +628,8 @@ static int gen8_ppgtt_allocate_page_directories(struct i915_hw_ppgtt *ppgtt,return 0 ; unwind_out: -while (i--) { -kfree (ppgtt->pdp.page_directory[i].page_table); -__free_page (ppgtt->pdp.page_directory[i].page); - } +while (i--) +unmap_and_free_pd (ppgtt->pdp.page_directory[i]);return -ENOMEM ; }@@ -561,14 +663,14 @@ static int gen8_ppgtt_setup_page_directories(struct i915_hw_ppgtt *ppgtt,int ret; pd_addr =pci_map_page (ppgtt->base.dev->pdev, - ppgtt->pdp.page_directory[pd].page,0 , + ppgtt->pdp.page_directory[pd]->page,0 ,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL ); ret =pci_dma_mapping_error (ppgtt->base.dev->pdev, pd_addr);if (ret)return ret; - ppgtt->pdp.page_directory[pd].daddr = pd_addr; + ppgtt->pdp.page_directory[pd]->daddr = pd_addr;return 0 ; }@@ -578,8 +680,8 @@ static int gen8_ppgtt_setup_page_tables(struct i915_hw_ppgtt *ppgtt, const int pt) {dma_addr_t pt_addr; -struct i915_page_directory_entry *pdir = &ppgtt->pdp.page_directory[pd]; -struct i915_page_table_entry *ptab = &pdir->page_table[pt]; +struct i915_page_directory_entry *pdir = ppgtt->pdp.page_directory[pd]; +struct i915_page_table_entry *ptab = pdir->page_table[pt];struct page *p = ptab->page;int ret;@@ -642,10 +744,12 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt, uint64_t size)* will never need to touch the PDEs again. */ for (i =0 ; i < max_pdp; i++) { +struct i915_page_directory_entry *pd = ppgtt->pdp.page_directory[i];gen8_ppgtt_pde_t *pd_vaddr; - pd_vaddr =kmap_atomic (ppgtt->pdp.page_directory[i].page); + pd_vaddr =kmap_atomic (ppgtt->pdp.page_directory[i]->page);for (j =0 ; j <GEN8_PDES_PER_PAGE ; j++) { -dma_addr_t addr = ppgtt->pdp.page_directory[i].page_table[j].daddr; +struct i915_page_table_entry *pt = pd->page_table[j]; +dma_addr_t addr = pt->daddr; pd_vaddr[j] =gen8_pde_encode (ppgtt->base.dev, addr,I915_CACHE_LLC ); }@@ -696,7 +800,7 @@ static void gen6_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m)for (pde =0 ; pde < ppgtt->num_pd_entries; pde++) {u32 expected;gen6_gtt_pte_t *pt_vaddr; -dma_addr_t pt_addr = ppgtt->pd.page_table[pde].daddr; +dma_addr_t pt_addr = ppgtt->pd.page_table[pde]->daddr; pd_entry =readl (pd_addr + pde); expected = (GEN6_PDE_ADDR_ENCODE (pt_addr) |GEN6_PDE_VALID );@@ -707,7 +811,7 @@ static void gen6_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m) expected);seq_printf (m,"\tPDE: %x\n" , pd_entry); - pt_vaddr =kmap_atomic (ppgtt->pd.page_table[pde].page); + pt_vaddr =kmap_atomic (ppgtt->pd.page_table[pde]->page);for (pte =0 ; pte <I915_PPGTT_PT_ENTRIES ; pte+=4 ) {unsigned long va = (pde * PAGE_SIZE * I915_PPGTT_PT_ENTRIES) +@@ -746,7 +850,7 @@ static void gen6_write_pdes(struct i915_hw_ppgtt *ppgtt)for (i =0 ; i < ppgtt->num_pd_entries; i++) {dma_addr_t pt_addr; - pt_addr = ppgtt->pd.page_table[i].daddr; + pt_addr = ppgtt->pd.page_table[i]->daddr; pd_entry =GEN6_PDE_ADDR_ENCODE (pt_addr); pd_entry |=GEN6_PDE_VALID ;@@ -922,7 +1026,7 @@ static void gen6_ppgtt_clear_range(struct i915_address_space *vm,if (last_pte >I915_PPGTT_PT_ENTRIES ) last_pte =I915_PPGTT_PT_ENTRIES ; - pt_vaddr =kmap_atomic (ppgtt->pd.page_table[act_pt].page); + pt_vaddr =kmap_atomic (ppgtt->pd.page_table[act_pt]->page);for (i = first_pte; i < last_pte; i++) pt_vaddr[i] = scratch_pte;@@ -951,7 +1055,7 @@ static void gen6_ppgtt_insert_entries(struct i915_address_space *vm, pt_vaddr =NULL ;for_each_sg_page (pages->sgl, &sg_iter, pages->nents,0 ) {if (pt_vaddr ==NULL ) - pt_vaddr =kmap_atomic (ppgtt->pd.page_table[act_pt].page); + pt_vaddr =kmap_atomic (ppgtt->pd.page_table[act_pt]->page); pt_vaddr[act_pte] = vm->pte_encode(sg_page_iter_dma_address(&sg_iter),@@ -974,7 +1078,7 @@ static void gen6_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt)for (i =0 ; i < ppgtt->num_pd_entries; i++)pci_unmap_page (ppgtt->base.dev->pdev, - ppgtt->pd.page_table[i].daddr, + ppgtt->pd.page_table[i]->daddr,4096 ,PCI_DMA_BIDIRECTIONAL ); }@@ -983,9 +1087,9 @@ static void gen6_ppgtt_free(struct i915_hw_ppgtt *ppgtt)int i;for (i =0 ; i < ppgtt->num_pd_entries; i++) -if (ppgtt->pd.page_table[i].page) -__free_page (ppgtt->pd.page_table[i].page); -kfree (ppgtt->pd.page_table); +unmap_and_free_pt (ppgtt->pd.page_table[i]); + +unmap_and_free_pd (&ppgtt->pd); }static void gen6_ppgtt_cleanup (struct i915_address_space *vm)@@ -1040,28 +1144,6 @@ alloc:return 0 ; } -static int gen6_ppgtt_allocate_page_tables (struct i915_hw_ppgtt *ppgtt) -{ -struct i915_page_table_entry *pt; -int i; - - pt =kcalloc (ppgtt->num_pd_entries,sizeof (*pt),GFP_KERNEL ); -if (!pt) -return -ENOMEM ; - - ppgtt->pd.page_table = pt; - -for (i =0 ; i < ppgtt->num_pd_entries; i++) { - pt[i].page =alloc_page (GFP_KERNEL ); -if (!pt->page) { -gen6_ppgtt_free (ppgtt); -return -ENOMEM ; - } - } - -return 0 ; -} -static int gen6_ppgtt_alloc (struct i915_hw_ppgtt *ppgtt) {int ret;@@ -1070,7 +1152,7 @@ static int gen6_ppgtt_alloc(struct i915_hw_ppgtt *ppgtt)if (ret)return ret; - ret =gen6_ppgtt_allocate_page_tables (ppgtt); + ret =alloc_pt_range (&ppgtt->pd,0 , ppgtt->num_pd_entries);if (ret) {drm_mm_remove_node (&ppgtt->node);return ret;@@ -1088,7 +1170,7 @@ static int gen6_ppgtt_setup_page_tables(struct i915_hw_ppgtt *ppgtt)struct page *page;dma_addr_t pt_addr; - page = ppgtt->pd.page_table[i].page; + page = ppgtt->pd.page_table[i]->page; pt_addr =pci_map_page (dev->pdev, page,0 ,4096 ,PCI_DMA_BIDIRECTIONAL );@@ -1097,7 +1179,7 @@ static int gen6_ppgtt_setup_page_tables(struct i915_hw_ppgtt *ppgtt)return -EIO ; } - ppgtt->pd.page_table[i].daddr = pt_addr; + ppgtt->pd.page_table[i]->daddr = pt_addr; }return 0 ;drivers/gpu/drm/i915/i915_gem_gtt.h +2
-2@@ -199,12 +199,12 @@ struct i915_page_directory_entry {dma_addr_t daddr; }; -struct i915_page_table_entry *page_table; +struct i915_page_table_entry *page_table[GEN6_PPGTT_PD_ENTRIES ];/* PDEs */ };struct i915_page_directory_pointer_entry {/* struct page *page; */ -struct i915_page_directory_entry page_directory[GEN8_LEGACY_PDPES ]; +struct i915_page_directory_entry *page_directory[GEN8_LEGACY_PDPES ]; };struct i915_address_space {drivers/gpu/drm/i915/intel_lrc.c +8
-8@@ -1735,14 +1735,14 @@ populate_lr_context(struct intel_context *ctx, struct drm_i915_gem_object *ctx_o reg_state[CTX_PDP1_LDW ] =GEN8_RING_PDP_LDW (ring,1 ); reg_state[CTX_PDP0_UDW ] =GEN8_RING_PDP_UDW (ring,0 ); reg_state[CTX_PDP0_LDW ] =GEN8_RING_PDP_LDW (ring,0 ); - reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[3 ].daddr); - reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[3 ].daddr); - reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[2 ].daddr); - reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[2 ].daddr); - reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[1 ].daddr); - reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[1 ].daddr); - reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[0 ].daddr); - reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[0 ].daddr); + reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[0 ]->daddr);if (ring->id ==RCS ) { reg_state[CTX_LRI_HEADER_2 ] =MI_LOAD_REGISTER_IMM (1 ); reg_state[CTX_R_PWR_CLK_STATE ] =0x20c8 ;Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v6 03/32] drm/i915: Create page table allocators
2015-02-25 10:34 GMT-03:00 Mika Kuoppala <[email protected]>:
Quoted 8 lines
Quoted 6 lines · Michel Thierry
From: Ben Widawsky <[email protected]>
As we move toward dynamic page table allocation, it becomes much easier to manage our data structures if break do things less coarsely by breaking up all of our actions into individual tasks. This makes the code easier to write, read, and verify.
QA reported a regression caused by this patch. BSW doesn't boot anymore.
https://bugs.freedesktop.org/show_bug.cgi?id=89350
Quoted 563 lines
Quoted 39 lines
Aside from the dissection of the allocation functions, the patch statically allocates the page table structures without a page directory. This remains the same for all platforms,
The patch itself should not have much functional difference. The primary noticeable difference is the fact that page tables are no longer allocated, but rather statically declared as part of the page directory. This has non-zero overhead, but things gain additional complexity as a result.
This patch exists for a few reasons:
1. Splitting out the functions allows easily combining GEN6 and GEN8 code. Page tables have no difference based on GEN8. As we'll see in a future patch when we add the DMA mappings to the allocations, it requires only one small change to make work, and error handling should just fall into place.2. Unless we always want to allocate all page tables under a given PDE, we'll have to eventually break this up into an array of pointers (or pointer to pointer).
3. Having the discrete functions is easier to review, and understand. All allocations and frees now take place in just a couple of locations. Reviewing, and catching leaks should be easy.
4. Less important: the GFP flags are confined to one location, which makes playing around with such things trivial.
v2: Updated commit message to explain why this patch exists
v3: For lrc, s/pdp.page_directory[i].daddr/pdp.page_directory[i]->daddr/
v4: Renamed free_pt/pd_single functions to unmap_and_free_pt/pd (Daniel)
v5: Added additional safety checks in gen8 clear/free/unmap.
v6: Use
WARN_ONand return-EINVALinalloc_pt_range(Mika).Quoted 7 lines
v7: Make
err_outloop symmetrical to the way we allocate inalloc_pt_range. Also s/page_tables/page_table and correct commit message (Mika)Cc Mika Kuoppala <[email protected]>Signed-off-by Ben Widawsky <[email protected]>Signed-off-by Michel Thierry <[email protected]> (v3+)Reviewed-by Mika Kuoppala <[email protected]>Quoted 506 lines
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 254 ++++++++++++++++++++++++------------ drivers/gpu/drm/i915/i915_gem_gtt.h | 4 +- drivers/gpu/drm/i915/intel_lrc.c | 16 +-- 3 files changed, 178 insertions(+), 96 deletions(-)drivers/gpu/drm/i915/i915_gem_gtt.c +168
-86@@ -279,6 +279,98 @@ static gen6_gtt_pte_t iris_pte_encode(dma_addr_t addr,return pte; } +static void unmap_and_free_pt (struct i915_page_table_entry *pt) +{ +if (WARN_ON (!pt->page)) +return ; +__free_page (pt->page); +kfree (pt); +} + +static struct i915_page_table_entry *alloc_pt_single (void ) +{ +struct i915_page_table_entry *pt; + + pt =kzalloc (sizeof (*pt),GFP_KERNEL ); +if (!pt) +return ERR_PTR (-ENOMEM ); + + pt->page =alloc_page (GFP_KERNEL | __GFP_ZERO); +if (!pt->page) { +kfree (pt); +return ERR_PTR (-ENOMEM ); + } + +return pt; +} + +/** +* alloc_pt_range() - Allocate a multiple page tables +* @pd: The page directory which will have at least @count entries +* available to point to the allocated page tables. +* @pde: First page directory entry for which we are allocating. +* @count: Number of pages to allocate. +* +* Allocates multiple page table pages and sets the appropriate entries in the +* page table structure within the page directory. Function cleans up after +* itself on any failures. +* +* Return: 0 if allocation succeeded. +*/ +static int alloc_pt_range (struct i915_page_directory_entry *pd,uint16_t pde,size_t count) +{ +int i, ret; + +/* 512 is the max page tables per page_directory on any platform. */ +if (WARN_ON (pde + count >GEN6_PPGTT_PD_ENTRIES )) +return -EINVAL ; + +for (i = pde; i < pde + count; i++) { +struct i915_page_table_entry *pt =alloc_pt_single (); + +if (IS_ERR (pt)) { + ret =PTR_ERR (pt); + goto err_out; + } +WARN (pd->page_table[i], +"Leaking page directory entry %d (%pa)\n" , + i, pd->page_table[i]); + pd->page_table[i] = pt; + } + +return 0 ; + +err_out: +while (i-- > pde) +unmap_and_free_pt (pd->page_table[i]); +return ret; +} + +static void unmap_and_free_pd (struct i915_page_directory_entry *pd) +{ +if (pd->page) { +__free_page (pd->page); +kfree (pd); + } +} + +static struct i915_page_directory_entry *alloc_pd_single (void ) +{ +struct i915_page_directory_entry *pd; + + pd =kzalloc (sizeof (*pd),GFP_KERNEL ); +if (!pd) +return ERR_PTR (-ENOMEM ); + + pd->page =alloc_page (GFP_KERNEL | __GFP_ZERO); +if (!pd->page) { +kfree (pd); +return ERR_PTR (-ENOMEM ); + } + +return pd; +} +/* Broadwell Page Directory Pointer Descriptors */ static int gen8_write_pdp (struct intel_engine_cs *ring,unsigned entry,uint64_t val)@@ -311,7 +403,7 @@ static int gen8_mm_switch(struct i915_hw_ppgtt *ppgtt,int used_pd = ppgtt->num_pd_entries /GEN8_PDES_PER_PAGE ;for (i = used_pd -1 ; i >=0 ; i--) { -dma_addr_t addr = ppgtt->pdp.page_directory[i].daddr; +dma_addr_t addr = ppgtt->pdp.page_directory[i]->daddr; ret =gen8_write_pdp (ring, i, addr);if (ret)return ret;@@ -338,8 +430,24 @@ static void gen8_ppgtt_clear_range(struct i915_address_space *vm, I915_CACHE_LLC, use_scratch);while (num_entries) { -struct i915_page_directory_entry *pd = &ppgtt->pdp.page_directory[pdpe]; -struct page *page_table = pd->page_table[pde].page; +struct i915_page_directory_entry *pd; +struct i915_page_table_entry *pt; +struct page *page_table; + +if (WARN_ON (!ppgtt->pdp.page_directory[pdpe])) +continue ; + + pd = ppgtt->pdp.page_directory[pdpe]; + +if (WARN_ON (!pd->page_table[pde])) +continue ; + + pt = pd->page_table[pde]; + +if (WARN_ON (!pt->page)) +continue ; + + page_table = pt->page; last_pte = pte + num_entries;if (last_pte >GEN8_PTES_PER_PAGE )@@ -384,8 +492,9 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm,break ;if (pt_vaddr ==NULL ) { -struct i915_page_directory_entry *pd = &ppgtt->pdp.page_directory[pdpe]; -struct page *page_table = pd->page_table[pde].page; +struct i915_page_directory_entry *pd = ppgtt->pdp.page_directory[pdpe]; +struct i915_page_table_entry *pt = pd->page_table[pde]; +struct page *page_table = pt->page; pt_vaddr =kmap_atomic (page_table); }@@ -416,19 +525,16 @@ static void gen8_free_page_tables(struct i915_page_directory_entry *pd) {int i; -if (pd->page_table ==NULL ) +if (!pd->page)return ; -for (i =0 ; i <GEN8_PDES_PER_PAGE ; i++) -if (pd->page_table[i].page) -__free_page (pd->page_table[i].page); -} +for (i =0 ; i <GEN8_PDES_PER_PAGE ; i++) { +if (WARN_ON (!pd->page_table[i])) +continue ; -static void gen8_free_page_directory (struct i915_page_directory_entry *pd) -{ -gen8_free_page_tables (pd); -kfree (pd->page_table); -__free_page (pd->page); +unmap_and_free_pt (pd->page_table[i]); + pd->page_table[i] =NULL ; + } }static void gen8_ppgtt_free (struct i915_hw_ppgtt *ppgtt)@@ -436,7 +542,11 @@ static void gen8_ppgtt_free(struct i915_hw_ppgtt *ppgtt)int i;for (i =0 ; i < ppgtt->num_pd_pages; i++) { -gen8_free_page_directory (&ppgtt->pdp.page_directory[i]); +if (WARN_ON (!ppgtt->pdp.page_directory[i])) +continue ; + +gen8_free_page_tables (ppgtt->pdp.page_directory[i]); +unmap_and_free_pd (ppgtt->pdp.page_directory[i]); } }@@ -448,14 +558,23 @@ static void gen8_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt)for (i =0 ; i < ppgtt->num_pd_pages; i++) {/* TODO: In the future we'll support sparse mappings, so this * will have to change. */ -if (!ppgtt->pdp.page_directory[i].daddr) +if (!ppgtt->pdp.page_directory[i]->daddr)continue ; -pci_unmap_page (hwdev, ppgtt->pdp.page_directory[i].daddr,PAGE_SIZE , +pci_unmap_page (hwdev, ppgtt->pdp.page_directory[i]->daddr,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL );for (j =0 ; j <GEN8_PDES_PER_PAGE ; j++) { -dma_addr_t addr = ppgtt->pdp.page_directory[i].page_table[j].daddr; +struct i915_page_directory_entry *pd = ppgtt->pdp.page_directory[i]; +struct i915_page_table_entry *pt; +dma_addr_t addr; + +if (WARN_ON (!pd->page_table[j])) +continue ; + + pt = pd->page_table[j]; + addr = pt->daddr; +if (addr)pci_unmap_page (hwdev, addr,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL );@@ -474,25 +593,20 @@ static void gen8_ppgtt_cleanup(struct i915_address_space *vm)static int gen8_ppgtt_allocate_page_tables (struct i915_hw_ppgtt *ppgtt) { -int i, j; +int i, ret;for (i =0 ; i < ppgtt->num_pd_pages; i++) { -struct i915_page_directory_entry *pd = &ppgtt->pdp.page_directory[i]; -for (j =0 ; j <GEN8_PDES_PER_PAGE ; j++) { -struct i915_page_table_entry *pt = &pd->page_table[j]; - - pt->page =alloc_page (GFP_KERNEL | __GFP_ZERO); -if (!pt->page) - goto unwind_out; - - } + ret =alloc_pt_range (ppgtt->pdp.page_directory[i], +0 ,GEN8_PDES_PER_PAGE ); +if (ret) + goto unwind_out; }return 0 ; unwind_out:while (i--) -gen8_free_page_tables (&ppgtt->pdp.page_directory[i]); +gen8_free_page_tables (ppgtt->pdp.page_directory[i]);return -ENOMEM ; }@@ -503,19 +617,9 @@ static int gen8_ppgtt_allocate_page_directories(struct i915_hw_ppgtt *ppgtt,int i;for (i =0 ; i < max_pdp; i++) { -struct i915_page_table_entry *pt; - - pt =kcalloc (GEN8_PDES_PER_PAGE ,sizeof (*pt),GFP_KERNEL ); -if (!pt) - goto unwind_out; - - ppgtt->pdp.page_directory[i].page =alloc_page (GFP_KERNEL ); -if (!ppgtt->pdp.page_directory[i].page) { -kfree (pt); + ppgtt->pdp.page_directory[i] =alloc_pd_single (); +if (IS_ERR (ppgtt->pdp.page_directory[i])) goto unwind_out; - } - - ppgtt->pdp.page_directory[i].page_table = pt; } ppgtt->num_pd_pages = max_pdp;@@ -524,10 +628,8 @@ static int gen8_ppgtt_allocate_page_directories(struct i915_hw_ppgtt *ppgtt,return 0 ; unwind_out: -while (i--) { -kfree (ppgtt->pdp.page_directory[i].page_table); -__free_page (ppgtt->pdp.page_directory[i].page); - } +while (i--) +unmap_and_free_pd (ppgtt->pdp.page_directory[i]);return -ENOMEM ; }@@ -561,14 +663,14 @@ static int gen8_ppgtt_setup_page_directories(struct i915_hw_ppgtt *ppgtt,int ret; pd_addr =pci_map_page (ppgtt->base.dev->pdev, - ppgtt->pdp.page_directory[pd].page,0 , + ppgtt->pdp.page_directory[pd]->page,0 ,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL ); ret =pci_dma_mapping_error (ppgtt->base.dev->pdev, pd_addr);if (ret)return ret; - ppgtt->pdp.page_directory[pd].daddr = pd_addr; + ppgtt->pdp.page_directory[pd]->daddr = pd_addr;return 0 ; }@@ -578,8 +680,8 @@ static int gen8_ppgtt_setup_page_tables(struct i915_hw_ppgtt *ppgtt, const int pt) {dma_addr_t pt_addr; -struct i915_page_directory_entry *pdir = &ppgtt->pdp.page_directory[pd]; -struct i915_page_table_entry *ptab = &pdir->page_table[pt]; +struct i915_page_directory_entry *pdir = ppgtt->pdp.page_directory[pd]; +struct i915_page_table_entry *ptab = pdir->page_table[pt];struct page *p = ptab->page;int ret;@@ -642,10 +744,12 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt, uint64_t size)* will never need to touch the PDEs again. */ for (i =0 ; i < max_pdp; i++) { +struct i915_page_directory_entry *pd = ppgtt->pdp.page_directory[i];gen8_ppgtt_pde_t *pd_vaddr; - pd_vaddr =kmap_atomic (ppgtt->pdp.page_directory[i].page); + pd_vaddr =kmap_atomic (ppgtt->pdp.page_directory[i]->page);for (j =0 ; j <GEN8_PDES_PER_PAGE ; j++) { -dma_addr_t addr = ppgtt->pdp.page_directory[i].page_table[j].daddr; +struct i915_page_table_entry *pt = pd->page_table[j]; +dma_addr_t addr = pt->daddr; pd_vaddr[j] =gen8_pde_encode (ppgtt->base.dev, addr,I915_CACHE_LLC ); }@@ -696,7 +800,7 @@ static void gen6_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m)for (pde =0 ; pde < ppgtt->num_pd_entries; pde++) {u32 expected;gen6_gtt_pte_t *pt_vaddr; -dma_addr_t pt_addr = ppgtt->pd.page_table[pde].daddr; +dma_addr_t pt_addr = ppgtt->pd.page_table[pde]->daddr; pd_entry =readl (pd_addr + pde); expected = (GEN6_PDE_ADDR_ENCODE (pt_addr) |GEN6_PDE_VALID );@@ -707,7 +811,7 @@ static void gen6_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m) expected);seq_printf (m,"\tPDE: %x\n" , pd_entry); - pt_vaddr =kmap_atomic (ppgtt->pd.page_table[pde].page); + pt_vaddr =kmap_atomic (ppgtt->pd.page_table[pde]->page);for (pte =0 ; pte <I915_PPGTT_PT_ENTRIES ; pte+=4 ) {unsigned long va = (pde * PAGE_SIZE * I915_PPGTT_PT_ENTRIES) +@@ -746,7 +850,7 @@ static void gen6_write_pdes(struct i915_hw_ppgtt *ppgtt)for (i =0 ; i < ppgtt->num_pd_entries; i++) {dma_addr_t pt_addr; - pt_addr = ppgtt->pd.page_table[i].daddr; + pt_addr = ppgtt->pd.page_table[i]->daddr; pd_entry =GEN6_PDE_ADDR_ENCODE (pt_addr); pd_entry |=GEN6_PDE_VALID ;@@ -922,7 +1026,7 @@ static void gen6_ppgtt_clear_range(struct i915_address_space *vm,if (last_pte >I915_PPGTT_PT_ENTRIES ) last_pte =I915_PPGTT_PT_ENTRIES ; - pt_vaddr =kmap_atomic (ppgtt->pd.page_table[act_pt].page); + pt_vaddr =kmap_atomic (ppgtt->pd.page_table[act_pt]->page);for (i = first_pte; i < last_pte; i++) pt_vaddr[i] = scratch_pte;@@ -951,7 +1055,7 @@ static void gen6_ppgtt_insert_entries(struct i915_address_space *vm, pt_vaddr =NULL ;for_each_sg_page (pages->sgl, &sg_iter, pages->nents,0 ) {if (pt_vaddr ==NULL ) - pt_vaddr =kmap_atomic (ppgtt->pd.page_table[act_pt].page); + pt_vaddr =kmap_atomic (ppgtt->pd.page_table[act_pt]->page); pt_vaddr[act_pte] = vm->pte_encode(sg_page_iter_dma_address(&sg_iter),@@ -974,7 +1078,7 @@ static void gen6_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt)for (i =0 ; i < ppgtt->num_pd_entries; i++)pci_unmap_page (ppgtt->base.dev->pdev, - ppgtt->pd.page_table[i].daddr, + ppgtt->pd.page_table[i]->daddr,4096 ,PCI_DMA_BIDIRECTIONAL ); }@@ -983,9 +1087,9 @@ static void gen6_ppgtt_free(struct i915_hw_ppgtt *ppgtt)int i;for (i =0 ; i < ppgtt->num_pd_entries; i++) -if (ppgtt->pd.page_table[i].page) -__free_page (ppgtt->pd.page_table[i].page); -kfree (ppgtt->pd.page_table); +unmap_and_free_pt (ppgtt->pd.page_table[i]); + +unmap_and_free_pd (&ppgtt->pd); }static void gen6_ppgtt_cleanup (struct i915_address_space *vm)@@ -1040,28 +1144,6 @@ alloc:return 0 ; } -static int gen6_ppgtt_allocate_page_tables (struct i915_hw_ppgtt *ppgtt) -{ -struct i915_page_table_entry *pt; -int i; - - pt =kcalloc (ppgtt->num_pd_entries,sizeof (*pt),GFP_KERNEL ); -if (!pt) -return -ENOMEM ; - - ppgtt->pd.page_table = pt; - -for (i =0 ; i < ppgtt->num_pd_entries; i++) { - pt[i].page =alloc_page (GFP_KERNEL ); -if (!pt->page) { -gen6_ppgtt_free (ppgtt); -return -ENOMEM ; - } - } - -return 0 ; -} -static int gen6_ppgtt_alloc (struct i915_hw_ppgtt *ppgtt) {int ret;@@ -1070,7 +1152,7 @@ static int gen6_ppgtt_alloc(struct i915_hw_ppgtt *ppgtt)if (ret)return ret; - ret =gen6_ppgtt_allocate_page_tables (ppgtt); + ret =alloc_pt_range (&ppgtt->pd,0 , ppgtt->num_pd_entries);if (ret) {drm_mm_remove_node (&ppgtt->node);return ret;@@ -1088,7 +1170,7 @@ static int gen6_ppgtt_setup_page_tables(struct i915_hw_ppgtt *ppgtt)struct page *page;dma_addr_t pt_addr; - page = ppgtt->pd.page_table[i].page; + page = ppgtt->pd.page_table[i]->page; pt_addr =pci_map_page (dev->pdev, page,0 ,4096 ,PCI_DMA_BIDIRECTIONAL );@@ -1097,7 +1179,7 @@ static int gen6_ppgtt_setup_page_tables(struct i915_hw_ppgtt *ppgtt)return -EIO ; } - ppgtt->pd.page_table[i].daddr = pt_addr; + ppgtt->pd.page_table[i]->daddr = pt_addr; }return 0 ;drivers/gpu/drm/i915/i915_gem_gtt.h +2
-2@@ -199,12 +199,12 @@ struct i915_page_directory_entry {dma_addr_t daddr; }; -struct i915_page_table_entry *page_table; +struct i915_page_table_entry *page_table[GEN6_PPGTT_PD_ENTRIES ];/* PDEs */ };struct i915_page_directory_pointer_entry {/* struct page *page; */ -struct i915_page_directory_entry page_directory[GEN8_LEGACY_PDPES ]; +struct i915_page_directory_entry *page_directory[GEN8_LEGACY_PDPES ]; };struct i915_address_space {drivers/gpu/drm/i915/intel_lrc.c +8
-9@@ -1735,14 +1735,14 @@ populate_lr_context(struct intel_context *ctx, struct drm_i915_gem_object *ctx_o reg_state[CTX_PDP1_LDW ] =GEN8_RING_PDP_LDW (ring,1 ); reg_state[CTX_PDP0_UDW ] =GEN8_RING_PDP_UDW (ring,0 ); reg_state[CTX_PDP0_LDW ] =GEN8_RING_PDP_LDW (ring,0 ); - reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[3 ].daddr); - reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[3 ].daddr); - reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[2 ].daddr); - reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[2 ].daddr); - reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[1 ].daddr); - reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[1 ].daddr); - reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[0 ].daddr); - reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[0 ].daddr); + reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[0 ]->daddr);if (ring->id ==RCS ) { reg_state[CTX_LRI_HEADER_2 ] =MI_LOAD_REGISTER_IMM (1 ); reg_state[CTX_R_PWR_CLK_STATE ] =0x20c8 ; --2.1.1
Quoted 4 lines
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 5 lines
Paulo Zanoni _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 4/32 drm/i915: Plumb drm_device through page tables operations
In reply to Michel ThierryThe next patch in the series will require it for alloc_pt_single.
v2: Rebased after s/page_tables/page_table/.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +16 -13
@@ -142,7 +142,6 @@ static int sanitize_enable_ppgtt(struct drm_device *dev, int enable_ppgtt)return has_aliasing_ppgtt ?1 :0 ; } -static void ppgtt_bind_vma (struct i915_vma *vma,enum i915_cache_level cache_level,u32 flags);
@@ -279,7 +278,7 @@ static gen6_gtt_pte_t iris_pte_encode(dma_addr_t addr,return pte; } -static void unmap_and_free_pt (struct i915_page_table_entry *pt) +static void unmap_and_free_pt (struct i915_page_table_entry *pt,struct drm_device *dev) {if (WARN_ON (!pt->page))return ;
@@ -287,7 +286,7 @@ static void unmap_and_free_pt(struct i915_page_table_entry *pt)kfree (pt); } -static struct i915_page_table_entry *alloc_pt_single (void ) +static struct i915_page_table_entry *alloc_pt_single (struct drm_device *dev) {struct i915_page_table_entry *pt;
@@ -317,7 +316,9 @@ static struct i915_page_table_entry *alloc_pt_single(void)* * Return: 0 if allocation succeeded. */ -static int alloc_pt_range (struct i915_page_directory_entry *pd,uint16_t pde,size_t count) +static int alloc_pt_range (struct i915_page_directory_entry *pd,uint16_t pde,size_t count, +struct drm_device *dev) + {int i, ret;
@@ -326,7 +327,7 @@ static int alloc_pt_range(struct i915_page_directory_entry *pd, uint16_t pde, sireturn -EINVAL ;for (i = pde; i < pde + count; i++) { -struct i915_page_table_entry *pt =alloc_pt_single (); +struct i915_page_table_entry *pt =alloc_pt_single (dev);if (IS_ERR (pt)) { ret =PTR_ERR (pt);
@@ -342,7 +343,7 @@ static int alloc_pt_range(struct i915_page_directory_entry *pd, uint16_t pde, si err_out:while (i-- > pde) -unmap_and_free_pt (pd->page_table[i]); +unmap_and_free_pt (pd->page_table[i], dev);return ret; }
@@ -521,7 +522,7 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm, } } -static void gen8_free_page_tables (struct i915_page_directory_entry *pd) +static void gen8_free_page_tables (struct i915_page_directory_entry *pd,struct drm_device *dev) {int i;
@@ -532,7 +533,7 @@ static void gen8_free_page_tables(struct i915_page_directory_entry *pd)if (WARN_ON (!pd->page_table[i]))continue ; -unmap_and_free_pt (pd->page_table[i]); +unmap_and_free_pt (pd->page_table[i], dev); pd->page_table[i] =NULL ; } }
@@ -545,7 +546,7 @@ static void gen8_ppgtt_free(struct i915_hw_ppgtt *ppgtt)if (WARN_ON (!ppgtt->pdp.page_directory[i]))continue ; -gen8_free_page_tables (ppgtt->pdp.page_directory[i]); +gen8_free_page_tables (ppgtt->pdp.page_directory[i], ppgtt->base.dev);unmap_and_free_pd (ppgtt->pdp.page_directory[i]); } }
@@ -597,7 +598,7 @@ static int gen8_ppgtt_allocate_page_tables(struct i915_hw_ppgtt *ppgtt)for (i =0 ; i < ppgtt->num_pd_pages; i++) { ret =alloc_pt_range (ppgtt->pdp.page_directory[i], -0 ,GEN8_PDES_PER_PAGE ); +0 ,GEN8_PDES_PER_PAGE , ppgtt->base.dev);if (ret) goto unwind_out; }
@@ -606,7 +607,7 @@ static int gen8_ppgtt_allocate_page_tables(struct i915_hw_ppgtt *ppgtt) unwind_out:while (i--) -gen8_free_page_tables (ppgtt->pdp.page_directory[i]); +gen8_free_page_tables (ppgtt->pdp.page_directory[i], ppgtt->base.dev);return -ENOMEM ; }
@@ -1087,7 +1088,7 @@ static void gen6_ppgtt_free(struct i915_hw_ppgtt *ppgtt)int i;for (i =0 ; i < ppgtt->num_pd_entries; i++) -unmap_and_free_pt (ppgtt->pd.page_table[i]); +unmap_and_free_pt (ppgtt->pd.page_table[i], ppgtt->base.dev);unmap_and_free_pd (&ppgtt->pd); }
@@ -1152,7 +1153,9 @@ static int gen6_ppgtt_alloc(struct i915_hw_ppgtt *ppgtt)if (ret)return ret; - ret =alloc_pt_range (&ppgtt->pd,0 , ppgtt->num_pd_entries); + ret =alloc_pt_range (&ppgtt->pd,0 , ppgtt->num_pd_entries, + ppgtt->base.dev); +if (ret) {drm_mm_remove_node (&ppgtt->node);return ret;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v6 04/32] drm/i915: Plumb drm_device through page tables operations
Quoted 5 lines · Michel Thierry
The next patch in the series will require it for
alloc_pt_single.v2: Rebased after s/page_tables/page_table/.
Signed-off-by Michel Thierry <[email protected]>
Quoted 135 lines
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)drivers/gpu/drm/i915/i915_gem_gtt.c +16
-13@@ -142,7 +142,6 @@ static int sanitize_enable_ppgtt(struct drm_device *dev, int enable_ppgtt)return has_aliasing_ppgtt ?1 :0 ; } -static void ppgtt_bind_vma (struct i915_vma *vma,enum i915_cache_level cache_level,u32 flags);@@ -279,7 +278,7 @@ static gen6_gtt_pte_t iris_pte_encode(dma_addr_t addr,return pte; } -static void unmap_and_free_pt (struct i915_page_table_entry *pt) +static void unmap_and_free_pt (struct i915_page_table_entry *pt,struct drm_device *dev) {if (WARN_ON (!pt->page))return ;@@ -287,7 +286,7 @@ static void unmap_and_free_pt(struct i915_page_table_entry *pt)kfree (pt); } -static struct i915_page_table_entry *alloc_pt_single (void ) +static struct i915_page_table_entry *alloc_pt_single (struct drm_device *dev) {struct i915_page_table_entry *pt;@@ -317,7 +316,9 @@ static struct i915_page_table_entry *alloc_pt_single(void)* * Return: 0 if allocation succeeded. */ -static int alloc_pt_range (struct i915_page_directory_entry *pd,uint16_t pde,size_t count) +static int alloc_pt_range (struct i915_page_directory_entry *pd,uint16_t pde,size_t count, +struct drm_device *dev) + {int i, ret;@@ -326,7 +327,7 @@ static int alloc_pt_range(struct i915_page_directory_entry *pd, uint16_t pde, sireturn -EINVAL ;for (i = pde; i < pde + count; i++) { -struct i915_page_table_entry *pt =alloc_pt_single (); +struct i915_page_table_entry *pt =alloc_pt_single (dev);if (IS_ERR (pt)) { ret =PTR_ERR (pt);@@ -342,7 +343,7 @@ static int alloc_pt_range(struct i915_page_directory_entry *pd, uint16_t pde, si err_out:while (i-- > pde) -unmap_and_free_pt (pd->page_table[i]); +unmap_and_free_pt (pd->page_table[i], dev);return ret; }@@ -521,7 +522,7 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm, } } -static void gen8_free_page_tables (struct i915_page_directory_entry *pd) +static void gen8_free_page_tables (struct i915_page_directory_entry *pd,struct drm_device *dev) {int i;@@ -532,7 +533,7 @@ static void gen8_free_page_tables(struct i915_page_directory_entry *pd)if (WARN_ON (!pd->page_table[i]))continue ; -unmap_and_free_pt (pd->page_table[i]); +unmap_and_free_pt (pd->page_table[i], dev); pd->page_table[i] =NULL ; } }@@ -545,7 +546,7 @@ static void gen8_ppgtt_free(struct i915_hw_ppgtt *ppgtt)if (WARN_ON (!ppgtt->pdp.page_directory[i]))continue ; -gen8_free_page_tables (ppgtt->pdp.page_directory[i]); +gen8_free_page_tables (ppgtt->pdp.page_directory[i], ppgtt->base.dev);unmap_and_free_pd (ppgtt->pdp.page_directory[i]); } }@@ -597,7 +598,7 @@ static int gen8_ppgtt_allocate_page_tables(struct i915_hw_ppgtt *ppgtt)for (i =0 ; i < ppgtt->num_pd_pages; i++) { ret =alloc_pt_range (ppgtt->pdp.page_directory[i], -0 ,GEN8_PDES_PER_PAGE ); +0 ,GEN8_PDES_PER_PAGE , ppgtt->base.dev);if (ret) goto unwind_out; }@@ -606,7 +607,7 @@ static int gen8_ppgtt_allocate_page_tables(struct i915_hw_ppgtt *ppgtt) unwind_out:while (i--) -gen8_free_page_tables (ppgtt->pdp.page_directory[i]); +gen8_free_page_tables (ppgtt->pdp.page_directory[i], ppgtt->base.dev);return -ENOMEM ; }@@ -1087,7 +1088,7 @@ static void gen6_ppgtt_free(struct i915_hw_ppgtt *ppgtt)int i;for (i =0 ; i < ppgtt->num_pd_entries; i++) -unmap_and_free_pt (ppgtt->pd.page_table[i]); +unmap_and_free_pt (ppgtt->pd.page_table[i], ppgtt->base.dev);unmap_and_free_pd (&ppgtt->pd); }@@ -1152,7 +1153,9 @@ static int gen6_ppgtt_alloc(struct i915_hw_ppgtt *ppgtt)if (ret)return ret; - ret =alloc_pt_range (&ppgtt->pd,0 , ppgtt->num_pd_entries); + ret =alloc_pt_range (&ppgtt->pd,0 , ppgtt->num_pd_entries, + ppgtt->base.dev); +if (ret) {drm_mm_remove_node (&ppgtt->node);return ret;Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v6 04/32] drm/i915: Plumb drm_device through page tables operations
Quoted 9 lines · Mika Kuoppala
Quoted 5 lines · Michel Thierry
The next patch in the series will require it for
alloc_pt_single.v2: Rebased after s/page_tables/page_table/.
Signed-off-by Michel Thierry <[email protected]>Reviewed-by Mika Kuoppala <[email protected]>
Merged up to this one, thanks for patches&review.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 5/32 drm/i915: Track GEN6 page table usage
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
Instead of implementing the full tracking + dynamic allocation, this patch does a bit less than half of the work, by tracking and warning on unexpected conditions. The tracking itself follows which PTEs within a page table are currently being used for objects. The next patch will modify this to actually allocate the page tables only when necessary.
With the current patch there isn't much in the way of making a gen agnostic range allocation function. However, in the next patch we'll add more specificity which makes having separate functions a bit easier to manage.
One important change introduced here is that DMA mappings are created/destroyed at the same page directories/tables are allocated/deallocated.
Notice that aliasing PPGTT is not managed here. The patch which actually begins dynamic allocation/teardown explains the reasoning for this.
v2: s/pdp.page_directory/pdp.page_directorys
Make a scratch page allocation helper
v3: Rebase and expand commit message.
v4: Allocate required pagetables only when it is needed, _bind_to_vm instead of bind_vma (Daniel).
v5: Rebased to remove the unnecessary noise in the diff, also:
- PDE mask is GEN agnostic, renamed GEN6_PDE_MASK to I915_PDE_MASK.
- Removed unnecessary checks in gen6_alloc_va_range.
- Changed map/unmap_px_single macros to use dma functions directly and be part of a static inline function instead.
- Moved drm_device plumbing through page tables operation to its own patch.
- Moved allocate/teardown_va_range calls until they are fully implemented (in subsequent patch).
- Merged pt and scratch_pt unmap_and_free path.
- Moved scratch page allocator helper to the patch that will use it.
v6: Reduce complexity by not tearing down pagetables dynamically, the same can be achieved while freeing empty vms. (Daniel)
v7: s/i915_dma_map_px_single/i915_dma_map_single s/gen6_write_pdes/gen6_write_pde
Prevent a NULL case when only GGTT is available. (Mika)
v8: Rebased after s/page_tables/page_table/.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 198 +++++++++++++++++++++++++----------- drivers/gpu/drm/i915/i915_gem_gtt.h | 75 ++++++++++++++ 2 files changed, 211 insertions(+), 62 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +136 -62
@@ -278,29 +278,88 @@ static gen6_gtt_pte_t iris_pte_encode(dma_addr_t addr,return pte; } -static void unmap_and_free_pt (struct i915_page_table_entry *pt,struct drm_device *dev) +#define i915_dma_unmap_single (px, dev) \ + __i915_dma_unmap_single((px)->daddr, dev) + +static inline void __i915_dma_unmap_single (dma_addr_t daddr, +struct drm_device *dev) +{ +struct device *device = &dev->pdev->dev; + +dma_unmap_page (device, daddr,4096 ,PCI_DMA_BIDIRECTIONAL ); +} + +/** +* i915_dma_map_single() - Create a dma mapping for a page table/dir/etc. +* @px: Page table/dir/etc to get a DMA map for +* @dev: drm device +* +* Page table allocations are unified across all gens. They always require a +* single 4k allocation, as well as a DMA mapping. If we keep the structs +* symmetric here, the simple macro covers us for every page table type. +* +* Return: 0 if success. +*/ +#define i915_dma_map_single (px, dev) \ + i915_dma_map_page_single((px)->page, (dev), &(px)->daddr) + +static inline int i915_dma_map_page_single (struct page *page, +struct drm_device *dev, +dma_addr_t *daddr) +{ +struct device *device = &dev->pdev->dev; + + *daddr =dma_map_page (device, page,0 ,4096 ,PCI_DMA_BIDIRECTIONAL ); +return dma_mapping_error (device, *daddr); +} + +static void unmap_and_free_pt (struct i915_page_table_entry *pt, +struct drm_device *dev) {if (WARN_ON (!pt->page))return ; + +i915_dma_unmap_single (pt, dev);__free_page (pt->page); +kfree (pt->used_ptes);kfree (pt); }static struct i915_page_table_entry *alloc_pt_single (struct drm_device *dev) {struct i915_page_table_entry *pt; +const size_t count =INTEL_INFO (dev)->gen >=8 ? +GEN8_PTES_PER_PAGE :I915_PPGTT_PT_ENTRIES ; +int ret = -ENOMEM ; pt =kzalloc (sizeof (*pt),GFP_KERNEL );if (!pt)return ERR_PTR (-ENOMEM ); + pt->used_ptes =kcalloc (BITS_TO_LONGS (count),sizeof (*pt->used_ptes), +GFP_KERNEL ); + +if (!pt->used_ptes) + goto fail_bitmap; + pt->page =alloc_page (GFP_KERNEL | __GFP_ZERO); -if (!pt->page) { -kfree (pt); -return ERR_PTR (-ENOMEM ); - } +if (!pt->page) + goto fail_page; + + ret =i915_dma_map_single (pt, dev); +if (ret) + goto fail_dma;return pt; + +fail_dma: +__free_page (pt->page); +fail_page: +kfree (pt->used_ptes); +fail_bitmap: +kfree (pt); + +return ERR_PTR (ret); }/**
@@ -838,26 +897,35 @@ static void gen6_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m) } } -static void gen6_write_pdes (struct i915_hw_ppgtt *ppgtt) +/* Write pde (index) from the page directory @pd to the page table @pt */ +static void gen6_write_pde (struct i915_page_directory_entry *pd, +const int pde,struct i915_page_table_entry *pt) { -struct drm_i915_private *dev_priv = ppgtt->base.dev->dev_private; -gen6_gtt_pte_t __iomem *pd_addr; -uint32_t pd_entry; -int i; +/* Caller needs to make sure the write completes if necessary */ +struct i915_hw_ppgtt *ppgtt = + container_of(pd, struct i915_hw_ppgtt, pd); +u32 pd_entry; -WARN_ON (ppgtt->pd.pd_offset &0x3f ); - pd_addr = (gen6_gtt_pte_t __iomem *)dev_priv->gtt.gsm + - ppgtt->pd.pd_offset /sizeof (gen6_gtt_pte_t); -for (i =0 ; i < ppgtt->num_pd_entries; i++) { -dma_addr_t pt_addr; + pd_entry =GEN6_PDE_ADDR_ENCODE (pt->daddr); + pd_entry |=GEN6_PDE_VALID ; - pt_addr = ppgtt->pd.page_table[i]->daddr; - pd_entry =GEN6_PDE_ADDR_ENCODE (pt_addr); - pd_entry |=GEN6_PDE_VALID ; +writel (pd_entry, ppgtt->pd_addr + pde); +} -writel (pd_entry, pd_addr + i); - } -readl (pd_addr); +/* Write all the page tables found in the ppgtt structure to incrementing page +* directories. */ +static void gen6_write_page_range (struct drm_i915_private *dev_priv, +struct i915_page_directory_entry *pd,uint32_t start,uint32_t length) +{ +struct i915_page_table_entry *pt; +uint32_t pde, temp; + +gen6_for_each_pde (pt, pd, start, length, temp, pde) +gen6_write_pde (pd, pde, pt); + +/* Make sure write is complete before other code can use this page +* table. Also require for WC mapped PTEs */ +readl (dev_priv->gtt.gsm); }static uint32_t get_pd_offset (struct i915_hw_ppgtt *ppgtt)
@@ -1083,6 +1151,28 @@ static void gen6_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt) 4096, PCI_DMA_BIDIRECTIONAL); } +static int gen6_alloc_va_range (struct i915_address_space *vm, +uint64_t start,uint64_t length) +{ +struct i915_hw_ppgtt *ppgtt = + container_of(vm, struct i915_hw_ppgtt, base); +struct i915_page_table_entry *pt; +uint32_t pde, temp; + +gen6_for_each_pde (pt, &ppgtt->pd, start, length, temp, pde) { +DECLARE_BITMAP (tmp_bitmap,I915_PPGTT_PT_ENTRIES ); + +bitmap_zero (tmp_bitmap,I915_PPGTT_PT_ENTRIES ); +bitmap_set (tmp_bitmap,gen6_pte_index (start), +gen6_pte_count (start, length)); + +bitmap_or (pt->used_ptes, pt->used_ptes, tmp_bitmap, +I915_PPGTT_PT_ENTRIES ); + } + +return 0 ; +} +static void gen6_ppgtt_free (struct i915_hw_ppgtt *ppgtt) {int i;
@@ -1129,20 +1219,24 @@ alloc:0 , dev_priv->gtt.base.total, 0);if (ret) -return ret; + goto err_out; retried = true; goto alloc; }if (ret) -return ret; + goto err_out; +if (ppgtt->node.start < dev_priv->gtt.mappable_end)DRM_DEBUG ("Forced to use aperture for PDEs\n" ); ppgtt->num_pd_entries =GEN6_PPGTT_PD_ENTRIES ;return 0 ; + +err_out: +return ret; }static int gen6_ppgtt_alloc (struct i915_hw_ppgtt *ppgtt)
@@ -1164,30 +1258,6 @@ static int gen6_ppgtt_alloc(struct i915_hw_ppgtt *ppgtt)return 0 ; } -static int gen6_ppgtt_setup_page_tables (struct i915_hw_ppgtt *ppgtt) -{ -struct drm_device *dev = ppgtt->base.dev; -int i; - -for (i =0 ; i < ppgtt->num_pd_entries; i++) { -struct page *page; -dma_addr_t pt_addr; - - page = ppgtt->pd.page_table[i]->page; - pt_addr =pci_map_page (dev->pdev, page,0 ,4096 , -PCI_DMA_BIDIRECTIONAL ); - -if (pci_dma_mapping_error (dev->pdev, pt_addr)) { -gen6_ppgtt_unmap_pages (ppgtt); -return -EIO ; - } - - ppgtt->pd.page_table[i]->daddr = pt_addr; - } - -return 0 ; -} -static int gen6_ppgtt_init (struct i915_hw_ppgtt *ppgtt) {struct drm_device *dev = ppgtt->base.dev;
@@ -1211,12 +1281,7 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)if (ret)return ret; - ret =gen6_ppgtt_setup_page_tables (ppgtt); -if (ret) { -gen6_ppgtt_free (ppgtt); -return ret; - } - + ppgtt->base.allocate_va_range = gen6_alloc_va_range; ppgtt->base.clear_range = gen6_ppgtt_clear_range; ppgtt->base.insert_entries = gen6_ppgtt_insert_entries; ppgtt->base.cleanup = gen6_ppgtt_cleanup;
@@ -1227,13 +1292,17 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt) ppgtt->pd.pd_offset = ppgtt->node.start /PAGE_SIZE *sizeof (gen6_gtt_pte_t); + ppgtt->pd_addr = (gen6_gtt_pte_t __iomem *)dev_priv->gtt.gsm + + ppgtt->pd.pd_offset /sizeof (gen6_gtt_pte_t); + ppgtt->base.clear_range (&ppgtt->base,0 , ppgtt->base.total, true); +gen6_write_page_range (dev_priv, &ppgtt->pd,0 , ppgtt->base.total); +DRM_DEBUG_DRIVER ("Allocated pde space (%ldM) at GTT entry: %lx\n" , ppgtt->node.size >>20 , ppgtt->node.start /PAGE_SIZE ); -gen6_write_pdes (ppgtt);DRM_DEBUG ("Adding PPGTT at offset %x\n" , ppgtt->pd.pd_offset <<10 );
@@ -1504,15 +1573,20 @@ void i915_gem_restore_gtt_mappings(struct drm_device *dev)return ; } -list_for_each_entry (vm, &dev_priv->vm_list, global_link) { -/* TODO: Perhaps it shouldn't be gen6 specific */ -if (i915_is_ggtt (vm)) { -if (dev_priv->mm.aliasing_ppgtt) -gen6_write_pdes (dev_priv->mm.aliasing_ppgtt); -continue ; - } +if (USES_PPGTT (dev)) { +list_for_each_entry (vm, &dev_priv->vm_list, global_link) { +/* TODO: Perhaps it shouldn't be gen6 specific */ + +struct i915_hw_ppgtt *ppgtt = + container_of(vm, struct i915_hw_ppgtt, + base); -gen6_write_pdes (container_of(vm ,struct i915_hw_ppgtt ,base )); +if (i915_is_ggtt (vm)) + ppgtt = dev_priv->mm.aliasing_ppgtt; + +gen6_write_page_range (dev_priv, &ppgtt->pd,0 , + ppgtt->num_pd_entries); + } }i915_ggtt_flush (dev_priv);
drivers/gpu/drm/i915/i915_gem_gtt.h +75 -0
106 lines not on this page · raw message
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v6 05/32] drm/i915: Track GEN6 page table usage
Quoted 400 lines · Michel Thierry
From: Ben Widawsky <[email protected]>
Instead of implementing the full tracking + dynamic allocation, this patch does a bit less than half of the work, by tracking and warning on unexpected conditions. The tracking itself follows which PTEs within a page table are currently being used for objects. The next patch will modify this to actually allocate the page tables only when necessary.
With the current patch there isn't much in the way of making a gen agnostic range allocation function. However, in the next patch we'll add more specificity which makes having separate functions a bit easier to manage.
One important change introduced here is that DMA mappings are created/destroyed at the same page directories/tables are allocated/deallocated.
Notice that aliasing PPGTT is not managed here. The patch which actually begins dynamic allocation/teardown explains the reasoning for this.
v2: s/pdp.page_directory/pdp.page_directorys
Make a scratch page allocation helperv3: Rebase and expand commit message.
v4: Allocate required pagetables only when it is needed,
_bind_to_vminstead ofbind_vma(Daniel).v5: Rebased to remove the unnecessary noise in the diff, also:
- PDE mask is GEN agnostic, renamedGEN6_PDE_MASKtoI915_PDE_MASK.
- Removed unnecessary checks ingen6_alloc_va_range.
- Changed map/unmap_px_single macros to use dma functions directly and be part of a static inline function instead.
- Moveddrm_deviceplumbing through page tables operation to its own patch.
- Moved allocate/teardown_va_range calls until they are fully implemented (in subsequent patch).
- Merged pt andscratch_ptunmap_and_freepath.
- Moved scratch page allocator helper to the patch that will use it.v6: Reduce complexity by not tearing down pagetables dynamically, the same can be achieved while freeing empty vms. (Daniel)
v7: s/i915_dma_map_px_single/i915_dma_map_single s/gen6_write_pdes/gen6_write_pde
Prevent a NULL case when only GGTT is available. (Mika)v8: Rebased after s/page_tables/page_table/.
Cc Daniel Vetter <[email protected]>Cc Mika Kuoppala <[email protected]>Signed-off-by Ben Widawsky <[email protected]>Signed-off-by Michel Thierry <[email protected]> (v3+)--- drivers/gpu/drm/i915/i915_gem_gtt.c | 198 +++++++++++++++++++++++++----------- drivers/gpu/drm/i915/i915_gem_gtt.h | 75 ++++++++++++++ 2 files changed, 211 insertions(+), 62 deletions(-)drivers/gpu/drm/i915/i915_gem_gtt.c +136
-62@@ -278,29 +278,88 @@ static gen6_gtt_pte_t iris_pte_encode(dma_addr_t addr,return pte; } -static void unmap_and_free_pt (struct i915_page_table_entry *pt,struct drm_device *dev) +#define i915_dma_unmap_single (px, dev) \ + __i915_dma_unmap_single((px)->daddr, dev) + +static inline void __i915_dma_unmap_single (dma_addr_t daddr, +struct drm_device *dev) +{ +struct device *device = &dev->pdev->dev; + +dma_unmap_page (device, daddr,4096 ,PCI_DMA_BIDIRECTIONAL ); +} + +/** +* i915_dma_map_single() - Create a dma mapping for a page table/dir/etc. +* @px: Page table/dir/etc to get a DMA map for +* @dev: drm device +* +* Page table allocations are unified across all gens. They always require a +* single 4k allocation, as well as a DMA mapping. If we keep the structs +* symmetric here, the simple macro covers us for every page table type. +* +* Return: 0 if success. +*/ +#define i915_dma_map_single (px, dev) \ + i915_dma_map_page_single((px)->page, (dev), &(px)->daddr) + +static inline int i915_dma_map_page_single (struct page *page, +struct drm_device *dev, +dma_addr_t *daddr) +{ +struct device *device = &dev->pdev->dev; + + *daddr =dma_map_page (device, page,0 ,4096 ,PCI_DMA_BIDIRECTIONAL ); +return dma_mapping_error (device, *daddr); +} + +static void unmap_and_free_pt (struct i915_page_table_entry *pt, +struct drm_device *dev) {if (WARN_ON (!pt->page))return ; + +i915_dma_unmap_single (pt, dev);__free_page (pt->page); +kfree (pt->used_ptes);kfree (pt); }static struct i915_page_table_entry *alloc_pt_single (struct drm_device *dev) {struct i915_page_table_entry *pt; +const size_t count =INTEL_INFO (dev)->gen >=8 ? +GEN8_PTES_PER_PAGE :I915_PPGTT_PT_ENTRIES ; +int ret = -ENOMEM ; pt =kzalloc (sizeof (*pt),GFP_KERNEL );if (!pt)return ERR_PTR (-ENOMEM ); + pt->used_ptes =kcalloc (BITS_TO_LONGS (count),sizeof (*pt->used_ptes), +GFP_KERNEL ); + +if (!pt->used_ptes) + goto fail_bitmap; + pt->page =alloc_page (GFP_KERNEL | __GFP_ZERO); -if (!pt->page) { -kfree (pt); -return ERR_PTR (-ENOMEM ); - } +if (!pt->page) + goto fail_page; + + ret =i915_dma_map_single (pt, dev); +if (ret) + goto fail_dma;return pt; + +fail_dma: +__free_page (pt->page); +fail_page: +kfree (pt->used_ptes); +fail_bitmap: +kfree (pt); + +return ERR_PTR (ret); }/** @@ -838,26 +897,35 @@ static void gen6_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m) } } -static void gen6_write_pdes (struct i915_hw_ppgtt *ppgtt) +/* Write pde (index) from the page directory @pd to the page table @pt */ +static void gen6_write_pde (struct i915_page_directory_entry *pd, +const int pde,struct i915_page_table_entry *pt) { -struct drm_i915_private *dev_priv = ppgtt->base.dev->dev_private; -gen6_gtt_pte_t __iomem *pd_addr; -uint32_t pd_entry; -int i; +/* Caller needs to make sure the write completes if necessary */ +struct i915_hw_ppgtt *ppgtt = + container_of(pd, struct i915_hw_ppgtt, pd); +u32 pd_entry; -WARN_ON (ppgtt->pd.pd_offset &0x3f ); - pd_addr = (gen6_gtt_pte_t __iomem *)dev_priv->gtt.gsm + - ppgtt->pd.pd_offset /sizeof (gen6_gtt_pte_t); -for (i =0 ; i < ppgtt->num_pd_entries; i++) { -dma_addr_t pt_addr; + pd_entry =GEN6_PDE_ADDR_ENCODE (pt->daddr); + pd_entry |=GEN6_PDE_VALID ; - pt_addr = ppgtt->pd.page_table[i]->daddr; - pd_entry =GEN6_PDE_ADDR_ENCODE (pt_addr); - pd_entry |=GEN6_PDE_VALID ; +writel (pd_entry, ppgtt->pd_addr + pde); +} -writel (pd_entry, pd_addr + i); - } -readl (pd_addr); +/* Write all the page tables found in the ppgtt structure to incrementing page +* directories. */ +static void gen6_write_page_range (struct drm_i915_private *dev_priv, +struct i915_page_directory_entry *pd,uint32_t start,uint32_t length) +{ +struct i915_page_table_entry *pt; +uint32_t pde, temp; + +gen6_for_each_pde (pt, pd, start, length, temp, pde) +gen6_write_pde (pd, pde, pt); + +/* Make sure write is complete before other code can use this page +* table. Also require for WC mapped PTEs */ +readl (dev_priv->gtt.gsm); }static uint32_t get_pd_offset (struct i915_hw_ppgtt *ppgtt)@@ -1083,6 +1151,28 @@ static void gen6_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt) 4096, PCI_DMA_BIDIRECTIONAL); } +static int gen6_alloc_va_range (struct i915_address_space *vm, +uint64_t start,uint64_t length) +{ +struct i915_hw_ppgtt *ppgtt = + container_of(vm, struct i915_hw_ppgtt, base); +struct i915_page_table_entry *pt; +uint32_t pde, temp; + +gen6_for_each_pde (pt, &ppgtt->pd, start, length, temp, pde) { +DECLARE_BITMAP (tmp_bitmap,I915_PPGTT_PT_ENTRIES ); + +bitmap_zero (tmp_bitmap,I915_PPGTT_PT_ENTRIES ); +bitmap_set (tmp_bitmap,gen6_pte_index (start), +gen6_pte_count (start, length)); + +bitmap_or (pt->used_ptes, pt->used_ptes, tmp_bitmap, +I915_PPGTT_PT_ENTRIES ); + } + +return 0 ; +} +static void gen6_ppgtt_free (struct i915_hw_ppgtt *ppgtt) {int i;@@ -1129,20 +1219,24 @@ alloc:0 , dev_priv->gtt.base.total, 0);if (ret) -return ret; + goto err_out; retried = true; goto alloc; }if (ret) -return ret; + goto err_out; +if (ppgtt->node.start < dev_priv->gtt.mappable_end)DRM_DEBUG ("Forced to use aperture for PDEs\n" ); ppgtt->num_pd_entries =GEN6_PPGTT_PD_ENTRIES ;return 0 ; + +err_out: +return ret; }static int gen6_ppgtt_alloc (struct i915_hw_ppgtt *ppgtt)@@ -1164,30 +1258,6 @@ static int gen6_ppgtt_alloc(struct i915_hw_ppgtt *ppgtt)return 0 ; } -static int gen6_ppgtt_setup_page_tables (struct i915_hw_ppgtt *ppgtt) -{ -struct drm_device *dev = ppgtt->base.dev; -int i; - -for (i =0 ; i < ppgtt->num_pd_entries; i++) { -struct page *page; -dma_addr_t pt_addr; - - page = ppgtt->pd.page_table[i]->page; - pt_addr =pci_map_page (dev->pdev, page,0 ,4096 , -PCI_DMA_BIDIRECTIONAL ); - -if (pci_dma_mapping_error (dev->pdev, pt_addr)) { -gen6_ppgtt_unmap_pages (ppgtt); -return -EIO ; - } - - ppgtt->pd.page_table[i]->daddr = pt_addr; - } - -return 0 ; -} -static int gen6_ppgtt_init (struct i915_hw_ppgtt *ppgtt) {struct drm_device *dev = ppgtt->base.dev;@@ -1211,12 +1281,7 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)if (ret)return ret; - ret =gen6_ppgtt_setup_page_tables (ppgtt); -if (ret) { -gen6_ppgtt_free (ppgtt); -return ret; - } - + ppgtt->base.allocate_va_range = gen6_alloc_va_range; ppgtt->base.clear_range = gen6_ppgtt_clear_range; ppgtt->base.insert_entries = gen6_ppgtt_insert_entries; ppgtt->base.cleanup = gen6_ppgtt_cleanup;@@ -1227,13 +1292,17 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt) ppgtt->pd.pd_offset = ppgtt->node.start /PAGE_SIZE *sizeof (gen6_gtt_pte_t); + ppgtt->pd_addr = (gen6_gtt_pte_t __iomem *)dev_priv->gtt.gsm + + ppgtt->pd.pd_offset /sizeof (gen6_gtt_pte_t); + ppgtt->base.clear_range (&ppgtt->base,0 , ppgtt->base.total, true); +gen6_write_page_range (dev_priv, &ppgtt->pd,0 , ppgtt->base.total); +DRM_DEBUG_DRIVER ("Allocated pde space (%ldM) at GTT entry: %lx\n" , ppgtt->node.size >>20 , ppgtt->node.start /PAGE_SIZE ); -gen6_write_pdes (ppgtt);DRM_DEBUG ("Adding PPGTT at offset %x\n" , ppgtt->pd.pd_offset <<10 );@@ -1504,15 +1573,20 @@ void i915_gem_restore_gtt_mappings(struct drm_device *dev)return ; } -list_for_each_entry (vm, &dev_priv->vm_list, global_link) { -/* TODO: Perhaps it shouldn't be gen6 specific */ -if (i915_is_ggtt (vm)) { -if (dev_priv->mm.aliasing_ppgtt) -gen6_write_pdes (dev_priv->mm.aliasing_ppgtt); -continue ; - } +if (USES_PPGTT (dev)) { +list_for_each_entry (vm, &dev_priv->vm_list, global_link) { +/* TODO: Perhaps it shouldn't be gen6 specific */ + +struct i915_hw_ppgtt *ppgtt = + container_of(vm, struct i915_hw_ppgtt, + base); -gen6_write_pdes (container_of(vm ,struct i915_hw_ppgtt ,base )); +if (i915_is_ggtt (vm)) + ppgtt = dev_priv->mm.aliasing_ppgtt; + +gen6_write_page_range (dev_priv, &ppgtt->pd,0 , + ppgtt->num_pd_entries); + } }i915_ggtt_flush (dev_priv);drivers/gpu/drm/i915/i915_gem_gtt.h +10
-0@@ -54,7 +54,10 @@ typedef gen8_gtt_pte_t gen8_ppgtt_pde_t;#define GEN6_PPGTT_PD_ENTRIES 512#define GEN6_PD_SIZE (GEN6_PPGTT_PD_ENTRIES * PAGE_SIZE)#define GEN6_PD_ALIGN (PAGE_SIZE * 16) +#define GEN6_PDE_SHIFT 22#define GEN6_PDE_VALID (1 << 0) +#define I915_PDE_MASK (GEN6_PPGTT_PD_ENTRIES-1) +#define NUM_PTE (pde_shift) (1 << (pde_shift - PAGE_SHIFT))#define GEN7_PTE_CACHE_L3_LLC (3 << 1)@@ -190,6 +193,8 @@ struct i915_vma {struct i915_page_table_entry {struct page *page;dma_addr_t daddr; + +unsigned long *used_ptes; };struct i915_page_directory_entry {@@ -246,6 +251,9 @@ struct i915_address_space {gen6_gtt_pte_t (*pte_encode)(dma_addr_t addr,enum i915_cache_level level,bool valid,u32 flags);/* Create a valid PTE */ +int (*allocate_va_range)(struct i915_address_space *vm, +uint64_t start, +uint64_t length); void (*clear_range)(struct i915_address_space *vm, uint64_t start, uint64_t length,@@ -298,12 +306,79 @@ struct i915_hw_ppgtt {struct drm_i915_file_private *file_priv; +gen6_gtt_pte_t __iomem *pd_addr; +int (*enable)(struct i915_hw_ppgtt *ppgtt);int (*switch_mm)(struct i915_hw_ppgtt *ppgtt,struct intel_engine_cs *ring);
drivers/gpu/drm/i915/i915_gem_gtt.h struct i915_hw_ppgtt { · line 323
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_gtt.h +7
-0void (*debug_dump)(struct i915_hw_ppgtt *ppgtt,struct seq_file *m); }; +/* For each pde iterates over every pde between from start until start + length. +* If start, and start+length are not perfectly divisible, the macro will round +* down, and up as needed. The macro modifies pde, start, and length. Dev is +* only used to differentiate shift values. Temp is temp. On gen6/7, start = 0, +* and length = 2G effectively iterates over every PDE in the system. On gen8+ +* it simply iterates over every page directory entry in a page directory. +*
There is nothing for gen8 in the macro yet, so comment is a bit misleading.
Quoted 27 lines
drivers/gpu/drm/i915/i915_gem_gtt.h +27
-0+* XXX: temp is not actually needed, but it saves doing the ALIGN operation. +*/ +#define gen6_for_each_pde (pt, pd, start, length, temp, iter) \ + for (iter = gen6_pde_index(start), pt = (pd)->page_table[iter]; \ + length > 0 && iter < GEN6_PPGTT_PD_ENTRIES; \ + pt = (pd)->page_table[++iter], \ + temp = ALIGN(start+1, 1 << GEN6_PDE_SHIFT) - start, \ + temp = min_t(unsigned, temp, length), \ + start += temp, length -= temp) + +static inline uint32_t i915_pte_index (uint64_t address,uint32_t pde_shift) +{ +const uint32_t mask =NUM_PTE (pde_shift) -1 ; + +return (address >>PAGE_SHIFT ) & mask; +} + +/* Helper to counts the number of PTEs within the given length. This count does +* not cross a page table boundary, so the max value would be +* I915_PPGTT_PT_ENTRIES for GEN6, and GEN8_PTES_PER_PAGE for GEN8. +*/ +static inline size_t i915_pte_count (uint64_t addr,size_t length, +uint32_t pde_shift) +{ +const uint64_t mask = ~((1 << pde_shift) -1 ); +uint64_t end; +
drivers/gpu/drm/i915/i915_gem_gtt.h struct i915_hw_ppgtt { · line 360
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_gtt.h +10
-0+BUG_ON (length ==0 ); +BUG_ON (offset_in_page (addr|length)); + + end = addr + length; + +if ((addr & mask) != (end & mask)) +return NUM_PTE (pde_shift) -i915_pte_index (addr, pde_shift); + +return i915_pte_index (end, pde_shift) -i915_pte_index (addr, pde_shift); +}
After trying to figure out the reasoning for this i915_pte_count and it's role in the used bitmap setup, I started to wonder why all the complexity here.
BUG_ON(offset_in_page(addr|length)) reveals that we can't be called with anything but a page boundary so the address parameter is irrelevant in here?
Then there is trickery with the pde_shifting. I tried to find some generalization down the series to take advantage of this. Perhaps I missed it?
For me it seems that we can replace this with simple:
static inline uint32_t i915_pte_count(uint64_t length, uint32_t pte_len)
{
return min_t(uint32_t, length / PAGE_SIZE, PAGE_SIZE / pte_len);
}...and not lose anything.
On top of that when trying to wrap my brain around the differences between GEN6/7 and GEN8+ the following patch before this patch would make things much easier to understand, atleast for me:
drivers/gpu/drm/i915/i915_gem_gtt.h +31 -12
@@ -36,13 +36,13 @@struct drm_i915_file_private ; -typedef uint32_t gen6_gtt_pte_t ; -typedef uint64_t gen8_gtt_pte_t ; -typedef gen8_gtt_pte_t gen8_ppgtt_pde_t ; +typedef uint32_t gen6_pte_t ; +typedef uint64_t gen8_pte_t ; +typedef uint64_t gen8_pde_t ;#define gtt_total_entries (gtt) ((gtt).base.total >> PAGE_SHIFT) -#define I915_PPGTT_PT_ENTRIES (PAGE_SIZE / sizeof(gen6_gtt_pte_t)) +/* gen6-hsw has bit 11-4 for physical addr bit 39-32 */ #define GEN6_GTT_ADDR_ENCODE (addr) ((addr) | (((addr) >> 28) & 0xff0))#define GEN6_PTE_ADDR_ENCODE (addr) GEN6_GTT_ADDR_ENCODE(addr)
@@ -51,8 +51,13 @@ typedef gen8_gtt_pte_t gen8_ppgtt_pde_t;#define GEN6_PTE_UNCACHED (1 << 1)#define GEN6_PTE_VALID (1 << 0) -#define GEN6_PPGTT_PD_ENTRIES 512 -#define GEN6_PD_SIZE (GEN6_PPGTT_PD_ENTRIES * PAGE_SIZE) +#define I915_PTES (pte_len) (PAGE_SIZE / (pte_len)) +#define I915_PTE_MASK (pte_len) (I915_PTES(pte_len) - 1) +#define I915_PDES 512 +#define I915_PDE_MASK (I915_PDES - 1) + +#define GEN6_PTES I915_PTES(sizeof(gen6_pte_t)) +#define GEN6_PD_SIZE (I915_PDES * PAGE_SIZE)#define GEN6_PD_ALIGN (PAGE_SIZE * 16)#define GEN6_PDE_VALID (1 << 0)
@@ -89,8 +94,7 @@ typedef gen8_gtt_pte_t gen8_ppgtt_pde_t;#define GEN8_PTE_SHIFT 12#define GEN8_PTE_MASK 0x1ff#define GEN8_LEGACY_PDPES 4 -#define GEN8_PTES_PER_PAGE (PAGE_SIZE / sizeof(gen8_gtt_pte_t)) -#define GEN8_PDES_PER_PAGE (PAGE_SIZE / sizeof(gen8_ppgtt_pde_t)) +#define GEN8_PTES I915_PTES(sizeof(gen8_pte_t))#define PPAT_UNCACHED_INDEX (_PAGE_PWT | _PAGE_PCD)#define PPAT_CACHED_PDE_INDEX 0/* WB LLC */
@@ -199,7 +203,7 @@ struct i915_page_directory_entry {dma_addr_t daddr; }; -struct i915_page_table_entry *page_table[GEN6_PPGTT_PD_ENTRIES ];/* PDEs */ +struct i915_page_table_entry *page_table[I915_PDES ];/* PDEs */ };struct i915_page_directory_pointer_entry {
@@ -243,9 +247,9 @@ struct i915_address_space {struct list_head inactive_list;/* FIXME: Need a more generic return type */ -gen6_gtt_pte_t (*pte_encode)(dma_addr_t addr, -enum i915_cache_level level, -bool valid,u32 flags);/* Create a valid PTE */ +gen6_pte_t (*pte_encode)(dma_addr_t addr, +enum i915_cache_level level, +bool valid,u32 flags);/* Create a valid PTE */ void (*clear_range)(struct i915_address_space *vm, uint64_t start, uint64_t length,
@@ -304,6 +308,21 @@ struct i915_hw_ppgtt {void (*debug_dump)(struct i915_hw_ppgtt *ppgtt,struct seq_file *m); }; +static inline uint32_t i915_pte_index (uint64_t address,uint32_t pte_len) +{ +return (address >>PAGE_SHIFT ) &I915_PTE_MASK (pte_len); +} + +static inline uint32_t i915_pte_count (uint64_t length,uint32_t pte_len) +{ +return min_t (uint32_t, length /PAGE_SIZE ,I915_PTES (pte_len)); +} + +static inline uint32_t i915_pde_index (uint64_t addr,uint32_t pde_shift) +{ +return (addr >> pde_shift) &I915_PDE_MASK ; +} +int i915_gem_gtt_init (struct drm_device *dev);void i915_gem_init_global_gtt (struct drm_device *dev);void i915_global_gtt_cleanup (struct drm_device *dev);
With that, I think you could write generic gen_for_each_pde more easily and just parametrize the gen6 variant and gen8 one further in the series.
--Mika
Quoted 30 lines
drivers/gpu/drm/i915/i915_gem_gtt.h +20
-0+static inline uint32_t i915_pde_index (uint64_t addr,uint32_t shift) +{ +return (addr >> shift) &I915_PDE_MASK ; +} + +static inline uint32_t gen6_pte_index (uint32_t addr) +{ +return i915_pte_index (addr,GEN6_PDE_SHIFT ); +} + +static inline size_t gen6_pte_count (uint32_t addr,uint32_t length) +{ +return i915_pte_count (addr, length,GEN6_PDE_SHIFT ); +} + +static inline uint32_t gen6_pde_index (uint32_t addr) +{ +return i915_pde_index (addr,GEN6_PDE_SHIFT ); +} +int i915_gem_gtt_init (struct drm_device *dev);void i915_gem_init_global_gtt (struct drm_device *dev);void i915_global_gtt_cleanup (struct drm_device *dev);Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v6 05/32] drm/i915: Track GEN6 page table usage
Quoted 467 lines · Mika Kuoppala
Quoted 400 lines · Michel Thierry
From: Ben Widawsky <[email protected]>
Instead of implementing the full tracking + dynamic allocation, this patch does a bit less than half of the work, by tracking and warning on unexpected conditions. The tracking itself follows which PTEs within a page table are currently being used for objects. The next patch will modify this to actually allocate the page tables only when necessary.
With the current patch there isn't much in the way of making a gen agnostic range allocation function. However, in the next patch we'll add more specificity which makes having separate functions a bit easier to manage.
One important change introduced here is that DMA mappings are created/destroyed at the same page directories/tables are allocated/deallocated.
Notice that aliasing PPGTT is not managed here. The patch which actually begins dynamic allocation/teardown explains the reasoning for this.
v2: s/pdp.page_directory/pdp.page_directorys
Make a scratch page allocation helperv3: Rebase and expand commit message.
v4: Allocate required pagetables only when it is needed,
_bind_to_vminstead ofbind_vma(Daniel).v5: Rebased to remove the unnecessary noise in the diff, also:
- PDE mask is GEN agnostic, renamedGEN6_PDE_MASKtoI915_PDE_MASK.
- Removed unnecessary checks ingen6_alloc_va_range.
- Changed map/unmap_px_single macros to use dma functions directly and be part of a static inline function instead.
- Moveddrm_deviceplumbing through page tables operation to its own patch.
- Moved allocate/teardown_va_range calls until they are fully implemented (in subsequent patch).
- Merged pt andscratch_ptunmap_and_freepath.
- Moved scratch page allocator helper to the patch that will use it.v6: Reduce complexity by not tearing down pagetables dynamically, the same can be achieved while freeing empty vms. (Daniel)
v7: s/i915_dma_map_px_single/i915_dma_map_single s/gen6_write_pdes/gen6_write_pde
Prevent a NULL case when only GGTT is available. (Mika)v8: Rebased after s/page_tables/page_table/.
Cc Daniel Vetter <[email protected]>Cc Mika Kuoppala <[email protected]>Signed-off-by Ben Widawsky <[email protected]>Signed-off-by Michel Thierry <[email protected]> (v3+)--- drivers/gpu/drm/i915/i915_gem_gtt.c | 198 +++++++++++++++++++++++++----------- drivers/gpu/drm/i915/i915_gem_gtt.h | 75 ++++++++++++++ 2 files changed, 211 insertions(+), 62 deletions(-)drivers/gpu/drm/i915/i915_gem_gtt.c +136
-62@@ -278,29 +278,88 @@ static gen6_gtt_pte_t iris_pte_encode(dma_addr_t addr,return pte; } -static void unmap_and_free_pt (struct i915_page_table_entry *pt,struct drm_device *dev) +#define i915_dma_unmap_single (px, dev) \ + __i915_dma_unmap_single((px)->daddr, dev) + +static inline void __i915_dma_unmap_single (dma_addr_t daddr, +struct drm_device *dev) +{ +struct device *device = &dev->pdev->dev; + +dma_unmap_page (device, daddr,4096 ,PCI_DMA_BIDIRECTIONAL ); +} + +/** +* i915_dma_map_single() - Create a dma mapping for a page table/dir/etc. +* @px: Page table/dir/etc to get a DMA map for +* @dev: drm device +* +* Page table allocations are unified across all gens. They always require a +* single 4k allocation, as well as a DMA mapping. If we keep the structs +* symmetric here, the simple macro covers us for every page table type. +* +* Return: 0 if success. +*/ +#define i915_dma_map_single (px, dev) \ + i915_dma_map_page_single((px)->page, (dev), &(px)->daddr) + +static inline int i915_dma_map_page_single (struct page *page, +struct drm_device *dev, +dma_addr_t *daddr) +{ +struct device *device = &dev->pdev->dev; + + *daddr =dma_map_page (device, page,0 ,4096 ,PCI_DMA_BIDIRECTIONAL ); +return dma_mapping_error (device, *daddr); +} + +static void unmap_and_free_pt (struct i915_page_table_entry *pt, +struct drm_device *dev) {if (WARN_ON (!pt->page))return ; + +i915_dma_unmap_single (pt, dev);__free_page (pt->page); +kfree (pt->used_ptes);kfree (pt); }static struct i915_page_table_entry *alloc_pt_single (struct drm_device *dev) {struct i915_page_table_entry *pt; +const size_t count =INTEL_INFO (dev)->gen >=8 ? +GEN8_PTES_PER_PAGE :I915_PPGTT_PT_ENTRIES ; +int ret = -ENOMEM ; pt =kzalloc (sizeof (*pt),GFP_KERNEL );if (!pt)return ERR_PTR (-ENOMEM ); + pt->used_ptes =kcalloc (BITS_TO_LONGS (count),sizeof (*pt->used_ptes), +GFP_KERNEL ); + +if (!pt->used_ptes) + goto fail_bitmap; + pt->page =alloc_page (GFP_KERNEL | __GFP_ZERO); -if (!pt->page) { -kfree (pt); -return ERR_PTR (-ENOMEM ); - } +if (!pt->page) + goto fail_page; + + ret =i915_dma_map_single (pt, dev); +if (ret) + goto fail_dma;return pt; + +fail_dma: +__free_page (pt->page); +fail_page: +kfree (pt->used_ptes); +fail_bitmap: +kfree (pt); + +return ERR_PTR (ret); }/** @@ -838,26 +897,35 @@ static void gen6_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m) } } -static void gen6_write_pdes (struct i915_hw_ppgtt *ppgtt) +/* Write pde (index) from the page directory @pd to the page table @pt */ +static void gen6_write_pde (struct i915_page_directory_entry *pd, +const int pde,struct i915_page_table_entry *pt) { -struct drm_i915_private *dev_priv = ppgtt->base.dev->dev_private; -gen6_gtt_pte_t __iomem *pd_addr; -uint32_t pd_entry; -int i; +/* Caller needs to make sure the write completes if necessary */ +struct i915_hw_ppgtt *ppgtt = + container_of(pd, struct i915_hw_ppgtt, pd); +u32 pd_entry; -WARN_ON (ppgtt->pd.pd_offset &0x3f ); - pd_addr = (gen6_gtt_pte_t __iomem *)dev_priv->gtt.gsm + - ppgtt->pd.pd_offset /sizeof (gen6_gtt_pte_t); -for (i =0 ; i < ppgtt->num_pd_entries; i++) { -dma_addr_t pt_addr; + pd_entry =GEN6_PDE_ADDR_ENCODE (pt->daddr); + pd_entry |=GEN6_PDE_VALID ; - pt_addr = ppgtt->pd.page_table[i]->daddr; - pd_entry =GEN6_PDE_ADDR_ENCODE (pt_addr); - pd_entry |=GEN6_PDE_VALID ; +writel (pd_entry, ppgtt->pd_addr + pde); +} -writel (pd_entry, pd_addr + i); - } -readl (pd_addr); +/* Write all the page tables found in the ppgtt structure to incrementing page +* directories. */ +static void gen6_write_page_range (struct drm_i915_private *dev_priv, +struct i915_page_directory_entry *pd,uint32_t start,uint32_t length) +{ +struct i915_page_table_entry *pt; +uint32_t pde, temp; + +gen6_for_each_pde (pt, pd, start, length, temp, pde) +gen6_write_pde (pd, pde, pt); + +/* Make sure write is complete before other code can use this page +* table. Also require for WC mapped PTEs */ +readl (dev_priv->gtt.gsm); }static uint32_t get_pd_offset (struct i915_hw_ppgtt *ppgtt)@@ -1083,6 +1151,28 @@ static void gen6_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt) 4096, PCI_DMA_BIDIRECTIONAL); } +static int gen6_alloc_va_range (struct i915_address_space *vm, +uint64_t start,uint64_t length) +{ +struct i915_hw_ppgtt *ppgtt = + container_of(vm, struct i915_hw_ppgtt, base); +struct i915_page_table_entry *pt; +uint32_t pde, temp; + +gen6_for_each_pde (pt, &ppgtt->pd, start, length, temp, pde) { +DECLARE_BITMAP (tmp_bitmap,I915_PPGTT_PT_ENTRIES ); + +bitmap_zero (tmp_bitmap,I915_PPGTT_PT_ENTRIES ); +bitmap_set (tmp_bitmap,gen6_pte_index (start), +gen6_pte_count (start, length)); + +bitmap_or (pt->used_ptes, pt->used_ptes, tmp_bitmap, +I915_PPGTT_PT_ENTRIES ); + } + +return 0 ; +} +static void gen6_ppgtt_free (struct i915_hw_ppgtt *ppgtt) {int i;@@ -1129,20 +1219,24 @@ alloc:0 , dev_priv->gtt.base.total, 0);if (ret) -return ret; + goto err_out; retried = true; goto alloc; }if (ret) -return ret; + goto err_out; +if (ppgtt->node.start < dev_priv->gtt.mappable_end)DRM_DEBUG ("Forced to use aperture for PDEs\n" ); ppgtt->num_pd_entries =GEN6_PPGTT_PD_ENTRIES ;return 0 ; + +err_out: +return ret; }static int gen6_ppgtt_alloc (struct i915_hw_ppgtt *ppgtt)@@ -1164,30 +1258,6 @@ static int gen6_ppgtt_alloc(struct i915_hw_ppgtt *ppgtt)return 0 ; } -static int gen6_ppgtt_setup_page_tables (struct i915_hw_ppgtt *ppgtt) -{ -struct drm_device *dev = ppgtt->base.dev; -int i; - -for (i =0 ; i < ppgtt->num_pd_entries; i++) { -struct page *page; -dma_addr_t pt_addr; - - page = ppgtt->pd.page_table[i]->page; - pt_addr =pci_map_page (dev->pdev, page,0 ,4096 , -PCI_DMA_BIDIRECTIONAL ); - -if (pci_dma_mapping_error (dev->pdev, pt_addr)) { -gen6_ppgtt_unmap_pages (ppgtt); -return -EIO ; - } - - ppgtt->pd.page_table[i]->daddr = pt_addr; - } - -return 0 ; -} -static int gen6_ppgtt_init (struct i915_hw_ppgtt *ppgtt) {struct drm_device *dev = ppgtt->base.dev;@@ -1211,12 +1281,7 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)if (ret)return ret; - ret =gen6_ppgtt_setup_page_tables (ppgtt); -if (ret) { -gen6_ppgtt_free (ppgtt); -return ret; - } - + ppgtt->base.allocate_va_range = gen6_alloc_va_range; ppgtt->base.clear_range = gen6_ppgtt_clear_range; ppgtt->base.insert_entries = gen6_ppgtt_insert_entries; ppgtt->base.cleanup = gen6_ppgtt_cleanup;@@ -1227,13 +1292,17 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt) ppgtt->pd.pd_offset = ppgtt->node.start /PAGE_SIZE *sizeof (gen6_gtt_pte_t); + ppgtt->pd_addr = (gen6_gtt_pte_t __iomem *)dev_priv->gtt.gsm + + ppgtt->pd.pd_offset /sizeof (gen6_gtt_pte_t); + ppgtt->base.clear_range (&ppgtt->base,0 , ppgtt->base.total, true); +gen6_write_page_range (dev_priv, &ppgtt->pd,0 , ppgtt->base.total); +DRM_DEBUG_DRIVER ("Allocated pde space (%ldM) at GTT entry: %lx\n" , ppgtt->node.size >>20 , ppgtt->node.start /PAGE_SIZE ); -gen6_write_pdes (ppgtt);DRM_DEBUG ("Adding PPGTT at offset %x\n" , ppgtt->pd.pd_offset <<10 );@@ -1504,15 +1573,20 @@ void i915_gem_restore_gtt_mappings(struct drm_device *dev)return ; } -list_for_each_entry (vm, &dev_priv->vm_list, global_link) { -/* TODO: Perhaps it shouldn't be gen6 specific */ -if (i915_is_ggtt (vm)) { -if (dev_priv->mm.aliasing_ppgtt) -gen6_write_pdes (dev_priv->mm.aliasing_ppgtt); -continue ; - } +if (USES_PPGTT (dev)) { +list_for_each_entry (vm, &dev_priv->vm_list, global_link) { +/* TODO: Perhaps it shouldn't be gen6 specific */ + +struct i915_hw_ppgtt *ppgtt = + container_of(vm, struct i915_hw_ppgtt, + base); -gen6_write_pdes (container_of(vm ,struct i915_hw_ppgtt ,base )); +if (i915_is_ggtt (vm)) + ppgtt = dev_priv->mm.aliasing_ppgtt; + +gen6_write_page_range (dev_priv, &ppgtt->pd,0 , + ppgtt->num_pd_entries); + } }i915_ggtt_flush (dev_priv);drivers/gpu/drm/i915/i915_gem_gtt.h +10
-0@@ -54,7 +54,10 @@ typedef gen8_gtt_pte_t gen8_ppgtt_pde_t;#define GEN6_PPGTT_PD_ENTRIES 512#define GEN6_PD_SIZE (GEN6_PPGTT_PD_ENTRIES * PAGE_SIZE)#define GEN6_PD_ALIGN (PAGE_SIZE * 16) +#define GEN6_PDE_SHIFT 22#define GEN6_PDE_VALID (1 << 0) +#define I915_PDE_MASK (GEN6_PPGTT_PD_ENTRIES-1) +#define NUM_PTE (pde_shift) (1 << (pde_shift - PAGE_SHIFT))#define GEN7_PTE_CACHE_L3_LLC (3 << 1)@@ -190,6 +193,8 @@ struct i915_vma {struct i915_page_table_entry {struct page *page;dma_addr_t daddr; + +unsigned long *used_ptes; };struct i915_page_directory_entry {@@ -246,6 +251,9 @@ struct i915_address_space {gen6_gtt_pte_t (*pte_encode)(dma_addr_t addr,enum i915_cache_level level,bool valid,u32 flags);/* Create a valid PTE */ +int (*allocate_va_range)(struct i915_address_space *vm, +uint64_t start, +uint64_t length); void (*clear_range)(struct i915_address_space *vm, uint64_t start, uint64_t length,@@ -298,12 +306,79 @@ struct i915_hw_ppgtt {struct drm_i915_file_private *file_priv; +gen6_gtt_pte_t __iomem *pd_addr; +int (*enable)(struct i915_hw_ppgtt *ppgtt);int (*switch_mm)(struct i915_hw_ppgtt *ppgtt,struct intel_engine_cs *ring);drivers/gpu/drm/i915/i915_gem_gtt.h struct i915_hw_ppgtt { · line 323
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_gtt.h +7
-0void (*debug_dump)(struct i915_hw_ppgtt *ppgtt,struct seq_file *m); }; +/* For each pde iterates over every pde between from start until start + length. +* If start, and start+length are not perfectly divisible, the macro will round +* down, and up as needed. The macro modifies pde, start, and length. Dev is +* only used to differentiate shift values. Temp is temp. On gen6/7, start = 0, +* and length = 2G effectively iterates over every PDE in the system. On gen8+ +* it simply iterates over every page directory entry in a page directory. +* There is nothing for gen8 in the macro yet, so comment is a bit misleading.
Quoted 27 lines
drivers/gpu/drm/i915/i915_gem_gtt.h +27
-0+* XXX: temp is not actually needed, but it saves doing the ALIGN operation. +*/ +#define gen6_for_each_pde (pt, pd, start, length, temp, iter) \ + for (iter = gen6_pde_index(start), pt = (pd)->page_table[iter]; \ + length > 0 && iter < GEN6_PPGTT_PD_ENTRIES; \ + pt = (pd)->page_table[++iter], \ + temp = ALIGN(start+1, 1 << GEN6_PDE_SHIFT) - start, \ + temp = min_t(unsigned, temp, length), \ + start += temp, length -= temp) + +static inline uint32_t i915_pte_index (uint64_t address,uint32_t pde_shift) +{ +const uint32_t mask =NUM_PTE (pde_shift) -1 ; + +return (address >>PAGE_SHIFT ) & mask; +} + +/* Helper to counts the number of PTEs within the given length. This count does +* not cross a page table boundary, so the max value would be +* I915_PPGTT_PT_ENTRIES for GEN6, and GEN8_PTES_PER_PAGE for GEN8. +*/ +static inline size_t i915_pte_count (uint64_t addr,size_t length, +uint32_t pde_shift) +{ +const uint64_t mask = ~((1 << pde_shift) -1 ); +uint64_t end; +drivers/gpu/drm/i915/i915_gem_gtt.h struct i915_hw_ppgtt { · line 360
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_gtt.h +10
-0+BUG_ON (length ==0 ); +BUG_ON (offset_in_page (addr|length)); + + end = addr + length; + +if ((addr & mask) != (end & mask)) +return NUM_PTE (pde_shift) -i915_pte_index (addr, pde_shift); + +return i915_pte_index (end, pde_shift) -i915_pte_index (addr, pde_shift); +}After trying to figure out the reasoning for this
i915_pte_countand it's role in the used bitmap setup, I started to wonder why all the complexity here.BUG_ON(offset_in_page(addr|length)) reveals that we can't be called with anything but a page boundary so the address parameter is irrelevant in here?
Then there is trickery with the
pde_shifting. I tried to find some generalization down the series to take advantage of this. Perhaps I missed it?For me it seems that we can replace this with simple:
Quoted 7 lines
static inline
uint32_ti915_pte_count(uint64_t length, uint32_t pte_len){ return min_t(uint32_t, length / PAGE_SIZE, PAGE_SIZE / pte_len); }...and not lose anything.
Oh we lose alot. The simplified version might work in the context of this patch but the macro will be broken. Michel explained it all to me in irc.
I apologize for this. Please ignore and keep the original i915_pte_count.
-Mika
Quoted 129 lines
On top of that when trying to wrap my brain around the differences between GEN6/7 and GEN8+ the following patch before this patch would make things much easier to understand, atleast for me:
drivers/gpu/drm/i915/i915_gem_gtt.h +31
-12@@ -36,13 +36,13 @@struct drm_i915_file_private ; -typedef uint32_t gen6_gtt_pte_t ; -typedef uint64_t gen8_gtt_pte_t ; -typedef gen8_gtt_pte_t gen8_ppgtt_pde_t ; +typedef uint32_t gen6_pte_t ; +typedef uint64_t gen8_pte_t ; +typedef uint64_t gen8_pde_t ;#define gtt_total_entries (gtt) ((gtt).base.total >> PAGE_SHIFT) -#define I915_PPGTT_PT_ENTRIES (PAGE_SIZE / sizeof(gen6_gtt_pte_t)) +/* gen6-hsw has bit 11-4 for physical addr bit 39-32 */ #define GEN6_GTT_ADDR_ENCODE (addr) ((addr) | (((addr) >> 28) & 0xff0))#define GEN6_PTE_ADDR_ENCODE (addr) GEN6_GTT_ADDR_ENCODE(addr)@@ -51,8 +51,13 @@ typedef gen8_gtt_pte_t gen8_ppgtt_pde_t;#define GEN6_PTE_UNCACHED (1 << 1)#define GEN6_PTE_VALID (1 << 0) -#define GEN6_PPGTT_PD_ENTRIES 512 -#define GEN6_PD_SIZE (GEN6_PPGTT_PD_ENTRIES * PAGE_SIZE) +#define I915_PTES (pte_len) (PAGE_SIZE / (pte_len)) +#define I915_PTE_MASK (pte_len) (I915_PTES(pte_len) - 1) +#define I915_PDES 512 +#define I915_PDE_MASK (I915_PDES - 1) + +#define GEN6_PTES I915_PTES(sizeof(gen6_pte_t)) +#define GEN6_PD_SIZE (I915_PDES * PAGE_SIZE)#define GEN6_PD_ALIGN (PAGE_SIZE * 16)#define GEN6_PDE_VALID (1 << 0)@@ -89,8 +94,7 @@ typedef gen8_gtt_pte_t gen8_ppgtt_pde_t;#define GEN8_PTE_SHIFT 12#define GEN8_PTE_MASK 0x1ff#define GEN8_LEGACY_PDPES 4 -#define GEN8_PTES_PER_PAGE (PAGE_SIZE / sizeof(gen8_gtt_pte_t)) -#define GEN8_PDES_PER_PAGE (PAGE_SIZE / sizeof(gen8_ppgtt_pde_t)) +#define GEN8_PTES I915_PTES(sizeof(gen8_pte_t))#define PPAT_UNCACHED_INDEX (_PAGE_PWT | _PAGE_PCD)#define PPAT_CACHED_PDE_INDEX 0/* WB LLC */ @@ -199,7 +203,7 @@ struct i915_page_directory_entry {dma_addr_t daddr; }; -struct i915_page_table_entry *page_table[GEN6_PPGTT_PD_ENTRIES ];/* PDEs */ +struct i915_page_table_entry *page_table[I915_PDES ];/* PDEs */ };struct i915_page_directory_pointer_entry {@@ -243,9 +247,9 @@ struct i915_address_space {struct list_head inactive_list;/* FIXME: Need a more generic return type */ -gen6_gtt_pte_t (*pte_encode)(dma_addr_t addr, -enum i915_cache_level level, -bool valid,u32 flags);/* Create a valid PTE */ +gen6_pte_t (*pte_encode)(dma_addr_t addr, +enum i915_cache_level level, +bool valid,u32 flags);/* Create a valid PTE */ void (*clear_range)(struct i915_address_space *vm, uint64_t start, uint64_t length,@@ -304,6 +308,21 @@ struct i915_hw_ppgtt {void (*debug_dump)(struct i915_hw_ppgtt *ppgtt,struct seq_file *m); }; +static inline uint32_t i915_pte_index (uint64_t address,uint32_t pte_len) +{ +return (address >>PAGE_SHIFT ) &I915_PTE_MASK (pte_len); +} + +static inline uint32_t i915_pte_count (uint64_t length,uint32_t pte_len) +{ +return min_t (uint32_t, length /PAGE_SIZE ,I915_PTES (pte_len)); +} + +static inline uint32_t i915_pde_index (uint64_t addr,uint32_t pde_shift) +{ +return (addr >> pde_shift) &I915_PDE_MASK ; +} +int i915_gem_gtt_init (struct drm_device *dev);void i915_gem_init_global_gtt (struct drm_device *dev);void i915_global_gtt_cleanup (struct drm_device *dev);With that, I think you could write generic
gen_for_each_pdemore easily and just parametrize the gen6 variant and gen8 one further in the series.--Mika
Quoted 26 lines
drivers/gpu/drm/i915/i915_gem_gtt.h +20
-0+static inline uint32_t i915_pde_index (uint64_t addr,uint32_t shift) +{ +return (addr >> shift) &I915_PDE_MASK ; +} + +static inline uint32_t gen6_pte_index (uint32_t addr) +{ +return i915_pte_index (addr,GEN6_PDE_SHIFT ); +} + +static inline size_t gen6_pte_count (uint32_t addr,uint32_t length) +{ +return i915_pte_count (addr, length,GEN6_PDE_SHIFT ); +} + +static inline uint32_t gen6_pde_index (uint32_t addr) +{ +return i915_pde_index (addr,GEN6_PDE_SHIFT ); +} +int i915_gem_gtt_init (struct drm_device *dev);void i915_gem_init_global_gtt (struct drm_device *dev);void i915_global_gtt_cleanup (struct drm_device *dev);Signature · 1 line
2.1.1
Quoted 8 lines
Quoted 4 lines
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 6/32 drm/i915: Extract context switch skip and pd load logic
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
We have some fanciness coming up. This patch just breaks out the logic of context switch skip, pd load pre, and pd load post.
v2: Use new functions to replace the logic right away (Daniel)
--- drivers/gpu/drm/i915/i915_gem_context.c | 40 +++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +31 -9
@@ -565,6 +565,33 @@ mi_set_context(struct intel_engine_cs *ring,return ret; } +static inline bool should_skip_switch (struct intel_engine_cs *ring, +struct intel_context *from, +struct intel_context *to) +{ +if (from == to && !to->remap_slice) +return true; + +return false; +} + +static bool +needs_pd_load_pre (struct intel_engine_cs *ring,struct intel_context *to) +{ +struct drm_i915_private *dev_priv = ring->dev->dev_private; + +return ((INTEL_INFO (ring->dev)->gen <8 ) || + (ring != &dev_priv->ring[RCS ])) && to->ppgtt; +} + +static bool +needs_pd_load_post (struct intel_engine_cs *ring,struct intel_context *to) +{ +return (!to->legacy_hw_ctx.initialized || +i915_gem_context_is_default (to)) && + to->ppgtt &&IS_GEN8 (ring->dev); +} +static int do_switch (struct intel_engine_cs *ring,struct intel_context *to) {
@@ -573,9 +600,6 @@ static int do_switch(struct intel_engine_cs *ring,u32 hw_flags =0 ;bool uninitialized = false;struct i915_vma *vma; -bool needs_pd_load_pre = ((INTEL_INFO (ring->dev)->gen <8 ) || - (ring != &dev_priv->ring[RCS ])) && to->ppgtt; -bool needs_pd_load_post = false;int ret, i;if (from !=NULL && ring == &dev_priv->ring[RCS ]) {
@@ -583,7 +607,7 @@ static int do_switch(struct intel_engine_cs *ring,BUG_ON (!i915_gem_obj_is_pinned (from->legacy_hw_ctx.rcs_state)); } -if (from == to && !to->remap_slice) +if (should_skip_switch (ring, from, to))return 0 ;/* Trying to pin first makes error handling easier. */
@@ -601,7 +625,7 @@ static int do_switch(struct intel_engine_cs *ring,*/ from = ring->last_context; -if (needs_pd_load_pre) { +if (needs_pd_load_pre (ring, to)) {/* Older GENs and non render rings still want the load first, * "PP_DCLV followed by PP_DIR_BASE register through Load * Register Immediate commands in Ring Buffer before submitting
@@ -646,16 +670,14 @@ static int do_switch(struct intel_engine_cs *ring,* XXX: If we implemented page directory eviction code, this * optimization needs to be removed. */ -if (!to->legacy_hw_ctx.initialized ||i915_gem_context_is_default (to)) { +if (!to->legacy_hw_ctx.initialized ||i915_gem_context_is_default (to)) hw_flags |=MI_RESTORE_INHIBIT ; - needs_pd_load_post = to->ppgtt &&IS_GEN8 (ring->dev); - } ret =mi_set_context (ring, to, hw_flags);if (ret) goto unpin_out; -if (needs_pd_load_post) { +if (needs_pd_load_post (ring, to)) { ret = to->ppgtt->switch_mm (to->ppgtt, ring);/* The hardware context switch is emitted, but we haven't * actually changed the state - so it's probably safe to bail
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v6 06/32] drm/i915: Extract context switch skip and pd load logic
Quoted 53 lines · Michel Thierry
From: Ben Widawsky <[email protected]>
We have some fanciness coming up. This patch just breaks out the logic of context switch skip, pd load pre, and pd load post.
v2: Use new functions to replace the logic right away (Daniel)
Cc Daniel Vetter <[email protected]>Signed-off-by Ben Widawsky <[email protected]>Signed-off-by Michel Thierry <[email protected]> (v2)--- drivers/gpu/drm/i915/i915_gem_context.c | 40 +++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 9 deletions(-)drivers/gpu/drm/i915/i915_gem_context.c +27
-0@@ -565,6 +565,33 @@ mi_set_context(struct intel_engine_cs *ring,return ret; } +static inline bool should_skip_switch (struct intel_engine_cs *ring, +struct intel_context *from, +struct intel_context *to) +{ +if (from == to && !to->remap_slice) +return true; + +return false; +} + +static bool +needs_pd_load_pre (struct intel_engine_cs *ring,struct intel_context *to) +{ +struct drm_i915_private *dev_priv = ring->dev->dev_private; + +return ((INTEL_INFO (ring->dev)->gen <8 ) || + (ring != &dev_priv->ring[RCS ])) && to->ppgtt; +} + +static bool +needs_pd_load_post (struct intel_engine_cs *ring,struct intel_context *to) +{ +return (!to->legacy_hw_ctx.initialized || +i915_gem_context_is_default (to)) && + to->ppgtt &&IS_GEN8 (ring->dev); +} +static int do_switch (struct intel_engine_cs *ring,struct intel_context *to) {
drivers/gpu/drm/i915/i915_gem_context.c static int do_switch(struct intel_engine_cs *ring, · line 578
Quoted 6 lines
drivers/gpu/drm/i915/i915_gem_context.c +0
-3@@ -573,9 +600,6 @@ static int do_switch(struct intel_engine_cs *ring,u32 hw_flags =0 ;bool uninitialized = false;struct i915_vma *vma; -bool needs_pd_load_pre = ((INTEL_INFO (ring->dev)->gen <8 ) || - (ring != &dev_priv->ring[RCS ])) && to->ppgtt; -bool needs_pd_load_post = false;
There is no such code in drm-intel-nightly. On top of which tree this is for?
-Mika
Quoted 47 lines
drivers/gpu/drm/i915/i915_gem_context.c +4
-6int ret, i;if (from !=NULL && ring == &dev_priv->ring[RCS ]) {@@ -583,7 +607,7 @@ static int do_switch(struct intel_engine_cs *ring,BUG_ON (!i915_gem_obj_is_pinned (from->legacy_hw_ctx.rcs_state)); } -if (from == to && !to->remap_slice) +if (should_skip_switch (ring, from, to))return 0 ;/* Trying to pin first makes error handling easier. */ @@ -601,7 +625,7 @@ static int do_switch(struct intel_engine_cs *ring,*/ from = ring->last_context; -if (needs_pd_load_pre) { +if (needs_pd_load_pre (ring, to)) {/* Older GENs and non render rings still want the load first, * "PP_DCLV followed by PP_DIR_BASE register through Load * Register Immediate commands in Ring Buffer before submitting @@ -646,16 +670,14 @@ static int do_switch(struct intel_engine_cs *ring,* XXX: If we implemented page directory eviction code, this * optimization needs to be removed. */ -if (!to->legacy_hw_ctx.initialized ||i915_gem_context_is_default (to)) { +if (!to->legacy_hw_ctx.initialized ||i915_gem_context_is_default (to)) hw_flags |=MI_RESTORE_INHIBIT ; - needs_pd_load_post = to->ppgtt &&IS_GEN8 (ring->dev); - } ret =mi_set_context (ring, to, hw_flags);if (ret) goto unpin_out; -if (needs_pd_load_post) { +if (needs_pd_load_post (ring, to)) { ret = to->ppgtt->switch_mm (to->ppgtt, ring);/* The hardware context switch is emitted, but we haven't * actually changed the state - so it's probably safe to bail Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 1/1 drm/i915: Extract context switch skip and add pd load logic
From: Ben Widawsky <[email protected]>
This patch just breaks out the logic of context switch skip.
It also adds pd load pre, and pd load post logic (for GEN8).
v2: Use new functions to replace the logic right away (Daniel)
v3: Add missing pd load logic.
--- drivers/gpu/drm/i915/i915_gem_context.c | 48 +++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +46 -2
@@ -569,6 +569,33 @@ mi_set_context(struct intel_engine_cs *ring,return ret; } +static inline bool should_skip_switch (struct intel_engine_cs *ring, +struct intel_context *from, +struct intel_context *to) +{ +if (from == to && !to->remap_slice) +return true; + +return false; +} + +static bool +needs_pd_load_pre (struct intel_engine_cs *ring,struct intel_context *to) +{ +struct drm_i915_private *dev_priv = ring->dev->dev_private; + +return ((INTEL_INFO (ring->dev)->gen <8 ) || + (ring != &dev_priv->ring[RCS ])) && to->ppgtt; +} + +static bool +needs_pd_load_post (struct intel_engine_cs *ring,struct intel_context *to) +{ +return (!to->legacy_hw_ctx.initialized || +i915_gem_context_is_default (to)) && + to->ppgtt &&IS_GEN8 (ring->dev); +} +static int do_switch (struct intel_engine_cs *ring,struct intel_context *to) {
@@ -584,7 +611,7 @@ static int do_switch(struct intel_engine_cs *ring,BUG_ON (!i915_gem_obj_is_pinned (from->legacy_hw_ctx.rcs_state)); } -if (from == to && !to->remap_slice) +if (should_skip_switch (ring, from, to))return 0 ;/* Trying to pin first makes error handling easier. */
@@ -602,7 +629,11 @@ static int do_switch(struct intel_engine_cs *ring,*/ from = ring->last_context; -if (to->ppgtt) { +if (needs_pd_load_pre (ring, to)) { +/* Older GENs and non render rings still want the load first, +* "PP_DCLV followed by PP_DIR_BASE register through Load +* Register Immediate commands in Ring Buffer before submitting +* a context."*/ trace_switch_mm (ring, to); ret = to->ppgtt->switch_mm (to->ppgtt, ring);if (ret)
@@ -644,6 +675,19 @@ static int do_switch(struct intel_engine_cs *ring,if (ret) goto unpin_out; +if (needs_pd_load_post (ring, to)) { + ret = to->ppgtt->switch_mm (to->ppgtt, ring); +/* The hardware context switch is emitted, but we haven't +* actually changed the state - so it's probably safe to bail +* here. Still, let the user know something dangerous has +* happened. +*/ +if (ret) { +DRM_ERROR ("Failed to change address space on context switch\n" ); + goto unpin_out; + } + } +for (i =0 ; i <MAX_L3_SLICES ; i++) {if (!(to->remap_slice & (1 <<i)))continue ;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH] drm/i915: Extract context switch skip and add pd load logic
Task id: 5853 -------------------------------------Summary-------------------------------------
Platform Delta drm-intel-nightly Series Applied
PNV 278/278 278/278 ILK 308/308 308/308 SNB 284/284 284/284 IVB 380/380 380/380 BYT 294/294 294/294 HSW -1 387/387 386/387 BDW -1 316/316 315/316
-------------------------------------Detailed-------------------------------------
Platform Test drm-intel-nightly Series Applied
*HSW igt_gem_storedw_loop_vebox PASS(1) DMESG_WARN(1)PASS(1)
*BDW igt_gem_gtt_hog PASS(8) DMESG_WARN(1)PASS(1)
Note: You need to pay more attention to line start with '*'
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH] drm/i915: Extract context switch skip and add pd load logic
In reply to Michel ThierryQuoted 6 lines · Michel Thierry
From: Ben Widawsky <[email protected]>
This patch just breaks out the logic of context switch skip.
It also adds pd load pre, and pd load post logic (for GEN8).
I dont think this patch just breaks out the logic but it changes it. And the reasons remains a mystery.
Could you please add justification why the logic changes are required?
Quoted 77 lines
v2: Use new functions to replace the logic right away (Daniel)
v3: Add missing pd load logic.Cc Daniel Vetter <[email protected]>Signed-off-by Ben Widawsky <[email protected]>Signed-off-by Michel Thierry <[email protected]> (v2+)--- drivers/gpu/drm/i915/i915_gem_context.c | 48 +++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/i915_gem_context.c +36
-2@@ -569,6 +569,33 @@ mi_set_context(struct intel_engine_cs *ring,return ret; } +static inline bool should_skip_switch (struct intel_engine_cs *ring, +struct intel_context *from, +struct intel_context *to) +{ +if (from == to && !to->remap_slice) +return true; + +return false; +} + +static bool +needs_pd_load_pre (struct intel_engine_cs *ring,struct intel_context *to) +{ +struct drm_i915_private *dev_priv = ring->dev->dev_private; + +return ((INTEL_INFO (ring->dev)->gen <8 ) || + (ring != &dev_priv->ring[RCS ])) && to->ppgtt; +} + +static bool +needs_pd_load_post (struct intel_engine_cs *ring,struct intel_context *to) +{ +return (!to->legacy_hw_ctx.initialized || +i915_gem_context_is_default (to)) && + to->ppgtt &&IS_GEN8 (ring->dev); +} +static int do_switch (struct intel_engine_cs *ring,struct intel_context *to) {@@ -584,7 +611,7 @@ static int do_switch(struct intel_engine_cs *ring,BUG_ON (!i915_gem_obj_is_pinned (from->legacy_hw_ctx.rcs_state)); } -if (from == to && !to->remap_slice) +if (should_skip_switch (ring, from, to))return 0 ;/* Trying to pin first makes error handling easier. */ @@ -602,7 +629,11 @@ static int do_switch(struct intel_engine_cs *ring,*/ from = ring->last_context; -if (to->ppgtt) { +if (needs_pd_load_pre (ring, to)) { +/* Older GENs and non render rings still want the load first, +* "PP_DCLV followed by PP_DIR_BASE register through Load +* Register Immediate commands in Ring Buffer before submitting +* a context."*/ trace_switch_mm (ring, to); ret = to->ppgtt->switch_mm (to->ppgtt, ring);if (ret)@@ -644,6 +675,19 @@ static int do_switch(struct intel_engine_cs *ring,if (ret) goto unpin_out; +if (needs_pd_load_post (ring, to)) { + ret = to->ppgtt->switch_mm (to->ppgtt, ring); +/* The hardware context switch is emitted, but we haven't
drivers/gpu/drm/i915/i915_gem_context.c static int do_switch(struct intel_engine_cs *ring, · line 690
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_context.c +10
-0+* actually changed the state - so it's probably safe to bail +* here. Still, let the user know something dangerous has +* happened. +*/ +if (ret) { +DRM_ERROR ("Failed to change address space on context switch\n" ); + goto unpin_out; + } + } +
Can there be a context where both pd load pre and pd load post is needed? If not, please consider adding WARN_ON which trigger is when we emit switch_mm twice due to both being true.
Thanks,
-Mika
Quoted 5 lines
drivers/gpu/drm/i915/i915_gem_context.c +0
-0for (i =0 ; i <MAX_L3_SLICES ; i++) {if (!(to->remap_slice & (1 <<i)))continue ;Signature · 1 line
2.1.1
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 7/32 drm/i915: Track page table reload need
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
This patch was formerly known as, "Force pd restore when PDEs change, gen6-7." I had to change the name because it is needed for GEN8 too.
The real issue this is trying to solve is when a new object is mapped into the current address space. The GPU does not snoop the new mapping so we must do the gen specific action to reload the page tables.
GEN8 and GEN7 do differ in the way they load page tables for the RCS. GEN8 does so with the context restore, while GEN7 requires the proper load commands in the command streamer. Non-render is similar for both.
Caveat for GEN7
The docs say you cannot change the PDEs of a currently running context. We never map new PDEs of a running context, and expect them to be present - so I think this is okay. (We can unmap, but this should also be okay since we only unmap unreferenced objects that the GPU shouldn't be tryingto va->pa xlate.) The MI_SET_CONTEXT command does have a flag to signal that even if the context is the same, force a reload. It's unclear exactly what this does, but I have a hunch it's the right thing to do.
The logic assumes that we always emit a context switch after mapping new PDEs, and before we submit a batch. This is the case today, and has been the case since the inception of hardware contexts. A note in the comment let's the user know.
It's not just for gen8. If the current context has mappings change, we need a context reload to switch
v2: Rebased after ppgtt clean up patches. Split the warning for aliasing and true ppgtt options. And do not break aliasing ppgtt, where to->ppgtt is always null.
v3: Invalidate PPGTT TLBs inside alloc_va_range.
v4: Rename ppgtt_invalidate_tlbs to mark_tlbs_dirty and move pd_dirty_rings from i915_address_space to i915_hw_ppgtt. Fixes when neither ctx->ppgtt and aliasing_ppgtt exist.
v5: Removed references to teardown_va_range.
--- drivers/gpu/drm/i915/i915_gem_context.c | 29 ++++++++++++++++++++++++----- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 11 +++++++++++ drivers/gpu/drm/i915/i915_gem_gtt.c | 11 +++++++++++ drivers/gpu/drm/i915/i915_gem_gtt.h | 1 + 4 files changed, 47 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +24 -5
@@ -569,8 +569,20 @@ static inline bool should_skip_switch(struct intel_engine_cs *ring,struct intel_context *from, struct intel_context *to) { -if (from == to && !to->remap_slice) -return true; + struct drm_i915_private *dev_priv = ring->dev->dev_private; + +if (to->remap_slice) +return false; + +if (to->ppgtt) { +if (from == to && !test_bit (ring->id, + &to->ppgtt->pd_dirty_rings)) +return true; + }else if (dev_priv->mm.aliasing_ppgtt) { +if (from == to && !test_bit (ring->id, + &dev_priv->mm.aliasing_ppgtt->pd_dirty_rings)) +return true; + }return false; }
@@ -587,9 +599,8 @@ needs_pd_load_pre(struct intel_engine_cs *ring, struct intel_context *to)static bool needs_pd_load_post (struct intel_engine_cs *ring,struct intel_context *to) { -return (!to->legacy_hw_ctx.initialized || -i915_gem_context_is_default (to)) && - to->ppgtt &&IS_GEN8 (ring->dev); +return IS_GEN8 (ring->dev) && + (to->ppgtt || &to->ppgtt->pd_dirty_rings); } static int do_switch(struct intel_engine_cs *ring,
@@ -634,6 +645,12 @@ static int do_switch(struct intel_engine_cs *ring, ret = to->ppgtt->switch_mm (to->ppgtt, ring);if (ret) goto unpin_out; + +/* Doing a PD load always reloads the page dirs */ +if (to->ppgtt) +clear_bit (ring->id, &to->ppgtt->pd_dirty_rings); +else +clear_bit (ring->id, &dev_priv->mm.aliasing_ppgtt->pd_dirty_rings); }if (ring != &dev_priv->ring[RCS ]) {
@@ -672,6 +689,8 @@ static int do_switch(struct intel_engine_cs *ring,*/ if (!to->legacy_hw_ctx.initialized ||i915_gem_context_is_default (to)) hw_flags |=MI_RESTORE_INHIBIT ; +else if (to->ppgtt &&test_and_clear_bit (ring->id, &to->ppgtt->pd_dirty_rings)) + hw_flags |=MI_FORCE_RESTORE ; ret =mi_set_context (ring, to, hw_flags);if (ret)
drivers/gpu/drm/i915/i915_gem_execbuffer.c +11 -0
@@ -1187,6 +1187,13 @@ i915_gem_ringbuffer_submission(struct drm_device *dev, struct drm_file *file,if (ret) goto error; +if (ctx->ppgtt) +WARN (ctx->ppgtt->pd_dirty_rings & (1 <<ring->id), +"%s didn't clear reload\n" , ring->name); +else if (dev_priv->mm.aliasing_ppgtt) +WARN (dev_priv->mm.aliasing_ppgtt->pd_dirty_rings & + (1 <<ring->id),"%s didn't clear reload\n" , ring->name); + instp_mode = args->flags &I915_EXEC_CONSTANTS_MASK ; instp_mask =I915_EXEC_CONSTANTS_MASK ;switch (instp_mode) {
@@ -1456,6 +1463,10 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,if (ret) goto err; +/* XXX: Reserve has possibly change PDEs which means we must do a +* context switch before we can coherently read some of the reserved +* VMAs. */ +/* The objects are in their final locations, apply the relocations. */ if (need_relocs) ret =i915_gem_execbuffer_relocate (eb);
drivers/gpu/drm/i915/i915_gem_gtt.c +11 -0
@@ -1151,6 +1151,16 @@ static void gen6_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt) 4096, PCI_DMA_BIDIRECTIONAL); } +/* PDE TLBs are a pain invalidate pre GEN8. It requires a context reload. If we +* are switching between contexts with the same LRCA, we also must do a force +* restore. +*/ +static inline void mark_tlbs_dirty (struct i915_hw_ppgtt *ppgtt) +{ +/* If current vm != vm, */ + ppgtt->pd_dirty_rings =INTEL_INFO (ppgtt->base.dev)->ring_mask; +} +static int gen6_alloc_va_range (struct i915_address_space *vm,uint64_t start,uint64_t length) {
@@ -1170,6 +1180,7 @@ static int gen6_alloc_va_range(struct i915_address_space *vm, I915_PPGTT_PT_ENTRIES); } +mark_tlbs_dirty (ppgtt);return 0 ; }
drivers/gpu/drm/i915/i915_gem_gtt.h +1 -0
@@ -297,6 +297,7 @@ struct i915_hw_ppgtt {struct i915_address_space base;struct kref ref;struct drm_mm_node node; +unsigned long pd_dirty_rings;unsigned num_pd_entries;unsigned num_pd_pages;/* gen8+ */ union {
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 8/32 drm/i915: Initialize all contexts
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
The problem is we're going to switch to a new context, which could be the default context. The plan was to use restore inhibit, which would be fine, except if we are using dynamic page tables (which we will). If we use dynamic page tables and we don't load new page tables, the previous page tables might go away, and future operations will fault.
CTXA runs.
switch to default, restore inhibit
CTXA dies and has its address space taken away.
Run CTXB, tries to save using the context A's address space - this fails.
The general solution is to make sure every context has it's own state, and its own address space. For cases when we must restore inhibit, first thing we do is load a valid address space. I thought this would be enough, but apparently there are references within the context itself which will refer to the old address space - therefore, we also must reinitialize.
It was tricky to track this down as we don't have much insight into what happens in a context save.
This is required for the next patch which enables dynamic page tables.
v2: to->ppgtt is only valid in full ppgtt.
--- drivers/gpu/drm/i915/i915_gem_context.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +11 -14
@@ -596,13 +596,6 @@ needs_pd_load_pre(struct intel_engine_cs *ring, struct intel_context *to) (ring != &dev_priv->ring[RCS])) && to->ppgtt; } -static bool -needs_pd_load_post (struct intel_engine_cs *ring,struct intel_context *to) -{ -return IS_GEN8 (ring->dev) && - (to->ppgtt || &to->ppgtt->pd_dirty_rings); -} -static int do_switch (struct intel_engine_cs *ring,struct intel_context *to) {
@@ -683,20 +676,24 @@ static int do_switch(struct intel_engine_cs *ring,/* GEN8 does *not* require an explicit reload if the PDPs have been * setup, and we do not wish to move them. -* -* XXX: If we implemented page directory eviction code, this -* optimization needs to be removed. */ -if (!to->legacy_hw_ctx.initialized ||i915_gem_context_is_default (to)) +if (!to->legacy_hw_ctx.initialized) { hw_flags |=MI_RESTORE_INHIBIT ; -else if (to->ppgtt &&test_and_clear_bit (ring->id, &to->ppgtt->pd_dirty_rings)) +/* NB: If we inhibit the restore, the context is not allowed to +* die because future work may end up depending on valid address +* space. This means we must enforce that a page table load +* occur when this occurs. */ + }else if (to->ppgtt &&test_and_clear_bit (ring->id, &to->ppgtt->pd_dirty_rings)) hw_flags |=MI_FORCE_RESTORE ; ret =mi_set_context (ring, to, hw_flags);if (ret) goto unpin_out; -if (needs_pd_load_post (ring, to)) { +if (IS_GEN8 (ring->dev) && to->ppgtt && (hw_flags &MI_RESTORE_INHIBIT )) { +/* We have a valid page directory (scratch) to switch to. This +* allows the old VM to be freed. Note that if anything occurs +* between the set context, and here, we are f*cked */ ret = to->ppgtt->switch_mm (to->ppgtt, ring);/* The hardware context switch is emitted, but we haven't * actually changed the state - so it's probably safe to bail
@@ -746,7 +743,7 @@ static int do_switch(struct intel_engine_cs *ring,i915_gem_context_unreference (from); } - uninitialized = !to->legacy_hw_ctx.initialized && from ==NULL ; + uninitialized = !to->legacy_hw_ctx.initialized; to->legacy_hw_ctx.initialized = true; done:
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 1/1 drm/i915: Initialize all contexts
From: Ben Widawsky <[email protected]>
The problem is we're going to switch to a new context, which could be the default context. The plan was to use restore inhibit, which would be fine, except if we are using dynamic page tables (which we will). If we use dynamic page tables and we don't load new page tables, the previous page tables might go away, and future operations will fault.
CTXA runs.
switch to default, restore inhibit
CTXA dies and has its address space taken away.
Run CTXB, tries to save using the context A's address space - this fails.
The general solution is to make sure every context has it's own state, and its own address space. For cases when we must restore inhibit, first thing we do is load a valid address space. I thought this would be enough, but apparently there are references within the context itself which will refer to the old address space - therefore, we also must reinitialize.
It was tricky to track this down as we don't have much insight into what happens in a context save.
This is required for the next patch which enables dynamic page tables.
v2: to->ppgtt is only valid in full ppgtt.
v3: Rebased.
--- drivers/gpu/drm/i915/i915_gem_context.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +14 -11
@@ -600,13 +600,6 @@ needs_pd_load_pre(struct intel_engine_cs *ring, struct intel_context *to) (ring != &dev_priv->ring[RCS])) && to->ppgtt; } -static bool -needs_pd_load_post (struct intel_engine_cs *ring,struct intel_context *to) -{ -return IS_GEN8 (ring->dev) && - (to->ppgtt || &to->ppgtt->pd_dirty_rings); -} -static int do_switch (struct intel_engine_cs *ring,struct intel_context *to) {
@@ -685,16 +678,26 @@ static int do_switch(struct intel_engine_cs *ring, goto unpin_out; } -if (!to->legacy_hw_ctx.initialized ||i915_gem_context_is_default (to)) +/* GEN8 does *not* require an explicit reload if the PDPs have been +* setup, and we do not wish to move them. +*/ +if (!to->legacy_hw_ctx.initialized) { hw_flags |=MI_RESTORE_INHIBIT ; -else if (to->ppgtt &&test_and_clear_bit (ring->id, &to->ppgtt->pd_dirty_rings)) +/* NB: If we inhibit the restore, the context is not allowed to +* die because future work may end up depending on valid address +* space. This means we must enforce that a page table load +* occur when this occurs. */ + }else if (to->ppgtt &&test_and_clear_bit (ring->id, &to->ppgtt->pd_dirty_rings)) hw_flags |=MI_FORCE_RESTORE ; ret =mi_set_context (ring, to, hw_flags);if (ret) goto unpin_out; -if (needs_pd_load_post (ring, to)) { +if (IS_GEN8 (ring->dev) && to->ppgtt && (hw_flags &MI_RESTORE_INHIBIT )) { +/* We have a valid page directory (scratch) to switch to. This +* allows the old VM to be freed. Note that if anything occurs +* between the set context, and here, we are f*cked */ ret = to->ppgtt->switch_mm (to->ppgtt, ring);/* The hardware context switch is emitted, but we haven't * actually changed the state - so it's probably safe to bail
@@ -744,7 +747,7 @@ static int do_switch(struct intel_engine_cs *ring,i915_gem_context_unreference (from); } - uninitialized = !to->legacy_hw_ctx.initialized && from ==NULL ; + uninitialized = !to->legacy_hw_ctx.initialized; to->legacy_hw_ctx.initialized = true; done:
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH] drm/i915: Initialize all contexts
Quoted 21 lines · Michel Thierry
From: Ben Widawsky <[email protected]>
The problem is we're going to switch to a new context, which could be the default context. The plan was to use restore inhibit, which would be fine, except if we are using dynamic page tables (which we will). If we use dynamic page tables and we don't load new page tables, the previous page tables might go away, and future operations will fault.
CTXA runs.
switch to default, restore inhibit
CTXA dies and has its address space taken away.
Run CTXB, tries to save using the context A's address space - this fails.The general solution is to make sure every context has it's own state, and its own address space. For cases when we must restore inhibit, first thing we do is load a valid address space. I thought this would be enough, but apparently there are references within the context itself which will refer to the old address space - therefore, we also must reinitialize.
Quoted 4 lines
It was tricky to track this down as we don't have much insight into what happens in a context save.
This is required for the next patch which enables dynamic page tables.
This sneaks in a major change that is not mentioned at all above. Namely:
drivers/gpu/drm/i915/i915_gem_context.c static int do_switch(struct intel_engine_cs *ring, · line 751
Quoted 7 lines
drivers/gpu/drm/i915/i915_gem_context.c +1
-1@@ -744,7 +747,7 @@ static int do_switch(struct intel_engine_cs *ring,i915_gem_context_unreference (from); } - uninitialized = !to->legacy_hw_ctx.initialized && from ==NULL ; + uninitialized = !to->legacy_hw_ctx.initialized; to->legacy_hw_ctx.initialized = true;
That has nothing to do with VM spaces, but with w/a that need to be applied to the context image.
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 9/32 drm/i915: Finish gen6/7 dynamic page table allocation
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
This patch continues on the idea from the previous patch. From here on, in the steady state, PDEs are all pointing to the scratch page table (as recommended in the spec). When an object is allocated in the VA range, the code will determine if we need to allocate a page for the page table. Similarly when the object is destroyed, we will remove, and free the page table pointing the PDE back to the scratch page.
Following patches will work to unify the code a bit as we bring in GEN8 support. GEN6 and GEN8 are different enough that I had a hard time to get to this point with as much common code as I do.
The aliasing PPGTT must pre-allocate all of the page tables. There are a few reasons for this. Two trivial ones: aliasing ppgtt goes through the ggtt paths, so it's hard to maintain, we currently do not restore the default context (assuming the previous force reload is indeed necessary). Most importantly though, the only way (it seems from empirical evidence) to invalidate the CS TLBs on non-render ring is to either use ring sync (which requires actually stopping the rings in order to synchronize when the sync completes vs. where you are in execution), or to reload DCLV. Since without full PPGTT we do not ever reload the DCLV register, there is no good way to achieve this. The simplest solution is just to not support dynamic page table creation/destruction in the aliasing PPGTT.
We could always reload DCLV, but this seems like quite a bit of excess overhead only to save at most 2MB-4k of memory for the aliasing PPGTT page tables.
v2: Make the page table bitmap declared inside the function (Chris) Simplify the way scratching address space works.
Move the alloc/teardown tracepoints up a level in the call stack so that both all implementations get the trace.
v3: Updated trace event to spit out a name
v4: Aliasing ppgtt is now initialized differently (in setup global gtt)
v5: Rebase to latest code. Also removed unnecessary aliasing ppgtt check for trace, as it is no longer possible after the PPGTT cleanup patch series of a couple of months ago (Daniel).
v6: Implement changes from code review (Daniel):
- allocate/teardown_va_range calls added.
- Add a scratch page allocation helper (only need the address).
- Move trace events to a new patch.
- Use updated mark_tlbs_dirty.
- Moved pt preallocation for aliasing ppgtt into gen6_ppgtt_init.
v7: teardown_va_range removed (Daniel).
In init, gen6_ppgtt_clear_range call is only needed for aliasing ppgtt.
v8: Rebase after s/page_tables/page_table/.
--- drivers/gpu/drm/i915/i915_debugfs.c | 3 +- drivers/gpu/drm/i915/i915_gem.c | 9 +++ drivers/gpu/drm/i915/i915_gem_gtt.c | 125 +++++++++++++++++++++++++++++++----- drivers/gpu/drm/i915/i915_gem_gtt.h | 3 + 4 files changed, 123 insertions(+), 17 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +2 -1
@@ -2181,6 +2181,8 @@ static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)seq_printf (m,"PP_DIR_BASE_READ: 0x%08x\n" ,I915_READ (RING_PP_DIR_BASE_READ (ring)));seq_printf (m,"PP_DIR_DCLV: 0x%08x\n" ,I915_READ (RING_PP_DIR_DCLV (ring))); } +seq_printf (m,"ECOCHK: 0x%08x\n\n" ,I915_READ (GAM_ECOCHK )); +if (dev_priv->mm.aliasing_ppgtt) {struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
@@ -2197,7 +2199,6 @@ static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev) get_pid_task(file->pid, PIDTYPE_PID)->comm);idr_for_each (&file_priv->context_idr, per_file_ctx, m); } -seq_printf (m,"ECOCHK: 0x%08x\n" ,I915_READ (GAM_ECOCHK )); }static int i915_ppgtt_info (struct seq_file *m,void *data)
drivers/gpu/drm/i915/i915_gem.c +9 -0
@@ -3599,6 +3599,15 @@ search_free:if (ret) goto err_remove_node; +/* allocate before insert / bind */ +if (vma->vm->allocate_va_range) { + ret = vma->vm->allocate_va_range (vma->vm, + vma->node.start, + vma->node.size); +if (ret) + goto err_remove_node; + } +trace_i915_vma_bind (vma, flags); ret =i915_vma_bind (vma, obj->cache_level, flags &PIN_GLOBAL ?GLOBAL_BIND :0 );
drivers/gpu/drm/i915/i915_gem_gtt.c +109 -16
217 lines not on this page · raw message
drivers/gpu/drm/i915/i915_gem_gtt.h +3 -0
@@ -195,6 +195,7 @@ struct i915_page_table_entry {dma_addr_t daddr;unsigned long *used_ptes; + unsigned int scratch:1; };struct i915_page_directory_entry {
@@ -305,6 +306,8 @@ struct i915_hw_ppgtt {struct i915_page_directory_entry pd; }; +struct i915_page_table_entry *scratch_pt; +struct drm_i915_file_private *file_priv;gen6_gtt_pte_t __iomem *pd_addr;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 10/32 drm/i915: Add dynamic page trace events
In reply to Michel ThierryTraces for page directories and tables allocation and map.
v2: Removed references to teardown.
v3: bitmap_scnprintf has been deprecated.
--- drivers/gpu/drm/i915/i915_gem.c | 2 + drivers/gpu/drm/i915/i915_gem_gtt.c | 5 ++ drivers/gpu/drm/i915/i915_trace.h | 95 +++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+)
drivers/gpu/drm/i915/i915_gem.c +2 -0
@@ -3601,6 +3601,8 @@ search_free:/* allocate before insert / bind */ if (vma->vm->allocate_va_range) { +trace_i915_va_alloc (vma->vm, vma->node.start, vma->node.size, +VM_TO_TRACE_NAME (vma->vm)); ret = vma->vm->allocate_va_range (vma->vm, vma->node.start, vma->node.size);
drivers/gpu/drm/i915/i915_gem_gtt.c +5 -0
@@ -1210,6 +1210,7 @@ static int gen6_alloc_va_range(struct i915_address_space *vm, ppgtt->pd.page_table[pde] = pt;set_bit (pde, new_page_tables); +trace_i915_page_table_entry_alloc (vm, pde, start,GEN6_PDE_SHIFT ); } start = start_save;
@@ -1225,6 +1226,10 @@ static int gen6_alloc_va_range(struct i915_address_space *vm,if (test_and_clear_bit (pde, new_page_tables))gen6_write_pde (&ppgtt->pd, pde, pt); +trace_i915_page_table_entry_map (vm, pde, pt, +gen6_pte_index (start), +gen6_pte_count (start, length), +I915_PPGTT_PT_ENTRIES );bitmap_or (pt->used_ptes, tmp_bitmap, pt->used_ptes,I915_PPGTT_PT_ENTRIES ); }
drivers/gpu/drm/i915/i915_trace.h +95 -0
101 lines not on this page · raw message
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v6 10/32] drm/i915: Add dynamic page trace events
Quoted 53 lines · Michel Thierry
Traces for page directories and tables allocation and map.
v2: Removed references to teardown.
v3:bitmap_scnprintfhas been deprecated.Signed-off-by Michel Thierry <[email protected]>--- drivers/gpu/drm/i915/i915_gem.c | 2 + drivers/gpu/drm/i915/i915_gem_gtt.c | 5 ++ drivers/gpu/drm/i915/i915_trace.h | 95 +++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+)drivers/gpu/drm/i915/i915_gem.c +2
-0@@ -3601,6 +3601,8 @@ search_free:/* allocate before insert / bind */ if (vma->vm->allocate_va_range) { +trace_i915_va_alloc (vma->vm, vma->node.start, vma->node.size, +VM_TO_TRACE_NAME (vma->vm)); ret = vma->vm->allocate_va_range (vma->vm, vma->node.start, vma->node.size);drivers/gpu/drm/i915/i915_gem_gtt.c +5
-0@@ -1210,6 +1210,7 @@ static int gen6_alloc_va_range(struct i915_address_space *vm, ppgtt->pd.page_table[pde] = pt;set_bit (pde, new_page_tables); +trace_i915_page_table_entry_alloc (vm, pde, start,GEN6_PDE_SHIFT ); } start = start_save;@@ -1225,6 +1226,10 @@ static int gen6_alloc_va_range(struct i915_address_space *vm,if (test_and_clear_bit (pde, new_page_tables))gen6_write_pde (&ppgtt->pd, pde, pt); +trace_i915_page_table_entry_map (vm, pde, pt, +gen6_pte_index (start), +gen6_pte_count (start, length), +I915_PPGTT_PT_ENTRIES );bitmap_or (pt->used_ptes, tmp_bitmap, pt->used_ptes,I915_PPGTT_PT_ENTRIES ); }drivers/gpu/drm/i915/i915_trace.h +0
-0
drivers/gpu/drm/i915/i915_trace.h TRACE_EVENT(i915_vma_unbind, · line 161
Quoted 6 lines
drivers/gpu/drm/i915/i915_trace.h +3
-0@@ -156,6 +156,101 @@ TRACE_EVENT(i915_vma_unbind, __entry->obj, __entry->offset, __entry->size, __entry->vm) ); +#define VM_TO_TRACE_NAME (vm) \ + (i915_is_ggtt(vm) ? "GGTT" : \ + "Private VM")
"G" and "P" would suffice but it is matter of taste.
Quoted 5 lines
drivers/gpu/drm/i915/i915_trace.h +5
-0+DECLARE_EVENT_CLASS(i915_va, + TP_PROTO(struct i915_address_space *vm, u64 start, u64 length, const char *name), + TP_ARGS(vm, start, length, name), + + TP_STRUCT__entry(
drivers/gpu/drm/i915/i915_trace.h TRACE_EVENT(i915_vma_unbind, · line 177
Quoted 10 lines
drivers/gpu/drm/i915/i915_trace.h +10
-0+ __field(struct i915_address_space *, vm) + __field(u64, start) + __field(u64, end) + __string(name, name) + ), + +TP_fast_assign ( + __entry->vm = vm; + __entry->start = start; + __entry->end = start + length;
__entry->end = start + length - 1;
Quoted 19 lines
drivers/gpu/drm/i915/i915_trace.h +19
-0+__assign_str (name, name); + ), + +TP_printk ("vm=%p (%s), 0x%llx-0x%llx" , + __entry->vm,__get_str (name), __entry->start, __entry->end) +); + +DEFINE_EVENT (i915_va, i915_va_alloc, + TP_PROTO(struct i915_address_space *vm, u64 start, u64 length, const char *name), +TP_ARGS (vm, start, length, name) +); + +DECLARE_EVENT_CLASS(i915_page_table_entry, + TP_PROTO(struct i915_address_space *vm, u32 pde, u64 start, u64 pde_shift), + TP_ARGS(vm, pde, start, pde_shift), + + TP_STRUCT__entry( + __field(struct i915_address_space *, vm) + __field(u32, pde)
drivers/gpu/drm/i915/i915_trace.h TRACE_EVENT(i915_vma_unbind,
Quoted 10 lines
drivers/gpu/drm/i915/i915_trace.h +9
-0+ __field(u64, start) +__field (u64, end) + ), + +TP_fast_assign ( + __entry->vm = vm; + __entry->pde = pde; + __entry->start = start; + __entry->end = (start + (1ULL << pde_shift)) & ~((1ULL << pde_shift)-1 );
-1 for her also?
Quoted 6 lines
drivers/gpu/drm/i915/i915_trace.h +6
-0+ ), + +TP_printk ("vm=%p, pde=%d (0x%llx-0x%llx)" , + __entry->vm, __entry->pde, __entry->start, __entry->end) +); +
drivers/gpu/drm/i915/i915_trace.h TRACE_EVENT(i915_vma_unbind, · line 221
Quoted 10 lines
drivers/gpu/drm/i915/i915_trace.h +10
-0+DEFINE_EVENT (i915_page_table_entry, i915_page_table_entry_alloc, + TP_PROTO(struct i915_address_space *vm, u32 pde, u64 start, u64 pde_shift), +TP_ARGS (vm, pde, start, pde_shift) +); + +/* Avoid extra math because we only support two sizes. The format is defined by +* bitmap_scnprintf. Each 32 bits is 8 HEX digits followed by comma */ +#define TRACE_PT_SIZE (bits) \ + ((((bits) == 1024) ? 288 : 144) + 1) +
This seems to be calculating the length of the output string, not the bitmap size.
drivers/gpu/drm/i915/i915_trace.h TRACE_EVENT(i915_vma_unbind, · line 232
Quoted 11 lines
drivers/gpu/drm/i915/i915_trace.h +11
-0+DECLARE_EVENT_CLASS(i915_page_table_entry_update, + TP_PROTO(struct i915_address_space *vm, u32 pde, + struct i915_page_table_entry *pt, u32 first, u32 len, size_t bits), + TP_ARGS(vm, pde, pt, first, len, bits), + + TP_STRUCT__entry( + __field(struct i915_address_space *, vm) + __field(u32, pde) + __field(u32, first) + __field(u32, last) + __bitmask(cur_ptes, TRACE_PT_SIZE(bits))
..and this seems wrong.
__bitmask(cur_ptes, bits);
And I would replace size_t with u32 throughout the patch.
drivers/gpu/drm/i915/i915_trace.h TRACE_EVENT(i915_vma_unbind, · line 239
Quoted 7 lines
drivers/gpu/drm/i915/i915_trace.h +7
-0+ ), + + TP_fast_assign( + __entry->vm = vm; + __entry->pde = pde; + __entry->first = first; + __entry->last = first + len;
It is not len that we are getting but count. So please rename the argument and
__entry->last = first + count - 1;
-Mika
Quoted 24 lines
drivers/gpu/drm/i915/i915_trace.h +14
-0+__assign_bitmask (cur_ptes, pt->used_ptes, bits); + ), + +TP_printk ("vm=%p, pde=%d, updating %u:%u\t%s" , + __entry->vm, __entry->pde, __entry->last, __entry->first, +__get_bitmask (cur_ptes)) +); + +DEFINE_EVENT (i915_page_table_entry_update, i915_page_table_entry_map, + TP_PROTO(struct i915_address_space *vm, u32 pde, + struct i915_page_table_entry *pt, u32 first, u32 len, size_t bits), +TP_ARGS (vm, pde, pt, first, len, bits) +); + TRACE_EVENT(i915_gem_object_change_domain, TP_PROTO(struct drm_i915_gem_object *obj, u32 old_read, u32 old_write), TP_ARGS(obj, old_read, old_write),Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 11/32 drm/i915/bdw: Use dynamic allocation idioms on free
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
The page directory freer is left here for now as it's still useful given that GEN8 still preallocates. Once the allocation functions are broken up into more discrete chunks, we'll follow suit and destroy this leftover piece.
v2: Match trace_i915_va_teardown params
v3: Multiple rebases.
v4: Updated to use unmap_and_free_pt.
v5: teardown_va_range logic no longer needed.
v6: Rebase after s/page_tables/page_table/.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 26 ++++++++++---------- drivers/gpu/drm/i915/i915_gem_gtt.h | 47 +++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 13 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +13 -13
@@ -607,19 +607,6 @@ static void gen8_free_page_tables(struct i915_page_directory_entry *pd, struct d } } -static void gen8_ppgtt_free (struct i915_hw_ppgtt *ppgtt) -{ -int i; - -for (i =0 ; i < ppgtt->num_pd_pages; i++) { -if (WARN_ON (!ppgtt->pdp.page_directory[i])) -continue ; - -gen8_free_page_tables (ppgtt->pdp.page_directory[i], ppgtt->base.dev); -unmap_and_free_pd (ppgtt->pdp.page_directory[i]); - } -} -static void gen8_ppgtt_unmap_pages (struct i915_hw_ppgtt *ppgtt) {struct pci_dev *hwdev = ppgtt->base.dev->pdev;
@@ -652,6 +639,19 @@ static void gen8_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt) } } +static void gen8_ppgtt_free (struct i915_hw_ppgtt *ppgtt) +{ +int i; + +for (i =0 ; i < ppgtt->num_pd_pages; i++) { +if (WARN_ON (!ppgtt->pdp.page_directory[i])) +continue ; + +gen8_free_page_tables (ppgtt->pdp.page_directory[i], ppgtt->base.dev); +unmap_and_free_pd (ppgtt->pdp.page_directory[i]); + } +} +static void gen8_ppgtt_cleanup (struct i915_address_space *vm) { struct i915_hw_ppgtt *ppgtt =
drivers/gpu/drm/i915/i915_gem_gtt.h +47 -0
53 lines not on this page · raw message
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 12/32 drm/i915/bdw: page directories rework allocation
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
Start using gen8_for_each_pdpe macro to allocate the page directories.
v2: Rebased after s/free_pt_*/unmap_and_free_pt/ change.
v3: Rebased after teardown va range logic was removed.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 43 ++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 13 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +30 -13
@@ -681,25 +681,39 @@ unwind_out:return -ENOMEM ; } -static int gen8_ppgtt_allocate_page_directories (struct i915_hw_ppgtt *ppgtt, -const int max_pdp) +static int gen8_ppgtt_alloc_page_directories (struct i915_page_directory_pointer_entry *pdp, +uint64_t start, +uint64_t length) { -int i; - -for (i =0 ; i < max_pdp; i++) { - ppgtt->pdp.page_directory[i] =alloc_pd_single (); -if (IS_ERR (ppgtt->pdp.page_directory[i])) +struct i915_hw_ppgtt *ppgtt = + container_of(pdp, struct i915_hw_ppgtt, pdp); +struct i915_page_directory_entry *unused; +uint64_t temp; +uint32_t pdpe; + +/* FIXME: PPGTT container_of won't work for 64b */ +BUG_ON ((start + length) >0x800000000ULL ); + +gen8_for_each_pdpe (unused, pdp, start, length, temp, pdpe) { +BUG_ON (unused); + pdp->page_directory[pdpe] =alloc_pd_single (); +if (IS_ERR (ppgtt->pdp.page_directory[pdpe])) goto unwind_out; + + ppgtt->num_pd_pages++; } - ppgtt->num_pd_pages = max_pdp;BUG_ON (ppgtt->num_pd_pages >GEN8_LEGACY_PDPES );return 0 ; unwind_out: -while (i--) -unmap_and_free_pd (ppgtt->pdp.page_directory[i]); +while (pdpe--) { +unmap_and_free_pd (ppgtt->pdp.page_directory[pdpe]); + ppgtt->num_pd_pages--; + } + +WARN_ON (ppgtt->num_pd_pages);return -ENOMEM ; }
@@ -709,7 +723,8 @@ static int gen8_ppgtt_alloc(struct i915_hw_ppgtt *ppgtt, {int ret; - ret =gen8_ppgtt_allocate_page_directories (ppgtt, max_pdp); + ret =gen8_ppgtt_alloc_page_directories (&ppgtt->pdp, ppgtt->base.start, + ppgtt->base.total);if (ret)return ret;
@@ -785,6 +800,10 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt, uint64_t size)if (size % (1 <<30 ))DRM_INFO ("Pages will be wasted unless GTT size (%llu) is divisible by 1GB\n" , size); + ppgtt->base.start =0 ; + ppgtt->base.total = size; +BUG_ON (ppgtt->base.total ==0 ); +/* 1. Do all our allocations for page directories and page tables. */ ret =gen8_ppgtt_alloc (ppgtt, max_pdp);if (ret)
@@ -832,8 +851,6 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt, uint64_t size) ppgtt->base.clear_range = gen8_ppgtt_clear_range; ppgtt->base.insert_entries = gen8_ppgtt_insert_entries; ppgtt->base.cleanup = gen8_ppgtt_cleanup; - ppgtt->base.start =0 ; - ppgtt->base.total = ppgtt->num_pd_entries *GEN8_PTES_PER_PAGE *PAGE_SIZE ; ppgtt->base.clear_range (&ppgtt->base,0 , ppgtt->base.total, true);
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 13/32 drm/i915/bdw: pagetable allocation rework
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
Start using gen8_for_each_pde macro to allocate page tables.
v2: teardown_va_range references removed.
v3: Rebase after s/page_tables/page_table/.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 46 +++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 17 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +29 -17
@@ -661,22 +661,27 @@ static void gen8_ppgtt_cleanup(struct i915_address_space *vm)gen8_ppgtt_free (ppgtt); } -static int gen8_ppgtt_allocate_page_tables (struct i915_hw_ppgtt *ppgtt) +static int gen8_ppgtt_alloc_pagetabs (struct i915_page_directory_entry *pd, +uint64_t start, +uint64_t length, +struct drm_device *dev) { -int i, ret; +struct i915_page_table_entry *unused; +uint64_t temp; +uint32_t pde; -for (i =0 ; i < ppgtt->num_pd_pages; i++) { - ret =alloc_pt_range (ppgtt->pdp.page_directory[i], -0 ,GEN8_PDES_PER_PAGE , ppgtt->base.dev); -if (ret) +gen8_for_each_pde (unused, pd, start, length, temp, pde) { +BUG_ON (unused); + pd->page_table[pde] =alloc_pt_single (dev); +if (IS_ERR (pd->page_table[pde])) goto unwind_out; }return 0 ; unwind_out: -while (i--) -gen8_free_page_tables (ppgtt->pdp.page_directory[i], ppgtt->base.dev); +while (pde--) +unmap_and_free_pt (pd->page_table[pde], dev);return -ENOMEM ; }
@@ -719,20 +724,28 @@ unwind_out: }static int gen8_ppgtt_alloc (struct i915_hw_ppgtt *ppgtt, -const int max_pdp) +uint64_t start, +uint64_t length) { +struct i915_page_directory_entry *pd; +uint64_t temp; +uint32_t pdpe;int ret; - ret =gen8_ppgtt_alloc_page_directories (&ppgtt->pdp, ppgtt->base.start, - ppgtt->base.total); + ret =gen8_ppgtt_alloc_page_directories (&ppgtt->pdp, start, length);if (ret)return ret; - ret =gen8_ppgtt_allocate_page_tables (ppgtt); -if (ret) - goto err_out; +gen8_for_each_pdpe (pd, &ppgtt->pdp, start, length, temp, pdpe) { + ret =gen8_ppgtt_alloc_pagetabs (pd, start, length, + ppgtt->base.dev); +if (ret) + goto err_out; + + ppgtt->num_pd_entries +=GEN8_PDES_PER_PAGE ; + } - ppgtt->num_pd_entries = max_pdp *GEN8_PDES_PER_PAGE ; +BUG_ON (pdpe > ppgtt->num_pd_pages);return 0 ;
@@ -802,10 +815,9 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt, uint64_t size) ppgtt->base.start =0 ; ppgtt->base.total = size; -BUG_ON (ppgtt->base.total ==0 );/* 1. Do all our allocations for page directories and page tables. */ - ret =gen8_ppgtt_alloc (ppgtt, max_pdp); + ret =gen8_ppgtt_alloc (ppgtt, ppgtt->base.start, ppgtt->base.total);if (ret)return ret;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 14/32 drm/i915/bdw: Update pdp switch and point unused PDPs to scratch page
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
One important part of this patch is we now write a scratch page directory into any unused PDP descriptors. This matters for 2 reasons, first, we're not allowed to just use 0, or an invalid pointer, and second, we must wipe out any previous contents from the last context.
The latter point only matters with full PPGTT. The former point only effect platforms with less than 4GB memory.
v2: Updated commit message to point that we must set unused PDPs to the scratch page.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 29 ++++++++++++++++++----------- drivers/gpu/drm/i915/i915_gem_gtt.h | 5 ++++- 2 files changed, 22 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +18 -11
@@ -442,8 +442,9 @@ static struct i915_page_directory_entry *alloc_pd_single(void) }/* Broadwell Page Directory Pointer Descriptors */ -static int gen8_write_pdp (struct intel_engine_cs *ring,unsigned entry, -uint64_t val) +static int gen8_write_pdp (struct intel_engine_cs *ring, +unsigned entry, +dma_addr_t addr) {int ret;
@@ -455,10 +456,10 @@ static int gen8_write_pdp(struct intel_engine_cs *ring, unsigned entry,intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 ));intel_ring_emit (ring,GEN8_RING_PDP_UDW (ring, entry)); -intel_ring_emit (ring, (u32)(val >>32 )); +intel_ring_emit (ring,upper_32_bits (addr));intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 ));intel_ring_emit (ring,GEN8_RING_PDP_LDW (ring, entry)); -intel_ring_emit (ring, (u32)(val)); +intel_ring_emit (ring,lower_32_bits (addr));intel_ring_advance (ring);return 0 ;
@@ -469,12 +470,12 @@ static int gen8_mm_switch(struct i915_hw_ppgtt *ppgtt, {int i, ret; -/* bit of a hack to find the actual last used pd */ -int used_pd = ppgtt->num_pd_entries /GEN8_PDES_PER_PAGE ; - -for (i = used_pd -1 ; i >=0 ; i--) { -dma_addr_t addr = ppgtt->pdp.page_directory[i]->daddr; - ret =gen8_write_pdp (ring, i, addr); +for (i =GEN8_LEGACY_PDPES -1 ; i >=0 ; i--) { +struct i915_page_directory_entry *pd = ppgtt->pdp.page_directory[i]; +dma_addr_t pd_daddr = pd ? pd->daddr : ppgtt->scratch_pd->daddr; +/* The page directory might be NULL, but we need to clear out +* whatever the previous context might have used. */ + ret =gen8_write_pdp (ring, i, pd_daddr);if (ret)return ret; }
@@ -816,10 +817,16 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt, uint64_t size) ppgtt->base.start =0 ; ppgtt->base.total = size; + ppgtt->scratch_pd =alloc_pt_scratch (ppgtt->base.dev); +if (IS_ERR (ppgtt->scratch_pd)) +return PTR_ERR (ppgtt->scratch_pd); +/* 1. Do all our allocations for page directories and page tables. */ ret =gen8_ppgtt_alloc (ppgtt, ppgtt->base.start, ppgtt->base.total); -if (ret) +if (ret) { +unmap_and_free_pt (ppgtt->scratch_pd, ppgtt->base.dev);return ret; + }/* * 2. Create DMA mappings for the page directories and page tables.
drivers/gpu/drm/i915/i915_gem_gtt.h +4 -1
@@ -306,7 +306,10 @@ struct i915_hw_ppgtt {struct i915_page_directory_entry pd; }; -struct i915_page_table_entry *scratch_pt; +union { +struct i915_page_table_entry *scratch_pt; +struct i915_page_table_entry *scratch_pd;/* Just need the daddr */ + };struct drm_i915_file_private *file_priv;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 15/32 drm/i915: num_pd_pages/num_pd_entries isn't useful
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
These values are never quite useful for dynamic allocations of the page tables. Getting rid of them will help prevent later confusion.
v2: Updated to use unmap_and_free_pd functions.
v3: Updated gen8_ppgtt_free after teardown logic was removed.
v4: Rebase after s/page_tables/page_table/.
--- drivers/gpu/drm/i915/i915_debugfs.c | 2 -- drivers/gpu/drm/i915/i915_gem_gtt.c | 72 ++++++++++++------------------------- drivers/gpu/drm/i915/i915_gem_gtt.h | 7 ++-- 3 files changed, 28 insertions(+), 53 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +0 -2
@@ -2149,8 +2149,6 @@ static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)if (!ppgtt)return ; -seq_printf (m,"Page directories: %d\n" , ppgtt->num_pd_pages); -seq_printf (m,"Page tables: %d\n" , ppgtt->num_pd_entries);for_each_ring (ring, dev_priv, unused) {seq_printf (m,"%s\n" , ring->name);for (i =0 ; i <4 ; i++) {
drivers/gpu/drm/i915/i915_gem_gtt.c +23 -49
170 lines not on this page · raw message
drivers/gpu/drm/i915/i915_gem_gtt.h +5 -2
@@ -299,8 +299,6 @@ struct i915_hw_ppgtt {struct kref ref;struct drm_mm_node node;unsigned long pd_dirty_rings; -unsigned num_pd_entries; -unsigned num_pd_pages;/* gen8+ */ union {struct i915_page_directory_pointer_entry pdp;struct i915_page_directory_entry pd;
@@ -338,6 +336,11 @@ struct i915_hw_ppgtt { temp = min_t(unsigned, temp, length), \ start += temp, length -= temp) +#define gen6_for_all_pdes (pt, ppgtt, iter) \ + for (iter = 0, pt = ppgtt->pd.page_table[iter]; \ + iter < gen6_pde_index(ppgtt->base.total); \ + pt = ppgtt->pd.page_table[++iter]) +static inline uint32_t i915_pte_index (uint64_t address,uint32_t pde_shift) {const uint32_t mask =NUM_PTE (pde_shift) -1 ;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 16/32 drm/i915: Extract PPGTT param from page_directory alloc
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
Now that we don't need to trace num_pd_pages, we may as well kill all need for the PPGTT structure in the alloc_page_directorys. This is very useful for when we move to 48b addressing, and the PDP isn't the root of the page table structure.
The param is replaced with drm_device, which is an unavoidable wart throughout the series. (in other words, not extra flagrant).
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +2 -4
@@ -689,8 +689,6 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_page_directory_pointer_ uint64_t start, uint64_t length) { -struct i915_hw_ppgtt *ppgtt = - container_of(pdp, struct i915_hw_ppgtt, pdp);struct i915_page_directory_entry *unused;uint64_t temp;uint32_t pdpe;
@@ -701,7 +699,7 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_page_directory_pointer_gen8_for_each_pdpe (unused, pdp, start, length, temp, pdpe) {BUG_ON (unused); pdp->page_directory[pdpe] =alloc_pd_single (); -if (IS_ERR (ppgtt->pdp.page_directory[pdpe])) +if (IS_ERR (pdp->page_directory[pdpe])) goto unwind_out; }
@@ -709,7 +707,7 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_page_directory_pointer_ unwind_out:while (pdpe--) -unmap_and_free_pd (ppgtt->pdp.page_directory[pdpe]); +unmap_and_free_pd (pdp->page_directory[pdpe]);return -ENOMEM ; }
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 17/32 drm/i915/bdw: Split out mappings
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
When we do dynamic page table allocations for gen8, we'll need to have more control over how and when we map page tables, similar to gen6. In particular, DMA mappings for page directories/tables occur at allocation time.
This patch adds the functionality and calls it at init, which should have no functional change.
The PDPEs are still a special case for now. We'll need a function for that in the future as well.
v2: Handle renamed unmap_and_free_page functions.
v3: Updated after teardown_va logic was removed.
v4: Rebase after s/page_tables/page_table/.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 176 ++++++++++++++---------------------- 1 file changed, 69 insertions(+), 107 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +69 -107
@@ -416,17 +416,20 @@ err_out:return ret; } -static void unmap_and_free_pd (struct i915_page_directory_entry *pd) +static void unmap_and_free_pd (struct i915_page_directory_entry *pd, +struct drm_device *dev) {if (pd->page) { +i915_dma_unmap_single (pd, dev);__free_page (pd->page);kfree (pd); } } -static struct i915_page_directory_entry *alloc_pd_single (void ) +static struct i915_page_directory_entry *alloc_pd_single (struct drm_device *dev) {struct i915_page_directory_entry *pd; +int ret; pd =kzalloc (sizeof (*pd),GFP_KERNEL );if (!pd)
@@ -438,6 +441,13 @@ static struct i915_page_directory_entry *alloc_pd_single(void)return ERR_PTR (-ENOMEM ); } + ret =i915_dma_map_single (pd, dev); +if (ret) { +__free_page (pd->page); +kfree (pd); +return ERR_PTR (ret); + } +return pd; }
@@ -592,6 +602,36 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm, } } +static void __gen8_do_map_pt (gen8_ppgtt_pde_t *pde, +struct i915_page_table_entry *pt, +struct drm_device *dev) +{ +gen8_ppgtt_pde_t entry = +gen8_pde_encode (dev, pt->daddr,I915_CACHE_LLC ); + *pde = entry; +} + +/* It's likely we'll map more than one pagetable at a time. This function will +* save us unnecessary kmap calls, but do no more functionally than multiple +* calls to map_pt. */ +static void gen8_map_pagetable_range (struct i915_page_directory_entry *pd, +uint64_t start, +uint64_t length, +struct drm_device *dev) +{ +gen8_ppgtt_pde_t *page_directory =kmap_atomic (pd->page); +struct i915_page_table_entry *pt; +uint64_t temp, pde; + +gen8_for_each_pde (pt, pd, start, length, temp, pde) +__gen8_do_map_pt (page_directory + pde, pt, dev); + +if (!HAS_LLC (dev)) +drm_clflush_virt_range (page_directory,PAGE_SIZE ); + +kunmap_atomic (page_directory); +} +static void gen8_free_page_tables (struct i915_page_directory_entry *pd,struct drm_device *dev) {int i;
@@ -647,7 +687,7 @@ static void gen8_ppgtt_free(struct i915_hw_ppgtt *ppgtt)continue ;gen8_free_page_tables (ppgtt->pdp.page_directory[i], ppgtt->base.dev); -unmap_and_free_pd (ppgtt->pdp.page_directory[i]); +unmap_and_free_pd (ppgtt->pdp.page_directory[i], ppgtt->base.dev); } }
@@ -687,7 +727,8 @@ unwind_out:static int gen8_ppgtt_alloc_page_directories (struct i915_page_directory_pointer_entry *pdp,uint64_t start, -uint64_t length) +uint64_t length, +struct drm_device *dev) {struct i915_page_directory_entry *unused;uint64_t temp;
@@ -698,7 +739,7 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_page_directory_pointer_gen8_for_each_pdpe (unused, pdp, start, length, temp, pdpe) {BUG_ON (unused); - pdp->page_directory[pdpe] =alloc_pd_single (); + pdp->page_directory[pdpe] =alloc_pd_single (dev);if (IS_ERR (pdp->page_directory[pdpe])) goto unwind_out; }
@@ -707,21 +748,24 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_page_directory_pointer_ unwind_out:while (pdpe--) -unmap_and_free_pd (pdp->page_directory[pdpe]); +unmap_and_free_pd (pdp->page_directory[pdpe], dev);return -ENOMEM ; } -static int gen8_ppgtt_alloc (struct i915_hw_ppgtt *ppgtt, -uint64_t start, -uint64_t length) +static int gen8_alloc_va_range (struct i915_address_space *vm, +uint64_t start, +uint64_t length) { +struct i915_hw_ppgtt *ppgtt = + container_of(vm, struct i915_hw_ppgtt, base);struct i915_page_directory_entry *pd;uint64_t temp;uint32_t pdpe;int ret; - ret =gen8_ppgtt_alloc_page_directories (&ppgtt->pdp, start, length); + ret =gen8_ppgtt_alloc_page_directories (&ppgtt->pdp, start, length, + ppgtt->base.dev);if (ret)return ret;
@@ -739,128 +783,46 @@ err_out:return ret; } -static int gen8_ppgtt_setup_page_directories (struct i915_hw_ppgtt *ppgtt, -const int pd) -{ -dma_addr_t pd_addr; -int ret; - - pd_addr =pci_map_page (ppgtt->base.dev->pdev, - ppgtt->pdp.page_directory[pd]->page,0 , -PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL ); - - ret =pci_dma_mapping_error (ppgtt->base.dev->pdev, pd_addr); -if (ret) -return ret; - - ppgtt->pdp.page_directory[pd]->daddr = pd_addr; - -return 0 ; -} - -static int gen8_ppgtt_setup_page_tables (struct i915_hw_ppgtt *ppgtt, -const int pd, -const int pt) -{ -dma_addr_t pt_addr; -struct i915_page_directory_entry *pdir = ppgtt->pdp.page_directory[pd]; -struct i915_page_table_entry *ptab = pdir->page_table[pt]; -struct page *p = ptab->page; -int ret; - - pt_addr =pci_map_page (ppgtt->base.dev->pdev, - p,0 ,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL ); - ret =pci_dma_mapping_error (ppgtt->base.dev->pdev, pt_addr); -if (ret) -return ret; - - ptab->daddr = pt_addr; - -return 0 ; -} -/** * GEN8 legacy ppgtt programming is accomplished through a max 4 PDP registers * with a net effect resembling a 2-level page table in normal x86 terms. Each * PDP represents 1GB of memory 4 * 512 * 512 * 4096 = 4GB legacy 32b address * space. * -* FIXME: split allocation into smaller pieces. For now we only ever do this -* once, but with full PPGTT, the multiple contiguous allocations will be bad. -* TODO: Do something with the size parameter */ static int gen8_ppgtt_init (struct i915_hw_ppgtt *ppgtt,uint64_t size) { -const int max_pdp =DIV_ROUND_UP (size,1 <<30 ); -int i, j, ret; - -if (size % (1 <<30 )) -DRM_INFO ("Pages will be wasted unless GTT size (%llu) is divisible by 1GB\n" , size); +struct i915_page_directory_entry *pd; +uint64_t temp, start =0 ; +const uint64_t orig_length = size; +uint32_t pdpe; +int ret; ppgtt->base.start =0 ; ppgtt->base.total = size; + ppgtt->base.clear_range = gen8_ppgtt_clear_range; + ppgtt->base.insert_entries = gen8_ppgtt_insert_entries; + ppgtt->base.cleanup = gen8_ppgtt_cleanup; + ppgtt->switch_mm = gen8_mm_switch; ppgtt->scratch_pd =alloc_pt_scratch (ppgtt->base.dev);if (IS_ERR (ppgtt->scratch_pd))return PTR_ERR (ppgtt->scratch_pd); -/* 1. Do all our allocations for page directories and page tables. */ - ret =gen8_ppgtt_alloc (ppgtt, ppgtt->base.start, ppgtt->base.total); + ret =gen8_alloc_va_range (&ppgtt->base, start, size);if (ret) {unmap_and_free_pt (ppgtt->scratch_pd, ppgtt->base.dev);return ret; } -/* -* 2. Create DMA mappings for the page directories and page tables. -*/ -for (i =0 ; i < max_pdp; i++) { - ret =gen8_ppgtt_setup_page_directories (ppgtt, i); -if (ret) - goto bail; + start =0 ; + size = orig_length; -for (j =0 ; j <GEN8_PDES_PER_PAGE ; j++) { - ret =gen8_ppgtt_setup_page_tables (ppgtt, i, j); -if (ret) - goto bail; - } - } - -/* -* 3. Map all the page directory entires to point to the page tables -* we've allocated. -* -* For now, the PPGTT helper functions all require that the PDEs are -* plugged in correctly. So we do that now/here. For aliasing PPGTT, we -* will never need to touch the PDEs again. -*/ -for (i =0 ; i < max_pdp; i++) { -struct i915_page_directory_entry *pd = ppgtt->pdp.page_directory[i]; -gen8_ppgtt_pde_t *pd_vaddr; - pd_vaddr =kmap_atomic (ppgtt->pdp.page_directory[i]->page); -for (j =0 ; j <GEN8_PDES_PER_PAGE ; j++) { -struct i915_page_table_entry *pt = pd->page_table[j]; -dma_addr_t addr = pt->daddr; - pd_vaddr[j] =gen8_pde_encode (ppgtt->base.dev, addr, -I915_CACHE_LLC ); - } -if (!HAS_LLC (ppgtt->base.dev)) -drm_clflush_virt_range (pd_vaddr,PAGE_SIZE ); -kunmap_atomic (pd_vaddr); - } - - ppgtt->switch_mm = gen8_mm_switch; - ppgtt->base.clear_range = gen8_ppgtt_clear_range; - ppgtt->base.insert_entries = gen8_ppgtt_insert_entries; - ppgtt->base.cleanup = gen8_ppgtt_cleanup; +gen8_for_each_pdpe (pd, &ppgtt->pdp, start, size, temp, pdpe) +gen8_map_pagetable_range (pd, start, size, ppgtt->base.dev); ppgtt->base.clear_range (&ppgtt->base,0 , ppgtt->base.total, true);return 0 ; - -bail: -gen8_ppgtt_unmap_pages (ppgtt); -gen8_ppgtt_free (ppgtt); -return ret; }static void gen6_dump_ppgtt (struct i915_hw_ppgtt *ppgtt,struct seq_file *m)
@@ -1276,7 +1238,7 @@ static void gen6_ppgtt_free(struct i915_hw_ppgtt *ppgtt) }unmap_and_free_pt (ppgtt->scratch_pt, ppgtt->base.dev); -unmap_and_free_pd (&ppgtt->pd); +unmap_and_free_pd (&ppgtt->pd, ppgtt->base.dev); }static void gen6_ppgtt_cleanup (struct i915_address_space *vm)
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 18/32 drm/i915/bdw: begin bitmap tracking
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
Like with gen6/7, we can enable bitmap tracking with all the preallocations to make sure things actually don't blow up.
v2: Rebased to match changes from previous patches.
v3: Without teardown logic, rely on used_pdpes and used_pdes when freeing page tables.
v4: Rebase after s/page_tables/page_table/.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 75 ++++++++++++++++++++++++++++--------- drivers/gpu/drm/i915/i915_gem_gtt.h | 24 ++++++++++++ 2 files changed, 81 insertions(+), 18 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +57 -18
@@ -422,6 +422,7 @@ static void unmap_and_free_pd(struct i915_page_directory_entry *pd,if (pd->page) {i915_dma_unmap_single (pd, dev);__free_page (pd->page); +kfree (pd->used_pdes);kfree (pd); } }
@@ -429,26 +430,35 @@ static void unmap_and_free_pd(struct i915_page_directory_entry *pd,static struct i915_page_directory_entry *alloc_pd_single (struct drm_device *dev) {struct i915_page_directory_entry *pd; -int ret; +int ret = -ENOMEM ; pd =kzalloc (sizeof (*pd),GFP_KERNEL );if (!pd)return ERR_PTR (-ENOMEM ); + pd->used_pdes =kcalloc (BITS_TO_LONGS (GEN8_PDES_PER_PAGE ), +sizeof (*pd->used_pdes),GFP_KERNEL ); +if (!pd->used_pdes) + goto free_pd; + pd->page =alloc_page (GFP_KERNEL | __GFP_ZERO); -if (!pd->page) { -kfree (pd); -return ERR_PTR (-ENOMEM ); - } +if (!pd->page) + goto free_bitmap; ret =i915_dma_map_single (pd, dev); -if (ret) { -__free_page (pd->page); -kfree (pd); -return ERR_PTR (ret); - } +if (ret) + goto free_page;return pd; + +free_page: +__free_page (pd->page); +free_bitmap: +kfree (pd->used_pdes); +free_pd: +kfree (pd); + +return ERR_PTR (ret); }/* Broadwell Page Directory Pointer Descriptors */
@@ -639,7 +649,7 @@ static void gen8_free_page_tables(struct i915_page_directory_entry *pd, struct dif (!pd->page)return ; -for (i =0 ; i <GEN8_PDES_PER_PAGE ; i++) { +for_each_set_bit (i, pd->used_pdes,GEN8_PDES_PER_PAGE ) {if (WARN_ON (!pd->page_table[i]))continue ;
@@ -653,15 +663,18 @@ static void gen8_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt)struct pci_dev *hwdev = ppgtt->base.dev->pdev;int i, j; -for (i =0 ; i <GEN8_LEGACY_PDPES ; i++) { -if (!ppgtt->pdp.page_directory[i]->daddr) +for_each_set_bit (i, ppgtt->pdp.used_pdpes,GEN8_LEGACY_PDPES ) { +struct i915_page_directory_entry *pd; + +if (WARN_ON (!ppgtt->pdp.page_directory[i]))continue ; -pci_unmap_page (hwdev, ppgtt->pdp.page_directory[i]->daddr,PAGE_SIZE , -PCI_DMA_BIDIRECTIONAL ); + pd = ppgtt->pdp.page_directory[i]; +if (!pd->daddr) +pci_unmap_page (hwdev, pd->daddr,PAGE_SIZE , +PCI_DMA_BIDIRECTIONAL ); -for (j =0 ; j <GEN8_PDES_PER_PAGE ; j++) { -struct i915_page_directory_entry *pd = ppgtt->pdp.page_directory[i]; +for_each_set_bit (j, pd->used_pdes,GEN8_PDES_PER_PAGE ) {struct i915_page_table_entry *pt;dma_addr_t addr;
@@ -682,7 +695,7 @@ static void gen8_ppgtt_free(struct i915_hw_ppgtt *ppgtt) {int i; -for (i =0 ; i <GEN8_LEGACY_PDPES ; i++) { +for_each_set_bit (i, ppgtt->pdp.used_pdpes,GEN8_LEGACY_PDPES ) {if (WARN_ON (!ppgtt->pdp.page_directory[i]))continue ;
@@ -725,6 +738,7 @@ unwind_out:return -ENOMEM ; } +/* bitmap of new page_directories */ static int gen8_ppgtt_alloc_page_directories(struct i915_page_directory_pointer_entry *pdp, uint64_t start, uint64_t length,
@@ -740,6 +754,7 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_page_directory_pointer_gen8_for_each_pdpe (unused, pdp, start, length, temp, pdpe) {BUG_ON (unused); pdp->page_directory[pdpe] =alloc_pd_single (dev); +if (IS_ERR (pdp->page_directory[pdpe])) goto unwind_out; }
@@ -760,10 +775,13 @@ static int gen8_alloc_va_range(struct i915_address_space *vm,struct i915_hw_ppgtt *ppgtt = container_of(vm, struct i915_hw_ppgtt, base);struct i915_page_directory_entry *pd; +const uint64_t orig_start = start; +const uint64_t orig_length = length;uint64_t temp;uint32_t pdpe;int ret; +/* Do the allocations first so we can easily bail out */ ret =gen8_ppgtt_alloc_page_directories (&ppgtt->pdp, start, length, ppgtt->base.dev);if (ret)
@@ -776,6 +794,27 @@ static int gen8_alloc_va_range(struct i915_address_space *vm, goto err_out; } +/* Now mark everything we've touched as used. This doesn't allow for +* robust error checking, but it makes the code a hell of a lot simpler. +*/ + start = orig_start; + length = orig_length; + +gen8_for_each_pdpe (pd, &ppgtt->pdp, start, length, temp, pdpe) { +struct i915_page_table_entry *pt; +uint64_t pd_len =gen8_clamp_pd (start, length); +uint64_t pd_start = start; +uint32_t pde; + +gen8_for_each_pde (pt, &ppgtt->pd, pd_start, pd_len, temp, pde) { +bitmap_set (pd->page_table[pde]->used_ptes, +gen8_pte_index (start), +gen8_pte_count (start, length)); +set_bit (pde, pd->used_pdes); + } +set_bit (pdpe, ppgtt->pdp.used_pdpes); + } +return 0 ; err_out:
drivers/gpu/drm/i915/i915_gem_gtt.h +24 -0
@@ -205,11 +205,13 @@ struct i915_page_directory_entry {dma_addr_t daddr; }; +unsigned long *used_pdes;struct i915_page_table_entry *page_table[GEN6_PPGTT_PD_ENTRIES ];/* PDEs */ };struct i915_page_directory_pointer_entry {/* struct page *page; */ + DECLARE_BITMAP(used_pdpes, GEN8_LEGACY_PDPES);struct i915_page_directory_entry *page_directory[GEN8_LEGACY_PDPES ]; };
@@ -436,6 +438,28 @@ static inline uint32_t gen8_pml4e_index(uint64_t address)BUG ();/* For 64B */ } +static inline size_t gen8_pte_count (uint64_t addr,uint64_t length) +{ +return i915_pte_count (addr, length,GEN8_PDE_SHIFT ); +} + +static inline size_t gen8_pde_count (uint64_t addr,uint64_t length) +{ +const uint32_t pdp_shift =GEN8_PDE_SHIFT +9 ; +const uint64_t mask = ~((1 << pdp_shift) -1 ); +uint64_t end; + +BUG_ON (length ==0 ); +BUG_ON (offset_in_page (addr|length)); + + end = addr + length; + +if ((addr & mask) != (end & mask)) +return GEN8_PDES_PER_PAGE -i915_pde_index (addr,GEN8_PDE_SHIFT ); + +return i915_pde_index (end,GEN8_PDE_SHIFT ) -i915_pde_index (addr,GEN8_PDE_SHIFT ); +} +int i915_gem_gtt_init (struct drm_device *dev);void i915_gem_init_global_gtt (struct drm_device *dev);void i915_global_gtt_cleanup (struct drm_device *dev);
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 19/32 drm/i915/bdw: Dynamic page table allocations
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
This finishes off the dynamic page tables allocations, in the legacy 3 level style that already exists. Most everything has already been setup to this point, the patch finishes off the enabling by setting the appropriate function pointers.
v2: Update aliasing/true ppgtt allocate/teardown/clear functions for gen 6 & 7.
v3: Rebase.
v4: Remove BUG() from ppgtt_unbind_vma, but keep checking that either teardown_va_range or clear_range functions exist (Daniel).
v5: Similar to gen6, in init, gen8_ppgtt_clear_range call is only needed for aliasing ppgtt. Zombie tracking was originally added for teardown function and is no longer required.
v6: Update err_out case in gen8_alloc_va_range (missed from lastest rebase).
v7: Rebase after s/page_tables/page_table/.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 300 +++++++++++++++++++++++++++++------- 1 file changed, 246 insertions(+), 54 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +246 -54
@@ -612,7 +612,7 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm, } } -static void __gen8_do_map_pt (gen8_ppgtt_pde_t *pde, +static void __gen8_do_map_pt (gen8_ppgtt_pde_t *const pde,struct i915_page_table_entry *pt,struct drm_device *dev) {
@@ -629,7 +629,7 @@ static void gen8_map_pagetable_range(struct i915_page_directory_entry *pd,uint64_t length, struct drm_device *dev) { - gen8_ppgtt_pde_t *page_directory = kmap_atomic(pd->page); + gen8_ppgtt_pde_t * const page_directory = kmap_atomic(pd->page);struct i915_page_table_entry *pt;uint64_t temp, pde;
@@ -713,58 +713,163 @@ static void gen8_ppgtt_cleanup(struct i915_address_space *vm)gen8_ppgtt_free (ppgtt); } -static int gen8_ppgtt_alloc_pagetabs (struct i915_page_directory_entry *pd, +/** +* gen8_ppgtt_alloc_pagetabs() - Allocate page tables for VA range. +* @ppgtt: Master ppgtt structure. +* @pd: Page directory for this address range. +* @start: Starting virtual address to begin allocations. +* @length Size of the allocations. +* @new_pts: Bitmap set by function with new allocations. Likely used by the +* caller to free on error. +* +* Allocate the required number of page tables. Extremely similar to +* gen8_ppgtt_alloc_page_directories(). The main difference is here we are limited by +* the page directory boundary (instead of the page directory pointer). That +* boundary is 1GB virtual. Therefore, unlike gen8_ppgtt_alloc_page_directories(), it is +* possible, and likely that the caller will need to use multiple calls of this +* function to achieve the appropriate allocation. +* +* Return: 0 if success; negative error code otherwise. +*/ +static int gen8_ppgtt_alloc_pagetabs (struct i915_hw_ppgtt *ppgtt, +struct i915_page_directory_entry *pd,uint64_t start,uint64_t length, -struct drm_device *dev) +unsigned long *new_pts) { -struct i915_page_table_entry *unused; +struct i915_page_table_entry *pt;uint64_t temp;uint32_t pde; -gen8_for_each_pde (unused, pd, start, length, temp, pde) { -BUG_ON (unused); - pd->page_table[pde] =alloc_pt_single (dev); -if (IS_ERR (pd->page_table[pde])) +gen8_for_each_pde (pt, pd, start, length, temp, pde) { +/* Don't reallocate page tables */ +if (pt) { +/* Scratch is never allocated this way */ +WARN_ON (pt->scratch); +continue ; + } + + pt =alloc_pt_single (ppgtt->base.dev); +if (IS_ERR (pt)) goto unwind_out; + + pd->page_table[pde] = pt; +set_bit (pde, new_pts); }return 0 ; unwind_out: -while (pde--) -unmap_and_free_pt (pd->page_table[pde], dev); +for_each_set_bit (pde, new_pts,GEN8_PDES_PER_PAGE ) +unmap_and_free_pt (pd->page_table[pde], ppgtt->base.dev);return -ENOMEM ; } -/* bitmap of new page_directories */ -static int gen8_ppgtt_alloc_page_directories (struct i915_page_directory_pointer_entry *pdp, +/** +* gen8_ppgtt_alloc_page_directories() - Allocate page directories for VA range. +* @ppgtt: Master ppgtt structure. +* @pdp: Page directory pointer for this address range. +* @start: Starting virtual address to begin allocations. +* @length Size of the allocations. +* @new_pds Bitmap set by function with new allocations. Likely used by the +* caller to free on error. +* +* Allocate the required number of page directories starting at the pde index of +* @start, and ending at the pde index @start + @length. This function will skip +* over already allocated page directories within the range, and only allocate +* new ones, setting the appropriate pointer within the pdp as well as the +* correct position in the bitmap @new_pds. +* +* The function will only allocate the pages within the range for a give page +* directory pointer. In other words, if @start + @length straddles a virtually +* addressed PDP boundary (512GB for 4k pages), there will be more allocations +* required by the caller, This is not currently possible, and the BUG in the +* code will prevent it. +* +* Return: 0 if success; negative error code otherwise. +*/ +static int gen8_ppgtt_alloc_page_directories (struct i915_hw_ppgtt *ppgtt, +struct i915_page_directory_pointer_entry *pdp,uint64_t start,uint64_t length, -struct drm_device *dev) +unsigned long *new_pds) { -struct i915_page_directory_entry *unused; +struct i915_page_directory_entry *pd;uint64_t temp;uint32_t pdpe; +BUG_ON (!bitmap_empty (new_pds,GEN8_LEGACY_PDPES )); +/* FIXME: PPGTT container_of won't work for 64b */ BUG_ON ((start + length) >0x800000000ULL ); -gen8_for_each_pdpe (unused, pdp, start, length, temp, pdpe) { -BUG_ON (unused); - pdp->page_directory[pdpe] =alloc_pd_single (dev); +gen8_for_each_pdpe (pd, pdp, start, length, temp, pdpe) { +if (pd) +continue ; -if (IS_ERR (pdp->page_directory[pdpe])) + pd =alloc_pd_single (ppgtt->base.dev); +if (IS_ERR (pd)) goto unwind_out; + + pdp->page_directory[pdpe] = pd; +set_bit (pdpe, new_pds); }return 0 ; unwind_out: -while (pdpe--) -unmap_and_free_pd (pdp->page_directory[pdpe], dev); +for_each_set_bit (pdpe, new_pds,GEN8_LEGACY_PDPES ) +unmap_and_free_pd (pdp->page_directory[pdpe], ppgtt->base.dev); + +return -ENOMEM ; +} + +static inline void +free_gen8_temp_bitmaps (unsigned long *new_pds,unsigned long **new_pts) +{ +int i; + +for (i =0 ; i <GEN8_LEGACY_PDPES ; i++) +kfree (new_pts[i]); +kfree (new_pts); +kfree (new_pds); +} + +/* Fills in the page directory bitmap, ant the array of page tables bitmap. Both +* of these are based on the number of PDPEs in the system. +*/ +int __must_check alloc_gen8_temp_bitmaps (unsigned long **new_pds, +unsigned long ***new_pts) +{ +int i; +unsigned long *pds; +unsigned long **pts; + + pds =kcalloc (BITS_TO_LONGS (GEN8_LEGACY_PDPES ),sizeof (unsigned long ),GFP_KERNEL ); +if (!pds) +return -ENOMEM ; + + pts =kcalloc (GEN8_PDES_PER_PAGE ,sizeof (unsigned long *),GFP_KERNEL ); +if (!pts) { +kfree (pds); +return -ENOMEM ; + } + +for (i =0 ; i <GEN8_LEGACY_PDPES ; i++) { + pts[i] =kcalloc (BITS_TO_LONGS (GEN8_PDES_PER_PAGE ), +sizeof (unsigned long ),GFP_KERNEL ); +if (!pts[i]) + goto err_out; + } + + *new_pds = pds; + *new_pts = (unsigned long **)pts; +return 0 ; + +err_out: +free_gen8_temp_bitmaps (pds, pts);return -ENOMEM ; }
@@ -774,6 +879,7 @@ static int gen8_alloc_va_range(struct i915_address_space *vm, {struct i915_hw_ppgtt *ppgtt = container_of(vm, struct i915_hw_ppgtt, base); +unsigned long *new_page_dirs, **new_page_tables;struct i915_page_directory_entry *pd;const uint64_t orig_start = start;const uint64_t orig_length = length;
@@ -781,44 +887,99 @@ static int gen8_alloc_va_range(struct i915_address_space *vm,uint32_t pdpe;int ret; -/* Do the allocations first so we can easily bail out */ - ret =gen8_ppgtt_alloc_page_directories (&ppgtt->pdp, start, length, - ppgtt->base.dev); +#ifndef CONFIG_64BIT +/* Disallow 64b address on 32b platforms. Nothing is wrong with doing +* this in hardware, but a lot of the drm code is not prepared to handle +* 64b offset on 32b platforms. +* This will be addressed when 48b PPGTT is added */ +if (start + length >0x100000000ULL ) +return -E2BIG ; +#endif + +/* Wrap is never okay since we can only represent 48b, and we don't +* actually use the other side of the canonical address space. +*/ +if (WARN_ON (start + length < start)) +return -ERANGE ; + + ret =alloc_gen8_temp_bitmaps (&new_page_dirs, &new_page_tables);if (ret)return ret; +/* Do the allocations first so we can easily bail out */ + ret =gen8_ppgtt_alloc_page_directories (ppgtt, &ppgtt->pdp, start, length, + new_page_dirs); +if (ret) { +free_gen8_temp_bitmaps (new_page_dirs, new_page_tables); +return ret; + } + +/* For every page directory referenced, allocate page tables */ gen8_for_each_pdpe (pd, &ppgtt->pdp, start, length, temp, pdpe) { - ret =gen8_ppgtt_alloc_pagetabs (pd, start, length, - ppgtt->base.dev); +bitmap_zero (new_page_tables[pdpe],GEN8_PDES_PER_PAGE ); + ret =gen8_ppgtt_alloc_pagetabs (ppgtt, pd, start, length, + new_page_tables[pdpe]);if (ret) goto err_out; } -/* Now mark everything we've touched as used. This doesn't allow for -* robust error checking, but it makes the code a hell of a lot simpler. -*/ start = orig_start; length = orig_length; +/* Allocations have completed successfully, so set the bitmaps, and do +* the mappings. */ gen8_for_each_pdpe (pd, &ppgtt->pdp, start, length, temp, pdpe) { +gen8_ppgtt_pde_t *const page_directory =kmap_atomic (pd->page);struct i915_page_table_entry *pt;uint64_t pd_len =gen8_clamp_pd (start, length);uint64_t pd_start = start;uint32_t pde; -gen8_for_each_pde (pt, &ppgtt->pd, pd_start, pd_len, temp, pde) { -bitmap_set (pd->page_table[pde]->used_ptes, -gen8_pte_index (start), -gen8_pte_count (start, length)); +/* Every pd should be allocated, we just did that above. */ +BUG_ON (!pd); + +gen8_for_each_pde (pt, pd, pd_start, pd_len, temp, pde) { +/* Same reasoning as pd */ +BUG_ON (!pt); +BUG_ON (!pd_len); +BUG_ON (!gen8_pte_count (pd_start, pd_len)); + +/* Set our used ptes within the page table */ +bitmap_set (pt->used_ptes, +gen8_pte_index (pd_start), +gen8_pte_count (pd_start, pd_len)); + +/* Our pde is now pointing to the pagetable, pt */ set_bit (pde, pd->used_pdes); + +/* Map the PDE to the page table */ +__gen8_do_map_pt (page_directory + pde, pt, vm->dev); + +/* NB: We haven't yet mapped ptes to pages. At this +* point we're still relying on insert_entries() */ } + +if (!HAS_LLC (vm->dev)) +drm_clflush_virt_range (page_directory,PAGE_SIZE ); + +kunmap_atomic (page_directory); +set_bit (pdpe, ppgtt->pdp.used_pdpes); } +free_gen8_temp_bitmaps (new_page_dirs, new_page_tables);return 0 ; err_out: -gen8_ppgtt_free (ppgtt); +while (pdpe--) { +for_each_set_bit (temp, new_page_tables[pdpe],GEN8_PDES_PER_PAGE ) +unmap_and_free_pt (pd->page_table[temp], vm->dev); + } + +for_each_set_bit (pdpe, new_page_dirs,GEN8_LEGACY_PDPES ) +unmap_and_free_pd (ppgtt->pdp.page_directory[pdpe], vm->dev); + +free_gen8_temp_bitmaps (new_page_dirs, new_page_tables);return ret; }
@@ -829,38 +990,67 @@ err_out:* space. * */ -static int gen8_ppgtt_init (struct i915_hw_ppgtt *ppgtt,uint64_t size) +static int gen8_ppgtt_init_common (struct i915_hw_ppgtt *ppgtt,uint64_t size) { -struct i915_page_directory_entry *pd; -uint64_t temp, start =0 ; -const uint64_t orig_length = size; -uint32_t pdpe; -int ret; + ppgtt->scratch_pd =alloc_pt_scratch (ppgtt->base.dev); +if (IS_ERR (ppgtt->scratch_pd)) +return PTR_ERR (ppgtt->scratch_pd); ppgtt->base.start =0 ; ppgtt->base.total = size; - ppgtt->base.clear_range = gen8_ppgtt_clear_range; - ppgtt->base.insert_entries = gen8_ppgtt_insert_entries; ppgtt->base.cleanup = gen8_ppgtt_cleanup; + ppgtt->base.insert_entries = gen8_ppgtt_insert_entries; + ppgtt->switch_mm = gen8_mm_switch; - ppgtt->scratch_pd =alloc_pt_scratch (ppgtt->base.dev); -if (IS_ERR (ppgtt->scratch_pd)) -return PTR_ERR (ppgtt->scratch_pd); +return 0 ; +} + +static int gen8_aliasing_ppgtt_init (struct i915_hw_ppgtt *ppgtt) +{ +struct drm_device *dev = ppgtt->base.dev; +struct drm_i915_private *dev_priv = dev->dev_private; +struct i915_page_directory_entry *pd; +uint64_t temp, start =0 , size = dev_priv->gtt.base.total; +uint32_t pdpe; +int ret; + + ret =gen8_ppgtt_init_common (ppgtt, dev_priv->gtt.base.total); +if (ret) +return ret; +/* Aliasing PPGTT has to always work and be mapped because of the way we +* use RESTORE_INHIBIT in the context switch. This will be fixed +* eventually. */ ret =gen8_alloc_va_range (&ppgtt->base, start, size);if (ret) {unmap_and_free_pt (ppgtt->scratch_pd, ppgtt->base.dev);return ret; } - start =0 ; - size = orig_length; -gen8_for_each_pdpe (pd, &ppgtt->pdp, start, size, temp, pdpe)gen8_map_pagetable_range (pd, start, size, ppgtt->base.dev); + ppgtt->base.allocate_va_range =NULL ; + ppgtt->base.clear_range = gen8_ppgtt_clear_range; ppgtt->base.clear_range (&ppgtt->base,0 , ppgtt->base.total, true); + +return 0 ; +} + +static int gen8_ppgtt_init (struct i915_hw_ppgtt *ppgtt) +{ +struct drm_device *dev = ppgtt->base.dev; +struct drm_i915_private *dev_priv = dev->dev_private; +int ret; + + ret =gen8_ppgtt_init_common (ppgtt, dev_priv->gtt.base.total); +if (ret) +return ret; + + ppgtt->base.allocate_va_range = gen8_alloc_va_range; + ppgtt->base.clear_range = gen8_ppgtt_clear_range; +return 0 ; }
@@ -1395,7 +1585,7 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt, bool aliasing) } } - ppgtt->base.allocate_va_range = gen6_alloc_va_range; + ppgtt->base.allocate_va_range = aliasing ?NULL : gen6_alloc_va_range; ppgtt->base.clear_range = gen6_ppgtt_clear_range; ppgtt->base.insert_entries = gen6_ppgtt_insert_entries; ppgtt->base.cleanup = gen6_ppgtt_cleanup;
@@ -1436,8 +1626,10 @@ static int __hw_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt,if (INTEL_INFO (dev)->gen <8 )return gen6_ppgtt_init (ppgtt, aliasing); +else if (aliasing) +return gen8_aliasing_ppgtt_init (ppgtt);else -return gen8_ppgtt_init (ppgtt, dev_priv->gtt.base.total); +return gen8_ppgtt_init (ppgtt); }int i915_ppgtt_init (struct drm_device *dev,struct i915_hw_ppgtt *ppgtt) {
@@ -1546,10 +1738,10 @@ ppgtt_bind_vma(struct i915_vma *vma,static void ppgtt_unbind_vma (struct i915_vma *vma) { - vma->vm->clear_range (vma->vm, - vma->node.start, - vma->obj->base.size, - true); + vma->vm->clear_range (vma->vm, + vma->node.start, + vma->obj->base.size, + true); }extern int intel_iommu_gfx_mapped;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 20/32 drm/i915/bdw: Support dynamic pdp updates in lrc mode
In reply to Michel ThierryLogic ring contexts need to know the PDPs when they are populated. With dynamic page table allocations, these PDPs may not exist yet.
Check if PDPs have been allocated and use the scratch page if they do not exist yet.
Before submission, update the PDPs in the logic ring context as PDPs have been allocated.
v2: Renamed commit title (Daniel)
--- drivers/gpu/drm/i915/intel_lrc.c | 80 +++++++++++++++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/intel_lrc.c +70 -10
@@ -320,6 +320,7 @@ static void execlists_elsp_write(struct intel_engine_cs *ring,static int execlists_update_context (struct drm_i915_gem_object *ctx_obj,struct drm_i915_gem_object *ring_obj, +struct i915_hw_ppgtt *ppgtt,u32 tail) {struct page *page;
@@ -331,6 +332,40 @@ static int execlists_update_context(struct drm_i915_gem_object *ctx_obj, reg_state[CTX_RING_TAIL +1 ] = tail; reg_state[CTX_RING_BUFFER_START +1 ] =i915_gem_obj_ggtt_offset (ring_obj); +/* True PPGTT with dynamic page allocation: update PDP registers and +* point the unallocated PDPs to the scratch page +*/ +if (ppgtt) { +if (test_bit (3 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + }else { + reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (test_bit (2 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + }else { + reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (test_bit (1 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + }else { + reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (test_bit (0 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + }else { + reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + } + } +kunmap_atomic (reg_state);return 0 ;
@@ -349,7 +384,7 @@ static void execlists_submit_contexts(struct intel_engine_cs *ring,WARN_ON (!i915_gem_obj_is_pinned (ctx_obj0));WARN_ON (!i915_gem_obj_is_pinned (ringbuf0->obj)); -execlists_update_context (ctx_obj0, ringbuf0->obj, tail0); +execlists_update_context (ctx_obj0, ringbuf0->obj, to0->ppgtt, tail0);if (to1) { ringbuf1 = to1->engine[ring->id].ringbuf;
@@ -358,7 +393,7 @@ static void execlists_submit_contexts(struct intel_engine_cs *ring,WARN_ON (!i915_gem_obj_is_pinned (ctx_obj1));WARN_ON (!i915_gem_obj_is_pinned (ringbuf1->obj)); -execlists_update_context (ctx_obj1, ringbuf1->obj, tail1); +execlists_update_context (ctx_obj1, ringbuf1->obj, to1->ppgtt, tail1); }execlists_elsp_write (ring, ctx_obj0, ctx_obj1);
@@ -1735,14 +1770,39 @@ populate_lr_context(struct intel_context *ctx, struct drm_i915_gem_object *ctx_o reg_state[CTX_PDP1_LDW ] =GEN8_RING_PDP_LDW (ring,1 ); reg_state[CTX_PDP0_UDW ] =GEN8_RING_PDP_UDW (ring,0 ); reg_state[CTX_PDP0_LDW ] =GEN8_RING_PDP_LDW (ring,0 ); - reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); - reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); - reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); - reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); - reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); - reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); - reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); - reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + +/* With dynamic page allocation, PDPs may not be allocated at this point, +* Point the unallocated PDPs to the scratch page +*/ +if (test_bit (3 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + }else { + reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (test_bit (2 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + }else { + reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (test_bit (1 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + }else { + reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (test_bit (0 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + }else { + reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (ring->id ==RCS ) { reg_state[CTX_LRI_HEADER_2 ] =MI_LOAD_REGISTER_IMM (1 ); reg_state[CTX_R_PWR_CLK_STATE ] =0x20c8 ;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 21/32 drm/i915/bdw: Make pdp allocation more dynamic
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
This transitional patch doesn't do much for the existing code. However, it should make upcoming patches to use the full 48b address space a bit easier to swallow. The patch also introduces the PML4, ie. the new top level structure of the page tables.
v2: Renamed pdp_free to be similar to pd/pt (unmap_and_free_pdp).
v3: To facilitate testing, 48b mode will be available on Broadwell and GEN9+, when i915.enable_ppgtt = 3.
v4: Rebase after s/page_tables/page_table/.
--- drivers/gpu/drm/i915/i915_drv.h | 7 ++- drivers/gpu/drm/i915/i915_gem_gtt.c | 109 +++++++++++++++++++++++++++++------- drivers/gpu/drm/i915/i915_gem_gtt.h | 41 +++++++++++--- 3 files changed, 127 insertions(+), 30 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +6 -1
@@ -2433,7 +2433,12 @@ struct drm_i915_cmd_table {#define HAS_HW_CONTEXTS (dev) (INTEL_INFO(dev)->gen >= 6)#define HAS_LOGICAL_RING_CONTEXTS (dev) (INTEL_INFO(dev)->gen >= 8)#define USES_PPGTT (dev) (i915.enable_ppgtt) -#define USES_FULL_PPGTT (dev) (i915.enable_ppgtt == 2) +#define USES_FULL_PPGTT (dev) (i915.enable_ppgtt >= 2) +#ifdef CONFIG_64BIT +# define USES_FULL_48BIT_PPGTT (dev) (i915.enable_ppgtt == 3) +#else +# define USES_FULL_48BIT_PPGTT (dev) false +#endif #define HAS_OVERLAY (dev) (INTEL_INFO(dev)->has_overlay)#define OVERLAY_NEEDS_PHYSICAL (dev) (INTEL_INFO(dev)->overlay_needs_physical)
drivers/gpu/drm/i915/i915_gem_gtt.c +89 -20
253 lines not on this page · raw message
drivers/gpu/drm/i915/i915_gem_gtt.h +32 -9
77 lines not on this page · raw message
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 22/32 drm/i915/bdw: Abstract PDP usage
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
Up until now, ppgtt->pdp has always been the root of our page tables. Legacy 32b addresses acted like it had 1 PDP with 4 PDPEs.
In preparation for 4 level page tables, we need to stop use ppgtt->pdp directly unless we know it's what we want. The future structure will use ppgtt->pml4 for the top level, and the pdp is just one of the entries being pointed to by a pml4e.
This patch addresses some carelessness done throughout development wrt assumptions made of the root page tables.
v2: Updated after dynamic page allocation changes.
v3: Rebase after s/page_tables/page_table/.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 123 ++++++++++++++++++++---------------- 1 file changed, 70 insertions(+), 53 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +70 -53
@@ -560,6 +560,7 @@ static void gen8_ppgtt_clear_range(struct i915_address_space *vm, {struct i915_hw_ppgtt *ppgtt = container_of(vm, struct i915_hw_ppgtt, base); +struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ gen8_gtt_pte_t *pt_vaddr, scratch_pte;unsigned pdpe = start >>GEN8_PDPE_SHIFT &GEN8_PDPE_MASK ;unsigned pde = start >>GEN8_PDE_SHIFT &GEN8_PDE_MASK ;
@@ -575,10 +576,10 @@ static void gen8_ppgtt_clear_range(struct i915_address_space *vm,struct i915_page_table_entry *pt;struct page *page_table; -if (WARN_ON (!ppgtt->pdp.page_directory[pdpe])) +if (WARN_ON (!pdp->page_directory[pdpe]))continue ; - pd = ppgtt->pdp.page_directory[pdpe]; + pd = pdp->page_directory[pdpe];if (WARN_ON (!pd->page_table[pde]))continue ;
@@ -620,6 +621,7 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm, {struct i915_hw_ppgtt *ppgtt = container_of(vm, struct i915_hw_ppgtt, base); +struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ gen8_gtt_pte_t *pt_vaddr;unsigned pdpe = start >>GEN8_PDPE_SHIFT &GEN8_PDPE_MASK ;unsigned pde = start >>GEN8_PDE_SHIFT &GEN8_PDE_MASK ;
@@ -630,7 +632,7 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm,for_each_sg_page (pages->sgl, &sg_iter, pages->nents,0 ) {if (pt_vaddr ==NULL ) { -struct i915_page_directory_entry *pd = ppgtt->pdp.page_directory[pdpe]; +struct i915_page_directory_entry *pd = pdp->page_directory[pdpe];struct i915_page_table_entry *pt = pd->page_table[pde];struct page *page_table = pt->page;
@@ -708,16 +710,17 @@ static void gen8_free_page_tables(struct i915_page_directory_entry *pd, struct dstatic void gen8_ppgtt_unmap_pages (struct i915_hw_ppgtt *ppgtt) {struct pci_dev *hwdev = ppgtt->base.dev->pdev; +struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ int i, j; -for_each_set_bit (i, ppgtt->pdp.used_pdpes, +for_each_set_bit (i, pdp->used_pdpes,I915_PDPES_PER_PDP (ppgtt->base.dev)) {struct i915_page_directory_entry *pd; -if (WARN_ON (!ppgtt->pdp.page_directory[i])) +if (WARN_ON (!pdp->page_directory[i]))continue ; - pd = ppgtt->pdp.page_directory[i]; + pd = pdp->page_directory[i];if (!pd->daddr)pci_unmap_page (hwdev, pd->daddr,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL );
@@ -743,15 +746,21 @@ static void gen8_ppgtt_free(struct i915_hw_ppgtt *ppgtt) {int i; -for_each_set_bit (i, ppgtt->pdp.used_pdpes, -I915_PDPES_PER_PDP (ppgtt->base.dev)) { -if (WARN_ON (!ppgtt->pdp.page_directory[i])) -continue ; +if (!USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) { +for_each_set_bit (i, ppgtt->pdp.used_pdpes, +I915_PDPES_PER_PDP (ppgtt->base.dev)) { +if (WARN_ON (!ppgtt->pdp.page_directory[i])) +continue ; -gen8_free_page_tables (ppgtt->pdp.page_directory[i], ppgtt->base.dev); -unmap_and_free_pd (ppgtt->pdp.page_directory[i], ppgtt->base.dev); +gen8_free_page_tables (ppgtt->pdp.page_directory[i], + ppgtt->base.dev); +unmap_and_free_pd (ppgtt->pdp.page_directory[i], + ppgtt->base.dev); + } +unmap_and_free_pdp (&ppgtt->pdp, ppgtt->base.dev); + }else { +BUG ();/* to be implemented later */ } -unmap_and_free_pdp (&ppgtt->pdp, ppgtt->base.dev); }static void gen8_ppgtt_cleanup (struct i915_address_space *vm)
@@ -765,7 +774,7 @@ static void gen8_ppgtt_cleanup(struct i915_address_space *vm)/** * gen8_ppgtt_alloc_pagetabs() - Allocate page tables for VA range. -* @ppgtt: Master ppgtt structure. +* @vm: Master vm structure. * @pd: Page directory for this address range. * @start: Starting virtual address to begin allocations. * @length Size of the allocations.
@@ -781,12 +790,13 @@ static void gen8_ppgtt_cleanup(struct i915_address_space *vm)* * Return: 0 if success; negative error code otherwise. */ -static int gen8_ppgtt_alloc_pagetabs (struct i915_hw_ppgtt *ppgtt, +static int gen8_ppgtt_alloc_pagetabs (struct i915_address_space *vm,struct i915_page_directory_entry *pd,uint64_t start,uint64_t length,unsigned long *new_pts) { +struct drm_device *dev = vm->dev;struct i915_page_table_entry *pt;uint64_t temp;uint32_t pde;
@@ -799,7 +809,7 @@ static int gen8_ppgtt_alloc_pagetabs(struct i915_hw_ppgtt *ppgtt,continue ; } - pt =alloc_pt_single (ppgtt->base.dev); + pt =alloc_pt_single (dev);if (IS_ERR (pt)) goto unwind_out;
@@ -811,14 +821,14 @@ static int gen8_ppgtt_alloc_pagetabs(struct i915_hw_ppgtt *ppgtt, unwind_out:for_each_set_bit (pde, new_pts,GEN8_PDES_PER_PAGE ) -unmap_and_free_pt (pd->page_table[pde], ppgtt->base.dev); +unmap_and_free_pt (pd->page_table[pde], dev);return -ENOMEM ; }/** * gen8_ppgtt_alloc_page_directories() - Allocate page directories for VA range. -* @ppgtt: Master ppgtt structure. +* @vm: Master vm structure. * @pdp: Page directory pointer for this address range. * @start: Starting virtual address to begin allocations. * @length Size of the allocations.
@@ -839,16 +849,17 @@ unwind_out:* * Return: 0 if success; negative error code otherwise. */ -static int gen8_ppgtt_alloc_page_directories (struct i915_hw_ppgtt *ppgtt, +static int gen8_ppgtt_alloc_page_directories (struct i915_address_space *vm,struct i915_page_directory_pointer_entry *pdp,uint64_t start,uint64_t length,unsigned long *new_pds) { +struct drm_device *dev = vm->dev;struct i915_page_directory_entry *pd;uint64_t temp;uint32_t pdpe; -size_t pdpes =I915_PDPES_PER_PDP (ppgtt->base.dev); +size_t pdpes =I915_PDPES_PER_PDP (vm->dev);BUG_ON (!bitmap_empty (new_pds, pdpes));
@@ -859,7 +870,7 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_hw_ppgtt *ppgtt,if (pd)continue ; - pd =alloc_pd_single (ppgtt->base.dev); + pd =alloc_pd_single (dev);if (IS_ERR (pd)) goto unwind_out;
@@ -871,7 +882,7 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_hw_ppgtt *ppgtt, unwind_out:for_each_set_bit (pdpe, new_pds, pdpes) -unmap_and_free_pd (pdp->page_directory[pdpe], ppgtt->base.dev); +unmap_and_free_pd (pdp->page_directory[pdpe], dev);return -ENOMEM ; }
@@ -926,13 +937,13 @@ err_out:return -ENOMEM ; } -static int gen8_alloc_va_range (struct i915_address_space *vm, -uint64_t start, -uint64_t length) +static int gen8_alloc_va_range_3lvl (struct i915_address_space *vm, +struct i915_page_directory_pointer_entry *pdp, +uint64_t start, +uint64_t length) { -struct i915_hw_ppgtt *ppgtt = - container_of(vm, struct i915_hw_ppgtt, base);unsigned long *new_page_dirs, **new_page_tables; +struct drm_device *dev = vm->dev;struct i915_page_directory_entry *pd;const uint64_t orig_start = start;const uint64_t orig_length = length;
@@ -961,17 +972,15 @@ static int gen8_alloc_va_range(struct i915_address_space *vm,return ret;/* Do the allocations first so we can easily bail out */ - ret =gen8_ppgtt_alloc_page_directories (ppgtt, &ppgtt->pdp, start, length, - new_page_dirs); + ret =gen8_ppgtt_alloc_page_directories (vm, pdp, start, length, new_page_dirs);if (ret) {free_gen8_temp_bitmaps (new_page_dirs, new_page_tables, pdpes);return ret; } -/* For every page directory referenced, allocate page tables */ -gen8_for_each_pdpe (pd, &ppgtt->pdp, start, length, temp, pdpe) { +gen8_for_each_pdpe (pd, pdp, start, length, temp, pdpe) {bitmap_zero (new_page_tables[pdpe],GEN8_PDES_PER_PAGE ); - ret =gen8_ppgtt_alloc_pagetabs (ppgtt, pd, start, length, + ret =gen8_ppgtt_alloc_pagetabs (vm, pd, start, length, new_page_tables[pdpe]);if (ret) goto err_out;
@@ -980,10 +989,7 @@ static int gen8_alloc_va_range(struct i915_address_space *vm, start = orig_start; length = orig_length; -/* Allocations have completed successfully, so set the bitmaps, and do -* the mappings. */ -gen8_for_each_pdpe (pd, &ppgtt->pdp, start, length, temp, pdpe) { -gen8_ppgtt_pde_t *const page_directory =kmap_atomic (pd->page); +gen8_for_each_pdpe (pd, pdp, start, length, temp, pdpe) {struct i915_page_table_entry *pt;uint64_t pd_len =gen8_clamp_pd (start, length);uint64_t pd_start = start;
@@ -1005,20 +1011,10 @@ static int gen8_alloc_va_range(struct i915_address_space *vm,/* Our pde is now pointing to the pagetable, pt */ set_bit (pde, pd->used_pdes); - -/* Map the PDE to the page table */ -__gen8_do_map_pt (page_directory + pde, pt, vm->dev); - -/* NB: We haven't yet mapped ptes to pages. At this -* point we're still relying on insert_entries() */ } -if (!HAS_LLC (vm->dev)) -drm_clflush_virt_range (page_directory,PAGE_SIZE ); - -kunmap_atomic (page_directory); - -set_bit (pdpe, ppgtt->pdp.used_pdpes); +set_bit (pdpe, pdp->used_pdpes); +gen8_map_pagetable_range (pd, start, length, dev); }free_gen8_temp_bitmaps (new_page_dirs, new_page_tables, pdpes);
@@ -1027,16 +1023,36 @@ static int gen8_alloc_va_range(struct i915_address_space *vm, err_out:while (pdpe--) {for_each_set_bit (temp, new_page_tables[pdpe],GEN8_PDES_PER_PAGE ) -unmap_and_free_pt (pd->page_table[temp], vm->dev); +unmap_and_free_pt (pd->page_table[temp], dev); }for_each_set_bit (pdpe, new_page_dirs, pdpes) -unmap_and_free_pd (ppgtt->pdp.page_directory[pdpe], vm->dev); +unmap_and_free_pd (pdp->page_directory[pdpe], dev);free_gen8_temp_bitmaps (new_page_dirs, new_page_tables, pdpes);return ret; } +static int __noreturn gen8_alloc_va_range_4lvl (struct i915_address_space *vm, +struct i915_pml4 *pml4, +uint64_t start, +uint64_t length) +{ +BUG ();/* to be implemented later */ +} + +static int gen8_alloc_va_range (struct i915_address_space *vm, +uint64_t start,uint64_t length) +{ +struct i915_hw_ppgtt *ppgtt = + container_of(vm, struct i915_hw_ppgtt, base); + +if (!USES_FULL_48BIT_PPGTT (vm->dev)) +return gen8_alloc_va_range_3lvl (vm, &ppgtt->pdp, start, length); +else +return gen8_alloc_va_range_4lvl (vm, &ppgtt->pml4, start, length); +} +static void gen8_ppgtt_fini_common (struct i915_hw_ppgtt *ppgtt) {unmap_and_free_pt (ppgtt->scratch_pd, ppgtt->base.dev);
@@ -1079,12 +1095,13 @@ static int gen8_aliasing_ppgtt_init(struct i915_hw_ppgtt *ppgtt) {struct drm_device *dev = ppgtt->base.dev;struct drm_i915_private *dev_priv = dev->dev_private; +struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ struct i915_page_directory_entry *pd;uint64_t temp, start =0 , size = dev_priv->gtt.base.total;uint32_t pdpe;int ret; - ret =gen8_ppgtt_init_common (ppgtt, dev_priv->gtt.base.total); + ret =gen8_ppgtt_init_common (ppgtt, size);if (ret)return ret;
@@ -1097,8 +1114,8 @@ static int gen8_aliasing_ppgtt_init(struct i915_hw_ppgtt *ppgtt)return ret; } -gen8_for_each_pdpe (pd, &ppgtt->pdp, start, size, temp, pdpe) -gen8_map_pagetable_range (pd, start, size, ppgtt->base.dev); +gen8_for_each_pdpe (pd, pdp, start, size, temp, pdpe) +gen8_map_pagetable_range (pd, start, size, dev); ppgtt->base.allocate_va_range =NULL ; ppgtt->base.clear_range = gen8_ppgtt_clear_range;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 23/32 drm/i915/bdw: Add dynamic page trace events
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
The dynamic page allocation patch series added it for GEN6, this patch adds them for GEN8.
v2: Consolidate pagetable/page_directory events
v3: Multiple rebases.
v4: Rebase after s/page_tables/page_table/.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 23 +++++++++++++++-------- drivers/gpu/drm/i915/i915_trace.h | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +15 -8
@@ -673,19 +673,24 @@ static void __gen8_do_map_pt(gen8_ppgtt_pde_t * const pde,/* It's likely we'll map more than one pagetable at a time. This function will * save us unnecessary kmap calls, but do no more functionally than multiple * calls to map_pt. */ -static void gen8_map_pagetable_range (struct i915_page_directory_entry *pd, +static void gen8_map_pagetable_range (struct i915_address_space *vm, +struct i915_page_directory_entry *pd,uint64_t start, -uint64_t length, -struct drm_device *dev) +uint64_t length) {gen8_ppgtt_pde_t *const page_directory =kmap_atomic (pd->page);struct i915_page_table_entry *pt;uint64_t temp, pde; -gen8_for_each_pde (pt, pd, start, length, temp, pde) -__gen8_do_map_pt (page_directory + pde, pt, dev); +gen8_for_each_pde (pt, pd, start, length, temp, pde) { +__gen8_do_map_pt (page_directory + pde, pt, vm->dev); +trace_i915_page_table_entry_map (vm, pde, pt, +gen8_pte_index (start), +gen8_pte_count (start, length), +GEN8_PTES_PER_PAGE ); + } -if (!HAS_LLC (dev)) +if (!HAS_LLC (vm->dev))drm_clflush_virt_range (page_directory,PAGE_SIZE );kunmap_atomic (page_directory);
@@ -815,6 +820,7 @@ static int gen8_ppgtt_alloc_pagetabs(struct i915_address_space *vm, pd->page_table[pde] = pt;set_bit (pde, new_pts); +trace_i915_page_table_entry_alloc (vm, pde, start,GEN8_PDE_SHIFT ); }return 0 ;
@@ -876,6 +882,7 @@ static int gen8_ppgtt_alloc_page_directories(struct i915_address_space *vm, pdp->page_directory[pdpe] = pd;set_bit (pdpe, new_pds); +trace_i915_page_directory_entry_alloc (vm, pdpe, start,GEN8_PDPE_SHIFT ); }return 0 ;
@@ -1014,7 +1021,7 @@ static int gen8_alloc_va_range_3lvl(struct i915_address_space *vm, }set_bit (pdpe, pdp->used_pdpes); -gen8_map_pagetable_range (pd, start, length, dev); +gen8_map_pagetable_range (vm, pd, start, length); }free_gen8_temp_bitmaps (new_page_dirs, new_page_tables, pdpes);
@@ -1115,7 +1122,7 @@ static int gen8_aliasing_ppgtt_init(struct i915_hw_ppgtt *ppgtt) }gen8_for_each_pdpe (pd, pdp, start, size, temp, pdpe) -gen8_map_pagetable_range (pd, start, size, dev); +gen8_map_pagetable_range (&ppgtt->base, pd,start, size); ppgtt->base.allocate_va_range =NULL ; ppgtt->base.clear_range = gen8_ppgtt_clear_range;
drivers/gpu/drm/i915/i915_trace.h +16 -0
@@ -214,6 +214,22 @@ DEFINE_EVENT(i915_page_table_entry, i915_page_table_entry_alloc,TP_ARGS (vm, pde, start, pde_shift) ); +DEFINE_EVENT_PRINT (i915_page_table_entry, i915_page_directory_entry_alloc, + TP_PROTO(struct i915_address_space *vm, u32 pdpe, u64 start, u64 pdpe_shift), +TP_ARGS (vm, pdpe, start, pdpe_shift), + +TP_printk ("vm=%p, pdpe=%d (0x%llx-0x%llx)" , + __entry->vm, __entry->pde, __entry->start, __entry->end) +); + +DEFINE_EVENT_PRINT (i915_page_table_entry, i915_page_directory_pointer_entry_alloc, + TP_PROTO(struct i915_address_space *vm, u32 pml4e, u64 start, u64 pml4e_shift), +TP_ARGS (vm, pml4e, start, pml4e_shift), + +TP_printk ("vm=%p, pml4e=%d (0x%llx-0x%llx)" , + __entry->vm, __entry->pde, __entry->start, __entry->end) +); +/* Avoid extra math because we only support two sizes. The format is defined by * bitmap_scnprintf. Each 32 bits is 8 HEX digits followed by comma */ #define TRACE_PT_SIZE (bits) \
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 24/32 drm/i915/bdw: Add ppgtt info for dynamic pages
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
Note that there is no gen8 ppgtt debug_dump function yet.
--- drivers/gpu/drm/i915/i915_debugfs.c | 19 ++++++++++--------- drivers/gpu/drm/i915/i915_gem_gtt.c | 32 ++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_gem_gtt.h | 9 +++++++++ 3 files changed, 51 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +10 -9
@@ -2165,7 +2165,6 @@ static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev) {struct drm_i915_private *dev_priv = dev->dev_private;struct intel_engine_cs *ring; -struct drm_file *file;int i;if (INTEL_INFO (dev)->gen ==6 )
@@ -2189,14 +2188,6 @@ static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev) ppgtt->debug_dump (ppgtt, m); } - -list_for_each_entry_reverse (file, &dev->filelist, lhead) { -struct drm_i915_file_private *file_priv = file->driver_priv; - -seq_printf (m,"proc: %s\n" , -get_pid_task (file->pid,PIDTYPE_PID )->comm); -idr_for_each (&file_priv->context_idr, per_file_ctx, m); - } }static int i915_ppgtt_info (struct seq_file *m,void *data)
@@ -2204,6 +2195,7 @@ static int i915_ppgtt_info(struct seq_file *m, void *data)struct drm_info_node *node = m->private;struct drm_device *dev = node->minor->dev;struct drm_i915_private *dev_priv = dev->dev_private; +struct drm_file *file;int ret =mutex_lock_interruptible (&dev->struct_mutex);if (ret)
@@ -2215,6 +2207,15 @@ static int i915_ppgtt_info(struct seq_file *m, void *data)else if (INTEL_INFO (dev)->gen >=6 )gen6_ppgtt_info (m, dev); +list_for_each_entry_reverse (file, &dev->filelist, lhead) { +struct drm_i915_file_private *file_priv = file->driver_priv; + +seq_printf (m,"\nproc: %s\n" , +get_pid_task (file->pid,PIDTYPE_PID )->comm); +idr_for_each (&file_priv->context_idr, per_file_ctx, + (void *)(unsigned long )m); + } +intel_runtime_pm_put (dev_priv);mutex_unlock (&dev->struct_mutex);
drivers/gpu/drm/i915/i915_gem_gtt.c +32 -0
@@ -2128,6 +2128,38 @@ static void gen8_ggtt_clear_range(struct i915_address_space *vm,readl (gtt_base); } +void gen8_for_every_pdpe_pde (struct i915_hw_ppgtt *ppgtt, +void (*callback)(struct i915_page_directory_pointer_entry *pdp, +struct i915_page_directory_entry *pd, +struct i915_page_table_entry *pt, +unsigned pdpe, +unsigned pde, +void *data), +void *data) +{ +uint64_t start = ppgtt->base.start; +uint64_t length = ppgtt->base.total; +uint64_t pdpe, pde, temp; + +struct i915_page_directory_entry *pd; +struct i915_page_table_entry *pt; + +gen8_for_each_pdpe (pd, &ppgtt->pdp, start, length, temp, pdpe) { +uint64_t pd_start = start, pd_length = length; +int i; + +if (pd ==NULL ) { +for (i =0 ; i <GEN8_PDES_PER_PAGE ; i++) +callback (&ppgtt->pdp,NULL ,NULL , pdpe, i, data); +continue ; + } + +gen8_for_each_pde (pt, pd, pd_start, pd_length, temp, pde) { +callback (&ppgtt->pdp, pd, pt, pdpe, pde, data); + } + } +} + static void gen6_ggtt_clear_range(struct i915_address_space *vm, uint64_t start, uint64_t length,
drivers/gpu/drm/i915/i915_gem_gtt.h +9 -0
@@ -483,6 +483,15 @@ static inline size_t gen8_pde_count(uint64_t addr, uint64_t length)return i915_pde_index (end,GEN8_PDE_SHIFT ) -i915_pde_index (addr,GEN8_PDE_SHIFT ); } +void gen8_for_every_pdpe_pde (struct i915_hw_ppgtt *ppgtt, +void (*callback)(struct i915_page_directory_pointer_entry *pdp, +struct i915_page_directory_entry *pd, +struct i915_page_table_entry *pt, +unsigned pdpe, +unsigned pde, +void *data), +void *data); +int i915_gem_gtt_init (struct drm_device *dev);void i915_gem_init_global_gtt (struct drm_device *dev);void i915_global_gtt_cleanup (struct drm_device *dev);
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 25/32 drm/i915/bdw: implement alloc/free for 4lvl
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
The code for 4lvl works just as one would expect, and nicely it is able to call into the existing 3lvl page table code to handle all of the lower levels.
PML4 has no special attributes, and there will always be a PML4. So simply initialize it at creation, and destroy it at the end.
v2: Return something at the end of gen8_alloc_va_range_4lvl to keep the compiler happy. And define ret only in one place.
Updated gen8_ppgtt_unmap_pages and gen8_ppgtt_free to handle 4lvl.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 240 +++++++++++++++++++++++++++++++----- drivers/gpu/drm/i915/i915_gem_gtt.h | 11 +- 2 files changed, 217 insertions(+), 34 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +207 -33
@@ -483,9 +483,12 @@ static void __pdp_fini(struct i915_page_directory_pointer_entry *pdp)static void unmap_and_free_pdp (struct i915_page_directory_pointer_entry *pdp,struct drm_device *dev) { -__pdp_fini (pdp); -if (USES_FULL_48BIT_PPGTT (dev)) +if (USES_FULL_48BIT_PPGTT (dev)) { +__pdp_fini (pdp); +i915_dma_unmap_single (pdp, dev); +__free_page (pdp->page);kfree (pdp); + } } static int __pdp_init(struct i915_page_directory_pointer_entry *pdp,
@@ -511,6 +514,60 @@ static int __pdp_init(struct i915_page_directory_pointer_entry *pdp,return 0 ; } +static struct i915_page_directory_pointer_entry *alloc_pdp_single (struct i915_hw_ppgtt *ppgtt, +struct i915_pml4 *pml4) +{ +struct drm_device *dev = ppgtt->base.dev; +struct i915_page_directory_pointer_entry *pdp; +int ret; + +BUG_ON (!USES_FULL_48BIT_PPGTT (dev)); + + pdp =kmalloc (sizeof (*pdp),GFP_KERNEL ); +if (!pdp) +return ERR_PTR (-ENOMEM ); + + pdp->page =alloc_page (GFP_KERNEL |GFP_DMA32 | __GFP_ZERO); +if (!pdp->page) { +kfree (pdp); +return ERR_PTR (-ENOMEM ); + } + + ret =__pdp_init (pdp, dev); +if (ret) { +__free_page (pdp->page); +kfree (pdp); +return ERR_PTR (ret); + } + +i915_dma_map_single (pdp, dev); + +return pdp; +} + +static void pml4_fini (struct i915_pml4 *pml4) +{ +struct i915_hw_ppgtt *ppgtt = + container_of(pml4, struct i915_hw_ppgtt, pml4); +i915_dma_unmap_single (pml4, ppgtt->base.dev); +__free_page (pml4->page); +/* HACK */ + pml4->page =NULL ; +} + +static int pml4_init (struct i915_hw_ppgtt *ppgtt) +{ +struct i915_pml4 *pml4 = &ppgtt->pml4; + + pml4->page =alloc_page (GFP_KERNEL | __GFP_ZERO); +if (!pml4->page) +return -ENOMEM ; + +i915_dma_map_single (pml4, ppgtt->base.dev); + +return 0 ; +} +/* Broadwell Page Directory Pointer Descriptors */ static int gen8_write_pdp(struct intel_engine_cs *ring, unsigned entry,
@@ -712,14 +769,13 @@ static void gen8_free_page_tables(struct i915_page_directory_entry *pd, struct d } } -static void gen8_ppgtt_unmap_pages (struct i915_hw_ppgtt *ppgtt) +static void gen8_ppgtt_unmap_pages_3lvl (struct i915_page_directory_pointer_entry *pdp, +struct drm_device *dev) { -struct pci_dev *hwdev = ppgtt->base.dev->pdev; -struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ +struct pci_dev *hwdev = dev->pdev;int i, j; -for_each_set_bit (i, pdp->used_pdpes, -I915_PDPES_PER_PDP (ppgtt->base.dev)) { +for_each_set_bit (i, pdp->used_pdpes,I915_PDPES_PER_PDP (dev)) {struct i915_page_directory_entry *pd;if (WARN_ON (!pdp->page_directory[i]))
@@ -747,27 +803,73 @@ static void gen8_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt) } } -static void gen8_ppgtt_free (struct i915_hw_ppgtt *ppgtt) +static void gen8_ppgtt_unmap_pages_4lvl (struct i915_hw_ppgtt *ppgtt) { +struct pci_dev *hwdev = ppgtt->base.dev->pdev;int i; -if (!USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) { -for_each_set_bit (i, ppgtt->pdp.used_pdpes, -I915_PDPES_PER_PDP (ppgtt->base.dev)) { -if (WARN_ON (!ppgtt->pdp.page_directory[i])) -continue ; +for_each_set_bit (i, ppgtt->pml4.used_pml4es,GEN8_PML4ES_PER_PML4 ) { +struct i915_page_directory_pointer_entry *pdp; -gen8_free_page_tables (ppgtt->pdp.page_directory[i], - ppgtt->base.dev); -unmap_and_free_pd (ppgtt->pdp.page_directory[i], - ppgtt->base.dev); - } -unmap_and_free_pdp (&ppgtt->pdp, ppgtt->base.dev); - }else { -BUG ();/* to be implemented later */ +if (WARN_ON (!ppgtt->pml4.pdps[i])) +continue ; + + pdp = ppgtt->pml4.pdps[i]; +if (!pdp->daddr) +pci_unmap_page (hwdev, pdp->daddr,PAGE_SIZE , +PCI_DMA_BIDIRECTIONAL ); + +gen8_ppgtt_unmap_pages_3lvl (ppgtt->pml4.pdps[i], + ppgtt->base.dev); } } +static void gen8_ppgtt_unmap_pages (struct i915_hw_ppgtt *ppgtt) +{ +if (!USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) +gen8_ppgtt_unmap_pages_3lvl (&ppgtt->pdp, ppgtt->base.dev); +else +gen8_ppgtt_unmap_pages_4lvl (ppgtt); +} + +static void gen8_ppgtt_free_3lvl (struct i915_page_directory_pointer_entry *pdp, +struct drm_device *dev) +{ +int i; + +for_each_set_bit (i, pdp->used_pdpes,I915_PDPES_PER_PDP (dev)) { +if (WARN_ON (!pdp->page_directory[i])) +continue ; + +gen8_free_page_tables (pdp->page_directory[i], dev); +unmap_and_free_pd (pdp->page_directory[i], dev); + } + +unmap_and_free_pdp (pdp, dev); +} + +static void gen8_ppgtt_free_4lvl (struct i915_hw_ppgtt *ppgtt) +{ +int i; + +for_each_set_bit (i, ppgtt->pml4.used_pml4es,GEN8_PML4ES_PER_PML4 ) { +if (WARN_ON (!ppgtt->pml4.pdps[i])) +continue ; + +gen8_ppgtt_free_3lvl (ppgtt->pml4.pdps[i], ppgtt->base.dev); + } + +pml4_fini (&ppgtt->pml4); +} + +static void gen8_ppgtt_free (struct i915_hw_ppgtt *ppgtt) +{ +if (!USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) +gen8_ppgtt_free_3lvl (&ppgtt->pdp, ppgtt->base.dev); +else +gen8_ppgtt_free_4lvl (ppgtt); +} +static void gen8_ppgtt_cleanup (struct i915_address_space *vm) { struct i915_hw_ppgtt *ppgtt =
@@ -1040,12 +1142,74 @@ err_out:return ret; } -static int __noreturn gen8_alloc_va_range_4lvl (struct i915_address_space *vm, -struct i915_pml4 *pml4, -uint64_t start, -uint64_t length) +static int gen8_alloc_va_range_4lvl (struct i915_address_space *vm, +struct i915_pml4 *pml4, +uint64_t start, +uint64_t length) { -BUG ();/* to be implemented later */ +DECLARE_BITMAP (new_pdps,GEN8_PML4ES_PER_PML4 ); +struct i915_hw_ppgtt *ppgtt = + container_of(vm, struct i915_hw_ppgtt, base); +struct i915_page_directory_pointer_entry *pdp; +const uint64_t orig_start = start; +const uint64_t orig_length = length; +uint64_t temp, pml4e; +int ret =0 ; + +/* Do the pml4 allocations first, so we don't need to track the newly +* allocated tables below the pdp */ +bitmap_zero (new_pdps,GEN8_PML4ES_PER_PML4 ); + +/* The page_directoryectory and pagetable allocations are done in the shared 3 +* and 4 level code. Just allocate the pdps. +*/ +gen8_for_each_pml4e (pdp, pml4, start, length, temp, pml4e) { +if (!pdp) { +WARN_ON (test_bit (pml4e, pml4->used_pml4es)); + pdp =alloc_pdp_single (ppgtt, pml4); +if (IS_ERR (pdp)) + goto err_alloc; + + pml4->pdps[pml4e] = pdp; +set_bit (pml4e, new_pdps); +trace_i915_page_directory_pointer_entry_alloc (&ppgtt->base, pml4e, + pml4e <<GEN8_PML4E_SHIFT , +GEN8_PML4E_SHIFT ); + + } + } + +WARN (bitmap_weight (new_pdps,GEN8_PML4ES_PER_PML4 ) >2 , +"The allocation has spanned more than 512GB. " +"It is highly likely this is incorrect." ); + + start = orig_start; + length = orig_length; + +gen8_for_each_pml4e (pdp, pml4, start, length, temp, pml4e) { +BUG_ON (!pdp); + + ret =gen8_alloc_va_range_3lvl (vm, pdp, start, length); +if (ret) + goto err_out; + } + +bitmap_or (pml4->used_pml4es, new_pdps, pml4->used_pml4es, +GEN8_PML4ES_PER_PML4 ); + +return 0 ; + +err_out: + start = orig_start; + length = orig_length; +gen8_for_each_pml4e (pdp, pml4, start, length, temp, pml4e) +gen8_ppgtt_free_3lvl (pdp, vm->dev); + +err_alloc: +for_each_set_bit (pml4e, new_pdps,GEN8_PML4ES_PER_PML4 ) +unmap_and_free_pdp (pdp, vm->dev); + +return ret; } static int gen8_alloc_va_range(struct i915_address_space *vm,
@@ -1054,16 +1218,19 @@ static int gen8_alloc_va_range(struct i915_address_space *vm,struct i915_hw_ppgtt *ppgtt = container_of(vm, struct i915_hw_ppgtt, base); -if (!USES_FULL_48BIT_PPGTT (vm->dev)) -return gen8_alloc_va_range_3lvl (vm, &ppgtt->pdp, start, length); -else +if (USES_FULL_48BIT_PPGTT (vm->dev))return gen8_alloc_va_range_4lvl (vm, &ppgtt->pml4, start, length); +else +return gen8_alloc_va_range_3lvl (vm, &ppgtt->pdp, start, length); }static void gen8_ppgtt_fini_common (struct i915_hw_ppgtt *ppgtt) {unmap_and_free_pt (ppgtt->scratch_pd, ppgtt->base.dev); -unmap_and_free_pdp (&ppgtt->pdp, ppgtt->base.dev); +if (USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) +pml4_fini (&ppgtt->pml4); +else +unmap_and_free_pdp (&ppgtt->pdp, ppgtt->base.dev); }/**
@@ -1086,14 +1253,21 @@ static int gen8_ppgtt_init_common(struct i915_hw_ppgtt *ppgtt, uint64_t size) ppgtt->switch_mm = gen8_mm_switch; -if (!USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) { +if (USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) { +int ret =pml4_init (ppgtt); +if (ret) { +unmap_and_free_pt (ppgtt->scratch_pd, ppgtt->base.dev); +return ret; + } + }else {int ret =__pdp_init (&ppgtt->pdp, false);if (ret) {unmap_and_free_pt (ppgtt->scratch_pd, ppgtt->base.dev);return ret; } - }else -return -EPERM ;/* Not yet implemented */ + +trace_i915_page_directory_pointer_entry_alloc (&ppgtt->base,0 ,0 ,GEN8_PML4E_SHIFT ); + }return 0 ; }
drivers/gpu/drm/i915/i915_gem_gtt.h +10 -1
@@ -87,6 +87,7 @@ typedef gen8_gtt_pte_t gen8_ppgtt_pde_t;*/ #define GEN8_PML4ES_PER_PML4 512#define GEN8_PML4E_SHIFT 39 +#define GEN8_PML4E_MASK (GEN8_PML4ES_PER_PML4 - 1)#define GEN8_PDPE_SHIFT 30/* NB: GEN8_PDPE_MASK is untrue for 32b platforms, but it has no impact on 32b page * tables */
@@ -427,6 +428,14 @@ static inline uint32_t gen6_pde_index(uint32_t addr) temp = min(temp, length), \ start += temp, length -= temp) +#define gen8_for_each_pml4e (pdp, pml4, start, length, temp, iter) \ + for (iter = gen8_pml4e_index(start), pdp = (pml4)->pdps[iter]; \ + length > 0 && iter < GEN8_PML4ES_PER_PML4; \ + pdp = (pml4)->pdps[++iter], \ + temp = ALIGN(start+1, 1ULL << GEN8_PML4E_SHIFT) - start, \ + temp = min(temp, length), \ + start += temp, length -= temp) +#define gen8_for_each_pdpe (pd, pdp, start, length, temp, iter) \ gen8_for_each_pdpe_e(pd, pdp, start, length, temp, iter, I915_PDPES_PER_PDP(dev))
@@ -458,7 +467,7 @@ static inline uint32_t gen8_pdpe_index(uint64_t address)static inline uint32_t gen8_pml4e_index (uint64_t address) { -BUG ();/* For 64B */ +return (address >>GEN8_PML4E_SHIFT ) &GEN8_PML4E_MASK ; }static inline size_t gen8_pte_count (uint64_t addr,uint64_t length)
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 26/32 drm/i915/bdw: Add 4 level switching infrastructure
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
Map is easy, it's the same register as the PDP descriptor 0, but it only has one entry.
v2: PML4 update in legacy context switch is left for historic reasons, the preferred mode of operation is with lrc context based submission.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 56 +++++++++++++++++++++++++++++++++---- drivers/gpu/drm/i915/i915_gem_gtt.h | 4 ++- drivers/gpu/drm/i915/i915_reg.h | 1 + 3 files changed, 55 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +51 -5
@@ -193,6 +193,9 @@ static inline gen8_ppgtt_pde_t gen8_pde_encode(struct drm_device *dev,return pde; } +#define gen8_pdpe_encode gen8_pde_encode +#define gen8_pml4e_encode gen8_pde_encode +static gen6_gtt_pte_t snb_pte_encode (dma_addr_t addr,enum i915_cache_level level,bool valid,u32 unused)
@@ -592,8 +595,8 @@ static int gen8_write_pdp(struct intel_engine_cs *ring,return 0 ; } -static int gen8_mm_switch (struct i915_hw_ppgtt *ppgtt, -struct intel_engine_cs *ring) +static int gen8_legacy_mm_switch (struct i915_hw_ppgtt *ppgtt, +struct intel_engine_cs *ring) {int i, ret;
@@ -610,6 +613,12 @@ static int gen8_mm_switch(struct i915_hw_ppgtt *ppgtt,return 0 ; } +static int gen8_48b_mm_switch (struct i915_hw_ppgtt *ppgtt, +struct intel_engine_cs *ring) +{ +return gen8_write_pdp (ring,0 , ppgtt->pml4.daddr); +} + static void gen8_ppgtt_clear_range(struct i915_address_space *vm, uint64_t start, uint64_t length,
@@ -753,6 +762,37 @@ static void gen8_map_pagetable_range(struct i915_address_space *vm,kunmap_atomic (page_directory); } +static void gen8_map_page_directory (struct i915_page_directory_pointer_entry *pdp, +struct i915_page_directory_entry *pd, +int index, +struct drm_device *dev) +{ +gen8_ppgtt_pdpe_t *page_directorypo; +gen8_ppgtt_pdpe_t pdpe; + +/* We do not need to clflush because no platform requiring flush +* supports 64b pagetables. */ +if (!USES_FULL_48BIT_PPGTT (dev)) +return ; + + page_directorypo =kmap_atomic (pdp->page); + pdpe =gen8_pdpe_encode (dev, pd->daddr,I915_CACHE_LLC ); + page_directorypo[index] = pdpe; +kunmap_atomic (page_directorypo); +} + +static void gen8_map_page_directory_pointer (struct i915_pml4 *pml4, +struct i915_page_directory_pointer_entry *pdp, +int index, +struct drm_device *dev) +{ +gen8_ppgtt_pml4e_t *pagemap =kmap_atomic (pml4->page); +gen8_ppgtt_pml4e_t pml4e =gen8_pml4e_encode (dev, pdp->daddr,I915_CACHE_LLC ); +BUG_ON (!USES_FULL_48BIT_PPGTT (dev)); + pagemap[index] = pml4e; +kunmap_atomic (pagemap); +} +static void gen8_free_page_tables (struct i915_page_directory_entry *pd,struct drm_device *dev) {int i;
@@ -1124,6 +1164,7 @@ static int gen8_alloc_va_range_3lvl(struct i915_address_space *vm,set_bit (pdpe, pdp->used_pdpes);gen8_map_pagetable_range (vm, pd, start, length); +gen8_map_page_directory (pdp, pd, pdpe, dev); }free_gen8_temp_bitmaps (new_page_dirs, new_page_tables, pdpes);
@@ -1192,6 +1233,8 @@ static int gen8_alloc_va_range_4lvl(struct i915_address_space *vm, ret =gen8_alloc_va_range_3lvl (vm, pdp, start, length);if (ret) goto err_out; + +gen8_map_page_directory_pointer (pml4, pdp, pml4e, vm->dev); } bitmap_or(pml4->used_pml4es, new_pdps, pml4->used_pml4es,
@@ -1251,14 +1294,14 @@ static int gen8_ppgtt_init_common(struct i915_hw_ppgtt *ppgtt, uint64_t size) ppgtt->base.cleanup = gen8_ppgtt_cleanup; ppgtt->base.insert_entries = gen8_ppgtt_insert_entries; - ppgtt->switch_mm = gen8_mm_switch; -if (USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) {int ret =pml4_init (ppgtt);if (ret) {unmap_and_free_pt (ppgtt->scratch_pd, ppgtt->base.dev);return ret; } + + ppgtt->switch_mm = gen8_48b_mm_switch; }else {int ret =__pdp_init (&ppgtt->pdp, false);if (ret) {
@@ -1266,6 +1309,7 @@ static int gen8_ppgtt_init_common(struct i915_hw_ppgtt *ppgtt, uint64_t size)return ret; } + ppgtt->switch_mm = gen8_legacy_mm_switch;trace_i915_page_directory_pointer_entry_alloc (&ppgtt->base,0 ,0 ,GEN8_PML4E_SHIFT ); }
@@ -1295,6 +1339,7 @@ static int gen8_aliasing_ppgtt_init(struct i915_hw_ppgtt *ppgtt)return ret; } +/* FIXME: PML4 */ gen8_for_each_pdpe (pd, pdp, start, size, temp, pdpe)gen8_map_pagetable_range (&ppgtt->base, pd,start, size);
@@ -1499,8 +1544,9 @@ static void gen8_ppgtt_enable(struct drm_device *dev)int j;for_each_ring (ring, dev_priv, j) { +u32 four_level =USES_FULL_48BIT_PPGTT (dev) ?GEN8_GFX_PPGTT_64B :0 ;I915_WRITE (RING_MODE_GEN7 (ring), -_MASKED_BIT_ENABLE (GFX_PPGTT_ENABLE )); +_MASKED_BIT_ENABLE (GFX_PPGTT_ENABLE | four_level)); } }
drivers/gpu/drm/i915/i915_gem_gtt.h +3 -1
@@ -38,7 +38,9 @@ struct drm_i915_file_private;typedef uint32_t gen6_gtt_pte_t ;typedef uint64_t gen8_gtt_pte_t ; -typedef gen8_gtt_pte_t gen8_ppgtt_pde_t ; +typedef gen8_gtt_pte_t gen8_ppgtt_pde_t ; +typedef gen8_ppgtt_pde_t gen8_ppgtt_pdpe_t ; +typedef gen8_ppgtt_pdpe_t gen8_ppgtt_pml4e_t ;#define gtt_total_entries (gtt) ((gtt).base.total >> PAGE_SHIFT)
drivers/gpu/drm/i915/i915_reg.h +1 -0
@@ -1348,6 +1348,7 @@ enum skl_disp_power_wells {#define GFX_REPLAY_MODE (1<<11)#define GFX_PSMI_GRANULARITY (1<<10)#define GFX_PPGTT_ENABLE (1<<9) +#define GEN8_GFX_PPGTT_64B (1<<7)#define VLV_DISPLAY_BASE 0x180000#define VLV_MIPI_BASE VLV_DISPLAY_BASE
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 27/32 drm/i915/bdw: Support 64 bit PPGTT in lrc mode
In reply to Michel ThierryIn 64b (48bit canonical) PPGTT addressing, the PDP0 register contains the base address to PML4, while the other PDP registers are ignored.
Also, the addressing mode must be specified in every context descriptor.
--- drivers/gpu/drm/i915/intel_lrc.c | 167 ++++++++++++++++++++++++++------------- 1 file changed, 114 insertions(+), 53 deletions(-)
drivers/gpu/drm/i915/intel_lrc.c +114 -53
@@ -255,7 +255,8 @@ u32 intel_execlists_ctx_id(struct drm_i915_gem_object *ctx_obj) }static uint64_t execlists_ctx_descriptor (struct intel_engine_cs *ring, -struct drm_i915_gem_object *ctx_obj) +struct drm_i915_gem_object *ctx_obj, +bool legacy_64bit_ctx) {struct drm_device *dev = ring->dev;uint64_t desc;
@@ -264,7 +265,10 @@ static uint64_t execlists_ctx_descriptor(struct intel_engine_cs *ring,WARN_ON (lrca &0xFFFFFFFF00000FFFULL ); desc =GEN8_CTX_VALID ; - desc |=LEGACY_CONTEXT <<GEN8_CTX_MODE_SHIFT ; +if (legacy_64bit_ctx) + desc |=LEGACY_64B_CONTEXT <<GEN8_CTX_MODE_SHIFT ; +else + desc |=LEGACY_CONTEXT <<GEN8_CTX_MODE_SHIFT ; desc |=GEN8_CTX_L3LLC_COHERENT ; desc |=GEN8_CTX_PRIVILEGE ; desc |= lrca;
@@ -292,16 +296,17 @@ static void execlists_elsp_write(struct intel_engine_cs *ring,struct drm_i915_private *dev_priv = dev->dev_private;uint64_t temp =0 ;uint32_t desc[4 ]; +bool legacy_64bit_ctx =USES_FULL_48BIT_PPGTT (dev);/* XXX: You must always write both descriptors in the order below. */ if (ctx_obj1) - temp =execlists_ctx_descriptor (ring, ctx_obj1); + temp =execlists_ctx_descriptor (ring, ctx_obj1, legacy_64bit_ctx);else temp =0 ; desc[1 ] = (u32)(temp >>32 ); desc[0 ] = (u32 )temp; - temp =execlists_ctx_descriptor (ring, ctx_obj0); + temp =execlists_ctx_descriptor (ring, ctx_obj0, legacy_64bit_ctx); desc[3 ] = (u32)(temp >>32 ); desc[2 ] = (u32 )temp;
@@ -332,37 +337,60 @@ static int execlists_update_context(struct drm_i915_gem_object *ctx_obj, reg_state[CTX_RING_TAIL +1 ] = tail; reg_state[CTX_RING_BUFFER_START +1 ] =i915_gem_obj_ggtt_offset (ring_obj); -/* True PPGTT with dynamic page allocation: update PDP registers and -* point the unallocated PDPs to the scratch page -*/ -if (ppgtt) { +if (ppgtt &&USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) { +/* True 64b PPGTT (48bit canonical) +* PDP0_DESCRIPTOR contains the base address to PML4 and +* other PDP Descriptors are ignored +*/ + reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pml4.daddr); + reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pml4.daddr); + }else if (ppgtt) { +/* True 32b PPGTT with dynamic page allocation: update PDP +* registers and point the unallocated PDPs to the scratch page +*/ if (test_bit (3 , ppgtt->pdp.used_pdpes)) { - reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); - reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + reg_state[CTX_PDP3_UDW +1 ] = +upper_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + reg_state[CTX_PDP3_LDW +1 ] = +lower_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); }else { - reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); - reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP3_UDW +1 ] = +upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP3_LDW +1 ] = +lower_32_bits (ppgtt->scratch_pd->daddr); }if (test_bit (2 , ppgtt->pdp.used_pdpes)) { - reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); - reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + reg_state[CTX_PDP2_UDW +1 ] = +upper_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + reg_state[CTX_PDP2_LDW +1 ] = +lower_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); }else { - reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); - reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP2_UDW +1 ] = +upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP2_LDW +1 ] = +lower_32_bits (ppgtt->scratch_pd->daddr); }if (test_bit (1 , ppgtt->pdp.used_pdpes)) { - reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); - reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + reg_state[CTX_PDP1_UDW +1 ] = +upper_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + reg_state[CTX_PDP1_LDW +1 ] = +lower_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); }else { - reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); - reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP1_UDW +1 ] = +upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP1_LDW +1 ] = +lower_32_bits (ppgtt->scratch_pd->daddr); }if (test_bit (0 , ppgtt->pdp.used_pdpes)) { - reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); - reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + reg_state[CTX_PDP0_UDW +1 ] = +upper_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + reg_state[CTX_PDP0_LDW +1 ] = +lower_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); }else { - reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); - reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP0_UDW +1 ] = +upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP0_LDW +1 ] = +lower_32_bits (ppgtt->scratch_pd->daddr); } }
@@ -1771,36 +1799,69 @@ populate_lr_context(struct intel_context *ctx, struct drm_i915_gem_object *ctx_o reg_state[CTX_PDP0_UDW ] =GEN8_RING_PDP_UDW (ring,0 ); reg_state[CTX_PDP0_LDW ] =GEN8_RING_PDP_LDW (ring,0 ); -/* With dynamic page allocation, PDPs may not be allocated at this point, -* Point the unallocated PDPs to the scratch page -*/ -if (test_bit (3 , ppgtt->pdp.used_pdpes)) { - reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); - reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); - }else { - reg_state[CTX_PDP3_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); - reg_state[CTX_PDP3_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); - } -if (test_bit (2 , ppgtt->pdp.used_pdpes)) { - reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); - reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); - }else { - reg_state[CTX_PDP2_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); - reg_state[CTX_PDP2_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); - } -if (test_bit (1 , ppgtt->pdp.used_pdpes)) { - reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); - reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); - }else { - reg_state[CTX_PDP1_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); - reg_state[CTX_PDP1_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); - } -if (test_bit (0 , ppgtt->pdp.used_pdpes)) { - reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); - reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); +if (USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) { +/* 64b PPGTT (48bit canonical) +* PDP0_DESCRIPTOR contains the base address to PML4 and +* other PDP Descriptors are ignored +*/ + reg_state[CTX_PDP3_UDW +1 ] =0 ; + reg_state[CTX_PDP3_LDW +1 ] =0 ; + reg_state[CTX_PDP2_UDW +1 ] =0 ; + reg_state[CTX_PDP2_LDW +1 ] =0 ; + reg_state[CTX_PDP1_UDW +1 ] =0 ; + reg_state[CTX_PDP1_LDW +1 ] =0 ; + reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->pml4.daddr); + reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->pml4.daddr); }else { - reg_state[CTX_PDP0_UDW +1 ] =upper_32_bits (ppgtt->scratch_pd->daddr); - reg_state[CTX_PDP0_LDW +1 ] =lower_32_bits (ppgtt->scratch_pd->daddr); +/* 32b PPGTT +* PDP*_DESCRIPTOR contains the base address of space supported. +* With dynamic page allocation, PDPs may not be allocated at +* this point. Point the unallocated PDPs to the scratch page +*/ +if (test_bit (3 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP3_UDW +1 ] = +upper_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + reg_state[CTX_PDP3_LDW +1 ] = +lower_32_bits (ppgtt->pdp.page_directory[3 ]->daddr); + }else { + reg_state[CTX_PDP3_UDW +1 ] = +upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP3_LDW +1 ] = +lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (test_bit (2 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP2_UDW +1 ] = +upper_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + reg_state[CTX_PDP2_LDW +1 ] = +lower_32_bits (ppgtt->pdp.page_directory[2 ]->daddr); + }else { + reg_state[CTX_PDP2_UDW +1 ] = +upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP2_LDW +1 ] = +lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (test_bit (1 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP1_UDW +1 ] = +upper_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + reg_state[CTX_PDP1_LDW +1 ] = +lower_32_bits (ppgtt->pdp.page_directory[1 ]->daddr); + }else { + reg_state[CTX_PDP1_UDW +1 ] = +upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP1_LDW +1 ] = +lower_32_bits (ppgtt->scratch_pd->daddr); + } +if (test_bit (0 , ppgtt->pdp.used_pdpes)) { + reg_state[CTX_PDP0_UDW +1 ] = +upper_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + reg_state[CTX_PDP0_LDW +1 ] = +lower_32_bits (ppgtt->pdp.page_directory[0 ]->daddr); + }else { + reg_state[CTX_PDP0_UDW +1 ] = +upper_32_bits (ppgtt->scratch_pd->daddr); + reg_state[CTX_PDP0_LDW +1 ] = +lower_32_bits (ppgtt->scratch_pd->daddr); + } }if (ring->id ==RCS ) {
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 28/32 drm/i915/bdw: Generalize PTE writing for GEN8 PPGTT
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
The insert_entries function was the function used to write PTEs. For the PPGTT it was "hardcoded" to only understand two level page tables, which was the case for GEN7. We can reuse this for 4 level page tables, and remove the concept of insert_entries, which was never viable past 2 level page tables anyway, but it requires a bit of rework to make the function a bit more generic.
This patch begins the generalization work, and it will be heavily used upon when the 48b code is complete. The patch series attempts to make each function which touches a part of code specific to the page table level and here is no exception. Having extra variables (such as the PPGTT) distracts and provides room to add bugs since the function shouldn't be touching anything in the higher order page tables.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 55 +++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 17 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +38 -17
@@ -619,23 +619,19 @@ static int gen8_48b_mm_switch(struct i915_hw_ppgtt *ppgtt,return gen8_write_pdp (ring,0 , ppgtt->pml4.daddr); } -static void gen8_ppgtt_clear_range (struct i915_address_space *vm, -uint64_t start, -uint64_t length, -bool use_scratch) +static void gen8_ppgtt_clear_pte_range (struct i915_page_directory_pointer_entry *pdp, +uint64_t start, +uint64_t length, +gen8_gtt_pte_t scratch_pte, +const bool flush) { -struct i915_hw_ppgtt *ppgtt = - container_of(vm, struct i915_hw_ppgtt, base); -struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ -gen8_gtt_pte_t *pt_vaddr, scratch_pte; +gen8_gtt_pte_t *pt_vaddr;unsigned pdpe = start >>GEN8_PDPE_SHIFT &GEN8_PDPE_MASK ;unsigned pde = start >>GEN8_PDE_SHIFT &GEN8_PDE_MASK ;unsigned pte = start >>GEN8_PTE_SHIFT &GEN8_PTE_MASK ;unsigned num_entries = length >>PAGE_SHIFT ;unsigned last_pte, i; - scratch_pte =gen8_pte_encode (ppgtt->base.scratch.addr, -I915_CACHE_LLC , use_scratch);while (num_entries) {struct i915_page_directory_entry *pd;
@@ -668,7 +664,7 @@ static void gen8_ppgtt_clear_range(struct i915_address_space *vm, num_entries--; } -if (!HAS_LLC (ppgtt->base.dev)) +if (flush)drm_clflush_virt_range (pt_vaddr,PAGE_SIZE );kunmap_atomic (pt_vaddr);
@@ -680,14 +676,27 @@ static void gen8_ppgtt_clear_range(struct i915_address_space *vm, } } -static void gen8_ppgtt_insert_entries (struct i915_address_space *vm, -struct sg_table *pages, -uint64_t start, -enum i915_cache_level cache_level,u32 unused) +static void gen8_ppgtt_clear_range (struct i915_address_space *vm, +uint64_t start, +uint64_t length, +bool use_scratch) {struct i915_hw_ppgtt *ppgtt = container_of(vm, struct i915_hw_ppgtt, base);struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ + +gen8_gtt_pte_t scratch_pte =gen8_pte_encode (ppgtt->base.scratch.addr, +I915_CACHE_LLC , use_scratch); + +gen8_ppgtt_clear_pte_range (pdp, start, length, scratch_pte, !HAS_LLC (vm->dev)); +} + +static void gen8_ppgtt_insert_pte_entries (struct i915_page_directory_pointer_entry *pdp, +struct sg_table *pages, +uint64_t start, +enum i915_cache_level cache_level, +const bool flush) +{gen8_gtt_pte_t *pt_vaddr;unsigned pdpe = start >>GEN8_PDPE_SHIFT &GEN8_PDPE_MASK ;unsigned pde = start >>GEN8_PDE_SHIFT &GEN8_PDE_MASK ;
@@ -709,7 +718,7 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm,gen8_pte_encode (sg_page_iter_dma_address (&sg_iter), cache_level, true);if (++pte ==GEN8_PTES_PER_PAGE ) { -if (!HAS_LLC (ppgtt->base.dev)) +if (flush)drm_clflush_virt_range (pt_vaddr,PAGE_SIZE );kunmap_atomic (pt_vaddr); pt_vaddr =NULL ;
@@ -721,12 +730,24 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm, } }if (pt_vaddr) { -if (!HAS_LLC (ppgtt->base.dev)) +if (flush)drm_clflush_virt_range (pt_vaddr,PAGE_SIZE );kunmap_atomic (pt_vaddr); } } +static void gen8_ppgtt_insert_entries (struct i915_address_space *vm, +struct sg_table *pages, +uint64_t start, +enum i915_cache_level cache_level, +u32 unused) +{ + struct i915_hw_ppgtt *ppgtt = container_of(vm, struct i915_hw_ppgtt, base); +struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ + +gen8_ppgtt_insert_pte_entries (pdp, pages, start, cache_level, !HAS_LLC (vm->dev)); +} +static void __gen8_do_map_pt (gen8_ppgtt_pde_t *const pde,struct i915_page_table_entry *pt,struct drm_device *dev)
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 29/32 drm/i915: Plumb sg_iter through va allocation ->maps
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
As a step towards implementing 4 levels, while not discarding the existing pte map functions, we need to pass the sg_iter through. The current function understands to the page directory granularity. An object's pages may span the page directory, and so using the iter directly as we write the PTEs allows the iterator to stay coherent through a VMA mapping operation spanning multiple page table levels.
v2: Rebase after s/page_tables/page_table/.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 46 +++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 17 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +29 -17
@@ -692,7 +692,7 @@ static void gen8_ppgtt_clear_range(struct i915_address_space *vm, }static void gen8_ppgtt_insert_pte_entries (struct i915_page_directory_pointer_entry *pdp, -struct sg_table *pages, +struct sg_page_iter *sg_iter,uint64_t start,enum i915_cache_level cache_level,const bool flush)
@@ -701,11 +701,10 @@ static void gen8_ppgtt_insert_pte_entries(struct i915_page_directory_pointer_entunsigned pdpe = start >>GEN8_PDPE_SHIFT &GEN8_PDPE_MASK ;unsigned pde = start >>GEN8_PDE_SHIFT &GEN8_PDE_MASK ;unsigned pte = start >>GEN8_PTE_SHIFT &GEN8_PTE_MASK ; -struct sg_page_iter sg_iter; pt_vaddr =NULL ; -for_each_sg_page (pages->sgl, &sg_iter, pages->nents,0 ) { +while (__sg_page_iter_next (sg_iter)) {if (pt_vaddr ==NULL ) {struct i915_page_directory_entry *pd = pdp->page_directory[pdpe];struct i915_page_table_entry *pt = pd->page_table[pde];
@@ -715,7 +714,7 @@ static void gen8_ppgtt_insert_pte_entries(struct i915_page_directory_pointer_ent } pt_vaddr[pte] = -gen8_pte_encode (sg_page_iter_dma_address (&sg_iter), +gen8_pte_encode (sg_page_iter_dma_address (sg_iter), cache_level, true);if (++pte ==GEN8_PTES_PER_PAGE ) {if (flush)
@@ -744,8 +743,10 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm, { struct i915_hw_ppgtt *ppgtt = container_of(vm, struct i915_hw_ppgtt, base);struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ +struct sg_page_iter sg_iter; -gen8_ppgtt_insert_pte_entries (pdp, pages, start, cache_level, !HAS_LLC (vm->dev)); +__sg_page_iter_start (&sg_iter, pages->sgl,sg_nents (pages->sgl),0 ); +gen8_ppgtt_insert_pte_entries (pdp, &sg_iter, start, cache_level, !HAS_LLC (vm->dev)); } static void __gen8_do_map_pt(gen8_ppgtt_pde_t * const pde,
@@ -1107,10 +1108,12 @@ err_out:return -ENOMEM ; } -static int gen8_alloc_va_range_3lvl (struct i915_address_space *vm, -struct i915_page_directory_pointer_entry *pdp, -uint64_t start, -uint64_t length) +static int __gen8_alloc_vma_range_3lvl (struct i915_address_space *vm, +struct i915_page_directory_pointer_entry *pdp, +struct sg_page_iter *sg_iter, +uint64_t start, +uint64_t length, +u32 flags) {unsigned long *new_page_dirs, **new_page_tables;struct drm_device *dev = vm->dev;
@@ -1179,7 +1182,11 @@ static int gen8_alloc_va_range_3lvl(struct i915_address_space *vm,gen8_pte_index (pd_start), gen8_pte_count(pd_start, pd_len)); -/* Our pde is now pointing to the pagetable, pt */ +if (sg_iter) { +BUG_ON (!sg_iter->__nents); +gen8_ppgtt_insert_pte_entries (pdp, sg_iter, pd_start, + flags, !HAS_LLC (vm->dev)); + }set_bit (pde, pd->used_pdes); }
@@ -1204,10 +1211,12 @@ err_out:return ret; } -static int gen8_alloc_va_range_4lvl (struct i915_address_space *vm, -struct i915_pml4 *pml4, -uint64_t start, -uint64_t length) +static int __gen8_alloc_vma_range_4lvl (struct i915_address_space *vm, +struct i915_pml4 *pml4, +struct sg_page_iter *sg_iter, +uint64_t start, +uint64_t length, +u32 flags) {DECLARE_BITMAP (new_pdps,GEN8_PML4ES_PER_PML4 ); struct i915_hw_ppgtt *ppgtt =
@@ -1251,7 +1260,8 @@ static int gen8_alloc_va_range_4lvl(struct i915_address_space *vm,gen8_for_each_pml4e (pdp, pml4, start, length, temp, pml4e) {BUG_ON (!pdp); - ret =gen8_alloc_va_range_3lvl (vm, pdp, start, length); + ret =__gen8_alloc_vma_range_3lvl (vm, pdp, sg_iter, + start, length, flags);if (ret) goto err_out;
@@ -1283,9 +1293,11 @@ static int gen8_alloc_va_range(struct i915_address_space *vm, container_of(vm, struct i915_hw_ppgtt, base);if (USES_FULL_48BIT_PPGTT (vm->dev)) -return gen8_alloc_va_range_4lvl (vm, &ppgtt->pml4, start, length); +return __gen8_alloc_vma_range_4lvl (vm, &ppgtt->pml4,NULL , + start, length,0 );else -return gen8_alloc_va_range_3lvl (vm, &ppgtt->pdp, start, length); +return __gen8_alloc_vma_range_3lvl (vm, &ppgtt->pdp,NULL , + start, length,0 ); }static void gen8_ppgtt_fini_common (struct i915_hw_ppgtt *ppgtt)
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 30/32 drm/i915/bdw: Add 4 level support in insert_entries and clear_range
In reply to Michel ThierryWhen 48b is enabled, gen8_ppgtt_insert_entries needs to read the Page Map Level 4 (PML4), before it selects which Page Directory Pointer (PDP) it will write to.
Similarly, gen8_ppgtt_clear_range needs to get the correct PDP/PD range.
Also add a scratch page for PML4.
This patch was inspired by Ben's "Depend exclusively on map and unmap_vma".
v2: Rebase after s/page_tables/page_table/.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 66 ++++++++++++++++++++++++++++++------- drivers/gpu/drm/i915/i915_gem_gtt.h | 12 +++++++ 2 files changed, 67 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +55 -11
@@ -676,24 +676,52 @@ static void gen8_ppgtt_clear_pte_range(struct i915_page_directory_pointer_entry } } +static void gen8_ppgtt_clear_range_4lvl (struct i915_hw_ppgtt *ppgtt, +gen8_gtt_pte_t scratch_pte, +uint64_t start, +uint64_t length) +{ +struct i915_page_directory_pointer_entry *pdp; +uint64_t templ4, templ3, pml4e, pdpe; + +gen8_for_each_pml4e (pdp, &ppgtt->pml4, start, length, templ4, pml4e) { +struct i915_page_directory_entry *pd; +uint64_t pdp_len =gen8_clamp_pdp (start, length); +uint64_t pdp_start = start; + +gen8_for_each_pdpe (pd, pdp, pdp_start, pdp_len, templ3, pdpe) { +uint64_t pd_len =gen8_clamp_pd (pdp_start, pdp_len); +uint64_t pd_start = pdp_start; + +gen8_ppgtt_clear_pte_range (pdp, pd_start, pd_len, + scratch_pte, !HAS_LLC (ppgtt->base.dev)); + } + } +} +static void gen8_ppgtt_clear_range (struct i915_address_space *vm, -uint64_t start, -uint64_t length, +uint64_t start,uint64_t length,bool use_scratch) {struct i915_hw_ppgtt *ppgtt = - container_of(vm, struct i915_hw_ppgtt, base); -struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ - + container_of(vm, struct i915_hw_ppgtt, base);gen8_gtt_pte_t scratch_pte =gen8_pte_encode (ppgtt->base.scratch.addr,I915_CACHE_LLC , use_scratch); -gen8_ppgtt_clear_pte_range (pdp, start, length, scratch_pte, !HAS_LLC (vm->dev)); +if (!USES_FULL_48BIT_PPGTT (vm->dev)) { +struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp; + +gen8_ppgtt_clear_pte_range (pdp, start, length, scratch_pte, + !HAS_LLC (ppgtt->base.dev)); + }else { +gen8_ppgtt_clear_range_4lvl (ppgtt, scratch_pte, start, length); + } }static void gen8_ppgtt_insert_pte_entries (struct i915_page_directory_pointer_entry *pdp,struct sg_page_iter *sg_iter,uint64_t start, +size_t pages,enum i915_cache_level cache_level,const bool flush) {
@@ -704,7 +732,7 @@ static void gen8_ppgtt_insert_pte_entries(struct i915_page_directory_pointer_ent pt_vaddr =NULL ; -while (__sg_page_iter_next (sg_iter)) { +while (pages-- &&__sg_page_iter_next (sg_iter)) {if (pt_vaddr ==NULL ) {struct i915_page_directory_entry *pd = pdp->page_directory[pdpe];struct i915_page_table_entry *pt = pd->page_table[pde];
@@ -742,11 +770,26 @@ static void gen8_ppgtt_insert_entries(struct i915_address_space *vm, u32 unused) { struct i915_hw_ppgtt *ppgtt = container_of(vm, struct i915_hw_ppgtt, base); -struct i915_page_directory_pointer_entry *pdp = &ppgtt->pdp;/* FIXME: 48b */ +struct i915_page_directory_pointer_entry *pdp;struct sg_page_iter sg_iter;__sg_page_iter_start (&sg_iter, pages->sgl,sg_nents (pages->sgl),0 ); -gen8_ppgtt_insert_pte_entries (pdp, &sg_iter, start, cache_level, !HAS_LLC (vm->dev)); + +if (!USES_FULL_48BIT_PPGTT (vm->dev)) { + pdp = &ppgtt->pdp; +gen8_ppgtt_insert_pte_entries (pdp, &sg_iter, start, +sg_nents (pages->sgl), + cache_level, !HAS_LLC (vm->dev)); + }else { +struct i915_pml4 *pml4; +unsigned pml4e =gen8_pml4e_index (start); + + pml4 = &ppgtt->pml4; + pdp = pml4->pdps[pml4e]; +gen8_ppgtt_insert_pte_entries (pdp, &sg_iter, start, +sg_nents (pages->sgl), + cache_level, !HAS_LLC (vm->dev)); + } } static void __gen8_do_map_pt(gen8_ppgtt_pde_t * const pde,
@@ -1185,7 +1228,8 @@ static int __gen8_alloc_vma_range_3lvl(struct i915_address_space *vm,if (sg_iter) {BUG_ON (!sg_iter->__nents);gen8_ppgtt_insert_pte_entries (pdp, sg_iter, pd_start, - flags, !HAS_LLC (vm->dev)); +gen8_pte_count (pd_start, pd_len), + flags, !HAS_LLC (vm->dev)); }set_bit (pde, pd->used_pdes); }
@@ -1330,7 +1374,7 @@ static int gen8_ppgtt_init_common(struct i915_hw_ppgtt *ppgtt, uint64_t size)if (USES_FULL_48BIT_PPGTT (ppgtt->base.dev)) {int ret =pml4_init (ppgtt);if (ret) { -unmap_and_free_pt (ppgtt->scratch_pd, ppgtt->base.dev); +unmap_and_free_pt (ppgtt->scratch_pml4, ppgtt->base.dev);return ret; }
drivers/gpu/drm/i915/i915_gem_gtt.h +12 -0
@@ -332,6 +332,7 @@ struct i915_hw_ppgtt {union {struct i915_page_table_entry *scratch_pt;struct i915_page_table_entry *scratch_pd;/* Just need the daddr */ +struct i915_page_table_entry *scratch_pml4; };struct drm_i915_file_private *file_priv;
@@ -452,6 +453,17 @@ static inline uint64_t gen8_clamp_pd(uint64_t start, uint64_t length)return next_pd - start; } +/* Clamp length to the next page_directory pointer boundary */ +static inline uint64_t gen8_clamp_pdp (uint64_t start,uint64_t length) +{ +uint64_t next_pdp =ALIGN (start +1 ,1ULL <<GEN8_PML4E_SHIFT ); + +if (next_pdp > (start + length)) +return length; + +return next_pdp - start; +} +static inline uint32_t gen8_pte_index (uint64_t address) {return i915_pte_index (address,GEN8_PDE_SHIFT );
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 31/32 drm/i915: Expand error state's address width to 64b
In reply to Michel ThierryFrom: Ben Widawsky <[email protected]>
v2: 0 pad the new 8B fields or else intel_error_decode has a hard time. Note, regardless we need an igt update.
v3: Make reloc_offset 64b also.
--- drivers/gpu/drm/i915/i915_drv.h | 4 ++-- drivers/gpu/drm/i915/i915_gpu_error.c | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +2 -2
@@ -459,7 +459,7 @@ struct drm_i915_error_state {struct drm_i915_error_object {int page_count; -u32 gtt_offset; +u64 gtt_offset;u32 *pages[0 ]; } *ringbuffer, *batchbuffer, *wa_batchbuffer, *ctx, *hws_page;
@@ -485,7 +485,7 @@ struct drm_i915_error_state {u32 size;u32 name;u32 rseqno, wseqno; -u32 gtt_offset; +u64 gtt_offset;u32 read_domains;u32 write_domain; s32 fence_reg:I915_MAX_NUM_FENCE_BITS;
drivers/gpu/drm/i915/i915_gpu_error.c +9 -8
@@ -195,7 +195,7 @@ static void print_error_buffers(struct drm_i915_error_state_buf *m,err_printf (m," %s [%d]:\n" , name, count);while (count--) { - err_printf(m, " %08x %8u %02x %02x %x %x", + err_printf(m, " %016llx %8u %02x %02x %x %x", err->gtt_offset, err->size, err->read_domains,
@@ -415,7 +415,7 @@ int i915_error_state_to_str(struct drm_i915_error_state_buf *m,err_printf (m," (submitted by %s [%d])" , error->ring[i].comm, error->ring[i].pid); -err_printf (m," --- gtt_offset = 0x%08x\n" , +err_printf (m," --- gtt_offset = 0x%016llx\n" , obj->gtt_offset);print_error_obj (m, obj); }
@@ -423,7 +423,8 @@ int i915_error_state_to_str(struct drm_i915_error_state_buf *m, obj = error->ring[i].wa_batchbuffer;if (obj) {err_printf (m,"%s (w/a) --- gtt_offset = 0x%08x\n" , - dev_priv->ring[i].name, obj->gtt_offset); + dev_priv->ring[i].name, +lower_32_bits (obj->gtt_offset));print_error_obj (m, obj); }
@@ -442,14 +443,14 @@ int i915_error_state_to_str(struct drm_i915_error_state_buf *m,if ((obj = error->ring[i].ringbuffer)) {err_printf (m,"%s --- ringbuffer = 0x%08x\n" , dev_priv->ring[i].name, - obj->gtt_offset); +lower_32_bits (obj->gtt_offset));print_error_obj (m, obj); }if ((obj = error->ring[i].hws_page)) {err_printf (m,"%s --- HW Status = 0x%08x\n" , dev_priv->ring[i].name, - obj->gtt_offset); +lower_32_bits (obj->gtt_offset)); offset =0 ;for (elt =0 ; elt <PAGE_SIZE /16 ; elt +=4 ) { err_printf(m, "[%04x] %08x %08x %08x %08x\n",
@@ -465,13 +466,13 @@ int i915_error_state_to_str(struct drm_i915_error_state_buf *m,if ((obj = error->ring[i].ctx)) {err_printf (m,"%s --- HW Context = 0x%08x\n" , dev_priv->ring[i].name, - obj->gtt_offset); +lower_32_bits (obj->gtt_offset));print_error_obj (m, obj); } }if ((obj = error->semaphore_obj)) { -err_printf (m,"Semaphore page = 0x%08x\n" , obj->gtt_offset); +err_printf (m,"Semaphore page = 0x%016llx\n" , obj->gtt_offset);for (elt =0 ; elt <PAGE_SIZE /16 ; elt +=4 ) { err_printf(m, "[%04x] %08x %08x %08x %08x\n", elt * 4,
@@ -571,7 +572,7 @@ i915_error_object_create(struct drm_i915_private *dev_priv,int num_pages;bool use_ggtt;int i =0 ; -u32 reloc_offset; +u64 reloc_offset;if (src ==NULL || src->pages ==NULL )return NULL ;
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx