numaq_32.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /*
  2. * Written by: Patricia Gaughen, IBM Corporation
  3. *
  4. * Copyright (C) 2002, IBM Corp.
  5. *
  6. * All rights reserved.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  16. * NON INFRINGEMENT. See the GNU General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. *
  23. * Send feedback to <gone@us.ibm.com>
  24. */
  25. #include <linux/mm.h>
  26. #include <linux/bootmem.h>
  27. #include <linux/mmzone.h>
  28. #include <linux/module.h>
  29. #include <linux/nodemask.h>
  30. #include <asm/numaq.h>
  31. #include <asm/topology.h>
  32. #include <asm/processor.h>
  33. #include <asm/genapic.h>
  34. #include <asm/e820.h>
  35. #include <asm/setup.h>
  36. #define MB_TO_PAGES(addr) ((addr) << (20 - PAGE_SHIFT))
  37. /*
  38. * Function: smp_dump_qct()
  39. *
  40. * Description: gets memory layout from the quad config table. This
  41. * function also updates node_online_map with the nodes (quads) present.
  42. */
  43. static void __init smp_dump_qct(void)
  44. {
  45. int node;
  46. struct eachquadmem *eq;
  47. struct sys_cfg_data *scd =
  48. (struct sys_cfg_data *)__va(SYS_CFG_DATA_PRIV_ADDR);
  49. nodes_clear(node_online_map);
  50. for_each_node(node) {
  51. if (scd->quads_present31_0 & (1 << node)) {
  52. node_set_online(node);
  53. eq = &scd->eq[node];
  54. /* Convert to pages */
  55. node_start_pfn[node] = MB_TO_PAGES(
  56. eq->hi_shrd_mem_start - eq->priv_mem_size);
  57. node_end_pfn[node] = MB_TO_PAGES(
  58. eq->hi_shrd_mem_start + eq->hi_shrd_mem_size);
  59. e820_register_active_regions(node, node_start_pfn[node],
  60. node_end_pfn[node]);
  61. memory_present(node,
  62. node_start_pfn[node], node_end_pfn[node]);
  63. node_remap_size[node] = node_memmap_size_bytes(node,
  64. node_start_pfn[node],
  65. node_end_pfn[node]);
  66. }
  67. }
  68. }
  69. void __cpuinit numaq_tsc_disable(void)
  70. {
  71. if (!found_numaq)
  72. return;
  73. if (num_online_nodes() > 1) {
  74. printk(KERN_DEBUG "NUMAQ: disabling TSC\n");
  75. setup_clear_cpu_cap(X86_FEATURE_TSC);
  76. }
  77. }
  78. static int __init numaq_pre_time_init(void)
  79. {
  80. numaq_tsc_disable();
  81. return 0;
  82. }
  83. int found_numaq;
  84. /*
  85. * Have to match translation table entries to main table entries by counter
  86. * hence the mpc_record variable .... can't see a less disgusting way of
  87. * doing this ....
  88. */
  89. struct mpc_config_translation {
  90. unsigned char mpc_type;
  91. unsigned char trans_len;
  92. unsigned char trans_type;
  93. unsigned char trans_quad;
  94. unsigned char trans_global;
  95. unsigned char trans_local;
  96. unsigned short trans_reserved;
  97. };
  98. /* x86_quirks member */
  99. static int mpc_record;
  100. static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY]
  101. __cpuinitdata;
  102. static inline int generate_logical_apicid(int quad, int phys_apicid)
  103. {
  104. return (quad << 4) + (phys_apicid ? phys_apicid << 1 : 1);
  105. }
  106. /* x86_quirks member */
  107. static int mpc_apic_id(struct mpc_cpu *m)
  108. {
  109. int quad = translation_table[mpc_record]->trans_quad;
  110. int logical_apicid = generate_logical_apicid(quad, m->apicid);
  111. printk(KERN_DEBUG "Processor #%d %u:%u APIC version %d (quad %d, apic %d)\n",
  112. m->apicid, (m->cpufeature & CPU_FAMILY_MASK) >> 8,
  113. (m->cpufeature & CPU_MODEL_MASK) >> 4,
  114. m->apicver, quad, logical_apicid);
  115. return logical_apicid;
  116. }
  117. int mp_bus_id_to_node[MAX_MP_BUSSES];
  118. int mp_bus_id_to_local[MAX_MP_BUSSES];
  119. /* x86_quirks member */
  120. static void mpc_oem_bus_info(struct mpc_bus *m, char *name)
  121. {
  122. int quad = translation_table[mpc_record]->trans_quad;
  123. int local = translation_table[mpc_record]->trans_local;
  124. mp_bus_id_to_node[m->busid] = quad;
  125. mp_bus_id_to_local[m->busid] = local;
  126. printk(KERN_INFO "Bus #%d is %s (node %d)\n",
  127. m->busid, name, quad);
  128. }
  129. int quad_local_to_mp_bus_id [NR_CPUS/4][4];
  130. /* x86_quirks member */
  131. static void mpc_oem_pci_bus(struct mpc_bus *m)
  132. {
  133. int quad = translation_table[mpc_record]->trans_quad;
  134. int local = translation_table[mpc_record]->trans_local;
  135. quad_local_to_mp_bus_id[quad][local] = m->busid;
  136. }
  137. static void __init MP_translation_info(struct mpc_config_translation *m)
  138. {
  139. printk(KERN_INFO
  140. "Translation: record %d, type %d, quad %d, global %d, local %d\n",
  141. mpc_record, m->trans_type, m->trans_quad, m->trans_global,
  142. m->trans_local);
  143. if (mpc_record >= MAX_MPC_ENTRY)
  144. printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
  145. else
  146. translation_table[mpc_record] = m; /* stash this for later */
  147. if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
  148. node_set_online(m->trans_quad);
  149. }
  150. static int __init mpf_checksum(unsigned char *mp, int len)
  151. {
  152. int sum = 0;
  153. while (len--)
  154. sum += *mp++;
  155. return sum & 0xFF;
  156. }
  157. /*
  158. * Read/parse the MPC oem tables
  159. */
  160. static void __init smp_read_mpc_oem(struct mpc_oemtable *oemtable,
  161. unsigned short oemsize)
  162. {
  163. int count = sizeof(*oemtable); /* the header size */
  164. unsigned char *oemptr = ((unsigned char *)oemtable) + count;
  165. mpc_record = 0;
  166. printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n",
  167. oemtable);
  168. if (memcmp(oemtable->signature, MPC_OEM_SIGNATURE, 4)) {
  169. printk(KERN_WARNING
  170. "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
  171. oemtable->signature[0], oemtable->signature[1],
  172. oemtable->signature[2], oemtable->signature[3]);
  173. return;
  174. }
  175. if (mpf_checksum((unsigned char *)oemtable, oemtable->length)) {
  176. printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
  177. return;
  178. }
  179. while (count < oemtable->length) {
  180. switch (*oemptr) {
  181. case MP_TRANSLATION:
  182. {
  183. struct mpc_config_translation *m =
  184. (struct mpc_config_translation *)oemptr;
  185. MP_translation_info(m);
  186. oemptr += sizeof(*m);
  187. count += sizeof(*m);
  188. ++mpc_record;
  189. break;
  190. }
  191. default:
  192. {
  193. printk(KERN_WARNING
  194. "Unrecognised OEM table entry type! - %d\n",
  195. (int)*oemptr);
  196. return;
  197. }
  198. }
  199. }
  200. }
  201. static int __init numaq_setup_ioapic_ids(void)
  202. {
  203. /* so can skip it */
  204. return 1;
  205. }
  206. static int __init numaq_update_genapic(void)
  207. {
  208. genapic->wakeup_cpu = wakeup_secondary_cpu_via_nmi;
  209. return 0;
  210. }
  211. static struct x86_quirks numaq_x86_quirks __initdata = {
  212. .arch_pre_time_init = numaq_pre_time_init,
  213. .arch_time_init = NULL,
  214. .arch_pre_intr_init = NULL,
  215. .arch_memory_setup = NULL,
  216. .arch_intr_init = NULL,
  217. .arch_trap_init = NULL,
  218. .mach_get_smp_config = NULL,
  219. .mach_find_smp_config = NULL,
  220. .mpc_record = &mpc_record,
  221. .mpc_apic_id = mpc_apic_id,
  222. .mpc_oem_bus_info = mpc_oem_bus_info,
  223. .mpc_oem_pci_bus = mpc_oem_pci_bus,
  224. .smp_read_mpc_oem = smp_read_mpc_oem,
  225. .setup_ioapic_ids = numaq_setup_ioapic_ids,
  226. .update_genapic = numaq_update_genapic,
  227. };
  228. void numaq_mps_oem_check(struct mpc_table *mpc, char *oem, char *productid)
  229. {
  230. if (strncmp(oem, "IBM NUMA", 8))
  231. printk("Warning! Not a NUMA-Q system!\n");
  232. else
  233. found_numaq = 1;
  234. }
  235. static __init void early_check_numaq(void)
  236. {
  237. /*
  238. * Find possible boot-time SMP configuration:
  239. */
  240. early_find_smp_config();
  241. /*
  242. * get boot-time SMP configuration:
  243. */
  244. if (smp_found_config)
  245. early_get_smp_config();
  246. if (found_numaq)
  247. x86_quirks = &numaq_x86_quirks;
  248. }
  249. int __init get_memcfg_numaq(void)
  250. {
  251. early_check_numaq();
  252. if (!found_numaq)
  253. return 0;
  254. smp_dump_qct();
  255. return 1;
  256. }