devices.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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/kernel.h>
  10. #include <linux/threads.h>
  11. #include <linux/string.h>
  12. #include <linux/init.h>
  13. #include <linux/errno.h>
  14. #include <asm/page.h>
  15. #include <asm/oplib.h>
  16. #include <asm/prom.h>
  17. #include <asm/smp.h>
  18. #include <asm/cpudata.h>
  19. #include <asm/cpu_type.h>
  20. extern void clock_stop_probe(void); /* tadpole.c */
  21. static char *cpu_mid_prop(void)
  22. {
  23. if (sparc_cpu_model == sun4d)
  24. return "cpu-id";
  25. return "mid";
  26. }
  27. static int check_cpu_node(phandle nd, int *cur_inst,
  28. int (*compare)(phandle, int, void *), void *compare_arg,
  29. phandle *prom_node, int *mid)
  30. {
  31. if (!compare(nd, *cur_inst, compare_arg)) {
  32. if (prom_node)
  33. *prom_node = nd;
  34. if (mid) {
  35. *mid = prom_getintdefault(nd, cpu_mid_prop(), 0);
  36. if (sparc_cpu_model == sun4m)
  37. *mid &= 3;
  38. }
  39. return 0;
  40. }
  41. (*cur_inst)++;
  42. return -ENODEV;
  43. }
  44. static int __cpu_find_by(int (*compare)(phandle, int, void *),
  45. void *compare_arg, phandle *prom_node, int *mid)
  46. {
  47. struct device_node *dp;
  48. int cur_inst;
  49. cur_inst = 0;
  50. for_each_node_by_type(dp, "cpu") {
  51. int err = check_cpu_node(dp->phandle, &cur_inst,
  52. compare, compare_arg,
  53. prom_node, mid);
  54. if (!err) {
  55. of_node_put(dp);
  56. return 0;
  57. }
  58. }
  59. return -ENODEV;
  60. }
  61. static int cpu_instance_compare(phandle nd, int instance, void *_arg)
  62. {
  63. int desired_instance = (int) _arg;
  64. if (instance == desired_instance)
  65. return 0;
  66. return -ENODEV;
  67. }
  68. int cpu_find_by_instance(int instance, phandle *prom_node, int *mid)
  69. {
  70. return __cpu_find_by(cpu_instance_compare, (void *)instance,
  71. prom_node, mid);
  72. }
  73. static int cpu_mid_compare(phandle nd, int instance, void *_arg)
  74. {
  75. int desired_mid = (int) _arg;
  76. int this_mid;
  77. this_mid = prom_getintdefault(nd, cpu_mid_prop(), 0);
  78. if (this_mid == desired_mid
  79. || (sparc_cpu_model == sun4m && (this_mid & 3) == desired_mid))
  80. return 0;
  81. return -ENODEV;
  82. }
  83. int cpu_find_by_mid(int mid, phandle *prom_node)
  84. {
  85. return __cpu_find_by(cpu_mid_compare, (void *)mid,
  86. prom_node, NULL);
  87. }
  88. /* sun4m uses truncated mids since we base the cpuid on the ttable/irqset
  89. * address (0-3). This gives us the true hardware mid, which might have
  90. * some other bits set. On 4d hardware and software mids are the same.
  91. */
  92. int cpu_get_hwmid(phandle prom_node)
  93. {
  94. return prom_getintdefault(prom_node, cpu_mid_prop(), -ENODEV);
  95. }
  96. void __init device_scan(void)
  97. {
  98. printk(KERN_NOTICE "Booting Linux...\n");
  99. #ifndef CONFIG_SMP
  100. {
  101. phandle cpu_node;
  102. int err;
  103. err = cpu_find_by_instance(0, &cpu_node, NULL);
  104. if (err) {
  105. /* Probably a sun4e, Sun is trying to trick us ;-) */
  106. prom_printf("No cpu nodes, cannot continue\n");
  107. prom_halt();
  108. }
  109. cpu_data(0).clock_tick = prom_getintdefault(cpu_node,
  110. "clock-frequency",
  111. 0);
  112. }
  113. #endif /* !CONFIG_SMP */
  114. {
  115. extern void auxio_probe(void);
  116. extern void auxio_power_probe(void);
  117. auxio_probe();
  118. auxio_power_probe();
  119. }
  120. clock_stop_probe();
  121. }