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