apic_numachip.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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.h>
  24. #include <asm/numachip/numachip_csr.h>
  25. #include <asm/smp.h>
  26. #include <asm/apic.h>
  27. #include <asm/ipi.h>
  28. #include <asm/apic_flat_64.h>
  29. #include <asm/pgtable.h>
  30. static int numachip_system __read_mostly;
  31. static const struct apic apic_numachip;
  32. static unsigned int get_apic_id(unsigned long x)
  33. {
  34. unsigned long value;
  35. unsigned int id = (x >> 24) & 0xff;
  36. if (static_cpu_has_safe(X86_FEATURE_NODEID_MSR)) {
  37. rdmsrl(MSR_FAM10H_NODE_ID, value);
  38. id |= (value << 2) & 0xff00;
  39. }
  40. return id;
  41. }
  42. static unsigned long set_apic_id(unsigned int id)
  43. {
  44. unsigned long x;
  45. x = ((id & 0xffU) << 24);
  46. return x;
  47. }
  48. static unsigned int read_xapic_id(void)
  49. {
  50. return get_apic_id(apic_read(APIC_ID));
  51. }
  52. static int numachip_apic_id_valid(int apicid)
  53. {
  54. /* Trust what bootloader passes in MADT */
  55. return 1;
  56. }
  57. static int numachip_apic_id_registered(void)
  58. {
  59. return physid_isset(read_xapic_id(), phys_cpu_present_map);
  60. }
  61. static int numachip_phys_pkg_id(int initial_apic_id, int index_msb)
  62. {
  63. return initial_apic_id >> index_msb;
  64. }
  65. static int numachip_wakeup_secondary(int phys_apicid, unsigned long start_rip)
  66. {
  67. union numachip_csr_g3_ext_irq_gen int_gen;
  68. int_gen.s._destination_apic_id = phys_apicid;
  69. int_gen.s._vector = 0;
  70. int_gen.s._msgtype = APIC_DM_INIT >> 8;
  71. int_gen.s._index = 0;
  72. write_lcsr(CSR_G3_EXT_IRQ_GEN, int_gen.v);
  73. int_gen.s._msgtype = APIC_DM_STARTUP >> 8;
  74. int_gen.s._vector = start_rip >> 12;
  75. write_lcsr(CSR_G3_EXT_IRQ_GEN, int_gen.v);
  76. return 0;
  77. }
  78. static void numachip_send_IPI_one(int cpu, int vector)
  79. {
  80. union numachip_csr_g3_ext_irq_gen int_gen;
  81. int apicid = per_cpu(x86_cpu_to_apicid, cpu);
  82. int_gen.s._destination_apic_id = apicid;
  83. int_gen.s._vector = vector;
  84. int_gen.s._msgtype = (vector == NMI_VECTOR ? APIC_DM_NMI : APIC_DM_FIXED) >> 8;
  85. int_gen.s._index = 0;
  86. write_lcsr(CSR_G3_EXT_IRQ_GEN, int_gen.v);
  87. }
  88. static void numachip_send_IPI_mask(const struct cpumask *mask, int vector)
  89. {
  90. unsigned int cpu;
  91. for_each_cpu(cpu, mask)
  92. numachip_send_IPI_one(cpu, vector);
  93. }
  94. static void numachip_send_IPI_mask_allbutself(const struct cpumask *mask,
  95. int vector)
  96. {
  97. unsigned int this_cpu = smp_processor_id();
  98. unsigned int cpu;
  99. for_each_cpu(cpu, mask) {
  100. if (cpu != this_cpu)
  101. numachip_send_IPI_one(cpu, vector);
  102. }
  103. }
  104. static void numachip_send_IPI_allbutself(int vector)
  105. {
  106. unsigned int this_cpu = smp_processor_id();
  107. unsigned int cpu;
  108. for_each_online_cpu(cpu) {
  109. if (cpu != this_cpu)
  110. numachip_send_IPI_one(cpu, vector);
  111. }
  112. }
  113. static void numachip_send_IPI_all(int vector)
  114. {
  115. numachip_send_IPI_mask(cpu_online_mask, vector);
  116. }
  117. static void numachip_send_IPI_self(int vector)
  118. {
  119. apic_write(APIC_SELF_IPI, vector);
  120. }
  121. static int __init numachip_probe(void)
  122. {
  123. return apic == &apic_numachip;
  124. }
  125. static void fixup_cpu_id(struct cpuinfo_x86 *c, int node)
  126. {
  127. u64 val;
  128. u32 nodes = 1;
  129. this_cpu_write(cpu_llc_id, node);
  130. /* Account for nodes per socket in multi-core-module processors */
  131. if (static_cpu_has_safe(X86_FEATURE_NODEID_MSR)) {
  132. rdmsrl(MSR_FAM10H_NODE_ID, val);
  133. nodes = ((val >> 3) & 7) + 1;
  134. }
  135. c->phys_proc_id = node / nodes;
  136. }
  137. static int __init numachip_system_init(void)
  138. {
  139. if (!numachip_system)
  140. return 0;
  141. init_extra_mapping_uc(NUMACHIP_LCSR_BASE, NUMACHIP_LCSR_SIZE);
  142. init_extra_mapping_uc(NUMACHIP_GCSR_BASE, NUMACHIP_GCSR_SIZE);
  143. x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
  144. x86_init.pci.arch_init = pci_numachip_init;
  145. return 0;
  146. }
  147. early_initcall(numachip_system_init);
  148. static int numachip_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  149. {
  150. if (!strncmp(oem_id, "NUMASC", 6)) {
  151. numachip_system = 1;
  152. return 1;
  153. }
  154. return 0;
  155. }
  156. static const struct apic apic_numachip __refconst = {
  157. .name = "NumaConnect system",
  158. .probe = numachip_probe,
  159. .acpi_madt_oem_check = numachip_acpi_madt_oem_check,
  160. .apic_id_valid = numachip_apic_id_valid,
  161. .apic_id_registered = numachip_apic_id_registered,
  162. .irq_delivery_mode = dest_Fixed,
  163. .irq_dest_mode = 0, /* physical */
  164. .target_cpus = online_target_cpus,
  165. .disable_esr = 0,
  166. .dest_logical = 0,
  167. .check_apicid_used = NULL,
  168. .vector_allocation_domain = default_vector_allocation_domain,
  169. .init_apic_ldr = flat_init_apic_ldr,
  170. .ioapic_phys_id_map = NULL,
  171. .setup_apic_routing = NULL,
  172. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  173. .apicid_to_cpu_present = NULL,
  174. .check_phys_apicid_present = default_check_phys_apicid_present,
  175. .phys_pkg_id = numachip_phys_pkg_id,
  176. .get_apic_id = get_apic_id,
  177. .set_apic_id = set_apic_id,
  178. .apic_id_mask = 0xffU << 24,
  179. .cpu_mask_to_apicid_and = default_cpu_mask_to_apicid_and,
  180. .send_IPI_mask = numachip_send_IPI_mask,
  181. .send_IPI_mask_allbutself = numachip_send_IPI_mask_allbutself,
  182. .send_IPI_allbutself = numachip_send_IPI_allbutself,
  183. .send_IPI_all = numachip_send_IPI_all,
  184. .send_IPI_self = numachip_send_IPI_self,
  185. .wakeup_secondary_cpu = numachip_wakeup_secondary,
  186. .inquire_remote_apic = NULL, /* REMRD not supported */
  187. .read = native_apic_mem_read,
  188. .write = native_apic_mem_write,
  189. .eoi_write = native_apic_mem_write,
  190. .icr_read = native_apic_icr_read,
  191. .icr_write = native_apic_icr_write,
  192. .wait_icr_idle = native_apic_wait_icr_idle,
  193. .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
  194. };
  195. apic_driver(apic_numachip);