linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] add hook to generic irq code (free_irq)
@ 2004-10-20  2:31 Chris Wedgwood
  2004-10-20 13:07 ` Christoph Hellwig
  0 siblings, 1 reply; 7+ messages in thread
From: Chris Wedgwood @ 2004-10-20  2:31 UTC (permalink / raw)
  To: LKML; +Cc: Ingo Molnar

This is needed because some architectures (well, presently only UML)
needs to be notified as things are freed.

Signed-off-by: cw@f00f.org


I can't say I'm 100% happy about this, either the name or a somewhat
ugly hook that is called with a spinlock held but for lack of any
better suggestions...

Comments?

 include/asm-i386/hardirq.h   |    3 +++
 include/asm-ppc/hardirq.h    |    3 +++
 include/asm-ppc64/hardirq.h  |    3 +++
 include/asm-x86_64/hardirq.h |    4 ++++
 kernel/irq/manage.c          |    1 +
 5 files changed, 14 insertions(+)


diff -Nru a/include/asm-i386/hardirq.h b/include/asm-i386/hardirq.h
--- a/include/asm-i386/hardirq.h	2004-10-19 17:47:40 -07:00
+++ b/include/asm-i386/hardirq.h	2004-10-19 17:47:40 -07:00
@@ -16,4 +16,7 @@
 
 void ack_bad_irq(unsigned int irq);
 
+/* NOP */
+#define platform_free_irq_notify(i, d)
+
 #endif /* __ASM_HARDIRQ_H */
diff -Nru a/include/asm-ppc/hardirq.h b/include/asm-ppc/hardirq.h
--- a/include/asm-ppc/hardirq.h	2004-10-19 17:47:40 -07:00
+++ b/include/asm-ppc/hardirq.h	2004-10-19 17:47:40 -07:00
@@ -27,5 +27,8 @@
 	BUG();
 }
 
+/* NOP */
+#define platform_free_irq_notify(i, d)
+
 #endif /* __ASM_HARDIRQ_H */
 #endif /* __KERNEL__ */
diff -Nru a/include/asm-ppc64/hardirq.h b/include/asm-ppc64/hardirq.h
--- a/include/asm-ppc64/hardirq.h	2004-10-19 17:47:40 -07:00
+++ b/include/asm-ppc64/hardirq.h	2004-10-19 17:47:40 -07:00
@@ -25,4 +25,7 @@
 	BUG();
 }
 
+/* NOP */
+#define platform_free_irq_notify(i, d)
+
 #endif /* __ASM_HARDIRQ_H */
diff -Nru a/include/asm-x86_64/hardirq.h b/include/asm-x86_64/hardirq.h
--- a/include/asm-x86_64/hardirq.h	2004-10-19 17:47:40 -07:00
+++ b/include/asm-x86_64/hardirq.h	2004-10-19 17:47:40 -07:00
@@ -36,4 +36,8 @@
 #endif
 #endif
 }
+
+/* NOP */
+#define platform_irq_free_notify(i, d)
+
 #endif /* __ASM_HARDIRQ_H */
diff -Nru a/kernel/irq/manage.c b/kernel/irq/manage.c
--- a/kernel/irq/manage.c	2004-10-19 17:47:40 -07:00
+++ b/kernel/irq/manage.c	2004-10-19 17:47:40 -07:00
@@ -260,6 +260,7 @@
 				else
 					desc->handler->disable(irq);
 			}
+			platform_free_irq_notify(irq, dev_id);
 			spin_unlock_irqrestore(&desc->lock,flags);
 			unregister_handler_proc(irq, action);
 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] add hook to generic irq code (free_irq)
  2004-10-20  2:31 [PATCH] add hook to generic irq code (free_irq) Chris Wedgwood
@ 2004-10-20 13:07 ` Christoph Hellwig
  2004-10-20 19:42   ` Chris Wedgwood
  2004-10-21  2:26   ` [RFC] add struct hw_interrupt_type->release Chris Wedgwood
  0 siblings, 2 replies; 7+ messages in thread
From: Christoph Hellwig @ 2004-10-20 13:07 UTC (permalink / raw)
  To: Chris Wedgwood; +Cc: LKML, Ingo Molnar

On Tue, Oct 19, 2004 at 07:31:56PM -0700, Chris Wedgwood wrote:
> This is needed because some architectures (well, presently only UML)
> needs to be notified as things are freed.
> 
> Signed-off-by: cw@f00f.org
> 
> 
> I can't say I'm 100% happy about this, either the name or a somewhat
> ugly hook that is called with a spinlock held but for lack of any
> better suggestions...

This looks rather bogus to me.  What prevents UML from doing it's work
at the struct hw_interrupt_type level?


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] add hook to generic irq code (free_irq)
  2004-10-20 13:07 ` Christoph Hellwig
@ 2004-10-20 19:42   ` Chris Wedgwood
  2004-10-21  2:26   ` [RFC] add struct hw_interrupt_type->release Chris Wedgwood
  1 sibling, 0 replies; 7+ messages in thread
From: Chris Wedgwood @ 2004-10-20 19:42 UTC (permalink / raw)
  To: Christoph Hellwig, LKML, Ingo Molnar

On Wed, Oct 20, 2004 at 02:07:15PM +0100, Christoph Hellwig wrote:

> This looks rather bogus to me.  What prevents UML from doing it's work
> at the struct hw_interrupt_type level?

Probably nothing, it's just not clear to me how that would work or
should look.  Let me poke about and see if I can figure it out.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFC] add struct hw_interrupt_type->release
  2004-10-20 13:07 ` Christoph Hellwig
  2004-10-20 19:42   ` Chris Wedgwood
@ 2004-10-21  2:26   ` Chris Wedgwood
  2004-10-21  2:35     ` [RFC] UML converstion to generic irq code (requires hw_interrupt_type->release(...) patch) Chris Wedgwood
  2004-10-21  7:23     ` [RFC] add struct hw_interrupt_type->release Christoph Hellwig
  1 sibling, 2 replies; 7+ messages in thread
From: Chris Wedgwood @ 2004-10-21  2:26 UTC (permalink / raw)
  To: LKML, Christoph Hellwig, Ingo Molnar

On Tue, Oct 19, 2004 at 07:31:56PM -0700, Chris Wedgwood wrote:

> +++ b/kernel/irq/manage.c	2004-10-19 17:47:40 -07:00
> @@ -260,6 +260,7 @@
>  				else
>  					desc->handler->disable(irq);
>  			}
                       ^^^
> +			platform_free_irq_notify(irq, dev_id);
>  			spin_unlock_irqrestore(&desc->lock,flags);
>  			unregister_handler_proc(irq, action);
>  

On Wed, Oct 20, 2004 at 02:07:15PM +0100, Christoph Hellwig wrote:

> This looks rather bogus to me.  What prevents UML from doing it's
> work at the struct hw_interrupt_type level?

the ^^^ marked part reads something like if (!desc->action) { ... }
presumably meaning the shutdown/disable is only done when the very
last user of an interrupt source is removed

UML needs to be notified when *any* user is removed so either need
some way to tell the generic code this or perhaps we could introduce
another op to hw_interrupt_type along the lines of ->release like
this:


===== include/linux/irq.h 1.12 vs edited =====
--- 1.12/include/linux/irq.h	2004-10-18 22:26:45 -07:00
+++ edited/include/linux/irq.h	2004-10-20 19:13:01 -07:00
@@ -47,6 +47,7 @@ struct hw_interrupt_type {
 	void (*ack)(unsigned int irq);
 	void (*end)(unsigned int irq);
 	void (*set_affinity)(unsigned int irq, cpumask_t dest);
+	void (*release)(unsigned int irq, void *dev_id);
 };
 
 typedef struct hw_interrupt_type  hw_irq_controller;
===== kernel/irq/manage.c 1.1 vs edited =====
--- 1.1/kernel/irq/manage.c	2004-10-18 22:26:39 -07:00
+++ edited/kernel/irq/manage.c	2004-10-20 18:55:05 -07:00
@@ -253,6 +253,10 @@ void free_irq(unsigned int irq, void *de
 
 			/* Found it - now remove it from the list of entries */
 			*pp = action->next;
+
+			if (desc->handler->release)
+				desc->handler->release(irq, dev_id);
+
 			if (!desc->action) {
 				desc->status |= IRQ_DISABLED;
 				if (desc->handler->shutdown)



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFC] UML converstion to generic irq code (requires hw_interrupt_type->release(...) patch)
  2004-10-21  2:26   ` [RFC] add struct hw_interrupt_type->release Chris Wedgwood
@ 2004-10-21  2:35     ` Chris Wedgwood
  2004-10-21  7:23     ` [RFC] add struct hw_interrupt_type->release Christoph Hellwig
  1 sibling, 0 replies; 7+ messages in thread
From: Chris Wedgwood @ 2004-10-21  2:35 UTC (permalink / raw)
  To: LKML, Christoph Hellwig, Ingo Molnar

> UML needs to be notified when *any* user is removed so either need
> some way to tell the generic code this or perhaps we could introduce
> another op to hw_interrupt_type along the lines of ->release like

[...]

and the UML changes to support this:


 arch/um/Kconfig               |    5 
 arch/um/include/irq_user.h    |    2 
 arch/um/kernel/irq.c          |  650 +-----------------------------------------
 arch/um/kernel/irq_user.c     |    2 
 arch/um/kernel/process_kern.c |    1 
 include/asm-um/hardirq.h      |   28 +
 6 files changed, 51 insertions(+), 637 deletions(-)


(actually, i think there is an uninteresting/obvious hunk missing,
i'll resend send all this properly after feedback though)



===== arch/um/Kconfig 1.18 vs edited =====
--- 1.18/arch/um/Kconfig	2004-10-13 21:08:32 -07:00
+++ edited/arch/um/Kconfig	2004-10-20 17:47:51 -07:00
@@ -1,3 +1,8 @@
+# UML uses the generic IRQ sugsystem
+config GENERIC_HARDIRQS
+	bool
+	default y
+
 config USERMODE
 	bool
 	default y
===== arch/um/include/irq_user.h 1.4 vs edited =====
--- 1.4/arch/um/include/irq_user.h	2004-09-13 17:23:23 -07:00
+++ edited/arch/um/include/irq_user.h	2004-10-20 19:00:29 -07:00
@@ -10,7 +10,7 @@
 
 extern void sigio_handler(int sig, union uml_pt_regs *regs);
 extern int activate_fd(int irq, int fd, int type, void *dev_id);
-extern void free_irq_by_irq_and_dev(int irq, void *dev_id);
+extern void free_irq_by_irq_and_dev(unsigned int irq, void *dev_id);
 extern void free_irq_by_fd(int fd);
 extern void reactivate_fd(int fd, int irqnum);
 extern void deactivate_fd(int fd, int irqnum);
===== arch/um/kernel/irq.c 1.21 vs edited =====
--- 1.21/arch/um/kernel/irq.c	2004-10-13 21:08:30 -07:00
+++ edited/arch/um/kernel/irq.c	2004-10-20 19:05:41 -07:00
@@ -32,58 +32,6 @@
 #include "irq_user.h"
 #include "irq_kern.h"
 
-static void register_irq_proc (unsigned int irq);
-
-irq_desc_t irq_desc[NR_IRQS] __cacheline_aligned = {
-	[0 ... NR_IRQS-1] = {
-		.handler = &no_irq_type,
-		.lock = SPIN_LOCK_UNLOCKED
-	}
-};
-
-/*
- * Generic no controller code
- */
-
-static void enable_none(unsigned int irq) { }
-static unsigned int startup_none(unsigned int irq) { return 0; }
-static void disable_none(unsigned int irq) { }
-static void ack_none(unsigned int irq)
-{
-/*
- * 'what should we do if we get a hw irq event on an illegal vector'.
- * each architecture has to answer this themselves, it doesn't deserve
- * a generic callback i think.
- */
-#ifdef CONFIG_X86
-	printk(KERN_ERR "unexpected IRQ trap at vector %02x\n", irq);
-#ifdef CONFIG_X86_LOCAL_APIC
-	/*
-	 * Currently unexpected vectors happen only on SMP and APIC.
-	 * We _must_ ack these because every local APIC has only N
-	 * irq slots per priority level, and a 'hanging, unacked' IRQ
-	 * holds up an irq slot - in excessive cases (when multiple
-	 * unexpected vectors occur) that might lock up the APIC
-	 * completely.
-	 */
-	ack_APIC_irq();
-#endif
-#endif
-}
-
-/* startup is the same as "enable", shutdown is same as "disable" */
-#define shutdown_none	disable_none
-#define end_none	enable_none
-
-struct hw_interrupt_type no_irq_type = {
-	"none",
-	startup_none,
-	shutdown_none,
-	enable_none,
-	disable_none,
-	ack_none,
-	end_none
-};
 
 /*
  * Generic, controller-independent functions:
@@ -126,10 +74,6 @@
 skip:
 		spin_unlock_irqrestore(&irq_desc[i].lock, flags);
 	} else if (i == NR_IRQS) {
-		seq_printf(p, "NMI: ");
-		for (j = 0; j < NR_CPUS; j++)
-			if (cpu_online(j))
-				seq_printf(p, "%10u ", nmi_count(j));
 		seq_putc(p, '\n');
 	}
 
@@ -137,295 +81,18 @@
 }
 
 /*
- * This should really return information about whether
- * we should do bottom half handling etc. Right now we
- * end up _always_ checking the bottom half, which is a
- * waste of time and is not what some drivers would
- * prefer.
- */
-int handle_IRQ_event(unsigned int irq, struct pt_regs * regs, 
-		     struct irqaction * action)
-{
-	int status = 1;	/* Force the "do bottom halves" bit */
-	int ret, retval = 0;
-
-	if (!(action->flags & SA_INTERRUPT))
-		local_irq_enable();
-
-	do {
-		ret = action->handler(irq, action->dev_id, regs);
-		if (ret == IRQ_HANDLED)
-			status |= action->flags;
-		retval |= ret;
-		action = action->next;
-	} while (action);
-	if (status & SA_SAMPLE_RANDOM)
-		add_interrupt_randomness(irq);
-
-	local_irq_disable();
-
-	return retval;
-}
-
-/*
- * Generic enable/disable code: this just calls
- * down into the PIC-specific version for the actual
- * hardware disable after having gotten the irq
- * controller lock. 
- */
- 
-/**
- *	disable_irq_nosync - disable an irq without waiting
- *	@irq: Interrupt to disable
- *
- *	Disable the selected interrupt line. Disables of an interrupt
- *	stack. Unlike disable_irq(), this function does not ensure existing
- *	instances of the IRQ handler have completed before returning.
- *
- *	This function may be called from IRQ context.
- */
- 
-inline void disable_irq_nosync(unsigned int irq)
-{
-	irq_desc_t *desc = irq_desc + irq;
-	unsigned long flags;
-
-	spin_lock_irqsave(&desc->lock, flags);
-	if (!desc->depth++) {
-		desc->status |= IRQ_DISABLED;
-		desc->handler->disable(irq);
-	}
-	spin_unlock_irqrestore(&desc->lock, flags);
-}
-
-#ifdef CONFIG_SMP
-inline void synchronize_irq(unsigned int irq)
-{
-	/* is there anything to synchronize with? */
-	if (!irq_desc[irq].action)
-		return;
- 
-	while (irq_desc[irq].status & IRQ_INPROGRESS)
-		cpu_relax();
-}
-#endif
-
-/**
- *	disable_irq - disable an irq and wait for completion
- *	@irq: Interrupt to disable
- *
- *	Disable the selected interrupt line. Disables of an interrupt
- *	stack. That is for two disables you need two enables. This
- *	function waits for any pending IRQ handlers for this interrupt
- *	to complete before returning. If you use this function while
- *	holding a resource the IRQ handler may need you will deadlock.
- *
- *	This function may be called - with care - from IRQ context.
- */
- 
-void disable_irq(unsigned int irq)
-{
-	disable_irq_nosync(irq);
-	synchronize_irq(irq);
-}
-
-/**
- *	enable_irq - enable interrupt handling on an irq
- *	@irq: Interrupt to enable
- *
- *	Re-enables the processing of interrupts on this IRQ line
- *	providing no disable_irq calls are now in effect.
- *
- *	This function may be called from IRQ context.
- */
- 
-void enable_irq(unsigned int irq)
-{
-	irq_desc_t *desc = irq_desc + irq;
-	unsigned long flags;
-
-	spin_lock_irqsave(&desc->lock, flags);
-	switch (desc->depth) {
-	case 1: {
-		unsigned int status = desc->status & ~IRQ_DISABLED;
-		desc->status = status;
-		if ((status & (IRQ_PENDING | IRQ_REPLAY)) == IRQ_PENDING) {
-			desc->status = status | IRQ_REPLAY;
-			hw_resend_irq(desc->handler,irq);
-		}
-		desc->handler->enable(irq);
-		/* fall-through */
-	}
-	default:
-		desc->depth--;
-		break;
-	case 0:
-		printk(KERN_ERR "enable_irq() unbalanced from %p\n",
-		       __builtin_return_address(0));
-	}
-	spin_unlock_irqrestore(&desc->lock, flags);
-}
-
-/*
  * do_IRQ handles all normal device IRQ's (the special
  * SMP cross-CPU interrupts have their own specific
  * handlers).
  */
 unsigned int do_IRQ(int irq, union uml_pt_regs *regs)
-{	
-	/* 
-	 * 0 return value means that this irq is already being
-	 * handled by some other CPU. (or is disabled)
-	 */
-	irq_desc_t *desc = irq_desc + irq;
-	struct irqaction * action;
-	unsigned int status;
-
-	irq_enter();
-	kstat_this_cpu.irqs[irq]++;
-	spin_lock(&desc->lock);
-	desc->handler->ack(irq);
-	/*
-	   REPLAY is when Linux resends an IRQ that was dropped earlier
-	   WAITING is used by probe to mark irqs that are being tested
-	   */
-	status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
-	status |= IRQ_PENDING; /* we _want_ to handle it */
-
-	/*
-	 * If the IRQ is disabled for whatever reason, we cannot
-	 * use the action we have.
-	 */
-	action = NULL;
-	if (!(status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
-		action = desc->action;
-		status &= ~IRQ_PENDING; /* we commit to handling */
-		status |= IRQ_INPROGRESS; /* we are handling it */
-	}
-	desc->status = status;
-
-	/*
-	 * If there is no IRQ handler or it was disabled, exit early.
-	   Since we set PENDING, if another processor is handling
-	   a different instance of this same irq, the other processor
-	   will take care of it.
-	 */
-	if (!action)
-		goto out;
-
-	/*
-	 * Edge triggered interrupts need to remember
-	 * pending events.
-	 * This applies to any hw interrupts that allow a second
-	 * instance of the same irq to arrive while we are in do_IRQ
-	 * or in the handler. But the code here only handles the _second_
-	 * instance of the irq, not the third or fourth. So it is mostly
-	 * useful for irq hardware that does not mask cleanly in an
-	 * SMP environment.
-	 */
-	for (;;) {
-		spin_unlock(&desc->lock);
-		handle_IRQ_event(irq, (struct pt_regs *) regs, action);
-		spin_lock(&desc->lock);
-		
-		if (!(desc->status & IRQ_PENDING))
-			break;
-		desc->status &= ~IRQ_PENDING;
-	}
-	desc->status &= ~IRQ_INPROGRESS;
-out:
-	/*
-	 * The ->end() handler has to deal with interrupts which got
-	 * disabled while the handler was running.
-	 */
-	desc->handler->end(irq);
-	spin_unlock(&desc->lock);
-
-	irq_exit();
-
-	return 1;
-}
-
-/**
- *	request_irq - allocate an interrupt line
- *	@irq: Interrupt line to allocate
- *	@handler: Function to be called when the IRQ occurs
- *	@irqflags: Interrupt type flags
- *	@devname: An ascii name for the claiming device
- *	@dev_id: A cookie passed back to the handler function
- *
- *	This call allocates interrupt resources and enables the
- *	interrupt line and IRQ handling. From the point this
- *	call is made your handler function may be invoked. Since
- *	your handler function must clear any interrupt the board 
- *	raises, you must take care both to initialise your hardware
- *	and to set up the interrupt handler in the right order.
- *
- *	Dev_id must be globally unique. Normally the address of the
- *	device data structure is used as the cookie. Since the handler
- *	receives this value it makes sense to use it.
- *
- *	If your interrupt is shared you must pass a non NULL dev_id
- *	as this is required when freeing the interrupt.
- *
- *	Flags:
- *
- *	SA_SHIRQ		Interrupt is shared
- *
- *	SA_INTERRUPT		Disable local interrupts while processing
- *
- *	SA_SAMPLE_RANDOM	The interrupt can be used for entropy
- *
- */
- 
-int request_irq(unsigned int irq,
-		irqreturn_t (*handler)(int, void *, struct pt_regs *),
-		unsigned long irqflags, 
-		const char * devname,
-		void *dev_id)
 {
-	int retval;
-	struct irqaction * action;
-
-#if 1
-	/*
-	 * Sanity-check: shared interrupts should REALLY pass in
-	 * a real dev-ID, otherwise we'll have trouble later trying
-	 * to figure out which interrupt is which (messes up the
-	 * interrupt freeing logic etc).
-	 */
-	if (irqflags & SA_SHIRQ) {
-		if (!dev_id)
-			printk(KERN_ERR "Bad boy: %s (at 0x%x) called us "
-			       "without a dev_id!\n", devname, (&irq)[-1]);
-	}
-#endif
-
-	if (irq >= NR_IRQS)
-		return -EINVAL;
-	if (!handler)
-		return -EINVAL;
-
-	action = (struct irqaction *)
-			kmalloc(sizeof(struct irqaction), GFP_KERNEL);
-	if (!action)
-		return -ENOMEM;
-
-	action->handler = handler;
-	action->flags = irqflags;
-	cpus_clear(action->mask);
-	action->name = devname;
-	action->next = NULL;
-	action->dev_id = dev_id;
-
-	retval = setup_irq(irq, action);
-	if (retval)
-		kfree(action);
-	return retval;
+       irq_enter();
+       __do_IRQ(irq, (struct pt_regs *) regs);
+       irq_exit();
+       return 1;
 }
 
-EXPORT_SYMBOL(request_irq);
-
 int um_request_irq(unsigned int irq, int fd, int type,
 		   irqreturn_t (*handler)(int, void *, struct pt_regs *),
 		   unsigned long irqflags, const char * devname,
@@ -444,222 +111,6 @@
 EXPORT_SYMBOL(um_request_irq);
 EXPORT_SYMBOL(reactivate_fd);
 
-/* this was setup_x86_irq but it seems pretty generic */
-int setup_irq(unsigned int irq, struct irqaction * new)
-{
-	int shared = 0;
-	unsigned long flags;
-	struct irqaction *old, **p;
-	irq_desc_t *desc = irq_desc + irq;
-
-	/*
-	 * Some drivers like serial.c use request_irq() heavily,
-	 * so we have to be careful not to interfere with a
-	 * running system.
-	 */
-	if (new->flags & SA_SAMPLE_RANDOM) {
-		/*
-		 * This function might sleep, we want to call it first,
-		 * outside of the atomic block.
-		 * Yes, this might clear the entropy pool if the wrong
-		 * driver is attempted to be loaded, without actually
-		 * installing a new handler, but is this really a problem,
-		 * only the sysadmin is able to do this.
-		 */
-		rand_initialize_irq(irq);
-	}
-
-	/*
-	 * The following block of code has to be executed atomically
-	 */
-	spin_lock_irqsave(&desc->lock,flags);
-	p = &desc->action;
-	old = *p;
-	if (old != NULL) {
-		/* Can't share interrupts unless both agree to */
-		if (!(old->flags & new->flags & SA_SHIRQ)) {
-			spin_unlock_irqrestore(&desc->lock,flags);
-			return -EBUSY;
-		}
-
-		/* add new interrupt at end of irq queue */
-		do {
-			p = &old->next;
-			old = *p;
-		} while (old);
-		shared = 1;
-	}
-
-	*p = new;
-
-	if (!shared) {
-		desc->depth = 0;
-		desc->status &= ~IRQ_DISABLED;
-		desc->handler->startup(irq);
-	}
-	spin_unlock_irqrestore(&desc->lock,flags);
-
-	register_irq_proc(irq);
-	return 0;
-}
-
-/**
- *	free_irq - free an interrupt
- *	@irq: Interrupt line to free
- *	@dev_id: Device identity to free
- *
- *	Remove an interrupt handler. The handler is removed and if the
- *	interrupt line is no longer in use by any driver it is disabled.
- *	On a shared IRQ the caller must ensure the interrupt is disabled
- *	on the card it drives before calling this function. The function
- *	does not return until any executing interrupts for this IRQ
- *	have completed.
- *
- *	This function may be called from interrupt context. 
- *
- *	Bugs: Attempting to free an irq in a handler for the same irq hangs
- *	      the machine.
- */
- 
-void free_irq(unsigned int irq, void *dev_id)
-{
-	irq_desc_t *desc;
-	struct irqaction **p;
-	unsigned long flags;
-
-	if (irq >= NR_IRQS)
-		return;
-
-	desc = irq_desc + irq;
-	spin_lock_irqsave(&desc->lock,flags);
-	p = &desc->action;
-	for (;;) {
-		struct irqaction * action = *p;
-		if (action) {
-			struct irqaction **pp = p;
-			p = &action->next;
-			if (action->dev_id != dev_id)
-				continue;
-
-			/* Found it - now remove it from the list of entries */
-			*pp = action->next;
-			if (!desc->action) {
-				desc->status |= IRQ_DISABLED;
-				desc->handler->shutdown(irq);
-			}
-			free_irq_by_irq_and_dev(irq, dev_id);
-			spin_unlock_irqrestore(&desc->lock,flags);
-
-			/* Wait to make sure it's not being used on another CPU */
-			synchronize_irq(irq);
-			kfree(action);
-			return;
-		}
-		printk(KERN_ERR "Trying to free free IRQ%d\n",irq);
-		spin_unlock_irqrestore(&desc->lock,flags);
-		return;
-	}
-}
-
-EXPORT_SYMBOL(free_irq);
-
-/* These are initialized by sysctl_init, which is called from init/main.c */
-static struct proc_dir_entry * root_irq_dir;
-static struct proc_dir_entry * irq_dir [NR_IRQS];
-static struct proc_dir_entry * smp_affinity_entry [NR_IRQS];
-
-/* These are read and written as longs, so a read won't see a partial write
- * even during a race.
- */
-static cpumask_t irq_affinity [NR_IRQS] = { [0 ... NR_IRQS-1] = CPU_MASK_ALL };
-
-static int irq_affinity_read_proc (char *page, char **start, off_t off,
-			int count, int *eof, void *data)
-{
-	int len = cpumask_scnprintf(page, count, irq_affinity[(long)data]);
-	if (count - len < 2)
-		return -EINVAL;
-	len += sprintf(page + len, "\n");
-	return len;
-}
-
-static int irq_affinity_write_proc (struct file *file, const char *buffer,
-					unsigned long count, void *data)
-{
-	int irq = (long) data, full_count = count, err;
-	cpumask_t new_value;
-
-	if (!irq_desc[irq].handler->set_affinity)
-		return -EIO;
-
-	err = cpumask_parse(buffer, count, new_value);
-	if(err)
-		return(err);
-
-#ifdef CONFIG_SMP
-	/*
-	 * Do not allow disabling IRQs completely - it's a too easy
-	 * way to make the system unusable accidentally :-) At least
-	 * one online CPU still has to be targeted.
-	 */
-	{ cpumask_t tmp;
-	  cpus_and(tmp, new_value, cpu_online_map);
-	  if (cpus_empty(tmp))
-		  return -EINVAL;
-	}
-#endif
-
-	irq_affinity[irq] = new_value;
-	irq_desc[irq].handler->set_affinity(irq, new_value);
-
-	return full_count;
-}
-
-#define MAX_NAMELEN 10
-
-static void register_irq_proc (unsigned int irq)
-{
-	struct proc_dir_entry *entry;
-	char name [MAX_NAMELEN];
-
-	if (!root_irq_dir || (irq_desc[irq].handler == &no_irq_type) ||
-	    irq_dir[irq])
-		return;
-
-	memset(name, 0, MAX_NAMELEN);
-	sprintf(name, "%d", irq);
-
-	/* create /proc/irq/1234 */
-	irq_dir[irq] = proc_mkdir(name, root_irq_dir);
-
-	/* create /proc/irq/1234/smp_affinity */
-	entry = create_proc_entry("smp_affinity", 0600, irq_dir[irq]);
-
-	entry->nlink = 1;
-	entry->data = (void *)(long)irq;
-	entry->read_proc = irq_affinity_read_proc;
-	entry->write_proc = irq_affinity_write_proc;
-
-	smp_affinity_entry[irq] = entry;
-}
-
-void __init init_irq_proc (void)
-{
-	int i;
-
-	/* create /proc/irq */
-	root_irq_dir = proc_mkdir("irq", 0);
-
-	/* create /proc/irq/prof_cpu_mask */
-	create_prof_cpu_mask(root_irq_dir);
-
-	/*
-	 * Create entries for all existing IRQs.
-	 */
-	for (i = 0; i < NR_IRQS; i++)
-		register_irq_proc(i);
-}
-
 static spinlock_t irq_spinlock = SPIN_LOCK_UNLOCKED;
 
 unsigned long irq_lock(void)
@@ -675,90 +126,29 @@
 	spin_unlock_irqrestore(&irq_spinlock, flags);
 }
 
-unsigned long probe_irq_on(void)
-{
-	return(0);
-}
-
-EXPORT_SYMBOL(probe_irq_on);
-
-int probe_irq_off(unsigned long val)
-{
-	return(0);
-}
-
-EXPORT_SYMBOL(probe_irq_off);
-
-static unsigned int startup_SIGIO_irq(unsigned int irq)
-{
-	return(0);
-}
-
-static void shutdown_SIGIO_irq(unsigned int irq)
-{
-}
-
-static void enable_SIGIO_irq(unsigned int irq)
-{
-}
-
-static void disable_SIGIO_irq(unsigned int irq)
-{
-}
-
-static void mask_and_ack_SIGIO(unsigned int irq)
-{
-}
-
-static void end_SIGIO_irq(unsigned int irq)
-{
-}
-
-static unsigned int startup_SIGVTALRM_irq(unsigned int irq)
-{
-	return(0);
-}
-
-static void shutdown_SIGVTALRM_irq(unsigned int irq)
-{
-}
-
-static void enable_SIGVTALRM_irq(unsigned int irq)
-{
-}
-
-static void disable_SIGVTALRM_irq(unsigned int irq)
-{
-}
-
-static void mask_and_ack_SIGVTALRM(unsigned int irq)
-{
-}
-
-static void end_SIGVTALRM_irq(unsigned int irq)
+/*  presently hw_interrupt_type must define (startup || enable) &&
+ *  disable && end */
+static void dummy(unsigned int irq)
 {
 }
 
 static struct hw_interrupt_type SIGIO_irq_type = {
-	"SIGIO",
-	startup_SIGIO_irq,
-	shutdown_SIGIO_irq,
-	enable_SIGIO_irq,
-	disable_SIGIO_irq,
-	mask_and_ack_SIGIO,
-	end_SIGIO_irq,
-	NULL
+	.typename = "SIGIO",
+	.release = free_irq_by_irq_and_dev,
+	.disable = dummy,
+	.enable = dummy,
+	.ack = dummy,
+	.end = dummy
 };
 
 static struct hw_interrupt_type SIGVTALRM_irq_type = {
-	"SIGVTALRM",
-	startup_SIGVTALRM_irq,
-	shutdown_SIGVTALRM_irq,
-	enable_SIGVTALRM_irq,
-	disable_SIGVTALRM_irq,
-	mask_and_ack_SIGVTALRM,
-	end_SIGVTALRM_irq,
-	NULL
+	.typename = "SIGVTALRM",
+	.release = free_irq_by_irq_and_dev,
+	.shutdown = dummy, /* this is never actually called anyhow */
+	.disable = dummy,
+	.enable = dummy,
+	.ack = dummy,
+	.end = dummy
 };
 
 void __init init_IRQ(void)
===== arch/um/kernel/irq_user.c 1.11 vs edited =====
--- 1.11/arch/um/kernel/irq_user.c	2004-09-13 17:23:23 -07:00
+++ edited/arch/um/kernel/irq_user.c	2004-10-20 19:01:06 -07:00
@@ -263,7 +263,7 @@
 	return((irq->irq == data->irq) && (irq->id == data->dev));
 }
 
-void free_irq_by_irq_and_dev(int irq, void *dev)
+void free_irq_by_irq_and_dev(unsigned int irq, void *dev)
 {
 	struct irq_and_dev data = ((struct irq_and_dev) { .irq  = irq,
 							  .dev  = dev });
===== arch/um/kernel/process_kern.c 1.23 vs edited =====
--- 1.23/arch/um/kernel/process_kern.c	2004-09-13 17:23:22 -07:00
+++ edited/arch/um/kernel/process_kern.c	2004-10-20 17:47:51 -07:00
@@ -206,7 +206,6 @@
 		 * although we are an idle CPU, we do not want to
 		 * get into the scheduler unnecessarily.
 		 */
-		irq_stat[smp_processor_id()].idle_timestamp = jiffies;
 		if(need_resched())
 			schedule();
 		
===== include/asm-um/hardirq.h 1.1 vs edited =====
--- 1.1/include/asm-um/hardirq.h	2002-09-06 10:29:29 -07:00
+++ edited/include/asm-um/hardirq.h	2004-10-20 17:47:51 -07:00
@@ -1,6 +1,26 @@
-#ifndef __UM_HARDIRQ_H
-#define __UM_HARDIRQ_H
+/* (c) 2004 cw@f00f.org, GPLv2 blah blah */
 
-#include "asm/arch/hardirq.h"
+#ifndef __ASM_UM_HARDIRQ_H
+#define __ASM_UM_HARDIRQ_H
 
-#endif
+#include <linux/config.h>
+#include <linux/threads.h>
+#include <linux/irq.h>
+
+/* NOTE: When SMP works again we might want to make this
+ * ____cacheline_aligned or maybe use per_cpu state? --cw */
+typedef struct {
+	unsigned int __softirq_pending;
+} irq_cpustat_t;
+
+#include <linux/irq_cpustat.h>
+
+/* As this would be very strange for UML to get we BUG() after the
+ * printk. */
+static inline void ack_bad_irq(unsigned int irq)
+{
+	printk(KERN_ERR "unexpected IRQ %02x\n", irq);
+	BUG();
+}
+
+#endif /* __ASM_UM_HARDIRQ_H */

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC] add struct hw_interrupt_type->release
  2004-10-21  2:26   ` [RFC] add struct hw_interrupt_type->release Chris Wedgwood
  2004-10-21  2:35     ` [RFC] UML converstion to generic irq code (requires hw_interrupt_type->release(...) patch) Chris Wedgwood
@ 2004-10-21  7:23     ` Christoph Hellwig
  2005-01-13  4:22       ` Paolo \'Blaisorblade\' Giarrusso
  1 sibling, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2004-10-21  7:23 UTC (permalink / raw)
  To: Chris Wedgwood; +Cc: LKML, Ingo Molnar

On Wed, Oct 20, 2004 at 07:26:30PM -0700, Chris Wedgwood wrote:
> On Tue, Oct 19, 2004 at 07:31:56PM -0700, Chris Wedgwood wrote:
> 
> > +++ b/kernel/irq/manage.c	2004-10-19 17:47:40 -07:00
> > @@ -260,6 +260,7 @@
> >  				else
> >  					desc->handler->disable(irq);
> >  			}
>                        ^^^
> > +			platform_free_irq_notify(irq, dev_id);
> >  			spin_unlock_irqrestore(&desc->lock,flags);
> >  			unregister_handler_proc(irq, action);
> >  
> 
> On Wed, Oct 20, 2004 at 02:07:15PM +0100, Christoph Hellwig wrote:
> 
> > This looks rather bogus to me.  What prevents UML from doing it's
> > work at the struct hw_interrupt_type level?
> 
> the ^^^ marked part reads something like if (!desc->action) { ... }
> presumably meaning the shutdown/disable is only done when the very
> last user of an interrupt source is removed
> 
> UML needs to be notified when *any* user is removed so either need
> some way to tell the generic code this or perhaps we could introduce
> another op to hw_interrupt_type along the lines of ->release like
> this:

Care to explain why it needs that?  How exactly is UML using hardirqs,
they seems to fit very badly into the concept of a usermode kernel if
you ask me.  Maybe UML would be better off to not use hardirqs at all,
ala s390.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC] add struct hw_interrupt_type->release
  2004-10-21  7:23     ` [RFC] add struct hw_interrupt_type->release Christoph Hellwig
@ 2005-01-13  4:22       ` Paolo \'Blaisorblade\' Giarrusso
  0 siblings, 0 replies; 7+ messages in thread
From: Paolo \'Blaisorblade\' Giarrusso @ 2005-01-13  4:22 UTC (permalink / raw)
  To: linux-kernel

Christoph Hellwig <hch <at> infradead.org> writes:

> 
> On Wed, Oct 20, 2004 at 07:26:30PM -0700, Chris Wedgwood wrote:
> > On Tue, Oct 19, 2004 at 07:31:56PM -0700, Chris Wedgwood wrote:
> > 
> > > +++ b/kernel/irq/manage.c	2004-10-19 17:47:40 -07:00
> > >  <at>  <at>  -260,6 +260,7  <at>  <at> 
> > >  				else
> > >  					desc->handler->disable(irq);
> > >  			}
> >                        ^^^
> > > +			platform_free_irq_notify(irq, dev_id);
> > >  			spin_unlock_irqrestore(&desc->lock,flags);
> > >  			unregister_handler_proc(irq, action);
> > >  
> > 
> > On Wed, Oct 20, 2004 at 02:07:15PM +0100, Christoph Hellwig wrote:
> > 
> > > This looks rather bogus to me.  What prevents UML from doing it's
> > > work at the struct hw_interrupt_type level?
> > 
> > the ^^^ marked part reads something like if (!desc->action) { ... }
> > presumably meaning the shutdown/disable is only done when the very
> > last user of an interrupt source is removed
> > 
> > UML needs to be notified when *any* user is removed so either need
> > some way to tell the generic code this or perhaps we could introduce
> > another op to hw_interrupt_type along the lines of ->release like
> > this:

> Care to explain why it needs that?  How exactly is UML using hardirqs,
> they seems to fit very badly into the concept of a usermode kernel if
> you ask me.

> Maybe UML would be better off to not use hardirqs at all,
> ala s390.
I don't know about s390, however we have another developer in UML which has 
experience with Linux on that platform... I'll ask him.

However, the main idea is if an hardirq is raised, something has happened on a 
certain file descriptor, associated with the IRQ; the definition of "something 
has happened" is the one which holds for poll(), which is used to implement this 
(see arch/um/kernel/irq_user.c:activate_fd() ).

So, it is clear the need we have?

One real example is for /dev/tty1, when it's emulated by an xterm: we use an IRQ 
to wait for when we receive on a socket the fd of the pipe which connects us 
with the xterm. (The actual datas are not passed through the IRQ).

However, any plan about removing the hardirqs from UML is low-priority for me... 
we have the main need to get the code stable, afterwards to add new missing 
important features, and at the end to rewrite such things... at least until when 
we see the need for such a rewrite.

But the idea is not bad, I think (I am a newcomer, so I don't know why and when 
it was born, for this you could ask to Jeff Dike, if you want).


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2005-01-13  4:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-20  2:31 [PATCH] add hook to generic irq code (free_irq) Chris Wedgwood
2004-10-20 13:07 ` Christoph Hellwig
2004-10-20 19:42   ` Chris Wedgwood
2004-10-21  2:26   ` [RFC] add struct hw_interrupt_type->release Chris Wedgwood
2004-10-21  2:35     ` [RFC] UML converstion to generic irq code (requires hw_interrupt_type->release(...) patch) Chris Wedgwood
2004-10-21  7:23     ` [RFC] add struct hw_interrupt_type->release Christoph Hellwig
2005-01-13  4:22       ` Paolo \'Blaisorblade\' Giarrusso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).