ibm4xx_machdep.c revision 1.2 1 /* $NetBSD: ibm4xx_machdep.c,v 1.2 2005/04/01 11:59:34 yamt Exp $ */
2 /* Original: ibm40x_machdep.c,v 1.3 2005/01/17 17:19:36 shige Exp $ */
3
4 /*
5 * Copyright 2001, 2002 Wasabi Systems, Inc.
6 * All rights reserved.
7 *
8 * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed for the NetBSD Project by
21 * Wasabi Systems, Inc.
22 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
23 * or promote products derived from this software without specific prior
24 * written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
41 * Copyright (C) 1995, 1996 TooLs GmbH.
42 * All rights reserved.
43 *
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 * 3. All advertising materials mentioning features or use of this software
53 * must display the following acknowledgement:
54 * This product includes software developed by TooLs GmbH.
55 * 4. The name of TooLs GmbH may not be used to endorse or promote products
56 * derived from this software without specific prior written permission.
57 *
58 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
59 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
62 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
63 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
64 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
65 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
66 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
67 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 */
69
70 #include <sys/cdefs.h>
71 __KERNEL_RCSID(0, "$NetBSD: ibm4xx_machdep.c,v 1.2 2005/04/01 11:59:34 yamt Exp $");
72
73 #include "opt_compat_netbsd.h"
74 #include "opt_ddb.h"
75 #include "opt_kgdb.h"
76 #include "opt_ipkdb.h"
77
78 #include <sys/param.h>
79 #include <sys/msgbuf.h>
80 #include <sys/proc.h>
81 #include <sys/user.h>
82
83 #include <uvm/uvm_extern.h>
84
85 #if defined(DDB)
86 #include <machine/db_machdep.h>
87 #include <ddb/db_extern.h>
88 #endif
89
90 #if defined(KGDB)
91 #include <sys/kgdb.h>
92 #endif
93
94 #if defined(IPKDB)
95 #include <ipkdb/ipkdb.h>
96 #endif
97
98 #include <machine/powerpc.h>
99 #include <powerpc/spr.h>
100 #include <machine/trap.h>
101
102 /*
103 * Global variables used here and there
104 */
105 extern struct user *proc0paddr;
106 paddr_t msgbuf_paddr;
107 vaddr_t msgbuf_vaddr;
108 char msgbuf[MSGBUFSIZE];
109
110 /*
111 * ibm4xx_init:
112 */
113 void
114 ibm4xx_init(void (*handler)(void))
115 {
116 extern int defaulttrap, defaultsize;
117 extern int sctrap, scsize;
118 extern int alitrap, alisize;
119 extern int dsitrap, dsisize;
120 extern int isitrap, isisize;
121 extern int mchktrap, mchksize;
122 extern int tlbimiss4xx, tlbim4size;
123 extern int tlbdmiss4xx, tlbdm4size;
124 extern int pitfitwdog, pitfitwdogsize;
125 extern int debugtrap, debugsize;
126 extern int errata51handler, errata51size;
127 #ifdef DDB
128 extern int ddblow, ddbsize;
129 #endif
130 #ifdef IPKDB
131 extern int ipkdblow, ipkdbsize;
132 #endif
133 uintptr_t exc;
134 struct cpu_info * const ci = curcpu();
135
136 /* Initialize cache info for memcpy, etc. */
137 cpu_probe_cache();
138
139 /*
140 * Initialize lwp0 and current pcb and pmap pointers.
141 */
142 KASSERT(ci != NULL);
143 KASSERT(curcpu() == ci);
144 lwp0.l_cpu = ci;
145 lwp0.l_addr = proc0paddr;
146 memset(lwp0.l_addr, 0, sizeof *lwp0.l_addr);
147 KASSERT(lwp0.l_cpu != NULL);
148
149 curpcb = &proc0paddr->u_pcb;
150 memset(curpcb, 0, sizeof(*curpcb));
151 curpcb->pcb_pm = pmap_kernel();
152
153 /*
154 * Set up trap vectors
155 */
156 for (exc = EXC_RSVD; exc <= EXC_LAST; exc += 0x100)
157 switch (exc) {
158 default:
159 memcpy((void *)exc, &defaulttrap, (size_t)&defaultsize);
160 break;
161 case EXC_EXI:
162 /*
163 * This one is (potentially) installed during autoconf
164 */
165 break;
166 case EXC_SC:
167 memcpy((void *)EXC_SC, &sctrap, (size_t)&scsize);
168 break;
169 case EXC_ALI:
170 memcpy((void *)EXC_ALI, &alitrap, (size_t)&alisize);
171 break;
172 case EXC_DSI:
173 memcpy((void *)EXC_DSI, &dsitrap, (size_t)&dsisize);
174 break;
175 case EXC_ISI:
176 memcpy((void *)EXC_ISI, &isitrap, (size_t)&isisize);
177 break;
178 case EXC_MCHK:
179 memcpy((void *)EXC_MCHK, &mchktrap, (size_t)&mchksize);
180 break;
181 case EXC_ITMISS:
182 memcpy((void *)EXC_ITMISS, &tlbimiss4xx,
183 (size_t)&tlbim4size);
184 break;
185 case EXC_DTMISS:
186 memcpy((void *)EXC_DTMISS, &tlbdmiss4xx,
187 (size_t)&tlbdm4size);
188 break;
189 /*
190 * EXC_PIT, EXC_FIT, EXC_WDOG handlers
191 * are spaced by 0x10 bytes only..
192 */
193 case EXC_PIT:
194 memcpy((void *)EXC_PIT, &pitfitwdog,
195 (size_t)&pitfitwdogsize);
196 break;
197 case EXC_DEBUG:
198 memcpy((void *)EXC_DEBUG, &debugtrap,
199 (size_t)&debugsize);
200 break;
201 case EXC_DTMISS|EXC_ALI:
202 /* PPC405GP Rev D errata item 51 */
203 memcpy((void *)(EXC_DTMISS|EXC_ALI), &errata51handler,
204 (size_t)&errata51size);
205 break;
206 #if defined(DDB) || defined(IPKDB)
207 case EXC_PGM:
208 #if defined(DDB)
209 memcpy((void *)exc, &ddblow, (size_t)&ddbsize);
210 #elif defined(IPKDB)
211 memcpy((void *)exc, &ipkdblow, (size_t)&ipkdbsize);
212 #endif
213 #endif /* DDB | IPKDB */
214 break;
215 }
216
217 __syncicache((void *)EXC_RST, EXC_LAST - EXC_RST + 0x100);
218 mtspr(SPR_EVPR, 0); /* Set Exception vector base */
219
220 consinit();
221
222 /* Handle trap instruction as PGM exception */
223 {
224 int dbcr0;
225 asm volatile("mfspr %0,%1":"=r"(dbcr0):"K"(SPR_DBCR0));
226 asm volatile("mtspr %0,%1"::"K"(SPR_DBCR0),"r"(dbcr0 & ~DBCR0_TDE));
227 }
228
229 /*
230 * external interrupt handler install
231 */
232 if (handler)
233 ibm4xx_install_extint(handler);
234
235 /*
236 * Now enable translation (and machine checks/recoverable interrupts).
237 */
238 asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
239 : : "r"(0), "K"(PSL_IR|PSL_DR));
240 /* XXXX PSL_ME - With ME set kernel gets stuck... */
241
242 KASSERT(curcpu() == ci);
243 }
244
245 void
246 ibm4xx_install_extint(void (*handler)(void))
247 {
248 extern int extint, extsize;
249 extern u_long extint_call;
250 u_long offset = (u_long)handler - (u_long)&extint_call;
251 int msr;
252
253 #ifdef DIAGNOSTIC
254 if (offset > 0x1ffffff)
255 panic("install_extint: too far away");
256 #endif
257 asm volatile ("mfmsr %0; wrteei 0" : "=r"(msr));
258 extint_call = (extint_call & 0xfc000003) | offset;
259 memcpy((void *)EXC_EXI, &extint, (size_t)&extsize);
260 __syncicache((void *)&extint_call, sizeof extint_call);
261 __syncicache((void *)EXC_EXI, (int)&extsize);
262 asm volatile ("mtmsr %0" :: "r"(msr));
263 }
264
265 /*
266 * ibm4xx_cpu_startup:
267 * Machine dependent startup code.
268 */
269 void
270 ibm4xx_cpu_startup(const char *model)
271 {
272 vaddr_t minaddr, maxaddr;
273 char pbuf[9];
274
275 KASSERT(curcpu() != NULL);
276 KASSERT(lwp0.l_cpu != NULL);
277 KASSERT(curcpu()->ci_intstk != 0);
278 KASSERT(curcpu()->ci_intrdepth == -1);
279
280 /*
281 * Initialize error message buffer (at end of core).
282 */
283 #if 0 /* For some reason this fails... --Artem
284 * Besides, do we really have to put it at the end of core?
285 * Let's use static buffer for now
286 */
287 if (!(msgbuf_vaddr = uvm_km_alloc(kernel_map, round_page(MSGBUFSIZE),
288 0, UVM_KMF_VAONLY)))
289 panic("startup: no room for message buffer");
290 for (i = 0; i < btoc(MSGBUFSIZE); i++)
291 pmap_kenter_pa(msgbuf_vaddr + i * PAGE_SIZE,
292 msgbuf_paddr + i * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE);
293 initmsgbuf((caddr_t)msgbuf_vaddr, round_page(MSGBUFSIZE));
294 #else
295 initmsgbuf((caddr_t)msgbuf, round_page(MSGBUFSIZE));
296 #endif
297
298 printf("%s", version);
299 if (model != NULL)
300 printf("Model: %s\n", model);
301
302 format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
303 printf("total memory = %s\n", pbuf);
304
305 minaddr = 0;
306 /*
307 * Allocate a submap for exec arguments. This map effectively
308 * limits the number of processes exec'ing at any time.
309 */
310 exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
311 16*NCARGS, VM_MAP_PAGEABLE, FALSE, NULL);
312
313 /*
314 * Allocate a submap for physio
315 */
316 phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
317 VM_PHYS_SIZE, 0, FALSE, NULL);
318
319 /*
320 * No need to allocate an mbuf cluster submap. Mbuf clusters
321 * are allocated via the pool allocator, and we use direct-mapped
322 * pool pages.
323 */
324
325 format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
326 printf("avail memory = %s\n", pbuf);
327 }
328
329 /*
330 * ibm4xx_dumpsys:
331 * Crash dump handling.
332 */
333 void
334 ibm4xx_dumpsys(void)
335 {
336
337 printf("dumpsys: TBD\n");
338 }
339