Home | History | Annotate | Line # | Download | only in ibm4xx
ibm40x_machdep.c revision 1.3
      1 /*	$NetBSD: ibm40x_machdep.c,v 1.3 2005/01/17 17:19:36 shige 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: ibm40x_machdep.c,v 1.3 2005/01/17 17:19:36 shige Exp $");
     71 
     72 #include "opt_compat_netbsd.h"
     73 #include "opt_ddb.h"
     74 #include "opt_kgdb.h"
     75 #include "opt_ipkdb.h"
     76 
     77 #include <sys/param.h>
     78 #include <sys/buf.h>
     79 #include <sys/exec.h>
     80 #include <sys/malloc.h>
     81 #include <sys/mbuf.h>
     82 #include <sys/mount.h>
     83 #include <sys/msgbuf.h>
     84 #include <sys/proc.h>
     85 #include <sys/reboot.h>
     86 #include <sys/sa.h>
     87 #include <sys/syscallargs.h>
     88 #include <sys/syslog.h>
     89 #include <sys/systm.h>
     90 #include <sys/kernel.h>
     91 #include <sys/user.h>
     92 #include <sys/boot_flag.h>
     93 #include <sys/properties.h>
     94 #include <sys/ksyms.h>
     95 
     96 #include <uvm/uvm_extern.h>
     97 
     98 #include <net/netisr.h>
     99 
    100 #if defined(DDB)
    101 #include <machine/db_machdep.h>
    102 #include <ddb/db_extern.h>
    103 #endif
    104 
    105 #if defined(KGDB)
    106 #include <sys/kgdb.h>
    107 #endif
    108 
    109 #if defined(IPKDB)
    110 #include <ipkdb/ipkdb.h>
    111 #endif
    112 
    113 #include <machine/bus.h>
    114 #include <machine/trap.h>
    115 #include <machine/powerpc.h>
    116 #include <powerpc/spr.h>
    117 #include <powerpc/ibm4xx/dcr405gp.h>
    118 
    119 /*
    120  * Global variables used here and there
    121  */
    122 struct vm_map *exec_map = NULL;
    123 struct vm_map *mb_map = NULL;
    124 struct vm_map *phys_map = NULL;
    125 
    126 char machine[] = MACHINE;		/* from <machine/param.h> */
    127 char machine_arch[] = MACHINE_ARCH;	/* from <machine/param.h> */
    128 
    129 #define MEMREGIONS	8
    130 struct mem_region physmemr[MEMREGIONS];	/* Hard code memory */
    131 struct mem_region availmemr[MEMREGIONS];/* Who's supposed to set these up? */
    132 
    133 extern struct user *proc0paddr;
    134 
    135 paddr_t msgbuf_paddr;
    136 vaddr_t msgbuf_vaddr;
    137 
    138 
    139 void
    140 ibm40x_memsize_init(u_int memsize, u_int startkernel)
    141 {
    142 
    143         /* Initialize cache info for memcpy, etc. */
    144         cpu_probe_cache();
    145 
    146 	memset(physmemr, 0, sizeof physmemr);
    147 	memset(availmemr, 0, sizeof availmemr);
    148 	physmemr[0].start = 0;
    149 	physmemr[0].size = memsize & ~PGOFSET;
    150 	/* Lower memory reserved by eval board BIOS */
    151 	availmemr[0].start = startkernel;
    152 	availmemr[0].size = memsize - availmemr[0].start;
    153 }
    154 
    155 void
    156 ibm4xx_init(void (*handler)(void))
    157 {
    158 	extern int defaulttrap, defaultsize;
    159 	extern int sctrap, scsize;
    160 	extern int alitrap, alisize;
    161 	extern int dsitrap, dsisize;
    162 	extern int isitrap, isisize;
    163 	extern int mchktrap, mchksize;
    164 	extern int tlbimiss4xx, tlbim4size;
    165 	extern int tlbdmiss4xx, tlbdm4size;
    166 	extern int pitfitwdog, pitfitwdogsize;
    167 	extern int debugtrap, debugsize;
    168 	extern int errata51handler, errata51size;
    169 #ifdef DDB
    170 	extern int ddblow, ddbsize;
    171 #endif
    172 #ifdef IPKDB
    173 	extern int ipkdblow, ipkdbsize;
    174 #endif
    175 	uintptr_t exc;
    176 	struct cpu_info * const ci = curcpu();
    177 
    178         /* Initialize cache info for memcpy, etc. */
    179 	cpu_probe_cache();
    180 
    181 	/*
    182 	 * Initialize lwp0 and current pcb and pmap pointers.
    183 	 */
    184         KASSERT(ci != NULL);
    185         KASSERT(curcpu() == ci);
    186 	lwp0.l_cpu = ci;
    187 	lwp0.l_addr = proc0paddr;
    188 	memset(lwp0.l_addr, 0, sizeof *lwp0.l_addr);
    189         KASSERT(lwp0.l_cpu != NULL);
    190 
    191 	curpcb = &proc0paddr->u_pcb;
    192         memset(curpcb, 0, sizeof(*curpcb));
    193 	curpcb->pcb_pm = pmap_kernel();
    194 
    195 	/*
    196 	 * Set up trap vectors
    197 	 */
    198 	for (exc = EXC_RSVD; exc <= EXC_LAST; exc += 0x100)
    199 		switch (exc) {
    200 		default:
    201 			memcpy((void *)exc, &defaulttrap, (size_t)&defaultsize);
    202 			break;
    203 		case EXC_EXI:
    204 			/*
    205 			 * This one is (potentially) installed during autoconf
    206 			 */
    207 			break;
    208 		case EXC_SC:
    209 			memcpy((void *)EXC_SC, &sctrap, (size_t)&scsize);
    210 			break;
    211 		case EXC_ALI:
    212 			memcpy((void *)EXC_ALI, &alitrap, (size_t)&alisize);
    213 			break;
    214 		case EXC_DSI:
    215 			memcpy((void *)EXC_DSI, &dsitrap, (size_t)&dsisize);
    216 			break;
    217 		case EXC_ISI:
    218 			memcpy((void *)EXC_ISI, &isitrap, (size_t)&isisize);
    219 			break;
    220 		case EXC_MCHK:
    221 			memcpy((void *)EXC_MCHK, &mchktrap, (size_t)&mchksize);
    222 			break;
    223 		case EXC_ITMISS:
    224 			memcpy((void *)EXC_ITMISS, &tlbimiss4xx,
    225 				(size_t)&tlbim4size);
    226 			break;
    227 		case EXC_DTMISS:
    228 			memcpy((void *)EXC_DTMISS, &tlbdmiss4xx,
    229 				(size_t)&tlbdm4size);
    230 			break;
    231 		/*
    232 		 * EXC_PIT, EXC_FIT, EXC_WDOG handlers
    233 		 * are spaced by 0x10 bytes only..
    234 		 */
    235 		case EXC_PIT:
    236 			memcpy((void *)EXC_PIT, &pitfitwdog,
    237 				(size_t)&pitfitwdogsize);
    238 			break;
    239 		case EXC_DEBUG:
    240 			memcpy((void *)EXC_DEBUG, &debugtrap,
    241 				(size_t)&debugsize);
    242 			break;
    243 		case EXC_DTMISS|EXC_ALI:
    244                         /* PPC405GP Rev D errata item 51 */
    245 			memcpy((void *)(EXC_DTMISS|EXC_ALI), &errata51handler,
    246 				(size_t)&errata51size);
    247 			break;
    248 #if defined(DDB) || defined(IPKDB)
    249 		case EXC_PGM:
    250 #if defined(DDB)
    251 			memcpy((void *)exc, &ddblow, (size_t)&ddbsize);
    252 #elif defined(IPKDB)
    253 			memcpy((void *)exc, &ipkdblow, (size_t)&ipkdbsize);
    254 #endif
    255 #endif /* DDB | IPKDB */
    256 			break;
    257 		}
    258 
    259 	__syncicache((void *)EXC_RST, EXC_LAST - EXC_RST + 0x100);
    260 	mtspr(SPR_EVPR, 0);		/* Set Exception vector base */
    261 
    262 	consinit();
    263 
    264 	/* Handle trap instruction as PGM exception */
    265 	{
    266 	  int dbcr0;
    267 	  asm volatile("mfspr %0,%1":"=r"(dbcr0):"K"(SPR_DBCR0));
    268 	  asm volatile("mtspr %0,%1"::"K"(SPR_DBCR0),"r"(dbcr0 & ~DBCR0_TDE));
    269 	}
    270 
    271 	/*
    272 	 * external interrupt handler install
    273 	 */
    274         if (handler)
    275 	    ibm4xx_install_extint(handler);
    276 
    277 	/*
    278 	 * Now enable translation (and machine checks/recoverable interrupts).
    279 	 */
    280 	asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
    281 		      : : "r"(0), "K"(PSL_IR|PSL_DR));
    282 	/* XXXX PSL_ME - With ME set kernel gets stuck... */
    283 
    284 	KASSERT(curcpu() == ci);
    285 }
    286 
    287 void
    288 ibm4xx_install_extint(void (*handler)(void))
    289 {
    290 	extern int extint, extsize;
    291 	extern u_long extint_call;
    292 	u_long offset = (u_long)handler - (u_long)&extint_call;
    293 	int msr;
    294 
    295 #ifdef	DIAGNOSTIC
    296 	if (offset > 0x1ffffff)
    297 		panic("install_extint: too far away");
    298 #endif
    299 	asm volatile ("mfmsr %0; wrteei 0" : "=r"(msr));
    300 	extint_call = (extint_call & 0xfc000003) | offset;
    301 	memcpy((void *)EXC_EXI, &extint, (size_t)&extsize);
    302 	__syncicache((void *)&extint_call, sizeof extint_call);
    303 	__syncicache((void *)EXC_EXI, (int)&extsize);
    304 	asm volatile ("mtmsr %0" :: "r"(msr));
    305 }
    306 
    307 /*
    308  * Machine dependent startup code.
    309  */
    310 
    311 char msgbuf[MSGBUFSIZE];
    312 
    313 void
    314 ibm4xx_startup(const char *model)
    315 {
    316 	vaddr_t minaddr, maxaddr;
    317 	char pbuf[9];
    318 
    319 	KASSERT(curcpu() != NULL);
    320 	KASSERT(lwp0.l_cpu != NULL);
    321 	KASSERT(curcpu()->ci_intstk != 0);
    322 	KASSERT(curcpu()->ci_intrdepth == -1);
    323 
    324 	/*
    325 	 * Initialize error message buffer (at end of core).
    326 	 */
    327 #if 0	/* For some reason this fails... --Artem
    328 	 * Besides, do we really have to put it at the end of core?
    329 	 * Let's use static buffer for now
    330 	 */
    331 	if (!(msgbuf_vaddr = uvm_km_alloc(kernel_map, round_page(MSGBUFSIZE))))
    332 		panic("startup: no room for message buffer");
    333 	for (i = 0; i < btoc(MSGBUFSIZE); i++)
    334 		pmap_kenter_pa(msgbuf_vaddr + i * PAGE_SIZE,
    335 		    msgbuf_paddr + i * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE);
    336 	initmsgbuf((caddr_t)msgbuf_vaddr, round_page(MSGBUFSIZE));
    337 #else
    338 	initmsgbuf((caddr_t)msgbuf, round_page(MSGBUFSIZE));
    339 #endif
    340 
    341 	printf("%s", version);
    342 	if (model != NULL)
    343 		printf("Model: %s\n", model);
    344 
    345 	format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
    346 	printf("total memory = %s\n", pbuf);
    347 
    348 	minaddr = 0;
    349 	/*
    350 	 * Allocate a submap for exec arguments.  This map effectively
    351 	 * limits the number of processes exec'ing at any time.
    352 	 */
    353 	exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    354 				 16*NCARGS, VM_MAP_PAGEABLE, FALSE, NULL);
    355 
    356 	/*
    357 	 * Allocate a submap for physio
    358 	 */
    359 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    360 				 VM_PHYS_SIZE, 0, FALSE, NULL);
    361 
    362 	/*
    363 	 * No need to allocate an mbuf cluster submap.  Mbuf clusters
    364 	 * are allocated via the pool allocator, and we use direct-mapped
    365 	 * pool pages.
    366 	 */
    367 
    368 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
    369 	printf("avail memory = %s\n", pbuf);
    370 }
    371 
    372 /*
    373  * Crash dump handling.
    374  */
    375 void
    376 ibm4xx_dumpsys(void)
    377 {
    378 	printf("dumpsys: TBD\n");
    379 }
    380 
    381 /*
    382  * Soft networking interrupts.
    383  */
    384 void
    385 softnet(void)
    386 {
    387 	int isr;
    388 
    389 	isr = netisr;
    390 	netisr = 0;
    391 
    392 #define DONETISR(bit, fn) do {		\
    393 	if (isr & (1 << bit))		\
    394 		fn();			\
    395 } while (0)
    396 
    397 #include <net/netisr_dispatch.h>
    398 
    399 #undef DONETISR
    400 
    401 }
    402 
    403 /*
    404  * Soft tty interrupts.
    405  */
    406 #include "com.h"
    407 void
    408 softserial(void)
    409 {
    410 #if NCOM > 0
    411 	void comsoft(void);	/* XXX from dev/ic/com.c */
    412 
    413 	comsoft();
    414 #endif
    415 }
    416 
    417 void
    418 mem_regions(struct mem_region **mem, struct mem_region **avail)
    419 {
    420 	*mem = physmemr;
    421 	*avail = availmemr;
    422 }
    423