apic_numachip.c 8.5 KB

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