apic_numachip.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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/errno.h>
  14. #include <linux/threads.h>
  15. #include <linux/cpumask.h>
  16. #include <linux/string.h>
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/ctype.h>
  20. #include <linux/init.h>
  21. #include <linux/hardirq.h>
  22. #include <linux/delay.h>
  23. #include <asm/numachip/numachip_csr.h>
  24. #include <asm/smp.h>
  25. #include <asm/apic.h>
  26. #include <asm/ipi.h>
  27. #include <asm/apic_flat_64.h>
  28. static int numachip_system __read_mostly;
  29. static struct apic apic_numachip __read_mostly;
  30. static unsigned int get_apic_id(unsigned long x)
  31. {
  32. unsigned long value;
  33. unsigned int id;
  34. rdmsrl(MSR_FAM10H_NODE_ID, value);
  35. id = ((x >> 24) & 0xffU) | ((value << 2) & 0x3f00U);
  36. return id;
  37. }
  38. static unsigned long set_apic_id(unsigned int id)
  39. {
  40. unsigned long x;
  41. x = ((id & 0xffU) << 24);
  42. return x;
  43. }
  44. static unsigned int read_xapic_id(void)
  45. {
  46. return get_apic_id(apic_read(APIC_ID));
  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 physid_isset(read_xapic_id(), phys_cpu_present_map);
  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 const struct cpumask *numachip_target_cpus(void)
  62. {
  63. return cpu_online_mask;
  64. }
  65. static void numachip_vector_allocation_domain(int cpu, struct cpumask *retmask)
  66. {
  67. cpumask_clear(retmask);
  68. cpumask_set_cpu(cpu, retmask);
  69. }
  70. static int __cpuinit numachip_wakeup_secondary(int phys_apicid, unsigned long start_rip)
  71. {
  72. union numachip_csr_g3_ext_irq_gen int_gen;
  73. int_gen.s._destination_apic_id = phys_apicid;
  74. int_gen.s._vector = 0;
  75. int_gen.s._msgtype = APIC_DM_INIT >> 8;
  76. int_gen.s._index = 0;
  77. write_lcsr(CSR_G3_EXT_IRQ_GEN, int_gen.v);
  78. int_gen.s._msgtype = APIC_DM_STARTUP >> 8;
  79. int_gen.s._vector = start_rip >> 12;
  80. write_lcsr(CSR_G3_EXT_IRQ_GEN, int_gen.v);
  81. atomic_set(&init_deasserted, 1);
  82. return 0;
  83. }
  84. static void numachip_send_IPI_one(int cpu, int vector)
  85. {
  86. union numachip_csr_g3_ext_irq_gen int_gen;
  87. int apicid = per_cpu(x86_cpu_to_apicid, cpu);
  88. int_gen.s._destination_apic_id = apicid;
  89. int_gen.s._vector = vector;
  90. int_gen.s._msgtype = (vector == NMI_VECTOR ? APIC_DM_NMI : APIC_DM_FIXED) >> 8;
  91. int_gen.s._index = 0;
  92. write_lcsr(CSR_G3_EXT_IRQ_GEN, int_gen.v);
  93. }
  94. static void numachip_send_IPI_mask(const struct cpumask *mask, int vector)
  95. {
  96. unsigned int cpu;
  97. for_each_cpu(cpu, mask)
  98. numachip_send_IPI_one(cpu, vector);
  99. }
  100. static void numachip_send_IPI_mask_allbutself(const struct cpumask *mask,
  101. int vector)
  102. {
  103. unsigned int this_cpu = smp_processor_id();
  104. unsigned int cpu;
  105. for_each_cpu(cpu, mask) {
  106. if (cpu != this_cpu)
  107. numachip_send_IPI_one(cpu, vector);
  108. }
  109. }
  110. static void numachip_send_IPI_allbutself(int vector)
  111. {
  112. unsigned int this_cpu = smp_processor_id();
  113. unsigned int cpu;
  114. for_each_online_cpu(cpu) {
  115. if (cpu != this_cpu)
  116. numachip_send_IPI_one(cpu, vector);
  117. }
  118. }
  119. static void numachip_send_IPI_all(int vector)
  120. {
  121. numachip_send_IPI_mask(cpu_online_mask, vector);
  122. }
  123. static void numachip_send_IPI_self(int vector)
  124. {
  125. __default_send_IPI_shortcut(APIC_DEST_SELF, vector, APIC_DEST_PHYSICAL);
  126. }
  127. static unsigned int numachip_cpu_mask_to_apicid(const struct cpumask *cpumask)
  128. {
  129. int cpu;
  130. /*
  131. * We're using fixed IRQ delivery, can only return one phys APIC ID.
  132. * May as well be the first.
  133. */
  134. cpu = cpumask_first(cpumask);
  135. if (likely((unsigned)cpu < nr_cpu_ids))
  136. return per_cpu(x86_cpu_to_apicid, cpu);
  137. return BAD_APICID;
  138. }
  139. static unsigned int
  140. numachip_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
  141. const struct cpumask *andmask)
  142. {
  143. int cpu;
  144. /*
  145. * We're using fixed IRQ delivery, can only return one phys APIC ID.
  146. * May as well be the first.
  147. */
  148. for_each_cpu_and(cpu, cpumask, andmask) {
  149. if (cpumask_test_cpu(cpu, cpu_online_mask))
  150. break;
  151. }
  152. return per_cpu(x86_cpu_to_apicid, cpu);
  153. }
  154. static int __init numachip_probe(void)
  155. {
  156. return apic == &apic_numachip;
  157. }
  158. static void __init map_csrs(void)
  159. {
  160. printk(KERN_INFO "NumaChip: Mapping local CSR space (%016llx - %016llx)\n",
  161. NUMACHIP_LCSR_BASE, NUMACHIP_LCSR_BASE + NUMACHIP_LCSR_SIZE - 1);
  162. init_extra_mapping_uc(NUMACHIP_LCSR_BASE, NUMACHIP_LCSR_SIZE);
  163. printk(KERN_INFO "NumaChip: Mapping global CSR space (%016llx - %016llx)\n",
  164. NUMACHIP_GCSR_BASE, NUMACHIP_GCSR_BASE + NUMACHIP_GCSR_SIZE - 1);
  165. init_extra_mapping_uc(NUMACHIP_GCSR_BASE, NUMACHIP_GCSR_SIZE);
  166. }
  167. static void fixup_cpu_id(struct cpuinfo_x86 *c, int node)
  168. {
  169. if (c->phys_proc_id != node) {
  170. c->phys_proc_id = node;
  171. per_cpu(cpu_llc_id, smp_processor_id()) = node;
  172. }
  173. }
  174. static int __init numachip_system_init(void)
  175. {
  176. unsigned int val;
  177. if (!numachip_system)
  178. return 0;
  179. x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
  180. map_csrs();
  181. val = read_lcsr(CSR_G0_NODE_IDS);
  182. printk(KERN_INFO "NumaChip: Local NodeID = %08x\n", val);
  183. return 0;
  184. }
  185. early_initcall(numachip_system_init);
  186. static int numachip_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  187. {
  188. if (!strncmp(oem_id, "NUMASC", 6)) {
  189. numachip_system = 1;
  190. return 1;
  191. }
  192. return 0;
  193. }
  194. static struct apic apic_numachip __refconst = {
  195. .name = "NumaConnect system",
  196. .probe = numachip_probe,
  197. .acpi_madt_oem_check = numachip_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 = numachip_target_cpus,
  203. .disable_esr = 0,
  204. .dest_logical = 0,
  205. .check_apicid_used = NULL,
  206. .check_apicid_present = NULL,
  207. .vector_allocation_domain = numachip_vector_allocation_domain,
  208. .init_apic_ldr = flat_init_apic_ldr,
  209. .ioapic_phys_id_map = NULL,
  210. .setup_apic_routing = NULL,
  211. .multi_timer_check = NULL,
  212. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  213. .apicid_to_cpu_present = NULL,
  214. .setup_portio_remap = NULL,
  215. .check_phys_apicid_present = default_check_phys_apicid_present,
  216. .enable_apic_mode = NULL,
  217. .phys_pkg_id = numachip_phys_pkg_id,
  218. .mps_oem_check = NULL,
  219. .get_apic_id = get_apic_id,
  220. .set_apic_id = set_apic_id,
  221. .apic_id_mask = 0xffU << 24,
  222. .cpu_mask_to_apicid = numachip_cpu_mask_to_apicid,
  223. .cpu_mask_to_apicid_and = numachip_cpu_mask_to_apicid_and,
  224. .send_IPI_mask = numachip_send_IPI_mask,
  225. .send_IPI_mask_allbutself = numachip_send_IPI_mask_allbutself,
  226. .send_IPI_allbutself = numachip_send_IPI_allbutself,
  227. .send_IPI_all = numachip_send_IPI_all,
  228. .send_IPI_self = numachip_send_IPI_self,
  229. .wakeup_secondary_cpu = numachip_wakeup_secondary,
  230. .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
  231. .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
  232. .wait_for_init_deassert = NULL,
  233. .smp_callin_clear_local_apic = NULL,
  234. .inquire_remote_apic = NULL, /* REMRD not supported */
  235. .read = native_apic_mem_read,
  236. .write = native_apic_mem_write,
  237. .icr_read = native_apic_icr_read,
  238. .icr_write = native_apic_icr_write,
  239. .wait_icr_idle = native_apic_wait_icr_idle,
  240. .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
  241. };
  242. apic_driver(apic_numachip);