2 * Shared interrupt handling code for IPR and INTC2 types of IRQs.
4 * Copyright (C) 2007, 2008 Magnus Damm
5 * Copyright (C) 2009 Paul Mundt
7 * Based on intc2.c and ipr.c
9 * Copyright (C) 1999 Niibe Yutaka & Takeshi Yaegashi
10 * Copyright (C) 2000 Kazumoto Kojima
11 * Copyright (C) 2001 David J. Mckay (david.mckay@st.com)
12 * Copyright (C) 2003 Takashi Kusuda <kusuda-takashi@hitachi-ul.co.jp>
13 * Copyright (C) 2005, 2006 Paul Mundt
15 * This file is subject to the terms and conditions of the GNU General Public
16 * License. See the file "COPYING" in the main directory of this archive
19 #include <linux/init.h>
20 #include <linux/irq.h>
21 #include <linux/module.h>
23 #include <linux/interrupt.h>
24 #include <linux/sh_intc.h>
25 #include <linux/sysdev.h>
26 #include <linux/list.h>
27 #include <linux/topology.h>
28 #include <linux/bitmap.h>
30 #define _INTC_MK(fn, mode, addr_e, addr_d, width, shift) \
31 ((shift) | ((width) << 5) | ((fn) << 9) | ((mode) << 13) | \
32 ((addr_e) << 16) | ((addr_d << 24)))
34 #define _INTC_SHIFT(h) (h & 0x1f)
35 #define _INTC_WIDTH(h) ((h >> 5) & 0xf)
36 #define _INTC_FN(h) ((h >> 9) & 0xf)
37 #define _INTC_MODE(h) ((h >> 13) & 0x7)
38 #define _INTC_ADDR_E(h) ((h >> 16) & 0xff)
39 #define _INTC_ADDR_D(h) ((h >> 24) & 0xff)
41 struct intc_handle_int
{
46 struct intc_desc_int
{
47 struct list_head list
;
48 struct sys_device sysdev
;
55 struct intc_handle_int
*prio
;
57 struct intc_handle_int
*sense
;
58 unsigned int nr_sense
;
62 static LIST_HEAD(intc_list
);
65 * The intc_irq_map provides a global map of bound IRQ vectors for a
66 * given platform. Allocation of IRQs are either static through the CPU
67 * vector map, or dynamic in the case of board mux vectors or MSI.
69 * As this is a central point for all IRQ controllers on the system,
70 * each of the available sources are mapped out here. This combined with
71 * sparseirq makes it quite trivial to keep the vector map tightly packed
72 * when dynamically creating IRQs, as well as tying in to otherwise
73 * unused irq_desc positions in the sparse array.
75 static DECLARE_BITMAP(intc_irq_map
, NR_IRQS
);
76 static DEFINE_SPINLOCK(vector_lock
);
79 #define IS_SMP(x) x.smp
80 #define INTC_REG(d, x, c) (d->reg[(x)] + ((d->smp[(x)] & 0xff) * c))
81 #define SMP_NR(d, x) ((d->smp[(x)] >> 8) ? (d->smp[(x)] >> 8) : 1)
84 #define INTC_REG(d, x, c) (d->reg[(x)])
85 #define SMP_NR(d, x) 1
88 static unsigned int intc_prio_level
[NR_IRQS
]; /* for now */
89 static unsigned long ack_handle
[NR_IRQS
];
91 static inline struct intc_desc_int
*get_intc_desc(unsigned int irq
)
93 struct irq_chip
*chip
= get_irq_chip(irq
);
94 return container_of(chip
, struct intc_desc_int
, chip
);
97 static inline unsigned int set_field(unsigned int value
,
98 unsigned int field_value
,
101 unsigned int width
= _INTC_WIDTH(handle
);
102 unsigned int shift
= _INTC_SHIFT(handle
);
104 value
&= ~(((1 << width
) - 1) << shift
);
105 value
|= field_value
<< shift
;
109 static void write_8(unsigned long addr
, unsigned long h
, unsigned long data
)
111 __raw_writeb(set_field(0, data
, h
), addr
);
112 (void)__raw_readb(addr
); /* Defeat write posting */
115 static void write_16(unsigned long addr
, unsigned long h
, unsigned long data
)
117 __raw_writew(set_field(0, data
, h
), addr
);
118 (void)__raw_readw(addr
); /* Defeat write posting */
121 static void write_32(unsigned long addr
, unsigned long h
, unsigned long data
)
123 __raw_writel(set_field(0, data
, h
), addr
);
124 (void)__raw_readl(addr
); /* Defeat write posting */
127 static void modify_8(unsigned long addr
, unsigned long h
, unsigned long data
)
130 local_irq_save(flags
);
131 __raw_writeb(set_field(__raw_readb(addr
), data
, h
), addr
);
132 (void)__raw_readb(addr
); /* Defeat write posting */
133 local_irq_restore(flags
);
136 static void modify_16(unsigned long addr
, unsigned long h
, unsigned long data
)
139 local_irq_save(flags
);
140 __raw_writew(set_field(__raw_readw(addr
), data
, h
), addr
);
141 (void)__raw_readw(addr
); /* Defeat write posting */
142 local_irq_restore(flags
);
145 static void modify_32(unsigned long addr
, unsigned long h
, unsigned long data
)
148 local_irq_save(flags
);
149 __raw_writel(set_field(__raw_readl(addr
), data
, h
), addr
);
150 (void)__raw_readl(addr
); /* Defeat write posting */
151 local_irq_restore(flags
);
154 enum { REG_FN_ERR
= 0, REG_FN_WRITE_BASE
= 1, REG_FN_MODIFY_BASE
= 5 };
156 static void (*intc_reg_fns
[])(unsigned long addr
,
158 unsigned long data
) = {
159 [REG_FN_WRITE_BASE
+ 0] = write_8
,
160 [REG_FN_WRITE_BASE
+ 1] = write_16
,
161 [REG_FN_WRITE_BASE
+ 3] = write_32
,
162 [REG_FN_MODIFY_BASE
+ 0] = modify_8
,
163 [REG_FN_MODIFY_BASE
+ 1] = modify_16
,
164 [REG_FN_MODIFY_BASE
+ 3] = modify_32
,
167 enum { MODE_ENABLE_REG
= 0, /* Bit(s) set -> interrupt enabled */
168 MODE_MASK_REG
, /* Bit(s) set -> interrupt disabled */
169 MODE_DUAL_REG
, /* Two registers, set bit to enable / disable */
170 MODE_PRIO_REG
, /* Priority value written to enable interrupt */
171 MODE_PCLR_REG
, /* Above plus all bits set to disable interrupt */
174 static void intc_mode_field(unsigned long addr
,
175 unsigned long handle
,
176 void (*fn
)(unsigned long,
181 fn(addr
, handle
, ((1 << _INTC_WIDTH(handle
)) - 1));
184 static void intc_mode_zero(unsigned long addr
,
185 unsigned long handle
,
186 void (*fn
)(unsigned long,
194 static void intc_mode_prio(unsigned long addr
,
195 unsigned long handle
,
196 void (*fn
)(unsigned long,
201 fn(addr
, handle
, intc_prio_level
[irq
]);
204 static void (*intc_enable_fns
[])(unsigned long addr
,
205 unsigned long handle
,
206 void (*fn
)(unsigned long,
209 unsigned int irq
) = {
210 [MODE_ENABLE_REG
] = intc_mode_field
,
211 [MODE_MASK_REG
] = intc_mode_zero
,
212 [MODE_DUAL_REG
] = intc_mode_field
,
213 [MODE_PRIO_REG
] = intc_mode_prio
,
214 [MODE_PCLR_REG
] = intc_mode_prio
,
217 static void (*intc_disable_fns
[])(unsigned long addr
,
218 unsigned long handle
,
219 void (*fn
)(unsigned long,
222 unsigned int irq
) = {
223 [MODE_ENABLE_REG
] = intc_mode_zero
,
224 [MODE_MASK_REG
] = intc_mode_field
,
225 [MODE_DUAL_REG
] = intc_mode_field
,
226 [MODE_PRIO_REG
] = intc_mode_zero
,
227 [MODE_PCLR_REG
] = intc_mode_field
,
230 static inline void _intc_enable(unsigned int irq
, unsigned long handle
)
232 struct intc_desc_int
*d
= get_intc_desc(irq
);
236 for (cpu
= 0; cpu
< SMP_NR(d
, _INTC_ADDR_E(handle
)); cpu
++) {
237 addr
= INTC_REG(d
, _INTC_ADDR_E(handle
), cpu
);
238 intc_enable_fns
[_INTC_MODE(handle
)](addr
, handle
, intc_reg_fns\
239 [_INTC_FN(handle
)], irq
);
243 static void intc_enable(unsigned int irq
)
245 _intc_enable(irq
, (unsigned long)get_irq_chip_data(irq
));
248 static void intc_disable(unsigned int irq
)
250 struct intc_desc_int
*d
= get_intc_desc(irq
);
251 unsigned long handle
= (unsigned long) get_irq_chip_data(irq
);
255 for (cpu
= 0; cpu
< SMP_NR(d
, _INTC_ADDR_D(handle
)); cpu
++) {
256 addr
= INTC_REG(d
, _INTC_ADDR_D(handle
), cpu
);
257 intc_disable_fns
[_INTC_MODE(handle
)](addr
, handle
,intc_reg_fns\
258 [_INTC_FN(handle
)], irq
);
262 static int intc_set_wake(unsigned int irq
, unsigned int on
)
264 return 0; /* allow wakeup, but setup hardware in intc_suspend() */
267 static void intc_mask_ack(unsigned int irq
)
269 struct intc_desc_int
*d
= get_intc_desc(irq
);
270 unsigned long handle
= ack_handle
[irq
];
275 /* read register and write zero only to the assocaited bit */
278 addr
= INTC_REG(d
, _INTC_ADDR_D(handle
), 0);
279 switch (_INTC_FN(handle
)) {
280 case REG_FN_MODIFY_BASE
+ 0: /* 8bit */
282 __raw_writeb(0xff ^ set_field(0, 1, handle
), addr
);
284 case REG_FN_MODIFY_BASE
+ 1: /* 16bit */
286 __raw_writew(0xffff ^ set_field(0, 1, handle
), addr
);
288 case REG_FN_MODIFY_BASE
+ 3: /* 32bit */
290 __raw_writel(0xffffffff ^ set_field(0, 1, handle
), addr
);
299 static struct intc_handle_int
*intc_find_irq(struct intc_handle_int
*hp
,
305 /* this doesn't scale well, but...
307 * this function should only be used for cerain uncommon
308 * operations such as intc_set_priority() and intc_set_sense()
309 * and in those rare cases performance doesn't matter that much.
310 * keeping the memory footprint low is more important.
312 * one rather simple way to speed this up and still keep the
313 * memory footprint down is to make sure the array is sorted
314 * and then perform a bisect to lookup the irq.
317 for (i
= 0; i
< nr_hp
; i
++) {
318 if ((hp
+ i
)->irq
!= irq
)
327 int intc_set_priority(unsigned int irq
, unsigned int prio
)
329 struct intc_desc_int
*d
= get_intc_desc(irq
);
330 struct intc_handle_int
*ihp
;
332 if (!intc_prio_level
[irq
] || prio
<= 1)
335 ihp
= intc_find_irq(d
->prio
, d
->nr_prio
, irq
);
337 if (prio
>= (1 << _INTC_WIDTH(ihp
->handle
)))
340 intc_prio_level
[irq
] = prio
;
343 * only set secondary masking method directly
344 * primary masking method is using intc_prio_level[irq]
345 * priority level will be set during next enable()
348 if (_INTC_FN(ihp
->handle
) != REG_FN_ERR
)
349 _intc_enable(irq
, ihp
->handle
);
354 #define VALID(x) (x | 0x80)
356 static unsigned char intc_irq_sense_table
[IRQ_TYPE_SENSE_MASK
+ 1] = {
357 [IRQ_TYPE_EDGE_FALLING
] = VALID(0),
358 [IRQ_TYPE_EDGE_RISING
] = VALID(1),
359 [IRQ_TYPE_LEVEL_LOW
] = VALID(2),
360 /* SH7706, SH7707 and SH7709 do not support high level triggered */
361 #if !defined(CONFIG_CPU_SUBTYPE_SH7706) && \
362 !defined(CONFIG_CPU_SUBTYPE_SH7707) && \
363 !defined(CONFIG_CPU_SUBTYPE_SH7709)
364 [IRQ_TYPE_LEVEL_HIGH
] = VALID(3),
368 static int intc_set_sense(unsigned int irq
, unsigned int type
)
370 struct intc_desc_int
*d
= get_intc_desc(irq
);
371 unsigned char value
= intc_irq_sense_table
[type
& IRQ_TYPE_SENSE_MASK
];
372 struct intc_handle_int
*ihp
;
378 ihp
= intc_find_irq(d
->sense
, d
->nr_sense
, irq
);
380 addr
= INTC_REG(d
, _INTC_ADDR_E(ihp
->handle
), 0);
381 intc_reg_fns
[_INTC_FN(ihp
->handle
)](addr
, ihp
->handle
, value
);
386 static unsigned int __init
intc_get_reg(struct intc_desc_int
*d
,
387 unsigned long address
)
391 for (k
= 0; k
< d
->nr_reg
; k
++) {
392 if (d
->reg
[k
] == address
)
400 static intc_enum __init
intc_grp_id(struct intc_desc
*desc
,
403 struct intc_group
*g
= desc
->groups
;
406 for (i
= 0; g
&& enum_id
&& i
< desc
->nr_groups
; i
++) {
407 g
= desc
->groups
+ i
;
409 for (j
= 0; g
->enum_ids
[j
]; j
++) {
410 if (g
->enum_ids
[j
] != enum_id
)
420 static unsigned int __init
intc_mask_data(struct intc_desc
*desc
,
421 struct intc_desc_int
*d
,
422 intc_enum enum_id
, int do_grps
)
424 struct intc_mask_reg
*mr
= desc
->mask_regs
;
425 unsigned int i
, j
, fn
, mode
;
426 unsigned long reg_e
, reg_d
;
428 for (i
= 0; mr
&& enum_id
&& i
< desc
->nr_mask_regs
; i
++) {
429 mr
= desc
->mask_regs
+ i
;
431 for (j
= 0; j
< ARRAY_SIZE(mr
->enum_ids
); j
++) {
432 if (mr
->enum_ids
[j
] != enum_id
)
435 if (mr
->set_reg
&& mr
->clr_reg
) {
436 fn
= REG_FN_WRITE_BASE
;
437 mode
= MODE_DUAL_REG
;
441 fn
= REG_FN_MODIFY_BASE
;
443 mode
= MODE_ENABLE_REG
;
447 mode
= MODE_MASK_REG
;
453 fn
+= (mr
->reg_width
>> 3) - 1;
454 return _INTC_MK(fn
, mode
,
455 intc_get_reg(d
, reg_e
),
456 intc_get_reg(d
, reg_d
),
458 (mr
->reg_width
- 1) - j
);
463 return intc_mask_data(desc
, d
, intc_grp_id(desc
, enum_id
), 0);
468 static unsigned int __init
intc_prio_data(struct intc_desc
*desc
,
469 struct intc_desc_int
*d
,
470 intc_enum enum_id
, int do_grps
)
472 struct intc_prio_reg
*pr
= desc
->prio_regs
;
473 unsigned int i
, j
, fn
, mode
, bit
;
474 unsigned long reg_e
, reg_d
;
476 for (i
= 0; pr
&& enum_id
&& i
< desc
->nr_prio_regs
; i
++) {
477 pr
= desc
->prio_regs
+ i
;
479 for (j
= 0; j
< ARRAY_SIZE(pr
->enum_ids
); j
++) {
480 if (pr
->enum_ids
[j
] != enum_id
)
483 if (pr
->set_reg
&& pr
->clr_reg
) {
484 fn
= REG_FN_WRITE_BASE
;
485 mode
= MODE_PCLR_REG
;
489 fn
= REG_FN_MODIFY_BASE
;
490 mode
= MODE_PRIO_REG
;
497 fn
+= (pr
->reg_width
>> 3) - 1;
499 BUG_ON((j
+ 1) * pr
->field_width
> pr
->reg_width
);
501 bit
= pr
->reg_width
- ((j
+ 1) * pr
->field_width
);
503 return _INTC_MK(fn
, mode
,
504 intc_get_reg(d
, reg_e
),
505 intc_get_reg(d
, reg_d
),
506 pr
->field_width
, bit
);
511 return intc_prio_data(desc
, d
, intc_grp_id(desc
, enum_id
), 0);
516 static unsigned int __init
intc_ack_data(struct intc_desc
*desc
,
517 struct intc_desc_int
*d
,
520 struct intc_mask_reg
*mr
= desc
->ack_regs
;
521 unsigned int i
, j
, fn
, mode
;
522 unsigned long reg_e
, reg_d
;
524 for (i
= 0; mr
&& enum_id
&& i
< desc
->nr_ack_regs
; i
++) {
525 mr
= desc
->ack_regs
+ i
;
527 for (j
= 0; j
< ARRAY_SIZE(mr
->enum_ids
); j
++) {
528 if (mr
->enum_ids
[j
] != enum_id
)
531 fn
= REG_FN_MODIFY_BASE
;
532 mode
= MODE_ENABLE_REG
;
536 fn
+= (mr
->reg_width
>> 3) - 1;
537 return _INTC_MK(fn
, mode
,
538 intc_get_reg(d
, reg_e
),
539 intc_get_reg(d
, reg_d
),
541 (mr
->reg_width
- 1) - j
);
548 static unsigned int __init
intc_sense_data(struct intc_desc
*desc
,
549 struct intc_desc_int
*d
,
552 struct intc_sense_reg
*sr
= desc
->sense_regs
;
553 unsigned int i
, j
, fn
, bit
;
555 for (i
= 0; sr
&& enum_id
&& i
< desc
->nr_sense_regs
; i
++) {
556 sr
= desc
->sense_regs
+ i
;
558 for (j
= 0; j
< ARRAY_SIZE(sr
->enum_ids
); j
++) {
559 if (sr
->enum_ids
[j
] != enum_id
)
562 fn
= REG_FN_MODIFY_BASE
;
563 fn
+= (sr
->reg_width
>> 3) - 1;
565 BUG_ON((j
+ 1) * sr
->field_width
> sr
->reg_width
);
567 bit
= sr
->reg_width
- ((j
+ 1) * sr
->field_width
);
569 return _INTC_MK(fn
, 0, intc_get_reg(d
, sr
->reg
),
570 0, sr
->field_width
, bit
);
577 static void __init
intc_register_irq(struct intc_desc
*desc
,
578 struct intc_desc_int
*d
,
582 struct intc_handle_int
*hp
;
583 unsigned int data
[2], primary
;
586 * Register the IRQ position with the global IRQ map
588 set_bit(irq
, intc_irq_map
);
590 /* Prefer single interrupt source bitmap over other combinations:
591 * 1. bitmap, single interrupt source
592 * 2. priority, single interrupt source
593 * 3. bitmap, multiple interrupt sources (groups)
594 * 4. priority, multiple interrupt sources (groups)
597 data
[0] = intc_mask_data(desc
, d
, enum_id
, 0);
598 data
[1] = intc_prio_data(desc
, d
, enum_id
, 0);
601 if (!data
[0] && data
[1])
604 if (!data
[0] && !data
[1])
605 pr_warning("intc: missing unique irq mask for "
606 "irq %d (vect 0x%04x)\n", irq
, irq2evt(irq
));
608 data
[0] = data
[0] ? data
[0] : intc_mask_data(desc
, d
, enum_id
, 1);
609 data
[1] = data
[1] ? data
[1] : intc_prio_data(desc
, d
, enum_id
, 1);
614 BUG_ON(!data
[primary
]); /* must have primary masking method */
616 disable_irq_nosync(irq
);
617 set_irq_chip_and_handler_name(irq
, &d
->chip
,
618 handle_level_irq
, "level");
619 set_irq_chip_data(irq
, (void *)data
[primary
]);
621 /* set priority level
622 * - this needs to be at least 2 for 5-bit priorities on 7780
624 intc_prio_level
[irq
] = 2;
626 /* enable secondary masking method if present */
628 _intc_enable(irq
, data
[!primary
]);
630 /* add irq to d->prio list if priority is available */
632 hp
= d
->prio
+ d
->nr_prio
;
634 hp
->handle
= data
[1];
638 * only secondary priority should access registers, so
639 * set _INTC_FN(h) = REG_FN_ERR for intc_set_priority()
642 hp
->handle
&= ~_INTC_MK(0x0f, 0, 0, 0, 0, 0);
643 hp
->handle
|= _INTC_MK(REG_FN_ERR
, 0, 0, 0, 0, 0);
648 /* add irq to d->sense list if sense is available */
649 data
[0] = intc_sense_data(desc
, d
, enum_id
);
651 (d
->sense
+ d
->nr_sense
)->irq
= irq
;
652 (d
->sense
+ d
->nr_sense
)->handle
= data
[0];
656 /* irq should be disabled by default */
660 ack_handle
[irq
] = intc_ack_data(desc
, d
, enum_id
);
663 static unsigned int __init
save_reg(struct intc_desc_int
*d
,
679 static void intc_redirect_irq(unsigned int irq
, struct irq_desc
*desc
)
681 generic_handle_irq((unsigned int)get_irq_data(irq
));
684 void __init
register_intc_controller(struct intc_desc
*desc
)
686 unsigned int i
, k
, smp
;
687 struct intc_desc_int
*d
;
689 d
= kzalloc(sizeof(*d
), GFP_NOWAIT
);
691 INIT_LIST_HEAD(&d
->list
);
692 list_add(&d
->list
, &intc_list
);
694 d
->nr_reg
= desc
->mask_regs
? desc
->nr_mask_regs
* 2 : 0;
695 d
->nr_reg
+= desc
->prio_regs
? desc
->nr_prio_regs
* 2 : 0;
696 d
->nr_reg
+= desc
->sense_regs
? desc
->nr_sense_regs
: 0;
697 d
->nr_reg
+= desc
->ack_regs
? desc
->nr_ack_regs
: 0;
699 d
->reg
= kzalloc(d
->nr_reg
* sizeof(*d
->reg
), GFP_NOWAIT
);
701 d
->smp
= kzalloc(d
->nr_reg
* sizeof(*d
->smp
), GFP_NOWAIT
);
705 if (desc
->mask_regs
) {
706 for (i
= 0; i
< desc
->nr_mask_regs
; i
++) {
707 smp
= IS_SMP(desc
->mask_regs
[i
]);
708 k
+= save_reg(d
, k
, desc
->mask_regs
[i
].set_reg
, smp
);
709 k
+= save_reg(d
, k
, desc
->mask_regs
[i
].clr_reg
, smp
);
713 if (desc
->prio_regs
) {
714 d
->prio
= kzalloc(desc
->nr_vectors
* sizeof(*d
->prio
), GFP_NOWAIT
);
716 for (i
= 0; i
< desc
->nr_prio_regs
; i
++) {
717 smp
= IS_SMP(desc
->prio_regs
[i
]);
718 k
+= save_reg(d
, k
, desc
->prio_regs
[i
].set_reg
, smp
);
719 k
+= save_reg(d
, k
, desc
->prio_regs
[i
].clr_reg
, smp
);
723 if (desc
->sense_regs
) {
724 d
->sense
= kzalloc(desc
->nr_vectors
* sizeof(*d
->sense
), GFP_NOWAIT
);
726 for (i
= 0; i
< desc
->nr_sense_regs
; i
++) {
727 k
+= save_reg(d
, k
, desc
->sense_regs
[i
].reg
, 0);
731 d
->chip
.name
= desc
->name
;
732 d
->chip
.mask
= intc_disable
;
733 d
->chip
.unmask
= intc_enable
;
734 d
->chip
.mask_ack
= intc_disable
;
735 d
->chip
.enable
= intc_enable
;
736 d
->chip
.disable
= intc_disable
;
737 d
->chip
.shutdown
= intc_disable
;
738 d
->chip
.set_type
= intc_set_sense
;
739 d
->chip
.set_wake
= intc_set_wake
;
741 if (desc
->ack_regs
) {
742 for (i
= 0; i
< desc
->nr_ack_regs
; i
++)
743 k
+= save_reg(d
, k
, desc
->ack_regs
[i
].set_reg
, 0);
745 d
->chip
.mask_ack
= intc_mask_ack
;
748 BUG_ON(k
> 256); /* _INTC_ADDR_E() and _INTC_ADDR_D() are 8 bits */
750 /* register the vectors one by one */
751 for (i
= 0; i
< desc
->nr_vectors
; i
++) {
752 struct intc_vect
*vect
= desc
->vectors
+ i
;
753 unsigned int irq
= evt2irq(vect
->vect
);
754 struct irq_desc
*irq_desc
;
759 irq_desc
= irq_to_desc_alloc_node(irq
, numa_node_id());
760 if (unlikely(!irq_desc
)) {
761 pr_info("can't get irq_desc for %d\n", irq
);
765 intc_register_irq(desc
, d
, vect
->enum_id
, irq
);
767 for (k
= i
+ 1; k
< desc
->nr_vectors
; k
++) {
768 struct intc_vect
*vect2
= desc
->vectors
+ k
;
769 unsigned int irq2
= evt2irq(vect2
->vect
);
771 if (vect
->enum_id
!= vect2
->enum_id
)
775 * In the case of multi-evt handling and sparse
776 * IRQ support, each vector still needs to have
777 * its own backing irq_desc.
779 irq_desc
= irq_to_desc_alloc_node(irq2
, numa_node_id());
780 if (unlikely(!irq_desc
)) {
781 pr_info("can't get irq_desc for %d\n", irq2
);
787 /* redirect this interrupts to the first one */
788 set_irq_chip_and_handler_name(irq2
, &d
->chip
,
789 intc_redirect_irq
, "redirect");
790 set_irq_data(irq2
, (void *)irq
);
795 static int intc_suspend(struct sys_device
*dev
, pm_message_t state
)
797 struct intc_desc_int
*d
;
798 struct irq_desc
*desc
;
801 /* get intc controller associated with this sysdev */
802 d
= container_of(dev
, struct intc_desc_int
, sysdev
);
804 switch (state
.event
) {
806 if (d
->state
.event
!= PM_EVENT_FREEZE
)
808 for_each_irq_desc(irq
, desc
) {
809 if (desc
->handle_irq
== intc_redirect_irq
)
811 if (desc
->chip
!= &d
->chip
)
813 if (desc
->status
& IRQ_DISABLED
)
819 case PM_EVENT_FREEZE
:
820 /* nothing has to be done */
822 case PM_EVENT_SUSPEND
:
823 /* enable wakeup irqs belonging to this intc controller */
824 for_each_irq_desc(irq
, desc
) {
825 if ((desc
->status
& IRQ_WAKEUP
) && (desc
->chip
== &d
->chip
))
835 static int intc_resume(struct sys_device
*dev
)
837 return intc_suspend(dev
, PMSG_ON
);
840 static struct sysdev_class intc_sysdev_class
= {
842 .suspend
= intc_suspend
,
843 .resume
= intc_resume
,
846 /* register this intc as sysdev to allow suspend/resume */
847 static int __init
register_intc_sysdevs(void)
849 struct intc_desc_int
*d
;
853 error
= sysdev_class_register(&intc_sysdev_class
);
855 list_for_each_entry(d
, &intc_list
, list
) {
857 d
->sysdev
.cls
= &intc_sysdev_class
;
858 error
= sysdev_register(&d
->sysdev
);
866 pr_warning("intc: sysdev registration error\n");
870 device_initcall(register_intc_sysdevs
);
873 * Dynamic IRQ allocation and deallocation
875 static unsigned int create_irq_on_node(unsigned int irq_want
, int node
)
877 unsigned int irq
= 0, new;
879 struct irq_desc
*desc
;
881 spin_lock_irqsave(&vector_lock
, flags
);
884 * First try the wanted IRQ, then scan.
886 if (test_and_set_bit(irq_want
, intc_irq_map
)) {
887 new = find_first_zero_bit(intc_irq_map
, nr_irqs
);
888 if (unlikely(new == nr_irqs
))
891 desc
= irq_to_desc_alloc_node(new, node
);
892 if (unlikely(!desc
)) {
893 pr_info("can't get irq_desc for %d\n", new);
897 desc
= move_irq_desc(desc
, node
);
898 __set_bit(new, intc_irq_map
);
903 spin_unlock_irqrestore(&vector_lock
, flags
);
906 dynamic_irq_init(irq
);
913 int nid
= cpu_to_node(smp_processor_id());
916 irq
= create_irq_on_node(NR_IRQS_LEGACY
, nid
);
923 void destroy_irq(unsigned int irq
)
927 dynamic_irq_cleanup(irq
);
929 spin_lock_irqsave(&vector_lock
, flags
);
930 __clear_bit(irq
, intc_irq_map
);
931 spin_unlock_irqrestore(&vector_lock
, flags
);
934 int reserve_irq_vector(unsigned int irq
)
939 spin_lock_irqsave(&vector_lock
, flags
);
940 if (test_and_set_bit(irq
, intc_irq_map
))
942 spin_unlock_irqrestore(&vector_lock
, flags
);
947 void reserve_irq_legacy(void)
952 spin_lock_irqsave(&vector_lock
, flags
);
953 j
= find_first_bit(intc_irq_map
, nr_irqs
);
954 for (i
= 0; i
< j
; i
++)
955 __set_bit(i
, intc_irq_map
);
956 spin_unlock_irqrestore(&vector_lock
, flags
);