ints.c 9.8 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 58
static int irq_depth[NR_IRQS];

static int m68k_first_user_vec;
59

60
static struct irq_chip auto_irq_chip = {
61
	.name		= "auto",
62 63
	.irq_startup	= m68k_irq_startup,
	.irq_shutdown	= m68k_irq_shutdown,
64
};
L
Linus Torvalds 已提交
65

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

#define NUM_IRQ_NODES 100
73
static struct irq_data nodes[NUM_IRQ_NODES];
L
Linus Torvalds 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89

/*
 * 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;

90 91 92 93 94 95
	/* assembly irq entry code relies on this... */
	if (HARDIRQ_MASK != 0x00ff0000) {
		extern void hardirq_mask_is_broken(void);
		hardirq_mask_is_broken();
	}

96
	for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++)
97
		irq_chip[i] = &auto_irq_chip;
L
Linus Torvalds 已提交
98

99 100 101 102 103 104 105 106
	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 已提交
107
 * standard __m68k_handle_int(), it will be called with irq numbers in the range
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
 * 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 已提交
126
 * to be called instead of the default __m68k_handle_int(), it will be called
127 128 129 130 131 132 133
 * 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;

134
	BUG_ON(IRQ_USER + cnt > NR_IRQS);
135 136
	m68k_first_user_vec = vec;
	for (i = 0; i < cnt; i++)
137
		irq_chip[IRQ_USER + i] = &user_irq_chip;
138 139 140 141 142 143 144
	*user_irqvec_fixup = vec - IRQ_USER;
	if (handler)
		*user_irqhandler_fixup = (u32)handler;
	flush_icache();
}

/**
145
 * m68k_setup_irq_chip
146 147 148 149 150 151 152 153
 * @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.
 */
154
void m68k_setup_irq_chip(struct irq_chip *contr, unsigned int irq,
155 156 157 158 159
			       unsigned int cnt)
{
	int i;

	for (i = 0; i < cnt; i++)
160
		irq_chip[irq + i] = contr;
L
Linus Torvalds 已提交
161 162
}

163
struct irq_data *new_irq_node(void)
L
Linus Torvalds 已提交
164
{
165
	struct irq_data *node;
L
Linus Torvalds 已提交
166 167
	short i;

168 169 170
	for (node = nodes, i = NUM_IRQ_NODES-1; i >= 0; node++, i--) {
		if (!node->handler) {
			memset(node, 0, sizeof(*node));
L
Linus Torvalds 已提交
171
			return node;
172 173
		}
	}
L
Linus Torvalds 已提交
174 175 176 177 178

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

179
int setup_irq(unsigned int irq, struct irq_data *node)
L
Linus Torvalds 已提交
180
{
181
	struct irq_chip *contr;
182
	struct irq_data **prev;
183 184
	unsigned long flags;

185
	if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
L
Linus Torvalds 已提交
186
		printk("%s: Incorrect IRQ %d from %s\n",
187
		       __func__, irq, node->devname);
L
Linus Torvalds 已提交
188 189 190
		return -ENXIO;
	}

191
	local_irq_save(flags);
192 193 194 195

	prev = irq_list + irq;
	if (*prev) {
		/* Can't share interrupts unless both agree to */
196
		if (!((*prev)->flags & node->flags & IRQF_SHARED)) {
197
			local_irq_restore(flags);
L
Linus Torvalds 已提交
198 199
			return -EBUSY;
		}
200 201
		while (*prev)
			prev = &(*prev)->next;
L
Linus Torvalds 已提交
202 203
	}

204
	if (!irq_list[irq]) {
205 206
		if (contr->irq_startup)
			contr->irq_startup(irq);
207
		else
208
			contr->irq_enable(irq);
209 210 211 212
	}
	node->next = NULL;
	*prev = node;

213
	local_irq_restore(flags);
214

L
Linus Torvalds 已提交
215 216 217
	return 0;
}

218
int request_irq(unsigned int irq,
219
		irq_handler_t handler,
220
		unsigned long flags, const char *devname, void *dev_id)
221
{
222
	struct irq_data *node;
223 224 225 226 227 228
	int res;

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

229
	node->irq     = irq;
230 231 232 233 234 235 236 237 238 239 240 241
	node->handler = handler;
	node->flags   = flags;
	node->dev_id  = dev_id;
	node->devname = devname;

	res = setup_irq(irq, node);
	if (res)
		node->handler = NULL;

	return res;
}

242 243 244
EXPORT_SYMBOL(request_irq);

void free_irq(unsigned int irq, void *dev_id)
L
Linus Torvalds 已提交
245
{
246
	struct irq_chip *contr;
247
	struct irq_data **p, *node;
248 249
	unsigned long flags;

250
	if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
251
		printk("%s: Incorrect IRQ %d\n", __func__, irq);
L
Linus Torvalds 已提交
252 253 254
		return;
	}

255
	local_irq_save(flags);
256 257 258 259 260 261 262 263 264 265 266 267 268

	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",
269
		       __func__, irq);
270

271
	if (!irq_list[irq]) {
272 273
		if (contr->irq_shutdown)
			contr->irq_shutdown(irq);
274
		else
275
			contr->irq_disable(irq);
276 277
	}

278
	local_irq_restore(flags);
279 280 281 282 283 284
}

EXPORT_SYMBOL(free_irq);

void enable_irq(unsigned int irq)
{
285
	struct irq_chip *contr;
286 287
	unsigned long flags;

288
	if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
289
		printk("%s: Incorrect IRQ %d\n",
290
		       __func__, irq);
291 292 293
		return;
	}

294
	local_irq_save(flags);
295 296
	if (irq_depth[irq]) {
		if (!--irq_depth[irq]) {
297 298
			if (contr->irq_enable)
				contr->irq_enable(irq);
299 300 301
		}
	} else
		WARN_ON(1);
302
	local_irq_restore(flags);
303 304 305
}

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

307 308
void disable_irq(unsigned int irq)
{
309
	struct irq_chip *contr;
310 311
	unsigned long flags;

312
	if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
313
		printk("%s: Incorrect IRQ %d\n",
314
		       __func__, irq);
315 316 317
		return;
	}

318
	local_irq_save(flags);
319
	if (!irq_depth[irq]++) {
320 321
		if (contr->irq_disable)
			contr->irq_disable(irq);
322
	}
323
	local_irq_restore(flags);
L
Linus Torvalds 已提交
324 325
}

326 327
EXPORT_SYMBOL(disable_irq);

328 329 330 331
void disable_irq_nosync(unsigned int irq) __attribute__((alias("disable_irq")));

EXPORT_SYMBOL(disable_irq_nosync);

332
unsigned int m68k_irq_startup(unsigned int irq)
333 334 335
{
	if (irq <= IRQ_AUTO_7)
		vectors[VEC_SPUR + irq] = auto_inthandler;
336 337
	else
		vectors[m68k_first_user_vec + irq - IRQ_USER] = user_inthandler;
338 339 340 341 342 343 344
	return 0;
}

void m68k_irq_shutdown(unsigned int irq)
{
	if (irq <= IRQ_AUTO_7)
		vectors[VEC_SPUR + irq] = bad_inthandler;
345 346
	else
		vectors[m68k_first_user_vec + irq - IRQ_USER] = bad_inthandler;
347 348 349
}


L
Linus Torvalds 已提交
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
/*
 * 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);

377
unsigned int irq_canonicalize(unsigned int irq)
L
Linus Torvalds 已提交
378
{
379 380 381 382 383
#ifdef CONFIG_Q40
	if (MACH_IS_Q40 && irq == 11)
		irq = 10;
#endif
	return irq;
L
Linus Torvalds 已提交
384 385
}

386
EXPORT_SYMBOL(irq_canonicalize);
L
Linus Torvalds 已提交
387

A
Al Viro 已提交
388
asmlinkage void m68k_handle_int(unsigned int irq)
L
Linus Torvalds 已提交
389
{
390
	struct irq_data *node;
391
	kstat_cpu(0).irqs[irq]++;
392 393
	node = irq_list[irq];
	do {
A
Al Viro 已提交
394
		node->handler(irq, node->dev_id);
395 396
		node = node->next;
	} while (node);
397 398
}

A
Al Viro 已提交
399 400 401 402 403 404 405 406
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);
}

407 408 409 410
asmlinkage void handle_badint(struct pt_regs *regs)
{
	kstat_cpu(0).irqs[0]++;
	printk("unexpected interrupt from %u\n", regs->vector);
L
Linus Torvalds 已提交
411 412 413 414
}

int show_interrupts(struct seq_file *p, void *v)
{
415
	struct irq_chip *contr;
416
	struct irq_data *node;
L
Linus Torvalds 已提交
417 418 419
	int i = *(loff_t *) v;

	/* autovector interrupts */
420
	if (irq_list[i]) {
421
		contr = irq_chip[i];
422
		node = irq_list[i];
423
		seq_printf(p, "%-8s %3u: %10u %s", contr->name, i, kstat_cpu(0).irqs[i], node->devname);
424 425 426
		while ((node = node->next))
			seq_printf(p, ", %s", node->devname);
		seq_puts(p, "\n");
427
	}
L
Linus Torvalds 已提交
428 429 430
	return 0;
}

431
#ifdef CONFIG_PROC_FS
L
Linus Torvalds 已提交
432 433 434 435
void init_irq_proc(void)
{
	/* Insert /proc/irq driver here */
}
436
#endif