2
* (C) Copyright 2011, Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
3
* (C) Copyright 2011, Julius Baxter <julius@opencores.org>
5
* SPDX-License-Identifier: GPL-2.0+
10
#include <asm/ptrace.h>
11
#include <asm/system.h>
12
#include <asm/openrisc_exc.h>
15
interrupt_handler_t *handler;
20
static struct irq_action handlers[32];
22
void interrupt_handler(void)
26
while ((irq = ffs(mfspr(SPR_PICSR)))) {
27
if (handlers[--irq].handler) {
28
handlers[irq].handler(handlers[irq].arg);
29
handlers[irq].count++;
31
/* disable the interrupt */
32
mtspr(SPR_PICMR, mfspr(SPR_PICMR) & ~(1 << irq));
33
printf("Unhandled interrupt: %d\n", irq);
35
/* clear the interrupt */
36
mtspr(SPR_PICSR, mfspr(SPR_PICSR) & ~(1 << irq));
40
int interrupt_init(void)
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);
50
void enable_interrupts(void)
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);
58
int disable_interrupts(void)
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);
68
void irq_install_handler(int irq, interrupt_handler_t *handler, void *arg)
70
if (irq < 0 || irq > 31)
73
handlers[irq].handler = handler;
74
handlers[irq].arg = arg;
77
void irq_free_handler(int irq)
79
if (irq < 0 || irq > 31)
82
handlers[irq].handler = 0;
83
handlers[irq].arg = 0;
86
#if defined(CONFIG_CMD_IRQ)
87
int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
91
printf("\nInterrupt-Information:\n\n");
92
printf("Nr Routine Arg Count\n");
93
printf("-----------------------------\n");
95
for (i = 0; i < 32; i++) {
96
if (handlers[i].handler) {
97
printf("%02d %08lx %08lx %d\n",
99
(ulong)handlers[i].handler,
100
(ulong)handlers[i].arg,