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