Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2009 Daniel Hellstrom (daniel@gaisler.com) Aeroflex Gaisler AB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2009 Konrad Eisele (konrad@gaisler.com) Aeroflex Gaisler AB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/clocksource.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/clockchips.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/oplib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <asm/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <asm/prom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/leon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/leon_amba.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <asm/traps.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <asm/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include "kernel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include "prom.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include "irq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) struct leon3_irqctrl_regs_map *leon3_irqctrl_regs; /* interrupt controller base address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) struct leon3_gptimer_regs_map *leon3_gptimer_regs; /* timer controller base address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) int leondebug_irq_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) int leon_debug_irqout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static volatile u32 dummy_master_l10_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) unsigned long amba_system_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static DEFINE_SPINLOCK(leon_irq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static unsigned long leon3_gptimer_idx; /* Timer Index (0..6) within Timer Core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static unsigned long leon3_gptimer_ackmask; /* For clearing pending bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) unsigned long leon3_gptimer_irq; /* interrupt controller irq number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) unsigned int sparc_leon_eirq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define LEON_IMASK(cpu) (&leon3_irqctrl_regs->mask[cpu])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define LEON_IACK (&leon3_irqctrl_regs->iclear)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define LEON_DO_ACK_HW 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) /* Return the last ACKed IRQ by the Extended IRQ controller. It has already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * been (automatically) ACKed when the CPU takes the trap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static inline unsigned int leon_eirq_get(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	return LEON3_BYPASS_LOAD_PA(&leon3_irqctrl_regs->intid[cpu]) & 0x1f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) /* Handle one or multiple IRQs from the extended interrupt controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) static void leon_handle_ext_irq(struct irq_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	unsigned int eirq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct irq_bucket *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	int cpu = sparc_leon3_cpuid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	eirq = leon_eirq_get(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	p = irq_map[eirq];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if ((eirq & 0x10) && p && p->irq) /* bit4 tells if IRQ happened */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		generic_handle_irq(p->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) /* The extended IRQ controller has been found, this function registers it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static void leon_eirq_setup(unsigned int eirq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	unsigned long mask, oldmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	unsigned int veirq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (eirq < 1 || eirq > 0xf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		printk(KERN_ERR "LEON EXT IRQ NUMBER BAD: %d\n", eirq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	veirq = leon_build_device_irq(eirq, leon_handle_ext_irq, "extirq", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	 * Unmask the Extended IRQ, the IRQs routed through the Ext-IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	 * controller have a mask-bit of their own, so this is safe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	irq_link(veirq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	mask = 1 << eirq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	oldmask = LEON3_BYPASS_LOAD_PA(LEON_IMASK(boot_cpu_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	LEON3_BYPASS_STORE_PA(LEON_IMASK(boot_cpu_id), (oldmask | mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	sparc_leon_eirq = eirq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) unsigned long leon_get_irqmask(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	unsigned long mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (!irq || ((irq > 0xf) && !sparc_leon_eirq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	    || ((irq > 0x1f) && sparc_leon_eirq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		printk(KERN_ERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		       "leon_get_irqmask: false irq number: %d\n", irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		mask = LEON_HARD_INT(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	return mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static int irq_choose_cpu(const struct cpumask *affinity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	cpumask_t mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	cpumask_and(&mask, cpu_online_mask, affinity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	if (cpumask_equal(&mask, cpu_online_mask) || cpumask_empty(&mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		return boot_cpu_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		return cpumask_first(&mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define irq_choose_cpu(affinity) boot_cpu_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static int leon_set_affinity(struct irq_data *data, const struct cpumask *dest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			     bool force)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	unsigned long mask, oldmask, flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	int oldcpu, newcpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	mask = (unsigned long)data->chip_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	oldcpu = irq_choose_cpu(irq_data_get_affinity_mask(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	newcpu = irq_choose_cpu(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (oldcpu == newcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	/* unmask on old CPU first before enabling on the selected CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	spin_lock_irqsave(&leon_irq_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	oldmask = LEON3_BYPASS_LOAD_PA(LEON_IMASK(oldcpu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	LEON3_BYPASS_STORE_PA(LEON_IMASK(oldcpu), (oldmask & ~mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	oldmask = LEON3_BYPASS_LOAD_PA(LEON_IMASK(newcpu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	LEON3_BYPASS_STORE_PA(LEON_IMASK(newcpu), (oldmask | mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	spin_unlock_irqrestore(&leon_irq_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	return IRQ_SET_MASK_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static void leon_unmask_irq(struct irq_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	unsigned long mask, oldmask, flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	mask = (unsigned long)data->chip_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	cpu = irq_choose_cpu(irq_data_get_affinity_mask(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	spin_lock_irqsave(&leon_irq_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	oldmask = LEON3_BYPASS_LOAD_PA(LEON_IMASK(cpu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	LEON3_BYPASS_STORE_PA(LEON_IMASK(cpu), (oldmask | mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	spin_unlock_irqrestore(&leon_irq_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static void leon_mask_irq(struct irq_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	unsigned long mask, oldmask, flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	mask = (unsigned long)data->chip_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	cpu = irq_choose_cpu(irq_data_get_affinity_mask(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	spin_lock_irqsave(&leon_irq_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	oldmask = LEON3_BYPASS_LOAD_PA(LEON_IMASK(cpu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	LEON3_BYPASS_STORE_PA(LEON_IMASK(cpu), (oldmask & ~mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	spin_unlock_irqrestore(&leon_irq_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static unsigned int leon_startup_irq(struct irq_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	irq_link(data->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	leon_unmask_irq(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static void leon_shutdown_irq(struct irq_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	leon_mask_irq(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	irq_unlink(data->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /* Used by external level sensitive IRQ handlers on the LEON: ACK IRQ ctrl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static void leon_eoi_irq(struct irq_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	unsigned long mask = (unsigned long)data->chip_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	if (mask & LEON_DO_ACK_HW)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		LEON3_BYPASS_STORE_PA(LEON_IACK, mask & ~LEON_DO_ACK_HW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static struct irq_chip leon_irq = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	.name			= "leon",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	.irq_startup		= leon_startup_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	.irq_shutdown		= leon_shutdown_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	.irq_mask		= leon_mask_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	.irq_unmask		= leon_unmask_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	.irq_eoi		= leon_eoi_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	.irq_set_affinity	= leon_set_affinity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  * Build a LEON IRQ for the edge triggered LEON IRQ controller:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  *  Edge (normal) IRQ           - handle_simple_irq, ack=DON'T-CARE, never ack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  *  Level IRQ (PCI|Level-GPIO)  - handle_fasteoi_irq, ack=1, ack after ISR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)  *  Per-CPU Edge                - handle_percpu_irq, ack=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) unsigned int leon_build_device_irq(unsigned int real_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 				    irq_flow_handler_t flow_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 				    const char *name, int do_ack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	unsigned int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	unsigned long mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	struct irq_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	irq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	mask = leon_get_irqmask(real_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (mask == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	irq = irq_alloc(real_irq, real_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (irq == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	if (do_ack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		mask |= LEON_DO_ACK_HW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	desc = irq_to_desc(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (!desc || !desc->handle_irq || desc->handle_irq == handle_bad_irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		irq_set_chip_and_handler_name(irq, &leon_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 					      flow_handler, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		irq_set_chip_data(irq, (void *)mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	return irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static unsigned int _leon_build_device_irq(struct platform_device *op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 					   unsigned int real_irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	return leon_build_device_irq(real_irq, handle_simple_irq, "edge", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) void leon_update_virq_handling(unsigned int virq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			      irq_flow_handler_t flow_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			      const char *name, int do_ack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	unsigned long mask = (unsigned long)irq_get_chip_data(virq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	mask &= ~LEON_DO_ACK_HW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if (do_ack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		mask |= LEON_DO_ACK_HW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	irq_set_chip_and_handler_name(virq, &leon_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 				      flow_handler, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	irq_set_chip_data(virq, (void *)mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static u32 leon_cycles_offset(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	u32 rld, val, ctrl, off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	rld = LEON3_BYPASS_LOAD_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx].rld);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	val = LEON3_BYPASS_LOAD_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx].val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	ctrl = LEON3_BYPASS_LOAD_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx].ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (LEON3_GPTIMER_CTRL_ISPENDING(ctrl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		val = LEON3_BYPASS_LOAD_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx].val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		off = 2 * rld - val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		off = rld - val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	return off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /* smp clockevent irq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static irqreturn_t leon_percpu_timer_ce_interrupt(int irq, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct clock_event_device *ce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	int cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	leon_clear_profile_irq(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	if (cpu == boot_cpu_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		timer_interrupt(irq, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	ce = &per_cpu(sparc32_clockevent, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	irq_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	if (ce->event_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		ce->event_handler(ce);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	irq_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) #endif /* CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) void __init leon_init_timers(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	int irq, eirq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	struct device_node *rootnp, *np, *nnp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	struct property *pp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	int icsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	int ampopts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	u32 config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	u32 ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	sparc_config.get_cycles_offset = leon_cycles_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	sparc_config.cs_period = 1000000 / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	sparc_config.features |= FEAT_L10_CLOCKSOURCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) #ifndef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	sparc_config.features |= FEAT_L10_CLOCKEVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	leondebug_irq_disable = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	leon_debug_irqout = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	master_l10_counter = (u32 __iomem *)&dummy_master_l10_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	dummy_master_l10_counter = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	rootnp = of_find_node_by_path("/ambapp0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (!rootnp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	/* Find System ID: GRLIB build ID and optional CHIP ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	pp = of_find_property(rootnp, "systemid", &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (pp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		amba_system_id = *(unsigned long *)pp->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	/* Find IRQMP IRQ Controller Registers base adr otherwise bail out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	np = of_find_node_by_name(rootnp, "GAISLER_IRQMP");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		np = of_find_node_by_name(rootnp, "01_00d");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	pp = of_find_property(np, "reg", &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	if (!pp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	leon3_irqctrl_regs = *(struct leon3_irqctrl_regs_map **)pp->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	/* Find GPTIMER Timer Registers base address otherwise bail out. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	nnp = rootnp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	np = of_find_node_by_name(nnp, "GAISLER_GPTIMER");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		np = of_find_node_by_name(nnp, "01_011");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	ampopts = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	pp = of_find_property(np, "ampopts", &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	if (pp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		ampopts = *(int *)pp->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		if (ampopts == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			/* Skip this instance, resource already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 			 * allocated by other OS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 			nnp = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 			goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	/* Select Timer-Instance on Timer Core. Default is zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	leon3_gptimer_idx = ampopts & 0x7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	pp = of_find_property(np, "reg", &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	if (pp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		leon3_gptimer_regs = *(struct leon3_gptimer_regs_map **)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 					pp->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	pp = of_find_property(np, "interrupts", &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	if (pp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		leon3_gptimer_irq = *(unsigned int *)pp->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	if (!(leon3_gptimer_regs && leon3_irqctrl_regs && leon3_gptimer_irq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	ctrl = LEON3_BYPASS_LOAD_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx].ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx].ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			      ctrl | LEON3_GPTIMER_CTRL_PENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	ctrl = LEON3_BYPASS_LOAD_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx].ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	if ((ctrl & LEON3_GPTIMER_CTRL_PENDING) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		leon3_gptimer_ackmask = ~LEON3_GPTIMER_CTRL_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		leon3_gptimer_ackmask = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx].val, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx].rld,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 				(((1000000 / HZ) - 1)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	LEON3_BYPASS_STORE_PA(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 			&leon3_gptimer_regs->e[leon3_gptimer_idx].ctrl, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	 * The IRQ controller may (if implemented) consist of multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	 * IRQ controllers, each mapped on a 4Kb boundary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	 * Each CPU may be routed to different IRQCTRLs, however
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	 * we assume that all CPUs (in SMP system) is routed to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	 * same IRQ Controller, and for non-SMP only one IRQCTRL is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	 * accessed anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	 * In AMP systems, Linux must run on CPU0 for the time being.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	icsel = LEON3_BYPASS_LOAD_PA(&leon3_irqctrl_regs->icsel[boot_cpu_id/8]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	icsel = (icsel >> ((7 - (boot_cpu_id&0x7)) * 4)) & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	leon3_irqctrl_regs += icsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	/* Mask all IRQs on boot-cpu IRQ controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	LEON3_BYPASS_STORE_PA(&leon3_irqctrl_regs->mask[boot_cpu_id], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	/* Probe extended IRQ controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	eirq = (LEON3_BYPASS_LOAD_PA(&leon3_irqctrl_regs->mpstatus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		>> 16) & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	if (eirq != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		leon_eirq_setup(eirq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		 * In SMP, sun4m adds a IPI handler to IRQ trap handler that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		 * LEON never must take, sun4d and LEON overwrites the branch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		 * with a NOP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		patchme_maybe_smp_msg[0] = 0x01000000; /* NOP out the branch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		local_ops->cache_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	config = LEON3_BYPASS_LOAD_PA(&leon3_gptimer_regs->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	if (config & (1 << LEON3_GPTIMER_SEPIRQ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		leon3_gptimer_irq += leon3_gptimer_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	else if ((config & LEON3_GPTIMER_TIMERS) > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		pr_warn("GPTIMER uses shared irqs, using other timers of the same core will fail.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	/* Install per-cpu IRQ handler for broadcasted ticker */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	irq = leon_build_device_irq(leon3_gptimer_irq, handle_percpu_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 				    "per-cpu", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	err = request_irq(irq, leon_percpu_timer_ce_interrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 			  IRQF_PERCPU | IRQF_TIMER, "timer", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	irq = _leon_build_device_irq(NULL, leon3_gptimer_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	err = request_irq(irq, timer_interrupt, IRQF_TIMER, "timer", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		pr_err("Unable to attach timer IRQ%d\n", irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		prom_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx].ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 			      LEON3_GPTIMER_EN |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 			      LEON3_GPTIMER_RL |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 			      LEON3_GPTIMER_LD |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 			      LEON3_GPTIMER_IRQEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) bad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	printk(KERN_ERR "No Timer/irqctrl found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) static void leon_clear_clock_irq(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	u32 ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	ctrl = LEON3_BYPASS_LOAD_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx].ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx].ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 			      ctrl & leon3_gptimer_ackmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static void leon_load_profile_irq(int cpu, unsigned int limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) void leon_clear_profile_irq(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) void leon_enable_irq_cpu(unsigned int irq_nr, unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	unsigned long mask, flags, *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	mask = leon_get_irqmask(irq_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	spin_lock_irqsave(&leon_irq_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	addr = (unsigned long *)LEON_IMASK(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	LEON3_BYPASS_STORE_PA(addr, (LEON3_BYPASS_LOAD_PA(addr) | mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	spin_unlock_irqrestore(&leon_irq_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) void __init leon_init_IRQ(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	sparc_config.init_timers      = leon_init_timers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	sparc_config.build_device_irq = _leon_build_device_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	sparc_config.clock_rate       = 1000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	sparc_config.clear_clock_irq  = leon_clear_clock_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	sparc_config.load_profile_irq = leon_load_profile_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }