prom.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. void __init early_init_devtree(void *params)
  45. {
  46. __be32 *dtb = (u32 *)__dtb_start;
  47. #if defined(CONFIG_NIOS2_DTB_AT_PHYS_ADDR)
  48. if (be32_to_cpup((__be32 *)CONFIG_NIOS2_DTB_PHYS_ADDR) ==
  49. OF_DT_HEADER) {
  50. params = (void *)CONFIG_NIOS2_DTB_PHYS_ADDR;
  51. early_init_dt_scan(params);
  52. return;
  53. }
  54. #endif
  55. if (be32_to_cpu((__be32) *dtb) == OF_DT_HEADER)
  56. params = (void *)__dtb_start;
  57. early_init_dt_scan(params);
  58. }
  59. #ifdef CONFIG_EARLY_PRINTK
  60. static int __init early_init_dt_scan_serial(unsigned long node,
  61. const char *uname, int depth, void *data)
  62. {
  63. u64 *addr64 = (u64 *) data;
  64. const char *p;
  65. /* only consider serial nodes */
  66. if (strncmp(uname, "serial", 6) != 0)
  67. return 0;
  68. p = of_get_flat_dt_prop(node, "compatible", NULL);
  69. if (!p)
  70. return 0;
  71. /*
  72. * We found an altera_jtaguart but it wasn't configured for console, so
  73. * skip it.
  74. */
  75. #ifndef CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE
  76. if (strncmp(p, "altr,juart", 10) == 0)
  77. return 0;
  78. #endif
  79. /*
  80. * Same for altera_uart.
  81. */
  82. #ifndef CONFIG_SERIAL_ALTERA_UART_CONSOLE
  83. if (strncmp(p, "altr,uart", 9) == 0)
  84. return 0;
  85. #endif
  86. *addr64 = fdt_translate_address((const void *)initial_boot_params,
  87. node);
  88. return *addr64 == OF_BAD_ADDR ? 0 : 1;
  89. }
  90. unsigned long __init of_early_console(void)
  91. {
  92. u64 base = 0;
  93. if (of_scan_flat_dt(early_init_dt_scan_serial, &base))
  94. return (u32)ioremap(base, 32);
  95. else
  96. return 0;
  97. }
  98. #endif /* CONFIG_EARLY_PRINTK */