Skip to content

Commit baa09f5

Browse files
bwidawskdanvet
authored andcommitted
drm/i915: Add probe and remove to the gtt ops
The idea, and much of the code came originally from: commit 0712f0249c3148d8cf42a3703403c278590d4de5 Author: Ben Widawsky <ben@bwidawsk.net> Date: Fri Jan 18 17:23:16 2013 -0800 drm/i915: Create a vtable for i915 gtt Daniel didn't like the color of that patch series, and so I asked him to start something which appealed to his sense of color. The preceding patches are those, and now this is going on top of that. [extracted from the original commit message] One immediately obvious thing to implement is our gmch probing. The init function was getting massively bloated. Fundamentally, all that's needed from GMCH probing is the GTT size, and the stolen size. It makes design sense to put the mappable calculation in there as well, but the code turns out a bit nicer without it (IMO) The intel_gtt bridge thing is still here, but the subsequent patches will finish ripping that out. Signed-off-by: Ben Widawsky <ben@bwidawsk.net> [danvet: Bikeshedded one comment (GMADR is just the PCI aperture, we use it for other things than just accessing tiled surfaces through a linear view) and cut the newly added long lines a bit. Also one checkpatch error.] Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
1 parent 3440d26 commit baa09f5

3 files changed

Lines changed: 114 additions & 79 deletions

File tree

‎drivers/gpu/drm/i915/i915_dma.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
16651665
out_rmmap:
16661666
pci_iounmap(dev->pdev, dev_priv->regs);
16671667
put_gmch:
1668-
i915_gem_gtt_fini(dev);
1668+
dev_priv->gtt.gtt_remove(dev);
16691669
put_bridge:
16701670
pci_dev_put(dev_priv->bridge_dev);
16711671
free_priv:

‎drivers/gpu/drm/i915/i915_drv.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ enum i915_cache_level {
381381
struct i915_gtt {
382382
unsigned long start; /* Start offset of used GTT */
383383
size_t total; /* Total size GTT can map */
384+
size_t stolen_size; /* Total size of stolen memory */
384385

385386
unsigned long mappable_end; /* End offset that we can CPU map */
386387
struct io_mapping *mappable; /* Mapping to our CPU mappable region */
@@ -394,6 +395,9 @@ struct i915_gtt {
394395
struct page *scratch_page;
395396

396397
/* global gtt ops */
398+
int (*gtt_probe)(struct drm_device *dev, size_t *gtt_total,
399+
size_t *stolen);
400+
void (*gtt_remove)(struct drm_device *dev);
397401
void (*gtt_clear_range)(struct drm_device *dev,
398402
unsigned int first_entry,
399403
unsigned int num_entries);
@@ -1689,7 +1693,6 @@ void i915_gem_init_global_gtt(struct drm_device *dev);
16891693
void i915_gem_setup_global_gtt(struct drm_device *dev, unsigned long start,
16901694
unsigned long mappable_end, unsigned long end);
16911695
int i915_gem_gtt_init(struct drm_device *dev);
1692-
void i915_gem_gtt_fini(struct drm_device *dev);
16931696
static inline void i915_gem_chipset_flush(struct drm_device *dev)
16941697
{
16951698
if (INTEL_INFO(dev)->gen < 6)

‎drivers/gpu/drm/i915/i915_gem_gtt.c‎

Lines changed: 109 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -707,14 +707,14 @@ static inline unsigned int gen6_get_total_gtt_size(u16 snb_gmch_ctl)
707707
return snb_gmch_ctl << 20;
708708
}
709709

710-
static inline unsigned int gen6_get_stolen_size(u16 snb_gmch_ctl)
710+
static inline size_t gen6_get_stolen_size(u16 snb_gmch_ctl)
711711
{
712712
snb_gmch_ctl >>= SNB_GMCH_GMS_SHIFT;
713713
snb_gmch_ctl &= SNB_GMCH_GMS_MASK;
714714
return snb_gmch_ctl << 25; /* 32 MB units */
715715
}
716716

717-
static inline unsigned int gen7_get_stolen_size(u16 snb_gmch_ctl)
717+
static inline size_t gen7_get_stolen_size(u16 snb_gmch_ctl)
718718
{
719719
static const int stolen_decoder[] = {
720720
0, 0, 0, 0, 0, 32, 48, 64, 128, 256, 96, 160, 224, 352};
@@ -723,109 +723,141 @@ static inline unsigned int gen7_get_stolen_size(u16 snb_gmch_ctl)
723723
return stolen_decoder[snb_gmch_ctl] << 20;
724724
}
725725

726-
int i915_gem_gtt_init(struct drm_device *dev)
726+
static int gen6_gmch_probe(struct drm_device *dev,
727+
size_t *gtt_total,
728+
size_t *stolen)
727729
{
728730
struct drm_i915_private *dev_priv = dev->dev_private;
729731
phys_addr_t gtt_bus_addr;
732+
unsigned int gtt_size;
730733
u16 snb_gmch_ctl;
731734
int ret;
732735

733-
dev_priv->gtt.mappable_base = pci_resource_start(dev->pdev, 2);
734-
dev_priv->gtt.mappable_end = pci_resource_len(dev->pdev, 2);
735-
736-
/* On modern platforms we need not worry ourself with the legacy
737-
* hostbridge query stuff. Skip it entirely
736+
/* 64/512MB is the current min/max we actually know of, but this is just
737+
* a coarse sanity check.
738738
*/
739-
if (INTEL_INFO(dev)->gen < 6) {
740-
ret = intel_gmch_probe(dev_priv->bridge_dev, dev->pdev, NULL);
741-
if (!ret) {
742-
DRM_ERROR("failed to set up gmch\n");
743-
return -EIO;
744-
}
745-
746-
dev_priv->mm.gtt = intel_gtt_get();
747-
if (!dev_priv->mm.gtt) {
748-
DRM_ERROR("Failed to initialize GTT\n");
749-
intel_gmch_remove();
750-
return -ENODEV;
751-
}
752-
753-
dev_priv->gtt.do_idle_maps = needs_idle_maps(dev);
754-
755-
dev_priv->gtt.gtt_clear_range = i915_ggtt_clear_range;
756-
dev_priv->gtt.gtt_insert_entries = i915_ggtt_insert_entries;
757-
758-
return 0;
739+
if ((dev_priv->gtt.mappable_end < (64<<20) ||
740+
(dev_priv->gtt.mappable_end > (512<<20)))) {
741+
DRM_ERROR("Unknown GMADR size (%lx)\n",
742+
dev_priv->gtt.mappable_end);
743+
return -ENXIO;
759744
}
760745

761746
if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(40)))
762747
pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(40));
763-
764-
dev_priv->mm.gtt = kzalloc(sizeof(*dev_priv->mm.gtt), GFP_KERNEL);
765-
if (!dev_priv->mm.gtt)
766-
return -ENOMEM;
767-
768-
/* For GEN6+ the PTEs for the ggtt live at 2MB + BAR0 */
769-
gtt_bus_addr = pci_resource_start(dev->pdev, 0) + (2<<20);
770-
771-
/* i9xx_setup */
772748
pci_read_config_word(dev->pdev, SNB_GMCH_CTRL, &snb_gmch_ctl);
773-
dev_priv->mm.gtt->gtt_total_entries =
774-
gen6_get_total_gtt_size(snb_gmch_ctl) / sizeof(gtt_pte_t);
775-
if (INTEL_INFO(dev)->gen < 7)
776-
dev_priv->mm.gtt->stolen_size = gen6_get_stolen_size(snb_gmch_ctl);
777-
else
778-
dev_priv->mm.gtt->stolen_size = gen7_get_stolen_size(snb_gmch_ctl);
749+
gtt_size = gen6_get_total_gtt_size(snb_gmch_ctl);
779750

780-
/* 64/512MB is the current min/max we actually know of, but this is just a
781-
* coarse sanity check.
782-
*/
783-
if ((dev_priv->gtt.mappable_end < (64<<20) ||
784-
(dev_priv->gtt.mappable_end > (512<<20)))) {
785-
DRM_ERROR("Unknown GMADR size (%lx)\n",
786-
dev_priv->gtt.mappable_end);
787-
ret = -ENXIO;
788-
goto err_out;
789-
}
751+
if (IS_GEN7(dev))
752+
*stolen = gen7_get_stolen_size(snb_gmch_ctl);
753+
else
754+
*stolen = gen6_get_stolen_size(snb_gmch_ctl);
790755

791-
ret = setup_scratch_page(dev);
792-
if (ret) {
793-
DRM_ERROR("Scratch setup failed\n");
794-
goto err_out;
795-
}
756+
*gtt_total = (gtt_size / sizeof(gtt_pte_t)) << PAGE_SHIFT;
796757

797-
dev_priv->gtt.gsm = ioremap_wc(gtt_bus_addr,
798-
dev_priv->mm.gtt->gtt_total_entries * sizeof(gtt_pte_t));
758+
/* For GEN6+ the PTEs for the ggtt live at 2MB + BAR0 */
759+
gtt_bus_addr = pci_resource_start(dev->pdev, 0) + (2<<20);
760+
dev_priv->gtt.gsm = ioremap_wc(gtt_bus_addr, gtt_size);
799761
if (!dev_priv->gtt.gsm) {
800762
DRM_ERROR("Failed to map the gtt page table\n");
801-
teardown_scratch_page(dev);
802-
ret = -ENOMEM;
803-
goto err_out;
763+
return -ENOMEM;
804764
}
805765

806-
/* GMADR is the PCI aperture used by SW to access tiled GFX surfaces in a linear fashion. */
807-
DRM_INFO("Memory usable by graphics device = %dM\n", dev_priv->mm.gtt->gtt_total_entries >> 8);
808-
DRM_DEBUG_DRIVER("GMADR size = %ldM\n", dev_priv->gtt.mappable_end >> 20);
809-
DRM_DEBUG_DRIVER("GTT stolen size = %dM\n", dev_priv->mm.gtt->stolen_size >> 20);
766+
ret = setup_scratch_page(dev);
767+
if (ret)
768+
DRM_ERROR("Scratch setup failed\n");
810769

811770
dev_priv->gtt.gtt_clear_range = gen6_ggtt_clear_range;
812771
dev_priv->gtt.gtt_insert_entries = gen6_ggtt_insert_entries;
813772

814-
return 0;
815-
816-
err_out:
817-
kfree(dev_priv->mm.gtt);
818-
if (INTEL_INFO(dev)->gen < 6)
819-
intel_gmch_remove();
820773
return ret;
821774
}
822775

823-
void i915_gem_gtt_fini(struct drm_device *dev)
776+
void gen6_gmch_remove(struct drm_device *dev)
824777
{
825778
struct drm_i915_private *dev_priv = dev->dev_private;
826779
iounmap(dev_priv->gtt.gsm);
827-
teardown_scratch_page(dev);
828-
if (INTEL_INFO(dev)->gen < 6)
829-
intel_gmch_remove();
780+
teardown_scratch_page(dev_priv->dev);
830781
kfree(dev_priv->mm.gtt);
831782
}
783+
784+
static int i915_gmch_probe(struct drm_device *dev,
785+
size_t *gtt_total,
786+
size_t *stolen)
787+
{
788+
struct drm_i915_private *dev_priv = dev->dev_private;
789+
int ret;
790+
791+
/* This is a temporary hack to make the code cleaner in
792+
* i915_gem_gtt_init. I promise it will go away very shortly. */
793+
kfree(dev_priv->mm.gtt);
794+
795+
ret = intel_gmch_probe(dev_priv->bridge_dev, dev_priv->dev->pdev, NULL);
796+
if (!ret) {
797+
DRM_ERROR("failed to set up gmch\n");
798+
return -EIO;
799+
}
800+
801+
dev_priv->mm.gtt = intel_gtt_get();
802+
if (!dev_priv->mm.gtt) {
803+
DRM_ERROR("Failed to initialize GTT\n");
804+
intel_gmch_remove();
805+
return -ENODEV;
806+
}
807+
808+
dev_priv->gtt.do_idle_maps = needs_idle_maps(dev_priv->dev);
809+
dev_priv->gtt.gtt_clear_range = i915_ggtt_clear_range;
810+
dev_priv->gtt.gtt_insert_entries = i915_ggtt_insert_entries;
811+
812+
return 0;
813+
}
814+
815+
static void i915_gmch_remove(struct drm_device *dev)
816+
{
817+
intel_gmch_remove();
818+
}
819+
820+
int i915_gem_gtt_init(struct drm_device *dev)
821+
{
822+
struct drm_i915_private *dev_priv = dev->dev_private;
823+
struct i915_gtt *gtt = &dev_priv->gtt;
824+
unsigned long gtt_size;
825+
int ret;
826+
827+
dev_priv->mm.gtt = kzalloc(sizeof(*dev_priv->mm.gtt), GFP_KERNEL);
828+
if (!dev_priv->mm.gtt)
829+
return -ENOMEM;
830+
831+
gtt->mappable_base = pci_resource_start(dev->pdev, 2);
832+
gtt->mappable_end = pci_resource_len(dev->pdev, 2);
833+
834+
if (INTEL_INFO(dev)->gen <= 5) {
835+
dev_priv->gtt.gtt_probe = i915_gmch_probe;
836+
dev_priv->gtt.gtt_remove = i915_gmch_remove;
837+
} else {
838+
dev_priv->gtt.gtt_probe = gen6_gmch_probe;
839+
dev_priv->gtt.gtt_remove = gen6_gmch_remove;
840+
}
841+
842+
ret = dev_priv->gtt.gtt_probe(dev, &dev_priv->gtt.total,
843+
&dev_priv->gtt.stolen_size);
844+
if (ret) {
845+
kfree(dev_priv->mm.gtt);
846+
return ret;
847+
}
848+
849+
dev_priv->mm.gtt->gtt_total_entries = dev_priv->gtt.total >> PAGE_SHIFT;
850+
dev_priv->mm.gtt->stolen_size = dev_priv->gtt.stolen_size;
851+
852+
gtt_size = (dev_priv->gtt.total >> PAGE_SHIFT) * sizeof(gtt_pte_t);
853+
854+
/* GMADR is the PCI mmio aperture into the global GTT. */
855+
DRM_INFO("Memory usable by graphics device = %zdM\n",
856+
dev_priv->gtt.total >> 20);
857+
DRM_DEBUG_DRIVER("GMADR size = %ldM\n",
858+
dev_priv->gtt.mappable_end >> 20);
859+
DRM_DEBUG_DRIVER("GTT stolen size = %zdM\n",
860+
dev_priv->gtt.stolen_size >> 20);
861+
862+
return 0;
863+
}

0 commit comments

Comments
 (0)