apic_numachip.c 8.5 KB

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