2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
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>
|
|
|
|
*/
|
|
|
|
|
2007-03-11 12:48:24 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2016-02-15 11:10:32 +00:00
|
|
|
#include <fdtdec.h>
|
2019-11-14 19:57:41 +00:00
|
|
|
#include <irq_func.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2012-07-10 08:31:31 +00:00
|
|
|
#include <malloc.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.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
|
|
|
|
2016-02-15 11:10:32 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2012-06-29 11:27:28 +00:00
|
|
|
void enable_interrupts(void)
|
2004-04-18 21:13:41 +00:00
|
|
|
{
|
2015-01-26 14:25:32 +00:00
|
|
|
debug("Enable interrupts for the whole CPU\n");
|
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);
|
2015-01-26 13:37:52 +00:00
|
|
|
|
|
|
|
debug("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask,
|
|
|
|
intc->ier);
|
|
|
|
debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
|
|
|
|
intc->iar, intc->mer);
|
2007-03-11 12:48:24 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2015-01-26 13:37:52 +00:00
|
|
|
|
|
|
|
debug("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask,
|
|
|
|
intc->ier);
|
|
|
|
debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
|
|
|
|
intc->iar, intc->mer);
|
2007-03-11 12:48:24 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2015-01-26 13:39:22 +00:00
|
|
|
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 */
|
2015-01-26 13:39:22 +00:00
|
|
|
act->handler = (interrupt_handler_t *)def_hdlr;
|
2012-06-29 12:21:52 +00:00
|
|
|
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;
|
2015-01-26 13:37:52 +00:00
|
|
|
|
|
|
|
debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
|
|
|
|
intc->iar, intc->mer);
|
2007-03-11 12:48:24 +00:00
|
|
|
}
|
|
|
|
|
2015-01-27 11:44:12 +00:00
|
|
|
int interrupt_init(void)
|
2007-03-11 12:48:24 +00:00
|
|
|
{
|
|
|
|
int i;
|
2016-02-15 11:10:32 +00:00
|
|
|
const void *blob = gd->fdt_blob;
|
|
|
|
int node = 0;
|
|
|
|
|
|
|
|
debug("INTC: Initialization\n");
|
|
|
|
|
|
|
|
node = fdt_node_offset_by_compatible(blob, node,
|
|
|
|
"xlnx,xps-intc-1.00.a");
|
|
|
|
if (node != -1) {
|
|
|
|
fdt_addr_t base = fdtdec_get_addr(blob, node, "reg");
|
|
|
|
if (base == FDT_ADDR_T_NONE)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
debug("INTC: Base addr %lx\n", base);
|
|
|
|
intc = (microblaze_intc_t *)base;
|
|
|
|
irq_no = fdtdec_get_int(blob, node, "xlnx,num-intr-inputs", 0);
|
|
|
|
debug("INTC: IRQ NO %x\n", irq_no);
|
|
|
|
} else {
|
|
|
|
return node;
|
|
|
|
}
|
2016-02-15 12:44:19 +00:00
|
|
|
|
2012-07-10 08:31:31 +00:00
|
|
|
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++) {
|
2015-01-26 13:39:22 +00:00
|
|
|
vecs[i].handler = (interrupt_handler_t *)def_hdlr;
|
2012-07-10 08:31:31 +00:00
|
|
|
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-05-07 15:22:25 +00:00
|
|
|
int value;
|
2010-04-16 09:51:59 +00:00
|
|
|
struct irq_action *act = vecs + irqs;
|
|
|
|
|
2015-01-26 13:37:52 +00:00
|
|
|
debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
|
|
|
|
intc->iar, intc->mer);
|
|
|
|
#ifdef DEBUG
|
|
|
|
R14(value);
|
2007-03-11 12:48:24 +00:00
|
|
|
#endif
|
2015-01-26 13:37:52 +00:00
|
|
|
debug("Interrupt handler on %x line, r14 %x\n", irqs, value);
|
|
|
|
|
|
|
|
debug("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n",
|
|
|
|
(u32)act->handler, act->count, (u32)act->arg);
|
2015-01-26 13:39:22 +00:00
|
|
|
act->handler(act->arg);
|
2010-04-16 09:51:59 +00:00
|
|
|
act->count++;
|
2007-05-07 15:22:25 +00:00
|
|
|
|
2012-02-22 18:12:43 +00:00
|
|
|
intc->iar = mask << irqs;
|
|
|
|
|
2015-01-26 13:37:52 +00:00
|
|
|
debug("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr,
|
|
|
|
intc->ier, intc->iar, intc->mer);
|
|
|
|
#ifdef DEBUG
|
2007-05-07 15:22:25 +00:00
|
|
|
R14(value);
|
2007-03-11 12:48:24 +00:00
|
|
|
#endif
|
2015-01-26 13:37:52 +00:00
|
|
|
debug("Interrupt handler on %x line, r14 %x\n", irqs, value);
|
2007-03-11 12:48:24 +00:00
|
|
|
}
|
|
|
|
|
2007-07-10 00:06:00 +00:00
|
|
|
#if defined(CONFIG_CMD_IRQ)
|
2020-05-10 17:40:03 +00:00
|
|
|
int do_irqinfo(struct cmd_tbl *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++) {
|
2015-01-26 13:39:22 +00:00
|
|
|
if (act->handler != (interrupt_handler_t *)def_hdlr) {
|
2012-07-10 08:31:31 +00:00
|
|
|
printf("%02d %08x %08x %d\n", i,
|
2015-01-26 13:39:22 +00:00
|
|
|
(int)act->handler, (int)act->arg,
|
|
|
|
act->count);
|
2012-07-10 08:31:31 +00:00
|
|
|
}
|
|
|
|
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
|