PCI: MSI: Restore read_msi_msg_desc(); add get_cached_msi_msg_desc()
authorBen Hutchings <bhutchings@solarflare.com>
Fri, 23 Jul 2010 13:56:28 +0000 (14:56 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 20 Sep 2010 20:17:44 +0000 (13:17 -0700)
commit 30da55242818a8ca08583188ebcbaccd283ad4d9 upstream.

commit 2ca1af9aa3285c6a5f103ed31ad09f7399fc65d7 "PCI: MSI: Remove
unsafe and unnecessary hardware access" changed read_msi_msg_desc() to
return the last MSI message written instead of reading it from the
device, since it may be called while the device is in a reduced
power state.

However, the pSeries platform code really does need to read messages
from the device, since they are initially written by firmware.
Therefore:
- Restore the previous behaviour of read_msi_msg_desc()
- Add new functions get_cached_msi_msg{,_desc}() which return the
  last MSI message written
- Use the new functions where appropriate

Acked-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
arch/ia64/kernel/msi_ia64.c
arch/ia64/sn/kernel/msi_sn.c
arch/x86/kernel/apic/io_apic.c
drivers/pci/msi.c
include/linux/msi.h

index 6c89228560493df8d17d6e0f7d1b65d28ee543ad..4a746ea838ff37b423f92f31a8eecc8207f6217a 100644 (file)
@@ -25,7 +25,7 @@ static int ia64_set_msi_irq_affinity(unsigned int irq,
        if (irq_prepare_move(irq, cpu))
                return -1;
 
-       read_msi_msg(irq, &msg);
+       get_cached_msi_msg(irq, &msg);
 
        addr = msg.address_lo;
        addr &= MSI_ADDR_DEST_ID_MASK;
index fbbfb970120128a29df68c549895187ea3e3013e..9ab2617e46ec1a292988d412a60aa2812fcb9cc7 100644 (file)
@@ -174,7 +174,7 @@ static int sn_set_msi_irq_affinity(unsigned int irq,
         * Release XIO resources for the old MSI PCI address
         */
 
-       read_msi_msg(irq, &msg);
+       get_cached_msi_msg(irq, &msg);
         sn_pdev = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
        pdev = sn_pdev->pdi_linux_pcidev;
        provider = SN_PCIDEV_BUSPROVIDER(pdev);
index 1acd1c451638f533447cc06765bd7d4deccaf636..0da649533dda1c64c68b1fe11f57f5b893ee31ff 100644 (file)
@@ -3338,7 +3338,7 @@ static int set_msi_irq_affinity(unsigned int irq, const struct cpumask *mask)
 
        cfg = desc->chip_data;
 
-       read_msi_msg_desc(desc, &msg);
+       get_cached_msi_msg_desc(desc, &msg);
 
        msg.data &= ~MSI_DATA_VECTOR_MASK;
        msg.data |= MSI_DATA_VECTOR(cfg->vector);
index 475fa456fd545615b47beb89e660177d4a8d67a4..0fb1d0542339281533895b53bbf3aba8988c64af 100644 (file)
@@ -196,9 +196,46 @@ void read_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
 {
        struct msi_desc *entry = get_irq_desc_msi(desc);
 
-       /* We do not touch the hardware (which may not even be
-        * accessible at the moment) but return the last message
-        * written.  Assert that this is valid, assuming that
+       BUG_ON(entry->dev->current_state != PCI_D0);
+
+       if (entry->msi_attrib.is_msix) {
+               void __iomem *base = entry->mask_base +
+                       entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE;
+
+               msg->address_lo = readl(base + PCI_MSIX_ENTRY_LOWER_ADDR);
+               msg->address_hi = readl(base + PCI_MSIX_ENTRY_UPPER_ADDR);
+               msg->data = readl(base + PCI_MSIX_ENTRY_DATA);
+       } else {
+               struct pci_dev *dev = entry->dev;
+               int pos = entry->msi_attrib.pos;
+               u16 data;
+
+               pci_read_config_dword(dev, msi_lower_address_reg(pos),
+                                       &msg->address_lo);
+               if (entry->msi_attrib.is_64) {
+                       pci_read_config_dword(dev, msi_upper_address_reg(pos),
+                                               &msg->address_hi);
+                       pci_read_config_word(dev, msi_data_reg(pos, 1), &data);
+               } else {
+                       msg->address_hi = 0;
+                       pci_read_config_word(dev, msi_data_reg(pos, 0), &data);
+               }
+               msg->data = data;
+       }
+}
+
+void read_msi_msg(unsigned int irq, struct msi_msg *msg)
+{
+       struct irq_desc *desc = irq_to_desc(irq);
+
+       read_msi_msg_desc(desc, msg);
+}
+
+void get_cached_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
+{
+       struct msi_desc *entry = get_irq_desc_msi(desc);
+
+       /* Assert that the cache is valid, assuming that
         * valid messages are not all-zeroes. */
        BUG_ON(!(entry->msg.address_hi | entry->msg.address_lo |
                 entry->msg.data));
@@ -206,11 +243,11 @@ void read_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
        *msg = entry->msg;
 }
 
-void read_msi_msg(unsigned int irq, struct msi_msg *msg)
+void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg)
 {
        struct irq_desc *desc = irq_to_desc(irq);
 
-       read_msi_msg_desc(desc, msg);
+       get_cached_msi_msg_desc(desc, msg);
 }
 
 void write_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
index 6991ab5b24d1bbfd736df4d27315a83ee7271779..91b05c171854f12488e92c8fe2d23812bb1f03e5 100644 (file)
@@ -14,8 +14,10 @@ struct irq_desc;
 extern void mask_msi_irq(unsigned int irq);
 extern void unmask_msi_irq(unsigned int irq);
 extern void read_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg);
+extern void get_cached_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg);
 extern void write_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg);
 extern void read_msi_msg(unsigned int irq, struct msi_msg *msg);
+extern void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg);
 extern void write_msi_msg(unsigned int irq, struct msi_msg *msg);
 
 struct msi_desc {