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