blob: 829ae26ad274b5767e14b916b7ba0454c35990cd [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk12490652004-04-18 21:13:41 +00002/*
Michal Simek922ce202007-03-11 13:48:24 +01003 * (C) Copyright 2007 Michal Simek
wdenk12490652004-04-18 21:13:41 +00004 * (C) Copyright 2004 Atmark Techno, Inc.
5 *
Michal Simek922ce202007-03-11 13:48:24 +01006 * Michal SIMEK <monstr@monstr.eu>
wdenk12490652004-04-18 21:13:41 +00007 * Yasushi SHOJI <yashi@atmark-techno.com>
wdenk12490652004-04-18 21:13:41 +00008 */
9
Michal Simek922ce202007-03-11 13:48:24 +010010#include <common.h>
11#include <command.h>
Michal Simekcf848852016-02-15 12:10:32 +010012#include <fdtdec.h>
Simon Glass9b61c7c2019-11-14 12:57:41 -070013#include <irq_func.h>
Simon Glass0f2af882020-05-10 11:40:05 -060014#include <log.h>
Michal Simek251ed2c2012-07-10 10:31:31 +020015#include <malloc.h>
Michal Simek922ce202007-03-11 13:48:24 +010016#include <asm/microblaze_intc.h>
Michal Simek77a1e242007-05-07 17:22:25 +020017#include <asm/asm.h>
Michal Simek922ce202007-03-11 13:48:24 +010018
Michal Simekcf848852016-02-15 12:10:32 +010019DECLARE_GLOBAL_DATA_PTR;
20
Michal Simek8b4bb3a2012-06-29 13:27:28 +020021void enable_interrupts(void)
wdenk12490652004-04-18 21:13:41 +000022{
Michal Simek056dbe82015-01-26 15:25:32 +010023 debug("Enable interrupts for the whole CPU\n");
Michal Simek98c19792007-05-07 23:58:31 +020024 MSRSET(0x2);
wdenk12490652004-04-18 21:13:41 +000025}
26
Michal Simek8b4bb3a2012-06-29 13:27:28 +020027int disable_interrupts(void)
wdenk12490652004-04-18 21:13:41 +000028{
Michal Simekc94f95e2010-12-21 08:30:39 +010029 unsigned int msr;
30
31 MFS(msr, rmsr);
Michal Simek98c19792007-05-07 23:58:31 +020032 MSRCLR(0x2);
Michal Simekc94f95e2010-12-21 08:30:39 +010033 return (msr & 0x2) != 0;
wdenk12490652004-04-18 21:13:41 +000034}
Michal Simek922ce202007-03-11 13:48:24 +010035
Michal Simek251ed2c2012-07-10 10:31:31 +020036static struct irq_action *vecs;
37static u32 irq_no;
Michal Simek922ce202007-03-11 13:48:24 +010038
39/* mapping structure to interrupt controller */
Michal Simek251ed2c2012-07-10 10:31:31 +020040microblaze_intc_t *intc;
Michal Simek922ce202007-03-11 13:48:24 +010041
42/* default handler */
Michal Simek251ed2c2012-07-10 10:31:31 +020043static void def_hdlr(void)
Michal Simek922ce202007-03-11 13:48:24 +010044{
Michal Simek8b4bb3a2012-06-29 13:27:28 +020045 puts("def_hdlr\n");
Michal Simek922ce202007-03-11 13:48:24 +010046}
47
Michal Simek251ed2c2012-07-10 10:31:31 +020048static void enable_one_interrupt(int irq)
Michal Simek922ce202007-03-11 13:48:24 +010049{
50 int mask;
51 int offset = 1;
Michal Simek8b4bb3a2012-06-29 13:27:28 +020052
Michal Simek922ce202007-03-11 13:48:24 +010053 offset <<= irq;
54 mask = intc->ier;
55 intc->ier = (mask | offset);
Michal Simekbaf51752015-01-26 14:37:52 +010056
57 debug("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask,
58 intc->ier);
59 debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
60 intc->iar, intc->mer);
Michal Simek922ce202007-03-11 13:48:24 +010061}
62
Michal Simek251ed2c2012-07-10 10:31:31 +020063static void disable_one_interrupt(int irq)
Michal Simek922ce202007-03-11 13:48:24 +010064{
65 int mask;
66 int offset = 1;
Michal Simek8b4bb3a2012-06-29 13:27:28 +020067
Michal Simek922ce202007-03-11 13:48:24 +010068 offset <<= irq;
69 mask = intc->ier;
70 intc->ier = (mask & ~offset);
Michal Simekbaf51752015-01-26 14:37:52 +010071
72 debug("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask,
73 intc->ier);
74 debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
75 intc->iar, intc->mer);
Michal Simek922ce202007-03-11 13:48:24 +010076}
77
Michal Simeke76a06e2012-06-29 14:21:52 +020078int install_interrupt_handler(int irq, interrupt_handler_t *hdlr, void *arg)
Michal Simek922ce202007-03-11 13:48:24 +010079{
80 struct irq_action *act;
Michal Simek8b4bb3a2012-06-29 13:27:28 +020081
Michal Simek922ce202007-03-11 13:48:24 +010082 /* irq out of range */
Michal Simek251ed2c2012-07-10 10:31:31 +020083 if ((irq < 0) || (irq > irq_no)) {
Michal Simek8b4bb3a2012-06-29 13:27:28 +020084 puts("IRQ out of range\n");
Michal Simeke76a06e2012-06-29 14:21:52 +020085 return -1;
Michal Simek922ce202007-03-11 13:48:24 +010086 }
87 act = &vecs[irq];
88 if (hdlr) { /* enable */
89 act->handler = hdlr;
90 act->arg = arg;
91 act->count = 0;
Michal Simek5e6c7472015-01-26 14:39:22 +010092 enable_one_interrupt(irq);
Michal Simeke76a06e2012-06-29 14:21:52 +020093 return 0;
Michal Simek922ce202007-03-11 13:48:24 +010094 }
Michal Simeke76a06e2012-06-29 14:21:52 +020095
96 /* Disable */
Michal Simek5e6c7472015-01-26 14:39:22 +010097 act->handler = (interrupt_handler_t *)def_hdlr;
Michal Simeke76a06e2012-06-29 14:21:52 +020098 act->arg = (void *)irq;
99 disable_one_interrupt(irq);
100 return 1;
Michal Simek922ce202007-03-11 13:48:24 +0100101}
102
103/* initialization interrupt controller - hardware */
Michal Simek251ed2c2012-07-10 10:31:31 +0200104static void intc_init(void)
Michal Simek922ce202007-03-11 13:48:24 +0100105{
106 intc->mer = 0;
107 intc->ier = 0;
108 intc->iar = 0xFFFFFFFF;
109 /* XIntc_Start - hw_interrupt enable and all interrupt enable */
110 intc->mer = 0x3;
Michal Simekbaf51752015-01-26 14:37:52 +0100111
112 debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
113 intc->iar, intc->mer);
Michal Simek922ce202007-03-11 13:48:24 +0100114}
115
Michal Simekb78df3d2015-01-27 12:44:12 +0100116int interrupt_init(void)
Michal Simek922ce202007-03-11 13:48:24 +0100117{
118 int i;
Michal Simekcf848852016-02-15 12:10:32 +0100119 const void *blob = gd->fdt_blob;
120 int node = 0;
121
122 debug("INTC: Initialization\n");
123
124 node = fdt_node_offset_by_compatible(blob, node,
125 "xlnx,xps-intc-1.00.a");
126 if (node != -1) {
127 fdt_addr_t base = fdtdec_get_addr(blob, node, "reg");
128 if (base == FDT_ADDR_T_NONE)
129 return -1;
130
131 debug("INTC: Base addr %lx\n", base);
132 intc = (microblaze_intc_t *)base;
133 irq_no = fdtdec_get_int(blob, node, "xlnx,num-intr-inputs", 0);
134 debug("INTC: IRQ NO %x\n", irq_no);
135 } else {
136 return node;
137 }
Michal Simekc3d51b92016-02-15 13:44:19 +0100138
Michal Simek251ed2c2012-07-10 10:31:31 +0200139 if (irq_no) {
140 vecs = calloc(1, sizeof(struct irq_action) * irq_no);
141 if (vecs == NULL) {
142 puts("Interrupt vector allocation failed\n");
143 return -1;
144 }
145
146 /* initialize irq list */
147 for (i = 0; i < irq_no; i++) {
Michal Simek5e6c7472015-01-26 14:39:22 +0100148 vecs[i].handler = (interrupt_handler_t *)def_hdlr;
Michal Simek251ed2c2012-07-10 10:31:31 +0200149 vecs[i].arg = (void *)i;
150 vecs[i].count = 0;
151 }
152 /* initialize intc controller */
153 intc_init();
154 enable_interrupts();
155 } else {
156 puts("Undefined interrupt controller\n");
Michal Simek922ce202007-03-11 13:48:24 +0100157 }
Michal Simek922ce202007-03-11 13:48:24 +0100158 return 0;
159}
160
Michal Simek8b4bb3a2012-06-29 13:27:28 +0200161void interrupt_handler(void)
Michal Simek922ce202007-03-11 13:48:24 +0100162{
Michal Simek2c004492010-04-16 11:51:59 +0200163 int irqs = intc->ivr; /* find active interrupt */
164 int mask = 1;
Michal Simek77a1e242007-05-07 17:22:25 +0200165 int value;
Michal Simek2c004492010-04-16 11:51:59 +0200166 struct irq_action *act = vecs + irqs;
167
Michal Simekbaf51752015-01-26 14:37:52 +0100168 debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
169 intc->iar, intc->mer);
170#ifdef DEBUG
171 R14(value);
Michal Simek922ce202007-03-11 13:48:24 +0100172#endif
Michal Simekbaf51752015-01-26 14:37:52 +0100173 debug("Interrupt handler on %x line, r14 %x\n", irqs, value);
174
175 debug("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n",
176 (u32)act->handler, act->count, (u32)act->arg);
Michal Simek5e6c7472015-01-26 14:39:22 +0100177 act->handler(act->arg);
Michal Simek2c004492010-04-16 11:51:59 +0200178 act->count++;
Michal Simek77a1e242007-05-07 17:22:25 +0200179
Stephan Linz5db50d62012-02-22 19:12:43 +0100180 intc->iar = mask << irqs;
181
Michal Simekbaf51752015-01-26 14:37:52 +0100182 debug("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr,
183 intc->ier, intc->iar, intc->mer);
184#ifdef DEBUG
Michal Simek77a1e242007-05-07 17:22:25 +0200185 R14(value);
Michal Simek922ce202007-03-11 13:48:24 +0100186#endif
Michal Simekbaf51752015-01-26 14:37:52 +0100187 debug("Interrupt handler on %x line, r14 %x\n", irqs, value);
Michal Simek922ce202007-03-11 13:48:24 +0100188}
Michal Simek922ce202007-03-11 13:48:24 +0100189
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500190#if defined(CONFIG_CMD_IRQ)
Simon Glassed38aef2020-05-10 11:40:03 -0600191int do_irqinfo(struct cmd_tbl *cmdtp, int flag, int argc, const char *argv[])
Michal Simek922ce202007-03-11 13:48:24 +0100192{
193 int i;
194 struct irq_action *act = vecs;
195
Michal Simek251ed2c2012-07-10 10:31:31 +0200196 if (irq_no) {
197 puts("\nInterrupt-Information:\n\n"
198 "Nr Routine Arg Count\n"
199 "-----------------------------\n");
Michal Simek922ce202007-03-11 13:48:24 +0100200
Michal Simek251ed2c2012-07-10 10:31:31 +0200201 for (i = 0; i < irq_no; i++) {
Michal Simek5e6c7472015-01-26 14:39:22 +0100202 if (act->handler != (interrupt_handler_t *)def_hdlr) {
Michal Simek251ed2c2012-07-10 10:31:31 +0200203 printf("%02d %08x %08x %d\n", i,
Michal Simek5e6c7472015-01-26 14:39:22 +0100204 (int)act->handler, (int)act->arg,
205 act->count);
Michal Simek251ed2c2012-07-10 10:31:31 +0200206 }
207 act++;
Michal Simek922ce202007-03-11 13:48:24 +0100208 }
Michal Simek251ed2c2012-07-10 10:31:31 +0200209 puts("\n");
210 } else {
211 puts("Undefined interrupt controller\n");
Michal Simek922ce202007-03-11 13:48:24 +0100212 }
Michal Simek251ed2c2012-07-10 10:31:31 +0200213 return 0;
Michal Simek922ce202007-03-11 13:48:24 +0100214}
215#endif