apic_noop.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * NOOP APIC driver.
  3. *
  4. * Does almost nothing and should be substituted by a real apic driver via
  5. * probe routine.
  6. *
  7. * Though in case if apic is disabled (for some reason) we try
  8. * to not uglify the caller's code and allow to call (some) apic routines
  9. * like self-ipi, etc... and issue a warning if an operation is not allowed
  10. */
  11. #include <linux/threads.h>
  12. #include <linux/cpumask.h>
  13. #include <linux/module.h>
  14. #include <linux/string.h>
  15. #include <linux/kernel.h>
  16. #include <linux/ctype.h>
  17. #include <linux/init.h>
  18. #include <linux/errno.h>
  19. #include <asm/fixmap.h>
  20. #include <asm/mpspec.h>
  21. #include <asm/apicdef.h>
  22. #include <asm/apic.h>
  23. #include <asm/setup.h>
  24. #include <linux/smp.h>
  25. #include <asm/ipi.h>
  26. #include <linux/interrupt.h>
  27. #include <asm/acpi.h>
  28. #include <asm/e820.h>
  29. /*
  30. * some operations should never be reached with
  31. * noop apic if it's not turned off, this mostly
  32. * means the caller forgot to disable apic (or
  33. * check the apic presence) before doing a call
  34. */
  35. static void warn_apic_enabled(void)
  36. {
  37. WARN_ONCE((cpu_has_apic || !disable_apic),
  38. "APIC: Called for NOOP operation with apic enabled\n");
  39. }
  40. /*
  41. * To check operations but do not bloat source code
  42. */
  43. #define NOOP_FUNC(func) func { warn_apic_enabled(); }
  44. #define NOOP_FUNC_RET(func, ret) func { warn_apic_enabled(); return ret; }
  45. NOOP_FUNC(static void noop_init_apic_ldr(void))
  46. NOOP_FUNC(static void noop_send_IPI_mask(const struct cpumask *cpumask, int vector))
  47. NOOP_FUNC(static void noop_send_IPI_mask_allbutself(const struct cpumask *cpumask, int vector))
  48. NOOP_FUNC(static void noop_send_IPI_allbutself(int vector))
  49. NOOP_FUNC(static void noop_send_IPI_all(int vector))
  50. NOOP_FUNC(static void noop_send_IPI_self(int vector))
  51. NOOP_FUNC_RET(static int noop_wakeup_secondary_cpu(int apicid, unsigned long start_eip), -1)
  52. NOOP_FUNC(static void noop_apic_write(u32 reg, u32 v))
  53. NOOP_FUNC(void noop_apic_wait_icr_idle(void))
  54. NOOP_FUNC_RET(static u32 noop_safe_apic_wait_icr_idle(void), 0)
  55. NOOP_FUNC_RET(static u64 noop_apic_icr_read(void), 0)
  56. NOOP_FUNC(static void noop_apic_icr_write(u32 low, u32 id))
  57. NOOP_FUNC_RET(static physid_mask_t noop_ioapic_phys_id_map(physid_mask_t phys_map), phys_map)
  58. NOOP_FUNC_RET(static int noop_cpu_to_logical_apicid(int cpu), 1)
  59. NOOP_FUNC_RET(static int noop_default_phys_pkg_id(int cpuid_apic, int index_msb), 0)
  60. NOOP_FUNC_RET(static unsigned int noop_get_apic_id(unsigned long x), 0)
  61. static int noop_probe(void)
  62. {
  63. /* should not ever be enabled this way */
  64. return 0;
  65. }
  66. static int noop_apic_id_registered(void)
  67. {
  68. warn_apic_enabled();
  69. return physid_isset(read_apic_id(), phys_cpu_present_map);
  70. }
  71. static const struct cpumask *noop_target_cpus(void)
  72. {
  73. warn_apic_enabled();
  74. /* only BSP here */
  75. return cpumask_of(0);
  76. }
  77. static unsigned long noop_check_apicid_used(physid_mask_t bitmap, int apicid)
  78. {
  79. warn_apic_enabled();
  80. return physid_isset(apicid, bitmap);
  81. }
  82. static unsigned long noop_check_apicid_present(int bit)
  83. {
  84. warn_apic_enabled();
  85. return physid_isset(bit, phys_cpu_present_map);
  86. }
  87. static void noop_vector_allocation_domain(int cpu, struct cpumask *retmask)
  88. {
  89. warn_apic_enabled();
  90. if (cpu != 0)
  91. pr_warning("APIC: Vector allocated for non-BSP cpu\n");
  92. cpumask_clear(retmask);
  93. cpumask_set_cpu(cpu, retmask);
  94. }
  95. int noop_apicid_to_node(int logical_apicid)
  96. {
  97. warn_apic_enabled();
  98. /* we're always on node 0 */
  99. return 0;
  100. }
  101. static u32 noop_apic_read(u32 reg)
  102. {
  103. /*
  104. * noop-read is always safe until we have
  105. * non-disabled unit
  106. */
  107. WARN_ON_ONCE((cpu_has_apic && !disable_apic));
  108. return 0;
  109. }
  110. struct apic apic_noop = {
  111. .name = "noop",
  112. .probe = noop_probe,
  113. .acpi_madt_oem_check = NULL,
  114. .apic_id_registered = noop_apic_id_registered,
  115. .irq_delivery_mode = dest_LowestPrio,
  116. /* logical delivery broadcast to all CPUs: */
  117. .irq_dest_mode = 1,
  118. .target_cpus = noop_target_cpus,
  119. .disable_esr = 0,
  120. .dest_logical = APIC_DEST_LOGICAL,
  121. .check_apicid_used = noop_check_apicid_used,
  122. .check_apicid_present = noop_check_apicid_present,
  123. .vector_allocation_domain = noop_vector_allocation_domain,
  124. .init_apic_ldr = noop_init_apic_ldr,
  125. .ioapic_phys_id_map = noop_ioapic_phys_id_map,
  126. .setup_apic_routing = NULL,
  127. .multi_timer_check = NULL,
  128. .apicid_to_node = noop_apicid_to_node,
  129. .cpu_to_logical_apicid = noop_cpu_to_logical_apicid,
  130. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  131. .apicid_to_cpu_present = default_apicid_to_cpu_present,
  132. .setup_portio_remap = NULL,
  133. .check_phys_apicid_present = default_check_phys_apicid_present,
  134. .enable_apic_mode = NULL,
  135. .phys_pkg_id = noop_default_phys_pkg_id,
  136. .mps_oem_check = NULL,
  137. .get_apic_id = noop_get_apic_id,
  138. .set_apic_id = NULL,
  139. .apic_id_mask = 0x0F << 24,
  140. .cpu_mask_to_apicid = default_cpu_mask_to_apicid,
  141. .cpu_mask_to_apicid_and = default_cpu_mask_to_apicid_and,
  142. .send_IPI_mask = noop_send_IPI_mask,
  143. .send_IPI_mask_allbutself = noop_send_IPI_mask_allbutself,
  144. .send_IPI_allbutself = noop_send_IPI_allbutself,
  145. .send_IPI_all = noop_send_IPI_all,
  146. .send_IPI_self = noop_send_IPI_self,
  147. .wakeup_secondary_cpu = noop_wakeup_secondary_cpu,
  148. /* should be safe */
  149. .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
  150. .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
  151. .wait_for_init_deassert = NULL,
  152. .smp_callin_clear_local_apic = NULL,
  153. .inquire_remote_apic = NULL,
  154. .read = noop_apic_read,
  155. .write = noop_apic_write,
  156. .icr_read = noop_apic_icr_read,
  157. .icr_write = noop_apic_icr_write,
  158. .wait_icr_idle = noop_apic_wait_icr_idle,
  159. .safe_wait_icr_idle = noop_safe_apic_wait_icr_idle,
  160. };