probe_32.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. /* should be called last. */
  61. static int probe_default(void)
  62. {
  63. return 1;
  64. }
  65. static struct apic apic_default = {
  66. .name = "default",
  67. .probe = probe_default,
  68. .acpi_madt_oem_check = NULL,
  69. .apic_id_valid = default_apic_id_valid,
  70. .apic_id_registered = default_apic_id_registered,
  71. .irq_delivery_mode = dest_LowestPrio,
  72. /* logical delivery broadcast to all CPUs: */
  73. .irq_dest_mode = 1,
  74. .target_cpus = default_target_cpus,
  75. .disable_esr = 0,
  76. .dest_logical = APIC_DEST_LOGICAL,
  77. .check_apicid_used = default_check_apicid_used,
  78. .vector_allocation_domain = flat_vector_allocation_domain,
  79. .init_apic_ldr = default_init_apic_ldr,
  80. .ioapic_phys_id_map = default_ioapic_phys_id_map,
  81. .setup_apic_routing = setup_apic_flat_routing,
  82. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  83. .apicid_to_cpu_present = physid_set_mask_of_physid,
  84. .check_phys_apicid_present = default_check_phys_apicid_present,
  85. .phys_pkg_id = default_phys_pkg_id,
  86. .get_apic_id = default_get_apic_id,
  87. .set_apic_id = NULL,
  88. .apic_id_mask = 0x0F << 24,
  89. .cpu_mask_to_apicid_and = flat_cpu_mask_to_apicid_and,
  90. .send_IPI_mask = default_send_IPI_mask_logical,
  91. .send_IPI_mask_allbutself = default_send_IPI_mask_allbutself_logical,
  92. .send_IPI_allbutself = default_send_IPI_allbutself,
  93. .send_IPI_all = default_send_IPI_all,
  94. .send_IPI_self = default_send_IPI_self,
  95. .wait_for_init_deassert = true,
  96. .inquire_remote_apic = default_inquire_remote_apic,
  97. .read = native_apic_mem_read,
  98. .write = native_apic_mem_write,
  99. .eoi_write = native_apic_mem_write,
  100. .icr_read = native_apic_icr_read,
  101. .icr_write = native_apic_icr_write,
  102. .wait_icr_idle = native_apic_wait_icr_idle,
  103. .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
  104. .x86_32_early_logical_apicid = default_x86_32_early_logical_apicid,
  105. };
  106. apic_driver(apic_default);
  107. struct apic *apic = &apic_default;
  108. EXPORT_SYMBOL_GPL(apic);
  109. static int cmdline_apic __initdata;
  110. static int __init parse_apic(char *arg)
  111. {
  112. struct apic **drv;
  113. if (!arg)
  114. return -EINVAL;
  115. for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
  116. if (!strcmp((*drv)->name, arg)) {
  117. apic = *drv;
  118. cmdline_apic = 1;
  119. return 0;
  120. }
  121. }
  122. /* Parsed again by __setup for debug/verbose */
  123. return 0;
  124. }
  125. early_param("apic", parse_apic);
  126. void __init default_setup_apic_routing(void)
  127. {
  128. int version = apic_version[boot_cpu_physical_apicid];
  129. if (num_possible_cpus() > 8) {
  130. switch (boot_cpu_data.x86_vendor) {
  131. case X86_VENDOR_INTEL:
  132. if (!APIC_XAPIC(version)) {
  133. def_to_bigsmp = 0;
  134. break;
  135. }
  136. /* If P4 and above fall through */
  137. case X86_VENDOR_AMD:
  138. def_to_bigsmp = 1;
  139. }
  140. }
  141. #ifdef CONFIG_X86_BIGSMP
  142. /*
  143. * This is used to switch to bigsmp mode when
  144. * - There is no apic= option specified by the user
  145. * - generic_apic_probe() has chosen apic_default as the sub_arch
  146. * - we find more than 8 CPUs in acpi LAPIC listing with xAPIC support
  147. */
  148. if (!cmdline_apic && apic == &apic_default)
  149. generic_bigsmp_probe();
  150. #endif
  151. if (apic->setup_apic_routing)
  152. apic->setup_apic_routing();
  153. if (x86_platform.apic_post_init)
  154. x86_platform.apic_post_init();
  155. }
  156. void __init generic_apic_probe(void)
  157. {
  158. if (!cmdline_apic) {
  159. struct apic **drv;
  160. for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
  161. if ((*drv)->probe()) {
  162. apic = *drv;
  163. break;
  164. }
  165. }
  166. /* Not visible without early console */
  167. if (drv == __apicdrivers_end)
  168. panic("Didn't find an APIC driver");
  169. }
  170. printk(KERN_INFO "Using APIC driver %s\n", apic->name);
  171. }
  172. /* This function can switch the APIC even after the initial ->probe() */
  173. int __init default_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  174. {
  175. struct apic **drv;
  176. for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
  177. if (!(*drv)->acpi_madt_oem_check)
  178. continue;
  179. if (!(*drv)->acpi_madt_oem_check(oem_id, oem_table_id))
  180. continue;
  181. if (!cmdline_apic) {
  182. apic = *drv;
  183. printk(KERN_INFO "Switched to APIC driver `%s'.\n",
  184. apic->name);
  185. }
  186. return 1;
  187. }
  188. return 0;
  189. }