Commit c114f76a authored by Mika Kuoppala's avatar Mika Kuoppala Committed by Daniel Vetter

drm/i915/gtt: Make scratch page i915_page_dma compatible

Lay out scratch page structure in similar manner than other
paging structures. This allows us to use the same tools for
setup and teardown.
Signed-off-by: default avatarMika Kuoppala <mika.kuoppala@intel.com>
Reviewed-by: default avatarMichel Thierry <michel.thierry@intel.com>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 567047be
...@@ -301,11 +301,12 @@ static gen6_pte_t iris_pte_encode(dma_addr_t addr, ...@@ -301,11 +301,12 @@ static gen6_pte_t iris_pte_encode(dma_addr_t addr,
return pte; return pte;
} }
static int setup_page_dma(struct drm_device *dev, struct i915_page_dma *p) static int __setup_page_dma(struct drm_device *dev,
struct i915_page_dma *p, gfp_t flags)
{ {
struct device *device = &dev->pdev->dev; struct device *device = &dev->pdev->dev;
p->page = alloc_page(GFP_KERNEL); p->page = alloc_page(flags);
if (!p->page) if (!p->page)
return -ENOMEM; return -ENOMEM;
...@@ -320,6 +321,11 @@ static int setup_page_dma(struct drm_device *dev, struct i915_page_dma *p) ...@@ -320,6 +321,11 @@ static int setup_page_dma(struct drm_device *dev, struct i915_page_dma *p)
return 0; return 0;
} }
static int setup_page_dma(struct drm_device *dev, struct i915_page_dma *p)
{
return __setup_page_dma(dev, p, GFP_KERNEL);
}
static void cleanup_page_dma(struct drm_device *dev, struct i915_page_dma *p) static void cleanup_page_dma(struct drm_device *dev, struct i915_page_dma *p)
{ {
if (WARN_ON(!p->page)) if (WARN_ON(!p->page))
...@@ -391,7 +397,8 @@ static void gen8_initialize_pt(struct i915_address_space *vm, ...@@ -391,7 +397,8 @@ static void gen8_initialize_pt(struct i915_address_space *vm,
{ {
gen8_pte_t scratch_pte; gen8_pte_t scratch_pte;
scratch_pte = gen8_pte_encode(vm->scratch.addr, I915_CACHE_LLC, true); scratch_pte = gen8_pte_encode(px_dma(vm->scratch_page),
I915_CACHE_LLC, true);
fill_px(vm->dev, pt, scratch_pte); fill_px(vm->dev, pt, scratch_pte);
} }
...@@ -519,7 +526,7 @@ static void gen8_ppgtt_clear_range(struct i915_address_space *vm, ...@@ -519,7 +526,7 @@ static void gen8_ppgtt_clear_range(struct i915_address_space *vm,
unsigned num_entries = length >> PAGE_SHIFT; unsigned num_entries = length >> PAGE_SHIFT;
unsigned last_pte, i; unsigned last_pte, i;
scratch_pte = gen8_pte_encode(ppgtt->base.scratch.addr, scratch_pte = gen8_pte_encode(px_dma(ppgtt->base.scratch_page),
I915_CACHE_LLC, use_scratch); I915_CACHE_LLC, use_scratch);
while (num_entries) { while (num_entries) {
...@@ -983,7 +990,7 @@ static void gen6_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m) ...@@ -983,7 +990,7 @@ static void gen6_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m)
uint32_t pte, pde, temp; uint32_t pte, pde, temp;
uint32_t start = ppgtt->base.start, length = ppgtt->base.total; uint32_t start = ppgtt->base.start, length = ppgtt->base.total;
scratch_pte = vm->pte_encode(vm->scratch.addr, I915_CACHE_LLC, true, 0); scratch_pte = vm->pte_encode(px_dma(vm->scratch_page), I915_CACHE_LLC, true, 0);
gen6_for_each_pde(unused, &ppgtt->pd, start, length, temp, pde) { gen6_for_each_pde(unused, &ppgtt->pd, start, length, temp, pde) {
u32 expected; u32 expected;
...@@ -1222,7 +1229,8 @@ static void gen6_ppgtt_clear_range(struct i915_address_space *vm, ...@@ -1222,7 +1229,8 @@ static void gen6_ppgtt_clear_range(struct i915_address_space *vm,
unsigned first_pte = first_entry % GEN6_PTES; unsigned first_pte = first_entry % GEN6_PTES;
unsigned last_pte, i; unsigned last_pte, i;
scratch_pte = vm->pte_encode(vm->scratch.addr, I915_CACHE_LLC, true, 0); scratch_pte = vm->pte_encode(px_dma(vm->scratch_page),
I915_CACHE_LLC, true, 0);
while (num_entries) { while (num_entries) {
last_pte = first_pte + num_entries; last_pte = first_pte + num_entries;
...@@ -1280,9 +1288,10 @@ static void gen6_initialize_pt(struct i915_address_space *vm, ...@@ -1280,9 +1288,10 @@ static void gen6_initialize_pt(struct i915_address_space *vm,
{ {
gen6_pte_t scratch_pte; gen6_pte_t scratch_pte;
WARN_ON(vm->scratch.addr == 0); WARN_ON(px_dma(vm->scratch_page) == 0);
scratch_pte = vm->pte_encode(vm->scratch.addr, I915_CACHE_LLC, true, 0); scratch_pte = vm->pte_encode(px_dma(vm->scratch_page),
I915_CACHE_LLC, true, 0);
fill32_px(vm->dev, pt, scratch_pte); fill32_px(vm->dev, pt, scratch_pte);
} }
...@@ -1519,13 +1528,14 @@ static int __hw_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt) ...@@ -1519,13 +1528,14 @@ static int __hw_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
struct drm_i915_private *dev_priv = dev->dev_private; struct drm_i915_private *dev_priv = dev->dev_private;
ppgtt->base.dev = dev; ppgtt->base.dev = dev;
ppgtt->base.scratch = dev_priv->gtt.base.scratch; ppgtt->base.scratch_page = dev_priv->gtt.base.scratch_page;
if (INTEL_INFO(dev)->gen < 8) if (INTEL_INFO(dev)->gen < 8)
return gen6_ppgtt_init(ppgtt); return gen6_ppgtt_init(ppgtt);
else else
return gen8_ppgtt_init(ppgtt); return gen8_ppgtt_init(ppgtt);
} }
int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt) int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
{ {
struct drm_i915_private *dev_priv = dev->dev_private; struct drm_i915_private *dev_priv = dev->dev_private;
...@@ -1842,7 +1852,7 @@ static void gen8_ggtt_clear_range(struct i915_address_space *vm, ...@@ -1842,7 +1852,7 @@ static void gen8_ggtt_clear_range(struct i915_address_space *vm,
first_entry, num_entries, max_entries)) first_entry, num_entries, max_entries))
num_entries = max_entries; num_entries = max_entries;
scratch_pte = gen8_pte_encode(vm->scratch.addr, scratch_pte = gen8_pte_encode(px_dma(vm->scratch_page),
I915_CACHE_LLC, I915_CACHE_LLC,
use_scratch); use_scratch);
for (i = 0; i < num_entries; i++) for (i = 0; i < num_entries; i++)
...@@ -1868,7 +1878,8 @@ static void gen6_ggtt_clear_range(struct i915_address_space *vm, ...@@ -1868,7 +1878,8 @@ static void gen6_ggtt_clear_range(struct i915_address_space *vm,
first_entry, num_entries, max_entries)) first_entry, num_entries, max_entries))
num_entries = max_entries; num_entries = max_entries;
scratch_pte = vm->pte_encode(vm->scratch.addr, I915_CACHE_LLC, use_scratch, 0); scratch_pte = vm->pte_encode(px_dma(vm->scratch_page),
I915_CACHE_LLC, use_scratch, 0);
for (i = 0; i < num_entries; i++) for (i = 0; i < num_entries; i++)
iowrite32(scratch_pte, &gtt_base[i]); iowrite32(scratch_pte, &gtt_base[i]);
...@@ -2125,42 +2136,40 @@ void i915_global_gtt_cleanup(struct drm_device *dev) ...@@ -2125,42 +2136,40 @@ void i915_global_gtt_cleanup(struct drm_device *dev)
vm->cleanup(vm); vm->cleanup(vm);
} }
static int setup_scratch_page(struct drm_device *dev) static int alloc_scratch_page(struct i915_address_space *vm)
{ {
struct drm_i915_private *dev_priv = dev->dev_private; struct i915_page_scratch *sp;
struct page *page; int ret;
dma_addr_t dma_addr;
WARN_ON(vm->scratch_page);
page = alloc_page(GFP_KERNEL | GFP_DMA32 | __GFP_ZERO); sp = kzalloc(sizeof(*sp), GFP_KERNEL);
if (page == NULL) if (sp == NULL)
return -ENOMEM; return -ENOMEM;
set_pages_uc(page, 1);
#ifdef CONFIG_INTEL_IOMMU ret = __setup_page_dma(vm->dev, px_base(sp), GFP_DMA32 | __GFP_ZERO);
dma_addr = pci_map_page(dev->pdev, page, 0, PAGE_SIZE, if (ret) {
PCI_DMA_BIDIRECTIONAL); kfree(sp);
if (pci_dma_mapping_error(dev->pdev, dma_addr)) { return ret;
__free_page(page);
return -EINVAL;
} }
#else
dma_addr = page_to_phys(page); set_pages_uc(px_page(sp), 1);
#endif
dev_priv->gtt.base.scratch.page = page; vm->scratch_page = sp;
dev_priv->gtt.base.scratch.addr = dma_addr;
return 0; return 0;
} }
static void teardown_scratch_page(struct drm_device *dev) static void free_scratch_page(struct i915_address_space *vm)
{ {
struct drm_i915_private *dev_priv = dev->dev_private; struct i915_page_scratch *sp = vm->scratch_page;
struct page *page = dev_priv->gtt.base.scratch.page;
set_pages_wb(page, 1); set_pages_wb(px_page(sp), 1);
pci_unmap_page(dev->pdev, dev_priv->gtt.base.scratch.addr,
PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); cleanup_px(vm->dev, sp);
__free_page(page); kfree(sp);
vm->scratch_page = NULL;
} }
static unsigned int gen6_get_total_gtt_size(u16 snb_gmch_ctl) static unsigned int gen6_get_total_gtt_size(u16 snb_gmch_ctl)
...@@ -2268,7 +2277,7 @@ static int ggtt_probe_common(struct drm_device *dev, ...@@ -2268,7 +2277,7 @@ static int ggtt_probe_common(struct drm_device *dev,
return -ENOMEM; return -ENOMEM;
} }
ret = setup_scratch_page(dev); ret = alloc_scratch_page(&dev_priv->gtt.base);
if (ret) { if (ret) {
DRM_ERROR("Scratch setup failed\n"); DRM_ERROR("Scratch setup failed\n");
/* iounmap will also get called at remove, but meh */ /* iounmap will also get called at remove, but meh */
...@@ -2447,7 +2456,7 @@ static void gen6_gmch_remove(struct i915_address_space *vm) ...@@ -2447,7 +2456,7 @@ static void gen6_gmch_remove(struct i915_address_space *vm)
struct i915_gtt *gtt = container_of(vm, struct i915_gtt, base); struct i915_gtt *gtt = container_of(vm, struct i915_gtt, base);
iounmap(gtt->gsm); iounmap(gtt->gsm);
teardown_scratch_page(vm->dev); free_scratch_page(vm);
} }
static int i915_gmch_probe(struct drm_device *dev, static int i915_gmch_probe(struct drm_device *dev,
...@@ -2511,13 +2520,13 @@ int i915_gem_gtt_init(struct drm_device *dev) ...@@ -2511,13 +2520,13 @@ int i915_gem_gtt_init(struct drm_device *dev)
dev_priv->gtt.base.cleanup = gen6_gmch_remove; dev_priv->gtt.base.cleanup = gen6_gmch_remove;
} }
gtt->base.dev = dev;
ret = gtt->gtt_probe(dev, &gtt->base.total, &gtt->stolen_size, ret = gtt->gtt_probe(dev, &gtt->base.total, &gtt->stolen_size,
&gtt->mappable_base, &gtt->mappable_end); &gtt->mappable_base, &gtt->mappable_end);
if (ret) if (ret)
return ret; return ret;
gtt->base.dev = dev;
/* GMADR is the PCI mmio aperture into the global GTT. */ /* GMADR is the PCI mmio aperture into the global GTT. */
DRM_INFO("Memory usable by graphics device = %lluM\n", DRM_INFO("Memory usable by graphics device = %lluM\n",
gtt->base.total >> 20); gtt->base.total >> 20);
......
...@@ -223,6 +223,10 @@ struct i915_page_dma { ...@@ -223,6 +223,10 @@ struct i915_page_dma {
#define px_page(px) (px_base(px)->page) #define px_page(px) (px_base(px)->page)
#define px_dma(px) (px_base(px)->daddr) #define px_dma(px) (px_base(px)->daddr)
struct i915_page_scratch {
struct i915_page_dma base;
};
struct i915_page_table { struct i915_page_table {
struct i915_page_dma base; struct i915_page_dma base;
...@@ -249,10 +253,7 @@ struct i915_address_space { ...@@ -249,10 +253,7 @@ struct i915_address_space {
u64 start; /* Start offset always 0 for dri2 */ u64 start; /* Start offset always 0 for dri2 */
u64 total; /* size addr space maps (ex. 2GB for ggtt) */ u64 total; /* size addr space maps (ex. 2GB for ggtt) */
struct { struct i915_page_scratch *scratch_page;
dma_addr_t addr;
struct page *page;
} scratch;
/** /**
* List of objects currently involved in rendering. * List of objects currently involved in rendering.
......
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