Steven J. Hill | 3070033 | 2012-05-30 21:02:49 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. |
Qais Yousef | 4432723 | 2013-12-06 11:00:42 +0000 | [diff] [blame] | 7 | * Copyright (C) 2013 Imagination Technologies Ltd. |
Steven J. Hill | 3070033 | 2012-05-30 21:02:49 +0000 | [diff] [blame] | 8 | */ |
| 9 | #include <linux/init.h> |
Qais Yousef | 4432723 | 2013-12-06 11:00:42 +0000 | [diff] [blame] | 10 | #include <linux/libfdt.h> |
Steven J. Hill | 9b73100 | 2013-01-17 11:37:03 -0600 | [diff] [blame] | 11 | #include <linux/of_platform.h> |
| 12 | #include <linux/of_fdt.h> |
Steven J. Hill | 9b73100 | 2013-01-17 11:37:03 -0600 | [diff] [blame] | 13 | |
Rob Herring | 089a49b | 2013-09-07 14:58:54 -0500 | [diff] [blame] | 14 | #include <asm/prom.h> |
Qais Yousef | 4432723 | 2013-12-06 11:00:42 +0000 | [diff] [blame] | 15 | #include <asm/fw/fw.h> |
Rob Herring | 089a49b | 2013-09-07 14:58:54 -0500 | [diff] [blame] | 16 | |
Steven J. Hill | 9b73100 | 2013-01-17 11:37:03 -0600 | [diff] [blame] | 17 | #include <asm/mips-boards/generic.h> |
Steven J. Hill | 3070033 | 2012-05-30 21:02:49 +0000 | [diff] [blame] | 18 | |
Steven J. Hill | 3070033 | 2012-05-30 21:02:49 +0000 | [diff] [blame] | 19 | const char *get_system_type(void) |
| 20 | { |
| 21 | return "MIPS SEAD3"; |
| 22 | } |
| 23 | |
Qais Yousef | 4432723 | 2013-12-06 11:00:42 +0000 | [diff] [blame] | 24 | static uint32_t get_memsize_from_cmdline(void) |
| 25 | { |
| 26 | int memsize = 0; |
| 27 | char *p = arcs_cmdline; |
| 28 | char *s = "memsize="; |
| 29 | |
| 30 | p = strstr(p, s); |
| 31 | if (p) { |
| 32 | p += strlen(s); |
| 33 | memsize = memparse(p, NULL); |
| 34 | } |
| 35 | |
| 36 | return memsize; |
| 37 | } |
| 38 | |
| 39 | static uint32_t get_memsize_from_env(void) |
| 40 | { |
| 41 | int memsize = 0; |
| 42 | char *p; |
| 43 | |
| 44 | p = fw_getenv("memsize"); |
| 45 | if (p) |
| 46 | memsize = memparse(p, NULL); |
| 47 | |
| 48 | return memsize; |
| 49 | } |
| 50 | |
| 51 | static uint32_t get_memsize(void) |
| 52 | { |
| 53 | uint32_t memsize; |
| 54 | |
| 55 | memsize = get_memsize_from_cmdline(); |
| 56 | if (memsize) |
| 57 | return memsize; |
| 58 | |
| 59 | return get_memsize_from_env(); |
| 60 | } |
| 61 | |
| 62 | static void __init parse_memsize_param(void) |
| 63 | { |
| 64 | int offset; |
| 65 | const uint64_t *prop_value; |
| 66 | int prop_len; |
| 67 | uint32_t memsize = get_memsize(); |
| 68 | |
| 69 | if (!memsize) |
| 70 | return; |
| 71 | |
Rob Herring | 0cdde83 | 2014-03-31 15:13:07 -0500 | [diff] [blame] | 72 | offset = fdt_path_offset(__dtb_start, "/memory"); |
Qais Yousef | 4432723 | 2013-12-06 11:00:42 +0000 | [diff] [blame] | 73 | if (offset > 0) { |
| 74 | uint64_t new_value; |
| 75 | /* |
| 76 | * reg contains 2 32-bits BE values, offset and size. We just |
| 77 | * want to replace the size value without affecting the offset |
| 78 | */ |
Rob Herring | 0cdde83 | 2014-03-31 15:13:07 -0500 | [diff] [blame] | 79 | prop_value = fdt_getprop(__dtb_start, offset, "reg", &prop_len); |
Qais Yousef | 4432723 | 2013-12-06 11:00:42 +0000 | [diff] [blame] | 80 | new_value = be64_to_cpu(*prop_value); |
| 81 | new_value = (new_value & ~0xffffffffllu) | memsize; |
Rob Herring | 0cdde83 | 2014-03-31 15:13:07 -0500 | [diff] [blame] | 82 | fdt_setprop_inplace_u64(__dtb_start, offset, "reg", new_value); |
Qais Yousef | 4432723 | 2013-12-06 11:00:42 +0000 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | |
Steven J. Hill | 3070033 | 2012-05-30 21:02:49 +0000 | [diff] [blame] | 86 | void __init plat_mem_setup(void) |
| 87 | { |
Qais Yousef | 4432723 | 2013-12-06 11:00:42 +0000 | [diff] [blame] | 88 | /* allow command line/bootloader env to override memory size in DT */ |
| 89 | parse_memsize_param(); |
| 90 | |
Steven J. Hill | 9b73100 | 2013-01-17 11:37:03 -0600 | [diff] [blame] | 91 | /* |
| 92 | * Load the builtin devicetree. This causes the chosen node to be |
| 93 | * parsed resulting in our memory appearing |
| 94 | */ |
Rob Herring | 0cdde83 | 2014-03-31 15:13:07 -0500 | [diff] [blame] | 95 | __dt_setup_arch(__dtb_start); |
Steven J. Hill | 9b73100 | 2013-01-17 11:37:03 -0600 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | void __init device_tree_init(void) |
| 99 | { |
Steven J. Hill | 9b73100 | 2013-01-17 11:37:03 -0600 | [diff] [blame] | 100 | if (!initial_boot_params) |
| 101 | return; |
| 102 | |
Qais Yousef | 7e8a276 | 2013-12-06 11:00:45 +0000 | [diff] [blame] | 103 | unflatten_and_copy_device_tree(); |
Steven J. Hill | 3070033 | 2012-05-30 21:02:49 +0000 | [diff] [blame] | 104 | } |
Qais Yousef | 187e7c5 | 2013-12-06 11:00:44 +0000 | [diff] [blame] | 105 | |
| 106 | static int __init customize_machine(void) |
| 107 | { |
| 108 | of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); |
| 109 | return 0; |
| 110 | } |
| 111 | arch_initcall(customize_machine); |