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