| @@ -1,523 +1,537 @@ | | | @@ -1,523 +1,537 @@ |
1 | /* $NetBSD: tegra_machdep.c,v 1.37 2015/12/22 22:10:36 jmcneill Exp $ */ | | 1 | /* $NetBSD: tegra_machdep.c,v 1.38 2016/03/26 09:07:31 skrll Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca> | | 4 | * Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
15 | * | | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | | 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 | * SUCH DAMAGE. | | 26 | * SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: tegra_machdep.c,v 1.37 2015/12/22 22:10:36 jmcneill Exp $"); | | 30 | __KERNEL_RCSID(0, "$NetBSD: tegra_machdep.c,v 1.38 2016/03/26 09:07:31 skrll Exp $"); |
31 | | | 31 | |
32 | #include "opt_tegra.h" | | 32 | #include "opt_tegra.h" |
33 | #include "opt_machdep.h" | | 33 | #include "opt_machdep.h" |
34 | #include "opt_ddb.h" | | 34 | #include "opt_ddb.h" |
35 | #include "opt_md.h" | | 35 | #include "opt_md.h" |
36 | #include "opt_arm_debug.h" | | 36 | #include "opt_arm_debug.h" |
37 | #include "opt_multiprocessor.h" | | 37 | #include "opt_multiprocessor.h" |
38 | | | 38 | |
39 | #include "com.h" | | 39 | #include "com.h" |
40 | #include "ukbd.h" | | 40 | #include "ukbd.h" |
41 | #include "genfb.h" | | 41 | #include "genfb.h" |
42 | #include "ether.h" | | 42 | #include "ether.h" |
43 | #include "as3722pmic.h" | | 43 | #include "as3722pmic.h" |
44 | | | 44 | |
45 | #include <sys/param.h> | | 45 | #include <sys/param.h> |
46 | #include <sys/systm.h> | | 46 | #include <sys/systm.h> |
47 | #include <sys/bus.h> | | 47 | #include <sys/bus.h> |
48 | #include <sys/atomic.h> | | 48 | #include <sys/atomic.h> |
49 | #include <sys/cpu.h> | | 49 | #include <sys/cpu.h> |
50 | #include <sys/device.h> | | 50 | #include <sys/device.h> |
51 | #include <sys/exec.h> | | 51 | #include <sys/exec.h> |
52 | #include <sys/kernel.h> | | 52 | #include <sys/kernel.h> |
53 | #include <sys/kmem.h> | | 53 | #include <sys/kmem.h> |
54 | #include <sys/ksyms.h> | | 54 | #include <sys/ksyms.h> |
55 | #include <sys/msgbuf.h> | | 55 | #include <sys/msgbuf.h> |
56 | #include <sys/proc.h> | | 56 | #include <sys/proc.h> |
57 | #include <sys/reboot.h> | | 57 | #include <sys/reboot.h> |
58 | #include <sys/termios.h> | | 58 | #include <sys/termios.h> |
59 | #include <sys/gpio.h> | | 59 | #include <sys/gpio.h> |
60 | | | 60 | |
61 | #include <uvm/uvm_extern.h> | | 61 | #include <uvm/uvm_extern.h> |
62 | | | 62 | |
63 | #include <sys/conf.h> | | 63 | #include <sys/conf.h> |
64 | #include <dev/cons.h> | | 64 | #include <dev/cons.h> |
65 | #include <dev/md.h> | | 65 | #include <dev/md.h> |
66 | | | 66 | |
67 | #include <machine/db_machdep.h> | | 67 | #include <machine/db_machdep.h> |
68 | #include <ddb/db_sym.h> | | 68 | #include <ddb/db_sym.h> |
69 | #include <ddb/db_extern.h> | | 69 | #include <ddb/db_extern.h> |
70 | | | 70 | |
71 | #include <machine/bootconfig.h> | | 71 | #include <machine/bootconfig.h> |
72 | #include <arm/armreg.h> | | 72 | #include <arm/armreg.h> |
73 | #include <arm/undefined.h> | | 73 | #include <arm/undefined.h> |
74 | | | 74 | |
75 | #include <arm/arm32/machdep.h> | | 75 | #include <arm/arm32/machdep.h> |
76 | #include <arm/mainbus/mainbus.h> | | 76 | #include <arm/mainbus/mainbus.h> |
77 | | | 77 | |
78 | #include <arm/nvidia/tegra_reg.h> | | 78 | #include <arm/nvidia/tegra_reg.h> |
79 | #include <arm/nvidia/tegra_var.h> | | 79 | #include <arm/nvidia/tegra_var.h> |
80 | | | 80 | |
81 | #include <arm/cortex/gtmr_var.h> | | 81 | #include <arm/cortex/gtmr_var.h> |
82 | | | 82 | |
83 | #include <evbarm/include/autoconf.h> | | 83 | #include <evbarm/include/autoconf.h> |
84 | #include <evbarm/tegra/platform.h> | | 84 | #include <evbarm/tegra/platform.h> |
85 | | | 85 | |
86 | #include <dev/ic/ns16550reg.h> | | 86 | #include <dev/ic/ns16550reg.h> |
87 | #include <dev/ic/comreg.h> | | 87 | #include <dev/ic/comreg.h> |
88 | #include <dev/ic/comvar.h> | | 88 | #include <dev/ic/comvar.h> |
89 | | | 89 | |
90 | #include <dev/usb/ukbdvar.h> | | 90 | #include <dev/usb/ukbdvar.h> |
91 | #include <net/if_ether.h> | | 91 | #include <net/if_ether.h> |
92 | | | 92 | |
93 | #if NAS3722PMIC > 0 | | 93 | #if NAS3722PMIC > 0 |
94 | #include <dev/i2c/as3722.h> | | 94 | #include <dev/i2c/as3722.h> |
95 | #endif | | 95 | #endif |
96 | | | 96 | |
97 | #ifndef TEGRA_MAX_BOOT_STRING | | 97 | #ifndef TEGRA_MAX_BOOT_STRING |
98 | #define TEGRA_MAX_BOOT_STRING 1024 | | 98 | #define TEGRA_MAX_BOOT_STRING 1024 |
99 | #endif | | 99 | #endif |
100 | | | 100 | |
101 | BootConfig bootconfig; | | 101 | BootConfig bootconfig; |
102 | char bootargs[TEGRA_MAX_BOOT_STRING] = ""; | | 102 | char bootargs[TEGRA_MAX_BOOT_STRING] = ""; |
103 | char *boot_args = NULL; | | 103 | char *boot_args = NULL; |
104 | u_int uboot_args[4] = { 0 }; /* filled in by tegra_start.S (not in bss) */ | | 104 | u_int uboot_args[4] = { 0 }; /* filled in by tegra_start.S (not in bss) */ |
105 | | | 105 | |
106 | #include <libfdt.h> | | 106 | #include <libfdt.h> |
107 | #include <dev/fdt/fdtvar.h> | | 107 | #include <dev/fdt/fdtvar.h> |
108 | #define FDT_BUF_SIZE (128*1024) | | 108 | #define FDT_BUF_SIZE (128*1024) |
109 | static uint8_t fdt_data[FDT_BUF_SIZE]; | | 109 | static uint8_t fdt_data[FDT_BUF_SIZE]; |
110 | | | 110 | |
111 | extern char KERNEL_BASE_phys[]; | | 111 | extern char KERNEL_BASE_phys[]; |
112 | #define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys) | | 112 | #define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys) |
113 | | | 113 | |
114 | static void tegra_device_register(device_t, void *); | | 114 | static void tegra_device_register(device_t, void *); |
115 | static void tegra_reset(void); | | 115 | static void tegra_reset(void); |
116 | static void tegra_powerdown(void); | | 116 | static void tegra_powerdown(void); |
117 | | | 117 | |
118 | bs_protos(bs_notimpl); | | 118 | bs_protos(bs_notimpl); |
119 | | | 119 | |
120 | #define _A(a) ((a) & ~L1_S_OFFSET) | | 120 | #define _A(a) ((a) & ~L1_S_OFFSET) |
121 | #define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1)) | | 121 | #define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1)) |
122 | | | 122 | |
123 | static const struct pmap_devmap devmap[] = { | | 123 | static const struct pmap_devmap devmap[] = { |
124 | { | | 124 | { |
| | | 125 | .pd_va = _A(TEGRA_HOST1X_VBASE), |
| | | 126 | .pd_pa = _A(TEGRA_HOST1X_BASE), |
| | | 127 | .pd_size = _S(TEGRA_HOST1X_SIZE), |
| | | 128 | .pd_prot = VM_PROT_READ|VM_PROT_WRITE, |
| | | 129 | .pd_cache = PTE_NOCACHE |
| | | 130 | }, |
| | | 131 | { |
125 | .pd_va = _A(TEGRA_PPSB_VBASE), | | 132 | .pd_va = _A(TEGRA_PPSB_VBASE), |
126 | .pd_pa = _A(TEGRA_PPSB_BASE), | | 133 | .pd_pa = _A(TEGRA_PPSB_BASE), |
127 | .pd_size = _S(TEGRA_PPSB_SIZE), | | 134 | .pd_size = _S(TEGRA_PPSB_SIZE), |
128 | .pd_prot = VM_PROT_READ|VM_PROT_WRITE, | | 135 | .pd_prot = VM_PROT_READ|VM_PROT_WRITE, |
129 | .pd_cache = PTE_NOCACHE | | 136 | .pd_cache = PTE_NOCACHE |
130 | }, | | 137 | }, |
131 | { | | 138 | { |
132 | .pd_va = _A(TEGRA_APB_VBASE), | | 139 | .pd_va = _A(TEGRA_APB_VBASE), |
133 | .pd_pa = _A(TEGRA_APB_BASE), | | 140 | .pd_pa = _A(TEGRA_APB_BASE), |
134 | .pd_size = _S(TEGRA_APB_SIZE), | | 141 | .pd_size = _S(TEGRA_APB_SIZE), |
135 | .pd_prot = VM_PROT_READ|VM_PROT_WRITE, | | 142 | .pd_prot = VM_PROT_READ|VM_PROT_WRITE, |
136 | .pd_cache = PTE_NOCACHE | | 143 | .pd_cache = PTE_NOCACHE |
137 | }, | | 144 | }, |
| | | 145 | { |
| | | 146 | .pd_va = _A(TEGRA_AHB_A2_VBASE), |
| | | 147 | .pd_pa = _A(TEGRA_AHB_A2_BASE), |
| | | 148 | .pd_size = _S(TEGRA_AHB_A2_SIZE), |
| | | 149 | .pd_prot = VM_PROT_READ|VM_PROT_WRITE, |
| | | 150 | .pd_cache = PTE_NOCACHE |
| | | 151 | }, |
138 | {0} | | 152 | {0} |
139 | }; | | 153 | }; |
140 | | | 154 | |
141 | #undef _A | | 155 | #undef _A |
142 | #undef _S | | 156 | #undef _S |
143 | | | 157 | |
144 | #ifdef PMAP_NEED_ALLOC_POOLPAGE | | 158 | #ifdef PMAP_NEED_ALLOC_POOLPAGE |
145 | static struct boot_physmem bp_lowgig = { | | 159 | static struct boot_physmem bp_lowgig = { |
146 | .bp_start = TEGRA_EXTMEM_BASE / NBPG, | | 160 | .bp_start = TEGRA_EXTMEM_BASE / NBPG, |
147 | .bp_pages = (KERNEL_VM_BASE - KERNEL_BASE) / NBPG, | | 161 | .bp_pages = (KERNEL_VM_BASE - KERNEL_BASE) / NBPG, |
148 | .bp_freelist = VM_FREELIST_ISADMA, | | 162 | .bp_freelist = VM_FREELIST_ISADMA, |
149 | .bp_flags = 0 | | 163 | .bp_flags = 0 |
150 | }; | | 164 | }; |
151 | #endif | | 165 | #endif |
152 | | | 166 | |
153 | #ifdef VERBOSE_INIT_ARM | | 167 | #ifdef VERBOSE_INIT_ARM |
154 | static void | | 168 | static void |
155 | tegra_putchar(char c) | | 169 | tegra_putchar(char c) |
156 | { | | 170 | { |
157 | volatile uint32_t *uartaddr = (volatile uint32_t *)CONSADDR_VA; | | 171 | volatile uint32_t *uartaddr = (volatile uint32_t *)CONSADDR_VA; |
158 | int timo = 150000; | | 172 | int timo = 150000; |
159 | | | 173 | |
160 | while ((uartaddr[com_lsr] & LSR_TXRDY) == 0) { | | 174 | while ((uartaddr[com_lsr] & LSR_TXRDY) == 0) { |
161 | if (--timo == 0) | | 175 | if (--timo == 0) |
162 | break; | | 176 | break; |
163 | } | | 177 | } |
164 | | | 178 | |
165 | uartaddr[com_data] = c; | | 179 | uartaddr[com_data] = c; |
166 | | | 180 | |
167 | while ((uartaddr[com_lsr] & LSR_TXRDY) == 0) { | | 181 | while ((uartaddr[com_lsr] & LSR_TXRDY) == 0) { |
168 | if (--timo == 0) | | 182 | if (--timo == 0) |
169 | break; | | 183 | break; |
170 | } | | 184 | } |
171 | } | | 185 | } |
172 | static void | | 186 | static void |
173 | tegra_putstr(const char *s) | | 187 | tegra_putstr(const char *s) |
174 | { | | 188 | { |
175 | for (const char *p = s; *p; p++) { | | 189 | for (const char *p = s; *p; p++) { |
176 | tegra_putchar(*p); | | 190 | tegra_putchar(*p); |
177 | } | | 191 | } |
178 | } | | 192 | } |
179 | | | 193 | |
180 | static void | | 194 | static void |
181 | tegra_printn(u_int n, int base) | | 195 | tegra_printn(u_int n, int base) |
182 | { | | 196 | { |
183 | char *p, buf[(sizeof(u_int) * NBBY / 3) + 1 + 2 /* ALT + SIGN */]; | | 197 | char *p, buf[(sizeof(u_int) * NBBY / 3) + 1 + 2 /* ALT + SIGN */]; |
184 | | | 198 | |
185 | p = buf; | | 199 | p = buf; |
186 | do { | | 200 | do { |
187 | *p++ = hexdigits[n % base]; | | 201 | *p++ = hexdigits[n % base]; |
188 | } while (n /= base); | | 202 | } while (n /= base); |
189 | | | 203 | |
190 | do { | | 204 | do { |
191 | tegra_putchar(*--p); | | 205 | tegra_putchar(*--p); |
192 | } while (p > buf); | | 206 | } while (p > buf); |
193 | } | | 207 | } |
194 | #define DPRINTF(...) printf(__VA_ARGS__) | | 208 | #define DPRINTF(...) printf(__VA_ARGS__) |
195 | #define DPRINT(x) tegra_putstr(x) | | 209 | #define DPRINT(x) tegra_putstr(x) |
196 | #define DPRINTN(x,b) tegra_printn((x), (b)) | | 210 | #define DPRINTN(x,b) tegra_printn((x), (b)) |
197 | #else | | 211 | #else |
198 | #define DPRINTF(...) | | 212 | #define DPRINTF(...) |
199 | #define DPRINT(x) | | 213 | #define DPRINT(x) |
200 | #define DPRINTN(x,b) | | 214 | #define DPRINTN(x,b) |
201 | #endif | | 215 | #endif |
202 | | | 216 | |
203 | extern void cortex_mpstart(void); | | 217 | extern void cortex_mpstart(void); |
204 | | | 218 | |
205 | /* | | 219 | /* |
206 | * u_int initarm(...) | | 220 | * u_int initarm(...) |
207 | * | | 221 | * |
208 | * Initial entry point on startup. This gets called before main() is | | 222 | * Initial entry point on startup. This gets called before main() is |
209 | * entered. | | 223 | * entered. |
210 | * It should be responsible for setting up everything that must be | | 224 | * It should be responsible for setting up everything that must be |
211 | * in place when main is called. | | 225 | * in place when main is called. |
212 | * This includes | | 226 | * This includes |
213 | * Taking a copy of the boot configuration structure. | | 227 | * Taking a copy of the boot configuration structure. |
214 | * Initialising the physical console so characters can be printed. | | 228 | * Initialising the physical console so characters can be printed. |
215 | * Setting up page tables for the kernel | | 229 | * Setting up page tables for the kernel |
216 | * Relocating the kernel to the bottom of physical memory | | 230 | * Relocating the kernel to the bottom of physical memory |
217 | */ | | 231 | */ |
218 | u_int | | 232 | u_int |
219 | initarm(void *arg) | | 233 | initarm(void *arg) |
220 | { | | 234 | { |
221 | psize_t ram_size = 0; | | 235 | psize_t ram_size = 0; |
222 | DPRINT("initarm:"); | | 236 | DPRINT("initarm:"); |
223 | | | 237 | |
224 | DPRINT(" mpstart<0x"); | | 238 | DPRINT(" mpstart<0x"); |
225 | DPRINTN((uint32_t)cortex_mpstart, 16); | | 239 | DPRINTN((uint32_t)cortex_mpstart, 16); |
226 | DPRINT(">"); | | 240 | DPRINT(">"); |
227 | | | 241 | |
228 | DPRINT(" devmap"); | | 242 | DPRINT(" devmap"); |
229 | pmap_devmap_register(devmap); | | 243 | pmap_devmap_register(devmap); |
230 | | | 244 | |
231 | DPRINT(" bootstrap"); | | 245 | DPRINT(" bootstrap"); |
232 | tegra_bootstrap(); | | 246 | tegra_bootstrap(); |
233 | | | 247 | |
234 | /* Heads up ... Setup the CPU / MMU / TLB functions. */ | | 248 | /* Heads up ... Setup the CPU / MMU / TLB functions. */ |
235 | DPRINT(" cpufunc"); | | 249 | DPRINT(" cpufunc"); |
236 | if (set_cpufuncs()) | | 250 | if (set_cpufuncs()) |
237 | panic("cpu not recognized!"); | | 251 | panic("cpu not recognized!"); |
238 | | | 252 | |
239 | DPRINT(" consinit"); | | 253 | DPRINT(" consinit"); |
240 | consinit(); | | 254 | consinit(); |
241 | | | 255 | |
242 | DPRINTF(" cbar=%#x", armreg_cbar_read()); | | 256 | DPRINTF(" cbar=%#x", armreg_cbar_read()); |
243 | | | 257 | |
244 | DPRINTF(" ok\n"); | | 258 | DPRINTF(" ok\n"); |
245 | | | 259 | |
246 | DPRINTF("uboot: args %#x, %#x, %#x, %#x\n", | | 260 | DPRINTF("uboot: args %#x, %#x, %#x, %#x\n", |
247 | uboot_args[0], uboot_args[1], uboot_args[2], uboot_args[3]); | | 261 | uboot_args[0], uboot_args[1], uboot_args[2], uboot_args[3]); |
248 | | | 262 | |
249 | cpu_reset_address = tegra_reset; | | 263 | cpu_reset_address = tegra_reset; |
250 | cpu_powerdown_address = tegra_powerdown; | | 264 | cpu_powerdown_address = tegra_powerdown; |
251 | | | 265 | |
252 | /* Talk to the user */ | | 266 | /* Talk to the user */ |
253 | DPRINTF("\nNetBSD/evbarm (tegra) booting ...\n"); | | 267 | DPRINTF("\nNetBSD/evbarm (tegra) booting ...\n"); |
254 | | | 268 | |
255 | #ifdef BOOT_ARGS | | 269 | #ifdef BOOT_ARGS |
256 | char mi_bootargs[] = BOOT_ARGS; | | 270 | char mi_bootargs[] = BOOT_ARGS; |
257 | parse_mi_bootargs(mi_bootargs); | | 271 | parse_mi_bootargs(mi_bootargs); |
258 | #endif | | 272 | #endif |
259 | | | 273 | |
260 | const uint8_t *fdt_addr_r = (const uint8_t *)uboot_args[2]; | | 274 | const uint8_t *fdt_addr_r = (const uint8_t *)uboot_args[2]; |
261 | int error = fdt_check_header(fdt_addr_r); | | 275 | int error = fdt_check_header(fdt_addr_r); |
262 | if (error == 0) { | | 276 | if (error == 0) { |
263 | error = fdt_move(fdt_addr_r, fdt_data, sizeof(fdt_data)); | | 277 | error = fdt_move(fdt_addr_r, fdt_data, sizeof(fdt_data)); |
264 | if (error != 0) { | | 278 | if (error != 0) { |
265 | panic("fdt_move failed: %s", fdt_strerror(error)); | | 279 | panic("fdt_move failed: %s", fdt_strerror(error)); |
266 | } | | 280 | } |
267 | fdtbus_set_data(fdt_data); | | 281 | fdtbus_set_data(fdt_data); |
268 | } else { | | 282 | } else { |
269 | panic("fdt_check_header failed: %s", fdt_strerror(error)); | | 283 | panic("fdt_check_header failed: %s", fdt_strerror(error)); |
270 | } | | 284 | } |
271 | | | 285 | |
272 | const u_int chip_id = tegra_chip_id(); | | 286 | const u_int chip_id = tegra_chip_id(); |
273 | switch (chip_id) { | | 287 | switch (chip_id) { |
274 | #ifdef SOC_TEGRA124 | | 288 | #ifdef SOC_TEGRA124 |
275 | case CHIP_ID_TEGRA124: { | | 289 | case CHIP_ID_TEGRA124: { |
276 | const char * const tegra124_compatible_strings[] = { | | 290 | const char * const tegra124_compatible_strings[] = { |
277 | "nvidia,tegra124", | | 291 | "nvidia,tegra124", |
278 | NULL | | 292 | NULL |
279 | }; | | 293 | }; |
280 | const int node = OF_peer(0); | | 294 | const int node = OF_peer(0); |
281 | if (of_compatible(node, tegra124_compatible_strings) < 0) { | | 295 | if (of_compatible(node, tegra124_compatible_strings) < 0) { |
282 | panic("FDT is not compatible with Tegra124"); | | 296 | panic("FDT is not compatible with Tegra124"); |
283 | } | | 297 | } |
284 | break; | | 298 | break; |
285 | } | | 299 | } |
286 | #endif | | 300 | #endif |
287 | default: | | 301 | default: |
288 | panic("Kernel does not support Tegra SOC ID %#x", chip_id); | | 302 | panic("Kernel does not support Tegra SOC ID %#x", chip_id); |
289 | } | | 303 | } |
290 | | | 304 | |
291 | DPRINTF("KERNEL_BASE=0x%x, KERNEL_VM_BASE=0x%x, KERNEL_VM_BASE - KERNEL_BASE=0x%x, KERNEL_BASE_VOFFSET=0x%x\n", | | 305 | DPRINTF("KERNEL_BASE=0x%x, KERNEL_VM_BASE=0x%x, KERNEL_VM_BASE - KERNEL_BASE=0x%x, KERNEL_BASE_VOFFSET=0x%x\n", |
292 | KERNEL_BASE, KERNEL_VM_BASE, KERNEL_VM_BASE - KERNEL_BASE, KERNEL_BASE_VOFFSET); | | 306 | KERNEL_BASE, KERNEL_VM_BASE, KERNEL_VM_BASE - KERNEL_BASE, KERNEL_BASE_VOFFSET); |
293 | | | 307 | |
294 | ram_size = tegra_mc_memsize(); | | 308 | ram_size = tegra_mc_memsize(); |
295 | | | 309 | |
296 | #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS | | 310 | #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS |
297 | const bool mapallmem_p = true; | | 311 | const bool mapallmem_p = true; |
298 | #ifndef PMAP_NEED_ALLOC_POOLPAGE | | 312 | #ifndef PMAP_NEED_ALLOC_POOLPAGE |
299 | if (ram_size > KERNEL_VM_BASE - KERNEL_BASE) { | | 313 | if (ram_size > KERNEL_VM_BASE - KERNEL_BASE) { |
300 | printf("%s: dropping RAM size from %luMB to %uMB\n", | | 314 | printf("%s: dropping RAM size from %luMB to %uMB\n", |
301 | __func__, (unsigned long) (ram_size >> 20), | | 315 | __func__, (unsigned long) (ram_size >> 20), |
302 | (KERNEL_VM_BASE - KERNEL_BASE) >> 20); | | 316 | (KERNEL_VM_BASE - KERNEL_BASE) >> 20); |
303 | ram_size = KERNEL_VM_BASE - KERNEL_BASE; | | 317 | ram_size = KERNEL_VM_BASE - KERNEL_BASE; |
304 | } | | 318 | } |
305 | #endif | | 319 | #endif |
306 | #else | | 320 | #else |
307 | const bool mapallmem_p = false; | | 321 | const bool mapallmem_p = false; |
308 | #endif | | 322 | #endif |
309 | | | 323 | |
310 | /* | | 324 | /* |
311 | * If MEMSIZE specified less than what we really have, limit ourselves | | 325 | * If MEMSIZE specified less than what we really have, limit ourselves |
312 | * to that. | | 326 | * to that. |
313 | */ | | 327 | */ |
314 | #ifdef MEMSIZE | | 328 | #ifdef MEMSIZE |
315 | if (ram_size == 0 || ram_size > (unsigned)MEMSIZE * 1024 * 1024) | | 329 | if (ram_size == 0 || ram_size > (unsigned)MEMSIZE * 1024 * 1024) |
316 | ram_size = (unsigned)MEMSIZE * 1024 * 1024; | | 330 | ram_size = (unsigned)MEMSIZE * 1024 * 1024; |
317 | DPRINTF("ram_size = 0x%x\n", (int)ram_size); | | 331 | DPRINTF("ram_size = 0x%x\n", (int)ram_size); |
318 | #else | | 332 | #else |
319 | KASSERTMSG(ram_size > 0, "RAM size unknown and MEMSIZE undefined"); | | 333 | KASSERTMSG(ram_size > 0, "RAM size unknown and MEMSIZE undefined"); |
320 | #endif | | 334 | #endif |
321 | | | 335 | |
322 | /* DMA tag setup */ | | 336 | /* DMA tag setup */ |
323 | tegra_dma_bootstrap(ram_size); | | 337 | tegra_dma_bootstrap(ram_size); |
324 | | | 338 | |
325 | /* Fake bootconfig structure for the benefit of pmap.c. */ | | 339 | /* Fake bootconfig structure for the benefit of pmap.c. */ |
326 | bootconfig.dramblocks = 1; | | 340 | bootconfig.dramblocks = 1; |
327 | bootconfig.dram[0].address = TEGRA_EXTMEM_BASE; /* DDR PHY addr */ | | 341 | bootconfig.dram[0].address = TEGRA_EXTMEM_BASE; /* DDR PHY addr */ |
328 | bootconfig.dram[0].pages = ram_size / PAGE_SIZE; | | 342 | bootconfig.dram[0].pages = ram_size / PAGE_SIZE; |
329 | | | 343 | |
330 | KASSERT((armreg_pfr1_read() & ARM_PFR1_SEC_MASK) != 0); | | 344 | KASSERT((armreg_pfr1_read() & ARM_PFR1_SEC_MASK) != 0); |
331 | | | 345 | |
332 | arm32_bootmem_init(bootconfig.dram[0].address, ram_size, | | 346 | arm32_bootmem_init(bootconfig.dram[0].address, ram_size, |
333 | KERNEL_BASE_PHYS); | | 347 | KERNEL_BASE_PHYS); |
334 | arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0, devmap, | | 348 | arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0, devmap, |
335 | mapallmem_p); | | 349 | mapallmem_p); |
336 | | | 350 | |
337 | const int chosen = OF_finddevice("/chosen"); | | 351 | const int chosen = OF_finddevice("/chosen"); |
338 | if (chosen >= 0) { | | 352 | if (chosen >= 0) { |
339 | OF_getprop(chosen, "bootargs", bootargs, sizeof(bootargs)); | | 353 | OF_getprop(chosen, "bootargs", bootargs, sizeof(bootargs)); |
340 | } | | 354 | } |
341 | | | 355 | |
342 | DPRINTF("bootargs: %s\n", bootargs); | | 356 | DPRINTF("bootargs: %s\n", bootargs); |
343 | | | 357 | |
344 | boot_args = bootargs; | | 358 | boot_args = bootargs; |
345 | parse_mi_bootargs(boot_args); | | 359 | parse_mi_bootargs(boot_args); |
346 | | | 360 | |
347 | evbarm_device_register = tegra_device_register; | | 361 | evbarm_device_register = tegra_device_register; |
348 | | | 362 | |
349 | #ifdef PMAP_NEED_ALLOC_POOLPAGE | | 363 | #ifdef PMAP_NEED_ALLOC_POOLPAGE |
350 | if (atop(ram_size) > bp_lowgig.bp_pages) { | | 364 | if (atop(ram_size) > bp_lowgig.bp_pages) { |
351 | arm_poolpage_vmfreelist = bp_lowgig.bp_freelist; | | 365 | arm_poolpage_vmfreelist = bp_lowgig.bp_freelist; |
352 | return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, | | 366 | return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, |
353 | &bp_lowgig, 1); | | 367 | &bp_lowgig, 1); |
354 | } | | 368 | } |
355 | #endif | | 369 | #endif |
356 | | | 370 | |
357 | return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0); | | 371 | return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0); |
358 | | | 372 | |
359 | } | | 373 | } |
360 | | | 374 | |
361 | #if NCOM > 0 | | 375 | #if NCOM > 0 |
362 | #ifndef CONSADDR | | 376 | #ifndef CONSADDR |
363 | #error Specify the address of the console UART with the CONSADDR option. | | 377 | #error Specify the address of the console UART with the CONSADDR option. |
364 | #endif | | 378 | #endif |
365 | #ifndef CONSPEED | | 379 | #ifndef CONSPEED |
366 | #define CONSPEED 115200 | | 380 | #define CONSPEED 115200 |
367 | #endif | | 381 | #endif |
368 | #ifndef CONMODE | | 382 | #ifndef CONMODE |
369 | #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ | | 383 | #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ |
370 | #endif | | 384 | #endif |
371 | #endif | | 385 | #endif |
372 | | | 386 | |
373 | void | | 387 | void |
374 | consinit(void) | | 388 | consinit(void) |
375 | { | | 389 | { |
376 | static bool consinit_called = false; | | 390 | static bool consinit_called = false; |
377 | | | 391 | |
378 | if (consinit_called) | | 392 | if (consinit_called) |
379 | return; | | 393 | return; |
380 | consinit_called = true; | | 394 | consinit_called = true; |
381 | | | 395 | |
382 | #if NCOM > 0 | | 396 | #if NCOM > 0 |
383 | const bus_space_tag_t bst = &armv7_generic_a4x_bs_tag; | | 397 | const bus_space_tag_t bst = &armv7_generic_a4x_bs_tag; |
384 | const u_int freq = 408000000; /* 408MHz PLLP_OUT0 */ | | 398 | const u_int freq = 408000000; /* 408MHz PLLP_OUT0 */ |
385 | if (comcnattach(bst, CONSADDR, CONSPEED, freq, | | 399 | if (comcnattach(bst, CONSADDR, CONSPEED, freq, |
386 | COM_TYPE_TEGRA, CONMODE)) { | | 400 | COM_TYPE_TEGRA, CONMODE)) { |
387 | panic("Serial console cannot be initialized."); | | 401 | panic("Serial console cannot be initialized."); |
388 | } | | 402 | } |
389 | #else | | 403 | #else |
390 | #error only COM console is supported | | 404 | #error only COM console is supported |
391 | #endif | | 405 | #endif |
392 | } | | 406 | } |
393 | | | 407 | |
394 | static bool | | 408 | static bool |
395 | tegra_bootconf_match(const char *key, const char *val) | | 409 | tegra_bootconf_match(const char *key, const char *val) |
396 | { | | 410 | { |
397 | char *s; | | 411 | char *s; |
398 | | | 412 | |
399 | if (!get_bootconf_option(boot_args, key, BOOTOPT_TYPE_STRING, &s)) | | 413 | if (!get_bootconf_option(boot_args, key, BOOTOPT_TYPE_STRING, &s)) |
400 | return false; | | 414 | return false; |
401 | | | 415 | |
402 | return strncmp(s, val, strlen(val)) == 0; | | 416 | return strncmp(s, val, strlen(val)) == 0; |
403 | } | | 417 | } |
404 | | | 418 | |
405 | static char * | | 419 | static char * |
406 | tegra_bootconf_strdup(const char *key) | | 420 | tegra_bootconf_strdup(const char *key) |
407 | { | | 421 | { |
408 | char *s, *ret; | | 422 | char *s, *ret; |
409 | int i = 0; | | 423 | int i = 0; |
410 | | | 424 | |
411 | if (!get_bootconf_option(boot_args, key, BOOTOPT_TYPE_STRING, &s)) | | 425 | if (!get_bootconf_option(boot_args, key, BOOTOPT_TYPE_STRING, &s)) |
412 | return NULL; | | 426 | return NULL; |
413 | | | 427 | |
414 | for (;;) { | | 428 | for (;;) { |
415 | if (s[i] == ' ' || s[i] == '\t' || s[i] == '\0') | | 429 | if (s[i] == ' ' || s[i] == '\t' || s[i] == '\0') |
416 | break; | | 430 | break; |
417 | ++i; | | 431 | ++i; |
418 | } | | 432 | } |
419 | | | 433 | |
420 | ret = kmem_alloc(i + 1, KM_SLEEP); | | 434 | ret = kmem_alloc(i + 1, KM_SLEEP); |
421 | if (ret == NULL) | | 435 | if (ret == NULL) |
422 | return NULL; | | 436 | return NULL; |
423 | | | 437 | |
424 | strlcpy(ret, s, i + 1); | | 438 | strlcpy(ret, s, i + 1); |
425 | return ret; | | 439 | return ret; |
426 | } | | 440 | } |
427 | | | 441 | |
428 | void | | 442 | void |
429 | tegra_device_register(device_t self, void *aux) | | 443 | tegra_device_register(device_t self, void *aux) |
430 | { | | 444 | { |
431 | prop_dictionary_t dict = device_properties(self); | | 445 | prop_dictionary_t dict = device_properties(self); |
432 | | | 446 | |
433 | if (device_is_a(self, "armperiph") | | 447 | if (device_is_a(self, "armperiph") |
434 | && device_is_a(device_parent(self), "mainbus")) { | | 448 | && device_is_a(device_parent(self), "mainbus")) { |
435 | struct mainbus_attach_args * const mb = aux; | | 449 | struct mainbus_attach_args * const mb = aux; |
436 | mb->mb_iot = &armv7_generic_bs_tag; | | 450 | mb->mb_iot = &armv7_generic_bs_tag; |
437 | return; | | 451 | return; |
438 | } | | 452 | } |
439 | | | 453 | |
440 | if (device_is_a(self, "armgtmr")) { | | 454 | if (device_is_a(self, "armgtmr")) { |
441 | prop_dictionary_set_uint32(dict, "frequency", TEGRA_REF_FREQ); | | 455 | prop_dictionary_set_uint32(dict, "frequency", TEGRA_REF_FREQ); |
442 | return; | | 456 | return; |
443 | } | | 457 | } |
444 | | | 458 | |
445 | if (device_is_a(self, "tegrafb") | | 459 | if (device_is_a(self, "tegrafb") |
446 | && tegra_bootconf_match("console", "fb")) { | | 460 | && tegra_bootconf_match("console", "fb")) { |
447 | prop_dictionary_set_bool(dict, "is_console", true); | | 461 | prop_dictionary_set_bool(dict, "is_console", true); |
448 | #if NUKBD > 0 | | 462 | #if NUKBD > 0 |
449 | ukbd_cnattach(); | | 463 | ukbd_cnattach(); |
450 | #endif | | 464 | #endif |
451 | } | | 465 | } |
452 | | | 466 | |
453 | if (device_is_a(self, "tegradrm")) { | | 467 | if (device_is_a(self, "tegradrm")) { |
454 | const char *video = tegra_bootconf_strdup("video"); | | 468 | const char *video = tegra_bootconf_strdup("video"); |
455 | | | 469 | |
456 | if (tegra_bootconf_match("hdmi.forcemode", "dvi")) { | | 470 | if (tegra_bootconf_match("hdmi.forcemode", "dvi")) { |
457 | prop_dictionary_set_bool(dict, "force-dvi", true); | | 471 | prop_dictionary_set_bool(dict, "force-dvi", true); |
458 | } | | 472 | } |
459 | | | 473 | |
460 | if (video) { | | 474 | if (video) { |
461 | prop_dictionary_set_cstring(dict, "HDMI-A-1", video); | | 475 | prop_dictionary_set_cstring(dict, "HDMI-A-1", video); |
462 | } | | 476 | } |
463 | } | | 477 | } |
464 | | | 478 | |
465 | if (device_is_a(self, "tegracec")) { | | 479 | if (device_is_a(self, "tegracec")) { |
466 | prop_dictionary_set_cstring(dict, "hdmi-device", "tegradrm0"); | | 480 | prop_dictionary_set_cstring(dict, "hdmi-device", "tegradrm0"); |
467 | } | | 481 | } |
468 | | | 482 | |
469 | if (device_is_a(self, "nouveau")) { | | 483 | if (device_is_a(self, "nouveau")) { |
470 | const char *config = tegra_bootconf_strdup("nouveau.config"); | | 484 | const char *config = tegra_bootconf_strdup("nouveau.config"); |
471 | const char *debug = tegra_bootconf_strdup("nouveau.debug"); | | 485 | const char *debug = tegra_bootconf_strdup("nouveau.debug"); |
472 | if (config) | | 486 | if (config) |
473 | prop_dictionary_set_cstring(dict, "config", config); | | 487 | prop_dictionary_set_cstring(dict, "config", config); |
474 | if (debug) | | 488 | if (debug) |
475 | prop_dictionary_set_cstring(dict, "debug", debug); | | 489 | prop_dictionary_set_cstring(dict, "debug", debug); |
476 | } | | 490 | } |
477 | | | 491 | |
478 | if (device_is_a(self, "tegrapcie")) { | | 492 | if (device_is_a(self, "tegrapcie")) { |
479 | const char * const jetsontk1_compat[] = { | | 493 | const char * const jetsontk1_compat[] = { |
480 | "nvidia,jetson-tk1", NULL | | 494 | "nvidia,jetson-tk1", NULL |
481 | }; | | 495 | }; |
482 | int phandle = OF_peer(0); | | 496 | int phandle = OF_peer(0); |
483 | if (of_match_compatible(phandle, jetsontk1_compat)) { | | 497 | if (of_match_compatible(phandle, jetsontk1_compat)) { |
484 | /* rfkill GPIO at GPIO X7 */ | | 498 | /* rfkill GPIO at GPIO X7 */ |
485 | struct tegra_gpio_pin *pin; | | 499 | struct tegra_gpio_pin *pin; |
486 | pin = tegra_gpio_acquire("X7", GPIO_PIN_OUTPUT); | | 500 | pin = tegra_gpio_acquire("X7", GPIO_PIN_OUTPUT); |
487 | if (pin) { | | 501 | if (pin) { |
488 | tegra_gpio_write(pin, 1); | | 502 | tegra_gpio_write(pin, 1); |
489 | } | | 503 | } |
490 | } | | 504 | } |
491 | } | | 505 | } |
492 | } | | 506 | } |
493 | | | 507 | |
494 | static void | | 508 | static void |
495 | tegra_reset(void) | | 509 | tegra_reset(void) |
496 | { | | 510 | { |
497 | #if NAS3722PMIC > 0 | | 511 | #if NAS3722PMIC > 0 |
498 | device_t pmic = device_find_by_driver_unit("as3722pmic", 0); | | 512 | device_t pmic = device_find_by_driver_unit("as3722pmic", 0); |
499 | if (pmic != NULL) { | | 513 | if (pmic != NULL) { |
500 | delay(1000000); | | 514 | delay(1000000); |
501 | if (as3722_reboot(pmic) != 0) { | | 515 | if (as3722_reboot(pmic) != 0) { |
502 | printf("WARNING: AS3722 reset failed\n"); | | 516 | printf("WARNING: AS3722 reset failed\n"); |
503 | return; | | 517 | return; |
504 | } | | 518 | } |
505 | } | | 519 | } |
506 | #endif | | 520 | #endif |
507 | tegra_pmc_reset(); | | 521 | tegra_pmc_reset(); |
508 | } | | 522 | } |
509 | | | 523 | |
510 | static void | | 524 | static void |
511 | tegra_powerdown(void) | | 525 | tegra_powerdown(void) |
512 | { | | 526 | { |
513 | #if NAS3722PMIC > 0 | | 527 | #if NAS3722PMIC > 0 |
514 | device_t pmic = device_find_by_driver_unit("as3722pmic", 0); | | 528 | device_t pmic = device_find_by_driver_unit("as3722pmic", 0); |
515 | if (pmic != NULL) { | | 529 | if (pmic != NULL) { |
516 | delay(1000000); | | 530 | delay(1000000); |
517 | if (as3722_poweroff(pmic) != 0) { | | 531 | if (as3722_poweroff(pmic) != 0) { |
518 | printf("WARNING: AS3722 poweroff failed\n"); | | 532 | printf("WARNING: AS3722 poweroff failed\n"); |
519 | return; | | 533 | return; |
520 | } | | 534 | } |
521 | } | | 535 | } |
522 | #endif | | 536 | #endif |
523 | } | | 537 | } |