blob: 1ecfbf03ac0891678a7ca17b315efd6d17005441 [file] [log] [blame]
Stefan Kristiansson952db942011-11-26 19:04:51 +00001/*
2 * (C) Copyright 2011, Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
3 * (C) Copyright 2011, Julius Baxter <julius@opencores.org>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Stefan Kristiansson952db942011-11-26 19:04:51 +00006 */
7
8#include <common.h>
9#include <asm/types.h>
10#include <asm/ptrace.h>
11#include <asm/system.h>
12#include <asm/openrisc_exc.h>
13
14struct irq_action {
15 interrupt_handler_t *handler;
16 void *arg;
17 int count;
18};
19
20static struct irq_action handlers[32];
21
22void interrupt_handler(void)
23{
24 int irq;
25
26 while ((irq = ffs(mfspr(SPR_PICSR)))) {
27 if (handlers[--irq].handler) {
28 handlers[irq].handler(handlers[irq].arg);
29 handlers[irq].count++;
30 } else {
31 /* disable the interrupt */
32 mtspr(SPR_PICMR, mfspr(SPR_PICMR) & ~(1 << irq));
33 printf("Unhandled interrupt: %d\n", irq);
34 }
35 /* clear the interrupt */
36 mtspr(SPR_PICSR, mfspr(SPR_PICSR) & ~(1 << irq));
37 }
38}
39
40int interrupt_init(void)
41{
42 /* install handler for external interrupt exception */
43 exception_install_handler(EXC_EXT_IRQ, interrupt_handler);
44 /* Enable interrupts in supervisor register */
45 mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
46
47 return 0;
48}
49
50void enable_interrupts(void)
51{
52 /* Set interrupt enable bit in supervisor register */
53 mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
54 /* Enable timer exception */
55 mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_TEE);
56}
57
58int disable_interrupts(void)
59{
60 /* Clear interrupt enable bit in supervisor register */
61 mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_IEE);
62 /* Disable timer exception */
63 mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_TEE);
64
65 return 0;
66}
67
68void irq_install_handler(int irq, interrupt_handler_t *handler, void *arg)
69{
70 if (irq < 0 || irq > 31)
71 return;
72
73 handlers[irq].handler = handler;
74 handlers[irq].arg = arg;
75}
76
77void irq_free_handler(int irq)
78{
79 if (irq < 0 || irq > 31)
80 return;
81
82 handlers[irq].handler = 0;
83 handlers[irq].arg = 0;
84}
85
86#if defined(CONFIG_CMD_IRQ)
87int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
88{
89 int i;
90
91 printf("\nInterrupt-Information:\n\n");
92 printf("Nr Routine Arg Count\n");
93 printf("-----------------------------\n");
94
95 for (i = 0; i < 32; i++) {
96 if (handlers[i].handler) {
97 printf("%02d %08lx %08lx %d\n",
98 i,
99 (ulong)handlers[i].handler,
100 (ulong)handlers[i].arg,
101 handlers[i].count);
102 }
103 }
104 printf("\n");
105
106 return 0;
107}
108#endif