chip.c 19.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * linux/kernel/irq/chip.c
 *
 * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
 * Copyright (C) 2005-2006, Thomas Gleixner, Russell King
 *
 * This file contains the core interrupt handling code, for irq-chip
 * based architectures.
 *
 * Detailed information is available in Documentation/DocBook/genericirq
 */

#include <linux/irq.h>
14
#include <linux/msi.h>
15 16 17 18 19 20 21
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/kernel_stat.h>

#include "internals.h"

/**
T
Thomas Gleixner 已提交
22
 *	irq_set_chip - set the irq chip for an irq
23 24 25
 *	@irq:	irq number
 *	@chip:	pointer to irq chip description structure
 */
T
Thomas Gleixner 已提交
26
int irq_set_chip(unsigned int irq, struct irq_chip *chip)
27
{
28
	struct irq_desc *desc = irq_to_desc(irq);
29 30
	unsigned long flags;

31
	if (!desc) {
32
		WARN(1, KERN_ERR "Trying to install chip for IRQ%d\n", irq);
33 34 35 36 37 38
		return -EINVAL;
	}

	if (!chip)
		chip = &no_irq_chip;

39
	raw_spin_lock_irqsave(&desc->lock, flags);
40
	irq_chip_set_defaults(chip);
41
	desc->irq_data.chip = chip;
42
	raw_spin_unlock_irqrestore(&desc->lock, flags);
43 44 45

	return 0;
}
T
Thomas Gleixner 已提交
46
EXPORT_SYMBOL(irq_set_chip);
47 48

/**
T
Thomas Gleixner 已提交
49
 *	irq_set_type - set the irq trigger type for an irq
50
 *	@irq:	irq number
D
David Brownell 已提交
51
 *	@type:	IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h
52
 */
T
Thomas Gleixner 已提交
53
int irq_set_irq_type(unsigned int irq, unsigned int type)
54
{
55
	struct irq_desc *desc = irq_to_desc(irq);
56 57 58
	unsigned long flags;
	int ret = -ENXIO;

59
	if (!desc) {
60 61 62 63
		printk(KERN_ERR "Trying to set irq type for IRQ%d\n", irq);
		return -ENODEV;
	}

64
	type &= IRQ_TYPE_SENSE_MASK;
D
David Brownell 已提交
65 66 67
	if (type == IRQ_TYPE_NONE)
		return 0;

68
	chip_bus_lock(desc);
69
	raw_spin_lock_irqsave(&desc->lock, flags);
70
	ret = __irq_set_trigger(desc, irq, type);
71
	raw_spin_unlock_irqrestore(&desc->lock, flags);
72
	chip_bus_sync_unlock(desc);
73 74
	return ret;
}
T
Thomas Gleixner 已提交
75
EXPORT_SYMBOL(irq_set_irq_type);
76 77

/**
T
Thomas Gleixner 已提交
78
 *	irq_set_handler_data - set irq handler data for an irq
79 80 81 82 83
 *	@irq:	Interrupt number
 *	@data:	Pointer to interrupt specific data
 *
 *	Set the hardware irq controller data for an irq
 */
T
Thomas Gleixner 已提交
84
int irq_set_handler_data(unsigned int irq, void *data)
85
{
86
	struct irq_desc *desc = irq_to_desc(irq);
87 88
	unsigned long flags;

89
	if (!desc) {
90 91 92 93 94
		printk(KERN_ERR
		       "Trying to install controller data for IRQ%d\n", irq);
		return -EINVAL;
	}

95
	raw_spin_lock_irqsave(&desc->lock, flags);
96
	desc->irq_data.handler_data = data;
97
	raw_spin_unlock_irqrestore(&desc->lock, flags);
98 99
	return 0;
}
T
Thomas Gleixner 已提交
100
EXPORT_SYMBOL(irq_set_handler_data);
101

102
/**
T
Thomas Gleixner 已提交
103
 *	irq_set_msi_desc - set MSI descriptor data for an irq
104
 *	@irq:	Interrupt number
R
Randy Dunlap 已提交
105
 *	@entry:	Pointer to MSI descriptor data
106
 *
L
Liuweni 已提交
107
 *	Set the MSI descriptor entry for an irq
108
 */
T
Thomas Gleixner 已提交
109
int irq_set_msi_desc(unsigned int irq, struct msi_desc *entry)
110
{
111
	struct irq_desc *desc = irq_to_desc(irq);
112 113
	unsigned long flags;

114
	if (!desc) {
115 116 117 118
		printk(KERN_ERR
		       "Trying to install msi data for IRQ%d\n", irq);
		return -EINVAL;
	}
119

120
	raw_spin_lock_irqsave(&desc->lock, flags);
121
	desc->irq_data.msi_desc = entry;
122 123
	if (entry)
		entry->irq = irq;
124
	raw_spin_unlock_irqrestore(&desc->lock, flags);
125 126 127
	return 0;
}

128
/**
T
Thomas Gleixner 已提交
129
 *	irq_set_chip_data - set irq chip data for an irq
130 131 132 133 134
 *	@irq:	Interrupt number
 *	@data:	Pointer to chip specific data
 *
 *	Set the hardware irq chip data for an irq
 */
T
Thomas Gleixner 已提交
135
int irq_set_chip_data(unsigned int irq, void *data)
136
{
137
	struct irq_desc *desc = irq_to_desc(irq);
138 139
	unsigned long flags;

140 141 142 143 144 145
	if (!desc) {
		printk(KERN_ERR
		       "Trying to install chip data for IRQ%d\n", irq);
		return -EINVAL;
	}

146
	if (!desc->irq_data.chip) {
147 148 149 150
		printk(KERN_ERR "BUG: bad set_irq_chip_data(IRQ#%d)\n", irq);
		return -EINVAL;
	}

151
	raw_spin_lock_irqsave(&desc->lock, flags);
152
	desc->irq_data.chip_data = data;
153
	raw_spin_unlock_irqrestore(&desc->lock, flags);
154 155 156

	return 0;
}
T
Thomas Gleixner 已提交
157
EXPORT_SYMBOL(irq_set_chip_data);
158

159 160 161 162 163 164 165 166
struct irq_data *irq_get_irq_data(unsigned int irq)
{
	struct irq_desc *desc = irq_to_desc(irq);

	return desc ? &desc->irq_data : NULL;
}
EXPORT_SYMBOL_GPL(irq_get_irq_data);

167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
/**
 *	set_irq_nested_thread - Set/Reset the IRQ_NESTED_THREAD flag of an irq
 *
 *	@irq:	Interrupt number
 *	@nest:	0 to clear / 1 to set the IRQ_NESTED_THREAD flag
 *
 *	The IRQ_NESTED_THREAD flag indicates that on
 *	request_threaded_irq() no separate interrupt thread should be
 *	created for the irq as the handler are called nested in the
 *	context of a demultiplexing interrupt handler thread.
 */
void set_irq_nested_thread(unsigned int irq, int nest)
{
	struct irq_desc *desc = irq_to_desc(irq);
	unsigned long flags;

	if (!desc)
		return;

186
	raw_spin_lock_irqsave(&desc->lock, flags);
187 188 189 190
	if (nest)
		desc->status |= IRQ_NESTED_THREAD;
	else
		desc->status &= ~IRQ_NESTED_THREAD;
191
	raw_spin_unlock_irqrestore(&desc->lock, flags);
192 193 194
}
EXPORT_SYMBOL_GPL(set_irq_nested_thread);

195 196 197 198 199 200 201 202
int irq_startup(struct irq_desc *desc)
{
	desc->status &= ~(IRQ_MASKED | IRQ_DISABLED);
	desc->depth = 0;

	if (desc->irq_data.chip->irq_startup)
		return desc->irq_data.chip->irq_startup(&desc->irq_data);

203
	irq_enable(desc);
204 205 206 207 208 209 210 211 212 213
	return 0;
}

void irq_shutdown(struct irq_desc *desc)
{
	desc->status |= IRQ_MASKED | IRQ_DISABLED;
	desc->depth = 1;
	desc->irq_data.chip->irq_shutdown(&desc->irq_data);
}

214 215 216 217 218 219 220 221 222 223
void irq_enable(struct irq_desc *desc)
{
	desc->irq_data.chip->irq_enable(&desc->irq_data);
}

void irq_disable(struct irq_desc *desc)
{
	desc->irq_data.chip->irq_disable(&desc->irq_data);
}

224 225 226
/*
 * default enable function
 */
227
static void default_enable(struct irq_data *data)
228
{
229
	struct irq_desc *desc = irq_data_to_desc(data);
230

231
	desc->irq_data.chip->irq_unmask(&desc->irq_data);
232 233 234 235 236 237
	desc->status &= ~IRQ_MASKED;
}

/*
 * default disable function
 */
238
static void default_disable(struct irq_data *data)
239 240 241
{
}

242 243 244
/*
 * default shutdown function
 */
245
static void default_shutdown(struct irq_data *data)
246
{
247
	struct irq_desc *desc = irq_data_to_desc(data);
248

249
	desc->irq_data.chip->irq_mask(&desc->irq_data);
250 251
}

252
#ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
253
/* Temporary migration helpers */
254 255 256 257 258
static void compat_irq_mask(struct irq_data *data)
{
	data->chip->mask(data->irq);
}

259 260 261 262 263
static void compat_irq_unmask(struct irq_data *data)
{
	data->chip->unmask(data->irq);
}

264 265 266 267 268
static void compat_irq_ack(struct irq_data *data)
{
	data->chip->ack(data->irq);
}

269 270 271 272 273
static void compat_irq_mask_ack(struct irq_data *data)
{
	data->chip->mask_ack(data->irq);
}

274 275 276 277 278
static void compat_irq_eoi(struct irq_data *data)
{
	data->chip->eoi(data->irq);
}

279 280 281 282 283
static void compat_irq_enable(struct irq_data *data)
{
	data->chip->enable(data->irq);
}

284 285 286 287 288 289 290 291 292 293
static void compat_irq_disable(struct irq_data *data)
{
	data->chip->disable(data->irq);
}

static void compat_irq_shutdown(struct irq_data *data)
{
	data->chip->shutdown(data->irq);
}

294 295 296 297 298
static unsigned int compat_irq_startup(struct irq_data *data)
{
	return data->chip->startup(data->irq);
}

299 300 301 302 303 304
static int compat_irq_set_affinity(struct irq_data *data,
				   const struct cpumask *dest, bool force)
{
	return data->chip->set_affinity(data->irq, dest);
}

305 306 307 308 309
static int compat_irq_set_type(struct irq_data *data, unsigned int type)
{
	return data->chip->set_type(data->irq, type);
}

310 311 312 313 314
static int compat_irq_set_wake(struct irq_data *data, unsigned int on)
{
	return data->chip->set_wake(data->irq, on);
}

315 316 317 318 319
static int compat_irq_retrigger(struct irq_data *data)
{
	return data->chip->retrigger(data->irq);
}

320 321 322 323 324 325 326 327 328
static void compat_bus_lock(struct irq_data *data)
{
	data->chip->bus_lock(data->irq);
}

static void compat_bus_sync_unlock(struct irq_data *data)
{
	data->chip->bus_sync_unlock(data->irq);
}
329
#endif
330

331 332 333 334 335
/*
 * Fixup enable/disable function pointers
 */
void irq_chip_set_defaults(struct irq_chip *chip)
{
336
#ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
337 338 339 340 341 342
	/*
	 * Compat fixup functions need to be before we set the
	 * defaults for enable/disable/startup/shutdown
	 */
	if (chip->enable)
		chip->irq_enable = compat_irq_enable;
343 344 345 346
	if (chip->disable)
		chip->irq_disable = compat_irq_disable;
	if (chip->shutdown)
		chip->irq_shutdown = compat_irq_shutdown;
347 348
	if (chip->startup)
		chip->irq_startup = compat_irq_startup;
349
#endif
350 351 352 353 354
	/*
	 * The real defaults
	 */
	if (!chip->irq_enable)
		chip->irq_enable = default_enable;
355 356
	if (!chip->irq_disable)
		chip->irq_disable = default_disable;
357
	/*
358 359
	 * We use chip->irq_disable, when the user provided its own. When
	 * we have default_disable set for chip->irq_disable, then we need
360 361 362
	 * to use default_shutdown, otherwise the irq line is not
	 * disabled on free_irq():
	 */
363 364 365
	if (!chip->irq_shutdown)
		chip->irq_shutdown = chip->irq_disable != default_disable ?
			chip->irq_disable : default_shutdown;
366 367

#ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
368 369
	if (!chip->end)
		chip->end = dummy_irq_chip.end;
370

371 372 373
	/*
	 * Now fix up the remaining compat handlers
	 */
374 375 376 377
	if (chip->bus_lock)
		chip->irq_bus_lock = compat_bus_lock;
	if (chip->bus_sync_unlock)
		chip->irq_bus_sync_unlock = compat_bus_sync_unlock;
378 379
	if (chip->mask)
		chip->irq_mask = compat_irq_mask;
380 381
	if (chip->unmask)
		chip->irq_unmask = compat_irq_unmask;
382 383
	if (chip->ack)
		chip->irq_ack = compat_irq_ack;
384 385
	if (chip->mask_ack)
		chip->irq_mask_ack = compat_irq_mask_ack;
386 387
	if (chip->eoi)
		chip->irq_eoi = compat_irq_eoi;
388 389
	if (chip->set_affinity)
		chip->irq_set_affinity = compat_irq_set_affinity;
390 391
	if (chip->set_type)
		chip->irq_set_type = compat_irq_set_type;
392 393
	if (chip->set_wake)
		chip->irq_set_wake = compat_irq_set_wake;
394 395
	if (chip->retrigger)
		chip->irq_retrigger = compat_irq_retrigger;
396
#endif
397 398
}

399
static inline void mask_ack_irq(struct irq_desc *desc)
400
{
401 402
	if (desc->irq_data.chip->irq_mask_ack)
		desc->irq_data.chip->irq_mask_ack(&desc->irq_data);
403
	else {
404
		desc->irq_data.chip->irq_mask(&desc->irq_data);
405 406
		if (desc->irq_data.chip->irq_ack)
			desc->irq_data.chip->irq_ack(&desc->irq_data);
407
	}
408 409 410
	desc->status |= IRQ_MASKED;
}

411
static inline void mask_irq(struct irq_desc *desc)
412
{
413 414
	if (desc->irq_data.chip->irq_mask) {
		desc->irq_data.chip->irq_mask(&desc->irq_data);
415 416 417 418
		desc->status |= IRQ_MASKED;
	}
}

419
static inline void unmask_irq(struct irq_desc *desc)
420
{
421 422
	if (desc->irq_data.chip->irq_unmask) {
		desc->irq_data.chip->irq_unmask(&desc->irq_data);
423 424
		desc->status &= ~IRQ_MASKED;
	}
425 426
}

427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
/*
 *	handle_nested_irq - Handle a nested irq from a irq thread
 *	@irq:	the interrupt number
 *
 *	Handle interrupts which are nested into a threaded interrupt
 *	handler. The handler function is called inside the calling
 *	threads context.
 */
void handle_nested_irq(unsigned int irq)
{
	struct irq_desc *desc = irq_to_desc(irq);
	struct irqaction *action;
	irqreturn_t action_ret;

	might_sleep();

443
	raw_spin_lock_irq(&desc->lock);
444 445 446 447 448 449 450 451

	kstat_incr_irqs_this_cpu(irq, desc);

	action = desc->action;
	if (unlikely(!action || (desc->status & IRQ_DISABLED)))
		goto out_unlock;

	desc->status |= IRQ_INPROGRESS;
452
	raw_spin_unlock_irq(&desc->lock);
453 454 455 456 457

	action_ret = action->thread_fn(action->irq, action->dev_id);
	if (!noirqdebug)
		note_interrupt(irq, desc, action_ret);

458
	raw_spin_lock_irq(&desc->lock);
459 460 461
	desc->status &= ~IRQ_INPROGRESS;

out_unlock:
462
	raw_spin_unlock_irq(&desc->lock);
463 464 465
}
EXPORT_SYMBOL_GPL(handle_nested_irq);

466 467 468 469 470 471 472
static bool irq_check_poll(struct irq_desc *desc)
{
	if (!(desc->status & IRQ_POLL_INPROGRESS))
		return false;
	return irq_wait_for_poll(desc);
}

473 474 475 476 477 478 479 480 481 482 483 484
/**
 *	handle_simple_irq - Simple and software-decoded IRQs.
 *	@irq:	the interrupt number
 *	@desc:	the interrupt description structure for this irq
 *
 *	Simple interrupts are either sent from a demultiplexing interrupt
 *	handler or come from hardware, where no interrupt hardware control
 *	is necessary.
 *
 *	Note: The caller is expected to handle the ack, clear, mask and
 *	unmask issues if necessary.
 */
485
void
486
handle_simple_irq(unsigned int irq, struct irq_desc *desc)
487 488 489 490
{
	struct irqaction *action;
	irqreturn_t action_ret;

491
	raw_spin_lock(&desc->lock);
492 493

	if (unlikely(desc->status & IRQ_INPROGRESS))
494 495 496
		if (!irq_check_poll(desc))
			goto out_unlock;

497
	desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
T
Thomas Gleixner 已提交
498
	kstat_incr_irqs_this_cpu(irq, desc);
499 500

	action = desc->action;
501
	if (unlikely(!action || (desc->status & IRQ_DISABLED)))
502 503 504
		goto out_unlock;

	desc->status |= IRQ_INPROGRESS;
505
	raw_spin_unlock(&desc->lock);
506

507
	action_ret = handle_IRQ_event(irq, action);
508
	if (!noirqdebug)
509
		note_interrupt(irq, desc, action_ret);
510

511
	raw_spin_lock(&desc->lock);
512 513
	desc->status &= ~IRQ_INPROGRESS;
out_unlock:
514
	raw_spin_unlock(&desc->lock);
515 516 517 518 519 520 521 522 523 524 525 526
}

/**
 *	handle_level_irq - Level type irq handler
 *	@irq:	the interrupt number
 *	@desc:	the interrupt description structure for this irq
 *
 *	Level type interrupts are active as long as the hardware line has
 *	the active level. This may require to mask the interrupt and unmask
 *	it after the associated handler has acknowledged the device, so the
 *	interrupt line is back to inactive.
 */
527
void
528
handle_level_irq(unsigned int irq, struct irq_desc *desc)
529 530 531 532
{
	struct irqaction *action;
	irqreturn_t action_ret;

533
	raw_spin_lock(&desc->lock);
534
	mask_ack_irq(desc);
535 536

	if (unlikely(desc->status & IRQ_INPROGRESS))
537 538 539
		if (!irq_check_poll(desc))
			goto out_unlock;

540
	desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
T
Thomas Gleixner 已提交
541
	kstat_incr_irqs_this_cpu(irq, desc);
542 543 544 545 546 547

	/*
	 * If its disabled or no action available
	 * keep it masked and get out of here
	 */
	action = desc->action;
548
	if (unlikely(!action || (desc->status & IRQ_DISABLED)))
549
		goto out_unlock;
550 551

	desc->status |= IRQ_INPROGRESS;
552
	raw_spin_unlock(&desc->lock);
553

554
	action_ret = handle_IRQ_event(irq, action);
555
	if (!noirqdebug)
556
		note_interrupt(irq, desc, action_ret);
557

558
	raw_spin_lock(&desc->lock);
559
	desc->status &= ~IRQ_INPROGRESS;
T
Thomas Gleixner 已提交
560

561
	if (!(desc->status & (IRQ_DISABLED | IRQ_ONESHOT)))
562
		unmask_irq(desc);
563
out_unlock:
564
	raw_spin_unlock(&desc->lock);
565
}
566
EXPORT_SYMBOL_GPL(handle_level_irq);
567 568

/**
569
 *	handle_fasteoi_irq - irq handler for transparent controllers
570 571 572
 *	@irq:	the interrupt number
 *	@desc:	the interrupt description structure for this irq
 *
573
 *	Only a single callback will be issued to the chip: an ->eoi()
574 575 576 577
 *	call when the interrupt has been serviced. This enables support
 *	for modern forms of interrupt handlers, which handle the flow
 *	details in hardware, transparently.
 */
578
void
579
handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
580 581 582 583
{
	struct irqaction *action;
	irqreturn_t action_ret;

584
	raw_spin_lock(&desc->lock);
585 586

	if (unlikely(desc->status & IRQ_INPROGRESS))
587 588
		if (!irq_check_poll(desc))
			goto out;
589 590

	desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
T
Thomas Gleixner 已提交
591
	kstat_incr_irqs_this_cpu(irq, desc);
592 593 594

	/*
	 * If its disabled or no action available
595
	 * then mask it and get out of here:
596 597
	 */
	action = desc->action;
598 599
	if (unlikely(!action || (desc->status & IRQ_DISABLED))) {
		desc->status |= IRQ_PENDING;
600
		mask_irq(desc);
601
		goto out;
602
	}
603 604

	desc->status |= IRQ_INPROGRESS;
605
	desc->status &= ~IRQ_PENDING;
606
	raw_spin_unlock(&desc->lock);
607

608
	action_ret = handle_IRQ_event(irq, action);
609
	if (!noirqdebug)
610
		note_interrupt(irq, desc, action_ret);
611

612
	raw_spin_lock(&desc->lock);
613 614
	desc->status &= ~IRQ_INPROGRESS;
out:
615
	desc->irq_data.chip->irq_eoi(&desc->irq_data);
616

617
	raw_spin_unlock(&desc->lock);
618 619 620 621 622 623 624 625 626 627 628
}

/**
 *	handle_edge_irq - edge type IRQ handler
 *	@irq:	the interrupt number
 *	@desc:	the interrupt description structure for this irq
 *
 *	Interrupt occures on the falling and/or rising edge of a hardware
 *	signal. The occurence is latched into the irq controller hardware
 *	and must be acked in order to be reenabled. After the ack another
 *	interrupt can happen on the same source even before the first one
629
 *	is handled by the associated event handler. If this happens it
630 631 632 633 634 635
 *	might be necessary to disable (mask) the interrupt depending on the
 *	controller hardware. This requires to reenable the interrupt inside
 *	of the loop which handles the interrupts which have arrived while
 *	the handler was running. If all pending interrupts are handled, the
 *	loop is left.
 */
636
void
637
handle_edge_irq(unsigned int irq, struct irq_desc *desc)
638
{
639
	raw_spin_lock(&desc->lock);
640 641 642 643 644 645 646 647 648 649

	desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);

	/*
	 * If we're currently running this IRQ, or its disabled,
	 * we shouldn't process the IRQ. Mark it pending, handle
	 * the necessary masking and go out
	 */
	if (unlikely((desc->status & (IRQ_INPROGRESS | IRQ_DISABLED)) ||
		    !desc->action)) {
650 651 652 653 654
		if (!irq_check_poll(desc)) {
			desc->status |= (IRQ_PENDING | IRQ_MASKED);
			mask_ack_irq(desc);
			goto out_unlock;
		}
655
	}
T
Thomas Gleixner 已提交
656
	kstat_incr_irqs_this_cpu(irq, desc);
657 658

	/* Start handling the irq */
659
	desc->irq_data.chip->irq_ack(&desc->irq_data);
660 661 662 663 664 665 666 667 668

	/* Mark the IRQ currently in progress.*/
	desc->status |= IRQ_INPROGRESS;

	do {
		struct irqaction *action = desc->action;
		irqreturn_t action_ret;

		if (unlikely(!action)) {
669
			mask_irq(desc);
670 671 672 673 674 675 676 677 678 679 680
			goto out_unlock;
		}

		/*
		 * When another irq arrived while we were handling
		 * one, we could have masked the irq.
		 * Renable it, if it was not disabled in meantime.
		 */
		if (unlikely((desc->status &
			       (IRQ_PENDING | IRQ_MASKED | IRQ_DISABLED)) ==
			      (IRQ_PENDING | IRQ_MASKED))) {
681
			unmask_irq(desc);
682 683 684
		}

		desc->status &= ~IRQ_PENDING;
685
		raw_spin_unlock(&desc->lock);
686
		action_ret = handle_IRQ_event(irq, action);
687
		if (!noirqdebug)
688
			note_interrupt(irq, desc, action_ret);
689
		raw_spin_lock(&desc->lock);
690 691 692 693 694

	} while ((desc->status & (IRQ_PENDING | IRQ_DISABLED)) == IRQ_PENDING);

	desc->status &= ~IRQ_INPROGRESS;
out_unlock:
695
	raw_spin_unlock(&desc->lock);
696 697 698
}

/**
L
Liuweni 已提交
699
 *	handle_percpu_irq - Per CPU local irq handler
700 701 702 703 704
 *	@irq:	the interrupt number
 *	@desc:	the interrupt description structure for this irq
 *
 *	Per CPU interrupts on SMP machines without locking requirements
 */
705
void
706
handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
707 708 709
{
	irqreturn_t action_ret;

T
Thomas Gleixner 已提交
710
	kstat_incr_irqs_this_cpu(irq, desc);
711

712 713
	if (desc->irq_data.chip->irq_ack)
		desc->irq_data.chip->irq_ack(&desc->irq_data);
714

715
	action_ret = handle_IRQ_event(irq, desc->action);
716
	if (!noirqdebug)
717
		note_interrupt(irq, desc, action_ret);
718

719 720
	if (desc->irq_data.chip->irq_eoi)
		desc->irq_data.chip->irq_eoi(&desc->irq_data);
721 722 723
}

void
724 725
__set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
		  const char *name)
726
{
727
	struct irq_desc *desc = irq_to_desc(irq);
728 729
	unsigned long flags;

730
	if (!desc) {
731 732 733 734 735 736 737
		printk(KERN_ERR
		       "Trying to install type control for IRQ%d\n", irq);
		return;
	}

	if (!handle)
		handle = handle_bad_irq;
738
	else if (desc->irq_data.chip == &no_irq_chip) {
739
		printk(KERN_WARNING "Trying to install %sinterrupt handler "
740
		       "for IRQ%d\n", is_chained ? "chained " : "", irq);
741 742 743 744 745 746 747
		/*
		 * Some ARM implementations install a handler for really dumb
		 * interrupt hardware without setting an irq_chip. This worked
		 * with the ARM no_irq_chip but the check in setup_irq would
		 * prevent us to setup the interrupt at all. Switch it to
		 * dummy_irq_chip for easy transition.
		 */
748
		desc->irq_data.chip = &dummy_irq_chip;
749
	}
750

751
	chip_bus_lock(desc);
752
	raw_spin_lock_irqsave(&desc->lock, flags);
753 754 755

	/* Uninstall? */
	if (handle == handle_bad_irq) {
756
		if (desc->irq_data.chip != &no_irq_chip)
757
			mask_ack_irq(desc);
758 759 760 761
		desc->status |= IRQ_DISABLED;
		desc->depth = 1;
	}
	desc->handle_irq = handle;
762
	desc->name = name;
763 764 765

	if (handle != handle_bad_irq && is_chained) {
		desc->status |= IRQ_NOREQUEST | IRQ_NOPROBE;
766
		irq_startup(desc);
767
	}
768
	raw_spin_unlock_irqrestore(&desc->lock, flags);
769
	chip_bus_sync_unlock(desc);
770
}
771
EXPORT_SYMBOL_GPL(__set_irq_handler);
772 773 774

void
set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
775
			 irq_flow_handler_t handle)
776 777
{
	set_irq_chip(irq, chip);
778
	__set_irq_handler(irq, handle, 0, NULL);
779 780
}

781 782 783
void
set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
			      irq_flow_handler_t handle, const char *name)
784
{
785 786
	set_irq_chip(irq, chip);
	__set_irq_handler(irq, handle, 0, name);
787
}
R
Ralf Baechle 已提交
788

T
Thomas Gleixner 已提交
789
void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set)
R
Ralf Baechle 已提交
790
{
791
	struct irq_desc *desc = irq_to_desc(irq);
R
Ralf Baechle 已提交
792 793
	unsigned long flags;

T
Thomas Gleixner 已提交
794
	if (!desc)
R
Ralf Baechle 已提交
795 796
		return;

T
Thomas Gleixner 已提交
797 798 799
	/* Sanitize flags */
	set &= IRQF_MODIFY_MASK;
	clr &= IRQF_MODIFY_MASK;
R
Ralf Baechle 已提交
800

801
	raw_spin_lock_irqsave(&desc->lock, flags);
T
Thomas Gleixner 已提交
802 803
	desc->status &= ~clr;
	desc->status |= set;
804
	raw_spin_unlock_irqrestore(&desc->lock, flags);
R
Ralf Baechle 已提交
805
}