devices.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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(int prom_node)
  113. {
  114. if (tlb_type == hypervisor) {
  115. struct linux_prom64_registers reg;
  116. if (prom_getproplen(prom_node, "cpuid") == 4)
  117. return prom_getintdefault(prom_node, "cpuid", 0);
  118. prom_getproperty(prom_node, "reg", (char *) &reg, sizeof(reg));
  119. return (reg.phys_addr >> 32) & 0x0fffffffUL;
  120. } else {
  121. const char *prop_name = cpu_mid_prop();
  122. return prom_getintdefault(prom_node, prop_name, 0);
  123. }
  124. }
  125. static int check_cpu_node(int nd, int *cur_inst,
  126. int (*compare)(int, int, void *), void *compare_arg,
  127. int *prom_node, int *mid)
  128. {
  129. char node_str[128];
  130. prom_getstring(nd, "device_type", node_str, sizeof(node_str));
  131. if (strcmp(node_str, "cpu"))
  132. return -ENODEV;
  133. if (!compare(nd, *cur_inst, compare_arg)) {
  134. if (prom_node)
  135. *prom_node = nd;
  136. if (mid)
  137. *mid = get_cpu_mid(nd);
  138. return 0;
  139. }
  140. (*cur_inst)++;
  141. return -ENODEV;
  142. }
  143. static int __cpu_find_by(int (*compare)(int, int, void *), void *compare_arg,
  144. int *prom_node, int *mid)
  145. {
  146. int nd, cur_inst, err;
  147. nd = prom_root_node;
  148. cur_inst = 0;
  149. err = check_cpu_node(nd, &cur_inst,
  150. compare, compare_arg,
  151. prom_node, mid);
  152. if (err == 0)
  153. return 0;
  154. nd = prom_getchild(nd);
  155. while ((nd = prom_getsibling(nd)) != 0) {
  156. err = check_cpu_node(nd, &cur_inst,
  157. compare, compare_arg,
  158. prom_node, mid);
  159. if (err == 0)
  160. return 0;
  161. }
  162. return -ENODEV;
  163. }
  164. static int cpu_instance_compare(int nd, int instance, void *_arg)
  165. {
  166. int desired_instance = (int) (long) _arg;
  167. if (instance == desired_instance)
  168. return 0;
  169. return -ENODEV;
  170. }
  171. int cpu_find_by_instance(int instance, int *prom_node, int *mid)
  172. {
  173. return __cpu_find_by(cpu_instance_compare, (void *)(long)instance,
  174. prom_node, mid);
  175. }
  176. static int cpu_mid_compare(int nd, int instance, void *_arg)
  177. {
  178. int desired_mid = (int) (long) _arg;
  179. int this_mid;
  180. this_mid = get_cpu_mid(nd);
  181. if (this_mid == desired_mid)
  182. return 0;
  183. return -ENODEV;
  184. }
  185. int cpu_find_by_mid(int mid, int *prom_node)
  186. {
  187. return __cpu_find_by(cpu_mid_compare, (void *)(long)mid,
  188. prom_node, NULL);
  189. }
  190. void __init device_scan(void)
  191. {
  192. /* FIX ME FAST... -DaveM */
  193. ioport_resource.end = 0xffffffffffffffffUL;
  194. prom_printf("Booting Linux...\n");
  195. #ifndef CONFIG_SMP
  196. {
  197. int err, cpu_node, def;
  198. err = cpu_find_by_instance(0, &cpu_node, NULL);
  199. if (err) {
  200. prom_printf("No cpu nodes, cannot continue\n");
  201. prom_halt();
  202. }
  203. cpu_data(0).clock_tick = prom_getintdefault(cpu_node,
  204. "clock-frequency",
  205. 0);
  206. def = ((tlb_type == hypervisor) ?
  207. (8 * 1024) :
  208. (16 * 1024));
  209. cpu_data(0).dcache_size = prom_getintdefault(cpu_node,
  210. "dcache-size",
  211. def);
  212. def = 32;
  213. cpu_data(0).dcache_line_size =
  214. prom_getintdefault(cpu_node, "dcache-line-size",
  215. def);
  216. def = 16 * 1024;
  217. cpu_data(0).icache_size = prom_getintdefault(cpu_node,
  218. "icache-size",
  219. def);
  220. def = 32;
  221. cpu_data(0).icache_line_size =
  222. prom_getintdefault(cpu_node, "icache-line-size",
  223. def);
  224. def = ((tlb_type == hypervisor) ?
  225. (3 * 1024 * 1024) :
  226. (4 * 1024 * 1024));
  227. cpu_data(0).ecache_size = prom_getintdefault(cpu_node,
  228. "ecache-size",
  229. def);
  230. def = 64;
  231. cpu_data(0).ecache_line_size =
  232. prom_getintdefault(cpu_node, "ecache-line-size",
  233. def);
  234. printk("CPU[0]: Caches "
  235. "D[sz(%d):line_sz(%d)] "
  236. "I[sz(%d):line_sz(%d)] "
  237. "E[sz(%d):line_sz(%d)]\n",
  238. cpu_data(0).dcache_size, cpu_data(0).dcache_line_size,
  239. cpu_data(0).icache_size, cpu_data(0).icache_line_size,
  240. cpu_data(0).ecache_size, cpu_data(0).ecache_line_size);
  241. }
  242. #endif
  243. sun4v_virtual_device_probe();
  244. central_probe();
  245. cpu_probe();
  246. }