Home | History | Annotate | Line # | Download | only in obs405
obs266_machdep.c revision 1.13
      1 /*	$NetBSD: obs266_machdep.c,v 1.13 2010/03/18 14:15:38 kiyohara 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.13 2010/03/18 14:15:38 kiyohara Exp $");
     72 
     73 #include "opt_compat_netbsd.h"
     74 #include "opt_ddb.h"
     75 #include "opt_ipkdb.h"
     76 #include "opt_modular.h"
     77 
     78 #include <sys/param.h>
     79 #include <sys/kernel.h>
     80 #include <sys/ksyms.h>
     81 #include <sys/mount.h>
     82 #include <sys/reboot.h>
     83 #include <sys/systm.h>
     84 #include <sys/device.h>
     85 
     86 #include <uvm/uvm.h>
     87 #include <uvm/uvm_extern.h>
     88 
     89 #include <machine/bus.h>
     90 #include <machine/cpu.h>
     91 #include <machine/obs266.h>
     92 #include <powerpc/spr.h>
     93 #include <powerpc/ibm4xx/dcr4xx.h>
     94 #include <powerpc/ibm4xx/dev/comopbvar.h>
     95 #include <powerpc/ibm4xx/ibm405gp.h>
     96 #include <powerpc/ibm4xx/openbios.h>
     97 #include <powerpc/ibm4xx/spr.h>
     98 
     99 #include <dev/ic/comreg.h>
    100 #include <dev/pci/pcivar.h>
    101 #include <dev/pci/pciconf.h>
    102 
    103 #include "ksyms.h"
    104 
    105 #include "com.h"
    106 #if (NCOM > 0)
    107 #include <sys/termios.h>
    108 
    109 #ifndef CONADDR
    110 #define CONADDR		IBM405GP_UART0_BASE
    111 #endif
    112 #ifndef CONSPEED
    113 #define CONSPEED	B9600
    114 #endif
    115 #ifndef CONMODE
    116 			/* 8N1 */
    117 #define CONMODE		((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)
    118 #endif
    119 #endif	/* NCOM */
    120 
    121 #define	TLB_PG_SIZE 	(16*1024*1024)
    122 
    123 /*
    124  * Global variables used here and there
    125  */
    126 char bootpath[256];
    127 
    128 extern paddr_t msgbuf_paddr;
    129 
    130 #if NKSYMS || defined(DDB) || defined(MODULAR)
    131 void *startsym, *endsym;
    132 #endif
    133 
    134 void initppc(u_int, u_int, char *, void *);
    135 int lcsplx(int);
    136 
    137 
    138 void
    139 initppc(u_int startkernel, u_int endkernel, char *args, void *info_block)
    140 {
    141 	vaddr_t va;
    142 	u_int memsize;
    143 
    144 	/* Setup board from OpenBIOS */
    145 	openbios_board_init(info_block, startkernel);
    146 	memsize = openbios_board_memsize_get();
    147 
    148 	/* Linear map kernel memory */
    149 	for (va = 0; va < endkernel; va += TLB_PG_SIZE)
    150 		ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX);
    151 
    152 	/* Map console after RAM (see pmap_tlbmiss()) */
    153 	ppc4xx_tlb_reserve(CONADDR, roundup(memsize, TLB_PG_SIZE), TLB_PG_SIZE,
    154 	    TLB_I | TLB_G);
    155 
    156 	/* Initialize IBM405GPr CPU */
    157 	ibm40x_memsize_init(memsize, startkernel);
    158 	ibm4xx_init((void (*)(void))ext_intr);
    159 
    160 	/*
    161 	 * Set the page size.
    162 	 */
    163 	uvm_setpagesize();
    164 
    165 	/*
    166 	 * Initialize pmap module.
    167 	 */
    168 	pmap_bootstrap(startkernel, endkernel);
    169 
    170 #ifdef DEBUG
    171 	openbios_board_print();
    172 #endif
    173 
    174 #if NKSYMS || defined(DDB) || defined(MODULAR)
    175 	ksyms_addsyms_elf((int)((u_int)endsym - (u_int)startsym), startsym, endsym);
    176 #endif
    177 #ifdef DDB
    178 	if (boothowto & RB_KDB)
    179 		Debugger();
    180 #endif
    181 #ifdef IPKDB
    182 	/*
    183 	 * Now trap to IPKDB
    184 	 */
    185 	ipkdb_init();
    186 	if (boothowto & RB_KDB)
    187 		ipkdb_connect(0);
    188 #endif
    189 }
    190 
    191 void
    192 consinit(void)
    193 {
    194 
    195 #if (NCOM > 0)
    196 	com_opb_cnattach(OBS266_COM_FREQ, CONADDR, CONSPEED, CONMODE);
    197 #endif
    198 }
    199 
    200 int
    201 lcsplx(int ipl)
    202 {
    203 
    204 	return spllower(ipl); 	/* XXX */
    205 }
    206 
    207 
    208 /*
    209  * Machine dependent startup code.
    210  */
    211 void
    212 cpu_startup(void)
    213 {
    214 
    215 	/*
    216 	 * cpu common startup
    217 	 */
    218 	ibm4xx_cpu_startup("OpenBlockS266 IBM PowerPC 405GPr Board");
    219 
    220 	/*
    221 	 * Set up the board properties database.
    222 	 */
    223 	openbios_board_info_set();
    224 
    225 	/*
    226 	 * Now that we have VM, malloc()s are OK in bus_space.
    227 	 */
    228 	bus_space_mallocok();
    229 
    230 	/*
    231 	 * no fake mapiodev
    232 	 */
    233 	fake_mapiodev = 0;
    234 }
    235 
    236 /*
    237  * Halt or reboot the machine after syncing/dumping according to howto.
    238  */
    239 void
    240 cpu_reboot(int howto, char *what)
    241 {
    242 	static int syncing;
    243 	static char str[256];
    244 	char *ap = str, *ap1 = ap;
    245 
    246 	boothowto = howto;
    247 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    248 		syncing = 1;
    249 		vfs_shutdown();		/* sync */
    250 		resettodr();		/* set wall clock */
    251 	}
    252 
    253 	splhigh();
    254 
    255 	if (!cold && (howto & RB_DUMP))
    256 		ibm4xx_dumpsys();
    257 
    258 	doshutdownhooks();
    259 
    260 	pmf_system_shutdown(boothowto);
    261 
    262 	if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
    263 	  /* Power off here if we know how...*/
    264 	}
    265 
    266 	if (howto & RB_HALT) {
    267 		printf("halted\n\n");
    268 
    269 #if 0
    270 		goto reboot;	/* XXX for now... */
    271 #endif
    272 
    273 #ifdef DDB
    274 		printf("dropping to debugger\n");
    275 		while(1)
    276 			Debugger();
    277 #endif
    278 	}
    279 
    280 	printf("rebooting\n\n");
    281 	if (what && *what) {
    282 		if (strlen(what) > sizeof str - 5)
    283 			printf("boot string too large, ignored\n");
    284 		else {
    285 			strcpy(str, what);
    286 			ap1 = ap = str + strlen(str);
    287 			*ap++ = ' ';
    288 		}
    289 	}
    290 	*ap++ = '-';
    291 	if (howto & RB_SINGLE)
    292 		*ap++ = 's';
    293 	if (howto & RB_KDB)
    294 		*ap++ = 'd';
    295 	*ap++ = 0;
    296 	if (ap[-2] == '-')
    297 		*ap1 = 0;
    298 
    299 	/* flush cache for msgbuf */
    300 	__syncicache((void *)msgbuf_paddr, round_page(MSGBUFSIZE));
    301 
    302 #if 0
    303  reboot:
    304 #endif
    305 	ppc4xx_reset();
    306 
    307 	printf("ppc4xx_reset() failed!\n");
    308 #ifdef DDB
    309 	while(1)
    310 		Debugger();
    311 #else
    312 	while (1)
    313 		/* nothing */;
    314 #endif
    315 }
    316 
    317 int
    318 pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
    319 {
    320 
    321 	/*
    322 	 * Bus number is irrelevant.  Configuration Mechanism 1 is in
    323 	 * use, can have devices 0-32 (i.e. the `normal' range).
    324 	 */
    325 	return 31;
    326 }
    327 
    328 int
    329 pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    330 {
    331 	/*
    332 	 * We need to map the interrupt pin to the interrupt bit
    333 	 * in the UIC associated with it.
    334 	 *
    335 	 * This platform has 4 PCI devices.
    336 	 *
    337 	 # External IRQ Mappings:
    338 	 *  dev 1 (Ext IRQ3):	PCI Connector
    339 	 *  dev 2 (Ext IRQ4):	PCI Connector
    340 	 *  dev 3 (Ext IRQ5):	HPT IDE Controller
    341 	 *  dev 4 (Ext IRQ6):	Davicom Ethernet
    342 	 */
    343 	static const int irqmap[4/*device*/][4/*pin*/] = {
    344 		{  3,  3,  3,  3 },	/* 1: PCI Connector 1 */
    345 		{  4,  4,  4,  4 },	/* 2: PCI Connector 2 */
    346 		{  5,  5, -1, -1 },	/* 3: HPT IDE Controller */
    347 		{  6,  6, -1, -1 },	/* 4: Damicom Ethernet */
    348 	};
    349 
    350 	int pin, dev, irq;
    351 
    352 	pin = pa->pa_intrpin;
    353 	dev = pa->pa_device;
    354         *ihp = -1;
    355 
    356 	/* if interrupt pin not used... */
    357 	if (pin == 0)
    358 		return 1;
    359 
    360 	if (pin > 4) {
    361 		printf("pci_intr_map: bad interrupt pin %d\n", pin);
    362 		return 1;
    363 	}
    364 
    365 	if ((dev < 1) || (dev > 4)) {
    366 		printf("pci_intr_map: bad device %d\n", dev);
    367 		return 1;
    368 	}
    369 
    370 
    371 	if ((irq = irqmap[dev - 1][pin - 1]) == -1) {
    372 		printf("pci_intr_map: no IRQ routing for device %d pin %d\n",
    373 			dev, pin);
    374 		return 1;
    375 	}
    376 
    377 	*ihp = irq + 25;
    378 	return 0;
    379 }
    380 
    381 void
    382 pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin,
    383 			int swiz, int *iline)
    384 {
    385 
    386 	static const int ilinemap[4/*device*/] = {
    387 		3, 4, 5 ,6
    388 	};
    389 
    390 	if ((dev < 1) || (dev > 4)) {
    391 		printf("pci_intr_map: bad device %d\n", dev);
    392 		*iline = 0;
    393 		return;
    394 	}
    395 	*iline = ilinemap[dev - 1] + 25;
    396 }
    397