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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/pci.h> |
| 16 | #include <linux/proc_fs.h> |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 17 | #include <linux/msi.h> |
Dan Williams | 4fdadeb | 2007-04-26 18:21:38 -0700 | [diff] [blame] | 18 | #include <linux/smp.h> |
Hidetoshi Seto | 500559a | 2009-08-10 10:14:15 +0900 | [diff] [blame] | 19 | #include <linux/errno.h> |
| 20 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | #include "pci.h" |
| 23 | #include "msi.h" |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | static int pci_msi_enable = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Adrian Bunk | 6a9e7f2 | 2007-12-11 23:19:41 +0100 | [diff] [blame] | 27 | /* Arch hooks */ |
| 28 | |
Michael Ellerman | 11df1f0 | 2009-01-19 11:31:00 +1100 | [diff] [blame] | 29 | #ifndef arch_msi_check_device |
| 30 | int arch_msi_check_device(struct pci_dev *dev, int nvec, int type) |
Adrian Bunk | 6a9e7f2 | 2007-12-11 23:19:41 +0100 | [diff] [blame] | 31 | { |
| 32 | return 0; |
| 33 | } |
Michael Ellerman | 11df1f0 | 2009-01-19 11:31:00 +1100 | [diff] [blame] | 34 | #endif |
Adrian Bunk | 6a9e7f2 | 2007-12-11 23:19:41 +0100 | [diff] [blame] | 35 | |
Michael Ellerman | 11df1f0 | 2009-01-19 11:31:00 +1100 | [diff] [blame] | 36 | #ifndef arch_setup_msi_irqs |
| 37 | int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) |
Adrian Bunk | 6a9e7f2 | 2007-12-11 23:19:41 +0100 | [diff] [blame] | 38 | { |
| 39 | struct msi_desc *entry; |
| 40 | int ret; |
| 41 | |
Matthew Wilcox | 1c8d7b0 | 2009-03-17 08:54:10 -0400 | [diff] [blame] | 42 | /* |
| 43 | * If an architecture wants to support multiple MSI, it needs to |
| 44 | * override arch_setup_msi_irqs() |
| 45 | */ |
| 46 | if (type == PCI_CAP_ID_MSI && nvec > 1) |
| 47 | return 1; |
| 48 | |
Adrian Bunk | 6a9e7f2 | 2007-12-11 23:19:41 +0100 | [diff] [blame] | 49 | list_for_each_entry(entry, &dev->msi_list, list) { |
| 50 | ret = arch_setup_msi_irq(dev, entry); |
Michael Ellerman | b5fbf53 | 2009-02-11 22:27:02 +1100 | [diff] [blame] | 51 | if (ret < 0) |
Adrian Bunk | 6a9e7f2 | 2007-12-11 23:19:41 +0100 | [diff] [blame] | 52 | return ret; |
Michael Ellerman | b5fbf53 | 2009-02-11 22:27:02 +1100 | [diff] [blame] | 53 | if (ret > 0) |
| 54 | return -ENOSPC; |
Adrian Bunk | 6a9e7f2 | 2007-12-11 23:19:41 +0100 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | return 0; |
| 58 | } |
Michael Ellerman | 11df1f0 | 2009-01-19 11:31:00 +1100 | [diff] [blame] | 59 | #endif |
Adrian Bunk | 6a9e7f2 | 2007-12-11 23:19:41 +0100 | [diff] [blame] | 60 | |
Michael Ellerman | 11df1f0 | 2009-01-19 11:31:00 +1100 | [diff] [blame] | 61 | #ifndef arch_teardown_msi_irqs |
| 62 | void arch_teardown_msi_irqs(struct pci_dev *dev) |
Adrian Bunk | 6a9e7f2 | 2007-12-11 23:19:41 +0100 | [diff] [blame] | 63 | { |
| 64 | struct msi_desc *entry; |
| 65 | |
| 66 | list_for_each_entry(entry, &dev->msi_list, list) { |
Matthew Wilcox | 1c8d7b0 | 2009-03-17 08:54:10 -0400 | [diff] [blame] | 67 | int i, nvec; |
| 68 | if (entry->irq == 0) |
| 69 | continue; |
| 70 | nvec = 1 << entry->msi_attrib.multiple; |
| 71 | for (i = 0; i < nvec; i++) |
| 72 | arch_teardown_msi_irq(entry->irq + i); |
Adrian Bunk | 6a9e7f2 | 2007-12-11 23:19:41 +0100 | [diff] [blame] | 73 | } |
| 74 | } |
Michael Ellerman | 11df1f0 | 2009-01-19 11:31:00 +1100 | [diff] [blame] | 75 | #endif |
Adrian Bunk | 6a9e7f2 | 2007-12-11 23:19:41 +0100 | [diff] [blame] | 76 | |
Matthew Wilcox | 110828c | 2009-06-16 06:31:45 -0600 | [diff] [blame] | 77 | static void msi_set_enable(struct pci_dev *dev, int pos, int enable) |
Eric W. Biederman | b1cbf4e | 2007-03-05 00:30:10 -0800 | [diff] [blame] | 78 | { |
Eric W. Biederman | b1cbf4e | 2007-03-05 00:30:10 -0800 | [diff] [blame] | 79 | u16 control; |
| 80 | |
Matthew Wilcox | 110828c | 2009-06-16 06:31:45 -0600 | [diff] [blame] | 81 | BUG_ON(!pos); |
Eric W. Biederman | b1cbf4e | 2007-03-05 00:30:10 -0800 | [diff] [blame] | 82 | |
Matthew Wilcox | 110828c | 2009-06-16 06:31:45 -0600 | [diff] [blame] | 83 | pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control); |
| 84 | control &= ~PCI_MSI_FLAGS_ENABLE; |
| 85 | if (enable) |
| 86 | control |= PCI_MSI_FLAGS_ENABLE; |
| 87 | pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control); |
Hidetoshi Seto | 5ca5c02 | 2008-05-19 13:48:17 +0900 | [diff] [blame] | 88 | } |
| 89 | |
Eric W. Biederman | b1cbf4e | 2007-03-05 00:30:10 -0800 | [diff] [blame] | 90 | static void msix_set_enable(struct pci_dev *dev, int enable) |
| 91 | { |
| 92 | int pos; |
| 93 | u16 control; |
| 94 | |
| 95 | pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); |
| 96 | if (pos) { |
| 97 | pci_read_config_word(dev, pos + PCI_MSIX_FLAGS, &control); |
| 98 | control &= ~PCI_MSIX_FLAGS_ENABLE; |
| 99 | if (enable) |
| 100 | control |= PCI_MSIX_FLAGS_ENABLE; |
| 101 | pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control); |
| 102 | } |
| 103 | } |
| 104 | |
Matthew Wilcox | bffac3c | 2009-01-21 19:19:19 -0500 | [diff] [blame] | 105 | static inline __attribute_const__ u32 msi_mask(unsigned x) |
| 106 | { |
Matthew Wilcox | 0b49ec37a2 | 2009-02-08 20:27:47 -0700 | [diff] [blame] | 107 | /* Don't shift by >= width of type */ |
| 108 | if (x >= 5) |
| 109 | return 0xffffffff; |
| 110 | return (1 << (1 << x)) - 1; |
Matthew Wilcox | bffac3c | 2009-01-21 19:19:19 -0500 | [diff] [blame] | 111 | } |
| 112 | |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 113 | static inline __attribute_const__ u32 msi_capable_mask(u16 control) |
Mitch Williams | 988cbb1 | 2007-03-30 11:54:08 -0700 | [diff] [blame] | 114 | { |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 115 | return msi_mask((control >> 1) & 7); |
| 116 | } |
Mitch Williams | 988cbb1 | 2007-03-30 11:54:08 -0700 | [diff] [blame] | 117 | |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 118 | static inline __attribute_const__ u32 msi_enabled_mask(u16 control) |
| 119 | { |
| 120 | return msi_mask((control >> 4) & 7); |
Mitch Williams | 988cbb1 | 2007-03-30 11:54:08 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Matthew Wilcox | ce6fce4 | 2008-07-25 15:42:58 -0600 | [diff] [blame] | 123 | /* |
| 124 | * PCI 2.3 does not specify mask bits for each MSI interrupt. Attempting to |
| 125 | * mask all MSI interrupts by clearing the MSI enable bit does not work |
| 126 | * reliably as devices without an INTx disable bit will then generate a |
| 127 | * level IRQ which will never be cleared. |
Matthew Wilcox | ce6fce4 | 2008-07-25 15:42:58 -0600 | [diff] [blame] | 128 | */ |
Hidetoshi Seto | 12abb8b | 2009-06-24 12:08:09 +0900 | [diff] [blame] | 129 | static u32 __msi_mask_irq(struct msi_desc *desc, u32 mask, u32 flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | { |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 131 | u32 mask_bits = desc->masked; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 133 | if (!desc->msi_attrib.maskbit) |
Hidetoshi Seto | 12abb8b | 2009-06-24 12:08:09 +0900 | [diff] [blame] | 134 | return 0; |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 135 | |
| 136 | mask_bits &= ~mask; |
| 137 | mask_bits |= flag; |
| 138 | pci_write_config_dword(desc->dev, desc->mask_pos, mask_bits); |
Hidetoshi Seto | 12abb8b | 2009-06-24 12:08:09 +0900 | [diff] [blame] | 139 | |
| 140 | return mask_bits; |
| 141 | } |
| 142 | |
| 143 | static void msi_mask_irq(struct msi_desc *desc, u32 mask, u32 flag) |
| 144 | { |
| 145 | desc->masked = __msi_mask_irq(desc, mask, flag); |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /* |
| 149 | * This internal function does not flush PCI writes to the device. |
| 150 | * All users must ensure that they read from the device before either |
| 151 | * assuming that the device state is up to date, or returning out of this |
| 152 | * file. This saves a few milliseconds when initialising devices with lots |
| 153 | * of MSI-X interrupts. |
| 154 | */ |
Hidetoshi Seto | 12abb8b | 2009-06-24 12:08:09 +0900 | [diff] [blame] | 155 | static u32 __msix_mask_irq(struct msi_desc *desc, u32 flag) |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 156 | { |
| 157 | u32 mask_bits = desc->masked; |
| 158 | unsigned offset = desc->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE + |
Hidetoshi Seto | 2c21fd4 | 2009-06-23 17:40:04 +0900 | [diff] [blame] | 159 | PCI_MSIX_ENTRY_VECTOR_CTRL; |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 160 | mask_bits &= ~1; |
| 161 | mask_bits |= flag; |
| 162 | writel(mask_bits, desc->mask_base + offset); |
Hidetoshi Seto | 12abb8b | 2009-06-24 12:08:09 +0900 | [diff] [blame] | 163 | |
| 164 | return mask_bits; |
| 165 | } |
| 166 | |
| 167 | static void msix_mask_irq(struct msi_desc *desc, u32 flag) |
| 168 | { |
| 169 | desc->masked = __msix_mask_irq(desc, flag); |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | static void msi_set_mask_bit(unsigned irq, u32 flag) |
| 173 | { |
| 174 | struct msi_desc *desc = get_irq_msi(irq); |
| 175 | |
| 176 | if (desc->msi_attrib.is_msix) { |
| 177 | msix_mask_irq(desc, flag); |
| 178 | readl(desc->mask_base); /* Flush write to device */ |
Matthew Wilcox | 24d2755 | 2009-03-17 08:54:06 -0400 | [diff] [blame] | 179 | } else { |
Matthew Wilcox | 1c8d7b0 | 2009-03-17 08:54:10 -0400 | [diff] [blame] | 180 | unsigned offset = irq - desc->dev->irq; |
| 181 | msi_mask_irq(desc, 1 << offset, flag << offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | void mask_msi_irq(unsigned int irq) |
| 186 | { |
| 187 | msi_set_mask_bit(irq, 1); |
| 188 | } |
| 189 | |
| 190 | void unmask_msi_irq(unsigned int irq) |
| 191 | { |
| 192 | msi_set_mask_bit(irq, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Yinghai Lu | 3145e94 | 2008-12-05 18:58:34 -0800 | [diff] [blame] | 195 | void read_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg) |
Eric W. Biederman | 0366f8f | 2006-10-04 02:16:33 -0700 | [diff] [blame] | 196 | { |
Yinghai Lu | 3145e94 | 2008-12-05 18:58:34 -0800 | [diff] [blame] | 197 | struct msi_desc *entry = get_irq_desc_msi(desc); |
Matthew Wilcox | 24d2755 | 2009-03-17 08:54:06 -0400 | [diff] [blame] | 198 | if (entry->msi_attrib.is_msix) { |
| 199 | void __iomem *base = entry->mask_base + |
| 200 | entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE; |
| 201 | |
Hidetoshi Seto | 2c21fd4 | 2009-06-23 17:40:04 +0900 | [diff] [blame] | 202 | msg->address_lo = readl(base + PCI_MSIX_ENTRY_LOWER_ADDR); |
| 203 | msg->address_hi = readl(base + PCI_MSIX_ENTRY_UPPER_ADDR); |
| 204 | msg->data = readl(base + PCI_MSIX_ENTRY_DATA); |
Matthew Wilcox | 24d2755 | 2009-03-17 08:54:06 -0400 | [diff] [blame] | 205 | } else { |
Eric W. Biederman | 0366f8f | 2006-10-04 02:16:33 -0700 | [diff] [blame] | 206 | struct pci_dev *dev = entry->dev; |
| 207 | int pos = entry->msi_attrib.pos; |
| 208 | u16 data; |
| 209 | |
| 210 | pci_read_config_dword(dev, msi_lower_address_reg(pos), |
| 211 | &msg->address_lo); |
| 212 | if (entry->msi_attrib.is_64) { |
| 213 | pci_read_config_dword(dev, msi_upper_address_reg(pos), |
| 214 | &msg->address_hi); |
| 215 | pci_read_config_word(dev, msi_data_reg(pos, 1), &data); |
| 216 | } else { |
| 217 | msg->address_hi = 0; |
Roland Dreier | cbf5d9e | 2007-10-03 11:15:11 -0700 | [diff] [blame] | 218 | pci_read_config_word(dev, msi_data_reg(pos, 0), &data); |
Eric W. Biederman | 0366f8f | 2006-10-04 02:16:33 -0700 | [diff] [blame] | 219 | } |
| 220 | msg->data = data; |
Eric W. Biederman | 0366f8f | 2006-10-04 02:16:33 -0700 | [diff] [blame] | 221 | } |
| 222 | } |
| 223 | |
Yinghai Lu | 3145e94 | 2008-12-05 18:58:34 -0800 | [diff] [blame] | 224 | void read_msi_msg(unsigned int irq, struct msi_msg *msg) |
Eric W. Biederman | 0366f8f | 2006-10-04 02:16:33 -0700 | [diff] [blame] | 225 | { |
Yinghai Lu | 3145e94 | 2008-12-05 18:58:34 -0800 | [diff] [blame] | 226 | struct irq_desc *desc = irq_to_desc(irq); |
| 227 | |
| 228 | read_msi_msg_desc(desc, msg); |
| 229 | } |
| 230 | |
| 231 | void write_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg) |
| 232 | { |
| 233 | struct msi_desc *entry = get_irq_desc_msi(desc); |
Matthew Wilcox | 24d2755 | 2009-03-17 08:54:06 -0400 | [diff] [blame] | 234 | if (entry->msi_attrib.is_msix) { |
| 235 | void __iomem *base; |
| 236 | base = entry->mask_base + |
| 237 | entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE; |
| 238 | |
Hidetoshi Seto | 2c21fd4 | 2009-06-23 17:40:04 +0900 | [diff] [blame] | 239 | writel(msg->address_lo, base + PCI_MSIX_ENTRY_LOWER_ADDR); |
| 240 | writel(msg->address_hi, base + PCI_MSIX_ENTRY_UPPER_ADDR); |
| 241 | writel(msg->data, base + PCI_MSIX_ENTRY_DATA); |
Matthew Wilcox | 24d2755 | 2009-03-17 08:54:06 -0400 | [diff] [blame] | 242 | } else { |
Eric W. Biederman | 0366f8f | 2006-10-04 02:16:33 -0700 | [diff] [blame] | 243 | struct pci_dev *dev = entry->dev; |
| 244 | int pos = entry->msi_attrib.pos; |
Matthew Wilcox | 1c8d7b0 | 2009-03-17 08:54:10 -0400 | [diff] [blame] | 245 | u16 msgctl; |
| 246 | |
| 247 | pci_read_config_word(dev, msi_control_reg(pos), &msgctl); |
| 248 | msgctl &= ~PCI_MSI_FLAGS_QSIZE; |
| 249 | msgctl |= entry->msi_attrib.multiple << 4; |
| 250 | pci_write_config_word(dev, msi_control_reg(pos), msgctl); |
Eric W. Biederman | 0366f8f | 2006-10-04 02:16:33 -0700 | [diff] [blame] | 251 | |
| 252 | pci_write_config_dword(dev, msi_lower_address_reg(pos), |
| 253 | msg->address_lo); |
| 254 | if (entry->msi_attrib.is_64) { |
| 255 | pci_write_config_dword(dev, msi_upper_address_reg(pos), |
| 256 | msg->address_hi); |
| 257 | pci_write_config_word(dev, msi_data_reg(pos, 1), |
| 258 | msg->data); |
| 259 | } else { |
| 260 | pci_write_config_word(dev, msi_data_reg(pos, 0), |
| 261 | msg->data); |
| 262 | } |
Eric W. Biederman | 0366f8f | 2006-10-04 02:16:33 -0700 | [diff] [blame] | 263 | } |
Eric W. Biederman | 392ee1e | 2007-03-08 13:04:57 -0700 | [diff] [blame] | 264 | entry->msg = *msg; |
Eric W. Biederman | 0366f8f | 2006-10-04 02:16:33 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Yinghai Lu | 3145e94 | 2008-12-05 18:58:34 -0800 | [diff] [blame] | 267 | void write_msi_msg(unsigned int irq, struct msi_msg *msg) |
| 268 | { |
| 269 | struct irq_desc *desc = irq_to_desc(irq); |
| 270 | |
| 271 | write_msi_msg_desc(desc, msg); |
| 272 | } |
| 273 | |
Hidetoshi Seto | f56e448 | 2009-08-06 11:32:51 +0900 | [diff] [blame] | 274 | static void free_msi_irqs(struct pci_dev *dev) |
| 275 | { |
| 276 | struct msi_desc *entry, *tmp; |
| 277 | |
| 278 | list_for_each_entry(entry, &dev->msi_list, list) { |
| 279 | int i, nvec; |
| 280 | if (!entry->irq) |
| 281 | continue; |
| 282 | nvec = 1 << entry->msi_attrib.multiple; |
| 283 | for (i = 0; i < nvec; i++) |
| 284 | BUG_ON(irq_has_action(entry->irq + i)); |
| 285 | } |
| 286 | |
| 287 | arch_teardown_msi_irqs(dev); |
| 288 | |
| 289 | list_for_each_entry_safe(entry, tmp, &dev->msi_list, list) { |
| 290 | if (entry->msi_attrib.is_msix) { |
| 291 | if (list_is_last(&entry->list, &dev->msi_list)) |
| 292 | iounmap(entry->mask_base); |
| 293 | } |
| 294 | list_del(&entry->list); |
| 295 | kfree(entry); |
| 296 | } |
| 297 | } |
Satoru Takeuchi | c54c187 | 2007-01-18 13:50:05 +0900 | [diff] [blame] | 298 | |
Matthew Wilcox | 379f532 | 2009-03-17 08:54:07 -0400 | [diff] [blame] | 299 | static struct msi_desc *alloc_msi_entry(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | { |
Matthew Wilcox | 379f532 | 2009-03-17 08:54:07 -0400 | [diff] [blame] | 301 | struct msi_desc *desc = kzalloc(sizeof(*desc), GFP_KERNEL); |
| 302 | if (!desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | return NULL; |
| 304 | |
Matthew Wilcox | 379f532 | 2009-03-17 08:54:07 -0400 | [diff] [blame] | 305 | INIT_LIST_HEAD(&desc->list); |
| 306 | desc->dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
Matthew Wilcox | 379f532 | 2009-03-17 08:54:07 -0400 | [diff] [blame] | 308 | return desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
| 310 | |
David Miller | ba698ad | 2007-10-25 01:16:30 -0700 | [diff] [blame] | 311 | static void pci_intx_for_msi(struct pci_dev *dev, int enable) |
| 312 | { |
| 313 | if (!(dev->dev_flags & PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG)) |
| 314 | pci_intx(dev, enable); |
| 315 | } |
| 316 | |
Michael Ellerman | 8fed4b6 | 2007-01-25 19:34:08 +1100 | [diff] [blame] | 317 | static void __pci_restore_msi_state(struct pci_dev *dev) |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 318 | { |
Eric W. Biederman | 392ee1e | 2007-03-08 13:04:57 -0700 | [diff] [blame] | 319 | int pos; |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 320 | u16 control; |
Eric W. Biederman | 392ee1e | 2007-03-08 13:04:57 -0700 | [diff] [blame] | 321 | struct msi_desc *entry; |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 322 | |
Eric W. Biederman | b1cbf4e | 2007-03-05 00:30:10 -0800 | [diff] [blame] | 323 | if (!dev->msi_enabled) |
| 324 | return; |
| 325 | |
Eric W. Biederman | 392ee1e | 2007-03-08 13:04:57 -0700 | [diff] [blame] | 326 | entry = get_irq_msi(dev->irq); |
| 327 | pos = entry->msi_attrib.pos; |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 328 | |
David Miller | ba698ad | 2007-10-25 01:16:30 -0700 | [diff] [blame] | 329 | pci_intx_for_msi(dev, 0); |
Matthew Wilcox | 110828c | 2009-06-16 06:31:45 -0600 | [diff] [blame] | 330 | msi_set_enable(dev, pos, 0); |
Eric W. Biederman | 392ee1e | 2007-03-08 13:04:57 -0700 | [diff] [blame] | 331 | write_msi_msg(dev->irq, &entry->msg); |
Eric W. Biederman | 392ee1e | 2007-03-08 13:04:57 -0700 | [diff] [blame] | 332 | |
| 333 | pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control); |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 334 | msi_mask_irq(entry, msi_capable_mask(control), entry->masked); |
Jesse Barnes | abad2ec | 2008-08-07 08:52:37 -0700 | [diff] [blame] | 335 | control &= ~PCI_MSI_FLAGS_QSIZE; |
Matthew Wilcox | 1c8d7b0 | 2009-03-17 08:54:10 -0400 | [diff] [blame] | 336 | control |= (entry->msi_attrib.multiple << 4) | PCI_MSI_FLAGS_ENABLE; |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 337 | pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control); |
Michael Ellerman | 8fed4b6 | 2007-01-25 19:34:08 +1100 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | static void __pci_restore_msix_state(struct pci_dev *dev) |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 341 | { |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 342 | int pos; |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 343 | struct msi_desc *entry; |
Eric W. Biederman | 392ee1e | 2007-03-08 13:04:57 -0700 | [diff] [blame] | 344 | u16 control; |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 345 | |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 346 | if (!dev->msix_enabled) |
| 347 | return; |
Matthew Wilcox | f598282 | 2009-06-18 19:15:59 -0700 | [diff] [blame] | 348 | BUG_ON(list_empty(&dev->msi_list)); |
Hidetoshi Seto | 9cc8d54 | 2009-08-06 11:32:04 +0900 | [diff] [blame] | 349 | entry = list_first_entry(&dev->msi_list, struct msi_desc, list); |
Matthew Wilcox | f598282 | 2009-06-18 19:15:59 -0700 | [diff] [blame] | 350 | pos = entry->msi_attrib.pos; |
| 351 | pci_read_config_word(dev, pos + PCI_MSIX_FLAGS, &control); |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 352 | |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 353 | /* route the table */ |
David Miller | ba698ad | 2007-10-25 01:16:30 -0700 | [diff] [blame] | 354 | pci_intx_for_msi(dev, 0); |
Matthew Wilcox | f598282 | 2009-06-18 19:15:59 -0700 | [diff] [blame] | 355 | control |= PCI_MSIX_FLAGS_ENABLE | PCI_MSIX_FLAGS_MASKALL; |
| 356 | pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control); |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 357 | |
Michael Ellerman | 4aa9bc9 | 2007-04-05 17:19:10 +1000 | [diff] [blame] | 358 | list_for_each_entry(entry, &dev->msi_list, list) { |
| 359 | write_msi_msg(entry->irq, &entry->msg); |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 360 | msix_mask_irq(entry, entry->masked); |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 361 | } |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 362 | |
Eric W. Biederman | 392ee1e | 2007-03-08 13:04:57 -0700 | [diff] [blame] | 363 | control &= ~PCI_MSIX_FLAGS_MASKALL; |
Eric W. Biederman | 392ee1e | 2007-03-08 13:04:57 -0700 | [diff] [blame] | 364 | pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control); |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 365 | } |
Michael Ellerman | 8fed4b6 | 2007-01-25 19:34:08 +1100 | [diff] [blame] | 366 | |
| 367 | void pci_restore_msi_state(struct pci_dev *dev) |
| 368 | { |
| 369 | __pci_restore_msi_state(dev); |
| 370 | __pci_restore_msix_state(dev); |
| 371 | } |
Linas Vepstas | 94688cf | 2007-11-07 15:43:59 -0600 | [diff] [blame] | 372 | EXPORT_SYMBOL_GPL(pci_restore_msi_state); |
Shaohua Li | 41017f0 | 2006-02-08 17:11:38 +0800 | [diff] [blame] | 373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | /** |
| 375 | * msi_capability_init - configure device's MSI capability structure |
| 376 | * @dev: pointer to the pci_dev data structure of MSI device function |
Matthew Wilcox | 1c8d7b0 | 2009-03-17 08:54:10 -0400 | [diff] [blame] | 377 | * @nvec: number of interrupts to allocate |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | * |
Matthew Wilcox | 1c8d7b0 | 2009-03-17 08:54:10 -0400 | [diff] [blame] | 379 | * Setup the MSI capability structure of the device with the requested |
| 380 | * number of interrupts. A return value of zero indicates the successful |
| 381 | * setup of an entry with the new MSI irq. A negative return value indicates |
| 382 | * an error, and a positive return value indicates the number of interrupts |
| 383 | * which could have been allocated. |
| 384 | */ |
| 385 | static int msi_capability_init(struct pci_dev *dev, int nvec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | { |
| 387 | struct msi_desc *entry; |
Michael Ellerman | 7fe3730 | 2007-04-18 19:39:21 +1000 | [diff] [blame] | 388 | int pos, ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | u16 control; |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 390 | unsigned mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
Hidetoshi Seto | 500559a | 2009-08-10 10:14:15 +0900 | [diff] [blame] | 392 | pos = pci_find_capability(dev, PCI_CAP_ID_MSI); |
Matthew Wilcox | 110828c | 2009-06-16 06:31:45 -0600 | [diff] [blame] | 393 | msi_set_enable(dev, pos, 0); /* Disable MSI during set up */ |
| 394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | pci_read_config_word(dev, msi_control_reg(pos), &control); |
| 396 | /* MSI Entry Initialization */ |
Matthew Wilcox | 379f532 | 2009-03-17 08:54:07 -0400 | [diff] [blame] | 397 | entry = alloc_msi_entry(dev); |
Eric W. Biederman | f7feaca | 2007-01-28 12:56:37 -0700 | [diff] [blame] | 398 | if (!entry) |
| 399 | return -ENOMEM; |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 400 | |
Hidetoshi Seto | 500559a | 2009-08-10 10:14:15 +0900 | [diff] [blame] | 401 | entry->msi_attrib.is_msix = 0; |
| 402 | entry->msi_attrib.is_64 = is_64bit_address(control); |
| 403 | entry->msi_attrib.entry_nr = 0; |
| 404 | entry->msi_attrib.maskbit = is_mask_bit_support(control); |
| 405 | entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */ |
| 406 | entry->msi_attrib.pos = pos; |
Hidetoshi Seto | 0db29af | 2008-12-24 17:27:04 +0900 | [diff] [blame] | 407 | |
Hidetoshi Seto | 67b5db6 | 2009-04-20 10:54:59 +0900 | [diff] [blame] | 408 | entry->mask_pos = msi_mask_reg(pos, entry->msi_attrib.is_64); |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 409 | /* All MSIs are unmasked by default, Mask them all */ |
| 410 | if (entry->msi_attrib.maskbit) |
| 411 | pci_read_config_dword(dev, entry->mask_pos, &entry->masked); |
| 412 | mask = msi_capable_mask(control); |
| 413 | msi_mask_irq(entry, mask, mask); |
| 414 | |
Eric W. Biederman | 0dd11f9 | 2007-06-01 00:46:32 -0700 | [diff] [blame] | 415 | list_add_tail(&entry->list, &dev->msi_list); |
Michael Ellerman | 9c83133 | 2007-04-18 19:39:21 +1000 | [diff] [blame] | 416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | /* Configure MSI capability structure */ |
Matthew Wilcox | 1c8d7b0 | 2009-03-17 08:54:10 -0400 | [diff] [blame] | 418 | ret = arch_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSI); |
Michael Ellerman | 7fe3730 | 2007-04-18 19:39:21 +1000 | [diff] [blame] | 419 | if (ret) { |
Hidetoshi Seto | 7ba1930 | 2009-06-23 17:39:27 +0900 | [diff] [blame] | 420 | msi_mask_irq(entry, mask, ~mask); |
Hidetoshi Seto | f56e448 | 2009-08-06 11:32:51 +0900 | [diff] [blame] | 421 | free_msi_irqs(dev); |
Michael Ellerman | 7fe3730 | 2007-04-18 19:39:21 +1000 | [diff] [blame] | 422 | return ret; |
Mark Maule | fd58e55 | 2006-04-10 21:17:48 -0500 | [diff] [blame] | 423 | } |
Eric W. Biederman | f7feaca | 2007-01-28 12:56:37 -0700 | [diff] [blame] | 424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | /* Set MSI enabled bits */ |
David Miller | ba698ad | 2007-10-25 01:16:30 -0700 | [diff] [blame] | 426 | pci_intx_for_msi(dev, 0); |
Matthew Wilcox | 110828c | 2009-06-16 06:31:45 -0600 | [diff] [blame] | 427 | msi_set_enable(dev, pos, 1); |
Eric W. Biederman | b1cbf4e | 2007-03-05 00:30:10 -0800 | [diff] [blame] | 428 | dev->msi_enabled = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
Michael Ellerman | 7fe3730 | 2007-04-18 19:39:21 +1000 | [diff] [blame] | 430 | dev->irq = entry->irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | return 0; |
| 432 | } |
| 433 | |
Hidetoshi Seto | 5a05a9d | 2009-08-06 11:34:34 +0900 | [diff] [blame] | 434 | static void __iomem *msix_map_region(struct pci_dev *dev, unsigned pos, |
| 435 | unsigned nr_entries) |
| 436 | { |
| 437 | unsigned long phys_addr; |
| 438 | u32 table_offset; |
| 439 | u8 bir; |
| 440 | |
| 441 | pci_read_config_dword(dev, msix_table_offset_reg(pos), &table_offset); |
| 442 | bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK); |
| 443 | table_offset &= ~PCI_MSIX_FLAGS_BIRMASK; |
| 444 | phys_addr = pci_resource_start(dev, bir) + table_offset; |
| 445 | |
| 446 | return ioremap_nocache(phys_addr, nr_entries * PCI_MSIX_ENTRY_SIZE); |
| 447 | } |
| 448 | |
Hidetoshi Seto | d9d7070 | 2009-08-06 11:35:48 +0900 | [diff] [blame] | 449 | static int msix_setup_entries(struct pci_dev *dev, unsigned pos, |
| 450 | void __iomem *base, struct msix_entry *entries, |
| 451 | int nvec) |
| 452 | { |
| 453 | struct msi_desc *entry; |
| 454 | int i; |
| 455 | |
| 456 | for (i = 0; i < nvec; i++) { |
| 457 | entry = alloc_msi_entry(dev); |
| 458 | if (!entry) { |
| 459 | if (!i) |
| 460 | iounmap(base); |
| 461 | else |
| 462 | free_msi_irqs(dev); |
| 463 | /* No enough memory. Don't try again */ |
| 464 | return -ENOMEM; |
| 465 | } |
| 466 | |
| 467 | entry->msi_attrib.is_msix = 1; |
| 468 | entry->msi_attrib.is_64 = 1; |
| 469 | entry->msi_attrib.entry_nr = entries[i].entry; |
| 470 | entry->msi_attrib.default_irq = dev->irq; |
| 471 | entry->msi_attrib.pos = pos; |
| 472 | entry->mask_base = base; |
| 473 | |
| 474 | list_add_tail(&entry->list, &dev->msi_list); |
| 475 | } |
| 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | |
Hidetoshi Seto | 75cb342 | 2009-08-06 11:35:10 +0900 | [diff] [blame] | 480 | static void msix_program_entries(struct pci_dev *dev, |
| 481 | struct msix_entry *entries) |
| 482 | { |
| 483 | struct msi_desc *entry; |
| 484 | int i = 0; |
| 485 | |
| 486 | list_for_each_entry(entry, &dev->msi_list, list) { |
| 487 | int offset = entries[i].entry * PCI_MSIX_ENTRY_SIZE + |
| 488 | PCI_MSIX_ENTRY_VECTOR_CTRL; |
| 489 | |
| 490 | entries[i].vector = entry->irq; |
| 491 | set_irq_msi(entry->irq, entry); |
| 492 | entry->masked = readl(entry->mask_base + offset); |
| 493 | msix_mask_irq(entry, 1); |
| 494 | i++; |
| 495 | } |
| 496 | } |
| 497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | /** |
| 499 | * msix_capability_init - configure device's MSI-X capability |
| 500 | * @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] | 501 | * @entries: pointer to an array of struct msix_entry entries |
| 502 | * @nvec: number of @entries |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | * |
Steven Cole | eaae4b3 | 2005-05-03 18:38:30 -0600 | [diff] [blame] | 504 | * Setup the MSI-X capability structure of device function with a |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 505 | * single MSI-X irq. A return of zero indicates the successful setup of |
| 506 | * requested MSI-X entries with allocated irqs or non-zero for otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | **/ |
| 508 | static int msix_capability_init(struct pci_dev *dev, |
| 509 | struct msix_entry *entries, int nvec) |
| 510 | { |
Hidetoshi Seto | d9d7070 | 2009-08-06 11:35:48 +0900 | [diff] [blame] | 511 | int pos, ret; |
Hidetoshi Seto | 5a05a9d | 2009-08-06 11:34:34 +0900 | [diff] [blame] | 512 | u16 control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | void __iomem *base; |
| 514 | |
Hidetoshi Seto | 500559a | 2009-08-10 10:14:15 +0900 | [diff] [blame] | 515 | pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); |
Matthew Wilcox | f598282 | 2009-06-18 19:15:59 -0700 | [diff] [blame] | 516 | pci_read_config_word(dev, pos + PCI_MSIX_FLAGS, &control); |
| 517 | |
| 518 | /* Ensure MSI-X is disabled while it is set up */ |
| 519 | control &= ~PCI_MSIX_FLAGS_ENABLE; |
| 520 | pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control); |
| 521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | /* Request & Map MSI-X table region */ |
Hidetoshi Seto | 5a05a9d | 2009-08-06 11:34:34 +0900 | [diff] [blame] | 523 | base = msix_map_region(dev, pos, multi_msix_capable(control)); |
| 524 | if (!base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | return -ENOMEM; |
| 526 | |
Hidetoshi Seto | d9d7070 | 2009-08-06 11:35:48 +0900 | [diff] [blame] | 527 | ret = msix_setup_entries(dev, pos, base, entries, nvec); |
| 528 | if (ret) |
| 529 | return ret; |
Michael Ellerman | 9c83133 | 2007-04-18 19:39:21 +1000 | [diff] [blame] | 530 | |
| 531 | ret = arch_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSIX); |
Hidetoshi Seto | 583871d | 2009-08-06 11:33:39 +0900 | [diff] [blame] | 532 | if (ret) |
| 533 | goto error; |
Michael Ellerman | 9c83133 | 2007-04-18 19:39:21 +1000 | [diff] [blame] | 534 | |
Matthew Wilcox | f598282 | 2009-06-18 19:15:59 -0700 | [diff] [blame] | 535 | /* |
| 536 | * Some devices require MSI-X to be enabled before we can touch the |
| 537 | * MSI-X registers. We need to mask all the vectors to prevent |
| 538 | * interrupts coming in before they're fully set up. |
| 539 | */ |
| 540 | control |= PCI_MSIX_FLAGS_MASKALL | PCI_MSIX_FLAGS_ENABLE; |
| 541 | pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control); |
| 542 | |
Hidetoshi Seto | 75cb342 | 2009-08-06 11:35:10 +0900 | [diff] [blame] | 543 | msix_program_entries(dev, entries); |
Matthew Wilcox | f598282 | 2009-06-18 19:15:59 -0700 | [diff] [blame] | 544 | |
| 545 | /* Set MSI-X enabled bits and unmask the function */ |
David Miller | ba698ad | 2007-10-25 01:16:30 -0700 | [diff] [blame] | 546 | pci_intx_for_msi(dev, 0); |
Eric W. Biederman | b1cbf4e | 2007-03-05 00:30:10 -0800 | [diff] [blame] | 547 | dev->msix_enabled = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | |
Matthew Wilcox | f598282 | 2009-06-18 19:15:59 -0700 | [diff] [blame] | 549 | control &= ~PCI_MSIX_FLAGS_MASKALL; |
| 550 | pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control); |
Matthew Wilcox | 8d18101 | 2009-05-08 07:13:33 -0600 | [diff] [blame] | 551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | return 0; |
Hidetoshi Seto | 583871d | 2009-08-06 11:33:39 +0900 | [diff] [blame] | 553 | |
| 554 | error: |
| 555 | if (ret < 0) { |
| 556 | /* |
| 557 | * If we had some success, report the number of irqs |
| 558 | * we succeeded in setting up. |
| 559 | */ |
Hidetoshi Seto | d9d7070 | 2009-08-06 11:35:48 +0900 | [diff] [blame] | 560 | struct msi_desc *entry; |
Hidetoshi Seto | 583871d | 2009-08-06 11:33:39 +0900 | [diff] [blame] | 561 | int avail = 0; |
| 562 | |
| 563 | list_for_each_entry(entry, &dev->msi_list, list) { |
| 564 | if (entry->irq != 0) |
| 565 | avail++; |
| 566 | } |
| 567 | if (avail != 0) |
| 568 | ret = avail; |
| 569 | } |
| 570 | |
| 571 | free_msi_irqs(dev); |
| 572 | |
| 573 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | /** |
Michael Ellerman | 17bbc12 | 2007-04-05 17:19:07 +1000 | [diff] [blame] | 577 | * pci_msi_check_device - check whether MSI may be enabled on a device |
Brice Goglin | 24334a1 | 2006-08-31 01:55:07 -0400 | [diff] [blame] | 578 | * @dev: pointer to the pci_dev data structure of MSI device function |
Michael Ellerman | c9953a7 | 2007-04-05 17:19:08 +1000 | [diff] [blame] | 579 | * @nvec: how many MSIs have been requested ? |
Michael Ellerman | b1e2303 | 2007-03-22 21:51:39 +1100 | [diff] [blame] | 580 | * @type: are we checking for MSI or MSI-X ? |
Brice Goglin | 24334a1 | 2006-08-31 01:55:07 -0400 | [diff] [blame] | 581 | * |
Brice Goglin | 0306ebf | 2006-10-05 10:24:31 +0200 | [diff] [blame] | 582 | * Look at global flags, the device itself, and its parent busses |
Michael Ellerman | 17bbc12 | 2007-04-05 17:19:07 +1000 | [diff] [blame] | 583 | * to determine if MSI/-X are supported for the device. If MSI/-X is |
| 584 | * supported return 0, else return an error code. |
Brice Goglin | 24334a1 | 2006-08-31 01:55:07 -0400 | [diff] [blame] | 585 | **/ |
Hidetoshi Seto | 500559a | 2009-08-10 10:14:15 +0900 | [diff] [blame] | 586 | static int pci_msi_check_device(struct pci_dev *dev, int nvec, int type) |
Brice Goglin | 24334a1 | 2006-08-31 01:55:07 -0400 | [diff] [blame] | 587 | { |
| 588 | struct pci_bus *bus; |
Michael Ellerman | c9953a7 | 2007-04-05 17:19:08 +1000 | [diff] [blame] | 589 | int ret; |
Brice Goglin | 24334a1 | 2006-08-31 01:55:07 -0400 | [diff] [blame] | 590 | |
Brice Goglin | 0306ebf | 2006-10-05 10:24:31 +0200 | [diff] [blame] | 591 | /* MSI must be globally enabled and supported by the device */ |
Brice Goglin | 24334a1 | 2006-08-31 01:55:07 -0400 | [diff] [blame] | 592 | if (!pci_msi_enable || !dev || dev->no_msi) |
| 593 | return -EINVAL; |
| 594 | |
Michael Ellerman | 314e77b | 2007-04-05 17:19:12 +1000 | [diff] [blame] | 595 | /* |
| 596 | * You can't ask to have 0 or less MSIs configured. |
| 597 | * a) it's stupid .. |
| 598 | * b) the list manipulation code assumes nvec >= 1. |
| 599 | */ |
| 600 | if (nvec < 1) |
| 601 | return -ERANGE; |
| 602 | |
Hidetoshi Seto | 500559a | 2009-08-10 10:14:15 +0900 | [diff] [blame] | 603 | /* |
| 604 | * Any bridge which does NOT route MSI transactions from its |
| 605 | * secondary bus to its primary bus must set NO_MSI flag on |
Brice Goglin | 0306ebf | 2006-10-05 10:24:31 +0200 | [diff] [blame] | 606 | * the secondary pci_bus. |
| 607 | * We expect only arch-specific PCI host bus controller driver |
| 608 | * or quirks for specific PCI bridges to be setting NO_MSI. |
| 609 | */ |
Brice Goglin | 24334a1 | 2006-08-31 01:55:07 -0400 | [diff] [blame] | 610 | for (bus = dev->bus; bus; bus = bus->parent) |
| 611 | if (bus->bus_flags & PCI_BUS_FLAGS_NO_MSI) |
| 612 | return -EINVAL; |
| 613 | |
Michael Ellerman | c9953a7 | 2007-04-05 17:19:08 +1000 | [diff] [blame] | 614 | ret = arch_msi_check_device(dev, nvec, type); |
| 615 | if (ret) |
| 616 | return ret; |
| 617 | |
Michael Ellerman | b1e2303 | 2007-03-22 21:51:39 +1100 | [diff] [blame] | 618 | if (!pci_find_capability(dev, type)) |
| 619 | return -EINVAL; |
| 620 | |
Brice Goglin | 24334a1 | 2006-08-31 01:55:07 -0400 | [diff] [blame] | 621 | return 0; |
| 622 | } |
| 623 | |
| 624 | /** |
Matthew Wilcox | 1c8d7b0 | 2009-03-17 08:54:10 -0400 | [diff] [blame] | 625 | * pci_enable_msi_block - configure device's MSI capability structure |
| 626 | * @dev: device to configure |
| 627 | * @nvec: number of interrupts to configure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | * |
Matthew Wilcox | 1c8d7b0 | 2009-03-17 08:54:10 -0400 | [diff] [blame] | 629 | * Allocate IRQs for a device with the MSI capability. |
| 630 | * This function returns a negative errno if an error occurs. If it |
| 631 | * is unable to allocate the number of interrupts requested, it returns |
| 632 | * the number of interrupts it might be able to allocate. If it successfully |
| 633 | * allocates at least the number of interrupts requested, it returns 0 and |
| 634 | * updates the @dev's irq member to the lowest new interrupt number; the |
| 635 | * other interrupt numbers allocated to this device are consecutive. |
| 636 | */ |
| 637 | int pci_enable_msi_block(struct pci_dev *dev, unsigned int nvec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | { |
Matthew Wilcox | 1c8d7b0 | 2009-03-17 08:54:10 -0400 | [diff] [blame] | 639 | int status, pos, maxvec; |
| 640 | u16 msgctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
Matthew Wilcox | 1c8d7b0 | 2009-03-17 08:54:10 -0400 | [diff] [blame] | 642 | pos = pci_find_capability(dev, PCI_CAP_ID_MSI); |
| 643 | if (!pos) |
| 644 | return -EINVAL; |
| 645 | pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl); |
| 646 | maxvec = 1 << ((msgctl & PCI_MSI_FLAGS_QMASK) >> 1); |
| 647 | if (nvec > maxvec) |
| 648 | return maxvec; |
| 649 | |
| 650 | status = pci_msi_check_device(dev, nvec, PCI_CAP_ID_MSI); |
Michael Ellerman | c9953a7 | 2007-04-05 17:19:08 +1000 | [diff] [blame] | 651 | if (status) |
| 652 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 654 | WARN_ON(!!dev->msi_enabled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | |
Matthew Wilcox | 1c8d7b0 | 2009-03-17 08:54:10 -0400 | [diff] [blame] | 656 | /* Check whether driver already requested MSI-X irqs */ |
Eric W. Biederman | b1cbf4e | 2007-03-05 00:30:10 -0800 | [diff] [blame] | 657 | if (dev->msix_enabled) { |
Bjorn Helgaas | 80ccba1 | 2008-06-13 10:52:11 -0600 | [diff] [blame] | 658 | dev_info(&dev->dev, "can't enable MSI " |
| 659 | "(MSI-X already enabled)\n"); |
Eric W. Biederman | b1cbf4e | 2007-03-05 00:30:10 -0800 | [diff] [blame] | 660 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | } |
Matthew Wilcox | 1c8d7b0 | 2009-03-17 08:54:10 -0400 | [diff] [blame] | 662 | |
| 663 | status = msi_capability_init(dev, nvec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | return status; |
| 665 | } |
Matthew Wilcox | 1c8d7b0 | 2009-03-17 08:54:10 -0400 | [diff] [blame] | 666 | EXPORT_SYMBOL(pci_enable_msi_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 668 | void pci_msi_shutdown(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | { |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 670 | struct msi_desc *desc; |
| 671 | u32 mask; |
| 672 | u16 ctrl; |
Matthew Wilcox | 110828c | 2009-06-16 06:31:45 -0600 | [diff] [blame] | 673 | unsigned pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | |
Michael Ellerman | 128bc5f | 2007-03-22 21:51:39 +1100 | [diff] [blame] | 675 | if (!pci_msi_enable || !dev || !dev->msi_enabled) |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 676 | return; |
| 677 | |
Matthew Wilcox | 110828c | 2009-06-16 06:31:45 -0600 | [diff] [blame] | 678 | BUG_ON(list_empty(&dev->msi_list)); |
| 679 | desc = list_first_entry(&dev->msi_list, struct msi_desc, list); |
| 680 | pos = desc->msi_attrib.pos; |
| 681 | |
| 682 | msi_set_enable(dev, pos, 0); |
David Miller | ba698ad | 2007-10-25 01:16:30 -0700 | [diff] [blame] | 683 | pci_intx_for_msi(dev, 1); |
Eric W. Biederman | b1cbf4e | 2007-03-05 00:30:10 -0800 | [diff] [blame] | 684 | dev->msi_enabled = 0; |
Eric W. Biederman | 7bd007e | 2006-10-04 02:16:31 -0700 | [diff] [blame] | 685 | |
Hidetoshi Seto | 12abb8b | 2009-06-24 12:08:09 +0900 | [diff] [blame] | 686 | /* Return the device with MSI unmasked as initial states */ |
Matthew Wilcox | 110828c | 2009-06-16 06:31:45 -0600 | [diff] [blame] | 687 | pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &ctrl); |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 688 | mask = msi_capable_mask(ctrl); |
Hidetoshi Seto | 12abb8b | 2009-06-24 12:08:09 +0900 | [diff] [blame] | 689 | /* Keep cached state to be restored */ |
| 690 | __msi_mask_irq(desc, mask, ~mask); |
Michael Ellerman | e387b9e | 2007-03-22 21:51:27 +1100 | [diff] [blame] | 691 | |
| 692 | /* Restore dev->irq to its default pin-assertion irq */ |
Matthew Wilcox | f2440d9 | 2009-03-17 08:54:09 -0400 | [diff] [blame] | 693 | dev->irq = desc->msi_attrib.default_irq; |
Yinghai Lu | d52877c | 2008-04-23 14:58:09 -0700 | [diff] [blame] | 694 | } |
Matthew Wilcox | 24d2755 | 2009-03-17 08:54:06 -0400 | [diff] [blame] | 695 | |
Hidetoshi Seto | 500559a | 2009-08-10 10:14:15 +0900 | [diff] [blame] | 696 | void pci_disable_msi(struct pci_dev *dev) |
Yinghai Lu | d52877c | 2008-04-23 14:58:09 -0700 | [diff] [blame] | 697 | { |
Yinghai Lu | d52877c | 2008-04-23 14:58:09 -0700 | [diff] [blame] | 698 | if (!pci_msi_enable || !dev || !dev->msi_enabled) |
| 699 | return; |
| 700 | |
| 701 | pci_msi_shutdown(dev); |
Hidetoshi Seto | f56e448 | 2009-08-06 11:32:51 +0900 | [diff] [blame] | 702 | free_msi_irqs(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | } |
Michael Ellerman | 4cc086f | 2007-03-22 21:51:34 +1100 | [diff] [blame] | 704 | EXPORT_SYMBOL(pci_disable_msi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | /** |
Rafael J. Wysocki | a52e2e3 | 2009-01-24 00:21:14 +0100 | [diff] [blame] | 707 | * pci_msix_table_size - return the number of device's MSI-X table entries |
| 708 | * @dev: pointer to the pci_dev data structure of MSI-X device function |
| 709 | */ |
| 710 | int pci_msix_table_size(struct pci_dev *dev) |
| 711 | { |
| 712 | int pos; |
| 713 | u16 control; |
| 714 | |
| 715 | pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); |
| 716 | if (!pos) |
| 717 | return 0; |
| 718 | |
| 719 | pci_read_config_word(dev, msi_control_reg(pos), &control); |
| 720 | return multi_msix_capable(control); |
| 721 | } |
| 722 | |
| 723 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | * pci_enable_msix - configure device's MSI-X capability structure |
| 725 | * @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] | 726 | * @entries: pointer to an array of MSI-X entries |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 727 | * @nvec: number of MSI-X irqs requested for allocation by device driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | * |
| 729 | * 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] | 730 | * of requested irqs upon its software driver call to request for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | * MSI-X mode enabled on its hardware device function. A return of zero |
| 732 | * indicates the successful configuration of MSI-X capability structure |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 733 | * 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] | 734 | * Or a return of > 0 indicates that driver request is exceeding the number |
Michael S. Tsirkin | 57fbf52 | 2009-05-07 11:28:41 +0300 | [diff] [blame] | 735 | * of irqs or MSI-X vectors available. Driver should use the returned value to |
| 736 | * re-send its request. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | **/ |
Hidetoshi Seto | 500559a | 2009-08-10 10:14:15 +0900 | [diff] [blame] | 738 | int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | { |
Rafael J. Wysocki | a52e2e3 | 2009-01-24 00:21:14 +0100 | [diff] [blame] | 740 | int status, nr_entries; |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 741 | int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | |
Michael Ellerman | c9953a7 | 2007-04-05 17:19:08 +1000 | [diff] [blame] | 743 | if (!entries) |
Hidetoshi Seto | 500559a | 2009-08-10 10:14:15 +0900 | [diff] [blame] | 744 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | |
Michael Ellerman | c9953a7 | 2007-04-05 17:19:08 +1000 | [diff] [blame] | 746 | status = pci_msi_check_device(dev, nvec, PCI_CAP_ID_MSIX); |
| 747 | if (status) |
| 748 | return status; |
| 749 | |
Rafael J. Wysocki | a52e2e3 | 2009-01-24 00:21:14 +0100 | [diff] [blame] | 750 | nr_entries = pci_msix_table_size(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | if (nvec > nr_entries) |
Michael S. Tsirkin | 57fbf52 | 2009-05-07 11:28:41 +0300 | [diff] [blame] | 752 | return nr_entries; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | |
| 754 | /* Check for any invalid entries */ |
| 755 | for (i = 0; i < nvec; i++) { |
| 756 | if (entries[i].entry >= nr_entries) |
| 757 | return -EINVAL; /* invalid entry */ |
| 758 | for (j = i + 1; j < nvec; j++) { |
| 759 | if (entries[i].entry == entries[j].entry) |
| 760 | return -EINVAL; /* duplicate entry */ |
| 761 | } |
| 762 | } |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 763 | WARN_ON(!!dev->msix_enabled); |
Eric W. Biederman | 7bd007e | 2006-10-04 02:16:31 -0700 | [diff] [blame] | 764 | |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 765 | /* Check whether driver already requested for MSI irq */ |
Hidetoshi Seto | 500559a | 2009-08-10 10:14:15 +0900 | [diff] [blame] | 766 | if (dev->msi_enabled) { |
Bjorn Helgaas | 80ccba1 | 2008-06-13 10:52:11 -0600 | [diff] [blame] | 767 | dev_info(&dev->dev, "can't enable MSI-X " |
| 768 | "(MSI IRQ already assigned)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | return -EINVAL; |
| 770 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | status = msix_capability_init(dev, entries, nvec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | return status; |
| 773 | } |
Michael Ellerman | 4cc086f | 2007-03-22 21:51:34 +1100 | [diff] [blame] | 774 | EXPORT_SYMBOL(pci_enable_msix); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | |
Hidetoshi Seto | 500559a | 2009-08-10 10:14:15 +0900 | [diff] [blame] | 776 | void pci_msix_shutdown(struct pci_dev *dev) |
Michael Ellerman | fc4afc7 | 2007-03-22 21:51:33 +1100 | [diff] [blame] | 777 | { |
Hidetoshi Seto | 12abb8b | 2009-06-24 12:08:09 +0900 | [diff] [blame] | 778 | struct msi_desc *entry; |
| 779 | |
Michael Ellerman | 128bc5f | 2007-03-22 21:51:39 +1100 | [diff] [blame] | 780 | if (!pci_msi_enable || !dev || !dev->msix_enabled) |
Eric W. Biederman | ded86d8 | 2007-01-28 12:42:52 -0700 | [diff] [blame] | 781 | return; |
| 782 | |
Hidetoshi Seto | 12abb8b | 2009-06-24 12:08:09 +0900 | [diff] [blame] | 783 | /* Return the device with MSI-X masked as initial states */ |
| 784 | list_for_each_entry(entry, &dev->msi_list, list) { |
| 785 | /* Keep cached states to be restored */ |
| 786 | __msix_mask_irq(entry, 1); |
| 787 | } |
| 788 | |
Eric W. Biederman | b1cbf4e | 2007-03-05 00:30:10 -0800 | [diff] [blame] | 789 | msix_set_enable(dev, 0); |
David Miller | ba698ad | 2007-10-25 01:16:30 -0700 | [diff] [blame] | 790 | pci_intx_for_msi(dev, 1); |
Eric W. Biederman | b1cbf4e | 2007-03-05 00:30:10 -0800 | [diff] [blame] | 791 | dev->msix_enabled = 0; |
Yinghai Lu | d52877c | 2008-04-23 14:58:09 -0700 | [diff] [blame] | 792 | } |
Hidetoshi Seto | c901851 | 2009-08-06 11:31:27 +0900 | [diff] [blame] | 793 | |
Hidetoshi Seto | 500559a | 2009-08-10 10:14:15 +0900 | [diff] [blame] | 794 | void pci_disable_msix(struct pci_dev *dev) |
Yinghai Lu | d52877c | 2008-04-23 14:58:09 -0700 | [diff] [blame] | 795 | { |
| 796 | if (!pci_msi_enable || !dev || !dev->msix_enabled) |
| 797 | return; |
| 798 | |
| 799 | pci_msix_shutdown(dev); |
Hidetoshi Seto | f56e448 | 2009-08-06 11:32:51 +0900 | [diff] [blame] | 800 | free_msi_irqs(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | } |
Michael Ellerman | 4cc086f | 2007-03-22 21:51:34 +1100 | [diff] [blame] | 802 | EXPORT_SYMBOL(pci_disable_msix); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
| 804 | /** |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 805 | * msi_remove_pci_irq_vectors - reclaim MSI(X) irqs to unused state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | * @dev: pointer to the pci_dev data structure of MSI(X) device function |
| 807 | * |
Steven Cole | eaae4b3 | 2005-05-03 18:38:30 -0600 | [diff] [blame] | 808 | * Being called during hotplug remove, from which the device function |
Eric W. Biederman | 1ce0337 | 2006-10-04 02:16:41 -0700 | [diff] [blame] | 809 | * is hot-removed. All previous assigned MSI/MSI-X irqs, if |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | * allocated for this device function, are reclaimed to unused state, |
| 811 | * which may be used later on. |
| 812 | **/ |
Hidetoshi Seto | 500559a | 2009-08-10 10:14:15 +0900 | [diff] [blame] | 813 | void msi_remove_pci_irq_vectors(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | if (!pci_msi_enable || !dev) |
Hidetoshi Seto | 500559a | 2009-08-10 10:14:15 +0900 | [diff] [blame] | 816 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
Hidetoshi Seto | f56e448 | 2009-08-06 11:32:51 +0900 | [diff] [blame] | 818 | if (dev->msi_enabled || dev->msix_enabled) |
| 819 | free_msi_irqs(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | } |
| 821 | |
Matthew Wilcox | 309e57d | 2006-03-05 22:33:34 -0700 | [diff] [blame] | 822 | void pci_no_msi(void) |
| 823 | { |
| 824 | pci_msi_enable = 0; |
| 825 | } |
Michael Ellerman | c9953a7 | 2007-04-05 17:19:08 +1000 | [diff] [blame] | 826 | |
Andrew Patterson | 07ae95f | 2008-11-10 15:31:05 -0700 | [diff] [blame] | 827 | /** |
| 828 | * pci_msi_enabled - is MSI enabled? |
| 829 | * |
| 830 | * Returns true if MSI has not been disabled by the command-line option |
| 831 | * pci=nomsi. |
| 832 | **/ |
| 833 | int pci_msi_enabled(void) |
| 834 | { |
| 835 | return pci_msi_enable; |
| 836 | } |
| 837 | EXPORT_SYMBOL(pci_msi_enabled); |
| 838 | |
Michael Ellerman | 4aa9bc9 | 2007-04-05 17:19:10 +1000 | [diff] [blame] | 839 | void pci_msi_init_pci_dev(struct pci_dev *dev) |
| 840 | { |
| 841 | INIT_LIST_HEAD(&dev->msi_list); |
| 842 | } |