bigsmp_32.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * APIC driver for "bigsmp" xAPIC machines with more than 8 virtual CPUs.
  3. *
  4. * Drives the local APIC in "clustered mode".
  5. */
  6. #include <linux/threads.h>
  7. #include <linux/cpumask.h>
  8. #include <linux/kernel.h>
  9. #include <linux/init.h>
  10. #include <linux/dmi.h>
  11. #include <linux/smp.h>
  12. #include <asm/apicdef.h>
  13. #include <asm/fixmap.h>
  14. #include <asm/mpspec.h>
  15. #include <asm/apic.h>
  16. #include <asm/ipi.h>
  17. static unsigned bigsmp_get_apic_id(unsigned long x)
  18. {
  19. return (x >> 24) & 0xFF;
  20. }
  21. static int bigsmp_apic_id_registered(void)
  22. {
  23. return 1;
  24. }
  25. static unsigned long bigsmp_check_apicid_used(physid_mask_t *map, int apicid)
  26. {
  27. return 0;
  28. }
  29. static int bigsmp_early_logical_apicid(int cpu)
  30. {
  31. /* on bigsmp, logical apicid is the same as physical */
  32. return early_per_cpu(x86_cpu_to_apicid, cpu);
  33. }
  34. static inline unsigned long calculate_ldr(int cpu)
  35. {
  36. unsigned long val, id;
  37. val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
  38. id = per_cpu(x86_bios_cpu_apicid, cpu);
  39. val |= SET_APIC_LOGICAL_ID(id);
  40. return val;
  41. }
  42. /*
  43. * Set up the logical destination ID.
  44. *
  45. * Intel recommends to set DFR, LDR and TPR before enabling
  46. * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
  47. * document number 292116). So here it goes...
  48. */
  49. static void bigsmp_init_apic_ldr(void)
  50. {
  51. unsigned long val;
  52. int cpu = smp_processor_id();
  53. apic_write(APIC_DFR, APIC_DFR_FLAT);
  54. val = calculate_ldr(cpu);
  55. apic_write(APIC_LDR, val);
  56. }
  57. static void bigsmp_setup_apic_routing(void)
  58. {
  59. printk(KERN_INFO
  60. "Enabling APIC mode: Physflat. Using %d I/O APICs\n",
  61. nr_ioapics);
  62. }
  63. static int bigsmp_cpu_present_to_apicid(int mps_cpu)
  64. {
  65. if (mps_cpu < nr_cpu_ids)
  66. return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu);
  67. return BAD_APICID;
  68. }
  69. static void bigsmp_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap)
  70. {
  71. /* For clustered we don't have a good way to do this yet - hack */
  72. physids_promote(0xFFL, retmap);
  73. }
  74. static int bigsmp_check_phys_apicid_present(int phys_apicid)
  75. {
  76. return 1;
  77. }
  78. static int bigsmp_phys_pkg_id(int cpuid_apic, int index_msb)
  79. {
  80. return cpuid_apic >> index_msb;
  81. }
  82. static void bigsmp_send_IPI_allbutself(int vector)
  83. {
  84. default_send_IPI_mask_allbutself_phys(cpu_online_mask, vector);
  85. }
  86. static void bigsmp_send_IPI_all(int vector)
  87. {
  88. default_send_IPI_mask_sequence_phys(cpu_online_mask, vector);
  89. }
  90. static int dmi_bigsmp; /* can be set by dmi scanners */
  91. static int hp_ht_bigsmp(const struct dmi_system_id *d)
  92. {
  93. printk(KERN_NOTICE "%s detected: force use of apic=bigsmp\n", d->ident);
  94. dmi_bigsmp = 1;
  95. return 0;
  96. }
  97. static const struct dmi_system_id bigsmp_dmi_table[] = {
  98. { hp_ht_bigsmp, "HP ProLiant DL760 G2",
  99. { DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
  100. DMI_MATCH(DMI_BIOS_VERSION, "P44-"),
  101. }
  102. },
  103. { hp_ht_bigsmp, "HP ProLiant DL740",
  104. { DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
  105. DMI_MATCH(DMI_BIOS_VERSION, "P47-"),
  106. }
  107. },
  108. { } /* NULL entry stops DMI scanning */
  109. };
  110. static int probe_bigsmp(void)
  111. {
  112. if (def_to_bigsmp)
  113. dmi_bigsmp = 1;
  114. else
  115. dmi_check_system(bigsmp_dmi_table);
  116. return dmi_bigsmp;
  117. }
  118. static struct apic apic_bigsmp __ro_after_init = {
  119. .name = "bigsmp",
  120. .probe = probe_bigsmp,
  121. .acpi_madt_oem_check = NULL,
  122. .apic_id_valid = default_apic_id_valid,
  123. .apic_id_registered = bigsmp_apic_id_registered,
  124. .irq_delivery_mode = dest_Fixed,
  125. /* phys delivery to target CPU: */
  126. .irq_dest_mode = 0,
  127. .target_cpus = default_target_cpus,
  128. .disable_esr = 1,
  129. .dest_logical = 0,
  130. .check_apicid_used = bigsmp_check_apicid_used,
  131. .vector_allocation_domain = default_vector_allocation_domain,
  132. .init_apic_ldr = bigsmp_init_apic_ldr,
  133. .ioapic_phys_id_map = bigsmp_ioapic_phys_id_map,
  134. .setup_apic_routing = bigsmp_setup_apic_routing,
  135. .cpu_present_to_apicid = bigsmp_cpu_present_to_apicid,
  136. .apicid_to_cpu_present = physid_set_mask_of_physid,
  137. .check_phys_apicid_present = bigsmp_check_phys_apicid_present,
  138. .phys_pkg_id = bigsmp_phys_pkg_id,
  139. .get_apic_id = bigsmp_get_apic_id,
  140. .set_apic_id = NULL,
  141. .cpu_mask_to_apicid_and = default_cpu_mask_to_apicid_and,
  142. .send_IPI = default_send_IPI_single_phys,
  143. .send_IPI_mask = default_send_IPI_mask_sequence_phys,
  144. .send_IPI_mask_allbutself = NULL,
  145. .send_IPI_allbutself = bigsmp_send_IPI_allbutself,
  146. .send_IPI_all = bigsmp_send_IPI_all,
  147. .send_IPI_self = default_send_IPI_self,
  148. .inquire_remote_apic = default_inquire_remote_apic,
  149. .read = native_apic_mem_read,
  150. .write = native_apic_mem_write,
  151. .eoi_write = native_apic_mem_write,
  152. .icr_read = native_apic_icr_read,
  153. .icr_write = native_apic_icr_write,
  154. .wait_icr_idle = native_apic_wait_icr_idle,
  155. .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
  156. .x86_32_early_logical_apicid = bigsmp_early_logical_apicid,
  157. };
  158. void __init generic_bigsmp_probe(void)
  159. {
  160. unsigned int cpu;
  161. if (!probe_bigsmp())
  162. return;
  163. apic = &apic_bigsmp;
  164. for_each_possible_cpu(cpu) {
  165. if (early_per_cpu(x86_cpu_to_logical_apicid,
  166. cpu) == BAD_APICID)
  167. continue;
  168. early_per_cpu(x86_cpu_to_logical_apicid, cpu) =
  169. bigsmp_early_logical_apicid(cpu);
  170. }
  171. pr_info("Overriding APIC driver with %s\n", apic_bigsmp.name);
  172. }
  173. apic_driver(apic_bigsmp);