Home | History | Annotate | Line # | Download | only in booke
e500_intr.c revision 1.2
      1  1.2  matt /*	$NetBSD: e500_intr.c,v 1.2 2011/01/18 01:02:52 matt Exp $	*/
      2  1.2  matt /*-
      3  1.2  matt  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
      4  1.2  matt  * All rights reserved.
      5  1.2  matt  *
      6  1.2  matt  * This code is derived from software contributed to The NetBSD Foundation
      7  1.2  matt  * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
      8  1.2  matt  * Agency and which was developed by Matt Thomas of 3am Software Foundry.
      9  1.2  matt  *
     10  1.2  matt  * This material is based upon work supported by the Defense Advanced Research
     11  1.2  matt  * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
     12  1.2  matt  * Contract No. N66001-09-C-2073.
     13  1.2  matt  * Approved for Public Release, Distribution Unlimited
     14  1.2  matt  *
     15  1.2  matt  * Redistribution and use in source and binary forms, with or without
     16  1.2  matt  * modification, are permitted provided that the following conditions
     17  1.2  matt  * are met:
     18  1.2  matt  * 1. Redistributions of source code must retain the above copyright
     19  1.2  matt  *    notice, this list of conditions and the following disclaimer.
     20  1.2  matt  * 2. Redistributions in binary form must reproduce the above copyright
     21  1.2  matt  *    notice, this list of conditions and the following disclaimer in the
     22  1.2  matt  *    documentation and/or other materials provided with the distribution.
     23  1.2  matt  *
     24  1.2  matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     25  1.2  matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     26  1.2  matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     27  1.2  matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     28  1.2  matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     29  1.2  matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     30  1.2  matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     31  1.2  matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     32  1.2  matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     33  1.2  matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     34  1.2  matt  * POSSIBILITY OF SUCH DAMAGE.
     35  1.2  matt  */
     36  1.2  matt 
     37  1.2  matt #define __INTR_PRIVATE
     38  1.2  matt 
     39  1.2  matt #include <sys/param.h>
     40  1.2  matt #include <sys/proc.h>
     41  1.2  matt #include <sys/intr.h>
     42  1.2  matt #include <sys/cpu.h>
     43  1.2  matt #include <sys/kmem.h>
     44  1.2  matt #include <sys/atomic.h>
     45  1.2  matt #include <sys/bus.h>
     46  1.2  matt 
     47  1.2  matt #include <uvm/uvm_extern.h>
     48  1.2  matt 
     49  1.2  matt #include <powerpc/spr.h>
     50  1.2  matt #include <powerpc/booke/spr.h>
     51  1.2  matt 
     52  1.2  matt #include <powerpc/booke/cpuvar.h>
     53  1.2  matt #include <powerpc/booke/e500reg.h>
     54  1.2  matt #include <powerpc/booke/e500var.h>
     55  1.2  matt #include <powerpc/booke/openpicreg.h>
     56  1.2  matt 
     57  1.2  matt #define	IPL2CTPR(ipl)		((ipl) + 15 - IPL_HIGH)
     58  1.2  matt #define CTPR2IPL(ctpr)		((ctpr) - (15 - IPL_HIGH))
     59  1.2  matt 
     60  1.2  matt #define	IST_PERCPU_P(ist)	((ist) >= IST_TIMER)
     61  1.2  matt 
     62  1.2  matt #define	IPL_SOFTMASK \
     63  1.2  matt 	    ((1 << IPL_SOFTSERIAL) | (1 << IPL_SOFTNET   )	\
     64  1.2  matt 	    |(1 << IPL_SOFTBIO   ) | (1 << IPL_SOFTCLOCK ))
     65  1.2  matt 
     66  1.2  matt #define SOFTINT2IPL_MAP \
     67  1.2  matt 	    ((IPL_SOFTSERIAL << (4*SOFTINT_SERIAL))	\
     68  1.2  matt 	    |(IPL_SOFTNET    << (4*SOFTINT_NET   ))	\
     69  1.2  matt 	    |(IPL_SOFTBIO    << (4*SOFTINT_BIO   ))	\
     70  1.2  matt 	    |(IPL_SOFTCLOCK  << (4*SOFTINT_CLOCK )))
     71  1.2  matt #define	SOFTINT2IPL(si_level)	((SOFTINT2IPL_MAP >> (4 * si_level)) & 0x0f)
     72  1.2  matt 
     73  1.2  matt struct e500_intr_irq_info {
     74  1.2  matt 	bus_addr_t irq_vpr;
     75  1.2  matt 	bus_addr_t irq_dr;
     76  1.2  matt 	u_int irq_vector;
     77  1.2  matt };
     78  1.2  matt 
     79  1.2  matt struct intr_source {
     80  1.2  matt 	int (*is_func)(void *);
     81  1.2  matt 	void *is_arg;
     82  1.2  matt 	int8_t is_ipl;
     83  1.2  matt 	uint8_t is_ist;
     84  1.2  matt 	uint8_t is_irq;
     85  1.2  matt 	bus_size_t is_vpr;
     86  1.2  matt 	bus_size_t is_dr;
     87  1.2  matt };
     88  1.2  matt 
     89  1.2  matt #define	INTR_SOURCE_INITIALIZER \
     90  1.2  matt 	{ .is_func = e500_intr_spurious, .is_arg = NULL, \
     91  1.2  matt 	.is_irq = -1, .is_ipl = IPL_NONE, .is_ist = IST_NONE, }
     92  1.2  matt 
     93  1.2  matt struct e500_intr_name {
     94  1.2  matt 	uint8_t in_irq;
     95  1.2  matt 	const char in_name[15];
     96  1.2  matt };
     97  1.2  matt 
     98  1.2  matt static const struct e500_intr_name e500_onchip_intr_names[] = {
     99  1.2  matt 	{ ISOURCE_L2, "l2" },
    100  1.2  matt 	{ ISOURCE_ECM, "ecm" },
    101  1.2  matt 	{ ISOURCE_DDR, "ddr" },
    102  1.2  matt 	{ ISOURCE_LBC, "lbc" },
    103  1.2  matt 	{ ISOURCE_DMA_CHAN1, "dma-chan1" },
    104  1.2  matt 	{ ISOURCE_DMA_CHAN2, "dma-chan2" },
    105  1.2  matt 	{ ISOURCE_DMA_CHAN3, "dma-chan3" },
    106  1.2  matt 	{ ISOURCE_DMA_CHAN4, "dma-chan4" },
    107  1.2  matt 	{ ISOURCE_PCI1, "pci1" },
    108  1.2  matt 	{ ISOURCE_PCIEX2, "pcie2" },
    109  1.2  matt 	{ ISOURCE_PCIEX	, "pcie1" },
    110  1.2  matt 	{ ISOURCE_PCIEX3, "pcie3" },
    111  1.2  matt 	{ ISOURCE_ETSEC1_TX, "etsec1-tx" },
    112  1.2  matt 	{ ISOURCE_ETSEC1_RX, "etsec1-rx" },
    113  1.2  matt 	{ ISOURCE_ETSEC3_TX, "etsec3-tx" },
    114  1.2  matt 	{ ISOURCE_ETSEC3_RX, "etsec3-rx" },
    115  1.2  matt 	{ ISOURCE_ETSEC3_ERR, "etsec3-err" },
    116  1.2  matt 	{ ISOURCE_ETSEC1_ERR, "etsec1-err" },
    117  1.2  matt 	{ ISOURCE_ETSEC2_TX, "etsec2-tx" },
    118  1.2  matt 	{ ISOURCE_ETSEC2_RX, "etsec2-rx" },
    119  1.2  matt 	{ ISOURCE_ETSEC4_TX, "etsec4-tx" },
    120  1.2  matt 	{ ISOURCE_ETSEC4_RX, "etsec4-rx" },
    121  1.2  matt 	{ ISOURCE_ETSEC4_ERR, "etsec4-err" },
    122  1.2  matt 	{ ISOURCE_ETSEC2_ERR, "etsec2-err" },
    123  1.2  matt 	{ ISOURCE_DUART, "duart" },
    124  1.2  matt 	{ ISOURCE_I2C, "i2c" },
    125  1.2  matt 	{ ISOURCE_PERFMON, "perfmon" },
    126  1.2  matt 	{ ISOURCE_SECURITY1, "sec1" },
    127  1.2  matt 	{ ISOURCE_SRIO_EWPU, "srio-ewpu" },
    128  1.2  matt 	{ ISOURCE_SRIO_ODBELL, "srio-odbell" },
    129  1.2  matt 	{ ISOURCE_SRIO_IDBELL, "srio-idbell" },
    130  1.2  matt 	{ ISOURCE_SRIO_OMU1, "srio-omu1" },
    131  1.2  matt 	{ ISOURCE_SRIO_IMU1, "srio-imu1" },
    132  1.2  matt 	{ ISOURCE_SRIO_OMU2, "srio-omu2" },
    133  1.2  matt 	{ ISOURCE_SRIO_IMU2, "srio-imu2" },
    134  1.2  matt 	{ 0, "" },
    135  1.2  matt };
    136  1.2  matt 
    137  1.2  matt const struct e500_intr_name mpc8548_external_intr_names[] = {
    138  1.2  matt 	{ 0, "" },
    139  1.2  matt };
    140  1.2  matt 
    141  1.2  matt const struct e500_intr_name mpc8536_external_intr_names[] = {
    142  1.2  matt 	{ 0, "" },
    143  1.2  matt };
    144  1.2  matt 
    145  1.2  matt const struct e500_intr_name mpc8572_external_intr_names[] = {
    146  1.2  matt 	{ 0, "" },
    147  1.2  matt };
    148  1.2  matt 
    149  1.2  matt const struct e500_intr_name mpc8548_onchip_intr_names[] = {
    150  1.2  matt 	{ ISOURCE_PCI1, "pci1" },
    151  1.2  matt 	{ ISOURCE_PCI2, "pci2" },
    152  1.2  matt 	{ 0, "" },
    153  1.2  matt };
    154  1.2  matt 
    155  1.2  matt const struct e500_intr_name mpc8544_onchip_intr_names[] = {
    156  1.2  matt 	{ 0, "" },
    157  1.2  matt };
    158  1.2  matt 
    159  1.2  matt const struct e500_intr_name mpc8536_onchip_intr_names[] = {
    160  1.2  matt 	{ ISOURCE_USB1, "usb1" },
    161  1.2  matt 	{ ISOURCE_SATA2, "sata2" },
    162  1.2  matt 	{ ISOURCE_USB2, "usb2" },
    163  1.2  matt 	{ ISOURCE_SECURITY2, "sec2" },
    164  1.2  matt 	{ ISOURCE_SPI, "spi" },
    165  1.2  matt 	{ ISOURCE_USB3, "usb3" },
    166  1.2  matt 	{ ISOURCE_ETSEC1_PTP, "etsec1-ptp" },
    167  1.2  matt 	{ ISOURCE_ETSEC3_PTP, "etsec3-ptp" },
    168  1.2  matt 	{ ISOURCE_ESDHC, "esdhc" },
    169  1.2  matt 	{ ISOURCE_SATA1, "sata1" },
    170  1.2  matt 	{ 0, "" },
    171  1.2  matt };
    172  1.2  matt 
    173  1.2  matt const struct e500_intr_name mpc8572_onchip_intr_names[] = {
    174  1.2  matt 	{ ISOURCE_PCIEX3_MPC8572, "pcie3" },
    175  1.2  matt 	{ ISOURCE_FEC, "fec" },
    176  1.2  matt 	{ ISOURCE_GPIO, "gpio" },
    177  1.2  matt 	{ ISOURCE_PME_GENERAL, "pme" },
    178  1.2  matt 	{ ISOURCE_SECURITY2, "sec2" },
    179  1.2  matt 	{ ISOURCE_TLU1, "tlu1" },
    180  1.2  matt 	{ ISOURCE_TLU2, "tlu2" },
    181  1.2  matt 	{ ISOURCE_PME_CHAN1, "pme-chan1" },
    182  1.2  matt 	{ ISOURCE_PME_CHAN2, "pme-chan2" },
    183  1.2  matt 	{ ISOURCE_PME_CHAN3, "pme-chan3" },
    184  1.2  matt 	{ ISOURCE_PME_CHAN4, "pme-chan4" },
    185  1.2  matt 	{ ISOURCE_ETSEC1_PTP, "etsec1-ptp" },
    186  1.2  matt 	{ ISOURCE_ETSEC2_PTP, "etsec2-ptp" },
    187  1.2  matt 	{ ISOURCE_ETSEC3_PTP, "etsec3-ptp" },
    188  1.2  matt 	{ ISOURCE_ETSEC4_PTP, "etsec4-ptp" },
    189  1.2  matt 	{ ISOURCE_DMA2_CHAN1, "dma2-chan1" },
    190  1.2  matt 	{ ISOURCE_DMA2_CHAN2, "dma2-chan2" },
    191  1.2  matt 	{ ISOURCE_DMA2_CHAN3, "dma2-chan3" },
    192  1.2  matt 	{ ISOURCE_DMA2_CHAN4, "dma2-chan4" },
    193  1.2  matt 	{ 0, "" },
    194  1.2  matt };
    195  1.2  matt 
    196  1.2  matt static const struct e500_intr_name e500_msigroup_intr_names[] = {
    197  1.2  matt 	{ 0, "msigroup0" },
    198  1.2  matt 	{ 1, "msigroup1" },
    199  1.2  matt 	{ 2, "msigroup2" },
    200  1.2  matt 	{ 3, "msigroup3" },
    201  1.2  matt 	{ 4, "msigroup4" },
    202  1.2  matt 	{ 5, "msigroup5" },
    203  1.2  matt 	{ 6, "msigroup6" },
    204  1.2  matt 	{ 7, "msigroup7" },
    205  1.2  matt 	{ 0, "" },
    206  1.2  matt };
    207  1.2  matt 
    208  1.2  matt static const struct e500_intr_name e500_timer_intr_names[] = {
    209  1.2  matt 	{ 0, "timer0" },
    210  1.2  matt 	{ 1, "timer1" },
    211  1.2  matt 	{ 2, "timer2" },
    212  1.2  matt 	{ 3, "timer3" },
    213  1.2  matt 	{ 0, "" },
    214  1.2  matt };
    215  1.2  matt 
    216  1.2  matt static const struct e500_intr_name e500_ipi_intr_names[] = {
    217  1.2  matt 	{ 0, "ipi0" },
    218  1.2  matt 	{ 1, "ipi1" },
    219  1.2  matt 	{ 2, "ipi2" },
    220  1.2  matt 	{ 3, "ipi3" },
    221  1.2  matt 	{ 0, "" },
    222  1.2  matt };
    223  1.2  matt 
    224  1.2  matt static const struct e500_intr_name e500_mi_intr_names[] = {
    225  1.2  matt 	{ 0, "mi0" },
    226  1.2  matt 	{ 1, "mi1" },
    227  1.2  matt 	{ 2, "mi2" },
    228  1.2  matt 	{ 3, "mi3" },
    229  1.2  matt 	{ 0, "" },
    230  1.2  matt };
    231  1.2  matt 
    232  1.2  matt struct e500_intr_info {
    233  1.2  matt 	u_int ii_external_sources;
    234  1.2  matt 	uint32_t ii_onchip_bitmap[2];
    235  1.2  matt 	u_int ii_onchip_sources;
    236  1.2  matt 	u_int ii_msigroup_sources;
    237  1.2  matt 	u_int ii_ipi_sources;			/* per-cpu */
    238  1.2  matt 	u_int ii_timer_sources;			/* per-cpu */
    239  1.2  matt 	u_int ii_mi_sources;			/* per-cpu */
    240  1.2  matt 	u_int ii_percpu_sources;
    241  1.2  matt 	const struct e500_intr_name *ii_external_intr_names;
    242  1.2  matt 	const struct e500_intr_name *ii_onchip_intr_names;
    243  1.2  matt 	u_int8_t ii_ist_vectors[IST_MAX+1];
    244  1.2  matt };
    245  1.2  matt 
    246  1.2  matt static kmutex_t e500_intr_lock __aligned(32);
    247  1.2  matt static struct e500_intr_info e500_intr_info;
    248  1.2  matt 
    249  1.2  matt static const struct e500_intr_info mpc8548_intr_info = {
    250  1.2  matt 	.ii_external_sources = MPC8548_EXTERNALSOURCES,
    251  1.2  matt 	.ii_onchip_bitmap = MPC8548_ONCHIPBITMAP,
    252  1.2  matt 	.ii_onchip_sources = MPC8548_ONCHIPSOURCES,
    253  1.2  matt 	.ii_msigroup_sources = MPC8548_MSIGROUPSOURCES,
    254  1.2  matt 	.ii_timer_sources = MPC8548_TIMERSOURCES,
    255  1.2  matt 	.ii_ipi_sources = MPC8548_IPISOURCES,
    256  1.2  matt 	.ii_mi_sources = MPC8548_MISOURCES,
    257  1.2  matt 	.ii_percpu_sources = MPC8548_TIMERSOURCES
    258  1.2  matt 	    + MPC8548_IPISOURCES + MPC8548_MISOURCES,
    259  1.2  matt 	.ii_external_intr_names = mpc8548_external_intr_names,
    260  1.2  matt 	.ii_onchip_intr_names = mpc8548_onchip_intr_names,
    261  1.2  matt 	.ii_ist_vectors = {
    262  1.2  matt 		[IST_NONE]		= ~0,
    263  1.2  matt 		[IST_EDGE]		= 0,
    264  1.2  matt 		[IST_LEVEL_LOW]		= 0,
    265  1.2  matt 		[IST_LEVEL_HIGH]	= 0,
    266  1.2  matt 		[IST_ONCHIP]		= MPC8548_EXTERNALSOURCES,
    267  1.2  matt 		[IST_MSIGROUP]		= MPC8548_EXTERNALSOURCES
    268  1.2  matt 					    + MPC8548_ONCHIPSOURCES,
    269  1.2  matt 		[IST_TIMER]		= MPC8548_EXTERNALSOURCES
    270  1.2  matt 					    + MPC8548_ONCHIPSOURCES
    271  1.2  matt 					    + MPC8548_MSIGROUPSOURCES,
    272  1.2  matt 		[IST_IPI]		= MPC8548_EXTERNALSOURCES
    273  1.2  matt 					    + MPC8548_ONCHIPSOURCES
    274  1.2  matt 					    + MPC8548_MSIGROUPSOURCES
    275  1.2  matt 					    + MPC8548_TIMERSOURCES,
    276  1.2  matt 		[IST_MI]		= MPC8548_EXTERNALSOURCES
    277  1.2  matt 					    + MPC8548_ONCHIPSOURCES
    278  1.2  matt 					    + MPC8548_MSIGROUPSOURCES
    279  1.2  matt 					    + MPC8548_TIMERSOURCES
    280  1.2  matt 					    + MPC8548_IPISOURCES,
    281  1.2  matt 		[IST_MAX]		= MPC8548_EXTERNALSOURCES
    282  1.2  matt 					    + MPC8548_ONCHIPSOURCES
    283  1.2  matt 					    + MPC8548_MSIGROUPSOURCES
    284  1.2  matt 					    + MPC8548_TIMERSOURCES
    285  1.2  matt 					    + MPC8548_IPISOURCES
    286  1.2  matt 					    + MPC8548_MISOURCES,
    287  1.2  matt 	},
    288  1.2  matt };
    289  1.2  matt 
    290  1.2  matt static const struct e500_intr_info mpc8536_intr_info = {
    291  1.2  matt 	.ii_external_sources = MPC8536_EXTERNALSOURCES,
    292  1.2  matt 	.ii_onchip_bitmap = MPC8536_ONCHIPBITMAP,
    293  1.2  matt 	.ii_onchip_sources = MPC8536_ONCHIPSOURCES,
    294  1.2  matt 	.ii_msigroup_sources = MPC8536_MSIGROUPSOURCES,
    295  1.2  matt 	.ii_timer_sources = MPC8536_TIMERSOURCES,
    296  1.2  matt 	.ii_ipi_sources = MPC8536_IPISOURCES,
    297  1.2  matt 	.ii_mi_sources = MPC8536_MISOURCES,
    298  1.2  matt 	.ii_percpu_sources = MPC8536_TIMERSOURCES
    299  1.2  matt 	    + MPC8536_IPISOURCES + MPC8536_MISOURCES,
    300  1.2  matt 	.ii_external_intr_names = mpc8536_external_intr_names,
    301  1.2  matt 	.ii_onchip_intr_names = mpc8536_onchip_intr_names,
    302  1.2  matt 	.ii_ist_vectors = {
    303  1.2  matt 		[IST_NONE]		= ~0,
    304  1.2  matt 		[IST_EDGE]		= 0,
    305  1.2  matt 		[IST_LEVEL_LOW]		= 0,
    306  1.2  matt 		[IST_LEVEL_HIGH]	= 0,
    307  1.2  matt 		[IST_ONCHIP]		= MPC8536_EXTERNALSOURCES,
    308  1.2  matt 		[IST_MSIGROUP]		= MPC8536_EXTERNALSOURCES
    309  1.2  matt 					    + MPC8536_ONCHIPSOURCES,
    310  1.2  matt 		[IST_TIMER]		= MPC8536_EXTERNALSOURCES
    311  1.2  matt 					    + MPC8536_ONCHIPSOURCES
    312  1.2  matt 					    + MPC8536_MSIGROUPSOURCES,
    313  1.2  matt 		[IST_IPI]		= MPC8536_EXTERNALSOURCES
    314  1.2  matt 					    + MPC8536_ONCHIPSOURCES
    315  1.2  matt 					    + MPC8536_MSIGROUPSOURCES
    316  1.2  matt 					    + MPC8536_TIMERSOURCES,
    317  1.2  matt 		[IST_MI]		= MPC8536_EXTERNALSOURCES
    318  1.2  matt 					    + MPC8536_ONCHIPSOURCES
    319  1.2  matt 					    + MPC8536_MSIGROUPSOURCES
    320  1.2  matt 					    + MPC8536_TIMERSOURCES
    321  1.2  matt 					    + MPC8536_IPISOURCES,
    322  1.2  matt 		[IST_MAX]		= MPC8536_EXTERNALSOURCES
    323  1.2  matt 					    + MPC8536_ONCHIPSOURCES
    324  1.2  matt 					    + MPC8536_MSIGROUPSOURCES
    325  1.2  matt 					    + MPC8536_TIMERSOURCES
    326  1.2  matt 					    + MPC8536_IPISOURCES
    327  1.2  matt 					    + MPC8536_MISOURCES,
    328  1.2  matt 	},
    329  1.2  matt };
    330  1.2  matt 
    331  1.2  matt static const struct e500_intr_info mpc8572_intr_info = {
    332  1.2  matt 	.ii_external_sources = MPC8572_EXTERNALSOURCES,
    333  1.2  matt 	.ii_onchip_bitmap = MPC8572_ONCHIPBITMAP,
    334  1.2  matt 	.ii_onchip_sources = MPC8572_ONCHIPSOURCES,
    335  1.2  matt 	.ii_msigroup_sources = MPC8572_MSIGROUPSOURCES,
    336  1.2  matt 	.ii_timer_sources = MPC8572_TIMERSOURCES,
    337  1.2  matt 	.ii_ipi_sources = MPC8572_IPISOURCES,
    338  1.2  matt 	.ii_mi_sources = MPC8572_MISOURCES,
    339  1.2  matt 	.ii_percpu_sources = MPC8572_TIMERSOURCES
    340  1.2  matt 	    + MPC8572_IPISOURCES + MPC8572_MISOURCES,
    341  1.2  matt 	.ii_external_intr_names = mpc8572_external_intr_names,
    342  1.2  matt 	.ii_onchip_intr_names = mpc8572_onchip_intr_names,
    343  1.2  matt 	.ii_ist_vectors = {
    344  1.2  matt 		[IST_NONE]		= ~0,
    345  1.2  matt 		[IST_EDGE]		= 0,
    346  1.2  matt 		[IST_LEVEL_LOW]		= 0,
    347  1.2  matt 		[IST_LEVEL_HIGH]	= 0,
    348  1.2  matt 		[IST_ONCHIP]		= MPC8572_EXTERNALSOURCES,
    349  1.2  matt 		[IST_MSIGROUP]		= MPC8572_EXTERNALSOURCES
    350  1.2  matt 					    + MPC8572_ONCHIPSOURCES,
    351  1.2  matt 		[IST_TIMER]		= MPC8572_EXTERNALSOURCES
    352  1.2  matt 					    + MPC8572_ONCHIPSOURCES
    353  1.2  matt 					    + MPC8572_MSIGROUPSOURCES,
    354  1.2  matt 		[IST_IPI]		= MPC8572_EXTERNALSOURCES
    355  1.2  matt 					    + MPC8572_ONCHIPSOURCES
    356  1.2  matt 					    + MPC8572_MSIGROUPSOURCES
    357  1.2  matt 					    + MPC8572_TIMERSOURCES,
    358  1.2  matt 		[IST_MI]		= MPC8572_EXTERNALSOURCES
    359  1.2  matt 					    + MPC8572_ONCHIPSOURCES
    360  1.2  matt 					    + MPC8572_MSIGROUPSOURCES
    361  1.2  matt 					    + MPC8572_TIMERSOURCES
    362  1.2  matt 					    + MPC8572_IPISOURCES,
    363  1.2  matt 		[IST_MAX]		= MPC8572_EXTERNALSOURCES
    364  1.2  matt 					    + MPC8572_ONCHIPSOURCES
    365  1.2  matt 					    + MPC8572_MSIGROUPSOURCES
    366  1.2  matt 					    + MPC8572_TIMERSOURCES
    367  1.2  matt 					    + MPC8572_IPISOURCES
    368  1.2  matt 					    + MPC8572_MISOURCES,
    369  1.2  matt 	},
    370  1.2  matt };
    371  1.2  matt 
    372  1.2  matt static const char ist_names[][12] = {
    373  1.2  matt 	[IST_NONE] = "none",
    374  1.2  matt 	[IST_EDGE] = "edge",
    375  1.2  matt 	[IST_LEVEL_LOW] = "level-",
    376  1.2  matt 	[IST_LEVEL_HIGH] = "level+",
    377  1.2  matt 	[IST_MSI] = "msi",
    378  1.2  matt 	[IST_ONCHIP] = "onchip",
    379  1.2  matt 	[IST_MSIGROUP] = "msigroup",
    380  1.2  matt 	[IST_TIMER] = "timer",
    381  1.2  matt 	[IST_IPI] = "ipi",
    382  1.2  matt 	[IST_MI] = "msgint",
    383  1.2  matt };
    384  1.2  matt 
    385  1.2  matt static struct intr_source *e500_intr_sources;
    386  1.2  matt static const struct intr_source *e500_intr_last_source;
    387  1.2  matt 
    388  1.2  matt static void 	*e500_intr_establish(int, int, int, int (*)(void *), void *);
    389  1.2  matt static void 	e500_intr_disestablish(void *);
    390  1.2  matt static void 	e500_intr_cpu_init(struct cpu_info *ci);
    391  1.2  matt static void 	e500_intr_init(void);
    392  1.2  matt static const char *e500_intr_string(int, int);
    393  1.2  matt static void 	e500_critintr(struct trapframe *tf);
    394  1.2  matt static void 	e500_decrintr(struct trapframe *tf);
    395  1.2  matt static void 	e500_extintr(struct trapframe *tf);
    396  1.2  matt static void 	e500_fitintr(struct trapframe *tf);
    397  1.2  matt static void 	e500_wdogintr(struct trapframe *tf);
    398  1.2  matt static void	e500_spl0(void);
    399  1.2  matt static int 	e500_splraise(int);
    400  1.2  matt static void 	e500_splx(int);
    401  1.2  matt #ifdef __HAVE_FAST_SOFTINTS
    402  1.2  matt static void 	e500_softint_init_md(lwp_t *l, u_int si_level, uintptr_t *machdep_p);
    403  1.2  matt static void 	e500_softint_trigger(uintptr_t machdep);
    404  1.2  matt #endif
    405  1.2  matt 
    406  1.2  matt const struct intrsw e500_intrsw = {
    407  1.2  matt 	.intrsw_establish = e500_intr_establish,
    408  1.2  matt 	.intrsw_disestablish = e500_intr_disestablish,
    409  1.2  matt 	.intrsw_init = e500_intr_init,
    410  1.2  matt 	.intrsw_cpu_init = e500_intr_cpu_init,
    411  1.2  matt 	.intrsw_string = e500_intr_string,
    412  1.2  matt 
    413  1.2  matt 	.intrsw_critintr = e500_critintr,
    414  1.2  matt 	.intrsw_decrintr = e500_decrintr,
    415  1.2  matt 	.intrsw_extintr = e500_extintr,
    416  1.2  matt 	.intrsw_fitintr = e500_fitintr,
    417  1.2  matt 	.intrsw_wdogintr = e500_wdogintr,
    418  1.2  matt 
    419  1.2  matt 	.intrsw_splraise = e500_splraise,
    420  1.2  matt 	.intrsw_splx = e500_splx,
    421  1.2  matt 	.intrsw_spl0 = e500_spl0,
    422  1.2  matt 
    423  1.2  matt #ifdef __HAVE_FAST_SOFTINTS
    424  1.2  matt 	.intrsw_softint_init_md = e500_softint_init_md,
    425  1.2  matt 	.intrsw_softint_trigger = e500_softint_trigger,
    426  1.2  matt #endif
    427  1.2  matt };
    428  1.2  matt 
    429  1.2  matt static inline uint32_t
    430  1.2  matt openpic_read(struct cpu_softc *cpu, bus_size_t offset)
    431  1.2  matt {
    432  1.2  matt 
    433  1.2  matt 	return bus_space_read_4(cpu->cpu_bst, cpu->cpu_bsh,
    434  1.2  matt 	    OPENPIC_BASE + offset);
    435  1.2  matt }
    436  1.2  matt 
    437  1.2  matt static inline void
    438  1.2  matt openpic_write(struct cpu_softc *cpu, bus_size_t offset, uint32_t val)
    439  1.2  matt {
    440  1.2  matt 
    441  1.2  matt 	return bus_space_write_4(cpu->cpu_bst, cpu->cpu_bsh,
    442  1.2  matt 	    OPENPIC_BASE + offset, val);
    443  1.2  matt }
    444  1.2  matt 
    445  1.2  matt static const char *
    446  1.2  matt e500_intr_external_name_lookup(int irq)
    447  1.2  matt {
    448  1.2  matt 	prop_array_t extirqs = board_info_get_object("external-irqs");
    449  1.2  matt 	prop_string_t irqname = prop_array_get(extirqs, irq);
    450  1.2  matt 	KASSERT(irqname != NULL);
    451  1.2  matt 	KASSERT(prop_object_type(irqname) == PROP_TYPE_STRING);
    452  1.2  matt 
    453  1.2  matt 	return prop_string_cstring_nocopy(irqname);
    454  1.2  matt }
    455  1.2  matt 
    456  1.2  matt static const char *
    457  1.2  matt e500_intr_name_lookup(const struct e500_intr_name *names, int irq)
    458  1.2  matt {
    459  1.2  matt 	for (; names->in_name[0] != '\0'; names++) {
    460  1.2  matt 		if (names->in_irq == irq)
    461  1.2  matt 			return names->in_name;
    462  1.2  matt 	}
    463  1.2  matt 
    464  1.2  matt 	return NULL;
    465  1.2  matt }
    466  1.2  matt 
    467  1.2  matt static const char *
    468  1.2  matt e500_intr_onchip_name_lookup(int irq)
    469  1.2  matt {
    470  1.2  matt 	const char *name;
    471  1.2  matt 
    472  1.2  matt 	return e500_intr_name_lookup(e500_intr_info.ii_onchip_intr_names, irq);
    473  1.2  matt 	if (name != NULL)
    474  1.2  matt 		return name;
    475  1.2  matt 
    476  1.2  matt 	name = e500_intr_name_lookup(e500_onchip_intr_names, irq);
    477  1.2  matt }
    478  1.2  matt 
    479  1.2  matt #ifdef __HAVE_FAST_SOFTINTS
    480  1.2  matt static inline void
    481  1.2  matt e500_softint_deliver(struct cpu_info *ci, struct cpu_softc *cpu,
    482  1.2  matt 	int ipl, int si_level)
    483  1.2  matt {
    484  1.2  matt 	KASSERT(ci->ci_data.cpu_softints & (1 << ipl));
    485  1.2  matt 	ci->ci_data.cpu_softints ^= 1 << ipl;
    486  1.2  matt 	softint_fast_dispatch(cpu->cpu_softlwps[si_level], ipl);
    487  1.2  matt 	KASSERT(cpu->cpu_softlwps[si_level]->l_ctxswtch == 0);
    488  1.2  matt 	KASSERTMSG(ci->ci_cpl == IPL_HIGH,
    489  1.2  matt 	    ("%s: cpl (%d) != HIGH", __func__, ci->ci_cpl));
    490  1.2  matt }
    491  1.2  matt 
    492  1.2  matt static inline void
    493  1.2  matt e500_softint(struct cpu_info *ci, struct cpu_softc *cpu, int old_ipl)
    494  1.2  matt {
    495  1.2  matt 	const u_int softint_mask = (IPL_SOFTMASK << old_ipl) & IPL_SOFTMASK;
    496  1.2  matt 	u_int softints;
    497  1.2  matt 
    498  1.2  matt 	KASSERT(ci->ci_mtx_count == 0);
    499  1.2  matt 	KASSERT(ci->ci_cpl == IPL_HIGH);
    500  1.2  matt 	while ((softints = (ci->ci_data.cpu_softints & softint_mask)) != 0) {
    501  1.2  matt 		KASSERT(old_ipl < IPL_SOFTSERIAL);
    502  1.2  matt 		if (softints & (1 << IPL_SOFTSERIAL)) {
    503  1.2  matt 			e500_softint_deliver(ci, cpu, IPL_SOFTSERIAL,
    504  1.2  matt 			    SOFTINT_SERIAL);
    505  1.2  matt 			continue;
    506  1.2  matt 		}
    507  1.2  matt 		KASSERT(old_ipl < IPL_SOFTNET);
    508  1.2  matt 		if (softints & (1 << IPL_SOFTNET)) {
    509  1.2  matt 			e500_softint_deliver(ci, cpu, IPL_SOFTNET,
    510  1.2  matt 			    SOFTINT_NET);
    511  1.2  matt 			continue;
    512  1.2  matt 		}
    513  1.2  matt 		KASSERT(old_ipl < IPL_SOFTBIO);
    514  1.2  matt 		if (softints & (1 << IPL_SOFTBIO)) {
    515  1.2  matt 			e500_softint_deliver(ci, cpu, IPL_SOFTBIO,
    516  1.2  matt 			    SOFTINT_BIO);
    517  1.2  matt 			continue;
    518  1.2  matt 		}
    519  1.2  matt 		KASSERT(old_ipl < IPL_SOFTCLOCK);
    520  1.2  matt 		if (softints & (1 << IPL_SOFTCLOCK)) {
    521  1.2  matt 			e500_softint_deliver(ci, cpu, IPL_SOFTCLOCK,
    522  1.2  matt 			    SOFTINT_CLOCK);
    523  1.2  matt 			continue;
    524  1.2  matt 		}
    525  1.2  matt 	}
    526  1.2  matt }
    527  1.2  matt #endif /* __HAVE_FAST_SOFTINTS */
    528  1.2  matt 
    529  1.2  matt static inline void
    530  1.2  matt e500_splset(struct cpu_info *ci, int ipl)
    531  1.2  matt {
    532  1.2  matt 	struct cpu_softc * const cpu = ci->ci_softc;
    533  1.2  matt 	//KASSERT(!cpu_intr_p() || ipl >= IPL_VM);
    534  1.2  matt 	KASSERT((curlwp->l_pflag & LP_INTR) == 0 || ipl != IPL_NONE);
    535  1.2  matt #if 0
    536  1.2  matt 	u_int ctpr = ipl;
    537  1.2  matt 	KASSERT(openpic_read(cpu, OPENPIC_CTPR) == ci->ci_cpl);
    538  1.2  matt #elif 0
    539  1.2  matt 	u_int old_ctpr = (ci->ci_cpl >= IPL_VM ? 15 : ci->ci_cpl);
    540  1.2  matt 	u_int ctpr = (ipl >= IPL_VM ? 15 : ipl);
    541  1.2  matt 	KASSERT(openpic_read(cpu, OPENPIC_CTPR) == old_ctpr);
    542  1.2  matt #else
    543  1.2  matt 	u_int old_ctpr = IPL2CTPR(ci->ci_cpl);
    544  1.2  matt 	u_int ctpr = IPL2CTPR(ipl);
    545  1.2  matt 	KASSERT(openpic_read(cpu, OPENPIC_CTPR) == old_ctpr);
    546  1.2  matt #endif
    547  1.2  matt 	openpic_write(cpu, OPENPIC_CTPR, ctpr);
    548  1.2  matt 	KASSERT(openpic_read(cpu, OPENPIC_CTPR) == ctpr);
    549  1.2  matt 	ci->ci_cpl = ipl;
    550  1.2  matt }
    551  1.2  matt 
    552  1.2  matt static void
    553  1.2  matt e500_spl0(void)
    554  1.2  matt {
    555  1.2  matt 	struct cpu_info * const ci = curcpu();
    556  1.2  matt 
    557  1.2  matt 	wrtee(0);
    558  1.2  matt 
    559  1.2  matt #ifdef __HAVE_FAST_SOFTINTS
    560  1.2  matt 	if (__predict_false(ci->ci_data.cpu_softints != 0)) {
    561  1.2  matt 		e500_splset(ci, IPL_HIGH);
    562  1.2  matt 		e500_softint(ci, ci->ci_softc, IPL_NONE);
    563  1.2  matt 	}
    564  1.2  matt #endif /* __HAVE_FAST_SOFTINTS */
    565  1.2  matt 	e500_splset(ci, IPL_NONE);
    566  1.2  matt 
    567  1.2  matt 	wrtee(PSL_EE);
    568  1.2  matt }
    569  1.2  matt 
    570  1.2  matt static void
    571  1.2  matt e500_splx(int ipl)
    572  1.2  matt {
    573  1.2  matt 	struct cpu_info * const ci = curcpu();
    574  1.2  matt 	const int old_ipl = ci->ci_cpl;
    575  1.2  matt 
    576  1.2  matt 	KASSERT(mfmsr() & PSL_CE);
    577  1.2  matt 
    578  1.2  matt 	if (ipl == old_ipl)
    579  1.2  matt 		return;
    580  1.2  matt 
    581  1.2  matt 	if (__predict_false(ipl > old_ipl)) {
    582  1.2  matt 		printf("%s: %p: cpl=%u: ignoring splx(%u) to raise ipl\n",
    583  1.2  matt 		    __func__, __builtin_return_address(0), old_ipl, ipl);
    584  1.2  matt 		if (old_ipl == IPL_NONE)
    585  1.2  matt 			Debugger();
    586  1.2  matt 	}
    587  1.2  matt 
    588  1.2  matt 	// const
    589  1.2  matt 	register_t msr = wrtee(0);
    590  1.2  matt #ifdef __HAVE_FAST_SOFTINTS
    591  1.2  matt 	const u_int softints = (ci->ci_data.cpu_softints << ipl) & IPL_SOFTMASK;
    592  1.2  matt 	if (__predict_false(softints != 0)) {
    593  1.2  matt 		e500_splset(ci, IPL_HIGH);
    594  1.2  matt 		e500_softint(ci, ci->ci_softc, ipl);
    595  1.2  matt 	}
    596  1.2  matt #endif /* __HAVE_FAST_SOFTINTS */
    597  1.2  matt 	e500_splset(ci, ipl);
    598  1.2  matt #if 1
    599  1.2  matt 	if (ipl < IPL_VM && old_ipl >= IPL_VM)
    600  1.2  matt 		msr = PSL_EE;
    601  1.2  matt #endif
    602  1.2  matt 	wrtee(msr);
    603  1.2  matt }
    604  1.2  matt 
    605  1.2  matt static int
    606  1.2  matt e500_splraise(int ipl)
    607  1.2  matt {
    608  1.2  matt 	struct cpu_info * const ci = curcpu();
    609  1.2  matt 	const int old_ipl = ci->ci_cpl;
    610  1.2  matt 
    611  1.2  matt 	KASSERT(mfmsr() & PSL_CE);
    612  1.2  matt 
    613  1.2  matt 	if (old_ipl < ipl) {
    614  1.2  matt 		//const
    615  1.2  matt 		register_t msr = wrtee(0);
    616  1.2  matt 		e500_splset(ci, ipl);
    617  1.2  matt #if 1
    618  1.2  matt 		if (old_ipl < IPL_VM && ipl >= IPL_VM)
    619  1.2  matt 			msr = 0;
    620  1.2  matt #endif
    621  1.2  matt 		wrtee(msr);
    622  1.2  matt 	} else if (ipl == IPL_NONE) {
    623  1.2  matt 		panic("%s: %p: cpl=%u: attempt to splraise(IPL_NONE)",
    624  1.2  matt 		    __func__, __builtin_return_address(0), old_ipl);
    625  1.2  matt #if 0
    626  1.2  matt 	} else if (old_ipl > ipl) {
    627  1.2  matt 		printf("%s: %p: cpl=%u: ignoring splraise(%u) to lower ipl\n",
    628  1.2  matt 		    __func__, __builtin_return_address(0), old_ipl, ipl);
    629  1.2  matt #endif
    630  1.2  matt 	}
    631  1.2  matt 
    632  1.2  matt 	return old_ipl;
    633  1.2  matt }
    634  1.2  matt 
    635  1.2  matt #ifdef __HAVE_FAST_SOFTINTS
    636  1.2  matt static void
    637  1.2  matt e500_softint_init_md(lwp_t *l, u_int si_level, uintptr_t *machdep_p)
    638  1.2  matt {
    639  1.2  matt 	struct cpu_info * const ci = l->l_cpu;
    640  1.2  matt 	struct cpu_softc * const cpu = ci->ci_softc;
    641  1.2  matt 
    642  1.2  matt 	*machdep_p = 1 << SOFTINT2IPL(si_level);
    643  1.2  matt 	KASSERT(*machdep_p & IPL_SOFTMASK);
    644  1.2  matt 	cpu->cpu_softlwps[si_level] = l;
    645  1.2  matt }
    646  1.2  matt 
    647  1.2  matt static void
    648  1.2  matt e500_softint_trigger(uintptr_t machdep)
    649  1.2  matt {
    650  1.2  matt 	struct cpu_info * const ci = curcpu();
    651  1.2  matt 
    652  1.2  matt 	atomic_or_uint(&ci->ci_data.cpu_softints, machdep);
    653  1.2  matt 	if (machdep == (1 << IPL_SOFTBIO))
    654  1.2  matt 		printf("%s(%u): cpl=%u\n", __func__, machdep, ci->ci_cpl);
    655  1.2  matt }
    656  1.2  matt #endif /* __HAVE_FAST_SOFTINTS */
    657  1.2  matt 
    658  1.2  matt static int
    659  1.2  matt e500_intr_spurious(void *arg)
    660  1.2  matt {
    661  1.2  matt 	return 0;
    662  1.2  matt }
    663  1.2  matt 
    664  1.2  matt static bool
    665  1.2  matt e500_intr_irq_info_get(struct cpu_info *ci, u_int irq, int ipl, int ist,
    666  1.2  matt 	struct e500_intr_irq_info *ii)
    667  1.2  matt {
    668  1.2  matt 	const struct e500_intr_info * const info = &e500_intr_info;
    669  1.2  matt 	bool ok;
    670  1.2  matt 
    671  1.2  matt #if DEBUG > 2
    672  1.2  matt 	printf("%s(%p,irq=%u,ipl=%u,ist=%u,%p)\n", __func__, ci, irq, ipl, ist, ii);
    673  1.2  matt #endif
    674  1.2  matt 
    675  1.2  matt 	if (ipl < IPL_VM || ipl > IPL_HIGH) {
    676  1.2  matt #if DEBUG > 2
    677  1.2  matt 		printf("%s:%d ipl=%u\n", __func__, __LINE__, ipl);
    678  1.2  matt #endif
    679  1.2  matt 		return false;
    680  1.2  matt 	}
    681  1.2  matt 
    682  1.2  matt 	if (ist <= IST_NONE || ist >= IST_MAX) {
    683  1.2  matt #if DEBUG > 2
    684  1.2  matt 		printf("%s:%d ist=%u\n", __func__, __LINE__, ist);
    685  1.2  matt #endif
    686  1.2  matt 		return false;
    687  1.2  matt 	}
    688  1.2  matt 
    689  1.2  matt 	ii->irq_vector = irq + info->ii_ist_vectors[ist];
    690  1.2  matt 	if (IST_PERCPU_P(ist))
    691  1.2  matt 		ii->irq_vector += ci->ci_cpuid * info->ii_percpu_sources;
    692  1.2  matt 
    693  1.2  matt 	switch (ist) {
    694  1.2  matt 	default:
    695  1.2  matt 		ii->irq_vpr = OPENPIC_EIVPR(irq);
    696  1.2  matt 		ii->irq_dr  = OPENPIC_EIDR(irq);
    697  1.2  matt 		ok = irq < info->ii_external_sources
    698  1.2  matt 		    && (ist == IST_EDGE
    699  1.2  matt 			|| ist == IST_LEVEL_LOW
    700  1.2  matt 			|| ist == IST_LEVEL_HIGH);
    701  1.2  matt 		break;
    702  1.2  matt 	case IST_ONCHIP:
    703  1.2  matt 		ii->irq_vpr = OPENPIC_IIVPR(irq);
    704  1.2  matt 		ii->irq_dr  = OPENPIC_IIDR(irq);
    705  1.2  matt 		ok = irq < 32 * __arraycount(info->ii_onchip_bitmap);
    706  1.2  matt #if DEBUG > 2
    707  1.2  matt 		printf("%s: irq=%u: ok=%u\n", __func__, irq, ok);
    708  1.2  matt #endif
    709  1.2  matt 		ok = ok && (info->ii_onchip_bitmap[irq/32] & (1 << (irq & 31)));
    710  1.2  matt #if DEBUG > 2
    711  1.2  matt 		printf("%s: %08x%08x -> %08x%08x: ok=%u\n", __func__,
    712  1.2  matt 		    irq < 32 ? 0 : (1 << irq), irq < 32 ? (1 << irq) : 0,
    713  1.2  matt 		    info->ii_onchip_bitmap[1], info->ii_onchip_bitmap[0],
    714  1.2  matt 		    ok);
    715  1.2  matt #endif
    716  1.2  matt 		break;
    717  1.2  matt 	case IST_MSIGROUP:
    718  1.2  matt 		ii->irq_vpr = OPENPIC_MSIVPR(irq);
    719  1.2  matt 		ii->irq_dr  = OPENPIC_MSIDR(irq);
    720  1.2  matt 		ok = irq < info->ii_msigroup_sources
    721  1.2  matt 		    && ipl == IPL_VM;
    722  1.2  matt 		break;
    723  1.2  matt 	case IST_TIMER:
    724  1.2  matt 		ii->irq_vpr = OPENPIC_GTVPR(ci->ci_cpuid, irq);
    725  1.2  matt 		ii->irq_dr  = OPENPIC_GTDR(ci->ci_cpuid, irq);
    726  1.2  matt 		ok = irq < info->ii_timer_sources;
    727  1.2  matt #if DEBUG > 2
    728  1.2  matt 		printf("%s: IST_TIMER irq=%u: ok=%u\n", __func__, irq, ok);
    729  1.2  matt #endif
    730  1.2  matt 		break;
    731  1.2  matt 	case IST_IPI:
    732  1.2  matt 		ii->irq_vpr = OPENPIC_IPIVPR(irq);
    733  1.2  matt 		ii->irq_dr  = OPENPIC_IPIDR(irq);
    734  1.2  matt 		ok = irq < info->ii_ipi_sources;
    735  1.2  matt 		break;
    736  1.2  matt 	case IST_MI:
    737  1.2  matt 		ii->irq_vpr = OPENPIC_MIVPR(irq);
    738  1.2  matt 		ii->irq_dr  = OPENPIC_MIDR(irq);
    739  1.2  matt 		ok = irq < info->ii_mi_sources;
    740  1.2  matt 		break;
    741  1.2  matt 	}
    742  1.2  matt 
    743  1.2  matt 	return ok;
    744  1.2  matt }
    745  1.2  matt 
    746  1.2  matt static const char *
    747  1.2  matt e500_intr_string(int irq, int ist)
    748  1.2  matt {
    749  1.2  matt 	struct cpu_info * const ci = curcpu();
    750  1.2  matt 	struct cpu_softc * const cpu = ci->ci_softc;
    751  1.2  matt 	struct e500_intr_irq_info ii;
    752  1.2  matt 
    753  1.2  matt 	if (!e500_intr_irq_info_get(ci, irq, IPL_VM, ist, &ii))
    754  1.2  matt 		return NULL;
    755  1.2  matt 
    756  1.2  matt 	return cpu->cpu_evcnt_intrs[ii.irq_vector].ev_name;
    757  1.2  matt }
    758  1.2  matt 
    759  1.2  matt static void *
    760  1.2  matt e500_intr_cpu_establish(struct cpu_info *ci, int irq, int ipl, int ist,
    761  1.2  matt 	int (*handler)(void *), void *arg)
    762  1.2  matt {
    763  1.2  matt 	struct cpu_softc * const cpu = ci->ci_softc;
    764  1.2  matt 	struct e500_intr_irq_info ii;
    765  1.2  matt 
    766  1.2  matt 	KASSERT(ipl >= IPL_VM && ipl <= IPL_HIGH);
    767  1.2  matt 	KASSERT(ist > IST_NONE && ist < IST_MAX && ist != IST_MSI);
    768  1.2  matt 
    769  1.2  matt 	if (!e500_intr_irq_info_get(ci, irq, ipl, ist, &ii)) {
    770  1.2  matt 		printf("%s: e500_intr_irq_info_get(%p,%u,%u,%u,%p) failed\n",
    771  1.2  matt 		    __func__, ci, irq, ipl, ist, &ii);
    772  1.2  matt 		return NULL;
    773  1.2  matt 	}
    774  1.2  matt 
    775  1.2  matt 	struct intr_source * const is = &e500_intr_sources[ii.irq_vector];
    776  1.2  matt 	mutex_enter(&e500_intr_lock);
    777  1.2  matt 	if (is->is_ipl != IPL_NONE)
    778  1.2  matt 		return NULL;
    779  1.2  matt 
    780  1.2  matt 	is->is_func = handler;
    781  1.2  matt 	is->is_arg = arg;
    782  1.2  matt 	is->is_ipl = ipl;
    783  1.2  matt 	is->is_ist = ist;
    784  1.2  matt 	is->is_irq = irq;
    785  1.2  matt 	is->is_vpr = ii.irq_vpr;
    786  1.2  matt 	is->is_dr = ii.irq_dr;
    787  1.2  matt 
    788  1.2  matt 	uint32_t vpr = VPR_PRIORITY_MAKE(IPL2CTPR(ipl))
    789  1.2  matt 	    | VPR_VECTOR_MAKE(((ii.irq_vector + 1) << 4) | ipl)
    790  1.2  matt 	    | (ist == IST_LEVEL_LOW
    791  1.2  matt 		? VPR_LEVEL_LOW
    792  1.2  matt 		: (ist == IST_LEVEL_HIGH
    793  1.2  matt 		    ? VPR_LEVEL_HIGH
    794  1.2  matt 		    : (ist == IST_ONCHIP
    795  1.2  matt 		      ? VPR_P_HIGH
    796  1.2  matt 		      : 0)));
    797  1.2  matt 
    798  1.2  matt 	/*
    799  1.2  matt 	 * All interrupts go to the primary except per-cpu interrupts which get
    800  1.2  matt 	 * routed to the appropriate cpu.
    801  1.2  matt 	 */
    802  1.2  matt 	uint32_t dr = IST_PERCPU_P(ist) ? 1 << ci->ci_cpuid : 1;
    803  1.2  matt 
    804  1.2  matt 	/*
    805  1.2  matt 	 * Update the vector/priority and destination registers keeping the
    806  1.2  matt 	 * interrupt masked.
    807  1.2  matt 	 */
    808  1.2  matt 	const register_t msr = wrtee(0);	/* disable interrupts */
    809  1.2  matt 	openpic_write(cpu, ii.irq_vpr, vpr | VPR_MSK);
    810  1.2  matt 	openpic_write(cpu, ii.irq_dr, dr);
    811  1.2  matt 
    812  1.2  matt 	/*
    813  1.2  matt 	 * Now unmask the interrupt.
    814  1.2  matt 	 */
    815  1.2  matt 	openpic_write(cpu, ii.irq_vpr, vpr);
    816  1.2  matt 
    817  1.2  matt 	wrtee(msr);				/* re-enable interrupts */
    818  1.2  matt 
    819  1.2  matt 	mutex_exit(&e500_intr_lock);
    820  1.2  matt 
    821  1.2  matt 	return is;
    822  1.2  matt }
    823  1.2  matt 
    824  1.2  matt static void *
    825  1.2  matt e500_intr_establish(int irq, int ipl, int ist,
    826  1.2  matt 	int (*handler)(void *), void *arg)
    827  1.2  matt {
    828  1.2  matt 	return e500_intr_cpu_establish(curcpu(), irq, ipl, ist, handler, arg);
    829  1.2  matt }
    830  1.2  matt 
    831  1.2  matt static void
    832  1.2  matt e500_intr_disestablish(void *vis)
    833  1.2  matt {
    834  1.2  matt 	struct cpu_softc * const cpu = curcpu()->ci_softc;
    835  1.2  matt 	struct intr_source * const is = vis;
    836  1.2  matt 	struct e500_intr_irq_info ii;
    837  1.2  matt 
    838  1.2  matt 	KASSERT(e500_intr_sources <= is);
    839  1.2  matt 	KASSERT(is < e500_intr_last_source);
    840  1.2  matt 	KASSERT(!cpu_intr_p());
    841  1.2  matt 
    842  1.2  matt 	bool ok = e500_intr_irq_info_get(curcpu(), is->is_irq, is->is_ipl,
    843  1.2  matt 	    is->is_ist, &ii);
    844  1.2  matt 	(void)ok;	/* appease gcc */
    845  1.2  matt 	KASSERT(ok);
    846  1.2  matt 	KASSERT(is - e500_intr_sources == ii.irq_vector);
    847  1.2  matt 
    848  1.2  matt 	mutex_enter(&e500_intr_lock);
    849  1.2  matt 	/*
    850  1.2  matt 	 * Mask the source using the mask (MSK) bit in the vector/priority reg.
    851  1.2  matt 	 */
    852  1.2  matt 	uint32_t vpr = openpic_read(cpu, ii.irq_vpr);
    853  1.2  matt 	openpic_write(cpu, ii.irq_vpr, VPR_MSK | vpr);
    854  1.2  matt 
    855  1.2  matt 	/*
    856  1.2  matt 	 * Wait for the Activity (A) bit for the source to be cleared.
    857  1.2  matt 	 */
    858  1.2  matt 	while (openpic_read(cpu, ii.irq_vpr) & VPR_A)
    859  1.2  matt 		;
    860  1.2  matt 
    861  1.2  matt 	/*
    862  1.2  matt 	 * Now the source can be modified.
    863  1.2  matt 	 */
    864  1.2  matt 	openpic_write(cpu, ii.irq_dr, 0);		/* stop delivery */
    865  1.2  matt 	openpic_write(cpu, ii.irq_vpr, VPR_MSK);	/* mask/reset it */
    866  1.2  matt 
    867  1.2  matt 	*is = (struct intr_source)INTR_SOURCE_INITIALIZER;
    868  1.2  matt 
    869  1.2  matt 	mutex_exit(&e500_intr_lock);
    870  1.2  matt }
    871  1.2  matt 
    872  1.2  matt static void
    873  1.2  matt e500_critintr(struct trapframe *tf)
    874  1.2  matt {
    875  1.2  matt 	panic("%s: srr0/srr1=%#lx/%#lx", __func__, tf->tf_srr0, tf->tf_srr1);
    876  1.2  matt }
    877  1.2  matt 
    878  1.2  matt static void
    879  1.2  matt e500_decrintr(struct trapframe *tf)
    880  1.2  matt {
    881  1.2  matt 	panic("%s: srr0/srr1=%#lx/%#lx", __func__, tf->tf_srr0, tf->tf_srr1);
    882  1.2  matt }
    883  1.2  matt 
    884  1.2  matt static void
    885  1.2  matt e500_fitintr(struct trapframe *tf)
    886  1.2  matt {
    887  1.2  matt 	panic("%s: srr0/srr1=%#lx/%#lx", __func__, tf->tf_srr0, tf->tf_srr1);
    888  1.2  matt }
    889  1.2  matt 
    890  1.2  matt static void
    891  1.2  matt e500_wdogintr(struct trapframe *tf)
    892  1.2  matt {
    893  1.2  matt 	mtspr(SPR_TSR, TSR_ENW|TSR_WIS);
    894  1.2  matt 	panic("%s: tf=%p tb=%"PRId64" srr0/srr1=%#lx/%#lx", __func__, tf,
    895  1.2  matt 	    mftb(), tf->tf_srr0, tf->tf_srr1);
    896  1.2  matt }
    897  1.2  matt 
    898  1.2  matt static void
    899  1.2  matt e500_extintr(struct trapframe *tf)
    900  1.2  matt {
    901  1.2  matt 	struct cpu_info * const ci = curcpu();
    902  1.2  matt 	struct cpu_softc * const cpu = ci->ci_softc;
    903  1.2  matt 	const int old_ipl = ci->ci_cpl;
    904  1.2  matt 
    905  1.2  matt 	KASSERT(mfmsr() & PSL_CE);
    906  1.2  matt 
    907  1.2  matt #if 0
    908  1.2  matt //	printf("%s(%p): idepth=%d enter\n", __func__, tf, ci->ci_idepth);
    909  1.2  matt 	if ((register_t)tf >= (register_t)curlwp->l_addr + USPACE
    910  1.2  matt 	    || (register_t)tf < (register_t)curlwp->l_addr + NBPG) {
    911  1.2  matt 		printf("%s(entry): pid %d.%d (%s): srr0/srr1=%#lx/%#lx: invalid tf addr %p\n",
    912  1.2  matt 		    __func__, curlwp->l_proc->p_pid, curlwp->l_lid,
    913  1.2  matt 		    curlwp->l_proc->p_comm, tf->tf_srr0, tf->tf_srr1, tf);
    914  1.2  matt 	}
    915  1.2  matt #endif
    916  1.2  matt 
    917  1.2  matt 
    918  1.2  matt 	ci->ci_data.cpu_nintr++;
    919  1.2  matt 	tf->tf_cf.cf_idepth = ci->ci_idepth++;
    920  1.2  matt 	cpu->cpu_pcpls[ci->ci_idepth] = old_ipl;
    921  1.2  matt #if 1
    922  1.2  matt 	if (mfmsr() & PSL_EE)
    923  1.2  matt 		panic("%s(%p): MSR[EE] is on (%#lx)!", __func__, tf, mfmsr());
    924  1.2  matt 	if (old_ipl == IPL_HIGH
    925  1.2  matt 	    || IPL2CTPR(old_ipl) != openpic_read(cpu, OPENPIC_CTPR))
    926  1.2  matt 		panic("%s(%p): old_ipl(%u) == IPL_HIGH(%u) "
    927  1.2  matt 		    "|| old_ipl + %u != OPENPIC_CTPR (%u)",
    928  1.2  matt 		    __func__, tf, old_ipl, IPL_HIGH,
    929  1.2  matt 		    15 - IPL_HIGH, openpic_read(cpu, OPENPIC_CTPR));
    930  1.2  matt #else
    931  1.2  matt 	if (old_ipl >= IPL_VM)
    932  1.2  matt 		panic("%s(%p): old_ipl(%u) >= IPL_VM(%u) CTPR=%u",
    933  1.2  matt 		    __func__, tf, old_ipl, IPL_VM, openpic_read(cpu, OPENPIC_CTPR));
    934  1.2  matt #endif
    935  1.2  matt 
    936  1.2  matt 	for (;;) {
    937  1.2  matt 		/*
    938  1.2  matt 		 * Find out the pending interrupt.
    939  1.2  matt 		 */
    940  1.2  matt 	if (mfmsr() & PSL_EE)
    941  1.2  matt 		panic("%s(%p): MSR[EE] turned on (%#lx)!", __func__, tf, mfmsr());
    942  1.2  matt 		if (IPL2CTPR(old_ipl) != openpic_read(cpu, OPENPIC_CTPR))
    943  1.2  matt 			panic("%s(%p): %d: old_ipl(%u) + %u != OPENPIC_CTPR (%u)",
    944  1.2  matt 			    __func__, tf, __LINE__, old_ipl,
    945  1.2  matt 			    15 - IPL_HIGH, openpic_read(cpu, OPENPIC_CTPR));
    946  1.2  matt 		const uint32_t iack = openpic_read(cpu, OPENPIC_IACK);
    947  1.2  matt 		const int ipl = iack & 0xf;
    948  1.2  matt 		const int irq = (iack >> 4) - 1;
    949  1.2  matt #if 0
    950  1.2  matt 		printf("%s: iack=%d ipl=%d irq=%d <%s>\n",
    951  1.2  matt 		    __func__, iack, ipl, irq,
    952  1.2  matt 		    (iack != IRQ_SPURIOUS ?
    953  1.2  matt 			cpu->cpu_evcnt_intrs[irq].ev_name : "spurious"));
    954  1.2  matt #endif
    955  1.2  matt 		if (IPL2CTPR(old_ipl) != openpic_read(cpu, OPENPIC_CTPR))
    956  1.2  matt 			panic("%s(%p): %d: old_ipl(%u) + %u != OPENPIC_CTPR (%u)",
    957  1.2  matt 			    __func__, tf, __LINE__, old_ipl,
    958  1.2  matt 			    15 - IPL_HIGH, openpic_read(cpu, OPENPIC_CTPR));
    959  1.2  matt 		if (iack == IRQ_SPURIOUS)
    960  1.2  matt 			break;
    961  1.2  matt 
    962  1.2  matt 		struct intr_source * const is = &e500_intr_sources[irq];
    963  1.2  matt 		if (__predict_true(is < e500_intr_last_source)) {
    964  1.2  matt 			/*
    965  1.2  matt 			 * Timer interrupts get their argument overriden with
    966  1.2  matt 			 * the pointer to the trapframe.
    967  1.2  matt 			 */
    968  1.2  matt 			KASSERT(is->is_ipl == ipl);
    969  1.2  matt 			void *arg = (is->is_ist == IST_TIMER ? tf : is->is_arg);
    970  1.2  matt 			if (is->is_ipl <= old_ipl)
    971  1.2  matt 				panic("%s(%p): %s (%u): is->is_ipl (%u) <= old_ipl (%u)\n",
    972  1.2  matt 				    __func__, tf,
    973  1.2  matt 				    cpu->cpu_evcnt_intrs[irq].ev_name, irq,
    974  1.2  matt 				    is->is_ipl, old_ipl);
    975  1.2  matt 			KASSERT(is->is_ipl > old_ipl);
    976  1.2  matt 			e500_splset(ci, is->is_ipl);	/* change IPL */
    977  1.2  matt 			if (__predict_false(is->is_func == NULL)) {
    978  1.2  matt 				aprint_error_dev(ci->ci_dev,
    979  1.2  matt 				    "interrupt from unestablished irq %d\n",
    980  1.2  matt 				    irq);
    981  1.2  matt 			} else {
    982  1.2  matt 				int (*func)(void *) = is->is_func;
    983  1.2  matt 				wrtee(PSL_EE);
    984  1.2  matt 				int rv = (*func)(arg);
    985  1.2  matt 				wrtee(0);
    986  1.2  matt #if DEBUG > 2
    987  1.2  matt 				printf("%s: %s handler %p(%p) returned %d\n",
    988  1.2  matt 				    __func__,
    989  1.2  matt 				    cpu->cpu_evcnt_intrs[irq].ev_name,
    990  1.2  matt 				    func, arg, rv);
    991  1.2  matt #endif
    992  1.2  matt 				if (rv == 0)
    993  1.2  matt 					cpu->cpu_evcnt_spurious_intr.ev_count++;
    994  1.2  matt 			}
    995  1.2  matt 			e500_splset(ci, old_ipl);	/* restore IPL */
    996  1.2  matt 			cpu->cpu_evcnt_intrs[irq].ev_count++;
    997  1.2  matt 		} else {
    998  1.2  matt 			aprint_error_dev(ci->ci_dev,
    999  1.2  matt 			    "interrupt from illegal irq %d\n", irq);
   1000  1.2  matt 			cpu->cpu_evcnt_spurious_intr.ev_count++;
   1001  1.2  matt 		}
   1002  1.2  matt 		/*
   1003  1.2  matt 		 * If this is a nested interrupt, simply ack it and exit
   1004  1.2  matt 		 * because the loop we interrupted will complete looking
   1005  1.2  matt 		 * for interrupts.
   1006  1.2  matt 		 */
   1007  1.2  matt 	if (mfmsr() & PSL_EE)
   1008  1.2  matt 		panic("%s(%p): MSR[EE] left on (%#lx)!", __func__, tf, mfmsr());
   1009  1.2  matt 		if (IPL2CTPR(old_ipl) != openpic_read(cpu, OPENPIC_CTPR))
   1010  1.2  matt 			panic("%s(%p): %d: old_ipl(%u) + %u != OPENPIC_CTPR (%u)",
   1011  1.2  matt 			    __func__, tf, __LINE__, old_ipl,
   1012  1.2  matt 			    15 - IPL_HIGH, openpic_read(cpu, OPENPIC_CTPR));
   1013  1.2  matt 
   1014  1.2  matt 		openpic_write(cpu, OPENPIC_EOI, 0);
   1015  1.2  matt 		if (IPL2CTPR(old_ipl) != openpic_read(cpu, OPENPIC_CTPR))
   1016  1.2  matt 			panic("%s(%p): %d: old_ipl(%u) + %u != OPENPIC_CTPR (%u)",
   1017  1.2  matt 			    __func__, tf, __LINE__, old_ipl,
   1018  1.2  matt 			    15 - IPL_HIGH, openpic_read(cpu, OPENPIC_CTPR));
   1019  1.2  matt 		if (ci->ci_idepth > 0)
   1020  1.2  matt 			break;
   1021  1.2  matt 	}
   1022  1.2  matt 
   1023  1.2  matt 	ci->ci_idepth--;
   1024  1.2  matt 
   1025  1.2  matt #ifdef __HAVE_FAST_SOFTINTS
   1026  1.2  matt 	/*
   1027  1.2  matt 	 * Before exiting, deal with any softints that need to be dealt with.
   1028  1.2  matt 	 */
   1029  1.2  matt 	const u_int softints = (ci->ci_data.cpu_softints << old_ipl) & IPL_SOFTMASK;
   1030  1.2  matt 	if (__predict_false(softints != 0)) {
   1031  1.2  matt 		KASSERT(old_ipl < IPL_VM);
   1032  1.2  matt 		e500_splset(ci, IPL_HIGH);	/* pop to high */
   1033  1.2  matt 		e500_softint(ci, cpu, old_ipl);	/* deal with them */
   1034  1.2  matt 		e500_splset(ci, old_ipl);	/* and drop back */
   1035  1.2  matt 	}
   1036  1.2  matt #endif /* __HAVE_FAST_SOFTINTS */
   1037  1.2  matt #if 1
   1038  1.2  matt 	KASSERT(ci->ci_cpl == old_ipl);
   1039  1.2  matt #else
   1040  1.2  matt 	e500_splset(ci, old_ipl);		/* and drop back */
   1041  1.2  matt #endif
   1042  1.2  matt 
   1043  1.2  matt //	printf("%s(%p): idepth=%d exit\n", __func__, tf, ci->ci_idepth);
   1044  1.2  matt }
   1045  1.2  matt 
   1046  1.2  matt static void
   1047  1.2  matt e500_intr_init(void)
   1048  1.2  matt {
   1049  1.2  matt 	struct cpu_info * const ci = curcpu();
   1050  1.2  matt 	struct cpu_softc * const cpu = ci->ci_softc;
   1051  1.2  matt 	const uint32_t frr = openpic_read(cpu, OPENPIC_FRR);
   1052  1.2  matt 	const u_int nirq = FRR_NIRQ_GET(frr) + 1;
   1053  1.2  matt //	const u_int ncpu = FRR_NCPU_GET(frr) + 1;
   1054  1.2  matt 	struct intr_source *is;
   1055  1.2  matt 	struct e500_intr_info * const ii = &e500_intr_info;
   1056  1.2  matt 
   1057  1.2  matt 	switch (nirq) {
   1058  1.2  matt 	case MPC8548_SOURCES: {
   1059  1.2  matt 		CTASSERT(MPC8548_ONCHIPSOURCES == MPC8544_ONCHIPSOURCES);
   1060  1.2  matt 		*ii = mpc8548_intr_info;
   1061  1.2  matt 		if ((mfspr(SPR_SVR) >> 16) == (SVR_MPC8544v1 >> 16)) {
   1062  1.2  matt 			uint32_t bitmap[2] = MPC8548_ONCHIPBITMAP;
   1063  1.2  matt 			ii->ii_onchip_bitmap[0] = bitmap[0];
   1064  1.2  matt 			ii->ii_onchip_bitmap[1] = bitmap[1];
   1065  1.2  matt 			ii->ii_onchip_sources = MPC8544_ONCHIPSOURCES;
   1066  1.2  matt 			ii->ii_onchip_intr_names = mpc8544_onchip_intr_names;
   1067  1.2  matt 		}
   1068  1.2  matt 		break;
   1069  1.2  matt 	}
   1070  1.2  matt 	case MPC8536_SOURCES:
   1071  1.2  matt 		*ii = mpc8536_intr_info;
   1072  1.2  matt 		break;
   1073  1.2  matt 	case MPC8572_SOURCES:
   1074  1.2  matt 		*ii = mpc8572_intr_info;
   1075  1.2  matt 		break;
   1076  1.2  matt 	default:
   1077  1.2  matt 		panic("%s: don't know how to deal with %u interrupt sources",
   1078  1.2  matt 		    __func__, nirq);
   1079  1.2  matt 	}
   1080  1.2  matt 
   1081  1.2  matt 	/*
   1082  1.2  matt 	 * We need to be in mixed mode.
   1083  1.2  matt 	 */
   1084  1.2  matt 	openpic_write(cpu, OPENPIC_GCR, GCR_M);
   1085  1.2  matt 
   1086  1.2  matt 	/*
   1087  1.2  matt 	 * Make we and the openpic both agree about the current SPL level.
   1088  1.2  matt 	 */
   1089  1.2  matt 	e500_splset(ci, ci->ci_cpl);
   1090  1.2  matt 
   1091  1.2  matt 	/*
   1092  1.2  matt 	 * Allow the required number of interrupt sources.
   1093  1.2  matt 	 */
   1094  1.2  matt 	is = kmem_zalloc(nirq * sizeof(*is), KM_SLEEP);
   1095  1.2  matt 	KASSERT(is);
   1096  1.2  matt 	e500_intr_sources = is;
   1097  1.2  matt 	e500_intr_last_source = is + nirq;
   1098  1.2  matt 
   1099  1.2  matt 	/*
   1100  1.2  matt 	 * Initialize all the external interrupts as active low.
   1101  1.2  matt 	 */
   1102  1.2  matt 	for (u_int irq = 0; irq < e500_intr_info.ii_external_sources; irq++) {
   1103  1.2  matt 		openpic_write(cpu, OPENPIC_EIVPR(irq),
   1104  1.2  matt 		    VPR_VECTOR_MAKE(irq) | VPR_LEVEL_LOW);
   1105  1.2  matt 	}
   1106  1.2  matt }
   1107  1.2  matt 
   1108  1.2  matt static void
   1109  1.2  matt e500_intr_cpu_init(struct cpu_info *ci)
   1110  1.2  matt {
   1111  1.2  matt 	struct cpu_softc * const cpu = ci->ci_softc;
   1112  1.2  matt 	const char * const xname = device_xname(ci->ci_dev);
   1113  1.2  matt 
   1114  1.2  matt 	const u_int32_t frr = openpic_read(cpu, OPENPIC_FRR);
   1115  1.2  matt 	const u_int nirq = FRR_NIRQ_GET(frr) + 1;
   1116  1.2  matt //	const u_int ncpu = FRR_NCPU_GET(frr) + 1;
   1117  1.2  matt 
   1118  1.2  matt 	const struct e500_intr_info * const info = &e500_intr_info;
   1119  1.2  matt 
   1120  1.2  matt 	cpu->cpu_clock_gtbcr = OPENPIC_GTBCR(ci->ci_cpuid, E500_CLOCK_TIMER);
   1121  1.2  matt 
   1122  1.2  matt 	cpu->cpu_evcnt_intrs =
   1123  1.2  matt 	    kmem_zalloc(nirq * sizeof(cpu->cpu_evcnt_intrs[0]), KM_SLEEP);
   1124  1.2  matt 	KASSERT(cpu->cpu_evcnt_intrs);
   1125  1.2  matt 
   1126  1.2  matt 	struct evcnt *evcnt = cpu->cpu_evcnt_intrs;
   1127  1.2  matt 	for (size_t j = 0; j < info->ii_external_sources; j++, evcnt++) {
   1128  1.2  matt 		const char *name = e500_intr_external_name_lookup(j);
   1129  1.2  matt 		evcnt_attach_dynamic(evcnt, EVCNT_TYPE_INTR, NULL, xname, name);
   1130  1.2  matt 	}
   1131  1.2  matt 	KASSERT(evcnt == cpu->cpu_evcnt_intrs + info->ii_ist_vectors[IST_ONCHIP]);
   1132  1.2  matt 	for (size_t j = 0; j < info->ii_onchip_sources; j++, evcnt++) {
   1133  1.2  matt 		const char *name = e500_intr_onchip_name_lookup(j);
   1134  1.2  matt 		if (name != NULL) {
   1135  1.2  matt 			evcnt_attach_dynamic(evcnt, EVCNT_TYPE_INTR,
   1136  1.2  matt 			    NULL, xname, name);
   1137  1.2  matt 		}
   1138  1.2  matt 	}
   1139  1.2  matt 
   1140  1.2  matt 	KASSERT(evcnt == cpu->cpu_evcnt_intrs + info->ii_ist_vectors[IST_MSIGROUP]);
   1141  1.2  matt 	for (size_t j = 0; j < info->ii_msigroup_sources; j++, evcnt++) {
   1142  1.2  matt 		evcnt_attach_dynamic(evcnt, EVCNT_TYPE_INTR,
   1143  1.2  matt 		    NULL, xname, e500_msigroup_intr_names[j].in_name);
   1144  1.2  matt 	}
   1145  1.2  matt 
   1146  1.2  matt 	KASSERT(evcnt == cpu->cpu_evcnt_intrs + info->ii_ist_vectors[IST_TIMER]);
   1147  1.2  matt 	evcnt += ci->ci_cpuid * info->ii_percpu_sources;
   1148  1.2  matt 	for (size_t j = 0; j < info->ii_timer_sources; j++, evcnt++) {
   1149  1.2  matt 		evcnt_attach_dynamic(evcnt, EVCNT_TYPE_INTR,
   1150  1.2  matt 		    NULL, xname, e500_timer_intr_names[j].in_name);
   1151  1.2  matt 	}
   1152  1.2  matt 
   1153  1.2  matt 	for (size_t j = 0; j < info->ii_ipi_sources; j++, evcnt++) {
   1154  1.2  matt 		evcnt_attach_dynamic(evcnt, EVCNT_TYPE_INTR,
   1155  1.2  matt 		    NULL, xname, e500_ipi_intr_names[j].in_name);
   1156  1.2  matt 	}
   1157  1.2  matt 
   1158  1.2  matt 	for (size_t j = 0; j < info->ii_mi_sources; j++, evcnt++) {
   1159  1.2  matt 		evcnt_attach_dynamic(evcnt, EVCNT_TYPE_INTR,
   1160  1.2  matt 		    NULL, xname, e500_mi_intr_names[j].in_name);
   1161  1.2  matt 	}
   1162  1.2  matt 
   1163  1.2  matt 	/*
   1164  1.2  matt 	 * Establish interrupt for this CPU.
   1165  1.2  matt 	 */
   1166  1.2  matt 	if (e500_intr_cpu_establish(ci, E500_CLOCK_TIMER, IPL_CLOCK, IST_TIMER,
   1167  1.2  matt 	    e500_clock_intr, NULL) == NULL)
   1168  1.2  matt 		panic("%s: failed to establish clock interrupt!", __func__);
   1169  1.2  matt 
   1170  1.2  matt 	/*
   1171  1.2  matt 	 * Enable watchdog interrupts.
   1172  1.2  matt 	 */
   1173  1.2  matt 	uint32_t tcr = mfspr(SPR_TCR);
   1174  1.2  matt 	tcr |= TCR_WIE;
   1175  1.2  matt 	mtspr(SPR_TCR, tcr);
   1176  1.2  matt }
   1177