1 /* 2 * MIPS support for CONFIG_OF device tree support 3 * 4 * Copyright (C) 2010 Cisco Systems Inc. <dediao@cisco.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 as 8 * published by the Free Software Foundation. 9 */ 10 11 #include <linux/init.h> 12 #include <linux/export.h> 13 #include <linux/errno.h> 14 #include <linux/types.h> 15 #include <linux/bootmem.h> 16 #include <linux/initrd.h> 17 #include <linux/debugfs.h> 18 #include <linux/of.h> 19 #include <linux/of_fdt.h> 20 #include <linux/of_irq.h> 21 #include <linux/of_platform.h> 22 23 #include <asm/page.h> 24 #include <asm/prom.h> 25 26 static char mips_machine_name[64] = "Unknown"; 27 28 __init void mips_set_machine_name(const char *name) 29 { 30 if (name == NULL) 31 return; 32 33 strlcpy(mips_machine_name, name, sizeof(mips_machine_name)); 34 pr_info("MIPS: machine is %s\n", mips_get_machine_name()); 35 } 36 37 char *mips_get_machine_name(void) 38 { 39 return mips_machine_name; 40 } 41 42 #ifdef CONFIG_OF 43 int __init early_init_dt_scan_memory_arch(unsigned long node, 44 const char *uname, int depth, 45 void *data) 46 { 47 return early_init_dt_scan_memory(node, uname, depth, data); 48 } 49 50 void __init early_init_dt_add_memory_arch(u64 base, u64 size) 51 { 52 return add_memory_region(base, size, BOOT_MEM_RAM); 53 } 54 55 void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align) 56 { 57 return __alloc_bootmem(size, align, __pa(MAX_DMA_ADDRESS)); 58 } 59 60 #ifdef CONFIG_BLK_DEV_INITRD 61 void __init early_init_dt_setup_initrd_arch(u64 start, u64 end) 62 { 63 initrd_start = (unsigned long)__va(start); 64 initrd_end = (unsigned long)__va(end); 65 initrd_below_start_ok = 1; 66 } 67 #endif 68 69 int __init early_init_dt_scan_model(unsigned long node, const char *uname, 70 int depth, void *data) 71 { 72 if (!depth) { 73 char *model = of_get_flat_dt_prop(node, "model", NULL); 74 75 if (model) 76 mips_set_machine_name(model); 77 } 78 return 0; 79 } 80 81 void __init early_init_devtree(void *params) 82 { 83 /* Setup flat device-tree pointer */ 84 initial_boot_params = params; 85 86 /* Retrieve various informations from the /chosen node of the 87 * device-tree, including the platform type, initrd location and 88 * size, and more ... 89 */ 90 of_scan_flat_dt(early_init_dt_scan_chosen, arcs_cmdline); 91 92 93 /* Scan memory nodes */ 94 of_scan_flat_dt(early_init_dt_scan_root, NULL); 95 of_scan_flat_dt(early_init_dt_scan_memory_arch, NULL); 96 97 /* try to load the mips machine name */ 98 of_scan_flat_dt(early_init_dt_scan_model, NULL); 99 } 100 101 void __init __dt_setup_arch(struct boot_param_header *bph) 102 { 103 if (be32_to_cpu(bph->magic) != OF_DT_HEADER) { 104 pr_err("DTB has bad magic, ignoring builtin OF DTB\n"); 105 106 return; 107 } 108 109 initial_boot_params = bph; 110 111 early_init_devtree(initial_boot_params); 112 } 113 #endif 114