2004-04-18 21:13:41 +00:00
|
|
|
/*
|
2007-03-11 12:48:24 +00:00
|
|
|
* (C) Copyright 2007 Michal Simek
|
2004-04-18 21:13:41 +00:00
|
|
|
* (C) Copyright 2004 Atmark Techno, Inc.
|
|
|
|
*
|
2007-03-11 12:48:24 +00:00
|
|
|
* Michal SIMEK <monstr@monstr.eu>
|
2004-04-18 21:13:41 +00:00
|
|
|
* Yasushi SHOJI <yashi@atmark-techno.com>
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-03-11 12:48:24 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2004-04-18 21:13:41 +00:00
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2007-03-11 12:48:24 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2012-07-10 08:31:31 +00:00
|
|
|
#include <malloc.h>
|
2007-03-11 12:48:24 +00:00
|
|
|
#include <asm/microblaze_intc.h>
|
2007-05-07 15:22:25 +00:00
|
|
|
#include <asm/asm.h>
|
2007-03-11 12:48:24 +00:00
|
|
|
|
|
|
|
#undef DEBUG_INT
|
|
|
|
|
2012-06-29 11:27:28 +00:00
|
|
|
void enable_interrupts(void)
|
2004-04-18 21:13:41 +00:00
|
|
|
{
|
2007-05-07 21:58:31 +00:00
|
|
|
MSRSET(0x2);
|
2004-04-18 21:13:41 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 11:27:28 +00:00
|
|
|
int disable_interrupts(void)
|
2004-04-18 21:13:41 +00:00
|
|
|
{
|
2010-12-21 07:30:39 +00:00
|
|
|
unsigned int msr;
|
|
|
|
|
|
|
|
MFS(msr, rmsr);
|
2007-05-07 21:58:31 +00:00
|
|
|
MSRCLR(0x2);
|
2010-12-21 07:30:39 +00:00
|
|
|
return (msr & 0x2) != 0;
|
2004-04-18 21:13:41 +00:00
|
|
|
}
|
2007-03-11 12:48:24 +00:00
|
|
|
|
2012-07-10 08:31:31 +00:00
|
|
|
static struct irq_action *vecs;
|
|
|
|
static u32 irq_no;
|
2007-03-11 12:48:24 +00:00
|
|
|
|
|
|
|
/* mapping structure to interrupt controller */
|
2012-07-10 08:31:31 +00:00
|
|
|
microblaze_intc_t *intc;
|
2007-03-11 12:48:24 +00:00
|
|
|
|
|
|
|
/* default handler */
|
2012-07-10 08:31:31 +00:00
|
|
|
static void def_hdlr(void)
|
2007-03-11 12:48:24 +00:00
|
|
|
{
|
2012-06-29 11:27:28 +00:00
|
|
|
puts("def_hdlr\n");
|
2007-03-11 12:48:24 +00:00
|
|
|
}
|
|
|
|
|
2012-07-10 08:31:31 +00:00
|
|
|
static void enable_one_interrupt(int irq)
|
2007-03-11 12:48:24 +00:00
|
|
|
{
|
|
|
|
int mask;
|
|
|
|
int offset = 1;
|
2012-06-29 11:27:28 +00:00
|
|
|
|
2007-03-11 12:48:24 +00:00
|
|
|
offset <<= irq;
|
|
|
|
mask = intc->ier;
|
|
|
|
intc->ier = (mask | offset);
|
|
|
|
#ifdef DEBUG_INT
|
2012-06-29 11:27:28 +00:00
|
|
|
printf("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask,
|
2007-03-11 12:48:24 +00:00
|
|
|
intc->ier);
|
2012-06-29 11:27:28 +00:00
|
|
|
printf("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
|
2007-03-11 12:48:24 +00:00
|
|
|
intc->iar, intc->mer);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-07-10 08:31:31 +00:00
|
|
|
static void disable_one_interrupt(int irq)
|
2007-03-11 12:48:24 +00:00
|
|
|
{
|
|
|
|
int mask;
|
|
|
|
int offset = 1;
|
2012-06-29 11:27:28 +00:00
|
|
|
|
2007-03-11 12:48:24 +00:00
|
|
|
offset <<= irq;
|
|
|
|
mask = intc->ier;
|
|
|
|
intc->ier = (mask & ~offset);
|
|
|
|
#ifdef DEBUG_INT
|
2012-06-29 11:27:28 +00:00
|
|
|
printf("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask,
|
2007-03-11 12:48:24 +00:00
|
|
|
intc->ier);
|
2012-06-29 11:27:28 +00:00
|
|
|
printf("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
|
2007-03-11 12:48:24 +00:00
|
|
|
intc->iar, intc->mer);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-06-29 12:21:52 +00:00
|
|
|
int install_interrupt_handler(int irq, interrupt_handler_t *hdlr, void *arg)
|
2007-03-11 12:48:24 +00:00
|
|
|
{
|
|
|
|
struct irq_action *act;
|
2012-06-29 11:27:28 +00:00
|
|
|
|
2007-03-11 12:48:24 +00:00
|
|
|
/* irq out of range */
|
2012-07-10 08:31:31 +00:00
|
|
|
if ((irq < 0) || (irq > irq_no)) {
|
2012-06-29 11:27:28 +00:00
|
|
|
puts("IRQ out of range\n");
|
2012-06-29 12:21:52 +00:00
|
|
|
return -1;
|
2007-03-11 12:48:24 +00:00
|
|
|
}
|
|
|
|
act = &vecs[irq];
|
|
|
|
if (hdlr) { /* enable */
|
|
|
|
act->handler = hdlr;
|
|
|
|
act->arg = arg;
|
|
|
|
act->count = 0;
|
|
|
|
enable_one_interrupt (irq);
|
2012-06-29 12:21:52 +00:00
|
|
|
return 0;
|
2007-03-11 12:48:24 +00:00
|
|
|
}
|
2012-06-29 12:21:52 +00:00
|
|
|
|
|
|
|
/* Disable */
|
|
|
|
act->handler = (interrupt_handler_t *) def_hdlr;
|
|
|
|
act->arg = (void *)irq;
|
|
|
|
disable_one_interrupt(irq);
|
|
|
|
return 1;
|
2007-03-11 12:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* initialization interrupt controller - hardware */
|
2012-07-10 08:31:31 +00:00
|
|
|
static void intc_init(void)
|
2007-03-11 12:48:24 +00:00
|
|
|
{
|
|
|
|
intc->mer = 0;
|
|
|
|
intc->ier = 0;
|
|
|
|
intc->iar = 0xFFFFFFFF;
|
|
|
|
/* XIntc_Start - hw_interrupt enable and all interrupt enable */
|
|
|
|
intc->mer = 0x3;
|
|
|
|
#ifdef DEBUG_INT
|
2012-06-29 11:27:28 +00:00
|
|
|
printf("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
|
2007-03-11 12:48:24 +00:00
|
|
|
intc->iar, intc->mer);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-07-10 08:31:31 +00:00
|
|
|
int interrupts_init(void)
|
2007-03-11 12:48:24 +00:00
|
|
|
{
|
|
|
|
int i;
|
2012-07-10 08:31:31 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_SYS_INTC_0_ADDR) && defined(CONFIG_SYS_INTC_0_NUM)
|
|
|
|
intc = (microblaze_intc_t *) (CONFIG_SYS_INTC_0_ADDR);
|
|
|
|
irq_no = CONFIG_SYS_INTC_0_NUM;
|
|
|
|
#endif
|
|
|
|
if (irq_no) {
|
|
|
|
vecs = calloc(1, sizeof(struct irq_action) * irq_no);
|
|
|
|
if (vecs == NULL) {
|
|
|
|
puts("Interrupt vector allocation failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize irq list */
|
|
|
|
for (i = 0; i < irq_no; i++) {
|
|
|
|
vecs[i].handler = (interrupt_handler_t *) def_hdlr;
|
|
|
|
vecs[i].arg = (void *)i;
|
|
|
|
vecs[i].count = 0;
|
|
|
|
}
|
|
|
|
/* initialize intc controller */
|
|
|
|
intc_init();
|
|
|
|
enable_interrupts();
|
|
|
|
} else {
|
|
|
|
puts("Undefined interrupt controller\n");
|
2007-03-11 12:48:24 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-29 11:27:28 +00:00
|
|
|
void interrupt_handler(void)
|
2007-03-11 12:48:24 +00:00
|
|
|
{
|
2010-04-16 09:51:59 +00:00
|
|
|
int irqs = intc->ivr; /* find active interrupt */
|
|
|
|
int mask = 1;
|
2007-03-11 12:48:24 +00:00
|
|
|
#ifdef DEBUG_INT
|
2007-05-07 15:22:25 +00:00
|
|
|
int value;
|
2007-03-11 12:48:24 +00:00
|
|
|
printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
|
|
|
|
intc->iar, intc->mer);
|
2007-05-07 15:22:25 +00:00
|
|
|
R14(value);
|
2007-03-11 12:48:24 +00:00
|
|
|
printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
|
|
|
|
#endif
|
2010-04-16 09:51:59 +00:00
|
|
|
struct irq_action *act = vecs + irqs;
|
|
|
|
|
2007-03-11 12:48:24 +00:00
|
|
|
#ifdef DEBUG_INT
|
2010-04-16 09:51:59 +00:00
|
|
|
printf
|
|
|
|
("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n",
|
|
|
|
act->handler, act->count, act->arg);
|
2007-03-11 12:48:24 +00:00
|
|
|
#endif
|
2010-04-16 09:51:59 +00:00
|
|
|
act->handler (act->arg);
|
|
|
|
act->count++;
|
2007-05-07 15:22:25 +00:00
|
|
|
|
2012-02-22 18:12:43 +00:00
|
|
|
intc->iar = mask << irqs;
|
|
|
|
|
2007-05-07 15:22:25 +00:00
|
|
|
#ifdef DEBUG_INT
|
2007-03-11 12:48:24 +00:00
|
|
|
printf ("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr,
|
|
|
|
intc->ier, intc->iar, intc->mer);
|
2007-05-07 15:22:25 +00:00
|
|
|
R14(value);
|
|
|
|
printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
|
2007-03-11 12:48:24 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-07-10 00:06:00 +00:00
|
|
|
#if defined(CONFIG_CMD_IRQ)
|
2012-07-10 08:31:31 +00:00
|
|
|
int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, const char *argv[])
|
2007-03-11 12:48:24 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct irq_action *act = vecs;
|
|
|
|
|
2012-07-10 08:31:31 +00:00
|
|
|
if (irq_no) {
|
|
|
|
puts("\nInterrupt-Information:\n\n"
|
|
|
|
"Nr Routine Arg Count\n"
|
|
|
|
"-----------------------------\n");
|
|
|
|
|
|
|
|
for (i = 0; i < irq_no; i++) {
|
|
|
|
if (act->handler != (interrupt_handler_t *) def_hdlr) {
|
|
|
|
printf("%02d %08x %08x %d\n", i,
|
|
|
|
(int)act->handler, (int)act->arg,
|
|
|
|
act->count);
|
|
|
|
}
|
|
|
|
act++;
|
2007-03-11 12:48:24 +00:00
|
|
|
}
|
2012-07-10 08:31:31 +00:00
|
|
|
puts("\n");
|
|
|
|
} else {
|
|
|
|
puts("Undefined interrupt controller\n");
|
2007-03-11 12:48:24 +00:00
|
|
|
}
|
2012-07-10 08:31:31 +00:00
|
|
|
return 0;
|
2007-03-11 12:48:24 +00:00
|
|
|
}
|
|
|
|
#endif
|