probe_32.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Default generic APIC driver. This handles up to 8 CPUs.
  4. *
  5. * Copyright 2003 Andi Kleen, SuSE Labs.
  6. *
  7. * Generic x86 APIC driver probe layer.
  8. */
  9. #include <linux/export.h>
  10. #include <linux/errno.h>
  11. #include <linux/smp.h>
  12. #include <asm/io_apic.h>
  13. #include <asm/apic.h>
  14. #include <asm/acpi.h>
  15. #include "local.h"
  16. static int default_x86_32_early_logical_apicid(int cpu)
  17. {
  18. return 1 << cpu;
  19. }
  20. static void setup_apic_flat_routing(void)
  21. {
  22. #ifdef CONFIG_X86_IO_APIC
  23. printk(KERN_INFO
  24. "Enabling APIC mode: Flat. Using %d I/O APICs\n",
  25. nr_ioapics);
  26. #endif
  27. }
  28. static int default_apic_id_registered(void)
  29. {
  30. return physid_isset(read_apic_id(), phys_cpu_present_map);
  31. }
  32. /*
  33. * Set up the logical destination ID. Intel recommends to set DFR, LDR and
  34. * TPR before enabling an APIC. See e.g. "AP-388 82489DX User's Manual"
  35. * (Intel document number 292116).
  36. */
  37. static void default_init_apic_ldr(void)
  38. {
  39. unsigned long val;
  40. apic_write(APIC_DFR, APIC_DFR_VALUE);
  41. val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
  42. val |= SET_APIC_LOGICAL_ID(1UL << smp_processor_id());
  43. apic_write(APIC_LDR, val);
  44. }
  45. static int default_phys_pkg_id(int cpuid_apic, int index_msb)
  46. {
  47. return cpuid_apic >> index_msb;
  48. }
  49. /* should be called last. */
  50. static int probe_default(void)
  51. {
  52. return 1;
  53. }
  54. static struct apic apic_default __ro_after_init = {
  55. .name = "default",
  56. .probe = probe_default,
  57. .acpi_madt_oem_check = NULL,
  58. .apic_id_valid = default_apic_id_valid,
  59. .apic_id_registered = default_apic_id_registered,
  60. .delivery_mode = APIC_DELIVERY_MODE_FIXED,
  61. .dest_mode_logical = true,
  62. .disable_esr = 0,
  63. .check_apicid_used = default_check_apicid_used,
  64. .init_apic_ldr = default_init_apic_ldr,
  65. .ioapic_phys_id_map = default_ioapic_phys_id_map,
  66. .setup_apic_routing = setup_apic_flat_routing,
  67. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  68. .apicid_to_cpu_present = physid_set_mask_of_physid,
  69. .check_phys_apicid_present = default_check_phys_apicid_present,
  70. .phys_pkg_id = default_phys_pkg_id,
  71. .get_apic_id = default_get_apic_id,
  72. .set_apic_id = NULL,
  73. .calc_dest_apicid = apic_flat_calc_apicid,
  74. .send_IPI = default_send_IPI_single,
  75. .send_IPI_mask = default_send_IPI_mask_logical,
  76. .send_IPI_mask_allbutself = default_send_IPI_mask_allbutself_logical,
  77. .send_IPI_allbutself = default_send_IPI_allbutself,
  78. .send_IPI_all = default_send_IPI_all,
  79. .send_IPI_self = default_send_IPI_self,
  80. .inquire_remote_apic = default_inquire_remote_apic,
  81. .read = native_apic_mem_read,
  82. .write = native_apic_mem_write,
  83. .eoi_write = native_apic_mem_write,
  84. .icr_read = native_apic_icr_read,
  85. .icr_write = native_apic_icr_write,
  86. .wait_icr_idle = native_apic_wait_icr_idle,
  87. .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
  88. .x86_32_early_logical_apicid = default_x86_32_early_logical_apicid,
  89. };
  90. apic_driver(apic_default);
  91. struct apic *apic __ro_after_init = &apic_default;
  92. EXPORT_SYMBOL_GPL(apic);
  93. static int cmdline_apic __initdata;
  94. static int __init parse_apic(char *arg)
  95. {
  96. struct apic **drv;
  97. if (!arg)
  98. return -EINVAL;
  99. for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
  100. if (!strcmp((*drv)->name, arg)) {
  101. apic = *drv;
  102. cmdline_apic = 1;
  103. return 0;
  104. }
  105. }
  106. /* Parsed again by __setup for debug/verbose */
  107. return 0;
  108. }
  109. early_param("apic", parse_apic);
  110. void __init default_setup_apic_routing(void)
  111. {
  112. int version = boot_cpu_apic_version;
  113. if (num_possible_cpus() > 8) {
  114. switch (boot_cpu_data.x86_vendor) {
  115. case X86_VENDOR_INTEL:
  116. if (!APIC_XAPIC(version)) {
  117. def_to_bigsmp = 0;
  118. break;
  119. }
  120. /* P4 and above */
  121. fallthrough;
  122. case X86_VENDOR_HYGON:
  123. case X86_VENDOR_AMD:
  124. def_to_bigsmp = 1;
  125. }
  126. }
  127. #ifdef CONFIG_X86_BIGSMP
  128. /*
  129. * This is used to switch to bigsmp mode when
  130. * - There is no apic= option specified by the user
  131. * - generic_apic_probe() has chosen apic_default as the sub_arch
  132. * - we find more than 8 CPUs in acpi LAPIC listing with xAPIC support
  133. */
  134. if (!cmdline_apic && apic == &apic_default)
  135. generic_bigsmp_probe();
  136. #endif
  137. if (apic->setup_apic_routing)
  138. apic->setup_apic_routing();
  139. }
  140. void __init generic_apic_probe(void)
  141. {
  142. if (!cmdline_apic) {
  143. struct apic **drv;
  144. for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
  145. if ((*drv)->probe()) {
  146. apic = *drv;
  147. break;
  148. }
  149. }
  150. /* Not visible without early console */
  151. if (drv == __apicdrivers_end)
  152. panic("Didn't find an APIC driver");
  153. }
  154. printk(KERN_INFO "Using APIC driver %s\n", apic->name);
  155. }
  156. /* This function can switch the APIC even after the initial ->probe() */
  157. int __init default_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  158. {
  159. struct apic **drv;
  160. for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
  161. if (!(*drv)->acpi_madt_oem_check)
  162. continue;
  163. if (!(*drv)->acpi_madt_oem_check(oem_id, oem_table_id))
  164. continue;
  165. if (!cmdline_apic) {
  166. apic = *drv;
  167. printk(KERN_INFO "Switched to APIC driver `%s'.\n",
  168. apic->name);
  169. }
  170. return 1;
  171. }
  172. return 0;
  173. }