sead3-setup.c 2.1 KB

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