Dezhong Diao | f2ffa5a | 2010-10-13 00:52:46 -0600 | [diff] [blame] | 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> |
Paul Gortmaker | 73bc256 | 2011-07-23 16:30:40 -0400 | [diff] [blame] | 12 | #include <linux/export.h> |
Dezhong Diao | f2ffa5a | 2010-10-13 00:52:46 -0600 | [diff] [blame] | 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 | |
John Crispin | 9169a5d | 2013-04-11 05:34:59 +0000 | [diff] [blame] | 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 | |
Chen Gang | 41c8366 | 2013-05-26 07:06:06 +0000 | [diff] [blame^] | 33 | strlcpy(mips_machine_name, name, sizeof(mips_machine_name)); |
John Crispin | 9169a5d | 2013-04-11 05:34:59 +0000 | [diff] [blame] | 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 |
Dezhong Diao | f2ffa5a | 2010-10-13 00:52:46 -0600 | [diff] [blame] | 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 | |
Grant Likely | 672c544 | 2011-01-13 15:36:09 -0700 | [diff] [blame] | 55 | void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align) |
Dezhong Diao | f2ffa5a | 2010-10-13 00:52:46 -0600 | [diff] [blame] | 56 | { |
Grant Likely | 672c544 | 2011-01-13 15:36:09 -0700 | [diff] [blame] | 57 | return __alloc_bootmem(size, align, __pa(MAX_DMA_ADDRESS)); |
Dezhong Diao | f2ffa5a | 2010-10-13 00:52:46 -0600 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | #ifdef CONFIG_BLK_DEV_INITRD |
| 61 | void __init early_init_dt_setup_initrd_arch(unsigned long start, |
| 62 | unsigned long end) |
| 63 | { |
| 64 | initrd_start = (unsigned long)__va(start); |
| 65 | initrd_end = (unsigned long)__va(end); |
| 66 | initrd_below_start_ok = 1; |
| 67 | } |
| 68 | #endif |
| 69 | |
John Crispin | 9169a5d | 2013-04-11 05:34:59 +0000 | [diff] [blame] | 70 | int __init early_init_dt_scan_model(unsigned long node, const char *uname, |
| 71 | int depth, void *data) |
| 72 | { |
| 73 | if (!depth) { |
| 74 | char *model = of_get_flat_dt_prop(node, "model", NULL); |
| 75 | |
| 76 | if (model) |
| 77 | mips_set_machine_name(model); |
| 78 | } |
| 79 | return 0; |
| 80 | } |
| 81 | |
Dezhong Diao | f2ffa5a | 2010-10-13 00:52:46 -0600 | [diff] [blame] | 82 | void __init early_init_devtree(void *params) |
| 83 | { |
| 84 | /* Setup flat device-tree pointer */ |
| 85 | initial_boot_params = params; |
| 86 | |
| 87 | /* Retrieve various informations from the /chosen node of the |
| 88 | * device-tree, including the platform type, initrd location and |
| 89 | * size, and more ... |
| 90 | */ |
Grant Likely | 85f60ae | 2011-04-29 00:18:16 -0600 | [diff] [blame] | 91 | of_scan_flat_dt(early_init_dt_scan_chosen, arcs_cmdline); |
| 92 | |
Dezhong Diao | f2ffa5a | 2010-10-13 00:52:46 -0600 | [diff] [blame] | 93 | |
| 94 | /* Scan memory nodes */ |
| 95 | of_scan_flat_dt(early_init_dt_scan_root, NULL); |
| 96 | of_scan_flat_dt(early_init_dt_scan_memory_arch, NULL); |
John Crispin | 9169a5d | 2013-04-11 05:34:59 +0000 | [diff] [blame] | 97 | |
| 98 | /* try to load the mips machine name */ |
| 99 | of_scan_flat_dt(early_init_dt_scan_model, NULL); |
Dezhong Diao | f2ffa5a | 2010-10-13 00:52:46 -0600 | [diff] [blame] | 100 | } |
| 101 | |
Ralf Baechle | 7d6168e | 2012-01-25 15:03:19 +0100 | [diff] [blame] | 102 | void __init __dt_setup_arch(struct boot_param_header *bph) |
| 103 | { |
| 104 | if (be32_to_cpu(bph->magic) != OF_DT_HEADER) { |
| 105 | pr_err("DTB has bad magic, ignoring builtin OF DTB\n"); |
| 106 | |
| 107 | return; |
| 108 | } |
| 109 | |
| 110 | initial_boot_params = bph; |
John Crispin | 40e91ae | 2012-05-02 12:27:35 +0200 | [diff] [blame] | 111 | |
| 112 | early_init_devtree(initial_boot_params); |
Ralf Baechle | 7d6168e | 2012-01-25 15:03:19 +0100 | [diff] [blame] | 113 | } |
John Crispin | 9169a5d | 2013-04-11 05:34:59 +0000 | [diff] [blame] | 114 | #endif |