blob: b13ba9d53b19a9012b7e18ab43edbb085ba47793 [file] [log] [blame]
Daniel Vetter76aaf222010-11-05 22:23:30 +01001/*
2 * Copyright © 2010 Daniel Vetter
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 */
24
David Howells760285e2012-10-02 18:01:07 +010025#include <drm/drmP.h>
26#include <drm/i915_drm.h>
Daniel Vetter76aaf222010-11-05 22:23:30 +010027#include "i915_drv.h"
28#include "i915_trace.h"
29#include "intel_drv.h"
30
Ben Widawskye7c2b582013-04-08 18:43:48 -070031typedef uint32_t gen6_gtt_pte_t;
Ben Widawskyf61c0602012-10-22 11:44:43 -070032
Ben Widawsky26b1ff32012-11-04 09:21:31 -080033/* PPGTT stuff */
34#define GEN6_GTT_ADDR_ENCODE(addr) ((addr) | (((addr) >> 28) & 0xff0))
35
36#define GEN6_PDE_VALID (1 << 0)
37/* gen6+ has bit 11-4 for physical addr bit 39-32 */
38#define GEN6_PDE_ADDR_ENCODE(addr) GEN6_GTT_ADDR_ENCODE(addr)
39
40#define GEN6_PTE_VALID (1 << 0)
41#define GEN6_PTE_UNCACHED (1 << 1)
42#define HSW_PTE_UNCACHED (0)
43#define GEN6_PTE_CACHE_LLC (2 << 1)
44#define GEN6_PTE_CACHE_LLC_MLC (3 << 1)
45#define GEN6_PTE_ADDR_ENCODE(addr) GEN6_GTT_ADDR_ENCODE(addr)
46
Ben Widawskye7c2b582013-04-08 18:43:48 -070047static inline gen6_gtt_pte_t gen6_pte_encode(struct drm_device *dev,
Ben Widawskyc81dbe02013-04-08 18:43:50 -070048 dma_addr_t addr,
49 enum i915_cache_level level)
Ben Widawsky54d12522012-09-24 16:44:32 -070050{
Ben Widawskye7c2b582013-04-08 18:43:48 -070051 gen6_gtt_pte_t pte = GEN6_PTE_VALID;
Ben Widawsky54d12522012-09-24 16:44:32 -070052 pte |= GEN6_PTE_ADDR_ENCODE(addr);
Ben Widawskye7210c32012-10-19 09:33:22 -070053
54 switch (level) {
55 case I915_CACHE_LLC_MLC:
56 /* Haswell doesn't set L3 this way */
57 if (IS_HASWELL(dev))
58 pte |= GEN6_PTE_CACHE_LLC;
59 else
60 pte |= GEN6_PTE_CACHE_LLC_MLC;
61 break;
62 case I915_CACHE_LLC:
63 pte |= GEN6_PTE_CACHE_LLC;
64 break;
65 case I915_CACHE_NONE:
66 if (IS_HASWELL(dev))
67 pte |= HSW_PTE_UNCACHED;
68 else
69 pte |= GEN6_PTE_UNCACHED;
70 break;
71 default:
72 BUG();
73 }
74
Ben Widawsky54d12522012-09-24 16:44:32 -070075 return pte;
76}
77
Daniel Vetter1d2a3142012-02-09 17:15:46 +010078/* PPGTT support for Sandybdrige/Gen6 and later */
Daniel Vetterdef886c2013-01-24 14:44:56 -080079static void gen6_ppgtt_clear_range(struct i915_hw_ppgtt *ppgtt,
Daniel Vetter1d2a3142012-02-09 17:15:46 +010080 unsigned first_entry,
81 unsigned num_entries)
82{
Ben Widawskye7c2b582013-04-08 18:43:48 -070083 gen6_gtt_pte_t *pt_vaddr, scratch_pte;
Daniel Vettera15326a2013-03-19 23:48:39 +010084 unsigned act_pt = first_entry / I915_PPGTT_PT_ENTRIES;
Daniel Vetter7bddb012012-02-09 17:15:47 +010085 unsigned first_pte = first_entry % I915_PPGTT_PT_ENTRIES;
86 unsigned last_pte, i;
Daniel Vetter1d2a3142012-02-09 17:15:46 +010087
Daniel Vetter960e3e42013-01-24 14:44:57 -080088 scratch_pte = gen6_pte_encode(ppgtt->dev,
89 ppgtt->scratch_page_dma_addr,
90 I915_CACHE_LLC);
Daniel Vetter1d2a3142012-02-09 17:15:46 +010091
Daniel Vetter7bddb012012-02-09 17:15:47 +010092 while (num_entries) {
93 last_pte = first_pte + num_entries;
94 if (last_pte > I915_PPGTT_PT_ENTRIES)
95 last_pte = I915_PPGTT_PT_ENTRIES;
Daniel Vetter1d2a3142012-02-09 17:15:46 +010096
Daniel Vettera15326a2013-03-19 23:48:39 +010097 pt_vaddr = kmap_atomic(ppgtt->pt_pages[act_pt]);
Daniel Vetter7bddb012012-02-09 17:15:47 +010098
99 for (i = first_pte; i < last_pte; i++)
100 pt_vaddr[i] = scratch_pte;
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100101
102 kunmap_atomic(pt_vaddr);
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100103
Daniel Vetter7bddb012012-02-09 17:15:47 +0100104 num_entries -= last_pte - first_pte;
105 first_pte = 0;
Daniel Vettera15326a2013-03-19 23:48:39 +0100106 act_pt++;
Daniel Vetter7bddb012012-02-09 17:15:47 +0100107 }
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100108}
109
Daniel Vetterdef886c2013-01-24 14:44:56 -0800110static void gen6_ppgtt_insert_entries(struct i915_hw_ppgtt *ppgtt,
111 struct sg_table *pages,
112 unsigned first_entry,
113 enum i915_cache_level cache_level)
114{
Ben Widawskye7c2b582013-04-08 18:43:48 -0700115 gen6_gtt_pte_t *pt_vaddr;
Daniel Vettera15326a2013-03-19 23:48:39 +0100116 unsigned act_pt = first_entry / I915_PPGTT_PT_ENTRIES;
Imre Deak6e995e22013-02-18 19:28:04 +0200117 unsigned act_pte = first_entry % I915_PPGTT_PT_ENTRIES;
118 struct sg_page_iter sg_iter;
Daniel Vetterdef886c2013-01-24 14:44:56 -0800119
Daniel Vettera15326a2013-03-19 23:48:39 +0100120 pt_vaddr = kmap_atomic(ppgtt->pt_pages[act_pt]);
Imre Deak6e995e22013-02-18 19:28:04 +0200121 for_each_sg_page(pages->sgl, &sg_iter, pages->nents, 0) {
122 dma_addr_t page_addr;
Daniel Vetterdef886c2013-01-24 14:44:56 -0800123
Imre Deak2db76d72013-03-26 15:14:18 +0200124 page_addr = sg_page_iter_dma_address(&sg_iter);
Imre Deak6e995e22013-02-18 19:28:04 +0200125 pt_vaddr[act_pte] = gen6_pte_encode(ppgtt->dev, page_addr,
Daniel Vetter6ddc4fc2013-03-19 23:37:08 +0100126 cache_level);
Imre Deak6e995e22013-02-18 19:28:04 +0200127 if (++act_pte == I915_PPGTT_PT_ENTRIES) {
128 kunmap_atomic(pt_vaddr);
Daniel Vettera15326a2013-03-19 23:48:39 +0100129 act_pt++;
130 pt_vaddr = kmap_atomic(ppgtt->pt_pages[act_pt]);
Imre Deak6e995e22013-02-18 19:28:04 +0200131 act_pte = 0;
Daniel Vetterdef886c2013-01-24 14:44:56 -0800132
Daniel Vetterdef886c2013-01-24 14:44:56 -0800133 }
Daniel Vetterdef886c2013-01-24 14:44:56 -0800134 }
Imre Deak6e995e22013-02-18 19:28:04 +0200135 kunmap_atomic(pt_vaddr);
Daniel Vetterdef886c2013-01-24 14:44:56 -0800136}
137
Daniel Vetter3440d262013-01-24 13:49:56 -0800138static void gen6_ppgtt_cleanup(struct i915_hw_ppgtt *ppgtt)
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100139{
Daniel Vetter3440d262013-01-24 13:49:56 -0800140 int i;
141
142 if (ppgtt->pt_dma_addr) {
143 for (i = 0; i < ppgtt->num_pd_entries; i++)
144 pci_unmap_page(ppgtt->dev->pdev,
145 ppgtt->pt_dma_addr[i],
146 4096, PCI_DMA_BIDIRECTIONAL);
147 }
148
149 kfree(ppgtt->pt_dma_addr);
150 for (i = 0; i < ppgtt->num_pd_entries; i++)
151 __free_page(ppgtt->pt_pages[i]);
152 kfree(ppgtt->pt_pages);
153 kfree(ppgtt);
154}
155
156static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
157{
158 struct drm_device *dev = ppgtt->dev;
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100159 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100160 unsigned first_pd_entry_in_global_pt;
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100161 int i;
162 int ret = -ENOMEM;
163
164 /* ppgtt PDEs reside in the global gtt pagetable, which has 512*1024
165 * entries. For aliasing ppgtt support we just steal them at the end for
166 * now. */
Ben Widawskya54c0c22013-01-24 14:45:00 -0800167 first_pd_entry_in_global_pt =
168 gtt_total_entries(dev_priv->gtt) - I915_PPGTT_PD_ENTRIES;
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100169
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100170 ppgtt->num_pd_entries = I915_PPGTT_PD_ENTRIES;
Daniel Vetterdef886c2013-01-24 14:44:56 -0800171 ppgtt->clear_range = gen6_ppgtt_clear_range;
172 ppgtt->insert_entries = gen6_ppgtt_insert_entries;
Daniel Vetter3440d262013-01-24 13:49:56 -0800173 ppgtt->cleanup = gen6_ppgtt_cleanup;
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100174 ppgtt->pt_pages = kzalloc(sizeof(struct page *)*ppgtt->num_pd_entries,
175 GFP_KERNEL);
176 if (!ppgtt->pt_pages)
Daniel Vetter3440d262013-01-24 13:49:56 -0800177 return -ENOMEM;
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100178
179 for (i = 0; i < ppgtt->num_pd_entries; i++) {
180 ppgtt->pt_pages[i] = alloc_page(GFP_KERNEL);
181 if (!ppgtt->pt_pages[i])
182 goto err_pt_alloc;
183 }
184
Ben Widawsky8d2e6302013-01-18 12:30:33 -0800185 ppgtt->pt_dma_addr = kzalloc(sizeof(dma_addr_t) *ppgtt->num_pd_entries,
186 GFP_KERNEL);
187 if (!ppgtt->pt_dma_addr)
188 goto err_pt_alloc;
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100189
Ben Widawsky8d2e6302013-01-18 12:30:33 -0800190 for (i = 0; i < ppgtt->num_pd_entries; i++) {
191 dma_addr_t pt_addr;
Daniel Vetter211c5682012-04-10 17:29:17 +0200192
Ben Widawsky8d2e6302013-01-18 12:30:33 -0800193 pt_addr = pci_map_page(dev->pdev, ppgtt->pt_pages[i], 0, 4096,
194 PCI_DMA_BIDIRECTIONAL);
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100195
Ben Widawsky8d2e6302013-01-18 12:30:33 -0800196 if (pci_dma_mapping_error(dev->pdev, pt_addr)) {
197 ret = -EIO;
198 goto err_pd_pin;
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100199
Daniel Vetter211c5682012-04-10 17:29:17 +0200200 }
Ben Widawsky8d2e6302013-01-18 12:30:33 -0800201 ppgtt->pt_dma_addr[i] = pt_addr;
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100202 }
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100203
Daniel Vetterdef886c2013-01-24 14:44:56 -0800204 ppgtt->clear_range(ppgtt, 0,
205 ppgtt->num_pd_entries*I915_PPGTT_PT_ENTRIES);
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100206
Ben Widawskye7c2b582013-04-08 18:43:48 -0700207 ppgtt->pd_offset = first_pd_entry_in_global_pt * sizeof(gen6_gtt_pte_t);
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100208
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100209 return 0;
210
211err_pd_pin:
212 if (ppgtt->pt_dma_addr) {
213 for (i--; i >= 0; i--)
214 pci_unmap_page(dev->pdev, ppgtt->pt_dma_addr[i],
215 4096, PCI_DMA_BIDIRECTIONAL);
216 }
217err_pt_alloc:
218 kfree(ppgtt->pt_dma_addr);
219 for (i = 0; i < ppgtt->num_pd_entries; i++) {
220 if (ppgtt->pt_pages[i])
221 __free_page(ppgtt->pt_pages[i]);
222 }
223 kfree(ppgtt->pt_pages);
Daniel Vetter3440d262013-01-24 13:49:56 -0800224
225 return ret;
226}
227
228static int i915_gem_init_aliasing_ppgtt(struct drm_device *dev)
229{
230 struct drm_i915_private *dev_priv = dev->dev_private;
231 struct i915_hw_ppgtt *ppgtt;
232 int ret;
233
234 ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL);
235 if (!ppgtt)
236 return -ENOMEM;
237
238 ppgtt->dev = dev;
Ben Widawsky1e7d12d2013-04-08 18:43:51 -0700239 ppgtt->scratch_page_dma_addr = dev_priv->gtt.scratch_page_dma;
Daniel Vetter3440d262013-01-24 13:49:56 -0800240
Ben Widawsky3ed124b2013-04-08 18:43:53 -0700241 if (INTEL_INFO(dev)->gen < 8)
242 ret = gen6_ppgtt_init(ppgtt);
243 else
244 BUG();
245
Daniel Vetter3440d262013-01-24 13:49:56 -0800246 if (ret)
247 kfree(ppgtt);
248 else
249 dev_priv->mm.aliasing_ppgtt = ppgtt;
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100250
251 return ret;
252}
253
254void i915_gem_cleanup_aliasing_ppgtt(struct drm_device *dev)
255{
256 struct drm_i915_private *dev_priv = dev->dev_private;
257 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100258
259 if (!ppgtt)
260 return;
261
Daniel Vetter3440d262013-01-24 13:49:56 -0800262 ppgtt->cleanup(ppgtt);
Daniel Vetter1d2a3142012-02-09 17:15:46 +0100263}
264
Daniel Vetter7bddb012012-02-09 17:15:47 +0100265void i915_ppgtt_bind_object(struct i915_hw_ppgtt *ppgtt,
266 struct drm_i915_gem_object *obj,
267 enum i915_cache_level cache_level)
268{
Daniel Vetterdef886c2013-01-24 14:44:56 -0800269 ppgtt->insert_entries(ppgtt, obj->pages,
270 obj->gtt_space->start >> PAGE_SHIFT,
271 cache_level);
Daniel Vetter7bddb012012-02-09 17:15:47 +0100272}
273
274void i915_ppgtt_unbind_object(struct i915_hw_ppgtt *ppgtt,
275 struct drm_i915_gem_object *obj)
276{
Daniel Vetterdef886c2013-01-24 14:44:56 -0800277 ppgtt->clear_range(ppgtt,
278 obj->gtt_space->start >> PAGE_SHIFT,
279 obj->base.size >> PAGE_SHIFT);
Daniel Vetter7bddb012012-02-09 17:15:47 +0100280}
281
Ben Widawsky26b1ff32012-11-04 09:21:31 -0800282void i915_gem_init_ppgtt(struct drm_device *dev)
283{
284 drm_i915_private_t *dev_priv = dev->dev_private;
285 uint32_t pd_offset;
286 struct intel_ring_buffer *ring;
287 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Ben Widawskye7c2b582013-04-08 18:43:48 -0700288 gen6_gtt_pte_t __iomem *pd_addr;
Ben Widawsky26b1ff32012-11-04 09:21:31 -0800289 uint32_t pd_entry;
290 int i;
291
292 if (!dev_priv->mm.aliasing_ppgtt)
293 return;
294
Ben Widawskye7c2b582013-04-08 18:43:48 -0700295 pd_addr = (gen6_gtt_pte_t __iomem *)dev_priv->gtt.gsm +
296 ppgtt->pd_offset / sizeof(gen6_gtt_pte_t);
Ben Widawsky26b1ff32012-11-04 09:21:31 -0800297 for (i = 0; i < ppgtt->num_pd_entries; i++) {
298 dma_addr_t pt_addr;
299
Ben Widawsky8d2e6302013-01-18 12:30:33 -0800300 pt_addr = ppgtt->pt_dma_addr[i];
Ben Widawsky26b1ff32012-11-04 09:21:31 -0800301 pd_entry = GEN6_PDE_ADDR_ENCODE(pt_addr);
302 pd_entry |= GEN6_PDE_VALID;
303
304 writel(pd_entry, pd_addr + i);
305 }
306 readl(pd_addr);
307
308 pd_offset = ppgtt->pd_offset;
309 pd_offset /= 64; /* in cachelines, */
310 pd_offset <<= 16;
311
312 if (INTEL_INFO(dev)->gen == 6) {
313 uint32_t ecochk, gab_ctl, ecobits;
314
315 ecobits = I915_READ(GAC_ECO_BITS);
316 I915_WRITE(GAC_ECO_BITS, ecobits | ECOBITS_PPGTT_CACHE64B);
317
318 gab_ctl = I915_READ(GAB_CTL);
319 I915_WRITE(GAB_CTL, gab_ctl | GAB_CTL_CONT_AFTER_PAGEFAULT);
320
321 ecochk = I915_READ(GAM_ECOCHK);
322 I915_WRITE(GAM_ECOCHK, ecochk | ECOCHK_SNB_BIT |
323 ECOCHK_PPGTT_CACHE64B);
324 I915_WRITE(GFX_MODE, _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE));
325 } else if (INTEL_INFO(dev)->gen >= 7) {
326 I915_WRITE(GAM_ECOCHK, ECOCHK_PPGTT_CACHE64B);
327 /* GFX_MODE is per-ring on gen7+ */
328 }
329
330 for_each_ring(ring, dev_priv, i) {
331 if (INTEL_INFO(dev)->gen >= 7)
332 I915_WRITE(RING_MODE_GEN7(ring),
333 _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE));
334
335 I915_WRITE(RING_PP_DIR_DCLV(ring), PP_DIR_DCLV_2G);
336 I915_WRITE(RING_PP_DIR_BASE(ring), pd_offset);
337 }
338}
339
Ben Widawskya81cc002013-01-18 12:30:31 -0800340extern int intel_iommu_gfx_mapped;
341/* Certain Gen5 chipsets require require idling the GPU before
342 * unmapping anything from the GTT when VT-d is enabled.
343 */
344static inline bool needs_idle_maps(struct drm_device *dev)
345{
346#ifdef CONFIG_INTEL_IOMMU
347 /* Query intel_iommu to see if we need the workaround. Presumably that
348 * was loaded first.
349 */
350 if (IS_GEN5(dev) && IS_MOBILE(dev) && intel_iommu_gfx_mapped)
351 return true;
352#endif
353 return false;
354}
355
Ben Widawsky5c042282011-10-17 15:51:55 -0700356static bool do_idling(struct drm_i915_private *dev_priv)
357{
358 bool ret = dev_priv->mm.interruptible;
359
Ben Widawskya81cc002013-01-18 12:30:31 -0800360 if (unlikely(dev_priv->gtt.do_idle_maps)) {
Ben Widawsky5c042282011-10-17 15:51:55 -0700361 dev_priv->mm.interruptible = false;
Ben Widawskyb2da9fe2012-04-26 16:02:58 -0700362 if (i915_gpu_idle(dev_priv->dev)) {
Ben Widawsky5c042282011-10-17 15:51:55 -0700363 DRM_ERROR("Couldn't idle GPU\n");
364 /* Wait a bit, in hopes it avoids the hang */
365 udelay(10);
366 }
367 }
368
369 return ret;
370}
371
372static void undo_idling(struct drm_i915_private *dev_priv, bool interruptible)
373{
Ben Widawskya81cc002013-01-18 12:30:31 -0800374 if (unlikely(dev_priv->gtt.do_idle_maps))
Ben Widawsky5c042282011-10-17 15:51:55 -0700375 dev_priv->mm.interruptible = interruptible;
376}
377
Daniel Vetter76aaf222010-11-05 22:23:30 +0100378void i915_gem_restore_gtt_mappings(struct drm_device *dev)
379{
380 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson05394f32010-11-08 19:18:58 +0000381 struct drm_i915_gem_object *obj;
Daniel Vetter76aaf222010-11-05 22:23:30 +0100382
Chris Wilsonbee4a182011-01-21 10:54:32 +0000383 /* First fill our portion of the GTT with scratch pages */
Daniel Vetter7faf1ab2013-01-24 14:44:55 -0800384 dev_priv->gtt.gtt_clear_range(dev, dev_priv->gtt.start / PAGE_SIZE,
385 dev_priv->gtt.total / PAGE_SIZE);
Chris Wilsonbee4a182011-01-21 10:54:32 +0000386
Chris Wilson6c085a72012-08-20 11:40:46 +0200387 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
Chris Wilsona8e93122010-12-08 14:28:54 +0000388 i915_gem_clflush_object(obj);
Daniel Vetter74163902012-02-15 23:50:21 +0100389 i915_gem_gtt_bind_object(obj, obj->cache_level);
Daniel Vetter76aaf222010-11-05 22:23:30 +0100390 }
391
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800392 i915_gem_chipset_flush(dev);
Daniel Vetter76aaf222010-11-05 22:23:30 +0100393}
Daniel Vetter7c2e6fd2010-11-06 10:10:47 +0100394
Daniel Vetter74163902012-02-15 23:50:21 +0100395int i915_gem_gtt_prepare_object(struct drm_i915_gem_object *obj)
Daniel Vetter7c2e6fd2010-11-06 10:10:47 +0100396{
Chris Wilson9da3da62012-06-01 15:20:22 +0100397 if (obj->has_dma_mapping)
Daniel Vetter74163902012-02-15 23:50:21 +0100398 return 0;
Chris Wilson9da3da62012-06-01 15:20:22 +0100399
400 if (!dma_map_sg(&obj->base.dev->pdev->dev,
401 obj->pages->sgl, obj->pages->nents,
402 PCI_DMA_BIDIRECTIONAL))
403 return -ENOSPC;
404
405 return 0;
Daniel Vetter7c2e6fd2010-11-06 10:10:47 +0100406}
407
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800408/*
409 * Binds an object into the global gtt with the specified cache level. The object
410 * will be accessible to the GPU via commands whose operands reference offsets
411 * within the global GTT as well as accessible by the GPU through the GMADR
412 * mapped BAR (dev_priv->mm.gtt->gtt).
413 */
Daniel Vetter7faf1ab2013-01-24 14:44:55 -0800414static void gen6_ggtt_insert_entries(struct drm_device *dev,
415 struct sg_table *st,
416 unsigned int first_entry,
417 enum i915_cache_level level)
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800418{
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800419 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskye7c2b582013-04-08 18:43:48 -0700420 gen6_gtt_pte_t __iomem *gtt_entries =
421 (gen6_gtt_pte_t __iomem *)dev_priv->gtt.gsm + first_entry;
Imre Deak6e995e22013-02-18 19:28:04 +0200422 int i = 0;
423 struct sg_page_iter sg_iter;
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800424 dma_addr_t addr;
425
Imre Deak6e995e22013-02-18 19:28:04 +0200426 for_each_sg_page(st->sgl, &sg_iter, st->nents, 0) {
Imre Deak2db76d72013-03-26 15:14:18 +0200427 addr = sg_page_iter_dma_address(&sg_iter);
Imre Deak6e995e22013-02-18 19:28:04 +0200428 iowrite32(gen6_pte_encode(dev, addr, level), &gtt_entries[i]);
429 i++;
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800430 }
431
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800432 /* XXX: This serves as a posting read to make sure that the PTE has
433 * actually been updated. There is some concern that even though
434 * registers and PTEs are within the same BAR that they are potentially
435 * of NUMA access patterns. Therefore, even with the way we assume
436 * hardware should work, we must keep this posting read for paranoia.
437 */
438 if (i != 0)
Daniel Vetter960e3e42013-01-24 14:44:57 -0800439 WARN_ON(readl(&gtt_entries[i-1])
440 != gen6_pte_encode(dev, addr, level));
Ben Widawsky0f9b91c2012-11-04 09:21:30 -0800441
442 /* This next bit makes the above posting read even more important. We
443 * want to flush the TLBs only after we're certain all the PTE updates
444 * have finished.
445 */
446 I915_WRITE(GFX_FLSH_CNTL_GEN6, GFX_FLSH_CNTL_EN);
447 POSTING_READ(GFX_FLSH_CNTL_GEN6);
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800448}
449
Daniel Vetter7faf1ab2013-01-24 14:44:55 -0800450static void gen6_ggtt_clear_range(struct drm_device *dev,
451 unsigned int first_entry,
452 unsigned int num_entries)
453{
454 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskye7c2b582013-04-08 18:43:48 -0700455 gen6_gtt_pte_t scratch_pte, __iomem *gtt_base =
456 (gen6_gtt_pte_t __iomem *) dev_priv->gtt.gsm + first_entry;
Ben Widawskya54c0c22013-01-24 14:45:00 -0800457 const int max_entries = gtt_total_entries(dev_priv->gtt) - first_entry;
Daniel Vetter7faf1ab2013-01-24 14:44:55 -0800458 int i;
459
460 if (WARN(num_entries > max_entries,
461 "First entry = %d; Num entries = %d (max=%d)\n",
462 first_entry, num_entries, max_entries))
463 num_entries = max_entries;
464
Daniel Vetter960e3e42013-01-24 14:44:57 -0800465 scratch_pte = gen6_pte_encode(dev, dev_priv->gtt.scratch_page_dma,
466 I915_CACHE_LLC);
Daniel Vetter7faf1ab2013-01-24 14:44:55 -0800467 for (i = 0; i < num_entries; i++)
468 iowrite32(scratch_pte, &gtt_base[i]);
469 readl(gtt_base);
470}
471
472
473static void i915_ggtt_insert_entries(struct drm_device *dev,
474 struct sg_table *st,
475 unsigned int pg_start,
476 enum i915_cache_level cache_level)
477{
478 unsigned int flags = (cache_level == I915_CACHE_NONE) ?
479 AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY;
480
481 intel_gtt_insert_sg_entries(st, pg_start, flags);
482
483}
484
485static void i915_ggtt_clear_range(struct drm_device *dev,
486 unsigned int first_entry,
487 unsigned int num_entries)
488{
489 intel_gtt_clear_range(first_entry, num_entries);
490}
491
492
Daniel Vetter74163902012-02-15 23:50:21 +0100493void i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj,
494 enum i915_cache_level cache_level)
Chris Wilsond5bd1442011-04-14 06:48:26 +0100495{
496 struct drm_device *dev = obj->base.dev;
Daniel Vetter7faf1ab2013-01-24 14:44:55 -0800497 struct drm_i915_private *dev_priv = dev->dev_private;
498
499 dev_priv->gtt.gtt_insert_entries(dev, obj->pages,
500 obj->gtt_space->start >> PAGE_SHIFT,
501 cache_level);
Chris Wilsond5bd1442011-04-14 06:48:26 +0100502
Daniel Vetter74898d72012-02-15 23:50:22 +0100503 obj->has_global_gtt_mapping = 1;
Chris Wilsond5bd1442011-04-14 06:48:26 +0100504}
505
Chris Wilson05394f32010-11-08 19:18:58 +0000506void i915_gem_gtt_unbind_object(struct drm_i915_gem_object *obj)
Daniel Vetter7c2e6fd2010-11-06 10:10:47 +0100507{
Daniel Vetter7faf1ab2013-01-24 14:44:55 -0800508 struct drm_device *dev = obj->base.dev;
509 struct drm_i915_private *dev_priv = dev->dev_private;
510
511 dev_priv->gtt.gtt_clear_range(obj->base.dev,
512 obj->gtt_space->start >> PAGE_SHIFT,
513 obj->base.size >> PAGE_SHIFT);
Daniel Vetter74898d72012-02-15 23:50:22 +0100514
515 obj->has_global_gtt_mapping = 0;
Daniel Vetter74163902012-02-15 23:50:21 +0100516}
517
518void i915_gem_gtt_finish_object(struct drm_i915_gem_object *obj)
519{
Ben Widawsky5c042282011-10-17 15:51:55 -0700520 struct drm_device *dev = obj->base.dev;
521 struct drm_i915_private *dev_priv = dev->dev_private;
522 bool interruptible;
523
524 interruptible = do_idling(dev_priv);
525
Chris Wilson9da3da62012-06-01 15:20:22 +0100526 if (!obj->has_dma_mapping)
527 dma_unmap_sg(&dev->pdev->dev,
528 obj->pages->sgl, obj->pages->nents,
529 PCI_DMA_BIDIRECTIONAL);
Ben Widawsky5c042282011-10-17 15:51:55 -0700530
531 undo_idling(dev_priv, interruptible);
Daniel Vetter7c2e6fd2010-11-06 10:10:47 +0100532}
Daniel Vetter644ec022012-03-26 09:45:40 +0200533
Chris Wilson42d6ab42012-07-26 11:49:32 +0100534static void i915_gtt_color_adjust(struct drm_mm_node *node,
535 unsigned long color,
536 unsigned long *start,
537 unsigned long *end)
538{
539 if (node->color != color)
540 *start += 4096;
541
542 if (!list_empty(&node->node_list)) {
543 node = list_entry(node->node_list.next,
544 struct drm_mm_node,
545 node_list);
546 if (node->allocated && node->color != color)
547 *end -= 4096;
548 }
549}
Ben Widawskyd7e50082012-12-18 10:31:25 -0800550void i915_gem_setup_global_gtt(struct drm_device *dev,
551 unsigned long start,
552 unsigned long mappable_end,
553 unsigned long end)
Daniel Vetter644ec022012-03-26 09:45:40 +0200554{
Ben Widawskye78891c2013-01-25 16:41:04 -0800555 /* Let GEM Manage all of the aperture.
556 *
557 * However, leave one page at the end still bound to the scratch page.
558 * There are a number of places where the hardware apparently prefetches
559 * past the end of the object, and we've seen multiple hangs with the
560 * GPU head pointer stuck in a batchbuffer bound at the last page of the
561 * aperture. One page should be enough to keep any prefetching inside
562 * of the aperture.
563 */
Daniel Vetter644ec022012-03-26 09:45:40 +0200564 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsoned2f3452012-11-15 11:32:19 +0000565 struct drm_mm_node *entry;
566 struct drm_i915_gem_object *obj;
567 unsigned long hole_start, hole_end;
Daniel Vetter644ec022012-03-26 09:45:40 +0200568
Ben Widawsky35451cb2013-01-17 12:45:13 -0800569 BUG_ON(mappable_end > end);
570
Chris Wilsoned2f3452012-11-15 11:32:19 +0000571 /* Subtract the guard page ... */
Daniel Vetterd1dd20a2012-03-26 09:45:42 +0200572 drm_mm_init(&dev_priv->mm.gtt_space, start, end - start - PAGE_SIZE);
Chris Wilson42d6ab42012-07-26 11:49:32 +0100573 if (!HAS_LLC(dev))
574 dev_priv->mm.gtt_space.color_adjust = i915_gtt_color_adjust;
Daniel Vetter644ec022012-03-26 09:45:40 +0200575
Chris Wilsoned2f3452012-11-15 11:32:19 +0000576 /* Mark any preallocated objects as occupied */
577 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
578 DRM_DEBUG_KMS("reserving preallocated space: %x + %zx\n",
579 obj->gtt_offset, obj->base.size);
580
581 BUG_ON(obj->gtt_space != I915_GTT_RESERVED);
582 obj->gtt_space = drm_mm_create_block(&dev_priv->mm.gtt_space,
583 obj->gtt_offset,
584 obj->base.size,
585 false);
586 obj->has_global_gtt_mapping = 1;
587 }
588
Ben Widawsky5d4545a2013-01-17 12:45:15 -0800589 dev_priv->gtt.start = start;
Ben Widawsky5d4545a2013-01-17 12:45:15 -0800590 dev_priv->gtt.total = end - start;
Daniel Vetter644ec022012-03-26 09:45:40 +0200591
Chris Wilsoned2f3452012-11-15 11:32:19 +0000592 /* Clear any non-preallocated blocks */
593 drm_mm_for_each_hole(entry, &dev_priv->mm.gtt_space,
594 hole_start, hole_end) {
595 DRM_DEBUG_KMS("clearing unused GTT space: [%lx, %lx]\n",
596 hole_start, hole_end);
Daniel Vetter7faf1ab2013-01-24 14:44:55 -0800597 dev_priv->gtt.gtt_clear_range(dev, hole_start / PAGE_SIZE,
598 (hole_end-hole_start) / PAGE_SIZE);
Chris Wilsoned2f3452012-11-15 11:32:19 +0000599 }
600
601 /* And finally clear the reserved guard page */
Daniel Vetter7faf1ab2013-01-24 14:44:55 -0800602 dev_priv->gtt.gtt_clear_range(dev, end / PAGE_SIZE - 1, 1);
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800603}
604
Ben Widawskyd7e50082012-12-18 10:31:25 -0800605static bool
606intel_enable_ppgtt(struct drm_device *dev)
607{
608 if (i915_enable_ppgtt >= 0)
609 return i915_enable_ppgtt;
610
611#ifdef CONFIG_INTEL_IOMMU
612 /* Disable ppgtt on SNB if VT-d is on. */
613 if (INTEL_INFO(dev)->gen == 6 && intel_iommu_gfx_mapped)
614 return false;
615#endif
616
617 return true;
618}
619
620void i915_gem_init_global_gtt(struct drm_device *dev)
621{
622 struct drm_i915_private *dev_priv = dev->dev_private;
623 unsigned long gtt_size, mappable_size;
Ben Widawskyd7e50082012-12-18 10:31:25 -0800624
Ben Widawskya54c0c22013-01-24 14:45:00 -0800625 gtt_size = dev_priv->gtt.total;
Ben Widawsky93d18792013-01-17 12:45:17 -0800626 mappable_size = dev_priv->gtt.mappable_end;
Ben Widawskyd7e50082012-12-18 10:31:25 -0800627
628 if (intel_enable_ppgtt(dev) && HAS_ALIASING_PPGTT(dev)) {
Ben Widawskye78891c2013-01-25 16:41:04 -0800629 int ret;
Ben Widawsky3eb1c002013-04-08 18:43:52 -0700630
631 if (INTEL_INFO(dev)->gen <= 7) {
632 /* PPGTT pdes are stolen from global gtt ptes, so shrink the
633 * aperture accordingly when using aliasing ppgtt. */
634 gtt_size -= I915_PPGTT_PD_ENTRIES*PAGE_SIZE;
635 }
Ben Widawskyd7e50082012-12-18 10:31:25 -0800636
637 i915_gem_setup_global_gtt(dev, 0, mappable_size, gtt_size);
638
639 ret = i915_gem_init_aliasing_ppgtt(dev);
Ben Widawskye78891c2013-01-25 16:41:04 -0800640 if (!ret)
Ben Widawskyd7e50082012-12-18 10:31:25 -0800641 return;
Ben Widawskye78891c2013-01-25 16:41:04 -0800642
643 DRM_ERROR("Aliased PPGTT setup failed %d\n", ret);
644 drm_mm_takedown(&dev_priv->mm.gtt_space);
645 gtt_size += I915_PPGTT_PD_ENTRIES*PAGE_SIZE;
Ben Widawskyd7e50082012-12-18 10:31:25 -0800646 }
Ben Widawskye78891c2013-01-25 16:41:04 -0800647 i915_gem_setup_global_gtt(dev, 0, mappable_size, gtt_size);
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800648}
649
650static int setup_scratch_page(struct drm_device *dev)
651{
652 struct drm_i915_private *dev_priv = dev->dev_private;
653 struct page *page;
654 dma_addr_t dma_addr;
655
656 page = alloc_page(GFP_KERNEL | GFP_DMA32 | __GFP_ZERO);
657 if (page == NULL)
658 return -ENOMEM;
659 get_page(page);
660 set_pages_uc(page, 1);
661
662#ifdef CONFIG_INTEL_IOMMU
663 dma_addr = pci_map_page(dev->pdev, page, 0, PAGE_SIZE,
664 PCI_DMA_BIDIRECTIONAL);
665 if (pci_dma_mapping_error(dev->pdev, dma_addr))
666 return -EINVAL;
667#else
668 dma_addr = page_to_phys(page);
669#endif
Ben Widawsky9c61a322013-01-18 12:30:32 -0800670 dev_priv->gtt.scratch_page = page;
671 dev_priv->gtt.scratch_page_dma = dma_addr;
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800672
673 return 0;
674}
675
676static void teardown_scratch_page(struct drm_device *dev)
677{
678 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky9c61a322013-01-18 12:30:32 -0800679 set_pages_wb(dev_priv->gtt.scratch_page, 1);
680 pci_unmap_page(dev->pdev, dev_priv->gtt.scratch_page_dma,
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800681 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
Ben Widawsky9c61a322013-01-18 12:30:32 -0800682 put_page(dev_priv->gtt.scratch_page);
683 __free_page(dev_priv->gtt.scratch_page);
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800684}
685
686static inline unsigned int gen6_get_total_gtt_size(u16 snb_gmch_ctl)
687{
688 snb_gmch_ctl >>= SNB_GMCH_GGMS_SHIFT;
689 snb_gmch_ctl &= SNB_GMCH_GGMS_MASK;
690 return snb_gmch_ctl << 20;
691}
692
Ben Widawskybaa09f52013-01-24 13:49:57 -0800693static inline size_t gen6_get_stolen_size(u16 snb_gmch_ctl)
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800694{
695 snb_gmch_ctl >>= SNB_GMCH_GMS_SHIFT;
696 snb_gmch_ctl &= SNB_GMCH_GMS_MASK;
697 return snb_gmch_ctl << 25; /* 32 MB units */
698}
699
Ben Widawskybaa09f52013-01-24 13:49:57 -0800700static inline size_t gen7_get_stolen_size(u16 snb_gmch_ctl)
Ben Widawsky03752f52012-11-04 09:21:28 -0800701{
702 static const int stolen_decoder[] = {
703 0, 0, 0, 0, 0, 32, 48, 64, 128, 256, 96, 160, 224, 352};
704 snb_gmch_ctl >>= IVB_GMCH_GMS_SHIFT;
705 snb_gmch_ctl &= IVB_GMCH_GMS_MASK;
706 return stolen_decoder[snb_gmch_ctl] << 20;
707}
708
Ben Widawskybaa09f52013-01-24 13:49:57 -0800709static int gen6_gmch_probe(struct drm_device *dev,
710 size_t *gtt_total,
Ben Widawsky41907dd2013-02-08 11:32:47 -0800711 size_t *stolen,
712 phys_addr_t *mappable_base,
713 unsigned long *mappable_end)
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800714{
715 struct drm_i915_private *dev_priv = dev->dev_private;
716 phys_addr_t gtt_bus_addr;
Ben Widawskybaa09f52013-01-24 13:49:57 -0800717 unsigned int gtt_size;
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800718 u16 snb_gmch_ctl;
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800719 int ret;
720
Ben Widawsky41907dd2013-02-08 11:32:47 -0800721 *mappable_base = pci_resource_start(dev->pdev, 2);
722 *mappable_end = pci_resource_len(dev->pdev, 2);
723
Ben Widawskybaa09f52013-01-24 13:49:57 -0800724 /* 64/512MB is the current min/max we actually know of, but this is just
725 * a coarse sanity check.
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800726 */
Ben Widawsky41907dd2013-02-08 11:32:47 -0800727 if ((*mappable_end < (64<<20) || (*mappable_end > (512<<20)))) {
Ben Widawskybaa09f52013-01-24 13:49:57 -0800728 DRM_ERROR("Unknown GMADR size (%lx)\n",
729 dev_priv->gtt.mappable_end);
730 return -ENXIO;
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800731 }
732
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800733 if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(40)))
734 pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(40));
Ben Widawskybaa09f52013-01-24 13:49:57 -0800735 pci_read_config_word(dev->pdev, SNB_GMCH_CTRL, &snb_gmch_ctl);
736 gtt_size = gen6_get_total_gtt_size(snb_gmch_ctl);
737
Jesse Barnes086ddcc2013-03-01 14:08:29 -0800738 if (IS_GEN7(dev) && !IS_VALLEYVIEW(dev))
Ben Widawskybaa09f52013-01-24 13:49:57 -0800739 *stolen = gen7_get_stolen_size(snb_gmch_ctl);
740 else
741 *stolen = gen6_get_stolen_size(snb_gmch_ctl);
742
Ben Widawskye7c2b582013-04-08 18:43:48 -0700743 *gtt_total = (gtt_size / sizeof(gen6_gtt_pte_t)) << PAGE_SHIFT;
Ben Widawskybaa09f52013-01-24 13:49:57 -0800744
Ben Widawskya93e4162013-04-08 18:43:47 -0700745 /* For Modern GENs the PTEs and register space are split in the BAR */
746 gtt_bus_addr = pci_resource_start(dev->pdev, 0) +
747 (pci_resource_len(dev->pdev, 0) / 2);
748
Ben Widawskybaa09f52013-01-24 13:49:57 -0800749 dev_priv->gtt.gsm = ioremap_wc(gtt_bus_addr, gtt_size);
750 if (!dev_priv->gtt.gsm) {
751 DRM_ERROR("Failed to map the gtt page table\n");
752 return -ENOMEM;
753 }
754
755 ret = setup_scratch_page(dev);
756 if (ret)
757 DRM_ERROR("Scratch setup failed\n");
758
759 dev_priv->gtt.gtt_clear_range = gen6_ggtt_clear_range;
760 dev_priv->gtt.gtt_insert_entries = gen6_ggtt_insert_entries;
761
762 return ret;
763}
764
Changlong Xied93c6232013-01-31 11:32:50 +0800765static void gen6_gmch_remove(struct drm_device *dev)
Ben Widawskybaa09f52013-01-24 13:49:57 -0800766{
767 struct drm_i915_private *dev_priv = dev->dev_private;
768 iounmap(dev_priv->gtt.gsm);
769 teardown_scratch_page(dev_priv->dev);
Ben Widawskybaa09f52013-01-24 13:49:57 -0800770}
771
772static int i915_gmch_probe(struct drm_device *dev,
773 size_t *gtt_total,
Ben Widawsky41907dd2013-02-08 11:32:47 -0800774 size_t *stolen,
775 phys_addr_t *mappable_base,
776 unsigned long *mappable_end)
Ben Widawskybaa09f52013-01-24 13:49:57 -0800777{
778 struct drm_i915_private *dev_priv = dev->dev_private;
779 int ret;
780
Ben Widawskybaa09f52013-01-24 13:49:57 -0800781 ret = intel_gmch_probe(dev_priv->bridge_dev, dev_priv->dev->pdev, NULL);
782 if (!ret) {
783 DRM_ERROR("failed to set up gmch\n");
784 return -EIO;
785 }
786
Ben Widawsky41907dd2013-02-08 11:32:47 -0800787 intel_gtt_get(gtt_total, stolen, mappable_base, mappable_end);
Ben Widawskybaa09f52013-01-24 13:49:57 -0800788
789 dev_priv->gtt.do_idle_maps = needs_idle_maps(dev_priv->dev);
790 dev_priv->gtt.gtt_clear_range = i915_ggtt_clear_range;
791 dev_priv->gtt.gtt_insert_entries = i915_ggtt_insert_entries;
792
793 return 0;
794}
795
796static void i915_gmch_remove(struct drm_device *dev)
797{
798 intel_gmch_remove();
799}
800
801int i915_gem_gtt_init(struct drm_device *dev)
802{
803 struct drm_i915_private *dev_priv = dev->dev_private;
804 struct i915_gtt *gtt = &dev_priv->gtt;
805 unsigned long gtt_size;
806 int ret;
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800807
Ben Widawskybaa09f52013-01-24 13:49:57 -0800808 if (INTEL_INFO(dev)->gen <= 5) {
809 dev_priv->gtt.gtt_probe = i915_gmch_probe;
810 dev_priv->gtt.gtt_remove = i915_gmch_remove;
811 } else {
812 dev_priv->gtt.gtt_probe = gen6_gmch_probe;
813 dev_priv->gtt.gtt_remove = gen6_gmch_remove;
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800814 }
815
Ben Widawskybaa09f52013-01-24 13:49:57 -0800816 ret = dev_priv->gtt.gtt_probe(dev, &dev_priv->gtt.total,
Ben Widawsky41907dd2013-02-08 11:32:47 -0800817 &dev_priv->gtt.stolen_size,
818 &gtt->mappable_base,
819 &gtt->mappable_end);
Ben Widawskya54c0c22013-01-24 14:45:00 -0800820 if (ret)
Ben Widawskybaa09f52013-01-24 13:49:57 -0800821 return ret;
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800822
Ben Widawskye7c2b582013-04-08 18:43:48 -0700823 gtt_size = (dev_priv->gtt.total >> PAGE_SHIFT) * sizeof(gen6_gtt_pte_t);
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800824
Ben Widawskybaa09f52013-01-24 13:49:57 -0800825 /* GMADR is the PCI mmio aperture into the global GTT. */
826 DRM_INFO("Memory usable by graphics device = %zdM\n",
827 dev_priv->gtt.total >> 20);
828 DRM_DEBUG_DRIVER("GMADR size = %ldM\n",
829 dev_priv->gtt.mappable_end >> 20);
830 DRM_DEBUG_DRIVER("GTT stolen size = %zdM\n",
831 dev_priv->gtt.stolen_size >> 20);
Daniel Vetter7faf1ab2013-01-24 14:44:55 -0800832
Ben Widawskye76e9ae2012-11-04 09:21:27 -0800833 return 0;
Daniel Vetter644ec022012-03-26 09:45:40 +0200834}