blob: 3d9efd14a63f239f6b8b905b5e8412dfe1610188 [file] [log] [blame]
Marc Zyngier1e6db002015-07-28 14:46:22 +01001/*
2 * Copyright (C) 2013-2015 ARM Limited, All Rights Reserved.
3 * Author: Marc Zyngier <marc.zyngier@arm.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <linux/device.h>
19#include <linux/msi.h>
20#include <linux/of.h>
21#include <linux/of_irq.h>
22
23static struct irq_chip its_pmsi_irq_chip = {
24 .name = "ITS-pMSI",
25};
26
Hanjun Guo9ab460c2017-03-07 20:40:00 +080027static int of_pmsi_get_dev_id(struct irq_domain *domain, struct device *dev,
28 u32 *dev_id)
Marc Zyngier1e6db002015-07-28 14:46:22 +010029{
Marc Zyngierdeac7fc2015-09-18 14:07:40 +010030 int ret, index = 0;
Marc Zyngier1e6db002015-07-28 14:46:22 +010031
Marc Zyngier1e6db002015-07-28 14:46:22 +010032 /* Suck the DeviceID out of the msi-parent property */
Marc Zyngierdeac7fc2015-09-18 14:07:40 +010033 do {
34 struct of_phandle_args args;
35
36 ret = of_parse_phandle_with_args(dev->of_node,
37 "msi-parent", "#msi-cells",
38 index, &args);
39 if (args.np == irq_domain_get_of_node(domain)) {
40 if (WARN_ON(args.args_count != 1))
41 return -EINVAL;
Hanjun Guo9ab460c2017-03-07 20:40:00 +080042 *dev_id = args.args[0];
Marc Zyngierdeac7fc2015-09-18 14:07:40 +010043 break;
44 }
45 } while (!ret);
46
Hanjun Guo9ab460c2017-03-07 20:40:00 +080047 return ret;
48}
49
50static int its_pmsi_prepare(struct irq_domain *domain, struct device *dev,
51 int nvec, msi_alloc_info_t *info)
52{
53 struct msi_domain_info *msi_info;
54 u32 dev_id;
55 int ret;
56
57 msi_info = msi_get_domain_info(domain->parent);
58
59 ret = of_pmsi_get_dev_id(domain, dev, &dev_id);
Marc Zyngier1e6db002015-07-28 14:46:22 +010060 if (ret)
61 return ret;
62
63 /* ITS specific DeviceID, as the core ITS ignores dev. */
64 info->scratchpad[0].ul = dev_id;
65
66 return msi_info->ops->msi_prepare(domain->parent,
67 dev, nvec, info);
68}
69
70static struct msi_domain_ops its_pmsi_ops = {
71 .msi_prepare = its_pmsi_prepare,
72};
73
74static struct msi_domain_info its_pmsi_domain_info = {
75 .flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS),
76 .ops = &its_pmsi_ops,
77 .chip = &its_pmsi_irq_chip,
78};
79
80static struct of_device_id its_device_id[] = {
81 { .compatible = "arm,gic-v3-its", },
82 {},
83};
84
Hanjun Guo42677db2017-03-07 20:40:01 +080085static int __init its_pmsi_init_one(struct fwnode_handle *fwnode,
86 const char *name)
87{
88 struct irq_domain *parent;
89
90 parent = irq_find_matching_fwnode(fwnode, DOMAIN_BUS_NEXUS);
91 if (!parent || !msi_get_domain_info(parent)) {
92 pr_err("%s: unable to locate ITS domain\n", name);
93 return -ENXIO;
94 }
95
96 if (!platform_msi_create_irq_domain(fwnode, &its_pmsi_domain_info,
97 parent)) {
98 pr_err("%s: unable to create platform domain\n", name);
99 return -ENXIO;
100 }
101
102 pr_info("Platform MSI: %s domain created\n", name);
103 return 0;
104}
105
106static void __init its_pmsi_of_init(void)
Marc Zyngier1e6db002015-07-28 14:46:22 +0100107{
108 struct device_node *np;
Marc Zyngier1e6db002015-07-28 14:46:22 +0100109
110 for (np = of_find_matching_node(NULL, its_device_id); np;
111 np = of_find_matching_node(np, its_device_id)) {
112 if (!of_property_read_bool(np, "msi-controller"))
113 continue;
114
Hanjun Guo42677db2017-03-07 20:40:01 +0800115 its_pmsi_init_one(of_node_to_fwnode(np), np->full_name);
Marc Zyngier1e6db002015-07-28 14:46:22 +0100116 }
Hanjun Guo42677db2017-03-07 20:40:01 +0800117}
Marc Zyngier1e6db002015-07-28 14:46:22 +0100118
Hanjun Guo42677db2017-03-07 20:40:01 +0800119static int __init its_pmsi_init(void)
120{
121 its_pmsi_of_init();
Marc Zyngier1e6db002015-07-28 14:46:22 +0100122 return 0;
123}
124early_initcall(its_pmsi_init);