prom_32.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. * Adapted for sparc32 by David S. Miller davem@davemloft.net
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version
  15. * 2 of the License, or (at your option) any later version.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/types.h>
  19. #include <linux/string.h>
  20. #include <linux/mm.h>
  21. #include <linux/bootmem.h>
  22. #include <linux/module.h>
  23. #include <asm/prom.h>
  24. #include <asm/oplib.h>
  25. #include "prom.h"
  26. void * __init prom_early_alloc(unsigned long size)
  27. {
  28. void *ret;
  29. ret = __alloc_bootmem(size, SMP_CACHE_BYTES, 0UL);
  30. if (ret != NULL)
  31. memset(ret, 0, size);
  32. prom_early_allocated += size;
  33. return ret;
  34. }
  35. /* The following routines deal with the black magic of fully naming a
  36. * node.
  37. *
  38. * Certain well known named nodes are just the simple name string.
  39. *
  40. * Actual devices have an address specifier appended to the base name
  41. * string, like this "foo@addr". The "addr" can be in any number of
  42. * formats, and the platform plus the type of the node determine the
  43. * format and how it is constructed.
  44. *
  45. * For children of the ROOT node, the naming convention is fixed and
  46. * determined by whether this is a sun4u or sun4v system.
  47. *
  48. * For children of other nodes, it is bus type specific. So
  49. * we walk up the tree until we discover a "device_type" property
  50. * we recognize and we go from there.
  51. */
  52. static void __init sparc32_path_component(struct device_node *dp, char *tmp_buf)
  53. {
  54. struct linux_prom_registers *regs;
  55. struct property *rprop;
  56. rprop = of_find_property(dp, "reg", NULL);
  57. if (!rprop)
  58. return;
  59. regs = rprop->value;
  60. sprintf(tmp_buf, "%s@%x,%x",
  61. dp->name,
  62. regs->which_io, regs->phys_addr);
  63. }
  64. /* "name@slot,offset" */
  65. static void __init sbus_path_component(struct device_node *dp, char *tmp_buf)
  66. {
  67. struct linux_prom_registers *regs;
  68. struct property *prop;
  69. prop = of_find_property(dp, "reg", NULL);
  70. if (!prop)
  71. return;
  72. regs = prop->value;
  73. sprintf(tmp_buf, "%s@%x,%x",
  74. dp->name,
  75. regs->which_io,
  76. regs->phys_addr);
  77. }
  78. /* "name@devnum[,func]" */
  79. static void __init pci_path_component(struct device_node *dp, char *tmp_buf)
  80. {
  81. struct linux_prom_pci_registers *regs;
  82. struct property *prop;
  83. unsigned int devfn;
  84. prop = of_find_property(dp, "reg", NULL);
  85. if (!prop)
  86. return;
  87. regs = prop->value;
  88. devfn = (regs->phys_hi >> 8) & 0xff;
  89. if (devfn & 0x07) {
  90. sprintf(tmp_buf, "%s@%x,%x",
  91. dp->name,
  92. devfn >> 3,
  93. devfn & 0x07);
  94. } else {
  95. sprintf(tmp_buf, "%s@%x",
  96. dp->name,
  97. devfn >> 3);
  98. }
  99. }
  100. /* "name@addrhi,addrlo" */
  101. static void __init ebus_path_component(struct device_node *dp, char *tmp_buf)
  102. {
  103. struct linux_prom_registers *regs;
  104. struct property *prop;
  105. prop = of_find_property(dp, "reg", NULL);
  106. if (!prop)
  107. return;
  108. regs = prop->value;
  109. sprintf(tmp_buf, "%s@%x,%x",
  110. dp->name,
  111. regs->which_io, regs->phys_addr);
  112. }
  113. static void __init __build_path_component(struct device_node *dp, char *tmp_buf)
  114. {
  115. struct device_node *parent = dp->parent;
  116. if (parent != NULL) {
  117. if (!strcmp(parent->type, "pci") ||
  118. !strcmp(parent->type, "pciex"))
  119. return pci_path_component(dp, tmp_buf);
  120. if (!strcmp(parent->type, "sbus"))
  121. return sbus_path_component(dp, tmp_buf);
  122. if (!strcmp(parent->type, "ebus"))
  123. return ebus_path_component(dp, tmp_buf);
  124. /* "isa" is handled with platform naming */
  125. }
  126. /* Use platform naming convention. */
  127. return sparc32_path_component(dp, tmp_buf);
  128. }
  129. char * __init build_path_component(struct device_node *dp)
  130. {
  131. char tmp_buf[64], *n;
  132. tmp_buf[0] = '\0';
  133. __build_path_component(dp, tmp_buf);
  134. if (tmp_buf[0] == '\0')
  135. strcpy(tmp_buf, dp->name);
  136. n = prom_early_alloc(strlen(tmp_buf) + 1);
  137. strcpy(n, tmp_buf);
  138. return n;
  139. }
  140. extern void restore_current(void);
  141. void __init of_console_init(void)
  142. {
  143. char *msg = "OF stdout device is: %s\n";
  144. struct device_node *dp;
  145. unsigned long flags;
  146. const char *type;
  147. phandle node;
  148. int skip, tmp, fd;
  149. of_console_path = prom_early_alloc(256);
  150. switch (prom_vers) {
  151. case PROM_V0:
  152. skip = 0;
  153. switch (*romvec->pv_stdout) {
  154. case PROMDEV_SCREEN:
  155. type = "display";
  156. break;
  157. case PROMDEV_TTYB:
  158. skip = 1;
  159. /* FALLTHRU */
  160. case PROMDEV_TTYA:
  161. type = "serial";
  162. break;
  163. default:
  164. prom_printf("Invalid PROM_V0 stdout value %u\n",
  165. *romvec->pv_stdout);
  166. prom_halt();
  167. }
  168. tmp = skip;
  169. for_each_node_by_type(dp, type) {
  170. if (!tmp--)
  171. break;
  172. }
  173. if (!dp) {
  174. prom_printf("Cannot find PROM_V0 console node.\n");
  175. prom_halt();
  176. }
  177. of_console_device = dp;
  178. strcpy(of_console_path, dp->full_name);
  179. if (!strcmp(type, "serial")) {
  180. strcat(of_console_path,
  181. (skip ? ":b" : ":a"));
  182. }
  183. break;
  184. default:
  185. case PROM_V2:
  186. case PROM_V3:
  187. fd = *romvec->pv_v2bootargs.fd_stdout;
  188. spin_lock_irqsave(&prom_lock, flags);
  189. node = (*romvec->pv_v2devops.v2_inst2pkg)(fd);
  190. restore_current();
  191. spin_unlock_irqrestore(&prom_lock, flags);
  192. if (!node) {
  193. prom_printf("Cannot resolve stdout node from "
  194. "instance %08x.\n", fd);
  195. prom_halt();
  196. }
  197. dp = of_find_node_by_phandle(node);
  198. type = of_get_property(dp, "device_type", NULL);
  199. if (!type) {
  200. prom_printf("Console stdout lacks "
  201. "device_type property.\n");
  202. prom_halt();
  203. }
  204. if (strcmp(type, "display") && strcmp(type, "serial")) {
  205. prom_printf("Console device_type is neither display "
  206. "nor serial.\n");
  207. prom_halt();
  208. }
  209. of_console_device = dp;
  210. if (prom_vers == PROM_V2) {
  211. strcpy(of_console_path, dp->full_name);
  212. switch (*romvec->pv_stdout) {
  213. case PROMDEV_TTYA:
  214. strcat(of_console_path, ":a");
  215. break;
  216. case PROMDEV_TTYB:
  217. strcat(of_console_path, ":b");
  218. break;
  219. }
  220. } else {
  221. const char *path;
  222. dp = of_find_node_by_path("/");
  223. path = of_get_property(dp, "stdout-path", NULL);
  224. if (!path) {
  225. prom_printf("No stdout-path in root node.\n");
  226. prom_halt();
  227. }
  228. strcpy(of_console_path, path);
  229. }
  230. break;
  231. }
  232. of_console_options = strrchr(of_console_path, ':');
  233. if (of_console_options) {
  234. of_console_options++;
  235. if (*of_console_options == '\0')
  236. of_console_options = NULL;
  237. }
  238. prom_printf(msg, of_console_path);
  239. printk(msg, of_console_path);
  240. }
  241. void __init of_fill_in_cpu_data(void)
  242. {
  243. }
  244. void __init irq_trans_init(struct device_node *dp)
  245. {
  246. }