Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/i915: Create a gtt structure

The 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_start
gtt_total
gtt_mappable_end
gtt_mappable
gtt_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).

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@gmail.com>
[Ben modified commit messages]
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>

authored by

Ben Widawsky and committed by
Daniel Vetter
5d4545ae 00fc2c3c

+61 -48
+2 -2
drivers/gpu/drm/i915/i915_debugfs.c
··· 259 259 count, size); 260 260 261 261 seq_printf(m, "%zu [%zu] gtt total\n", 262 - dev_priv->mm.gtt_total, 263 - dev_priv->mm.gtt_mappable_end - dev_priv->mm.gtt_start); 262 + dev_priv->gtt.total, 263 + dev_priv->gtt.mappable_end - dev_priv->gtt.start); 264 264 265 265 mutex_unlock(&dev->struct_mutex); 266 266
+10 -10
drivers/gpu/drm/i915/i915_dma.c
··· 1076 1076 ring->status_page.gfx_addr = hws->addr & (0x1ffff<<12); 1077 1077 1078 1078 dev_priv->dri1.gfx_hws_cpu_addr = 1079 - ioremap_wc(dev_priv->mm.gtt_base_addr + hws->addr, 4096); 1079 + ioremap_wc(dev_priv->gtt.mappable_base + hws->addr, 4096); 1080 1080 if (dev_priv->dri1.gfx_hws_cpu_addr == NULL) { 1081 1081 i915_dma_cleanup(dev); 1082 1082 ring->status_page.gfx_addr = 0; ··· 1543 1543 } 1544 1544 1545 1545 aperture_size = dev_priv->mm.gtt->gtt_mappable_entries << PAGE_SHIFT; 1546 - dev_priv->mm.gtt_base_addr = dev_priv->mm.gtt->gma_bus_addr; 1546 + dev_priv->gtt.mappable_base = dev_priv->mm.gtt->gma_bus_addr; 1547 1547 1548 - dev_priv->mm.gtt_mapping = 1549 - io_mapping_create_wc(dev_priv->mm.gtt_base_addr, 1548 + dev_priv->gtt.mappable = 1549 + io_mapping_create_wc(dev_priv->gtt.mappable_base, 1550 1550 aperture_size); 1551 - if (dev_priv->mm.gtt_mapping == NULL) { 1551 + if (dev_priv->gtt.mappable == NULL) { 1552 1552 ret = -EIO; 1553 1553 goto out_rmmap; 1554 1554 } 1555 1555 1556 - i915_mtrr_setup(dev_priv, dev_priv->mm.gtt_base_addr, 1556 + i915_mtrr_setup(dev_priv, dev_priv->gtt.mappable_base, 1557 1557 aperture_size); 1558 1558 1559 1559 /* The i915 workqueue is primarily used for batched retirement of ··· 1658 1658 out_mtrrfree: 1659 1659 if (dev_priv->mm.gtt_mtrr >= 0) { 1660 1660 mtrr_del(dev_priv->mm.gtt_mtrr, 1661 - dev_priv->mm.gtt_base_addr, 1661 + dev_priv->gtt.mappable_base, 1662 1662 aperture_size); 1663 1663 dev_priv->mm.gtt_mtrr = -1; 1664 1664 } 1665 - io_mapping_free(dev_priv->mm.gtt_mapping); 1665 + io_mapping_free(dev_priv->gtt.mappable); 1666 1666 out_rmmap: 1667 1667 pci_iounmap(dev->pdev, dev_priv->regs); 1668 1668 put_gmch: ··· 1696 1696 /* Cancel the retire work handler, which should be idle now. */ 1697 1697 cancel_delayed_work_sync(&dev_priv->mm.retire_work); 1698 1698 1699 - io_mapping_free(dev_priv->mm.gtt_mapping); 1699 + io_mapping_free(dev_priv->gtt.mappable); 1700 1700 if (dev_priv->mm.gtt_mtrr >= 0) { 1701 1701 mtrr_del(dev_priv->mm.gtt_mtrr, 1702 - dev_priv->mm.gtt_base_addr, 1702 + dev_priv->gtt.mappable_base, 1703 1703 dev_priv->mm.gtt->gtt_mappable_entries * PAGE_SIZE); 1704 1704 dev_priv->mm.gtt_mtrr = -1; 1705 1705 }
+21 -8
drivers/gpu/drm/i915/i915_drv.h
··· 364 364 u8 has_llc:1; 365 365 }; 366 366 367 + /* The Graphics Translation Table is the way in which GEN hardware translates a 368 + * Graphics Virtual Address into a Physical Address. In addition to the normal 369 + * collateral associated with any va->pa translations GEN hardware also has a 370 + * portion of the GTT which can be mapped by the CPU and remain both coherent 371 + * and correct (in cases like swizzling). That region is referred to as GMADR in 372 + * the spec. 373 + */ 374 + struct i915_gtt { 375 + unsigned long start; /* Start offset of used GTT */ 376 + size_t total; /* Total size GTT can map */ 377 + 378 + unsigned long mappable_end; /* End offset that we can CPU map */ 379 + struct io_mapping *mappable; /* Mapping to our CPU mappable region */ 380 + phys_addr_t mappable_base; /* PA of our GMADR */ 381 + 382 + /** "Graphics Stolen Memory" holds the global PTEs */ 383 + void __iomem *gsm; 384 + }; 385 + 367 386 #define I915_PPGTT_PD_ENTRIES 512 368 387 #define I915_PPGTT_PT_ENTRIES 1024 369 388 struct i915_hw_ppgtt { ··· 800 781 /* Register state */ 801 782 bool modeset_on_lid; 802 783 784 + struct i915_gtt gtt; 785 + 803 786 struct { 804 787 /** Bridge to intel-gtt-ko */ 805 788 struct intel_gtt *gtt; ··· 820 799 struct list_head unbound_list; 821 800 822 801 /** Usable portion of the GTT for GEM */ 823 - unsigned long gtt_start; 824 - unsigned long gtt_mappable_end; 825 802 unsigned long stolen_base; /* limited to low memory (32-bit) */ 826 803 827 - /** "Graphics Stolen Memory" holds the global PTEs */ 828 - void __iomem *gsm; 829 - 830 - struct io_mapping *gtt_mapping; 831 - phys_addr_t gtt_base_addr; 832 804 int gtt_mtrr; 833 805 834 806 /** PPGTT used for aliasing the PPGTT with the GTT */ ··· 899 885 struct drm_i915_gem_phys_object *phys_objs[I915_MAX_PHYS_OBJECT]; 900 886 901 887 /* accounting, useful for userland debugging */ 902 - size_t gtt_total; 903 888 size_t object_memory; 904 889 u32 object_count; 905 890 } mm;
+7 -7
drivers/gpu/drm/i915/i915_gem.c
··· 186 186 pinned += obj->gtt_space->size; 187 187 mutex_unlock(&dev->struct_mutex); 188 188 189 - args->aper_size = dev_priv->mm.gtt_total; 189 + args->aper_size = dev_priv->gtt.total; 190 190 args->aper_available_size = args->aper_size - pinned; 191 191 192 192 return 0; ··· 637 637 * source page isn't available. Return the error and we'll 638 638 * retry in the slow path. 639 639 */ 640 - if (fast_user_write(dev_priv->mm.gtt_mapping, page_base, 640 + if (fast_user_write(dev_priv->gtt.mappable, page_base, 641 641 page_offset, user_data, page_length)) { 642 642 ret = -EFAULT; 643 643 goto out_unpin; ··· 1362 1362 1363 1363 obj->fault_mappable = true; 1364 1364 1365 - pfn = ((dev_priv->mm.gtt_base_addr + obj->gtt_offset) >> PAGE_SHIFT) + 1365 + pfn = ((dev_priv->gtt.mappable_base + obj->gtt_offset) >> PAGE_SHIFT) + 1366 1366 page_offset; 1367 1367 1368 1368 /* Finally, remap it using the new GTT offset */ ··· 1544 1544 goto unlock; 1545 1545 } 1546 1546 1547 - if (obj->base.size > dev_priv->mm.gtt_mappable_end) { 1547 + if (obj->base.size > dev_priv->gtt.mappable_end) { 1548 1548 ret = -E2BIG; 1549 1549 goto out; 1550 1550 } ··· 2910 2910 * before evicting everything in a vain attempt to find space. 2911 2911 */ 2912 2912 if (obj->base.size > 2913 - (map_and_fenceable ? dev_priv->mm.gtt_mappable_end : dev_priv->mm.gtt_total)) { 2913 + (map_and_fenceable ? dev_priv->gtt.mappable_end : dev_priv->gtt.total)) { 2914 2914 DRM_ERROR("Attempting to bind an object larger than the aperture\n"); 2915 2915 return -E2BIG; 2916 2916 } ··· 2931 2931 if (map_and_fenceable) 2932 2932 ret = drm_mm_insert_node_in_range_generic(&dev_priv->mm.gtt_space, node, 2933 2933 size, alignment, obj->cache_level, 2934 - 0, dev_priv->mm.gtt_mappable_end); 2934 + 0, dev_priv->gtt.mappable_end); 2935 2935 else 2936 2936 ret = drm_mm_insert_node_generic(&dev_priv->mm.gtt_space, node, 2937 2937 size, alignment, obj->cache_level); ··· 2971 2971 (node->start & (fence_alignment - 1)) == 0; 2972 2972 2973 2973 mappable = 2974 - obj->gtt_offset + obj->base.size <= dev_priv->mm.gtt_mappable_end; 2974 + obj->gtt_offset + obj->base.size <= dev_priv->gtt.mappable_end; 2975 2975 2976 2976 obj->map_and_fenceable = mappable && fenceable; 2977 2977
+1 -1
drivers/gpu/drm/i915/i915_gem_evict.c
··· 80 80 if (mappable) 81 81 drm_mm_init_scan_with_range(&dev_priv->mm.gtt_space, 82 82 min_size, alignment, cache_level, 83 - 0, dev_priv->mm.gtt_mappable_end); 83 + 0, dev_priv->gtt.mappable_end); 84 84 else 85 85 drm_mm_init_scan(&dev_priv->mm.gtt_space, 86 86 min_size, alignment, cache_level);
+1 -1
drivers/gpu/drm/i915/i915_gem_execbuffer.c
··· 281 281 282 282 /* Map the page containing the relocation we're going to perform. */ 283 283 reloc->offset += obj->gtt_offset; 284 - reloc_page = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping, 284 + reloc_page = io_mapping_map_atomic_wc(dev_priv->gtt.mappable, 285 285 reloc->offset & PAGE_MASK); 286 286 reloc_entry = (uint32_t __iomem *) 287 287 (reloc_page + (reloc->offset & ~PAGE_MASK));
+12 -12
drivers/gpu/drm/i915/i915_gem_gtt.c
··· 290 290 return; 291 291 292 292 293 - pd_addr = (gtt_pte_t __iomem*)dev_priv->mm.gsm + ppgtt->pd_offset/sizeof(gtt_pte_t); 293 + pd_addr = (gtt_pte_t __iomem*)dev_priv->gtt.gsm + ppgtt->pd_offset/sizeof(gtt_pte_t); 294 294 for (i = 0; i < ppgtt->num_pd_entries; i++) { 295 295 dma_addr_t pt_addr; 296 296 ··· 367 367 { 368 368 struct drm_i915_private *dev_priv = dev->dev_private; 369 369 gtt_pte_t scratch_pte; 370 - gtt_pte_t __iomem *gtt_base = (gtt_pte_t __iomem *) dev_priv->mm.gsm + first_entry; 370 + gtt_pte_t __iomem *gtt_base = (gtt_pte_t __iomem *) dev_priv->gtt.gsm + first_entry; 371 371 const int max_entries = dev_priv->mm.gtt->gtt_total_entries - first_entry; 372 372 int i; 373 373 ··· 393 393 struct drm_i915_gem_object *obj; 394 394 395 395 /* First fill our portion of the GTT with scratch pages */ 396 - i915_ggtt_clear_range(dev, dev_priv->mm.gtt_start / PAGE_SIZE, 397 - dev_priv->mm.gtt_total / PAGE_SIZE); 396 + i915_ggtt_clear_range(dev, dev_priv->gtt.start / PAGE_SIZE, 397 + dev_priv->gtt.total / PAGE_SIZE); 398 398 399 399 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) { 400 400 i915_gem_clflush_object(obj); ··· 433 433 const int first_entry = obj->gtt_space->start >> PAGE_SHIFT; 434 434 const int max_entries = dev_priv->mm.gtt->gtt_total_entries - first_entry; 435 435 gtt_pte_t __iomem *gtt_entries = 436 - (gtt_pte_t __iomem *)dev_priv->mm.gsm + first_entry; 436 + (gtt_pte_t __iomem *)dev_priv->gtt.gsm + first_entry; 437 437 int unused, i = 0; 438 438 unsigned int len, m = 0; 439 439 dma_addr_t addr; ··· 556 556 obj->has_global_gtt_mapping = 1; 557 557 } 558 558 559 - dev_priv->mm.gtt_start = start; 560 - dev_priv->mm.gtt_mappable_end = mappable_end; 561 - dev_priv->mm.gtt_total = end - start; 559 + dev_priv->gtt.start = start; 560 + dev_priv->gtt.mappable_end = mappable_end; 561 + dev_priv->gtt.total = end - start; 562 562 563 563 /* Clear any non-preallocated blocks */ 564 564 drm_mm_for_each_hole(entry, &dev_priv->mm.gtt_space, ··· 752 752 goto err_out; 753 753 } 754 754 755 - dev_priv->mm.gsm = ioremap_wc(gtt_bus_addr, 756 - dev_priv->mm.gtt->gtt_total_entries * sizeof(gtt_pte_t)); 757 - if (!dev_priv->mm.gsm) { 755 + dev_priv->gtt.gsm = ioremap_wc(gtt_bus_addr, 756 + dev_priv->mm.gtt->gtt_total_entries * sizeof(gtt_pte_t)); 757 + if (!dev_priv->gtt.gsm) { 758 758 DRM_ERROR("Failed to map the gtt page table\n"); 759 759 teardown_scratch_page(dev); 760 760 ret = -ENOMEM; ··· 778 778 void i915_gem_gtt_fini(struct drm_device *dev) 779 779 { 780 780 struct drm_i915_private *dev_priv = dev->dev_private; 781 - iounmap(dev_priv->mm.gsm); 781 + iounmap(dev_priv->gtt.gsm); 782 782 teardown_scratch_page(dev); 783 783 if (INTEL_INFO(dev)->gen < 6) 784 784 intel_gmch_remove();
+1 -1
drivers/gpu/drm/i915/i915_gem_tiling.c
··· 357 357 358 358 obj->map_and_fenceable = 359 359 obj->gtt_space == NULL || 360 - (obj->gtt_offset + obj->base.size <= dev_priv->mm.gtt_mappable_end && 360 + (obj->gtt_offset + obj->base.size <= dev_priv->gtt.mappable_end && 361 361 i915_gem_object_fence_ok(obj, args->tiling_mode)); 362 362 363 363 /* Rebind if we need a change of alignment */
+2 -2
drivers/gpu/drm/i915/i915_irq.c
··· 939 939 goto unwind; 940 940 941 941 local_irq_save(flags); 942 - if (reloc_offset < dev_priv->mm.gtt_mappable_end && 942 + if (reloc_offset < dev_priv->gtt.mappable_end && 943 943 src->has_global_gtt_mapping) { 944 944 void __iomem *s; 945 945 ··· 948 948 * captures what the GPU read. 949 949 */ 950 950 951 - s = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping, 951 + s = io_mapping_map_atomic_wc(dev_priv->gtt.mappable, 952 952 reloc_offset); 953 953 memcpy_fromio(d, s, PAGE_SIZE); 954 954 io_mapping_unmap_atomic(s);
+1 -1
drivers/gpu/drm/i915/intel_display.c
··· 8687 8687 dev->mode_config.max_width = 8192; 8688 8688 dev->mode_config.max_height = 8192; 8689 8689 } 8690 - dev->mode_config.fb_base = dev_priv->mm.gtt_base_addr; 8690 + dev->mode_config.fb_base = dev_priv->gtt.mappable_base; 8691 8691 8692 8692 DRM_DEBUG_KMS("%d display pipe%s available.\n", 8693 8693 dev_priv->num_pipe, dev_priv->num_pipe > 1 ? "s" : "");
+1 -1
drivers/gpu/drm/i915/intel_fb.c
··· 142 142 info->fix.smem_len = size; 143 143 144 144 info->screen_base = 145 - ioremap_wc(dev_priv->mm.gtt_base_addr + obj->gtt_offset, 145 + ioremap_wc(dev_priv->gtt.mappable_base + obj->gtt_offset, 146 146 size); 147 147 if (!info->screen_base) { 148 148 ret = -ENOSPC;
+2 -2
drivers/gpu/drm/i915/intel_overlay.c
··· 195 195 if (OVERLAY_NEEDS_PHYSICAL(overlay->dev)) 196 196 regs = (struct overlay_registers __iomem *)overlay->reg_bo->phys_obj->handle->vaddr; 197 197 else 198 - regs = io_mapping_map_wc(dev_priv->mm.gtt_mapping, 198 + regs = io_mapping_map_wc(dev_priv->gtt.mappable, 199 199 overlay->reg_bo->gtt_offset); 200 200 201 201 return regs; ··· 1434 1434 regs = (struct overlay_registers __iomem *) 1435 1435 overlay->reg_bo->phys_obj->handle->vaddr; 1436 1436 else 1437 - regs = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping, 1437 + regs = io_mapping_map_atomic_wc(dev_priv->gtt.mappable, 1438 1438 overlay->reg_bo->gtt_offset); 1439 1439 1440 1440 return regs;