ints.c 10.1 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/*
 * linux/arch/m68k/kernel/ints.c -- Linux/m68k general interrupt handling code
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file COPYING in the main directory of this archive
 * for more details.
 *
 * 07/03/96: Timer initialization, and thus mach_sched_init(),
 *           removed from request_irq() and moved to init_time().
 *           We should therefore consider renaming our add_isr() and
 *           remove_isr() to request_irq() and free_irq()
 *           respectively, so they are compliant with the other
 *           architectures.                                     /Jes
 * 11/07/96: Changed all add_/remove_isr() to request_/free_irq() calls.
 *           Removed irq list support, if any machine needs an irq server
 *           it must implement this itself (as it's already done), instead
 *           only default handler are used with mach_default_handler.
 *           request_irq got some flags different from other architectures:
 *           - IRQ_FLG_REPLACE : Replace an existing handler (the default one
 *                               can be replaced without this flag)
 *           - IRQ_FLG_LOCK : handler can't be replaced
 *           There are other machine depending flags, see there
 *           If you want to replace a default handler you should know what
 *           you're doing, since it might handle different other irq sources
 *           which must be served                               /Roman Zippel
 */

#include <linux/module.h>
#include <linux/types.h>
#include <linux/sched.h>
31
#include <linux/interrupt.h>
L
Linus Torvalds 已提交
32 33 34 35 36 37 38 39 40 41
#include <linux/kernel_stat.h>
#include <linux/errno.h>
#include <linux/init.h>

#include <asm/setup.h>
#include <asm/system.h>
#include <asm/irq.h>
#include <asm/traps.h>
#include <asm/page.h>
#include <asm/machdep.h>
42
#include <asm/cacheflush.h>
A
Al Viro 已提交
43
#include <asm/irq_regs.h>
L
Linus Torvalds 已提交
44 45 46 47 48

#ifdef CONFIG_Q40
#include <asm/q40ints.h>
#endif

49 50 51 52
extern u32 auto_irqhandler_fixup[];
extern u32 user_irqhandler_fixup[];
extern u16 user_irqvec_fixup[];

L
Linus Torvalds 已提交
53
/* table for system interrupt handlers */
54
static struct irq_data *irq_list[NR_IRQS];
55
static struct irq_chip *irq_chip[NR_IRQS];
56 57
static int irq_depth[NR_IRQS];

58 59 60 61 62 63
static inline int irq_set_chip(unsigned int irq, struct irq_chip *chip)
{
	irq_chip[irq] = chip;
	return 0;
}

64
static int m68k_first_user_vec;
65

66
static struct irq_chip auto_irq_chip = {
67
	.name		= "auto",
68 69
	.irq_startup	= m68k_irq_startup,
	.irq_shutdown	= m68k_irq_shutdown,
70
};
L
Linus Torvalds 已提交
71

72
static struct irq_chip user_irq_chip = {
73
	.name		= "user",
74 75
	.irq_startup	= m68k_irq_startup,
	.irq_shutdown	= m68k_irq_shutdown,
L
Linus Torvalds 已提交
76 77 78
};

#define NUM_IRQ_NODES 100
79
static struct irq_data nodes[NUM_IRQ_NODES];
L
Linus Torvalds 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

/*
 * void init_IRQ(void)
 *
 * Parameters:	None
 *
 * Returns:	Nothing
 *
 * This function should be called during kernel startup to initialize
 * the IRQ handling routines.
 */

void __init init_IRQ(void)
{
	int i;

96 97 98 99 100 101
	/* assembly irq entry code relies on this... */
	if (HARDIRQ_MASK != 0x00ff0000) {
		extern void hardirq_mask_is_broken(void);
		hardirq_mask_is_broken();
	}

102
	for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++)
103
		irq_set_chip(i, &auto_irq_chip);
L
Linus Torvalds 已提交
104

105 106 107 108 109 110 111 112
	mach_init_IRQ();
}

/**
 * m68k_setup_auto_interrupt
 * @handler: called from auto vector interrupts
 *
 * setup the handler to be called from auto vector interrupts instead of the
A
Al Viro 已提交
113
 * standard __m68k_handle_int(), it will be called with irq numbers in the range
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
 * from IRQ_AUTO_1 - IRQ_AUTO_7.
 */
void __init m68k_setup_auto_interrupt(void (*handler)(unsigned int, struct pt_regs *))
{
	if (handler)
		*auto_irqhandler_fixup = (u32)handler;
	flush_icache();
}

/**
 * m68k_setup_user_interrupt
 * @vec: first user vector interrupt to handle
 * @cnt: number of active user vector interrupts
 * @handler: called from user vector interrupts
 *
 * setup user vector interrupts, this includes activating the specified range
 * of interrupts, only then these interrupts can be requested (note: this is
 * different from auto vector interrupts). An optional handler can be installed
A
Al Viro 已提交
132
 * to be called instead of the default __m68k_handle_int(), it will be called
133 134 135 136 137 138 139
 * with irq numbers starting from IRQ_USER.
 */
void __init m68k_setup_user_interrupt(unsigned int vec, unsigned int cnt,
				      void (*handler)(unsigned int, struct pt_regs *))
{
	int i;

140
	BUG_ON(IRQ_USER + cnt > NR_IRQS);
141 142
	m68k_first_user_vec = vec;
	for (i = 0; i < cnt; i++)
143
		irq_set_chip(IRQ_USER + i, &user_irq_chip);
144 145 146 147 148 149 150
	*user_irqvec_fixup = vec - IRQ_USER;
	if (handler)
		*user_irqhandler_fixup = (u32)handler;
	flush_icache();
}

/**
151
 * m68k_setup_irq_chip
152 153 154 155 156 157 158 159
 * @contr: irq controller which controls specified irq
 * @irq: first irq to be managed by the controller
 *
 * Change the controller for the specified range of irq, which will be used to
 * manage these irq. auto/user irq already have a default controller, which can
 * be changed as well, but the controller probably should use m68k_irq_startup/
 * m68k_irq_shutdown.
 */
160
void m68k_setup_irq_chip(struct irq_chip *contr, unsigned int irq,
161 162 163 164 165
			       unsigned int cnt)
{
	int i;

	for (i = 0; i < cnt; i++)
166
		irq_set_chip(irq + i, contr);
L
Linus Torvalds 已提交
167 168
}

169
struct irq_data *new_irq_node(void)
L
Linus Torvalds 已提交
170
{
171
	struct irq_data *node;
L
Linus Torvalds 已提交
172 173
	short i;

174 175 176
	for (node = nodes, i = NUM_IRQ_NODES-1; i >= 0; node++, i--) {
		if (!node->handler) {
			memset(node, 0, sizeof(*node));
L
Linus Torvalds 已提交
177
			return node;
178 179
		}
	}
L
Linus Torvalds 已提交
180 181 182 183 184

	printk ("new_irq_node: out of nodes\n");
	return NULL;
}

185
static int m68k_setup_irq(unsigned int irq, struct irq_data *node)
L
Linus Torvalds 已提交
186
{
187
	struct irq_chip *contr;
188
	struct irq_data **prev;
189 190
	unsigned long flags;

191
	if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
L
Linus Torvalds 已提交
192
		printk("%s: Incorrect IRQ %d from %s\n",
193
		       __func__, irq, node->devname);
L
Linus Torvalds 已提交
194 195 196
		return -ENXIO;
	}

197
	local_irq_save(flags);
198 199 200 201

	prev = irq_list + irq;
	if (*prev) {
		/* Can't share interrupts unless both agree to */
202
		if (!((*prev)->flags & node->flags & IRQF_SHARED)) {
203
			local_irq_restore(flags);
L
Linus Torvalds 已提交
204 205
			return -EBUSY;
		}
206 207
		while (*prev)
			prev = &(*prev)->next;
L
Linus Torvalds 已提交
208 209
	}

210
	if (!irq_list[irq]) {
211
		if (contr->irq_startup)
212
			contr->irq_startup(node);
213
		else
214
			contr->irq_enable(node);
215 216 217 218
	}
	node->next = NULL;
	*prev = node;

219
	local_irq_restore(flags);
220

L
Linus Torvalds 已提交
221 222 223
	return 0;
}

224
int request_irq(unsigned int irq,
225
		irq_handler_t handler,
226
		unsigned long flags, const char *devname, void *dev_id)
227
{
228
	struct irq_data *node;
229 230 231 232 233 234
	int res;

	node = new_irq_node();
	if (!node)
		return -ENOMEM;

235
	node->irq     = irq;
236 237 238 239 240
	node->handler = handler;
	node->flags   = flags;
	node->dev_id  = dev_id;
	node->devname = devname;

241
	res = m68k_setup_irq(irq, node);
242 243 244 245 246 247
	if (res)
		node->handler = NULL;

	return res;
}

248 249 250
EXPORT_SYMBOL(request_irq);

void free_irq(unsigned int irq, void *dev_id)
L
Linus Torvalds 已提交
251
{
252
	struct irq_chip *contr;
253
	struct irq_data **p, *node;
254 255
	unsigned long flags;

256
	if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
257
		printk("%s: Incorrect IRQ %d\n", __func__, irq);
L
Linus Torvalds 已提交
258 259 260
		return;
	}

261
	local_irq_save(flags);
262 263 264 265 266 267 268 269 270 271 272 273 274

	p = irq_list + irq;
	while ((node = *p)) {
		if (node->dev_id == dev_id)
			break;
		p = &node->next;
	}

	if (node) {
		*p = node->next;
		node->handler = NULL;
	} else
		printk("%s: Removing probably wrong IRQ %d\n",
275
		       __func__, irq);
276

277
	if (!irq_list[irq]) {
278
		if (contr->irq_shutdown)
279
			contr->irq_shutdown(node);
280
		else
281
			contr->irq_disable(node);
282 283
	}

284
	local_irq_restore(flags);
285 286 287 288 289 290
}

EXPORT_SYMBOL(free_irq);

void enable_irq(unsigned int irq)
{
291
	struct irq_chip *contr;
292 293
	unsigned long flags;

294
	if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
295
		printk("%s: Incorrect IRQ %d\n",
296
		       __func__, irq);
297 298 299
		return;
	}

300
	local_irq_save(flags);
301 302
	if (irq_depth[irq]) {
		if (!--irq_depth[irq]) {
303
			if (contr->irq_enable)
304
				contr->irq_enable(irq_list[irq]);
305 306 307
		}
	} else
		WARN_ON(1);
308
	local_irq_restore(flags);
309 310 311
}

EXPORT_SYMBOL(enable_irq);
L
Linus Torvalds 已提交
312

313 314
void disable_irq(unsigned int irq)
{
315
	struct irq_chip *contr;
316 317
	unsigned long flags;

318
	if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
319
		printk("%s: Incorrect IRQ %d\n",
320
		       __func__, irq);
321 322 323
		return;
	}

324
	local_irq_save(flags);
325
	if (!irq_depth[irq]++) {
326
		if (contr->irq_disable)
327
			contr->irq_disable(irq_list[irq]);
328
	}
329
	local_irq_restore(flags);
L
Linus Torvalds 已提交
330 331
}

332 333
EXPORT_SYMBOL(disable_irq);

334 335 336 337
void disable_irq_nosync(unsigned int irq) __attribute__((alias("disable_irq")));

EXPORT_SYMBOL(disable_irq_nosync);

338
unsigned int m68k_irq_startup_irq(unsigned int irq)
339 340 341
{
	if (irq <= IRQ_AUTO_7)
		vectors[VEC_SPUR + irq] = auto_inthandler;
342 343
	else
		vectors[m68k_first_user_vec + irq - IRQ_USER] = user_inthandler;
344 345 346
	return 0;
}

347
unsigned int m68k_irq_startup(struct irq_data *data)
348
{
349 350 351 352 353 354 355
	return m68k_irq_startup_irq(data->irq);
}

void m68k_irq_shutdown(struct irq_data *data)
{
	unsigned int irq = data->irq;

356 357
	if (irq <= IRQ_AUTO_7)
		vectors[VEC_SPUR + irq] = bad_inthandler;
358 359
	else
		vectors[m68k_first_user_vec + irq - IRQ_USER] = bad_inthandler;
360 361 362
}


L
Linus Torvalds 已提交
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
/*
 * Do we need these probe functions on the m68k?
 *
 *  ... may be useful with ISA devices
 */
unsigned long probe_irq_on (void)
{
#ifdef CONFIG_Q40
	if (MACH_IS_Q40)
		return q40_probe_irq_on();
#endif
	return 0;
}

EXPORT_SYMBOL(probe_irq_on);

int probe_irq_off (unsigned long irqs)
{
#ifdef CONFIG_Q40
	if (MACH_IS_Q40)
		return q40_probe_irq_off(irqs);
#endif
	return 0;
}

EXPORT_SYMBOL(probe_irq_off);

390
unsigned int irq_canonicalize(unsigned int irq)
L
Linus Torvalds 已提交
391
{
392 393 394 395 396
#ifdef CONFIG_Q40
	if (MACH_IS_Q40 && irq == 11)
		irq = 10;
#endif
	return irq;
L
Linus Torvalds 已提交
397 398
}

399
EXPORT_SYMBOL(irq_canonicalize);
L
Linus Torvalds 已提交
400

A
Al Viro 已提交
401
asmlinkage void m68k_handle_int(unsigned int irq)
L
Linus Torvalds 已提交
402
{
403
	struct irq_data *node;
404
	kstat_cpu(0).irqs[irq]++;
405 406
	node = irq_list[irq];
	do {
A
Al Viro 已提交
407
		node->handler(irq, node->dev_id);
408 409
		node = node->next;
	} while (node);
410 411
}

A
Al Viro 已提交
412 413 414 415 416 417 418 419
asmlinkage void __m68k_handle_int(unsigned int irq, struct pt_regs *regs)
{
	struct pt_regs *old_regs;
	old_regs = set_irq_regs(regs);
	m68k_handle_int(irq);
	set_irq_regs(old_regs);
}

420 421 422 423
asmlinkage void handle_badint(struct pt_regs *regs)
{
	kstat_cpu(0).irqs[0]++;
	printk("unexpected interrupt from %u\n", regs->vector);
L
Linus Torvalds 已提交
424 425 426 427
}

int show_interrupts(struct seq_file *p, void *v)
{
428
	struct irq_chip *contr;
429
	struct irq_data *node;
L
Linus Torvalds 已提交
430 431 432
	int i = *(loff_t *) v;

	/* autovector interrupts */
433
	if (irq_list[i]) {
434
		contr = irq_chip[i];
435
		node = irq_list[i];
436
		seq_printf(p, "%-8s %3u: %10u %s", contr->name, i, kstat_cpu(0).irqs[i], node->devname);
437 438 439
		while ((node = node->next))
			seq_printf(p, ", %s", node->devname);
		seq_puts(p, "\n");
440
	}
L
Linus Torvalds 已提交
441 442 443
	return 0;
}

444
#ifdef CONFIG_PROC_FS
L
Linus Torvalds 已提交
445 446 447 448
void init_irq_proc(void)
{
	/* Insert /proc/irq driver here */
}
449
#endif