Introduce irq_remap_ops to x86
Subsystems (3)
cover Introduce irq_remap_ops to x86
Hi,
in order to implement interrupt remapping using the AMD IOMMU I did some refactoring of the current Intel-specific interrupt remapping code. The result is posted for comments in this patch-set.
The patch-set basically removes the Intel-specific calls from the X86 apic and io-apic code and replaces all of them with helper functions that use the irq_remap_ops to hook into an implementation specific implementation.
I have done basic testing on this patch-set on a VT-d machine with interrupt remapping and found no regression so far. But as usual this doesn't mean that there is none ;-)
Anyway, since I am on vacation soon I sent out these patches to receive all kinds of comments so that I can start over to add the AMD part when I am back.
Thanks,
Joerg
Diffstat:
arch/ia64/include/asm/intr_remapping.h | 4 + arch/x86/include/asm/intr_remapping.h | 101 +++ arch/x86/include/asm/irq_remapping.h | 45 -- arch/x86/kernel/apic/apic.c | 20 +- arch/x86/kernel/apic/io_apic.c | 276 ++------- drivers/iommu/Makefile | 2 +- drivers/iommu/amd_iommu_init.c | 123 +++-- drivers/iommu/dmar.c | 1 + drivers/iommu/intel-iommu.c | 1 + drivers/iommu/intel_intr_remapping.c | 1065 ++++++++++++++++++++++++++++++++ drivers/iommu/intr_remapping.c | 810 +++---------------------- drivers/iommu/intr_remapping.h | 97 +++- include/linux/amd-iommu.h | 2 +- include/linux/dmar.h | 85 --- 14 files changed, 1469 insertions(+), 1163 deletions(-)
PATCH 1/9 iommu/amd: Split amd_iommu_init function
The hardware-initializtion part of the AMD IOMMU driver is split out into a seperate function. This function can now be called either from amd_iommu_init() itself or any other place if the hardware needs to be ready earlier. This will be used to implement interrupt remapping for AMD.
--- drivers/iommu/amd_iommu_init.c | 123 +++++++++++++++++++++++++-------------- include/linux/amd-iommu.h | 2 +- 2 files changed, 80 insertions(+), 45 deletions(-)
drivers/iommu/amd_iommu_init.c +79 -44
@@ -1424,10 +1424,40 @@ static struct syscore_ops amd_iommu_syscore_ops = { .resume = amd_iommu_resume, }; +static void __init free_on_init_error (void ) +{ +amd_iommu_uninit_devices (); + +free_pages ((unsigned long )amd_iommu_pd_alloc_bitmap, +get_order (MAX_DOMAIN_ID /8 )); + +free_pages ((unsigned long )amd_iommu_rlookup_table, +get_order (rlookup_table_size)); + +free_pages ((unsigned long )amd_iommu_alias_table, +get_order (alias_table_size)); + +free_pages ((unsigned long )amd_iommu_dev_table, +get_order (dev_table_size)); + +free_iommu_all (); + +free_unity_maps (); + +#ifdef CONFIG_GART_IOMMU +/* +* We failed to initialize the AMD IOMMU - try fallback to GART +* if possible. +*/ +gart_iommu_init (); + +#endif +} +/* -* This is the core init function for AMD IOMMU hardware in the system. -* This function is called from the generic x86 DMA layer initialization -* code. +* This is the hardware init function for AMD IOMMU in the system. +* This function is called either from amd_iommu_init or from the interrupt +* remapping setup code. * * This function basically parses the ACPI table for AMD IOMMU (IVRS) * three times:
@@ -1446,16 +1476,21 @@ static struct syscore_ops amd_iommu_syscore_ops = {* remapping requirements parsed out of the ACPI table in * this last pass. * -* After that the hardware is initialized and ready to go. In the last -* step we do some Linux specific things like registering the driver in -* the dma_ops interface and initializing the suspend/resume support -* functions. Finally it prints some information about AMD IOMMUs and -* the driver state and enables the hardware. +* After everything is set up the IOMMUs are enabled and the necessary +* hotplug and suspend notifiers are registered. */ -static int __init amd_iommu_init (void ) +int __init amd_iommu_init_hardware (void ) {int i, ret =0 ; +if (!amd_iommu_detected) +return -ENODEV ; + +if (amd_iommu_dev_table !=NULL ) { +/* Hardware already initialized */ +return 0 ; + } +/* * First parse ACPI tables to find the largest Bus/Dev/Func * we need to handle. Upon this information the shared data
@@ -1472,9 +1507,8 @@ static int __init amd_iommu_init(void) alias_table_size =tbl_size (ALIAS_TABLE_ENTRY_SIZE ); rlookup_table_size =tbl_size (RLOOKUP_TABLE_ENTRY_SIZE ); - ret = -ENOMEM ; -/* Device table - directly used by all IOMMUs */ + ret = -ENOMEM ; amd_iommu_dev_table = (void *)__get_free_pages (GFP_KERNEL | __GFP_ZERO,get_order (dev_table_size));if (amd_iommu_dev_table ==NULL )
@@ -1546,20 +1580,46 @@ static int __init amd_iommu_init(void)enable_iommus (); +amd_iommu_init_notifier (); + +register_syscore_ops (&amd_iommu_syscore_ops); + +out: +return ret; + +free: +free_on_init_error (); + +return ret; +} + +/* +* This is the core init function for AMD IOMMU hardware in the system. +* This function is called from the generic x86 DMA layer initialization +* code. +* +* The function calls amd_iommu_init_hardware() to setup and enable the +* IOMMU hardware if this has not happened yet. After that the driver +* registers for the DMA-API and for the IOMMU-API as necessary. +*/ +static int __init amd_iommu_init (void ) +{ +int ret =0 ; + + ret =amd_iommu_init_hardware (); +if (ret) + goto out; +if (iommu_pass_through) ret =amd_iommu_init_passthrough ();else ret =amd_iommu_init_dma_ops ();if (ret) - goto free_disable; + goto free;amd_iommu_init_api (); -amd_iommu_init_notifier (); - -register_syscore_ops (&amd_iommu_syscore_ops); -if (iommu_pass_through) goto out;
@@ -1569,39 +1629,14 @@ static int __init amd_iommu_init(void)printk (KERN_INFO "AMD-Vi: Lazy IO/TLB flushing enabled\n" ); x86_platform.iommu_shutdown = disable_iommus; + out:return ret; -free_disable: -disable_iommus (); - free: -amd_iommu_uninit_devices (); - -free_pages ((unsigned long )amd_iommu_pd_alloc_bitmap, -get_order (MAX_DOMAIN_ID /8 )); - -free_pages ((unsigned long )amd_iommu_rlookup_table, -get_order (rlookup_table_size)); - -free_pages ((unsigned long )amd_iommu_alias_table, -get_order (alias_table_size)); - -free_pages ((unsigned long )amd_iommu_dev_table, -get_order (dev_table_size)); - -free_iommu_all (); - -free_unity_maps (); - -#ifdef CONFIG_GART_IOMMU -/* -* We failed to initialize the AMD IOMMU - try fallback to GART -* if possible. -*/ -gart_iommu_init (); +disable_iommus (); -#endif +free_on_init_error (); goto out; }
include/linux/amd-iommu.h +1 -1
@@ -28,7 +28,7 @@ struct task_struct;struct pci_dev ;extern int amd_iommu_detect (void ); - +extern int amd_iommu_init_hardware (void );/** * amd_iommu_enable_device_erratum() - Enable erratum workaround for device
Signature · 1 line
1.7.5.4
PATCH 2/9 iommu: Rename intr_remapping files to intel_intr_remapping
In reply to Joerg RoedelThe files contain code mostly relevant for the Intel implementation of interrupt remapping. Make that visible in the file names. Also inline intr_remapping.h into intr_remapping.c because it is only included there and the content is very small. So there is no reason for a seperate header file.
--- drivers/iommu/Makefile | 2 +- drivers/iommu/intel_intr_remapping.c | 849 ++++++++++++++++++++++++++++++++++ drivers/iommu/intr_remapping.c | 834 --------------------------------- drivers/iommu/intr_remapping.h | 17 - 4 files changed, 850 insertions(+), 852 deletions(-) create mode 100644 drivers/iommu/intel_intr_remapping.c delete mode 100644 drivers/iommu/intr_remapping.c delete mode 100644 drivers/iommu/intr_remapping.h
drivers/iommu/Makefile +1 -1
@@ -4,7 +4,7 @@ obj-$(CONFIG_AMD_IOMMU) += amd_iommu.o amd_iommu_init.o obj-$(CONFIG_AMD_IOMMU_V2) += amd_iommu_v2.o obj-$(CONFIG_DMAR_TABLE) += dmar.o obj-$(CONFIG_INTEL_IOMMU) += iova.o intel-iommu.o -obj-$(CONFIG_IRQ_REMAP) += intr_remapping.o +obj-$(CONFIG_IRQ_REMAP) += intel_intr_remapping.o obj-$(CONFIG_OMAP_IOMMU) += omap-iommu.o obj-$(CONFIG_OMAP_IOVMM) += omap-iovmm.o obj-$(CONFIG_OMAP_IOMMU_DEBUG) += omap-iommu-debug.o
drivers/iommu/intel_intr_remapping.c new file +849 -0
849 lines not on this page · raw message
drivers/iommu/intr_remapping.c deleted +0 -834
834 lines not on this page · raw message
drivers/iommu/intr_remapping.h deleted +0 -17
@@ -1,17 +0,0 @@ -#include <linux/intel-iommu.h> - -struct ioapic_scope { -struct intel_iommu *iommu; -unsigned int id; -unsigned int bus;/* PCI bus number */ -unsigned int devfn;/* PCI devfn number */ -}; - -struct hpet_scope { -struct intel_iommu *iommu; -u8 id; -unsigned int bus; -unsigned int devfn; -}; - -#define IR_X2APIC_MODE (mode) (mode ? (1 << 11) : 0)
Signature · 1 line
1.7.5.4
PATCH 3/9 iommu/vt-d: Make intr-remapping initialization generic
In reply to Joerg RoedelThis patch introduces irq_remap_ops to hold implementation specific function pointer to handle interrupt remapping. As the first part the initialization functions for VT-d are converted to these ops.
--- arch/ia64/include/asm/intr_remapping.h | 4 ++ arch/x86/include/asm/intr_remapping.h | 45 +++++++++++++++++++ arch/x86/kernel/apic/apic.c | 14 ++++-- arch/x86/kernel/apic/io_apic.c | 1 + drivers/iommu/Makefile | 2 +- drivers/iommu/dmar.c | 1 + drivers/iommu/intel-iommu.c | 1 + drivers/iommu/intel_intr_remapping.c | 52 +++++----------------- drivers/iommu/intr_remapping.c | 76 ++++++++++++++++++++++++++++++++ drivers/iommu/intr_remapping.h | 46 +++++++++++++++++++ include/linux/dmar.h | 3 - 11 files changed, 196 insertions(+), 49 deletions(-) create mode 100644 arch/ia64/include/asm/intr_remapping.h create mode 100644 arch/x86/include/asm/intr_remapping.h create mode 100644 drivers/iommu/intr_remapping.c create mode 100644 drivers/iommu/intr_remapping.h
arch/ia64/include/asm/intr_remapping.h new file +4 -0
@@ -0,0 +1,4 @@ +#ifndef __IA64_INTR_REMAPPING_H +#define __IA64_INTR_REMAPPING_H +#define intr_remapping_enabled 0 +#endif
arch/x86/include/asm/intr_remapping.h new file +45 -0
45 lines not on this page · raw message
arch/x86/kernel/apic/apic.c +9 -5
@@ -35,6 +35,7 @@#include <linux/smp.h> #include <linux/mm.h> +#include <asm/intr_remapping.h> #include <asm/perf_event.h> #include <asm/x86_init.h> #include <asm/pgalloc.h>
@@ -1523,7 +1524,7 @@ int __init enable_IR(void) return -1; } -return enable_intr_remapping (); +return intr_hardware_enable ();#endif return -1 ; }
@@ -1532,10 +1533,13 @@ void __init enable_IR_x2apic(void) {unsigned long flags;int ret, x2apic_enabled =0 ; -int dmar_table_init_ret; +int hardware_init_ret; - dmar_table_init_ret =dmar_table_init (); -if (dmar_table_init_ret && !x2apic_supported ()) +/* Make sure irq_remap_ops are initialized */ +setup_intr_remapping (); + + hardware_init_ret =intr_hardware_init (); +if (hardware_init_ret && !x2apic_supported ())return ; ret =save_ioapic_entries ();
@@ -1551,7 +1555,7 @@ void __init enable_IR_x2apic(void)if (x2apic_preenabled && nox2apic)disable_x2apic (); -if (dmar_table_init_ret) +if (hardware_init_ret) ret =-1 ;else ret =enable_IR ();
arch/x86/kernel/apic/io_apic.c +1 -0
@@ -57,6 +57,7 @@#include <asm/msidef.h> #include <asm/hypertransport.h> #include <asm/setup.h> +#include <asm/intr_remapping.h> #include <asm/irq_remapping.h> #include <asm/hpet.h> #include <asm/hw_irq.h>
drivers/iommu/Makefile +1 -1
@@ -4,7 +4,7 @@ obj-$(CONFIG_AMD_IOMMU) += amd_iommu.o amd_iommu_init.o obj-$(CONFIG_AMD_IOMMU_V2) += amd_iommu_v2.o obj-$(CONFIG_DMAR_TABLE) += dmar.o obj-$(CONFIG_INTEL_IOMMU) += iova.o intel-iommu.o -obj-$(CONFIG_IRQ_REMAP) += intel_intr_remapping.o +obj-$(CONFIG_IRQ_REMAP) += intel_intr_remapping.o intr_remapping.o obj-$(CONFIG_OMAP_IOMMU) += omap-iommu.o obj-$(CONFIG_OMAP_IOVMM) += omap-iovmm.o obj-$(CONFIG_OMAP_IOMMU_DEBUG) += omap-iommu-debug.o
drivers/iommu/dmar.c +1 -0
@@ -36,6 +36,7 @@#include <linux/tboot.h> #include <linux/dmi.h> #include <linux/slab.h> +#include <asm/intr_remapping.h> #include <asm/iommu_table.h> #define PREFIX "DMAR: "
drivers/iommu/intel-iommu.c +1 -0
@@ -42,6 +42,7 @@#include <linux/dmi.h> #include <linux/pci-ats.h> #include <linux/memblock.h> +#include <asm/intr_remapping.h> #include <asm/cacheflush.h> #include <asm/iommu.h>
drivers/iommu/intel_intr_remapping.c +12 -40
93 lines not on this page · raw message
drivers/iommu/intr_remapping.c new file +76 -0
76 lines not on this page · raw message
drivers/iommu/intr_remapping.h new file +46 -0
46 lines not on this page · raw message
include/linux/dmar.h +0 -3
@@ -115,9 +115,6 @@ struct irte { };#ifdef CONFIG_IRQ_REMAP -extern int intr_remapping_enabled; -extern int intr_remapping_supported (void ); -extern int enable_intr_remapping (void );extern void disable_intr_remapping (void );extern int reenable_intr_remapping (int );
Signature · 1 line
1.7.5.4
PATCH 4/9 iommu/vt-d: Convert missing apic.c intr-remapping call to remap_ops
In reply to Joerg RoedelConvert these calls too:
* Disable of remapping hardware
* Reenable of remapping hardware
* Enable fault handling
With that all of arch/x86/kernel/apic/apic.c is converted to use the generic intr-remapping interface.
--- arch/x86/include/asm/intr_remapping.h | 6 ++++++ arch/x86/kernel/apic/apic.c | 6 +++--- drivers/iommu/intel_intr_remapping.c | 7 +++++-- drivers/iommu/intr_remapping.c | 24 ++++++++++++++++++++++++ drivers/iommu/intr_remapping.h | 9 +++++++++ include/linux/dmar.h | 18 ------------------ 6 files changed, 47 insertions(+), 23 deletions(-)
arch/x86/include/asm/intr_remapping.h +6 -0
@@ -30,6 +30,9 @@ extern void setup_intr_remapping(void);extern int intr_remapping_supported (void );extern int intr_hardware_init (void );extern int intr_hardware_enable (void ); +extern void intr_hardware_disable (void ); +extern int intr_hardware_reenable (int ); +extern int intr_enable_fault_handling (void );#else /* CONFIG_IRQ_REMAP */
@@ -39,6 +42,9 @@ static inline void setup_intr_remapping(void) { }static inline int intr_remapping_supported (void ) {return 0 ; }static inline int intr_hardware_init (void ) {return -ENODEV ; }static inline int intr_hardware_enable (void ) {return -ENODEV ; } +static inline void intr_hardware_disable (void ) { } +static inline int intr_hardware_reenable (int eim) {return -ENODEV ; } +static inline int intr_enable_fault_handling (void ) {return -ENODEV ; }#endif /* CONFIG_IRQ_REMAP */
arch/x86/kernel/apic/apic.c +3 -3
@@ -1438,7 +1438,7 @@ void __init bsp_end_local_APIC_setup(void)* handling for interrupt remapping. */ if (intr_remapping_enabled) -enable_drhd_fault_handling (); +intr_enable_fault_handling (); }
@@ -2172,7 +2172,7 @@ static int lapic_suspend(void)disable_local_APIC ();if (intr_remapping_enabled) -disable_intr_remapping (); +intr_hardware_disable ();local_irq_restore (flags);return 0 ;
@@ -2239,7 +2239,7 @@ static void lapic_resume(void)apic_read (APIC_ESR );if (intr_remapping_enabled) -reenable_intr_remapping (x2apic_mode); +intr_hardware_reenable (x2apic_mode);local_irq_restore (flags); }
drivers/iommu/intel_intr_remapping.c +5 -2
@@ -764,7 +764,7 @@ int __init ir_dev_scope_init(void) }rootfs_initcall (ir_dev_scope_init); -void disable_intr_remapping (void ) +static void disable_intr_remapping (void ) {struct dmar_drhd_unit *drhd;struct intel_iommu *iommu =NULL ;
@@ -780,7 +780,7 @@ void disable_intr_remapping(void) } } -int reenable_intr_remapping (int eim) +static int reenable_intr_remapping (int eim) {struct dmar_drhd_unit *drhd;int setup =0 ;
@@ -818,4 +818,7 @@ struct irq_remap_ops intel_irq_remap_ops = { .supported = intel_intr_remapping_supported, .hardware_init = dmar_table_init, .hardware_enable = intel_enable_intr_remapping, + .hardware_disable = disable_intr_remapping, + .hardware_reenable = reenable_intr_remapping, + .enable_faulting = enable_drhd_fault_handling, };
drivers/iommu/intr_remapping.c +24 -0
@@ -74,3 +74,27 @@ int __init intr_hardware_enable(void)return remap_ops->hardware_enable (); } + +void intr_hardware_disable (void ) +{ +if (!remap_ops || !remap_ops->hardware_disable) +return ; + + remap_ops->hardware_disable (); +} + +int intr_hardware_reenable (int mode) +{ +if (!remap_ops || !remap_ops->hardware_reenable) +return 0 ; + +return remap_ops->hardware_reenable (mode); +} + +int __init intr_enable_fault_handling (void ) +{ +if (!remap_ops || !remap_ops->enable_faulting) +return -ENODEV ; + +return remap_ops->enable_faulting (); +}
drivers/iommu/intr_remapping.h +9 -0
@@ -37,6 +37,15 @@ struct irq_remap_ops {/* Enables the remapping hardware */ int (*hardware_enable)(void ); + +/* Disables the remapping hardware */ +void (*hardware_disable)(void ); + +/* Reenables the remapping hardware */ +int (*hardware_reenable)(int ); + +/* Enable fault handling */ +int (*enable_faulting)(void ); };extern struct irq_remap_ops intel_irq_remap_ops;
include/linux/dmar.h +0 -18
@@ -115,9 +115,6 @@ struct irte { };#ifdef CONFIG_IRQ_REMAP -extern void disable_intr_remapping (void ); -extern int reenable_intr_remapping (int ); -extern int get_irte (int irq,struct irte *entry);extern int modify_irte (int irq,struct irte *irte_modified);extern int alloc_irte (struct intel_iommu *iommu,int irq,u16 count);
@@ -179,21 +176,6 @@ static inline int set_msi_sid(struct irte *irte, struct pci_dev *dev)return 0 ; } -#define intr_remapping_enabled (0) - -static inline int enable_intr_remapping (void ) -{ -return -1 ; -} - -static inline void disable_intr_remapping (void ) -{ -} - -static inline int reenable_intr_remapping (int eim) -{ -return 0 ; -}#endif enum {
Signature · 1 line
1.7.5.4
PATCH 5/9 iommu/vt-d: Convert IR ioapic-setup to use remap_ops
In reply to Joerg RoedelThe IOAPIC setup routine for interrupt remapping is VT-d specific. Move it to the irq_remap_ops and add a call helper function.
--- arch/x86/include/asm/intr_remapping.h | 15 +++++- arch/x86/kernel/apic/io_apic.c | 68 +------------------------ drivers/iommu/intel_intr_remapping.c | 89 +++++++++++++++++++++++++++++++++ drivers/iommu/intr_remapping.c | 12 +++++ drivers/iommu/intr_remapping.h | 8 +++ 5 files changed, 125 insertions(+), 67 deletions(-)
arch/x86/include/asm/intr_remapping.h +14 -1
@@ -24,6 +24,9 @@#ifdef CONFIG_IRQ_REMAP +struct IO_APIC_route_entry ; +struct io_apic_irq_attr ; +extern int intr_remapping_enabled;extern void setup_intr_remapping (void );
@@ -33,6 +36,10 @@ extern int intr_hardware_enable(void);extern void intr_hardware_disable (void );extern int intr_hardware_reenable (int );extern int intr_enable_fault_handling (void ); +extern int intr_setup_ioapic_entry (int irq, +struct IO_APIC_route_entry *entry, +unsigned int destination,int vector, +struct io_apic_irq_attr *attr);#else /* CONFIG_IRQ_REMAP */
@@ -45,7 +52,13 @@ static inline int intr_hardware_enable(void) { return -ENODEV; }static inline void intr_hardware_disable (void ) { }static inline int intr_hardware_reenable (int eim) {return -ENODEV ; }static inline int intr_enable_fault_handling (void ) {return -ENODEV ; } - +static inline int intr_setup_ioapic_entry (int irq, +struct IO_APIC_route_entry *entry, +unsigned int destination,int vector, +struct io_apic_irq_attr *attr) +{ +return -ENODEV ; +}#endif /* CONFIG_IRQ_REMAP */ #endif /* __X86_INTR_REMAPPING_H */
arch/x86/kernel/apic/io_apic.c +2 -66
79 lines not on this page · raw message
drivers/iommu/intel_intr_remapping.c +89 -0
105 lines not on this page · raw message
drivers/iommu/intr_remapping.c +12 -0
@@ -98,3 +98,15 @@ int __init intr_enable_fault_handling(void)return remap_ops->enable_faulting (); } + +int intr_setup_ioapic_entry (int irq, +struct IO_APIC_route_entry *entry, +unsigned int destination,int vector, +struct io_apic_irq_attr *attr) +{ +if (!remap_ops || !remap_ops->setup_ioapic_entry) +return -ENODEV ; + +return remap_ops->setup_ioapic_entry (irq, entry, destination, + vector, attr); +}
drivers/iommu/intr_remapping.h +8 -0
@@ -24,6 +24,9 @@#ifdef CONFIG_IRQ_REMAP +struct IO_APIC_route_entry ; +struct io_apic_irq_attr ; +extern int disable_intremap;extern int disable_sourceid_checking;extern int no_x2apic_optout;
@@ -46,6 +49,11 @@ struct irq_remap_ops {/* Enable fault handling */ int (*enable_faulting)(void ); + +/* IO-APIC setup routine */ +int (*setup_ioapic_entry)(int irq,struct IO_APIC_route_entry *, +unsigned int ,int , +struct io_apic_irq_attr *); };extern struct irq_remap_ops intel_irq_remap_ops;
Signature · 1 line
1.7.5.4
PATCH 6/9 iommu/vt-d: Convert IR set_affinity function to remap_ops
In reply to Joerg RoedelThe function to set interrupt affinity with interrupt remapping enabled is Intel specific too. So move it to the irq_remap_ops too.
--- arch/x86/include/asm/intr_remapping.h | 9 ++++ arch/x86/kernel/apic/io_apic.c | 69 +-------------------------------- drivers/iommu/intel_intr_remapping.c | 54 +++++++++++++++++++++++++ drivers/iommu/intr_remapping.c | 9 ++++ drivers/iommu/intr_remapping.h | 6 +++ 5 files changed, 80 insertions(+), 67 deletions(-)
arch/x86/include/asm/intr_remapping.h +9 -0
@@ -40,6 +40,9 @@ extern int intr_setup_ioapic_entry(int irq,struct IO_APIC_route_entry *entry, unsigned int destination, int vector, struct io_apic_irq_attr *attr); +extern int intr_set_affinity (struct irq_data *data, +const struct cpumask *mask, +bool force);#else /* CONFIG_IRQ_REMAP */
@@ -59,6 +62,12 @@ static inline int intr_setup_ioapic_entry(int irq, {return -ENODEV ; } +static inline int intr_set_affinity (struct irq_data *data, +const struct cpumask *mask, +bool force) +{ +return 0 ; +}#endif /* CONFIG_IRQ_REMAP */ #endif /* __X86_INTR_REMAPPING_H */
arch/x86/kernel/apic/io_apic.c +2 -67
87 lines not on this page · raw message
drivers/iommu/intel_intr_remapping.c +54 -0
64 lines not on this page · raw message
drivers/iommu/intr_remapping.c +9 -0
@@ -110,3 +110,12 @@ int intr_setup_ioapic_entry(int irq,return remap_ops->setup_ioapic_entry (irq, entry, destination, vector, attr); } + +int intr_set_affinity (struct irq_data *data,const struct cpumask *mask, +bool force) +{ +if (!remap_ops || !remap_ops->set_affinity) +return 0 ; + +return remap_ops->set_affinity (data, mask, force); +}
drivers/iommu/intr_remapping.h +6 -0
@@ -26,6 +26,8 @@struct IO_APIC_route_entry ;struct io_apic_irq_attr ; +struct irq_data ; +struct cpumask ;extern int disable_intremap;extern int disable_sourceid_checking;
@@ -54,6 +56,10 @@ struct irq_remap_ops {int (*setup_ioapic_entry)(int irq,struct IO_APIC_route_entry *,unsigned int ,int ,struct io_apic_irq_attr *); + +/* Set the CPU affinity of a remapped interrupt */ +int (*set_affinity)(struct irq_data *data,const struct cpumask *mask, +bool force); };extern struct irq_remap_ops intel_irq_remap_ops;
Signature · 1 line
1.7.5.4
PATCH 7/9 iommu/vt-d: Convert free_irte into a remap_ops callback
In reply to Joerg RoedelThe operation for releasing a remapping entry is iommu specific too.
--- arch/x86/include/asm/intr_remapping.h | 2 ++ arch/x86/kernel/apic/io_apic.c | 2 +- drivers/iommu/intel_intr_remapping.c | 3 ++- drivers/iommu/intr_remapping.c | 8 ++++++++ drivers/iommu/intr_remapping.h | 3 +++ include/linux/dmar.h | 5 ----- 6 files changed, 16 insertions(+), 7 deletions(-)
arch/x86/include/asm/intr_remapping.h +2 -0
@@ -43,6 +43,7 @@ extern int intr_setup_ioapic_entry(int irq,extern int intr_set_affinity (struct irq_data *data,const struct cpumask *mask,bool force); +extern void intr_free_irq (int irq);#else /* CONFIG_IRQ_REMAP */
@@ -68,6 +69,7 @@ static inline int intr_set_affinity(struct irq_data *data, {return 0 ; } +static inline void intr_free_irq (int irq) { }#endif /* CONFIG_IRQ_REMAP */ #endif /* __X86_INTR_REMAPPING_H */
arch/x86/kernel/apic/io_apic.c +1 -1
@@ -2981,7 +2981,7 @@ void destroy_irq(unsigned int irq)irq_set_status_flags (irq,IRQ_NOREQUEST |IRQ_NOPROBE );if (irq_remapped (cfg)) -free_irte (irq); +intr_free_irq (irq);raw_spin_lock_irqsave (&vector_lock, flags);__clear_irq_vector (irq, cfg);raw_spin_unlock_irqrestore (&vector_lock, flags);
drivers/iommu/intel_intr_remapping.c +2 -1
@@ -253,7 +253,7 @@ static int clear_entries(struct irq_2_iommu *irq_iommu)return qi_flush_iec (iommu, index, irq_iommu->irte_mask); } -int free_irte (int irq) +static int free_irte (int irq) {struct irq_2_iommu *irq_iommu =irq_2_iommu (irq);unsigned long flags;
@@ -964,4 +964,5 @@ struct irq_remap_ops intel_irq_remap_ops = { .enable_faulting = enable_drhd_fault_handling, .setup_ioapic_entry = intel_setup_ioapic_entry, .set_affinity = intel_ioapic_set_affinity, + .free_irq = free_irte, };
drivers/iommu/intr_remapping.c +8 -0
@@ -119,3 +119,11 @@ int intr_set_affinity(struct irq_data *data, const struct cpumask *mask,return remap_ops->set_affinity (data, mask, force); } + +void intr_free_irq (int irq) +{ +if (!remap_ops || !remap_ops->free_irq) +return ; + + remap_ops->free_irq (irq); +}
drivers/iommu/intr_remapping.h +3 -0
@@ -60,6 +60,9 @@ struct irq_remap_ops {/* Set the CPU affinity of a remapped interrupt */ int (*set_affinity)(struct irq_data *data,const struct cpumask *mask,bool force); + +/* Free an IRQ */ +int (*free_irq)(int ); };extern struct irq_remap_ops intel_irq_remap_ops;
include/linux/dmar.h +0 -5
@@ -121,7 +121,6 @@ extern int alloc_irte(struct intel_iommu *iommu, int irq, u16 count);extern int set_irte_irq (int irq,struct intel_iommu *iommu,u16 index,u16 sub_handle);extern int map_irq_to_irte_handle (int irq,u16 *sub_handle); -extern int free_irte (int irq);extern struct intel_iommu *map_dev_to_ir (struct pci_dev *dev);extern struct intel_iommu *map_ioapic_to_ir (int apic);
@@ -138,10 +137,6 @@ static inline int modify_irte(int irq, struct irte *irte_modified) {return -1 ; } -static inline int free_irte (int irq) -{ -return -1 ; -}static inline int map_irq_to_irte_handle (int irq,u16 *sub_handle) {return -1 ;
Signature · 1 line
1.7.5.4
PATCH 8/9 iommu/vt-d: Convert MSI remapping setup to remap_ops
In reply to Joerg RoedelThis patch introduces remapping-ops for setting ups MSI interrupts.
--- arch/x86/include/asm/intr_remapping.h | 26 +++++++ arch/x86/include/asm/irq_remapping.h | 23 ------ arch/x86/kernel/apic/io_apic.c | 121 ++++++++------------------------- drivers/iommu/intel_intr_remapping.c | 97 ++++++++++++++++++++++++++ drivers/iommu/intr_remapping.c | 35 ++++++++++ drivers/iommu/intr_remapping.h | 16 +++++ 6 files changed, 203 insertions(+), 115 deletions(-)
arch/x86/include/asm/intr_remapping.h +26 -0
@@ -26,6 +26,7 @@struct IO_APIC_route_entry ;struct io_apic_irq_attr ; +struct pci_dev ;extern int intr_remapping_enabled;
@@ -44,6 +45,13 @@ extern int intr_set_affinity(struct irq_data *data,const struct cpumask *mask, bool force);extern void intr_free_irq (int irq); +extern void intr_compose_msi_msg (struct pci_dev *pdev, +unsigned int irq,unsigned int dest, +struct msi_msg *msg,u8 hpet_id); +extern int intr_msi_alloc_irq (struct pci_dev *pdev,int irq,int nvec); +extern int intr_msi_setup_irq (struct pci_dev *pdev,unsigned int irq, +int index,int sub_handle); +extern int intr_setup_hpet_msi (unsigned int irq,unsigned int id);#else /* CONFIG_IRQ_REMAP */
@@ -70,6 +78,24 @@ static inline int intr_set_affinity(struct irq_data *data,return 0 ; }static inline void intr_free_irq (int irq) { } +static inline void intr_compose_msi_msg (struct pci_dev *pdev, +unsigned int irq,unsigned int dest, +struct msi_msg *msg,u8 hpet_id) +{ +} +static inline int intr_msi_alloc_irq (struct pci_dev *pdev,int irq,int nvec) +{ +return -ENODEV ; +} +static inline int intr_msi_setup_irq (struct pci_dev *pdev,unsigned int irq, +int index,int sub_handle) +{ +return -ENODEV ; +} +static inline int intr_setup_hpet_msi (unsigned int irq,unsigned int id) +{ +return -ENODEV ; +}#endif /* CONFIG_IRQ_REMAP */ #endif /* __X86_INTR_REMAPPING_H */
arch/x86/include/asm/irq_remapping.h +0 -23
@@ -5,34 +5,11 @@#ifdef CONFIG_IRQ_REMAP static void irq_remap_modify_chip_defaults (struct irq_chip *chip); -static inline void prepare_irte (struct irte *irte,int vector, -unsigned int dest) -{ -memset (irte,0 ,sizeof (*irte)); - - irte->present =1 ; - irte->dst_mode = apic->irq_dest_mode; -/* -* Trigger mode in the IRTE will always be edge, and for IO-APIC, the -* actual level or edge trigger will be setup in the IO-APIC -* RTE. This will help simplify level triggered irq migration. -* For more details, see the comments (in io_apic.c) explainig IO-APIC -* irq migration in the presence of interrupt-remapping. -*/ - irte->trigger_mode =0 ; - irte->dlvry_mode = apic->irq_delivery_mode; - irte->vector = vector; - irte->dest_id =IRTE_DEST (dest); - irte->redir_hint =1 ; -}static inline bool irq_remapped (struct irq_cfg *cfg) {return cfg->irq_2_iommu.iommu !=NULL ; }#else -static void prepare_irte (struct irte *irte,int vector,unsigned int dest) -{ -}static inline bool irq_remapped (struct irq_cfg *cfg) {return false;
arch/x86/kernel/apic/io_apic.c +28 -91
159 lines not on this page · raw message
drivers/iommu/intel_intr_remapping.c +97 -0
113 lines not on this page · raw message
drivers/iommu/intr_remapping.c +35 -0
@@ -127,3 +127,38 @@ void intr_free_irq(int irq) remap_ops->free_irq (irq); } + +void intr_compose_msi_msg (struct pci_dev *pdev, +unsigned int irq,unsigned int dest, +struct msi_msg *msg,u8 hpet_id) +{ +if (!remap_ops || !remap_ops->compose_msi_msg) +return ; + + remap_ops->compose_msi_msg (pdev, irq, dest, msg, hpet_id); +} + +int intr_msi_alloc_irq (struct pci_dev *pdev,int irq,int nvec) +{ +if (!remap_ops || !remap_ops->msi_alloc_irq) +return -ENODEV ; + +return remap_ops->msi_alloc_irq (pdev, irq, nvec); +} + +int intr_msi_setup_irq (struct pci_dev *pdev,unsigned int irq, +int index,int sub_handle) +{ +if (!remap_ops || !remap_ops->msi_setup_irq) +return -ENODEV ; + +return remap_ops->msi_setup_irq (pdev, irq, index, sub_handle); +} + +int intr_setup_hpet_msi (unsigned int irq,unsigned int id) +{ +if (!remap_ops || !remap_ops->setup_hpet_msi) +return -ENODEV ; + +return remap_ops->setup_hpet_msi (irq, id); +}
drivers/iommu/intr_remapping.h +16 -0
@@ -28,6 +28,8 @@ struct IO_APIC_route_entry;struct io_apic_irq_attr ;struct irq_data ;struct cpumask ; +struct pci_dev ; +struct msi_msg ;extern int disable_intremap;extern int disable_sourceid_checking;
@@ -63,6 +65,20 @@ struct irq_remap_ops {/* Free an IRQ */ int (*free_irq)(int ); + +/* Create MSI msg to use for interrupt remapping */ +void (*compose_msi_msg)(struct pci_dev *, +unsigned int ,unsigned int , +struct msi_msg *,u8 ); + +/* Allocate remapping resources for MSI */ +int (*msi_alloc_irq)(struct pci_dev *,int ,int ); + +/* Setup the remapped MSI irq */ +int (*msi_setup_irq)(struct pci_dev *,unsigned int ,int ,int ); + +/* Setup interrupt remapping for an HPET MSI */ +int (*setup_hpet_msi)(unsigned int ,unsigned int ); };extern struct irq_remap_ops intel_irq_remap_ops;
Signature · 1 line
1.7.5.4
PATCH 9/9 x86, iommu/vt-d: Clean up interfaces for interrupt remapping
In reply to Joerg RoedelRemove the Intel specific interfaces from dmar.h and remove asm/irq_remapping.h which is only used for io_apic.c anyway.
--- arch/x86/include/asm/irq_remapping.h | 22 ------------ arch/x86/kernel/apic/io_apic.c | 17 +++++++++- drivers/iommu/intel_intr_remapping.c | 20 ++++++------ include/linux/dmar.h | 59 ---------------------------------- 4 files changed, 26 insertions(+), 92 deletions(-) delete mode 100644 arch/x86/include/asm/irq_remapping.h
arch/x86/include/asm/irq_remapping.h deleted +0 -22
@@ -1,22 +0,0 @@ -#ifndef _ASM_X86_IRQ_REMAPPING_H -#define _ASM_X86_IRQ_REMAPPING_H - -#define IRTE_DEST (dest) ((x2apic_mode) ? dest : dest << 8) - -#ifdef CONFIG_IRQ_REMAP -static void irq_remap_modify_chip_defaults (struct irq_chip *chip); -static inline bool irq_remapped (struct irq_cfg *cfg) -{ -return cfg->irq_2_iommu.iommu !=NULL ; -} -#else -static inline bool irq_remapped (struct irq_cfg *cfg) -{ -return false; -} -static inline void irq_remap_modify_chip_defaults (struct irq_chip *chip) -{ -} -#endif - -#endif /* _ASM_X86_IRQ_REMAPPING_H */
arch/x86/kernel/apic/io_apic.c +16 -1
@@ -58,7 +58,6 @@#include <asm/hypertransport.h> #include <asm/setup.h> #include <asm/intr_remapping.h> -#include <asm/irq_remapping.h> #include <asm/hpet.h> #include <asm/hw_irq.h>
@@ -68,6 +67,22 @@#define for_each_irq_pin (entry, head) \ for (entry = head; entry; entry = entry->next) +#ifdef CONFIG_IRQ_REMAP +static void irq_remap_modify_chip_defaults (struct irq_chip *chip); +static inline bool irq_remapped (struct irq_cfg *cfg) +{ +return cfg->irq_2_iommu.iommu !=NULL ; +} +#else +static inline bool irq_remapped (struct irq_cfg *cfg) +{ +return false; +} +static inline void irq_remap_modify_chip_defaults (struct irq_chip *chip) +{ +} +#endif +/* * Is the SiS APIC rmw bug present ? * -1 = don't know, 0 = no, 1 = yes
drivers/iommu/intel_intr_remapping.c +10 -10
@@ -64,7 +64,7 @@ int get_irte(int irq, struct irte *entry)return 0 ; } -int alloc_irte (struct intel_iommu *iommu,int irq,u16 count) +static int alloc_irte (struct intel_iommu *iommu,int irq,u16 count) {struct ir_table *table = iommu->ir_table;struct irq_2_iommu *irq_iommu =irq_2_iommu (irq);
@@ -136,7 +136,7 @@ static int qi_flush_iec(struct intel_iommu *iommu, int index, int mask)return qi_submit_sync (&desc, iommu); } -int map_irq_to_irte_handle (int irq,u16 *sub_handle) +static int map_irq_to_irte_handle (int irq,u16 *sub_handle) {struct irq_2_iommu *irq_iommu =irq_2_iommu (irq);unsigned long flags;
@@ -152,7 +152,7 @@ int map_irq_to_irte_handle(int irq, u16 *sub_handle)return index; } -int set_irte_irq (int irq,struct intel_iommu *iommu,u16 index,u16 subhandle) +static int set_irte_irq (int irq,struct intel_iommu *iommu,u16 index,u16 subhandle) {struct irq_2_iommu *irq_iommu =irq_2_iommu (irq);unsigned long flags;
@@ -172,7 +172,7 @@ int set_irte_irq(int irq, struct intel_iommu *iommu, u16 index, u16 subhandle)return 0 ; } -int modify_irte (int irq,struct irte *irte_modified) +static int modify_irte (int irq,struct irte *irte_modified) {struct irq_2_iommu *irq_iommu =irq_2_iommu (irq);struct intel_iommu *iommu;
@@ -200,7 +200,7 @@ int modify_irte(int irq, struct irte *irte_modified)return rc; } -struct intel_iommu *map_hpet_to_ir (u8 hpet_id) +static struct intel_iommu *map_hpet_to_ir (u8 hpet_id) {int i;
@@ -210,7 +210,7 @@ struct intel_iommu *map_hpet_to_ir(u8 hpet_id)return NULL ; } -struct intel_iommu *map_ioapic_to_ir (int apic) +static struct intel_iommu *map_ioapic_to_ir (int apic) {int i;
@@ -220,7 +220,7 @@ struct intel_iommu *map_ioapic_to_ir(int apic)return NULL ; } -struct intel_iommu *map_dev_to_ir (struct pci_dev *dev) +static struct intel_iommu *map_dev_to_ir (struct pci_dev *dev) {struct dmar_drhd_unit *drhd;
@@ -312,7 +312,7 @@ static void set_irte_sid(struct irte *irte, unsigned int svt, irte->sid = sid; } -int set_ioapic_sid (struct irte *irte,int apic) +static int set_ioapic_sid (struct irte *irte,int apic) {int i;u16 sid =0 ;
@@ -337,7 +337,7 @@ int set_ioapic_sid(struct irte *irte, int apic)return 0 ; } -int set_hpet_sid (struct irte *irte,u8 id) +static int set_hpet_sid (struct irte *irte,u8 id) {int i;u16 sid =0 ;
@@ -367,7 +367,7 @@ int set_hpet_sid(struct irte *irte, u8 id)return 0 ; } -int set_msi_sid (struct irte *irte,struct pci_dev *dev) +static int set_msi_sid (struct irte *irte,struct pci_dev *dev) {struct pci_dev *bridge;
include/linux/dmar.h +0 -59
65 lines not on this page · raw message
Signature · 1 line
1.7.5.4
Quoted 11 lines · Joerg Roedel
Hi,
in order to implement interrupt remapping using the AMD IOMMU I did some refactoring of the current Intel-specific interrupt remapping code. The result is posted for comments in this patch-set.
The patch-set basically removes the Intel-specific calls from the X86 apic and io-apic code and replaces all of them with helper functions that use the
irq_remap_opsto hook into an implementation specific implementation.
Quoted 7 lines
I have done basic testing on this patch-set on a VT-d machine with interrupt remapping and found no regression so far. But as usual this doesn't mean that there is none ;-)
Anyway, since I am on vacation soon I sent out these patches to receive all kinds of comments so that I can start over to add the AMD part when I am back.
Do you have git branch that I could check?
Thanks
Yinghai
Joerg Roedel
maintainerQuoted 1 line · Yinghai Lu
Do you have git branch that I could check?
Just pushed it to
git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git intr-remapping
May take some time until it appears on the mirrors.
Joerg
Quoted 39 lines · Joerg Roedel
Hi,
in order to implement interrupt remapping using the AMD IOMMU I did some refactoring of the current Intel-specific interrupt remapping code. The result is posted for comments in this patch-set.
The patch-set basically removes the Intel-specific calls from the X86 apic and io-apic code and replaces all of them with helper functions that use the
irq_remap_opsto hook into an implementation specific implementation.I have done basic testing on this patch-set on a VT-d machine with interrupt remapping and found no regression so far. But as usual this doesn't mean that there is none ;-)
Anyway, since I am on vacation soon I sent out these patches to receive all kinds of comments so that I can start over to add the AMD part when I am back.
Thanks,
Joerg
Diffstat:
arch/ia64/include/asm/intr_remapping.h | 4 +
arch/x86/include/asm/intr_remapping.h| 101 +++arch/x86/include/asm/irq_remapping.h| 45 --arch/x86/kernel/apic/apic.c| 20 +-arch/x86/kernel/apic/io_apic.c| 276 ++-------drivers/iommu/Makefile| 2 +-drivers/iommu/amd_iommu_init.c| 123 +++--drivers/iommu/dmar.c| 1 +drivers/iommu/intel-iommu.c| 1 +drivers/iommu/intel_intr_remapping.c| 1065 ++++++++++++++++++++++++++++++++drivers/iommu/intr_remapping.c| 810 +++----------------------drivers/iommu/intr_remapping.h| 97 +++-include/linux/amd-iommu.h| 2 +-include/linux/dmar.h| 85 ---
Quoted 1 line
14 files changed, 1469 insertions(+), 1163 deletions(-)
Yes, it is good clean up for ioapic.c at least.