devices.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* devices.c: Initial scan of the prom device tree for important
  2. * Sparc device nodes which we need to find.
  3. *
  4. * This is based on the sparc64 version, but sun4m doesn't always use
  5. * the hardware MIDs, so be careful.
  6. *
  7. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  8. */
  9. #include <linux/config.h>
  10. #include <linux/kernel.h>
  11. #include <linux/threads.h>
  12. #include <linux/string.h>
  13. #include <linux/init.h>
  14. #include <linux/errno.h>
  15. #include <asm/page.h>
  16. #include <asm/oplib.h>
  17. #include <asm/smp.h>
  18. #include <asm/system.h>
  19. #include <asm/cpudata.h>
  20. extern void cpu_probe(void);
  21. extern void clock_stop_probe(void); /* tadpole.c */
  22. extern void sun4c_probe_memerr_reg(void);
  23. static char *cpu_mid_prop(void)
  24. {
  25. if (sparc_cpu_model == sun4d)
  26. return "cpu-id";
  27. return "mid";
  28. }
  29. static int check_cpu_node(int nd, int *cur_inst,
  30. int (*compare)(int, int, void *), void *compare_arg,
  31. int *prom_node, int *mid)
  32. {
  33. char node_str[128];
  34. prom_getstring(nd, "device_type", node_str, sizeof(node_str));
  35. if (strcmp(node_str, "cpu"))
  36. return -ENODEV;
  37. if (!compare(nd, *cur_inst, compare_arg)) {
  38. if (prom_node)
  39. *prom_node = nd;
  40. if (mid) {
  41. *mid = prom_getintdefault(nd, cpu_mid_prop(), 0);
  42. if (sparc_cpu_model == sun4m)
  43. *mid &= 3;
  44. }
  45. return 0;
  46. }
  47. (*cur_inst)++;
  48. return -ENODEV;
  49. }
  50. static int __cpu_find_by(int (*compare)(int, int, void *), void *compare_arg,
  51. int *prom_node, int *mid)
  52. {
  53. int nd, cur_inst, err;
  54. nd = prom_root_node;
  55. cur_inst = 0;
  56. err = check_cpu_node(nd, &cur_inst, compare, compare_arg,
  57. prom_node, mid);
  58. if (!err)
  59. return 0;
  60. nd = prom_getchild(nd);
  61. while ((nd = prom_getsibling(nd)) != 0) {
  62. err = check_cpu_node(nd, &cur_inst, compare, compare_arg,
  63. prom_node, mid);
  64. if (!err)
  65. return 0;
  66. }
  67. return -ENODEV;
  68. }
  69. static int cpu_instance_compare(int nd, int instance, void *_arg)
  70. {
  71. int desired_instance = (int) _arg;
  72. if (instance == desired_instance)
  73. return 0;
  74. return -ENODEV;
  75. }
  76. int cpu_find_by_instance(int instance, int *prom_node, int *mid)
  77. {
  78. return __cpu_find_by(cpu_instance_compare, (void *)instance,
  79. prom_node, mid);
  80. }
  81. static int cpu_mid_compare(int nd, int instance, void *_arg)
  82. {
  83. int desired_mid = (int) _arg;
  84. int this_mid;
  85. this_mid = prom_getintdefault(nd, cpu_mid_prop(), 0);
  86. if (this_mid == desired_mid
  87. || (sparc_cpu_model == sun4m && (this_mid & 3) == desired_mid))
  88. return 0;
  89. return -ENODEV;
  90. }
  91. int cpu_find_by_mid(int mid, int *prom_node)
  92. {
  93. return __cpu_find_by(cpu_mid_compare, (void *)mid,
  94. prom_node, NULL);
  95. }
  96. /* sun4m uses truncated mids since we base the cpuid on the ttable/irqset
  97. * address (0-3). This gives us the true hardware mid, which might have
  98. * some other bits set. On 4d hardware and software mids are the same.
  99. */
  100. int cpu_get_hwmid(int prom_node)
  101. {
  102. return prom_getintdefault(prom_node, cpu_mid_prop(), -ENODEV);
  103. }
  104. void __init device_scan(void)
  105. {
  106. prom_printf("Booting Linux...\n");
  107. #ifndef CONFIG_SMP
  108. {
  109. int err, cpu_node;
  110. err = cpu_find_by_instance(0, &cpu_node, NULL);
  111. if (err) {
  112. /* Probably a sun4e, Sun is trying to trick us ;-) */
  113. prom_printf("No cpu nodes, cannot continue\n");
  114. prom_halt();
  115. }
  116. cpu_data(0).clock_tick = prom_getintdefault(cpu_node,
  117. "clock-frequency",
  118. 0);
  119. }
  120. #endif /* !CONFIG_SMP */
  121. cpu_probe();
  122. #ifdef CONFIG_SUN_AUXIO
  123. {
  124. extern void auxio_probe(void);
  125. extern void auxio_power_probe(void);
  126. auxio_probe();
  127. auxio_power_probe();
  128. }
  129. #endif
  130. clock_stop_probe();
  131. if (ARCH_SUN4C_SUN4)
  132. sun4c_probe_memerr_reg();
  133. return;
  134. }