prom_32.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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 <asm/leon.h>
  26. #include <asm/leon_amba.h>
  27. #include "prom.h"
  28. void * __init prom_early_alloc(unsigned long size)
  29. {
  30. void *ret;
  31. ret = __alloc_bootmem(size, SMP_CACHE_BYTES, 0UL);
  32. if (ret != NULL)
  33. memset(ret, 0, size);
  34. prom_early_allocated += size;
  35. return ret;
  36. }
  37. /* The following routines deal with the black magic of fully naming a
  38. * node.
  39. *
  40. * Certain well known named nodes are just the simple name string.
  41. *
  42. * Actual devices have an address specifier appended to the base name
  43. * string, like this "foo@addr". The "addr" can be in any number of
  44. * formats, and the platform plus the type of the node determine the
  45. * format and how it is constructed.
  46. *
  47. * For children of the ROOT node, the naming convention is fixed and
  48. * determined by whether this is a sun4u or sun4v system.
  49. *
  50. * For children of other nodes, it is bus type specific. So
  51. * we walk up the tree until we discover a "device_type" property
  52. * we recognize and we go from there.
  53. */
  54. static void __init sparc32_path_component(struct device_node *dp, char *tmp_buf)
  55. {
  56. struct linux_prom_registers *regs;
  57. struct property *rprop;
  58. rprop = of_find_property(dp, "reg", NULL);
  59. if (!rprop)
  60. return;
  61. regs = rprop->value;
  62. sprintf(tmp_buf, "%s@%x,%x",
  63. dp->name,
  64. regs->which_io, regs->phys_addr);
  65. }
  66. /* "name@slot,offset" */
  67. static void __init sbus_path_component(struct device_node *dp, char *tmp_buf)
  68. {
  69. struct linux_prom_registers *regs;
  70. struct property *prop;
  71. prop = of_find_property(dp, "reg", NULL);
  72. if (!prop)
  73. return;
  74. regs = prop->value;
  75. sprintf(tmp_buf, "%s@%x,%x",
  76. dp->name,
  77. regs->which_io,
  78. regs->phys_addr);
  79. }
  80. /* "name@devnum[,func]" */
  81. static void __init pci_path_component(struct device_node *dp, char *tmp_buf)
  82. {
  83. struct linux_prom_pci_registers *regs;
  84. struct property *prop;
  85. unsigned int devfn;
  86. prop = of_find_property(dp, "reg", NULL);
  87. if (!prop)
  88. return;
  89. regs = prop->value;
  90. devfn = (regs->phys_hi >> 8) & 0xff;
  91. if (devfn & 0x07) {
  92. sprintf(tmp_buf, "%s@%x,%x",
  93. dp->name,
  94. devfn >> 3,
  95. devfn & 0x07);
  96. } else {
  97. sprintf(tmp_buf, "%s@%x",
  98. dp->name,
  99. devfn >> 3);
  100. }
  101. }
  102. /* "name@addrhi,addrlo" */
  103. static void __init ebus_path_component(struct device_node *dp, char *tmp_buf)
  104. {
  105. struct linux_prom_registers *regs;
  106. struct property *prop;
  107. prop = of_find_property(dp, "reg", NULL);
  108. if (!prop)
  109. return;
  110. regs = prop->value;
  111. sprintf(tmp_buf, "%s@%x,%x",
  112. dp->name,
  113. regs->which_io, regs->phys_addr);
  114. }
  115. /* "name:vendor:device@irq,addrlo" */
  116. static void __init ambapp_path_component(struct device_node *dp, char *tmp_buf)
  117. {
  118. struct amba_prom_registers *regs;
  119. unsigned int *intr, *device, *vendor, reg0;
  120. struct property *prop;
  121. int interrupt = 0;
  122. /* In order to get a unique ID in the device tree (multiple AMBA devices
  123. * may have the same name) the node number is printed
  124. */
  125. prop = of_find_property(dp, "reg", NULL);
  126. if (!prop) {
  127. reg0 = (unsigned int)dp->phandle;
  128. } else {
  129. regs = prop->value;
  130. reg0 = regs->phys_addr;
  131. }
  132. /* Not all cores have Interrupt */
  133. prop = of_find_property(dp, "interrupts", NULL);
  134. if (!prop)
  135. intr = &interrupt; /* IRQ0 does not exist */
  136. else
  137. intr = prop->value;
  138. prop = of_find_property(dp, "vendor", NULL);
  139. if (!prop)
  140. return;
  141. vendor = prop->value;
  142. prop = of_find_property(dp, "device", NULL);
  143. if (!prop)
  144. return;
  145. device = prop->value;
  146. sprintf(tmp_buf, "%s:%d:%d@%x,%x",
  147. dp->name, *vendor, *device,
  148. *intr, reg0);
  149. }
  150. static void __init __build_path_component(struct device_node *dp, char *tmp_buf)
  151. {
  152. struct device_node *parent = dp->parent;
  153. if (parent != NULL) {
  154. if (!strcmp(parent->type, "pci") ||
  155. !strcmp(parent->type, "pciex"))
  156. return pci_path_component(dp, tmp_buf);
  157. if (!strcmp(parent->type, "sbus"))
  158. return sbus_path_component(dp, tmp_buf);
  159. if (!strcmp(parent->type, "ebus"))
  160. return ebus_path_component(dp, tmp_buf);
  161. if (!strcmp(parent->type, "ambapp"))
  162. return ambapp_path_component(dp, tmp_buf);
  163. /* "isa" is handled with platform naming */
  164. }
  165. /* Use platform naming convention. */
  166. return sparc32_path_component(dp, tmp_buf);
  167. }
  168. char * __init build_path_component(struct device_node *dp)
  169. {
  170. char tmp_buf[64], *n;
  171. tmp_buf[0] = '\0';
  172. __build_path_component(dp, tmp_buf);
  173. if (tmp_buf[0] == '\0')
  174. strcpy(tmp_buf, dp->name);
  175. n = prom_early_alloc(strlen(tmp_buf) + 1);
  176. strcpy(n, tmp_buf);
  177. return n;
  178. }
  179. extern void restore_current(void);
  180. void __init of_console_init(void)
  181. {
  182. char *msg = "OF stdout device is: %s\n";
  183. struct device_node *dp;
  184. unsigned long flags;
  185. const char *type;
  186. phandle node;
  187. int skip, tmp, fd;
  188. of_console_path = prom_early_alloc(256);
  189. switch (prom_vers) {
  190. case PROM_V0:
  191. skip = 0;
  192. switch (*romvec->pv_stdout) {
  193. case PROMDEV_SCREEN:
  194. type = "display";
  195. break;
  196. case PROMDEV_TTYB:
  197. skip = 1;
  198. /* FALLTHRU */
  199. case PROMDEV_TTYA:
  200. type = "serial";
  201. break;
  202. default:
  203. prom_printf("Invalid PROM_V0 stdout value %u\n",
  204. *romvec->pv_stdout);
  205. prom_halt();
  206. }
  207. tmp = skip;
  208. for_each_node_by_type(dp, type) {
  209. if (!tmp--)
  210. break;
  211. }
  212. if (!dp) {
  213. prom_printf("Cannot find PROM_V0 console node.\n");
  214. prom_halt();
  215. }
  216. of_console_device = dp;
  217. strcpy(of_console_path, dp->full_name);
  218. if (!strcmp(type, "serial")) {
  219. strcat(of_console_path,
  220. (skip ? ":b" : ":a"));
  221. }
  222. break;
  223. default:
  224. case PROM_V2:
  225. case PROM_V3:
  226. fd = *romvec->pv_v2bootargs.fd_stdout;
  227. spin_lock_irqsave(&prom_lock, flags);
  228. node = (*romvec->pv_v2devops.v2_inst2pkg)(fd);
  229. restore_current();
  230. spin_unlock_irqrestore(&prom_lock, flags);
  231. if (!node) {
  232. prom_printf("Cannot resolve stdout node from "
  233. "instance %08x.\n", fd);
  234. prom_halt();
  235. }
  236. dp = of_find_node_by_phandle(node);
  237. type = of_get_property(dp, "device_type", NULL);
  238. if (!type) {
  239. prom_printf("Console stdout lacks "
  240. "device_type property.\n");
  241. prom_halt();
  242. }
  243. if (strcmp(type, "display") && strcmp(type, "serial")) {
  244. prom_printf("Console device_type is neither display "
  245. "nor serial.\n");
  246. prom_halt();
  247. }
  248. of_console_device = dp;
  249. if (prom_vers == PROM_V2) {
  250. strcpy(of_console_path, dp->full_name);
  251. switch (*romvec->pv_stdout) {
  252. case PROMDEV_TTYA:
  253. strcat(of_console_path, ":a");
  254. break;
  255. case PROMDEV_TTYB:
  256. strcat(of_console_path, ":b");
  257. break;
  258. }
  259. } else {
  260. const char *path;
  261. dp = of_find_node_by_path("/");
  262. path = of_get_property(dp, "stdout-path", NULL);
  263. if (!path) {
  264. prom_printf("No stdout-path in root node.\n");
  265. prom_halt();
  266. }
  267. strcpy(of_console_path, path);
  268. }
  269. break;
  270. }
  271. of_console_options = strrchr(of_console_path, ':');
  272. if (of_console_options) {
  273. of_console_options++;
  274. if (*of_console_options == '\0')
  275. of_console_options = NULL;
  276. }
  277. printk(msg, of_console_path);
  278. }
  279. void __init of_fill_in_cpu_data(void)
  280. {
  281. }
  282. void __init irq_trans_init(struct device_node *dp)
  283. {
  284. }