probe_32.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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/export.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/api.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 int default_apic_id_registered(void)
  61. {
  62. return physid_isset(read_apic_id(), phys_cpu_present_map);
  63. }
  64. /*
  65. * Set up the logical destination ID. Intel recommends to set DFR, LDR and
  66. * TPR before enabling an APIC. See e.g. "AP-388 82489DX User's Manual"
  67. * (Intel document number 292116).
  68. */
  69. static void default_init_apic_ldr(void)
  70. {
  71. unsigned long val;
  72. apic_write(APIC_DFR, APIC_DFR_VALUE);
  73. val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
  74. val |= SET_APIC_LOGICAL_ID(1UL << smp_processor_id());
  75. apic_write(APIC_LDR, val);
  76. }
  77. static int default_phys_pkg_id(int cpuid_apic, int index_msb)
  78. {
  79. return cpuid_apic >> index_msb;
  80. }
  81. /* should be called last. */
  82. static int probe_default(void)
  83. {
  84. return 1;
  85. }
  86. static struct apic apic_default __ro_after_init = {
  87. .name = "default",
  88. .probe = probe_default,
  89. .acpi_madt_oem_check = NULL,
  90. .apic_id_valid = default_apic_id_valid,
  91. .apic_id_registered = default_apic_id_registered,
  92. .irq_delivery_mode = dest_Fixed,
  93. /* logical delivery broadcast to all CPUs: */
  94. .irq_dest_mode = 1,
  95. .disable_esr = 0,
  96. .dest_logical = APIC_DEST_LOGICAL,
  97. .check_apicid_used = default_check_apicid_used,
  98. .init_apic_ldr = default_init_apic_ldr,
  99. .ioapic_phys_id_map = default_ioapic_phys_id_map,
  100. .setup_apic_routing = setup_apic_flat_routing,
  101. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  102. .apicid_to_cpu_present = physid_set_mask_of_physid,
  103. .check_phys_apicid_present = default_check_phys_apicid_present,
  104. .phys_pkg_id = default_phys_pkg_id,
  105. .get_apic_id = default_get_apic_id,
  106. .set_apic_id = NULL,
  107. .calc_dest_apicid = apic_flat_calc_apicid,
  108. .send_IPI = default_send_IPI_single,
  109. .send_IPI_mask = default_send_IPI_mask_logical,
  110. .send_IPI_mask_allbutself = default_send_IPI_mask_allbutself_logical,
  111. .send_IPI_allbutself = default_send_IPI_allbutself,
  112. .send_IPI_all = default_send_IPI_all,
  113. .send_IPI_self = default_send_IPI_self,
  114. .inquire_remote_apic = default_inquire_remote_apic,
  115. .read = native_apic_mem_read,
  116. .write = native_apic_mem_write,
  117. .eoi_write = native_apic_mem_write,
  118. .icr_read = native_apic_icr_read,
  119. .icr_write = native_apic_icr_write,
  120. .wait_icr_idle = native_apic_wait_icr_idle,
  121. .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
  122. .x86_32_early_logical_apicid = default_x86_32_early_logical_apicid,
  123. };
  124. apic_driver(apic_default);
  125. struct apic *apic __ro_after_init = &apic_default;
  126. EXPORT_SYMBOL_GPL(apic);
  127. static int cmdline_apic __initdata;
  128. static int __init parse_apic(char *arg)
  129. {
  130. struct apic **drv;
  131. if (!arg)
  132. return -EINVAL;
  133. for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
  134. if (!strcmp((*drv)->name, arg)) {
  135. apic = *drv;
  136. cmdline_apic = 1;
  137. return 0;
  138. }
  139. }
  140. /* Parsed again by __setup for debug/verbose */
  141. return 0;
  142. }
  143. early_param("apic", parse_apic);
  144. void __init default_setup_apic_routing(void)
  145. {
  146. int version = boot_cpu_apic_version;
  147. if (num_possible_cpus() > 8) {
  148. switch (boot_cpu_data.x86_vendor) {
  149. case X86_VENDOR_INTEL:
  150. if (!APIC_XAPIC(version)) {
  151. def_to_bigsmp = 0;
  152. break;
  153. }
  154. /* If P4 and above fall through */
  155. case X86_VENDOR_AMD:
  156. def_to_bigsmp = 1;
  157. }
  158. }
  159. #ifdef CONFIG_X86_BIGSMP
  160. /*
  161. * This is used to switch to bigsmp mode when
  162. * - There is no apic= option specified by the user
  163. * - generic_apic_probe() has chosen apic_default as the sub_arch
  164. * - we find more than 8 CPUs in acpi LAPIC listing with xAPIC support
  165. */
  166. if (!cmdline_apic && apic == &apic_default)
  167. generic_bigsmp_probe();
  168. #endif
  169. if (apic->setup_apic_routing)
  170. apic->setup_apic_routing();
  171. if (x86_platform.apic_post_init)
  172. x86_platform.apic_post_init();
  173. }
  174. void __init generic_apic_probe(void)
  175. {
  176. if (!cmdline_apic) {
  177. struct apic **drv;
  178. for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
  179. if ((*drv)->probe()) {
  180. apic = *drv;
  181. break;
  182. }
  183. }
  184. /* Not visible without early console */
  185. if (drv == __apicdrivers_end)
  186. panic("Didn't find an APIC driver");
  187. }
  188. printk(KERN_INFO "Using APIC driver %s\n", apic->name);
  189. }
  190. /* This function can switch the APIC even after the initial ->probe() */
  191. int __init default_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  192. {
  193. struct apic **drv;
  194. for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
  195. if (!(*drv)->acpi_madt_oem_check)
  196. continue;
  197. if (!(*drv)->acpi_madt_oem_check(oem_id, oem_table_id))
  198. continue;
  199. if (!cmdline_apic) {
  200. apic = *drv;
  201. printk(KERN_INFO "Switched to APIC driver `%s'.\n",
  202. apic->name);
  203. }
  204. return 1;
  205. }
  206. return 0;
  207. }