machdep.c revision 1.1.2.3 1 1.1.2.3 cliff /* $NetBSD: machdep.c,v 1.1.2.3 2009/09/15 02:46:43 cliff Exp $ */
2 1.1.2.1 cliff
3 1.1.2.1 cliff /*
4 1.1.2.1 cliff * Copyright 2001, 2002 Wasabi Systems, Inc.
5 1.1.2.1 cliff * All rights reserved.
6 1.1.2.1 cliff *
7 1.1.2.1 cliff * Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc.
8 1.1.2.1 cliff *
9 1.1.2.1 cliff * Redistribution and use in source and binary forms, with or without
10 1.1.2.1 cliff * modification, are permitted provided that the following conditions
11 1.1.2.1 cliff * are met:
12 1.1.2.1 cliff * 1. Redistributions of source code must retain the above copyright
13 1.1.2.1 cliff * notice, this list of conditions and the following disclaimer.
14 1.1.2.1 cliff * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.2.1 cliff * notice, this list of conditions and the following disclaimer in the
16 1.1.2.1 cliff * documentation and/or other materials provided with the distribution.
17 1.1.2.1 cliff * 3. All advertising materials mentioning features or use of this software
18 1.1.2.1 cliff * must display the following acknowledgement:
19 1.1.2.1 cliff * This product includes software developed for the NetBSD Project by
20 1.1.2.1 cliff * Wasabi Systems, Inc.
21 1.1.2.1 cliff * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1.2.1 cliff * or promote products derived from this software without specific prior
23 1.1.2.1 cliff * written permission.
24 1.1.2.1 cliff *
25 1.1.2.1 cliff * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1.2.1 cliff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1.2.1 cliff * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1.2.1 cliff * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1.2.1 cliff * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1.2.1 cliff * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1.2.1 cliff * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1.2.1 cliff * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1.2.1 cliff * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1.2.1 cliff * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1.2.1 cliff * POSSIBILITY OF SUCH DAMAGE.
36 1.1.2.1 cliff */
37 1.1.2.1 cliff
38 1.1.2.1 cliff /*
39 1.1.2.1 cliff * Copyright (c) 1992, 1993
40 1.1.2.1 cliff * The Regents of the University of California. All rights reserved.
41 1.1.2.1 cliff *
42 1.1.2.1 cliff * This code is derived from software contributed to Berkeley by
43 1.1.2.1 cliff * the Systems Programming Group of the University of Utah Computer
44 1.1.2.1 cliff * Science Department, The Mach Operating System project at
45 1.1.2.1 cliff * Carnegie-Mellon University and Ralph Campbell.
46 1.1.2.1 cliff *
47 1.1.2.1 cliff * Redistribution and use in source and binary forms, with or without
48 1.1.2.1 cliff * modification, are permitted provided that the following conditions
49 1.1.2.1 cliff * are met:
50 1.1.2.1 cliff * 1. Redistributions of source code must retain the above copyright
51 1.1.2.1 cliff * notice, this list of conditions and the following disclaimer.
52 1.1.2.1 cliff * 2. Redistributions in binary form must reproduce the above copyright
53 1.1.2.1 cliff * notice, this list of conditions and the following disclaimer in the
54 1.1.2.1 cliff * documentation and/or other materials provided with the distribution.
55 1.1.2.1 cliff * 3. Neither the name of the University nor the names of its contributors
56 1.1.2.1 cliff * may be used to endorse or promote products derived from this software
57 1.1.2.1 cliff * without specific prior written permission.
58 1.1.2.1 cliff *
59 1.1.2.1 cliff * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 1.1.2.1 cliff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 1.1.2.1 cliff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 1.1.2.1 cliff * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 1.1.2.1 cliff * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 1.1.2.1 cliff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 1.1.2.1 cliff * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 1.1.2.1 cliff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 1.1.2.1 cliff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 1.1.2.1 cliff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 1.1.2.1 cliff * SUCH DAMAGE.
70 1.1.2.1 cliff *
71 1.1.2.1 cliff * @(#)machdep.c 8.3 (Berkeley) 1/12/94
72 1.1.2.1 cliff * from: Utah Hdr: machdep.c 1.63 91/04/24
73 1.1.2.1 cliff */
74 1.1.2.1 cliff /*
75 1.1.2.1 cliff * Copyright (c) 1988 University of Utah.
76 1.1.2.1 cliff *
77 1.1.2.1 cliff * This code is derived from software contributed to Berkeley by
78 1.1.2.1 cliff * the Systems Programming Group of the University of Utah Computer
79 1.1.2.1 cliff * Science Department, The Mach Operating System project at
80 1.1.2.1 cliff * Carnegie-Mellon University and Ralph Campbell.
81 1.1.2.1 cliff *
82 1.1.2.1 cliff * Redistribution and use in source and binary forms, with or without
83 1.1.2.1 cliff * modification, are permitted provided that the following conditions
84 1.1.2.1 cliff * are met:
85 1.1.2.1 cliff * 1. Redistributions of source code must retain the above copyright
86 1.1.2.1 cliff * notice, this list of conditions and the following disclaimer.
87 1.1.2.1 cliff * 2. Redistributions in binary form must reproduce the above copyright
88 1.1.2.1 cliff * notice, this list of conditions and the following disclaimer in the
89 1.1.2.1 cliff * documentation and/or other materials provided with the distribution.
90 1.1.2.1 cliff * 3. All advertising materials mentioning features or use of this software
91 1.1.2.1 cliff * must display the following acknowledgement:
92 1.1.2.1 cliff * This product includes software developed by the University of
93 1.1.2.1 cliff * California, Berkeley and its contributors.
94 1.1.2.1 cliff * 4. Neither the name of the University nor the names of its contributors
95 1.1.2.1 cliff * may be used to endorse or promote products derived from this software
96 1.1.2.1 cliff * without specific prior written permission.
97 1.1.2.1 cliff *
98 1.1.2.1 cliff * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
99 1.1.2.1 cliff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
100 1.1.2.1 cliff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
101 1.1.2.1 cliff * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
102 1.1.2.1 cliff * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
103 1.1.2.1 cliff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
104 1.1.2.1 cliff * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
105 1.1.2.1 cliff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
106 1.1.2.1 cliff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
107 1.1.2.1 cliff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
108 1.1.2.1 cliff * SUCH DAMAGE.
109 1.1.2.1 cliff *
110 1.1.2.1 cliff * @(#)machdep.c 8.3 (Berkeley) 1/12/94
111 1.1.2.1 cliff * from: Utah Hdr: machdep.c 1.63 91/04/24
112 1.1.2.1 cliff */
113 1.1.2.1 cliff
114 1.1.2.1 cliff #include <sys/cdefs.h>
115 1.1.2.3 cliff __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.1.2.3 2009/09/15 02:46:43 cliff Exp $");
116 1.1.2.1 cliff
117 1.1.2.1 cliff #include "opt_ddb.h"
118 1.1.2.1 cliff #include "opt_com.h"
119 1.1.2.1 cliff #include "opt_execfmt.h"
120 1.1.2.1 cliff #include "opt_memsize.h"
121 1.1.2.1 cliff
122 1.1.2.1 cliff #include <sys/param.h>
123 1.1.2.1 cliff #include <sys/systm.h>
124 1.1.2.1 cliff #include <sys/kernel.h>
125 1.1.2.1 cliff #include <sys/buf.h>
126 1.1.2.1 cliff #include <sys/reboot.h>
127 1.1.2.1 cliff #include <sys/user.h>
128 1.1.2.1 cliff #include <sys/mount.h>
129 1.1.2.1 cliff #include <sys/kcore.h>
130 1.1.2.1 cliff #include <sys/boot_flag.h>
131 1.1.2.1 cliff #include <sys/termios.h>
132 1.1.2.1 cliff #include <sys/ksyms.h>
133 1.1.2.1 cliff #include <sys/bus.h>
134 1.1.2.1 cliff #include <sys/device.h>
135 1.1.2.1 cliff
136 1.1.2.1 cliff #include <uvm/uvm_extern.h>
137 1.1.2.1 cliff
138 1.1.2.1 cliff #include <dev/cons.h>
139 1.1.2.1 cliff
140 1.1.2.1 cliff #include "ksyms.h"
141 1.1.2.1 cliff
142 1.1.2.1 cliff #if NKSYMS || defined(DDB) || defined(LKM)
143 1.1.2.1 cliff #include <machine/db_machdep.h>
144 1.1.2.1 cliff #include <ddb/db_extern.h>
145 1.1.2.1 cliff #endif
146 1.1.2.1 cliff
147 1.1.2.1 cliff #include <machine/cpu.h>
148 1.1.2.1 cliff #include <machine/psl.h>
149 1.1.2.1 cliff
150 1.1.2.1 cliff #include "com.h"
151 1.1.2.1 cliff #if NCOM == 0
152 1.1.2.1 cliff #error no serial console
153 1.1.2.1 cliff #endif
154 1.1.2.1 cliff
155 1.1.2.1 cliff #include <dev/ic/comreg.h>
156 1.1.2.1 cliff #include <dev/ic/comvar.h>
157 1.1.2.1 cliff
158 1.1.2.1 cliff #include <mips/rmi/rmixl_comvar.h>
159 1.1.2.1 cliff #include <mips/rmi/rmixlvar.h>
160 1.1.2.1 cliff #include <mips/rmi/rmixl_firmware.h>
161 1.1.2.1 cliff #include <mips/rmi/rmixlreg.h>
162 1.1.2.1 cliff
163 1.1.2.1 cliff #ifndef CONSPEED
164 1.1.2.1 cliff # define CONSPEED 38400
165 1.1.2.1 cliff #endif
166 1.1.2.1 cliff #ifndef CONMODE
167 1.1.2.1 cliff # define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)
168 1.1.2.1 cliff #endif
169 1.1.2.1 cliff #ifndef CONSADDR
170 1.1.2.1 cliff # define CONSADDR RMIXL_IO_DEV_UART_1
171 1.1.2.1 cliff #endif
172 1.1.2.1 cliff
173 1.1.2.1 cliff int comcnfreq = -1;
174 1.1.2.1 cliff uint comcnspeed = CONSPEED;
175 1.1.2.1 cliff uint comcnmode = CONMODE;
176 1.1.2.1 cliff bus_addr_t comcnaddr = (bus_addr_t)CONSADDR;
177 1.1.2.1 cliff
178 1.1.2.1 cliff struct rmixl_config rmixl_configuration;
179 1.1.2.1 cliff
180 1.1.2.1 cliff
181 1.1.2.1 cliff /*
182 1.1.2.1 cliff * array of tested firmware versions
183 1.1.2.1 cliff * if you fiund new ones and they work
184 1.1.2.1 cliff * please add them
185 1.1.2.1 cliff */
186 1.1.2.1 cliff static uint64_t rmiclfw_psb_versions[] = {
187 1.1.2.1 cliff 0x4958d4fb00000056,
188 1.1.2.1 cliff };
189 1.1.2.1 cliff #define RMICLFW_PSB_VERSIONS_LEN \
190 1.1.2.1 cliff (sizeof(rmiclfw_psb_versions)/sizeof(rmiclfw_psb_versions[0]))
191 1.1.2.1 cliff
192 1.1.2.1 cliff /*
193 1.1.2.1 cliff * kernel copies of firmware info
194 1.1.2.1 cliff */
195 1.1.2.1 cliff static rmixlfw_info_t rmixlfw_info;
196 1.1.2.1 cliff static rmixlfw_mmap_t rmixlfw_phys_mmap;
197 1.1.2.1 cliff static rmixlfw_mmap_t rmixlfw_avail_mmap;
198 1.1.2.1 cliff
199 1.1.2.1 cliff
200 1.1.2.1 cliff /* For sysctl_hw. */
201 1.1.2.1 cliff extern char cpu_model[];
202 1.1.2.1 cliff
203 1.1.2.1 cliff /* Our exported CPU info; we can have only one. */
204 1.1.2.1 cliff struct cpu_info cpu_info_store;
205 1.1.2.1 cliff
206 1.1.2.1 cliff /* Maps for VM objects. */
207 1.1.2.1 cliff struct vm_map *mb_map = NULL;
208 1.1.2.1 cliff struct vm_map *phys_map = NULL;
209 1.1.2.1 cliff
210 1.1.2.1 cliff int physmem; /* Total physical memory */
211 1.1.2.1 cliff
212 1.1.2.1 cliff int netboot; /* Are we netbooting? */
213 1.1.2.1 cliff
214 1.1.2.1 cliff
215 1.1.2.1 cliff phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
216 1.1.2.1 cliff int mem_cluster_cnt;
217 1.1.2.1 cliff
218 1.1.2.1 cliff void configure(void);
219 1.1.2.1 cliff void mach_init(int, int32_t *, void *, void *);
220 1.1.2.1 cliff static u_long rmixlfw_init(void *);
221 1.1.2.1 cliff static void __attribute__((__noreturn__)) rmixl_exit(int);
222 1.1.2.1 cliff
223 1.1.2.1 cliff
224 1.1.2.1 cliff /*
225 1.1.2.1 cliff * safepri is a safe priority for sleep to set for a spin-wait during
226 1.1.2.1 cliff * autoconfiguration or after a panic. Used as an argument to splx().
227 1.1.2.1 cliff */
228 1.1.2.1 cliff int safepri = MIPS1_PSL_LOWIPL;
229 1.1.2.1 cliff
230 1.1.2.1 cliff extern struct user *proc0paddr;
231 1.1.2.1 cliff
232 1.1.2.1 cliff /*
233 1.1.2.1 cliff * Do all the stuff that locore normally does before calling main().
234 1.1.2.1 cliff */
235 1.1.2.1 cliff void
236 1.1.2.1 cliff mach_init(int argc, int32_t *argv, void *envp, void *infop)
237 1.1.2.1 cliff {
238 1.1.2.1 cliff struct rmixl_config *rcp;
239 1.1.2.1 cliff void *kernend, *v;
240 1.1.2.1 cliff size_t first, last;
241 1.1.2.1 cliff u_long memsize;
242 1.1.2.1 cliff extern char edata[], end[];
243 1.1.2.1 cliff
244 1.1.2.1 cliff /*
245 1.1.2.1 cliff * Clear the BSS segment.
246 1.1.2.1 cliff */
247 1.1.2.1 cliff kernend = (void *)mips_round_page(end);
248 1.1.2.1 cliff memset(edata, 0, (char *)kernend - edata);
249 1.1.2.1 cliff
250 1.1.2.1 cliff /*
251 1.1.2.1 cliff * Set up the exception vectors and CPU-specific function
252 1.1.2.1 cliff * vectors early on. We need the wbflush() vector set up
253 1.1.2.1 cliff * before comcnattach() is called (or at least before the
254 1.1.2.1 cliff * first printf() after that is called).
255 1.1.2.1 cliff * Also clears the I+D caches.
256 1.1.2.1 cliff */
257 1.1.2.1 cliff mips_vector_init();
258 1.1.2.1 cliff
259 1.1.2.1 cliff memsize = rmixlfw_init(infop);
260 1.1.2.1 cliff
261 1.1.2.1 cliff /* set the VM page size */
262 1.1.2.1 cliff uvm_setpagesize();
263 1.1.2.1 cliff
264 1.1.2.1 cliff physmem = btoc(memsize);
265 1.1.2.1 cliff
266 1.1.2.1 cliff rcp = &rmixl_configuration;
267 1.1.2.2 cliff rcp->rc_io_pbase = MIPS_KSEG1_TO_PHYS(rmixlfw_info.io_base);
268 1.1.2.3 cliff rmixl_eb_bus_mem_init(&rcp->rc_eb_memt, rcp); /* need for console */
269 1.1.2.3 cliff rmixl_el_bus_mem_init(&rcp->rc_el_memt, rcp); /* XXX defer ? */
270 1.1.2.1 cliff
271 1.1.2.1 cliff #if NCOM > 0
272 1.1.2.1 cliff rmixl_com_cnattach(comcnaddr, comcnspeed, comcnfreq,
273 1.1.2.1 cliff COM_TYPE_NORMAL, comcnmode);
274 1.1.2.1 cliff #endif
275 1.1.2.1 cliff
276 1.1.2.1 cliff printf("\nNetBSD/rmixl\n");
277 1.1.2.1 cliff printf("memsize = %#lx\n", memsize);
278 1.1.2.1 cliff
279 1.1.2.1 cliff /*
280 1.1.2.1 cliff * Obtain the cpu frequency
281 1.1.2.1 cliff * Compute the number of ticks for hz.
282 1.1.2.1 cliff * Compute the delay divisor.
283 1.1.2.1 cliff * Double the Hz if this CPU runs at twice the
284 1.1.2.1 cliff * external/cp0-count frequency
285 1.1.2.1 cliff */
286 1.1.2.1 cliff curcpu()->ci_cpu_freq = rmixlfw_info.cpu_frequency;
287 1.1.2.1 cliff curcpu()->ci_cycles_per_hz = (curcpu()->ci_cpu_freq + hz / 2) / hz;
288 1.1.2.1 cliff curcpu()->ci_divisor_delay =
289 1.1.2.1 cliff ((curcpu()->ci_cpu_freq + 500000) / 1000000);
290 1.1.2.1 cliff if (mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
291 1.1.2.1 cliff curcpu()->ci_cpu_freq *= 2;
292 1.1.2.1 cliff
293 1.1.2.1 cliff /*
294 1.1.2.1 cliff * Look at arguments passed to us and compute boothowto.
295 1.1.2.1 cliff * - rmixl firmware gives us a 32 bit argv[i], so adapt
296 1.1.2.1 cliff * by forcing sign extension in cast to (char *)
297 1.1.2.1 cliff */
298 1.1.2.1 cliff boothowto = RB_AUTOBOOT;
299 1.1.2.1 cliff for (int i = 1; i < argc; i++) {
300 1.1.2.1 cliff for (char *cp = (char *)(uint64_t)argv[i]; *cp; cp++) {
301 1.1.2.1 cliff int howto;
302 1.1.2.1 cliff /* Ignore superfluous '-', if there is one */
303 1.1.2.1 cliff if (*cp == '-')
304 1.1.2.1 cliff continue;
305 1.1.2.1 cliff
306 1.1.2.1 cliff howto = 0;
307 1.1.2.1 cliff BOOT_FLAG(*cp, howto);
308 1.1.2.1 cliff if (! howto)
309 1.1.2.1 cliff printf("bootflag '%c' not recognised\n", *cp);
310 1.1.2.1 cliff else
311 1.1.2.1 cliff boothowto |= howto;
312 1.1.2.1 cliff }
313 1.1.2.1 cliff }
314 1.1.2.1 cliff printf("boothowto %#x\n", boothowto);
315 1.1.2.1 cliff
316 1.1.2.1 cliff /*
317 1.1.2.1 cliff * Load the rest of the available pages into the VM system.
318 1.1.2.1 cliff */
319 1.1.2.1 cliff first = round_page(MIPS_KSEG0_TO_PHYS(kernend));
320 1.1.2.1 cliff last = mem_clusters[0].start + mem_clusters[0].size;
321 1.1.2.1 cliff uvm_page_physload(atop(first), atop(last), atop(first), atop(last),
322 1.1.2.1 cliff VM_FREELIST_DEFAULT);
323 1.1.2.1 cliff for (int i = 1; i < mem_cluster_cnt; i++) {
324 1.1.2.1 cliff first = round_page(mem_clusters[i].start);
325 1.1.2.1 cliff last = mem_clusters[i].start + mem_clusters[i].size;
326 1.1.2.1 cliff uvm_page_physload(atop(first), atop(last), atop(first), atop(last),
327 1.1.2.1 cliff VM_FREELIST_DEFAULT);
328 1.1.2.1 cliff }
329 1.1.2.1 cliff
330 1.1.2.1 cliff /*
331 1.1.2.1 cliff * Initialize error message buffer (at end of core).
332 1.1.2.1 cliff */
333 1.1.2.1 cliff mips_init_msgbuf();
334 1.1.2.1 cliff
335 1.1.2.1 cliff pmap_bootstrap();
336 1.1.2.1 cliff
337 1.1.2.1 cliff /*
338 1.1.2.1 cliff * Allocate space for proc0's USPACE.
339 1.1.2.1 cliff */
340 1.1.2.1 cliff v = (void *)uvm_pageboot_alloc(USPACE);
341 1.1.2.1 cliff lwp0.l_addr = proc0paddr = (struct user *)v;
342 1.1.2.1 cliff lwp0.l_md.md_regs = (struct frame *)((char *)v + USPACE) - 1;
343 1.1.2.1 cliff #ifdef _LP64
344 1.1.2.1 cliff lwp0.l_md.md_regs->f_regs[_R_SR] = MIPS_SR_KX;
345 1.1.2.1 cliff #endif
346 1.1.2.1 cliff proc0paddr->u_pcb.pcb_context.val[_L_SR] =
347 1.1.2.1 cliff #ifdef _LP64
348 1.1.2.1 cliff MIPS_SR_KX |
349 1.1.2.1 cliff #endif
350 1.1.2.1 cliff MIPS_INT_MASK | MIPS_SR_INT_IE; /* SR */
351 1.1.2.1 cliff
352 1.1.2.1 cliff
353 1.1.2.1 cliff /*
354 1.1.2.1 cliff * Initialize debuggers, and break into them, if appropriate.
355 1.1.2.1 cliff */
356 1.1.2.1 cliff #if NKSYMS || defined(DDB) || defined(LKM)
357 1.1.2.1 cliff ksyms_init(0, 0, 0);
358 1.1.2.1 cliff #endif
359 1.1.2.1 cliff
360 1.1.2.1 cliff #if defined(DDB)
361 1.1.2.1 cliff if (boothowto & RB_KDB)
362 1.1.2.1 cliff Debugger();
363 1.1.2.1 cliff #endif
364 1.1.2.1 cliff
365 1.1.2.1 cliff }
366 1.1.2.1 cliff
367 1.1.2.1 cliff static u_long
368 1.1.2.1 cliff rmixlfw_init(void *infop)
369 1.1.2.1 cliff {
370 1.1.2.1 cliff uint64_t tmp;
371 1.1.2.1 cliff uint64_t sz;
372 1.1.2.1 cliff uint64_t sum;
373 1.1.2.1 cliff #ifdef MEMSIZE
374 1.1.2.1 cliff u_long memsize = MEMSIZE;
375 1.1.2.1 cliff #endif
376 1.1.2.1 cliff
377 1.1.2.1 cliff strcpy(cpu_model, "RMI XLS616ATX VIIA"); /* XXX */
378 1.1.2.1 cliff
379 1.1.2.1 cliff tmp = (int64_t)infop;
380 1.1.2.1 cliff tmp |= 0xffffffffULL << 32;
381 1.1.2.1 cliff infop = (void *)tmp;
382 1.1.2.1 cliff rmixlfw_info = *(rmixlfw_info_t *)infop;
383 1.1.2.1 cliff
384 1.1.2.1 cliff for (int i=0; i < RMICLFW_PSB_VERSIONS_LEN; i++) {
385 1.1.2.1 cliff if (rmiclfw_psb_versions[i] == rmixlfw_info.psb_version)
386 1.1.2.1 cliff goto found;
387 1.1.2.1 cliff }
388 1.1.2.1 cliff
389 1.1.2.2 cliff rmixl_putchar_init(MIPS_KSEG1_TO_PHYS(rmixlfw_info.io_base));
390 1.1.2.1 cliff rmixl_puts("\r\nWARNING: untested psb_version: ");
391 1.1.2.1 cliff rmixl_puthex64(rmixlfw_info.psb_version);
392 1.1.2.1 cliff rmixl_puts("\r\n");
393 1.1.2.1 cliff found:
394 1.1.2.1 cliff
395 1.1.2.1 cliff rmixlfw_phys_mmap = *(rmixlfw_mmap_t *)rmixlfw_info.psb_physaddr_map;
396 1.1.2.1 cliff rmixlfw_avail_mmap = *(rmixlfw_mmap_t *)rmixlfw_info.avail_mem_map;
397 1.1.2.1 cliff
398 1.1.2.1 cliff sum = 0;
399 1.1.2.1 cliff mem_cluster_cnt = 0;
400 1.1.2.1 cliff for (uint32_t i=0; i < rmixlfw_avail_mmap.nmmaps; i++) {
401 1.1.2.1 cliff if (rmixlfw_avail_mmap.entry[i].type != RMIXLFW_MMAP_TYPE_RAM)
402 1.1.2.1 cliff continue;
403 1.1.2.1 cliff mem_clusters[i].start = rmixlfw_avail_mmap.entry[i].start;
404 1.1.2.1 cliff sz = rmixlfw_avail_mmap.entry[i].size;
405 1.1.2.1 cliff sum += sz;
406 1.1.2.1 cliff mem_clusters[i].size = sz;
407 1.1.2.1 cliff mem_cluster_cnt++;
408 1.1.2.1 cliff #ifdef DEBUG
409 1.1.2.1 cliff rmixl_puthex32(i);
410 1.1.2.1 cliff rmixl_puts(": ");
411 1.1.2.1 cliff rmixl_puthex64(mem_clusters[i].start);
412 1.1.2.1 cliff rmixl_puts(": ");
413 1.1.2.1 cliff rmixl_puthex64(sz);
414 1.1.2.1 cliff rmixl_puts(": ");
415 1.1.2.1 cliff rmixl_puthex64(sum);
416 1.1.2.1 cliff rmixl_puts("\r\n");
417 1.1.2.1 cliff #endif
418 1.1.2.1 cliff #ifdef MEMSIZE
419 1.1.2.1 cliff /*
420 1.1.2.1 cliff * configurably limit memsize
421 1.1.2.1 cliff */
422 1.1.2.1 cliff if (sum == memsize)
423 1.1.2.1 cliff break;
424 1.1.2.1 cliff if (sum > memsize) {
425 1.1.2.1 cliff tmp = sum - memsize;
426 1.1.2.1 cliff sz -= tmp;
427 1.1.2.1 cliff sum -= tmp;
428 1.1.2.1 cliff mem_clusters[i].size = sz;
429 1.1.2.1 cliff break;
430 1.1.2.1 cliff }
431 1.1.2.1 cliff #endif
432 1.1.2.1 cliff }
433 1.1.2.1 cliff return sum;
434 1.1.2.1 cliff }
435 1.1.2.1 cliff
436 1.1.2.1 cliff void
437 1.1.2.1 cliff consinit(void)
438 1.1.2.1 cliff {
439 1.1.2.1 cliff
440 1.1.2.1 cliff /*
441 1.1.2.1 cliff * Everything related to console initialization is done
442 1.1.2.1 cliff * in mach_init().
443 1.1.2.1 cliff */
444 1.1.2.1 cliff }
445 1.1.2.1 cliff
446 1.1.2.1 cliff /*
447 1.1.2.1 cliff * Allocate memory for variable-sized tables,
448 1.1.2.1 cliff */
449 1.1.2.1 cliff void
450 1.1.2.1 cliff cpu_startup()
451 1.1.2.1 cliff {
452 1.1.2.1 cliff vaddr_t minaddr, maxaddr;
453 1.1.2.1 cliff char pbuf[9];
454 1.1.2.1 cliff
455 1.1.2.1 cliff /*
456 1.1.2.1 cliff * Good {morning,afternoon,evening,night}.
457 1.1.2.1 cliff */
458 1.1.2.1 cliff printf("%s%s", copyright, version);
459 1.1.2.1 cliff format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
460 1.1.2.1 cliff printf("total memory = %s\n", pbuf);
461 1.1.2.1 cliff
462 1.1.2.1 cliff /*
463 1.1.2.1 cliff * Virtual memory is bootstrapped -- notify the bus spaces
464 1.1.2.1 cliff * that memory allocation is now safe.
465 1.1.2.1 cliff */
466 1.1.2.1 cliff rmixl_configuration.rc_mallocsafe = 1;
467 1.1.2.1 cliff
468 1.1.2.1 cliff minaddr = 0;
469 1.1.2.1 cliff /*
470 1.1.2.1 cliff * Allocate a submap for physio.
471 1.1.2.1 cliff */
472 1.1.2.1 cliff phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
473 1.1.2.1 cliff VM_PHYS_SIZE, 0, FALSE, NULL);
474 1.1.2.1 cliff
475 1.1.2.1 cliff /*
476 1.1.2.1 cliff * (No need to allocate an mbuf cluster submap. Mbuf clusters
477 1.1.2.1 cliff * are allocated via the pool allocator, and we use KSEG to
478 1.1.2.1 cliff * map those pages.)
479 1.1.2.1 cliff */
480 1.1.2.1 cliff
481 1.1.2.1 cliff format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
482 1.1.2.1 cliff printf("avail memory = %s\n", pbuf);
483 1.1.2.1 cliff }
484 1.1.2.1 cliff
485 1.1.2.1 cliff int waittime = -1;
486 1.1.2.1 cliff
487 1.1.2.1 cliff void
488 1.1.2.1 cliff cpu_reboot(howto, bootstr)
489 1.1.2.1 cliff int howto;
490 1.1.2.1 cliff char *bootstr;
491 1.1.2.1 cliff {
492 1.1.2.1 cliff
493 1.1.2.1 cliff /* Take a snapshot before clobbering any registers. */
494 1.1.2.1 cliff if (curproc)
495 1.1.2.1 cliff savectx((struct user *)curpcb);
496 1.1.2.1 cliff
497 1.1.2.1 cliff if (cold) {
498 1.1.2.1 cliff howto |= RB_HALT;
499 1.1.2.1 cliff goto haltsys;
500 1.1.2.1 cliff }
501 1.1.2.1 cliff
502 1.1.2.1 cliff /* If "always halt" was specified as a boot flag, obey. */
503 1.1.2.1 cliff if (boothowto & RB_HALT)
504 1.1.2.1 cliff howto |= RB_HALT;
505 1.1.2.1 cliff
506 1.1.2.1 cliff boothowto = howto;
507 1.1.2.1 cliff if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) {
508 1.1.2.1 cliff waittime = 0;
509 1.1.2.1 cliff vfs_shutdown();
510 1.1.2.1 cliff
511 1.1.2.1 cliff /*
512 1.1.2.1 cliff * If we've been adjusting the clock, the todr
513 1.1.2.1 cliff * will be out of synch; adjust it now.
514 1.1.2.1 cliff */
515 1.1.2.1 cliff resettodr();
516 1.1.2.1 cliff }
517 1.1.2.1 cliff
518 1.1.2.1 cliff splhigh();
519 1.1.2.1 cliff
520 1.1.2.1 cliff if (howto & RB_DUMP)
521 1.1.2.1 cliff dumpsys();
522 1.1.2.1 cliff
523 1.1.2.1 cliff haltsys:
524 1.1.2.1 cliff doshutdownhooks();
525 1.1.2.1 cliff
526 1.1.2.1 cliff if (howto & RB_HALT) {
527 1.1.2.1 cliff printf("\n");
528 1.1.2.1 cliff printf("The operating system has halted.\n");
529 1.1.2.1 cliff printf("Please press any key to reboot.\n\n");
530 1.1.2.1 cliff cnpollc(1); /* For proper keyboard command handling */
531 1.1.2.1 cliff cngetc();
532 1.1.2.1 cliff cnpollc(0);
533 1.1.2.1 cliff }
534 1.1.2.1 cliff
535 1.1.2.1 cliff printf("rebooting...\n\n");
536 1.1.2.1 cliff
537 1.1.2.1 cliff rmixl_exit(0);
538 1.1.2.1 cliff }
539 1.1.2.1 cliff
540 1.1.2.1 cliff /*
541 1.1.2.1 cliff * goodbye world
542 1.1.2.1 cliff */
543 1.1.2.1 cliff #define GPIO_CPU_RST 0xa0 /* XXX TMP */
544 1.1.2.1 cliff void __attribute__((__noreturn__))
545 1.1.2.1 cliff rmixl_exit(int howto)
546 1.1.2.1 cliff {
547 1.1.2.1 cliff /* use firmware callbak to reboot */
548 1.1.2.1 cliff void (*reset)(void) = (void *)rmixlfw_info.warm_reset;
549 1.1.2.1 cliff (*reset)();
550 1.1.2.1 cliff printf("warm reset callback failed, spinning...\n");
551 1.1.2.1 cliff for (;;);
552 1.1.2.1 cliff }
553