@@ -114,6 +114,10 @@ struct msi_desc;
int native_setup_msi_irqs(struct pci_dev *dev, int nvec, int type);
void native_teardown_msi_irq(unsigned int irq);
void native_restore_msi_irqs(struct pci_dev *dev);
+#ifdef CONFIG_MSI_IMS
+int native_setup_ims_irqs(struct device *dev, int nvec);
+#endif
+
#else
#define native_setup_msi_irqs NULL
#define native_teardown_msi_irq NULL
@@ -287,6 +287,15 @@ struct x86_msi_ops {
void (*restore_msi_irqs)(struct pci_dev *dev);
};
+struct device;
+
+struct x86_ims_ops {
+ int (*setup_ims_irqs)(struct device *dev, int nvec);
+ void (*teardown_ims_irq)(unsigned int irq);
+ void (*teardown_ims_irqs)(struct device *dev);
+ void (*restore_ims_irqs)(struct device *dev);
+};
+
struct x86_apic_ops {
unsigned int (*io_apic_read) (unsigned int apic, unsigned int reg);
void (*restore)(void);
@@ -297,6 +306,7 @@ extern struct x86_cpuinit_ops x86_cpuinit;
extern struct x86_platform_ops x86_platform;
extern struct x86_msi_ops x86_msi;
extern struct x86_apic_ops x86_apic_ops;
+extern struct x86_ims_ops x86_ims;
extern void x86_early_init_platform_quirks(void);
extern void x86_init_noop(void);
@@ -9,6 +9,7 @@
#include <linux/irq.h>
#include <linux/mdev.h>
#include <linux/pci.h>
+#include <asm/irq_remapping.h>
/*
* Determine if a dev is mdev or not. Return NULL if not mdev device.
@@ -45,6 +46,23 @@ static struct pci_dev *ims_get_pci_dev(struct device *dev)
return pdev;
}
+int native_setup_ims_irqs(struct device *dev, int nvec)
+{
+ struct irq_domain *domain;
+ struct irq_alloc_info info;
+ struct pci_dev *pdev = ims_get_pci_dev(dev);
+
+ init_irq_alloc_info(&info, NULL);
+ info.type = X86_IRQ_ALLOC_TYPE_MSIX;
+ info.msi_dev = pdev;
+
+ domain = irq_remapping_get_ims_irq_domain(&info);
+ if (!domain)
+ return -ENOSYS;
+
+ return msi_domain_alloc_irqs(domain, dev, nvec);
+}
+
int dev_ims_prepare(struct irq_domain *domain, struct device *dev, int nvec,
msi_alloc_info_t *arg)
{
@@ -153,6 +153,29 @@ void arch_restore_msi_irqs(struct pci_dev *dev)
}
#endif
+#if defined(CONFIG_MSI_IMS)
+struct x86_ims_ops x86_ims __ro_after_init = {
+ .setup_ims_irqs = native_setup_ims_irqs,
+ .teardown_ims_irqs = dev_ims_teardown_irqs,
+ .restore_ims_irqs = dev_ims_restore_irqs,
+};
+
+int arch_setup_ims_irqs(struct device *dev, int nvec)
+{
+ return x86_ims.setup_ims_irqs(dev, nvec);
+}
+
+void arch_teardown_ims_irqs(struct device *dev)
+{
+ x86_ims.teardown_ims_irqs(dev);
+}
+
+void arch_restore_ims_irqs(struct device *dev)
+{
+ x86_ims.restore_ims_irqs(dev);
+}
+#endif
+
struct x86_apic_ops x86_apic_ops __ro_after_init = {
.io_apic_read = native_io_apic_read,
.restore = native_restore_boot_irq_mode,
@@ -92,3 +92,37 @@ void dev_ims_write_msg(struct irq_data *data, struct msi_msg *msg)
__dev_write_ims_msg(desc, msg);
}
EXPORT_SYMBOL_GPL(dev_ims_write_msg);
+
+void dev_ims_teardown_irqs(struct device *dev)
+{
+ struct msi_desc *entry;
+
+ for_each_msi_entry(entry, dev)
+ if (entry->irq && entry->tag == IRQ_MSI_TAG_IMS)
+ arch_teardown_msi_irq(entry->irq);
+}
+
+static void dev_ims_restore_irq(struct device *dev, int irq)
+{
+ struct msi_desc *entry = NULL;
+ struct dev_ims_ops *ops;
+
+ for_each_msi_entry(entry, dev)
+ if (irq == entry->irq && entry->tag == IRQ_MSI_TAG_IMS)
+ break;
+
+ if (entry) {
+ ops = entry->dev_ims.priv->ims_ops;
+ if (ops && ops->irq_write_msi_msg)
+ ops->irq_write_msi_msg(entry, &entry->msg);
+ }
+}
+
+void dev_ims_restore_irqs(struct device *dev)
+{
+ struct msi_desc *entry;
+
+ for_each_msi_entry(entry, dev)
+ if (entry->tag == IRQ_MSI_TAG_IMS)
+ dev_ims_restore_irq(dev, entry->irq);
+}
@@ -233,6 +233,8 @@ void pci_msi_unmask_irq(struct irq_data *data);
void dev_ims_unmask_irq(struct irq_data *data);
void dev_ims_mask_irq(struct irq_data *data);
void dev_ims_write_msg(struct irq_data *data, struct msi_msg *msg);
+void dev_ims_teardown_irqs(struct device *dev);
+void dev_ims_restore_irqs(struct device *dev);
/*
* The arch hooks to setup up msi irqs. Those functions are
@@ -245,6 +247,10 @@ int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type);
void arch_teardown_msi_irqs(struct pci_dev *dev);
void arch_restore_msi_irqs(struct pci_dev *dev);
+int arch_setup_ims_irqs(struct device *dev, int nvec);
+void arch_teardown_ims_irqs(struct device *dev);
+void arch_restore_ims_irqs(struct device *dev);
+
void default_teardown_msi_irqs(struct pci_dev *dev);
void default_restore_msi_irqs(struct pci_dev *dev);