Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Local APIC related interfaces to support IOAPIC, MSI, HT_IRQ etc. |
| 3 | * |
| 4 | * Copyright (C) 1997, 1998, 1999, 2000, 2009 Ingo Molnar, Hajnalka Szabo |
| 5 | * Moved from arch/x86/kernel/apic/io_apic.c. |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 6 | * Jiang Liu <jiang.liu@linux.intel.com> |
| 7 | * Enable support of hierarchical irqdomains |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | #include <linux/interrupt.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/compiler.h> |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 16 | #include <linux/slab.h> |
Jiang Liu | d746d1e | 2015-04-14 10:30:09 +0800 | [diff] [blame] | 17 | #include <asm/irqdomain.h> |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 18 | #include <asm/hw_irq.h> |
| 19 | #include <asm/apic.h> |
| 20 | #include <asm/i8259.h> |
| 21 | #include <asm/desc.h> |
| 22 | #include <asm/irq_remapping.h> |
| 23 | |
Jiang Liu | 7f3262e | 2015-04-14 10:30:03 +0800 | [diff] [blame] | 24 | struct apic_chip_data { |
| 25 | struct irq_cfg cfg; |
Thomas Gleixner | 029c6e1 | 2017-09-13 23:29:31 +0200 | [diff] [blame^] | 26 | unsigned int cpu; |
| 27 | unsigned int prev_cpu; |
Jiang Liu | 7f3262e | 2015-04-14 10:30:03 +0800 | [diff] [blame] | 28 | cpumask_var_t domain; |
| 29 | cpumask_var_t old_domain; |
| 30 | u8 move_in_progress : 1; |
| 31 | }; |
| 32 | |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 33 | struct irq_domain *x86_vector_domain; |
Jake Oshins | c8f3e51 | 2015-12-10 17:52:59 +0000 | [diff] [blame] | 34 | EXPORT_SYMBOL_GPL(x86_vector_domain); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 35 | static DEFINE_RAW_SPINLOCK(vector_lock); |
Thomas Gleixner | 3716fd2 | 2015-12-31 16:30:48 +0000 | [diff] [blame] | 36 | static cpumask_var_t vector_cpumask, vector_searchmask, searched_cpumask; |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 37 | static struct irq_chip lapic_controller; |
Jiang Liu | 1331532 | 2015-04-13 14:11:56 +0800 | [diff] [blame] | 38 | #ifdef CONFIG_X86_IO_APIC |
Jiang Liu | 7f3262e | 2015-04-14 10:30:03 +0800 | [diff] [blame] | 39 | static struct apic_chip_data *legacy_irq_data[NR_IRQS_LEGACY]; |
Jiang Liu | 1331532 | 2015-04-13 14:11:56 +0800 | [diff] [blame] | 40 | #endif |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 41 | |
| 42 | void lock_vector_lock(void) |
| 43 | { |
| 44 | /* Used to the online set of cpus does not change |
| 45 | * during assign_irq_vector. |
| 46 | */ |
| 47 | raw_spin_lock(&vector_lock); |
| 48 | } |
| 49 | |
| 50 | void unlock_vector_lock(void) |
| 51 | { |
| 52 | raw_spin_unlock(&vector_lock); |
| 53 | } |
| 54 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 55 | static struct apic_chip_data *apic_chip_data(struct irq_data *irqd) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 56 | { |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 57 | if (!irqd) |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 58 | return NULL; |
| 59 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 60 | while (irqd->parent_data) |
| 61 | irqd = irqd->parent_data; |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 62 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 63 | return irqd->chip_data; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 64 | } |
| 65 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 66 | struct irq_cfg *irqd_cfg(struct irq_data *irqd) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 67 | { |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 68 | struct apic_chip_data *apicd = apic_chip_data(irqd); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 69 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 70 | return apicd ? &apicd->cfg : NULL; |
Jiang Liu | 7f3262e | 2015-04-14 10:30:03 +0800 | [diff] [blame] | 71 | } |
Jake Oshins | c8f3e51 | 2015-12-10 17:52:59 +0000 | [diff] [blame] | 72 | EXPORT_SYMBOL_GPL(irqd_cfg); |
Jiang Liu | 7f3262e | 2015-04-14 10:30:03 +0800 | [diff] [blame] | 73 | |
| 74 | struct irq_cfg *irq_cfg(unsigned int irq) |
| 75 | { |
| 76 | return irqd_cfg(irq_get_irq_data(irq)); |
| 77 | } |
| 78 | |
| 79 | static struct apic_chip_data *alloc_apic_chip_data(int node) |
| 80 | { |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 81 | struct apic_chip_data *apicd; |
Jiang Liu | 7f3262e | 2015-04-14 10:30:03 +0800 | [diff] [blame] | 82 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 83 | apicd = kzalloc_node(sizeof(*apicd), GFP_KERNEL, node); |
| 84 | if (!apicd) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 85 | return NULL; |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 86 | if (!zalloc_cpumask_var_node(&apicd->domain, GFP_KERNEL, node)) |
Jiang Liu | 7f3262e | 2015-04-14 10:30:03 +0800 | [diff] [blame] | 87 | goto out_data; |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 88 | if (!zalloc_cpumask_var_node(&apicd->old_domain, GFP_KERNEL, node)) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 89 | goto out_domain; |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 90 | return apicd; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 91 | out_domain: |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 92 | free_cpumask_var(apicd->domain); |
Jiang Liu | 7f3262e | 2015-04-14 10:30:03 +0800 | [diff] [blame] | 93 | out_data: |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 94 | kfree(apicd); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 95 | return NULL; |
| 96 | } |
| 97 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 98 | static void free_apic_chip_data(struct apic_chip_data *apicd) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 99 | { |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 100 | if (apicd) { |
| 101 | free_cpumask_var(apicd->domain); |
| 102 | free_cpumask_var(apicd->old_domain); |
| 103 | kfree(apicd); |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 104 | } |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 105 | } |
| 106 | |
Jiang Liu | 7f3262e | 2015-04-14 10:30:03 +0800 | [diff] [blame] | 107 | static int __assign_irq_vector(int irq, struct apic_chip_data *d, |
Thomas Gleixner | 0e24f7c | 2017-06-20 01:37:44 +0200 | [diff] [blame] | 108 | const struct cpumask *mask, |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 109 | struct irq_data *irqd) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 110 | { |
| 111 | /* |
| 112 | * NOTE! The local APIC isn't very good at handling |
| 113 | * multiple interrupts at the same interrupt level. |
| 114 | * As the interrupt level is determined by taking the |
| 115 | * vector number and shifting that right by 4, we |
| 116 | * want to spread these out a bit so that they don't |
| 117 | * all fall in the same interrupt level. |
| 118 | * |
| 119 | * Also, we've got to be careful not to trash gate |
| 120 | * 0x80, because int 0x80 is hm, kind of importantish. ;) |
| 121 | */ |
| 122 | static int current_vector = FIRST_EXTERNAL_VECTOR + VECTOR_OFFSET_START; |
| 123 | static int current_offset = VECTOR_OFFSET_START % 16; |
Thomas Gleixner | ab25ac0 | 2015-12-31 16:30:49 +0000 | [diff] [blame] | 124 | int cpu, vector; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 125 | |
Thomas Gleixner | 98229aa | 2015-12-31 16:30:54 +0000 | [diff] [blame] | 126 | /* |
| 127 | * If there is still a move in progress or the previous move has not |
| 128 | * been cleaned up completely, tell the caller to come back later. |
| 129 | */ |
| 130 | if (d->move_in_progress || |
| 131 | cpumask_intersects(d->old_domain, cpu_online_mask)) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 132 | return -EBUSY; |
| 133 | |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 134 | /* Only try and allocate irqs on cpus that are present */ |
Jiang Liu | 7f3262e | 2015-04-14 10:30:03 +0800 | [diff] [blame] | 135 | cpumask_clear(d->old_domain); |
Jiang Liu | 8a580f7 | 2015-12-31 16:30:46 +0000 | [diff] [blame] | 136 | cpumask_clear(searched_cpumask); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 137 | cpu = cpumask_first_and(mask, cpu_online_mask); |
| 138 | while (cpu < nr_cpu_ids) { |
Thomas Gleixner | ab25ac0 | 2015-12-31 16:30:49 +0000 | [diff] [blame] | 139 | int new_cpu, offset; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 140 | |
Thomas Gleixner | fdba46f | 2017-09-13 23:29:27 +0200 | [diff] [blame] | 141 | cpumask_copy(vector_cpumask, cpumask_of(cpu)); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 142 | |
Thomas Gleixner | 3716fd2 | 2015-12-31 16:30:48 +0000 | [diff] [blame] | 143 | /* |
| 144 | * Clear the offline cpus from @vector_cpumask for searching |
| 145 | * and verify whether the result overlaps with @mask. If true, |
Thomas Gleixner | 91cd9cb | 2017-06-20 01:37:43 +0200 | [diff] [blame] | 146 | * then the call to apic->cpu_mask_to_apicid() will |
Thomas Gleixner | 3716fd2 | 2015-12-31 16:30:48 +0000 | [diff] [blame] | 147 | * succeed as well. If not, no point in trying to find a |
| 148 | * vector in this mask. |
| 149 | */ |
| 150 | cpumask_and(vector_searchmask, vector_cpumask, cpu_online_mask); |
| 151 | if (!cpumask_intersects(vector_searchmask, mask)) |
| 152 | goto next_cpu; |
| 153 | |
Jiang Liu | f7fa7ae | 2015-04-14 10:30:10 +0800 | [diff] [blame] | 154 | if (cpumask_subset(vector_cpumask, d->domain)) { |
Jiang Liu | f7fa7ae | 2015-04-14 10:30:10 +0800 | [diff] [blame] | 155 | if (cpumask_equal(vector_cpumask, d->domain)) |
Thomas Gleixner | 433cbd5 | 2015-12-31 16:30:46 +0000 | [diff] [blame] | 156 | goto success; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 157 | /* |
Thomas Gleixner | ab25ac0 | 2015-12-31 16:30:49 +0000 | [diff] [blame] | 158 | * Mark the cpus which are not longer in the mask for |
| 159 | * cleanup. |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 160 | */ |
Thomas Gleixner | ab25ac0 | 2015-12-31 16:30:49 +0000 | [diff] [blame] | 161 | cpumask_andnot(d->old_domain, d->domain, vector_cpumask); |
| 162 | vector = d->cfg.vector; |
| 163 | goto update; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | vector = current_vector; |
| 167 | offset = current_offset; |
| 168 | next: |
| 169 | vector += 16; |
Thomas Gleixner | 05161b9 | 2017-08-28 08:47:18 +0200 | [diff] [blame] | 170 | if (vector >= FIRST_SYSTEM_VECTOR) { |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 171 | offset = (offset + 1) % 16; |
| 172 | vector = FIRST_EXTERNAL_VECTOR + offset; |
| 173 | } |
| 174 | |
Thomas Gleixner | 95ffeb4 | 2015-12-31 16:30:47 +0000 | [diff] [blame] | 175 | /* If the search wrapped around, try the next cpu */ |
| 176 | if (unlikely(current_vector == vector)) |
| 177 | goto next_cpu; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 178 | |
Thomas Gleixner | 7854f82 | 2017-09-13 23:29:26 +0200 | [diff] [blame] | 179 | if (test_bit(vector, system_vectors)) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 180 | goto next; |
| 181 | |
Thomas Gleixner | 3716fd2 | 2015-12-31 16:30:48 +0000 | [diff] [blame] | 182 | for_each_cpu(new_cpu, vector_searchmask) { |
Thomas Gleixner | a782a7e | 2015-08-02 20:38:27 +0000 | [diff] [blame] | 183 | if (!IS_ERR_OR_NULL(per_cpu(vector_irq, new_cpu)[vector])) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 184 | goto next; |
| 185 | } |
| 186 | /* Found one! */ |
| 187 | current_vector = vector; |
| 188 | current_offset = offset; |
Thomas Gleixner | ab25ac0 | 2015-12-31 16:30:49 +0000 | [diff] [blame] | 189 | /* Schedule the old vector for cleanup on all cpus */ |
| 190 | if (d->cfg.vector) |
Jiang Liu | 7f3262e | 2015-04-14 10:30:03 +0800 | [diff] [blame] | 191 | cpumask_copy(d->old_domain, d->domain); |
Thomas Gleixner | 3716fd2 | 2015-12-31 16:30:48 +0000 | [diff] [blame] | 192 | for_each_cpu(new_cpu, vector_searchmask) |
Thomas Gleixner | a782a7e | 2015-08-02 20:38:27 +0000 | [diff] [blame] | 193 | per_cpu(vector_irq, new_cpu)[vector] = irq_to_desc(irq); |
Thomas Gleixner | ab25ac0 | 2015-12-31 16:30:49 +0000 | [diff] [blame] | 194 | goto update; |
Thomas Gleixner | 95ffeb4 | 2015-12-31 16:30:47 +0000 | [diff] [blame] | 195 | |
| 196 | next_cpu: |
| 197 | /* |
| 198 | * We exclude the current @vector_cpumask from the requested |
| 199 | * @mask and try again with the next online cpu in the |
| 200 | * result. We cannot modify @mask, so we use @vector_cpumask |
| 201 | * as a temporary buffer here as it will be reassigned when |
| 202 | * calling apic->vector_allocation_domain() above. |
| 203 | */ |
| 204 | cpumask_or(searched_cpumask, searched_cpumask, vector_cpumask); |
| 205 | cpumask_andnot(vector_cpumask, mask, searched_cpumask); |
| 206 | cpu = cpumask_first_and(vector_cpumask, cpu_online_mask); |
| 207 | continue; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 208 | } |
Thomas Gleixner | 433cbd5 | 2015-12-31 16:30:46 +0000 | [diff] [blame] | 209 | return -ENOSPC; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 210 | |
Thomas Gleixner | ab25ac0 | 2015-12-31 16:30:49 +0000 | [diff] [blame] | 211 | update: |
Thomas Gleixner | 847667e | 2015-12-31 16:30:50 +0000 | [diff] [blame] | 212 | /* |
| 213 | * Exclude offline cpus from the cleanup mask and set the |
| 214 | * move_in_progress flag when the result is not empty. |
| 215 | */ |
| 216 | cpumask_and(d->old_domain, d->old_domain, cpu_online_mask); |
| 217 | d->move_in_progress = !cpumask_empty(d->old_domain); |
Thomas Gleixner | 551adc6 | 2016-03-14 09:40:46 +0100 | [diff] [blame] | 218 | d->cfg.old_vector = d->move_in_progress ? d->cfg.vector : 0; |
Thomas Gleixner | 029c6e1 | 2017-09-13 23:29:31 +0200 | [diff] [blame^] | 219 | d->prev_cpu = d->cpu; |
Thomas Gleixner | ab25ac0 | 2015-12-31 16:30:49 +0000 | [diff] [blame] | 220 | d->cfg.vector = vector; |
| 221 | cpumask_copy(d->domain, vector_cpumask); |
Thomas Gleixner | 433cbd5 | 2015-12-31 16:30:46 +0000 | [diff] [blame] | 222 | success: |
Thomas Gleixner | 3716fd2 | 2015-12-31 16:30:48 +0000 | [diff] [blame] | 223 | /* |
| 224 | * Cache destination APIC IDs into cfg->dest_apicid. This cannot fail |
| 225 | * as we already established, that mask & d->domain & cpu_online_mask |
| 226 | * is not empty. |
Thomas Gleixner | 52b166a | 2017-06-20 01:37:42 +0200 | [diff] [blame] | 227 | * |
| 228 | * vector_searchmask is a subset of d->domain and has the offline |
| 229 | * cpus masked out. |
Thomas Gleixner | 3716fd2 | 2015-12-31 16:30:48 +0000 | [diff] [blame] | 230 | */ |
Thomas Gleixner | 91cd9cb | 2017-06-20 01:37:43 +0200 | [diff] [blame] | 231 | cpumask_and(vector_searchmask, vector_searchmask, mask); |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 232 | BUG_ON(apic->cpu_mask_to_apicid(vector_searchmask, irqd, |
Thomas Gleixner | 0e24f7c | 2017-06-20 01:37:44 +0200 | [diff] [blame] | 233 | &d->cfg.dest_apicid)); |
Thomas Gleixner | 029c6e1 | 2017-09-13 23:29:31 +0200 | [diff] [blame^] | 234 | d->cpu = cpumask_first(vector_searchmask); |
Thomas Gleixner | 3716fd2 | 2015-12-31 16:30:48 +0000 | [diff] [blame] | 235 | return 0; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 236 | } |
| 237 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 238 | static int assign_irq_vector(int irq, struct apic_chip_data *apicd, |
Thomas Gleixner | 0e24f7c | 2017-06-20 01:37:44 +0200 | [diff] [blame] | 239 | const struct cpumask *mask, |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 240 | struct irq_data *irqd) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 241 | { |
| 242 | int err; |
| 243 | unsigned long flags; |
| 244 | |
| 245 | raw_spin_lock_irqsave(&vector_lock, flags); |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 246 | err = __assign_irq_vector(irq, apicd, mask, irqd); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 247 | raw_spin_unlock_irqrestore(&vector_lock, flags); |
| 248 | return err; |
| 249 | } |
| 250 | |
Jiang Liu | 486ca53 | 2015-05-07 10:53:56 +0800 | [diff] [blame] | 251 | static int assign_irq_vector_policy(int irq, int node, |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 252 | struct apic_chip_data *apicd, |
Thomas Gleixner | 0e24f7c | 2017-06-20 01:37:44 +0200 | [diff] [blame] | 253 | struct irq_alloc_info *info, |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 254 | struct irq_data *irqd) |
Jiang Liu | 486ca53 | 2015-05-07 10:53:56 +0800 | [diff] [blame] | 255 | { |
| 256 | if (info && info->mask) |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 257 | return assign_irq_vector(irq, apicd, info->mask, irqd); |
Jiang Liu | 486ca53 | 2015-05-07 10:53:56 +0800 | [diff] [blame] | 258 | if (node != NUMA_NO_NODE && |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 259 | assign_irq_vector(irq, apicd, cpumask_of_node(node), irqd) == 0) |
Jiang Liu | 486ca53 | 2015-05-07 10:53:56 +0800 | [diff] [blame] | 260 | return 0; |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 261 | return assign_irq_vector(irq, apicd, cpu_online_mask, irqd); |
Jiang Liu | 486ca53 | 2015-05-07 10:53:56 +0800 | [diff] [blame] | 262 | } |
| 263 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 264 | static void clear_irq_vector(int irq, struct apic_chip_data *apicd) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 265 | { |
Thomas Gleixner | a782a7e | 2015-08-02 20:38:27 +0000 | [diff] [blame] | 266 | struct irq_desc *desc; |
Thomas Gleixner | a782a7e | 2015-08-02 20:38:27 +0000 | [diff] [blame] | 267 | int cpu, vector; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 268 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 269 | if (!apicd->cfg.vector) |
Keith Busch | 1bdb897 | 2016-04-27 14:22:32 -0600 | [diff] [blame] | 270 | return; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 271 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 272 | vector = apicd->cfg.vector; |
| 273 | for_each_cpu_and(cpu, apicd->domain, cpu_online_mask) |
Thomas Gleixner | 7276c6a | 2015-08-02 20:38:25 +0000 | [diff] [blame] | 274 | per_cpu(vector_irq, cpu)[vector] = VECTOR_UNUSED; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 275 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 276 | apicd->cfg.vector = 0; |
| 277 | cpumask_clear(apicd->domain); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 278 | |
Thomas Gleixner | 98229aa | 2015-12-31 16:30:54 +0000 | [diff] [blame] | 279 | /* |
| 280 | * If move is in progress or the old_domain mask is not empty, |
| 281 | * i.e. the cleanup IPI has not been processed yet, we need to remove |
| 282 | * the old references to desc from all cpus vector tables. |
| 283 | */ |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 284 | if (!apicd->move_in_progress && cpumask_empty(apicd->old_domain)) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 285 | return; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 286 | |
Thomas Gleixner | a782a7e | 2015-08-02 20:38:27 +0000 | [diff] [blame] | 287 | desc = irq_to_desc(irq); |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 288 | for_each_cpu_and(cpu, apicd->old_domain, cpu_online_mask) { |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 289 | for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; |
| 290 | vector++) { |
Thomas Gleixner | a782a7e | 2015-08-02 20:38:27 +0000 | [diff] [blame] | 291 | if (per_cpu(vector_irq, cpu)[vector] != desc) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 292 | continue; |
Thomas Gleixner | 7276c6a | 2015-08-02 20:38:25 +0000 | [diff] [blame] | 293 | per_cpu(vector_irq, cpu)[vector] = VECTOR_UNUSED; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 294 | break; |
| 295 | } |
| 296 | } |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 297 | apicd->move_in_progress = 0; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 298 | } |
| 299 | |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 300 | void init_irq_alloc_info(struct irq_alloc_info *info, |
| 301 | const struct cpumask *mask) |
| 302 | { |
| 303 | memset(info, 0, sizeof(*info)); |
| 304 | info->mask = mask; |
| 305 | } |
| 306 | |
| 307 | void copy_irq_alloc_info(struct irq_alloc_info *dst, struct irq_alloc_info *src) |
| 308 | { |
| 309 | if (src) |
| 310 | *dst = *src; |
| 311 | else |
| 312 | memset(dst, 0, sizeof(*dst)); |
| 313 | } |
| 314 | |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 315 | static void x86_vector_free_irqs(struct irq_domain *domain, |
| 316 | unsigned int virq, unsigned int nr_irqs) |
| 317 | { |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 318 | struct apic_chip_data *apicd; |
| 319 | struct irq_data *irqd; |
Jiang Liu | 111abeb | 2015-12-31 16:30:44 +0000 | [diff] [blame] | 320 | unsigned long flags; |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 321 | int i; |
| 322 | |
| 323 | for (i = 0; i < nr_irqs; i++) { |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 324 | irqd = irq_domain_get_irq_data(x86_vector_domain, virq + i); |
| 325 | if (irqd && irqd->chip_data) { |
Jiang Liu | 111abeb | 2015-12-31 16:30:44 +0000 | [diff] [blame] | 326 | raw_spin_lock_irqsave(&vector_lock, flags); |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 327 | clear_irq_vector(virq + i, irqd->chip_data); |
| 328 | apicd = irqd->chip_data; |
| 329 | irq_domain_reset_irq_data(irqd); |
Jiang Liu | 111abeb | 2015-12-31 16:30:44 +0000 | [diff] [blame] | 330 | raw_spin_unlock_irqrestore(&vector_lock, flags); |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 331 | free_apic_chip_data(apicd); |
Jiang Liu | 1331532 | 2015-04-13 14:11:56 +0800 | [diff] [blame] | 332 | #ifdef CONFIG_X86_IO_APIC |
| 333 | if (virq + i < nr_legacy_irqs()) |
Jiang Liu | 7f3262e | 2015-04-14 10:30:03 +0800 | [diff] [blame] | 334 | legacy_irq_data[virq + i] = NULL; |
Jiang Liu | 1331532 | 2015-04-13 14:11:56 +0800 | [diff] [blame] | 335 | #endif |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | static int x86_vector_alloc_irqs(struct irq_domain *domain, unsigned int virq, |
| 341 | unsigned int nr_irqs, void *arg) |
| 342 | { |
| 343 | struct irq_alloc_info *info = arg; |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 344 | struct apic_chip_data *apicd; |
| 345 | struct irq_data *irqd; |
Jiang Liu | 5f2dbbc | 2015-06-01 16:05:14 +0800 | [diff] [blame] | 346 | int i, err, node; |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 347 | |
| 348 | if (disable_apic) |
| 349 | return -ENXIO; |
| 350 | |
| 351 | /* Currently vector allocator can't guarantee contiguous allocations */ |
| 352 | if ((info->flags & X86_IRQ_ALLOC_CONTIGUOUS_VECTORS) && nr_irqs > 1) |
| 353 | return -ENOSYS; |
| 354 | |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 355 | for (i = 0; i < nr_irqs; i++) { |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 356 | irqd = irq_domain_get_irq_data(domain, virq + i); |
| 357 | BUG_ON(!irqd); |
| 358 | node = irq_data_get_node(irqd); |
Jiang Liu | 1331532 | 2015-04-13 14:11:56 +0800 | [diff] [blame] | 359 | #ifdef CONFIG_X86_IO_APIC |
Jiang Liu | 7f3262e | 2015-04-14 10:30:03 +0800 | [diff] [blame] | 360 | if (virq + i < nr_legacy_irqs() && legacy_irq_data[virq + i]) |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 361 | apicd = legacy_irq_data[virq + i]; |
Jiang Liu | 1331532 | 2015-04-13 14:11:56 +0800 | [diff] [blame] | 362 | else |
| 363 | #endif |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 364 | apicd = alloc_apic_chip_data(node); |
| 365 | if (!apicd) { |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 366 | err = -ENOMEM; |
| 367 | goto error; |
| 368 | } |
| 369 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 370 | irqd->chip = &lapic_controller; |
| 371 | irqd->chip_data = apicd; |
| 372 | irqd->hwirq = virq + i; |
| 373 | irqd_set_single_target(irqd); |
| 374 | err = assign_irq_vector_policy(virq + i, node, apicd, info, |
| 375 | irqd); |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 376 | if (err) |
| 377 | goto error; |
| 378 | } |
| 379 | |
| 380 | return 0; |
| 381 | |
| 382 | error: |
| 383 | x86_vector_free_irqs(domain, virq, i + 1); |
| 384 | return err; |
| 385 | } |
| 386 | |
Thomas Gleixner | eb18cf5 | 2015-05-05 11:10:11 +0200 | [diff] [blame] | 387 | static const struct irq_domain_ops x86_vector_domain_ops = { |
| 388 | .alloc = x86_vector_alloc_irqs, |
| 389 | .free = x86_vector_free_irqs, |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 390 | }; |
| 391 | |
Jiang Liu | 11d686e | 2014-10-27 16:12:05 +0800 | [diff] [blame] | 392 | int __init arch_probe_nr_irqs(void) |
| 393 | { |
| 394 | int nr; |
| 395 | |
| 396 | if (nr_irqs > (NR_VECTORS * nr_cpu_ids)) |
| 397 | nr_irqs = NR_VECTORS * nr_cpu_ids; |
| 398 | |
| 399 | nr = (gsi_top + nr_legacy_irqs()) + 8 * nr_cpu_ids; |
| 400 | #if defined(CONFIG_PCI_MSI) || defined(CONFIG_HT_IRQ) |
| 401 | /* |
| 402 | * for MSI and HT dyn irq |
| 403 | */ |
| 404 | if (gsi_top <= NR_IRQS_LEGACY) |
| 405 | nr += 8 * nr_cpu_ids; |
| 406 | else |
| 407 | nr += gsi_top * 16; |
| 408 | #endif |
| 409 | if (nr < nr_irqs) |
| 410 | nr_irqs = nr; |
| 411 | |
Vitaly Kuznetsov | 8c058b0 | 2015-11-03 10:40:14 +0100 | [diff] [blame] | 412 | /* |
| 413 | * We don't know if PIC is present at this point so we need to do |
| 414 | * probe() to get the right number of legacy IRQs. |
| 415 | */ |
| 416 | return legacy_pic->probe(); |
Jiang Liu | 11d686e | 2014-10-27 16:12:05 +0800 | [diff] [blame] | 417 | } |
| 418 | |
Jiang Liu | 1331532 | 2015-04-13 14:11:56 +0800 | [diff] [blame] | 419 | #ifdef CONFIG_X86_IO_APIC |
Dou Liyang | a884d25 | 2017-06-21 18:14:21 +0800 | [diff] [blame] | 420 | static void __init init_legacy_irqs(void) |
Jiang Liu | 1331532 | 2015-04-13 14:11:56 +0800 | [diff] [blame] | 421 | { |
| 422 | int i, node = cpu_to_node(0); |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 423 | struct apic_chip_data *apicd; |
Jiang Liu | 1331532 | 2015-04-13 14:11:56 +0800 | [diff] [blame] | 424 | |
| 425 | /* |
| 426 | * For legacy IRQ's, start with assigning irq0 to irq15 to |
Ingo Molnar | 191a663 | 2015-05-11 16:05:09 +0200 | [diff] [blame] | 427 | * ISA_IRQ_VECTOR(i) for all cpu's. |
Jiang Liu | 1331532 | 2015-04-13 14:11:56 +0800 | [diff] [blame] | 428 | */ |
| 429 | for (i = 0; i < nr_legacy_irqs(); i++) { |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 430 | apicd = legacy_irq_data[i] = alloc_apic_chip_data(node); |
| 431 | BUG_ON(!apicd); |
Ingo Molnar | 191a663 | 2015-05-11 16:05:09 +0200 | [diff] [blame] | 432 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 433 | apicd->cfg.vector = ISA_IRQ_VECTOR(i); |
| 434 | cpumask_copy(apicd->domain, cpumask_of(0)); |
Thomas Gleixner | 029c6e1 | 2017-09-13 23:29:31 +0200 | [diff] [blame^] | 435 | apicd->cpu = 0; |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 436 | irq_set_chip_data(i, apicd); |
Jiang Liu | 1331532 | 2015-04-13 14:11:56 +0800 | [diff] [blame] | 437 | } |
| 438 | } |
| 439 | #else |
Dou Liyang | a884d25 | 2017-06-21 18:14:21 +0800 | [diff] [blame] | 440 | static inline void init_legacy_irqs(void) { } |
Jiang Liu | 1331532 | 2015-04-13 14:11:56 +0800 | [diff] [blame] | 441 | #endif |
| 442 | |
Jiang Liu | 11d686e | 2014-10-27 16:12:05 +0800 | [diff] [blame] | 443 | int __init arch_early_irq_init(void) |
| 444 | { |
Thomas Gleixner | 9d35f85 | 2017-06-20 01:37:06 +0200 | [diff] [blame] | 445 | struct fwnode_handle *fn; |
| 446 | |
Jiang Liu | 1331532 | 2015-04-13 14:11:56 +0800 | [diff] [blame] | 447 | init_legacy_irqs(); |
| 448 | |
Thomas Gleixner | 9d35f85 | 2017-06-20 01:37:06 +0200 | [diff] [blame] | 449 | fn = irq_domain_alloc_named_fwnode("VECTOR"); |
| 450 | BUG_ON(!fn); |
| 451 | x86_vector_domain = irq_domain_create_tree(fn, &x86_vector_domain_ops, |
| 452 | NULL); |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 453 | BUG_ON(x86_vector_domain == NULL); |
Thomas Gleixner | 9d35f85 | 2017-06-20 01:37:06 +0200 | [diff] [blame] | 454 | irq_domain_free_fwnode(fn); |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 455 | irq_set_default_host(x86_vector_domain); |
| 456 | |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 457 | arch_init_msi_domain(x86_vector_domain); |
Jiang Liu | 49e07d8 | 2015-04-13 14:11:43 +0800 | [diff] [blame] | 458 | arch_init_htirq_domain(x86_vector_domain); |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 459 | |
Jiang Liu | f7fa7ae | 2015-04-14 10:30:10 +0800 | [diff] [blame] | 460 | BUG_ON(!alloc_cpumask_var(&vector_cpumask, GFP_KERNEL)); |
Thomas Gleixner | 3716fd2 | 2015-12-31 16:30:48 +0000 | [diff] [blame] | 461 | BUG_ON(!alloc_cpumask_var(&vector_searchmask, GFP_KERNEL)); |
Jiang Liu | 8a580f7 | 2015-12-31 16:30:46 +0000 | [diff] [blame] | 462 | BUG_ON(!alloc_cpumask_var(&searched_cpumask, GFP_KERNEL)); |
Jiang Liu | f7fa7ae | 2015-04-14 10:30:10 +0800 | [diff] [blame] | 463 | |
Jiang Liu | 11d686e | 2014-10-27 16:12:05 +0800 | [diff] [blame] | 464 | return arch_early_ioapic_init(); |
| 465 | } |
| 466 | |
Thomas Gleixner | f0cc6cc | 2017-09-13 23:29:29 +0200 | [diff] [blame] | 467 | /* Temporary hack to keep things working */ |
| 468 | static void vector_update_shutdown_irqs(void) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 469 | { |
Thomas Gleixner | a782a7e | 2015-08-02 20:38:27 +0000 | [diff] [blame] | 470 | struct irq_desc *desc; |
Thomas Gleixner | f0cc6cc | 2017-09-13 23:29:29 +0200 | [diff] [blame] | 471 | int irq; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 472 | |
Thomas Gleixner | a782a7e | 2015-08-02 20:38:27 +0000 | [diff] [blame] | 473 | for_each_irq_desc(irq, desc) { |
Thomas Gleixner | f0cc6cc | 2017-09-13 23:29:29 +0200 | [diff] [blame] | 474 | struct irq_data *irqd = irq_desc_get_irq_data(desc); |
| 475 | struct apic_chip_data *ad = apic_chip_data(irqd); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 476 | |
Thomas Gleixner | f0cc6cc | 2017-09-13 23:29:29 +0200 | [diff] [blame] | 477 | if (ad && cpumask_test_cpu(cpu, ad->domain) && ad->cfg.vector) |
| 478 | this_cpu_write(vector_irq[ad->cfg.vector], desc); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 479 | } |
Thomas Gleixner | f0cc6cc | 2017-09-13 23:29:29 +0200 | [diff] [blame] | 480 | } |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 481 | |
Thomas Gleixner | f0cc6cc | 2017-09-13 23:29:29 +0200 | [diff] [blame] | 482 | static struct irq_desc *__setup_vector_irq(int vector) |
| 483 | { |
| 484 | int isairq = vector - ISA_IRQ_VECTOR(0); |
| 485 | |
| 486 | /* Check whether the irq is in the legacy space */ |
| 487 | if (isairq < 0 || isairq >= nr_legacy_irqs()) |
| 488 | return VECTOR_UNUSED; |
| 489 | /* Check whether the irq is handled by the IOAPIC */ |
| 490 | if (test_bit(isairq, &io_apic_irqs)) |
| 491 | return VECTOR_UNUSED; |
| 492 | return irq_to_desc(isairq); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | /* |
Thomas Gleixner | 5a3f75e | 2015-07-05 17:12:32 +0000 | [diff] [blame] | 496 | * Setup the vector to irq mappings. Must be called with vector_lock held. |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 497 | */ |
| 498 | void setup_vector_irq(int cpu) |
| 499 | { |
Thomas Gleixner | f0cc6cc | 2017-09-13 23:29:29 +0200 | [diff] [blame] | 500 | unsigned int vector; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 501 | |
Thomas Gleixner | 5a3f75e | 2015-07-05 17:12:32 +0000 | [diff] [blame] | 502 | lockdep_assert_held(&vector_lock); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 503 | /* |
Thomas Gleixner | f0cc6cc | 2017-09-13 23:29:29 +0200 | [diff] [blame] | 504 | * The interrupt affinity logic never targets interrupts to offline |
| 505 | * CPUs. The exception are the legacy PIC interrupts. In general |
| 506 | * they are only targeted to CPU0, but depending on the platform |
| 507 | * they can be distributed to any online CPU in hardware. The |
| 508 | * kernel has no influence on that. So all active legacy vectors |
| 509 | * must be installed on all CPUs. All non legacy interrupts can be |
| 510 | * cleared. |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 511 | */ |
Thomas Gleixner | f0cc6cc | 2017-09-13 23:29:29 +0200 | [diff] [blame] | 512 | for (vector = 0; vector < NR_VECTORS; vector++) |
| 513 | this_cpu_write(vector_irq[vector], __setup_vector_irq(vector)); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 514 | |
Thomas Gleixner | f0cc6cc | 2017-09-13 23:29:29 +0200 | [diff] [blame] | 515 | /* |
| 516 | * Until the rewrite of the managed interrupt management is in |
| 517 | * place it's necessary to walk the irq descriptors and check for |
| 518 | * interrupts which are targeted at this CPU. |
| 519 | */ |
| 520 | vector_update_shutdown_irqs(); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 521 | } |
| 522 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 523 | static int apic_retrigger_irq(struct irq_data *irqd) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 524 | { |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 525 | struct apic_chip_data *apicd = apic_chip_data(irqd); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 526 | unsigned long flags; |
| 527 | int cpu; |
| 528 | |
| 529 | raw_spin_lock_irqsave(&vector_lock, flags); |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 530 | cpu = cpumask_first_and(apicd->domain, cpu_online_mask); |
| 531 | apic->send_IPI_mask(cpumask_of(cpu), apicd->cfg.vector); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 532 | raw_spin_unlock_irqrestore(&vector_lock, flags); |
| 533 | |
| 534 | return 1; |
| 535 | } |
| 536 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 537 | void apic_ack_edge(struct irq_data *irqd) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 538 | { |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 539 | irq_complete_move(irqd_cfg(irqd)); |
| 540 | irq_move_irq(irqd); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 541 | ack_APIC_irq(); |
| 542 | } |
| 543 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 544 | static int apic_set_affinity(struct irq_data *irqd, |
Jiang Liu | 68f9f44 | 2015-04-14 10:30:01 +0800 | [diff] [blame] | 545 | const struct cpumask *dest, bool force) |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 546 | { |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 547 | struct apic_chip_data *apicd = irqd->chip_data; |
| 548 | int err, irq = irqd->irq; |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 549 | |
Masahiro Yamada | 97f2645 | 2016-08-03 13:45:50 -0700 | [diff] [blame] | 550 | if (!IS_ENABLED(CONFIG_SMP)) |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 551 | return -EPERM; |
| 552 | |
| 553 | if (!cpumask_intersects(dest, cpu_online_mask)) |
| 554 | return -EINVAL; |
| 555 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 556 | err = assign_irq_vector(irq, apicd, dest, irqd); |
Thomas Gleixner | 3716fd2 | 2015-12-31 16:30:48 +0000 | [diff] [blame] | 557 | return err ? err : IRQ_SET_MASK_OK; |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | static struct irq_chip lapic_controller = { |
Thomas Gleixner | 8947dfb | 2017-06-20 01:37:01 +0200 | [diff] [blame] | 561 | .name = "APIC", |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 562 | .irq_ack = apic_ack_edge, |
Jiang Liu | 68f9f44 | 2015-04-14 10:30:01 +0800 | [diff] [blame] | 563 | .irq_set_affinity = apic_set_affinity, |
Jiang Liu | b5dc8e6 | 2015-04-13 14:11:24 +0800 | [diff] [blame] | 564 | .irq_retrigger = apic_retrigger_irq, |
| 565 | }; |
| 566 | |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 567 | #ifdef CONFIG_SMP |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 568 | static void __send_cleanup_vector(struct apic_chip_data *apicd) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 569 | { |
Thomas Gleixner | c1684f5 | 2015-12-31 16:30:51 +0000 | [diff] [blame] | 570 | raw_spin_lock(&vector_lock); |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 571 | cpumask_and(apicd->old_domain, apicd->old_domain, cpu_online_mask); |
| 572 | apicd->move_in_progress = 0; |
| 573 | if (!cpumask_empty(apicd->old_domain)) |
| 574 | apic->send_IPI_mask(apicd->old_domain, IRQ_MOVE_CLEANUP_VECTOR); |
Thomas Gleixner | c1684f5 | 2015-12-31 16:30:51 +0000 | [diff] [blame] | 575 | raw_spin_unlock(&vector_lock); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 576 | } |
| 577 | |
Jiang Liu | c6c2002 | 2015-04-14 10:30:02 +0800 | [diff] [blame] | 578 | void send_cleanup_vector(struct irq_cfg *cfg) |
| 579 | { |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 580 | struct apic_chip_data *apicd; |
Jiang Liu | 7f3262e | 2015-04-14 10:30:03 +0800 | [diff] [blame] | 581 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 582 | apicd = container_of(cfg, struct apic_chip_data, cfg); |
| 583 | if (apicd->move_in_progress) |
| 584 | __send_cleanup_vector(apicd); |
Jiang Liu | c6c2002 | 2015-04-14 10:30:02 +0800 | [diff] [blame] | 585 | } |
| 586 | |
Daniel Bristot de Oliveira | c4158ff | 2017-01-04 12:20:33 +0100 | [diff] [blame] | 587 | asmlinkage __visible void __irq_entry smp_irq_move_cleanup_interrupt(void) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 588 | { |
| 589 | unsigned vector, me; |
| 590 | |
Thomas Gleixner | 6af7faf | 2015-05-15 15:48:25 +0200 | [diff] [blame] | 591 | entering_ack_irq(); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 592 | |
Thomas Gleixner | df54c49 | 2015-08-02 20:38:23 +0000 | [diff] [blame] | 593 | /* Prevent vectors vanishing under us */ |
| 594 | raw_spin_lock(&vector_lock); |
| 595 | |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 596 | me = smp_processor_id(); |
| 597 | for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) { |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 598 | struct apic_chip_data *apicd; |
Thomas Gleixner | a782a7e | 2015-08-02 20:38:27 +0000 | [diff] [blame] | 599 | struct irq_desc *desc; |
| 600 | unsigned int irr; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 601 | |
Thomas Gleixner | df54c49 | 2015-08-02 20:38:23 +0000 | [diff] [blame] | 602 | retry: |
Thomas Gleixner | a782a7e | 2015-08-02 20:38:27 +0000 | [diff] [blame] | 603 | desc = __this_cpu_read(vector_irq[vector]); |
| 604 | if (IS_ERR_OR_NULL(desc)) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 605 | continue; |
| 606 | |
Thomas Gleixner | df54c49 | 2015-08-02 20:38:23 +0000 | [diff] [blame] | 607 | if (!raw_spin_trylock(&desc->lock)) { |
| 608 | raw_spin_unlock(&vector_lock); |
| 609 | cpu_relax(); |
| 610 | raw_spin_lock(&vector_lock); |
| 611 | goto retry; |
| 612 | } |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 613 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 614 | apicd = apic_chip_data(irq_desc_get_irq_data(desc)); |
| 615 | if (!apicd) |
Thomas Gleixner | df54c49 | 2015-08-02 20:38:23 +0000 | [diff] [blame] | 616 | goto unlock; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 617 | |
| 618 | /* |
Thomas Gleixner | 98229aa | 2015-12-31 16:30:54 +0000 | [diff] [blame] | 619 | * Nothing to cleanup if irq migration is in progress |
| 620 | * or this cpu is not set in the cleanup mask. |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 621 | */ |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 622 | if (apicd->move_in_progress || |
| 623 | !cpumask_test_cpu(me, apicd->old_domain)) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 624 | goto unlock; |
| 625 | |
Thomas Gleixner | 98229aa | 2015-12-31 16:30:54 +0000 | [diff] [blame] | 626 | /* |
| 627 | * We have two cases to handle here: |
| 628 | * 1) vector is unchanged but the target mask got reduced |
| 629 | * 2) vector and the target mask has changed |
| 630 | * |
| 631 | * #1 is obvious, but in #2 we have two vectors with the same |
| 632 | * irq descriptor: the old and the new vector. So we need to |
| 633 | * make sure that we only cleanup the old vector. The new |
| 634 | * vector has the current @vector number in the config and |
| 635 | * this cpu is part of the target mask. We better leave that |
| 636 | * one alone. |
| 637 | */ |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 638 | if (vector == apicd->cfg.vector && |
| 639 | cpumask_test_cpu(me, apicd->domain)) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 640 | goto unlock; |
| 641 | |
| 642 | irr = apic_read(APIC_IRR + (vector / 32 * 0x10)); |
| 643 | /* |
| 644 | * Check if the vector that needs to be cleanedup is |
| 645 | * registered at the cpu's IRR. If so, then this is not |
| 646 | * the best time to clean it up. Lets clean it up in the |
| 647 | * next attempt by sending another IRQ_MOVE_CLEANUP_VECTOR |
| 648 | * to myself. |
| 649 | */ |
| 650 | if (irr & (1 << (vector % 32))) { |
| 651 | apic->send_IPI_self(IRQ_MOVE_CLEANUP_VECTOR); |
| 652 | goto unlock; |
| 653 | } |
Thomas Gleixner | 7276c6a | 2015-08-02 20:38:25 +0000 | [diff] [blame] | 654 | __this_cpu_write(vector_irq[vector], VECTOR_UNUSED); |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 655 | cpumask_clear_cpu(me, apicd->old_domain); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 656 | unlock: |
| 657 | raw_spin_unlock(&desc->lock); |
| 658 | } |
| 659 | |
Thomas Gleixner | df54c49 | 2015-08-02 20:38:23 +0000 | [diff] [blame] | 660 | raw_spin_unlock(&vector_lock); |
| 661 | |
Thomas Gleixner | 6af7faf | 2015-05-15 15:48:25 +0200 | [diff] [blame] | 662 | exiting_irq(); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | static void __irq_complete_move(struct irq_cfg *cfg, unsigned vector) |
| 666 | { |
| 667 | unsigned me; |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 668 | struct apic_chip_data *apicd; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 669 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 670 | apicd = container_of(cfg, struct apic_chip_data, cfg); |
| 671 | if (likely(!apicd->move_in_progress)) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 672 | return; |
| 673 | |
| 674 | me = smp_processor_id(); |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 675 | if (vector == apicd->cfg.vector && cpumask_test_cpu(me, apicd->domain)) |
| 676 | __send_cleanup_vector(apicd); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | void irq_complete_move(struct irq_cfg *cfg) |
| 680 | { |
| 681 | __irq_complete_move(cfg, ~get_irq_regs()->orig_ax); |
| 682 | } |
| 683 | |
Thomas Gleixner | 90a2282 | 2015-12-31 16:30:53 +0000 | [diff] [blame] | 684 | /* |
Thomas Gleixner | 551adc6 | 2016-03-14 09:40:46 +0100 | [diff] [blame] | 685 | * Called from fixup_irqs() with @desc->lock held and interrupts disabled. |
Thomas Gleixner | 90a2282 | 2015-12-31 16:30:53 +0000 | [diff] [blame] | 686 | */ |
| 687 | void irq_force_complete_move(struct irq_desc *desc) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 688 | { |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 689 | struct irq_data *irqd; |
| 690 | struct apic_chip_data *apicd; |
Mika Westerberg | db91aa7 | 2016-10-03 13:17:08 +0300 | [diff] [blame] | 691 | struct irq_cfg *cfg; |
Thomas Gleixner | 551adc6 | 2016-03-14 09:40:46 +0100 | [diff] [blame] | 692 | unsigned int cpu; |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 693 | |
Mika Westerberg | db91aa7 | 2016-10-03 13:17:08 +0300 | [diff] [blame] | 694 | /* |
| 695 | * The function is called for all descriptors regardless of which |
| 696 | * irqdomain they belong to. For example if an IRQ is provided by |
| 697 | * an irq_chip as part of a GPIO driver, the chip data for that |
| 698 | * descriptor is specific to the irq_chip in question. |
| 699 | * |
| 700 | * Check first that the chip_data is what we expect |
| 701 | * (apic_chip_data) before touching it any further. |
| 702 | */ |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 703 | irqd = irq_domain_get_irq_data(x86_vector_domain, |
Mika Westerberg | db91aa7 | 2016-10-03 13:17:08 +0300 | [diff] [blame] | 704 | irq_desc_get_irq(desc)); |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 705 | if (!irqd) |
Mika Westerberg | db91aa7 | 2016-10-03 13:17:08 +0300 | [diff] [blame] | 706 | return; |
| 707 | |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 708 | apicd = apic_chip_data(irqd); |
| 709 | cfg = apicd ? &apicd->cfg : NULL; |
Mika Westerberg | db91aa7 | 2016-10-03 13:17:08 +0300 | [diff] [blame] | 710 | |
Thomas Gleixner | 56d7d2f | 2015-12-31 16:30:52 +0000 | [diff] [blame] | 711 | if (!cfg) |
| 712 | return; |
| 713 | |
Thomas Gleixner | 56d7d2f | 2015-12-31 16:30:52 +0000 | [diff] [blame] | 714 | /* |
Thomas Gleixner | 98229aa | 2015-12-31 16:30:54 +0000 | [diff] [blame] | 715 | * This is tricky. If the cleanup of @data->old_domain has not been |
| 716 | * done yet, then the following setaffinity call will fail with |
| 717 | * -EBUSY. This can leave the interrupt in a stale state. |
| 718 | * |
Thomas Gleixner | 551adc6 | 2016-03-14 09:40:46 +0100 | [diff] [blame] | 719 | * All CPUs are stuck in stop machine with interrupts disabled so |
| 720 | * calling __irq_complete_move() would be completely pointless. |
Thomas Gleixner | 56d7d2f | 2015-12-31 16:30:52 +0000 | [diff] [blame] | 721 | */ |
| 722 | raw_spin_lock(&vector_lock); |
Thomas Gleixner | 551adc6 | 2016-03-14 09:40:46 +0100 | [diff] [blame] | 723 | /* |
| 724 | * Clean out all offline cpus (including the outgoing one) from the |
| 725 | * old_domain mask. |
| 726 | */ |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 727 | cpumask_and(apicd->old_domain, apicd->old_domain, cpu_online_mask); |
Thomas Gleixner | 551adc6 | 2016-03-14 09:40:46 +0100 | [diff] [blame] | 728 | |
| 729 | /* |
| 730 | * If move_in_progress is cleared and the old_domain mask is empty, |
| 731 | * then there is nothing to cleanup. fixup_irqs() will take care of |
| 732 | * the stale vectors on the outgoing cpu. |
| 733 | */ |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 734 | if (!apicd->move_in_progress && cpumask_empty(apicd->old_domain)) { |
Thomas Gleixner | 98229aa | 2015-12-31 16:30:54 +0000 | [diff] [blame] | 735 | raw_spin_unlock(&vector_lock); |
Thomas Gleixner | 551adc6 | 2016-03-14 09:40:46 +0100 | [diff] [blame] | 736 | return; |
Thomas Gleixner | 98229aa | 2015-12-31 16:30:54 +0000 | [diff] [blame] | 737 | } |
Thomas Gleixner | 551adc6 | 2016-03-14 09:40:46 +0100 | [diff] [blame] | 738 | |
| 739 | /* |
| 740 | * 1) The interrupt is in move_in_progress state. That means that we |
| 741 | * have not seen an interrupt since the io_apic was reprogrammed to |
| 742 | * the new vector. |
| 743 | * |
| 744 | * 2) The interrupt has fired on the new vector, but the cleanup IPIs |
| 745 | * have not been processed yet. |
| 746 | */ |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 747 | if (apicd->move_in_progress) { |
Thomas Gleixner | 551adc6 | 2016-03-14 09:40:46 +0100 | [diff] [blame] | 748 | /* |
| 749 | * In theory there is a race: |
| 750 | * |
| 751 | * set_ioapic(new_vector) <-- Interrupt is raised before update |
| 752 | * is effective, i.e. it's raised on |
| 753 | * the old vector. |
| 754 | * |
| 755 | * So if the target cpu cannot handle that interrupt before |
| 756 | * the old vector is cleaned up, we get a spurious interrupt |
| 757 | * and in the worst case the ioapic irq line becomes stale. |
| 758 | * |
| 759 | * But in case of cpu hotplug this should be a non issue |
| 760 | * because if the affinity update happens right before all |
| 761 | * cpus rendevouz in stop machine, there is no way that the |
| 762 | * interrupt can be blocked on the target cpu because all cpus |
| 763 | * loops first with interrupts enabled in stop machine, so the |
| 764 | * old vector is not yet cleaned up when the interrupt fires. |
| 765 | * |
| 766 | * So the only way to run into this issue is if the delivery |
| 767 | * of the interrupt on the apic/system bus would be delayed |
| 768 | * beyond the point where the target cpu disables interrupts |
| 769 | * in stop machine. I doubt that it can happen, but at least |
| 770 | * there is a theroretical chance. Virtualization might be |
| 771 | * able to expose this, but AFAICT the IOAPIC emulation is not |
| 772 | * as stupid as the real hardware. |
| 773 | * |
| 774 | * Anyway, there is nothing we can do about that at this point |
| 775 | * w/o refactoring the whole fixup_irq() business completely. |
| 776 | * We print at least the irq number and the old vector number, |
| 777 | * so we have the necessary information when a problem in that |
| 778 | * area arises. |
| 779 | */ |
| 780 | pr_warn("IRQ fixup: irq %d move in progress, old vector %d\n", |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 781 | irqd->irq, cfg->old_vector); |
Thomas Gleixner | 551adc6 | 2016-03-14 09:40:46 +0100 | [diff] [blame] | 782 | } |
| 783 | /* |
| 784 | * If old_domain is not empty, then other cpus still have the irq |
| 785 | * descriptor set in their vector array. Clean it up. |
| 786 | */ |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 787 | for_each_cpu(cpu, apicd->old_domain) |
Thomas Gleixner | 551adc6 | 2016-03-14 09:40:46 +0100 | [diff] [blame] | 788 | per_cpu(vector_irq, cpu)[cfg->old_vector] = VECTOR_UNUSED; |
| 789 | |
| 790 | /* Cleanup the left overs of the (half finished) move */ |
Thomas Gleixner | 86ba655 | 2017-09-13 23:29:30 +0200 | [diff] [blame] | 791 | cpumask_clear(apicd->old_domain); |
| 792 | apicd->move_in_progress = 0; |
Thomas Gleixner | 56d7d2f | 2015-12-31 16:30:52 +0000 | [diff] [blame] | 793 | raw_spin_unlock(&vector_lock); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 794 | } |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 795 | #endif |
| 796 | |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 797 | static void __init print_APIC_field(int base) |
| 798 | { |
| 799 | int i; |
| 800 | |
| 801 | printk(KERN_DEBUG); |
| 802 | |
| 803 | for (i = 0; i < 8; i++) |
| 804 | pr_cont("%08x", apic_read(base + i*0x10)); |
| 805 | |
| 806 | pr_cont("\n"); |
| 807 | } |
| 808 | |
| 809 | static void __init print_local_APIC(void *dummy) |
| 810 | { |
| 811 | unsigned int i, v, ver, maxlvt; |
| 812 | u64 icr; |
| 813 | |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 814 | pr_debug("printing local APIC contents on CPU#%d/%d:\n", |
| 815 | smp_processor_id(), hard_smp_processor_id()); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 816 | v = apic_read(APIC_ID); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 817 | pr_info("... APIC ID: %08x (%01x)\n", v, read_apic_id()); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 818 | v = apic_read(APIC_LVR); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 819 | pr_info("... APIC VERSION: %08x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 820 | ver = GET_APIC_VERSION(v); |
| 821 | maxlvt = lapic_get_maxlvt(); |
| 822 | |
| 823 | v = apic_read(APIC_TASKPRI); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 824 | pr_debug("... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 825 | |
| 826 | /* !82489DX */ |
| 827 | if (APIC_INTEGRATED(ver)) { |
| 828 | if (!APIC_XAPIC(ver)) { |
| 829 | v = apic_read(APIC_ARBPRI); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 830 | pr_debug("... APIC ARBPRI: %08x (%02x)\n", |
| 831 | v, v & APIC_ARBPRI_MASK); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 832 | } |
| 833 | v = apic_read(APIC_PROCPRI); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 834 | pr_debug("... APIC PROCPRI: %08x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | /* |
| 838 | * Remote read supported only in the 82489DX and local APIC for |
| 839 | * Pentium processors. |
| 840 | */ |
| 841 | if (!APIC_INTEGRATED(ver) || maxlvt == 3) { |
| 842 | v = apic_read(APIC_RRR); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 843 | pr_debug("... APIC RRR: %08x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | v = apic_read(APIC_LDR); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 847 | pr_debug("... APIC LDR: %08x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 848 | if (!x2apic_enabled()) { |
| 849 | v = apic_read(APIC_DFR); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 850 | pr_debug("... APIC DFR: %08x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 851 | } |
| 852 | v = apic_read(APIC_SPIV); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 853 | pr_debug("... APIC SPIV: %08x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 854 | |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 855 | pr_debug("... APIC ISR field:\n"); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 856 | print_APIC_field(APIC_ISR); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 857 | pr_debug("... APIC TMR field:\n"); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 858 | print_APIC_field(APIC_TMR); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 859 | pr_debug("... APIC IRR field:\n"); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 860 | print_APIC_field(APIC_IRR); |
| 861 | |
| 862 | /* !82489DX */ |
| 863 | if (APIC_INTEGRATED(ver)) { |
| 864 | /* Due to the Pentium erratum 3AP. */ |
| 865 | if (maxlvt > 3) |
| 866 | apic_write(APIC_ESR, 0); |
| 867 | |
| 868 | v = apic_read(APIC_ESR); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 869 | pr_debug("... APIC ESR: %08x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | icr = apic_icr_read(); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 873 | pr_debug("... APIC ICR: %08x\n", (u32)icr); |
| 874 | pr_debug("... APIC ICR2: %08x\n", (u32)(icr >> 32)); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 875 | |
| 876 | v = apic_read(APIC_LVTT); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 877 | pr_debug("... APIC LVTT: %08x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 878 | |
| 879 | if (maxlvt > 3) { |
| 880 | /* PC is LVT#4. */ |
| 881 | v = apic_read(APIC_LVTPC); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 882 | pr_debug("... APIC LVTPC: %08x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 883 | } |
| 884 | v = apic_read(APIC_LVT0); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 885 | pr_debug("... APIC LVT0: %08x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 886 | v = apic_read(APIC_LVT1); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 887 | pr_debug("... APIC LVT1: %08x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 888 | |
| 889 | if (maxlvt > 2) { |
| 890 | /* ERR is LVT#3. */ |
| 891 | v = apic_read(APIC_LVTERR); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 892 | pr_debug("... APIC LVTERR: %08x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | v = apic_read(APIC_TMICT); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 896 | pr_debug("... APIC TMICT: %08x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 897 | v = apic_read(APIC_TMCCT); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 898 | pr_debug("... APIC TMCCT: %08x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 899 | v = apic_read(APIC_TDCR); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 900 | pr_debug("... APIC TDCR: %08x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 901 | |
| 902 | if (boot_cpu_has(X86_FEATURE_EXTAPIC)) { |
| 903 | v = apic_read(APIC_EFEAT); |
| 904 | maxlvt = (v >> 16) & 0xff; |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 905 | pr_debug("... APIC EFEAT: %08x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 906 | v = apic_read(APIC_ECTRL); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 907 | pr_debug("... APIC ECTRL: %08x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 908 | for (i = 0; i < maxlvt; i++) { |
| 909 | v = apic_read(APIC_EILVTn(i)); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 910 | pr_debug("... APIC EILVT%d: %08x\n", i, v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 911 | } |
| 912 | } |
| 913 | pr_cont("\n"); |
| 914 | } |
| 915 | |
| 916 | static void __init print_local_APICs(int maxcpu) |
| 917 | { |
| 918 | int cpu; |
| 919 | |
| 920 | if (!maxcpu) |
| 921 | return; |
| 922 | |
| 923 | preempt_disable(); |
| 924 | for_each_online_cpu(cpu) { |
| 925 | if (cpu >= maxcpu) |
| 926 | break; |
| 927 | smp_call_function_single(cpu, print_local_APIC, NULL, 1); |
| 928 | } |
| 929 | preempt_enable(); |
| 930 | } |
| 931 | |
| 932 | static void __init print_PIC(void) |
| 933 | { |
| 934 | unsigned int v; |
| 935 | unsigned long flags; |
| 936 | |
| 937 | if (!nr_legacy_irqs()) |
| 938 | return; |
| 939 | |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 940 | pr_debug("\nprinting PIC contents\n"); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 941 | |
| 942 | raw_spin_lock_irqsave(&i8259A_lock, flags); |
| 943 | |
| 944 | v = inb(0xa1) << 8 | inb(0x21); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 945 | pr_debug("... PIC IMR: %04x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 946 | |
| 947 | v = inb(0xa0) << 8 | inb(0x20); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 948 | pr_debug("... PIC IRR: %04x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 949 | |
| 950 | outb(0x0b, 0xa0); |
| 951 | outb(0x0b, 0x20); |
| 952 | v = inb(0xa0) << 8 | inb(0x20); |
| 953 | outb(0x0a, 0xa0); |
| 954 | outb(0x0a, 0x20); |
| 955 | |
| 956 | raw_spin_unlock_irqrestore(&i8259A_lock, flags); |
| 957 | |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 958 | pr_debug("... PIC ISR: %04x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 959 | |
| 960 | v = inb(0x4d1) << 8 | inb(0x4d0); |
Jiang Liu | 849d356 | 2014-10-27 16:12:01 +0800 | [diff] [blame] | 961 | pr_debug("... PIC ELCR: %04x\n", v); |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | static int show_lapic __initdata = 1; |
| 965 | static __init int setup_show_lapic(char *arg) |
| 966 | { |
| 967 | int num = -1; |
| 968 | |
| 969 | if (strcmp(arg, "all") == 0) { |
| 970 | show_lapic = CONFIG_NR_CPUS; |
| 971 | } else { |
| 972 | get_option(&arg, &num); |
| 973 | if (num >= 0) |
| 974 | show_lapic = num; |
| 975 | } |
| 976 | |
| 977 | return 1; |
| 978 | } |
| 979 | __setup("show_lapic=", setup_show_lapic); |
| 980 | |
| 981 | static int __init print_ICs(void) |
| 982 | { |
| 983 | if (apic_verbosity == APIC_QUIET) |
| 984 | return 0; |
| 985 | |
| 986 | print_PIC(); |
| 987 | |
| 988 | /* don't print out if apic is not there */ |
Borislav Petkov | 93984fb | 2016-04-04 22:25:00 +0200 | [diff] [blame] | 989 | if (!boot_cpu_has(X86_FEATURE_APIC) && !apic_from_smp_config()) |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 990 | return 0; |
| 991 | |
| 992 | print_local_APICs(show_lapic); |
| 993 | print_IO_APICs(); |
| 994 | |
| 995 | return 0; |
| 996 | } |
| 997 | |
| 998 | late_initcall(print_ICs); |