apic_numachip.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Numascale NumaConnect-Specific APIC Code
  7. *
  8. * Copyright (C) 2011 Numascale AS. All rights reserved.
  9. *
  10. * Send feedback to <[email protected]>
  11. *
  12. */
  13. #include <linux/types.h>
  14. #include <linux/init.h>
  15. #include <linux/pgtable.h>
  16. #include <asm/numachip/numachip.h>
  17. #include <asm/numachip/numachip_csr.h>
  18. #include "local.h"
  19. u8 numachip_system __read_mostly;
  20. static const struct apic apic_numachip1;
  21. static const struct apic apic_numachip2;
  22. static void (*numachip_apic_icr_write)(int apicid, unsigned int val) __read_mostly;
  23. static unsigned int numachip1_get_apic_id(unsigned long x)
  24. {
  25. unsigned long value;
  26. unsigned int id = (x >> 24) & 0xff;
  27. if (static_cpu_has(X86_FEATURE_NODEID_MSR)) {
  28. rdmsrl(MSR_FAM10H_NODE_ID, value);
  29. id |= (value << 2) & 0xff00;
  30. }
  31. return id;
  32. }
  33. static u32 numachip1_set_apic_id(unsigned int id)
  34. {
  35. return (id & 0xff) << 24;
  36. }
  37. static unsigned int numachip2_get_apic_id(unsigned long x)
  38. {
  39. u64 mcfg;
  40. rdmsrl(MSR_FAM10H_MMIO_CONF_BASE, mcfg);
  41. return ((mcfg >> (28 - 8)) & 0xfff00) | (x >> 24);
  42. }
  43. static u32 numachip2_set_apic_id(unsigned int id)
  44. {
  45. return id << 24;
  46. }
  47. static int numachip_apic_id_valid(u32 apicid)
  48. {
  49. /* Trust what bootloader passes in MADT */
  50. return 1;
  51. }
  52. static int numachip_apic_id_registered(void)
  53. {
  54. return 1;
  55. }
  56. static int numachip_phys_pkg_id(int initial_apic_id, int index_msb)
  57. {
  58. return initial_apic_id >> index_msb;
  59. }
  60. static void numachip1_apic_icr_write(int apicid, unsigned int val)
  61. {
  62. write_lcsr(CSR_G3_EXT_IRQ_GEN, (apicid << 16) | val);
  63. }
  64. static void numachip2_apic_icr_write(int apicid, unsigned int val)
  65. {
  66. numachip2_write32_lcsr(NUMACHIP2_APIC_ICR, (apicid << 12) | val);
  67. }
  68. static int numachip_wakeup_secondary(int phys_apicid, unsigned long start_rip)
  69. {
  70. numachip_apic_icr_write(phys_apicid, APIC_DM_INIT);
  71. numachip_apic_icr_write(phys_apicid, APIC_DM_STARTUP |
  72. (start_rip >> 12));
  73. return 0;
  74. }
  75. static void numachip_send_IPI_one(int cpu, int vector)
  76. {
  77. int local_apicid, apicid = per_cpu(x86_cpu_to_apicid, cpu);
  78. unsigned int dmode;
  79. preempt_disable();
  80. local_apicid = __this_cpu_read(x86_cpu_to_apicid);
  81. /* Send via local APIC where non-local part matches */
  82. if (!((apicid ^ local_apicid) >> NUMACHIP_LAPIC_BITS)) {
  83. unsigned long flags;
  84. local_irq_save(flags);
  85. __default_send_IPI_dest_field(apicid, vector,
  86. APIC_DEST_PHYSICAL);
  87. local_irq_restore(flags);
  88. preempt_enable();
  89. return;
  90. }
  91. preempt_enable();
  92. dmode = (vector == NMI_VECTOR) ? APIC_DM_NMI : APIC_DM_FIXED;
  93. numachip_apic_icr_write(apicid, dmode | vector);
  94. }
  95. static void numachip_send_IPI_mask(const struct cpumask *mask, int vector)
  96. {
  97. unsigned int cpu;
  98. for_each_cpu(cpu, mask)
  99. numachip_send_IPI_one(cpu, vector);
  100. }
  101. static void numachip_send_IPI_mask_allbutself(const struct cpumask *mask,
  102. int vector)
  103. {
  104. unsigned int this_cpu = smp_processor_id();
  105. unsigned int cpu;
  106. for_each_cpu(cpu, mask) {
  107. if (cpu != this_cpu)
  108. numachip_send_IPI_one(cpu, vector);
  109. }
  110. }
  111. static void numachip_send_IPI_allbutself(int vector)
  112. {
  113. unsigned int this_cpu = smp_processor_id();
  114. unsigned int cpu;
  115. for_each_online_cpu(cpu) {
  116. if (cpu != this_cpu)
  117. numachip_send_IPI_one(cpu, vector);
  118. }
  119. }
  120. static void numachip_send_IPI_all(int vector)
  121. {
  122. numachip_send_IPI_mask(cpu_online_mask, vector);
  123. }
  124. static void numachip_send_IPI_self(int vector)
  125. {
  126. apic_write(APIC_SELF_IPI, vector);
  127. }
  128. static int __init numachip1_probe(void)
  129. {
  130. return apic == &apic_numachip1;
  131. }
  132. static int __init numachip2_probe(void)
  133. {
  134. return apic == &apic_numachip2;
  135. }
  136. static void fixup_cpu_id(struct cpuinfo_x86 *c, int node)
  137. {
  138. u64 val;
  139. u32 nodes = 1;
  140. this_cpu_write(cpu_llc_id, node);
  141. /* Account for nodes per socket in multi-core-module processors */
  142. if (boot_cpu_has(X86_FEATURE_NODEID_MSR)) {
  143. rdmsrl(MSR_FAM10H_NODE_ID, val);
  144. nodes = ((val >> 3) & 7) + 1;
  145. }
  146. c->phys_proc_id = node / nodes;
  147. }
  148. static int __init numachip_system_init(void)
  149. {
  150. /* Map the LCSR area and set up the apic_icr_write function */
  151. switch (numachip_system) {
  152. case 1:
  153. init_extra_mapping_uc(NUMACHIP_LCSR_BASE, NUMACHIP_LCSR_SIZE);
  154. numachip_apic_icr_write = numachip1_apic_icr_write;
  155. break;
  156. case 2:
  157. init_extra_mapping_uc(NUMACHIP2_LCSR_BASE, NUMACHIP2_LCSR_SIZE);
  158. numachip_apic_icr_write = numachip2_apic_icr_write;
  159. break;
  160. default:
  161. return 0;
  162. }
  163. x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
  164. x86_init.pci.arch_init = pci_numachip_init;
  165. return 0;
  166. }
  167. early_initcall(numachip_system_init);
  168. static int numachip1_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  169. {
  170. if ((strncmp(oem_id, "NUMASC", 6) != 0) ||
  171. (strncmp(oem_table_id, "NCONNECT", 8) != 0))
  172. return 0;
  173. numachip_system = 1;
  174. return 1;
  175. }
  176. static int numachip2_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  177. {
  178. if ((strncmp(oem_id, "NUMASC", 6) != 0) ||
  179. (strncmp(oem_table_id, "NCONECT2", 8) != 0))
  180. return 0;
  181. numachip_system = 2;
  182. return 1;
  183. }
  184. /* APIC IPIs are queued */
  185. static void numachip_apic_wait_icr_idle(void)
  186. {
  187. }
  188. /* APIC NMI IPIs are queued */
  189. static u32 numachip_safe_apic_wait_icr_idle(void)
  190. {
  191. return 0;
  192. }
  193. static const struct apic apic_numachip1 __refconst = {
  194. .name = "NumaConnect system",
  195. .probe = numachip1_probe,
  196. .acpi_madt_oem_check = numachip1_acpi_madt_oem_check,
  197. .apic_id_valid = numachip_apic_id_valid,
  198. .apic_id_registered = numachip_apic_id_registered,
  199. .delivery_mode = APIC_DELIVERY_MODE_FIXED,
  200. .dest_mode_logical = false,
  201. .disable_esr = 0,
  202. .check_apicid_used = NULL,
  203. .init_apic_ldr = flat_init_apic_ldr,
  204. .ioapic_phys_id_map = NULL,
  205. .setup_apic_routing = NULL,
  206. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  207. .apicid_to_cpu_present = NULL,
  208. .check_phys_apicid_present = default_check_phys_apicid_present,
  209. .phys_pkg_id = numachip_phys_pkg_id,
  210. .get_apic_id = numachip1_get_apic_id,
  211. .set_apic_id = numachip1_set_apic_id,
  212. .calc_dest_apicid = apic_default_calc_apicid,
  213. .send_IPI = numachip_send_IPI_one,
  214. .send_IPI_mask = numachip_send_IPI_mask,
  215. .send_IPI_mask_allbutself = numachip_send_IPI_mask_allbutself,
  216. .send_IPI_allbutself = numachip_send_IPI_allbutself,
  217. .send_IPI_all = numachip_send_IPI_all,
  218. .send_IPI_self = numachip_send_IPI_self,
  219. .wakeup_secondary_cpu = numachip_wakeup_secondary,
  220. .inquire_remote_apic = NULL, /* REMRD not supported */
  221. .read = native_apic_mem_read,
  222. .write = native_apic_mem_write,
  223. .eoi_write = native_apic_mem_write,
  224. .icr_read = native_apic_icr_read,
  225. .icr_write = native_apic_icr_write,
  226. .wait_icr_idle = numachip_apic_wait_icr_idle,
  227. .safe_wait_icr_idle = numachip_safe_apic_wait_icr_idle,
  228. };
  229. apic_driver(apic_numachip1);
  230. static const struct apic apic_numachip2 __refconst = {
  231. .name = "NumaConnect2 system",
  232. .probe = numachip2_probe,
  233. .acpi_madt_oem_check = numachip2_acpi_madt_oem_check,
  234. .apic_id_valid = numachip_apic_id_valid,
  235. .apic_id_registered = numachip_apic_id_registered,
  236. .delivery_mode = APIC_DELIVERY_MODE_FIXED,
  237. .dest_mode_logical = false,
  238. .disable_esr = 0,
  239. .check_apicid_used = NULL,
  240. .init_apic_ldr = flat_init_apic_ldr,
  241. .ioapic_phys_id_map = NULL,
  242. .setup_apic_routing = NULL,
  243. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  244. .apicid_to_cpu_present = NULL,
  245. .check_phys_apicid_present = default_check_phys_apicid_present,
  246. .phys_pkg_id = numachip_phys_pkg_id,
  247. .get_apic_id = numachip2_get_apic_id,
  248. .set_apic_id = numachip2_set_apic_id,
  249. .calc_dest_apicid = apic_default_calc_apicid,
  250. .send_IPI = numachip_send_IPI_one,
  251. .send_IPI_mask = numachip_send_IPI_mask,
  252. .send_IPI_mask_allbutself = numachip_send_IPI_mask_allbutself,
  253. .send_IPI_allbutself = numachip_send_IPI_allbutself,
  254. .send_IPI_all = numachip_send_IPI_all,
  255. .send_IPI_self = numachip_send_IPI_self,
  256. .wakeup_secondary_cpu = numachip_wakeup_secondary,
  257. .inquire_remote_apic = NULL, /* REMRD not supported */
  258. .read = native_apic_mem_read,
  259. .write = native_apic_mem_write,
  260. .eoi_write = native_apic_mem_write,
  261. .icr_read = native_apic_icr_read,
  262. .icr_write = native_apic_icr_write,
  263. .wait_icr_idle = numachip_apic_wait_icr_idle,
  264. .safe_wait_icr_idle = numachip_safe_apic_wait_icr_idle,
  265. };
  266. apic_driver(apic_numachip2);