devices.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /* devices.c: Initial scan of the prom device tree for important
  2. * Sparc device nodes which we need to find.
  3. *
  4. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  5. */
  6. #include <linux/config.h>
  7. #include <linux/kernel.h>
  8. #include <linux/threads.h>
  9. #include <linux/init.h>
  10. #include <linux/ioport.h>
  11. #include <linux/string.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/errno.h>
  14. #include <linux/bootmem.h>
  15. #include <asm/page.h>
  16. #include <asm/oplib.h>
  17. #include <asm/system.h>
  18. #include <asm/smp.h>
  19. #include <asm/spitfire.h>
  20. #include <asm/timer.h>
  21. #include <asm/cpudata.h>
  22. #include <asm/vdev.h>
  23. #include <asm/irq.h>
  24. /* Used to synchronize acceses to NatSemi SUPER I/O chip configure
  25. * operations in asm/ns87303.h
  26. */
  27. DEFINE_SPINLOCK(ns87303_lock);
  28. extern void cpu_probe(void);
  29. extern void central_probe(void);
  30. u32 sun4v_vdev_devhandle;
  31. struct device_node *sun4v_vdev_root;
  32. struct vdev_intmap {
  33. unsigned int phys;
  34. unsigned int irq;
  35. unsigned int cnode;
  36. unsigned int cinterrupt;
  37. };
  38. struct vdev_intmask {
  39. unsigned int phys;
  40. unsigned int interrupt;
  41. unsigned int __unused;
  42. };
  43. static struct vdev_intmap *vdev_intmap;
  44. static int vdev_num_intmap;
  45. static struct vdev_intmask *vdev_intmask;
  46. static void __init sun4v_virtual_device_probe(void)
  47. {
  48. struct linux_prom64_registers *regs;
  49. struct property *prop;
  50. struct device_node *dp;
  51. int sz;
  52. if (tlb_type != hypervisor)
  53. return;
  54. dp = of_find_node_by_name(NULL, "virtual-devices");
  55. if (!dp) {
  56. prom_printf("SUN4V: Fatal error, no virtual-devices node.\n");
  57. prom_halt();
  58. }
  59. sun4v_vdev_root = dp;
  60. prop = of_find_property(dp, "reg", NULL);
  61. regs = prop->value;
  62. sun4v_vdev_devhandle = (regs[0].phys_addr >> 32UL) & 0x0fffffff;
  63. prop = of_find_property(dp, "interrupt-map", &sz);
  64. vdev_intmap = prop->value;
  65. vdev_num_intmap = sz / sizeof(struct vdev_intmap);
  66. prop = of_find_property(dp, "interrupt-map-mask", NULL);
  67. vdev_intmask = prop->value;
  68. printk("%s: Virtual Device Bus devhandle[%x]\n",
  69. dp->full_name, sun4v_vdev_devhandle);
  70. }
  71. unsigned int sun4v_vdev_device_interrupt(struct device_node *dev_node)
  72. {
  73. struct property *prop;
  74. unsigned int irq, reg;
  75. int i;
  76. prop = of_find_property(dev_node, "interrupts", NULL);
  77. if (!prop) {
  78. printk("VDEV: Cannot get \"interrupts\" "
  79. "property for OBP node %s\n",
  80. dev_node->full_name);
  81. return 0;
  82. }
  83. irq = *(unsigned int *) prop->value;
  84. prop = of_find_property(dev_node, "reg", NULL);
  85. if (!prop) {
  86. printk("VDEV: Cannot get \"reg\" "
  87. "property for OBP node %s\n",
  88. dev_node->full_name);
  89. return 0;
  90. }
  91. reg = *(unsigned int *) prop->value;
  92. for (i = 0; i < vdev_num_intmap; i++) {
  93. if (vdev_intmap[i].phys == (reg & vdev_intmask->phys) &&
  94. vdev_intmap[i].irq == (irq & vdev_intmask->interrupt)) {
  95. irq = vdev_intmap[i].cinterrupt;
  96. break;
  97. }
  98. }
  99. if (i == vdev_num_intmap) {
  100. printk("VDEV: No matching interrupt map entry "
  101. "for OBP node %s\n", dev_node->full_name);
  102. return 0;
  103. }
  104. return sun4v_build_irq(sun4v_vdev_devhandle, irq);
  105. }
  106. static const char *cpu_mid_prop(void)
  107. {
  108. if (tlb_type == spitfire)
  109. return "upa-portid";
  110. return "portid";
  111. }
  112. static int get_cpu_mid(struct device_node *dp)
  113. {
  114. struct property *prop;
  115. if (tlb_type == hypervisor) {
  116. struct linux_prom64_registers *reg;
  117. int len;
  118. prop = of_find_property(dp, "cpuid", &len);
  119. if (prop && len == 4)
  120. return *(int *) prop->value;
  121. prop = of_find_property(dp, "reg", NULL);
  122. reg = prop->value;
  123. return (reg[0].phys_addr >> 32) & 0x0fffffffUL;
  124. } else {
  125. const char *prop_name = cpu_mid_prop();
  126. prop = of_find_property(dp, prop_name, NULL);
  127. if (prop)
  128. return *(int *) prop->value;
  129. return 0;
  130. }
  131. }
  132. static int check_cpu_node(struct device_node *dp, int *cur_inst,
  133. int (*compare)(struct device_node *, int, void *),
  134. void *compare_arg,
  135. struct device_node **dev_node, int *mid)
  136. {
  137. if (strcmp(dp->type, "cpu"))
  138. return -ENODEV;
  139. if (!compare(dp, *cur_inst, compare_arg)) {
  140. if (dev_node)
  141. *dev_node = dp;
  142. if (mid)
  143. *mid = get_cpu_mid(dp);
  144. return 0;
  145. }
  146. (*cur_inst)++;
  147. return -ENODEV;
  148. }
  149. static int __cpu_find_by(int (*compare)(struct device_node *, int, void *),
  150. void *compare_arg,
  151. struct device_node **dev_node, int *mid)
  152. {
  153. struct device_node *dp;
  154. int cur_inst;
  155. cur_inst = 0;
  156. for_each_node_by_type(dp, "cpu") {
  157. int err = check_cpu_node(dp, &cur_inst,
  158. compare, compare_arg,
  159. dev_node, mid);
  160. if (err == 0)
  161. return 0;
  162. }
  163. return -ENODEV;
  164. }
  165. static int cpu_instance_compare(struct device_node *dp, int instance, void *_arg)
  166. {
  167. int desired_instance = (int) (long) _arg;
  168. if (instance == desired_instance)
  169. return 0;
  170. return -ENODEV;
  171. }
  172. int cpu_find_by_instance(int instance, struct device_node **dev_node, int *mid)
  173. {
  174. return __cpu_find_by(cpu_instance_compare, (void *)(long)instance,
  175. dev_node, mid);
  176. }
  177. static int cpu_mid_compare(struct device_node *dp, int instance, void *_arg)
  178. {
  179. int desired_mid = (int) (long) _arg;
  180. int this_mid;
  181. this_mid = get_cpu_mid(dp);
  182. if (this_mid == desired_mid)
  183. return 0;
  184. return -ENODEV;
  185. }
  186. int cpu_find_by_mid(int mid, struct device_node **dev_node)
  187. {
  188. return __cpu_find_by(cpu_mid_compare, (void *)(long)mid,
  189. dev_node, NULL);
  190. }
  191. void __init device_scan(void)
  192. {
  193. /* FIX ME FAST... -DaveM */
  194. ioport_resource.end = 0xffffffffffffffffUL;
  195. prom_printf("Booting Linux...\n");
  196. #ifndef CONFIG_SMP
  197. {
  198. struct device_node *dp;
  199. int err, def;
  200. err = cpu_find_by_instance(0, &dp, NULL);
  201. if (err) {
  202. prom_printf("No cpu nodes, cannot continue\n");
  203. prom_halt();
  204. }
  205. cpu_data(0).clock_tick =
  206. of_getintprop_default(dp, "clock-frequency", 0);
  207. def = ((tlb_type == hypervisor) ?
  208. (8 * 1024) :
  209. (16 * 1024));
  210. cpu_data(0).dcache_size = of_getintprop_default(dp,
  211. "dcache-size",
  212. def);
  213. def = 32;
  214. cpu_data(0).dcache_line_size =
  215. of_getintprop_default(dp, "dcache-line-size", def);
  216. def = 16 * 1024;
  217. cpu_data(0).icache_size = of_getintprop_default(dp,
  218. "icache-size",
  219. def);
  220. def = 32;
  221. cpu_data(0).icache_line_size =
  222. of_getintprop_default(dp, "icache-line-size", def);
  223. def = ((tlb_type == hypervisor) ?
  224. (3 * 1024 * 1024) :
  225. (4 * 1024 * 1024));
  226. cpu_data(0).ecache_size = of_getintprop_default(dp,
  227. "ecache-size",
  228. def);
  229. def = 64;
  230. cpu_data(0).ecache_line_size =
  231. of_getintprop_default(dp, "ecache-line-size", def);
  232. printk("CPU[0]: Caches "
  233. "D[sz(%d):line_sz(%d)] "
  234. "I[sz(%d):line_sz(%d)] "
  235. "E[sz(%d):line_sz(%d)]\n",
  236. cpu_data(0).dcache_size, cpu_data(0).dcache_line_size,
  237. cpu_data(0).icache_size, cpu_data(0).icache_line_size,
  238. cpu_data(0).ecache_size, cpu_data(0).ecache_line_size);
  239. }
  240. #endif
  241. sun4v_virtual_device_probe();
  242. central_probe();
  243. cpu_probe();
  244. }