genapic.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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/config.h>
  12. #include <linux/threads.h>
  13. #include <linux/cpumask.h>
  14. #include <linux/string.h>
  15. #include <linux/kernel.h>
  16. #include <linux/ctype.h>
  17. #include <linux/init.h>
  18. #include <linux/module.h>
  19. #include <asm/smp.h>
  20. #include <asm/ipi.h>
  21. #if defined(CONFIG_ACPI_BUS)
  22. #include <acpi/acpi_bus.h>
  23. #endif
  24. /* which logical CPU number maps to which CPU (physical APIC ID) */
  25. u8 x86_cpu_to_apicid[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID };
  26. EXPORT_SYMBOL(x86_cpu_to_apicid);
  27. u8 x86_cpu_to_log_apicid[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID };
  28. extern struct genapic apic_cluster;
  29. extern struct genapic apic_flat;
  30. struct genapic *genapic = &apic_flat;
  31. /*
  32. * Check the APIC IDs in bios_cpu_apicid and choose the APIC mode.
  33. */
  34. void __init clustered_apic_check(void)
  35. {
  36. long i;
  37. u8 clusters, max_cluster;
  38. u8 id;
  39. u8 cluster_cnt[NUM_APIC_CLUSTERS];
  40. if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
  41. /* AMD always uses flat mode right now */
  42. genapic = &apic_flat;
  43. goto print;
  44. }
  45. #if defined(CONFIG_ACPI_BUS)
  46. /*
  47. * Some x86_64 machines use physical APIC mode regardless of how many
  48. * procs/clusters are present (x86_64 ES7000 is an example).
  49. */
  50. if (acpi_fadt.revision > FADT2_REVISION_ID)
  51. if (acpi_fadt.force_apic_physical_destination_mode) {
  52. genapic = &apic_cluster;
  53. goto print;
  54. }
  55. #endif
  56. memset(cluster_cnt, 0, sizeof(cluster_cnt));
  57. for (i = 0; i < NR_CPUS; i++) {
  58. id = bios_cpu_apicid[i];
  59. if (id != BAD_APICID)
  60. cluster_cnt[APIC_CLUSTERID(id)]++;
  61. }
  62. clusters = 0;
  63. max_cluster = 0;
  64. for (i = 0; i < NUM_APIC_CLUSTERS; i++) {
  65. if (cluster_cnt[i] > 0) {
  66. ++clusters;
  67. if (cluster_cnt[i] > max_cluster)
  68. max_cluster = cluster_cnt[i];
  69. }
  70. }
  71. /*
  72. * If we have clusters <= 1 and CPUs <= 8 in cluster 0, then flat mode,
  73. * else if max_cluster <= 4 and cluster_cnt[15] == 0, clustered logical
  74. * else physical mode.
  75. * (We don't use lowest priority delivery + HW APIC IRQ steering, so
  76. * can ignore the clustered logical case and go straight to physical.)
  77. */
  78. if (clusters <= 1 && max_cluster <= 8 && cluster_cnt[0] == max_cluster)
  79. genapic = &apic_flat;
  80. else
  81. genapic = &apic_cluster;
  82. print:
  83. printk(KERN_INFO "Setting APIC routing to %s\n", genapic->name);
  84. }
  85. /* Same for both flat and clustered. */
  86. void send_IPI_self(int vector)
  87. {
  88. __send_IPI_shortcut(APIC_DEST_SELF, vector, APIC_DEST_PHYSICAL);
  89. }