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