mfd: kempld-core: Constify variables that point to const structure
[linux-2.6-block.git] / drivers / irqchip / irq-gic-v3-its-platform-msi.c
CommitLineData
1e6db000
MZ
1/*
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
f785f7d2 18#include <linux/acpi_iort.h>
1e6db000
MZ
19#include <linux/device.h>
20#include <linux/msi.h>
21#include <linux/of.h>
22#include <linux/of_irq.h>
23
24static struct irq_chip its_pmsi_irq_chip = {
25 .name = "ITS-pMSI",
26};
27
9ab460c2
HG
28static int of_pmsi_get_dev_id(struct irq_domain *domain, struct device *dev,
29 u32 *dev_id)
1e6db000 30{
deac7fc1 31 int ret, index = 0;
1e6db000 32
1e6db000 33 /* Suck the DeviceID out of the msi-parent property */
deac7fc1
MZ
34 do {
35 struct of_phandle_args args;
36
37 ret = of_parse_phandle_with_args(dev->of_node,
38 "msi-parent", "#msi-cells",
39 index, &args);
40 if (args.np == irq_domain_get_of_node(domain)) {
41 if (WARN_ON(args.args_count != 1))
42 return -EINVAL;
9ab460c2 43 *dev_id = args.args[0];
deac7fc1
MZ
44 break;
45 }
a0088737 46 index++;
deac7fc1
MZ
47 } while (!ret);
48
9ab460c2
HG
49 return ret;
50}
51
c2c8661f
MZ
52int __weak iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id)
53{
54 return -1;
55}
56
9ab460c2
HG
57static int its_pmsi_prepare(struct irq_domain *domain, struct device *dev,
58 int nvec, msi_alloc_info_t *info)
59{
60 struct msi_domain_info *msi_info;
61 u32 dev_id;
62 int ret;
63
64 msi_info = msi_get_domain_info(domain->parent);
65
c2c8661f
MZ
66 if (dev->of_node)
67 ret = of_pmsi_get_dev_id(domain, dev, &dev_id);
68 else
69 ret = iort_pmsi_get_dev_id(dev, &dev_id);
1e6db000
MZ
70 if (ret)
71 return ret;
72
73 /* ITS specific DeviceID, as the core ITS ignores dev. */
74 info->scratchpad[0].ul = dev_id;
75
76 return msi_info->ops->msi_prepare(domain->parent,
77 dev, nvec, info);
78}
79
80static struct msi_domain_ops its_pmsi_ops = {
81 .msi_prepare = its_pmsi_prepare,
82};
83
84static struct msi_domain_info its_pmsi_domain_info = {
85 .flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS),
86 .ops = &its_pmsi_ops,
87 .chip = &its_pmsi_irq_chip,
88};
89
5b867061 90static const struct of_device_id its_device_id[] = {
1e6db000
MZ
91 { .compatible = "arm,gic-v3-its", },
92 {},
93};
94
42677db9
HG
95static int __init its_pmsi_init_one(struct fwnode_handle *fwnode,
96 const char *name)
1e6db000 97{
1e6db000
MZ
98 struct irq_domain *parent;
99
42677db9
HG
100 parent = irq_find_matching_fwnode(fwnode, DOMAIN_BUS_NEXUS);
101 if (!parent || !msi_get_domain_info(parent)) {
102 pr_err("%s: unable to locate ITS domain\n", name);
103 return -ENXIO;
104 }
105
106 if (!platform_msi_create_irq_domain(fwnode, &its_pmsi_domain_info,
107 parent)) {
108 pr_err("%s: unable to create platform domain\n", name);
109 return -ENXIO;
110 }
111
112 pr_info("Platform MSI: %s domain created\n", name);
113 return 0;
114}
115
f785f7d2
HG
116#ifdef CONFIG_ACPI
117static int __init
118its_pmsi_parse_madt(struct acpi_subtable_header *header,
119 const unsigned long end)
120{
121 struct acpi_madt_generic_translator *its_entry;
122 struct fwnode_handle *domain_handle;
123 const char *node_name;
124 int err = -ENXIO;
125
126 its_entry = (struct acpi_madt_generic_translator *)header;
127 node_name = kasprintf(GFP_KERNEL, "ITS@0x%lx",
128 (long)its_entry->base_address);
129 domain_handle = iort_find_domain_token(its_entry->translation_id);
130 if (!domain_handle) {
131 pr_err("%s: Unable to locate ITS domain handle\n", node_name);
132 goto out;
133 }
134
135 err = its_pmsi_init_one(domain_handle, node_name);
136
137out:
138 kfree(node_name);
139 return err;
140}
141
142static void __init its_pmsi_acpi_init(void)
143{
144 acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_TRANSLATOR,
145 its_pmsi_parse_madt, 0);
146}
147#else
148static inline void its_pmsi_acpi_init(void) { }
149#endif
150
42677db9
HG
151static void __init its_pmsi_of_init(void)
152{
153 struct device_node *np;
154
1e6db000
MZ
155 for (np = of_find_matching_node(NULL, its_device_id); np;
156 np = of_find_matching_node(np, its_device_id)) {
95a25625
SB
157 if (!of_device_is_available(np))
158 continue;
1e6db000
MZ
159 if (!of_property_read_bool(np, "msi-controller"))
160 continue;
161
42677db9 162 its_pmsi_init_one(of_node_to_fwnode(np), np->full_name);
1e6db000 163 }
42677db9 164}
1e6db000 165
42677db9
HG
166static int __init its_pmsi_init(void)
167{
168 its_pmsi_of_init();
f785f7d2 169 its_pmsi_acpi_init();
1e6db000
MZ
170 return 0;
171}
172early_initcall(its_pmsi_init);