devices.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* devices.c: Initial scan of the prom device tree for important
  3. * Sparc device nodes which we need to find.
  4. *
  5. * This is based on the sparc64 version, but sun4m doesn't always use
  6. * the hardware MIDs, so be careful.
  7. *
  8. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  9. */
  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/prom.h>
  18. #include <asm/smp.h>
  19. #include <asm/cpudata.h>
  20. #include <asm/cpu_type.h>
  21. #include <asm/setup.h>
  22. #include "kernel.h"
  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(phandle nd, int *cur_inst,
  30. int (*compare)(phandle, int, void *), void *compare_arg,
  31. phandle *prom_node, int *mid)
  32. {
  33. if (!compare(nd, *cur_inst, compare_arg)) {
  34. if (prom_node)
  35. *prom_node = nd;
  36. if (mid) {
  37. *mid = prom_getintdefault(nd, cpu_mid_prop(), 0);
  38. if (sparc_cpu_model == sun4m)
  39. *mid &= 3;
  40. }
  41. return 0;
  42. }
  43. (*cur_inst)++;
  44. return -ENODEV;
  45. }
  46. static int __cpu_find_by(int (*compare)(phandle, int, void *),
  47. void *compare_arg, phandle *prom_node, int *mid)
  48. {
  49. struct device_node *dp;
  50. int cur_inst;
  51. cur_inst = 0;
  52. for_each_node_by_type(dp, "cpu") {
  53. int err = check_cpu_node(dp->phandle, &cur_inst,
  54. compare, compare_arg,
  55. prom_node, mid);
  56. if (!err) {
  57. of_node_put(dp);
  58. return 0;
  59. }
  60. }
  61. return -ENODEV;
  62. }
  63. static int cpu_instance_compare(phandle nd, int instance, void *_arg)
  64. {
  65. int desired_instance = (int) _arg;
  66. if (instance == desired_instance)
  67. return 0;
  68. return -ENODEV;
  69. }
  70. int cpu_find_by_instance(int instance, phandle *prom_node, int *mid)
  71. {
  72. return __cpu_find_by(cpu_instance_compare, (void *)instance,
  73. prom_node, mid);
  74. }
  75. static int cpu_mid_compare(phandle nd, int instance, void *_arg)
  76. {
  77. int desired_mid = (int) _arg;
  78. int this_mid;
  79. this_mid = prom_getintdefault(nd, cpu_mid_prop(), 0);
  80. if (this_mid == desired_mid
  81. || (sparc_cpu_model == sun4m && (this_mid & 3) == desired_mid))
  82. return 0;
  83. return -ENODEV;
  84. }
  85. int cpu_find_by_mid(int mid, phandle *prom_node)
  86. {
  87. return __cpu_find_by(cpu_mid_compare, (void *)mid,
  88. prom_node, NULL);
  89. }
  90. /* sun4m uses truncated mids since we base the cpuid on the ttable/irqset
  91. * address (0-3). This gives us the true hardware mid, which might have
  92. * some other bits set. On 4d hardware and software mids are the same.
  93. */
  94. int cpu_get_hwmid(phandle prom_node)
  95. {
  96. return prom_getintdefault(prom_node, cpu_mid_prop(), -ENODEV);
  97. }
  98. void __init device_scan(void)
  99. {
  100. printk(KERN_NOTICE "Booting Linux...\n");
  101. #ifndef CONFIG_SMP
  102. {
  103. phandle cpu_node;
  104. int err;
  105. err = cpu_find_by_instance(0, &cpu_node, NULL);
  106. if (err) {
  107. /* Probably a sun4e, Sun is trying to trick us ;-) */
  108. prom_printf("No cpu nodes, cannot continue\n");
  109. prom_halt();
  110. }
  111. cpu_data(0).clock_tick = prom_getintdefault(cpu_node,
  112. "clock-frequency",
  113. 0);
  114. }
  115. #endif /* !CONFIG_SMP */
  116. auxio_probe();
  117. auxio_power_probe();
  118. }