bigsmp_32.c 6.3 KB

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