14 #include <linux/module.h>
18 #include <linux/sched.h>
20 #include <asm/delay.h>
22 #include <linux/ipipe.h>
24 #include <asm/traps.h>
29 #include <asm/traps.h>
32 # define SIC_SYSIRQ(irq) (irq - (IRQ_CORETMR + 1))
34 # define SIC_SYSIRQ(irq) ((irq) - IVG15)
68 static struct ivg_slice {
79 static void __init search_IAR(
void)
81 unsigned ivg, irq_pos = 0;
82 for (ivg = 0; ivg <=
IVG13 -
IVG7; ivg++) {
85 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
91 #
if defined(CONFIG_BF51x) || defined(CONFIG_BF52x) || \
92 defined(CONFIG_BF538) || defined(CONFIG_BF539)
98 for (irqn = irqN; irqn < irqN + 4; ++irqn) {
99 int iar_shift = (irqn & 7) * 4;
100 if (ivg == (0xf & (iar >> iar_shift))) {
101 ivg_table[irq_pos].irqno = IVG7 + irqn;
102 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
103 ivg7_13[ivg].istop++;
120 static void bfin_core_mask_irq(
struct irq_data *
d)
123 if (!hard_irqs_disabled())
127 static void bfin_core_unmask_irq(
struct irq_data *d)
139 if (!hard_irqs_disabled())
153 # if defined(CONFIG_SMP) || defined(CONFIG_ICC)
165 static void bfin_internal_mask_irq_chip(
struct irq_data *d)
171 void bfin_internal_unmask_irq_affinity(
unsigned int irq,
204 static void bfin_sec_preflow_handler(
struct irq_data *d)
214 static void bfin_sec_mask_ack_irq(
struct irq_data *d)
224 static void bfin_sec_unmask_irq(
struct irq_data *d)
234 static void bfin_sec_enable_ssi(
unsigned int sid)
245 static void bfin_sec_disable_ssi(
unsigned int sid)
256 static void bfin_sec_set_ssi_coreid(
unsigned int sid,
unsigned int coreid)
267 static void bfin_sec_enable_sci(
unsigned int sid)
281 static void bfin_sec_disable_sci(
unsigned int sid)
292 static void bfin_sec_enable(
struct irq_data *d)
297 bfin_sec_enable_sci(sid);
298 bfin_sec_enable_ssi(sid);
303 static void bfin_sec_disable(
struct irq_data *d)
308 bfin_sec_disable_sci(sid);
309 bfin_sec_disable_ssi(sid);
340 static void init_software_driven_irq(
void)
342 bfin_sec_set_ssi_coreid(34, 0);
343 bfin_sec_set_ssi_coreid(35, 1);
344 bfin_sec_set_ssi_coreid(36, 0);
345 bfin_sec_set_ssi_coreid(37, 1);
348 void bfin_sec_resume(
void)
356 void handle_sec_sfi_fault(
uint32_t gstat)
361 void handle_sec_sci_fault(
uint32_t gstat)
380 void handle_sec_ssi_fault(
uint32_t gstat)
390 void handle_sec_fault(
unsigned int irq,
struct irq_desc *
desc)
401 handle_sec_sfi_fault(sec_gstat);
404 handle_sec_sci_fault(sec_gstat);
407 handle_sec_ssi_fault(sec_gstat);
417 void handle_core_fault(
unsigned int irq,
struct irq_desc *desc)
434 panic(
"Kernel core hardware error");
437 panic(
"NMI occurs unexpectedly");
440 panic(
"Core 1 fault occurs unexpectedly");
448 static void bfin_internal_unmask_irq_chip(
struct irq_data *d)
450 bfin_internal_unmask_irq_affinity(d->
irq, d->
affinity);
453 static int bfin_internal_set_affinity(
struct irq_data *d,
457 bfin_internal_unmask_irq_affinity(d->
irq, mask);
462 static void bfin_internal_unmask_irq_chip(
struct irq_data *d)
468 #if defined(CONFIG_PM) && !defined(SEC_GCTL)
471 u32 bank,
bit, wakeup = 0;
531 # define bfin_internal_set_wake_chip NULL
534 static struct irq_chip bfin_core_irqchip = {
536 .irq_mask = bfin_core_mask_irq,
537 .irq_unmask = bfin_core_unmask_irq,
540 static struct irq_chip bfin_internal_irqchip = {
542 .irq_mask = bfin_internal_mask_irq_chip,
543 .irq_unmask = bfin_internal_unmask_irq_chip,
544 .irq_disable = bfin_internal_mask_irq_chip,
545 .irq_enable = bfin_internal_unmask_irq_chip,
547 .irq_set_affinity = bfin_internal_set_affinity,
553 static struct irq_chip bfin_sec_irqchip = {
555 .irq_mask_ack = bfin_sec_mask_ack_irq,
556 .irq_mask = bfin_sec_mask_ack_irq,
557 .irq_unmask = bfin_sec_unmask_irq,
558 .irq_eoi = bfin_sec_unmask_irq,
559 .irq_disable = bfin_sec_disable,
560 .irq_enable = bfin_sec_enable,
568 ipipe_trace_irq_entry(irq);
570 ipipe_trace_irq_exit(irq);
576 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
577 static int mac_stat_int_mask;
579 static void bfin_mac_status_ack_irq(
unsigned int irq)
611 static void bfin_mac_status_mask_irq(
struct irq_data *d)
613 unsigned int irq = d->
irq;
625 if (!mac_stat_int_mask)
628 bfin_mac_status_ack_irq(irq);
631 static void bfin_mac_status_unmask_irq(
struct irq_data *d)
633 unsigned int irq = d->
irq;
644 if (!mac_stat_int_mask)
651 int bfin_mac_status_set_wake(
struct irq_data *d,
unsigned int state)
660 # define bfin_mac_status_set_wake NULL
663 static struct irq_chip bfin_mac_status_irqchip = {
665 .irq_mask = bfin_mac_status_mask_irq,
666 .irq_unmask = bfin_mac_status_unmask_irq,
667 .irq_set_wake = bfin_mac_status_set_wake,
677 if (status & (1L << i)) {
686 bfin_mac_status_ack_irq(irq);
688 " MASKED MAC ERROR INTERRUPT ASSERTED\n",
693 "%s : %s : LINE %d :\nIRQ ?: MAC ERROR"
694 " INTERRUPT ASSERTED BUT NO SOURCE FOUND"
695 "(EMAC_SYSTAT=0x%X)\n",
696 __func__, __FILE__, __LINE__, status);
705 __irq_set_handler_locked(irq, handle);
713 static void bfin_gpio_ack_irq(
struct irq_data *d)
721 static void bfin_gpio_mask_ack_irq(
struct irq_data *d)
723 unsigned int irq = d->
irq;
726 if (!irqd_is_level_type(d))
732 static void bfin_gpio_mask_irq(
struct irq_data *d)
737 static void bfin_gpio_unmask_irq(
struct irq_data *d)
742 static unsigned int bfin_gpio_irq_startup(
struct irq_data *d)
749 bfin_gpio_unmask_irq(d);
754 static void bfin_gpio_irq_shutdown(
struct irq_data *d)
758 bfin_gpio_mask_irq(d);
763 static int bfin_gpio_irq_type(
struct irq_data *d,
unsigned int type)
765 unsigned int irq = d->
irq;
780 snprintf(buf, 16,
"gpio-irq%d", irq);
831 # define bfin_gpio_set_wake NULL
834 static void bfin_demux_gpio_block(
unsigned int irq)
855 #if defined(BF537_FAMILY)
857 bfin_demux_gpio_block(
IRQ_PF0);
863 #elif defined(BF533_FAMILY)
867 #elif defined(BF538_FAMILY)
871 #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
881 #elif defined(CONFIG_BF561)
897 bfin_demux_gpio_block(irq);
902 #define NR_PINT_BITS 32
903 #define IRQ_NOT_AVAIL 0xFF
905 #define PINT_2_BANK(x) ((x) >> 5)
906 #define PINT_2_BIT(x) ((x) & 0x1F)
907 #define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
909 static unsigned char irq2pint_lut[
NR_PINTS];
923 inline unsigned int get_irq_base(
u32 bank,
u8 bmap)
925 unsigned int irq_base;
929 irq_base =
IRQ_PA0 + bmap * 16;
931 irq_base =
IRQ_PC0 + bmap * 16;
934 irq_base =
IRQ_PA0 + bank * 16 + bmap * 16;
940 void init_pint_lut(
void)
942 u16 bank,
bit, irq_base, bit_pos;
946 memset(irq2pint_lut, IRQ_NOT_AVAIL,
sizeof(irq2pint_lut));
950 pint_assign = pint[bank]->
assign;
952 for (bit = 0; bit < NR_PINT_BITS; bit++) {
954 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
956 irq_base = get_irq_base(bank, bmap);
958 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
959 bit_pos = bit + bank * NR_PINT_BITS;
961 pint2irq_lut[bit_pos] = irq_base -
SYS_IRQS;
962 irq2pint_lut[irq_base -
SYS_IRQS] = bit_pos;
967 static void bfin_gpio_ack_irq(
struct irq_data *d)
970 u32 pintbit = PINT_BIT(pint_val);
971 u32 bank = PINT_2_BANK(pint_val);
983 static void bfin_gpio_mask_ack_irq(
struct irq_data *d)
986 u32 pintbit = PINT_BIT(pint_val);
987 u32 bank = PINT_2_BANK(pint_val);
1000 static void bfin_gpio_mask_irq(
struct irq_data *d)
1004 pint[PINT_2_BANK(pint_val)]->
mask_clear = PINT_BIT(pint_val);
1007 static void bfin_gpio_unmask_irq(
struct irq_data *d)
1010 u32 pintbit = PINT_BIT(pint_val);
1011 u32 bank = PINT_2_BANK(pint_val);
1016 static unsigned int bfin_gpio_irq_startup(
struct irq_data *d)
1018 unsigned int irq = d->
irq;
1022 if (pint_val == IRQ_NOT_AVAIL) {
1024 "GPIO IRQ %d :Not in PINT Assign table "
1025 "Reconfigure Interrupt to Port Assignemt\n", irq);
1032 bfin_gpio_unmask_irq(d);
1037 static void bfin_gpio_irq_shutdown(
struct irq_data *d)
1041 bfin_gpio_mask_irq(d);
1046 static int bfin_gpio_irq_type(
struct irq_data *d,
unsigned int type)
1048 unsigned int irq = d->
irq;
1053 u32 pintbit = PINT_BIT(pint_val);
1054 u32 bank = PINT_2_BANK(pint_val);
1056 if (pint_val == IRQ_NOT_AVAIL)
1061 if (
test_bit(gpionr, gpio_enabled))
1069 snprintf(buf, 16,
"gpio-irq%d", irq);
1114 u32 bank = PINT_2_BANK(pint_val);
1146 void bfin_pint_suspend(
void)
1151 save_pint_reg[bank].mask_set = pint[bank]->
mask_set;
1152 save_pint_reg[bank].assign = pint[bank]->
assign;
1153 save_pint_reg[bank].edge_set = pint[bank]->
edge_set;
1154 save_pint_reg[bank].invert_set = pint[bank]->
invert_set;
1158 void bfin_pint_resume(
void)
1163 pint[bank]->
mask_set = save_pint_reg[bank].mask_set;
1164 pint[bank]->
assign = save_pint_reg[bank].assign;
1165 pint[bank]->
edge_set = save_pint_reg[bank].edge_set;
1166 pint[bank]->
invert_set = save_pint_reg[bank].invert_set;
1171 static int sec_suspend(
void)
1180 static void sec_resume(
void)
1195 .resume = sec_resume,
1199 # define bfin_gpio_set_wake NULL
1244 pint_val = bank * NR_PINT_BITS;
1246 request = pint[bank]->
request;
1252 irq = pint2irq_lut[pint_val] +
SYS_IRQS;
1253 if (level_mask & PINT_BIT(pint_val)) {
1268 static struct irq_chip bfin_gpio_irqchip = {
1270 .irq_ack = bfin_gpio_ack_irq,
1271 .irq_mask = bfin_gpio_mask_irq,
1272 .irq_mask_ack = bfin_gpio_mask_ack_irq,
1273 .irq_unmask = bfin_gpio_unmask_irq,
1274 .irq_disable = bfin_gpio_mask_irq,
1275 .irq_enable = bfin_gpio_unmask_irq,
1276 .irq_set_type = bfin_gpio_irq_type,
1277 .irq_startup = bfin_gpio_irq_startup,
1278 .irq_shutdown = bfin_gpio_irq_shutdown,
1313 unsigned long ilat = 0;
1322 # if defined(CONFIG_SMP) || defined(CONFIG_ICC)
1333 # ifdef CONFIG_PINTx_REASSIGN
1334 pint[0]->
assign = CONFIG_PINT0_ASSIGN;
1335 pint[1]->
assign = CONFIG_PINT1_ASSIGN;
1336 pint[2]->
assign = CONFIG_PINT2_ASSIGN;
1337 pint[3]->
assign = CONFIG_PINT3_ASSIGN;
1343 for (irq = 0; irq <=
SYS_IRQS; irq++) {
1355 #elif defined(BF537_FAMILY)
1358 #elif defined(BF533_FAMILY)
1360 #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
1364 #elif defined(CONFIG_BF561)
1368 #elif defined(BF538_FAMILY)
1373 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1375 irq_set_chained_handler(irq,
1379 #if defined(CONFIG_SMP) || defined(CONFIG_ICC)
1386 #ifdef CONFIG_TICKSOURCE_CORETMR
1396 #ifdef CONFIG_TICKSOURCE_GPTMR0
1414 #if (defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
1416 irq_set_chip_and_handler(irq, &bfin_mac_status_irqchip,
1422 irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
1431 printk(
KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
1470 #ifdef CONFIG_DO_IRQ_L1
1473 static int vec_to_irq(
int vec)
1475 struct ivgx *ivg = ivg7_13[vec -
IVG7].ifirst;
1476 struct ivgx *ivg_stop = ivg7_13[vec -
IVG7].istop;
1477 unsigned long sic_status[3];
1499 if (ivg >= ivg_stop)
1502 if (sic_status[0] & ivg->isrflag)
1504 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1520 unsigned long ilat = 0;
1527 # ifdef CONFIG_PINTx_REASSIGN
1528 pint[0]->
assign = CONFIG_PINT0_ASSIGN;
1529 pint[1]->
assign = CONFIG_PINT1_ASSIGN;
1530 pint[2]->
assign = CONFIG_PINT2_ASSIGN;
1531 pint[3]->
assign = CONFIG_PINT3_ASSIGN;
1532 pint[4]->
assign = CONFIG_PINT4_ASSIGN;
1533 pint[5]->
assign = CONFIG_PINT5_ASSIGN;
1539 for (irq = 0; irq <=
SYS_IRQS; irq++) {
1542 #ifdef CONFIG_TICKSOURCE_CORETMR
1551 irq_set_chip_and_handler(irq, &bfin_internal_irqchip,
1554 irq_set_chip_and_handler(irq, &bfin_sec_irqchip,
1557 irq_set_chip_and_handler(irq, &bfin_sec_irqchip,
1566 irq_set_chip_and_handler(irq, &bfin_sec_irqchip,
1568 __irq_set_preflow_handler(irq, bfin_sec_preflow_handler);
1573 irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
1583 printk(
KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
1585 bfin_sec_set_priority(CONFIG_SEC_IRQ_PRIORITY_LEVELS, sec_int_priority);
1587 bfin_sec_set_priority(CONFIG_SEC_IRQ_PRIORITY_LEVELS, sec_int_priority);
1604 init_software_driven_irq();
1610 #ifdef CONFIG_DO_IRQ_L1
1613 static int vec_to_irq(
int vec)
1622 #ifdef CONFIG_DO_IRQ_L1
1627 int irq = vec_to_irq(vec);
1635 int __ipipe_get_irq_priority(
unsigned irq)
1647 struct ivgx *ivg = ivg_table + ient;
1648 if (ivg->irqno == irq) {
1649 for (prio = 0; prio <=
IVG13-
IVG7; prio++) {
1650 if (ivg7_13[prio].ifirst <= ivg &&
1651 ivg7_13[prio].istop > ivg)
1662 #ifdef CONFIG_DO_IRQ_L1
1667 struct ipipe_percpu_domain_data *
p = ipipe_root_cpudom_ptr();
1668 struct ipipe_domain *this_domain = __ipipe_current_domain;
1671 irq = vec_to_irq(vec);
1676 #if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
1682 if (this_domain != ipipe_root_domain)
1703 if (this_domain == ipipe_root_domain) {
1708 ipipe_trace_irq_entry(irq);
1710 ipipe_trace_irq_exit(irq);
1713 !ipipe_test_foreign_stack() &&
1714 (
current->ipipe_flags & PF_EVTRET) != 0) {
1726 current->ipipe_flags &= ~PF_EVTRET;
1727 __ipipe_dispatch_event(IPIPE_EVENT_RETURN, regs);
1730 if (this_domain == ipipe_root_domain) {
1731 set_thread_flag(TIF_IRQ_SYNC);
1734 return !
test_bit(IPIPE_STALL_FLAG, &p->status);