Home | History | Annotate | Line # | Download | only in walnut
machdep.c revision 1.65
      1  1.65       rin /*	$NetBSD: machdep.c,v 1.65 2021/03/30 02:04:44 rin Exp $	*/
      2   1.1       scw 
      3   1.1       scw /*
      4   1.1       scw  * Copyright 2001, 2002 Wasabi Systems, Inc.
      5   1.1       scw  * All rights reserved.
      6   1.1       scw  *
      7   1.1       scw  * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
      8   1.1       scw  *
      9   1.1       scw  * Redistribution and use in source and binary forms, with or without
     10   1.1       scw  * modification, are permitted provided that the following conditions
     11   1.1       scw  * are met:
     12   1.1       scw  * 1. Redistributions of source code must retain the above copyright
     13   1.1       scw  *    notice, this list of conditions and the following disclaimer.
     14   1.1       scw  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1       scw  *    notice, this list of conditions and the following disclaimer in the
     16   1.1       scw  *    documentation and/or other materials provided with the distribution.
     17   1.1       scw  * 3. All advertising materials mentioning features or use of this software
     18   1.1       scw  *    must display the following acknowledgement:
     19   1.1       scw  *      This product includes software developed for the NetBSD Project by
     20   1.1       scw  *      Wasabi Systems, Inc.
     21   1.1       scw  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22   1.1       scw  *    or promote products derived from this software without specific prior
     23   1.1       scw  *    written permission.
     24   1.1       scw  *
     25   1.1       scw  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26   1.1       scw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27   1.1       scw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28   1.1       scw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29   1.1       scw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30   1.1       scw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31   1.1       scw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32   1.1       scw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33   1.1       scw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34   1.1       scw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35   1.1       scw  * POSSIBILITY OF SUCH DAMAGE.
     36   1.1       scw  */
     37   1.1       scw 
     38   1.1       scw /*
     39   1.1       scw  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
     40   1.1       scw  * Copyright (C) 1995, 1996 TooLs GmbH.
     41   1.1       scw  * All rights reserved.
     42   1.1       scw  *
     43   1.1       scw  * Redistribution and use in source and binary forms, with or without
     44   1.1       scw  * modification, are permitted provided that the following conditions
     45   1.1       scw  * are met:
     46   1.1       scw  * 1. Redistributions of source code must retain the above copyright
     47   1.1       scw  *    notice, this list of conditions and the following disclaimer.
     48   1.1       scw  * 2. Redistributions in binary form must reproduce the above copyright
     49   1.1       scw  *    notice, this list of conditions and the following disclaimer in the
     50   1.1       scw  *    documentation and/or other materials provided with the distribution.
     51   1.1       scw  * 3. All advertising materials mentioning features or use of this software
     52   1.1       scw  *    must display the following acknowledgement:
     53   1.1       scw  *	This product includes software developed by TooLs GmbH.
     54   1.1       scw  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     55   1.1       scw  *    derived from this software without specific prior written permission.
     56   1.1       scw  *
     57   1.1       scw  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     58   1.1       scw  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     59   1.1       scw  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     60   1.1       scw  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     61   1.1       scw  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     62   1.1       scw  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     63   1.1       scw  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     64   1.1       scw  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     65   1.1       scw  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     66   1.1       scw  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     67   1.1       scw  */
     68  1.14     lukem 
     69  1.14     lukem #include <sys/cdefs.h>
     70  1.65       rin __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.65 2021/03/30 02:04:44 rin Exp $");
     71   1.1       scw 
     72   1.1       scw #include "opt_compat_netbsd.h"
     73   1.1       scw #include "opt_ddb.h"
     74   1.1       scw 
     75   1.1       scw #include <sys/param.h>
     76  1.52      matt #include <sys/boot_flag.h>
     77   1.1       scw #include <sys/buf.h>
     78  1.52      matt #include <sys/bus.h>
     79  1.52      matt #include <sys/cpu.h>
     80  1.52      matt #include <sys/device.h>
     81   1.1       scw #include <sys/exec.h>
     82  1.52      matt #include <sys/kernel.h>
     83  1.52      matt #include <sys/ksyms.h>
     84   1.1       scw #include <sys/malloc.h>
     85   1.1       scw #include <sys/mbuf.h>
     86  1.52      matt #include <sys/module.h>
     87   1.1       scw #include <sys/mount.h>
     88   1.1       scw #include <sys/msgbuf.h>
     89   1.1       scw #include <sys/proc.h>
     90   1.1       scw #include <sys/reboot.h>
     91   1.1       scw #include <sys/syscallargs.h>
     92   1.1       scw #include <sys/syslog.h>
     93   1.1       scw #include <sys/systm.h>
     94   1.1       scw 
     95   1.1       scw #include <uvm/uvm_extern.h>
     96   1.1       scw 
     97  1.27   thorpej #include <prop/proplib.h>
     98  1.27   thorpej 
     99   1.1       scw #include <machine/powerpc.h>
    100   1.1       scw #include <machine/walnut.h>
    101  1.52      matt 
    102  1.52      matt #include <powerpc/trap.h>
    103  1.52      matt #include <powerpc/pcb.h>
    104   1.1       scw 
    105   1.1       scw #include <powerpc/spr.h>
    106  1.45      matt #include <powerpc/ibm4xx/spr.h>
    107  1.51      matt #include <powerpc/ibm4xx/cpu.h>
    108  1.46  kiyohara #include <powerpc/ibm4xx/dcr4xx.h>
    109  1.61       rin #include <powerpc/ibm4xx/ibm405gp.h>
    110   1.1       scw 
    111  1.65       rin #include <powerpc/ibm4xx/openbios.h>
    112  1.65       rin 
    113  1.54      matt #include <powerpc/ibm4xx/pci_machdep.h>
    114  1.54      matt 
    115  1.53      matt #include <powerpc/pic/picvar.h>
    116  1.53      matt 
    117   1.1       scw #include <dev/cons.h>
    118  1.46  kiyohara #include <dev/pci/pcivar.h>
    119  1.46  kiyohara #include <dev/pci/pciconf.h>
    120   1.1       scw 
    121   1.9     ragge #include "ksyms.h"
    122   1.9     ragge 
    123   1.9     ragge #if defined(DDB)
    124  1.52      matt #include <powerpc/db_machdep.h>
    125   1.1       scw #include <ddb/db_extern.h>
    126   1.1       scw #endif
    127   1.1       scw 
    128  1.30  kiyohara 
    129  1.30  kiyohara #define TLB_PG_SIZE 	(16*1024*1024)
    130  1.30  kiyohara 
    131   1.1       scw /*
    132   1.1       scw  * Global variables used here and there
    133   1.1       scw  */
    134   1.1       scw struct vm_map *phys_map = NULL;
    135   1.1       scw 
    136   1.1       scw /*
    137   1.1       scw  * This should probably be in autoconf!				XXX
    138   1.1       scw  */
    139   1.1       scw char machine[] = MACHINE;		/* from <machine/param.h> */
    140   1.1       scw char machine_arch[] = MACHINE_ARCH;	/* from <machine/param.h> */
    141   1.1       scw 
    142  1.53      matt void initppc(vaddr_t, vaddr_t, char *, void *);
    143   1.1       scw 
    144   1.1       scw void
    145  1.53      matt initppc(vaddr_t startkernel, vaddr_t endkernel, char *args, void *info_block)
    146   1.1       scw {
    147  1.65       rin 	u_int memsize;
    148  1.65       rin 
    149   1.1       scw 	/* Disable all external interrupts */
    150  1.46  kiyohara 	mtdcr(DCR_UIC0_BASE + DCR_UIC_ER, 0);
    151   1.1       scw 
    152  1.65       rin 	/* Setup board from OpenBIOS */
    153  1.65       rin 	openbios_board_init(info_block);
    154  1.65       rin 	memsize = openbios_board_memsize_get();
    155   1.1       scw 
    156  1.31     freza 	/* Linear map kernel memory */
    157  1.53      matt 	for (vaddr_t va = 0; va < endkernel; va += TLB_PG_SIZE) {
    158  1.30  kiyohara 		ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX);
    159  1.53      matt 	}
    160  1.30  kiyohara 
    161  1.31     freza 	/* Map console after physmem (see pmap_tlbmiss()) */
    162  1.65       rin 	ppc4xx_tlb_reserve(IBM405GP_UART0_BASE, roundup(memsize, TLB_PG_SIZE),
    163  1.31     freza 	    TLB_PG_SIZE, TLB_I | TLB_G);
    164  1.30  kiyohara 
    165  1.53      matt 	mtspr(SPR_TCR, 0);	/* disable all timers */
    166   1.1       scw 
    167  1.65       rin 	ibm40x_memsize_init(memsize, startkernel);
    168  1.53      matt 	ibm4xx_init(startkernel, endkernel, pic_ext_intr);
    169   1.1       scw 
    170   1.1       scw #ifdef DEBUG
    171  1.65       rin 	openbios_board_print();
    172   1.1       scw #endif
    173   1.1       scw 
    174   1.1       scw #ifdef DDB
    175   1.1       scw 	if (boothowto & RB_KDB)
    176   1.1       scw 		Debugger();
    177   1.1       scw #endif
    178  1.49       mrg 
    179  1.49       mrg 	/*
    180  1.49       mrg 	 * Look for the ibm4xx modules in the right place.
    181  1.49       mrg 	 */
    182  1.49       mrg 	module_machine = module_machine_ibm4xx;
    183   1.1       scw }
    184   1.1       scw 
    185   1.1       scw /*
    186   1.1       scw  * Machine dependent startup code.
    187   1.1       scw  */
    188   1.1       scw 
    189   1.1       scw void
    190   1.1       scw cpu_startup(void)
    191   1.1       scw {
    192   1.1       scw 
    193  1.62       rin 	ibm4xx_cpu_startup("Walnut PowerPC 405GP Evaluation Board");
    194   1.1       scw 
    195  1.65       rin 	openbios_board_info_set();
    196  1.16       scw 
    197  1.16       scw 	/*
    198  1.16       scw 	 * Now that we have VM, malloc()s are OK in bus_space.
    199  1.16       scw 	 */
    200  1.16       scw 	bus_space_mallocok();
    201  1.16       scw 	fake_mapiodev = 0;
    202   1.1       scw }
    203   1.1       scw 
    204  1.46  kiyohara int
    205  1.54      matt ibm4xx_pci_bus_maxdevs(void *v, int busno)
    206  1.46  kiyohara {
    207  1.46  kiyohara 
    208  1.46  kiyohara 	/*
    209  1.46  kiyohara 	 * Bus number is irrelevant.  Configuration Mechanism 1 is in
    210  1.46  kiyohara 	 * use, can have devices 0-32 (i.e. the `normal' range).
    211  1.46  kiyohara 	 */
    212  1.46  kiyohara 	return 5;
    213  1.46  kiyohara }
    214  1.46  kiyohara 
    215  1.46  kiyohara int
    216  1.54      matt ibm4xx_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    217  1.46  kiyohara {
    218  1.46  kiyohara 	int pin = pa->pa_intrpin;
    219  1.46  kiyohara 	int dev = pa->pa_device;
    220  1.46  kiyohara 
    221  1.46  kiyohara 	if (pin == 0)
    222  1.46  kiyohara 		/* No IRQ used. */
    223  1.46  kiyohara 		goto bad;
    224  1.46  kiyohara 
    225  1.46  kiyohara 	if (pin > 4) {
    226  1.54      matt 		printf("%s: bad interrupt pin %d\n", __func__, pin);
    227  1.46  kiyohara 		goto bad;
    228  1.46  kiyohara 	}
    229  1.46  kiyohara 
    230  1.46  kiyohara 	/*
    231  1.46  kiyohara 	 * We need to map the interrupt pin to the interrupt bit in the UIC
    232  1.46  kiyohara 	 * associated with it.  This is highly machine-dependent.
    233  1.46  kiyohara 	 */
    234  1.46  kiyohara 	switch(dev) {
    235  1.46  kiyohara 	case 1:
    236  1.46  kiyohara 	case 2:
    237  1.46  kiyohara 	case 3:
    238  1.46  kiyohara 	case 4:
    239  1.46  kiyohara 		*ihp = 27 + dev;
    240  1.46  kiyohara 		break;
    241  1.46  kiyohara 	default:
    242  1.46  kiyohara 		printf("Hmm.. PCI device %d should not exist on this board\n",
    243  1.46  kiyohara 			dev);
    244  1.46  kiyohara 		goto bad;
    245  1.46  kiyohara 	}
    246  1.46  kiyohara 	return 0;
    247  1.46  kiyohara 
    248  1.46  kiyohara bad:
    249  1.46  kiyohara 	*ihp = -1;
    250  1.46  kiyohara 	return 1;
    251  1.46  kiyohara }
    252  1.46  kiyohara 
    253  1.46  kiyohara void
    254  1.54      matt ibm4xx_pci_conf_interrupt(void *v, int bus, int dev, int pin, int swiz,
    255  1.54      matt     int *iline)
    256  1.46  kiyohara {
    257  1.46  kiyohara 
    258  1.54      matt 	if (bus == 0) {
    259  1.46  kiyohara 		switch(dev) {
    260  1.46  kiyohara 		case 1:
    261  1.46  kiyohara 		case 2:
    262  1.46  kiyohara 		case 3:
    263  1.46  kiyohara 		case 4:
    264  1.46  kiyohara 			*iline = 31 - dev;
    265  1.46  kiyohara 		}
    266  1.54      matt 	} else
    267  1.46  kiyohara 		*iline = 20 + ((swiz + dev + 1) & 3);
    268  1.46  kiyohara }
    269