aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/msi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci/msi.c')
-rw-r--r--drivers/pci/msi.c180
1 files changed, 82 insertions, 98 deletions
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 00cc78c7aa04..d40bed726769 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -22,10 +22,12 @@
22#include <linux/slab.h> 22#include <linux/slab.h>
23 23
24#include "pci.h" 24#include "pci.h"
25#include "msi.h"
26 25
27static int pci_msi_enable = 1; 26static int pci_msi_enable = 1;
28 27
28#define msix_table_size(flags) ((flags & PCI_MSIX_FLAGS_QSIZE) + 1)
29
30
29/* Arch hooks */ 31/* Arch hooks */
30 32
31#ifndef arch_msi_check_device 33#ifndef arch_msi_check_device
@@ -111,32 +113,26 @@ void default_restore_msi_irqs(struct pci_dev *dev, int irq)
111} 113}
112#endif 114#endif
113 115
114static void msi_set_enable(struct pci_dev *dev, int pos, int enable) 116static void msi_set_enable(struct pci_dev *dev, int enable)
115{ 117{
116 u16 control; 118 u16 control;
117 119
118 BUG_ON(!pos); 120 pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control);
119
120 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control);
121 control &= ~PCI_MSI_FLAGS_ENABLE; 121 control &= ~PCI_MSI_FLAGS_ENABLE;
122 if (enable) 122 if (enable)
123 control |= PCI_MSI_FLAGS_ENABLE; 123 control |= PCI_MSI_FLAGS_ENABLE;
124 pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control); 124 pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, control);
125} 125}
126 126
127static void msix_set_enable(struct pci_dev *dev, int enable) 127static void msix_set_enable(struct pci_dev *dev, int enable)
128{ 128{
129 int pos;
130 u16 control; 129 u16 control;
131 130
132 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); 131 pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);
133 if (pos) { 132 control &= ~PCI_MSIX_FLAGS_ENABLE;
134 pci_read_config_word(dev, pos + PCI_MSIX_FLAGS, &control); 133 if (enable)
135 control &= ~PCI_MSIX_FLAGS_ENABLE; 134 control |= PCI_MSIX_FLAGS_ENABLE;
136 if (enable) 135 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
137 control |= PCI_MSIX_FLAGS_ENABLE;
138 pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control);
139 }
140} 136}
141 137
142static inline __attribute_const__ u32 msi_mask(unsigned x) 138static inline __attribute_const__ u32 msi_mask(unsigned x)
@@ -247,18 +243,18 @@ void __read_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
247 msg->data = readl(base + PCI_MSIX_ENTRY_DATA); 243 msg->data = readl(base + PCI_MSIX_ENTRY_DATA);
248 } else { 244 } else {
249 struct pci_dev *dev = entry->dev; 245 struct pci_dev *dev = entry->dev;
250 int pos = entry->msi_attrib.pos; 246 int pos = dev->msi_cap;
251 u16 data; 247 u16 data;
252 248
253 pci_read_config_dword(dev, msi_lower_address_reg(pos), 249 pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_LO,
254 &msg->address_lo); 250 &msg->address_lo);
255 if (entry->msi_attrib.is_64) { 251 if (entry->msi_attrib.is_64) {
256 pci_read_config_dword(dev, msi_upper_address_reg(pos), 252 pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_HI,
257 &msg->address_hi); 253 &msg->address_hi);
258 pci_read_config_word(dev, msi_data_reg(pos, 1), &data); 254 pci_read_config_word(dev, pos + PCI_MSI_DATA_64, &data);
259 } else { 255 } else {
260 msg->address_hi = 0; 256 msg->address_hi = 0;
261 pci_read_config_word(dev, msi_data_reg(pos, 0), &data); 257 pci_read_config_word(dev, pos + PCI_MSI_DATA_32, &data);
262 } 258 }
263 msg->data = data; 259 msg->data = data;
264 } 260 }
@@ -302,24 +298,24 @@ void __write_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
302 writel(msg->data, base + PCI_MSIX_ENTRY_DATA); 298 writel(msg->data, base + PCI_MSIX_ENTRY_DATA);
303 } else { 299 } else {
304 struct pci_dev *dev = entry->dev; 300 struct pci_dev *dev = entry->dev;
305 int pos = entry->msi_attrib.pos; 301 int pos = dev->msi_cap;
306 u16 msgctl; 302 u16 msgctl;
307 303
308 pci_read_config_word(dev, msi_control_reg(pos), &msgctl); 304 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl);
309 msgctl &= ~PCI_MSI_FLAGS_QSIZE; 305 msgctl &= ~PCI_MSI_FLAGS_QSIZE;
310 msgctl |= entry->msi_attrib.multiple << 4; 306 msgctl |= entry->msi_attrib.multiple << 4;
311 pci_write_config_word(dev, msi_control_reg(pos), msgctl); 307 pci_write_config_word(dev, pos + PCI_MSI_FLAGS, msgctl);
312 308
313 pci_write_config_dword(dev, msi_lower_address_reg(pos), 309 pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO,
314 msg->address_lo); 310 msg->address_lo);
315 if (entry->msi_attrib.is_64) { 311 if (entry->msi_attrib.is_64) {
316 pci_write_config_dword(dev, msi_upper_address_reg(pos), 312 pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI,
317 msg->address_hi); 313 msg->address_hi);
318 pci_write_config_word(dev, msi_data_reg(pos, 1), 314 pci_write_config_word(dev, pos + PCI_MSI_DATA_64,
319 msg->data); 315 msg->data);
320 } else { 316 } else {
321 pci_write_config_word(dev, msi_data_reg(pos, 0), 317 pci_write_config_word(dev, pos + PCI_MSI_DATA_32,
322 msg->data); 318 msg->data);
323 } 319 }
324 } 320 }
325 entry->msg = *msg; 321 entry->msg = *msg;
@@ -391,7 +387,6 @@ static void pci_intx_for_msi(struct pci_dev *dev, int enable)
391 387
392static void __pci_restore_msi_state(struct pci_dev *dev) 388static void __pci_restore_msi_state(struct pci_dev *dev)
393{ 389{
394 int pos;
395 u16 control; 390 u16 control;
396 struct msi_desc *entry; 391 struct msi_desc *entry;
397 392
@@ -399,22 +394,20 @@ static void __pci_restore_msi_state(struct pci_dev *dev)
399 return; 394 return;
400 395
401 entry = irq_get_msi_desc(dev->irq); 396 entry = irq_get_msi_desc(dev->irq);
402 pos = entry->msi_attrib.pos;
403 397
404 pci_intx_for_msi(dev, 0); 398 pci_intx_for_msi(dev, 0);
405 msi_set_enable(dev, pos, 0); 399 msi_set_enable(dev, 0);
406 arch_restore_msi_irqs(dev, dev->irq); 400 arch_restore_msi_irqs(dev, dev->irq);
407 401
408 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control); 402 pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control);
409 msi_mask_irq(entry, msi_capable_mask(control), entry->masked); 403 msi_mask_irq(entry, msi_capable_mask(control), entry->masked);
410 control &= ~PCI_MSI_FLAGS_QSIZE; 404 control &= ~PCI_MSI_FLAGS_QSIZE;
411 control |= (entry->msi_attrib.multiple << 4) | PCI_MSI_FLAGS_ENABLE; 405 control |= (entry->msi_attrib.multiple << 4) | PCI_MSI_FLAGS_ENABLE;
412 pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control); 406 pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, control);
413} 407}
414 408
415static void __pci_restore_msix_state(struct pci_dev *dev) 409static void __pci_restore_msix_state(struct pci_dev *dev)
416{ 410{
417 int pos;
418 struct msi_desc *entry; 411 struct msi_desc *entry;
419 u16 control; 412 u16 control;
420 413
@@ -422,13 +415,12 @@ static void __pci_restore_msix_state(struct pci_dev *dev)
422 return; 415 return;
423 BUG_ON(list_empty(&dev->msi_list)); 416 BUG_ON(list_empty(&dev->msi_list));
424 entry = list_first_entry(&dev->msi_list, struct msi_desc, list); 417 entry = list_first_entry(&dev->msi_list, struct msi_desc, list);
425 pos = entry->msi_attrib.pos; 418 pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);
426 pci_read_config_word(dev, pos + PCI_MSIX_FLAGS, &control);
427 419
428 /* route the table */ 420 /* route the table */
429 pci_intx_for_msi(dev, 0); 421 pci_intx_for_msi(dev, 0);
430 control |= PCI_MSIX_FLAGS_ENABLE | PCI_MSIX_FLAGS_MASKALL; 422 control |= PCI_MSIX_FLAGS_ENABLE | PCI_MSIX_FLAGS_MASKALL;
431 pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control); 423 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
432 424
433 list_for_each_entry(entry, &dev->msi_list, list) { 425 list_for_each_entry(entry, &dev->msi_list, list) {
434 arch_restore_msi_irqs(dev, entry->irq); 426 arch_restore_msi_irqs(dev, entry->irq);
@@ -436,7 +428,7 @@ static void __pci_restore_msix_state(struct pci_dev *dev)
436 } 428 }
437 429
438 control &= ~PCI_MSIX_FLAGS_MASKALL; 430 control &= ~PCI_MSIX_FLAGS_MASKALL;
439 pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control); 431 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
440} 432}
441 433
442void pci_restore_msi_state(struct pci_dev *dev) 434void pci_restore_msi_state(struct pci_dev *dev)
@@ -484,12 +476,12 @@ static struct msi_attribute mode_attribute =
484 __ATTR(mode, S_IRUGO, show_msi_mode, NULL); 476 __ATTR(mode, S_IRUGO, show_msi_mode, NULL);
485 477
486 478
487struct attribute *msi_irq_default_attrs[] = { 479static struct attribute *msi_irq_default_attrs[] = {
488 &mode_attribute.attr, 480 &mode_attribute.attr,
489 NULL 481 NULL
490}; 482};
491 483
492void msi_kobj_release(struct kobject *kobj) 484static void msi_kobj_release(struct kobject *kobj)
493{ 485{
494 struct msi_desc *entry = to_msi_desc(kobj); 486 struct msi_desc *entry = to_msi_desc(kobj);
495 487
@@ -552,27 +544,27 @@ out_unroll:
552static int msi_capability_init(struct pci_dev *dev, int nvec) 544static int msi_capability_init(struct pci_dev *dev, int nvec)
553{ 545{
554 struct msi_desc *entry; 546 struct msi_desc *entry;
555 int pos, ret; 547 int ret;
556 u16 control; 548 u16 control;
557 unsigned mask; 549 unsigned mask;
558 550
559 pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 551 msi_set_enable(dev, 0); /* Disable MSI during set up */
560 msi_set_enable(dev, pos, 0); /* Disable MSI during set up */
561 552
562 pci_read_config_word(dev, msi_control_reg(pos), &control); 553 pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control);
563 /* MSI Entry Initialization */ 554 /* MSI Entry Initialization */
564 entry = alloc_msi_entry(dev); 555 entry = alloc_msi_entry(dev);
565 if (!entry) 556 if (!entry)
566 return -ENOMEM; 557 return -ENOMEM;
567 558
568 entry->msi_attrib.is_msix = 0; 559 entry->msi_attrib.is_msix = 0;
569 entry->msi_attrib.is_64 = is_64bit_address(control); 560 entry->msi_attrib.is_64 = !!(control & PCI_MSI_FLAGS_64BIT);
570 entry->msi_attrib.entry_nr = 0; 561 entry->msi_attrib.entry_nr = 0;
571 entry->msi_attrib.maskbit = is_mask_bit_support(control); 562 entry->msi_attrib.maskbit = !!(control & PCI_MSI_FLAGS_MASKBIT);
572 entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */ 563 entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */
573 entry->msi_attrib.pos = pos; 564 entry->msi_attrib.pos = dev->msi_cap;
574 565
575 entry->mask_pos = msi_mask_reg(pos, entry->msi_attrib.is_64); 566 entry->mask_pos = dev->msi_cap + (control & PCI_MSI_FLAGS_64BIT) ?
567 PCI_MSI_MASK_64 : PCI_MSI_MASK_32;
576 /* All MSIs are unmasked by default, Mask them all */ 568 /* All MSIs are unmasked by default, Mask them all */
577 if (entry->msi_attrib.maskbit) 569 if (entry->msi_attrib.maskbit)
578 pci_read_config_dword(dev, entry->mask_pos, &entry->masked); 570 pci_read_config_dword(dev, entry->mask_pos, &entry->masked);
@@ -598,31 +590,30 @@ static int msi_capability_init(struct pci_dev *dev, int nvec)
598 590
599 /* Set MSI enabled bits */ 591 /* Set MSI enabled bits */
600 pci_intx_for_msi(dev, 0); 592 pci_intx_for_msi(dev, 0);
601 msi_set_enable(dev, pos, 1); 593 msi_set_enable(dev, 1);
602 dev->msi_enabled = 1; 594 dev->msi_enabled = 1;
603 595
604 dev->irq = entry->irq; 596 dev->irq = entry->irq;
605 return 0; 597 return 0;
606} 598}
607 599
608static void __iomem *msix_map_region(struct pci_dev *dev, unsigned pos, 600static void __iomem *msix_map_region(struct pci_dev *dev, unsigned nr_entries)
609 unsigned nr_entries)
610{ 601{
611 resource_size_t phys_addr; 602 resource_size_t phys_addr;
612 u32 table_offset; 603 u32 table_offset;
613 u8 bir; 604 u8 bir;
614 605
615 pci_read_config_dword(dev, msix_table_offset_reg(pos), &table_offset); 606 pci_read_config_dword(dev, dev->msix_cap + PCI_MSIX_TABLE,
616 bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK); 607 &table_offset);
617 table_offset &= ~PCI_MSIX_FLAGS_BIRMASK; 608 bir = (u8)(table_offset & PCI_MSIX_TABLE_BIR);
609 table_offset &= PCI_MSIX_TABLE_OFFSET;
618 phys_addr = pci_resource_start(dev, bir) + table_offset; 610 phys_addr = pci_resource_start(dev, bir) + table_offset;
619 611
620 return ioremap_nocache(phys_addr, nr_entries * PCI_MSIX_ENTRY_SIZE); 612 return ioremap_nocache(phys_addr, nr_entries * PCI_MSIX_ENTRY_SIZE);
621} 613}
622 614
623static int msix_setup_entries(struct pci_dev *dev, unsigned pos, 615static int msix_setup_entries(struct pci_dev *dev, void __iomem *base,
624 void __iomem *base, struct msix_entry *entries, 616 struct msix_entry *entries, int nvec)
625 int nvec)
626{ 617{
627 struct msi_desc *entry; 618 struct msi_desc *entry;
628 int i; 619 int i;
@@ -642,7 +633,7 @@ static int msix_setup_entries(struct pci_dev *dev, unsigned pos,
642 entry->msi_attrib.is_64 = 1; 633 entry->msi_attrib.is_64 = 1;
643 entry->msi_attrib.entry_nr = entries[i].entry; 634 entry->msi_attrib.entry_nr = entries[i].entry;
644 entry->msi_attrib.default_irq = dev->irq; 635 entry->msi_attrib.default_irq = dev->irq;
645 entry->msi_attrib.pos = pos; 636 entry->msi_attrib.pos = dev->msix_cap;
646 entry->mask_base = base; 637 entry->mask_base = base;
647 638
648 list_add_tail(&entry->list, &dev->msi_list); 639 list_add_tail(&entry->list, &dev->msi_list);
@@ -652,7 +643,7 @@ static int msix_setup_entries(struct pci_dev *dev, unsigned pos,
652} 643}
653 644
654static void msix_program_entries(struct pci_dev *dev, 645static void msix_program_entries(struct pci_dev *dev,
655 struct msix_entry *entries) 646 struct msix_entry *entries)
656{ 647{
657 struct msi_desc *entry; 648 struct msi_desc *entry;
658 int i = 0; 649 int i = 0;
@@ -682,23 +673,22 @@ static void msix_program_entries(struct pci_dev *dev,
682static int msix_capability_init(struct pci_dev *dev, 673static int msix_capability_init(struct pci_dev *dev,
683 struct msix_entry *entries, int nvec) 674 struct msix_entry *entries, int nvec)
684{ 675{
685 int pos, ret; 676 int ret;
686 u16 control; 677 u16 control;
687 void __iomem *base; 678 void __iomem *base;
688 679
689 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); 680 pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);
690 pci_read_config_word(dev, pos + PCI_MSIX_FLAGS, &control);
691 681
692 /* Ensure MSI-X is disabled while it is set up */ 682 /* Ensure MSI-X is disabled while it is set up */
693 control &= ~PCI_MSIX_FLAGS_ENABLE; 683 control &= ~PCI_MSIX_FLAGS_ENABLE;
694 pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control); 684 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
695 685
696 /* Request & Map MSI-X table region */ 686 /* Request & Map MSI-X table region */
697 base = msix_map_region(dev, pos, multi_msix_capable(control)); 687 base = msix_map_region(dev, msix_table_size(control));
698 if (!base) 688 if (!base)
699 return -ENOMEM; 689 return -ENOMEM;
700 690
701 ret = msix_setup_entries(dev, pos, base, entries, nvec); 691 ret = msix_setup_entries(dev, base, entries, nvec);
702 if (ret) 692 if (ret)
703 return ret; 693 return ret;
704 694
@@ -712,7 +702,7 @@ static int msix_capability_init(struct pci_dev *dev,
712 * interrupts coming in before they're fully set up. 702 * interrupts coming in before they're fully set up.
713 */ 703 */
714 control |= PCI_MSIX_FLAGS_MASKALL | PCI_MSIX_FLAGS_ENABLE; 704 control |= PCI_MSIX_FLAGS_MASKALL | PCI_MSIX_FLAGS_ENABLE;
715 pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control); 705 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
716 706
717 msix_program_entries(dev, entries); 707 msix_program_entries(dev, entries);
718 708
@@ -727,7 +717,7 @@ static int msix_capability_init(struct pci_dev *dev,
727 dev->msix_enabled = 1; 717 dev->msix_enabled = 1;
728 718
729 control &= ~PCI_MSIX_FLAGS_MASKALL; 719 control &= ~PCI_MSIX_FLAGS_MASKALL;
730 pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control); 720 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
731 721
732 return 0; 722 return 0;
733 723
@@ -795,9 +785,6 @@ static int pci_msi_check_device(struct pci_dev *dev, int nvec, int type)
795 if (ret) 785 if (ret)
796 return ret; 786 return ret;
797 787
798 if (!pci_find_capability(dev, type))
799 return -EINVAL;
800
801 return 0; 788 return 0;
802} 789}
803 790
@@ -816,13 +803,13 @@ static int pci_msi_check_device(struct pci_dev *dev, int nvec, int type)
816 */ 803 */
817int pci_enable_msi_block(struct pci_dev *dev, unsigned int nvec) 804int pci_enable_msi_block(struct pci_dev *dev, unsigned int nvec)
818{ 805{
819 int status, pos, maxvec; 806 int status, maxvec;
820 u16 msgctl; 807 u16 msgctl;
821 808
822 pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 809 if (!dev->msi_cap)
823 if (!pos)
824 return -EINVAL; 810 return -EINVAL;
825 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl); 811
812 pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &msgctl);
826 maxvec = 1 << ((msgctl & PCI_MSI_FLAGS_QMASK) >> 1); 813 maxvec = 1 << ((msgctl & PCI_MSI_FLAGS_QMASK) >> 1);
827 if (nvec > maxvec) 814 if (nvec > maxvec)
828 return maxvec; 815 return maxvec;
@@ -847,14 +834,13 @@ EXPORT_SYMBOL(pci_enable_msi_block);
847 834
848int pci_enable_msi_block_auto(struct pci_dev *dev, unsigned int *maxvec) 835int pci_enable_msi_block_auto(struct pci_dev *dev, unsigned int *maxvec)
849{ 836{
850 int ret, pos, nvec; 837 int ret, nvec;
851 u16 msgctl; 838 u16 msgctl;
852 839
853 pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 840 if (!dev->msi_cap)
854 if (!pos)
855 return -EINVAL; 841 return -EINVAL;
856 842
857 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl); 843 pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &msgctl);
858 ret = 1 << ((msgctl & PCI_MSI_FLAGS_QMASK) >> 1); 844 ret = 1 << ((msgctl & PCI_MSI_FLAGS_QMASK) >> 1);
859 845
860 if (maxvec) 846 if (maxvec)
@@ -876,21 +862,19 @@ void pci_msi_shutdown(struct pci_dev *dev)
876 struct msi_desc *desc; 862 struct msi_desc *desc;
877 u32 mask; 863 u32 mask;
878 u16 ctrl; 864 u16 ctrl;
879 unsigned pos;
880 865
881 if (!pci_msi_enable || !dev || !dev->msi_enabled) 866 if (!pci_msi_enable || !dev || !dev->msi_enabled)
882 return; 867 return;
883 868
884 BUG_ON(list_empty(&dev->msi_list)); 869 BUG_ON(list_empty(&dev->msi_list));
885 desc = list_first_entry(&dev->msi_list, struct msi_desc, list); 870 desc = list_first_entry(&dev->msi_list, struct msi_desc, list);
886 pos = desc->msi_attrib.pos;
887 871
888 msi_set_enable(dev, pos, 0); 872 msi_set_enable(dev, 0);
889 pci_intx_for_msi(dev, 1); 873 pci_intx_for_msi(dev, 1);
890 dev->msi_enabled = 0; 874 dev->msi_enabled = 0;
891 875
892 /* Return the device with MSI unmasked as initial states */ 876 /* Return the device with MSI unmasked as initial states */
893 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &ctrl); 877 pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &ctrl);
894 mask = msi_capable_mask(ctrl); 878 mask = msi_capable_mask(ctrl);
895 /* Keep cached state to be restored */ 879 /* Keep cached state to be restored */
896 __msi_mask_irq(desc, mask, ~mask); 880 __msi_mask_irq(desc, mask, ~mask);
@@ -917,15 +901,13 @@ EXPORT_SYMBOL(pci_disable_msi);
917 */ 901 */
918int pci_msix_table_size(struct pci_dev *dev) 902int pci_msix_table_size(struct pci_dev *dev)
919{ 903{
920 int pos;
921 u16 control; 904 u16 control;
922 905
923 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); 906 if (!dev->msix_cap)
924 if (!pos)
925 return 0; 907 return 0;
926 908
927 pci_read_config_word(dev, msi_control_reg(pos), &control); 909 pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);
928 return multi_msix_capable(control); 910 return msix_table_size(control);
929} 911}
930 912
931/** 913/**
@@ -948,7 +930,7 @@ int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec)
948 int status, nr_entries; 930 int status, nr_entries;
949 int i, j; 931 int i, j;
950 932
951 if (!entries) 933 if (!entries || !dev->msix_cap)
952 return -EINVAL; 934 return -EINVAL;
953 935
954 status = pci_msi_check_device(dev, nvec, PCI_CAP_ID_MSIX); 936 status = pci_msi_check_device(dev, nvec, PCI_CAP_ID_MSIX);
@@ -1048,15 +1030,17 @@ EXPORT_SYMBOL(pci_msi_enabled);
1048 1030
1049void pci_msi_init_pci_dev(struct pci_dev *dev) 1031void pci_msi_init_pci_dev(struct pci_dev *dev)
1050{ 1032{
1051 int pos;
1052 INIT_LIST_HEAD(&dev->msi_list); 1033 INIT_LIST_HEAD(&dev->msi_list);
1053 1034
1054 /* Disable the msi hardware to avoid screaming interrupts 1035 /* Disable the msi hardware to avoid screaming interrupts
1055 * during boot. This is the power on reset default so 1036 * during boot. This is the power on reset default so
1056 * usually this should be a noop. 1037 * usually this should be a noop.
1057 */ 1038 */
1058 pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 1039 dev->msi_cap = pci_find_capability(dev, PCI_CAP_ID_MSI);
1059 if (pos) 1040 if (dev->msi_cap)
1060 msi_set_enable(dev, pos, 0); 1041 msi_set_enable(dev, 0);
1061 msix_set_enable(dev, 0); 1042
1043 dev->msix_cap = pci_find_capability(dev, PCI_CAP_ID_MSIX);
1044 if (dev->msix_cap)
1045 msix_set_enable(dev, 0);
1062} 1046}