bigsmp_32.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 const struct cpumask *bigsmp_target_cpus(void)
  26. {
  27. #ifdef CONFIG_SMP
  28. return cpu_online_mask;
  29. #else
  30. return cpumask_of(0);
  31. #endif
  32. }
  33. static unsigned long bigsmp_check_apicid_used(physid_mask_t *map, int apicid)
  34. {
  35. return 0;
  36. }
  37. static unsigned long bigsmp_check_apicid_present(int bit)
  38. {
  39. return 1;
  40. }
  41. static int bigsmp_early_logical_apicid(int cpu)
  42. {
  43. /* on bigsmp, logical apicid is the same as physical */
  44. return early_per_cpu(x86_cpu_to_apicid, cpu);
  45. }
  46. static inline unsigned long calculate_ldr(int cpu)
  47. {
  48. unsigned long val, id;
  49. val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
  50. id = per_cpu(x86_bios_cpu_apicid, cpu);
  51. val |= SET_APIC_LOGICAL_ID(id);
  52. return val;
  53. }
  54. /*
  55. * Set up the logical destination ID.
  56. *
  57. * Intel recommends to set DFR, LDR and TPR before enabling
  58. * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
  59. * document number 292116). So here it goes...
  60. */
  61. static void bigsmp_init_apic_ldr(void)
  62. {
  63. unsigned long val;
  64. int cpu = smp_processor_id();
  65. apic_write(APIC_DFR, APIC_DFR_FLAT);
  66. val = calculate_ldr(cpu);
  67. apic_write(APIC_LDR, val);
  68. }
  69. static void bigsmp_setup_apic_routing(void)
  70. {
  71. printk(KERN_INFO
  72. "Enabling APIC mode: Physflat. Using %d I/O APICs\n",
  73. nr_ioapics);
  74. }
  75. static int bigsmp_cpu_present_to_apicid(int mps_cpu)
  76. {
  77. if (mps_cpu < nr_cpu_ids)
  78. return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu);
  79. return BAD_APICID;
  80. }
  81. static void bigsmp_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap)
  82. {
  83. /* For clustered we don't have a good way to do this yet - hack */
  84. physids_promote(0xFFL, retmap);
  85. }
  86. static int bigsmp_check_phys_apicid_present(int phys_apicid)
  87. {
  88. return 1;
  89. }
  90. /* As we are using single CPU as destination, pick only one CPU here */
  91. static unsigned int bigsmp_cpu_mask_to_apicid(const struct cpumask *cpumask)
  92. {
  93. int cpu = cpumask_first(cpumask);
  94. if (cpu < nr_cpu_ids)
  95. return cpu_physical_id(cpu);
  96. return BAD_APICID;
  97. }
  98. static unsigned int bigsmp_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
  99. const struct cpumask *andmask)
  100. {
  101. int cpu;
  102. /*
  103. * We're using fixed IRQ delivery, can only return one phys APIC ID.
  104. * May as well be the first.
  105. */
  106. for_each_cpu_and(cpu, cpumask, andmask) {
  107. if (cpumask_test_cpu(cpu, cpu_online_mask))
  108. return cpu_physical_id(cpu);
  109. }
  110. return BAD_APICID;
  111. }
  112. static int bigsmp_phys_pkg_id(int cpuid_apic, int index_msb)
  113. {
  114. return cpuid_apic >> index_msb;
  115. }
  116. static inline void bigsmp_send_IPI_mask(const struct cpumask *mask, int vector)
  117. {
  118. default_send_IPI_mask_sequence_phys(mask, vector);
  119. }
  120. static void bigsmp_send_IPI_allbutself(int vector)
  121. {
  122. default_send_IPI_mask_allbutself_phys(cpu_online_mask, vector);
  123. }
  124. static void bigsmp_send_IPI_all(int vector)
  125. {
  126. bigsmp_send_IPI_mask(cpu_online_mask, vector);
  127. }
  128. static int dmi_bigsmp; /* can be set by dmi scanners */
  129. static int hp_ht_bigsmp(const struct dmi_system_id *d)
  130. {
  131. printk(KERN_NOTICE "%s detected: force use of apic=bigsmp\n", d->ident);
  132. dmi_bigsmp = 1;
  133. return 0;
  134. }
  135. static const struct dmi_system_id bigsmp_dmi_table[] = {
  136. { hp_ht_bigsmp, "HP ProLiant DL760 G2",
  137. { DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
  138. DMI_MATCH(DMI_BIOS_VERSION, "P44-"),
  139. }
  140. },
  141. { hp_ht_bigsmp, "HP ProLiant DL740",
  142. { DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
  143. DMI_MATCH(DMI_BIOS_VERSION, "P47-"),
  144. }
  145. },
  146. { } /* NULL entry stops DMI scanning */
  147. };
  148. static void bigsmp_vector_allocation_domain(int cpu, struct cpumask *retmask)
  149. {
  150. cpumask_clear(retmask);
  151. cpumask_set_cpu(cpu, retmask);
  152. }
  153. static int probe_bigsmp(void)
  154. {
  155. if (def_to_bigsmp)
  156. dmi_bigsmp = 1;
  157. else
  158. dmi_check_system(bigsmp_dmi_table);
  159. return dmi_bigsmp;
  160. }
  161. static struct apic apic_bigsmp = {
  162. .name = "bigsmp",
  163. .probe = probe_bigsmp,
  164. .acpi_madt_oem_check = NULL,
  165. .apic_id_valid = default_apic_id_valid,
  166. .apic_id_registered = bigsmp_apic_id_registered,
  167. .irq_delivery_mode = dest_Fixed,
  168. /* phys delivery to target CPU: */
  169. .irq_dest_mode = 0,
  170. .target_cpus = bigsmp_target_cpus,
  171. .disable_esr = 1,
  172. .dest_logical = 0,
  173. .check_apicid_used = bigsmp_check_apicid_used,
  174. .check_apicid_present = bigsmp_check_apicid_present,
  175. .vector_allocation_domain = bigsmp_vector_allocation_domain,
  176. .init_apic_ldr = bigsmp_init_apic_ldr,
  177. .ioapic_phys_id_map = bigsmp_ioapic_phys_id_map,
  178. .setup_apic_routing = bigsmp_setup_apic_routing,
  179. .multi_timer_check = NULL,
  180. .cpu_present_to_apicid = bigsmp_cpu_present_to_apicid,
  181. .apicid_to_cpu_present = physid_set_mask_of_physid,
  182. .setup_portio_remap = NULL,
  183. .check_phys_apicid_present = bigsmp_check_phys_apicid_present,
  184. .enable_apic_mode = NULL,
  185. .phys_pkg_id = bigsmp_phys_pkg_id,
  186. .mps_oem_check = NULL,
  187. .get_apic_id = bigsmp_get_apic_id,
  188. .set_apic_id = NULL,
  189. .apic_id_mask = 0xFF << 24,
  190. .cpu_mask_to_apicid = bigsmp_cpu_mask_to_apicid,
  191. .cpu_mask_to_apicid_and = bigsmp_cpu_mask_to_apicid_and,
  192. .send_IPI_mask = bigsmp_send_IPI_mask,
  193. .send_IPI_mask_allbutself = NULL,
  194. .send_IPI_allbutself = bigsmp_send_IPI_allbutself,
  195. .send_IPI_all = bigsmp_send_IPI_all,
  196. .send_IPI_self = default_send_IPI_self,
  197. .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
  198. .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
  199. .wait_for_init_deassert = default_wait_for_init_deassert,
  200. .smp_callin_clear_local_apic = NULL,
  201. .inquire_remote_apic = default_inquire_remote_apic,
  202. .read = native_apic_mem_read,
  203. .write = native_apic_mem_write,
  204. .icr_read = native_apic_icr_read,
  205. .icr_write = native_apic_icr_write,
  206. .wait_icr_idle = native_apic_wait_icr_idle,
  207. .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
  208. .x86_32_early_logical_apicid = bigsmp_early_logical_apicid,
  209. };
  210. void __init generic_bigsmp_probe(void)
  211. {
  212. unsigned int cpu;
  213. if (!probe_bigsmp())
  214. return;
  215. apic = &apic_bigsmp;
  216. for_each_possible_cpu(cpu) {
  217. if (early_per_cpu(x86_cpu_to_logical_apicid,
  218. cpu) == BAD_APICID)
  219. continue;
  220. early_per_cpu(x86_cpu_to_logical_apicid, cpu) =
  221. bigsmp_early_logical_apicid(cpu);
  222. }
  223. pr_info("Overriding APIC driver with %s\n", apic_bigsmp.name);
  224. }
  225. apic_driver(apic_bigsmp);