machdep.c revision 1.4.2.4 1 1.4.2.4 martin /* $NetBSD: machdep.c,v 1.4.2.4 2024/10/26 15:28:55 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.4 martin __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.4.2.4 2024/10/26 15:28:55 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.3 martin #ifndef WII_DEFAULT_CMDLINE
126 1.4.2.3 martin #define WII_DEFAULT_CMDLINE "root=ld0a"
127 1.4.2.3 martin #endif
128 1.4.2.3 martin
129 1.4.2.2 martin #define IBM750CL_SPR_HID4 1011
130 1.4.2.2 martin #define L2_CCFI 0x00100000 /* L2 complete castout prior
131 1.4.2.2 martin * to L2 flash invalidate.
132 1.4.2.2 martin */
133 1.4.2.2 martin
134 1.4.2.3 martin #define MINI_MEM2_START 0x13f00000 /* Start of reserved MEM2 for MINI */
135 1.4.2.3 martin
136 1.4.2.2 martin extern u_int l2cr_config;
137 1.4.2.2 martin
138 1.4.2.2 martin struct powerpc_bus_space wii_mem_tag = {
139 1.4.2.2 martin .pbs_flags = _BUS_SPACE_BIG_ENDIAN |
140 1.4.2.2 martin _BUS_SPACE_MEM_TYPE,
141 1.4.2.2 martin .pbs_offset = 0,
142 1.4.2.2 martin .pbs_base = 0x0c000000,
143 1.4.2.2 martin .pbs_limit = 0x0dffffff,
144 1.4.2.2 martin .pbs_extent = NULL,
145 1.4.2.2 martin };
146 1.4.2.2 martin
147 1.4.2.2 martin static char ex_storage[1][EXTENT_FIXED_STORAGE_SIZE(EXTMAP_RANGES)]
148 1.4.2.2 martin __attribute__((aligned(8)));
149 1.4.2.2 martin
150 1.4.2.2 martin static bus_addr_t
151 1.4.2.2 martin wii_dma_phys_to_bus_mem(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 bus_addr_t
157 1.4.2.2 martin wii_dma_bus_mem_to_phys(bus_dma_tag_t t, bus_addr_t addr)
158 1.4.2.2 martin {
159 1.4.2.2 martin return addr;
160 1.4.2.2 martin }
161 1.4.2.2 martin
162 1.4.2.2 martin static int
163 1.4.2.2 martin wii_mem2_dmamem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment,
164 1.4.2.2 martin bus_size_t boundary, bus_dma_segment_t *segs, int nsegs, int *rsegs,
165 1.4.2.2 martin int flags)
166 1.4.2.2 martin {
167 1.4.2.2 martin struct mem_region *mem, *avail;
168 1.4.2.2 martin
169 1.4.2.2 martin /* Restrict memory used for DMA to ranges in MEM2 */
170 1.4.2.2 martin mem_regions(&mem, &avail);
171 1.4.2.2 martin if (mem[1].size == 0) {
172 1.4.2.2 martin return ENOMEM;
173 1.4.2.2 martin }
174 1.4.2.2 martin
175 1.4.2.2 martin return _bus_dmamem_alloc_range(t, size, alignment, boundary, segs,
176 1.4.2.2 martin nsegs, rsegs, flags, mem[1].start,
177 1.4.2.2 martin mem[1].start + mem[1].size - PAGE_SIZE - 1);
178 1.4.2.2 martin }
179 1.4.2.2 martin
180 1.4.2.2 martin struct powerpc_bus_dma_tag wii_bus_dma_tag = {
181 1.4.2.2 martin 0, /* _bounce_thresh */
182 1.4.2.2 martin _bus_dmamap_create,
183 1.4.2.2 martin _bus_dmamap_destroy,
184 1.4.2.2 martin _bus_dmamap_load,
185 1.4.2.2 martin _bus_dmamap_load_mbuf,
186 1.4.2.2 martin _bus_dmamap_load_uio,
187 1.4.2.2 martin _bus_dmamap_load_raw,
188 1.4.2.2 martin _bus_dmamap_unload,
189 1.4.2.2 martin _bus_dmamap_sync,
190 1.4.2.2 martin _bus_dmamem_alloc,
191 1.4.2.2 martin _bus_dmamem_free,
192 1.4.2.2 martin _bus_dmamem_map,
193 1.4.2.2 martin _bus_dmamem_unmap,
194 1.4.2.2 martin _bus_dmamem_mmap,
195 1.4.2.2 martin wii_dma_phys_to_bus_mem,
196 1.4.2.2 martin wii_dma_bus_mem_to_phys,
197 1.4.2.2 martin };
198 1.4.2.2 martin
199 1.4.2.2 martin struct powerpc_bus_dma_tag wii_mem2_bus_dma_tag = {
200 1.4.2.2 martin 0, /* _bounce_thresh */
201 1.4.2.2 martin _bus_dmamap_create,
202 1.4.2.2 martin _bus_dmamap_destroy,
203 1.4.2.2 martin _bus_dmamap_load,
204 1.4.2.2 martin _bus_dmamap_load_mbuf,
205 1.4.2.2 martin _bus_dmamap_load_uio,
206 1.4.2.2 martin _bus_dmamap_load_raw,
207 1.4.2.2 martin _bus_dmamap_unload,
208 1.4.2.2 martin _bus_dmamap_sync,
209 1.4.2.2 martin wii_mem2_dmamem_alloc,
210 1.4.2.2 martin _bus_dmamem_free,
211 1.4.2.2 martin _bus_dmamem_map,
212 1.4.2.2 martin _bus_dmamem_unmap,
213 1.4.2.2 martin _bus_dmamem_mmap,
214 1.4.2.2 martin wii_dma_phys_to_bus_mem,
215 1.4.2.2 martin wii_dma_bus_mem_to_phys,
216 1.4.2.2 martin };
217 1.4.2.2 martin
218 1.4.2.2 martin
219 1.4.2.2 martin /*
220 1.4.2.2 martin * Global variables used here and there
221 1.4.2.2 martin */
222 1.4.2.2 martin struct mem_region physmemr[3], availmemr[3];
223 1.4.2.2 martin char wii_cmdline[1024];
224 1.4.2.2 martin
225 1.4.2.2 martin void initppc(u_int, u_int, u_int, void *); /* Called from locore */
226 1.4.2.2 martin void wii_dolphin_elf_loader_id(void);
227 1.4.2.2 martin
228 1.4.2.2 martin static void wii_setup(void);
229 1.4.2.2 martin static void init_decrementer(void);
230 1.4.2.2 martin
231 1.4.2.2 martin void
232 1.4.2.2 martin initppc(u_int startkernel, u_int endkernel, u_int args, void *btinfo)
233 1.4.2.2 martin {
234 1.4.2.4 martin extern uint32_t ticks_per_sec;
235 1.4.2.4 martin extern uint32_t ticks_per_msec;
236 1.4.2.2 martin extern unsigned char edata[], end[];
237 1.4.2.2 martin extern struct wii_argv wii_argv;
238 1.4.2.3 martin uint32_t mem2_start, mem2_end;
239 1.4.2.2 martin register_t scratch;
240 1.4.2.2 martin
241 1.4.2.2 martin memset(&edata, 0, end - edata); /* clear BSS */
242 1.4.2.2 martin
243 1.4.2.3 martin wii_cmdline[0] = '\0';
244 1.4.2.2 martin if (wii_argv.magic == WII_ARGV_MAGIC) {
245 1.4.2.2 martin void *ptr = (void *)(uintptr_t)(wii_argv.cmdline & ~0x80000000);
246 1.4.2.2 martin if (ptr != NULL) {
247 1.4.2.2 martin memcpy(wii_cmdline, ptr, wii_argv.length);
248 1.4.2.2 martin }
249 1.4.2.3 martin } else {
250 1.4.2.3 martin snprintf(wii_cmdline, sizeof(wii_cmdline), WII_DEFAULT_CMDLINE);
251 1.4.2.2 martin }
252 1.4.2.2 martin
253 1.4.2.3 martin mem2_start = in32(GLOBAL_MEM2_AVAIL_START) & ~0x80000000;
254 1.4.2.3 martin mem2_end = in32(GLOBAL_MEM2_AVAIL_END) & ~0x80000000;
255 1.4.2.3 martin if (mem2_start < WII_MEM2_BASE) {
256 1.4.2.3 martin /* Must have been booted from MINI. */
257 1.4.2.3 martin mem2_start = WII_MEM2_BASE + DSP_MEM_SIZE;
258 1.4.2.3 martin mem2_end = MINI_MEM2_START;
259 1.4.2.3 martin }
260 1.4.2.3 martin /*
261 1.4.2.3 martin * Clear GLOBAL_MEM2_AVAIL_{START,END} so we can detect the correct
262 1.4.2.3 martin * memory size when soft resetting from IOS to MINI.
263 1.4.2.3 martin */
264 1.4.2.3 martin out32(GLOBAL_MEM2_AVAIL_START, 0);
265 1.4.2.3 martin out32(GLOBAL_MEM2_AVAIL_END, 0);
266 1.4.2.2 martin
267 1.4.2.2 martin /* MEM1 24MB 1T-SRAM */
268 1.4.2.2 martin physmemr[0].start = WII_MEM1_BASE;
269 1.4.2.2 martin physmemr[0].size = WII_MEM1_SIZE;
270 1.4.2.2 martin
271 1.4.2.2 martin /* MEM2 64MB GDDR3 */
272 1.4.2.2 martin physmemr[1].start = WII_MEM2_BASE;
273 1.4.2.3 martin physmemr[1].size = WII_MEM2_SIZE;
274 1.4.2.2 martin
275 1.4.2.2 martin physmemr[2].size = 0;
276 1.4.2.2 martin
277 1.4.2.2 martin /* MEM1 available memory */
278 1.4.2.2 martin availmemr[0].start = ((endkernel & ~0x80000000) + PGOFSET) & ~PGOFSET;
279 1.4.2.2 martin availmemr[0].size = physmemr[0].size - availmemr[0].start;
280 1.4.2.2 martin /* External framebuffer is at the end of MEM1 */
281 1.4.2.2 martin availmemr[0].size -= XFB_SIZE;
282 1.4.2.2 martin
283 1.4.2.2 martin /* MEM2 available memory */
284 1.4.2.3 martin availmemr[1].start = mem2_start;
285 1.4.2.3 martin availmemr[1].size = mem2_end - mem2_start;
286 1.4.2.2 martin
287 1.4.2.2 martin availmemr[2].size = 0;
288 1.4.2.2 martin
289 1.4.2.2 martin #ifdef BOOTHOWTO
290 1.4.2.2 martin /*
291 1.4.2.2 martin * boothowto
292 1.4.2.2 martin */
293 1.4.2.2 martin boothowto = BOOTHOWTO;
294 1.4.2.2 martin #endif
295 1.4.2.2 martin
296 1.4.2.2 martin /* HID4[L2_CCFI] must be set to 1 for correct operation of L2 cache */
297 1.4.2.2 martin mtspr(IBM750CL_SPR_HID4, mfspr(IBM750CL_SPR_HID4) | L2_CCFI);
298 1.4.2.2 martin
299 1.4.2.2 martin /* Configure L2 cache */
300 1.4.2.2 martin l2cr_config = L2CR_L2E | L2CR_L2PE;
301 1.4.2.2 martin
302 1.4.2.2 martin if (bus_space_init(&wii_mem_tag, "iomem",
303 1.4.2.2 martin ex_storage[0], sizeof(ex_storage[0]))) {
304 1.4.2.2 martin panic("bus_space_init failed");
305 1.4.2.2 martin }
306 1.4.2.2 martin
307 1.4.2.2 martin /*
308 1.4.2.2 martin * Initialize the BAT registers
309 1.4.2.2 martin */
310 1.4.2.2 martin oea_batinit(
311 1.4.2.2 martin WII_IOMEM_BASE, BAT_BL_32M,
312 1.4.2.2 martin 0);
313 1.4.2.2 martin
314 1.4.2.2 martin /*
315 1.4.2.2 martin * Set up trap vectors
316 1.4.2.2 martin */
317 1.4.2.2 martin oea_init(NULL);
318 1.4.2.2 martin
319 1.4.2.2 martin /*
320 1.4.2.2 martin * Get CPU clock
321 1.4.2.2 martin */
322 1.4.2.2 martin ticks_per_sec = TIMEBASE_FREQ_HZ;
323 1.4.2.4 martin ticks_per_msec = ticks_per_sec / 1000;
324 1.4.2.2 martin cpu_timebase = ticks_per_sec;
325 1.4.2.2 martin
326 1.4.2.2 martin wii_setup();
327 1.4.2.2 martin
328 1.4.2.2 martin uvm_md_init();
329 1.4.2.2 martin
330 1.4.2.2 martin /*
331 1.4.2.2 martin * Initialize pmap module.
332 1.4.2.2 martin */
333 1.4.2.2 martin pmap_bootstrap(startkernel, endkernel);
334 1.4.2.2 martin
335 1.4.2.2 martin /* Now enable translation (and machine checks/recoverable interrupts) */
336 1.4.2.2 martin __asm __volatile ("sync; mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
337 1.4.2.2 martin : "=r"(scratch)
338 1.4.2.2 martin : "K"(PSL_IR|PSL_DR|PSL_ME|PSL_RI));
339 1.4.2.2 martin
340 1.4.2.2 martin /*
341 1.4.2.2 martin * Setup decrementer
342 1.4.2.2 martin */
343 1.4.2.2 martin init_decrementer();
344 1.4.2.2 martin }
345 1.4.2.2 martin
346 1.4.2.2 martin void
347 1.4.2.2 martin mem_regions(struct mem_region **mem, struct mem_region **avail)
348 1.4.2.2 martin {
349 1.4.2.2 martin *mem = physmemr;
350 1.4.2.2 martin *avail = availmemr;
351 1.4.2.2 martin }
352 1.4.2.2 martin
353 1.4.2.2 martin /*
354 1.4.2.2 martin * Machine dependent startup code.
355 1.4.2.2 martin */
356 1.4.2.2 martin void
357 1.4.2.2 martin cpu_startup(void)
358 1.4.2.2 martin {
359 1.4.2.2 martin extern void pi_init_intr(void);
360 1.4.2.2 martin
361 1.4.2.2 martin oea_startup(NULL);
362 1.4.2.2 martin
363 1.4.2.2 martin /*
364 1.4.2.2 martin * Now that we have VM, malloc()s are OK in bus_space.
365 1.4.2.2 martin */
366 1.4.2.2 martin bus_space_mallocok();
367 1.4.2.2 martin
368 1.4.2.2 martin /* Set up interrupt controller */
369 1.4.2.2 martin pic_init();
370 1.4.2.2 martin pi_init_intr();
371 1.4.2.2 martin oea_install_extint(pic_ext_intr);
372 1.4.2.2 martin }
373 1.4.2.2 martin
374 1.4.2.2 martin /*
375 1.4.2.2 martin * No early console support.
376 1.4.2.2 martin */
377 1.4.2.2 martin void
378 1.4.2.2 martin consinit(void)
379 1.4.2.2 martin {
380 1.4.2.2 martin #if NUKBD > 0
381 1.4.2.2 martin ukbd_cnattach();
382 1.4.2.2 martin #endif
383 1.4.2.2 martin }
384 1.4.2.2 martin
385 1.4.2.2 martin /*
386 1.4.2.2 martin * Halt or reboot the machine after syncing/dumping according to howto.
387 1.4.2.2 martin */
388 1.4.2.2 martin void
389 1.4.2.2 martin cpu_reboot(int howto, char *what)
390 1.4.2.2 martin {
391 1.4.2.2 martin static int syncing;
392 1.4.2.2 martin extern void disable_intr(void);
393 1.4.2.2 martin
394 1.4.2.2 martin boothowto = howto;
395 1.4.2.2 martin if (!cold && !(howto & RB_NOSYNC) && !syncing) {
396 1.4.2.2 martin syncing = 1;
397 1.4.2.2 martin vfs_shutdown(); /* sync */
398 1.4.2.2 martin resettodr(); /* set wall clock */
399 1.4.2.2 martin }
400 1.4.2.2 martin splhigh();
401 1.4.2.2 martin if (!cold && (howto & RB_DUMP)) {
402 1.4.2.2 martin oea_dumpsys();
403 1.4.2.2 martin }
404 1.4.2.2 martin pmf_system_shutdown(boothowto);
405 1.4.2.2 martin doshutdownhooks();
406 1.4.2.2 martin
407 1.4.2.2 martin disable_intr();
408 1.4.2.2 martin
409 1.4.2.2 martin /* Force halt on panic to capture the cause on screen. */
410 1.4.2.2 martin if (panicstr != NULL) {
411 1.4.2.2 martin howto |= RB_HALT;
412 1.4.2.2 martin }
413 1.4.2.2 martin if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
414 1.4.2.2 martin printf("power off\n\n");
415 1.4.2.2 martin out32(HW_GPIOB_OUT, in32(HW_GPIOB_OUT) | __BIT(GPIO_SHUTDOWN));
416 1.4.2.2 martin delay(100000);
417 1.4.2.2 martin printf("power off failed!\n\n");
418 1.4.2.2 martin }
419 1.4.2.2 martin if (howto & RB_HALT) {
420 1.4.2.2 martin printf("halted\n\n");
421 1.4.2.2 martin while (1);
422 1.4.2.2 martin }
423 1.4.2.2 martin
424 1.4.2.2 martin printf("rebooting\n\n");
425 1.4.2.2 martin out32(HW_RESETS, in32(HW_RESETS) & ~RSTBINB);
426 1.4.2.2 martin while (1);
427 1.4.2.2 martin }
428 1.4.2.2 martin
429 1.4.2.2 martin static void
430 1.4.2.2 martin wii_setup(void)
431 1.4.2.2 martin {
432 1.4.2.2 martin /* Turn on the drive slot LED. */
433 1.4.2.3 martin wii_slot_led(true);
434 1.4.2.2 martin
435 1.4.2.2 martin /* Enable PPC access to SHUTDOWN GPIO. */
436 1.4.2.2 martin out32(HW_GPIO_OWNER, in32(HW_GPIO_OWNER) | __BIT(GPIO_SHUTDOWN));
437 1.4.2.3 martin
438 1.4.2.3 martin /* Enable PPC access to EXI bus. */
439 1.4.2.3 martin out32(HW_AIPPROT, in32(HW_AIPPROT) | ENAHBIOPI);
440 1.4.2.2 martin }
441 1.4.2.2 martin
442 1.4.2.2 martin static void
443 1.4.2.2 martin init_decrementer(void)
444 1.4.2.2 martin {
445 1.4.2.2 martin extern uint32_t ns_per_tick;
446 1.4.2.2 martin extern uint32_t ticks_per_intr;
447 1.4.2.4 martin extern uint32_t ticks_per_sec;
448 1.4.2.2 martin int scratch, msr;
449 1.4.2.2 martin
450 1.4.2.2 martin KASSERT(ticks_per_sec != 0);
451 1.4.2.2 martin
452 1.4.2.2 martin __asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1"
453 1.4.2.2 martin : "=r"(msr), "=r"(scratch) : "K"((u_short)~PSL_EE));
454 1.4.2.2 martin ns_per_tick = 1000000000 / ticks_per_sec;
455 1.4.2.2 martin ticks_per_intr = ticks_per_sec / hz;
456 1.4.2.2 martin cpu_timebase = ticks_per_sec;
457 1.4.2.2 martin
458 1.4.2.2 martin curcpu()->ci_lasttb = mftbl();
459 1.4.2.2 martin
460 1.4.2.2 martin mtspr(SPR_DEC, ticks_per_intr);
461 1.4.2.2 martin mtmsr(msr);
462 1.4.2.2 martin }
463