blob: eaeb3c51e14b47a97f630afd04d1c841f2aaccb3 [file] [log] [blame]
J. German Rivera3a288fd2016-01-06 16:03:22 -06001/*
2 * Freescale Management Complex (MC) bus driver MSI support
3 *
4 * Copyright (C) 2015 Freescale Semiconductor, Inc.
5 * Author: German Rivera <German.Rivera@freescale.com>
6 *
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
10 */
11
J. German Rivera3a288fd2016-01-06 16:03:22 -060012#include <linux/of_device.h>
13#include <linux/of_address.h>
14#include <linux/irqchip/arm-gic-v3.h>
15#include <linux/irq.h>
16#include <linux/msi.h>
17#include <linux/of.h>
18#include <linux/of_irq.h>
Stuart Yoderd4e75132016-08-23 17:14:23 -050019#include "../include/mc-bus.h"
Bogdan Purcareata733ab052017-10-07 22:36:46 +000020#include "fsl-mc-private.h"
J. German Rivera3a288fd2016-01-06 16:03:22 -060021
22static struct irq_chip its_msi_irq_chip = {
23 .name = "fsl-mc-bus-msi",
24 .irq_mask = irq_chip_mask_parent,
25 .irq_unmask = irq_chip_unmask_parent,
26 .irq_eoi = irq_chip_eoi_parent,
27 .irq_set_affinity = msi_domain_set_affinity
28};
29
30static int its_fsl_mc_msi_prepare(struct irq_domain *msi_domain,
31 struct device *dev,
32 int nvec, msi_alloc_info_t *info)
33{
34 struct fsl_mc_device *mc_bus_dev;
35 struct msi_domain_info *msi_info;
36
Nipun Guptadf5e9b52016-06-29 22:44:39 +053037 if (WARN_ON(!dev_is_fsl_mc(dev)))
J. German Rivera3a288fd2016-01-06 16:03:22 -060038 return -EINVAL;
39
40 mc_bus_dev = to_fsl_mc_device(dev);
41 if (WARN_ON(!(mc_bus_dev->flags & FSL_MC_IS_DPRC)))
42 return -EINVAL;
43
44 /*
45 * Set the device Id to be passed to the GIC-ITS:
46 *
47 * NOTE: This device id corresponds to the IOMMU stream ID
48 * associated with the DPRC object (ICID).
49 */
50 info->scratchpad[0].ul = mc_bus_dev->icid;
51 msi_info = msi_get_domain_info(msi_domain->parent);
52 return msi_info->ops->msi_prepare(msi_domain->parent, dev, nvec, info);
53}
54
55static struct msi_domain_ops its_fsl_mc_msi_ops = {
56 .msi_prepare = its_fsl_mc_msi_prepare,
57};
58
59static struct msi_domain_info its_fsl_mc_msi_domain_info = {
60 .flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS),
61 .ops = &its_fsl_mc_msi_ops,
62 .chip = &its_msi_irq_chip,
63};
64
65static const struct of_device_id its_device_id[] = {
66 { .compatible = "arm,gic-v3-its", },
67 {},
68};
69
70int __init its_fsl_mc_msi_init(void)
71{
72 struct device_node *np;
73 struct irq_domain *parent;
74 struct irq_domain *mc_msi_domain;
75
76 for (np = of_find_matching_node(NULL, its_device_id); np;
77 np = of_find_matching_node(np, its_device_id)) {
78 if (!of_property_read_bool(np, "msi-controller"))
79 continue;
80
81 parent = irq_find_matching_host(np, DOMAIN_BUS_NEXUS);
82 if (!parent || !msi_get_domain_info(parent)) {
83 pr_err("%s: unable to locate ITS domain\n",
84 np->full_name);
85 continue;
86 }
87
88 mc_msi_domain = fsl_mc_msi_create_irq_domain(
89 of_node_to_fwnode(np),
90 &its_fsl_mc_msi_domain_info,
91 parent);
92 if (!mc_msi_domain) {
93 pr_err("%s: unable to create fsl-mc domain\n",
94 np->full_name);
95 continue;
96 }
97
98 WARN_ON(mc_msi_domain->
99 host_data != &its_fsl_mc_msi_domain_info);
100
101 pr_info("fsl-mc MSI: %s domain created\n", np->full_name);
102 }
103
104 return 0;
105}
106
107void its_fsl_mc_msi_cleanup(void)
108{
109 struct device_node *np;
110
111 for (np = of_find_matching_node(NULL, its_device_id); np;
112 np = of_find_matching_node(np, its_device_id)) {
113 struct irq_domain *mc_msi_domain = irq_find_matching_host(
114 np,
115 DOMAIN_BUS_FSL_MC_MSI);
116
117 if (!of_property_read_bool(np, "msi-controller"))
118 continue;
119
J. German Rivera3a288fd2016-01-06 16:03:22 -0600120 if (mc_msi_domain &&
121 mc_msi_domain->host_data == &its_fsl_mc_msi_domain_info)
122 irq_domain_remove(mc_msi_domain);
123 }
124}