genx2apic_cluster.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #include <linux/threads.h>
  2. #include <linux/cpumask.h>
  3. #include <linux/string.h>
  4. #include <linux/kernel.h>
  5. #include <linux/ctype.h>
  6. #include <linux/init.h>
  7. #include <linux/dmar.h>
  8. #include <asm/smp.h>
  9. #include <asm/ipi.h>
  10. #include <asm/genapic.h>
  11. DEFINE_PER_CPU(u32, x86_cpu_to_logical_apicid);
  12. static int x2apic_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  13. {
  14. if (cpu_has_x2apic)
  15. return 1;
  16. return 0;
  17. }
  18. /* Start with all IRQs pointing to boot CPU. IRQ balancing will shift them. */
  19. static cpumask_t x2apic_target_cpus(void)
  20. {
  21. return cpumask_of_cpu(0);
  22. }
  23. /*
  24. * for now each logical cpu is in its own vector allocation domain.
  25. */
  26. static cpumask_t x2apic_vector_allocation_domain(int cpu)
  27. {
  28. cpumask_t domain = CPU_MASK_NONE;
  29. cpu_set(cpu, domain);
  30. return domain;
  31. }
  32. static void __x2apic_send_IPI_dest(unsigned int apicid, int vector,
  33. unsigned int dest)
  34. {
  35. unsigned long cfg;
  36. cfg = __prepare_ICR(0, vector, dest);
  37. /*
  38. * send the IPI.
  39. */
  40. x2apic_icr_write(cfg, apicid);
  41. }
  42. /*
  43. * for now, we send the IPI's one by one in the cpumask.
  44. * TBD: Based on the cpu mask, we can send the IPI's to the cluster group
  45. * at once. We have 16 cpu's in a cluster. This will minimize IPI register
  46. * writes.
  47. */
  48. static void x2apic_send_IPI_mask(cpumask_t mask, int vector)
  49. {
  50. unsigned long flags;
  51. unsigned long query_cpu;
  52. local_irq_save(flags);
  53. for_each_cpu_mask(query_cpu, mask) {
  54. __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_logical_apicid, query_cpu),
  55. vector, APIC_DEST_LOGICAL);
  56. }
  57. local_irq_restore(flags);
  58. }
  59. static void x2apic_send_IPI_allbutself(int vector)
  60. {
  61. cpumask_t mask = cpu_online_map;
  62. cpu_clear(smp_processor_id(), mask);
  63. if (!cpus_empty(mask))
  64. x2apic_send_IPI_mask(mask, vector);
  65. }
  66. static void x2apic_send_IPI_all(int vector)
  67. {
  68. x2apic_send_IPI_mask(cpu_online_map, vector);
  69. }
  70. static int x2apic_apic_id_registered(void)
  71. {
  72. return 1;
  73. }
  74. static unsigned int x2apic_cpu_mask_to_apicid(cpumask_t cpumask)
  75. {
  76. int cpu;
  77. /*
  78. * We're using fixed IRQ delivery, can only return one phys APIC ID.
  79. * May as well be the first.
  80. */
  81. cpu = first_cpu(cpumask);
  82. if ((unsigned)cpu < NR_CPUS)
  83. return per_cpu(x86_cpu_to_logical_apicid, cpu);
  84. else
  85. return BAD_APICID;
  86. }
  87. static unsigned int get_apic_id(unsigned long x)
  88. {
  89. unsigned int id;
  90. id = x;
  91. return id;
  92. }
  93. static unsigned long set_apic_id(unsigned int id)
  94. {
  95. unsigned long x;
  96. x = id;
  97. return x;
  98. }
  99. static unsigned int phys_pkg_id(int index_msb)
  100. {
  101. return current_cpu_data.initial_apicid >> index_msb;
  102. }
  103. static void x2apic_send_IPI_self(int vector)
  104. {
  105. apic_write(APIC_SELF_IPI, vector);
  106. }
  107. static void init_x2apic_ldr(void)
  108. {
  109. int cpu = smp_processor_id();
  110. per_cpu(x86_cpu_to_logical_apicid, cpu) = apic_read(APIC_LDR);
  111. return;
  112. }
  113. struct genapic apic_x2apic_cluster = {
  114. .name = "cluster x2apic",
  115. .acpi_madt_oem_check = x2apic_acpi_madt_oem_check,
  116. .int_delivery_mode = dest_LowestPrio,
  117. .int_dest_mode = (APIC_DEST_LOGICAL != 0),
  118. .target_cpus = x2apic_target_cpus,
  119. .vector_allocation_domain = x2apic_vector_allocation_domain,
  120. .apic_id_registered = x2apic_apic_id_registered,
  121. .init_apic_ldr = init_x2apic_ldr,
  122. .send_IPI_all = x2apic_send_IPI_all,
  123. .send_IPI_allbutself = x2apic_send_IPI_allbutself,
  124. .send_IPI_mask = x2apic_send_IPI_mask,
  125. .send_IPI_self = x2apic_send_IPI_self,
  126. .cpu_mask_to_apicid = x2apic_cpu_mask_to_apicid,
  127. .phys_pkg_id = phys_pkg_id,
  128. .get_apic_id = get_apic_id,
  129. .set_apic_id = set_apic_id,
  130. .apic_id_mask = (0xFFFFFFFFu),
  131. };