bigsmp_32.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * APIC driver for "bigsmp" XAPIC machines with more than 8 virtual CPUs.
  3. * Drives the local APIC in "clustered mode".
  4. */
  5. #include <linux/threads.h>
  6. #include <linux/cpumask.h>
  7. #include <asm/mpspec.h>
  8. #include <asm/apic.h>
  9. #include <asm/fixmap.h>
  10. #include <asm/apicdef.h>
  11. #include <asm/ipi.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/dmi.h>
  15. #include <linux/smp.h>
  16. static inline unsigned bigsmp_get_apic_id(unsigned long x)
  17. {
  18. return (x >> 24) & 0xFF;
  19. }
  20. #define xapic_phys_to_log_apicid(cpu) (per_cpu(x86_bios_cpu_apicid, cpu))
  21. static inline int bigsmp_apic_id_registered(void)
  22. {
  23. return 1;
  24. }
  25. static inline const cpumask_t *bigsmp_target_cpus(void)
  26. {
  27. #ifdef CONFIG_SMP
  28. return &cpu_online_map;
  29. #else
  30. return &cpumask_of_cpu(0);
  31. #endif
  32. }
  33. #define APIC_DFR_VALUE (APIC_DFR_FLAT)
  34. static inline unsigned long
  35. bigsmp_check_apicid_used(physid_mask_t bitmap, int apicid)
  36. {
  37. return 0;
  38. }
  39. static inline unsigned long bigsmp_check_apicid_present(int bit)
  40. {
  41. return 1;
  42. }
  43. static inline unsigned long calculate_ldr(int cpu)
  44. {
  45. unsigned long val, id;
  46. val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
  47. id = xapic_phys_to_log_apicid(cpu);
  48. val |= SET_APIC_LOGICAL_ID(id);
  49. return val;
  50. }
  51. /*
  52. * Set up the logical destination ID.
  53. *
  54. * Intel recommends to set DFR, LDR and TPR before enabling
  55. * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
  56. * document number 292116). So here it goes...
  57. */
  58. static inline void bigsmp_init_apic_ldr(void)
  59. {
  60. unsigned long val;
  61. int cpu = smp_processor_id();
  62. apic_write(APIC_DFR, APIC_DFR_VALUE);
  63. val = calculate_ldr(cpu);
  64. apic_write(APIC_LDR, val);
  65. }
  66. static inline void bigsmp_setup_apic_routing(void)
  67. {
  68. printk("Enabling APIC mode: %s. Using %d I/O APICs\n",
  69. "Physflat", nr_ioapics);
  70. }
  71. static inline int bigsmp_apicid_to_node(int logical_apicid)
  72. {
  73. return apicid_2_node[hard_smp_processor_id()];
  74. }
  75. static inline 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 inline physid_mask_t bigsmp_apicid_to_cpu_present(int phys_apicid)
  82. {
  83. return physid_mask_of_physid(phys_apicid);
  84. }
  85. extern u8 cpu_2_logical_apicid[];
  86. /* Mapping from cpu number to logical apicid */
  87. static inline int bigsmp_cpu_to_logical_apicid(int cpu)
  88. {
  89. if (cpu >= nr_cpu_ids)
  90. return BAD_APICID;
  91. return cpu_physical_id(cpu);
  92. }
  93. static inline physid_mask_t bigsmp_ioapic_phys_id_map(physid_mask_t phys_map)
  94. {
  95. /* For clustered we don't have a good way to do this yet - hack */
  96. return physids_promote(0xFFL);
  97. }
  98. static inline void bigsmp_setup_portio_remap(void)
  99. {
  100. }
  101. static inline int bigsmp_check_phys_apicid_present(int boot_cpu_physical_apicid)
  102. {
  103. return 1;
  104. }
  105. /* As we are using single CPU as destination, pick only one CPU here */
  106. static inline unsigned int bigsmp_cpu_mask_to_apicid(const cpumask_t *cpumask)
  107. {
  108. return bigsmp_cpu_to_logical_apicid(first_cpu(*cpumask));
  109. }
  110. static inline unsigned int
  111. bigsmp_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
  112. const struct cpumask *andmask)
  113. {
  114. int cpu;
  115. /*
  116. * We're using fixed IRQ delivery, can only return one phys APIC ID.
  117. * May as well be the first.
  118. */
  119. for_each_cpu_and(cpu, cpumask, andmask) {
  120. if (cpumask_test_cpu(cpu, cpu_online_mask))
  121. break;
  122. }
  123. if (cpu < nr_cpu_ids)
  124. return bigsmp_cpu_to_logical_apicid(cpu);
  125. return BAD_APICID;
  126. }
  127. static inline int bigsmp_phys_pkg_id(int cpuid_apic, int index_msb)
  128. {
  129. return cpuid_apic >> index_msb;
  130. }
  131. static inline void bigsmp_send_IPI_mask(const struct cpumask *mask, int vector)
  132. {
  133. default_send_IPI_mask_sequence_phys(mask, vector);
  134. }
  135. static inline void bigsmp_send_IPI_allbutself(int vector)
  136. {
  137. default_send_IPI_mask_allbutself_phys(cpu_online_mask, vector);
  138. }
  139. static inline void bigsmp_send_IPI_all(int vector)
  140. {
  141. bigsmp_send_IPI_mask(cpu_online_mask, vector);
  142. }
  143. static int dmi_bigsmp; /* can be set by dmi scanners */
  144. static int hp_ht_bigsmp(const struct dmi_system_id *d)
  145. {
  146. printk(KERN_NOTICE "%s detected: force use of apic=bigsmp\n", d->ident);
  147. dmi_bigsmp = 1;
  148. return 0;
  149. }
  150. static const struct dmi_system_id bigsmp_dmi_table[] = {
  151. { hp_ht_bigsmp, "HP ProLiant DL760 G2",
  152. { DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
  153. DMI_MATCH(DMI_BIOS_VERSION, "P44-"),}
  154. },
  155. { hp_ht_bigsmp, "HP ProLiant DL740",
  156. { DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
  157. DMI_MATCH(DMI_BIOS_VERSION, "P47-"),}
  158. },
  159. { }
  160. };
  161. static void bigsmp_vector_allocation_domain(int cpu, cpumask_t *retmask)
  162. {
  163. cpus_clear(*retmask);
  164. cpu_set(cpu, *retmask);
  165. }
  166. static int probe_bigsmp(void)
  167. {
  168. if (def_to_bigsmp)
  169. dmi_bigsmp = 1;
  170. else
  171. dmi_check_system(bigsmp_dmi_table);
  172. return dmi_bigsmp;
  173. }
  174. struct genapic apic_bigsmp = {
  175. .name = "bigsmp",
  176. .probe = probe_bigsmp,
  177. .acpi_madt_oem_check = NULL,
  178. .apic_id_registered = bigsmp_apic_id_registered,
  179. .irq_delivery_mode = dest_Fixed,
  180. /* phys delivery to target CPU: */
  181. .irq_dest_mode = 0,
  182. .target_cpus = bigsmp_target_cpus,
  183. .disable_esr = 1,
  184. .dest_logical = 0,
  185. .check_apicid_used = bigsmp_check_apicid_used,
  186. .check_apicid_present = bigsmp_check_apicid_present,
  187. .vector_allocation_domain = bigsmp_vector_allocation_domain,
  188. .init_apic_ldr = bigsmp_init_apic_ldr,
  189. .ioapic_phys_id_map = bigsmp_ioapic_phys_id_map,
  190. .setup_apic_routing = bigsmp_setup_apic_routing,
  191. .multi_timer_check = NULL,
  192. .apicid_to_node = bigsmp_apicid_to_node,
  193. .cpu_to_logical_apicid = bigsmp_cpu_to_logical_apicid,
  194. .cpu_present_to_apicid = bigsmp_cpu_present_to_apicid,
  195. .apicid_to_cpu_present = bigsmp_apicid_to_cpu_present,
  196. .setup_portio_remap = NULL,
  197. .check_phys_apicid_present = bigsmp_check_phys_apicid_present,
  198. .enable_apic_mode = NULL,
  199. .phys_pkg_id = bigsmp_phys_pkg_id,
  200. .mps_oem_check = NULL,
  201. .get_apic_id = bigsmp_get_apic_id,
  202. .set_apic_id = NULL,
  203. .apic_id_mask = 0xFF << 24,
  204. .cpu_mask_to_apicid = bigsmp_cpu_mask_to_apicid,
  205. .cpu_mask_to_apicid_and = bigsmp_cpu_mask_to_apicid_and,
  206. .send_IPI_mask = bigsmp_send_IPI_mask,
  207. .send_IPI_mask_allbutself = NULL,
  208. .send_IPI_allbutself = bigsmp_send_IPI_allbutself,
  209. .send_IPI_all = bigsmp_send_IPI_all,
  210. .send_IPI_self = default_send_IPI_self,
  211. .wakeup_cpu = NULL,
  212. .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
  213. .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
  214. .wait_for_init_deassert = default_wait_for_init_deassert,
  215. .smp_callin_clear_local_apic = NULL,
  216. .store_NMI_vector = NULL,
  217. .inquire_remote_apic = default_inquire_remote_apic,
  218. .read = native_apic_mem_read,
  219. .write = native_apic_mem_write,
  220. .icr_read = native_apic_icr_read,
  221. .icr_write = native_apic_icr_write,
  222. .wait_icr_idle = native_apic_wait_icr_idle,
  223. .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
  224. };