genapic.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright 2004 James Cleverdon, IBM.
  3. * Subject to the GNU Public License, v.2
  4. *
  5. * Generic APIC sub-arch probe layer.
  6. *
  7. * Hacked for x86-64 by James Cleverdon from i386 architecture code by
  8. * Martin Bligh, Andi Kleen, James Bottomley, John Stultz, and
  9. * James Cleverdon.
  10. */
  11. #include <linux/threads.h>
  12. #include <linux/cpumask.h>
  13. #include <linux/string.h>
  14. #include <linux/kernel.h>
  15. #include <linux/ctype.h>
  16. #include <linux/init.h>
  17. #include <linux/module.h>
  18. #include <asm/smp.h>
  19. #include <asm/ipi.h>
  20. #if defined(CONFIG_ACPI)
  21. #include <acpi/acpi_bus.h>
  22. #endif
  23. /* which logical CPU number maps to which CPU (physical APIC ID) */
  24. u8 x86_cpu_to_apicid[NR_CPUS] __read_mostly = { [0 ... NR_CPUS-1] = BAD_APICID };
  25. EXPORT_SYMBOL(x86_cpu_to_apicid);
  26. u8 x86_cpu_to_log_apicid[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID };
  27. extern struct genapic apic_cluster;
  28. extern struct genapic apic_flat;
  29. extern struct genapic apic_physflat;
  30. struct genapic *genapic = &apic_flat;
  31. struct genapic *genapic_force;
  32. /*
  33. * Check the APIC IDs in bios_cpu_apicid and choose the APIC mode.
  34. */
  35. void __init clustered_apic_check(void)
  36. {
  37. long i;
  38. u8 clusters, max_cluster;
  39. u8 id;
  40. u8 cluster_cnt[NUM_APIC_CLUSTERS];
  41. int max_apic = 0;
  42. /* genapic selection can be forced because of certain quirks.
  43. */
  44. if (genapic_force) {
  45. genapic = genapic_force;
  46. goto print;
  47. }
  48. #if defined(CONFIG_ACPI)
  49. /*
  50. * Some x86_64 machines use physical APIC mode regardless of how many
  51. * procs/clusters are present (x86_64 ES7000 is an example).
  52. */
  53. if (acpi_gbl_FADT.header.revision > FADT2_REVISION_ID)
  54. if (acpi_gbl_FADT.flags & ACPI_FADT_APIC_PHYSICAL) {
  55. genapic = &apic_cluster;
  56. goto print;
  57. }
  58. #endif
  59. memset(cluster_cnt, 0, sizeof(cluster_cnt));
  60. for (i = 0; i < NR_CPUS; i++) {
  61. id = bios_cpu_apicid[i];
  62. if (id == BAD_APICID)
  63. continue;
  64. if (id > max_apic)
  65. max_apic = id;
  66. cluster_cnt[APIC_CLUSTERID(id)]++;
  67. }
  68. /* Don't use clustered mode on AMD platforms. */
  69. if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
  70. genapic = &apic_physflat;
  71. #ifndef CONFIG_HOTPLUG_CPU
  72. /* In the CPU hotplug case we cannot use broadcast mode
  73. because that opens a race when a CPU is removed.
  74. Stay at physflat mode in this case.
  75. It is bad to do this unconditionally though. Once
  76. we have ACPI platform support for CPU hotplug
  77. we should detect hotplug capablity from ACPI tables and
  78. only do this when really needed. -AK */
  79. if (max_apic <= 8)
  80. genapic = &apic_flat;
  81. #endif
  82. goto print;
  83. }
  84. clusters = 0;
  85. max_cluster = 0;
  86. for (i = 0; i < NUM_APIC_CLUSTERS; i++) {
  87. if (cluster_cnt[i] > 0) {
  88. ++clusters;
  89. if (cluster_cnt[i] > max_cluster)
  90. max_cluster = cluster_cnt[i];
  91. }
  92. }
  93. /*
  94. * If we have clusters <= 1 and CPUs <= 8 in cluster 0, then flat mode,
  95. * else if max_cluster <= 4 and cluster_cnt[15] == 0, clustered logical
  96. * else physical mode.
  97. * (We don't use lowest priority delivery + HW APIC IRQ steering, so
  98. * can ignore the clustered logical case and go straight to physical.)
  99. */
  100. if (clusters <= 1 && max_cluster <= 8 && cluster_cnt[0] == max_cluster) {
  101. #ifdef CONFIG_HOTPLUG_CPU
  102. /* Don't use APIC shortcuts in CPU hotplug to avoid races */
  103. genapic = &apic_physflat;
  104. #else
  105. genapic = &apic_flat;
  106. #endif
  107. } else
  108. genapic = &apic_cluster;
  109. print:
  110. printk(KERN_INFO "Setting APIC routing to %s\n", genapic->name);
  111. }
  112. /* Same for both flat and clustered. */
  113. void send_IPI_self(int vector)
  114. {
  115. __send_IPI_shortcut(APIC_DEST_SELF, vector, APIC_DEST_PHYSICAL);
  116. }