18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2000,2001,2002,2003,2004 Broadcom Corporation
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci#include <linux/kernel.h>
68c2ecf20Sopenharmony_ci#include <linux/init.h>
78c2ecf20Sopenharmony_ci#include <linux/linkage.h>
88c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
98c2ecf20Sopenharmony_ci#include <linux/smp.h>
108c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
118c2ecf20Sopenharmony_ci#include <linux/mm.h>
128c2ecf20Sopenharmony_ci#include <linux/kernel_stat.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <asm/errno.h>
158c2ecf20Sopenharmony_ci#include <asm/irq_regs.h>
168c2ecf20Sopenharmony_ci#include <asm/signal.h>
178c2ecf20Sopenharmony_ci#include <asm/io.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include <asm/sibyte/bcm1480_regs.h>
208c2ecf20Sopenharmony_ci#include <asm/sibyte/bcm1480_int.h>
218c2ecf20Sopenharmony_ci#include <asm/sibyte/bcm1480_scd.h>
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#include <asm/sibyte/sb1250_uart.h>
248c2ecf20Sopenharmony_ci#include <asm/sibyte/sb1250.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/*
278c2ecf20Sopenharmony_ci * These are the routines that handle all the low level interrupt stuff.
288c2ecf20Sopenharmony_ci * Actions handled here are: initialization of the interrupt map, requesting of
298c2ecf20Sopenharmony_ci * interrupt lines by handlers, dispatching if interrupts to handlers, probing
308c2ecf20Sopenharmony_ci * for interrupt lines
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI
348c2ecf20Sopenharmony_ciextern unsigned long ht_eoi_space;
358c2ecf20Sopenharmony_ci#endif
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/* Store the CPU id (not the logical number) */
388c2ecf20Sopenharmony_ciint bcm1480_irq_owner[BCM1480_NR_IRQS];
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistatic DEFINE_RAW_SPINLOCK(bcm1480_imr_lock);
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_civoid bcm1480_mask_irq(int cpu, int irq)
438c2ecf20Sopenharmony_ci{
448c2ecf20Sopenharmony_ci	unsigned long flags, hl_spacing;
458c2ecf20Sopenharmony_ci	u64 cur_ints;
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	raw_spin_lock_irqsave(&bcm1480_imr_lock, flags);
488c2ecf20Sopenharmony_ci	hl_spacing = 0;
498c2ecf20Sopenharmony_ci	if ((irq >= BCM1480_NR_IRQS_HALF) && (irq <= BCM1480_NR_IRQS)) {
508c2ecf20Sopenharmony_ci		hl_spacing = BCM1480_IMR_HL_SPACING;
518c2ecf20Sopenharmony_ci		irq -= BCM1480_NR_IRQS_HALF;
528c2ecf20Sopenharmony_ci	}
538c2ecf20Sopenharmony_ci	cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
548c2ecf20Sopenharmony_ci	cur_ints |= (((u64) 1) << irq);
558c2ecf20Sopenharmony_ci	____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
568c2ecf20Sopenharmony_ci	raw_spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
578c2ecf20Sopenharmony_ci}
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_civoid bcm1480_unmask_irq(int cpu, int irq)
608c2ecf20Sopenharmony_ci{
618c2ecf20Sopenharmony_ci	unsigned long flags, hl_spacing;
628c2ecf20Sopenharmony_ci	u64 cur_ints;
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci	raw_spin_lock_irqsave(&bcm1480_imr_lock, flags);
658c2ecf20Sopenharmony_ci	hl_spacing = 0;
668c2ecf20Sopenharmony_ci	if ((irq >= BCM1480_NR_IRQS_HALF) && (irq <= BCM1480_NR_IRQS)) {
678c2ecf20Sopenharmony_ci		hl_spacing = BCM1480_IMR_HL_SPACING;
688c2ecf20Sopenharmony_ci		irq -= BCM1480_NR_IRQS_HALF;
698c2ecf20Sopenharmony_ci	}
708c2ecf20Sopenharmony_ci	cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
718c2ecf20Sopenharmony_ci	cur_ints &= ~(((u64) 1) << irq);
728c2ecf20Sopenharmony_ci	____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
738c2ecf20Sopenharmony_ci	raw_spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
748c2ecf20Sopenharmony_ci}
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP
778c2ecf20Sopenharmony_cistatic int bcm1480_set_affinity(struct irq_data *d, const struct cpumask *mask,
788c2ecf20Sopenharmony_ci				bool force)
798c2ecf20Sopenharmony_ci{
808c2ecf20Sopenharmony_ci	unsigned int irq_dirty, irq = d->irq;
818c2ecf20Sopenharmony_ci	int i = 0, old_cpu, cpu, int_on, k;
828c2ecf20Sopenharmony_ci	u64 cur_ints;
838c2ecf20Sopenharmony_ci	unsigned long flags;
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci	i = cpumask_first_and(mask, cpu_online_mask);
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	/* Convert logical CPU to physical CPU */
888c2ecf20Sopenharmony_ci	cpu = cpu_logical_map(i);
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	/* Protect against other affinity changers and IMR manipulation */
918c2ecf20Sopenharmony_ci	raw_spin_lock_irqsave(&bcm1480_imr_lock, flags);
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci	/* Swizzle each CPU's IMR (but leave the IP selection alone) */
948c2ecf20Sopenharmony_ci	old_cpu = bcm1480_irq_owner[irq];
958c2ecf20Sopenharmony_ci	irq_dirty = irq;
968c2ecf20Sopenharmony_ci	if ((irq_dirty >= BCM1480_NR_IRQS_HALF) && (irq_dirty <= BCM1480_NR_IRQS)) {
978c2ecf20Sopenharmony_ci		irq_dirty -= BCM1480_NR_IRQS_HALF;
988c2ecf20Sopenharmony_ci	}
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	for (k=0; k<2; k++) { /* Loop through high and low interrupt mask register */
1018c2ecf20Sopenharmony_ci		cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(old_cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
1028c2ecf20Sopenharmony_ci		int_on = !(cur_ints & (((u64) 1) << irq_dirty));
1038c2ecf20Sopenharmony_ci		if (int_on) {
1048c2ecf20Sopenharmony_ci			/* If it was on, mask it */
1058c2ecf20Sopenharmony_ci			cur_ints |= (((u64) 1) << irq_dirty);
1068c2ecf20Sopenharmony_ci			____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(old_cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
1078c2ecf20Sopenharmony_ci		}
1088c2ecf20Sopenharmony_ci		bcm1480_irq_owner[irq] = cpu;
1098c2ecf20Sopenharmony_ci		if (int_on) {
1108c2ecf20Sopenharmony_ci			/* unmask for the new CPU */
1118c2ecf20Sopenharmony_ci			cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
1128c2ecf20Sopenharmony_ci			cur_ints &= ~(((u64) 1) << irq_dirty);
1138c2ecf20Sopenharmony_ci			____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
1148c2ecf20Sopenharmony_ci		}
1158c2ecf20Sopenharmony_ci	}
1168c2ecf20Sopenharmony_ci	raw_spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	return 0;
1198c2ecf20Sopenharmony_ci}
1208c2ecf20Sopenharmony_ci#endif
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci/*****************************************************************************/
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_cistatic void disable_bcm1480_irq(struct irq_data *d)
1268c2ecf20Sopenharmony_ci{
1278c2ecf20Sopenharmony_ci	unsigned int irq = d->irq;
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci	bcm1480_mask_irq(bcm1480_irq_owner[irq], irq);
1308c2ecf20Sopenharmony_ci}
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cistatic void enable_bcm1480_irq(struct irq_data *d)
1338c2ecf20Sopenharmony_ci{
1348c2ecf20Sopenharmony_ci	unsigned int irq = d->irq;
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci	bcm1480_unmask_irq(bcm1480_irq_owner[irq], irq);
1378c2ecf20Sopenharmony_ci}
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_cistatic void ack_bcm1480_irq(struct irq_data *d)
1418c2ecf20Sopenharmony_ci{
1428c2ecf20Sopenharmony_ci	unsigned int irq_dirty, irq = d->irq;
1438c2ecf20Sopenharmony_ci	u64 pending;
1448c2ecf20Sopenharmony_ci	int k;
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci	/*
1478c2ecf20Sopenharmony_ci	 * If the interrupt was an HT interrupt, now is the time to
1488c2ecf20Sopenharmony_ci	 * clear it.  NOTE: we assume the HT bridge was set up to
1498c2ecf20Sopenharmony_ci	 * deliver the interrupts to all CPUs (which makes affinity
1508c2ecf20Sopenharmony_ci	 * changing easier for us)
1518c2ecf20Sopenharmony_ci	 */
1528c2ecf20Sopenharmony_ci	irq_dirty = irq;
1538c2ecf20Sopenharmony_ci	if ((irq_dirty >= BCM1480_NR_IRQS_HALF) && (irq_dirty <= BCM1480_NR_IRQS)) {
1548c2ecf20Sopenharmony_ci		irq_dirty -= BCM1480_NR_IRQS_HALF;
1558c2ecf20Sopenharmony_ci	}
1568c2ecf20Sopenharmony_ci	for (k=0; k<2; k++) { /* Loop through high and low LDT interrupts */
1578c2ecf20Sopenharmony_ci		pending = __raw_readq(IOADDR(A_BCM1480_IMR_REGISTER(bcm1480_irq_owner[irq],
1588c2ecf20Sopenharmony_ci						R_BCM1480_IMR_LDT_INTERRUPT_H + (k*BCM1480_IMR_HL_SPACING))));
1598c2ecf20Sopenharmony_ci		pending &= ((u64)1 << (irq_dirty));
1608c2ecf20Sopenharmony_ci		if (pending) {
1618c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP
1628c2ecf20Sopenharmony_ci			int i;
1638c2ecf20Sopenharmony_ci			for (i=0; i<NR_CPUS; i++) {
1648c2ecf20Sopenharmony_ci				/*
1658c2ecf20Sopenharmony_ci				 * Clear for all CPUs so an affinity switch
1668c2ecf20Sopenharmony_ci				 * doesn't find an old status
1678c2ecf20Sopenharmony_ci				 */
1688c2ecf20Sopenharmony_ci				__raw_writeq(pending, IOADDR(A_BCM1480_IMR_REGISTER(cpu_logical_map(i),
1698c2ecf20Sopenharmony_ci								R_BCM1480_IMR_LDT_INTERRUPT_CLR_H + (k*BCM1480_IMR_HL_SPACING))));
1708c2ecf20Sopenharmony_ci			}
1718c2ecf20Sopenharmony_ci#else
1728c2ecf20Sopenharmony_ci			__raw_writeq(pending, IOADDR(A_BCM1480_IMR_REGISTER(0, R_BCM1480_IMR_LDT_INTERRUPT_CLR_H + (k*BCM1480_IMR_HL_SPACING))));
1738c2ecf20Sopenharmony_ci#endif
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci			/*
1768c2ecf20Sopenharmony_ci			 * Generate EOI.  For Pass 1 parts, EOI is a nop.  For
1778c2ecf20Sopenharmony_ci			 * Pass 2, the LDT world may be edge-triggered, but
1788c2ecf20Sopenharmony_ci			 * this EOI shouldn't hurt.  If they are
1798c2ecf20Sopenharmony_ci			 * level-sensitive, the EOI is required.
1808c2ecf20Sopenharmony_ci			 */
1818c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI
1828c2ecf20Sopenharmony_ci			if (ht_eoi_space)
1838c2ecf20Sopenharmony_ci				*(uint32_t *)(ht_eoi_space+(irq<<16)+(7<<2)) = 0;
1848c2ecf20Sopenharmony_ci#endif
1858c2ecf20Sopenharmony_ci		}
1868c2ecf20Sopenharmony_ci	}
1878c2ecf20Sopenharmony_ci	bcm1480_mask_irq(bcm1480_irq_owner[irq], irq);
1888c2ecf20Sopenharmony_ci}
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_cistatic struct irq_chip bcm1480_irq_type = {
1918c2ecf20Sopenharmony_ci	.name = "BCM1480-IMR",
1928c2ecf20Sopenharmony_ci	.irq_mask_ack = ack_bcm1480_irq,
1938c2ecf20Sopenharmony_ci	.irq_mask = disable_bcm1480_irq,
1948c2ecf20Sopenharmony_ci	.irq_unmask = enable_bcm1480_irq,
1958c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP
1968c2ecf20Sopenharmony_ci	.irq_set_affinity = bcm1480_set_affinity
1978c2ecf20Sopenharmony_ci#endif
1988c2ecf20Sopenharmony_ci};
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_civoid __init init_bcm1480_irqs(void)
2018c2ecf20Sopenharmony_ci{
2028c2ecf20Sopenharmony_ci	int i;
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci	for (i = 0; i < BCM1480_NR_IRQS; i++) {
2058c2ecf20Sopenharmony_ci		irq_set_chip_and_handler(i, &bcm1480_irq_type,
2068c2ecf20Sopenharmony_ci					 handle_level_irq);
2078c2ecf20Sopenharmony_ci		bcm1480_irq_owner[i] = 0;
2088c2ecf20Sopenharmony_ci	}
2098c2ecf20Sopenharmony_ci}
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci/*
2128c2ecf20Sopenharmony_ci *  init_IRQ is called early in the boot sequence from init/main.c.  It
2138c2ecf20Sopenharmony_ci *  is responsible for setting up the interrupt mapper and installing the
2148c2ecf20Sopenharmony_ci *  handler that will be responsible for dispatching interrupts to the
2158c2ecf20Sopenharmony_ci *  "right" place.
2168c2ecf20Sopenharmony_ci */
2178c2ecf20Sopenharmony_ci/*
2188c2ecf20Sopenharmony_ci * For now, map all interrupts to IP[2].  We could save
2198c2ecf20Sopenharmony_ci * some cycles by parceling out system interrupts to different
2208c2ecf20Sopenharmony_ci * IP lines, but keep it simple for bringup.  We'll also direct
2218c2ecf20Sopenharmony_ci * all interrupts to a single CPU; we should probably route
2228c2ecf20Sopenharmony_ci * PCI and LDT to one cpu and everything else to the other
2238c2ecf20Sopenharmony_ci * to balance the load a bit.
2248c2ecf20Sopenharmony_ci *
2258c2ecf20Sopenharmony_ci * On the second cpu, everything is set to IP5, which is
2268c2ecf20Sopenharmony_ci * ignored, EXCEPT the mailbox interrupt.  That one is
2278c2ecf20Sopenharmony_ci * set to IP[2] so it is handled.  This is needed so we
2288c2ecf20Sopenharmony_ci * can do cross-cpu function calls, as required by SMP
2298c2ecf20Sopenharmony_ci */
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci#define IMR_IP2_VAL	K_BCM1480_INT_MAP_I0
2328c2ecf20Sopenharmony_ci#define IMR_IP3_VAL	K_BCM1480_INT_MAP_I1
2338c2ecf20Sopenharmony_ci#define IMR_IP4_VAL	K_BCM1480_INT_MAP_I2
2348c2ecf20Sopenharmony_ci#define IMR_IP5_VAL	K_BCM1480_INT_MAP_I3
2358c2ecf20Sopenharmony_ci#define IMR_IP6_VAL	K_BCM1480_INT_MAP_I4
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_civoid __init arch_init_irq(void)
2388c2ecf20Sopenharmony_ci{
2398c2ecf20Sopenharmony_ci	unsigned int i, cpu;
2408c2ecf20Sopenharmony_ci	u64 tmp;
2418c2ecf20Sopenharmony_ci	unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 |
2428c2ecf20Sopenharmony_ci		STATUSF_IP1 | STATUSF_IP0;
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci	/* Default everything to IP2 */
2458c2ecf20Sopenharmony_ci	/* Start with _high registers which has no bit 0 interrupt source */
2468c2ecf20Sopenharmony_ci	for (i = 1; i < BCM1480_NR_IRQS_HALF; i++) {	/* was I0 */
2478c2ecf20Sopenharmony_ci		for (cpu = 0; cpu < 4; cpu++) {
2488c2ecf20Sopenharmony_ci			__raw_writeq(IMR_IP2_VAL,
2498c2ecf20Sopenharmony_ci				     IOADDR(A_BCM1480_IMR_REGISTER(cpu,
2508c2ecf20Sopenharmony_ci								   R_BCM1480_IMR_INTERRUPT_MAP_BASE_H) + (i << 3)));
2518c2ecf20Sopenharmony_ci		}
2528c2ecf20Sopenharmony_ci	}
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci	/* Now do _low registers */
2558c2ecf20Sopenharmony_ci	for (i = 0; i < BCM1480_NR_IRQS_HALF; i++) {
2568c2ecf20Sopenharmony_ci		for (cpu = 0; cpu < 4; cpu++) {
2578c2ecf20Sopenharmony_ci			__raw_writeq(IMR_IP2_VAL,
2588c2ecf20Sopenharmony_ci				     IOADDR(A_BCM1480_IMR_REGISTER(cpu,
2598c2ecf20Sopenharmony_ci								   R_BCM1480_IMR_INTERRUPT_MAP_BASE_L) + (i << 3)));
2608c2ecf20Sopenharmony_ci		}
2618c2ecf20Sopenharmony_ci	}
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci	init_bcm1480_irqs();
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	/*
2668c2ecf20Sopenharmony_ci	 * Map the high 16 bits of mailbox_0 registers to IP[3], for
2678c2ecf20Sopenharmony_ci	 * inter-cpu messages
2688c2ecf20Sopenharmony_ci	 */
2698c2ecf20Sopenharmony_ci	/* Was I1 */
2708c2ecf20Sopenharmony_ci	for (cpu = 0; cpu < 4; cpu++) {
2718c2ecf20Sopenharmony_ci		__raw_writeq(IMR_IP3_VAL, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MAP_BASE_H) +
2728c2ecf20Sopenharmony_ci						 (K_BCM1480_INT_MBOX_0_0 << 3)));
2738c2ecf20Sopenharmony_ci	}
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci	/* Clear the mailboxes.	 The firmware may leave them dirty */
2778c2ecf20Sopenharmony_ci	for (cpu = 0; cpu < 4; cpu++) {
2788c2ecf20Sopenharmony_ci		__raw_writeq(0xffffffffffffffffULL,
2798c2ecf20Sopenharmony_ci			     IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_MAILBOX_0_CLR_CPU)));
2808c2ecf20Sopenharmony_ci		__raw_writeq(0xffffffffffffffffULL,
2818c2ecf20Sopenharmony_ci			     IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_MAILBOX_1_CLR_CPU)));
2828c2ecf20Sopenharmony_ci	}
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci	/* Mask everything except the high 16 bit of mailbox_0 registers for all cpus */
2868c2ecf20Sopenharmony_ci	tmp = ~((u64) 0) ^ ( (((u64) 1) << K_BCM1480_INT_MBOX_0_0));
2878c2ecf20Sopenharmony_ci	for (cpu = 0; cpu < 4; cpu++) {
2888c2ecf20Sopenharmony_ci		__raw_writeq(tmp, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MASK_H)));
2898c2ecf20Sopenharmony_ci	}
2908c2ecf20Sopenharmony_ci	tmp = ~((u64) 0);
2918c2ecf20Sopenharmony_ci	for (cpu = 0; cpu < 4; cpu++) {
2928c2ecf20Sopenharmony_ci		__raw_writeq(tmp, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MASK_L)));
2938c2ecf20Sopenharmony_ci	}
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ci	/*
2968c2ecf20Sopenharmony_ci	 * Note that the timer interrupts are also mapped, but this is
2978c2ecf20Sopenharmony_ci	 * done in bcm1480_time_init().	 Also, the profiling driver
2988c2ecf20Sopenharmony_ci	 * does its own management of IP7.
2998c2ecf20Sopenharmony_ci	 */
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci	/* Enable necessary IPs, disable the rest */
3028c2ecf20Sopenharmony_ci	change_c0_status(ST0_IM, imask);
3038c2ecf20Sopenharmony_ci}
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ciextern void bcm1480_mailbox_interrupt(void);
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_cistatic inline void dispatch_ip2(void)
3088c2ecf20Sopenharmony_ci{
3098c2ecf20Sopenharmony_ci	unsigned long long mask_h, mask_l;
3108c2ecf20Sopenharmony_ci	unsigned int cpu = smp_processor_id();
3118c2ecf20Sopenharmony_ci	unsigned long base;
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci	/*
3148c2ecf20Sopenharmony_ci	 * Default...we've hit an IP[2] interrupt, which means we've got to
3158c2ecf20Sopenharmony_ci	 * check the 1480 interrupt registers to figure out what to do.	 Need
3168c2ecf20Sopenharmony_ci	 * to detect which CPU we're on, now that smp_affinity is supported.
3178c2ecf20Sopenharmony_ci	 */
3188c2ecf20Sopenharmony_ci	base = A_BCM1480_IMR_MAPPER(cpu);
3198c2ecf20Sopenharmony_ci	mask_h = __raw_readq(
3208c2ecf20Sopenharmony_ci		IOADDR(base + R_BCM1480_IMR_INTERRUPT_STATUS_BASE_H));
3218c2ecf20Sopenharmony_ci	mask_l = __raw_readq(
3228c2ecf20Sopenharmony_ci		IOADDR(base + R_BCM1480_IMR_INTERRUPT_STATUS_BASE_L));
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ci	if (mask_h) {
3258c2ecf20Sopenharmony_ci		if (mask_h ^ 1)
3268c2ecf20Sopenharmony_ci			do_IRQ(fls64(mask_h) - 1);
3278c2ecf20Sopenharmony_ci		else if (mask_l)
3288c2ecf20Sopenharmony_ci			do_IRQ(63 + fls64(mask_l));
3298c2ecf20Sopenharmony_ci	}
3308c2ecf20Sopenharmony_ci}
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ciasmlinkage void plat_irq_dispatch(void)
3338c2ecf20Sopenharmony_ci{
3348c2ecf20Sopenharmony_ci	unsigned int cpu = smp_processor_id();
3358c2ecf20Sopenharmony_ci	unsigned int pending;
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci	pending = read_c0_cause() & read_c0_status();
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci	if (pending & CAUSEF_IP4)
3408c2ecf20Sopenharmony_ci		do_IRQ(K_BCM1480_INT_TIMER_0 + cpu);
3418c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP
3428c2ecf20Sopenharmony_ci	else if (pending & CAUSEF_IP3)
3438c2ecf20Sopenharmony_ci		bcm1480_mailbox_interrupt();
3448c2ecf20Sopenharmony_ci#endif
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_ci	else if (pending & CAUSEF_IP2)
3478c2ecf20Sopenharmony_ci		dispatch_ip2();
3488c2ecf20Sopenharmony_ci}
349