machdep.c revision 1.4.2.6 1 1.4.2.6 skrll /* $NetBSD: machdep.c,v 1.4.2.6 2017/02/05 13:40:09 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.6 skrll #include "opt_cavium.h"
116 1.4.2.3 skrll
117 1.4.2.2 skrll #include <sys/cdefs.h>
118 1.4.2.6 skrll __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.4.2.6 2017/02/05 13:40:09 skrll Exp $");
119 1.4.2.2 skrll
120 1.4.2.2 skrll #include <sys/param.h>
121 1.4.2.2 skrll #include <sys/systm.h>
122 1.4.2.2 skrll #include <sys/kernel.h>
123 1.4.2.2 skrll #include <sys/buf.h>
124 1.4.2.2 skrll #include <sys/cpu.h>
125 1.4.2.2 skrll #include <sys/reboot.h>
126 1.4.2.2 skrll #include <sys/mount.h>
127 1.4.2.2 skrll #include <sys/kcore.h>
128 1.4.2.2 skrll #include <sys/boot_flag.h>
129 1.4.2.2 skrll #include <sys/termios.h>
130 1.4.2.2 skrll #include <sys/ksyms.h>
131 1.4.2.2 skrll
132 1.4.2.2 skrll #include <uvm/uvm_extern.h>
133 1.4.2.2 skrll
134 1.4.2.2 skrll #include <dev/cons.h>
135 1.4.2.2 skrll
136 1.4.2.2 skrll #include "ksyms.h"
137 1.4.2.2 skrll
138 1.4.2.2 skrll #if NKSYMS || defined(DDB) || defined(LKM)
139 1.4.2.2 skrll #include <machine/db_machdep.h>
140 1.4.2.2 skrll #include <ddb/db_extern.h>
141 1.4.2.2 skrll #endif
142 1.4.2.2 skrll
143 1.4.2.2 skrll #include <machine/psl.h>
144 1.4.2.2 skrll #include <machine/locore.h>
145 1.4.2.2 skrll
146 1.4.2.2 skrll #include <mips/cavium/autoconf.h>
147 1.4.2.2 skrll #include <mips/cavium/octeonvar.h>
148 1.4.2.2 skrll #include <mips/cavium/include/iobusvar.h>
149 1.4.2.2 skrll #include <mips/cavium/include/bootbusvar.h>
150 1.4.2.2 skrll
151 1.4.2.2 skrll #include <mips/cavium/dev/octeon_uartreg.h>
152 1.4.2.2 skrll #include <mips/cavium/dev/octeon_ciureg.h>
153 1.4.2.2 skrll #include <mips/cavium/dev/octeon_gpioreg.h>
154 1.4.2.2 skrll
155 1.4.2.2 skrll #include <evbmips/cavium/octeon_uboot.h>
156 1.4.2.2 skrll
157 1.4.2.2 skrll static void mach_init_bss(void);
158 1.4.2.2 skrll static void mach_init_vector(void);
159 1.4.2.2 skrll static void mach_init_bus_space(void);
160 1.4.2.2 skrll static void mach_init_console(void);
161 1.4.2.2 skrll static void mach_init_memory(u_quad_t);
162 1.4.2.2 skrll
163 1.4.2.2 skrll #include "com.h"
164 1.4.2.2 skrll #if NCOM > 0
165 1.4.2.2 skrll #include <dev/ic/comreg.h>
166 1.4.2.2 skrll #include <dev/ic/comvar.h>
167 1.4.2.2 skrll int comcnrate = 115200; /* XXX should be config option */
168 1.4.2.2 skrll #endif /* NCOM > 0 */
169 1.4.2.2 skrll
170 1.4.2.2 skrll /* Maps for VM objects. */
171 1.4.2.2 skrll struct vm_map *phys_map = NULL;
172 1.4.2.2 skrll
173 1.4.2.2 skrll int netboot;
174 1.4.2.2 skrll
175 1.4.2.2 skrll phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
176 1.4.2.2 skrll int mem_cluster_cnt;
177 1.4.2.2 skrll
178 1.4.2.2 skrll void mach_init(uint64_t, uint64_t, uint64_t, uint64_t);
179 1.4.2.2 skrll
180 1.4.2.2 skrll struct octeon_config octeon_configuration;
181 1.4.2.2 skrll struct octeon_btinfo octeon_btinfo;
182 1.4.2.2 skrll
183 1.4.2.4 skrll char octeon_nmi_stack[PAGE_SIZE] __section(".data1") __aligned(PAGE_SIZE);
184 1.4.2.4 skrll
185 1.4.2.2 skrll /*
186 1.4.2.2 skrll * Do all the stuff that locore normally does before calling main().
187 1.4.2.2 skrll */
188 1.4.2.2 skrll void
189 1.4.2.2 skrll mach_init(uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3)
190 1.4.2.2 skrll {
191 1.4.2.2 skrll uint64_t btinfo_paddr;
192 1.4.2.2 skrll u_quad_t memsize;
193 1.4.2.2 skrll int corefreq;
194 1.4.2.2 skrll
195 1.4.2.2 skrll mach_init_bss();
196 1.4.2.2 skrll
197 1.4.2.2 skrll KASSERT(MIPS_XKPHYS_P(arg3));
198 1.4.2.4 skrll btinfo_paddr = mips3_ld(arg3 + OCTEON_BTINFO_PADDR_OFFSET);
199 1.4.2.2 skrll
200 1.4.2.2 skrll /* Should be in first 256MB segment */
201 1.4.2.2 skrll KASSERT(btinfo_paddr < 256 * 1024 * 1024);
202 1.4.2.2 skrll memcpy(&octeon_btinfo,
203 1.4.2.2 skrll (struct octeon_btinfo *)MIPS_PHYS_TO_KSEG0(btinfo_paddr),
204 1.4.2.2 skrll sizeof(octeon_btinfo));
205 1.4.2.2 skrll
206 1.4.2.2 skrll corefreq = octeon_btinfo.obt_eclock_hz;
207 1.4.2.6 skrll #ifdef OCTEON_MEMSIZE // avoid uvm issue
208 1.4.2.6 skrll memsize = OCTEON_MEMSIZE;
209 1.4.2.6 skrll #else
210 1.4.2.2 skrll memsize = octeon_btinfo.obt_dram_size * 1024 * 1024;
211 1.4.2.6 skrll #endif
212 1.4.2.2 skrll
213 1.4.2.2 skrll octeon_cal_timer(corefreq);
214 1.4.2.2 skrll
215 1.4.2.2 skrll switch (MIPS_PRID_IMPL(mips_options.mips_cpu_id)) {
216 1.4.2.2 skrll case 0: cpu_setmodel("Cavium Octeon CN38XX/CN36XX"); break;
217 1.4.2.2 skrll case 1: cpu_setmodel("Cavium Octeon CN31XX/CN3020"); break;
218 1.4.2.2 skrll case 2: cpu_setmodel("Cavium Octeon CN3005/CN3010"); break;
219 1.4.2.2 skrll case 3: cpu_setmodel("Cavium Octeon CN58XX"); break;
220 1.4.2.2 skrll case 4: cpu_setmodel("Cavium Octeon CN5[4-7]XX"); break;
221 1.4.2.2 skrll case 6: cpu_setmodel("Cavium Octeon CN50XX"); break;
222 1.4.2.2 skrll case 7: cpu_setmodel("Cavium Octeon CN52XX"); break;
223 1.4.2.2 skrll default: cpu_setmodel("Cavium Octeon"); break;
224 1.4.2.2 skrll }
225 1.4.2.3 skrll
226 1.4.2.2 skrll mach_init_vector();
227 1.4.2.2 skrll
228 1.4.2.6 skrll uvm_md_init();
229 1.4.2.2 skrll
230 1.4.2.2 skrll mach_init_bus_space();
231 1.4.2.2 skrll
232 1.4.2.2 skrll mach_init_console();
233 1.4.2.2 skrll
234 1.4.2.2 skrll mach_init_memory(memsize);
235 1.4.2.2 skrll
236 1.4.2.2 skrll /*
237 1.4.2.2 skrll * Allocate uarea page for lwp0 and set it.
238 1.4.2.2 skrll */
239 1.4.2.2 skrll mips_init_lwp0_uarea();
240 1.4.2.2 skrll
241 1.4.2.2 skrll boothowto = RB_AUTOBOOT;
242 1.4.2.3 skrll boothowto |= AB_VERBOSE;
243 1.4.2.2 skrll
244 1.4.2.4 skrll #if 0
245 1.4.2.4 skrll curcpu()->ci_nmi_stack = octeon_nmi_stack + sizeof(octeon_nmi_stack) - sizeof(struct kernframe);
246 1.4.2.4 skrll *(uint64_t *)MIPS_PHYS_TO_KSEG0(0x800) = (intptr_t)octeon_reset_vector;
247 1.4.2.4 skrll const uint64_t wdog_reg = MIPS_PHYS_TO_XKPHYS_UNCACHED(CIU_WDOG0);
248 1.4.2.4 skrll uint64_t wdog = mips3_ld(wdog_reg);
249 1.4.2.4 skrll wdog &= ~(CIU_WDOGX_MODE|CIU_WDOGX_LEN);
250 1.4.2.4 skrll wdog |= __SHIFTIN(3, CIU_WDOGX_MODE);
251 1.4.2.4 skrll wdog |= CIU_WDOGX_LEN; // max period
252 1.4.2.4 skrll mips64_sd_a64(wdog_reg, wdog);
253 1.4.2.4 skrll printf("Watchdog enabled!\n");
254 1.4.2.4 skrll #endif
255 1.4.2.4 skrll
256 1.4.2.2 skrll #if defined(DDB)
257 1.4.2.2 skrll if (boothowto & RB_KDB)
258 1.4.2.2 skrll Debugger();
259 1.4.2.2 skrll #endif
260 1.4.2.2 skrll }
261 1.4.2.2 skrll
262 1.4.2.2 skrll void
263 1.4.2.2 skrll consinit(void)
264 1.4.2.2 skrll {
265 1.4.2.2 skrll
266 1.4.2.2 skrll /*
267 1.4.2.2 skrll * Everything related to console initialization is done
268 1.4.2.2 skrll * in mach_init().
269 1.4.2.2 skrll */
270 1.4.2.2 skrll }
271 1.4.2.2 skrll
272 1.4.2.2 skrll void
273 1.4.2.2 skrll mach_init_bss(void)
274 1.4.2.2 skrll {
275 1.4.2.2 skrll extern char edata[], end[];
276 1.4.2.2 skrll
277 1.4.2.2 skrll /*
278 1.4.2.2 skrll * Clear the BSS segment.
279 1.4.2.2 skrll */
280 1.4.2.2 skrll memset(edata, 0, mips_round_page(end) - (uintptr_t)edata);
281 1.4.2.2 skrll }
282 1.4.2.2 skrll
283 1.4.2.2 skrll void
284 1.4.2.2 skrll mach_init_vector(void)
285 1.4.2.2 skrll {
286 1.4.2.2 skrll
287 1.4.2.2 skrll /* Make sure exception base at 0 (MIPS_COP_0_EBASE) */
288 1.4.2.3 skrll __asm __volatile("mtc0 %0, $15, 1" : : "r"(0x80000000) );
289 1.4.2.2 skrll
290 1.4.2.2 skrll /*
291 1.4.2.2 skrll * Set up the exception vectors and CPU-specific function
292 1.4.2.2 skrll * vectors early on. We need the wbflush() vector set up
293 1.4.2.2 skrll * before comcnattach() is called (or at least before the
294 1.4.2.2 skrll * first printf() after that is called).
295 1.4.2.2 skrll * Also clears the I+D caches.
296 1.4.2.2 skrll */
297 1.4.2.2 skrll mips_vector_init(NULL, true);
298 1.4.2.2 skrll }
299 1.4.2.2 skrll
300 1.4.2.2 skrll void
301 1.4.2.2 skrll mach_init_bus_space(void)
302 1.4.2.2 skrll {
303 1.4.2.2 skrll struct octeon_config *mcp = &octeon_configuration;
304 1.4.2.2 skrll
305 1.4.2.2 skrll octeon_dma_init(mcp);
306 1.4.2.2 skrll
307 1.4.2.2 skrll iobus_bootstrap(mcp);
308 1.4.2.2 skrll bootbus_bootstrap(mcp);
309 1.4.2.2 skrll }
310 1.4.2.2 skrll
311 1.4.2.2 skrll void
312 1.4.2.2 skrll mach_init_console(void)
313 1.4.2.2 skrll {
314 1.4.2.2 skrll #if NCOM > 0
315 1.4.2.2 skrll struct octeon_config *mcp = &octeon_configuration;
316 1.4.2.2 skrll int status;
317 1.4.2.2 skrll extern int octeon_uart_com_cnattach(bus_space_tag_t, int, int);
318 1.4.2.2 skrll
319 1.4.2.2 skrll /*
320 1.4.2.2 skrll * Delay to allow firmware putchars to complete.
321 1.4.2.2 skrll * FIFO depth * character time.
322 1.4.2.2 skrll * character time = (1000000 / (defaultrate / 10))
323 1.4.2.2 skrll */
324 1.4.2.2 skrll delay(640000000 / comcnrate);
325 1.4.2.2 skrll
326 1.4.2.2 skrll status = octeon_uart_com_cnattach(
327 1.4.2.2 skrll &mcp->mc_iobus_bust,
328 1.4.2.2 skrll 0, /* XXX port 0 */
329 1.4.2.2 skrll comcnrate);
330 1.4.2.2 skrll if (status != 0)
331 1.4.2.2 skrll panic("can't initialize console!"); /* XXX print to nowhere! */
332 1.4.2.2 skrll #else
333 1.4.2.2 skrll panic("octeon: not configured to use serial console");
334 1.4.2.2 skrll #endif /* NCOM > 0 */
335 1.4.2.2 skrll }
336 1.4.2.2 skrll
337 1.4.2.2 skrll void
338 1.4.2.2 skrll mach_init_memory(u_quad_t memsize)
339 1.4.2.2 skrll {
340 1.4.2.2 skrll extern char kernel_text[];
341 1.4.2.2 skrll extern char end[];
342 1.4.2.2 skrll
343 1.4.2.2 skrll physmem = btoc(memsize);
344 1.4.2.2 skrll
345 1.4.2.2 skrll if (memsize <= 256 * 1024 * 1024) {
346 1.4.2.2 skrll mem_clusters[0].start = 0;
347 1.4.2.2 skrll mem_clusters[0].size = memsize;
348 1.4.2.2 skrll mem_cluster_cnt = 1;
349 1.4.2.2 skrll } else if (memsize <= 512 * 1024 * 1024) {
350 1.4.2.2 skrll mem_clusters[0].start = 0;
351 1.4.2.2 skrll mem_clusters[0].size = 256 * 1024 * 1024;
352 1.4.2.2 skrll mem_clusters[1].start = 0x410000000ULL;
353 1.4.2.2 skrll mem_clusters[1].size = memsize - 256 * 1024 * 1024;
354 1.4.2.2 skrll mem_cluster_cnt = 2;
355 1.4.2.2 skrll } else {
356 1.4.2.2 skrll mem_clusters[0].start = 0;
357 1.4.2.2 skrll mem_clusters[0].size = 256 * 1024 * 1024;
358 1.4.2.2 skrll mem_clusters[1].start = 0x20000000;
359 1.4.2.2 skrll mem_clusters[1].size = memsize - 512 * 1024 * 1024;
360 1.4.2.2 skrll mem_clusters[2].start = 0x410000000ULL;
361 1.4.2.2 skrll mem_clusters[2].size = 256 * 1024 * 1024;
362 1.4.2.2 skrll mem_cluster_cnt = 3;
363 1.4.2.2 skrll }
364 1.4.2.2 skrll
365 1.4.2.3 skrll
366 1.4.2.2 skrll #ifdef MULTIPROCESSOR
367 1.4.2.2 skrll const u_int cores = mipsNN_cp0_ebase_read() & MIPS_EBASE_CPUNUM;
368 1.4.2.2 skrll mem_clusters[0].start = cores * 4096;
369 1.4.2.2 skrll #endif
370 1.4.2.2 skrll
371 1.4.2.2 skrll /*
372 1.4.2.2 skrll * Load the rest of the available pages into the VM system.
373 1.4.2.2 skrll */
374 1.4.2.2 skrll mips_page_physload(mips_trunc_page(kernel_text), mips_round_page(end),
375 1.4.2.2 skrll mem_clusters, mem_cluster_cnt, NULL, 0);
376 1.4.2.2 skrll
377 1.4.2.2 skrll /*
378 1.4.2.2 skrll * Initialize error message buffer (at end of core).
379 1.4.2.2 skrll */
380 1.4.2.2 skrll mips_init_msgbuf();
381 1.4.2.2 skrll
382 1.4.2.2 skrll pmap_bootstrap();
383 1.4.2.2 skrll }
384 1.4.2.2 skrll
385 1.4.2.2 skrll /*
386 1.4.2.2 skrll * cpu_startup
387 1.4.2.2 skrll * cpu_reboot
388 1.4.2.2 skrll */
389 1.4.2.2 skrll
390 1.4.2.2 skrll int waittime = -1;
391 1.4.2.2 skrll
392 1.4.2.2 skrll /*
393 1.4.2.2 skrll * Allocate memory for variable-sized tables,
394 1.4.2.2 skrll */
395 1.4.2.2 skrll void
396 1.4.2.2 skrll cpu_startup(void)
397 1.4.2.2 skrll {
398 1.4.2.3 skrll #ifdef MULTIPROCESSOR
399 1.4.2.3 skrll // Create a kcpuset so we can see on which CPUs the kernel was started.
400 1.4.2.3 skrll kcpuset_create(&cpus_booted, true);
401 1.4.2.3 skrll #endif
402 1.4.2.3 skrll
403 1.4.2.2 skrll /*
404 1.4.2.2 skrll * Do the common startup items.
405 1.4.2.2 skrll */
406 1.4.2.2 skrll cpu_startup_common();
407 1.4.2.2 skrll
408 1.4.2.2 skrll /*
409 1.4.2.2 skrll * Virtual memory is bootstrapped -- notify the bus spaces
410 1.4.2.2 skrll * that memory allocation is now safe.
411 1.4.2.2 skrll */
412 1.4.2.2 skrll octeon_configuration.mc_mallocsafe = 1;
413 1.4.2.2 skrll }
414 1.4.2.2 skrll
415 1.4.2.2 skrll void
416 1.4.2.2 skrll cpu_reboot(int howto, char *bootstr)
417 1.4.2.2 skrll {
418 1.4.2.2 skrll
419 1.4.2.2 skrll /* Take a snapshot before clobbering any registers. */
420 1.4.2.2 skrll savectx(curpcb);
421 1.4.2.2 skrll
422 1.4.2.2 skrll if (cold) {
423 1.4.2.2 skrll howto |= RB_HALT;
424 1.4.2.2 skrll goto haltsys;
425 1.4.2.2 skrll }
426 1.4.2.2 skrll
427 1.4.2.2 skrll /* If "always halt" was specified as a boot flag, obey. */
428 1.4.2.2 skrll if (boothowto & RB_HALT)
429 1.4.2.2 skrll howto |= RB_HALT;
430 1.4.2.2 skrll
431 1.4.2.2 skrll boothowto = howto;
432 1.4.2.2 skrll if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) {
433 1.4.2.2 skrll waittime = 0;
434 1.4.2.2 skrll vfs_shutdown();
435 1.4.2.2 skrll
436 1.4.2.2 skrll /*
437 1.4.2.2 skrll * If we've been adjusting the clock, the todr
438 1.4.2.2 skrll * will be out of synch; adjust it now.
439 1.4.2.2 skrll */
440 1.4.2.2 skrll resettodr();
441 1.4.2.2 skrll }
442 1.4.2.2 skrll
443 1.4.2.2 skrll splhigh();
444 1.4.2.2 skrll
445 1.4.2.2 skrll if (howto & RB_DUMP)
446 1.4.2.2 skrll dumpsys();
447 1.4.2.2 skrll
448 1.4.2.2 skrll haltsys:
449 1.4.2.2 skrll doshutdownhooks();
450 1.4.2.2 skrll
451 1.4.2.2 skrll if (howto & RB_HALT) {
452 1.4.2.2 skrll printf("\n");
453 1.4.2.2 skrll printf("The operating system has halted.\n");
454 1.4.2.2 skrll printf("Please press any key to reboot.\n\n");
455 1.4.2.5 skrll cnpollc(1); /* For proper keyboard command handling */
456 1.4.2.5 skrll cngetc();
457 1.4.2.5 skrll cnpollc(0);
458 1.4.2.2 skrll }
459 1.4.2.2 skrll
460 1.4.2.2 skrll printf("%s\n\n", ((howto & RB_HALT) != 0) ? "halted." : "rebooting...");
461 1.4.2.2 skrll
462 1.4.2.2 skrll /*
463 1.4.2.2 skrll * Need a small delay here, otherwise we see the first few characters of
464 1.4.2.2 skrll * the warning below.
465 1.4.2.2 skrll */
466 1.4.2.2 skrll delay(80000);
467 1.4.2.2 skrll
468 1.4.2.2 skrll /* initiate chip soft-reset */
469 1.4.2.2 skrll uint64_t fuse = octeon_read_csr(CIU_FUSE);
470 1.4.2.2 skrll octeon_write_csr(CIU_SOFT_BIST, fuse);
471 1.4.2.2 skrll octeon_read_csr(CIU_SOFT_RST);
472 1.4.2.2 skrll octeon_write_csr(CIU_SOFT_RST, fuse);
473 1.4.2.2 skrll
474 1.4.2.2 skrll delay(1000000);
475 1.4.2.2 skrll
476 1.4.2.2 skrll printf("WARNING: reset failed!\nSpinning...");
477 1.4.2.2 skrll
478 1.4.2.2 skrll for (;;)
479 1.4.2.2 skrll /* spin forever */ ; /* XXX */
480 1.4.2.2 skrll }
481