Home | History | Annotate | Line # | Download | only in walnut
machdep.c revision 1.67
      1  1.67       rin /*	$NetBSD: machdep.c,v 1.67 2021/03/30 05:08:16 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.67       rin __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.67 2021/03/30 05:08:16 rin Exp $");
     71   1.1       scw 
     72   1.1       scw #include "opt_ddb.h"
     73   1.1       scw 
     74   1.1       scw #include <sys/param.h>
     75  1.52      matt #include <sys/bus.h>
     76  1.52      matt #include <sys/device.h>
     77  1.52      matt #include <sys/kernel.h>
     78  1.52      matt #include <sys/module.h>
     79   1.1       scw #include <sys/reboot.h>
     80   1.1       scw #include <sys/systm.h>
     81   1.1       scw 
     82   1.1       scw #include <machine/walnut.h>
     83  1.52      matt 
     84   1.1       scw #include <powerpc/spr.h>
     85  1.45      matt #include <powerpc/ibm4xx/spr.h>
     86  1.67       rin 
     87  1.51      matt #include <powerpc/ibm4xx/cpu.h>
     88  1.46  kiyohara #include <powerpc/ibm4xx/dcr4xx.h>
     89  1.61       rin #include <powerpc/ibm4xx/ibm405gp.h>
     90  1.65       rin #include <powerpc/ibm4xx/openbios.h>
     91  1.67       rin #include <powerpc/ibm4xx/tlb.h>
     92  1.65       rin 
     93  1.54      matt #include <powerpc/ibm4xx/pci_machdep.h>
     94  1.67       rin #include <dev/pci/pciconf.h>
     95  1.46  kiyohara #include <dev/pci/pcivar.h>
     96  1.30  kiyohara 
     97  1.30  kiyohara #define TLB_PG_SIZE 	(16*1024*1024)
     98  1.30  kiyohara 
     99  1.53      matt void initppc(vaddr_t, vaddr_t, char *, void *);
    100   1.1       scw 
    101   1.1       scw void
    102  1.53      matt initppc(vaddr_t startkernel, vaddr_t endkernel, char *args, void *info_block)
    103   1.1       scw {
    104  1.65       rin 	u_int memsize;
    105  1.65       rin 
    106   1.1       scw 	/* Disable all external interrupts */
    107  1.46  kiyohara 	mtdcr(DCR_UIC0_BASE + DCR_UIC_ER, 0);
    108   1.1       scw 
    109  1.65       rin 	/* Setup board from OpenBIOS */
    110  1.65       rin 	openbios_board_init(info_block);
    111  1.65       rin 	memsize = openbios_board_memsize_get();
    112   1.1       scw 
    113  1.31     freza 	/* Linear map kernel memory */
    114  1.53      matt 	for (vaddr_t va = 0; va < endkernel; va += TLB_PG_SIZE) {
    115  1.30  kiyohara 		ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX);
    116  1.53      matt 	}
    117  1.30  kiyohara 
    118  1.31     freza 	/* Map console after physmem (see pmap_tlbmiss()) */
    119  1.65       rin 	ppc4xx_tlb_reserve(IBM405GP_UART0_BASE, roundup(memsize, TLB_PG_SIZE),
    120  1.31     freza 	    TLB_PG_SIZE, TLB_I | TLB_G);
    121  1.30  kiyohara 
    122  1.53      matt 	mtspr(SPR_TCR, 0);	/* disable all timers */
    123   1.1       scw 
    124  1.65       rin 	ibm40x_memsize_init(memsize, startkernel);
    125  1.53      matt 	ibm4xx_init(startkernel, endkernel, pic_ext_intr);
    126   1.1       scw 
    127   1.1       scw #ifdef DEBUG
    128  1.65       rin 	openbios_board_print();
    129   1.1       scw #endif
    130   1.1       scw 
    131   1.1       scw #ifdef DDB
    132   1.1       scw 	if (boothowto & RB_KDB)
    133   1.1       scw 		Debugger();
    134   1.1       scw #endif
    135  1.49       mrg 
    136  1.49       mrg 	/*
    137  1.49       mrg 	 * Look for the ibm4xx modules in the right place.
    138  1.49       mrg 	 */
    139  1.49       mrg 	module_machine = module_machine_ibm4xx;
    140   1.1       scw }
    141   1.1       scw 
    142   1.1       scw /*
    143   1.1       scw  * Machine dependent startup code.
    144   1.1       scw  */
    145   1.1       scw 
    146   1.1       scw void
    147   1.1       scw cpu_startup(void)
    148   1.1       scw {
    149   1.1       scw 
    150  1.62       rin 	ibm4xx_cpu_startup("Walnut PowerPC 405GP Evaluation Board");
    151   1.1       scw 
    152  1.65       rin 	openbios_board_info_set();
    153  1.16       scw 
    154  1.16       scw 	/*
    155  1.16       scw 	 * Now that we have VM, malloc()s are OK in bus_space.
    156  1.16       scw 	 */
    157  1.16       scw 	bus_space_mallocok();
    158  1.16       scw 	fake_mapiodev = 0;
    159   1.1       scw }
    160   1.1       scw 
    161  1.46  kiyohara int
    162  1.54      matt ibm4xx_pci_bus_maxdevs(void *v, int busno)
    163  1.46  kiyohara {
    164  1.46  kiyohara 
    165  1.46  kiyohara 	/*
    166  1.46  kiyohara 	 * Bus number is irrelevant.  Configuration Mechanism 1 is in
    167  1.46  kiyohara 	 * use, can have devices 0-32 (i.e. the `normal' range).
    168  1.46  kiyohara 	 */
    169  1.46  kiyohara 	return 5;
    170  1.46  kiyohara }
    171  1.46  kiyohara 
    172  1.46  kiyohara int
    173  1.54      matt ibm4xx_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    174  1.46  kiyohara {
    175  1.46  kiyohara 	int pin = pa->pa_intrpin;
    176  1.46  kiyohara 	int dev = pa->pa_device;
    177  1.46  kiyohara 
    178  1.46  kiyohara 	if (pin == 0)
    179  1.46  kiyohara 		/* No IRQ used. */
    180  1.46  kiyohara 		goto bad;
    181  1.46  kiyohara 
    182  1.46  kiyohara 	if (pin > 4) {
    183  1.54      matt 		printf("%s: bad interrupt pin %d\n", __func__, pin);
    184  1.46  kiyohara 		goto bad;
    185  1.46  kiyohara 	}
    186  1.46  kiyohara 
    187  1.46  kiyohara 	/*
    188  1.46  kiyohara 	 * We need to map the interrupt pin to the interrupt bit in the UIC
    189  1.46  kiyohara 	 * associated with it.  This is highly machine-dependent.
    190  1.46  kiyohara 	 */
    191  1.46  kiyohara 	switch(dev) {
    192  1.46  kiyohara 	case 1:
    193  1.46  kiyohara 	case 2:
    194  1.46  kiyohara 	case 3:
    195  1.46  kiyohara 	case 4:
    196  1.46  kiyohara 		*ihp = 27 + dev;
    197  1.46  kiyohara 		break;
    198  1.46  kiyohara 	default:
    199  1.46  kiyohara 		printf("Hmm.. PCI device %d should not exist on this board\n",
    200  1.46  kiyohara 			dev);
    201  1.46  kiyohara 		goto bad;
    202  1.46  kiyohara 	}
    203  1.46  kiyohara 	return 0;
    204  1.46  kiyohara 
    205  1.46  kiyohara bad:
    206  1.46  kiyohara 	*ihp = -1;
    207  1.46  kiyohara 	return 1;
    208  1.46  kiyohara }
    209  1.46  kiyohara 
    210  1.46  kiyohara void
    211  1.54      matt ibm4xx_pci_conf_interrupt(void *v, int bus, int dev, int pin, int swiz,
    212  1.54      matt     int *iline)
    213  1.46  kiyohara {
    214  1.46  kiyohara 
    215  1.54      matt 	if (bus == 0) {
    216  1.46  kiyohara 		switch(dev) {
    217  1.46  kiyohara 		case 1:
    218  1.46  kiyohara 		case 2:
    219  1.46  kiyohara 		case 3:
    220  1.46  kiyohara 		case 4:
    221  1.46  kiyohara 			*iline = 31 - dev;
    222  1.46  kiyohara 		}
    223  1.54      matt 	} else
    224  1.46  kiyohara 		*iline = 20 + ((swiz + dev + 1) & 3);
    225  1.46  kiyohara }
    226