Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 1 | #include <linux/kernel.h> |
| 2 | #include <linux/string.h> |
Joerg Roedel | 98f1ad2 | 2012-07-06 13:28:37 +0200 | [diff] [blame] | 3 | #include <linux/cpumask.h> |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 4 | #include <linux/errno.h> |
Joerg Roedel | 98f1ad2 | 2012-07-06 13:28:37 +0200 | [diff] [blame] | 5 | #include <linux/msi.h> |
| 6 | |
| 7 | #include <asm/hw_irq.h> |
| 8 | #include <asm/irq_remapping.h> |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 9 | |
Suresh Siddha | 8a8f422 | 2012-03-30 11:47:08 -0700 | [diff] [blame] | 10 | #include "irq_remapping.h" |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 11 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 12 | int irq_remapping_enabled; |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 13 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 14 | int disable_irq_remap; |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 15 | int disable_sourceid_checking; |
| 16 | int no_x2apic_optout; |
| 17 | |
| 18 | static struct irq_remap_ops *remap_ops; |
| 19 | |
| 20 | static __init int setup_nointremap(char *str) |
| 21 | { |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 22 | disable_irq_remap = 1; |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 23 | return 0; |
| 24 | } |
| 25 | early_param("nointremap", setup_nointremap); |
| 26 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 27 | static __init int setup_irqremap(char *str) |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 28 | { |
| 29 | if (!str) |
| 30 | return -EINVAL; |
| 31 | |
| 32 | while (*str) { |
| 33 | if (!strncmp(str, "on", 2)) |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 34 | disable_irq_remap = 0; |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 35 | else if (!strncmp(str, "off", 3)) |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 36 | disable_irq_remap = 1; |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 37 | else if (!strncmp(str, "nosid", 5)) |
| 38 | disable_sourceid_checking = 1; |
| 39 | else if (!strncmp(str, "no_x2apic_optout", 16)) |
| 40 | no_x2apic_optout = 1; |
| 41 | |
| 42 | str += strcspn(str, ","); |
| 43 | while (*str == ',') |
| 44 | str++; |
| 45 | } |
| 46 | |
| 47 | return 0; |
| 48 | } |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 49 | early_param("intremap", setup_irqremap); |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 50 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 51 | void __init setup_irq_remapping_ops(void) |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 52 | { |
| 53 | remap_ops = &intel_irq_remap_ops; |
| 54 | } |
| 55 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 56 | int irq_remapping_supported(void) |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 57 | { |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 58 | if (disable_irq_remap) |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 59 | return 0; |
| 60 | |
| 61 | if (!remap_ops || !remap_ops->supported) |
| 62 | return 0; |
| 63 | |
| 64 | return remap_ops->supported(); |
| 65 | } |
| 66 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 67 | int __init irq_remapping_prepare(void) |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 68 | { |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 69 | if (!remap_ops || !remap_ops->prepare) |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 70 | return -ENODEV; |
| 71 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 72 | return remap_ops->prepare(); |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 75 | int __init irq_remapping_enable(void) |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 76 | { |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 77 | if (!remap_ops || !remap_ops->enable) |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 78 | return -ENODEV; |
| 79 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 80 | return remap_ops->enable(); |
Joerg Roedel | 736baef | 2012-03-30 11:47:00 -0700 | [diff] [blame] | 81 | } |
Joerg Roedel | 4f3d8b6 | 2012-03-30 11:47:01 -0700 | [diff] [blame] | 82 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 83 | void irq_remapping_disable(void) |
Joerg Roedel | 4f3d8b6 | 2012-03-30 11:47:01 -0700 | [diff] [blame] | 84 | { |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 85 | if (!remap_ops || !remap_ops->disable) |
Joerg Roedel | 4f3d8b6 | 2012-03-30 11:47:01 -0700 | [diff] [blame] | 86 | return; |
| 87 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 88 | remap_ops->disable(); |
Joerg Roedel | 4f3d8b6 | 2012-03-30 11:47:01 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 91 | int irq_remapping_reenable(int mode) |
Joerg Roedel | 4f3d8b6 | 2012-03-30 11:47:01 -0700 | [diff] [blame] | 92 | { |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 93 | if (!remap_ops || !remap_ops->reenable) |
Joerg Roedel | 4f3d8b6 | 2012-03-30 11:47:01 -0700 | [diff] [blame] | 94 | return 0; |
| 95 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 96 | return remap_ops->reenable(mode); |
Joerg Roedel | 4f3d8b6 | 2012-03-30 11:47:01 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 99 | int __init irq_remap_enable_fault_handling(void) |
Joerg Roedel | 4f3d8b6 | 2012-03-30 11:47:01 -0700 | [diff] [blame] | 100 | { |
| 101 | if (!remap_ops || !remap_ops->enable_faulting) |
| 102 | return -ENODEV; |
| 103 | |
| 104 | return remap_ops->enable_faulting(); |
| 105 | } |
Joerg Roedel | 0c3f173 | 2012-03-30 11:47:02 -0700 | [diff] [blame] | 106 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 107 | int setup_ioapic_remapped_entry(int irq, |
| 108 | struct IO_APIC_route_entry *entry, |
| 109 | unsigned int destination, int vector, |
| 110 | struct io_apic_irq_attr *attr) |
Joerg Roedel | 0c3f173 | 2012-03-30 11:47:02 -0700 | [diff] [blame] | 111 | { |
| 112 | if (!remap_ops || !remap_ops->setup_ioapic_entry) |
| 113 | return -ENODEV; |
| 114 | |
| 115 | return remap_ops->setup_ioapic_entry(irq, entry, destination, |
| 116 | vector, attr); |
| 117 | } |
Joerg Roedel | 4c1bad6 | 2012-03-30 11:47:03 -0700 | [diff] [blame] | 118 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 119 | int set_remapped_irq_affinity(struct irq_data *data, const struct cpumask *mask, |
| 120 | bool force) |
Joerg Roedel | 4c1bad6 | 2012-03-30 11:47:03 -0700 | [diff] [blame] | 121 | { |
Suresh Siddha | 7eb9ae0 | 2012-06-14 18:28:49 -0700 | [diff] [blame] | 122 | if (!config_enabled(CONFIG_SMP) || !remap_ops || |
| 123 | !remap_ops->set_affinity) |
Joerg Roedel | 4c1bad6 | 2012-03-30 11:47:03 -0700 | [diff] [blame] | 124 | return 0; |
| 125 | |
| 126 | return remap_ops->set_affinity(data, mask, force); |
| 127 | } |
Joerg Roedel | 9d619f6 | 2012-03-30 11:47:04 -0700 | [diff] [blame] | 128 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 129 | void free_remapped_irq(int irq) |
Joerg Roedel | 9d619f6 | 2012-03-30 11:47:04 -0700 | [diff] [blame] | 130 | { |
| 131 | if (!remap_ops || !remap_ops->free_irq) |
| 132 | return; |
| 133 | |
| 134 | remap_ops->free_irq(irq); |
| 135 | } |
Joerg Roedel | 5e2b930 | 2012-03-30 11:47:05 -0700 | [diff] [blame] | 136 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 137 | void compose_remapped_msi_msg(struct pci_dev *pdev, |
| 138 | unsigned int irq, unsigned int dest, |
| 139 | struct msi_msg *msg, u8 hpet_id) |
Joerg Roedel | 5e2b930 | 2012-03-30 11:47:05 -0700 | [diff] [blame] | 140 | { |
| 141 | if (!remap_ops || !remap_ops->compose_msi_msg) |
| 142 | return; |
| 143 | |
| 144 | remap_ops->compose_msi_msg(pdev, irq, dest, msg, hpet_id); |
| 145 | } |
| 146 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 147 | int msi_alloc_remapped_irq(struct pci_dev *pdev, int irq, int nvec) |
Joerg Roedel | 5e2b930 | 2012-03-30 11:47:05 -0700 | [diff] [blame] | 148 | { |
| 149 | if (!remap_ops || !remap_ops->msi_alloc_irq) |
| 150 | return -ENODEV; |
| 151 | |
| 152 | return remap_ops->msi_alloc_irq(pdev, irq, nvec); |
| 153 | } |
| 154 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 155 | int msi_setup_remapped_irq(struct pci_dev *pdev, unsigned int irq, |
| 156 | int index, int sub_handle) |
Joerg Roedel | 5e2b930 | 2012-03-30 11:47:05 -0700 | [diff] [blame] | 157 | { |
| 158 | if (!remap_ops || !remap_ops->msi_setup_irq) |
| 159 | return -ENODEV; |
| 160 | |
| 161 | return remap_ops->msi_setup_irq(pdev, irq, index, sub_handle); |
| 162 | } |
| 163 | |
Suresh Siddha | 95a02e9 | 2012-03-30 11:47:07 -0700 | [diff] [blame] | 164 | int setup_hpet_msi_remapped(unsigned int irq, unsigned int id) |
Joerg Roedel | 5e2b930 | 2012-03-30 11:47:05 -0700 | [diff] [blame] | 165 | { |
| 166 | if (!remap_ops || !remap_ops->setup_hpet_msi) |
| 167 | return -ENODEV; |
| 168 | |
| 169 | return remap_ops->setup_hpet_msi(irq, id); |
| 170 | } |