Message signaled irq handling cleanups
cover Message signaled irq handling cleanups
The following patch set should be enough to clear up the outstanding issues with genirq on i386 and x86_64. This actually takes things a step farther and moves all of architecture dependencies I could find into the appropriate architecture.
So hopefully we are finally close enough that other architectures will be able implement msi support, without too much trouble.
msi: Simplify msi sanity checks by adding with generic irq code.
msi: Only use a single irq_chip for msi interrupts
msi: Refactor and move the msi irq_chip into the arch code.
msi: Move the ia64 code into arch/ia64
htirq: Tidy up the htirq code
Eric
PATCH 1/5 msi: Simplify msi sanity checks by adding with generic irq code.
Currently msi.c is doing sanity checks that make certain before an irq is destroyed it has no more users.
By adding irq_has_action I can perform the test is a generic way, instead of relying on a msi specific data structure.
By performing the core check in dynamic_irq_cleanup I ensure every user of dynamic irqs has a test present and we don't free resources that are in use.
In msi.c this allows me to kill the attrib.state member of msi_desc and all of the assciated code to maintain it.
To keep from freeing data structures when irq cleanup code is called to soon changing dyanamic_irq_cleanup is insufficient because there are msi specific data structures that are also not safe to free.
--- drivers/pci/msi.c | 43 ++++++++----------------------------------- drivers/pci/msi.h | 2 +- include/linux/irq.h | 7 +++++++ kernel/irq/chip.c | 7 +++++++ 4 files changed, 23 insertions(+), 36 deletions(-)
drivers/pci/msi.c +8 -35
@@ -188,18 +188,6 @@ static void unmask_MSI_irq(unsigned intstatic unsigned int startup_msi_irq_wo_maskbit (unsigned int irq) { -struct msi_desc *entry; -unsigned long flags; - -spin_lock_irqsave (&msi_lock, flags); - entry = msi_desc[irq]; -if (!entry || !entry->dev) { -spin_unlock_irqrestore (&msi_lock, flags); -return 0 ; - } - entry->msi_attrib.state =1 ;/* Mark it active */ -spin_unlock_irqrestore (&msi_lock, flags); -return 0 ;/* never anything pending */ }
@@ -212,14 +200,6 @@ static unsigned int startup_msi_irq_w_mastatic void shutdown_msi_irq (unsigned int irq) { -struct msi_desc *entry; -unsigned long flags; - -spin_lock_irqsave (&msi_lock, flags); - entry = msi_desc[irq]; -if (entry && entry->dev) - entry->msi_attrib.state =0 ;/* Mark it not active */ -spin_unlock_irqrestore (&msi_lock, flags); }static void end_msi_irq_wo_maskbit (unsigned int irq)
@@ -671,7 +651,6 @@ static int msi_capability_init(struct pc entry->link.head = irq; entry->link.tail = irq; entry->msi_attrib.type =PCI_CAP_ID_MSI ; - entry->msi_attrib.state =0 ;/* Mark it not active */ entry->msi_attrib.is_64 =is_64bit_address (control); entry->msi_attrib.entry_nr =0 ; entry->msi_attrib.maskbit =is_mask_bit_support (control);
@@ -744,7 +723,6 @@ static int msix_capability_init(struct p j = entries[i].entry; entries[i].vector = irq; entry->msi_attrib.type =PCI_CAP_ID_MSIX ; - entry->msi_attrib.state =0 ;/* Mark it not active */ entry->msi_attrib.is_64 =1 ; entry->msi_attrib.entry_nr = j; entry->msi_attrib.maskbit =1 ;
@@ -897,12 +875,12 @@ void pci_disable_msi(struct pci_dev* devspin_unlock_irqrestore (&msi_lock, flags);return ; } -if (entry->msi_attrib.state) { +if (irq_has_action (dev->irq)) {spin_unlock_irqrestore (&msi_lock, flags);printk (KERN_WARNING "PCI: %s: pci_disable_msi() called without " "free_irq() on MSI irq %d\n" ,pci_name (dev), dev->irq); -BUG_ON (entry->msi_attrib.state >0 ); +BUG_ON (irq_has_action (dev->irq)); }else { default_irq = entry->msi_attrib.default_irq;spin_unlock_irqrestore (&msi_lock, flags);
@@ -1035,17 +1013,16 @@ void pci_disable_msix(struct pci_dev* de temp = dev->irq;if (!msi_lookup_irq (dev,PCI_CAP_ID_MSIX )) { -int state, irq, head, tail =0 , warning =0 ; +int irq, head, tail =0 , warning =0 ;unsigned long flags; irq = head = dev->irq; dev->irq = temp;/* Restore pin IRQ */ while (head != tail) {spin_lock_irqsave (&msi_lock, flags); - state = msi_desc[irq]->msi_attrib.state; tail = msi_desc[irq]->link.tail;spin_unlock_irqrestore (&msi_lock, flags); -if (state) +if (irq_has_action (irq)) warning =1 ;else if (irq != head)/* Release MSI-X irq */ msi_free_irq (dev, irq);
@@ -1072,7 +1049,7 @@ void pci_disable_msix(struct pci_dev* de**/ void msi_remove_pci_irq_vectors (struct pci_dev * dev) { -int state, pos, temp; +int pos, temp;unsigned long flags;if (!pci_msi_enable || !dev)
@@ -1081,14 +1058,11 @@ void msi_remove_pci_irq_vectors(struct p temp = dev->irq;/* Save IOAPIC IRQ */ pos =pci_find_capability (dev,PCI_CAP_ID_MSI );if (pos >0 && !msi_lookup_irq (dev,PCI_CAP_ID_MSI )) { -spin_lock_irqsave (&msi_lock, flags); - state = msi_desc[dev->irq]->msi_attrib.state; -spin_unlock_irqrestore (&msi_lock, flags); -if (state) { +if (irq_has_action (dev->irq)) {printk (KERN_WARNING "PCI: %s: msi_remove_pci_irq_vectors() " "called without free_irq() on MSI irq %d\n" ,pci_name (dev), dev->irq); -BUG_ON (state >0 ); +BUG_ON (irq_has_action (dev->irq)); }else /* Release MSI irq assigned to this device */ msi_free_irq (dev, dev->irq); dev->irq = temp;/* Restore IOAPIC IRQ */
@@ -1101,11 +1075,10 @@ void msi_remove_pci_irq_vectors(struct p irq = head = dev->irq;while (head != tail) {spin_lock_irqsave (&msi_lock, flags); - state = msi_desc[irq]->msi_attrib.state; tail = msi_desc[irq]->link.tail; base = msi_desc[irq]->mask_base;spin_unlock_irqrestore (&msi_lock, flags); -if (state) +if (irq_has_action (irq)) warning =1 ;else if (irq != head)/* Release MSI-X irq */ msi_free_irq (dev, irq);
drivers/pci/msi.h +1 -1
@@ -53,7 +53,7 @@ struct msi_desc {struct {__u8 type :5 ;/* {0: unused, 5h:MSI, 11h:MSI-X} */ __u8 maskbit :1 ;/* mask-pending bit supported ? */ -__u8 state :1 ;/* {0: free, 1: busy} */ +__u8 unused :1 ;__u8 is_64 :1 ;/* Address size: 0=32bit 1=64bit */ __u8 pos;/* Location of the msi capability */ __u16 entry_nr;/* specific enabled entry */
include/linux/irq.h +7 -0
@@ -373,6 +373,13 @@ set_irq_chained_handler(unsigned int irqextern int create_irq (void );extern void destroy_irq (unsigned int irq); +/* Test to see if a driver has successfully requested an irq */ +static inline int irq_has_action (unsigned int irq) +{ +struct irq_desc *desc = irq_desc + irq; +return desc->action !=NULL ; +} +/* Dynamic irq helper functions */ extern void dynamic_irq_init (unsigned int irq);extern void dynamic_irq_cleanup (unsigned int irq);
kernel/irq/chip.c +7 -0
@@ -151,6 +151,13 @@ void dynamic_irq_cleanup(unsigned int ir desc = irq_desc + irq;spin_lock_irqsave (&desc->lock, flags); +if (desc->action) { +spin_unlock_irqrestore (&desc->lock, flags); +printk (KERN_ERR "Destroying IRQ%d without calling free_irq\n" , + irq); +WARN_ON (1 ); +return ; + } desc->handle_irq = handle_bad_irq; desc->chip = &no_irq_chip;spin_unlock_irqrestore (&desc->lock, flags);
Signature · 1 line
1.4.2.rc3.g7e18e-dirty
PATCH 2/5 msi: Only use a single irq_chip for msi interrupts
In reply to Eric W. BiedermanThe logic works like this.
Since we no longer track the state logic by hand in msi.c startup and shutdown are no longer needed.
By updating msi_set_mask_bit to work on msi devices that do not implement a mask bit we can always call the mask/unmask functions.
What we really have are mask and unmask so we use them to implement the .mask and .unmask functions instead of .enable and .disable.
By switching to the handle_edge_irq handler we only need an ack function that moves the irq if necessary. Which removes the old end and ack functions and their peculiar logic of sometimes disabling an irq.
This removes the reliance on pre genirq irq handling methods.
--- drivers/pci/msi.c | 115 +++++++++++------------------------------------------ 1 files changed, 24 insertions(+), 91 deletions(-)
drivers/pci/msi.c +24 -91
@@ -53,21 +53,20 @@ static void msi_set_mask_bit(unsigned instruct msi_desc *entry; entry = msi_desc[irq]; -if (!entry || !entry->dev || !entry->mask_base) -return ; +BUG_ON (!entry || !entry->dev);switch (entry->msi_attrib.type) {case PCI_CAP_ID_MSI : - { -int pos; -u32 mask_bits; - - pos = (long )entry->mask_base; -pci_read_config_dword (entry->dev, pos, &mask_bits); - mask_bits &= ~(1 ); - mask_bits |= flag; -pci_write_config_dword (entry->dev, pos, mask_bits); +if (entry->msi_attrib.maskbit) { +int pos; +u32 mask_bits; + + pos = (long )entry->mask_base; +pci_read_config_dword (entry->dev, pos, &mask_bits); + mask_bits &= ~(1 ); + mask_bits |= flag; +pci_write_config_dword (entry->dev, pos, mask_bits); + }break ; - }case PCI_CAP_ID_MSIX : { int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE +
@@ -76,6 +75,7 @@ static void msi_set_mask_bit(unsigned inbreak ; }default : +BUG ();break ; } }
@@ -186,83 +186,21 @@ static void unmask_MSI_irq(unsigned intmsi_set_mask_bit (irq,0 ); } -static unsigned int startup_msi_irq_wo_maskbit (unsigned int irq) -{ -return 0 ;/* never anything pending */ -} - -static unsigned int startup_msi_irq_w_maskbit (unsigned int irq) -{ -startup_msi_irq_wo_maskbit (irq); -unmask_MSI_irq (irq); -return 0 ;/* never anything pending */ -} - -static void shutdown_msi_irq (unsigned int irq) -{ -} - -static void end_msi_irq_wo_maskbit (unsigned int irq) +static void ack_msi_irq (unsigned int irq) {move_native_irq (irq);ack_APIC_irq (); } -static void end_msi_irq_w_maskbit (unsigned int irq) -{ -move_native_irq (irq); -unmask_MSI_irq (irq); -ack_APIC_irq (); -} - -static void do_nothing (unsigned int irq) -{ -} - -/* -* Interrupt Type for MSI-X PCI/PCI-X/PCI-Express Devices, -* which implement the MSI-X Capability Structure. -*/ -static struct hw_interrupt_type msix_irq_type = { - .typename ="PCI-MSI-X" , - .startup = startup_msi_irq_w_maskbit, - .shutdown = shutdown_msi_irq, - .enable = unmask_MSI_irq, - .disable = mask_MSI_irq, - .ack = mask_MSI_irq, - .end = end_msi_irq_w_maskbit, - .set_affinity = set_msi_affinity -}; - -/* -* Interrupt Type for MSI PCI/PCI-X/PCI-Express Devices, -* which implement the MSI Capability Structure with -* Mask-and-Pending Bits. -*/ -static struct hw_interrupt_type msi_irq_w_maskbit_type = { - .typename ="PCI-MSI" , - .startup = startup_msi_irq_w_maskbit, - .shutdown = shutdown_msi_irq, - .enable = unmask_MSI_irq, - .disable = mask_MSI_irq, - .ack = mask_MSI_irq, - .end = end_msi_irq_w_maskbit, - .set_affinity = set_msi_affinity -}; -/* -* Interrupt Type for MSI PCI/PCI-X/PCI-Express Devices, -* which implement the MSI Capability Structure without -* Mask-and-Pending Bits. +* IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices, +* which implement the MSI or MSI-X Capability Structure. */ -static struct hw_interrupt_type msi_irq_wo_maskbit_type = { - .typename ="PCI-MSI" , - .startup = startup_msi_irq_wo_maskbit, - .shutdown = shutdown_msi_irq, - .enable = do_nothing, - .disable = do_nothing, - .ack = do_nothing, - .end = end_msi_irq_wo_maskbit, +static struct irq_chip msi_chip = { + .name ="PCI-MSI" , + .unmask = unmask_MSI_irq, + .mask = mask_MSI_irq, + .ack = ack_msi_irq, .set_affinity = set_msi_affinity };
@@ -330,7 +268,7 @@ static void attach_msi_entry(struct msi_spin_unlock_irqrestore (&msi_lock, flags); } -static int create_msi_irq (struct hw_interrupt_type *handler) +static int create_msi_irq (struct irq_chip *chip) {struct msi_desc *entry;int irq;
@@ -345,7 +283,7 @@ static int create_msi_irq(struct hw_intereturn -EBUSY ; } -set_irq_chip (irq, handler); +set_irq_chip_and_handler (irq, chip, handle_edge_irq);set_irq_data (irq, entry);return irq;
@@ -634,16 +572,11 @@ static int msi_capability_init(struct pcstruct msi_desc *entry;int pos, irq;u16 control; -struct hw_interrupt_type *handler; pos =pci_find_capability (dev,PCI_CAP_ID_MSI );pci_read_config_word (dev,msi_control_reg (pos), &control);/* MSI Entry Initialization */ - handler = &msi_irq_wo_maskbit_type; -if (is_mask_bit_support (control)) - handler = &msi_irq_w_maskbit_type; - - irq =create_msi_irq (handler); + irq =create_msi_irq (&msi_chip);if (irq <0 )return irq;
@@ -715,7 +648,7 @@ static int msix_capability_init(struct p/* MSI-X Table Initialization */ for (i =0 ; i < nvec; i++) { - irq =create_msi_irq (&msix_irq_type); + irq =create_msi_irq (&msi_chip);if (irq <0 )break ;
Signature · 1 line
1.4.2.rc3.g7e18e-dirty
PATCH 3/5 msi: Refactor and move the msi irq_chip into the arch code.
In reply to Eric W. BiedermanIt turns out msi_ops was simply not enough to abstract the architecture specific details of msi. So I have moved the resposibility of constructing the struct irq_chip to the architectures, and have two architecture specific functions arch_setup_msi_irq, and arch_teardown_msi_irq.
For simple architectures those functions can do all of the work. For architectures with platform dependencies they can call into the appropriate platform code.
With this msi.c is finally free of assuming you have an apic, and this actually takes less code.
The helpers for the architecture specific code are declared in the linux/msi.h to keep them separate from the msi functions used by drivers in linux/pci.h
--- arch/i386/kernel/io_apic.c | 81 +++++++++++++++------- arch/x86_64/kernel/io_apic.c | 89 +++++++++++++++++------- drivers/pci/msi-altix.c | 78 +++++++++++++-------- drivers/pci/msi-apic.c | 86 +++++++++++++++++------ drivers/pci/msi.c | 150 ++++++++-------------------------------- drivers/pci/msi.h | 27 ------- include/asm-i386/msi.h | 20 ----- include/asm-ia64/machvec.h | 21 ++++-- include/asm-ia64/machvec_sn2.h | 9 ++ include/asm-ia64/msi.h | 29 -------- include/asm-x86_64/msi.h | 21 ------ include/linux/msi.h | 49 +++++++++++++ include/linux/pci.h | 67 ------------------ 13 files changed, 333 insertions(+), 394 deletions(-)
arch/i386/kernel/io_apic.c +58 -23
@@ -32,6 +32,7 @@ #include <linux/acpi.h>#include <linux/module.h> #include <linux/sysdev.h> #include <linux/pci.h> +#include <linux/msi.h> #include <asm/io.h> #include <asm/smp.h>
@@ -2455,11 +2456,8 @@ #endif /* CONFIG_PCI_MSI */* MSI mesage composition */ #ifdef CONFIG_PCI_MSI -static int msi_msg_setup (struct pci_dev *pdev,unsigned int irq,struct msi_msg *msg) +static int msi_compose_msg (struct pci_dev *pdev,unsigned int irq,struct msi_msg *msg) { -/* For now always this code always uses physical delivery -* mode. -*/ int vector;unsigned dest;
@@ -2489,34 +2487,71 @@ static int msi_msg_setup(struct pci_devreturn vector; } -static void msi_msg_teardown (unsigned int irq) -{ -return ; -} - -static void msi_msg_set_affinity (unsigned int irq,cpumask_t mask,struct msi_msg *msg) +#ifdef CONFIG_SMP +static void set_msi_irq_affinity (unsigned int irq,cpumask_t mask) { +struct msi_msg msg; +unsigned int dest; +cpumask_t tmp;int vector; -unsigned dest; + +cpus_and (tmp, mask, cpu_online_map); +if (cpus_empty (tmp)) + tmp =TARGET_CPUS ; vector =assign_irq_vector (irq); -if (vector >0 ) { - dest =cpu_mask_to_apicid (mask); +if (vector <0 ) +return ; - msg->data &= ~MSI_DATA_VECTOR_MASK ; - msg->data |=MSI_DATA_VECTOR (vector); - msg->address_lo &= ~MSI_ADDR_DEST_ID_MASK ; - msg->address_lo |=MSI_ADDR_DEST_ID (dest); - } + dest =cpu_mask_to_apicid (mask); + +read_msi_msg (irq, &msg); + + msg.data &= ~MSI_DATA_VECTOR_MASK ; + msg.data |=MSI_DATA_VECTOR (vector); + msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK ; + msg.address_lo |=MSI_ADDR_DEST_ID (dest); + +write_msi_msg (irq, &msg); +set_native_irq_info (irq, mask); } +#endif /* CONFIG_SMP */ -struct msi_ops arch_msi_ops = { - .needs_64bit_address =0 , - .setup = msi_msg_setup, - .teardown = msi_msg_teardown, - .target = msi_msg_set_affinity, +/* +* IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices, +* which implement the MSI or MSI-X Capability Structure. +*/ +static struct irq_chip msi_chip = { + .name ="PCI-MSI" , + .unmask = unmask_msi_irq, + .mask = mask_msi_irq, + .ack = ack_ioapic_irq, +#ifdef CONFIG_SMP + .set_affinity = set_msi_irq_affinity, +#endif + .retrigger = ioapic_retrigger_irq, }; +int arch_setup_msi_irq (unsigned int irq,struct pci_dev *dev) +{ +struct msi_msg msg; +int ret; + ret =msi_compose_msg (dev, irq, &msg); +if (ret <0 ) +return ret; + +write_msi_msg (irq, &msg); + +set_irq_chip_and_handler (irq, &msi_chip, handle_edge_irq); + +return 0 ; +} + +void arch_teardown_msi_irq (unsigned int irq) +{ +return ; +} +#endif /* CONFIG_PCI_MSI */ /*
arch/x86_64/kernel/io_apic.c +62 -27
118 lines not on this page · raw message
drivers/pci/msi-altix.c +48 -30
144 lines not on this page · raw message
drivers/pci/msi-apic.c +64 -22
138 lines not on this page · raw message
drivers/pci/msi.c +31 -119
290 lines not on this page · raw message
drivers/pci/msi.h +0 -27
@@ -6,8 +6,6 @@#ifndef MSI_H #define MSI_H -#include <asm/msi.h> -/* * MSI-X Address Register */
@@ -49,29 +47,4 @@ #define msix_unmask(address) (address#define msix_mask (address) (address | PCI_MSIX_FLAGS_BITMASK)#define msix_is_pending (address) (address & PCI_MSIX_FLAGS_PENDMASK) -struct msi_desc { -struct { -__u8 type :5 ;/* {0: unused, 5h:MSI, 11h:MSI-X} */ -__u8 maskbit :1 ;/* mask-pending bit supported ? */ -__u8 unused :1 ; -__u8 is_64 :1 ;/* Address size: 0=32bit 1=64bit */ -__u8 pos;/* Location of the msi capability */ -__u16 entry_nr;/* specific enabled entry */ -unsigned default_irq;/* default pre-assigned irq */ - }msi_attrib; - -struct { -__u16 head; -__u16 tail; - }link; - -void __iomem *mask_base; -struct pci_dev *dev; - -#ifdef CONFIG_PM -/* PM save area for MSIX address/data */ -struct msi_msg msg_save; -#endif -}; -#endif /* MSI_H */
include/asm-i386/msi.h deleted +0 -20
@@ -1,20 +0,0 @@ -/* -* Copyright (C) 2003-2004 Intel -* Copyright (C) Tom Long Nguyen ([email protected]) -*/ - -#ifndef ASM_MSI_H -#define ASM_MSI_H - -#include <asm/desc.h> -#include <mach_apic.h> - -extern struct msi_ops arch_msi_ops; - -static inline int msi_arch_init (void ) -{ -msi_register (&arch_msi_ops); -return 0 ; -} - -#endif /* ASM_MSI_H */
include/asm-ia64/machvec.h +15 -6
@@ -20,6 +20,7 @@ struct page;struct mm_struct ;struct pci_bus ;struct task_struct ; +struct pci_dev ;typedef void ia64_mv_setup_t (char **);typedef void ia64_mv_cpu_init_t (void );
@@ -75,7 +76,9 @@ typedef unsigned char ia64_mv_readb_relatypedef unsigned short ia64_mv_readw_relaxed_t (const volatile void __iomem *);typedef unsigned int ia64_mv_readl_relaxed_t (const volatile void __iomem *);typedef unsigned long ia64_mv_readq_relaxed_t (const volatile void __iomem *); -typedef int ia64_mv_msi_init_t (void ); + +typedef int ia64_mv_setup_msi_irq_t (unsigned int irq,struct pci_dev *pdev); +typedef void ia64_mv_teardown_msi_irq_t (unsigned int irq);static inline void machvec_noop (void )
@@ -154,7 +157,8 @@ # define platform_readw_relaxed# define platform_readl_relaxed ia64_mv.readl_relaxed# define platform_readq_relaxed ia64_mv.readq_relaxed# define platform_migrate ia64_mv.migrate -# define platform_msi_init ia64_mv.msi_init +# define platform_setup_msi_irq ia64_mv.setup_msi_irq +# define platform_teardown_msi_irq ia64_mv.teardown_msi_irq# endif /* __attribute__((__aligned__(16))) is required to make size of the
@@ -204,7 +208,8 @@ struct ia64_machine_vector {ia64_mv_readl_relaxed_t *readl_relaxed;ia64_mv_readq_relaxed_t *readq_relaxed;ia64_mv_migrate_t *migrate; -ia64_mv_msi_init_t *msi_init; +ia64_mv_setup_msi_irq_t *setup_msi_irq; +ia64_mv_teardown_msi_irq_t *teardown_msi_irq; } __attribute__((__aligned__(16))); /* align attrib? see above comment */#define MACHVEC_INIT (name) \
@@ -250,7 +255,8 @@ #define MACHVEC_INIT(name) \ platform_readl_relaxed, \ platform_readq_relaxed, \ platform_migrate, \ - platform_msi_init, \ + platform_setup_msi_irq, \ + platform_teardown_msi_irq, \ } extern struct ia64_machine_vector ia64_mv;
@@ -404,8 +410,11 @@ #endif#ifndef platform_migrate# define platform_migrate machvec_noop_task#endif -#ifndef platform_msi_init -# define platform_msi_init ((ia64_mv_msi_init_t*)NULL) +#ifndef platform_setup_msi_irq +# define platform_setup_msi_irq ((ia64_mv_setup_msi_irq_t*)NULL) +#endif +#ifndef platform_teardown_msi_irq +# define platform_teardown_msi_irq ((ia64_mv_teardown_msi_irq_t*)NULL)#endif #endif /* _ASM_IA64_MACHVEC_H */
include/asm-ia64/machvec_sn2.h +6 -3
@@ -67,7 +67,8 @@ extern ia64_mv_dma_sync_sg_for_device snextern ia64_mv_dma_mapping_error sn_dma_mapping_error;extern ia64_mv_dma_supported sn_dma_supported;extern ia64_mv_migrate_t sn_migrate; -extern ia64_mv_msi_init_t sn_msi_init; +extern ia64_mv_setup_msi_irq_t sn_setup_msi_irq; +extern ia64_mv_teardown_msi_irq_t sn_teardown_msi_irq;/*
@@ -120,9 +121,11 @@ #define platform_dma_mapping_error sn_d#define platform_dma_supported sn_dma_supported#define platform_migrate sn_migrate#ifdef CONFIG_PCI_MSI -#define platform_msi_init sn_msi_init +#define platform_setup_msi_irq sn_setup_msi_irq +#define platform_teardown_msi_irq sn_teardown_msi_irq#else -#define platform_msi_init ((ia64_mv_msi_init_t*)NULL) +#define platform_setup_msi_irq ((ia64_mv_setup_msi_irq_t*)NULL) +#define platform_teardown_msi_irq ((ia64_mv_teardown_msi_irq_t*)NULL)#endif #include <asm/sn/io.h>
include/asm-ia64/msi.h deleted +0 -29
@@ -1,29 +0,0 @@ -/* -* Copyright (C) 2003-2004 Intel -* Copyright (C) Tom Long Nguyen ([email protected]) -*/ - -#ifndef ASM_MSI_H -#define ASM_MSI_H - -#define NR_VECTORS NR_IRQS -#define FIRST_DEVICE_VECTOR IA64_FIRST_DEVICE_VECTOR -#define LAST_DEVICE_VECTOR IA64_LAST_DEVICE_VECTOR -static inline void set_intr_gate (int nr,void *func) {} -#define IO_APIC_VECTOR (irq) (irq) -#define ack_APIC_irq ia64_eoi -#define MSI_TARGET_CPU_SHIFT 4 - -extern struct msi_ops msi_apic_ops; - -static inline int msi_arch_init (void ) -{ -if (platform_msi_init) -return platform_msi_init (); - -/* default ops for most ia64 platforms */ -msi_register (&msi_apic_ops); -return 0 ; -} - -#endif /* ASM_MSI_H */
include/asm-x86_64/msi.h deleted +0 -21
@@ -1,21 +0,0 @@ -/* -* Copyright (C) 2003-2004 Intel -* Copyright (C) Tom Long Nguyen ([email protected]) -*/ - -#ifndef ASM_MSI_H -#define ASM_MSI_H - -#include <asm/desc.h> -#include <asm/mach_apic.h> -#include <asm/smp.h> - -extern struct msi_ops arch_msi_ops; - -static inline int msi_arch_init (void ) -{ -msi_register (&arch_msi_ops); -return 0 ; -} - -#endif /* ASM_MSI_H */
include/linux/msi.h new file +49 -0
49 lines not on this page · raw message
include/linux/pci.h +0 -67
79 lines not on this page · raw message
Signature · 1 line
1.4.2.rc3.g7e18e-dirty
PATCH 4/5 msi: Move the ia64 code into arch/ia64
In reply to Eric W. BiedermanThis is just a few makefile tweaks and some file renames.
--- arch/ia64/kernel/Makefile | 1 arch/ia64/kernel/msi_ia64.c | 143 ++++++++++++++++++++++++++ arch/ia64/sn/kernel/Makefile | 1 arch/ia64/sn/kernel/msi_sn.c | 229 ++++++++++++++++++++++++++++++++++++++++++ drivers/pci/Makefile | 9 +- drivers/pci/msi-altix.c | 229 ------------------------------------------ drivers/pci/msi-apic.c | 143 -------------------------- 7 files changed, 377 insertions(+), 378 deletions(-)
arch/ia64/kernel/Makefile +1 -0
@@ -31,6 +31,7 @@ obj-$(CONFIG_KPROBES) += kprobes.o jpro obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o crash.o obj-$(CONFIG_IA64_UNCACHED_ALLOCATOR) += uncached.o obj-$(CONFIG_AUDIT) += audit.o +obj-$(CONFIG_PCI_MSI) += msi_ia64.o mca_recovery-y += mca_drv.o mca_drv_asm.o obj-$(CONFIG_IA64_ESI) += esi.o
arch/ia64/kernel/msi_ia64.c new file +143 -0
143 lines not on this page · raw message
arch/ia64/sn/kernel/Makefile +1 -0
@@ -19,3 +19,4 @@ xp-y := xp_main.o xp_nofault.o obj-$(CONFIG_IA64_SGI_SN_XP) += xpc.o xpc-y := xpc_main.o xpc_channel.o xpc_partition.o obj-$(CONFIG_IA64_SGI_SN_XP) += xpnet.o +obj-$(CONFIG_PCI_MSI) += msi_sn.o
arch/ia64/sn/kernel/msi_sn.c new file +229 -0
229 lines not on this page · raw message
drivers/pci/Makefile +3 -6
@@ -14,6 +14,9 @@ obj-$(CONFIG_HOTPLUG) += hotplug.o # Build the PCI Hotplug drivers if we were asked to obj-$(CONFIG_HOTPLUG_PCI) += hotplug/ +# Build the PCI MSI interrupt support +obj-$(CONFIG_PCI_MSI) += msi.o + # # Some architectures use the generic PCI setup functions #
@@ -28,12 +31,6 @@ obj-$(CONFIG_MIPS) += setup-bus.o setup- obj-$(CONFIG_X86_VISWS) += setup-irq.o obj-$(CONFIG_HT_IRQ) += htirq.o -msiobj-y := msi.o -msiobj-$(CONFIG_IA64) += msi-apic.o -msiobj-$(CONFIG_IA64_GENERIC) += msi-altix.o -msiobj-$(CONFIG_IA64_SGI_SN2) += msi-altix.o -obj-$(CONFIG_PCI_MSI) += $(msiobj-y) - # # ACPI Related PCI FW Functions #
drivers/pci/msi-altix.c deleted +0 -229
229 lines not on this page · raw message
drivers/pci/msi-apic.c deleted +0 -143
143 lines not on this page · raw message
Signature · 1 line
1.4.2.rc3.g7e18e-dirty
PATCH 5/5 htirq: Tidy up the htirq code
In reply to Eric W. BiedermanThis moves the declarations for the architecture helpers into include/linux/htirq.h from the generic include/linux/pci.h. Hopefully this will make this distinction clearer.
htirq.h is included where it is needed.
The dependency on the msi code is fixed and removed.
The Makefile is tidied up.
--- arch/i386/kernel/io_apic.c | 5 ++--- arch/x86_64/kernel/io_apic.c | 1 + drivers/pci/Kconfig | 1 - drivers/pci/Makefile | 4 +++- drivers/pci/htirq.c | 1 + include/linux/htirq.h | 15 +++++++++++++++ include/linux/pci.h | 11 ----------- 7 files changed, 22 insertions(+), 16 deletions(-)
arch/i386/kernel/io_apic.c +2 -3
@@ -33,6 +33,7 @@ #include <linux/module.h>#include <linux/sysdev.h> #include <linux/pci.h> #include <linux/msi.h> +#include <linux/htirq.h> #include <asm/io.h> #include <asm/smp.h>
@@ -2409,9 +2410,8 @@ static int __init ioapic_init_sysfs(voiddevice_initcall (ioapic_init_sysfs); -#ifdef CONFIG_PCI_MSI /* -* Dynamic irq allocate and deallocation for MSI +* Dynamic irq allocate and deallocation */ int create_irq (void ) {
@@ -2450,7 +2450,6 @@ void destroy_irq(unsigned int irq) irq_vector[irq] =0 ;spin_unlock_irqrestore (&vector_lock, flags); } -#endif /* CONFIG_PCI_MSI */ /* * MSI mesage composition
arch/x86_64/kernel/io_apic.c +1 -0
@@ -31,6 +31,7 @@ #include <linux/mc146818rtc.h>#include <linux/acpi.h> #include <linux/sysdev.h> #include <linux/msi.h> +#include <linux/htirq.h> #ifdef CONFIG_ACPI #include <acpi/acpi_bus.h> #endif
drivers/pci/Kconfig +0 -1
@@ -55,7 +55,6 @@ config PCI_DEBUG config HT_IRQ bool "Interrupts on hypertransport devices" default y - depends on PCI_MSI depends on X86_LOCAL_APIC && X86_IO_APIC help This allows native hypertransport devices to use interrupts.
drivers/pci/Makefile +3 -1
@@ -17,6 +17,9 @@ obj-$(CONFIG_HOTPLUG_PCI) += hotplug/ # Build the PCI MSI interrupt support obj-$(CONFIG_PCI_MSI) += msi.o +# Build the Hypertransport interrupt support +obj-$(CONFIG_HT_IRQ) += htirq.o + # # Some architectures use the generic PCI setup functions #
@@ -29,7 +32,6 @@ obj-$(CONFIG_PPC32) += setup-irq.o obj-$(CONFIG_PPC64) += setup-bus.o obj-$(CONFIG_MIPS) += setup-bus.o setup-irq.o obj-$(CONFIG_X86_VISWS) += setup-irq.o -obj-$(CONFIG_HT_IRQ) += htirq.o # # ACPI Related PCI FW Functions
drivers/pci/htirq.c +1 -0
@@ -11,6 +11,7 @@ #include <linux/pci.h>#include <linux/spinlock.h> #include <linux/slab.h> #include <linux/gfp.h> +#include <linux/htirq.h> /* Global ht irq lock. *
include/linux/htirq.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef LINUX_HTIRQ_H +#define LINUX_HTIRQ_H + +/* Helper functions.. */ +void write_ht_irq_low (unsigned int irq,u32 data); +void write_ht_irq_high (unsigned int irq,u32 data); +u32 read_ht_irq_low (unsigned int irq); +u32 read_ht_irq_high (unsigned int irq); +void mask_ht_irq (unsigned int irq); +void unmask_ht_irq (unsigned int irq); + +/* The arch hook for getting things started */ +int arch_setup_ht_irq (unsigned int irq,struct pci_dev *dev); + +#endif /* LINUX_HTIRQ_H */
include/linux/pci.h +0 -11
@@ -619,20 +619,9 @@ extern void msi_remove_pci_irq_vectors(s#endif #ifdef CONFIG_HT_IRQ -/* Helper functions.. */ -void write_ht_irq_low (unsigned int irq,u32 data); -void write_ht_irq_high (unsigned int irq,u32 data); -u32 read_ht_irq_low (unsigned int irq); -u32 read_ht_irq_high (unsigned int irq); -void mask_ht_irq (unsigned int irq); -void unmask_ht_irq (unsigned int irq); -/* The functions a driver should call */ int ht_create_irq (struct pci_dev *dev,int idx);void ht_destroy_irq (unsigned int irq); - -/* The arch hook for getting things started */ -int arch_setup_ht_irq (unsigned int irq,struct pci_dev *dev);#endif /* CONFIG_HT_IRQ */ extern void pci_block_user_cfg_access (struct pci_dev *dev);
Signature · 1 line
1.4.2.rc3.g7e18e-dirty
Quoted 8 lines · [email protected] (Eric W. Biederman) writes:
The following patch set should be enough to clear up the outstanding issues with genirq on i386 and
x86_64. This actually takes things a step farther and moves all of architecture dependencies I could find into the appropriate architecture.So hopefully we are finally close enough that other architectures will be able implement msi support, without too much trouble.
Quoted 7 lines
msi: Simplify msi sanity checks by adding with generic irq code.
msi: Only use a singleirq_chipfor msi interrupts
msi: Refactor and move the msiirq_chipinto the arch code.
msi: Move the ia64 code intoarch/ia64
htirq: Tidy up the htirq codeEric
Grr.. My ia64 compiler is way too slow. It just told me I had some
trivial bugs in the altix portion of what I posted. Sorry I forgot
to mention all I can do is compile test ia64.
So here comes a second time with code that actually compiles :)
Darn this code that is so ugly that you have to test the cleanup on multiple architectures!
Eric
PATCH 1/5 msi: Simplify msi sanity checks by adding with generic irq code.
Currently msi.c is doing sanity checks that make certain before an irq is destroyed it has no more users.
By adding irq_has_action I can perform the test is a generic way, instead of relying on a msi specific data structure.
By performing the core check in dynamic_irq_cleanup I ensure every user of dynamic irqs has a test present and we don't free resources that are in use.
In msi.c this allows me to kill the attrib.state member of msi_desc and all of the assciated code to maintain it.
To keep from freeing data structures when irq cleanup code is called to soon changing dyanamic_irq_cleanup is insufficient because there are msi specific data structures that are also not safe to free.
--- drivers/pci/msi.c | 43 ++++++++----------------------------------- drivers/pci/msi.h | 2 +- include/linux/irq.h | 7 +++++++ kernel/irq/chip.c | 7 +++++++ 4 files changed, 23 insertions(+), 36 deletions(-)
drivers/pci/msi.c +8 -35
@@ -188,18 +188,6 @@ static void unmask_MSI_irq(unsigned intstatic unsigned int startup_msi_irq_wo_maskbit (unsigned int irq) { -struct msi_desc *entry; -unsigned long flags; - -spin_lock_irqsave (&msi_lock, flags); - entry = msi_desc[irq]; -if (!entry || !entry->dev) { -spin_unlock_irqrestore (&msi_lock, flags); -return 0 ; - } - entry->msi_attrib.state =1 ;/* Mark it active */ -spin_unlock_irqrestore (&msi_lock, flags); -return 0 ;/* never anything pending */ }
@@ -212,14 +200,6 @@ static unsigned int startup_msi_irq_w_mastatic void shutdown_msi_irq (unsigned int irq) { -struct msi_desc *entry; -unsigned long flags; - -spin_lock_irqsave (&msi_lock, flags); - entry = msi_desc[irq]; -if (entry && entry->dev) - entry->msi_attrib.state =0 ;/* Mark it not active */ -spin_unlock_irqrestore (&msi_lock, flags); }static void end_msi_irq_wo_maskbit (unsigned int irq)
@@ -671,7 +651,6 @@ static int msi_capability_init(struct pc entry->link.head = irq; entry->link.tail = irq; entry->msi_attrib.type =PCI_CAP_ID_MSI ; - entry->msi_attrib.state =0 ;/* Mark it not active */ entry->msi_attrib.is_64 =is_64bit_address (control); entry->msi_attrib.entry_nr =0 ; entry->msi_attrib.maskbit =is_mask_bit_support (control);
@@ -744,7 +723,6 @@ static int msix_capability_init(struct p j = entries[i].entry; entries[i].vector = irq; entry->msi_attrib.type =PCI_CAP_ID_MSIX ; - entry->msi_attrib.state =0 ;/* Mark it not active */ entry->msi_attrib.is_64 =1 ; entry->msi_attrib.entry_nr = j; entry->msi_attrib.maskbit =1 ;
@@ -897,12 +875,12 @@ void pci_disable_msi(struct pci_dev* devspin_unlock_irqrestore (&msi_lock, flags);return ; } -if (entry->msi_attrib.state) { +if (irq_has_action (dev->irq)) {spin_unlock_irqrestore (&msi_lock, flags);printk (KERN_WARNING "PCI: %s: pci_disable_msi() called without " "free_irq() on MSI irq %d\n" ,pci_name (dev), dev->irq); -BUG_ON (entry->msi_attrib.state >0 ); +BUG_ON (irq_has_action (dev->irq)); }else { default_irq = entry->msi_attrib.default_irq;spin_unlock_irqrestore (&msi_lock, flags);
@@ -1035,17 +1013,16 @@ void pci_disable_msix(struct pci_dev* de temp = dev->irq;if (!msi_lookup_irq (dev,PCI_CAP_ID_MSIX )) { -int state, irq, head, tail =0 , warning =0 ; +int irq, head, tail =0 , warning =0 ;unsigned long flags; irq = head = dev->irq; dev->irq = temp;/* Restore pin IRQ */ while (head != tail) {spin_lock_irqsave (&msi_lock, flags); - state = msi_desc[irq]->msi_attrib.state; tail = msi_desc[irq]->link.tail;spin_unlock_irqrestore (&msi_lock, flags); -if (state) +if (irq_has_action (irq)) warning =1 ;else if (irq != head)/* Release MSI-X irq */ msi_free_irq (dev, irq);
@@ -1072,7 +1049,7 @@ void pci_disable_msix(struct pci_dev* de**/ void msi_remove_pci_irq_vectors (struct pci_dev * dev) { -int state, pos, temp; +int pos, temp;unsigned long flags;if (!pci_msi_enable || !dev)
@@ -1081,14 +1058,11 @@ void msi_remove_pci_irq_vectors(struct p temp = dev->irq;/* Save IOAPIC IRQ */ pos =pci_find_capability (dev,PCI_CAP_ID_MSI );if (pos >0 && !msi_lookup_irq (dev,PCI_CAP_ID_MSI )) { -spin_lock_irqsave (&msi_lock, flags); - state = msi_desc[dev->irq]->msi_attrib.state; -spin_unlock_irqrestore (&msi_lock, flags); -if (state) { +if (irq_has_action (dev->irq)) {printk (KERN_WARNING "PCI: %s: msi_remove_pci_irq_vectors() " "called without free_irq() on MSI irq %d\n" ,pci_name (dev), dev->irq); -BUG_ON (state >0 ); +BUG_ON (irq_has_action (dev->irq)); }else /* Release MSI irq assigned to this device */ msi_free_irq (dev, dev->irq); dev->irq = temp;/* Restore IOAPIC IRQ */
@@ -1101,11 +1075,10 @@ void msi_remove_pci_irq_vectors(struct p irq = head = dev->irq;while (head != tail) {spin_lock_irqsave (&msi_lock, flags); - state = msi_desc[irq]->msi_attrib.state; tail = msi_desc[irq]->link.tail; base = msi_desc[irq]->mask_base;spin_unlock_irqrestore (&msi_lock, flags); -if (state) +if (irq_has_action (irq)) warning =1 ;else if (irq != head)/* Release MSI-X irq */ msi_free_irq (dev, irq);
drivers/pci/msi.h +1 -1
@@ -53,7 +53,7 @@ struct msi_desc {struct {__u8 type :5 ;/* {0: unused, 5h:MSI, 11h:MSI-X} */ __u8 maskbit :1 ;/* mask-pending bit supported ? */ -__u8 state :1 ;/* {0: free, 1: busy} */ +__u8 unused :1 ;__u8 is_64 :1 ;/* Address size: 0=32bit 1=64bit */ __u8 pos;/* Location of the msi capability */ __u16 entry_nr;/* specific enabled entry */
include/linux/irq.h +7 -0
@@ -373,6 +373,13 @@ set_irq_chained_handler(unsigned int irqextern int create_irq (void );extern void destroy_irq (unsigned int irq); +/* Test to see if a driver has successfully requested an irq */ +static inline int irq_has_action (unsigned int irq) +{ +struct irq_desc *desc = irq_desc + irq; +return desc->action !=NULL ; +} +/* Dynamic irq helper functions */ extern void dynamic_irq_init (unsigned int irq);extern void dynamic_irq_cleanup (unsigned int irq);
kernel/irq/chip.c +7 -0
@@ -151,6 +151,13 @@ void dynamic_irq_cleanup(unsigned int ir desc = irq_desc + irq;spin_lock_irqsave (&desc->lock, flags); +if (desc->action) { +spin_unlock_irqrestore (&desc->lock, flags); +printk (KERN_ERR "Destroying IRQ%d without calling free_irq\n" , + irq); +WARN_ON (1 ); +return ; + } desc->handle_irq = handle_bad_irq; desc->chip = &no_irq_chip;spin_unlock_irqrestore (&desc->lock, flags);
Signature · 1 line
1.4.2.rc3.g7e18e-dirty
PATCH 2/5 msi: Only use a single irq_chip for msi interrupts
In reply to Eric W. BiedermanThe logic works like this.
Since we no longer track the state logic by hand in msi.c startup and shutdown are no longer needed.
By updating msi_set_mask_bit to work on msi devices that do not implement a mask bit we can always call the mask/unmask functions.
What we really have are mask and unmask so we use them to implement the .mask and .unmask functions instead of .enable and .disable.
By switching to the handle_edge_irq handler we only need an ack function that moves the irq if necessary. Which removes the old end and ack functions and their peculiar logic of sometimes disabling an irq.
This removes the reliance on pre genirq irq handling methods.
--- drivers/pci/msi.c | 115 +++++++++++------------------------------------------ 1 files changed, 24 insertions(+), 91 deletions(-)
drivers/pci/msi.c +24 -91
@@ -53,21 +53,20 @@ static void msi_set_mask_bit(unsigned instruct msi_desc *entry; entry = msi_desc[irq]; -if (!entry || !entry->dev || !entry->mask_base) -return ; +BUG_ON (!entry || !entry->dev);switch (entry->msi_attrib.type) {case PCI_CAP_ID_MSI : - { -int pos; -u32 mask_bits; - - pos = (long )entry->mask_base; -pci_read_config_dword (entry->dev, pos, &mask_bits); - mask_bits &= ~(1 ); - mask_bits |= flag; -pci_write_config_dword (entry->dev, pos, mask_bits); +if (entry->msi_attrib.maskbit) { +int pos; +u32 mask_bits; + + pos = (long )entry->mask_base; +pci_read_config_dword (entry->dev, pos, &mask_bits); + mask_bits &= ~(1 ); + mask_bits |= flag; +pci_write_config_dword (entry->dev, pos, mask_bits); + }break ; - }case PCI_CAP_ID_MSIX : { int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE +
@@ -76,6 +75,7 @@ static void msi_set_mask_bit(unsigned inbreak ; }default : +BUG ();break ; } }
@@ -186,83 +186,21 @@ static void unmask_MSI_irq(unsigned intmsi_set_mask_bit (irq,0 ); } -static unsigned int startup_msi_irq_wo_maskbit (unsigned int irq) -{ -return 0 ;/* never anything pending */ -} - -static unsigned int startup_msi_irq_w_maskbit (unsigned int irq) -{ -startup_msi_irq_wo_maskbit (irq); -unmask_MSI_irq (irq); -return 0 ;/* never anything pending */ -} - -static void shutdown_msi_irq (unsigned int irq) -{ -} - -static void end_msi_irq_wo_maskbit (unsigned int irq) +static void ack_msi_irq (unsigned int irq) {move_native_irq (irq);ack_APIC_irq (); } -static void end_msi_irq_w_maskbit (unsigned int irq) -{ -move_native_irq (irq); -unmask_MSI_irq (irq); -ack_APIC_irq (); -} - -static void do_nothing (unsigned int irq) -{ -} - -/* -* Interrupt Type for MSI-X PCI/PCI-X/PCI-Express Devices, -* which implement the MSI-X Capability Structure. -*/ -static struct hw_interrupt_type msix_irq_type = { - .typename ="PCI-MSI-X" , - .startup = startup_msi_irq_w_maskbit, - .shutdown = shutdown_msi_irq, - .enable = unmask_MSI_irq, - .disable = mask_MSI_irq, - .ack = mask_MSI_irq, - .end = end_msi_irq_w_maskbit, - .set_affinity = set_msi_affinity -}; - -/* -* Interrupt Type for MSI PCI/PCI-X/PCI-Express Devices, -* which implement the MSI Capability Structure with -* Mask-and-Pending Bits. -*/ -static struct hw_interrupt_type msi_irq_w_maskbit_type = { - .typename ="PCI-MSI" , - .startup = startup_msi_irq_w_maskbit, - .shutdown = shutdown_msi_irq, - .enable = unmask_MSI_irq, - .disable = mask_MSI_irq, - .ack = mask_MSI_irq, - .end = end_msi_irq_w_maskbit, - .set_affinity = set_msi_affinity -}; -/* -* Interrupt Type for MSI PCI/PCI-X/PCI-Express Devices, -* which implement the MSI Capability Structure without -* Mask-and-Pending Bits. +* IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices, +* which implement the MSI or MSI-X Capability Structure. */ -static struct hw_interrupt_type msi_irq_wo_maskbit_type = { - .typename ="PCI-MSI" , - .startup = startup_msi_irq_wo_maskbit, - .shutdown = shutdown_msi_irq, - .enable = do_nothing, - .disable = do_nothing, - .ack = do_nothing, - .end = end_msi_irq_wo_maskbit, +static struct irq_chip msi_chip = { + .name ="PCI-MSI" , + .unmask = unmask_MSI_irq, + .mask = mask_MSI_irq, + .ack = ack_msi_irq, .set_affinity = set_msi_affinity };
@@ -330,7 +268,7 @@ static void attach_msi_entry(struct msi_spin_unlock_irqrestore (&msi_lock, flags); } -static int create_msi_irq (struct hw_interrupt_type *handler) +static int create_msi_irq (struct irq_chip *chip) {struct msi_desc *entry;int irq;
@@ -345,7 +283,7 @@ static int create_msi_irq(struct hw_intereturn -EBUSY ; } -set_irq_chip (irq, handler); +set_irq_chip_and_handler (irq, chip, handle_edge_irq);set_irq_data (irq, entry);return irq;
@@ -634,16 +572,11 @@ static int msi_capability_init(struct pcstruct msi_desc *entry;int pos, irq;u16 control; -struct hw_interrupt_type *handler; pos =pci_find_capability (dev,PCI_CAP_ID_MSI );pci_read_config_word (dev,msi_control_reg (pos), &control);/* MSI Entry Initialization */ - handler = &msi_irq_wo_maskbit_type; -if (is_mask_bit_support (control)) - handler = &msi_irq_w_maskbit_type; - - irq =create_msi_irq (handler); + irq =create_msi_irq (&msi_chip);if (irq <0 )return irq;
@@ -715,7 +648,7 @@ static int msix_capability_init(struct p/* MSI-X Table Initialization */ for (i =0 ; i < nvec; i++) { - irq =create_msi_irq (&msix_irq_type); + irq =create_msi_irq (&msi_chip);if (irq <0 )break ;
Signature · 1 line
1.4.2.rc3.g7e18e-dirty
PATCH 3/5 msi: Refactor and move the msi irq_chip into the arch code.
In reply to Eric W. BiedermanIt turns out msi_ops was simply not enough to abstract the architecture specific details of msi. So I have moved the resposibility of constructing the struct irq_chip to the architectures, and have two architecture specific functions arch_setup_msi_irq, and arch_teardown_msi_irq.
For simple architectures those functions can do all of the work. For architectures with platform dependencies they can call into the appropriate platform code.
With this msi.c is finally free of assuming you have an apic, and this actually takes less code.
The helpers for the architecture specific code are declared in the linux/msi.h to keep them separate from the msi functions used by drivers in linux/pci.h
--- arch/i386/kernel/io_apic.c | 81 +++++++++++++++------- arch/x86_64/kernel/io_apic.c | 89 +++++++++++++++++------- drivers/pci/msi-altix.c | 81 +++++++++++++--------- drivers/pci/msi-apic.c | 86 +++++++++++++++++------ drivers/pci/msi.c | 150 ++++++++-------------------------------- drivers/pci/msi.h | 27 ------- include/asm-i386/msi.h | 20 ----- include/asm-ia64/machvec.h | 21 ++++-- include/asm-ia64/machvec_sn2.h | 9 ++ include/asm-ia64/msi.h | 29 -------- include/asm-x86_64/msi.h | 21 ------ include/linux/msi.h | 49 +++++++++++++ include/linux/pci.h | 67 ------------------ 13 files changed, 335 insertions(+), 395 deletions(-)
arch/i386/kernel/io_apic.c +58 -23
@@ -32,6 +32,7 @@ #include <linux/acpi.h>#include <linux/module.h> #include <linux/sysdev.h> #include <linux/pci.h> +#include <linux/msi.h> #include <asm/io.h> #include <asm/smp.h>
@@ -2455,11 +2456,8 @@ #endif /* CONFIG_PCI_MSI */* MSI mesage composition */ #ifdef CONFIG_PCI_MSI -static int msi_msg_setup (struct pci_dev *pdev,unsigned int irq,struct msi_msg *msg) +static int msi_compose_msg (struct pci_dev *pdev,unsigned int irq,struct msi_msg *msg) { -/* For now always this code always uses physical delivery -* mode. -*/ int vector;unsigned dest;
@@ -2489,34 +2487,71 @@ static int msi_msg_setup(struct pci_devreturn vector; } -static void msi_msg_teardown (unsigned int irq) -{ -return ; -} - -static void msi_msg_set_affinity (unsigned int irq,cpumask_t mask,struct msi_msg *msg) +#ifdef CONFIG_SMP +static void set_msi_irq_affinity (unsigned int irq,cpumask_t mask) { +struct msi_msg msg; +unsigned int dest; +cpumask_t tmp;int vector; -unsigned dest; + +cpus_and (tmp, mask, cpu_online_map); +if (cpus_empty (tmp)) + tmp =TARGET_CPUS ; vector =assign_irq_vector (irq); -if (vector >0 ) { - dest =cpu_mask_to_apicid (mask); +if (vector <0 ) +return ; - msg->data &= ~MSI_DATA_VECTOR_MASK ; - msg->data |=MSI_DATA_VECTOR (vector); - msg->address_lo &= ~MSI_ADDR_DEST_ID_MASK ; - msg->address_lo |=MSI_ADDR_DEST_ID (dest); - } + dest =cpu_mask_to_apicid (mask); + +read_msi_msg (irq, &msg); + + msg.data &= ~MSI_DATA_VECTOR_MASK ; + msg.data |=MSI_DATA_VECTOR (vector); + msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK ; + msg.address_lo |=MSI_ADDR_DEST_ID (dest); + +write_msi_msg (irq, &msg); +set_native_irq_info (irq, mask); } +#endif /* CONFIG_SMP */ -struct msi_ops arch_msi_ops = { - .needs_64bit_address =0 , - .setup = msi_msg_setup, - .teardown = msi_msg_teardown, - .target = msi_msg_set_affinity, +/* +* IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices, +* which implement the MSI or MSI-X Capability Structure. +*/ +static struct irq_chip msi_chip = { + .name ="PCI-MSI" , + .unmask = unmask_msi_irq, + .mask = mask_msi_irq, + .ack = ack_ioapic_irq, +#ifdef CONFIG_SMP + .set_affinity = set_msi_irq_affinity, +#endif + .retrigger = ioapic_retrigger_irq, }; +int arch_setup_msi_irq (unsigned int irq,struct pci_dev *dev) +{ +struct msi_msg msg; +int ret; + ret =msi_compose_msg (dev, irq, &msg); +if (ret <0 ) +return ret; + +write_msi_msg (irq, &msg); + +set_irq_chip_and_handler (irq, &msi_chip, handle_edge_irq); + +return 0 ; +} + +void arch_teardown_msi_irq (unsigned int irq) +{ +return ; +} +#endif /* CONFIG_PCI_MSI */ /*
arch/x86_64/kernel/io_apic.c +62 -27
118 lines not on this page · raw message
drivers/pci/msi-altix.c +50 -31
153 lines not on this page · raw message
drivers/pci/msi-apic.c +64 -22
138 lines not on this page · raw message
drivers/pci/msi.c +31 -119
290 lines not on this page · raw message
drivers/pci/msi.h +0 -27
@@ -6,8 +6,6 @@#ifndef MSI_H #define MSI_H -#include <asm/msi.h> -/* * MSI-X Address Register */
@@ -49,29 +47,4 @@ #define msix_unmask(address) (address#define msix_mask (address) (address | PCI_MSIX_FLAGS_BITMASK)#define msix_is_pending (address) (address & PCI_MSIX_FLAGS_PENDMASK) -struct msi_desc { -struct { -__u8 type :5 ;/* {0: unused, 5h:MSI, 11h:MSI-X} */ -__u8 maskbit :1 ;/* mask-pending bit supported ? */ -__u8 unused :1 ; -__u8 is_64 :1 ;/* Address size: 0=32bit 1=64bit */ -__u8 pos;/* Location of the msi capability */ -__u16 entry_nr;/* specific enabled entry */ -unsigned default_irq;/* default pre-assigned irq */ - }msi_attrib; - -struct { -__u16 head; -__u16 tail; - }link; - -void __iomem *mask_base; -struct pci_dev *dev; - -#ifdef CONFIG_PM -/* PM save area for MSIX address/data */ -struct msi_msg msg_save; -#endif -}; -#endif /* MSI_H */
include/asm-i386/msi.h deleted +0 -20
@@ -1,20 +0,0 @@ -/* -* Copyright (C) 2003-2004 Intel -* Copyright (C) Tom Long Nguyen ([email protected]) -*/ - -#ifndef ASM_MSI_H -#define ASM_MSI_H - -#include <asm/desc.h> -#include <mach_apic.h> - -extern struct msi_ops arch_msi_ops; - -static inline int msi_arch_init (void ) -{ -msi_register (&arch_msi_ops); -return 0 ; -} - -#endif /* ASM_MSI_H */
include/asm-ia64/machvec.h +15 -6
@@ -20,6 +20,7 @@ struct page;struct mm_struct ;struct pci_bus ;struct task_struct ; +struct pci_dev ;typedef void ia64_mv_setup_t (char **);typedef void ia64_mv_cpu_init_t (void );
@@ -75,7 +76,9 @@ typedef unsigned char ia64_mv_readb_relatypedef unsigned short ia64_mv_readw_relaxed_t (const volatile void __iomem *);typedef unsigned int ia64_mv_readl_relaxed_t (const volatile void __iomem *);typedef unsigned long ia64_mv_readq_relaxed_t (const volatile void __iomem *); -typedef int ia64_mv_msi_init_t (void ); + +typedef int ia64_mv_setup_msi_irq_t (unsigned int irq,struct pci_dev *pdev); +typedef void ia64_mv_teardown_msi_irq_t (unsigned int irq);static inline void machvec_noop (void )
@@ -154,7 +157,8 @@ # define platform_readw_relaxed# define platform_readl_relaxed ia64_mv.readl_relaxed# define platform_readq_relaxed ia64_mv.readq_relaxed# define platform_migrate ia64_mv.migrate -# define platform_msi_init ia64_mv.msi_init +# define platform_setup_msi_irq ia64_mv.setup_msi_irq +# define platform_teardown_msi_irq ia64_mv.teardown_msi_irq# endif /* __attribute__((__aligned__(16))) is required to make size of the
@@ -204,7 +208,8 @@ struct ia64_machine_vector {ia64_mv_readl_relaxed_t *readl_relaxed;ia64_mv_readq_relaxed_t *readq_relaxed;ia64_mv_migrate_t *migrate; -ia64_mv_msi_init_t *msi_init; +ia64_mv_setup_msi_irq_t *setup_msi_irq; +ia64_mv_teardown_msi_irq_t *teardown_msi_irq; } __attribute__((__aligned__(16))); /* align attrib? see above comment */#define MACHVEC_INIT (name) \
@@ -250,7 +255,8 @@ #define MACHVEC_INIT(name) \ platform_readl_relaxed, \ platform_readq_relaxed, \ platform_migrate, \ - platform_msi_init, \ + platform_setup_msi_irq, \ + platform_teardown_msi_irq, \ } extern struct ia64_machine_vector ia64_mv;
@@ -404,8 +410,11 @@ #endif#ifndef platform_migrate# define platform_migrate machvec_noop_task#endif -#ifndef platform_msi_init -# define platform_msi_init ((ia64_mv_msi_init_t*)NULL) +#ifndef platform_setup_msi_irq +# define platform_setup_msi_irq ((ia64_mv_setup_msi_irq_t*)NULL) +#endif +#ifndef platform_teardown_msi_irq +# define platform_teardown_msi_irq ((ia64_mv_teardown_msi_irq_t*)NULL)#endif #endif /* _ASM_IA64_MACHVEC_H */
include/asm-ia64/machvec_sn2.h +6 -3
@@ -67,7 +67,8 @@ extern ia64_mv_dma_sync_sg_for_device snextern ia64_mv_dma_mapping_error sn_dma_mapping_error;extern ia64_mv_dma_supported sn_dma_supported;extern ia64_mv_migrate_t sn_migrate; -extern ia64_mv_msi_init_t sn_msi_init; +extern ia64_mv_setup_msi_irq_t sn_setup_msi_irq; +extern ia64_mv_teardown_msi_irq_t sn_teardown_msi_irq;/*
@@ -120,9 +121,11 @@ #define platform_dma_mapping_error sn_d#define platform_dma_supported sn_dma_supported#define platform_migrate sn_migrate#ifdef CONFIG_PCI_MSI -#define platform_msi_init sn_msi_init +#define platform_setup_msi_irq sn_setup_msi_irq +#define platform_teardown_msi_irq sn_teardown_msi_irq#else -#define platform_msi_init ((ia64_mv_msi_init_t*)NULL) +#define platform_setup_msi_irq ((ia64_mv_setup_msi_irq_t*)NULL) +#define platform_teardown_msi_irq ((ia64_mv_teardown_msi_irq_t*)NULL)#endif #include <asm/sn/io.h>
include/asm-ia64/msi.h deleted +0 -29
@@ -1,29 +0,0 @@ -/* -* Copyright (C) 2003-2004 Intel -* Copyright (C) Tom Long Nguyen ([email protected]) -*/ - -#ifndef ASM_MSI_H -#define ASM_MSI_H - -#define NR_VECTORS NR_IRQS -#define FIRST_DEVICE_VECTOR IA64_FIRST_DEVICE_VECTOR -#define LAST_DEVICE_VECTOR IA64_LAST_DEVICE_VECTOR -static inline void set_intr_gate (int nr,void *func) {} -#define IO_APIC_VECTOR (irq) (irq) -#define ack_APIC_irq ia64_eoi -#define MSI_TARGET_CPU_SHIFT 4 - -extern struct msi_ops msi_apic_ops; - -static inline int msi_arch_init (void ) -{ -if (platform_msi_init) -return platform_msi_init (); - -/* default ops for most ia64 platforms */ -msi_register (&msi_apic_ops); -return 0 ; -} - -#endif /* ASM_MSI_H */
include/asm-x86_64/msi.h deleted +0 -21
@@ -1,21 +0,0 @@ -/* -* Copyright (C) 2003-2004 Intel -* Copyright (C) Tom Long Nguyen ([email protected]) -*/ - -#ifndef ASM_MSI_H -#define ASM_MSI_H - -#include <asm/desc.h> -#include <asm/mach_apic.h> -#include <asm/smp.h> - -extern struct msi_ops arch_msi_ops; - -static inline int msi_arch_init (void ) -{ -msi_register (&arch_msi_ops); -return 0 ; -} - -#endif /* ASM_MSI_H */
include/linux/msi.h new file +49 -0
49 lines not on this page · raw message
include/linux/pci.h +0 -67
79 lines not on this page · raw message
Signature · 1 line
1.4.2.rc3.g7e18e-dirty
PATCH 4/5 msi: Move the ia64 code into arch/ia64
In reply to Eric W. BiedermanThis is just a few makefile tweaks and some file renames.
--- arch/ia64/kernel/Makefile | 1 arch/ia64/kernel/msi_ia64.c | 143 ++++++++++++++++++++++++++ arch/ia64/sn/kernel/Makefile | 1 arch/ia64/sn/kernel/msi_sn.c | 230 ++++++++++++++++++++++++++++++++++++++++++ drivers/pci/Makefile | 9 +- drivers/pci/msi-altix.c | 230 ------------------------------------------ drivers/pci/msi-apic.c | 143 -------------------------- 7 files changed, 378 insertions(+), 379 deletions(-)
arch/ia64/kernel/Makefile +1 -0
@@ -31,6 +31,7 @@ obj-$(CONFIG_KPROBES) += kprobes.o jpro obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o crash.o obj-$(CONFIG_IA64_UNCACHED_ALLOCATOR) += uncached.o obj-$(CONFIG_AUDIT) += audit.o +obj-$(CONFIG_PCI_MSI) += msi_ia64.o mca_recovery-y += mca_drv.o mca_drv_asm.o obj-$(CONFIG_IA64_ESI) += esi.o
arch/ia64/kernel/msi_ia64.c new file +143 -0
143 lines not on this page · raw message
arch/ia64/sn/kernel/Makefile +1 -0
@@ -19,3 +19,4 @@ xp-y := xp_main.o xp_nofault.o obj-$(CONFIG_IA64_SGI_SN_XP) += xpc.o xpc-y := xpc_main.o xpc_channel.o xpc_partition.o obj-$(CONFIG_IA64_SGI_SN_XP) += xpnet.o +obj-$(CONFIG_PCI_MSI) += msi_sn.o
arch/ia64/sn/kernel/msi_sn.c new file +230 -0
230 lines not on this page · raw message
drivers/pci/Makefile +3 -6
@@ -14,6 +14,9 @@ obj-$(CONFIG_HOTPLUG) += hotplug.o # Build the PCI Hotplug drivers if we were asked to obj-$(CONFIG_HOTPLUG_PCI) += hotplug/ +# Build the PCI MSI interrupt support +obj-$(CONFIG_PCI_MSI) += msi.o + # # Some architectures use the generic PCI setup functions #
@@ -28,12 +31,6 @@ obj-$(CONFIG_MIPS) += setup-bus.o setup- obj-$(CONFIG_X86_VISWS) += setup-irq.o obj-$(CONFIG_HT_IRQ) += htirq.o -msiobj-y := msi.o -msiobj-$(CONFIG_IA64) += msi-apic.o -msiobj-$(CONFIG_IA64_GENERIC) += msi-altix.o -msiobj-$(CONFIG_IA64_SGI_SN2) += msi-altix.o -obj-$(CONFIG_PCI_MSI) += $(msiobj-y) - # # ACPI Related PCI FW Functions #
drivers/pci/msi-altix.c deleted +0 -230
230 lines not on this page · raw message
drivers/pci/msi-apic.c deleted +0 -143
143 lines not on this page · raw message
Signature · 1 line
1.4.2.rc3.g7e18e-dirty
PATCH 5/5 htirq: Tidy up the htirq code
In reply to Eric W. BiedermanThis moves the declarations for the architecture helpers into include/linux/htirq.h from the generic include/linux/pci.h. Hopefully this will make this distinction clearer.
htirq.h is included where it is needed.
The dependency on the msi code is fixed and removed.
The Makefile is tidied up.
--- arch/i386/kernel/io_apic.c | 5 ++--- arch/x86_64/kernel/io_apic.c | 1 + drivers/pci/Kconfig | 1 - drivers/pci/Makefile | 4 +++- drivers/pci/htirq.c | 1 + include/linux/htirq.h | 15 +++++++++++++++ include/linux/pci.h | 11 ----------- 7 files changed, 22 insertions(+), 16 deletions(-)
arch/i386/kernel/io_apic.c +2 -3
@@ -33,6 +33,7 @@ #include <linux/module.h>#include <linux/sysdev.h> #include <linux/pci.h> #include <linux/msi.h> +#include <linux/htirq.h> #include <asm/io.h> #include <asm/smp.h>
@@ -2409,9 +2410,8 @@ static int __init ioapic_init_sysfs(voiddevice_initcall (ioapic_init_sysfs); -#ifdef CONFIG_PCI_MSI /* -* Dynamic irq allocate and deallocation for MSI +* Dynamic irq allocate and deallocation */ int create_irq (void ) {
@@ -2450,7 +2450,6 @@ void destroy_irq(unsigned int irq) irq_vector[irq] =0 ;spin_unlock_irqrestore (&vector_lock, flags); } -#endif /* CONFIG_PCI_MSI */ /* * MSI mesage composition
arch/x86_64/kernel/io_apic.c +1 -0
@@ -31,6 +31,7 @@ #include <linux/mc146818rtc.h>#include <linux/acpi.h> #include <linux/sysdev.h> #include <linux/msi.h> +#include <linux/htirq.h> #ifdef CONFIG_ACPI #include <acpi/acpi_bus.h> #endif
drivers/pci/Kconfig +0 -1
@@ -55,7 +55,6 @@ config PCI_DEBUG config HT_IRQ bool "Interrupts on hypertransport devices" default y - depends on PCI_MSI depends on X86_LOCAL_APIC && X86_IO_APIC help This allows native hypertransport devices to use interrupts.
drivers/pci/Makefile +3 -1
@@ -17,6 +17,9 @@ obj-$(CONFIG_HOTPLUG_PCI) += hotplug/ # Build the PCI MSI interrupt support obj-$(CONFIG_PCI_MSI) += msi.o +# Build the Hypertransport interrupt support +obj-$(CONFIG_HT_IRQ) += htirq.o + # # Some architectures use the generic PCI setup functions #
@@ -29,7 +32,6 @@ obj-$(CONFIG_PPC32) += setup-irq.o obj-$(CONFIG_PPC64) += setup-bus.o obj-$(CONFIG_MIPS) += setup-bus.o setup-irq.o obj-$(CONFIG_X86_VISWS) += setup-irq.o -obj-$(CONFIG_HT_IRQ) += htirq.o # # ACPI Related PCI FW Functions
drivers/pci/htirq.c +1 -0
@@ -11,6 +11,7 @@ #include <linux/pci.h>#include <linux/spinlock.h> #include <linux/slab.h> #include <linux/gfp.h> +#include <linux/htirq.h> /* Global ht irq lock. *
include/linux/htirq.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef LINUX_HTIRQ_H +#define LINUX_HTIRQ_H + +/* Helper functions.. */ +void write_ht_irq_low (unsigned int irq,u32 data); +void write_ht_irq_high (unsigned int irq,u32 data); +u32 read_ht_irq_low (unsigned int irq); +u32 read_ht_irq_high (unsigned int irq); +void mask_ht_irq (unsigned int irq); +void unmask_ht_irq (unsigned int irq); + +/* The arch hook for getting things started */ +int arch_setup_ht_irq (unsigned int irq,struct pci_dev *dev); + +#endif /* LINUX_HTIRQ_H */
include/linux/pci.h +0 -11
@@ -619,20 +619,9 @@ extern void msi_remove_pci_irq_vectors(s#endif #ifdef CONFIG_HT_IRQ -/* Helper functions.. */ -void write_ht_irq_low (unsigned int irq,u32 data); -void write_ht_irq_high (unsigned int irq,u32 data); -u32 read_ht_irq_low (unsigned int irq); -u32 read_ht_irq_high (unsigned int irq); -void mask_ht_irq (unsigned int irq); -void unmask_ht_irq (unsigned int irq); -/* The functions a driver should call */ int ht_create_irq (struct pci_dev *dev,int idx);void ht_destroy_irq (unsigned int irq); - -/* The arch hook for getting things started */ -int arch_setup_ht_irq (unsigned int irq,struct pci_dev *dev);#endif /* CONFIG_HT_IRQ */ extern void pci_block_user_cfg_access (struct pci_dev *dev);
Signature · 1 line
1.4.2.rc3.g7e18e-dirty
Quoted 9 lines
So hopefully we are finally close enough that other architectures will be able implement msi support, without too much trouble.
msi: Simplify msi sanity checks by adding with generic irq code.
msi: Only use a singleirq_chipfor msi interrupts
msi: Refactor and move the msiirq_chipinto the arch code.
msi: Move the ia64 code intoarch/ia64
htirq: Tidy up the htirq code
Heh ! And Michael was just coming up with a rewritten MSI core for PowerPC :) Oh well... I'll dig through your patches.
My main problem is that you have thus dynamic_irq stuff in the generic code. I just can't see any way that code can apply to me in any shape or form. PowerPC has a virtual IRQ layer that remaps linux IRQs to controller/line pairs to handle multiple controllers etc... thus we have some primitives for allocating virtual irqs and binding them to a controller etc...
I have the feeling that this dynamic_irq_* thing you introduced will not only not work properly for us but can't be made to work in our context, not with the current API and not with any "generic" non platform specific API.
Also we need to have different low level callbacks for different busses in the system for the various bits, ranging from allocating & providing up the irq_chip, to setting up the MSI. Unfortunately, even your reworked code just don't fit our needs at the moment in that area. Also, you hijack irq data which we can't do as it can/will be used by our PIC code that actually gets the MSIs on some machines (they are just routed to it as normal irqs) etc....
At this point, best is that we finish a working implementation based on Michael reworked core for PowerPC (which is currently located in arch/powerpc and doesn't exclude whatever sits in drivers/pci/ except that we don't build the later on PowerPC) so you can see more what our approach looks like and why we need to go that way.
Ben.
Quoted 6 lines
At this point, best is that we finish a working implementation based on Michael reworked core for PowerPC (which is currently located in
arch/powerpcand doesn't exclude whatever sits indrivers/pci/except that we don't build the later on PowerPC) so you can see more what our approach looks like and why we need to go that way.
Don't look for it in the tree btw, it's not beem merged, though Michael posted some versions to linuxppc-dev.
Ben.