prom.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Device tree support
  3. *
  4. * Copyright (C) 2013, 2015 Altera Corporation
  5. * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
  6. *
  7. * Based on MIPS support for CONFIG_OF device tree support
  8. *
  9. * Copyright (C) 2010 Cisco Systems Inc. <dediao@cisco.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. #include <linux/init.h>
  26. #include <linux/types.h>
  27. #include <linux/bootmem.h>
  28. #include <linux/of.h>
  29. #include <linux/of_fdt.h>
  30. #include <linux/io.h>
  31. #include <asm/prom.h>
  32. #include <asm/sections.h>
  33. void __init early_init_dt_add_memory_arch(u64 base, u64 size)
  34. {
  35. u64 kernel_start = (u64)virt_to_phys(_text);
  36. if (!memory_size &&
  37. (kernel_start >= base) && (kernel_start < (base + size)))
  38. memory_size = size;
  39. }
  40. void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
  41. {
  42. return alloc_bootmem_align(size, align);
  43. }
  44. int __init early_init_dt_reserve_memory_arch(phys_addr_t base, phys_addr_t size,
  45. bool nomap)
  46. {
  47. reserve_bootmem(base, size, BOOTMEM_DEFAULT);
  48. return 0;
  49. }
  50. void __init early_init_devtree(void *params)
  51. {
  52. __be32 *dtb = (u32 *)__dtb_start;
  53. #if defined(CONFIG_NIOS2_DTB_AT_PHYS_ADDR)
  54. if (be32_to_cpup((__be32 *)CONFIG_NIOS2_DTB_PHYS_ADDR) ==
  55. OF_DT_HEADER) {
  56. params = (void *)CONFIG_NIOS2_DTB_PHYS_ADDR;
  57. early_init_dt_scan(params);
  58. return;
  59. }
  60. #endif
  61. if (be32_to_cpu((__be32) *dtb) == OF_DT_HEADER)
  62. params = (void *)__dtb_start;
  63. early_init_dt_scan(params);
  64. }
  65. #ifdef CONFIG_EARLY_PRINTK
  66. static int __init early_init_dt_scan_serial(unsigned long node,
  67. const char *uname, int depth, void *data)
  68. {
  69. u64 *addr64 = (u64 *) data;
  70. const char *p;
  71. /* only consider serial nodes */
  72. if (strncmp(uname, "serial", 6) != 0)
  73. return 0;
  74. p = of_get_flat_dt_prop(node, "compatible", NULL);
  75. if (!p)
  76. return 0;
  77. /*
  78. * We found an altera_jtaguart but it wasn't configured for console, so
  79. * skip it.
  80. */
  81. #ifndef CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE
  82. if (strncmp(p, "altr,juart", 10) == 0)
  83. return 0;
  84. #endif
  85. /*
  86. * Same for altera_uart.
  87. */
  88. #ifndef CONFIG_SERIAL_ALTERA_UART_CONSOLE
  89. if (strncmp(p, "altr,uart", 9) == 0)
  90. return 0;
  91. #endif
  92. *addr64 = fdt_translate_address((const void *)initial_boot_params,
  93. node);
  94. return *addr64 == OF_BAD_ADDR ? 0 : 1;
  95. }
  96. unsigned long __init of_early_console(void)
  97. {
  98. u64 base = 0;
  99. if (of_scan_flat_dt(early_init_dt_scan_serial, &base))
  100. return (u32)ioremap(base, 32);
  101. else
  102. return 0;
  103. }
  104. #endif /* CONFIG_EARLY_PRINTK */