From: Muli Ben-Yehuda Hook Calgary into the build and the x86-64 IOMMU initialization paths. It makes the following changes: - add Kconfig entry for Calgary - add Makefile stanza for Calgary - try to initialize Calgary in pci_iommu_init - parse calgary=xxx boot options in parse_cmdline_early (early because we need them in detect_calgary(), called from setup_arch()) - add Calgary boot options documentation - make sure PCI_UNMAP_ADDR/PCI_UNMAP_LEN are defined properly for Calgary - add prototypes for gart_iommu_init(), no_iommu_init() and detect_calgary() to proto.h This is patch -C1 against 2.6.16-git. Changes from previous version: - remove dependency on MPSC in Kconfig - elaborate in the Kconfig message on Calgary's isolation capabilities - switch the initialization order: first Calgary, then gart Signed-off-by: Muli Ben-Yehuda Signed-off-by: Jon Mason Cc: Andi Kleen Signed-off-by: Andrew Morton --- Documentation/x86_64/boot-options.txt | 21 +++++++++++++++++++++ arch/x86_64/Kconfig | 18 ++++++++++++++++++ arch/x86_64/kernel/Makefile | 1 + arch/x86_64/kernel/pci-dma.c | 19 +++++++++++++++++++ arch/x86_64/kernel/pci-gart.c | 7 ++----- arch/x86_64/kernel/setup.c | 8 ++++++++ include/asm-x86_64/pci.h | 2 +- include/asm-x86_64/proto.h | 4 +++- 8 files changed, 73 insertions(+), 7 deletions(-) diff -puN arch/x86_64/Kconfig~x86-64-calgary-iommu-hook-it-in arch/x86_64/Kconfig --- devel/arch/x86_64/Kconfig~x86-64-calgary-iommu-hook-it-in 2006-04-05 21:28:05.000000000 -0700 +++ devel-akpm/arch/x86_64/Kconfig 2006-04-05 21:28:05.000000000 -0700 @@ -397,6 +397,24 @@ config GART_IOMMU northbridge and a software emulation used on other systems without hardware IOMMU. If unsure, say Y. +config CALGARY_IOMMU + bool "IBM x366 server IOMMU" + default y + depends on PCI && EXPERIMENTAL + help + Support for hardware IOMMUs in IBM's xSeries x366 and x460 + systems. Needed to run systems with more than 3GB of memory + properly with 32-bit PCI devices that do not support DAC + (Double Address Cycle). Calgary also supports bus level + isolation, where all DMAs pass through the IOMMU. This + prevents them from going anywhere except their intended + destination. This catches hard-to-find kernel bugs and + mis-behaving drivers and devices that do not use the DMA-API + properly to set up their DMA buffers. The IOMMU can be + turned off at boot time with the iommu=off parameter. + Normally the kernel will make the right choice by itself. + If unsure, say Y. + # need this always enabled with GART_IOMMU for the VIA workaround config SWIOTLB bool diff -puN arch/x86_64/kernel/Makefile~x86-64-calgary-iommu-hook-it-in arch/x86_64/kernel/Makefile --- devel/arch/x86_64/kernel/Makefile~x86-64-calgary-iommu-hook-it-in 2006-04-05 21:28:05.000000000 -0700 +++ devel-akpm/arch/x86_64/kernel/Makefile 2006-04-05 21:28:05.000000000 -0700 @@ -29,6 +29,7 @@ obj-$(CONFIG_SOFTWARE_SUSPEND) += suspen obj-$(CONFIG_CPU_FREQ) += cpufreq/ obj-$(CONFIG_EARLY_PRINTK) += early_printk.o obj-$(CONFIG_GART_IOMMU) += pci-gart.o aperture.o +obj-$(CONFIG_CALGARY_IOMMU) += pci-calgary.o tce.o obj-$(CONFIG_SWIOTLB) += pci-swiotlb.o obj-$(CONFIG_KPROBES) += kprobes.o obj-$(CONFIG_X86_PM_TIMER) += pmtimer.o diff -puN arch/x86_64/kernel/pci-dma.c~x86-64-calgary-iommu-hook-it-in arch/x86_64/kernel/pci-dma.c --- devel/arch/x86_64/kernel/pci-dma.c~x86-64-calgary-iommu-hook-it-in 2006-04-05 21:28:05.000000000 -0700 +++ devel-akpm/arch/x86_64/kernel/pci-dma.c 2006-04-05 21:28:05.000000000 -0700 @@ -9,6 +9,7 @@ #include #include #include +#include int iommu_merge __read_mostly = 0; EXPORT_SYMBOL(iommu_merge); @@ -275,3 +276,21 @@ __init int iommu_setup(char *p) } return 1; } + +static int __init pci_iommu_init(void) +{ + int rc = 0; + +#ifdef CONFIG_CALGARY_IOMMU + rc = calgary_iommu_init(); + if (!rc) /* success? */ + return 0; +#endif +#ifdef CONFIG_GART_IOMMU + rc = gart_iommu_init(); +#endif + return rc; +} + +/* Must execute after PCI subsystem */ +fs_initcall(pci_iommu_init); diff -puN arch/x86_64/kernel/pci-gart.c~x86-64-calgary-iommu-hook-it-in arch/x86_64/kernel/pci-gart.c --- devel/arch/x86_64/kernel/pci-gart.c~x86-64-calgary-iommu-hook-it-in 2006-04-05 21:28:05.000000000 -0700 +++ devel-akpm/arch/x86_64/kernel/pci-gart.c 2006-04-05 21:28:05.000000000 -0700 @@ -606,7 +606,7 @@ static struct dma_mapping_ops gart_dma_o .unmap_sg = gart_unmap_sg, }; -static int __init pci_iommu_init(void) +int __init gart_iommu_init(void) { struct agp_kern_info info; unsigned long aper_size; @@ -726,10 +726,7 @@ static int __init pci_iommu_init(void) return 0; } -/* Must execute after PCI subsystem */ -fs_initcall(pci_iommu_init); - -void gart_parse_options(char *p) +void __init gart_parse_options(char *p) { int arg; diff -puN arch/x86_64/kernel/setup.c~x86-64-calgary-iommu-hook-it-in arch/x86_64/kernel/setup.c --- devel/arch/x86_64/kernel/setup.c~x86-64-calgary-iommu-hook-it-in 2006-04-05 21:28:05.000000000 -0700 +++ devel-akpm/arch/x86_64/kernel/setup.c 2006-04-05 21:28:05.000000000 -0700 @@ -69,6 +69,7 @@ #include #include #include +#include /* * Machine setup.. @@ -400,6 +401,10 @@ static __init void parse_cmdline_early ( iommu_setup(from+6); } +#ifdef CONFIG_CALGARY_IOMMU + if (!memcmp(from,"calgary=",8)) + calgary_parse_options(from+8); +#endif if (fullarg(from,"oops=panic")) panic_on_oops = 1; @@ -760,6 +765,9 @@ void __init setup_arch(char **cmdline_p) #ifdef CONFIG_GART_IOMMU iommu_hole_init(); #endif +#ifdef CONFIG_CALGARY_IOMMU + detect_calgary(); +#endif #ifdef CONFIG_VT #if defined(CONFIG_VGA_CONSOLE) diff -puN Documentation/x86_64/boot-options.txt~x86-64-calgary-iommu-hook-it-in Documentation/x86_64/boot-options.txt --- devel/Documentation/x86_64/boot-options.txt~x86-64-calgary-iommu-hook-it-in 2006-04-05 21:28:05.000000000 -0700 +++ devel-akpm/Documentation/x86_64/boot-options.txt 2006-04-05 21:28:05.000000000 -0700 @@ -205,6 +205,27 @@ IOMMU pages Prereserve that many 128K pages for the software IO bounce buffering. force Force all IO through the software TLB. + calgary=[64k,128k,256k,512k,1M,2M,4M,8M] + calgary=[translate_empty_slots,translate_phb0] + + 64k,...,8M - Set the size of each PCI slot's translation table + when using the Calgary IOMMU. This is the size of the translation + table itself in main memory. The smallest table, 64k, covers an IO + space of 32MB; the largest, 8MB table, can cover an IO space of + 4GB. Normally the kernel will make the right choice by itself. + + translate_empty_slots - Enable translation even on slots that have + no devices attached to them, in case a device will be hotplugged + in the future. + + translate_phb0 - Enable translation on PHB0. The built-in graphics + adapter resides on the first bridge (PHB0); if translation + (isolation) is enabled on this PHB, X servers that access the + hardware directly from user space might stop working. Enable this + option if your X server only accesses hardware through the kernel + (or you're not using X) and you wants isolation for this bridge as + well. + Debugging oops=panic Always panic on oopses. Default is to just kill the process, diff -puN include/asm-x86_64/pci.h~x86-64-calgary-iommu-hook-it-in include/asm-x86_64/pci.h --- devel/include/asm-x86_64/pci.h~x86-64-calgary-iommu-hook-it-in 2006-04-05 21:28:05.000000000 -0700 +++ devel-akpm/include/asm-x86_64/pci.h 2006-04-05 21:28:05.000000000 -0700 @@ -53,7 +53,7 @@ extern int iommu_setup(char *opt); */ #define PCI_DMA_BUS_IS_PHYS (dma_ops->is_phys) -#ifdef CONFIG_GART_IOMMU +#if defined(CONFIG_GART_IOMMU) || defined(CONFIG_CALGARY_IOMMU) /* * x86-64 always supports DAC, but sometimes it is useful to force diff -puN include/asm-x86_64/proto.h~x86-64-calgary-iommu-hook-it-in include/asm-x86_64/proto.h --- devel/include/asm-x86_64/proto.h~x86-64-calgary-iommu-hook-it-in 2006-04-05 21:28:05.000000000 -0700 +++ devel-akpm/include/asm-x86_64/proto.h 2006-04-05 21:28:05.000000000 -0700 @@ -102,7 +102,9 @@ extern int unsynchronized_tsc(void); extern void select_idle_routine(const struct cpuinfo_x86 *c); extern void gart_parse_options(char *); -extern void __init no_iommu_init(void); +extern int gart_iommu_init(void); +extern void no_iommu_init(void); +extern void detect_calgary(void); extern unsigned long table_start, table_end; _