]>
Commit | Line | Data |
---|---|---|
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 | ||
79433a4e | 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 | ||
24 | static struct irq_chip its_pmsi_irq_chip = { | |
25 | .name = "ITS-pMSI", | |
26 | }; | |
27 | ||
408f79a5 HG |
28 | static 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; | |
408f79a5 | 43 | *dev_id = args.args[0]; |
deac7fc1 MZ |
44 | break; |
45 | } | |
46 | } while (!ret); | |
47 | ||
408f79a5 HG |
48 | return ret; |
49 | } | |
50 | ||
51 | static int its_pmsi_prepare(struct irq_domain *domain, struct device *dev, | |
52 | int nvec, msi_alloc_info_t *info) | |
53 | { | |
54 | struct msi_domain_info *msi_info; | |
55 | u32 dev_id; | |
56 | int ret; | |
57 | ||
58 | msi_info = msi_get_domain_info(domain->parent); | |
59 | ||
f658ef27 HG |
60 | ret = dev->of_node ? of_pmsi_get_dev_id(domain, dev, &dev_id) : |
61 | iort_pmsi_get_dev_id(dev, &dev_id); | |
1e6db000 MZ |
62 | if (ret) |
63 | return ret; | |
64 | ||
65 | /* ITS specific DeviceID, as the core ITS ignores dev. */ | |
66 | info->scratchpad[0].ul = dev_id; | |
67 | ||
68 | return msi_info->ops->msi_prepare(domain->parent, | |
69 | dev, nvec, info); | |
70 | } | |
71 | ||
72 | static struct msi_domain_ops its_pmsi_ops = { | |
73 | .msi_prepare = its_pmsi_prepare, | |
74 | }; | |
75 | ||
76 | static struct msi_domain_info its_pmsi_domain_info = { | |
77 | .flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS), | |
78 | .ops = &its_pmsi_ops, | |
79 | .chip = &its_pmsi_irq_chip, | |
80 | }; | |
81 | ||
82 | static struct of_device_id its_device_id[] = { | |
83 | { .compatible = "arm,gic-v3-its", }, | |
84 | {}, | |
85 | }; | |
86 | ||
35ebe7ec HG |
87 | static int __init its_pmsi_init_one(struct fwnode_handle *fwnode, |
88 | const char *name) | |
1e6db000 | 89 | { |
1e6db000 MZ |
90 | struct irq_domain *parent; |
91 | ||
35ebe7ec HG |
92 | parent = irq_find_matching_fwnode(fwnode, DOMAIN_BUS_NEXUS); |
93 | if (!parent || !msi_get_domain_info(parent)) { | |
94 | pr_err("%s: unable to locate ITS domain\n", name); | |
95 | return -ENXIO; | |
96 | } | |
97 | ||
98 | if (!platform_msi_create_irq_domain(fwnode, &its_pmsi_domain_info, | |
99 | parent)) { | |
100 | pr_err("%s: unable to create platform domain\n", name); | |
101 | return -ENXIO; | |
102 | } | |
103 | ||
104 | pr_info("Platform MSI: %s domain created\n", name); | |
105 | return 0; | |
106 | } | |
107 | ||
79433a4e HG |
108 | #ifdef CONFIG_ACPI |
109 | static int __init | |
110 | its_pmsi_parse_madt(struct acpi_subtable_header *header, | |
111 | const unsigned long end) | |
112 | { | |
113 | struct acpi_madt_generic_translator *its_entry; | |
114 | struct fwnode_handle *domain_handle; | |
115 | const char *node_name; | |
116 | int err = -ENXIO; | |
117 | ||
118 | its_entry = (struct acpi_madt_generic_translator *)header; | |
119 | node_name = kasprintf(GFP_KERNEL, "ITS@0x%lx", | |
120 | (long)its_entry->base_address); | |
121 | domain_handle = iort_find_domain_token(its_entry->translation_id); | |
122 | if (!domain_handle) { | |
123 | pr_err("%s: Unable to locate ITS domain handle\n", node_name); | |
124 | goto out; | |
125 | } | |
126 | ||
127 | err = its_pmsi_init_one(domain_handle, node_name); | |
128 | ||
129 | out: | |
130 | kfree(node_name); | |
131 | return err; | |
132 | } | |
133 | ||
134 | static void __init its_pmsi_acpi_init(void) | |
135 | { | |
136 | acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_TRANSLATOR, | |
137 | its_pmsi_parse_madt, 0); | |
138 | } | |
139 | #else | |
140 | static inline void its_pmsi_acpi_init(void) { } | |
141 | #endif | |
142 | ||
35ebe7ec HG |
143 | static void __init its_pmsi_of_init(void) |
144 | { | |
145 | struct device_node *np; | |
146 | ||
1e6db000 MZ |
147 | for (np = of_find_matching_node(NULL, its_device_id); np; |
148 | np = of_find_matching_node(np, its_device_id)) { | |
149 | if (!of_property_read_bool(np, "msi-controller")) | |
150 | continue; | |
151 | ||
35ebe7ec | 152 | its_pmsi_init_one(of_node_to_fwnode(np), np->full_name); |
1e6db000 | 153 | } |
35ebe7ec | 154 | } |
1e6db000 | 155 | |
35ebe7ec HG |
156 | static int __init its_pmsi_init(void) |
157 | { | |
158 | its_pmsi_of_init(); | |
79433a4e | 159 | its_pmsi_acpi_init(); |
1e6db000 MZ |
160 | return 0; |
161 | } | |
162 | early_initcall(its_pmsi_init); |