Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * File: msi.c |
| 3 | * Purpose: PCI Message Signaled Interrupt (MSI) |
| 4 | * |
| 5 | * Copyright (C) 2003-2004 Intel |
| 6 | * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com) |
| 7 | */ |
| 8 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 9 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/mm.h> |
| 11 | #include <linux/irq.h> |
| 12 | #include <linux/interrupt.h> |
| 13 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/ioport.h> |
| 15 | #include <linux/smp_lock.h> |
| 16 | #include <linux/pci.h> |
| 17 | #include <linux/proc_fs.h> |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 18 | #include <linux/msi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | #include <asm/errno.h> |
| 21 | #include <asm/io.h> |
| 22 | #include <asm/smp.h> |
| 23 | |
| 24 | #include "pci.h" |
| 25 | #include "msi.h" |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | static struct msi_desc* msi_desc[NR_IRQS] = { [0 ... NR_IRQS-1] = NULL }; |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 28 | static struct kmem_cache* msi_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | static int pci_msi_enable = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | static int msi_cache_init(void) |
| 33 | { |
Pekka J Enberg | 5718178 | 2006-09-27 01:51:03 -0700 | [diff] [blame] | 34 | msi_cachep = kmem_cache_create("msi_cache", sizeof(struct msi_desc), |
| 35 | 0, SLAB_HWCACHE_ALIGN, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | if (!msi_cachep) |
| 37 | return -ENOMEM; |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 42 | static void msi_set_mask_bit(unsigned int irq, int flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | { |
| 44 | struct msi_desc *entry; |
| 45 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 46 | entry = msi_desc[irq]; |
Eric W. Biederman | 277bc33 | 2006-10-04 02:16:57 -0700 | [diff] [blame] | 47 | BUG_ON(!entry || !entry->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | switch (entry->msi_attrib.type) { |
| 49 | case PCI_CAP_ID_MSI: |
Eric W. Biederman | 277bc33 | 2006-10-04 02:16:57 -0700 | [diff] [blame] | 50 | if (entry->msi_attrib.maskbit) { |
Satoru Takeuchi | c54c187 | 2007-01-18 13:50:05 +0900 | [diff] [blame] | 51 | int pos; |
| 52 | u32 mask_bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Eric W. Biederman | 277bc33 | 2006-10-04 02:16:57 -0700 | [diff] [blame] | 54 | pos = (long)entry->mask_base; |
| 55 | pci_read_config_dword(entry->dev, pos, &mask_bits); |
| 56 | mask_bits &= ~(1); |
| 57 | mask_bits |= flag; |
| 58 | pci_write_config_dword(entry->dev, pos, mask_bits); |
| 59 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | case PCI_CAP_ID_MSIX: |
| 62 | { |
| 63 | int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE + |
| 64 | PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET; |
| 65 | writel(flag, entry->mask_base + offset); |
| 66 | break; |
| 67 | } |
| 68 | default: |
Eric W. Biederman | 277bc33 | 2006-10-04 02:16:57 -0700 | [diff] [blame] | 69 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | break; |
| 71 | } |
| 72 | } |
| 73 | |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 74 | void read_msi_msg(unsigned int irq, struct msi_msg *msg) |
Eric W. Biederman | 0366f8f | 2006-10-04 02:16:33 -0700 | [diff] [blame] | 75 | { |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 76 | struct msi_desc *entry = get_irq_data(irq); |
Eric W. Biederman | 0366f8f | 2006-10-04 02:16:33 -0700 | [diff] [blame] | 77 | switch(entry->msi_attrib.type) { |
| 78 | case PCI_CAP_ID_MSI: |
| 79 | { |
| 80 | struct pci_dev *dev = entry->dev; |
| 81 | int pos = entry->msi_attrib.pos; |
| 82 | u16 data; |
| 83 | |
| 84 | pci_read_config_dword(dev, msi_lower_address_reg(pos), |
| 85 | &msg->address_lo); |
| 86 | if (entry->msi_attrib.is_64) { |
| 87 | pci_read_config_dword(dev, msi_upper_address_reg(pos), |
| 88 | &msg->address_hi); |
| 89 | pci_read_config_word(dev, msi_data_reg(pos, 1), &data); |
| 90 | } else { |
| 91 | msg->address_hi = 0; |
| 92 | pci_read_config_word(dev, msi_data_reg(pos, 1), &data); |
| 93 | } |
| 94 | msg->data = data; |
| 95 | break; |
| 96 | } |
| 97 | case PCI_CAP_ID_MSIX: |
| 98 | { |
| 99 | void __iomem *base; |
| 100 | base = entry->mask_base + |
| 101 | entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE; |
| 102 | |
| 103 | msg->address_lo = readl(base + PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET); |
| 104 | msg->address_hi = readl(base + PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET); |
| 105 | msg->data = readl(base + PCI_MSIX_ENTRY_DATA_OFFSET); |
| 106 | break; |
| 107 | } |
| 108 | default: |
| 109 | BUG(); |
| 110 | } |
| 111 | } |
| 112 | |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 113 | void write_msi_msg(unsigned int irq, struct msi_msg *msg) |
Eric W. Biederman | 0366f8f | 2006-10-04 02:16:33 -0700 | [diff] [blame] | 114 | { |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 115 | struct msi_desc *entry = get_irq_data(irq); |
Eric W. Biederman | 0366f8f | 2006-10-04 02:16:33 -0700 | [diff] [blame] | 116 | switch (entry->msi_attrib.type) { |
| 117 | case PCI_CAP_ID_MSI: |
| 118 | { |
| 119 | struct pci_dev *dev = entry->dev; |
| 120 | int pos = entry->msi_attrib.pos; |
| 121 | |
| 122 | pci_write_config_dword(dev, msi_lower_address_reg(pos), |
| 123 | msg->address_lo); |
| 124 | if (entry->msi_attrib.is_64) { |
| 125 | pci_write_config_dword(dev, msi_upper_address_reg(pos), |
| 126 | msg->address_hi); |
| 127 | pci_write_config_word(dev, msi_data_reg(pos, 1), |
| 128 | msg->data); |
| 129 | } else { |
| 130 | pci_write_config_word(dev, msi_data_reg(pos, 0), |
| 131 | msg->data); |
| 132 | } |
| 133 | break; |
| 134 | } |
| 135 | case PCI_CAP_ID_MSIX: |
| 136 | { |
| 137 | void __iomem *base; |
| 138 | base = entry->mask_base + |
| 139 | entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE; |
| 140 | |
| 141 | writel(msg->address_lo, |
| 142 | base + PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET); |
| 143 | writel(msg->address_hi, |
| 144 | base + PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET); |
| 145 | writel(msg->data, base + PCI_MSIX_ENTRY_DATA_OFFSET); |
| 146 | break; |
| 147 | } |
| 148 | default: |
| 149 | BUG(); |
| 150 | } |
| 151 | } |
| 152 | |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 153 | void mask_msi_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 155 | msi_set_mask_bit(irq, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 158 | void unmask_msi_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 160 | msi_set_mask_bit(irq, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 163 | static int msi_free_irq(struct pci_dev* dev, int irq); |
Satoru Takeuchi | c54c187 | 2007-01-18 13:50:05 +0900 | [diff] [blame] | 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | static int msi_init(void) |
| 166 | { |
| 167 | static int status = -ENOMEM; |
| 168 | |
| 169 | if (!status) |
| 170 | return status; |
| 171 | |
Grant Grundler | b64c05e | 2006-01-14 00:34:53 -0700 | [diff] [blame] | 172 | status = msi_cache_init(); |
| 173 | if (status < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | pci_msi_enable = 0; |
| 175 | printk(KERN_WARNING "PCI: MSI cache init failed\n"); |
| 176 | return status; |
| 177 | } |
Mark Maule | fd58e55 | 2006-04-10 21:17:48 -0500 | [diff] [blame] | 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | return status; |
| 180 | } |
| 181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | static struct msi_desc* alloc_msi_entry(void) |
| 183 | { |
| 184 | struct msi_desc *entry; |
| 185 | |
Pekka J Enberg | 5718178 | 2006-09-27 01:51:03 -0700 | [diff] [blame] | 186 | entry = kmem_cache_zalloc(msi_cachep, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | if (!entry) |
| 188 | return NULL; |
| 189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | entry->link.tail = entry->link.head = 0; /* single message */ |
| 191 | entry->dev = NULL; |
| 192 | |
| 193 | return entry; |
| 194 | } |
| 195 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 196 | static void attach_msi_entry(struct msi_desc *entry, int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | { |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 198 | msi_desc[irq] = entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 201 | static int create_msi_irq(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 203 | struct msi_desc *entry; |
| 204 | int irq; |
Ingo Molnar | f6bc266 | 2006-01-26 01:42:11 +0100 | [diff] [blame] | 205 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 206 | entry = alloc_msi_entry(); |
| 207 | if (!entry) |
| 208 | return -ENOMEM; |
| 209 | |
| 210 | irq = create_irq(); |
| 211 | if (irq < 0) { |
| 212 | kmem_cache_free(msi_cachep, entry); |
| 213 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 215 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 216 | set_irq_data(irq, entry); |
| 217 | |
| 218 | return irq; |
| 219 | } |
| 220 | |
| 221 | static void destroy_msi_irq(unsigned int irq) |
| 222 | { |
| 223 | struct msi_desc *entry; |
| 224 | |
| 225 | entry = get_irq_data(irq); |
| 226 | set_irq_chip(irq, NULL); |
| 227 | set_irq_data(irq, NULL); |
| 228 | destroy_irq(irq); |
| 229 | kmem_cache_free(msi_cachep, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | static void enable_msi_mode(struct pci_dev *dev, int pos, int type) |
| 233 | { |
| 234 | u16 control; |
| 235 | |
| 236 | pci_read_config_word(dev, msi_control_reg(pos), &control); |
| 237 | if (type == PCI_CAP_ID_MSI) { |
| 238 | /* Set enabled bits to single MSI & enable MSI_enable bit */ |
| 239 | msi_enable(control, 1); |
| 240 | pci_write_config_word(dev, msi_control_reg(pos), control); |
Shaohua Li | 99dc804 | 2006-05-26 10:58:27 +0800 | [diff] [blame] | 241 | dev->msi_enabled = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } else { |
| 243 | msix_enable(control); |
| 244 | pci_write_config_word(dev, msi_control_reg(pos), control); |
Shaohua Li | 99dc804 | 2006-05-26 10:58:27 +0800 | [diff] [blame] | 245 | dev->msix_enabled = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } |
Jeff Garzik | 1769b46 | 2006-12-07 17:56:06 -0500 | [diff] [blame] | 247 | |
| 248 | pci_intx(dev, 0); /* disable intx */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Kristen Accardi | 4602b88 | 2005-08-16 15:15:58 -0700 | [diff] [blame] | 251 | void disable_msi_mode(struct pci_dev *dev, int pos, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | { |
| 253 | u16 control; |
| 254 | |
| 255 | pci_read_config_word(dev, msi_control_reg(pos), &control); |
| 256 | if (type == PCI_CAP_ID_MSI) { |
| 257 | /* Set enabled bits to single MSI & enable MSI_enable bit */ |
| 258 | msi_disable(control); |
| 259 | pci_write_config_word(dev, msi_control_reg(pos), control); |
Shaohua Li | 99dc804 | 2006-05-26 10:58:27 +0800 | [diff] [blame] | 260 | dev->msi_enabled = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | } else { |
| 262 | msix_disable(control); |
| 263 | pci_write_config_word(dev, msi_control_reg(pos), control); |
Shaohua Li | 99dc804 | 2006-05-26 10:58:27 +0800 | [diff] [blame] | 264 | dev->msix_enabled = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
Jeff Garzik | 1769b46 | 2006-12-07 17:56:06 -0500 | [diff] [blame] | 266 | |
| 267 | pci_intx(dev, 1); /* enable intx */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 270 | #ifdef CONFIG_PM |
Michael Ellerman | 8fed4b6 | 2007-01-25 19:34:08 +1100 | [diff] [blame] | 271 | static int __pci_save_msi_state(struct pci_dev *dev) |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 272 | { |
| 273 | int pos, i = 0; |
| 274 | u16 control; |
| 275 | struct pci_cap_saved_state *save_state; |
| 276 | u32 *cap; |
| 277 | |
| 278 | pos = pci_find_capability(dev, PCI_CAP_ID_MSI); |
| 279 | if (pos <= 0 || dev->no_msi) |
| 280 | return 0; |
| 281 | |
| 282 | pci_read_config_word(dev, msi_control_reg(pos), &control); |
| 283 | if (!(control & PCI_MSI_FLAGS_ENABLE)) |
| 284 | return 0; |
| 285 | |
| 286 | save_state = kzalloc(sizeof(struct pci_cap_saved_state) + sizeof(u32) * 5, |
| 287 | GFP_KERNEL); |
| 288 | if (!save_state) { |
| 289 | printk(KERN_ERR "Out of memory in pci_save_msi_state\n"); |
| 290 | return -ENOMEM; |
| 291 | } |
| 292 | cap = &save_state->data[0]; |
| 293 | |
| 294 | pci_read_config_dword(dev, pos, &cap[i++]); |
| 295 | control = cap[0] >> 16; |
| 296 | pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_LO, &cap[i++]); |
| 297 | if (control & PCI_MSI_FLAGS_64BIT) { |
| 298 | pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_HI, &cap[i++]); |
| 299 | pci_read_config_dword(dev, pos + PCI_MSI_DATA_64, &cap[i++]); |
| 300 | } else |
| 301 | pci_read_config_dword(dev, pos + PCI_MSI_DATA_32, &cap[i++]); |
| 302 | if (control & PCI_MSI_FLAGS_MASKBIT) |
| 303 | pci_read_config_dword(dev, pos + PCI_MSI_MASK_BIT, &cap[i++]); |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 304 | save_state->cap_nr = PCI_CAP_ID_MSI; |
| 305 | pci_add_saved_cap(dev, save_state); |
| 306 | return 0; |
| 307 | } |
| 308 | |
Michael Ellerman | 8fed4b6 | 2007-01-25 19:34:08 +1100 | [diff] [blame] | 309 | static void __pci_restore_msi_state(struct pci_dev *dev) |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 310 | { |
| 311 | int i = 0, pos; |
| 312 | u16 control; |
| 313 | struct pci_cap_saved_state *save_state; |
| 314 | u32 *cap; |
| 315 | |
| 316 | save_state = pci_find_saved_cap(dev, PCI_CAP_ID_MSI); |
| 317 | pos = pci_find_capability(dev, PCI_CAP_ID_MSI); |
| 318 | if (!save_state || pos <= 0) |
| 319 | return; |
| 320 | cap = &save_state->data[0]; |
| 321 | |
| 322 | control = cap[i++] >> 16; |
| 323 | pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO, cap[i++]); |
| 324 | if (control & PCI_MSI_FLAGS_64BIT) { |
| 325 | pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI, cap[i++]); |
| 326 | pci_write_config_dword(dev, pos + PCI_MSI_DATA_64, cap[i++]); |
| 327 | } else |
| 328 | pci_write_config_dword(dev, pos + PCI_MSI_DATA_32, cap[i++]); |
| 329 | if (control & PCI_MSI_FLAGS_MASKBIT) |
| 330 | pci_write_config_dword(dev, pos + PCI_MSI_MASK_BIT, cap[i++]); |
| 331 | pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control); |
| 332 | enable_msi_mode(dev, pos, PCI_CAP_ID_MSI); |
| 333 | pci_remove_saved_cap(save_state); |
| 334 | kfree(save_state); |
| 335 | } |
| 336 | |
Michael Ellerman | 8fed4b6 | 2007-01-25 19:34:08 +1100 | [diff] [blame] | 337 | static int __pci_save_msix_state(struct pci_dev *dev) |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 338 | { |
| 339 | int pos; |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 340 | int irq, head, tail = 0; |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 341 | u16 control; |
| 342 | struct pci_cap_saved_state *save_state; |
| 343 | |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 344 | if (!dev->msix_enabled) |
| 345 | return 0; |
| 346 | |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 347 | pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); |
| 348 | if (pos <= 0 || dev->no_msi) |
| 349 | return 0; |
| 350 | |
Mark Maule | fd58e55 | 2006-04-10 21:17:48 -0500 | [diff] [blame] | 351 | /* save the capability */ |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 352 | pci_read_config_word(dev, msi_control_reg(pos), &control); |
| 353 | if (!(control & PCI_MSIX_FLAGS_ENABLE)) |
| 354 | return 0; |
| 355 | save_state = kzalloc(sizeof(struct pci_cap_saved_state) + sizeof(u16), |
| 356 | GFP_KERNEL); |
| 357 | if (!save_state) { |
| 358 | printk(KERN_ERR "Out of memory in pci_save_msix_state\n"); |
| 359 | return -ENOMEM; |
| 360 | } |
| 361 | *((u16 *)&save_state->data[0]) = control; |
| 362 | |
Mark Maule | fd58e55 | 2006-04-10 21:17:48 -0500 | [diff] [blame] | 363 | /* save the table */ |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 364 | irq = head = dev->first_msi_irq; |
Mark Maule | fd58e55 | 2006-04-10 21:17:48 -0500 | [diff] [blame] | 365 | while (head != tail) { |
Mark Maule | fd58e55 | 2006-04-10 21:17:48 -0500 | [diff] [blame] | 366 | struct msi_desc *entry; |
| 367 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 368 | entry = msi_desc[irq]; |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 369 | read_msi_msg(irq, &entry->msg_save); |
Mark Maule | fd58e55 | 2006-04-10 21:17:48 -0500 | [diff] [blame] | 370 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 371 | tail = msi_desc[irq]->link.tail; |
| 372 | irq = tail; |
Mark Maule | fd58e55 | 2006-04-10 21:17:48 -0500 | [diff] [blame] | 373 | } |
Mark Maule | fd58e55 | 2006-04-10 21:17:48 -0500 | [diff] [blame] | 374 | |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 375 | save_state->cap_nr = PCI_CAP_ID_MSIX; |
| 376 | pci_add_saved_cap(dev, save_state); |
| 377 | return 0; |
| 378 | } |
| 379 | |
Michael Ellerman | 8fed4b6 | 2007-01-25 19:34:08 +1100 | [diff] [blame] | 380 | int pci_save_msi_state(struct pci_dev *dev) |
| 381 | { |
| 382 | int rc; |
| 383 | |
| 384 | rc = __pci_save_msi_state(dev); |
| 385 | if (rc) |
| 386 | return rc; |
| 387 | |
| 388 | rc = __pci_save_msix_state(dev); |
| 389 | |
| 390 | return rc; |
| 391 | } |
| 392 | |
| 393 | static void __pci_restore_msix_state(struct pci_dev *dev) |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 394 | { |
| 395 | u16 save; |
| 396 | int pos; |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 397 | int irq, head, tail = 0; |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 398 | struct msi_desc *entry; |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 399 | struct pci_cap_saved_state *save_state; |
| 400 | |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 401 | if (!dev->msix_enabled) |
| 402 | return; |
| 403 | |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 404 | save_state = pci_find_saved_cap(dev, PCI_CAP_ID_MSIX); |
| 405 | if (!save_state) |
| 406 | return; |
| 407 | save = *((u16 *)&save_state->data[0]); |
| 408 | pci_remove_saved_cap(save_state); |
| 409 | kfree(save_state); |
| 410 | |
| 411 | pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); |
| 412 | if (pos <= 0) |
| 413 | return; |
| 414 | |
| 415 | /* route the table */ |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 416 | irq = head = dev->first_msi_irq; |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 417 | while (head != tail) { |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 418 | entry = msi_desc[irq]; |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 419 | write_msi_msg(irq, &entry->msg_save); |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 420 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 421 | tail = msi_desc[irq]->link.tail; |
| 422 | irq = tail; |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 423 | } |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 424 | |
| 425 | pci_write_config_word(dev, msi_control_reg(pos), save); |
| 426 | enable_msi_mode(dev, pos, PCI_CAP_ID_MSIX); |
| 427 | } |
Michael Ellerman | 8fed4b6 | 2007-01-25 19:34:08 +1100 | [diff] [blame] | 428 | |
| 429 | void pci_restore_msi_state(struct pci_dev *dev) |
| 430 | { |
| 431 | __pci_restore_msi_state(dev); |
| 432 | __pci_restore_msix_state(dev); |
| 433 | } |
Satoru Takeuchi | c54c187 | 2007-01-18 13:50:05 +0900 | [diff] [blame] | 434 | #endif /* CONFIG_PM */ |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | /** |
| 437 | * msi_capability_init - configure device's MSI capability structure |
| 438 | * @dev: pointer to the pci_dev data structure of MSI device function |
| 439 | * |
Steven Cole | eaae4b3 | 2005-05-03 18:38:30 -0600 | [diff] [blame] | 440 | * Setup the MSI capability structure of device function with a single |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 441 | * MSI irq, regardless of device function is capable of handling |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | * multiple messages. A return of zero indicates the successful setup |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 443 | * of an entry zero with the new MSI irq or non-zero for otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | **/ |
| 445 | static int msi_capability_init(struct pci_dev *dev) |
| 446 | { |
Mark Maule | fd58e55 | 2006-04-10 21:17:48 -0500 | [diff] [blame] | 447 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | struct msi_desc *entry; |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 449 | int pos, irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | u16 control; |
| 451 | |
| 452 | pos = pci_find_capability(dev, PCI_CAP_ID_MSI); |
| 453 | pci_read_config_word(dev, msi_control_reg(pos), &control); |
| 454 | /* MSI Entry Initialization */ |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 455 | irq = create_msi_irq(); |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 456 | if (irq < 0) |
| 457 | return irq; |
| 458 | |
| 459 | entry = get_irq_data(irq); |
| 460 | entry->link.head = irq; |
| 461 | entry->link.tail = irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | entry->msi_attrib.type = PCI_CAP_ID_MSI; |
Eric W. Biederman | 0366f8f | 2006-10-04 02:16:33 -0700 | [diff] [blame] | 463 | entry->msi_attrib.is_64 = is_64bit_address(control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | entry->msi_attrib.entry_nr = 0; |
| 465 | entry->msi_attrib.maskbit = is_mask_bit_support(control); |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 466 | entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */ |
Eric W. Biederman | 0366f8f | 2006-10-04 02:16:33 -0700 | [diff] [blame] | 467 | entry->msi_attrib.pos = pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | if (is_mask_bit_support(control)) { |
| 469 | entry->mask_base = (void __iomem *)(long)msi_mask_bits_reg(pos, |
| 470 | is_64bit_address(control)); |
| 471 | } |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 472 | entry->dev = dev; |
| 473 | if (entry->msi_attrib.maskbit) { |
| 474 | unsigned int maskbits, temp; |
| 475 | /* All MSIs are unmasked by default, Mask them all */ |
| 476 | pci_read_config_dword(dev, |
| 477 | msi_mask_bits_reg(pos, is_64bit_address(control)), |
| 478 | &maskbits); |
| 479 | temp = (1 << multi_msi_capable(control)); |
| 480 | temp = ((temp - 1) & ~temp); |
| 481 | maskbits |= temp; |
| 482 | pci_write_config_dword(dev, |
| 483 | msi_mask_bits_reg(pos, is_64bit_address(control)), |
| 484 | maskbits); |
| 485 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | /* Configure MSI capability structure */ |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 487 | status = arch_setup_msi_irq(irq, dev); |
| 488 | if (status < 0) { |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 489 | destroy_msi_irq(irq); |
Mark Maule | fd58e55 | 2006-04-10 21:17:48 -0500 | [diff] [blame] | 490 | return status; |
| 491 | } |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 492 | |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 493 | dev->first_msi_irq = irq; |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 494 | attach_msi_entry(entry, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | /* Set MSI enabled bits */ |
| 496 | enable_msi_mode(dev, pos, PCI_CAP_ID_MSI); |
| 497 | |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 498 | dev->irq = irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | return 0; |
| 500 | } |
| 501 | |
| 502 | /** |
| 503 | * msix_capability_init - configure device's MSI-X capability |
| 504 | * @dev: pointer to the pci_dev data structure of MSI-X device function |
Randy Dunlap | 8f7020d | 2005-10-23 11:57:38 -0700 | [diff] [blame] | 505 | * @entries: pointer to an array of struct msix_entry entries |
| 506 | * @nvec: number of @entries |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | * |
Steven Cole | eaae4b3 | 2005-05-03 18:38:30 -0600 | [diff] [blame] | 508 | * Setup the MSI-X capability structure of device function with a |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 509 | * single MSI-X irq. A return of zero indicates the successful setup of |
| 510 | * requested MSI-X entries with allocated irqs or non-zero for otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | **/ |
| 512 | static int msix_capability_init(struct pci_dev *dev, |
| 513 | struct msix_entry *entries, int nvec) |
| 514 | { |
| 515 | struct msi_desc *head = NULL, *tail = NULL, *entry = NULL; |
Mark Maule | fd58e55 | 2006-04-10 21:17:48 -0500 | [diff] [blame] | 516 | int status; |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 517 | int irq, pos, i, j, nr_entries, temp = 0; |
Grant Grundler | a0454b4 | 2006-02-16 23:58:29 -0800 | [diff] [blame] | 518 | unsigned long phys_addr; |
| 519 | u32 table_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | u16 control; |
| 521 | u8 bir; |
| 522 | void __iomem *base; |
| 523 | |
| 524 | pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); |
| 525 | /* Request & Map MSI-X table region */ |
| 526 | pci_read_config_word(dev, msi_control_reg(pos), &control); |
| 527 | nr_entries = multi_msix_capable(control); |
Grant Grundler | a0454b4 | 2006-02-16 23:58:29 -0800 | [diff] [blame] | 528 | |
| 529 | pci_read_config_dword(dev, msix_table_offset_reg(pos), &table_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK); |
Grant Grundler | a0454b4 | 2006-02-16 23:58:29 -0800 | [diff] [blame] | 531 | table_offset &= ~PCI_MSIX_FLAGS_BIRMASK; |
| 532 | phys_addr = pci_resource_start (dev, bir) + table_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | base = ioremap_nocache(phys_addr, nr_entries * PCI_MSIX_ENTRY_SIZE); |
| 534 | if (base == NULL) |
| 535 | return -ENOMEM; |
| 536 | |
| 537 | /* MSI-X Table Initialization */ |
| 538 | for (i = 0; i < nvec; i++) { |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 539 | irq = create_msi_irq(); |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 540 | if (irq < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 543 | entry = get_irq_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | j = entries[i].entry; |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 545 | entries[i].vector = irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | entry->msi_attrib.type = PCI_CAP_ID_MSIX; |
Eric W. Biederman | 0366f8f | 2006-10-04 02:16:33 -0700 | [diff] [blame] | 547 | entry->msi_attrib.is_64 = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | entry->msi_attrib.entry_nr = j; |
| 549 | entry->msi_attrib.maskbit = 1; |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 550 | entry->msi_attrib.default_irq = dev->irq; |
Eric W. Biederman | 0366f8f | 2006-10-04 02:16:33 -0700 | [diff] [blame] | 551 | entry->msi_attrib.pos = pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | entry->dev = dev; |
| 553 | entry->mask_base = base; |
| 554 | if (!head) { |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 555 | entry->link.head = irq; |
| 556 | entry->link.tail = irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | head = entry; |
| 558 | } else { |
| 559 | entry->link.head = temp; |
| 560 | entry->link.tail = tail->link.tail; |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 561 | tail->link.tail = irq; |
| 562 | head->link.head = irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | } |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 564 | temp = irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | tail = entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | /* Configure MSI-X capability structure */ |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 567 | status = arch_setup_msi_irq(irq, dev); |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 568 | if (status < 0) { |
| 569 | destroy_msi_irq(irq); |
Mark Maule | fd58e55 | 2006-04-10 21:17:48 -0500 | [diff] [blame] | 570 | break; |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 571 | } |
Mark Maule | fd58e55 | 2006-04-10 21:17:48 -0500 | [diff] [blame] | 572 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 573 | attach_msi_entry(entry, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | } |
| 575 | if (i != nvec) { |
Eric W. Biederman | 92db6d1 | 2006-10-04 02:16:35 -0700 | [diff] [blame] | 576 | int avail = i - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | i--; |
| 578 | for (; i >= 0; i--) { |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 579 | irq = (entries + i)->vector; |
| 580 | msi_free_irq(dev, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | (entries + i)->vector = 0; |
| 582 | } |
Eric W. Biederman | 92db6d1 | 2006-10-04 02:16:35 -0700 | [diff] [blame] | 583 | /* If we had some success report the number of irqs |
| 584 | * we succeeded in setting up. |
| 585 | */ |
| 586 | if (avail <= 0) |
| 587 | avail = -EBUSY; |
| 588 | return avail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | } |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 590 | dev->first_msi_irq = entries[0].vector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | /* Set MSI-X enabled bits */ |
| 592 | enable_msi_mode(dev, pos, PCI_CAP_ID_MSIX); |
| 593 | |
| 594 | return 0; |
| 595 | } |
| 596 | |
| 597 | /** |
Brice Goglin | 24334a1 | 2006-08-31 01:55:07 -0400 | [diff] [blame] | 598 | * pci_msi_supported - check whether MSI may be enabled on device |
| 599 | * @dev: pointer to the pci_dev data structure of MSI device function |
| 600 | * |
Brice Goglin | 0306ebf | 2006-10-05 10:24:31 +0200 | [diff] [blame] | 601 | * Look at global flags, the device itself, and its parent busses |
| 602 | * to return 0 if MSI are supported for the device. |
Brice Goglin | 24334a1 | 2006-08-31 01:55:07 -0400 | [diff] [blame] | 603 | **/ |
| 604 | static |
| 605 | int pci_msi_supported(struct pci_dev * dev) |
| 606 | { |
| 607 | struct pci_bus *bus; |
| 608 | |
Brice Goglin | 0306ebf | 2006-10-05 10:24:31 +0200 | [diff] [blame] | 609 | /* MSI must be globally enabled and supported by the device */ |
Brice Goglin | 24334a1 | 2006-08-31 01:55:07 -0400 | [diff] [blame] | 610 | if (!pci_msi_enable || !dev || dev->no_msi) |
| 611 | return -EINVAL; |
| 612 | |
Brice Goglin | 0306ebf | 2006-10-05 10:24:31 +0200 | [diff] [blame] | 613 | /* Any bridge which does NOT route MSI transactions from it's |
| 614 | * secondary bus to it's primary bus must set NO_MSI flag on |
| 615 | * the secondary pci_bus. |
| 616 | * We expect only arch-specific PCI host bus controller driver |
| 617 | * or quirks for specific PCI bridges to be setting NO_MSI. |
| 618 | */ |
Brice Goglin | 24334a1 | 2006-08-31 01:55:07 -0400 | [diff] [blame] | 619 | for (bus = dev->bus; bus; bus = bus->parent) |
| 620 | if (bus->bus_flags & PCI_BUS_FLAGS_NO_MSI) |
| 621 | return -EINVAL; |
| 622 | |
| 623 | return 0; |
| 624 | } |
| 625 | |
| 626 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | * pci_enable_msi - configure device's MSI capability structure |
| 628 | * @dev: pointer to the pci_dev data structure of MSI device function |
| 629 | * |
| 630 | * Setup the MSI capability structure of device function with |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 631 | * a single MSI irq upon its software driver call to request for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | * MSI mode enabled on its hardware device function. A return of zero |
| 633 | * indicates the successful setup of an entry zero with the new MSI |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 634 | * irq or non-zero for otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | **/ |
| 636 | int pci_enable_msi(struct pci_dev* dev) |
| 637 | { |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 638 | int pos, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
Brice Goglin | 24334a1 | 2006-08-31 01:55:07 -0400 | [diff] [blame] | 640 | if (pci_msi_supported(dev) < 0) |
| 641 | return -EINVAL; |
Michael S. Tsirkin | 6e325a6 | 2006-02-14 18:52:22 +0200 | [diff] [blame] | 642 | |
Grant Grundler | b64c05e | 2006-01-14 00:34:53 -0700 | [diff] [blame] | 643 | status = msi_init(); |
| 644 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | return status; |
| 646 | |
Grant Grundler | b64c05e | 2006-01-14 00:34:53 -0700 | [diff] [blame] | 647 | pos = pci_find_capability(dev, PCI_CAP_ID_MSI); |
| 648 | if (!pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | return -EINVAL; |
| 650 | |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 651 | WARN_ON(!!dev->msi_enabled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 653 | /* Check whether driver already requested for MSI-X irqs */ |
Grant Grundler | b64c05e | 2006-01-14 00:34:53 -0700 | [diff] [blame] | 654 | pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 655 | if (pos > 0 && dev->msix_enabled) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | printk(KERN_INFO "PCI: %s: Can't enable MSI. " |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 657 | "Device already has MSI-X enabled\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | pci_name(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | return -EINVAL; |
| 660 | } |
| 661 | status = msi_capability_init(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | return status; |
| 663 | } |
| 664 | |
| 665 | void pci_disable_msi(struct pci_dev* dev) |
| 666 | { |
| 667 | struct msi_desc *entry; |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 668 | int pos, default_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | u16 control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | |
Matthew Wilcox | 309e57d | 2006-03-05 22:33:34 -0700 | [diff] [blame] | 671 | if (!pci_msi_enable) |
| 672 | return; |
Grant Grundler | b64c05e | 2006-01-14 00:34:53 -0700 | [diff] [blame] | 673 | if (!dev) |
| 674 | return; |
Matthew Wilcox | 309e57d | 2006-03-05 22:33:34 -0700 | [diff] [blame] | 675 | |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 676 | if (!dev->msi_enabled) |
| 677 | return; |
| 678 | |
Grant Grundler | b64c05e | 2006-01-14 00:34:53 -0700 | [diff] [blame] | 679 | pos = pci_find_capability(dev, PCI_CAP_ID_MSI); |
| 680 | if (!pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | return; |
| 682 | |
| 683 | pci_read_config_word(dev, msi_control_reg(pos), &control); |
| 684 | if (!(control & PCI_MSI_FLAGS_ENABLE)) |
| 685 | return; |
| 686 | |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 687 | |
Eric W. Biederman | 7bd007e | 2006-10-04 02:16:31 -0700 | [diff] [blame] | 688 | disable_msi_mode(dev, pos, PCI_CAP_ID_MSI); |
| 689 | |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 690 | entry = msi_desc[dev->first_msi_irq]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | if (!entry || !entry->dev || entry->msi_attrib.type != PCI_CAP_ID_MSI) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | return; |
| 693 | } |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 694 | if (irq_has_action(dev->first_msi_irq)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | printk(KERN_WARNING "PCI: %s: pci_disable_msi() called without " |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 696 | "free_irq() on MSI irq %d\n", |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 697 | pci_name(dev), dev->first_msi_irq); |
| 698 | BUG_ON(irq_has_action(dev->first_msi_irq)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | } else { |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 700 | default_irq = entry->msi_attrib.default_irq; |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 701 | msi_free_irq(dev, dev->first_msi_irq); |
Eric W. Biederman | 7bd007e | 2006-10-04 02:16:31 -0700 | [diff] [blame] | 702 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 703 | /* Restore dev->irq to its default pin-assertion irq */ |
| 704 | dev->irq = default_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | } |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 706 | dev->first_msi_irq = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 709 | static int msi_free_irq(struct pci_dev* dev, int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | { |
| 711 | struct msi_desc *entry; |
| 712 | int head, entry_nr, type; |
| 713 | void __iomem *base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 715 | arch_teardown_msi_irq(irq); |
Mark Maule | fd58e55 | 2006-04-10 21:17:48 -0500 | [diff] [blame] | 716 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 717 | entry = msi_desc[irq]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | if (!entry || entry->dev != dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | return -EINVAL; |
| 720 | } |
| 721 | type = entry->msi_attrib.type; |
| 722 | entry_nr = entry->msi_attrib.entry_nr; |
| 723 | head = entry->link.head; |
| 724 | base = entry->mask_base; |
| 725 | msi_desc[entry->link.head]->link.tail = entry->link.tail; |
| 726 | msi_desc[entry->link.tail]->link.head = entry->link.head; |
| 727 | entry->dev = NULL; |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 728 | msi_desc[irq] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 730 | destroy_msi_irq(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | |
| 732 | if (type == PCI_CAP_ID_MSIX) { |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 733 | writel(1, base + entry_nr * PCI_MSIX_ENTRY_SIZE + |
| 734 | PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 736 | if (head == irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | iounmap(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | return 0; |
| 741 | } |
| 742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | /** |
| 744 | * pci_enable_msix - configure device's MSI-X capability structure |
| 745 | * @dev: pointer to the pci_dev data structure of MSI-X device function |
Greg Kroah-Hartman | 70549ad | 2005-06-06 23:07:46 -0700 | [diff] [blame] | 746 | * @entries: pointer to an array of MSI-X entries |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 747 | * @nvec: number of MSI-X irqs requested for allocation by device driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | * |
| 749 | * Setup the MSI-X capability structure of device function with the number |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 750 | * of requested irqs upon its software driver call to request for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | * MSI-X mode enabled on its hardware device function. A return of zero |
| 752 | * indicates the successful configuration of MSI-X capability structure |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 753 | * with new allocated MSI-X irqs. A return of < 0 indicates a failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | * Or a return of > 0 indicates that driver request is exceeding the number |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 755 | * of irqs available. Driver should use the returned value to re-send |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | * its request. |
| 757 | **/ |
| 758 | int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec) |
| 759 | { |
Eric W. Biederman | 92db6d1 | 2006-10-04 02:16:35 -0700 | [diff] [blame] | 760 | int status, pos, nr_entries; |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 761 | int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | u16 control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | |
Brice Goglin | 24334a1 | 2006-08-31 01:55:07 -0400 | [diff] [blame] | 764 | if (!entries || pci_msi_supported(dev) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | return -EINVAL; |
| 766 | |
Grant Grundler | b64c05e | 2006-01-14 00:34:53 -0700 | [diff] [blame] | 767 | status = msi_init(); |
| 768 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | return status; |
| 770 | |
Grant Grundler | b64c05e | 2006-01-14 00:34:53 -0700 | [diff] [blame] | 771 | pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); |
| 772 | if (!pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | return -EINVAL; |
| 774 | |
| 775 | pci_read_config_word(dev, msi_control_reg(pos), &control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | nr_entries = multi_msix_capable(control); |
| 777 | if (nvec > nr_entries) |
| 778 | return -EINVAL; |
| 779 | |
| 780 | /* Check for any invalid entries */ |
| 781 | for (i = 0; i < nvec; i++) { |
| 782 | if (entries[i].entry >= nr_entries) |
| 783 | return -EINVAL; /* invalid entry */ |
| 784 | for (j = i + 1; j < nvec; j++) { |
| 785 | if (entries[i].entry == entries[j].entry) |
| 786 | return -EINVAL; /* duplicate entry */ |
| 787 | } |
| 788 | } |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 789 | WARN_ON(!!dev->msix_enabled); |
Eric W. Biederman | 7bd007e | 2006-10-04 02:16:31 -0700 | [diff] [blame] | 790 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 791 | /* Check whether driver already requested for MSI irq */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | if (pci_find_capability(dev, PCI_CAP_ID_MSI) > 0 && |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 793 | dev->msi_enabled) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | printk(KERN_INFO "PCI: %s: Can't enable MSI-X. " |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 795 | "Device already has an MSI irq assigned\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | pci_name(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | return -EINVAL; |
| 798 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | status = msix_capability_init(dev, entries, nvec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | return status; |
| 801 | } |
| 802 | |
| 803 | void pci_disable_msix(struct pci_dev* dev) |
| 804 | { |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 805 | int irq, head, tail = 0, warning = 0; |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 806 | int pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | u16 control; |
| 808 | |
Matthew Wilcox | 309e57d | 2006-03-05 22:33:34 -0700 | [diff] [blame] | 809 | if (!pci_msi_enable) |
| 810 | return; |
Grant Grundler | b64c05e | 2006-01-14 00:34:53 -0700 | [diff] [blame] | 811 | if (!dev) |
| 812 | return; |
| 813 | |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 814 | if (!dev->msix_enabled) |
| 815 | return; |
| 816 | |
Grant Grundler | b64c05e | 2006-01-14 00:34:53 -0700 | [diff] [blame] | 817 | pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); |
| 818 | if (!pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | return; |
| 820 | |
| 821 | pci_read_config_word(dev, msi_control_reg(pos), &control); |
| 822 | if (!(control & PCI_MSIX_FLAGS_ENABLE)) |
| 823 | return; |
| 824 | |
Eric W. Biederman | 7bd007e | 2006-10-04 02:16:31 -0700 | [diff] [blame] | 825 | disable_msi_mode(dev, pos, PCI_CAP_ID_MSIX); |
| 826 | |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 827 | irq = head = dev->first_msi_irq; |
| 828 | while (head != tail) { |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 829 | tail = msi_desc[irq]->link.tail; |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 830 | if (irq_has_action(irq)) |
| 831 | warning = 1; |
| 832 | else if (irq != head) /* Release MSI-X irq */ |
| 833 | msi_free_irq(dev, irq); |
| 834 | irq = tail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | } |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 836 | msi_free_irq(dev, irq); |
| 837 | if (warning) { |
| 838 | printk(KERN_WARNING "PCI: %s: pci_disable_msix() called without " |
| 839 | "free_irq() on all MSI-X irqs\n", |
| 840 | pci_name(dev)); |
| 841 | BUG_ON(warning > 0); |
| 842 | } |
| 843 | dev->first_msi_irq = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | /** |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 847 | * msi_remove_pci_irq_vectors - reclaim MSI(X) irqs to unused state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | * @dev: pointer to the pci_dev data structure of MSI(X) device function |
| 849 | * |
Steven Cole | eaae4b3 | 2005-05-03 18:38:30 -0600 | [diff] [blame] | 850 | * Being called during hotplug remove, from which the device function |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 851 | * is hot-removed. All previous assigned MSI/MSI-X irqs, if |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | * allocated for this device function, are reclaimed to unused state, |
| 853 | * which may be used later on. |
| 854 | **/ |
| 855 | void msi_remove_pci_irq_vectors(struct pci_dev* dev) |
| 856 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | if (!pci_msi_enable || !dev) |
| 858 | return; |
| 859 | |
Eric W. Biederman | 866a8c8 | 2007-01-28 12:45:54 -0700 | [diff] [blame^] | 860 | if (dev->msi_enabled) { |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 861 | if (irq_has_action(dev->first_msi_irq)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | printk(KERN_WARNING "PCI: %s: msi_remove_pci_irq_vectors() " |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 863 | "called without free_irq() on MSI irq %d\n", |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 864 | pci_name(dev), dev->first_msi_irq); |
| 865 | BUG_ON(irq_has_action(dev->first_msi_irq)); |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 866 | } else /* Release MSI irq assigned to this device */ |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 867 | msi_free_irq(dev, dev->first_msi_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | } |
Eric W. Biederman | 866a8c8 | 2007-01-28 12:45:54 -0700 | [diff] [blame^] | 869 | if (dev->msix_enabled) { |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 870 | int irq, head, tail = 0, warning = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | void __iomem *base = NULL; |
| 872 | |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 873 | irq = head = dev->first_msi_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | while (head != tail) { |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 875 | tail = msi_desc[irq]->link.tail; |
| 876 | base = msi_desc[irq]->mask_base; |
Eric W. Biederman | 1f80025 | 2006-10-04 02:16:56 -0700 | [diff] [blame] | 877 | if (irq_has_action(irq)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | warning = 1; |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 879 | else if (irq != head) /* Release MSI-X irq */ |
| 880 | msi_free_irq(dev, irq); |
| 881 | irq = tail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | } |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 883 | msi_free_irq(dev, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | if (warning) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | iounmap(base); |
| 886 | printk(KERN_WARNING "PCI: %s: msi_remove_pci_irq_vectors() " |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 887 | "called without free_irq() on all MSI-X irqs\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | pci_name(dev)); |
| 889 | BUG_ON(warning > 0); |
| 890 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | } |
| 892 | } |
| 893 | |
Matthew Wilcox | 309e57d | 2006-03-05 22:33:34 -0700 | [diff] [blame] | 894 | void pci_no_msi(void) |
| 895 | { |
| 896 | pci_msi_enable = 0; |
| 897 | } |
| 898 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | EXPORT_SYMBOL(pci_enable_msi); |
| 900 | EXPORT_SYMBOL(pci_disable_msi); |
| 901 | EXPORT_SYMBOL(pci_enable_msix); |
| 902 | EXPORT_SYMBOL(pci_disable_msix); |