Home | History | Annotate | Line # | Download | only in obs405
obs266_machdep.c revision 1.1
      1 /*	$NetBSD: obs266_machdep.c,v 1.1 2005/03/18 14:12:34 shige Exp $	*/
      2 /*	Original: md_machdep.c,v 1.3 2005/01/24 18:47:37 shige Exp $	*/
      3 
      4 /*
      5  * Copyright 2001, 2002 Wasabi Systems, Inc.
      6  * All rights reserved.
      7  *
      8  * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *      This product includes software developed for the NetBSD Project by
     21  *      Wasabi Systems, Inc.
     22  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     23  *    or promote products derived from this software without specific prior
     24  *    written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
     41  * Copyright (C) 1995, 1996 TooLs GmbH.
     42  * All rights reserved.
     43  *
     44  * Redistribution and use in source and binary forms, with or without
     45  * modification, are permitted provided that the following conditions
     46  * are met:
     47  * 1. Redistributions of source code must retain the above copyright
     48  *    notice, this list of conditions and the following disclaimer.
     49  * 2. Redistributions in binary form must reproduce the above copyright
     50  *    notice, this list of conditions and the following disclaimer in the
     51  *    documentation and/or other materials provided with the distribution.
     52  * 3. All advertising materials mentioning features or use of this software
     53  *    must display the following acknowledgement:
     54  *	This product includes software developed by TooLs GmbH.
     55  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     56  *    derived from this software without specific prior written permission.
     57  *
     58  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     59  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     60  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     61  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     62  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     63  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     64  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     65  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     66  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     67  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     68  */
     69 
     70 #include <sys/cdefs.h>
     71 __KERNEL_RCSID(0, "$NetBSD: obs266_machdep.c,v 1.1 2005/03/18 14:12:34 shige Exp $");
     72 
     73 #include "opt_compat_netbsd.h"
     74 #include "opt_ddb.h"
     75 #include "opt_ipkdb.h"
     76 
     77 #include <sys/param.h>
     78 #include <sys/kernel.h>
     79 #include <sys/ksyms.h>
     80 #include <sys/mount.h>
     81 #include <sys/reboot.h>
     82 #include <sys/systm.h>
     83 
     84 #include <uvm/uvm.h>
     85 #include <uvm/uvm_extern.h>
     86 
     87 #include <machine/bus.h>
     88 #include <machine/cpu.h>
     89 #include <machine/obs266.h>
     90 #include <powerpc/spr.h>
     91 
     92 #include <powerpc/ibm4xx/dcr405gp.h>
     93 #include <powerpc/ibm4xx/openbios.h>
     94 
     95 #include "ksyms.h"
     96 
     97 /*
     98  * Global variables used here and there
     99  */
    100 char bootpath[256];
    101 
    102 extern paddr_t msgbuf_paddr;
    103 
    104 #if NKSYMS || defined(DDB) || defined(LKM)
    105 void *startsym, *endsym;
    106 #endif
    107 
    108 void initppc(u_int, u_int, char *, void *);
    109 int lcsplx(int);
    110 
    111 
    112 void
    113 initppc(u_int startkernel, u_int endkernel, char *args, void *info_block)
    114 {
    115 	u_int memsize;
    116 
    117 	/* Disable all external interrupts */
    118 	mtdcr(DCR_UIC0_ER, 0);
    119 
    120 	/* Setup board from OpenBIOS */
    121 	openbios_board_init(info_block, startkernel);
    122 	memsize = openbios_board_memsize_get();
    123 
    124 	/* Initialize IBM405GPr CPU */
    125 	ibm40x_memsize_init(memsize, startkernel);
    126 	ibm4xx_init((void (*)(void))ext_intr);
    127 
    128 	/*
    129 	 * Initialize console.
    130 	 */
    131 	consinit();
    132 
    133 	/*
    134 	 * Set the page size.
    135 	 */
    136 	uvm_setpagesize();
    137 
    138 	/*
    139 	 * Initialize pmap module.
    140 	 */
    141 	pmap_bootstrap(startkernel, endkernel);
    142 
    143 #ifdef DEBUG
    144 	openbios_board_print();
    145 #endif
    146 
    147 #if NKSYMS || defined(DDB) || defined(LKM)
    148 	ksyms_init((int)((u_int)endsym - (u_int)startsym), startsym, endsym);
    149 #endif
    150 #ifdef DDB
    151 	if (boothowto & RB_KDB)
    152 		Debugger();
    153 #endif
    154 #ifdef IPKDB
    155 	/*
    156 	 * Now trap to IPKDB
    157 	 */
    158 	ipkdb_init();
    159 	if (boothowto & RB_KDB)
    160 		ipkdb_connect(0);
    161 #endif
    162 }
    163 
    164 void
    165 consinit(void)
    166 {
    167 
    168 	obs405_consinit(OBS266_COM_FREQ);
    169 }
    170 
    171 int
    172 lcsplx(int ipl)
    173 {
    174 
    175 	return spllower(ipl); 	/* XXX */
    176 }
    177 
    178 
    179 /*
    180  * Machine dependent startup code.
    181  */
    182 void
    183 cpu_startup(void)
    184 {
    185 
    186 	/*
    187 	 * cpu common startup
    188 	 */
    189 	ibm4xx_cpu_startup("OpenBlockS266 IBM PowerPC 405GPr Board");
    190 
    191 	/*
    192 	 * Set up the board properties database.
    193 	 */
    194 	openbios_board_info_set();
    195 
    196 	/*
    197 	 * Now that we have VM, malloc()s are OK in bus_space.
    198 	 */
    199 	bus_space_mallocok();
    200 
    201 	/*
    202 	 * no fake mapiodev
    203 	 */
    204 	fake_mapiodev = 0;
    205 }
    206 
    207 /*
    208  * Halt or reboot the machine after syncing/dumping according to howto.
    209  */
    210 void
    211 cpu_reboot(int howto, char *what)
    212 {
    213 	static int syncing;
    214 	static char str[256];
    215 	char *ap = str, *ap1 = ap;
    216 
    217 	obs266_led_set(OBS266_LED_ON);
    218 
    219 	boothowto = howto;
    220 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    221 		syncing = 1;
    222 		vfs_shutdown();		/* sync */
    223 		resettodr();		/* set wall clock */
    224 	}
    225 
    226 	splhigh();
    227 
    228 	if (!cold && (howto & RB_DUMP))
    229 		ibm4xx_dumpsys();
    230 
    231 	doshutdownhooks();
    232 
    233 	if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
    234 	  /* Power off here if we know how...*/
    235 	}
    236 
    237 	if (howto & RB_HALT) {
    238 		printf("halted\n\n");
    239 
    240 #if 0
    241 		goto reboot;	/* XXX for now... */
    242 #endif
    243 
    244 #ifdef DDB
    245 		printf("dropping to debugger\n");
    246 		while(1)
    247 			Debugger();
    248 #endif
    249 	}
    250 
    251 	printf("rebooting\n\n");
    252 	if (what && *what) {
    253 		if (strlen(what) > sizeof str - 5)
    254 			printf("boot string too large, ignored\n");
    255 		else {
    256 			strcpy(str, what);
    257 			ap1 = ap = str + strlen(str);
    258 			*ap++ = ' ';
    259 		}
    260 	}
    261 	*ap++ = '-';
    262 	if (howto & RB_SINGLE)
    263 		*ap++ = 's';
    264 	if (howto & RB_KDB)
    265 		*ap++ = 'd';
    266 	*ap++ = 0;
    267 	if (ap[-2] == '-')
    268 		*ap1 = 0;
    269 
    270 	/* flush cache for msgbuf */
    271 	__syncicache((void *)msgbuf_paddr, round_page(MSGBUFSIZE));
    272 
    273 #if 0
    274  reboot:
    275 #endif
    276 	ppc4xx_reset();
    277 
    278 	printf("ppc4xx_reset() failed!\n");
    279 #ifdef DDB
    280 	while(1)
    281 		Debugger();
    282 #else
    283 	while (1)
    284 		/* nothing */;
    285 #endif
    286 }
    287