blob: baba2eb5367df54bcc947333beda7e56332f3785 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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. Biederman1ce03372006-10-04 02:16:41 -07009#include <linux/err.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/mm.h>
11#include <linux/irq.h>
12#include <linux/interrupt.h>
13#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/pci.h>
16#include <linux/proc_fs.h>
Eric W. Biederman3b7d1922006-10-04 02:16:59 -070017#include <linux/msi.h>
Dan Williams4fdadeb2007-04-26 18:21:38 -070018#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#include <asm/errno.h>
21#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23#include "pci.h"
24#include "msi.h"
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026static int pci_msi_enable = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Adrian Bunk6a9e7f22007-12-11 23:19:41 +010028/* Arch hooks */
29
30int __attribute__ ((weak))
31arch_msi_check_device(struct pci_dev *dev, int nvec, int type)
32{
33 return 0;
34}
35
36int __attribute__ ((weak))
37arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *entry)
38{
39 return 0;
40}
41
42int __attribute__ ((weak))
43arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
44{
45 struct msi_desc *entry;
46 int ret;
47
48 list_for_each_entry(entry, &dev->msi_list, list) {
49 ret = arch_setup_msi_irq(dev, entry);
50 if (ret)
51 return ret;
52 }
53
54 return 0;
55}
56
57void __attribute__ ((weak)) arch_teardown_msi_irq(unsigned int irq)
58{
59 return;
60}
61
62void __attribute__ ((weak))
63arch_teardown_msi_irqs(struct pci_dev *dev)
64{
65 struct msi_desc *entry;
66
67 list_for_each_entry(entry, &dev->msi_list, list) {
68 if (entry->irq != 0)
69 arch_teardown_msi_irq(entry->irq);
70 }
71}
72
Hidetoshi Seto5ca5c022008-05-19 13:48:17 +090073static void __msi_set_enable(struct pci_dev *dev, int pos, int enable)
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -080074{
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -080075 u16 control;
76
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -080077 if (pos) {
78 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control);
79 control &= ~PCI_MSI_FLAGS_ENABLE;
80 if (enable)
81 control |= PCI_MSI_FLAGS_ENABLE;
82 pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control);
83 }
84}
85
Hidetoshi Seto5ca5c022008-05-19 13:48:17 +090086static void msi_set_enable(struct pci_dev *dev, int enable)
87{
88 __msi_set_enable(dev, pci_find_capability(dev, PCI_CAP_ID_MSI), enable);
89}
90
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -080091static void msix_set_enable(struct pci_dev *dev, int enable)
92{
93 int pos;
94 u16 control;
95
96 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
97 if (pos) {
98 pci_read_config_word(dev, pos + PCI_MSIX_FLAGS, &control);
99 control &= ~PCI_MSIX_FLAGS_ENABLE;
100 if (enable)
101 control |= PCI_MSIX_FLAGS_ENABLE;
102 pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control);
103 }
104}
105
Matthew Wilcoxbffac3c2009-01-21 19:19:19 -0500106static inline __attribute_const__ u32 msi_mask(unsigned x)
107{
Matthew Wilcox0b49ec32009-02-08 20:27:47 -0700108 /* Don't shift by >= width of type */
109 if (x >= 5)
110 return 0xffffffff;
111 return (1 << (1 << x)) - 1;
Matthew Wilcoxbffac3c2009-01-21 19:19:19 -0500112}
113
Yinghai Lu3145e942008-12-05 18:58:34 -0800114static void msix_flush_writes(struct irq_desc *desc)
Mitch Williams988cbb12007-03-30 11:54:08 -0700115{
116 struct msi_desc *entry;
117
Yinghai Lu3145e942008-12-05 18:58:34 -0800118 entry = get_irq_desc_msi(desc);
Mitch Williams988cbb12007-03-30 11:54:08 -0700119 BUG_ON(!entry || !entry->dev);
120 switch (entry->msi_attrib.type) {
121 case PCI_CAP_ID_MSI:
122 /* nothing to do */
123 break;
124 case PCI_CAP_ID_MSIX:
125 {
126 int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE +
127 PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET;
128 readl(entry->mask_base + offset);
129 break;
130 }
131 default:
132 BUG();
133 break;
134 }
135}
136
Matthew Wilcoxce6fce42008-07-25 15:42:58 -0600137/*
138 * PCI 2.3 does not specify mask bits for each MSI interrupt. Attempting to
139 * mask all MSI interrupts by clearing the MSI enable bit does not work
140 * reliably as devices without an INTx disable bit will then generate a
141 * level IRQ which will never be cleared.
142 *
143 * Returns 1 if it succeeded in masking the interrupt and 0 if the device
144 * doesn't support MSI masking.
145 */
Yinghai Lu3145e942008-12-05 18:58:34 -0800146static int msi_set_mask_bits(struct irq_desc *desc, u32 mask, u32 flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
148 struct msi_desc *entry;
149
Yinghai Lu3145e942008-12-05 18:58:34 -0800150 entry = get_irq_desc_msi(desc);
Eric W. Biederman277bc332006-10-04 02:16:57 -0700151 BUG_ON(!entry || !entry->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 switch (entry->msi_attrib.type) {
153 case PCI_CAP_ID_MSI:
Eric W. Biederman277bc332006-10-04 02:16:57 -0700154 if (entry->msi_attrib.maskbit) {
Satoru Takeuchic54c1872007-01-18 13:50:05 +0900155 int pos;
156 u32 mask_bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Eric W. Biederman277bc332006-10-04 02:16:57 -0700158 pos = (long)entry->mask_base;
159 pci_read_config_dword(entry->dev, pos, &mask_bits);
Yinghai Lu8e149e02008-04-23 14:56:30 -0700160 mask_bits &= ~(mask);
161 mask_bits |= flag & mask;
Eric W. Biederman277bc332006-10-04 02:16:57 -0700162 pci_write_config_dword(entry->dev, pos, mask_bits);
Eric W. Biederman58e05432007-03-05 00:30:11 -0800163 } else {
Matthew Wilcoxce6fce42008-07-25 15:42:58 -0600164 return 0;
Eric W. Biederman277bc332006-10-04 02:16:57 -0700165 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 case PCI_CAP_ID_MSIX:
168 {
169 int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE +
170 PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET;
171 writel(flag, entry->mask_base + offset);
Eric W. Biederman348e3fd2007-04-03 01:41:49 -0600172 readl(entry->mask_base + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 break;
174 }
175 default:
Eric W. Biederman277bc332006-10-04 02:16:57 -0700176 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 break;
178 }
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700179 entry->msi_attrib.masked = !!flag;
Matthew Wilcoxce6fce42008-07-25 15:42:58 -0600180 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181}
182
Yinghai Lu3145e942008-12-05 18:58:34 -0800183void read_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700184{
Yinghai Lu3145e942008-12-05 18:58:34 -0800185 struct msi_desc *entry = get_irq_desc_msi(desc);
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700186 switch(entry->msi_attrib.type) {
187 case PCI_CAP_ID_MSI:
188 {
189 struct pci_dev *dev = entry->dev;
190 int pos = entry->msi_attrib.pos;
191 u16 data;
192
193 pci_read_config_dword(dev, msi_lower_address_reg(pos),
194 &msg->address_lo);
195 if (entry->msi_attrib.is_64) {
196 pci_read_config_dword(dev, msi_upper_address_reg(pos),
197 &msg->address_hi);
198 pci_read_config_word(dev, msi_data_reg(pos, 1), &data);
199 } else {
200 msg->address_hi = 0;
Roland Dreiercbf5d9e2007-10-03 11:15:11 -0700201 pci_read_config_word(dev, msi_data_reg(pos, 0), &data);
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700202 }
203 msg->data = data;
204 break;
205 }
206 case PCI_CAP_ID_MSIX:
207 {
208 void __iomem *base;
209 base = entry->mask_base +
210 entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE;
211
212 msg->address_lo = readl(base + PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET);
213 msg->address_hi = readl(base + PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET);
214 msg->data = readl(base + PCI_MSIX_ENTRY_DATA_OFFSET);
215 break;
216 }
217 default:
218 BUG();
219 }
220}
221
Yinghai Lu3145e942008-12-05 18:58:34 -0800222void read_msi_msg(unsigned int irq, struct msi_msg *msg)
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700223{
Yinghai Lu3145e942008-12-05 18:58:34 -0800224 struct irq_desc *desc = irq_to_desc(irq);
225
226 read_msi_msg_desc(desc, msg);
227}
228
229void write_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
230{
231 struct msi_desc *entry = get_irq_desc_msi(desc);
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700232 switch (entry->msi_attrib.type) {
233 case PCI_CAP_ID_MSI:
234 {
235 struct pci_dev *dev = entry->dev;
236 int pos = entry->msi_attrib.pos;
237
238 pci_write_config_dword(dev, msi_lower_address_reg(pos),
239 msg->address_lo);
240 if (entry->msi_attrib.is_64) {
241 pci_write_config_dword(dev, msi_upper_address_reg(pos),
242 msg->address_hi);
243 pci_write_config_word(dev, msi_data_reg(pos, 1),
244 msg->data);
245 } else {
246 pci_write_config_word(dev, msi_data_reg(pos, 0),
247 msg->data);
248 }
249 break;
250 }
251 case PCI_CAP_ID_MSIX:
252 {
253 void __iomem *base;
254 base = entry->mask_base +
255 entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE;
256
257 writel(msg->address_lo,
258 base + PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET);
259 writel(msg->address_hi,
260 base + PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET);
261 writel(msg->data, base + PCI_MSIX_ENTRY_DATA_OFFSET);
262 break;
263 }
264 default:
265 BUG();
266 }
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700267 entry->msg = *msg;
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700268}
269
Yinghai Lu3145e942008-12-05 18:58:34 -0800270void write_msi_msg(unsigned int irq, struct msi_msg *msg)
271{
272 struct irq_desc *desc = irq_to_desc(irq);
273
274 write_msi_msg_desc(desc, msg);
275}
276
Eric W. Biederman3b7d1922006-10-04 02:16:59 -0700277void mask_msi_irq(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
Yinghai Lu3145e942008-12-05 18:58:34 -0800279 struct irq_desc *desc = irq_to_desc(irq);
280
281 msi_set_mask_bits(desc, 1, 1);
282 msix_flush_writes(desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283}
284
Eric W. Biederman3b7d1922006-10-04 02:16:59 -0700285void unmask_msi_irq(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
Yinghai Lu3145e942008-12-05 18:58:34 -0800287 struct irq_desc *desc = irq_to_desc(irq);
288
289 msi_set_mask_bits(desc, 1, 0);
290 msix_flush_writes(desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291}
292
Michael Ellerman032de8e2007-04-18 19:39:22 +1000293static int msi_free_irqs(struct pci_dev* dev);
Satoru Takeuchic54c1872007-01-18 13:50:05 +0900294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295static struct msi_desc* alloc_msi_entry(void)
296{
297 struct msi_desc *entry;
298
Michael Ellerman3e916c02007-03-22 21:51:36 +1100299 entry = kzalloc(sizeof(struct msi_desc), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 if (!entry)
301 return NULL;
302
Michael Ellerman4aa9bc92007-04-05 17:19:10 +1000303 INIT_LIST_HEAD(&entry->list);
304 entry->irq = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 entry->dev = NULL;
306
307 return entry;
308}
309
David Millerba698ad2007-10-25 01:16:30 -0700310static void pci_intx_for_msi(struct pci_dev *dev, int enable)
311{
312 if (!(dev->dev_flags & PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG))
313 pci_intx(dev, enable);
314}
315
Michael Ellerman8fed4b62007-01-25 19:34:08 +1100316static void __pci_restore_msi_state(struct pci_dev *dev)
Shaohua Li41017f02006-02-08 17:11:38 +0800317{
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700318 int pos;
Shaohua Li41017f02006-02-08 17:11:38 +0800319 u16 control;
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700320 struct msi_desc *entry;
Shaohua Li41017f02006-02-08 17:11:38 +0800321
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800322 if (!dev->msi_enabled)
323 return;
324
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700325 entry = get_irq_msi(dev->irq);
326 pos = entry->msi_attrib.pos;
Shaohua Li41017f02006-02-08 17:11:38 +0800327
David Millerba698ad2007-10-25 01:16:30 -0700328 pci_intx_for_msi(dev, 0);
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800329 msi_set_enable(dev, 0);
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700330 write_msi_msg(dev->irq, &entry->msg);
Yinghai Lu3145e942008-12-05 18:58:34 -0800331 if (entry->msi_attrib.maskbit) {
332 struct irq_desc *desc = irq_to_desc(dev->irq);
333 msi_set_mask_bits(desc, entry->msi_attrib.maskbits_mask,
Yinghai Lu8e149e02008-04-23 14:56:30 -0700334 entry->msi_attrib.masked);
Yinghai Lu3145e942008-12-05 18:58:34 -0800335 }
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700336
337 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control);
Jesse Barnesabad2ec2008-08-07 08:52:37 -0700338 control &= ~PCI_MSI_FLAGS_QSIZE;
339 control |= PCI_MSI_FLAGS_ENABLE;
Shaohua Li41017f02006-02-08 17:11:38 +0800340 pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control);
Michael Ellerman8fed4b62007-01-25 19:34:08 +1100341}
342
343static void __pci_restore_msix_state(struct pci_dev *dev)
Shaohua Li41017f02006-02-08 17:11:38 +0800344{
Shaohua Li41017f02006-02-08 17:11:38 +0800345 int pos;
Shaohua Li41017f02006-02-08 17:11:38 +0800346 struct msi_desc *entry;
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700347 u16 control;
Shaohua Li41017f02006-02-08 17:11:38 +0800348
Eric W. Biedermanded86d82007-01-28 12:42:52 -0700349 if (!dev->msix_enabled)
350 return;
351
Shaohua Li41017f02006-02-08 17:11:38 +0800352 /* route the table */
David Millerba698ad2007-10-25 01:16:30 -0700353 pci_intx_for_msi(dev, 0);
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800354 msix_set_enable(dev, 0);
Shaohua Li41017f02006-02-08 17:11:38 +0800355
Michael Ellerman4aa9bc92007-04-05 17:19:10 +1000356 list_for_each_entry(entry, &dev->msi_list, list) {
Yinghai Lu3145e942008-12-05 18:58:34 -0800357 struct irq_desc *desc = irq_to_desc(entry->irq);
Michael Ellerman4aa9bc92007-04-05 17:19:10 +1000358 write_msi_msg(entry->irq, &entry->msg);
Yinghai Lu3145e942008-12-05 18:58:34 -0800359 msi_set_mask_bits(desc, 1, entry->msi_attrib.masked);
Shaohua Li41017f02006-02-08 17:11:38 +0800360 }
Shaohua Li41017f02006-02-08 17:11:38 +0800361
Michael Ellerman314e77b2007-04-05 17:19:12 +1000362 BUG_ON(list_empty(&dev->msi_list));
363 entry = list_entry(dev->msi_list.next, struct msi_desc, list);
Michael Ellerman4aa9bc92007-04-05 17:19:10 +1000364 pos = entry->msi_attrib.pos;
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700365 pci_read_config_word(dev, pos + PCI_MSIX_FLAGS, &control);
366 control &= ~PCI_MSIX_FLAGS_MASKALL;
367 control |= PCI_MSIX_FLAGS_ENABLE;
368 pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control);
Shaohua Li41017f02006-02-08 17:11:38 +0800369}
Michael Ellerman8fed4b62007-01-25 19:34:08 +1100370
371void pci_restore_msi_state(struct pci_dev *dev)
372{
373 __pci_restore_msi_state(dev);
374 __pci_restore_msix_state(dev);
375}
Linas Vepstas94688cf2007-11-07 15:43:59 -0600376EXPORT_SYMBOL_GPL(pci_restore_msi_state);
Shaohua Li41017f02006-02-08 17:11:38 +0800377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378/**
379 * msi_capability_init - configure device's MSI capability structure
380 * @dev: pointer to the pci_dev data structure of MSI device function
381 *
Steven Coleeaae4b32005-05-03 18:38:30 -0600382 * Setup the MSI capability structure of device function with a single
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700383 * MSI irq, regardless of device function is capable of handling
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 * multiple messages. A return of zero indicates the successful setup
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700385 * of an entry zero with the new MSI irq or non-zero for otherwise.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 **/
387static int msi_capability_init(struct pci_dev *dev)
388{
389 struct msi_desc *entry;
Michael Ellerman7fe37302007-04-18 19:39:21 +1000390 int pos, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 u16 control;
392
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800393 msi_set_enable(dev, 0); /* Ensure msi is disabled as I set it up */
394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
396 pci_read_config_word(dev, msi_control_reg(pos), &control);
397 /* MSI Entry Initialization */
Eric W. Biedermanf7feaca2007-01-28 12:56:37 -0700398 entry = alloc_msi_entry();
399 if (!entry)
400 return -ENOMEM;
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700401
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 entry->msi_attrib.type = PCI_CAP_ID_MSI;
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700403 entry->msi_attrib.is_64 = is_64bit_address(control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 entry->msi_attrib.entry_nr = 0;
405 entry->msi_attrib.maskbit = is_mask_bit_support(control);
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700406 entry->msi_attrib.masked = 1;
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700407 entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700408 entry->msi_attrib.pos = pos;
Eric W. Biederman3b7d1922006-10-04 02:16:59 -0700409 entry->dev = dev;
410 if (entry->msi_attrib.maskbit) {
Hidetoshi Seto0db29af2008-12-24 17:27:04 +0900411 unsigned int base, maskbits, temp;
412
413 base = msi_mask_bits_reg(pos, entry->msi_attrib.is_64);
414 entry->mask_base = (void __iomem *)(long)base;
415
Eric W. Biederman3b7d1922006-10-04 02:16:59 -0700416 /* All MSIs are unmasked by default, Mask them all */
Hidetoshi Seto0db29af2008-12-24 17:27:04 +0900417 pci_read_config_dword(dev, base, &maskbits);
Matthew Wilcoxbffac3c2009-01-21 19:19:19 -0500418 temp = msi_mask((control & PCI_MSI_FLAGS_QMASK) >> 1);
Eric W. Biederman3b7d1922006-10-04 02:16:59 -0700419 maskbits |= temp;
Hidetoshi Seto0db29af2008-12-24 17:27:04 +0900420 pci_write_config_dword(dev, base, maskbits);
Yinghai Lu8e149e02008-04-23 14:56:30 -0700421 entry->msi_attrib.maskbits_mask = temp;
Eric W. Biederman3b7d1922006-10-04 02:16:59 -0700422 }
Eric W. Biederman0dd11f92007-06-01 00:46:32 -0700423 list_add_tail(&entry->list, &dev->msi_list);
Michael Ellerman9c831332007-04-18 19:39:21 +1000424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 /* Configure MSI capability structure */
Michael Ellerman9c831332007-04-18 19:39:21 +1000426 ret = arch_setup_msi_irqs(dev, 1, PCI_CAP_ID_MSI);
Michael Ellerman7fe37302007-04-18 19:39:21 +1000427 if (ret) {
Michael Ellerman032de8e2007-04-18 19:39:22 +1000428 msi_free_irqs(dev);
Michael Ellerman7fe37302007-04-18 19:39:21 +1000429 return ret;
Mark Maulefd58e552006-04-10 21:17:48 -0500430 }
Eric W. Biedermanf7feaca2007-01-28 12:56:37 -0700431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 /* Set MSI enabled bits */
David Millerba698ad2007-10-25 01:16:30 -0700433 pci_intx_for_msi(dev, 0);
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800434 msi_set_enable(dev, 1);
435 dev->msi_enabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Michael Ellerman7fe37302007-04-18 19:39:21 +1000437 dev->irq = entry->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 return 0;
439}
440
441/**
442 * msix_capability_init - configure device's MSI-X capability
443 * @dev: pointer to the pci_dev data structure of MSI-X device function
Randy Dunlap8f7020d2005-10-23 11:57:38 -0700444 * @entries: pointer to an array of struct msix_entry entries
445 * @nvec: number of @entries
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 *
Steven Coleeaae4b32005-05-03 18:38:30 -0600447 * Setup the MSI-X capability structure of device function with a
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700448 * single MSI-X irq. A return of zero indicates the successful setup of
449 * requested MSI-X entries with allocated irqs or non-zero for otherwise.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 **/
451static int msix_capability_init(struct pci_dev *dev,
452 struct msix_entry *entries, int nvec)
453{
Michael Ellerman4aa9bc92007-04-05 17:19:10 +1000454 struct msi_desc *entry;
Michael Ellerman9c831332007-04-18 19:39:21 +1000455 int pos, i, j, nr_entries, ret;
Grant Grundlera0454b42006-02-16 23:58:29 -0800456 unsigned long phys_addr;
457 u32 table_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 u16 control;
459 u8 bir;
460 void __iomem *base;
461
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800462 msix_set_enable(dev, 0);/* Ensure msix is disabled as I set it up */
463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
465 /* Request & Map MSI-X table region */
466 pci_read_config_word(dev, msi_control_reg(pos), &control);
467 nr_entries = multi_msix_capable(control);
Grant Grundlera0454b42006-02-16 23:58:29 -0800468
469 pci_read_config_dword(dev, msix_table_offset_reg(pos), &table_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK);
Grant Grundlera0454b42006-02-16 23:58:29 -0800471 table_offset &= ~PCI_MSIX_FLAGS_BIRMASK;
472 phys_addr = pci_resource_start (dev, bir) + table_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 base = ioremap_nocache(phys_addr, nr_entries * PCI_MSIX_ENTRY_SIZE);
474 if (base == NULL)
475 return -ENOMEM;
476
477 /* MSI-X Table Initialization */
478 for (i = 0; i < nvec; i++) {
Eric W. Biedermanf7feaca2007-01-28 12:56:37 -0700479 entry = alloc_msi_entry();
480 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483 j = entries[i].entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 entry->msi_attrib.type = PCI_CAP_ID_MSIX;
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700485 entry->msi_attrib.is_64 = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 entry->msi_attrib.entry_nr = j;
487 entry->msi_attrib.maskbit = 1;
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700488 entry->msi_attrib.masked = 1;
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700489 entry->msi_attrib.default_irq = dev->irq;
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700490 entry->msi_attrib.pos = pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 entry->dev = dev;
492 entry->mask_base = base;
Eric W. Biedermanf7feaca2007-01-28 12:56:37 -0700493
Eric W. Biederman0dd11f92007-06-01 00:46:32 -0700494 list_add_tail(&entry->list, &dev->msi_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 }
Michael Ellerman9c831332007-04-18 19:39:21 +1000496
497 ret = arch_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSIX);
498 if (ret) {
499 int avail = 0;
500 list_for_each_entry(entry, &dev->msi_list, list) {
501 if (entry->irq != 0) {
502 avail++;
Michael Ellerman9c831332007-04-18 19:39:21 +1000503 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 }
Michael Ellerman9c831332007-04-18 19:39:21 +1000505
Michael Ellerman032de8e2007-04-18 19:39:22 +1000506 msi_free_irqs(dev);
507
Eric W. Biederman92db6d12006-10-04 02:16:35 -0700508 /* If we had some success report the number of irqs
509 * we succeeded in setting up.
510 */
Michael Ellerman9c831332007-04-18 19:39:21 +1000511 if (avail == 0)
512 avail = ret;
Eric W. Biederman92db6d12006-10-04 02:16:35 -0700513 return avail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 }
Michael Ellerman9c831332007-04-18 19:39:21 +1000515
516 i = 0;
517 list_for_each_entry(entry, &dev->msi_list, list) {
518 entries[i].vector = entry->irq;
519 set_irq_msi(entry->irq, entry);
520 i++;
521 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 /* Set MSI-X enabled bits */
David Millerba698ad2007-10-25 01:16:30 -0700523 pci_intx_for_msi(dev, 0);
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800524 msix_set_enable(dev, 1);
525 dev->msix_enabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
527 return 0;
528}
529
530/**
Michael Ellerman17bbc122007-04-05 17:19:07 +1000531 * pci_msi_check_device - check whether MSI may be enabled on a device
Brice Goglin24334a12006-08-31 01:55:07 -0400532 * @dev: pointer to the pci_dev data structure of MSI device function
Michael Ellermanc9953a72007-04-05 17:19:08 +1000533 * @nvec: how many MSIs have been requested ?
Michael Ellermanb1e23032007-03-22 21:51:39 +1100534 * @type: are we checking for MSI or MSI-X ?
Brice Goglin24334a12006-08-31 01:55:07 -0400535 *
Brice Goglin0306ebf2006-10-05 10:24:31 +0200536 * Look at global flags, the device itself, and its parent busses
Michael Ellerman17bbc122007-04-05 17:19:07 +1000537 * to determine if MSI/-X are supported for the device. If MSI/-X is
538 * supported return 0, else return an error code.
Brice Goglin24334a12006-08-31 01:55:07 -0400539 **/
Michael Ellermanc9953a72007-04-05 17:19:08 +1000540static int pci_msi_check_device(struct pci_dev* dev, int nvec, int type)
Brice Goglin24334a12006-08-31 01:55:07 -0400541{
542 struct pci_bus *bus;
Michael Ellermanc9953a72007-04-05 17:19:08 +1000543 int ret;
Brice Goglin24334a12006-08-31 01:55:07 -0400544
Brice Goglin0306ebf2006-10-05 10:24:31 +0200545 /* MSI must be globally enabled and supported by the device */
Brice Goglin24334a12006-08-31 01:55:07 -0400546 if (!pci_msi_enable || !dev || dev->no_msi)
547 return -EINVAL;
548
Michael Ellerman314e77b2007-04-05 17:19:12 +1000549 /*
550 * You can't ask to have 0 or less MSIs configured.
551 * a) it's stupid ..
552 * b) the list manipulation code assumes nvec >= 1.
553 */
554 if (nvec < 1)
555 return -ERANGE;
556
Brice Goglin0306ebf2006-10-05 10:24:31 +0200557 /* Any bridge which does NOT route MSI transactions from it's
558 * secondary bus to it's primary bus must set NO_MSI flag on
559 * the secondary pci_bus.
560 * We expect only arch-specific PCI host bus controller driver
561 * or quirks for specific PCI bridges to be setting NO_MSI.
562 */
Brice Goglin24334a12006-08-31 01:55:07 -0400563 for (bus = dev->bus; bus; bus = bus->parent)
564 if (bus->bus_flags & PCI_BUS_FLAGS_NO_MSI)
565 return -EINVAL;
566
Michael Ellermanc9953a72007-04-05 17:19:08 +1000567 ret = arch_msi_check_device(dev, nvec, type);
568 if (ret)
569 return ret;
570
Michael Ellermanb1e23032007-03-22 21:51:39 +1100571 if (!pci_find_capability(dev, type))
572 return -EINVAL;
573
Brice Goglin24334a12006-08-31 01:55:07 -0400574 return 0;
575}
576
577/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 * pci_enable_msi - configure device's MSI capability structure
579 * @dev: pointer to the pci_dev data structure of MSI device function
580 *
581 * Setup the MSI capability structure of device function with
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700582 * a single MSI irq upon its software driver call to request for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 * MSI mode enabled on its hardware device function. A return of zero
584 * indicates the successful setup of an entry zero with the new MSI
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700585 * irq or non-zero for otherwise.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 **/
587int pci_enable_msi(struct pci_dev* dev)
588{
Michael Ellermanb1e23032007-03-22 21:51:39 +1100589 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Michael Ellermanc9953a72007-04-05 17:19:08 +1000591 status = pci_msi_check_device(dev, 1, PCI_CAP_ID_MSI);
592 if (status)
593 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Eric W. Biedermanded86d82007-01-28 12:42:52 -0700595 WARN_ON(!!dev->msi_enabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700597 /* Check whether driver already requested for MSI-X irqs */
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800598 if (dev->msix_enabled) {
Bjorn Helgaas80ccba12008-06-13 10:52:11 -0600599 dev_info(&dev->dev, "can't enable MSI "
600 "(MSI-X already enabled)\n");
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800601 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 }
603 status = msi_capability_init(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 return status;
605}
Michael Ellerman4cc086f2007-03-22 21:51:34 +1100606EXPORT_SYMBOL(pci_enable_msi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Yinghai Lud52877c2008-04-23 14:58:09 -0700608void pci_msi_shutdown(struct pci_dev* dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609{
610 struct msi_desc *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Michael Ellerman128bc5f2007-03-22 21:51:39 +1100612 if (!pci_msi_enable || !dev || !dev->msi_enabled)
Eric W. Biedermanded86d82007-01-28 12:42:52 -0700613 return;
614
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800615 msi_set_enable(dev, 0);
David Millerba698ad2007-10-25 01:16:30 -0700616 pci_intx_for_msi(dev, 1);
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800617 dev->msi_enabled = 0;
Eric W. Biederman7bd007e2006-10-04 02:16:31 -0700618
Michael Ellerman314e77b2007-04-05 17:19:12 +1000619 BUG_ON(list_empty(&dev->msi_list));
620 entry = list_entry(dev->msi_list.next, struct msi_desc, list);
Yinghai Lu8e149e02008-04-23 14:56:30 -0700621 /* Return the the pci reset with msi irqs unmasked */
622 if (entry->msi_attrib.maskbit) {
623 u32 mask = entry->msi_attrib.maskbits_mask;
Yinghai Lu3145e942008-12-05 18:58:34 -0800624 struct irq_desc *desc = irq_to_desc(dev->irq);
625 msi_set_mask_bits(desc, mask, ~mask);
Yinghai Lu8e149e02008-04-23 14:56:30 -0700626 }
Yinghai Lud52877c2008-04-23 14:58:09 -0700627 if (!entry->dev || entry->msi_attrib.type != PCI_CAP_ID_MSI)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 return;
Michael Ellermane387b9e2007-03-22 21:51:27 +1100629
630 /* Restore dev->irq to its default pin-assertion irq */
Yinghai Lud52877c2008-04-23 14:58:09 -0700631 dev->irq = entry->msi_attrib.default_irq;
632}
633void pci_disable_msi(struct pci_dev* dev)
634{
635 struct msi_desc *entry;
636
637 if (!pci_msi_enable || !dev || !dev->msi_enabled)
638 return;
639
640 pci_msi_shutdown(dev);
641
642 entry = list_entry(dev->msi_list.next, struct msi_desc, list);
643 if (!entry->dev || entry->msi_attrib.type != PCI_CAP_ID_MSI)
644 return;
645
646 msi_free_irqs(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647}
Michael Ellerman4cc086f2007-03-22 21:51:34 +1100648EXPORT_SYMBOL(pci_disable_msi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Michael Ellerman032de8e2007-04-18 19:39:22 +1000650static int msi_free_irqs(struct pci_dev* dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651{
Michael Ellerman032de8e2007-04-18 19:39:22 +1000652 struct msi_desc *entry, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
David Millerb3b7cc72007-05-11 13:26:44 -0700654 list_for_each_entry(entry, &dev->msi_list, list) {
655 if (entry->irq)
656 BUG_ON(irq_has_action(entry->irq));
657 }
Michael Ellerman7ede9c12007-03-22 21:51:34 +1100658
Michael Ellerman032de8e2007-04-18 19:39:22 +1000659 arch_teardown_msi_irqs(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
Michael Ellerman032de8e2007-04-18 19:39:22 +1000661 list_for_each_entry_safe(entry, tmp, &dev->msi_list, list) {
662 if (entry->msi_attrib.type == PCI_CAP_ID_MSIX) {
Michael Ellerman032de8e2007-04-18 19:39:22 +1000663 writel(1, entry->mask_base + entry->msi_attrib.entry_nr
664 * PCI_MSIX_ENTRY_SIZE
665 + PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET);
Eric W. Biederman78b76112007-06-01 00:46:33 -0700666
667 if (list_is_last(&entry->list, &dev->msi_list))
668 iounmap(entry->mask_base);
Michael Ellerman032de8e2007-04-18 19:39:22 +1000669 }
670 list_del(&entry->list);
671 kfree(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 }
673
674 return 0;
675}
676
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677/**
678 * pci_enable_msix - configure device's MSI-X capability structure
679 * @dev: pointer to the pci_dev data structure of MSI-X device function
Greg Kroah-Hartman70549ad2005-06-06 23:07:46 -0700680 * @entries: pointer to an array of MSI-X entries
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700681 * @nvec: number of MSI-X irqs requested for allocation by device driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 *
683 * Setup the MSI-X capability structure of device function with the number
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700684 * of requested irqs upon its software driver call to request for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 * MSI-X mode enabled on its hardware device function. A return of zero
686 * indicates the successful configuration of MSI-X capability structure
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700687 * with new allocated MSI-X irqs. A return of < 0 indicates a failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 * Or a return of > 0 indicates that driver request is exceeding the number
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700689 * of irqs available. Driver should use the returned value to re-send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 * its request.
691 **/
692int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec)
693{
Eric W. Biederman92db6d12006-10-04 02:16:35 -0700694 int status, pos, nr_entries;
Eric W. Biedermanded86d82007-01-28 12:42:52 -0700695 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 u16 control;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
Michael Ellermanc9953a72007-04-05 17:19:08 +1000698 if (!entries)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 return -EINVAL;
700
Michael Ellermanc9953a72007-04-05 17:19:08 +1000701 status = pci_msi_check_device(dev, nvec, PCI_CAP_ID_MSIX);
702 if (status)
703 return status;
704
Grant Grundlerb64c05e2006-01-14 00:34:53 -0700705 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 pci_read_config_word(dev, msi_control_reg(pos), &control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 nr_entries = multi_msix_capable(control);
708 if (nvec > nr_entries)
709 return -EINVAL;
710
711 /* Check for any invalid entries */
712 for (i = 0; i < nvec; i++) {
713 if (entries[i].entry >= nr_entries)
714 return -EINVAL; /* invalid entry */
715 for (j = i + 1; j < nvec; j++) {
716 if (entries[i].entry == entries[j].entry)
717 return -EINVAL; /* duplicate entry */
718 }
719 }
Eric W. Biedermanded86d82007-01-28 12:42:52 -0700720 WARN_ON(!!dev->msix_enabled);
Eric W. Biederman7bd007e2006-10-04 02:16:31 -0700721
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700722 /* Check whether driver already requested for MSI irq */
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800723 if (dev->msi_enabled) {
Bjorn Helgaas80ccba12008-06-13 10:52:11 -0600724 dev_info(&dev->dev, "can't enable MSI-X "
725 "(MSI IRQ already assigned)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 return -EINVAL;
727 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 status = msix_capability_init(dev, entries, nvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 return status;
730}
Michael Ellerman4cc086f2007-03-22 21:51:34 +1100731EXPORT_SYMBOL(pci_enable_msix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
Michael Ellermanfc4afc72007-03-22 21:51:33 +1100733static void msix_free_all_irqs(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734{
Michael Ellerman032de8e2007-04-18 19:39:22 +1000735 msi_free_irqs(dev);
Michael Ellermanfc4afc72007-03-22 21:51:33 +1100736}
737
Yinghai Lud52877c2008-04-23 14:58:09 -0700738void pci_msix_shutdown(struct pci_dev* dev)
Michael Ellermanfc4afc72007-03-22 21:51:33 +1100739{
Michael Ellerman128bc5f2007-03-22 21:51:39 +1100740 if (!pci_msi_enable || !dev || !dev->msix_enabled)
Eric W. Biedermanded86d82007-01-28 12:42:52 -0700741 return;
742
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800743 msix_set_enable(dev, 0);
David Millerba698ad2007-10-25 01:16:30 -0700744 pci_intx_for_msi(dev, 1);
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800745 dev->msix_enabled = 0;
Yinghai Lud52877c2008-04-23 14:58:09 -0700746}
747void pci_disable_msix(struct pci_dev* dev)
748{
749 if (!pci_msi_enable || !dev || !dev->msix_enabled)
750 return;
751
752 pci_msix_shutdown(dev);
Eric W. Biederman7bd007e2006-10-04 02:16:31 -0700753
Michael Ellermanfc4afc72007-03-22 21:51:33 +1100754 msix_free_all_irqs(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755}
Michael Ellerman4cc086f2007-03-22 21:51:34 +1100756EXPORT_SYMBOL(pci_disable_msix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
758/**
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700759 * msi_remove_pci_irq_vectors - reclaim MSI(X) irqs to unused state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 * @dev: pointer to the pci_dev data structure of MSI(X) device function
761 *
Steven Coleeaae4b32005-05-03 18:38:30 -0600762 * Being called during hotplug remove, from which the device function
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700763 * is hot-removed. All previous assigned MSI/MSI-X irqs, if
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 * allocated for this device function, are reclaimed to unused state,
765 * which may be used later on.
766 **/
767void msi_remove_pci_irq_vectors(struct pci_dev* dev)
768{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 if (!pci_msi_enable || !dev)
770 return;
771
Michael Ellerman032de8e2007-04-18 19:39:22 +1000772 if (dev->msi_enabled)
773 msi_free_irqs(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Michael Ellermanfc4afc72007-03-22 21:51:33 +1100775 if (dev->msix_enabled)
776 msix_free_all_irqs(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777}
778
Matthew Wilcox309e57d2006-03-05 22:33:34 -0700779void pci_no_msi(void)
780{
781 pci_msi_enable = 0;
782}
Michael Ellermanc9953a72007-04-05 17:19:08 +1000783
Andrew Patterson07ae95f2008-11-10 15:31:05 -0700784/**
785 * pci_msi_enabled - is MSI enabled?
786 *
787 * Returns true if MSI has not been disabled by the command-line option
788 * pci=nomsi.
789 **/
790int pci_msi_enabled(void)
791{
792 return pci_msi_enable;
793}
794EXPORT_SYMBOL(pci_msi_enabled);
795
Michael Ellerman4aa9bc92007-04-05 17:19:10 +1000796void pci_msi_init_pci_dev(struct pci_dev *dev)
797{
798 INIT_LIST_HEAD(&dev->msi_list);
799}