blob: e4768fcdc67270521f8ca14af0a87024a1eb782e [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
27static int its_pmsi_prepare(struct irq_domain *domain, struct device *dev,
28 int nvec, msi_alloc_info_t *info)
29{
30 struct msi_domain_info *msi_info;
31 u32 dev_id;
Marc Zyngierdeac7fc2015-09-18 14:07:40 +010032 int ret, index = 0;
Marc Zyngier1e6db002015-07-28 14:46:22 +010033
34 msi_info = msi_get_domain_info(domain->parent);
35
36 /* Suck the DeviceID out of the msi-parent property */
Marc Zyngierdeac7fc2015-09-18 14:07:40 +010037 do {
38 struct of_phandle_args args;
39
40 ret = of_parse_phandle_with_args(dev->of_node,
41 "msi-parent", "#msi-cells",
42 index, &args);
43 if (args.np == irq_domain_get_of_node(domain)) {
44 if (WARN_ON(args.args_count != 1))
45 return -EINVAL;
46 dev_id = args.args[0];
47 break;
48 }
49 } while (!ret);
50
Marc Zyngier1e6db002015-07-28 14:46:22 +010051 if (ret)
52 return ret;
53
54 /* ITS specific DeviceID, as the core ITS ignores dev. */
55 info->scratchpad[0].ul = dev_id;
56
57 return msi_info->ops->msi_prepare(domain->parent,
58 dev, nvec, info);
59}
60
61static struct msi_domain_ops its_pmsi_ops = {
62 .msi_prepare = its_pmsi_prepare,
63};
64
65static struct msi_domain_info its_pmsi_domain_info = {
66 .flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS),
67 .ops = &its_pmsi_ops,
68 .chip = &its_pmsi_irq_chip,
69};
70
71static struct of_device_id its_device_id[] = {
72 { .compatible = "arm,gic-v3-its", },
73 {},
74};
75
76static int __init its_pmsi_init(void)
77{
78 struct device_node *np;
79 struct irq_domain *parent;
80
81 for (np = of_find_matching_node(NULL, its_device_id); np;
82 np = of_find_matching_node(np, its_device_id)) {
Stephen Boyd7f409f12018-02-01 09:03:29 -080083 if (!of_device_is_available(np))
84 continue;
Marc Zyngier1e6db002015-07-28 14:46:22 +010085 if (!of_property_read_bool(np, "msi-controller"))
86 continue;
87
88 parent = irq_find_matching_host(np, DOMAIN_BUS_NEXUS);
89 if (!parent || !msi_get_domain_info(parent)) {
90 pr_err("%s: unable to locate ITS domain\n",
91 np->full_name);
92 continue;
93 }
94
Marc Zyngierbe5436c2015-10-13 12:51:44 +010095 if (!platform_msi_create_irq_domain(of_node_to_fwnode(np),
96 &its_pmsi_domain_info,
Marc Zyngier1e6db002015-07-28 14:46:22 +010097 parent)) {
98 pr_err("%s: unable to create platform domain\n",
99 np->full_name);
100 continue;
101 }
102
103 pr_info("Platform MSI: %s domain created\n", np->full_name);
104 }
105
106 return 0;
107}
108early_initcall(its_pmsi_init);