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