1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <common.h>
22#include <asm/types.h>
23#include <asm/ptrace.h>
24#include <asm/system.h>
25#include <asm/openrisc_exc.h>
26
27struct irq_action {
28 interrupt_handler_t *handler;
29 void *arg;
30 int count;
31};
32
33static struct irq_action handlers[32];
34
35void interrupt_handler(void)
36{
37 int irq;
38
39 while ((irq = ffs(mfspr(SPR_PICSR)))) {
40 if (handlers[--irq].handler) {
41 handlers[irq].handler(handlers[irq].arg);
42 handlers[irq].count++;
43 } else {
44
45 mtspr(SPR_PICMR, mfspr(SPR_PICMR) & ~(1 << irq));
46 printf("Unhandled interrupt: %d\n", irq);
47 }
48
49 mtspr(SPR_PICSR, mfspr(SPR_PICSR) & ~(1 << irq));
50 }
51}
52
53int interrupt_init(void)
54{
55
56 exception_install_handler(EXC_EXT_IRQ, interrupt_handler);
57
58 mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
59
60 return 0;
61}
62
63void enable_interrupts(void)
64{
65
66 mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
67
68 mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_TEE);
69}
70
71int disable_interrupts(void)
72{
73
74 mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_IEE);
75
76 mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_TEE);
77
78 return 0;
79}
80
81void irq_install_handler(int irq, interrupt_handler_t *handler, void *arg)
82{
83 if (irq < 0 || irq > 31)
84 return;
85
86 handlers[irq].handler = handler;
87 handlers[irq].arg = arg;
88}
89
90void irq_free_handler(int irq)
91{
92 if (irq < 0 || irq > 31)
93 return;
94
95 handlers[irq].handler = 0;
96 handlers[irq].arg = 0;
97}
98
99#if defined(CONFIG_CMD_IRQ)
100int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
101{
102 int i;
103
104 printf("\nInterrupt-Information:\n\n");
105 printf("Nr Routine Arg Count\n");
106 printf("-----------------------------\n");
107
108 for (i = 0; i < 32; i++) {
109 if (handlers[i].handler) {
110 printf("%02d %08lx %08lx %d\n",
111 i,
112 (ulong)handlers[i].handler,
113 (ulong)handlers[i].arg,
114 handlers[i].count);
115 }
116 }
117 printf("\n");
118
119 return 0;
120}
121#endif
122