new file mode 100644
@@ -0,0 +1,26 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ARM64_MSI_H__
+#define __ARM64_MSI_H__
+
+struct arm64_msi_info {
+ struct pci_dev *pdev;
+ irq_hw_number_t msi_hwirq;
+ int nvec;
+};
+
+void arm64_init_msi_domain(struct irq_domain *parent, irq_flow_handler_t handle);
+
+#endif /* __ARM64_MSI_H__ */
@@ -31,6 +31,7 @@ arm64-obj-$(CONFIG_JUMP_LABEL) += jump_label.o
arm64-obj-$(CONFIG_KGDB) += kgdb.o
arm64-obj-$(CONFIG_EFI) += efi.o efi-stub.o efi-entry.o
arm64-obj-$(CONFIG_PCI) += pci.o
+arm64-obj-$(CONFIG_PCI_MSI_IRQ_DOMAIN) += msi.o
obj-y += $(arm64-obj-y) vdso/
obj-m += $(arm64-obj-m)
new file mode 100644
@@ -0,0 +1,114 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/irq.h>
+#include <linux/irqdomain.h>
+#include <linux/msi.h>
+
+#include <asm/msi.h>
+
+static struct irq_domain *pci_msi_default_domain;
+
+static void arm64_mask_msi_irq(struct irq_data *d)
+{
+ mask_msi_irq(d);
+ irq_chip_mask_parent(d);
+}
+
+static void arm64_unmask_msi_irq(struct irq_data *d)
+{
+ unmask_msi_irq(d);
+ irq_chip_unmask_parent(d);
+}
+
+static struct irq_chip pci_msi_irq_chip = {
+ .name = "PCI-MSI",
+ .irq_unmask = arm64_unmask_msi_irq,
+ .irq_mask = arm64_mask_msi_irq,
+ .irq_eoi = irq_chip_eoi_parent,
+ .irq_set_affinity = irq_chip_set_affinity_parent,
+ .irq_write_msi_msg = pci_msi_write_msg,
+};
+
+static void pci_msi_generate_hwirq(struct msi_domain_info *minfo, void *arg,
+ struct msi_desc *desc)
+{
+ struct arm64_msi_info *info = arg;
+
+ info->msi_hwirq = pci_msi_calc_hwirq(info->pdev, desc);
+}
+
+static irq_hw_number_t pci_msi_get_hwirq(struct msi_domain_info *minfo,
+ void *arg)
+{
+ struct arm64_msi_info *info = arg;
+
+ return info->msi_hwirq;
+}
+
+static int pci_msi_init(struct irq_domain *domain,
+ struct msi_domain_info *minfo, unsigned int virq,
+ irq_hw_number_t hwirq, void *arg)
+{
+ irq_domain_set_info(domain, virq, hwirq, minfo->chip, NULL,
+ minfo->data, NULL, NULL);
+
+ return 0;
+}
+
+static void pci_msi_free(struct irq_domain *domain,
+ struct msi_domain_info *info, unsigned int virq)
+{
+ struct msi_desc *desc = irq_get_msi_desc(virq);
+
+ if (desc)
+ desc->irq = 0;
+}
+
+static struct msi_domain_ops pci_msi_ops = {
+ .calc_hwirq = pci_msi_generate_hwirq,
+ .get_hwirq = pci_msi_get_hwirq,
+ .msi_init = pci_msi_init,
+ .msi_free = pci_msi_free,
+};
+
+static struct msi_domain_info pci_msi_info = {
+ .ops = &pci_msi_ops,
+ .chip = &pci_msi_irq_chip,
+ /* .data is used to contain our flow handler */
+};
+
+void arm64_init_msi_domain(struct irq_domain *parent, irq_flow_handler_t handle)
+{
+ WARN_ON(pci_msi_default_domain);
+ WARN_ON(pci_msi_info.data);
+ pci_msi_info.data = handle;
+ pci_msi_default_domain = msi_create_irq_domain(NULL,
+ &pci_msi_info,
+ parent);
+ if (!pci_msi_default_domain)
+ pr_warn("failed to initialize irqdomain for MSI/MSI-x.\n");
+}
+
+/* Override the weak version from drivers/pci/msi.c */
+int arch_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
+{
+ struct arm64_msi_info info;
+
+ info.pdev = pdev;
+ info.nvec = nvec;
+
+ return pci_msi_irq_domain_alloc_irqs(pci_msi_default_domain,
+ type, pdev, &info);
+}