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