devices.c 3.0 KB

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