layerscape: add ls1088ardb device support
[openwrt/staging/lynxis/omap.git] / target / linux / layerscape / patches-4.4 / 7146-staging-fsl-mc-Added-GICv3-ITS-support-for-FSL-MC-MS.patch
1 From 85cb8ae26b6c69f0a118f32b7b7cd4f22d782da3 Mon Sep 17 00:00:00 2001
2 From: "J. German Rivera" <German.Rivera@freescale.com>
3 Date: Wed, 6 Jan 2016 16:03:22 -0600
4 Subject: [PATCH 146/226] staging: fsl-mc: Added GICv3-ITS support for FSL-MC
5 MSIs
6
7 Added platform-specific MSI support layer for FSL-MC devices.
8
9 Signed-off-by: J. German Rivera <German.Rivera@freescale.com>
10 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
11 ---
12 drivers/staging/fsl-mc/bus/Makefile | 1 +
13 .../staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c | 127 ++++++++++++++++++++
14 drivers/staging/fsl-mc/include/mc-private.h | 4 +
15 3 files changed, 132 insertions(+)
16 create mode 100644 drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
17
18 --- a/drivers/staging/fsl-mc/bus/Makefile
19 +++ b/drivers/staging/fsl-mc/bus/Makefile
20 @@ -14,5 +14,6 @@ mc-bus-driver-objs := mc-bus.o \
21 dprc-driver.o \
22 mc-allocator.o \
23 mc-msi.o \
24 + irq-gic-v3-its-fsl-mc-msi.o \
25 dpmcp.o \
26 dpbp.o
27 --- /dev/null
28 +++ b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
29 @@ -0,0 +1,127 @@
30 +/*
31 + * Freescale Management Complex (MC) bus driver MSI support
32 + *
33 + * Copyright (C) 2015 Freescale Semiconductor, Inc.
34 + * Author: German Rivera <German.Rivera@freescale.com>
35 + *
36 + * This file is licensed under the terms of the GNU General Public
37 + * License version 2. This program is licensed "as is" without any
38 + * warranty of any kind, whether express or implied.
39 + */
40 +
41 +#include "../include/mc-private.h"
42 +#include <linux/of_device.h>
43 +#include <linux/of_address.h>
44 +#include <linux/irqchip/arm-gic-v3.h>
45 +#include <linux/irq.h>
46 +#include <linux/msi.h>
47 +#include <linux/of.h>
48 +#include <linux/of_irq.h>
49 +#include "../include/mc-sys.h"
50 +#include "dprc-cmd.h"
51 +
52 +static struct irq_chip its_msi_irq_chip = {
53 + .name = "fsl-mc-bus-msi",
54 + .irq_mask = irq_chip_mask_parent,
55 + .irq_unmask = irq_chip_unmask_parent,
56 + .irq_eoi = irq_chip_eoi_parent,
57 + .irq_set_affinity = msi_domain_set_affinity
58 +};
59 +
60 +static int its_fsl_mc_msi_prepare(struct irq_domain *msi_domain,
61 + struct device *dev,
62 + int nvec, msi_alloc_info_t *info)
63 +{
64 + struct fsl_mc_device *mc_bus_dev;
65 + struct msi_domain_info *msi_info;
66 +
67 + if (WARN_ON(dev->bus != &fsl_mc_bus_type))
68 + return -EINVAL;
69 +
70 + mc_bus_dev = to_fsl_mc_device(dev);
71 + if (WARN_ON(!(mc_bus_dev->flags & FSL_MC_IS_DPRC)))
72 + return -EINVAL;
73 +
74 + /*
75 + * Set the device Id to be passed to the GIC-ITS:
76 + *
77 + * NOTE: This device id corresponds to the IOMMU stream ID
78 + * associated with the DPRC object (ICID).
79 + */
80 + info->scratchpad[0].ul = mc_bus_dev->icid;
81 + msi_info = msi_get_domain_info(msi_domain->parent);
82 + return msi_info->ops->msi_prepare(msi_domain->parent, dev, nvec, info);
83 +}
84 +
85 +static struct msi_domain_ops its_fsl_mc_msi_ops = {
86 + .msi_prepare = its_fsl_mc_msi_prepare,
87 +};
88 +
89 +static struct msi_domain_info its_fsl_mc_msi_domain_info = {
90 + .flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS),
91 + .ops = &its_fsl_mc_msi_ops,
92 + .chip = &its_msi_irq_chip,
93 +};
94 +
95 +static const struct of_device_id its_device_id[] = {
96 + { .compatible = "arm,gic-v3-its", },
97 + {},
98 +};
99 +
100 +int __init its_fsl_mc_msi_init(void)
101 +{
102 + struct device_node *np;
103 + struct irq_domain *parent;
104 + struct irq_domain *mc_msi_domain;
105 +
106 + for (np = of_find_matching_node(NULL, its_device_id); np;
107 + np = of_find_matching_node(np, its_device_id)) {
108 + if (!of_property_read_bool(np, "msi-controller"))
109 + continue;
110 +
111 + parent = irq_find_matching_host(np, DOMAIN_BUS_NEXUS);
112 + if (!parent || !msi_get_domain_info(parent)) {
113 + pr_err("%s: unable to locate ITS domain\n",
114 + np->full_name);
115 + continue;
116 + }
117 +
118 + mc_msi_domain = fsl_mc_msi_create_irq_domain(
119 + of_node_to_fwnode(np),
120 + &its_fsl_mc_msi_domain_info,
121 + parent);
122 + if (!mc_msi_domain) {
123 + pr_err("%s: unable to create fsl-mc domain\n",
124 + np->full_name);
125 + continue;
126 + }
127 +
128 + WARN_ON(mc_msi_domain->
129 + host_data != &its_fsl_mc_msi_domain_info);
130 +
131 + pr_info("fsl-mc MSI: %s domain created\n", np->full_name);
132 + }
133 +
134 + return 0;
135 +}
136 +
137 +void its_fsl_mc_msi_cleanup(void)
138 +{
139 + struct device_node *np;
140 +
141 + for (np = of_find_matching_node(NULL, its_device_id); np;
142 + np = of_find_matching_node(np, its_device_id)) {
143 + struct irq_domain *mc_msi_domain = irq_find_matching_host(
144 + np,
145 + DOMAIN_BUS_FSL_MC_MSI);
146 +
147 + if (!of_property_read_bool(np, "msi-controller"))
148 + continue;
149 +
150 + mc_msi_domain = irq_find_matching_host(np,
151 + DOMAIN_BUS_FSL_MC_MSI);
152 + if (mc_msi_domain &&
153 + mc_msi_domain->host_data == &its_fsl_mc_msi_domain_info)
154 + irq_domain_remove(mc_msi_domain);
155 + }
156 +}
157 --- a/drivers/staging/fsl-mc/include/mc-private.h
158 +++ b/drivers/staging/fsl-mc/include/mc-private.h
159 @@ -133,4 +133,8 @@ int fsl_mc_msi_domain_alloc_irqs(struct
160
161 void fsl_mc_msi_domain_free_irqs(struct device *dev);
162
163 +int __init its_fsl_mc_msi_init(void);
164 +
165 +void its_fsl_mc_msi_cleanup(void);
166 +
167 #endif /* _FSL_MC_PRIVATE_H_ */