prom.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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/export.h>
  17. #include <linux/kernel.h>
  18. #include <linux/string.h>
  19. #include <linux/init.h>
  20. #include <linux/threads.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/types.h>
  23. #include <linux/pci.h>
  24. #include <linux/stringify.h>
  25. #include <linux/delay.h>
  26. #include <linux/initrd.h>
  27. #include <linux/bitops.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/mmu.h>
  38. #include <asm/pgtable.h>
  39. #include <asm/sections.h>
  40. #include <asm/pci-bridge.h>
  41. void __init early_init_dt_add_memory_arch(u64 base, u64 size)
  42. {
  43. memblock_add(base, size);
  44. }
  45. #ifdef CONFIG_EARLY_PRINTK
  46. static char *stdout;
  47. static int __init early_init_dt_scan_chosen_serial(unsigned long node,
  48. const char *uname, int depth, void *data)
  49. {
  50. unsigned long l;
  51. char *p;
  52. pr_debug("%s: depth: %d, uname: %s\n", __func__, depth, uname);
  53. if (depth == 1 && (strcmp(uname, "chosen") == 0 ||
  54. strcmp(uname, "chosen@0") == 0)) {
  55. p = of_get_flat_dt_prop(node, "linux,stdout-path", &l);
  56. if (p != NULL && l > 0)
  57. stdout = p; /* store pointer to stdout-path */
  58. }
  59. if (stdout && strstr(stdout, uname)) {
  60. p = of_get_flat_dt_prop(node, "compatible", &l);
  61. pr_debug("Compatible string: %s\n", p);
  62. if ((strncmp(p, "xlnx,xps-uart16550", 18) == 0) ||
  63. (strncmp(p, "xlnx,axi-uart16550", 18) == 0)) {
  64. unsigned int addr;
  65. *(u32 *)data = UART16550;
  66. addr = *(u32 *)of_get_flat_dt_prop(node, "reg", &l);
  67. addr += *(u32 *)of_get_flat_dt_prop(node,
  68. "reg-offset", &l);
  69. /* clear register offset */
  70. return be32_to_cpu(addr) & ~3;
  71. }
  72. if ((strncmp(p, "xlnx,xps-uartlite", 17) == 0) ||
  73. (strncmp(p, "xlnx,opb-uartlite", 17) == 0) ||
  74. (strncmp(p, "xlnx,axi-uartlite", 17) == 0) ||
  75. (strncmp(p, "xlnx,mdm", 8) == 0)) {
  76. unsigned int *addrp;
  77. *(u32 *)data = UARTLITE;
  78. addrp = of_get_flat_dt_prop(node, "reg", &l);
  79. return be32_to_cpup(addrp); /* return address */
  80. }
  81. }
  82. return 0;
  83. }
  84. /* this function is looking for early console - Microblaze specific */
  85. int __init of_early_console(void *version)
  86. {
  87. return of_scan_flat_dt(early_init_dt_scan_chosen_serial, version);
  88. }
  89. #endif
  90. void __init early_init_devtree(void *params)
  91. {
  92. pr_debug(" -> early_init_devtree(%p)\n", params);
  93. /* Setup flat device-tree pointer */
  94. initial_boot_params = params;
  95. /* Retrieve various informations from the /chosen node of the
  96. * device-tree, including the platform type, initrd location and
  97. * size, TCE reserve, and more ...
  98. */
  99. of_scan_flat_dt(early_init_dt_scan_chosen, cmd_line);
  100. /* Scan memory nodes and rebuild MEMBLOCKs */
  101. of_scan_flat_dt(early_init_dt_scan_root, NULL);
  102. of_scan_flat_dt(early_init_dt_scan_memory, NULL);
  103. /* Save command line for /proc/cmdline and then parse parameters */
  104. strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE);
  105. parse_early_param();
  106. memblock_allow_resize();
  107. pr_debug("Phys. mem: %lx\n", (unsigned long) memblock_phys_mem_size());
  108. pr_debug(" <- early_init_devtree()\n");
  109. }
  110. #ifdef CONFIG_BLK_DEV_INITRD
  111. void __init early_init_dt_setup_initrd_arch(u64 start, u64 end)
  112. {
  113. initrd_start = (unsigned long)__va(start);
  114. initrd_end = (unsigned long)__va(end);
  115. initrd_below_start_ok = 1;
  116. }
  117. #endif
  118. /*******
  119. *
  120. * New implementation of the OF "find" APIs, return a refcounted
  121. * object, call of_node_put() when done. The device tree and list
  122. * are protected by a rw_lock.
  123. *
  124. * Note that property management will need some locking as well,
  125. * this isn't dealt with yet.
  126. *
  127. *******/
  128. #if defined(CONFIG_DEBUG_FS) && defined(DEBUG)
  129. static struct debugfs_blob_wrapper flat_dt_blob;
  130. static int __init export_flat_device_tree(void)
  131. {
  132. struct dentry *d;
  133. flat_dt_blob.data = initial_boot_params;
  134. flat_dt_blob.size = initial_boot_params->totalsize;
  135. d = debugfs_create_blob("flat-device-tree", S_IFREG | S_IRUSR,
  136. of_debugfs_root, &flat_dt_blob);
  137. if (!d)
  138. return 1;
  139. return 0;
  140. }
  141. device_initcall(export_flat_device_tree);
  142. #endif