2009-08-17 00:13:29 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 Daniel Hellstrom (daniel@gaisler.com) Aeroflex Gaisler AB
|
|
|
|
* Copyright (C) 2009 Konrad Eisele (konrad@gaisler.com) Aeroflex Gaisler AB
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_platform.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/of_device.h>
|
2009-08-31 22:08:13 +00:00
|
|
|
|
2009-08-17 00:13:29 +00:00
|
|
|
#include <asm/oplib.h>
|
|
|
|
#include <asm/timer.h>
|
|
|
|
#include <asm/prom.h>
|
|
|
|
#include <asm/leon.h>
|
|
|
|
#include <asm/leon_amba.h>
|
2009-08-31 22:08:13 +00:00
|
|
|
#include <asm/traps.h>
|
|
|
|
#include <asm/cacheflush.h>
|
2009-08-17 00:13:29 +00:00
|
|
|
|
|
|
|
#include "prom.h"
|
|
|
|
#include "irq.h"
|
|
|
|
|
2011-01-04 01:41:29 +00:00
|
|
|
struct leon3_irqctrl_regs_map *leon3_irqctrl_regs; /* interrupt controller base address */
|
|
|
|
struct leon3_gptimer_regs_map *leon3_gptimer_regs; /* timer controller base address */
|
2009-08-17 00:13:29 +00:00
|
|
|
struct amba_apb_device leon_percpu_timer_dev[16];
|
|
|
|
|
|
|
|
int leondebug_irq_disable;
|
|
|
|
int leon_debug_irqout;
|
|
|
|
static int dummy_master_l10_counter;
|
2011-01-27 01:26:58 +00:00
|
|
|
unsigned long amba_system_id;
|
2009-08-17 00:13:29 +00:00
|
|
|
|
2011-01-04 01:41:29 +00:00
|
|
|
unsigned long leon3_gptimer_irq; /* interrupt controller irq number */
|
2011-01-04 01:41:32 +00:00
|
|
|
unsigned long leon3_gptimer_idx; /* Timer Index (0..6) within Timer Core */
|
2009-08-17 00:13:29 +00:00
|
|
|
unsigned int sparc_leon_eirq;
|
|
|
|
#define LEON_IMASK ((&leon3_irqctrl_regs->mask[0]))
|
|
|
|
|
|
|
|
/* Return the IRQ of the pending IRQ on the extended IRQ controller */
|
|
|
|
int sparc_leon_eirq_get(int eirq, int cpu)
|
|
|
|
{
|
|
|
|
return LEON3_BYPASS_LOAD_PA(&leon3_irqctrl_regs->intid[cpu]) & 0x1f;
|
|
|
|
}
|
|
|
|
|
|
|
|
irqreturn_t sparc_leon_eirq_isr(int dummy, void *dev_id)
|
|
|
|
{
|
|
|
|
printk(KERN_ERR "sparc_leon_eirq_isr: ERROR EXTENDED IRQ\n");
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The extended IRQ controller has been found, this function registers it */
|
|
|
|
void sparc_leon_eirq_register(int eirq)
|
|
|
|
{
|
|
|
|
int irq;
|
|
|
|
|
|
|
|
/* Register a "BAD" handler for this interrupt, it should never happen */
|
|
|
|
irq = request_irq(eirq, sparc_leon_eirq_isr,
|
|
|
|
(IRQF_DISABLED | SA_STATIC_ALLOC), "extirq", NULL);
|
|
|
|
|
|
|
|
if (irq) {
|
|
|
|
printk(KERN_ERR
|
|
|
|
"sparc_leon_eirq_register: unable to attach IRQ%d\n",
|
|
|
|
eirq);
|
|
|
|
} else {
|
|
|
|
sparc_leon_eirq = eirq;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long get_irqmask(unsigned int irq)
|
|
|
|
{
|
|
|
|
unsigned long mask;
|
|
|
|
|
|
|
|
if (!irq || ((irq > 0xf) && !sparc_leon_eirq)
|
|
|
|
|| ((irq > 0x1f) && sparc_leon_eirq)) {
|
|
|
|
printk(KERN_ERR
|
|
|
|
"leon_get_irqmask: false irq number: %d\n", irq);
|
|
|
|
mask = 0;
|
|
|
|
} else {
|
|
|
|
mask = LEON_HARD_INT(irq);
|
|
|
|
}
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2011-04-18 11:25:44 +00:00
|
|
|
static void leon_unmask_irq(struct irq_data *data)
|
2009-08-17 00:13:29 +00:00
|
|
|
{
|
|
|
|
unsigned long mask, flags;
|
2011-04-18 11:25:44 +00:00
|
|
|
|
|
|
|
mask = (unsigned long)data->chip_data;
|
2009-08-17 00:13:29 +00:00
|
|
|
local_irq_save(flags);
|
|
|
|
LEON3_BYPASS_STORE_PA(LEON_IMASK,
|
|
|
|
(LEON3_BYPASS_LOAD_PA(LEON_IMASK) | (mask)));
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
2011-04-18 11:25:44 +00:00
|
|
|
static void leon_mask_irq(struct irq_data *data)
|
2009-08-17 00:13:29 +00:00
|
|
|
{
|
|
|
|
unsigned long mask, flags;
|
2011-04-18 11:25:44 +00:00
|
|
|
|
|
|
|
mask = (unsigned long)data->chip_data;
|
2009-08-17 00:13:29 +00:00
|
|
|
local_irq_save(flags);
|
|
|
|
LEON3_BYPASS_STORE_PA(LEON_IMASK,
|
|
|
|
(LEON3_BYPASS_LOAD_PA(LEON_IMASK) & ~(mask)));
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-04-18 11:25:44 +00:00
|
|
|
static unsigned int leon_startup_irq(struct irq_data *data)
|
|
|
|
{
|
|
|
|
irq_link(data->irq);
|
|
|
|
leon_unmask_irq(data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void leon_shutdown_irq(struct irq_data *data)
|
|
|
|
{
|
|
|
|
leon_mask_irq(data);
|
|
|
|
irq_unlink(data->irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct irq_chip leon_irq = {
|
|
|
|
.name = "leon",
|
|
|
|
.irq_startup = leon_startup_irq,
|
|
|
|
.irq_shutdown = leon_shutdown_irq,
|
|
|
|
.irq_mask = leon_mask_irq,
|
|
|
|
.irq_unmask = leon_unmask_irq,
|
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned int leon_build_device_irq(struct platform_device *op,
|
|
|
|
unsigned int real_irq)
|
|
|
|
{
|
|
|
|
unsigned int irq;
|
|
|
|
unsigned long mask;
|
|
|
|
|
|
|
|
irq = 0;
|
|
|
|
mask = get_irqmask(real_irq);
|
|
|
|
if (mask == 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
irq = irq_alloc(real_irq, real_irq);
|
|
|
|
if (irq == 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
irq_set_chip_and_handler_name(irq, &leon_irq,
|
|
|
|
handle_simple_irq, "edge");
|
|
|
|
irq_set_chip_data(irq, (void *)mask);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return irq;
|
|
|
|
}
|
|
|
|
|
2009-08-17 00:13:29 +00:00
|
|
|
void __init leon_init_timers(irq_handler_t counter_fn)
|
|
|
|
{
|
|
|
|
int irq;
|
2011-01-04 01:41:32 +00:00
|
|
|
struct device_node *rootnp, *np, *nnp;
|
2011-01-04 01:41:29 +00:00
|
|
|
struct property *pp;
|
|
|
|
int len;
|
2011-01-04 01:41:30 +00:00
|
|
|
int cpu, icsel;
|
2011-01-04 01:41:32 +00:00
|
|
|
int ampopts;
|
2011-04-18 11:25:44 +00:00
|
|
|
int err;
|
2009-08-17 00:13:29 +00:00
|
|
|
|
|
|
|
leondebug_irq_disable = 0;
|
|
|
|
leon_debug_irqout = 0;
|
|
|
|
master_l10_counter = (unsigned int *)&dummy_master_l10_counter;
|
|
|
|
dummy_master_l10_counter = 0;
|
|
|
|
|
2011-01-04 01:41:29 +00:00
|
|
|
rootnp = of_find_node_by_path("/ambapp0");
|
|
|
|
if (!rootnp)
|
|
|
|
goto bad;
|
2011-01-27 01:26:58 +00:00
|
|
|
|
|
|
|
/* Find System ID: GRLIB build ID and optional CHIP ID */
|
|
|
|
pp = of_find_property(rootnp, "systemid", &len);
|
|
|
|
if (pp)
|
|
|
|
amba_system_id = *(unsigned long *)pp->value;
|
|
|
|
|
|
|
|
/* Find IRQMP IRQ Controller Registers base adr otherwise bail out */
|
2011-01-04 01:41:29 +00:00
|
|
|
np = of_find_node_by_name(rootnp, "GAISLER_IRQMP");
|
2011-01-04 01:41:31 +00:00
|
|
|
if (!np) {
|
|
|
|
np = of_find_node_by_name(rootnp, "01_00d");
|
|
|
|
if (!np)
|
|
|
|
goto bad;
|
|
|
|
}
|
2011-01-04 01:41:29 +00:00
|
|
|
pp = of_find_property(np, "reg", &len);
|
|
|
|
if (!pp)
|
|
|
|
goto bad;
|
|
|
|
leon3_irqctrl_regs = *(struct leon3_irqctrl_regs_map **)pp->value;
|
|
|
|
|
|
|
|
/* Find GPTIMER Timer Registers base address otherwise bail out. */
|
2011-01-04 01:41:32 +00:00
|
|
|
nnp = rootnp;
|
|
|
|
do {
|
|
|
|
np = of_find_node_by_name(nnp, "GAISLER_GPTIMER");
|
|
|
|
if (!np) {
|
|
|
|
np = of_find_node_by_name(nnp, "01_011");
|
|
|
|
if (!np)
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
ampopts = 0;
|
|
|
|
pp = of_find_property(np, "ampopts", &len);
|
|
|
|
if (pp) {
|
|
|
|
ampopts = *(int *)pp->value;
|
|
|
|
if (ampopts == 0) {
|
|
|
|
/* Skip this instance, resource already
|
|
|
|
* allocated by other OS */
|
|
|
|
nnp = np;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Select Timer-Instance on Timer Core. Default is zero */
|
|
|
|
leon3_gptimer_idx = ampopts & 0x7;
|
|
|
|
|
|
|
|
pp = of_find_property(np, "reg", &len);
|
|
|
|
if (pp)
|
|
|
|
leon3_gptimer_regs = *(struct leon3_gptimer_regs_map **)
|
|
|
|
pp->value;
|
|
|
|
pp = of_find_property(np, "interrupts", &len);
|
|
|
|
if (pp)
|
|
|
|
leon3_gptimer_irq = *(unsigned int *)pp->value;
|
|
|
|
} while (0);
|
2011-01-04 01:41:29 +00:00
|
|
|
|
|
|
|
if (leon3_gptimer_regs && leon3_irqctrl_regs && leon3_gptimer_irq) {
|
2011-01-04 01:41:32 +00:00
|
|
|
LEON3_BYPASS_STORE_PA(
|
|
|
|
&leon3_gptimer_regs->e[leon3_gptimer_idx].val, 0);
|
|
|
|
LEON3_BYPASS_STORE_PA(
|
|
|
|
&leon3_gptimer_regs->e[leon3_gptimer_idx].rld,
|
|
|
|
(((1000000 / HZ) - 1)));
|
|
|
|
LEON3_BYPASS_STORE_PA(
|
|
|
|
&leon3_gptimer_regs->e[leon3_gptimer_idx].ctrl, 0);
|
2009-08-17 00:13:29 +00:00
|
|
|
|
2009-08-31 22:08:13 +00:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
leon_percpu_timer_dev[0].start = (int)leon3_gptimer_regs;
|
2011-01-04 01:41:32 +00:00
|
|
|
leon_percpu_timer_dev[0].irq = leon3_gptimer_irq + 1 +
|
|
|
|
leon3_gptimer_idx;
|
2009-08-31 22:08:13 +00:00
|
|
|
|
|
|
|
if (!(LEON3_BYPASS_LOAD_PA(&leon3_gptimer_regs->config) &
|
|
|
|
(1<<LEON3_GPTIMER_SEPIRQ))) {
|
2010-02-12 20:08:51 +00:00
|
|
|
prom_printf("irq timer not configured with separate irqs\n");
|
2009-08-31 22:08:13 +00:00
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
|
2011-01-04 01:41:32 +00:00
|
|
|
LEON3_BYPASS_STORE_PA(
|
|
|
|
&leon3_gptimer_regs->e[leon3_gptimer_idx+1].val, 0);
|
|
|
|
LEON3_BYPASS_STORE_PA(
|
|
|
|
&leon3_gptimer_regs->e[leon3_gptimer_idx+1].rld,
|
|
|
|
(((1000000/HZ) - 1)));
|
|
|
|
LEON3_BYPASS_STORE_PA(
|
|
|
|
&leon3_gptimer_regs->e[leon3_gptimer_idx+1].ctrl, 0);
|
2009-08-31 22:08:13 +00:00
|
|
|
# endif
|
|
|
|
|
2011-01-04 01:41:30 +00:00
|
|
|
/*
|
|
|
|
* The IRQ controller may (if implemented) consist of multiple
|
|
|
|
* IRQ controllers, each mapped on a 4Kb boundary.
|
|
|
|
* Each CPU may be routed to different IRQCTRLs, however
|
|
|
|
* we assume that all CPUs (in SMP system) is routed to the
|
|
|
|
* same IRQ Controller, and for non-SMP only one IRQCTRL is
|
|
|
|
* accessed anyway.
|
|
|
|
* In AMP systems, Linux must run on CPU0 for the time being.
|
|
|
|
*/
|
|
|
|
cpu = sparc_leon3_cpuid();
|
|
|
|
icsel = LEON3_BYPASS_LOAD_PA(&leon3_irqctrl_regs->icsel[cpu/8]);
|
|
|
|
icsel = (icsel >> ((7 - (cpu&0x7)) * 4)) & 0xf;
|
|
|
|
leon3_irqctrl_regs += icsel;
|
2009-08-17 00:13:29 +00:00
|
|
|
} else {
|
2011-01-04 01:41:29 +00:00
|
|
|
goto bad;
|
2009-08-17 00:13:29 +00:00
|
|
|
}
|
|
|
|
|
2011-04-18 11:25:44 +00:00
|
|
|
irq = leon_build_device_irq(NULL, leon3_gptimer_irq + leon3_gptimer_idx);
|
|
|
|
err = request_irq(irq, counter_fn, IRQF_TIMER, "timer", NULL);
|
2009-08-17 00:13:29 +00:00
|
|
|
|
2011-04-18 11:25:44 +00:00
|
|
|
if (err) {
|
2009-08-17 00:13:29 +00:00
|
|
|
printk(KERN_ERR "leon_time_init: unable to attach IRQ%d\n",
|
|
|
|
LEON_INTERRUPT_TIMER1);
|
|
|
|
prom_halt();
|
|
|
|
}
|
|
|
|
|
2009-08-31 22:08:13 +00:00
|
|
|
# ifdef CONFIG_SMP
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct tt_entry *trap_table = &sparc_ttable[SP_TRAP_IRQ1 + (leon_percpu_timer_dev[0].irq - 1)];
|
|
|
|
|
|
|
|
/* For SMP we use the level 14 ticker, however the bootup code
|
|
|
|
* has copied the firmwares level 14 vector into boot cpu's
|
|
|
|
* trap table, we must fix this now or we get squashed.
|
|
|
|
*/
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
patchme_maybe_smp_msg[0] = 0x01000000; /* NOP out the branch */
|
|
|
|
|
|
|
|
/* Adjust so that we jump directly to smpleon_ticker */
|
|
|
|
trap_table->inst_three += smpleon_ticker - real_irq_entry;
|
|
|
|
|
|
|
|
local_flush_cache_all();
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
2009-08-17 00:13:29 +00:00
|
|
|
if (leon3_gptimer_regs) {
|
2011-01-04 01:41:32 +00:00
|
|
|
LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx].ctrl,
|
2009-08-17 00:13:29 +00:00
|
|
|
LEON3_GPTIMER_EN |
|
|
|
|
LEON3_GPTIMER_RL |
|
|
|
|
LEON3_GPTIMER_LD | LEON3_GPTIMER_IRQEN);
|
2009-08-31 22:08:13 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
2011-01-04 01:41:32 +00:00
|
|
|
LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx+1].ctrl,
|
2009-08-31 22:08:13 +00:00
|
|
|
LEON3_GPTIMER_EN |
|
|
|
|
LEON3_GPTIMER_RL |
|
|
|
|
LEON3_GPTIMER_LD |
|
|
|
|
LEON3_GPTIMER_IRQEN);
|
|
|
|
#endif
|
|
|
|
|
2009-08-17 00:13:29 +00:00
|
|
|
}
|
2011-01-04 01:41:29 +00:00
|
|
|
return;
|
|
|
|
bad:
|
|
|
|
printk(KERN_ERR "No Timer/irqctrl found\n");
|
|
|
|
BUG();
|
|
|
|
return;
|
2009-08-17 00:13:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void leon_clear_clock_irq(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void leon_load_profile_irq(int cpu, unsigned int limit)
|
|
|
|
{
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void __init leon_trans_init(struct device_node *dp)
|
|
|
|
{
|
|
|
|
if (strcmp(dp->type, "cpu") == 0 && strcmp(dp->name, "<NULL>") == 0) {
|
|
|
|
struct property *p;
|
|
|
|
p = of_find_property(dp, "mid", (void *)0);
|
|
|
|
if (p) {
|
|
|
|
int mid;
|
|
|
|
dp->name = prom_early_alloc(5 + 1);
|
|
|
|
memcpy(&mid, p->value, p->length);
|
|
|
|
sprintf((char *)dp->name, "cpu%.2d", mid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void __initdata (*prom_amba_init)(struct device_node *dp, struct device_node ***nextp) = 0;
|
|
|
|
|
|
|
|
void __init leon_node_init(struct device_node *dp, struct device_node ***nextp)
|
|
|
|
{
|
|
|
|
if (prom_amba_init &&
|
|
|
|
strcmp(dp->type, "ambapp") == 0 &&
|
|
|
|
strcmp(dp->name, "ambapp0") == 0) {
|
|
|
|
prom_amba_init(dp, nextp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-31 22:08:13 +00:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
|
|
|
|
void leon_set_cpu_int(int cpu, int level)
|
|
|
|
{
|
|
|
|
unsigned long mask;
|
|
|
|
mask = get_irqmask(level);
|
|
|
|
LEON3_BYPASS_STORE_PA(&leon3_irqctrl_regs->force[cpu], mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void leon_clear_ipi(int cpu, int level)
|
|
|
|
{
|
|
|
|
unsigned long mask;
|
|
|
|
mask = get_irqmask(level);
|
|
|
|
LEON3_BYPASS_STORE_PA(&leon3_irqctrl_regs->force[cpu], mask<<16);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void leon_set_udt(int cpu)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void leon_clear_profile_irq(int cpu)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void leon_enable_irq_cpu(unsigned int irq_nr, unsigned int cpu)
|
|
|
|
{
|
|
|
|
unsigned long mask, flags, *addr;
|
|
|
|
mask = get_irqmask(irq_nr);
|
|
|
|
local_irq_save(flags);
|
|
|
|
addr = (unsigned long *)&(leon3_irqctrl_regs->mask[cpu]);
|
|
|
|
LEON3_BYPASS_STORE_PA(addr, (LEON3_BYPASS_LOAD_PA(addr) | (mask)));
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-08-17 00:13:29 +00:00
|
|
|
void __init leon_init_IRQ(void)
|
|
|
|
{
|
2011-04-18 11:25:44 +00:00
|
|
|
sparc_irq_config.init_timers = leon_init_timers;
|
|
|
|
sparc_irq_config.build_device_irq = leon_build_device_irq;
|
2009-08-17 00:13:29 +00:00
|
|
|
|
|
|
|
BTFIXUPSET_CALL(clear_clock_irq, leon_clear_clock_irq,
|
|
|
|
BTFIXUPCALL_NORM);
|
|
|
|
BTFIXUPSET_CALL(load_profile_irq, leon_load_profile_irq,
|
|
|
|
BTFIXUPCALL_NOP);
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
BTFIXUPSET_CALL(set_cpu_int, leon_set_cpu_int, BTFIXUPCALL_NORM);
|
|
|
|
BTFIXUPSET_CALL(clear_cpu_int, leon_clear_ipi, BTFIXUPCALL_NORM);
|
|
|
|
BTFIXUPSET_CALL(set_irq_udt, leon_set_udt, BTFIXUPCALL_NORM);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init leon_init(void)
|
|
|
|
{
|
2010-10-11 03:51:25 +00:00
|
|
|
of_pdt_build_more = &leon_node_init;
|
2009-08-17 00:13:29 +00:00
|
|
|
}
|