chip.c 18.0 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
{
	unsigned long flags;
29
	struct irq_desc *desc = irq_get_desc_lock(irq, &flags);
30

31
	if (!desc)
32 33 34 35 36 37
		return -EINVAL;

	if (!chip)
		chip = &no_irq_chip;

	irq_chip_set_defaults(chip);
38
	desc->irq_data.chip = chip;
39
	irq_put_desc_unlock(desc, flags);
40 41 42 43 44 45
	/*
	 * For !CONFIG_SPARSE_IRQ make the irq show up in
	 * allocated_irqs. For the CONFIG_SPARSE_IRQ case, it is
	 * already marked, and this call is harmless.
	 */
	irq_reserve_irq(irq);
46 47
	return 0;
}
T
Thomas Gleixner 已提交
48
EXPORT_SYMBOL(irq_set_chip);
49 50

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

61 62
	if (!desc)
		return -EINVAL;
63

64
	type &= IRQ_TYPE_SENSE_MASK;
65 66 67
	if (type != IRQ_TYPE_NONE)
		ret = __irq_set_trigger(desc, irq, type);
	irq_put_desc_busunlock(desc, flags);
68 69
	return ret;
}
T
Thomas Gleixner 已提交
70
EXPORT_SYMBOL(irq_set_irq_type);
71 72

/**
T
Thomas Gleixner 已提交
73
 *	irq_set_handler_data - set irq handler data for an irq
74 75 76 77 78
 *	@irq:	Interrupt number
 *	@data:	Pointer to interrupt specific data
 *
 *	Set the hardware irq controller data for an irq
 */
T
Thomas Gleixner 已提交
79
int irq_set_handler_data(unsigned int irq, void *data)
80 81
{
	unsigned long flags;
82
	struct irq_desc *desc = irq_get_desc_lock(irq, &flags);
83

84
	if (!desc)
85
		return -EINVAL;
86
	desc->irq_data.handler_data = data;
87
	irq_put_desc_unlock(desc, flags);
88 89
	return 0;
}
T
Thomas Gleixner 已提交
90
EXPORT_SYMBOL(irq_set_handler_data);
91

92
/**
T
Thomas Gleixner 已提交
93
 *	irq_set_msi_desc - set MSI descriptor data for an irq
94
 *	@irq:	Interrupt number
R
Randy Dunlap 已提交
95
 *	@entry:	Pointer to MSI descriptor data
96
 *
L
Liuweni 已提交
97
 *	Set the MSI descriptor entry for an irq
98
 */
T
Thomas Gleixner 已提交
99
int irq_set_msi_desc(unsigned int irq, struct msi_desc *entry)
100 101
{
	unsigned long flags;
102
	struct irq_desc *desc = irq_get_desc_lock(irq, &flags);
103

104
	if (!desc)
105
		return -EINVAL;
106
	desc->irq_data.msi_desc = entry;
107 108
	if (entry)
		entry->irq = irq;
109
	irq_put_desc_unlock(desc, flags);
110 111 112
	return 0;
}

113
/**
T
Thomas Gleixner 已提交
114
 *	irq_set_chip_data - set irq chip data for an irq
115 116 117 118 119
 *	@irq:	Interrupt number
 *	@data:	Pointer to chip specific data
 *
 *	Set the hardware irq chip data for an irq
 */
T
Thomas Gleixner 已提交
120
int irq_set_chip_data(unsigned int irq, void *data)
121 122
{
	unsigned long flags;
123
	struct irq_desc *desc = irq_get_desc_lock(irq, &flags);
124

125
	if (!desc)
126
		return -EINVAL;
127
	desc->irq_data.chip_data = data;
128
	irq_put_desc_unlock(desc, flags);
129 130
	return 0;
}
T
Thomas Gleixner 已提交
131
EXPORT_SYMBOL(irq_set_chip_data);
132

133 134 135 136 137 138 139 140
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);

141 142 143
static void irq_state_clr_disabled(struct irq_desc *desc)
{
	desc->istate &= ~IRQS_DISABLED;
144
	irqd_clear(&desc->irq_data, IRQD_IRQ_DISABLED);
145 146 147 148 149 150
	irq_compat_clr_disabled(desc);
}

static void irq_state_set_disabled(struct irq_desc *desc)
{
	desc->istate |= IRQS_DISABLED;
151
	irqd_set(&desc->irq_data, IRQD_IRQ_DISABLED);
152 153 154
	irq_compat_set_disabled(desc);
}

155 156 157 158 159 160 161 162 163 164 165 166
static void irq_state_clr_masked(struct irq_desc *desc)
{
	desc->istate &= ~IRQS_MASKED;
	irq_compat_clr_masked(desc);
}

static void irq_state_set_masked(struct irq_desc *desc)
{
	desc->istate |= IRQS_MASKED;
	irq_compat_set_masked(desc);
}

167 168
int irq_startup(struct irq_desc *desc)
{
169
	irq_state_clr_disabled(desc);
170 171
	desc->depth = 0;

172 173
	if (desc->irq_data.chip->irq_startup) {
		int ret = desc->irq_data.chip->irq_startup(&desc->irq_data);
174
		irq_state_clr_masked(desc);
175 176
		return ret;
	}
177

178
	irq_enable(desc);
179 180 181 182 183
	return 0;
}

void irq_shutdown(struct irq_desc *desc)
{
184
	irq_state_set_disabled(desc);
185
	desc->depth = 1;
T
Thomas Gleixner 已提交
186 187 188 189 190 191
	if (desc->irq_data.chip->irq_shutdown)
		desc->irq_data.chip->irq_shutdown(&desc->irq_data);
	if (desc->irq_data.chip->irq_disable)
		desc->irq_data.chip->irq_disable(&desc->irq_data);
	else
		desc->irq_data.chip->irq_mask(&desc->irq_data);
192
	irq_state_set_masked(desc);
193 194
}

195 196
void irq_enable(struct irq_desc *desc)
{
197
	irq_state_clr_disabled(desc);
T
Thomas Gleixner 已提交
198 199 200 201
	if (desc->irq_data.chip->irq_enable)
		desc->irq_data.chip->irq_enable(&desc->irq_data);
	else
		desc->irq_data.chip->irq_unmask(&desc->irq_data);
202
	irq_state_clr_masked(desc);
203 204
}

T
Thomas Gleixner 已提交
205
void irq_disable(struct irq_desc *desc)
206
{
207
	irq_state_set_disabled(desc);
T
Thomas Gleixner 已提交
208 209
	if (desc->irq_data.chip->irq_disable) {
		desc->irq_data.chip->irq_disable(&desc->irq_data);
210
		irq_state_set_masked(desc);
T
Thomas Gleixner 已提交
211
	}
212 213
}

214
#ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
215
/* Temporary migration helpers */
216 217 218 219 220
static void compat_irq_mask(struct irq_data *data)
{
	data->chip->mask(data->irq);
}

221 222 223 224 225
static void compat_irq_unmask(struct irq_data *data)
{
	data->chip->unmask(data->irq);
}

226 227 228 229 230
static void compat_irq_ack(struct irq_data *data)
{
	data->chip->ack(data->irq);
}

231 232 233 234 235
static void compat_irq_mask_ack(struct irq_data *data)
{
	data->chip->mask_ack(data->irq);
}

236 237 238 239 240
static void compat_irq_eoi(struct irq_data *data)
{
	data->chip->eoi(data->irq);
}

241 242 243 244 245
static void compat_irq_enable(struct irq_data *data)
{
	data->chip->enable(data->irq);
}

246 247 248 249 250 251 252 253 254 255
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);
}

256 257 258 259 260
static unsigned int compat_irq_startup(struct irq_data *data)
{
	return data->chip->startup(data->irq);
}

261 262 263 264 265 266
static int compat_irq_set_affinity(struct irq_data *data,
				   const struct cpumask *dest, bool force)
{
	return data->chip->set_affinity(data->irq, dest);
}

267 268 269 270 271
static int compat_irq_set_type(struct irq_data *data, unsigned int type)
{
	return data->chip->set_type(data->irq, type);
}

272 273 274 275 276
static int compat_irq_set_wake(struct irq_data *data, unsigned int on)
{
	return data->chip->set_wake(data->irq, on);
}

277 278 279 280 281
static int compat_irq_retrigger(struct irq_data *data)
{
	return data->chip->retrigger(data->irq);
}

282 283 284 285 286 287 288 289 290
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);
}
291
#endif
292

293 294 295 296 297
/*
 * Fixup enable/disable function pointers
 */
void irq_chip_set_defaults(struct irq_chip *chip)
{
298
#ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
299 300
	if (chip->enable)
		chip->irq_enable = compat_irq_enable;
301 302 303 304
	if (chip->disable)
		chip->irq_disable = compat_irq_disable;
	if (chip->shutdown)
		chip->irq_shutdown = compat_irq_shutdown;
305 306
	if (chip->startup)
		chip->irq_startup = compat_irq_startup;
307 308
	if (!chip->end)
		chip->end = dummy_irq_chip.end;
309 310 311 312
	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;
313 314
	if (chip->mask)
		chip->irq_mask = compat_irq_mask;
315 316
	if (chip->unmask)
		chip->irq_unmask = compat_irq_unmask;
317 318
	if (chip->ack)
		chip->irq_ack = compat_irq_ack;
319 320
	if (chip->mask_ack)
		chip->irq_mask_ack = compat_irq_mask_ack;
321 322
	if (chip->eoi)
		chip->irq_eoi = compat_irq_eoi;
323 324
	if (chip->set_affinity)
		chip->irq_set_affinity = compat_irq_set_affinity;
325 326
	if (chip->set_type)
		chip->irq_set_type = compat_irq_set_type;
327 328
	if (chip->set_wake)
		chip->irq_set_wake = compat_irq_set_wake;
329 330
	if (chip->retrigger)
		chip->irq_retrigger = compat_irq_retrigger;
331
#endif
332 333
}

334
static inline void mask_ack_irq(struct irq_desc *desc)
335
{
336 337
	if (desc->irq_data.chip->irq_mask_ack)
		desc->irq_data.chip->irq_mask_ack(&desc->irq_data);
338
	else {
339
		desc->irq_data.chip->irq_mask(&desc->irq_data);
340 341
		if (desc->irq_data.chip->irq_ack)
			desc->irq_data.chip->irq_ack(&desc->irq_data);
342
	}
343
	irq_state_set_masked(desc);
344 345
}

346
void mask_irq(struct irq_desc *desc)
347
{
348 349
	if (desc->irq_data.chip->irq_mask) {
		desc->irq_data.chip->irq_mask(&desc->irq_data);
350
		irq_state_set_masked(desc);
351 352 353
	}
}

354
void unmask_irq(struct irq_desc *desc)
355
{
356 357
	if (desc->irq_data.chip->irq_unmask) {
		desc->irq_data.chip->irq_unmask(&desc->irq_data);
358
		irq_state_clr_masked(desc);
359
	}
360 361
}

362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
/*
 *	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();

378
	raw_spin_lock_irq(&desc->lock);
379 380 381 382

	kstat_incr_irqs_this_cpu(irq, desc);

	action = desc->action;
383
	if (unlikely(!action || (desc->istate & IRQS_DISABLED)))
384 385
		goto out_unlock;

386 387
	irq_compat_set_progress(desc);
	desc->istate |= IRQS_INPROGRESS;
388
	raw_spin_unlock_irq(&desc->lock);
389 390 391 392 393

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

394
	raw_spin_lock_irq(&desc->lock);
395 396
	desc->istate &= ~IRQS_INPROGRESS;
	irq_compat_clr_progress(desc);
397 398

out_unlock:
399
	raw_spin_unlock_irq(&desc->lock);
400 401 402
}
EXPORT_SYMBOL_GPL(handle_nested_irq);

403 404
static bool irq_check_poll(struct irq_desc *desc)
{
405
	if (!(desc->istate & IRQS_POLL_INPROGRESS))
406 407 408 409
		return false;
	return irq_wait_for_poll(desc);
}

410 411 412 413 414 415 416 417 418 419 420 421
/**
 *	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.
 */
422
void
423
handle_simple_irq(unsigned int irq, struct irq_desc *desc)
424
{
425
	raw_spin_lock(&desc->lock);
426

427
	if (unlikely(desc->istate & IRQS_INPROGRESS))
428 429 430
		if (!irq_check_poll(desc))
			goto out_unlock;

431
	desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
T
Thomas Gleixner 已提交
432
	kstat_incr_irqs_this_cpu(irq, desc);
433

434
	if (unlikely(!desc->action || (desc->istate & IRQS_DISABLED)))
435 436
		goto out_unlock;

437
	handle_irq_event(desc);
438 439

out_unlock:
440
	raw_spin_unlock(&desc->lock);
441 442 443 444 445 446 447 448 449 450 451 452
}

/**
 *	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.
 */
453
void
454
handle_level_irq(unsigned int irq, struct irq_desc *desc)
455
{
456
	raw_spin_lock(&desc->lock);
457
	mask_ack_irq(desc);
458

459
	if (unlikely(desc->istate & IRQS_INPROGRESS))
460 461 462
		if (!irq_check_poll(desc))
			goto out_unlock;

463
	desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
T
Thomas Gleixner 已提交
464
	kstat_incr_irqs_this_cpu(irq, desc);
465 466 467 468 469

	/*
	 * If its disabled or no action available
	 * keep it masked and get out of here
	 */
470
	if (unlikely(!desc->action || (desc->istate & IRQS_DISABLED)))
471
		goto out_unlock;
472

473
	handle_irq_event(desc);
T
Thomas Gleixner 已提交
474

475
	if (!(desc->istate & (IRQS_DISABLED | IRQS_ONESHOT)))
476
		unmask_irq(desc);
477
out_unlock:
478
	raw_spin_unlock(&desc->lock);
479
}
480
EXPORT_SYMBOL_GPL(handle_level_irq);
481

482 483 484 485 486 487 488 489 490 491
#ifdef CONFIG_IRQ_PREFLOW_FASTEOI
static inline void preflow_handler(struct irq_desc *desc)
{
	if (desc->preflow_handler)
		desc->preflow_handler(&desc->irq_data);
}
#else
static inline void preflow_handler(struct irq_desc *desc) { }
#endif

492
/**
493
 *	handle_fasteoi_irq - irq handler for transparent controllers
494 495 496
 *	@irq:	the interrupt number
 *	@desc:	the interrupt description structure for this irq
 *
497
 *	Only a single callback will be issued to the chip: an ->eoi()
498 499 500 501
 *	call when the interrupt has been serviced. This enables support
 *	for modern forms of interrupt handlers, which handle the flow
 *	details in hardware, transparently.
 */
502
void
503
handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
504
{
505
	raw_spin_lock(&desc->lock);
506

507
	if (unlikely(desc->istate & IRQS_INPROGRESS))
508 509
		if (!irq_check_poll(desc))
			goto out;
510

511
	desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
T
Thomas Gleixner 已提交
512
	kstat_incr_irqs_this_cpu(irq, desc);
513 514 515

	/*
	 * If its disabled or no action available
516
	 * then mask it and get out of here:
517
	 */
518
	if (unlikely(!desc->action || (desc->istate & IRQS_DISABLED))) {
519 520
		irq_compat_set_pending(desc);
		desc->istate |= IRQS_PENDING;
521
		mask_irq(desc);
522
		goto out;
523
	}
524 525 526 527

	if (desc->istate & IRQS_ONESHOT)
		mask_irq(desc);

528
	preflow_handler(desc);
529
	handle_irq_event(desc);
530 531

out_eoi:
532
	desc->irq_data.chip->irq_eoi(&desc->irq_data);
533
out_unlock:
534
	raw_spin_unlock(&desc->lock);
535 536 537 538 539
	return;
out:
	if (!(desc->irq_data.chip->flags & IRQCHIP_EOI_IF_HANDLED))
		goto out_eoi;
	goto out_unlock;
540 541 542 543 544 545 546 547 548 549 550
}

/**
 *	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
551
 *	is handled by the associated event handler. If this happens it
552 553 554 555 556 557
 *	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.
 */
558
void
559
handle_edge_irq(unsigned int irq, struct irq_desc *desc)
560
{
561
	raw_spin_lock(&desc->lock);
562

563
	desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
564 565 566 567 568
	/*
	 * 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
	 */
569 570
	if (unlikely((desc->istate & (IRQS_DISABLED | IRQS_INPROGRESS) ||
		      !desc->action))) {
571
		if (!irq_check_poll(desc)) {
572 573
			irq_compat_set_pending(desc);
			desc->istate |= IRQS_PENDING;
574 575 576
			mask_ack_irq(desc);
			goto out_unlock;
		}
577
	}
T
Thomas Gleixner 已提交
578
	kstat_incr_irqs_this_cpu(irq, desc);
579 580

	/* Start handling the irq */
581
	desc->irq_data.chip->irq_ack(&desc->irq_data);
582 583

	do {
584
		if (unlikely(!desc->action)) {
585
			mask_irq(desc);
586 587 588 589 590 591 592 593
			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.
		 */
594
		if (unlikely(desc->istate & IRQS_PENDING)) {
595
			if (!(desc->istate & IRQS_DISABLED) &&
596
			    (desc->istate & IRQS_MASKED))
597
				unmask_irq(desc);
598 599
		}

600
		handle_irq_event(desc);
601

602
	} while ((desc->istate & IRQS_PENDING) &&
603
		 !(desc->istate & IRQS_DISABLED));
604 605

out_unlock:
606
	raw_spin_unlock(&desc->lock);
607 608 609
}

/**
L
Liuweni 已提交
610
 *	handle_percpu_irq - Per CPU local irq handler
611 612 613 614 615
 *	@irq:	the interrupt number
 *	@desc:	the interrupt description structure for this irq
 *
 *	Per CPU interrupts on SMP machines without locking requirements
 */
616
void
617
handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
618
{
619
	struct irq_chip *chip = irq_desc_get_chip(desc);
620

T
Thomas Gleixner 已提交
621
	kstat_incr_irqs_this_cpu(irq, desc);
622

623 624
	if (chip->irq_ack)
		chip->irq_ack(&desc->irq_data);
625

626
	handle_irq_event_percpu(desc, desc->action);
627

628 629
	if (chip->irq_eoi)
		chip->irq_eoi(&desc->irq_data);
630 631 632
}

void
633
__irq_set_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
634
		  const char *name)
635 636
{
	unsigned long flags;
637
	struct irq_desc *desc = irq_get_desc_buslock(irq, &flags);
638

639
	if (!desc)
640 641
		return;

642
	if (!handle) {
643
		handle = handle_bad_irq;
644 645
	} else {
		if (WARN_ON(desc->irq_data.chip == &no_irq_chip))
646
			goto out;
647
	}
648 649 650

	/* Uninstall? */
	if (handle == handle_bad_irq) {
651
		if (desc->irq_data.chip != &no_irq_chip)
652
			mask_ack_irq(desc);
653
		irq_state_set_disabled(desc);
654 655 656
		desc->depth = 1;
	}
	desc->handle_irq = handle;
657
	desc->name = name;
658 659

	if (handle != handle_bad_irq && is_chained) {
660 661
		irq_settings_set_noprobe(desc);
		irq_settings_set_norequest(desc);
662
		irq_startup(desc);
663
	}
664 665
out:
	irq_put_desc_busunlock(desc, flags);
666
}
667
EXPORT_SYMBOL_GPL(__irq_set_handler);
668 669

void
670
irq_set_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
671
			      irq_flow_handler_t handle, const char *name)
672
{
673
	irq_set_chip(irq, chip);
674
	__irq_set_handler(irq, handle, 0, name);
675
}
R
Ralf Baechle 已提交
676

T
Thomas Gleixner 已提交
677
void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set)
R
Ralf Baechle 已提交
678 679
{
	unsigned long flags;
680
	struct irq_desc *desc = irq_get_desc_lock(irq, &flags);
R
Ralf Baechle 已提交
681

T
Thomas Gleixner 已提交
682
	if (!desc)
R
Ralf Baechle 已提交
683
		return;
684 685
	irq_settings_clr_and_set(desc, clr, set);

686
	irqd_clear(&desc->irq_data, IRQD_NO_BALANCING | IRQD_PER_CPU |
687
		   IRQD_TRIGGER_MASK | IRQD_LEVEL | IRQD_MOVE_PCNTXT);
688 689 690 691
	if (irq_settings_has_no_balance_set(desc))
		irqd_set(&desc->irq_data, IRQD_NO_BALANCING);
	if (irq_settings_is_per_cpu(desc))
		irqd_set(&desc->irq_data, IRQD_PER_CPU);
692 693
	if (irq_settings_can_move_pcntxt(desc))
		irqd_set(&desc->irq_data, IRQD_MOVE_PCNTXT);
694

695 696
	irqd_set(&desc->irq_data, irq_settings_get_trigger_mask(desc));

697
	irq_put_desc_unlock(desc, flags);
R
Ralf Baechle 已提交
698
}
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720

/**
 *	irq_cpu_online - Invoke all irq_cpu_online functions.
 *
 *	Iterate through all irqs and invoke the chip.irq_cpu_online()
 *	for each.
 */
void irq_cpu_online(void)
{
	struct irq_desc *desc;
	struct irq_chip *chip;
	unsigned long flags;
	unsigned int irq;

	for_each_active_irq(irq) {
		desc = irq_to_desc(irq);
		if (!desc)
			continue;

		raw_spin_lock_irqsave(&desc->lock, flags);

		chip = irq_data_get_irq_chip(&desc->irq_data);
721 722 723
		if (chip && chip->irq_cpu_online &&
		    (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) ||
		     !(desc->istate & IRQS_DISABLED)))
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
			chip->irq_cpu_online(&desc->irq_data);

		raw_spin_unlock_irqrestore(&desc->lock, flags);
	}
}

/**
 *	irq_cpu_offline - Invoke all irq_cpu_offline functions.
 *
 *	Iterate through all irqs and invoke the chip.irq_cpu_offline()
 *	for each.
 */
void irq_cpu_offline(void)
{
	struct irq_desc *desc;
	struct irq_chip *chip;
	unsigned long flags;
	unsigned int irq;

	for_each_active_irq(irq) {
		desc = irq_to_desc(irq);
		if (!desc)
			continue;

		raw_spin_lock_irqsave(&desc->lock, flags);

		chip = irq_data_get_irq_chip(&desc->irq_data);
751 752 753
		if (chip && chip->irq_cpu_offline &&
		    (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) ||
		     !(desc->istate & IRQS_DISABLED)))
754 755 756 757 758
			chip->irq_cpu_offline(&desc->irq_data);

		raw_spin_unlock_irqrestore(&desc->lock, flags);
	}
}