machdep.c revision 1.4 1 1.4 matt /* $NetBSD: machdep.c,v 1.4 2003/01/30 07:46:28 matt 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.1 scw
69 1.1 scw #include "opt_compat_netbsd.h"
70 1.1 scw #include "opt_ddb.h"
71 1.1 scw #include "opt_ipkdb.h"
72 1.1 scw
73 1.1 scw #include <sys/param.h>
74 1.1 scw #include <sys/buf.h>
75 1.1 scw #include <sys/exec.h>
76 1.1 scw #include <sys/malloc.h>
77 1.1 scw #include <sys/mbuf.h>
78 1.1 scw #include <sys/mount.h>
79 1.1 scw #include <sys/msgbuf.h>
80 1.1 scw #include <sys/proc.h>
81 1.1 scw #include <sys/reboot.h>
82 1.3 thorpej #include <sys/sa.h>
83 1.1 scw #include <sys/syscallargs.h>
84 1.1 scw #include <sys/syslog.h>
85 1.1 scw #include <sys/systm.h>
86 1.1 scw #include <sys/kernel.h>
87 1.1 scw #include <sys/user.h>
88 1.1 scw #include <sys/boot_flag.h>
89 1.1 scw #include <sys/properties.h>
90 1.1 scw
91 1.1 scw #include <uvm/uvm_extern.h>
92 1.1 scw
93 1.1 scw #include <net/netisr.h>
94 1.1 scw
95 1.1 scw #include <machine/bus.h>
96 1.1 scw #include <machine/powerpc.h>
97 1.1 scw #include <machine/trap.h>
98 1.1 scw #include <machine/walnut.h>
99 1.1 scw #include <machine/dcr.h>
100 1.1 scw
101 1.1 scw #include <powerpc/spr.h>
102 1.1 scw #include <machine/bus.h>
103 1.1 scw
104 1.1 scw #include <dev/cons.h>
105 1.1 scw
106 1.1 scw #ifdef DDB
107 1.1 scw #include <machine/db_machdep.h>
108 1.1 scw #include <ddb/db_extern.h>
109 1.1 scw #endif
110 1.1 scw
111 1.1 scw #include "com.h"
112 1.1 scw #if NCOM > 0
113 1.1 scw #include <dev/ic/comreg.h> /* For COM_FREQ */
114 1.1 scw #endif
115 1.1 scw
116 1.1 scw /*
117 1.1 scw * Global variables used here and there
118 1.1 scw */
119 1.1 scw struct vm_map *exec_map = NULL;
120 1.1 scw struct vm_map *mb_map = NULL;
121 1.1 scw struct vm_map *phys_map = NULL;
122 1.1 scw
123 1.1 scw /*
124 1.1 scw * This should probably be in autoconf! XXX
125 1.1 scw */
126 1.1 scw char cpu_model[80];
127 1.1 scw char machine[] = MACHINE; /* from <machine/param.h> */
128 1.1 scw char machine_arch[] = MACHINE_ARCH; /* from <machine/param.h> */
129 1.1 scw
130 1.1 scw struct pcb *curpcb;
131 1.1 scw struct pmap *curpm;
132 1.1 scw struct proc *fpuproc; /* XXX - shouldn't need this on fpu-less CPUs */
133 1.1 scw
134 1.1 scw extern struct user *proc0paddr;
135 1.1 scw
136 1.1 scw char bootpath[256];
137 1.1 scw paddr_t msgbuf_paddr;
138 1.1 scw vaddr_t msgbuf_vaddr;
139 1.1 scw
140 1.1 scw #ifdef DDB
141 1.1 scw void *startsym, *endsym;
142 1.1 scw #endif
143 1.1 scw
144 1.1 scw int lcsplx(int);
145 1.1 scw void initppc(u_int, u_int, char *, void *);
146 1.1 scw
147 1.1 scw static void dumpsys(void);
148 1.1 scw static void install_extint(void (*)(void));
149 1.1 scw
150 1.1 scw #define MEMREGIONS 8
151 1.1 scw struct mem_region physmemr[MEMREGIONS]; /* Hard code memory */
152 1.1 scw struct mem_region availmemr[MEMREGIONS]; /* Who's supposed to set these up? */
153 1.1 scw
154 1.1 scw struct board_cfg_data board_data;
155 1.1 scw struct propdb *board_info = NULL;
156 1.1 scw
157 1.1 scw void
158 1.1 scw initppc(u_int startkernel, u_int endkernel, char *args, void *info_block)
159 1.1 scw {
160 1.1 scw extern int defaulttrap, defaultsize;
161 1.1 scw extern int sctrap, scsize;
162 1.1 scw extern int alitrap, alisize;
163 1.1 scw extern int dsitrap, dsisize;
164 1.1 scw extern int isitrap, isisize;
165 1.1 scw extern int mchktrap, mchksize;
166 1.1 scw extern int tlbimiss4xx, tlbim4size;
167 1.1 scw extern int tlbdmiss4xx, tlbdm4size;
168 1.1 scw extern int pitfitwdog, pitfitwdogsize;
169 1.1 scw extern int debugtrap, debugsize;
170 1.1 scw extern int errata51handler, errata51size;
171 1.1 scw #ifdef DDB
172 1.1 scw extern int ddblow, ddbsize;
173 1.1 scw #endif
174 1.1 scw #ifdef IPKDB
175 1.1 scw extern int ipkdblow, ipkdbsize;
176 1.1 scw #endif
177 1.1 scw int exc;
178 1.1 scw extern char _edata, _end;
179 1.3 thorpej struct cpu_info * const ci = &cpu_info_store;
180 1.4 matt
181 1.4 matt /* Set the curcpu() pointer */
182 1.4 matt mtspr(SPR_SPRG0, ci);
183 1.1 scw
184 1.1 scw /* Disable all external interrupts */
185 1.1 scw mtdcr(DCR_UIC0_ER, 0);
186 1.1 scw
187 1.1 scw /* Initialize cache info for memcpy, etc. */
188 1.1 scw cpu_probe_cache();
189 1.1 scw
190 1.1 scw memset(&_edata, 0, &_end-&_edata); /* Clear BSS area */
191 1.1 scw
192 1.1 scw /* Save info block */
193 1.1 scw if (info_block == NULL)
194 1.1 scw /* XXX why isn't r3 set correctly?!?!? */
195 1.1 scw info_block = (void *)0x8e10;
196 1.1 scw memcpy(&board_data, info_block, sizeof(board_data));
197 1.1 scw
198 1.1 scw memset(physmemr, 0, sizeof physmemr);
199 1.1 scw memset(availmemr, 0, sizeof availmemr);
200 1.1 scw physmemr[0].start = 0;
201 1.1 scw physmemr[0].size = board_data.mem_size & ~PGOFSET;
202 1.1 scw /* Lower memory reserved by eval board BIOS */
203 1.1 scw availmemr[0].start = startkernel;
204 1.1 scw availmemr[0].size = board_data.mem_size - availmemr[0].start;
205 1.1 scw
206 1.3 thorpej /*
207 1.3 thorpej * Initialize lwp0 and current pcb and pmap pointers.
208 1.3 thorpej */
209 1.3 thorpej lwp0.l_cpu = ci;
210 1.3 thorpej lwp0.l_addr = proc0paddr;
211 1.3 thorpej memset(lwp0.l_addr, 0, sizeof *lwp0.l_addr);
212 1.1 scw
213 1.1 scw curpcb = &proc0paddr->u_pcb;
214 1.1 scw curpm = curpcb->pcb_pmreal = curpcb->pcb_pm = pmap_kernel();
215 1.1 scw
216 1.1 scw /*
217 1.1 scw * Set up trap vectors
218 1.1 scw */
219 1.1 scw for (exc = EXC_RSVD; exc <= EXC_LAST; exc += 0x100)
220 1.1 scw switch (exc) {
221 1.1 scw default:
222 1.1 scw memcpy((void *)exc, &defaulttrap, (size_t)&defaultsize);
223 1.1 scw break;
224 1.1 scw case EXC_EXI:
225 1.1 scw /*
226 1.1 scw * This one is (potentially) installed during autoconf
227 1.1 scw */
228 1.1 scw break;
229 1.1 scw case EXC_SC:
230 1.1 scw memcpy((void *)EXC_SC, &sctrap, (size_t)&scsize);
231 1.1 scw break;
232 1.1 scw case EXC_ALI:
233 1.1 scw memcpy((void *)EXC_ALI, &alitrap, (size_t)&alisize);
234 1.1 scw break;
235 1.1 scw case EXC_DSI:
236 1.1 scw memcpy((void *)EXC_DSI, &dsitrap, (size_t)&dsisize);
237 1.1 scw break;
238 1.1 scw case EXC_ISI:
239 1.1 scw memcpy((void *)EXC_ISI, &isitrap, (size_t)&isisize);
240 1.1 scw break;
241 1.1 scw case EXC_MCHK:
242 1.1 scw memcpy((void *)EXC_MCHK, &mchktrap, (size_t)&mchksize);
243 1.1 scw break;
244 1.1 scw case EXC_ITMISS:
245 1.1 scw memcpy((void *)EXC_ITMISS, &tlbimiss4xx,
246 1.1 scw (size_t)&tlbim4size);
247 1.1 scw break;
248 1.1 scw case EXC_DTMISS:
249 1.1 scw memcpy((void *)EXC_DTMISS, &tlbdmiss4xx,
250 1.1 scw (size_t)&tlbdm4size);
251 1.1 scw break;
252 1.1 scw /*
253 1.1 scw * EXC_PIT, EXC_FIT, EXC_WDOG handlers
254 1.1 scw * are spaced by 0x10 bytes only..
255 1.1 scw */
256 1.1 scw case EXC_PIT:
257 1.1 scw memcpy((void *)EXC_PIT, &pitfitwdog,
258 1.1 scw (size_t)&pitfitwdogsize);
259 1.1 scw break;
260 1.1 scw case EXC_DEBUG:
261 1.1 scw memcpy((void *)EXC_DEBUG, &debugtrap,
262 1.1 scw (size_t)&debugsize);
263 1.1 scw break;
264 1.1 scw case EXC_DTMISS|EXC_ALI:
265 1.1 scw /* PPC405GP Rev D errata item 51 */
266 1.1 scw memcpy((void *)(EXC_DTMISS|EXC_ALI), &errata51handler,
267 1.1 scw (size_t)&errata51size);
268 1.1 scw break;
269 1.2 thorpej #if defined(DDB) || defined(IPKDB)
270 1.1 scw case EXC_PGM:
271 1.1 scw #if defined(DDB)
272 1.1 scw memcpy((void *)exc, &ddblow, (size_t)&ddbsize);
273 1.1 scw #elif defined(IPKDB)
274 1.1 scw memcpy((void *)exc, &ipkdblow, (size_t)&ipkdbsize);
275 1.1 scw #endif
276 1.2 thorpej #endif /* DDB | IPKDB */
277 1.1 scw break;
278 1.1 scw }
279 1.1 scw
280 1.1 scw __syncicache((void *)EXC_RST, EXC_LAST - EXC_RST + 0x100);
281 1.1 scw mtspr(SPR_EVPR, 0); /* Set Exception vector base */
282 1.1 scw consinit();
283 1.1 scw
284 1.1 scw /* Handle trap instruction as PGM exception */
285 1.1 scw {
286 1.1 scw int dbcr0;
287 1.1 scw asm volatile("mfspr %0,%1":"=r"(dbcr0):"K"(SPR_DBCR0));
288 1.1 scw asm volatile("mtspr %0,%1"::"K"(SPR_DBCR0),"r"(dbcr0 & ~DBCR0_TDE));
289 1.1 scw }
290 1.1 scw
291 1.1 scw /*
292 1.1 scw * external interrupt handler install
293 1.1 scw */
294 1.1 scw install_extint(ext_intr);
295 1.1 scw
296 1.1 scw /*
297 1.1 scw * Now enable translation (and machine checks/recoverable interrupts).
298 1.1 scw */
299 1.1 scw asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
300 1.1 scw : : "r"(0), "K"(PSL_IR|PSL_DR));
301 1.1 scw /* XXXX PSL_ME - With ME set kernel gets stuck... */
302 1.1 scw
303 1.1 scw uvm_setpagesize();
304 1.1 scw
305 1.1 scw /*
306 1.1 scw * Initialize pmap module.
307 1.1 scw */
308 1.1 scw pmap_bootstrap(startkernel, endkernel);
309 1.1 scw
310 1.1 scw consinit();
311 1.1 scw
312 1.1 scw #ifdef DEBUG
313 1.1 scw printf("Board config data:\n");
314 1.1 scw printf(" usr_config_ver = %s\n", board_data.usr_config_ver);
315 1.1 scw printf(" rom_sw_ver = %s\n", board_data.rom_sw_ver);
316 1.1 scw printf(" mem_size = %u\n", board_data.mem_size);
317 1.1 scw printf(" mac_address_local = %02x:%02x:%02x:%02x:%02x:%02x\n",
318 1.1 scw board_data.mac_address_local[0], board_data.mac_address_local[1],
319 1.1 scw board_data.mac_address_local[2], board_data.mac_address_local[3],
320 1.1 scw board_data.mac_address_local[4], board_data.mac_address_local[5]);
321 1.1 scw printf(" mac_address_pci = %02x:%02x:%02x:%02x:%02x:%02x\n",
322 1.1 scw board_data.mac_address_pci[0], board_data.mac_address_pci[1],
323 1.1 scw board_data.mac_address_pci[2], board_data.mac_address_pci[3],
324 1.1 scw board_data.mac_address_pci[4], board_data.mac_address_pci[5]);
325 1.1 scw printf(" processor_speed = %u\n", board_data.processor_speed);
326 1.1 scw printf(" plb_speed = %u\n", board_data.plb_speed);
327 1.1 scw printf(" pci_speed = %u\n", board_data.pci_speed);
328 1.1 scw #endif
329 1.1 scw
330 1.1 scw #ifdef DDB
331 1.1 scw ddb_init((int)((u_int)endsym - (u_int)startsym), startsym, endsym);
332 1.1 scw if (boothowto & RB_KDB)
333 1.1 scw Debugger();
334 1.1 scw #endif
335 1.1 scw #ifdef IPKDB
336 1.1 scw /*
337 1.1 scw * Now trap to IPKDB
338 1.1 scw */
339 1.1 scw ipkdb_init();
340 1.1 scw if (boothowto & RB_KDB)
341 1.1 scw ipkdb_connect(0);
342 1.1 scw #endif
343 1.1 scw fake_mapiodev = 0;
344 1.1 scw }
345 1.1 scw
346 1.1 scw static void
347 1.1 scw install_extint(void (*handler)(void))
348 1.1 scw {
349 1.1 scw extern int extint, extsize;
350 1.1 scw extern u_long extint_call;
351 1.1 scw u_long offset = (u_long)handler - (u_long)&extint_call;
352 1.1 scw int omsr, msr;
353 1.1 scw
354 1.1 scw #ifdef DIAGNOSTIC
355 1.1 scw if (offset > 0x1ffffff)
356 1.1 scw panic("install_extint: too far away");
357 1.1 scw #endif
358 1.1 scw asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1"
359 1.1 scw : "=r"(omsr), "=r"(msr) : "K"((u_short)~PSL_EE));
360 1.1 scw extint_call = (extint_call & 0xfc000003) | offset;
361 1.1 scw memcpy((void *)EXC_EXI, &extint, (size_t)&extsize);
362 1.1 scw __syncicache((void *)&extint_call, sizeof extint_call);
363 1.1 scw __syncicache((void *)EXC_EXI, (int)&extsize);
364 1.1 scw asm volatile ("mtmsr %0" :: "r"(omsr));
365 1.1 scw }
366 1.1 scw
367 1.1 scw /*
368 1.1 scw * Machine dependent startup code.
369 1.1 scw */
370 1.1 scw
371 1.1 scw char msgbuf[MSGBUFSIZE];
372 1.1 scw
373 1.1 scw void
374 1.1 scw cpu_startup(void)
375 1.1 scw {
376 1.1 scw caddr_t v;
377 1.1 scw vaddr_t minaddr, maxaddr;
378 1.1 scw u_int sz, i, base, residual;
379 1.1 scw char pbuf[9];
380 1.1 scw
381 1.1 scw /*
382 1.1 scw * Initialize error message buffer (at end of core).
383 1.1 scw */
384 1.1 scw #if 0 /* For some reason this fails... --Artem
385 1.1 scw * Besides, do we really have to put it at the end of core?
386 1.1 scw * Let's use static buffer for now
387 1.1 scw */
388 1.1 scw if (!(msgbuf_vaddr = uvm_km_alloc(kernel_map, round_page(MSGBUFSIZE))))
389 1.1 scw panic("startup: no room for message buffer");
390 1.1 scw for (i = 0; i < btoc(MSGBUFSIZE); i++)
391 1.1 scw pmap_kenter_pa(msgbuf_vaddr + i * NBPG,
392 1.1 scw msgbuf_paddr + i * NBPG, VM_PROT_READ|VM_PROT_WRITE);
393 1.1 scw initmsgbuf((caddr_t)msgbuf_vaddr, round_page(MSGBUFSIZE));
394 1.1 scw #else
395 1.1 scw initmsgbuf((caddr_t)msgbuf, round_page(MSGBUFSIZE));
396 1.1 scw #endif
397 1.1 scw
398 1.1 scw
399 1.1 scw printf("%s", version);
400 1.1 scw printf("Walnut PowerPC 405GP Evaluation Board\n");
401 1.1 scw
402 1.1 scw format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
403 1.1 scw printf("total memory = %s\n", pbuf);
404 1.1 scw
405 1.1 scw /*
406 1.1 scw * Find out how much space we need, allocate it,
407 1.1 scw * and then give everything true virtual addresses.
408 1.1 scw */
409 1.1 scw sz = (u_int)allocsys(NULL, NULL);
410 1.1 scw if ((v = (caddr_t)uvm_km_zalloc(kernel_map, round_page(sz))) == 0)
411 1.1 scw panic("startup: no room for tables");
412 1.1 scw if (allocsys(v, NULL) - v != sz)
413 1.1 scw panic("startup: table size inconsistency");
414 1.1 scw
415 1.1 scw /*
416 1.1 scw * Now allocate buffers proper. They are different than the above
417 1.1 scw * in that they usually occupy more virtual memory than physical.
418 1.1 scw */
419 1.1 scw sz = MAXBSIZE * nbuf;
420 1.1 scw minaddr = 0;
421 1.1 scw if (uvm_map(kernel_map, (vaddr_t *)&minaddr, round_page(sz),
422 1.1 scw NULL, UVM_UNKNOWN_OFFSET, 0,
423 1.1 scw UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE,
424 1.1 scw UVM_ADV_NORMAL, 0)) != 0)
425 1.1 scw panic("startup: cannot allocate VM for buffers");
426 1.1 scw buffers = (char *)minaddr;
427 1.1 scw base = bufpages / nbuf;
428 1.1 scw residual = bufpages % nbuf;
429 1.1 scw if (base >= MAXBSIZE) {
430 1.1 scw /* Don't want to alloc more physical mem than ever needed */
431 1.1 scw base = MAXBSIZE;
432 1.1 scw residual = 0;
433 1.1 scw }
434 1.1 scw for (i = 0; i < nbuf; i++) {
435 1.1 scw vsize_t curbufsize;
436 1.1 scw vaddr_t curbuf;
437 1.1 scw struct vm_page *pg;
438 1.1 scw
439 1.1 scw curbuf = (vaddr_t)buffers + i * MAXBSIZE;
440 1.1 scw curbufsize = NBPG * (i < residual ? base + 1 : base);
441 1.1 scw
442 1.1 scw while (curbufsize) {
443 1.1 scw pg = uvm_pagealloc(NULL, 0, NULL, 0);
444 1.1 scw if (pg == NULL)
445 1.1 scw panic("cpu_startup: not enough memory for "
446 1.1 scw "buffer cache");
447 1.1 scw pmap_kenter_pa(curbuf, VM_PAGE_TO_PHYS(pg),
448 1.1 scw VM_PROT_READ | VM_PROT_WRITE);
449 1.1 scw curbuf += PAGE_SIZE;
450 1.1 scw curbufsize -= PAGE_SIZE;
451 1.1 scw }
452 1.1 scw }
453 1.1 scw
454 1.1 scw /*
455 1.1 scw * Allocate a submap for exec arguments. This map effectively
456 1.1 scw * limits the number of processes exec'ing at any time.
457 1.1 scw */
458 1.1 scw exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
459 1.1 scw 16*NCARGS, VM_MAP_PAGEABLE, FALSE, NULL);
460 1.1 scw
461 1.1 scw /*
462 1.1 scw * Allocate a submap for physio
463 1.1 scw */
464 1.1 scw phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
465 1.1 scw VM_PHYS_SIZE, 0, FALSE, NULL);
466 1.1 scw
467 1.1 scw /*
468 1.1 scw * No need to allocate an mbuf cluster submap. Mbuf clusters
469 1.1 scw * are allocated via the pool allocator, and we use direct-mapped
470 1.1 scw * pool pages.
471 1.1 scw */
472 1.1 scw
473 1.1 scw format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
474 1.1 scw printf("avail memory = %s\n", pbuf);
475 1.1 scw format_bytes(pbuf, sizeof(pbuf), bufpages * NBPG);
476 1.1 scw printf("using %u buffers containing %s of memory\n", nbuf, pbuf);
477 1.1 scw
478 1.1 scw /*
479 1.1 scw * Set up the buffers.
480 1.1 scw */
481 1.1 scw bufinit();
482 1.1 scw
483 1.1 scw /*
484 1.1 scw * Set up the board properties database.
485 1.1 scw */
486 1.1 scw if (!(board_info = propdb_create("board info")))
487 1.1 scw panic("Cannot create board info database");
488 1.1 scw
489 1.1 scw if (board_info_set("mem-size", &board_data.mem_size,
490 1.1 scw sizeof(&board_data.mem_size), PROP_CONST, 0))
491 1.1 scw panic("setting mem-size");
492 1.1 scw if (board_info_set("emac-mac-addr", &board_data.mac_address_local,
493 1.1 scw sizeof(&board_data.mac_address_local), PROP_CONST, 0))
494 1.1 scw panic("setting emac-mac-addr");
495 1.1 scw if (board_info_set("sip0-mac-addr", &board_data.mac_address_pci,
496 1.1 scw sizeof(&board_data.mac_address_pci), PROP_CONST, 0))
497 1.1 scw panic("setting sip0-mac-addr");
498 1.1 scw if (board_info_set("processor-frequency", &board_data.processor_speed,
499 1.1 scw sizeof(&board_data.processor_speed), PROP_CONST, 0))
500 1.1 scw panic("setting processor-frequency");
501 1.1 scw #if NCOM > 0
502 1.1 scw {
503 1.1 scw unsigned int comfreq = COM_FREQ * 6;
504 1.1 scw if (board_info_set("com-opb-frequency", &comfreq,
505 1.1 scw sizeof(&comfreq), 0, 0))
506 1.1 scw panic("setting com-opb-frequency");
507 1.1 scw }
508 1.1 scw #endif
509 1.1 scw }
510 1.1 scw
511 1.1 scw
512 1.1 scw static void
513 1.1 scw dumpsys(void)
514 1.1 scw {
515 1.1 scw
516 1.1 scw printf("dumpsys: TBD\n");
517 1.1 scw }
518 1.1 scw
519 1.1 scw /*
520 1.1 scw * Soft networking interrupts.
521 1.1 scw */
522 1.1 scw void
523 1.1 scw softnet(void)
524 1.1 scw {
525 1.1 scw int isr;
526 1.1 scw
527 1.1 scw isr = netisr;
528 1.1 scw netisr = 0;
529 1.1 scw
530 1.1 scw #define DONETISR(bit, fn) do { \
531 1.1 scw if (isr & (1 << bit)) \
532 1.1 scw fn(); \
533 1.1 scw } while (0)
534 1.1 scw
535 1.1 scw #include <net/netisr_dispatch.h>
536 1.1 scw
537 1.1 scw #undef DONETISR
538 1.1 scw
539 1.1 scw }
540 1.1 scw
541 1.1 scw /*
542 1.1 scw * Soft tty interrupts.
543 1.1 scw */
544 1.1 scw void
545 1.1 scw softserial(void)
546 1.1 scw {
547 1.1 scw #if NCOM > 0
548 1.1 scw void comsoft(void); /* XXX from dev/ic/com.c */
549 1.1 scw
550 1.1 scw comsoft();
551 1.1 scw #endif
552 1.1 scw }
553 1.1 scw
554 1.1 scw /*
555 1.1 scw * Halt or reboot the machine after syncing/dumping according to howto.
556 1.1 scw */
557 1.1 scw void
558 1.1 scw cpu_reboot(int howto, char *what)
559 1.1 scw {
560 1.1 scw static int syncing;
561 1.1 scw static char str[256];
562 1.1 scw char *ap = str, *ap1 = ap;
563 1.1 scw
564 1.1 scw boothowto = howto;
565 1.1 scw if (!cold && !(howto & RB_NOSYNC) && !syncing) {
566 1.1 scw syncing = 1;
567 1.1 scw vfs_shutdown(); /* sync */
568 1.1 scw resettodr(); /* set wall clock */
569 1.1 scw }
570 1.1 scw
571 1.1 scw splhigh();
572 1.1 scw
573 1.1 scw if (!cold && (howto & RB_DUMP))
574 1.1 scw dumpsys();
575 1.1 scw
576 1.1 scw doshutdownhooks();
577 1.1 scw
578 1.1 scw if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
579 1.1 scw /* Power off here if we know how...*/
580 1.1 scw }
581 1.1 scw
582 1.1 scw if (howto & RB_HALT) {
583 1.1 scw printf("halted\n\n");
584 1.1 scw
585 1.1 scw goto reboot; /* XXX for now... */
586 1.1 scw
587 1.1 scw #ifdef DDB
588 1.1 scw printf("dropping to debugger\n");
589 1.1 scw while(1)
590 1.1 scw Debugger();
591 1.1 scw #endif
592 1.1 scw }
593 1.1 scw
594 1.1 scw printf("rebooting\n\n");
595 1.1 scw if (what && *what) {
596 1.1 scw if (strlen(what) > sizeof str - 5)
597 1.1 scw printf("boot string too large, ignored\n");
598 1.1 scw else {
599 1.1 scw strcpy(str, what);
600 1.1 scw ap1 = ap = str + strlen(str);
601 1.1 scw *ap++ = ' ';
602 1.1 scw }
603 1.1 scw }
604 1.1 scw *ap++ = '-';
605 1.1 scw if (howto & RB_SINGLE)
606 1.1 scw *ap++ = 's';
607 1.1 scw if (howto & RB_KDB)
608 1.1 scw *ap++ = 'd';
609 1.1 scw *ap++ = 0;
610 1.1 scw if (ap[-2] == '-')
611 1.1 scw *ap1 = 0;
612 1.1 scw
613 1.1 scw /* flush cache for msgbuf */
614 1.1 scw __syncicache((void *)msgbuf_paddr, round_page(MSGBUFSIZE));
615 1.1 scw
616 1.1 scw reboot:
617 1.1 scw ppc4xx_reset();
618 1.1 scw
619 1.1 scw printf("ppc4xx_reset() failed!\n");
620 1.1 scw #ifdef DDB
621 1.1 scw while(1)
622 1.1 scw Debugger();
623 1.1 scw #else
624 1.1 scw while (1)
625 1.1 scw /* nothing */;
626 1.1 scw #endif
627 1.1 scw }
628 1.1 scw
629 1.1 scw int
630 1.1 scw lcsplx(int ipl)
631 1.1 scw {
632 1.1 scw
633 1.1 scw return spllower(ipl); /* XXX */
634 1.1 scw }
635 1.1 scw
636 1.1 scw void
637 1.1 scw mem_regions(struct mem_region **mem, struct mem_region **avail)
638 1.1 scw {
639 1.1 scw
640 1.1 scw *mem = physmemr;
641 1.1 scw *avail = availmemr;
642 1.1 scw }
643