/*-
* Copyright (c) 2007 Ruslan Ermilov and Vsevolod Lobko.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The names of the authors may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*/
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Platform-specific interrupt support for the RMI XLP, XLR, XLS
*/
/*
* do not clear these when acking EIRR
* (otherwise they get lost)
*/
#define RMIXL_EIRR_PRESERVE_MASK \
((MIPS_INT_MASK_5|MIPS_SOFT_INT_MASK) >> 8)
/*
* IRT assignments depends on the RMI chip family
* (XLS1xx vs. XLS2xx vs. XLS3xx vs. XLS6xx)
* use the right display string table for the CPU that's running.
*/
/*
* rmixl_irtnames_xlrxxx
* - use for XLRxxx
*/
static const char * const rmixl_irtnames_xlrxxx[NIRTS] = {
"pic int 0 (watchdog)", /* 0 */
"pic int 1 (timer0)", /* 1 */
"pic int 2 (timer1)", /* 2 */
"pic int 3 (timer2)", /* 3 */
"pic int 4 (timer3)", /* 4 */
"pic int 5 (timer4)", /* 5 */
"pic int 6 (timer5)", /* 6 */
"pic int 7 (timer6)", /* 7 */
"pic int 8 (timer7)", /* 8 */
"pic int 9 (uart0)", /* 9 */
"pic int 10 (uart1)", /* 10 */
"pic int 11 (i2c0)", /* 11 */
"pic int 12 (i2c1)", /* 12 */
"pic int 13 (pcmcia)", /* 13 */
"pic int 14 (gpio)", /* 14 */
"pic int 15 (hyper)", /* 15 */
"pic int 16 (pcix)", /* 16 */
"pic int 17 (gmac0)", /* 17 */
"pic int 18 (gmac1)", /* 18 */
"pic int 19 (gmac2)", /* 19 */
"pic int 20 (gmac3)", /* 20 */
"pic int 21 (xgs0)", /* 21 */
"pic int 22 (xgs1)", /* 22 */
"pic int 23 (irq23)", /* 23 */
"pic int 24 (hyper_fatal)", /* 24 */
"pic int 25 (bridge_aerr)", /* 25 */
"pic int 26 (bridge_berr)", /* 26 */
"pic int 27 (bridge_tb)", /* 27 */
"pic int 28 (bridge_nmi)", /* 28 */
"pic int 29 (bridge_sram_derr)",/* 29 */
"pic int 30 (gpio_fatal)", /* 30 */
"pic int 31 (reserved)", /* 31 */
};
/*
* rmixl_irtnames_xls2xx
* - use for XLS2xx
*/
static const char * const rmixl_irtnames_xls2xx[NIRTS] = {
"pic int 0 (watchdog)", /* 0 */
"pic int 1 (timer0)", /* 1 */
"pic int 2 (timer1)", /* 2 */
"pic int 3 (timer2)", /* 3 */
"pic int 4 (timer3)", /* 4 */
"pic int 5 (timer4)", /* 5 */
"pic int 6 (timer5)", /* 6 */
"pic int 7 (timer6)", /* 7 */
"pic int 8 (timer7)", /* 8 */
"pic int 9 (uart0)", /* 9 */
"pic int 10 (uart1)", /* 10 */
"pic int 11 (i2c0)", /* 11 */
"pic int 12 (i2c1)", /* 12 */
"pic int 13 (pcmcia)", /* 13 */
"pic int 14 (gpio_a)", /* 14 */
"pic int 15 (irq15)", /* 15 */
"pic int 16 (bridge_tb)", /* 16 */
"pic int 17 (gmac0)", /* 17 */
"pic int 18 (gmac1)", /* 18 */
"pic int 19 (gmac2)", /* 19 */
"pic int 20 (gmac3)", /* 20 */
"pic int 21 (irq21)", /* 21 */
"pic int 22 (irq22)", /* 22 */
"pic int 23 (pcie_link2)", /* 23 */
"pic int 24 (pcie_link3)", /* 24 */
"pic int 25 (bridge_err)", /* 25 */
"pic int 26 (pcie_link0)", /* 26 */
"pic int 27 (pcie_link1)", /* 27 */
"pic int 28 (irq28)", /* 28 */
"pic int 29 (pcie_err)", /* 29 */
"pic int 30 (gpio_b)", /* 30 */
"pic int 31 (usb)", /* 31 */
};
/*
* rmixl_irtnames_xls1xx
* - use for XLS1xx, XLS4xx-Lite
*/
static const char * const rmixl_irtnames_xls1xx[NIRTS] = {
"pic int 0 (watchdog)", /* 0 */
"pic int 1 (timer0)", /* 1 */
"pic int 2 (timer1)", /* 2 */
"pic int 3 (timer2)", /* 3 */
"pic int 4 (timer3)", /* 4 */
"pic int 5 (timer4)", /* 5 */
"pic int 6 (timer5)", /* 6 */
"pic int 7 (timer6)", /* 7 */
"pic int 8 (timer7)", /* 8 */
"pic int 9 (uart0)", /* 9 */
"pic int 10 (uart1)", /* 10 */
"pic int 11 (i2c0)", /* 11 */
"pic int 12 (i2c1)", /* 12 */
"pic int 13 (pcmcia)", /* 13 */
"pic int 14 (gpio_a)", /* 14 */
"pic int 15 (irq15)", /* 15 */
"pic int 16 (bridge_tb)", /* 16 */
"pic int 17 (gmac0)", /* 17 */
"pic int 18 (gmac1)", /* 18 */
"pic int 19 (gmac2)", /* 19 */
"pic int 20 (gmac3)", /* 20 */
"pic int 21 (irq21)", /* 21 */
"pic int 22 (irq22)", /* 22 */
"pic int 23 (irq23)", /* 23 */
"pic int 24 (irq24)", /* 24 */
"pic int 25 (bridge_err)", /* 25 */
"pic int 26 (pcie_link0)", /* 26 */
"pic int 27 (pcie_link1)", /* 27 */
"pic int 28 (irq28)", /* 28 */
"pic int 29 (pcie_err)", /* 29 */
"pic int 30 (gpio_b)", /* 30 */
"pic int 31 (usb)", /* 31 */
};
/*
* rmixl_irtnames_xls4xx:
* - use for XLS4xx, XLS6xx
*/
static const char * const rmixl_irtnames_xls4xx[NIRTS] = {
"pic int 0 (watchdog)", /* 0 */
"pic int 1 (timer0)", /* 1 */
"pic int 2 (timer1)", /* 2 */
"pic int 3 (timer2)", /* 3 */
"pic int 4 (timer3)", /* 4 */
"pic int 5 (timer4)", /* 5 */
"pic int 6 (timer5)", /* 6 */
"pic int 7 (timer6)", /* 7 */
"pic int 8 (timer7)", /* 8 */
"pic int 9 (uart0)", /* 9 */
"pic int 10 (uart1)", /* 10 */
"pic int 11 (i2c0)", /* 11 */
"pic int 12 (i2c1)", /* 12 */
"pic int 13 (pcmcia)", /* 13 */
"pic int 14 (gpio_a)", /* 14 */
"pic int 15 (irq15)", /* 15 */
"pic int 16 (bridge_tb)", /* 16 */
"pic int 17 (gmac0)", /* 17 */
"pic int 18 (gmac1)", /* 18 */
"pic int 19 (gmac2)", /* 19 */
"pic int 20 (gmac3)", /* 20 */
"pic int 21 (irq21)", /* 21 */
"pic int 22 (irq22)", /* 22 */
"pic int 23 (irq23)", /* 23 */
"pic int 24 (irq24)", /* 24 */
"pic int 25 (bridge_err)", /* 25 */
"pic int 26 (pcie_link0)", /* 26 */
"pic int 27 (pcie_link1)", /* 27 */
"pic int 28 (pcie_link2)", /* 28 */
"pic int 29 (pcie_link3)", /* 29 */
"pic int 30 (gpio_b)", /* 30 */
"pic int 31 (usb)", /* 31 */
};
#ifdef MULTIPROCESSOR
static int rmixl_send_ipi(struct cpu_info *, int);
static int rmixl_ipi_intr(void *);
#endif
#if defined(DIAGNOSTIC) || defined(IOINTR_DEBUG) || defined(DDB)
int rmixl_intrhand_print_subr(int);
int rmixl_intrhand_print(void);
int rmixl_irt_print(void);
void rmixl_ipl_eimr_map_print(void);
#endif
/*
* initialize (zero) all IRT Entries in the PIC
*/
for (u_int i = 0; i < NIRTS; i++) {
rmixl_irt_init(i);
}
/*
* disable watchdog NMI, timers
*
* XXX
* WATCHDOG_ENB is preserved because clearing it causes
* hang on the XLS616 (but not on the XLS408)
*/
r = RMIXL_PICREG_READ(RMIXL_PIC_CONTROL);
r &= RMIXL_PIC_CONTROL_RESV|RMIXL_PIC_CONTROL_WATCHDOG_ENB;
RMIXL_PICREG_WRITE(RMIXL_PIC_CONTROL, r);
/*
* establish vector for mips3 count/compare clock interrupt
* this ensures we enable in EIRR,
* even though cpu_intr() handles the interrupt
* note the 'mpsafe' arg here is a placeholder only
*/
void
rmixl_intr_init_clk(void)
{
const int vec = ffs(MIPS_INT_MASK_5 >> MIPS_INT_MASK_SHIFT) - 1;
switch (MIPS_PRID_IMPL(mips_options.mips_cpu_id)) {
case MIPS_XLS104:
case MIPS_XLS108:
case MIPS_XLS404LITE:
case MIPS_XLS408LITE:
name = rmixl_irtnames_xls1xx[irt];
break;
case MIPS_XLS204:
case MIPS_XLS208:
name = rmixl_irtnames_xls2xx[irt];
break;
case MIPS_XLS404:
case MIPS_XLS408:
case MIPS_XLS416:
case MIPS_XLS608:
case MIPS_XLS616:
name = rmixl_irtnames_xls4xx[irt];
break;
default:
name = rmixl_vecnames_common[RMIXL_IRT_VECTOR(irt)];
break;
}
return name;
}
/*
* rmixl_irt_thread_mask
*
* given a bitmask of cpus, return a, IRT thread mask
*/
static uint32_t
rmixl_irt_thread_mask(int cpumask)
{
uint32_t irtc0;
/*
* discount cpus not present
*/
cpumask &= cpu_present_mask;
switch (MIPS_PRID_IMPL(mips_options.mips_cpu_id)) {
case MIPS_XLS104:
case MIPS_XLS204:
case MIPS_XLS404:
case MIPS_XLS404LITE:
irtc0 = ((cpumask >> 2) << 4) | (cpumask & __BITS(1,0));
irtc0 &= (__BITS(5,4) | __BITS(1,0));
break;
case MIPS_XLS108:
case MIPS_XLS208:
case MIPS_XLS408:
case MIPS_XLS408LITE:
case MIPS_XLS608:
irtc0 = cpumask & __BITS(7,0);
break;
case MIPS_XLS416:
case MIPS_XLS616:
irtc0 = cpumask & __BITS(15,0);
break;
default:
panic("%s: unknown cpu ID %#x\n", __func__,
mips_options.mips_cpu_id);
}
#else
irtc0 = 1;
#endif /* MULTIPROCESSOR */
return irtc0;
}
/*
* rmixl_irt_init
* - initialize IRT Entry for given index
* - unmask Thread#0 in low word (assume we only have 1 thread)
*/
static void
rmixl_irt_init(int irt)
{
KASSERT(irt < NIRTS);
RMIXL_PICREG_WRITE(RMIXL_PIC_IRTENTRYC1(irt), 0); /* high word */
RMIXL_PICREG_WRITE(RMIXL_PIC_IRTENTRYC0(irt), 0); /* low word */
}
/*
* rmixl_irt_disestablish
* - invalidate IRT Entry for given index
*/
static void
rmixl_irt_disestablish(int irt)
{
KASSERT(mutex_owned(&rmixl_intr_lock));
DPRINTF(("%s: irt %d, irtc1 %#x\n", __func__, irt, 0));
rmixl_irt_init(irt);
}
/*
* rmixl_irt_establish
* - construct an IRT Entry for irt and write to PIC
*/
static void
rmixl_irt_establish(int irt, int vec, int cpumask, rmixl_intr_trigger_t trigger,
rmixl_intr_polarity_t polarity)
{
uint32_t irtc1;
uint32_t irtc0;
KASSERT(mutex_owned(&rmixl_intr_lock));
if (irt >= NIRTS)
panic("%s: bad irt %d\n", __func__, irt);
if (! RMIXL_VECTOR_IS_IRT(vec))
panic("%s: bad vec %d\n", __func__, vec);
switch (trigger) {
case RMIXL_TRIG_EDGE:
case RMIXL_TRIG_LEVEL:
break;
default:
panic("%s: bad trigger %d\n", __func__, trigger);
}
switch (polarity) {
case RMIXL_POLR_RISING:
case RMIXL_POLR_HIGH:
case RMIXL_POLR_FALLING:
case RMIXL_POLR_LOW:
break;
default:
panic("%s: bad polarity %d\n", __func__, polarity);
}
/*
* XXX IRT entries are not shared
*/
KASSERT(RMIXL_PICREG_READ(RMIXL_PIC_IRTENTRYC0(irt)) == 0);
KASSERT(RMIXL_PICREG_READ(RMIXL_PIC_IRTENTRYC1(irt)) == 0);
/*
* rmixl_intr_establish
* - used to establish an IRT-based interrupt only
*/
void *
rmixl_intr_establish(int irt, int cpumask, int ipl,
rmixl_intr_trigger_t trigger, rmixl_intr_polarity_t polarity,
int (*func)(void *), void *arg, bool mpsafe)
{
rmixl_intrhand_t *ih;
int vec;
#ifdef DIAGNOSTIC
if (rmixl_pic_init_done == 0)
panic("%s: called before rmixl_pic_init_done", __func__);
#endif
/*
* check args
*/
if (irt < 0 || irt >= NIRTS)
panic("%s: irt %d out of range, max %d",
__func__, irt, NIRTS - 1);
if (ipl <= 0 || ipl >= _IPL_N)
panic("%s: ipl %d out of range, min %d, max %d",
__func__, ipl, 1, _IPL_N - 1);
/*
* reduce eirr to
* - ints that are enabled at or below this ipl
* - exclude count/compare clock and soft ints
* they are handled elsewhere
*/
eirr &= ipl_eimr_map[ipl-1];
eirr &= ~ipl_eimr_map[ipl];
eirr &= ~((MIPS_INT_MASK_5 | MIPS_SOFT_INT_MASK) >> 8);
if (eirr == 0)
break;
/*
* ack in EIRR, and in PIC if needed,
* the irq we are about to handle
*/
rmixl_eirr_ack(eimr, vecbit, RMIXL_EIRR_PRESERVE_MASK);
if (RMIXL_VECTOR_IS_IRT(vec))
RMIXL_PICREG_WRITE(RMIXL_PIC_INTRACK,
1 << RMIXL_VECTOR_IRT(vec));
/* if the request is clear, it was previously processed */
if ((atomic_load_relaxed(&ci->ci_request_ipis) & ipi_mask) == 0)
return 0;
membar_acquire();