Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Local APIC handling, local APIC timers |
| 3 | * |
Ingo Molnar | 8f47e16 | 2009-01-31 02:03:42 +0100 | [diff] [blame] | 4 | * (c) 1999, 2000, 2009 Ingo Molnar <mingo@redhat.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * Fixes |
| 7 | * Maciej W. Rozycki : Bits for genuine 82489DX APICs; |
| 8 | * thanks to Eric Gilmore |
| 9 | * and Rolf G. Tews |
| 10 | * for testing these extensively. |
| 11 | * Maciej W. Rozycki : Various updates and fixes. |
| 12 | * Mikael Pettersson : Power Management for UP-APIC. |
| 13 | * Pavel Machek and |
| 14 | * Mikael Pettersson : PM converted to driver model. |
| 15 | */ |
| 16 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 17 | #include <linux/perf_event.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/kernel_stat.h> |
Ingo Molnar | d1de36f | 2009-01-31 01:59:14 +0100 | [diff] [blame] | 19 | #include <linux/mc146818rtc.h> |
Thomas Gleixner | 70a2002 | 2008-01-30 13:30:18 +0100 | [diff] [blame] | 20 | #include <linux/acpi_pmtmr.h> |
Ingo Molnar | d1de36f | 2009-01-31 01:59:14 +0100 | [diff] [blame] | 21 | #include <linux/clockchips.h> |
| 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/bootmem.h> |
Frederic Weisbecker | bcbc4f2 | 2008-12-09 23:54:20 +0100 | [diff] [blame] | 24 | #include <linux/ftrace.h> |
Ingo Molnar | d1de36f | 2009-01-31 01:59:14 +0100 | [diff] [blame] | 25 | #include <linux/ioport.h> |
| 26 | #include <linux/module.h> |
Rafael J. Wysocki | f3c6ea1 | 2011-03-23 22:15:54 +0100 | [diff] [blame] | 27 | #include <linux/syscore_ops.h> |
Ingo Molnar | d1de36f | 2009-01-31 01:59:14 +0100 | [diff] [blame] | 28 | #include <linux/delay.h> |
Jaswinder Singh Rajput | e423e33 | 2009-01-04 16:16:25 +0530 | [diff] [blame] | 29 | #include <linux/timex.h> |
Ralf Baechle | 334955e | 2011-06-01 19:04:57 +0100 | [diff] [blame] | 30 | #include <linux/i8253.h> |
Ingo Molnar | d1de36f | 2009-01-31 01:59:14 +0100 | [diff] [blame] | 31 | #include <linux/dmar.h> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/cpu.h> |
| 34 | #include <linux/dmi.h> |
Ingo Molnar | d1de36f | 2009-01-31 01:59:14 +0100 | [diff] [blame] | 35 | #include <linux/smp.h> |
| 36 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Steven Rostedt (Red Hat) | 83ab851 | 2013-06-21 10:29:05 -0400 | [diff] [blame] | 38 | #include <asm/trace/irq_vectors.h> |
Suresh Siddha | 8a8f422 | 2012-03-30 11:47:08 -0700 | [diff] [blame] | 39 | #include <asm/irq_remapping.h> |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 40 | #include <asm/perf_event.h> |
Thomas Gleixner | 736deca | 2009-08-19 12:35:53 +0200 | [diff] [blame] | 41 | #include <asm/x86_init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <asm/pgalloc.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 43 | #include <linux/atomic.h> |
Ingo Molnar | d1de36f | 2009-01-31 01:59:14 +0100 | [diff] [blame] | 44 | #include <asm/mpspec.h> |
Ingo Molnar | d1de36f | 2009-01-31 01:59:14 +0100 | [diff] [blame] | 45 | #include <asm/i8259.h> |
Andi Kleen | 73dea47 | 2006-02-03 21:50:50 +0100 | [diff] [blame] | 46 | #include <asm/proto.h> |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 47 | #include <asm/apic.h> |
Henrik Kretzschmar | 7167d08 | 2011-02-22 15:38:05 +0100 | [diff] [blame] | 48 | #include <asm/io_apic.h> |
Ingo Molnar | d1de36f | 2009-01-31 01:59:14 +0100 | [diff] [blame] | 49 | #include <asm/desc.h> |
| 50 | #include <asm/hpet.h> |
| 51 | #include <asm/idle.h> |
| 52 | #include <asm/mtrr.h> |
Ralf Baechle | 16f871b | 2011-06-01 19:05:06 +0100 | [diff] [blame] | 53 | #include <asm/time.h> |
Jaswinder Singh Rajput | 2bc1379 | 2009-01-11 20:34:47 +0530 | [diff] [blame] | 54 | #include <asm/smp.h> |
Andi Kleen | be71b85 | 2009-02-12 13:49:38 +0100 | [diff] [blame] | 55 | #include <asm/mce.h> |
Kerstin Jonsson | 8c3ba8d | 2010-05-24 12:13:15 -0700 | [diff] [blame] | 56 | #include <asm/tsc.h> |
Sheng Yang | 2904ed8 | 2010-12-21 14:18:48 +0800 | [diff] [blame] | 57 | #include <asm/hypervisor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Brian Gerst | ec70de8 | 2009-01-27 12:56:47 +0900 | [diff] [blame] | 59 | unsigned int num_processors; |
Ingo Molnar | fdbecd9 | 2009-01-31 03:57:12 +0100 | [diff] [blame] | 60 | |
Brian Gerst | ec70de8 | 2009-01-27 12:56:47 +0900 | [diff] [blame] | 61 | unsigned disabled_cpus __cpuinitdata; |
Ingo Molnar | fdbecd9 | 2009-01-31 03:57:12 +0100 | [diff] [blame] | 62 | |
Brian Gerst | ec70de8 | 2009-01-27 12:56:47 +0900 | [diff] [blame] | 63 | /* Processor that is doing the boot up */ |
| 64 | unsigned int boot_cpu_physical_apicid = -1U; |
Glauber Costa | 5af5573 | 2008-03-25 13:28:56 -0300 | [diff] [blame] | 65 | |
Cyrill Gorcunov | 80e5609 | 2008-08-24 02:01:42 -0700 | [diff] [blame] | 66 | /* |
Ingo Molnar | fdbecd9 | 2009-01-31 03:57:12 +0100 | [diff] [blame] | 67 | * The highest APIC ID seen during enumeration. |
Cyrill Gorcunov | 80e5609 | 2008-08-24 02:01:42 -0700 | [diff] [blame] | 68 | */ |
Brian Gerst | ec70de8 | 2009-01-27 12:56:47 +0900 | [diff] [blame] | 69 | unsigned int max_physical_apicid; |
| 70 | |
Ingo Molnar | fdbecd9 | 2009-01-31 03:57:12 +0100 | [diff] [blame] | 71 | /* |
| 72 | * Bitmask of physically existing CPUs: |
| 73 | */ |
Brian Gerst | ec70de8 | 2009-01-27 12:56:47 +0900 | [diff] [blame] | 74 | physid_mask_t phys_cpu_present_map; |
| 75 | |
| 76 | /* |
| 77 | * Map cpu index to physical APIC ID |
| 78 | */ |
Vlad Zolotarov | 0816b0f | 2012-06-11 12:56:52 +0300 | [diff] [blame] | 79 | DEFINE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid, BAD_APICID); |
| 80 | DEFINE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_bios_cpu_apicid, BAD_APICID); |
Brian Gerst | ec70de8 | 2009-01-27 12:56:47 +0900 | [diff] [blame] | 81 | EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_apicid); |
| 82 | EXPORT_EARLY_PER_CPU_SYMBOL(x86_bios_cpu_apicid); |
Cyrill Gorcunov | 80e5609 | 2008-08-24 02:01:42 -0700 | [diff] [blame] | 83 | |
Yinghai Lu | b3c5117 | 2008-08-24 02:01:46 -0700 | [diff] [blame] | 84 | #ifdef CONFIG_X86_32 |
Tejun Heo | 4c321ff | 2011-01-23 14:37:30 +0100 | [diff] [blame] | 85 | |
Tejun Heo | 4c321ff | 2011-01-23 14:37:30 +0100 | [diff] [blame] | 86 | /* |
| 87 | * On x86_32, the mapping between cpu and logical apicid may vary |
| 88 | * depending on apic in use. The following early percpu variable is |
| 89 | * used for the mapping. This is where the behaviors of x86_64 and 32 |
| 90 | * actually diverge. Let's keep it ugly for now. |
| 91 | */ |
Vlad Zolotarov | 0816b0f | 2012-06-11 12:56:52 +0300 | [diff] [blame] | 92 | DEFINE_EARLY_PER_CPU_READ_MOSTLY(int, x86_cpu_to_logical_apicid, BAD_APICID); |
Tejun Heo | 4c321ff | 2011-01-23 14:37:30 +0100 | [diff] [blame] | 93 | |
Yinghai Lu | f28c0ae | 2008-08-24 02:01:49 -0700 | [diff] [blame] | 94 | /* Local APIC was disabled by the BIOS and enabled by the kernel */ |
| 95 | static int enabled_via_apicbase; |
| 96 | |
Cyrill Gorcunov | c0eaa45 | 2009-04-12 20:47:40 +0400 | [diff] [blame] | 97 | /* |
| 98 | * Handle interrupt mode configuration register (IMCR). |
| 99 | * This register controls whether the interrupt signals |
| 100 | * that reach the BSP come from the master PIC or from the |
| 101 | * local APIC. Before entering Symmetric I/O Mode, either |
| 102 | * the BIOS or the operating system must switch out of |
| 103 | * PIC Mode by changing the IMCR. |
| 104 | */ |
Alexander van Heukelum | 5cda395 | 2009-04-13 17:39:24 +0200 | [diff] [blame] | 105 | static inline void imcr_pic_to_apic(void) |
Cyrill Gorcunov | c0eaa45 | 2009-04-12 20:47:40 +0400 | [diff] [blame] | 106 | { |
| 107 | /* select IMCR register */ |
| 108 | outb(0x70, 0x22); |
| 109 | /* NMI and 8259 INTR go through APIC */ |
| 110 | outb(0x01, 0x23); |
| 111 | } |
| 112 | |
Alexander van Heukelum | 5cda395 | 2009-04-13 17:39:24 +0200 | [diff] [blame] | 113 | static inline void imcr_apic_to_pic(void) |
Cyrill Gorcunov | c0eaa45 | 2009-04-12 20:47:40 +0400 | [diff] [blame] | 114 | { |
| 115 | /* select IMCR register */ |
| 116 | outb(0x70, 0x22); |
| 117 | /* NMI and 8259 INTR go directly to BSP */ |
| 118 | outb(0x00, 0x23); |
| 119 | } |
Yinghai Lu | b3c5117 | 2008-08-24 02:01:46 -0700 | [diff] [blame] | 120 | #endif |
| 121 | |
Suresh Siddha | 279f146 | 2012-10-22 14:37:58 -0700 | [diff] [blame] | 122 | /* |
| 123 | * Knob to control our willingness to enable the local APIC. |
| 124 | * |
| 125 | * +1=force-enable |
| 126 | */ |
| 127 | static int force_enable_local_apic __initdata; |
| 128 | /* |
| 129 | * APIC command line parameters |
| 130 | */ |
| 131 | static int __init parse_lapic(char *arg) |
| 132 | { |
| 133 | if (config_enabled(CONFIG_X86_32) && !arg) |
| 134 | force_enable_local_apic = 1; |
Mathias Krause | 27cf929 | 2013-02-19 20:47:07 +0100 | [diff] [blame] | 135 | else if (arg && !strncmp(arg, "notscdeadline", 13)) |
Suresh Siddha | 279f146 | 2012-10-22 14:37:58 -0700 | [diff] [blame] | 136 | setup_clear_cpu_cap(X86_FEATURE_TSC_DEADLINE_TIMER); |
| 137 | return 0; |
| 138 | } |
| 139 | early_param("lapic", parse_lapic); |
| 140 | |
Yinghai Lu | b3c5117 | 2008-08-24 02:01:46 -0700 | [diff] [blame] | 141 | #ifdef CONFIG_X86_64 |
Chris Wright | bc1d99c | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 142 | static int apic_calibrate_pmtmr __initdata; |
Yinghai Lu | b3c5117 | 2008-08-24 02:01:46 -0700 | [diff] [blame] | 143 | static __init int setup_apicpmtimer(char *s) |
| 144 | { |
| 145 | apic_calibrate_pmtmr = 1; |
| 146 | notsc_setup(NULL); |
| 147 | return 0; |
| 148 | } |
| 149 | __setup("apicpmtimer", setup_apicpmtimer); |
| 150 | #endif |
| 151 | |
Suresh Siddha | fc1edaf | 2009-04-20 13:02:27 -0700 | [diff] [blame] | 152 | int x2apic_mode; |
Yinghai Lu | 06cd9a7 | 2009-02-16 17:29:58 -0800 | [diff] [blame] | 153 | #ifdef CONFIG_X86_X2APIC |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 154 | /* x2apic enabled before OS handover */ |
Yinghai Lu | fb209bd | 2011-12-21 17:45:17 -0800 | [diff] [blame] | 155 | int x2apic_preenabled; |
| 156 | static int x2apic_disabled; |
Yinghai Lu | a31bc32 | 2011-12-23 11:01:43 -0800 | [diff] [blame] | 157 | static int nox2apic; |
Yinghai Lu | 49899ea | 2008-08-24 02:01:47 -0700 | [diff] [blame] | 158 | static __init int setup_nox2apic(char *str) |
| 159 | { |
Suresh Siddha | 39d83a5 | 2009-04-20 13:02:29 -0700 | [diff] [blame] | 160 | if (x2apic_enabled()) { |
Yinghai Lu | a31bc32 | 2011-12-23 11:01:43 -0800 | [diff] [blame] | 161 | int apicid = native_apic_msr_read(APIC_ID); |
Suresh Siddha | 39d83a5 | 2009-04-20 13:02:29 -0700 | [diff] [blame] | 162 | |
Yinghai Lu | a31bc32 | 2011-12-23 11:01:43 -0800 | [diff] [blame] | 163 | if (apicid >= 255) { |
| 164 | pr_warning("Apicid: %08x, cannot enforce nox2apic\n", |
| 165 | apicid); |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | pr_warning("x2apic already enabled. will disable it\n"); |
| 170 | } else |
| 171 | setup_clear_cpu_cap(X86_FEATURE_X2APIC); |
| 172 | |
| 173 | nox2apic = 1; |
| 174 | |
Yinghai Lu | 49899ea | 2008-08-24 02:01:47 -0700 | [diff] [blame] | 175 | return 0; |
| 176 | } |
| 177 | early_param("nox2apic", setup_nox2apic); |
| 178 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
Yinghai Lu | b3c5117 | 2008-08-24 02:01:46 -0700 | [diff] [blame] | 180 | unsigned long mp_lapic_addr; |
| 181 | int disable_apic; |
| 182 | /* Disable local APIC timer from the kernel commandline or via dmi quirk */ |
Henrik Kretzschmar | 25874a2 | 2011-03-11 08:02:36 +0100 | [diff] [blame] | 183 | static int disable_apic_timer __initdata; |
Hiroshi Shimamoto | e83a5fd | 2008-01-30 13:32:35 +0100 | [diff] [blame] | 184 | /* Local APIC timer works in C2 */ |
Linus Torvalds | 2e7c283 | 2007-03-23 11:32:31 -0700 | [diff] [blame] | 185 | int local_apic_timer_c2_ok; |
| 186 | EXPORT_SYMBOL_GPL(local_apic_timer_c2_ok); |
| 187 | |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 188 | int first_system_vector = 0xfe; |
| 189 | |
Hiroshi Shimamoto | e83a5fd | 2008-01-30 13:32:35 +0100 | [diff] [blame] | 190 | /* |
| 191 | * Debug level, exported for io_apic.c |
| 192 | */ |
Maciej W. Rozycki | baa1318 | 2008-07-14 18:44:51 +0100 | [diff] [blame] | 193 | unsigned int apic_verbosity; |
Hiroshi Shimamoto | e83a5fd | 2008-01-30 13:32:35 +0100 | [diff] [blame] | 194 | |
Cyrill Gorcunov | 89c38c2 | 2008-08-24 02:01:43 -0700 | [diff] [blame] | 195 | int pic_mode; |
| 196 | |
Alexey Starikovskiy | bab4b27 | 2008-05-19 19:47:03 +0400 | [diff] [blame] | 197 | /* Have we found an MP table */ |
| 198 | int smp_found_config; |
| 199 | |
Aaron Durbin | 3992872 | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 200 | static struct resource lapic_resource = { |
| 201 | .name = "Local APIC", |
| 202 | .flags = IORESOURCE_MEM | IORESOURCE_BUSY, |
| 203 | }; |
| 204 | |
Jacob Pan | 1ade93e | 2011-11-10 13:42:40 +0000 | [diff] [blame] | 205 | unsigned int lapic_timer_frequency = 0; |
Thomas Gleixner | d03030e | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 206 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 207 | static void apic_pm_activate(void); |
Thomas Gleixner | ba7eda4 | 2007-10-12 23:04:07 +0200 | [diff] [blame] | 208 | |
Andi Kleen | d343289 | 2008-01-30 13:33:17 +0100 | [diff] [blame] | 209 | static unsigned long apic_phys; |
| 210 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 211 | /* |
| 212 | * Get the LAPIC version |
| 213 | */ |
| 214 | static inline int lapic_get_version(void) |
| 215 | { |
| 216 | return GET_APIC_VERSION(apic_read(APIC_LVR)); |
| 217 | } |
| 218 | |
| 219 | /* |
Cyrill Gorcunov | 9c80386 | 2008-08-16 23:21:54 +0400 | [diff] [blame] | 220 | * Check, if the APIC is integrated or a separate chip |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 221 | */ |
| 222 | static inline int lapic_is_integrated(void) |
| 223 | { |
Cyrill Gorcunov | 9c80386 | 2008-08-16 23:21:54 +0400 | [diff] [blame] | 224 | #ifdef CONFIG_X86_64 |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 225 | return 1; |
Cyrill Gorcunov | 9c80386 | 2008-08-16 23:21:54 +0400 | [diff] [blame] | 226 | #else |
| 227 | return APIC_INTEGRATED(lapic_get_version()); |
| 228 | #endif |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | /* |
| 232 | * Check, whether this is a modern or a first generation APIC |
| 233 | */ |
| 234 | static int modern_apic(void) |
| 235 | { |
| 236 | /* AMD systems use old APIC versions, so check the CPU */ |
| 237 | if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD && |
| 238 | boot_cpu_data.x86 >= 0xf) |
| 239 | return 1; |
| 240 | return lapic_get_version() >= 0x14; |
| 241 | } |
| 242 | |
Cyrill Gorcunov | 08306ce | 2009-04-12 20:47:41 +0400 | [diff] [blame] | 243 | /* |
Cyrill Gorcunov | a933c61 | 2009-10-14 00:07:04 +0400 | [diff] [blame] | 244 | * right after this call apic become NOOP driven |
| 245 | * so apic->write/read doesn't do anything |
Cyrill Gorcunov | 08306ce | 2009-04-12 20:47:41 +0400 | [diff] [blame] | 246 | */ |
Henrik Kretzschmar | 25874a2 | 2011-03-11 08:02:36 +0100 | [diff] [blame] | 247 | static void __init apic_disable(void) |
Cyrill Gorcunov | 08306ce | 2009-04-12 20:47:41 +0400 | [diff] [blame] | 248 | { |
Cyrill Gorcunov | f88f2b4 | 2009-10-15 19:04:16 +0400 | [diff] [blame] | 249 | pr_info("APIC: switched to apic NOOP\n"); |
Cyrill Gorcunov | a933c61 | 2009-10-14 00:07:04 +0400 | [diff] [blame] | 250 | apic = &apic_noop; |
Cyrill Gorcunov | 08306ce | 2009-04-12 20:47:41 +0400 | [diff] [blame] | 251 | } |
| 252 | |
Yinghai Lu | c1eeb2d | 2009-02-16 23:02:14 -0800 | [diff] [blame] | 253 | void native_apic_wait_icr_idle(void) |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 254 | { |
| 255 | while (apic_read(APIC_ICR) & APIC_ICR_BUSY) |
| 256 | cpu_relax(); |
| 257 | } |
| 258 | |
Yinghai Lu | c1eeb2d | 2009-02-16 23:02:14 -0800 | [diff] [blame] | 259 | u32 native_safe_apic_wait_icr_idle(void) |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 260 | { |
| 261 | u32 send_status; |
| 262 | int timeout; |
| 263 | |
| 264 | timeout = 0; |
| 265 | do { |
| 266 | send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY; |
| 267 | if (!send_status) |
| 268 | break; |
Fernando Luis Vazquez Cao | b49d7d8 | 2011-12-15 11:32:24 +0900 | [diff] [blame] | 269 | inc_irq_stat(icr_read_retry_count); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 270 | udelay(100); |
| 271 | } while (timeout++ < 1000); |
| 272 | |
| 273 | return send_status; |
| 274 | } |
| 275 | |
Yinghai Lu | c1eeb2d | 2009-02-16 23:02:14 -0800 | [diff] [blame] | 276 | void native_apic_icr_write(u32 low, u32 id) |
Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 277 | { |
Cyrill Gorcunov | ed4e5ec | 2008-08-15 13:51:20 +0200 | [diff] [blame] | 278 | apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(id)); |
Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 279 | apic_write(APIC_ICR, low); |
| 280 | } |
| 281 | |
Yinghai Lu | c1eeb2d | 2009-02-16 23:02:14 -0800 | [diff] [blame] | 282 | u64 native_apic_icr_read(void) |
Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 283 | { |
| 284 | u32 icr1, icr2; |
| 285 | |
| 286 | icr2 = apic_read(APIC_ICR2); |
| 287 | icr1 = apic_read(APIC_ICR); |
| 288 | |
Cyrill Gorcunov | cf9768d7 | 2008-08-16 23:21:55 +0400 | [diff] [blame] | 289 | return icr1 | ((u64)icr2 << 32); |
Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Cyrill Gorcunov | 7c37e48 | 2008-08-24 02:01:40 -0700 | [diff] [blame] | 292 | #ifdef CONFIG_X86_32 |
| 293 | /** |
| 294 | * get_physical_broadcast - Get number of physical broadcast IDs |
| 295 | */ |
| 296 | int get_physical_broadcast(void) |
| 297 | { |
| 298 | return modern_apic() ? 0xff : 0xf; |
| 299 | } |
| 300 | #endif |
| 301 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 302 | /** |
| 303 | * lapic_get_maxlvt - get the maximum number of local vector table entries |
| 304 | */ |
| 305 | int lapic_get_maxlvt(void) |
| 306 | { |
Cyrill Gorcunov | 36a028d | 2008-07-24 13:52:28 +0200 | [diff] [blame] | 307 | unsigned int v; |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 308 | |
| 309 | v = apic_read(APIC_LVR); |
Cyrill Gorcunov | 36a028d | 2008-07-24 13:52:28 +0200 | [diff] [blame] | 310 | /* |
| 311 | * - we always have APIC integrated on 64bit mode |
| 312 | * - 82489DXs do not report # of LVT entries |
| 313 | */ |
| 314 | return APIC_INTEGRATED(GET_APIC_VERSION(v)) ? GET_APIC_MAXLVT(v) : 2; |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | /* |
Cyrill Gorcunov | 274cfe5 | 2008-08-16 23:21:53 +0400 | [diff] [blame] | 318 | * Local APIC timer |
| 319 | */ |
| 320 | |
Cyrill Gorcunov | c40aaec | 2008-08-18 20:45:55 +0400 | [diff] [blame] | 321 | /* Clock divisor */ |
Cyrill Gorcunov | c40aaec | 2008-08-18 20:45:55 +0400 | [diff] [blame] | 322 | #define APIC_DIVISOR 16 |
Suresh Siddha | 279f146 | 2012-10-22 14:37:58 -0700 | [diff] [blame] | 323 | #define TSC_DIVISOR 32 |
Cyrill Gorcunov | f07f4f9 | 2008-08-15 13:51:21 +0200 | [diff] [blame] | 324 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 325 | /* |
| 326 | * This function sets up the local APIC timer, with a timeout of |
| 327 | * 'clocks' APIC bus clock. During calibration we actually call |
| 328 | * this function twice on the boot CPU, once with a bogus timeout |
| 329 | * value, second time for real. The other (noncalibrating) CPUs |
| 330 | * call this function only once, with the real, calibrated value. |
| 331 | * |
| 332 | * We do reads before writes even if unnecessary, to get around the |
| 333 | * P5 APIC double write bug. |
| 334 | */ |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 335 | static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen) |
| 336 | { |
| 337 | unsigned int lvtt_value, tmp_value; |
| 338 | |
| 339 | lvtt_value = LOCAL_TIMER_VECTOR; |
| 340 | if (!oneshot) |
| 341 | lvtt_value |= APIC_LVT_TIMER_PERIODIC; |
Suresh Siddha | 279f146 | 2012-10-22 14:37:58 -0700 | [diff] [blame] | 342 | else if (boot_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER)) |
| 343 | lvtt_value |= APIC_LVT_TIMER_TSCDEADLINE; |
| 344 | |
Cyrill Gorcunov | f07f4f9 | 2008-08-15 13:51:21 +0200 | [diff] [blame] | 345 | if (!lapic_is_integrated()) |
| 346 | lvtt_value |= SET_APIC_TIMER_BASE(APIC_TIMER_BASE_DIV); |
| 347 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 348 | if (!irqen) |
| 349 | lvtt_value |= APIC_LVT_MASKED; |
| 350 | |
| 351 | apic_write(APIC_LVTT, lvtt_value); |
| 352 | |
Suresh Siddha | 279f146 | 2012-10-22 14:37:58 -0700 | [diff] [blame] | 353 | if (lvtt_value & APIC_LVT_TIMER_TSCDEADLINE) { |
| 354 | printk_once(KERN_DEBUG "TSC deadline timer enabled\n"); |
| 355 | return; |
| 356 | } |
| 357 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 358 | /* |
| 359 | * Divide PICLK by 16 |
| 360 | */ |
| 361 | tmp_value = apic_read(APIC_TDCR); |
Cyrill Gorcunov | c40aaec | 2008-08-18 20:45:55 +0400 | [diff] [blame] | 362 | apic_write(APIC_TDCR, |
| 363 | (tmp_value & ~(APIC_TDR_DIV_1 | APIC_TDR_DIV_TMBASE)) | |
| 364 | APIC_TDR_DIV_16); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 365 | |
| 366 | if (!oneshot) |
Cyrill Gorcunov | f07f4f9 | 2008-08-15 13:51:21 +0200 | [diff] [blame] | 367 | apic_write(APIC_TMICT, clocks / APIC_DIVISOR); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | /* |
Robert Richter | a68c439 | 2010-10-06 12:27:53 +0200 | [diff] [blame] | 371 | * Setup extended LVT, AMD specific |
Robert Richter | 7b83dae | 2008-01-30 13:30:40 +0100 | [diff] [blame] | 372 | * |
Robert Richter | a68c439 | 2010-10-06 12:27:53 +0200 | [diff] [blame] | 373 | * Software should use the LVT offsets the BIOS provides. The offsets |
| 374 | * are determined by the subsystems using it like those for MCE |
| 375 | * threshold or IBS. On K8 only offset 0 (APIC500) and MCE interrupts |
| 376 | * are supported. Beginning with family 10h at least 4 offsets are |
| 377 | * available. |
Robert Richter | 286f571 | 2008-07-22 21:08:46 +0200 | [diff] [blame] | 378 | * |
Robert Richter | a68c439 | 2010-10-06 12:27:53 +0200 | [diff] [blame] | 379 | * Since the offsets must be consistent for all cores, we keep track |
| 380 | * of the LVT offsets in software and reserve the offset for the same |
| 381 | * vector also to be used on other cores. An offset is freed by |
| 382 | * setting the entry to APIC_EILVT_MASKED. |
| 383 | * |
| 384 | * If the BIOS is right, there should be no conflicts. Otherwise a |
| 385 | * "[Firmware Bug]: ..." error message is generated. However, if |
| 386 | * software does not properly determines the offsets, it is not |
| 387 | * necessarily a BIOS bug. |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 388 | */ |
Robert Richter | 7b83dae | 2008-01-30 13:30:40 +0100 | [diff] [blame] | 389 | |
Robert Richter | a68c439 | 2010-10-06 12:27:53 +0200 | [diff] [blame] | 390 | static atomic_t eilvt_offsets[APIC_EILVT_NR_MAX]; |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 391 | |
Robert Richter | a68c439 | 2010-10-06 12:27:53 +0200 | [diff] [blame] | 392 | static inline int eilvt_entry_is_changeable(unsigned int old, unsigned int new) |
| 393 | { |
| 394 | return (old & APIC_EILVT_MASKED) |
| 395 | || (new == APIC_EILVT_MASKED) |
| 396 | || ((new & ~APIC_EILVT_MASKED) == old); |
| 397 | } |
| 398 | |
| 399 | static unsigned int reserve_eilvt_offset(int offset, unsigned int new) |
| 400 | { |
Robert Richter | 8abc312 | 2012-03-27 20:04:02 +0200 | [diff] [blame] | 401 | unsigned int rsvd, vector; |
Robert Richter | a68c439 | 2010-10-06 12:27:53 +0200 | [diff] [blame] | 402 | |
| 403 | if (offset >= APIC_EILVT_NR_MAX) |
| 404 | return ~0; |
| 405 | |
Robert Richter | 8abc312 | 2012-03-27 20:04:02 +0200 | [diff] [blame] | 406 | rsvd = atomic_read(&eilvt_offsets[offset]); |
Robert Richter | a68c439 | 2010-10-06 12:27:53 +0200 | [diff] [blame] | 407 | do { |
Robert Richter | 8abc312 | 2012-03-27 20:04:02 +0200 | [diff] [blame] | 408 | vector = rsvd & ~APIC_EILVT_MASKED; /* 0: unassigned */ |
| 409 | if (vector && !eilvt_entry_is_changeable(vector, new)) |
Robert Richter | a68c439 | 2010-10-06 12:27:53 +0200 | [diff] [blame] | 410 | /* may not change if vectors are different */ |
| 411 | return rsvd; |
| 412 | rsvd = atomic_cmpxchg(&eilvt_offsets[offset], rsvd, new); |
| 413 | } while (rsvd != new); |
| 414 | |
Robert Richter | 8abc312 | 2012-03-27 20:04:02 +0200 | [diff] [blame] | 415 | rsvd &= ~APIC_EILVT_MASKED; |
| 416 | if (rsvd && rsvd != vector) |
| 417 | pr_info("LVT offset %d assigned for vector 0x%02x\n", |
| 418 | offset, rsvd); |
| 419 | |
Robert Richter | a68c439 | 2010-10-06 12:27:53 +0200 | [diff] [blame] | 420 | return new; |
| 421 | } |
| 422 | |
| 423 | /* |
| 424 | * If mask=1, the LVT entry does not generate interrupts while mask=0 |
Robert Richter | cbf74ce | 2011-05-30 16:31:11 +0200 | [diff] [blame] | 425 | * enables the vector. See also the BKDGs. Must be called with |
| 426 | * preemption disabled. |
Robert Richter | a68c439 | 2010-10-06 12:27:53 +0200 | [diff] [blame] | 427 | */ |
| 428 | |
Robert Richter | 27afdf2 | 2010-10-06 12:27:54 +0200 | [diff] [blame] | 429 | int setup_APIC_eilvt(u8 offset, u8 vector, u8 msg_type, u8 mask) |
Robert Richter | a68c439 | 2010-10-06 12:27:53 +0200 | [diff] [blame] | 430 | { |
| 431 | unsigned long reg = APIC_EILVTn(offset); |
| 432 | unsigned int new, old, reserved; |
| 433 | |
| 434 | new = (mask << 16) | (msg_type << 8) | vector; |
| 435 | old = apic_read(reg); |
| 436 | reserved = reserve_eilvt_offset(offset, new); |
| 437 | |
| 438 | if (reserved != new) { |
Robert Richter | eb48c9c | 2010-10-25 16:03:39 +0200 | [diff] [blame] | 439 | pr_err(FW_BUG "cpu %d, try to use APIC%lX (LVT offset %d) for " |
| 440 | "vector 0x%x, but the register is already in use for " |
| 441 | "vector 0x%x on another cpu\n", |
| 442 | smp_processor_id(), reg, offset, new, reserved); |
Robert Richter | a68c439 | 2010-10-06 12:27:53 +0200 | [diff] [blame] | 443 | return -EINVAL; |
| 444 | } |
| 445 | |
| 446 | if (!eilvt_entry_is_changeable(old, new)) { |
Robert Richter | eb48c9c | 2010-10-25 16:03:39 +0200 | [diff] [blame] | 447 | pr_err(FW_BUG "cpu %d, try to use APIC%lX (LVT offset %d) for " |
| 448 | "vector 0x%x, but the register is already in use for " |
| 449 | "vector 0x%x on this cpu\n", |
| 450 | smp_processor_id(), reg, offset, new, old); |
Robert Richter | a68c439 | 2010-10-06 12:27:53 +0200 | [diff] [blame] | 451 | return -EBUSY; |
| 452 | } |
| 453 | |
| 454 | apic_write(reg, new); |
| 455 | |
| 456 | return 0; |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 457 | } |
Robert Richter | 27afdf2 | 2010-10-06 12:27:54 +0200 | [diff] [blame] | 458 | EXPORT_SYMBOL_GPL(setup_APIC_eilvt); |
Robert Richter | 7b83dae | 2008-01-30 13:30:40 +0100 | [diff] [blame] | 459 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 460 | /* |
| 461 | * Program the next event, relative to now |
| 462 | */ |
Thomas Gleixner | ba7eda4 | 2007-10-12 23:04:07 +0200 | [diff] [blame] | 463 | static int lapic_next_event(unsigned long delta, |
| 464 | struct clock_event_device *evt) |
| 465 | { |
| 466 | apic_write(APIC_TMICT, delta); |
| 467 | return 0; |
| 468 | } |
| 469 | |
Suresh Siddha | 279f146 | 2012-10-22 14:37:58 -0700 | [diff] [blame] | 470 | static int lapic_next_deadline(unsigned long delta, |
| 471 | struct clock_event_device *evt) |
| 472 | { |
| 473 | u64 tsc; |
| 474 | |
| 475 | rdtscll(tsc); |
| 476 | wrmsrl(MSR_IA32_TSC_DEADLINE, tsc + (((u64) delta) * TSC_DIVISOR)); |
| 477 | return 0; |
| 478 | } |
| 479 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 480 | /* |
| 481 | * Setup the lapic timer in periodic or oneshot mode |
| 482 | */ |
Thomas Gleixner | ba7eda4 | 2007-10-12 23:04:07 +0200 | [diff] [blame] | 483 | static void lapic_timer_setup(enum clock_event_mode mode, |
| 484 | struct clock_event_device *evt) |
| 485 | { |
| 486 | unsigned long flags; |
| 487 | unsigned int v; |
| 488 | |
| 489 | /* Lapic used as dummy for broadcast ? */ |
| 490 | if (evt->features & CLOCK_EVT_FEAT_DUMMY) |
| 491 | return; |
| 492 | |
| 493 | local_irq_save(flags); |
| 494 | |
| 495 | switch (mode) { |
| 496 | case CLOCK_EVT_MODE_PERIODIC: |
| 497 | case CLOCK_EVT_MODE_ONESHOT: |
Jacob Pan | 1ade93e | 2011-11-10 13:42:40 +0000 | [diff] [blame] | 498 | __setup_APIC_LVTT(lapic_timer_frequency, |
Thomas Gleixner | ba7eda4 | 2007-10-12 23:04:07 +0200 | [diff] [blame] | 499 | mode != CLOCK_EVT_MODE_PERIODIC, 1); |
| 500 | break; |
| 501 | case CLOCK_EVT_MODE_UNUSED: |
| 502 | case CLOCK_EVT_MODE_SHUTDOWN: |
| 503 | v = apic_read(APIC_LVTT); |
| 504 | v |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR); |
| 505 | apic_write(APIC_LVTT, v); |
Andreas Herrmann | 6f9b410 | 2009-10-27 11:01:38 +0100 | [diff] [blame] | 506 | apic_write(APIC_TMICT, 0); |
Thomas Gleixner | ba7eda4 | 2007-10-12 23:04:07 +0200 | [diff] [blame] | 507 | break; |
| 508 | case CLOCK_EVT_MODE_RESUME: |
| 509 | /* Nothing to do here */ |
| 510 | break; |
| 511 | } |
| 512 | |
| 513 | local_irq_restore(flags); |
| 514 | } |
| 515 | |
| 516 | /* |
| 517 | * Local APIC timer broadcast function |
| 518 | */ |
Mike Travis | 9628937 | 2008-12-31 18:08:46 -0800 | [diff] [blame] | 519 | static void lapic_timer_broadcast(const struct cpumask *mask) |
Thomas Gleixner | ba7eda4 | 2007-10-12 23:04:07 +0200 | [diff] [blame] | 520 | { |
| 521 | #ifdef CONFIG_SMP |
Ingo Molnar | dac5f41 | 2009-01-28 15:42:24 +0100 | [diff] [blame] | 522 | apic->send_IPI_mask(mask, LOCAL_TIMER_VECTOR); |
Thomas Gleixner | ba7eda4 | 2007-10-12 23:04:07 +0200 | [diff] [blame] | 523 | #endif |
| 524 | } |
| 525 | |
Henrik Kretzschmar | 25874a2 | 2011-03-11 08:02:36 +0100 | [diff] [blame] | 526 | |
| 527 | /* |
| 528 | * The local apic timer can be used for any function which is CPU local. |
| 529 | */ |
| 530 | static struct clock_event_device lapic_clockevent = { |
| 531 | .name = "lapic", |
| 532 | .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT |
| 533 | | CLOCK_EVT_FEAT_C3STOP | CLOCK_EVT_FEAT_DUMMY, |
| 534 | .shift = 32, |
| 535 | .set_mode = lapic_timer_setup, |
| 536 | .set_next_event = lapic_next_event, |
| 537 | .broadcast = lapic_timer_broadcast, |
| 538 | .rating = 100, |
| 539 | .irq = -1, |
| 540 | }; |
| 541 | static DEFINE_PER_CPU(struct clock_event_device, lapic_events); |
| 542 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 543 | /* |
Uwe Kleine-König | 421f91d | 2010-06-11 12:17:00 +0200 | [diff] [blame] | 544 | * Setup the local APIC timer for this CPU. Copy the initialized values |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 545 | * of the boot CPU and register the clock event in the framework. |
| 546 | */ |
Cyrill Gorcunov | db4b552 | 2008-08-24 02:01:39 -0700 | [diff] [blame] | 547 | static void __cpuinit setup_APIC_timer(void) |
Fernando Luis VazquezCao | 8339e9f | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 548 | { |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 549 | struct clock_event_device *levt = &__get_cpu_var(lapic_events); |
| 550 | |
Christoph Lameter | 349c004 | 2011-03-12 12:50:10 +0100 | [diff] [blame] | 551 | if (this_cpu_has(X86_FEATURE_ARAT)) { |
Venkatesh Pallipadi | db954b5 | 2009-04-06 18:51:29 -0700 | [diff] [blame] | 552 | lapic_clockevent.features &= ~CLOCK_EVT_FEAT_C3STOP; |
| 553 | /* Make LAPIC timer preferrable over percpu HPET */ |
| 554 | lapic_clockevent.rating = 150; |
| 555 | } |
| 556 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 557 | memcpy(levt, &lapic_clockevent, sizeof(*levt)); |
Rusty Russell | 320ab2b | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 558 | levt->cpumask = cpumask_of(smp_processor_id()); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 559 | |
Suresh Siddha | 279f146 | 2012-10-22 14:37:58 -0700 | [diff] [blame] | 560 | if (this_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER)) { |
| 561 | levt->features &= ~(CLOCK_EVT_FEAT_PERIODIC | |
| 562 | CLOCK_EVT_FEAT_DUMMY); |
| 563 | levt->set_next_event = lapic_next_deadline; |
| 564 | clockevents_config_and_register(levt, |
| 565 | (tsc_khz / TSC_DIVISOR) * 1000, |
| 566 | 0xF, ~0UL); |
| 567 | } else |
| 568 | clockevents_register_device(levt); |
Fernando Luis VazquezCao | 8339e9f | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 569 | } |
| 570 | |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 571 | /* |
| 572 | * In this functions we calibrate APIC bus clocks to the external timer. |
| 573 | * |
| 574 | * We want to do the calibration only once since we want to have local timer |
| 575 | * irqs syncron. CPUs connected by the same APIC bus have the very same bus |
| 576 | * frequency. |
| 577 | * |
| 578 | * This was previously done by reading the PIT/HPET and waiting for a wrap |
| 579 | * around to find out, that a tick has elapsed. I have a box, where the PIT |
| 580 | * readout is broken, so it never gets out of the wait loop again. This was |
| 581 | * also reported by others. |
| 582 | * |
| 583 | * Monitoring the jiffies value is inaccurate and the clockevents |
| 584 | * infrastructure allows us to do a simple substitution of the interrupt |
| 585 | * handler. |
| 586 | * |
| 587 | * The calibration routine also uses the pm_timer when possible, as the PIT |
| 588 | * happens to run way too slow (factor 2.3 on my VAIO CoreDuo, which goes |
| 589 | * back to normal later in the boot process). |
| 590 | */ |
| 591 | |
| 592 | #define LAPIC_CAL_LOOPS (HZ/10) |
| 593 | |
| 594 | static __initdata int lapic_cal_loops = -1; |
| 595 | static __initdata long lapic_cal_t1, lapic_cal_t2; |
| 596 | static __initdata unsigned long long lapic_cal_tsc1, lapic_cal_tsc2; |
| 597 | static __initdata unsigned long lapic_cal_pm1, lapic_cal_pm2; |
| 598 | static __initdata unsigned long lapic_cal_j1, lapic_cal_j2; |
| 599 | |
| 600 | /* |
| 601 | * Temporary interrupt handler. |
| 602 | */ |
| 603 | static void __init lapic_cal_handler(struct clock_event_device *dev) |
| 604 | { |
| 605 | unsigned long long tsc = 0; |
| 606 | long tapic = apic_read(APIC_TMCCT); |
| 607 | unsigned long pm = acpi_pm_read_early(); |
| 608 | |
| 609 | if (cpu_has_tsc) |
| 610 | rdtscll(tsc); |
| 611 | |
| 612 | switch (lapic_cal_loops++) { |
| 613 | case 0: |
| 614 | lapic_cal_t1 = tapic; |
| 615 | lapic_cal_tsc1 = tsc; |
| 616 | lapic_cal_pm1 = pm; |
| 617 | lapic_cal_j1 = jiffies; |
| 618 | break; |
| 619 | |
| 620 | case LAPIC_CAL_LOOPS: |
| 621 | lapic_cal_t2 = tapic; |
| 622 | lapic_cal_tsc2 = tsc; |
| 623 | if (pm < lapic_cal_pm1) |
| 624 | pm += ACPI_PM_OVRRUN; |
| 625 | lapic_cal_pm2 = pm; |
| 626 | lapic_cal_j2 = jiffies; |
| 627 | break; |
| 628 | } |
| 629 | } |
| 630 | |
Yasuaki Ishimatsu | 754ef0c | 2009-01-28 12:51:09 +0900 | [diff] [blame] | 631 | static int __init |
| 632 | calibrate_by_pmtimer(long deltapm, long *delta, long *deltatsc) |
Cyrill Gorcunov | b189892 | 2008-09-12 23:58:24 +0400 | [diff] [blame] | 633 | { |
| 634 | const long pm_100ms = PMTMR_TICKS_PER_SEC / 10; |
| 635 | const long pm_thresh = pm_100ms / 100; |
| 636 | unsigned long mult; |
| 637 | u64 res; |
| 638 | |
| 639 | #ifndef CONFIG_X86_PM_TIMER |
| 640 | return -1; |
| 641 | #endif |
| 642 | |
Yasuaki Ishimatsu | 39ba5d4 | 2009-01-28 12:52:24 +0900 | [diff] [blame] | 643 | apic_printk(APIC_VERBOSE, "... PM-Timer delta = %ld\n", deltapm); |
Cyrill Gorcunov | b189892 | 2008-09-12 23:58:24 +0400 | [diff] [blame] | 644 | |
| 645 | /* Check, if the PM timer is available */ |
| 646 | if (!deltapm) |
| 647 | return -1; |
| 648 | |
| 649 | mult = clocksource_hz2mult(PMTMR_TICKS_PER_SEC, 22); |
| 650 | |
| 651 | if (deltapm > (pm_100ms - pm_thresh) && |
| 652 | deltapm < (pm_100ms + pm_thresh)) { |
Yasuaki Ishimatsu | 39ba5d4 | 2009-01-28 12:52:24 +0900 | [diff] [blame] | 653 | apic_printk(APIC_VERBOSE, "... PM-Timer result ok\n"); |
Yasuaki Ishimatsu | 754ef0c | 2009-01-28 12:51:09 +0900 | [diff] [blame] | 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | res = (((u64)deltapm) * mult) >> 22; |
| 658 | do_div(res, 1000000); |
| 659 | pr_warning("APIC calibration not consistent " |
Yasuaki Ishimatsu | 39ba5d4 | 2009-01-28 12:52:24 +0900 | [diff] [blame] | 660 | "with PM-Timer: %ldms instead of 100ms\n",(long)res); |
Yasuaki Ishimatsu | 754ef0c | 2009-01-28 12:51:09 +0900 | [diff] [blame] | 661 | |
| 662 | /* Correct the lapic counter value */ |
| 663 | res = (((u64)(*delta)) * pm_100ms); |
| 664 | do_div(res, deltapm); |
| 665 | pr_info("APIC delta adjusted to PM-Timer: " |
| 666 | "%lu (%ld)\n", (unsigned long)res, *delta); |
| 667 | *delta = (long)res; |
| 668 | |
| 669 | /* Correct the tsc counter value */ |
| 670 | if (cpu_has_tsc) { |
| 671 | res = (((u64)(*deltatsc)) * pm_100ms); |
Cyrill Gorcunov | b189892 | 2008-09-12 23:58:24 +0400 | [diff] [blame] | 672 | do_div(res, deltapm); |
Yasuaki Ishimatsu | 754ef0c | 2009-01-28 12:51:09 +0900 | [diff] [blame] | 673 | apic_printk(APIC_VERBOSE, "TSC delta adjusted to " |
Frans Pop | 3235dc3 | 2010-02-06 18:47:17 +0100 | [diff] [blame] | 674 | "PM-Timer: %lu (%ld)\n", |
Yasuaki Ishimatsu | 754ef0c | 2009-01-28 12:51:09 +0900 | [diff] [blame] | 675 | (unsigned long)res, *deltatsc); |
| 676 | *deltatsc = (long)res; |
Cyrill Gorcunov | b189892 | 2008-09-12 23:58:24 +0400 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | return 0; |
| 680 | } |
| 681 | |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 682 | static int __init calibrate_APIC_clock(void) |
| 683 | { |
| 684 | struct clock_event_device *levt = &__get_cpu_var(lapic_events); |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 685 | void (*real_handler)(struct clock_event_device *dev); |
| 686 | unsigned long deltaj; |
Yasuaki Ishimatsu | 754ef0c | 2009-01-28 12:51:09 +0900 | [diff] [blame] | 687 | long delta, deltatsc; |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 688 | int pm_referenced = 0; |
| 689 | |
Jacob Pan | 1ade93e | 2011-11-10 13:42:40 +0000 | [diff] [blame] | 690 | /** |
| 691 | * check if lapic timer has already been calibrated by platform |
| 692 | * specific routine, such as tsc calibration code. if so, we just fill |
| 693 | * in the clockevent structure and return. |
| 694 | */ |
| 695 | |
Suresh Siddha | 279f146 | 2012-10-22 14:37:58 -0700 | [diff] [blame] | 696 | if (boot_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER)) { |
| 697 | return 0; |
| 698 | } else if (lapic_timer_frequency) { |
Jacob Pan | 1ade93e | 2011-11-10 13:42:40 +0000 | [diff] [blame] | 699 | apic_printk(APIC_VERBOSE, "lapic timer already calibrated %d\n", |
| 700 | lapic_timer_frequency); |
| 701 | lapic_clockevent.mult = div_sc(lapic_timer_frequency/APIC_DIVISOR, |
| 702 | TICK_NSEC, lapic_clockevent.shift); |
| 703 | lapic_clockevent.max_delta_ns = |
| 704 | clockevent_delta2ns(0x7FFFFF, &lapic_clockevent); |
| 705 | lapic_clockevent.min_delta_ns = |
| 706 | clockevent_delta2ns(0xF, &lapic_clockevent); |
| 707 | lapic_clockevent.features &= ~CLOCK_EVT_FEAT_DUMMY; |
| 708 | return 0; |
| 709 | } |
| 710 | |
Suresh Siddha | 279f146 | 2012-10-22 14:37:58 -0700 | [diff] [blame] | 711 | apic_printk(APIC_VERBOSE, "Using local APIC timer interrupts.\n" |
| 712 | "calibrating APIC timer ...\n"); |
| 713 | |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 714 | local_irq_disable(); |
| 715 | |
| 716 | /* Replace the global interrupt handler */ |
| 717 | real_handler = global_clock_event->event_handler; |
| 718 | global_clock_event->event_handler = lapic_cal_handler; |
| 719 | |
| 720 | /* |
Cyrill Gorcunov | 81608f3 | 2008-10-10 19:00:17 +0400 | [diff] [blame] | 721 | * Setup the APIC counter to maximum. There is no way the lapic |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 722 | * can underflow in the 100ms detection time frame |
| 723 | */ |
Cyrill Gorcunov | 81608f3 | 2008-10-10 19:00:17 +0400 | [diff] [blame] | 724 | __setup_APIC_LVTT(0xffffffff, 0, 0); |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 725 | |
| 726 | /* Let the interrupts run */ |
| 727 | local_irq_enable(); |
| 728 | |
| 729 | while (lapic_cal_loops <= LAPIC_CAL_LOOPS) |
| 730 | cpu_relax(); |
| 731 | |
| 732 | local_irq_disable(); |
| 733 | |
| 734 | /* Restore the real event handler */ |
| 735 | global_clock_event->event_handler = real_handler; |
| 736 | |
| 737 | /* Build delta t1-t2 as apic timer counts down */ |
| 738 | delta = lapic_cal_t1 - lapic_cal_t2; |
| 739 | apic_printk(APIC_VERBOSE, "... lapic delta = %ld\n", delta); |
| 740 | |
Yasuaki Ishimatsu | 754ef0c | 2009-01-28 12:51:09 +0900 | [diff] [blame] | 741 | deltatsc = (long)(lapic_cal_tsc2 - lapic_cal_tsc1); |
| 742 | |
Cyrill Gorcunov | b189892 | 2008-09-12 23:58:24 +0400 | [diff] [blame] | 743 | /* we trust the PM based calibration if possible */ |
| 744 | pm_referenced = !calibrate_by_pmtimer(lapic_cal_pm2 - lapic_cal_pm1, |
Yasuaki Ishimatsu | 754ef0c | 2009-01-28 12:51:09 +0900 | [diff] [blame] | 745 | &delta, &deltatsc); |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 746 | |
| 747 | /* Calculate the scaled math multiplication factor */ |
| 748 | lapic_clockevent.mult = div_sc(delta, TICK_NSEC * LAPIC_CAL_LOOPS, |
| 749 | lapic_clockevent.shift); |
| 750 | lapic_clockevent.max_delta_ns = |
Pierre Tardy | 4aed89d | 2011-01-06 16:23:29 +0100 | [diff] [blame] | 751 | clockevent_delta2ns(0x7FFFFFFF, &lapic_clockevent); |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 752 | lapic_clockevent.min_delta_ns = |
| 753 | clockevent_delta2ns(0xF, &lapic_clockevent); |
| 754 | |
Jacob Pan | 1ade93e | 2011-11-10 13:42:40 +0000 | [diff] [blame] | 755 | lapic_timer_frequency = (delta * APIC_DIVISOR) / LAPIC_CAL_LOOPS; |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 756 | |
| 757 | apic_printk(APIC_VERBOSE, "..... delta %ld\n", delta); |
Thomas Gleixner | 411462f | 2009-11-16 11:52:39 +0100 | [diff] [blame] | 758 | apic_printk(APIC_VERBOSE, "..... mult: %u\n", lapic_clockevent.mult); |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 759 | apic_printk(APIC_VERBOSE, "..... calibration result: %u\n", |
Jacob Pan | 1ade93e | 2011-11-10 13:42:40 +0000 | [diff] [blame] | 760 | lapic_timer_frequency); |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 761 | |
| 762 | if (cpu_has_tsc) { |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 763 | apic_printk(APIC_VERBOSE, "..... CPU clock speed is " |
| 764 | "%ld.%04ld MHz.\n", |
Yasuaki Ishimatsu | 754ef0c | 2009-01-28 12:51:09 +0900 | [diff] [blame] | 765 | (deltatsc / LAPIC_CAL_LOOPS) / (1000000 / HZ), |
| 766 | (deltatsc / LAPIC_CAL_LOOPS) % (1000000 / HZ)); |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | apic_printk(APIC_VERBOSE, "..... host bus clock speed is " |
| 770 | "%u.%04u MHz.\n", |
Jacob Pan | 1ade93e | 2011-11-10 13:42:40 +0000 | [diff] [blame] | 771 | lapic_timer_frequency / (1000000 / HZ), |
| 772 | lapic_timer_frequency % (1000000 / HZ)); |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 773 | |
| 774 | /* |
| 775 | * Do a sanity check on the APIC calibration result |
| 776 | */ |
Jacob Pan | 1ade93e | 2011-11-10 13:42:40 +0000 | [diff] [blame] | 777 | if (lapic_timer_frequency < (1000000 / HZ)) { |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 778 | local_irq_enable(); |
Cyrill Gorcunov | ba21ebb | 2008-11-10 09:16:41 +0100 | [diff] [blame] | 779 | pr_warning("APIC frequency too slow, disabling apic timer\n"); |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 780 | return -1; |
| 781 | } |
| 782 | |
| 783 | levt->features &= ~CLOCK_EVT_FEAT_DUMMY; |
| 784 | |
Cyrill Gorcunov | b189892 | 2008-09-12 23:58:24 +0400 | [diff] [blame] | 785 | /* |
| 786 | * PM timer calibration failed or not turned on |
| 787 | * so lets try APIC timer based calibration |
| 788 | */ |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 789 | if (!pm_referenced) { |
| 790 | apic_printk(APIC_VERBOSE, "... verify APIC timer\n"); |
| 791 | |
| 792 | /* |
| 793 | * Setup the apic timer manually |
| 794 | */ |
| 795 | levt->event_handler = lapic_cal_handler; |
| 796 | lapic_timer_setup(CLOCK_EVT_MODE_PERIODIC, levt); |
| 797 | lapic_cal_loops = -1; |
| 798 | |
| 799 | /* Let the interrupts run */ |
| 800 | local_irq_enable(); |
| 801 | |
| 802 | while (lapic_cal_loops <= LAPIC_CAL_LOOPS) |
| 803 | cpu_relax(); |
| 804 | |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 805 | /* Stop the lapic timer */ |
| 806 | lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, levt); |
| 807 | |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 808 | /* Jiffies delta */ |
| 809 | deltaj = lapic_cal_j2 - lapic_cal_j1; |
| 810 | apic_printk(APIC_VERBOSE, "... jiffies delta = %lu\n", deltaj); |
| 811 | |
| 812 | /* Check, if the jiffies result is consistent */ |
| 813 | if (deltaj >= LAPIC_CAL_LOOPS-2 && deltaj <= LAPIC_CAL_LOOPS+2) |
| 814 | apic_printk(APIC_VERBOSE, "... jiffies result ok\n"); |
| 815 | else |
| 816 | levt->features |= CLOCK_EVT_FEAT_DUMMY; |
| 817 | } else |
| 818 | local_irq_enable(); |
| 819 | |
| 820 | if (levt->features & CLOCK_EVT_FEAT_DUMMY) { |
Jaswinder Singh Rajput | e423e33 | 2009-01-04 16:16:25 +0530 | [diff] [blame] | 821 | pr_warning("APIC timer disabled due to verification failure\n"); |
Yinghai Lu | 2f04fa8 | 2008-08-24 02:01:54 -0700 | [diff] [blame] | 822 | return -1; |
| 823 | } |
| 824 | |
| 825 | return 0; |
| 826 | } |
| 827 | |
Hiroshi Shimamoto | e83a5fd | 2008-01-30 13:32:35 +0100 | [diff] [blame] | 828 | /* |
| 829 | * Setup the boot APIC |
| 830 | * |
| 831 | * Calibrate and verify the result. |
| 832 | */ |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 833 | void __init setup_boot_APIC_clock(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | { |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 835 | /* |
Cyrill Gorcunov | 274cfe5 | 2008-08-16 23:21:53 +0400 | [diff] [blame] | 836 | * The local apic timer can be disabled via the kernel |
| 837 | * commandline or from the CPU detection code. Register the lapic |
| 838 | * timer as a dummy clock event source on SMP systems, so the |
| 839 | * broadcast mechanism is used. On UP systems simply ignore it. |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 840 | */ |
| 841 | if (disable_apic_timer) { |
Cyrill Gorcunov | ba21ebb | 2008-11-10 09:16:41 +0100 | [diff] [blame] | 842 | pr_info("Disabling APIC timer\n"); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 843 | /* No broadcast on UP ! */ |
Thomas Gleixner | 9d09951 | 2008-01-30 13:33:04 +0100 | [diff] [blame] | 844 | if (num_possible_cpus() > 1) { |
| 845 | lapic_clockevent.mult = 1; |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 846 | setup_APIC_timer(); |
Thomas Gleixner | 9d09951 | 2008-01-30 13:33:04 +0100 | [diff] [blame] | 847 | } |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 848 | return; |
| 849 | } |
Thomas Gleixner | 6935d1f | 2007-07-21 17:10:17 +0200 | [diff] [blame] | 850 | |
Cyrill Gorcunov | 89b3b1f | 2008-07-15 21:02:54 +0400 | [diff] [blame] | 851 | if (calibrate_APIC_clock()) { |
Thomas Gleixner | c2b84b3 | 2008-01-30 13:33:04 +0100 | [diff] [blame] | 852 | /* No broadcast on UP ! */ |
| 853 | if (num_possible_cpus() > 1) |
| 854 | setup_APIC_timer(); |
| 855 | return; |
| 856 | } |
| 857 | |
| 858 | /* |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 859 | * If nmi_watchdog is set to IO_APIC, we need the |
| 860 | * PIT/HPET going. Otherwise register lapic as a dummy |
| 861 | * device. |
| 862 | */ |
Don Zickus | 072b198 | 2010-11-12 11:22:24 -0500 | [diff] [blame] | 863 | lapic_clockevent.features &= ~CLOCK_EVT_FEAT_DUMMY; |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 864 | |
Cyrill Gorcunov | 274cfe5 | 2008-08-16 23:21:53 +0400 | [diff] [blame] | 865 | /* Setup the lapic or request the broadcast */ |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 866 | setup_APIC_timer(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 869 | void __cpuinit setup_secondary_APIC_clock(void) |
| 870 | { |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 871 | setup_APIC_timer(); |
| 872 | } |
| 873 | |
| 874 | /* |
| 875 | * The guts of the apic timer interrupt |
| 876 | */ |
| 877 | static void local_apic_timer_interrupt(void) |
| 878 | { |
| 879 | int cpu = smp_processor_id(); |
| 880 | struct clock_event_device *evt = &per_cpu(lapic_events, cpu); |
| 881 | |
| 882 | /* |
| 883 | * Normally we should not be here till LAPIC has been initialized but |
| 884 | * in some cases like kdump, its possible that there is a pending LAPIC |
| 885 | * timer interrupt from previous kernel's context and is delivered in |
| 886 | * new kernel the moment interrupts are enabled. |
| 887 | * |
| 888 | * Interrupts are enabled early and LAPIC is setup much later, hence |
| 889 | * its possible that when we get here evt->event_handler is NULL. |
| 890 | * Check for event_handler being NULL and discard the interrupt as |
| 891 | * spurious. |
| 892 | */ |
| 893 | if (!evt->event_handler) { |
Cyrill Gorcunov | ba21ebb | 2008-11-10 09:16:41 +0100 | [diff] [blame] | 894 | pr_warning("Spurious LAPIC timer interrupt on cpu %d\n", cpu); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 895 | /* Switch it off */ |
| 896 | lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, evt); |
| 897 | return; |
| 898 | } |
| 899 | |
| 900 | /* |
| 901 | * the NMI deadlock-detector uses this. |
| 902 | */ |
Hiroshi Shimamoto | 915b0d0 | 2008-12-08 19:19:26 -0800 | [diff] [blame] | 903 | inc_irq_stat(apic_timer_irqs); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 904 | |
| 905 | evt->event_handler(evt); |
| 906 | } |
| 907 | |
| 908 | /* |
| 909 | * Local APIC timer interrupt. This is the most natural way for doing |
| 910 | * local interrupts, but local timer interrupts can be emulated by |
| 911 | * broadcast interrupts too. [in case the hw doesn't support APIC timers] |
| 912 | * |
| 913 | * [ if a single-CPU system runs an SMP kernel then we call the local |
| 914 | * interrupt as well. Thus we cannot inline the local irq ... ] |
| 915 | */ |
Frederic Weisbecker | bcbc4f2 | 2008-12-09 23:54:20 +0100 | [diff] [blame] | 916 | void __irq_entry smp_apic_timer_interrupt(struct pt_regs *regs) |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 917 | { |
| 918 | struct pt_regs *old_regs = set_irq_regs(regs); |
| 919 | |
| 920 | /* |
| 921 | * NOTE! We'd better ACK the irq immediately, |
| 922 | * because timer handling can be slow. |
Seiji Aguchi | eddc0e9 | 2013-06-20 11:45:17 -0400 | [diff] [blame] | 923 | * |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 924 | * update_process_times() expects us to have done irq_enter(). |
| 925 | * Besides, if we don't timer interrupts ignore the global |
| 926 | * interrupt lock, which is the WrongThing (tm) to do. |
| 927 | */ |
Seiji Aguchi | eddc0e9 | 2013-06-20 11:45:17 -0400 | [diff] [blame] | 928 | entering_ack_irq(); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 929 | local_apic_timer_interrupt(); |
Seiji Aguchi | eddc0e9 | 2013-06-20 11:45:17 -0400 | [diff] [blame] | 930 | exiting_irq(); |
Cyrill Gorcunov | 274cfe5 | 2008-08-16 23:21:53 +0400 | [diff] [blame] | 931 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 932 | set_irq_regs(old_regs); |
| 933 | } |
| 934 | |
Seiji Aguchi | cf910e8 | 2013-06-20 11:46:53 -0400 | [diff] [blame] | 935 | void __irq_entry smp_trace_apic_timer_interrupt(struct pt_regs *regs) |
| 936 | { |
| 937 | struct pt_regs *old_regs = set_irq_regs(regs); |
| 938 | |
| 939 | /* |
| 940 | * NOTE! We'd better ACK the irq immediately, |
| 941 | * because timer handling can be slow. |
| 942 | * |
| 943 | * update_process_times() expects us to have done irq_enter(). |
| 944 | * Besides, if we don't timer interrupts ignore the global |
| 945 | * interrupt lock, which is the WrongThing (tm) to do. |
| 946 | */ |
| 947 | entering_ack_irq(); |
| 948 | trace_local_timer_entry(LOCAL_TIMER_VECTOR); |
| 949 | local_apic_timer_interrupt(); |
| 950 | trace_local_timer_exit(LOCAL_TIMER_VECTOR); |
| 951 | exiting_irq(); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 952 | |
| 953 | set_irq_regs(old_regs); |
| 954 | } |
| 955 | |
| 956 | int setup_profiling_timer(unsigned int multiplier) |
| 957 | { |
| 958 | return -EINVAL; |
| 959 | } |
| 960 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 961 | /* |
| 962 | * Local APIC start and shutdown |
| 963 | */ |
| 964 | |
| 965 | /** |
| 966 | * clear_local_APIC - shutdown the local APIC |
| 967 | * |
| 968 | * This is called, when a CPU is disabled and before rebooting, so the state of |
| 969 | * the local APIC has no dangling leftovers. Also used to cleanout any BIOS |
| 970 | * leftovers during boot. |
| 971 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | void clear_local_APIC(void) |
| 973 | { |
Chuck Ebbert | 2584a82 | 2008-05-20 18:18:12 -0400 | [diff] [blame] | 974 | int maxlvt; |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 975 | u32 v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | |
Andi Kleen | d343289 | 2008-01-30 13:33:17 +0100 | [diff] [blame] | 977 | /* APIC hasn't been mapped yet */ |
Suresh Siddha | fc1edaf | 2009-04-20 13:02:27 -0700 | [diff] [blame] | 978 | if (!x2apic_mode && !apic_phys) |
Andi Kleen | d343289 | 2008-01-30 13:33:17 +0100 | [diff] [blame] | 979 | return; |
| 980 | |
| 981 | maxlvt = lapic_get_maxlvt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | /* |
Siddha, Suresh B | 704fc59 | 2006-06-26 13:59:53 +0200 | [diff] [blame] | 983 | * Masking an LVT entry can trigger a local APIC error |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | * if the vector is zero. Mask LVTERR first to prevent this. |
| 985 | */ |
| 986 | if (maxlvt >= 3) { |
| 987 | v = ERROR_APIC_VECTOR; /* any non-zero vector will do */ |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 988 | apic_write(APIC_LVTERR, v | APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | } |
| 990 | /* |
| 991 | * Careful: we have to set masks only first to deassert |
| 992 | * any level-triggered sources. |
| 993 | */ |
| 994 | v = apic_read(APIC_LVTT); |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 995 | apic_write(APIC_LVTT, v | APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | v = apic_read(APIC_LVT0); |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 997 | apic_write(APIC_LVT0, v | APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | v = apic_read(APIC_LVT1); |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 999 | apic_write(APIC_LVT1, v | APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | if (maxlvt >= 4) { |
| 1001 | v = apic_read(APIC_LVTPC); |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 1002 | apic_write(APIC_LVTPC, v | APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
Cyrill Gorcunov | 6764014 | 2008-08-16 23:21:50 +0400 | [diff] [blame] | 1005 | /* lets not touch this if we didn't frob it */ |
Andi Kleen | 4efc067 | 2009-04-28 19:07:31 +0200 | [diff] [blame] | 1006 | #ifdef CONFIG_X86_THERMAL_VECTOR |
Cyrill Gorcunov | 6764014 | 2008-08-16 23:21:50 +0400 | [diff] [blame] | 1007 | if (maxlvt >= 5) { |
| 1008 | v = apic_read(APIC_LVTTHMR); |
| 1009 | apic_write(APIC_LVTTHMR, v | APIC_LVT_MASKED); |
| 1010 | } |
| 1011 | #endif |
Andi Kleen | 5ca8681 | 2009-02-12 13:49:37 +0100 | [diff] [blame] | 1012 | #ifdef CONFIG_X86_MCE_INTEL |
| 1013 | if (maxlvt >= 6) { |
| 1014 | v = apic_read(APIC_LVTCMCI); |
| 1015 | if (!(v & APIC_LVT_MASKED)) |
| 1016 | apic_write(APIC_LVTCMCI, v | APIC_LVT_MASKED); |
| 1017 | } |
| 1018 | #endif |
| 1019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | /* |
| 1021 | * Clean APIC state for other OSs: |
| 1022 | */ |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 1023 | apic_write(APIC_LVTT, APIC_LVT_MASKED); |
| 1024 | apic_write(APIC_LVT0, APIC_LVT_MASKED); |
| 1025 | apic_write(APIC_LVT1, APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | if (maxlvt >= 3) |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 1027 | apic_write(APIC_LVTERR, APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | if (maxlvt >= 4) |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 1029 | apic_write(APIC_LVTPC, APIC_LVT_MASKED); |
Cyrill Gorcunov | 6764014 | 2008-08-16 23:21:50 +0400 | [diff] [blame] | 1030 | |
| 1031 | /* Integrated APIC (!82489DX) ? */ |
| 1032 | if (lapic_is_integrated()) { |
| 1033 | if (maxlvt > 3) |
| 1034 | /* Clear ESR due to Pentium errata 3AP and 11AP */ |
| 1035 | apic_write(APIC_ESR, 0); |
| 1036 | apic_read(APIC_ESR); |
| 1037 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1040 | /** |
| 1041 | * disable_local_APIC - clear and disable the local APIC |
| 1042 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | void disable_local_APIC(void) |
| 1044 | { |
| 1045 | unsigned int value; |
| 1046 | |
Jan Beulich | 4a13ad0 | 2009-01-14 12:28:51 +0000 | [diff] [blame] | 1047 | /* APIC hasn't been mapped yet */ |
Yinghai Lu | fd19dce | 2010-07-15 00:00:59 -0700 | [diff] [blame] | 1048 | if (!x2apic_mode && !apic_phys) |
Jan Beulich | 4a13ad0 | 2009-01-14 12:28:51 +0000 | [diff] [blame] | 1049 | return; |
| 1050 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | clear_local_APIC(); |
| 1052 | |
| 1053 | /* |
| 1054 | * Disable APIC (implies clearing of registers |
| 1055 | * for 82489DX!). |
| 1056 | */ |
| 1057 | value = apic_read(APIC_SPIV); |
| 1058 | value &= ~APIC_SPIV_APIC_ENABLED; |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 1059 | apic_write(APIC_SPIV, value); |
Cyrill Gorcunov | 990b183 | 2008-08-18 20:45:51 +0400 | [diff] [blame] | 1060 | |
| 1061 | #ifdef CONFIG_X86_32 |
| 1062 | /* |
| 1063 | * When LAPIC was disabled by the BIOS and enabled by the kernel, |
| 1064 | * restore the disabled state. |
| 1065 | */ |
| 1066 | if (enabled_via_apicbase) { |
| 1067 | unsigned int l, h; |
| 1068 | |
| 1069 | rdmsr(MSR_IA32_APICBASE, l, h); |
| 1070 | l &= ~MSR_IA32_APICBASE_ENABLE; |
| 1071 | wrmsr(MSR_IA32_APICBASE, l, h); |
| 1072 | } |
| 1073 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | } |
| 1075 | |
Cyrill Gorcunov | fe4024d | 2008-08-18 20:45:52 +0400 | [diff] [blame] | 1076 | /* |
| 1077 | * If Linux enabled the LAPIC against the BIOS default disable it down before |
| 1078 | * re-entering the BIOS on shutdown. Otherwise the BIOS may get confused and |
| 1079 | * not power-off. Additionally clear all LVT entries before disable_local_APIC |
| 1080 | * for the case where Linux didn't enable the LAPIC. |
| 1081 | */ |
Hiroshi Shimamoto | 9b7711f | 2007-10-19 18:21:11 -0700 | [diff] [blame] | 1082 | void lapic_shutdown(void) |
| 1083 | { |
| 1084 | unsigned long flags; |
| 1085 | |
Cyrill Gorcunov | 8312136 | 2009-09-15 11:12:30 +0400 | [diff] [blame] | 1086 | if (!cpu_has_apic && !apic_from_smp_config()) |
Hiroshi Shimamoto | 9b7711f | 2007-10-19 18:21:11 -0700 | [diff] [blame] | 1087 | return; |
| 1088 | |
| 1089 | local_irq_save(flags); |
| 1090 | |
Cyrill Gorcunov | fe4024d | 2008-08-18 20:45:52 +0400 | [diff] [blame] | 1091 | #ifdef CONFIG_X86_32 |
| 1092 | if (!enabled_via_apicbase) |
| 1093 | clear_local_APIC(); |
| 1094 | else |
| 1095 | #endif |
| 1096 | disable_local_APIC(); |
| 1097 | |
Hiroshi Shimamoto | 9b7711f | 2007-10-19 18:21:11 -0700 | [diff] [blame] | 1098 | |
| 1099 | local_irq_restore(flags); |
| 1100 | } |
| 1101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | /* |
| 1103 | * This is to verify that we're looking at a real local APIC. |
| 1104 | * Check these against your board if the CPUs aren't getting |
| 1105 | * started for no apparent reason. |
| 1106 | */ |
| 1107 | int __init verify_local_APIC(void) |
| 1108 | { |
| 1109 | unsigned int reg0, reg1; |
| 1110 | |
| 1111 | /* |
| 1112 | * The version register is read-only in a real APIC. |
| 1113 | */ |
| 1114 | reg0 = apic_read(APIC_LVR); |
| 1115 | apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg0); |
| 1116 | apic_write(APIC_LVR, reg0 ^ APIC_LVR_MASK); |
| 1117 | reg1 = apic_read(APIC_LVR); |
| 1118 | apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg1); |
| 1119 | |
| 1120 | /* |
| 1121 | * The two version reads above should print the same |
| 1122 | * numbers. If the second one is different, then we |
| 1123 | * poke at a non-APIC. |
| 1124 | */ |
| 1125 | if (reg1 != reg0) |
| 1126 | return 0; |
| 1127 | |
| 1128 | /* |
| 1129 | * Check if the version looks reasonably. |
| 1130 | */ |
| 1131 | reg1 = GET_APIC_VERSION(reg0); |
| 1132 | if (reg1 == 0x00 || reg1 == 0xff) |
| 1133 | return 0; |
Thomas Gleixner | 37e650c | 2008-01-30 13:30:14 +0100 | [diff] [blame] | 1134 | reg1 = lapic_get_maxlvt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | if (reg1 < 0x02 || reg1 == 0xff) |
| 1136 | return 0; |
| 1137 | |
| 1138 | /* |
| 1139 | * The ID register is read/write in a real APIC. |
| 1140 | */ |
Suresh Siddha | 2d7a66d | 2008-07-11 14:24:19 -0700 | [diff] [blame] | 1141 | reg0 = apic_read(APIC_ID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | apic_printk(APIC_DEBUG, "Getting ID: %x\n", reg0); |
Ingo Molnar | 5b81272 | 2009-01-28 14:59:17 +0100 | [diff] [blame] | 1143 | apic_write(APIC_ID, reg0 ^ apic->apic_id_mask); |
Suresh Siddha | 2d7a66d | 2008-07-11 14:24:19 -0700 | [diff] [blame] | 1144 | reg1 = apic_read(APIC_ID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | apic_printk(APIC_DEBUG, "Getting ID: %x\n", reg1); |
| 1146 | apic_write(APIC_ID, reg0); |
Ingo Molnar | 5b81272 | 2009-01-28 14:59:17 +0100 | [diff] [blame] | 1147 | if (reg1 != (reg0 ^ apic->apic_id_mask)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | return 0; |
| 1149 | |
| 1150 | /* |
| 1151 | * The next two are just to see if we have sane values. |
| 1152 | * They're only really relevant if we're in Virtual Wire |
| 1153 | * compatibility mode, but most boxes are anymore. |
| 1154 | */ |
| 1155 | reg0 = apic_read(APIC_LVT0); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1156 | apic_printk(APIC_DEBUG, "Getting LVT0: %x\n", reg0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | reg1 = apic_read(APIC_LVT1); |
| 1158 | apic_printk(APIC_DEBUG, "Getting LVT1: %x\n", reg1); |
| 1159 | |
| 1160 | return 1; |
| 1161 | } |
| 1162 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1163 | /** |
| 1164 | * sync_Arb_IDs - synchronize APIC bus arbitration IDs |
| 1165 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | void __init sync_Arb_IDs(void) |
| 1167 | { |
Cyrill Gorcunov | 296cb95 | 2008-08-15 13:51:23 +0200 | [diff] [blame] | 1168 | /* |
| 1169 | * Unsupported on P4 - see Intel Dev. Manual Vol. 3, Ch. 8.6.1 And not |
| 1170 | * needed on AMD. |
| 1171 | */ |
| 1172 | if (modern_apic() || boot_cpu_data.x86_vendor == X86_VENDOR_AMD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | return; |
| 1174 | |
| 1175 | /* |
| 1176 | * Wait for idle. |
| 1177 | */ |
| 1178 | apic_wait_icr_idle(); |
| 1179 | |
| 1180 | apic_printk(APIC_DEBUG, "Synchronizing Arb IDs.\n"); |
Cyrill Gorcunov | 6f6da97 | 2008-08-15 23:05:19 +0400 | [diff] [blame] | 1181 | apic_write(APIC_ICR, APIC_DEST_ALLINC | |
| 1182 | APIC_INT_LEVELTRIG | APIC_DM_INIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | /* |
| 1186 | * An initial setup of the virtual wire mode. |
| 1187 | */ |
| 1188 | void __init init_bsp_APIC(void) |
| 1189 | { |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 1190 | unsigned int value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | |
| 1192 | /* |
| 1193 | * Don't do the setup now if we have a SMP BIOS as the |
| 1194 | * through-I/O-APIC virtual wire mode might be active. |
| 1195 | */ |
| 1196 | if (smp_found_config || !cpu_has_apic) |
| 1197 | return; |
| 1198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | /* |
| 1200 | * Do not trust the local APIC being empty at bootup. |
| 1201 | */ |
| 1202 | clear_local_APIC(); |
| 1203 | |
| 1204 | /* |
| 1205 | * Enable APIC. |
| 1206 | */ |
| 1207 | value = apic_read(APIC_SPIV); |
| 1208 | value &= ~APIC_VECTOR_MASK; |
| 1209 | value |= APIC_SPIV_APIC_ENABLED; |
Cyrill Gorcunov | 638c041 | 2008-08-15 23:05:18 +0400 | [diff] [blame] | 1210 | |
| 1211 | #ifdef CONFIG_X86_32 |
| 1212 | /* This bit is reserved on P4/Xeon and should be cleared */ |
| 1213 | if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) && |
| 1214 | (boot_cpu_data.x86 == 15)) |
| 1215 | value &= ~APIC_SPIV_FOCUS_DISABLED; |
| 1216 | else |
| 1217 | #endif |
| 1218 | value |= APIC_SPIV_FOCUS_DISABLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | value |= SPURIOUS_APIC_VECTOR; |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 1220 | apic_write(APIC_SPIV, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | |
| 1222 | /* |
| 1223 | * Set up the virtual wire mode. |
| 1224 | */ |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 1225 | apic_write(APIC_LVT0, APIC_DM_EXTINT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | value = APIC_DM_NMI; |
Cyrill Gorcunov | 638c041 | 2008-08-15 23:05:18 +0400 | [diff] [blame] | 1227 | if (!lapic_is_integrated()) /* 82489DX */ |
| 1228 | value |= APIC_LVT_LEVEL_TRIGGER; |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 1229 | apic_write(APIC_LVT1, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | } |
| 1231 | |
Cyrill Gorcunov | c43da2f | 2008-08-18 20:45:54 +0400 | [diff] [blame] | 1232 | static void __cpuinit lapic_setup_esr(void) |
| 1233 | { |
Cyrill Gorcunov | 9df08f1 | 2008-09-14 11:55:37 +0400 | [diff] [blame] | 1234 | unsigned int oldvalue, value, maxlvt; |
Cyrill Gorcunov | c43da2f | 2008-08-18 20:45:54 +0400 | [diff] [blame] | 1235 | |
Cyrill Gorcunov | 9df08f1 | 2008-09-14 11:55:37 +0400 | [diff] [blame] | 1236 | if (!lapic_is_integrated()) { |
Cyrill Gorcunov | ba21ebb | 2008-11-10 09:16:41 +0100 | [diff] [blame] | 1237 | pr_info("No ESR for 82489DX.\n"); |
Cyrill Gorcunov | 9df08f1 | 2008-09-14 11:55:37 +0400 | [diff] [blame] | 1238 | return; |
Cyrill Gorcunov | c43da2f | 2008-08-18 20:45:54 +0400 | [diff] [blame] | 1239 | } |
Cyrill Gorcunov | 9df08f1 | 2008-09-14 11:55:37 +0400 | [diff] [blame] | 1240 | |
Ingo Molnar | 08125d3 | 2009-01-28 05:08:44 +0100 | [diff] [blame] | 1241 | if (apic->disable_esr) { |
Cyrill Gorcunov | 9df08f1 | 2008-09-14 11:55:37 +0400 | [diff] [blame] | 1242 | /* |
| 1243 | * Something untraceable is creating bad interrupts on |
| 1244 | * secondary quads ... for the moment, just leave the |
| 1245 | * ESR disabled - we can't do anything useful with the |
| 1246 | * errors anyway - mbligh |
| 1247 | */ |
Cyrill Gorcunov | ba21ebb | 2008-11-10 09:16:41 +0100 | [diff] [blame] | 1248 | pr_info("Leaving ESR disabled.\n"); |
Cyrill Gorcunov | 9df08f1 | 2008-09-14 11:55:37 +0400 | [diff] [blame] | 1249 | return; |
| 1250 | } |
| 1251 | |
| 1252 | maxlvt = lapic_get_maxlvt(); |
| 1253 | if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */ |
| 1254 | apic_write(APIC_ESR, 0); |
| 1255 | oldvalue = apic_read(APIC_ESR); |
| 1256 | |
| 1257 | /* enables sending errors */ |
| 1258 | value = ERROR_APIC_VECTOR; |
| 1259 | apic_write(APIC_LVTERR, value); |
| 1260 | |
| 1261 | /* |
| 1262 | * spec says clear errors after enabling vector. |
| 1263 | */ |
| 1264 | if (maxlvt > 3) |
| 1265 | apic_write(APIC_ESR, 0); |
| 1266 | value = apic_read(APIC_ESR); |
| 1267 | if (value != oldvalue) |
| 1268 | apic_printk(APIC_VERBOSE, "ESR value before enabling " |
| 1269 | "vector: 0x%08x after: 0x%08x\n", |
| 1270 | oldvalue, value); |
Cyrill Gorcunov | c43da2f | 2008-08-18 20:45:54 +0400 | [diff] [blame] | 1271 | } |
| 1272 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1273 | /** |
| 1274 | * setup_local_APIC - setup the local APIC |
Tejun Heo | 0aa002f | 2010-12-09 11:47:21 +0100 | [diff] [blame] | 1275 | * |
| 1276 | * Used to setup local APIC while initializing BSP or bringin up APs. |
| 1277 | * Always called with preemption disabled. |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1278 | */ |
| 1279 | void __cpuinit setup_local_APIC(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | { |
Tejun Heo | 0aa002f | 2010-12-09 11:47:21 +0100 | [diff] [blame] | 1281 | int cpu = smp_processor_id(); |
Kerstin Jonsson | 8c3ba8d | 2010-05-24 12:13:15 -0700 | [diff] [blame] | 1282 | unsigned int value, queued; |
| 1283 | int i, j, acked = 0; |
| 1284 | unsigned long long tsc = 0, ntsc; |
| 1285 | long long max_loops = cpu_khz; |
| 1286 | |
| 1287 | if (cpu_has_tsc) |
| 1288 | rdtscll(tsc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | |
Jan Beulich | f118263 | 2009-01-14 12:27:35 +0000 | [diff] [blame] | 1290 | if (disable_apic) { |
Henrik Kretzschmar | 7167d08 | 2011-02-22 15:38:05 +0100 | [diff] [blame] | 1291 | disable_ioapic_support(); |
Jan Beulich | f118263 | 2009-01-14 12:27:35 +0000 | [diff] [blame] | 1292 | return; |
| 1293 | } |
| 1294 | |
Cyrill Gorcunov | 89c38c2 | 2008-08-24 02:01:43 -0700 | [diff] [blame] | 1295 | #ifdef CONFIG_X86_32 |
| 1296 | /* Pound the ESR really hard over the head with a big hammer - mbligh */ |
Ingo Molnar | 08125d3 | 2009-01-28 05:08:44 +0100 | [diff] [blame] | 1297 | if (lapic_is_integrated() && apic->disable_esr) { |
Cyrill Gorcunov | 89c38c2 | 2008-08-24 02:01:43 -0700 | [diff] [blame] | 1298 | apic_write(APIC_ESR, 0); |
| 1299 | apic_write(APIC_ESR, 0); |
| 1300 | apic_write(APIC_ESR, 0); |
| 1301 | apic_write(APIC_ESR, 0); |
| 1302 | } |
| 1303 | #endif |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 1304 | perf_events_lapic_init(); |
Cyrill Gorcunov | 89c38c2 | 2008-08-24 02:01:43 -0700 | [diff] [blame] | 1305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | /* |
| 1307 | * Double-check whether this APIC is really registered. |
| 1308 | * This is meaningless in clustered apic mode, so we skip it. |
| 1309 | */ |
Daniel Walker | c2777f9 | 2009-09-12 10:40:20 -0700 | [diff] [blame] | 1310 | BUG_ON(!apic->apic_id_registered()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | |
| 1312 | /* |
| 1313 | * Intel recommends to set DFR, LDR and TPR before enabling |
| 1314 | * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel |
| 1315 | * document number 292116). So here it goes... |
| 1316 | */ |
Ingo Molnar | a5c4329 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 1317 | apic->init_apic_ldr(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | |
Tejun Heo | 6f802c4 | 2011-01-23 14:37:31 +0100 | [diff] [blame] | 1319 | #ifdef CONFIG_X86_32 |
| 1320 | /* |
Tejun Heo | acb8bc0 | 2011-01-23 14:37:33 +0100 | [diff] [blame] | 1321 | * APIC LDR is initialized. If logical_apicid mapping was |
| 1322 | * initialized during get_smp_config(), make sure it matches the |
| 1323 | * actual value. |
Tejun Heo | 6f802c4 | 2011-01-23 14:37:31 +0100 | [diff] [blame] | 1324 | */ |
Tejun Heo | acb8bc0 | 2011-01-23 14:37:33 +0100 | [diff] [blame] | 1325 | i = early_per_cpu(x86_cpu_to_logical_apicid, cpu); |
| 1326 | WARN_ON(i != BAD_APICID && i != logical_smp_processor_id()); |
| 1327 | /* always use the value from LDR */ |
Tejun Heo | 6f802c4 | 2011-01-23 14:37:31 +0100 | [diff] [blame] | 1328 | early_per_cpu(x86_cpu_to_logical_apicid, cpu) = |
| 1329 | logical_smp_processor_id(); |
Tejun Heo | c4b90c1 | 2011-05-02 14:18:52 +0200 | [diff] [blame] | 1330 | |
| 1331 | /* |
| 1332 | * Some NUMA implementations (NUMAQ) don't initialize apicid to |
| 1333 | * node mapping during NUMA init. Now that logical apicid is |
| 1334 | * guaranteed to be known, give it another chance. This is already |
| 1335 | * a bit too late - percpu allocation has already happened without |
| 1336 | * proper NUMA affinity. |
| 1337 | */ |
Tejun Heo | 84914ed0 | 2011-05-02 14:18:52 +0200 | [diff] [blame] | 1338 | if (apic->x86_32_numa_cpu_node) |
| 1339 | set_apicid_to_node(early_per_cpu(x86_cpu_to_apicid, cpu), |
| 1340 | apic->x86_32_numa_cpu_node(cpu)); |
Tejun Heo | 6f802c4 | 2011-01-23 14:37:31 +0100 | [diff] [blame] | 1341 | #endif |
| 1342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | /* |
| 1344 | * Set Task Priority to 'accept all'. We never change this |
| 1345 | * later on. |
| 1346 | */ |
| 1347 | value = apic_read(APIC_TASKPRI); |
| 1348 | value &= ~APIC_TPRI_MASK; |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 1349 | apic_write(APIC_TASKPRI, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | |
| 1351 | /* |
Vivek Goyal | da7ed9f | 2006-03-25 16:31:16 +0100 | [diff] [blame] | 1352 | * After a crash, we no longer service the interrupts and a pending |
| 1353 | * interrupt from previous kernel might still have ISR bit set. |
| 1354 | * |
| 1355 | * Most probably by now CPU has serviced that pending interrupt and |
| 1356 | * it might not have done the ack_APIC_irq() because it thought, |
| 1357 | * interrupt came from i8259 as ExtInt. LAPIC did not get EOI so it |
| 1358 | * does not clear the ISR bit and cpu thinks it has already serivced |
| 1359 | * the interrupt. Hence a vector might get locked. It was noticed |
| 1360 | * for timer irq (vector 0x31). Issue an extra EOI to clear ISR. |
| 1361 | */ |
Kerstin Jonsson | 8c3ba8d | 2010-05-24 12:13:15 -0700 | [diff] [blame] | 1362 | do { |
| 1363 | queued = 0; |
| 1364 | for (i = APIC_ISR_NR - 1; i >= 0; i--) |
| 1365 | queued |= apic_read(APIC_IRR + i*0x10); |
| 1366 | |
| 1367 | for (i = APIC_ISR_NR - 1; i >= 0; i--) { |
| 1368 | value = apic_read(APIC_ISR + i*0x10); |
| 1369 | for (j = 31; j >= 0; j--) { |
| 1370 | if (value & (1<<j)) { |
| 1371 | ack_APIC_irq(); |
| 1372 | acked++; |
| 1373 | } |
| 1374 | } |
Vivek Goyal | da7ed9f | 2006-03-25 16:31:16 +0100 | [diff] [blame] | 1375 | } |
Kerstin Jonsson | 8c3ba8d | 2010-05-24 12:13:15 -0700 | [diff] [blame] | 1376 | if (acked > 256) { |
| 1377 | printk(KERN_ERR "LAPIC pending interrupts after %d EOI\n", |
| 1378 | acked); |
| 1379 | break; |
| 1380 | } |
Shai Fultheim | 42fa425 | 2012-04-20 01:12:32 +0300 | [diff] [blame] | 1381 | if (queued) { |
| 1382 | if (cpu_has_tsc) { |
| 1383 | rdtscll(ntsc); |
| 1384 | max_loops = (cpu_khz << 10) - (ntsc - tsc); |
| 1385 | } else |
| 1386 | max_loops--; |
| 1387 | } |
Kerstin Jonsson | 8c3ba8d | 2010-05-24 12:13:15 -0700 | [diff] [blame] | 1388 | } while (queued && max_loops > 0); |
| 1389 | WARN_ON(max_loops <= 0); |
Vivek Goyal | da7ed9f | 2006-03-25 16:31:16 +0100 | [diff] [blame] | 1390 | |
| 1391 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | * Now that we are all set up, enable the APIC |
| 1393 | */ |
| 1394 | value = apic_read(APIC_SPIV); |
| 1395 | value &= ~APIC_VECTOR_MASK; |
| 1396 | /* |
| 1397 | * Enable APIC |
| 1398 | */ |
| 1399 | value |= APIC_SPIV_APIC_ENABLED; |
| 1400 | |
Cyrill Gorcunov | 89c38c2 | 2008-08-24 02:01:43 -0700 | [diff] [blame] | 1401 | #ifdef CONFIG_X86_32 |
| 1402 | /* |
| 1403 | * Some unknown Intel IO/APIC (or APIC) errata is biting us with |
| 1404 | * certain networking cards. If high frequency interrupts are |
| 1405 | * happening on a particular IOAPIC pin, plus the IOAPIC routing |
| 1406 | * entry is masked/unmasked at a high rate as well then sooner or |
| 1407 | * later IOAPIC line gets 'stuck', no more interrupts are received |
| 1408 | * from the device. If focus CPU is disabled then the hang goes |
| 1409 | * away, oh well :-( |
| 1410 | * |
| 1411 | * [ This bug can be reproduced easily with a level-triggered |
| 1412 | * PCI Ne2000 networking cards and PII/PIII processors, dual |
| 1413 | * BX chipset. ] |
| 1414 | */ |
| 1415 | /* |
| 1416 | * Actually disabling the focus CPU check just makes the hang less |
| 1417 | * frequent as it makes the interrupt distributon model be more |
| 1418 | * like LRU than MRU (the short-term load is more even across CPUs). |
| 1419 | * See also the comment in end_level_ioapic_irq(). --macro |
| 1420 | */ |
| 1421 | |
| 1422 | /* |
| 1423 | * - enable focus processor (bit==0) |
| 1424 | * - 64bit mode always use processor focus |
| 1425 | * so no need to set it |
| 1426 | */ |
| 1427 | value &= ~APIC_SPIV_FOCUS_DISABLED; |
| 1428 | #endif |
Andi Kleen | 3f14c74 | 2006-09-26 10:52:29 +0200 | [diff] [blame] | 1429 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | /* |
| 1431 | * Set spurious IRQ vector |
| 1432 | */ |
| 1433 | value |= SPURIOUS_APIC_VECTOR; |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 1434 | apic_write(APIC_SPIV, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | |
| 1436 | /* |
| 1437 | * Set up LVT0, LVT1: |
| 1438 | * |
| 1439 | * set up through-local-APIC on the BP's LINT0. This is not |
| 1440 | * strictly necessary in pure symmetric-IO mode, but sometimes |
| 1441 | * we delegate interrupts to the 8259A. |
| 1442 | */ |
| 1443 | /* |
| 1444 | * TODO: set up through-local-APIC from through-I/O-APIC? --macro |
| 1445 | */ |
| 1446 | value = apic_read(APIC_LVT0) & APIC_LVT_MASKED; |
Tejun Heo | 0aa002f | 2010-12-09 11:47:21 +0100 | [diff] [blame] | 1447 | if (!cpu && (pic_mode || !value)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | value = APIC_DM_EXTINT; |
Tejun Heo | 0aa002f | 2010-12-09 11:47:21 +0100 | [diff] [blame] | 1449 | apic_printk(APIC_VERBOSE, "enabled ExtINT on CPU#%d\n", cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | } else { |
| 1451 | value = APIC_DM_EXTINT | APIC_LVT_MASKED; |
Tejun Heo | 0aa002f | 2010-12-09 11:47:21 +0100 | [diff] [blame] | 1452 | apic_printk(APIC_VERBOSE, "masked ExtINT on CPU#%d\n", cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | } |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 1454 | apic_write(APIC_LVT0, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | |
| 1456 | /* |
| 1457 | * only the BP should see the LINT1 NMI signal, obviously. |
| 1458 | */ |
Tejun Heo | 0aa002f | 2010-12-09 11:47:21 +0100 | [diff] [blame] | 1459 | if (!cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | value = APIC_DM_NMI; |
| 1461 | else |
| 1462 | value = APIC_DM_NMI | APIC_LVT_MASKED; |
Cyrill Gorcunov | 89c38c2 | 2008-08-24 02:01:43 -0700 | [diff] [blame] | 1463 | if (!lapic_is_integrated()) /* 82489DX */ |
| 1464 | value |= APIC_LVT_LEVEL_TRIGGER; |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 1465 | apic_write(APIC_LVT1, value); |
Cyrill Gorcunov | 89c38c2 | 2008-08-24 02:01:43 -0700 | [diff] [blame] | 1466 | |
Andi Kleen | be71b85 | 2009-02-12 13:49:38 +0100 | [diff] [blame] | 1467 | #ifdef CONFIG_X86_MCE_INTEL |
| 1468 | /* Recheck CMCI information after local APIC is up on CPU #0 */ |
Tejun Heo | 0aa002f | 2010-12-09 11:47:21 +0100 | [diff] [blame] | 1469 | if (!cpu) |
Andi Kleen | be71b85 | 2009-02-12 13:49:38 +0100 | [diff] [blame] | 1470 | cmci_recheck(); |
| 1471 | #endif |
Andi Kleen | 739f33b | 2008-01-30 13:30:40 +0100 | [diff] [blame] | 1472 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | |
Andi Kleen | 739f33b | 2008-01-30 13:30:40 +0100 | [diff] [blame] | 1474 | void __cpuinit end_local_APIC_setup(void) |
| 1475 | { |
| 1476 | lapic_setup_esr(); |
Cyrill Gorcunov | fa6b95f | 2008-08-18 20:45:58 +0400 | [diff] [blame] | 1477 | |
| 1478 | #ifdef CONFIG_X86_32 |
Cyrill Gorcunov | 1b4ee4e | 2008-08-18 23:12:33 +0400 | [diff] [blame] | 1479 | { |
| 1480 | unsigned int value; |
| 1481 | /* Disable the local apic timer */ |
| 1482 | value = apic_read(APIC_LVTT); |
| 1483 | value |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR); |
| 1484 | apic_write(APIC_LVTT, value); |
| 1485 | } |
Cyrill Gorcunov | fa6b95f | 2008-08-18 20:45:58 +0400 | [diff] [blame] | 1486 | #endif |
| 1487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | apic_pm_activate(); |
Jan Beulich | 2fb270f | 2011-02-09 08:21:02 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | void __init bsp_end_local_APIC_setup(void) |
| 1492 | { |
| 1493 | end_local_APIC_setup(); |
Kenji Kaneshige | 7f7fbf4 | 2010-11-30 22:22:28 -0800 | [diff] [blame] | 1494 | |
| 1495 | /* |
| 1496 | * Now that local APIC setup is completed for BP, configure the fault |
| 1497 | * handling for interrupt remapping. |
| 1498 | */ |
Joerg Roedel | 70733e0 | 2012-09-26 12:44:33 +0200 | [diff] [blame] | 1499 | irq_remap_enable_fault_handling(); |
Kenji Kaneshige | 7f7fbf4 | 2010-11-30 22:22:28 -0800 | [diff] [blame] | 1500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
Yinghai Lu | 06cd9a7 | 2009-02-16 17:29:58 -0800 | [diff] [blame] | 1503 | #ifdef CONFIG_X86_X2APIC |
Yinghai Lu | fb209bd | 2011-12-21 17:45:17 -0800 | [diff] [blame] | 1504 | /* |
| 1505 | * Need to disable xapic and x2apic at the same time and then enable xapic mode |
| 1506 | */ |
| 1507 | static inline void __disable_x2apic(u64 msr) |
| 1508 | { |
| 1509 | wrmsrl(MSR_IA32_APICBASE, |
| 1510 | msr & ~(X2APIC_ENABLE | XAPIC_ENABLE)); |
| 1511 | wrmsrl(MSR_IA32_APICBASE, msr & ~X2APIC_ENABLE); |
| 1512 | } |
| 1513 | |
Yinghai Lu | a31bc32 | 2011-12-23 11:01:43 -0800 | [diff] [blame] | 1514 | static __init void disable_x2apic(void) |
Yinghai Lu | fb209bd | 2011-12-21 17:45:17 -0800 | [diff] [blame] | 1515 | { |
| 1516 | u64 msr; |
| 1517 | |
| 1518 | if (!cpu_has_x2apic) |
| 1519 | return; |
| 1520 | |
| 1521 | rdmsrl(MSR_IA32_APICBASE, msr); |
| 1522 | if (msr & X2APIC_ENABLE) { |
| 1523 | u32 x2apic_id = read_apic_id(); |
| 1524 | |
| 1525 | if (x2apic_id >= 255) |
| 1526 | panic("Cannot disable x2apic, id: %08x\n", x2apic_id); |
| 1527 | |
| 1528 | pr_info("Disabling x2apic\n"); |
| 1529 | __disable_x2apic(msr); |
| 1530 | |
Yinghai Lu | a31bc32 | 2011-12-23 11:01:43 -0800 | [diff] [blame] | 1531 | if (nox2apic) { |
| 1532 | clear_cpu_cap(&cpu_data(0), X86_FEATURE_X2APIC); |
| 1533 | setup_clear_cpu_cap(X86_FEATURE_X2APIC); |
| 1534 | } |
| 1535 | |
Yinghai Lu | fb209bd | 2011-12-21 17:45:17 -0800 | [diff] [blame] | 1536 | x2apic_disabled = 1; |
| 1537 | x2apic_mode = 0; |
| 1538 | |
| 1539 | register_lapic_address(mp_lapic_addr); |
| 1540 | } |
| 1541 | } |
| 1542 | |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 1543 | void check_x2apic(void) |
| 1544 | { |
Suresh Siddha | ef1f87a | 2009-02-21 14:23:21 -0800 | [diff] [blame] | 1545 | if (x2apic_enabled()) { |
Cyrill Gorcunov | ba21ebb | 2008-11-10 09:16:41 +0100 | [diff] [blame] | 1546 | pr_info("x2apic enabled by BIOS, switching to x2apic ops\n"); |
Suresh Siddha | fc1edaf | 2009-04-20 13:02:27 -0700 | [diff] [blame] | 1547 | x2apic_preenabled = x2apic_mode = 1; |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | void enable_x2apic(void) |
| 1552 | { |
Yinghai Lu | fb209bd | 2011-12-21 17:45:17 -0800 | [diff] [blame] | 1553 | u64 msr; |
| 1554 | |
| 1555 | rdmsrl(MSR_IA32_APICBASE, msr); |
| 1556 | if (x2apic_disabled) { |
| 1557 | __disable_x2apic(msr); |
| 1558 | return; |
| 1559 | } |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 1560 | |
Suresh Siddha | fc1edaf | 2009-04-20 13:02:27 -0700 | [diff] [blame] | 1561 | if (!x2apic_mode) |
Yinghai Lu | 06cd9a7 | 2009-02-16 17:29:58 -0800 | [diff] [blame] | 1562 | return; |
| 1563 | |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 1564 | if (!(msr & X2APIC_ENABLE)) { |
Mike Travis | 450b1e8 | 2009-12-11 08:08:50 -0800 | [diff] [blame] | 1565 | printk_once(KERN_INFO "Enabling x2apic\n"); |
Yinghai Lu | fb209bd | 2011-12-21 17:45:17 -0800 | [diff] [blame] | 1566 | wrmsrl(MSR_IA32_APICBASE, msr | X2APIC_ENABLE); |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 1567 | } |
| 1568 | } |
Weidong Han | 9375823 | 2009-04-17 16:42:14 +0800 | [diff] [blame] | 1569 | #endif /* CONFIG_X86_X2APIC */ |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 1570 | |
Gleb Natapov | ce69a78 | 2009-07-20 15:24:17 +0300 | [diff] [blame] | 1571 | int __init enable_IR(void) |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 1572 | { |
Suresh Siddha | d3f1381 | 2011-08-23 17:05:25 -0700 | [diff] [blame] | 1573 | #ifdef CONFIG_IRQ_REMAP |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 1574 | if (!irq_remapping_supported()) { |
Weidong Han | 9375823 | 2009-04-17 16:42:14 +0800 | [diff] [blame] | 1575 | pr_debug("intr-remapping not supported\n"); |
Suresh Siddha | 41750d3 | 2011-08-23 17:05:18 -0700 | [diff] [blame] | 1576 | return -1; |
Weidong Han | 9375823 | 2009-04-17 16:42:14 +0800 | [diff] [blame] | 1577 | } |
| 1578 | |
Weidong Han | 9375823 | 2009-04-17 16:42:14 +0800 | [diff] [blame] | 1579 | if (!x2apic_preenabled && skip_ioapic_setup) { |
| 1580 | pr_info("Skipped enabling intr-remap because of skipping " |
| 1581 | "io-apic setup\n"); |
Suresh Siddha | 41750d3 | 2011-08-23 17:05:18 -0700 | [diff] [blame] | 1582 | return -1; |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 1583 | } |
| 1584 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 1585 | return irq_remapping_enable(); |
Gleb Natapov | ce69a78 | 2009-07-20 15:24:17 +0300 | [diff] [blame] | 1586 | #endif |
Suresh Siddha | 41750d3 | 2011-08-23 17:05:18 -0700 | [diff] [blame] | 1587 | return -1; |
Gleb Natapov | ce69a78 | 2009-07-20 15:24:17 +0300 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | void __init enable_IR_x2apic(void) |
| 1591 | { |
| 1592 | unsigned long flags; |
Gleb Natapov | ce69a78 | 2009-07-20 15:24:17 +0300 | [diff] [blame] | 1593 | int ret, x2apic_enabled = 0; |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 1594 | int hardware_init_ret; |
Yinghai Lu | b7f42ab | 2009-08-17 11:19:40 -0700 | [diff] [blame] | 1595 | |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 1596 | /* Make sure irq_remap_ops are initialized */ |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 1597 | setup_irq_remapping_ops(); |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 1598 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 1599 | hardware_init_ret = irq_remapping_prepare(); |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 1600 | if (hardware_init_ret && !x2apic_supported()) |
Yinghai Lu | e670761 | 2009-11-21 00:23:37 -0800 | [diff] [blame] | 1601 | return; |
Gleb Natapov | ce69a78 | 2009-07-20 15:24:17 +0300 | [diff] [blame] | 1602 | |
Suresh Siddha | 31dce14 | 2011-05-18 16:31:33 -0700 | [diff] [blame] | 1603 | ret = save_ioapic_entries(); |
Cyrill Gorcunov | 5ffa4eb | 2008-09-18 23:37:57 +0400 | [diff] [blame] | 1604 | if (ret) { |
Cyrill Gorcunov | ba21ebb | 2008-11-10 09:16:41 +0100 | [diff] [blame] | 1605 | pr_info("Saving IO-APIC state failed: %d\n", ret); |
Yinghai Lu | fb209bd | 2011-12-21 17:45:17 -0800 | [diff] [blame] | 1606 | return; |
Cyrill Gorcunov | 5ffa4eb | 2008-09-18 23:37:57 +0400 | [diff] [blame] | 1607 | } |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 1608 | |
Suresh Siddha | 05c3dc2 | 2009-03-16 17:05:03 -0700 | [diff] [blame] | 1609 | local_irq_save(flags); |
Jacob Pan | b81bb37 | 2009-11-09 11:27:04 -0800 | [diff] [blame] | 1610 | legacy_pic->mask_all(); |
Suresh Siddha | 31dce14 | 2011-05-18 16:31:33 -0700 | [diff] [blame] | 1611 | mask_ioapic_entries(); |
Suresh Siddha | 05c3dc2 | 2009-03-16 17:05:03 -0700 | [diff] [blame] | 1612 | |
Yinghai Lu | a31bc32 | 2011-12-23 11:01:43 -0800 | [diff] [blame] | 1613 | if (x2apic_preenabled && nox2apic) |
| 1614 | disable_x2apic(); |
| 1615 | |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 1616 | if (hardware_init_ret) |
Suresh Siddha | 41750d3 | 2011-08-23 17:05:18 -0700 | [diff] [blame] | 1617 | ret = -1; |
Yinghai Lu | b7f42ab | 2009-08-17 11:19:40 -0700 | [diff] [blame] | 1618 | else |
| 1619 | ret = enable_IR(); |
| 1620 | |
Yinghai Lu | fb209bd | 2011-12-21 17:45:17 -0800 | [diff] [blame] | 1621 | if (!x2apic_supported()) |
Yinghai Lu | a31bc32 | 2011-12-23 11:01:43 -0800 | [diff] [blame] | 1622 | goto skip_x2apic; |
Yinghai Lu | fb209bd | 2011-12-21 17:45:17 -0800 | [diff] [blame] | 1623 | |
Suresh Siddha | 41750d3 | 2011-08-23 17:05:18 -0700 | [diff] [blame] | 1624 | if (ret < 0) { |
Gleb Natapov | ce69a78 | 2009-07-20 15:24:17 +0300 | [diff] [blame] | 1625 | /* IR is required if there is APIC ID > 255 even when running |
| 1626 | * under KVM |
| 1627 | */ |
Sheng Yang | 2904ed8 | 2010-12-21 14:18:48 +0800 | [diff] [blame] | 1628 | if (max_physical_apicid > 255 || |
Yinghai Lu | fb209bd | 2011-12-21 17:45:17 -0800 | [diff] [blame] | 1629 | !hypervisor_x2apic_available()) { |
| 1630 | if (x2apic_preenabled) |
| 1631 | disable_x2apic(); |
Yinghai Lu | a31bc32 | 2011-12-23 11:01:43 -0800 | [diff] [blame] | 1632 | goto skip_x2apic; |
Yinghai Lu | fb209bd | 2011-12-21 17:45:17 -0800 | [diff] [blame] | 1633 | } |
Gleb Natapov | ce69a78 | 2009-07-20 15:24:17 +0300 | [diff] [blame] | 1634 | /* |
| 1635 | * without IR all CPUs can be addressed by IOAPIC/MSI |
| 1636 | * only in physical mode |
| 1637 | */ |
| 1638 | x2apic_force_phys(); |
| 1639 | } |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 1640 | |
Yinghai Lu | fb209bd | 2011-12-21 17:45:17 -0800 | [diff] [blame] | 1641 | if (ret == IRQ_REMAP_XAPIC_MODE) { |
| 1642 | pr_info("x2apic not enabled, IRQ remapping is in xapic mode\n"); |
Yinghai Lu | a31bc32 | 2011-12-23 11:01:43 -0800 | [diff] [blame] | 1643 | goto skip_x2apic; |
Yinghai Lu | fb209bd | 2011-12-21 17:45:17 -0800 | [diff] [blame] | 1644 | } |
Suresh Siddha | 41750d3 | 2011-08-23 17:05:18 -0700 | [diff] [blame] | 1645 | |
Gleb Natapov | ce69a78 | 2009-07-20 15:24:17 +0300 | [diff] [blame] | 1646 | x2apic_enabled = 1; |
Weidong Han | 9375823 | 2009-04-17 16:42:14 +0800 | [diff] [blame] | 1647 | |
Suresh Siddha | fc1edaf | 2009-04-20 13:02:27 -0700 | [diff] [blame] | 1648 | if (x2apic_supported() && !x2apic_mode) { |
| 1649 | x2apic_mode = 1; |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 1650 | enable_x2apic(); |
Weidong Han | 9375823 | 2009-04-17 16:42:14 +0800 | [diff] [blame] | 1651 | pr_info("Enabled x2apic\n"); |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 1652 | } |
Cyrill Gorcunov | 5ffa4eb | 2008-09-18 23:37:57 +0400 | [diff] [blame] | 1653 | |
Yinghai Lu | a31bc32 | 2011-12-23 11:01:43 -0800 | [diff] [blame] | 1654 | skip_x2apic: |
Suresh Siddha | 41750d3 | 2011-08-23 17:05:18 -0700 | [diff] [blame] | 1655 | if (ret < 0) /* IR enabling failed */ |
Suresh Siddha | 31dce14 | 2011-05-18 16:31:33 -0700 | [diff] [blame] | 1656 | restore_ioapic_entries(); |
Jacob Pan | b81bb37 | 2009-11-09 11:27:04 -0800 | [diff] [blame] | 1657 | legacy_pic->restore_mask(); |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 1658 | local_irq_restore(flags); |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 1659 | } |
Weidong Han | 9375823 | 2009-04-17 16:42:14 +0800 | [diff] [blame] | 1660 | |
Yinghai Lu | be7a656 | 2008-08-24 02:01:51 -0700 | [diff] [blame] | 1661 | #ifdef CONFIG_X86_64 |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1662 | /* |
| 1663 | * Detect and enable local APICs on non-SMP boards. |
| 1664 | * Original code written by Keir Fraser. |
| 1665 | * On AMD64 we trust the BIOS - if it says no APIC it is likely |
| 1666 | * not correctly set up (usually the APIC timer won't work etc.) |
| 1667 | */ |
| 1668 | static int __init detect_init_APIC(void) |
| 1669 | { |
| 1670 | if (!cpu_has_apic) { |
Cyrill Gorcunov | ba21ebb | 2008-11-10 09:16:41 +0100 | [diff] [blame] | 1671 | pr_info("No local APIC present\n"); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1672 | return -1; |
| 1673 | } |
| 1674 | |
| 1675 | mp_lapic_addr = APIC_DEFAULT_PHYS_BASE; |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1676 | return 0; |
| 1677 | } |
Yinghai Lu | be7a656 | 2008-08-24 02:01:51 -0700 | [diff] [blame] | 1678 | #else |
Thomas Gleixner | 5a7ae78 | 2010-10-19 10:46:28 -0700 | [diff] [blame] | 1679 | |
Henrik Kretzschmar | 25874a2 | 2011-03-11 08:02:36 +0100 | [diff] [blame] | 1680 | static int __init apic_verify(void) |
Thomas Gleixner | 5a7ae78 | 2010-10-19 10:46:28 -0700 | [diff] [blame] | 1681 | { |
| 1682 | u32 features, h, l; |
| 1683 | |
| 1684 | /* |
| 1685 | * The APIC feature bit should now be enabled |
| 1686 | * in `cpuid' |
| 1687 | */ |
| 1688 | features = cpuid_edx(1); |
| 1689 | if (!(features & (1 << X86_FEATURE_APIC))) { |
| 1690 | pr_warning("Could not enable APIC!\n"); |
| 1691 | return -1; |
| 1692 | } |
| 1693 | set_cpu_cap(&boot_cpu_data, X86_FEATURE_APIC); |
| 1694 | mp_lapic_addr = APIC_DEFAULT_PHYS_BASE; |
| 1695 | |
| 1696 | /* The BIOS may have set up the APIC at some other address */ |
Bryan O'Donoghue | cbf2829 | 2012-04-18 17:37:39 +0100 | [diff] [blame] | 1697 | if (boot_cpu_data.x86 >= 6) { |
| 1698 | rdmsr(MSR_IA32_APICBASE, l, h); |
| 1699 | if (l & MSR_IA32_APICBASE_ENABLE) |
| 1700 | mp_lapic_addr = l & MSR_IA32_APICBASE_BASE; |
| 1701 | } |
Thomas Gleixner | 5a7ae78 | 2010-10-19 10:46:28 -0700 | [diff] [blame] | 1702 | |
| 1703 | pr_info("Found and enabled local APIC!\n"); |
| 1704 | return 0; |
| 1705 | } |
| 1706 | |
Henrik Kretzschmar | 25874a2 | 2011-03-11 08:02:36 +0100 | [diff] [blame] | 1707 | int __init apic_force_enable(unsigned long addr) |
Thomas Gleixner | 5a7ae78 | 2010-10-19 10:46:28 -0700 | [diff] [blame] | 1708 | { |
| 1709 | u32 h, l; |
| 1710 | |
| 1711 | if (disable_apic) |
| 1712 | return -1; |
| 1713 | |
| 1714 | /* |
| 1715 | * Some BIOSes disable the local APIC in the APIC_BASE |
| 1716 | * MSR. This can only be done in software for Intel P6 or later |
| 1717 | * and AMD K7 (Model > 1) or later. |
| 1718 | */ |
Bryan O'Donoghue | cbf2829 | 2012-04-18 17:37:39 +0100 | [diff] [blame] | 1719 | if (boot_cpu_data.x86 >= 6) { |
| 1720 | rdmsr(MSR_IA32_APICBASE, l, h); |
| 1721 | if (!(l & MSR_IA32_APICBASE_ENABLE)) { |
| 1722 | pr_info("Local APIC disabled by BIOS -- reenabling.\n"); |
| 1723 | l &= ~MSR_IA32_APICBASE_BASE; |
| 1724 | l |= MSR_IA32_APICBASE_ENABLE | addr; |
| 1725 | wrmsr(MSR_IA32_APICBASE, l, h); |
| 1726 | enabled_via_apicbase = 1; |
| 1727 | } |
Thomas Gleixner | 5a7ae78 | 2010-10-19 10:46:28 -0700 | [diff] [blame] | 1728 | } |
| 1729 | return apic_verify(); |
| 1730 | } |
| 1731 | |
Yinghai Lu | be7a656 | 2008-08-24 02:01:51 -0700 | [diff] [blame] | 1732 | /* |
| 1733 | * Detect and initialize APIC |
| 1734 | */ |
| 1735 | static int __init detect_init_APIC(void) |
| 1736 | { |
Yinghai Lu | be7a656 | 2008-08-24 02:01:51 -0700 | [diff] [blame] | 1737 | /* Disabled by kernel option? */ |
| 1738 | if (disable_apic) |
| 1739 | return -1; |
| 1740 | |
| 1741 | switch (boot_cpu_data.x86_vendor) { |
| 1742 | case X86_VENDOR_AMD: |
| 1743 | if ((boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model > 1) || |
Borislav Petkov | 8587706 | 2009-02-03 16:24:22 +0100 | [diff] [blame] | 1744 | (boot_cpu_data.x86 >= 15)) |
Yinghai Lu | be7a656 | 2008-08-24 02:01:51 -0700 | [diff] [blame] | 1745 | break; |
| 1746 | goto no_apic; |
| 1747 | case X86_VENDOR_INTEL: |
| 1748 | if (boot_cpu_data.x86 == 6 || boot_cpu_data.x86 == 15 || |
| 1749 | (boot_cpu_data.x86 == 5 && cpu_has_apic)) |
| 1750 | break; |
| 1751 | goto no_apic; |
| 1752 | default: |
| 1753 | goto no_apic; |
| 1754 | } |
| 1755 | |
| 1756 | if (!cpu_has_apic) { |
| 1757 | /* |
| 1758 | * Over-ride BIOS and try to enable the local APIC only if |
| 1759 | * "lapic" specified. |
| 1760 | */ |
| 1761 | if (!force_enable_local_apic) { |
Cyrill Gorcunov | ba21ebb | 2008-11-10 09:16:41 +0100 | [diff] [blame] | 1762 | pr_info("Local APIC disabled by BIOS -- " |
| 1763 | "you can enable it with \"lapic\"\n"); |
Yinghai Lu | be7a656 | 2008-08-24 02:01:51 -0700 | [diff] [blame] | 1764 | return -1; |
| 1765 | } |
Thomas Gleixner | a906fda | 2011-02-25 16:09:31 +0100 | [diff] [blame] | 1766 | if (apic_force_enable(APIC_DEFAULT_PHYS_BASE)) |
Thomas Gleixner | 5a7ae78 | 2010-10-19 10:46:28 -0700 | [diff] [blame] | 1767 | return -1; |
| 1768 | } else { |
| 1769 | if (apic_verify()) |
| 1770 | return -1; |
Yinghai Lu | be7a656 | 2008-08-24 02:01:51 -0700 | [diff] [blame] | 1771 | } |
Yinghai Lu | be7a656 | 2008-08-24 02:01:51 -0700 | [diff] [blame] | 1772 | |
| 1773 | apic_pm_activate(); |
| 1774 | |
| 1775 | return 0; |
| 1776 | |
| 1777 | no_apic: |
Cyrill Gorcunov | ba21ebb | 2008-11-10 09:16:41 +0100 | [diff] [blame] | 1778 | pr_info("No local APIC present or hardware disabled\n"); |
Yinghai Lu | be7a656 | 2008-08-24 02:01:51 -0700 | [diff] [blame] | 1779 | return -1; |
| 1780 | } |
| 1781 | #endif |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1782 | |
| 1783 | /** |
| 1784 | * init_apic_mappings - initialize APIC mappings |
| 1785 | */ |
| 1786 | void __init init_apic_mappings(void) |
| 1787 | { |
Yinghai Lu | 4401da6 | 2009-05-02 10:40:57 -0700 | [diff] [blame] | 1788 | unsigned int new_apicid; |
| 1789 | |
Suresh Siddha | fc1edaf | 2009-04-20 13:02:27 -0700 | [diff] [blame] | 1790 | if (x2apic_mode) { |
Yinghai Lu | 4c9961d | 2008-07-11 18:44:16 -0700 | [diff] [blame] | 1791 | boot_cpu_physical_apicid = read_apic_id(); |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 1792 | return; |
| 1793 | } |
| 1794 | |
Yinghai Lu | 4797f6b | 2009-05-02 10:40:57 -0700 | [diff] [blame] | 1795 | /* If no local APIC can be found return early */ |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1796 | if (!smp_found_config && detect_init_APIC()) { |
Yinghai Lu | 4797f6b | 2009-05-02 10:40:57 -0700 | [diff] [blame] | 1797 | /* lets NOP'ify apic operations */ |
Cyrill Gorcunov | cec6be6 | 2009-05-11 17:41:40 +0400 | [diff] [blame] | 1798 | pr_info("APIC: disable apic facility\n"); |
| 1799 | apic_disable(); |
Yinghai Lu | 4797f6b | 2009-05-02 10:40:57 -0700 | [diff] [blame] | 1800 | } else { |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1801 | apic_phys = mp_lapic_addr; |
| 1802 | |
Yinghai Lu | 4797f6b | 2009-05-02 10:40:57 -0700 | [diff] [blame] | 1803 | /* |
| 1804 | * acpi lapic path already maps that address in |
| 1805 | * acpi_register_lapic_address() |
| 1806 | */ |
Eric W. Biederman | 5989cd6 | 2010-08-04 13:30:27 -0700 | [diff] [blame] | 1807 | if (!acpi_lapic && !smp_found_config) |
Yinghai Lu | 326a2e6 | 2010-12-07 00:55:38 -0800 | [diff] [blame] | 1808 | register_lapic_address(apic_phys); |
Cyrill Gorcunov | cec6be6 | 2009-05-11 17:41:40 +0400 | [diff] [blame] | 1809 | } |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1810 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1811 | /* |
| 1812 | * Fetch the APIC ID of the BSP in case we have a |
| 1813 | * default configuration (or the MP table is broken). |
| 1814 | */ |
Yinghai Lu | 4401da6 | 2009-05-02 10:40:57 -0700 | [diff] [blame] | 1815 | new_apicid = read_apic_id(); |
| 1816 | if (boot_cpu_physical_apicid != new_apicid) { |
| 1817 | boot_cpu_physical_apicid = new_apicid; |
Cyrill Gorcunov | 103428e | 2009-06-07 16:48:40 +0400 | [diff] [blame] | 1818 | /* |
| 1819 | * yeah -- we lie about apic_version |
| 1820 | * in case if apic was disabled via boot option |
| 1821 | * but it's not a problem for SMP compiled kernel |
| 1822 | * since smp_sanity_check is prepared for such a case |
| 1823 | * and disable smp mode |
| 1824 | */ |
Yinghai Lu | 4401da6 | 2009-05-02 10:40:57 -0700 | [diff] [blame] | 1825 | apic_version[new_apicid] = |
| 1826 | GET_APIC_VERSION(apic_read(APIC_LVR)); |
Cyrill Gorcunov | 08306ce | 2009-04-12 20:47:41 +0400 | [diff] [blame] | 1827 | } |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1828 | } |
| 1829 | |
Yinghai Lu | c0104d3 | 2010-12-07 00:55:17 -0800 | [diff] [blame] | 1830 | void __init register_lapic_address(unsigned long address) |
| 1831 | { |
| 1832 | mp_lapic_addr = address; |
| 1833 | |
Yinghai Lu | 0450193 | 2010-12-07 00:55:56 -0800 | [diff] [blame] | 1834 | if (!x2apic_mode) { |
| 1835 | set_fixmap_nocache(FIX_APIC_BASE, address); |
| 1836 | apic_printk(APIC_VERBOSE, "mapped APIC to %16lx (%16lx)\n", |
| 1837 | APIC_BASE, mp_lapic_addr); |
| 1838 | } |
Yinghai Lu | c0104d3 | 2010-12-07 00:55:17 -0800 | [diff] [blame] | 1839 | if (boot_cpu_physical_apicid == -1U) { |
| 1840 | boot_cpu_physical_apicid = read_apic_id(); |
| 1841 | apic_version[boot_cpu_physical_apicid] = |
| 1842 | GET_APIC_VERSION(apic_read(APIC_LVR)); |
| 1843 | } |
| 1844 | } |
| 1845 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1846 | /* |
| 1847 | * This initializes the IO-APIC and APIC hardware if this is |
| 1848 | * a UP kernel. |
| 1849 | */ |
Yinghai Lu | 56d91f1 | 2010-12-16 19:09:24 -0800 | [diff] [blame] | 1850 | int apic_version[MAX_LOCAL_APIC]; |
Cyrill Gorcunov | 1b313f4 | 2008-08-18 20:45:57 +0400 | [diff] [blame] | 1851 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1852 | int __init APIC_init_uniprocessor(void) |
| 1853 | { |
| 1854 | if (disable_apic) { |
Cyrill Gorcunov | ba21ebb | 2008-11-10 09:16:41 +0100 | [diff] [blame] | 1855 | pr_info("Apic disabled\n"); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1856 | return -1; |
| 1857 | } |
Jan Beulich | f118263 | 2009-01-14 12:27:35 +0000 | [diff] [blame] | 1858 | #ifdef CONFIG_X86_64 |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1859 | if (!cpu_has_apic) { |
| 1860 | disable_apic = 1; |
Cyrill Gorcunov | ba21ebb | 2008-11-10 09:16:41 +0100 | [diff] [blame] | 1861 | pr_info("Apic disabled by BIOS\n"); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1862 | return -1; |
| 1863 | } |
Yinghai Lu | fa2bd35 | 2008-08-24 02:01:50 -0700 | [diff] [blame] | 1864 | #else |
| 1865 | if (!smp_found_config && !cpu_has_apic) |
| 1866 | return -1; |
| 1867 | |
| 1868 | /* |
| 1869 | * Complain if the BIOS pretends there is one. |
| 1870 | */ |
| 1871 | if (!cpu_has_apic && |
| 1872 | APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) { |
Cyrill Gorcunov | ba21ebb | 2008-11-10 09:16:41 +0100 | [diff] [blame] | 1873 | pr_err("BIOS bug, local APIC 0x%x not detected!...\n", |
| 1874 | boot_cpu_physical_apicid); |
Yinghai Lu | fa2bd35 | 2008-08-24 02:01:50 -0700 | [diff] [blame] | 1875 | return -1; |
| 1876 | } |
| 1877 | #endif |
| 1878 | |
Ingo Molnar | 72ce016 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 1879 | default_setup_apic_routing(); |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 1880 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1881 | verify_local_APIC(); |
Glauber Costa | b584176 | 2008-05-28 13:38:28 -0300 | [diff] [blame] | 1882 | connect_bsp_APIC(); |
| 1883 | |
Yinghai Lu | fa2bd35 | 2008-08-24 02:01:50 -0700 | [diff] [blame] | 1884 | #ifdef CONFIG_X86_64 |
Glauber de Oliveira Costa | c70dcb7 | 2008-03-19 14:25:58 -0300 | [diff] [blame] | 1885 | apic_write(APIC_ID, SET_APIC_ID(boot_cpu_physical_apicid)); |
Yinghai Lu | fa2bd35 | 2008-08-24 02:01:50 -0700 | [diff] [blame] | 1886 | #else |
| 1887 | /* |
| 1888 | * Hack: In case of kdump, after a crash, kernel might be booting |
| 1889 | * on a cpu with non-zero lapic id. But boot_cpu_physical_apicid |
| 1890 | * might be zero if read from MP tables. Get it from LAPIC. |
| 1891 | */ |
| 1892 | # ifdef CONFIG_CRASH_DUMP |
| 1893 | boot_cpu_physical_apicid = read_apic_id(); |
| 1894 | # endif |
| 1895 | #endif |
| 1896 | physid_set_mask_of_physid(boot_cpu_physical_apicid, &phys_cpu_present_map); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1897 | setup_local_APIC(); |
| 1898 | |
Yinghai Lu | 88d0f55 | 2009-02-14 23:57:28 -0800 | [diff] [blame] | 1899 | #ifdef CONFIG_X86_IO_APIC |
Andi Kleen | 739f33b | 2008-01-30 13:30:40 +0100 | [diff] [blame] | 1900 | /* |
| 1901 | * Now enable IO-APICs, actually call clear_IO_APIC |
Yinghai Lu | 98c061b | 2009-02-16 00:00:50 -0800 | [diff] [blame] | 1902 | * We need clear_IO_APIC before enabling error vector |
Andi Kleen | 739f33b | 2008-01-30 13:30:40 +0100 | [diff] [blame] | 1903 | */ |
| 1904 | if (!skip_ioapic_setup && nr_ioapics) |
| 1905 | enable_IO_APIC(); |
Yinghai Lu | fa2bd35 | 2008-08-24 02:01:50 -0700 | [diff] [blame] | 1906 | #endif |
Andi Kleen | 739f33b | 2008-01-30 13:30:40 +0100 | [diff] [blame] | 1907 | |
Jan Beulich | 2fb270f | 2011-02-09 08:21:02 +0000 | [diff] [blame] | 1908 | bsp_end_local_APIC_setup(); |
Andi Kleen | 739f33b | 2008-01-30 13:30:40 +0100 | [diff] [blame] | 1909 | |
Yinghai Lu | fa2bd35 | 2008-08-24 02:01:50 -0700 | [diff] [blame] | 1910 | #ifdef CONFIG_X86_IO_APIC |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1911 | if (smp_found_config && !skip_ioapic_setup && nr_ioapics) |
| 1912 | setup_IO_APIC(); |
Yinghai Lu | 98c061b | 2009-02-16 00:00:50 -0800 | [diff] [blame] | 1913 | else { |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1914 | nr_ioapics = 0; |
Yinghai Lu | 98c061b | 2009-02-16 00:00:50 -0800 | [diff] [blame] | 1915 | } |
Yinghai Lu | fa2bd35 | 2008-08-24 02:01:50 -0700 | [diff] [blame] | 1916 | #endif |
| 1917 | |
Thomas Gleixner | 736deca | 2009-08-19 12:35:53 +0200 | [diff] [blame] | 1918 | x86_init.timers.setup_percpu_clockev(); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1919 | return 0; |
| 1920 | } |
| 1921 | |
| 1922 | /* |
| 1923 | * Local APIC interrupts |
| 1924 | */ |
| 1925 | |
| 1926 | /* |
| 1927 | * This interrupt should _never_ happen with our APIC/SMP architecture |
| 1928 | */ |
Seiji Aguchi | eddc0e9 | 2013-06-20 11:45:17 -0400 | [diff] [blame] | 1929 | static inline void __smp_spurious_interrupt(void) |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1930 | { |
Yinghai Lu | dc1528d | 2008-08-24 02:01:53 -0700 | [diff] [blame] | 1931 | u32 v; |
| 1932 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1933 | /* |
| 1934 | * Check if this really is a spurious interrupt and ACK it |
| 1935 | * if it is a vectored one. Just in case... |
| 1936 | * Spurious interrupts should not be ACKed. |
| 1937 | */ |
| 1938 | v = apic_read(APIC_ISR + ((SPURIOUS_APIC_VECTOR & ~0x1f) >> 1)); |
| 1939 | if (v & (1 << (SPURIOUS_APIC_VECTOR & 0x1f))) |
| 1940 | ack_APIC_irq(); |
| 1941 | |
Hiroshi Shimamoto | 915b0d0 | 2008-12-08 19:19:26 -0800 | [diff] [blame] | 1942 | inc_irq_stat(irq_spurious_count); |
| 1943 | |
Yinghai Lu | dc1528d | 2008-08-24 02:01:53 -0700 | [diff] [blame] | 1944 | /* see sw-dev-man vol 3, chapter 7.4.13.5 */ |
Cyrill Gorcunov | ba21ebb | 2008-11-10 09:16:41 +0100 | [diff] [blame] | 1945 | pr_info("spurious APIC interrupt on CPU#%d, " |
| 1946 | "should never happen.\n", smp_processor_id()); |
Seiji Aguchi | eddc0e9 | 2013-06-20 11:45:17 -0400 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | void smp_spurious_interrupt(struct pt_regs *regs) |
| 1950 | { |
| 1951 | entering_irq(); |
| 1952 | __smp_spurious_interrupt(); |
| 1953 | exiting_irq(); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1954 | } |
| 1955 | |
Seiji Aguchi | cf910e8 | 2013-06-20 11:46:53 -0400 | [diff] [blame] | 1956 | void smp_trace_spurious_interrupt(struct pt_regs *regs) |
| 1957 | { |
| 1958 | entering_irq(); |
| 1959 | trace_spurious_apic_entry(SPURIOUS_APIC_VECTOR); |
| 1960 | __smp_spurious_interrupt(); |
| 1961 | trace_spurious_apic_exit(SPURIOUS_APIC_VECTOR); |
| 1962 | exiting_irq(); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | /* |
| 1966 | * This interrupt should never happen with our APIC/SMP architecture |
| 1967 | */ |
Seiji Aguchi | eddc0e9 | 2013-06-20 11:45:17 -0400 | [diff] [blame] | 1968 | static inline void __smp_error_interrupt(struct pt_regs *regs) |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1969 | { |
Youquan Song | 2b398bd | 2011-04-14 14:36:08 +0800 | [diff] [blame] | 1970 | u32 v0, v1; |
| 1971 | u32 i = 0; |
| 1972 | static const char * const error_interrupt_reason[] = { |
| 1973 | "Send CS error", /* APIC Error Bit 0 */ |
| 1974 | "Receive CS error", /* APIC Error Bit 1 */ |
| 1975 | "Send accept error", /* APIC Error Bit 2 */ |
| 1976 | "Receive accept error", /* APIC Error Bit 3 */ |
| 1977 | "Redirectable IPI", /* APIC Error Bit 4 */ |
| 1978 | "Send illegal vector", /* APIC Error Bit 5 */ |
| 1979 | "Received illegal vector", /* APIC Error Bit 6 */ |
| 1980 | "Illegal register address", /* APIC Error Bit 7 */ |
| 1981 | }; |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1982 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1983 | /* First tickle the hardware, only then report what went on. -- REW */ |
Youquan Song | 2b398bd | 2011-04-14 14:36:08 +0800 | [diff] [blame] | 1984 | v0 = apic_read(APIC_ESR); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1985 | apic_write(APIC_ESR, 0); |
| 1986 | v1 = apic_read(APIC_ESR); |
| 1987 | ack_APIC_irq(); |
| 1988 | atomic_inc(&irq_err_count); |
| 1989 | |
Youquan Song | 2b398bd | 2011-04-14 14:36:08 +0800 | [diff] [blame] | 1990 | apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)", |
| 1991 | smp_processor_id(), v0 , v1); |
| 1992 | |
| 1993 | v1 = v1 & 0xff; |
| 1994 | while (v1) { |
| 1995 | if (v1 & 0x1) |
| 1996 | apic_printk(APIC_DEBUG, KERN_CONT " : %s", error_interrupt_reason[i]); |
| 1997 | i++; |
| 1998 | v1 >>= 1; |
Peter Senna Tschudin | 4b8073e | 2012-09-18 18:36:14 +0200 | [diff] [blame] | 1999 | } |
Youquan Song | 2b398bd | 2011-04-14 14:36:08 +0800 | [diff] [blame] | 2000 | |
| 2001 | apic_printk(APIC_DEBUG, KERN_CONT "\n"); |
| 2002 | |
Seiji Aguchi | eddc0e9 | 2013-06-20 11:45:17 -0400 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | void smp_error_interrupt(struct pt_regs *regs) |
| 2006 | { |
| 2007 | entering_irq(); |
| 2008 | __smp_error_interrupt(regs); |
| 2009 | exiting_irq(); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 2010 | } |
| 2011 | |
Seiji Aguchi | cf910e8 | 2013-06-20 11:46:53 -0400 | [diff] [blame] | 2012 | void smp_trace_error_interrupt(struct pt_regs *regs) |
| 2013 | { |
| 2014 | entering_irq(); |
| 2015 | trace_error_apic_entry(ERROR_APIC_VECTOR); |
| 2016 | __smp_error_interrupt(regs); |
| 2017 | trace_error_apic_exit(ERROR_APIC_VECTOR); |
| 2018 | exiting_irq(); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 2019 | } |
| 2020 | |
Glauber Costa | b584176 | 2008-05-28 13:38:28 -0300 | [diff] [blame] | 2021 | /** |
Cyrill Gorcunov | 36c9d67 | 2008-08-18 20:45:53 +0400 | [diff] [blame] | 2022 | * connect_bsp_APIC - attach the APIC to the interrupt system |
| 2023 | */ |
Glauber Costa | b584176 | 2008-05-28 13:38:28 -0300 | [diff] [blame] | 2024 | void __init connect_bsp_APIC(void) |
| 2025 | { |
Cyrill Gorcunov | 36c9d67 | 2008-08-18 20:45:53 +0400 | [diff] [blame] | 2026 | #ifdef CONFIG_X86_32 |
| 2027 | if (pic_mode) { |
| 2028 | /* |
| 2029 | * Do not trust the local APIC being empty at bootup. |
| 2030 | */ |
| 2031 | clear_local_APIC(); |
| 2032 | /* |
| 2033 | * PIC mode, enable APIC mode in the IMCR, i.e. connect BSP's |
| 2034 | * local APIC to INT and NMI lines. |
| 2035 | */ |
| 2036 | apic_printk(APIC_VERBOSE, "leaving PIC mode, " |
| 2037 | "enabling APIC mode.\n"); |
Cyrill Gorcunov | c0eaa45 | 2009-04-12 20:47:40 +0400 | [diff] [blame] | 2038 | imcr_pic_to_apic(); |
Cyrill Gorcunov | 36c9d67 | 2008-08-18 20:45:53 +0400 | [diff] [blame] | 2039 | } |
| 2040 | #endif |
Ingo Molnar | 4904033 | 2009-01-28 12:43:18 +0100 | [diff] [blame] | 2041 | if (apic->enable_apic_mode) |
| 2042 | apic->enable_apic_mode(); |
Glauber Costa | b584176 | 2008-05-28 13:38:28 -0300 | [diff] [blame] | 2043 | } |
| 2044 | |
Cyrill Gorcunov | 274cfe5 | 2008-08-16 23:21:53 +0400 | [diff] [blame] | 2045 | /** |
| 2046 | * disconnect_bsp_APIC - detach the APIC from the interrupt system |
| 2047 | * @virt_wire_setup: indicates, whether virtual wire mode is selected |
| 2048 | * |
| 2049 | * Virtual wire mode is necessary to deliver legacy interrupts even when the |
| 2050 | * APIC is disabled. |
| 2051 | */ |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 2052 | void disconnect_bsp_APIC(int virt_wire_setup) |
| 2053 | { |
Cyrill Gorcunov | 1b4ee4e | 2008-08-18 23:12:33 +0400 | [diff] [blame] | 2054 | unsigned int value; |
| 2055 | |
Cyrill Gorcunov | c177b0b | 2008-08-18 20:45:56 +0400 | [diff] [blame] | 2056 | #ifdef CONFIG_X86_32 |
| 2057 | if (pic_mode) { |
| 2058 | /* |
| 2059 | * Put the board back into PIC mode (has an effect only on |
| 2060 | * certain older boards). Note that APIC interrupts, including |
| 2061 | * IPIs, won't work beyond this point! The only exception are |
| 2062 | * INIT IPIs. |
| 2063 | */ |
| 2064 | apic_printk(APIC_VERBOSE, "disabling APIC mode, " |
| 2065 | "entering PIC mode.\n"); |
Cyrill Gorcunov | c0eaa45 | 2009-04-12 20:47:40 +0400 | [diff] [blame] | 2066 | imcr_apic_to_pic(); |
Cyrill Gorcunov | c177b0b | 2008-08-18 20:45:56 +0400 | [diff] [blame] | 2067 | return; |
| 2068 | } |
| 2069 | #endif |
| 2070 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 2071 | /* Go back to Virtual Wire compatibility mode */ |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 2072 | |
| 2073 | /* For the spurious interrupt use vector F, and enable it */ |
| 2074 | value = apic_read(APIC_SPIV); |
| 2075 | value &= ~APIC_VECTOR_MASK; |
| 2076 | value |= APIC_SPIV_APIC_ENABLED; |
| 2077 | value |= 0xf; |
| 2078 | apic_write(APIC_SPIV, value); |
| 2079 | |
| 2080 | if (!virt_wire_setup) { |
| 2081 | /* |
| 2082 | * For LVT0 make it edge triggered, active high, |
| 2083 | * external and enabled |
| 2084 | */ |
| 2085 | value = apic_read(APIC_LVT0); |
| 2086 | value &= ~(APIC_MODE_MASK | APIC_SEND_PENDING | |
| 2087 | APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR | |
| 2088 | APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED); |
| 2089 | value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING; |
| 2090 | value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_EXTINT); |
| 2091 | apic_write(APIC_LVT0, value); |
| 2092 | } else { |
| 2093 | /* Disable LVT0 */ |
| 2094 | apic_write(APIC_LVT0, APIC_LVT_MASKED); |
| 2095 | } |
| 2096 | |
Cyrill Gorcunov | c177b0b | 2008-08-18 20:45:56 +0400 | [diff] [blame] | 2097 | /* |
| 2098 | * For LVT1 make it edge triggered, active high, |
| 2099 | * nmi and enabled |
| 2100 | */ |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 2101 | value = apic_read(APIC_LVT1); |
| 2102 | value &= ~(APIC_MODE_MASK | APIC_SEND_PENDING | |
| 2103 | APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR | |
| 2104 | APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED); |
| 2105 | value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING; |
| 2106 | value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_NMI); |
| 2107 | apic_write(APIC_LVT1, value); |
| 2108 | } |
| 2109 | |
Alexey Starikovskiy | be8a568 | 2008-03-27 23:56:19 +0300 | [diff] [blame] | 2110 | void __cpuinit generic_processor_info(int apicid, int version) |
| 2111 | { |
Vivek Goyal | 14cb6dc | 2011-07-08 13:19:26 -0400 | [diff] [blame] | 2112 | int cpu, max = nr_cpu_ids; |
| 2113 | bool boot_cpu_detected = physid_isset(boot_cpu_physical_apicid, |
| 2114 | phys_cpu_present_map); |
| 2115 | |
| 2116 | /* |
| 2117 | * If boot cpu has not been detected yet, then only allow upto |
| 2118 | * nr_cpu_ids - 1 processors and keep one slot free for boot cpu |
| 2119 | */ |
| 2120 | if (!boot_cpu_detected && num_processors >= nr_cpu_ids - 1 && |
| 2121 | apicid != boot_cpu_physical_apicid) { |
| 2122 | int thiscpu = max + disabled_cpus - 1; |
| 2123 | |
| 2124 | pr_warning( |
| 2125 | "ACPI: NR_CPUS/possible_cpus limit of %i almost" |
| 2126 | " reached. Keeping one slot for boot cpu." |
| 2127 | " Processor %d/0x%x ignored.\n", max, thiscpu, apicid); |
| 2128 | |
| 2129 | disabled_cpus++; |
| 2130 | return; |
| 2131 | } |
Alexey Starikovskiy | be8a568 | 2008-03-27 23:56:19 +0300 | [diff] [blame] | 2132 | |
Mike Travis | 3b11ce7 | 2008-12-17 15:21:39 -0800 | [diff] [blame] | 2133 | if (num_processors >= nr_cpu_ids) { |
Mike Travis | 3b11ce7 | 2008-12-17 15:21:39 -0800 | [diff] [blame] | 2134 | int thiscpu = max + disabled_cpus; |
| 2135 | |
| 2136 | pr_warning( |
| 2137 | "ACPI: NR_CPUS/possible_cpus limit of %i reached." |
| 2138 | " Processor %d/0x%x ignored.\n", max, thiscpu, apicid); |
| 2139 | |
| 2140 | disabled_cpus++; |
Alexey Starikovskiy | be8a568 | 2008-03-27 23:56:19 +0300 | [diff] [blame] | 2141 | return; |
| 2142 | } |
| 2143 | |
| 2144 | num_processors++; |
Alexey Starikovskiy | be8a568 | 2008-03-27 23:56:19 +0300 | [diff] [blame] | 2145 | if (apicid == boot_cpu_physical_apicid) { |
| 2146 | /* |
| 2147 | * x86_bios_cpu_apicid is required to have processors listed |
| 2148 | * in same order as logical cpu numbers. Hence the first |
| 2149 | * entry is BSP, and so on. |
Yinghai Lu | e5fea86 | 2011-02-08 23:22:17 -0800 | [diff] [blame] | 2150 | * boot_cpu_init() already hold bit 0 in cpu_present_mask |
| 2151 | * for BSP. |
Alexey Starikovskiy | be8a568 | 2008-03-27 23:56:19 +0300 | [diff] [blame] | 2152 | */ |
| 2153 | cpu = 0; |
Yinghai Lu | e5fea86 | 2011-02-08 23:22:17 -0800 | [diff] [blame] | 2154 | } else |
| 2155 | cpu = cpumask_next_zero(-1, cpu_present_mask); |
| 2156 | |
| 2157 | /* |
| 2158 | * Validate version |
| 2159 | */ |
| 2160 | if (version == 0x0) { |
| 2161 | pr_warning("BIOS bug: APIC version is 0 for CPU %d/0x%x, fixing up to 0x10\n", |
| 2162 | cpu, apicid); |
| 2163 | version = 0x10; |
Alexey Starikovskiy | be8a568 | 2008-03-27 23:56:19 +0300 | [diff] [blame] | 2164 | } |
Yinghai Lu | e5fea86 | 2011-02-08 23:22:17 -0800 | [diff] [blame] | 2165 | apic_version[apicid] = version; |
| 2166 | |
| 2167 | if (version != apic_version[boot_cpu_physical_apicid]) { |
| 2168 | pr_warning("BIOS bug: APIC version mismatch, boot CPU: %x, CPU %d: version %x\n", |
| 2169 | apic_version[boot_cpu_physical_apicid], cpu, version); |
| 2170 | } |
| 2171 | |
| 2172 | physid_set(apicid, phys_cpu_present_map); |
Yinghai Lu | e0da336 | 2008-06-08 18:29:22 -0700 | [diff] [blame] | 2173 | if (apicid > max_physical_apicid) |
| 2174 | max_physical_apicid = apicid; |
| 2175 | |
Ingo Molnar | 3e5095d | 2009-01-27 17:07:08 +0100 | [diff] [blame] | 2176 | #if defined(CONFIG_SMP) || defined(CONFIG_X86_64) |
Tejun Heo | f10fcd4 | 2009-01-13 20:41:34 +0900 | [diff] [blame] | 2177 | early_per_cpu(x86_cpu_to_apicid, cpu) = apicid; |
| 2178 | early_per_cpu(x86_bios_cpu_apicid, cpu) = apicid; |
Cyrill Gorcunov | 1b313f4 | 2008-08-18 20:45:57 +0400 | [diff] [blame] | 2179 | #endif |
Tejun Heo | acb8bc0 | 2011-01-23 14:37:33 +0100 | [diff] [blame] | 2180 | #ifdef CONFIG_X86_32 |
| 2181 | early_per_cpu(x86_cpu_to_logical_apicid, cpu) = |
| 2182 | apic->x86_32_early_logical_apicid(cpu); |
| 2183 | #endif |
Mike Travis | 1de88cd | 2008-12-16 17:34:02 -0800 | [diff] [blame] | 2184 | set_cpu_possible(cpu, true); |
| 2185 | set_cpu_present(cpu, true); |
Alexey Starikovskiy | be8a568 | 2008-03-27 23:56:19 +0300 | [diff] [blame] | 2186 | } |
| 2187 | |
Suresh Siddha | 0c81c74 | 2008-07-10 11:16:48 -0700 | [diff] [blame] | 2188 | int hard_smp_processor_id(void) |
| 2189 | { |
| 2190 | return read_apic_id(); |
| 2191 | } |
Ingo Molnar | 1dcdd3d | 2009-01-28 17:55:37 +0100 | [diff] [blame] | 2192 | |
| 2193 | void default_init_apic_ldr(void) |
| 2194 | { |
| 2195 | unsigned long val; |
| 2196 | |
| 2197 | apic_write(APIC_DFR, APIC_DFR_VALUE); |
| 2198 | val = apic_read(APIC_LDR) & ~APIC_LDR_MASK; |
| 2199 | val |= SET_APIC_LOGICAL_ID(1UL << smp_processor_id()); |
| 2200 | apic_write(APIC_LDR, val); |
| 2201 | } |
| 2202 | |
Alexander Gordeev | ff16432 | 2012-06-07 15:15:59 +0200 | [diff] [blame] | 2203 | int default_cpu_mask_to_apicid_and(const struct cpumask *cpumask, |
| 2204 | const struct cpumask *andmask, |
| 2205 | unsigned int *apicid) |
Alexander Gordeev | 6398268 | 2012-06-05 13:23:44 +0200 | [diff] [blame] | 2206 | { |
Alexander Gordeev | ea3807e | 2012-06-14 09:49:55 +0200 | [diff] [blame] | 2207 | unsigned int cpu; |
Alexander Gordeev | 6398268 | 2012-06-05 13:23:44 +0200 | [diff] [blame] | 2208 | |
| 2209 | for_each_cpu_and(cpu, cpumask, andmask) { |
| 2210 | if (cpumask_test_cpu(cpu, cpu_online_mask)) |
| 2211 | break; |
| 2212 | } |
Alexander Gordeev | ff16432 | 2012-06-07 15:15:59 +0200 | [diff] [blame] | 2213 | |
Alexander Gordeev | ea3807e | 2012-06-14 09:49:55 +0200 | [diff] [blame] | 2214 | if (likely(cpu < nr_cpu_ids)) { |
Alexander Gordeev | a5a3915 | 2012-06-14 09:49:35 +0200 | [diff] [blame] | 2215 | *apicid = per_cpu(x86_cpu_to_apicid, cpu); |
| 2216 | return 0; |
Alexander Gordeev | a5a3915 | 2012-06-14 09:49:35 +0200 | [diff] [blame] | 2217 | } |
Alexander Gordeev | ea3807e | 2012-06-14 09:49:55 +0200 | [diff] [blame] | 2218 | |
| 2219 | return -EINVAL; |
Alexander Gordeev | 6398268 | 2012-06-05 13:23:44 +0200 | [diff] [blame] | 2220 | } |
| 2221 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 2222 | /* |
Michael S. Tsirkin | 1551df6 | 2012-07-15 15:56:46 +0300 | [diff] [blame] | 2223 | * Override the generic EOI implementation with an optimized version. |
| 2224 | * Only called during early boot when only one CPU is active and with |
| 2225 | * interrupts disabled, so we know this does not race with actual APIC driver |
| 2226 | * use. |
| 2227 | */ |
| 2228 | void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v)) |
| 2229 | { |
| 2230 | struct apic **drv; |
| 2231 | |
| 2232 | for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) { |
| 2233 | /* Should happen once for each apic */ |
| 2234 | WARN_ON((*drv)->eoi_write == eoi_write); |
| 2235 | (*drv)->eoi_write = eoi_write; |
| 2236 | } |
| 2237 | } |
| 2238 | |
| 2239 | /* |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 2240 | * Power management |
| 2241 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | #ifdef CONFIG_PM |
| 2243 | |
| 2244 | static struct { |
Cyrill Gorcunov | 274cfe5 | 2008-08-16 23:21:53 +0400 | [diff] [blame] | 2245 | /* |
| 2246 | * 'active' is true if the local APIC was enabled by us and |
| 2247 | * not the BIOS; this signifies that we are also responsible |
| 2248 | * for disabling it before entering apm/acpi suspend |
| 2249 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | int active; |
| 2251 | /* r/w apic fields */ |
| 2252 | unsigned int apic_id; |
| 2253 | unsigned int apic_taskpri; |
| 2254 | unsigned int apic_ldr; |
| 2255 | unsigned int apic_dfr; |
| 2256 | unsigned int apic_spiv; |
| 2257 | unsigned int apic_lvtt; |
| 2258 | unsigned int apic_lvtpc; |
| 2259 | unsigned int apic_lvt0; |
| 2260 | unsigned int apic_lvt1; |
| 2261 | unsigned int apic_lvterr; |
| 2262 | unsigned int apic_tmict; |
| 2263 | unsigned int apic_tdcr; |
| 2264 | unsigned int apic_thmr; |
| 2265 | } apic_pm_state; |
| 2266 | |
Rafael J. Wysocki | f3c6ea1 | 2011-03-23 22:15:54 +0100 | [diff] [blame] | 2267 | static int lapic_suspend(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | { |
| 2269 | unsigned long flags; |
Karsten Wiese | f990fff | 2006-12-07 02:14:11 +0100 | [diff] [blame] | 2270 | int maxlvt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | |
| 2272 | if (!apic_pm_state.active) |
| 2273 | return 0; |
| 2274 | |
Thomas Gleixner | 37e650c | 2008-01-30 13:30:14 +0100 | [diff] [blame] | 2275 | maxlvt = lapic_get_maxlvt(); |
Karsten Wiese | f990fff | 2006-12-07 02:14:11 +0100 | [diff] [blame] | 2276 | |
Suresh Siddha | 2d7a66d | 2008-07-11 14:24:19 -0700 | [diff] [blame] | 2277 | apic_pm_state.apic_id = apic_read(APIC_ID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | apic_pm_state.apic_taskpri = apic_read(APIC_TASKPRI); |
| 2279 | apic_pm_state.apic_ldr = apic_read(APIC_LDR); |
| 2280 | apic_pm_state.apic_dfr = apic_read(APIC_DFR); |
| 2281 | apic_pm_state.apic_spiv = apic_read(APIC_SPIV); |
| 2282 | apic_pm_state.apic_lvtt = apic_read(APIC_LVTT); |
Karsten Wiese | f990fff | 2006-12-07 02:14:11 +0100 | [diff] [blame] | 2283 | if (maxlvt >= 4) |
| 2284 | apic_pm_state.apic_lvtpc = apic_read(APIC_LVTPC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | apic_pm_state.apic_lvt0 = apic_read(APIC_LVT0); |
| 2286 | apic_pm_state.apic_lvt1 = apic_read(APIC_LVT1); |
| 2287 | apic_pm_state.apic_lvterr = apic_read(APIC_LVTERR); |
| 2288 | apic_pm_state.apic_tmict = apic_read(APIC_TMICT); |
| 2289 | apic_pm_state.apic_tdcr = apic_read(APIC_TDCR); |
Andi Kleen | 4efc067 | 2009-04-28 19:07:31 +0200 | [diff] [blame] | 2290 | #ifdef CONFIG_X86_THERMAL_VECTOR |
Karsten Wiese | f990fff | 2006-12-07 02:14:11 +0100 | [diff] [blame] | 2291 | if (maxlvt >= 5) |
| 2292 | apic_pm_state.apic_thmr = apic_read(APIC_LVTTHMR); |
| 2293 | #endif |
Cyrill Gorcunov | 24968cf | 2008-08-16 23:21:52 +0400 | [diff] [blame] | 2294 | |
Fernando Luis Vázquez Cao | 2b94ab2 | 2006-09-26 10:52:33 +0200 | [diff] [blame] | 2295 | local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | disable_local_APIC(); |
Suresh Siddha | fc1edaf | 2009-04-20 13:02:27 -0700 | [diff] [blame] | 2297 | |
Joerg Roedel | 70733e0 | 2012-09-26 12:44:33 +0200 | [diff] [blame] | 2298 | irq_remapping_disable(); |
Suresh Siddha | fc1edaf | 2009-04-20 13:02:27 -0700 | [diff] [blame] | 2299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | local_irq_restore(flags); |
| 2301 | return 0; |
| 2302 | } |
| 2303 | |
Rafael J. Wysocki | f3c6ea1 | 2011-03-23 22:15:54 +0100 | [diff] [blame] | 2304 | static void lapic_resume(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | { |
| 2306 | unsigned int l, h; |
| 2307 | unsigned long flags; |
Suresh Siddha | 31dce14 | 2011-05-18 16:31:33 -0700 | [diff] [blame] | 2308 | int maxlvt; |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 2309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | if (!apic_pm_state.active) |
Rafael J. Wysocki | f3c6ea1 | 2011-03-23 22:15:54 +0100 | [diff] [blame] | 2311 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 2313 | local_irq_save(flags); |
Joerg Roedel | 336224b | 2012-09-26 12:44:34 +0200 | [diff] [blame] | 2314 | |
| 2315 | /* |
| 2316 | * IO-APIC and PIC have their own resume routines. |
| 2317 | * We just mask them here to make sure the interrupt |
| 2318 | * subsystem is completely quiet while we enable x2apic |
| 2319 | * and interrupt-remapping. |
| 2320 | */ |
| 2321 | mask_ioapic_entries(); |
| 2322 | legacy_pic->mask_all(); |
Karsten Wiese | f990fff | 2006-12-07 02:14:11 +0100 | [diff] [blame] | 2323 | |
Suresh Siddha | fc1edaf | 2009-04-20 13:02:27 -0700 | [diff] [blame] | 2324 | if (x2apic_mode) |
Cyrill Gorcunov | 92206c9 | 2008-08-16 23:21:51 +0400 | [diff] [blame] | 2325 | enable_x2apic(); |
Suresh Siddha | cf6567f | 2009-03-16 17:05:00 -0700 | [diff] [blame] | 2326 | else { |
Cyrill Gorcunov | 92206c9 | 2008-08-16 23:21:51 +0400 | [diff] [blame] | 2327 | /* |
| 2328 | * Make sure the APICBASE points to the right address |
| 2329 | * |
| 2330 | * FIXME! This will be wrong if we ever support suspend on |
| 2331 | * SMP! We'll need to do this as part of the CPU restore! |
| 2332 | */ |
Bryan O'Donoghue | cbf2829 | 2012-04-18 17:37:39 +0100 | [diff] [blame] | 2333 | if (boot_cpu_data.x86 >= 6) { |
| 2334 | rdmsr(MSR_IA32_APICBASE, l, h); |
| 2335 | l &= ~MSR_IA32_APICBASE_BASE; |
| 2336 | l |= MSR_IA32_APICBASE_ENABLE | mp_lapic_addr; |
| 2337 | wrmsr(MSR_IA32_APICBASE, l, h); |
| 2338 | } |
Yinghai Lu | d5e629a | 2008-08-17 21:12:27 -0700 | [diff] [blame] | 2339 | } |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 2340 | |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 2341 | maxlvt = lapic_get_maxlvt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | apic_write(APIC_LVTERR, ERROR_APIC_VECTOR | APIC_LVT_MASKED); |
| 2343 | apic_write(APIC_ID, apic_pm_state.apic_id); |
| 2344 | apic_write(APIC_DFR, apic_pm_state.apic_dfr); |
| 2345 | apic_write(APIC_LDR, apic_pm_state.apic_ldr); |
| 2346 | apic_write(APIC_TASKPRI, apic_pm_state.apic_taskpri); |
| 2347 | apic_write(APIC_SPIV, apic_pm_state.apic_spiv); |
| 2348 | apic_write(APIC_LVT0, apic_pm_state.apic_lvt0); |
| 2349 | apic_write(APIC_LVT1, apic_pm_state.apic_lvt1); |
Paul Bolle | 71c69f7 | 2013-05-29 20:57:30 +0200 | [diff] [blame] | 2350 | #if defined(CONFIG_X86_MCE_INTEL) |
Karsten Wiese | f990fff | 2006-12-07 02:14:11 +0100 | [diff] [blame] | 2351 | if (maxlvt >= 5) |
| 2352 | apic_write(APIC_LVTTHMR, apic_pm_state.apic_thmr); |
| 2353 | #endif |
| 2354 | if (maxlvt >= 4) |
| 2355 | apic_write(APIC_LVTPC, apic_pm_state.apic_lvtpc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | apic_write(APIC_LVTT, apic_pm_state.apic_lvtt); |
| 2357 | apic_write(APIC_TDCR, apic_pm_state.apic_tdcr); |
| 2358 | apic_write(APIC_TMICT, apic_pm_state.apic_tmict); |
| 2359 | apic_write(APIC_ESR, 0); |
| 2360 | apic_read(APIC_ESR); |
| 2361 | apic_write(APIC_LVTERR, apic_pm_state.apic_lvterr); |
| 2362 | apic_write(APIC_ESR, 0); |
| 2363 | apic_read(APIC_ESR); |
Cyrill Gorcunov | 92206c9 | 2008-08-16 23:21:51 +0400 | [diff] [blame] | 2364 | |
Joerg Roedel | 70733e0 | 2012-09-26 12:44:33 +0200 | [diff] [blame] | 2365 | irq_remapping_reenable(x2apic_mode); |
Suresh Siddha | 31dce14 | 2011-05-18 16:31:33 -0700 | [diff] [blame] | 2366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | } |
| 2369 | |
Cyrill Gorcunov | 274cfe5 | 2008-08-16 23:21:53 +0400 | [diff] [blame] | 2370 | /* |
| 2371 | * This device has no shutdown method - fully functioning local APICs |
| 2372 | * are needed on every CPU up until machine_halt/restart/poweroff. |
| 2373 | */ |
| 2374 | |
Rafael J. Wysocki | f3c6ea1 | 2011-03-23 22:15:54 +0100 | [diff] [blame] | 2375 | static struct syscore_ops lapic_syscore_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | .resume = lapic_resume, |
| 2377 | .suspend = lapic_suspend, |
| 2378 | }; |
| 2379 | |
Ashok Raj | e6982c6 | 2005-06-25 14:54:58 -0700 | [diff] [blame] | 2380 | static void __cpuinit apic_pm_activate(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | { |
| 2382 | apic_pm_state.active = 1; |
| 2383 | } |
| 2384 | |
| 2385 | static int __init init_lapic_sysfs(void) |
| 2386 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | /* XXX: remove suspend/resume procs if !apic_pm_state.active? */ |
Rafael J. Wysocki | f3c6ea1 | 2011-03-23 22:15:54 +0100 | [diff] [blame] | 2388 | if (cpu_has_apic) |
| 2389 | register_syscore_ops(&lapic_syscore_ops); |
Hiroshi Shimamoto | e83a5fd | 2008-01-30 13:32:35 +0100 | [diff] [blame] | 2390 | |
Rafael J. Wysocki | f3c6ea1 | 2011-03-23 22:15:54 +0100 | [diff] [blame] | 2391 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | } |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 2393 | |
| 2394 | /* local apic needs to resume before other devices access its registers. */ |
| 2395 | core_initcall(init_lapic_sysfs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | |
| 2397 | #else /* CONFIG_PM */ |
| 2398 | |
| 2399 | static void apic_pm_activate(void) { } |
| 2400 | |
| 2401 | #endif /* CONFIG_PM */ |
| 2402 | |
Yinghai Lu | f28c0ae | 2008-08-24 02:01:49 -0700 | [diff] [blame] | 2403 | #ifdef CONFIG_X86_64 |
Yinghai Lu | e0e4214 | 2009-04-26 23:39:38 -0700 | [diff] [blame] | 2404 | |
| 2405 | static int __cpuinit apic_cluster_num(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | { |
| 2407 | int i, clusters, zeros; |
| 2408 | unsigned id; |
Yinghai Lu | 322850a | 2008-02-23 21:48:42 -0800 | [diff] [blame] | 2409 | u16 *bios_cpu_apicid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS); |
| 2411 | |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 2412 | bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid); |
Suresh Siddha | 376ec33 | 2005-05-16 21:53:32 -0700 | [diff] [blame] | 2413 | bitmap_zero(clustermap, NUM_APIC_CLUSTERS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | |
Mike Travis | 168ef54 | 2008-12-16 17:34:01 -0800 | [diff] [blame] | 2415 | for (i = 0; i < nr_cpu_ids; i++) { |
travis@sgi.com | e8c10ef | 2008-01-30 13:33:12 +0100 | [diff] [blame] | 2416 | /* are we being called early in kernel startup? */ |
Mike Travis | 693e3c5 | 2008-01-30 13:33:14 +0100 | [diff] [blame] | 2417 | if (bios_cpu_apicid) { |
| 2418 | id = bios_cpu_apicid[i]; |
Jaswinder Singh Rajput | e423e33 | 2009-01-04 16:16:25 +0530 | [diff] [blame] | 2419 | } else if (i < nr_cpu_ids) { |
travis@sgi.com | e8c10ef | 2008-01-30 13:33:12 +0100 | [diff] [blame] | 2420 | if (cpu_present(i)) |
| 2421 | id = per_cpu(x86_bios_cpu_apicid, i); |
| 2422 | else |
| 2423 | continue; |
Jaswinder Singh Rajput | e423e33 | 2009-01-04 16:16:25 +0530 | [diff] [blame] | 2424 | } else |
travis@sgi.com | e8c10ef | 2008-01-30 13:33:12 +0100 | [diff] [blame] | 2425 | break; |
| 2426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | if (id != BAD_APICID) |
| 2428 | __set_bit(APIC_CLUSTERID(id), clustermap); |
| 2429 | } |
| 2430 | |
| 2431 | /* Problem: Partially populated chassis may not have CPUs in some of |
| 2432 | * the APIC clusters they have been allocated. Only present CPUs have |
travis@sgi.com | 602a54a | 2008-01-30 13:33:21 +0100 | [diff] [blame] | 2433 | * x86_bios_cpu_apicid entries, thus causing zeroes in the bitmap. |
| 2434 | * Since clusters are allocated sequentially, count zeros only if |
| 2435 | * they are bounded by ones. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | */ |
| 2437 | clusters = 0; |
| 2438 | zeros = 0; |
| 2439 | for (i = 0; i < NUM_APIC_CLUSTERS; i++) { |
| 2440 | if (test_bit(i, clustermap)) { |
| 2441 | clusters += 1 + zeros; |
| 2442 | zeros = 0; |
| 2443 | } else |
| 2444 | ++zeros; |
| 2445 | } |
| 2446 | |
Yinghai Lu | e0e4214 | 2009-04-26 23:39:38 -0700 | [diff] [blame] | 2447 | return clusters; |
| 2448 | } |
| 2449 | |
| 2450 | static int __cpuinitdata multi_checked; |
| 2451 | static int __cpuinitdata multi; |
| 2452 | |
| 2453 | static int __cpuinit set_multi(const struct dmi_system_id *d) |
| 2454 | { |
| 2455 | if (multi) |
| 2456 | return 0; |
Cyrill Gorcunov | 6f0aced | 2009-05-01 23:54:25 +0400 | [diff] [blame] | 2457 | pr_info("APIC: %s detected, Multi Chassis\n", d->ident); |
Yinghai Lu | e0e4214 | 2009-04-26 23:39:38 -0700 | [diff] [blame] | 2458 | multi = 1; |
| 2459 | return 0; |
| 2460 | } |
| 2461 | |
| 2462 | static const __cpuinitconst struct dmi_system_id multi_dmi_table[] = { |
| 2463 | { |
| 2464 | .callback = set_multi, |
| 2465 | .ident = "IBM System Summit2", |
| 2466 | .matches = { |
| 2467 | DMI_MATCH(DMI_SYS_VENDOR, "IBM"), |
| 2468 | DMI_MATCH(DMI_PRODUCT_NAME, "Summit2"), |
| 2469 | }, |
| 2470 | }, |
| 2471 | {} |
| 2472 | }; |
| 2473 | |
| 2474 | static void __cpuinit dmi_check_multi(void) |
| 2475 | { |
| 2476 | if (multi_checked) |
| 2477 | return; |
| 2478 | |
| 2479 | dmi_check_system(multi_dmi_table); |
| 2480 | multi_checked = 1; |
| 2481 | } |
| 2482 | |
| 2483 | /* |
| 2484 | * apic_is_clustered_box() -- Check if we can expect good TSC |
| 2485 | * |
| 2486 | * Thus far, the major user of this is IBM's Summit2 series: |
| 2487 | * Clustered boxes may have unsynced TSC problems if they are |
| 2488 | * multi-chassis. |
| 2489 | * Use DMI to check them |
| 2490 | */ |
| 2491 | __cpuinit int apic_is_clustered_box(void) |
| 2492 | { |
| 2493 | dmi_check_multi(); |
| 2494 | if (multi) |
Ravikiran G Thirumalai | 1cb6848 | 2008-03-20 00:45:08 -0700 | [diff] [blame] | 2495 | return 1; |
| 2496 | |
Yinghai Lu | e0e4214 | 2009-04-26 23:39:38 -0700 | [diff] [blame] | 2497 | if (!is_vsmp_box()) |
| 2498 | return 0; |
| 2499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | /* |
Yinghai Lu | e0e4214 | 2009-04-26 23:39:38 -0700 | [diff] [blame] | 2501 | * ScaleMP vSMPowered boxes have one cluster per board and TSCs are |
| 2502 | * not guaranteed to be synced between boards |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2503 | */ |
Yinghai Lu | e0e4214 | 2009-04-26 23:39:38 -0700 | [diff] [blame] | 2504 | if (apic_cluster_num() > 1) |
| 2505 | return 1; |
| 2506 | |
| 2507 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | } |
Yinghai Lu | f28c0ae | 2008-08-24 02:01:49 -0700 | [diff] [blame] | 2509 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | |
| 2511 | /* |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 2512 | * APIC command line parameters |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | */ |
Cyrill Gorcunov | 789fa73 | 2008-08-18 20:46:01 +0400 | [diff] [blame] | 2514 | static int __init setup_disableapic(char *arg) |
Thomas Gleixner | 6935d1f | 2007-07-21 17:10:17 +0200 | [diff] [blame] | 2515 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 | disable_apic = 1; |
Yinghai Lu | 9175fc0 | 2008-07-21 01:38:14 -0700 | [diff] [blame] | 2517 | setup_clear_cpu_cap(X86_FEATURE_APIC); |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 2518 | return 0; |
| 2519 | } |
| 2520 | early_param("disableapic", setup_disableapic); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 2522 | /* same as disableapic, for compatibility */ |
Cyrill Gorcunov | 789fa73 | 2008-08-18 20:46:01 +0400 | [diff] [blame] | 2523 | static int __init setup_nolapic(char *arg) |
Thomas Gleixner | 6935d1f | 2007-07-21 17:10:17 +0200 | [diff] [blame] | 2524 | { |
Cyrill Gorcunov | 789fa73 | 2008-08-18 20:46:01 +0400 | [diff] [blame] | 2525 | return setup_disableapic(arg); |
Thomas Gleixner | 6935d1f | 2007-07-21 17:10:17 +0200 | [diff] [blame] | 2526 | } |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 2527 | early_param("nolapic", setup_nolapic); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2528 | |
Linus Torvalds | 2e7c283 | 2007-03-23 11:32:31 -0700 | [diff] [blame] | 2529 | static int __init parse_lapic_timer_c2_ok(char *arg) |
| 2530 | { |
| 2531 | local_apic_timer_c2_ok = 1; |
| 2532 | return 0; |
| 2533 | } |
| 2534 | early_param("lapic_timer_c2_ok", parse_lapic_timer_c2_ok); |
| 2535 | |
Cyrill Gorcunov | 36fef09 | 2008-08-15 13:51:20 +0200 | [diff] [blame] | 2536 | static int __init parse_disable_apic_timer(char *arg) |
Thomas Gleixner | 6935d1f | 2007-07-21 17:10:17 +0200 | [diff] [blame] | 2537 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | disable_apic_timer = 1; |
Cyrill Gorcunov | 36fef09 | 2008-08-15 13:51:20 +0200 | [diff] [blame] | 2539 | return 0; |
Thomas Gleixner | 6935d1f | 2007-07-21 17:10:17 +0200 | [diff] [blame] | 2540 | } |
Cyrill Gorcunov | 36fef09 | 2008-08-15 13:51:20 +0200 | [diff] [blame] | 2541 | early_param("noapictimer", parse_disable_apic_timer); |
| 2542 | |
| 2543 | static int __init parse_nolapic_timer(char *arg) |
| 2544 | { |
| 2545 | disable_apic_timer = 1; |
| 2546 | return 0; |
| 2547 | } |
| 2548 | early_param("nolapic_timer", parse_nolapic_timer); |
Andi Kleen | 73dea47 | 2006-02-03 21:50:50 +0100 | [diff] [blame] | 2549 | |
Cyrill Gorcunov | 79af9be | 2008-08-18 20:46:00 +0400 | [diff] [blame] | 2550 | static int __init apic_set_verbosity(char *arg) |
| 2551 | { |
| 2552 | if (!arg) { |
| 2553 | #ifdef CONFIG_X86_64 |
| 2554 | skip_ioapic_setup = 0; |
Cyrill Gorcunov | 79af9be | 2008-08-18 20:46:00 +0400 | [diff] [blame] | 2555 | return 0; |
| 2556 | #endif |
| 2557 | return -EINVAL; |
| 2558 | } |
| 2559 | |
| 2560 | if (strcmp("debug", arg) == 0) |
| 2561 | apic_verbosity = APIC_DEBUG; |
| 2562 | else if (strcmp("verbose", arg) == 0) |
| 2563 | apic_verbosity = APIC_VERBOSE; |
| 2564 | else { |
Cyrill Gorcunov | ba21ebb | 2008-11-10 09:16:41 +0100 | [diff] [blame] | 2565 | pr_warning("APIC Verbosity level %s not recognised" |
Cyrill Gorcunov | 79af9be | 2008-08-18 20:46:00 +0400 | [diff] [blame] | 2566 | " use apic=verbose or apic=debug\n", arg); |
| 2567 | return -EINVAL; |
| 2568 | } |
| 2569 | |
| 2570 | return 0; |
| 2571 | } |
| 2572 | early_param("apic", apic_set_verbosity); |
| 2573 | |
Yinghai Lu | 1e934dd | 2008-02-22 13:37:26 -0800 | [diff] [blame] | 2574 | static int __init lapic_insert_resource(void) |
| 2575 | { |
| 2576 | if (!apic_phys) |
| 2577 | return -1; |
| 2578 | |
| 2579 | /* Put local APIC into the resource map. */ |
| 2580 | lapic_resource.start = apic_phys; |
| 2581 | lapic_resource.end = lapic_resource.start + PAGE_SIZE - 1; |
| 2582 | insert_resource(&iomem_resource, &lapic_resource); |
| 2583 | |
| 2584 | return 0; |
| 2585 | } |
| 2586 | |
| 2587 | /* |
| 2588 | * need call insert after e820_reserve_resources() |
| 2589 | * that is using request_resource |
| 2590 | */ |
| 2591 | late_initcall(lapic_insert_resource); |