Sun Dec 23 11:45:39 2018 UTC ()
Appease clang.  Tested by roy.


(skrll)
diff -r1.56 -r1.57 src/sys/arch/evbarm/fdt/fdt_machdep.c

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

--- src/sys/arch/evbarm/fdt/fdt_machdep.c 2018/11/28 09:16:19 1.56
+++ src/sys/arch/evbarm/fdt/fdt_machdep.c 2018/12/23 11:45:39 1.57
@@ -1,784 +1,786 @@ @@ -1,784 +1,786 @@
1/* $NetBSD: fdt_machdep.c,v 1.56 2018/11/28 09:16:19 ryo Exp $ */ 1/* $NetBSD: fdt_machdep.c,v 1.57 2018/12/23 11:45:39 skrll 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.56 2018/11/28 09:16:19 ryo Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.57 2018/12/23 11:45:39 skrll Exp $");
31 31
32#include "opt_machdep.h" 32#include "opt_machdep.h"
33#include "opt_bootconfig.h" 33#include "opt_bootconfig.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#include "opt_cpuoptions.h" 38#include "opt_cpuoptions.h"
39#include "opt_efi.h" 39#include "opt_efi.h"
40 40
41#include "ukbd.h" 41#include "ukbd.h"
42#include "wsdisplay.h" 42#include "wsdisplay.h"
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <sys/systm.h> 45#include <sys/systm.h>
46#include <sys/bus.h> 46#include <sys/bus.h>
47#include <sys/atomic.h> 47#include <sys/atomic.h>
48#include <sys/cpu.h> 48#include <sys/cpu.h>
49#include <sys/device.h> 49#include <sys/device.h>
50#include <sys/exec.h> 50#include <sys/exec.h>
51#include <sys/kernel.h> 51#include <sys/kernel.h>
52#include <sys/kmem.h> 52#include <sys/kmem.h>
53#include <sys/ksyms.h> 53#include <sys/ksyms.h>
54#include <sys/msgbuf.h> 54#include <sys/msgbuf.h>
55#include <sys/proc.h> 55#include <sys/proc.h>
56#include <sys/reboot.h> 56#include <sys/reboot.h>
57#include <sys/termios.h> 57#include <sys/termios.h>
58#include <sys/bootblock.h> 58#include <sys/bootblock.h>
59#include <sys/disklabel.h> 59#include <sys/disklabel.h>
60#include <sys/vnode.h> 60#include <sys/vnode.h>
61#include <sys/kauth.h> 61#include <sys/kauth.h>
62#include <sys/fcntl.h> 62#include <sys/fcntl.h>
63#include <sys/uuid.h> 63#include <sys/uuid.h>
64#include <sys/disk.h> 64#include <sys/disk.h>
65#include <sys/md5.h> 65#include <sys/md5.h>
66#include <sys/pserialize.h> 66#include <sys/pserialize.h>
67 67
68#include <net/if.h> 68#include <net/if.h>
69#include <net/if_dl.h> 69#include <net/if_dl.h>
70 70
71#include <dev/cons.h> 71#include <dev/cons.h>
72#include <uvm/uvm_extern.h> 72#include <uvm/uvm_extern.h>
73 73
74#include <sys/conf.h> 74#include <sys/conf.h>
75 75
76#include <machine/db_machdep.h> 76#include <machine/db_machdep.h>
77#include <ddb/db_sym.h> 77#include <ddb/db_sym.h>
78#include <ddb/db_extern.h> 78#include <ddb/db_extern.h>
79 79
80#include <machine/bootconfig.h> 80#include <machine/bootconfig.h>
81#include <arm/armreg.h> 81#include <arm/armreg.h>
82 82
83#include <arm/cpufunc.h> 83#include <arm/cpufunc.h>
84 84
85#include <evbarm/include/autoconf.h> 85#include <evbarm/include/autoconf.h>
86#include <evbarm/fdt/machdep.h> 86#include <evbarm/fdt/machdep.h>
87#include <evbarm/fdt/platform.h> 87#include <evbarm/fdt/platform.h>
88#include <evbarm/fdt/fdt_memory.h> 88#include <evbarm/fdt/fdt_memory.h>
89 89
90#include <arm/fdt/arm_fdtvar.h> 90#include <arm/fdt/arm_fdtvar.h>
91 91
92#ifdef EFI_RUNTIME 92#ifdef EFI_RUNTIME
93#include <arm/arm/efi_runtime.h> 93#include <arm/arm/efi_runtime.h>
94#endif 94#endif
95 95
96#if NUKBD > 0 96#if NUKBD > 0
97#include <dev/usb/ukbdvar.h> 97#include <dev/usb/ukbdvar.h>
98#endif 98#endif
99#if NWSDISPLAY > 0 99#if NWSDISPLAY > 0
100#include <dev/wscons/wsdisplayvar.h> 100#include <dev/wscons/wsdisplayvar.h>
101#endif 101#endif
102 102
103#ifdef MEMORY_DISK_DYNAMIC 103#ifdef MEMORY_DISK_DYNAMIC
104#include <dev/md.h> 104#include <dev/md.h>
105#endif 105#endif
106 106
107#ifndef FDT_MAX_BOOT_STRING 107#ifndef FDT_MAX_BOOT_STRING
108#define FDT_MAX_BOOT_STRING 1024 108#define FDT_MAX_BOOT_STRING 1024
109#endif 109#endif
110 110
111BootConfig bootconfig; 111BootConfig bootconfig;
112char bootargs[FDT_MAX_BOOT_STRING] = ""; 112char bootargs[FDT_MAX_BOOT_STRING] = "";
113char *boot_args = NULL; 113char *boot_args = NULL;
114 114
115/* filled in before cleaning bss. keep in .data */ 115/* filled in before cleaning bss. keep in .data */
116u_long uboot_args[4] __attribute__((__section__(".data"))); 116u_long uboot_args[4] __attribute__((__section__(".data")));
117const uint8_t *fdt_addr_r __attribute__((__section__(".data"))); 117const uint8_t *fdt_addr_r __attribute__((__section__(".data")));
118 118
119static uint64_t initrd_start, initrd_end; 119static uint64_t initrd_start, initrd_end;
120 120
121#include <libfdt.h> 121#include <libfdt.h>
122#include <dev/fdt/fdtvar.h> 122#include <dev/fdt/fdtvar.h>
123#define FDT_BUF_SIZE (512*1024) 123#define FDT_BUF_SIZE (512*1024)
124static uint8_t fdt_data[FDT_BUF_SIZE]; 124static uint8_t fdt_data[FDT_BUF_SIZE];
125 125
126extern char KERNEL_BASE_phys[]; 126extern char KERNEL_BASE_phys[];
127#define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys) 127#define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys)
128 128
129static void fdt_update_stdout_path(void); 129static void fdt_update_stdout_path(void);
130static void fdt_device_register(device_t, void *); 130static void fdt_device_register(device_t, void *);
131static void fdt_device_register_post_config(device_t, void *); 131static void fdt_device_register_post_config(device_t, void *);
132static void fdt_cpu_rootconf(void); 132static void fdt_cpu_rootconf(void);
133static void fdt_reset(void); 133static void fdt_reset(void);
134static void fdt_powerdown(void); 134static void fdt_powerdown(void);
135 135
136static void 136static void
137earlyconsputc(dev_t dev, int c) 137earlyconsputc(dev_t dev, int c)
138{ 138{
139 uartputc(c); 139 uartputc(c);
140} 140}
141 141
142static int 142static int
143earlyconsgetc(dev_t dev) 143earlyconsgetc(dev_t dev)
144{ 144{
145 return 0; 145 return 0;
146} 146}
147 147
148static struct consdev earlycons = { 148static struct consdev earlycons = {
149 .cn_putc = earlyconsputc, 149 .cn_putc = earlyconsputc,
150 .cn_getc = earlyconsgetc, 150 .cn_getc = earlyconsgetc,
151 .cn_pollc = nullcnpollc, 151 .cn_pollc = nullcnpollc,
152}; 152};
153 153
154#ifdef VERBOSE_INIT_ARM 154#ifdef VERBOSE_INIT_ARM
155#define VPRINTF(...) printf(__VA_ARGS__) 155#define VPRINTF(...) printf(__VA_ARGS__)
156#else 156#else
157#define VPRINTF(...) __nothing 157#define VPRINTF(...) __nothing
158#endif 158#endif
159 159
160/* 160/*
161 * ARM: Get the first physically contiguous region of memory. 161 * ARM: Get the first physically contiguous region of memory.
162 * ARM64: Get all of physical memory, including holes. 162 * ARM64: Get all of physical memory, including holes.
163 */ 163 */
164static void 164static void
165fdt_get_memory(uint64_t *pstart, uint64_t *pend) 165fdt_get_memory(uint64_t *pstart, uint64_t *pend)
166{ 166{
167 const int memory = OF_finddevice("/memory"); 167 const int memory = OF_finddevice("/memory");
168 uint64_t cur_addr, cur_size; 168 uint64_t cur_addr, cur_size;
169 int index; 169 int index;
170 170
171 /* Assume the first entry is the start of memory */ 171 /* Assume the first entry is the start of memory */
172 if (fdtbus_get_reg64(memory, 0, &cur_addr, &cur_size) != 0) 172 if (fdtbus_get_reg64(memory, 0, &cur_addr, &cur_size) != 0)
173 panic("Cannot determine memory size"); 173 panic("Cannot determine memory size");
174 174
175 *pstart = cur_addr; 175 *pstart = cur_addr;
176 *pend = cur_addr + cur_size; 176 *pend = cur_addr + cur_size;
177 177
178 VPRINTF("FDT /memory [%d] @ 0x%" PRIx64 " size 0x%" PRIx64 "\n", 178 VPRINTF("FDT /memory [%d] @ 0x%" PRIx64 " size 0x%" PRIx64 "\n",
179 0, *pstart, *pend - *pstart); 179 0, *pstart, *pend - *pstart);
180 180
181 for (index = 1; 181 for (index = 1;
182 fdtbus_get_reg64(memory, index, &cur_addr, &cur_size) == 0; 182 fdtbus_get_reg64(memory, index, &cur_addr, &cur_size) == 0;
183 index++) { 183 index++) {
184 VPRINTF("FDT /memory [%d] @ 0x%" PRIx64 " size 0x%" PRIx64 "\n", 184 VPRINTF("FDT /memory [%d] @ 0x%" PRIx64 " size 0x%" PRIx64 "\n",
185 index, cur_addr, cur_size); 185 index, cur_addr, cur_size);
186 186
187#ifdef __aarch64__ 187#ifdef __aarch64__
188 if (cur_addr + cur_size > *pend) 188 if (cur_addr + cur_size > *pend)
189 *pend = cur_addr + cur_size; 189 *pend = cur_addr + cur_size;
190#else 190#else
191 /* If subsequent entries follow the previous, append them. */ 191 /* If subsequent entries follow the previous, append them. */
192 if (*pend == cur_addr) 192 if (*pend == cur_addr)
193 *pend = cur_addr + cur_size; 193 *pend = cur_addr + cur_size;
194#endif 194#endif
195 } 195 }
196} 196}
197 197
198void 198void
199fdt_add_reserved_memory_range(uint64_t addr, uint64_t size) 199fdt_add_reserved_memory_range(uint64_t addr, uint64_t size)
200{ 200{
201 fdt_memory_remove_range(addr, size); 201 fdt_memory_remove_range(addr, size);
202} 202}
203 203
204/* 204/*
205 * Exclude memory ranges from memory config from the device tree 205 * Exclude memory ranges from memory config from the device tree
206 */ 206 */
207static void 207static void
208fdt_add_reserved_memory(uint64_t min_addr, uint64_t max_addr) 208fdt_add_reserved_memory(uint64_t min_addr, uint64_t max_addr)
209{ 209{
210 uint64_t lstart = 0, lend = 0; 210 uint64_t lstart = 0, lend = 0;
211 uint64_t addr, size; 211 uint64_t addr, size;
212 int index, error; 212 int index, error;
213 213
214 const int num = fdt_num_mem_rsv(fdtbus_get_data()); 214 const int num = fdt_num_mem_rsv(fdtbus_get_data());
215 for (index = 0; index <= num; index++) { 215 for (index = 0; index <= num; index++) {
216 error = fdt_get_mem_rsv(fdtbus_get_data(), index, 216 error = fdt_get_mem_rsv(fdtbus_get_data(), index,
217 &addr, &size); 217 &addr, &size);
218 if (error != 0) 218 if (error != 0)
219 continue; 219 continue;
220 if (lstart <= addr && addr <= lend) { 220 if (lstart <= addr && addr <= lend) {
221 size -= (lend - addr); 221 size -= (lend - addr);
222 addr = lend; 222 addr = lend;
223 } 223 }
224 if (size == 0) 224 if (size == 0)
225 continue; 225 continue;
226 if (addr + size <= min_addr) 226 if (addr + size <= min_addr)
227 continue; 227 continue;
228 if (addr >= max_addr) 228 if (addr >= max_addr)
229 continue; 229 continue;
230 if (addr < min_addr) { 230 if (addr < min_addr) {
231 size -= (min_addr - addr); 231 size -= (min_addr - addr);
232 addr = min_addr; 232 addr = min_addr;
233 } 233 }
234 if (addr + size > max_addr) 234 if (addr + size > max_addr)
235 size = max_addr - addr; 235 size = max_addr - addr;
236 fdt_add_reserved_memory_range(addr, size); 236 fdt_add_reserved_memory_range(addr, size);
237 lstart = addr; 237 lstart = addr;
238 lend = addr + size; 238 lend = addr + size;
239 } 239 }
240} 240}
241 241
242static void 242static void
243fdt_add_dram_blocks(const struct fdt_memory *m, void *arg) 243fdt_add_dram_blocks(const struct fdt_memory *m, void *arg)
244{ 244{
245 BootConfig *bc = arg; 245 BootConfig *bc = arg;
246 246
247 VPRINTF(" %" PRIx64 " - %" PRIx64 "\n", m->start, m->end - 1); 247 VPRINTF(" %" PRIx64 " - %" PRIx64 "\n", m->start, m->end - 1);
248 bc->dram[bc->dramblocks].address = m->start; 248 bc->dram[bc->dramblocks].address = m->start;
249 bc->dram[bc->dramblocks].pages = 249 bc->dram[bc->dramblocks].pages =
250 (m->end - m->start) / PAGE_SIZE; 250 (m->end - m->start) / PAGE_SIZE;
251 bc->dramblocks++; 251 bc->dramblocks++;
252} 252}
253 253
254#define MAX_PHYSMEM 64 254#define MAX_PHYSMEM 64
255static int nfdt_physmem = 0; 255static int nfdt_physmem = 0;
256static struct boot_physmem fdt_physmem[MAX_PHYSMEM]; 256static struct boot_physmem fdt_physmem[MAX_PHYSMEM];
257 257
258static void 258static void
259fdt_add_boot_physmem(const struct fdt_memory *m, void *arg) 259fdt_add_boot_physmem(const struct fdt_memory *m, void *arg)
260{ 260{
261 struct boot_physmem *bp = &fdt_physmem[nfdt_physmem++]; 261 struct boot_physmem *bp = &fdt_physmem[nfdt_physmem++];
262 262
263 VPRINTF(" %" PRIx64 " - %" PRIx64 "\n", m->start, m->end - 1); 263 VPRINTF(" %" PRIx64 " - %" PRIx64 "\n", m->start, m->end - 1);
264 264
265 KASSERT(nfdt_physmem <= MAX_PHYSMEM); 265 KASSERT(nfdt_physmem <= MAX_PHYSMEM);
266 266
267 bp->bp_start = atop(round_page(m->start)); 267 bp->bp_start = atop(round_page(m->start));
268 bp->bp_pages = atop(trunc_page(m->end)) - bp->bp_start; 268 bp->bp_pages = atop(trunc_page(m->end)) - bp->bp_start;
269 bp->bp_freelist = VM_FREELIST_DEFAULT; 269 bp->bp_freelist = VM_FREELIST_DEFAULT;
270 270
271#ifdef _LP64 271#ifdef _LP64
272 if (m->end > 0x100000000) 272 if (m->end > 0x100000000)
273 bp->bp_freelist = VM_FREELIST_HIGHMEM; 273 bp->bp_freelist = VM_FREELIST_HIGHMEM;
274#endif 274#endif
275 275
276#ifdef PMAP_NEED_ALLOC_POOLPAGE 276#ifdef PMAP_NEED_ALLOC_POOLPAGE
277 const uint64_t memory_size = *(uint64_t *)arg; 277 const uint64_t memory_size = *(uint64_t *)arg;
278 if (atop(memory_size) > bp->bp_pages) { 278 if (atop(memory_size) > bp->bp_pages) {
279 arm_poolpage_vmfreelist = VM_FREELIST_DIRECTMAP; 279 arm_poolpage_vmfreelist = VM_FREELIST_DIRECTMAP;
280 bp->bp_freelist = VM_FREELIST_DIRECTMAP; 280 bp->bp_freelist = VM_FREELIST_DIRECTMAP;
281 } 281 }
282#endif 282#endif
283} 283}
284 284
285/* 285/*
286 * Define usable memory regions. 286 * Define usable memory regions.
287 */ 287 */
288static void 288static void
289fdt_build_bootconfig(uint64_t mem_start, uint64_t mem_end) 289fdt_build_bootconfig(uint64_t mem_start, uint64_t mem_end)
290{ 290{
291 const int memory = OF_finddevice("/memory"); 291 const int memory = OF_finddevice("/memory");
292 BootConfig *bc = &bootconfig; 292 BootConfig *bc = &bootconfig;
293 uint64_t addr, size; 293 uint64_t addr, size;
294 int index; 294 int index;
295 295
296 for (index = 0; 296 for (index = 0;
297 fdtbus_get_reg64(memory, index, &addr, &size) == 0; 297 fdtbus_get_reg64(memory, index, &addr, &size) == 0;
298 index++) { 298 index++) {
299 if (addr >= mem_end || size == 0) 299 if (addr >= mem_end || size == 0)
300 continue; 300 continue;
301 if (addr + size > mem_end) 301 if (addr + size > mem_end)
302 size = mem_end - addr; 302 size = mem_end - addr;
303 303
304 fdt_memory_add_range(addr, size); 304 fdt_memory_add_range(addr, size);
305 } 305 }
306 306
307 fdt_add_reserved_memory(mem_start, mem_end); 307 fdt_add_reserved_memory(mem_start, mem_end);
308 308
309 const uint64_t initrd_size = initrd_end - initrd_start; 309 const uint64_t initrd_size = initrd_end - initrd_start;
310 if (initrd_size > 0) 310 if (initrd_size > 0)
311 fdt_memory_remove_range(initrd_start, initrd_size); 311 fdt_memory_remove_range(initrd_start, initrd_size);
312 312
313 const int framebuffer = OF_finddevice("/chosen/framebuffer"); 313 const int framebuffer = OF_finddevice("/chosen/framebuffer");
314 if (framebuffer >= 0) { 314 if (framebuffer >= 0) {
315 for (index = 0; 315 for (index = 0;
316 fdtbus_get_reg64(framebuffer, index, &addr, &size) == 0; 316 fdtbus_get_reg64(framebuffer, index, &addr, &size) == 0;
317 index++) { 317 index++) {
318 fdt_add_reserved_memory_range(addr, size); 318 fdt_add_reserved_memory_range(addr, size);
319 } 319 }
320 } 320 }
321 321
322 VPRINTF("Usable memory:\n"); 322 VPRINTF("Usable memory:\n");
323 bc->dramblocks = 0; 323 bc->dramblocks = 0;
324 fdt_memory_foreach(fdt_add_dram_blocks, bc); 324 fdt_memory_foreach(fdt_add_dram_blocks, bc);
325} 325}
326 326
327static void 327static void
328fdt_probe_initrd(uint64_t *pstart, uint64_t *pend) 328fdt_probe_initrd(uint64_t *pstart, uint64_t *pend)
329{ 329{
330 *pstart = *pend = 0; 330 *pstart = *pend = 0;
331 331
332#ifdef MEMORY_DISK_DYNAMIC 332#ifdef MEMORY_DISK_DYNAMIC
333 const int chosen = OF_finddevice("/chosen"); 333 const int chosen = OF_finddevice("/chosen");
334 if (chosen < 0) 334 if (chosen < 0)
335 return; 335 return;
336 336
337 int len; 337 int len;
338 const void *start_data = fdtbus_get_prop(chosen, 338 const void *start_data = fdtbus_get_prop(chosen,
339 "linux,initrd-start", &len); 339 "linux,initrd-start", &len);
340 const void *end_data = fdtbus_get_prop(chosen, 340 const void *end_data = fdtbus_get_prop(chosen,
341 "linux,initrd-end", NULL); 341 "linux,initrd-end", NULL);
342 if (start_data == NULL || end_data == NULL) 342 if (start_data == NULL || end_data == NULL)
343 return; 343 return;
344 344
345 switch (len) { 345 switch (len) {
346 case 4: 346 case 4:
347 *pstart = be32dec(start_data); 347 *pstart = be32dec(start_data);
348 *pend = be32dec(end_data); 348 *pend = be32dec(end_data);
349 break; 349 break;
350 case 8: 350 case 8:
351 *pstart = be64dec(start_data); 351 *pstart = be64dec(start_data);
352 *pend = be64dec(end_data); 352 *pend = be64dec(end_data);
353 break; 353 break;
354 default: 354 default:
355 printf("Unsupported len %d for /chosen/initrd-start\n", len); 355 printf("Unsupported len %d for /chosen/initrd-start\n", len);
356 return; 356 return;
357 } 357 }
358#endif 358#endif
359} 359}
360 360
361static void 361static void
362fdt_setup_initrd(void) 362fdt_setup_initrd(void)
363{ 363{
364#ifdef MEMORY_DISK_DYNAMIC 364#ifdef MEMORY_DISK_DYNAMIC
365 const uint64_t initrd_size = initrd_end - initrd_start; 365 const uint64_t initrd_size = initrd_end - initrd_start;
366 paddr_t startpa = trunc_page(initrd_start); 366 paddr_t startpa = trunc_page(initrd_start);
367 paddr_t endpa = round_page(initrd_end); 367 paddr_t endpa = round_page(initrd_end);
368 paddr_t pa; 368 paddr_t pa;
369 vaddr_t va; 369 vaddr_t va;
370 void *md_start; 370 void *md_start;
371 371
372 if (initrd_size == 0) 372 if (initrd_size == 0)
373 return; 373 return;
374 374
375 va = uvm_km_alloc(kernel_map, initrd_size, 0, 375 va = uvm_km_alloc(kernel_map, initrd_size, 0,
376 UVM_KMF_VAONLY | UVM_KMF_NOWAIT); 376 UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
377 if (va == 0) { 377 if (va == 0) {
378 printf("Failed to allocate VA for initrd\n"); 378 printf("Failed to allocate VA for initrd\n");
379 return; 379 return;
380 } 380 }
381 381
382 md_start = (void *)va; 382 md_start = (void *)va;
383 383
384 for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) 384 for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE)
385 pmap_kenter_pa(va, pa, VM_PROT_READ|VM_PROT_WRITE, 0); 385 pmap_kenter_pa(va, pa, VM_PROT_READ|VM_PROT_WRITE, 0);
386 pmap_update(pmap_kernel()); 386 pmap_update(pmap_kernel());
387 387
388 md_root_setconf(md_start, initrd_size); 388 md_root_setconf(md_start, initrd_size);
389#endif 389#endif
390} 390}
391 391
392#ifdef EFI_RUNTIME 392#ifdef EFI_RUNTIME
393static void 393static void
394fdt_map_efi_runtime(const char *prop, enum arm_efirt_mem_type type) 394fdt_map_efi_runtime(const char *prop, enum arm_efirt_mem_type type)
395{ 395{
396 int len; 396 int len;
397 397
398 const int chosen_off = fdt_path_offset(fdt_data, "/chosen"); 398 const int chosen_off = fdt_path_offset(fdt_data, "/chosen");
399 if (chosen_off < 0) 399 if (chosen_off < 0)
400 return; 400 return;
401 401
402 const uint64_t *map = fdt_getprop(fdt_data, chosen_off, prop, &len); 402 const uint64_t *map = fdt_getprop(fdt_data, chosen_off, prop, &len);
403 if (map == NULL) 403 if (map == NULL)
404 return; 404 return;
405 405
406 while (len >= 24) { 406 while (len >= 24) {
407 const paddr_t pa = be64toh(map[0]); 407 const paddr_t pa = be64toh(map[0]);
408 const vaddr_t va = be64toh(map[1]); 408 const vaddr_t va = be64toh(map[1]);
409 const uint64_t sz = be64toh(map[2]); 409 const uint64_t sz = be64toh(map[2]);
410 VPRINTF("%s: %s %lx-%lx (%lx-%lx)\n", __func__, prop, pa, pa+sz-1, va, va+sz-1); 410 VPRINTF("%s: %s %lx-%lx (%lx-%lx)\n", __func__, prop, pa, pa+sz-1, va, va+sz-1);
411 arm_efirt_md_map_range(va, pa, sz, type); 411 arm_efirt_md_map_range(va, pa, sz, type);
412 map += 3; 412 map += 3;
413 len -= 24; 413 len -= 24;
414 } 414 }
415} 415}
416#endif 416#endif
417 417
418u_int initarm(void *arg); 418u_int initarm(void *arg);
419 419
420u_int 420u_int
421initarm(void *arg) 421initarm(void *arg)
422{ 422{
423 const struct arm_platform *plat; 423 const struct arm_platform *plat;
424 uint64_t memory_start, memory_end; 424 uint64_t memory_start, memory_end;
425 425
426 /* set temporally to work printf()/panic() even before consinit() */ 426 /* set temporally to work printf()/panic() even before consinit() */
427 cn_tab = &earlycons; 427 cn_tab = &earlycons;
428 428
429 /* Load FDT */ 429 /* Load FDT */
430 int error = fdt_check_header(fdt_addr_r); 430 int error = fdt_check_header(fdt_addr_r);
431 if (error == 0) { 431 if (error == 0) {
432 /* If the DTB is too big, try to pack it in place first. */ 432 /* If the DTB is too big, try to pack it in place first. */
433 if (fdt_totalsize(fdt_addr_r) > sizeof(fdt_data)) 433 if (fdt_totalsize(fdt_addr_r) > sizeof(fdt_data))
434 (void)fdt_pack(__UNCONST(fdt_addr_r)); 434 (void)fdt_pack(__UNCONST(fdt_addr_r));
435 error = fdt_open_into(fdt_addr_r, fdt_data, sizeof(fdt_data)); 435 error = fdt_open_into(fdt_addr_r, fdt_data, sizeof(fdt_data));
436 if (error != 0) 436 if (error != 0)
437 panic("fdt_move failed: %s", fdt_strerror(error)); 437 panic("fdt_move failed: %s", fdt_strerror(error));
438 fdtbus_set_data(fdt_data); 438 fdtbus_set_data(fdt_data);
439 } else { 439 } else {
440 panic("fdt_check_header failed: %s", fdt_strerror(error)); 440 panic("fdt_check_header failed: %s", fdt_strerror(error));
441 } 441 }
442 442
443 /* Lookup platform specific backend */ 443 /* Lookup platform specific backend */
444 plat = arm_fdt_platform(); 444 plat = arm_fdt_platform();
445 if (plat == NULL) 445 if (plat == NULL)
446 panic("Kernel does not support this device"); 446 panic("Kernel does not support this device");
447 447
448 /* Early console may be available, announce ourselves. */ 448 /* Early console may be available, announce ourselves. */
449 VPRINTF("FDT<%p>\n", fdt_addr_r); 449 VPRINTF("FDT<%p>\n", fdt_addr_r);
450 450
451 const int chosen = OF_finddevice("/chosen"); 451 const int chosen = OF_finddevice("/chosen");
452 if (chosen >= 0) 452 if (chosen >= 0)
453 OF_getprop(chosen, "bootargs", bootargs, sizeof(bootargs)); 453 OF_getprop(chosen, "bootargs", bootargs, sizeof(bootargs));
454 boot_args = bootargs; 454 boot_args = bootargs;
455 455
456 /* Heads up ... Setup the CPU / MMU / TLB functions. */ 456 /* Heads up ... Setup the CPU / MMU / TLB functions. */
457 VPRINTF("cpufunc\n"); 457 VPRINTF("cpufunc\n");
458 if (set_cpufuncs()) 458 if (set_cpufuncs())
459 panic("cpu not recognized!"); 459 panic("cpu not recognized!");
460 460
461 /* 461 /*
462 * Memory is still identity/flat mapped this point so using ttbr for 462 * Memory is still identity/flat mapped this point so using ttbr for
463 * l1pt VA is fine 463 * l1pt VA is fine
464 */ 464 */
465 465
466 VPRINTF("devmap\n"); 466 VPRINTF("devmap\n");
467 extern char ARM_BOOTSTRAP_LxPT[]; 467 extern char ARM_BOOTSTRAP_LxPT[];
468 pmap_devmap_bootstrap((vaddr_t)ARM_BOOTSTRAP_LxPT, plat->ap_devmap()); 468 pmap_devmap_bootstrap((vaddr_t)ARM_BOOTSTRAP_LxPT, plat->ap_devmap());
469 469
470 VPRINTF("bootstrap\n"); 470 VPRINTF("bootstrap\n");
471 plat->ap_bootstrap(); 471 plat->ap_bootstrap();
472 472
473 /* 473 /*
474 * If stdout-path is specified on the command line, override the 474 * If stdout-path is specified on the command line, override the
475 * value in /chosen/stdout-path before initializing console. 475 * value in /chosen/stdout-path before initializing console.
476 */ 476 */
477 VPRINTF("stdout\n"); 477 VPRINTF("stdout\n");
478 fdt_update_stdout_path(); 478 fdt_update_stdout_path();
479 479
480 /* 480 /*
481 * Done making changes to the FDT. 481 * Done making changes to the FDT.
482 */ 482 */
483 fdt_pack(fdt_data); 483 fdt_pack(fdt_data);
484 484
485 VPRINTF("consinit "); 485 VPRINTF("consinit ");
486 consinit(); 486 consinit();
487 VPRINTF("ok\n"); 487 VPRINTF("ok\n");
488 488
489 VPRINTF("uboot: args %#lx, %#lx, %#lx, %#lx\n", 489 VPRINTF("uboot: args %#lx, %#lx, %#lx, %#lx\n",
490 uboot_args[0], uboot_args[1], uboot_args[2], uboot_args[3]); 490 uboot_args[0], uboot_args[1], uboot_args[2], uboot_args[3]);
491 491
492 cpu_reset_address = fdt_reset; 492 cpu_reset_address = fdt_reset;
493 cpu_powerdown_address = fdt_powerdown; 493 cpu_powerdown_address = fdt_powerdown;
494 evbarm_device_register = fdt_device_register; 494 evbarm_device_register = fdt_device_register;
495 evbarm_device_register_post_config = fdt_device_register_post_config; 495 evbarm_device_register_post_config = fdt_device_register_post_config;
496 evbarm_cpu_rootconf = fdt_cpu_rootconf; 496 evbarm_cpu_rootconf = fdt_cpu_rootconf;
497 497
498 /* Talk to the user */ 498 /* Talk to the user */
499 printf("NetBSD/evbarm (fdt) booting ...\n"); 499 printf("NetBSD/evbarm (fdt) booting ...\n");
500 500
501#ifdef BOOT_ARGS 501#ifdef BOOT_ARGS
502 char mi_bootargs[] = BOOT_ARGS; 502 char mi_bootargs[] = BOOT_ARGS;
503 parse_mi_bootargs(mi_bootargs); 503 parse_mi_bootargs(mi_bootargs);
504#endif 504#endif
505 505
506 fdt_get_memory(&memory_start, &memory_end); 506 fdt_get_memory(&memory_start, &memory_end);
507 507
508#if !defined(_LP64) 508#if !defined(_LP64)
509 /* Cannot map memory above 4GB */ 509 /* Cannot map memory above 4GB */
510 if (memory_end >= 0x100000000ULL) 510 if (memory_end >= 0x100000000ULL)
511 memory_end = 0x100000000ULL - PAGE_SIZE; 511 memory_end = 0x100000000ULL - PAGE_SIZE;
512 512
513#endif 513#endif
514 uint64_t memory_size = memory_end - memory_start; 514 uint64_t memory_size = memory_end - memory_start;
515 515
516 VPRINTF("%s: memory start %" PRIx64 " end %" PRIx64 " (len %" 516 VPRINTF("%s: memory start %" PRIx64 " end %" PRIx64 " (len %"
517 PRIx64 ")\n", __func__, memory_start, memory_end, memory_size); 517 PRIx64 ")\n", __func__, memory_start, memory_end, memory_size);
518 518
519 /* Parse ramdisk info */ 519 /* Parse ramdisk info */
520 fdt_probe_initrd(&initrd_start, &initrd_end); 520 fdt_probe_initrd(&initrd_start, &initrd_end);
521 521
522 /* 522 /*
523 * Populate bootconfig structure for the benefit of 523 * Populate bootconfig structure for the benefit of
524 * dodumpsys 524 * dodumpsys
525 */ 525 */
526 VPRINTF("%s: fdt_build_bootconfig\n", __func__); 526 VPRINTF("%s: fdt_build_bootconfig\n", __func__);
527 fdt_build_bootconfig(memory_start, memory_end); 527 fdt_build_bootconfig(memory_start, memory_end);
528 528
529#ifdef EFI_RUNTIME 529#ifdef EFI_RUNTIME
530 fdt_map_efi_runtime("netbsd,uefi-runtime-code", ARM_EFIRT_MEM_CODE); 530 fdt_map_efi_runtime("netbsd,uefi-runtime-code", ARM_EFIRT_MEM_CODE);
531 fdt_map_efi_runtime("netbsd,uefi-runtime-data", ARM_EFIRT_MEM_DATA); 531 fdt_map_efi_runtime("netbsd,uefi-runtime-data", ARM_EFIRT_MEM_DATA);
532 fdt_map_efi_runtime("netbsd,uefi-runtime-mmio", ARM_EFIRT_MEM_MMIO); 532 fdt_map_efi_runtime("netbsd,uefi-runtime-mmio", ARM_EFIRT_MEM_MMIO);
533#endif 533#endif
534 534
535 /* Perform PT build and VM init */ 535 /* Perform PT build and VM init */
536 cpu_kernel_vm_init(memory_start, memory_size); 536 cpu_kernel_vm_init(memory_start, memory_size);
537 537
538 VPRINTF("bootargs: %s\n", bootargs); 538 VPRINTF("bootargs: %s\n", bootargs);
539 539
540 parse_mi_bootargs(boot_args); 540 parse_mi_bootargs(boot_args);
541 541
542 VPRINTF("Memory regions:\n"); 542 VPRINTF("Memory regions:\n");
543 fdt_memory_foreach(fdt_add_boot_physmem, &memory_size); 543 fdt_memory_foreach(fdt_add_boot_physmem, &memory_size);
544 544
545 u_int sp = initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, fdt_physmem, 545 u_int sp = initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, fdt_physmem,
546 nfdt_physmem); 546 nfdt_physmem);
547 547
548 if ((boothowto & RB_MD1) == 0) { 548 if ((boothowto & RB_MD1) == 0) {
549 VPRINTF("mpstart\n"); 549 VPRINTF("mpstart\n");
550 if (plat->ap_mpstart) 550 if (plat->ap_mpstart)
551 plat->ap_mpstart(); 551 plat->ap_mpstart();
552 } 552 }
553 553
554 /* 554 /*
555 * Now we have APs started the pages used for stacks and L1PT can 555 * Now we have APs started the pages used for stacks and L1PT can
556 * be given to uvm 556 * be given to uvm
557 */ 557 */
558 extern char __start__init_memory[], __stop__init_memory[]; 558 extern char const __start__init_memory[];
 559 extern char const __stop__init_memory[] __weak;
 560
559 if (__start__init_memory != __stop__init_memory) { 561 if (__start__init_memory != __stop__init_memory) {
560 const paddr_t spa = KERN_VTOPHYS((vaddr_t)__start__init_memory); 562 const paddr_t spa = KERN_VTOPHYS((vaddr_t)__start__init_memory);
561 const paddr_t epa = KERN_VTOPHYS((vaddr_t)__stop__init_memory); 563 const paddr_t epa = KERN_VTOPHYS((vaddr_t)__stop__init_memory);
562 const paddr_t spg = atop(spa); 564 const paddr_t spg = atop(spa);
563 const paddr_t epg = atop(epa); 565 const paddr_t epg = atop(epa);
564 566
565 uvm_page_physload(spg, epg, spg, epg, VM_FREELIST_DEFAULT); 567 uvm_page_physload(spg, epg, spg, epg, VM_FREELIST_DEFAULT);
566 568
567 VPRINTF(" start %08lx end %08lx", ptoa(spa), ptoa(epa)); 569 VPRINTF(" start %08lx end %08lx", ptoa(spa), ptoa(epa));
568 } 570 }
569 571
570 return sp; 572 return sp;
571} 573}
572 574
573static void 575static void
574fdt_update_stdout_path(void) 576fdt_update_stdout_path(void)
575{ 577{
576 char *stdout_path, *ep; 578 char *stdout_path, *ep;
577 int stdout_path_len; 579 int stdout_path_len;
578 char buf[256]; 580 char buf[256];
579 581
580 const int chosen_off = fdt_path_offset(fdt_data, "/chosen"); 582 const int chosen_off = fdt_path_offset(fdt_data, "/chosen");
581 if (chosen_off == -1) 583 if (chosen_off == -1)
582 return; 584 return;
583 585
584 if (get_bootconf_option(boot_args, "stdout-path", 586 if (get_bootconf_option(boot_args, "stdout-path",
585 BOOTOPT_TYPE_STRING, &stdout_path) == 0) 587 BOOTOPT_TYPE_STRING, &stdout_path) == 0)
586 return; 588 return;
587 589
588 ep = strchr(stdout_path, ' '); 590 ep = strchr(stdout_path, ' ');
589 stdout_path_len = ep ? (ep - stdout_path) : strlen(stdout_path); 591 stdout_path_len = ep ? (ep - stdout_path) : strlen(stdout_path);
590 if (stdout_path_len >= sizeof(buf)) 592 if (stdout_path_len >= sizeof(buf))
591 return; 593 return;
592 594
593 strncpy(buf, stdout_path, stdout_path_len); 595 strncpy(buf, stdout_path, stdout_path_len);
594 buf[stdout_path_len] = '\0'; 596 buf[stdout_path_len] = '\0';
595 fdt_setprop(fdt_data, chosen_off, "stdout-path", 597 fdt_setprop(fdt_data, chosen_off, "stdout-path",
596 buf, stdout_path_len + 1); 598 buf, stdout_path_len + 1);
597} 599}
598 600
599void 601void
600consinit(void) 602consinit(void)
601{ 603{
602 static bool initialized = false; 604 static bool initialized = false;
603 const struct arm_platform *plat = arm_fdt_platform(); 605 const struct arm_platform *plat = arm_fdt_platform();
604 const struct fdt_console *cons = fdtbus_get_console(); 606 const struct fdt_console *cons = fdtbus_get_console();
605 struct fdt_attach_args faa; 607 struct fdt_attach_args faa;
606 u_int uart_freq = 0; 608 u_int uart_freq = 0;
607 609
608 if (initialized || cons == NULL) 610 if (initialized || cons == NULL)
609 return; 611 return;
610 612
611 plat->ap_init_attach_args(&faa); 613 plat->ap_init_attach_args(&faa);
612 faa.faa_phandle = fdtbus_get_stdout_phandle(); 614 faa.faa_phandle = fdtbus_get_stdout_phandle();
613 615
614 if (plat->ap_uart_freq != NULL) 616 if (plat->ap_uart_freq != NULL)
615 uart_freq = plat->ap_uart_freq(); 617 uart_freq = plat->ap_uart_freq();
616 618
617 cons->consinit(&faa, uart_freq); 619 cons->consinit(&faa, uart_freq);
618 620
619 initialized = true; 621 initialized = true;
620} 622}
621 623
622void 624void
623delay(u_int us) 625delay(u_int us)
624{ 626{
625 const struct arm_platform *plat = arm_fdt_platform(); 627 const struct arm_platform *plat = arm_fdt_platform();
626 628
627 plat->ap_delay(us); 629 plat->ap_delay(us);
628} 630}
629 631
630static void 632static void
631fdt_detect_root_device(device_t dev) 633fdt_detect_root_device(device_t dev)
632{ 634{
633 struct mbr_sector mbr; 635 struct mbr_sector mbr;
634 uint8_t buf[DEV_BSIZE]; 636 uint8_t buf[DEV_BSIZE];
635 uint8_t hash[16]; 637 uint8_t hash[16];
636 const uint8_t *rhash; 638 const uint8_t *rhash;
637 char rootarg[64]; 639 char rootarg[64];
638 struct vnode *vp; 640 struct vnode *vp;
639 MD5_CTX md5ctx; 641 MD5_CTX md5ctx;
640 int error, len; 642 int error, len;
641 size_t resid; 643 size_t resid;
642 u_int part; 644 u_int part;
643 645
644 const int chosen = OF_finddevice("/chosen"); 646 const int chosen = OF_finddevice("/chosen");
645 if (chosen < 0) 647 if (chosen < 0)
646 return; 648 return;
647 649
648 if (of_hasprop(chosen, "netbsd,mbr") && 650 if (of_hasprop(chosen, "netbsd,mbr") &&
649 of_hasprop(chosen, "netbsd,partition")) { 651 of_hasprop(chosen, "netbsd,partition")) {
650 652
651 /* 653 /*
652 * The bootloader has passed in a partition index and MD5 hash 654 * The bootloader has passed in a partition index and MD5 hash
653 * of the MBR sector. Read the MBR of this device, calculate the 655 * of the MBR sector. Read the MBR of this device, calculate the
654 * hash, and compare it with the value passed in. 656 * hash, and compare it with the value passed in.
655 */ 657 */
656 rhash = fdtbus_get_prop(chosen, "netbsd,mbr", &len); 658 rhash = fdtbus_get_prop(chosen, "netbsd,mbr", &len);
657 if (rhash == NULL || len != 16) 659 if (rhash == NULL || len != 16)
658 return; 660 return;
659 of_getprop_uint32(chosen, "netbsd,partition", &part); 661 of_getprop_uint32(chosen, "netbsd,partition", &part);
660 if (part >= MAXPARTITIONS) 662 if (part >= MAXPARTITIONS)
661 return; 663 return;
662 664
663 vp = opendisk(dev); 665 vp = opendisk(dev);
664 if (!vp) 666 if (!vp)
665 return; 667 return;
666 error = vn_rdwr(UIO_READ, vp, buf, sizeof(buf), 0, UIO_SYSSPACE, 668 error = vn_rdwr(UIO_READ, vp, buf, sizeof(buf), 0, UIO_SYSSPACE,
667 0, NOCRED, &resid, NULL); 669 0, NOCRED, &resid, NULL);
668 VOP_CLOSE(vp, FREAD, NOCRED); 670 VOP_CLOSE(vp, FREAD, NOCRED);
669 vput(vp); 671 vput(vp);
670 672
671 if (error != 0) 673 if (error != 0)
672 return; 674 return;
673 675
674 memcpy(&mbr, buf, sizeof(mbr)); 676 memcpy(&mbr, buf, sizeof(mbr));
675 MD5Init(&md5ctx); 677 MD5Init(&md5ctx);
676 MD5Update(&md5ctx, (void *)&mbr, sizeof(mbr)); 678 MD5Update(&md5ctx, (void *)&mbr, sizeof(mbr));
677 MD5Final(hash, &md5ctx); 679 MD5Final(hash, &md5ctx);
678 680
679 if (memcmp(rhash, hash, 16) != 0) 681 if (memcmp(rhash, hash, 16) != 0)
680 return; 682 return;
681 683
682 snprintf(rootarg, sizeof(rootarg), " root=%s%c", device_xname(dev), part + 'a'); 684 snprintf(rootarg, sizeof(rootarg), " root=%s%c", device_xname(dev), part + 'a');
683 strcat(boot_args, rootarg); 685 strcat(boot_args, rootarg);
684 } 686 }
685 687
686 if (of_hasprop(chosen, "netbsd,gpt-guid")) { 688 if (of_hasprop(chosen, "netbsd,gpt-guid")) {
687 char guidbuf[UUID_STR_LEN]; 689 char guidbuf[UUID_STR_LEN];
688 const struct uuid *guid = fdtbus_get_prop(chosen, "netbsd,gpt-guid", &len); 690 const struct uuid *guid = fdtbus_get_prop(chosen, "netbsd,gpt-guid", &len);
689 if (guid == NULL || len != 16) 691 if (guid == NULL || len != 16)
690 return; 692 return;
691 693
692 uuid_snprintf(guidbuf, sizeof(guidbuf), guid); 694 uuid_snprintf(guidbuf, sizeof(guidbuf), guid);
693 snprintf(rootarg, sizeof(rootarg), " root=wedge:%s", guidbuf); 695 snprintf(rootarg, sizeof(rootarg), " root=wedge:%s", guidbuf);
694 strcat(boot_args, rootarg); 696 strcat(boot_args, rootarg);
695 } 697 }
696 698
697 if (of_hasprop(chosen, "netbsd,gpt-label")) { 699 if (of_hasprop(chosen, "netbsd,gpt-label")) {
698 const char *label = fdtbus_get_string(chosen, "netbsd,gpt-label"); 700 const char *label = fdtbus_get_string(chosen, "netbsd,gpt-label");
699 if (label == NULL || *label == '\0') 701 if (label == NULL || *label == '\0')
700 return; 702 return;
701 703
702 device_t dv = dkwedge_find_by_wname(label); 704 device_t dv = dkwedge_find_by_wname(label);
703 if (dv != NULL) 705 if (dv != NULL)
704 booted_device = dv; 706 booted_device = dv;
705 } 707 }
706 708
707 if (of_hasprop(chosen, "netbsd,booted-mac-address")) { 709 if (of_hasprop(chosen, "netbsd,booted-mac-address")) {
708 const uint8_t *macaddr = fdtbus_get_prop(chosen, "netbsd,booted-mac-address", &len); 710 const uint8_t *macaddr = fdtbus_get_prop(chosen, "netbsd,booted-mac-address", &len);
709 if (macaddr == NULL || len != 6) 711 if (macaddr == NULL || len != 6)
710 return; 712 return;
711 int s = pserialize_read_enter(); 713 int s = pserialize_read_enter();
712 struct ifnet *ifp; 714 struct ifnet *ifp;
713 IFNET_READER_FOREACH(ifp) { 715 IFNET_READER_FOREACH(ifp) {
714 if (memcmp(macaddr, CLLADDR(ifp->if_sadl), len) == 0) { 716 if (memcmp(macaddr, CLLADDR(ifp->if_sadl), len) == 0) {
715 device_t dv = device_find_by_xname(ifp->if_xname); 717 device_t dv = device_find_by_xname(ifp->if_xname);
716 if (dv != NULL) 718 if (dv != NULL)
717 booted_device = dv; 719 booted_device = dv;
718 break; 720 break;
719 } 721 }
720 } 722 }
721 pserialize_read_exit(s); 723 pserialize_read_exit(s);
722 } 724 }
723} 725}
724 726
725static void 727static void
726fdt_device_register(device_t self, void *aux) 728fdt_device_register(device_t self, void *aux)
727{ 729{
728 const struct arm_platform *plat = arm_fdt_platform(); 730 const struct arm_platform *plat = arm_fdt_platform();
729 731
730 if (device_is_a(self, "armfdt")) 732 if (device_is_a(self, "armfdt"))
731 fdt_setup_initrd(); 733 fdt_setup_initrd();
732 734
733 if (plat && plat->ap_device_register) 735 if (plat && plat->ap_device_register)
734 plat->ap_device_register(self, aux); 736 plat->ap_device_register(self, aux);
735} 737}
736 738
737static void 739static void
738fdt_device_register_post_config(device_t self, void *aux) 740fdt_device_register_post_config(device_t self, void *aux)
739{ 741{
740#if NUKBD > 0 && NWSDISPLAY > 0 742#if NUKBD > 0 && NWSDISPLAY > 0
741 if (device_is_a(self, "wsdisplay")) { 743 if (device_is_a(self, "wsdisplay")) {
742 struct wsdisplay_softc *sc = device_private(self); 744 struct wsdisplay_softc *sc = device_private(self);
743 if (wsdisplay_isconsole(sc)) 745 if (wsdisplay_isconsole(sc))
744 ukbd_cnattach(); 746 ukbd_cnattach();
745 } 747 }
746#endif 748#endif
747} 749}
748 750
749static void 751static void
750fdt_cpu_rootconf(void) 752fdt_cpu_rootconf(void)
751{ 753{
752 device_t dev; 754 device_t dev;
753 deviter_t di; 755 deviter_t di;
754 char *ptr; 756 char *ptr;
755 757
756 for (dev = deviter_first(&di, 0); dev; dev = deviter_next(&di)) { 758 for (dev = deviter_first(&di, 0); dev; dev = deviter_next(&di)) {
757 if (device_class(dev) != DV_DISK) 759 if (device_class(dev) != DV_DISK)
758 continue; 760 continue;
759 761
760 if (get_bootconf_option(boot_args, "root", BOOTOPT_TYPE_STRING, &ptr) != 0) 762 if (get_bootconf_option(boot_args, "root", BOOTOPT_TYPE_STRING, &ptr) != 0)
761 break; 763 break;
762 764
763 if (device_is_a(dev, "ld") || device_is_a(dev, "sd") || device_is_a(dev, "wd")) 765 if (device_is_a(dev, "ld") || device_is_a(dev, "sd") || device_is_a(dev, "wd"))
764 fdt_detect_root_device(dev); 766 fdt_detect_root_device(dev);
765 } 767 }
766 deviter_release(&di); 768 deviter_release(&di);
767} 769}
768 770
769static void 771static void
770fdt_reset(void) 772fdt_reset(void)
771{ 773{
772 const struct arm_platform *plat = arm_fdt_platform(); 774 const struct arm_platform *plat = arm_fdt_platform();
773 775
774 fdtbus_power_reset(); 776 fdtbus_power_reset();
775 777
776 if (plat && plat->ap_reset) 778 if (plat && plat->ap_reset)
777 plat->ap_reset(); 779 plat->ap_reset();
778} 780}
779 781
780static void 782static void
781fdt_powerdown(void) 783fdt_powerdown(void)
782{ 784{
783 fdtbus_power_poweroff(); 785 fdtbus_power_poweroff();
784} 786}