0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/acpi.h>
0011 #include <linux/acpi_iort.h>
0012 #include <linux/of_device.h>
0013 #include <linux/of_address.h>
0014 #include <linux/irq.h>
0015 #include <linux/msi.h>
0016 #include <linux/of.h>
0017 #include <linux/of_irq.h>
0018 #include <linux/fsl/mc.h>
0019
0020 static struct irq_chip its_msi_irq_chip = {
0021 .name = "ITS-fMSI",
0022 .irq_mask = irq_chip_mask_parent,
0023 .irq_unmask = irq_chip_unmask_parent,
0024 .irq_eoi = irq_chip_eoi_parent,
0025 .irq_set_affinity = msi_domain_set_affinity
0026 };
0027
0028 static u32 fsl_mc_msi_domain_get_msi_id(struct irq_domain *domain,
0029 struct fsl_mc_device *mc_dev)
0030 {
0031 struct device_node *of_node;
0032 u32 out_id;
0033
0034 of_node = irq_domain_get_of_node(domain);
0035 out_id = of_node ? of_msi_map_id(&mc_dev->dev, of_node, mc_dev->icid) :
0036 iort_msi_map_id(&mc_dev->dev, mc_dev->icid);
0037
0038 return out_id;
0039 }
0040
0041 static int its_fsl_mc_msi_prepare(struct irq_domain *msi_domain,
0042 struct device *dev,
0043 int nvec, msi_alloc_info_t *info)
0044 {
0045 struct fsl_mc_device *mc_bus_dev;
0046 struct msi_domain_info *msi_info;
0047
0048 if (!dev_is_fsl_mc(dev))
0049 return -EINVAL;
0050
0051 mc_bus_dev = to_fsl_mc_device(dev);
0052 if (!(mc_bus_dev->flags & FSL_MC_IS_DPRC))
0053 return -EINVAL;
0054
0055
0056
0057
0058
0059
0060
0061 info->scratchpad[0].ul = fsl_mc_msi_domain_get_msi_id(msi_domain,
0062 mc_bus_dev);
0063 msi_info = msi_get_domain_info(msi_domain->parent);
0064
0065
0066 nvec = max_t(int, 32, roundup_pow_of_two(nvec));
0067 return msi_info->ops->msi_prepare(msi_domain->parent, dev, nvec, info);
0068 }
0069
0070 static struct msi_domain_ops its_fsl_mc_msi_ops __ro_after_init = {
0071 .msi_prepare = its_fsl_mc_msi_prepare,
0072 };
0073
0074 static struct msi_domain_info its_fsl_mc_msi_domain_info = {
0075 .flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS),
0076 .ops = &its_fsl_mc_msi_ops,
0077 .chip = &its_msi_irq_chip,
0078 };
0079
0080 static const struct of_device_id its_device_id[] = {
0081 { .compatible = "arm,gic-v3-its", },
0082 {},
0083 };
0084
0085 static void __init its_fsl_mc_msi_init_one(struct fwnode_handle *handle,
0086 const char *name)
0087 {
0088 struct irq_domain *parent;
0089 struct irq_domain *mc_msi_domain;
0090
0091 parent = irq_find_matching_fwnode(handle, DOMAIN_BUS_NEXUS);
0092 if (!parent || !msi_get_domain_info(parent)) {
0093 pr_err("%s: unable to locate ITS domain\n", name);
0094 return;
0095 }
0096
0097 mc_msi_domain = fsl_mc_msi_create_irq_domain(handle,
0098 &its_fsl_mc_msi_domain_info,
0099 parent);
0100 if (!mc_msi_domain) {
0101 pr_err("%s: unable to create fsl-mc domain\n", name);
0102 return;
0103 }
0104
0105 pr_info("fsl-mc MSI: %s domain created\n", name);
0106 }
0107
0108 #ifdef CONFIG_ACPI
0109 static int __init
0110 its_fsl_mc_msi_parse_madt(union acpi_subtable_headers *header,
0111 const unsigned long end)
0112 {
0113 struct acpi_madt_generic_translator *its_entry;
0114 struct fwnode_handle *dom_handle;
0115 const char *node_name;
0116 int err = 0;
0117
0118 its_entry = (struct acpi_madt_generic_translator *)header;
0119 node_name = kasprintf(GFP_KERNEL, "ITS@0x%lx",
0120 (long)its_entry->base_address);
0121
0122 dom_handle = iort_find_domain_token(its_entry->translation_id);
0123 if (!dom_handle) {
0124 pr_err("%s: Unable to locate ITS domain handle\n", node_name);
0125 err = -ENXIO;
0126 goto out;
0127 }
0128
0129 its_fsl_mc_msi_init_one(dom_handle, node_name);
0130
0131 out:
0132 kfree(node_name);
0133 return err;
0134 }
0135
0136
0137 static void __init its_fsl_mc_acpi_msi_init(void)
0138 {
0139 acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_TRANSLATOR,
0140 its_fsl_mc_msi_parse_madt, 0);
0141 }
0142 #else
0143 static inline void its_fsl_mc_acpi_msi_init(void) { }
0144 #endif
0145
0146 static void __init its_fsl_mc_of_msi_init(void)
0147 {
0148 struct device_node *np;
0149
0150 for (np = of_find_matching_node(NULL, its_device_id); np;
0151 np = of_find_matching_node(np, its_device_id)) {
0152 if (!of_device_is_available(np))
0153 continue;
0154 if (!of_property_read_bool(np, "msi-controller"))
0155 continue;
0156
0157 its_fsl_mc_msi_init_one(of_node_to_fwnode(np),
0158 np->full_name);
0159 }
0160 }
0161
0162 static int __init its_fsl_mc_msi_init(void)
0163 {
0164 its_fsl_mc_of_msi_init();
0165 its_fsl_mc_acpi_msi_init();
0166
0167 return 0;
0168 }
0169
0170 early_initcall(its_fsl_mc_msi_init);