Skip to content

Commit 68387c4

Browse files
Roman ZippelLinus Torvalds
authored andcommitted
[PATCH] m68k: convert generic irq code to irq controller
Convert the generic irq code to use irq controller, this gets rid of the machine specific callbacks and gives better control over irq handling without duplicating lots of code. Signed-off-by: Roman Zippel <zippel@linux-m68k.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent b5dc784 commit 68387c4

8 files changed

Lines changed: 188 additions & 148 deletions

File tree

‎arch/m68k/kernel/entry.S‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
.globl sys_call_table
4949
.globl sys_fork, sys_clone, sys_vfork
5050
.globl ret_from_interrupt, bad_interrupt
51+
.globl auto_irqhandler_fixup
52+
.globl user_irqvec_fixup, user_irqhandler_fixup
5153

5254
.text
5355
ENTRY(buserr)
@@ -212,6 +214,7 @@ ENTRY(auto_inthandler)
212214
jbra 3f
213215
1:
214216
#endif
217+
auto_irqhandler_fixup = . + 2
215218
jsr m68k_handle_int | process the IRQ
216219
3: addql #8,%sp | pop parameters off stack
217220

@@ -234,17 +237,19 @@ ret_from_last_interrupt:
234237

235238
/* Handler for user defined interrupt vectors */
236239

237-
ENTRY(mach_inthandler)
240+
ENTRY(user_inthandler)
238241
SAVE_ALL_INT
239242
GET_CURRENT(%d0)
240243
addqb #1,%curptr@(TASK_INFO+TINFO_PREEMPT+1)
241244
| put exception # in d0
242245
bfextu %sp@(PT_VECTOR){#4,#10},%d0
246+
user_irqvec_fixup = . + 2
247+
subw #VEC_USER,%d0
243248

244249
movel %sp,%sp@-
245250
movel %d0,%sp@- | put vector # on stack
246-
movel mach_process_int,%a0
247-
jsr %a0@ | process the IRQ
251+
user_irqhandler_fixup = . + 2
252+
jsr m68k_handle_int | process the IRQ
248253
addql #8,%sp | pop parameters off stack
249254

250255
subqb #1,%curptr@(TASK_INFO+TINFO_PREEMPT+1)

‎arch/m68k/kernel/ints.c‎

Lines changed: 152 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,22 @@
3939
#include <asm/traps.h>
4040
#include <asm/page.h>
4141
#include <asm/machdep.h>
42+
#include <asm/cacheflush.h>
4243

4344
#ifdef CONFIG_Q40
4445
#include <asm/q40ints.h>
4546
#endif
4647

48+
extern u32 auto_irqhandler_fixup[];
49+
extern u32 user_irqhandler_fixup[];
50+
extern u16 user_irqvec_fixup[];
51+
4752
/* table for system interrupt handlers */
48-
static struct irq_node *irq_list[SYS_IRQS];
49-
static struct irq_controller *irq_controller[SYS_IRQS];
53+
static struct irq_node *irq_list[NR_IRQS];
54+
static struct irq_controller *irq_controller[NR_IRQS];
55+
static int irq_depth[NR_IRQS];
56+
57+
static int m68k_first_user_vec;
5058

5159
static struct irq_controller auto_irq_controller = {
5260
.name = "auto",
@@ -55,39 +63,16 @@ static struct irq_controller auto_irq_controller = {
5563
.shutdown = m68k_irq_shutdown,
5664
};
5765

58-
static const char *default_names[SYS_IRQS] = {
59-
[0] = "spurious int",
60-
[1] = "int1 handler",
61-
[2] = "int2 handler",
62-
[3] = "int3 handler",
63-
[4] = "int4 handler",
64-
[5] = "int5 handler",
65-
[6] = "int6 handler",
66-
[7] = "int7 handler"
66+
static struct irq_controller user_irq_controller = {
67+
.name = "user",
68+
.lock = SPIN_LOCK_UNLOCKED,
69+
.startup = m68k_irq_startup,
70+
.shutdown = m68k_irq_shutdown,
6771
};
6872

69-
/* The number of spurious interrupts */
70-
volatile unsigned int num_spurious;
71-
7273
#define NUM_IRQ_NODES 100
7374
static irq_node_t nodes[NUM_IRQ_NODES];
7475

75-
static void dummy_enable_irq(unsigned int irq);
76-
static void dummy_disable_irq(unsigned int irq);
77-
static int dummy_request_irq(unsigned int irq,
78-
irqreturn_t (*handler) (int, void *, struct pt_regs *),
79-
unsigned long flags, const char *devname, void *dev_id);
80-
static void dummy_free_irq(unsigned int irq, void *dev_id);
81-
82-
void (*enable_irq) (unsigned int) = dummy_enable_irq;
83-
void (*disable_irq) (unsigned int) = dummy_disable_irq;
84-
85-
int (*mach_request_irq) (unsigned int, irqreturn_t (*)(int, void *, struct pt_regs *),
86-
unsigned long, const char *, void *) = dummy_request_irq;
87-
void (*mach_free_irq) (unsigned int, void *) = dummy_free_irq;
88-
89-
void init_irq_proc(void);
90-
9176
/*
9277
* void init_IRQ(void)
9378
*
@@ -109,14 +94,70 @@ void __init init_IRQ(void)
10994
hardirq_mask_is_broken();
11095
}
11196

112-
for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++) {
97+
for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++)
11398
irq_controller[i] = &auto_irq_controller;
114-
if (mach_default_handler && (*mach_default_handler)[i])
115-
cpu_request_irq(i, (*mach_default_handler)[i],
116-
0, default_names[i], NULL);
117-
}
11899

119-
mach_init_IRQ ();
100+
mach_init_IRQ();
101+
}
102+
103+
/**
104+
* m68k_setup_auto_interrupt
105+
* @handler: called from auto vector interrupts
106+
*
107+
* setup the handler to be called from auto vector interrupts instead of the
108+
* standard m68k_handle_int(), it will be called with irq numbers in the range
109+
* from IRQ_AUTO_1 - IRQ_AUTO_7.
110+
*/
111+
void __init m68k_setup_auto_interrupt(void (*handler)(unsigned int, struct pt_regs *))
112+
{
113+
if (handler)
114+
*auto_irqhandler_fixup = (u32)handler;
115+
flush_icache();
116+
}
117+
118+
/**
119+
* m68k_setup_user_interrupt
120+
* @vec: first user vector interrupt to handle
121+
* @cnt: number of active user vector interrupts
122+
* @handler: called from user vector interrupts
123+
*
124+
* setup user vector interrupts, this includes activating the specified range
125+
* of interrupts, only then these interrupts can be requested (note: this is
126+
* different from auto vector interrupts). An optional handler can be installed
127+
* to be called instead of the default m68k_handle_int(), it will be called
128+
* with irq numbers starting from IRQ_USER.
129+
*/
130+
void __init m68k_setup_user_interrupt(unsigned int vec, unsigned int cnt,
131+
void (*handler)(unsigned int, struct pt_regs *))
132+
{
133+
int i;
134+
135+
m68k_first_user_vec = vec;
136+
for (i = 0; i < cnt; i++)
137+
irq_controller[IRQ_USER + i] = &user_irq_controller;
138+
*user_irqvec_fixup = vec - IRQ_USER;
139+
if (handler)
140+
*user_irqhandler_fixup = (u32)handler;
141+
flush_icache();
142+
}
143+
144+
/**
145+
* m68k_setup_irq_controller
146+
* @contr: irq controller which controls specified irq
147+
* @irq: first irq to be managed by the controller
148+
*
149+
* Change the controller for the specified range of irq, which will be used to
150+
* manage these irq. auto/user irq already have a default controller, which can
151+
* be changed as well, but the controller probably should use m68k_irq_startup/
152+
* m68k_irq_shutdown.
153+
*/
154+
void m68k_setup_irq_controller(struct irq_controller *contr, unsigned int irq,
155+
unsigned int cnt)
156+
{
157+
int i;
158+
159+
for (i = 0; i < cnt; i++)
160+
irq_controller[irq + i] = contr;
120161
}
121162

122163
irq_node_t *new_irq_node(void)
@@ -135,34 +176,13 @@ irq_node_t *new_irq_node(void)
135176
return NULL;
136177
}
137178

138-
/*
139-
* We will keep these functions until I have convinced Linus to move
140-
* the declaration of them from include/linux/sched.h to
141-
* include/asm/irq.h.
142-
*/
143-
int request_irq(unsigned int irq,
144-
irqreturn_t (*handler) (int, void *, struct pt_regs *),
145-
unsigned long flags, const char *devname, void *dev_id)
146-
{
147-
return mach_request_irq(irq, handler, flags, devname, dev_id);
148-
}
149-
150-
EXPORT_SYMBOL(request_irq);
151-
152-
void free_irq(unsigned int irq, void *dev_id)
153-
{
154-
mach_free_irq(irq, dev_id);
155-
}
156-
157-
EXPORT_SYMBOL(free_irq);
158-
159179
int setup_irq(unsigned int irq, struct irq_node *node)
160180
{
161181
struct irq_controller *contr;
162182
struct irq_node **prev;
163183
unsigned long flags;
164184

165-
if (irq >= SYS_IRQS || !(contr = irq_controller[irq])) {
185+
if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
166186
printk("%s: Incorrect IRQ %d from %s\n",
167187
__FUNCTION__, irq, node->devname);
168188
return -ENXIO;
@@ -195,9 +215,9 @@ int setup_irq(unsigned int irq, struct irq_node *node)
195215
return 0;
196216
}
197217

198-
int cpu_request_irq(unsigned int irq,
199-
irqreturn_t (*handler)(int, void *, struct pt_regs *),
200-
unsigned long flags, const char *devname, void *dev_id)
218+
int request_irq(unsigned int irq,
219+
irqreturn_t (*handler) (int, void *, struct pt_regs *),
220+
unsigned long flags, const char *devname, void *dev_id)
201221
{
202222
struct irq_node *node;
203223
int res;
@@ -218,13 +238,15 @@ int cpu_request_irq(unsigned int irq,
218238
return res;
219239
}
220240

221-
void cpu_free_irq(unsigned int irq, void *dev_id)
241+
EXPORT_SYMBOL(request_irq);
242+
243+
void free_irq(unsigned int irq, void *dev_id)
222244
{
223245
struct irq_controller *contr;
224246
struct irq_node **p, *node;
225247
unsigned long flags;
226248

227-
if (irq >= SYS_IRQS || !(contr = irq_controller[irq])) {
249+
if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
228250
printk("%s: Incorrect IRQ %d\n", __FUNCTION__, irq);
229251
return;
230252
}
@@ -245,23 +267,78 @@ void cpu_free_irq(unsigned int irq, void *dev_id)
245267
printk("%s: Removing probably wrong IRQ %d\n",
246268
__FUNCTION__, irq);
247269

248-
if (!irq_list[irq])
249-
contr->shutdown(irq);
270+
if (!irq_list[irq]) {
271+
if (contr->shutdown)
272+
contr->shutdown(irq);
273+
else
274+
contr->disable(irq);
275+
}
276+
277+
spin_unlock_irqrestore(&contr->lock, flags);
278+
}
279+
280+
EXPORT_SYMBOL(free_irq);
281+
282+
void enable_irq(unsigned int irq)
283+
{
284+
struct irq_controller *contr;
285+
unsigned long flags;
286+
287+
if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
288+
printk("%s: Incorrect IRQ %d\n",
289+
__FUNCTION__, irq);
290+
return;
291+
}
292+
293+
spin_lock_irqsave(&contr->lock, flags);
294+
if (irq_depth[irq]) {
295+
if (!--irq_depth[irq]) {
296+
if (contr->enable)
297+
contr->enable(irq);
298+
}
299+
} else
300+
WARN_ON(1);
301+
spin_unlock_irqrestore(&contr->lock, flags);
302+
}
303+
304+
EXPORT_SYMBOL(enable_irq);
250305

306+
void disable_irq(unsigned int irq)
307+
{
308+
struct irq_controller *contr;
309+
unsigned long flags;
310+
311+
if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
312+
printk("%s: Incorrect IRQ %d\n",
313+
__FUNCTION__, irq);
314+
return;
315+
}
316+
317+
spin_lock_irqsave(&contr->lock, flags);
318+
if (!irq_depth[irq]++) {
319+
if (contr->disable)
320+
contr->disable(irq);
321+
}
251322
spin_unlock_irqrestore(&contr->lock, flags);
252323
}
253324

325+
EXPORT_SYMBOL(disable_irq);
326+
254327
int m68k_irq_startup(unsigned int irq)
255328
{
256329
if (irq <= IRQ_AUTO_7)
257330
vectors[VEC_SPUR + irq] = auto_inthandler;
331+
else
332+
vectors[m68k_first_user_vec + irq - IRQ_USER] = user_inthandler;
258333
return 0;
259334
}
260335

261336
void m68k_irq_shutdown(unsigned int irq)
262337
{
263338
if (irq <= IRQ_AUTO_7)
264339
vectors[VEC_SPUR + irq] = bad_inthandler;
340+
else
341+
vectors[m68k_first_user_vec + irq - IRQ_USER] = bad_inthandler;
265342
}
266343

267344

@@ -292,28 +369,16 @@ int probe_irq_off (unsigned long irqs)
292369

293370
EXPORT_SYMBOL(probe_irq_off);
294371

295-
static void dummy_enable_irq(unsigned int irq)
372+
unsigned int irq_canonicalize(unsigned int irq)
296373
{
297-
printk("calling uninitialized enable_irq()\n");
298-
}
299-
300-
static void dummy_disable_irq(unsigned int irq)
301-
{
302-
printk("calling uninitialized disable_irq()\n");
303-
}
304-
305-
static int dummy_request_irq(unsigned int irq,
306-
irqreturn_t (*handler) (int, void *, struct pt_regs *),
307-
unsigned long flags, const char *devname, void *dev_id)
308-
{
309-
printk("calling uninitialized request_irq()\n");
310-
return 0;
374+
#ifdef CONFIG_Q40
375+
if (MACH_IS_Q40 && irq == 11)
376+
irq = 10;
377+
#endif
378+
return irq;
311379
}
312380

313-
static void dummy_free_irq(unsigned int irq, void *dev_id)
314-
{
315-
printk("calling uninitialized disable_irq()\n");
316-
}
381+
EXPORT_SYMBOL(irq_canonicalize);
317382

318383
asmlinkage void m68k_handle_int(unsigned int irq, struct pt_regs *regs)
319384
{
@@ -340,15 +405,14 @@ int show_interrupts(struct seq_file *p, void *v)
340405
int i = *(loff_t *) v;
341406

342407
/* autovector interrupts */
343-
if (i < SYS_IRQS && irq_list[i]) {
408+
if (irq_list[i]) {
344409
contr = irq_controller[i];
345410
node = irq_list[i];
346-
seq_printf(p, "%s %u: %10u %s", contr->name, i, kstat_cpu(0).irqs[i], node->devname);
411+
seq_printf(p, "%-8s %3u: %10u %s", contr->name, i, kstat_cpu(0).irqs[i], node->devname);
347412
while ((node = node->next))
348413
seq_printf(p, ", %s", node->devname);
349414
seq_puts(p, "\n");
350-
} else if (i == SYS_IRQS)
351-
mach_get_irq_list(p, v);
415+
}
352416
return 0;
353417
}
354418

‎arch/m68k/kernel/m68k_ksyms.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ EXPORT_SYMBOL(dump_thread);
5757
EXPORT_SYMBOL(strnlen);
5858
EXPORT_SYMBOL(strrchr);
5959
EXPORT_SYMBOL(strstr);
60-
EXPORT_SYMBOL(enable_irq);
61-
EXPORT_SYMBOL(disable_irq);
6260
EXPORT_SYMBOL(kernel_thread);
6361
#ifdef CONFIG_VME
6462
EXPORT_SYMBOL(vme_brdtype);

0 commit comments

Comments
 (0)