prom_32.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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; unsigned int *intr;
  119. unsigned int *device, *vendor;
  120. struct property *prop;
  121. prop = of_find_property(dp, "reg", NULL);
  122. if (!prop)
  123. return;
  124. regs = prop->value;
  125. prop = of_find_property(dp, "interrupts", NULL);
  126. if (!prop)
  127. return;
  128. intr = prop->value;
  129. prop = of_find_property(dp, "vendor", NULL);
  130. if (!prop)
  131. return;
  132. vendor = prop->value;
  133. prop = of_find_property(dp, "device", NULL);
  134. if (!prop)
  135. return;
  136. device = prop->value;
  137. sprintf(tmp_buf, "%s:%d:%d@%x,%x",
  138. dp->name, *vendor, *device,
  139. *intr, regs->phys_addr);
  140. }
  141. static void __init __build_path_component(struct device_node *dp, char *tmp_buf)
  142. {
  143. struct device_node *parent = dp->parent;
  144. if (parent != NULL) {
  145. if (!strcmp(parent->type, "pci") ||
  146. !strcmp(parent->type, "pciex"))
  147. return pci_path_component(dp, tmp_buf);
  148. if (!strcmp(parent->type, "sbus"))
  149. return sbus_path_component(dp, tmp_buf);
  150. if (!strcmp(parent->type, "ebus"))
  151. return ebus_path_component(dp, tmp_buf);
  152. if (!strcmp(parent->type, "ambapp"))
  153. return ambapp_path_component(dp, tmp_buf);
  154. /* "isa" is handled with platform naming */
  155. }
  156. /* Use platform naming convention. */
  157. return sparc32_path_component(dp, tmp_buf);
  158. }
  159. char * __init build_path_component(struct device_node *dp)
  160. {
  161. char tmp_buf[64], *n;
  162. tmp_buf[0] = '\0';
  163. __build_path_component(dp, tmp_buf);
  164. if (tmp_buf[0] == '\0')
  165. strcpy(tmp_buf, dp->name);
  166. n = prom_early_alloc(strlen(tmp_buf) + 1);
  167. strcpy(n, tmp_buf);
  168. return n;
  169. }
  170. extern void restore_current(void);
  171. void __init of_console_init(void)
  172. {
  173. char *msg = "OF stdout device is: %s\n";
  174. struct device_node *dp;
  175. unsigned long flags;
  176. const char *type;
  177. phandle node;
  178. int skip, tmp, fd;
  179. of_console_path = prom_early_alloc(256);
  180. switch (prom_vers) {
  181. case PROM_V0:
  182. skip = 0;
  183. switch (*romvec->pv_stdout) {
  184. case PROMDEV_SCREEN:
  185. type = "display";
  186. break;
  187. case PROMDEV_TTYB:
  188. skip = 1;
  189. /* FALLTHRU */
  190. case PROMDEV_TTYA:
  191. type = "serial";
  192. break;
  193. default:
  194. prom_printf("Invalid PROM_V0 stdout value %u\n",
  195. *romvec->pv_stdout);
  196. prom_halt();
  197. }
  198. tmp = skip;
  199. for_each_node_by_type(dp, type) {
  200. if (!tmp--)
  201. break;
  202. }
  203. if (!dp) {
  204. prom_printf("Cannot find PROM_V0 console node.\n");
  205. prom_halt();
  206. }
  207. of_console_device = dp;
  208. strcpy(of_console_path, dp->full_name);
  209. if (!strcmp(type, "serial")) {
  210. strcat(of_console_path,
  211. (skip ? ":b" : ":a"));
  212. }
  213. break;
  214. default:
  215. case PROM_V2:
  216. case PROM_V3:
  217. fd = *romvec->pv_v2bootargs.fd_stdout;
  218. spin_lock_irqsave(&prom_lock, flags);
  219. node = (*romvec->pv_v2devops.v2_inst2pkg)(fd);
  220. restore_current();
  221. spin_unlock_irqrestore(&prom_lock, flags);
  222. if (!node) {
  223. prom_printf("Cannot resolve stdout node from "
  224. "instance %08x.\n", fd);
  225. prom_halt();
  226. }
  227. dp = of_find_node_by_phandle(node);
  228. type = of_get_property(dp, "device_type", NULL);
  229. if (!type) {
  230. prom_printf("Console stdout lacks "
  231. "device_type property.\n");
  232. prom_halt();
  233. }
  234. if (strcmp(type, "display") && strcmp(type, "serial")) {
  235. prom_printf("Console device_type is neither display "
  236. "nor serial.\n");
  237. prom_halt();
  238. }
  239. of_console_device = dp;
  240. if (prom_vers == PROM_V2) {
  241. strcpy(of_console_path, dp->full_name);
  242. switch (*romvec->pv_stdout) {
  243. case PROMDEV_TTYA:
  244. strcat(of_console_path, ":a");
  245. break;
  246. case PROMDEV_TTYB:
  247. strcat(of_console_path, ":b");
  248. break;
  249. }
  250. } else {
  251. const char *path;
  252. dp = of_find_node_by_path("/");
  253. path = of_get_property(dp, "stdout-path", NULL);
  254. if (!path) {
  255. prom_printf("No stdout-path in root node.\n");
  256. prom_halt();
  257. }
  258. strcpy(of_console_path, path);
  259. }
  260. break;
  261. }
  262. of_console_options = strrchr(of_console_path, ':');
  263. if (of_console_options) {
  264. of_console_options++;
  265. if (*of_console_options == '\0')
  266. of_console_options = NULL;
  267. }
  268. prom_printf(msg, of_console_path);
  269. printk(msg, of_console_path);
  270. }
  271. void __init of_fill_in_cpu_data(void)
  272. {
  273. }
  274. void __init irq_trans_init(struct device_node *dp)
  275. {
  276. }