es7000.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /*
  2. * APIC driver for the Unisys ES7000 chipset.
  3. */
  4. #define APIC_DEFINITION 1
  5. #include <linux/threads.h>
  6. #include <linux/cpumask.h>
  7. #include <asm/mpspec.h>
  8. #include <asm/genapic.h>
  9. #include <asm/fixmap.h>
  10. #include <asm/apicdef.h>
  11. #include <linux/kernel.h>
  12. #include <linux/string.h>
  13. #include <linux/init.h>
  14. #include <linux/acpi.h>
  15. #include <linux/smp.h>
  16. #include <asm/ipi.h>
  17. #define APIC_DFR_VALUE_CLUSTER (APIC_DFR_CLUSTER)
  18. #define INT_DELIVERY_MODE_CLUSTER (dest_LowestPrio)
  19. #define INT_DEST_MODE_CLUSTER (1) /* logical delivery broadcast to all procs */
  20. #define APIC_DFR_VALUE (APIC_DFR_FLAT)
  21. extern void es7000_enable_apic_mode(void);
  22. extern int apic_version [MAX_APICS];
  23. extern u8 cpu_2_logical_apicid[];
  24. extern unsigned int boot_cpu_physical_apicid;
  25. extern int parse_unisys_oem (char *oemptr);
  26. extern int find_unisys_acpi_oem_table(unsigned long *oem_addr);
  27. extern void unmap_unisys_acpi_oem_table(unsigned long oem_addr);
  28. extern void setup_unisys(void);
  29. #define apicid_cluster(apicid) (apicid & 0xF0)
  30. #define xapic_phys_to_log_apicid(cpu) per_cpu(x86_bios_cpu_apicid, cpu)
  31. static void es7000_vector_allocation_domain(int cpu, cpumask_t *retmask)
  32. {
  33. /* Careful. Some cpus do not strictly honor the set of cpus
  34. * specified in the interrupt destination when using lowest
  35. * priority interrupt delivery mode.
  36. *
  37. * In particular there was a hyperthreading cpu observed to
  38. * deliver interrupts to the wrong hyperthread when only one
  39. * hyperthread was specified in the interrupt desitination.
  40. */
  41. *retmask = (cpumask_t){ { [0] = APIC_ALL_CPUS, } };
  42. }
  43. static void es7000_wait_for_init_deassert(atomic_t *deassert)
  44. {
  45. #ifndef CONFIG_ES7000_CLUSTERED_APIC
  46. while (!atomic_read(deassert))
  47. cpu_relax();
  48. #endif
  49. return;
  50. }
  51. static unsigned int es7000_get_apic_id(unsigned long x)
  52. {
  53. return (x >> 24) & 0xFF;
  54. }
  55. #ifdef CONFIG_ACPI
  56. static int es7000_check_dsdt(void)
  57. {
  58. struct acpi_table_header header;
  59. if (ACPI_SUCCESS(acpi_get_table_header(ACPI_SIG_DSDT, 0, &header)) &&
  60. !strncmp(header.oem_id, "UNISYS", 6))
  61. return 1;
  62. return 0;
  63. }
  64. #endif
  65. static void es7000_send_IPI_mask(const struct cpumask *mask, int vector)
  66. {
  67. default_send_IPI_mask_sequence(mask, vector);
  68. }
  69. static void es7000_send_IPI_allbutself(int vector)
  70. {
  71. default_send_IPI_mask_allbutself(cpu_online_mask, vector);
  72. }
  73. static void es7000_send_IPI_all(int vector)
  74. {
  75. es7000_send_IPI_mask(cpu_online_mask, vector);
  76. }
  77. static int es7000_apic_id_registered(void)
  78. {
  79. return 1;
  80. }
  81. static const cpumask_t *target_cpus_cluster(void)
  82. {
  83. return &CPU_MASK_ALL;
  84. }
  85. static const cpumask_t *es7000_target_cpus(void)
  86. {
  87. return &cpumask_of_cpu(smp_processor_id());
  88. }
  89. static unsigned long
  90. es7000_check_apicid_used(physid_mask_t bitmap, int apicid)
  91. {
  92. return 0;
  93. }
  94. static unsigned long es7000_check_apicid_present(int bit)
  95. {
  96. return physid_isset(bit, phys_cpu_present_map);
  97. }
  98. static unsigned long calculate_ldr(int cpu)
  99. {
  100. unsigned long id = xapic_phys_to_log_apicid(cpu);
  101. return (SET_APIC_LOGICAL_ID(id));
  102. }
  103. /*
  104. * Set up the logical destination ID.
  105. *
  106. * Intel recommends to set DFR, LdR and TPR before enabling
  107. * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
  108. * document number 292116). So here it goes...
  109. */
  110. static void es7000_init_apic_ldr_cluster(void)
  111. {
  112. unsigned long val;
  113. int cpu = smp_processor_id();
  114. apic_write(APIC_DFR, APIC_DFR_VALUE_CLUSTER);
  115. val = calculate_ldr(cpu);
  116. apic_write(APIC_LDR, val);
  117. }
  118. static void es7000_init_apic_ldr(void)
  119. {
  120. unsigned long val;
  121. int cpu = smp_processor_id();
  122. apic_write(APIC_DFR, APIC_DFR_VALUE);
  123. val = calculate_ldr(cpu);
  124. apic_write(APIC_LDR, val);
  125. }
  126. static void es7000_setup_apic_routing(void)
  127. {
  128. int apic = per_cpu(x86_bios_cpu_apicid, smp_processor_id());
  129. printk("Enabling APIC mode: %s. Using %d I/O APICs, target cpus %lx\n",
  130. (apic_version[apic] == 0x14) ?
  131. "Physical Cluster" : "Logical Cluster",
  132. nr_ioapics, cpus_addr(*es7000_target_cpus())[0]);
  133. }
  134. static int es7000_apicid_to_node(int logical_apicid)
  135. {
  136. return 0;
  137. }
  138. static int es7000_cpu_present_to_apicid(int mps_cpu)
  139. {
  140. if (!mps_cpu)
  141. return boot_cpu_physical_apicid;
  142. else if (mps_cpu < nr_cpu_ids)
  143. return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu);
  144. else
  145. return BAD_APICID;
  146. }
  147. static physid_mask_t es7000_apicid_to_cpu_present(int phys_apicid)
  148. {
  149. static int id = 0;
  150. physid_mask_t mask;
  151. mask = physid_mask_of_physid(id);
  152. ++id;
  153. return mask;
  154. }
  155. /* Mapping from cpu number to logical apicid */
  156. static int es7000_cpu_to_logical_apicid(int cpu)
  157. {
  158. #ifdef CONFIG_SMP
  159. if (cpu >= nr_cpu_ids)
  160. return BAD_APICID;
  161. return (int)cpu_2_logical_apicid[cpu];
  162. #else
  163. return logical_smp_processor_id();
  164. #endif
  165. }
  166. static physid_mask_t es7000_ioapic_phys_id_map(physid_mask_t phys_map)
  167. {
  168. /* For clustered we don't have a good way to do this yet - hack */
  169. return physids_promote(0xff);
  170. }
  171. static int es7000_check_phys_apicid_present(int cpu_physical_apicid)
  172. {
  173. boot_cpu_physical_apicid = read_apic_id();
  174. return (1);
  175. }
  176. static unsigned int
  177. es7000_cpu_mask_to_apicid_cluster(const struct cpumask *cpumask)
  178. {
  179. int cpus_found = 0;
  180. int num_bits_set;
  181. int apicid;
  182. int cpu;
  183. num_bits_set = cpumask_weight(cpumask);
  184. /* Return id to all */
  185. if (num_bits_set == nr_cpu_ids)
  186. return 0xFF;
  187. /*
  188. * The cpus in the mask must all be on the apic cluster. If are not
  189. * on the same apicid cluster return default value of target_cpus():
  190. */
  191. cpu = cpumask_first(cpumask);
  192. apicid = es7000_cpu_to_logical_apicid(cpu);
  193. while (cpus_found < num_bits_set) {
  194. if (cpumask_test_cpu(cpu, cpumask)) {
  195. int new_apicid = es7000_cpu_to_logical_apicid(cpu);
  196. if (apicid_cluster(apicid) !=
  197. apicid_cluster(new_apicid)) {
  198. printk ("%s: Not a valid mask!\n", __func__);
  199. return 0xFF;
  200. }
  201. apicid = new_apicid;
  202. cpus_found++;
  203. }
  204. cpu++;
  205. }
  206. return apicid;
  207. }
  208. static unsigned int es7000_cpu_mask_to_apicid(const cpumask_t *cpumask)
  209. {
  210. int cpus_found = 0;
  211. int num_bits_set;
  212. int apicid;
  213. int cpu;
  214. num_bits_set = cpus_weight(*cpumask);
  215. /* Return id to all */
  216. if (num_bits_set == nr_cpu_ids)
  217. return es7000_cpu_to_logical_apicid(0);
  218. /*
  219. * The cpus in the mask must all be on the apic cluster. If are not
  220. * on the same apicid cluster return default value of target_cpus():
  221. */
  222. cpu = first_cpu(*cpumask);
  223. apicid = es7000_cpu_to_logical_apicid(cpu);
  224. while (cpus_found < num_bits_set) {
  225. if (cpu_isset(cpu, *cpumask)) {
  226. int new_apicid = es7000_cpu_to_logical_apicid(cpu);
  227. if (apicid_cluster(apicid) !=
  228. apicid_cluster(new_apicid)) {
  229. printk ("%s: Not a valid mask!\n", __func__);
  230. return es7000_cpu_to_logical_apicid(0);
  231. }
  232. apicid = new_apicid;
  233. cpus_found++;
  234. }
  235. cpu++;
  236. }
  237. return apicid;
  238. }
  239. static unsigned int
  240. es7000_cpu_mask_to_apicid_and(const struct cpumask *inmask,
  241. const struct cpumask *andmask)
  242. {
  243. int apicid = es7000_cpu_to_logical_apicid(0);
  244. cpumask_var_t cpumask;
  245. if (!alloc_cpumask_var(&cpumask, GFP_ATOMIC))
  246. return apicid;
  247. cpumask_and(cpumask, inmask, andmask);
  248. cpumask_and(cpumask, cpumask, cpu_online_mask);
  249. apicid = es7000_cpu_mask_to_apicid(cpumask);
  250. free_cpumask_var(cpumask);
  251. return apicid;
  252. }
  253. static int es7000_phys_pkg_id(int cpuid_apic, int index_msb)
  254. {
  255. return cpuid_apic >> index_msb;
  256. }
  257. void __init es7000_update_genapic_to_cluster(void)
  258. {
  259. apic->target_cpus = target_cpus_cluster;
  260. apic->irq_delivery_mode = INT_DELIVERY_MODE_CLUSTER;
  261. apic->irq_dest_mode = INT_DEST_MODE_CLUSTER;
  262. apic->init_apic_ldr = es7000_init_apic_ldr_cluster;
  263. apic->cpu_mask_to_apicid = es7000_cpu_mask_to_apicid_cluster;
  264. }
  265. static int probe_es7000(void)
  266. {
  267. /* probed later in mptable/ACPI hooks */
  268. return 0;
  269. }
  270. static __init int
  271. es7000_mps_oem_check(struct mpc_table *mpc, char *oem, char *productid)
  272. {
  273. if (mpc->oemptr) {
  274. struct mpc_oemtable *oem_table =
  275. (struct mpc_oemtable *)mpc->oemptr;
  276. if (!strncmp(oem, "UNISYS", 6))
  277. return parse_unisys_oem((char *)oem_table);
  278. }
  279. return 0;
  280. }
  281. #ifdef CONFIG_ACPI
  282. /* Hook from generic ACPI tables.c */
  283. static int __init es7000_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  284. {
  285. unsigned long oem_addr = 0;
  286. int check_dsdt;
  287. int ret = 0;
  288. /* check dsdt at first to avoid clear fix_map for oem_addr */
  289. check_dsdt = es7000_check_dsdt();
  290. if (!find_unisys_acpi_oem_table(&oem_addr)) {
  291. if (check_dsdt)
  292. ret = parse_unisys_oem((char *)oem_addr);
  293. else {
  294. setup_unisys();
  295. ret = 1;
  296. }
  297. /*
  298. * we need to unmap it
  299. */
  300. unmap_unisys_acpi_oem_table(oem_addr);
  301. }
  302. return ret;
  303. }
  304. #else
  305. static int __init es7000_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  306. {
  307. return 0;
  308. }
  309. #endif
  310. struct genapic apic_es7000 = {
  311. .name = "es7000",
  312. .probe = probe_es7000,
  313. .acpi_madt_oem_check = es7000_acpi_madt_oem_check,
  314. .apic_id_registered = es7000_apic_id_registered,
  315. .irq_delivery_mode = dest_Fixed,
  316. /* phys delivery to target CPUs: */
  317. .irq_dest_mode = 0,
  318. .target_cpus = es7000_target_cpus,
  319. .disable_esr = 1,
  320. .dest_logical = 0,
  321. .check_apicid_used = es7000_check_apicid_used,
  322. .check_apicid_present = es7000_check_apicid_present,
  323. .vector_allocation_domain = es7000_vector_allocation_domain,
  324. .init_apic_ldr = es7000_init_apic_ldr,
  325. .ioapic_phys_id_map = es7000_ioapic_phys_id_map,
  326. .setup_apic_routing = es7000_setup_apic_routing,
  327. .multi_timer_check = NULL,
  328. .apicid_to_node = es7000_apicid_to_node,
  329. .cpu_to_logical_apicid = es7000_cpu_to_logical_apicid,
  330. .cpu_present_to_apicid = es7000_cpu_present_to_apicid,
  331. .apicid_to_cpu_present = es7000_apicid_to_cpu_present,
  332. .setup_portio_remap = NULL,
  333. .check_phys_apicid_present = es7000_check_phys_apicid_present,
  334. .enable_apic_mode = es7000_enable_apic_mode,
  335. .phys_pkg_id = es7000_phys_pkg_id,
  336. .mps_oem_check = es7000_mps_oem_check,
  337. .get_apic_id = es7000_get_apic_id,
  338. .set_apic_id = NULL,
  339. .apic_id_mask = 0xFF << 24,
  340. .cpu_mask_to_apicid = es7000_cpu_mask_to_apicid,
  341. .cpu_mask_to_apicid_and = es7000_cpu_mask_to_apicid_and,
  342. .send_IPI_mask = es7000_send_IPI_mask,
  343. .send_IPI_mask_allbutself = NULL,
  344. .send_IPI_allbutself = es7000_send_IPI_allbutself,
  345. .send_IPI_all = es7000_send_IPI_all,
  346. .send_IPI_self = NULL,
  347. .wakeup_cpu = NULL,
  348. .trampoline_phys_low = 0x467,
  349. .trampoline_phys_high = 0x469,
  350. .wait_for_init_deassert = es7000_wait_for_init_deassert,
  351. /* Nothing to do for most platforms, since cleared by the INIT cycle: */
  352. .smp_callin_clear_local_apic = NULL,
  353. .store_NMI_vector = NULL,
  354. .inquire_remote_apic = default_inquire_remote_apic,
  355. };