PCI/MSI: Introduce helpers to hide struct msi_desc implementation details
authorJiang Liu <jiang.liu@linux.intel.com>
Sat, 15 Nov 2014 14:24:03 +0000 (22:24 +0800)
committerThomas Gleixner <tglx@linutronix.de>
Sun, 23 Nov 2014 12:01:45 +0000 (13:01 +0100)
Introduce helpers to hide struct msi_desc implementation details,
so we could easily support non-PCI-compliant MSI devices later by
moving msi_list into struct device.

Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Grant Likely <grant.likely@linaro.org>
Cc: Marc Zyngier <marc.zyngier@arm.com>
Cc: Yijing Wang <wangyijing@huawei.com>
Cc: Yingjoe Chen <yingjoe.chen@mediatek.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: Alexander Gordeev <agordeev@redhat.com>
Link: http://lkml.kernel.org/r/1416061447-9472-6-git-send-email-jiang.liu@linux.intel.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
include/linux/msi.h

index 1dcad0c1e80692df26713221eb81b74913f42967..e0d08517bd3d16a54514014e5c6fc124f00cc609 100644 (file)
@@ -43,6 +43,25 @@ struct msi_desc {
        struct msi_msg msg;
 };
 
+/* Helpers to hide struct msi_desc implementation details */
+#define msi_desc_to_dev(desc)          (&(desc)->dev.dev)
+#define dev_to_msi_list(dev)           (&to_pci_dev((dev))->msi_list)
+#define first_msi_entry(dev)           \
+       list_first_entry(dev_to_msi_list((dev)), struct msi_desc, list)
+#define for_each_msi_entry(desc, dev)  \
+       list_for_each_entry((desc), dev_to_msi_list((dev)), list)
+
+#ifdef CONFIG_PCI_MSI
+#define first_pci_msi_entry(pdev)      first_msi_entry(&(pdev)->dev)
+#define for_each_pci_msi_entry(desc, pdev)     \
+       for_each_msi_entry((desc), &(pdev)->dev)
+
+static inline struct pci_dev *msi_desc_to_pci_dev(struct msi_desc *desc)
+{
+       return desc->dev;
+}
+#endif /* CONFIG_PCI_MSI */
+
 void __pci_read_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
 void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
 void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg);