machdep.c revision 1.1.4.2 1 1.1.4.2 ad /* $NetBSD: machdep.c,v 1.1.4.2 2007/04/10 13:39:27 ad Exp $ */
2 1.1.4.2 ad
3 1.1.4.2 ad /*-
4 1.1.4.2 ad * Copyright (c) 2007 Ruslan Ermilov and Vsevolod Lobko.
5 1.1.4.2 ad * All rights reserved.
6 1.1.4.2 ad *
7 1.1.4.2 ad * Redistribution and use in source and binary forms, with or
8 1.1.4.2 ad * without modification, are permitted provided that the following
9 1.1.4.2 ad * conditions are met:
10 1.1.4.2 ad * 1. Redistributions of source code must retain the above copyright
11 1.1.4.2 ad * notice, this list of conditions and the following disclaimer.
12 1.1.4.2 ad * 2. Redistributions in binary form must reproduce the above
13 1.1.4.2 ad * copyright notice, this list of conditions and the following
14 1.1.4.2 ad * disclaimer in the documentation and/or other materials provided
15 1.1.4.2 ad * with the distribution.
16 1.1.4.2 ad * 3. The names of the authors may not be used to endorse or promote
17 1.1.4.2 ad * products derived from this software without specific prior
18 1.1.4.2 ad * written permission.
19 1.1.4.2 ad *
20 1.1.4.2 ad * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY
21 1.1.4.2 ad * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 1.1.4.2 ad * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 1.1.4.2 ad * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS
24 1.1.4.2 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25 1.1.4.2 ad * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 1.1.4.2 ad * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
27 1.1.4.2 ad * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1.4.2 ad * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
29 1.1.4.2 ad * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 1.1.4.2 ad * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31 1.1.4.2 ad * OF SUCH DAMAGE.
32 1.1.4.2 ad */
33 1.1.4.2 ad /*
34 1.1.4.2 ad * Copyright (c) 1992, 1993
35 1.1.4.2 ad * The Regents of the University of California. All rights reserved.
36 1.1.4.2 ad *
37 1.1.4.2 ad * This code is derived from software contributed to Berkeley by
38 1.1.4.2 ad * the Systems Programming Group of the University of Utah Computer
39 1.1.4.2 ad * Science Department, The Mach Operating System project at
40 1.1.4.2 ad * Carnegie-Mellon University and Ralph Campbell.
41 1.1.4.2 ad *
42 1.1.4.2 ad * Redistribution and use in source and binary forms, with or without
43 1.1.4.2 ad * modification, are permitted provided that the following conditions
44 1.1.4.2 ad * are met:
45 1.1.4.2 ad * 1. Redistributions of source code must retain the above copyright
46 1.1.4.2 ad * notice, this list of conditions and the following disclaimer.
47 1.1.4.2 ad * 2. Redistributions in binary form must reproduce the above copyright
48 1.1.4.2 ad * notice, this list of conditions and the following disclaimer in the
49 1.1.4.2 ad * documentation and/or other materials provided with the distribution.
50 1.1.4.2 ad * 3. Neither the name of the University nor the names of its contributors
51 1.1.4.2 ad * may be used to endorse or promote products derived from this software
52 1.1.4.2 ad * without specific prior written permission.
53 1.1.4.2 ad *
54 1.1.4.2 ad * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 1.1.4.2 ad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 1.1.4.2 ad * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 1.1.4.2 ad * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 1.1.4.2 ad * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 1.1.4.2 ad * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 1.1.4.2 ad * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 1.1.4.2 ad * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 1.1.4.2 ad * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 1.1.4.2 ad * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 1.1.4.2 ad * SUCH DAMAGE.
65 1.1.4.2 ad *
66 1.1.4.2 ad * @(#)machdep.c 8.3 (Berkeley) 1/12/94
67 1.1.4.2 ad * from: Utah Hdr: machdep.c 1.63 91/04/24
68 1.1.4.2 ad */
69 1.1.4.2 ad /*
70 1.1.4.2 ad * Copyright (c) 1988 University of Utah.
71 1.1.4.2 ad *
72 1.1.4.2 ad * This code is derived from software contributed to Berkeley by
73 1.1.4.2 ad * the Systems Programming Group of the University of Utah Computer
74 1.1.4.2 ad * Science Department, The Mach Operating System project at
75 1.1.4.2 ad * Carnegie-Mellon University and Ralph Campbell.
76 1.1.4.2 ad *
77 1.1.4.2 ad * Redistribution and use in source and binary forms, with or without
78 1.1.4.2 ad * modification, are permitted provided that the following conditions
79 1.1.4.2 ad * are met:
80 1.1.4.2 ad * 1. Redistributions of source code must retain the above copyright
81 1.1.4.2 ad * notice, this list of conditions and the following disclaimer.
82 1.1.4.2 ad * 2. Redistributions in binary form must reproduce the above copyright
83 1.1.4.2 ad * notice, this list of conditions and the following disclaimer in the
84 1.1.4.2 ad * documentation and/or other materials provided with the distribution.
85 1.1.4.2 ad * 3. All advertising materials mentioning features or use of this software
86 1.1.4.2 ad * must display the following acknowledgement:
87 1.1.4.2 ad * This product includes software developed by the University of
88 1.1.4.2 ad * California, Berkeley and its contributors.
89 1.1.4.2 ad * 4. Neither the name of the University nor the names of its contributors
90 1.1.4.2 ad * may be used to endorse or promote products derived from this software
91 1.1.4.2 ad * without specific prior written permission.
92 1.1.4.2 ad *
93 1.1.4.2 ad * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
94 1.1.4.2 ad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
95 1.1.4.2 ad * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
96 1.1.4.2 ad * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
97 1.1.4.2 ad * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
98 1.1.4.2 ad * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
99 1.1.4.2 ad * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 1.1.4.2 ad * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
101 1.1.4.2 ad * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
102 1.1.4.2 ad * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
103 1.1.4.2 ad * SUCH DAMAGE.
104 1.1.4.2 ad *
105 1.1.4.2 ad * @(#)machdep.c 8.3 (Berkeley) 1/12/94
106 1.1.4.2 ad * from: Utah Hdr: machdep.c 1.63 91/04/24
107 1.1.4.2 ad */
108 1.1.4.2 ad
109 1.1.4.2 ad #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
110 1.1.4.2 ad __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.1.4.2 2007/04/10 13:39:27 ad Exp $");
111 1.1.4.2 ad
112 1.1.4.2 ad #include "opt_ddb.h"
113 1.1.4.2 ad #include "opt_kgdb.h"
114 1.1.4.2 ad
115 1.1.4.2 ad #include "opt_memsize.h"
116 1.1.4.2 ad #include "opt_ethaddr.h"
117 1.1.4.2 ad
118 1.1.4.2 ad #include "opt_pci.h"
119 1.1.4.2 ad #include "pci.h"
120 1.1.4.2 ad
121 1.1.4.2 ad #include <sys/param.h>
122 1.1.4.2 ad #include <sys/systm.h>
123 1.1.4.2 ad #include <sys/kernel.h>
124 1.1.4.2 ad #include <sys/buf.h>
125 1.1.4.2 ad #include <sys/reboot.h>
126 1.1.4.2 ad #include <sys/user.h>
127 1.1.4.2 ad #include <sys/mount.h>
128 1.1.4.2 ad #include <sys/kcore.h>
129 1.1.4.2 ad #include <sys/boot_flag.h>
130 1.1.4.2 ad #include <sys/termios.h>
131 1.1.4.2 ad #include <sys/ksyms.h>
132 1.1.4.2 ad
133 1.1.4.2 ad #include <net/if.h>
134 1.1.4.2 ad #include <net/if_ether.h>
135 1.1.4.2 ad
136 1.1.4.2 ad #include <uvm/uvm_extern.h>
137 1.1.4.2 ad
138 1.1.4.2 ad #include <dev/cons.h>
139 1.1.4.2 ad
140 1.1.4.2 ad #include "ksyms.h"
141 1.1.4.2 ad
142 1.1.4.2 ad #if NKSYMS || defined(DDB) || defined(LKM)
143 1.1.4.2 ad #include <machine/db_machdep.h>
144 1.1.4.2 ad #include <ddb/db_extern.h>
145 1.1.4.2 ad #endif
146 1.1.4.2 ad
147 1.1.4.2 ad #include <mips/cache.h>
148 1.1.4.2 ad #include <mips/locore.h>
149 1.1.4.2 ad
150 1.1.4.2 ad #include <mips/adm5120/include/adm5120reg.h>
151 1.1.4.2 ad #include <mips/adm5120/include/adm5120var.h>
152 1.1.4.2 ad #include <mips/adm5120/include/adm5120_extiovar.h>
153 1.1.4.2 ad #include <mips/adm5120/include/adm5120_obiovar.h>
154 1.1.4.2 ad #include <mips/adm5120/include/adm5120_mainbusvar.h>
155 1.1.4.2 ad #include <mips/adm5120/include/adm5120_pcivar.h>
156 1.1.4.2 ad #include <mips/adm5120/dev/uart.h>
157 1.1.4.2 ad
158 1.1.4.2 ad #ifndef MEMSIZE
159 1.1.4.2 ad #define MEMSIZE 4 * 1024 * 1024
160 1.1.4.2 ad #endif /* !MEMSIZE */
161 1.1.4.2 ad
162 1.1.4.2 ad struct user *proc0paddr;
163 1.1.4.2 ad
164 1.1.4.2 ad /* Our exported CPU info; we can have only one. */
165 1.1.4.2 ad struct cpu_info cpu_info_store;
166 1.1.4.2 ad
167 1.1.4.2 ad /* Maps for VM objects. */
168 1.1.4.2 ad struct vm_map *exec_map = NULL;
169 1.1.4.2 ad struct vm_map *mb_map = NULL;
170 1.1.4.2 ad struct vm_map *phys_map = NULL;
171 1.1.4.2 ad
172 1.1.4.2 ad int physmem; /* # pages of physical memory */
173 1.1.4.2 ad int maxmem; /* max memory per process */
174 1.1.4.2 ad
175 1.1.4.2 ad int mem_cluster_cnt;
176 1.1.4.2 ad phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
177 1.1.4.2 ad
178 1.1.4.2 ad struct adm5120_config adm5120_configuration;
179 1.1.4.2 ad
180 1.1.4.2 ad void adm5120_setcpufreq(void);
181 1.1.4.2 ad
182 1.1.4.2 ad void
183 1.1.4.2 ad adm5120_setcpufreq(void)
184 1.1.4.2 ad {
185 1.1.4.2 ad uint32_t v, freq;
186 1.1.4.2 ad
187 1.1.4.2 ad v = SW_READ(SW_CODE_REG);
188 1.1.4.2 ad switch (v & CLKS_MASK) {
189 1.1.4.2 ad case CLKS_175MHZ:
190 1.1.4.2 ad freq = 175 * 1000 * 1000;
191 1.1.4.2 ad break;
192 1.1.4.2 ad case CLKS_200MHZ:
193 1.1.4.2 ad freq = 200 * 1000 * 1000;
194 1.1.4.2 ad break;
195 1.1.4.2 ad default:
196 1.1.4.2 ad panic("adm5120: cannot determine CPU clock speed");
197 1.1.4.2 ad }
198 1.1.4.2 ad
199 1.1.4.2 ad curcpu()->ci_cpu_freq = freq;
200 1.1.4.2 ad curcpu()->ci_cycles_per_hz = (freq + hz / 2) / hz / 2;
201 1.1.4.2 ad curcpu()->ci_divisor_delay = ((freq + 500000) / 1000000) / 2;
202 1.1.4.2 ad MIPS_SET_CI_RECIPRICAL(curcpu());
203 1.1.4.2 ad }
204 1.1.4.2 ad
205 1.1.4.2 ad void mach_init(int, char **, void *, void *); /* XXX */
206 1.1.4.2 ad
207 1.1.4.2 ad static void
208 1.1.4.2 ad copy_args(int argc, char **argv)
209 1.1.4.2 ad {
210 1.1.4.2 ad struct adm5120_config *admc = &adm5120_configuration;
211 1.1.4.2 ad int i;
212 1.1.4.2 ad char *buf;
213 1.1.4.2 ad size_t buflen, rc;
214 1.1.4.2 ad
215 1.1.4.2 ad buf = admc->args;
216 1.1.4.2 ad buflen = sizeof(admc->args);
217 1.1.4.2 ad
218 1.1.4.2 ad if (argc >= __arraycount(admc->argv))
219 1.1.4.2 ad panic("%s: too many boot args\n", __func__);
220 1.1.4.2 ad
221 1.1.4.2 ad for (i = 0; buflen > 0 && i < argc && argv[i] != NULL; i++) {
222 1.1.4.2 ad admc->argv[i] = buf;
223 1.1.4.2 ad if ((rc = strlcpy(buf, argv[i], buflen)) >= buflen)
224 1.1.4.2 ad panic("%s: boot args too long\n", __func__);
225 1.1.4.2 ad
226 1.1.4.2 ad buf += rc;
227 1.1.4.2 ad buflen -= rc;
228 1.1.4.2 ad *buf++ = '\0';
229 1.1.4.2 ad buflen--;
230 1.1.4.2 ad }
231 1.1.4.2 ad if (i < argc)
232 1.1.4.2 ad panic("%s: boot args too long\n", __func__);
233 1.1.4.2 ad
234 1.1.4.2 ad admc->argc = argc;
235 1.1.4.2 ad }
236 1.1.4.2 ad
237 1.1.4.2 ad static void
238 1.1.4.2 ad parse_args(prop_dictionary_t properties, int argc, char **argv,
239 1.1.4.2 ad uint32_t *memsizep)
240 1.1.4.2 ad {
241 1.1.4.2 ad char buf[32];
242 1.1.4.2 ad char *key, *val, *valend;
243 1.1.4.2 ad unsigned long tmp;
244 1.1.4.2 ad int i;
245 1.1.4.2 ad uint8_t enaddr[ETHER_ADDR_LEN];
246 1.1.4.2 ad
247 1.1.4.2 ad if (memsizep != NULL)
248 1.1.4.2 ad *memsizep = MEMSIZE;
249 1.1.4.2 ad
250 1.1.4.2 ad for (i = 0; i < argc && argv[i] != NULL; i++) {
251 1.1.4.2 ad if (strlcpy(buf, argv[i], sizeof(buf)) >= sizeof(buf))
252 1.1.4.2 ad goto err;
253 1.1.4.2 ad val = buf;
254 1.1.4.2 ad key = strsep(&val, "=");
255 1.1.4.2 ad if (val == NULL)
256 1.1.4.2 ad goto err;
257 1.1.4.2 ad if (strcmp(key, "mem") == 0) {
258 1.1.4.2 ad tmp = strtoul(val, &valend, 10);
259 1.1.4.2 ad if (val == valend || *valend != 'M')
260 1.1.4.2 ad goto err;
261 1.1.4.2 ad if (memsizep != NULL)
262 1.1.4.2 ad *memsizep = tmp * 1024 * 1024;
263 1.1.4.2 ad } else if (strcmp(key, "HZ") == 0)
264 1.1.4.2 ad ;
265 1.1.4.2 ad else if (strcmp(key, "gpio") == 0) {
266 1.1.4.2 ad prop_number_t pn;
267 1.1.4.2 ad
268 1.1.4.2 ad tmp = strtoul(val, &valend, 10);
269 1.1.4.2 ad if (val == valend || *valend != '\0')
270 1.1.4.2 ad goto err;
271 1.1.4.2 ad if (properties == NULL)
272 1.1.4.2 ad continue;
273 1.1.4.2 ad pn = prop_number_create_unsigned_integer(tmp);
274 1.1.4.2 ad if (pn == NULL) {
275 1.1.4.2 ad printf(
276 1.1.4.2 ad "%s: prop_number_create_unsigned_integer\n",
277 1.1.4.2 ad __func__);
278 1.1.4.2 ad continue;
279 1.1.4.2 ad }
280 1.1.4.2 ad if (!prop_dictionary_set(properties, "initial-gpio",
281 1.1.4.2 ad pn)) {
282 1.1.4.2 ad printf("%s: prop_dictionary_set(gpio)\n",
283 1.1.4.2 ad __func__);
284 1.1.4.2 ad }
285 1.1.4.2 ad prop_object_release(pn);
286 1.1.4.2 ad } else if (strcmp(key, "kmac") == 0) {
287 1.1.4.2 ad prop_data_t pd;
288 1.1.4.2 ad
289 1.1.4.2 ad ether_nonstatic_aton(enaddr, val);
290 1.1.4.2 ad if (properties == NULL)
291 1.1.4.2 ad continue;
292 1.1.4.2 ad pd = prop_data_create_data(enaddr, sizeof(enaddr));
293 1.1.4.2 ad if (pd == NULL) {
294 1.1.4.2 ad printf("%s: prop_data_create_data\n", __func__);
295 1.1.4.2 ad continue;
296 1.1.4.2 ad }
297 1.1.4.2 ad if (!prop_dictionary_set(properties, "mac-addr", pd)) {
298 1.1.4.2 ad printf("%s: prop_dictionary_set(mac)\n",
299 1.1.4.2 ad __func__);
300 1.1.4.2 ad }
301 1.1.4.2 ad prop_object_release(pd);
302 1.1.4.2 ad } else if (strcmp(key, "board") == 0)
303 1.1.4.2 ad printf("Routerboard %s\n", val);
304 1.1.4.2 ad else if (strcmp(key, "boot") == 0)
305 1.1.4.2 ad ;
306 1.1.4.2 ad continue;
307 1.1.4.2 ad err:
308 1.1.4.2 ad printf("bad argv[%d] (%s)\n", i, argv[i]);
309 1.1.4.2 ad }
310 1.1.4.2 ad }
311 1.1.4.2 ad
312 1.1.4.2 ad void
313 1.1.4.2 ad mach_init(int argc, char **argv, void *a2, void *a3)
314 1.1.4.2 ad {
315 1.1.4.2 ad struct adm5120_config *admc = &adm5120_configuration;
316 1.1.4.2 ad uint32_t memsize;
317 1.1.4.2 ad vaddr_t kernend;
318 1.1.4.2 ad u_long first, last;
319 1.1.4.2 ad vaddr_t v;
320 1.1.4.2 ad
321 1.1.4.2 ad extern char edata[], end[]; /* XXX */
322 1.1.4.2 ad
323 1.1.4.2 ad /* clear the BSS segment */
324 1.1.4.2 ad kernend = mips_round_page(end);
325 1.1.4.2 ad memset(edata, 0, kernend - (vaddr_t)edata);
326 1.1.4.2 ad
327 1.1.4.2 ad /* set CPU model info for sysctl_hw */
328 1.1.4.2 ad strcpy(cpu_model, "Infineon ADM5120");
329 1.1.4.2 ad
330 1.1.4.2 ad /*
331 1.1.4.2 ad * Set up the exception vectors and CPU-specific function
332 1.1.4.2 ad * vectors early on. We need the wbflush() vector set up
333 1.1.4.2 ad * before comcnattach() is called (or at least before the
334 1.1.4.2 ad * first printf() after that is called).
335 1.1.4.2 ad * Sets up mips_cpu_flags that may be queried by other
336 1.1.4.2 ad * functions called during startup.
337 1.1.4.2 ad * Also clears the I+D caches.
338 1.1.4.2 ad */
339 1.1.4.2 ad mips_vector_init();
340 1.1.4.2 ad
341 1.1.4.2 ad /*
342 1.1.4.2 ad * Set the VM page size.
343 1.1.4.2 ad */
344 1.1.4.2 ad uvm_setpagesize();
345 1.1.4.2 ad
346 1.1.4.2 ad adm5120_setcpufreq();
347 1.1.4.2 ad
348 1.1.4.2 ad /*
349 1.1.4.2 ad * Initialize bus space tags.
350 1.1.4.2 ad */
351 1.1.4.2 ad obio_bus_mem_init(&admc->obio_space, admc);
352 1.1.4.2 ad extio_bus_mem_init(&admc->extio_space, admc);
353 1.1.4.2 ad #if NPCI > 0
354 1.1.4.2 ad pciio_bus_mem_init(&admc->pciio_space, admc);
355 1.1.4.2 ad pcimem_bus_mem_init(&admc->pcimem_space, admc);
356 1.1.4.2 ad #endif
357 1.1.4.2 ad
358 1.1.4.2 ad /*
359 1.1.4.2 ad * Initialize bus DMA tag.
360 1.1.4.2 ad */
361 1.1.4.2 ad obio_dma_init(&admc->obio_dmat);
362 1.1.4.2 ad
363 1.1.4.2 ad /*
364 1.1.4.2 ad * Attach serial console.
365 1.1.4.2 ad */
366 1.1.4.2 ad uart_cnattach();
367 1.1.4.2 ad
368 1.1.4.2 ad /*
369 1.1.4.2 ad * Look at arguments passed to us and compute boothowto.
370 1.1.4.2 ad */
371 1.1.4.2 ad boothowto = RB_AUTOBOOT;
372 1.1.4.2 ad #ifdef KADB
373 1.1.4.2 ad boothowto |= RB_KDB;
374 1.1.4.2 ad #endif
375 1.1.4.2 ad
376 1.1.4.2 ad parse_args(NULL, argc, argv, &memsize);
377 1.1.4.2 ad
378 1.1.4.2 ad /*
379 1.1.4.2 ad * Determine the memory size.
380 1.1.4.2 ad *
381 1.1.4.2 ad * Note: Reserve the first page! That's where the trap
382 1.1.4.2 ad * vectors are located.
383 1.1.4.2 ad */
384 1.1.4.2 ad
385 1.1.4.2 ad #if 0
386 1.1.4.2 ad if (GET_MEMSIZE(memsize) == 0) {
387 1.1.4.2 ad uint32_t val;
388 1.1.4.2 ad
389 1.1.4.2 ad /* This does not seem to work... --dyoung */
390 1.1.4.2 ad val = SW_READ(SW_MEMCONT_REG);
391 1.1.4.2 ad printf("SW_MEMCONT_REG: 0x%08" PRIx32 "\n", val);
392 1.1.4.2 ad switch (val & SDRAM_SIZE_MASK) {
393 1.1.4.2 ad case SDRAM_SIZE_4MBYTES:
394 1.1.4.2 ad memsize = 4 * 1024 * 1024;
395 1.1.4.2 ad break;
396 1.1.4.2 ad case SDRAM_SIZE_8MBYTES:
397 1.1.4.2 ad memsize = 8 * 1024 * 1024;
398 1.1.4.2 ad break;
399 1.1.4.2 ad case SDRAM_SIZE_16MBYTES:
400 1.1.4.2 ad memsize = 16 * 1024 * 1024;
401 1.1.4.2 ad break;
402 1.1.4.2 ad case SDRAM_SIZE_64MBYTES:
403 1.1.4.2 ad memsize = 64 * 1024 * 1024;
404 1.1.4.2 ad break;
405 1.1.4.2 ad case SDRAM_SIZE_128MBYTES:
406 1.1.4.2 ad memsize = 128 * 1024 * 1024;
407 1.1.4.2 ad break;
408 1.1.4.2 ad default:
409 1.1.4.2 ad panic("adm5120: cannot determine memory size");
410 1.1.4.2 ad }
411 1.1.4.2 ad }
412 1.1.4.2 ad #endif
413 1.1.4.2 ad
414 1.1.4.2 ad physmem = btoc(memsize);
415 1.1.4.2 ad
416 1.1.4.2 ad mem_clusters[mem_cluster_cnt].start = PAGE_SIZE;
417 1.1.4.2 ad mem_clusters[mem_cluster_cnt].size =
418 1.1.4.2 ad memsize - mem_clusters[mem_cluster_cnt].start;
419 1.1.4.2 ad mem_cluster_cnt++;
420 1.1.4.2 ad
421 1.1.4.2 ad /*
422 1.1.4.2 ad * Load the rest of the available pages into the VM system.
423 1.1.4.2 ad */
424 1.1.4.2 ad first = round_page(MIPS_KSEG0_TO_PHYS(kernend));
425 1.1.4.2 ad last = mem_clusters[0].start + mem_clusters[0].size;
426 1.1.4.2 ad uvm_page_physload(atop(first), atop(last), atop(first), atop(last),
427 1.1.4.2 ad VM_FREELIST_DEFAULT);
428 1.1.4.2 ad
429 1.1.4.2 ad /*
430 1.1.4.2 ad * Initialize message buffer (at end of core).
431 1.1.4.2 ad */
432 1.1.4.2 ad mips_init_msgbuf();
433 1.1.4.2 ad
434 1.1.4.2 ad /*
435 1.1.4.2 ad * Initialize the virtual memory system.
436 1.1.4.2 ad */
437 1.1.4.2 ad pmap_bootstrap();
438 1.1.4.2 ad
439 1.1.4.2 ad /*
440 1.1.4.2 ad * Init mapping for u page(s) for proc0.
441 1.1.4.2 ad */
442 1.1.4.2 ad v = uvm_pageboot_alloc(USPACE);
443 1.1.4.2 ad lwp0.l_addr = proc0paddr = (struct user *)v;
444 1.1.4.2 ad lwp0.l_md.md_regs = (struct frame *)(v + USPACE) - 1;
445 1.1.4.2 ad curpcb = &lwp0.l_addr->u_pcb;
446 1.1.4.2 ad curpcb->pcb_context[11] = MIPS_INT_MASK | MIPS_SR_INT_IE; /* SR */
447 1.1.4.2 ad
448 1.1.4.2 ad /*
449 1.1.4.2 ad * Initialize debuggers, and break into them, if appropriate.
450 1.1.4.2 ad */
451 1.1.4.2 ad #if NKSYMS || defined(DDB) || defined(LKM)
452 1.1.4.2 ad ksyms_init(0, 0, 0);
453 1.1.4.2 ad #endif
454 1.1.4.2 ad #ifdef DDB
455 1.1.4.2 ad if (boothowto & RB_KDB)
456 1.1.4.2 ad Debugger();
457 1.1.4.2 ad #endif
458 1.1.4.2 ad
459 1.1.4.2 ad copy_args(argc, argv);
460 1.1.4.2 ad }
461 1.1.4.2 ad
462 1.1.4.2 ad void
463 1.1.4.2 ad consinit(void)
464 1.1.4.2 ad {
465 1.1.4.2 ad
466 1.1.4.2 ad /*
467 1.1.4.2 ad * Everything related to console initialization is done
468 1.1.4.2 ad * in mach_init().
469 1.1.4.2 ad */
470 1.1.4.2 ad }
471 1.1.4.2 ad
472 1.1.4.2 ad void
473 1.1.4.2 ad cpu_startup(void)
474 1.1.4.2 ad {
475 1.1.4.2 ad struct adm5120_config *admc = &adm5120_configuration;
476 1.1.4.2 ad char pbuf[9];
477 1.1.4.2 ad vaddr_t minaddr, maxaddr;
478 1.1.4.2 ad #ifdef DEBUG
479 1.1.4.2 ad extern int pmapdebug; /* XXX */
480 1.1.4.2 ad int opmapdebug = pmapdebug;
481 1.1.4.2 ad
482 1.1.4.2 ad pmapdebug = 0; /* Shut up pmap debug during bootstrap */
483 1.1.4.2 ad #endif
484 1.1.4.2 ad
485 1.1.4.2 ad if ((admc->properties = prop_dictionary_create()) == NULL)
486 1.1.4.2 ad printf("%s: prop_dictionary_create\n", __func__);
487 1.1.4.2 ad parse_args(admc->properties, admc->argc, admc->argv, NULL);
488 1.1.4.2 ad
489 1.1.4.2 ad /*
490 1.1.4.2 ad * Good {morning,afternoon,evening,night}.
491 1.1.4.2 ad */
492 1.1.4.2 ad printf("%s%s", copyright, version);
493 1.1.4.2 ad printf("%s\n", cpu_model);
494 1.1.4.2 ad format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
495 1.1.4.2 ad printf("total memory = %s\n", pbuf);
496 1.1.4.2 ad
497 1.1.4.2 ad minaddr = 0;
498 1.1.4.2 ad /*
499 1.1.4.2 ad * Allocate a submap for exec arguments. This map effectively
500 1.1.4.2 ad * limits the number of processes exec'ing at any time.
501 1.1.4.2 ad */
502 1.1.4.2 ad exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
503 1.1.4.2 ad 16 * NCARGS, VM_MAP_PAGEABLE, FALSE, NULL);
504 1.1.4.2 ad
505 1.1.4.2 ad /*
506 1.1.4.2 ad * Allocate a submap for physio
507 1.1.4.2 ad */
508 1.1.4.2 ad phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
509 1.1.4.2 ad VM_PHYS_SIZE, 0, FALSE, NULL);
510 1.1.4.2 ad
511 1.1.4.2 ad /*
512 1.1.4.2 ad * No need to allocate an mbuf cluster submap. Mbuf clusters
513 1.1.4.2 ad * are allocated via the pool allocator, and we use KSEG to
514 1.1.4.2 ad * map those pages.
515 1.1.4.2 ad */
516 1.1.4.2 ad
517 1.1.4.2 ad #ifdef DEBUG
518 1.1.4.2 ad pmapdebug = opmapdebug;
519 1.1.4.2 ad #endif
520 1.1.4.2 ad format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
521 1.1.4.2 ad printf("avail memory = %s\n", pbuf);
522 1.1.4.2 ad }
523 1.1.4.2 ad
524 1.1.4.2 ad void
525 1.1.4.2 ad cpu_reboot(int howto, char *bootstr)
526 1.1.4.2 ad {
527 1.1.4.2 ad static int waittime = -1;
528 1.1.4.2 ad
529 1.1.4.2 ad /* Take a snapshot before clobbering any registers. */
530 1.1.4.2 ad if (curproc)
531 1.1.4.2 ad savectx((struct user *)curpcb);
532 1.1.4.2 ad
533 1.1.4.2 ad /* If "always halt" was specified as a boot flag, obey. */
534 1.1.4.2 ad if (boothowto & RB_HALT)
535 1.1.4.2 ad howto |= RB_HALT;
536 1.1.4.2 ad
537 1.1.4.2 ad boothowto = howto;
538 1.1.4.2 ad
539 1.1.4.2 ad /* If system is cold, just halt. */
540 1.1.4.2 ad if (cold) {
541 1.1.4.2 ad boothowto |= RB_HALT;
542 1.1.4.2 ad goto haltsys;
543 1.1.4.2 ad }
544 1.1.4.2 ad
545 1.1.4.2 ad if ((boothowto & RB_NOSYNC) == 0 && waittime < 0) {
546 1.1.4.2 ad waittime = 0;
547 1.1.4.2 ad
548 1.1.4.2 ad /*
549 1.1.4.2 ad * Synchronize the disks....
550 1.1.4.2 ad */
551 1.1.4.2 ad vfs_shutdown();
552 1.1.4.2 ad
553 1.1.4.2 ad /*
554 1.1.4.2 ad * If we've been adjusting the clock, the todr
555 1.1.4.2 ad * will be out of synch; adjust it now.
556 1.1.4.2 ad */
557 1.1.4.2 ad resettodr();
558 1.1.4.2 ad }
559 1.1.4.2 ad
560 1.1.4.2 ad /* Disable interrupts. */
561 1.1.4.2 ad splhigh();
562 1.1.4.2 ad
563 1.1.4.2 ad if (boothowto & RB_DUMP)
564 1.1.4.2 ad dumpsys();
565 1.1.4.2 ad
566 1.1.4.2 ad haltsys:
567 1.1.4.2 ad /* Run any shutdown hooks. */
568 1.1.4.2 ad doshutdownhooks();
569 1.1.4.2 ad
570 1.1.4.2 ad /*
571 1.1.4.2 ad * Routerboard BIOS may autoboot, so "pseudo-halt".
572 1.1.4.2 ad */
573 1.1.4.2 ad if (boothowto & RB_HALT) {
574 1.1.4.2 ad printf("\n");
575 1.1.4.2 ad printf("The operating system has halted.\n");
576 1.1.4.2 ad printf("Please press any key to reboot.\n\n");
577 1.1.4.2 ad cnpollc(1); /* For proper keyboard command handling */
578 1.1.4.2 ad cngetc();
579 1.1.4.2 ad cnpollc(0);
580 1.1.4.2 ad }
581 1.1.4.2 ad
582 1.1.4.2 ad printf("reseting board...\n\n");
583 1.1.4.2 ad mips_icache_sync_all();
584 1.1.4.2 ad mips_dcache_wbinv_all();
585 1.1.4.2 ad SW_WRITE(SW_SFTRES_REG, 0); /* reset */
586 1.1.4.2 ad for (;;)
587 1.1.4.2 ad /* spin forever */ ; /* XXX */
588 1.1.4.2 ad /*NOTREACHED*/
589 1.1.4.2 ad }
590