machdep.c revision 1.1.4.5 1 1.1.4.5 yamt /* $NetBSD: machdep.c,v 1.1.4.5 2007/10/27 11:26:03 yamt Exp $ */
2 1.1.4.2 yamt
3 1.1.4.2 yamt /*
4 1.1.4.2 yamt * Copyright (c) 2006 Jachym Holecek
5 1.1.4.2 yamt * All rights reserved.
6 1.1.4.2 yamt *
7 1.1.4.2 yamt * Written for DFC Design, s.r.o.
8 1.1.4.2 yamt *
9 1.1.4.2 yamt * Redistribution and use in source and binary forms, with or without
10 1.1.4.2 yamt * modification, are permitted provided that the following conditions
11 1.1.4.2 yamt * are met:
12 1.1.4.2 yamt *
13 1.1.4.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.1.4.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.1.4.2 yamt *
16 1.1.4.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
17 1.1.4.2 yamt * notice, this list of conditions and the following disclaimer in the
18 1.1.4.2 yamt * documentation and/or other materials provided with the distribution.
19 1.1.4.2 yamt *
20 1.1.4.2 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1.4.2 yamt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1.4.2 yamt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1.4.2 yamt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1.4.2 yamt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1.4.2 yamt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1.4.2 yamt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1.4.2 yamt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1.4.2 yamt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1.4.2 yamt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1.4.2 yamt */
31 1.1.4.2 yamt
32 1.1.4.2 yamt /*
33 1.1.4.2 yamt * Based on Walnut and Explora.
34 1.1.4.2 yamt */
35 1.1.4.2 yamt
36 1.1.4.2 yamt #include <sys/cdefs.h>
37 1.1.4.5 yamt __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.1.4.5 2007/10/27 11:26:03 yamt Exp $");
38 1.1.4.2 yamt
39 1.1.4.2 yamt #include "opt_compat_netbsd.h"
40 1.1.4.2 yamt #include "opt_ddb.h"
41 1.1.4.2 yamt #include "opt_ipkdb.h"
42 1.1.4.2 yamt #include "opt_virtex.h"
43 1.1.4.5 yamt #include "opt_kgdb.h"
44 1.1.4.2 yamt
45 1.1.4.2 yamt #include <sys/param.h>
46 1.1.4.2 yamt #include <sys/buf.h>
47 1.1.4.2 yamt #include <sys/exec.h>
48 1.1.4.2 yamt #include <sys/malloc.h>
49 1.1.4.2 yamt #include <sys/mbuf.h>
50 1.1.4.2 yamt #include <sys/mount.h>
51 1.1.4.2 yamt #include <sys/msgbuf.h>
52 1.1.4.2 yamt #include <sys/proc.h>
53 1.1.4.2 yamt #include <sys/reboot.h>
54 1.1.4.2 yamt #include <sys/syscallargs.h>
55 1.1.4.2 yamt #include <sys/syslog.h>
56 1.1.4.2 yamt #include <sys/systm.h>
57 1.1.4.2 yamt #include <sys/kernel.h>
58 1.1.4.2 yamt #include <sys/user.h>
59 1.1.4.2 yamt #include <sys/boot_flag.h>
60 1.1.4.2 yamt #include <sys/ksyms.h>
61 1.1.4.2 yamt
62 1.1.4.2 yamt #include <uvm/uvm_extern.h>
63 1.1.4.2 yamt
64 1.1.4.2 yamt #include <net/netisr.h>
65 1.1.4.2 yamt
66 1.1.4.2 yamt #include <dev/cons.h>
67 1.1.4.2 yamt
68 1.1.4.2 yamt #include <machine/bus.h>
69 1.1.4.2 yamt #include <machine/powerpc.h>
70 1.1.4.2 yamt #include <machine/trap.h>
71 1.1.4.2 yamt
72 1.1.4.2 yamt #include <powerpc/spr.h>
73 1.1.4.2 yamt
74 1.1.4.2 yamt #include <evbppc/virtex/dcr.h>
75 1.1.4.2 yamt #include <evbppc/virtex/virtex.h>
76 1.1.4.2 yamt
77 1.1.4.2 yamt #include "ksyms.h"
78 1.1.4.2 yamt
79 1.1.4.2 yamt #if defined(DDB)
80 1.1.4.2 yamt #include <machine/db_machdep.h>
81 1.1.4.2 yamt #include <ddb/db_extern.h>
82 1.1.4.2 yamt #endif
83 1.1.4.2 yamt
84 1.1.4.5 yamt #if defined(KGDB)
85 1.1.4.5 yamt #include <sys/kgdb.h>
86 1.1.4.5 yamt #endif
87 1.1.4.2 yamt
88 1.1.4.2 yamt /*
89 1.1.4.2 yamt * Global variables used here and there
90 1.1.4.2 yamt */
91 1.1.4.2 yamt struct vm_map *exec_map = NULL;
92 1.1.4.2 yamt struct vm_map *mb_map = NULL;
93 1.1.4.2 yamt struct vm_map *phys_map = NULL;
94 1.1.4.2 yamt
95 1.1.4.2 yamt /*
96 1.1.4.2 yamt * This should probably be in autoconf! XXX
97 1.1.4.2 yamt */
98 1.1.4.2 yamt char cpu_model[80];
99 1.1.4.2 yamt char machine[] = MACHINE; /* from <machine/param.h> */
100 1.1.4.2 yamt char machine_arch[] = MACHINE_ARCH; /* from <machine/param.h> */
101 1.1.4.2 yamt
102 1.1.4.2 yamt extern struct user *proc0paddr;
103 1.1.4.2 yamt
104 1.1.4.2 yamt char bootpath[256];
105 1.1.4.2 yamt paddr_t msgbuf_paddr;
106 1.1.4.2 yamt vaddr_t msgbuf_vaddr;
107 1.1.4.2 yamt
108 1.1.4.2 yamt #if NKSYMS || defined(DDB) || defined(LKM)
109 1.1.4.2 yamt void *startsym, *endsym;
110 1.1.4.2 yamt #endif
111 1.1.4.2 yamt
112 1.1.4.2 yamt int lcsplx(int);
113 1.1.4.2 yamt void initppc(u_int, u_int);
114 1.1.4.2 yamt
115 1.1.4.2 yamt static void dumpsys(void);
116 1.1.4.2 yamt static void install_extint(void (*)(void));
117 1.1.4.2 yamt static void trapcpy(int, void *, size_t);
118 1.1.4.2 yamt
119 1.1.4.2 yamt
120 1.1.4.2 yamt /* These two live in powerpc/powerpc/trap_subr.S */
121 1.1.4.2 yamt extern int extint, extsize;
122 1.1.4.2 yamt extern u_long extint_call;
123 1.1.4.2 yamt
124 1.1.4.2 yamt extern int defaulttrap, defaultsize;
125 1.1.4.2 yamt extern int sctrap, scsize;
126 1.1.4.2 yamt extern int alitrap, alisize;
127 1.1.4.2 yamt extern int dsitrap, dsisize;
128 1.1.4.2 yamt extern int isitrap, isisize;
129 1.1.4.2 yamt extern int mchktrap, mchksize;
130 1.1.4.2 yamt extern int tlbimiss4xx, tlbim4size;
131 1.1.4.2 yamt extern int tlbdmiss4xx, tlbdm4size;
132 1.1.4.2 yamt extern int pitfitwdog, pitfitwdogsize;
133 1.1.4.2 yamt extern int debugtrap, debugsize;
134 1.1.4.2 yamt extern int errata51handler, errata51size;
135 1.1.4.2 yamt #ifdef DDB
136 1.1.4.2 yamt extern int ddblow, ddbsize;
137 1.1.4.2 yamt #endif
138 1.1.4.2 yamt #ifdef IPKDB
139 1.1.4.2 yamt extern int ipkdblow, ipkdbsize;
140 1.1.4.2 yamt #endif
141 1.1.4.2 yamt
142 1.1.4.2 yamt /* BSS segment start & end. */
143 1.1.4.2 yamt extern char edata[], end[];
144 1.1.4.2 yamt
145 1.1.4.2 yamt /* One region holds all memory, the other is terminator expected by 405 pmap. */
146 1.1.4.2 yamt #define MEMREGIONS 2
147 1.1.4.2 yamt struct mem_region physmemr[MEMREGIONS];
148 1.1.4.2 yamt struct mem_region availmemr[MEMREGIONS];
149 1.1.4.2 yamt
150 1.1.4.2 yamt static struct {
151 1.1.4.2 yamt int vector;
152 1.1.4.2 yamt void *addr;
153 1.1.4.2 yamt void *size;
154 1.1.4.2 yamt } traps[] = {
155 1.1.4.2 yamt /* EXC_EXI handled by install_extint(). */
156 1.1.4.2 yamt { EXC_SC, &sctrap, &scsize },
157 1.1.4.2 yamt { EXC_ALI, &alitrap, &alisize },
158 1.1.4.2 yamt { EXC_DSI, &dsitrap, &dsisize },
159 1.1.4.2 yamt { EXC_ISI, &isitrap, &isisize },
160 1.1.4.2 yamt { EXC_MCHK, &mchktrap, &mchksize },
161 1.1.4.2 yamt { EXC_ITMISS, &tlbimiss4xx, &tlbim4size },
162 1.1.4.2 yamt { EXC_DTMISS, &tlbdmiss4xx, &tlbdm4size },
163 1.1.4.2 yamt
164 1.1.4.2 yamt /* EXC_{PIT, FIT, WDOG} handlers are spaced by 0x10 bytes only.. */
165 1.1.4.2 yamt { EXC_PIT, &pitfitwdog, &pitfitwdogsize },
166 1.1.4.2 yamt { EXC_DEBUG, &debugtrap, &debugsize },
167 1.1.4.2 yamt
168 1.1.4.2 yamt /* PPC405GP Rev D errata item 51 */
169 1.1.4.2 yamt { EXC_DTMISS|EXC_ALI, &errata51handler, &errata51size },
170 1.1.4.2 yamt
171 1.1.4.2 yamt #if defined(DDB)
172 1.1.4.2 yamt { EXC_PGM, &ddblow, &ddbsize },
173 1.1.4.2 yamt #elif defined(IPKDB)
174 1.1.4.2 yamt { EXC_PGM, &ipkdblow, &ipkdbsize },
175 1.1.4.2 yamt #endif
176 1.1.4.2 yamt };
177 1.1.4.2 yamt
178 1.1.4.2 yamt /* Maximum TLB page size. */
179 1.1.4.2 yamt #define TLB_PG_SIZE (16*1024*1024)
180 1.1.4.2 yamt
181 1.1.4.2 yamt void
182 1.1.4.2 yamt initppc(u_int startkernel, u_int endkernel)
183 1.1.4.2 yamt {
184 1.1.4.2 yamt struct cpu_info * const ci = curcpu();
185 1.1.4.2 yamt u_int addr, memsize;
186 1.1.4.2 yamt int exc, dbcr0, i;
187 1.1.4.2 yamt
188 1.1.4.2 yamt /* Initialize cache info for memcpy, memset, etc. */
189 1.1.4.2 yamt cpu_probe_cache();
190 1.1.4.2 yamt
191 1.1.4.2 yamt memset(physmemr, 0, sizeof(physmemr)); /* [1].size = 0 */
192 1.1.4.2 yamt memset(availmemr, 0, sizeof(availmemr)); /* [1].size = 0 */
193 1.1.4.2 yamt
194 1.1.4.2 yamt memsize = (PHYSMEM * 1024 * 1024) & ~PGOFSET;
195 1.1.4.2 yamt
196 1.1.4.2 yamt physmemr[0].start = 0;
197 1.1.4.2 yamt physmemr[0].size = memsize;
198 1.1.4.2 yamt
199 1.1.4.2 yamt availmemr[0].start = startkernel;
200 1.1.4.2 yamt availmemr[0].size = memsize - availmemr[0].start;
201 1.1.4.2 yamt
202 1.1.4.2 yamt /* Map kernel memory linearly. */
203 1.1.4.2 yamt for (addr = 0; addr < endkernel; addr += TLB_PG_SIZE)
204 1.1.4.2 yamt ppc4xx_tlb_reserve(addr, addr, TLB_PG_SIZE, TLB_EX);
205 1.1.4.2 yamt
206 1.1.4.2 yamt /* Give design-specific code a hint for reserved mappings. */
207 1.1.4.2 yamt virtex_machdep_init(roundup(memsize, TLB_PG_SIZE), TLB_PG_SIZE,
208 1.1.4.2 yamt physmemr, availmemr);
209 1.1.4.2 yamt
210 1.1.4.2 yamt lwp0.l_cpu = ci;
211 1.1.4.2 yamt lwp0.l_addr = proc0paddr;
212 1.1.4.2 yamt memset(lwp0.l_addr, 0, sizeof(*lwp0.l_addr));
213 1.1.4.2 yamt
214 1.1.4.2 yamt curpcb = &proc0paddr->u_pcb;
215 1.1.4.2 yamt curpcb->pcb_pm = pmap_kernel();
216 1.1.4.2 yamt
217 1.1.4.2 yamt for (exc = EXC_RSVD; exc <= EXC_LAST; exc += 0x100)
218 1.1.4.2 yamt trapcpy(exc, &defaulttrap, (size_t)&defaultsize);
219 1.1.4.2 yamt
220 1.1.4.2 yamt for (i = 0; i < __arraycount(traps); i++)
221 1.1.4.2 yamt trapcpy(traps[i].vector, traps[i].addr, (size_t)traps[i].size);
222 1.1.4.2 yamt
223 1.1.4.2 yamt __syncicache((void *)EXC_RST, EXC_LAST - EXC_RST + 0x100);
224 1.1.4.2 yamt
225 1.1.4.2 yamt /* set exception vector base */
226 1.1.4.2 yamt mtspr(SPR_EVPR, 0);
227 1.1.4.2 yamt
228 1.1.4.2 yamt /* handle trap instruction as PGM exception */
229 1.1.4.2 yamt dbcr0 = mfspr(SPR_DBCR0) & ~DBCR0_TDE;
230 1.1.4.2 yamt mtspr(SPR_DBCR0, dbcr0);
231 1.1.4.2 yamt
232 1.1.4.2 yamt install_extint(ext_intr);
233 1.1.4.2 yamt
234 1.1.4.2 yamt /* enable translation */
235 1.1.4.2 yamt __asm volatile (
236 1.1.4.2 yamt " mfmsr %0 \n"
237 1.1.4.2 yamt " ori %0,%0,%1 \n"
238 1.1.4.2 yamt " mtmsr %0 \n"
239 1.1.4.2 yamt " sync \n"
240 1.1.4.2 yamt " isync \n"
241 1.1.4.2 yamt : : "r"(0), "K"(PSL_IR | PSL_DR | PSL_ME));
242 1.1.4.2 yamt
243 1.1.4.2 yamt /* now that we enabled MMU, we can map console */
244 1.1.4.2 yamt consinit();
245 1.1.4.2 yamt
246 1.1.4.2 yamt uvm_setpagesize();
247 1.1.4.2 yamt pmap_bootstrap(startkernel, endkernel);
248 1.1.4.2 yamt
249 1.1.4.2 yamt #if NKSYMS || defined(DDB) || defined(LKM)
250 1.1.4.2 yamt ksyms_init((int)((u_int)endsym - (u_int)startsym), startsym, endsym);
251 1.1.4.2 yamt #endif
252 1.1.4.2 yamt #ifdef DDB
253 1.1.4.2 yamt if (boothowto & RB_KDB)
254 1.1.4.2 yamt Debugger();
255 1.1.4.2 yamt #endif
256 1.1.4.2 yamt #ifdef IPKDB
257 1.1.4.2 yamt /*
258 1.1.4.2 yamt * Now trap to IPKDB
259 1.1.4.2 yamt */
260 1.1.4.2 yamt ipkdb_init();
261 1.1.4.2 yamt if (boothowto & RB_KDB)
262 1.1.4.2 yamt ipkdb_connect(0);
263 1.1.4.2 yamt #endif
264 1.1.4.5 yamt #ifdef KGDB
265 1.1.4.5 yamt /*
266 1.1.4.5 yamt * Now trap to KGDB
267 1.1.4.5 yamt */
268 1.1.4.5 yamt kgdb_connect(1);
269 1.1.4.5 yamt #endif /* KGDB */
270 1.1.4.2 yamt }
271 1.1.4.2 yamt
272 1.1.4.2 yamt /*
273 1.1.4.2 yamt * trapcpy:
274 1.1.4.2 yamt *
275 1.1.4.2 yamt * Install a trap vector. We cannot use memcpy because the
276 1.1.4.2 yamt * destination may be zero. Borrowed from Explora.
277 1.1.4.2 yamt */
278 1.1.4.2 yamt static void
279 1.1.4.2 yamt trapcpy(int dest, void *src, size_t len)
280 1.1.4.2 yamt {
281 1.1.4.2 yamt uint32_t *dest_p = (void *)dest;
282 1.1.4.2 yamt uint32_t *src_p = src;
283 1.1.4.2 yamt
284 1.1.4.2 yamt while (len > 0) {
285 1.1.4.2 yamt *dest_p++ = *src_p++;
286 1.1.4.2 yamt len -= sizeof(uint32_t);
287 1.1.4.2 yamt }
288 1.1.4.2 yamt }
289 1.1.4.2 yamt
290 1.1.4.2 yamt static void
291 1.1.4.2 yamt install_extint(void (*handler)(void))
292 1.1.4.2 yamt {
293 1.1.4.2 yamt u_long offset = (u_long)handler - (u_long)&extint_call;
294 1.1.4.2 yamt
295 1.1.4.2 yamt #ifdef DIAGNOSTIC
296 1.1.4.2 yamt if (offset > 0x1ffffff)
297 1.1.4.2 yamt panic("install_extint: too far away");
298 1.1.4.2 yamt #endif
299 1.1.4.2 yamt
300 1.1.4.2 yamt /* Patch branch target in EXC_EXI handler. */
301 1.1.4.2 yamt extint_call = (extint_call & 0xfc000003) | offset;
302 1.1.4.2 yamt
303 1.1.4.2 yamt memcpy((void *)EXC_EXI, &extint, (size_t)&extsize);
304 1.1.4.2 yamt __syncicache((void *)&extint_call, sizeof(extint_call));
305 1.1.4.2 yamt __syncicache((void *)EXC_EXI, (int)&extsize);
306 1.1.4.2 yamt }
307 1.1.4.2 yamt
308 1.1.4.2 yamt /*
309 1.1.4.2 yamt * Machine dependent startup code.
310 1.1.4.2 yamt */
311 1.1.4.2 yamt
312 1.1.4.2 yamt char msgbuf[MSGBUFSIZE];
313 1.1.4.2 yamt
314 1.1.4.2 yamt void
315 1.1.4.2 yamt cpu_startup(void)
316 1.1.4.2 yamt {
317 1.1.4.2 yamt /* For use by propdb. */
318 1.1.4.2 yamt static u_int memsize = PHYSMEM * 1024 * 1024;
319 1.1.4.2 yamt static u_int cpuspeed = CPUFREQ * 1000 * 1000;
320 1.1.4.2 yamt prop_number_t pn;
321 1.1.4.2 yamt
322 1.1.4.2 yamt vaddr_t minaddr, maxaddr;
323 1.1.4.2 yamt char pbuf[9];
324 1.1.4.2 yamt
325 1.1.4.2 yamt curcpu()->ci_khz = cpuspeed / 1000;
326 1.1.4.2 yamt
327 1.1.4.2 yamt /* Initialize error message buffer. */
328 1.1.4.4 yamt initmsgbuf((void *)msgbuf, round_page(MSGBUFSIZE));
329 1.1.4.2 yamt
330 1.1.4.2 yamt printf("%s%s", copyright, version);
331 1.1.4.2 yamt
332 1.1.4.2 yamt format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
333 1.1.4.2 yamt printf("total memory = %s\n", pbuf);
334 1.1.4.2 yamt
335 1.1.4.2 yamt minaddr = 0;
336 1.1.4.2 yamt /*
337 1.1.4.2 yamt * Allocate a submap for exec arguments. This map effectively
338 1.1.4.2 yamt * limits the number of processes exec'ing at any time.
339 1.1.4.2 yamt */
340 1.1.4.2 yamt exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
341 1.1.4.3 yamt 16*NCARGS, VM_MAP_PAGEABLE, false, NULL);
342 1.1.4.2 yamt
343 1.1.4.2 yamt /*
344 1.1.4.2 yamt * Allocate a submap for physio
345 1.1.4.2 yamt */
346 1.1.4.2 yamt phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
347 1.1.4.3 yamt VM_PHYS_SIZE, 0, false, NULL);
348 1.1.4.2 yamt
349 1.1.4.2 yamt /*
350 1.1.4.2 yamt * No need to allocate an mbuf cluster submap. Mbuf clusters
351 1.1.4.2 yamt * are allocated via the pool allocator, and we use direct-mapped
352 1.1.4.2 yamt * pool pages.
353 1.1.4.2 yamt */
354 1.1.4.2 yamt
355 1.1.4.2 yamt format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
356 1.1.4.2 yamt printf("avail memory = %s\n", pbuf);
357 1.1.4.2 yamt
358 1.1.4.2 yamt /*
359 1.1.4.2 yamt * Set up the board properties database.
360 1.1.4.2 yamt */
361 1.1.4.2 yamt board_info_init();
362 1.1.4.2 yamt
363 1.1.4.2 yamt pn = prop_number_create_integer(memsize);
364 1.1.4.2 yamt KASSERT(pn != NULL);
365 1.1.4.3 yamt if (prop_dictionary_set(board_properties, "mem-size", pn) == false)
366 1.1.4.2 yamt panic("setting mem-size");
367 1.1.4.2 yamt prop_object_release(pn);
368 1.1.4.2 yamt
369 1.1.4.2 yamt pn = prop_number_create_integer(cpuspeed);
370 1.1.4.2 yamt KASSERT(pn != NULL);
371 1.1.4.2 yamt if (prop_dictionary_set(board_properties, "processor-frequency",
372 1.1.4.3 yamt pn) == false)
373 1.1.4.2 yamt panic("setting processor-frequency");
374 1.1.4.2 yamt prop_object_release(pn);
375 1.1.4.2 yamt
376 1.1.4.2 yamt /*
377 1.1.4.2 yamt * Now that we have VM, malloc()s are OK in bus_space.
378 1.1.4.2 yamt */
379 1.1.4.2 yamt bus_space_mallocok();
380 1.1.4.2 yamt fake_mapiodev = 0;
381 1.1.4.2 yamt }
382 1.1.4.2 yamt
383 1.1.4.2 yamt
384 1.1.4.2 yamt static void
385 1.1.4.2 yamt dumpsys(void)
386 1.1.4.2 yamt {
387 1.1.4.2 yamt printf("dumpsys: TBD\n");
388 1.1.4.2 yamt }
389 1.1.4.2 yamt
390 1.1.4.2 yamt /* Hook used by 405 pmap module. */
391 1.1.4.2 yamt void
392 1.1.4.2 yamt mem_regions(struct mem_region **mem, struct mem_region **avail)
393 1.1.4.2 yamt {
394 1.1.4.2 yamt *mem = physmemr;
395 1.1.4.2 yamt *avail = availmemr;
396 1.1.4.2 yamt }
397 1.1.4.2 yamt
398 1.1.4.2 yamt /*
399 1.1.4.2 yamt * Halt or reboot the machine after syncing/dumping according to howto.
400 1.1.4.2 yamt */
401 1.1.4.2 yamt void
402 1.1.4.2 yamt cpu_reboot(int howto, char *what)
403 1.1.4.2 yamt {
404 1.1.4.2 yamt static int syncing;
405 1.1.4.2 yamt static char str[256];
406 1.1.4.2 yamt char *ap = str, *ap1 = ap;
407 1.1.4.2 yamt
408 1.1.4.2 yamt boothowto = howto;
409 1.1.4.2 yamt if (!cold && !(howto & RB_NOSYNC) && !syncing) {
410 1.1.4.2 yamt syncing = 1;
411 1.1.4.2 yamt vfs_shutdown(); /* sync */
412 1.1.4.2 yamt resettodr(); /* set wall clock */
413 1.1.4.2 yamt }
414 1.1.4.2 yamt
415 1.1.4.2 yamt splhigh();
416 1.1.4.2 yamt
417 1.1.4.2 yamt if (!cold && (howto & RB_DUMP))
418 1.1.4.2 yamt dumpsys();
419 1.1.4.2 yamt
420 1.1.4.2 yamt doshutdownhooks();
421 1.1.4.2 yamt
422 1.1.4.2 yamt if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
423 1.1.4.2 yamt /* Power off here if we know how...*/
424 1.1.4.2 yamt }
425 1.1.4.2 yamt
426 1.1.4.2 yamt if (howto & RB_HALT) {
427 1.1.4.2 yamt printf("halted\n\n");
428 1.1.4.2 yamt
429 1.1.4.2 yamt goto reboot; /* XXX for now... */
430 1.1.4.2 yamt
431 1.1.4.2 yamt #ifdef DDB
432 1.1.4.2 yamt printf("dropping to debugger\n");
433 1.1.4.2 yamt while(1)
434 1.1.4.2 yamt Debugger();
435 1.1.4.2 yamt #endif
436 1.1.4.5 yamt #ifdef KGDB
437 1.1.4.5 yamt printf("dropping to kgdb\n");
438 1.1.4.5 yamt while(1)
439 1.1.4.5 yamt kgdb_connect(1);
440 1.1.4.5 yamt #endif
441 1.1.4.2 yamt }
442 1.1.4.2 yamt
443 1.1.4.2 yamt printf("rebooting\n\n");
444 1.1.4.2 yamt if (what && *what) {
445 1.1.4.2 yamt if (strlen(what) > sizeof str - 5)
446 1.1.4.2 yamt printf("boot string too large, ignored\n");
447 1.1.4.2 yamt else {
448 1.1.4.2 yamt strcpy(str, what);
449 1.1.4.2 yamt ap1 = ap = str + strlen(str);
450 1.1.4.2 yamt *ap++ = ' ';
451 1.1.4.2 yamt }
452 1.1.4.2 yamt }
453 1.1.4.2 yamt *ap++ = '-';
454 1.1.4.2 yamt if (howto & RB_SINGLE)
455 1.1.4.2 yamt *ap++ = 's';
456 1.1.4.2 yamt if (howto & RB_KDB)
457 1.1.4.2 yamt *ap++ = 'd';
458 1.1.4.2 yamt *ap++ = 0;
459 1.1.4.2 yamt if (ap[-2] == '-')
460 1.1.4.2 yamt *ap1 = 0;
461 1.1.4.2 yamt
462 1.1.4.2 yamt /* flush cache for msgbuf */
463 1.1.4.2 yamt __syncicache((void *)msgbuf_paddr, round_page(MSGBUFSIZE));
464 1.1.4.2 yamt
465 1.1.4.2 yamt reboot:
466 1.1.4.2 yamt ppc4xx_reset();
467 1.1.4.2 yamt
468 1.1.4.2 yamt printf("ppc4xx_reset() failed!\n");
469 1.1.4.2 yamt #ifdef DDB
470 1.1.4.2 yamt while(1)
471 1.1.4.2 yamt Debugger();
472 1.1.4.5 yamt #endif
473 1.1.4.5 yamt #ifdef KGDB
474 1.1.4.5 yamt while(1)
475 1.1.4.5 yamt kgdb_connect(1);
476 1.1.4.2 yamt #else
477 1.1.4.2 yamt while (1)
478 1.1.4.2 yamt /* nothing */;
479 1.1.4.2 yamt #endif
480 1.1.4.2 yamt }
481 1.1.4.2 yamt
482 1.1.4.2 yamt int
483 1.1.4.2 yamt lcsplx(int ipl)
484 1.1.4.2 yamt {
485 1.1.4.2 yamt return spllower(ipl); /* XXX */
486 1.1.4.2 yamt }
487