[BACK]Return to fdt_machdep.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / arch / evbarm / fdt

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sys/arch/evbarm/fdt/fdt_machdep.c between version 1.4.2.5 and 1.107

version 1.4.2.5, 2017/08/25 05:39:52 version 1.107, 2024/01/19 09:09:04
Line 29 
Line 29 
 #include <sys/cdefs.h>  #include <sys/cdefs.h>
 __KERNEL_RCSID(0, "$NetBSD$");  __KERNEL_RCSID(0, "$NetBSD$");
   
 #include "opt_machdep.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_machdep.h"
   #include "opt_multiprocessor.h"
   
   #include "genfb.h"
   #include "ukbd.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/extent.h>  #include <sys/vnode.h>
   #include <sys/uuid.h>
   
 #include <uvm/uvm_extern.h>  #include <net/if.h>
   #include <net/if_dl.h>
   
 #include <sys/conf.h>  #include <dev/cons.h>
   #include <uvm/uvm_extern.h>
   
 #include <machine/db_machdep.h>  #include <machine/db_machdep.h>
 #include <ddb/db_sym.h>  #include <ddb/db_sym.h>
Line 62  __KERNEL_RCSID(0, "$NetBSD$");
Line 81  __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>
   
 #ifdef MEMORY_DISK_DYNAMIC  #include <dev/fdt/fdtvar.h>
 #include <dev/md.h>  #include <dev/fdt/fdt_boot.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  #endif
   
 #ifndef FDT_MAX_BOOT_STRING  #if NUKBD > 0
 #define FDT_MAX_BOOT_STRING 1024  #include <dev/usb/ukbdvar.h>
   #endif
   #if NWSDISPLAY > 0
   #include <dev/wscons/wsdisplayvar.h>
 #endif  #endif
   
 BootConfig bootconfig;  BootConfig bootconfig;
 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) */  
   
 static char fdt_memory_ext_storage[EXTENT_FIXED_STORAGE_SIZE(DRAM_BLOCKS)];  
 static struct extent *fdt_memory_ext;  
   
 static uint64_t initrd_start, initrd_end;  /* 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")));
   
 #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[];
 #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_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 void  static int
 fdt_putstr(const char *s)  earlyconsgetc(dev_t dev)
 {  {
         for (const char *p = s; *p; p++)          return -1;
                 fdt_putchar(*p);  
 }  }
   
 static void  static struct consdev earlycons = {
 fdt_printn(u_int n, int base)          .cn_putc = earlyconsputc,
 {          .cn_getc = earlyconsgetc,
         char *p, buf[(sizeof(u_int) * NBBY / 3) + 1 + 2 /* ALT + SIGN */];          .cn_pollc = nullcnpollc,
   };
   
         p = buf;  #ifdef VERBOSE_INIT_ARM
         do {  #define VPRINTF(...)    printf(__VA_ARGS__)
                 *p++ = hexdigits[n % base];  
         } while (n /= base);  
   
         do {  
                 fdt_putchar(*--p);  
         } while (p > buf);  
 }  
 #define DPRINTF(...)            printf(__VA_ARGS__)  
 #define DPRINT(x)               fdt_putstr(x)  
 #define DPRINTN(x,b)            fdt_printn((x), (b))  
 #else  #else
 #define DPRINTF(...)  #define VPRINTF(...)    __nothing
 #define DPRINT(x)  
 #define DPRINTN(x,b)  
 #endif  #endif
   
 /*  
  * Get the first physically contiguous region of memory.  
  */  
 static void  static void
 fdt_get_memory(uint64_t *paddr, uint64_t *psize)  fdt_add_dram_blocks(const struct fdt_memory *m, void *arg)
 {  {
         const int memory = OF_finddevice("/memory");          BootConfig *bc = arg;
         uint64_t cur_addr, cur_size;  
         int index;  
   
         /* Assume the first entry is the start of memory */          VPRINTF("  %" PRIx64 " - %" PRIx64 "\n", m->start, m->end - 1);
         if (fdtbus_get_reg64(memory, 0, paddr, psize) != 0)          bc->dram[bc->dramblocks].address = m->start;
                 panic("Cannot determine memory size");          bc->dram[bc->dramblocks].pages =
               (m->end - m->start) / PAGE_SIZE;
         DPRINTF("FDT /memory [%d] @ 0x%" PRIx64 " size 0x%" PRIx64 "\n",          bc->dramblocks++;
             0, *paddr, *psize);  
   
         /* 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;  
         }  
 }  }
   
 static void  static int nfdt_physmem = 0;
 fdt_add_reserved_memory_range(uint64_t addr, uint64_t size)  static struct boot_physmem fdt_physmem[FDT_MEMORY_RANGES];
 {  
         int error;  
   
         addr = trunc_page(addr);  
         size = round_page(size);  
   
         error = extent_free(fdt_memory_ext, addr, size, EX_NOWAIT);  
         if (error != 0)  
                 printf("MEM ERROR: res %llx-%llx failed: %d\n",  
                     addr, addr + size, error);  
         else  
                 DPRINTF("MEM: res %llx-%llx\n", addr, addr + size);  
 }  
   
 /*  
  * Exclude memory ranges from memory config from the device tree  
  */  
 static void  static void
 fdt_add_reserved_memory(uint64_t max_addr)  fdt_add_boot_physmem(const struct fdt_memory *m, void *arg)
 {  {
         uint64_t addr, size;          const paddr_t saddr = round_page(m->start);
         int index, error;          const paddr_t eaddr = trunc_page(m->end);
   
         const int num = fdt_num_mem_rsv(fdtbus_get_data());          VPRINTF("  %" PRIx64 " - %" PRIx64, m->start, m->end - 1);
         for (index = 0; index <= num; index++) {          if (saddr >= eaddr) {
                 error = fdt_get_mem_rsv(fdtbus_get_data(), index,                  VPRINTF(" skipped\n");
                     &addr, &size);                  return;
                 if (error != 0 || size == 0)  
                         continue;  
                 if (addr >= max_addr)  
                         continue;  
                 if (addr + size > max_addr)  
                         size = max_addr - addr;  
                 fdt_add_reserved_memory_range(addr, size);  
         }          }
 }          VPRINTF("\n");
   
 /*  
  * Define usable memory regions.  
  */  
 static void  
 fdt_build_bootconfig(uint64_t mem_addr, uint64_t mem_size)  
 {  
         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_storage, sizeof(fdt_memory_ext_storage), 0);  
   
         for (index = 0;  
              fdtbus_get_reg64(memory, index, &addr, &size) == 0;  
              index++) {  
                 if (addr >= max_addr || size == 0)  
                         continue;  
                 if (addr + size > max_addr)  
                         size = max_addr - addr;  
   
                 error = extent_alloc_region(fdt_memory_ext, addr, size,          struct boot_physmem *bp = &fdt_physmem[nfdt_physmem++];
                     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);  
         }  
   
         fdt_add_reserved_memory(max_addr);          KASSERT(nfdt_physmem <= FDT_MEMORY_RANGES);
   
         const uint64_t initrd_size = initrd_end - initrd_start;          bp->bp_start = atop(saddr);
         if (initrd_size > 0)          bp->bp_pages = atop(eaddr) - bp->bp_start;
                 fdt_add_reserved_memory_range(initrd_start, initrd_size);          bp->bp_freelist = VM_FREELIST_DEFAULT;
   
         DPRINTF("Usable memory:\n");  #ifdef PMAP_NEED_ALLOC_POOLPAGE
         bc->dramblocks = 0;          const uint64_t memory_size = *(uint64_t *)arg;
         LIST_FOREACH(er, &fdt_memory_ext->ex_regions, er_link) {          if (atop(memory_size) > bp->bp_pages) {
                 DPRINTF("  %lx - %lx\n", er->er_start, er->er_end);                  arm_poolpage_vmfreelist = VM_FREELIST_DIRECTMAP;
                 bc->dram[bc->dramblocks].address = er->er_start;                  bp->bp_freelist = VM_FREELIST_DIRECTMAP;
                 bc->dram[bc->dramblocks].pages =  
                     (er->er_end - er->er_start) / PAGE_SIZE;  
                 bc->dramblocks++;  
         }          }
   #endif
 }  }
   
   
 static void  static void
 fdt_probe_initrd(uint64_t *pstart, uint64_t *pend)  fdt_print_memory(const struct fdt_memory *m, void *arg)
 {  {
         *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) {          VPRINTF("FDT /memory @ 0x%" PRIx64 " size 0x%" PRIx64 "\n",
         case 4:              m->start, m->end - m->start);
                 *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  
 }  }
   
   
   /*
    * Define usable memory regions.
    */
 static void  static void
 fdt_setup_initrd(void)  fdt_build_bootconfig(uint64_t mem_start, uint64_t mem_end)
 {  {
 #ifdef MEMORY_DISK_DYNAMIC          BootConfig *bc = &bootconfig;
         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)          uint64_t addr, size;
                 return;          int index;
   
         va = uvm_km_alloc(kernel_map, initrd_size, 0,          /* Reserve pages for ramdisk, rndseed, and firmware's RNG */
             UVM_KMF_VAONLY | UVM_KMF_NOWAIT);          fdt_reserve_initrd();
         if (va == 0) {          fdt_reserve_rndseed();
                 printf("Failed to allocate VA for initrd\n");          fdt_reserve_efirng();
                 return;  
           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);
                   }
         }          }
   
         md_start = (void *)va;          VPRINTF("Usable memory:\n");
           bc->dramblocks = 0;
         for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE)          fdt_memory_foreach(fdt_add_dram_blocks, bc);
                 pmap_kenter_pa(va, pa, VM_PROT_READ|VM_PROT_WRITE, 0);  
         pmap_update(pmap_kernel());  
   
         md_root_setconf(md_start, initrd_size);  
 #endif  
 }  }
   
 u_int  
   vaddr_t
 initarm(void *arg)  initarm(void *arg)
 {  {
         const struct arm_platform *plat;          const struct fdt_platform *plat;
         uint64_t memory_addr, memory_size;          uint64_t memory_start, memory_end;
   
           /* 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 = 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. */
         DPRINT("FDT<");          VPRINTF("FDT<%p>\n", fdt_addr_r);
         DPRINTN((uintptr_t)fdt_addr_r, 16);  
         DPRINT(">");  
   
         const int chosen = OF_finddevice("/chosen");  
         if (chosen >= 0)  
                 OF_getprop(chosen, "bootargs", bootargs, sizeof(bootargs));  
         boot_args = bootargs;  
   
         DPRINT(" devmap");  
         pmap_devmap_register(plat->devmap());  
   
         DPRINT(" bootstrap");          boot_args = fdt_get_bootargs();
         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->fp_devmap());
           extern char ARM_BOOTSTRAP_LxPT[];
           pmap_devmap_bootstrap((vaddr_t)ARM_BOOTSTRAP_LxPT, plat->fp_devmap());
   
           VPRINTF("bootstrap\n");
           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.
          */           */
         fdt_update_stdout_path();          VPRINTF("stdout\n");
           fdt_update_stdout_path(fdt_data, boot_args);
   
         DPRINT(" consinit");  #if BYTE_ORDER == BIG_ENDIAN
         consinit();          /*
            * 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.
            */
           fdt_pack(fdt_data);
   
         DPRINTF(" ok\n");          VPRINTF("consinit ");
           consinit();
           VPRINTF("ok\n");
   
         DPRINTF("uboot: args %#x, %#x, %#x, %#x\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 - PAGE_SIZE;          if (memory_end > memory_limit) {
 #endif                  fdt_memory_remove_range(memory_limit , memory_end);
                   memory_end = memory_limit;
 #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),  
                     (KERNEL_VM_BASE - KERNEL_BASE) >> 20);  
                 memory_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);
   
         /* 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 pmap.c. */          /*
         fdt_build_bootconfig(memory_addr, memory_size);           * Populate bootconfig structure for the benefit of dodumpsys
            */
           VPRINTF("%s: fdt_build_bootconfig\n", __func__);
           fdt_build_bootconfig(memory_start, memory_end);
   
         arm32_bootmem_init(bootconfig.dram[0].address, memory_size,          /* Perform PT build and VM init */
             KERNEL_BASE_PHYS);          cpu_kernel_vm_init(memory_start, memory_size);
         arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0,  
             plat->devmap(), mapallmem_p);  
   
         DPRINTF("bootargs: %s\n", bootargs);          VPRINTF("bootargs: %s\n", boot_args);
   
         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->fp_mpstart)
                           error = plat->fp_mpstart();
         }          }
 #endif  
   
         return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0);          if (error)
 }                  return sp;
   
 static void          /*
 fdt_update_stdout_path(void)           * Now we have APs started the pages used for stacks and L1PT can
 {           * be given to uvm
         char *stdout_path, *ep;           */
         int stdout_path_len;          extern char const __start__init_memory[];
         char buf[256];          extern char const __stop__init_memory[] __weak;
   
         const int chosen_off = fdt_path_offset(fdt_data, "/chosen");          if (&__start__init_memory[0] != &__stop__init_memory[0]) {
         if (chosen_off == -1)                  const paddr_t spa = KERN_VTOPHYS((vaddr_t)__start__init_memory);
                 return;                  const paddr_t epa = KERN_VTOPHYS((vaddr_t)__stop__init_memory);
                   const paddr_t spg = atop(spa);
                   const paddr_t epg = atop(epa);
   
         if (get_bootconf_option(boot_args, "stdout-path",                  VPRINTF("         start %08lx  end %08lx... "
             BOOTOPT_TYPE_STRING, &stdout_path) == 0)                      "loading in freelist %d\n", spa, epa, VM_FREELIST_DEFAULT);
                 return;  
   
         ep = strchr(stdout_path, ' ');                  uvm_page_physload(spg, epg, spg, epg, VM_FREELIST_DEFAULT);
         stdout_path_len = ep ? (ep - stdout_path) : strlen(stdout_path);          }
         if (stdout_path_len >= sizeof(buf))  
                 return;  
   
         strncpy(buf, stdout_path, stdout_path_len);          return sp;
         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;
Line 496  consinit(void)
Line 433  consinit(void)
         if (initialized || cons == NULL)          if (initialized || cons == NULL)
                 return;                  return;
   
         plat->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->uart_freq != NULL)          if (plat->fp_uart_freq != NULL)
                 uart_freq = plat->uart_freq();                  uart_freq = plat->fp_uart_freq();
   
         cons->consinit(&faa, uart_freq);          cons->consinit(&faa, uart_freq);
   
Line 508  consinit(void)
Line 445  consinit(void)
 }  }
   
 void  void
 delay(u_int us)  cpu_startup_hook(void)
 {  {
         const struct arm_platform *plat = arm_fdt_platform();  #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
   
         plat->delay(us);          fdtbus_intr_init();
   
           fdt_setup_rndseed();
           fdt_setup_efirng();
 }  }
   
   void
   delay(u_int us)
   {
           const struct fdt_platform *plat = fdt_platform_find();
   
           plat->fp_delay(us);
   }
 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->device_register)  #if NWSDISPLAY > 0 && NGENFB > 0
                 plat->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
   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  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->reset)          if (plat && plat->fp_reset)
                 plat->reset();                  plat->fp_reset();
 }  }
   
 static void  static void
Line 543  fdt_powerdown(void)
Line 522  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

Legend:
Removed from v.1.4.2.5  
changed lines
  Added in v.1.107

CVSweb <webmaster@jp.NetBSD.org>