Home | History | Annotate | Line # | Download | only in obs405
obs266_machdep.c revision 1.6.52.1
      1  1.6.52.1       mjf /*	$NetBSD: obs266_machdep.c,v 1.6.52.1 2009/01/17 13:28:00 mjf Exp $	*/
      2       1.1     shige /*	Original: md_machdep.c,v 1.3 2005/01/24 18:47:37 shige Exp $	*/
      3       1.1     shige 
      4       1.1     shige /*
      5       1.1     shige  * Copyright 2001, 2002 Wasabi Systems, Inc.
      6       1.1     shige  * All rights reserved.
      7       1.1     shige  *
      8       1.1     shige  * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
      9       1.1     shige  *
     10       1.1     shige  * Redistribution and use in source and binary forms, with or without
     11       1.1     shige  * modification, are permitted provided that the following conditions
     12       1.1     shige  * are met:
     13       1.1     shige  * 1. Redistributions of source code must retain the above copyright
     14       1.1     shige  *    notice, this list of conditions and the following disclaimer.
     15       1.1     shige  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1     shige  *    notice, this list of conditions and the following disclaimer in the
     17       1.1     shige  *    documentation and/or other materials provided with the distribution.
     18       1.1     shige  * 3. All advertising materials mentioning features or use of this software
     19       1.1     shige  *    must display the following acknowledgement:
     20       1.1     shige  *      This product includes software developed for the NetBSD Project by
     21       1.1     shige  *      Wasabi Systems, Inc.
     22       1.1     shige  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     23       1.1     shige  *    or promote products derived from this software without specific prior
     24       1.1     shige  *    written permission.
     25       1.1     shige  *
     26       1.1     shige  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     27       1.1     shige  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1     shige  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1     shige  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     30       1.1     shige  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1     shige  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1     shige  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1     shige  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1     shige  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1     shige  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1     shige  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1     shige  */
     38       1.1     shige 
     39       1.1     shige /*
     40       1.1     shige  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
     41       1.1     shige  * Copyright (C) 1995, 1996 TooLs GmbH.
     42       1.1     shige  * All rights reserved.
     43       1.1     shige  *
     44       1.1     shige  * Redistribution and use in source and binary forms, with or without
     45       1.1     shige  * modification, are permitted provided that the following conditions
     46       1.1     shige  * are met:
     47       1.1     shige  * 1. Redistributions of source code must retain the above copyright
     48       1.1     shige  *    notice, this list of conditions and the following disclaimer.
     49       1.1     shige  * 2. Redistributions in binary form must reproduce the above copyright
     50       1.1     shige  *    notice, this list of conditions and the following disclaimer in the
     51       1.1     shige  *    documentation and/or other materials provided with the distribution.
     52       1.1     shige  * 3. All advertising materials mentioning features or use of this software
     53       1.1     shige  *    must display the following acknowledgement:
     54       1.1     shige  *	This product includes software developed by TooLs GmbH.
     55       1.1     shige  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     56       1.1     shige  *    derived from this software without specific prior written permission.
     57       1.1     shige  *
     58       1.1     shige  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     59       1.1     shige  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     60       1.1     shige  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     61       1.1     shige  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     62       1.1     shige  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     63       1.1     shige  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     64       1.1     shige  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     65       1.1     shige  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     66       1.1     shige  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     67       1.1     shige  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     68       1.1     shige  */
     69       1.1     shige 
     70       1.1     shige #include <sys/cdefs.h>
     71  1.6.52.1       mjf __KERNEL_RCSID(0, "$NetBSD: obs266_machdep.c,v 1.6.52.1 2009/01/17 13:28:00 mjf Exp $");
     72       1.1     shige 
     73       1.1     shige #include "opt_compat_netbsd.h"
     74       1.1     shige #include "opt_ddb.h"
     75       1.1     shige #include "opt_ipkdb.h"
     76       1.1     shige 
     77       1.1     shige #include <sys/param.h>
     78       1.1     shige #include <sys/kernel.h>
     79       1.1     shige #include <sys/ksyms.h>
     80       1.1     shige #include <sys/mount.h>
     81       1.1     shige #include <sys/reboot.h>
     82       1.1     shige #include <sys/systm.h>
     83  1.6.52.1       mjf #include <sys/device.h>
     84       1.1     shige 
     85       1.1     shige #include <uvm/uvm.h>
     86       1.1     shige #include <uvm/uvm_extern.h>
     87       1.1     shige 
     88       1.1     shige #include <machine/bus.h>
     89       1.1     shige #include <machine/cpu.h>
     90       1.1     shige #include <machine/obs266.h>
     91       1.1     shige #include <powerpc/spr.h>
     92       1.1     shige 
     93       1.4     shige #include <dev/pci/pcivar.h>
     94       1.4     shige #include <dev/pci/pciconf.h>
     95       1.4     shige 
     96       1.1     shige #include <powerpc/ibm4xx/dcr405gp.h>
     97       1.1     shige #include <powerpc/ibm4xx/openbios.h>
     98       1.1     shige 
     99       1.1     shige #include "ksyms.h"
    100       1.1     shige 
    101       1.5  kiyohara 
    102       1.5  kiyohara #define	TLB_PG_SIZE 	(16*1024*1024)
    103       1.5  kiyohara 
    104       1.1     shige /*
    105       1.1     shige  * Global variables used here and there
    106       1.1     shige  */
    107       1.1     shige char bootpath[256];
    108       1.1     shige 
    109       1.1     shige extern paddr_t msgbuf_paddr;
    110       1.1     shige 
    111  1.6.52.1       mjf #if NKSYMS || defined(DDB) || defined(MODULAR)
    112       1.1     shige void *startsym, *endsym;
    113       1.1     shige #endif
    114       1.1     shige 
    115       1.1     shige void initppc(u_int, u_int, char *, void *);
    116       1.1     shige int lcsplx(int);
    117       1.1     shige 
    118       1.1     shige 
    119       1.1     shige void
    120       1.1     shige initppc(u_int startkernel, u_int endkernel, char *args, void *info_block)
    121       1.1     shige {
    122       1.5  kiyohara 	vaddr_t va;
    123       1.1     shige 	u_int memsize;
    124       1.1     shige 
    125       1.1     shige 	/* Disable all external interrupts */
    126       1.1     shige 	mtdcr(DCR_UIC0_ER, 0);
    127       1.1     shige 
    128       1.1     shige 	/* Setup board from OpenBIOS */
    129       1.1     shige 	openbios_board_init(info_block, startkernel);
    130       1.1     shige 	memsize = openbios_board_memsize_get();
    131       1.1     shige 
    132       1.6     freza 	/* Linear map kernel memory */
    133       1.6     freza 	for (va = 0; va < endkernel; va += TLB_PG_SIZE)
    134       1.5  kiyohara 		ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX);
    135       1.5  kiyohara 
    136       1.6     freza 	/* Map console after RAM (see pmap_tlbmiss()) */
    137       1.6     freza 	ppc4xx_tlb_reserve(OBS405_CONADDR, roundup(memsize, TLB_PG_SIZE),
    138       1.6     freza 	    TLB_PG_SIZE, TLB_I | TLB_G);
    139       1.5  kiyohara 
    140       1.1     shige 	/* Initialize IBM405GPr CPU */
    141       1.1     shige 	ibm40x_memsize_init(memsize, startkernel);
    142       1.1     shige 	ibm4xx_init((void (*)(void))ext_intr);
    143       1.1     shige 
    144       1.1     shige 	/*
    145       1.1     shige 	 * Set the page size.
    146       1.1     shige 	 */
    147       1.1     shige 	uvm_setpagesize();
    148       1.1     shige 
    149       1.1     shige 	/*
    150       1.1     shige 	 * Initialize pmap module.
    151       1.1     shige 	 */
    152       1.1     shige 	pmap_bootstrap(startkernel, endkernel);
    153       1.1     shige 
    154       1.1     shige #ifdef DEBUG
    155       1.1     shige 	openbios_board_print();
    156       1.1     shige #endif
    157       1.1     shige 
    158  1.6.52.1       mjf #if NKSYMS || defined(DDB) || defined(MODULAR)
    159  1.6.52.1       mjf 	ksyms_addsyms_elf((int)((u_int)endsym - (u_int)startsym), startsym, endsym);
    160       1.1     shige #endif
    161       1.1     shige #ifdef DDB
    162       1.1     shige 	if (boothowto & RB_KDB)
    163       1.1     shige 		Debugger();
    164       1.1     shige #endif
    165       1.1     shige #ifdef IPKDB
    166       1.1     shige 	/*
    167       1.1     shige 	 * Now trap to IPKDB
    168       1.1     shige 	 */
    169       1.1     shige 	ipkdb_init();
    170       1.1     shige 	if (boothowto & RB_KDB)
    171       1.1     shige 		ipkdb_connect(0);
    172       1.1     shige #endif
    173       1.1     shige }
    174       1.1     shige 
    175       1.1     shige void
    176       1.1     shige consinit(void)
    177       1.1     shige {
    178       1.1     shige 
    179       1.1     shige 	obs405_consinit(OBS266_COM_FREQ);
    180       1.1     shige }
    181       1.1     shige 
    182       1.1     shige int
    183       1.1     shige lcsplx(int ipl)
    184       1.1     shige {
    185       1.1     shige 
    186       1.1     shige 	return spllower(ipl); 	/* XXX */
    187       1.1     shige }
    188       1.1     shige 
    189       1.1     shige 
    190       1.1     shige /*
    191       1.1     shige  * Machine dependent startup code.
    192       1.1     shige  */
    193       1.1     shige void
    194       1.1     shige cpu_startup(void)
    195       1.1     shige {
    196       1.1     shige 
    197       1.1     shige 	/*
    198       1.1     shige 	 * cpu common startup
    199       1.1     shige 	 */
    200       1.1     shige 	ibm4xx_cpu_startup("OpenBlockS266 IBM PowerPC 405GPr Board");
    201       1.1     shige 
    202       1.1     shige 	/*
    203       1.1     shige 	 * Set up the board properties database.
    204       1.1     shige 	 */
    205       1.1     shige 	openbios_board_info_set();
    206       1.1     shige 
    207       1.1     shige 	/*
    208       1.1     shige 	 * Now that we have VM, malloc()s are OK in bus_space.
    209       1.1     shige 	 */
    210       1.1     shige 	bus_space_mallocok();
    211       1.1     shige 
    212       1.1     shige 	/*
    213       1.1     shige 	 * no fake mapiodev
    214       1.1     shige 	 */
    215       1.1     shige 	fake_mapiodev = 0;
    216       1.1     shige }
    217       1.1     shige 
    218       1.1     shige /*
    219       1.1     shige  * Halt or reboot the machine after syncing/dumping according to howto.
    220       1.1     shige  */
    221       1.1     shige void
    222       1.1     shige cpu_reboot(int howto, char *what)
    223       1.1     shige {
    224       1.1     shige 	static int syncing;
    225       1.1     shige 	static char str[256];
    226       1.1     shige 	char *ap = str, *ap1 = ap;
    227       1.1     shige 
    228       1.1     shige 	boothowto = howto;
    229       1.1     shige 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    230       1.1     shige 		syncing = 1;
    231       1.1     shige 		vfs_shutdown();		/* sync */
    232       1.1     shige 		resettodr();		/* set wall clock */
    233       1.1     shige 	}
    234       1.1     shige 
    235       1.1     shige 	splhigh();
    236       1.1     shige 
    237       1.1     shige 	if (!cold && (howto & RB_DUMP))
    238       1.1     shige 		ibm4xx_dumpsys();
    239       1.1     shige 
    240       1.1     shige 	doshutdownhooks();
    241       1.1     shige 
    242  1.6.52.1       mjf 	pmf_system_shutdown(boothowto);
    243  1.6.52.1       mjf 
    244       1.1     shige 	if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
    245       1.1     shige 	  /* Power off here if we know how...*/
    246       1.1     shige 	}
    247       1.1     shige 
    248       1.1     shige 	if (howto & RB_HALT) {
    249       1.1     shige 		printf("halted\n\n");
    250       1.1     shige 
    251       1.1     shige #if 0
    252       1.1     shige 		goto reboot;	/* XXX for now... */
    253       1.1     shige #endif
    254       1.1     shige 
    255       1.1     shige #ifdef DDB
    256       1.1     shige 		printf("dropping to debugger\n");
    257       1.1     shige 		while(1)
    258       1.1     shige 			Debugger();
    259       1.1     shige #endif
    260       1.1     shige 	}
    261       1.1     shige 
    262       1.1     shige 	printf("rebooting\n\n");
    263       1.1     shige 	if (what && *what) {
    264       1.1     shige 		if (strlen(what) > sizeof str - 5)
    265       1.1     shige 			printf("boot string too large, ignored\n");
    266       1.1     shige 		else {
    267       1.1     shige 			strcpy(str, what);
    268       1.1     shige 			ap1 = ap = str + strlen(str);
    269       1.1     shige 			*ap++ = ' ';
    270       1.1     shige 		}
    271       1.1     shige 	}
    272       1.1     shige 	*ap++ = '-';
    273       1.1     shige 	if (howto & RB_SINGLE)
    274       1.1     shige 		*ap++ = 's';
    275       1.1     shige 	if (howto & RB_KDB)
    276       1.1     shige 		*ap++ = 'd';
    277       1.1     shige 	*ap++ = 0;
    278       1.1     shige 	if (ap[-2] == '-')
    279       1.1     shige 		*ap1 = 0;
    280       1.1     shige 
    281       1.1     shige 	/* flush cache for msgbuf */
    282       1.1     shige 	__syncicache((void *)msgbuf_paddr, round_page(MSGBUFSIZE));
    283       1.1     shige 
    284       1.1     shige #if 0
    285       1.1     shige  reboot:
    286       1.1     shige #endif
    287       1.1     shige 	ppc4xx_reset();
    288       1.1     shige 
    289       1.1     shige 	printf("ppc4xx_reset() failed!\n");
    290       1.1     shige #ifdef DDB
    291       1.1     shige 	while(1)
    292       1.1     shige 		Debugger();
    293       1.1     shige #else
    294       1.1     shige 	while (1)
    295       1.1     shige 		/* nothing */;
    296       1.1     shige #endif
    297       1.1     shige }
    298       1.4     shige 
    299       1.4     shige int
    300       1.4     shige pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    301       1.4     shige {
    302       1.4     shige 	/*
    303       1.4     shige 	 * We need to map the interrupt pin to the interrupt bit
    304       1.4     shige 	 * in the UIC associated with it.
    305       1.4     shige 	 *
    306       1.4     shige 	 * This platform has 4 PCI devices.
    307       1.4     shige 	 *
    308       1.4     shige 	 # External IRQ Mappings:
    309       1.4     shige 	 *  dev 1 (Ext IRQ3):	PCI Connector
    310       1.4     shige 	 *  dev 2 (Ext IRQ4):	PCI Connector
    311       1.4     shige 	 *  dev 3 (Ext IRQ5):	HPT IDE Controller
    312       1.4     shige 	 *  dev 4 (Ext IRQ6):	Davicom Ethernet
    313       1.4     shige 	 */
    314       1.4     shige 	static const int irqmap[4/*device*/][4/*pin*/] = {
    315       1.4     shige 		{  3,  3,  3,  3 },	/* 1: PCI Connector 1 */
    316       1.4     shige 		{  4,  4,  4,  4 },	/* 2: PCI Connector 2 */
    317       1.4     shige 		{  5,  5, -1, -1 },	/* 3: HPT IDE Controller */
    318       1.4     shige 		{  6,  6, -1, -1 },	/* 4: Damicom Ethernet */
    319       1.4     shige 	};
    320       1.4     shige 
    321       1.4     shige 	int pin, dev, irq;
    322       1.4     shige 
    323       1.4     shige 	pin = pa->pa_intrpin;
    324       1.4     shige 	dev = pa->pa_device;
    325       1.4     shige         *ihp = -1;
    326       1.4     shige 
    327       1.4     shige 	/* if interrupt pin not used... */
    328       1.4     shige 	if (pin == 0)
    329       1.4     shige 		return 1;
    330       1.4     shige 
    331       1.4     shige 	if (pin > 4) {
    332       1.4     shige 		printf("pci_intr_map: bad interrupt pin %d\n", pin);
    333       1.4     shige 		return 1;
    334       1.4     shige 	}
    335       1.4     shige 
    336       1.4     shige 	if ((dev < 1) || (dev > 4)) {
    337       1.4     shige 		printf("pci_intr_map: bad device %d\n", dev);
    338       1.4     shige 		return 1;
    339       1.4     shige 	}
    340       1.4     shige 
    341       1.4     shige 
    342       1.4     shige 	if ((irq = irqmap[dev - 1][pin - 1]) == -1) {
    343       1.4     shige 		printf("pci_intr_map: no IRQ routing for device %d pin %d\n",
    344       1.4     shige 			dev, pin);
    345       1.4     shige 		return 1;
    346       1.4     shige 	}
    347       1.4     shige 
    348       1.4     shige 	*ihp = irq + 25;
    349       1.4     shige 	return 0;
    350       1.4     shige }
    351       1.4     shige 
    352       1.4     shige void
    353       1.4     shige pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin,
    354       1.4     shige 			int swiz, int *iline)
    355       1.4     shige {
    356       1.4     shige 
    357       1.4     shige 	static const int ilinemap[4/*device*/] = {
    358       1.4     shige 		3, 4, 5 ,6
    359       1.4     shige 	};
    360       1.4     shige 
    361       1.4     shige 	if ((dev < 1) || (dev > 4)) {
    362       1.4     shige 		printf("pci_intr_map: bad device %d\n", dev);
    363       1.4     shige 		*iline = 0;
    364       1.4     shige 		return;
    365       1.4     shige 	}
    366       1.4     shige 	*iline = ilinemap[dev - 1] + 25;
    367       1.4     shige }
    368