Suresh Siddha | 2d9579a | 2008-07-10 11:16:59 -0700 | [diff] [blame] | 1 | #include <linux/threads.h> |
| 2 | #include <linux/cpumask.h> |
| 3 | #include <linux/string.h> |
| 4 | #include <linux/kernel.h> |
| 5 | #include <linux/ctype.h> |
| 6 | #include <linux/init.h> |
Yinghai Lu | 1b9b89e | 2008-07-21 22:08:21 -0700 | [diff] [blame] | 7 | #include <linux/dmar.h> |
| 8 | |
Suresh Siddha | 2d9579a | 2008-07-10 11:16:59 -0700 | [diff] [blame] | 9 | #include <asm/smp.h> |
Cyrill Gorcunov | 79deb8e | 2011-05-19 16:45:50 -0700 | [diff] [blame] | 10 | #include <asm/x2apic.h> |
Suresh Siddha | 2d9579a | 2008-07-10 11:16:59 -0700 | [diff] [blame] | 11 | |
Suresh Siddha | ef1f87a | 2009-02-21 14:23:21 -0800 | [diff] [blame] | 12 | int x2apic_phys; |
Yinghai Lu | 1b9b89e | 2008-07-21 22:08:21 -0700 | [diff] [blame] | 13 | |
| 14 | static int set_x2apic_phys_mode(char *arg) |
| 15 | { |
| 16 | x2apic_phys = 1; |
| 17 | return 0; |
| 18 | } |
| 19 | early_param("x2apic_phys", set_x2apic_phys_mode); |
| 20 | |
Marcin Slusarz | 3cfba08 | 2008-10-12 11:46:23 +0200 | [diff] [blame] | 21 | static int x2apic_acpi_madt_oem_check(char *oem_id, char *oem_table_id) |
Yinghai Lu | 1b9b89e | 2008-07-21 22:08:21 -0700 | [diff] [blame] | 22 | { |
Suresh Siddha | ef1f87a | 2009-02-21 14:23:21 -0800 | [diff] [blame] | 23 | if (x2apic_phys) |
| 24 | return x2apic_enabled(); |
| 25 | else |
| 26 | return 0; |
Yinghai Lu | 1b9b89e | 2008-07-21 22:08:21 -0700 | [diff] [blame] | 27 | } |
Suresh Siddha | 2d9579a | 2008-07-10 11:16:59 -0700 | [diff] [blame] | 28 | |
Ingo Molnar | dac5f41 | 2009-01-28 15:42:24 +0100 | [diff] [blame] | 29 | static void |
Suresh Siddha | a27d0b5 | 2011-05-19 16:45:47 -0700 | [diff] [blame] | 30 | __x2apic_send_IPI_mask(const struct cpumask *mask, int vector, int apic_dest) |
Mike Travis | e798673 | 2008-12-16 17:33:52 -0800 | [diff] [blame] | 31 | { |
Ingo Molnar | dac5f41 | 2009-01-28 15:42:24 +0100 | [diff] [blame] | 32 | unsigned long query_cpu; |
Suresh Siddha | a27d0b5 | 2011-05-19 16:45:47 -0700 | [diff] [blame] | 33 | unsigned long this_cpu; |
Ingo Molnar | dac5f41 | 2009-01-28 15:42:24 +0100 | [diff] [blame] | 34 | unsigned long flags; |
Mike Travis | e798673 | 2008-12-16 17:33:52 -0800 | [diff] [blame] | 35 | |
Suresh Siddha | ce4e240 | 2009-03-17 10:16:54 -0800 | [diff] [blame] | 36 | x2apic_wrmsr_fence(); |
| 37 | |
Mike Travis | e798673 | 2008-12-16 17:33:52 -0800 | [diff] [blame] | 38 | local_irq_save(flags); |
Suresh Siddha | a27d0b5 | 2011-05-19 16:45:47 -0700 | [diff] [blame] | 39 | |
| 40 | this_cpu = smp_processor_id(); |
Mike Travis | bcda016 | 2008-12-16 17:33:59 -0800 | [diff] [blame] | 41 | for_each_cpu(query_cpu, mask) { |
Suresh Siddha | a27d0b5 | 2011-05-19 16:45:47 -0700 | [diff] [blame] | 42 | if (apic_dest == APIC_DEST_ALLBUT && this_cpu == query_cpu) |
Ingo Molnar | dac5f41 | 2009-01-28 15:42:24 +0100 | [diff] [blame] | 43 | continue; |
| 44 | __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu), |
| 45 | vector, APIC_DEST_PHYSICAL); |
| 46 | } |
Mike Travis | e798673 | 2008-12-16 17:33:52 -0800 | [diff] [blame] | 47 | local_irq_restore(flags); |
Suresh Siddha | 2d9579a | 2008-07-10 11:16:59 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Suresh Siddha | a27d0b5 | 2011-05-19 16:45:47 -0700 | [diff] [blame] | 50 | static void x2apic_send_IPI_mask(const struct cpumask *mask, int vector) |
| 51 | { |
| 52 | __x2apic_send_IPI_mask(mask, vector, APIC_DEST_ALLINC); |
| 53 | } |
| 54 | |
| 55 | static void |
| 56 | x2apic_send_IPI_mask_allbutself(const struct cpumask *mask, int vector) |
| 57 | { |
| 58 | __x2apic_send_IPI_mask(mask, vector, APIC_DEST_ALLBUT); |
| 59 | } |
| 60 | |
| 61 | static void x2apic_send_IPI_allbutself(int vector) |
| 62 | { |
| 63 | __x2apic_send_IPI_mask(cpu_online_mask, vector, APIC_DEST_ALLBUT); |
| 64 | } |
| 65 | |
Suresh Siddha | 2d9579a | 2008-07-10 11:16:59 -0700 | [diff] [blame] | 66 | static void x2apic_send_IPI_all(int vector) |
| 67 | { |
Suresh Siddha | a27d0b5 | 2011-05-19 16:45:47 -0700 | [diff] [blame] | 68 | __x2apic_send_IPI_mask(cpu_online_mask, vector, APIC_DEST_ALLINC); |
Suresh Siddha | 2d9579a | 2008-07-10 11:16:59 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Mike Travis | bcda016 | 2008-12-16 17:33:59 -0800 | [diff] [blame] | 71 | static unsigned int x2apic_cpu_mask_to_apicid(const struct cpumask *cpumask) |
Suresh Siddha | 2d9579a | 2008-07-10 11:16:59 -0700 | [diff] [blame] | 72 | { |
Suresh Siddha | 2d9579a | 2008-07-10 11:16:59 -0700 | [diff] [blame] | 73 | /* |
| 74 | * We're using fixed IRQ delivery, can only return one phys APIC ID. |
| 75 | * May as well be the first. |
| 76 | */ |
Ingo Molnar | debccb3 | 2009-01-28 15:20:18 +0100 | [diff] [blame] | 77 | int cpu = cpumask_first(cpumask); |
| 78 | |
Mike Travis | e798673 | 2008-12-16 17:33:52 -0800 | [diff] [blame] | 79 | if ((unsigned)cpu < nr_cpu_ids) |
Suresh Siddha | 2d9579a | 2008-07-10 11:16:59 -0700 | [diff] [blame] | 80 | return per_cpu(x86_cpu_to_apicid, cpu); |
| 81 | else |
| 82 | return BAD_APICID; |
| 83 | } |
| 84 | |
Ingo Molnar | debccb3 | 2009-01-28 15:20:18 +0100 | [diff] [blame] | 85 | static unsigned int |
| 86 | x2apic_cpu_mask_to_apicid_and(const struct cpumask *cpumask, |
| 87 | const struct cpumask *andmask) |
Mike Travis | 95d313c | 2008-12-16 17:33:54 -0800 | [diff] [blame] | 88 | { |
| 89 | int cpu; |
| 90 | |
| 91 | /* |
| 92 | * We're using fixed IRQ delivery, can only return one phys APIC ID. |
| 93 | * May as well be the first. |
| 94 | */ |
Ingo Molnar | debccb3 | 2009-01-28 15:20:18 +0100 | [diff] [blame] | 95 | for_each_cpu_and(cpu, cpumask, andmask) { |
Mike Travis | a775a38 | 2008-12-17 15:21:39 -0800 | [diff] [blame] | 96 | if (cpumask_test_cpu(cpu, cpu_online_mask)) |
| 97 | break; |
Ingo Molnar | debccb3 | 2009-01-28 15:20:18 +0100 | [diff] [blame] | 98 | } |
| 99 | |
Suresh Siddha | 18374d8 | 2009-12-17 18:29:46 -0800 | [diff] [blame] | 100 | return per_cpu(x86_cpu_to_apicid, cpu); |
Mike Travis | 95d313c | 2008-12-16 17:33:54 -0800 | [diff] [blame] | 101 | } |
| 102 | |
Jaswinder Singh Rajput | 4d08d97 | 2008-12-29 22:11:40 +0530 | [diff] [blame] | 103 | static void init_x2apic_ldr(void) |
Suresh Siddha | 2d9579a | 2008-07-10 11:16:59 -0700 | [diff] [blame] | 104 | { |
Suresh Siddha | 2d9579a | 2008-07-10 11:16:59 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Suresh Siddha | 9ebd680 | 2011-05-19 16:45:46 -0700 | [diff] [blame] | 107 | static int x2apic_phys_probe(void) |
| 108 | { |
| 109 | if (x2apic_mode && x2apic_phys) |
| 110 | return 1; |
| 111 | |
| 112 | return apic == &apic_x2apic_phys; |
| 113 | } |
| 114 | |
Ingo Molnar | be163a1 | 2009-02-17 16:28:46 +0100 | [diff] [blame] | 115 | struct apic apic_x2apic_phys = { |
Ingo Molnar | 05c155c | 2009-01-28 02:37:01 +0100 | [diff] [blame] | 116 | |
| 117 | .name = "physical x2apic", |
Suresh Siddha | 9ebd680 | 2011-05-19 16:45:46 -0700 | [diff] [blame] | 118 | .probe = x2apic_phys_probe, |
Ingo Molnar | 05c155c | 2009-01-28 02:37:01 +0100 | [diff] [blame] | 119 | .acpi_madt_oem_check = x2apic_acpi_madt_oem_check, |
| 120 | .apic_id_registered = x2apic_apic_id_registered, |
| 121 | |
Ingo Molnar | f8987a1 | 2009-01-28 04:02:31 +0100 | [diff] [blame] | 122 | .irq_delivery_mode = dest_Fixed, |
Ingo Molnar | 0b06e73 | 2009-01-28 05:13:04 +0100 | [diff] [blame] | 123 | .irq_dest_mode = 0, /* physical */ |
Ingo Molnar | 05c155c | 2009-01-28 02:37:01 +0100 | [diff] [blame] | 124 | |
| 125 | .target_cpus = x2apic_target_cpus, |
Ingo Molnar | 08125d3 | 2009-01-28 05:08:44 +0100 | [diff] [blame] | 126 | .disable_esr = 0, |
Ingo Molnar | bdb1a9b | 2009-01-28 05:29:25 +0100 | [diff] [blame] | 127 | .dest_logical = 0, |
Ingo Molnar | 05c155c | 2009-01-28 02:37:01 +0100 | [diff] [blame] | 128 | .check_apicid_used = NULL, |
| 129 | .check_apicid_present = NULL, |
| 130 | |
Ingo Molnar | 05c155c | 2009-01-28 02:37:01 +0100 | [diff] [blame] | 131 | .vector_allocation_domain = x2apic_vector_allocation_domain, |
| 132 | .init_apic_ldr = init_x2apic_ldr, |
| 133 | |
| 134 | .ioapic_phys_id_map = NULL, |
| 135 | .setup_apic_routing = NULL, |
| 136 | .multi_timer_check = NULL, |
Ingo Molnar | a21769a4 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 137 | .cpu_present_to_apicid = default_cpu_present_to_apicid, |
Ingo Molnar | 05c155c | 2009-01-28 02:37:01 +0100 | [diff] [blame] | 138 | .apicid_to_cpu_present = NULL, |
| 139 | .setup_portio_remap = NULL, |
Ingo Molnar | a27a621 | 2009-01-28 12:43:18 +0100 | [diff] [blame] | 140 | .check_phys_apicid_present = default_check_phys_apicid_present, |
Ingo Molnar | 05c155c | 2009-01-28 02:37:01 +0100 | [diff] [blame] | 141 | .enable_apic_mode = NULL, |
Ingo Molnar | d4c9a9f | 2009-01-28 13:31:22 +0100 | [diff] [blame] | 142 | .phys_pkg_id = x2apic_phys_pkg_id, |
Ingo Molnar | 05c155c | 2009-01-28 02:37:01 +0100 | [diff] [blame] | 143 | .mps_oem_check = NULL, |
| 144 | |
Cyrill Gorcunov | 79deb8e | 2011-05-19 16:45:50 -0700 | [diff] [blame] | 145 | .get_apic_id = x2apic_get_apic_id, |
| 146 | .set_apic_id = x2apic_set_apic_id, |
Ingo Molnar | 05c155c | 2009-01-28 02:37:01 +0100 | [diff] [blame] | 147 | .apic_id_mask = 0xFFFFFFFFu, |
| 148 | |
| 149 | .cpu_mask_to_apicid = x2apic_cpu_mask_to_apicid, |
| 150 | .cpu_mask_to_apicid_and = x2apic_cpu_mask_to_apicid_and, |
| 151 | |
| 152 | .send_IPI_mask = x2apic_send_IPI_mask, |
| 153 | .send_IPI_mask_allbutself = x2apic_send_IPI_mask_allbutself, |
| 154 | .send_IPI_allbutself = x2apic_send_IPI_allbutself, |
| 155 | .send_IPI_all = x2apic_send_IPI_all, |
| 156 | .send_IPI_self = x2apic_send_IPI_self, |
| 157 | |
Ingo Molnar | abfa584 | 2009-01-28 16:15:16 +0100 | [diff] [blame] | 158 | .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW, |
| 159 | .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH, |
Ingo Molnar | 05c155c | 2009-01-28 02:37:01 +0100 | [diff] [blame] | 160 | .wait_for_init_deassert = NULL, |
| 161 | .smp_callin_clear_local_apic = NULL, |
Ingo Molnar | 05c155c | 2009-01-28 02:37:01 +0100 | [diff] [blame] | 162 | .inquire_remote_apic = NULL, |
Yinghai Lu | c1eeb2d | 2009-02-16 23:02:14 -0800 | [diff] [blame] | 163 | |
| 164 | .read = native_apic_msr_read, |
| 165 | .write = native_apic_msr_write, |
| 166 | .icr_read = native_x2apic_icr_read, |
| 167 | .icr_write = native_x2apic_icr_write, |
| 168 | .wait_icr_idle = native_x2apic_wait_icr_idle, |
| 169 | .safe_wait_icr_idle = native_safe_x2apic_wait_icr_idle, |
Suresh Siddha | 2d9579a | 2008-07-10 11:16:59 -0700 | [diff] [blame] | 170 | }; |
Suresh Siddha | 107e0e0 | 2011-05-20 17:51:17 -0700 | [diff] [blame^] | 171 | |
| 172 | apic_driver(apic_x2apic_phys); |