Tue Mar 3 23:20:04 2015 UTC ()
fix build without VERBOSE_INIT_ARM


(jmcneill)
diff -r1.11 -r1.12 src/sys/arch/evbarm/amlogic/amlogic_machdep.c

cvs diff -r1.11 -r1.12 src/sys/arch/evbarm/amlogic/Attic/amlogic_machdep.c (switch to unified diff)

--- src/sys/arch/evbarm/amlogic/Attic/amlogic_machdep.c 2015/03/03 23:14:41 1.11
+++ src/sys/arch/evbarm/amlogic/Attic/amlogic_machdep.c 2015/03/03 23:20:04 1.12
@@ -1,644 +1,637 @@ @@ -1,644 +1,637 @@
1/* $NetBSD: amlogic_machdep.c,v 1.11 2015/03/03 23:14:41 jmcneill Exp $ */ 1/* $NetBSD: amlogic_machdep.c,v 1.12 2015/03/03 23:20:04 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.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of Genetec Corporation may not be used to endorse or 18 * 3. The name of Genetec Corporation may not be used to endorse or
19 * promote products derived from this software without specific prior 19 * promote products derived from this software without specific prior
20 * written permission. 20 * written permission.
21 * 21 *
22 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND 22 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION 25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE. 32 * POSSIBILITY OF SUCH DAMAGE.
33 * 33 *
34 * Copyright (c) 2001 Wasabi Systems, Inc. 34 * Copyright (c) 2001 Wasabi Systems, Inc.
35 * All rights reserved. 35 * All rights reserved.
36 * 36 *
37 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 37 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
38 * 38 *
39 * Redistribution and use in source and binary forms, with or without 39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions 40 * modification, are permitted provided that the following conditions
41 * are met: 41 * are met:
42 * 1. Redistributions of source code must retain the above copyright 42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer. 43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright 44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the 45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution. 46 * documentation and/or other materials provided with the distribution.
47 * 3. All advertising materials mentioning features or use of this software 47 * 3. All advertising materials mentioning features or use of this software
48 * must display the following acknowledgement: 48 * must display the following acknowledgement:
49 * This product includes software developed for the NetBSD Project by 49 * This product includes software developed for the NetBSD Project by
50 * Wasabi Systems, Inc. 50 * Wasabi Systems, Inc.
51 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 51 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
52 * or promote products derived from this software without specific prior 52 * or promote products derived from this software without specific prior
53 * written permission. 53 * written permission.
54 * 54 *
55 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 55 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
57 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 57 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 58 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
59 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 59 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
60 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 60 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
61 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 61 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
62 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 62 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
63 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 63 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
64 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 64 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
65 * POSSIBILITY OF SUCH DAMAGE. 65 * POSSIBILITY OF SUCH DAMAGE.
66 * 66 *
67 * Copyright (c) 1997,1998 Mark Brinicombe. 67 * Copyright (c) 1997,1998 Mark Brinicombe.
68 * Copyright (c) 1997,1998 Causality Limited. 68 * Copyright (c) 1997,1998 Causality Limited.
69 * All rights reserved. 69 * All rights reserved.
70 * 70 *
71 * Redistribution and use in source and binary forms, with or without 71 * Redistribution and use in source and binary forms, with or without
72 * modification, are permitted provided that the following conditions 72 * modification, are permitted provided that the following conditions
73 * are met: 73 * are met:
74 * 1. Redistributions of source code must retain the above copyright 74 * 1. Redistributions of source code must retain the above copyright
75 * notice, this list of conditions and the following disclaimer. 75 * notice, this list of conditions and the following disclaimer.
76 * 2. Redistributions in binary form must reproduce the above copyright 76 * 2. Redistributions in binary form must reproduce the above copyright
77 * notice, this list of conditions and the following disclaimer in the 77 * notice, this list of conditions and the following disclaimer in the
78 * documentation and/or other materials provided with the distribution. 78 * documentation and/or other materials provided with the distribution.
79 * 3. All advertising materials mentioning features or use of this software 79 * 3. All advertising materials mentioning features or use of this software
80 * must display the following acknowledgement: 80 * must display the following acknowledgement:
81 * This product includes software developed by Mark Brinicombe 81 * This product includes software developed by Mark Brinicombe
82 * for the NetBSD Project. 82 * for the NetBSD Project.
83 * 4. The name of the company nor the name of the author may be used to 83 * 4. The name of the company nor the name of the author may be used to
84 * endorse or promote products derived from this software without specific 84 * endorse or promote products derived from this software without specific
85 * prior written permission. 85 * prior written permission.
86 * 86 *
87 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 87 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
88 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 88 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
89 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 89 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
90 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 90 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
91 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 91 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
92 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 92 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
93 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 93 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
94 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 94 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
95 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 95 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
96 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 96 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
97 * SUCH DAMAGE. 97 * SUCH DAMAGE.
98 * 98 *
99 * Copyright (c) 2007 Microsoft 99 * Copyright (c) 2007 Microsoft
100 * All rights reserved. 100 * All rights reserved.
101 * 101 *
102 * Redistribution and use in source and binary forms, with or without 102 * Redistribution and use in source and binary forms, with or without
103 * modification, are permitted provided that the following conditions 103 * modification, are permitted provided that the following conditions
104 * are met: 104 * are met:
105 * 1. Redistributions of source code must retain the above copyright 105 * 1. Redistributions of source code must retain the above copyright
106 * notice, this list of conditions and the following disclaimer. 106 * notice, this list of conditions and the following disclaimer.
107 * 2. Redistributions in binary form must reproduce the above copyright 107 * 2. Redistributions in binary form must reproduce the above copyright
108 * notice, this list of conditions and the following disclaimer in the 108 * notice, this list of conditions and the following disclaimer in the
109 * documentation and/or other materials provided with the distribution. 109 * documentation and/or other materials provided with the distribution.
110 * 3. All advertising materials mentioning features or use of this software 110 * 3. All advertising materials mentioning features or use of this software
111 * must display the following acknowledgement: 111 * must display the following acknowledgement:
112 * This product includes software developed by Microsoft 112 * This product includes software developed by Microsoft
113 * 113 *
114 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 114 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
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.11 2015/03/03 23:14:41 jmcneill Exp $"); 128__KERNEL_RCSID(0, "$NetBSD: amlogic_machdep.c,v 1.12 2015/03/03 23:20:04 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_md.h" 132#include "opt_md.h"
133#include "opt_amlogic.h" 133#include "opt_amlogic.h"
134#include "opt_arm_debug.h" 134#include "opt_arm_debug.h"
135#include "opt_multiprocessor.h" 135#include "opt_multiprocessor.h"
136 136
137#include "amlogic_com.h" 137#include "amlogic_com.h"
138#include "arml2cc.h" 138#include "arml2cc.h"
139#include "ether.h" 139#include "ether.h"
140 140
141#include <sys/param.h> 141#include <sys/param.h>
142#include <sys/systm.h> 142#include <sys/systm.h>
143#include <sys/bus.h> 143#include <sys/bus.h>
144#include <sys/atomic.h> 144#include <sys/atomic.h>
145#include <sys/cpu.h> 145#include <sys/cpu.h>
146#include <sys/device.h> 146#include <sys/device.h>
147#include <sys/exec.h> 147#include <sys/exec.h>
148#include <sys/kernel.h> 148#include <sys/kernel.h>
149#include <sys/ksyms.h> 149#include <sys/ksyms.h>
150#include <sys/msgbuf.h> 150#include <sys/msgbuf.h>
151#include <sys/proc.h> 151#include <sys/proc.h>
152#include <sys/reboot.h> 152#include <sys/reboot.h>
153#include <sys/termios.h> 153#include <sys/termios.h>
154#include <sys/gpio.h> 154#include <sys/gpio.h>
155 155
156#include <uvm/uvm_extern.h> 156#include <uvm/uvm_extern.h>
157 157
158#include <sys/conf.h> 158#include <sys/conf.h>
159#include <dev/cons.h> 159#include <dev/cons.h>
160#include <dev/md.h> 160#include <dev/md.h>
161 161
162#include <machine/db_machdep.h> 162#include <machine/db_machdep.h>
163#include <ddb/db_sym.h> 163#include <ddb/db_sym.h>
164#include <ddb/db_extern.h> 164#include <ddb/db_extern.h>
165 165
166#include <machine/bootconfig.h> 166#include <machine/bootconfig.h>
167#include <arm/armreg.h> 167#include <arm/armreg.h>
168#include <arm/undefined.h> 168#include <arm/undefined.h>
169 169
170#include <arm/arm32/machdep.h> 170#include <arm/arm32/machdep.h>
171#include <arm/mainbus/mainbus.h> 171#include <arm/mainbus/mainbus.h>
172 172
173#include <arm/amlogic/amlogic_reg.h> 173#include <arm/amlogic/amlogic_reg.h>
174#include <arm/amlogic/amlogic_crureg.h> 174#include <arm/amlogic/amlogic_crureg.h>
175#include <arm/amlogic/amlogic_var.h> 175#include <arm/amlogic/amlogic_var.h>
176#include <arm/amlogic/amlogic_comreg.h> 176#include <arm/amlogic/amlogic_comreg.h>
177#include <arm/amlogic/amlogic_comvar.h> 177#include <arm/amlogic/amlogic_comvar.h>
178 178
179#include <arm/cortex/pl310_reg.h> 179#include <arm/cortex/pl310_reg.h>
180#include <arm/cortex/scu_reg.h> 180#include <arm/cortex/scu_reg.h>
181 181
182#include <arm/cortex/a9tmr_var.h> 182#include <arm/cortex/a9tmr_var.h>
183#include <arm/cortex/pl310_var.h> 183#include <arm/cortex/pl310_var.h>
184 184
185#include <arm/cortex/gtmr_var.h> 185#include <arm/cortex/gtmr_var.h>
186 186
187#include <evbarm/include/autoconf.h> 187#include <evbarm/include/autoconf.h>
188#include <evbarm/amlogic/platform.h> 188#include <evbarm/amlogic/platform.h>
189 189
190#include <dev/usb/ukbdvar.h> 190#include <dev/usb/ukbdvar.h>
191#include <net/if_ether.h> 191#include <net/if_ether.h>
192 192
193#ifndef AMLOGIC_MAX_BOOT_STRING 193#ifndef AMLOGIC_MAX_BOOT_STRING
194#define AMLOGIC_MAX_BOOT_STRING 1024 194#define AMLOGIC_MAX_BOOT_STRING 1024
195#endif 195#endif
196 196
197BootConfig bootconfig; /* Boot config storage */ 197BootConfig bootconfig; /* Boot config storage */
198static char bootargs[AMLOGIC_MAX_BOOT_STRING]; 198static char bootargs[AMLOGIC_MAX_BOOT_STRING];
199char *boot_args = NULL; 199char *boot_args = NULL;
200char *boot_file = NULL; 200char *boot_file = NULL;
201u_int uboot_args[4] = { 0 }; /* filled in by amlogic_start.S (not in bss) */ 201u_int uboot_args[4] = { 0 }; /* filled in by amlogic_start.S (not in bss) */
202 202
203/* Same things, but for the free (unused by the kernel) memory. */ 203/* Same things, but for the free (unused by the kernel) memory. */
204 204
205extern char KERNEL_BASE_phys[]; 205extern char KERNEL_BASE_phys[];
206extern char _end[]; 206extern char _end[];
207 207
208/* 208/*
209 * 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
210 * kernel address space. *Not* for general use. 210 * kernel address space. *Not* for general use.
211 */ 211 */
212#define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys) 212#define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys)
213#define AMLOGIC_CORE_VOFFSET (AMLOGIC_CORE_VBASE - AMLOGIC_CORE_BASE) 213#define AMLOGIC_CORE_VOFFSET (AMLOGIC_CORE_VBASE - AMLOGIC_CORE_BASE)
214/* Prototypes */ 214/* Prototypes */
215 215
216void consinit(void); 216void consinit(void);
217 217
218static void amlogic_device_register(device_t, void *); 218static void amlogic_device_register(device_t, void *);
219static void amlogic_reset(void); 219static void amlogic_reset(void);
220 220
221bs_protos(bs_notimpl); 221bs_protos(bs_notimpl);
222 222
223/* 223/*
224 * Static device mappings. These peripheral registers are mapped at 224 * Static device mappings. These peripheral registers are mapped at
225 * 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
226 * them while booting the kernel, and stay at the same address 226 * them while booting the kernel, and stay at the same address
227 * throughout whole kernel's life time. 227 * throughout whole kernel's life time.
228 * 228 *
229 * 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
230 * with kernel's page table which we build up in initarm(). 230 * with kernel's page table which we build up in initarm().
231 * 231 *
232 * Since we map these registers into the bootstrap page table using 232 * Since we map these registers into the bootstrap page table using
233 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map 233 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
234 * registers segment-aligned and segment-rounded in order to avoid 234 * registers segment-aligned and segment-rounded in order to avoid
235 * using the 2nd page tables. 235 * using the 2nd page tables.
236 */ 236 */
237 237
238#define _A(a) ((a) & ~L1_S_OFFSET) 238#define _A(a) ((a) & ~L1_S_OFFSET)
239#define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1)) 239#define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
240 240
241static const struct pmap_devmap devmap[] = { 241static const struct pmap_devmap devmap[] = {
242 { 242 {
243 .pd_va = _A(AMLOGIC_CORE_VBASE), 243 .pd_va = _A(AMLOGIC_CORE_VBASE),
244 .pd_pa = _A(AMLOGIC_CORE_BASE), 244 .pd_pa = _A(AMLOGIC_CORE_BASE),
245 .pd_size = _S(AMLOGIC_CORE_SIZE), 245 .pd_size = _S(AMLOGIC_CORE_SIZE),
246 .pd_prot = VM_PROT_READ|VM_PROT_WRITE, 246 .pd_prot = VM_PROT_READ|VM_PROT_WRITE,
247 .pd_cache = PTE_NOCACHE 247 .pd_cache = PTE_NOCACHE
248 }, 248 },
249 {0} 249 {0}
250}; 250};
251 251
252#undef _A 252#undef _A
253#undef _S 253#undef _S
254 254
255#ifdef DDB 255#ifdef DDB
256static void 256static void
257amlogic_db_trap(int where) 257amlogic_db_trap(int where)
258{ 258{
259 /* NOT YET */ 259 /* NOT YET */
260} 260}
261#endif 261#endif
262 262
263#ifdef VERBOSE_INIT_ARM 263#ifdef VERBOSE_INIT_ARM
264static void 264static void
265amlogic_putchar(char c) 265amlogic_putchar(char c)
266{ 266{
267 volatile uint32_t *uartaddr = (volatile uint32_t *)CONSADDR_VA; 267 volatile uint32_t *uartaddr = (volatile uint32_t *)CONSADDR_VA;
268 int timo = 150000; 268 int timo = 150000;
269 269
270 while ((uartaddr[UART_STATUS_REG/4] & UART_STATUS_TX_EMPTY) == 0) { 270 while ((uartaddr[UART_STATUS_REG/4] & UART_STATUS_TX_EMPTY) == 0) {
271 if (--timo == 0) 271 if (--timo == 0)
272 break; 272 break;
273 } 273 }
274 274
275 uartaddr[UART_WFIFO_REG/4] = c; 275 uartaddr[UART_WFIFO_REG/4] = c;
276 276
277 while ((uartaddr[UART_STATUS_REG/4] & UART_STATUS_TX_EMPTY) == 0) { 277 while ((uartaddr[UART_STATUS_REG/4] & UART_STATUS_TX_EMPTY) == 0) {
278 if (--timo == 0) 278 if (--timo == 0)
279 break; 279 break;
280 } 280 }
281} 281}
282static void 282static void
283amlogic_putstr(const char *s) 283amlogic_putstr(const char *s)
284{ 284{
285 for (const char *p = s; *p; p++) { 285 for (const char *p = s; *p; p++) {
286 amlogic_putchar(*p); 286 amlogic_putchar(*p);
287 } 287 }
288} 288}
289#define DPRINTF(...) printf(__VA_ARGS__) 289#define DPRINTF(...) printf(__VA_ARGS__)
290#define DPRINT(x) amlogic_putstr(x) 290#define DPRINT(x) amlogic_putstr(x)
291#else 291#else
292#define DPRINTF(...) 292#define DPRINTF(...)
293#define DPRINT(x) 293#define DPRINT(x)
294#endif 294#endif
295 295
296static psize_t 296static psize_t
297amlogic_get_ram_size(void) 297amlogic_get_ram_size(void)
298{ 298{
299 const bus_space_handle_t ao_bsh = 299 const bus_space_handle_t ao_bsh =
300 AMLOGIC_CORE_VBASE + AMLOGIC_SRAM_OFFSET; 300 AMLOGIC_CORE_VBASE + AMLOGIC_SRAM_OFFSET;
301 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;
302} 302}
303 303
304/* 304/*
305 * u_int initarm(...) 305 * u_int initarm(...)
306 * 306 *
307 * Initial entry point on startup. This gets called before main() is 307 * Initial entry point on startup. This gets called before main() is
308 * entered. 308 * entered.
309 * It should be responsible for setting up everything that must be 309 * It should be responsible for setting up everything that must be
310 * in place when main is called. 310 * in place when main is called.
311 * This includes 311 * This includes
312 * Taking a copy of the boot configuration structure. 312 * Taking a copy of the boot configuration structure.
313 * Initialising the physical console so characters can be printed. 313 * Initialising the physical console so characters can be printed.
314 * Setting up page tables for the kernel 314 * Setting up page tables for the kernel
315 * Relocating the kernel to the bottom of physical memory 315 * Relocating the kernel to the bottom of physical memory
316 */ 316 */
317u_int 317u_int
318initarm(void *arg) 318initarm(void *arg)
319{ 319{
320 psize_t ram_size = 0; 320 psize_t ram_size = 0;
321 DPRINT("initarm:"); 321 DPRINT("initarm:");
322 322
323 DPRINT(" devmap"); 323 DPRINT(" devmap");
324 pmap_devmap_register(devmap); 324 pmap_devmap_register(devmap);
325 325
326 DPRINT(" bootstrap"); 326 DPRINT(" bootstrap");
327 amlogic_bootstrap(); 327 amlogic_bootstrap();
328 328
329#ifdef MULTIPROCESSOR 329#ifdef MULTIPROCESSOR
330 DPRINT(" ncpu"); 330 DPRINT(" ncpu");
331 const bus_addr_t cbar = armreg_cbar_read(); 331 const bus_addr_t cbar = armreg_cbar_read();
332 if (cbar) { 332 if (cbar) {
333 const bus_space_handle_t scu_bsh = 333 const bus_space_handle_t scu_bsh =
334 cbar - AMLOGIC_CORE_BASE + AMLOGIC_CORE_VBASE; 334 cbar - AMLOGIC_CORE_BASE + AMLOGIC_CORE_VBASE;
335 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,
336 SCU_CFG); 336 SCU_CFG);
337 arm_cpu_max = (scu_cfg & SCU_CFG_CPUMAX) + 1; 337 arm_cpu_max = (scu_cfg & SCU_CFG_CPUMAX) + 1;
338 membar_producer(); 338 membar_producer();
339 } 339 }
340#endif 340#endif
341 341
342 /* Heads up ... Setup the CPU / MMU / TLB functions. */ 342 /* Heads up ... Setup the CPU / MMU / TLB functions. */
343 DPRINT(" cpufunc"); 343 DPRINT(" cpufunc");
344 if (set_cpufuncs()) 344 if (set_cpufuncs())
345 panic("cpu not recognized!"); 345 panic("cpu not recognized!");
346 346
347 DPRINT(" consinit"); 347 DPRINT(" consinit");
348 consinit(); 348 consinit();
349 349
350#if NARML2CC > 0 350#if NARML2CC > 0
351 /* 351 /*
352 * Probe the PL310 L2CC 352 * Probe the PL310 L2CC
353 */ 353 */
354 DPRINTF(" l2cc"); 354 DPRINTF(" l2cc");
355 const bus_space_handle_t pl310_bh = 355 const bus_space_handle_t pl310_bh =
356 AMLOGIC_CORE_VBASE + AMLOGIC_PL310_OFFSET; 356 AMLOGIC_CORE_VBASE + AMLOGIC_PL310_OFFSET;
357 arml2cc_init(&amlogic_bs_tag, pl310_bh, 0); 357 arml2cc_init(&amlogic_bs_tag, pl310_bh, 0);
358#endif 358#endif
359 359
360 DPRINTF(" cbar=%#x", armreg_cbar_read()); 360 DPRINTF(" cbar=%#x", armreg_cbar_read());
361 361
362 DPRINTF(" ok\n"); 362 DPRINTF(" ok\n");
363 363
364 DPRINTF("uboot: args %#x, %#x, %#x, %#x\n", 364 DPRINTF("uboot: args %#x, %#x, %#x, %#x\n",
365 uboot_args[0], uboot_args[1], uboot_args[2], uboot_args[3]); 365 uboot_args[0], uboot_args[1], uboot_args[2], uboot_args[3]);
366 366
367 cpu_reset_address = amlogic_reset; 367 cpu_reset_address = amlogic_reset;
368 368
369 /* Talk to the user */ 369 /* Talk to the user */
370 DPRINTF("\nNetBSD/evbarm (amlogic) booting ...\n"); 370 DPRINTF("\nNetBSD/evbarm (amlogic) booting ...\n");
371 371
372#ifdef BOOT_ARGS 372#ifdef BOOT_ARGS
373 char mi_bootargs[] = BOOT_ARGS; 373 char mi_bootargs[] = BOOT_ARGS;
374 parse_mi_bootargs(mi_bootargs); 374 parse_mi_bootargs(mi_bootargs);
375#endif 375#endif
376 376
377 DPRINTF("KERNEL_BASE=0x%x, KERNEL_VM_BASE=0x%x, KERNEL_VM_BASE - KERNEL_BASE=0x%x, KERNEL_BASE_VOFFSET=0x%x\n", 377 DPRINTF("KERNEL_BASE=0x%x, KERNEL_VM_BASE=0x%x, KERNEL_VM_BASE - KERNEL_BASE=0x%x, KERNEL_BASE_VOFFSET=0x%x\n",
378 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);
379 379
380 ram_size = amlogic_get_ram_size(); 380 ram_size = amlogic_get_ram_size();
381 381
382#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS 382#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
383 if (ram_size > KERNEL_VM_BASE - KERNEL_BASE) { 383 if (ram_size > KERNEL_VM_BASE - KERNEL_BASE) {
384 printf("%s: dropping RAM size from %luMB to %uMB\n", 384 printf("%s: dropping RAM size from %luMB to %uMB\n",
385 __func__, (unsigned long) (ram_size >> 20),  385 __func__, (unsigned long) (ram_size >> 20),
386 (KERNEL_VM_BASE - KERNEL_BASE) >> 20); 386 (KERNEL_VM_BASE - KERNEL_BASE) >> 20);
387 ram_size = KERNEL_VM_BASE - KERNEL_BASE; 387 ram_size = KERNEL_VM_BASE - KERNEL_BASE;
388 } 388 }
389#endif 389#endif
390 390
391 /* 391 /*
392 * If MEMSIZE specified less than what we really have, limit ourselves 392 * If MEMSIZE specified less than what we really have, limit ourselves
393 * to that. 393 * to that.
394 */ 394 */
395#ifdef MEMSIZE 395#ifdef MEMSIZE
396 if (ram_size == 0 || ram_size > (unsigned)MEMSIZE * 1024 * 1024) 396 if (ram_size == 0 || ram_size > (unsigned)MEMSIZE * 1024 * 1024)
397 ram_size = (unsigned)MEMSIZE * 1024 * 1024; 397 ram_size = (unsigned)MEMSIZE * 1024 * 1024;
398 DPRINTF("ram_size = 0x%x\n", (int)ram_size); 398 DPRINTF("ram_size = 0x%x\n", (int)ram_size);
399#else 399#else
400 KASSERTMSG(ram_size > 0, "RAM size unknown and MEMSIZE undefined"); 400 KASSERTMSG(ram_size > 0, "RAM size unknown and MEMSIZE undefined");
401#endif 401#endif
402 402
403 /* Fake bootconfig structure for the benefit of pmap.c. */ 403 /* Fake bootconfig structure for the benefit of pmap.c. */
404 bootconfig.dramblocks = 1; 404 bootconfig.dramblocks = 1;
405 bootconfig.dram[0].address = 0x00000000; /* DDR PHY addr */ 405 bootconfig.dram[0].address = 0x00000000; /* DDR PHY addr */
406 bootconfig.dram[0].pages = ram_size / PAGE_SIZE; 406 bootconfig.dram[0].pages = ram_size / PAGE_SIZE;
407 407
408#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS 408#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
409 const bool mapallmem_p = true; 409 const bool mapallmem_p = true;
410 KASSERT(ram_size <= KERNEL_VM_BASE - KERNEL_BASE); 410 KASSERT(ram_size <= KERNEL_VM_BASE - KERNEL_BASE);
411#else 411#else
412 const bool mapallmem_p = false; 412 const bool mapallmem_p = false;
413#endif 413#endif
414 KASSERT((armreg_pfr1_read() & ARM_PFR1_SEC_MASK) != 0); 414 KASSERT((armreg_pfr1_read() & ARM_PFR1_SEC_MASK) != 0);
415 415
416 arm32_bootmem_init(bootconfig.dram[0].address, ram_size, 416 arm32_bootmem_init(bootconfig.dram[0].address, ram_size,
417 KERNEL_BASE_PHYS); 417 KERNEL_BASE_PHYS);
418 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,
419 mapallmem_p); 419 mapallmem_p);
420 420
421 if (mapallmem_p) { 421 if (mapallmem_p) {
422 if (uboot_args[3] < ram_size) { 422 if (uboot_args[3] < ram_size) {
423 const char * const args = (const char *) 423 const char * const args = (const char *)
424 (uboot_args[3] + KERNEL_BASE_VOFFSET); 424 (uboot_args[3] + KERNEL_BASE_VOFFSET);
425 strlcpy(bootargs, args, sizeof(bootargs)); 425 strlcpy(bootargs, args, sizeof(bootargs));
426 } 426 }
427 } 427 }
428 428
429 DPRINTF("bootargs: %s\n", bootargs); 429 DPRINTF("bootargs: %s\n", bootargs);
430 430
431 boot_args = bootargs; 431 boot_args = bootargs;
432 parse_mi_bootargs(boot_args); 432 parse_mi_bootargs(boot_args);
433 433
434 /* we've a specific device_register routine */ 434 /* we've a specific device_register routine */
435 evbarm_device_register = amlogic_device_register; 435 evbarm_device_register = amlogic_device_register;
436 436
437 db_trap_callback = amlogic_db_trap; 437 db_trap_callback = amlogic_db_trap;
438 438
439 return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0); 439 return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0);
440 440
441} 441}
442 442
443#if NAMLOGIC_COM > 0 443#if NAMLOGIC_COM > 0
444#ifndef CONSADDR 444#ifndef CONSADDR
445#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.
446#endif 446#endif
447#ifndef CONSPEED 447#ifndef CONSPEED
448#define CONSPEED 115200 448#define CONSPEED 115200
449#endif 449#endif
450#ifndef CONMODE 450#ifndef CONMODE
451#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 451#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
452#endif 452#endif
453 453
454static const bus_addr_t consaddr = CONSADDR; 454static const bus_addr_t consaddr = CONSADDR;
455static const int conspeed = CONSPEED; 455static const int conspeed = CONSPEED;
456static const int conmode = CONMODE; 456static const int conmode = CONMODE;
457#endif 457#endif
458 458
459void 459void
460consinit(void) 460consinit(void)
461{ 461{
462 static int consinit_called = 0; 462 static int consinit_called = 0;
463 463
464 if (consinit_called != 0) 464 if (consinit_called != 0)
465 return; 465 return;
466 466
467 consinit_called = 1; 467 consinit_called = 1;
468 468
469#if NAMLOGIC_COM > 0 469#if NAMLOGIC_COM > 0
470 const bus_space_handle_t bsh = 470 const bus_space_handle_t bsh =
471 AMLOGIC_CORE_VBASE + (consaddr - AMLOGIC_CORE_BASE); 471 AMLOGIC_CORE_VBASE + (consaddr - AMLOGIC_CORE_BASE);
472 amlogic_com_cnattach(&amlogic_bs_tag, bsh, conspeed, conmode); 472 amlogic_com_cnattach(&amlogic_bs_tag, bsh, conspeed, conmode);
473#endif 473#endif
474 474
475#if NUKBD > 0 475#if NUKBD > 0
476 ukbd_cnattach(); /* allow USB keyboard to become console */ 476 ukbd_cnattach(); /* allow USB keyboard to become console */
477#endif 477#endif
478} 478}
479 479
480void 480void
481amlogic_reset(void) 481amlogic_reset(void)
482{ 482{
483 bus_space_tag_t bst = &amlogic_bs_tag; 483 bus_space_tag_t bst = &amlogic_bs_tag;
484 bus_space_handle_t bsh = amlogic_core_bsh; 484 bus_space_handle_t bsh = amlogic_core_bsh;
485 bus_size_t off = AMLOGIC_CBUS_OFFSET; 485 bus_size_t off = AMLOGIC_CBUS_OFFSET;
486 486
487 bus_space_write_4(bst, bsh, off + WATCHDOG_TC_REG, 487 bus_space_write_4(bst, bsh, off + WATCHDOG_TC_REG,
488 WATCHDOG_TC_CPUS | WATCHDOG_TC_ENABLE | 1); 488 WATCHDOG_TC_CPUS | WATCHDOG_TC_ENABLE | 1);
489 bus_space_write_4(bst, bsh, off + WATCHDOG_RESET_REG, 0); 489 bus_space_write_4(bst, bsh, off + WATCHDOG_RESET_REG, 0);
490 490
491 for (;;) { 491 for (;;) {
492 __asm("wfi"); 492 __asm("wfi");
493 } 493 }
494} 494}
495 495
496void 496void
497amlogic_device_register(device_t self, void *aux) 497amlogic_device_register(device_t self, void *aux)
498{ 498{
499 prop_dictionary_t dict = device_properties(self); 499 prop_dictionary_t dict = device_properties(self);
500 500
501 if (device_is_a(self, "armperiph") 501 if (device_is_a(self, "armperiph")
502 && device_is_a(device_parent(self), "mainbus")) { 502 && device_is_a(device_parent(self), "mainbus")) {
503 struct mainbus_attach_args * const mb = aux; 503 struct mainbus_attach_args * const mb = aux;
504 mb->mb_iot = &amlogic_bs_tag; 504 mb->mb_iot = &amlogic_bs_tag;
505 return; 505 return;
506 } 506 }
507 507
508 /* 508 /*
509 * We need to tell the A9 Global/Watchdog Timer 509 * We need to tell the A9 Global/Watchdog Timer
510 * what frequency it runs at. 510 * what frequency it runs at.
511 */ 511 */
512 if (device_is_a(self, "a9tmr") || device_is_a(self, "a9wdt")) { 512 if (device_is_a(self, "a9tmr") || device_is_a(self, "a9wdt")) {
513 prop_dictionary_set_uint32(dict, "frequency", 513 prop_dictionary_set_uint32(dict, "frequency",
514 amlogic_get_rate_a9periph()); 514 amlogic_get_rate_a9periph());
515 515
516 return; 516 return;
517 } 517 }
518 518
519 if (device_is_a(self, "arml2cc")) { 519 if (device_is_a(self, "arml2cc")) {
520 /* 520 /*
521 * L2 cache regs are at C4200000 and A9 periph base is 521 * L2 cache regs are at C4200000 and A9 periph base is
522 * at C4300000; pass as a negative offset for the benefit 522 * at C4300000; pass as a negative offset for the benefit
523 * of armperiph bus. 523 * of armperiph bus.
524 */ 524 */
525 prop_dictionary_set_uint32(dict, "offset", 0xfff00000); 525 prop_dictionary_set_uint32(dict, "offset", 0xfff00000);
526 } 526 }
527} 527}
528 528
529#if defined(MULTIPROCESSOR) 529#if defined(MULTIPROCESSOR)
530void amlogic_mpinit(uint32_t); 530void amlogic_mpinit(uint32_t);
531 531
532static void 532static void
533amlogic_mpinit_delay(u_int n) 533amlogic_mpinit_delay(u_int n)
534{ 534{
535 for (volatile int i = 0; i < n; i++) 535 for (volatile int i = 0; i < n; i++)
536 ; 536 ;
537} 537}
538 538
539static void 539static void
540amlogic_mpinit_cpu(int cpu) 540amlogic_mpinit_cpu(int cpu)
541{ 541{
542 const bus_addr_t cbar = armreg_cbar_read(); 542 const bus_addr_t cbar = armreg_cbar_read();
543 bus_space_tag_t bst = &amlogic_bs_tag; 543 bus_space_tag_t bst = &amlogic_bs_tag;
544 const bus_space_handle_t scu_bsh = 544 const bus_space_handle_t scu_bsh =
545 cbar - AMLOGIC_CORE_BASE + AMLOGIC_CORE_VBASE; 545 cbar - AMLOGIC_CORE_BASE + AMLOGIC_CORE_VBASE;
546 const bus_space_handle_t ao_bsh = 546 const bus_space_handle_t ao_bsh =
547 AMLOGIC_CORE_VBASE + AMLOGIC_AOBUS_OFFSET; 547 AMLOGIC_CORE_VBASE + AMLOGIC_AOBUS_OFFSET;
548 const bus_space_handle_t cbus_bsh = 548 const bus_space_handle_t cbus_bsh =
549 AMLOGIC_CORE_VBASE + AMLOGIC_CBUS_OFFSET; 549 AMLOGIC_CORE_VBASE + AMLOGIC_CBUS_OFFSET;
550 uint32_t pwr_sts, pwr_cntl0, pwr_cntl1, cpuclk, mempd0; 550 uint32_t pwr_sts, pwr_cntl0, pwr_cntl1, cpuclk, mempd0;
551 551
552 pwr_sts = bus_space_read_4(bst, scu_bsh, SCU_CPU_PWR_STS); 552 pwr_sts = bus_space_read_4(bst, scu_bsh, SCU_CPU_PWR_STS);
553 pwr_sts &= ~(3 << (8 * cpu)); 553 pwr_sts &= ~(3 << (8 * cpu));
554 bus_space_write_4(bst, scu_bsh, SCU_CPU_PWR_STS, pwr_sts); 554 bus_space_write_4(bst, scu_bsh, SCU_CPU_PWR_STS, pwr_sts);
555 555
556 pwr_cntl0 = bus_space_read_4(bst, ao_bsh, AMLOGIC_AOBUS_PWR_CTRL0_REG); 556 pwr_cntl0 = bus_space_read_4(bst, ao_bsh, AMLOGIC_AOBUS_PWR_CTRL0_REG);
557 pwr_cntl0 &= ~((3 << 18) << ((cpu - 1) * 2)); 557 pwr_cntl0 &= ~((3 << 18) << ((cpu - 1) * 2));
558 bus_space_write_4(bst, ao_bsh, AMLOGIC_AOBUS_PWR_CTRL0_REG, pwr_cntl0); 558 bus_space_write_4(bst, ao_bsh, AMLOGIC_AOBUS_PWR_CTRL0_REG, pwr_cntl0);
559 559
560 amlogic_mpinit_delay(5000); 560 amlogic_mpinit_delay(5000);
561 561
562 cpuclk = bus_space_read_4(bst, cbus_bsh, AMLOGIC_CBUS_CPU_CLK_CNTL_REG); 562 cpuclk = bus_space_read_4(bst, cbus_bsh, AMLOGIC_CBUS_CPU_CLK_CNTL_REG);
563 cpuclk |= (1 << (24 + cpu)); 563 cpuclk |= (1 << (24 + cpu));
564 bus_space_write_4(bst, cbus_bsh, AMLOGIC_CBUS_CPU_CLK_CNTL_REG, cpuclk); 564 bus_space_write_4(bst, cbus_bsh, AMLOGIC_CBUS_CPU_CLK_CNTL_REG, cpuclk);
565 565
566 mempd0 = bus_space_read_4(bst, ao_bsh, AMLOGIC_AOBUS_PWR_MEM_PD0_REG); 566 mempd0 = bus_space_read_4(bst, ao_bsh, AMLOGIC_AOBUS_PWR_MEM_PD0_REG);
567 mempd0 &= ~((uint32_t)(0xf << 28) >> ((cpu - 1) * 4)); 567 mempd0 &= ~((uint32_t)(0xf << 28) >> ((cpu - 1) * 4));
568 bus_space_write_4(bst, ao_bsh, AMLOGIC_AOBUS_PWR_MEM_PD0_REG, mempd0); 568 bus_space_write_4(bst, ao_bsh, AMLOGIC_AOBUS_PWR_MEM_PD0_REG, mempd0);
569 569
570 pwr_cntl1 = bus_space_read_4(bst, ao_bsh, AMLOGIC_AOBUS_PWR_CTRL1_REG); 570 pwr_cntl1 = bus_space_read_4(bst, ao_bsh, AMLOGIC_AOBUS_PWR_CTRL1_REG);
571 pwr_cntl1 &= ~((3 << 4) << ((cpu - 1) * 2)); 571 pwr_cntl1 &= ~((3 << 4) << ((cpu - 1) * 2));
572 bus_space_write_4(bst, ao_bsh, AMLOGIC_AOBUS_PWR_CTRL1_REG, pwr_cntl1); 572 bus_space_write_4(bst, ao_bsh, AMLOGIC_AOBUS_PWR_CTRL1_REG, pwr_cntl1);
573 573
574 amlogic_mpinit_delay(10000); 574 amlogic_mpinit_delay(10000);
575 575
576 for (;;) { 576 for (;;) {
577 pwr_cntl1 = bus_space_read_4(bst, ao_bsh, 577 pwr_cntl1 = bus_space_read_4(bst, ao_bsh,
578 AMLOGIC_AOBUS_PWR_CTRL1_REG) & ((1 << 17) << (cpu - 1)); 578 AMLOGIC_AOBUS_PWR_CTRL1_REG) & ((1 << 17) << (cpu - 1));
579 if (pwr_cntl1) 579 if (pwr_cntl1)
580 break; 580 break;
581 amlogic_mpinit_delay(10000); 581 amlogic_mpinit_delay(10000);
582 } 582 }
583 583
584 pwr_cntl0 = bus_space_read_4(bst, ao_bsh, AMLOGIC_AOBUS_PWR_CTRL0_REG); 584 pwr_cntl0 = bus_space_read_4(bst, ao_bsh, AMLOGIC_AOBUS_PWR_CTRL0_REG);
585 pwr_cntl0 &= ~(1 << cpu); 585 pwr_cntl0 &= ~(1 << cpu);
586 bus_space_write_4(bst, ao_bsh, AMLOGIC_AOBUS_PWR_CTRL0_REG, pwr_cntl0); 586 bus_space_write_4(bst, ao_bsh, AMLOGIC_AOBUS_PWR_CTRL0_REG, pwr_cntl0);
587 587
588 cpuclk = bus_space_read_4(bst, cbus_bsh, AMLOGIC_CBUS_CPU_CLK_CNTL_REG); 588 cpuclk = bus_space_read_4(bst, cbus_bsh, AMLOGIC_CBUS_CPU_CLK_CNTL_REG);
589 cpuclk &= ~(1 << (24 + cpu)); 589 cpuclk &= ~(1 << (24 + cpu));
590 bus_space_write_4(bst, cbus_bsh, AMLOGIC_CBUS_CPU_CLK_CNTL_REG, cpuclk); 590 bus_space_write_4(bst, cbus_bsh, AMLOGIC_CBUS_CPU_CLK_CNTL_REG, cpuclk);
591 591
592 bus_space_write_4(bst, scu_bsh, SCU_CPU_PWR_STS, pwr_sts); 592 bus_space_write_4(bst, scu_bsh, SCU_CPU_PWR_STS, pwr_sts);
593} 593}
594 594
595void 595void
596amlogic_mpinit(uint32_t mpinit_vec) 596amlogic_mpinit(uint32_t mpinit_vec)
597{ 597{
598 const bus_addr_t cbar = armreg_cbar_read(); 598 const bus_addr_t cbar = armreg_cbar_read();
599 bus_space_tag_t bst = &amlogic_bs_tag; 599 bus_space_tag_t bst = &amlogic_bs_tag;
600 volatile int i; 600 volatile int i;
601 uint32_t ctrl, hatched = 0; 601 uint32_t ctrl, hatched = 0;
602 int cpu; 602 int cpu;
603 603
604 if (cbar == 0) 604 if (cbar == 0)
605 return; 605 return;
606 606
607 const bus_space_handle_t scu_bsh = 607 const bus_space_handle_t scu_bsh =
608 cbar - AMLOGIC_CORE_BASE + AMLOGIC_CORE_VBASE; 608 cbar - AMLOGIC_CORE_BASE + AMLOGIC_CORE_VBASE;
609 const bus_space_handle_t cpuconf_bsh = 609 const bus_space_handle_t cpuconf_bsh =
610 AMLOGIC_CORE_VBASE + AMLOGIC_CPUCONF_OFFSET; 610 AMLOGIC_CORE_VBASE + AMLOGIC_CPUCONF_OFFSET;
611 611
612 const uint32_t scu_cfg = bus_space_read_4(bst, scu_bsh, SCU_CFG); 612 const uint32_t scu_cfg = bus_space_read_4(bst, scu_bsh, SCU_CFG);
613 const u_int ncpus = (scu_cfg & SCU_CFG_CPUMAX) + 1; 613 const u_int ncpus = (scu_cfg & SCU_CFG_CPUMAX) + 1;
614 if (ncpus < 2) 614 if (ncpus < 2)
615 return; 615 return;
616 616
617 for (cpu = 1; cpu < ncpus; cpu++) { 617 for (cpu = 1; cpu < ncpus; cpu++) {
618 bus_space_write_4(bst, cpuconf_bsh, 618 bus_space_write_4(bst, cpuconf_bsh,
619 AMLOGIC_CPUCONF_CPU_ADDR_REG(cpu), mpinit_vec); 619 AMLOGIC_CPUCONF_CPU_ADDR_REG(cpu), mpinit_vec);
620 amlogic_mpinit_cpu(cpu); 620 amlogic_mpinit_cpu(cpu);
621 hatched |= __BIT(cpu); 621 hatched |= __BIT(cpu);
622 } 622 }
623 ctrl = bus_space_read_4(bst, cpuconf_bsh, AMLOGIC_CPUCONF_CTRL_REG); 623 ctrl = bus_space_read_4(bst, cpuconf_bsh, AMLOGIC_CPUCONF_CTRL_REG);
624 for (cpu = 0; cpu < ncpus; cpu++) { 624 for (cpu = 0; cpu < ncpus; cpu++) {
625 ctrl |= __BIT(cpu); 625 ctrl |= __BIT(cpu);
626 } 626 }
627 bus_space_write_4(bst, cpuconf_bsh, AMLOGIC_CPUCONF_CTRL_REG, ctrl); 627 bus_space_write_4(bst, cpuconf_bsh, AMLOGIC_CPUCONF_CTRL_REG, ctrl);
628 628
629 __asm __volatile("sev"); 629 __asm __volatile("sev");
630 630
631 for (i = 0x10000000; i > 0; i--) { 631 for (i = 0x10000000; i > 0; i--) {
632 __asm __volatile("dmb" ::: "memory"); 632 __asm __volatile("dmb" ::: "memory");
633 if (arm_cpu_hatched == hatched) 633 if (arm_cpu_hatched == hatched)
634 break; 634 break;
635 } 635 }
636 
637 if (i == 0) { 
638 const char *msg = "\nWARNING: Some APs failed to start\n"; 
639 const char *p = msg; 
640 while (*p) 
641 amlogic_putchar(*p++); 
642 } 
643} 636}
644#endif 637#endif