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 | * |
Alan Cox | 87c6fe2 | 2009-01-05 14:08:04 +0000 | [diff] [blame] | 5 | * (c) 1995 Alan Cox, Building #3 <alan@lxorguk.ukuu.org.uk> |
Ingo Molnar | 8f47e16 | 2009-01-31 02:03:42 +0100 | [diff] [blame] | 6 | * (c) 1998, 1999, 2000, 2009 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> |
Yinghai Lu | 72d7c3b | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 14 | #include <linux/memblock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/kernel_stat.h> |
| 16 | #include <linux/mc146818rtc.h> |
| 17 | #include <linux/bitops.h> |
Alexey Starikovskiy | 85bddde | 2008-04-04 23:43:18 +0400 | [diff] [blame] | 18 | #include <linux/acpi.h> |
| 19 | #include <linux/module.h> |
Jaswinder Singh Rajput | 103ceff | 2009-01-02 23:43:25 +0530 | [diff] [blame] | 20 | #include <linux/smp.h> |
Yinghai Lu | 629e15d | 2009-05-15 13:05:16 -0700 | [diff] [blame] | 21 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/mtrr.h> |
| 24 | #include <asm/mpspec.h> |
Alexey Starikovskiy | 85bddde | 2008-04-04 23:43:18 +0400 | [diff] [blame] | 25 | #include <asm/pgalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <asm/io_apic.h> |
Alexey Starikovskiy | 85bddde | 2008-04-04 23:43:18 +0400 | [diff] [blame] | 27 | #include <asm/proto.h> |
Alexey Starikovskiy | ce3fe6b | 2008-03-17 22:08:17 +0300 | [diff] [blame] | 28 | #include <asm/bios_ebda.h> |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 29 | #include <asm/e820.h> |
| 30 | #include <asm/trampoline.h> |
Yinghai Lu | 3c9cb6d | 2008-07-19 02:07:25 -0700 | [diff] [blame] | 31 | #include <asm/setup.h> |
Jaswinder Singh Rajput | 4884d8e | 2009-01-11 18:38:55 +0530 | [diff] [blame] | 32 | #include <asm/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Ingo Molnar | 7b6aa33 | 2009-02-17 13:58:15 +0100 | [diff] [blame] | 34 | #include <asm/apic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | * Checksum an MP configuration block. |
| 37 | */ |
| 38 | |
| 39 | static int __init mpf_checksum(unsigned char *mp, int len) |
| 40 | { |
| 41 | int sum = 0; |
| 42 | |
| 43 | while (len--) |
| 44 | sum += *mp++; |
| 45 | |
| 46 | return sum & 0xFF; |
| 47 | } |
| 48 | |
Thomas Gleixner | fd6c666 | 2009-08-20 10:41:58 +0200 | [diff] [blame] | 49 | int __init default_mpc_apic_id(struct mpc_cpu *m) |
| 50 | { |
| 51 | return m->apicid; |
| 52 | } |
| 53 | |
Jaswinder Singh Rajput | f4f21b7 | 2009-01-03 15:48:52 +0530 | [diff] [blame] | 54 | static void __init MP_processor_info(struct mpc_cpu *m) |
Alexey Starikovskiy | c853c67 | 2008-03-27 23:54:13 +0300 | [diff] [blame] | 55 | { |
| 56 | int apicid; |
Alexey Starikovskiy | 746f224 | 2008-04-04 23:42:15 +0400 | [diff] [blame] | 57 | char *bootup_cpu = ""; |
Alexey Starikovskiy | c853c67 | 2008-03-27 23:54:13 +0300 | [diff] [blame] | 58 | |
Jaswinder Singh Rajput | c456382 | 2009-01-04 21:58:25 +0530 | [diff] [blame] | 59 | if (!(m->cpuflag & CPU_ENABLED)) { |
Glauber Costa | 7b1292e | 2008-03-03 14:12:41 -0300 | [diff] [blame] | 60 | disabled_cpus++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | return; |
Glauber Costa | 7b1292e | 2008-03-03 14:12:41 -0300 | [diff] [blame] | 62 | } |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 63 | |
Thomas Gleixner | fd6c666 | 2009-08-20 10:41:58 +0200 | [diff] [blame] | 64 | apicid = x86_init.mpparse.mpc_apic_id(m); |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 65 | |
Jaswinder Singh Rajput | c456382 | 2009-01-04 21:58:25 +0530 | [diff] [blame] | 66 | if (m->cpuflag & CPU_BOOTPROCESSOR) { |
Alexey Starikovskiy | 746f224 | 2008-04-04 23:42:15 +0400 | [diff] [blame] | 67 | bootup_cpu = " (Bootup-CPU)"; |
Jaswinder Singh Rajput | c456382 | 2009-01-04 21:58:25 +0530 | [diff] [blame] | 68 | boot_cpu_physical_apicid = m->apicid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Jaswinder Singh Rajput | c456382 | 2009-01-04 21:58:25 +0530 | [diff] [blame] | 71 | printk(KERN_INFO "Processor #%d%s\n", m->apicid, bootup_cpu); |
| 72 | generic_processor_info(apicid, m->apicver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Thomas Gleixner | 85cc35f | 2008-05-25 21:21:36 +0200 | [diff] [blame] | 75 | #ifdef CONFIG_X86_IO_APIC |
Thomas Gleixner | 90e1c69 | 2009-08-20 12:34:47 +0200 | [diff] [blame] | 76 | void __init default_mpc_oem_bus_info(struct mpc_bus *m, char *str) |
| 77 | { |
| 78 | memcpy(str, m->bustype, 6); |
| 79 | str[6] = 0; |
| 80 | apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->busid, str); |
| 81 | } |
| 82 | |
Jaswinder Singh Rajput | 00fb860 | 2009-01-03 15:47:32 +0530 | [diff] [blame] | 83 | static void __init MP_bus_info(struct mpc_bus *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
| 85 | char str[7]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Thomas Gleixner | 90e1c69 | 2009-08-20 12:34:47 +0200 | [diff] [blame] | 87 | x86_init.mpparse.mpc_oem_bus_info(m, str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Andi Kleen | 5e4edbb | 2006-09-26 10:52:35 +0200 | [diff] [blame] | 89 | #if MAX_MP_BUSSES < 256 |
Jaswinder Singh Rajput | d4c715f | 2009-01-04 21:59:26 +0530 | [diff] [blame] | 90 | if (m->busid >= MAX_MP_BUSSES) { |
Randy Dunlap | c0ec31a | 2006-04-10 22:53:13 -0700 | [diff] [blame] | 91 | printk(KERN_WARNING "MP table busid value (%d) for bustype %s " |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 92 | " is too large, max. supported is %d\n", |
Jaswinder Singh Rajput | d4c715f | 2009-01-04 21:59:26 +0530 | [diff] [blame] | 93 | m->busid, str, MAX_MP_BUSSES - 1); |
Randy Dunlap | c0ec31a | 2006-04-10 22:53:13 -0700 | [diff] [blame] | 94 | return; |
| 95 | } |
Andi Kleen | 5e4edbb | 2006-09-26 10:52:35 +0200 | [diff] [blame] | 96 | #endif |
Randy Dunlap | c0ec31a | 2006-04-10 22:53:13 -0700 | [diff] [blame] | 97 | |
Alexey Starikovskiy | f8924e7 | 2008-04-04 23:42:21 +0400 | [diff] [blame] | 98 | if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) { |
Jaswinder Singh Rajput | d4c715f | 2009-01-04 21:59:26 +0530 | [diff] [blame] | 99 | set_bit(m->busid, mp_bus_not_pci); |
Jaswinder Singh Rajput | 103ceff | 2009-01-02 23:43:25 +0530 | [diff] [blame] | 100 | #if defined(CONFIG_EISA) || defined(CONFIG_MCA) |
Jaswinder Singh Rajput | d4c715f | 2009-01-04 21:59:26 +0530 | [diff] [blame] | 101 | mp_bus_id_to_type[m->busid] = MP_BUS_ISA; |
Alexey Starikovskiy | f8924e7 | 2008-04-04 23:42:21 +0400 | [diff] [blame] | 102 | #endif |
| 103 | } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) { |
Thomas Gleixner | 52fdb56 | 2009-08-20 12:45:33 +0200 | [diff] [blame] | 104 | if (x86_init.mpparse.mpc_oem_pci_bus) |
| 105 | x86_init.mpparse.mpc_oem_pci_bus(m); |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 106 | |
Jaswinder Singh Rajput | d4c715f | 2009-01-04 21:59:26 +0530 | [diff] [blame] | 107 | clear_bit(m->busid, mp_bus_not_pci); |
Jaswinder Singh Rajput | 103ceff | 2009-01-02 23:43:25 +0530 | [diff] [blame] | 108 | #if defined(CONFIG_EISA) || defined(CONFIG_MCA) |
Jaswinder Singh Rajput | d4c715f | 2009-01-04 21:59:26 +0530 | [diff] [blame] | 109 | mp_bus_id_to_type[m->busid] = MP_BUS_PCI; |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 110 | } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) { |
Jaswinder Singh Rajput | d4c715f | 2009-01-04 21:59:26 +0530 | [diff] [blame] | 111 | mp_bus_id_to_type[m->busid] = MP_BUS_EISA; |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 112 | } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) { |
Jaswinder Singh Rajput | d4c715f | 2009-01-04 21:59:26 +0530 | [diff] [blame] | 113 | mp_bus_id_to_type[m->busid] = MP_BUS_MCA; |
Alexey Starikovskiy | c0a282c | 2008-03-20 14:55:02 +0300 | [diff] [blame] | 114 | #endif |
Alexey Starikovskiy | f8924e7 | 2008-04-04 23:42:21 +0400 | [diff] [blame] | 115 | } else |
| 116 | printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 118 | |
Jaswinder Singh Rajput | 2b85b5f | 2009-01-03 15:49:57 +0530 | [diff] [blame] | 119 | static void __init MP_ioapic_info(struct mpc_ioapic *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { |
Jaswinder Singh Rajput | 5df82c7 | 2009-01-04 21:54:39 +0530 | [diff] [blame] | 121 | if (!(m->flags & MPC_APIC_USABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | return; |
| 123 | |
Thomas Gleixner | 64883ab | 2008-01-30 13:30:35 +0100 | [diff] [blame] | 124 | printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n", |
Jaswinder Singh Rajput | 5df82c7 | 2009-01-04 21:54:39 +0530 | [diff] [blame] | 125 | m->apicid, m->apicver, m->apicaddr); |
Alexey Starikovskiy | 857033a | 2008-03-17 22:08:05 +0300 | [diff] [blame] | 126 | |
Eric W. Biederman | a4384df | 2010-06-08 11:44:32 -0700 | [diff] [blame] | 127 | mp_register_ioapic(m->apicid, m->apicaddr, gsi_top); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Jaswinder Singh Rajput | 540d4e7 | 2009-01-03 15:50:52 +0530 | [diff] [blame] | 130 | static void print_MP_intsrc_info(struct mpc_intsrc *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
Rene Herman | eeb0d7d | 2008-08-11 17:44:57 +0200 | [diff] [blame] | 132 | apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x," |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | " IRQ %02x, APIC ID %x, APIC INT %02x\n", |
Jaswinder Singh Rajput | e253b39 | 2009-01-04 21:56:44 +0530 | [diff] [blame] | 134 | m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus, |
| 135 | m->srcbusirq, m->dstapic, m->dstirq); |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 138 | static void __init print_mp_irq_info(struct mpc_intsrc *mp_irq) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 139 | { |
Rene Herman | eeb0d7d | 2008-08-11 17:44:57 +0200 | [diff] [blame] | 140 | apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x," |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 141 | " IRQ %02x, APIC ID %x, APIC INT %02x\n", |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 142 | mp_irq->irqtype, mp_irq->irqflag & 3, |
| 143 | (mp_irq->irqflag >> 2) & 3, mp_irq->srcbus, |
| 144 | mp_irq->srcbusirq, mp_irq->dstapic, mp_irq->dstirq); |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Jaswinder Singh Rajput | 540d4e7 | 2009-01-03 15:50:52 +0530 | [diff] [blame] | 147 | static void __init assign_to_mp_irq(struct mpc_intsrc *m, |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 148 | struct mpc_intsrc *mp_irq) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 149 | { |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 150 | mp_irq->dstapic = m->dstapic; |
| 151 | mp_irq->type = m->type; |
| 152 | mp_irq->irqtype = m->irqtype; |
| 153 | mp_irq->irqflag = m->irqflag; |
| 154 | mp_irq->srcbus = m->srcbus; |
| 155 | mp_irq->srcbusirq = m->srcbusirq; |
| 156 | mp_irq->dstirq = m->dstirq; |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 159 | static void __init assign_to_mpc_intsrc(struct mpc_intsrc *mp_irq, |
Jaswinder Singh Rajput | 540d4e7 | 2009-01-03 15:50:52 +0530 | [diff] [blame] | 160 | struct mpc_intsrc *m) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 161 | { |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 162 | m->dstapic = mp_irq->dstapic; |
| 163 | m->type = mp_irq->type; |
| 164 | m->irqtype = mp_irq->irqtype; |
| 165 | m->irqflag = mp_irq->irqflag; |
| 166 | m->srcbus = mp_irq->srcbus; |
| 167 | m->srcbusirq = mp_irq->srcbusirq; |
| 168 | m->dstirq = mp_irq->dstirq; |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 171 | static int __init mp_irq_mpc_intsrc_cmp(struct mpc_intsrc *mp_irq, |
Jaswinder Singh Rajput | 540d4e7 | 2009-01-03 15:50:52 +0530 | [diff] [blame] | 172 | struct mpc_intsrc *m) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 173 | { |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 174 | if (mp_irq->dstapic != m->dstapic) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 175 | return 1; |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 176 | if (mp_irq->type != m->type) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 177 | return 2; |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 178 | if (mp_irq->irqtype != m->irqtype) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 179 | return 3; |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 180 | if (mp_irq->irqflag != m->irqflag) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 181 | return 4; |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 182 | if (mp_irq->srcbus != m->srcbus) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 183 | return 5; |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 184 | if (mp_irq->srcbusirq != m->srcbusirq) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 185 | return 6; |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 186 | if (mp_irq->dstirq != m->dstirq) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 187 | return 7; |
| 188 | |
| 189 | return 0; |
| 190 | } |
| 191 | |
Jaswinder Singh Rajput | 540d4e7 | 2009-01-03 15:50:52 +0530 | [diff] [blame] | 192 | static void __init MP_intsrc_info(struct mpc_intsrc *m) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 193 | { |
| 194 | int i; |
| 195 | |
| 196 | print_MP_intsrc_info(m); |
| 197 | |
Yinghai Lu | fcfa146 | 2008-06-18 17:29:31 -0700 | [diff] [blame] | 198 | for (i = 0; i < mp_irq_entries; i++) { |
| 199 | if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m)) |
| 200 | return; |
| 201 | } |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 202 | |
| 203 | assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | if (++mp_irq_entries == MAX_IRQ_SOURCES) |
| 205 | panic("Max # of irq sources exceeded!!\n"); |
| 206 | } |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 207 | #else /* CONFIG_X86_IO_APIC */ |
| 208 | static inline void __init MP_bus_info(struct mpc_bus *m) {} |
| 209 | static inline void __init MP_ioapic_info(struct mpc_ioapic *m) {} |
| 210 | static inline void __init MP_intsrc_info(struct mpc_intsrc *m) {} |
| 211 | #endif /* CONFIG_X86_IO_APIC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 213 | |
Jaswinder Singh Rajput | 8fb2952 | 2009-01-03 15:51:54 +0530 | [diff] [blame] | 214 | static void __init MP_lintsrc_info(struct mpc_lintsrc *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | { |
Rene Herman | eeb0d7d | 2008-08-11 17:44:57 +0200 | [diff] [blame] | 216 | apic_printk(APIC_VERBOSE, "Lint: type %d, pol %d, trig %d, bus %02x," |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | " IRQ %02x, APIC ID %x, APIC LINT %02x\n", |
Jaswinder Singh Rajput | b5ced7c | 2009-01-04 21:55:53 +0530 | [diff] [blame] | 218 | m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbusid, |
| 219 | m->srcbusirq, m->destapic, m->destapiclint); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | /* |
| 223 | * Read/parse the MPC |
| 224 | */ |
| 225 | |
Jaswinder Singh Rajput | f29521e | 2009-01-03 15:46:57 +0530 | [diff] [blame] | 226 | static int __init smp_check_mpc(struct mpc_table *mpc, char *oem, char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
Jaswinder Singh Rajput | 6c65da5 | 2009-01-04 22:22:56 +0530 | [diff] [blame] | 229 | if (memcmp(mpc->signature, MPC_SIGNATURE, 4)) { |
Alexey Starikovskiy | e950bea | 2008-04-04 23:42:27 +0400 | [diff] [blame] | 230 | printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n", |
Jaswinder Singh Rajput | 6c65da5 | 2009-01-04 22:22:56 +0530 | [diff] [blame] | 231 | mpc->signature[0], mpc->signature[1], |
| 232 | mpc->signature[2], mpc->signature[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | return 0; |
| 234 | } |
Jaswinder Singh Rajput | 6c65da5 | 2009-01-04 22:22:56 +0530 | [diff] [blame] | 235 | if (mpf_checksum((unsigned char *)mpc, mpc->length)) { |
Alexey Starikovskiy | e950bea | 2008-04-04 23:42:27 +0400 | [diff] [blame] | 236 | printk(KERN_ERR "MPTABLE: checksum error!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | return 0; |
| 238 | } |
Jaswinder Singh Rajput | 6c65da5 | 2009-01-04 22:22:56 +0530 | [diff] [blame] | 239 | if (mpc->spec != 0x01 && mpc->spec != 0x04) { |
Alexey Starikovskiy | e950bea | 2008-04-04 23:42:27 +0400 | [diff] [blame] | 240 | printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n", |
Jaswinder Singh Rajput | 6c65da5 | 2009-01-04 22:22:56 +0530 | [diff] [blame] | 241 | mpc->spec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | return 0; |
| 243 | } |
Jaswinder Singh Rajput | 6c65da5 | 2009-01-04 22:22:56 +0530 | [diff] [blame] | 244 | if (!mpc->lapic) { |
Alexey Starikovskiy | e950bea | 2008-04-04 23:42:27 +0400 | [diff] [blame] | 245 | printk(KERN_ERR "MPTABLE: null local APIC address!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | return 0; |
| 247 | } |
Jaswinder Singh Rajput | 6c65da5 | 2009-01-04 22:22:56 +0530 | [diff] [blame] | 248 | memcpy(oem, mpc->oem, 8); |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 249 | oem[8] = 0; |
Yinghai Lu | 11a62a0 | 2008-05-12 15:43:38 +0200 | [diff] [blame] | 250 | printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Jaswinder Singh Rajput | 6c65da5 | 2009-01-04 22:22:56 +0530 | [diff] [blame] | 252 | memcpy(str, mpc->productid, 12); |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 253 | str[12] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Yinghai Lu | 11a62a0 | 2008-05-12 15:43:38 +0200 | [diff] [blame] | 255 | printk(KERN_INFO "MPTABLE: Product ID: %s\n", str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Jaswinder Singh Rajput | 6c65da5 | 2009-01-04 22:22:56 +0530 | [diff] [blame] | 257 | printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->lapic); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 259 | return 1; |
| 260 | } |
| 261 | |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 262 | static void skip_entry(unsigned char **ptr, int *count, int size) |
| 263 | { |
| 264 | *ptr += size; |
| 265 | *count += size; |
| 266 | } |
| 267 | |
Jaswinder Singh Rajput | 5a5737e | 2009-03-21 13:28:39 +0530 | [diff] [blame] | 268 | static void __init smp_dump_mptable(struct mpc_table *mpc, unsigned char *mpt) |
| 269 | { |
| 270 | printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n" |
| 271 | "type %x\n", *mpt); |
| 272 | print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16, |
| 273 | 1, mpc, mpc->length, 1); |
| 274 | } |
| 275 | |
Thomas Gleixner | 7230214 | 2009-08-20 12:18:32 +0200 | [diff] [blame] | 276 | void __init default_smp_read_mpc_oem(struct mpc_table *mpc) { } |
| 277 | |
Eric W. Biederman | 5989cd6 | 2010-08-04 13:30:27 -0700 | [diff] [blame] | 278 | static void __init smp_register_lapic_address(unsigned long address) |
| 279 | { |
| 280 | mp_lapic_addr = address; |
| 281 | |
| 282 | set_fixmap_nocache(FIX_APIC_BASE, address); |
| 283 | if (boot_cpu_physical_apicid == -1U) { |
| 284 | boot_cpu_physical_apicid = read_apic_id(); |
| 285 | apic_version[boot_cpu_physical_apicid] = |
| 286 | GET_APIC_VERSION(apic_read(APIC_LVR)); |
| 287 | } |
| 288 | } |
| 289 | |
Jaswinder Singh Rajput | f29521e | 2009-01-03 15:46:57 +0530 | [diff] [blame] | 290 | static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 291 | { |
| 292 | char str[16]; |
| 293 | char oem[10]; |
| 294 | |
| 295 | int count = sizeof(*mpc); |
| 296 | unsigned char *mpt = ((unsigned char *)mpc) + count; |
| 297 | |
| 298 | if (!smp_check_mpc(mpc, oem, str)) |
| 299 | return 0; |
| 300 | |
| 301 | #ifdef CONFIG_X86_32 |
Ingo Molnar | 9c76424 | 2009-01-28 13:44:32 +0100 | [diff] [blame] | 302 | generic_mps_oem_check(mpc, oem, str); |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 303 | #endif |
Alexey Starikovskiy | e950bea | 2008-04-04 23:42:27 +0400 | [diff] [blame] | 304 | /* save the local APIC address, it might be non-default */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | if (!acpi_lapic) |
Jaswinder Singh Rajput | 6c65da5 | 2009-01-04 22:22:56 +0530 | [diff] [blame] | 306 | mp_lapic_addr = mpc->lapic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
Alexey Starikovskiy | 888032c | 2008-04-04 23:42:09 +0400 | [diff] [blame] | 308 | if (early) |
| 309 | return 1; |
| 310 | |
Eric W. Biederman | 5989cd6 | 2010-08-04 13:30:27 -0700 | [diff] [blame] | 311 | /* Initialize the lapic mapping */ |
| 312 | if (!acpi_lapic) |
| 313 | smp_register_lapic_address(mpc->lapic); |
| 314 | |
Thomas Gleixner | 7230214 | 2009-08-20 12:18:32 +0200 | [diff] [blame] | 315 | if (mpc->oemptr) |
| 316 | x86_init.mpparse.smp_read_mpc_oem(mpc); |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | /* |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 319 | * Now process the configuration blocks. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | */ |
Thomas Gleixner | f484847 | 2009-08-20 12:05:01 +0200 | [diff] [blame] | 321 | x86_init.mpparse.mpc_record(0); |
Yinghai Lu | 64898a8 | 2008-07-19 18:01:16 -0700 | [diff] [blame] | 322 | |
Jaswinder Singh Rajput | 6c65da5 | 2009-01-04 22:22:56 +0530 | [diff] [blame] | 323 | while (count < mpc->length) { |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 324 | switch (*mpt) { |
| 325 | case MP_PROCESSOR: |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 326 | /* ACPI may have already provided this data */ |
| 327 | if (!acpi_lapic) |
Ingo Molnar | c58603e | 2009-03-19 08:50:35 +0100 | [diff] [blame] | 328 | MP_processor_info((struct mpc_cpu *)mpt); |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 329 | skip_entry(&mpt, &count, sizeof(struct mpc_cpu)); |
| 330 | break; |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 331 | case MP_BUS: |
Ingo Molnar | c58603e | 2009-03-19 08:50:35 +0100 | [diff] [blame] | 332 | MP_bus_info((struct mpc_bus *)mpt); |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 333 | skip_entry(&mpt, &count, sizeof(struct mpc_bus)); |
| 334 | break; |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 335 | case MP_IOAPIC: |
Ingo Molnar | c58603e | 2009-03-19 08:50:35 +0100 | [diff] [blame] | 336 | MP_ioapic_info((struct mpc_ioapic *)mpt); |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 337 | skip_entry(&mpt, &count, sizeof(struct mpc_ioapic)); |
| 338 | break; |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 339 | case MP_INTSRC: |
Ingo Molnar | c58603e | 2009-03-19 08:50:35 +0100 | [diff] [blame] | 340 | MP_intsrc_info((struct mpc_intsrc *)mpt); |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 341 | skip_entry(&mpt, &count, sizeof(struct mpc_intsrc)); |
| 342 | break; |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 343 | case MP_LINTSRC: |
Ingo Molnar | c58603e | 2009-03-19 08:50:35 +0100 | [diff] [blame] | 344 | MP_lintsrc_info((struct mpc_lintsrc *)mpt); |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 345 | skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc)); |
| 346 | break; |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 347 | default: |
Yinghai Lu | 711554d | 2008-04-07 11:36:39 -0700 | [diff] [blame] | 348 | /* wrong mptable */ |
Jaswinder Singh Rajput | 5a5737e | 2009-03-21 13:28:39 +0530 | [diff] [blame] | 349 | smp_dump_mptable(mpc, mpt); |
Jaswinder Singh Rajput | 6c65da5 | 2009-01-04 22:22:56 +0530 | [diff] [blame] | 350 | count = mpc->length; |
Yinghai Lu | 711554d | 2008-04-07 11:36:39 -0700 | [diff] [blame] | 351 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } |
Thomas Gleixner | f484847 | 2009-08-20 12:05:01 +0200 | [diff] [blame] | 353 | x86_init.mpparse.mpc_record(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | } |
Yinghai Lu | e0da336 | 2008-06-08 18:29:22 -0700 | [diff] [blame] | 355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | if (!num_processors) |
Alexey Starikovskiy | e950bea | 2008-04-04 23:42:27 +0400 | [diff] [blame] | 357 | printk(KERN_ERR "MPTABLE: no processors registered!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | return num_processors; |
| 359 | } |
| 360 | |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 361 | #ifdef CONFIG_X86_IO_APIC |
| 362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | static int __init ELCR_trigger(unsigned int irq) |
| 364 | { |
| 365 | unsigned int port; |
| 366 | |
| 367 | port = 0x4d0 + (irq >> 3); |
| 368 | return (inb(port) >> (irq & 7)) & 1; |
| 369 | } |
| 370 | |
| 371 | static void __init construct_default_ioirq_mptable(int mpc_default_type) |
| 372 | { |
Jaswinder Singh Rajput | 540d4e7 | 2009-01-03 15:50:52 +0530 | [diff] [blame] | 373 | struct mpc_intsrc intsrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | int i; |
| 375 | int ELCR_fallback = 0; |
| 376 | |
Jaswinder Singh Rajput | e253b39 | 2009-01-04 21:56:44 +0530 | [diff] [blame] | 377 | intsrc.type = MP_INTSRC; |
| 378 | intsrc.irqflag = 0; /* conforming */ |
| 379 | intsrc.srcbus = 0; |
Jaswinder Singh Rajput | b5ba7e6 | 2009-01-12 17:46:17 +0530 | [diff] [blame] | 380 | intsrc.dstapic = mp_ioapics[0].apicid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
Jaswinder Singh Rajput | e253b39 | 2009-01-04 21:56:44 +0530 | [diff] [blame] | 382 | intsrc.irqtype = mp_INT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
| 384 | /* |
| 385 | * If true, we have an ISA/PCI system with no IRQ entries |
| 386 | * in the MP table. To prevent the PCI interrupts from being set up |
| 387 | * incorrectly, we try to use the ELCR. The sanity check to see if |
| 388 | * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can |
| 389 | * never be level sensitive, so we simply see if the ELCR agrees. |
| 390 | * If it does, we assume it's valid. |
| 391 | */ |
| 392 | if (mpc_default_type == 5) { |
Alexey Starikovskiy | 62441bf | 2008-04-04 23:42:34 +0400 | [diff] [blame] | 393 | printk(KERN_INFO "ISA/PCI bus type with no IRQ information... " |
| 394 | "falling back to ELCR\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
Alexey Starikovskiy | 62441bf | 2008-04-04 23:42:34 +0400 | [diff] [blame] | 396 | if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) || |
| 397 | ELCR_trigger(13)) |
| 398 | printk(KERN_ERR "ELCR contains invalid data... " |
| 399 | "not using ELCR\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | else { |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 401 | printk(KERN_INFO |
| 402 | "Using ELCR to identify PCI interrupts\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | ELCR_fallback = 1; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | for (i = 0; i < 16; i++) { |
| 408 | switch (mpc_default_type) { |
| 409 | case 2: |
| 410 | if (i == 0 || i == 13) |
| 411 | continue; /* IRQ0 & IRQ13 not connected */ |
| 412 | /* fall through */ |
| 413 | default: |
| 414 | if (i == 2) |
| 415 | continue; /* IRQ2 is never connected */ |
| 416 | } |
| 417 | |
| 418 | if (ELCR_fallback) { |
| 419 | /* |
| 420 | * If the ELCR indicates a level-sensitive interrupt, we |
| 421 | * copy that information over to the MP table in the |
| 422 | * irqflag field (level sensitive, active high polarity). |
| 423 | */ |
| 424 | if (ELCR_trigger(i)) |
Jaswinder Singh Rajput | e253b39 | 2009-01-04 21:56:44 +0530 | [diff] [blame] | 425 | intsrc.irqflag = 13; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | else |
Jaswinder Singh Rajput | e253b39 | 2009-01-04 21:56:44 +0530 | [diff] [blame] | 427 | intsrc.irqflag = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Jaswinder Singh Rajput | e253b39 | 2009-01-04 21:56:44 +0530 | [diff] [blame] | 430 | intsrc.srcbusirq = i; |
| 431 | intsrc.dstirq = i ? i : 2; /* IRQ0 to INTIN2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | MP_intsrc_info(&intsrc); |
| 433 | } |
| 434 | |
Jaswinder Singh Rajput | e253b39 | 2009-01-04 21:56:44 +0530 | [diff] [blame] | 435 | intsrc.irqtype = mp_ExtINT; |
| 436 | intsrc.srcbusirq = 0; |
| 437 | intsrc.dstirq = 0; /* 8259A to INTIN0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | MP_intsrc_info(&intsrc); |
| 439 | } |
| 440 | |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 441 | |
Marcin Slusarz | 39e00fe | 2008-08-11 00:09:38 +0200 | [diff] [blame] | 442 | static void __init construct_ioapic_table(int mpc_default_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | { |
Jaswinder Singh Rajput | 2b85b5f | 2009-01-03 15:49:57 +0530 | [diff] [blame] | 444 | struct mpc_ioapic ioapic; |
Jaswinder Singh Rajput | 00fb860 | 2009-01-03 15:47:32 +0530 | [diff] [blame] | 445 | struct mpc_bus bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Jaswinder Singh Rajput | d4c715f | 2009-01-04 21:59:26 +0530 | [diff] [blame] | 447 | bus.type = MP_BUS; |
| 448 | bus.busid = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | switch (mpc_default_type) { |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 450 | default: |
Alexey Starikovskiy | 62441bf | 2008-04-04 23:42:34 +0400 | [diff] [blame] | 451 | printk(KERN_ERR "???\nUnknown standard configuration %d\n", |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 452 | mpc_default_type); |
| 453 | /* fall through */ |
| 454 | case 1: |
| 455 | case 5: |
Jaswinder Singh Rajput | d4c715f | 2009-01-04 21:59:26 +0530 | [diff] [blame] | 456 | memcpy(bus.bustype, "ISA ", 6); |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 457 | break; |
| 458 | case 2: |
| 459 | case 6: |
| 460 | case 3: |
Jaswinder Singh Rajput | d4c715f | 2009-01-04 21:59:26 +0530 | [diff] [blame] | 461 | memcpy(bus.bustype, "EISA ", 6); |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 462 | break; |
| 463 | case 4: |
| 464 | case 7: |
Jaswinder Singh Rajput | d4c715f | 2009-01-04 21:59:26 +0530 | [diff] [blame] | 465 | memcpy(bus.bustype, "MCA ", 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | } |
| 467 | MP_bus_info(&bus); |
| 468 | if (mpc_default_type > 4) { |
Jaswinder Singh Rajput | d4c715f | 2009-01-04 21:59:26 +0530 | [diff] [blame] | 469 | bus.busid = 1; |
| 470 | memcpy(bus.bustype, "PCI ", 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | MP_bus_info(&bus); |
| 472 | } |
| 473 | |
Cyrill Gorcunov | 8f3e1df | 2009-08-24 21:53:36 +0400 | [diff] [blame] | 474 | ioapic.type = MP_IOAPIC; |
| 475 | ioapic.apicid = 2; |
| 476 | ioapic.apicver = mpc_default_type > 4 ? 0x10 : 0x01; |
| 477 | ioapic.flags = MPC_APIC_USABLE; |
| 478 | ioapic.apicaddr = IO_APIC_DEFAULT_PHYS_BASE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | MP_ioapic_info(&ioapic); |
| 480 | |
| 481 | /* |
| 482 | * We set up most of the low 16 IO-APIC pins according to MPS rules. |
| 483 | */ |
| 484 | construct_default_ioirq_mptable(mpc_default_type); |
Thomas Gleixner | 85cc35f | 2008-05-25 21:21:36 +0200 | [diff] [blame] | 485 | } |
| 486 | #else |
Marcin Slusarz | 39e00fe | 2008-08-11 00:09:38 +0200 | [diff] [blame] | 487 | static inline void __init construct_ioapic_table(int mpc_default_type) { } |
Alexey Starikovskiy | 61048c6 | 2008-04-04 23:41:07 +0400 | [diff] [blame] | 488 | #endif |
Thomas Gleixner | 85cc35f | 2008-05-25 21:21:36 +0200 | [diff] [blame] | 489 | |
| 490 | static inline void __init construct_default_ISA_mptable(int mpc_default_type) |
| 491 | { |
Jaswinder Singh Rajput | f4f21b7 | 2009-01-03 15:48:52 +0530 | [diff] [blame] | 492 | struct mpc_cpu processor; |
Jaswinder Singh Rajput | 8fb2952 | 2009-01-03 15:51:54 +0530 | [diff] [blame] | 493 | struct mpc_lintsrc lintsrc; |
Thomas Gleixner | 85cc35f | 2008-05-25 21:21:36 +0200 | [diff] [blame] | 494 | int linttypes[2] = { mp_ExtINT, mp_NMI }; |
| 495 | int i; |
| 496 | |
| 497 | /* |
| 498 | * local APIC has default address |
| 499 | */ |
| 500 | mp_lapic_addr = APIC_DEFAULT_PHYS_BASE; |
| 501 | |
| 502 | /* |
| 503 | * 2 CPUs, numbered 0 & 1. |
| 504 | */ |
Jaswinder Singh Rajput | c456382 | 2009-01-04 21:58:25 +0530 | [diff] [blame] | 505 | processor.type = MP_PROCESSOR; |
Thomas Gleixner | 85cc35f | 2008-05-25 21:21:36 +0200 | [diff] [blame] | 506 | /* Either an integrated APIC or a discrete 82489DX. */ |
Jaswinder Singh Rajput | c456382 | 2009-01-04 21:58:25 +0530 | [diff] [blame] | 507 | processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01; |
| 508 | processor.cpuflag = CPU_ENABLED; |
| 509 | processor.cpufeature = (boot_cpu_data.x86 << 8) | |
Thomas Gleixner | 85cc35f | 2008-05-25 21:21:36 +0200 | [diff] [blame] | 510 | (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask; |
Jaswinder Singh Rajput | c456382 | 2009-01-04 21:58:25 +0530 | [diff] [blame] | 511 | processor.featureflag = boot_cpu_data.x86_capability[0]; |
| 512 | processor.reserved[0] = 0; |
| 513 | processor.reserved[1] = 0; |
Thomas Gleixner | 85cc35f | 2008-05-25 21:21:36 +0200 | [diff] [blame] | 514 | for (i = 0; i < 2; i++) { |
Jaswinder Singh Rajput | c456382 | 2009-01-04 21:58:25 +0530 | [diff] [blame] | 515 | processor.apicid = i; |
Thomas Gleixner | 85cc35f | 2008-05-25 21:21:36 +0200 | [diff] [blame] | 516 | MP_processor_info(&processor); |
| 517 | } |
| 518 | |
| 519 | construct_ioapic_table(mpc_default_type); |
| 520 | |
Jaswinder Singh Rajput | b5ced7c | 2009-01-04 21:55:53 +0530 | [diff] [blame] | 521 | lintsrc.type = MP_LINTSRC; |
| 522 | lintsrc.irqflag = 0; /* conforming */ |
| 523 | lintsrc.srcbusid = 0; |
| 524 | lintsrc.srcbusirq = 0; |
| 525 | lintsrc.destapic = MP_APIC_ALL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | for (i = 0; i < 2; i++) { |
Jaswinder Singh Rajput | b5ced7c | 2009-01-04 21:55:53 +0530 | [diff] [blame] | 527 | lintsrc.irqtype = linttypes[i]; |
| 528 | lintsrc.destapiclint = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | MP_lintsrc_info(&lintsrc); |
| 530 | } |
| 531 | } |
| 532 | |
Jaswinder Singh Rajput | 41401db | 2009-01-08 15:42:46 +0530 | [diff] [blame] | 533 | static struct mpf_intel *mpf_found; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
Yinghai Lu | 8d4dd91 | 2009-03-04 01:25:21 -0800 | [diff] [blame] | 535 | static unsigned long __init get_mpc_size(unsigned long physptr) |
| 536 | { |
| 537 | struct mpc_table *mpc; |
| 538 | unsigned long size; |
| 539 | |
| 540 | mpc = early_ioremap(physptr, PAGE_SIZE); |
| 541 | size = mpc->length; |
| 542 | early_iounmap(mpc, PAGE_SIZE); |
| 543 | apic_printk(APIC_VERBOSE, " mpc: %lx-%lx\n", physptr, physptr + size); |
| 544 | |
| 545 | return size; |
| 546 | } |
| 547 | |
Jaswinder Singh Rajput | 0b3ba0c | 2009-03-21 13:43:20 +0530 | [diff] [blame] | 548 | static int __init check_physptr(struct mpf_intel *mpf, unsigned int early) |
| 549 | { |
| 550 | struct mpc_table *mpc; |
| 551 | unsigned long size; |
| 552 | |
| 553 | size = get_mpc_size(mpf->physptr); |
| 554 | mpc = early_ioremap(mpf->physptr, size); |
| 555 | /* |
| 556 | * Read the physical hardware table. Anything here will |
| 557 | * override the defaults. |
| 558 | */ |
| 559 | if (!smp_read_mpc(mpc, early)) { |
| 560 | #ifdef CONFIG_X86_LOCAL_APIC |
| 561 | smp_found_config = 0; |
| 562 | #endif |
| 563 | printk(KERN_ERR "BIOS bug, MP table errors detected!...\n" |
| 564 | "... disabling SMP support. (tell your hw vendor)\n"); |
| 565 | early_iounmap(mpc, size); |
| 566 | return -1; |
| 567 | } |
| 568 | early_iounmap(mpc, size); |
| 569 | |
| 570 | if (early) |
| 571 | return -1; |
| 572 | |
| 573 | #ifdef CONFIG_X86_IO_APIC |
| 574 | /* |
| 575 | * If there are no explicit MP IRQ entries, then we are |
| 576 | * broken. We set up most of the low 16 IO-APIC pins to |
| 577 | * ISA defaults and hope it will work. |
| 578 | */ |
| 579 | if (!mp_irq_entries) { |
| 580 | struct mpc_bus bus; |
| 581 | |
| 582 | printk(KERN_ERR "BIOS bug, no explicit IRQ entries, " |
| 583 | "using default mptable. (tell your hw vendor)\n"); |
| 584 | |
| 585 | bus.type = MP_BUS; |
| 586 | bus.busid = 0; |
| 587 | memcpy(bus.bustype, "ISA ", 6); |
| 588 | MP_bus_info(&bus); |
| 589 | |
| 590 | construct_default_ioirq_mptable(0); |
| 591 | } |
| 592 | #endif |
| 593 | |
| 594 | return 0; |
| 595 | } |
| 596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | /* |
| 598 | * Scan the memory blocks for an SMP configuration block. |
| 599 | */ |
Thomas Gleixner | b3f1b61 | 2009-08-20 11:11:52 +0200 | [diff] [blame] | 600 | void __init default_get_smp_config(unsigned int early) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | { |
Jaswinder Singh Rajput | 41401db | 2009-01-08 15:42:46 +0530 | [diff] [blame] | 602 | struct mpf_intel *mpf = mpf_found; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
Yinghai Lu | 69b88af | 2008-12-05 22:45:50 -0800 | [diff] [blame] | 604 | if (!mpf) |
| 605 | return; |
| 606 | |
| 607 | if (acpi_lapic && early) |
| 608 | return; |
| 609 | |
| 610 | /* |
| 611 | * MPS doesn't support hyperthreading, aka only have |
| 612 | * thread 0 apic id in MPS table |
| 613 | */ |
| 614 | if (acpi_lapic && acpi_ioapic) |
| 615 | return; |
| 616 | |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 617 | printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n", |
Jaswinder Singh Rajput | 1eb1b3b | 2009-01-08 15:43:26 +0530 | [diff] [blame] | 618 | mpf->specification); |
Alexey Starikovskiy | b3e2416 | 2008-05-23 01:54:44 +0400 | [diff] [blame] | 619 | #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32) |
Jaswinder Singh Rajput | 1eb1b3b | 2009-01-08 15:43:26 +0530 | [diff] [blame] | 620 | if (mpf->feature2 & (1 << 7)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | printk(KERN_INFO " IMCR and PIC compatibility mode.\n"); |
| 622 | pic_mode = 1; |
| 623 | } else { |
| 624 | printk(KERN_INFO " Virtual Wire compatibility mode.\n"); |
| 625 | pic_mode = 0; |
| 626 | } |
Alexey Starikovskiy | 4421b1c | 2008-04-04 23:42:40 +0400 | [diff] [blame] | 627 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | /* |
| 629 | * Now see if we need to read further. |
| 630 | */ |
Jaswinder Singh Rajput | 1eb1b3b | 2009-01-08 15:43:26 +0530 | [diff] [blame] | 631 | if (mpf->feature1 != 0) { |
Alexey Starikovskiy | 888032c | 2008-04-04 23:42:09 +0400 | [diff] [blame] | 632 | if (early) { |
| 633 | /* |
| 634 | * local APIC has default address |
| 635 | */ |
| 636 | mp_lapic_addr = APIC_DEFAULT_PHYS_BASE; |
| 637 | return; |
| 638 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 640 | printk(KERN_INFO "Default MP configuration #%d\n", |
Jaswinder Singh Rajput | 1eb1b3b | 2009-01-08 15:43:26 +0530 | [diff] [blame] | 641 | mpf->feature1); |
| 642 | construct_default_ISA_mptable(mpf->feature1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
Jaswinder Singh Rajput | 1eb1b3b | 2009-01-08 15:43:26 +0530 | [diff] [blame] | 644 | } else if (mpf->physptr) { |
Jaswinder Singh Rajput | 0b3ba0c | 2009-03-21 13:43:20 +0530 | [diff] [blame] | 645 | if (check_physptr(mpf, early)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } else |
| 648 | BUG(); |
| 649 | |
Alexey Starikovskiy | 888032c | 2008-04-04 23:42:09 +0400 | [diff] [blame] | 650 | if (!early) |
| 651 | printk(KERN_INFO "Processors: %d\n", num_processors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | /* |
| 653 | * Only use the first configuration found. |
| 654 | */ |
| 655 | } |
| 656 | |
Yinghai Lu | b24c2a9 | 2009-11-24 02:48:18 -0800 | [diff] [blame] | 657 | static void __init smp_reserve_memory(struct mpf_intel *mpf) |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 658 | { |
| 659 | unsigned long size = get_mpc_size(mpf->physptr); |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 660 | |
Yinghai Lu | 72d7c3b | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 661 | memblock_x86_reserve_range(mpf->physptr, mpf->physptr+size, "* MP-table mpc"); |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 662 | } |
| 663 | |
Yinghai Lu | b24c2a9 | 2009-11-24 02:48:18 -0800 | [diff] [blame] | 664 | static int __init smp_scan_config(unsigned long base, unsigned long length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | { |
Alexey Starikovskiy | 92fd4b7 | 2008-04-04 23:42:46 +0400 | [diff] [blame] | 666 | unsigned int *bp = phys_to_virt(base); |
Jaswinder Singh Rajput | 41401db | 2009-01-08 15:42:46 +0530 | [diff] [blame] | 667 | struct mpf_intel *mpf; |
Yinghai Lu | b24c2a9 | 2009-11-24 02:48:18 -0800 | [diff] [blame] | 668 | unsigned long mem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | |
Rene Herman | eeb0d7d | 2008-08-11 17:44:57 +0200 | [diff] [blame] | 670 | apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n", |
| 671 | bp, length); |
Akinobu Mita | 5d47a27 | 2008-04-19 23:55:11 +0900 | [diff] [blame] | 672 | BUILD_BUG_ON(sizeof(*mpf) != 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
| 674 | while (length > 0) { |
Jaswinder Singh Rajput | 41401db | 2009-01-08 15:42:46 +0530 | [diff] [blame] | 675 | mpf = (struct mpf_intel *)bp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | if ((*bp == SMP_MAGIC_IDENT) && |
Jaswinder Singh Rajput | 1eb1b3b | 2009-01-08 15:43:26 +0530 | [diff] [blame] | 677 | (mpf->length == 1) && |
Alexey Starikovskiy | 4ef8129 | 2008-04-04 23:42:03 +0400 | [diff] [blame] | 678 | !mpf_checksum((unsigned char *)bp, 16) && |
Jaswinder Singh Rajput | 1eb1b3b | 2009-01-08 15:43:26 +0530 | [diff] [blame] | 679 | ((mpf->specification == 1) |
| 680 | || (mpf->specification == 4))) { |
Alexey Starikovskiy | bab4b27 | 2008-05-19 19:47:03 +0400 | [diff] [blame] | 681 | #ifdef CONFIG_X86_LOCAL_APIC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | smp_found_config = 1; |
Alexey Starikovskiy | bab4b27 | 2008-05-19 19:47:03 +0400 | [diff] [blame] | 683 | #endif |
Alexey Starikovskiy | 92fd4b7 | 2008-04-04 23:42:46 +0400 | [diff] [blame] | 684 | mpf_found = mpf; |
Yinghai Lu | b1f006b | 2008-06-09 18:11:36 -0700 | [diff] [blame] | 685 | |
Jaswinder Singh Rajput | ba1511b | 2009-02-11 23:38:25 +0530 | [diff] [blame] | 686 | printk(KERN_INFO "found SMP MP-table at [%p] %llx\n", |
| 687 | mpf, (u64)virt_to_phys(mpf)); |
Yinghai Lu | b1f006b | 2008-06-09 18:11:36 -0700 | [diff] [blame] | 688 | |
Yinghai Lu | b24c2a9 | 2009-11-24 02:48:18 -0800 | [diff] [blame] | 689 | mem = virt_to_phys(mpf); |
Yinghai Lu | 72d7c3b | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 690 | memblock_x86_reserve_range(mem, mem + sizeof(*mpf), "* MP-table mpf"); |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 691 | if (mpf->physptr) |
Yinghai Lu | b24c2a9 | 2009-11-24 02:48:18 -0800 | [diff] [blame] | 692 | smp_reserve_memory(mpf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
Yinghai Lu | d2dbf34 | 2008-06-13 02:00:56 -0700 | [diff] [blame] | 694 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | } |
| 696 | bp += 4; |
| 697 | length -= 16; |
| 698 | } |
| 699 | return 0; |
| 700 | } |
| 701 | |
Yinghai Lu | b24c2a9 | 2009-11-24 02:48:18 -0800 | [diff] [blame] | 702 | void __init default_find_smp_config(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | { |
| 704 | unsigned int address; |
| 705 | |
| 706 | /* |
| 707 | * FIXME: Linux assumes you have 640K of base ram.. |
| 708 | * this continues the error... |
| 709 | * |
| 710 | * 1) Scan the bottom 1K for a signature |
| 711 | * 2) Scan the top 1K of base RAM |
| 712 | * 3) Scan the 64K of bios |
| 713 | */ |
Yinghai Lu | b24c2a9 | 2009-11-24 02:48:18 -0800 | [diff] [blame] | 714 | if (smp_scan_config(0x0, 0x400) || |
| 715 | smp_scan_config(639 * 0x400, 0x400) || |
| 716 | smp_scan_config(0xF0000, 0x10000)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | return; |
| 718 | /* |
| 719 | * If it is an SMP machine we should know now, unless the |
| 720 | * configuration is in an EISA/MCA bus machine with an |
| 721 | * extended bios data area. |
| 722 | * |
| 723 | * there is a real-mode segmented pointer pointing to the |
| 724 | * 4K EBDA area at 0x40E, calculate and scan it here. |
| 725 | * |
| 726 | * NOTE! There are Linux loaders that will corrupt the EBDA |
| 727 | * area, and as such this kind of SMP config may be less |
| 728 | * trustworthy, simply because the SMP table may have been |
| 729 | * stomped on during early boot. These loaders are buggy and |
| 730 | * should be fixed. |
| 731 | * |
| 732 | * MP1.4 SPEC states to only scan first 1K of 4K EBDA. |
| 733 | */ |
| 734 | |
| 735 | address = get_bios_ebda(); |
| 736 | if (address) |
Yinghai Lu | b24c2a9 | 2009-11-24 02:48:18 -0800 | [diff] [blame] | 737 | smp_scan_config(address, 0x400); |
Alexey Starikovskiy | 888032c | 2008-04-04 23:42:09 +0400 | [diff] [blame] | 738 | } |
| 739 | |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 740 | #ifdef CONFIG_X86_IO_APIC |
| 741 | static u8 __initdata irq_used[MAX_IRQ_SOURCES]; |
| 742 | |
Jaswinder Singh Rajput | 540d4e7 | 2009-01-03 15:50:52 +0530 | [diff] [blame] | 743 | static int __init get_MP_intsrc_index(struct mpc_intsrc *m) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 744 | { |
| 745 | int i; |
| 746 | |
Jaswinder Singh Rajput | e253b39 | 2009-01-04 21:56:44 +0530 | [diff] [blame] | 747 | if (m->irqtype != mp_INT) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 748 | return 0; |
| 749 | |
Jaswinder Singh Rajput | e253b39 | 2009-01-04 21:56:44 +0530 | [diff] [blame] | 750 | if (m->irqflag != 0x0f) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 751 | return 0; |
| 752 | |
| 753 | /* not legacy */ |
| 754 | |
| 755 | for (i = 0; i < mp_irq_entries; i++) { |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 756 | if (mp_irqs[i].irqtype != mp_INT) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 757 | continue; |
| 758 | |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 759 | if (mp_irqs[i].irqflag != 0x0f) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 760 | continue; |
| 761 | |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 762 | if (mp_irqs[i].srcbus != m->srcbus) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 763 | continue; |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 764 | if (mp_irqs[i].srcbusirq != m->srcbusirq) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 765 | continue; |
| 766 | if (irq_used[i]) { |
| 767 | /* already claimed */ |
| 768 | return -2; |
| 769 | } |
| 770 | irq_used[i] = 1; |
| 771 | return i; |
| 772 | } |
| 773 | |
| 774 | /* not found */ |
| 775 | return -1; |
| 776 | } |
| 777 | |
| 778 | #define SPARE_SLOT_NUM 20 |
| 779 | |
Jaswinder Singh Rajput | 540d4e7 | 2009-01-03 15:50:52 +0530 | [diff] [blame] | 780 | static struct mpc_intsrc __initdata *m_spare[SPARE_SLOT_NUM]; |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 781 | |
Rakib Mullick | 5759222 | 2009-04-11 09:04:59 +0600 | [diff] [blame] | 782 | static void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare) |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 783 | { |
| 784 | int i; |
| 785 | |
| 786 | apic_printk(APIC_VERBOSE, "OLD "); |
| 787 | print_MP_intsrc_info(m); |
| 788 | |
| 789 | i = get_MP_intsrc_index(m); |
| 790 | if (i > 0) { |
| 791 | assign_to_mpc_intsrc(&mp_irqs[i], m); |
| 792 | apic_printk(APIC_VERBOSE, "NEW "); |
| 793 | print_mp_irq_info(&mp_irqs[i]); |
| 794 | return; |
| 795 | } |
| 796 | if (!i) { |
| 797 | /* legacy, do nothing */ |
| 798 | return; |
| 799 | } |
| 800 | if (*nr_m_spare < SPARE_SLOT_NUM) { |
| 801 | /* |
| 802 | * not found (-1), or duplicated (-2) are invalid entries, |
| 803 | * we need to use the slot later |
| 804 | */ |
| 805 | m_spare[*nr_m_spare] = m; |
| 806 | *nr_m_spare += 1; |
| 807 | } |
| 808 | } |
| 809 | #else /* CONFIG_X86_IO_APIC */ |
Rakib Mullick | 5759222 | 2009-04-11 09:04:59 +0600 | [diff] [blame] | 810 | static |
| 811 | inline void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare) {} |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 812 | #endif /* CONFIG_X86_IO_APIC */ |
| 813 | |
Yinghai Lu | ee21455 | 2009-05-06 10:07:07 -0700 | [diff] [blame] | 814 | static int |
| 815 | check_slot(unsigned long mpc_new_phys, unsigned long mpc_new_length, int count) |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 816 | { |
Yinghai Lu | ee21455 | 2009-05-06 10:07:07 -0700 | [diff] [blame] | 817 | int ret = 0; |
| 818 | |
| 819 | if (!mpc_new_phys || count <= mpc_new_length) { |
| 820 | WARN(1, "update_mptable: No spare slots (length: %x)\n", count); |
| 821 | return -1; |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 822 | } |
| 823 | |
Yinghai Lu | ee21455 | 2009-05-06 10:07:07 -0700 | [diff] [blame] | 824 | return ret; |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 825 | } |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 826 | |
Jaswinder Singh Rajput | f29521e | 2009-01-03 15:46:57 +0530 | [diff] [blame] | 827 | static int __init replace_intsrc_all(struct mpc_table *mpc, |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 828 | unsigned long mpc_new_phys, |
| 829 | unsigned long mpc_new_length) |
| 830 | { |
| 831 | #ifdef CONFIG_X86_IO_APIC |
| 832 | int i; |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 833 | #endif |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 834 | int count = sizeof(*mpc); |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 835 | int nr_m_spare = 0; |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 836 | unsigned char *mpt = ((unsigned char *)mpc) + count; |
| 837 | |
Jaswinder Singh Rajput | 6c65da5 | 2009-01-04 22:22:56 +0530 | [diff] [blame] | 838 | printk(KERN_INFO "mpc_length %x\n", mpc->length); |
| 839 | while (count < mpc->length) { |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 840 | switch (*mpt) { |
| 841 | case MP_PROCESSOR: |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 842 | skip_entry(&mpt, &count, sizeof(struct mpc_cpu)); |
| 843 | break; |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 844 | case MP_BUS: |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 845 | skip_entry(&mpt, &count, sizeof(struct mpc_bus)); |
| 846 | break; |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 847 | case MP_IOAPIC: |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 848 | skip_entry(&mpt, &count, sizeof(struct mpc_ioapic)); |
| 849 | break; |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 850 | case MP_INTSRC: |
Ingo Molnar | c58603e | 2009-03-19 08:50:35 +0100 | [diff] [blame] | 851 | check_irq_src((struct mpc_intsrc *)mpt, &nr_m_spare); |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 852 | skip_entry(&mpt, &count, sizeof(struct mpc_intsrc)); |
| 853 | break; |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 854 | case MP_LINTSRC: |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 855 | skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc)); |
| 856 | break; |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 857 | default: |
| 858 | /* wrong mptable */ |
Jaswinder Singh Rajput | 5a5737e | 2009-03-21 13:28:39 +0530 | [diff] [blame] | 859 | smp_dump_mptable(mpc, mpt); |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 860 | goto out; |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | #ifdef CONFIG_X86_IO_APIC |
| 865 | for (i = 0; i < mp_irq_entries; i++) { |
| 866 | if (irq_used[i]) |
| 867 | continue; |
| 868 | |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 869 | if (mp_irqs[i].irqtype != mp_INT) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 870 | continue; |
| 871 | |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 872 | if (mp_irqs[i].irqflag != 0x0f) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 873 | continue; |
| 874 | |
| 875 | if (nr_m_spare > 0) { |
Jan Beulich | 82034d6 | 2009-03-12 12:57:10 +0000 | [diff] [blame] | 876 | apic_printk(APIC_VERBOSE, "*NEW* found\n"); |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 877 | nr_m_spare--; |
| 878 | assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]); |
| 879 | m_spare[nr_m_spare] = NULL; |
| 880 | } else { |
Jaswinder Singh Rajput | 540d4e7 | 2009-01-03 15:50:52 +0530 | [diff] [blame] | 881 | struct mpc_intsrc *m = (struct mpc_intsrc *)mpt; |
| 882 | count += sizeof(struct mpc_intsrc); |
Yinghai Lu | ee21455 | 2009-05-06 10:07:07 -0700 | [diff] [blame] | 883 | if (check_slot(mpc_new_phys, mpc_new_length, count) < 0) |
Jaswinder Singh Rajput | a683027 | 2009-03-18 20:42:28 +0530 | [diff] [blame] | 884 | goto out; |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 885 | assign_to_mpc_intsrc(&mp_irqs[i], m); |
Jaswinder Singh Rajput | 6c65da5 | 2009-01-04 22:22:56 +0530 | [diff] [blame] | 886 | mpc->length = count; |
Jaswinder Singh Rajput | 540d4e7 | 2009-01-03 15:50:52 +0530 | [diff] [blame] | 887 | mpt += sizeof(struct mpc_intsrc); |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 888 | } |
| 889 | print_mp_irq_info(&mp_irqs[i]); |
| 890 | } |
| 891 | #endif |
| 892 | out: |
| 893 | /* update checksum */ |
Jaswinder Singh Rajput | 6c65da5 | 2009-01-04 22:22:56 +0530 | [diff] [blame] | 894 | mpc->checksum = 0; |
| 895 | mpc->checksum -= mpf_checksum((unsigned char *)mpc, mpc->length); |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 896 | |
| 897 | return 0; |
| 898 | } |
| 899 | |
Yinghai Lu | f1bdb52 | 2009-05-15 13:05:16 -0700 | [diff] [blame] | 900 | int enable_update_mptable; |
Yinghai Lu | fcfa146 | 2008-06-18 17:29:31 -0700 | [diff] [blame] | 901 | |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 902 | static int __init update_mptable_setup(char *str) |
| 903 | { |
| 904 | enable_update_mptable = 1; |
Yinghai Lu | 629e15d | 2009-05-15 13:05:16 -0700 | [diff] [blame] | 905 | #ifdef CONFIG_PCI |
| 906 | pci_routeirq = 1; |
| 907 | #endif |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 908 | return 0; |
| 909 | } |
| 910 | early_param("update_mptable", update_mptable_setup); |
| 911 | |
| 912 | static unsigned long __initdata mpc_new_phys; |
| 913 | static unsigned long mpc_new_length __initdata = 4096; |
| 914 | |
| 915 | /* alloc_mptable or alloc_mptable=4k */ |
| 916 | static int __initdata alloc_mptable; |
| 917 | static int __init parse_alloc_mptable_opt(char *p) |
| 918 | { |
| 919 | enable_update_mptable = 1; |
Yinghai Lu | 629e15d | 2009-05-15 13:05:16 -0700 | [diff] [blame] | 920 | #ifdef CONFIG_PCI |
| 921 | pci_routeirq = 1; |
| 922 | #endif |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 923 | alloc_mptable = 1; |
| 924 | if (!p) |
| 925 | return 0; |
| 926 | mpc_new_length = memparse(p, &p); |
| 927 | return 0; |
| 928 | } |
| 929 | early_param("alloc_mptable", parse_alloc_mptable_opt); |
| 930 | |
| 931 | void __init early_reserve_e820_mpc_new(void) |
| 932 | { |
| 933 | if (enable_update_mptable && alloc_mptable) { |
| 934 | u64 startt = 0; |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 935 | mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4); |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | static int __init update_mp_table(void) |
| 940 | { |
| 941 | char str[16]; |
| 942 | char oem[10]; |
Jaswinder Singh Rajput | 41401db | 2009-01-08 15:42:46 +0530 | [diff] [blame] | 943 | struct mpf_intel *mpf; |
Jaswinder Singh Rajput | f29521e | 2009-01-03 15:46:57 +0530 | [diff] [blame] | 944 | struct mpc_table *mpc, *mpc_new; |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 945 | |
| 946 | if (!enable_update_mptable) |
| 947 | return 0; |
| 948 | |
| 949 | mpf = mpf_found; |
| 950 | if (!mpf) |
| 951 | return 0; |
| 952 | |
| 953 | /* |
| 954 | * Now see if we need to go further. |
| 955 | */ |
Jaswinder Singh Rajput | 1eb1b3b | 2009-01-08 15:43:26 +0530 | [diff] [blame] | 956 | if (mpf->feature1 != 0) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 957 | return 0; |
| 958 | |
Jaswinder Singh Rajput | 1eb1b3b | 2009-01-08 15:43:26 +0530 | [diff] [blame] | 959 | if (!mpf->physptr) |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 960 | return 0; |
| 961 | |
Jaswinder Singh Rajput | 1eb1b3b | 2009-01-08 15:43:26 +0530 | [diff] [blame] | 962 | mpc = phys_to_virt(mpf->physptr); |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 963 | |
| 964 | if (!smp_check_mpc(mpc, oem, str)) |
| 965 | return 0; |
| 966 | |
Jaswinder Singh Rajput | ba1511b | 2009-02-11 23:38:25 +0530 | [diff] [blame] | 967 | printk(KERN_INFO "mpf: %llx\n", (u64)virt_to_phys(mpf)); |
Jaswinder Singh Rajput | 1eb1b3b | 2009-01-08 15:43:26 +0530 | [diff] [blame] | 968 | printk(KERN_INFO "physptr: %x\n", mpf->physptr); |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 969 | |
Jaswinder Singh Rajput | 6c65da5 | 2009-01-04 22:22:56 +0530 | [diff] [blame] | 970 | if (mpc_new_phys && mpc->length > mpc_new_length) { |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 971 | mpc_new_phys = 0; |
| 972 | printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n", |
| 973 | mpc_new_length); |
| 974 | } |
| 975 | |
| 976 | if (!mpc_new_phys) { |
| 977 | unsigned char old, new; |
| 978 | /* check if we can change the postion */ |
Jaswinder Singh Rajput | 6c65da5 | 2009-01-04 22:22:56 +0530 | [diff] [blame] | 979 | mpc->checksum = 0; |
| 980 | old = mpf_checksum((unsigned char *)mpc, mpc->length); |
| 981 | mpc->checksum = 0xff; |
| 982 | new = mpf_checksum((unsigned char *)mpc, mpc->length); |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 983 | if (old == new) { |
| 984 | printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n"); |
| 985 | return 0; |
| 986 | } |
| 987 | printk(KERN_INFO "use in-positon replacing\n"); |
| 988 | } else { |
Jaswinder Singh Rajput | 1eb1b3b | 2009-01-08 15:43:26 +0530 | [diff] [blame] | 989 | mpf->physptr = mpc_new_phys; |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 990 | mpc_new = phys_to_virt(mpc_new_phys); |
Jaswinder Singh Rajput | 6c65da5 | 2009-01-04 22:22:56 +0530 | [diff] [blame] | 991 | memcpy(mpc_new, mpc, mpc->length); |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 992 | mpc = mpc_new; |
| 993 | /* check if we can modify that */ |
Jaswinder Singh Rajput | 1eb1b3b | 2009-01-08 15:43:26 +0530 | [diff] [blame] | 994 | if (mpc_new_phys - mpf->physptr) { |
Jaswinder Singh Rajput | 41401db | 2009-01-08 15:42:46 +0530 | [diff] [blame] | 995 | struct mpf_intel *mpf_new; |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 996 | /* steal 16 bytes from [0, 1k) */ |
| 997 | printk(KERN_INFO "mpf new: %x\n", 0x400 - 16); |
| 998 | mpf_new = phys_to_virt(0x400 - 16); |
| 999 | memcpy(mpf_new, mpf, 16); |
| 1000 | mpf = mpf_new; |
Jaswinder Singh Rajput | 1eb1b3b | 2009-01-08 15:43:26 +0530 | [diff] [blame] | 1001 | mpf->physptr = mpc_new_phys; |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 1002 | } |
Jaswinder Singh Rajput | 1eb1b3b | 2009-01-08 15:43:26 +0530 | [diff] [blame] | 1003 | mpf->checksum = 0; |
| 1004 | mpf->checksum -= mpf_checksum((unsigned char *)mpf, 16); |
| 1005 | printk(KERN_INFO "physptr new: %x\n", mpf->physptr); |
Yinghai Lu | 2944e16 | 2008-06-01 13:17:38 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | /* |
| 1009 | * only replace the one with mp_INT and |
| 1010 | * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, |
| 1011 | * already in mp_irqs , stored by ... and mp_config_acpi_gsi, |
| 1012 | * may need pci=routeirq for all coverage |
| 1013 | */ |
| 1014 | replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length); |
| 1015 | |
| 1016 | return 0; |
| 1017 | } |
| 1018 | |
| 1019 | late_initcall(update_mp_table); |