machdep.c revision 1.4.2.2 1 1.4.2.2 martin /* $NetBSD: machdep.c,v 1.4.2.2 2024/02/03 11:47:07 martin Exp $ */
2 1.4.2.2 martin
3 1.4.2.2 martin /*
4 1.4.2.2 martin * Copyright (c) 2002, 2024 The NetBSD Foundation, Inc.
5 1.4.2.2 martin * All rights reserved.
6 1.4.2.2 martin *
7 1.4.2.2 martin * This code is derived from software contributed to The NetBSD Foundation
8 1.4.2.2 martin * by Lennart Augustsson (lennart (at) augustsson.net) at Sandburst Corp.
9 1.4.2.2 martin *
10 1.4.2.2 martin * Redistribution and use in source and binary forms, with or without
11 1.4.2.2 martin * modification, are permitted provided that the following conditions
12 1.4.2.2 martin * are met:
13 1.4.2.2 martin * 1. Redistributions of source code must retain the above copyright
14 1.4.2.2 martin * notice, this list of conditions and the following disclaimer.
15 1.4.2.2 martin * 2. Redistributions in binary form must reproduce the above copyright
16 1.4.2.2 martin * notice, this list of conditions and the following disclaimer in the
17 1.4.2.2 martin * documentation and/or other materials provided with the distribution.
18 1.4.2.2 martin *
19 1.4.2.2 martin * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.4.2.2 martin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.4.2.2 martin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.4.2.2 martin * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.4.2.2 martin * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.4.2.2 martin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.4.2.2 martin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.4.2.2 martin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.4.2.2 martin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.4.2.2 martin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.4.2.2 martin * POSSIBILITY OF SUCH DAMAGE.
30 1.4.2.2 martin */
31 1.4.2.2 martin
32 1.4.2.2 martin /*
33 1.4.2.2 martin * Copyright (C) 1995, 1996 Wolfgang Solfrank.
34 1.4.2.2 martin * Copyright (C) 1995, 1996 TooLs GmbH.
35 1.4.2.2 martin * All rights reserved.
36 1.4.2.2 martin *
37 1.4.2.2 martin * Redistribution and use in source and binary forms, with or without
38 1.4.2.2 martin * modification, are permitted provided that the following conditions
39 1.4.2.2 martin * are met:
40 1.4.2.2 martin * 1. Redistributions of source code must retain the above copyright
41 1.4.2.2 martin * notice, this list of conditions and the following disclaimer.
42 1.4.2.2 martin * 2. Redistributions in binary form must reproduce the above copyright
43 1.4.2.2 martin * notice, this list of conditions and the following disclaimer in the
44 1.4.2.2 martin * documentation and/or other materials provided with the distribution.
45 1.4.2.2 martin * 3. All advertising materials mentioning features or use of this software
46 1.4.2.2 martin * must display the following acknowledgement:
47 1.4.2.2 martin * This product includes software developed by TooLs GmbH.
48 1.4.2.2 martin * 4. The name of TooLs GmbH may not be used to endorse or promote products
49 1.4.2.2 martin * derived from this software without specific prior written permission.
50 1.4.2.2 martin *
51 1.4.2.2 martin * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
52 1.4.2.2 martin * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
53 1.4.2.2 martin * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
54 1.4.2.2 martin * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 1.4.2.2 martin * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
56 1.4.2.2 martin * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
57 1.4.2.2 martin * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
58 1.4.2.2 martin * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
59 1.4.2.2 martin * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
60 1.4.2.2 martin * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 1.4.2.2 martin */
62 1.4.2.2 martin
63 1.4.2.2 martin #define _POWERPC_BUS_DMA_PRIVATE
64 1.4.2.2 martin
65 1.4.2.2 martin #include <sys/cdefs.h>
66 1.4.2.2 martin __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.4.2.2 2024/02/03 11:47:07 martin Exp $");
67 1.4.2.2 martin
68 1.4.2.2 martin #include "opt_compat_netbsd.h"
69 1.4.2.2 martin #include "opt_ddb.h"
70 1.4.2.2 martin #include "opt_ddbparam.h"
71 1.4.2.2 martin #include "opt_inet.h"
72 1.4.2.2 martin #include "opt_ns.h"
73 1.4.2.2 martin #include "opt_oea.h"
74 1.4.2.2 martin
75 1.4.2.2 martin #include <sys/param.h>
76 1.4.2.2 martin #include <sys/buf.h>
77 1.4.2.2 martin #include <sys/bus.h>
78 1.4.2.2 martin #include <sys/conf.h>
79 1.4.2.2 martin #include <sys/device.h>
80 1.4.2.2 martin #include <sys/exec.h>
81 1.4.2.2 martin #include <sys/extent.h>
82 1.4.2.2 martin #include <sys/intr.h>
83 1.4.2.2 martin #include <sys/kernel.h>
84 1.4.2.2 martin #include <sys/kgdb.h>
85 1.4.2.2 martin #include <sys/ksyms.h>
86 1.4.2.2 martin #include <sys/mbuf.h>
87 1.4.2.2 martin #include <sys/mount.h>
88 1.4.2.2 martin #include <sys/msgbuf.h>
89 1.4.2.2 martin #include <sys/proc.h>
90 1.4.2.2 martin #include <sys/reboot.h>
91 1.4.2.2 martin #include <sys/syscallargs.h>
92 1.4.2.2 martin #include <sys/sysctl.h>
93 1.4.2.2 martin #include <sys/syslog.h>
94 1.4.2.2 martin #include <sys/systm.h>
95 1.4.2.2 martin
96 1.4.2.2 martin #include <uvm/uvm_extern.h>
97 1.4.2.2 martin
98 1.4.2.2 martin #include <machine/powerpc.h>
99 1.4.2.2 martin #include <machine/wii.h>
100 1.4.2.2 martin
101 1.4.2.2 martin #include <powerpc/bus_funcs.h>
102 1.4.2.2 martin #include <powerpc/db_machdep.h>
103 1.4.2.2 martin #include <powerpc/pio.h>
104 1.4.2.2 martin #include <powerpc/pmap.h>
105 1.4.2.2 martin #include <powerpc/spr.h>
106 1.4.2.2 martin #include <powerpc/trap.h>
107 1.4.2.2 martin
108 1.4.2.2 martin #include <powerpc/oea/bat.h>
109 1.4.2.2 martin #include <powerpc/oea/spr.h>
110 1.4.2.2 martin #include <powerpc/pic/picvar.h>
111 1.4.2.2 martin
112 1.4.2.2 martin #include <ddb/db_extern.h>
113 1.4.2.2 martin
114 1.4.2.2 martin #include <dev/wscons/wsconsio.h>
115 1.4.2.2 martin #include <dev/wscons/wsdisplayvar.h>
116 1.4.2.2 martin #include <dev/rasops/rasops.h>
117 1.4.2.2 martin #include <dev/wsfont/wsfont.h>
118 1.4.2.2 martin #include <dev/wscons/wsdisplay_vconsvar.h>
119 1.4.2.2 martin
120 1.4.2.2 martin #include <dev/usb/ukbdvar.h>
121 1.4.2.2 martin
122 1.4.2.2 martin #include "ksyms.h"
123 1.4.2.2 martin #include "ukbd.h"
124 1.4.2.2 martin
125 1.4.2.2 martin #define IBM750CL_SPR_HID4 1011
126 1.4.2.2 martin #define L2_CCFI 0x00100000 /* L2 complete castout prior
127 1.4.2.2 martin * to L2 flash invalidate.
128 1.4.2.2 martin */
129 1.4.2.2 martin
130 1.4.2.2 martin extern u_int l2cr_config;
131 1.4.2.2 martin
132 1.4.2.2 martin struct powerpc_bus_space wii_mem_tag = {
133 1.4.2.2 martin .pbs_flags = _BUS_SPACE_BIG_ENDIAN |
134 1.4.2.2 martin _BUS_SPACE_MEM_TYPE,
135 1.4.2.2 martin .pbs_offset = 0,
136 1.4.2.2 martin .pbs_base = 0x0c000000,
137 1.4.2.2 martin .pbs_limit = 0x0dffffff,
138 1.4.2.2 martin .pbs_extent = NULL,
139 1.4.2.2 martin };
140 1.4.2.2 martin
141 1.4.2.2 martin static char ex_storage[1][EXTENT_FIXED_STORAGE_SIZE(EXTMAP_RANGES)]
142 1.4.2.2 martin __attribute__((aligned(8)));
143 1.4.2.2 martin
144 1.4.2.2 martin static bus_addr_t
145 1.4.2.2 martin wii_dma_phys_to_bus_mem(bus_dma_tag_t t, bus_addr_t addr)
146 1.4.2.2 martin {
147 1.4.2.2 martin return addr;
148 1.4.2.2 martin }
149 1.4.2.2 martin
150 1.4.2.2 martin static bus_addr_t
151 1.4.2.2 martin wii_dma_bus_mem_to_phys(bus_dma_tag_t t, bus_addr_t addr)
152 1.4.2.2 martin {
153 1.4.2.2 martin return addr;
154 1.4.2.2 martin }
155 1.4.2.2 martin
156 1.4.2.2 martin static int
157 1.4.2.2 martin wii_mem2_dmamem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment,
158 1.4.2.2 martin bus_size_t boundary, bus_dma_segment_t *segs, int nsegs, int *rsegs,
159 1.4.2.2 martin int flags)
160 1.4.2.2 martin {
161 1.4.2.2 martin struct mem_region *mem, *avail;
162 1.4.2.2 martin
163 1.4.2.2 martin /* Restrict memory used for DMA to ranges in MEM2 */
164 1.4.2.2 martin mem_regions(&mem, &avail);
165 1.4.2.2 martin if (mem[1].size == 0) {
166 1.4.2.2 martin return ENOMEM;
167 1.4.2.2 martin }
168 1.4.2.2 martin
169 1.4.2.2 martin return _bus_dmamem_alloc_range(t, size, alignment, boundary, segs,
170 1.4.2.2 martin nsegs, rsegs, flags, mem[1].start,
171 1.4.2.2 martin mem[1].start + mem[1].size - PAGE_SIZE - 1);
172 1.4.2.2 martin }
173 1.4.2.2 martin
174 1.4.2.2 martin struct powerpc_bus_dma_tag wii_bus_dma_tag = {
175 1.4.2.2 martin 0, /* _bounce_thresh */
176 1.4.2.2 martin _bus_dmamap_create,
177 1.4.2.2 martin _bus_dmamap_destroy,
178 1.4.2.2 martin _bus_dmamap_load,
179 1.4.2.2 martin _bus_dmamap_load_mbuf,
180 1.4.2.2 martin _bus_dmamap_load_uio,
181 1.4.2.2 martin _bus_dmamap_load_raw,
182 1.4.2.2 martin _bus_dmamap_unload,
183 1.4.2.2 martin _bus_dmamap_sync,
184 1.4.2.2 martin _bus_dmamem_alloc,
185 1.4.2.2 martin _bus_dmamem_free,
186 1.4.2.2 martin _bus_dmamem_map,
187 1.4.2.2 martin _bus_dmamem_unmap,
188 1.4.2.2 martin _bus_dmamem_mmap,
189 1.4.2.2 martin wii_dma_phys_to_bus_mem,
190 1.4.2.2 martin wii_dma_bus_mem_to_phys,
191 1.4.2.2 martin };
192 1.4.2.2 martin
193 1.4.2.2 martin struct powerpc_bus_dma_tag wii_mem2_bus_dma_tag = {
194 1.4.2.2 martin 0, /* _bounce_thresh */
195 1.4.2.2 martin _bus_dmamap_create,
196 1.4.2.2 martin _bus_dmamap_destroy,
197 1.4.2.2 martin _bus_dmamap_load,
198 1.4.2.2 martin _bus_dmamap_load_mbuf,
199 1.4.2.2 martin _bus_dmamap_load_uio,
200 1.4.2.2 martin _bus_dmamap_load_raw,
201 1.4.2.2 martin _bus_dmamap_unload,
202 1.4.2.2 martin _bus_dmamap_sync,
203 1.4.2.2 martin wii_mem2_dmamem_alloc,
204 1.4.2.2 martin _bus_dmamem_free,
205 1.4.2.2 martin _bus_dmamem_map,
206 1.4.2.2 martin _bus_dmamem_unmap,
207 1.4.2.2 martin _bus_dmamem_mmap,
208 1.4.2.2 martin wii_dma_phys_to_bus_mem,
209 1.4.2.2 martin wii_dma_bus_mem_to_phys,
210 1.4.2.2 martin };
211 1.4.2.2 martin
212 1.4.2.2 martin
213 1.4.2.2 martin /*
214 1.4.2.2 martin * Global variables used here and there
215 1.4.2.2 martin */
216 1.4.2.2 martin struct mem_region physmemr[3], availmemr[3];
217 1.4.2.2 martin char wii_cmdline[1024];
218 1.4.2.2 martin
219 1.4.2.2 martin void initppc(u_int, u_int, u_int, void *); /* Called from locore */
220 1.4.2.2 martin void wii_dolphin_elf_loader_id(void);
221 1.4.2.2 martin
222 1.4.2.2 martin static void wii_setup(void);
223 1.4.2.2 martin static void init_decrementer(void);
224 1.4.2.2 martin
225 1.4.2.2 martin void
226 1.4.2.2 martin initppc(u_int startkernel, u_int endkernel, u_int args, void *btinfo)
227 1.4.2.2 martin {
228 1.4.2.2 martin extern u_long ticks_per_sec;
229 1.4.2.2 martin extern unsigned char edata[], end[];
230 1.4.2.2 martin extern struct wii_argv wii_argv;
231 1.4.2.2 martin uint32_t mem2_size;
232 1.4.2.2 martin register_t scratch;
233 1.4.2.2 martin
234 1.4.2.2 martin memset(&edata, 0, end - edata); /* clear BSS */
235 1.4.2.2 martin
236 1.4.2.2 martin if (wii_argv.magic == WII_ARGV_MAGIC) {
237 1.4.2.2 martin void *ptr = (void *)(uintptr_t)(wii_argv.cmdline & ~0x80000000);
238 1.4.2.2 martin if (ptr != NULL) {
239 1.4.2.2 martin memcpy(wii_cmdline, ptr, wii_argv.length);
240 1.4.2.2 martin }
241 1.4.2.2 martin }
242 1.4.2.2 martin
243 1.4.2.2 martin mem2_size = in32(GLOBAL_MEM2_SIZE);
244 1.4.2.2 martin
245 1.4.2.2 martin /* MEM1 24MB 1T-SRAM */
246 1.4.2.2 martin physmemr[0].start = WII_MEM1_BASE;
247 1.4.2.2 martin physmemr[0].size = WII_MEM1_SIZE;
248 1.4.2.2 martin
249 1.4.2.2 martin /* MEM2 64MB GDDR3 */
250 1.4.2.2 martin physmemr[1].start = WII_MEM2_BASE;
251 1.4.2.2 martin physmemr[1].size = mem2_size;
252 1.4.2.2 martin
253 1.4.2.2 martin physmemr[2].size = 0;
254 1.4.2.2 martin
255 1.4.2.2 martin /* MEM1 available memory */
256 1.4.2.2 martin availmemr[0].start = ((endkernel & ~0x80000000) + PGOFSET) & ~PGOFSET;
257 1.4.2.2 martin availmemr[0].size = physmemr[0].size - availmemr[0].start;
258 1.4.2.2 martin /* External framebuffer is at the end of MEM1 */
259 1.4.2.2 martin availmemr[0].size -= XFB_SIZE;
260 1.4.2.2 martin
261 1.4.2.2 martin /* MEM2 available memory */
262 1.4.2.2 martin availmemr[1].start = physmemr[1].start;
263 1.4.2.2 martin availmemr[1].size = physmemr[1].size;
264 1.4.2.2 martin if (mem2_size != 0) {
265 1.4.2.2 martin /* DSP uses 16KB at the start of MEM2 */
266 1.4.2.2 martin availmemr[1].start += DSP_MEM_SIZE;
267 1.4.2.2 martin availmemr[1].size -= DSP_MEM_SIZE;
268 1.4.2.2 martin /* IPC and Starlet use memory at the end of MEM2 */
269 1.4.2.2 martin availmemr[1].size -= IPC_SIZE;
270 1.4.2.2 martin availmemr[1].size -= ARM_SIZE;
271 1.4.2.2 martin }
272 1.4.2.2 martin
273 1.4.2.2 martin availmemr[2].size = 0;
274 1.4.2.2 martin
275 1.4.2.2 martin #ifdef BOOTHOWTO
276 1.4.2.2 martin /*
277 1.4.2.2 martin * boothowto
278 1.4.2.2 martin */
279 1.4.2.2 martin boothowto = BOOTHOWTO;
280 1.4.2.2 martin #endif
281 1.4.2.2 martin
282 1.4.2.2 martin /* HID4[L2_CCFI] must be set to 1 for correct operation of L2 cache */
283 1.4.2.2 martin mtspr(IBM750CL_SPR_HID4, mfspr(IBM750CL_SPR_HID4) | L2_CCFI);
284 1.4.2.2 martin
285 1.4.2.2 martin /* Configure L2 cache */
286 1.4.2.2 martin l2cr_config = L2CR_L2E | L2CR_L2PE;
287 1.4.2.2 martin
288 1.4.2.2 martin if (bus_space_init(&wii_mem_tag, "iomem",
289 1.4.2.2 martin ex_storage[0], sizeof(ex_storage[0]))) {
290 1.4.2.2 martin panic("bus_space_init failed");
291 1.4.2.2 martin }
292 1.4.2.2 martin
293 1.4.2.2 martin /*
294 1.4.2.2 martin * Initialize the BAT registers
295 1.4.2.2 martin */
296 1.4.2.2 martin oea_batinit(
297 1.4.2.2 martin WII_IOMEM_BASE, BAT_BL_32M,
298 1.4.2.2 martin 0);
299 1.4.2.2 martin
300 1.4.2.2 martin /*
301 1.4.2.2 martin * Set up trap vectors
302 1.4.2.2 martin */
303 1.4.2.2 martin oea_init(NULL);
304 1.4.2.2 martin
305 1.4.2.2 martin /*
306 1.4.2.2 martin * Get CPU clock
307 1.4.2.2 martin */
308 1.4.2.2 martin ticks_per_sec = TIMEBASE_FREQ_HZ;
309 1.4.2.2 martin cpu_timebase = ticks_per_sec;
310 1.4.2.2 martin
311 1.4.2.2 martin wii_setup();
312 1.4.2.2 martin
313 1.4.2.2 martin uvm_md_init();
314 1.4.2.2 martin
315 1.4.2.2 martin /*
316 1.4.2.2 martin * Initialize pmap module.
317 1.4.2.2 martin */
318 1.4.2.2 martin pmap_bootstrap(startkernel, endkernel);
319 1.4.2.2 martin
320 1.4.2.2 martin /* Now enable translation (and machine checks/recoverable interrupts) */
321 1.4.2.2 martin __asm __volatile ("sync; mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
322 1.4.2.2 martin : "=r"(scratch)
323 1.4.2.2 martin : "K"(PSL_IR|PSL_DR|PSL_ME|PSL_RI));
324 1.4.2.2 martin
325 1.4.2.2 martin /*
326 1.4.2.2 martin * Setup decrementer
327 1.4.2.2 martin */
328 1.4.2.2 martin init_decrementer();
329 1.4.2.2 martin }
330 1.4.2.2 martin
331 1.4.2.2 martin void
332 1.4.2.2 martin mem_regions(struct mem_region **mem, struct mem_region **avail)
333 1.4.2.2 martin {
334 1.4.2.2 martin *mem = physmemr;
335 1.4.2.2 martin *avail = availmemr;
336 1.4.2.2 martin }
337 1.4.2.2 martin
338 1.4.2.2 martin /*
339 1.4.2.2 martin * Machine dependent startup code.
340 1.4.2.2 martin */
341 1.4.2.2 martin void
342 1.4.2.2 martin cpu_startup(void)
343 1.4.2.2 martin {
344 1.4.2.2 martin extern void pi_init_intr(void);
345 1.4.2.2 martin
346 1.4.2.2 martin oea_startup(NULL);
347 1.4.2.2 martin
348 1.4.2.2 martin /*
349 1.4.2.2 martin * Now that we have VM, malloc()s are OK in bus_space.
350 1.4.2.2 martin */
351 1.4.2.2 martin bus_space_mallocok();
352 1.4.2.2 martin
353 1.4.2.2 martin /* Set up interrupt controller */
354 1.4.2.2 martin pic_init();
355 1.4.2.2 martin pi_init_intr();
356 1.4.2.2 martin oea_install_extint(pic_ext_intr);
357 1.4.2.2 martin }
358 1.4.2.2 martin
359 1.4.2.2 martin /*
360 1.4.2.2 martin * No early console support.
361 1.4.2.2 martin */
362 1.4.2.2 martin void
363 1.4.2.2 martin consinit(void)
364 1.4.2.2 martin {
365 1.4.2.2 martin #if NUKBD > 0
366 1.4.2.2 martin ukbd_cnattach();
367 1.4.2.2 martin #endif
368 1.4.2.2 martin }
369 1.4.2.2 martin
370 1.4.2.2 martin /*
371 1.4.2.2 martin * Halt or reboot the machine after syncing/dumping according to howto.
372 1.4.2.2 martin */
373 1.4.2.2 martin void
374 1.4.2.2 martin cpu_reboot(int howto, char *what)
375 1.4.2.2 martin {
376 1.4.2.2 martin static int syncing;
377 1.4.2.2 martin extern void disable_intr(void);
378 1.4.2.2 martin
379 1.4.2.2 martin boothowto = howto;
380 1.4.2.2 martin if (!cold && !(howto & RB_NOSYNC) && !syncing) {
381 1.4.2.2 martin syncing = 1;
382 1.4.2.2 martin vfs_shutdown(); /* sync */
383 1.4.2.2 martin resettodr(); /* set wall clock */
384 1.4.2.2 martin }
385 1.4.2.2 martin splhigh();
386 1.4.2.2 martin if (!cold && (howto & RB_DUMP)) {
387 1.4.2.2 martin oea_dumpsys();
388 1.4.2.2 martin }
389 1.4.2.2 martin pmf_system_shutdown(boothowto);
390 1.4.2.2 martin doshutdownhooks();
391 1.4.2.2 martin
392 1.4.2.2 martin disable_intr();
393 1.4.2.2 martin
394 1.4.2.2 martin /* Force halt on panic to capture the cause on screen. */
395 1.4.2.2 martin if (panicstr != NULL) {
396 1.4.2.2 martin howto |= RB_HALT;
397 1.4.2.2 martin }
398 1.4.2.2 martin if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
399 1.4.2.2 martin printf("power off\n\n");
400 1.4.2.2 martin out32(HW_GPIOB_OUT, in32(HW_GPIOB_OUT) | __BIT(GPIO_SHUTDOWN));
401 1.4.2.2 martin delay(100000);
402 1.4.2.2 martin printf("power off failed!\n\n");
403 1.4.2.2 martin }
404 1.4.2.2 martin if (howto & RB_HALT) {
405 1.4.2.2 martin printf("halted\n\n");
406 1.4.2.2 martin while (1);
407 1.4.2.2 martin }
408 1.4.2.2 martin
409 1.4.2.2 martin printf("rebooting\n\n");
410 1.4.2.2 martin out32(HW_RESETS, in32(HW_RESETS) & ~RSTBINB);
411 1.4.2.2 martin while (1);
412 1.4.2.2 martin }
413 1.4.2.2 martin
414 1.4.2.2 martin static void
415 1.4.2.2 martin wii_setup(void)
416 1.4.2.2 martin {
417 1.4.2.2 martin /* Turn on the drive slot LED. */
418 1.4.2.2 martin out32(HW_GPIOB_OUT, in32(HW_GPIOB_OUT) | __BIT(GPIO_SLOT_LED));
419 1.4.2.2 martin
420 1.4.2.2 martin /* Enable PPC access to SHUTDOWN GPIO. */
421 1.4.2.2 martin out32(HW_GPIO_OWNER, in32(HW_GPIO_OWNER) | __BIT(GPIO_SHUTDOWN));
422 1.4.2.2 martin }
423 1.4.2.2 martin
424 1.4.2.2 martin static void
425 1.4.2.2 martin init_decrementer(void)
426 1.4.2.2 martin {
427 1.4.2.2 martin extern uint32_t ns_per_tick;
428 1.4.2.2 martin extern uint32_t ticks_per_intr;
429 1.4.2.2 martin extern u_long ticks_per_sec;
430 1.4.2.2 martin int scratch, msr;
431 1.4.2.2 martin
432 1.4.2.2 martin KASSERT(ticks_per_sec != 0);
433 1.4.2.2 martin
434 1.4.2.2 martin __asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1"
435 1.4.2.2 martin : "=r"(msr), "=r"(scratch) : "K"((u_short)~PSL_EE));
436 1.4.2.2 martin ns_per_tick = 1000000000 / ticks_per_sec;
437 1.4.2.2 martin ticks_per_intr = ticks_per_sec / hz;
438 1.4.2.2 martin cpu_timebase = ticks_per_sec;
439 1.4.2.2 martin
440 1.4.2.2 martin curcpu()->ci_lasttb = mftbl();
441 1.4.2.2 martin
442 1.4.2.2 martin mtspr(SPR_DEC, ticks_per_intr);
443 1.4.2.2 martin mtmsr(msr);
444 1.4.2.2 martin }
445