blob: 44f15ff70c1d4f5f6c135d68367cbfb57b31783e [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 -0500106/*
107 * Essentially, this is ((1 << (1 << x)) - 1), but without the
108 * undefinedness of a << 32.
109 */
110static inline __attribute_const__ u32 msi_mask(unsigned x)
111{
112 static const u32 mask[] = { 1, 2, 4, 0xf, 0xff, 0xffff, 0xffffffff };
113 return mask[x];
114}
115
Yinghai Lu3145e942008-12-05 18:58:34 -0800116static void msix_flush_writes(struct irq_desc *desc)
Mitch Williams988cbb12007-03-30 11:54:08 -0700117{
118 struct msi_desc *entry;
119
Yinghai Lu3145e942008-12-05 18:58:34 -0800120 entry = get_irq_desc_msi(desc);
Mitch Williams988cbb12007-03-30 11:54:08 -0700121 BUG_ON(!entry || !entry->dev);
122 switch (entry->msi_attrib.type) {
123 case PCI_CAP_ID_MSI:
124 /* nothing to do */
125 break;
126 case PCI_CAP_ID_MSIX:
127 {
128 int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE +
129 PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET;
130 readl(entry->mask_base + offset);
131 break;
132 }
133 default:
134 BUG();
135 break;
136 }
137}
138
Matthew Wilcoxce6fce42008-07-25 15:42:58 -0600139/*
140 * PCI 2.3 does not specify mask bits for each MSI interrupt. Attempting to
141 * mask all MSI interrupts by clearing the MSI enable bit does not work
142 * reliably as devices without an INTx disable bit will then generate a
143 * level IRQ which will never be cleared.
144 *
145 * Returns 1 if it succeeded in masking the interrupt and 0 if the device
146 * doesn't support MSI masking.
147 */
Yinghai Lu3145e942008-12-05 18:58:34 -0800148static int msi_set_mask_bits(struct irq_desc *desc, u32 mask, u32 flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
150 struct msi_desc *entry;
151
Yinghai Lu3145e942008-12-05 18:58:34 -0800152 entry = get_irq_desc_msi(desc);
Eric W. Biederman277bc332006-10-04 02:16:57 -0700153 BUG_ON(!entry || !entry->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 switch (entry->msi_attrib.type) {
155 case PCI_CAP_ID_MSI:
Eric W. Biederman277bc332006-10-04 02:16:57 -0700156 if (entry->msi_attrib.maskbit) {
Satoru Takeuchic54c1872007-01-18 13:50:05 +0900157 int pos;
158 u32 mask_bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Eric W. Biederman277bc332006-10-04 02:16:57 -0700160 pos = (long)entry->mask_base;
161 pci_read_config_dword(entry->dev, pos, &mask_bits);
Yinghai Lu8e149e02008-04-23 14:56:30 -0700162 mask_bits &= ~(mask);
163 mask_bits |= flag & mask;
Eric W. Biederman277bc332006-10-04 02:16:57 -0700164 pci_write_config_dword(entry->dev, pos, mask_bits);
Eric W. Biederman58e05432007-03-05 00:30:11 -0800165 } else {
Matthew Wilcoxce6fce42008-07-25 15:42:58 -0600166 return 0;
Eric W. Biederman277bc332006-10-04 02:16:57 -0700167 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 case PCI_CAP_ID_MSIX:
170 {
171 int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE +
172 PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET;
173 writel(flag, entry->mask_base + offset);
Eric W. Biederman348e3fd2007-04-03 01:41:49 -0600174 readl(entry->mask_base + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 break;
176 }
177 default:
Eric W. Biederman277bc332006-10-04 02:16:57 -0700178 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 break;
180 }
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700181 entry->msi_attrib.masked = !!flag;
Matthew Wilcoxce6fce42008-07-25 15:42:58 -0600182 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183}
184
Yinghai Lu3145e942008-12-05 18:58:34 -0800185void read_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700186{
Yinghai Lu3145e942008-12-05 18:58:34 -0800187 struct msi_desc *entry = get_irq_desc_msi(desc);
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700188 switch(entry->msi_attrib.type) {
189 case PCI_CAP_ID_MSI:
190 {
191 struct pci_dev *dev = entry->dev;
192 int pos = entry->msi_attrib.pos;
193 u16 data;
194
195 pci_read_config_dword(dev, msi_lower_address_reg(pos),
196 &msg->address_lo);
197 if (entry->msi_attrib.is_64) {
198 pci_read_config_dword(dev, msi_upper_address_reg(pos),
199 &msg->address_hi);
200 pci_read_config_word(dev, msi_data_reg(pos, 1), &data);
201 } else {
202 msg->address_hi = 0;
Roland Dreiercbf5d9e2007-10-03 11:15:11 -0700203 pci_read_config_word(dev, msi_data_reg(pos, 0), &data);
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700204 }
205 msg->data = data;
206 break;
207 }
208 case PCI_CAP_ID_MSIX:
209 {
210 void __iomem *base;
211 base = entry->mask_base +
212 entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE;
213
214 msg->address_lo = readl(base + PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET);
215 msg->address_hi = readl(base + PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET);
216 msg->data = readl(base + PCI_MSIX_ENTRY_DATA_OFFSET);
217 break;
218 }
219 default:
220 BUG();
221 }
222}
223
Yinghai Lu3145e942008-12-05 18:58:34 -0800224void read_msi_msg(unsigned int irq, struct msi_msg *msg)
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700225{
Yinghai Lu3145e942008-12-05 18:58:34 -0800226 struct irq_desc *desc = irq_to_desc(irq);
227
228 read_msi_msg_desc(desc, msg);
229}
230
231void write_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
232{
233 struct msi_desc *entry = get_irq_desc_msi(desc);
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700234 switch (entry->msi_attrib.type) {
235 case PCI_CAP_ID_MSI:
236 {
237 struct pci_dev *dev = entry->dev;
238 int pos = entry->msi_attrib.pos;
239
240 pci_write_config_dword(dev, msi_lower_address_reg(pos),
241 msg->address_lo);
242 if (entry->msi_attrib.is_64) {
243 pci_write_config_dword(dev, msi_upper_address_reg(pos),
244 msg->address_hi);
245 pci_write_config_word(dev, msi_data_reg(pos, 1),
246 msg->data);
247 } else {
248 pci_write_config_word(dev, msi_data_reg(pos, 0),
249 msg->data);
250 }
251 break;
252 }
253 case PCI_CAP_ID_MSIX:
254 {
255 void __iomem *base;
256 base = entry->mask_base +
257 entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE;
258
259 writel(msg->address_lo,
260 base + PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET);
261 writel(msg->address_hi,
262 base + PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET);
263 writel(msg->data, base + PCI_MSIX_ENTRY_DATA_OFFSET);
264 break;
265 }
266 default:
267 BUG();
268 }
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700269 entry->msg = *msg;
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700270}
271
Yinghai Lu3145e942008-12-05 18:58:34 -0800272void write_msi_msg(unsigned int irq, struct msi_msg *msg)
273{
274 struct irq_desc *desc = irq_to_desc(irq);
275
276 write_msi_msg_desc(desc, msg);
277}
278
Eric W. Biederman3b7d1922006-10-04 02:16:59 -0700279void mask_msi_irq(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
Yinghai Lu3145e942008-12-05 18:58:34 -0800281 struct irq_desc *desc = irq_to_desc(irq);
282
283 msi_set_mask_bits(desc, 1, 1);
284 msix_flush_writes(desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
286
Eric W. Biederman3b7d1922006-10-04 02:16:59 -0700287void unmask_msi_irq(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
Yinghai Lu3145e942008-12-05 18:58:34 -0800289 struct irq_desc *desc = irq_to_desc(irq);
290
291 msi_set_mask_bits(desc, 1, 0);
292 msix_flush_writes(desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293}
294
Michael Ellerman032de8e2007-04-18 19:39:22 +1000295static int msi_free_irqs(struct pci_dev* dev);
Satoru Takeuchic54c1872007-01-18 13:50:05 +0900296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297static struct msi_desc* alloc_msi_entry(void)
298{
299 struct msi_desc *entry;
300
Michael Ellerman3e916c02007-03-22 21:51:36 +1100301 entry = kzalloc(sizeof(struct msi_desc), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 if (!entry)
303 return NULL;
304
Michael Ellerman4aa9bc92007-04-05 17:19:10 +1000305 INIT_LIST_HEAD(&entry->list);
306 entry->irq = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 entry->dev = NULL;
308
309 return entry;
310}
311
David Millerba698ad2007-10-25 01:16:30 -0700312static void pci_intx_for_msi(struct pci_dev *dev, int enable)
313{
314 if (!(dev->dev_flags & PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG))
315 pci_intx(dev, enable);
316}
317
Michael Ellerman8fed4b62007-01-25 19:34:08 +1100318static void __pci_restore_msi_state(struct pci_dev *dev)
Shaohua Li41017f02006-02-08 17:11:38 +0800319{
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700320 int pos;
Shaohua Li41017f02006-02-08 17:11:38 +0800321 u16 control;
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700322 struct msi_desc *entry;
Shaohua Li41017f02006-02-08 17:11:38 +0800323
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800324 if (!dev->msi_enabled)
325 return;
326
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700327 entry = get_irq_msi(dev->irq);
328 pos = entry->msi_attrib.pos;
Shaohua Li41017f02006-02-08 17:11:38 +0800329
David Millerba698ad2007-10-25 01:16:30 -0700330 pci_intx_for_msi(dev, 0);
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800331 msi_set_enable(dev, 0);
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700332 write_msi_msg(dev->irq, &entry->msg);
Yinghai Lu3145e942008-12-05 18:58:34 -0800333 if (entry->msi_attrib.maskbit) {
334 struct irq_desc *desc = irq_to_desc(dev->irq);
335 msi_set_mask_bits(desc, entry->msi_attrib.maskbits_mask,
Yinghai Lu8e149e02008-04-23 14:56:30 -0700336 entry->msi_attrib.masked);
Yinghai Lu3145e942008-12-05 18:58:34 -0800337 }
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700338
339 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control);
Jesse Barnesabad2ec2008-08-07 08:52:37 -0700340 control &= ~PCI_MSI_FLAGS_QSIZE;
341 control |= PCI_MSI_FLAGS_ENABLE;
Shaohua Li41017f02006-02-08 17:11:38 +0800342 pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control);
Michael Ellerman8fed4b62007-01-25 19:34:08 +1100343}
344
345static void __pci_restore_msix_state(struct pci_dev *dev)
Shaohua Li41017f02006-02-08 17:11:38 +0800346{
Shaohua Li41017f02006-02-08 17:11:38 +0800347 int pos;
Shaohua Li41017f02006-02-08 17:11:38 +0800348 struct msi_desc *entry;
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700349 u16 control;
Shaohua Li41017f02006-02-08 17:11:38 +0800350
Eric W. Biedermanded86d82007-01-28 12:42:52 -0700351 if (!dev->msix_enabled)
352 return;
353
Shaohua Li41017f02006-02-08 17:11:38 +0800354 /* route the table */
David Millerba698ad2007-10-25 01:16:30 -0700355 pci_intx_for_msi(dev, 0);
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800356 msix_set_enable(dev, 0);
Shaohua Li41017f02006-02-08 17:11:38 +0800357
Michael Ellerman4aa9bc92007-04-05 17:19:10 +1000358 list_for_each_entry(entry, &dev->msi_list, list) {
Yinghai Lu3145e942008-12-05 18:58:34 -0800359 struct irq_desc *desc = irq_to_desc(entry->irq);
Michael Ellerman4aa9bc92007-04-05 17:19:10 +1000360 write_msi_msg(entry->irq, &entry->msg);
Yinghai Lu3145e942008-12-05 18:58:34 -0800361 msi_set_mask_bits(desc, 1, entry->msi_attrib.masked);
Shaohua Li41017f02006-02-08 17:11:38 +0800362 }
Shaohua Li41017f02006-02-08 17:11:38 +0800363
Michael Ellerman314e77b2007-04-05 17:19:12 +1000364 BUG_ON(list_empty(&dev->msi_list));
365 entry = list_entry(dev->msi_list.next, struct msi_desc, list);
Michael Ellerman4aa9bc92007-04-05 17:19:10 +1000366 pos = entry->msi_attrib.pos;
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700367 pci_read_config_word(dev, pos + PCI_MSIX_FLAGS, &control);
368 control &= ~PCI_MSIX_FLAGS_MASKALL;
369 control |= PCI_MSIX_FLAGS_ENABLE;
370 pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control);
Shaohua Li41017f02006-02-08 17:11:38 +0800371}
Michael Ellerman8fed4b62007-01-25 19:34:08 +1100372
373void pci_restore_msi_state(struct pci_dev *dev)
374{
375 __pci_restore_msi_state(dev);
376 __pci_restore_msix_state(dev);
377}
Linas Vepstas94688cf2007-11-07 15:43:59 -0600378EXPORT_SYMBOL_GPL(pci_restore_msi_state);
Shaohua Li41017f02006-02-08 17:11:38 +0800379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380/**
381 * msi_capability_init - configure device's MSI capability structure
382 * @dev: pointer to the pci_dev data structure of MSI device function
383 *
Steven Coleeaae4b32005-05-03 18:38:30 -0600384 * Setup the MSI capability structure of device function with a single
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700385 * MSI irq, regardless of device function is capable of handling
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 * multiple messages. A return of zero indicates the successful setup
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700387 * of an entry zero with the new MSI irq or non-zero for otherwise.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 **/
389static int msi_capability_init(struct pci_dev *dev)
390{
391 struct msi_desc *entry;
Michael Ellerman7fe37302007-04-18 19:39:21 +1000392 int pos, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 u16 control;
394
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800395 msi_set_enable(dev, 0); /* Ensure msi is disabled as I set it up */
396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
398 pci_read_config_word(dev, msi_control_reg(pos), &control);
399 /* MSI Entry Initialization */
Eric W. Biedermanf7feaca2007-01-28 12:56:37 -0700400 entry = alloc_msi_entry();
401 if (!entry)
402 return -ENOMEM;
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 entry->msi_attrib.type = PCI_CAP_ID_MSI;
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700405 entry->msi_attrib.is_64 = is_64bit_address(control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 entry->msi_attrib.entry_nr = 0;
407 entry->msi_attrib.maskbit = is_mask_bit_support(control);
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700408 entry->msi_attrib.masked = 1;
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700409 entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700410 entry->msi_attrib.pos = pos;
Eric W. Biederman3b7d1922006-10-04 02:16:59 -0700411 entry->dev = dev;
412 if (entry->msi_attrib.maskbit) {
Hidetoshi Seto0db29af2008-12-24 17:27:04 +0900413 unsigned int base, maskbits, temp;
414
415 base = msi_mask_bits_reg(pos, entry->msi_attrib.is_64);
416 entry->mask_base = (void __iomem *)(long)base;
417
Eric W. Biederman3b7d1922006-10-04 02:16:59 -0700418 /* All MSIs are unmasked by default, Mask them all */
Hidetoshi Seto0db29af2008-12-24 17:27:04 +0900419 pci_read_config_dword(dev, base, &maskbits);
Matthew Wilcoxbffac3c2009-01-21 19:19:19 -0500420 temp = msi_mask((control & PCI_MSI_FLAGS_QMASK) >> 1);
Eric W. Biederman3b7d1922006-10-04 02:16:59 -0700421 maskbits |= temp;
Hidetoshi Seto0db29af2008-12-24 17:27:04 +0900422 pci_write_config_dword(dev, base, maskbits);
Yinghai Lu8e149e02008-04-23 14:56:30 -0700423 entry->msi_attrib.maskbits_mask = temp;
Eric W. Biederman3b7d1922006-10-04 02:16:59 -0700424 }
Eric W. Biederman0dd11f92007-06-01 00:46:32 -0700425 list_add_tail(&entry->list, &dev->msi_list);
Michael Ellerman9c831332007-04-18 19:39:21 +1000426
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 /* Configure MSI capability structure */
Michael Ellerman9c831332007-04-18 19:39:21 +1000428 ret = arch_setup_msi_irqs(dev, 1, PCI_CAP_ID_MSI);
Michael Ellerman7fe37302007-04-18 19:39:21 +1000429 if (ret) {
Michael Ellerman032de8e2007-04-18 19:39:22 +1000430 msi_free_irqs(dev);
Michael Ellerman7fe37302007-04-18 19:39:21 +1000431 return ret;
Mark Maulefd58e552006-04-10 21:17:48 -0500432 }
Eric W. Biedermanf7feaca2007-01-28 12:56:37 -0700433
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 /* Set MSI enabled bits */
David Millerba698ad2007-10-25 01:16:30 -0700435 pci_intx_for_msi(dev, 0);
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800436 msi_set_enable(dev, 1);
437 dev->msi_enabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Michael Ellerman7fe37302007-04-18 19:39:21 +1000439 dev->irq = entry->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 return 0;
441}
442
443/**
444 * msix_capability_init - configure device's MSI-X capability
445 * @dev: pointer to the pci_dev data structure of MSI-X device function
Randy Dunlap8f7020d2005-10-23 11:57:38 -0700446 * @entries: pointer to an array of struct msix_entry entries
447 * @nvec: number of @entries
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 *
Steven Coleeaae4b32005-05-03 18:38:30 -0600449 * Setup the MSI-X capability structure of device function with a
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700450 * single MSI-X irq. A return of zero indicates the successful setup of
451 * requested MSI-X entries with allocated irqs or non-zero for otherwise.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 **/
453static int msix_capability_init(struct pci_dev *dev,
454 struct msix_entry *entries, int nvec)
455{
Michael Ellerman4aa9bc92007-04-05 17:19:10 +1000456 struct msi_desc *entry;
Michael Ellerman9c831332007-04-18 19:39:21 +1000457 int pos, i, j, nr_entries, ret;
Grant Grundlera0454b42006-02-16 23:58:29 -0800458 unsigned long phys_addr;
459 u32 table_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 u16 control;
461 u8 bir;
462 void __iomem *base;
463
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800464 msix_set_enable(dev, 0);/* Ensure msix is disabled as I set it up */
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
467 /* Request & Map MSI-X table region */
468 pci_read_config_word(dev, msi_control_reg(pos), &control);
469 nr_entries = multi_msix_capable(control);
Grant Grundlera0454b42006-02-16 23:58:29 -0800470
471 pci_read_config_dword(dev, msix_table_offset_reg(pos), &table_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK);
Grant Grundlera0454b42006-02-16 23:58:29 -0800473 table_offset &= ~PCI_MSIX_FLAGS_BIRMASK;
474 phys_addr = pci_resource_start (dev, bir) + table_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 base = ioremap_nocache(phys_addr, nr_entries * PCI_MSIX_ENTRY_SIZE);
476 if (base == NULL)
477 return -ENOMEM;
478
479 /* MSI-X Table Initialization */
480 for (i = 0; i < nvec; i++) {
Eric W. Biedermanf7feaca2007-01-28 12:56:37 -0700481 entry = alloc_msi_entry();
482 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 j = entries[i].entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 entry->msi_attrib.type = PCI_CAP_ID_MSIX;
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700487 entry->msi_attrib.is_64 = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 entry->msi_attrib.entry_nr = j;
489 entry->msi_attrib.maskbit = 1;
Eric W. Biederman392ee1e2007-03-08 13:04:57 -0700490 entry->msi_attrib.masked = 1;
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700491 entry->msi_attrib.default_irq = dev->irq;
Eric W. Biederman0366f8f2006-10-04 02:16:33 -0700492 entry->msi_attrib.pos = pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 entry->dev = dev;
494 entry->mask_base = base;
Eric W. Biedermanf7feaca2007-01-28 12:56:37 -0700495
Eric W. Biederman0dd11f92007-06-01 00:46:32 -0700496 list_add_tail(&entry->list, &dev->msi_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 }
Michael Ellerman9c831332007-04-18 19:39:21 +1000498
499 ret = arch_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSIX);
500 if (ret) {
501 int avail = 0;
502 list_for_each_entry(entry, &dev->msi_list, list) {
503 if (entry->irq != 0) {
504 avail++;
Michael Ellerman9c831332007-04-18 19:39:21 +1000505 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 }
Michael Ellerman9c831332007-04-18 19:39:21 +1000507
Michael Ellerman032de8e2007-04-18 19:39:22 +1000508 msi_free_irqs(dev);
509
Eric W. Biederman92db6d12006-10-04 02:16:35 -0700510 /* If we had some success report the number of irqs
511 * we succeeded in setting up.
512 */
Michael Ellerman9c831332007-04-18 19:39:21 +1000513 if (avail == 0)
514 avail = ret;
Eric W. Biederman92db6d12006-10-04 02:16:35 -0700515 return avail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 }
Michael Ellerman9c831332007-04-18 19:39:21 +1000517
518 i = 0;
519 list_for_each_entry(entry, &dev->msi_list, list) {
520 entries[i].vector = entry->irq;
521 set_irq_msi(entry->irq, entry);
522 i++;
523 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 /* Set MSI-X enabled bits */
David Millerba698ad2007-10-25 01:16:30 -0700525 pci_intx_for_msi(dev, 0);
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800526 msix_set_enable(dev, 1);
527 dev->msix_enabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
529 return 0;
530}
531
532/**
Michael Ellerman17bbc122007-04-05 17:19:07 +1000533 * pci_msi_check_device - check whether MSI may be enabled on a device
Brice Goglin24334a12006-08-31 01:55:07 -0400534 * @dev: pointer to the pci_dev data structure of MSI device function
Michael Ellermanc9953a72007-04-05 17:19:08 +1000535 * @nvec: how many MSIs have been requested ?
Michael Ellermanb1e23032007-03-22 21:51:39 +1100536 * @type: are we checking for MSI or MSI-X ?
Brice Goglin24334a12006-08-31 01:55:07 -0400537 *
Brice Goglin0306ebf2006-10-05 10:24:31 +0200538 * Look at global flags, the device itself, and its parent busses
Michael Ellerman17bbc122007-04-05 17:19:07 +1000539 * to determine if MSI/-X are supported for the device. If MSI/-X is
540 * supported return 0, else return an error code.
Brice Goglin24334a12006-08-31 01:55:07 -0400541 **/
Michael Ellermanc9953a72007-04-05 17:19:08 +1000542static int pci_msi_check_device(struct pci_dev* dev, int nvec, int type)
Brice Goglin24334a12006-08-31 01:55:07 -0400543{
544 struct pci_bus *bus;
Michael Ellermanc9953a72007-04-05 17:19:08 +1000545 int ret;
Brice Goglin24334a12006-08-31 01:55:07 -0400546
Brice Goglin0306ebf2006-10-05 10:24:31 +0200547 /* MSI must be globally enabled and supported by the device */
Brice Goglin24334a12006-08-31 01:55:07 -0400548 if (!pci_msi_enable || !dev || dev->no_msi)
549 return -EINVAL;
550
Michael Ellerman314e77b2007-04-05 17:19:12 +1000551 /*
552 * You can't ask to have 0 or less MSIs configured.
553 * a) it's stupid ..
554 * b) the list manipulation code assumes nvec >= 1.
555 */
556 if (nvec < 1)
557 return -ERANGE;
558
Brice Goglin0306ebf2006-10-05 10:24:31 +0200559 /* Any bridge which does NOT route MSI transactions from it's
560 * secondary bus to it's primary bus must set NO_MSI flag on
561 * the secondary pci_bus.
562 * We expect only arch-specific PCI host bus controller driver
563 * or quirks for specific PCI bridges to be setting NO_MSI.
564 */
Brice Goglin24334a12006-08-31 01:55:07 -0400565 for (bus = dev->bus; bus; bus = bus->parent)
566 if (bus->bus_flags & PCI_BUS_FLAGS_NO_MSI)
567 return -EINVAL;
568
Michael Ellermanc9953a72007-04-05 17:19:08 +1000569 ret = arch_msi_check_device(dev, nvec, type);
570 if (ret)
571 return ret;
572
Michael Ellermanb1e23032007-03-22 21:51:39 +1100573 if (!pci_find_capability(dev, type))
574 return -EINVAL;
575
Brice Goglin24334a12006-08-31 01:55:07 -0400576 return 0;
577}
578
579/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 * pci_enable_msi - configure device's MSI capability structure
581 * @dev: pointer to the pci_dev data structure of MSI device function
582 *
583 * Setup the MSI capability structure of device function with
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700584 * a single MSI irq upon its software driver call to request for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 * MSI mode enabled on its hardware device function. A return of zero
586 * indicates the successful setup of an entry zero with the new MSI
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700587 * irq or non-zero for otherwise.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 **/
589int pci_enable_msi(struct pci_dev* dev)
590{
Michael Ellermanb1e23032007-03-22 21:51:39 +1100591 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Michael Ellermanc9953a72007-04-05 17:19:08 +1000593 status = pci_msi_check_device(dev, 1, PCI_CAP_ID_MSI);
594 if (status)
595 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Eric W. Biedermanded86d82007-01-28 12:42:52 -0700597 WARN_ON(!!dev->msi_enabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700599 /* Check whether driver already requested for MSI-X irqs */
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800600 if (dev->msix_enabled) {
Bjorn Helgaas80ccba12008-06-13 10:52:11 -0600601 dev_info(&dev->dev, "can't enable MSI "
602 "(MSI-X already enabled)\n");
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800603 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 }
605 status = msi_capability_init(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 return status;
607}
Michael Ellerman4cc086f2007-03-22 21:51:34 +1100608EXPORT_SYMBOL(pci_enable_msi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Yinghai Lud52877c2008-04-23 14:58:09 -0700610void pci_msi_shutdown(struct pci_dev* dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
612 struct msi_desc *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
Michael Ellerman128bc5f2007-03-22 21:51:39 +1100614 if (!pci_msi_enable || !dev || !dev->msi_enabled)
Eric W. Biedermanded86d82007-01-28 12:42:52 -0700615 return;
616
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800617 msi_set_enable(dev, 0);
David Millerba698ad2007-10-25 01:16:30 -0700618 pci_intx_for_msi(dev, 1);
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800619 dev->msi_enabled = 0;
Eric W. Biederman7bd007e2006-10-04 02:16:31 -0700620
Michael Ellerman314e77b2007-04-05 17:19:12 +1000621 BUG_ON(list_empty(&dev->msi_list));
622 entry = list_entry(dev->msi_list.next, struct msi_desc, list);
Yinghai Lu8e149e02008-04-23 14:56:30 -0700623 /* Return the the pci reset with msi irqs unmasked */
624 if (entry->msi_attrib.maskbit) {
625 u32 mask = entry->msi_attrib.maskbits_mask;
Yinghai Lu3145e942008-12-05 18:58:34 -0800626 struct irq_desc *desc = irq_to_desc(dev->irq);
627 msi_set_mask_bits(desc, mask, ~mask);
Yinghai Lu8e149e02008-04-23 14:56:30 -0700628 }
Yinghai Lud52877c2008-04-23 14:58:09 -0700629 if (!entry->dev || entry->msi_attrib.type != PCI_CAP_ID_MSI)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 return;
Michael Ellermane387b9e2007-03-22 21:51:27 +1100631
632 /* Restore dev->irq to its default pin-assertion irq */
Yinghai Lud52877c2008-04-23 14:58:09 -0700633 dev->irq = entry->msi_attrib.default_irq;
634}
635void pci_disable_msi(struct pci_dev* dev)
636{
637 struct msi_desc *entry;
638
639 if (!pci_msi_enable || !dev || !dev->msi_enabled)
640 return;
641
642 pci_msi_shutdown(dev);
643
644 entry = list_entry(dev->msi_list.next, struct msi_desc, list);
645 if (!entry->dev || entry->msi_attrib.type != PCI_CAP_ID_MSI)
646 return;
647
648 msi_free_irqs(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649}
Michael Ellerman4cc086f2007-03-22 21:51:34 +1100650EXPORT_SYMBOL(pci_disable_msi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Michael Ellerman032de8e2007-04-18 19:39:22 +1000652static int msi_free_irqs(struct pci_dev* dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653{
Michael Ellerman032de8e2007-04-18 19:39:22 +1000654 struct msi_desc *entry, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
David Millerb3b7cc72007-05-11 13:26:44 -0700656 list_for_each_entry(entry, &dev->msi_list, list) {
657 if (entry->irq)
658 BUG_ON(irq_has_action(entry->irq));
659 }
Michael Ellerman7ede9c12007-03-22 21:51:34 +1100660
Michael Ellerman032de8e2007-04-18 19:39:22 +1000661 arch_teardown_msi_irqs(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
Michael Ellerman032de8e2007-04-18 19:39:22 +1000663 list_for_each_entry_safe(entry, tmp, &dev->msi_list, list) {
664 if (entry->msi_attrib.type == PCI_CAP_ID_MSIX) {
Michael Ellerman032de8e2007-04-18 19:39:22 +1000665 writel(1, entry->mask_base + entry->msi_attrib.entry_nr
666 * PCI_MSIX_ENTRY_SIZE
667 + PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET);
Eric W. Biederman78b76112007-06-01 00:46:33 -0700668
669 if (list_is_last(&entry->list, &dev->msi_list))
670 iounmap(entry->mask_base);
Michael Ellerman032de8e2007-04-18 19:39:22 +1000671 }
672 list_del(&entry->list);
673 kfree(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 }
675
676 return 0;
677}
678
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679/**
680 * pci_enable_msix - configure device's MSI-X capability structure
681 * @dev: pointer to the pci_dev data structure of MSI-X device function
Greg Kroah-Hartman70549ad2005-06-06 23:07:46 -0700682 * @entries: pointer to an array of MSI-X entries
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700683 * @nvec: number of MSI-X irqs requested for allocation by device driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 *
685 * Setup the MSI-X capability structure of device function with the number
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700686 * of requested irqs upon its software driver call to request for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 * MSI-X mode enabled on its hardware device function. A return of zero
688 * indicates the successful configuration of MSI-X capability structure
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700689 * with new allocated MSI-X irqs. A return of < 0 indicates a failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 * Or a return of > 0 indicates that driver request is exceeding the number
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700691 * of irqs available. Driver should use the returned value to re-send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 * its request.
693 **/
694int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec)
695{
Eric W. Biederman92db6d12006-10-04 02:16:35 -0700696 int status, pos, nr_entries;
Eric W. Biedermanded86d82007-01-28 12:42:52 -0700697 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 u16 control;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Michael Ellermanc9953a72007-04-05 17:19:08 +1000700 if (!entries)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 return -EINVAL;
702
Michael Ellermanc9953a72007-04-05 17:19:08 +1000703 status = pci_msi_check_device(dev, nvec, PCI_CAP_ID_MSIX);
704 if (status)
705 return status;
706
Grant Grundlerb64c05e2006-01-14 00:34:53 -0700707 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 pci_read_config_word(dev, msi_control_reg(pos), &control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 nr_entries = multi_msix_capable(control);
710 if (nvec > nr_entries)
711 return -EINVAL;
712
713 /* Check for any invalid entries */
714 for (i = 0; i < nvec; i++) {
715 if (entries[i].entry >= nr_entries)
716 return -EINVAL; /* invalid entry */
717 for (j = i + 1; j < nvec; j++) {
718 if (entries[i].entry == entries[j].entry)
719 return -EINVAL; /* duplicate entry */
720 }
721 }
Eric W. Biedermanded86d82007-01-28 12:42:52 -0700722 WARN_ON(!!dev->msix_enabled);
Eric W. Biederman7bd007e2006-10-04 02:16:31 -0700723
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700724 /* Check whether driver already requested for MSI irq */
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800725 if (dev->msi_enabled) {
Bjorn Helgaas80ccba12008-06-13 10:52:11 -0600726 dev_info(&dev->dev, "can't enable MSI-X "
727 "(MSI IRQ already assigned)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 return -EINVAL;
729 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 status = msix_capability_init(dev, entries, nvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 return status;
732}
Michael Ellerman4cc086f2007-03-22 21:51:34 +1100733EXPORT_SYMBOL(pci_enable_msix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
Michael Ellermanfc4afc72007-03-22 21:51:33 +1100735static void msix_free_all_irqs(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736{
Michael Ellerman032de8e2007-04-18 19:39:22 +1000737 msi_free_irqs(dev);
Michael Ellermanfc4afc72007-03-22 21:51:33 +1100738}
739
Yinghai Lud52877c2008-04-23 14:58:09 -0700740void pci_msix_shutdown(struct pci_dev* dev)
Michael Ellermanfc4afc72007-03-22 21:51:33 +1100741{
Michael Ellerman128bc5f2007-03-22 21:51:39 +1100742 if (!pci_msi_enable || !dev || !dev->msix_enabled)
Eric W. Biedermanded86d82007-01-28 12:42:52 -0700743 return;
744
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800745 msix_set_enable(dev, 0);
David Millerba698ad2007-10-25 01:16:30 -0700746 pci_intx_for_msi(dev, 1);
Eric W. Biedermanb1cbf4e2007-03-05 00:30:10 -0800747 dev->msix_enabled = 0;
Yinghai Lud52877c2008-04-23 14:58:09 -0700748}
749void pci_disable_msix(struct pci_dev* dev)
750{
751 if (!pci_msi_enable || !dev || !dev->msix_enabled)
752 return;
753
754 pci_msix_shutdown(dev);
Eric W. Biederman7bd007e2006-10-04 02:16:31 -0700755
Michael Ellermanfc4afc72007-03-22 21:51:33 +1100756 msix_free_all_irqs(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757}
Michael Ellerman4cc086f2007-03-22 21:51:34 +1100758EXPORT_SYMBOL(pci_disable_msix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
760/**
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700761 * msi_remove_pci_irq_vectors - reclaim MSI(X) irqs to unused state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 * @dev: pointer to the pci_dev data structure of MSI(X) device function
763 *
Steven Coleeaae4b32005-05-03 18:38:30 -0600764 * Being called during hotplug remove, from which the device function
Eric W. Biederman1ce03372006-10-04 02:16:41 -0700765 * is hot-removed. All previous assigned MSI/MSI-X irqs, if
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 * allocated for this device function, are reclaimed to unused state,
767 * which may be used later on.
768 **/
769void msi_remove_pci_irq_vectors(struct pci_dev* dev)
770{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 if (!pci_msi_enable || !dev)
772 return;
773
Michael Ellerman032de8e2007-04-18 19:39:22 +1000774 if (dev->msi_enabled)
775 msi_free_irqs(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Michael Ellermanfc4afc72007-03-22 21:51:33 +1100777 if (dev->msix_enabled)
778 msix_free_all_irqs(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779}
780
Matthew Wilcox309e57d2006-03-05 22:33:34 -0700781void pci_no_msi(void)
782{
783 pci_msi_enable = 0;
784}
Michael Ellermanc9953a72007-04-05 17:19:08 +1000785
Andrew Patterson07ae95f2008-11-10 15:31:05 -0700786/**
787 * pci_msi_enabled - is MSI enabled?
788 *
789 * Returns true if MSI has not been disabled by the command-line option
790 * pci=nomsi.
791 **/
792int pci_msi_enabled(void)
793{
794 return pci_msi_enable;
795}
796EXPORT_SYMBOL(pci_msi_enabled);
797
Michael Ellerman4aa9bc92007-04-05 17:19:10 +1000798void pci_msi_init_pci_dev(struct pci_dev *dev)
799{
800 INIT_LIST_HEAD(&dev->msi_list);
801}