fdt_machdep.c revision 1.108 1 1.108 jmcneill /* $NetBSD: fdt_machdep.c,v 1.108 2024/06/30 17:55:28 jmcneill Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2015-2017 Jared McNeill <jmcneill (at) invisible.ca>
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
8 1.1 jmcneill * modification, are permitted provided that the following conditions
9 1.1 jmcneill * are met:
10 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
11 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
12 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
14 1.1 jmcneill * documentation and/or other materials provided with the distribution.
15 1.1 jmcneill *
16 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 jmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 jmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 jmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 jmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 jmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 jmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 jmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 jmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 jmcneill * SUCH DAMAGE.
27 1.1 jmcneill */
28 1.1 jmcneill
29 1.1 jmcneill #include <sys/cdefs.h>
30 1.108 jmcneill __KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.108 2024/06/30 17:55:28 jmcneill Exp $");
31 1.1 jmcneill
32 1.84 skrll #include "opt_arm_debug.h"
33 1.21 ryo #include "opt_bootconfig.h"
34 1.84 skrll #include "opt_cpuoptions.h"
35 1.1 jmcneill #include "opt_ddb.h"
36 1.84 skrll #include "opt_efi.h"
37 1.84 skrll #include "opt_machdep.h"
38 1.1 jmcneill #include "opt_multiprocessor.h"
39 1.1 jmcneill
40 1.75 jmcneill #include "genfb.h"
41 1.14 jmcneill #include "ukbd.h"
42 1.39 bouyer #include "wsdisplay.h"
43 1.14 jmcneill
44 1.1 jmcneill #include <sys/param.h>
45 1.93 skrll #include <sys/types.h>
46 1.93 skrll
47 1.93 skrll #include <sys/atomic.h>
48 1.93 skrll #include <sys/bootblock.h>
49 1.1 jmcneill #include <sys/bus.h>
50 1.93 skrll #include <sys/conf.h>
51 1.1 jmcneill #include <sys/cpu.h>
52 1.1 jmcneill #include <sys/device.h>
53 1.93 skrll #include <sys/disk.h>
54 1.93 skrll #include <sys/disklabel.h>
55 1.76 rin #include <sys/endian.h>
56 1.1 jmcneill #include <sys/exec.h>
57 1.93 skrll #include <sys/fcntl.h>
58 1.93 skrll #include <sys/kauth.h>
59 1.1 jmcneill #include <sys/kernel.h>
60 1.1 jmcneill #include <sys/kmem.h>
61 1.1 jmcneill #include <sys/ksyms.h>
62 1.93 skrll #include <sys/md5.h>
63 1.1 jmcneill #include <sys/msgbuf.h>
64 1.1 jmcneill #include <sys/proc.h>
65 1.93 skrll #include <sys/pserialize.h>
66 1.1 jmcneill #include <sys/reboot.h>
67 1.93 skrll #include <sys/systm.h>
68 1.1 jmcneill #include <sys/termios.h>
69 1.34 jmcneill #include <sys/vnode.h>
70 1.53 jmcneill #include <sys/uuid.h>
71 1.55 jmcneill
72 1.55 jmcneill #include <net/if.h>
73 1.55 jmcneill #include <net/if_dl.h>
74 1.1 jmcneill
75 1.23 ryo #include <dev/cons.h>
76 1.1 jmcneill #include <uvm/uvm_extern.h>
77 1.1 jmcneill
78 1.1 jmcneill #include <machine/db_machdep.h>
79 1.1 jmcneill #include <ddb/db_sym.h>
80 1.1 jmcneill #include <ddb/db_extern.h>
81 1.1 jmcneill
82 1.1 jmcneill #include <machine/bootconfig.h>
83 1.1 jmcneill #include <arm/armreg.h>
84 1.1 jmcneill
85 1.21 ryo #include <arm/cpufunc.h>
86 1.1 jmcneill
87 1.1 jmcneill #include <evbarm/include/autoconf.h>
88 1.30 skrll #include <evbarm/fdt/machdep.h>
89 1.1 jmcneill #include <evbarm/fdt/platform.h>
90 1.1 jmcneill
91 1.1 jmcneill #include <arm/fdt/arm_fdtvar.h>
92 1.102 skrll
93 1.102 skrll #include <dev/fdt/fdtvar.h>
94 1.103 skrll #include <dev/fdt/fdt_boot.h>
95 1.68 skrll #include <dev/fdt/fdt_private.h>
96 1.83 skrll #include <dev/fdt/fdt_memory.h>
97 1.1 jmcneill
98 1.46 jmcneill #ifdef EFI_RUNTIME
99 1.46 jmcneill #include <arm/arm/efi_runtime.h>
100 1.46 jmcneill #endif
101 1.46 jmcneill
102 1.75 jmcneill #if NWSDISPLAY > 0 && NGENFB > 0
103 1.75 jmcneill #include <arm/fdt/arm_simplefb.h>
104 1.75 jmcneill #endif
105 1.75 jmcneill
106 1.14 jmcneill #if NUKBD > 0
107 1.14 jmcneill #include <dev/usb/ukbdvar.h>
108 1.14 jmcneill #endif
109 1.39 bouyer #if NWSDISPLAY > 0
110 1.39 bouyer #include <dev/wscons/wsdisplayvar.h>
111 1.39 bouyer #endif
112 1.14 jmcneill
113 1.1 jmcneill BootConfig bootconfig;
114 1.1 jmcneill char *boot_args = NULL;
115 1.26 christos
116 1.26 christos /* filled in before cleaning bss. keep in .data */
117 1.27 christos u_long uboot_args[4] __attribute__((__section__(".data")));
118 1.28 skrll const uint8_t *fdt_addr_r __attribute__((__section__(".data")));
119 1.1 jmcneill
120 1.1 jmcneill #include <libfdt.h>
121 1.1 jmcneill #include <dev/fdt/fdtvar.h>
122 1.40 jmcneill #define FDT_BUF_SIZE (512*1024)
123 1.1 jmcneill static uint8_t fdt_data[FDT_BUF_SIZE];
124 1.1 jmcneill
125 1.1 jmcneill extern char KERNEL_BASE_phys[];
126 1.1 jmcneill #define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys)
127 1.1 jmcneill
128 1.1 jmcneill static void fdt_device_register(device_t, void *);
129 1.39 bouyer static void fdt_device_register_post_config(device_t, void *);
130 1.1 jmcneill static void fdt_reset(void);
131 1.1 jmcneill static void fdt_powerdown(void);
132 1.1 jmcneill
133 1.76 rin #if BYTE_ORDER == BIG_ENDIAN
134 1.76 rin static void fdt_update_fb_format(void);
135 1.76 rin #endif
136 1.76 rin
137 1.1 jmcneill static void
138 1.23 ryo earlyconsputc(dev_t dev, int c)
139 1.1 jmcneill {
140 1.48 skrll uartputc(c);
141 1.1 jmcneill }
142 1.1 jmcneill
143 1.23 ryo static int
144 1.23 ryo earlyconsgetc(dev_t dev)
145 1.1 jmcneill {
146 1.87 jmcneill return -1;
147 1.23 ryo }
148 1.1 jmcneill
149 1.54 skrll static struct consdev earlycons = {
150 1.54 skrll .cn_putc = earlyconsputc,
151 1.54 skrll .cn_getc = earlyconsgetc,
152 1.54 skrll .cn_pollc = nullcnpollc,
153 1.54 skrll };
154 1.54 skrll
155 1.23 ryo #ifdef VERBOSE_INIT_ARM
156 1.29 skrll #define VPRINTF(...) printf(__VA_ARGS__)
157 1.1 jmcneill #else
158 1.43 skrll #define VPRINTF(...) __nothing
159 1.1 jmcneill #endif
160 1.1 jmcneill
161 1.49 jmcneill static void
162 1.49 jmcneill fdt_add_dram_blocks(const struct fdt_memory *m, void *arg)
163 1.49 jmcneill {
164 1.49 jmcneill BootConfig *bc = arg;
165 1.49 jmcneill
166 1.52 jmcneill VPRINTF(" %" PRIx64 " - %" PRIx64 "\n", m->start, m->end - 1);
167 1.49 jmcneill bc->dram[bc->dramblocks].address = m->start;
168 1.49 jmcneill bc->dram[bc->dramblocks].pages =
169 1.49 jmcneill (m->end - m->start) / PAGE_SIZE;
170 1.49 jmcneill bc->dramblocks++;
171 1.49 jmcneill }
172 1.49 jmcneill
173 1.49 jmcneill static int nfdt_physmem = 0;
174 1.99 jmcneill static struct boot_physmem fdt_physmem[FDT_MEMORY_RANGES];
175 1.49 jmcneill
176 1.49 jmcneill static void
177 1.49 jmcneill fdt_add_boot_physmem(const struct fdt_memory *m, void *arg)
178 1.49 jmcneill {
179 1.62 skrll const paddr_t saddr = round_page(m->start);
180 1.62 skrll const paddr_t eaddr = trunc_page(m->end);
181 1.62 skrll
182 1.62 skrll VPRINTF(" %" PRIx64 " - %" PRIx64, m->start, m->end - 1);
183 1.62 skrll if (saddr >= eaddr) {
184 1.62 skrll VPRINTF(" skipped\n");
185 1.62 skrll return;
186 1.62 skrll }
187 1.62 skrll VPRINTF("\n");
188 1.62 skrll
189 1.49 jmcneill struct boot_physmem *bp = &fdt_physmem[nfdt_physmem++];
190 1.49 jmcneill
191 1.99 jmcneill KASSERT(nfdt_physmem <= FDT_MEMORY_RANGES);
192 1.49 jmcneill
193 1.62 skrll bp->bp_start = atop(saddr);
194 1.62 skrll bp->bp_pages = atop(eaddr) - bp->bp_start;
195 1.49 jmcneill bp->bp_freelist = VM_FREELIST_DEFAULT;
196 1.49 jmcneill
197 1.49 jmcneill #ifdef PMAP_NEED_ALLOC_POOLPAGE
198 1.49 jmcneill const uint64_t memory_size = *(uint64_t *)arg;
199 1.49 jmcneill if (atop(memory_size) > bp->bp_pages) {
200 1.49 jmcneill arm_poolpage_vmfreelist = VM_FREELIST_DIRECTMAP;
201 1.49 jmcneill bp->bp_freelist = VM_FREELIST_DIRECTMAP;
202 1.49 jmcneill }
203 1.49 jmcneill #endif
204 1.49 jmcneill }
205 1.49 jmcneill
206 1.83 skrll
207 1.83 skrll static void
208 1.83 skrll fdt_print_memory(const struct fdt_memory *m, void *arg)
209 1.83 skrll {
210 1.83 skrll
211 1.83 skrll VPRINTF("FDT /memory @ 0x%" PRIx64 " size 0x%" PRIx64 "\n",
212 1.83 skrll m->start, m->end - m->start);
213 1.83 skrll }
214 1.83 skrll
215 1.83 skrll
216 1.8 jmcneill /*
217 1.8 jmcneill * Define usable memory regions.
218 1.8 jmcneill */
219 1.8 jmcneill static void
220 1.21 ryo fdt_build_bootconfig(uint64_t mem_start, uint64_t mem_end)
221 1.8 jmcneill {
222 1.8 jmcneill BootConfig *bc = &bootconfig;
223 1.83 skrll
224 1.8 jmcneill uint64_t addr, size;
225 1.49 jmcneill int index;
226 1.8 jmcneill
227 1.104 rin /* Reserve pages for ramdisk, rndseed, and firmware's RNG */
228 1.104 rin fdt_reserve_initrd();
229 1.104 rin fdt_reserve_rndseed();
230 1.104 rin fdt_reserve_efirng();
231 1.69 riastrad
232 1.47 jmcneill const int framebuffer = OF_finddevice("/chosen/framebuffer");
233 1.47 jmcneill if (framebuffer >= 0) {
234 1.47 jmcneill for (index = 0;
235 1.47 jmcneill fdtbus_get_reg64(framebuffer, index, &addr, &size) == 0;
236 1.47 jmcneill index++) {
237 1.83 skrll fdt_memory_remove_range(addr, size);
238 1.47 jmcneill }
239 1.47 jmcneill }
240 1.47 jmcneill
241 1.29 skrll VPRINTF("Usable memory:\n");
242 1.8 jmcneill bc->dramblocks = 0;
243 1.49 jmcneill fdt_memory_foreach(fdt_add_dram_blocks, bc);
244 1.8 jmcneill }
245 1.8 jmcneill
246 1.46 jmcneill
247 1.64 skrll vaddr_t
248 1.1 jmcneill initarm(void *arg)
249 1.1 jmcneill {
250 1.102 skrll const struct fdt_platform *plat;
251 1.21 ryo uint64_t memory_start, memory_end;
252 1.1 jmcneill
253 1.23 ryo /* set temporally to work printf()/panic() even before consinit() */
254 1.23 ryo cn_tab = &earlycons;
255 1.23 ryo
256 1.1 jmcneill /* Load FDT */
257 1.1 jmcneill int error = fdt_check_header(fdt_addr_r);
258 1.79 skrll if (error != 0)
259 1.1 jmcneill panic("fdt_check_header failed: %s", fdt_strerror(error));
260 1.79 skrll
261 1.79 skrll /* If the DTB is too big, try to pack it in place first. */
262 1.79 skrll if (fdt_totalsize(fdt_addr_r) > sizeof(fdt_data))
263 1.79 skrll (void)fdt_pack(__UNCONST(fdt_addr_r));
264 1.83 skrll
265 1.79 skrll error = fdt_open_into(fdt_addr_r, fdt_data, sizeof(fdt_data));
266 1.79 skrll if (error != 0)
267 1.79 skrll panic("fdt_move failed: %s", fdt_strerror(error));
268 1.79 skrll
269 1.79 skrll fdtbus_init(fdt_data);
270 1.1 jmcneill
271 1.1 jmcneill /* Lookup platform specific backend */
272 1.102 skrll plat = fdt_platform_find();
273 1.1 jmcneill if (plat == NULL)
274 1.1 jmcneill panic("Kernel does not support this device");
275 1.1 jmcneill
276 1.1 jmcneill /* Early console may be available, announce ourselves. */
277 1.29 skrll VPRINTF("FDT<%p>\n", fdt_addr_r);
278 1.1 jmcneill
279 1.105 rin boot_args = fdt_get_bootargs();
280 1.6 jmcneill
281 1.1 jmcneill /* Heads up ... Setup the CPU / MMU / TLB functions. */
282 1.29 skrll VPRINTF("cpufunc\n");
283 1.1 jmcneill if (set_cpufuncs())
284 1.1 jmcneill panic("cpu not recognized!");
285 1.1 jmcneill
286 1.44 skrll /*
287 1.44 skrll * Memory is still identity/flat mapped this point so using ttbr for
288 1.44 skrll * l1pt VA is fine
289 1.44 skrll */
290 1.44 skrll
291 1.102 skrll VPRINTF("devmap %p\n", plat->fp_devmap());
292 1.44 skrll extern char ARM_BOOTSTRAP_LxPT[];
293 1.102 skrll pmap_devmap_bootstrap((vaddr_t)ARM_BOOTSTRAP_LxPT, plat->fp_devmap());
294 1.44 skrll
295 1.29 skrll VPRINTF("bootstrap\n");
296 1.102 skrll plat->fp_bootstrap();
297 1.16 skrll
298 1.5 jmcneill /*
299 1.5 jmcneill * If stdout-path is specified on the command line, override the
300 1.5 jmcneill * value in /chosen/stdout-path before initializing console.
301 1.5 jmcneill */
302 1.44 skrll VPRINTF("stdout\n");
303 1.103 skrll fdt_update_stdout_path(fdt_data, boot_args);
304 1.5 jmcneill
305 1.76 rin #if BYTE_ORDER == BIG_ENDIAN
306 1.76 rin /*
307 1.92 skrll * Most boards are configured to little-endian mode initially, and
308 1.76 rin * switched to big-endian mode after kernel is loaded. In this case,
309 1.76 rin * framebuffer seems byte-swapped to CPU. Override FDT to let
310 1.76 rin * drivers know.
311 1.76 rin */
312 1.76 rin VPRINTF("fb_format\n");
313 1.76 rin fdt_update_fb_format();
314 1.76 rin #endif
315 1.76 rin
316 1.38 jmcneill /*
317 1.38 jmcneill * Done making changes to the FDT.
318 1.38 jmcneill */
319 1.38 jmcneill fdt_pack(fdt_data);
320 1.38 jmcneill
321 1.29 skrll VPRINTF("consinit ");
322 1.1 jmcneill consinit();
323 1.29 skrll VPRINTF("ok\n");
324 1.1 jmcneill
325 1.29 skrll VPRINTF("uboot: args %#lx, %#lx, %#lx, %#lx\n",
326 1.1 jmcneill uboot_args[0], uboot_args[1], uboot_args[2], uboot_args[3]);
327 1.1 jmcneill
328 1.1 jmcneill cpu_reset_address = fdt_reset;
329 1.1 jmcneill cpu_powerdown_address = fdt_powerdown;
330 1.1 jmcneill evbarm_device_register = fdt_device_register;
331 1.39 bouyer evbarm_device_register_post_config = fdt_device_register_post_config;
332 1.34 jmcneill evbarm_cpu_rootconf = fdt_cpu_rootconf;
333 1.1 jmcneill
334 1.1 jmcneill /* Talk to the user */
335 1.45 skrll printf("NetBSD/evbarm (fdt) booting ...\n");
336 1.1 jmcneill
337 1.1 jmcneill #ifdef BOOT_ARGS
338 1.1 jmcneill char mi_bootargs[] = BOOT_ARGS;
339 1.1 jmcneill parse_mi_bootargs(mi_bootargs);
340 1.1 jmcneill #endif
341 1.1 jmcneill
342 1.83 skrll fdt_memory_get(&memory_start, &memory_end);
343 1.83 skrll
344 1.83 skrll fdt_memory_foreach(fdt_print_memory, NULL);
345 1.1 jmcneill
346 1.1 jmcneill #if !defined(_LP64)
347 1.81 skrll /* Cannot map memory above 4GB (remove last page as well) */
348 1.81 skrll const uint64_t memory_limit = 0x100000000ULL - PAGE_SIZE;
349 1.83 skrll if (memory_end > memory_limit) {
350 1.83 skrll fdt_memory_remove_range(memory_limit , memory_end);
351 1.81 skrll memory_end = memory_limit;
352 1.83 skrll }
353 1.31 skrll #endif
354 1.21 ryo uint64_t memory_size = memory_end - memory_start;
355 1.1 jmcneill
356 1.44 skrll VPRINTF("%s: memory start %" PRIx64 " end %" PRIx64 " (len %"
357 1.44 skrll PRIx64 ")\n", __func__, memory_start, memory_end, memory_size);
358 1.44 skrll
359 1.8 jmcneill /* Parse ramdisk info */
360 1.104 rin fdt_probe_initrd();
361 1.8 jmcneill
362 1.69 riastrad /* Parse our on-disk rndseed and the firmware's RNG from EFI */
363 1.104 rin fdt_probe_rndseed();
364 1.104 rin fdt_probe_efirng();
365 1.65 riastrad
366 1.98 skrll fdt_memory_remove_reserved(memory_start, memory_end);
367 1.96 skrll
368 1.16 skrll /*
369 1.80 skrll * Populate bootconfig structure for the benefit of dodumpsys
370 1.16 skrll */
371 1.44 skrll VPRINTF("%s: fdt_build_bootconfig\n", __func__);
372 1.21 ryo fdt_build_bootconfig(memory_start, memory_end);
373 1.21 ryo
374 1.31 skrll /* Perform PT build and VM init */
375 1.31 skrll cpu_kernel_vm_init(memory_start, memory_size);
376 1.1 jmcneill
377 1.105 rin VPRINTF("bootargs: %s\n", boot_args);
378 1.1 jmcneill
379 1.1 jmcneill parse_mi_bootargs(boot_args);
380 1.1 jmcneill
381 1.49 jmcneill VPRINTF("Memory regions:\n");
382 1.86 skrll
383 1.86 skrll /* Populate fdt_physmem / nfdt_physmem for initarm_common */
384 1.49 jmcneill fdt_memory_foreach(fdt_add_boot_physmem, &memory_size);
385 1.1 jmcneill
386 1.64 skrll vaddr_t sp = initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, fdt_physmem,
387 1.16 skrll nfdt_physmem);
388 1.44 skrll
389 1.59 skrll /*
390 1.60 skrll * initarm_common flushes cache if required before AP start
391 1.59 skrll */
392 1.58 skrll error = 0;
393 1.56 ryo if ((boothowto & RB_MD1) == 0) {
394 1.56 ryo VPRINTF("mpstart\n");
395 1.102 skrll if (plat->fp_mpstart)
396 1.102 skrll error = plat->fp_mpstart();
397 1.56 ryo }
398 1.44 skrll
399 1.58 skrll if (error)
400 1.58 skrll return sp;
401 1.74 skrll
402 1.44 skrll /*
403 1.44 skrll * Now we have APs started the pages used for stacks and L1PT can
404 1.44 skrll * be given to uvm
405 1.44 skrll */
406 1.57 skrll extern char const __start__init_memory[];
407 1.57 skrll extern char const __stop__init_memory[] __weak;
408 1.57 skrll
409 1.106 mrg if (&__start__init_memory[0] != &__stop__init_memory[0]) {
410 1.44 skrll const paddr_t spa = KERN_VTOPHYS((vaddr_t)__start__init_memory);
411 1.44 skrll const paddr_t epa = KERN_VTOPHYS((vaddr_t)__stop__init_memory);
412 1.44 skrll const paddr_t spg = atop(spa);
413 1.44 skrll const paddr_t epg = atop(epa);
414 1.44 skrll
415 1.63 skrll VPRINTF(" start %08lx end %08lx... "
416 1.63 skrll "loading in freelist %d\n", spa, epa, VM_FREELIST_DEFAULT);
417 1.63 skrll
418 1.44 skrll uvm_page_physload(spg, epg, spg, epg, VM_FREELIST_DEFAULT);
419 1.44 skrll }
420 1.44 skrll
421 1.44 skrll return sp;
422 1.1 jmcneill }
423 1.1 jmcneill
424 1.1 jmcneill void
425 1.1 jmcneill consinit(void)
426 1.1 jmcneill {
427 1.1 jmcneill static bool initialized = false;
428 1.102 skrll const struct fdt_platform *plat = fdt_platform_find();
429 1.1 jmcneill const struct fdt_console *cons = fdtbus_get_console();
430 1.1 jmcneill struct fdt_attach_args faa;
431 1.4 jmcneill u_int uart_freq = 0;
432 1.1 jmcneill
433 1.1 jmcneill if (initialized || cons == NULL)
434 1.1 jmcneill return;
435 1.1 jmcneill
436 1.102 skrll plat->fp_init_attach_args(&faa);
437 1.1 jmcneill faa.faa_phandle = fdtbus_get_stdout_phandle();
438 1.1 jmcneill
439 1.102 skrll if (plat->fp_uart_freq != NULL)
440 1.102 skrll uart_freq = plat->fp_uart_freq();
441 1.4 jmcneill
442 1.4 jmcneill cons->consinit(&faa, uart_freq);
443 1.1 jmcneill
444 1.1 jmcneill initialized = true;
445 1.1 jmcneill }
446 1.1 jmcneill
447 1.3 jmcneill void
448 1.65 riastrad cpu_startup_hook(void)
449 1.65 riastrad {
450 1.91 skrll #ifdef EFI_RUNTIME
451 1.91 skrll fdt_map_efi_runtime("netbsd,uefi-runtime-code", ARM_EFIRT_MEM_CODE);
452 1.91 skrll fdt_map_efi_runtime("netbsd,uefi-runtime-data", ARM_EFIRT_MEM_DATA);
453 1.91 skrll fdt_map_efi_runtime("netbsd,uefi-runtime-mmio", ARM_EFIRT_MEM_MMIO);
454 1.91 skrll #endif
455 1.65 riastrad
456 1.68 skrll fdtbus_intr_init();
457 1.68 skrll
458 1.65 riastrad fdt_setup_rndseed();
459 1.69 riastrad fdt_setup_efirng();
460 1.65 riastrad }
461 1.65 riastrad
462 1.65 riastrad void
463 1.3 jmcneill delay(u_int us)
464 1.3 jmcneill {
465 1.102 skrll const struct fdt_platform *plat = fdt_platform_find();
466 1.3 jmcneill
467 1.102 skrll plat->fp_delay(us);
468 1.3 jmcneill }
469 1.34 jmcneill static void
470 1.1 jmcneill fdt_device_register(device_t self, void *aux)
471 1.1 jmcneill {
472 1.102 skrll const struct fdt_platform *plat = fdt_platform_find();
473 1.1 jmcneill
474 1.75 jmcneill if (device_is_a(self, "armfdt")) {
475 1.8 jmcneill fdt_setup_initrd();
476 1.8 jmcneill
477 1.75 jmcneill #if NWSDISPLAY > 0 && NGENFB > 0
478 1.75 jmcneill /*
479 1.75 jmcneill * Setup framebuffer console, if present.
480 1.75 jmcneill */
481 1.75 jmcneill arm_simplefb_preattach();
482 1.75 jmcneill #endif
483 1.75 jmcneill }
484 1.75 jmcneill
485 1.77 jmcneill #if NWSDISPLAY > 0 && NGENFB > 0
486 1.77 jmcneill if (device_is_a(self, "genfb")) {
487 1.77 jmcneill prop_dictionary_t dict = device_properties(self);
488 1.77 jmcneill prop_dictionary_set_uint64(dict,
489 1.77 jmcneill "simplefb-physaddr", arm_simplefb_physaddr());
490 1.77 jmcneill }
491 1.77 jmcneill #endif
492 1.77 jmcneill
493 1.102 skrll if (plat && plat->fp_device_register)
494 1.102 skrll plat->fp_device_register(self, aux);
495 1.1 jmcneill }
496 1.1 jmcneill
497 1.1 jmcneill static void
498 1.39 bouyer fdt_device_register_post_config(device_t self, void *aux)
499 1.39 bouyer {
500 1.108 jmcneill const struct fdt_platform *plat = fdt_platform_find();
501 1.108 jmcneill
502 1.108 jmcneill if (plat && plat->fp_device_register_post_config)
503 1.108 jmcneill plat->fp_device_register_post_config(self, aux);
504 1.108 jmcneill
505 1.39 bouyer #if NUKBD > 0 && NWSDISPLAY > 0
506 1.39 bouyer if (device_is_a(self, "wsdisplay")) {
507 1.39 bouyer struct wsdisplay_softc *sc = device_private(self);
508 1.39 bouyer if (wsdisplay_isconsole(sc))
509 1.39 bouyer ukbd_cnattach();
510 1.39 bouyer }
511 1.39 bouyer #endif
512 1.39 bouyer }
513 1.39 bouyer
514 1.39 bouyer static void
515 1.1 jmcneill fdt_reset(void)
516 1.1 jmcneill {
517 1.102 skrll const struct fdt_platform *plat = fdt_platform_find();
518 1.1 jmcneill
519 1.1 jmcneill fdtbus_power_reset();
520 1.1 jmcneill
521 1.102 skrll if (plat && plat->fp_reset)
522 1.102 skrll plat->fp_reset();
523 1.1 jmcneill }
524 1.1 jmcneill
525 1.1 jmcneill static void
526 1.1 jmcneill fdt_powerdown(void)
527 1.1 jmcneill {
528 1.1 jmcneill fdtbus_power_poweroff();
529 1.1 jmcneill }
530 1.76 rin
531 1.76 rin #if BYTE_ORDER == BIG_ENDIAN
532 1.76 rin static void
533 1.76 rin fdt_update_fb_format(void)
534 1.76 rin {
535 1.76 rin int off, len;
536 1.76 rin const char *format, *replace;
537 1.76 rin
538 1.76 rin off = fdt_path_offset(fdt_data, "/chosen");
539 1.76 rin if (off < 0)
540 1.76 rin return;
541 1.76 rin
542 1.76 rin for (;;) {
543 1.76 rin off = fdt_node_offset_by_compatible(fdt_data, off,
544 1.76 rin "simple-framebuffer");
545 1.76 rin if (off < 0)
546 1.76 rin return;
547 1.76 rin
548 1.76 rin format = fdt_getprop(fdt_data, off, "format", &len);
549 1.76 rin if (format == NULL)
550 1.76 rin continue;
551 1.76 rin
552 1.76 rin replace = NULL;
553 1.76 rin if (strcmp(format, "a8b8g8r8") == 0)
554 1.76 rin replace = "r8g8b8a8";
555 1.76 rin else if (strcmp(format, "x8r8g8b8") == 0)
556 1.76 rin replace = "b8g8r8x8";
557 1.76 rin if (replace != NULL)
558 1.76 rin fdt_setprop(fdt_data, off, "format", replace,
559 1.76 rin strlen(replace) + 1);
560 1.76 rin }
561 1.76 rin }
562 1.76 rin #endif
563