]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm/allwinner/allwinner_machdep.c
Reduce complexity of RSB by always using polling mode. Unfortunately
[FreeBSD/FreeBSD.git] / sys / arm / allwinner / allwinner_machdep.c
1 /*-
2  * Copyright (c) 2012 Ganbold Tsagaankhuu <ganbold@freebsd.org>
3  * Copyright (c) 2015-2016 Emmanuel Vadot <manu@bidouilliste.com>
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  * from: FreeBSD: //depot/projects/arm/src/sys/arm/ti/ti_machdep.c
30  */
31
32 #include "opt_ddb.h"
33 #include "opt_platform.h"
34
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
37
38 #define _ARM32_BUS_DMA_PRIVATE
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/allwinner_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 a20_attach(platform_t plat)
72 {
73         soc_type = ALLWINNERSOC_A20;
74         soc_family = ALLWINNERSOC_SUN7I;
75
76         return (0);
77 }
78
79 static int
80 a31_attach(platform_t plat)
81 {
82         soc_type = ALLWINNERSOC_A31;
83         soc_family = ALLWINNERSOC_SUN6I;
84
85         return (0);
86 }
87
88 static int
89 a31s_attach(platform_t plat)
90 {
91         soc_type = ALLWINNERSOC_A31S;
92         soc_family = ALLWINNERSOC_SUN6I;
93
94         return (0);
95 }
96
97 static int
98 a83t_attach(platform_t plat)
99 {
100         soc_type = ALLWINNERSOC_A83T;
101         soc_family = ALLWINNERSOC_SUN8I;
102
103         return (0);
104 }
105
106 static int
107 h3_attach(platform_t plat)
108 {
109         soc_type = ALLWINNERSOC_H3;
110         soc_family = ALLWINNERSOC_SUN8I;
111
112         return (0);
113 }
114
115 static vm_offset_t
116 allwinner_lastaddr(platform_t plat)
117 {
118
119         return (devmap_lastaddr());
120 }
121
122 /*
123  * Set up static device mappings.
124  *
125  * This covers all the on-chip device with 1MB section mappings, which is good
126  * for performance (uses fewer TLB entries for device access).
127  *
128  * XXX It also covers a block of SRAM and some GPU (mali400) stuff that maybe
129  * shouldn't be device-mapped.  The original code mapped a 4MB block, but
130  * perhaps a 1MB block would be more appropriate.
131  */
132 static int
133 allwinner_devmap_init(platform_t plat)
134 {
135
136         devmap_add_entry(0x01C00000, 0x00400000); /* 4MB */
137
138         return (0);
139 }
140
141 struct arm32_dma_range *
142 bus_dma_get_range(void)
143 {
144         return (NULL);
145 }
146
147 int
148 bus_dma_get_range_nb(void)
149 {
150         return (0);
151 }
152
153 void
154 cpu_reset()
155 {
156         aw_wdog_watchdog_reset();
157         printf("Reset failed!\n");
158         while (1);
159 }
160
161 #if defined(SOC_ALLWINNER_A10)
162 static platform_method_t a10_methods[] = {
163         PLATFORMMETHOD(platform_attach,         a10_attach),
164         PLATFORMMETHOD(platform_lastaddr,       allwinner_lastaddr),
165         PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
166
167         PLATFORMMETHOD_END,
168 };
169 FDT_PLATFORM_DEF(a10, "a10", 0, "allwinner,sun4i-a10", 200);
170 #endif
171
172 #if defined(SOC_ALLWINNER_A20)
173 static platform_method_t a20_methods[] = {
174         PLATFORMMETHOD(platform_attach,         a20_attach),
175         PLATFORMMETHOD(platform_lastaddr,       allwinner_lastaddr),
176         PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
177
178 #ifdef SMP
179         PLATFORMMETHOD(platform_mp_start_ap,    aw_mp_start_ap),
180         PLATFORMMETHOD(platform_mp_setmaxid,    aw_mp_setmaxid),
181 #endif
182         PLATFORMMETHOD_END,
183 };
184 FDT_PLATFORM_DEF(a20, "a20", 0, "allwinner,sun7i-a20", 200);
185 #endif
186
187 #if defined(SOC_ALLWINNER_A31)
188 static platform_method_t a31_methods[] = {
189         PLATFORMMETHOD(platform_attach,         a31_attach),
190         PLATFORMMETHOD(platform_lastaddr,       allwinner_lastaddr),
191         PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
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(a31, "a31", 0, "allwinner,sun6i-a31", 200);
200 #endif
201
202 #if defined(SOC_ALLWINNER_A31S)
203 static platform_method_t a31s_methods[] = {
204         PLATFORMMETHOD(platform_attach,         a31s_attach),
205         PLATFORMMETHOD(platform_lastaddr,       allwinner_lastaddr),
206         PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
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(a31s, "a31s", 0, "allwinner,sun6i-a31s", 200);
215 #endif
216
217 #if defined(SOC_ALLWINNER_A83T)
218 static platform_method_t a83t_methods[] = {
219         PLATFORMMETHOD(platform_attach,         a83t_attach),
220         PLATFORMMETHOD(platform_lastaddr,       allwinner_lastaddr),
221         PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
222
223 #ifdef SMP
224         PLATFORMMETHOD(platform_mp_start_ap,    a83t_mp_start_ap),
225         PLATFORMMETHOD(platform_mp_setmaxid,    aw_mp_setmaxid),
226 #endif
227         PLATFORMMETHOD_END,
228 };
229 FDT_PLATFORM_DEF(a83t, "a83t", 0, "allwinner,sun8i-a83t", 200);
230 #endif
231
232 #if defined(SOC_ALLWINNER_H3)
233 static platform_method_t h3_methods[] = {
234         PLATFORMMETHOD(platform_attach,         h3_attach),
235         PLATFORMMETHOD(platform_lastaddr,       allwinner_lastaddr),
236         PLATFORMMETHOD(platform_devmap_init,    allwinner_devmap_init),
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(h3, "h3", 0, "allwinner,sun8i-h3", 200);
245 #endif
246
247 u_int
248 allwinner_soc_type(void)
249 {
250         return (soc_type);
251 }
252
253 u_int
254 allwinner_soc_family(void)
255 {
256         return (soc_family);
257 }