machdep.c revision 1.1 1 1.1 bouyer /* $NetBSD: machdep.c,v 1.1 2011/08/27 13:42:45 bouyer Exp $ */
2 1.1 bouyer
3 1.1 bouyer /*
4 1.1 bouyer * Copyright 2001, 2002 Wasabi Systems, Inc.
5 1.1 bouyer * All rights reserved.
6 1.1 bouyer *
7 1.1 bouyer * Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc.
8 1.1 bouyer *
9 1.1 bouyer * Redistribution and use in source and binary forms, with or without
10 1.1 bouyer * modification, are permitted provided that the following conditions
11 1.1 bouyer * are met:
12 1.1 bouyer * 1. Redistributions of source code must retain the above copyright
13 1.1 bouyer * notice, this list of conditions and the following disclaimer.
14 1.1 bouyer * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 bouyer * notice, this list of conditions and the following disclaimer in the
16 1.1 bouyer * documentation and/or other materials provided with the distribution.
17 1.1 bouyer * 3. All advertising materials mentioning features or use of this software
18 1.1 bouyer * must display the following acknowledgement:
19 1.1 bouyer * This product includes software developed for the NetBSD Project by
20 1.1 bouyer * Wasabi Systems, Inc.
21 1.1 bouyer * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1 bouyer * or promote products derived from this software without specific prior
23 1.1 bouyer * written permission.
24 1.1 bouyer *
25 1.1 bouyer * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1 bouyer * POSSIBILITY OF SUCH DAMAGE.
36 1.1 bouyer */
37 1.1 bouyer
38 1.1 bouyer /*
39 1.1 bouyer * Copyright (c) 1988 University of Utah.
40 1.1 bouyer * Copyright (c) 1992, 1993
41 1.1 bouyer * The Regents of the University of California. All rights reserved.
42 1.1 bouyer *
43 1.1 bouyer * This code is derived from software contributed to Berkeley by
44 1.1 bouyer * the Systems Programming Group of the University of Utah Computer
45 1.1 bouyer * Science Department, The Mach Operating System project at
46 1.1 bouyer * Carnegie-Mellon University and Ralph Campbell.
47 1.1 bouyer *
48 1.1 bouyer * Redistribution and use in source and binary forms, with or without
49 1.1 bouyer * modification, are permitted provided that the following conditions
50 1.1 bouyer * are met:
51 1.1 bouyer * 1. Redistributions of source code must retain the above copyright
52 1.1 bouyer * notice, this list of conditions and the following disclaimer.
53 1.1 bouyer * 2. Redistributions in binary form must reproduce the above copyright
54 1.1 bouyer * notice, this list of conditions and the following disclaimer in the
55 1.1 bouyer * documentation and/or other materials provided with the distribution.
56 1.1 bouyer * 3. Neither the name of the University nor the names of its contributors
57 1.1 bouyer * may be used to endorse or promote products derived from this software
58 1.1 bouyer * without specific prior written permission.
59 1.1 bouyer *
60 1.1 bouyer * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
61 1.1 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62 1.1 bouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63 1.1 bouyer * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
64 1.1 bouyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65 1.1 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
66 1.1 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67 1.1 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68 1.1 bouyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69 1.1 bouyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 1.1 bouyer * SUCH DAMAGE.
71 1.1 bouyer *
72 1.1 bouyer * @(#)machdep.c 8.3 (Berkeley) 1/12/94
73 1.1 bouyer * from: Utah Hdr: machdep.c 1.63 91/04/24
74 1.1 bouyer */
75 1.1 bouyer
76 1.1 bouyer /*
77 1.1 bouyer * Copyright (c) 2009, 2010 Miodrag Vallat.
78 1.1 bouyer *
79 1.1 bouyer * Permission to use, copy, modify, and distribute this software for any
80 1.1 bouyer * purpose with or without fee is hereby granted, provided that the above
81 1.1 bouyer * copyright notice and this permission notice appear in all copies.
82 1.1 bouyer *
83 1.1 bouyer * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
84 1.1 bouyer * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
85 1.1 bouyer * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
86 1.1 bouyer * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
87 1.1 bouyer * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
88 1.1 bouyer * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
89 1.1 bouyer * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
90 1.1 bouyer */
91 1.1 bouyer
92 1.1 bouyer #include <sys/cdefs.h>
93 1.1 bouyer __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.1 2011/08/27 13:42:45 bouyer Exp $");
94 1.1 bouyer
95 1.1 bouyer #include "opt_ddb.h"
96 1.1 bouyer #include "opt_execfmt.h"
97 1.1 bouyer #include "opt_modular.h"
98 1.1 bouyer
99 1.1 bouyer #define _MIPS_BUS_DMA_PRIVATE
100 1.1 bouyer
101 1.1 bouyer #include <sys/param.h>
102 1.1 bouyer #include <sys/systm.h>
103 1.1 bouyer #include <sys/kernel.h>
104 1.1 bouyer #include <sys/buf.h>
105 1.1 bouyer #include <sys/reboot.h>
106 1.1 bouyer #include <sys/mount.h>
107 1.1 bouyer #include <sys/kcore.h>
108 1.1 bouyer #include <sys/boot_flag.h>
109 1.1 bouyer #include <sys/termios.h>
110 1.1 bouyer #include <sys/ksyms.h>
111 1.1 bouyer #include <sys/device.h>
112 1.1 bouyer
113 1.1 bouyer #include <uvm/uvm_extern.h>
114 1.1 bouyer
115 1.1 bouyer #include <dev/cons.h>
116 1.1 bouyer
117 1.1 bouyer #include "ksyms.h"
118 1.1 bouyer
119 1.1 bouyer #if NKSYMS || defined(DDB) || defined(MODULAR)
120 1.1 bouyer #include <machine/db_machdep.h>
121 1.1 bouyer #include <ddb/db_extern.h>
122 1.1 bouyer #include <sys/exec_elf.h>
123 1.1 bouyer #endif
124 1.1 bouyer
125 1.1 bouyer #include <evbmips/loongson/autoconf.h>
126 1.1 bouyer #include <evbmips/loongson/loongson_intr.h>
127 1.1 bouyer #include <evbmips/loongson/loongson_bus_defs.h>
128 1.1 bouyer #include <machine/cpu.h>
129 1.1 bouyer #include <machine/psl.h>
130 1.1 bouyer
131 1.1 bouyer #include <mips/locore.h>
132 1.1 bouyer
133 1.1 bouyer #include <mips/bonito/bonitoreg.h>
134 1.1 bouyer #include <mips/bonito/bonitovar.h>
135 1.1 bouyer #include <mips/pmon/pmon.h>
136 1.1 bouyer #include <dev/pci/sisfb.h>
137 1.1 bouyer
138 1.1 bouyer #include "com.h"
139 1.1 bouyer #if NCOM > 0
140 1.1 bouyer #include <dev/ic/comreg.h>
141 1.1 bouyer #include <dev/ic/comvar.h>
142 1.1 bouyer
143 1.1 bouyer #ifdef LOW_DEBUG
144 1.1 bouyer #define DPRINTF(x) printf x
145 1.1 bouyer #define DPPRINTF(x) pmon_printf x
146 1.1 bouyer #else
147 1.1 bouyer #define DPRINTF(x)
148 1.1 bouyer #define DPPRINTF(x)
149 1.1 bouyer #endif
150 1.1 bouyer
151 1.1 bouyer bus_space_tag_t comconsiot;
152 1.1 bouyer bus_addr_t comconsaddr;
153 1.1 bouyer int comconsrate = 0;
154 1.1 bouyer #endif /* NCOM > 0 */
155 1.1 bouyer
156 1.1 bouyer #include "sisfb.h"
157 1.1 bouyer
158 1.1 bouyer
159 1.1 bouyer int ex_mallocsafe = 0;
160 1.1 bouyer struct extent *loongson_io_ex = NULL;
161 1.1 bouyer struct extent *loongson_mem_ex = NULL;
162 1.1 bouyer struct mips_bus_space bonito_iot;
163 1.1 bouyer struct mips_bus_space bonito_memt;
164 1.1 bouyer struct mips_bus_dma_tag bonito_dmat;
165 1.1 bouyer struct mips_pci_chipset bonito_pc;
166 1.1 bouyer
167 1.1 bouyer uint loongson_ver;
168 1.1 bouyer
169 1.1 bouyer const struct platform *sys_platform;
170 1.1 bouyer struct bonito_flavour {
171 1.1 bouyer const char *prefix;
172 1.1 bouyer const struct platform *platform;
173 1.1 bouyer };
174 1.1 bouyer
175 1.1 bouyer extern const struct platform fuloong_platform;
176 1.1 bouyer extern const struct platform gdium_platform;
177 1.1 bouyer extern const struct platform generic2e_platform;
178 1.1 bouyer extern const struct platform lynloong_platform;
179 1.1 bouyer extern const struct platform yeeloong_platform;
180 1.1 bouyer
181 1.1 bouyer const struct bonito_flavour bonito_flavours[] = {
182 1.1 bouyer /* Lemote Fuloong 2F mini-PC */
183 1.1 bouyer { "LM6002", &fuloong_platform }, /* dual Ethernet, no prefix */
184 1.1 bouyer { "LM6003", &fuloong_platform },
185 1.1 bouyer { "LM6004", &fuloong_platform },
186 1.1 bouyer /* EMTEC Gdium Liberty 1000 */
187 1.1 bouyer { "Gdium", &gdium_platform },
188 1.1 bouyer /* Lemote Yeeloong 8.9" netbook */
189 1.1 bouyer { "LM8089", &yeeloong_platform },
190 1.1 bouyer /* supposedly Lemote Yeeloong 10.1" netbook, but those found so far
191 1.1 bouyer report themselves as LM8089 */
192 1.1 bouyer { "LM8101", &yeeloong_platform },
193 1.1 bouyer /* Lemote Lynloong all-in-one computer */
194 1.1 bouyer { "LM9001", &lynloong_platform },
195 1.1 bouyer { NULL }
196 1.1 bouyer };
197 1.1 bouyer
198 1.1 bouyer /* For sysctl_hw. */
199 1.1 bouyer extern char cpu_model[];
200 1.1 bouyer
201 1.1 bouyer /* Maps for VM objects. */
202 1.1 bouyer struct vm_map *phys_map = NULL;
203 1.1 bouyer
204 1.1 bouyer int netboot; /* Are we netbooting? */
205 1.1 bouyer
206 1.1 bouyer phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
207 1.1 bouyer int mem_cluster_cnt;
208 1.1 bouyer
209 1.1 bouyer void mach_init(int, int32_t, int32_t, int32_t, char *);
210 1.1 bouyer
211 1.1 bouyer static int pmoncngetc(dev_t);
212 1.1 bouyer static void pmoncnputc(dev_t, int);
213 1.1 bouyer
214 1.1 bouyer struct consdev pmoncons = {
215 1.1 bouyer NULL, /* probe */
216 1.1 bouyer NULL, /* init */
217 1.1 bouyer pmoncngetc, /* getc */
218 1.1 bouyer pmoncnputc, /* putc */
219 1.1 bouyer nullcnpollc, /* poolc */
220 1.1 bouyer NULL, /* BELL */
221 1.1 bouyer makedev(0, 0),
222 1.1 bouyer CN_DEAD
223 1.1 bouyer };
224 1.1 bouyer
225 1.1 bouyer /*
226 1.1 bouyer * Do all the stuff that locore normally does before calling main().
227 1.1 bouyer */
228 1.1 bouyer void
229 1.1 bouyer mach_init(int32_t argc, int32_t argva, int32_t enva, int32_t callvec,
230 1.1 bouyer char *boot_esym)
231 1.1 bouyer {
232 1.1 bouyer void *kernend;
233 1.1 bouyer #ifdef NOTYET
234 1.1 bouyer int howto;
235 1.1 bouyer #endif
236 1.1 bouyer const char *env;
237 1.1 bouyer int i;
238 1.1 bouyer psize_t memlo, memhi;
239 1.1 bouyer const struct bonito_flavour *f;
240 1.1 bouyer char *ssym = NULL, *esym = NULL;
241 1.1 bouyer pcireg_t reg;
242 1.1 bouyer pcitag_t pcitag;
243 1.1 bouyer
244 1.1 bouyer extern char edata[], end[];
245 1.1 bouyer
246 1.1 bouyer /*
247 1.1 bouyer * Clear the BSS segment.
248 1.1 bouyer */
249 1.1 bouyer memset(edata, 0, (char *)end - edata);
250 1.1 bouyer
251 1.1 bouyer pmon_init(argc, argva, enva, callvec);
252 1.1 bouyer DPPRINTF(("pmon hello\n"));
253 1.1 bouyer
254 1.1 bouyer cn_tab = &pmoncons;
255 1.1 bouyer
256 1.1 bouyer DPRINTF(("hello 0x%x %d 0x%x 0x%x %p stack %p\n", pmon_callvec, argc, argva, enva, boot_esym, &i));
257 1.1 bouyer
258 1.1 bouyer /*
259 1.1 bouyer * Reserve space for the symbol table, if it exists.
260 1.1 bouyer */
261 1.1 bouyer
262 1.1 bouyer #if NKSYMS || defined(DDB) || defined(MODULAR)
263 1.1 bouyer /* Attempt to locate ELF header and symbol table after kernel. */
264 1.1 bouyer if (end[0] == ELFMAG0 && end[1] == ELFMAG1 &&
265 1.1 bouyer end[2] == ELFMAG2 && end[3] == ELFMAG3) {
266 1.1 bouyer /* ELF header exists directly after kernel. */
267 1.1 bouyer ssym = end;
268 1.1 bouyer esym = boot_esym;
269 1.1 bouyer kernend = (void *)mips_round_page(esym);
270 1.1 bouyer } else {
271 1.1 bouyer ssym = (char *)(vaddr_t)*(int32_t *)end;
272 1.1 bouyer if (((long)ssym - (long)end) >= 0 &&
273 1.1 bouyer ((long)ssym - (long)end) <= 0x1000 &&
274 1.1 bouyer ssym[0] == ELFMAG0 && ssym[1] == ELFMAG1 &&
275 1.1 bouyer ssym[2] == ELFMAG2 && ssym[3] == ELFMAG3) {
276 1.1 bouyer /* Pointers exist directly after kernel. */
277 1.1 bouyer esym = (char *)(vaddr_t)*((int32_t *)end + 1);
278 1.1 bouyer kernend = (void *)mips_round_page(esym);
279 1.1 bouyer } else {
280 1.1 bouyer /* Pointers aren't setup either... */
281 1.1 bouyer ssym = NULL;
282 1.1 bouyer esym = NULL;
283 1.1 bouyer kernend = (void *)mips_round_page(end);
284 1.1 bouyer }
285 1.1 bouyer }
286 1.1 bouyer DPRINTF(("ssym %p esym %p\n", ssym, esym));
287 1.1 bouyer #endif
288 1.1 bouyer
289 1.1 bouyer /*
290 1.1 bouyer * Set up the exception vectors and CPU-specific function
291 1.1 bouyer * vectors early on. We need the wbflush() vector set up
292 1.1 bouyer * before comcnattach() is called (or at least before the
293 1.1 bouyer * first printf() after that is called).
294 1.1 bouyer * Also clears the I+D caches.
295 1.1 bouyer */
296 1.1 bouyer DPRINTF(("mips_vector_init "));
297 1.1 bouyer mips_vector_init(NULL, false);
298 1.1 bouyer
299 1.1 bouyer DPRINTF(("uvm_setpagesize\n"));
300 1.1 bouyer /* set the VM page size */
301 1.1 bouyer uvm_setpagesize();
302 1.1 bouyer #if NKSYMS || defined(DDB) || defined(MODULAR)
303 1.1 bouyer //ksyms_addsyms_elf((vaddr_t)esym - (vaddr_t)ssym, ssym, esym);
304 1.1 bouyer #endif
305 1.1 bouyer
306 1.1 bouyer /*
307 1.1 bouyer * Try and figure out what kind of hardware we are.
308 1.1 bouyer */
309 1.1 bouyer
310 1.1 bouyer env = pmon_getenv("systype");
311 1.1 bouyer if (env == NULL) {
312 1.1 bouyer printf("Unable to figure out system type!\n");
313 1.1 bouyer goto unsupported;
314 1.1 bouyer }
315 1.1 bouyer if (strcmp(env, "Bonito") != 0) {
316 1.1 bouyer printf("This kernel doesn't support system type \"%s\".\n",
317 1.1 bouyer env);
318 1.1 bouyer goto unsupported;
319 1.1 bouyer }
320 1.1 bouyer
321 1.1 bouyer /*
322 1.1 bouyer * While the kernel supports other processor types than Loongson,
323 1.1 bouyer * we are not expecting a Bonito-based system with a different
324 1.1 bouyer * processor. Just to be on the safe side, refuse to run on
325 1.1 bouyer * non Loongson2 processors for now.
326 1.1 bouyer */
327 1.1 bouyer
328 1.1 bouyer switch ((mips_options.mips_cpu_id >> 8) & 0xff) {
329 1.1 bouyer case MIPS_LOONGSON2:
330 1.1 bouyer switch (mips_options.mips_cpu_id & 0xff) {
331 1.1 bouyer case 0x00:
332 1.1 bouyer loongson_ver = 0x2c;
333 1.1 bouyer break;
334 1.1 bouyer case 0x02:
335 1.1 bouyer loongson_ver = 0x2e;
336 1.1 bouyer break;
337 1.1 bouyer case 0x03:
338 1.1 bouyer loongson_ver = 0x2f;
339 1.1 bouyer break;
340 1.1 bouyer case 0x05:
341 1.1 bouyer loongson_ver = 0x3a;
342 1.1 bouyer break;
343 1.1 bouyer }
344 1.1 bouyer if (loongson_ver == 0x2e || loongson_ver == 0x2f)
345 1.1 bouyer break;
346 1.1 bouyer /* FALLTHROUGH */
347 1.1 bouyer default:
348 1.1 bouyer printf("This kernel doesn't support processor type 0x%x"
349 1.1 bouyer ", version %d.%d.\n",
350 1.1 bouyer (mips_options.mips_cpu_id >> 8) & 0xff,
351 1.1 bouyer (mips_options.mips_cpu_id >> 4) & 0x0f,
352 1.1 bouyer mips_options.mips_cpu_id & 0x0f);
353 1.1 bouyer goto unsupported;
354 1.1 bouyer }
355 1.1 bouyer
356 1.1 bouyer /*
357 1.1 bouyer * Try to figure out what particular machine we run on, depending
358 1.1 bouyer * on the PMON version information.
359 1.1 bouyer */
360 1.1 bouyer
361 1.1 bouyer env = pmon_getenv("Version");
362 1.1 bouyer if (env == NULL) {
363 1.1 bouyer /*
364 1.1 bouyer * If this is a 2E system, use the generic code and hope
365 1.1 bouyer * for the best.
366 1.1 bouyer */
367 1.1 bouyer if (loongson_ver == 0x2e) {
368 1.1 bouyer sys_platform = &generic2e_platform;
369 1.1 bouyer } else {
370 1.1 bouyer printf("Unable to figure out model!\n");
371 1.1 bouyer goto unsupported;
372 1.1 bouyer }
373 1.1 bouyer } else {
374 1.1 bouyer for (f = bonito_flavours; f->prefix != NULL; f++)
375 1.1 bouyer if (strncmp(env, f->prefix, strlen(f->prefix)) ==
376 1.1 bouyer 0) {
377 1.1 bouyer sys_platform = f->platform;
378 1.1 bouyer break;
379 1.1 bouyer }
380 1.1 bouyer
381 1.1 bouyer if (sys_platform == NULL) {
382 1.1 bouyer /*
383 1.1 bouyer * Early Lemote designs shipped without a model prefix.
384 1.1 bouyer * Hopefully these well be close enough to the first
385 1.1 bouyer * generation Fuloong 2F design (LM6002); let's warn
386 1.1 bouyer * the user and try this if version is 1.2.something
387 1.1 bouyer * (1.3 onwards are expected to have a model prefix,
388 1.1 bouyer * and there are currently no reports of 1.1 and
389 1.1 bouyer * below being 2F systems).
390 1.1 bouyer *
391 1.1 bouyer * Note that this could be handled by adding a
392 1.1 bouyer * "1.2." machine type entry to the flavours table,
393 1.1 bouyer * but I prefer have it stand out.
394 1.1 bouyer * LM6002 users are encouraged to add the system
395 1.1 bouyer * model prefix to the `Version' variable.
396 1.1 bouyer */
397 1.1 bouyer if (strncmp(env, "1.2.", 4) == 0) {
398 1.1 bouyer printf("No model prefix in version"
399 1.1 bouyer " string \"%s\".\n"
400 1.1 bouyer "Attempting to match as Lemote Fuloong\n",
401 1.1 bouyer env);
402 1.1 bouyer sys_platform = &fuloong_platform;
403 1.1 bouyer }
404 1.1 bouyer }
405 1.1 bouyer
406 1.1 bouyer if (sys_platform == NULL) {
407 1.1 bouyer printf("This kernel doesn't support model \"%s\"."
408 1.1 bouyer "\n", env);
409 1.1 bouyer goto unsupported;
410 1.1 bouyer }
411 1.1 bouyer }
412 1.1 bouyer
413 1.1 bouyer sprintf(cpu_model, "%s %s", sys_platform->vendor,
414 1.1 bouyer sys_platform->product);
415 1.1 bouyer DPRINTF(("Found %s, setting up.\n", cpu_model));
416 1.1 bouyer
417 1.1 bouyer /*
418 1.1 bouyer * Figure out memory information.
419 1.1 bouyer * PMON reports it in two chunks, the memory under the 256MB
420 1.1 bouyer * CKSEG limit, and memory above that limit. We need to do the
421 1.1 bouyer * math ourselves.
422 1.1 bouyer */
423 1.1 bouyer
424 1.1 bouyer env = pmon_getenv("memsize");
425 1.1 bouyer if (env == NULL) {
426 1.1 bouyer printf("Could not get memory information"
427 1.1 bouyer " from the firmware\n");
428 1.1 bouyer goto unsupported;
429 1.1 bouyer }
430 1.1 bouyer memlo = strtoul(env, NULL, 10); /* size in MB */
431 1.1 bouyer DPRINTF(("memlo %" PRIdPSIZE, memlo));
432 1.1 bouyer if (memlo < 0 || memlo > 256) {
433 1.1 bouyer printf("Incorrect low memory size `%s'\n", env);
434 1.1 bouyer goto unsupported;
435 1.1 bouyer }
436 1.1 bouyer
437 1.1 bouyer /* 3A PMON only reports up to 240MB as low memory */
438 1.1 bouyer if (memlo >= 240) {
439 1.1 bouyer env = pmon_getenv("highmemsize");
440 1.1 bouyer if (env == NULL)
441 1.1 bouyer memhi = 0;
442 1.1 bouyer else
443 1.1 bouyer memhi = strtoul(env, NULL, 10); /* size in MB */
444 1.1 bouyer if (memhi < 0 || memhi > (64 * 1024) - 256) {
445 1.1 bouyer printf("Incorrect high memory size `%s'\n",
446 1.1 bouyer env);
447 1.1 bouyer /* better expose the problem than limit to 256MB */
448 1.1 bouyer goto unsupported;
449 1.1 bouyer }
450 1.1 bouyer } else
451 1.1 bouyer memhi = 0;
452 1.1 bouyer
453 1.1 bouyer DPRINTF(("memhi %" PRIdPSIZE "\n", memhi));
454 1.1 bouyer memlo = memlo * 1024 * 1024;
455 1.1 bouyer memhi = memhi * 1024 * 1024;
456 1.1 bouyer
457 1.1 bouyer switch (loongson_ver) {
458 1.1 bouyer case 0x2e:
459 1.1 bouyer loongson2e_setup(memlo, memhi,
460 1.1 bouyer MIPS_KSEG0_START, (vaddr_t)kernend, &bonito_dmat);
461 1.1 bouyer break;
462 1.1 bouyer default:
463 1.1 bouyer case 0x2f:
464 1.1 bouyer case 0x3a:
465 1.1 bouyer loongson2f_setup(memlo, memhi,
466 1.1 bouyer MIPS_KSEG0_START, (vaddr_t)kernend, &bonito_dmat);
467 1.1 bouyer break;
468 1.1 bouyer }
469 1.1 bouyer
470 1.1 bouyer DPRINTF(("bonito_pci_init "));
471 1.1 bouyer bonito_pci_init(&bonito_pc, sys_platform->bonito_config);
472 1.1 bouyer bonito_pc.pc_intr_v = __UNCONST(sys_platform->bonito_config);
473 1.1 bouyer bonito_pc.pc_intr_map = loongson_pci_intr_map;
474 1.1 bouyer bonito_pc.pc_intr_string = loongson_pci_intr_string;
475 1.1 bouyer bonito_pc.pc_intr_evcnt = loongson_pci_intr_evcnt;
476 1.1 bouyer bonito_pc.pc_intr_establish = loongson_pci_intr_establish;
477 1.1 bouyer bonito_pc.pc_intr_disestablish = loongson_pci_intr_disestablish;
478 1.1 bouyer bonito_pc.pc_conf_interrupt = loongson_pci_conf_interrupt;
479 1.1 bouyer bonito_pc.pc_pciide_compat_intr_establish =
480 1.1 bouyer loongson_pciide_compat_intr_establish;
481 1.1 bouyer DPRINTF(("bonito_bus_io_init "));
482 1.1 bouyer bonito_bus_io_init(&bonito_iot, NULL);
483 1.1 bouyer DPRINTF(("bonito_bus_mem_init\n"));
484 1.1 bouyer bonito_bus_mem_init(&bonito_memt, NULL);
485 1.1 bouyer
486 1.1 bouyer bonito_dmat._cookie = __UNCONST(sys_platform);
487 1.1 bouyer bonito_dmat._dmamap_ops = mips_bus_dmamap_ops;
488 1.1 bouyer bonito_dmat._dmamem_ops = mips_bus_dmamem_ops;
489 1.1 bouyer bonito_dmat._dmatag_ops = mips_bus_dmatag_ops;
490 1.1 bouyer
491 1.1 bouyer DPRINTF(("sys_platform->setup %p\n", sys_platform->setup));
492 1.1 bouyer if (sys_platform->setup != NULL)
493 1.1 bouyer (*(sys_platform->setup))();
494 1.1 bouyer
495 1.1 bouyer #if NCOM > 0
496 1.1 bouyer DPRINTF(("comconsrate %d\n", comconsrate));
497 1.1 bouyer if (comconsrate > 0) {
498 1.1 bouyer if (comcnattach(comconsiot, comconsaddr, comconsrate,
499 1.1 bouyer COM_FREQ, COM_TYPE_NORMAL,
500 1.1 bouyer (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8) != 0)
501 1.1 bouyer panic("unable to initialize serial console");
502 1.1 bouyer }
503 1.1 bouyer #endif /* NCOM > 0 */
504 1.1 bouyer
505 1.1 bouyer for (i = 0; i < 32 - 0x11; i++) {
506 1.1 bouyer pcitag = pci_make_tag(&bonito_pc, 0, i, 0);
507 1.1 bouyer reg = pci_conf_read(&bonito_pc, pcitag, PCI_CLASS_REG);
508 1.1 bouyer DPRINTF(("dev %d class 0x%x", i, reg));
509 1.1 bouyer reg = pci_conf_read(&bonito_pc, pcitag, PCI_ID_REG);
510 1.1 bouyer DPRINTF((" id 0x%x; ", reg));
511 1.1 bouyer #if NSISFB > 0
512 1.1 bouyer if (cn_tab == &pmoncons)
513 1.1 bouyer sisfb_cnattach(&bonito_memt, &bonito_iot, &bonito_pc,
514 1.1 bouyer pcitag, reg);
515 1.1 bouyer #endif
516 1.1 bouyer }
517 1.1 bouyer DPRINTF(("\n"));
518 1.1 bouyer
519 1.1 bouyer /*
520 1.1 bouyer * Get the timer from PMON.
521 1.1 bouyer */
522 1.1 bouyer DPRINTF(("search cpuclock "));
523 1.1 bouyer env = pmon_getenv("cpuclock");
524 1.1 bouyer DPRINTF(("got %s ", env));
525 1.1 bouyer if (env != NULL) {
526 1.1 bouyer curcpu()->ci_cpu_freq =
527 1.1 bouyer strtoul(env, NULL, 10);
528 1.1 bouyer }
529 1.1 bouyer
530 1.1 bouyer DPRINTF(("cpuclock %ld\n", curcpu()->ci_cpu_freq));
531 1.1 bouyer
532 1.1 bouyer if (mips_options.mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
533 1.1 bouyer curcpu()->ci_cpu_freq /= 2;
534 1.1 bouyer
535 1.1 bouyer
536 1.1 bouyer /* Compute the number of ticks for hz. */
537 1.1 bouyer curcpu()->ci_cycles_per_hz = (curcpu()->ci_cpu_freq + hz / 2) / hz;
538 1.1 bouyer
539 1.1 bouyer /* Compute the delay divisor. */
540 1.1 bouyer curcpu()->ci_divisor_delay =
541 1.1 bouyer ((curcpu()->ci_cpu_freq + 500000) / 1000000);
542 1.1 bouyer
543 1.1 bouyer /*
544 1.1 bouyer * Get correct cpu frequency if the CPU runs at twice the
545 1.1 bouyer * external/cp0-count frequency.
546 1.1 bouyer */
547 1.1 bouyer if (mips_options.mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
548 1.1 bouyer curcpu()->ci_cpu_freq *= 2;
549 1.1 bouyer
550 1.1 bouyer #ifdef DEBUG
551 1.1 bouyer printf("Timer calibration: %lu cycles/sec\n",
552 1.1 bouyer curcpu()->ci_cpu_freq);
553 1.1 bouyer #endif
554 1.1 bouyer
555 1.1 bouyer #if NCOM > 0 && 0
556 1.1 bouyer /*
557 1.1 bouyer * Delay to allow firmware putchars to complete.
558 1.1 bouyer * FIFO depth * character time.
559 1.1 bouyer * character time = (1000000 / (defaultrate / 10))
560 1.1 bouyer */
561 1.1 bouyer delay(160000000 / comcnrate);
562 1.1 bouyer if (comcnattach(&gc->gc_iot, MALTA_UART0ADR, comcnrate,
563 1.1 bouyer COM_FREQ, COM_TYPE_NORMAL,
564 1.1 bouyer (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8) != 0)
565 1.1 bouyer panic("malta: unable to initialize serial console");
566 1.1 bouyer #endif /* NCOM > 0 */
567 1.1 bouyer
568 1.1 bouyer /*
569 1.1 bouyer * XXX: check argv[0] - do something if "gdb"???
570 1.1 bouyer */
571 1.1 bouyer
572 1.1 bouyer /*
573 1.1 bouyer * Look at arguments passed to us and compute boothowto.
574 1.1 bouyer */
575 1.1 bouyer boothowto = RB_AUTOBOOT;
576 1.1 bouyer #ifdef NOTYET
577 1.1 bouyer for (i = 1; i < argc; i++) {
578 1.1 bouyer for (cp = argv[i]; *cp; cp++) {
579 1.1 bouyer /* Ignore superfluous '-', if there is one */
580 1.1 bouyer if (*cp == '-')
581 1.1 bouyer continue;
582 1.1 bouyer
583 1.1 bouyer howto = 0;
584 1.1 bouyer BOOT_FLAG(*cp, howto);
585 1.1 bouyer if (! howto)
586 1.1 bouyer printf("bootflag '%c' not recognised\n", *cp);
587 1.1 bouyer else
588 1.1 bouyer boothowto |= howto;
589 1.1 bouyer }
590 1.1 bouyer }
591 1.1 bouyer #endif
592 1.1 bouyer
593 1.1 bouyer /*
594 1.1 bouyer * Load the rest of the available pages into the VM system.
595 1.1 bouyer */
596 1.1 bouyer mips_page_physload(MIPS_KSEG0_START, (vaddr_t)kernend,
597 1.1 bouyer mem_clusters, mem_cluster_cnt, NULL, 0);
598 1.1 bouyer
599 1.1 bouyer /*
600 1.1 bouyer * Initialize error message buffer (at end of core).
601 1.1 bouyer */
602 1.1 bouyer DPRINTF(("mips_init_msgbuf\n"));
603 1.1 bouyer mips_init_msgbuf();
604 1.1 bouyer
605 1.1 bouyer DPRINTF(("pmap_bootstrap\n"));
606 1.1 bouyer pmap_bootstrap();
607 1.1 bouyer
608 1.1 bouyer /*
609 1.1 bouyer * Allocate uarea page for lwp0 and set it.
610 1.1 bouyer */
611 1.1 bouyer DPRINTF(("curlwp %p ", curlwp));
612 1.1 bouyer DPRINTF(("curlwp stack %p\n", curlwp->l_addr));
613 1.1 bouyer mips_init_lwp0_uarea();
614 1.1 bouyer
615 1.1 bouyer DPRINTF(("curlwp %p ", curlwp));
616 1.1 bouyer DPRINTF(("curlwp stack %p\n", curlwp->l_addr));
617 1.1 bouyer
618 1.1 bouyer /*
619 1.1 bouyer * Initialize debuggers, and break into them, if appropriate.
620 1.1 bouyer */
621 1.1 bouyer #if defined(DDB)
622 1.1 bouyer if (boothowto & RB_KDB)
623 1.1 bouyer Debugger();
624 1.1 bouyer #endif
625 1.1 bouyer DPRINTF(("return\n"));
626 1.1 bouyer return;
627 1.1 bouyer unsupported:
628 1.1 bouyer panic("unsupported hardware\n");
629 1.1 bouyer }
630 1.1 bouyer
631 1.1 bouyer void
632 1.1 bouyer consinit(void)
633 1.1 bouyer {
634 1.1 bouyer
635 1.1 bouyer /*
636 1.1 bouyer * Everything related to console initialization is done
637 1.1 bouyer * in mach_init().
638 1.1 bouyer */
639 1.1 bouyer }
640 1.1 bouyer
641 1.1 bouyer /*
642 1.1 bouyer * Allocate memory for variable-sized tables,
643 1.1 bouyer */
644 1.1 bouyer void
645 1.1 bouyer cpu_startup(void)
646 1.1 bouyer {
647 1.1 bouyer /*
648 1.1 bouyer * Do the common startup items.
649 1.1 bouyer */
650 1.1 bouyer cpu_startup_common();
651 1.1 bouyer
652 1.1 bouyer /*
653 1.1 bouyer * Virtual memory is bootstrapped -- notify the bus spaces
654 1.1 bouyer * that memory allocation is now safe.
655 1.1 bouyer */
656 1.1 bouyer ex_mallocsafe = 1;
657 1.1 bouyer
658 1.1 bouyer }
659 1.1 bouyer
660 1.1 bouyer int waittime = -1;
661 1.1 bouyer
662 1.1 bouyer void
663 1.1 bouyer cpu_reboot(int howto, char *bootstr)
664 1.1 bouyer {
665 1.1 bouyer
666 1.1 bouyer /* Take a snapshot before clobbering any registers. */
667 1.1 bouyer savectx(curpcb);
668 1.1 bouyer
669 1.1 bouyer if (cold) {
670 1.1 bouyer howto |= RB_HALT;
671 1.1 bouyer goto haltsys;
672 1.1 bouyer }
673 1.1 bouyer
674 1.1 bouyer /* If "always halt" was specified as a boot flag, obey. */
675 1.1 bouyer if (boothowto & RB_HALT)
676 1.1 bouyer howto |= RB_HALT;
677 1.1 bouyer
678 1.1 bouyer boothowto = howto;
679 1.1 bouyer if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) {
680 1.1 bouyer waittime = 0;
681 1.1 bouyer vfs_shutdown();
682 1.1 bouyer
683 1.1 bouyer /*
684 1.1 bouyer * If we've been adjusting the clock, the todr
685 1.1 bouyer * will be out of synch; adjust it now.
686 1.1 bouyer */
687 1.1 bouyer resettodr();
688 1.1 bouyer }
689 1.1 bouyer
690 1.1 bouyer splhigh();
691 1.1 bouyer
692 1.1 bouyer if (howto & RB_DUMP)
693 1.1 bouyer dumpsys();
694 1.1 bouyer
695 1.1 bouyer haltsys:
696 1.1 bouyer doshutdownhooks();
697 1.1 bouyer
698 1.1 bouyer pmf_system_shutdown(boothowto);
699 1.1 bouyer
700 1.1 bouyer if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
701 1.1 bouyer if (sys_platform->powerdown != NULL)
702 1.1 bouyer sys_platform->powerdown();
703 1.1 bouyer }
704 1.1 bouyer
705 1.1 bouyer if (howto & RB_HALT) {
706 1.1 bouyer printf("\n");
707 1.1 bouyer printf("The operating system has halted.\n");
708 1.1 bouyer printf("Please press any key to reboot.\n\n");
709 1.1 bouyer cnpollc(1); /* For proper keyboard command handling */
710 1.1 bouyer cngetc();
711 1.1 bouyer cnpollc(0);
712 1.1 bouyer }
713 1.1 bouyer
714 1.1 bouyer printf("%s\n\n", ((howto & RB_HALT) != 0) ? "halted." : "rebooting...");
715 1.1 bouyer
716 1.1 bouyer if (sys_platform->reset != NULL)
717 1.1 bouyer sys_platform->reset();
718 1.1 bouyer
719 1.1 bouyer __asm__ __volatile__ (
720 1.1 bouyer "\t.long 0x3c02bfc0\n"
721 1.1 bouyer "\t.long 0x00400008\n"
722 1.1 bouyer ::: "v0");
723 1.1 bouyer }
724 1.1 bouyer
725 1.1 bouyer /*
726 1.1 bouyer * Early console through pmon routines.
727 1.1 bouyer */
728 1.1 bouyer
729 1.1 bouyer int
730 1.1 bouyer pmoncngetc(dev_t dev)
731 1.1 bouyer {
732 1.1 bouyer /*
733 1.1 bouyer * PMON does not give us a getc routine. So try to get a whole line
734 1.1 bouyer * and return it char by char, trying not to lose the \n. Kind
735 1.1 bouyer * of ugly but should work.
736 1.1 bouyer *
737 1.1 bouyer * Note that one could theoretically use pmon_read(STDIN, &c, 1)
738 1.1 bouyer * but the value of STDIN within PMON is not a constant and there
739 1.1 bouyer * does not seem to be a way of letting us know which value to use.
740 1.1 bouyer */
741 1.1 bouyer static char buf[1 + PMON_MAXLN];
742 1.1 bouyer static char *bufpos = buf;
743 1.1 bouyer int c;
744 1.1 bouyer
745 1.1 bouyer if (*bufpos == '\0') {
746 1.1 bouyer bufpos = buf;
747 1.1 bouyer if (pmon_gets(buf) == NULL) {
748 1.1 bouyer /* either an empty line or EOF. assume the former */
749 1.1 bouyer return (int)'\n';
750 1.1 bouyer } else {
751 1.1 bouyer /* put back the \n sign */
752 1.1 bouyer buf[strlen(buf)] = '\n';
753 1.1 bouyer }
754 1.1 bouyer }
755 1.1 bouyer
756 1.1 bouyer c = (int)*bufpos++;
757 1.1 bouyer if (bufpos - buf > PMON_MAXLN) {
758 1.1 bouyer bufpos = buf;
759 1.1 bouyer *bufpos = '\0';
760 1.1 bouyer }
761 1.1 bouyer
762 1.1 bouyer return c;
763 1.1 bouyer }
764 1.1 bouyer
765 1.1 bouyer void
766 1.1 bouyer pmoncnputc(dev_t dev, int c)
767 1.1 bouyer {
768 1.1 bouyer if (c == '\n')
769 1.1 bouyer pmon_printf("\n");
770 1.1 bouyer else
771 1.1 bouyer pmon_printf("%c", c);
772 1.1 bouyer }
773