2 * Dynamic DMA mapping support for AMD Hammer.
4 * Use the integrated AGP GART in the Hammer northbridge as an IOMMU for PCI.
5 * This allows to use PCI devices that only support 32bit addresses on systems
8 * See Documentation/PCI/PCI-DMA-mapping.txt for the interface specification.
10 * Copyright 2002 Andi Kleen, SuSE Labs.
11 * Subject to the GNU General Public License v2 only.
14 #include <linux/types.h>
15 #include <linux/ctype.h>
16 #include <linux/agp_backend.h>
17 #include <linux/init.h>
19 #include <linux/sched.h>
20 #include <linux/string.h>
21 #include <linux/spinlock.h>
22 #include <linux/pci.h>
23 #include <linux/module.h>
24 #include <linux/topology.h>
25 #include <linux/interrupt.h>
26 #include <linux/bitops.h>
27 #include <linux/kdebug.h>
28 #include <linux/scatterlist.h>
29 #include <linux/iommu-helper.h>
30 #include <linux/sysdev.h>
32 #include <asm/atomic.h>
34 #include <asm/pgtable.h>
35 #include <asm/proto.h>
36 #include <asm/iommu.h>
38 #include <asm/cacheflush.h>
39 #include <asm/swiotlb.h>
42 #include <asm/x86_init.h>
44 static unsigned long iommu_bus_base
; /* GART remapping area (physical) */
45 static unsigned long iommu_size
; /* size of remapping area bytes */
46 static unsigned long iommu_pages
; /* .. and in pages */
48 static u32
*iommu_gatt_base
; /* Remapping table */
50 static dma_addr_t bad_dma_addr
;
53 * If this is disabled the IOMMU will use an optimized flushing strategy
54 * of only flushing when an mapping is reused. With it true the GART is
55 * flushed for every mapping. Problem is that doing the lazy flush seems
56 * to trigger bugs with some popular PCI cards, in particular 3ware (but
57 * has been also also seen with Qlogic at least).
59 static int iommu_fullflush
= 1;
61 /* Allocation bitmap for the remapping area: */
62 static DEFINE_SPINLOCK(iommu_bitmap_lock
);
63 /* Guarded by iommu_bitmap_lock: */
64 static unsigned long *iommu_gart_bitmap
;
66 static u32 gart_unmapped_entry
;
69 #define GPTE_COHERENT 2
70 #define GPTE_ENCODE(x) \
71 (((x) & 0xfffff000) | (((x) >> 32) << 4) | GPTE_VALID | GPTE_COHERENT)
72 #define GPTE_DECODE(x) (((x) & 0xfffff000) | (((u64)(x) & 0xff0) << 28))
74 #define EMERGENCY_PAGES 32 /* = 128KB */
77 #define AGPEXTERN extern
82 /* backdoor interface to AGP driver */
83 AGPEXTERN
int agp_memory_reserved
;
84 AGPEXTERN __u32
*agp_gatt_table
;
86 static unsigned long next_bit
; /* protected by iommu_bitmap_lock */
87 static bool need_flush
; /* global flush state. set for each gart wrap */
89 static unsigned long alloc_iommu(struct device
*dev
, int size
,
90 unsigned long align_mask
)
92 unsigned long offset
, flags
;
93 unsigned long boundary_size
;
94 unsigned long base_index
;
96 base_index
= ALIGN(iommu_bus_base
& dma_get_seg_boundary(dev
),
97 PAGE_SIZE
) >> PAGE_SHIFT
;
98 boundary_size
= ALIGN((u64
)dma_get_seg_boundary(dev
) + 1,
99 PAGE_SIZE
) >> PAGE_SHIFT
;
101 spin_lock_irqsave(&iommu_bitmap_lock
, flags
);
102 offset
= iommu_area_alloc(iommu_gart_bitmap
, iommu_pages
, next_bit
,
103 size
, base_index
, boundary_size
, align_mask
);
106 offset
= iommu_area_alloc(iommu_gart_bitmap
, iommu_pages
, 0,
107 size
, base_index
, boundary_size
,
111 next_bit
= offset
+size
;
112 if (next_bit
>= iommu_pages
) {
119 spin_unlock_irqrestore(&iommu_bitmap_lock
, flags
);
124 static void free_iommu(unsigned long offset
, int size
)
128 spin_lock_irqsave(&iommu_bitmap_lock
, flags
);
129 iommu_area_free(iommu_gart_bitmap
, offset
, size
);
130 if (offset
>= next_bit
)
131 next_bit
= offset
+ size
;
132 spin_unlock_irqrestore(&iommu_bitmap_lock
, flags
);
136 * Use global flush state to avoid races with multiple flushers.
138 static void flush_gart(void)
142 spin_lock_irqsave(&iommu_bitmap_lock
, flags
);
147 spin_unlock_irqrestore(&iommu_bitmap_lock
, flags
);
150 #ifdef CONFIG_IOMMU_LEAK
151 /* Debugging aid for drivers that don't free their IOMMU tables */
152 static int leak_trace
;
153 static int iommu_leak_pages
= 20;
155 static void dump_leak(void)
163 show_stack(NULL
, NULL
);
164 debug_dma_dump_mappings(NULL
);
168 static void iommu_full(struct device
*dev
, size_t size
, int dir
)
171 * Ran out of IOMMU space for this operation. This is very bad.
172 * Unfortunately the drivers cannot handle this operation properly.
173 * Return some non mapped prereserved space in the aperture and
174 * let the Northbridge deal with it. This will result in garbage
175 * in the IO operation. When the size exceeds the prereserved space
176 * memory corruption will occur or random memory will be DMAed
177 * out. Hopefully no network devices use single mappings that big.
180 dev_err(dev
, "PCI-DMA: Out of IOMMU space for %lu bytes\n", size
);
182 if (size
> PAGE_SIZE
*EMERGENCY_PAGES
) {
183 if (dir
== PCI_DMA_FROMDEVICE
|| dir
== PCI_DMA_BIDIRECTIONAL
)
184 panic("PCI-DMA: Memory would be corrupted\n");
185 if (dir
== PCI_DMA_TODEVICE
|| dir
== PCI_DMA_BIDIRECTIONAL
)
187 "PCI-DMA: Random memory would be DMAed\n");
189 #ifdef CONFIG_IOMMU_LEAK
195 need_iommu(struct device
*dev
, unsigned long addr
, size_t size
)
197 return force_iommu
|| !dma_capable(dev
, addr
, size
);
201 nonforced_iommu(struct device
*dev
, unsigned long addr
, size_t size
)
203 return !dma_capable(dev
, addr
, size
);
206 /* Map a single continuous physical area into the IOMMU.
207 * Caller needs to check if the iommu is needed and flush.
209 static dma_addr_t
dma_map_area(struct device
*dev
, dma_addr_t phys_mem
,
210 size_t size
, int dir
, unsigned long align_mask
)
212 unsigned long npages
= iommu_num_pages(phys_mem
, size
, PAGE_SIZE
);
213 unsigned long iommu_page
= alloc_iommu(dev
, npages
, align_mask
);
216 if (iommu_page
== -1) {
217 if (!nonforced_iommu(dev
, phys_mem
, size
))
219 if (panic_on_overflow
)
220 panic("dma_map_area overflow %lu bytes\n", size
);
221 iommu_full(dev
, size
, dir
);
225 for (i
= 0; i
< npages
; i
++) {
226 iommu_gatt_base
[iommu_page
+ i
] = GPTE_ENCODE(phys_mem
);
227 phys_mem
+= PAGE_SIZE
;
229 return iommu_bus_base
+ iommu_page
*PAGE_SIZE
+ (phys_mem
& ~PAGE_MASK
);
232 /* Map a single area into the IOMMU */
233 static dma_addr_t
gart_map_page(struct device
*dev
, struct page
*page
,
234 unsigned long offset
, size_t size
,
235 enum dma_data_direction dir
,
236 struct dma_attrs
*attrs
)
239 phys_addr_t paddr
= page_to_phys(page
) + offset
;
242 dev
= &x86_dma_fallback_dev
;
244 if (!need_iommu(dev
, paddr
, size
))
247 bus
= dma_map_area(dev
, paddr
, size
, dir
, 0);
254 * Free a DMA mapping.
256 static void gart_unmap_page(struct device
*dev
, dma_addr_t dma_addr
,
257 size_t size
, enum dma_data_direction dir
,
258 struct dma_attrs
*attrs
)
260 unsigned long iommu_page
;
264 if (dma_addr
< iommu_bus_base
+ EMERGENCY_PAGES
*PAGE_SIZE
||
265 dma_addr
>= iommu_bus_base
+ iommu_size
)
268 iommu_page
= (dma_addr
- iommu_bus_base
)>>PAGE_SHIFT
;
269 npages
= iommu_num_pages(dma_addr
, size
, PAGE_SIZE
);
270 for (i
= 0; i
< npages
; i
++) {
271 iommu_gatt_base
[iommu_page
+ i
] = gart_unmapped_entry
;
273 free_iommu(iommu_page
, npages
);
277 * Wrapper for pci_unmap_single working with scatterlists.
279 static void gart_unmap_sg(struct device
*dev
, struct scatterlist
*sg
, int nents
,
280 enum dma_data_direction dir
, struct dma_attrs
*attrs
)
282 struct scatterlist
*s
;
285 for_each_sg(sg
, s
, nents
, i
) {
286 if (!s
->dma_length
|| !s
->length
)
288 gart_unmap_page(dev
, s
->dma_address
, s
->dma_length
, dir
, NULL
);
292 /* Fallback for dma_map_sg in case of overflow */
293 static int dma_map_sg_nonforce(struct device
*dev
, struct scatterlist
*sg
,
296 struct scatterlist
*s
;
299 #ifdef CONFIG_IOMMU_DEBUG
300 pr_debug("dma_map_sg overflow\n");
303 for_each_sg(sg
, s
, nents
, i
) {
304 unsigned long addr
= sg_phys(s
);
306 if (nonforced_iommu(dev
, addr
, s
->length
)) {
307 addr
= dma_map_area(dev
, addr
, s
->length
, dir
, 0);
308 if (addr
== bad_dma_addr
) {
310 gart_unmap_sg(dev
, sg
, i
, dir
, NULL
);
312 sg
[0].dma_length
= 0;
316 s
->dma_address
= addr
;
317 s
->dma_length
= s
->length
;
324 /* Map multiple scatterlist entries continuous into the first. */
325 static int __dma_map_cont(struct device
*dev
, struct scatterlist
*start
,
326 int nelems
, struct scatterlist
*sout
,
329 unsigned long iommu_start
= alloc_iommu(dev
, pages
, 0);
330 unsigned long iommu_page
= iommu_start
;
331 struct scatterlist
*s
;
334 if (iommu_start
== -1)
337 for_each_sg(start
, s
, nelems
, i
) {
338 unsigned long pages
, addr
;
339 unsigned long phys_addr
= s
->dma_address
;
341 BUG_ON(s
!= start
&& s
->offset
);
343 sout
->dma_address
= iommu_bus_base
;
344 sout
->dma_address
+= iommu_page
*PAGE_SIZE
+ s
->offset
;
345 sout
->dma_length
= s
->length
;
347 sout
->dma_length
+= s
->length
;
351 pages
= iommu_num_pages(s
->offset
, s
->length
, PAGE_SIZE
);
353 iommu_gatt_base
[iommu_page
] = GPTE_ENCODE(addr
);
358 BUG_ON(iommu_page
- iommu_start
!= pages
);
364 dma_map_cont(struct device
*dev
, struct scatterlist
*start
, int nelems
,
365 struct scatterlist
*sout
, unsigned long pages
, int need
)
369 sout
->dma_address
= start
->dma_address
;
370 sout
->dma_length
= start
->length
;
373 return __dma_map_cont(dev
, start
, nelems
, sout
, pages
);
377 * DMA map all entries in a scatterlist.
378 * Merge chunks that have page aligned sizes into a continuous mapping.
380 static int gart_map_sg(struct device
*dev
, struct scatterlist
*sg
, int nents
,
381 enum dma_data_direction dir
, struct dma_attrs
*attrs
)
383 struct scatterlist
*s
, *ps
, *start_sg
, *sgmap
;
384 int need
= 0, nextneed
, i
, out
, start
;
385 unsigned long pages
= 0;
386 unsigned int seg_size
;
387 unsigned int max_seg_size
;
393 dev
= &x86_dma_fallback_dev
;
400 max_seg_size
= dma_get_max_seg_size(dev
);
401 ps
= NULL
; /* shut up gcc */
403 for_each_sg(sg
, s
, nents
, i
) {
404 dma_addr_t addr
= sg_phys(s
);
406 s
->dma_address
= addr
;
407 BUG_ON(s
->length
== 0);
409 nextneed
= need_iommu(dev
, addr
, s
->length
);
411 /* Handle the previous not yet processed entries */
414 * Can only merge when the last chunk ends on a
415 * page boundary and the new one doesn't have an
418 if (!iommu_merge
|| !nextneed
|| !need
|| s
->offset
||
419 (s
->length
+ seg_size
> max_seg_size
) ||
420 (ps
->offset
+ ps
->length
) % PAGE_SIZE
) {
421 if (dma_map_cont(dev
, start_sg
, i
- start
,
422 sgmap
, pages
, need
) < 0)
427 sgmap
= sg_next(sgmap
);
434 seg_size
+= s
->length
;
436 pages
+= iommu_num_pages(s
->offset
, s
->length
, PAGE_SIZE
);
439 if (dma_map_cont(dev
, start_sg
, i
- start
, sgmap
, pages
, need
) < 0)
444 sgmap
= sg_next(sgmap
);
445 sgmap
->dma_length
= 0;
451 gart_unmap_sg(dev
, sg
, out
, dir
, NULL
);
453 /* When it was forced or merged try again in a dumb way */
454 if (force_iommu
|| iommu_merge
) {
455 out
= dma_map_sg_nonforce(dev
, sg
, nents
, dir
);
459 if (panic_on_overflow
)
460 panic("dma_map_sg: overflow on %lu pages\n", pages
);
462 iommu_full(dev
, pages
<< PAGE_SHIFT
, dir
);
463 for_each_sg(sg
, s
, nents
, i
)
464 s
->dma_address
= bad_dma_addr
;
468 /* allocate and map a coherent mapping */
470 gart_alloc_coherent(struct device
*dev
, size_t size
, dma_addr_t
*dma_addr
,
474 unsigned long align_mask
;
477 if (force_iommu
&& !(flag
& GFP_DMA
)) {
478 flag
&= ~(__GFP_DMA
| __GFP_HIGHMEM
| __GFP_DMA32
);
479 page
= alloc_pages(flag
| __GFP_ZERO
, get_order(size
));
483 align_mask
= (1UL << get_order(size
)) - 1;
484 paddr
= dma_map_area(dev
, page_to_phys(page
), size
,
485 DMA_BIDIRECTIONAL
, align_mask
);
488 if (paddr
!= bad_dma_addr
) {
490 return page_address(page
);
492 __free_pages(page
, get_order(size
));
494 return dma_generic_alloc_coherent(dev
, size
, dma_addr
, flag
);
499 /* free a coherent mapping */
501 gart_free_coherent(struct device
*dev
, size_t size
, void *vaddr
,
504 gart_unmap_page(dev
, dma_addr
, size
, DMA_BIDIRECTIONAL
, NULL
);
505 free_pages((unsigned long)vaddr
, get_order(size
));
508 static int gart_mapping_error(struct device
*dev
, dma_addr_t dma_addr
)
510 return (dma_addr
== bad_dma_addr
);
515 static __init
unsigned long check_iommu_size(unsigned long aper
, u64 aper_size
)
520 iommu_size
= aper_size
;
525 a
= aper
+ iommu_size
;
526 iommu_size
-= round_up(a
, PMD_PAGE_SIZE
) - a
;
528 if (iommu_size
< 64*1024*1024) {
530 "PCI-DMA: Warning: Small IOMMU %luMB."
531 " Consider increasing the AGP aperture in BIOS\n",
538 static __init
unsigned read_aperture(struct pci_dev
*dev
, u32
*size
)
540 unsigned aper_size
= 0, aper_base_32
, aper_order
;
543 pci_read_config_dword(dev
, AMD64_GARTAPERTUREBASE
, &aper_base_32
);
544 pci_read_config_dword(dev
, AMD64_GARTAPERTURECTL
, &aper_order
);
545 aper_order
= (aper_order
>> 1) & 7;
547 aper_base
= aper_base_32
& 0x7fff;
550 aper_size
= (32 * 1024 * 1024) << aper_order
;
551 if (aper_base
+ aper_size
> 0x100000000UL
|| !aper_size
)
558 static void enable_gart_translations(void)
562 for (i
= 0; i
< num_k8_northbridges
; i
++) {
563 struct pci_dev
*dev
= k8_northbridges
[i
];
565 enable_gart_translation(dev
, __pa(agp_gatt_table
));
570 * If fix_up_north_bridges is set, the north bridges have to be fixed up on
571 * resume in the same way as they are handled in gart_iommu_hole_init().
573 static bool fix_up_north_bridges
;
574 static u32 aperture_order
;
575 static u32 aperture_alloc
;
577 void set_up_gart_resume(u32 aper_order
, u32 aper_alloc
)
579 fix_up_north_bridges
= true;
580 aperture_order
= aper_order
;
581 aperture_alloc
= aper_alloc
;
584 static void gart_fixup_northbridges(struct sys_device
*dev
)
588 if (!fix_up_north_bridges
)
591 pr_info("PCI-DMA: Restoring GART aperture settings\n");
593 for (i
= 0; i
< num_k8_northbridges
; i
++) {
594 struct pci_dev
*dev
= k8_northbridges
[i
];
597 * Don't enable translations just yet. That is the next
598 * step. Restore the pre-suspend aperture settings.
600 pci_write_config_dword(dev
, AMD64_GARTAPERTURECTL
, aperture_order
<< 1);
601 pci_write_config_dword(dev
, AMD64_GARTAPERTUREBASE
, aperture_alloc
>> 25);
605 static int gart_resume(struct sys_device
*dev
)
607 pr_info("PCI-DMA: Resuming GART IOMMU\n");
609 gart_fixup_northbridges(dev
);
611 enable_gart_translations();
616 static int gart_suspend(struct sys_device
*dev
, pm_message_t state
)
621 static struct sysdev_class gart_sysdev_class
= {
623 .suspend
= gart_suspend
,
624 .resume
= gart_resume
,
628 static struct sys_device device_gart
= {
629 .cls
= &gart_sysdev_class
,
633 * Private Northbridge GATT initialization in case we cannot use the
634 * AGP driver for some reason.
636 static __init
int init_k8_gatt(struct agp_kern_info
*info
)
638 unsigned aper_size
, gatt_size
, new_aper_size
;
639 unsigned aper_base
, new_aper_base
;
644 pr_info("PCI-DMA: Disabling AGP.\n");
646 aper_size
= aper_base
= info
->aper_size
= 0;
648 for (i
= 0; i
< num_k8_northbridges
; i
++) {
649 dev
= k8_northbridges
[i
];
650 new_aper_base
= read_aperture(dev
, &new_aper_size
);
655 aper_size
= new_aper_size
;
656 aper_base
= new_aper_base
;
658 if (aper_size
!= new_aper_size
|| aper_base
!= new_aper_base
)
664 info
->aper_base
= aper_base
;
665 info
->aper_size
= aper_size
>> 20;
667 gatt_size
= (aper_size
>> PAGE_SHIFT
) * sizeof(u32
);
668 gatt
= (void *)__get_free_pages(GFP_KERNEL
| __GFP_ZERO
,
669 get_order(gatt_size
));
671 panic("Cannot allocate GATT table");
672 if (set_memory_uc((unsigned long)gatt
, gatt_size
>> PAGE_SHIFT
))
673 panic("Could not set GART PTEs to uncacheable pages");
675 agp_gatt_table
= gatt
;
677 error
= sysdev_class_register(&gart_sysdev_class
);
679 error
= sysdev_register(&device_gart
);
681 panic("Could not register gart_sysdev -- "
682 "would corrupt data on next suspend");
686 pr_info("PCI-DMA: aperture base @ %x size %u KB\n",
687 aper_base
, aper_size
>>10);
692 /* Should not happen anymore */
693 pr_warning("PCI-DMA: More than 4GB of RAM and no IOMMU\n"
694 "falling back to iommu=soft.\n");
698 static struct dma_map_ops gart_dma_ops
= {
699 .map_sg
= gart_map_sg
,
700 .unmap_sg
= gart_unmap_sg
,
701 .map_page
= gart_map_page
,
702 .unmap_page
= gart_unmap_page
,
703 .alloc_coherent
= gart_alloc_coherent
,
704 .free_coherent
= gart_free_coherent
,
705 .mapping_error
= gart_mapping_error
,
708 static void gart_iommu_shutdown(void)
716 for (i
= 0; i
< num_k8_northbridges
; i
++) {
719 dev
= k8_northbridges
[i
];
720 pci_read_config_dword(dev
, AMD64_GARTAPERTURECTL
, &ctl
);
724 pci_write_config_dword(dev
, AMD64_GARTAPERTURECTL
, ctl
);
728 int __init
gart_iommu_init(void)
730 struct agp_kern_info info
;
731 unsigned long iommu_start
;
732 unsigned long aper_base
, aper_size
;
733 unsigned long start_pfn
, end_pfn
;
734 unsigned long scratch
;
737 if (cache_k8_northbridges() < 0 || num_k8_northbridges
== 0)
740 #ifndef CONFIG_AGP_AMD64
743 /* Makefile puts PCI initialization via subsys_initcall first. */
744 /* Add other K8 AGP bridge drivers here */
746 (agp_amd64_init() < 0) ||
747 (agp_copy_info(agp_bridge
, &info
) < 0);
751 (!force_iommu
&& max_pfn
<= MAX_DMA32_PFN
) ||
752 !gart_iommu_aperture
||
753 (no_agp
&& init_k8_gatt(&info
) < 0)) {
754 if (max_pfn
> MAX_DMA32_PFN
) {
755 pr_warning("More than 4GB of memory but GART IOMMU not available.\n");
756 pr_warning("falling back to iommu=soft.\n");
761 /* need to map that range */
762 aper_size
= info
.aper_size
<< 20;
763 aper_base
= info
.aper_base
;
764 end_pfn
= (aper_base
>>PAGE_SHIFT
) + (aper_size
>>PAGE_SHIFT
);
766 if (end_pfn
> max_low_pfn_mapped
) {
767 start_pfn
= (aper_base
>>PAGE_SHIFT
);
768 init_memory_mapping(start_pfn
<<PAGE_SHIFT
, end_pfn
<<PAGE_SHIFT
);
771 pr_info("PCI-DMA: using GART IOMMU.\n");
772 iommu_size
= check_iommu_size(info
.aper_base
, aper_size
);
773 iommu_pages
= iommu_size
>> PAGE_SHIFT
;
775 iommu_gart_bitmap
= (void *) __get_free_pages(GFP_KERNEL
| __GFP_ZERO
,
776 get_order(iommu_pages
/8));
777 if (!iommu_gart_bitmap
)
778 panic("Cannot allocate iommu bitmap\n");
780 #ifdef CONFIG_IOMMU_LEAK
784 ret
= dma_debug_resize_entries(iommu_pages
);
786 pr_debug("PCI-DMA: Cannot trace all the entries\n");
791 * Out of IOMMU space handling.
792 * Reserve some invalid pages at the beginning of the GART.
794 iommu_area_reserve(iommu_gart_bitmap
, 0, EMERGENCY_PAGES
);
796 pr_info("PCI-DMA: Reserving %luMB of IOMMU area in the AGP aperture\n",
799 agp_memory_reserved
= iommu_size
;
800 iommu_start
= aper_size
- iommu_size
;
801 iommu_bus_base
= info
.aper_base
+ iommu_start
;
802 bad_dma_addr
= iommu_bus_base
;
803 iommu_gatt_base
= agp_gatt_table
+ (iommu_start
>>PAGE_SHIFT
);
806 * Unmap the IOMMU part of the GART. The alias of the page is
807 * always mapped with cache enabled and there is no full cache
808 * coherency across the GART remapping. The unmapping avoids
809 * automatic prefetches from the CPU allocating cache lines in
810 * there. All CPU accesses are done via the direct mapping to
811 * the backing memory. The GART address is only used by PCI
814 set_memory_np((unsigned long)__va(iommu_bus_base
),
815 iommu_size
>> PAGE_SHIFT
);
817 * Tricky. The GART table remaps the physical memory range,
818 * so the CPU wont notice potential aliases and if the memory
819 * is remapped to UC later on, we might surprise the PCI devices
820 * with a stray writeout of a cacheline. So play it sure and
821 * do an explicit, full-scale wbinvd() _after_ having marked all
822 * the pages as Not-Present:
827 * Now all caches are flushed and we can safely enable
828 * GART hardware. Doing it early leaves the possibility
829 * of stale cache entries that can lead to GART PTE
832 enable_gart_translations();
835 * Try to workaround a bug (thanks to BenH):
836 * Set unmapped entries to a scratch page instead of 0.
837 * Any prefetches that hit unmapped entries won't get an bus abort
838 * then. (P2P bridge may be prefetching on DMA reads).
840 scratch
= get_zeroed_page(GFP_KERNEL
);
842 panic("Cannot allocate iommu scratch page");
843 gart_unmapped_entry
= GPTE_ENCODE(__pa(scratch
));
844 for (i
= EMERGENCY_PAGES
; i
< iommu_pages
; i
++)
845 iommu_gatt_base
[i
] = gart_unmapped_entry
;
848 dma_ops
= &gart_dma_ops
;
849 x86_platform
.iommu_shutdown
= gart_iommu_shutdown
;
855 void __init
gart_parse_options(char *p
)
859 #ifdef CONFIG_IOMMU_LEAK
860 if (!strncmp(p
, "leak", 4)) {
865 if (isdigit(*p
) && get_option(&p
, &arg
))
866 iommu_leak_pages
= arg
;
869 if (isdigit(*p
) && get_option(&p
, &arg
))
871 if (!strncmp(p
, "fullflush", 9))
873 if (!strncmp(p
, "nofullflush", 11))
875 if (!strncmp(p
, "noagp", 5))
877 if (!strncmp(p
, "noaperture", 10))
879 /* duplicated from pci-dma.c */
880 if (!strncmp(p
, "force", 5))
881 gart_iommu_aperture_allowed
= 1;
882 if (!strncmp(p
, "allowed", 7))
883 gart_iommu_aperture_allowed
= 1;
884 if (!strncmp(p
, "memaper", 7)) {
885 fallback_aper_force
= 1;
889 if (get_option(&p
, &arg
))
890 fallback_aper_order
= arg
;