Home | History | Annotate | Line # | Download | only in ofppc
machdep.c revision 1.93
      1 /*	$NetBSD: machdep.c,v 1.93 2007/10/17 19:56:10 garbled Exp $	*/
      2 
      3 /*
      4  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
      5  * Copyright (C) 1995, 1996 TooLs GmbH.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by TooLs GmbH.
     19  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     28  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #include <sys/cdefs.h>
     35 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.93 2007/10/17 19:56:10 garbled Exp $");
     36 
     37 #include <sys/param.h>
     38 #include <sys/buf.h>
     39 #include <sys/boot_flag.h>
     40 #include <sys/mount.h>
     41 #include <sys/kernel.h>
     42 
     43 #include <uvm/uvm_extern.h>
     44 
     45 #include <dev/ofw/openfirm.h>
     46 #include <dev/cons.h>
     47 
     48 #include <machine/autoconf.h>
     49 #include <machine/pmap.h>
     50 #include <machine/powerpc.h>
     51 #include <machine/trap.h>
     52 #include <machine/bus.h>
     53 #include <machine/isa_machdep.h>
     54 
     55 #include <powerpc/oea/bat.h>
     56 #include <powerpc/ofw_cons.h>
     57 
     58 
     59 struct pmap ofw_pmap;
     60 char bootpath[256];
     61 
     62 void ofwppc_batinit(void);
     63 void	ofppc_bootstrap_console(void);
     64 
     65 void
     66 initppc(u_int startkernel, u_int endkernel, char *args)
     67 {
     68 	/* Initialize the bootstrap console. */
     69 	ofppc_bootstrap_console();
     70 	printf( "\n\nHallo Welt!\n\n");
     71 	ofwoea_initppc(startkernel, endkernel, args);
     72 	map_isa_ioregs();
     73 }
     74 
     75 void
     76 cpu_startup(void)
     77 {
     78 	oea_startup(NULL);
     79 }
     80 
     81 /*
     82 void
     83 consinit(void)
     84 {
     85 	ofwoea_consinit();
     86 }
     87 */
     88 
     89 void
     90 dumpsys(void)
     91 {
     92 	printf("dumpsys: TBD\n");
     93 }
     94 
     95 /*
     96  * Halt or reboot the machine after syncing/dumping according to howto.
     97  */
     98 
     99 void
    100 cpu_reboot(int howto, char *what)
    101 {
    102 	static int syncing;
    103 	static char str[256];
    104 	char *ap = str, *ap1 = ap;
    105 
    106 	boothowto = howto;
    107 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    108 		syncing = 1;
    109 		vfs_shutdown();         /* sync */
    110 		resettodr();            /* set wall clock */
    111 	}
    112 	splhigh();
    113 	if (howto & RB_HALT) {
    114 		doshutdownhooks();
    115 		printf("halted\n\n");
    116 		ppc_exit();
    117 	}
    118 	if (!cold && (howto & RB_DUMP))
    119 		oea_dumpsys();
    120 	doshutdownhooks();
    121 	printf("rebooting\n\n");
    122 	if (what && *what) {
    123 		if (strlen(what) > sizeof str - 5)
    124 			printf("boot string too large, ignored\n");
    125 		else {
    126 			strcpy(str, what);
    127 			ap1 = ap = str + strlen(str);
    128 			*ap++ = ' ';
    129 		}
    130 	}
    131 	*ap++ = '-';
    132 	if (howto & RB_SINGLE)
    133 		*ap++ = 's';
    134 	if (howto & RB_KDB)
    135 		*ap++ = 'd';
    136 	*ap++ = 0;
    137 	if (ap[-2] == '-')
    138 		*ap1 = 0;
    139 	ppc_boot(str);
    140 }
    141 
    142 /*
    143  * XXX
    144  * The following code is subject to die at a later date.  This is the only
    145  * remaining code in this file subject to the Tools GmbH copyright.
    146  */
    147 
    148 void
    149 consinit()
    150 {
    151 
    152 	(*cn_tab->cn_probe)(cn_tab);
    153 }
    154 
    155 void	ofcons_cnprobe(struct consdev *);
    156 int	ofppc_cngetc(dev_t);
    157 void	ofppc_cnputc(dev_t, int);
    158 
    159 struct consdev ofppc_bootcons = {
    160 	ofcons_cnprobe, NULL, ofppc_cngetc, ofppc_cnputc, nullcnpollc, NULL,
    161 	    NULL, NULL, makedev(0,0), 1,
    162 };
    163 
    164 int	ofppc_stdin_ihandle, ofppc_stdout_ihandle;
    165 int	ofppc_stdin_phandle, ofppc_stdout_phandle;
    166 
    167 void
    168 ofppc_bootstrap_console(void)
    169 {
    170 	int chosen;
    171 	char data[4];
    172 
    173 	chosen = OF_finddevice("/chosen");
    174 
    175 	if (OF_getprop(chosen, "stdin", data, sizeof(data)) != sizeof(int))
    176 		goto nocons;
    177 	ofppc_stdin_ihandle = of_decode_int(data);
    178 	ofppc_stdin_phandle = OF_instance_to_package(ofppc_stdin_ihandle);
    179 
    180 	if (OF_getprop(chosen, "stdout", data, sizeof(data)) != sizeof(int))
    181 		goto nocons;
    182 	ofppc_stdout_ihandle = of_decode_int(data);
    183 	ofppc_stdout_phandle = OF_instance_to_package(ofppc_stdout_ihandle);
    184 
    185 	cn_tab = &ofppc_bootcons;
    186 
    187  nocons:
    188 	return;
    189 }
    190 
    191 int
    192 ofppc_cngetc(dev_t dev)
    193 {
    194 	u_char ch = '\0';
    195 	int l;
    196 
    197 	while ((l = OF_read(ofppc_stdin_ihandle, &ch, 1)) != 1)
    198 		if (l != -2 && l != 0)
    199 			return (-1);
    200 
    201 	return (ch);
    202 }
    203 
    204 void
    205 ofppc_cnputc(dev_t dev, int c)
    206 {
    207 	char ch = c;
    208 
    209 	OF_write(ofppc_stdout_ihandle, &ch, 1);
    210 }
    211 
    212