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