machdep.c revision 1.4.2.3 1 1.4.2.3 skrll /* $NetBSD: machdep.c,v 1.4.2.3 2015/09/22 12:05:41 skrll Exp $ */
2 1.4.2.2 skrll
3 1.4.2.2 skrll /*
4 1.4.2.2 skrll * Copyright 2001, 2002 Wasabi Systems, Inc.
5 1.4.2.2 skrll * All rights reserved.
6 1.4.2.2 skrll *
7 1.4.2.2 skrll * Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc.
8 1.4.2.2 skrll *
9 1.4.2.2 skrll * Redistribution and use in source and binary forms, with or without
10 1.4.2.2 skrll * modification, are permitted provided that the following conditions
11 1.4.2.2 skrll * are met:
12 1.4.2.2 skrll * 1. Redistributions of source code must retain the above copyright
13 1.4.2.2 skrll * notice, this list of conditions and the following disclaimer.
14 1.4.2.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
15 1.4.2.2 skrll * notice, this list of conditions and the following disclaimer in the
16 1.4.2.2 skrll * documentation and/or other materials provided with the distribution.
17 1.4.2.2 skrll * 3. All advertising materials mentioning features or use of this software
18 1.4.2.2 skrll * must display the following acknowledgement:
19 1.4.2.2 skrll * This product includes software developed for the NetBSD Project by
20 1.4.2.2 skrll * Wasabi Systems, Inc.
21 1.4.2.2 skrll * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.4.2.2 skrll * or promote products derived from this software without specific prior
23 1.4.2.2 skrll * written permission.
24 1.4.2.2 skrll *
25 1.4.2.2 skrll * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.4.2.2 skrll * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.4.2.2 skrll * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.4.2.2 skrll * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.4.2.2 skrll * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.4.2.2 skrll * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.4.2.2 skrll * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.4.2.2 skrll * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.4.2.2 skrll * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.4.2.2 skrll * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.4.2.2 skrll * POSSIBILITY OF SUCH DAMAGE.
36 1.4.2.2 skrll */
37 1.4.2.2 skrll
38 1.4.2.2 skrll /*
39 1.4.2.2 skrll * Copyright (c) 1992, 1993
40 1.4.2.2 skrll * The Regents of the University of California. All rights reserved.
41 1.4.2.2 skrll *
42 1.4.2.2 skrll * This code is derived from software contributed to Berkeley by
43 1.4.2.2 skrll * the Systems Programming Group of the University of Utah Computer
44 1.4.2.2 skrll * Science Department, The Mach Operating System project at
45 1.4.2.2 skrll * Carnegie-Mellon University and Ralph Campbell.
46 1.4.2.2 skrll *
47 1.4.2.2 skrll * Redistribution and use in source and binary forms, with or without
48 1.4.2.2 skrll * modification, are permitted provided that the following conditions
49 1.4.2.2 skrll * are met:
50 1.4.2.2 skrll * 1. Redistributions of source code must retain the above copyright
51 1.4.2.2 skrll * notice, this list of conditions and the following disclaimer.
52 1.4.2.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
53 1.4.2.2 skrll * notice, this list of conditions and the following disclaimer in the
54 1.4.2.2 skrll * documentation and/or other materials provided with the distribution.
55 1.4.2.2 skrll * 3. Neither the name of the University nor the names of its contributors
56 1.4.2.2 skrll * may be used to endorse or promote products derived from this software
57 1.4.2.2 skrll * without specific prior written permission.
58 1.4.2.2 skrll *
59 1.4.2.2 skrll * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 1.4.2.2 skrll * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 1.4.2.2 skrll * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 1.4.2.2 skrll * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 1.4.2.2 skrll * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 1.4.2.2 skrll * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 1.4.2.2 skrll * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 1.4.2.2 skrll * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 1.4.2.2 skrll * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 1.4.2.2 skrll * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 1.4.2.2 skrll * SUCH DAMAGE.
70 1.4.2.2 skrll *
71 1.4.2.2 skrll * @(#)machdep.c 8.3 (Berkeley) 1/12/94
72 1.4.2.2 skrll * from: Utah Hdr: machdep.c 1.63 91/04/24
73 1.4.2.2 skrll */
74 1.4.2.2 skrll /*
75 1.4.2.2 skrll * Copyright (c) 1988 University of Utah.
76 1.4.2.2 skrll *
77 1.4.2.2 skrll * This code is derived from software contributed to Berkeley by
78 1.4.2.2 skrll * the Systems Programming Group of the University of Utah Computer
79 1.4.2.2 skrll * Science Department, The Mach Operating System project at
80 1.4.2.2 skrll * Carnegie-Mellon University and Ralph Campbell.
81 1.4.2.2 skrll *
82 1.4.2.2 skrll * Redistribution and use in source and binary forms, with or without
83 1.4.2.2 skrll * modification, are permitted provided that the following conditions
84 1.4.2.2 skrll * are met:
85 1.4.2.2 skrll * 1. Redistributions of source code must retain the above copyright
86 1.4.2.2 skrll * notice, this list of conditions and the following disclaimer.
87 1.4.2.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
88 1.4.2.2 skrll * notice, this list of conditions and the following disclaimer in the
89 1.4.2.2 skrll * documentation and/or other materials provided with the distribution.
90 1.4.2.2 skrll * 3. All advertising materials mentioning features or use of this software
91 1.4.2.2 skrll * must display the following acknowledgement:
92 1.4.2.2 skrll * This product includes software developed by the University of
93 1.4.2.2 skrll * California, Berkeley and its contributors.
94 1.4.2.2 skrll * 4. Neither the name of the University nor the names of its contributors
95 1.4.2.2 skrll * may be used to endorse or promote products derived from this software
96 1.4.2.2 skrll * without specific prior written permission.
97 1.4.2.2 skrll *
98 1.4.2.2 skrll * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
99 1.4.2.2 skrll * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
100 1.4.2.2 skrll * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
101 1.4.2.2 skrll * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
102 1.4.2.2 skrll * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
103 1.4.2.2 skrll * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
104 1.4.2.2 skrll * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
105 1.4.2.2 skrll * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
106 1.4.2.2 skrll * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
107 1.4.2.2 skrll * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
108 1.4.2.2 skrll * SUCH DAMAGE.
109 1.4.2.2 skrll *
110 1.4.2.2 skrll * @(#)machdep.c 8.3 (Berkeley) 1/12/94
111 1.4.2.2 skrll * from: Utah Hdr: machdep.c 1.63 91/04/24
112 1.4.2.2 skrll */
113 1.4.2.2 skrll
114 1.4.2.3 skrll #include "opt_multiprocessor.h"
115 1.4.2.3 skrll
116 1.4.2.2 skrll #include <sys/cdefs.h>
117 1.4.2.3 skrll __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.4.2.3 2015/09/22 12:05:41 skrll Exp $");
118 1.4.2.2 skrll
119 1.4.2.2 skrll #include <sys/param.h>
120 1.4.2.2 skrll #include <sys/systm.h>
121 1.4.2.2 skrll #include <sys/kernel.h>
122 1.4.2.2 skrll #include <sys/buf.h>
123 1.4.2.2 skrll #include <sys/cpu.h>
124 1.4.2.2 skrll #include <sys/reboot.h>
125 1.4.2.2 skrll #include <sys/mount.h>
126 1.4.2.2 skrll #include <sys/kcore.h>
127 1.4.2.2 skrll #include <sys/boot_flag.h>
128 1.4.2.2 skrll #include <sys/termios.h>
129 1.4.2.2 skrll #include <sys/ksyms.h>
130 1.4.2.2 skrll
131 1.4.2.2 skrll #include <uvm/uvm_extern.h>
132 1.4.2.2 skrll
133 1.4.2.2 skrll #include <dev/cons.h>
134 1.4.2.2 skrll
135 1.4.2.2 skrll #include "ksyms.h"
136 1.4.2.2 skrll
137 1.4.2.2 skrll #if NKSYMS || defined(DDB) || defined(LKM)
138 1.4.2.2 skrll #include <machine/db_machdep.h>
139 1.4.2.2 skrll #include <ddb/db_extern.h>
140 1.4.2.2 skrll #endif
141 1.4.2.2 skrll
142 1.4.2.2 skrll #include <machine/psl.h>
143 1.4.2.2 skrll #include <machine/locore.h>
144 1.4.2.2 skrll
145 1.4.2.2 skrll #include <mips/cavium/autoconf.h>
146 1.4.2.2 skrll #include <mips/cavium/octeonvar.h>
147 1.4.2.2 skrll #include <mips/cavium/include/iobusvar.h>
148 1.4.2.2 skrll #include <mips/cavium/include/bootbusvar.h>
149 1.4.2.2 skrll
150 1.4.2.2 skrll #include <mips/cavium/dev/octeon_uartreg.h>
151 1.4.2.2 skrll #include <mips/cavium/dev/octeon_ciureg.h>
152 1.4.2.2 skrll #include <mips/cavium/dev/octeon_gpioreg.h>
153 1.4.2.2 skrll
154 1.4.2.2 skrll #include <evbmips/cavium/octeon_uboot.h>
155 1.4.2.2 skrll
156 1.4.2.2 skrll static void mach_init_bss(void);
157 1.4.2.2 skrll static void mach_init_vector(void);
158 1.4.2.2 skrll static void mach_init_bus_space(void);
159 1.4.2.2 skrll static void mach_init_console(void);
160 1.4.2.2 skrll static void mach_init_memory(u_quad_t);
161 1.4.2.2 skrll
162 1.4.2.2 skrll #include "com.h"
163 1.4.2.2 skrll #if NCOM > 0
164 1.4.2.2 skrll #include <dev/ic/comreg.h>
165 1.4.2.2 skrll #include <dev/ic/comvar.h>
166 1.4.2.2 skrll int comcnrate = 115200; /* XXX should be config option */
167 1.4.2.2 skrll #endif /* NCOM > 0 */
168 1.4.2.2 skrll
169 1.4.2.2 skrll /* Maps for VM objects. */
170 1.4.2.2 skrll struct vm_map *phys_map = NULL;
171 1.4.2.2 skrll
172 1.4.2.2 skrll int netboot;
173 1.4.2.2 skrll
174 1.4.2.2 skrll phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
175 1.4.2.2 skrll int mem_cluster_cnt;
176 1.4.2.2 skrll
177 1.4.2.2 skrll void mach_init(uint64_t, uint64_t, uint64_t, uint64_t);
178 1.4.2.2 skrll
179 1.4.2.2 skrll struct octeon_config octeon_configuration;
180 1.4.2.2 skrll struct octeon_btinfo octeon_btinfo;
181 1.4.2.2 skrll
182 1.4.2.2 skrll /*
183 1.4.2.2 skrll * Do all the stuff that locore normally does before calling main().
184 1.4.2.2 skrll */
185 1.4.2.2 skrll void
186 1.4.2.2 skrll mach_init(uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3)
187 1.4.2.2 skrll {
188 1.4.2.2 skrll uint64_t btinfo_paddr;
189 1.4.2.2 skrll u_quad_t memsize;
190 1.4.2.2 skrll int corefreq;
191 1.4.2.2 skrll
192 1.4.2.2 skrll mach_init_bss();
193 1.4.2.2 skrll
194 1.4.2.2 skrll KASSERT(MIPS_XKPHYS_P(arg3));
195 1.4.2.2 skrll btinfo_paddr = mips64_ld_a64(arg3 + OCTEON_BTINFO_PADDR_OFFSET);
196 1.4.2.2 skrll
197 1.4.2.2 skrll /* Should be in first 256MB segment */
198 1.4.2.2 skrll KASSERT(btinfo_paddr < 256 * 1024 * 1024);
199 1.4.2.2 skrll memcpy(&octeon_btinfo,
200 1.4.2.2 skrll (struct octeon_btinfo *)MIPS_PHYS_TO_KSEG0(btinfo_paddr),
201 1.4.2.2 skrll sizeof(octeon_btinfo));
202 1.4.2.2 skrll
203 1.4.2.2 skrll corefreq = octeon_btinfo.obt_eclock_hz;
204 1.4.2.2 skrll memsize = octeon_btinfo.obt_dram_size * 1024 * 1024;
205 1.4.2.2 skrll
206 1.4.2.2 skrll octeon_cal_timer(corefreq);
207 1.4.2.2 skrll
208 1.4.2.2 skrll switch (MIPS_PRID_IMPL(mips_options.mips_cpu_id)) {
209 1.4.2.2 skrll case 0: cpu_setmodel("Cavium Octeon CN38XX/CN36XX"); break;
210 1.4.2.2 skrll case 1: cpu_setmodel("Cavium Octeon CN31XX/CN3020"); break;
211 1.4.2.2 skrll case 2: cpu_setmodel("Cavium Octeon CN3005/CN3010"); break;
212 1.4.2.2 skrll case 3: cpu_setmodel("Cavium Octeon CN58XX"); break;
213 1.4.2.2 skrll case 4: cpu_setmodel("Cavium Octeon CN5[4-7]XX"); break;
214 1.4.2.2 skrll case 6: cpu_setmodel("Cavium Octeon CN50XX"); break;
215 1.4.2.2 skrll case 7: cpu_setmodel("Cavium Octeon CN52XX"); break;
216 1.4.2.2 skrll default: cpu_setmodel("Cavium Octeon"); break;
217 1.4.2.2 skrll }
218 1.4.2.3 skrll
219 1.4.2.2 skrll mach_init_vector();
220 1.4.2.2 skrll
221 1.4.2.2 skrll /* set the VM page size */
222 1.4.2.2 skrll uvm_setpagesize();
223 1.4.2.2 skrll
224 1.4.2.2 skrll mach_init_bus_space();
225 1.4.2.2 skrll
226 1.4.2.2 skrll mach_init_console();
227 1.4.2.2 skrll
228 1.4.2.2 skrll mach_init_memory(memsize);
229 1.4.2.2 skrll
230 1.4.2.2 skrll /*
231 1.4.2.2 skrll * Allocate uarea page for lwp0 and set it.
232 1.4.2.2 skrll */
233 1.4.2.2 skrll mips_init_lwp0_uarea();
234 1.4.2.2 skrll
235 1.4.2.2 skrll boothowto = RB_AUTOBOOT;
236 1.4.2.3 skrll boothowto |= AB_VERBOSE;
237 1.4.2.2 skrll
238 1.4.2.2 skrll #if defined(DDB)
239 1.4.2.2 skrll if (boothowto & RB_KDB)
240 1.4.2.2 skrll Debugger();
241 1.4.2.2 skrll #endif
242 1.4.2.2 skrll }
243 1.4.2.2 skrll
244 1.4.2.2 skrll void
245 1.4.2.2 skrll consinit(void)
246 1.4.2.2 skrll {
247 1.4.2.2 skrll
248 1.4.2.2 skrll /*
249 1.4.2.2 skrll * Everything related to console initialization is done
250 1.4.2.2 skrll * in mach_init().
251 1.4.2.2 skrll */
252 1.4.2.2 skrll }
253 1.4.2.2 skrll
254 1.4.2.2 skrll void
255 1.4.2.2 skrll mach_init_bss(void)
256 1.4.2.2 skrll {
257 1.4.2.2 skrll extern char edata[], end[];
258 1.4.2.2 skrll
259 1.4.2.2 skrll /*
260 1.4.2.2 skrll * Clear the BSS segment.
261 1.4.2.2 skrll */
262 1.4.2.2 skrll memset(edata, 0, mips_round_page(end) - (uintptr_t)edata);
263 1.4.2.2 skrll }
264 1.4.2.2 skrll
265 1.4.2.2 skrll void
266 1.4.2.2 skrll mach_init_vector(void)
267 1.4.2.2 skrll {
268 1.4.2.2 skrll
269 1.4.2.2 skrll /* Make sure exception base at 0 (MIPS_COP_0_EBASE) */
270 1.4.2.3 skrll __asm __volatile("mtc0 %0, $15, 1" : : "r"(0x80000000) );
271 1.4.2.2 skrll
272 1.4.2.2 skrll /*
273 1.4.2.2 skrll * Set up the exception vectors and CPU-specific function
274 1.4.2.2 skrll * vectors early on. We need the wbflush() vector set up
275 1.4.2.2 skrll * before comcnattach() is called (or at least before the
276 1.4.2.2 skrll * first printf() after that is called).
277 1.4.2.2 skrll * Also clears the I+D caches.
278 1.4.2.2 skrll */
279 1.4.2.2 skrll mips_vector_init(NULL, true);
280 1.4.2.2 skrll }
281 1.4.2.2 skrll
282 1.4.2.2 skrll void
283 1.4.2.2 skrll mach_init_bus_space(void)
284 1.4.2.2 skrll {
285 1.4.2.2 skrll struct octeon_config *mcp = &octeon_configuration;
286 1.4.2.2 skrll
287 1.4.2.2 skrll octeon_dma_init(mcp);
288 1.4.2.2 skrll
289 1.4.2.2 skrll iobus_bootstrap(mcp);
290 1.4.2.2 skrll bootbus_bootstrap(mcp);
291 1.4.2.2 skrll }
292 1.4.2.2 skrll
293 1.4.2.2 skrll void
294 1.4.2.2 skrll mach_init_console(void)
295 1.4.2.2 skrll {
296 1.4.2.2 skrll #if NCOM > 0
297 1.4.2.2 skrll struct octeon_config *mcp = &octeon_configuration;
298 1.4.2.2 skrll int status;
299 1.4.2.2 skrll extern int octeon_uart_com_cnattach(bus_space_tag_t, int, int);
300 1.4.2.2 skrll
301 1.4.2.2 skrll /*
302 1.4.2.2 skrll * Delay to allow firmware putchars to complete.
303 1.4.2.2 skrll * FIFO depth * character time.
304 1.4.2.2 skrll * character time = (1000000 / (defaultrate / 10))
305 1.4.2.2 skrll */
306 1.4.2.2 skrll delay(640000000 / comcnrate);
307 1.4.2.2 skrll
308 1.4.2.2 skrll status = octeon_uart_com_cnattach(
309 1.4.2.2 skrll &mcp->mc_iobus_bust,
310 1.4.2.2 skrll 0, /* XXX port 0 */
311 1.4.2.2 skrll comcnrate);
312 1.4.2.2 skrll if (status != 0)
313 1.4.2.2 skrll panic("can't initialize console!"); /* XXX print to nowhere! */
314 1.4.2.2 skrll #else
315 1.4.2.2 skrll panic("octeon: not configured to use serial console");
316 1.4.2.2 skrll #endif /* NCOM > 0 */
317 1.4.2.2 skrll }
318 1.4.2.2 skrll
319 1.4.2.2 skrll void
320 1.4.2.2 skrll mach_init_memory(u_quad_t memsize)
321 1.4.2.2 skrll {
322 1.4.2.2 skrll extern char kernel_text[];
323 1.4.2.2 skrll extern char end[];
324 1.4.2.2 skrll
325 1.4.2.2 skrll physmem = btoc(memsize);
326 1.4.2.2 skrll
327 1.4.2.2 skrll if (memsize <= 256 * 1024 * 1024) {
328 1.4.2.2 skrll mem_clusters[0].start = 0;
329 1.4.2.2 skrll mem_clusters[0].size = memsize;
330 1.4.2.2 skrll mem_cluster_cnt = 1;
331 1.4.2.2 skrll } else if (memsize <= 512 * 1024 * 1024) {
332 1.4.2.2 skrll mem_clusters[0].start = 0;
333 1.4.2.2 skrll mem_clusters[0].size = 256 * 1024 * 1024;
334 1.4.2.2 skrll mem_clusters[1].start = 0x410000000ULL;
335 1.4.2.2 skrll mem_clusters[1].size = memsize - 256 * 1024 * 1024;
336 1.4.2.2 skrll mem_cluster_cnt = 2;
337 1.4.2.2 skrll } else {
338 1.4.2.2 skrll mem_clusters[0].start = 0;
339 1.4.2.2 skrll mem_clusters[0].size = 256 * 1024 * 1024;
340 1.4.2.2 skrll mem_clusters[1].start = 0x20000000;
341 1.4.2.2 skrll mem_clusters[1].size = memsize - 512 * 1024 * 1024;
342 1.4.2.2 skrll mem_clusters[2].start = 0x410000000ULL;
343 1.4.2.2 skrll mem_clusters[2].size = 256 * 1024 * 1024;
344 1.4.2.2 skrll mem_cluster_cnt = 3;
345 1.4.2.2 skrll }
346 1.4.2.2 skrll
347 1.4.2.3 skrll
348 1.4.2.2 skrll #ifdef MULTIPROCESSOR
349 1.4.2.2 skrll const u_int cores = mipsNN_cp0_ebase_read() & MIPS_EBASE_CPUNUM;
350 1.4.2.2 skrll mem_clusters[0].start = cores * 4096;
351 1.4.2.2 skrll #endif
352 1.4.2.2 skrll
353 1.4.2.2 skrll /*
354 1.4.2.2 skrll * Load the rest of the available pages into the VM system.
355 1.4.2.2 skrll */
356 1.4.2.2 skrll mips_page_physload(mips_trunc_page(kernel_text), mips_round_page(end),
357 1.4.2.2 skrll mem_clusters, mem_cluster_cnt, NULL, 0);
358 1.4.2.2 skrll
359 1.4.2.2 skrll /*
360 1.4.2.2 skrll * Initialize error message buffer (at end of core).
361 1.4.2.2 skrll */
362 1.4.2.2 skrll mips_init_msgbuf();
363 1.4.2.2 skrll
364 1.4.2.2 skrll pmap_bootstrap();
365 1.4.2.2 skrll }
366 1.4.2.2 skrll
367 1.4.2.2 skrll /*
368 1.4.2.2 skrll * cpu_startup
369 1.4.2.2 skrll * cpu_reboot
370 1.4.2.2 skrll */
371 1.4.2.2 skrll
372 1.4.2.2 skrll int waittime = -1;
373 1.4.2.2 skrll
374 1.4.2.2 skrll /*
375 1.4.2.2 skrll * Allocate memory for variable-sized tables,
376 1.4.2.2 skrll */
377 1.4.2.2 skrll void
378 1.4.2.2 skrll cpu_startup(void)
379 1.4.2.2 skrll {
380 1.4.2.3 skrll #ifdef MULTIPROCESSOR
381 1.4.2.3 skrll // Create a kcpuset so we can see on which CPUs the kernel was started.
382 1.4.2.3 skrll kcpuset_create(&cpus_booted, true);
383 1.4.2.3 skrll #endif
384 1.4.2.3 skrll
385 1.4.2.2 skrll /*
386 1.4.2.2 skrll * Do the common startup items.
387 1.4.2.2 skrll */
388 1.4.2.2 skrll cpu_startup_common();
389 1.4.2.2 skrll
390 1.4.2.2 skrll /*
391 1.4.2.2 skrll * Virtual memory is bootstrapped -- notify the bus spaces
392 1.4.2.2 skrll * that memory allocation is now safe.
393 1.4.2.2 skrll */
394 1.4.2.2 skrll octeon_configuration.mc_mallocsafe = 1;
395 1.4.2.2 skrll }
396 1.4.2.2 skrll
397 1.4.2.2 skrll void
398 1.4.2.2 skrll cpu_reboot(int howto, char *bootstr)
399 1.4.2.2 skrll {
400 1.4.2.2 skrll
401 1.4.2.2 skrll /* Take a snapshot before clobbering any registers. */
402 1.4.2.2 skrll savectx(curpcb);
403 1.4.2.2 skrll
404 1.4.2.2 skrll if (cold) {
405 1.4.2.2 skrll howto |= RB_HALT;
406 1.4.2.2 skrll goto haltsys;
407 1.4.2.2 skrll }
408 1.4.2.2 skrll
409 1.4.2.2 skrll /* If "always halt" was specified as a boot flag, obey. */
410 1.4.2.2 skrll if (boothowto & RB_HALT)
411 1.4.2.2 skrll howto |= RB_HALT;
412 1.4.2.2 skrll
413 1.4.2.2 skrll boothowto = howto;
414 1.4.2.2 skrll if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) {
415 1.4.2.2 skrll waittime = 0;
416 1.4.2.2 skrll vfs_shutdown();
417 1.4.2.2 skrll
418 1.4.2.2 skrll /*
419 1.4.2.2 skrll * If we've been adjusting the clock, the todr
420 1.4.2.2 skrll * will be out of synch; adjust it now.
421 1.4.2.2 skrll */
422 1.4.2.2 skrll resettodr();
423 1.4.2.2 skrll }
424 1.4.2.2 skrll
425 1.4.2.2 skrll splhigh();
426 1.4.2.2 skrll
427 1.4.2.2 skrll if (howto & RB_DUMP)
428 1.4.2.2 skrll dumpsys();
429 1.4.2.2 skrll
430 1.4.2.2 skrll haltsys:
431 1.4.2.2 skrll doshutdownhooks();
432 1.4.2.2 skrll
433 1.4.2.2 skrll if (howto & RB_HALT) {
434 1.4.2.2 skrll printf("\n");
435 1.4.2.2 skrll printf("The operating system has halted.\n");
436 1.4.2.2 skrll printf("Please press any key to reboot.\n\n");
437 1.4.2.2 skrll }
438 1.4.2.2 skrll
439 1.4.2.2 skrll printf("%s\n\n", ((howto & RB_HALT) != 0) ? "halted." : "rebooting...");
440 1.4.2.2 skrll
441 1.4.2.2 skrll /*
442 1.4.2.2 skrll * Need a small delay here, otherwise we see the first few characters of
443 1.4.2.2 skrll * the warning below.
444 1.4.2.2 skrll */
445 1.4.2.2 skrll delay(80000);
446 1.4.2.2 skrll
447 1.4.2.2 skrll /* initiate chip soft-reset */
448 1.4.2.2 skrll uint64_t fuse = octeon_read_csr(CIU_FUSE);
449 1.4.2.2 skrll octeon_write_csr(CIU_SOFT_BIST, fuse);
450 1.4.2.2 skrll octeon_read_csr(CIU_SOFT_RST);
451 1.4.2.2 skrll octeon_write_csr(CIU_SOFT_RST, fuse);
452 1.4.2.2 skrll
453 1.4.2.2 skrll delay(1000000);
454 1.4.2.2 skrll
455 1.4.2.2 skrll printf("WARNING: reset failed!\nSpinning...");
456 1.4.2.2 skrll
457 1.4.2.2 skrll for (;;)
458 1.4.2.2 skrll /* spin forever */ ; /* XXX */
459 1.4.2.2 skrll }
460