probe_32.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * Default generic APIC driver. This handles up to 8 CPUs.
  3. *
  4. * Copyright 2003 Andi Kleen, SuSE Labs.
  5. * Subject to the GNU Public License, v.2
  6. *
  7. * Generic x86 APIC driver probe layer.
  8. */
  9. #include <linux/threads.h>
  10. #include <linux/cpumask.h>
  11. #include <linux/module.h>
  12. #include <linux/string.h>
  13. #include <linux/kernel.h>
  14. #include <linux/ctype.h>
  15. #include <linux/init.h>
  16. #include <linux/errno.h>
  17. #include <asm/fixmap.h>
  18. #include <asm/mpspec.h>
  19. #include <asm/apicdef.h>
  20. #include <asm/apic.h>
  21. #include <asm/setup.h>
  22. #include <linux/smp.h>
  23. #include <asm/ipi.h>
  24. #include <linux/interrupt.h>
  25. #include <asm/acpi.h>
  26. #include <asm/e820.h>
  27. #ifdef CONFIG_HOTPLUG_CPU
  28. #define DEFAULT_SEND_IPI (1)
  29. #else
  30. #define DEFAULT_SEND_IPI (0)
  31. #endif
  32. int no_broadcast = DEFAULT_SEND_IPI;
  33. static __init int no_ipi_broadcast(char *str)
  34. {
  35. get_option(&str, &no_broadcast);
  36. pr_info("Using %s mode\n",
  37. no_broadcast ? "No IPI Broadcast" : "IPI Broadcast");
  38. return 1;
  39. }
  40. __setup("no_ipi_broadcast=", no_ipi_broadcast);
  41. static int __init print_ipi_mode(void)
  42. {
  43. pr_info("Using IPI %s mode\n",
  44. no_broadcast ? "No-Shortcut" : "Shortcut");
  45. return 0;
  46. }
  47. late_initcall(print_ipi_mode);
  48. static int default_x86_32_early_logical_apicid(int cpu)
  49. {
  50. return 1 << cpu;
  51. }
  52. static void setup_apic_flat_routing(void)
  53. {
  54. #ifdef CONFIG_X86_IO_APIC
  55. printk(KERN_INFO
  56. "Enabling APIC mode: Flat. Using %d I/O APICs\n",
  57. nr_ioapics);
  58. #endif
  59. }
  60. static void default_vector_allocation_domain(int cpu, struct cpumask *retmask)
  61. {
  62. /*
  63. * Careful. Some cpus do not strictly honor the set of cpus
  64. * specified in the interrupt destination when using lowest
  65. * priority interrupt delivery mode.
  66. *
  67. * In particular there was a hyperthreading cpu observed to
  68. * deliver interrupts to the wrong hyperthread when only one
  69. * hyperthread was specified in the interrupt desitination.
  70. */
  71. cpumask_clear(retmask);
  72. cpumask_bits(retmask)[0] = APIC_ALL_CPUS;
  73. }
  74. /* should be called last. */
  75. static int probe_default(void)
  76. {
  77. return 1;
  78. }
  79. static struct apic apic_default = {
  80. .name = "default",
  81. .probe = probe_default,
  82. .acpi_madt_oem_check = NULL,
  83. .apic_id_valid = default_apic_id_valid,
  84. .apic_id_registered = default_apic_id_registered,
  85. .irq_delivery_mode = dest_LowestPrio,
  86. /* logical delivery broadcast to all CPUs: */
  87. .irq_dest_mode = 1,
  88. .target_cpus = default_target_cpus,
  89. .disable_esr = 0,
  90. .dest_logical = APIC_DEST_LOGICAL,
  91. .check_apicid_used = default_check_apicid_used,
  92. .check_apicid_present = default_check_apicid_present,
  93. .vector_allocation_domain = default_vector_allocation_domain,
  94. .init_apic_ldr = default_init_apic_ldr,
  95. .ioapic_phys_id_map = default_ioapic_phys_id_map,
  96. .setup_apic_routing = setup_apic_flat_routing,
  97. .multi_timer_check = NULL,
  98. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  99. .apicid_to_cpu_present = physid_set_mask_of_physid,
  100. .setup_portio_remap = NULL,
  101. .check_phys_apicid_present = default_check_phys_apicid_present,
  102. .enable_apic_mode = NULL,
  103. .phys_pkg_id = default_phys_pkg_id,
  104. .mps_oem_check = NULL,
  105. .get_apic_id = default_get_apic_id,
  106. .set_apic_id = NULL,
  107. .apic_id_mask = 0x0F << 24,
  108. .cpu_mask_to_apicid = default_cpu_mask_to_apicid,
  109. .cpu_mask_to_apicid_and = default_cpu_mask_to_apicid_and,
  110. .send_IPI_mask = default_send_IPI_mask_logical,
  111. .send_IPI_mask_allbutself = default_send_IPI_mask_allbutself_logical,
  112. .send_IPI_allbutself = default_send_IPI_allbutself,
  113. .send_IPI_all = default_send_IPI_all,
  114. .send_IPI_self = default_send_IPI_self,
  115. .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
  116. .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
  117. .wait_for_init_deassert = default_wait_for_init_deassert,
  118. .smp_callin_clear_local_apic = NULL,
  119. .inquire_remote_apic = default_inquire_remote_apic,
  120. .read = native_apic_mem_read,
  121. .write = native_apic_mem_write,
  122. .eoi_write = native_apic_mem_write,
  123. .icr_read = native_apic_icr_read,
  124. .icr_write = native_apic_icr_write,
  125. .wait_icr_idle = native_apic_wait_icr_idle,
  126. .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
  127. .x86_32_early_logical_apicid = default_x86_32_early_logical_apicid,
  128. };
  129. apic_driver(apic_default);
  130. struct apic *apic = &apic_default;
  131. EXPORT_SYMBOL_GPL(apic);
  132. static int cmdline_apic __initdata;
  133. static int __init parse_apic(char *arg)
  134. {
  135. struct apic **drv;
  136. if (!arg)
  137. return -EINVAL;
  138. for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
  139. if (!strcmp((*drv)->name, arg)) {
  140. apic = *drv;
  141. cmdline_apic = 1;
  142. return 0;
  143. }
  144. }
  145. /* Parsed again by __setup for debug/verbose */
  146. return 0;
  147. }
  148. early_param("apic", parse_apic);
  149. void __init default_setup_apic_routing(void)
  150. {
  151. int version = apic_version[boot_cpu_physical_apicid];
  152. if (num_possible_cpus() > 8) {
  153. switch (boot_cpu_data.x86_vendor) {
  154. case X86_VENDOR_INTEL:
  155. if (!APIC_XAPIC(version)) {
  156. def_to_bigsmp = 0;
  157. break;
  158. }
  159. /* If P4 and above fall through */
  160. case X86_VENDOR_AMD:
  161. def_to_bigsmp = 1;
  162. }
  163. }
  164. #ifdef CONFIG_X86_BIGSMP
  165. /*
  166. * This is used to switch to bigsmp mode when
  167. * - There is no apic= option specified by the user
  168. * - generic_apic_probe() has chosen apic_default as the sub_arch
  169. * - we find more than 8 CPUs in acpi LAPIC listing with xAPIC support
  170. */
  171. if (!cmdline_apic && apic == &apic_default)
  172. generic_bigsmp_probe();
  173. #endif
  174. if (apic->setup_apic_routing)
  175. apic->setup_apic_routing();
  176. }
  177. void __init generic_apic_probe(void)
  178. {
  179. if (!cmdline_apic) {
  180. struct apic **drv;
  181. for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
  182. if ((*drv)->probe()) {
  183. apic = *drv;
  184. break;
  185. }
  186. }
  187. /* Not visible without early console */
  188. if (drv == __apicdrivers_end)
  189. panic("Didn't find an APIC driver");
  190. }
  191. printk(KERN_INFO "Using APIC driver %s\n", apic->name);
  192. }
  193. /* These functions can switch the APIC even after the initial ->probe() */
  194. int __init
  195. generic_mps_oem_check(struct mpc_table *mpc, char *oem, char *productid)
  196. {
  197. struct apic **drv;
  198. for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
  199. if (!((*drv)->mps_oem_check))
  200. continue;
  201. if (!(*drv)->mps_oem_check(mpc, oem, productid))
  202. continue;
  203. if (!cmdline_apic) {
  204. apic = *drv;
  205. printk(KERN_INFO "Switched to APIC driver `%s'.\n",
  206. apic->name);
  207. }
  208. return 1;
  209. }
  210. return 0;
  211. }
  212. int __init default_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  213. {
  214. struct apic **drv;
  215. for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
  216. if (!(*drv)->acpi_madt_oem_check)
  217. continue;
  218. if (!(*drv)->acpi_madt_oem_check(oem_id, oem_table_id))
  219. continue;
  220. if (!cmdline_apic) {
  221. apic = *drv;
  222. printk(KERN_INFO "Switched to APIC driver `%s'.\n",
  223. apic->name);
  224. }
  225. return 1;
  226. }
  227. return 0;
  228. }