xref: /freebsd/sys/arm/allwinner/aw_machdep.c (revision f5463265955b829775bbb32e1fd0bc11dafc36ce)
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/param.h>
37 #include <sys/systm.h>
38 #include <sys/bus.h>
39 #include <sys/devmap.h>
40 
41 #include <vm/vm.h>
42 #include <vm/pmap.h>
43 
44 #include <machine/bus.h>
45 #include <machine/machdep.h>
46 #include <machine/platformvar.h>
47 
48 #include <arm/allwinner/aw_mp.h>
49 #include <arm/allwinner/aw_wdog.h>
50 #include <arm/allwinner/aw_machdep.h>
51 
52 #include "platform_if.h"
53 
54 static platform_attach_t a10_attach;
55 static platform_attach_t a13_attach;
56 static platform_attach_t a20_attach;
57 static platform_attach_t a31_attach;
58 static platform_attach_t a31s_attach;
59 static platform_attach_t a83t_attach;
60 static platform_attach_t h3_attach;
61 static platform_devmap_init_t allwinner_devmap_init;
62 static platform_cpu_reset_t allwinner_cpu_reset;
63 
64 static u_int soc_type;
65 static u_int soc_family;
66 
67 static int
68 a10_attach(platform_t plat)
69 {
70 	soc_type = ALLWINNERSOC_A10;
71 	soc_family = ALLWINNERSOC_SUN4I;
72 	return (0);
73 }
74 
75 static int
76 a13_attach(platform_t plat)
77 {
78 	soc_type = ALLWINNERSOC_A13;
79 	soc_family = ALLWINNERSOC_SUN5I;
80 	return (0);
81 }
82 
83 static int
84 a20_attach(platform_t plat)
85 {
86 	soc_type = ALLWINNERSOC_A20;
87 	soc_family = ALLWINNERSOC_SUN7I;
88 
89 	return (0);
90 }
91 
92 static int
93 a31_attach(platform_t plat)
94 {
95 	soc_type = ALLWINNERSOC_A31;
96 	soc_family = ALLWINNERSOC_SUN6I;
97 
98 	return (0);
99 }
100 
101 static int
102 a31s_attach(platform_t plat)
103 {
104 	soc_type = ALLWINNERSOC_A31S;
105 	soc_family = ALLWINNERSOC_SUN6I;
106 
107 	return (0);
108 }
109 
110 static int
111 a33_attach(platform_t plat)
112 {
113 	soc_type = ALLWINNERSOC_A33;
114 	soc_family = ALLWINNERSOC_SUN8I;
115 
116 	return (0);
117 }
118 
119 static int
120 a83t_attach(platform_t plat)
121 {
122 	soc_type = ALLWINNERSOC_A83T;
123 	soc_family = ALLWINNERSOC_SUN8I;
124 
125 	return (0);
126 }
127 
128 static int
129 h3_attach(platform_t plat)
130 {
131 	soc_type = ALLWINNERSOC_H3;
132 	soc_family = ALLWINNERSOC_SUN8I;
133 
134 	return (0);
135 }
136 
137 /*
138  * Set up static device mappings.
139  *
140  * This covers all the on-chip device with 1MB section mappings, which is good
141  * for performance (uses fewer TLB entries for device access).
142  *
143  * XXX It also covers a block of SRAM and some GPU (mali400) stuff that maybe
144  * shouldn't be device-mapped.  The original code mapped a 4MB block, but
145  * perhaps a 1MB block would be more appropriate.
146  */
147 static int
148 allwinner_devmap_init(platform_t plat)
149 {
150 
151 	devmap_add_entry(0x01C00000, 0x00400000); /* 4MB */
152 
153 	return (0);
154 }
155 
156 static void
157 allwinner_cpu_reset(platform_t plat)
158 {
159 	aw_wdog_watchdog_reset();
160 	printf("Reset failed!\n");
161 	while (1);
162 }
163 
164 #if defined(SOC_ALLWINNER_A10)
165 static platform_method_t a10_methods[] = {
166 	PLATFORMMETHOD(platform_attach,         a10_attach),
167 	PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
168 	PLATFORMMETHOD(platform_cpu_reset,	allwinner_cpu_reset),
169 
170 	PLATFORMMETHOD_END,
171 };
172 FDT_PLATFORM_DEF(a10, "a10", 0, "allwinner,sun4i-a10", 200);
173 #endif
174 
175 #if defined(SOC_ALLWINNER_A13)
176 static platform_method_t a13_methods[] = {
177 	PLATFORMMETHOD(platform_attach,         a13_attach),
178 	PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
179 	PLATFORMMETHOD(platform_cpu_reset,	allwinner_cpu_reset),
180 
181 	PLATFORMMETHOD_END,
182 };
183 FDT_PLATFORM_DEF(a13, "a13", 0, "allwinner,sun5i-a13", 200);
184 #endif
185 
186 #if defined(SOC_ALLWINNER_A20)
187 static platform_method_t a20_methods[] = {
188 	PLATFORMMETHOD(platform_attach,         a20_attach),
189 	PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
190 	PLATFORMMETHOD(platform_cpu_reset,	allwinner_cpu_reset),
191 
192 #ifdef SMP
193 	PLATFORMMETHOD(platform_mp_start_ap,	aw_mp_start_ap),
194 	PLATFORMMETHOD(platform_mp_setmaxid,	aw_mp_setmaxid),
195 #endif
196 	PLATFORMMETHOD_END,
197 };
198 FDT_PLATFORM_DEF(a20, "a20", 0, "allwinner,sun7i-a20", 200);
199 #endif
200 
201 #if defined(SOC_ALLWINNER_A31)
202 static platform_method_t a31_methods[] = {
203 	PLATFORMMETHOD(platform_attach,         a31_attach),
204 	PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
205 	PLATFORMMETHOD(platform_cpu_reset,	allwinner_cpu_reset),
206 
207 #ifdef SMP
208 	PLATFORMMETHOD(platform_mp_start_ap,	aw_mp_start_ap),
209 	PLATFORMMETHOD(platform_mp_setmaxid,	aw_mp_setmaxid),
210 #endif
211 	PLATFORMMETHOD_END,
212 };
213 FDT_PLATFORM_DEF(a31, "a31", 0, "allwinner,sun6i-a31", 200);
214 #endif
215 
216 #if defined(SOC_ALLWINNER_A31S)
217 static platform_method_t a31s_methods[] = {
218 	PLATFORMMETHOD(platform_attach,         a31s_attach),
219 	PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
220 	PLATFORMMETHOD(platform_cpu_reset,	allwinner_cpu_reset),
221 
222 #ifdef SMP
223 	PLATFORMMETHOD(platform_mp_start_ap,	aw_mp_start_ap),
224 	PLATFORMMETHOD(platform_mp_setmaxid,	aw_mp_setmaxid),
225 #endif
226 	PLATFORMMETHOD_END,
227 };
228 FDT_PLATFORM_DEF(a31s, "a31s", 0, "allwinner,sun6i-a31s", 200);
229 #endif
230 
231 #if defined(SOC_ALLWINNER_A33)
232 static platform_method_t a33_methods[] = {
233 	PLATFORMMETHOD(platform_attach,         a33_attach),
234 	PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
235 	PLATFORMMETHOD(platform_cpu_reset,	allwinner_cpu_reset),
236 
237 #ifdef SMP
238 	PLATFORMMETHOD(platform_mp_start_ap,	aw_mp_start_ap),
239 	PLATFORMMETHOD(platform_mp_setmaxid,	aw_mp_setmaxid),
240 #endif
241 	PLATFORMMETHOD_END,
242 };
243 FDT_PLATFORM_DEF(a33, "a33", 0, "allwinner,sun8i-a33", 200);
244 #endif
245 
246 #if defined(SOC_ALLWINNER_A83T)
247 static platform_method_t a83t_methods[] = {
248 	PLATFORMMETHOD(platform_attach,         a83t_attach),
249 	PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
250 	PLATFORMMETHOD(platform_cpu_reset,	allwinner_cpu_reset),
251 
252 #ifdef SMP
253 	PLATFORMMETHOD(platform_mp_start_ap,	a83t_mp_start_ap),
254 	PLATFORMMETHOD(platform_mp_setmaxid,	aw_mp_setmaxid),
255 #endif
256 	PLATFORMMETHOD_END,
257 };
258 FDT_PLATFORM_DEF(a83t, "a83t", 0, "allwinner,sun8i-a83t", 200);
259 #endif
260 
261 #if defined(SOC_ALLWINNER_H2PLUS)
262 static platform_method_t h2_plus_methods[] = {
263 	PLATFORMMETHOD(platform_attach,         h3_attach),
264 	PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
265 	PLATFORMMETHOD(platform_cpu_reset,	allwinner_cpu_reset),
266 
267 #ifdef SMP
268 	PLATFORMMETHOD(platform_mp_start_ap,	aw_mp_start_ap),
269 	PLATFORMMETHOD(platform_mp_setmaxid,	aw_mp_setmaxid),
270 #endif
271 	PLATFORMMETHOD_END,
272 };
273 FDT_PLATFORM_DEF(h2_plus, "h2_plus", 0, "allwinner,sun8i-h2-plus", 200);
274 #endif
275 
276 #if defined(SOC_ALLWINNER_H3)
277 static platform_method_t h3_methods[] = {
278 	PLATFORMMETHOD(platform_attach,         h3_attach),
279 	PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
280 	PLATFORMMETHOD(platform_cpu_reset,	allwinner_cpu_reset),
281 
282 #ifdef SMP
283 	PLATFORMMETHOD(platform_mp_start_ap,	aw_mp_start_ap),
284 	PLATFORMMETHOD(platform_mp_setmaxid,	aw_mp_setmaxid),
285 #endif
286 	PLATFORMMETHOD_END,
287 };
288 FDT_PLATFORM_DEF(h3, "h3", 0, "allwinner,sun8i-h3", 200);
289 #endif
290 
291 u_int
292 allwinner_soc_type(void)
293 {
294 	return (soc_type);
295 }
296 
297 u_int
298 allwinner_soc_family(void)
299 {
300 	return (soc_family);
301 }
302