ip27-klconfig.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (C) 1999, 2000 Ralf Baechle (ralf@gnu.org)
  3. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  4. */
  5. #include <linux/init.h>
  6. #include <linux/kernel.h>
  7. #include <linux/sched.h>
  8. #include <linux/interrupt.h>
  9. #include <linux/kernel_stat.h>
  10. #include <linux/param.h>
  11. #include <linux/timex.h>
  12. #include <linux/mm.h>
  13. #include <asm/sn/klconfig.h>
  14. #include <asm/sn/arch.h>
  15. #include <asm/sn/gda.h>
  16. klinfo_t *find_component(lboard_t *brd, klinfo_t *kli, unsigned char struct_type)
  17. {
  18. int index, j;
  19. if (kli == (klinfo_t *)NULL) {
  20. index = 0;
  21. } else {
  22. for (j = 0; j < KLCF_NUM_COMPS(brd); j++)
  23. if (kli == KLCF_COMP(brd, j))
  24. break;
  25. index = j;
  26. if (index == KLCF_NUM_COMPS(brd)) {
  27. printk("find_component: Bad pointer: 0x%p\n", kli);
  28. return (klinfo_t *)NULL;
  29. }
  30. index++; /* next component */
  31. }
  32. for (; index < KLCF_NUM_COMPS(brd); index++) {
  33. kli = KLCF_COMP(brd, index);
  34. if (KLCF_COMP_TYPE(kli) == struct_type)
  35. return kli;
  36. }
  37. /* Didn't find it. */
  38. return (klinfo_t *)NULL;
  39. }
  40. klinfo_t *find_first_component(lboard_t *brd, unsigned char struct_type)
  41. {
  42. return find_component(brd, (klinfo_t *)NULL, struct_type);
  43. }
  44. lboard_t *find_lboard(lboard_t *start, unsigned char brd_type)
  45. {
  46. /* Search all boards stored on this node. */
  47. while (start) {
  48. if (start->brd_type == brd_type)
  49. return start;
  50. start = KLCF_NEXT(start);
  51. }
  52. /* Didn't find it. */
  53. return (lboard_t *)NULL;
  54. }
  55. lboard_t *find_lboard_class(lboard_t *start, unsigned char brd_type)
  56. {
  57. /* Search all boards stored on this node. */
  58. while (start) {
  59. if (KLCLASS(start->brd_type) == KLCLASS(brd_type))
  60. return start;
  61. start = KLCF_NEXT(start);
  62. }
  63. /* Didn't find it. */
  64. return (lboard_t *)NULL;
  65. }
  66. cnodeid_t get_cpu_cnode(cpuid_t cpu)
  67. {
  68. return CPUID_TO_COMPACT_NODEID(cpu);
  69. }
  70. klcpu_t *nasid_slice_to_cpuinfo(nasid_t nasid, int slice)
  71. {
  72. lboard_t *brd;
  73. klcpu_t *acpu;
  74. if (!(brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_IP27)))
  75. return (klcpu_t *)NULL;
  76. if (!(acpu = (klcpu_t *)find_first_component(brd, KLSTRUCT_CPU)))
  77. return (klcpu_t *)NULL;
  78. do {
  79. if ((acpu->cpu_info.physid) == slice)
  80. return acpu;
  81. } while ((acpu = (klcpu_t *)find_component(brd, (klinfo_t *)acpu,
  82. KLSTRUCT_CPU)));
  83. return (klcpu_t *)NULL;
  84. }
  85. klcpu_t *sn_get_cpuinfo(cpuid_t cpu)
  86. {
  87. nasid_t nasid;
  88. int slice;
  89. klcpu_t *acpu;
  90. gda_t *gdap = GDA;
  91. cnodeid_t cnode;
  92. if (!(cpu < MAXCPUS)) {
  93. printk("sn_get_cpuinfo: illegal cpuid 0x%lx\n", cpu);
  94. return NULL;
  95. }
  96. cnode = get_cpu_cnode(cpu);
  97. if (cnode == INVALID_CNODEID)
  98. return NULL;
  99. if ((nasid = gdap->g_nasidtable[cnode]) == INVALID_NASID)
  100. return NULL;
  101. for (slice = 0; slice < CPUS_PER_NODE; slice++) {
  102. acpu = nasid_slice_to_cpuinfo(nasid, slice);
  103. if (acpu && acpu->cpu_info.virtid == cpu)
  104. return acpu;
  105. }
  106. return NULL;
  107. }
  108. int get_cpu_slice(cpuid_t cpu)
  109. {
  110. klcpu_t *acpu;
  111. if ((acpu = sn_get_cpuinfo(cpu)) == NULL)
  112. return -1;
  113. return acpu->cpu_info.physid;
  114. }