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