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