Tue Mar 3 23:14:41 2015 UTC ()
cleanup, copy in boot args from uboot


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

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

--- src/sys/arch/evbarm/amlogic/Attic/amlogic_machdep.c 2015/03/01 15:37:26 1.10
+++ src/sys/arch/evbarm/amlogic/Attic/amlogic_machdep.c 2015/03/03 23:14:41 1.11
@@ -1,701 +1,644 @@ @@ -1,701 +1,644 @@
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.
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.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
211BootConfig bootconfig; /* Boot config storage */ 197BootConfig bootconfig; /* Boot config storage */
212static char bootargs[AMLOGIC_MAX_BOOT_STRING]; 198static char bootargs[AMLOGIC_MAX_BOOT_STRING];
213char *boot_args = NULL; 199char *boot_args = NULL;
214char *boot_file = NULL; 200char *boot_file = NULL;
215#if 0 
216static uint8_t amlogic_edid[128]; /* EDID storage */ 
217#endif 
218u_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) */
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
222extern char KERNEL_BASE_phys[]; 205extern char KERNEL_BASE_phys[];
223extern char _end[]; 206extern 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
233void consinit(void); 216void consinit(void);
234#ifdef KGDB 
235static void kgdb_port_init(void); 
236#endif 
237 217
238static void init_clocks(void); 
239static void amlogic_device_register(device_t, void *); 218static void amlogic_device_register(device_t, void *);
240static void amlogic_reset(void); 219static void amlogic_reset(void);
241 220
242bs_protos(bs_notimpl); 221bs_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().
252 * 231 *
253 * Since we map these registers into the bootstrap page table using 232 * Since we map these registers into the bootstrap page table using
254 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map 233 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
255 * registers segment-aligned and segment-rounded in order to avoid 234 * registers segment-aligned and segment-rounded in order to avoid
256 * using the 2nd page tables. 235 * using the 2nd page tables.
257 */ 236 */
258 237
259#define _A(a) ((a) & ~L1_S_OFFSET) 238#define _A(a) ((a) & ~L1_S_OFFSET)
260#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))
261 240
262static const struct pmap_devmap devmap[] = { 241static const struct pmap_devmap devmap[] = {
263 { 242 {
264 .pd_va = _A(AMLOGIC_CORE_VBASE), 243 .pd_va = _A(AMLOGIC_CORE_VBASE),
265 .pd_pa = _A(AMLOGIC_CORE_BASE), 244 .pd_pa = _A(AMLOGIC_CORE_BASE),
266 .pd_size = _S(AMLOGIC_CORE_SIZE), 245 .pd_size = _S(AMLOGIC_CORE_SIZE),
267 .pd_prot = VM_PROT_READ|VM_PROT_WRITE, 246 .pd_prot = VM_PROT_READ|VM_PROT_WRITE,
268 .pd_cache = PTE_NOCACHE 247 .pd_cache = PTE_NOCACHE
269 }, 248 },
270 {0} 249 {0}
271}; 250};
272 251
273#undef _A 252#undef _A
274#undef _S 253#undef _S
275 254
276#ifdef DDB 255#ifdef DDB
277static void 256static void
278amlogic_db_trap(int where) 257amlogic_db_trap(int where)
279{ 258{
280 /* NOT YET */ 259 /* NOT YET */
281} 260}
282#endif 261#endif
283 262
284void amlogic_putchar(char c); 263#ifdef VERBOSE_INIT_ARM
285void 264static void
286amlogic_putchar(char c) 265amlogic_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}
 282static void
 283amlogic_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
304static psize_t 296static psize_t
305amlogic_get_ram_size(void) 297amlogic_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 */
325u_int 317u_int
326initarm(void *arg) 318initarm(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
452static void 
453init_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
469static const bus_addr_t consaddr = CONSADDR; 454static const bus_addr_t consaddr = CONSADDR;
470static const int conspeed = CONSPEED; 455static const int conspeed = CONSPEED;
471static const int conmode = CONMODE; 456static const int conmode = CONMODE;
472#endif 457#endif
473 458
474void 459void
475consinit(void) 460consinit(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
500void 480void
501amlogic_reset(void) 481amlogic_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 
527static const vaddr_t comkgdbaddr = KGDB_DEVADDR; 
528static const int comkgdbspeed = KGDB_DEVRATE; 
529static const int comkgdbmode = KGDB_DEVMODE; 
530 
531void 
532static 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 
553void 496void
554amlogic_device_register(device_t self, void *aux) 497amlogic_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 /*
566 * We need to tell the A9 Global/Watchdog Timer 509 * We need to tell the A9 Global/Watchdog Timer
567 * what frequency it runs at. 510 * what frequency it runs at.
568 */ 511 */
569 if (device_is_a(self, "a9tmr") || device_is_a(self, "a9wdt")) { 512 if (device_is_a(self, "a9tmr") || device_is_a(self, "a9wdt")) {
570 prop_dictionary_set_uint32(dict, "frequency", 513 prop_dictionary_set_uint32(dict, "frequency",
571 amlogic_get_rate_a9periph()); 514 amlogic_get_rate_a9periph());
572 515
573 return; 516 return;
574 } 517 }
575 518
576 if (device_is_a(self, "arml2cc")) { 519 if (device_is_a(self, "arml2cc")) {
577 /* 520 /*
578 * L2 cache regs are at C4200000 and A9 periph base is 521 * L2 cache regs are at C4200000 and A9 periph base is
579 * at C4300000; pass as a negative offset for the benefit 522 * at C4300000; pass as a negative offset for the benefit
580 * of armperiph bus. 523 * of armperiph bus.
581 */ 524 */
582 prop_dictionary_set_uint32(dict, "offset", 0xfff00000); 525 prop_dictionary_set_uint32(dict, "offset", 0xfff00000);
583 } 526 }
584} 527}
585 528
586#if defined(MULTIPROCESSOR) 529#if defined(MULTIPROCESSOR)
587void amlogic_mpinit(uint32_t); 530void amlogic_mpinit(uint32_t);
588 531
589static void 532static void
590amlogic_mpinit_delay(u_int n) 533amlogic_mpinit_delay(u_int n)
591{ 534{
592 for (volatile int i = 0; i < n; i++) 535 for (volatile int i = 0; i < n; i++)
593 ; 536 ;
594} 537}
595 538
596static void 539static void
597amlogic_mpinit_cpu(int cpu) 540amlogic_mpinit_cpu(int cpu)
598{ 541{
599 const bus_addr_t cbar = armreg_cbar_read(); 542 const bus_addr_t cbar = armreg_cbar_read();
600 bus_space_tag_t bst = &amlogic_bs_tag; 543 bus_space_tag_t bst = &amlogic_bs_tag;
601 const bus_space_handle_t scu_bsh = 544 const bus_space_handle_t scu_bsh =
602 cbar - AMLOGIC_CORE_BASE + AMLOGIC_CORE_VBASE; 545 cbar - AMLOGIC_CORE_BASE + AMLOGIC_CORE_VBASE;
603 const bus_space_handle_t ao_bsh = 546 const bus_space_handle_t ao_bsh =
604 AMLOGIC_CORE_VBASE + AMLOGIC_AOBUS_OFFSET; 547 AMLOGIC_CORE_VBASE + AMLOGIC_AOBUS_OFFSET;
605 const bus_space_handle_t cbus_bsh = 548 const bus_space_handle_t cbus_bsh =
606 AMLOGIC_CORE_VBASE + AMLOGIC_CBUS_OFFSET; 549 AMLOGIC_CORE_VBASE + AMLOGIC_CBUS_OFFSET;
607 uint32_t pwr_sts, pwr_cntl0, pwr_cntl1, cpuclk, mempd0; 550 uint32_t pwr_sts, pwr_cntl0, pwr_cntl1, cpuclk, mempd0;
608 551
609 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);
610 pwr_sts &= ~(3 << (8 * cpu)); 553 pwr_sts &= ~(3 << (8 * cpu));
611 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);
612 555
613 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);
614 pwr_cntl0 &= ~((3 << 18) << ((cpu - 1) * 2)); 557 pwr_cntl0 &= ~((3 << 18) << ((cpu - 1) * 2));
615 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);
616 559
617 amlogic_mpinit_delay(5000); 560 amlogic_mpinit_delay(5000);
618 561
619 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);
620 cpuclk |= (1 << (24 + cpu)); 563 cpuclk |= (1 << (24 + cpu));
621 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);
622 565
623 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);
624 mempd0 &= ~((uint32_t)(0xf << 28) >> ((cpu - 1) * 4)); 567 mempd0 &= ~((uint32_t)(0xf << 28) >> ((cpu - 1) * 4));
625 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);
626 569
627 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);
628 pwr_cntl1 &= ~((3 << 4) << ((cpu - 1) * 2)); 571 pwr_cntl1 &= ~((3 << 4) << ((cpu - 1) * 2));
629 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);
630 573
631 amlogic_mpinit_delay(10000); 574 amlogic_mpinit_delay(10000);
632 575
633 for (;;) { 576 for (;;) {
634 pwr_cntl1 = bus_space_read_4(bst, ao_bsh, 577 pwr_cntl1 = bus_space_read_4(bst, ao_bsh,
635 AMLOGIC_AOBUS_PWR_CTRL1_REG) & ((1 << 17) << (cpu - 1)); 578 AMLOGIC_AOBUS_PWR_CTRL1_REG) & ((1 << 17) << (cpu - 1));
636 if (pwr_cntl1) 579 if (pwr_cntl1)
637 break; 580 break;
638 amlogic_mpinit_delay(10000); 581 amlogic_mpinit_delay(10000);
639 } 582 }
640 583
641 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);
642 pwr_cntl0 &= ~(1 << cpu); 585 pwr_cntl0 &= ~(1 << cpu);
643 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);
644 587
645 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);
646 cpuclk &= ~(1 << (24 + cpu)); 589 cpuclk &= ~(1 << (24 + cpu));
647 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);
648 591
649 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);
650} 593}
651 594
652void 595void
653amlogic_mpinit(uint32_t mpinit_vec) 596amlogic_mpinit(uint32_t mpinit_vec)
654{ 597{
655 const bus_addr_t cbar = armreg_cbar_read(); 598 const bus_addr_t cbar = armreg_cbar_read();
656 bus_space_tag_t bst = &amlogic_bs_tag; 599 bus_space_tag_t bst = &amlogic_bs_tag;
657 volatile int i; 600 volatile int i;
658 uint32_t ctrl, hatched = 0; 601 uint32_t ctrl, hatched = 0;
659 int cpu; 602 int cpu;
660 603
661 if (cbar == 0) 604 if (cbar == 0)
662 return; 605 return;
663 606
664 const bus_space_handle_t scu_bsh = 607 const bus_space_handle_t scu_bsh =
665 cbar - AMLOGIC_CORE_BASE + AMLOGIC_CORE_VBASE; 608 cbar - AMLOGIC_CORE_BASE + AMLOGIC_CORE_VBASE;
666 const bus_space_handle_t cpuconf_bsh = 609 const bus_space_handle_t cpuconf_bsh =
667 AMLOGIC_CORE_VBASE + AMLOGIC_CPUCONF_OFFSET; 610 AMLOGIC_CORE_VBASE + AMLOGIC_CPUCONF_OFFSET;
668 611
669 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);
670 const u_int ncpus = (scu_cfg & SCU_CFG_CPUMAX) + 1; 613 const u_int ncpus = (scu_cfg & SCU_CFG_CPUMAX) + 1;
671 if (ncpus < 2) 614 if (ncpus < 2)
672 return; 615 return;
673 616
674 for (cpu = 1; cpu < ncpus; cpu++) { 617 for (cpu = 1; cpu < ncpus; cpu++) {
675 bus_space_write_4(bst, cpuconf_bsh, 618 bus_space_write_4(bst, cpuconf_bsh,
676 AMLOGIC_CPUCONF_CPU_ADDR_REG(cpu), mpinit_vec); 619 AMLOGIC_CPUCONF_CPU_ADDR_REG(cpu), mpinit_vec);
677 amlogic_mpinit_cpu(cpu); 620 amlogic_mpinit_cpu(cpu);
678 hatched |= __BIT(cpu); 621 hatched |= __BIT(cpu);
679 } 622 }
680 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);
681 for (cpu = 0; cpu < ncpus; cpu++) { 624 for (cpu = 0; cpu < ncpus; cpu++) {
682 ctrl |= __BIT(cpu); 625 ctrl |= __BIT(cpu);
683 } 626 }
684 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);
685 628
686 __asm __volatile("sev"); 629 __asm __volatile("sev");
687 630
688 for (i = 0x10000000; i > 0; i--) { 631 for (i = 0x10000000; i > 0; i--) {
689 __asm __volatile("dmb" ::: "memory"); 632 __asm __volatile("dmb" ::: "memory");
690 if (arm_cpu_hatched == hatched) 633 if (arm_cpu_hatched == hatched)
691 break; 634 break;
692 } 635 }
693 636
694 if (i == 0) { 637 if (i == 0) {
695 const char *msg = "\nWARNING: Some APs failed to start\n"; 638 const char *msg = "\nWARNING: Some APs failed to start\n";
696 const char *p = msg; 639 const char *p = msg;
697 while (*p) 640 while (*p)
698 amlogic_putchar(*p++); 641 amlogic_putchar(*p++);
699 } 642 }
700} 643}
701#endif 644#endif