sead3-setup.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.
  7. * Copyright (C) 2013 Imagination Technologies Ltd.
  8. */
  9. #include <linux/init.h>
  10. #include <linux/libfdt.h>
  11. #include <linux/of_platform.h>
  12. #include <linux/of_fdt.h>
  13. #include <asm/prom.h>
  14. #include <asm/fw/fw.h>
  15. #include <asm/mips-boards/generic.h>
  16. const char *get_system_type(void)
  17. {
  18. return "MIPS SEAD3";
  19. }
  20. static uint32_t get_memsize_from_cmdline(void)
  21. {
  22. int memsize = 0;
  23. char *p = arcs_cmdline;
  24. char *s = "memsize=";
  25. p = strstr(p, s);
  26. if (p) {
  27. p += strlen(s);
  28. memsize = memparse(p, NULL);
  29. }
  30. return memsize;
  31. }
  32. static uint32_t get_memsize_from_env(void)
  33. {
  34. int memsize = 0;
  35. char *p;
  36. p = fw_getenv("memsize");
  37. if (p)
  38. memsize = memparse(p, NULL);
  39. return memsize;
  40. }
  41. static uint32_t get_memsize(void)
  42. {
  43. uint32_t memsize;
  44. memsize = get_memsize_from_cmdline();
  45. if (memsize)
  46. return memsize;
  47. return get_memsize_from_env();
  48. }
  49. static void __init parse_memsize_param(void)
  50. {
  51. int offset;
  52. const uint64_t *prop_value;
  53. int prop_len;
  54. uint32_t memsize = get_memsize();
  55. if (!memsize)
  56. return;
  57. offset = fdt_path_offset(__dtb_start, "/memory");
  58. if (offset > 0) {
  59. uint64_t new_value;
  60. /*
  61. * reg contains 2 32-bits BE values, offset and size. We just
  62. * want to replace the size value without affecting the offset
  63. */
  64. prop_value = fdt_getprop(__dtb_start, offset, "reg", &prop_len);
  65. new_value = be64_to_cpu(*prop_value);
  66. new_value = (new_value & ~0xffffffffllu) | memsize;
  67. fdt_setprop_inplace_u64(__dtb_start, offset, "reg", new_value);
  68. }
  69. }
  70. void __init plat_mem_setup(void)
  71. {
  72. /* allow command line/bootloader env to override memory size in DT */
  73. parse_memsize_param();
  74. /*
  75. * Load the builtin devicetree. This causes the chosen node to be
  76. * parsed resulting in our memory appearing
  77. */
  78. __dt_setup_arch(__dtb_start);
  79. }
  80. void __init device_tree_init(void)
  81. {
  82. if (!initial_boot_params)
  83. return;
  84. unflatten_and_copy_device_tree();
  85. }
  86. static int __init customize_machine(void)
  87. {
  88. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  89. return 0;
  90. }
  91. arch_initcall(customize_machine);