Commit baa09f5f authored by Ben Widawsky's avatar Ben Widawsky Committed by Daniel Vetter

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: default avatarBen 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: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 3440d265
...@@ -1665,7 +1665,7 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags) ...@@ -1665,7 +1665,7 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
out_rmmap: out_rmmap:
pci_iounmap(dev->pdev, dev_priv->regs); pci_iounmap(dev->pdev, dev_priv->regs);
put_gmch: put_gmch:
i915_gem_gtt_fini(dev); dev_priv->gtt.gtt_remove(dev);
put_bridge: put_bridge:
pci_dev_put(dev_priv->bridge_dev); pci_dev_put(dev_priv->bridge_dev);
free_priv: free_priv:
......
...@@ -381,6 +381,7 @@ enum i915_cache_level { ...@@ -381,6 +381,7 @@ enum i915_cache_level {
struct i915_gtt { struct i915_gtt {
unsigned long start; /* Start offset of used GTT */ unsigned long start; /* Start offset of used GTT */
size_t total; /* Total size GTT can map */ size_t total; /* Total size GTT can map */
size_t stolen_size; /* Total size of stolen memory */
unsigned long mappable_end; /* End offset that we can CPU map */ unsigned long mappable_end; /* End offset that we can CPU map */
struct io_mapping *mappable; /* Mapping to our CPU mappable region */ struct io_mapping *mappable; /* Mapping to our CPU mappable region */
...@@ -394,6 +395,9 @@ struct i915_gtt { ...@@ -394,6 +395,9 @@ struct i915_gtt {
struct page *scratch_page; struct page *scratch_page;
/* global gtt ops */ /* global gtt ops */
int (*gtt_probe)(struct drm_device *dev, size_t *gtt_total,
size_t *stolen);
void (*gtt_remove)(struct drm_device *dev);
void (*gtt_clear_range)(struct drm_device *dev, void (*gtt_clear_range)(struct drm_device *dev,
unsigned int first_entry, unsigned int first_entry,
unsigned int num_entries); unsigned int num_entries);
...@@ -1689,7 +1693,6 @@ void i915_gem_init_global_gtt(struct drm_device *dev); ...@@ -1689,7 +1693,6 @@ void i915_gem_init_global_gtt(struct drm_device *dev);
void i915_gem_setup_global_gtt(struct drm_device *dev, unsigned long start, void i915_gem_setup_global_gtt(struct drm_device *dev, unsigned long start,
unsigned long mappable_end, unsigned long end); unsigned long mappable_end, unsigned long end);
int i915_gem_gtt_init(struct drm_device *dev); int i915_gem_gtt_init(struct drm_device *dev);
void i915_gem_gtt_fini(struct drm_device *dev);
static inline void i915_gem_chipset_flush(struct drm_device *dev) static inline void i915_gem_chipset_flush(struct drm_device *dev)
{ {
if (INTEL_INFO(dev)->gen < 6) if (INTEL_INFO(dev)->gen < 6)
......
...@@ -707,14 +707,14 @@ static inline unsigned int gen6_get_total_gtt_size(u16 snb_gmch_ctl) ...@@ -707,14 +707,14 @@ static inline unsigned int gen6_get_total_gtt_size(u16 snb_gmch_ctl)
return snb_gmch_ctl << 20; return snb_gmch_ctl << 20;
} }
static inline unsigned int gen6_get_stolen_size(u16 snb_gmch_ctl) static inline size_t gen6_get_stolen_size(u16 snb_gmch_ctl)
{ {
snb_gmch_ctl >>= SNB_GMCH_GMS_SHIFT; snb_gmch_ctl >>= SNB_GMCH_GMS_SHIFT;
snb_gmch_ctl &= SNB_GMCH_GMS_MASK; snb_gmch_ctl &= SNB_GMCH_GMS_MASK;
return snb_gmch_ctl << 25; /* 32 MB units */ return snb_gmch_ctl << 25; /* 32 MB units */
} }
static inline unsigned int gen7_get_stolen_size(u16 snb_gmch_ctl) static inline size_t gen7_get_stolen_size(u16 snb_gmch_ctl)
{ {
static const int stolen_decoder[] = { static const int stolen_decoder[] = {
0, 0, 0, 0, 0, 32, 48, 64, 128, 256, 96, 160, 224, 352}; 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) ...@@ -723,109 +723,141 @@ static inline unsigned int gen7_get_stolen_size(u16 snb_gmch_ctl)
return stolen_decoder[snb_gmch_ctl] << 20; return stolen_decoder[snb_gmch_ctl] << 20;
} }
int i915_gem_gtt_init(struct drm_device *dev) static int gen6_gmch_probe(struct drm_device *dev,
size_t *gtt_total,
size_t *stolen)
{ {
struct drm_i915_private *dev_priv = dev->dev_private; struct drm_i915_private *dev_priv = dev->dev_private;
phys_addr_t gtt_bus_addr; phys_addr_t gtt_bus_addr;
unsigned int gtt_size;
u16 snb_gmch_ctl; u16 snb_gmch_ctl;
int ret; int ret;
dev_priv->gtt.mappable_base = pci_resource_start(dev->pdev, 2); /* 64/512MB is the current min/max we actually know of, but this is just
dev_priv->gtt.mappable_end = pci_resource_len(dev->pdev, 2); * a coarse sanity check.
/* On modern platforms we need not worry ourself with the legacy
* hostbridge query stuff. Skip it entirely
*/ */
if (INTEL_INFO(dev)->gen < 6) { if ((dev_priv->gtt.mappable_end < (64<<20) ||
ret = intel_gmch_probe(dev_priv->bridge_dev, dev->pdev, NULL); (dev_priv->gtt.mappable_end > (512<<20)))) {
if (!ret) { DRM_ERROR("Unknown GMADR size (%lx)\n",
DRM_ERROR("failed to set up gmch\n"); dev_priv->gtt.mappable_end);
return -EIO; return -ENXIO;
}
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);
dev_priv->gtt.gtt_clear_range = i915_ggtt_clear_range;
dev_priv->gtt.gtt_insert_entries = i915_ggtt_insert_entries;
return 0;
} }
if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(40))) if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(40)))
pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(40)); pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(40));
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);
/* i9xx_setup */
pci_read_config_word(dev->pdev, SNB_GMCH_CTRL, &snb_gmch_ctl); pci_read_config_word(dev->pdev, SNB_GMCH_CTRL, &snb_gmch_ctl);
dev_priv->mm.gtt->gtt_total_entries = gtt_size = gen6_get_total_gtt_size(snb_gmch_ctl);
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
dev_priv->mm.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 if (IS_GEN7(dev))
* coarse sanity check. *stolen = gen7_get_stolen_size(snb_gmch_ctl);
*/ else
if ((dev_priv->gtt.mappable_end < (64<<20) || *stolen = gen6_get_stolen_size(snb_gmch_ctl);
(dev_priv->gtt.mappable_end > (512<<20)))) {
DRM_ERROR("Unknown GMADR size (%lx)\n",
dev_priv->gtt.mappable_end);
ret = -ENXIO;
goto err_out;
}
ret = setup_scratch_page(dev); *gtt_total = (gtt_size / sizeof(gtt_pte_t)) << PAGE_SHIFT;
if (ret) {
DRM_ERROR("Scratch setup failed\n");
goto err_out;
}
dev_priv->gtt.gsm = ioremap_wc(gtt_bus_addr, /* For GEN6+ the PTEs for the ggtt live at 2MB + BAR0 */
dev_priv->mm.gtt->gtt_total_entries * sizeof(gtt_pte_t)); gtt_bus_addr = pci_resource_start(dev->pdev, 0) + (2<<20);
dev_priv->gtt.gsm = ioremap_wc(gtt_bus_addr, gtt_size);
if (!dev_priv->gtt.gsm) { if (!dev_priv->gtt.gsm) {
DRM_ERROR("Failed to map the gtt page table\n"); DRM_ERROR("Failed to map the gtt page table\n");
teardown_scratch_page(dev); return -ENOMEM;
ret = -ENOMEM;
goto err_out;
} }
/* GMADR is the PCI aperture used by SW to access tiled GFX surfaces in a linear fashion. */ ret = setup_scratch_page(dev);
DRM_INFO("Memory usable by graphics device = %dM\n", dev_priv->mm.gtt->gtt_total_entries >> 8); if (ret)
DRM_DEBUG_DRIVER("GMADR size = %ldM\n", dev_priv->gtt.mappable_end >> 20); DRM_ERROR("Scratch setup failed\n");
DRM_DEBUG_DRIVER("GTT stolen size = %dM\n", dev_priv->mm.gtt->stolen_size >> 20);
dev_priv->gtt.gtt_clear_range = gen6_ggtt_clear_range; dev_priv->gtt.gtt_clear_range = gen6_ggtt_clear_range;
dev_priv->gtt.gtt_insert_entries = gen6_ggtt_insert_entries; dev_priv->gtt.gtt_insert_entries = gen6_ggtt_insert_entries;
return 0;
err_out:
kfree(dev_priv->mm.gtt);
if (INTEL_INFO(dev)->gen < 6)
intel_gmch_remove();
return ret; return ret;
} }
void i915_gem_gtt_fini(struct drm_device *dev) void gen6_gmch_remove(struct drm_device *dev)
{ {
struct drm_i915_private *dev_priv = dev->dev_private; struct drm_i915_private *dev_priv = dev->dev_private;
iounmap(dev_priv->gtt.gsm); iounmap(dev_priv->gtt.gsm);
teardown_scratch_page(dev); teardown_scratch_page(dev_priv->dev);
if (INTEL_INFO(dev)->gen < 6)
intel_gmch_remove();
kfree(dev_priv->mm.gtt); kfree(dev_priv->mm.gtt);
} }
static int i915_gmch_probe(struct drm_device *dev,
size_t *gtt_total,
size_t *stolen)
{
struct drm_i915_private *dev_priv = dev->dev_private;
int ret;
/* This is a temporary hack to make the code cleaner in
* i915_gem_gtt_init. I promise it will go away very shortly. */
kfree(dev_priv->mm.gtt);
ret = intel_gmch_probe(dev_priv->bridge_dev, dev_priv->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_priv->dev);
dev_priv->gtt.gtt_clear_range = i915_ggtt_clear_range;
dev_priv->gtt.gtt_insert_entries = i915_ggtt_insert_entries;
return 0;
}
static void i915_gmch_remove(struct drm_device *dev)
{
intel_gmch_remove();
}
int i915_gem_gtt_init(struct drm_device *dev)
{
struct drm_i915_private *dev_priv = dev->dev_private;
struct i915_gtt *gtt = &dev_priv->gtt;
unsigned long gtt_size;
int ret;
dev_priv->mm.gtt = kzalloc(sizeof(*dev_priv->mm.gtt), GFP_KERNEL);
if (!dev_priv->mm.gtt)
return -ENOMEM;
gtt->mappable_base = pci_resource_start(dev->pdev, 2);
gtt->mappable_end = pci_resource_len(dev->pdev, 2);
if (INTEL_INFO(dev)->gen <= 5) {
dev_priv->gtt.gtt_probe = i915_gmch_probe;
dev_priv->gtt.gtt_remove = i915_gmch_remove;
} else {
dev_priv->gtt.gtt_probe = gen6_gmch_probe;
dev_priv->gtt.gtt_remove = gen6_gmch_remove;
}
ret = dev_priv->gtt.gtt_probe(dev, &dev_priv->gtt.total,
&dev_priv->gtt.stolen_size);
if (ret) {
kfree(dev_priv->mm.gtt);
return ret;
}
dev_priv->mm.gtt->gtt_total_entries = dev_priv->gtt.total >> PAGE_SHIFT;
dev_priv->mm.gtt->stolen_size = dev_priv->gtt.stolen_size;
gtt_size = (dev_priv->gtt.total >> PAGE_SHIFT) * sizeof(gtt_pte_t);
/* GMADR is the PCI mmio aperture into the global GTT. */
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 = %zdM\n",
dev_priv->gtt.stolen_size >> 20);
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment