numaq_32.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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/mpspec.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_config_processor *m)
  108. {
  109. int quad = translation_table[mpc_record]->trans_quad;
  110. int logical_apicid = generate_logical_apicid(quad, m->mpc_apicid);
  111. printk(KERN_DEBUG "Processor #%d %u:%u APIC version %d (quad %d, apic %d)\n",
  112. m->mpc_apicid,
  113. (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
  114. (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
  115. m->mpc_apicver, quad, logical_apicid);
  116. return logical_apicid;
  117. }
  118. int mp_bus_id_to_node[MAX_MP_BUSSES];
  119. int mp_bus_id_to_local[MAX_MP_BUSSES];
  120. /* x86_quirks member */
  121. static void mpc_oem_bus_info(struct mpc_config_bus *m, char *name)
  122. {
  123. int quad = translation_table[mpc_record]->trans_quad;
  124. int local = translation_table[mpc_record]->trans_local;
  125. mp_bus_id_to_node[m->mpc_busid] = quad;
  126. mp_bus_id_to_local[m->mpc_busid] = local;
  127. printk(KERN_INFO "Bus #%d is %s (node %d)\n",
  128. m->mpc_busid, name, quad);
  129. }
  130. int quad_local_to_mp_bus_id [NR_CPUS/4][4];
  131. /* x86_quirks member */
  132. static void mpc_oem_pci_bus(struct mpc_config_bus *m)
  133. {
  134. int quad = translation_table[mpc_record]->trans_quad;
  135. int local = translation_table[mpc_record]->trans_local;
  136. quad_local_to_mp_bus_id[quad][local] = m->mpc_busid;
  137. }
  138. static void __init MP_translation_info(struct mpc_config_translation *m)
  139. {
  140. printk(KERN_INFO
  141. "Translation: record %d, type %d, quad %d, global %d, local %d\n",
  142. mpc_record, m->trans_type, m->trans_quad, m->trans_global,
  143. m->trans_local);
  144. if (mpc_record >= MAX_MPC_ENTRY)
  145. printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
  146. else
  147. translation_table[mpc_record] = m; /* stash this for later */
  148. if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
  149. node_set_online(m->trans_quad);
  150. }
  151. static int __init mpf_checksum(unsigned char *mp, int len)
  152. {
  153. int sum = 0;
  154. while (len--)
  155. sum += *mp++;
  156. return sum & 0xFF;
  157. }
  158. /*
  159. * Read/parse the MPC oem tables
  160. */
  161. static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable,
  162. unsigned short oemsize)
  163. {
  164. int count = sizeof(*oemtable); /* the header size */
  165. unsigned char *oemptr = ((unsigned char *)oemtable) + count;
  166. mpc_record = 0;
  167. printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n",
  168. oemtable);
  169. if (memcmp(oemtable->oem_signature, MPC_OEM_SIGNATURE, 4)) {
  170. printk(KERN_WARNING
  171. "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
  172. oemtable->oem_signature[0], oemtable->oem_signature[1],
  173. oemtable->oem_signature[2], oemtable->oem_signature[3]);
  174. return;
  175. }
  176. if (mpf_checksum((unsigned char *)oemtable, oemtable->oem_length)) {
  177. printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
  178. return;
  179. }
  180. while (count < oemtable->oem_length) {
  181. switch (*oemptr) {
  182. case MP_TRANSLATION:
  183. {
  184. struct mpc_config_translation *m =
  185. (struct mpc_config_translation *)oemptr;
  186. MP_translation_info(m);
  187. oemptr += sizeof(*m);
  188. count += sizeof(*m);
  189. ++mpc_record;
  190. break;
  191. }
  192. default:
  193. {
  194. printk(KERN_WARNING
  195. "Unrecognised OEM table entry type! - %d\n",
  196. (int)*oemptr);
  197. return;
  198. }
  199. }
  200. }
  201. }
  202. static struct x86_quirks numaq_x86_quirks __initdata = {
  203. .arch_pre_time_init = numaq_pre_time_init,
  204. .arch_time_init = NULL,
  205. .arch_pre_intr_init = NULL,
  206. .arch_memory_setup = NULL,
  207. .arch_intr_init = NULL,
  208. .arch_trap_init = NULL,
  209. .mach_get_smp_config = NULL,
  210. .mach_find_smp_config = NULL,
  211. .mpc_record = &mpc_record,
  212. .mpc_apic_id = mpc_apic_id,
  213. .mpc_oem_bus_info = mpc_oem_bus_info,
  214. .mpc_oem_pci_bus = mpc_oem_pci_bus,
  215. .smp_read_mpc_oem = smp_read_mpc_oem,
  216. };
  217. void numaq_mps_oem_check(struct mp_config_table *mpc, char *oem,
  218. char *productid)
  219. {
  220. if (strncmp(oem, "IBM NUMA", 8))
  221. printk("Warning! Not a NUMA-Q system!\n");
  222. else
  223. found_numaq = 1;
  224. }
  225. static __init void early_check_numaq(void)
  226. {
  227. /*
  228. * Find possible boot-time SMP configuration:
  229. */
  230. early_find_smp_config();
  231. /*
  232. * get boot-time SMP configuration:
  233. */
  234. if (smp_found_config)
  235. early_get_smp_config();
  236. if (found_numaq)
  237. x86_quirks = &numaq_x86_quirks;
  238. }
  239. int __init get_memcfg_numaq(void)
  240. {
  241. early_check_numaq();
  242. if (!found_numaq)
  243. return 0;
  244. smp_dump_qct();
  245. return 1;
  246. }