| 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * irq_domain - IRQ Translation Domains |
| 4 | * |
| 5 | * See Documentation/core-api/irq/irq-domain.rst for the details. |
| 6 | */ |
| 7 | |
| 8 | #ifndef _LINUX_IRQDOMAIN_H |
| 9 | #define _LINUX_IRQDOMAIN_H |
| 10 | |
| 11 | #include <linux/types.h> |
| 12 | #include <linux/irqdomain_defs.h> |
| 13 | #include <linux/irqhandler.h> |
| 14 | #include <linux/of.h> |
| 15 | #include <linux/mutex.h> |
| 16 | #include <linux/radix-tree.h> |
| 17 | |
| 18 | struct device_node; |
| 19 | struct fwnode_handle; |
| 20 | struct irq_domain; |
| 21 | struct irq_chip; |
| 22 | struct irq_data; |
| 23 | struct irq_desc; |
| 24 | struct cpumask; |
| 25 | struct seq_file; |
| 26 | struct irq_affinity_desc; |
| 27 | struct msi_parent_ops; |
| 28 | |
| 29 | #define IRQ_DOMAIN_IRQ_SPEC_PARAMS 16 |
| 30 | |
| 31 | /** |
| 32 | * struct irq_fwspec - generic IRQ specifier structure |
| 33 | * |
| 34 | * @fwnode: Pointer to a firmware-specific descriptor |
| 35 | * @param_count: Number of device-specific parameters |
| 36 | * @param: Device-specific parameters |
| 37 | * |
| 38 | * This structure, directly modeled after of_phandle_args, is used to |
| 39 | * pass a device-specific description of an interrupt. |
| 40 | */ |
| 41 | struct irq_fwspec { |
| 42 | struct fwnode_handle *fwnode; |
| 43 | int param_count; |
| 44 | u32 param[IRQ_DOMAIN_IRQ_SPEC_PARAMS]; |
| 45 | }; |
| 46 | |
| 47 | /* Conversion function from of_phandle_args fields to fwspec */ |
| 48 | void of_phandle_args_to_fwspec(struct device_node *np, const u32 *args, |
| 49 | unsigned int count, struct irq_fwspec *fwspec); |
| 50 | |
| 51 | /** |
| 52 | * struct irq_domain_ops - Methods for irq_domain objects |
| 53 | * @match: Match an interrupt controller device node to a domain, returns |
| 54 | * 1 on a match |
| 55 | * @select: Match an interrupt controller fw specification. It is more generic |
| 56 | * than @match as it receives a complete struct irq_fwspec. Therefore, |
| 57 | * @select is preferred if provided. Returns 1 on a match. |
| 58 | * @map: Create or update a mapping between a virtual irq number and a hw |
| 59 | * irq number. This is called only once for a given mapping. |
| 60 | * @unmap: Dispose of such a mapping |
| 61 | * @xlate: Given a device tree node and interrupt specifier, decode |
| 62 | * the hardware irq number and linux irq type value. |
| 63 | * @alloc: Allocate @nr_irqs interrupts starting from @virq. |
| 64 | * @free: Free @nr_irqs interrupts starting from @virq. |
| 65 | * @activate: Activate one interrupt in HW (@irqd). If @reserve is set, only |
| 66 | * reserve the vector. If unset, assign the vector (called from |
| 67 | * request_irq()). |
| 68 | * @deactivate: Disarm one interrupt (@irqd). |
| 69 | * @translate: Given @fwspec, decode the hardware irq number (@out_hwirq) and |
| 70 | * linux irq type value (@out_type). This is a generalised @xlate |
| 71 | * (over struct irq_fwspec) and is preferred if provided. |
| 72 | * @debug_show: For domains to show specific data for an interrupt in debugfs. |
| 73 | * |
| 74 | * Functions below are provided by the driver and called whenever a new mapping |
| 75 | * is created or an old mapping is disposed. The driver can then proceed to |
| 76 | * whatever internal data structures management is required. It also needs |
| 77 | * to setup the irq_desc when returning from map(). |
| 78 | */ |
| 79 | struct irq_domain_ops { |
| 80 | int (*match)(struct irq_domain *d, struct device_node *node, |
| 81 | enum irq_domain_bus_token bus_token); |
| 82 | int (*select)(struct irq_domain *d, struct irq_fwspec *fwspec, |
| 83 | enum irq_domain_bus_token bus_token); |
| 84 | int (*map)(struct irq_domain *d, unsigned int virq, irq_hw_number_t hw); |
| 85 | void (*unmap)(struct irq_domain *d, unsigned int virq); |
| 86 | int (*xlate)(struct irq_domain *d, struct device_node *node, |
| 87 | const u32 *intspec, unsigned int intsize, |
| 88 | unsigned long *out_hwirq, unsigned int *out_type); |
| 89 | #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY |
| 90 | /* extended V2 interfaces to support hierarchy irq_domains */ |
| 91 | int (*alloc)(struct irq_domain *d, unsigned int virq, |
| 92 | unsigned int nr_irqs, void *arg); |
| 93 | void (*free)(struct irq_domain *d, unsigned int virq, |
| 94 | unsigned int nr_irqs); |
| 95 | int (*activate)(struct irq_domain *d, struct irq_data *irqd, bool reserve); |
| 96 | void (*deactivate)(struct irq_domain *d, struct irq_data *irq_data); |
| 97 | int (*translate)(struct irq_domain *d, struct irq_fwspec *fwspec, |
| 98 | unsigned long *out_hwirq, unsigned int *out_type); |
| 99 | #endif |
| 100 | #ifdef CONFIG_GENERIC_IRQ_DEBUGFS |
| 101 | void (*debug_show)(struct seq_file *m, struct irq_domain *d, |
| 102 | struct irq_data *irqd, int ind); |
| 103 | #endif |
| 104 | }; |
| 105 | |
| 106 | extern const struct irq_domain_ops irq_generic_chip_ops; |
| 107 | |
| 108 | struct irq_domain_chip_generic; |
| 109 | |
| 110 | /** |
| 111 | * struct irq_domain - Hardware interrupt number translation object |
| 112 | * @link: Element in global irq_domain list. |
| 113 | * @name: Name of interrupt domain |
| 114 | * @ops: Pointer to irq_domain methods |
| 115 | * @host_data: Private data pointer for use by owner. Not touched by irq_domain |
| 116 | * core code. |
| 117 | * @flags: Per irq_domain flags |
| 118 | * @mapcount: The number of mapped interrupts |
| 119 | * @mutex: Domain lock, hierarchical domains use root domain's lock |
| 120 | * @root: Pointer to root domain, or containing structure if non-hierarchical |
| 121 | * |
| 122 | * Optional elements: |
| 123 | * @fwnode: Pointer to firmware node associated with the irq_domain. Pretty easy |
| 124 | * to swap it for the of_node via the irq_domain_get_of_node accessor |
| 125 | * @bus_token: @fwnode's device_node might be used for several irq domains. But |
| 126 | * in connection with @bus_token, the pair shall be unique in a |
| 127 | * system. |
| 128 | * @gc: Pointer to a list of generic chips. There is a helper function for |
| 129 | * setting up one or more generic chips for interrupt controllers |
| 130 | * drivers using the generic chip library which uses this pointer. |
| 131 | * @dev: Pointer to the device which instantiated the irqdomain |
| 132 | * With per device irq domains this is not necessarily the same |
| 133 | * as @pm_dev. |
| 134 | * @pm_dev: Pointer to a device that can be utilized for power management |
| 135 | * purposes related to the irq domain. |
| 136 | * @parent: Pointer to parent irq_domain to support hierarchy irq_domains |
| 137 | * @msi_parent_ops: Pointer to MSI parent domain methods for per device domain init |
| 138 | * @exit: Function called when the domain is destroyed |
| 139 | * |
| 140 | * Revmap data, used internally by the irq domain code: |
| 141 | * @hwirq_max: Top limit for the HW irq number. Especially to avoid |
| 142 | * conflicts/failures with reserved HW irqs. Can be ~0. |
| 143 | * @revmap_size: Size of the linear map table @revmap |
| 144 | * @revmap_tree: Radix map tree for hwirqs that don't fit in the linear map |
| 145 | * @revmap: Linear table of irq_data pointers |
| 146 | */ |
| 147 | struct irq_domain { |
| 148 | struct list_head link; |
| 149 | const char *name; |
| 150 | const struct irq_domain_ops *ops; |
| 151 | void *host_data; |
| 152 | unsigned int flags; |
| 153 | unsigned int mapcount; |
| 154 | struct mutex mutex; |
| 155 | struct irq_domain *root; |
| 156 | |
| 157 | /* Optional data */ |
| 158 | struct fwnode_handle *fwnode; |
| 159 | enum irq_domain_bus_token bus_token; |
| 160 | struct irq_domain_chip_generic *gc; |
| 161 | struct device *dev; |
| 162 | struct device *pm_dev; |
| 163 | #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY |
| 164 | struct irq_domain *parent; |
| 165 | #endif |
| 166 | #ifdef CONFIG_GENERIC_MSI_IRQ |
| 167 | const struct msi_parent_ops *msi_parent_ops; |
| 168 | #endif |
| 169 | void (*exit)(struct irq_domain *d); |
| 170 | |
| 171 | /* reverse map data. The linear map gets appended to the irq_domain */ |
| 172 | irq_hw_number_t hwirq_max; |
| 173 | unsigned int revmap_size; |
| 174 | struct radix_tree_root revmap_tree; |
| 175 | struct irq_data __rcu *revmap[] __counted_by(revmap_size); |
| 176 | }; |
| 177 | |
| 178 | /* Irq domain flags */ |
| 179 | enum { |
| 180 | /* Irq domain is hierarchical */ |
| 181 | IRQ_DOMAIN_FLAG_HIERARCHY = (1 << 0), |
| 182 | |
| 183 | /* Irq domain name was allocated internally */ |
| 184 | IRQ_DOMAIN_NAME_ALLOCATED = (1 << 1), |
| 185 | |
| 186 | /* Irq domain is an IPI domain with virq per cpu */ |
| 187 | IRQ_DOMAIN_FLAG_IPI_PER_CPU = (1 << 2), |
| 188 | |
| 189 | /* Irq domain is an IPI domain with single virq */ |
| 190 | IRQ_DOMAIN_FLAG_IPI_SINGLE = (1 << 3), |
| 191 | |
| 192 | /* Irq domain implements MSIs */ |
| 193 | IRQ_DOMAIN_FLAG_MSI = (1 << 4), |
| 194 | |
| 195 | /* |
| 196 | * Irq domain implements isolated MSI, see msi_device_has_isolated_msi() |
| 197 | */ |
| 198 | IRQ_DOMAIN_FLAG_ISOLATED_MSI = (1 << 5), |
| 199 | |
| 200 | /* Irq domain doesn't translate anything */ |
| 201 | IRQ_DOMAIN_FLAG_NO_MAP = (1 << 6), |
| 202 | |
| 203 | /* Irq domain is a MSI parent domain */ |
| 204 | IRQ_DOMAIN_FLAG_MSI_PARENT = (1 << 8), |
| 205 | |
| 206 | /* Irq domain is a MSI device domain */ |
| 207 | IRQ_DOMAIN_FLAG_MSI_DEVICE = (1 << 9), |
| 208 | |
| 209 | /* Irq domain must destroy generic chips when removed */ |
| 210 | IRQ_DOMAIN_FLAG_DESTROY_GC = (1 << 10), |
| 211 | |
| 212 | /* Address and data pair is mutable when irq_set_affinity() */ |
| 213 | IRQ_DOMAIN_FLAG_MSI_IMMUTABLE = (1 << 11), |
| 214 | |
| 215 | /* |
| 216 | * Flags starting from IRQ_DOMAIN_FLAG_NONCORE are reserved |
| 217 | * for implementation specific purposes and ignored by the |
| 218 | * core code. |
| 219 | */ |
| 220 | IRQ_DOMAIN_FLAG_NONCORE = (1 << 16), |
| 221 | }; |
| 222 | |
| 223 | static inline struct device_node *irq_domain_get_of_node(struct irq_domain *d) |
| 224 | { |
| 225 | return to_of_node(d->fwnode); |
| 226 | } |
| 227 | |
| 228 | static inline void irq_domain_set_pm_device(struct irq_domain *d, struct device *dev) |
| 229 | { |
| 230 | if (d) |
| 231 | d->pm_dev = dev; |
| 232 | } |
| 233 | |
| 234 | #ifdef CONFIG_IRQ_DOMAIN |
| 235 | struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id, |
| 236 | const char *name, phys_addr_t *pa); |
| 237 | |
| 238 | enum { |
| 239 | IRQCHIP_FWNODE_REAL, |
| 240 | IRQCHIP_FWNODE_NAMED, |
| 241 | IRQCHIP_FWNODE_NAMED_ID, |
| 242 | }; |
| 243 | |
| 244 | static inline struct fwnode_handle *irq_domain_alloc_named_fwnode(const char *name) |
| 245 | { |
| 246 | return __irq_domain_alloc_fwnode(IRQCHIP_FWNODE_NAMED, 0, name, NULL); |
| 247 | } |
| 248 | |
| 249 | static inline struct fwnode_handle *irq_domain_alloc_named_id_fwnode(const char *name, int id) |
| 250 | { |
| 251 | return __irq_domain_alloc_fwnode(IRQCHIP_FWNODE_NAMED_ID, id, name, |
| 252 | NULL); |
| 253 | } |
| 254 | |
| 255 | static inline struct fwnode_handle *irq_domain_alloc_fwnode(phys_addr_t *pa) |
| 256 | { |
| 257 | return __irq_domain_alloc_fwnode(IRQCHIP_FWNODE_REAL, 0, NULL, pa); |
| 258 | } |
| 259 | |
| 260 | void irq_domain_free_fwnode(struct fwnode_handle *fwnode); |
| 261 | |
| 262 | DEFINE_FREE(irq_domain_free_fwnode, struct fwnode_handle *, if (_T) irq_domain_free_fwnode(_T)) |
| 263 | |
| 264 | struct irq_domain_chip_generic_info; |
| 265 | |
| 266 | /** |
| 267 | * struct irq_domain_info - Domain information structure |
| 268 | * @fwnode: firmware node for the interrupt controller |
| 269 | * @domain_flags: Additional flags to add to the domain flags |
| 270 | * @size: Size of linear map; 0 for radix mapping only |
| 271 | * @hwirq_max: Maximum number of interrupts supported by controller |
| 272 | * @direct_max: Maximum value of direct maps; |
| 273 | * Use ~0 for no limit; 0 for no direct mapping |
| 274 | * @hwirq_base: The first hardware interrupt number (legacy domains only) |
| 275 | * @virq_base: The first Linux interrupt number for legacy domains to |
| 276 | * immediately associate the interrupts after domain creation |
| 277 | * @bus_token: Domain bus token |
| 278 | * @name_suffix: Optional name suffix to avoid collisions when multiple |
| 279 | * domains are added using same fwnode |
| 280 | * @ops: Domain operation callbacks |
| 281 | * @host_data: Controller private data pointer |
| 282 | * @dgc_info: Geneneric chip information structure pointer used to |
| 283 | * create generic chips for the domain if not NULL. |
| 284 | * @init: Function called when the domain is created. |
| 285 | * Allow to do some additional domain initialisation. |
| 286 | * @exit: Function called when the domain is destroyed. |
| 287 | * Allow to do some additional cleanup operation. |
| 288 | */ |
| 289 | struct irq_domain_info { |
| 290 | struct fwnode_handle *fwnode; |
| 291 | unsigned int domain_flags; |
| 292 | unsigned int size; |
| 293 | irq_hw_number_t hwirq_max; |
| 294 | int direct_max; |
| 295 | unsigned int hwirq_base; |
| 296 | unsigned int virq_base; |
| 297 | enum irq_domain_bus_token bus_token; |
| 298 | const char *name_suffix; |
| 299 | const struct irq_domain_ops *ops; |
| 300 | void *host_data; |
| 301 | #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY |
| 302 | /** |
| 303 | * @parent: Pointer to the parent irq domain used in a hierarchy domain |
| 304 | */ |
| 305 | struct irq_domain *parent; |
| 306 | #endif |
| 307 | struct irq_domain_chip_generic_info *dgc_info; |
| 308 | int (*init)(struct irq_domain *d); |
| 309 | void (*exit)(struct irq_domain *d); |
| 310 | }; |
| 311 | |
| 312 | struct irq_domain *irq_domain_instantiate(const struct irq_domain_info *info); |
| 313 | struct irq_domain *devm_irq_domain_instantiate(struct device *dev, |
| 314 | const struct irq_domain_info *info); |
| 315 | |
| 316 | struct irq_domain *irq_domain_create_simple(struct fwnode_handle *fwnode, unsigned int size, |
| 317 | unsigned int first_irq, |
| 318 | const struct irq_domain_ops *ops, void *host_data); |
| 319 | struct irq_domain *irq_domain_create_legacy(struct fwnode_handle *fwnode, unsigned int size, |
| 320 | unsigned int first_irq, irq_hw_number_t first_hwirq, |
| 321 | const struct irq_domain_ops *ops, void *host_data); |
| 322 | struct irq_domain *irq_find_matching_fwspec(struct irq_fwspec *fwspec, |
| 323 | enum irq_domain_bus_token bus_token); |
| 324 | void irq_set_default_domain(struct irq_domain *domain); |
| 325 | struct irq_domain *irq_get_default_domain(void); |
| 326 | int irq_domain_alloc_descs(int virq, unsigned int nr_irqs, irq_hw_number_t hwirq, int node, |
| 327 | const struct irq_affinity_desc *affinity); |
| 328 | |
| 329 | extern const struct fwnode_operations irqchip_fwnode_ops; |
| 330 | |
| 331 | static inline bool is_fwnode_irqchip(const struct fwnode_handle *fwnode) |
| 332 | { |
| 333 | return fwnode && fwnode->ops == &irqchip_fwnode_ops; |
| 334 | } |
| 335 | |
| 336 | void irq_domain_update_bus_token(struct irq_domain *domain, enum irq_domain_bus_token bus_token); |
| 337 | |
| 338 | static inline struct irq_domain *irq_find_matching_fwnode(struct fwnode_handle *fwnode, |
| 339 | enum irq_domain_bus_token bus_token) |
| 340 | { |
| 341 | struct irq_fwspec fwspec = { |
| 342 | .fwnode = fwnode, |
| 343 | }; |
| 344 | |
| 345 | return irq_find_matching_fwspec(&fwspec, bus_token); |
| 346 | } |
| 347 | |
| 348 | static inline struct irq_domain *irq_find_matching_host(struct device_node *node, |
| 349 | enum irq_domain_bus_token bus_token) |
| 350 | { |
| 351 | return irq_find_matching_fwnode(of_fwnode_handle(node), bus_token); |
| 352 | } |
| 353 | |
| 354 | static inline struct irq_domain *irq_find_host(struct device_node *node) |
| 355 | { |
| 356 | struct irq_domain *d; |
| 357 | |
| 358 | d = irq_find_matching_host(node, DOMAIN_BUS_WIRED); |
| 359 | if (!d) |
| 360 | d = irq_find_matching_host(node, DOMAIN_BUS_ANY); |
| 361 | |
| 362 | return d; |
| 363 | } |
| 364 | |
| 365 | #ifdef CONFIG_IRQ_DOMAIN_NOMAP |
| 366 | static inline struct irq_domain *irq_domain_create_nomap(struct fwnode_handle *fwnode, |
| 367 | unsigned int max_irq, |
| 368 | const struct irq_domain_ops *ops, |
| 369 | void *host_data) |
| 370 | { |
| 371 | const struct irq_domain_info info = { |
| 372 | .fwnode = fwnode, |
| 373 | .hwirq_max = max_irq, |
| 374 | .direct_max = max_irq, |
| 375 | .ops = ops, |
| 376 | .host_data = host_data, |
| 377 | }; |
| 378 | struct irq_domain *d = irq_domain_instantiate(&info); |
| 379 | |
| 380 | return IS_ERR(d) ? NULL : d; |
| 381 | } |
| 382 | |
| 383 | unsigned int irq_create_direct_mapping(struct irq_domain *domain); |
| 384 | #endif |
| 385 | |
| 386 | /** |
| 387 | * irq_domain_create_linear - Allocate and register a linear revmap irq_domain. |
| 388 | * @fwnode: pointer to interrupt controller's FW node. |
| 389 | * @size: Number of interrupts in the domain. |
| 390 | * @ops: map/unmap domain callbacks |
| 391 | * @host_data: Controller private data pointer |
| 392 | * |
| 393 | * Returns: Newly created irq_domain |
| 394 | */ |
| 395 | static inline struct irq_domain *irq_domain_create_linear(struct fwnode_handle *fwnode, |
| 396 | unsigned int size, |
| 397 | const struct irq_domain_ops *ops, |
| 398 | void *host_data) |
| 399 | { |
| 400 | const struct irq_domain_info info = { |
| 401 | .fwnode = fwnode, |
| 402 | .size = size, |
| 403 | .hwirq_max = size, |
| 404 | .ops = ops, |
| 405 | .host_data = host_data, |
| 406 | }; |
| 407 | struct irq_domain *d = irq_domain_instantiate(&info); |
| 408 | |
| 409 | return IS_ERR(d) ? NULL : d; |
| 410 | } |
| 411 | |
| 412 | static inline struct irq_domain *irq_domain_create_tree(struct fwnode_handle *fwnode, |
| 413 | const struct irq_domain_ops *ops, |
| 414 | void *host_data) |
| 415 | { |
| 416 | const struct irq_domain_info info = { |
| 417 | .fwnode = fwnode, |
| 418 | .hwirq_max = ~0, |
| 419 | .ops = ops, |
| 420 | .host_data = host_data, |
| 421 | }; |
| 422 | struct irq_domain *d = irq_domain_instantiate(&info); |
| 423 | |
| 424 | return IS_ERR(d) ? NULL : d; |
| 425 | } |
| 426 | |
| 427 | void irq_domain_remove(struct irq_domain *domain); |
| 428 | |
| 429 | int irq_domain_associate(struct irq_domain *domain, unsigned int irq, irq_hw_number_t hwirq); |
| 430 | void irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base, |
| 431 | irq_hw_number_t hwirq_base, int count); |
| 432 | |
| 433 | unsigned int irq_create_mapping_affinity(struct irq_domain *domain, irq_hw_number_t hwirq, |
| 434 | const struct irq_affinity_desc *affinity); |
| 435 | unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec); |
| 436 | void irq_dispose_mapping(unsigned int virq); |
| 437 | |
| 438 | /** |
| 439 | * irq_create_mapping - Map a hardware interrupt into linux irq space |
| 440 | * @domain: domain owning this hardware interrupt or NULL for default domain |
| 441 | * @hwirq: hardware irq number in that domain space |
| 442 | * |
| 443 | * Only one mapping per hardware interrupt is permitted. |
| 444 | * |
| 445 | * If the sense/trigger is to be specified, set_irq_type() should be called |
| 446 | * on the number returned from that call. |
| 447 | * |
| 448 | * Returns: Linux irq number or 0 on error |
| 449 | */ |
| 450 | static inline unsigned int irq_create_mapping(struct irq_domain *domain, irq_hw_number_t hwirq) |
| 451 | { |
| 452 | return irq_create_mapping_affinity(domain, hwirq, NULL); |
| 453 | } |
| 454 | |
| 455 | struct irq_desc *__irq_resolve_mapping(struct irq_domain *domain, |
| 456 | irq_hw_number_t hwirq, |
| 457 | unsigned int *irq); |
| 458 | |
| 459 | /** |
| 460 | * irq_resolve_mapping - Find a linux irq from a hw irq number. |
| 461 | * @domain: domain owning this hardware interrupt |
| 462 | * @hwirq: hardware irq number in that domain space |
| 463 | * |
| 464 | * Returns: Interrupt descriptor |
| 465 | */ |
| 466 | static inline struct irq_desc *irq_resolve_mapping(struct irq_domain *domain, |
| 467 | irq_hw_number_t hwirq) |
| 468 | { |
| 469 | return __irq_resolve_mapping(domain, hwirq, NULL); |
| 470 | } |
| 471 | |
| 472 | /** |
| 473 | * irq_find_mapping() - Find a linux irq from a hw irq number. |
| 474 | * @domain: domain owning this hardware interrupt |
| 475 | * @hwirq: hardware irq number in that domain space |
| 476 | * |
| 477 | * Returns: Linux irq number or 0 if not found |
| 478 | */ |
| 479 | static inline unsigned int irq_find_mapping(struct irq_domain *domain, |
| 480 | irq_hw_number_t hwirq) |
| 481 | { |
| 482 | unsigned int irq; |
| 483 | |
| 484 | if (__irq_resolve_mapping(domain, hwirq, &irq)) |
| 485 | return irq; |
| 486 | |
| 487 | return 0; |
| 488 | } |
| 489 | |
| 490 | extern const struct irq_domain_ops irq_domain_simple_ops; |
| 491 | |
| 492 | /* stock xlate functions */ |
| 493 | int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr, |
| 494 | const u32 *intspec, unsigned int intsize, |
| 495 | irq_hw_number_t *out_hwirq, unsigned int *out_type); |
| 496 | int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr, |
| 497 | const u32 *intspec, unsigned int intsize, |
| 498 | irq_hw_number_t *out_hwirq, unsigned int *out_type); |
| 499 | int irq_domain_xlate_onetwocell(struct irq_domain *d, struct device_node *ctrlr, |
| 500 | const u32 *intspec, unsigned int intsize, |
| 501 | irq_hw_number_t *out_hwirq, unsigned int *out_type); |
| 502 | int irq_domain_xlate_twothreecell(struct irq_domain *d, struct device_node *ctrlr, |
| 503 | const u32 *intspec, unsigned int intsize, |
| 504 | irq_hw_number_t *out_hwirq, unsigned int *out_type); |
| 505 | |
| 506 | int irq_domain_translate_onecell(struct irq_domain *d, struct irq_fwspec *fwspec, |
| 507 | unsigned long *out_hwirq, unsigned int *out_type); |
| 508 | int irq_domain_translate_twocell(struct irq_domain *d, struct irq_fwspec *fwspec, |
| 509 | unsigned long *out_hwirq, unsigned int *out_type); |
| 510 | int irq_domain_translate_twothreecell(struct irq_domain *d, struct irq_fwspec *fwspec, |
| 511 | unsigned long *out_hwirq, unsigned int *out_type); |
| 512 | |
| 513 | /* IPI functions */ |
| 514 | int irq_reserve_ipi(struct irq_domain *domain, const struct cpumask *dest); |
| 515 | int irq_destroy_ipi(unsigned int irq, const struct cpumask *dest); |
| 516 | |
| 517 | /* V2 interfaces to support hierarchy IRQ domains. */ |
| 518 | struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain, unsigned int virq); |
| 519 | void irq_domain_set_info(struct irq_domain *domain, unsigned int virq, irq_hw_number_t hwirq, |
| 520 | const struct irq_chip *chip, void *chip_data, irq_flow_handler_t handler, |
| 521 | void *handler_data, const char *handler_name); |
| 522 | void irq_domain_reset_irq_data(struct irq_data *irq_data); |
| 523 | #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY |
| 524 | /** |
| 525 | * irq_domain_create_hierarchy - Add a irqdomain into the hierarchy |
| 526 | * @parent: Parent irq domain to associate with the new domain |
| 527 | * @flags: Irq domain flags associated to the domain |
| 528 | * @size: Size of the domain. See below |
| 529 | * @fwnode: Optional fwnode of the interrupt controller |
| 530 | * @ops: Pointer to the interrupt domain callbacks |
| 531 | * @host_data: Controller private data pointer |
| 532 | * |
| 533 | * If @size is 0 a tree domain is created, otherwise a linear domain. |
| 534 | * |
| 535 | * If successful the parent is associated to the new domain and the |
| 536 | * domain flags are set. |
| 537 | * |
| 538 | * Returns: A pointer to IRQ domain, or %NULL on failure. |
| 539 | */ |
| 540 | static inline struct irq_domain *irq_domain_create_hierarchy(struct irq_domain *parent, |
| 541 | unsigned int flags, unsigned int size, |
| 542 | struct fwnode_handle *fwnode, |
| 543 | const struct irq_domain_ops *ops, |
| 544 | void *host_data) |
| 545 | { |
| 546 | const struct irq_domain_info info = { |
| 547 | .fwnode = fwnode, |
| 548 | .size = size, |
| 549 | .hwirq_max = size ? : ~0U, |
| 550 | .ops = ops, |
| 551 | .host_data = host_data, |
| 552 | .domain_flags = flags, |
| 553 | .parent = parent, |
| 554 | }; |
| 555 | struct irq_domain *d = irq_domain_instantiate(&info); |
| 556 | |
| 557 | return IS_ERR(d) ? NULL : d; |
| 558 | } |
| 559 | |
| 560 | int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base, unsigned int nr_irqs, |
| 561 | int node, void *arg, bool realloc, |
| 562 | const struct irq_affinity_desc *affinity); |
| 563 | void irq_domain_free_irqs(unsigned int virq, unsigned int nr_irqs); |
| 564 | int irq_domain_activate_irq(struct irq_data *irq_data, bool early); |
| 565 | void irq_domain_deactivate_irq(struct irq_data *irq_data); |
| 566 | |
| 567 | /** |
| 568 | * irq_domain_alloc_irqs - Allocate IRQs from domain |
| 569 | * @domain: domain to allocate from |
| 570 | * @nr_irqs: number of IRQs to allocate |
| 571 | * @node: NUMA node id for memory allocation |
| 572 | * @arg: domain specific argument |
| 573 | * |
| 574 | * See __irq_domain_alloc_irqs()' documentation. |
| 575 | */ |
| 576 | static inline int irq_domain_alloc_irqs(struct irq_domain *domain, unsigned int nr_irqs, |
| 577 | int node, void *arg) |
| 578 | { |
| 579 | return __irq_domain_alloc_irqs(domain, -1, nr_irqs, node, arg, false, NULL); |
| 580 | } |
| 581 | |
| 582 | int irq_domain_set_hwirq_and_chip(struct irq_domain *domain, unsigned int virq, |
| 583 | irq_hw_number_t hwirq, const struct irq_chip *chip, |
| 584 | void *chip_data); |
| 585 | void irq_domain_free_irqs_common(struct irq_domain *domain, unsigned int virq, |
| 586 | unsigned int nr_irqs); |
| 587 | void irq_domain_free_irqs_top(struct irq_domain *domain, unsigned int virq, unsigned int nr_irqs); |
| 588 | |
| 589 | int irq_domain_push_irq(struct irq_domain *domain, int virq, void *arg); |
| 590 | int irq_domain_pop_irq(struct irq_domain *domain, int virq); |
| 591 | |
| 592 | int irq_domain_alloc_irqs_parent(struct irq_domain *domain, unsigned int irq_base, |
| 593 | unsigned int nr_irqs, void *arg); |
| 594 | |
| 595 | void irq_domain_free_irqs_parent(struct irq_domain *domain, unsigned int irq_base, |
| 596 | unsigned int nr_irqs); |
| 597 | |
| 598 | int irq_domain_disconnect_hierarchy(struct irq_domain *domain, unsigned int virq); |
| 599 | |
| 600 | static inline bool irq_domain_is_hierarchy(struct irq_domain *domain) |
| 601 | { |
| 602 | return domain->flags & IRQ_DOMAIN_FLAG_HIERARCHY; |
| 603 | } |
| 604 | |
| 605 | static inline bool irq_domain_is_ipi(struct irq_domain *domain) |
| 606 | { |
| 607 | return domain->flags & (IRQ_DOMAIN_FLAG_IPI_PER_CPU | IRQ_DOMAIN_FLAG_IPI_SINGLE); |
| 608 | } |
| 609 | |
| 610 | static inline bool irq_domain_is_ipi_per_cpu(struct irq_domain *domain) |
| 611 | { |
| 612 | return domain->flags & IRQ_DOMAIN_FLAG_IPI_PER_CPU; |
| 613 | } |
| 614 | |
| 615 | static inline bool irq_domain_is_ipi_single(struct irq_domain *domain) |
| 616 | { |
| 617 | return domain->flags & IRQ_DOMAIN_FLAG_IPI_SINGLE; |
| 618 | } |
| 619 | |
| 620 | static inline bool irq_domain_is_msi(struct irq_domain *domain) |
| 621 | { |
| 622 | return domain->flags & IRQ_DOMAIN_FLAG_MSI; |
| 623 | } |
| 624 | |
| 625 | static inline bool irq_domain_is_msi_parent(struct irq_domain *domain) |
| 626 | { |
| 627 | return domain->flags & IRQ_DOMAIN_FLAG_MSI_PARENT; |
| 628 | } |
| 629 | |
| 630 | static inline bool irq_domain_is_msi_device(struct irq_domain *domain) |
| 631 | { |
| 632 | return domain->flags & IRQ_DOMAIN_FLAG_MSI_DEVICE; |
| 633 | } |
| 634 | |
| 635 | static inline bool irq_domain_is_msi_immutable(struct irq_domain *domain) |
| 636 | { |
| 637 | return domain->flags & IRQ_DOMAIN_FLAG_MSI_IMMUTABLE; |
| 638 | } |
| 639 | #else /* CONFIG_IRQ_DOMAIN_HIERARCHY */ |
| 640 | static inline int irq_domain_alloc_irqs(struct irq_domain *domain, unsigned int nr_irqs, |
| 641 | int node, void *arg) |
| 642 | { |
| 643 | return -1; |
| 644 | } |
| 645 | |
| 646 | static inline void irq_domain_free_irqs(unsigned int virq, unsigned int nr_irqs) { } |
| 647 | |
| 648 | static inline bool irq_domain_is_hierarchy(struct irq_domain *domain) |
| 649 | { |
| 650 | return false; |
| 651 | } |
| 652 | |
| 653 | static inline bool irq_domain_is_ipi(struct irq_domain *domain) |
| 654 | { |
| 655 | return false; |
| 656 | } |
| 657 | |
| 658 | static inline bool irq_domain_is_ipi_per_cpu(struct irq_domain *domain) |
| 659 | { |
| 660 | return false; |
| 661 | } |
| 662 | |
| 663 | static inline bool irq_domain_is_ipi_single(struct irq_domain *domain) |
| 664 | { |
| 665 | return false; |
| 666 | } |
| 667 | |
| 668 | static inline bool irq_domain_is_msi(struct irq_domain *domain) |
| 669 | { |
| 670 | return false; |
| 671 | } |
| 672 | |
| 673 | static inline bool irq_domain_is_msi_parent(struct irq_domain *domain) |
| 674 | { |
| 675 | return false; |
| 676 | } |
| 677 | |
| 678 | static inline bool irq_domain_is_msi_device(struct irq_domain *domain) |
| 679 | { |
| 680 | return false; |
| 681 | } |
| 682 | |
| 683 | #endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */ |
| 684 | |
| 685 | #ifdef CONFIG_GENERIC_MSI_IRQ |
| 686 | int msi_device_domain_alloc_wired(struct irq_domain *domain, unsigned int hwirq, unsigned int type); |
| 687 | void msi_device_domain_free_wired(struct irq_domain *domain, unsigned int virq); |
| 688 | #else |
| 689 | static inline int msi_device_domain_alloc_wired(struct irq_domain *domain, unsigned int hwirq, |
| 690 | unsigned int type) |
| 691 | { |
| 692 | WARN_ON_ONCE(1); |
| 693 | return -EINVAL; |
| 694 | } |
| 695 | static inline void msi_device_domain_free_wired(struct irq_domain *domain, unsigned int virq) |
| 696 | { |
| 697 | WARN_ON_ONCE(1); |
| 698 | } |
| 699 | #endif |
| 700 | |
| 701 | /* Deprecated functions. Will be removed in the merge window */ |
| 702 | static inline struct fwnode_handle *of_node_to_fwnode(struct device_node *node) |
| 703 | { |
| 704 | return node ? &node->fwnode : NULL; |
| 705 | } |
| 706 | |
| 707 | static inline struct irq_domain *irq_domain_add_tree(struct device_node *of_node, |
| 708 | const struct irq_domain_ops *ops, |
| 709 | void *host_data) |
| 710 | { |
| 711 | struct irq_domain_info info = { |
| 712 | .fwnode = of_fwnode_handle(of_node), |
| 713 | .hwirq_max = ~0U, |
| 714 | .ops = ops, |
| 715 | .host_data = host_data, |
| 716 | }; |
| 717 | struct irq_domain *d; |
| 718 | |
| 719 | d = irq_domain_instantiate(&info); |
| 720 | return IS_ERR(d) ? NULL : d; |
| 721 | } |
| 722 | |
| 723 | static inline struct irq_domain *irq_domain_add_linear(struct device_node *of_node, |
| 724 | unsigned int size, |
| 725 | const struct irq_domain_ops *ops, |
| 726 | void *host_data) |
| 727 | { |
| 728 | struct irq_domain_info info = { |
| 729 | .fwnode = of_fwnode_handle(of_node), |
| 730 | .size = size, |
| 731 | .hwirq_max = size, |
| 732 | .ops = ops, |
| 733 | .host_data = host_data, |
| 734 | }; |
| 735 | struct irq_domain *d; |
| 736 | |
| 737 | d = irq_domain_instantiate(&info); |
| 738 | return IS_ERR(d) ? NULL : d; |
| 739 | } |
| 740 | |
| 741 | #else /* CONFIG_IRQ_DOMAIN */ |
| 742 | static inline void irq_dispose_mapping(unsigned int virq) { } |
| 743 | static inline struct irq_domain *irq_find_matching_fwnode(struct fwnode_handle *fwnode, |
| 744 | enum irq_domain_bus_token bus_token) |
| 745 | { |
| 746 | return NULL; |
| 747 | } |
| 748 | #endif /* !CONFIG_IRQ_DOMAIN */ |
| 749 | |
| 750 | #endif /* _LINUX_IRQDOMAIN_H */ |