Home | History | Annotate | Line # | Download | only in ofppc
machdep.c revision 1.97
      1  1.97   garbled /*	$NetBSD: machdep.c,v 1.97 2007/11/13 19:17:31 garbled Exp $	*/
      2  1.96   garbled /*-
      3  1.96   garbled  * Copyright (c) 2007 The NetBSD Foundation, Inc.
      4   1.1        ws  * All rights reserved.
      5   1.1        ws  *
      6  1.96   garbled  * This code is derived from software contributed to The NetBSD Foundation
      7  1.96   garbled  * by Tim Rightnour
      8  1.96   garbled  *
      9   1.1        ws  * Redistribution and use in source and binary forms, with or without
     10   1.1        ws  * modification, are permitted provided that the following conditions
     11   1.1        ws  * are met:
     12   1.1        ws  * 1. Redistributions of source code must retain the above copyright
     13   1.1        ws  *    notice, this list of conditions and the following disclaimer.
     14   1.1        ws  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1        ws  *    notice, this list of conditions and the following disclaimer in the
     16   1.1        ws  *    documentation and/or other materials provided with the distribution.
     17   1.1        ws  * 3. All advertising materials mentioning features or use of this software
     18   1.1        ws  *    must display the following acknowledgement:
     19  1.96   garbled  *        This product includes software developed by the NetBSD
     20  1.96   garbled  *        Foundation, Inc. and its contributors.
     21  1.96   garbled  * 4. Neither the name of The NetBSD Foundation nor the names of its
     22  1.96   garbled  *    contributors may be used to endorse or promote products derived
     23  1.96   garbled  *    from this software without specific prior written permission.
     24   1.1        ws  *
     25  1.96   garbled  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     26  1.96   garbled  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.96   garbled  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.96   garbled  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     29  1.96   garbled  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.96   garbled  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.96   garbled  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.96   garbled  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.96   garbled  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.96   garbled  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.96   garbled  * POSSIBILITY OF SUCH DAMAGE.
     36   1.1        ws  */
     37  1.86     lukem 
     38  1.86     lukem #include <sys/cdefs.h>
     39  1.97   garbled __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.97 2007/11/13 19:17:31 garbled Exp $");
     40   1.1        ws 
     41   1.1        ws #include <sys/param.h>
     42   1.1        ws #include <sys/buf.h>
     43  1.93   garbled #include <sys/boot_flag.h>
     44   1.1        ws #include <sys/mount.h>
     45  1.43   thorpej #include <sys/kernel.h>
     46   1.1        ws 
     47  1.19  sakamoto #include <uvm/uvm_extern.h>
     48  1.19  sakamoto 
     49  1.70   thorpej #include <dev/ofw/openfirm.h>
     50  1.93   garbled #include <dev/cons.h>
     51  1.70   thorpej 
     52  1.68      matt #include <machine/autoconf.h>
     53   1.1        ws #include <machine/pmap.h>
     54   1.1        ws #include <machine/powerpc.h>
     55   1.1        ws #include <machine/trap.h>
     56  1.93   garbled #include <machine/bus.h>
     57  1.93   garbled #include <machine/isa_machdep.h>
     58  1.54   thorpej 
     59  1.87      matt #include <powerpc/oea/bat.h>
     60  1.93   garbled #include <powerpc/ofw_cons.h>
     61  1.71   thorpej 
     62  1.97   garbled #include "com.h"
     63  1.97   garbled #if (NCOM > 0)
     64  1.97   garbled #include <sys/termios.h>
     65  1.97   garbled #include <dev/ic/comreg.h>
     66  1.97   garbled #include <dev/ic/comvar.h>
     67  1.97   garbled #endif
     68  1.97   garbled 
     69  1.93   garbled struct pmap ofw_pmap;
     70  1.78       chs char bootpath[256];
     71  1.97   garbled extern int console_node;
     72   1.1        ws 
     73  1.93   garbled void ofwppc_batinit(void);
     74  1.71   thorpej void	ofppc_bootstrap_console(void);
     75  1.77      matt 
     76   1.1        ws void
     77  1.93   garbled initppc(u_int startkernel, u_int endkernel, char *args)
     78   1.1        ws {
     79  1.93   garbled 	ofwoea_initppc(startkernel, endkernel, args);
     80   1.1        ws }
     81   1.1        ws 
     82   1.1        ws void
     83  1.93   garbled cpu_startup(void)
     84   1.1        ws {
     85  1.82      matt 	oea_startup(NULL);
     86   1.1        ws }
     87   1.1        ws 
     88  1.96   garbled 
     89   1.1        ws void
     90  1.93   garbled consinit(void)
     91   1.1        ws {
     92  1.93   garbled 	ofwoea_consinit();
     93  1.71   thorpej }
     94  1.96   garbled 
     95  1.71   thorpej 
     96  1.71   thorpej void
     97  1.93   garbled dumpsys(void)
     98  1.71   thorpej {
     99  1.93   garbled 	printf("dumpsys: TBD\n");
    100   1.1        ws }
    101   1.1        ws 
    102   1.1        ws /*
    103  1.93   garbled  * Halt or reboot the machine after syncing/dumping according to howto.
    104   1.1        ws  */
    105  1.95   garbled void rtas_reboot(void);
    106   1.1        ws 
    107   1.1        ws void
    108  1.93   garbled cpu_reboot(int howto, char *what)
    109   1.1        ws {
    110   1.1        ws 	static int syncing;
    111   1.1        ws 	static char str[256];
    112   1.1        ws 	char *ap = str, *ap1 = ap;
    113   1.1        ws 
    114   1.1        ws 	boothowto = howto;
    115   1.1        ws 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    116   1.1        ws 		syncing = 1;
    117  1.93   garbled 		vfs_shutdown();         /* sync */
    118  1.93   garbled 		resettodr();            /* set wall clock */
    119   1.1        ws 	}
    120   1.1        ws 	splhigh();
    121   1.1        ws 	if (howto & RB_HALT) {
    122   1.1        ws 		doshutdownhooks();
    123   1.3  christos 		printf("halted\n\n");
    124   1.1        ws 		ppc_exit();
    125   1.1        ws 	}
    126   1.1        ws 	if (!cold && (howto & RB_DUMP))
    127  1.82      matt 		oea_dumpsys();
    128   1.1        ws 	doshutdownhooks();
    129   1.3  christos 	printf("rebooting\n\n");
    130  1.95   garbled 
    131  1.95   garbled 	rtas_reboot();
    132  1.95   garbled 
    133   1.1        ws 	if (what && *what) {
    134   1.1        ws 		if (strlen(what) > sizeof str - 5)
    135   1.3  christos 			printf("boot string too large, ignored\n");
    136   1.1        ws 		else {
    137   1.1        ws 			strcpy(str, what);
    138   1.1        ws 			ap1 = ap = str + strlen(str);
    139   1.1        ws 			*ap++ = ' ';
    140   1.1        ws 		}
    141   1.1        ws 	}
    142   1.1        ws 	*ap++ = '-';
    143   1.1        ws 	if (howto & RB_SINGLE)
    144   1.1        ws 		*ap++ = 's';
    145   1.1        ws 	if (howto & RB_KDB)
    146   1.1        ws 		*ap++ = 'd';
    147   1.1        ws 	*ap++ = 0;
    148   1.1        ws 	if (ap[-2] == '-')
    149   1.1        ws 		*ap1 = 0;
    150   1.1        ws 	ppc_boot(str);
    151   1.1        ws }
    152  1.97   garbled 
    153  1.97   garbled /*
    154  1.97   garbled  */
    155  1.97   garbled 
    156  1.97   garbled #define divrnd(n, q)	(((n)*2/(q)+1)/2)
    157  1.97   garbled 
    158  1.97   garbled void
    159  1.97   garbled ofppc_init_comcons(void)
    160  1.97   garbled {
    161  1.97   garbled #if (NCOM > 0)
    162  1.97   garbled 	char name[64];
    163  1.97   garbled 	uint32_t reg[2], comfreq;
    164  1.97   garbled 	uint8_t dll, dlm;
    165  1.97   garbled 	int speed, rate, err;
    166  1.97   garbled 	bus_space_tag_t tag = &genppc_isa_io_space_tag;
    167  1.97   garbled 
    168  1.97   garbled 	/* if we have a serial cons, we have work to do */
    169  1.97   garbled 	memset(name, 0, sizeof(name));
    170  1.97   garbled 	OF_getprop(console_node, "device_type", name, sizeof(name));
    171  1.97   garbled 	if (strcmp(name, "serial") != 0)
    172  1.97   garbled 		return;
    173  1.97   garbled 
    174  1.97   garbled 	if (OF_getprop(console_node, "reg", reg, sizeof(reg)) == -1)
    175  1.97   garbled 		return;
    176  1.97   garbled 
    177  1.97   garbled 	if (OF_getprop(console_node, "clock-frequency", &comfreq, 4) == -1)
    178  1.97   garbled 		comfreq = 0;
    179  1.97   garbled 
    180  1.97   garbled 	if (comfreq == 0)
    181  1.97   garbled 		comfreq = COM_FREQ;
    182  1.97   garbled 
    183  1.97   garbled 	isa_outb(reg[1] + com_cfcr, LCR_DLAB);
    184  1.97   garbled 	dll = isa_inb(reg[1] + com_dlbl);
    185  1.97   garbled 	dlm = isa_inb(reg[1] + com_dlbh);
    186  1.97   garbled 	rate = dll | (dlm << 8);
    187  1.97   garbled 	isa_outb(reg[1] + com_cfcr, LCR_8BITS);
    188  1.97   garbled 	speed = divrnd((comfreq / 16), rate);
    189  1.97   garbled 	err = speed - (speed + 150)/300 * 300;
    190  1.97   garbled 	speed -= err;
    191  1.97   garbled 	if (err < 0)
    192  1.97   garbled 		err = -err;
    193  1.97   garbled 	if (err > 50)
    194  1.97   garbled 		speed = 9600;
    195  1.97   garbled 
    196  1.97   garbled 	/* Now we can attach the comcons */
    197  1.97   garbled 	aprint_verbose("Switching to COM console at speed %d", speed);
    198  1.97   garbled 	if (comcnattach(tag, reg[1], speed, comfreq, COM_TYPE_NORMAL,
    199  1.97   garbled 	    ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)))
    200  1.97   garbled 		panic("Can't init serial console");
    201  1.97   garbled 	aprint_verbose("\n");
    202  1.97   garbled #endif /*NCOM*/
    203  1.97   garbled }
    204