machdep.c revision 1.1.2.12 1 /* $NetBSD: machdep.c,v 1.1.2.12 2010/01/03 08:37:14 cliff Exp $ */
2
3 /*
4 * Copyright 2001, 2002 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 /*
39 * Copyright (c) 1992, 1993
40 * The Regents of the University of California. All rights reserved.
41 *
42 * This code is derived from software contributed to Berkeley by
43 * the Systems Programming Group of the University of Utah Computer
44 * Science Department, The Mach Operating System project at
45 * Carnegie-Mellon University and Ralph Campbell.
46 *
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
49 * are met:
50 * 1. Redistributions of source code must retain the above copyright
51 * notice, this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright
53 * notice, this list of conditions and the following disclaimer in the
54 * documentation and/or other materials provided with the distribution.
55 * 3. Neither the name of the University nor the names of its contributors
56 * may be used to endorse or promote products derived from this software
57 * without specific prior written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 *
71 * @(#)machdep.c 8.3 (Berkeley) 1/12/94
72 * from: Utah Hdr: machdep.c 1.63 91/04/24
73 */
74 /*
75 * Copyright (c) 1988 University of Utah.
76 *
77 * This code is derived from software contributed to Berkeley by
78 * the Systems Programming Group of the University of Utah Computer
79 * Science Department, The Mach Operating System project at
80 * Carnegie-Mellon University and Ralph Campbell.
81 *
82 * Redistribution and use in source and binary forms, with or without
83 * modification, are permitted provided that the following conditions
84 * are met:
85 * 1. Redistributions of source code must retain the above copyright
86 * notice, this list of conditions and the following disclaimer.
87 * 2. Redistributions in binary form must reproduce the above copyright
88 * notice, this list of conditions and the following disclaimer in the
89 * documentation and/or other materials provided with the distribution.
90 * 3. All advertising materials mentioning features or use of this software
91 * must display the following acknowledgement:
92 * This product includes software developed by the University of
93 * California, Berkeley and its contributors.
94 * 4. Neither the name of the University nor the names of its contributors
95 * may be used to endorse or promote products derived from this software
96 * without specific prior written permission.
97 *
98 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
99 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
100 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
101 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
102 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
103 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
104 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
105 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
106 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
107 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
108 * SUCH DAMAGE.
109 *
110 * @(#)machdep.c 8.3 (Berkeley) 1/12/94
111 * from: Utah Hdr: machdep.c 1.63 91/04/24
112 */
113
114 #include <sys/cdefs.h>
115 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.1.2.12 2010/01/03 08:37:14 cliff Exp $");
116
117 #include "opt_ddb.h"
118 #include "opt_com.h"
119 #include "opt_execfmt.h"
120 #include "opt_memsize.h"
121
122 #include <sys/param.h>
123 #include <sys/systm.h>
124 #include <sys/kernel.h>
125 #include <sys/buf.h>
126 #include <sys/reboot.h>
127 #include <sys/user.h>
128 #include <sys/mount.h>
129 #include <sys/kcore.h>
130 #include <sys/boot_flag.h>
131 #include <sys/termios.h>
132 #include <sys/ksyms.h>
133 #include <sys/bus.h>
134 #include <sys/device.h>
135 #include <sys/extent.h>
136 #include <sys/malloc.h>
137
138 #include <uvm/uvm_extern.h>
139
140 #include <dev/cons.h>
141
142 #include "ksyms.h"
143
144 #if NKSYMS || defined(DDB) || defined(LKM)
145 #include <machine/db_machdep.h>
146 #include <ddb/db_extern.h>
147 #endif
148
149 #include <machine/cpu.h>
150 #include <machine/psl.h>
151
152 #include "com.h"
153 #if NCOM == 0
154 #error no serial console
155 #endif
156
157 #include <dev/ic/comreg.h>
158 #include <dev/ic/comvar.h>
159
160 #include <mips/rmi/rmixl_comvar.h>
161 #include <mips/rmi/rmixlvar.h>
162 #include <mips/rmi/rmixl_firmware.h>
163 #include <mips/rmi/rmixlreg.h>
164
165 #ifdef MACHDEP_DEBUG
166 int machdep_debug=MACHDEP_DEBUG;
167 # define DPRINTF(x) do { if (machdep_debug) printf x ; } while(0)
168 #else
169 # define DPRINTF(x)
170 #endif
171
172 #ifndef CONSFREQ
173 # define CONSFREQ 66000000
174 #endif
175 #ifndef CONSPEED
176 # define CONSPEED 38400
177 #endif
178 #ifndef CONMODE
179 # define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)
180 #endif
181 #ifndef CONSADDR
182 # define CONSADDR RMIXL_IO_DEV_UART_1
183 #endif
184
185 int comcnfreq = CONSFREQ;
186 int comcnspeed = CONSPEED;
187 tcflag_t comcnmode = CONMODE;
188 bus_addr_t comcnaddr = (bus_addr_t)CONSADDR;
189
190 struct rmixl_config rmixl_configuration;
191
192
193 /*
194 * array of tested firmware versions
195 * if you find new ones and they work
196 * please add them
197 */
198 static uint64_t rmiclfw_psb_versions[] = {
199 0x4958d4fb00000056ULL,
200 0x49a5a8fa00000056ULL,
201 0x4aacdb6a00000056ULL,
202 };
203 #define RMICLFW_PSB_VERSIONS_LEN \
204 (sizeof(rmiclfw_psb_versions)/sizeof(rmiclfw_psb_versions[0]))
205
206 /*
207 * kernel copies of firmware info
208 */
209 static rmixlfw_info_t rmixlfw_info;
210 static rmixlfw_mmap_t rmixlfw_phys_mmap;
211 static rmixlfw_mmap_t rmixlfw_avail_mmap;
212 #define RMIXLFW_INFOP_LEGAL 0x8c000000
213
214
215 /*
216 * storage for fixed extent used to allocate physical address regions
217 * because extent(9) start and end values are u_long, they are only
218 * 32 bits on a 32 bit kernel, which is insuffucuent since XLS physical
219 * address is 40 bits wide. So the "physaddr" map stores regions
220 * in units of megabytes.
221 */
222 static u_long rmixl_physaddr_storage[
223 EXTENT_FIXED_STORAGE_SIZE(32)/sizeof(u_long)
224 ];
225
226 /* For sysctl_hw. */
227 extern char cpu_model[];
228
229 /* Our exported CPU info; we can have only one. */
230 struct cpu_info cpu_info_store;
231
232 /* Maps for VM objects. */
233 struct vm_map *mb_map = NULL;
234 struct vm_map *phys_map = NULL;
235
236 int physmem; /* Total physical memory */
237
238 int netboot; /* Are we netbooting? */
239
240
241 phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
242 u_int mem_cluster_cnt;
243
244
245 void configure(void);
246 void mach_init(int, int32_t *, void *, int64_t);
247 static u_long rmixlfw_init(int64_t);
248 static u_long mem_clusters_init(rmixlfw_mmap_t *, rmixlfw_mmap_t *);
249 static void __attribute__((__noreturn__)) rmixl_reset(void);
250 static void rmixl_physaddr_init(void);
251 static u_int ram_seg_resv(phys_ram_seg_t *, u_int, u_quad_t, u_quad_t);
252 void rmixlfw_mmap_print(rmixlfw_mmap_t *);
253
254
255 /*
256 * safepri is a safe priority for sleep to set for a spin-wait during
257 * autoconfiguration or after a panic. Used as an argument to splx().
258 */
259 int safepri = MIPS1_PSL_LOWIPL;
260
261 /*
262 * Do all the stuff that locore normally does before calling main().
263 */
264 void
265 mach_init(int argc, int32_t *argv, void *envp, int64_t infop)
266 {
267 struct rmixl_config *rcp = &rmixl_configuration;
268 void *kernend;
269 u_long memsize;
270 u_int vm_cluster_cnt;
271 uint32_t r;
272 phys_ram_seg_t vm_clusters[VM_PHYSSEG_MAX];
273 extern char edata[], end[];
274
275 rmixl_mtcr(0, 1); /* disable all threads except #0 */
276
277 r = rmixl_mfcr(0x300);
278 r &= ~__BIT(14); /* disabled Unaligned Access */
279 rmixl_mtcr(0x300, r);
280
281 rmixl_mtcr(0x400, 0); /* enable MMU clock gating */
282 /* set single MMU Thread Mode */
283 /* TLB is partitioned (1 partition) */
284
285 /*
286 * Clear the BSS segment.
287 */
288 kernend = (void *)mips_round_page(end);
289 memset(edata, 0, (char *)kernend - edata);
290
291 /*
292 * Set up the exception vectors and CPU-specific function
293 * vectors early on. We need the wbflush() vector set up
294 * before comcnattach() is called (or at least before the
295 * first printf() after that is called).
296 * Also clears the I+D caches.
297 */
298 mips_vector_init();
299
300 memsize = rmixlfw_init(infop);
301
302 /* set the VM page size */
303 uvm_setpagesize();
304
305 physmem = btoc(memsize);
306
307 rmixl_obio_eb_bus_mem_init(&rcp->rc_obio_eb_memt, rcp);
308
309 #if NCOM > 0
310 rmixl_com_cnattach(comcnaddr, comcnspeed, comcnfreq,
311 COM_TYPE_NORMAL, comcnmode);
312 #endif
313
314 printf("\nNetBSD/rmixl\n");
315 printf("memsize = %#lx\n", memsize);
316
317 rmixl_physaddr_init();
318
319 /*
320 * Obtain the cpu frequency
321 * Compute the number of ticks for hz.
322 * Compute the delay divisor.
323 * Double the Hz if this CPU runs at twice the
324 * external/cp0-count frequency
325 */
326 curcpu()->ci_cpu_freq = rmixlfw_info.cpu_frequency;
327 curcpu()->ci_cycles_per_hz = (curcpu()->ci_cpu_freq + hz / 2) / hz;
328 curcpu()->ci_divisor_delay =
329 ((curcpu()->ci_cpu_freq + 500000) / 1000000);
330 if (mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
331 curcpu()->ci_cpu_freq *= 2;
332
333 /*
334 * Look at arguments passed to us and compute boothowto.
335 * - rmixl firmware gives us a 32 bit argv[i], so adapt
336 * by forcing sign extension in cast to (char *)
337 */
338 boothowto = RB_AUTOBOOT;
339 for (int i = 1; i < argc; i++) {
340 for (char *cp = (char *)(intptr_t)argv[i]; *cp; cp++) {
341 int howto;
342 /* Ignore superfluous '-', if there is one */
343 if (*cp == '-')
344 continue;
345
346 howto = 0;
347 BOOT_FLAG(*cp, howto);
348 if (howto != 0)
349 boothowto |= howto;
350 #ifdef DIAGNOSTIC
351 else
352 printf("bootflag '%c' not recognised\n", *cp);
353 #endif
354 }
355 }
356 #ifdef DIAGNOSTIC
357 printf("boothowto %#x\n", boothowto);
358 #endif
359
360 /*
361 * Reserve pages from the VM system.
362 * to maintain mem_clusters[] as a map of raw ram,
363 * copy into temporary table vm_clusters[]
364 * work on that and use it to feed vm_physload()
365 */
366 KASSERT(sizeof(mem_clusters) == sizeof(vm_clusters));
367 memcpy(&vm_clusters, &mem_clusters, sizeof(vm_clusters));
368 vm_cluster_cnt = mem_cluster_cnt;
369
370 /* reserve 0..start..kernend pages */
371 vm_cluster_cnt = ram_seg_resv(vm_clusters, vm_cluster_cnt,
372 0, round_page(MIPS_KSEG0_TO_PHYS(kernend)));
373
374 /* reserve reset exception vector page */
375 /* should never be in our clusters anyway... */
376 vm_cluster_cnt = ram_seg_resv(vm_clusters, vm_cluster_cnt,
377 0x1FC00000, 0x1FC00000+NBPG);
378
379 /*
380 * Load vm_clusters[] into the VM system.
381 */
382 mips_page_physload(MIPS_KSEG0_START, (vaddr_t) kernend,
383 vm_clusters, vm_cluster_cnt, NULL, 0);
384
385 /*
386 * Initialize error message buffer (at end of core).
387 */
388 mips_init_msgbuf();
389
390 pmap_bootstrap();
391
392 /*
393 * Allocate space for proc0's USPACE.
394 */
395 mips_init_lwp0_uarea();
396
397 /*
398 * Initialize debuggers, and break into them, if appropriate.
399 */
400 #if NKSYMS || defined(DDB) || defined(LKM)
401 ksyms_init(0, 0, 0);
402 #endif
403
404 #if defined(DDB)
405 if (boothowto & RB_KDB)
406 Debugger();
407 #endif
408 }
409
410 /*
411 * ram_seg_resv - cut reserved regions out of segs, fragmenting as needed
412 *
413 * we simply build a new table of segs, then copy it back over the given one
414 * this is inefficient but simple and called only a few times
415 *
416 * note: 'last' here means 1st addr past the end of the segment (start+size)
417 */
418 static u_int
419 ram_seg_resv(phys_ram_seg_t *segs, u_int nsegs,
420 u_quad_t resv_first, u_quad_t resv_last)
421 {
422 u_quad_t first, last;
423 int new_nsegs=0;
424 int resv_flag;
425 phys_ram_seg_t new_segs[VM_PHYSSEG_MAX];
426
427 for (u_int i=0; i < nsegs; i++) {
428 resv_flag = 0;
429 first = trunc_page(segs[i].start);
430 last = round_page(segs[i].start + segs[i].size);
431
432 KASSERT(new_nsegs < VM_PHYSSEG_MAX);
433 if ((resv_first <= first) && (resv_last >= last)) {
434 /* whole segment is resverved */
435 continue;
436 }
437 if ((resv_first > first) && (resv_first < last)) {
438 u_quad_t new_last;
439
440 /*
441 * reserved start in segment
442 * salvage the leading fragment
443 */
444 resv_flag = 1;
445 new_last = last - (last - resv_first);
446 KASSERT (new_last > first);
447 new_segs[new_nsegs].start = first;
448 new_segs[new_nsegs].size = new_last - first;
449 new_nsegs++;
450 }
451 if ((resv_last > first) && (resv_last < last)) {
452 u_quad_t new_first;
453
454 /*
455 * reserved end in segment
456 * salvage the trailing fragment
457 */
458 resv_flag = 1;
459 new_first = first + (resv_last - first);
460 KASSERT (last > (new_first + NBPG));
461 new_segs[new_nsegs].start = new_first;
462 new_segs[new_nsegs].size = last - new_first;
463 new_nsegs++;
464 }
465 if (resv_flag == 0) {
466 /*
467 * nothing reserved here, take it all
468 */
469 new_segs[new_nsegs].start = first;
470 new_segs[new_nsegs].size = last - first;
471 new_nsegs++;
472 }
473
474 }
475
476 memcpy(segs, new_segs, sizeof(new_segs));
477
478 return new_nsegs;
479 }
480
481 /*
482 * create an extent for physical address space
483 * these are in units of MB for sake of compression (for sake of 32 bit kernels)
484 * allocate the regions where we have known functions (DRAM, IO, etc)
485 * what remains can be allocated as needed for other stuff
486 * e.g. to configure BARs that are not already initialized and enabled.
487 */
488 static void
489 rmixl_physaddr_init(void)
490 {
491 struct extent *ext;
492 unsigned long start = 0UL;
493 unsigned long end = (__BIT(40) / (1024 * 1024)) -1;
494 u_long base;
495 u_long size;
496 uint32_t r;
497
498 ext = extent_create("physaddr", start, end, M_DEVBUF,
499 (void *)rmixl_physaddr_storage, sizeof(rmixl_physaddr_storage),
500 EX_NOWAIT | EX_NOCOALESCE);
501
502 if (ext == NULL)
503 panic("%s: extent_create failed", __func__);
504
505 /*
506 * grab regions per DRAM BARs
507 */
508 for (u_int i=0; i < RMIXL_SBC_DRAM_NBARS; i++) {
509 r = RMIXL_IOREG_READ(RMIXL_SBC_DRAM_BAR(i));
510 if ((r & RMIXL_DRAM_BAR_STATUS) == 0)
511 continue; /* not enabled */
512 base = (u_long)(DRAM_BAR_TO_BASE((uint64_t)r) / (1024 * 1024));
513 size = (u_long)(DRAM_BAR_TO_SIZE((uint64_t)r) / (1024 * 1024));
514
515 DPRINTF(("%s: %d: %d: 0x%08x -- 0x%010lx:%lu MB\n",
516 __func__, __LINE__, i, r, base * (1024 * 1024), size));
517 if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
518 panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
519 "failed", __func__, ext, base, size, EX_NOWAIT);
520 }
521
522 /*
523 * grab regions per PCIe CFG, ECFG, IO, MEM BARs
524 */
525 r = RMIXL_IOREG_READ(RMIXL_SBC_PCIE_CFG_BAR);
526 if ((r & RMIXL_PCIE_CFG_BAR_ENB) != 0) {
527 base = (u_long)(RMIXL_PCIE_CFG_BAR_TO_BA((uint64_t)r)
528 / (1024 * 1024));
529 size = (u_long)RMIXL_PCIE_CFG_SIZE / (1024 * 1024);
530 DPRINTF(("%s: %d: %s: 0x%08x -- 0x%010lx:%ld MB\n", __func__,
531 __LINE__, "CFG", r, base * 1024 * 1024, size));
532 if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
533 panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
534 "failed", __func__, ext, base, size, EX_NOWAIT);
535 }
536 r = RMIXL_IOREG_READ(RMIXL_SBC_PCIE_ECFG_BAR);
537 if ((r & RMIXL_PCIE_ECFG_BAR_ENB) != 0) {
538 base = (u_long)(RMIXL_PCIE_ECFG_BAR_TO_BA((uint64_t)r)
539 / (1024 * 1024));
540 size = (u_long)RMIXL_PCIE_ECFG_SIZE / (1024 * 1024);
541 DPRINTF(("%s: %d: %s: 0x%08x -- 0x%010lx:%ld MB\n", __func__,
542 __LINE__, "ECFG", r, base * 1024 * 1024, size));
543 if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
544 panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
545 "failed", __func__, ext, base, size, EX_NOWAIT);
546 }
547 r = RMIXL_IOREG_READ(RMIXL_SBC_PCIE_MEM_BAR);
548 if ((r & RMIXL_PCIE_MEM_BAR_ENB) != 0) {
549 base = (u_long)(RMIXL_PCIE_MEM_BAR_TO_BA((uint64_t)r)
550 / (1024 * 1024));
551 size = (u_long)(RMIXL_PCIE_MEM_BAR_TO_SIZE((uint64_t)r)
552 / (1024 * 1024));
553 DPRINTF(("%s: %d: %s: 0x%08x -- 0x%010lx:%ld MB\n", __func__,
554 __LINE__, "MEM", r, base * 1024 * 1024, size));
555 if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
556 panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
557 "failed", __func__, ext, base, size, EX_NOWAIT);
558 }
559 r = RMIXL_IOREG_READ(RMIXL_SBC_PCIE_IO_BAR);
560 if ((r & RMIXL_PCIE_IO_BAR_ENB) != 0) {
561 base = (u_long)(RMIXL_PCIE_IO_BAR_TO_BA((uint64_t)r)
562 / (1024 * 1024));
563 size = (u_long)(RMIXL_PCIE_IO_BAR_TO_SIZE((uint64_t)r)
564 / (1024 * 1024));
565 DPRINTF(("%s: %d: %s: 0x%08x -- 0x%010lx:%ld MB\n", __func__,
566 __LINE__, "IO", r, base * 1024 * 1024, size));
567 if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
568 panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
569 "failed", __func__, ext, base, size, EX_NOWAIT);
570 }
571
572 /*
573 * at this point all regions left in "physaddr" extent
574 * are unused holes in the physical adress space
575 * available for use as needed.
576 */
577 rmixl_configuration.rc_phys_ex = ext;
578 #ifdef MACHDEP_DEBUG
579 extent_print(ext);
580 #endif
581 }
582
583 static u_long
584 rmixlfw_init(int64_t infop)
585 {
586 struct rmixl_config *rcp = &rmixl_configuration;
587
588 strcpy(cpu_model, "RMI XLS616ATX VIIA"); /* XXX */
589
590 infop |= MIPS_KSEG0_START;
591 rmixlfw_info = *(rmixlfw_info_t *)(intptr_t)infop;
592
593 for (int i=0; i < RMICLFW_PSB_VERSIONS_LEN; i++) {
594 if (rmiclfw_psb_versions[i] == rmixlfw_info.psb_version)
595 goto found;
596 }
597
598 rcp->rc_io_pbase = RMIXL_IO_DEV_PBASE;
599 rmixl_putchar_init(rcp->rc_io_pbase);
600
601 #ifdef DIAGNOSTIC
602 rmixl_puts("\r\nWARNING: untested psb_version: ");
603 rmixl_puthex64(rmixlfw_info.psb_version);
604 rmixl_puts("\r\n");
605 #endif
606
607 /* XXX trust and use MEMSIZE */
608 mem_clusters[0].start = 0;
609 mem_clusters[0].size = MEMSIZE;
610 mem_cluster_cnt = 1;
611 return MEMSIZE;
612
613 found:
614 rcp->rc_io_pbase = MIPS_KSEG1_TO_PHYS(rmixlfw_info.io_base);
615 rmixl_putchar_init(rcp->rc_io_pbase);
616 #ifdef MACHDEP_DEBUG
617 rmixl_puts("\r\ninfop: ");
618 rmixl_puthex64((uint64_t)(intptr_t)infop);
619 #endif
620 #ifdef DIAGNOSTIC
621 rmixl_puts("\r\nrecognized psb_version: ");
622 rmixl_puthex64(rmixlfw_info.psb_version);
623 rmixl_puts("\r\n");
624 #endif
625
626 return mem_clusters_init(
627 (rmixlfw_mmap_t *)(intptr_t)rmixlfw_info.psb_physaddr_map,
628 (rmixlfw_mmap_t *)(intptr_t)rmixlfw_info.avail_mem_map);
629 }
630
631 void
632 rmixlfw_mmap_print(rmixlfw_mmap_t *map)
633 {
634 #ifdef MACHDEP_DEBUG
635 for (uint32_t i=0; i < map->nmmaps; i++) {
636 rmixl_puthex32(i);
637 rmixl_puts(", ");
638 rmixl_puthex64(map->entry[i].start);
639 rmixl_puts(", ");
640 rmixl_puthex64(map->entry[i].size);
641 rmixl_puts(", ");
642 rmixl_puthex32(map->entry[i].type);
643 rmixl_puts("\r\n");
644 }
645 #endif
646 }
647
648 /*
649 * mem_clusters_init
650 *
651 * initialize mem_clusters[] table based on memory address mapping
652 * provided by boot firmware.
653 *
654 * prefer avail_mem_map if we can, otherwise use psb_physaddr_map.
655 * these will be limited by MEMSIZE if it is configured.
656 * if neither are available, just use MEMSIZE.
657 */
658 static u_long
659 mem_clusters_init(
660 rmixlfw_mmap_t *psb_physaddr_map,
661 rmixlfw_mmap_t *avail_mem_map)
662 {
663 rmixlfw_mmap_t *map = NULL;
664 const char *mapname;
665 uint64_t tmp;
666 uint64_t sz;
667 uint64_t sum;
668 u_int cnt;
669 #ifdef MEMSIZE
670 u_long memsize = MEMSIZE;
671 #endif
672
673 #ifdef MACHDEP_DEBUG
674 rmixl_puts("psb_physaddr_map: ");
675 rmixl_puthex64((uint64_t)(intptr_t)psb_physaddr_map);
676 rmixl_puts("\r\n");
677 #endif
678 if (psb_physaddr_map != NULL) {
679 rmixlfw_phys_mmap = *psb_physaddr_map;
680 map = &rmixlfw_phys_mmap;
681 mapname = "psb_physaddr_map";
682 rmixlfw_mmap_print(map);
683 }
684 #ifdef DIAGNOSTIC
685 else {
686 rmixl_puts("WARNING: no psb_physaddr_map\r\n");
687 }
688 #endif
689
690 #ifdef MACHDEP_DEBUG
691 rmixl_puts("avail_mem_map: ");
692 rmixl_puthex64((uint64_t)(intptr_t)avail_mem_map);
693 rmixl_puts("\r\n");
694 #endif
695 if (avail_mem_map != NULL) {
696 rmixlfw_avail_mmap = *avail_mem_map;
697 map = &rmixlfw_avail_mmap;
698 mapname = "avail_mem_map";
699 rmixlfw_mmap_print(map);
700 }
701 #ifdef DIAGNOSTIC
702 else {
703 rmixl_puts("WARNING: no avail_mem_map\r\n");
704 }
705 #endif
706
707 if (map == NULL) {
708 #ifndef MEMSIZE
709 rmixl_puts("panic: no firmware memory map, "
710 "must configure MEMSIZE\r\n");
711 for(;;); /* XXX */
712 #else
713 #ifdef DIAGNOSTIC
714 rmixl_puts("WARNING: no avail_mem_map, "
715 "using MEMSIZE\r\n");
716 #endif
717
718 mem_clusters[0].start = 0;
719 mem_clusters[0].size = MEMSIZE;
720 mem_cluster_cnt = 1;
721 return MEMSIZE;
722 #endif /* MEMSIZE */
723 }
724
725 #ifdef DIAGNOSTIC
726 rmixl_puts("using ");
727 rmixl_puts(mapname);
728 rmixl_puts("\r\n");
729 #endif
730 #ifdef MACHDEP_DEBUG
731 rmixl_puts("memory clusters:\r\n");
732 #endif
733 sum = 0;
734 cnt = 0;
735 for (uint32_t i=0; i < map->nmmaps; i++) {
736 if (map->entry[i].type != RMIXLFW_MMAP_TYPE_RAM)
737 continue;
738 mem_clusters[cnt].start = map->entry[i].start;
739 sz = map->entry[i].size;
740 sum += sz;
741 mem_clusters[cnt].size = sz;
742 #ifdef MACHDEP_DEBUG
743 rmixl_puthex32(i);
744 rmixl_puts(": ");
745 rmixl_puthex64(mem_clusters[cnt].start);
746 rmixl_puts(", ");
747 rmixl_puthex64(sz);
748 rmixl_puts(": ");
749 rmixl_puthex64(sum);
750 rmixl_puts("\r\n");
751 #endif
752 #ifdef MEMSIZE
753 /*
754 * configurably limit memsize
755 */
756 if (sum == memsize)
757 break;
758 if (sum > memsize) {
759 tmp = sum - memsize;
760 sz -= tmp;
761 sum -= tmp;
762 mem_clusters[cnt].size = sz;
763 break;
764 }
765 #endif
766 cnt++;
767 }
768 mem_cluster_cnt = cnt;
769 return sum;
770 }
771
772 void
773 consinit(void)
774 {
775
776 /*
777 * Everything related to console initialization is done
778 * in mach_init().
779 */
780 }
781
782 /*
783 * Allocate memory for variable-sized tables,
784 */
785 void
786 cpu_startup()
787 {
788 vaddr_t minaddr, maxaddr;
789 char pbuf[9];
790
791 /*
792 * Good {morning,afternoon,evening,night}.
793 */
794 printf("%s%s", copyright, version);
795 format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
796 printf("total memory = %s\n", pbuf);
797
798 /*
799 * Virtual memory is bootstrapped -- notify the bus spaces
800 * that memory allocation is now safe.
801 */
802 rmixl_configuration.rc_mallocsafe = 1;
803
804 minaddr = 0;
805 /*
806 * Allocate a submap for physio.
807 */
808 phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
809 VM_PHYS_SIZE, 0, FALSE, NULL);
810
811 /*
812 * (No need to allocate an mbuf cluster submap. Mbuf clusters
813 * are allocated via the pool allocator, and we use XKSEG to
814 * map those pages.)
815 */
816
817 format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
818 printf("avail memory = %s\n", pbuf);
819 }
820
821 int waittime = -1;
822
823 void
824 cpu_reboot(howto, bootstr)
825 int howto;
826 char *bootstr;
827 {
828
829 /* Take a snapshot before clobbering any registers. */
830 if (curproc)
831 savectx((struct user *)curpcb);
832
833 if (cold) {
834 howto |= RB_HALT;
835 goto haltsys;
836 }
837
838 /* If "always halt" was specified as a boot flag, obey. */
839 if (boothowto & RB_HALT)
840 howto |= RB_HALT;
841
842 boothowto = howto;
843 if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) {
844 waittime = 0;
845 vfs_shutdown();
846
847 /*
848 * If we've been adjusting the clock, the todr
849 * will be out of synch; adjust it now.
850 */
851 resettodr();
852 }
853
854 splhigh();
855
856 if (howto & RB_DUMP)
857 dumpsys();
858
859 haltsys:
860 doshutdownhooks();
861
862 if (howto & RB_HALT) {
863 printf("\n");
864 printf("The operating system has halted.\n");
865 printf("Please press any key to reboot.\n\n");
866 cnpollc(1); /* For proper keyboard command handling */
867 cngetc();
868 cnpollc(0);
869 }
870
871 printf("rebooting...\n\n");
872
873 rmixl_reset();
874 }
875
876 /*
877 * goodbye world
878 */
879 void __attribute__((__noreturn__))
880 rmixl_reset(void)
881 {
882 uint32_t r;
883
884 r = RMIXL_IOREG_READ(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET);
885 r |= RMIXL_GPIO_RESET_RESET;
886 RMIXL_IOREG_WRITE(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET, r);
887
888 printf("soft reset failed, spinning...\n");
889 for (;;);
890 }
891