Home | History | Annotate | Line # | Download | only in mpc85xx
machdep.c revision 1.29.2.2
      1  1.29.2.1       tls /*	$NetBSD: machdep.c,v 1.29.2.2 2017/12/03 11:36:11 jdolecek 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 #include <sys/cdefs.h>
     38       1.2      matt 
     39       1.2      matt __KERNEL_RCSID(0, "$NetSBD$");
     40       1.2      matt 
     41      1.20      matt #include "opt_altivec.h"
     42      1.20      matt #include "opt_ddb.h"
     43       1.2      matt #include "opt_mpc85xx.h"
     44  1.29.2.2  jdolecek #include "opt_multiprocessor.h"
     45       1.2      matt #include "opt_pci.h"
     46       1.2      matt #include "gpio.h"
     47       1.2      matt #include "pci.h"
     48       1.2      matt 
     49       1.2      matt #define	DDRC_PRIVATE
     50       1.2      matt #define	GLOBAL_PRIVATE
     51       1.2      matt #define	L2CACHE_PRIVATE
     52       1.2      matt #define _POWERPC_BUS_DMA_PRIVATE
     53       1.2      matt 
     54       1.2      matt #include <sys/param.h>
     55       1.2      matt #include <sys/cpu.h>
     56       1.2      matt #include <sys/intr.h>
     57       1.2      matt #include <sys/msgbuf.h>
     58       1.2      matt #include <sys/tty.h>
     59       1.2      matt #include <sys/kcore.h>
     60       1.2      matt #include <sys/bitops.h>
     61       1.2      matt #include <sys/bus.h>
     62       1.2      matt #include <sys/extent.h>
     63      1.29      matt #include <sys/reboot.h>
     64       1.8       mrg #include <sys/module.h>
     65       1.2      matt 
     66       1.2      matt #include <uvm/uvm_extern.h>
     67       1.2      matt 
     68       1.2      matt #include <prop/proplib.h>
     69       1.2      matt 
     70       1.2      matt #include <dev/cons.h>
     71       1.2      matt 
     72       1.2      matt #include <dev/ic/comreg.h>
     73       1.2      matt #include <dev/ic/comvar.h>
     74       1.2      matt 
     75       1.2      matt #include <net/if.h>
     76       1.2      matt #include <net/if_media.h>
     77       1.2      matt #include <dev/mii/miivar.h>
     78       1.2      matt 
     79       1.2      matt #include <powerpc/pcb.h>
     80       1.2      matt #include <powerpc/spr.h>
     81       1.2      matt #include <powerpc/booke/spr.h>
     82       1.2      matt 
     83       1.2      matt #include <powerpc/booke/cpuvar.h>
     84       1.2      matt #include <powerpc/booke/e500reg.h>
     85       1.2      matt #include <powerpc/booke/e500var.h>
     86       1.2      matt #include <powerpc/booke/etsecreg.h>
     87       1.2      matt #include <powerpc/booke/openpicreg.h>
     88       1.2      matt #ifdef CADMUS
     89       1.2      matt #include <evbppc/mpc85xx/cadmusreg.h>
     90       1.2      matt #endif
     91       1.2      matt #ifdef PIXIS
     92       1.2      matt #include <evbppc/mpc85xx/pixisreg.h>
     93       1.2      matt #endif
     94       1.2      matt 
     95      1.10      matt struct uboot_bdinfo {
     96      1.10      matt 	uint32_t bd_memstart;
     97      1.10      matt 	uint32_t bd_memsize;
     98      1.10      matt 	uint32_t bd_flashstart;
     99      1.10      matt 	uint32_t bd_flashsize;
    100      1.10      matt /*10*/	uint32_t bd_flashoffset;
    101      1.10      matt 	uint32_t bd_sramstart;
    102      1.10      matt 	uint32_t bd_sramsize;
    103      1.10      matt 	uint32_t bd_immrbase;
    104      1.10      matt /*20*/	uint32_t bd_bootflags;
    105      1.10      matt 	uint32_t bd_ipaddr;
    106      1.10      matt 	uint8_t bd_etheraddr[6];
    107      1.10      matt 	uint16_t bd_ethspeed;
    108      1.10      matt /*30*/	uint32_t bd_intfreq;
    109      1.10      matt 	uint32_t bd_cpufreq;
    110      1.10      matt 	uint32_t bd_baudrate;
    111      1.10      matt /*3c*/	uint8_t bd_etheraddr1[6];
    112      1.10      matt /*42*/	uint8_t bd_etheraddr2[6];
    113      1.10      matt /*48*/	uint8_t bd_etheraddr3[6];
    114      1.10      matt /*4e*/	uint16_t bd_pad;
    115      1.10      matt };
    116      1.10      matt 
    117      1.29      matt char root_string[16];
    118      1.29      matt 
    119       1.9       mrg /*
    120       1.9       mrg  * booke kernels need to set module_machine to this for modules to work.
    121       1.9       mrg  */
    122       1.9       mrg char module_machine_booke[] = "powerpc-booke";
    123       1.9       mrg 
    124      1.29      matt void	initppc(vaddr_t, vaddr_t, void *, void *, char *, char *);
    125       1.2      matt 
    126       1.2      matt #define	MEMREGIONS	4
    127      1.19      matt phys_ram_seg_t physmemr[MEMREGIONS];		/* All memory */
    128      1.19      matt phys_ram_seg_t availmemr[2*MEMREGIONS];		/* Available memory */
    129       1.2      matt static u_int nmemr;
    130       1.2      matt 
    131       1.2      matt #ifndef CONSFREQ
    132       1.2      matt # define CONSFREQ	-1            /* inherit from firmware */
    133       1.2      matt #endif
    134       1.2      matt #ifndef CONSPEED
    135       1.2      matt # define CONSPEED	115200
    136       1.2      matt #endif
    137       1.2      matt #ifndef CONMODE
    138       1.2      matt # define CONMODE	((TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)
    139       1.2      matt #endif
    140       1.2      matt #ifndef CONSADDR
    141       1.2      matt # define CONSADDR	DUART2_BASE
    142       1.2      matt #endif
    143       1.2      matt 
    144       1.2      matt int		comcnfreq  = CONSFREQ;
    145       1.2      matt int		comcnspeed = CONSPEED;
    146       1.2      matt tcflag_t	comcnmode  = CONMODE;
    147       1.2      matt bus_addr_t	comcnaddr  = (bus_addr_t)CONSADDR;
    148       1.2      matt 
    149       1.2      matt #if NPCI > 0
    150       1.2      matt struct extent *pcimem_ex;
    151       1.2      matt struct extent *pciio_ex;
    152       1.2      matt #endif
    153       1.2      matt 
    154       1.2      matt struct powerpc_bus_space gur_bst = {
    155       1.2      matt 	.pbs_flags = _BUS_SPACE_BIG_ENDIAN|_BUS_SPACE_MEM_TYPE,
    156       1.2      matt 	.pbs_offset = GUR_BASE,
    157       1.2      matt 	.pbs_limit = GUR_SIZE,
    158       1.2      matt };
    159       1.2      matt 
    160       1.5      matt struct powerpc_bus_space gur_le_bst = {
    161       1.5      matt 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
    162       1.5      matt 	.pbs_offset = GUR_BASE,
    163       1.5      matt 	.pbs_limit = GUR_SIZE,
    164       1.5      matt };
    165       1.5      matt 
    166       1.2      matt const bus_space_handle_t gur_bsh = (bus_space_handle_t)(uintptr_t)(GUR_BASE);
    167       1.2      matt 
    168       1.6      matt #if defined(SYS_CLK)
    169       1.6      matt static uint64_t e500_sys_clk = SYS_CLK;
    170       1.6      matt #endif
    171       1.2      matt #ifdef CADMUS
    172       1.2      matt static uint8_t cadmus_pci;
    173       1.2      matt static uint8_t cadmus_csr;
    174       1.6      matt #ifndef SYS_CLK
    175       1.2      matt static uint64_t e500_sys_clk = 33333333; /* 33.333333Mhz */
    176       1.6      matt #endif
    177       1.2      matt #elif defined(PIXIS)
    178       1.2      matt static const uint32_t pixis_spd_map[8] = {
    179       1.2      matt     [PX_SPD_33MHZ] = 33333333,
    180       1.2      matt     [PX_SPD_40MHZ] = 40000000,
    181       1.2      matt     [PX_SPD_50MHZ] = 50000000,
    182       1.2      matt     [PX_SPD_66MHZ] = 66666666,
    183       1.2      matt     [PX_SPD_83MHZ] = 83333333,
    184       1.6      matt     [PX_SPD_100MHZ] = 100000000,
    185       1.2      matt     [PX_SPD_133MHZ] = 133333333,
    186       1.2      matt     [PX_SPD_166MHZ] = 166666667,
    187       1.2      matt };
    188       1.2      matt static uint8_t pixis_spd;
    189       1.6      matt #ifndef SYS_CLK
    190       1.2      matt static uint64_t e500_sys_clk;
    191       1.6      matt #endif
    192       1.6      matt #elif !defined(SYS_CLK)
    193       1.2      matt static uint64_t e500_sys_clk = 66666667; /* 66.666667Mhz */
    194       1.2      matt #endif
    195       1.2      matt 
    196       1.2      matt static int e500_cngetc(dev_t);
    197       1.2      matt static void e500_cnputc(dev_t, int);
    198       1.2      matt 
    199       1.2      matt static struct consdev e500_earlycons = {
    200       1.2      matt 	.cn_getc = e500_cngetc,
    201       1.2      matt 	.cn_putc = e500_cnputc,
    202       1.2      matt 	.cn_pollc = nullcnpollc,
    203       1.2      matt };
    204       1.2      matt 
    205       1.2      matt /*
    206       1.2      matt  * List of port-specific devices to attach to the processor local bus.
    207       1.2      matt  */
    208       1.2      matt static const struct cpunode_locators mpc8548_cpunode_locs[] = {
    209       1.6      matt 	{ "cpu", 0, 0, 0, 0, { 0 }, 0,	/* not a real device */
    210      1.25      matt 		{ 0xffff, SVR_MPC8572v1 >> 16, SVR_P2020v2 >> 16,
    211  1.29.2.2  jdolecek 		  SVR_P1025v1 >> 16, SVR_P1023v1 >> 16 } },
    212  1.29.2.2  jdolecek #if defined(MPC8572) || defined(P2020) || defined(P1025) \
    213  1.29.2.2  jdolecek     || defined(P1023)
    214       1.6      matt 	{ "cpu", 0, 0, 1, 0, { 0 }, 0,	/* not a real device */
    215      1.25      matt 		{ SVR_MPC8572v1 >> 16, SVR_P2020v2 >> 16,
    216  1.29.2.2  jdolecek 		  SVR_P1025v1 >> 16, SVR_P1023v1 >> 16 } },
    217       1.6      matt 	{ "cpu", 0, 0, 2, 0, { 0 }, 0,	/* not a real device */
    218      1.25      matt 		{ SVR_MPC8572v1 >> 16, SVR_P2020v2 >> 16,
    219  1.29.2.2  jdolecek 		  SVR_P1025v1 >> 16, SVR_P1023v1 >> 16 } },
    220       1.6      matt #endif
    221       1.2      matt 	{ "wdog" },	/* not a real device */
    222       1.3      matt 	{ "duart", DUART1_BASE, 2*DUART_SIZE, 0,
    223       1.3      matt 		1, { ISOURCE_DUART },
    224       1.2      matt 		1 + ilog2(DEVDISR_DUART) },
    225       1.3      matt 	{ "tsec", ETSEC1_BASE, ETSEC_SIZE, 1,
    226       1.3      matt 		3, { ISOURCE_ETSEC1_TX, ISOURCE_ETSEC1_RX, ISOURCE_ETSEC1_ERR },
    227      1.26      matt 		1 + ilog2(DEVDISR_TSEC1),
    228  1.29.2.2  jdolecek 		{ 0xffff, SVR_P1025v1 >> 16, SVR_P1023v1 >> 16 } },
    229      1.26      matt #if defined(P1025)
    230      1.28      matt 	{ "mdio", ETSEC1_BASE, ETSEC_SIZE, 1,
    231      1.28      matt 		0, { },
    232      1.28      matt 		1 + ilog2(DEVDISR_TSEC1),
    233      1.28      matt 		{ SVR_P1025v1 >> 16 } },
    234      1.26      matt 	{ "tsec", ETSEC1_G0_BASE, ETSEC_SIZE, 1,
    235      1.26      matt 		3, { ISOURCE_ETSEC1_TX, ISOURCE_ETSEC1_RX, ISOURCE_ETSEC1_ERR },
    236      1.26      matt 		1 + ilog2(DEVDISR_TSEC1),
    237      1.26      matt 		{ SVR_P1025v1 >> 16 } },
    238      1.26      matt #if 0
    239      1.26      matt 	{ "tsec", ETSEC1_G1_BASE, ETSEC_SIZE, 1,
    240      1.26      matt 		3, { ISOURCE_ETSEC1_G1_TX, ISOURCE_ETSEC1_G1_RX,
    241      1.26      matt 		     ISOURCE_ETSEC1_G1_ERR },
    242      1.26      matt 		1 + ilog2(DEVDISR_TSEC1),
    243      1.26      matt 		{ SVR_P1025v1 >> 16 } },
    244      1.26      matt #endif
    245      1.26      matt #endif
    246      1.25      matt #if defined(MPC8548) || defined(MPC8555) || defined(MPC8572) \
    247      1.26      matt     || defined(P2020)
    248       1.3      matt 	{ "tsec", ETSEC2_BASE, ETSEC_SIZE, 2,
    249       1.3      matt 		3, { ISOURCE_ETSEC2_TX, ISOURCE_ETSEC2_RX, ISOURCE_ETSEC2_ERR },
    250       1.3      matt 		1 + ilog2(DEVDISR_TSEC2),
    251       1.3      matt 		{ SVR_MPC8548v1 >> 16, SVR_MPC8555v1 >> 16,
    252      1.25      matt 		  SVR_MPC8572v1 >> 16, SVR_P2020v2 >> 16,
    253      1.25      matt 		  SVR_P1025v1 >> 16 } },
    254       1.2      matt #endif
    255      1.26      matt #if defined(P1025)
    256      1.28      matt 	{ "mdio", ETSEC2_BASE, ETSEC_SIZE, 2,
    257      1.28      matt 		0, { },
    258      1.28      matt 		1 + ilog2(DEVDISR_TSEC2),
    259      1.28      matt 		{ SVR_P1025v1 >> 16 } },
    260      1.26      matt 	{ "tsec", ETSEC2_G0_BASE, ETSEC_SIZE, 2,
    261      1.26      matt 		3, { ISOURCE_ETSEC2_TX, ISOURCE_ETSEC2_RX, ISOURCE_ETSEC2_ERR },
    262      1.26      matt 		1 + ilog2(DEVDISR_TSEC2),
    263      1.26      matt 		{ SVR_P1025v1 >> 16 } },
    264      1.26      matt #if 0
    265      1.26      matt 	{ "tsec", ETSEC2_G1_BASE, ETSEC_SIZE, 5,
    266      1.26      matt 		3, { ISOURCE_ETSEC2_G1_TX, ISOURCE_ETSEC2_G1_RX,
    267      1.26      matt 		     ISOURCE_ETSEC2_G1_ERR },
    268      1.26      matt 		1 + ilog2(DEVDISR_TSEC2),
    269      1.26      matt 		{ SVR_P1025v1 >> 16 } },
    270      1.26      matt #endif
    271      1.26      matt #endif
    272       1.2      matt #if defined(MPC8544) || defined(MPC8536)
    273       1.3      matt 	{ "tsec", ETSEC3_BASE, ETSEC_SIZE, 2,
    274       1.3      matt 		3, { ISOURCE_ETSEC3_TX, ISOURCE_ETSEC3_RX, ISOURCE_ETSEC3_ERR },
    275       1.3      matt 		1 + ilog2(DEVDISR_TSEC3),
    276       1.3      matt 		{ SVR_MPC8536v1 >> 16, SVR_MPC8544v1 >> 16 } },
    277       1.3      matt #endif
    278      1.26      matt #if defined(MPC8548) || defined(MPC8572) || defined(P2020)
    279       1.3      matt 	{ "tsec", ETSEC3_BASE, ETSEC_SIZE, 3,
    280       1.3      matt 		3, { ISOURCE_ETSEC3_TX, ISOURCE_ETSEC3_RX, ISOURCE_ETSEC3_ERR },
    281       1.3      matt 		1 + ilog2(DEVDISR_TSEC3),
    282       1.3      matt 		{ SVR_MPC8548v1 >> 16, SVR_MPC8572v1 >> 16,
    283      1.26      matt 		  SVR_P2020v2 >> 16 } },
    284      1.26      matt #endif
    285      1.26      matt #if defined(P1025)
    286      1.28      matt 	{ "mdio", ETSEC3_BASE, ETSEC_SIZE, 3,
    287      1.28      matt 		0, { },
    288      1.28      matt 		1 + ilog2(DEVDISR_TSEC3),
    289      1.28      matt 		{ SVR_P1025v1 >> 16 } },
    290      1.26      matt 	{ "tsec", ETSEC3_G0_BASE, ETSEC_SIZE, 3,
    291      1.26      matt 		3, { ISOURCE_ETSEC3_TX, ISOURCE_ETSEC3_RX, ISOURCE_ETSEC3_ERR },
    292      1.26      matt 		1 + ilog2(DEVDISR_TSEC3),
    293      1.26      matt 		{ SVR_P1025v1 >> 16 } },
    294      1.26      matt #if 0
    295      1.26      matt 	{ "tsec", ETSEC3_G1_BASE, ETSEC_SIZE, 3,
    296      1.26      matt 		3, { ISOURCE_ETSEC3_G1_TX, ISOURCE_ETSEC3_G1_RX,
    297      1.26      matt 		     ISOURCE_ETSEC3_G1_ERR },
    298      1.26      matt 		1 + ilog2(DEVDISR_TSEC3),
    299      1.26      matt 		{ SVR_P1025v1 >> 16 } },
    300      1.26      matt #endif
    301       1.3      matt #endif
    302       1.3      matt #if defined(MPC8548) || defined(MPC8572)
    303       1.3      matt 	{ "tsec", ETSEC4_BASE, ETSEC_SIZE, 4,
    304       1.3      matt 		3, { ISOURCE_ETSEC4_TX, ISOURCE_ETSEC4_RX, ISOURCE_ETSEC4_ERR },
    305       1.3      matt 		1 + ilog2(DEVDISR_TSEC4),
    306       1.3      matt 		{ SVR_MPC8548v1 >> 16, SVR_MPC8572v1 >> 16 } },
    307       1.3      matt #endif
    308       1.3      matt 	{ "diic", I2C1_BASE, 2*I2C_SIZE, 0,
    309       1.3      matt 		1, { ISOURCE_I2C },
    310       1.3      matt 		1 + ilog2(DEVDISR_I2C) },
    311       1.2      matt 	/* MPC8572 doesn't have any GPIO */
    312       1.3      matt 	{ "gpio", GLOBAL_BASE, GLOBAL_SIZE, 0,
    313       1.3      matt 		1, { ISOURCE_GPIO },
    314       1.3      matt 		0,
    315       1.3      matt 		{ 0xffff, SVR_MPC8572v1 >> 16 } },
    316       1.3      matt 	{ "ddrc", DDRC1_BASE, DDRC_SIZE, 0,
    317       1.3      matt 		1, { ISOURCE_DDR },
    318       1.3      matt 		1 + ilog2(DEVDISR_DDR_15),
    319       1.3      matt 		{ 0xffff, SVR_MPC8572v1 >> 16, SVR_MPC8536v1 >> 16 } },
    320       1.3      matt #if defined(MPC8536)
    321       1.3      matt 	{ "ddrc", DDRC1_BASE, DDRC_SIZE, 0,
    322       1.3      matt 		1, { ISOURCE_DDR },
    323       1.3      matt 		1 + ilog2(DEVDISR_DDR_16),
    324       1.3      matt 		{ SVR_MPC8536v1 >> 16 } },
    325       1.3      matt #endif
    326       1.3      matt #if defined(MPC8572)
    327       1.3      matt 	{ "ddrc", DDRC1_BASE, DDRC_SIZE, 1,
    328       1.3      matt 		1, { ISOURCE_DDR },
    329       1.3      matt 		1 + ilog2(DEVDISR_DDR_15),
    330       1.3      matt 		{ SVR_MPC8572v1 >> 16 } },
    331      1.21      matt 	{ "ddrc", DDRC2_BASE, DDRC_SIZE, 2,
    332       1.3      matt 		1, { ISOURCE_DDR },
    333       1.3      matt 		1 + ilog2(DEVDISR_DDR2_14),
    334       1.3      matt 		{ SVR_MPC8572v1 >> 16 } },
    335       1.2      matt #endif
    336       1.6      matt 	{ "lbc", LBC_BASE, LBC_SIZE, 0,
    337       1.6      matt 		1, { ISOURCE_LBC },
    338       1.6      matt 		1 + ilog2(DEVDISR_LBC) },
    339       1.2      matt #if defined(MPC8544) || defined(MPC8536)
    340       1.3      matt 	{ "pcie", PCIE1_BASE, PCI_SIZE, 1,
    341       1.3      matt 		1, { ISOURCE_PCIEX },
    342       1.3      matt 		1 + ilog2(DEVDISR_PCIE),
    343       1.3      matt 		{ SVR_MPC8536v1 >> 16, SVR_MPC8544v1 >> 16 } },
    344       1.3      matt 	{ "pcie", PCIE2_MPC8544_BASE, PCI_SIZE, 2,
    345       1.3      matt 		1, { ISOURCE_PCIEX2 },
    346       1.3      matt 		1 + ilog2(DEVDISR_PCIE2),
    347       1.3      matt 		{ SVR_MPC8536v1 >> 16, SVR_MPC8544v1 >> 16 } },
    348       1.3      matt 	{ "pcie", PCIE3_MPC8544_BASE, PCI_SIZE, 3,
    349       1.3      matt 		1, { ISOURCE_PCIEX3 },
    350       1.3      matt 		1 + ilog2(DEVDISR_PCIE3),
    351       1.3      matt 		{ SVR_MPC8536v1 >> 16, SVR_MPC8544v1 >> 16 } },
    352       1.3      matt 	{ "pci", PCIX1_MPC8544_BASE, PCI_SIZE, 0,
    353       1.3      matt 		1, { ISOURCE_PCI1 },
    354       1.3      matt 		1 + ilog2(DEVDISR_PCI1),
    355       1.3      matt 		{ SVR_MPC8536v1 >> 16, SVR_MPC8544v1 >> 16 } },
    356       1.2      matt #endif
    357       1.2      matt #ifdef MPC8548
    358       1.3      matt 	{ "pcie", PCIE1_BASE, PCI_SIZE, 0,
    359       1.3      matt 		1, { ISOURCE_PCIEX },
    360       1.3      matt 		1 + ilog2(DEVDISR_PCIE),
    361       1.4      matt 		{ SVR_MPC8548v1 >> 16 }, },
    362       1.3      matt 	{ "pci", PCIX1_MPC8548_BASE, PCI_SIZE, 1,
    363       1.3      matt 		1, { ISOURCE_PCI1 },
    364       1.3      matt 		1 + ilog2(DEVDISR_PCI1),
    365       1.4      matt 		{ SVR_MPC8548v1 >> 16 }, },
    366       1.3      matt 	{ "pci", PCIX2_MPC8548_BASE, PCI_SIZE, 2,
    367       1.3      matt 		1, { ISOURCE_PCI2 },
    368       1.3      matt 		1 + ilog2(DEVDISR_PCI2),
    369       1.4      matt 		{ SVR_MPC8548v1 >> 16 }, },
    370       1.3      matt #endif
    371  1.29.2.2  jdolecek #if defined(MPC8572) || defined(P1025) || defined(P2020) \
    372  1.29.2.2  jdolecek     || defined(P1023)
    373       1.3      matt 	{ "pcie", PCIE1_BASE, PCI_SIZE, 1,
    374       1.3      matt 		1, { ISOURCE_PCIEX },
    375       1.3      matt 		1 + ilog2(DEVDISR_PCIE),
    376      1.25      matt 		{ SVR_MPC8572v1 >> 16, SVR_P2020v2 >> 16,
    377  1.29.2.2  jdolecek 		  SVR_P1025v1 >> 16, SVR_P1023v1 >> 16 } },
    378       1.3      matt 	{ "pcie", PCIE2_MPC8572_BASE, PCI_SIZE, 2,
    379       1.3      matt 		1, { ISOURCE_PCIEX2 },
    380       1.3      matt 		1 + ilog2(DEVDISR_PCIE2),
    381      1.25      matt 		{ SVR_MPC8572v1 >> 16, SVR_P2020v2 >> 16,
    382  1.29.2.2  jdolecek 		  SVR_P1025v1 >> 16, SVR_P1023v1 >> 16 } },
    383      1.27      matt #endif
    384  1.29.2.2  jdolecek #if defined(MPC8572) || defined(P2020) || defined(_P1023)
    385       1.3      matt 	{ "pcie", PCIE3_MPC8572_BASE, PCI_SIZE, 3,
    386       1.3      matt 		1, { ISOURCE_PCIEX3_MPC8572 },
    387       1.3      matt 		1 + ilog2(DEVDISR_PCIE3),
    388  1.29.2.2  jdolecek 		{ SVR_MPC8572v1 >> 16, SVR_P2020v2 >> 16,
    389  1.29.2.2  jdolecek 		  SVR_P1023v1 >> 16 } },
    390       1.3      matt #endif
    391  1.29.2.2  jdolecek #if defined(MPC8536) || defined(P1025) || defined(P2020) \
    392  1.29.2.2  jdolecek     || defined(P1023)
    393       1.3      matt 	{ "ehci", USB1_BASE, USB_SIZE, 1,
    394       1.3      matt 		1, { ISOURCE_USB1 },
    395       1.3      matt 		1 + ilog2(DEVDISR_USB1),
    396      1.25      matt 		{ SVR_MPC8536v1 >> 16, SVR_P2020v2 >> 16,
    397  1.29.2.2  jdolecek 		  SVR_P1025v1 >> 16, SVR_P1023v1 >> 16 } },
    398       1.2      matt #endif
    399       1.2      matt #ifdef MPC8536
    400       1.3      matt 	{ "ehci", USB2_BASE, USB_SIZE, 2,
    401       1.3      matt 		1, { ISOURCE_USB2 },
    402       1.3      matt 		1 + ilog2(DEVDISR_USB2),
    403       1.3      matt 		{ SVR_MPC8536v1 >> 16 }, },
    404       1.3      matt 	{ "ehci", USB3_BASE, USB_SIZE, 3,
    405       1.3      matt 		1, { ISOURCE_USB3 },
    406       1.3      matt 		1 + ilog2(DEVDISR_USB3),
    407       1.3      matt 		{ SVR_MPC8536v1 >> 16 }, },
    408       1.3      matt 	{ "sata", SATA1_BASE, SATA_SIZE, 1,
    409       1.3      matt 		1, { ISOURCE_SATA1 },
    410       1.3      matt 		1 + ilog2(DEVDISR_SATA1),
    411       1.3      matt 		{ SVR_MPC8536v1 >> 16 }, },
    412       1.3      matt 	{ "sata", SATA2_BASE, SATA_SIZE, 2,
    413       1.3      matt 		1, { ISOURCE_SATA2 },
    414       1.3      matt 		1 + ilog2(DEVDISR_SATA2),
    415       1.3      matt 		{ SVR_MPC8536v1 >> 16 }, },
    416       1.3      matt 	{ "spi", SPI_BASE, SPI_SIZE, 0,
    417       1.3      matt 		1, { ISOURCE_SPI },
    418       1.3      matt 		1 + ilog2(DEVDISR_SPI_15),
    419       1.3      matt 		{ SVR_MPC8536v1 >> 16 }, },
    420       1.3      matt 	{ "sdhc", ESDHC_BASE, ESDHC_SIZE, 0,
    421       1.3      matt 		1, { ISOURCE_ESDHC },
    422       1.3      matt 		1 + ilog2(DEVDISR_ESDHC_12),
    423       1.3      matt 		{ SVR_MPC8536v1 >> 16 }, },
    424       1.3      matt #endif
    425  1.29.2.2  jdolecek #if defined(P1025) || defined(P2020) || defined(P1023)
    426       1.3      matt 	{ "spi", SPI_BASE, SPI_SIZE, 0,
    427       1.3      matt 		1, { ISOURCE_SPI },
    428       1.3      matt 		1 + ilog2(DEVDISR_SPI_28),
    429  1.29.2.2  jdolecek 		{ SVR_P2020v2 >> 16, SVR_P1025v1 >> 16,
    430  1.29.2.2  jdolecek 		  SVR_P1023v1 >> 16 }, },
    431  1.29.2.2  jdolecek #endif
    432  1.29.2.2  jdolecek #if defined(P1025) || defined(P2020)
    433       1.3      matt 	{ "sdhc", ESDHC_BASE, ESDHC_SIZE, 0,
    434       1.3      matt 		1, { ISOURCE_ESDHC },
    435       1.3      matt 		1 + ilog2(DEVDISR_ESDHC_10),
    436      1.25      matt 		{ SVR_P2020v2 >> 16, SVR_P1025v1 >> 16 }, },
    437       1.2      matt #endif
    438       1.2      matt 	//{ "sec", RNG_BASE, RNG_SIZE, 0, 0, },
    439       1.2      matt 	{ NULL }
    440       1.2      matt };
    441       1.2      matt 
    442       1.2      matt static int
    443       1.2      matt e500_cngetc(dev_t dv)
    444       1.2      matt {
    445       1.2      matt 	volatile uint8_t * const com0addr = (void *)(GUR_BASE+CONSADDR);
    446       1.2      matt 
    447       1.2      matt         if ((com0addr[com_lsr] & LSR_RXRDY) == 0)
    448       1.2      matt 		return -1;
    449       1.2      matt 
    450       1.2      matt 	return com0addr[com_data] & 0xff;
    451       1.2      matt }
    452       1.2      matt 
    453       1.2      matt static void
    454       1.2      matt e500_cnputc(dev_t dv, int c)
    455       1.2      matt {
    456       1.2      matt 	volatile uint8_t * const com0addr = (void *)(GUR_BASE+CONSADDR);
    457       1.2      matt 	int timo = 150000;
    458       1.2      matt 
    459       1.2      matt 	while ((com0addr[com_lsr] & LSR_TXRDY) == 0 && --timo > 0)
    460       1.2      matt 		;
    461       1.2      matt 
    462       1.2      matt 	com0addr[com_data] = c;
    463       1.2      matt 	__asm("mbar");
    464       1.2      matt 
    465       1.2      matt 	while ((com0addr[com_lsr] & LSR_TSRE) == 0 && --timo > 0)
    466       1.2      matt 		;
    467       1.2      matt }
    468       1.2      matt 
    469       1.2      matt static void *
    470      1.15      matt gur_tlb_mapiodev(paddr_t pa, psize_t len, bool prefetchable)
    471       1.2      matt {
    472      1.15      matt 	if (prefetchable)
    473      1.15      matt 		return NULL;
    474       1.2      matt 	if (pa < gur_bst.pbs_offset)
    475       1.2      matt 		return NULL;
    476       1.2      matt 	if (pa + len > gur_bst.pbs_offset + gur_bst.pbs_limit)
    477       1.2      matt 		return NULL;
    478       1.2      matt 	return (void *)pa;
    479       1.2      matt }
    480       1.2      matt 
    481      1.15      matt static void *(* const early_tlb_mapiodev)(paddr_t, psize_t, bool) = gur_tlb_mapiodev;
    482       1.2      matt 
    483       1.2      matt static void
    484       1.2      matt e500_cpu_reset(void)
    485       1.2      matt {
    486       1.2      matt 	__asm volatile("sync");
    487       1.2      matt 	cpu_write_4(GLOBAL_BASE + RSTCR, HRESET_REQ);
    488       1.2      matt 	__asm volatile("msync;isync");
    489       1.2      matt }
    490       1.2      matt 
    491       1.2      matt static psize_t
    492       1.2      matt memprobe(vaddr_t endkernel)
    493       1.2      matt {
    494       1.2      matt 	phys_ram_seg_t *mr;
    495       1.6      matt 	paddr_t boot_page = cpu_read_4(GUR_BPTR);
    496       1.6      matt 	printf(" bptr=%"PRIxPADDR, boot_page);
    497       1.6      matt 	if (boot_page & BPTR_EN) {
    498       1.6      matt 		/*
    499       1.6      matt 		 * shift it to an address
    500       1.6      matt 		 */
    501       1.6      matt 		boot_page = (boot_page & BPTR_BOOT_PAGE) << PAGE_SHIFT;
    502       1.6      matt 	} else {
    503       1.6      matt 		boot_page = ~(paddr_t)0;
    504       1.6      matt 	}
    505       1.2      matt 
    506       1.2      matt 	/*
    507       1.2      matt 	 * First we need to find out how much physical memory we have.
    508       1.2      matt 	 * We could let our bootloader tell us, but it's almost as easy
    509       1.2      matt 	 * to ask the DDR memory controller.
    510       1.2      matt 	 */
    511       1.2      matt 	mr = physmemr;
    512       1.2      matt 	for (u_int i = 0; i < 4; i++) {
    513       1.2      matt 		uint32_t v = cpu_read_4(DDRC1_BASE + CS_CONFIG(i));
    514       1.2      matt 		if (v & CS_CONFIG_EN) {
    515       1.2      matt 			v = cpu_read_4(DDRC1_BASE + CS_BNDS(i));
    516       1.6      matt 			if (v == 0)
    517       1.6      matt 				continue;
    518       1.2      matt 			mr->start = BNDS_SA_GET(v);
    519       1.2      matt 			mr->size  = BNDS_SIZE_GET(v);
    520      1.20      matt #ifdef MEMSIZE
    521      1.20      matt 			if (mr->start >= MEMSIZE)
    522      1.20      matt 				continue;
    523      1.20      matt 			if (mr->start + mr->size > MEMSIZE)
    524      1.20      matt 				mr->size = MEMSIZE - mr->start;
    525      1.20      matt #endif
    526       1.6      matt #if 0
    527       1.6      matt 			printf(" [%zd]={%#"PRIx64"@%#"PRIx64"}",
    528       1.6      matt 			    mr - physmemr, mr->size, mr->start);
    529       1.6      matt #endif
    530       1.2      matt 			mr++;
    531       1.2      matt 		}
    532       1.2      matt 	}
    533       1.2      matt 
    534       1.2      matt 	if (mr == physmemr)
    535       1.2      matt 		panic("no memory configured!");
    536       1.2      matt 
    537       1.2      matt 	/*
    538       1.2      matt 	 * Sort memory regions from low to high and coalesce adjacent regions
    539       1.2      matt 	 */
    540       1.2      matt 	u_int cnt = mr - physmemr;
    541       1.2      matt 	if (cnt > 1) {
    542       1.2      matt 		for (u_int i = 0; i < cnt - 1; i++) {
    543       1.2      matt 			for (u_int j = i + 1; j < cnt; j++) {
    544       1.2      matt 				if (physmemr[j].start < physmemr[i].start) {
    545       1.2      matt 					phys_ram_seg_t tmp = physmemr[i];
    546       1.2      matt 					physmemr[i] = physmemr[j];
    547       1.2      matt 					physmemr[j] = tmp;
    548       1.2      matt 				}
    549       1.2      matt 			}
    550       1.2      matt 		}
    551       1.2      matt 		mr = physmemr;
    552      1.16      matt 		for (u_int i = 0; i + 1 < cnt; i++, mr++) {
    553       1.2      matt 			if (mr->start + mr->size == mr[1].start) {
    554       1.2      matt 				mr->size += mr[1].size;
    555      1.16      matt 				for (u_int j = 1; i + j + 1 < cnt; j++)
    556       1.2      matt 					mr[j] = mr[j+1];
    557       1.2      matt 				cnt--;
    558       1.2      matt 			}
    559       1.2      matt 		}
    560      1.17      matt 	} else if (cnt == 0) {
    561      1.16      matt 		panic("%s: no memory found", __func__);
    562       1.2      matt 	}
    563       1.2      matt 
    564       1.2      matt 	/*
    565       1.2      matt 	 * Copy physical memory to available memory.
    566       1.2      matt 	 */
    567       1.2      matt 	memcpy(availmemr, physmemr, cnt * sizeof(physmemr[0]));
    568       1.2      matt 
    569       1.2      matt 	/*
    570       1.2      matt 	 * Adjust available memory to skip kernel at start of memory.
    571       1.2      matt 	 */
    572       1.2      matt 	availmemr[0].size -= endkernel - availmemr[0].start;
    573       1.2      matt 	availmemr[0].start = endkernel;
    574       1.2      matt 
    575       1.6      matt 	mr = availmemr;
    576       1.6      matt 	for (u_int i = 0; i < cnt; i++, mr++) {
    577       1.6      matt 		/*
    578       1.6      matt 		 * U-boot reserves a boot-page on multi-core chips.
    579       1.6      matt 		 * We need to make sure that we never disturb it.
    580       1.6      matt 		 */
    581       1.6      matt 		const paddr_t mr_end = mr->start + mr->size;
    582       1.6      matt 		if (mr_end > boot_page && boot_page >= mr->start) {
    583       1.6      matt 			/*
    584       1.6      matt 			 * Normally u-boot will put in at the end
    585       1.6      matt 			 * of memory.  But in case it doesn't, deal
    586       1.6      matt 			 * with all possibilities.
    587       1.6      matt 			 */
    588       1.6      matt 			if (boot_page + PAGE_SIZE == mr_end) {
    589       1.6      matt 				mr->size -= PAGE_SIZE;
    590       1.6      matt 			} else if (boot_page == mr->start) {
    591       1.6      matt 				mr->start += PAGE_SIZE;
    592       1.6      matt 				mr->size -= PAGE_SIZE;
    593       1.6      matt 			} else {
    594       1.6      matt 				mr->size = boot_page - mr->start;
    595       1.6      matt 				mr++;
    596       1.6      matt 				for (u_int j = cnt; j > i + 1; j--) {
    597       1.6      matt 					availmemr[j] = availmemr[j-1];
    598       1.6      matt 				}
    599       1.6      matt 				cnt++;
    600       1.6      matt 				mr->start = boot_page + PAGE_SIZE;
    601       1.6      matt 				mr->size = mr_end - mr->start;
    602       1.6      matt 			}
    603       1.6      matt 			break;
    604       1.6      matt 		}
    605       1.6      matt 	}
    606       1.6      matt 
    607       1.2      matt 	/*
    608       1.2      matt 	 * Steal pages at the end of memory for the kernel message buffer.
    609       1.2      matt 	 */
    610      1.19      matt 	mr = availmemr + cnt - 1;
    611      1.19      matt 	KASSERT(mr->size >= round_page(MSGBUFSIZE));
    612      1.19      matt 	mr->size -= round_page(MSGBUFSIZE);
    613      1.19      matt 	msgbuf_paddr = (uintptr_t)(mr->start + mr->size);
    614       1.2      matt 
    615       1.2      matt 	/*
    616       1.2      matt 	 * Calculate physmem.
    617       1.2      matt 	 */
    618       1.2      matt 	for (u_int i = 0; i < cnt; i++)
    619       1.2      matt 		physmem += atop(physmemr[i].size);
    620       1.2      matt 
    621       1.2      matt 	nmemr = cnt;
    622       1.2      matt 	return physmemr[cnt-1].start + physmemr[cnt-1].size;
    623       1.2      matt }
    624       1.2      matt 
    625       1.2      matt void
    626       1.2      matt consinit(void)
    627       1.2      matt {
    628       1.2      matt 	static bool attached = false;
    629       1.2      matt 
    630       1.2      matt 	if (attached)
    631       1.2      matt 		return;
    632       1.2      matt 	attached = true;
    633       1.2      matt 
    634       1.2      matt 	if (comcnfreq == -1) {
    635       1.2      matt 		const uint32_t porpplsr = cpu_read_4(GLOBAL_BASE + PORPLLSR);
    636       1.2      matt 		const uint32_t plat_ratio = PLAT_RATIO_GET(porpplsr);
    637       1.2      matt 		comcnfreq = e500_sys_clk * plat_ratio;
    638       1.2      matt 		printf(" comcnfreq=%u", comcnfreq);
    639       1.2      matt 	}
    640       1.2      matt 
    641       1.2      matt 	comcnattach(&gur_bst, comcnaddr, comcnspeed, comcnfreq,
    642       1.2      matt 	    COM_TYPE_NORMAL, comcnmode);
    643       1.2      matt }
    644       1.2      matt 
    645       1.2      matt void
    646       1.2      matt cpu_probe_cache(void)
    647       1.2      matt {
    648       1.2      matt 	struct cpu_info * const ci = curcpu();
    649       1.2      matt 	const uint32_t l1cfg0 = mfspr(SPR_L1CFG0);
    650  1.29.2.2  jdolecek 	const int dcache_assoc = L1CFG_CNWAY_GET(l1cfg0);
    651       1.2      matt 
    652       1.2      matt 	ci->ci_ci.dcache_size = L1CFG_CSIZE_GET(l1cfg0);
    653       1.2      matt 	ci->ci_ci.dcache_line_size = 32 << L1CFG_CBSIZE_GET(l1cfg0);
    654       1.2      matt 
    655       1.2      matt 	if (L1CFG_CARCH_GET(l1cfg0) == L1CFG_CARCH_HARVARD) {
    656       1.2      matt 		const uint32_t l1cfg1 = mfspr(SPR_L1CFG1);
    657       1.2      matt 
    658       1.2      matt 		ci->ci_ci.icache_size = L1CFG_CSIZE_GET(l1cfg1);
    659       1.2      matt 		ci->ci_ci.icache_line_size = 32 << L1CFG_CBSIZE_GET(l1cfg1);
    660       1.2      matt 	} else {
    661       1.2      matt 		ci->ci_ci.icache_size = ci->ci_ci.dcache_size;
    662       1.2      matt 		ci->ci_ci.icache_line_size = ci->ci_ci.dcache_line_size;
    663       1.2      matt 	}
    664       1.2      matt 
    665  1.29.2.2  jdolecek 	/*
    666  1.29.2.2  jdolecek 	 * Possibly recolor.
    667  1.29.2.2  jdolecek 	 */
    668  1.29.2.2  jdolecek 	uvm_page_recolor(atop(curcpu()->ci_ci.dcache_size / dcache_assoc));
    669  1.29.2.2  jdolecek 
    670       1.2      matt #ifdef DEBUG
    671       1.2      matt 	uint32_t l1csr0 = mfspr(SPR_L1CSR0);
    672       1.2      matt 	if ((L1CSR_CE & l1csr0) == 0)
    673       1.2      matt 		printf(" DC=off");
    674       1.2      matt 
    675       1.2      matt 	uint32_t l1csr1 = mfspr(SPR_L1CSR1);
    676       1.2      matt 	if ((L1CSR_CE & l1csr1) == 0)
    677       1.2      matt 		printf(" IC=off");
    678       1.2      matt #endif
    679       1.2      matt }
    680       1.2      matt 
    681       1.3      matt static uint16_t
    682       1.3      matt getsvr(void)
    683       1.3      matt {
    684       1.3      matt 	uint16_t svr = mfspr(SPR_SVR) >> 16;
    685       1.3      matt 
    686       1.3      matt 	svr &= ~0x8;		/* clear security bit */
    687       1.3      matt 	switch (svr) {
    688       1.3      matt 	case SVR_MPC8543v1 >> 16:	return SVR_MPC8548v1 >> 16;
    689       1.3      matt 	case SVR_MPC8541v1 >> 16:	return SVR_MPC8555v1 >> 16;
    690       1.3      matt 	case SVR_P2010v2 >> 16:		return SVR_P2020v2 >> 16;
    691      1.25      matt 	case SVR_P1016v1 >> 16:		return SVR_P1025v1 >> 16;
    692  1.29.2.2  jdolecek 	case SVR_P1017v1 >> 16:		return SVR_P1023v1 >> 16;
    693       1.3      matt 	default:			return svr;
    694       1.3      matt 	}
    695       1.3      matt }
    696       1.3      matt 
    697       1.2      matt static const char *
    698       1.2      matt socname(uint32_t svr)
    699       1.2      matt {
    700       1.3      matt 	svr &= ~0x80000;	/* clear security bit */
    701       1.2      matt 	switch (svr >> 8) {
    702       1.5      matt 	case SVR_MPC8533 >> 8: return "MPC8533";
    703       1.3      matt 	case SVR_MPC8536v1 >> 8: return "MPC8536";
    704       1.3      matt 	case SVR_MPC8541v1 >> 8: return "MPC8541";
    705       1.2      matt 	case SVR_MPC8543v2 >> 8: return "MPC8543";
    706       1.2      matt 	case SVR_MPC8544v1 >> 8: return "MPC8544";
    707       1.3      matt 	case SVR_MPC8545v2 >> 8: return "MPC8545";
    708       1.3      matt 	case SVR_MPC8547v2 >> 8: return "MPC8547";
    709       1.3      matt 	case SVR_MPC8548v2 >> 8: return "MPC8548";
    710       1.3      matt 	case SVR_MPC8555v1 >> 8: return "MPC8555";
    711       1.3      matt 	case SVR_MPC8568v1 >> 8: return "MPC8568";
    712       1.3      matt 	case SVR_MPC8567v1 >> 8: return "MPC8567";
    713       1.3      matt 	case SVR_MPC8572v1 >> 8: return "MPC8572";
    714       1.3      matt 	case SVR_P2020v2 >> 8: return "P2020";
    715       1.3      matt 	case SVR_P2010v2 >> 8: return "P2010";
    716      1.25      matt 	case SVR_P1016v1 >> 8: return "P1016";
    717  1.29.2.2  jdolecek 	case SVR_P1017v1 >> 8: return "P1017";
    718  1.29.2.2  jdolecek 	case SVR_P1023v1 >> 8: return "P1023";
    719      1.25      matt 	case SVR_P1025v1 >> 8: return "P1025";
    720       1.2      matt 	default:
    721       1.2      matt 		panic("%s: unknown SVR %#x", __func__, svr);
    722       1.2      matt 	}
    723       1.2      matt }
    724       1.2      matt 
    725       1.2      matt static void
    726       1.2      matt e500_tlb_print(device_t self, const char *name, uint32_t tlbcfg)
    727       1.2      matt {
    728       1.2      matt 	static const char units[16] = "KKKKKMMMMMGGGGGT";
    729       1.2      matt 
    730       1.2      matt 	const uint32_t minsize = 1U << (2 * TLBCFG_MINSIZE(tlbcfg));
    731       1.2      matt 	const uint32_t assoc = TLBCFG_ASSOC(tlbcfg);
    732       1.2      matt 	const u_int maxsize_log4k = TLBCFG_MAXSIZE(tlbcfg);
    733       1.2      matt 	const uint64_t maxsize = 1ULL << (2 * maxsize_log4k % 10);
    734       1.2      matt 	const uint32_t nentries = TLBCFG_NENTRY(tlbcfg);
    735       1.2      matt 
    736       1.2      matt 	aprint_normal_dev(self, "%s:", name);
    737       1.2      matt 
    738       1.2      matt 	aprint_normal(" %u", nentries);
    739       1.2      matt 	if (TLBCFG_AVAIL_P(tlbcfg)) {
    740       1.2      matt 		aprint_normal(" variable-size (%uKB..%"PRIu64"%cB)",
    741       1.2      matt 		    minsize, maxsize, units[maxsize_log4k]);
    742       1.2      matt 	} else {
    743       1.2      matt 		aprint_normal(" fixed-size (%uKB)", minsize);
    744       1.2      matt 	}
    745       1.2      matt 	if (assoc == 0 || assoc == nentries)
    746       1.2      matt 		aprint_normal(" fully");
    747       1.2      matt 	else
    748       1.2      matt 		aprint_normal(" %u-way set", assoc);
    749       1.2      matt 	aprint_normal(" associative entries\n");
    750       1.2      matt }
    751       1.2      matt 
    752       1.2      matt static void
    753      1.14      matt cpu_print_info(struct cpu_info *ci)
    754       1.2      matt {
    755       1.2      matt 	uint64_t freq = board_info_get_number("processor-frequency");
    756      1.14      matt 	device_t self = ci->ci_dev;
    757       1.6      matt 
    758       1.2      matt 	char freqbuf[10];
    759       1.2      matt 	if (freq >= 999500000) {
    760       1.2      matt 		const uint32_t freq32 = (freq + 500000) / 10000000;
    761       1.2      matt 		snprintf(freqbuf, sizeof(freqbuf), "%u.%02u GHz",
    762       1.2      matt 		    freq32 / 100, freq32 % 100);
    763       1.2      matt 	} else {
    764       1.2      matt 		const uint32_t freq32 = (freq + 500000) / 1000000;
    765       1.2      matt 		snprintf(freqbuf, sizeof(freqbuf), "%u MHz", freq32);
    766       1.2      matt 	}
    767       1.2      matt 
    768       1.2      matt 	const uint32_t pvr = mfpvr();
    769       1.2      matt 	const uint32_t svr = mfspr(SPR_SVR);
    770       1.2      matt 	const uint32_t pir = mfspr(SPR_PIR);
    771       1.2      matt 
    772       1.2      matt 	aprint_normal_dev(self, "%s %s%s %u.%u with an e500%s %u.%u core, "
    773       1.2      matt 	   "ID %u%s\n",
    774       1.2      matt 	   freqbuf, socname(svr), (SVR_SECURITY_P(svr) ? "E" : ""),
    775       1.2      matt 	   (svr >> 4) & 15, svr & 15,
    776       1.2      matt 	   (pvr >> 16) == PVR_MPCe500v2 ? "v2" : "",
    777       1.2      matt 	   (pvr >> 4) & 15, pvr & 15,
    778       1.2      matt 	   pir, (pir == 0 ? " (Primary)" : ""));
    779       1.2      matt 
    780       1.2      matt 	const uint32_t l1cfg0 = mfspr(SPR_L1CFG0);
    781       1.2      matt 	aprint_normal_dev(self,
    782       1.2      matt 	    "%uKB/%uB %u-way L1 %s cache\n",
    783       1.2      matt 	    L1CFG_CSIZE_GET(l1cfg0) >> 10,
    784       1.2      matt 	    32 << L1CFG_CBSIZE_GET(l1cfg0),
    785       1.2      matt 	    L1CFG_CNWAY_GET(l1cfg0),
    786       1.2      matt 	    L1CFG_CARCH_GET(l1cfg0) == L1CFG_CARCH_HARVARD
    787       1.2      matt 		? "data" : "unified");
    788       1.2      matt 
    789       1.2      matt 	if (L1CFG_CARCH_GET(l1cfg0) == L1CFG_CARCH_HARVARD) {
    790       1.2      matt 		const uint32_t l1cfg1 = mfspr(SPR_L1CFG1);
    791       1.2      matt 		aprint_normal_dev(self,
    792       1.2      matt 		    "%uKB/%uB %u-way L1 %s cache\n",
    793       1.2      matt 		    L1CFG_CSIZE_GET(l1cfg1) >> 10,
    794       1.2      matt 		    32 << L1CFG_CBSIZE_GET(l1cfg1),
    795       1.2      matt 		    L1CFG_CNWAY_GET(l1cfg1),
    796       1.2      matt 		    "instruction");
    797       1.2      matt 	}
    798       1.2      matt 
    799       1.2      matt 	const uint32_t mmucfg = mfspr(SPR_MMUCFG);
    800       1.2      matt 	aprint_normal_dev(self,
    801       1.2      matt 	    "%u TLBs, %u concurrent %u-bit PIDs (%u total)\n",
    802       1.2      matt 	    MMUCFG_NTLBS_GET(mmucfg) + 1,
    803       1.2      matt 	    MMUCFG_NPIDS_GET(mmucfg),
    804       1.2      matt 	    MMUCFG_PIDSIZE_GET(mmucfg) + 1,
    805       1.2      matt 	    1 << (MMUCFG_PIDSIZE_GET(mmucfg) + 1));
    806       1.2      matt 
    807       1.2      matt 	e500_tlb_print(self, "tlb0", mfspr(SPR_TLB0CFG));
    808       1.2      matt 	e500_tlb_print(self, "tlb1", mfspr(SPR_TLB1CFG));
    809      1.14      matt }
    810      1.14      matt 
    811      1.14      matt #ifdef MULTIPROCESSOR
    812      1.14      matt static void
    813      1.14      matt e500_cpu_spinup(device_t self, struct cpu_info *ci)
    814      1.14      matt {
    815      1.14      matt 	uintptr_t spinup_table_addr = board_info_get_number("mp-spin-up-table");
    816      1.14      matt 	struct pglist splist;
    817      1.14      matt 
    818      1.14      matt 	if (spinup_table_addr == 0) {
    819      1.14      matt 		aprint_error_dev(self, "hatch failed (no spin-up table)");
    820      1.14      matt 		return;
    821      1.14      matt 	}
    822      1.14      matt 
    823      1.14      matt 	struct uboot_spinup_entry * const e = (void *)spinup_table_addr;
    824      1.14      matt 	volatile struct cpu_hatch_data * const h = &cpu_hatch_data;
    825      1.14      matt 	const size_t id = cpu_index(ci);
    826  1.29.2.1       tls 	kcpuset_t * const hatchlings = cpuset_info.cpus_hatched;
    827      1.14      matt 
    828      1.14      matt 	if (h->hatch_sp == 0) {
    829      1.14      matt 		int error = uvm_pglistalloc(PAGE_SIZE, PAGE_SIZE,
    830      1.14      matt 		    64*1024*1024, PAGE_SIZE, 0, &splist, 1, 1);
    831      1.14      matt 		if (error) {
    832      1.14      matt 			aprint_error_dev(self,
    833      1.14      matt 			    "unable to allocate hatch stack\n");
    834      1.14      matt 			return;
    835      1.14      matt 		}
    836      1.14      matt 		h->hatch_sp = VM_PAGE_TO_PHYS(TAILQ_FIRST(&splist))
    837      1.14      matt 		    + PAGE_SIZE - CALLFRAMELEN;
    838      1.14      matt         }
    839      1.14      matt 
    840      1.14      matt 
    841      1.14      matt 	for (size_t i = 1; e[i].entry_pir != 0; i++) {
    842      1.14      matt 		printf("%s: cpu%u: entry#%zu(%p): pir=%u\n",
    843      1.14      matt 		    __func__, ci->ci_cpuid, i, &e[i], e[i].entry_pir);
    844      1.14      matt 		if (e[i].entry_pir == ci->ci_cpuid) {
    845      1.14      matt 
    846      1.14      matt 			ci->ci_curlwp = ci->ci_data.cpu_idlelwp;
    847      1.14      matt 			ci->ci_curpcb = lwp_getpcb(ci->ci_curlwp);
    848      1.14      matt 			ci->ci_curpm = pmap_kernel();
    849      1.14      matt 			ci->ci_lasttb = cpu_info[0].ci_lasttb;
    850      1.14      matt 			ci->ci_data.cpu_cc_freq =
    851      1.14      matt 			    cpu_info[0].ci_data.cpu_cc_freq;
    852      1.14      matt 
    853      1.14      matt 			h->hatch_self = self;
    854      1.14      matt 			h->hatch_ci = ci;
    855      1.14      matt 			h->hatch_running = -1;
    856      1.14      matt 			h->hatch_pir = e[i].entry_pir;
    857      1.14      matt 			h->hatch_hid0 = mfspr(SPR_HID0);
    858  1.29.2.1       tls 			u_int tlbidx;
    859  1.29.2.1       tls 		        e500_tlb_lookup_xtlb(0, &tlbidx);
    860  1.29.2.1       tls 		        h->hatch_tlbidx = tlbidx;
    861      1.14      matt 			KASSERT(h->hatch_sp != 0);
    862      1.14      matt 			/*
    863      1.14      matt 			 * Get new timebase.  We don't want to deal with
    864      1.14      matt 			 * timebase crossing a 32-bit boundary so make sure
    865      1.14      matt 			 * that we have enough headroom to do the timebase
    866      1.14      matt 			 * synchronization.
    867      1.14      matt 			 */
    868      1.14      matt #define	TBSYNC_SLOP	2000
    869      1.14      matt 			uint32_t tbl;
    870      1.14      matt 			uint32_t tbu;
    871      1.14      matt 			do {
    872      1.14      matt 				tbu = mfspr(SPR_RTBU);
    873      1.14      matt 				tbl = mfspr(SPR_RTBL) + TBSYNC_SLOP;
    874      1.14      matt 			} while (tbl < TBSYNC_SLOP);
    875      1.14      matt 
    876      1.14      matt 			h->hatch_tbu = tbu;
    877      1.14      matt 			h->hatch_tbl = tbl;
    878      1.14      matt 			__asm("sync;isync");
    879      1.14      matt 			dcache_wbinv((vaddr_t)h, sizeof(*h));
    880      1.14      matt 
    881      1.14      matt 			/*
    882      1.14      matt 			 * And here we go...
    883      1.14      matt 			 */
    884      1.14      matt 			e[i].entry_addr_lower =
    885      1.14      matt 			    (uint32_t)e500_spinup_trampoline;
    886      1.14      matt 			dcache_wbinv((vaddr_t)&e[i], sizeof(e[i]));
    887      1.14      matt 			__asm __volatile("sync;isync");
    888      1.14      matt 			__insn_barrier();
    889      1.14      matt 
    890      1.14      matt 			for (u_int timo = 0; timo++ < 10000; ) {
    891      1.14      matt 				dcache_inv((vaddr_t)&e[i], sizeof(e[i]));
    892      1.14      matt 				if (e[i].entry_addr_lower == 3) {
    893  1.29.2.1       tls #if 0
    894      1.14      matt 					printf(
    895      1.14      matt 					    "%s: cpu%u started in %u spins\n",
    896      1.14      matt 					    __func__, cpu_index(ci), timo);
    897  1.29.2.1       tls #endif
    898      1.14      matt 					break;
    899      1.14      matt 				}
    900      1.14      matt 			}
    901      1.14      matt 			for (u_int timo = 0; timo++ < 10000; ) {
    902      1.14      matt 				dcache_inv((vaddr_t)h, sizeof(*h));
    903      1.14      matt 				if (h->hatch_running == 0) {
    904  1.29.2.1       tls #if 0
    905      1.14      matt 					printf(
    906      1.14      matt 					    "%s: cpu%u cracked in %u spins: (running=%d)\n",
    907      1.14      matt 					    __func__, cpu_index(ci),
    908      1.14      matt 					    timo, h->hatch_running);
    909  1.29.2.1       tls #endif
    910      1.14      matt 					break;
    911      1.14      matt 				}
    912      1.14      matt 			}
    913      1.14      matt 			if (h->hatch_running == -1) {
    914      1.14      matt 				aprint_error_dev(self,
    915      1.14      matt 				    "hatch failed (timeout): running=%d"
    916      1.14      matt 				    ", entry=%#x\n",
    917      1.14      matt 				    h->hatch_running, e[i].entry_addr_lower);
    918      1.14      matt 				goto out;
    919      1.14      matt 			}
    920      1.14      matt 
    921      1.14      matt 			/*
    922      1.14      matt 			 * First then we do is to synchronize timebases.
    923      1.14      matt 			 * TBSYNC_SLOP*16 should be more than enough
    924      1.14      matt 			 * instructions.
    925      1.14      matt 			 */
    926      1.14      matt 			while (tbl != mftbl())
    927      1.14      matt 				continue;
    928      1.14      matt 			h->hatch_running = 1;
    929      1.14      matt 			dcache_wbinv((vaddr_t)h, sizeof(*h));
    930      1.14      matt 			__asm("sync;isync");
    931      1.14      matt 			__insn_barrier();
    932  1.29.2.1       tls 			printf("%s: cpu%u set to running\n",
    933  1.29.2.1       tls 			    __func__, cpu_index(ci));
    934      1.14      matt 
    935      1.14      matt 			for (u_int timo = 10000; timo-- > 0; ) {
    936      1.14      matt 				dcache_inv((vaddr_t)h, sizeof(*h));
    937      1.14      matt 				if (h->hatch_running > 1)
    938      1.14      matt 					break;
    939      1.14      matt 			}
    940      1.14      matt 			if (h->hatch_running == 1) {
    941      1.14      matt 				printf(
    942      1.14      matt 				    "%s: tb sync failed: offset from %"PRId64"=%"PRId64" (running=%d)\n",
    943      1.14      matt 				    __func__,
    944      1.14      matt 				    ((int64_t)tbu << 32) + tbl,
    945      1.14      matt 				    (int64_t)
    946      1.14      matt 					(((uint64_t)h->hatch_tbu << 32)
    947      1.14      matt 					+ (uint64_t)h->hatch_tbl),
    948      1.14      matt 				    h->hatch_running);
    949      1.14      matt 				goto out;
    950      1.14      matt 			}
    951      1.14      matt 			printf(
    952      1.14      matt 			    "%s: tb synced: offset=%"PRId64" (running=%d)\n",
    953      1.14      matt 			    __func__,
    954      1.14      matt 			    (int64_t)
    955      1.14      matt 				(((uint64_t)h->hatch_tbu << 32)
    956      1.14      matt 				+ (uint64_t)h->hatch_tbl),
    957      1.14      matt 			    h->hatch_running);
    958      1.14      matt 			/*
    959  1.29.2.2  jdolecek 			 * Now we wait for the hatching to complete.  30ms
    960      1.14      matt 			 * should be long enough.
    961      1.14      matt 			 */
    962  1.29.2.2  jdolecek 			for (u_int timo = 30000; timo-- > 0; ) {
    963  1.29.2.1       tls 				if (kcpuset_isset(hatchlings, id)) {
    964      1.14      matt 					aprint_normal_dev(self,
    965      1.14      matt 					    "hatch successful (%u spins, "
    966      1.14      matt 					    "timebase adjusted by %"PRId64")\n",
    967  1.29.2.2  jdolecek 					    30000 - timo,
    968      1.14      matt 					    (int64_t)
    969      1.14      matt 						(((uint64_t)h->hatch_tbu << 32)
    970      1.14      matt 						+ (uint64_t)h->hatch_tbl));
    971      1.14      matt 					goto out;
    972      1.14      matt 				}
    973      1.14      matt 				DELAY(1);
    974      1.14      matt 			}
    975      1.14      matt 
    976      1.14      matt 			aprint_error_dev(self,
    977      1.14      matt 			    "hatch failed (timeout): running=%u\n",
    978      1.14      matt 			    h->hatch_running);
    979      1.14      matt 			goto out;
    980      1.14      matt 		}
    981      1.14      matt 	}
    982      1.14      matt 
    983      1.14      matt 	aprint_error_dev(self, "hatch failed (no spin-up entry for PIR %u)",
    984      1.14      matt 	    ci->ci_cpuid);
    985      1.14      matt out:
    986      1.14      matt 	if (h->hatch_sp == 0)
    987      1.14      matt 		uvm_pglistfree(&splist);
    988      1.14      matt }
    989      1.14      matt #endif
    990      1.14      matt 
    991      1.14      matt void
    992      1.14      matt e500_cpu_hatch(struct cpu_info *ci)
    993      1.14      matt {
    994      1.14      matt 	mtmsr(mfmsr() | PSL_CE | PSL_ME | PSL_DE);
    995      1.14      matt 
    996      1.14      matt 	/*
    997      1.14      matt 	 * Make sure interrupts are blocked.
    998      1.14      matt 	 */
    999      1.14      matt 	cpu_write_4(OPENPIC_BASE + OPENPIC_CTPR, 15);	/* IPL_HIGH */
   1000      1.14      matt 
   1001  1.29.2.2  jdolecek 	/* Set the MAS4 defaults */
   1002  1.29.2.2  jdolecek 	mtspr(SPR_MAS4, MAS4_TSIZED_4KB | MAS4_MD);
   1003  1.29.2.2  jdolecek 	tlb_invalidate_all();
   1004  1.29.2.2  jdolecek 
   1005      1.14      matt 	intr_cpu_hatch(ci);
   1006      1.14      matt 
   1007  1.29.2.2  jdolecek 	cpu_probe_cache();
   1008      1.14      matt 	cpu_print_info(ci);
   1009      1.14      matt 
   1010      1.14      matt /*
   1011      1.14      matt  */
   1012      1.14      matt }
   1013      1.14      matt 
   1014      1.14      matt static void
   1015      1.14      matt e500_cpu_attach(device_t self, u_int instance)
   1016      1.14      matt {
   1017      1.14      matt 	struct cpu_info * const ci = &cpu_info[instance - (instance > 0)];
   1018      1.14      matt 
   1019      1.14      matt 	if (instance > 1) {
   1020      1.14      matt #if defined(MULTIPROCESSOR)
   1021      1.14      matt 		ci->ci_idepth = -1;
   1022      1.14      matt 		self->dv_private = ci;
   1023      1.14      matt 
   1024      1.14      matt 		ci->ci_cpuid = instance - (instance > 0);
   1025      1.14      matt 		ci->ci_dev = self;
   1026      1.14      matt 		ci->ci_tlb_info = cpu_info[0].ci_tlb_info;
   1027      1.14      matt 
   1028      1.14      matt 		mi_cpu_attach(ci);
   1029      1.14      matt 
   1030      1.14      matt 		intr_cpu_attach(ci);
   1031      1.14      matt 		cpu_evcnt_attach(ci);
   1032      1.14      matt 
   1033      1.14      matt 		e500_cpu_spinup(self, ci);
   1034      1.14      matt 		return;
   1035      1.14      matt #else
   1036      1.14      matt 		aprint_error_dev(self, "disabled (uniprocessor kernel)\n");
   1037      1.14      matt 		return;
   1038      1.14      matt #endif
   1039      1.14      matt 	}
   1040      1.14      matt 
   1041      1.14      matt 	self->dv_private = ci;
   1042      1.14      matt 
   1043      1.14      matt 	ci->ci_cpuid = instance - (instance > 0);
   1044      1.14      matt 	ci->ci_dev = self;
   1045       1.2      matt 
   1046       1.7      matt 	intr_cpu_attach(ci);
   1047       1.2      matt 	cpu_evcnt_attach(ci);
   1048       1.7      matt 
   1049      1.14      matt 	KASSERT(ci == curcpu());
   1050      1.14      matt 	intr_cpu_hatch(ci);
   1051      1.14      matt 
   1052      1.14      matt 	cpu_print_info(ci);
   1053       1.2      matt }
   1054       1.2      matt 
   1055       1.7      matt void
   1056       1.7      matt e500_ipi_halt(void)
   1057       1.7      matt {
   1058  1.29.2.2  jdolecek #ifdef MULTIPROCESSOR
   1059  1.29.2.2  jdolecek 	struct cpuset_info * const csi = &cpuset_info;
   1060  1.29.2.2  jdolecek 	const cpuid_t index = cpu_index(curcpu());
   1061  1.29.2.2  jdolecek 
   1062  1.29.2.2  jdolecek 	printf("cpu%lu: shutting down\n", index);
   1063  1.29.2.2  jdolecek 	kcpuset_set(csi->cpus_halted, index);
   1064  1.29.2.2  jdolecek #endif
   1065       1.7      matt 	register_t msr, hid0;
   1066       1.7      matt 
   1067       1.7      matt 	msr = wrtee(0);
   1068       1.7      matt 
   1069       1.7      matt 	hid0 = mfspr(SPR_HID0);
   1070      1.13      matt 	hid0 = (hid0 & ~(HID0_TBEN|HID0_NAP|HID0_SLEEP)) | HID0_DOZE;
   1071       1.7      matt 	mtspr(SPR_HID0, hid0);
   1072       1.7      matt 
   1073       1.7      matt 	msr = (msr & ~(PSL_EE|PSL_CE|PSL_ME)) | PSL_WE;
   1074       1.7      matt 	mtmsr(msr);
   1075       1.7      matt 	for (;;);	/* loop forever */
   1076       1.7      matt }
   1077       1.7      matt 
   1078       1.7      matt 
   1079       1.2      matt static void
   1080       1.2      matt calltozero(void)
   1081       1.2      matt {
   1082       1.2      matt 	panic("call to 0 from %p", __builtin_return_address(0));
   1083       1.2      matt }
   1084       1.2      matt 
   1085  1.29.2.2  jdolecek #if !defined(ROUTERBOOT)
   1086      1.29      matt static void
   1087      1.29      matt parse_cmdline(char *cp)
   1088      1.29      matt {
   1089      1.29      matt 	int ourhowto = 0;
   1090      1.29      matt 	char c;
   1091      1.29      matt 	bool opt = false;
   1092      1.29      matt 	for (; (c = *cp) != '\0'; cp++) {
   1093      1.29      matt 		if (c == '-') {
   1094      1.29      matt 			opt = true;
   1095      1.29      matt 			continue;
   1096      1.29      matt 		}
   1097      1.29      matt 		if (c == ' ') {
   1098      1.29      matt 			opt = false;
   1099      1.29      matt 			continue;
   1100      1.29      matt 		}
   1101      1.29      matt 		if (opt) {
   1102      1.29      matt 			switch (c) {
   1103      1.29      matt 			case 'a': ourhowto |= RB_ASKNAME; break;
   1104      1.29      matt 			case 'd': ourhowto |= AB_DEBUG; break;
   1105      1.29      matt 			case 'q': ourhowto |= AB_QUIET; break;
   1106      1.29      matt 			case 's': ourhowto |= RB_SINGLE; break;
   1107      1.29      matt 			case 'v': ourhowto |= AB_VERBOSE; break;
   1108      1.29      matt 			}
   1109      1.29      matt 			continue;
   1110      1.29      matt 		}
   1111      1.29      matt 		strlcpy(root_string, cp, sizeof(root_string));
   1112      1.29      matt 		break;
   1113      1.29      matt 	}
   1114      1.29      matt 	if (ourhowto) {
   1115      1.29      matt 		boothowto |= ourhowto;
   1116      1.29      matt 		printf(" boothowto=%#x(%#x)", boothowto, ourhowto);
   1117      1.29      matt 	}
   1118      1.29      matt 	if (root_string[0])
   1119      1.29      matt 		printf(" root=%s", root_string);
   1120      1.29      matt }
   1121  1.29.2.2  jdolecek #endif	/* !ROUTERBOOT */
   1122      1.29      matt 
   1123       1.2      matt void
   1124      1.10      matt initppc(vaddr_t startkernel, vaddr_t endkernel,
   1125      1.29      matt 	void *a0, void *a1, char *a2, char *a3)
   1126       1.2      matt {
   1127       1.2      matt 	struct cpu_info * const ci = curcpu();
   1128       1.2      matt 	struct cpu_softc * const cpu = ci->ci_softc;
   1129       1.2      matt 
   1130       1.2      matt 	cn_tab = &e500_earlycons;
   1131      1.10      matt 	printf(" initppc(%#"PRIxVADDR", %#"PRIxVADDR", %p, %p, %p, %p)<enter>",
   1132      1.10      matt 	    startkernel, endkernel, a0, a1, a2, a3);
   1133       1.2      matt 
   1134  1.29.2.2  jdolecek #if !defined(ROUTERBOOT)
   1135      1.29      matt 	if (a2[0] != '\0')
   1136      1.29      matt 		printf(" consdev=<%s>", a2);
   1137      1.29      matt 	if (a3[0] != '\0') {
   1138      1.29      matt 		printf(" cmdline=<%s>", a3);
   1139      1.29      matt 		parse_cmdline(a3);
   1140      1.29      matt 	}
   1141  1.29.2.2  jdolecek #endif	/* !ROUTERBOOT */
   1142      1.29      matt 
   1143      1.13      matt 	/*
   1144      1.13      matt 	 * Make sure we don't enter NAP or SLEEP if PSL_POW (MSR[WE]) is set.
   1145      1.13      matt 	 * DOZE is ok.
   1146      1.13      matt 	 */
   1147       1.2      matt 	const register_t hid0 = mfspr(SPR_HID0);
   1148      1.13      matt 	mtspr(SPR_HID0,
   1149      1.13      matt 	    (hid0 & ~(HID0_NAP | HID0_SLEEP)) | HID0_TBEN | HID0_EMCP | HID0_DOZE);
   1150       1.2      matt #ifdef CADMUS
   1151       1.2      matt 	/*
   1152       1.2      matt 	 * Need to cache this from cadmus since we need to unmap cadmus since
   1153       1.2      matt 	 * it falls in the middle of kernel address space.
   1154       1.2      matt 	 */
   1155       1.2      matt 	cadmus_pci = ((uint8_t *)0xf8004000)[CM_PCI];
   1156       1.2      matt 	cadmus_csr = ((uint8_t *)0xf8004000)[CM_CSR];
   1157       1.2      matt 	((uint8_t *)0xf8004000)[CM_CSR] |= CM_RST_PHYRST;
   1158       1.2      matt 	printf(" cadmus_pci=%#x", cadmus_pci);
   1159       1.2      matt 	printf(" cadmus_csr=%#x", cadmus_csr);
   1160       1.2      matt 	((uint8_t *)0xf8004000)[CM_CSR] = 0;
   1161       1.2      matt 	if ((cadmus_pci & CM_PCI_PSPEED) == CM_PCI_PSPEED_66) {
   1162       1.2      matt 		e500_sys_clk *= 2;
   1163       1.2      matt 	}
   1164       1.2      matt #endif
   1165       1.2      matt #ifdef PIXIS
   1166       1.2      matt 	pixis_spd = ((uint8_t *)PX_BASE)[PX_SPD];
   1167       1.6      matt 	printf(" pixis_spd=%#x sysclk=%"PRIuMAX,
   1168       1.6      matt 	    pixis_spd, PX_SPD_SYSCLK_GET(pixis_spd));
   1169       1.6      matt #ifndef SYS_CLK
   1170       1.2      matt 	e500_sys_clk = pixis_spd_map[PX_SPD_SYSCLK_GET(pixis_spd)];
   1171       1.6      matt #else
   1172       1.6      matt 	printf(" pixis_sysclk=%u", pixis_spd_map[PX_SPD_SYSCLK_GET(pixis_spd)]);
   1173       1.6      matt #endif
   1174       1.2      matt #endif
   1175       1.2      matt 	printf(" porpllsr=0x%08x",
   1176       1.2      matt 	    *(uint32_t *)(GUR_BASE + GLOBAL_BASE + PORPLLSR));
   1177       1.2      matt 	printf(" sys_clk=%"PRIu64, e500_sys_clk);
   1178       1.2      matt 
   1179       1.2      matt 	/*
   1180       1.2      matt 	 * Make sure arguments are page aligned.
   1181       1.2      matt 	 */
   1182       1.2      matt 	startkernel = trunc_page(startkernel);
   1183       1.2      matt 	endkernel = round_page(endkernel);
   1184       1.2      matt 
   1185       1.2      matt 	/*
   1186       1.2      matt 	 * Initialize the bus space tag used to access the 85xx general
   1187       1.2      matt 	 * utility registers.  It doesn't need to be extent protected.
   1188       1.2      matt 	 * We know the GUR is mapped via a TLB1 entry so we add a limited
   1189       1.2      matt 	 * mapiodev which allows mappings in GUR space.
   1190       1.2      matt 	 */
   1191      1.12      matt 	CTASSERT(offsetof(struct tlb_md_io_ops, md_tlb_mapiodev) == 0);
   1192      1.12      matt 	cpu_md_ops.md_tlb_io_ops = (const void *)&early_tlb_mapiodev;
   1193       1.2      matt 	bus_space_init(&gur_bst, NULL, NULL, 0);
   1194       1.5      matt 	bus_space_init(&gur_le_bst, NULL, NULL, 0);
   1195       1.2      matt 	cpu->cpu_bst = &gur_bst;
   1196       1.5      matt 	cpu->cpu_le_bst = &gur_le_bst;
   1197       1.2      matt 	cpu->cpu_bsh = gur_bsh;
   1198       1.2      matt 
   1199       1.2      matt 	/*
   1200       1.2      matt 	 * Attach the console early, really early.
   1201       1.2      matt 	 */
   1202       1.2      matt 	consinit();
   1203       1.2      matt 
   1204       1.2      matt 	/*
   1205       1.2      matt 	 * Reset the PIC to a known state.
   1206       1.2      matt 	 */
   1207       1.2      matt 	cpu_write_4(OPENPIC_BASE + OPENPIC_GCR, GCR_RST);
   1208       1.2      matt 	while (cpu_read_4(OPENPIC_BASE + OPENPIC_GCR) & GCR_RST)
   1209       1.2      matt 		;
   1210       1.2      matt #if 0
   1211       1.2      matt 	cpu_write_4(OPENPIC_BASE + OPENPIC_CTPR, 15);	/* IPL_HIGH */
   1212       1.2      matt #endif
   1213       1.2      matt 	printf(" openpic-reset(ctpr=%u)",
   1214       1.2      matt 	    cpu_read_4(OPENPIC_BASE + OPENPIC_CTPR));
   1215       1.2      matt 
   1216       1.2      matt 	/*
   1217       1.2      matt 	 * fill in with an absolute branch to a routine that will panic.
   1218       1.2      matt 	 */
   1219  1.29.2.1       tls 	*(volatile int *)0 = 0x48000002 | (int) calltozero;
   1220       1.2      matt 
   1221       1.2      matt 	/*
   1222       1.2      matt 	 * Get the cache sizes.
   1223       1.2      matt 	 */
   1224       1.2      matt 	cpu_probe_cache();
   1225       1.6      matt 		printf(" cache(DC=%uKB/%u,IC=%uKB/%u)",
   1226       1.2      matt 		    ci->ci_ci.dcache_size >> 10,
   1227       1.2      matt 		    ci->ci_ci.dcache_line_size,
   1228       1.2      matt 		    ci->ci_ci.icache_size >> 10,
   1229       1.2      matt 		    ci->ci_ci.icache_line_size);
   1230       1.2      matt 
   1231       1.2      matt 	/*
   1232       1.2      matt 	 * Now find out how much memory is attached
   1233       1.2      matt 	 */
   1234       1.2      matt 	pmemsize = memprobe(endkernel);
   1235       1.5      matt 	cpu->cpu_highmem = pmemsize;
   1236       1.2      matt 		printf(" memprobe=%zuMB", (size_t) (pmemsize >> 20));
   1237       1.2      matt 
   1238       1.2      matt 	/*
   1239       1.2      matt 	 * Now we need cleanout the TLB of stuff that we don't need.
   1240       1.2      matt 	 */
   1241       1.2      matt 	e500_tlb_init(endkernel, pmemsize);
   1242       1.2      matt 		printf(" e500_tlbinit(%#lx,%zuMB)",
   1243       1.2      matt 		    endkernel, (size_t) (pmemsize >> 20));
   1244       1.2      matt 
   1245       1.2      matt 	/*
   1246       1.2      matt 	 *
   1247       1.2      matt 	 */
   1248       1.2      matt 	printf(" hid0=%#lx/%#lx", hid0, mfspr(SPR_HID0));
   1249       1.2      matt 	printf(" hid1=%#lx", mfspr(SPR_HID1));
   1250       1.2      matt 	printf(" pordevsr=%#x", cpu_read_4(GLOBAL_BASE + PORDEVSR));
   1251       1.2      matt 	printf(" devdisr=%#x", cpu_read_4(GLOBAL_BASE + DEVDISR));
   1252       1.2      matt 
   1253       1.2      matt 	mtmsr(mfmsr() | PSL_CE | PSL_ME | PSL_DE);
   1254       1.2      matt 
   1255       1.2      matt 	/*
   1256       1.2      matt 	 * Initialize the message buffer.
   1257       1.2      matt 	 */
   1258       1.2      matt 	initmsgbuf((void *)msgbuf_paddr, round_page(MSGBUFSIZE));
   1259       1.2      matt 	printf(" msgbuf=%p", (void *)msgbuf_paddr);
   1260       1.2      matt 
   1261       1.2      matt 	/*
   1262       1.2      matt 	 * Initialize exception vectors and interrupts
   1263       1.2      matt 	 */
   1264       1.2      matt 	exception_init(&e500_intrsw);
   1265      1.14      matt 
   1266       1.2      matt 	printf(" exception_init=%p", &e500_intrsw);
   1267      1.14      matt 
   1268       1.2      matt 	mtspr(SPR_TCR, TCR_WIE | mfspr(SPR_TCR));
   1269       1.2      matt 
   1270  1.29.2.2  jdolecek 	uvm_md_init();
   1271       1.2      matt 
   1272       1.2      matt 	/*
   1273       1.2      matt 	 * Initialize the pmap.
   1274       1.2      matt 	 */
   1275      1.23      matt 	endkernel = pmap_bootstrap(startkernel, endkernel, availmemr, nmemr);
   1276       1.2      matt 
   1277       1.2      matt 	/*
   1278       1.2      matt 	 * Let's take all the indirect calls via our stubs and patch
   1279       1.2      matt 	 * them to be direct calls.
   1280       1.2      matt 	 */
   1281      1.11      matt 	cpu_fixup_stubs();
   1282      1.23      matt 
   1283       1.2      matt 	/*
   1284       1.2      matt 	 * As a debug measure we can change the TLB entry that maps all of
   1285       1.2      matt 	 * memory to one that encompasses the 64KB with the kernel vectors.
   1286       1.2      matt 	 * All other pages will be soft faulted into the TLB as needed.
   1287       1.2      matt 	 */
   1288      1.23      matt 	e500_tlb_minimize(endkernel);
   1289       1.2      matt 
   1290       1.2      matt 	/*
   1291       1.2      matt 	 * Set some more MD helpers
   1292       1.2      matt 	 */
   1293       1.2      matt 	cpu_md_ops.md_cpunode_locs = mpc8548_cpunode_locs;
   1294       1.2      matt 	cpu_md_ops.md_device_register = e500_device_register;
   1295       1.2      matt 	cpu_md_ops.md_cpu_attach = e500_cpu_attach;
   1296       1.2      matt 	cpu_md_ops.md_cpu_reset = e500_cpu_reset;
   1297       1.2      matt #if NGPIO > 0
   1298       1.2      matt 	cpu_md_ops.md_cpunode_attach = pq3gpio_attach;
   1299       1.2      matt #endif
   1300       1.2      matt 
   1301      1.24     skrll 	printf(" initppc done!\n");
   1302       1.8       mrg 
   1303       1.8       mrg 	/*
   1304       1.8       mrg 	 * Look for the Book-E modules in the right place.
   1305       1.8       mrg 	 */
   1306       1.8       mrg 	module_machine = module_machine_booke;
   1307       1.2      matt }
   1308       1.2      matt 
   1309       1.2      matt #ifdef MPC8548
   1310       1.2      matt static const char * const mpc8548cds_extirq_names[] = {
   1311       1.2      matt 	[0] = "pci inta",
   1312       1.2      matt 	[1] = "pci intb",
   1313       1.2      matt 	[2] = "pci intc",
   1314       1.2      matt 	[3] = "pci intd",
   1315       1.2      matt 	[4] = "irq4",
   1316       1.2      matt 	[5] = "gige phy",
   1317       1.2      matt 	[6] = "atm phy",
   1318       1.2      matt 	[7] = "cpld",
   1319       1.2      matt 	[8] = "irq8",
   1320       1.2      matt 	[9] = "nvram",
   1321       1.2      matt 	[10] = "debug",
   1322       1.2      matt 	[11] = "pci2 inta",
   1323       1.2      matt };
   1324       1.2      matt #endif
   1325       1.2      matt 
   1326  1.29.2.1       tls #ifndef MPC8548
   1327       1.2      matt static const char * const mpc85xx_extirq_names[] = {
   1328       1.2      matt 	[0] = "extirq 0",
   1329       1.2      matt 	[1] = "extirq 1",
   1330       1.2      matt 	[2] = "extirq 2",
   1331       1.2      matt 	[3] = "extirq 3",
   1332       1.2      matt 	[4] = "extirq 4",
   1333       1.2      matt 	[5] = "extirq 5",
   1334       1.2      matt 	[6] = "extirq 6",
   1335       1.2      matt 	[7] = "extirq 7",
   1336       1.2      matt 	[8] = "extirq 8",
   1337       1.2      matt 	[9] = "extirq 9",
   1338       1.2      matt 	[10] = "extirq 10",
   1339       1.2      matt 	[11] = "extirq 11",
   1340       1.2      matt };
   1341  1.29.2.1       tls #endif
   1342       1.2      matt 
   1343       1.2      matt static void
   1344       1.2      matt mpc85xx_extirq_setup(void)
   1345       1.2      matt {
   1346       1.2      matt #ifdef MPC8548
   1347       1.2      matt 	const char * const * names = mpc8548cds_extirq_names;
   1348       1.2      matt 	const size_t n = __arraycount(mpc8548cds_extirq_names);
   1349       1.2      matt #else
   1350       1.2      matt 	const char * const * names = mpc85xx_extirq_names;
   1351       1.2      matt 	const size_t n = __arraycount(mpc85xx_extirq_names);
   1352       1.2      matt #endif
   1353       1.2      matt 	prop_array_t extirqs = prop_array_create_with_capacity(n);
   1354       1.2      matt 	for (u_int i = 0; i < n; i++) {
   1355       1.2      matt 		prop_string_t ps = prop_string_create_cstring_nocopy(names[i]);
   1356       1.2      matt 		prop_array_set(extirqs, i, ps);
   1357       1.2      matt 		prop_object_release(ps);
   1358       1.2      matt 	}
   1359       1.2      matt 	board_info_add_object("external-irqs", extirqs);
   1360       1.2      matt 	prop_object_release(extirqs);
   1361       1.2      matt }
   1362       1.2      matt 
   1363       1.2      matt static void
   1364       1.2      matt mpc85xx_pci_setup(const char *name, uint32_t intmask, int ist, int inta, ...)
   1365       1.2      matt {
   1366       1.2      matt 	prop_dictionary_t pci_intmap = prop_dictionary_create();
   1367       1.2      matt 	KASSERT(pci_intmap != NULL);
   1368       1.2      matt 	prop_number_t mask = prop_number_create_unsigned_integer(intmask);
   1369       1.2      matt 	KASSERT(mask != NULL);
   1370       1.2      matt 	prop_dictionary_set(pci_intmap, "interrupt-mask", mask);
   1371       1.2      matt 	prop_object_release(mask);
   1372       1.2      matt 	prop_number_t pn_ist = prop_number_create_unsigned_integer(ist);
   1373       1.2      matt 	KASSERT(pn_ist != NULL);
   1374       1.2      matt 	prop_number_t pn_intr = prop_number_create_unsigned_integer(inta);
   1375       1.2      matt 	KASSERT(pn_intr != NULL);
   1376       1.2      matt 	prop_dictionary_t entry = prop_dictionary_create();
   1377       1.2      matt 	KASSERT(entry != NULL);
   1378       1.2      matt 	prop_dictionary_set(entry, "interrupt", pn_intr);
   1379       1.2      matt 	prop_dictionary_set(entry, "type", pn_ist);
   1380       1.2      matt 	prop_dictionary_set(pci_intmap, "000000", entry);
   1381       1.2      matt 	prop_object_release(pn_intr);
   1382       1.2      matt 	prop_object_release(entry);
   1383       1.2      matt 	va_list ap;
   1384       1.2      matt 	va_start(ap, inta);
   1385       1.2      matt 	u_int intrinc = __LOWEST_SET_BIT(intmask);
   1386       1.2      matt 	for (u_int i = 0; i < intmask; i += intrinc) {
   1387       1.2      matt 		char prop_name[12];
   1388       1.2      matt 		snprintf(prop_name, sizeof(prop_name), "%06x", i + intrinc);
   1389       1.2      matt 		entry = prop_dictionary_create();
   1390       1.2      matt 		KASSERT(entry != NULL);
   1391       1.2      matt 		pn_intr = prop_number_create_unsigned_integer(va_arg(ap, u_int));
   1392       1.2      matt 		KASSERT(pn_intr != NULL);
   1393       1.2      matt 		prop_dictionary_set(entry, "interrupt", pn_intr);
   1394       1.2      matt 		prop_dictionary_set(entry, "type", pn_ist);
   1395       1.2      matt 		prop_dictionary_set(pci_intmap, prop_name, entry);
   1396       1.2      matt 		prop_object_release(pn_intr);
   1397       1.2      matt 		prop_object_release(entry);
   1398       1.2      matt 	}
   1399       1.2      matt 	va_end(ap);
   1400       1.2      matt 	prop_object_release(pn_ist);
   1401       1.2      matt 	board_info_add_object(name, pci_intmap);
   1402       1.2      matt 	prop_object_release(pci_intmap);
   1403       1.2      matt }
   1404       1.2      matt 
   1405       1.2      matt void
   1406       1.2      matt cpu_startup(void)
   1407       1.2      matt {
   1408       1.2      matt 	struct cpu_info * const ci = curcpu();
   1409       1.3      matt 	const uint16_t svr = getsvr();
   1410       1.2      matt 
   1411      1.13      matt 	powersave = 0;	/* we can do it but turn it on by default */
   1412      1.13      matt 
   1413       1.2      matt 	booke_cpu_startup(socname(mfspr(SPR_SVR)));
   1414       1.2      matt 
   1415       1.2      matt 	uint32_t v = cpu_read_4(GLOBAL_BASE + PORPLLSR);
   1416       1.2      matt 	uint32_t plat_ratio = PLAT_RATIO_GET(v);
   1417       1.2      matt 	uint32_t e500_ratio = E500_RATIO_GET(v);
   1418       1.2      matt 
   1419       1.2      matt 	uint64_t ccb_freq = e500_sys_clk * plat_ratio;
   1420       1.2      matt 	uint64_t cpu_freq = ccb_freq * e500_ratio / 2;
   1421       1.2      matt 
   1422       1.2      matt 	ci->ci_khz = (cpu_freq + 500) / 1000;
   1423       1.2      matt 	cpu_timebase = ci->ci_data.cpu_cc_freq = ccb_freq / 8;
   1424       1.2      matt 
   1425       1.3      matt 	board_info_add_number("my-id", svr);
   1426       1.2      matt 	board_info_add_bool("pq3");
   1427       1.2      matt 	board_info_add_number("mem-size", pmemsize);
   1428       1.2      matt 	const uint32_t l2ctl = cpu_read_4(L2CACHE_BASE + L2CTL);
   1429       1.2      matt 	uint32_t l2siz = L2CTL_L2SIZ_GET(l2ctl);
   1430       1.2      matt 	uint32_t l2banks = l2siz >> 16;
   1431       1.2      matt #ifdef MPC85555
   1432       1.3      matt 	if (svr == (MPC8555v1 >> 16)) {
   1433       1.2      matt 		l2siz >>= 1;
   1434       1.2      matt 		l2banks >>= 1;
   1435       1.2      matt 	}
   1436       1.2      matt #endif
   1437       1.6      matt 	paddr_t boot_page = cpu_read_4(GUR_BPTR);
   1438       1.6      matt 	if (boot_page & BPTR_EN) {
   1439       1.6      matt 		bool found = false;
   1440       1.6      matt 		boot_page = (boot_page & BPTR_BOOT_PAGE) << PAGE_SHIFT;
   1441       1.6      matt 		for (const uint32_t *dp = (void *)(boot_page + PAGE_SIZE - 4),
   1442       1.6      matt 		     * const bp = (void *)boot_page;
   1443       1.6      matt 		     bp <= dp; dp--) {
   1444       1.6      matt 			if (*dp == boot_page) {
   1445       1.6      matt 				uintptr_t spinup_table_addr = (uintptr_t)++dp;
   1446       1.6      matt 				spinup_table_addr =
   1447       1.6      matt 				    roundup2(spinup_table_addr, 32);
   1448       1.6      matt 				board_info_add_number("mp-boot-page",
   1449       1.6      matt 				    boot_page);
   1450       1.6      matt 				board_info_add_number("mp-spin-up-table",
   1451       1.6      matt 				    spinup_table_addr);
   1452       1.6      matt 				printf("Found MP boot page @ %#"PRIxPADDR". "
   1453       1.6      matt 				    "Spin-up table @ %#"PRIxPTR"\n",
   1454       1.6      matt 				    boot_page, spinup_table_addr);
   1455       1.6      matt 				found = true;
   1456       1.6      matt 				break;
   1457       1.6      matt 			}
   1458       1.6      matt 		}
   1459      1.14      matt 		if (!found) {
   1460       1.6      matt 			printf("Found MP boot page @ %#"PRIxPADDR
   1461       1.6      matt 			    " with missing U-boot signature!\n", boot_page);
   1462      1.14      matt 			board_info_add_number("mp-spin-up-table", 0);
   1463      1.14      matt 		}
   1464       1.6      matt 	}
   1465       1.2      matt 	board_info_add_number("l2-cache-size", l2siz);
   1466       1.2      matt 	board_info_add_number("l2-cache-line-size", 32);
   1467       1.2      matt 	board_info_add_number("l2-cache-banks", l2banks);
   1468       1.2      matt 	board_info_add_number("l2-cache-ways", 8);
   1469       1.2      matt 
   1470       1.2      matt 	board_info_add_number("processor-frequency", cpu_freq);
   1471       1.2      matt 	board_info_add_number("bus-frequency", ccb_freq);
   1472       1.2      matt 	board_info_add_number("pci-frequency", e500_sys_clk);
   1473       1.2      matt 	board_info_add_number("timebase-frequency", ccb_freq / 8);
   1474       1.2      matt 
   1475       1.2      matt #ifdef CADMUS
   1476       1.2      matt 	const uint8_t phy_base = CM_CSR_EPHY_GET(cadmus_csr) << 2;
   1477       1.2      matt 	board_info_add_number("tsec1-phy-addr", phy_base + 0);
   1478       1.2      matt 	board_info_add_number("tsec2-phy-addr", phy_base + 1);
   1479       1.2      matt 	board_info_add_number("tsec3-phy-addr", phy_base + 2);
   1480       1.2      matt 	board_info_add_number("tsec4-phy-addr", phy_base + 3);
   1481       1.2      matt #else
   1482       1.2      matt 	board_info_add_number("tsec1-phy-addr", MII_PHY_ANY);
   1483       1.2      matt 	board_info_add_number("tsec2-phy-addr", MII_PHY_ANY);
   1484       1.2      matt 	board_info_add_number("tsec3-phy-addr", MII_PHY_ANY);
   1485       1.2      matt 	board_info_add_number("tsec4-phy-addr", MII_PHY_ANY);
   1486       1.2      matt #endif
   1487       1.2      matt 
   1488       1.2      matt 	uint64_t macstnaddr =
   1489       1.2      matt 	    ((uint64_t)le32toh(cpu_read_4(ETSEC1_BASE + MACSTNADDR1)) << 16)
   1490       1.2      matt 	    | ((uint64_t)le32toh(cpu_read_4(ETSEC1_BASE + MACSTNADDR2)) << 48);
   1491       1.2      matt 	board_info_add_data("tsec-mac-addr-base", &macstnaddr, 6);
   1492       1.2      matt 
   1493       1.2      matt #if NPCI > 0 && defined(PCI_MEMBASE)
   1494       1.2      matt 	pcimem_ex = extent_create("pcimem",
   1495       1.2      matt 	    PCI_MEMBASE, PCI_MEMBASE + 4*PCI_MEMSIZE,
   1496      1.22      para 	    NULL, 0, EX_WAITOK);
   1497       1.2      matt #endif
   1498       1.2      matt #if NPCI > 0 && defined(PCI_IOBASE)
   1499       1.2      matt 	pciio_ex = extent_create("pciio",
   1500       1.2      matt 	    PCI_IOBASE, PCI_IOBASE + 4*PCI_IOSIZE,
   1501      1.22      para 	    NULL, 0, EX_WAITOK);
   1502       1.2      matt #endif
   1503       1.2      matt 	mpc85xx_extirq_setup();
   1504       1.2      matt 	/*
   1505       1.2      matt 	 * PCI-Express virtual wire interrupts on combined with
   1506       1.2      matt 	 * External IRQ0/1/2/3.
   1507       1.2      matt 	 */
   1508       1.3      matt 	switch (svr) {
   1509       1.2      matt #if defined(MPC8548)
   1510       1.3      matt 	case SVR_MPC8548v1 >> 16:
   1511       1.3      matt 		mpc85xx_pci_setup("pcie0-interrupt-map", 0x001800,
   1512       1.3      matt 		    IST_LEVEL, 0, 1, 2, 3);
   1513       1.3      matt 		break;
   1514       1.3      matt #endif
   1515      1.25      matt #if defined(MPC8544) || defined(MPC8572) || defined(MPC8536) \
   1516  1.29.2.2  jdolecek     || defined(P1025) || defined(P2020) || defined(P1023)
   1517       1.3      matt 	case SVR_MPC8536v1 >> 16:
   1518       1.3      matt 	case SVR_MPC8544v1 >> 16:
   1519       1.3      matt 	case SVR_MPC8572v1 >> 16:
   1520      1.25      matt 	case SVR_P1016v1 >> 16:
   1521  1.29.2.2  jdolecek 	case SVR_P1017v1 >> 16:
   1522  1.29.2.2  jdolecek 	case SVR_P1023v1 >> 16:
   1523       1.3      matt 	case SVR_P2010v2 >> 16:
   1524       1.3      matt 	case SVR_P2020v2 >> 16:
   1525      1.27      matt 		mpc85xx_pci_setup("pcie3-interrupt-map", 0x001800, IST_LEVEL,
   1526      1.27      matt 		    8, 9, 10, 11);
   1527      1.27      matt 		/* FALLTHROUGH */
   1528      1.27      matt 	case SVR_P1025v1 >> 16:
   1529      1.27      matt 		mpc85xx_pci_setup("pcie2-interrupt-map", 0x001800, IST_LEVEL,
   1530      1.27      matt 		    4, 5, 6, 7);
   1531       1.3      matt 		mpc85xx_pci_setup("pcie1-interrupt-map", 0x001800, IST_LEVEL,
   1532       1.3      matt 		    0, 1, 2, 3);
   1533       1.3      matt 		break;
   1534       1.2      matt #endif
   1535       1.3      matt 	}
   1536       1.3      matt 	switch (svr) {
   1537       1.2      matt #if defined(MPC8536)
   1538       1.3      matt 	case SVR_MPC8536v1 >> 16:
   1539       1.5      matt 		mpc85xx_pci_setup("pci0-interrupt-map", 0x001800, IST_LEVEL,
   1540       1.3      matt 		    1, 2, 3, 4);
   1541       1.3      matt 		break;
   1542       1.3      matt #endif
   1543       1.3      matt #if defined(MPC8544)
   1544       1.3      matt 	case SVR_MPC8544v1 >> 16:
   1545       1.5      matt 		mpc85xx_pci_setup("pci0-interrupt-map", 0x001800, IST_LEVEL,
   1546       1.3      matt 		    0, 1, 2, 3);
   1547       1.3      matt 		break;
   1548       1.2      matt #endif
   1549       1.2      matt #if defined(MPC8548)
   1550       1.3      matt 	case SVR_MPC8548v1 >> 16:
   1551       1.3      matt 		mpc85xx_pci_setup("pci1-interrupt-map", 0x001800, IST_LEVEL,
   1552       1.3      matt 		    0, 1, 2, 3);
   1553       1.3      matt 		mpc85xx_pci_setup("pci2-interrupt-map", 0x001800, IST_LEVEL,
   1554       1.3      matt 		    11, 1, 2, 3);
   1555       1.3      matt 		break;
   1556       1.2      matt #endif
   1557       1.3      matt 	}
   1558       1.2      matt }
   1559