| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: amlogic_machdep.c,v 1.10 2015/03/01 15:37:26 jmcneill Exp $ */ | | 1 | /* $NetBSD: amlogic_machdep.c,v 1.11 2015/03/03 23:14:41 jmcneill Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Machine dependent functions for kernel setup for TI OSK5912 board. | | 4 | * Machine dependent functions for kernel setup for TI OSK5912 board. |
5 | * Based on lubbock_machdep.c which in turn was based on iq80310_machhdep.c | | 5 | * Based on lubbock_machdep.c which in turn was based on iq80310_machhdep.c |
6 | * | | 6 | * |
7 | * Copyright (c) 2002, 2003, 2005 Genetec Corporation. All rights reserved. | | 7 | * Copyright (c) 2002, 2003, 2005 Genetec Corporation. All rights reserved. |
8 | * Written by Hiroyuki Bessho for Genetec Corporation. | | 8 | * Written by Hiroyuki Bessho for Genetec Corporation. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -115,137 +115,116 @@ | | | @@ -115,137 +115,116 @@ |
115 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | | 115 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
116 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 116 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
117 | * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTERS BE LIABLE FOR ANY DIRECT, | | 117 | * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTERS BE LIABLE FOR ANY DIRECT, |
118 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | 118 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
119 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | | 119 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
120 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 120 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
121 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 121 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
122 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 122 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
123 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 123 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
124 | * SUCH DAMAGE. | | 124 | * SUCH DAMAGE. |
125 | */ | | 125 | */ |
126 | | | 126 | |
127 | #include <sys/cdefs.h> | | 127 | #include <sys/cdefs.h> |
128 | __KERNEL_RCSID(0, "$NetBSD: amlogic_machdep.c,v 1.10 2015/03/01 15:37:26 jmcneill Exp $"); | | 128 | __KERNEL_RCSID(0, "$NetBSD: amlogic_machdep.c,v 1.11 2015/03/03 23:14:41 jmcneill Exp $"); |
129 | | | 129 | |
130 | #include "opt_machdep.h" | | 130 | #include "opt_machdep.h" |
131 | #include "opt_ddb.h" | | 131 | #include "opt_ddb.h" |
132 | #include "opt_kgdb.h" | | | |
133 | #include "opt_ipkdb.h" | | | |
134 | #include "opt_md.h" | | 132 | #include "opt_md.h" |
135 | #include "opt_amlogic.h" | | 133 | #include "opt_amlogic.h" |
136 | #include "opt_arm_debug.h" | | 134 | #include "opt_arm_debug.h" |
137 | #include "opt_multiprocessor.h" | | 135 | #include "opt_multiprocessor.h" |
138 | | | 136 | |
139 | #include "amlogic_com.h" | | 137 | #include "amlogic_com.h" |
140 | #if 0 | | | |
141 | #include "prcm.h" | | | |
142 | #include "sdhc.h" | | | |
143 | #include "ukbd.h" | | | |
144 | #endif | | | |
145 | #include "arml2cc.h" | | 138 | #include "arml2cc.h" |
146 | #include "act8846pm.h" | | | |
147 | #include "ether.h" | | 139 | #include "ether.h" |
148 | | | 140 | |
149 | #include <sys/param.h> | | 141 | #include <sys/param.h> |
150 | #include <sys/systm.h> | | 142 | #include <sys/systm.h> |
151 | #include <sys/bus.h> | | 143 | #include <sys/bus.h> |
152 | #include <sys/atomic.h> | | 144 | #include <sys/atomic.h> |
153 | #include <sys/cpu.h> | | 145 | #include <sys/cpu.h> |
154 | #include <sys/device.h> | | 146 | #include <sys/device.h> |
155 | #include <sys/exec.h> | | 147 | #include <sys/exec.h> |
156 | #include <sys/kernel.h> | | 148 | #include <sys/kernel.h> |
157 | #include <sys/ksyms.h> | | 149 | #include <sys/ksyms.h> |
158 | #include <sys/msgbuf.h> | | 150 | #include <sys/msgbuf.h> |
159 | #include <sys/proc.h> | | 151 | #include <sys/proc.h> |
160 | #include <sys/reboot.h> | | 152 | #include <sys/reboot.h> |
161 | #include <sys/termios.h> | | 153 | #include <sys/termios.h> |
162 | #include <sys/gpio.h> | | 154 | #include <sys/gpio.h> |
163 | | | 155 | |
164 | #include <uvm/uvm_extern.h> | | 156 | #include <uvm/uvm_extern.h> |
165 | | | 157 | |
166 | #include <sys/conf.h> | | 158 | #include <sys/conf.h> |
167 | #include <dev/cons.h> | | 159 | #include <dev/cons.h> |
168 | #include <dev/md.h> | | 160 | #include <dev/md.h> |
169 | | | 161 | |
170 | #include <machine/db_machdep.h> | | 162 | #include <machine/db_machdep.h> |
171 | #include <ddb/db_sym.h> | | 163 | #include <ddb/db_sym.h> |
172 | #include <ddb/db_extern.h> | | 164 | #include <ddb/db_extern.h> |
173 | #ifdef KGDB | | | |
174 | #include <sys/kgdb.h> | | | |
175 | #endif | | | |
176 | | | 165 | |
177 | #include <machine/bootconfig.h> | | 166 | #include <machine/bootconfig.h> |
178 | #include <arm/armreg.h> | | 167 | #include <arm/armreg.h> |
179 | #include <arm/undefined.h> | | 168 | #include <arm/undefined.h> |
180 | | | 169 | |
181 | #include <arm/arm32/machdep.h> | | 170 | #include <arm/arm32/machdep.h> |
182 | #include <arm/mainbus/mainbus.h> | | 171 | #include <arm/mainbus/mainbus.h> |
183 | | | 172 | |
184 | #include <arm/amlogic/amlogic_reg.h> | | 173 | #include <arm/amlogic/amlogic_reg.h> |
185 | #include <arm/amlogic/amlogic_crureg.h> | | 174 | #include <arm/amlogic/amlogic_crureg.h> |
186 | #include <arm/amlogic/amlogic_var.h> | | 175 | #include <arm/amlogic/amlogic_var.h> |
187 | #include <arm/amlogic/amlogic_comreg.h> | | 176 | #include <arm/amlogic/amlogic_comreg.h> |
188 | #include <arm/amlogic/amlogic_comvar.h> | | 177 | #include <arm/amlogic/amlogic_comvar.h> |
189 | | | 178 | |
190 | #include <arm/cortex/pl310_reg.h> | | 179 | #include <arm/cortex/pl310_reg.h> |
191 | #include <arm/cortex/scu_reg.h> | | 180 | #include <arm/cortex/scu_reg.h> |
192 | | | 181 | |
193 | #include <arm/cortex/a9tmr_var.h> | | 182 | #include <arm/cortex/a9tmr_var.h> |
194 | #include <arm/cortex/pl310_var.h> | | 183 | #include <arm/cortex/pl310_var.h> |
195 | | | 184 | |
196 | #include <arm/cortex/gtmr_var.h> | | 185 | #include <arm/cortex/gtmr_var.h> |
197 | | | 186 | |
198 | #include <evbarm/include/autoconf.h> | | 187 | #include <evbarm/include/autoconf.h> |
199 | #include <evbarm/amlogic/platform.h> | | 188 | #include <evbarm/amlogic/platform.h> |
200 | | | 189 | |
201 | #include <dev/i2c/i2cvar.h> | | | |
202 | #include <dev/i2c/ddcreg.h> | | | |
203 | | | | |
204 | #include <dev/usb/ukbdvar.h> | | 190 | #include <dev/usb/ukbdvar.h> |
205 | #include <net/if_ether.h> | | 191 | #include <net/if_ether.h> |
206 | | | 192 | |
207 | #ifndef AMLOGIC_MAX_BOOT_STRING | | 193 | #ifndef AMLOGIC_MAX_BOOT_STRING |
208 | #define AMLOGIC_MAX_BOOT_STRING 1024 | | 194 | #define AMLOGIC_MAX_BOOT_STRING 1024 |
209 | #endif | | 195 | #endif |
210 | | | 196 | |
211 | BootConfig bootconfig; /* Boot config storage */ | | 197 | BootConfig bootconfig; /* Boot config storage */ |
212 | static char bootargs[AMLOGIC_MAX_BOOT_STRING]; | | 198 | static char bootargs[AMLOGIC_MAX_BOOT_STRING]; |
213 | char *boot_args = NULL; | | 199 | char *boot_args = NULL; |
214 | char *boot_file = NULL; | | 200 | char *boot_file = NULL; |
215 | #if 0 | | | |
216 | static uint8_t amlogic_edid[128]; /* EDID storage */ | | | |
217 | #endif | | | |
218 | u_int uboot_args[4] = { 0 }; /* filled in by amlogic_start.S (not in bss) */ | | 201 | u_int uboot_args[4] = { 0 }; /* filled in by amlogic_start.S (not in bss) */ |
219 | | | 202 | |
220 | /* Same things, but for the free (unused by the kernel) memory. */ | | 203 | /* Same things, but for the free (unused by the kernel) memory. */ |
221 | | | 204 | |
222 | extern char KERNEL_BASE_phys[]; | | 205 | extern char KERNEL_BASE_phys[]; |
223 | extern char _end[]; | | 206 | extern char _end[]; |
224 | | | 207 | |
225 | /* | | 208 | /* |
226 | * Macros to translate between physical and virtual for a subset of the | | 209 | * Macros to translate between physical and virtual for a subset of the |
227 | * kernel address space. *Not* for general use. | | 210 | * kernel address space. *Not* for general use. |
228 | */ | | 211 | */ |
229 | #define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys) | | 212 | #define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys) |
230 | #define AMLOGIC_CORE_VOFFSET (AMLOGIC_CORE_VBASE - AMLOGIC_CORE_BASE) | | 213 | #define AMLOGIC_CORE_VOFFSET (AMLOGIC_CORE_VBASE - AMLOGIC_CORE_BASE) |
231 | /* Prototypes */ | | 214 | /* Prototypes */ |
232 | | | 215 | |
233 | void consinit(void); | | 216 | void consinit(void); |
234 | #ifdef KGDB | | | |
235 | static void kgdb_port_init(void); | | | |
236 | #endif | | | |
237 | | | 217 | |
238 | static void init_clocks(void); | | | |
239 | static void amlogic_device_register(device_t, void *); | | 218 | static void amlogic_device_register(device_t, void *); |
240 | static void amlogic_reset(void); | | 219 | static void amlogic_reset(void); |
241 | | | 220 | |
242 | bs_protos(bs_notimpl); | | 221 | bs_protos(bs_notimpl); |
243 | | | 222 | |
244 | /* | | 223 | /* |
245 | * Static device mappings. These peripheral registers are mapped at | | 224 | * Static device mappings. These peripheral registers are mapped at |
246 | * fixed virtual addresses very early in initarm() so that we can use | | 225 | * fixed virtual addresses very early in initarm() so that we can use |
247 | * them while booting the kernel, and stay at the same address | | 226 | * them while booting the kernel, and stay at the same address |
248 | * throughout whole kernel's life time. | | 227 | * throughout whole kernel's life time. |
249 | * | | 228 | * |
250 | * We use this table twice; once with bootstrap page table, and once | | 229 | * We use this table twice; once with bootstrap page table, and once |
251 | * with kernel's page table which we build up in initarm(). | | 230 | * with kernel's page table which we build up in initarm(). |
| @@ -271,295 +250,259 @@ static const struct pmap_devmap devmap[] | | | @@ -271,295 +250,259 @@ static const struct pmap_devmap devmap[] |
271 | }; | | 250 | }; |
272 | | | 251 | |
273 | #undef _A | | 252 | #undef _A |
274 | #undef _S | | 253 | #undef _S |
275 | | | 254 | |
276 | #ifdef DDB | | 255 | #ifdef DDB |
277 | static void | | 256 | static void |
278 | amlogic_db_trap(int where) | | 257 | amlogic_db_trap(int where) |
279 | { | | 258 | { |
280 | /* NOT YET */ | | 259 | /* NOT YET */ |
281 | } | | 260 | } |
282 | #endif | | 261 | #endif |
283 | | | 262 | |
284 | void amlogic_putchar(char c); | | 263 | #ifdef VERBOSE_INIT_ARM |
285 | void | | 264 | static void |
286 | amlogic_putchar(char c) | | 265 | amlogic_putchar(char c) |
287 | { | | 266 | { |
288 | volatile uint32_t *uartaddr = (volatile uint32_t *)CONSADDR_VA; | | 267 | volatile uint32_t *uartaddr = (volatile uint32_t *)CONSADDR_VA; |
289 | int timo = 150000; | | 268 | int timo = 150000; |
290 | | | 269 | |
291 | while ((uartaddr[UART_STATUS_REG/4] & UART_STATUS_TX_EMPTY) == 0) { | | 270 | while ((uartaddr[UART_STATUS_REG/4] & UART_STATUS_TX_EMPTY) == 0) { |
292 | if (--timo == 0) | | 271 | if (--timo == 0) |
293 | break; | | 272 | break; |
294 | } | | 273 | } |
295 | | | 274 | |
296 | uartaddr[UART_WFIFO_REG/4] = c; | | 275 | uartaddr[UART_WFIFO_REG/4] = c; |
297 | | | 276 | |
298 | while ((uartaddr[UART_STATUS_REG/4] & UART_STATUS_TX_EMPTY) == 0) { | | 277 | while ((uartaddr[UART_STATUS_REG/4] & UART_STATUS_TX_EMPTY) == 0) { |
299 | if (--timo == 0) | | 278 | if (--timo == 0) |
300 | break; | | 279 | break; |
301 | } | | 280 | } |
302 | } | | 281 | } |
| | | 282 | static void |
| | | 283 | amlogic_putstr(const char *s) |
| | | 284 | { |
| | | 285 | for (const char *p = s; *p; p++) { |
| | | 286 | amlogic_putchar(*p); |
| | | 287 | } |
| | | 288 | } |
| | | 289 | #define DPRINTF(...) printf(__VA_ARGS__) |
| | | 290 | #define DPRINT(x) amlogic_putstr(x) |
| | | 291 | #else |
| | | 292 | #define DPRINTF(...) |
| | | 293 | #define DPRINT(x) |
| | | 294 | #endif |
303 | | | 295 | |
304 | static psize_t | | 296 | static psize_t |
305 | amlogic_get_ram_size(void) | | 297 | amlogic_get_ram_size(void) |
306 | { | | 298 | { |
307 | const bus_space_handle_t ao_bsh = | | 299 | const bus_space_handle_t ao_bsh = |
308 | AMLOGIC_CORE_VBASE + AMLOGIC_SRAM_OFFSET; | | 300 | AMLOGIC_CORE_VBASE + AMLOGIC_SRAM_OFFSET; |
309 | return bus_space_read_4(&amlogic_bs_tag, ao_bsh, 0) << 20; | | 301 | return bus_space_read_4(&amlogic_bs_tag, ao_bsh, 0) << 20; |
310 | } | | 302 | } |
311 | | | 303 | |
312 | /* | | 304 | /* |
313 | * u_int initarm(...) | | 305 | * u_int initarm(...) |
314 | * | | 306 | * |
315 | * Initial entry point on startup. This gets called before main() is | | 307 | * Initial entry point on startup. This gets called before main() is |
316 | * entered. | | 308 | * entered. |
317 | * It should be responsible for setting up everything that must be | | 309 | * It should be responsible for setting up everything that must be |
318 | * in place when main is called. | | 310 | * in place when main is called. |
319 | * This includes | | 311 | * This includes |
320 | * Taking a copy of the boot configuration structure. | | 312 | * Taking a copy of the boot configuration structure. |
321 | * Initialising the physical console so characters can be printed. | | 313 | * Initialising the physical console so characters can be printed. |
322 | * Setting up page tables for the kernel | | 314 | * Setting up page tables for the kernel |
323 | * Relocating the kernel to the bottom of physical memory | | 315 | * Relocating the kernel to the bottom of physical memory |
324 | */ | | 316 | */ |
325 | u_int | | 317 | u_int |
326 | initarm(void *arg) | | 318 | initarm(void *arg) |
327 | { | | 319 | { |
328 | psize_t ram_size = 0; | | 320 | psize_t ram_size = 0; |
329 | *(volatile int *)CONSADDR_VA = 0x40; /* output '@' */ | | 321 | DPRINT("initarm:"); |
330 | | | 322 | |
331 | amlogic_putchar('d'); | | 323 | DPRINT(" devmap"); |
332 | pmap_devmap_register(devmap); | | 324 | pmap_devmap_register(devmap); |
333 | | | 325 | |
334 | amlogic_putchar('b'); | | 326 | DPRINT(" bootstrap"); |
335 | amlogic_bootstrap(); | | 327 | amlogic_bootstrap(); |
336 | | | 328 | |
337 | amlogic_putchar('!'); | | | |
338 | | | | |
339 | #ifdef MULTIPROCESSOR | | 329 | #ifdef MULTIPROCESSOR |
| | | 330 | DPRINT(" ncpu"); |
340 | const bus_addr_t cbar = armreg_cbar_read(); | | 331 | const bus_addr_t cbar = armreg_cbar_read(); |
341 | if (cbar) { | | 332 | if (cbar) { |
342 | const bus_space_handle_t scu_bsh = | | 333 | const bus_space_handle_t scu_bsh = |
343 | cbar - AMLOGIC_CORE_BASE + AMLOGIC_CORE_VBASE; | | 334 | cbar - AMLOGIC_CORE_BASE + AMLOGIC_CORE_VBASE; |
344 | uint32_t scu_cfg = bus_space_read_4(&amlogic_bs_tag, scu_bsh, | | 335 | uint32_t scu_cfg = bus_space_read_4(&amlogic_bs_tag, scu_bsh, |
345 | SCU_CFG); | | 336 | SCU_CFG); |
346 | arm_cpu_max = (scu_cfg & SCU_CFG_CPUMAX) + 1; | | 337 | arm_cpu_max = (scu_cfg & SCU_CFG_CPUMAX) + 1; |
347 | membar_producer(); | | 338 | membar_producer(); |
348 | } | | 339 | } |
349 | #endif | | 340 | #endif |
350 | | | 341 | |
351 | /* Heads up ... Setup the CPU / MMU / TLB functions. */ | | 342 | /* Heads up ... Setup the CPU / MMU / TLB functions. */ |
| | | 343 | DPRINT(" cpufunc"); |
352 | if (set_cpufuncs()) | | 344 | if (set_cpufuncs()) |
353 | panic("cpu not recognized!"); | | 345 | panic("cpu not recognized!"); |
354 | | | 346 | |
355 | init_clocks(); | | 347 | DPRINT(" consinit"); |
356 | | | | |
357 | consinit(); | | 348 | consinit(); |
358 | | | 349 | |
359 | #if NARML2CC > 0 | | 350 | #if NARML2CC > 0 |
360 | /* | | 351 | /* |
361 | * Probe the PL310 L2CC | | 352 | * Probe the PL310 L2CC |
362 | */ | | 353 | */ |
363 | printf("probe the PL310 L2CC\n"); | | 354 | DPRINTF(" l2cc"); |
364 | const bus_space_handle_t pl310_bh = | | 355 | const bus_space_handle_t pl310_bh = |
365 | AMLOGIC_CORE_VBASE + AMLOGIC_PL310_OFFSET; | | 356 | AMLOGIC_CORE_VBASE + AMLOGIC_PL310_OFFSET; |
366 | arml2cc_init(&amlogic_bs_tag, pl310_bh, 0); | | 357 | arml2cc_init(&amlogic_bs_tag, pl310_bh, 0); |
367 | amlogic_putchar('l'); | | | |
368 | #endif | | 358 | #endif |
369 | | | 359 | |
370 | printf("\nuboot arg = %#x, %#x, %#x, %#x\n", | | 360 | DPRINTF(" cbar=%#x", armreg_cbar_read()); |
371 | uboot_args[0], uboot_args[1], uboot_args[2], uboot_args[3]); | | | |
372 | | | 361 | |
373 | #ifdef KGDB | | 362 | DPRINTF(" ok\n"); |
374 | kgdb_port_init(); | | 363 | |
375 | #endif | | 364 | DPRINTF("uboot: args %#x, %#x, %#x, %#x\n", |
| | | 365 | uboot_args[0], uboot_args[1], uboot_args[2], uboot_args[3]); |
376 | | | 366 | |
377 | cpu_reset_address = amlogic_reset; | | 367 | cpu_reset_address = amlogic_reset; |
378 | | | 368 | |
379 | #ifdef VERBOSE_INIT_ARM | | | |
380 | /* Talk to the user */ | | 369 | /* Talk to the user */ |
381 | printf("\nNetBSD/evbarm (amlogic) booting ...\n"); | | 370 | DPRINTF("\nNetBSD/evbarm (amlogic) booting ...\n"); |
382 | #endif | | | |
383 | | | 371 | |
384 | #ifdef BOOT_ARGS | | 372 | #ifdef BOOT_ARGS |
385 | char mi_bootargs[] = BOOT_ARGS; | | 373 | char mi_bootargs[] = BOOT_ARGS; |
386 | parse_mi_bootargs(mi_bootargs); | | 374 | parse_mi_bootargs(mi_bootargs); |
387 | #endif | | 375 | #endif |
388 | | | 376 | |
389 | #ifdef VERBOSE_INIT_ARM | | 377 | DPRINTF("KERNEL_BASE=0x%x, KERNEL_VM_BASE=0x%x, KERNEL_VM_BASE - KERNEL_BASE=0x%x, KERNEL_BASE_VOFFSET=0x%x\n", |
390 | printf("initarm: Configuring system ...\n"); | | | |
391 | | | | |
392 | printf("initarm: cbar=%#x\n", armreg_cbar_read()); | | | |
393 | printf("KERNEL_BASE=0x%x, KERNEL_VM_BASE=0x%x, KERNEL_VM_BASE - KERNEL_BASE=0x%x, KERNEL_BASE_VOFFSET=0x%x\n", | | | |
394 | KERNEL_BASE, KERNEL_VM_BASE, KERNEL_VM_BASE - KERNEL_BASE, KERNEL_BASE_VOFFSET); | | 378 | KERNEL_BASE, KERNEL_VM_BASE, KERNEL_VM_BASE - KERNEL_BASE, KERNEL_BASE_VOFFSET); |
395 | #endif | | | |
396 | | | 379 | |
397 | ram_size = amlogic_get_ram_size(); | | 380 | ram_size = amlogic_get_ram_size(); |
398 | | | 381 | |
399 | #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS | | 382 | #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS |
400 | if (ram_size > KERNEL_VM_BASE - KERNEL_BASE) { | | 383 | if (ram_size > KERNEL_VM_BASE - KERNEL_BASE) { |
401 | printf("%s: dropping RAM size from %luMB to %uMB\n", | | 384 | printf("%s: dropping RAM size from %luMB to %uMB\n", |
402 | __func__, (unsigned long) (ram_size >> 20), | | 385 | __func__, (unsigned long) (ram_size >> 20), |
403 | (KERNEL_VM_BASE - KERNEL_BASE) >> 20); | | 386 | (KERNEL_VM_BASE - KERNEL_BASE) >> 20); |
404 | ram_size = KERNEL_VM_BASE - KERNEL_BASE; | | 387 | ram_size = KERNEL_VM_BASE - KERNEL_BASE; |
405 | } | | 388 | } |
406 | #endif | | 389 | #endif |
407 | | | 390 | |
408 | /* | | 391 | /* |
409 | * If MEMSIZE specified less than what we really have, limit ourselves | | 392 | * If MEMSIZE specified less than what we really have, limit ourselves |
410 | * to that. | | 393 | * to that. |
411 | */ | | 394 | */ |
412 | #ifdef MEMSIZE | | 395 | #ifdef MEMSIZE |
413 | if (ram_size == 0 || ram_size > (unsigned)MEMSIZE * 1024 * 1024) | | 396 | if (ram_size == 0 || ram_size > (unsigned)MEMSIZE * 1024 * 1024) |
414 | ram_size = (unsigned)MEMSIZE * 1024 * 1024; | | 397 | ram_size = (unsigned)MEMSIZE * 1024 * 1024; |
415 | printf("ram_size = 0x%x\n", (int)ram_size); | | 398 | DPRINTF("ram_size = 0x%x\n", (int)ram_size); |
416 | #else | | 399 | #else |
417 | KASSERTMSG(ram_size > 0, "RAM size unknown and MEMSIZE undefined"); | | 400 | KASSERTMSG(ram_size > 0, "RAM size unknown and MEMSIZE undefined"); |
418 | #endif | | 401 | #endif |
419 | | | 402 | |
420 | /* Fake bootconfig structure for the benefit of pmap.c. */ | | 403 | /* Fake bootconfig structure for the benefit of pmap.c. */ |
421 | bootconfig.dramblocks = 1; | | 404 | bootconfig.dramblocks = 1; |
422 | bootconfig.dram[0].address = 0x00000000; /* DDR PHY addr */ | | 405 | bootconfig.dram[0].address = 0x00000000; /* DDR PHY addr */ |
423 | bootconfig.dram[0].pages = ram_size / PAGE_SIZE; | | 406 | bootconfig.dram[0].pages = ram_size / PAGE_SIZE; |
424 | | | 407 | |
425 | #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS | | 408 | #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS |
426 | const bool mapallmem_p = true; | | 409 | const bool mapallmem_p = true; |
427 | KASSERT(ram_size <= KERNEL_VM_BASE - KERNEL_BASE); | | 410 | KASSERT(ram_size <= KERNEL_VM_BASE - KERNEL_BASE); |
428 | #else | | 411 | #else |
429 | const bool mapallmem_p = false; | | 412 | const bool mapallmem_p = false; |
430 | #endif | | 413 | #endif |
431 | KASSERT((armreg_pfr1_read() & ARM_PFR1_SEC_MASK) != 0); | | 414 | KASSERT((armreg_pfr1_read() & ARM_PFR1_SEC_MASK) != 0); |
432 | | | 415 | |
433 | arm32_bootmem_init(bootconfig.dram[0].address, ram_size, | | 416 | arm32_bootmem_init(bootconfig.dram[0].address, ram_size, |
434 | KERNEL_BASE_PHYS); | | 417 | KERNEL_BASE_PHYS); |
435 | arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0, devmap, | | 418 | arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0, devmap, |
436 | mapallmem_p); | | 419 | mapallmem_p); |
437 | | | 420 | |
438 | printf("bootargs: %s\n", bootargs); | | 421 | if (mapallmem_p) { |
| | | 422 | if (uboot_args[3] < ram_size) { |
| | | 423 | const char * const args = (const char *) |
| | | 424 | (uboot_args[3] + KERNEL_BASE_VOFFSET); |
| | | 425 | strlcpy(bootargs, args, sizeof(bootargs)); |
| | | 426 | } |
| | | 427 | } |
| | | 428 | |
| | | 429 | DPRINTF("bootargs: %s\n", bootargs); |
439 | | | 430 | |
440 | boot_args = bootargs; | | 431 | boot_args = bootargs; |
441 | parse_mi_bootargs(boot_args); | | 432 | parse_mi_bootargs(boot_args); |
442 | | | 433 | |
443 | /* we've a specific device_register routine */ | | 434 | /* we've a specific device_register routine */ |
444 | evbarm_device_register = amlogic_device_register; | | 435 | evbarm_device_register = amlogic_device_register; |
445 | | | 436 | |
446 | db_trap_callback = amlogic_db_trap; | | 437 | db_trap_callback = amlogic_db_trap; |
447 | | | 438 | |
448 | return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0); | | 439 | return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0); |
449 | | | 440 | |
450 | } | | 441 | } |
451 | | | 442 | |
452 | static void | | | |
453 | init_clocks(void) | | | |
454 | { | | | |
455 | /* NOT YET */ | | | |
456 | } | | | |
457 | | | | |
458 | #if NAMLOGIC_COM > 0 | | 443 | #if NAMLOGIC_COM > 0 |
459 | #ifndef CONSADDR | | 444 | #ifndef CONSADDR |
460 | #error Specify the address of the console UART with the CONSADDR option. | | 445 | #error Specify the address of the console UART with the CONSADDR option. |
461 | #endif | | 446 | #endif |
462 | #ifndef CONSPEED | | 447 | #ifndef CONSPEED |
463 | #define CONSPEED 115200 | | 448 | #define CONSPEED 115200 |
464 | #endif | | 449 | #endif |
465 | #ifndef CONMODE | | 450 | #ifndef CONMODE |
466 | #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ | | 451 | #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ |
467 | #endif | | 452 | #endif |
468 | | | 453 | |
469 | static const bus_addr_t consaddr = CONSADDR; | | 454 | static const bus_addr_t consaddr = CONSADDR; |
470 | static const int conspeed = CONSPEED; | | 455 | static const int conspeed = CONSPEED; |
471 | static const int conmode = CONMODE; | | 456 | static const int conmode = CONMODE; |
472 | #endif | | 457 | #endif |
473 | | | 458 | |
474 | void | | 459 | void |
475 | consinit(void) | | 460 | consinit(void) |
476 | { | | 461 | { |
477 | static int consinit_called = 0; | | 462 | static int consinit_called = 0; |
478 | | | 463 | |
479 | if (consinit_called != 0) | | 464 | if (consinit_called != 0) |
480 | return; | | 465 | return; |
481 | | | 466 | |
482 | consinit_called = 1; | | 467 | consinit_called = 1; |
483 | | | 468 | |
484 | amlogic_putchar('e'); | | | |
485 | | | | |
486 | #if NAMLOGIC_COM > 0 | | 469 | #if NAMLOGIC_COM > 0 |
487 | const bus_space_handle_t bsh = | | 470 | const bus_space_handle_t bsh = |
488 | AMLOGIC_CORE_VBASE + (consaddr - AMLOGIC_CORE_BASE); | | 471 | AMLOGIC_CORE_VBASE + (consaddr - AMLOGIC_CORE_BASE); |
489 | amlogic_com_cnattach(&amlogic_bs_tag, bsh, conspeed, conmode); | | 472 | amlogic_com_cnattach(&amlogic_bs_tag, bsh, conspeed, conmode); |
490 | #endif | | 473 | #endif |
491 | | | 474 | |
492 | #if NUKBD > 0 | | 475 | #if NUKBD > 0 |
493 | ukbd_cnattach(); /* allow USB keyboard to become console */ | | 476 | ukbd_cnattach(); /* allow USB keyboard to become console */ |
494 | #endif | | 477 | #endif |
495 | | | | |
496 | amlogic_putchar('f'); | | | |
497 | amlogic_putchar('g'); | | | |
498 | } | | 478 | } |
499 | | | 479 | |
500 | void | | 480 | void |
501 | amlogic_reset(void) | | 481 | amlogic_reset(void) |
502 | { | | 482 | { |
503 | bus_space_tag_t bst = &amlogic_bs_tag; | | 483 | bus_space_tag_t bst = &amlogic_bs_tag; |
504 | bus_space_handle_t bsh = amlogic_core_bsh; | | 484 | bus_space_handle_t bsh = amlogic_core_bsh; |
505 | bus_size_t off = AMLOGIC_CBUS_OFFSET; | | 485 | bus_size_t off = AMLOGIC_CBUS_OFFSET; |
506 | | | 486 | |
507 | bus_space_write_4(bst, bsh, off + WATCHDOG_TC_REG, | | 487 | bus_space_write_4(bst, bsh, off + WATCHDOG_TC_REG, |
508 | WATCHDOG_TC_CPUS | WATCHDOG_TC_ENABLE | 1); | | 488 | WATCHDOG_TC_CPUS | WATCHDOG_TC_ENABLE | 1); |
509 | bus_space_write_4(bst, bsh, off + WATCHDOG_RESET_REG, 0); | | 489 | bus_space_write_4(bst, bsh, off + WATCHDOG_RESET_REG, 0); |
510 | | | 490 | |
511 | for (;;) { | | 491 | for (;;) { |
512 | __asm("wfi"); | | 492 | __asm("wfi"); |
513 | } | | 493 | } |
514 | } | | 494 | } |
515 | | | 495 | |
516 | #ifdef KGDB | | | |
517 | #ifndef KGDB_DEVADDR | | | |
518 | #error Specify the address of the kgdb UART with the KGDB_DEVADDR option. | | | |
519 | #endif | | | |
520 | #ifndef KGDB_DEVRATE | | | |
521 | #define KGDB_DEVRATE 115200 | | | |
522 | #endif | | | |
523 | | | | |
524 | #ifndef KGDB_DEVMODE | | | |
525 | #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ | | | |
526 | #endif | | | |
527 | static const vaddr_t comkgdbaddr = KGDB_DEVADDR; | | | |
528 | static const int comkgdbspeed = KGDB_DEVRATE; | | | |
529 | static const int comkgdbmode = KGDB_DEVMODE; | | | |
530 | | | | |
531 | void | | | |
532 | static kgdb_port_init(void) | | | |
533 | { | | | |
534 | static int kgdbsinit_called = 0; | | | |
535 | | | | |
536 | if (kgdbsinit_called != 0) | | | |
537 | return; | | | |
538 | | | | |
539 | kgdbsinit_called = 1; | | | |
540 | | | | |
541 | bus_space_handle_t bh; | | | |
542 | if (bus_space_map(&amlogic_a4x_bs_tag, comkgdbaddr, ROCKCHIP_COM_SIZE, 0, &bh)) | | | |
543 | panic("kgdb port can not be mapped."); | | | |
544 | | | | |
545 | if (com_kgdb_attach(&amlogic_a4x_bs_tag, comkgdbaddr, comkgdbspeed, | | | |
546 | ROCKCHIP_COM_FREQ, COM_TYPE_NORMAL, comkgdbmode)) | | | |
547 | panic("KGDB uart can not be initialized."); | | | |
548 | | | | |
549 | bus_space_unmap(&amlogic_a4x_bs_tag, bh, ROCKCHIP_COM_SIZE); | | | |
550 | } | | | |
551 | #endif | | | |
552 | | | | |
553 | void | | 496 | void |
554 | amlogic_device_register(device_t self, void *aux) | | 497 | amlogic_device_register(device_t self, void *aux) |
555 | { | | 498 | { |
556 | prop_dictionary_t dict = device_properties(self); | | 499 | prop_dictionary_t dict = device_properties(self); |
557 | | | 500 | |
558 | if (device_is_a(self, "armperiph") | | 501 | if (device_is_a(self, "armperiph") |
559 | && device_is_a(device_parent(self), "mainbus")) { | | 502 | && device_is_a(device_parent(self), "mainbus")) { |
560 | struct mainbus_attach_args * const mb = aux; | | 503 | struct mainbus_attach_args * const mb = aux; |
561 | mb->mb_iot = &amlogic_bs_tag; | | 504 | mb->mb_iot = &amlogic_bs_tag; |
562 | return; | | 505 | return; |
563 | } | | 506 | } |
564 | | | 507 | |
565 | /* | | 508 | /* |