xref: /freebsd/sys/arm/allwinner/aw_machdep.c (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
1 /*-
2  * Copyright (c) 2012 Ganbold Tsagaankhuu <ganbold@freebsd.org>
3  * Copyright (c) 2015-2016 Emmanuel Vadot <manu@freebsd.org>
4  * All rights reserved.
5  *
6  * This code is derived from software written for Brini by Mark Brinicombe
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29 
30  * from: FreeBSD: //depot/projects/arm/src/sys/arm/ti/ti_machdep.c
31  */
32 
33 #include "opt_ddb.h"
34 #include "opt_platform.h"
35 
36 #include <sys/cdefs.h>
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/bus.h>
40 #include <sys/devmap.h>
41 
42 #include <vm/vm.h>
43 #include <vm/pmap.h>
44 
45 #include <machine/bus.h>
46 #include <machine/machdep.h>
47 #include <machine/platformvar.h>
48 
49 #include <arm/allwinner/aw_mp.h>
50 #include <arm/allwinner/aw_wdog.h>
51 #include <arm/allwinner/aw_machdep.h>
52 
53 #include "platform_if.h"
54 
55 static platform_attach_t a10_attach;
56 static platform_attach_t a13_attach;
57 static platform_attach_t a20_attach;
58 static platform_attach_t a31_attach;
59 static platform_attach_t a31s_attach;
60 static platform_attach_t a83t_attach;
61 static platform_attach_t h3_attach;
62 static platform_devmap_init_t allwinner_devmap_init;
63 static platform_cpu_reset_t allwinner_cpu_reset;
64 
65 static u_int soc_type;
66 static u_int soc_family;
67 
68 static int
69 a10_attach(platform_t plat)
70 {
71 	soc_type = ALLWINNERSOC_A10;
72 	soc_family = ALLWINNERSOC_SUN4I;
73 	return (0);
74 }
75 
76 static int
77 a13_attach(platform_t plat)
78 {
79 	soc_type = ALLWINNERSOC_A13;
80 	soc_family = ALLWINNERSOC_SUN5I;
81 	return (0);
82 }
83 
84 static int
85 a20_attach(platform_t plat)
86 {
87 	soc_type = ALLWINNERSOC_A20;
88 	soc_family = ALLWINNERSOC_SUN7I;
89 
90 	return (0);
91 }
92 
93 static int
94 a31_attach(platform_t plat)
95 {
96 	soc_type = ALLWINNERSOC_A31;
97 	soc_family = ALLWINNERSOC_SUN6I;
98 
99 	return (0);
100 }
101 
102 static int
103 a31s_attach(platform_t plat)
104 {
105 	soc_type = ALLWINNERSOC_A31S;
106 	soc_family = ALLWINNERSOC_SUN6I;
107 
108 	return (0);
109 }
110 
111 static int
112 a33_attach(platform_t plat)
113 {
114 	soc_type = ALLWINNERSOC_A33;
115 	soc_family = ALLWINNERSOC_SUN8I;
116 
117 	return (0);
118 }
119 
120 static int
121 a83t_attach(platform_t plat)
122 {
123 	soc_type = ALLWINNERSOC_A83T;
124 	soc_family = ALLWINNERSOC_SUN8I;
125 
126 	return (0);
127 }
128 
129 static int
130 h3_attach(platform_t plat)
131 {
132 	soc_type = ALLWINNERSOC_H3;
133 	soc_family = ALLWINNERSOC_SUN8I;
134 
135 	return (0);
136 }
137 
138 /*
139  * Set up static device mappings.
140  *
141  * This covers all the on-chip device with 1MB section mappings, which is good
142  * for performance (uses fewer TLB entries for device access).
143  *
144  * XXX It also covers a block of SRAM and some GPU (mali400) stuff that maybe
145  * shouldn't be device-mapped.  The original code mapped a 4MB block, but
146  * perhaps a 1MB block would be more appropriate.
147  */
148 static int
149 allwinner_devmap_init(platform_t plat)
150 {
151 
152 	devmap_add_entry(0x01C00000, 0x00400000); /* 4MB */
153 
154 	return (0);
155 }
156 
157 static void
158 allwinner_cpu_reset(platform_t plat)
159 {
160 	aw_wdog_watchdog_reset();
161 	printf("Reset failed!\n");
162 	while (1);
163 }
164 
165 #if defined(SOC_ALLWINNER_A10)
166 static platform_method_t a10_methods[] = {
167 	PLATFORMMETHOD(platform_attach,         a10_attach),
168 	PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
169 	PLATFORMMETHOD(platform_cpu_reset,	allwinner_cpu_reset),
170 
171 	PLATFORMMETHOD_END,
172 };
173 FDT_PLATFORM_DEF(a10, "a10", 0, "allwinner,sun4i-a10", 200);
174 #endif
175 
176 #if defined(SOC_ALLWINNER_A13)
177 static platform_method_t a13_methods[] = {
178 	PLATFORMMETHOD(platform_attach,         a13_attach),
179 	PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
180 	PLATFORMMETHOD(platform_cpu_reset,	allwinner_cpu_reset),
181 
182 	PLATFORMMETHOD_END,
183 };
184 FDT_PLATFORM_DEF(a13, "a13", 0, "allwinner,sun5i-a13", 200);
185 #endif
186 
187 #if defined(SOC_ALLWINNER_A20)
188 static platform_method_t a20_methods[] = {
189 	PLATFORMMETHOD(platform_attach,         a20_attach),
190 	PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
191 	PLATFORMMETHOD(platform_cpu_reset,	allwinner_cpu_reset),
192 
193 #ifdef SMP
194 	PLATFORMMETHOD(platform_mp_start_ap,	aw_mp_start_ap),
195 	PLATFORMMETHOD(platform_mp_setmaxid,	aw_mp_setmaxid),
196 #endif
197 	PLATFORMMETHOD_END,
198 };
199 FDT_PLATFORM_DEF(a20, "a20", 0, "allwinner,sun7i-a20", 200);
200 #endif
201 
202 #if defined(SOC_ALLWINNER_A31)
203 static platform_method_t a31_methods[] = {
204 	PLATFORMMETHOD(platform_attach,         a31_attach),
205 	PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
206 	PLATFORMMETHOD(platform_cpu_reset,	allwinner_cpu_reset),
207 
208 #ifdef SMP
209 	PLATFORMMETHOD(platform_mp_start_ap,	aw_mp_start_ap),
210 	PLATFORMMETHOD(platform_mp_setmaxid,	aw_mp_setmaxid),
211 #endif
212 	PLATFORMMETHOD_END,
213 };
214 FDT_PLATFORM_DEF(a31, "a31", 0, "allwinner,sun6i-a31", 200);
215 #endif
216 
217 #if defined(SOC_ALLWINNER_A31S)
218 static platform_method_t a31s_methods[] = {
219 	PLATFORMMETHOD(platform_attach,         a31s_attach),
220 	PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
221 	PLATFORMMETHOD(platform_cpu_reset,	allwinner_cpu_reset),
222 
223 #ifdef SMP
224 	PLATFORMMETHOD(platform_mp_start_ap,	aw_mp_start_ap),
225 	PLATFORMMETHOD(platform_mp_setmaxid,	aw_mp_setmaxid),
226 #endif
227 	PLATFORMMETHOD_END,
228 };
229 FDT_PLATFORM_DEF(a31s, "a31s", 0, "allwinner,sun6i-a31s", 200);
230 #endif
231 
232 #if defined(SOC_ALLWINNER_A33)
233 static platform_method_t a33_methods[] = {
234 	PLATFORMMETHOD(platform_attach,         a33_attach),
235 	PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
236 	PLATFORMMETHOD(platform_cpu_reset,	allwinner_cpu_reset),
237 
238 #ifdef SMP
239 	PLATFORMMETHOD(platform_mp_start_ap,	aw_mp_start_ap),
240 	PLATFORMMETHOD(platform_mp_setmaxid,	aw_mp_setmaxid),
241 #endif
242 	PLATFORMMETHOD_END,
243 };
244 FDT_PLATFORM_DEF(a33, "a33", 0, "allwinner,sun8i-a33", 200);
245 #endif
246 
247 #if defined(SOC_ALLWINNER_A83T)
248 static platform_method_t a83t_methods[] = {
249 	PLATFORMMETHOD(platform_attach,         a83t_attach),
250 	PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
251 	PLATFORMMETHOD(platform_cpu_reset,	allwinner_cpu_reset),
252 
253 #ifdef SMP
254 	PLATFORMMETHOD(platform_mp_start_ap,	a83t_mp_start_ap),
255 	PLATFORMMETHOD(platform_mp_setmaxid,	aw_mp_setmaxid),
256 #endif
257 	PLATFORMMETHOD_END,
258 };
259 FDT_PLATFORM_DEF(a83t, "a83t", 0, "allwinner,sun8i-a83t", 200);
260 #endif
261 
262 #if defined(SOC_ALLWINNER_H2PLUS)
263 static platform_method_t h2_plus_methods[] = {
264 	PLATFORMMETHOD(platform_attach,         h3_attach),
265 	PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
266 	PLATFORMMETHOD(platform_cpu_reset,	allwinner_cpu_reset),
267 
268 #ifdef SMP
269 	PLATFORMMETHOD(platform_mp_start_ap,	aw_mp_start_ap),
270 	PLATFORMMETHOD(platform_mp_setmaxid,	aw_mp_setmaxid),
271 #endif
272 	PLATFORMMETHOD_END,
273 };
274 FDT_PLATFORM_DEF(h2_plus, "h2_plus", 0, "allwinner,sun8i-h2-plus", 200);
275 #endif
276 
277 #if defined(SOC_ALLWINNER_H3)
278 static platform_method_t h3_methods[] = {
279 	PLATFORMMETHOD(platform_attach,         h3_attach),
280 	PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
281 	PLATFORMMETHOD(platform_cpu_reset,	allwinner_cpu_reset),
282 
283 #ifdef SMP
284 	PLATFORMMETHOD(platform_mp_start_ap,	aw_mp_start_ap),
285 	PLATFORMMETHOD(platform_mp_setmaxid,	aw_mp_setmaxid),
286 #endif
287 	PLATFORMMETHOD_END,
288 };
289 FDT_PLATFORM_DEF(h3, "h3", 0, "allwinner,sun8i-h3", 200);
290 #endif
291 
292 u_int
293 allwinner_soc_type(void)
294 {
295 	return (soc_type);
296 }
297 
298 u_int
299 allwinner_soc_family(void)
300 {
301 	return (soc_family);
302 }
303