ip27-klconfig.c 2.8 KB

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