Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 1 | #include <linux/debugfs.h> |
| 2 | #include <linux/hardirq.h> |
| 3 | #include <linux/interrupt.h> |
Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 4 | #include <linux/irq.h> |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 5 | #include <linux/irqdesc.h> |
Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 6 | #include <linux/irqdomain.h> |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/mutex.h> |
| 9 | #include <linux/of.h> |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 10 | #include <linux/of_address.h> |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 11 | #include <linux/seq_file.h> |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 12 | #include <linux/slab.h> |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 13 | #include <linux/smp.h> |
| 14 | #include <linux/fs.h> |
Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 15 | |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame^] | 16 | #define IRQ_DOMAIN_MAP_LEGACY 0 /* driver allocated fixed range of irqs. |
| 17 | * ie. legacy 8259, gets irqs 1..15 */ |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 18 | #define IRQ_DOMAIN_MAP_NOMAP 1 /* no fast reverse mapping */ |
| 19 | #define IRQ_DOMAIN_MAP_LINEAR 2 /* linear map of interrupts */ |
| 20 | #define IRQ_DOMAIN_MAP_TREE 3 /* radix tree */ |
| 21 | |
Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 22 | static LIST_HEAD(irq_domain_list); |
| 23 | static DEFINE_MUTEX(irq_domain_mutex); |
| 24 | |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 25 | #ifdef CONFIG_PPC |
| 26 | static DEFINE_MUTEX(revmap_trees_mutex); |
| 27 | static unsigned int irq_virq_count = NR_IRQS; |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 28 | static struct irq_domain *irq_default_domain; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 29 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 30 | static int default_irq_domain_match(struct irq_domain *d, struct device_node *np) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 31 | { |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 32 | return d->of_node != NULL && d->of_node == np; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | /** |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 36 | * irq_domain_alloc() - Allocate a new irq_domain data structure |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 37 | * @of_node: optional device-tree node of the interrupt controller |
| 38 | * @revmap_type: type of reverse mapping to use |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 39 | * @ops: map/unmap domain callbacks |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 40 | * @host_data: Controller private data pointer |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 41 | * |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 42 | * Allocates and initialize and irq_domain structure. Caller is expected to |
| 43 | * register allocated irq_domain with irq_domain_register(). Returns pointer |
| 44 | * to IRQ domain, or NULL on failure. |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 45 | */ |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 46 | static struct irq_domain *irq_domain_alloc(struct device_node *of_node, |
| 47 | unsigned int revmap_type, |
| 48 | struct irq_domain_ops *ops, |
| 49 | void *host_data) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 50 | { |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 51 | struct irq_domain *domain; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 52 | |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 53 | domain = kzalloc(sizeof(*domain), GFP_KERNEL); |
| 54 | if (WARN_ON(!domain)) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 55 | return NULL; |
| 56 | |
| 57 | /* Fill structure */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 58 | domain->revmap_type = revmap_type; |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 59 | domain->ops = ops; |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 60 | domain->host_data = host_data; |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 61 | domain->of_node = of_node_get(of_node); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 62 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 63 | if (domain->ops->match == NULL) |
| 64 | domain->ops->match = default_irq_domain_match; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 65 | |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 66 | return domain; |
| 67 | } |
| 68 | |
| 69 | static void irq_domain_add(struct irq_domain *domain) |
| 70 | { |
| 71 | mutex_lock(&irq_domain_mutex); |
| 72 | list_add(&domain->link, &irq_domain_list); |
| 73 | mutex_unlock(&irq_domain_mutex); |
| 74 | pr_debug("irq: Allocated domain of type %d @0x%p\n", |
| 75 | domain->revmap_type, domain); |
| 76 | } |
| 77 | |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame^] | 78 | static unsigned int irq_domain_legacy_revmap(struct irq_domain *domain, |
| 79 | irq_hw_number_t hwirq) |
| 80 | { |
| 81 | irq_hw_number_t first_hwirq = domain->revmap_data.legacy.first_hwirq; |
| 82 | int size = domain->revmap_data.legacy.size; |
| 83 | |
| 84 | if (WARN_ON(hwirq < first_hwirq || hwirq >= first_hwirq + size)) |
| 85 | return 0; |
| 86 | return hwirq - first_hwirq + domain->revmap_data.legacy.first_irq; |
| 87 | } |
| 88 | |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 89 | /** |
| 90 | * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain. |
| 91 | * @of_node: pointer to interrupt controller's device tree node. |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame^] | 92 | * @size: total number of irqs in legacy mapping |
| 93 | * @first_irq: first number of irq block assigned to the domain |
| 94 | * @first_hwirq: first hwirq number to use for the translation. Should normally |
| 95 | * be '0', but a positive integer can be used if the effective |
| 96 | * hwirqs numbering does not begin at zero. |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 97 | * @ops: map/unmap domain callbacks |
| 98 | * @host_data: Controller private data pointer |
| 99 | * |
| 100 | * Note: the map() callback will be called before this function returns |
| 101 | * for all legacy interrupts except 0 (which is always the invalid irq for |
| 102 | * a legacy controller). |
| 103 | */ |
| 104 | struct irq_domain *irq_domain_add_legacy(struct device_node *of_node, |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame^] | 105 | unsigned int size, |
| 106 | unsigned int first_irq, |
| 107 | irq_hw_number_t first_hwirq, |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 108 | struct irq_domain_ops *ops, |
| 109 | void *host_data) |
| 110 | { |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame^] | 111 | struct irq_domain *domain; |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 112 | unsigned int i; |
| 113 | |
| 114 | domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LEGACY, ops, host_data); |
| 115 | if (!domain) |
| 116 | return NULL; |
| 117 | |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame^] | 118 | domain->revmap_data.legacy.first_irq = first_irq; |
| 119 | domain->revmap_data.legacy.first_hwirq = first_hwirq; |
| 120 | domain->revmap_data.legacy.size = size; |
| 121 | |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 122 | mutex_lock(&irq_domain_mutex); |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame^] | 123 | /* Verify that all the irqs are available */ |
| 124 | for (i = 0; i < size; i++) { |
| 125 | int irq = first_irq + i; |
| 126 | struct irq_data *irq_data = irq_get_irq_data(irq); |
| 127 | |
| 128 | if (WARN_ON(!irq_data || irq_data->domain)) { |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 129 | mutex_unlock(&irq_domain_mutex); |
| 130 | of_node_put(domain->of_node); |
| 131 | kfree(domain); |
| 132 | return NULL; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 133 | } |
| 134 | } |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame^] | 135 | |
| 136 | /* Claim all of the irqs before registering a legacy domain */ |
| 137 | for (i = 0; i < size; i++) { |
| 138 | struct irq_data *irq_data = irq_get_irq_data(first_irq + i); |
| 139 | irq_data->hwirq = first_hwirq + i; |
| 140 | irq_data->domain = domain; |
| 141 | } |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 142 | mutex_unlock(&irq_domain_mutex); |
| 143 | |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame^] | 144 | for (i = 0; i < size; i++) { |
| 145 | int irq = first_irq + i; |
| 146 | int hwirq = first_hwirq + i; |
| 147 | |
| 148 | /* IRQ0 gets ignored */ |
| 149 | if (!irq) |
| 150 | continue; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 151 | |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 152 | /* Legacy flags are left to default at this point, |
| 153 | * one can then use irq_create_mapping() to |
| 154 | * explicitly change them |
| 155 | */ |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame^] | 156 | ops->map(domain, irq, hwirq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 157 | |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 158 | /* Clear norequest flags */ |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame^] | 159 | irq_clear_status_flags(irq, IRQ_NOREQUEST); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 160 | } |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame^] | 161 | |
| 162 | irq_domain_add(domain); |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 163 | return domain; |
| 164 | } |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 165 | |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 166 | /** |
| 167 | * irq_domain_add_linear() - Allocate and register a legacy revmap irq_domain. |
| 168 | * @of_node: pointer to interrupt controller's device tree node. |
| 169 | * @ops: map/unmap domain callbacks |
| 170 | * @host_data: Controller private data pointer |
| 171 | */ |
| 172 | struct irq_domain *irq_domain_add_linear(struct device_node *of_node, |
| 173 | unsigned int size, |
| 174 | struct irq_domain_ops *ops, |
| 175 | void *host_data) |
| 176 | { |
| 177 | struct irq_domain *domain; |
| 178 | unsigned int *revmap; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 179 | |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 180 | revmap = kzalloc(sizeof(*revmap) * size, GFP_KERNEL); |
| 181 | if (WARN_ON(!revmap)) |
| 182 | return NULL; |
| 183 | |
| 184 | domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LINEAR, ops, host_data); |
| 185 | if (!domain) { |
| 186 | kfree(revmap); |
| 187 | return NULL; |
| 188 | } |
| 189 | domain->revmap_data.linear.size = size; |
| 190 | domain->revmap_data.linear.revmap = revmap; |
| 191 | irq_domain_add(domain); |
| 192 | return domain; |
| 193 | } |
| 194 | |
| 195 | struct irq_domain *irq_domain_add_nomap(struct device_node *of_node, |
| 196 | struct irq_domain_ops *ops, |
| 197 | void *host_data) |
| 198 | { |
| 199 | struct irq_domain *domain = irq_domain_alloc(of_node, |
| 200 | IRQ_DOMAIN_MAP_NOMAP, ops, host_data); |
| 201 | if (domain) |
| 202 | irq_domain_add(domain); |
| 203 | return domain; |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * irq_domain_add_tree() |
| 208 | * @of_node: pointer to interrupt controller's device tree node. |
| 209 | * @ops: map/unmap domain callbacks |
| 210 | * |
| 211 | * Note: The radix tree will be allocated later during boot automatically |
| 212 | * (the reverse mapping will use the slow path until that happens). |
| 213 | */ |
| 214 | struct irq_domain *irq_domain_add_tree(struct device_node *of_node, |
| 215 | struct irq_domain_ops *ops, |
| 216 | void *host_data) |
| 217 | { |
| 218 | struct irq_domain *domain = irq_domain_alloc(of_node, |
| 219 | IRQ_DOMAIN_MAP_TREE, ops, host_data); |
| 220 | if (domain) { |
| 221 | INIT_RADIX_TREE(&domain->revmap_data.tree, GFP_KERNEL); |
| 222 | irq_domain_add(domain); |
| 223 | } |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 224 | return domain; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /** |
| 228 | * irq_find_host() - Locates a domain for a given device node |
| 229 | * @node: device-tree node of the interrupt controller |
| 230 | */ |
| 231 | struct irq_domain *irq_find_host(struct device_node *node) |
| 232 | { |
| 233 | struct irq_domain *h, *found = NULL; |
| 234 | |
| 235 | /* We might want to match the legacy controller last since |
| 236 | * it might potentially be set to match all interrupts in |
| 237 | * the absence of a device node. This isn't a problem so far |
| 238 | * yet though... |
| 239 | */ |
| 240 | mutex_lock(&irq_domain_mutex); |
| 241 | list_for_each_entry(h, &irq_domain_list, link) |
| 242 | if (h->ops->match(h, node)) { |
| 243 | found = h; |
| 244 | break; |
| 245 | } |
| 246 | mutex_unlock(&irq_domain_mutex); |
| 247 | return found; |
| 248 | } |
| 249 | EXPORT_SYMBOL_GPL(irq_find_host); |
| 250 | |
| 251 | /** |
| 252 | * irq_set_default_host() - Set a "default" irq domain |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 253 | * @domain: default domain pointer |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 254 | * |
| 255 | * For convenience, it's possible to set a "default" domain that will be used |
| 256 | * whenever NULL is passed to irq_create_mapping(). It makes life easier for |
| 257 | * platforms that want to manipulate a few hard coded interrupt numbers that |
| 258 | * aren't properly represented in the device-tree. |
| 259 | */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 260 | void irq_set_default_host(struct irq_domain *domain) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 261 | { |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 262 | pr_debug("irq: Default domain set to @0x%p\n", domain); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 263 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 264 | irq_default_domain = domain; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /** |
| 268 | * irq_set_virq_count() - Set the maximum number of linux irqs |
| 269 | * @count: number of linux irqs, capped with NR_IRQS |
| 270 | * |
| 271 | * This is mainly for use by platforms like iSeries who want to program |
| 272 | * the virtual irq number in the controller to avoid the reverse mapping |
| 273 | */ |
| 274 | void irq_set_virq_count(unsigned int count) |
| 275 | { |
| 276 | pr_debug("irq: Trying to set virq count to %d\n", count); |
| 277 | |
| 278 | BUG_ON(count < NUM_ISA_INTERRUPTS); |
| 279 | if (count < NR_IRQS) |
| 280 | irq_virq_count = count; |
| 281 | } |
| 282 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 283 | static int irq_setup_virq(struct irq_domain *domain, unsigned int virq, |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 284 | irq_hw_number_t hwirq) |
| 285 | { |
| 286 | struct irq_data *irq_data = irq_get_irq_data(virq); |
| 287 | |
| 288 | irq_data->hwirq = hwirq; |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 289 | irq_data->domain = domain; |
| 290 | if (domain->ops->map(domain, virq, hwirq)) { |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 291 | pr_debug("irq: -> mapping failed, freeing\n"); |
| 292 | irq_data->domain = NULL; |
| 293 | irq_data->hwirq = 0; |
| 294 | return -1; |
| 295 | } |
| 296 | |
| 297 | irq_clear_status_flags(virq, IRQ_NOREQUEST); |
| 298 | |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * irq_create_direct_mapping() - Allocate an irq for direct mapping |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 304 | * @domain: domain to allocate the irq for or NULL for default domain |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 305 | * |
| 306 | * This routine is used for irq controllers which can choose the hardware |
| 307 | * interrupt numbers they generate. In such a case it's simplest to use |
| 308 | * the linux irq as the hardware interrupt number. |
| 309 | */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 310 | unsigned int irq_create_direct_mapping(struct irq_domain *domain) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 311 | { |
| 312 | unsigned int virq; |
| 313 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 314 | if (domain == NULL) |
| 315 | domain = irq_default_domain; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 316 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 317 | BUG_ON(domain == NULL); |
| 318 | WARN_ON(domain->revmap_type != IRQ_DOMAIN_MAP_NOMAP); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 319 | |
| 320 | virq = irq_alloc_desc_from(1, 0); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 321 | if (!virq) { |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 322 | pr_debug("irq: create_direct virq allocation failed\n"); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 323 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 324 | } |
| 325 | if (virq >= irq_virq_count) { |
| 326 | pr_err("ERROR: no free irqs available below %i maximum\n", |
| 327 | irq_virq_count); |
| 328 | irq_free_desc(virq); |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | pr_debug("irq: create_direct obtained virq %d\n", virq); |
| 333 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 334 | if (irq_setup_virq(domain, virq, virq)) { |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 335 | irq_free_desc(virq); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 336 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | return virq; |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * irq_create_mapping() - Map a hardware interrupt into linux irq space |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 344 | * @domain: domain owning this hardware interrupt or NULL for default domain |
| 345 | * @hwirq: hardware irq number in that domain space |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 346 | * |
| 347 | * Only one mapping per hardware interrupt is permitted. Returns a linux |
| 348 | * irq number. |
| 349 | * If the sense/trigger is to be specified, set_irq_type() should be called |
| 350 | * on the number returned from that call. |
| 351 | */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 352 | unsigned int irq_create_mapping(struct irq_domain *domain, |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 353 | irq_hw_number_t hwirq) |
| 354 | { |
| 355 | unsigned int virq, hint; |
| 356 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 357 | pr_debug("irq: irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 358 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 359 | /* Look for default domain if nececssary */ |
| 360 | if (domain == NULL) |
| 361 | domain = irq_default_domain; |
| 362 | if (domain == NULL) { |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 363 | printk(KERN_WARNING "irq_create_mapping called for" |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 364 | " NULL domain, hwirq=%lx\n", hwirq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 365 | WARN_ON(1); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 366 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 367 | } |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 368 | pr_debug("irq: -> using domain @%p\n", domain); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 369 | |
| 370 | /* Check if mapping already exists */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 371 | virq = irq_find_mapping(domain, hwirq); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 372 | if (virq) { |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 373 | pr_debug("irq: -> existing mapping on virq %d\n", virq); |
| 374 | return virq; |
| 375 | } |
| 376 | |
| 377 | /* Get a virtual interrupt number */ |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame^] | 378 | if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY) |
| 379 | return irq_domain_legacy_revmap(domain, hwirq); |
| 380 | |
| 381 | /* Allocate a virtual interrupt number */ |
| 382 | hint = hwirq % irq_virq_count; |
| 383 | if (hint == 0) |
| 384 | hint++; |
| 385 | virq = irq_alloc_desc_from(hint, 0); |
| 386 | if (!virq) |
| 387 | virq = irq_alloc_desc_from(1, 0); |
| 388 | if (!virq) { |
| 389 | pr_debug("irq: -> virq allocation failed\n"); |
| 390 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 393 | if (irq_setup_virq(domain, virq, hwirq)) { |
| 394 | if (domain->revmap_type != IRQ_DOMAIN_MAP_LEGACY) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 395 | irq_free_desc(virq); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 396 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 399 | pr_debug("irq: irq %lu on domain %s mapped to virtual irq %u\n", |
| 400 | hwirq, domain->of_node ? domain->of_node->full_name : "null", virq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 401 | |
| 402 | return virq; |
| 403 | } |
| 404 | EXPORT_SYMBOL_GPL(irq_create_mapping); |
| 405 | |
| 406 | unsigned int irq_create_of_mapping(struct device_node *controller, |
| 407 | const u32 *intspec, unsigned int intsize) |
| 408 | { |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 409 | struct irq_domain *domain; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 410 | irq_hw_number_t hwirq; |
| 411 | unsigned int type = IRQ_TYPE_NONE; |
| 412 | unsigned int virq; |
| 413 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 414 | domain = controller ? irq_find_host(controller) : irq_default_domain; |
| 415 | if (!domain) { |
| 416 | printk(KERN_WARNING "irq: no irq domain found for %s !\n", |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 417 | controller->full_name); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 418 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 419 | } |
| 420 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 421 | /* If domain has no translation, then we assume interrupt line */ |
| 422 | if (domain->ops->xlate == NULL) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 423 | hwirq = intspec[0]; |
| 424 | else { |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 425 | if (domain->ops->xlate(domain, controller, intspec, intsize, |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 426 | &hwirq, &type)) |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 427 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | /* Create mapping */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 431 | virq = irq_create_mapping(domain, hwirq); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 432 | if (!virq) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 433 | return virq; |
| 434 | |
| 435 | /* Set type if specified and different than the current one */ |
| 436 | if (type != IRQ_TYPE_NONE && |
| 437 | type != (irqd_get_trigger_type(irq_get_irq_data(virq)))) |
| 438 | irq_set_irq_type(virq, type); |
| 439 | return virq; |
| 440 | } |
| 441 | EXPORT_SYMBOL_GPL(irq_create_of_mapping); |
| 442 | |
| 443 | /** |
| 444 | * irq_dispose_mapping() - Unmap an interrupt |
| 445 | * @virq: linux irq number of the interrupt to unmap |
| 446 | */ |
| 447 | void irq_dispose_mapping(unsigned int virq) |
| 448 | { |
| 449 | struct irq_data *irq_data = irq_get_irq_data(virq); |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 450 | struct irq_domain *domain; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 451 | irq_hw_number_t hwirq; |
| 452 | |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 453 | if (!virq || !irq_data) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 454 | return; |
| 455 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 456 | domain = irq_data->domain; |
| 457 | if (WARN_ON(domain == NULL)) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 458 | return; |
| 459 | |
| 460 | /* Never unmap legacy interrupts */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 461 | if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 462 | return; |
| 463 | |
| 464 | irq_set_status_flags(virq, IRQ_NOREQUEST); |
| 465 | |
| 466 | /* remove chip and handler */ |
| 467 | irq_set_chip_and_handler(virq, NULL, NULL); |
| 468 | |
| 469 | /* Make sure it's completed */ |
| 470 | synchronize_irq(virq); |
| 471 | |
| 472 | /* Tell the PIC about it */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 473 | if (domain->ops->unmap) |
| 474 | domain->ops->unmap(domain, virq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 475 | smp_mb(); |
| 476 | |
| 477 | /* Clear reverse map */ |
| 478 | hwirq = irq_data->hwirq; |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 479 | switch(domain->revmap_type) { |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 480 | case IRQ_DOMAIN_MAP_LINEAR: |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 481 | if (hwirq < domain->revmap_data.linear.size) |
| 482 | domain->revmap_data.linear.revmap[hwirq] = 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 483 | break; |
| 484 | case IRQ_DOMAIN_MAP_TREE: |
| 485 | mutex_lock(&revmap_trees_mutex); |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 486 | radix_tree_delete(&domain->revmap_data.tree, hwirq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 487 | mutex_unlock(&revmap_trees_mutex); |
| 488 | break; |
| 489 | } |
| 490 | |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 491 | irq_free_desc(virq); |
| 492 | } |
| 493 | EXPORT_SYMBOL_GPL(irq_dispose_mapping); |
| 494 | |
| 495 | /** |
| 496 | * irq_find_mapping() - Find a linux irq from an hw irq number. |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 497 | * @domain: domain owning this hardware interrupt |
| 498 | * @hwirq: hardware irq number in that domain space |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 499 | * |
| 500 | * This is a slow path, for use by generic code. It's expected that an |
| 501 | * irq controller implementation directly calls the appropriate low level |
| 502 | * mapping function. |
| 503 | */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 504 | unsigned int irq_find_mapping(struct irq_domain *domain, |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 505 | irq_hw_number_t hwirq) |
| 506 | { |
| 507 | unsigned int i; |
| 508 | unsigned int hint = hwirq % irq_virq_count; |
| 509 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 510 | /* Look for default domain if nececssary */ |
| 511 | if (domain == NULL) |
| 512 | domain = irq_default_domain; |
| 513 | if (domain == NULL) |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 514 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 515 | |
| 516 | /* legacy -> bail early */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 517 | if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY) |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame^] | 518 | return irq_domain_legacy_revmap(domain, hwirq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 519 | |
| 520 | /* Slow path does a linear search of the map */ |
| 521 | if (hint == 0) |
| 522 | hint = 1; |
| 523 | i = hint; |
| 524 | do { |
| 525 | struct irq_data *data = irq_get_irq_data(i); |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 526 | if (data && (data->domain == domain) && (data->hwirq == hwirq)) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 527 | return i; |
| 528 | i++; |
| 529 | if (i >= irq_virq_count) |
| 530 | i = 1; |
| 531 | } while(i != hint); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 532 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 533 | } |
| 534 | EXPORT_SYMBOL_GPL(irq_find_mapping); |
| 535 | |
| 536 | /** |
| 537 | * irq_radix_revmap_lookup() - Find a linux irq from a hw irq number. |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 538 | * @domain: domain owning this hardware interrupt |
| 539 | * @hwirq: hardware irq number in that domain space |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 540 | * |
| 541 | * This is a fast path, for use by irq controller code that uses radix tree |
| 542 | * revmaps |
| 543 | */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 544 | unsigned int irq_radix_revmap_lookup(struct irq_domain *domain, |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 545 | irq_hw_number_t hwirq) |
| 546 | { |
| 547 | struct irq_data *irq_data; |
| 548 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 549 | if (WARN_ON_ONCE(domain->revmap_type != IRQ_DOMAIN_MAP_TREE)) |
| 550 | return irq_find_mapping(domain, hwirq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 551 | |
| 552 | /* |
| 553 | * Freeing an irq can delete nodes along the path to |
| 554 | * do the lookup via call_rcu. |
| 555 | */ |
| 556 | rcu_read_lock(); |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 557 | irq_data = radix_tree_lookup(&domain->revmap_data.tree, hwirq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 558 | rcu_read_unlock(); |
| 559 | |
| 560 | /* |
| 561 | * If found in radix tree, then fine. |
| 562 | * Else fallback to linear lookup - this should not happen in practice |
| 563 | * as it means that we failed to insert the node in the radix tree. |
| 564 | */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 565 | return irq_data ? irq_data->irq : irq_find_mapping(domain, hwirq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | /** |
| 569 | * irq_radix_revmap_insert() - Insert a hw irq to linux irq number mapping. |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 570 | * @domain: domain owning this hardware interrupt |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 571 | * @virq: linux irq number |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 572 | * @hwirq: hardware irq number in that domain space |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 573 | * |
| 574 | * This is for use by irq controllers that use a radix tree reverse |
| 575 | * mapping for fast lookup. |
| 576 | */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 577 | void irq_radix_revmap_insert(struct irq_domain *domain, unsigned int virq, |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 578 | irq_hw_number_t hwirq) |
| 579 | { |
| 580 | struct irq_data *irq_data = irq_get_irq_data(virq); |
| 581 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 582 | if (WARN_ON(domain->revmap_type != IRQ_DOMAIN_MAP_TREE)) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 583 | return; |
| 584 | |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 585 | if (virq) { |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 586 | mutex_lock(&revmap_trees_mutex); |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 587 | radix_tree_insert(&domain->revmap_data.tree, hwirq, irq_data); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 588 | mutex_unlock(&revmap_trees_mutex); |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | /** |
| 593 | * irq_linear_revmap() - Find a linux irq from a hw irq number. |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 594 | * @domain: domain owning this hardware interrupt |
| 595 | * @hwirq: hardware irq number in that domain space |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 596 | * |
| 597 | * This is a fast path, for use by irq controller code that uses linear |
| 598 | * revmaps. It does fallback to the slow path if the revmap doesn't exist |
| 599 | * yet and will create the revmap entry with appropriate locking |
| 600 | */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 601 | unsigned int irq_linear_revmap(struct irq_domain *domain, |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 602 | irq_hw_number_t hwirq) |
| 603 | { |
| 604 | unsigned int *revmap; |
| 605 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 606 | if (WARN_ON_ONCE(domain->revmap_type != IRQ_DOMAIN_MAP_LINEAR)) |
| 607 | return irq_find_mapping(domain, hwirq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 608 | |
| 609 | /* Check revmap bounds */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 610 | if (unlikely(hwirq >= domain->revmap_data.linear.size)) |
| 611 | return irq_find_mapping(domain, hwirq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 612 | |
| 613 | /* Check if revmap was allocated */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 614 | revmap = domain->revmap_data.linear.revmap; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 615 | if (unlikely(revmap == NULL)) |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 616 | return irq_find_mapping(domain, hwirq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 617 | |
| 618 | /* Fill up revmap with slow path if no mapping found */ |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 619 | if (unlikely(!revmap[hwirq])) |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 620 | revmap[hwirq] = irq_find_mapping(domain, hwirq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 621 | |
| 622 | return revmap[hwirq]; |
| 623 | } |
| 624 | |
| 625 | #ifdef CONFIG_VIRQ_DEBUG |
| 626 | static int virq_debug_show(struct seq_file *m, void *private) |
| 627 | { |
| 628 | unsigned long flags; |
| 629 | struct irq_desc *desc; |
| 630 | const char *p; |
| 631 | static const char none[] = "none"; |
| 632 | void *data; |
| 633 | int i; |
| 634 | |
| 635 | seq_printf(m, "%-5s %-7s %-15s %-18s %s\n", "virq", "hwirq", |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 636 | "chip name", "chip data", "domain name"); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 637 | |
| 638 | for (i = 1; i < nr_irqs; i++) { |
| 639 | desc = irq_to_desc(i); |
| 640 | if (!desc) |
| 641 | continue; |
| 642 | |
| 643 | raw_spin_lock_irqsave(&desc->lock, flags); |
| 644 | |
| 645 | if (desc->action && desc->action->handler) { |
| 646 | struct irq_chip *chip; |
| 647 | |
| 648 | seq_printf(m, "%5d ", i); |
| 649 | seq_printf(m, "0x%05lx ", desc->irq_data.hwirq); |
| 650 | |
| 651 | chip = irq_desc_get_chip(desc); |
| 652 | if (chip && chip->name) |
| 653 | p = chip->name; |
| 654 | else |
| 655 | p = none; |
| 656 | seq_printf(m, "%-15s ", p); |
| 657 | |
| 658 | data = irq_desc_get_chip_data(desc); |
| 659 | seq_printf(m, "0x%16p ", data); |
| 660 | |
| 661 | if (desc->irq_data.domain->of_node) |
| 662 | p = desc->irq_data.domain->of_node->full_name; |
| 663 | else |
| 664 | p = none; |
| 665 | seq_printf(m, "%s\n", p); |
| 666 | } |
| 667 | |
| 668 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
| 669 | } |
| 670 | |
| 671 | return 0; |
| 672 | } |
| 673 | |
| 674 | static int virq_debug_open(struct inode *inode, struct file *file) |
| 675 | { |
| 676 | return single_open(file, virq_debug_show, inode->i_private); |
| 677 | } |
| 678 | |
| 679 | static const struct file_operations virq_debug_fops = { |
| 680 | .open = virq_debug_open, |
| 681 | .read = seq_read, |
| 682 | .llseek = seq_lseek, |
| 683 | .release = single_release, |
| 684 | }; |
| 685 | |
| 686 | static int __init irq_debugfs_init(void) |
| 687 | { |
| 688 | if (debugfs_create_file("virq_mapping", S_IRUGO, powerpc_debugfs_root, |
| 689 | NULL, &virq_debug_fops) == NULL) |
| 690 | return -ENOMEM; |
| 691 | |
| 692 | return 0; |
| 693 | } |
| 694 | __initcall(irq_debugfs_init); |
| 695 | #endif /* CONFIG_VIRQ_DEBUG */ |
| 696 | |
| 697 | #else /* CONFIG_PPC */ |
| 698 | |
Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 699 | /** |
| 700 | * irq_domain_add() - Register an irq_domain |
| 701 | * @domain: ptr to initialized irq_domain structure |
| 702 | * |
| 703 | * Registers an irq_domain structure. The irq_domain must at a minimum be |
| 704 | * initialized with an ops structure pointer, and either a ->to_irq hook or |
| 705 | * a valid irq_base value. Everything else is optional. |
| 706 | */ |
| 707 | void irq_domain_add(struct irq_domain *domain) |
| 708 | { |
| 709 | struct irq_data *d; |
Rob Herring | 6d27430 | 2011-09-30 10:48:38 -0500 | [diff] [blame] | 710 | int hwirq, irq; |
Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 711 | |
| 712 | /* |
| 713 | * This assumes that the irq_domain owner has already allocated |
| 714 | * the irq_descs. This block will be removed when support for dynamic |
| 715 | * allocation of irq_descs is added to irq_domain. |
| 716 | */ |
Rob Herring | 6d27430 | 2011-09-30 10:48:38 -0500 | [diff] [blame] | 717 | irq_domain_for_each_irq(domain, hwirq, irq) { |
| 718 | d = irq_get_irq_data(irq); |
Rob Herring | eef24af | 2011-09-14 11:31:37 -0500 | [diff] [blame] | 719 | if (!d) { |
| 720 | WARN(1, "error: assigning domain to non existant irq_desc"); |
| 721 | return; |
| 722 | } |
| 723 | if (d->domain) { |
Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 724 | /* things are broken; just report, don't clean up */ |
| 725 | WARN(1, "error: irq_desc already assigned to a domain"); |
| 726 | return; |
| 727 | } |
| 728 | d->domain = domain; |
| 729 | d->hwirq = hwirq; |
| 730 | } |
| 731 | |
| 732 | mutex_lock(&irq_domain_mutex); |
Grant Likely | 7bb69ba | 2012-02-14 14:06:48 -0700 | [diff] [blame] | 733 | list_add(&domain->link, &irq_domain_list); |
Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 734 | mutex_unlock(&irq_domain_mutex); |
| 735 | } |
| 736 | |
| 737 | /** |
| 738 | * irq_domain_del() - Unregister an irq_domain |
| 739 | * @domain: ptr to registered irq_domain. |
| 740 | */ |
| 741 | void irq_domain_del(struct irq_domain *domain) |
| 742 | { |
| 743 | struct irq_data *d; |
Rob Herring | 6d27430 | 2011-09-30 10:48:38 -0500 | [diff] [blame] | 744 | int hwirq, irq; |
Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 745 | |
| 746 | mutex_lock(&irq_domain_mutex); |
Grant Likely | 7bb69ba | 2012-02-14 14:06:48 -0700 | [diff] [blame] | 747 | list_del(&domain->link); |
Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 748 | mutex_unlock(&irq_domain_mutex); |
| 749 | |
| 750 | /* Clear the irq_domain assignments */ |
Rob Herring | 6d27430 | 2011-09-30 10:48:38 -0500 | [diff] [blame] | 751 | irq_domain_for_each_irq(domain, hwirq, irq) { |
| 752 | d = irq_get_irq_data(irq); |
Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 753 | d->domain = NULL; |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | #if defined(CONFIG_OF_IRQ) |
| 758 | /** |
| 759 | * irq_create_of_mapping() - Map a linux irq number from a DT interrupt spec |
| 760 | * |
| 761 | * Used by the device tree interrupt mapping code to translate a device tree |
| 762 | * interrupt specifier to a valid linux irq number. Returns either a valid |
| 763 | * linux IRQ number or 0. |
| 764 | * |
| 765 | * When the caller no longer need the irq number returned by this function it |
| 766 | * should arrange to call irq_dispose_mapping(). |
| 767 | */ |
| 768 | unsigned int irq_create_of_mapping(struct device_node *controller, |
| 769 | const u32 *intspec, unsigned int intsize) |
| 770 | { |
| 771 | struct irq_domain *domain; |
| 772 | unsigned long hwirq; |
| 773 | unsigned int irq, type; |
| 774 | int rc = -EINVAL; |
| 775 | |
| 776 | /* Find a domain which can translate the irq spec */ |
| 777 | mutex_lock(&irq_domain_mutex); |
Grant Likely | 7bb69ba | 2012-02-14 14:06:48 -0700 | [diff] [blame] | 778 | list_for_each_entry(domain, &irq_domain_list, link) { |
| 779 | if (!domain->ops->xlate) |
Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 780 | continue; |
Grant Likely | 7bb69ba | 2012-02-14 14:06:48 -0700 | [diff] [blame] | 781 | rc = domain->ops->xlate(domain, controller, |
Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 782 | intspec, intsize, &hwirq, &type); |
| 783 | if (rc == 0) |
| 784 | break; |
| 785 | } |
| 786 | mutex_unlock(&irq_domain_mutex); |
| 787 | |
| 788 | if (rc != 0) |
| 789 | return 0; |
| 790 | |
| 791 | irq = irq_domain_to_irq(domain, hwirq); |
| 792 | if (type != IRQ_TYPE_NONE) |
| 793 | irq_set_irq_type(irq, type); |
| 794 | pr_debug("%s: mapped hwirq=%i to irq=%i, flags=%x\n", |
| 795 | controller->full_name, (int)hwirq, irq, type); |
| 796 | return irq; |
| 797 | } |
| 798 | EXPORT_SYMBOL_GPL(irq_create_of_mapping); |
| 799 | |
| 800 | /** |
| 801 | * irq_dispose_mapping() - Discard a mapping created by irq_create_of_mapping() |
| 802 | * @irq: linux irq number to be discarded |
| 803 | * |
| 804 | * Calling this function indicates the caller no longer needs a reference to |
| 805 | * the linux irq number returned by a prior call to irq_create_of_mapping(). |
| 806 | */ |
| 807 | void irq_dispose_mapping(unsigned int irq) |
| 808 | { |
| 809 | /* |
| 810 | * nothing yet; will be filled when support for dynamic allocation of |
| 811 | * irq_descs is added to irq_domain |
| 812 | */ |
| 813 | } |
| 814 | EXPORT_SYMBOL_GPL(irq_dispose_mapping); |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 815 | |
Grant Likely | 7bb69ba | 2012-02-14 14:06:48 -0700 | [diff] [blame] | 816 | int irq_domain_simple_xlate(struct irq_domain *d, |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 817 | struct device_node *controller, |
| 818 | const u32 *intspec, unsigned int intsize, |
| 819 | unsigned long *out_hwirq, unsigned int *out_type) |
| 820 | { |
| 821 | if (d->of_node != controller) |
| 822 | return -EINVAL; |
| 823 | if (intsize < 1) |
| 824 | return -EINVAL; |
Rob Herring | 93797d8 | 2011-12-12 09:59:14 -0600 | [diff] [blame] | 825 | if (d->nr_irq && ((intspec[0] < d->hwirq_base) || |
| 826 | (intspec[0] >= d->hwirq_base + d->nr_irq))) |
| 827 | return -EINVAL; |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 828 | |
| 829 | *out_hwirq = intspec[0]; |
| 830 | *out_type = IRQ_TYPE_NONE; |
| 831 | if (intsize > 1) |
| 832 | *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK; |
| 833 | return 0; |
| 834 | } |
| 835 | |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 836 | /** |
| 837 | * irq_domain_create_simple() - Set up a 'simple' translation range |
| 838 | */ |
| 839 | void irq_domain_add_simple(struct device_node *controller, int irq_base) |
| 840 | { |
| 841 | struct irq_domain *domain; |
| 842 | |
| 843 | domain = kzalloc(sizeof(*domain), GFP_KERNEL); |
| 844 | if (!domain) { |
| 845 | WARN_ON(1); |
| 846 | return; |
| 847 | } |
| 848 | |
| 849 | domain->irq_base = irq_base; |
| 850 | domain->of_node = of_node_get(controller); |
| 851 | domain->ops = &irq_domain_simple_ops; |
| 852 | irq_domain_add(domain); |
| 853 | } |
| 854 | EXPORT_SYMBOL_GPL(irq_domain_add_simple); |
| 855 | |
| 856 | void irq_domain_generate_simple(const struct of_device_id *match, |
| 857 | u64 phys_base, unsigned int irq_start) |
| 858 | { |
| 859 | struct device_node *node; |
Grant Likely | e1964c5 | 2012-02-14 14:06:48 -0700 | [diff] [blame] | 860 | pr_debug("looking for phys_base=%llx, irq_start=%i\n", |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 861 | (unsigned long long) phys_base, (int) irq_start); |
| 862 | node = of_find_matching_node_by_address(NULL, match, phys_base); |
| 863 | if (node) |
| 864 | irq_domain_add_simple(node, irq_start); |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 865 | } |
| 866 | EXPORT_SYMBOL_GPL(irq_domain_generate_simple); |
Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 867 | #endif /* CONFIG_OF_IRQ */ |
Jamie Iles | c87fb57 | 2011-12-14 23:43:16 +0100 | [diff] [blame] | 868 | |
| 869 | struct irq_domain_ops irq_domain_simple_ops = { |
| 870 | #ifdef CONFIG_OF_IRQ |
Grant Likely | 7bb69ba | 2012-02-14 14:06:48 -0700 | [diff] [blame] | 871 | .xlate = irq_domain_simple_xlate, |
Jamie Iles | c87fb57 | 2011-12-14 23:43:16 +0100 | [diff] [blame] | 872 | #endif /* CONFIG_OF_IRQ */ |
| 873 | }; |
| 874 | EXPORT_SYMBOL_GPL(irq_domain_simple_ops); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 875 | |
| 876 | #endif /* !CONFIG_PPC */ |