prom.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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/lmb.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. /* export that to outside world */
  43. struct device_node *of_chosen;
  44. #define early_init_dt_scan_drconf_memory(node) 0
  45. void __init early_init_dt_scan_chosen_arch(unsigned long node)
  46. {
  47. /* No Microblaze specific code here */
  48. }
  49. static int __init early_init_dt_scan_memory(unsigned long node,
  50. const char *uname, int depth, void *data)
  51. {
  52. char *type = of_get_flat_dt_prop(node, "device_type", NULL);
  53. __be32 *reg, *endp;
  54. unsigned long l;
  55. /* Look for the ibm,dynamic-reconfiguration-memory node */
  56. /* if (depth == 1 &&
  57. strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0)
  58. return early_init_dt_scan_drconf_memory(node);
  59. */
  60. /* We are scanning "memory" nodes only */
  61. if (type == NULL) {
  62. /*
  63. * The longtrail doesn't have a device_type on the
  64. * /memory node, so look for the node called /memory@0.
  65. */
  66. if (depth != 1 || strcmp(uname, "memory@0") != 0)
  67. return 0;
  68. } else if (strcmp(type, "memory") != 0)
  69. return 0;
  70. reg = (__be32 *)of_get_flat_dt_prop(node, "linux,usable-memory", &l);
  71. if (reg == NULL)
  72. reg = (__be32 *)of_get_flat_dt_prop(node, "reg", &l);
  73. if (reg == NULL)
  74. return 0;
  75. endp = reg + (l / sizeof(__be32));
  76. pr_debug("memory scan node %s, reg size %ld, data: %x %x %x %x,\n",
  77. uname, l, reg[0], reg[1], reg[2], reg[3]);
  78. while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
  79. u64 base, size;
  80. base = dt_mem_next_cell(dt_root_addr_cells, &reg);
  81. size = dt_mem_next_cell(dt_root_size_cells, &reg);
  82. if (size == 0)
  83. continue;
  84. pr_debug(" - %llx , %llx\n", (unsigned long long)base,
  85. (unsigned long long)size);
  86. lmb_add(base, size);
  87. }
  88. return 0;
  89. }
  90. #ifdef CONFIG_EARLY_PRINTK
  91. /* MS this is Microblaze specifig function */
  92. static int __init early_init_dt_scan_serial(unsigned long node,
  93. const char *uname, int depth, void *data)
  94. {
  95. unsigned long l;
  96. char *p;
  97. int *addr;
  98. pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
  99. /* find all serial nodes */
  100. if (strncmp(uname, "serial", 6) != 0)
  101. return 0;
  102. early_init_dt_check_for_initrd(node);
  103. /* find compatible node with uartlite */
  104. p = of_get_flat_dt_prop(node, "compatible", &l);
  105. if ((strncmp(p, "xlnx,xps-uartlite", 17) != 0) &&
  106. (strncmp(p, "xlnx,opb-uartlite", 17) != 0))
  107. return 0;
  108. addr = of_get_flat_dt_prop(node, "reg", &l);
  109. return *addr; /* return address */
  110. }
  111. /* this function is looking for early uartlite console - Microblaze specific */
  112. int __init early_uartlite_console(void)
  113. {
  114. return of_scan_flat_dt(early_init_dt_scan_serial, NULL);
  115. }
  116. #endif
  117. void __init early_init_devtree(void *params)
  118. {
  119. pr_debug(" -> early_init_devtree(%p)\n", params);
  120. /* Setup flat device-tree pointer */
  121. initial_boot_params = params;
  122. /* Retrieve various informations from the /chosen node of the
  123. * device-tree, including the platform type, initrd location and
  124. * size, TCE reserve, and more ...
  125. */
  126. of_scan_flat_dt(early_init_dt_scan_chosen, NULL);
  127. /* Scan memory nodes and rebuild LMBs */
  128. lmb_init();
  129. of_scan_flat_dt(early_init_dt_scan_root, NULL);
  130. of_scan_flat_dt(early_init_dt_scan_memory, NULL);
  131. /* Save command line for /proc/cmdline and then parse parameters */
  132. strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE);
  133. parse_early_param();
  134. lmb_analyze();
  135. pr_debug("Phys. mem: %lx\n", (unsigned long) lmb_phys_mem_size());
  136. pr_debug(" <- early_init_devtree()\n");
  137. }
  138. /*******
  139. *
  140. * New implementation of the OF "find" APIs, return a refcounted
  141. * object, call of_node_put() when done. The device tree and list
  142. * are protected by a rw_lock.
  143. *
  144. * Note that property management will need some locking as well,
  145. * this isn't dealt with yet.
  146. *
  147. *******/
  148. #if defined(CONFIG_DEBUG_FS) && defined(DEBUG)
  149. static struct debugfs_blob_wrapper flat_dt_blob;
  150. static int __init export_flat_device_tree(void)
  151. {
  152. struct dentry *d;
  153. flat_dt_blob.data = initial_boot_params;
  154. flat_dt_blob.size = initial_boot_params->totalsize;
  155. d = debugfs_create_blob("flat-device-tree", S_IFREG | S_IRUSR,
  156. of_debugfs_root, &flat_dt_blob);
  157. if (!d)
  158. return 1;
  159. return 0;
  160. }
  161. device_initcall(export_flat_device_tree);
  162. #endif