]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/powerpc/wii/platform_wii.c
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / sys / powerpc / wii / platform_wii.c
1 /*-
2  * Copyright (C) 2012 Margarida Gouveia
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer,
10  *    without modification, immediately at the beginning of the file.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/kernel.h>
32 #include <sys/bus.h>
33 #include <sys/pcpu.h>
34 #include <sys/proc.h>
35 #include <sys/reboot.h>
36 #include <sys/smp.h>
37 #include <sys/fbio.h>
38
39 #include <vm/vm.h>
40 #include <vm/pmap.h>
41
42 #include <machine/bus.h>
43 #include <machine/cpu.h>
44 #include <machine/hid.h>
45 #include <machine/platform.h>
46 #include <machine/platformvar.h>
47 #include <machine/pmap.h>
48 #include <machine/smp.h>
49 #include <machine/spr.h>
50 #include <machine/vmparam.h>
51
52 #include <powerpc/wii/wii_fbreg.h>
53 #include <powerpc/wii/wii_ipcreg.h>
54
55 #include "platform_if.h"
56
57 static int              wii_probe(platform_t);
58 static int              wii_attach(platform_t);
59 static void             wii_mem_regions(platform_t, struct mem_region **,
60                             int *, struct mem_region **, int *);
61 static unsigned long    wii_timebase_freq(platform_t, struct cpuref *);
62 static void             wii_reset(platform_t);
63 static void             wii_cpu_idle(sbintime_t);
64
65 extern void              wiibus_reset_system(void);
66
67 static platform_method_t wii_methods[] = {
68         PLATFORMMETHOD(platform_probe,          wii_probe),
69         PLATFORMMETHOD(platform_attach,         wii_attach),
70         PLATFORMMETHOD(platform_mem_regions,    wii_mem_regions),
71         PLATFORMMETHOD(platform_timebase_freq,  wii_timebase_freq),
72         PLATFORMMETHOD(platform_reset,          wii_reset),
73  
74         PLATFORMMETHOD_END
75 };
76
77 static platform_def_t wii_platform = {
78         "wii",
79         wii_methods,
80         0
81 };
82
83 PLATFORM_DEF(wii_platform);
84
85 static int
86 wii_probe(platform_t plat)
87 {
88         register_t vers = mfpvr();
89
90         /*
91          * The Wii includes a PowerPC 750CL with custom modifications
92          * ("Broadway").
93          * For now, we just assume that if we are running on a
94          * PowerPC 750CL, then this platform is a Nintendo Wii.
95          */
96         if ((vers & 0xfffff0e0) == (MPC750 << 16 | MPC750CL))
97                 return (BUS_PROBE_SPECIFIC);
98
99         return (ENXIO);
100 }
101
102 static int
103 wii_attach(platform_t plat)
104 {
105         cpu_idle_hook = wii_cpu_idle;
106
107         return (0);
108 }
109
110 #define MEM_REGIONS     2
111 static struct mem_region avail_regions[MEM_REGIONS];
112
113 static void
114 wii_mem_regions(platform_t plat, struct mem_region **phys, int *physsz,
115     struct mem_region **avail, int *availsz)
116 {
117         /* 24MB 1T-SRAM */
118         avail_regions[0].mr_start = 0x00000000;
119         avail_regions[0].mr_size  = 0x01800000;
120
121         /*
122          * Reserve space for the framebuffer which is located
123          * at the end of this 24MB memory region. See wii_fbreg.h.
124          */
125         avail_regions[0].mr_size -= WIIFB_FB_LEN;
126
127         /* 64MB GDDR3 SDRAM */
128         avail_regions[1].mr_start = 0x10000000;
129         avail_regions[1].mr_size  = 0x04000000;
130
131         /*
132          * Reserve space for the DSP.
133          */
134         avail_regions[1].mr_start += 0x4000;
135         avail_regions[1].mr_size -= 0x4000;
136
137         /*
138          * Reserve space for the IOS I/O memory.
139          */
140         avail_regions[1].mr_size -= WIIIPC_IOH_LEN + 1;
141
142         *phys = *avail = avail_regions;
143         *physsz = *availsz = MEM_REGIONS;
144 }
145
146 static u_long
147 wii_timebase_freq(platform_t plat, struct cpuref *cpuref)
148 {
149         
150         /* Bus Frequency (243MHz) / 4 */
151         return (60750000);
152 }
153
154 static void
155 wii_reset(platform_t plat __unused)
156 {
157
158         wiibus_reset_system();
159 }
160
161 static void
162 wii_cpu_idle(sbintime_t sbt)
163 {
164 }