genx2apic_phys.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. static int x2apic_phys;
  12. static int set_x2apic_phys_mode(char *arg)
  13. {
  14. x2apic_phys = 1;
  15. return 0;
  16. }
  17. early_param("x2apic_phys", set_x2apic_phys_mode);
  18. static int x2apic_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  19. {
  20. if (cpu_has_x2apic && x2apic_phys)
  21. return 1;
  22. return 0;
  23. }
  24. /* Start with all IRQs pointing to boot CPU. IRQ balancing will shift them. */
  25. static cpumask_t x2apic_target_cpus(void)
  26. {
  27. return cpumask_of_cpu(0);
  28. }
  29. static cpumask_t x2apic_vector_allocation_domain(int cpu)
  30. {
  31. cpumask_t domain = CPU_MASK_NONE;
  32. cpu_set(cpu, domain);
  33. return domain;
  34. }
  35. static void __x2apic_send_IPI_dest(unsigned int apicid, int vector,
  36. unsigned int dest)
  37. {
  38. unsigned long cfg;
  39. cfg = __prepare_ICR(0, vector, dest);
  40. /*
  41. * send the IPI.
  42. */
  43. x2apic_icr_write(cfg, apicid);
  44. }
  45. static void x2apic_send_IPI_mask(cpumask_t mask, int vector)
  46. {
  47. unsigned long flags;
  48. unsigned long query_cpu;
  49. local_irq_save(flags);
  50. for_each_cpu_mask(query_cpu, mask) {
  51. __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu),
  52. vector, APIC_DEST_PHYSICAL);
  53. }
  54. local_irq_restore(flags);
  55. }
  56. static void x2apic_send_IPI_allbutself(int vector)
  57. {
  58. cpumask_t mask = cpu_online_map;
  59. cpu_clear(smp_processor_id(), mask);
  60. if (!cpus_empty(mask))
  61. x2apic_send_IPI_mask(mask, vector);
  62. }
  63. static void x2apic_send_IPI_all(int vector)
  64. {
  65. x2apic_send_IPI_mask(cpu_online_map, vector);
  66. }
  67. static int x2apic_apic_id_registered(void)
  68. {
  69. return 1;
  70. }
  71. static unsigned int x2apic_cpu_mask_to_apicid(cpumask_t cpumask)
  72. {
  73. int cpu;
  74. /*
  75. * We're using fixed IRQ delivery, can only return one phys APIC ID.
  76. * May as well be the first.
  77. */
  78. cpu = first_cpu(cpumask);
  79. if ((unsigned)cpu < NR_CPUS)
  80. return per_cpu(x86_cpu_to_apicid, cpu);
  81. else
  82. return BAD_APICID;
  83. }
  84. static unsigned int get_apic_id(unsigned long x)
  85. {
  86. unsigned int id;
  87. id = x;
  88. return id;
  89. }
  90. static unsigned long set_apic_id(unsigned int id)
  91. {
  92. unsigned long x;
  93. x = id;
  94. return x;
  95. }
  96. static unsigned int phys_pkg_id(int index_msb)
  97. {
  98. return current_cpu_data.initial_apicid >> index_msb;
  99. }
  100. void x2apic_send_IPI_self(int vector)
  101. {
  102. apic_write(APIC_SELF_IPI, vector);
  103. }
  104. void init_x2apic_ldr(void)
  105. {
  106. return;
  107. }
  108. struct genapic apic_x2apic_phys = {
  109. .name = "physical x2apic",
  110. .acpi_madt_oem_check = x2apic_acpi_madt_oem_check,
  111. .int_delivery_mode = dest_Fixed,
  112. .int_dest_mode = (APIC_DEST_PHYSICAL != 0),
  113. .target_cpus = x2apic_target_cpus,
  114. .vector_allocation_domain = x2apic_vector_allocation_domain,
  115. .apic_id_registered = x2apic_apic_id_registered,
  116. .init_apic_ldr = init_x2apic_ldr,
  117. .send_IPI_all = x2apic_send_IPI_all,
  118. .send_IPI_allbutself = x2apic_send_IPI_allbutself,
  119. .send_IPI_mask = x2apic_send_IPI_mask,
  120. .send_IPI_self = x2apic_send_IPI_self,
  121. .cpu_mask_to_apicid = x2apic_cpu_mask_to_apicid,
  122. .phys_pkg_id = phys_pkg_id,
  123. .get_apic_id = get_apic_id,
  124. .set_apic_id = set_apic_id,
  125. .apic_id_mask = (0xFFFFFFFFu),
  126. };