prom.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * Procedures for creating, accessing and interpreting the device tree.
  3. *
  4. * Paul Mackerras August 1996.
  5. * Copyright (C) 1996-2005 Paul Mackerras.
  6. *
  7. * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
  8. * {engebret|bergner}@us.ibm.com
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version
  13. * 2 of the License, or (at your option) any later version.
  14. */
  15. #include <stdarg.h>
  16. #include <linux/kernel.h>
  17. #include <linux/string.h>
  18. #include <linux/init.h>
  19. #include <linux/threads.h>
  20. #include <linux/spinlock.h>
  21. #include <linux/types.h>
  22. #include <linux/pci.h>
  23. #include <linux/stringify.h>
  24. #include <linux/delay.h>
  25. #include <linux/initrd.h>
  26. #include <linux/bitops.h>
  27. #include <linux/module.h>
  28. #include <linux/kexec.h>
  29. #include <linux/debugfs.h>
  30. #include <linux/irq.h>
  31. #include <linux/memblock.h>
  32. #include <asm/prom.h>
  33. #include <asm/page.h>
  34. #include <asm/processor.h>
  35. #include <asm/irq.h>
  36. #include <linux/io.h>
  37. #include <asm/system.h>
  38. #include <asm/mmu.h>
  39. #include <asm/pgtable.h>
  40. #include <asm/sections.h>
  41. #include <asm/pci-bridge.h>
  42. void __init early_init_dt_add_memory_arch(u64 base, u64 size)
  43. {
  44. memblock_add(base, size);
  45. }
  46. u64 __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
  47. {
  48. return memblock_alloc(size, align);
  49. }
  50. #ifdef CONFIG_EARLY_PRINTK
  51. /* MS this is Microblaze specifig function */
  52. static int __init early_init_dt_scan_serial(unsigned long node,
  53. const char *uname, int depth, void *data)
  54. {
  55. unsigned long l;
  56. char *p;
  57. int *addr;
  58. pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
  59. /* find all serial nodes */
  60. if (strncmp(uname, "serial", 6) != 0)
  61. return 0;
  62. early_init_dt_check_for_initrd(node);
  63. /* find compatible node with uartlite */
  64. p = of_get_flat_dt_prop(node, "compatible", &l);
  65. if ((strncmp(p, "xlnx,xps-uartlite", 17) != 0) &&
  66. (strncmp(p, "xlnx,opb-uartlite", 17) != 0) &&
  67. (strncmp(p, "xlnx,axi-uartlite", 17) != 0))
  68. return 0;
  69. addr = of_get_flat_dt_prop(node, "reg", &l);
  70. return be32_to_cpup(addr); /* return address */
  71. }
  72. /* this function is looking for early uartlite console - Microblaze specific */
  73. int __init early_uartlite_console(void)
  74. {
  75. return of_scan_flat_dt(early_init_dt_scan_serial, NULL);
  76. }
  77. /* MS this is Microblaze specifig function */
  78. static int __init early_init_dt_scan_serial_full(unsigned long node,
  79. const char *uname, int depth, void *data)
  80. {
  81. unsigned long l;
  82. char *p;
  83. unsigned int addr;
  84. pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
  85. /* find all serial nodes */
  86. if (strncmp(uname, "serial", 6) != 0)
  87. return 0;
  88. early_init_dt_check_for_initrd(node);
  89. /* find compatible node with uartlite */
  90. p = of_get_flat_dt_prop(node, "compatible", &l);
  91. if ((strncmp(p, "xlnx,xps-uart16550", 18) != 0) &&
  92. (strncmp(p, "xlnx,axi-uart16550", 18) != 0))
  93. return 0;
  94. addr = *(u32 *)of_get_flat_dt_prop(node, "reg", &l);
  95. addr += *(u32 *)of_get_flat_dt_prop(node, "reg-offset", &l);
  96. return be32_to_cpu(addr); /* return address */
  97. }
  98. /* this function is looking for early uartlite console - Microblaze specific */
  99. int __init early_uart16550_console(void)
  100. {
  101. return of_scan_flat_dt(early_init_dt_scan_serial_full, NULL);
  102. }
  103. #endif
  104. void __init early_init_devtree(void *params)
  105. {
  106. pr_debug(" -> early_init_devtree(%p)\n", params);
  107. /* Setup flat device-tree pointer */
  108. initial_boot_params = params;
  109. /* Retrieve various informations from the /chosen node of the
  110. * device-tree, including the platform type, initrd location and
  111. * size, TCE reserve, and more ...
  112. */
  113. of_scan_flat_dt(early_init_dt_scan_chosen, NULL);
  114. /* Scan memory nodes and rebuild MEMBLOCKs */
  115. memblock_init();
  116. of_scan_flat_dt(early_init_dt_scan_root, NULL);
  117. of_scan_flat_dt(early_init_dt_scan_memory, NULL);
  118. /* Save command line for /proc/cmdline and then parse parameters */
  119. strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE);
  120. parse_early_param();
  121. memblock_analyze();
  122. pr_debug("Phys. mem: %lx\n", (unsigned long) memblock_phys_mem_size());
  123. pr_debug(" <- early_init_devtree()\n");
  124. }
  125. #ifdef CONFIG_BLK_DEV_INITRD
  126. void __init early_init_dt_setup_initrd_arch(unsigned long start,
  127. unsigned long end)
  128. {
  129. initrd_start = (unsigned long)__va(start);
  130. initrd_end = (unsigned long)__va(end);
  131. initrd_below_start_ok = 1;
  132. }
  133. #endif
  134. /*******
  135. *
  136. * New implementation of the OF "find" APIs, return a refcounted
  137. * object, call of_node_put() when done. The device tree and list
  138. * are protected by a rw_lock.
  139. *
  140. * Note that property management will need some locking as well,
  141. * this isn't dealt with yet.
  142. *
  143. *******/
  144. #if defined(CONFIG_DEBUG_FS) && defined(DEBUG)
  145. static struct debugfs_blob_wrapper flat_dt_blob;
  146. static int __init export_flat_device_tree(void)
  147. {
  148. struct dentry *d;
  149. flat_dt_blob.data = initial_boot_params;
  150. flat_dt_blob.size = initial_boot_params->totalsize;
  151. d = debugfs_create_blob("flat-device-tree", S_IFREG | S_IRUSR,
  152. of_debugfs_root, &flat_dt_blob);
  153. if (!d)
  154. return 1;
  155. return 0;
  156. }
  157. device_initcall(export_flat_device_tree);
  158. #endif