version 1.7, 2017/06/11 20:25:07 |
version 1.77.2.2, 2021/01/03 16:34:53 |
|
|
#include <sys/cdefs.h> |
#include <sys/cdefs.h> |
__KERNEL_RCSID(0, "$NetBSD$"); |
__KERNEL_RCSID(0, "$NetBSD$"); |
|
|
#include "opt_machdep.h" |
#include "opt_arm_debug.h" |
|
#include "opt_bootconfig.h" |
|
#include "opt_cpuoptions.h" |
#include "opt_ddb.h" |
#include "opt_ddb.h" |
|
#include "opt_efi.h" |
|
#include "opt_machdep.h" |
#include "opt_md.h" |
#include "opt_md.h" |
#include "opt_arm_debug.h" |
|
#include "opt_multiprocessor.h" |
#include "opt_multiprocessor.h" |
#include "opt_cpuoptions.h" |
|
|
#include "genfb.h" |
|
#include "ukbd.h" |
|
#include "wsdisplay.h" |
|
|
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/systm.h> |
#include <sys/systm.h> |
Line 42 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 48 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <sys/atomic.h> |
#include <sys/atomic.h> |
#include <sys/cpu.h> |
#include <sys/cpu.h> |
#include <sys/device.h> |
#include <sys/device.h> |
|
#include <sys/endian.h> |
#include <sys/exec.h> |
#include <sys/exec.h> |
#include <sys/kernel.h> |
#include <sys/kernel.h> |
#include <sys/kmem.h> |
#include <sys/kmem.h> |
Line 50 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 57 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <sys/proc.h> |
#include <sys/proc.h> |
#include <sys/reboot.h> |
#include <sys/reboot.h> |
#include <sys/termios.h> |
#include <sys/termios.h> |
|
#include <sys/bootblock.h> |
|
#include <sys/disklabel.h> |
|
#include <sys/vnode.h> |
|
#include <sys/kauth.h> |
|
#include <sys/fcntl.h> |
|
#include <sys/uuid.h> |
|
#include <sys/disk.h> |
|
#include <sys/md5.h> |
|
#include <sys/pserialize.h> |
|
#include <sys/rnd.h> |
|
#include <sys/rndsource.h> |
|
|
|
#include <net/if.h> |
|
#include <net/if_dl.h> |
|
|
|
#include <dev/cons.h> |
#include <uvm/uvm_extern.h> |
#include <uvm/uvm_extern.h> |
|
|
#include <sys/conf.h> |
#include <sys/conf.h> |
Line 61 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 83 __KERNEL_RCSID(0, "$NetBSD$"); |
|
|
|
#include <machine/bootconfig.h> |
#include <machine/bootconfig.h> |
#include <arm/armreg.h> |
#include <arm/armreg.h> |
#include <arm/undefined.h> |
|
|
|
#include <arm/arm32/machdep.h> |
#include <arm/cpufunc.h> |
|
|
#include <evbarm/include/autoconf.h> |
#include <evbarm/include/autoconf.h> |
|
#include <evbarm/fdt/machdep.h> |
#include <evbarm/fdt/platform.h> |
#include <evbarm/fdt/platform.h> |
|
|
#include <arm/fdt/arm_fdtvar.h> |
#include <arm/fdt/arm_fdtvar.h> |
|
#include <dev/fdt/fdt_private.h> |
|
#include <dev/fdt/fdt_memory.h> |
|
|
|
#ifdef EFI_RUNTIME |
|
#include <arm/arm/efi_runtime.h> |
|
#endif |
|
|
|
#if NWSDISPLAY > 0 && NGENFB > 0 |
|
#include <arm/fdt/arm_simplefb.h> |
|
#endif |
|
|
|
#if NUKBD > 0 |
|
#include <dev/usb/ukbdvar.h> |
|
#endif |
|
#if NWSDISPLAY > 0 |
|
#include <dev/wscons/wsdisplayvar.h> |
|
#endif |
|
|
|
#ifdef MEMORY_DISK_DYNAMIC |
|
#include <dev/md.h> |
|
#endif |
|
|
#ifndef FDT_MAX_BOOT_STRING |
#ifndef FDT_MAX_BOOT_STRING |
#define FDT_MAX_BOOT_STRING 1024 |
#define FDT_MAX_BOOT_STRING 1024 |
Line 77 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 120 __KERNEL_RCSID(0, "$NetBSD$"); |
|
BootConfig bootconfig; |
BootConfig bootconfig; |
char bootargs[FDT_MAX_BOOT_STRING] = ""; |
char bootargs[FDT_MAX_BOOT_STRING] = ""; |
char *boot_args = NULL; |
char *boot_args = NULL; |
u_int uboot_args[4] = { 0 }; /* filled in by xxx_start.S (not in bss) */ |
|
|
/* filled in before cleaning bss. keep in .data */ |
|
u_long uboot_args[4] __attribute__((__section__(".data"))); |
|
const uint8_t *fdt_addr_r __attribute__((__section__(".data"))); |
|
|
|
static uint64_t initrd_start, initrd_end; |
|
static uint64_t rndseed_start, rndseed_end; /* our on-disk seed */ |
|
static uint64_t efirng_start, efirng_end; /* firmware's EFI RNG output */ |
|
|
#include <libfdt.h> |
#include <libfdt.h> |
#include <dev/fdt/fdtvar.h> |
#include <dev/fdt/fdtvar.h> |
#define FDT_BUF_SIZE (128*1024) |
#define FDT_BUF_SIZE (512*1024) |
static uint8_t fdt_data[FDT_BUF_SIZE]; |
static uint8_t fdt_data[FDT_BUF_SIZE]; |
|
|
extern char KERNEL_BASE_phys[]; |
extern char KERNEL_BASE_phys[]; |
Line 89 extern char KERNEL_BASE_phys[]; |
|
Line 139 extern char KERNEL_BASE_phys[]; |
|
|
|
static void fdt_update_stdout_path(void); |
static void fdt_update_stdout_path(void); |
static void fdt_device_register(device_t, void *); |
static void fdt_device_register(device_t, void *); |
|
static void fdt_device_register_post_config(device_t, void *); |
|
static void fdt_cpu_rootconf(void); |
static void fdt_reset(void); |
static void fdt_reset(void); |
static void fdt_powerdown(void); |
static void fdt_powerdown(void); |
|
|
#ifdef PMAP_NEED_ALLOC_POOLPAGE |
#if BYTE_ORDER == BIG_ENDIAN |
static struct boot_physmem bp_lowgig = { |
static void fdt_update_fb_format(void); |
.bp_pages = (KERNEL_VM_BASE - KERNEL_BASE) / NBPG, |
|
.bp_freelist = VM_FREELIST_ISADMA, |
|
.bp_flags = 0 |
|
}; |
|
#endif |
#endif |
|
|
#ifdef VERBOSE_INIT_ARM |
|
static void |
static void |
fdt_putchar(char c) |
earlyconsputc(dev_t dev, int c) |
{ |
{ |
const struct arm_platform *plat = arm_fdt_platform(); |
uartputc(c); |
if (plat && plat->early_putchar) |
|
plat->early_putchar(c); |
|
} |
} |
|
|
|
static int |
|
earlyconsgetc(dev_t dev) |
|
{ |
|
return 0; |
|
} |
|
|
|
static struct consdev earlycons = { |
|
.cn_putc = earlyconsputc, |
|
.cn_getc = earlyconsgetc, |
|
.cn_pollc = nullcnpollc, |
|
}; |
|
|
|
#ifdef VERBOSE_INIT_ARM |
|
#define VPRINTF(...) printf(__VA_ARGS__) |
|
#else |
|
#define VPRINTF(...) __nothing |
|
#endif |
|
|
static void |
static void |
fdt_putstr(const char *s) |
fdt_add_dram_blocks(const struct fdt_memory *m, void *arg) |
{ |
{ |
for (const char *p = s; *p; p++) |
BootConfig *bc = arg; |
fdt_putchar(*p); |
|
|
VPRINTF(" %" PRIx64 " - %" PRIx64 "\n", m->start, m->end - 1); |
|
bc->dram[bc->dramblocks].address = m->start; |
|
bc->dram[bc->dramblocks].pages = |
|
(m->end - m->start) / PAGE_SIZE; |
|
bc->dramblocks++; |
} |
} |
|
|
|
#define MAX_PHYSMEM 64 |
|
static int nfdt_physmem = 0; |
|
static struct boot_physmem fdt_physmem[MAX_PHYSMEM]; |
|
|
static void |
static void |
fdt_printn(u_int n, int base) |
fdt_add_boot_physmem(const struct fdt_memory *m, void *arg) |
{ |
{ |
char *p, buf[(sizeof(u_int) * NBBY / 3) + 1 + 2 /* ALT + SIGN */]; |
const paddr_t saddr = round_page(m->start); |
|
const paddr_t eaddr = trunc_page(m->end); |
|
|
p = buf; |
VPRINTF(" %" PRIx64 " - %" PRIx64, m->start, m->end - 1); |
do { |
if (saddr >= eaddr) { |
*p++ = hexdigits[n % base]; |
VPRINTF(" skipped\n"); |
} while (n /= base); |
return; |
|
} |
|
VPRINTF("\n"); |
|
|
do { |
struct boot_physmem *bp = &fdt_physmem[nfdt_physmem++]; |
fdt_putchar(*--p); |
|
} while (p > buf); |
KASSERT(nfdt_physmem <= MAX_PHYSMEM); |
} |
|
#define DPRINTF(...) printf(__VA_ARGS__) |
bp->bp_start = atop(saddr); |
#define DPRINT(x) fdt_putstr(x) |
bp->bp_pages = atop(eaddr) - bp->bp_start; |
#define DPRINTN(x,b) fdt_printn((x), (b)) |
bp->bp_freelist = VM_FREELIST_DEFAULT; |
#else |
|
#define DPRINTF(...) |
#ifdef PMAP_NEED_ALLOC_POOLPAGE |
#define DPRINT(x) |
const uint64_t memory_size = *(uint64_t *)arg; |
#define DPRINTN(x,b) |
if (atop(memory_size) > bp->bp_pages) { |
|
arm_poolpage_vmfreelist = VM_FREELIST_DIRECTMAP; |
|
bp->bp_freelist = VM_FREELIST_DIRECTMAP; |
|
} |
#endif |
#endif |
|
} |
|
|
|
|
|
static void |
|
fdt_print_memory(const struct fdt_memory *m, void *arg) |
|
{ |
|
|
|
VPRINTF("FDT /memory @ 0x%" PRIx64 " size 0x%" PRIx64 "\n", |
|
m->start, m->end - m->start); |
|
} |
|
|
|
|
/* |
/* |
* Get the first physically contiguous region of memory. |
* Define usable memory regions. |
*/ |
*/ |
static void |
static void |
fdt_get_memory(uint64_t *paddr, uint64_t *psize) |
fdt_build_bootconfig(uint64_t mem_start, uint64_t mem_end) |
{ |
{ |
const int memory = OF_finddevice("/memory"); |
BootConfig *bc = &bootconfig; |
uint64_t cur_addr, cur_size; |
|
|
uint64_t addr, size; |
int index; |
int index; |
|
|
/* Assume the first entry is the start of memory */ |
fdt_memory_remove_reserved(mem_start, mem_end); |
if (fdtbus_get_reg64(memory, 0, paddr, psize) != 0) |
|
panic("Cannot determine memory size"); |
const uint64_t initrd_size = |
|
round_page(initrd_end) - trunc_page(initrd_start); |
|
if (initrd_size > 0) |
|
fdt_memory_remove_range(trunc_page(initrd_start), initrd_size); |
|
|
|
const uint64_t rndseed_size = |
|
round_page(rndseed_end) - trunc_page(rndseed_start); |
|
if (rndseed_size > 0) |
|
fdt_memory_remove_range(trunc_page(rndseed_start), |
|
rndseed_size); |
|
|
|
const uint64_t efirng_size = |
|
round_page(efirng_end) - trunc_page(efirng_start); |
|
if (efirng_size > 0) |
|
fdt_memory_remove_range(trunc_page(efirng_start), efirng_size); |
|
|
|
const int framebuffer = OF_finddevice("/chosen/framebuffer"); |
|
if (framebuffer >= 0) { |
|
for (index = 0; |
|
fdtbus_get_reg64(framebuffer, index, &addr, &size) == 0; |
|
index++) { |
|
fdt_memory_remove_range(addr, size); |
|
} |
|
} |
|
|
|
VPRINTF("Usable memory:\n"); |
|
bc->dramblocks = 0; |
|
fdt_memory_foreach(fdt_add_dram_blocks, bc); |
|
} |
|
|
|
static void |
|
fdt_probe_range(const char *startname, const char *endname, |
|
uint64_t *pstart, uint64_t *pend) |
|
{ |
|
int chosen, len; |
|
const void *start_data, *end_data; |
|
|
|
*pstart = *pend = 0; |
|
|
|
chosen = OF_finddevice("/chosen"); |
|
if (chosen < 0) |
|
return; |
|
|
|
start_data = fdtbus_get_prop(chosen, startname, &len); |
|
end_data = fdtbus_get_prop(chosen, endname, NULL); |
|
if (start_data == NULL || end_data == NULL) |
|
return; |
|
|
|
switch (len) { |
|
case 4: |
|
*pstart = be32dec(start_data); |
|
*pend = be32dec(end_data); |
|
break; |
|
case 8: |
|
*pstart = be64dec(start_data); |
|
*pend = be64dec(end_data); |
|
break; |
|
default: |
|
printf("Unsupported len %d for /chosen `%s'\n", |
|
len, startname); |
|
return; |
|
} |
|
} |
|
|
|
static void * |
|
fdt_map_range(uint64_t start, uint64_t end, uint64_t *psize, |
|
const char *purpose) |
|
{ |
|
const paddr_t startpa = trunc_page(start); |
|
const paddr_t endpa = round_page(end); |
|
paddr_t pa; |
|
vaddr_t va; |
|
void *ptr; |
|
|
|
*psize = end - start; |
|
if (*psize == 0) |
|
return NULL; |
|
|
|
const vaddr_t voff = start & PAGE_MASK; |
|
|
|
va = uvm_km_alloc(kernel_map, *psize, 0, UVM_KMF_VAONLY|UVM_KMF_NOWAIT); |
|
if (va == 0) { |
|
printf("Failed to allocate VA for %s\n", purpose); |
|
return NULL; |
|
} |
|
ptr = (void *)(va + voff); |
|
|
|
for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) |
|
pmap_kenter_pa(va, pa, VM_PROT_READ|VM_PROT_WRITE, 0); |
|
pmap_update(pmap_kernel()); |
|
|
|
return ptr; |
|
} |
|
|
|
static void |
|
fdt_unmap_range(void *ptr, uint64_t size) |
|
{ |
|
const char *start = ptr, *end = start + size; |
|
const vaddr_t startva = trunc_page((vaddr_t)(uintptr_t)start); |
|
const vaddr_t endva = round_page((vaddr_t)(uintptr_t)end); |
|
|
|
pmap_kremove(startva, endva - startva); |
|
pmap_update(pmap_kernel()); |
|
} |
|
|
|
static void |
|
fdt_probe_initrd(uint64_t *pstart, uint64_t *pend) |
|
{ |
|
*pstart = *pend = 0; |
|
|
|
#ifdef MEMORY_DISK_DYNAMIC |
|
fdt_probe_range("linux,initrd-start", "linux,initrd-end", pstart, pend); |
|
#endif |
|
} |
|
|
|
static void |
|
fdt_setup_initrd(void) |
|
{ |
|
#ifdef MEMORY_DISK_DYNAMIC |
|
void *md_start; |
|
uint64_t initrd_size; |
|
|
|
md_start = fdt_map_range(initrd_start, initrd_end, &initrd_size, |
|
"initrd"); |
|
if (md_start == NULL) |
|
return; |
|
md_root_setconf(md_start, initrd_size); |
|
#endif |
|
} |
|
|
|
static void |
|
fdt_probe_rndseed(uint64_t *pstart, uint64_t *pend) |
|
{ |
|
|
|
fdt_probe_range("netbsd,rndseed-start", "netbsd,rndseed-end", |
|
pstart, pend); |
|
} |
|
|
|
static void |
|
fdt_setup_rndseed(void) |
|
{ |
|
uint64_t rndseed_size; |
|
void *rndseed; |
|
|
|
rndseed = fdt_map_range(rndseed_start, rndseed_end, &rndseed_size, |
|
"rndseed"); |
|
if (rndseed == NULL) |
|
return; |
|
rnd_seed(rndseed, rndseed_size); |
|
fdt_unmap_range(rndseed, rndseed_size); |
|
} |
|
|
|
static void |
|
fdt_probe_efirng(uint64_t *pstart, uint64_t *pend) |
|
{ |
|
|
|
fdt_probe_range("netbsd,efirng-start", "netbsd,efirng-end", |
|
pstart, pend); |
|
} |
|
|
|
static struct krndsource efirng_source; |
|
|
|
static void |
|
fdt_setup_efirng(void) |
|
{ |
|
uint64_t efirng_size; |
|
void *efirng; |
|
|
|
efirng = fdt_map_range(efirng_start, efirng_end, &efirng_size, |
|
"efirng"); |
|
if (efirng == NULL) |
|
return; |
|
|
|
rnd_attach_source(&efirng_source, "efirng", RND_TYPE_RNG, |
|
RND_FLAG_DEFAULT); |
|
|
|
/* |
|
* We don't really have specific information about the physical |
|
* process underlying the data provided by the firmware via the |
|
* EFI RNG API, so the entropy estimate here is heuristic. |
|
* What efiboot provides us is up to 4096 bytes of data from |
|
* the EFI RNG API, although in principle it may return short. |
|
* |
|
* The UEFI Specification (2.8 Errata A, February 2020[1]) says |
|
* |
|
* When a Deterministic Random Bit Generator (DRBG) is |
|
* used on the output of a (raw) entropy source, its |
|
* security level must be at least 256 bits. |
|
* |
|
* It's not entirely clear whether `it' refers to the DRBG or |
|
* the entropy source; if it refers to the DRBG, it's not |
|
* entirely clear how ANSI X9.31 3DES, one of the options for |
|
* DRBG in the UEFI spec, can provide a `256-bit security |
|
* level' because it has only 232 bits of inputs (three 56-bit |
|
* keys and one 64-bit block). That said, even if it provides |
|
* only 232 bits of entropy, that's enough to prevent all |
|
* attacks and we probably get a few more bits from sampling |
|
* the clock anyway. |
|
* |
|
* In the event we get raw samples, e.g. the bits sampled by a |
|
* ring oscillator, we hope that the samples have at least half |
|
* a bit of entropy per bit of data -- and efiboot tries to |
|
* draw 4096 bytes to provide plenty of slop. Hence we divide |
|
* the total number of bits by two and clamp at 256. There are |
|
* ways this could go wrong, but on most machines it should |
|
* behave reasonably. |
|
* |
|
* [1] https://uefi.org/sites/default/files/resources/UEFI_Spec_2_8_A_Feb14.pdf |
|
*/ |
|
rnd_add_data(&efirng_source, efirng, efirng_size, |
|
MIN(256, efirng_size*NBBY/2)); |
|
|
|
explicit_memset(efirng, 0, efirng_size); |
|
fdt_unmap_range(efirng, efirng_size); |
|
} |
|
|
|
#ifdef EFI_RUNTIME |
|
static void |
|
fdt_map_efi_runtime(const char *prop, enum arm_efirt_mem_type type) |
|
{ |
|
int len; |
|
|
DPRINTF("FDT /memory [%d] @ 0x%" PRIx64 " size 0x%" PRIx64 "\n", |
const int chosen_off = fdt_path_offset(fdt_data, "/chosen"); |
0, *paddr, *psize); |
if (chosen_off < 0) |
|
return; |
|
|
/* If subsequent entries follow the previous one, append them. */ |
const uint64_t *map = fdt_getprop(fdt_data, chosen_off, prop, &len); |
for (index = 1; |
if (map == NULL) |
fdtbus_get_reg64(memory, index, &cur_addr, &cur_size) == 0; |
return; |
index++) { |
|
DPRINTF("FDT /memory [%d] @ 0x%" PRIx64 " size 0x%" PRIx64 "\n", |
while (len >= 24) { |
index, cur_addr, cur_size); |
const paddr_t pa = be64toh(map[0]); |
if (*paddr + *psize == cur_addr) |
const vaddr_t va = be64toh(map[1]); |
*psize += cur_size; |
const size_t sz = be64toh(map[2]); |
|
VPRINTF("%s: %s %" PRIxPADDR "-%" PRIxVADDR "(%" PRIxVADDR |
|
"-%" PRIxVSIZE "\n", __func__, prop, pa, pa + sz - 1, |
|
va, va + sz - 1); |
|
arm_efirt_md_map_range(va, pa, sz, type); |
|
map += 3; |
|
len -= 24; |
} |
} |
} |
} |
|
#endif |
|
|
u_int |
vaddr_t |
initarm(void *arg) |
initarm(void *arg) |
{ |
{ |
const struct arm_platform *plat; |
const struct arm_platform *plat; |
uint64_t memory_addr, memory_size; |
uint64_t memory_start, memory_end; |
psize_t ram_size = 0; |
|
|
/* set temporally to work printf()/panic() even before consinit() */ |
|
cn_tab = &earlycons; |
|
|
/* Load FDT */ |
/* Load FDT */ |
const uint8_t *fdt_addr_r = (const uint8_t *)uboot_args[2]; |
|
int error = fdt_check_header(fdt_addr_r); |
int error = fdt_check_header(fdt_addr_r); |
if (error == 0) { |
if (error != 0) |
error = fdt_move(fdt_addr_r, fdt_data, sizeof(fdt_data)); |
|
if (error != 0) |
|
panic("fdt_move failed: %s", fdt_strerror(error)); |
|
fdtbus_set_data(fdt_data); |
|
} else { |
|
panic("fdt_check_header failed: %s", fdt_strerror(error)); |
panic("fdt_check_header failed: %s", fdt_strerror(error)); |
} |
|
|
/* If the DTB is too big, try to pack it in place first. */ |
|
if (fdt_totalsize(fdt_addr_r) > sizeof(fdt_data)) |
|
(void)fdt_pack(__UNCONST(fdt_addr_r)); |
|
|
|
error = fdt_open_into(fdt_addr_r, fdt_data, sizeof(fdt_data)); |
|
if (error != 0) |
|
panic("fdt_move failed: %s", fdt_strerror(error)); |
|
|
|
fdtbus_init(fdt_data); |
|
|
/* Lookup platform specific backend */ |
/* Lookup platform specific backend */ |
plat = arm_fdt_platform(); |
plat = arm_fdt_platform(); |
Line 192 initarm(void *arg) |
|
Line 515 initarm(void *arg) |
|
panic("Kernel does not support this device"); |
panic("Kernel does not support this device"); |
|
|
/* Early console may be available, announce ourselves. */ |
/* Early console may be available, announce ourselves. */ |
DPRINT("FDT<"); |
VPRINTF("FDT<%p>\n", fdt_addr_r); |
DPRINTN((uintptr_t)fdt_addr_r, 16); |
|
DPRINT(">"); |
|
|
|
const int chosen = OF_finddevice("/chosen"); |
const int chosen = OF_finddevice("/chosen"); |
if (chosen >= 0) |
if (chosen >= 0) |
OF_getprop(chosen, "bootargs", bootargs, sizeof(bootargs)); |
OF_getprop(chosen, "bootargs", bootargs, sizeof(bootargs)); |
boot_args = bootargs; |
boot_args = bootargs; |
|
|
DPRINT(" devmap"); |
|
pmap_devmap_register(plat->devmap()); |
|
|
|
DPRINT(" bootstrap"); |
|
plat->bootstrap(); |
|
|
|
/* Heads up ... Setup the CPU / MMU / TLB functions. */ |
/* Heads up ... Setup the CPU / MMU / TLB functions. */ |
DPRINT(" cpufunc"); |
VPRINTF("cpufunc\n"); |
if (set_cpufuncs()) |
if (set_cpufuncs()) |
panic("cpu not recognized!"); |
panic("cpu not recognized!"); |
|
|
/* |
/* |
|
* Memory is still identity/flat mapped this point so using ttbr for |
|
* l1pt VA is fine |
|
*/ |
|
|
|
VPRINTF("devmap %p\n", plat->ap_devmap()); |
|
extern char ARM_BOOTSTRAP_LxPT[]; |
|
pmap_devmap_bootstrap((vaddr_t)ARM_BOOTSTRAP_LxPT, plat->ap_devmap()); |
|
|
|
VPRINTF("bootstrap\n"); |
|
plat->ap_bootstrap(); |
|
|
|
/* |
* If stdout-path is specified on the command line, override the |
* If stdout-path is specified on the command line, override the |
* value in /chosen/stdout-path before initializing console. |
* value in /chosen/stdout-path before initializing console. |
*/ |
*/ |
|
VPRINTF("stdout\n"); |
fdt_update_stdout_path(); |
fdt_update_stdout_path(); |
|
|
DPRINT(" consinit"); |
#if BYTE_ORDER == BIG_ENDIAN |
consinit(); |
/* |
|
* Most boards are configured to little-endian mode in initial, and |
|
* switched to big-endian mode after kernel is loaded. In this case, |
|
* framebuffer seems byte-swapped to CPU. Override FDT to let |
|
* drivers know. |
|
*/ |
|
VPRINTF("fb_format\n"); |
|
fdt_update_fb_format(); |
|
#endif |
|
|
DPRINTF(" ok\n"); |
/* |
|
* Done making changes to the FDT. |
|
*/ |
|
fdt_pack(fdt_data); |
|
|
DPRINTF("uboot: args %#x, %#x, %#x, %#x\n", |
VPRINTF("consinit "); |
|
consinit(); |
|
VPRINTF("ok\n"); |
|
|
|
VPRINTF("uboot: args %#lx, %#lx, %#lx, %#lx\n", |
uboot_args[0], uboot_args[1], uboot_args[2], uboot_args[3]); |
uboot_args[0], uboot_args[1], uboot_args[2], uboot_args[3]); |
|
|
cpu_reset_address = fdt_reset; |
cpu_reset_address = fdt_reset; |
cpu_powerdown_address = fdt_powerdown; |
cpu_powerdown_address = fdt_powerdown; |
evbarm_device_register = fdt_device_register; |
evbarm_device_register = fdt_device_register; |
|
evbarm_device_register_post_config = fdt_device_register_post_config; |
|
evbarm_cpu_rootconf = fdt_cpu_rootconf; |
|
|
/* Talk to the user */ |
/* Talk to the user */ |
DPRINTF("\nNetBSD/evbarm (fdt) booting ...\n"); |
printf("NetBSD/evbarm (fdt) booting ...\n"); |
|
|
#ifdef BOOT_ARGS |
#ifdef BOOT_ARGS |
char mi_bootargs[] = BOOT_ARGS; |
char mi_bootargs[] = BOOT_ARGS; |
parse_mi_bootargs(mi_bootargs); |
parse_mi_bootargs(mi_bootargs); |
#endif |
#endif |
|
|
DPRINTF("KERNEL_BASE=0x%x, " |
fdt_memory_get(&memory_start, &memory_end); |
"KERNEL_VM_BASE=0x%x, " |
|
"KERNEL_VM_BASE - KERNEL_BASE=0x%x, " |
|
"KERNEL_BASE_VOFFSET=0x%x\n", |
|
KERNEL_BASE, |
|
KERNEL_VM_BASE, |
|
KERNEL_VM_BASE - KERNEL_BASE, |
|
KERNEL_BASE_VOFFSET); |
|
|
|
fdt_get_memory(&memory_addr, &memory_size); |
fdt_memory_foreach(fdt_print_memory, NULL); |
|
|
#if !defined(_LP64) |
#if !defined(_LP64) |
/* Cannot map memory above 4GB */ |
/* Cannot map memory above 4GB (remove last page as well) */ |
if (memory_addr + memory_size > 0x100000000) |
const uint64_t memory_limit = 0x100000000ULL - PAGE_SIZE; |
memory_size = 0x100000000 - memory_addr; |
if (memory_end > memory_limit) { |
#endif |
fdt_memory_remove_range(memory_limit , memory_end); |
|
memory_end = memory_limit; |
ram_size = (bus_size_t)memory_size; |
|
|
|
#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS |
|
const bool mapallmem_p = true; |
|
#ifndef PMAP_NEED_ALLOC_POOLPAGE |
|
if (ram_size > KERNEL_VM_BASE - KERNEL_BASE) { |
|
DPRINTF("%s: dropping RAM size from %luMB to %uMB\n", |
|
__func__, (unsigned long) (ram_size >> 20), |
|
(KERNEL_VM_BASE - KERNEL_BASE) >> 20); |
|
ram_size = KERNEL_VM_BASE - KERNEL_BASE; |
|
} |
} |
#endif |
#endif |
#else |
uint64_t memory_size = memory_end - memory_start; |
const bool mapallmem_p = false; |
|
#endif |
VPRINTF("%s: memory start %" PRIx64 " end %" PRIx64 " (len %" |
|
PRIx64 ")\n", __func__, memory_start, memory_end, memory_size); |
|
|
/* Fake bootconfig structure for the benefit of pmap.c. */ |
/* Parse ramdisk info */ |
bootconfig.dramblocks = 1; |
fdt_probe_initrd(&initrd_start, &initrd_end); |
bootconfig.dram[0].address = (bus_addr_t)memory_addr; |
|
bootconfig.dram[0].pages = ram_size / PAGE_SIZE; |
|
|
|
arm32_bootmem_init(bootconfig.dram[0].address, ram_size, |
/* Parse our on-disk rndseed and the firmware's RNG from EFI */ |
KERNEL_BASE_PHYS); |
fdt_probe_rndseed(&rndseed_start, &rndseed_end); |
arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0, |
fdt_probe_efirng(&efirng_start, &efirng_end); |
plat->devmap(), mapallmem_p); |
|
|
|
DPRINTF("bootargs: %s\n", bootargs); |
/* |
|
* Populate bootconfig structure for the benefit of dodumpsys |
|
*/ |
|
VPRINTF("%s: fdt_build_bootconfig\n", __func__); |
|
fdt_build_bootconfig(memory_start, memory_end); |
|
|
|
#ifdef EFI_RUNTIME |
|
fdt_map_efi_runtime("netbsd,uefi-runtime-code", ARM_EFIRT_MEM_CODE); |
|
fdt_map_efi_runtime("netbsd,uefi-runtime-data", ARM_EFIRT_MEM_DATA); |
|
fdt_map_efi_runtime("netbsd,uefi-runtime-mmio", ARM_EFIRT_MEM_MMIO); |
|
#endif |
|
|
|
/* Perform PT build and VM init */ |
|
cpu_kernel_vm_init(memory_start, memory_size); |
|
|
|
VPRINTF("bootargs: %s\n", bootargs); |
|
|
parse_mi_bootargs(boot_args); |
parse_mi_bootargs(boot_args); |
|
|
#ifdef PMAP_NEED_ALLOC_POOLPAGE |
VPRINTF("Memory regions:\n"); |
bp_lowgig.bp_start = memory_addr / NBPG; |
|
if (atop(ram_size) > bp_lowgig.bp_pages) { |
/* Populate fdt_physmem / nfdt_physmem for initarm_common */ |
arm_poolpage_vmfreelist = bp_lowgig.bp_freelist; |
fdt_memory_foreach(fdt_add_boot_physmem, &memory_size); |
return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, |
|
&bp_lowgig, 1); |
vaddr_t sp = initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, fdt_physmem, |
|
nfdt_physmem); |
|
|
|
/* |
|
* initarm_common flushes cache if required before AP start |
|
*/ |
|
error = 0; |
|
if ((boothowto & RB_MD1) == 0) { |
|
VPRINTF("mpstart\n"); |
|
if (plat->ap_mpstart) |
|
error = plat->ap_mpstart(); |
} |
} |
#endif |
|
|
|
return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0); |
if (error) |
|
return sp; |
|
|
|
/* |
|
* Now we have APs started the pages used for stacks and L1PT can |
|
* be given to uvm |
|
*/ |
|
extern char const __start__init_memory[]; |
|
extern char const __stop__init_memory[] __weak; |
|
|
|
if (__start__init_memory != __stop__init_memory) { |
|
const paddr_t spa = KERN_VTOPHYS((vaddr_t)__start__init_memory); |
|
const paddr_t epa = KERN_VTOPHYS((vaddr_t)__stop__init_memory); |
|
const paddr_t spg = atop(spa); |
|
const paddr_t epg = atop(epa); |
|
|
|
VPRINTF(" start %08lx end %08lx... " |
|
"loading in freelist %d\n", spa, epa, VM_FREELIST_DEFAULT); |
|
|
|
uvm_page_physload(spg, epg, spg, epg, VM_FREELIST_DEFAULT); |
|
|
|
} |
|
|
|
return sp; |
} |
} |
|
|
static void |
static void |
|
|
if (initialized || cons == NULL) |
if (initialized || cons == NULL) |
return; |
return; |
|
|
plat->init_attach_args(&faa); |
plat->ap_init_attach_args(&faa); |
faa.faa_phandle = fdtbus_get_stdout_phandle(); |
faa.faa_phandle = fdtbus_get_stdout_phandle(); |
|
|
if (plat->uart_freq != NULL) |
if (plat->ap_uart_freq != NULL) |
uart_freq = plat->uart_freq(); |
uart_freq = plat->ap_uart_freq(); |
|
|
cons->consinit(&faa, uart_freq); |
cons->consinit(&faa, uart_freq); |
|
|
|
|
} |
} |
|
|
void |
void |
|
cpu_startup_hook(void) |
|
{ |
|
|
|
fdtbus_intr_init(); |
|
|
|
fdt_setup_rndseed(); |
|
fdt_setup_efirng(); |
|
} |
|
|
|
void |
delay(u_int us) |
delay(u_int us) |
{ |
{ |
const struct arm_platform *plat = arm_fdt_platform(); |
const struct arm_platform *plat = arm_fdt_platform(); |
|
|
plat->delay(us); |
plat->ap_delay(us); |
|
} |
|
|
|
static void |
|
fdt_detect_root_device(device_t dev) |
|
{ |
|
struct mbr_sector mbr; |
|
uint8_t buf[DEV_BSIZE]; |
|
uint8_t hash[16]; |
|
const uint8_t *rhash; |
|
char rootarg[64]; |
|
struct vnode *vp; |
|
MD5_CTX md5ctx; |
|
int error, len; |
|
size_t resid; |
|
u_int part; |
|
|
|
const int chosen = OF_finddevice("/chosen"); |
|
if (chosen < 0) |
|
return; |
|
|
|
if (of_hasprop(chosen, "netbsd,mbr") && |
|
of_hasprop(chosen, "netbsd,partition")) { |
|
|
|
/* |
|
* The bootloader has passed in a partition index and MD5 hash |
|
* of the MBR sector. Read the MBR of this device, calculate the |
|
* hash, and compare it with the value passed in. |
|
*/ |
|
rhash = fdtbus_get_prop(chosen, "netbsd,mbr", &len); |
|
if (rhash == NULL || len != 16) |
|
return; |
|
of_getprop_uint32(chosen, "netbsd,partition", &part); |
|
if (part >= MAXPARTITIONS) |
|
return; |
|
|
|
vp = opendisk(dev); |
|
if (!vp) |
|
return; |
|
error = vn_rdwr(UIO_READ, vp, buf, sizeof(buf), 0, UIO_SYSSPACE, |
|
0, NOCRED, &resid, NULL); |
|
VOP_CLOSE(vp, FREAD, NOCRED); |
|
vput(vp); |
|
|
|
if (error != 0) |
|
return; |
|
|
|
memcpy(&mbr, buf, sizeof(mbr)); |
|
MD5Init(&md5ctx); |
|
MD5Update(&md5ctx, (void *)&mbr, sizeof(mbr)); |
|
MD5Final(hash, &md5ctx); |
|
|
|
if (memcmp(rhash, hash, 16) != 0) |
|
return; |
|
|
|
snprintf(rootarg, sizeof(rootarg), " root=%s%c", device_xname(dev), part + 'a'); |
|
strcat(boot_args, rootarg); |
|
} |
|
|
|
if (of_hasprop(chosen, "netbsd,gpt-guid")) { |
|
char guidbuf[UUID_STR_LEN]; |
|
const struct uuid *guid = fdtbus_get_prop(chosen, "netbsd,gpt-guid", &len); |
|
if (guid == NULL || len != 16) |
|
return; |
|
|
|
uuid_snprintf(guidbuf, sizeof(guidbuf), guid); |
|
snprintf(rootarg, sizeof(rootarg), " root=wedge:%s", guidbuf); |
|
strcat(boot_args, rootarg); |
|
} |
|
|
|
if (of_hasprop(chosen, "netbsd,gpt-label")) { |
|
const char *label = fdtbus_get_string(chosen, "netbsd,gpt-label"); |
|
if (label == NULL || *label == '\0') |
|
return; |
|
|
|
device_t dv = dkwedge_find_by_wname(label); |
|
if (dv != NULL) |
|
booted_device = dv; |
|
} |
|
|
|
if (of_hasprop(chosen, "netbsd,booted-mac-address")) { |
|
const uint8_t *macaddr = fdtbus_get_prop(chosen, "netbsd,booted-mac-address", &len); |
|
if (macaddr == NULL || len != 6) |
|
return; |
|
int s = pserialize_read_enter(); |
|
struct ifnet *ifp; |
|
IFNET_READER_FOREACH(ifp) { |
|
if (memcmp(macaddr, CLLADDR(ifp->if_sadl), len) == 0) { |
|
device_t dv = device_find_by_xname(ifp->if_xname); |
|
if (dv != NULL) |
|
booted_device = dv; |
|
break; |
|
} |
|
} |
|
pserialize_read_exit(s); |
|
} |
} |
} |
|
|
static void |
static void |
Line 360 fdt_device_register(device_t self, void |
|
Line 837 fdt_device_register(device_t self, void |
|
{ |
{ |
const struct arm_platform *plat = arm_fdt_platform(); |
const struct arm_platform *plat = arm_fdt_platform(); |
|
|
if (plat && plat->device_register) |
if (device_is_a(self, "armfdt")) { |
plat->device_register(self, aux); |
fdt_setup_initrd(); |
|
|
|
#if NWSDISPLAY > 0 && NGENFB > 0 |
|
/* |
|
* Setup framebuffer console, if present. |
|
*/ |
|
arm_simplefb_preattach(); |
|
#endif |
|
} |
|
|
|
#if NWSDISPLAY > 0 && NGENFB > 0 |
|
if (device_is_a(self, "genfb")) { |
|
prop_dictionary_t dict = device_properties(self); |
|
prop_dictionary_set_uint64(dict, |
|
"simplefb-physaddr", arm_simplefb_physaddr()); |
|
} |
|
#endif |
|
|
|
if (plat && plat->ap_device_register) |
|
plat->ap_device_register(self, aux); |
|
} |
|
|
|
static void |
|
fdt_device_register_post_config(device_t self, void *aux) |
|
{ |
|
#if NUKBD > 0 && NWSDISPLAY > 0 |
|
if (device_is_a(self, "wsdisplay")) { |
|
struct wsdisplay_softc *sc = device_private(self); |
|
if (wsdisplay_isconsole(sc)) |
|
ukbd_cnattach(); |
|
} |
|
#endif |
|
} |
|
|
|
static void |
|
fdt_cpu_rootconf(void) |
|
{ |
|
device_t dev; |
|
deviter_t di; |
|
char *ptr; |
|
|
|
for (dev = deviter_first(&di, 0); dev; dev = deviter_next(&di)) { |
|
if (device_class(dev) != DV_DISK) |
|
continue; |
|
|
|
if (get_bootconf_option(boot_args, "root", BOOTOPT_TYPE_STRING, &ptr) != 0) |
|
break; |
|
|
|
if (device_is_a(dev, "ld") || device_is_a(dev, "sd") || device_is_a(dev, "wd")) |
|
fdt_detect_root_device(dev); |
|
} |
|
deviter_release(&di); |
} |
} |
|
|
static void |
static void |
|
|
|
|
fdtbus_power_reset(); |
fdtbus_power_reset(); |
|
|
if (plat && plat->reset) |
if (plat && plat->ap_reset) |
plat->reset(); |
plat->ap_reset(); |
} |
} |
|
|
static void |
static void |
Line 380 fdt_powerdown(void) |
|
Line 908 fdt_powerdown(void) |
|
{ |
{ |
fdtbus_power_poweroff(); |
fdtbus_power_poweroff(); |
} |
} |
|
|
|
#if BYTE_ORDER == BIG_ENDIAN |
|
static void |
|
fdt_update_fb_format(void) |
|
{ |
|
int off, len; |
|
const char *format, *replace; |
|
|
|
off = fdt_path_offset(fdt_data, "/chosen"); |
|
if (off < 0) |
|
return; |
|
|
|
for (;;) { |
|
off = fdt_node_offset_by_compatible(fdt_data, off, |
|
"simple-framebuffer"); |
|
if (off < 0) |
|
return; |
|
|
|
format = fdt_getprop(fdt_data, off, "format", &len); |
|
if (format == NULL) |
|
continue; |
|
|
|
replace = NULL; |
|
if (strcmp(format, "a8b8g8r8") == 0) |
|
replace = "r8g8b8a8"; |
|
else if (strcmp(format, "x8r8g8b8") == 0) |
|
replace = "b8g8r8x8"; |
|
if (replace != NULL) |
|
fdt_setprop(fdt_data, off, "format", replace, |
|
strlen(replace) + 1); |
|
} |
|
} |
|
#endif |