Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Alexey Starikovskiy | 11113f8 | 2008-05-14 19:02:57 +0400 | [diff] [blame] | 2 | * Intel Multiprocessor Specification 1.1 and 1.4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Alexey Starikovskiy | 85bddde | 2008-04-04 23:43:18 +0400 | [diff] [blame] | 7 | * (c) 2008 Alexey Starikovskiy <astarikovskiy@suse.de> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/bootmem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/kernel_stat.h> |
| 15 | #include <linux/mc146818rtc.h> |
| 16 | #include <linux/bitops.h> |
Alexey Starikovskiy | 85bddde | 2008-04-04 23:43:18 +0400 | [diff] [blame] | 17 | #include <linux/acpi.h> |
| 18 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | #include <asm/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/mtrr.h> |
| 22 | #include <asm/mpspec.h> |
Alexey Starikovskiy | 85bddde | 2008-04-04 23:43:18 +0400 | [diff] [blame] | 23 | #include <asm/pgalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/io_apic.h> |
Alexey Starikovskiy | 85bddde | 2008-04-04 23:43:18 +0400 | [diff] [blame] | 25 | #include <asm/proto.h> |
| 26 | #include <asm/acpi.h> |
Alexey Starikovskiy | ce3fe6b | 2008-03-17 22:08:17 +0300 | [diff] [blame] | 27 | #include <asm/bios_ebda.h> |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame^] | 28 | #include <asm/e820.h> |
| 29 | #include <asm/trampoline.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | #include <mach_apic.h> |
Alexey Starikovskiy | 85bddde | 2008-04-04 23:43:18 +0400 | [diff] [blame] | 32 | #ifdef CONFIG_X86_32 |
Andi Kleen | 874c4fe | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 33 | #include <mach_apicdef.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <mach_mpparse.h> |
Alexey Starikovskiy | 85bddde | 2008-04-04 23:43:18 +0400 | [diff] [blame] | 35 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | * Checksum an MP configuration block. |
| 39 | */ |
| 40 | |
| 41 | static int __init mpf_checksum(unsigned char *mp, int len) |
| 42 | { |
| 43 | int sum = 0; |
| 44 | |
| 45 | while (len--) |
| 46 | sum += *mp++; |
| 47 | |
| 48 | return sum & 0xFF; |
| 49 | } |
| 50 | |
Alexey Starikovskiy | 8642050 | 2008-03-17 22:08:55 +0300 | [diff] [blame] | 51 | #ifdef CONFIG_X86_NUMAQ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | /* |
| 53 | * Have to match translation table entries to main table entries by counter |
| 54 | * hence the mpc_record variable .... can't see a less disgusting way of |
| 55 | * doing this .... |
| 56 | */ |
| 57 | |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 58 | static int mpc_record; |
| 59 | static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY] |
| 60 | __cpuinitdata; |
Alexey Starikovskiy | 8642050 | 2008-03-17 22:08:55 +0300 | [diff] [blame] | 61 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Alexey Starikovskiy | c853c67 | 2008-03-27 23:54:13 +0300 | [diff] [blame] | 63 | static void __cpuinit MP_processor_info(struct mpc_config_processor *m) |
| 64 | { |
| 65 | int apicid; |
Alexey Starikovskiy | 746f224 | 2008-04-04 23:42:15 +0400 | [diff] [blame] | 66 | char *bootup_cpu = ""; |
Alexey Starikovskiy | c853c67 | 2008-03-27 23:54:13 +0300 | [diff] [blame] | 67 | |
Glauber Costa | 7b1292e | 2008-03-03 14:12:41 -0300 | [diff] [blame] | 68 | if (!(m->mpc_cpuflag & CPU_ENABLED)) { |
| 69 | disabled_cpus++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | return; |
Glauber Costa | 7b1292e | 2008-03-03 14:12:41 -0300 | [diff] [blame] | 71 | } |
Alexey Starikovskiy | 4655c7d | 2008-03-17 22:08:36 +0300 | [diff] [blame] | 72 | #ifdef CONFIG_X86_NUMAQ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | apicid = mpc_apic_id(m, translation_table[mpc_record]); |
Alexey Starikovskiy | 4655c7d | 2008-03-17 22:08:36 +0300 | [diff] [blame] | 74 | #else |
Alexey Starikovskiy | 4655c7d | 2008-03-17 22:08:36 +0300 | [diff] [blame] | 75 | apicid = m->mpc_apicid; |
| 76 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) { |
Alexey Starikovskiy | 746f224 | 2008-04-04 23:42:15 +0400 | [diff] [blame] | 78 | bootup_cpu = " (Bootup-CPU)"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | boot_cpu_physical_apicid = m->mpc_apicid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Alexey Starikovskiy | 746f224 | 2008-04-04 23:42:15 +0400 | [diff] [blame] | 82 | printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu); |
Alexey Starikovskiy | c853c67 | 2008-03-27 23:54:13 +0300 | [diff] [blame] | 83 | generic_processor_info(apicid, m->mpc_apicver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Thomas Gleixner | 85cc35f | 2008-05-25 21:21:36 +0200 | [diff] [blame] | 86 | #ifdef CONFIG_X86_IO_APIC |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 87 | static void __init MP_bus_info(struct mpc_config_bus *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
| 89 | char str[7]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | memcpy(str, m->mpc_bustype, 6); |
| 91 | str[6] = 0; |
| 92 | |
Alexey Starikovskiy | 0ec153a | 2008-03-17 22:08:48 +0300 | [diff] [blame] | 93 | #ifdef CONFIG_X86_NUMAQ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | mpc_oem_bus_info(m, str, translation_table[mpc_record]); |
Alexey Starikovskiy | 0ec153a | 2008-03-17 22:08:48 +0300 | [diff] [blame] | 95 | #else |
Yinghai Lu | 11a62a0 | 2008-05-12 15:43:38 +0200 | [diff] [blame] | 96 | printk(KERN_INFO "Bus #%d is %s\n", m->mpc_busid, str); |
Alexey Starikovskiy | 0ec153a | 2008-03-17 22:08:48 +0300 | [diff] [blame] | 97 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Andi Kleen | 5e4edbb | 2006-09-26 10:52:35 +0200 | [diff] [blame] | 99 | #if MAX_MP_BUSSES < 256 |
Randy Dunlap | c0ec31a | 2006-04-10 22:53:13 -0700 | [diff] [blame] | 100 | if (m->mpc_busid >= MAX_MP_BUSSES) { |
| 101 | printk(KERN_WARNING "MP table busid value (%d) for bustype %s " |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 102 | " is too large, max. supported is %d\n", |
| 103 | m->mpc_busid, str, MAX_MP_BUSSES - 1); |
Randy Dunlap | c0ec31a | 2006-04-10 22:53:13 -0700 | [diff] [blame] | 104 | return; |
| 105 | } |
Andi Kleen | 5e4edbb | 2006-09-26 10:52:35 +0200 | [diff] [blame] | 106 | #endif |
Randy Dunlap | c0ec31a | 2006-04-10 22:53:13 -0700 | [diff] [blame] | 107 | |
Alexey Starikovskiy | f8924e7 | 2008-04-04 23:42:21 +0400 | [diff] [blame] | 108 | if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) { |
| 109 | set_bit(m->mpc_busid, mp_bus_not_pci); |
| 110 | #if defined(CONFIG_EISA) || defined (CONFIG_MCA) |
| 111 | mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA; |
| 112 | #endif |
| 113 | } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) { |
Alexey Starikovskiy | d285e33 | 2008-03-17 22:08:42 +0300 | [diff] [blame] | 114 | #ifdef CONFIG_X86_NUMAQ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | mpc_oem_pci_bus(m, translation_table[mpc_record]); |
Alexey Starikovskiy | d285e33 | 2008-03-17 22:08:42 +0300 | [diff] [blame] | 116 | #endif |
Alexey Starikovskiy | a6333c3 | 2008-03-20 14:54:09 +0300 | [diff] [blame] | 117 | clear_bit(m->mpc_busid, mp_bus_not_pci); |
Alexey Starikovskiy | c0a282c | 2008-03-20 14:55:02 +0300 | [diff] [blame] | 118 | #if defined(CONFIG_EISA) || defined (CONFIG_MCA) |
| 119 | mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI; |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 120 | } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) { |
Alexey Starikovskiy | 9e0a2de | 2008-03-20 14:54:56 +0300 | [diff] [blame] | 121 | mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA; |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 122 | } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA; |
Alexey Starikovskiy | c0a282c | 2008-03-20 14:55:02 +0300 | [diff] [blame] | 124 | #endif |
Alexey Starikovskiy | f8924e7 | 2008-04-04 23:42:21 +0400 | [diff] [blame] | 125 | } else |
| 126 | printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } |
Thomas Gleixner | 85cc35f | 2008-05-25 21:21:36 +0200 | [diff] [blame] | 128 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 130 | #ifdef CONFIG_X86_IO_APIC |
| 131 | |
Alexey Starikovskiy | 857033a | 2008-03-17 22:08:05 +0300 | [diff] [blame] | 132 | static int bad_ioapic(unsigned long address) |
| 133 | { |
| 134 | if (nr_ioapics >= MAX_IO_APICS) { |
| 135 | printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded " |
| 136 | "(found %d)\n", MAX_IO_APICS, nr_ioapics); |
| 137 | panic("Recompile kernel with bigger MAX_IO_APICS!\n"); |
| 138 | } |
| 139 | if (!address) { |
| 140 | printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address" |
| 141 | " found in table, skipping!\n"); |
| 142 | return 1; |
| 143 | } |
| 144 | return 0; |
| 145 | } |
| 146 | |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 147 | static void __init MP_ioapic_info(struct mpc_config_ioapic *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { |
| 149 | if (!(m->mpc_flags & MPC_APIC_USABLE)) |
| 150 | return; |
| 151 | |
Thomas Gleixner | 64883ab | 2008-01-30 13:30:35 +0100 | [diff] [blame] | 152 | printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n", |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 153 | m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr); |
Alexey Starikovskiy | 857033a | 2008-03-17 22:08:05 +0300 | [diff] [blame] | 154 | |
| 155 | if (bad_ioapic(m->mpc_apicaddr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | return; |
Alexey Starikovskiy | 857033a | 2008-03-17 22:08:05 +0300 | [diff] [blame] | 157 | |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 158 | mp_ioapics[nr_ioapics].mp_apicaddr = m->mpc_apicaddr; |
| 159 | mp_ioapics[nr_ioapics].mp_apicid = m->mpc_apicid; |
| 160 | mp_ioapics[nr_ioapics].mp_type = m->mpc_type; |
| 161 | mp_ioapics[nr_ioapics].mp_apicver = m->mpc_apicver; |
| 162 | mp_ioapics[nr_ioapics].mp_flags = m->mpc_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | nr_ioapics++; |
| 164 | } |
| 165 | |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame^] | 166 | static void print_MP_intsrc_info(struct mpc_config_intsrc *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame^] | 168 | printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x," |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | " IRQ %02x, APIC ID %x, APIC INT %02x\n", |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 170 | m->mpc_irqtype, m->mpc_irqflag & 3, |
| 171 | (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus, |
| 172 | m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq); |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame^] | 173 | } |
| 174 | |
| 175 | static void __init print_mp_irq_info(struct mp_config_intsrc *mp_irq) |
| 176 | { |
| 177 | printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x," |
| 178 | " IRQ %02x, APIC ID %x, APIC INT %02x\n", |
| 179 | mp_irq->mp_irqtype, mp_irq->mp_irqflag & 3, |
| 180 | (mp_irq->mp_irqflag >> 2) & 3, mp_irq->mp_srcbus, |
| 181 | mp_irq->mp_srcbusirq, mp_irq->mp_dstapic, mp_irq->mp_dstirq); |
| 182 | } |
| 183 | |
| 184 | static void assign_to_mp_irq(struct mpc_config_intsrc *m, |
| 185 | struct mp_config_intsrc *mp_irq) |
| 186 | { |
| 187 | mp_irq->mp_dstapic = m->mpc_dstapic; |
| 188 | mp_irq->mp_type = m->mpc_type; |
| 189 | mp_irq->mp_irqtype = m->mpc_irqtype; |
| 190 | mp_irq->mp_irqflag = m->mpc_irqflag; |
| 191 | mp_irq->mp_srcbus = m->mpc_srcbus; |
| 192 | mp_irq->mp_srcbusirq = m->mpc_srcbusirq; |
| 193 | mp_irq->mp_dstirq = m->mpc_dstirq; |
| 194 | } |
| 195 | |
| 196 | static void __init assign_to_mpc_intsrc(struct mp_config_intsrc *mp_irq, |
| 197 | struct mpc_config_intsrc *m) |
| 198 | { |
| 199 | m->mpc_dstapic = mp_irq->mp_dstapic; |
| 200 | m->mpc_type = mp_irq->mp_type; |
| 201 | m->mpc_irqtype = mp_irq->mp_irqtype; |
| 202 | m->mpc_irqflag = mp_irq->mp_irqflag; |
| 203 | m->mpc_srcbus = mp_irq->mp_srcbus; |
| 204 | m->mpc_srcbusirq = mp_irq->mp_srcbusirq; |
| 205 | m->mpc_dstirq = mp_irq->mp_dstirq; |
| 206 | } |
| 207 | |
| 208 | static int mp_irq_mpc_intsrc_cmp(struct mp_config_intsrc *mp_irq, |
| 209 | struct mpc_config_intsrc *m) |
| 210 | { |
| 211 | if (mp_irq->mp_dstapic != m->mpc_dstapic) |
| 212 | return 1; |
| 213 | if (mp_irq->mp_type != m->mpc_type) |
| 214 | return 2; |
| 215 | if (mp_irq->mp_irqtype != m->mpc_irqtype) |
| 216 | return 3; |
| 217 | if (mp_irq->mp_irqflag != m->mpc_irqflag) |
| 218 | return 4; |
| 219 | if (mp_irq->mp_srcbus != m->mpc_srcbus) |
| 220 | return 5; |
| 221 | if (mp_irq->mp_srcbusirq != m->mpc_srcbusirq) |
| 222 | return 6; |
| 223 | if (mp_irq->mp_dstirq != m->mpc_dstirq) |
| 224 | return 7; |
| 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | void MP_intsrc_info(struct mpc_config_intsrc *m) |
| 230 | { |
| 231 | int i; |
| 232 | |
| 233 | print_MP_intsrc_info(m); |
| 234 | |
| 235 | for (i = 0; i < mp_irq_entries; i++) { |
| 236 | if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m)) |
| 237 | return; |
| 238 | } |
| 239 | |
| 240 | assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | if (++mp_irq_entries == MAX_IRQ_SOURCES) |
| 242 | panic("Max # of irq sources exceeded!!\n"); |
| 243 | } |
| 244 | |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 245 | #endif |
| 246 | |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 247 | static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { |
Yinghai Lu | 11a62a0 | 2008-05-12 15:43:38 +0200 | [diff] [blame] | 249 | printk(KERN_INFO "Lint: type %d, pol %d, trig %d, bus %02x," |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | " IRQ %02x, APIC ID %x, APIC LINT %02x\n", |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 251 | m->mpc_irqtype, m->mpc_irqflag & 3, |
| 252 | (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid, |
| 253 | m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | #ifdef CONFIG_X86_NUMAQ |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 257 | static void __init MP_translation_info(struct mpc_config_translation *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 259 | printk(KERN_INFO |
| 260 | "Translation: record %d, type %d, quad %d, global %d, local %d\n", |
| 261 | mpc_record, m->trans_type, m->trans_quad, m->trans_global, |
| 262 | m->trans_local); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 264 | if (mpc_record >= MAX_MPC_ENTRY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n"); |
| 266 | else |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 267 | translation_table[mpc_record] = m; /* stash this for later */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad)) |
| 269 | node_set_online(m->trans_quad); |
| 270 | } |
| 271 | |
| 272 | /* |
| 273 | * Read/parse the MPC oem tables |
| 274 | */ |
| 275 | |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 276 | static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable, |
| 277 | unsigned short oemsize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 279 | int count = sizeof(*oemtable); /* the header size */ |
| 280 | unsigned char *oemptr = ((unsigned char *)oemtable) + count; |
| 281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | mpc_record = 0; |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 283 | printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n", |
| 284 | oemtable); |
| 285 | if (memcmp(oemtable->oem_signature, MPC_OEM_SIGNATURE, 4)) { |
| 286 | printk(KERN_WARNING |
| 287 | "SMP mpc oemtable: bad signature [%c%c%c%c]!\n", |
| 288 | oemtable->oem_signature[0], oemtable->oem_signature[1], |
| 289 | oemtable->oem_signature[2], oemtable->oem_signature[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | return; |
| 291 | } |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 292 | if (mpf_checksum((unsigned char *)oemtable, oemtable->oem_length)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | printk(KERN_WARNING "SMP oem mptable: checksum error!\n"); |
| 294 | return; |
| 295 | } |
| 296 | while (count < oemtable->oem_length) { |
| 297 | switch (*oemptr) { |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 298 | case MP_TRANSLATION: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | { |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 300 | struct mpc_config_translation *m = |
| 301 | (struct mpc_config_translation *)oemptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | MP_translation_info(m); |
| 303 | oemptr += sizeof(*m); |
| 304 | count += sizeof(*m); |
| 305 | ++mpc_record; |
| 306 | break; |
| 307 | } |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 308 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | { |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 310 | printk(KERN_WARNING |
| 311 | "Unrecognised OEM table entry type! - %d\n", |
| 312 | (int)*oemptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | return; |
| 314 | } |
| 315 | } |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 316 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | static inline void mps_oem_check(struct mp_config_table *mpc, char *oem, |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 320 | char *productid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | { |
| 322 | if (strncmp(oem, "IBM NUMA", 8)) |
| 323 | printk("Warning! May not be a NUMA-Q system!\n"); |
| 324 | if (mpc->mpc_oemptr) |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 325 | smp_read_mpc_oem((struct mp_config_oemtable *)mpc->mpc_oemptr, |
| 326 | mpc->mpc_oemsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 328 | #endif /* CONFIG_X86_NUMAQ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | /* |
| 331 | * Read/parse the MPC |
| 332 | */ |
| 333 | |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame^] | 334 | static int __init smp_check_mpc(struct mp_config_table *mpc, char *oem, |
| 335 | char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 338 | if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) { |
Alexey Starikovskiy | e950bea | 2008-04-04 23:42:27 +0400 | [diff] [blame] | 339 | printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n", |
| 340 | mpc->mpc_signature[0], mpc->mpc_signature[1], |
| 341 | mpc->mpc_signature[2], mpc->mpc_signature[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | return 0; |
| 343 | } |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 344 | if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) { |
Alexey Starikovskiy | e950bea | 2008-04-04 23:42:27 +0400 | [diff] [blame] | 345 | printk(KERN_ERR "MPTABLE: checksum error!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | return 0; |
| 347 | } |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 348 | if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) { |
Alexey Starikovskiy | e950bea | 2008-04-04 23:42:27 +0400 | [diff] [blame] | 349 | printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n", |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 350 | mpc->mpc_spec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | return 0; |
| 352 | } |
| 353 | if (!mpc->mpc_lapic) { |
Alexey Starikovskiy | e950bea | 2008-04-04 23:42:27 +0400 | [diff] [blame] | 354 | printk(KERN_ERR "MPTABLE: null local APIC address!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | return 0; |
| 356 | } |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 357 | memcpy(oem, mpc->mpc_oem, 8); |
| 358 | oem[8] = 0; |
Yinghai Lu | 11a62a0 | 2008-05-12 15:43:38 +0200 | [diff] [blame] | 359 | printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 361 | memcpy(str, mpc->mpc_productid, 12); |
| 362 | str[12] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
Yinghai Lu | 11a62a0 | 2008-05-12 15:43:38 +0200 | [diff] [blame] | 364 | printk(KERN_INFO "MPTABLE: Product ID: %s\n", str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
Alexey Starikovskiy | e950bea | 2008-04-04 23:42:27 +0400 | [diff] [blame] | 366 | printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame^] | 368 | return 1; |
| 369 | } |
| 370 | |
| 371 | static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early) |
| 372 | { |
| 373 | char str[16]; |
| 374 | char oem[10]; |
| 375 | |
| 376 | int count = sizeof(*mpc); |
| 377 | unsigned char *mpt = ((unsigned char *)mpc) + count; |
| 378 | |
| 379 | if (!smp_check_mpc(mpc, oem, str)) |
| 380 | return 0; |
| 381 | |
| 382 | #ifdef CONFIG_X86_32 |
| 383 | mps_oem_check(mpc, oem, str); |
| 384 | #endif |
| 385 | |
Alexey Starikovskiy | e950bea | 2008-04-04 23:42:27 +0400 | [diff] [blame] | 386 | /* save the local APIC address, it might be non-default */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | if (!acpi_lapic) |
| 388 | mp_lapic_addr = mpc->mpc_lapic; |
| 389 | |
Alexey Starikovskiy | 888032c | 2008-04-04 23:42:09 +0400 | [diff] [blame] | 390 | if (early) |
| 391 | return 1; |
| 392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | /* |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 394 | * Now process the configuration blocks. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | */ |
Alexey Starikovskiy | 8642050 | 2008-03-17 22:08:55 +0300 | [diff] [blame] | 396 | #ifdef CONFIG_X86_NUMAQ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | mpc_record = 0; |
Alexey Starikovskiy | 8642050 | 2008-03-17 22:08:55 +0300 | [diff] [blame] | 398 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | while (count < mpc->mpc_length) { |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 400 | switch (*mpt) { |
| 401 | case MP_PROCESSOR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | { |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 403 | struct mpc_config_processor *m = |
| 404 | (struct mpc_config_processor *)mpt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | /* ACPI may have already provided this data */ |
| 406 | if (!acpi_lapic) |
| 407 | MP_processor_info(m); |
| 408 | mpt += sizeof(*m); |
| 409 | count += sizeof(*m); |
| 410 | break; |
| 411 | } |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 412 | case MP_BUS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | { |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 414 | struct mpc_config_bus *m = |
| 415 | (struct mpc_config_bus *)mpt; |
Thomas Gleixner | 85cc35f | 2008-05-25 21:21:36 +0200 | [diff] [blame] | 416 | #ifdef CONFIG_X86_IO_APIC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | MP_bus_info(m); |
Thomas Gleixner | 85cc35f | 2008-05-25 21:21:36 +0200 | [diff] [blame] | 418 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | mpt += sizeof(*m); |
| 420 | count += sizeof(*m); |
| 421 | break; |
| 422 | } |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 423 | case MP_IOAPIC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | { |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 425 | #ifdef CONFIG_X86_IO_APIC |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 426 | struct mpc_config_ioapic *m = |
| 427 | (struct mpc_config_ioapic *)mpt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | MP_ioapic_info(m); |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 429 | #endif |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 430 | mpt += sizeof(struct mpc_config_ioapic); |
| 431 | count += sizeof(struct mpc_config_ioapic); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | break; |
| 433 | } |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 434 | case MP_INTSRC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | { |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 436 | #ifdef CONFIG_X86_IO_APIC |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 437 | struct mpc_config_intsrc *m = |
| 438 | (struct mpc_config_intsrc *)mpt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
| 440 | MP_intsrc_info(m); |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 441 | #endif |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 442 | mpt += sizeof(struct mpc_config_intsrc); |
| 443 | count += sizeof(struct mpc_config_intsrc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | break; |
| 445 | } |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 446 | case MP_LINTSRC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | { |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 448 | struct mpc_config_lintsrc *m = |
| 449 | (struct mpc_config_lintsrc *)mpt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | MP_lintsrc_info(m); |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 451 | mpt += sizeof(*m); |
| 452 | count += sizeof(*m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | break; |
| 454 | } |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 455 | default: |
Yinghai Lu | 711554d | 2008-04-07 11:36:39 -0700 | [diff] [blame] | 456 | /* wrong mptable */ |
| 457 | printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n"); |
| 458 | printk(KERN_ERR "type %x\n", *mpt); |
| 459 | print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16, |
| 460 | 1, mpc, mpc->mpc_length, 1); |
| 461 | count = mpc->mpc_length; |
| 462 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | } |
Alexey Starikovskiy | 8642050 | 2008-03-17 22:08:55 +0300 | [diff] [blame] | 464 | #ifdef CONFIG_X86_NUMAQ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | ++mpc_record; |
Alexey Starikovskiy | 8642050 | 2008-03-17 22:08:55 +0300 | [diff] [blame] | 466 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | } |
Ingo Molnar | 3c43f03 | 2007-05-02 19:27:04 +0200 | [diff] [blame] | 468 | setup_apic_routing(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | if (!num_processors) |
Alexey Starikovskiy | e950bea | 2008-04-04 23:42:27 +0400 | [diff] [blame] | 470 | printk(KERN_ERR "MPTABLE: no processors registered!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | return num_processors; |
| 472 | } |
| 473 | |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 474 | #ifdef CONFIG_X86_IO_APIC |
| 475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | static int __init ELCR_trigger(unsigned int irq) |
| 477 | { |
| 478 | unsigned int port; |
| 479 | |
| 480 | port = 0x4d0 + (irq >> 3); |
| 481 | return (inb(port) >> (irq & 7)) & 1; |
| 482 | } |
| 483 | |
| 484 | static void __init construct_default_ioirq_mptable(int mpc_default_type) |
| 485 | { |
| 486 | struct mpc_config_intsrc intsrc; |
| 487 | int i; |
| 488 | int ELCR_fallback = 0; |
| 489 | |
| 490 | intsrc.mpc_type = MP_INTSRC; |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 491 | intsrc.mpc_irqflag = 0; /* conforming */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | intsrc.mpc_srcbus = 0; |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 493 | intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
| 495 | intsrc.mpc_irqtype = mp_INT; |
| 496 | |
| 497 | /* |
| 498 | * If true, we have an ISA/PCI system with no IRQ entries |
| 499 | * in the MP table. To prevent the PCI interrupts from being set up |
| 500 | * incorrectly, we try to use the ELCR. The sanity check to see if |
| 501 | * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can |
| 502 | * never be level sensitive, so we simply see if the ELCR agrees. |
| 503 | * If it does, we assume it's valid. |
| 504 | */ |
| 505 | if (mpc_default_type == 5) { |
Alexey Starikovskiy | 62441bf | 2008-04-04 23:42:34 +0400 | [diff] [blame] | 506 | printk(KERN_INFO "ISA/PCI bus type with no IRQ information... " |
| 507 | "falling back to ELCR\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
Alexey Starikovskiy | 62441bf | 2008-04-04 23:42:34 +0400 | [diff] [blame] | 509 | if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) || |
| 510 | ELCR_trigger(13)) |
| 511 | printk(KERN_ERR "ELCR contains invalid data... " |
| 512 | "not using ELCR\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | else { |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 514 | printk(KERN_INFO |
| 515 | "Using ELCR to identify PCI interrupts\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | ELCR_fallback = 1; |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | for (i = 0; i < 16; i++) { |
| 521 | switch (mpc_default_type) { |
| 522 | case 2: |
| 523 | if (i == 0 || i == 13) |
| 524 | continue; /* IRQ0 & IRQ13 not connected */ |
| 525 | /* fall through */ |
| 526 | default: |
| 527 | if (i == 2) |
| 528 | continue; /* IRQ2 is never connected */ |
| 529 | } |
| 530 | |
| 531 | if (ELCR_fallback) { |
| 532 | /* |
| 533 | * If the ELCR indicates a level-sensitive interrupt, we |
| 534 | * copy that information over to the MP table in the |
| 535 | * irqflag field (level sensitive, active high polarity). |
| 536 | */ |
| 537 | if (ELCR_trigger(i)) |
| 538 | intsrc.mpc_irqflag = 13; |
| 539 | else |
| 540 | intsrc.mpc_irqflag = 0; |
| 541 | } |
| 542 | |
| 543 | intsrc.mpc_srcbusirq = i; |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 544 | intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | MP_intsrc_info(&intsrc); |
| 546 | } |
| 547 | |
| 548 | intsrc.mpc_irqtype = mp_ExtINT; |
| 549 | intsrc.mpc_srcbusirq = 0; |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 550 | intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | MP_intsrc_info(&intsrc); |
| 552 | } |
| 553 | |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 554 | |
Thomas Gleixner | 85cc35f | 2008-05-25 21:21:36 +0200 | [diff] [blame] | 555 | static void construct_ioapic_table(int mpc_default_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | struct mpc_config_ioapic ioapic; |
Thomas Gleixner | 85cc35f | 2008-05-25 21:21:36 +0200 | [diff] [blame] | 558 | struct mpc_config_bus bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | |
| 560 | bus.mpc_type = MP_BUS; |
| 561 | bus.mpc_busid = 0; |
| 562 | switch (mpc_default_type) { |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 563 | default: |
Alexey Starikovskiy | 62441bf | 2008-04-04 23:42:34 +0400 | [diff] [blame] | 564 | printk(KERN_ERR "???\nUnknown standard configuration %d\n", |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 565 | mpc_default_type); |
| 566 | /* fall through */ |
| 567 | case 1: |
| 568 | case 5: |
| 569 | memcpy(bus.mpc_bustype, "ISA ", 6); |
| 570 | break; |
| 571 | case 2: |
| 572 | case 6: |
| 573 | case 3: |
| 574 | memcpy(bus.mpc_bustype, "EISA ", 6); |
| 575 | break; |
| 576 | case 4: |
| 577 | case 7: |
| 578 | memcpy(bus.mpc_bustype, "MCA ", 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | } |
| 580 | MP_bus_info(&bus); |
| 581 | if (mpc_default_type > 4) { |
| 582 | bus.mpc_busid = 1; |
| 583 | memcpy(bus.mpc_bustype, "PCI ", 6); |
| 584 | MP_bus_info(&bus); |
| 585 | } |
| 586 | |
| 587 | ioapic.mpc_type = MP_IOAPIC; |
| 588 | ioapic.mpc_apicid = 2; |
| 589 | ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01; |
| 590 | ioapic.mpc_flags = MPC_APIC_USABLE; |
| 591 | ioapic.mpc_apicaddr = 0xFEC00000; |
| 592 | MP_ioapic_info(&ioapic); |
| 593 | |
| 594 | /* |
| 595 | * We set up most of the low 16 IO-APIC pins according to MPS rules. |
| 596 | */ |
| 597 | construct_default_ioirq_mptable(mpc_default_type); |
Thomas Gleixner | 85cc35f | 2008-05-25 21:21:36 +0200 | [diff] [blame] | 598 | } |
| 599 | #else |
| 600 | static inline void construct_ioapic_table(int mpc_default_type) { } |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 601 | #endif |
Thomas Gleixner | 85cc35f | 2008-05-25 21:21:36 +0200 | [diff] [blame] | 602 | |
| 603 | static inline void __init construct_default_ISA_mptable(int mpc_default_type) |
| 604 | { |
| 605 | struct mpc_config_processor processor; |
| 606 | struct mpc_config_lintsrc lintsrc; |
| 607 | int linttypes[2] = { mp_ExtINT, mp_NMI }; |
| 608 | int i; |
| 609 | |
| 610 | /* |
| 611 | * local APIC has default address |
| 612 | */ |
| 613 | mp_lapic_addr = APIC_DEFAULT_PHYS_BASE; |
| 614 | |
| 615 | /* |
| 616 | * 2 CPUs, numbered 0 & 1. |
| 617 | */ |
| 618 | processor.mpc_type = MP_PROCESSOR; |
| 619 | /* Either an integrated APIC or a discrete 82489DX. */ |
| 620 | processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01; |
| 621 | processor.mpc_cpuflag = CPU_ENABLED; |
| 622 | processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) | |
| 623 | (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask; |
| 624 | processor.mpc_featureflag = boot_cpu_data.x86_capability[0]; |
| 625 | processor.mpc_reserved[0] = 0; |
| 626 | processor.mpc_reserved[1] = 0; |
| 627 | for (i = 0; i < 2; i++) { |
| 628 | processor.mpc_apicid = i; |
| 629 | MP_processor_info(&processor); |
| 630 | } |
| 631 | |
| 632 | construct_ioapic_table(mpc_default_type); |
| 633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | lintsrc.mpc_type = MP_LINTSRC; |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 635 | lintsrc.mpc_irqflag = 0; /* conforming */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | lintsrc.mpc_srcbusid = 0; |
| 637 | lintsrc.mpc_srcbusirq = 0; |
| 638 | lintsrc.mpc_destapic = MP_APIC_ALL; |
| 639 | for (i = 0; i < 2; i++) { |
| 640 | lintsrc.mpc_irqtype = linttypes[i]; |
| 641 | lintsrc.mpc_destapiclint = i; |
| 642 | MP_lintsrc_info(&lintsrc); |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | static struct intel_mp_floating *mpf_found; |
| 647 | |
| 648 | /* |
| 649 | * Scan the memory blocks for an SMP configuration block. |
| 650 | */ |
Alexey Starikovskiy | 888032c | 2008-04-04 23:42:09 +0400 | [diff] [blame] | 651 | static void __init __get_smp_config(unsigned early) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | { |
| 653 | struct intel_mp_floating *mpf = mpf_found; |
| 654 | |
Alexey Starikovskiy | 888032c | 2008-04-04 23:42:09 +0400 | [diff] [blame] | 655 | if (acpi_lapic && early) |
| 656 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | /* |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 658 | * ACPI supports both logical (e.g. Hyper-Threading) and physical |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | * processors, where MPS only supports physical. |
| 660 | */ |
| 661 | if (acpi_lapic && acpi_ioapic) { |
Alexey Starikovskiy | 4421b1c | 2008-04-04 23:42:40 +0400 | [diff] [blame] | 662 | printk(KERN_INFO "Using ACPI (MADT) for SMP configuration " |
| 663 | "information\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | return; |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 665 | } else if (acpi_lapic) |
Alexey Starikovskiy | 4421b1c | 2008-04-04 23:42:40 +0400 | [diff] [blame] | 666 | printk(KERN_INFO "Using ACPI for processor (LAPIC) " |
| 667 | "configuration information\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 669 | printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n", |
| 670 | mpf->mpf_specification); |
Alexey Starikovskiy | b3e2416 | 2008-05-23 01:54:44 +0400 | [diff] [blame] | 671 | #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32) |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 672 | if (mpf->mpf_feature2 & (1 << 7)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | printk(KERN_INFO " IMCR and PIC compatibility mode.\n"); |
| 674 | pic_mode = 1; |
| 675 | } else { |
| 676 | printk(KERN_INFO " Virtual Wire compatibility mode.\n"); |
| 677 | pic_mode = 0; |
| 678 | } |
Alexey Starikovskiy | 4421b1c | 2008-04-04 23:42:40 +0400 | [diff] [blame] | 679 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | /* |
| 681 | * Now see if we need to read further. |
| 682 | */ |
| 683 | if (mpf->mpf_feature1 != 0) { |
Alexey Starikovskiy | 888032c | 2008-04-04 23:42:09 +0400 | [diff] [blame] | 684 | if (early) { |
| 685 | /* |
| 686 | * local APIC has default address |
| 687 | */ |
| 688 | mp_lapic_addr = APIC_DEFAULT_PHYS_BASE; |
| 689 | return; |
| 690 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 692 | printk(KERN_INFO "Default MP configuration #%d\n", |
| 693 | mpf->mpf_feature1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | construct_default_ISA_mptable(mpf->mpf_feature1); |
| 695 | |
| 696 | } else if (mpf->mpf_physptr) { |
| 697 | |
| 698 | /* |
| 699 | * Read the physical hardware table. Anything here will |
| 700 | * override the defaults. |
| 701 | */ |
Alexey Starikovskiy | 888032c | 2008-04-04 23:42:09 +0400 | [diff] [blame] | 702 | if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) { |
Alexey Starikovskiy | bab4b27 | 2008-05-19 19:47:03 +0400 | [diff] [blame] | 703 | #ifdef CONFIG_X86_LOCAL_APIC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | smp_found_config = 0; |
Alexey Starikovskiy | bab4b27 | 2008-05-19 19:47:03 +0400 | [diff] [blame] | 705 | #endif |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 706 | printk(KERN_ERR |
| 707 | "BIOS bug, MP table errors detected!...\n"); |
Alexey Starikovskiy | 4421b1c | 2008-04-04 23:42:40 +0400 | [diff] [blame] | 708 | printk(KERN_ERR "... disabling SMP support. " |
| 709 | "(tell your hw vendor)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | return; |
| 711 | } |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 712 | |
Alexey Starikovskiy | 888032c | 2008-04-04 23:42:09 +0400 | [diff] [blame] | 713 | if (early) |
| 714 | return; |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 715 | #ifdef CONFIG_X86_IO_APIC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | /* |
| 717 | * If there are no explicit MP IRQ entries, then we are |
| 718 | * broken. We set up most of the low 16 IO-APIC pins to |
| 719 | * ISA defaults and hope it will work. |
| 720 | */ |
| 721 | if (!mp_irq_entries) { |
| 722 | struct mpc_config_bus bus; |
| 723 | |
Alexey Starikovskiy | 4421b1c | 2008-04-04 23:42:40 +0400 | [diff] [blame] | 724 | printk(KERN_ERR "BIOS bug, no explicit IRQ entries, " |
| 725 | "using default mptable. " |
| 726 | "(tell your hw vendor)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
| 728 | bus.mpc_type = MP_BUS; |
| 729 | bus.mpc_busid = 0; |
| 730 | memcpy(bus.mpc_bustype, "ISA ", 6); |
| 731 | MP_bus_info(&bus); |
| 732 | |
| 733 | construct_default_ioirq_mptable(0); |
| 734 | } |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 735 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | } else |
| 737 | BUG(); |
| 738 | |
Alexey Starikovskiy | 888032c | 2008-04-04 23:42:09 +0400 | [diff] [blame] | 739 | if (!early) |
| 740 | printk(KERN_INFO "Processors: %d\n", num_processors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | /* |
| 742 | * Only use the first configuration found. |
| 743 | */ |
| 744 | } |
| 745 | |
Alexey Starikovskiy | 888032c | 2008-04-04 23:42:09 +0400 | [diff] [blame] | 746 | void __init early_get_smp_config(void) |
| 747 | { |
| 748 | __get_smp_config(1); |
| 749 | } |
| 750 | |
| 751 | void __init get_smp_config(void) |
| 752 | { |
| 753 | __get_smp_config(0); |
| 754 | } |
| 755 | |
| 756 | static int __init smp_scan_config(unsigned long base, unsigned long length, |
| 757 | unsigned reserve) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | { |
Alexey Starikovskiy | 92fd4b7 | 2008-04-04 23:42:46 +0400 | [diff] [blame] | 759 | unsigned int *bp = phys_to_virt(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | struct intel_mp_floating *mpf; |
| 761 | |
Yinghai Lu | 11a62a0 | 2008-05-12 15:43:38 +0200 | [diff] [blame] | 762 | printk(KERN_DEBUG "Scan SMP from %p for %ld bytes.\n", bp, length); |
Akinobu Mita | 5d47a27 | 2008-04-19 23:55:11 +0900 | [diff] [blame] | 763 | BUILD_BUG_ON(sizeof(*mpf) != 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | |
| 765 | while (length > 0) { |
| 766 | mpf = (struct intel_mp_floating *)bp; |
| 767 | if ((*bp == SMP_MAGIC_IDENT) && |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 768 | (mpf->mpf_length == 1) && |
| 769 | !mpf_checksum((unsigned char *)bp, 16) && |
| 770 | ((mpf->mpf_specification == 1) |
| 771 | || (mpf->mpf_specification == 4))) { |
Alexey Starikovskiy | bab4b27 | 2008-05-19 19:47:03 +0400 | [diff] [blame] | 772 | #ifdef CONFIG_X86_LOCAL_APIC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | smp_found_config = 1; |
Alexey Starikovskiy | bab4b27 | 2008-05-19 19:47:03 +0400 | [diff] [blame] | 774 | #endif |
Alexey Starikovskiy | 92fd4b7 | 2008-04-04 23:42:46 +0400 | [diff] [blame] | 775 | mpf_found = mpf; |
| 776 | #ifdef CONFIG_X86_32 |
Ingo Molnar | e91a3b43 | 2008-01-30 13:33:08 +0100 | [diff] [blame] | 777 | printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n", |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 778 | mpf, virt_to_phys(mpf)); |
Bernhard Walle | 72a7fe3 | 2008-02-07 00:15:17 -0800 | [diff] [blame] | 779 | reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE, |
| 780 | BOOTMEM_DEFAULT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | if (mpf->mpf_physptr) { |
| 782 | /* |
| 783 | * We cannot access to MPC table to compute |
| 784 | * table size yet, as only few megabytes from |
| 785 | * the bottom is mapped now. |
| 786 | * PC-9800's MPC table places on the very last |
| 787 | * of physical memory; so that simply reserving |
| 788 | * PAGE_SIZE from mpg->mpf_physptr yields BUG() |
| 789 | * in reserve_bootmem. |
| 790 | */ |
| 791 | unsigned long size = PAGE_SIZE; |
| 792 | unsigned long end = max_low_pfn * PAGE_SIZE; |
| 793 | if (mpf->mpf_physptr + size > end) |
| 794 | size = end - mpf->mpf_physptr; |
Bernhard Walle | 72a7fe3 | 2008-02-07 00:15:17 -0800 | [diff] [blame] | 795 | reserve_bootmem(mpf->mpf_physptr, size, |
| 796 | BOOTMEM_DEFAULT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Alexey Starikovskiy | 92fd4b7 | 2008-04-04 23:42:46 +0400 | [diff] [blame] | 799 | #else |
| 800 | if (!reserve) |
| 801 | return 1; |
| 802 | |
| 803 | reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE); |
| 804 | if (mpf->mpf_physptr) |
| 805 | reserve_bootmem_generic(mpf->mpf_physptr, |
| 806 | PAGE_SIZE); |
| 807 | #endif |
| 808 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | } |
| 810 | bp += 4; |
| 811 | length -= 16; |
| 812 | } |
| 813 | return 0; |
| 814 | } |
| 815 | |
Alexey Starikovskiy | 888032c | 2008-04-04 23:42:09 +0400 | [diff] [blame] | 816 | static void __init __find_smp_config(unsigned reserve) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | { |
| 818 | unsigned int address; |
| 819 | |
| 820 | /* |
| 821 | * FIXME: Linux assumes you have 640K of base ram.. |
| 822 | * this continues the error... |
| 823 | * |
| 824 | * 1) Scan the bottom 1K for a signature |
| 825 | * 2) Scan the top 1K of base RAM |
| 826 | * 3) Scan the 64K of bios |
| 827 | */ |
Alexey Starikovskiy | 888032c | 2008-04-04 23:42:09 +0400 | [diff] [blame] | 828 | if (smp_scan_config(0x0, 0x400, reserve) || |
| 829 | smp_scan_config(639 * 0x400, 0x400, reserve) || |
| 830 | smp_scan_config(0xF0000, 0x10000, reserve)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | return; |
| 832 | /* |
| 833 | * If it is an SMP machine we should know now, unless the |
| 834 | * configuration is in an EISA/MCA bus machine with an |
| 835 | * extended bios data area. |
| 836 | * |
| 837 | * there is a real-mode segmented pointer pointing to the |
| 838 | * 4K EBDA area at 0x40E, calculate and scan it here. |
| 839 | * |
| 840 | * NOTE! There are Linux loaders that will corrupt the EBDA |
| 841 | * area, and as such this kind of SMP config may be less |
| 842 | * trustworthy, simply because the SMP table may have been |
| 843 | * stomped on during early boot. These loaders are buggy and |
| 844 | * should be fixed. |
| 845 | * |
| 846 | * MP1.4 SPEC states to only scan first 1K of 4K EBDA. |
| 847 | */ |
| 848 | |
| 849 | address = get_bios_ebda(); |
| 850 | if (address) |
Alexey Starikovskiy | 888032c | 2008-04-04 23:42:09 +0400 | [diff] [blame] | 851 | smp_scan_config(address, 0x400, reserve); |
| 852 | } |
| 853 | |
| 854 | void __init early_find_smp_config(void) |
| 855 | { |
| 856 | __find_smp_config(0); |
| 857 | } |
| 858 | |
| 859 | void __init find_smp_config(void) |
| 860 | { |
| 861 | __find_smp_config(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | } |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame^] | 863 | |
| 864 | #ifdef CONFIG_X86_IO_APIC |
| 865 | static u8 __initdata irq_used[MAX_IRQ_SOURCES]; |
| 866 | |
| 867 | static int __init get_MP_intsrc_index(struct mpc_config_intsrc *m) |
| 868 | { |
| 869 | int i; |
| 870 | |
| 871 | if (m->mpc_irqtype != mp_INT) |
| 872 | return 0; |
| 873 | |
| 874 | if (m->mpc_irqflag != 0x0f) |
| 875 | return 0; |
| 876 | |
| 877 | /* not legacy */ |
| 878 | |
| 879 | for (i = 0; i < mp_irq_entries; i++) { |
| 880 | if (mp_irqs[i].mp_irqtype != mp_INT) |
| 881 | continue; |
| 882 | |
| 883 | if (mp_irqs[i].mp_irqflag != 0x0f) |
| 884 | continue; |
| 885 | |
| 886 | if (mp_irqs[i].mp_srcbus != m->mpc_srcbus) |
| 887 | continue; |
| 888 | if (mp_irqs[i].mp_srcbusirq != m->mpc_srcbusirq) |
| 889 | continue; |
| 890 | if (irq_used[i]) { |
| 891 | /* already claimed */ |
| 892 | return -2; |
| 893 | } |
| 894 | irq_used[i] = 1; |
| 895 | return i; |
| 896 | } |
| 897 | |
| 898 | /* not found */ |
| 899 | return -1; |
| 900 | } |
| 901 | |
| 902 | #define SPARE_SLOT_NUM 20 |
| 903 | |
| 904 | static struct mpc_config_intsrc __initdata *m_spare[SPARE_SLOT_NUM]; |
| 905 | #endif |
| 906 | |
| 907 | static int __init replace_intsrc_all(struct mp_config_table *mpc, |
| 908 | unsigned long mpc_new_phys, |
| 909 | unsigned long mpc_new_length) |
| 910 | { |
| 911 | #ifdef CONFIG_X86_IO_APIC |
| 912 | int i; |
| 913 | int nr_m_spare = 0; |
| 914 | #endif |
| 915 | |
| 916 | int count = sizeof(*mpc); |
| 917 | unsigned char *mpt = ((unsigned char *)mpc) + count; |
| 918 | |
| 919 | printk(KERN_INFO "mpc_length %x\n", mpc->mpc_length); |
| 920 | while (count < mpc->mpc_length) { |
| 921 | switch (*mpt) { |
| 922 | case MP_PROCESSOR: |
| 923 | { |
| 924 | struct mpc_config_processor *m = |
| 925 | (struct mpc_config_processor *)mpt; |
| 926 | mpt += sizeof(*m); |
| 927 | count += sizeof(*m); |
| 928 | break; |
| 929 | } |
| 930 | case MP_BUS: |
| 931 | { |
| 932 | struct mpc_config_bus *m = |
| 933 | (struct mpc_config_bus *)mpt; |
| 934 | mpt += sizeof(*m); |
| 935 | count += sizeof(*m); |
| 936 | break; |
| 937 | } |
| 938 | case MP_IOAPIC: |
| 939 | { |
| 940 | mpt += sizeof(struct mpc_config_ioapic); |
| 941 | count += sizeof(struct mpc_config_ioapic); |
| 942 | break; |
| 943 | } |
| 944 | case MP_INTSRC: |
| 945 | { |
| 946 | #ifdef CONFIG_X86_IO_APIC |
| 947 | struct mpc_config_intsrc *m = |
| 948 | (struct mpc_config_intsrc *)mpt; |
| 949 | |
| 950 | printk(KERN_INFO "OLD "); |
| 951 | print_MP_intsrc_info(m); |
| 952 | i = get_MP_intsrc_index(m); |
| 953 | if (i > 0) { |
| 954 | assign_to_mpc_intsrc(&mp_irqs[i], m); |
| 955 | printk(KERN_INFO "NEW "); |
| 956 | print_mp_irq_info(&mp_irqs[i]); |
| 957 | } else if (!i) { |
| 958 | /* legacy, do nothing */ |
| 959 | } else if (nr_m_spare < SPARE_SLOT_NUM) { |
| 960 | /* |
| 961 | * not found (-1), or duplicated (-2) |
| 962 | * are invalid entries, |
| 963 | * we need to use the slot later |
| 964 | */ |
| 965 | m_spare[nr_m_spare] = m; |
| 966 | nr_m_spare++; |
| 967 | } |
| 968 | #endif |
| 969 | mpt += sizeof(struct mpc_config_intsrc); |
| 970 | count += sizeof(struct mpc_config_intsrc); |
| 971 | break; |
| 972 | } |
| 973 | case MP_LINTSRC: |
| 974 | { |
| 975 | struct mpc_config_lintsrc *m = |
| 976 | (struct mpc_config_lintsrc *)mpt; |
| 977 | mpt += sizeof(*m); |
| 978 | count += sizeof(*m); |
| 979 | break; |
| 980 | } |
| 981 | default: |
| 982 | /* wrong mptable */ |
| 983 | printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n"); |
| 984 | printk(KERN_ERR "type %x\n", *mpt); |
| 985 | print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16, |
| 986 | 1, mpc, mpc->mpc_length, 1); |
| 987 | goto out; |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | #ifdef CONFIG_X86_IO_APIC |
| 992 | for (i = 0; i < mp_irq_entries; i++) { |
| 993 | if (irq_used[i]) |
| 994 | continue; |
| 995 | |
| 996 | if (mp_irqs[i].mp_irqtype != mp_INT) |
| 997 | continue; |
| 998 | |
| 999 | if (mp_irqs[i].mp_irqflag != 0x0f) |
| 1000 | continue; |
| 1001 | |
| 1002 | if (nr_m_spare > 0) { |
| 1003 | printk(KERN_INFO "*NEW* found "); |
| 1004 | nr_m_spare--; |
| 1005 | assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]); |
| 1006 | m_spare[nr_m_spare] = NULL; |
| 1007 | } else { |
| 1008 | struct mpc_config_intsrc *m = |
| 1009 | (struct mpc_config_intsrc *)mpt; |
| 1010 | count += sizeof(struct mpc_config_intsrc); |
| 1011 | if (!mpc_new_phys) { |
| 1012 | printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count); |
| 1013 | } else { |
| 1014 | if (count <= mpc_new_length) |
| 1015 | printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count); |
| 1016 | else { |
| 1017 | printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length); |
| 1018 | goto out; |
| 1019 | } |
| 1020 | } |
| 1021 | assign_to_mpc_intsrc(&mp_irqs[i], m); |
| 1022 | mpc->mpc_length = count; |
| 1023 | mpt += sizeof(struct mpc_config_intsrc); |
| 1024 | } |
| 1025 | print_mp_irq_info(&mp_irqs[i]); |
| 1026 | } |
| 1027 | #endif |
| 1028 | out: |
| 1029 | /* update checksum */ |
| 1030 | mpc->mpc_checksum = 0; |
| 1031 | mpc->mpc_checksum -= mpf_checksum((unsigned char *)mpc, |
| 1032 | mpc->mpc_length); |
| 1033 | |
| 1034 | return 0; |
| 1035 | } |
| 1036 | |
| 1037 | int __initdata enable_update_mptable; |
| 1038 | |
| 1039 | static int __init update_mptable_setup(char *str) |
| 1040 | { |
| 1041 | enable_update_mptable = 1; |
| 1042 | return 0; |
| 1043 | } |
| 1044 | early_param("update_mptable", update_mptable_setup); |
| 1045 | |
| 1046 | static unsigned long __initdata mpc_new_phys; |
| 1047 | static unsigned long mpc_new_length __initdata = 4096; |
| 1048 | |
| 1049 | /* alloc_mptable or alloc_mptable=4k */ |
| 1050 | static int __initdata alloc_mptable; |
| 1051 | static int __init parse_alloc_mptable_opt(char *p) |
| 1052 | { |
| 1053 | enable_update_mptable = 1; |
| 1054 | alloc_mptable = 1; |
| 1055 | if (!p) |
| 1056 | return 0; |
| 1057 | mpc_new_length = memparse(p, &p); |
| 1058 | return 0; |
| 1059 | } |
| 1060 | early_param("alloc_mptable", parse_alloc_mptable_opt); |
| 1061 | |
| 1062 | void __init early_reserve_e820_mpc_new(void) |
| 1063 | { |
| 1064 | if (enable_update_mptable && alloc_mptable) { |
| 1065 | u64 startt = 0; |
| 1066 | #ifdef CONFIG_X86_TRAMPOLINE |
| 1067 | startt = TRAMPOLINE_BASE; |
| 1068 | #endif |
| 1069 | mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4); |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | static int __init update_mp_table(void) |
| 1074 | { |
| 1075 | char str[16]; |
| 1076 | char oem[10]; |
| 1077 | struct intel_mp_floating *mpf; |
| 1078 | struct mp_config_table *mpc; |
| 1079 | struct mp_config_table *mpc_new; |
| 1080 | |
| 1081 | if (!enable_update_mptable) |
| 1082 | return 0; |
| 1083 | |
| 1084 | mpf = mpf_found; |
| 1085 | if (!mpf) |
| 1086 | return 0; |
| 1087 | |
| 1088 | /* |
| 1089 | * Now see if we need to go further. |
| 1090 | */ |
| 1091 | if (mpf->mpf_feature1 != 0) |
| 1092 | return 0; |
| 1093 | |
| 1094 | if (!mpf->mpf_physptr) |
| 1095 | return 0; |
| 1096 | |
| 1097 | mpc = phys_to_virt(mpf->mpf_physptr); |
| 1098 | |
| 1099 | if (!smp_check_mpc(mpc, oem, str)) |
| 1100 | return 0; |
| 1101 | |
| 1102 | printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf)); |
| 1103 | printk(KERN_INFO "mpf_physptr: %x\n", mpf->mpf_physptr); |
| 1104 | |
| 1105 | if (mpc_new_phys && mpc->mpc_length > mpc_new_length) { |
| 1106 | mpc_new_phys = 0; |
| 1107 | printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n", |
| 1108 | mpc_new_length); |
| 1109 | } |
| 1110 | |
| 1111 | if (!mpc_new_phys) { |
| 1112 | unsigned char old, new; |
| 1113 | /* check if we can change the postion */ |
| 1114 | mpc->mpc_checksum = 0; |
| 1115 | old = mpf_checksum((unsigned char *)mpc, mpc->mpc_length); |
| 1116 | mpc->mpc_checksum = 0xff; |
| 1117 | new = mpf_checksum((unsigned char *)mpc, mpc->mpc_length); |
| 1118 | if (old == new) { |
| 1119 | printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n"); |
| 1120 | return 0; |
| 1121 | } |
| 1122 | printk(KERN_INFO "use in-positon replacing\n"); |
| 1123 | } else { |
| 1124 | mpf->mpf_physptr = mpc_new_phys; |
| 1125 | mpc_new = phys_to_virt(mpc_new_phys); |
| 1126 | memcpy(mpc_new, mpc, mpc->mpc_length); |
| 1127 | mpc = mpc_new; |
| 1128 | /* check if we can modify that */ |
| 1129 | if (mpc_new_phys - mpf->mpf_physptr) { |
| 1130 | struct intel_mp_floating *mpf_new; |
| 1131 | /* steal 16 bytes from [0, 1k) */ |
| 1132 | printk(KERN_INFO "mpf new: %x\n", 0x400 - 16); |
| 1133 | mpf_new = phys_to_virt(0x400 - 16); |
| 1134 | memcpy(mpf_new, mpf, 16); |
| 1135 | mpf = mpf_new; |
| 1136 | mpf->mpf_physptr = mpc_new_phys; |
| 1137 | } |
| 1138 | mpf->mpf_checksum = 0; |
| 1139 | mpf->mpf_checksum -= mpf_checksum((unsigned char *)mpf, 16); |
| 1140 | printk(KERN_INFO "mpf_physptr new: %x\n", mpf->mpf_physptr); |
| 1141 | } |
| 1142 | |
| 1143 | /* |
| 1144 | * only replace the one with mp_INT and |
| 1145 | * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, |
| 1146 | * already in mp_irqs , stored by ... and mp_config_acpi_gsi, |
| 1147 | * may need pci=routeirq for all coverage |
| 1148 | */ |
| 1149 | replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length); |
| 1150 | |
| 1151 | return 0; |
| 1152 | } |
| 1153 | |
| 1154 | late_initcall(update_mp_table); |