blob: ee67082188cf78094ea8c5e0a7847223c22eb6f6 [file] [log] [blame]
wdenk507bbe32004-04-18 21:13:41 +00001/*
Michal Simekcfc67112007-03-11 13:48:24 +01002 * (C) Copyright 2007 Michal Simek
wdenk507bbe32004-04-18 21:13:41 +00003 * (C) Copyright 2004 Atmark Techno, Inc.
4 *
Michal Simekcfc67112007-03-11 13:48:24 +01005 * Michal SIMEK <monstr@monstr.eu>
wdenk507bbe32004-04-18 21:13:41 +00006 * Yasushi SHOJI <yashi@atmark-techno.com>
7 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Michal Simekcfc67112007-03-11 13:48:24 +010018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenk507bbe32004-04-18 21:13:41 +000019 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
Michal Simekcfc67112007-03-11 13:48:24 +010027#include <common.h>
28#include <command.h>
Michal Simek575a3d22012-07-10 10:31:31 +020029#include <malloc.h>
Michal Simekcfc67112007-03-11 13:48:24 +010030#include <asm/microblaze_intc.h>
Michal Simek42efed62007-05-07 17:22:25 +020031#include <asm/asm.h>
Michal Simekcfc67112007-03-11 13:48:24 +010032
33#undef DEBUG_INT
34
35extern void microblaze_disable_interrupts (void);
36extern void microblaze_enable_interrupts (void);
37
38void enable_interrupts (void)
wdenk507bbe32004-04-18 21:13:41 +000039{
Michal Simekfb05f6d2007-05-07 23:58:31 +020040 MSRSET(0x2);
wdenk507bbe32004-04-18 21:13:41 +000041}
42
Michal Simekcfc67112007-03-11 13:48:24 +010043int disable_interrupts (void)
wdenk507bbe32004-04-18 21:13:41 +000044{
Michal Simek68e99e52010-12-21 08:30:39 +010045 unsigned int msr;
46
47 MFS(msr, rmsr);
Michal Simekfb05f6d2007-05-07 23:58:31 +020048 MSRCLR(0x2);
Michal Simek68e99e52010-12-21 08:30:39 +010049 return (msr & 0x2) != 0;
wdenk507bbe32004-04-18 21:13:41 +000050}
Michal Simekcfc67112007-03-11 13:48:24 +010051
Michal Simek575a3d22012-07-10 10:31:31 +020052static struct irq_action *vecs;
53static u32 irq_no;
Michal Simekcfc67112007-03-11 13:48:24 +010054
55/* mapping structure to interrupt controller */
Michal Simek575a3d22012-07-10 10:31:31 +020056microblaze_intc_t *intc;
Michal Simekcfc67112007-03-11 13:48:24 +010057
58/* default handler */
Michal Simek575a3d22012-07-10 10:31:31 +020059static void def_hdlr(void)
Michal Simekcfc67112007-03-11 13:48:24 +010060{
61 puts ("def_hdlr\n");
62}
63
Michal Simek575a3d22012-07-10 10:31:31 +020064static void enable_one_interrupt(int irq)
Michal Simekcfc67112007-03-11 13:48:24 +010065{
66 int mask;
67 int offset = 1;
68 offset <<= irq;
69 mask = intc->ier;
70 intc->ier = (mask | offset);
71#ifdef DEBUG_INT
72 printf ("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask,
73 intc->ier);
74 printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
75 intc->iar, intc->mer);
76#endif
77}
78
Michal Simek575a3d22012-07-10 10:31:31 +020079static void disable_one_interrupt(int irq)
Michal Simekcfc67112007-03-11 13:48:24 +010080{
81 int mask;
82 int offset = 1;
83 offset <<= irq;
84 mask = intc->ier;
85 intc->ier = (mask & ~offset);
86#ifdef DEBUG_INT
87 printf ("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask,
88 intc->ier);
89 printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
90 intc->iar, intc->mer);
91#endif
92}
93
94/* adding new handler for interrupt */
95void install_interrupt_handler (int irq, interrupt_handler_t * hdlr, void *arg)
96{
97 struct irq_action *act;
98 /* irq out of range */
Michal Simek575a3d22012-07-10 10:31:31 +020099 if ((irq < 0) || (irq > irq_no)) {
Michal Simekcfc67112007-03-11 13:48:24 +0100100 puts ("IRQ out of range\n");
101 return;
102 }
103 act = &vecs[irq];
104 if (hdlr) { /* enable */
105 act->handler = hdlr;
106 act->arg = arg;
107 act->count = 0;
108 enable_one_interrupt (irq);
109 } else { /* disable */
Michal Simekcfc67112007-03-11 13:48:24 +0100110 act->handler = (interrupt_handler_t *) def_hdlr;
111 act->arg = (void *)irq;
112 disable_one_interrupt (irq);
113 }
114}
115
116/* initialization interrupt controller - hardware */
Michal Simek575a3d22012-07-10 10:31:31 +0200117static void intc_init(void)
Michal Simekcfc67112007-03-11 13:48:24 +0100118{
119 intc->mer = 0;
120 intc->ier = 0;
121 intc->iar = 0xFFFFFFFF;
122 /* XIntc_Start - hw_interrupt enable and all interrupt enable */
123 intc->mer = 0x3;
124#ifdef DEBUG_INT
125 printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
126 intc->iar, intc->mer);
127#endif
128}
129
Michal Simek575a3d22012-07-10 10:31:31 +0200130int interrupts_init(void)
Michal Simekcfc67112007-03-11 13:48:24 +0100131{
132 int i;
Michal Simek575a3d22012-07-10 10:31:31 +0200133
134#if defined(CONFIG_SYS_INTC_0_ADDR) && defined(CONFIG_SYS_INTC_0_NUM)
135 intc = (microblaze_intc_t *) (CONFIG_SYS_INTC_0_ADDR);
136 irq_no = CONFIG_SYS_INTC_0_NUM;
137#endif
138 if (irq_no) {
139 vecs = calloc(1, sizeof(struct irq_action) * irq_no);
140 if (vecs == NULL) {
141 puts("Interrupt vector allocation failed\n");
142 return -1;
143 }
144
145 /* initialize irq list */
146 for (i = 0; i < irq_no; i++) {
147 vecs[i].handler = (interrupt_handler_t *) def_hdlr;
148 vecs[i].arg = (void *)i;
149 vecs[i].count = 0;
150 }
151 /* initialize intc controller */
152 intc_init();
153 enable_interrupts();
154 } else {
155 puts("Undefined interrupt controller\n");
Michal Simekcfc67112007-03-11 13:48:24 +0100156 }
Michal Simekcfc67112007-03-11 13:48:24 +0100157 return 0;
158}
159
160void interrupt_handler (void)
161{
Michal Simek8125c982010-04-16 11:51:59 +0200162 int irqs = intc->ivr; /* find active interrupt */
163 int mask = 1;
Michal Simekcfc67112007-03-11 13:48:24 +0100164#ifdef DEBUG_INT
Michal Simek42efed62007-05-07 17:22:25 +0200165 int value;
Michal Simekcfc67112007-03-11 13:48:24 +0100166 printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
167 intc->iar, intc->mer);
Michal Simek42efed62007-05-07 17:22:25 +0200168 R14(value);
Michal Simekcfc67112007-03-11 13:48:24 +0100169 printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
170#endif
Michal Simek8125c982010-04-16 11:51:59 +0200171 struct irq_action *act = vecs + irqs;
172
Michal Simekcfc67112007-03-11 13:48:24 +0100173#ifdef DEBUG_INT
Michal Simek8125c982010-04-16 11:51:59 +0200174 printf
175 ("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n",
176 act->handler, act->count, act->arg);
Michal Simekcfc67112007-03-11 13:48:24 +0100177#endif
Michal Simek8125c982010-04-16 11:51:59 +0200178 act->handler (act->arg);
179 act->count++;
Michal Simek42efed62007-05-07 17:22:25 +0200180
Stephan Linz0f883262012-02-22 19:12:43 +0100181 intc->iar = mask << irqs;
182
Michal Simek42efed62007-05-07 17:22:25 +0200183#ifdef DEBUG_INT
Michal Simekcfc67112007-03-11 13:48:24 +0100184 printf ("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr,
185 intc->ier, intc->iar, intc->mer);
Michal Simek42efed62007-05-07 17:22:25 +0200186 R14(value);
187 printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
Michal Simekcfc67112007-03-11 13:48:24 +0100188#endif
189}
Michal Simekcfc67112007-03-11 13:48:24 +0100190
Jon Loeliger44312832007-07-09 19:06:00 -0500191#if defined(CONFIG_CMD_IRQ)
Michal Simek575a3d22012-07-10 10:31:31 +0200192int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, const char *argv[])
Michal Simekcfc67112007-03-11 13:48:24 +0100193{
194 int i;
195 struct irq_action *act = vecs;
196
Michal Simek575a3d22012-07-10 10:31:31 +0200197 if (irq_no) {
198 puts("\nInterrupt-Information:\n\n"
199 "Nr Routine Arg Count\n"
200 "-----------------------------\n");
Michal Simekcfc67112007-03-11 13:48:24 +0100201
Michal Simek575a3d22012-07-10 10:31:31 +0200202 for (i = 0; i < irq_no; i++) {
203 if (act->handler != (interrupt_handler_t *) def_hdlr) {
204 printf("%02d %08x %08x %d\n", i,
205 (int)act->handler, (int)act->arg,
206 act->count);
207 }
208 act++;
Michal Simekcfc67112007-03-11 13:48:24 +0100209 }
Michal Simek575a3d22012-07-10 10:31:31 +0200210 puts("\n");
211 } else {
212 puts("Undefined interrupt controller\n");
Michal Simekcfc67112007-03-11 13:48:24 +0100213 }
Michal Simek575a3d22012-07-10 10:31:31 +0200214 return 0;
Michal Simekcfc67112007-03-11 13:48:24 +0100215}
Jon Loeliger44312832007-07-09 19:06:00 -0500216#endif