From: Pantelis Antoniou <panto@intracom.gr>
To: Ingo Molnar <mingo@elte.hu>, Tom Rini <trini@kernel.crashing.org>,
Linuxppc-Embedded <linuxppc-embedded@lists.linuxppc.org>,
Linux Kernel list <linux-kernel@vger.kernel.org>
Subject: [PATCH] Fix early request_irq
Date: Fri, 29 Oct 2004 17:05:09 +0300 [thread overview]
Message-ID: <41824E15.4090906@intracom.gr> (raw)
[-- Attachment #1: Type: text/plain, Size: 623 bytes --]
Hi there
The recent consolidation of the IRQ code has caused
a number of PPC embedded cpus to stop working.
The problem is that on init_IRQ these platforms call
request_irq very early, which in turn calls kmalloc
without the memory subsystem being initialized.
The following patch fixes it by keeping a small static
array of irqactions just for this purpose.
This is still not enough to get these platforms working
since I crash on the first interrupt, but at least is a
start.
Regards
Pantelis
Signed-off-by: Pantelis Antoniou <panto@intracom.gr>
---------------------------------------------------------------
[-- Attachment #2: early-irq-fix.patch --]
[-- Type: text/x-patch, Size: 2263 bytes --]
--- linux-2.5/kernel/irq/manage.c 2004-10-29 16:39:08.496715752 +0300
+++ linuxppc_2.5-public/kernel/irq/manage.c 2004-10-29 16:44:13.361369280 +0300
@@ -10,6 +10,7 @@
#include <linux/module.h>
#include <linux/random.h>
#include <linux/interrupt.h>
+#include <linux/bitops.h>
#include "internals.h"
@@ -144,6 +145,53 @@
return !action;
}
+/* we must support request_irqs before mem init */
+
+#define IRQ_CACHE_ENTRIES 8 /* 8 should be enough */
+
+static spinlock_t irqa_lock = SPIN_LOCK_UNLOCKED;
+static unsigned int irqa_cache_map = (1 << IRQ_CACHE_ENTRIES) - 1;
+static struct irqaction irqa_cache[IRQ_CACHE_ENTRIES];
+
+static struct irqaction *irqaction_alloc(int pri)
+{
+ extern int mem_init_done;
+ int i;
+ unsigned long flags;
+ struct irqaction *irqa;
+
+ if (mem_init_done)
+ return kmalloc(sizeof(struct irqaction), pri);
+
+ spin_lock_irqsave(&irqa_lock, flags);
+ i = ffs(irqa_cache_map);
+ if (i > 0 && --i < IRQ_CACHE_ENTRIES) {
+ irqa_cache_map &= ~(1 << i);
+ irqa = irqa_cache + i;
+ } else
+ irqa = NULL;
+ spin_unlock_irqrestore(&irqa_lock, flags);
+
+ return irqa;
+}
+
+static void irqaction_free(void *ptr)
+{
+ struct irqaction *irqa = ptr;
+ unsigned long flags;
+ int i;
+
+ if (irqa < irqa_cache || irqa >= irqa_cache + IRQ_CACHE_ENTRIES) {
+ kfree(ptr);
+ return;
+ }
+
+ spin_lock_irqsave(&irqa_lock, flags);
+ i = irqa_cache - irqa;
+ irqa_cache_map |= 1 << i;
+ spin_unlock_irqrestore(&irqa_lock, flags);
+}
+
/*
* Internal function to register an irqaction - typically used to
* allocate special interrupts that are part of the architecture.
@@ -265,7 +313,7 @@
/* Make sure it's not being used on another CPU */
synchronize_irq(irq);
- kfree(action);
+ irqaction_free(action);
return;
}
printk(KERN_ERR "Trying to free free IRQ%d\n",irq);
@@ -325,7 +373,7 @@
if (!handler)
return -EINVAL;
- action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
+ action = irqaction_alloc(GFP_ATOMIC);
if (!action)
return -ENOMEM;
@@ -337,10 +385,12 @@
action->dev_id = dev_id;
retval = setup_irq(irq, action);
- if (retval)
- kfree(action);
+ if (retval) {
+ irqaction_free(action);
+ return retval;
+ }
- return retval;
+ return 0;
}
EXPORT_SYMBOL(request_irq);
next reply other threads:[~2004-10-29 14:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-29 14:05 Pantelis Antoniou [this message]
2004-10-29 14:16 ` [PATCH] Fix early request_irq Ingo Molnar
2004-10-29 14:20 ` Pantelis Antoniou
2004-10-29 14:21 ` Christoph Hellwig
2004-10-29 16:11 ` Tom Rini
2004-11-01 17:41 ` Kumar Gala
2004-11-01 19:59 ` Tom Rini
2004-11-02 7:51 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=41824E15.4090906@intracom.gr \
--to=panto@intracom.gr \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-embedded@lists.linuxppc.org \
--cc=mingo@elte.hu \
--cc=trini@kernel.crashing.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.