Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Jiang Liu | 4438098 | 2014-10-27 16:12:02 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Support of MSI, HPET and DMAR interrupts. |
| 4 | * |
| 5 | * Copyright (C) 1997, 1998, 1999, 2000, 2009 Ingo Molnar, Hajnalka Szabo |
| 6 | * Moved from arch/x86/kernel/apic/io_apic.c. |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 7 | * Jiang Liu <jiang.liu@linux.intel.com> |
| 8 | * Convert to hierarchical irqdomain |
Jiang Liu | 4438098 | 2014-10-27 16:12:02 +0800 | [diff] [blame] | 9 | */ |
| 10 | #include <linux/mm.h> |
| 11 | #include <linux/interrupt.h> |
Nicolai Stange | 447ae31 | 2018-07-29 12:15:33 +0200 | [diff] [blame] | 12 | #include <linux/irq.h> |
Jiang Liu | 4438098 | 2014-10-27 16:12:02 +0800 | [diff] [blame] | 13 | #include <linux/pci.h> |
| 14 | #include <linux/dmar.h> |
| 15 | #include <linux/hpet.h> |
| 16 | #include <linux/msi.h> |
Jiang Liu | d746d1e | 2015-04-14 10:30:09 +0800 | [diff] [blame] | 17 | #include <asm/irqdomain.h> |
Jiang Liu | 4438098 | 2014-10-27 16:12:02 +0800 | [diff] [blame] | 18 | #include <asm/hpet.h> |
| 19 | #include <asm/hw_irq.h> |
| 20 | #include <asm/apic.h> |
| 21 | #include <asm/irq_remapping.h> |
Thomas Gleixner | ae72f31 | 2021-12-06 23:27:42 +0100 | [diff] [blame] | 22 | #include <asm/xen/hypervisor.h> |
Jiang Liu | 4438098 | 2014-10-27 16:12:02 +0800 | [diff] [blame] | 23 | |
Thomas Gleixner | 2c681e6 | 2020-08-26 13:17:01 +0200 | [diff] [blame] | 24 | struct irq_domain *x86_pci_msi_default_domain __ro_after_init; |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 25 | |
Thomas Gleixner | 6f1a489 | 2020-01-31 15:26:52 +0100 | [diff] [blame] | 26 | static void irq_msi_update_msg(struct irq_data *irqd, struct irq_cfg *cfg) |
| 27 | { |
| 28 | struct msi_msg msg[2] = { [1] = { }, }; |
| 29 | |
David Woodhouse | 47bea87 | 2020-10-24 22:35:02 +0100 | [diff] [blame] | 30 | __irq_msi_compose_msg(cfg, msg, false); |
Thomas Gleixner | 6f1a489 | 2020-01-31 15:26:52 +0100 | [diff] [blame] | 31 | irq_data_get_irq_chip(irqd)->irq_write_msi_msg(irqd, msg); |
| 32 | } |
| 33 | |
| 34 | static int |
| 35 | msi_set_affinity(struct irq_data *irqd, const struct cpumask *mask, bool force) |
| 36 | { |
| 37 | struct irq_cfg old_cfg, *cfg = irqd_cfg(irqd); |
| 38 | struct irq_data *parent = irqd->parent_data; |
| 39 | unsigned int cpu; |
| 40 | int ret; |
| 41 | |
| 42 | /* Save the current configuration */ |
| 43 | cpu = cpumask_first(irq_data_get_effective_affinity_mask(irqd)); |
| 44 | old_cfg = *cfg; |
| 45 | |
| 46 | /* Allocate a new target vector */ |
| 47 | ret = parent->chip->irq_set_affinity(parent, mask, force); |
| 48 | if (ret < 0 || ret == IRQ_SET_MASK_OK_DONE) |
| 49 | return ret; |
| 50 | |
| 51 | /* |
| 52 | * For non-maskable and non-remapped MSI interrupts the migration |
| 53 | * to a different destination CPU and a different vector has to be |
| 54 | * done careful to handle the possible stray interrupt which can be |
| 55 | * caused by the non-atomic update of the address/data pair. |
| 56 | * |
| 57 | * Direct update is possible when: |
| 58 | * - The MSI is maskable (remapped MSI does not use this code path)). |
| 59 | * The quirk bit is not set in this case. |
| 60 | * - The new vector is the same as the old vector |
| 61 | * - The old vector is MANAGED_IRQ_SHUTDOWN_VECTOR (interrupt starts up) |
Thomas Gleixner | ff363f4 | 2021-07-29 23:51:50 +0200 | [diff] [blame] | 62 | * - The interrupt is not yet started up |
Thomas Gleixner | 6f1a489 | 2020-01-31 15:26:52 +0100 | [diff] [blame] | 63 | * - The new destination CPU is the same as the old destination CPU |
| 64 | */ |
| 65 | if (!irqd_msi_nomask_quirk(irqd) || |
| 66 | cfg->vector == old_cfg.vector || |
| 67 | old_cfg.vector == MANAGED_IRQ_SHUTDOWN_VECTOR || |
Thomas Gleixner | ff363f4 | 2021-07-29 23:51:50 +0200 | [diff] [blame] | 68 | !irqd_is_started(irqd) || |
Thomas Gleixner | 6f1a489 | 2020-01-31 15:26:52 +0100 | [diff] [blame] | 69 | cfg->dest_apicid == old_cfg.dest_apicid) { |
| 70 | irq_msi_update_msg(irqd, cfg); |
| 71 | return ret; |
| 72 | } |
| 73 | |
| 74 | /* |
| 75 | * Paranoia: Validate that the interrupt target is the local |
| 76 | * CPU. |
| 77 | */ |
| 78 | if (WARN_ON_ONCE(cpu != smp_processor_id())) { |
| 79 | irq_msi_update_msg(irqd, cfg); |
| 80 | return ret; |
| 81 | } |
| 82 | |
| 83 | /* |
| 84 | * Redirect the interrupt to the new vector on the current CPU |
| 85 | * first. This might cause a spurious interrupt on this vector if |
| 86 | * the device raises an interrupt right between this update and the |
| 87 | * update to the final destination CPU. |
| 88 | * |
| 89 | * If the vector is in use then the installed device handler will |
| 90 | * denote it as spurious which is no harm as this is a rare event |
| 91 | * and interrupt handlers have to cope with spurious interrupts |
| 92 | * anyway. If the vector is unused, then it is marked so it won't |
Thomas Gleixner | fa5e5c4 | 2020-05-21 22:05:37 +0200 | [diff] [blame] | 93 | * trigger the 'No irq handler for vector' warning in |
| 94 | * common_interrupt(). |
Thomas Gleixner | 6f1a489 | 2020-01-31 15:26:52 +0100 | [diff] [blame] | 95 | * |
| 96 | * This requires to hold vector lock to prevent concurrent updates to |
| 97 | * the affected vector. |
| 98 | */ |
| 99 | lock_vector_lock(); |
| 100 | |
| 101 | /* |
| 102 | * Mark the new target vector on the local CPU if it is currently |
| 103 | * unused. Reuse the VECTOR_RETRIGGERED state which is also used in |
| 104 | * the CPU hotplug path for a similar purpose. This cannot be |
| 105 | * undone here as the current CPU has interrupts disabled and |
| 106 | * cannot handle the interrupt before the whole set_affinity() |
| 107 | * section is done. In the CPU unplug case, the current CPU is |
| 108 | * about to vanish and will not handle any interrupts anymore. The |
| 109 | * vector is cleaned up when the CPU comes online again. |
| 110 | */ |
| 111 | if (IS_ERR_OR_NULL(this_cpu_read(vector_irq[cfg->vector]))) |
| 112 | this_cpu_write(vector_irq[cfg->vector], VECTOR_RETRIGGERED); |
| 113 | |
| 114 | /* Redirect it to the new vector on the local CPU temporarily */ |
| 115 | old_cfg.vector = cfg->vector; |
| 116 | irq_msi_update_msg(irqd, &old_cfg); |
| 117 | |
| 118 | /* Now transition it to the target CPU */ |
| 119 | irq_msi_update_msg(irqd, cfg); |
| 120 | |
| 121 | /* |
| 122 | * All interrupts after this point are now targeted at the new |
| 123 | * vector/CPU. |
| 124 | * |
| 125 | * Drop vector lock before testing whether the temporary assignment |
| 126 | * to the local CPU was hit by an interrupt raised in the device, |
| 127 | * because the retrigger function acquires vector lock again. |
| 128 | */ |
| 129 | unlock_vector_lock(); |
| 130 | |
| 131 | /* |
| 132 | * Check whether the transition raced with a device interrupt and |
| 133 | * is pending in the local APICs IRR. It is safe to do this outside |
| 134 | * of vector lock as the irq_desc::lock of this interrupt is still |
| 135 | * held and interrupts are disabled: The check is not accessing the |
| 136 | * underlying vector store. It's just checking the local APIC's |
| 137 | * IRR. |
| 138 | */ |
| 139 | if (lapic_vector_set_in_irr(cfg->vector)) |
| 140 | irq_data_get_irq_chip(irqd)->irq_retrigger(irqd); |
| 141 | |
| 142 | return ret; |
| 143 | } |
| 144 | |
Jiang Liu | 4438098 | 2014-10-27 16:12:02 +0800 | [diff] [blame] | 145 | /* |
| 146 | * IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices, |
| 147 | * which implement the MSI or MSI-X Capability Structure. |
| 148 | */ |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 149 | static struct irq_chip pci_msi_controller = { |
Jiang Liu | 4438098 | 2014-10-27 16:12:02 +0800 | [diff] [blame] | 150 | .name = "PCI-MSI", |
| 151 | .irq_unmask = pci_msi_unmask_irq, |
| 152 | .irq_mask = pci_msi_mask_irq, |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 153 | .irq_ack = irq_chip_ack_parent, |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 154 | .irq_retrigger = irq_chip_retrigger_hierarchy, |
Thomas Gleixner | 6f1a489 | 2020-01-31 15:26:52 +0100 | [diff] [blame] | 155 | .irq_set_affinity = msi_set_affinity, |
Thomas Gleixner | ff363f4 | 2021-07-29 23:51:50 +0200 | [diff] [blame] | 156 | .flags = IRQCHIP_SKIP_SET_WAKE | |
| 157 | IRQCHIP_AFFINITY_PRE_STARTUP, |
Jiang Liu | 4438098 | 2014-10-27 16:12:02 +0800 | [diff] [blame] | 158 | }; |
| 159 | |
Jake Oshins | c8f3e51 | 2015-12-10 17:52:59 +0000 | [diff] [blame] | 160 | int pci_msi_prepare(struct irq_domain *domain, struct device *dev, int nvec, |
| 161 | msi_alloc_info_t *arg) |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 162 | { |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 163 | init_irq_alloc_info(arg, NULL); |
Thomas Gleixner | b3f8236 | 2021-12-10 23:18:47 +0100 | [diff] [blame] | 164 | if (to_pci_dev(dev)->msix_enabled) { |
Thomas Gleixner | 801b5e4 | 2020-08-26 13:16:35 +0200 | [diff] [blame] | 165 | arg->type = X86_IRQ_ALLOC_TYPE_PCI_MSIX; |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 166 | } else { |
Thomas Gleixner | 801b5e4 | 2020-08-26 13:16:35 +0200 | [diff] [blame] | 167 | arg->type = X86_IRQ_ALLOC_TYPE_PCI_MSI; |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 168 | arg->flags |= X86_IRQ_ALLOC_CONTIGUOUS_VECTORS; |
| 169 | } |
| 170 | |
| 171 | return 0; |
| 172 | } |
Jake Oshins | c8f3e51 | 2015-12-10 17:52:59 +0000 | [diff] [blame] | 173 | EXPORT_SYMBOL_GPL(pci_msi_prepare); |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 174 | |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 175 | static struct msi_domain_ops pci_msi_domain_ops = { |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 176 | .msi_prepare = pci_msi_prepare, |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | static struct msi_domain_info pci_msi_domain_info = { |
| 180 | .flags = MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS | |
Jiang Liu | 68682a2 | 2015-04-13 14:11:46 +0800 | [diff] [blame] | 181 | MSI_FLAG_PCI_MSIX, |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 182 | .ops = &pci_msi_domain_ops, |
| 183 | .chip = &pci_msi_controller, |
| 184 | .handler = handle_edge_irq, |
| 185 | .handler_name = "edge", |
| 186 | }; |
| 187 | |
Thomas Gleixner | 6b15ffa | 2020-08-26 13:16:50 +0200 | [diff] [blame] | 188 | struct irq_domain * __init native_create_pci_msi_domain(void) |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 189 | { |
Thomas Gleixner | f8f37ca | 2017-06-20 01:37:14 +0200 | [diff] [blame] | 190 | struct fwnode_handle *fn; |
Thomas Gleixner | 6b15ffa | 2020-08-26 13:16:50 +0200 | [diff] [blame] | 191 | struct irq_domain *d; |
Thomas Gleixner | f8f37ca | 2017-06-20 01:37:14 +0200 | [diff] [blame] | 192 | |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 193 | if (disable_apic) |
Thomas Gleixner | 6b15ffa | 2020-08-26 13:16:50 +0200 | [diff] [blame] | 194 | return NULL; |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 195 | |
Thomas Gleixner | f8f37ca | 2017-06-20 01:37:14 +0200 | [diff] [blame] | 196 | fn = irq_domain_alloc_named_fwnode("PCI-MSI"); |
Thomas Gleixner | 6b15ffa | 2020-08-26 13:16:50 +0200 | [diff] [blame] | 197 | if (!fn) |
| 198 | return NULL; |
| 199 | |
| 200 | d = pci_msi_create_irq_domain(fn, &pci_msi_domain_info, |
| 201 | x86_vector_domain); |
| 202 | if (!d) { |
Thomas Gleixner | e3beca48 | 2020-07-09 11:53:06 +0200 | [diff] [blame] | 203 | irq_domain_free_fwnode(fn); |
Thomas Gleixner | 6b15ffa | 2020-08-26 13:16:50 +0200 | [diff] [blame] | 204 | pr_warn("Failed to initialize PCI-MSI irqdomain.\n"); |
Thomas Gleixner | e3beca48 | 2020-07-09 11:53:06 +0200 | [diff] [blame] | 205 | } else { |
Thomas Gleixner | 6b15ffa | 2020-08-26 13:16:50 +0200 | [diff] [blame] | 206 | d->flags |= IRQ_DOMAIN_MSI_NOMASK_QUIRK; |
Thomas Gleixner | e3beca48 | 2020-07-09 11:53:06 +0200 | [diff] [blame] | 207 | } |
Thomas Gleixner | 6b15ffa | 2020-08-26 13:16:50 +0200 | [diff] [blame] | 208 | return d; |
| 209 | } |
| 210 | |
| 211 | void __init x86_create_pci_msi_domain(void) |
| 212 | { |
| 213 | x86_pci_msi_default_domain = x86_init.irqs.create_pci_msi_domain(); |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | #ifdef CONFIG_IRQ_REMAP |
Jiang Liu | 68682a2 | 2015-04-13 14:11:46 +0800 | [diff] [blame] | 217 | static struct irq_chip pci_msi_ir_controller = { |
| 218 | .name = "IR-PCI-MSI", |
| 219 | .irq_unmask = pci_msi_unmask_irq, |
| 220 | .irq_mask = pci_msi_mask_irq, |
| 221 | .irq_ack = irq_chip_ack_parent, |
Jiang Liu | 68682a2 | 2015-04-13 14:11:46 +0800 | [diff] [blame] | 222 | .irq_retrigger = irq_chip_retrigger_hierarchy, |
Thomas Gleixner | ff363f4 | 2021-07-29 23:51:50 +0200 | [diff] [blame] | 223 | .flags = IRQCHIP_SKIP_SET_WAKE | |
| 224 | IRQCHIP_AFFINITY_PRE_STARTUP, |
Jiang Liu | 68682a2 | 2015-04-13 14:11:46 +0800 | [diff] [blame] | 225 | }; |
| 226 | |
| 227 | static struct msi_domain_info pci_msi_ir_domain_info = { |
| 228 | .flags = MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS | |
| 229 | MSI_FLAG_MULTI_PCI_MSI | MSI_FLAG_PCI_MSIX, |
| 230 | .ops = &pci_msi_domain_ops, |
| 231 | .chip = &pci_msi_ir_controller, |
| 232 | .handler = handle_edge_irq, |
| 233 | .handler_name = "edge", |
| 234 | }; |
| 235 | |
Thomas Gleixner | 667724c | 2017-06-20 01:37:10 +0200 | [diff] [blame] | 236 | struct irq_domain *arch_create_remap_msi_irq_domain(struct irq_domain *parent, |
| 237 | const char *name, int id) |
| 238 | { |
| 239 | struct fwnode_handle *fn; |
| 240 | struct irq_domain *d; |
| 241 | |
| 242 | fn = irq_domain_alloc_named_id_fwnode(name, id); |
| 243 | if (!fn) |
| 244 | return NULL; |
| 245 | d = pci_msi_create_irq_domain(fn, &pci_msi_ir_domain_info, parent); |
Thomas Gleixner | e3beca48 | 2020-07-09 11:53:06 +0200 | [diff] [blame] | 246 | if (!d) |
| 247 | irq_domain_free_fwnode(fn); |
Thomas Gleixner | 667724c | 2017-06-20 01:37:10 +0200 | [diff] [blame] | 248 | return d; |
| 249 | } |
Jiang Liu | 52f518a | 2015-04-13 14:11:35 +0800 | [diff] [blame] | 250 | #endif |
| 251 | |
Jiang Liu | 4438098 | 2014-10-27 16:12:02 +0800 | [diff] [blame] | 252 | #ifdef CONFIG_DMAR_TABLE |
David Woodhouse | 47bea87 | 2020-10-24 22:35:02 +0100 | [diff] [blame] | 253 | /* |
| 254 | * The Intel IOMMU (ab)uses the high bits of the MSI address to contain the |
| 255 | * high bits of the destination APIC ID. This can't be done in the general |
| 256 | * case for MSIs as it would be targeting real memory above 4GiB not the |
| 257 | * APIC. |
| 258 | */ |
| 259 | static void dmar_msi_compose_msg(struct irq_data *data, struct msi_msg *msg) |
| 260 | { |
| 261 | __irq_msi_compose_msg(irqd_cfg(data), msg, true); |
| 262 | } |
| 263 | |
Jiang Liu | 62ac178 | 2015-04-13 14:11:48 +0800 | [diff] [blame] | 264 | static void dmar_msi_write_msg(struct irq_data *data, struct msi_msg *msg) |
| 265 | { |
| 266 | dmar_msi_write(data->irq, msg); |
| 267 | } |
| 268 | |
Jiang Liu | 0921f1d | 2015-04-13 14:11:42 +0800 | [diff] [blame] | 269 | static struct irq_chip dmar_msi_controller = { |
Jiang Liu | 81dabe2 | 2015-04-13 14:11:45 +0800 | [diff] [blame] | 270 | .name = "DMAR-MSI", |
Jiang Liu | 4438098 | 2014-10-27 16:12:02 +0800 | [diff] [blame] | 271 | .irq_unmask = dmar_msi_unmask, |
| 272 | .irq_mask = dmar_msi_mask, |
Jiang Liu | 0921f1d | 2015-04-13 14:11:42 +0800 | [diff] [blame] | 273 | .irq_ack = irq_chip_ack_parent, |
Jiang Liu | e390d89 | 2015-04-13 14:11:49 +0800 | [diff] [blame] | 274 | .irq_set_affinity = msi_domain_set_affinity, |
Jiang Liu | 0921f1d | 2015-04-13 14:11:42 +0800 | [diff] [blame] | 275 | .irq_retrigger = irq_chip_retrigger_hierarchy, |
David Woodhouse | 47bea87 | 2020-10-24 22:35:02 +0100 | [diff] [blame] | 276 | .irq_compose_msi_msg = dmar_msi_compose_msg, |
Jiang Liu | 62ac178 | 2015-04-13 14:11:48 +0800 | [diff] [blame] | 277 | .irq_write_msi_msg = dmar_msi_write_msg, |
Thomas Gleixner | ff363f4 | 2021-07-29 23:51:50 +0200 | [diff] [blame] | 278 | .flags = IRQCHIP_SKIP_SET_WAKE | |
| 279 | IRQCHIP_AFFINITY_PRE_STARTUP, |
Jiang Liu | 4438098 | 2014-10-27 16:12:02 +0800 | [diff] [blame] | 280 | }; |
| 281 | |
Jiang Liu | e390d89 | 2015-04-13 14:11:49 +0800 | [diff] [blame] | 282 | static int dmar_msi_init(struct irq_domain *domain, |
| 283 | struct msi_domain_info *info, unsigned int virq, |
| 284 | irq_hw_number_t hwirq, msi_alloc_info_t *arg) |
Jiang Liu | 0921f1d | 2015-04-13 14:11:42 +0800 | [diff] [blame] | 285 | { |
Thomas Gleixner | 55e0391 | 2020-08-26 13:16:43 +0200 | [diff] [blame] | 286 | irq_domain_set_info(domain, virq, arg->devid, info->chip, NULL, |
| 287 | handle_edge_irq, arg->data, "edge"); |
Jiang Liu | e390d89 | 2015-04-13 14:11:49 +0800 | [diff] [blame] | 288 | |
| 289 | return 0; |
Jiang Liu | 0921f1d | 2015-04-13 14:11:42 +0800 | [diff] [blame] | 290 | } |
| 291 | |
Jiang Liu | e390d89 | 2015-04-13 14:11:49 +0800 | [diff] [blame] | 292 | static struct msi_domain_ops dmar_msi_domain_ops = { |
Jiang Liu | e390d89 | 2015-04-13 14:11:49 +0800 | [diff] [blame] | 293 | .msi_init = dmar_msi_init, |
| 294 | }; |
Jiang Liu | 0921f1d | 2015-04-13 14:11:42 +0800 | [diff] [blame] | 295 | |
Jiang Liu | e390d89 | 2015-04-13 14:11:49 +0800 | [diff] [blame] | 296 | static struct msi_domain_info dmar_msi_domain_info = { |
| 297 | .ops = &dmar_msi_domain_ops, |
| 298 | .chip = &dmar_msi_controller, |
Thomas Gleixner | d27e623 | 2020-09-27 10:46:44 +0200 | [diff] [blame] | 299 | .flags = MSI_FLAG_USE_DEF_DOM_OPS, |
Jiang Liu | 0921f1d | 2015-04-13 14:11:42 +0800 | [diff] [blame] | 300 | }; |
| 301 | |
| 302 | static struct irq_domain *dmar_get_irq_domain(void) |
| 303 | { |
| 304 | static struct irq_domain *dmar_domain; |
| 305 | static DEFINE_MUTEX(dmar_lock); |
Thomas Gleixner | f8f37ca | 2017-06-20 01:37:14 +0200 | [diff] [blame] | 306 | struct fwnode_handle *fn; |
Jiang Liu | 0921f1d | 2015-04-13 14:11:42 +0800 | [diff] [blame] | 307 | |
| 308 | mutex_lock(&dmar_lock); |
Thomas Gleixner | f8f37ca | 2017-06-20 01:37:14 +0200 | [diff] [blame] | 309 | if (dmar_domain) |
| 310 | goto out; |
Jiang Liu | 0921f1d | 2015-04-13 14:11:42 +0800 | [diff] [blame] | 311 | |
Thomas Gleixner | f8f37ca | 2017-06-20 01:37:14 +0200 | [diff] [blame] | 312 | fn = irq_domain_alloc_named_fwnode("DMAR-MSI"); |
| 313 | if (fn) { |
| 314 | dmar_domain = msi_create_irq_domain(fn, &dmar_msi_domain_info, |
| 315 | x86_vector_domain); |
Thomas Gleixner | e3beca48 | 2020-07-09 11:53:06 +0200 | [diff] [blame] | 316 | if (!dmar_domain) |
| 317 | irq_domain_free_fwnode(fn); |
Thomas Gleixner | f8f37ca | 2017-06-20 01:37:14 +0200 | [diff] [blame] | 318 | } |
| 319 | out: |
| 320 | mutex_unlock(&dmar_lock); |
Jiang Liu | 0921f1d | 2015-04-13 14:11:42 +0800 | [diff] [blame] | 321 | return dmar_domain; |
| 322 | } |
| 323 | |
| 324 | int dmar_alloc_hwirq(int id, int node, void *arg) |
| 325 | { |
| 326 | struct irq_domain *domain = dmar_get_irq_domain(); |
| 327 | struct irq_alloc_info info; |
| 328 | |
| 329 | if (!domain) |
| 330 | return -1; |
| 331 | |
| 332 | init_irq_alloc_info(&info, NULL); |
| 333 | info.type = X86_IRQ_ALLOC_TYPE_DMAR; |
Thomas Gleixner | 55e0391 | 2020-08-26 13:16:43 +0200 | [diff] [blame] | 334 | info.devid = id; |
Thomas Gleixner | 9006c13 | 2020-08-26 13:16:47 +0200 | [diff] [blame] | 335 | info.hwirq = id; |
Thomas Gleixner | 55e0391 | 2020-08-26 13:16:43 +0200 | [diff] [blame] | 336 | info.data = arg; |
Jiang Liu | 0921f1d | 2015-04-13 14:11:42 +0800 | [diff] [blame] | 337 | |
| 338 | return irq_domain_alloc_irqs(domain, 1, node, &info); |
Jiang Liu | a62b32c | 2015-04-13 14:11:29 +0800 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | void dmar_free_hwirq(int irq) |
| 342 | { |
| 343 | irq_domain_free_irqs(irq, 1); |
| 344 | } |
Jiang Liu | 4438098 | 2014-10-27 16:12:02 +0800 | [diff] [blame] | 345 | #endif |
Thomas Gleixner | ae72f31 | 2021-12-06 23:27:42 +0100 | [diff] [blame] | 346 | |
| 347 | bool arch_restore_msi_irqs(struct pci_dev *dev) |
| 348 | { |
| 349 | return xen_initdom_restore_msi(dev); |
| 350 | } |