version 1.63, 2019/07/15 08:44:33 |
version 1.105, 2023/07/10 07:01:48 |
|
|
#include <sys/cdefs.h> |
#include <sys/cdefs.h> |
__KERNEL_RCSID(0, "$NetBSD$"); |
__KERNEL_RCSID(0, "$NetBSD$"); |
|
|
#include "opt_machdep.h" |
|
#include "opt_bootconfig.h" |
|
#include "opt_ddb.h" |
|
#include "opt_md.h" |
|
#include "opt_arm_debug.h" |
#include "opt_arm_debug.h" |
#include "opt_multiprocessor.h" |
#include "opt_bootconfig.h" |
#include "opt_cpuoptions.h" |
#include "opt_cpuoptions.h" |
|
#include "opt_ddb.h" |
#include "opt_efi.h" |
#include "opt_efi.h" |
|
#include "opt_machdep.h" |
|
#include "opt_multiprocessor.h" |
|
|
|
#include "genfb.h" |
#include "ukbd.h" |
#include "ukbd.h" |
#include "wsdisplay.h" |
#include "wsdisplay.h" |
|
|
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/systm.h> |
#include <sys/types.h> |
#include <sys/bus.h> |
|
#include <sys/atomic.h> |
#include <sys/atomic.h> |
|
#include <sys/bootblock.h> |
|
#include <sys/bus.h> |
|
#include <sys/conf.h> |
#include <sys/cpu.h> |
#include <sys/cpu.h> |
#include <sys/device.h> |
#include <sys/device.h> |
|
#include <sys/disk.h> |
|
#include <sys/disklabel.h> |
|
#include <sys/endian.h> |
#include <sys/exec.h> |
#include <sys/exec.h> |
|
#include <sys/fcntl.h> |
|
#include <sys/kauth.h> |
#include <sys/kernel.h> |
#include <sys/kernel.h> |
#include <sys/kmem.h> |
#include <sys/kmem.h> |
#include <sys/ksyms.h> |
#include <sys/ksyms.h> |
|
#include <sys/md5.h> |
#include <sys/msgbuf.h> |
#include <sys/msgbuf.h> |
#include <sys/proc.h> |
#include <sys/proc.h> |
|
#include <sys/pserialize.h> |
#include <sys/reboot.h> |
#include <sys/reboot.h> |
|
#include <sys/systm.h> |
#include <sys/termios.h> |
#include <sys/termios.h> |
#include <sys/bootblock.h> |
|
#include <sys/disklabel.h> |
|
#include <sys/vnode.h> |
#include <sys/vnode.h> |
#include <sys/kauth.h> |
|
#include <sys/fcntl.h> |
|
#include <sys/uuid.h> |
#include <sys/uuid.h> |
#include <sys/disk.h> |
|
#include <sys/md5.h> |
|
#include <sys/pserialize.h> |
|
|
|
#include <net/if.h> |
#include <net/if.h> |
#include <net/if_dl.h> |
#include <net/if_dl.h> |
Line 71 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 75 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <dev/cons.h> |
#include <dev/cons.h> |
#include <uvm/uvm_extern.h> |
#include <uvm/uvm_extern.h> |
|
|
#include <sys/conf.h> |
|
|
|
#include <machine/db_machdep.h> |
#include <machine/db_machdep.h> |
#include <ddb/db_sym.h> |
#include <ddb/db_sym.h> |
#include <ddb/db_extern.h> |
#include <ddb/db_extern.h> |
Line 85 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 87 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <evbarm/include/autoconf.h> |
#include <evbarm/include/autoconf.h> |
#include <evbarm/fdt/machdep.h> |
#include <evbarm/fdt/machdep.h> |
#include <evbarm/fdt/platform.h> |
#include <evbarm/fdt/platform.h> |
#include <evbarm/fdt/fdt_memory.h> |
|
|
|
#include <arm/fdt/arm_fdtvar.h> |
#include <arm/fdt/arm_fdtvar.h> |
|
|
|
#include <dev/fdt/fdtvar.h> |
|
#include <dev/fdt/fdt_boot.h> |
|
#include <dev/fdt/fdt_private.h> |
|
#include <dev/fdt/fdt_memory.h> |
|
|
#ifdef EFI_RUNTIME |
#ifdef EFI_RUNTIME |
#include <arm/arm/efi_runtime.h> |
#include <arm/arm/efi_runtime.h> |
#endif |
#endif |
|
|
|
#if NWSDISPLAY > 0 && NGENFB > 0 |
|
#include <arm/fdt/arm_simplefb.h> |
|
#endif |
|
|
#if NUKBD > 0 |
#if NUKBD > 0 |
#include <dev/usb/ukbdvar.h> |
#include <dev/usb/ukbdvar.h> |
#endif |
#endif |
Line 100 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 110 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <dev/wscons/wsdisplayvar.h> |
#include <dev/wscons/wsdisplayvar.h> |
#endif |
#endif |
|
|
#ifdef MEMORY_DISK_DYNAMIC |
|
#include <dev/md.h> |
|
#endif |
|
|
|
#ifndef FDT_MAX_BOOT_STRING |
|
#define FDT_MAX_BOOT_STRING 1024 |
|
#endif |
|
|
|
BootConfig bootconfig; |
BootConfig bootconfig; |
char bootargs[FDT_MAX_BOOT_STRING] = ""; |
|
char *boot_args = NULL; |
char *boot_args = NULL; |
|
|
/* filled in before cleaning bss. keep in .data */ |
/* filled in before cleaning bss. keep in .data */ |
u_long uboot_args[4] __attribute__((__section__(".data"))); |
u_long uboot_args[4] __attribute__((__section__(".data"))); |
const uint8_t *fdt_addr_r __attribute__((__section__(".data"))); |
const uint8_t *fdt_addr_r __attribute__((__section__(".data"))); |
|
|
static uint64_t initrd_start, initrd_end; |
|
|
|
#include <libfdt.h> |
#include <libfdt.h> |
#include <dev/fdt/fdtvar.h> |
#include <dev/fdt/fdtvar.h> |
#define FDT_BUF_SIZE (512*1024) |
#define FDT_BUF_SIZE (512*1024) |
Line 126 static uint8_t fdt_data[FDT_BUF_SIZE]; |
|
Line 125 static uint8_t fdt_data[FDT_BUF_SIZE]; |
|
extern char KERNEL_BASE_phys[]; |
extern char KERNEL_BASE_phys[]; |
#define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys) |
#define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys) |
|
|
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_device_register_post_config(device_t, void *); |
static void fdt_cpu_rootconf(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); |
|
|
|
#if BYTE_ORDER == BIG_ENDIAN |
|
static void fdt_update_fb_format(void); |
|
#endif |
|
|
static void |
static void |
earlyconsputc(dev_t dev, int c) |
earlyconsputc(dev_t dev, int c) |
{ |
{ |
Line 142 earlyconsputc(dev_t dev, int c) |
|
Line 144 earlyconsputc(dev_t dev, int c) |
|
static int |
static int |
earlyconsgetc(dev_t dev) |
earlyconsgetc(dev_t dev) |
{ |
{ |
return 0; |
return -1; |
} |
} |
|
|
static struct consdev earlycons = { |
static struct consdev earlycons = { |
Line 157 static struct consdev earlycons = { |
|
Line 159 static struct consdev earlycons = { |
|
#define VPRINTF(...) __nothing |
#define VPRINTF(...) __nothing |
#endif |
#endif |
|
|
/* |
|
* Get all of physical memory, including holes. |
|
*/ |
|
static void |
|
fdt_get_memory(uint64_t *pstart, uint64_t *pend) |
|
{ |
|
const int memory = OF_finddevice("/memory"); |
|
uint64_t cur_addr, cur_size; |
|
int index; |
|
|
|
/* Assume the first entry is the start of memory */ |
|
if (fdtbus_get_reg64(memory, 0, &cur_addr, &cur_size) != 0) |
|
panic("Cannot determine memory size"); |
|
|
|
*pstart = cur_addr; |
|
*pend = cur_addr + cur_size; |
|
|
|
VPRINTF("FDT /memory [%d] @ 0x%" PRIx64 " size 0x%" PRIx64 "\n", |
|
0, *pstart, *pend - *pstart); |
|
|
|
for (index = 1; |
|
fdtbus_get_reg64(memory, index, &cur_addr, &cur_size) == 0; |
|
index++) { |
|
VPRINTF("FDT /memory [%d] @ 0x%" PRIx64 " size 0x%" PRIx64 "\n", |
|
index, cur_addr, cur_size); |
|
|
|
if (cur_addr + cur_size > *pend) |
|
*pend = cur_addr + cur_size; |
|
} |
|
} |
|
|
|
void |
|
fdt_add_reserved_memory_range(uint64_t addr, uint64_t size) |
|
{ |
|
fdt_memory_remove_range(addr, size); |
|
} |
|
|
|
/* |
|
* Exclude memory ranges from memory config from the device tree |
|
*/ |
|
static void |
|
fdt_add_reserved_memory(uint64_t min_addr, uint64_t max_addr) |
|
{ |
|
uint64_t lstart = 0, lend = 0; |
|
uint64_t addr, size; |
|
int index, error; |
|
|
|
const int num = fdt_num_mem_rsv(fdtbus_get_data()); |
|
for (index = 0; index <= num; index++) { |
|
error = fdt_get_mem_rsv(fdtbus_get_data(), index, |
|
&addr, &size); |
|
if (error != 0) |
|
continue; |
|
if (lstart <= addr && addr <= lend) { |
|
size -= (lend - addr); |
|
addr = lend; |
|
} |
|
if (size == 0) |
|
continue; |
|
if (addr + size <= min_addr) |
|
continue; |
|
if (addr >= max_addr) |
|
continue; |
|
if (addr < min_addr) { |
|
size -= (min_addr - addr); |
|
addr = min_addr; |
|
} |
|
if (addr + size > max_addr) |
|
size = max_addr - addr; |
|
fdt_add_reserved_memory_range(addr, size); |
|
lstart = addr; |
|
lend = addr + size; |
|
} |
|
} |
|
|
|
static void |
static void |
fdt_add_dram_blocks(const struct fdt_memory *m, void *arg) |
fdt_add_dram_blocks(const struct fdt_memory *m, void *arg) |
{ |
{ |
Line 244 fdt_add_dram_blocks(const struct fdt_mem |
|
Line 171 fdt_add_dram_blocks(const struct fdt_mem |
|
bc->dramblocks++; |
bc->dramblocks++; |
} |
} |
|
|
#define MAX_PHYSMEM 64 |
|
static int nfdt_physmem = 0; |
static int nfdt_physmem = 0; |
static struct boot_physmem fdt_physmem[MAX_PHYSMEM]; |
static struct boot_physmem fdt_physmem[FDT_MEMORY_RANGES]; |
|
|
static void |
static void |
fdt_add_boot_physmem(const struct fdt_memory *m, void *arg) |
fdt_add_boot_physmem(const struct fdt_memory *m, void *arg) |
Line 263 fdt_add_boot_physmem(const struct fdt_me |
|
Line 189 fdt_add_boot_physmem(const struct fdt_me |
|
|
|
struct boot_physmem *bp = &fdt_physmem[nfdt_physmem++]; |
struct boot_physmem *bp = &fdt_physmem[nfdt_physmem++]; |
|
|
KASSERT(nfdt_physmem <= MAX_PHYSMEM); |
KASSERT(nfdt_physmem <= FDT_MEMORY_RANGES); |
|
|
bp->bp_start = atop(saddr); |
bp->bp_start = atop(saddr); |
bp->bp_pages = atop(eaddr) - bp->bp_start; |
bp->bp_pages = atop(eaddr) - bp->bp_start; |
bp->bp_freelist = VM_FREELIST_DEFAULT; |
bp->bp_freelist = VM_FREELIST_DEFAULT; |
|
|
#ifdef _LP64 |
|
if (m->end > 0x100000000) |
|
bp->bp_freelist = VM_FREELIST_HIGHMEM; |
|
#endif |
|
|
|
#ifdef PMAP_NEED_ALLOC_POOLPAGE |
#ifdef PMAP_NEED_ALLOC_POOLPAGE |
const uint64_t memory_size = *(uint64_t *)arg; |
const uint64_t memory_size = *(uint64_t *)arg; |
if (atop(memory_size) > bp->bp_pages) { |
if (atop(memory_size) > bp->bp_pages) { |
Line 283 fdt_add_boot_physmem(const struct fdt_me |
|
Line 204 fdt_add_boot_physmem(const struct fdt_me |
|
#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); |
|
} |
|
|
|
|
/* |
/* |
* Define usable memory regions. |
* Define usable memory regions. |
*/ |
*/ |
static void |
static void |
fdt_build_bootconfig(uint64_t mem_start, uint64_t mem_end) |
fdt_build_bootconfig(uint64_t mem_start, uint64_t mem_end) |
{ |
{ |
const int memory = OF_finddevice("/memory"); |
|
BootConfig *bc = &bootconfig; |
BootConfig *bc = &bootconfig; |
|
|
uint64_t addr, size; |
uint64_t addr, size; |
int index; |
int index; |
|
|
for (index = 0; |
/* Reserve pages for ramdisk, rndseed, and firmware's RNG */ |
fdtbus_get_reg64(memory, index, &addr, &size) == 0; |
fdt_reserve_initrd(); |
index++) { |
fdt_reserve_rndseed(); |
if (addr >= mem_end || size == 0) |
fdt_reserve_efirng(); |
continue; |
|
if (addr + size > mem_end) |
|
size = mem_end - addr; |
|
|
|
fdt_memory_add_range(addr, size); |
|
} |
|
|
|
fdt_add_reserved_memory(mem_start, mem_end); |
|
|
|
const uint64_t initrd_size = initrd_end - initrd_start; |
|
if (initrd_size > 0) |
|
fdt_memory_remove_range(initrd_start, initrd_size); |
|
|
|
const int framebuffer = OF_finddevice("/chosen/framebuffer"); |
const int framebuffer = OF_finddevice("/chosen/framebuffer"); |
if (framebuffer >= 0) { |
if (framebuffer >= 0) { |
for (index = 0; |
for (index = 0; |
fdtbus_get_reg64(framebuffer, index, &addr, &size) == 0; |
fdtbus_get_reg64(framebuffer, index, &addr, &size) == 0; |
index++) { |
index++) { |
fdt_add_reserved_memory_range(addr, size); |
fdt_memory_remove_range(addr, size); |
} |
} |
} |
} |
|
|
Line 325 fdt_build_bootconfig(uint64_t mem_start, |
|
Line 244 fdt_build_bootconfig(uint64_t mem_start, |
|
fdt_memory_foreach(fdt_add_dram_blocks, bc); |
fdt_memory_foreach(fdt_add_dram_blocks, bc); |
} |
} |
|
|
static void |
|
fdt_probe_initrd(uint64_t *pstart, uint64_t *pend) |
|
{ |
|
*pstart = *pend = 0; |
|
|
|
#ifdef MEMORY_DISK_DYNAMIC |
|
const int chosen = OF_finddevice("/chosen"); |
|
if (chosen < 0) |
|
return; |
|
|
|
int len; |
|
const void *start_data = fdtbus_get_prop(chosen, |
|
"linux,initrd-start", &len); |
|
const void *end_data = fdtbus_get_prop(chosen, |
|
"linux,initrd-end", 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/initrd-start\n", len); |
|
return; |
|
} |
|
#endif |
|
} |
|
|
|
static void |
|
fdt_setup_initrd(void) |
|
{ |
|
#ifdef MEMORY_DISK_DYNAMIC |
|
const uint64_t initrd_size = initrd_end - initrd_start; |
|
paddr_t startpa = trunc_page(initrd_start); |
|
paddr_t endpa = round_page(initrd_end); |
|
paddr_t pa; |
|
vaddr_t va; |
|
void *md_start; |
|
|
|
if (initrd_size == 0) |
|
return; |
|
|
|
va = uvm_km_alloc(kernel_map, initrd_size, 0, |
|
UVM_KMF_VAONLY | UVM_KMF_NOWAIT); |
|
if (va == 0) { |
|
printf("Failed to allocate VA for initrd\n"); |
|
return; |
|
} |
|
|
|
md_start = (void *)va; |
|
|
|
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()); |
|
|
|
md_root_setconf(md_start, initrd_size); |
|
#endif |
|
} |
|
|
|
#ifdef EFI_RUNTIME |
|
static void |
|
fdt_map_efi_runtime(const char *prop, enum arm_efirt_mem_type type) |
|
{ |
|
int len; |
|
|
|
const int chosen_off = fdt_path_offset(fdt_data, "/chosen"); |
|
if (chosen_off < 0) |
|
return; |
|
|
|
const uint64_t *map = fdt_getprop(fdt_data, chosen_off, prop, &len); |
|
if (map == NULL) |
|
return; |
|
|
|
while (len >= 24) { |
vaddr_t |
const paddr_t pa = be64toh(map[0]); |
|
const vaddr_t va = be64toh(map[1]); |
|
const uint64_t sz = be64toh(map[2]); |
|
VPRINTF("%s: %s %lx-%lx (%lx-%lx)\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 initarm(void *arg); |
|
|
|
u_int |
|
initarm(void *arg) |
initarm(void *arg) |
{ |
{ |
const struct arm_platform *plat; |
const struct fdt_platform *plat; |
uint64_t memory_start, memory_end; |
uint64_t memory_start, memory_end; |
|
|
/* set temporally to work printf()/panic() even before consinit() */ |
/* set temporally to work printf()/panic() even before consinit() */ |
Line 429 initarm(void *arg) |
|
Line 256 initarm(void *arg) |
|
|
|
/* Load FDT */ |
/* Load FDT */ |
int error = fdt_check_header(fdt_addr_r); |
int error = fdt_check_header(fdt_addr_r); |
if (error == 0) { |
if (error != 0) |
/* 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_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 = fdt_platform_find(); |
if (plat == NULL) |
if (plat == NULL) |
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. */ |
VPRINTF("FDT<%p>\n", fdt_addr_r); |
VPRINTF("FDT<%p>\n", fdt_addr_r); |
|
|
const int chosen = OF_finddevice("/chosen"); |
boot_args = fdt_get_bootargs(); |
if (chosen >= 0) |
|
OF_getprop(chosen, "bootargs", bootargs, sizeof(bootargs)); |
|
boot_args = bootargs; |
|
|
|
/* Heads up ... Setup the CPU / MMU / TLB functions. */ |
/* Heads up ... Setup the CPU / MMU / TLB functions. */ |
VPRINTF("cpufunc\n"); |
VPRINTF("cpufunc\n"); |
Line 464 initarm(void *arg) |
|
Line 289 initarm(void *arg) |
|
* l1pt VA is fine |
* l1pt VA is fine |
*/ |
*/ |
|
|
VPRINTF("devmap\n"); |
VPRINTF("devmap %p\n", plat->fp_devmap()); |
extern char ARM_BOOTSTRAP_LxPT[]; |
extern char ARM_BOOTSTRAP_LxPT[]; |
pmap_devmap_bootstrap((vaddr_t)ARM_BOOTSTRAP_LxPT, plat->ap_devmap()); |
pmap_devmap_bootstrap((vaddr_t)ARM_BOOTSTRAP_LxPT, plat->fp_devmap()); |
|
|
VPRINTF("bootstrap\n"); |
VPRINTF("bootstrap\n"); |
plat->ap_bootstrap(); |
plat->fp_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"); |
VPRINTF("stdout\n"); |
fdt_update_stdout_path(); |
fdt_update_stdout_path(fdt_data, boot_args); |
|
|
|
#if BYTE_ORDER == BIG_ENDIAN |
|
/* |
|
* Most boards are configured to little-endian mode initially, 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 |
|
|
/* |
/* |
* Done making changes to the FDT. |
* Done making changes to the FDT. |
Line 504 initarm(void *arg) |
|
Line 340 initarm(void *arg) |
|
parse_mi_bootargs(mi_bootargs); |
parse_mi_bootargs(mi_bootargs); |
#endif |
#endif |
|
|
fdt_get_memory(&memory_start, &memory_end); |
fdt_memory_get(&memory_start, &memory_end); |
|
|
#if !defined(_LP64) |
fdt_memory_foreach(fdt_print_memory, NULL); |
/* Cannot map memory above 4GB */ |
|
if (memory_end >= 0x100000000ULL) |
|
memory_end = 0x100000000ULL - PAGE_SIZE; |
|
|
|
|
#if !defined(_LP64) |
|
/* Cannot map memory above 4GB (remove last page as well) */ |
|
const uint64_t memory_limit = 0x100000000ULL - PAGE_SIZE; |
|
if (memory_end > memory_limit) { |
|
fdt_memory_remove_range(memory_limit , memory_end); |
|
memory_end = memory_limit; |
|
} |
#endif |
#endif |
uint64_t memory_size = memory_end - memory_start; |
uint64_t memory_size = memory_end - memory_start; |
|
|
Line 518 initarm(void *arg) |
|
Line 358 initarm(void *arg) |
|
PRIx64 ")\n", __func__, memory_start, memory_end, memory_size); |
PRIx64 ")\n", __func__, memory_start, memory_end, memory_size); |
|
|
/* Parse ramdisk info */ |
/* Parse ramdisk info */ |
fdt_probe_initrd(&initrd_start, &initrd_end); |
fdt_probe_initrd(); |
|
|
|
/* Parse our on-disk rndseed and the firmware's RNG from EFI */ |
|
fdt_probe_rndseed(); |
|
fdt_probe_efirng(); |
|
|
|
fdt_memory_remove_reserved(memory_start, memory_end); |
|
|
/* |
/* |
* Populate bootconfig structure for the benefit of |
* Populate bootconfig structure for the benefit of dodumpsys |
* dodumpsys |
|
*/ |
*/ |
VPRINTF("%s: fdt_build_bootconfig\n", __func__); |
VPRINTF("%s: fdt_build_bootconfig\n", __func__); |
fdt_build_bootconfig(memory_start, memory_end); |
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 */ |
/* Perform PT build and VM init */ |
cpu_kernel_vm_init(memory_start, memory_size); |
cpu_kernel_vm_init(memory_start, memory_size); |
|
|
VPRINTF("bootargs: %s\n", bootargs); |
VPRINTF("bootargs: %s\n", boot_args); |
|
|
parse_mi_bootargs(boot_args); |
parse_mi_bootargs(boot_args); |
|
|
VPRINTF("Memory regions:\n"); |
VPRINTF("Memory regions:\n"); |
|
|
|
/* Populate fdt_physmem / nfdt_physmem for initarm_common */ |
fdt_memory_foreach(fdt_add_boot_physmem, &memory_size); |
fdt_memory_foreach(fdt_add_boot_physmem, &memory_size); |
|
|
u_int sp = initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, fdt_physmem, |
vaddr_t sp = initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, fdt_physmem, |
nfdt_physmem); |
nfdt_physmem); |
|
|
/* |
/* |
Line 552 initarm(void *arg) |
|
Line 393 initarm(void *arg) |
|
error = 0; |
error = 0; |
if ((boothowto & RB_MD1) == 0) { |
if ((boothowto & RB_MD1) == 0) { |
VPRINTF("mpstart\n"); |
VPRINTF("mpstart\n"); |
if (plat->ap_mpstart) |
if (plat->fp_mpstart) |
error = plat->ap_mpstart(); |
error = plat->fp_mpstart(); |
} |
} |
|
|
if (error) |
if (error) |
return sp; |
return sp; |
|
|
/* |
/* |
* Now we have APs started the pages used for stacks and L1PT can |
* Now we have APs started the pages used for stacks and L1PT can |
* be given to uvm |
* be given to uvm |
Line 575 initarm(void *arg) |
|
Line 417 initarm(void *arg) |
|
"loading in freelist %d\n", spa, epa, VM_FREELIST_DEFAULT); |
"loading in freelist %d\n", spa, epa, VM_FREELIST_DEFAULT); |
|
|
uvm_page_physload(spg, epg, spg, epg, VM_FREELIST_DEFAULT); |
uvm_page_physload(spg, epg, spg, epg, VM_FREELIST_DEFAULT); |
|
|
} |
} |
|
|
return sp; |
return sp; |
} |
} |
|
|
static void |
|
fdt_update_stdout_path(void) |
|
{ |
|
char *stdout_path, *ep; |
|
int stdout_path_len; |
|
char buf[256]; |
|
|
|
const int chosen_off = fdt_path_offset(fdt_data, "/chosen"); |
|
if (chosen_off == -1) |
|
return; |
|
|
|
if (get_bootconf_option(boot_args, "stdout-path", |
|
BOOTOPT_TYPE_STRING, &stdout_path) == 0) |
|
return; |
|
|
|
ep = strchr(stdout_path, ' '); |
|
stdout_path_len = ep ? (ep - stdout_path) : strlen(stdout_path); |
|
if (stdout_path_len >= sizeof(buf)) |
|
return; |
|
|
|
strncpy(buf, stdout_path, stdout_path_len); |
|
buf[stdout_path_len] = '\0'; |
|
fdt_setprop(fdt_data, chosen_off, "stdout-path", |
|
buf, stdout_path_len + 1); |
|
} |
|
|
|
void |
void |
consinit(void) |
consinit(void) |
{ |
{ |
static bool initialized = false; |
static bool initialized = false; |
const struct arm_platform *plat = arm_fdt_platform(); |
const struct fdt_platform *plat = fdt_platform_find(); |
const struct fdt_console *cons = fdtbus_get_console(); |
const struct fdt_console *cons = fdtbus_get_console(); |
struct fdt_attach_args faa; |
struct fdt_attach_args faa; |
u_int uart_freq = 0; |
u_int uart_freq = 0; |
|
|
if (initialized || cons == NULL) |
if (initialized || cons == NULL) |
return; |
return; |
|
|
plat->ap_init_attach_args(&faa); |
plat->fp_init_attach_args(&faa); |
faa.faa_phandle = fdtbus_get_stdout_phandle(); |
faa.faa_phandle = fdtbus_get_stdout_phandle(); |
|
|
if (plat->ap_uart_freq != NULL) |
if (plat->fp_uart_freq != NULL) |
uart_freq = plat->ap_uart_freq(); |
uart_freq = plat->fp_uart_freq(); |
|
|
cons->consinit(&faa, uart_freq); |
cons->consinit(&faa, uart_freq); |
|
|
|
|
} |
} |
|
|
void |
void |
|
cpu_startup_hook(void) |
|
{ |
|
#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 |
|
|
|
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 fdt_platform *plat = fdt_platform_find(); |
|
|
plat->ap_delay(us); |
plat->fp_delay(us); |
} |
} |
|
|
static void |
static void |
fdt_detect_root_device(device_t dev) |
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; |
int error, len; |
size_t resid; |
|
u_int part; |
|
|
|
const int chosen = OF_finddevice("/chosen"); |
const int chosen = OF_finddevice("/chosen"); |
if (chosen < 0) |
if (chosen < 0) |
Line 658 fdt_detect_root_device(device_t dev) |
|
Line 479 fdt_detect_root_device(device_t dev) |
|
|
|
if (of_hasprop(chosen, "netbsd,mbr") && |
if (of_hasprop(chosen, "netbsd,mbr") && |
of_hasprop(chosen, "netbsd,partition")) { |
of_hasprop(chosen, "netbsd,partition")) { |
|
struct mbr_sector mbr; |
|
uint8_t buf[DEV_BSIZE]; |
|
uint8_t hash[16]; |
|
const uint8_t *rhash; |
|
struct vnode *vp; |
|
MD5_CTX md5ctx; |
|
size_t resid; |
|
u_int part; |
|
|
/* |
/* |
* The bootloader has passed in a partition index and MD5 hash |
* The bootloader has passed in a partition index and MD5 hash |
Line 675 fdt_detect_root_device(device_t dev) |
|
Line 504 fdt_detect_root_device(device_t dev) |
|
if (!vp) |
if (!vp) |
return; |
return; |
error = vn_rdwr(UIO_READ, vp, buf, sizeof(buf), 0, UIO_SYSSPACE, |
error = vn_rdwr(UIO_READ, vp, buf, sizeof(buf), 0, UIO_SYSSPACE, |
0, NOCRED, &resid, NULL); |
IO_NODELOCKED, NOCRED, &resid, NULL); |
VOP_CLOSE(vp, FREAD, NOCRED); |
VOP_CLOSE(vp, FREAD, NOCRED); |
vput(vp); |
vput(vp); |
|
|
Line 687 fdt_detect_root_device(device_t dev) |
|
Line 516 fdt_detect_root_device(device_t dev) |
|
MD5Update(&md5ctx, (void *)&mbr, sizeof(mbr)); |
MD5Update(&md5ctx, (void *)&mbr, sizeof(mbr)); |
MD5Final(hash, &md5ctx); |
MD5Final(hash, &md5ctx); |
|
|
if (memcmp(rhash, hash, 16) != 0) |
if (memcmp(rhash, hash, 16) == 0) { |
return; |
booted_device = dev; |
|
booted_partition = part; |
|
} |
|
|
snprintf(rootarg, sizeof(rootarg), " root=%s%c", device_xname(dev), part + 'a'); |
return; |
strcat(boot_args, rootarg); |
|
} |
} |
|
|
if (of_hasprop(chosen, "netbsd,gpt-guid")) { |
if (of_hasprop(chosen, "netbsd,gpt-guid")) { |
char guidbuf[UUID_STR_LEN]; |
const struct uuid *guid = |
const struct uuid *guid = fdtbus_get_prop(chosen, "netbsd,gpt-guid", &len); |
fdtbus_get_prop(chosen, "netbsd,gpt-guid", &len); |
|
|
if (guid == NULL || len != 16) |
if (guid == NULL || len != 16) |
return; |
return; |
|
|
uuid_snprintf(guidbuf, sizeof(guidbuf), guid); |
char guidstr[UUID_STR_LEN]; |
snprintf(rootarg, sizeof(rootarg), " root=wedge:%s", guidbuf); |
uuid_snprintf(guidstr, sizeof(guidstr), guid); |
strcat(boot_args, rootarg); |
|
|
device_t dv = dkwedge_find_by_wname(guidstr); |
|
if (dv != NULL) |
|
booted_device = dv; |
|
|
|
return; |
} |
} |
|
|
if (of_hasprop(chosen, "netbsd,gpt-label")) { |
if (of_hasprop(chosen, "netbsd,gpt-label")) { |
Line 713 fdt_detect_root_device(device_t dev) |
|
Line 549 fdt_detect_root_device(device_t dev) |
|
device_t dv = dkwedge_find_by_wname(label); |
device_t dv = dkwedge_find_by_wname(label); |
if (dv != NULL) |
if (dv != NULL) |
booted_device = dv; |
booted_device = dv; |
|
|
|
return; |
} |
} |
|
|
if (of_hasprop(chosen, "netbsd,booted-mac-address")) { |
if (of_hasprop(chosen, "netbsd,booted-mac-address")) { |
const uint8_t *macaddr = fdtbus_get_prop(chosen, "netbsd,booted-mac-address", &len); |
const uint8_t *macaddr = |
|
fdtbus_get_prop(chosen, "netbsd,booted-mac-address", &len); |
|
struct ifnet *ifp; |
|
|
if (macaddr == NULL || len != 6) |
if (macaddr == NULL || len != 6) |
return; |
return; |
|
|
int s = pserialize_read_enter(); |
int s = pserialize_read_enter(); |
struct ifnet *ifp; |
|
IFNET_READER_FOREACH(ifp) { |
IFNET_READER_FOREACH(ifp) { |
if (memcmp(macaddr, CLLADDR(ifp->if_sadl), len) == 0) { |
if (memcmp(macaddr, CLLADDR(ifp->if_sadl), len) == 0) { |
device_t dv = device_find_by_xname(ifp->if_xname); |
device_t dv = device_find_by_xname(ifp->if_xname); |
Line 730 fdt_detect_root_device(device_t dev) |
|
Line 571 fdt_detect_root_device(device_t dev) |
|
} |
} |
} |
} |
pserialize_read_exit(s); |
pserialize_read_exit(s); |
|
|
|
return; |
} |
} |
} |
} |
|
|
static void |
static void |
fdt_device_register(device_t self, void *aux) |
fdt_device_register(device_t self, void *aux) |
{ |
{ |
const struct arm_platform *plat = arm_fdt_platform(); |
const struct fdt_platform *plat = fdt_platform_find(); |
|
|
if (device_is_a(self, "armfdt")) |
if (device_is_a(self, "armfdt")) { |
fdt_setup_initrd(); |
fdt_setup_initrd(); |
|
|
if (plat && plat->ap_device_register) |
#if NWSDISPLAY > 0 && NGENFB > 0 |
plat->ap_device_register(self, aux); |
/* |
|
* 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->fp_device_register) |
|
plat->fp_device_register(self, aux); |
} |
} |
|
|
static void |
static void |
Line 762 fdt_cpu_rootconf(void) |
|
Line 621 fdt_cpu_rootconf(void) |
|
{ |
{ |
device_t dev; |
device_t dev; |
deviter_t di; |
deviter_t di; |
char *ptr; |
|
|
if (booted_device != NULL) |
|
return; |
|
|
for (dev = deviter_first(&di, 0); dev; dev = deviter_next(&di)) { |
for (dev = deviter_first(&di, 0); dev; dev = deviter_next(&di)) { |
if (device_class(dev) != DV_DISK) |
if (device_class(dev) != DV_DISK) |
continue; |
continue; |
|
|
if (get_bootconf_option(boot_args, "root", BOOTOPT_TYPE_STRING, &ptr) != 0) |
fdt_detect_root_device(dev); |
break; |
|
|
|
if (device_is_a(dev, "ld") || device_is_a(dev, "sd") || device_is_a(dev, "wd")) |
if (booted_device != NULL) |
fdt_detect_root_device(dev); |
break; |
} |
} |
deviter_release(&di); |
deviter_release(&di); |
} |
} |
Line 780 fdt_cpu_rootconf(void) |
|
Line 640 fdt_cpu_rootconf(void) |
|
static void |
static void |
fdt_reset(void) |
fdt_reset(void) |
{ |
{ |
const struct arm_platform *plat = arm_fdt_platform(); |
const struct fdt_platform *plat = fdt_platform_find(); |
|
|
fdtbus_power_reset(); |
fdtbus_power_reset(); |
|
|
if (plat && plat->ap_reset) |
if (plat && plat->fp_reset) |
plat->ap_reset(); |
plat->fp_reset(); |
} |
} |
|
|
static void |
static void |
Line 793 fdt_powerdown(void) |
|
Line 653 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 |