Home | History | Annotate | Line # | Download | only in ev64260
machdep.c revision 1.3
      1  1.3  matt /*	$NetBSD: machdep.c,v 1.3 2003/03/07 18:24:01 matt Exp $	*/
      2  1.1  matt 
      3  1.1  matt /*
      4  1.1  matt  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
      5  1.1  matt  * Copyright (C) 1995, 1996 TooLs GmbH.
      6  1.1  matt  * All rights reserved.
      7  1.1  matt  *
      8  1.1  matt  * Redistribution and use in source and binary forms, with or without
      9  1.1  matt  * modification, are permitted provided that the following conditions
     10  1.1  matt  * are met:
     11  1.1  matt  * 1. Redistributions of source code must retain the above copyright
     12  1.1  matt  *    notice, this list of conditions and the following disclaimer.
     13  1.1  matt  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  matt  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  matt  *    documentation and/or other materials provided with the distribution.
     16  1.1  matt  * 3. All advertising materials mentioning features or use of this software
     17  1.1  matt  *    must display the following acknowledgement:
     18  1.1  matt  *	This product includes software developed by TooLs GmbH.
     19  1.1  matt  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     20  1.1  matt  *    derived from this software without specific prior written permission.
     21  1.1  matt  *
     22  1.1  matt  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     23  1.1  matt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1  matt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1  matt  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     26  1.1  matt  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     27  1.1  matt  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     28  1.1  matt  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     29  1.1  matt  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     30  1.1  matt  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     31  1.1  matt  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.1  matt  */
     33  1.1  matt 
     34  1.1  matt #include "opt_marvell.h"
     35  1.1  matt #include "opt_compat_netbsd.h"
     36  1.1  matt #include "opt_ddb.h"
     37  1.1  matt #include "opt_inet.h"
     38  1.1  matt #include "opt_ccitt.h"
     39  1.1  matt #include "opt_iso.h"
     40  1.1  matt #include "opt_ns.h"
     41  1.1  matt #include "opt_ipkdb.h"
     42  1.1  matt 
     43  1.1  matt #include <sys/param.h>
     44  1.1  matt #include <sys/conf.h>
     45  1.1  matt #include <sys/device.h>
     46  1.1  matt #include <sys/kernel.h>
     47  1.1  matt #include <sys/malloc.h>
     48  1.1  matt #include <sys/mount.h>
     49  1.1  matt #include <sys/msgbuf.h>
     50  1.1  matt #include <sys/proc.h>
     51  1.1  matt #include <sys/reboot.h>
     52  1.1  matt #include <sys/syslog.h>
     53  1.1  matt #include <sys/systm.h>
     54  1.1  matt 
     55  1.1  matt #include <uvm/uvm.h>
     56  1.1  matt #include <uvm/uvm_extern.h>
     57  1.1  matt 
     58  1.1  matt #include <net/netisr.h>
     59  1.1  matt 
     60  1.1  matt #include <machine/bus.h>
     61  1.1  matt #include <machine/db_machdep.h>
     62  1.1  matt #include <machine/intr.h>
     63  1.1  matt #include <machine/pmap.h>
     64  1.1  matt #include <machine/powerpc.h>
     65  1.1  matt #include <machine/trap.h>
     66  1.1  matt 
     67  1.1  matt #include <powerpc/oea/bat.h>
     68  1.1  matt #include <powerpc/marvell/watchdog.h>
     69  1.1  matt 
     70  1.1  matt #include <ddb/db_extern.h>
     71  1.1  matt 
     72  1.1  matt #include <dev/cons.h>
     73  1.1  matt 
     74  1.1  matt #include "vga.h"
     75  1.1  matt #if (NVGA > 0)
     76  1.1  matt #include <dev/ic/mc6845reg.h>
     77  1.1  matt #include <dev/ic/pcdisplayvar.h>
     78  1.1  matt #include <dev/ic/vgareg.h>
     79  1.1  matt #include <dev/ic/vgavar.h>
     80  1.1  matt #endif
     81  1.1  matt 
     82  1.1  matt #include "isa.h"
     83  1.1  matt #if (NISA > 0)
     84  1.1  matt void isa_intr_init(void);
     85  1.1  matt #endif
     86  1.1  matt 
     87  1.1  matt #include "pckbc.h"
     88  1.1  matt #if (NPCKBC > 0)
     89  1.1  matt #include <dev/isa/isareg.h>
     90  1.1  matt #include <dev/ic/i8042reg.h>
     91  1.1  matt #include <dev/ic/pckbcvar.h>
     92  1.1  matt #endif
     93  1.1  matt 
     94  1.1  matt #include "com.h"
     95  1.1  matt #if (NCOM > 0)
     96  1.1  matt #include <sys/termios.h>
     97  1.1  matt #include <dev/ic/comreg.h>
     98  1.1  matt #include <dev/ic/comvar.h>
     99  1.1  matt #endif
    100  1.1  matt 
    101  1.2  matt #include <dev/marvell/gtreg.h>
    102  1.1  matt #include <dev/marvell/gtvar.h>
    103  1.1  matt 
    104  1.1  matt /*
    105  1.1  matt  * Global variables used here and there
    106  1.1  matt  */
    107  1.1  matt extern struct user *proc0paddr;
    108  1.1  matt 
    109  1.1  matt struct bat battable[16];
    110  1.1  matt 
    111  1.1  matt #define	PMONMEMREGIONS	32
    112  1.1  matt struct mem_region physmemr[PMONMEMREGIONS], availmemr[PMONMEMREGIONS];
    113  1.1  matt 
    114  1.1  matt char *bootpath;
    115  1.1  matt 
    116  1.1  matt paddr_t msgbuf_paddr;
    117  1.1  matt vaddr_t msgbuf_vaddr;
    118  1.1  matt 
    119  1.1  matt paddr_t avail_end;			/* XXX temporary */
    120  1.1  matt 
    121  1.1  matt void initppc(u_int, u_int, u_int, void *); /* Called from locore */
    122  1.1  matt void strayintr(int);
    123  1.1  matt int lcsplx(int);
    124  1.1  matt 
    125  1.1  matt cons_decl(gtmpsc);
    126  1.1  matt 
    127  1.1  matt struct consdev constab[] = {
    128  1.1  matt 	cons_init_halt(gtmpsc),
    129  1.1  matt 	{ 0 }
    130  1.1  matt };
    131  1.1  matt 
    132  1.1  matt extern void return_to_dink(int);
    133  1.1  matt 
    134  1.1  matt void
    135  1.1  matt initppc(startkernel, endkernel, args, btinfo)
    136  1.1  matt 	u_int startkernel, endkernel, args;
    137  1.1  matt 	void *btinfo;
    138  1.1  matt {
    139  1.1  matt #ifdef DDB
    140  1.1  matt 	extern void *startsym, *endsym;
    141  1.1  matt #endif
    142  1.1  matt 	extern vaddr_t gtbase;
    143  1.2  matt 	volatile u_int32_t *gt = (volatile u_int32_t *) gtbase;
    144  1.1  matt 
    145  1.1  matt #if 1
    146  1.1  matt 	{
    147  1.1  matt 		extern unsigned char edata[], end[];
    148  1.1  matt 		struct cpu_info tmp = cpu_info[0];
    149  1.1  matt 		memset(edata, 0, end - edata);
    150  1.1  matt 		cpu_info[0] = tmp;
    151  1.1  matt 	}
    152  1.1  matt #endif
    153  1.1  matt 
    154  1.2  matt 	/*
    155  1.2  matt 	 * Relocate Discovery to desired address.
    156  1.2  matt 	 */
    157  1.2  matt 	if (gtbase != GT_BASE) {
    158  1.2  matt 		u_int32_t v = inlrb(gt + GT_Internal_Decode);
    159  1.2  matt 		outlrb(gt + GT_Internal_Decode,
    160  1.2  matt 		     (GT_BASE >> 20) | (v & ~0xffff));
    161  1.2  matt 		gtbase = GT_BASE;
    162  1.2  matt 	}
    163  1.2  matt 	{
    164  1.3  matt 		extern struct powerpc_bus_space gt_mem_bs_tag;
    165  1.3  matt 		gt_mem_bs_tag.pbs_base = GT_BASE;
    166  1.3  matt 		gt_mem_bs_tag.pbs_limit = GT_BASE + 4096;
    167  1.2  matt 	}
    168  1.1  matt 
    169  1.1  matt 	/*
    170  1.1  matt 	 * Hardcode 32MB for now--we should probe for this or get it
    171  1.1  matt 	 * from a boot loader, but for now, we are booting via an
    172  1.1  matt 	 * S-record loader.
    173  1.1  matt 	 */
    174  1.1  matt 	{	/* XXX AKB */
    175  1.1  matt 		u_int32_t	physmemsize;
    176  1.1  matt 
    177  1.1  matt 		physmemsize = 64 * 1024 * 1024;
    178  1.1  matt 		physmemr[0].start = 0;
    179  1.1  matt 		physmemr[0].size = physmemsize;
    180  1.1  matt 		physmemr[1].size = 0;
    181  1.1  matt 		availmemr[0].start = (endkernel + PGOFSET) & ~PGOFSET;
    182  1.1  matt 		availmemr[0].size = physmemsize - availmemr[0].start;
    183  1.1  matt 		availmemr[1].size = 0;
    184  1.1  matt 	}
    185  1.1  matt 	avail_end = physmemr[0].start + physmemr[0].size;    /* XXX temporary */
    186  1.1  matt 
    187  1.1  matt 	/*
    188  1.1  matt 	 * Get CPU clock
    189  1.1  matt 	 */
    190  1.1  matt 	{	/* XXX AKB */
    191  1.1  matt 		extern u_long ticks_per_sec, ns_per_tick;
    192  1.1  matt 		extern void calc_delayconst(void);
    193  1.1  matt 
    194  1.1  matt 		ticks_per_sec = 100000000;	/* 100 MHz */
    195  1.1  matt 		/* ticks_per_sec = 66000000;	* 66 MHz */
    196  1.1  matt 		ticks_per_sec /= 4;	/* 4 cycles per DEC tick */
    197  1.1  matt 		cpu_timebase = ticks_per_sec;
    198  1.1  matt 		ns_per_tick = 1000000000 / ticks_per_sec;
    199  1.1  matt 		calc_delayconst();
    200  1.1  matt 	}
    201  1.1  matt 
    202  1.1  matt 	/*
    203  1.1  matt 	 * boothowto
    204  1.1  matt 	 */
    205  1.1  matt 	boothowto = RB_SINGLE;
    206  1.1  matt 
    207  1.3  matt 	bus_space_init();
    208  1.1  matt 
    209  1.2  matt 	oea_batinit(0x80000000, BAT_BL_256M, 0xf0000000, BAT_BL_256M);
    210  1.1  matt 	oea_init((void (*)(void))ext_intr);
    211  1.1  matt 
    212  1.1  matt 	cninit();
    213  1.1  matt 
    214  1.1  matt #if (NISA > 0)
    215  1.1  matt 	isa_intr_init();
    216  1.1  matt #endif
    217  1.1  matt 
    218  1.1  matt         /*
    219  1.1  matt 	 * Set the page size.
    220  1.1  matt 	 */
    221  1.1  matt 	uvm_setpagesize();
    222  1.1  matt 
    223  1.1  matt 	/*
    224  1.1  matt 	 * Initialize pmap module.
    225  1.1  matt 	 */
    226  1.1  matt 	pmap_bootstrap(startkernel, endkernel);
    227  1.1  matt 
    228  1.1  matt #ifdef DDB
    229  1.1  matt 	ddb_init((int)((u_int)endsym - (u_int)startsym), startsym, endsym);
    230  1.1  matt #endif
    231  1.1  matt #ifdef IPKDB
    232  1.1  matt 	/*
    233  1.1  matt 	 * Now trap to IPKDB
    234  1.1  matt 	 */
    235  1.1  matt 	ipkdb_init();
    236  1.1  matt 	if (boothowto & RB_KDB)
    237  1.1  matt 		ipkdb_connect(0);
    238  1.1  matt #endif
    239  1.1  matt }
    240  1.1  matt 
    241  1.1  matt void
    242  1.1  matt mem_regions(mem, avail)
    243  1.1  matt 	struct mem_region **mem, **avail;
    244  1.1  matt {
    245  1.1  matt 	*mem = physmemr;
    246  1.1  matt 	*avail = availmemr;
    247  1.1  matt }
    248  1.1  matt 
    249  1.1  matt /*
    250  1.1  matt  * Machine dependent startup code.
    251  1.1  matt  */
    252  1.1  matt void
    253  1.1  matt cpu_startup()
    254  1.1  matt {
    255  1.1  matt 	register_t msr;
    256  1.1  matt 
    257  1.1  matt 	oea_startup(NULL);
    258  1.1  matt 
    259  1.1  matt 	/*
    260  1.1  matt 	 * Now that we have VM, malloc()s are OK in bus_space.
    261  1.1  matt 	 */
    262  1.3  matt 	bus_space_mallocok();
    263  1.1  matt 
    264  1.1  matt 	/*
    265  1.1  matt 	 * Now allow hardware interrupts.
    266  1.1  matt 	 */
    267  1.1  matt 	splhigh();
    268  1.1  matt 	__asm __volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0"
    269  1.1  matt 	    :	"=r"(msr)
    270  1.1  matt 	    :	"K"(PSL_EE));
    271  1.1  matt }
    272  1.1  matt 
    273  1.1  matt /*
    274  1.1  matt  * consinit
    275  1.1  matt  * Initialize system console.
    276  1.1  matt  */
    277  1.1  matt void
    278  1.1  matt consinit()
    279  1.1  matt {
    280  1.1  matt 	cninit();
    281  1.1  matt }
    282  1.1  matt 
    283  1.1  matt #if (NPCKBC > 0) && (NPCKBD == 0)
    284  1.1  matt /*
    285  1.1  matt  * glue code to support old console code with the
    286  1.1  matt  * mi keyboard controller driver
    287  1.1  matt  */
    288  1.1  matt int
    289  1.1  matt pckbc_machdep_cnattach(kbctag, kbcslot)
    290  1.1  matt 	pckbc_tag_t kbctag;
    291  1.1  matt 	pckbc_slot_t kbcslot;
    292  1.1  matt {
    293  1.1  matt #if (NPC > 0)
    294  1.1  matt 	return (pcconskbd_cnattach(kbctag, kbcslot));
    295  1.1  matt #else
    296  1.1  matt 	return (ENXIO);
    297  1.1  matt #endif
    298  1.1  matt }
    299  1.1  matt #endif
    300  1.1  matt 
    301  1.1  matt /*
    302  1.1  matt  * Stray interrupts.
    303  1.1  matt  */
    304  1.1  matt void
    305  1.1  matt strayintr(int irq)
    306  1.1  matt {
    307  1.1  matt 	log(LOG_ERR, "stray interrupt %d\n", irq);
    308  1.1  matt }
    309  1.1  matt 
    310  1.1  matt /*
    311  1.1  matt  * Halt or reboot the machine after syncing/dumping according to howto.
    312  1.1  matt  */
    313  1.1  matt void
    314  1.1  matt cpu_reboot(howto, what)
    315  1.1  matt 	int howto;
    316  1.1  matt 	char *what;
    317  1.1  matt {
    318  1.1  matt 	static int syncing;
    319  1.1  matt 	static char str[256];
    320  1.1  matt 	char *ap = str, *ap1 = ap;
    321  1.1  matt 
    322  1.1  matt 	boothowto = howto;
    323  1.1  matt 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    324  1.1  matt 		syncing = 1;
    325  1.1  matt 		vfs_shutdown();		/* sync */
    326  1.1  matt 		resettodr();		/* set wall clock */
    327  1.1  matt 	}
    328  1.1  matt 	splhigh();
    329  1.1  matt 	if (howto & RB_HALT) {
    330  1.1  matt 		doshutdownhooks();
    331  1.1  matt 		printf("halted\n\n");
    332  1.1  matt 		cnhalt();
    333  1.1  matt 		while(1);
    334  1.1  matt 	}
    335  1.1  matt 	if (!cold && (howto & RB_DUMP))
    336  1.1  matt 		oea_dumpsys();
    337  1.1  matt 	doshutdownhooks();
    338  1.1  matt 	printf("rebooting\n\n");
    339  1.1  matt 	if (what && *what) {
    340  1.1  matt 		if (strlen(what) > sizeof str - 5)
    341  1.1  matt 			printf("boot string too large, ignored\n");
    342  1.1  matt 		else {
    343  1.1  matt 			strcpy(str, what);
    344  1.1  matt 			ap1 = ap = str + strlen(str);
    345  1.1  matt 			*ap++ = ' ';
    346  1.1  matt 		}
    347  1.1  matt 	}
    348  1.1  matt 	*ap++ = '-';
    349  1.1  matt 	if (howto & RB_SINGLE)
    350  1.1  matt 		*ap++ = 's';
    351  1.1  matt 	if (howto & RB_KDB)
    352  1.1  matt 		*ap++ = 'd';
    353  1.1  matt 	*ap++ = 0;
    354  1.1  matt 	if (ap[-2] == '-')
    355  1.1  matt 		*ap1 = 0;
    356  1.1  matt #if 0
    357  1.1  matt 	{
    358  1.1  matt 		void mvpppc_reboot(void);
    359  1.1  matt 		mvpppc_reboot();
    360  1.1  matt 	}
    361  1.1  matt #endif
    362  1.1  matt 	gt_watchdog_reset();
    363  1.1  matt 	/* NOTREACHED */
    364  1.1  matt 	while (1);
    365  1.1  matt }
    366  1.1  matt 
    367  1.1  matt int
    368  1.1  matt lcsplx(ipl)
    369  1.1  matt 	int ipl;
    370  1.1  matt {
    371  1.1  matt 	return spllower(ipl);
    372  1.1  matt }
    373  1.1  matt 
    374  1.1  matt int
    375  1.1  matt gtget_macaddr(struct gt_softc *gt, int macno, char *enaddr)
    376  1.1  matt {
    377  1.1  matt 	enaddr[0] = 0x02;
    378  1.1  matt 	enaddr[1] = 0x00;
    379  1.1  matt 	enaddr[2] = 0x04;
    380  1.1  matt 	enaddr[3] = 0x00;
    381  1.1  matt 	enaddr[4] = 0x00;
    382  1.1  matt 	enaddr[5] = 0x04 + macno;
    383  1.1  matt 
    384  1.1  matt 	return 0;
    385  1.1  matt }
    386