Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/arch/evbarm/fdt/fdt_machdep.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/arch/evbarm/fdt/fdt_machdep.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.13 retrieving revision 1.22 diff -u -p -r1.13 -r1.22 --- src/sys/arch/evbarm/fdt/fdt_machdep.c 2017/08/24 11:33:28 1.13 +++ src/sys/arch/evbarm/fdt/fdt_machdep.c 2018/06/14 10:53:39 1.22 @@ -1,4 +1,4 @@ -/* $NetBSD: fdt_machdep.c,v 1.13 2017/08/24 11:33:28 jmcneill Exp $ */ +/* $NetBSD: fdt_machdep.c,v 1.22 2018/06/14 10:53:39 jmcneill Exp $ */ /*- * Copyright (c) 2015-2017 Jared McNeill @@ -27,15 +27,18 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.13 2017/08/24 11:33:28 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.22 2018/06/14 10:53:39 jmcneill Exp $"); #include "opt_machdep.h" +#include "opt_bootconfig.h" #include "opt_ddb.h" #include "opt_md.h" #include "opt_arm_debug.h" #include "opt_multiprocessor.h" #include "opt_cpuoptions.h" +#include "ukbd.h" + #include #include #include @@ -62,15 +65,24 @@ __KERNEL_RCSID(0, "$NetBSD: fdt_machdep. #include #include -#include +#include +#ifdef __aarch64__ +#include +#else #include +#endif + #include #include #include +#if NUKBD > 0 +#include +#endif + #ifdef MEMORY_DISK_DYNAMIC #include #endif @@ -82,7 +94,11 @@ __KERNEL_RCSID(0, "$NetBSD: fdt_machdep. BootConfig bootconfig; char bootargs[FDT_MAX_BOOT_STRING] = ""; char *boot_args = NULL; -u_int uboot_args[4] = { 0 }; /* filled in by xxx_start.S (not in bss) */ +/* + * filled in by xxx_start.S (must not be in bss) + */ +unsigned long uboot_args[4] = { 0 }; +const uint8_t *fdt_addr_r = (const uint8_t *)0xdeadc0de; static char fdt_memory_ext_storage[EXTENT_FIXED_STORAGE_SIZE(DRAM_BLOCKS)]; static struct extent *fdt_memory_ext; @@ -91,7 +107,7 @@ static uint64_t initrd_start, initrd_end #include #include -#define FDT_BUF_SIZE (128*1024) +#define FDT_BUF_SIZE (256*1024) static uint8_t fdt_data[FDT_BUF_SIZE]; extern char KERNEL_BASE_phys[]; @@ -102,14 +118,6 @@ static void fdt_device_register(device_t static void fdt_reset(void); static void fdt_powerdown(void); -#ifdef PMAP_NEED_ALLOC_POOLPAGE -static struct boot_physmem bp_lowgig = { - .bp_pages = (KERNEL_VM_BASE - KERNEL_BASE) / NBPG, - .bp_freelist = VM_FREELIST_ISADMA, - .bp_flags = 0 -}; -#endif - #ifdef VERBOSE_INIT_ARM static void fdt_putchar(char c) @@ -127,9 +135,9 @@ fdt_putstr(const char *s) } static void -fdt_printn(u_int n, int base) +fdt_printn(unsigned long n, int base) { - char *p, buf[(sizeof(u_int) * NBBY / 3) + 1 + 2 /* ALT + SIGN */]; + char *p, buf[(sizeof(unsigned long) * NBBY / 3) + 1 + 2 /* ALT + SIGN */]; p = buf; do { @@ -150,47 +158,56 @@ fdt_printn(u_int n, int base) #endif /* - * Get the first physically contiguous region of memory. + * ARM: Get the first physically contiguous region of memory. + * ARM64: Get all of physical memory, including holes. */ static void -fdt_get_memory(uint64_t *paddr, uint64_t *psize) +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, paddr, psize) != 0) + if (fdtbus_get_reg64(memory, 0, &cur_addr, &cur_size) != 0) panic("Cannot determine memory size"); + *pstart = cur_addr; + *pend = cur_addr + cur_size; + DPRINTF("FDT /memory [%d] @ 0x%" PRIx64 " size 0x%" PRIx64 "\n", - 0, *paddr, *psize); + 0, *pstart, *pend - *pstart); - /* If subsequent entries follow the previous one, append them. */ for (index = 1; fdtbus_get_reg64(memory, index, &cur_addr, &cur_size) == 0; index++) { DPRINTF("FDT /memory [%d] @ 0x%" PRIx64 " size 0x%" PRIx64 "\n", index, cur_addr, cur_size); - if (*paddr + *psize == cur_addr) - *psize += cur_size; + +#ifdef __aarch64__ + if (cur_addr + cur_size > *pend) + *pend = cur_addr + cur_size; +#else + /* If subsequent entries follow the previous, append them. */ + if (*pend == cur_addr) + *pend = cur_addr + cur_size; +#endif } } -static void +void fdt_add_reserved_memory_range(uint64_t addr, uint64_t size) { - int error; + uint64_t start = trunc_page(addr); + uint64_t end = round_page(addr + size); - addr = trunc_page(addr); - size = round_page(size); - - error = extent_free(fdt_memory_ext, addr, size, EX_NOWAIT); + int error = extent_free(fdt_memory_ext, start, + end - start, EX_NOWAIT); if (error != 0) printf("MEM ERROR: res %llx-%llx failed: %d\n", - addr, addr + size, error); + start, end, error); else - DPRINTF("MEM: res %llx-%llx\n", addr, addr + size); + DPRINTF("MEM: res %llx-%llx\n", start, end); } /* @@ -220,35 +237,34 @@ fdt_add_reserved_memory(uint64_t max_add * Define usable memory regions. */ static void -fdt_build_bootconfig(uint64_t mem_addr, uint64_t mem_size) +fdt_build_bootconfig(uint64_t mem_start, uint64_t mem_end) { const int memory = OF_finddevice("/memory"); - const uint64_t max_addr = mem_addr + mem_size; BootConfig *bc = &bootconfig; struct extent_region *er; uint64_t addr, size; int index, error; - - fdt_memory_ext = extent_create("FDT Memory", mem_addr, max_addr, + + fdt_memory_ext = extent_create("FDT Memory", mem_start, mem_end, fdt_memory_ext_storage, sizeof(fdt_memory_ext_storage), EX_EARLY); for (index = 0; fdtbus_get_reg64(memory, index, &addr, &size) == 0; index++) { - if (addr >= max_addr || size == 0) + if (addr >= mem_end || size == 0) continue; - if (addr + size > max_addr) - size = max_addr - addr; + if (addr + size > mem_end) + size = mem_end - addr; error = extent_alloc_region(fdt_memory_ext, addr, size, EX_NOWAIT); if (error != 0) printf("MEM ERROR: add %llx-%llx failed: %d\n", - addr, size, error); - DPRINTF("MEM: add %llx-%llx\n", addr, size); + addr, addr + size, error); + DPRINTF("MEM: add %llx-%llx\n", addr, addr + size); } - fdt_add_reserved_memory(max_addr); + fdt_add_reserved_memory(mem_end); const uint64_t initrd_size = initrd_end - initrd_start; if (initrd_size > 0) @@ -330,14 +346,15 @@ fdt_setup_initrd(void) #endif } +u_int initarm(void *arg); + u_int initarm(void *arg) { const struct arm_platform *plat; - uint64_t memory_addr, memory_size; + uint64_t memory_start, memory_end; /* Load FDT */ - const uint8_t *fdt_addr_r = (const uint8_t *)uboot_args[2]; int error = fdt_check_header(fdt_addr_r); if (error == 0) { error = fdt_move(fdt_addr_r, fdt_data, sizeof(fdt_data)); @@ -365,15 +382,18 @@ initarm(void *arg) DPRINT(" devmap"); pmap_devmap_register(plat->devmap()); - - DPRINT(" bootstrap"); - plat->bootstrap(); +#ifdef __aarch64__ + pmap_devmap_bootstrap(plat->devmap()); +#endif /* Heads up ... Setup the CPU / MMU / TLB functions. */ DPRINT(" cpufunc"); if (set_cpufuncs()) panic("cpu not recognized!"); + DPRINT(" bootstrap"); + plat->bootstrap(); + /* * If stdout-path is specified on the command line, override the * value in /chosen/stdout-path before initializing console. @@ -385,7 +405,7 @@ initarm(void *arg) DPRINTF(" ok\n"); - DPRINTF("uboot: args %#x, %#x, %#x, %#x\n", + DPRINTF("uboot: args %#lx, %#lx, %#lx, %#lx\n", uboot_args[0], uboot_args[1], uboot_args[2], uboot_args[3]); cpu_reset_address = fdt_reset; @@ -400,6 +420,7 @@ initarm(void *arg) parse_mi_bootargs(mi_bootargs); #endif +#ifndef __aarch64__ DPRINTF("KERNEL_BASE=0x%x, " "KERNEL_VM_BASE=0x%x, " "KERNEL_VM_BASE - KERNEL_BASE=0x%x, " @@ -408,21 +429,25 @@ initarm(void *arg) KERNEL_VM_BASE, KERNEL_VM_BASE - KERNEL_BASE, KERNEL_BASE_VOFFSET); +#endif - fdt_get_memory(&memory_addr, &memory_size); + fdt_get_memory(&memory_start, &memory_end); #if !defined(_LP64) /* Cannot map memory above 4GB */ - if (memory_addr + memory_size >= 0x100000000) - memory_size = 0x100000000 - memory_addr - PAGE_SIZE; + if (memory_end >= 0x100000000ULL) + memory_end = 0x100000000ULL - PAGE_SIZE; + + uint64_t memory_size = memory_end - memory_start; #endif +#ifndef __aarch64__ #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS const bool mapallmem_p = true; #ifndef PMAP_NEED_ALLOC_POOLPAGE if (memory_size > KERNEL_VM_BASE - KERNEL_BASE) { DPRINTF("%s: dropping RAM size from %luMB to %uMB\n", - __func__, (unsigned long) (memory_size >> 20), + __func__, (unsigned long) (memory_size >> 20), (KERNEL_VM_BASE - KERNEL_BASE) >> 20); memory_size = KERNEL_VM_BASE - KERNEL_BASE; } @@ -430,32 +455,70 @@ initarm(void *arg) #else const bool mapallmem_p = false; #endif +#endif /* Parse ramdisk info */ fdt_probe_initrd(&initrd_start, &initrd_end); - /* Populate bootconfig structure for the benefit of pmap.c. */ - fdt_build_bootconfig(memory_addr, memory_size); + /* + * Populate bootconfig structure for the benefit of + * dodumpsys + */ + fdt_build_bootconfig(memory_start, memory_end); + +#ifdef __aarch64__ + extern char __kernel_text[]; + extern char _end[]; + + vaddr_t kernstart = trunc_page((vaddr_t)__kernel_text); + vaddr_t kernend = round_page((vaddr_t)_end); - arm32_bootmem_init(bootconfig.dram[0].address, memory_size, - KERNEL_BASE_PHYS); + paddr_t kernstart_phys = KERN_VTOPHYS(kernstart); + paddr_t kernend_phys = KERN_VTOPHYS(kernend); + + DPRINTF("%s: kernel phys start %lx end %lx\n", __func__, kernstart_phys, kernend_phys); + + fdt_add_reserved_memory_range(kernstart_phys, + kernend_phys - kernstart_phys); +#else + arm32_bootmem_init(memory_start, memory_size, KERNEL_BASE_PHYS); arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0, plat->devmap(), mapallmem_p); +#endif DPRINTF("bootargs: %s\n", bootargs); parse_mi_bootargs(boot_args); + #define MAX_PHYSMEM 16 + static struct boot_physmem fdt_physmem[MAX_PHYSMEM]; + int nfdt_physmem = 0; + struct extent_region *er; + + LIST_FOREACH(er, &fdt_memory_ext->ex_regions, er_link) { + DPRINTF(" %lx - %lx\n", er->er_start, er->er_end); + struct boot_physmem *bp = &fdt_physmem[nfdt_physmem++]; + + KASSERT(nfdt_physmem <= MAX_PHYSMEM); + bp->bp_start = atop(er->er_start); + bp->bp_pages = atop(er->er_end - er->er_start); + bp->bp_freelist = VM_FREELIST_DEFAULT; + +#ifdef _LP64 + if (er->er_end > 0x100000000) + bp->bp_freelist = VM_FREELIST_HIGHMEM; +#endif + #ifdef PMAP_NEED_ALLOC_POOLPAGE - bp_lowgig.bp_start = memory_addr / NBPG; - if (atop(ram_size) > bp_lowgig.bp_pages) { - arm_poolpage_vmfreelist = bp_lowgig.bp_freelist; - return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, - &bp_lowgig, 1); - } + if (atop(memory_size) > bp->bp_pages) { + arm_poolpage_vmfreelist = VM_FREELIST_DIRECTMAP; + bp->bp_freelist = VM_FREELIST_DIRECTMAP; + } #endif + } - return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0); + return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, fdt_physmem, + nfdt_physmem); } static void @@ -504,6 +567,10 @@ consinit(void) cons->consinit(&faa, uart_freq); +#if NUKBD > 0 + ukbd_cnattach(); /* allow USB keyboard to become console */ +#endif + initialized = true; }