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