Wed Jun 14 04:54:21 2017 UTC ()
Pull up following revision(s) (requested by jmcneill in ticket #31):
	sys/arch/evbarm/fdt/fdt_machdep.c: revision 1.7
Parse more than one entry from the /memory node's reg property.


(snj)
diff -r1.4.2.1 -r1.4.2.2 src/sys/arch/evbarm/fdt/fdt_machdep.c

cvs diff -r1.4.2.1 -r1.4.2.2 src/sys/arch/evbarm/fdt/fdt_machdep.c (switch to unified diff)

--- src/sys/arch/evbarm/fdt/fdt_machdep.c 2017/06/06 16:26:53 1.4.2.1
+++ src/sys/arch/evbarm/fdt/fdt_machdep.c 2017/06/14 04:54:21 1.4.2.2
@@ -1,356 +1,382 @@ @@ -1,356 +1,382 @@
1/* $NetBSD: fdt_machdep.c,v 1.4.2.1 2017/06/06 16:26:53 snj Exp $ */ 1/* $NetBSD: fdt_machdep.c,v 1.4.2.2 2017/06/14 04:54:21 snj Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2015-2017 Jared McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2015-2017 Jared 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: fdt_machdep.c,v 1.4.2.1 2017/06/06 16:26:53 snj Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.4.2.2 2017/06/14 04:54:21 snj Exp $");
31 31
32#include "opt_machdep.h" 32#include "opt_machdep.h"
33#include "opt_ddb.h" 33#include "opt_ddb.h"
34#include "opt_md.h" 34#include "opt_md.h"
35#include "opt_arm_debug.h" 35#include "opt_arm_debug.h"
36#include "opt_multiprocessor.h" 36#include "opt_multiprocessor.h"
37#include "opt_cpuoptions.h" 37#include "opt_cpuoptions.h"
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/systm.h> 40#include <sys/systm.h>
41#include <sys/bus.h> 41#include <sys/bus.h>
42#include <sys/atomic.h> 42#include <sys/atomic.h>
43#include <sys/cpu.h> 43#include <sys/cpu.h>
44#include <sys/device.h> 44#include <sys/device.h>
45#include <sys/exec.h> 45#include <sys/exec.h>
46#include <sys/kernel.h> 46#include <sys/kernel.h>
47#include <sys/kmem.h> 47#include <sys/kmem.h>
48#include <sys/ksyms.h> 48#include <sys/ksyms.h>
49#include <sys/msgbuf.h> 49#include <sys/msgbuf.h>
50#include <sys/proc.h> 50#include <sys/proc.h>
51#include <sys/reboot.h> 51#include <sys/reboot.h>
52#include <sys/termios.h> 52#include <sys/termios.h>
53 53
54#include <uvm/uvm_extern.h> 54#include <uvm/uvm_extern.h>
55 55
56#include <sys/conf.h> 56#include <sys/conf.h>
57 57
58#include <machine/db_machdep.h> 58#include <machine/db_machdep.h>
59#include <ddb/db_sym.h> 59#include <ddb/db_sym.h>
60#include <ddb/db_extern.h> 60#include <ddb/db_extern.h>
61 61
62#include <machine/bootconfig.h> 62#include <machine/bootconfig.h>
63#include <arm/armreg.h> 63#include <arm/armreg.h>
64#include <arm/undefined.h> 64#include <arm/undefined.h>
65 65
66#include <arm/arm32/machdep.h> 66#include <arm/arm32/machdep.h>
67 67
68#include <evbarm/include/autoconf.h> 68#include <evbarm/include/autoconf.h>
69#include <evbarm/fdt/platform.h> 69#include <evbarm/fdt/platform.h>
70 70
71#include <arm/fdt/arm_fdtvar.h> 71#include <arm/fdt/arm_fdtvar.h>
72 72
73#ifndef FDT_MAX_BOOT_STRING 73#ifndef FDT_MAX_BOOT_STRING
74#define FDT_MAX_BOOT_STRING 1024 74#define FDT_MAX_BOOT_STRING 1024
75#endif 75#endif
76 76
77BootConfig bootconfig; 77BootConfig bootconfig;
78char bootargs[FDT_MAX_BOOT_STRING] = ""; 78char bootargs[FDT_MAX_BOOT_STRING] = "";
79char *boot_args = NULL; 79char *boot_args = NULL;
80u_int uboot_args[4] = { 0 }; /* filled in by xxx_start.S (not in bss) */ 80u_int uboot_args[4] = { 0 }; /* filled in by xxx_start.S (not in bss) */
81 81
82#include <libfdt.h> 82#include <libfdt.h>
83#include <dev/fdt/fdtvar.h> 83#include <dev/fdt/fdtvar.h>
84#define FDT_BUF_SIZE (128*1024) 84#define FDT_BUF_SIZE (128*1024)
85static uint8_t fdt_data[FDT_BUF_SIZE]; 85static uint8_t fdt_data[FDT_BUF_SIZE];
86 86
87extern char KERNEL_BASE_phys[]; 87extern char KERNEL_BASE_phys[];
88#define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys) 88#define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys)
89 89
90static void fdt_update_stdout_path(void); 90static void fdt_update_stdout_path(void);
91static void fdt_device_register(device_t, void *); 91static void fdt_device_register(device_t, void *);
92static void fdt_reset(void); 92static void fdt_reset(void);
93static void fdt_powerdown(void); 93static void fdt_powerdown(void);
94 94
95#ifdef PMAP_NEED_ALLOC_POOLPAGE 95#ifdef PMAP_NEED_ALLOC_POOLPAGE
96static struct boot_physmem bp_lowgig = { 96static struct boot_physmem bp_lowgig = {
97 .bp_pages = (KERNEL_VM_BASE - KERNEL_BASE) / NBPG, 97 .bp_pages = (KERNEL_VM_BASE - KERNEL_BASE) / NBPG,
98 .bp_freelist = VM_FREELIST_ISADMA, 98 .bp_freelist = VM_FREELIST_ISADMA,
99 .bp_flags = 0 99 .bp_flags = 0
100}; 100};
101#endif 101#endif
102 102
103#ifdef VERBOSE_INIT_ARM 103#ifdef VERBOSE_INIT_ARM
104static void 104static void
105fdt_putchar(char c) 105fdt_putchar(char c)
106{ 106{
107 const struct arm_platform *plat = arm_fdt_platform(); 107 const struct arm_platform *plat = arm_fdt_platform();
108 if (plat && plat->early_putchar) 108 if (plat && plat->early_putchar)
109 plat->early_putchar(c); 109 plat->early_putchar(c);
110} 110}
111 111
112static void 112static void
113fdt_putstr(const char *s) 113fdt_putstr(const char *s)
114{ 114{
115 for (const char *p = s; *p; p++) 115 for (const char *p = s; *p; p++)
116 fdt_putchar(*p); 116 fdt_putchar(*p);
117} 117}
118 118
119static void 119static void
120fdt_printn(u_int n, int base) 120fdt_printn(u_int n, int base)
121{ 121{
122 char *p, buf[(sizeof(u_int) * NBBY / 3) + 1 + 2 /* ALT + SIGN */]; 122 char *p, buf[(sizeof(u_int) * NBBY / 3) + 1 + 2 /* ALT + SIGN */];
123 123
124 p = buf; 124 p = buf;
125 do { 125 do {
126 *p++ = hexdigits[n % base]; 126 *p++ = hexdigits[n % base];
127 } while (n /= base); 127 } while (n /= base);
128 128
129 do { 129 do {
130 fdt_putchar(*--p); 130 fdt_putchar(*--p);
131 } while (p > buf); 131 } while (p > buf);
132} 132}
133#define DPRINTF(...) printf(__VA_ARGS__) 133#define DPRINTF(...) printf(__VA_ARGS__)
134#define DPRINT(x) fdt_putstr(x) 134#define DPRINT(x) fdt_putstr(x)
135#define DPRINTN(x,b) fdt_printn((x), (b)) 135#define DPRINTN(x,b) fdt_printn((x), (b))
136#else 136#else
137#define DPRINTF(...) 137#define DPRINTF(...)
138#define DPRINT(x) 138#define DPRINT(x)
139#define DPRINTN(x,b) 139#define DPRINTN(x,b)
140#endif 140#endif
141 141
 142/*
 143 * Get the first physically contiguous region of memory.
 144 */
 145static void
 146fdt_get_memory(uint64_t *paddr, uint64_t *psize)
 147{
 148 const int memory = OF_finddevice("/memory");
 149 uint64_t cur_addr, cur_size;
 150 int index;
 151
 152 /* Assume the first entry is the start of memory */
 153 if (fdtbus_get_reg64(memory, 0, paddr, psize) != 0)
 154 panic("Cannot determine memory size");
 155
 156 DPRINTF("FDT /memory [%d] @ 0x%" PRIx64 " size 0x%" PRIx64 "\n",
 157 0, *paddr, *psize);
 158
 159 /* If subsequent entries follow the previous one, append them. */
 160 for (index = 1;
 161 fdtbus_get_reg64(memory, index, &cur_addr, &cur_size) == 0;
 162 index++) {
 163 DPRINTF("FDT /memory [%d] @ 0x%" PRIx64 " size 0x%" PRIx64 "\n",
 164 index, cur_addr, cur_size);
 165 if (*paddr + *psize == cur_addr)
 166 *psize += cur_size;
 167 }
 168}
 169
142u_int 170u_int
143initarm(void *arg) 171initarm(void *arg)
144{ 172{
145 const struct arm_platform *plat; 173 const struct arm_platform *plat;
146 uint64_t memory_addr, memory_size; 174 uint64_t memory_addr, memory_size;
147 psize_t ram_size = 0; 175 psize_t ram_size = 0;
148 176
149 /* Load FDT */ 177 /* Load FDT */
150 const uint8_t *fdt_addr_r = (const uint8_t *)uboot_args[2]; 178 const uint8_t *fdt_addr_r = (const uint8_t *)uboot_args[2];
151 int error = fdt_check_header(fdt_addr_r); 179 int error = fdt_check_header(fdt_addr_r);
152 if (error == 0) { 180 if (error == 0) {
153 error = fdt_move(fdt_addr_r, fdt_data, sizeof(fdt_data)); 181 error = fdt_move(fdt_addr_r, fdt_data, sizeof(fdt_data));
154 if (error != 0) 182 if (error != 0)
155 panic("fdt_move failed: %s", fdt_strerror(error)); 183 panic("fdt_move failed: %s", fdt_strerror(error));
156 fdtbus_set_data(fdt_data); 184 fdtbus_set_data(fdt_data);
157 } else { 185 } else {
158 panic("fdt_check_header failed: %s", fdt_strerror(error)); 186 panic("fdt_check_header failed: %s", fdt_strerror(error));
159 } 187 }
160 188
161 /* Lookup platform specific backend */ 189 /* Lookup platform specific backend */
162 plat = arm_fdt_platform(); 190 plat = arm_fdt_platform();
163 if (plat == NULL) 191 if (plat == NULL)
164 panic("Kernel does not support this device"); 192 panic("Kernel does not support this device");
165 193
166 /* Early console may be available, announce ourselves. */ 194 /* Early console may be available, announce ourselves. */
167 DPRINT("FDT<"); 195 DPRINT("FDT<");
168 DPRINTN((uintptr_t)fdt_addr_r, 16); 196 DPRINTN((uintptr_t)fdt_addr_r, 16);
169 DPRINT(">"); 197 DPRINT(">");
170 198
171 const int chosen = OF_finddevice("/chosen"); 199 const int chosen = OF_finddevice("/chosen");
172 if (chosen >= 0) 200 if (chosen >= 0)
173 OF_getprop(chosen, "bootargs", bootargs, sizeof(bootargs)); 201 OF_getprop(chosen, "bootargs", bootargs, sizeof(bootargs));
174 boot_args = bootargs; 202 boot_args = bootargs;
175 203
176 DPRINT(" devmap"); 204 DPRINT(" devmap");
177 pmap_devmap_register(plat->devmap()); 205 pmap_devmap_register(plat->devmap());
178 206
179 DPRINT(" bootstrap"); 207 DPRINT(" bootstrap");
180 plat->bootstrap(); 208 plat->bootstrap();
181 209
182 /* Heads up ... Setup the CPU / MMU / TLB functions. */ 210 /* Heads up ... Setup the CPU / MMU / TLB functions. */
183 DPRINT(" cpufunc"); 211 DPRINT(" cpufunc");
184 if (set_cpufuncs()) 212 if (set_cpufuncs())
185 panic("cpu not recognized!"); 213 panic("cpu not recognized!");
186 214
187 /* 215 /*
188 * If stdout-path is specified on the command line, override the 216 * If stdout-path is specified on the command line, override the
189 * value in /chosen/stdout-path before initializing console. 217 * value in /chosen/stdout-path before initializing console.
190 */ 218 */
191 fdt_update_stdout_path(); 219 fdt_update_stdout_path();
192 220
193 DPRINT(" consinit"); 221 DPRINT(" consinit");
194 consinit(); 222 consinit();
195 223
196 DPRINTF(" ok\n"); 224 DPRINTF(" ok\n");
197 225
198 DPRINTF("uboot: args %#x, %#x, %#x, %#x\n", 226 DPRINTF("uboot: args %#x, %#x, %#x, %#x\n",
199 uboot_args[0], uboot_args[1], uboot_args[2], uboot_args[3]); 227 uboot_args[0], uboot_args[1], uboot_args[2], uboot_args[3]);
200 228
201 cpu_reset_address = fdt_reset; 229 cpu_reset_address = fdt_reset;
202 cpu_powerdown_address = fdt_powerdown; 230 cpu_powerdown_address = fdt_powerdown;
203 evbarm_device_register = fdt_device_register; 231 evbarm_device_register = fdt_device_register;
204 232
205 /* Talk to the user */ 233 /* Talk to the user */
206 DPRINTF("\nNetBSD/evbarm (fdt) booting ...\n"); 234 DPRINTF("\nNetBSD/evbarm (fdt) booting ...\n");
207 235
208#ifdef BOOT_ARGS 236#ifdef BOOT_ARGS
209 char mi_bootargs[] = BOOT_ARGS; 237 char mi_bootargs[] = BOOT_ARGS;
210 parse_mi_bootargs(mi_bootargs); 238 parse_mi_bootargs(mi_bootargs);
211#endif 239#endif
212 240
213 DPRINTF("KERNEL_BASE=0x%x, " 241 DPRINTF("KERNEL_BASE=0x%x, "
214 "KERNEL_VM_BASE=0x%x, " 242 "KERNEL_VM_BASE=0x%x, "
215 "KERNEL_VM_BASE - KERNEL_BASE=0x%x, " 243 "KERNEL_VM_BASE - KERNEL_BASE=0x%x, "
216 "KERNEL_BASE_VOFFSET=0x%x\n", 244 "KERNEL_BASE_VOFFSET=0x%x\n",
217 KERNEL_BASE, 245 KERNEL_BASE,
218 KERNEL_VM_BASE, 246 KERNEL_VM_BASE,
219 KERNEL_VM_BASE - KERNEL_BASE, 247 KERNEL_VM_BASE - KERNEL_BASE,
220 KERNEL_BASE_VOFFSET); 248 KERNEL_BASE_VOFFSET);
221 249
222 const int memory = OF_finddevice("/memory"); 250 fdt_get_memory(&memory_addr, &memory_size);
223 if (fdtbus_get_reg64(memory, 0, &memory_addr, &memory_size) != 0) 
224 panic("Cannot determine memory size"); 
225 251
226#if !defined(_LP64) 252#if !defined(_LP64)
227 /* Cannot map memory above 4GB */ 253 /* Cannot map memory above 4GB */
228 if (memory_addr + memory_size > 0x100000000) 254 if (memory_addr + memory_size > 0x100000000)
229 memory_size = 0x100000000 - memory_addr; 255 memory_size = 0x100000000 - memory_addr;
230#endif 256#endif
231 257
232 ram_size = (bus_size_t)memory_size; 258 ram_size = (bus_size_t)memory_size;
233 259
234#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS 260#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
235 const bool mapallmem_p = true; 261 const bool mapallmem_p = true;
236#ifndef PMAP_NEED_ALLOC_POOLPAGE 262#ifndef PMAP_NEED_ALLOC_POOLPAGE
237 if (ram_size > KERNEL_VM_BASE - KERNEL_BASE) { 263 if (ram_size > KERNEL_VM_BASE - KERNEL_BASE) {
238 DPRINTF("%s: dropping RAM size from %luMB to %uMB\n", 264 DPRINTF("%s: dropping RAM size from %luMB to %uMB\n",
239 __func__, (unsigned long) (ram_size >> 20),  265 __func__, (unsigned long) (ram_size >> 20),
240 (KERNEL_VM_BASE - KERNEL_BASE) >> 20); 266 (KERNEL_VM_BASE - KERNEL_BASE) >> 20);
241 ram_size = KERNEL_VM_BASE - KERNEL_BASE; 267 ram_size = KERNEL_VM_BASE - KERNEL_BASE;
242 } 268 }
243#endif 269#endif
244#else 270#else
245 const bool mapallmem_p = false; 271 const bool mapallmem_p = false;
246#endif 272#endif
247 273
248 /* Fake bootconfig structure for the benefit of pmap.c. */ 274 /* Fake bootconfig structure for the benefit of pmap.c. */
249 bootconfig.dramblocks = 1; 275 bootconfig.dramblocks = 1;
250 bootconfig.dram[0].address = (bus_addr_t)memory_addr; 276 bootconfig.dram[0].address = (bus_addr_t)memory_addr;
251 bootconfig.dram[0].pages = ram_size / PAGE_SIZE; 277 bootconfig.dram[0].pages = ram_size / PAGE_SIZE;
252 278
253 arm32_bootmem_init(bootconfig.dram[0].address, ram_size, 279 arm32_bootmem_init(bootconfig.dram[0].address, ram_size,
254 KERNEL_BASE_PHYS); 280 KERNEL_BASE_PHYS);
255 arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0, 281 arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0,
256 plat->devmap(), mapallmem_p); 282 plat->devmap(), mapallmem_p);
257 283
258 DPRINTF("bootargs: %s\n", bootargs); 284 DPRINTF("bootargs: %s\n", bootargs);
259 285
260 parse_mi_bootargs(boot_args); 286 parse_mi_bootargs(boot_args);
261 287
262#ifdef PMAP_NEED_ALLOC_POOLPAGE 288#ifdef PMAP_NEED_ALLOC_POOLPAGE
263 bp_lowgig.bp_start = memory_addr / NBPG; 289 bp_lowgig.bp_start = memory_addr / NBPG;
264 if (atop(ram_size) > bp_lowgig.bp_pages) { 290 if (atop(ram_size) > bp_lowgig.bp_pages) {
265 arm_poolpage_vmfreelist = bp_lowgig.bp_freelist; 291 arm_poolpage_vmfreelist = bp_lowgig.bp_freelist;
266 return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, 292 return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE,
267 &bp_lowgig, 1); 293 &bp_lowgig, 1);
268 } 294 }
269#endif 295#endif
270 296
271 return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0); 297 return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0);
272 298
273} 299}
274 300
275static void 301static void
276fdt_update_stdout_path(void) 302fdt_update_stdout_path(void)
277{ 303{
278 char *stdout_path, *ep; 304 char *stdout_path, *ep;
279 int stdout_path_len; 305 int stdout_path_len;
280 char buf[256]; 306 char buf[256];
281 307
282 const int chosen_off = fdt_path_offset(fdt_data, "/chosen"); 308 const int chosen_off = fdt_path_offset(fdt_data, "/chosen");
283 if (chosen_off == -1) 309 if (chosen_off == -1)
284 return; 310 return;
285 311
286 if (get_bootconf_option(boot_args, "stdout-path", 312 if (get_bootconf_option(boot_args, "stdout-path",
287 BOOTOPT_TYPE_STRING, &stdout_path) == 0) 313 BOOTOPT_TYPE_STRING, &stdout_path) == 0)
288 return; 314 return;
289 315
290 ep = strchr(stdout_path, ' '); 316 ep = strchr(stdout_path, ' ');
291 stdout_path_len = ep ? (ep - stdout_path) : strlen(stdout_path); 317 stdout_path_len = ep ? (ep - stdout_path) : strlen(stdout_path);
292 if (stdout_path_len >= sizeof(buf)) 318 if (stdout_path_len >= sizeof(buf))
293 return; 319 return;
294 320
295 strncpy(buf, stdout_path, stdout_path_len); 321 strncpy(buf, stdout_path, stdout_path_len);
296 buf[stdout_path_len] = '\0'; 322 buf[stdout_path_len] = '\0';
297 fdt_setprop(fdt_data, chosen_off, "stdout-path", 323 fdt_setprop(fdt_data, chosen_off, "stdout-path",
298 buf, stdout_path_len + 1); 324 buf, stdout_path_len + 1);
299} 325}
300 326
301void 327void
302consinit(void) 328consinit(void)
303{ 329{
304 static bool initialized = false; 330 static bool initialized = false;
305 const struct arm_platform *plat = arm_fdt_platform(); 331 const struct arm_platform *plat = arm_fdt_platform();
306 const struct fdt_console *cons = fdtbus_get_console(); 332 const struct fdt_console *cons = fdtbus_get_console();
307 struct fdt_attach_args faa; 333 struct fdt_attach_args faa;
308 u_int uart_freq = 0; 334 u_int uart_freq = 0;
309 335
310 if (initialized || cons == NULL) 336 if (initialized || cons == NULL)
311 return; 337 return;
312 338
313 plat->init_attach_args(&faa); 339 plat->init_attach_args(&faa);
314 faa.faa_phandle = fdtbus_get_stdout_phandle(); 340 faa.faa_phandle = fdtbus_get_stdout_phandle();
315 341
316 if (plat->uart_freq != NULL) 342 if (plat->uart_freq != NULL)
317 uart_freq = plat->uart_freq(); 343 uart_freq = plat->uart_freq();
318 344
319 cons->consinit(&faa, uart_freq); 345 cons->consinit(&faa, uart_freq);
320 346
321 initialized = true; 347 initialized = true;
322} 348}
323 349
324void 350void
325delay(u_int us) 351delay(u_int us)
326{ 352{
327 const struct arm_platform *plat = arm_fdt_platform(); 353 const struct arm_platform *plat = arm_fdt_platform();
328 354
329 plat->delay(us); 355 plat->delay(us);
330} 356}
331 357
332static void 358static void
333fdt_device_register(device_t self, void *aux) 359fdt_device_register(device_t self, void *aux)
334{ 360{
335 const struct arm_platform *plat = arm_fdt_platform(); 361 const struct arm_platform *plat = arm_fdt_platform();
336 362
337 if (plat && plat->device_register) 363 if (plat && plat->device_register)
338 plat->device_register(self, aux); 364 plat->device_register(self, aux);
339} 365}
340 366
341static void 367static void
342fdt_reset(void) 368fdt_reset(void)
343{ 369{
344 const struct arm_platform *plat = arm_fdt_platform(); 370 const struct arm_platform *plat = arm_fdt_platform();
345 371
346 fdtbus_power_reset(); 372 fdtbus_power_reset();
347 373
348 if (plat && plat->reset) 374 if (plat && plat->reset)
349 plat->reset(); 375 plat->reset();
350} 376}
351 377
352static void 378static void
353fdt_powerdown(void) 379fdt_powerdown(void)
354{ 380{
355 fdtbus_power_poweroff(); 381 fdtbus_power_poweroff();
356} 382}