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