1f2ffa5abSDezhong Diao /* 2f2ffa5abSDezhong Diao * MIPS support for CONFIG_OF device tree support 3f2ffa5abSDezhong Diao * 4f2ffa5abSDezhong Diao * Copyright (C) 2010 Cisco Systems Inc. <dediao@cisco.com> 5f2ffa5abSDezhong Diao * 6f2ffa5abSDezhong Diao * This program is free software; you can redistribute it and/or modify 7f2ffa5abSDezhong Diao * it under the terms of the GNU General Public License version 2 as 8f2ffa5abSDezhong Diao * published by the Free Software Foundation. 9f2ffa5abSDezhong Diao */ 10f2ffa5abSDezhong Diao 11f2ffa5abSDezhong Diao #include <linux/init.h> 1273bc256dSPaul Gortmaker #include <linux/export.h> 13f2ffa5abSDezhong Diao #include <linux/errno.h> 14f2ffa5abSDezhong Diao #include <linux/types.h> 15f2ffa5abSDezhong Diao #include <linux/bootmem.h> 16f2ffa5abSDezhong Diao #include <linux/initrd.h> 17f2ffa5abSDezhong Diao #include <linux/debugfs.h> 18f2ffa5abSDezhong Diao #include <linux/of.h> 19f2ffa5abSDezhong Diao #include <linux/of_fdt.h> 20f2ffa5abSDezhong Diao #include <linux/of_irq.h> 21f2ffa5abSDezhong Diao #include <linux/of_platform.h> 22f2ffa5abSDezhong Diao 23f2ffa5abSDezhong Diao #include <asm/page.h> 24f2ffa5abSDezhong Diao #include <asm/prom.h> 25f2ffa5abSDezhong Diao 269169a5d0SJohn Crispin static char mips_machine_name[64] = "Unknown"; 279169a5d0SJohn Crispin 289169a5d0SJohn Crispin __init void mips_set_machine_name(const char *name) 299169a5d0SJohn Crispin { 309169a5d0SJohn Crispin if (name == NULL) 319169a5d0SJohn Crispin return; 329169a5d0SJohn Crispin 339169a5d0SJohn Crispin strncpy(mips_machine_name, name, sizeof(mips_machine_name)); 349169a5d0SJohn Crispin pr_info("MIPS: machine is %s\n", mips_get_machine_name()); 359169a5d0SJohn Crispin } 369169a5d0SJohn Crispin 379169a5d0SJohn Crispin char *mips_get_machine_name(void) 389169a5d0SJohn Crispin { 399169a5d0SJohn Crispin return mips_machine_name; 409169a5d0SJohn Crispin } 419169a5d0SJohn Crispin 429169a5d0SJohn Crispin #ifdef CONFIG_OF 43f2ffa5abSDezhong Diao int __init early_init_dt_scan_memory_arch(unsigned long node, 44f2ffa5abSDezhong Diao const char *uname, int depth, 45f2ffa5abSDezhong Diao void *data) 46f2ffa5abSDezhong Diao { 47f2ffa5abSDezhong Diao return early_init_dt_scan_memory(node, uname, depth, data); 48f2ffa5abSDezhong Diao } 49f2ffa5abSDezhong Diao 50f2ffa5abSDezhong Diao void __init early_init_dt_add_memory_arch(u64 base, u64 size) 51f2ffa5abSDezhong Diao { 52f2ffa5abSDezhong Diao return add_memory_region(base, size, BOOT_MEM_RAM); 53f2ffa5abSDezhong Diao } 54f2ffa5abSDezhong Diao 55672c5446SGrant Likely void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align) 56f2ffa5abSDezhong Diao { 57672c5446SGrant Likely return __alloc_bootmem(size, align, __pa(MAX_DMA_ADDRESS)); 58f2ffa5abSDezhong Diao } 59f2ffa5abSDezhong Diao 60f2ffa5abSDezhong Diao #ifdef CONFIG_BLK_DEV_INITRD 61f2ffa5abSDezhong Diao void __init early_init_dt_setup_initrd_arch(unsigned long start, 62f2ffa5abSDezhong Diao unsigned long end) 63f2ffa5abSDezhong Diao { 64f2ffa5abSDezhong Diao initrd_start = (unsigned long)__va(start); 65f2ffa5abSDezhong Diao initrd_end = (unsigned long)__va(end); 66f2ffa5abSDezhong Diao initrd_below_start_ok = 1; 67f2ffa5abSDezhong Diao } 68f2ffa5abSDezhong Diao #endif 69f2ffa5abSDezhong Diao 709169a5d0SJohn Crispin int __init early_init_dt_scan_model(unsigned long node, const char *uname, 719169a5d0SJohn Crispin int depth, void *data) 729169a5d0SJohn Crispin { 739169a5d0SJohn Crispin if (!depth) { 749169a5d0SJohn Crispin char *model = of_get_flat_dt_prop(node, "model", NULL); 759169a5d0SJohn Crispin 769169a5d0SJohn Crispin if (model) 779169a5d0SJohn Crispin mips_set_machine_name(model); 789169a5d0SJohn Crispin } 799169a5d0SJohn Crispin return 0; 809169a5d0SJohn Crispin } 819169a5d0SJohn Crispin 82f2ffa5abSDezhong Diao void __init early_init_devtree(void *params) 83f2ffa5abSDezhong Diao { 84f2ffa5abSDezhong Diao /* Setup flat device-tree pointer */ 85f2ffa5abSDezhong Diao initial_boot_params = params; 86f2ffa5abSDezhong Diao 87f2ffa5abSDezhong Diao /* Retrieve various informations from the /chosen node of the 88f2ffa5abSDezhong Diao * device-tree, including the platform type, initrd location and 89f2ffa5abSDezhong Diao * size, and more ... 90f2ffa5abSDezhong Diao */ 9185f60ae4SGrant Likely of_scan_flat_dt(early_init_dt_scan_chosen, arcs_cmdline); 9285f60ae4SGrant Likely 93f2ffa5abSDezhong Diao 94f2ffa5abSDezhong Diao /* Scan memory nodes */ 95f2ffa5abSDezhong Diao of_scan_flat_dt(early_init_dt_scan_root, NULL); 96f2ffa5abSDezhong Diao of_scan_flat_dt(early_init_dt_scan_memory_arch, NULL); 979169a5d0SJohn Crispin 989169a5d0SJohn Crispin /* try to load the mips machine name */ 999169a5d0SJohn Crispin of_scan_flat_dt(early_init_dt_scan_model, NULL); 100f2ffa5abSDezhong Diao } 101f2ffa5abSDezhong Diao 1027d6168e5SRalf Baechle void __init __dt_setup_arch(struct boot_param_header *bph) 1037d6168e5SRalf Baechle { 1047d6168e5SRalf Baechle if (be32_to_cpu(bph->magic) != OF_DT_HEADER) { 1057d6168e5SRalf Baechle pr_err("DTB has bad magic, ignoring builtin OF DTB\n"); 1067d6168e5SRalf Baechle 1077d6168e5SRalf Baechle return; 1087d6168e5SRalf Baechle } 1097d6168e5SRalf Baechle 1107d6168e5SRalf Baechle initial_boot_params = bph; 11140e91aecSJohn Crispin 11240e91aecSJohn Crispin early_init_devtree(initial_boot_params); 1137d6168e5SRalf Baechle } 1149169a5d0SJohn Crispin #endif 115