Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Intel Multiprocessor Specification 1.1 and 1.4 |
| 3 | * compliant MP-table parsing routines. |
| 4 | * |
| 5 | * (c) 1995 Alan Cox, Building #3 <alan@redhat.com> |
| 6 | * (c) 1998, 1999, 2000 Ingo Molnar <mingo@redhat.com> |
| 7 | * |
| 8 | * Fixes |
| 9 | * Erich Boleyn : MP v1.4 and additional changes. |
| 10 | * Alan Cox : Added EBDA scanning |
| 11 | * Ingo Molnar : various cleanups and rewrites |
| 12 | * Maciej W. Rozycki: Bits for default MP configurations |
| 13 | * Paul Diefenbaugh: Added full ACPI support |
| 14 | */ |
| 15 | |
| 16 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/init.h> |
| 18 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/bootmem.h> |
| 20 | #include <linux/smp_lock.h> |
| 21 | #include <linux/kernel_stat.h> |
| 22 | #include <linux/mc146818rtc.h> |
| 23 | #include <linux/acpi.h> |
Christoph Lameter | 8c5a090 | 2005-06-23 00:08:18 -0700 | [diff] [blame] | 24 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | #include <asm/smp.h> |
| 27 | #include <asm/mtrr.h> |
| 28 | #include <asm/mpspec.h> |
| 29 | #include <asm/pgalloc.h> |
| 30 | #include <asm/io_apic.h> |
| 31 | #include <asm/proto.h> |
Andi Kleen | 8d91640 | 2005-05-31 14:39:26 -0700 | [diff] [blame] | 32 | #include <asm/acpi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | /* Have we found an MP table */ |
| 35 | int smp_found_config; |
| 36 | unsigned int __initdata maxcpus = NR_CPUS; |
| 37 | |
| 38 | int acpi_found_madt; |
| 39 | |
| 40 | /* |
| 41 | * Various Linux-internal data structures created from the |
| 42 | * MP-table. |
| 43 | */ |
Andi Kleen | 55f05ff | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 44 | DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | int mp_bus_id_to_pci_bus [MAX_MP_BUSSES] = { [0 ... MAX_MP_BUSSES-1] = -1 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | static int mp_current_pci_id = 0; |
| 48 | /* I/O APIC entries */ |
| 49 | struct mpc_config_ioapic mp_ioapics[MAX_IO_APICS]; |
| 50 | |
| 51 | /* # of MP IRQ source entries */ |
| 52 | struct mpc_config_intsrc mp_irqs[MAX_IRQ_SOURCES]; |
| 53 | |
| 54 | /* MP IRQ source entries */ |
| 55 | int mp_irq_entries; |
| 56 | |
| 57 | int nr_ioapics; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | unsigned long mp_lapic_addr = 0; |
| 59 | |
| 60 | |
| 61 | |
| 62 | /* Processor that is doing the boot up */ |
| 63 | unsigned int boot_cpu_id = -1U; |
| 64 | /* Internal processor count */ |
Andi Kleen | 420f8f6 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 65 | unsigned int num_processors __initdata = 0; |
| 66 | |
| 67 | unsigned disabled_cpus __initdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | /* Bitmask of physically existing CPUs */ |
| 70 | physid_mask_t phys_cpu_present_map = PHYSID_MASK_NONE; |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | u8 bios_cpu_apicid[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID }; |
| 73 | |
| 74 | |
| 75 | /* |
| 76 | * Intel MP BIOS table parsing routines: |
| 77 | */ |
| 78 | |
| 79 | /* |
| 80 | * Checksum an MP configuration block. |
| 81 | */ |
| 82 | |
| 83 | static int __init mpf_checksum(unsigned char *mp, int len) |
| 84 | { |
| 85 | int sum = 0; |
| 86 | |
| 87 | while (len--) |
| 88 | sum += *mp++; |
| 89 | |
| 90 | return sum & 0xFF; |
| 91 | } |
| 92 | |
Ashok Raj | 51f62e1 | 2006-03-25 16:29:28 +0100 | [diff] [blame] | 93 | static void __cpuinit MP_processor_info (struct mpc_config_processor *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
Andi Kleen | 8893166 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 95 | int cpu; |
Ashok Raj | 51f62e1 | 2006-03-25 16:29:28 +0100 | [diff] [blame] | 96 | cpumask_t tmp_map; |
Andi Kleen | f2c2cca | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 97 | char *bootup_cpu = ""; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Andi Kleen | 420f8f6 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 99 | if (!(m->mpc_cpuflag & CPU_ENABLED)) { |
| 100 | disabled_cpus++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | return; |
Andi Kleen | 420f8f6 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 102 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) { |
Andi Kleen | f2c2cca | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 104 | bootup_cpu = " (Bootup-CPU)"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | boot_cpu_id = m->mpc_apicid; |
| 106 | } |
Andi Kleen | f2c2cca | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 107 | |
| 108 | printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu); |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | if (num_processors >= NR_CPUS) { |
| 111 | printk(KERN_WARNING "WARNING: NR_CPUS limit of %i reached." |
| 112 | " Processor ignored.\n", NR_CPUS); |
| 113 | return; |
| 114 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Ashok Raj | 51f62e1 | 2006-03-25 16:29:28 +0100 | [diff] [blame] | 116 | num_processors++; |
| 117 | cpus_complement(tmp_map, cpu_present_map); |
| 118 | cpu = first_cpu(tmp_map); |
| 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | physid_set(m->mpc_apicid, phys_cpu_present_map); |
Andi Kleen | 18a2b64 | 2005-05-16 21:53:35 -0700 | [diff] [blame] | 121 | if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) { |
| 122 | /* |
| 123 | * bios_cpu_apicid is required to have processors listed |
| 124 | * in same order as logical cpu numbers. Hence the first |
| 125 | * entry is BSP, and so on. |
| 126 | */ |
Andi Kleen | 61b1b2d | 2005-07-28 21:15:27 -0700 | [diff] [blame] | 127 | cpu = 0; |
Ashok Raj | 51f62e1 | 2006-03-25 16:29:28 +0100 | [diff] [blame] | 128 | } |
Andi Kleen | 61b1b2d | 2005-07-28 21:15:27 -0700 | [diff] [blame] | 129 | bios_cpu_apicid[cpu] = m->mpc_apicid; |
| 130 | x86_cpu_to_apicid[cpu] = m->mpc_apicid; |
| 131 | |
| 132 | cpu_set(cpu, cpu_possible_map); |
| 133 | cpu_set(cpu, cpu_present_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static void __init MP_bus_info (struct mpc_config_bus *m) |
| 137 | { |
| 138 | char str[7]; |
| 139 | |
| 140 | memcpy(str, m->mpc_bustype, 6); |
| 141 | str[6] = 0; |
| 142 | Dprintk("Bus #%d is %s\n", m->mpc_busid, str); |
| 143 | |
| 144 | if (strncmp(str, "ISA", 3) == 0) { |
Andi Kleen | 55f05ff | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 145 | set_bit(m->mpc_busid, mp_bus_not_pci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | } else if (strncmp(str, "PCI", 3) == 0) { |
Andi Kleen | 55f05ff | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 147 | clear_bit(m->mpc_busid, mp_bus_not_pci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | mp_bus_id_to_pci_bus[m->mpc_busid] = mp_current_pci_id; |
| 149 | mp_current_pci_id++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } else { |
| 151 | printk(KERN_ERR "Unknown bustype %s\n", str); |
| 152 | } |
| 153 | } |
| 154 | |
Andi Kleen | 013bf2c | 2006-09-30 01:47:55 +0200 | [diff] [blame] | 155 | static int bad_ioapic(unsigned long address) |
| 156 | { |
| 157 | if (nr_ioapics >= MAX_IO_APICS) { |
| 158 | printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded " |
| 159 | "(found %d)\n", MAX_IO_APICS, nr_ioapics); |
| 160 | panic("Recompile kernel with bigger MAX_IO_APICS!\n"); |
| 161 | } |
| 162 | if (!address) { |
| 163 | printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address" |
| 164 | " found in table, skipping!\n"); |
| 165 | return 1; |
| 166 | } |
| 167 | return 0; |
| 168 | } |
| 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | static void __init MP_ioapic_info (struct mpc_config_ioapic *m) |
| 171 | { |
| 172 | if (!(m->mpc_flags & MPC_APIC_USABLE)) |
| 173 | return; |
| 174 | |
Andi Kleen | f2c2cca | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 175 | printk("I/O APIC #%d at 0x%X.\n", |
| 176 | m->mpc_apicid, m->mpc_apicaddr); |
Andi Kleen | 013bf2c | 2006-09-30 01:47:55 +0200 | [diff] [blame] | 177 | |
| 178 | if (bad_ioapic(m->mpc_apicaddr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | return; |
Andi Kleen | 013bf2c | 2006-09-30 01:47:55 +0200 | [diff] [blame] | 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | mp_ioapics[nr_ioapics] = *m; |
| 182 | nr_ioapics++; |
| 183 | } |
| 184 | |
| 185 | static void __init MP_intsrc_info (struct mpc_config_intsrc *m) |
| 186 | { |
| 187 | mp_irqs [mp_irq_entries] = *m; |
| 188 | Dprintk("Int: type %d, pol %d, trig %d, bus %d," |
| 189 | " IRQ %02x, APIC ID %x, APIC INT %02x\n", |
| 190 | m->mpc_irqtype, m->mpc_irqflag & 3, |
| 191 | (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus, |
| 192 | m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq); |
James Cleverdon | 6004e1b | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 193 | if (++mp_irq_entries >= MAX_IRQ_SOURCES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | panic("Max # of irq sources exceeded!!\n"); |
| 195 | } |
| 196 | |
| 197 | static void __init MP_lintsrc_info (struct mpc_config_lintsrc *m) |
| 198 | { |
| 199 | Dprintk("Lint: type %d, pol %d, trig %d, bus %d," |
| 200 | " IRQ %02x, APIC ID %x, APIC LINT %02x\n", |
| 201 | m->mpc_irqtype, m->mpc_irqflag & 3, |
| 202 | (m->mpc_irqflag >> 2) &3, m->mpc_srcbusid, |
| 203 | m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | /* |
| 207 | * Read/parse the MPC |
| 208 | */ |
| 209 | |
| 210 | static int __init smp_read_mpc(struct mp_config_table *mpc) |
| 211 | { |
| 212 | char str[16]; |
| 213 | int count=sizeof(*mpc); |
| 214 | unsigned char *mpt=((unsigned char *)mpc)+count; |
| 215 | |
| 216 | if (memcmp(mpc->mpc_signature,MPC_SIGNATURE,4)) { |
Andi Kleen | aecc636 | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 217 | printk("MPTABLE: bad signature [%c%c%c%c]!\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | mpc->mpc_signature[0], |
| 219 | mpc->mpc_signature[1], |
| 220 | mpc->mpc_signature[2], |
| 221 | mpc->mpc_signature[3]); |
| 222 | return 0; |
| 223 | } |
| 224 | if (mpf_checksum((unsigned char *)mpc,mpc->mpc_length)) { |
Andi Kleen | aecc636 | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 225 | printk("MPTABLE: checksum error!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | return 0; |
| 227 | } |
| 228 | if (mpc->mpc_spec!=0x01 && mpc->mpc_spec!=0x04) { |
Andi Kleen | aecc636 | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 229 | printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | mpc->mpc_spec); |
| 231 | return 0; |
| 232 | } |
| 233 | if (!mpc->mpc_lapic) { |
Andi Kleen | aecc636 | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 234 | printk(KERN_ERR "MPTABLE: null local APIC address!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | return 0; |
| 236 | } |
| 237 | memcpy(str,mpc->mpc_oem,8); |
Andi Kleen | aecc636 | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 238 | str[8] = 0; |
| 239 | printk(KERN_INFO "MPTABLE: OEM ID: %s ",str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
| 241 | memcpy(str,mpc->mpc_productid,12); |
Andi Kleen | aecc636 | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 242 | str[12] = 0; |
| 243 | printk("MPTABLE: Product ID: %s ",str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Andi Kleen | aecc636 | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 245 | printk("MPTABLE: APIC at: 0x%X\n",mpc->mpc_lapic); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
| 247 | /* save the local APIC address, it might be non-default */ |
| 248 | if (!acpi_lapic) |
Andi Kleen | aecc636 | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 249 | mp_lapic_addr = mpc->mpc_lapic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | /* |
| 252 | * Now process the configuration blocks. |
| 253 | */ |
| 254 | while (count < mpc->mpc_length) { |
| 255 | switch(*mpt) { |
| 256 | case MP_PROCESSOR: |
| 257 | { |
| 258 | struct mpc_config_processor *m= |
| 259 | (struct mpc_config_processor *)mpt; |
| 260 | if (!acpi_lapic) |
Andi Kleen | aecc636 | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 261 | MP_processor_info(m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | mpt += sizeof(*m); |
| 263 | count += sizeof(*m); |
| 264 | break; |
| 265 | } |
| 266 | case MP_BUS: |
| 267 | { |
| 268 | struct mpc_config_bus *m= |
| 269 | (struct mpc_config_bus *)mpt; |
| 270 | MP_bus_info(m); |
| 271 | mpt += sizeof(*m); |
| 272 | count += sizeof(*m); |
| 273 | break; |
| 274 | } |
| 275 | case MP_IOAPIC: |
| 276 | { |
| 277 | struct mpc_config_ioapic *m= |
| 278 | (struct mpc_config_ioapic *)mpt; |
| 279 | MP_ioapic_info(m); |
Andi Kleen | aecc636 | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 280 | mpt += sizeof(*m); |
| 281 | count += sizeof(*m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | break; |
| 283 | } |
| 284 | case MP_INTSRC: |
| 285 | { |
| 286 | struct mpc_config_intsrc *m= |
| 287 | (struct mpc_config_intsrc *)mpt; |
| 288 | |
| 289 | MP_intsrc_info(m); |
Andi Kleen | aecc636 | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 290 | mpt += sizeof(*m); |
| 291 | count += sizeof(*m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | break; |
| 293 | } |
| 294 | case MP_LINTSRC: |
| 295 | { |
| 296 | struct mpc_config_lintsrc *m= |
| 297 | (struct mpc_config_lintsrc *)mpt; |
| 298 | MP_lintsrc_info(m); |
Andi Kleen | aecc636 | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 299 | mpt += sizeof(*m); |
| 300 | count += sizeof(*m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | break; |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | clustered_apic_check(); |
| 306 | if (!num_processors) |
Andi Kleen | aecc636 | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 307 | printk(KERN_ERR "MPTABLE: no processors registered!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | return num_processors; |
| 309 | } |
| 310 | |
| 311 | static int __init ELCR_trigger(unsigned int irq) |
| 312 | { |
| 313 | unsigned int port; |
| 314 | |
| 315 | port = 0x4d0 + (irq >> 3); |
| 316 | return (inb(port) >> (irq & 7)) & 1; |
| 317 | } |
| 318 | |
| 319 | static void __init construct_default_ioirq_mptable(int mpc_default_type) |
| 320 | { |
| 321 | struct mpc_config_intsrc intsrc; |
| 322 | int i; |
| 323 | int ELCR_fallback = 0; |
| 324 | |
| 325 | intsrc.mpc_type = MP_INTSRC; |
| 326 | intsrc.mpc_irqflag = 0; /* conforming */ |
| 327 | intsrc.mpc_srcbus = 0; |
| 328 | intsrc.mpc_dstapic = mp_ioapics[0].mpc_apicid; |
| 329 | |
| 330 | intsrc.mpc_irqtype = mp_INT; |
| 331 | |
| 332 | /* |
| 333 | * If true, we have an ISA/PCI system with no IRQ entries |
| 334 | * in the MP table. To prevent the PCI interrupts from being set up |
| 335 | * incorrectly, we try to use the ELCR. The sanity check to see if |
| 336 | * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can |
| 337 | * never be level sensitive, so we simply see if the ELCR agrees. |
| 338 | * If it does, we assume it's valid. |
| 339 | */ |
| 340 | if (mpc_default_type == 5) { |
| 341 | printk(KERN_INFO "ISA/PCI bus type with no IRQ information... falling back to ELCR\n"); |
| 342 | |
| 343 | if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) || ELCR_trigger(13)) |
| 344 | printk(KERN_ERR "ELCR contains invalid data... not using ELCR\n"); |
| 345 | else { |
| 346 | printk(KERN_INFO "Using ELCR to identify PCI interrupts\n"); |
| 347 | ELCR_fallback = 1; |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | for (i = 0; i < 16; i++) { |
| 352 | switch (mpc_default_type) { |
| 353 | case 2: |
| 354 | if (i == 0 || i == 13) |
| 355 | continue; /* IRQ0 & IRQ13 not connected */ |
| 356 | /* fall through */ |
| 357 | default: |
| 358 | if (i == 2) |
| 359 | continue; /* IRQ2 is never connected */ |
| 360 | } |
| 361 | |
| 362 | if (ELCR_fallback) { |
| 363 | /* |
| 364 | * If the ELCR indicates a level-sensitive interrupt, we |
| 365 | * copy that information over to the MP table in the |
| 366 | * irqflag field (level sensitive, active high polarity). |
| 367 | */ |
| 368 | if (ELCR_trigger(i)) |
| 369 | intsrc.mpc_irqflag = 13; |
| 370 | else |
| 371 | intsrc.mpc_irqflag = 0; |
| 372 | } |
| 373 | |
| 374 | intsrc.mpc_srcbusirq = i; |
| 375 | intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */ |
| 376 | MP_intsrc_info(&intsrc); |
| 377 | } |
| 378 | |
| 379 | intsrc.mpc_irqtype = mp_ExtINT; |
| 380 | intsrc.mpc_srcbusirq = 0; |
| 381 | intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */ |
| 382 | MP_intsrc_info(&intsrc); |
| 383 | } |
| 384 | |
| 385 | static inline void __init construct_default_ISA_mptable(int mpc_default_type) |
| 386 | { |
| 387 | struct mpc_config_processor processor; |
| 388 | struct mpc_config_bus bus; |
| 389 | struct mpc_config_ioapic ioapic; |
| 390 | struct mpc_config_lintsrc lintsrc; |
| 391 | int linttypes[2] = { mp_ExtINT, mp_NMI }; |
| 392 | int i; |
| 393 | |
| 394 | /* |
| 395 | * local APIC has default address |
| 396 | */ |
| 397 | mp_lapic_addr = APIC_DEFAULT_PHYS_BASE; |
| 398 | |
| 399 | /* |
| 400 | * 2 CPUs, numbered 0 & 1. |
| 401 | */ |
| 402 | processor.mpc_type = MP_PROCESSOR; |
Andi Kleen | f2c2cca | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 403 | processor.mpc_apicver = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | processor.mpc_cpuflag = CPU_ENABLED; |
Andi Kleen | f2c2cca | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 405 | processor.mpc_cpufeature = 0; |
| 406 | processor.mpc_featureflag = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | processor.mpc_reserved[0] = 0; |
| 408 | processor.mpc_reserved[1] = 0; |
| 409 | for (i = 0; i < 2; i++) { |
| 410 | processor.mpc_apicid = i; |
| 411 | MP_processor_info(&processor); |
| 412 | } |
| 413 | |
| 414 | bus.mpc_type = MP_BUS; |
| 415 | bus.mpc_busid = 0; |
| 416 | switch (mpc_default_type) { |
| 417 | default: |
| 418 | printk(KERN_ERR "???\nUnknown standard configuration %d\n", |
| 419 | mpc_default_type); |
| 420 | /* fall through */ |
| 421 | case 1: |
| 422 | case 5: |
| 423 | memcpy(bus.mpc_bustype, "ISA ", 6); |
| 424 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | } |
| 426 | MP_bus_info(&bus); |
| 427 | if (mpc_default_type > 4) { |
| 428 | bus.mpc_busid = 1; |
| 429 | memcpy(bus.mpc_bustype, "PCI ", 6); |
| 430 | MP_bus_info(&bus); |
| 431 | } |
| 432 | |
| 433 | ioapic.mpc_type = MP_IOAPIC; |
| 434 | ioapic.mpc_apicid = 2; |
Andi Kleen | f2c2cca | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 435 | ioapic.mpc_apicver = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | ioapic.mpc_flags = MPC_APIC_USABLE; |
| 437 | ioapic.mpc_apicaddr = 0xFEC00000; |
| 438 | MP_ioapic_info(&ioapic); |
| 439 | |
| 440 | /* |
| 441 | * We set up most of the low 16 IO-APIC pins according to MPS rules. |
| 442 | */ |
| 443 | construct_default_ioirq_mptable(mpc_default_type); |
| 444 | |
| 445 | lintsrc.mpc_type = MP_LINTSRC; |
| 446 | lintsrc.mpc_irqflag = 0; /* conforming */ |
| 447 | lintsrc.mpc_srcbusid = 0; |
| 448 | lintsrc.mpc_srcbusirq = 0; |
| 449 | lintsrc.mpc_destapic = MP_APIC_ALL; |
| 450 | for (i = 0; i < 2; i++) { |
| 451 | lintsrc.mpc_irqtype = linttypes[i]; |
| 452 | lintsrc.mpc_destapiclint = i; |
| 453 | MP_lintsrc_info(&lintsrc); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | static struct intel_mp_floating *mpf_found; |
| 458 | |
| 459 | /* |
| 460 | * Scan the memory blocks for an SMP configuration block. |
| 461 | */ |
| 462 | void __init get_smp_config (void) |
| 463 | { |
| 464 | struct intel_mp_floating *mpf = mpf_found; |
| 465 | |
| 466 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | * ACPI supports both logical (e.g. Hyper-Threading) and physical |
| 468 | * processors, where MPS only supports physical. |
| 469 | */ |
| 470 | if (acpi_lapic && acpi_ioapic) { |
| 471 | printk(KERN_INFO "Using ACPI (MADT) for SMP configuration information\n"); |
| 472 | return; |
| 473 | } |
| 474 | else if (acpi_lapic) |
| 475 | printk(KERN_INFO "Using ACPI for processor (LAPIC) configuration information\n"); |
| 476 | |
| 477 | printk("Intel MultiProcessor Specification v1.%d\n", mpf->mpf_specification); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
| 479 | /* |
| 480 | * Now see if we need to read further. |
| 481 | */ |
| 482 | if (mpf->mpf_feature1 != 0) { |
| 483 | |
| 484 | printk(KERN_INFO "Default MP configuration #%d\n", mpf->mpf_feature1); |
| 485 | construct_default_ISA_mptable(mpf->mpf_feature1); |
| 486 | |
| 487 | } else if (mpf->mpf_physptr) { |
| 488 | |
| 489 | /* |
| 490 | * Read the physical hardware table. Anything here will |
| 491 | * override the defaults. |
| 492 | */ |
Siddha, Suresh B | f6c2e33 | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 493 | if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | smp_found_config = 0; |
| 495 | printk(KERN_ERR "BIOS bug, MP table errors detected!...\n"); |
| 496 | printk(KERN_ERR "... disabling SMP support. (tell your hw vendor)\n"); |
| 497 | return; |
| 498 | } |
| 499 | /* |
| 500 | * If there are no explicit MP IRQ entries, then we are |
| 501 | * broken. We set up most of the low 16 IO-APIC pins to |
| 502 | * ISA defaults and hope it will work. |
| 503 | */ |
| 504 | if (!mp_irq_entries) { |
| 505 | struct mpc_config_bus bus; |
| 506 | |
| 507 | printk(KERN_ERR "BIOS bug, no explicit IRQ entries, using default mptable. (tell your hw vendor)\n"); |
| 508 | |
| 509 | bus.mpc_type = MP_BUS; |
| 510 | bus.mpc_busid = 0; |
| 511 | memcpy(bus.mpc_bustype, "ISA ", 6); |
| 512 | MP_bus_info(&bus); |
| 513 | |
| 514 | construct_default_ioirq_mptable(0); |
| 515 | } |
| 516 | |
| 517 | } else |
| 518 | BUG(); |
| 519 | |
| 520 | printk(KERN_INFO "Processors: %d\n", num_processors); |
| 521 | /* |
| 522 | * Only use the first configuration found. |
| 523 | */ |
| 524 | } |
| 525 | |
| 526 | static int __init smp_scan_config (unsigned long base, unsigned long length) |
| 527 | { |
| 528 | extern void __bad_mpf_size(void); |
| 529 | unsigned int *bp = phys_to_virt(base); |
| 530 | struct intel_mp_floating *mpf; |
| 531 | |
| 532 | Dprintk("Scan SMP from %p for %ld bytes.\n", bp,length); |
| 533 | if (sizeof(*mpf) != 16) |
| 534 | __bad_mpf_size(); |
| 535 | |
| 536 | while (length > 0) { |
| 537 | mpf = (struct intel_mp_floating *)bp; |
| 538 | if ((*bp == SMP_MAGIC_IDENT) && |
| 539 | (mpf->mpf_length == 1) && |
| 540 | !mpf_checksum((unsigned char *)bp, 16) && |
| 541 | ((mpf->mpf_specification == 1) |
| 542 | || (mpf->mpf_specification == 4)) ) { |
| 543 | |
| 544 | smp_found_config = 1; |
| 545 | reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE); |
| 546 | if (mpf->mpf_physptr) |
| 547 | reserve_bootmem_generic(mpf->mpf_physptr, PAGE_SIZE); |
| 548 | mpf_found = mpf; |
| 549 | return 1; |
| 550 | } |
| 551 | bp += 4; |
| 552 | length -= 16; |
| 553 | } |
| 554 | return 0; |
| 555 | } |
| 556 | |
Andi Kleen | a01fd3b | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 557 | void __init find_smp_config(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | { |
| 559 | unsigned int address; |
| 560 | |
| 561 | /* |
| 562 | * FIXME: Linux assumes you have 640K of base ram.. |
| 563 | * this continues the error... |
| 564 | * |
| 565 | * 1) Scan the bottom 1K for a signature |
| 566 | * 2) Scan the top 1K of base RAM |
| 567 | * 3) Scan the 64K of bios |
| 568 | */ |
| 569 | if (smp_scan_config(0x0,0x400) || |
| 570 | smp_scan_config(639*0x400,0x400) || |
| 571 | smp_scan_config(0xF0000,0x10000)) |
| 572 | return; |
| 573 | /* |
Andi Kleen | e509913 | 2006-09-26 10:52:29 +0200 | [diff] [blame] | 574 | * If it is an SMP machine we should know now. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | * |
| 576 | * there is a real-mode segmented pointer pointing to the |
| 577 | * 4K EBDA area at 0x40E, calculate and scan it here. |
| 578 | * |
| 579 | * NOTE! There are Linux loaders that will corrupt the EBDA |
| 580 | * area, and as such this kind of SMP config may be less |
| 581 | * trustworthy, simply because the SMP table may have been |
| 582 | * stomped on during early boot. These loaders are buggy and |
| 583 | * should be fixed. |
| 584 | */ |
| 585 | |
| 586 | address = *(unsigned short *)phys_to_virt(0x40E); |
| 587 | address <<= 4; |
| 588 | if (smp_scan_config(address, 0x1000)) |
| 589 | return; |
| 590 | |
| 591 | /* If we have come this far, we did not find an MP table */ |
| 592 | printk(KERN_INFO "No mptable found.\n"); |
| 593 | } |
| 594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | /* -------------------------------------------------------------------------- |
| 596 | ACPI-based MP Configuration |
| 597 | -------------------------------------------------------------------------- */ |
| 598 | |
Len Brown | 888ba6c | 2005-08-24 12:07:20 -0400 | [diff] [blame] | 599 | #ifdef CONFIG_ACPI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | |
Andi Kleen | efec3b9 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 601 | void __init mp_register_lapic_address(u64 address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | { |
| 603 | mp_lapic_addr = (unsigned long) address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | set_fixmap_nocache(FIX_APIC_BASE, mp_lapic_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | if (boot_cpu_id == -1U) |
| 606 | boot_cpu_id = GET_APIC_ID(apic_read(APIC_ID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Andi Kleen | efec3b9 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 609 | void __cpuinit mp_register_lapic (u8 id, u8 enabled) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | { |
| 611 | struct mpc_config_processor processor; |
| 612 | int boot_cpu = 0; |
| 613 | |
Andi Kleen | e4251e1 | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 614 | if (id == boot_cpu_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | boot_cpu = 1; |
| 616 | |
| 617 | processor.mpc_type = MP_PROCESSOR; |
| 618 | processor.mpc_apicid = id; |
Andi Kleen | f2c2cca | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 619 | processor.mpc_apicver = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | processor.mpc_cpuflag = (enabled ? CPU_ENABLED : 0); |
| 621 | processor.mpc_cpuflag |= (boot_cpu ? CPU_BOOTPROCESSOR : 0); |
Andi Kleen | f2c2cca | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 622 | processor.mpc_cpufeature = 0; |
| 623 | processor.mpc_featureflag = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | processor.mpc_reserved[0] = 0; |
| 625 | processor.mpc_reserved[1] = 0; |
| 626 | |
| 627 | MP_processor_info(&processor); |
| 628 | } |
| 629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | #define MP_ISA_BUS 0 |
| 631 | #define MP_MAX_IOAPIC_PIN 127 |
| 632 | |
| 633 | static struct mp_ioapic_routing { |
| 634 | int apic_id; |
| 635 | int gsi_start; |
| 636 | int gsi_end; |
| 637 | u32 pin_programmed[4]; |
| 638 | } mp_ioapic_routing[MAX_IO_APICS]; |
| 639 | |
Andi Kleen | efec3b9 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 640 | static int mp_find_ioapic(int gsi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | { |
Andi Kleen | efec3b9 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 642 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
| 644 | /* Find the IOAPIC that manages this GSI. */ |
| 645 | for (i = 0; i < nr_ioapics; i++) { |
| 646 | if ((gsi >= mp_ioapic_routing[i].gsi_start) |
| 647 | && (gsi <= mp_ioapic_routing[i].gsi_end)) |
| 648 | return i; |
| 649 | } |
| 650 | |
| 651 | printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | return -1; |
| 653 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
Andi Kleen | efec3b9 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 655 | void __init mp_register_ioapic(u8 id, u32 address, u32 gsi_base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | { |
Andi Kleen | efec3b9 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 657 | int idx = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | |
Andi Kleen | 013bf2c | 2006-09-30 01:47:55 +0200 | [diff] [blame] | 659 | if (bad_ioapic(address)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | |
| 662 | idx = nr_ioapics++; |
| 663 | |
| 664 | mp_ioapics[idx].mpc_type = MP_IOAPIC; |
| 665 | mp_ioapics[idx].mpc_flags = MPC_APIC_USABLE; |
| 666 | mp_ioapics[idx].mpc_apicaddr = address; |
| 667 | |
| 668 | set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address); |
Andi Kleen | 0af2be0 | 2005-05-16 21:53:27 -0700 | [diff] [blame] | 669 | mp_ioapics[idx].mpc_apicid = id; |
Andi Kleen | f2c2cca | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 670 | mp_ioapics[idx].mpc_apicver = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
| 672 | /* |
| 673 | * Build basic IRQ lookup table to facilitate gsi->io_apic lookups |
| 674 | * and to prevent reprogramming of IOAPIC pins (PCI IRQs). |
| 675 | */ |
| 676 | mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].mpc_apicid; |
| 677 | mp_ioapic_routing[idx].gsi_start = gsi_base; |
| 678 | mp_ioapic_routing[idx].gsi_end = gsi_base + |
| 679 | io_apic_get_redir_entries(idx); |
| 680 | |
Andi Kleen | f2c2cca | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 681 | printk(KERN_INFO "IOAPIC[%d]: apic_id %d, address 0x%x, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | "GSI %d-%d\n", idx, mp_ioapics[idx].mpc_apicid, |
Andi Kleen | f2c2cca | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 683 | mp_ioapics[idx].mpc_apicaddr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | mp_ioapic_routing[idx].gsi_start, |
| 685 | mp_ioapic_routing[idx].gsi_end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | } |
| 687 | |
Andi Kleen | efec3b9 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 688 | void __init |
| 689 | mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | { |
| 691 | struct mpc_config_intsrc intsrc; |
| 692 | int ioapic = -1; |
| 693 | int pin = -1; |
| 694 | |
| 695 | /* |
| 696 | * Convert 'gsi' to 'ioapic.pin'. |
| 697 | */ |
| 698 | ioapic = mp_find_ioapic(gsi); |
| 699 | if (ioapic < 0) |
| 700 | return; |
| 701 | pin = gsi - mp_ioapic_routing[ioapic].gsi_start; |
| 702 | |
| 703 | /* |
| 704 | * TBD: This check is for faulty timer entries, where the override |
| 705 | * erroneously sets the trigger to level, resulting in a HUGE |
| 706 | * increase of timer interrupts! |
| 707 | */ |
| 708 | if ((bus_irq == 0) && (trigger == 3)) |
| 709 | trigger = 1; |
| 710 | |
| 711 | intsrc.mpc_type = MP_INTSRC; |
| 712 | intsrc.mpc_irqtype = mp_INT; |
| 713 | intsrc.mpc_irqflag = (trigger << 2) | polarity; |
| 714 | intsrc.mpc_srcbus = MP_ISA_BUS; |
| 715 | intsrc.mpc_srcbusirq = bus_irq; /* IRQ */ |
| 716 | intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid; /* APIC ID */ |
| 717 | intsrc.mpc_dstirq = pin; /* INTIN# */ |
| 718 | |
| 719 | Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, %d-%d\n", |
| 720 | intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3, |
| 721 | (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus, |
| 722 | intsrc.mpc_srcbusirq, intsrc.mpc_dstapic, intsrc.mpc_dstirq); |
| 723 | |
| 724 | mp_irqs[mp_irq_entries] = intsrc; |
| 725 | if (++mp_irq_entries == MAX_IRQ_SOURCES) |
| 726 | panic("Max # of irq sources exceeded!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | } |
| 728 | |
Andi Kleen | efec3b9 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 729 | void __init mp_config_acpi_legacy_irqs(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | { |
| 731 | struct mpc_config_intsrc intsrc; |
Andi Kleen | efec3b9 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 732 | int i = 0; |
| 733 | int ioapic = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
| 735 | /* |
| 736 | * Fabricate the legacy ISA bus (bus #31). |
| 737 | */ |
Andi Kleen | 55f05ff | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 738 | set_bit(MP_ISA_BUS, mp_bus_not_pci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | |
| 740 | /* |
| 741 | * Locate the IOAPIC that manages the ISA IRQs (0-15). |
| 742 | */ |
| 743 | ioapic = mp_find_ioapic(0); |
| 744 | if (ioapic < 0) |
| 745 | return; |
| 746 | |
| 747 | intsrc.mpc_type = MP_INTSRC; |
| 748 | intsrc.mpc_irqflag = 0; /* Conforming */ |
| 749 | intsrc.mpc_srcbus = MP_ISA_BUS; |
| 750 | intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid; |
| 751 | |
| 752 | /* |
| 753 | * Use the default configuration for the IRQs 0-15. Unless |
| 754 | * overridden by (MADT) interrupt source override entries. |
| 755 | */ |
| 756 | for (i = 0; i < 16; i++) { |
| 757 | int idx; |
| 758 | |
| 759 | for (idx = 0; idx < mp_irq_entries; idx++) { |
| 760 | struct mpc_config_intsrc *irq = mp_irqs + idx; |
| 761 | |
| 762 | /* Do we already have a mapping for this ISA IRQ? */ |
| 763 | if (irq->mpc_srcbus == MP_ISA_BUS && irq->mpc_srcbusirq == i) |
| 764 | break; |
| 765 | |
| 766 | /* Do we already have a mapping for this IOAPIC pin */ |
| 767 | if ((irq->mpc_dstapic == intsrc.mpc_dstapic) && |
| 768 | (irq->mpc_dstirq == i)) |
| 769 | break; |
| 770 | } |
| 771 | |
| 772 | if (idx != mp_irq_entries) { |
| 773 | printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i); |
| 774 | continue; /* IRQ already used */ |
| 775 | } |
| 776 | |
| 777 | intsrc.mpc_irqtype = mp_INT; |
| 778 | intsrc.mpc_srcbusirq = i; /* Identity mapped */ |
| 779 | intsrc.mpc_dstirq = i; |
| 780 | |
| 781 | Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, " |
| 782 | "%d-%d\n", intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3, |
| 783 | (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus, |
| 784 | intsrc.mpc_srcbusirq, intsrc.mpc_dstapic, |
| 785 | intsrc.mpc_dstirq); |
| 786 | |
| 787 | mp_irqs[mp_irq_entries] = intsrc; |
| 788 | if (++mp_irq_entries == MAX_IRQ_SOURCES) |
| 789 | panic("Max # of irq sources exceeded!\n"); |
| 790 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 793 | int mp_register_gsi(u32 gsi, int triggering, int polarity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | { |
Andi Kleen | efec3b9 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 795 | int ioapic = -1; |
| 796 | int ioapic_pin = 0; |
| 797 | int idx, bit = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
| 799 | if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC) |
| 800 | return gsi; |
| 801 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | /* Don't set up the ACPI SCI because it's already set up */ |
| 803 | if (acpi_fadt.sci_int == gsi) |
| 804 | return gsi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | |
| 806 | ioapic = mp_find_ioapic(gsi); |
| 807 | if (ioapic < 0) { |
| 808 | printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi); |
| 809 | return gsi; |
| 810 | } |
| 811 | |
| 812 | ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_start; |
| 813 | |
| 814 | /* |
| 815 | * Avoid pin reprogramming. PRTs typically include entries |
| 816 | * with redundant pin->gsi mappings (but unique PCI devices); |
| 817 | * we only program the IOAPIC on the first. |
| 818 | */ |
| 819 | bit = ioapic_pin % 32; |
| 820 | idx = (ioapic_pin < 32) ? 0 : (ioapic_pin / 32); |
| 821 | if (idx > 3) { |
| 822 | printk(KERN_ERR "Invalid reference to IOAPIC pin " |
| 823 | "%d-%d\n", mp_ioapic_routing[ioapic].apic_id, |
| 824 | ioapic_pin); |
| 825 | return gsi; |
| 826 | } |
| 827 | if ((1<<bit) & mp_ioapic_routing[ioapic].pin_programmed[idx]) { |
| 828 | Dprintk(KERN_DEBUG "Pin %d-%d already programmed\n", |
| 829 | mp_ioapic_routing[ioapic].apic_id, ioapic_pin); |
Eric W. Biederman | cd1182f | 2006-10-04 02:16:53 -0700 | [diff] [blame^] | 830 | return gsi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | mp_ioapic_routing[ioapic].pin_programmed[idx] |= (1<<bit); |
| 834 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | io_apic_set_pci_routing(ioapic, ioapic_pin, gsi, |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 836 | triggering == ACPI_EDGE_SENSITIVE ? 0 : 1, |
| 837 | polarity == ACPI_ACTIVE_HIGH ? 0 : 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | return gsi; |
| 839 | } |
Len Brown | 888ba6c | 2005-08-24 12:07:20 -0400 | [diff] [blame] | 840 | #endif /*CONFIG_ACPI*/ |