Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Written by: Patricia Gaughen, IBM Corporation |
| 3 | * |
| 4 | * Copyright (C) 2002, IBM Corp. |
Ingo Molnar | cb81eae | 2009-02-17 17:53:54 +0100 | [diff] [blame] | 5 | * Copyright (C) 2009, Red Hat, Inc., Ingo Molnar |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
Ingo Molnar | 4f179d1 | 2009-02-01 11:25:57 +0100 | [diff] [blame] | 7 | * All rights reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 17 | * NON INFRINGEMENT. See the GNU General Public License for more |
| 18 | * details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | * |
| 24 | * Send feedback to <gone@us.ibm.com> |
| 25 | */ |
Ingo Molnar | 4f179d1 | 2009-02-01 11:25:57 +0100 | [diff] [blame] | 26 | #include <linux/nodemask.h> |
Ingo Molnar | cb81eae | 2009-02-17 17:53:54 +0100 | [diff] [blame] | 27 | #include <linux/topology.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/bootmem.h> |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 29 | #include <linux/threads.h> |
| 30 | #include <linux/cpumask.h> |
| 31 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/mmzone.h> |
| 33 | #include <linux/module.h> |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 34 | #include <linux/string.h> |
| 35 | #include <linux/init.h> |
| 36 | #include <linux/numa.h> |
| 37 | #include <linux/smp.h> |
Ingo Molnar | cb81eae | 2009-02-17 17:53:54 +0100 | [diff] [blame] | 38 | #include <linux/io.h> |
Ingo Molnar | 4f179d1 | 2009-02-01 11:25:57 +0100 | [diff] [blame] | 39 | #include <linux/mm.h> |
| 40 | |
Dave Hansen | e1474e2 | 2005-07-28 21:16:18 -0700 | [diff] [blame] | 41 | #include <asm/processor.h> |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 42 | #include <asm/fixmap.h> |
| 43 | #include <asm/mpspec.h> |
Ingo Molnar | 4f179d1 | 2009-02-01 11:25:57 +0100 | [diff] [blame] | 44 | #include <asm/numaq.h> |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 45 | #include <asm/setup.h> |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 46 | #include <asm/apic.h> |
Ingo Molnar | 4f179d1 | 2009-02-01 11:25:57 +0100 | [diff] [blame] | 47 | #include <asm/e820.h> |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 48 | #include <asm/ipi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 50 | #define MB_TO_PAGES(addr) ((addr) << (20 - PAGE_SHIFT)) |
| 51 | |
Ingo Molnar | cb81eae | 2009-02-17 17:53:54 +0100 | [diff] [blame] | 52 | int found_numaq; |
| 53 | |
| 54 | /* |
| 55 | * Have to match translation table entries to main table entries by counter |
| 56 | * hence the mpc_record variable .... can't see a less disgusting way of |
| 57 | * doing this .... |
| 58 | */ |
| 59 | struct mpc_trans { |
| 60 | unsigned char mpc_type; |
| 61 | unsigned char trans_len; |
| 62 | unsigned char trans_type; |
| 63 | unsigned char trans_quad; |
| 64 | unsigned char trans_global; |
| 65 | unsigned char trans_local; |
| 66 | unsigned short trans_reserved; |
| 67 | }; |
| 68 | |
Ingo Molnar | cb81eae | 2009-02-17 17:53:54 +0100 | [diff] [blame] | 69 | static int mpc_record; |
| 70 | |
Jiri Slaby | b6122b3 | 2009-03-02 11:34:29 +0100 | [diff] [blame] | 71 | static struct mpc_trans *translation_table[MAX_MPC_ENTRY]; |
Ingo Molnar | cb81eae | 2009-02-17 17:53:54 +0100 | [diff] [blame] | 72 | |
| 73 | int mp_bus_id_to_node[MAX_MP_BUSSES]; |
| 74 | int mp_bus_id_to_local[MAX_MP_BUSSES]; |
| 75 | int quad_local_to_mp_bus_id[NR_CPUS/4][4]; |
| 76 | |
| 77 | |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 78 | static inline void numaq_register_node(int node, struct sys_cfg_data *scd) |
| 79 | { |
| 80 | struct eachquadmem *eq = scd->eq + node; |
| 81 | |
| 82 | node_set_online(node); |
| 83 | |
| 84 | /* Convert to pages */ |
| 85 | node_start_pfn[node] = |
| 86 | MB_TO_PAGES(eq->hi_shrd_mem_start - eq->priv_mem_size); |
| 87 | |
| 88 | node_end_pfn[node] = |
| 89 | MB_TO_PAGES(eq->hi_shrd_mem_start + eq->hi_shrd_mem_size); |
| 90 | |
| 91 | e820_register_active_regions(node, node_start_pfn[node], |
| 92 | node_end_pfn[node]); |
| 93 | |
| 94 | memory_present(node, node_start_pfn[node], node_end_pfn[node]); |
| 95 | |
| 96 | node_remap_size[node] = node_memmap_size_bytes(node, |
| 97 | node_start_pfn[node], |
| 98 | node_end_pfn[node]); |
| 99 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | /* |
| 102 | * Function: smp_dump_qct() |
| 103 | * |
| 104 | * Description: gets memory layout from the quad config table. This |
| 105 | * function also updates node_online_map with the nodes (quads) present. |
| 106 | */ |
| 107 | static void __init smp_dump_qct(void) |
| 108 | { |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 109 | struct sys_cfg_data *scd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | int node; |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 111 | |
| 112 | scd = (void *)__va(SYS_CFG_DATA_PRIV_ADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | nodes_clear(node_online_map); |
| 115 | for_each_node(node) { |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 116 | if (scd->quads_present31_0 & (1 << node)) |
| 117 | numaq_register_node(node, scd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
Vegard Nossum | b2a6a58 | 2008-08-20 18:18:26 +0200 | [diff] [blame] | 121 | void __cpuinit numaq_tsc_disable(void) |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 122 | { |
| 123 | if (!found_numaq) |
| 124 | return; |
| 125 | |
| 126 | if (num_online_nodes() > 1) { |
| 127 | printk(KERN_DEBUG "NUMAQ: disabling TSC\n"); |
| 128 | setup_clear_cpu_cap(X86_FEATURE_TSC); |
| 129 | } |
| 130 | } |
| 131 | |
Yinghai Lu | 63b5d7a | 2008-07-19 18:02:26 -0700 | [diff] [blame] | 132 | static int __init numaq_pre_time_init(void) |
| 133 | { |
| 134 | numaq_tsc_disable(); |
| 135 | return 0; |
| 136 | } |
| 137 | |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 138 | static inline int generate_logical_apicid(int quad, int phys_apicid) |
| 139 | { |
| 140 | return (quad << 4) + (phys_apicid ? phys_apicid << 1 : 1); |
| 141 | } |
| 142 | |
| 143 | /* x86_quirks member */ |
Jaswinder Singh Rajput | f4f21b7 | 2009-01-03 15:48:52 +0530 | [diff] [blame] | 144 | static int mpc_apic_id(struct mpc_cpu *m) |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 145 | { |
| 146 | int quad = translation_table[mpc_record]->trans_quad; |
Jaswinder Singh Rajput | c456382 | 2009-01-04 21:58:25 +0530 | [diff] [blame] | 147 | int logical_apicid = generate_logical_apicid(quad, m->apicid); |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 148 | |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 149 | printk(KERN_DEBUG |
| 150 | "Processor #%d %u:%u APIC version %d (quad %d, apic %d)\n", |
| 151 | m->apicid, (m->cpufeature & CPU_FAMILY_MASK) >> 8, |
| 152 | (m->cpufeature & CPU_MODEL_MASK) >> 4, |
| 153 | m->apicver, quad, logical_apicid); |
| 154 | |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 155 | return logical_apicid; |
| 156 | } |
| 157 | |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 158 | /* x86_quirks member */ |
Jaswinder Singh Rajput | 00fb860 | 2009-01-03 15:47:32 +0530 | [diff] [blame] | 159 | static void mpc_oem_bus_info(struct mpc_bus *m, char *name) |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 160 | { |
| 161 | int quad = translation_table[mpc_record]->trans_quad; |
| 162 | int local = translation_table[mpc_record]->trans_local; |
| 163 | |
Jaswinder Singh Rajput | d4c715f | 2009-01-04 21:59:26 +0530 | [diff] [blame] | 164 | mp_bus_id_to_node[m->busid] = quad; |
| 165 | mp_bus_id_to_local[m->busid] = local; |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 166 | |
| 167 | printk(KERN_INFO "Bus #%d is %s (node %d)\n", m->busid, name, quad); |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 170 | /* x86_quirks member */ |
Jaswinder Singh Rajput | 00fb860 | 2009-01-03 15:47:32 +0530 | [diff] [blame] | 171 | static void mpc_oem_pci_bus(struct mpc_bus *m) |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 172 | { |
| 173 | int quad = translation_table[mpc_record]->trans_quad; |
| 174 | int local = translation_table[mpc_record]->trans_local; |
| 175 | |
Jaswinder Singh Rajput | d4c715f | 2009-01-04 21:59:26 +0530 | [diff] [blame] | 176 | quad_local_to_mp_bus_id[quad][local] = m->busid; |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Thomas Gleixner | f484847 | 2009-08-20 12:05:01 +0200 | [diff] [blame] | 179 | /* |
| 180 | * Called from mpparse code. |
| 181 | * mode = 0: prescan |
| 182 | * mode = 1: one mpc entry scanned |
| 183 | */ |
| 184 | static void numaq_mpc_record(unsigned int mode) |
| 185 | { |
| 186 | if (!mode) |
| 187 | mpc_record = 0; |
| 188 | else |
| 189 | mpc_record++; |
| 190 | } |
| 191 | |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 192 | static void __init MP_translation_info(struct mpc_trans *m) |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 193 | { |
| 194 | printk(KERN_INFO |
Ingo Molnar | cb81eae | 2009-02-17 17:53:54 +0100 | [diff] [blame] | 195 | "Translation: record %d, type %d, quad %d, global %d, local %d\n", |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 196 | mpc_record, m->trans_type, m->trans_quad, m->trans_global, |
| 197 | m->trans_local); |
| 198 | |
| 199 | if (mpc_record >= MAX_MPC_ENTRY) |
| 200 | printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n"); |
| 201 | else |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 202 | translation_table[mpc_record] = m; /* stash this for later */ |
| 203 | |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 204 | if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad)) |
| 205 | node_set_online(m->trans_quad); |
| 206 | } |
| 207 | |
| 208 | static int __init mpf_checksum(unsigned char *mp, int len) |
| 209 | { |
| 210 | int sum = 0; |
| 211 | |
| 212 | while (len--) |
| 213 | sum += *mp++; |
| 214 | |
| 215 | return sum & 0xFF; |
| 216 | } |
| 217 | |
| 218 | /* |
| 219 | * Read/parse the MPC oem tables |
| 220 | */ |
Thomas Gleixner | 7230214 | 2009-08-20 12:18:32 +0200 | [diff] [blame] | 221 | static void __init smp_read_mpc_oem(struct mpc_table *mpc) |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 222 | { |
Thomas Gleixner | 7230214 | 2009-08-20 12:18:32 +0200 | [diff] [blame] | 223 | struct mpc_oemtable *oemtable = (void *)(long)mpc->oemptr; |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 224 | int count = sizeof(*oemtable); /* the header size */ |
| 225 | unsigned char *oemptr = ((unsigned char *)oemtable) + count; |
| 226 | |
| 227 | mpc_record = 0; |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 228 | printk(KERN_INFO |
| 229 | "Found an OEM MPC table at %8p - parsing it ... \n", oemtable); |
| 230 | |
Jaswinder Singh Rajput | a1d0272 | 2009-01-04 22:00:46 +0530 | [diff] [blame] | 231 | if (memcmp(oemtable->signature, MPC_OEM_SIGNATURE, 4)) { |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 232 | printk(KERN_WARNING |
| 233 | "SMP mpc oemtable: bad signature [%c%c%c%c]!\n", |
Jaswinder Singh Rajput | a1d0272 | 2009-01-04 22:00:46 +0530 | [diff] [blame] | 234 | oemtable->signature[0], oemtable->signature[1], |
| 235 | oemtable->signature[2], oemtable->signature[3]); |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 236 | return; |
| 237 | } |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 238 | |
Jaswinder Singh Rajput | a1d0272 | 2009-01-04 22:00:46 +0530 | [diff] [blame] | 239 | if (mpf_checksum((unsigned char *)oemtable, oemtable->length)) { |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 240 | printk(KERN_WARNING "SMP oem mptable: checksum error!\n"); |
| 241 | return; |
| 242 | } |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 243 | |
Jaswinder Singh Rajput | a1d0272 | 2009-01-04 22:00:46 +0530 | [diff] [blame] | 244 | while (count < oemtable->length) { |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 245 | switch (*oemptr) { |
| 246 | case MP_TRANSLATION: |
| 247 | { |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 248 | struct mpc_trans *m = (void *)oemptr; |
| 249 | |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 250 | MP_translation_info(m); |
| 251 | oemptr += sizeof(*m); |
| 252 | count += sizeof(*m); |
| 253 | ++mpc_record; |
| 254 | break; |
| 255 | } |
| 256 | default: |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 257 | printk(KERN_WARNING |
| 258 | "Unrecognised OEM table entry type! - %d\n", |
| 259 | (int)*oemptr); |
| 260 | return; |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | static struct x86_quirks numaq_x86_quirks __initdata = { |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 266 | .arch_pre_time_init = numaq_pre_time_init, |
| 267 | .arch_time_init = NULL, |
| 268 | .arch_pre_intr_init = NULL, |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 269 | .arch_intr_init = NULL, |
| 270 | .arch_trap_init = NULL, |
| 271 | .mach_get_smp_config = NULL, |
| 272 | .mach_find_smp_config = NULL, |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 273 | }; |
| 274 | |
Yinghai Lu | ab530e1 | 2008-06-03 10:25:54 -0700 | [diff] [blame] | 275 | static __init void early_check_numaq(void) |
| 276 | { |
| 277 | /* |
| 278 | * Find possible boot-time SMP configuration: |
| 279 | */ |
| 280 | early_find_smp_config(); |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 281 | |
Yinghai Lu | ab530e1 | 2008-06-03 10:25:54 -0700 | [diff] [blame] | 282 | /* |
| 283 | * get boot-time SMP configuration: |
| 284 | */ |
| 285 | if (smp_found_config) |
| 286 | early_get_smp_config(); |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 287 | |
Thomas Gleixner | f484847 | 2009-08-20 12:05:01 +0200 | [diff] [blame] | 288 | if (found_numaq) { |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 289 | x86_quirks = &numaq_x86_quirks; |
Thomas Gleixner | f484847 | 2009-08-20 12:05:01 +0200 | [diff] [blame] | 290 | x86_init.mpparse.mpc_record = numaq_mpc_record; |
Thomas Gleixner | de93410 | 2009-08-20 09:27:29 +0200 | [diff] [blame] | 291 | x86_init.mpparse.setup_ioapic_ids = x86_init_noop; |
Thomas Gleixner | fd6c666 | 2009-08-20 10:41:58 +0200 | [diff] [blame] | 292 | x86_init.mpparse.mpc_apic_id = mpc_apic_id; |
Thomas Gleixner | 7230214 | 2009-08-20 12:18:32 +0200 | [diff] [blame] | 293 | x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem; |
Thomas Gleixner | 52fdb56 | 2009-08-20 12:45:33 +0200 | [diff] [blame] | 294 | x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus; |
Thomas Gleixner | 90e1c69 | 2009-08-20 12:34:47 +0200 | [diff] [blame^] | 295 | x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info; |
Thomas Gleixner | f484847 | 2009-08-20 12:05:01 +0200 | [diff] [blame] | 296 | } |
Yinghai Lu | ab530e1 | 2008-06-03 10:25:54 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | int __init get_memcfg_numaq(void) |
| 300 | { |
Yinghai Lu | ab530e1 | 2008-06-03 10:25:54 -0700 | [diff] [blame] | 301 | early_check_numaq(); |
| 302 | if (!found_numaq) |
| 303 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | smp_dump_qct(); |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | return 1; |
| 307 | } |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 308 | |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 309 | #define NUMAQ_APIC_DFR_VALUE (APIC_DFR_CLUSTER) |
| 310 | |
| 311 | static inline unsigned int numaq_get_apic_id(unsigned long x) |
| 312 | { |
| 313 | return (x >> 24) & 0x0F; |
| 314 | } |
| 315 | |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 316 | static inline void numaq_send_IPI_mask(const struct cpumask *mask, int vector) |
| 317 | { |
Yinghai Lu | 43f3989 | 2009-01-29 19:31:49 -0800 | [diff] [blame] | 318 | default_send_IPI_mask_sequence_logical(mask, vector); |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | static inline void numaq_send_IPI_allbutself(int vector) |
| 322 | { |
Yinghai Lu | 43f3989 | 2009-01-29 19:31:49 -0800 | [diff] [blame] | 323 | default_send_IPI_mask_allbutself_logical(cpu_online_mask, vector); |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | static inline void numaq_send_IPI_all(int vector) |
| 327 | { |
| 328 | numaq_send_IPI_mask(cpu_online_mask, vector); |
| 329 | } |
| 330 | |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 331 | #define NUMAQ_TRAMPOLINE_PHYS_LOW (0x8) |
| 332 | #define NUMAQ_TRAMPOLINE_PHYS_HIGH (0xa) |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 333 | |
| 334 | /* |
| 335 | * Because we use NMIs rather than the INIT-STARTUP sequence to |
| 336 | * bootstrap the CPUs, the APIC may be in a weird state. Kick it: |
| 337 | */ |
| 338 | static inline void numaq_smp_callin_clear_local_apic(void) |
| 339 | { |
| 340 | clear_local_APIC(); |
| 341 | } |
| 342 | |
Rusty Russell | 73e907d | 2009-03-13 14:49:57 +1030 | [diff] [blame] | 343 | static inline const struct cpumask *numaq_target_cpus(void) |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 344 | { |
Rusty Russell | 101aaca | 2009-03-13 14:49:47 +1030 | [diff] [blame] | 345 | return cpu_all_mask; |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | static inline unsigned long |
| 349 | numaq_check_apicid_used(physid_mask_t bitmap, int apicid) |
| 350 | { |
| 351 | return physid_isset(apicid, bitmap); |
| 352 | } |
| 353 | |
| 354 | static inline unsigned long numaq_check_apicid_present(int bit) |
| 355 | { |
| 356 | return physid_isset(bit, phys_cpu_present_map); |
| 357 | } |
| 358 | |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 359 | static inline int numaq_apic_id_registered(void) |
| 360 | { |
| 361 | return 1; |
| 362 | } |
| 363 | |
| 364 | static inline void numaq_init_apic_ldr(void) |
| 365 | { |
| 366 | /* Already done in NUMA-Q firmware */ |
| 367 | } |
| 368 | |
| 369 | static inline void numaq_setup_apic_routing(void) |
| 370 | { |
Ingo Molnar | cb81eae | 2009-02-17 17:53:54 +0100 | [diff] [blame] | 371 | printk(KERN_INFO |
| 372 | "Enabling APIC mode: NUMA-Q. Using %d I/O APICs\n", |
| 373 | nr_ioapics); |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | /* |
| 377 | * Skip adding the timer int on secondary nodes, which causes |
| 378 | * a small but painful rift in the time-space continuum. |
| 379 | */ |
| 380 | static inline int numaq_multi_timer_check(int apic, int irq) |
| 381 | { |
| 382 | return apic != 0 && irq == 0; |
| 383 | } |
| 384 | |
| 385 | static inline physid_mask_t numaq_ioapic_phys_id_map(physid_mask_t phys_map) |
| 386 | { |
| 387 | /* We don't have a good way to do this yet - hack */ |
| 388 | return physids_promote(0xFUL); |
| 389 | } |
| 390 | |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 391 | static inline int numaq_cpu_to_logical_apicid(int cpu) |
| 392 | { |
| 393 | if (cpu >= nr_cpu_ids) |
| 394 | return BAD_APICID; |
Ingo Molnar | 2f205bc | 2009-02-17 14:45:30 +0100 | [diff] [blame] | 395 | return cpu_2_logical_apicid[cpu]; |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | /* |
| 399 | * Supporting over 60 cpus on NUMA-Q requires a locality-dependent |
| 400 | * cpu to APIC ID relation to properly interact with the intelligent |
| 401 | * mode of the cluster controller. |
| 402 | */ |
| 403 | static inline int numaq_cpu_present_to_apicid(int mps_cpu) |
| 404 | { |
| 405 | if (mps_cpu < 60) |
| 406 | return ((mps_cpu >> 2) << 4) | (1 << (mps_cpu & 0x3)); |
| 407 | else |
| 408 | return BAD_APICID; |
| 409 | } |
| 410 | |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 411 | static inline int numaq_apicid_to_node(int logical_apicid) |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 412 | { |
| 413 | return logical_apicid >> 4; |
| 414 | } |
| 415 | |
| 416 | static inline physid_mask_t numaq_apicid_to_cpu_present(int logical_apicid) |
| 417 | { |
| 418 | int node = numaq_apicid_to_node(logical_apicid); |
| 419 | int cpu = __ffs(logical_apicid & 0xf); |
| 420 | |
| 421 | return physid_mask_of_physid(cpu + 4*node); |
| 422 | } |
| 423 | |
Ingo Molnar | 4f179d1 | 2009-02-01 11:25:57 +0100 | [diff] [blame] | 424 | /* Where the IO area was mapped on multiquad, always 0 otherwise */ |
| 425 | void *xquad_portio; |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 426 | |
| 427 | static inline int numaq_check_phys_apicid_present(int boot_cpu_physical_apicid) |
| 428 | { |
| 429 | return 1; |
| 430 | } |
| 431 | |
| 432 | /* |
| 433 | * We use physical apicids here, not logical, so just return the default |
| 434 | * physical broadcast to stop people from breaking us |
| 435 | */ |
Rusty Russell | 73e907d | 2009-03-13 14:49:57 +1030 | [diff] [blame] | 436 | static unsigned int numaq_cpu_mask_to_apicid(const struct cpumask *cpumask) |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 437 | { |
| 438 | return 0x0F; |
| 439 | } |
| 440 | |
| 441 | static inline unsigned int |
| 442 | numaq_cpu_mask_to_apicid_and(const struct cpumask *cpumask, |
| 443 | const struct cpumask *andmask) |
| 444 | { |
| 445 | return 0x0F; |
| 446 | } |
| 447 | |
| 448 | /* No NUMA-Q box has a HT CPU, but it can't hurt to use the default code. */ |
| 449 | static inline int numaq_phys_pkg_id(int cpuid_apic, int index_msb) |
| 450 | { |
| 451 | return cpuid_apic >> index_msb; |
| 452 | } |
Ingo Molnar | 36afc3a | 2009-02-17 15:50:25 +0100 | [diff] [blame] | 453 | |
| 454 | static int |
Ingo Molnar | cb81eae | 2009-02-17 17:53:54 +0100 | [diff] [blame] | 455 | numaq_mps_oem_check(struct mpc_table *mpc, char *oem, char *productid) |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 456 | { |
Ingo Molnar | cb81eae | 2009-02-17 17:53:54 +0100 | [diff] [blame] | 457 | if (strncmp(oem, "IBM NUMA", 8)) |
| 458 | printk(KERN_ERR "Warning! Not a NUMA-Q system!\n"); |
| 459 | else |
| 460 | found_numaq = 1; |
| 461 | |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 462 | return found_numaq; |
| 463 | } |
| 464 | |
| 465 | static int probe_numaq(void) |
| 466 | { |
| 467 | /* already know from get_memcfg_numaq() */ |
| 468 | return found_numaq; |
| 469 | } |
| 470 | |
Rusty Russell | 73e907d | 2009-03-13 14:49:57 +1030 | [diff] [blame] | 471 | static void numaq_vector_allocation_domain(int cpu, struct cpumask *retmask) |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 472 | { |
| 473 | /* Careful. Some cpus do not strictly honor the set of cpus |
| 474 | * specified in the interrupt destination when using lowest |
| 475 | * priority interrupt delivery mode. |
| 476 | * |
| 477 | * In particular there was a hyperthreading cpu observed to |
| 478 | * deliver interrupts to the wrong hyperthread when only one |
| 479 | * hyperthread was specified in the interrupt desitination. |
| 480 | */ |
Rusty Russell | 5c6cb5e | 2009-03-13 14:49:56 +1030 | [diff] [blame] | 481 | cpumask_clear(retmask); |
| 482 | cpumask_bits(retmask)[0] = APIC_ALL_CPUS; |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | static void numaq_setup_portio_remap(void) |
| 486 | { |
| 487 | int num_quads = num_online_nodes(); |
| 488 | |
| 489 | if (num_quads <= 1) |
Ingo Molnar | 4f179d1 | 2009-02-01 11:25:57 +0100 | [diff] [blame] | 490 | return; |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 491 | |
Ingo Molnar | cb81eae | 2009-02-17 17:53:54 +0100 | [diff] [blame] | 492 | printk(KERN_INFO |
| 493 | "Remapping cross-quad port I/O for %d quads\n", num_quads); |
| 494 | |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 495 | xquad_portio = ioremap(XQUAD_PORTIO_BASE, num_quads*XQUAD_PORTIO_QUAD); |
Ingo Molnar | cb81eae | 2009-02-17 17:53:54 +0100 | [diff] [blame] | 496 | |
| 497 | printk(KERN_INFO |
| 498 | "xquad_portio vaddr 0x%08lx, len %08lx\n", |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 499 | (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD); |
| 500 | } |
| 501 | |
Rakib Mullick | 7473727 | 2009-07-12 17:07:19 +0600 | [diff] [blame] | 502 | /* Use __refdata to keep false positive warning calm. */ |
| 503 | struct apic __refdata apic_numaq = { |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 504 | |
| 505 | .name = "NUMAQ", |
| 506 | .probe = probe_numaq, |
| 507 | .acpi_madt_oem_check = NULL, |
| 508 | .apic_id_registered = numaq_apic_id_registered, |
| 509 | |
| 510 | .irq_delivery_mode = dest_LowestPrio, |
| 511 | /* physical delivery on LOCAL quad: */ |
| 512 | .irq_dest_mode = 0, |
| 513 | |
| 514 | .target_cpus = numaq_target_cpus, |
| 515 | .disable_esr = 1, |
| 516 | .dest_logical = APIC_DEST_LOGICAL, |
| 517 | .check_apicid_used = numaq_check_apicid_used, |
| 518 | .check_apicid_present = numaq_check_apicid_present, |
| 519 | |
| 520 | .vector_allocation_domain = numaq_vector_allocation_domain, |
| 521 | .init_apic_ldr = numaq_init_apic_ldr, |
| 522 | |
| 523 | .ioapic_phys_id_map = numaq_ioapic_phys_id_map, |
| 524 | .setup_apic_routing = numaq_setup_apic_routing, |
| 525 | .multi_timer_check = numaq_multi_timer_check, |
| 526 | .apicid_to_node = numaq_apicid_to_node, |
| 527 | .cpu_to_logical_apicid = numaq_cpu_to_logical_apicid, |
| 528 | .cpu_present_to_apicid = numaq_cpu_present_to_apicid, |
| 529 | .apicid_to_cpu_present = numaq_apicid_to_cpu_present, |
| 530 | .setup_portio_remap = numaq_setup_portio_remap, |
| 531 | .check_phys_apicid_present = numaq_check_phys_apicid_present, |
| 532 | .enable_apic_mode = NULL, |
| 533 | .phys_pkg_id = numaq_phys_pkg_id, |
Ingo Molnar | cb81eae | 2009-02-17 17:53:54 +0100 | [diff] [blame] | 534 | .mps_oem_check = numaq_mps_oem_check, |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 535 | |
| 536 | .get_apic_id = numaq_get_apic_id, |
| 537 | .set_apic_id = NULL, |
| 538 | .apic_id_mask = 0x0F << 24, |
| 539 | |
| 540 | .cpu_mask_to_apicid = numaq_cpu_mask_to_apicid, |
| 541 | .cpu_mask_to_apicid_and = numaq_cpu_mask_to_apicid_and, |
| 542 | |
| 543 | .send_IPI_mask = numaq_send_IPI_mask, |
| 544 | .send_IPI_mask_allbutself = NULL, |
| 545 | .send_IPI_allbutself = numaq_send_IPI_allbutself, |
| 546 | .send_IPI_all = numaq_send_IPI_all, |
Ingo Molnar | 6b64ee0 | 2009-01-30 23:42:18 +0100 | [diff] [blame] | 547 | .send_IPI_self = default_send_IPI_self, |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 548 | |
Ingo Molnar | 1f5bcab | 2009-02-26 13:51:40 +0100 | [diff] [blame] | 549 | .wakeup_secondary_cpu = wakeup_secondary_cpu_via_nmi, |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 550 | .trampoline_phys_low = NUMAQ_TRAMPOLINE_PHYS_LOW, |
| 551 | .trampoline_phys_high = NUMAQ_TRAMPOLINE_PHYS_HIGH, |
| 552 | |
| 553 | /* We don't do anything here because we use NMI's to boot instead */ |
| 554 | .wait_for_init_deassert = NULL, |
| 555 | |
| 556 | .smp_callin_clear_local_apic = numaq_smp_callin_clear_local_apic, |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 557 | .inquire_remote_apic = NULL, |
Yinghai Lu | c1eeb2d | 2009-02-16 23:02:14 -0800 | [diff] [blame] | 558 | |
| 559 | .read = native_apic_mem_read, |
| 560 | .write = native_apic_mem_write, |
| 561 | .icr_read = native_apic_icr_read, |
| 562 | .icr_write = native_apic_icr_write, |
| 563 | .wait_icr_idle = native_apic_wait_icr_idle, |
| 564 | .safe_wait_icr_idle = native_safe_apic_wait_icr_idle, |
Ingo Molnar | 61b90b7 | 2009-01-28 19:01:05 +0100 | [diff] [blame] | 565 | }; |