Home | History | Annotate | Line # | Download | only in ofppc
      1  1.121    martin /*	$NetBSD: machdep.c,v 1.121 2024/12/16 11:52:43 martin 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  *
     18   1.96   garbled  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19   1.96   garbled  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20   1.96   garbled  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21   1.96   garbled  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22   1.96   garbled  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23   1.96   garbled  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24   1.96   garbled  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25   1.96   garbled  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26   1.96   garbled  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27   1.96   garbled  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28   1.96   garbled  * POSSIBILITY OF SUCH DAMAGE.
     29    1.1        ws  */
     30   1.86     lukem 
     31   1.86     lukem #include <sys/cdefs.h>
     32  1.121    martin __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.121 2024/12/16 11:52:43 martin Exp $");
     33  1.118   thorpej 
     34  1.118   thorpej #include "opt_ofwoea.h"
     35    1.1        ws 
     36    1.1        ws #include <sys/param.h>
     37  1.107    dyoung #include <sys/systm.h>
     38    1.1        ws #include <sys/buf.h>
     39   1.93   garbled #include <sys/boot_flag.h>
     40    1.1        ws #include <sys/mount.h>
     41   1.43   thorpej #include <sys/kernel.h>
     42  1.107    dyoung #include <sys/device.h>
     43    1.1        ws 
     44   1.19  sakamoto #include <uvm/uvm_extern.h>
     45   1.19  sakamoto 
     46   1.70   thorpej #include <dev/ofw/openfirm.h>
     47   1.93   garbled #include <dev/cons.h>
     48   1.70   thorpej 
     49   1.68      matt #include <machine/autoconf.h>
     50    1.1        ws #include <machine/pmap.h>
     51    1.1        ws #include <machine/powerpc.h>
     52    1.1        ws #include <machine/trap.h>
     53  1.115    dyoung #include <sys/bus.h>
     54   1.93   garbled #include <machine/isa_machdep.h>
     55   1.54   thorpej 
     56  1.110      matt #include <powerpc/spr.h>
     57  1.110      matt #include <powerpc/oea/spr.h>
     58   1.87      matt #include <powerpc/oea/bat.h>
     59   1.93   garbled #include <powerpc/ofw_cons.h>
     60  1.102   garbled #include <powerpc/rtas.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.109       phx #include "rtas.h"
     69   1.97   garbled 
     70  1.116      matt extern struct pmap ofw_pmap;
     71  1.116      matt extern char bootpath[256];
     72    1.1        ws 
     73   1.99   garbled extern u_int l2cr_config;
     74  1.108       phx #if (NRTAS > 0)
     75  1.103   garbled extern int machine_has_rtas;
     76  1.108       phx #endif
     77   1.99   garbled 
     78  1.105   garbled struct model_data modeldata;
     79  1.118   thorpej static void model_init(void);
     80  1.118   thorpej 
     81  1.118   thorpej #ifdef OFWOEA_DEBUG
     82  1.118   thorpej #define	DPRINTF printf
     83  1.118   thorpej #else
     84  1.118   thorpej #define	DPRINTF while (0) printf
     85  1.118   thorpej #endif
     86  1.118   thorpej 
     87  1.118   thorpej /*
     88  1.118   thorpej  * Scan the device tree for ranges, and return them as bitmap 0..15
     89  1.118   thorpej  */
     90  1.118   thorpej static uint16_t
     91  1.118   thorpej ranges_bitmap(int node, uint16_t bitmap)
     92  1.118   thorpej {
     93  1.118   thorpej 	int child, mlen, acells, scells, reclen, i, j;
     94  1.118   thorpej 	uint32_t addr, len, map[160];
     95  1.118   thorpej 
     96  1.118   thorpej 	for (child = OF_child(node); child; child = OF_peer(child)) {
     97  1.118   thorpej 		mlen = OF_getprop(child, "ranges", map, sizeof(map));
     98  1.118   thorpej 		if (mlen == -1)
     99  1.118   thorpej 	  		goto noranges;
    100  1.118   thorpej 
    101  1.118   thorpej 		j = OF_getprop(child, "#address-cells", &acells,
    102  1.118   thorpej 		    sizeof(acells));
    103  1.118   thorpej 		if (j == -1)
    104  1.118   thorpej 			goto noranges;
    105  1.118   thorpej 
    106  1.118   thorpej 		j = OF_getprop(child, "#size-cells", &scells,
    107  1.118   thorpej 		    sizeof(scells));
    108  1.118   thorpej 		if (j == -1)
    109  1.118   thorpej 			goto noranges;
    110  1.118   thorpej 
    111  1.118   thorpej 		reclen = acells + modeldata.ranges_offset + scells;
    112  1.118   thorpej 
    113  1.118   thorpej 		for (i = 0; i < (mlen / 4) / reclen; i++) {
    114  1.118   thorpej 			addr = map[reclen * i + acells];
    115  1.118   thorpej 			len = map[reclen * i + reclen - 1];
    116  1.118   thorpej 			for (j = 0; j < len / 0x10000000; j++)
    117  1.118   thorpej 				bitmap |= 1 << ((addr+j*0x10000000) >> 28);
    118  1.118   thorpej 			bitmap |= 1 << (addr >> 28);
    119  1.118   thorpej 		}
    120  1.118   thorpej  noranges:
    121  1.118   thorpej 		bitmap |= ranges_bitmap(child, bitmap);
    122  1.118   thorpej 		continue;
    123  1.118   thorpej 	}
    124  1.118   thorpej 	return bitmap;
    125  1.118   thorpej }
    126  1.105   garbled 
    127    1.1        ws void
    128   1.93   garbled initppc(u_int startkernel, u_int endkernel, char *args)
    129    1.1        ws {
    130  1.118   thorpej 	int node, i;
    131  1.118   thorpej 	uint16_t bitmap;
    132  1.118   thorpej 
    133  1.118   thorpej 	node = OF_finddevice("/");
    134  1.118   thorpej 	if (node != -1) {
    135  1.118   thorpej 		i = OF_getprop(node, "model", model_name, sizeof(model_name));
    136  1.118   thorpej 		if (i == -1) {
    137  1.118   thorpej 			OF_getprop(node, "name", model_name,
    138  1.118   thorpej 			    sizeof(model_name));
    139  1.118   thorpej 		}
    140  1.118   thorpej 	}
    141  1.121    martin 	model_init();
    142  1.118   thorpej 
    143  1.118   thorpej 	if ((oeacpufeat & OEACPU_NOBAT) == 0) {
    144  1.118   thorpej 		node = OF_finddevice("/");
    145  1.118   thorpej 
    146  1.118   thorpej 		bitmap = ranges_bitmap(node, 0);
    147  1.118   thorpej 		oea_batinit(0);
    148  1.118   thorpej 
    149  1.118   thorpej 		for (i = 1; i < 0x10; i++) {
    150  1.118   thorpej 			/* skip the three vital SR regions */
    151  1.118   thorpej 			if (i == USER_SR || i == KERNEL_SR || i == KERNEL2_SR) {
    152  1.118   thorpej 				continue;
    153  1.118   thorpej 			}
    154  1.118   thorpej 			if (bitmap & (1 << i)) {
    155  1.118   thorpej 				oea_iobat_add(0x10000000 * i, BAT_BL_256M);
    156  1.118   thorpej 				DPRINTF("Batmapped 256M at 0x%x\n",
    157  1.118   thorpej 				    0x10000000 * i);
    158  1.118   thorpej 			}
    159  1.118   thorpej 		}
    160  1.118   thorpej 	}
    161  1.118   thorpej 
    162  1.119   thorpej #if defined(MULTIPROCESSOR)
    163  1.119   thorpej 	int l;
    164  1.119   thorpej 	char cpupath[32];
    165  1.119   thorpej 
    166  1.119   thorpej 	extern void cpu_spinstart(u_int);
    167  1.119   thorpej 	extern volatile u_int cpu_spinstart_ack;
    168  1.119   thorpej 
    169  1.119   thorpej 	for (i = 1; i < CPU_MAXNUM; i++) {
    170  1.119   thorpej 		snprintf(cpupath, sizeof(cpupath), "/cpus/@%x", i);
    171  1.119   thorpej 		node = OF_finddevice(cpupath);
    172  1.119   thorpej 		if (node <= 0)
    173  1.119   thorpej 			continue;
    174  1.119   thorpej 		aprint_verbose("Starting up CPU %d %s\n", i, cpupath);
    175  1.119   thorpej 		OF_start_cpu(node, (u_int)cpu_spinstart, i);
    176  1.119   thorpej 		for (l = 0; l < 100000000; l++) {
    177  1.119   thorpej 			if (cpu_spinstart_ack == i) {
    178  1.119   thorpej 				aprint_verbose("CPU %d spun up.\n", i);
    179  1.119   thorpej 				break;
    180  1.119   thorpej 			}
    181  1.119   thorpej 			__asm volatile ("sync");
    182  1.119   thorpej 		}
    183  1.119   thorpej 	}
    184  1.119   thorpej #endif /* MULTIPROCESSOR */
    185  1.119   thorpej 
    186   1.93   garbled 	ofwoea_initppc(startkernel, endkernel, args);
    187    1.1        ws }
    188    1.1        ws 
    189   1.98   garbled /* perform model-specific actions at initppc() */
    190  1.118   thorpej static void
    191   1.98   garbled model_init(void)
    192   1.98   garbled {
    193  1.105   garbled 	int qhandle, phandle, j;
    194  1.105   garbled 
    195  1.105   garbled 	memset(&modeldata, 0, sizeof(struct model_data));
    196  1.105   garbled 	/* provide sane defaults */
    197  1.105   garbled 	for (j=0; j < MAX_PCI_BUSSES; j++) {
    198  1.105   garbled 		modeldata.pciiodata[j].start = 0x00008000;
    199  1.105   garbled 		modeldata.pciiodata[j].limit = 0x0000ffff;
    200  1.105   garbled 	}
    201  1.105   garbled 	modeldata.ranges_offset = 1;
    202  1.105   garbled 
    203  1.105   garbled 	if (strncmp(model_name, "FirePower,", 10) == 0) {
    204  1.105   garbled 		modeldata.ranges_offset = 0;
    205  1.105   garbled 	}
    206  1.105   garbled 	if (strcmp(model_name, "MOT,PowerStack_II_Pro4000") == 0) {
    207  1.105   garbled 		modeldata.ranges_offset = 0;
    208  1.105   garbled 	}
    209  1.105   garbled 
    210  1.105   garbled 	/* 7044-270 and 7044-170 */
    211  1.105   garbled 	if (strncmp(model_name, "IBM,7044", 8) == 0) {
    212  1.105   garbled 		for (j=0; j < MAX_PCI_BUSSES; j++) {
    213  1.105   garbled 			modeldata.pciiodata[j].start = 0x00fff000;
    214  1.105   garbled 			modeldata.pciiodata[j].limit = 0x00ffffff;
    215  1.105   garbled 		}
    216  1.105   garbled 	}
    217   1.98   garbled 
    218   1.98   garbled 	/* Pegasos1, Pegasos2 */
    219   1.98   garbled 	if (strncmp(model_name, "Pegasos", 7) == 0) {
    220   1.98   garbled 		static uint16_t modew[] = { 640, 800, 1024, 1280, 0 };
    221   1.98   garbled 		static uint16_t modeh[] = { 480, 600, 768, 1024, 0 };
    222   1.98   garbled 		uint32_t width, height, mode, fbaddr;
    223   1.98   garbled 		char buf[32];
    224   1.98   garbled 		int i;
    225   1.98   garbled 
    226  1.105   garbled 		modeldata.pciiodata[0].start = 0x00001400;
    227  1.105   garbled 		modeldata.pciiodata[0].limit = 0x0000ffff;
    228  1.105   garbled 
    229  1.113       phx 		/* the pegasos doesn't bother to set the L2 cache up */
    230   1.99   garbled 		l2cr_config = L2CR_L2PE;
    231   1.99   garbled 
    232   1.98   garbled 		/* fix the device_type property of a graphics card */
    233   1.98   garbled 		for (qhandle = OF_peer(0); qhandle; qhandle = phandle) {
    234   1.98   garbled 			if (OF_getprop(qhandle, "name", buf, sizeof buf) > 0
    235   1.98   garbled 			    && strncmp(buf, "display", 7) == 0) {
    236   1.98   garbled 				OF_setprop(qhandle, "device_type", "display", 8);
    237   1.98   garbled 				break;
    238   1.98   garbled 			}
    239   1.98   garbled 			if ((phandle = OF_child(qhandle)))
    240   1.98   garbled 				continue;
    241   1.98   garbled 			while (qhandle) {
    242   1.98   garbled 				if ((phandle = OF_peer(qhandle)))
    243   1.98   garbled 					break;
    244   1.98   garbled 				qhandle = OF_parent(qhandle);
    245   1.98   garbled 			}
    246   1.98   garbled 		}
    247   1.98   garbled 
    248   1.98   garbled 		/*
    249   1.98   garbled 		 * Get screen width/height and switch to framebuffer mode.
    250   1.98   garbled 		 * The default dimensions are: 800 x 600
    251   1.98   garbled 		 */
    252   1.98   garbled 		OF_interpret("screen-width", 0, 1, &width);
    253   1.98   garbled 		if (width == 0)
    254   1.98   garbled 			width = 800;
    255   1.98   garbled 
    256   1.98   garbled 		OF_interpret("screen-height", 0, 1, &height);
    257   1.98   garbled 		if (height == 0)
    258   1.98   garbled 			height = 600;
    259   1.98   garbled 
    260   1.98   garbled 		/* find VESA mode */
    261   1.98   garbled 		for (i = 0, mode = 0; modew[i] != 0; i++) {
    262   1.98   garbled 			if (modew[i] == width && modeh[i] == height) {
    263   1.98   garbled 				mode = 0x101 + 2 * i;
    264   1.98   garbled 				break;
    265   1.98   garbled 			}
    266   1.98   garbled 		}
    267   1.98   garbled 		if (!mode) {
    268  1.113       phx 			mode = 0x103;
    269   1.98   garbled 			width = 800;
    270   1.98   garbled 			height = 600;
    271   1.98   garbled 		}
    272   1.98   garbled 
    273   1.98   garbled 		/* init frame buffer mode */
    274  1.117  christos 		snprintf(buf, sizeof(buf), "%x vesa-set-mode", mode);
    275   1.98   garbled 		OF_interpret(buf, 0, 0);
    276   1.98   garbled 
    277   1.98   garbled 		/* set dimensions and frame buffer address in OFW */
    278  1.117  christos 		snprintf(buf, sizeof(buf), "%x to screen-width", width);
    279   1.98   garbled 		OF_interpret(buf, 0, 0);
    280  1.117  christos 		snprintf(buf, sizeof(buf), "%x to screen-height", height);
    281   1.98   garbled 		OF_interpret(buf, 0, 0);
    282   1.98   garbled 		OF_interpret("vesa-frame-buffer-adr", 0, 1, &fbaddr);
    283   1.98   garbled 		if (fbaddr != 0) {
    284  1.117  christos 			snprintf(buf, sizeof(buf), "%x to frame-buffer-adr", fbaddr);
    285   1.98   garbled 			OF_interpret(buf, 0, 0);
    286   1.98   garbled 		}
    287   1.98   garbled 	}
    288   1.98   garbled }
    289   1.98   garbled 
    290    1.1        ws void
    291   1.93   garbled cpu_startup(void)
    292    1.1        ws {
    293   1.98   garbled 	oea_startup(model_name[0] ? model_name : NULL);
    294  1.104   garbled 	bus_space_mallocok();
    295    1.1        ws }
    296    1.1        ws 
    297   1.96   garbled 
    298    1.1        ws void
    299   1.93   garbled consinit(void)
    300    1.1        ws {
    301   1.93   garbled 	ofwoea_consinit();
    302   1.71   thorpej }
    303   1.96   garbled 
    304   1.71   thorpej 
    305   1.71   thorpej void
    306   1.93   garbled dumpsys(void)
    307   1.71   thorpej {
    308  1.101   garbled 	aprint_normal("dumpsys: TBD\n");
    309    1.1        ws }
    310    1.1        ws 
    311    1.1        ws /*
    312   1.93   garbled  * Halt or reboot the machine after syncing/dumping according to howto.
    313    1.1        ws  */
    314    1.1        ws 
    315    1.1        ws void
    316   1.93   garbled cpu_reboot(int howto, char *what)
    317    1.1        ws {
    318    1.1        ws 	static int syncing;
    319    1.1        ws 	static char str[256];
    320  1.108       phx 	char *ap = str, *ap1 = ap;
    321  1.108       phx #if (NRTAS > 0)
    322  1.102   garbled 	int junk;
    323  1.108       phx #endif
    324    1.1        ws 
    325    1.1        ws 	boothowto = howto;
    326    1.1        ws 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    327    1.1        ws 		syncing = 1;
    328   1.93   garbled 		vfs_shutdown();         /* sync */
    329    1.1        ws 	}
    330    1.1        ws 	splhigh();
    331    1.1        ws 	if (howto & RB_HALT) {
    332    1.1        ws 		doshutdownhooks();
    333  1.107    dyoung 		pmf_system_shutdown(boothowto);
    334  1.101   garbled 		aprint_normal("halted\n\n");
    335  1.108       phx #if (NRTAS > 0)
    336  1.103   garbled 		if ((howto & 0x800) && machine_has_rtas &&
    337  1.103   garbled 		    rtas_has_func(RTAS_FUNC_POWER_OFF))
    338  1.103   garbled 			rtas_call(RTAS_FUNC_POWER_OFF, 2, 1, 0, 0, &junk);
    339  1.108       phx #endif
    340    1.1        ws 		ppc_exit();
    341    1.1        ws 	}
    342    1.1        ws 	if (!cold && (howto & RB_DUMP))
    343   1.82      matt 		oea_dumpsys();
    344    1.1        ws 	doshutdownhooks();
    345  1.107    dyoung 
    346  1.107    dyoung 	pmf_system_shutdown(boothowto);
    347  1.101   garbled 	aprint_normal("rebooting\n\n");
    348   1.95   garbled 
    349  1.108       phx #if (NRTAS > 0)
    350  1.103   garbled 	if (machine_has_rtas && rtas_has_func(RTAS_FUNC_SYSTEM_REBOOT)) {
    351  1.103   garbled 		rtas_call(RTAS_FUNC_SYSTEM_REBOOT, 0, 1, &junk);
    352  1.103   garbled 		for(;;);
    353  1.103   garbled 	}
    354  1.108       phx #endif
    355    1.1        ws 	if (what && *what) {
    356    1.1        ws 		if (strlen(what) > sizeof str - 5)
    357  1.101   garbled 			aprint_normal("boot string too large, ignored\n");
    358    1.1        ws 		else {
    359    1.1        ws 			strcpy(str, what);
    360    1.1        ws 			ap1 = ap = str + strlen(str);
    361    1.1        ws 			*ap++ = ' ';
    362    1.1        ws 		}
    363    1.1        ws 	}
    364    1.1        ws 	*ap++ = '-';
    365    1.1        ws 	if (howto & RB_SINGLE)
    366    1.1        ws 		*ap++ = 's';
    367    1.1        ws 	if (howto & RB_KDB)
    368    1.1        ws 		*ap++ = 'd';
    369    1.1        ws 	*ap++ = 0;
    370    1.1        ws 	if (ap[-2] == '-')
    371    1.1        ws 		*ap1 = 0;
    372    1.1        ws 	ppc_boot(str);
    373    1.1        ws }
    374   1.97   garbled 
    375   1.97   garbled /*
    376   1.97   garbled  */
    377   1.97   garbled 
    378   1.97   garbled #define divrnd(n, q)	(((n)*2/(q)+1)/2)
    379   1.97   garbled 
    380   1.97   garbled void
    381   1.98   garbled ofppc_init_comcons(int isa_node)
    382   1.97   garbled {
    383   1.97   garbled #if (NCOM > 0)
    384   1.97   garbled 	char name[64];
    385   1.97   garbled 	uint32_t reg[2], comfreq;
    386   1.97   garbled 	uint8_t dll, dlm;
    387   1.98   garbled 	int speed, rate, err, com_node, child;
    388  1.104   garbled 	bus_space_handle_t comh;
    389   1.97   garbled 
    390   1.97   garbled 	/* if we have a serial cons, we have work to do */
    391   1.97   garbled 	memset(name, 0, sizeof(name));
    392   1.97   garbled 	OF_getprop(console_node, "device_type", name, sizeof(name));
    393   1.97   garbled 	if (strcmp(name, "serial") != 0)
    394   1.97   garbled 		return;
    395   1.97   garbled 
    396   1.98   garbled 	/* scan ISA children for serial devices to match our console */
    397   1.98   garbled 	com_node = -1;
    398   1.98   garbled 	for (child = OF_child(isa_node); child; child = OF_peer(child)) {
    399   1.98   garbled 		memset(name, 0, sizeof(name));
    400   1.98   garbled 		OF_getprop(child, "device_type", name, sizeof(name));
    401   1.98   garbled 		if (strcmp(name, "serial") == 0) {
    402   1.98   garbled 			/*
    403   1.98   garbled 			 * Serial device even matches our console_node?
    404   1.98   garbled 			 * Then we're done!
    405   1.98   garbled 			 */
    406   1.98   garbled 			if (child == console_node) {
    407   1.98   garbled 				com_node = child;
    408   1.98   garbled 				break;
    409   1.98   garbled 			}
    410   1.98   garbled 			/* remember first serial device found */
    411   1.98   garbled 			if (com_node == -1)
    412   1.98   garbled 				com_node = child;
    413   1.98   garbled 		}
    414   1.98   garbled 	}
    415   1.98   garbled 
    416   1.98   garbled 	if (com_node == -1)
    417   1.98   garbled 		return;
    418   1.98   garbled 
    419   1.98   garbled 	if (OF_getprop(com_node, "reg", reg, sizeof(reg)) == -1)
    420   1.97   garbled 		return;
    421   1.97   garbled 
    422   1.98   garbled 	if (OF_getprop(com_node, "clock-frequency", &comfreq, 4) == -1)
    423   1.97   garbled 		comfreq = 0;
    424   1.97   garbled 
    425   1.97   garbled 	if (comfreq == 0)
    426   1.97   garbled 		comfreq = COM_FREQ;
    427   1.97   garbled 
    428  1.104   garbled 	/* we need to BSM this, and then undo that before calling
    429  1.104   garbled 	 * comcnattach.
    430  1.104   garbled 	 */
    431  1.104   garbled 
    432  1.104   garbled 	if (bus_space_map(&genppc_isa_io_space_tag, reg[1], 8, 0, &comh) != 0)
    433  1.104   garbled 		panic("Can't map isa serial\n");
    434  1.104   garbled 
    435  1.104   garbled 	bus_space_write_1(&genppc_isa_io_space_tag, comh, com_cfcr, LCR_DLAB);
    436  1.104   garbled 	dll = bus_space_read_1(&genppc_isa_io_space_tag, comh, com_dlbl);
    437  1.104   garbled 	dlm = bus_space_read_1(&genppc_isa_io_space_tag, comh, com_dlbh);
    438   1.97   garbled 	rate = dll | (dlm << 8);
    439  1.104   garbled 	bus_space_write_1(&genppc_isa_io_space_tag, comh, com_cfcr, LCR_8BITS);
    440   1.97   garbled 	speed = divrnd((comfreq / 16), rate);
    441   1.97   garbled 	err = speed - (speed + 150)/300 * 300;
    442   1.97   garbled 	speed -= err;
    443   1.97   garbled 	if (err < 0)
    444   1.97   garbled 		err = -err;
    445   1.97   garbled 	if (err > 50)
    446   1.97   garbled 		speed = 9600;
    447   1.97   garbled 
    448  1.104   garbled 	bus_space_unmap(&genppc_isa_io_space_tag, comh, 8);
    449  1.104   garbled 
    450   1.97   garbled 	/* Now we can attach the comcons */
    451   1.97   garbled 	aprint_verbose("Switching to COM console at speed %d", speed);
    452   1.98   garbled 	if (comcnattach(&genppc_isa_io_space_tag, reg[1],
    453   1.98   garbled 	    speed, comfreq, COM_TYPE_NORMAL,
    454   1.97   garbled 	    ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)))
    455   1.97   garbled 		panic("Can't init serial console");
    456   1.97   garbled 	aprint_verbose("\n");
    457   1.97   garbled #endif /*NCOM*/
    458   1.97   garbled }
    459   1.98   garbled 
    460   1.98   garbled void
    461  1.114      matt copy_disp_props(device_t dev, int node, prop_dictionary_t dict)
    462   1.98   garbled {
    463   1.98   garbled 	uint32_t temp;
    464   1.98   garbled 	char typestr[32];
    465   1.98   garbled 
    466   1.98   garbled 	memset(typestr, 0, sizeof(typestr));
    467   1.98   garbled 	OF_getprop(console_node, "device_type", typestr, sizeof(typestr));
    468   1.98   garbled 	if (strcmp(typestr, "serial") != 0) {
    469   1.98   garbled 		/* this is our console, when we don't have a serial console */
    470   1.98   garbled 		prop_dictionary_set_bool(dict, "is_console", 1);
    471   1.98   garbled 	}
    472   1.98   garbled 
    473   1.98   garbled 	if (!of_to_uint32_prop(dict, node, "width", "width")) {
    474   1.98   garbled 
    475   1.98   garbled 		OF_interpret("screen-width", 0, 1, &temp);
    476   1.98   garbled 		prop_dictionary_set_uint32(dict, "width", temp);
    477   1.98   garbled 	}
    478   1.98   garbled 	if (!of_to_uint32_prop(dict, node, "height", "height")) {
    479   1.98   garbled 
    480   1.98   garbled 		OF_interpret("screen-height", 0, 1, &temp);
    481   1.98   garbled 		prop_dictionary_set_uint32(dict, "height", temp);
    482   1.98   garbled 	}
    483   1.98   garbled 	of_to_uint32_prop(dict, node, "linebytes", "linebytes");
    484   1.98   garbled 	if (!of_to_uint32_prop(dict, node, "depth", "depth")) {
    485   1.98   garbled 		/*
    486   1.98   garbled 		 * XXX we should check linebytes vs. width but those
    487   1.98   garbled 		 * FBs that don't have a depth property ( /chaos/control... )
    488   1.98   garbled 		 * won't have linebytes either
    489   1.98   garbled 		 */
    490   1.98   garbled 		prop_dictionary_set_uint32(dict, "depth", 8);
    491   1.98   garbled 	}
    492   1.98   garbled 	if (!of_to_uint32_prop(dict, node, "address", "address")) {
    493   1.98   garbled 		uint32_t fbaddr = 0;
    494  1.111  kiyohara 
    495  1.111  kiyohara 		OF_interpret("frame-buffer-adr", 0, 1, &fbaddr);
    496   1.98   garbled 		if (fbaddr != 0)
    497   1.98   garbled 			prop_dictionary_set_uint32(dict, "address", fbaddr);
    498   1.98   garbled 	}
    499   1.98   garbled }
    500