The final nail in AGP on GEN6+
Subsystems (3)
v2 cover The final nail in AGP on GEN6+
Rebased on a nightly branch which had some decent rebase conflicts resolved for Daniel. Rodrigo's reviewed-by applied, and a few minor fixes here and there.
Needs some testing on pre-GEN6 platforms.
Ben Widawsky (13):
drm/i915: Kill gtt_end
drm/i915: Mappable_end can't ever be > end drm/i915: Remove gtt_mappable_total drm/i915: Create a gtt structure
drm/i915: Remove use on gma_bus_addr on gen6+ drm/i915: Remove use of gtt_mappable_entries drm/i915: Stop using gtt_total_entries drm/i915: Move stolen_size to the new struct agp/intel: decouple more of the agp-i915 sharing drm/i915: Needs_dmar, not
drm/i915: Cut out the infamous ILK w/a from AGP layer drm/i915: Remove scratch page from shared drm/i915: Finally kill off struct intel_gtt
drivers/char/agp/intel-gtt.c | 88 ++++++--------- drivers/gpu/drm/i915/i915_debugfs.c | 3 +- drivers/gpu/drm/i915/i915_dma.c | 29 +++-- drivers/gpu/drm/i915/i915_drv.h | 39 +++++-- drivers/gpu/drm/i915/i915_gem.c | 16 +-- drivers/gpu/drm/i915/i915_gem_evict.c | 2 +- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 2 +- drivers/gpu/drm/i915/i915_gem_gtt.c | 174 ++++++++++++++--------------- drivers/gpu/drm/i915/i915_gem_stolen.c | 8 +- drivers/gpu/drm/i915/i915_gem_tiling.c | 2 +- drivers/gpu/drm/i915/i915_irq.c | 4 +- drivers/gpu/drm/i915/intel_display.c | 2 +- drivers/gpu/drm/i915/intel_fb.c | 5 +- drivers/gpu/drm/i915/intel_overlay.c | 4 +- drivers/gpu/drm/i915/intel_ringbuffer.c | 2 +- include/drm/intel-gtt.h | 19 ---- 16 files changed, 183 insertions(+), 216 deletions(-)
Signature · 1 line
1.8.1.1
PATCH v2 1/13 drm/i915: Kill gtt_end
It's duplicated in the more useful gtt_total.
--- drivers/gpu/drm/i915/i915_drv.h | 1 - drivers/gpu/drm/i915/i915_gem_gtt.c | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +0 -1
@@ -804,7 +804,6 @@ typedef struct drm_i915_private {/** Usable portion of the GTT for GEM */ unsigned long gtt_start;unsigned long gtt_mappable_end; -unsigned long gtt_end;unsigned long stolen_base;/* limited to low memory (32-bit) */ /** "Graphics Stolen Memory" holds the global PTEs */
drivers/gpu/drm/i915/i915_gem_gtt.c +1 -2
@@ -394,7 +394,7 @@ void i915_gem_restore_gtt_mappings(struct drm_device *dev)/* First fill our portion of the GTT with scratch pages */ i915_ggtt_clear_range (dev, dev_priv->mm.gtt_start /PAGE_SIZE , - (dev_priv->mm.gtt_end - dev_priv->mm.gtt_start) /PAGE_SIZE ); + dev_priv->mm.gtt_total /PAGE_SIZE );list_for_each_entry (obj, &dev_priv->mm.bound_list, gtt_list) {i915_gem_clflush_object (obj);
@@ -556,7 +556,6 @@ void i915_gem_setup_global_gtt(struct drm_device *dev, dev_priv->mm.gtt_start = start; dev_priv->mm.gtt_mappable_end = mappable_end; - dev_priv->mm.gtt_end = end; dev_priv->mm.gtt_total = end - start; dev_priv->mm.mappable_gtt_total =min (end, mappable_end) - start;
Signature · 1 line
1.8.1.1
PATCH v2 2/13 drm/i915: Mappable_end can't ever be > end
In reply to Ben WidawskyBoth DRI1 and DRI2 can never specify a mappable size which goes past the GTT size. Don't pretend otherwise.
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +3 -1
@@ -536,6 +536,8 @@ void i915_gem_setup_global_gtt(struct drm_device *dev,struct drm_i915_gem_object *obj;unsigned long hole_start, hole_end; +BUG_ON (mappable_end > end); +/* Subtract the guard page ... */ drm_mm_init (&dev_priv->mm.gtt_space, start, end - start -PAGE_SIZE );if (!HAS_LLC (dev))
@@ -557,7 +559,7 @@ void i915_gem_setup_global_gtt(struct drm_device *dev, dev_priv->mm.gtt_start = start; dev_priv->mm.gtt_mappable_end = mappable_end; dev_priv->mm.gtt_total = end - start; - dev_priv->mm.mappable_gtt_total =min (end, mappable_end) - start; + dev_priv->mm.mappable_gtt_total = mappable_end - start;/* Clear any non-preallocated blocks */ drm_mm_for_each_hole(entry, &dev_priv->mm.gtt_space,
Signature · 1 line
1.8.1.1
PATCH v2 3/13 drm/i915: Remove gtt_mappable_total
In reply to Ben WidawskyWith the assertion from the previous patch in place, it should be safe to get rid gtt_mappable_total. Keeps things saner to not have to track the same info in two places.
In order to keep the diff as simple as possible and keep with the existing gtt_setup semantics we opt to keep gtt_mappable_end. It's not as consistent with the 'total' used in the previous patch, but that can be fixed later.
--- drivers/gpu/drm/i915/i915_debugfs.c | 3 ++- drivers/gpu/drm/i915/i915_drv.h | 1 - drivers/gpu/drm/i915/i915_gem_gtt.c | 1 - 3 files changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +2 -1
@@ -259,7 +259,8 @@ static int i915_gem_object_info(struct seq_file *m, void* data) count, size);seq_printf (m,"%zu [%zu] gtt total\n" , - dev_priv->mm.gtt_total, dev_priv->mm.mappable_gtt_total); + dev_priv->mm.gtt_total, + dev_priv->mm.gtt_mappable_end - dev_priv->mm.gtt_start);mutex_unlock (&dev->struct_mutex);
drivers/gpu/drm/i915/i915_drv.h +0 -1
@@ -889,7 +889,6 @@ typedef struct drm_i915_private {/* accounting, useful for userland debugging */ size_t gtt_total; -size_t mappable_gtt_total;size_t object_memory;u32 object_count; } mm;
drivers/gpu/drm/i915/i915_gem_gtt.c +0 -1
@@ -559,7 +559,6 @@ void i915_gem_setup_global_gtt(struct drm_device *dev, dev_priv->mm.gtt_start = start; dev_priv->mm.gtt_mappable_end = mappable_end; dev_priv->mm.gtt_total = end - start; - dev_priv->mm.mappable_gtt_total = mappable_end - start;/* Clear any non-preallocated blocks */ drm_mm_for_each_hole(entry, &dev_priv->mm.gtt_space,
Signature · 1 line
1.8.1.1
PATCH v2 4/13 drm/i915: Create a gtt structure
In reply to Ben WidawskyThe purpose of the gtt structure is to help isolate our gtt specific properties from the rest of the code (in doing so it help us finish the isolation from the AGP connection).
The following members are pulled out (and renamed):gtt_startgtt_totalgtt_mappable_endgtt_mappablegtt_base_addr
gsm
The gtt structure will serve as a nice place to put gen specific gtt routines in upcoming patches. As far as what else I feel belongs in this
structure: it is meant to encapsulate the GTT's physical properties. This is why I've not added fields which track various drm_mm properties, or things like gtt_mtrr (which is itself a pretty transient field).
--- drivers/gpu/drm/i915/i915_debugfs.c | 4 ++-- drivers/gpu/drm/i915/i915_dma.c | 20 ++++++++++---------- drivers/gpu/drm/i915/i915_drv.h | 29 +++++++++++++++++++++-------- drivers/gpu/drm/i915/i915_gem.c | 14 +++++++------- drivers/gpu/drm/i915/i915_gem_evict.c | 2 +- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 2 +- drivers/gpu/drm/i915/i915_gem_gtt.c | 24 ++++++++++++------------ drivers/gpu/drm/i915/i915_gem_tiling.c | 2 +- drivers/gpu/drm/i915/i915_irq.c | 4 ++-- drivers/gpu/drm/i915/intel_display.c | 2 +- drivers/gpu/drm/i915/intel_fb.c | 2 +- drivers/gpu/drm/i915/intel_overlay.c | 4 ++-- 12 files changed, 61 insertions(+), 48 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +2 -2
@@ -259,8 +259,8 @@ static int i915_gem_object_info(struct seq_file *m, void* data) count, size);seq_printf (m,"%zu [%zu] gtt total\n" , - dev_priv->mm.gtt_total, - dev_priv->mm.gtt_mappable_end - dev_priv->mm.gtt_start); + dev_priv->gtt.total, + dev_priv->gtt.mappable_end - dev_priv->gtt.start);mutex_unlock (&dev->struct_mutex);
drivers/gpu/drm/i915/i915_dma.c +10 -10
@@ -1076,7 +1076,7 @@ static int i915_set_status_page(struct drm_device *dev, void *data, ring->status_page.gfx_addr = hws->addr & (0x1ffff <<12 ); dev_priv->dri1.gfx_hws_cpu_addr = -ioremap_wc (dev_priv->mm.gtt_base_addr + hws->addr,4096 ); +ioremap_wc (dev_priv->gtt.mappable_base + hws->addr,4096 );if (dev_priv->dri1.gfx_hws_cpu_addr ==NULL ) {i915_dma_cleanup (dev); ring->status_page.gfx_addr =0 ;
@@ -1543,17 +1543,17 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags) } aperture_size = dev_priv->mm.gtt->gtt_mappable_entries <<PAGE_SHIFT ; - dev_priv->mm.gtt_base_addr = dev_priv->mm.gtt->gma_bus_addr; + dev_priv->gtt.mappable_base = dev_priv->mm.gtt->gma_bus_addr; - dev_priv->mm.gtt_mapping = -io_mapping_create_wc (dev_priv->mm.gtt_base_addr, + dev_priv->gtt.mappable = +io_mapping_create_wc (dev_priv->gtt.mappable_base, aperture_size); -if (dev_priv->mm.gtt_mapping ==NULL ) { +if (dev_priv->gtt.mappable ==NULL ) { ret = -EIO ; goto out_rmmap; } -i915_mtrr_setup (dev_priv, dev_priv->mm.gtt_base_addr, +i915_mtrr_setup (dev_priv, dev_priv->gtt.mappable_base, aperture_size);/* The i915 workqueue is primarily used for batched retirement of
@@ -1658,11 +1658,11 @@ out_gem_unload: out_mtrrfree:if (dev_priv->mm.gtt_mtrr >=0 ) {mtrr_del (dev_priv->mm.gtt_mtrr, - dev_priv->mm.gtt_base_addr, + dev_priv->gtt.mappable_base, aperture_size); dev_priv->mm.gtt_mtrr =-1 ; } -io_mapping_free (dev_priv->mm.gtt_mapping); +io_mapping_free (dev_priv->gtt.mappable); out_rmmap:pci_iounmap (dev->pdev, dev_priv->regs); put_gmch:
@@ -1696,10 +1696,10 @@ int i915_driver_unload(struct drm_device *dev)/* Cancel the retire work handler, which should be idle now. */ cancel_delayed_work_sync (&dev_priv->mm.retire_work); -io_mapping_free (dev_priv->mm.gtt_mapping); +io_mapping_free (dev_priv->gtt.mappable);if (dev_priv->mm.gtt_mtrr >=0 ) {mtrr_del (dev_priv->mm.gtt_mtrr, - dev_priv->mm.gtt_base_addr, + dev_priv->gtt.mappable_base, dev_priv->mm.gtt->gtt_mappable_entries *PAGE_SIZE ); dev_priv->mm.gtt_mtrr =-1 ; }
drivers/gpu/drm/i915/i915_drv.h +21 -8
@@ -367,6 +367,25 @@ struct intel_device_info { u8 has_llc:1; }; +/* The Graphics Translation Table is the way in which GEN hardware translates a +* Graphics Virtual Address into a Physical Address. In addition to the normal +* collateral associated with any va->pa translations GEN hardware also has a +* portion of the GTT which can be mapped by the CPU and remain both coherent +* and correct (in cases like swizzling). That region is referred to as GMADR in +* the spec. +*/ +struct i915_gtt { +unsigned long start;/* Start offset of used GTT */ +size_t total;/* Total size GTT can map */ + +unsigned long mappable_end;/* End offset that we can CPU map */ +struct io_mapping *mappable;/* Mapping to our CPU mappable region */ +phys_addr_t mappable_base;/* PA of our GMADR */ + +/** "Graphics Stolen Memory" holds the global PTEs */ +void __iomem *gsm; +}; +#define I915_PPGTT_PD_ENTRIES 512#define I915_PPGTT_PT_ENTRIES 1024struct i915_hw_ppgtt {
@@ -784,6 +803,8 @@ typedef struct drm_i915_private {/* Register state */ bool modeset_on_lid; +struct i915_gtt gtt; +struct {/** Bridge to intel-gtt-ko */ struct intel_gtt *gtt;
@@ -802,15 +823,8 @@ typedef struct drm_i915_private {struct list_head unbound_list;/** Usable portion of the GTT for GEM */ -unsigned long gtt_start; -unsigned long gtt_mappable_end;unsigned long stolen_base;/* limited to low memory (32-bit) */ -/** "Graphics Stolen Memory" holds the global PTEs */ -void __iomem *gsm; - -struct io_mapping *gtt_mapping; -phys_addr_t gtt_base_addr;int gtt_mtrr;/** PPGTT used for aliasing the PPGTT with the GTT */
@@ -888,7 +902,6 @@ typedef struct drm_i915_private {struct drm_i915_gem_phys_object *phys_objs[I915_MAX_PHYS_OBJECT ];/* accounting, useful for userland debugging */ -size_t gtt_total;size_t object_memory;u32 object_count; } mm;
drivers/gpu/drm/i915/i915_gem.c +7 -7
@@ -186,7 +186,7 @@ i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data, pinned += obj->gtt_space->size;mutex_unlock (&dev->struct_mutex); - args->aper_size = dev_priv->mm.gtt_total; + args->aper_size = dev_priv->gtt.total; args->aper_available_size = args->aper_size - pinned;return 0 ;
@@ -637,7 +637,7 @@ i915_gem_gtt_pwrite_fast(struct drm_device *dev,* source page isn't available. Return the error and we'll * retry in the slow path. */ -if (fast_user_write (dev_priv->mm.gtt_mapping, page_base, +if (fast_user_write (dev_priv->gtt.mappable, page_base, page_offset, user_data, page_length)) { ret = -EFAULT ; goto out_unpin;
@@ -1362,7 +1362,7 @@ int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) obj->fault_mappable = true; - pfn = ((dev_priv->mm.gtt_base_addr + obj->gtt_offset) >>PAGE_SHIFT ) + + pfn = ((dev_priv->gtt.mappable_base + obj->gtt_offset) >>PAGE_SHIFT ) + page_offset;/* Finally, remap it using the new GTT offset */
@@ -1544,7 +1544,7 @@ i915_gem_mmap_gtt(struct drm_file *file, goto unlock; } -if (obj->base.size > dev_priv->mm.gtt_mappable_end) { +if (obj->base.size > dev_priv->gtt.mappable_end) { ret = -E2BIG ; goto out; }
@@ -2917,7 +2917,7 @@ i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj,* before evicting everything in a vain attempt to find space. */ if (obj->base.size > - (map_and_fenceable ? dev_priv->mm.gtt_mappable_end : dev_priv->mm.gtt_total)) { + (map_and_fenceable ? dev_priv->gtt.mappable_end : dev_priv->gtt.total)) {DRM_ERROR ("Attempting to bind an object larger than the aperture\n" );return -E2BIG ; }
@@ -2938,7 +2938,7 @@ i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj,if (map_and_fenceable) ret =drm_mm_insert_node_in_range_generic (&dev_priv->mm.gtt_space, node, size, alignment, obj->cache_level, -0 , dev_priv->mm.gtt_mappable_end); +0 , dev_priv->gtt.mappable_end);else ret =drm_mm_insert_node_generic (&dev_priv->mm.gtt_space, node, size, alignment, obj->cache_level);
@@ -2978,7 +2978,7 @@ i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj, (node->start & (fence_alignment -1 )) ==0 ; mappable = - obj->gtt_offset + obj->base.size <= dev_priv->mm.gtt_mappable_end; + obj->gtt_offset + obj->base.size <= dev_priv->gtt.mappable_end; obj->map_and_fenceable = mappable && fenceable;
drivers/gpu/drm/i915/i915_gem_evict.c +1 -1
@@ -80,7 +80,7 @@ i915_gem_evict_something(struct drm_device *dev, int min_size,if (mappable)drm_mm_init_scan_with_range (&dev_priv->mm.gtt_space, min_size, alignment, cache_level, -0 , dev_priv->mm.gtt_mappable_end); +0 , dev_priv->gtt.mappable_end);else drm_mm_init_scan (&dev_priv->mm.gtt_space, min_size, alignment, cache_level);
drivers/gpu/drm/i915/i915_gem_execbuffer.c +1 -1
@@ -281,7 +281,7 @@ i915_gem_execbuffer_relocate_entry(struct drm_i915_gem_object *obj,/* Map the page containing the relocation we're going to perform. */ reloc->offset += obj->gtt_offset; - reloc_page =io_mapping_map_atomic_wc (dev_priv->mm.gtt_mapping, + reloc_page =io_mapping_map_atomic_wc (dev_priv->gtt.mappable, reloc->offset &PAGE_MASK ); reloc_entry = (uint32_t __iomem *) (reloc_page + (reloc->offset & ~PAGE_MASK ));
drivers/gpu/drm/i915/i915_gem_gtt.c +12 -12
@@ -290,7 +290,7 @@ void i915_gem_init_ppgtt(struct drm_device *dev)return ; - pd_addr = (gtt_pte_t __iomem *)dev_priv->mm.gsm + ppgtt->pd_offset/sizeof (gtt_pte_t); + pd_addr = (gtt_pte_t __iomem *)dev_priv->gtt.gsm + ppgtt->pd_offset/sizeof (gtt_pte_t);for (i =0 ; i < ppgtt->num_pd_entries; i++) {dma_addr_t pt_addr;
@@ -367,7 +367,7 @@ static void i915_ggtt_clear_range(struct drm_device *dev, {struct drm_i915_private *dev_priv = dev->dev_private;gtt_pte_t scratch_pte; -gtt_pte_t __iomem *gtt_base = (gtt_pte_t __iomem *) dev_priv->mm.gsm + first_entry; +gtt_pte_t __iomem *gtt_base = (gtt_pte_t __iomem *) dev_priv->gtt.gsm + first_entry;const int max_entries = dev_priv->mm.gtt->gtt_total_entries - first_entry;int i;
@@ -393,8 +393,8 @@ void i915_gem_restore_gtt_mappings(struct drm_device *dev)struct drm_i915_gem_object *obj;/* First fill our portion of the GTT with scratch pages */ -i915_ggtt_clear_range (dev, dev_priv->mm.gtt_start /PAGE_SIZE , - dev_priv->mm.gtt_total /PAGE_SIZE ); +i915_ggtt_clear_range (dev, dev_priv->gtt.start /PAGE_SIZE , + dev_priv->gtt.total /PAGE_SIZE );list_for_each_entry (obj, &dev_priv->mm.bound_list, gtt_list) {i915_gem_clflush_object (obj);
@@ -433,7 +433,7 @@ static void gen6_ggtt_bind_object(struct drm_i915_gem_object *obj,const int first_entry = obj->gtt_space->start >>PAGE_SHIFT ;const int max_entries = dev_priv->mm.gtt->gtt_total_entries - first_entry;gtt_pte_t __iomem *gtt_entries = - (gtt_pte_t __iomem *)dev_priv->mm.gsm + first_entry; + (gtt_pte_t __iomem *)dev_priv->gtt.gsm + first_entry;int unused, i =0 ;unsigned int len, m =0 ;dma_addr_t addr;
@@ -556,9 +556,9 @@ void i915_gem_setup_global_gtt(struct drm_device *dev, obj->has_global_gtt_mapping =1 ; } - dev_priv->mm.gtt_start = start; - dev_priv->mm.gtt_mappable_end = mappable_end; - dev_priv->mm.gtt_total = end - start; + dev_priv->gtt.start = start; + dev_priv->gtt.mappable_end = mappable_end; + dev_priv->gtt.total = end - start;/* Clear any non-preallocated blocks */ drm_mm_for_each_hole(entry, &dev_priv->mm.gtt_space,
@@ -752,9 +752,9 @@ int i915_gem_gtt_init(struct drm_device *dev) goto err_out; } - dev_priv->mm.gsm =ioremap_wc (gtt_bus_addr, - dev_priv->mm.gtt->gtt_total_entries *sizeof (gtt_pte_t)); -if (!dev_priv->mm.gsm) { + dev_priv->gtt.gsm =ioremap_wc (gtt_bus_addr, + dev_priv->mm.gtt->gtt_total_entries *sizeof (gtt_pte_t)); +if (!dev_priv->gtt.gsm) {DRM_ERROR ("Failed to map the gtt page table\n" );teardown_scratch_page (dev); ret = -ENOMEM ;
@@ -778,7 +778,7 @@ err_out:void i915_gem_gtt_fini (struct drm_device *dev) {struct drm_i915_private *dev_priv = dev->dev_private; -iounmap (dev_priv->mm.gsm); +iounmap (dev_priv->gtt.gsm);teardown_scratch_page (dev);if (INTEL_INFO (dev)->gen <6 )intel_gmch_remove ();
drivers/gpu/drm/i915/i915_gem_tiling.c +1 -1
@@ -357,7 +357,7 @@ i915_gem_set_tiling(struct drm_device *dev, void *data, obj->map_and_fenceable = obj->gtt_space ==NULL || - (obj->gtt_offset + obj->base.size <= dev_priv->mm.gtt_mappable_end && + (obj->gtt_offset + obj->base.size <= dev_priv->gtt.mappable_end &&i915_gem_object_fence_ok (obj, args->tiling_mode));/* Rebind if we need a change of alignment */
drivers/gpu/drm/i915/i915_irq.c +2 -2
@@ -939,7 +939,7 @@ i915_error_object_create(struct drm_i915_private *dev_priv, goto unwind;local_irq_save (flags); -if (reloc_offset < dev_priv->mm.gtt_mappable_end && +if (reloc_offset < dev_priv->gtt.mappable_end && src->has_global_gtt_mapping) {void __iomem *s;
@@ -948,7 +948,7 @@ i915_error_object_create(struct drm_i915_private *dev_priv,* captures what the GPU read. */ - s =io_mapping_map_atomic_wc (dev_priv->mm.gtt_mapping, + s =io_mapping_map_atomic_wc (dev_priv->gtt.mappable, reloc_offset);memcpy_fromio (d, s,PAGE_SIZE );io_mapping_unmap_atomic (s);
drivers/gpu/drm/i915/intel_display.c +1 -1
@@ -8705,7 +8705,7 @@ void intel_modeset_init(struct drm_device *dev) dev->mode_config.max_width =8192 ; dev->mode_config.max_height =8192 ; } - dev->mode_config.fb_base = dev_priv->mm.gtt_base_addr; + dev->mode_config.fb_base = dev_priv->gtt.mappable_base;DRM_DEBUG_KMS ("%d display pipe%s available.\n" , dev_priv->num_pipe, dev_priv->num_pipe >1 ?"s" :"" );
drivers/gpu/drm/i915/intel_fb.c +1 -1
@@ -142,7 +142,7 @@ static int intelfb_create(struct intel_fbdev *ifbdev, info->fix.smem_len = size; info->screen_base = -ioremap_wc (dev_priv->mm.gtt_base_addr + obj->gtt_offset, +ioremap_wc (dev_priv->gtt.mappable_base + obj->gtt_offset, size);if (!info->screen_base) { ret = -ENOSPC ;
drivers/gpu/drm/i915/intel_overlay.c +2 -2
@@ -195,7 +195,7 @@ intel_overlay_map_regs(struct intel_overlay *overlay)if (OVERLAY_NEEDS_PHYSICAL (overlay->dev)) regs = (struct overlay_registers __iomem *)overlay->reg_bo->phys_obj->handle->vaddr;else - regs =io_mapping_map_wc (dev_priv->mm.gtt_mapping, + regs =io_mapping_map_wc (dev_priv->gtt.mappable, overlay->reg_bo->gtt_offset);return regs;
@@ -1434,7 +1434,7 @@ intel_overlay_map_regs_atomic(struct intel_overlay *overlay) regs = (struct overlay_registers __iomem *) overlay->reg_bo->phys_obj->handle->vaddr; else - regs =io_mapping_map_atomic_wc (dev_priv->mm.gtt_mapping, + regs =io_mapping_map_atomic_wc (dev_priv->gtt.mappable, overlay->reg_bo->gtt_offset);return regs;
Signature · 1 line
1.8.1.1
PATCH v2 5/13 drm/i915: Remove use on gma_bus_addr on gen6+
In reply to Ben WidawskyWe have enough info to not use the intel_gtt bridge stuff.
v2: Move setup of mappable_base above the legacy init stuff because we still need that on older platforms. (Daniel)
v3: Remove the dev_priv hunk which was rebased in by accident
--- drivers/gpu/drm/i915/i915_dma.c | 3 +-- drivers/gpu/drm/i915/i915_gem_gtt.c | 3 ++- drivers/gpu/drm/i915/intel_ringbuffer.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +1 -2
@@ -1426,7 +1426,7 @@ static void i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv)if (!ap)return ; - ap->ranges[0 ].base = dev_priv->mm.gtt->gma_bus_addr; + ap->ranges[0 ].base = dev_priv->gtt.mappable_base; ap->ranges[0 ].size = dev_priv->mm.gtt->gtt_mappable_entries <<PAGE_SHIFT ; primary =
@@ -1543,7 +1543,6 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags) } aperture_size = dev_priv->mm.gtt->gtt_mappable_entries <<PAGE_SHIFT ; - dev_priv->gtt.mappable_base = dev_priv->mm.gtt->gma_bus_addr; dev_priv->gtt.mappable = io_mapping_create_wc(dev_priv->gtt.mappable_base,
drivers/gpu/drm/i915/i915_gem_gtt.c +2 -1
@@ -691,6 +691,8 @@ int i915_gem_gtt_init(struct drm_device *dev)u16 snb_gmch_ctl;int ret; + dev_priv->gtt.mappable_base =pci_resource_start (dev->pdev,2 ); +/* On modern platforms we need not worry ourself with the legacy * hostbridge query stuff. Skip it entirely */
@@ -723,7 +725,6 @@ int i915_gem_gtt_init(struct drm_device *dev)/* For GEN6+ the PTEs for the ggtt live at 2MB + BAR0 */ gtt_bus_addr =pci_resource_start (dev->pdev,0 ) + (2 <<20 ); - dev_priv->mm.gtt->gma_bus_addr =pci_resource_start (dev->pdev,2 );/* i9xx_setup */ pci_read_config_word (dev->pdev,SNB_GMCH_CTRL , &snb_gmch_ctl);
drivers/gpu/drm/i915/intel_ringbuffer.c +1 -1
@@ -1203,7 +1203,7 @@ static int intel_init_ring_buffer(struct drm_device *dev, goto err_unpin; ring->virtual_start = -ioremap_wc (dev_priv->mm.gtt->gma_bus_addr + obj->gtt_offset, +ioremap_wc (dev_priv->gtt.mappable_base + obj->gtt_offset, ring->size);if (ring->virtual_start ==NULL ) {DRM_ERROR ("Failed to map ringbuffer.\n" );
Signature · 1 line
1.8.1.1
PATCH v2 6/13 drm/i915: Remove use of gtt_mappable_entries
In reply to Ben WidawskyMappable_end, ie. size is almost always what you want as opposed to the number of entries. Since we already have that information, we can scrap the number of entries and only calculate it when needed.
If gtt_start is !0, this will have slightly different behavior. This difference can only occur in DRI1, and exists when we try to kick out the firmware fb. The new code seems like a bugfix to me.
The other case where we've changed the behavior is during init we check the mappable region against our current known upper and lower limits (64MB, and 512MB). This now matches the comment, and makes things more convenient after removing gtt_mappable_entries.
Also worth noting is the setting of mappable_end is taken out of setup because we do it earlier now in the DRI2 case and therefore need to add that tiny hunk to support the DRI1 IOCTL.
v2: Move up mappable end to before legacy AGP init
v3: Add the dev_priv inclusion here from previous rebase error in patch 5
--- drivers/gpu/drm/i915/i915_dma.c | 8 ++++---- drivers/gpu/drm/i915/i915_gem.c | 2 ++ drivers/gpu/drm/i915/i915_gem_gtt.c | 15 +++++++-------- drivers/gpu/drm/i915/intel_fb.c | 3 +-- 4 files changed, 14 insertions(+), 14 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +4 -4
@@ -1427,8 +1427,8 @@ static void i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv)return ; ap->ranges[0 ].base = dev_priv->gtt.mappable_base; - ap->ranges[0 ].size = - dev_priv->mm.gtt->gtt_mappable_entries <<PAGE_SHIFT ; + ap->ranges[0 ].size = dev_priv->gtt.mappable_end - dev_priv->gtt.start; + primary = pdev->resource[PCI_ROM_RESOURCE ].flags &IORESOURCE_ROM_SHADOW ;
@@ -1542,7 +1542,7 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags) goto put_gmch; } - aperture_size = dev_priv->mm.gtt->gtt_mappable_entries <<PAGE_SHIFT ; + aperture_size = dev_priv->gtt.mappable_end; dev_priv->gtt.mappable = io_mapping_create_wc(dev_priv->gtt.mappable_base,
@@ -1699,7 +1699,7 @@ int i915_driver_unload(struct drm_device *dev)if (dev_priv->mm.gtt_mtrr >=0 ) {mtrr_del (dev_priv->mm.gtt_mtrr, dev_priv->gtt.mappable_base, - dev_priv->mm.gtt->gtt_mappable_entries *PAGE_SIZE ); + dev_priv->gtt.mappable_end); dev_priv->mm.gtt_mtrr =-1 ; }
drivers/gpu/drm/i915/i915_gem.c +2 -0
@@ -149,6 +149,7 @@ int i915_gem_init_ioctl(struct drm_device *dev, void *data, struct drm_file *file) { + struct drm_i915_private *dev_priv = dev->dev_private;struct drm_i915_gem_init *args = data;if (drm_core_check_feature (dev,DRIVER_MODESET ))
@@ -165,6 +166,7 @@ i915_gem_init_ioctl(struct drm_device *dev, void *data,mutex_lock (&dev->struct_mutex);i915_gem_setup_global_gtt (dev, args->gtt_start, args->gtt_end, args->gtt_end); + dev_priv->gtt.mappable_end = args->gtt_end;mutex_unlock (&dev->struct_mutex);return 0 ;
drivers/gpu/drm/i915/i915_gem_gtt.c +7 -8
@@ -557,7 +557,6 @@ void i915_gem_setup_global_gtt(struct drm_device *dev, } dev_priv->gtt.start = start; - dev_priv->gtt.mappable_end = mappable_end; dev_priv->gtt.total = end - start;/* Clear any non-preallocated blocks */
@@ -596,7 +595,7 @@ void i915_gem_init_global_gtt(struct drm_device *dev)int ret; gtt_size = dev_priv->mm.gtt->gtt_total_entries <<PAGE_SHIFT ; - mappable_size = dev_priv->mm.gtt->gtt_mappable_entries <<PAGE_SHIFT ; + mappable_size = dev_priv->gtt.mappable_end;if (intel_enable_ppgtt (dev) &&HAS_ALIASING_PPGTT (dev)) {/* PPGTT pdes are stolen from global gtt ptes, so shrink the
@@ -692,6 +691,7 @@ int i915_gem_gtt_init(struct drm_device *dev)int ret; dev_priv->gtt.mappable_base =pci_resource_start (dev->pdev,2 ); + dev_priv->gtt.mappable_end =pci_resource_len (dev->pdev,2 );/* On modern platforms we need not worry ourself with the legacy * hostbridge query stuff. Skip it entirely
@@ -735,14 +735,13 @@ int i915_gem_gtt_init(struct drm_device *dev)else dev_priv->mm.gtt->stolen_size =gen7_get_stolen_size (snb_gmch_ctl); - dev_priv->mm.gtt->gtt_mappable_entries =pci_resource_len (dev->pdev,2 ) >>PAGE_SHIFT ;/* 64/512MB is the current min/max we actually know of, but this is just a * coarse sanity check. */ -if ((dev_priv->mm.gtt->gtt_mappable_entries >>8 ) <64 || - dev_priv->mm.gtt->gtt_mappable_entries > dev_priv->mm.gtt->gtt_total_entries) { -DRM_ERROR ("Unknown GMADR entries (%d)\n" , - dev_priv->mm.gtt->gtt_mappable_entries); +if ((dev_priv->gtt.mappable_end < (64 <<20 ) || + (dev_priv->gtt.mappable_end > (512 <<20 )))) { +DRM_ERROR ("Unknown GMADR size (%lx)\n" , + dev_priv->gtt.mappable_end); ret = -ENXIO ; goto err_out; }
@@ -764,7 +763,7 @@ int i915_gem_gtt_init(struct drm_device *dev)/* GMADR is the PCI aperture used by SW to access tiled GFX surfaces in a linear fashion. */ DRM_INFO ("Memory usable by graphics device = %dM\n" , dev_priv->mm.gtt->gtt_total_entries >>8 ); -DRM_DEBUG_DRIVER ("GMADR size = %dM\n" , dev_priv->mm.gtt->gtt_mappable_entries >>8 ); +DRM_DEBUG_DRIVER ("GMADR size = %ldM\n" , dev_priv->gtt.mappable_end >>20 );DRM_DEBUG_DRIVER ("GTT stolen size = %dM\n" , dev_priv->mm.gtt->stolen_size >>20 );return 0 ;
drivers/gpu/drm/i915/intel_fb.c +1 -2
@@ -135,8 +135,7 @@ static int intelfb_create(struct intel_fbdev *ifbdev, goto out_unpin; } info->apertures->ranges[0 ].base = dev->mode_config.fb_base; - info->apertures->ranges[0 ].size = - dev_priv->mm.gtt->gtt_mappable_entries <<PAGE_SHIFT ; + info->apertures->ranges[0 ].size = dev_priv->gtt.mappable_end; info->fix.smem_start = dev->mode_config.fb_base + obj->gtt_offset; info->fix.smem_len = size;
Signature · 1 line
1.8.1.1
Re: [PATCH 06/13] drm/i915: Remove use of gtt_mappable_entries
Quoted 17 lines · Ben Widawsky
Mappable_end, ie. size is almost always what you want as opposed to the number of entries. Since we already have that information, we can scrap the number of entries and only calculate it when needed.If
gtt_startis !0, this will have slightly different behavior. This difference can only occur in DRI1, and exists when we try to kick out the firmware fb. The new code seems like a bugfix to me.The other case where we've changed the behavior is during init we check the mappable region against our current known upper and lower limits (64MB, and 512MB). This now matches the comment, and makes things more convenient after removing
gtt_mappable_entries.Also worth noting is the setting of
mappable_endis taken out of setup because we do it earlier now in the DRI2 case and therefore need to add that tiny hunk to support the DRI1 IOCTL.
Quoted 7 lines
v2: Move up mappable end to before legacy AGP init
v3: Add the
dev_privinclusion here from previous rebase error in patch 5Reviewed-by Rodrigo Vivi <[email protected]> (v2)Signed-off-by Ben Widawsky <[email protected]>
Merged up to here to dinq, thanks for the patches. I haven't completed testing on older platforms yet, so still a chance I'll have to drop a few ... Hence I'll wait a bit with rebasing the internal trees until this settles.
-Daniel
Quoted 138 lines
--- drivers/gpu/drm/i915/i915_dma.c | 8 ++++---- drivers/gpu/drm/i915/i915_gem.c | 2 ++ drivers/gpu/drm/i915/i915_gem_gtt.c | 15 +++++++-------- drivers/gpu/drm/i915/intel_fb.c | 3 +-- 4 files changed, 14 insertions(+), 14 deletions(-)drivers/gpu/drm/i915/i915_dma.c +4
-4@@ -1427,8 +1427,8 @@ static void i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv)return ; ap->ranges[0 ].base = dev_priv->gtt.mappable_base; - ap->ranges[0 ].size = - dev_priv->mm.gtt->gtt_mappable_entries <<PAGE_SHIFT ; + ap->ranges[0 ].size = dev_priv->gtt.mappable_end - dev_priv->gtt.start; + primary = pdev->resource[PCI_ROM_RESOURCE ].flags &IORESOURCE_ROM_SHADOW ;@@ -1542,7 +1542,7 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags) goto put_gmch; } - aperture_size = dev_priv->mm.gtt->gtt_mappable_entries <<PAGE_SHIFT ; + aperture_size = dev_priv->gtt.mappable_end; dev_priv->gtt.mappable = io_mapping_create_wc(dev_priv->gtt.mappable_base,@@ -1699,7 +1699,7 @@ int i915_driver_unload(struct drm_device *dev)if (dev_priv->mm.gtt_mtrr >=0 ) {mtrr_del (dev_priv->mm.gtt_mtrr, dev_priv->gtt.mappable_base, - dev_priv->mm.gtt->gtt_mappable_entries *PAGE_SIZE ); + dev_priv->gtt.mappable_end); dev_priv->mm.gtt_mtrr =-1 ; }drivers/gpu/drm/i915/i915_gem.c +2
-0@@ -149,6 +149,7 @@ int i915_gem_init_ioctl(struct drm_device *dev, void *data, struct drm_file *file) { + struct drm_i915_private *dev_priv = dev->dev_private;struct drm_i915_gem_init *args = data;if (drm_core_check_feature (dev,DRIVER_MODESET ))@@ -165,6 +166,7 @@ i915_gem_init_ioctl(struct drm_device *dev, void *data,mutex_lock (&dev->struct_mutex);i915_gem_setup_global_gtt (dev, args->gtt_start, args->gtt_end, args->gtt_end); + dev_priv->gtt.mappable_end = args->gtt_end;mutex_unlock (&dev->struct_mutex);return 0 ;drivers/gpu/drm/i915/i915_gem_gtt.c +7
-8@@ -557,7 +557,6 @@ void i915_gem_setup_global_gtt(struct drm_device *dev, } dev_priv->gtt.start = start; - dev_priv->gtt.mappable_end = mappable_end; dev_priv->gtt.total = end - start;/* Clear any non-preallocated blocks */ @@ -596,7 +595,7 @@ void i915_gem_init_global_gtt(struct drm_device *dev)int ret; gtt_size = dev_priv->mm.gtt->gtt_total_entries <<PAGE_SHIFT ; - mappable_size = dev_priv->mm.gtt->gtt_mappable_entries <<PAGE_SHIFT ; + mappable_size = dev_priv->gtt.mappable_end;if (intel_enable_ppgtt (dev) &&HAS_ALIASING_PPGTT (dev)) {/* PPGTT pdes are stolen from global gtt ptes, so shrink the @@ -692,6 +691,7 @@ int i915_gem_gtt_init(struct drm_device *dev)int ret; dev_priv->gtt.mappable_base =pci_resource_start (dev->pdev,2 ); + dev_priv->gtt.mappable_end =pci_resource_len (dev->pdev,2 );/* On modern platforms we need not worry ourself with the legacy * hostbridge query stuff. Skip it entirely @@ -735,14 +735,13 @@ int i915_gem_gtt_init(struct drm_device *dev)else dev_priv->mm.gtt->stolen_size =gen7_get_stolen_size (snb_gmch_ctl); - dev_priv->mm.gtt->gtt_mappable_entries =pci_resource_len (dev->pdev,2 ) >>PAGE_SHIFT ;/* 64/512MB is the current min/max we actually know of, but this is just a * coarse sanity check. */ -if ((dev_priv->mm.gtt->gtt_mappable_entries >>8 ) <64 || - dev_priv->mm.gtt->gtt_mappable_entries > dev_priv->mm.gtt->gtt_total_entries) { -DRM_ERROR ("Unknown GMADR entries (%d)\n" , - dev_priv->mm.gtt->gtt_mappable_entries); +if ((dev_priv->gtt.mappable_end < (64 <<20 ) || + (dev_priv->gtt.mappable_end > (512 <<20 )))) { +DRM_ERROR ("Unknown GMADR size (%lx)\n" , + dev_priv->gtt.mappable_end); ret = -ENXIO ; goto err_out; }@@ -764,7 +763,7 @@ int i915_gem_gtt_init(struct drm_device *dev)/* GMADR is the PCI aperture used by SW to access tiled GFX surfaces in a linear fashion. */ DRM_INFO ("Memory usable by graphics device = %dM\n" , dev_priv->mm.gtt->gtt_total_entries >>8 ); -DRM_DEBUG_DRIVER ("GMADR size = %dM\n" , dev_priv->mm.gtt->gtt_mappable_entries >>8 ); +DRM_DEBUG_DRIVER ("GMADR size = %ldM\n" , dev_priv->gtt.mappable_end >>20 );DRM_DEBUG_DRIVER ("GTT stolen size = %dM\n" , dev_priv->mm.gtt->stolen_size >>20 );return 0 ;drivers/gpu/drm/i915/intel_fb.c +1
-2@@ -135,8 +135,7 @@ static int intelfb_create(struct intel_fbdev *ifbdev, goto out_unpin; } info->apertures->ranges[0 ].base = dev->mode_config.fb_base; - info->apertures->ranges[0 ].size = - dev_priv->mm.gtt->gtt_mappable_entries <<PAGE_SHIFT ; + info->apertures->ranges[0 ].size = dev_priv->gtt.mappable_end; info->fix.smem_start = dev->mode_config.fb_base + obj->gtt_offset; info->fix.smem_len = size;Signature · 6 lines
1.8.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
PATCH v2 7/13 drm/i915: Stop using gtt_total_entries
In reply to Ben WidawskySimilar to gtt_mappable_entries we don't usually want the entries, it's easy enough to calculate it when you need.
v2: Move relevant fields above pre-gen6 init
--- drivers/gpu/drm/i915/i915_drv.h | 3 +++ drivers/gpu/drm/i915/i915_gem_gtt.c | 33 ++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +3 -0
@@ -377,6 +377,7 @@ struct intel_device_info {struct i915_gtt {unsigned long start;/* Start offset of used GTT */ size_t total;/* Total size GTT can map */ +size_t used;/* Amount used <= total */ unsigned long mappable_end;/* End offset that we can CPU map */ struct io_mapping *mappable;/* Mapping to our CPU mappable region */
@@ -384,7 +385,9 @@ struct i915_gtt {/** "Graphics Stolen Memory" holds the global PTEs */ void __iomem *gsm; + }; +#define gtt_total_entries (gtt) ((gtt).total >> PAGE_SHIFT)#define I915_PPGTT_PD_ENTRIES 512#define I915_PPGTT_PT_ENTRIES 1024
drivers/gpu/drm/i915/i915_gem_gtt.c +18 -15
@@ -119,7 +119,8 @@ int i915_gem_init_aliasing_ppgtt(struct drm_device *dev)/* ppgtt PDEs reside in the global gtt pagetable, which has 512*1024 * entries. For aliasing ppgtt support we just steal them at the end for * now. */ - first_pd_entry_in_global_pt = dev_priv->mm.gtt->gtt_total_entries -I915_PPGTT_PD_ENTRIES ; + first_pd_entry_in_global_pt = +gtt_total_entries (dev_priv->gtt) -I915_PPGTT_PD_ENTRIES ; ppgtt =kzalloc (sizeof (*ppgtt),GFP_KERNEL );if (!ppgtt)
@@ -368,7 +369,7 @@ static void i915_ggtt_clear_range(struct drm_device *dev,struct drm_i915_private *dev_priv = dev->dev_private;gtt_pte_t scratch_pte;gtt_pte_t __iomem *gtt_base = (gtt_pte_t __iomem *) dev_priv->gtt.gsm + first_entry; -const int max_entries = dev_priv->mm.gtt->gtt_total_entries - first_entry; +const int max_entries =gtt_total_entries (dev_priv->gtt) - first_entry;int i;if (INTEL_INFO (dev)->gen <6 ) {
@@ -431,7 +432,7 @@ static void gen6_ggtt_bind_object(struct drm_i915_gem_object *obj,struct sg_table *st = obj->pages;struct scatterlist *sg = st->sgl;const int first_entry = obj->gtt_space->start >>PAGE_SHIFT ; -const int max_entries = dev_priv->mm.gtt->gtt_total_entries - first_entry; +const int max_entries =gtt_total_entries (dev_priv->gtt) - first_entry;gtt_pte_t __iomem *gtt_entries = (gtt_pte_t __iomem *)dev_priv->gtt.gsm + first_entry;int unused, i =0 ;
@@ -557,7 +558,9 @@ void i915_gem_setup_global_gtt(struct drm_device *dev, } dev_priv->gtt.start = start; - dev_priv->gtt.total = end - start; + dev_priv->gtt.used = end - start; +if (dev_priv->gtt.used < dev_priv->gtt.total) +DRM_DEBUG_DRIVER ("Warning: using less than total memory\n" );/* Clear any non-preallocated blocks */ drm_mm_for_each_hole(entry, &dev_priv->mm.gtt_space,
@@ -594,7 +597,7 @@ void i915_gem_init_global_gtt(struct drm_device *dev)unsigned long gtt_size, mappable_size;int ret; - gtt_size = dev_priv->mm.gtt->gtt_total_entries <<PAGE_SHIFT ; + gtt_size = dev_priv->gtt.total; mappable_size = dev_priv->gtt.mappable_end;if (intel_enable_ppgtt (dev) &&HAS_ALIASING_PPGTT (dev)) {
@@ -687,11 +690,18 @@ int i915_gem_gtt_init(struct drm_device *dev) {struct drm_i915_private *dev_priv = dev->dev_private;phys_addr_t gtt_bus_addr; +u32 gtt_size;u16 snb_gmch_ctl;int ret; +if (!pci_set_dma_mask (dev->pdev,DMA_BIT_MASK (40 ))) +pci_set_consistent_dma_mask (dev->pdev,DMA_BIT_MASK (40 )); + +pci_read_config_word (dev->pdev,SNB_GMCH_CTRL , &snb_gmch_ctl); dev_priv->gtt.mappable_base =pci_resource_start (dev->pdev,2 ); dev_priv->gtt.mappable_end =pci_resource_len (dev->pdev,2 ); + gtt_size =gen6_get_total_gtt_size (snb_gmch_ctl); + dev_priv->gtt.total = (gtt_size /sizeof (gtt_pte_t)) <<PAGE_SHIFT ;/* On modern platforms we need not worry ourself with the legacy * hostbridge query stuff. Skip it entirely
@@ -716,9 +726,6 @@ int i915_gem_gtt_init(struct drm_device *dev)if (!dev_priv->mm.gtt)return -ENOMEM ; -if (!pci_set_dma_mask (dev->pdev,DMA_BIT_MASK (40 ))) -pci_set_consistent_dma_mask (dev->pdev,DMA_BIT_MASK (40 )); -#ifdef CONFIG_INTEL_IOMMU dev_priv->mm.gtt->needs_dmar =1 ;#endif
@@ -726,10 +733,6 @@ int i915_gem_gtt_init(struct drm_device *dev)/* For GEN6+ the PTEs for the ggtt live at 2MB + BAR0 */ gtt_bus_addr =pci_resource_start (dev->pdev,0 ) + (2 <<20 ); -/* i9xx_setup */ -pci_read_config_word (dev->pdev,SNB_GMCH_CTRL , &snb_gmch_ctl); - dev_priv->mm.gtt->gtt_total_entries = -gen6_get_total_gtt_size (snb_gmch_ctl) /sizeof (gtt_pte_t);if (INTEL_INFO (dev)->gen <7 ) dev_priv->mm.gtt->stolen_size =gen6_get_stolen_size (snb_gmch_ctl);else
@@ -752,8 +755,7 @@ int i915_gem_gtt_init(struct drm_device *dev) goto err_out; } - dev_priv->gtt.gsm =ioremap_wc (gtt_bus_addr, - dev_priv->mm.gtt->gtt_total_entries *sizeof (gtt_pte_t)); + dev_priv->gtt.gsm =ioremap_wc (gtt_bus_addr, gtt_size);if (!dev_priv->gtt.gsm) {DRM_ERROR ("Failed to map the gtt page table\n" );teardown_scratch_page (dev);
@@ -762,7 +764,8 @@ int i915_gem_gtt_init(struct drm_device *dev) }/* GMADR is the PCI aperture used by SW to access tiled GFX surfaces in a linear fashion. */ -DRM_INFO ("Memory usable by graphics device = %dM\n" , dev_priv->mm.gtt->gtt_total_entries >>8 ); +DRM_INFO ("Memory usable by graphics device = %zdM\n" , + dev_priv->gtt.total >>20 );DRM_DEBUG_DRIVER ("GMADR size = %ldM\n" , dev_priv->gtt.mappable_end >>20 );DRM_DEBUG_DRIVER ("GTT stolen size = %dM\n" , dev_priv->mm.gtt->stolen_size >>20 );
Signature · 1 line
1.8.1.1
Re: [PATCH 07/13] drm/i915: Stop using gtt_total_entries
Quoted 7 lines · Ben Widawsky
Similar to
gtt_mappable_entrieswe don't usually want the entries, it's easy enough to calculate it when you need.v2: Move relevant fields above pre-gen6 init
Reviewed-by Rodrigo Vivi <[email protected]>Signed-off-by Ben Widawsky <[email protected]>
[snip]
Quoted 5 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +1
-0@@ -687,11 +690,18 @@ int i915_gem_gtt_init(struct drm_device *dev) {struct drm_i915_private *dev_priv = dev->dev_private;phys_addr_t gtt_bus_addr; +u32 gtt_size;
drivers/gpu/drm/i915/i915_gem_gtt.c int i915_gem_gtt_init(struct drm_device *dev) · line 703
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +5
-0u16 snb_gmch_ctl;int ret; +if (!pci_set_dma_mask (dev->pdev,DMA_BIT_MASK (40 ))) +pci_set_consistent_dma_mask (dev->pdev,DMA_BIT_MASK (40 )); + +pci_read_config_word (dev->pdev,SNB_GMCH_CTRL , &snb_gmch_ctl); dev_priv->gtt.mappable_base =pci_resource_start (dev->pdev,2 ); dev_priv->gtt.mappable_end =pci_resource_len (dev->pdev,2 ); + gtt_size =gen6_get_total_gtt_size (snb_gmch_ctl);
Calculating gtt size like this doesn't work too well on pre-gen6. -Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH 07/13] drm/i915: Stop using gtt_total_entries
Quoted 19 lines · On Fri, 18 Jan 2013 00:04:24 +0100 Daniel Vetter <[email protected]> wrote:
Quoted 7 lines · Ben Widawsky
Similar to
gtt_mappable_entrieswe don't usually want the entries, it's easy enough to calculate it when you need.v2: Move relevant fields above pre-gen6 init
Reviewed-by Rodrigo Vivi <[email protected]>Signed-off-by Ben Widawsky <[email protected]>[snip]
Quoted 8 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +1
-0@@ -687,11 +690,18 @@ int i915_gem_gtt_init(struct drm_device *dev) {struct drm_i915_private *dev_priv = dev->dev_private;phys_addr_t gtt_bus_addr; +u32 gtt_size;u16 snb_gmch_ctl;int ret;
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_gtt.c int i915_gem_gtt_init(struct drm_device *dev) · line 703
Quoted 7 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +5
-0+if (!pci_set_dma_mask (dev->pdev,DMA_BIT_MASK (40 ))) +pci_set_consistent_dma_mask (dev->pdev,DMA_BIT_MASK (40 )); + +pci_read_config_word (dev->pdev,SNB_GMCH_CTRL , &snb_gmch_ctl); dev_priv->gtt.mappable_base =pci_resource_start (dev->pdev,2 ); dev_priv->gtt.mappable_end =pci_resource_len (dev->pdev,2 ); + gtt_size =gen6_get_total_gtt_size (snb_gmch_ctl);Calculating gtt size like this doesn't work too well on pre-gen6. -Daniel
Cc Chris in case he has an opinion.
Daniel, you're right as usual. I botched this again. We actually care about those values in so few places, I thought it might be okay, but it looks like it's not.
Just to update others on our private IRC conversation, my plan unless it turns out too ugly is to create a vtable with a gmch probing function. The vtable is required for other stuff coming soon (more below).
Something like:
int (*gmch_probe)(dev, *mappable_size, *gtt_size, *stolen_size); and then add/update the relevant code in agp/intel-gtt.c.
This allows me to still kill intel_gtt, which for whatever reason I'm pretty gung-ho on killing. I'll need the vtable for things like clear_range, and write_entry among some others I know of and probably a few I haven't yet discovered.
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
PATCH v2 8/13 drm/i915: Move stolen_size to the new struct
In reply to Ben Widawsky--- drivers/gpu/drm/i915/i915_drv.h | 2 ++ drivers/gpu/drm/i915/i915_gem_gtt.c | 7 ++++--- drivers/gpu/drm/i915/i915_gem_stolen.c | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -383,6 +383,8 @@ struct i915_gtt {struct io_mapping *mappable;/* Mapping to our CPU mappable region */ phys_addr_t mappable_base;/* PA of our GMADR */ +size_t stolen_size; +/** "Graphics Stolen Memory" holds the global PTEs */ void __iomem *gsm;
drivers/gpu/drm/i915/i915_gem_gtt.c +4 -3
@@ -734,9 +734,9 @@ int i915_gem_gtt_init(struct drm_device *dev) gtt_bus_addr =pci_resource_start (dev->pdev,0 ) + (2 <<20 );if (INTEL_INFO (dev)->gen <7 ) - dev_priv->mm.gtt->stolen_size =gen6_get_stolen_size (snb_gmch_ctl); + dev_priv->gtt.stolen_size =gen6_get_stolen_size (snb_gmch_ctl);else - dev_priv->mm.gtt->stolen_size =gen7_get_stolen_size (snb_gmch_ctl); + dev_priv->gtt.stolen_size =gen7_get_stolen_size (snb_gmch_ctl);/* 64/512MB is the current min/max we actually know of, but this is just a * coarse sanity check.
@@ -767,7 +767,8 @@ int i915_gem_gtt_init(struct drm_device *dev)DRM_INFO ("Memory usable by graphics device = %zdM\n" , dev_priv->gtt.total >>20 );DRM_DEBUG_DRIVER ("GMADR size = %ldM\n" , dev_priv->gtt.mappable_end >>20 ); -DRM_DEBUG_DRIVER ("GTT stolen size = %dM\n" , dev_priv->mm.gtt->stolen_size >>20 ); +DRM_DEBUG_DRIVER ("GTT stolen size = %zdM\n" , + dev_priv->gtt.stolen_size >>20 );return 0 ;
drivers/gpu/drm/i915/i915_gem_stolen.c +4 -4
@@ -187,11 +187,11 @@ int i915_gem_init_stolen(struct drm_device *dev)if (dev_priv->mm.stolen_base ==0 )return 0 ; -DRM_DEBUG_KMS ("found %d bytes of stolen memory at %08lx\n" , - dev_priv->mm.gtt->stolen_size, dev_priv->mm.stolen_base); +DRM_DEBUG_KMS ("found %zd bytes of stolen memory at %08lx\n" , + dev_priv->gtt.stolen_size, dev_priv->mm.stolen_base);/* Basic memrange allocator for stolen space */ -drm_mm_init (&dev_priv->mm.stolen,0 , dev_priv->mm.gtt->stolen_size); +drm_mm_init (&dev_priv->mm.stolen,0 , dev_priv->gtt.stolen_size);return 0 ; }
@@ -205,7 +205,7 @@ i915_pages_create_for_stolen(struct drm_device *dev,struct scatterlist *sg;DRM_DEBUG_DRIVER ("offset=0x%x, size=%d\n" , offset, size); -BUG_ON (offset > dev_priv->mm.gtt->stolen_size - size); +BUG_ON (offset > dev_priv->gtt.stolen_size - size);/* We hide that we have no struct page backing our stolen object * by wrapping the contiguous physical allocation with a fake
Signature · 1 line
1.8.1.1
Re: [PATCH 08/13] drm/i915: Move stolen_size to the new struct
Quoted 26 lines · Ben Widawsky
Reviewed-by Rodrigo Vivi <[email protected]>Signed-off-by Ben Widawsky <[email protected]>--- drivers/gpu/drm/i915/i915_drv.h | 2 ++ drivers/gpu/drm/i915/i915_gem_gtt.c | 7 ++++--- drivers/gpu/drm/i915/i915_gem_stolen.c | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-)drivers/gpu/drm/i915/i915_drv.h +2
-0@@ -383,6 +383,8 @@ struct i915_gtt {struct io_mapping *mappable;/* Mapping to our CPU mappable region */ phys_addr_t mappable_base;/* PA of our GMADR */ +size_t stolen_size; +/** "Graphics Stolen Memory" holds the global PTEs */ void __iomem *gsm;drivers/gpu/drm/i915/i915_gem_gtt.c +0
-0
drivers/gpu/drm/i915/i915_gem_gtt.c int i915_gem_gtt_init(struct drm_device *dev) · line 737
Quoted 5 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +1
-1@@ -734,9 +734,9 @@ int i915_gem_gtt_init(struct drm_device *dev) gtt_bus_addr =pci_resource_start (dev->pdev,0 ) + (2 <<20 );if (INTEL_INFO (dev)->gen <7 ) - dev_priv->mm.gtt->stolen_size =gen6_get_stolen_size (snb_gmch_ctl); + dev_priv->gtt.stolen_size =gen6_get_stolen_size (snb_gmch_ctl);
Calculating stolen size like that on pre-gen6 won't work too well ... -Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
PATCH v2 9/13 agp/intel: decouple more of the agp-i915 sharing
In reply to Ben Widawsky--- drivers/char/agp/intel-gtt.c | 35 +++++++++++++++++++++-------------- include/drm/intel-gtt.h | 11 +---------- 2 files changed, 22 insertions(+), 24 deletions(-)
drivers/char/agp/intel-gtt.c +21 -14
@@ -76,6 +76,14 @@ static struct _intel_private {int resource_valid;struct page *scratch_page;int refcount; +/* Size of memory reserved for graphics by the BIOS */ +unsigned int stolen_size; +/* Total number of gtt entries. */ +unsigned int gtt_total_entries; +/* Part of the gtt that is mappable by the cpu, for those chips where +* this is not the full gtt. */ +unsigned int gtt_mappable_entries; +phys_addr_t gma_bus_addr; } intel_private;#define INTEL_GTT_GEN intel_private.driver->gen
@@ -506,7 +514,7 @@ static unsigned int intel_gtt_total_entries(void)/* On previous hardware, the GTT size was just what was * required to map the aperture. */ -return intel_private.base.gtt_mappable_entries; +return intel_private.gtt_mappable_entries; } }
@@ -572,8 +580,8 @@ static int intel_gtt_init(void)if (ret !=0 )return ret; - intel_private.base.gtt_mappable_entries =intel_gtt_mappable_entries (); - intel_private.base.gtt_total_entries =intel_gtt_total_entries (); + intel_private.gtt_mappable_entries =intel_gtt_mappable_entries (); + intel_private.gtt_total_entries =intel_gtt_total_entries ();/* save the PGETBL reg for resume */ intel_private.PGETBL_save =
@@ -585,10 +593,10 @@ static int intel_gtt_init(void)dev_info (&intel_private.bridge_dev->dev,"detected gtt size: %dK total, %dK mappable\n" , - intel_private.base.gtt_total_entries *4 , - intel_private.base.gtt_mappable_entries *4 ); + intel_private.gtt_total_entries *4 , + intel_private.gtt_mappable_entries *4 ); - gtt_map_size = intel_private.base.gtt_total_entries *4 ; + gtt_map_size = intel_private.gtt_total_entries *4 ; intel_private.gtt =NULL ;if (INTEL_GTT_GEN <6 &&INTEL_GTT_GEN >2 )
@@ -605,7 +613,7 @@ static int intel_gtt_init(void)global_cache_flush ();/* FIXME: ? */ - intel_private.base.stolen_size =intel_gtt_stolen_size (); + intel_private.stolen_size =intel_gtt_stolen_size (); intel_private.base.needs_dmar =USE_PCI_DMA_API &&INTEL_GTT_GEN >2 ;
@@ -622,7 +630,7 @@ static int intel_gtt_init(void)pci_read_config_dword (intel_private.pcidev,I915_GMADDR , &gma_addr); - intel_private.base.gma_bus_addr = (gma_addr &PCI_BASE_ADDRESS_MEM_MASK ); + intel_private.gma_bus_addr = (gma_addr &PCI_BASE_ADDRESS_MEM_MASK );return 0 ; }
@@ -633,8 +641,7 @@ static int intel_fake_agp_fetch_size(void)unsigned int aper_size;int i; - aper_size = (intel_private.base.gtt_mappable_entries <<PAGE_SHIFT ) - /MB (1 ); + aper_size = (intel_private.gtt_mappable_entries <<PAGE_SHIFT ) /MB (1 );for (i =0 ; i < num_sizes; i++) {if (aper_size == intel_fake_agp_sizes[i].size) {
@@ -778,7 +785,7 @@ static int intel_fake_agp_configure(void)return -EIO ; intel_private.clear_fake_agp = true; - agp_bridge->gart_bus_addr = intel_private.base.gma_bus_addr; + agp_bridge->gart_bus_addr = intel_private.gma_bus_addr;return 0 ; }
@@ -844,8 +851,8 @@ static int intel_fake_agp_insert_entries(struct agp_memory *mem,return -ENODEV ;if (intel_private.clear_fake_agp) { -int start = intel_private.base.stolen_size /PAGE_SIZE ; -int end = intel_private.base.gtt_mappable_entries; +int start = intel_private.stolen_size /PAGE_SIZE ; +int end = intel_private.gtt_mappable_entries;intel_gtt_clear_range (start, end - start); intel_private.clear_fake_agp = false; }
@@ -856,7 +863,7 @@ static int intel_fake_agp_insert_entries(struct agp_memory *mem,if (mem->page_count ==0 ) goto out; -if (pg_start + mem->page_count > intel_private.base.gtt_total_entries) +if (pg_start + mem->page_count > intel_private.gtt_total_entries) goto out_err;if (type != mem->type)
include/drm/intel-gtt.h +1 -10
@@ -4,22 +4,13 @@#define _DRM_INTEL_GTT_Hstruct intel_gtt { -/* Size of memory reserved for graphics by the BIOS */ -unsigned int stolen_size; -/* Total number of gtt entries. */ -unsigned int gtt_total_entries; -/* Part of the gtt that is mappable by the cpu, for those chips where -* this is not the full gtt. */ -unsigned int gtt_mappable_entries; -/* Whether i915 needs to use the dmar apis or not. */ +/* Whether i915 needs to use the dmar apis or not. */ unsigned int needs_dmar :1 ;/* Whether we idle the gpu before mapping/unmapping */ unsigned int do_idle_maps :1 ;/* Share the scratch page dma with ppgtts. */ dma_addr_t scratch_page_dma;struct page *scratch_page; -/* needed for ioremap in drm/i915 */ -phys_addr_t gma_bus_addr; } *intel_gtt_get (void ); int intel_gmch_probe(struct pci_dev *bridge_pdev, struct pci_dev *gpu_pdev,
Signature · 1 line
1.8.1.1
PATCH v2 10/13 drm/i915: Needs_dmar, not
In reply to Ben WidawskyThe reasoning behind our code taking two paths depending upon whether or not we may have been configured for IOMMU isn't clear to me. It should always be safe to use the pci mapping functions as they are designed to abstract the decision we were handling in i915.
Aside from simpler code, removing another member for the intel_gtt struct is a nice motivation.
I ran this by Chris, and he wasn't concerned about the extra kzalloc, and memory references vs. page_to_phys calculation in the case without IOMMU.
v2: Update commit message
v3: Remove needs_dmar addition from Haihao upstream
--- drivers/char/agp/intel-gtt.c | 10 ++++++---- drivers/gpu/drm/i915/i915_gem_gtt.c | 39 +++++++++++++------------------------ include/drm/intel-gtt.h | 2 -- 3 files changed, 19 insertions(+), 32 deletions(-)
drivers/char/agp/intel-gtt.c +6 -4
@@ -84,6 +84,8 @@ static struct _intel_private {* this is not the full gtt. */ unsigned int gtt_mappable_entries;phys_addr_t gma_bus_addr; +/* Whether i915 needs to use the dmar apis or not. */ + unsigned int needs_dmar : 1; } intel_private;#define INTEL_GTT_GEN intel_private.driver->gen
@@ -299,7 +301,7 @@ static int intel_gtt_setup_scratch_page(void)get_page (page);set_pages_uc (page,1 ); -if (intel_private.base.needs_dmar) { +if (intel_private.needs_dmar) { dma_addr =pci_map_page (intel_private.pcidev, page,0 ,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL );if (pci_dma_mapping_error (intel_private.pcidev, dma_addr))
@@ -615,7 +617,7 @@ static int intel_gtt_init(void) intel_private.stolen_size =intel_gtt_stolen_size (); - intel_private.base.needs_dmar =USE_PCI_DMA_API &&INTEL_GTT_GEN >2 ; + intel_private.needs_dmar =USE_PCI_DMA_API &&INTEL_GTT_GEN >2 ; ret =intel_gtt_setup_scratch_page ();if (ret !=0 ) {
@@ -875,7 +877,7 @@ static int intel_fake_agp_insert_entries(struct agp_memory *mem,if (!mem->is_flushed)global_cache_flush (); -if (intel_private.base.needs_dmar) { +if (intel_private.needs_dmar) {struct sg_table st; ret =intel_gtt_map_memory (mem->pages, mem->page_count, &st);
@@ -919,7 +921,7 @@ static int intel_fake_agp_remove_entries(struct agp_memory *mem,intel_gtt_clear_range (pg_start, mem->page_count); -if (intel_private.base.needs_dmar) { +if (intel_private.needs_dmar) {intel_gtt_unmap_memory (mem->sg_list, mem->num_sg); mem->sg_list =NULL ; mem->num_sg =0 ;
drivers/gpu/drm/i915/i915_gem_gtt.c +13 -26
@@ -139,28 +139,23 @@ int i915_gem_init_aliasing_ppgtt(struct drm_device *dev) goto err_pt_alloc; } -if (dev_priv->mm.gtt->needs_dmar) { - ppgtt->pt_dma_addr =kzalloc (sizeof (dma_addr_t) - *ppgtt->num_pd_entries, -GFP_KERNEL ); -if (!ppgtt->pt_dma_addr) - goto err_pt_alloc; + ppgtt->pt_dma_addr =kzalloc (sizeof (dma_addr_t) *ppgtt->num_pd_entries, +GFP_KERNEL ); +if (!ppgtt->pt_dma_addr) + goto err_pt_alloc; -for (i =0 ; i < ppgtt->num_pd_entries; i++) { -dma_addr_t pt_addr; +for (i =0 ; i < ppgtt->num_pd_entries; i++) { +dma_addr_t pt_addr; - pt_addr =pci_map_page (dev->pdev, ppgtt->pt_pages[i], -0 ,4096 , -PCI_DMA_BIDIRECTIONAL ); + pt_addr =pci_map_page (dev->pdev, ppgtt->pt_pages[i],0 ,4096 , +PCI_DMA_BIDIRECTIONAL ); -if (pci_dma_mapping_error (dev->pdev, - pt_addr)) { - ret = -EIO ; - goto err_pd_pin; +if (pci_dma_mapping_error (dev->pdev, pt_addr)) { + ret = -EIO ; + goto err_pd_pin; - } - ppgtt->pt_dma_addr[i] = pt_addr; } + ppgtt->pt_dma_addr[i] = pt_addr; } ppgtt->scratch_page_dma_addr = dev_priv->mm.gtt->scratch_page_dma;
@@ -295,11 +290,7 @@ void i915_gem_init_ppgtt(struct drm_device *dev)for (i =0 ; i < ppgtt->num_pd_entries; i++) {dma_addr_t pt_addr; -if (dev_priv->mm.gtt->needs_dmar) - pt_addr = ppgtt->pt_dma_addr[i]; -else - pt_addr =page_to_phys (ppgtt->pt_pages[i]); - + pt_addr = ppgtt->pt_dma_addr[i]; pd_entry =GEN6_PDE_ADDR_ENCODE (pt_addr); pd_entry |=GEN6_PDE_VALID ;
@@ -726,10 +717,6 @@ int i915_gem_gtt_init(struct drm_device *dev)if (!dev_priv->mm.gtt)return -ENOMEM ; -#ifdef CONFIG_INTEL_IOMMU - dev_priv->mm.gtt->needs_dmar =1 ; -#endif -/* For GEN6+ the PTEs for the ggtt live at 2MB + BAR0 */ gtt_bus_addr =pci_resource_start (dev->pdev,0 ) + (2 <<20 );
include/drm/intel-gtt.h +0 -2
@@ -4,8 +4,6 @@#define _DRM_INTEL_GTT_Hstruct intel_gtt { -/* Whether i915 needs to use the dmar apis or not. */ -unsigned int needs_dmar :1 ;/* Whether we idle the gpu before mapping/unmapping */ unsigned int do_idle_maps :1 ;/* Share the scratch page dma with ppgtts. */
Signature · 1 line
1.8.1.1
PATCH v2 11/13 drm/i915: Cut out the infamous ILK w/a from AGP layer
In reply to Ben WidawskyAnd, move it to where the rest of the logic is.
There is some slight functionality changes. There was extra paranoid checks in AGP code making sure we never do idle maps on gen2 parts. That was not duplicated as the simple PCI id check should do the right thing.
v2: use IS_GEN5 && IS_MOBILE check instead. For now, this is the same as IS_IRONLAKE_M but is more future proof. The workaround docs hint that more than one platform may be effected, but we've never seen such a platform in the wild. (Rodrigo, Daniel)
--- drivers/char/agp/intel-gtt.c | 27 --------------------------- drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/i915_gem_gtt.c | 24 +++++++++++++++++++++--- include/drm/intel-gtt.h | 2 -- 4 files changed, 22 insertions(+), 32 deletions(-)
drivers/char/agp/intel-gtt.c +0 -27
@@ -849,9 +849,6 @@ static int intel_fake_agp_insert_entries(struct agp_memory *mem, {int ret = -EINVAL ; -if (intel_private.base.do_idle_maps) -return -ENODEV ; -if (intel_private.clear_fake_agp) {int start = intel_private.stolen_size /PAGE_SIZE ;int end = intel_private.gtt_mappable_entries;
@@ -916,9 +913,6 @@ static int intel_fake_agp_remove_entries(struct agp_memory *mem,if (mem->page_count ==0 )return 0 ; -if (intel_private.base.do_idle_maps) -return -ENODEV ; -intel_gtt_clear_range (pg_start, mem->page_count);if (intel_private.needs_dmar) {
@@ -1078,24 +1072,6 @@ static void i965_write_entry(dma_addr_t addr,writel (addr | pte_flags, intel_private.gtt + entry); } -/* Certain Gen5 chipsets require require idling the GPU before -* unmapping anything from the GTT when VT-d is enabled. -*/ -static inline int needs_idle_maps (void ) -{ -#ifdef CONFIG_INTEL_IOMMU -const unsigned short gpu_devid = intel_private.pcidev->device; - -/* Query intel_iommu to see if we need the workaround. Presumably that -* was loaded first. -*/ -if ((gpu_devid ==PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB || - gpu_devid ==PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG ) && - intel_iommu_gfx_mapped) -return 1 ; -#endif -return 0 ; -}static int i9xx_setup (void ) {
@@ -1124,9 +1100,6 @@ static int i9xx_setup(void)break ; } -if (needs_idle_maps ()) - intel_private.base.do_idle_maps =1 ; -intel_i9xx_setup_flush ();return 0 ;
drivers/gpu/drm/i915/i915_drv.h +1 -0
@@ -388,6 +388,7 @@ struct i915_gtt {/** "Graphics Stolen Memory" holds the global PTEs */ void __iomem *gsm; +bool do_idle_maps; };#define gtt_total_entries (gtt) ((gtt).total >> PAGE_SHIFT)
drivers/gpu/drm/i915/i915_gem_gtt.c +21 -3
@@ -330,11 +330,27 @@ void i915_gem_init_ppgtt(struct drm_device *dev) } } +extern int intel_iommu_gfx_mapped; +/* Certain Gen5 chipsets require require idling the GPU before +* unmapping anything from the GTT when VT-d is enabled. +*/ +static inline bool needs_idle_maps (struct drm_device *dev) +{ +#ifdef CONFIG_INTEL_IOMMU +/* Query intel_iommu to see if we need the workaround. Presumably that +* was loaded first. +*/ +if (IS_GEN5 (dev) &&IS_MOBILE (dev) && intel_iommu_gfx_mapped) +return true; +#endif +return false; +} +static bool do_idling (struct drm_i915_private *dev_priv) {bool ret = dev_priv->mm.interruptible; -if (unlikely (dev_priv->mm.gtt->do_idle_maps)) { +if (unlikely (dev_priv->gtt.do_idle_maps)) { dev_priv->mm.interruptible = false;if (i915_gpu_idle (dev_priv->dev)) {DRM_ERROR ("Couldn't idle GPU\n" );
@@ -348,11 +364,10 @@ static bool do_idling(struct drm_i915_private *dev_priv)static void undo_idling (struct drm_i915_private *dev_priv,bool interruptible) { -if (unlikely (dev_priv->mm.gtt->do_idle_maps)) +if (unlikely (dev_priv->gtt.do_idle_maps)) dev_priv->mm.interruptible = interruptible; } -static void i915_ggtt_clear_range (struct drm_device *dev,unsigned first_entry,unsigned num_entries)
@@ -710,6 +725,9 @@ int i915_gem_gtt_init(struct drm_device *dev)intel_gmch_remove ();return -ENODEV ; } + + dev_priv->gtt.do_idle_maps =needs_idle_maps (dev); +return 0 ; }
include/drm/intel-gtt.h +0 -2
@@ -4,8 +4,6 @@#define _DRM_INTEL_GTT_Hstruct intel_gtt { -/* Whether we idle the gpu before mapping/unmapping */ -unsigned int do_idle_maps :1 ;/* Share the scratch page dma with ppgtts. */ dma_addr_t scratch_page_dma;struct page *scratch_page;
Signature · 1 line
1.8.1.1
PATCH v2 12/13 drm/i915: Remove scratch page from shared
In reply to Ben WidawskyWe already had a mapping in both (minus the phys_addr in AGP).
--- drivers/char/agp/intel-gtt.c | 9 +++++---- drivers/gpu/drm/i915/i915_drv.h | 2 ++ drivers/gpu/drm/i915/i915_gem_gtt.c | 16 ++++++++-------- include/drm/intel-gtt.h | 3 --- 4 files changed, 15 insertions(+), 15 deletions(-)
drivers/char/agp/intel-gtt.c +5 -4
@@ -75,6 +75,7 @@ static struct _intel_private {struct resource ifp_resource;int resource_valid;struct page *scratch_page; +phys_addr_t scratch_page_dma;int refcount;/* Size of memory reserved for graphics by the BIOS */ unsigned int stolen_size;
@@ -307,9 +308,9 @@ static int intel_gtt_setup_scratch_page(void)if (pci_dma_mapping_error (intel_private.pcidev, dma_addr))return -EINVAL ; - intel_private.base.scratch_page_dma = dma_addr; + intel_private.scratch_page_dma = dma_addr; }else - intel_private.base.scratch_page_dma =page_to_phys (page); + intel_private.scratch_page_dma =page_to_phys (page); intel_private.scratch_page = page;
@@ -556,7 +557,7 @@ static unsigned int intel_gtt_mappable_entries(void)static void intel_gtt_teardown_scratch_page (void ) {set_pages_wb (intel_private.scratch_page,1 ); -pci_unmap_page (intel_private.pcidev, intel_private.base.scratch_page_dma, +pci_unmap_page (intel_private.pcidev, intel_private.scratch_page_dma,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL );put_page (intel_private.scratch_page);__free_page (intel_private.scratch_page);
@@ -900,7 +901,7 @@ void intel_gtt_clear_range(unsigned int first_entry, unsigned int num_entries)unsigned int i;for (i = first_entry; i < (first_entry + num_entries); i++) { - intel_private.driver->write_entry (intel_private.base.scratch_page_dma, + intel_private.driver->write_entry (intel_private.scratch_page_dma, i,0 ); }readl (intel_private.gtt+i-1 );
drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -389,6 +389,8 @@ struct i915_gtt {void __iomem *gsm;bool do_idle_maps; +dma_addr_t scratch_page_dma; +struct page *scratch_page; };#define gtt_total_entries (gtt) ((gtt).total >> PAGE_SHIFT)
drivers/gpu/drm/i915/i915_gem_gtt.c +8 -8
@@ -158,7 +158,7 @@ int i915_gem_init_aliasing_ppgtt(struct drm_device *dev) ppgtt->pt_dma_addr[i] = pt_addr; } - ppgtt->scratch_page_dma_addr = dev_priv->mm.gtt->scratch_page_dma; + ppgtt->scratch_page_dma_addr = dev_priv->gtt.scratch_page_dma;i915_ppgtt_clear_range (ppgtt,0 , ppgtt->num_pd_entries*I915_PPGTT_PT_ENTRIES );
@@ -388,7 +388,7 @@ static void i915_ggtt_clear_range(struct drm_device *dev, first_entry, num_entries, max_entries)) num_entries = max_entries; - scratch_pte =pte_encode (dev, dev_priv->mm.gtt->scratch_page_dma,I915_CACHE_LLC ); + scratch_pte =pte_encode (dev, dev_priv->gtt.scratch_page_dma,I915_CACHE_LLC );for (i =0 ; i < num_entries; i++)iowrite32 (scratch_pte, >t_base[i]);readl (gtt_base);
@@ -653,8 +653,8 @@ static int setup_scratch_page(struct drm_device *dev)#else dma_addr =page_to_phys (page);#endif - dev_priv->mm.gtt->scratch_page = page; - dev_priv->mm.gtt->scratch_page_dma = dma_addr; + dev_priv->gtt.scratch_page = page; + dev_priv->gtt.scratch_page_dma = dma_addr;return 0 ; }
@@ -662,11 +662,11 @@ static int setup_scratch_page(struct drm_device *dev)static void teardown_scratch_page (struct drm_device *dev) {struct drm_i915_private *dev_priv = dev->dev_private; -set_pages_wb (dev_priv->mm.gtt->scratch_page,1 ); -pci_unmap_page (dev->pdev, dev_priv->mm.gtt->scratch_page_dma, +set_pages_wb (dev_priv->gtt.scratch_page,1 ); +pci_unmap_page (dev->pdev, dev_priv->gtt.scratch_page_dma,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL ); -put_page (dev_priv->mm.gtt->scratch_page); -__free_page (dev_priv->mm.gtt->scratch_page); +put_page (dev_priv->gtt.scratch_page); +__free_page (dev_priv->gtt.scratch_page); }static inline unsigned int gen6_get_total_gtt_size (u16 snb_gmch_ctl)
include/drm/intel-gtt.h +0 -3
@@ -4,9 +4,6 @@#define _DRM_INTEL_GTT_Hstruct intel_gtt { -/* Share the scratch page dma with ppgtts. */ -dma_addr_t scratch_page_dma; -struct page *scratch_page; } *intel_gtt_get (void ); int intel_gmch_probe(struct pci_dev *bridge_pdev, struct pci_dev *gpu_pdev,
Signature · 1 line
1.8.1.1
PATCH v2 13/13 drm/i915: Finally kill off struct intel_gtt
In reply to Ben WidawskyNothing is shared anymore between AGP and drm/i915 driver. Pre-GEN6 still uses AGP, but all necessary info is encapsulated per driver.
v2: Conflict resolution from earlier rebase
--- drivers/char/agp/intel-gtt.c | 7 ------- drivers/gpu/drm/i915/i915_gem_gtt.c | 21 +-------------------- include/drm/intel-gtt.h | 3 --- 3 files changed, 1 insertion(+), 30 deletions(-)
drivers/char/agp/intel-gtt.c +0 -7
@@ -60,7 +60,6 @@ struct intel_gtt_driver { }; static struct _intel_private { - struct intel_gtt base; const struct intel_gtt_driver *driver; struct pci_dev *pcidev; /* device one */ struct pci_dev *bridge_dev;
@@ -1372,12 +1371,6 @@ int intel_gmch_probe(struct pci_dev *bridge_pdev, struct pci_dev *gpu_pdev, }EXPORT_SYMBOL (intel_gmch_probe); -struct intel_gtt *intel_gtt_get (void ) -{ -return &intel_private.base; -} -EXPORT_SYMBOL (intel_gtt_get); -void intel_gtt_chipset_flush (void ) {if (intel_private.driver->chipset_flush)
drivers/gpu/drm/i915/i915_gem_gtt.c +1 -20
@@ -713,28 +713,10 @@ int i915_gem_gtt_init(struct drm_device *dev)* hostbridge query stuff. Skip it entirely */ if (INTEL_INFO (dev)->gen <6 ) { - ret =intel_gmch_probe (dev_priv->bridge_dev, dev->pdev,NULL ); -if (!ret) { -DRM_ERROR ("failed to set up gmch\n" ); -return -EIO ; - } - - dev_priv->mm.gtt =intel_gtt_get (); -if (!dev_priv->mm.gtt) { -DRM_ERROR ("Failed to initialize GTT\n" ); -intel_gmch_remove (); -return -ENODEV ; - } - dev_priv->gtt.do_idle_maps =needs_idle_maps (dev); - -return 0 ; +return intel_gmch_probe (dev_priv->bridge_dev, dev->pdev,NULL ); } - dev_priv->mm.gtt =kzalloc (sizeof (*dev_priv->mm.gtt),GFP_KERNEL ); -if (!dev_priv->mm.gtt) -return -ENOMEM ; -/* For GEN6+ the PTEs for the ggtt live at 2MB + BAR0 */ gtt_bus_addr =pci_resource_start (dev->pdev,0 ) + (2 <<20 );
@@ -791,5 +773,4 @@ void i915_gem_gtt_fini(struct drm_device *dev)teardown_scratch_page (dev);if (INTEL_INFO (dev)->gen <6 )intel_gmch_remove (); -kfree (dev_priv->mm.gtt); }
include/drm/intel-gtt.h +0 -3
@@ -3,9 +3,6 @@#ifndef _DRM_INTEL_GTT_H#define _DRM_INTEL_GTT_H -struct intel_gtt { -} *intel_gtt_get (void ); -int intel_gmch_probe (struct pci_dev *bridge_pdev,struct pci_dev *gpu_pdev,struct agp_bridge_data *bridge);void intel_gmch_remove (void );
Signature · 1 line
1.8.1.1