4 * Copyright (c) 2006 Itronix Inc.
7 * Portions written by Garrett D'Amore for Itronix Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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. The name of Itronix Inc. may not be used to endorse
18 * or promote products derived from this software without specific
19 * prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1992, 1993
35 * The Regents of the University of California. All rights reserved.
37 * This code is derived from software contributed to Berkeley by
38 * the Systems Programming Group of the University of Utah Computer
39 * Science Department, The Mach Operating System project at
40 * Carnegie-Mellon University and Ralph Campbell.
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * @(#)machdep.c 8.3 (Berkeley) 1/12/94
67 * from: Utah Hdr: machdep.c 1.63 91/04/24
70 * Copyright (c) 1988 University of Utah.
72 * This code is derived from software contributed to Berkeley by
73 * the Systems Programming Group of the University of Utah Computer
74 * Science Department, The Mach Operating System project at
75 * Carnegie-Mellon University and Ralph Campbell.
77 * Redistribution and use in source and binary forms, with or without
78 * modification, are permitted provided that the following conditions
80 * 1. Redistributions of source code must retain the above copyright
81 * notice, this list of conditions and the following disclaimer.
82 * 2. Redistributions in binary form must reproduce the above copyright
83 * notice, this list of conditions and the following disclaimer in the
84 * documentation and/or other materials provided with the distribution.
85 * 3. All advertising materials mentioning features or use of this software
86 * must display the following acknowledgement:
87 * This product includes software developed by the University of
88 * California, Berkeley and its contributors.
89 * 4. Neither the name of the University nor the names of its contributors
90 * may be used to endorse or promote products derived from this software
91 * without specific prior written permission.
93 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
94 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
95 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
96 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
97 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
98 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
99 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
101 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
102 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
105 * @(#)machdep.c 8.3 (Berkeley) 1/12/94
106 * from: Utah Hdr: machdep.c 1.63 91/04/24
109 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
110 __KERNEL_RCSID(0, "$NetBSD$");
113 #include "opt_kgdb.h"
115 #include "opt_memsize.h"
116 #include "opt_modular.h"
117 #include "opt_ethaddr.h"
119 #include <sys/param.h>
120 #include <sys/systm.h>
121 #include <sys/kernel.h>
123 #include <sys/reboot.h>
124 #include <sys/mount.h>
125 #include <sys/kcore.h>
126 #include <sys/boot_flag.h>
127 #include <sys/termios.h>
128 #include <sys/ksyms.h>
129 #include <sys/device.h>
132 #include <net/if_ether.h>
134 #include <uvm/uvm_extern.h>
136 #include <dev/cons.h>
140 #if NKSYMS || defined(DDB) || defined(MODULAR)
141 #include <machine/db_machdep.h>
142 #include <ddb/db_extern.h>
145 #include <mips/cache.h>
146 #include <mips/locore.h>
147 #include <machine/yamon.h>
149 #include <evbmips/alchemy/board.h>
150 #include <mips/alchemy/dev/aupcivar.h>
151 #include <mips/alchemy/dev/aupcmciavar.h>
152 #include <mips/alchemy/dev/auspivar.h>
153 #include <mips/alchemy/include/aureg.h>
154 #include <mips/alchemy/include/auvar.h>
155 #include <mips/alchemy/include/aubusvar.h>
161 #endif /* NAUCOM > 0 */
165 /* Our exported CPU info; we can have only one. */
166 struct cpu_info cpu_info_store
;
168 /* Maps for VM objects. */
169 struct vm_map
*mb_map
= NULL
;
170 struct vm_map
*phys_map
= NULL
;
172 int maxmem
; /* max memory per process */
175 phys_ram_seg_t mem_clusters
[VM_PHYSSEG_MAX
];
177 yamon_env_var
*yamon_envp
;
178 struct mips_bus_space alchemy_cpuregt
;
180 void mach_init(int, char **, yamon_env_var
*, u_long
); /* XXX */
183 mach_init(int argc
, char **argv
, yamon_env_var
*envp
, u_long memsize
)
185 bus_space_handle_t sh
;
189 int freqok
, howto
, i
;
190 const struct alchemy_board
*board
;
192 extern char edata
[], end
[]; /* XXX */
194 board
= board_info();
195 KASSERT(board
!= NULL
);
197 /* clear the BSS segment */
198 kernend
= (void *)mips_round_page(end
);
199 memset(edata
, 0, (char *)kernend
- edata
);
201 /* set CPU model info for sysctl_hw */
202 strcpy(cpu_model
, board
->ab_name
);
204 /* save the yamon environment pointer */
207 /* Use YAMON callbacks for early console I/O */
208 cn_tab
= &yamon_promcd
;
211 * Set up the exception vectors and CPU-specific function
212 * vectors early on. We need the wbflush() vector set up
213 * before comcnattach() is called (or at least before the
214 * first printf() after that is called).
215 * Sets up mips_cpu_flags that may be queried by other
216 * functions called during startup.
217 * Also clears the I+D caches.
222 * Set the VM page size.
227 * Use YAMON's CPU frequency if available.
229 freqok
= yamon_setcpufreq(1);
232 * Initialize bus space tags.
234 au_cpureg_bus_mem_init(&alchemy_cpuregt
, &alchemy_cpuregt
);
235 aubus_st
= &alchemy_cpuregt
;
238 * Calibrate the timer if YAMON failed to tell us.
241 bus_space_map(aubus_st
, PC_BASE
, PC_SIZE
, 0, &sh
);
242 au_cal_timers(aubus_st
, sh
);
243 bus_space_unmap(aubus_st
, sh
, PC_SIZE
);
247 * Perform board-specific initialization.
252 * Bring up the console.
256 if (aucomcnrate
== 0)
257 aucomcnrate
= CONSPEED
;
258 #else /* !CONSPEED */
260 * Learn default console speed. We use the YAMON environment,
261 * though we could probably also figure it out by checking the
262 * aucom registers directly.
264 if ((aucomcnrate
== 0) && ((cp
= yamon_getenv("modetty0")) != NULL
))
265 aucomcnrate
= strtoul(cp
, NULL
, 0);
267 if (aucomcnrate
== 0) {
268 printf("FATAL: `modetty0' YAMON variable not set. Set it\n");
269 printf(" to the speed of the console and try again.\n");
270 printf(" Or, build a kernel with the `CONSPEED' "
274 #endif /* CONSPEED */
277 * Delay to allow firmware putchars to complete.
278 * FIFO depth * character time.
279 * character time = (1000000 / (defaultrate / 10))
281 delay(160000000 / aucomcnrate
);
282 if (com_aubus_cnattach(UART0_BASE
, aucomcnrate
) != 0)
283 panic("mach_init: unable to initialize serial console");
286 panic("mach_init: not configured to use serial console");
287 #endif /* NAUCOM > 0 */
290 * Look at arguments passed to us and compute boothowto.
292 boothowto
= RB_AUTOBOOT
;
296 for (i
= 1; i
< argc
; i
++) {
297 for (cp
= argv
[i
]; *cp
; cp
++) {
298 /* Ignore superfluous '-', if there is one */
303 BOOT_FLAG(*cp
, howto
);
305 printf("bootflag '%c' not recognised\n", *cp
);
312 * Determine the memory size. Use the `memsize' PMON
313 * variable. If that's not available, panic.
315 * Note: Reserve the first page! That's where the trap
316 * vectors are located.
323 if ((cp
= yamon_getenv("memsize")) != NULL
)
324 memsize
= strtoul(cp
, NULL
, 0);
326 printf("FATAL: `memsize' YAMON variable not set. Set it to\n");
327 printf(" the amount of memory (in MB) and try again.\n");
328 printf(" Or, build a kernel with the `MEMSIZE' "
334 printf("Memory size: 0x%08lx\n", memsize
);
335 physmem
= btoc(memsize
);
337 mem_clusters
[mem_cluster_cnt
].start
= PAGE_SIZE
;
338 mem_clusters
[mem_cluster_cnt
].size
=
339 memsize
- mem_clusters
[mem_cluster_cnt
].start
;
343 * Load the rest of the available pages into the VM system.
345 first
= round_page(MIPS_KSEG0_TO_PHYS(kernend
));
346 last
= mem_clusters
[0].start
+ mem_clusters
[0].size
;
347 uvm_page_physload(atop(first
), atop(last
), atop(first
), atop(last
),
348 VM_FREELIST_DEFAULT
);
351 * Initialize message buffer (at end of core).
356 * Initialize the virtual memory system.
361 * Allocate uarea page for lwp0 and set it.
363 mips_init_lwp0_uarea();
366 * Initialize debuggers, and break into them, if appropriate.
369 if (boothowto
& RB_KDB
)
379 * Everything related to console initialization is done
388 vaddr_t minaddr
, maxaddr
;
390 extern int pmapdebug
; /* XXX */
391 int opmapdebug
= pmapdebug
;
393 pmapdebug
= 0; /* Shut up pmap debug during bootstrap */
397 * Good {morning,afternoon,evening,night}.
399 printf("%s%s", copyright
, version
);
400 printf("%s\n", cpu_model
);
401 format_bytes(pbuf
, sizeof(pbuf
), ctob(physmem
));
402 printf("total memory = %s\n", pbuf
);
407 * Allocate a submap for physio
409 phys_map
= uvm_km_suballoc(kernel_map
, &minaddr
, &maxaddr
,
410 VM_PHYS_SIZE
, 0, false, NULL
);
413 * No need to allocate an mbuf cluster submap. Mbuf clusters
414 * are allocated via the pool allocator, and we use KSEG to
419 pmapdebug
= opmapdebug
;
421 format_bytes(pbuf
, sizeof(pbuf
), ptoa(uvmexp
.free
));
422 printf("avail memory = %s\n", pbuf
);
426 cpu_reboot(int howto
, char *bootstr
)
428 static int waittime
= -1;
429 const struct alchemy_board
*board
;
431 /* Take a snapshot before clobbering any registers. */
435 board
= board_info();
436 KASSERT(board
!= NULL
);
438 /* If "always halt" was specified as a boot flag, obey. */
439 if (boothowto
& RB_HALT
)
444 /* If system is cold, just halt. */
446 boothowto
|= RB_HALT
;
450 if ((boothowto
& RB_NOSYNC
) == 0 && waittime
< 0) {
454 * Synchronize the disks....
459 * If we've been adjusting the clock, the todr
460 * will be out of synch; adjust it now.
465 /* Disable interrupts. */
468 if (boothowto
& RB_DUMP
)
472 /* Run any shutdown hooks. */
475 pmf_system_shutdown(boothowto
);
477 if ((boothowto
& RB_POWERDOWN
) == RB_POWERDOWN
)
478 if (board
&& board
->ab_poweroff
)
479 board
->ab_poweroff();
482 * YAMON may autoboot (depending on settings), and we cannot pass
483 * flags to it (at least I haven't figured out how to yet), so
484 * we "pseudo-halt" now.
486 if (boothowto
& RB_HALT
) {
488 printf("The operating system has halted.\n");
489 printf("Please press any key to reboot.\n\n");
490 cnpollc(1); /* For proper keyboard command handling */
495 printf("reseting board...\n\n");
498 * Try to use board-specific reset logic, which might involve a better
501 if (board
->ab_reboot
)
506 * For some reason we are leaving the ethernet MAC in a state where
507 * YAMON isn't happy with it. So just call the reset vector (grr,
508 * Alchemy YAMON doesn't have a "reset" command).
510 mips_icache_sync_all();
511 mips_dcache_wbinv_all();
512 __asm
volatile("jr %0" :: "r"(MIPS_RESET_EXC_VEC
));
514 printf("%s\n\n", ((howto
& RB_HALT
) != 0) ? "halted." : "rebooting...");
515 yamon_exit(boothowto
);
516 printf("Oops, back from yamon_exit()\n\nSpinning...");
519 /* spin forever */ ; /* XXX */
524 * Export our interrupt map function so aupci can find it.
527 aupci_intr_map(struct pci_attach_args
*pa
, pci_intr_handle_t
*ihp
)
529 const struct alchemy_board
*board
;
531 board
= board_info();
532 if (board
->ab_pci_intr_map
!= NULL
)
533 return (board
->ab_pci_intr_map(pa
, ihp
));
537 struct aupcmcia_machdep
*
538 aupcmcia_machdep(void)
540 const struct alchemy_board
*board
;
542 board
= board_info();
543 return (board
->ab_pcmcia
);
546 const struct auspi_machdep
*
547 auspi_machdep(bus_addr_t ba
)
549 const struct alchemy_board
*board
;
551 board
= board_info();
552 if (board
->ab_spi
!= NULL
)
553 return (board
->ab_spi(ba
));