1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
208a543adSGrant Likely /*
308a543adSGrant Likely * irq_domain - IRQ translation domains
408a543adSGrant Likely *
508a543adSGrant Likely * Translation infrastructure between hw and linux irq numbers. This is
608a543adSGrant Likely * helpful for interrupt controllers to implement mapping between hardware
708a543adSGrant Likely * irq numbers and the Linux irq number space.
808a543adSGrant Likely *
9e7a46c81SMarc Zyngier * irq_domains also have hooks for translating device tree or other
10e7a46c81SMarc Zyngier * firmware interrupt representations into a hardware irq number that
11e7a46c81SMarc Zyngier * can be mapped back to a Linux irq number without any extra platform
12e7a46c81SMarc Zyngier * support code.
1308a543adSGrant Likely *
147bb69badSGrant Likely * Interrupt controller "domain" data structure. This could be defined as a
157bb69badSGrant Likely * irq domain controller. That is, it handles the mapping between hardware
167bb69badSGrant Likely * and virtual interrupt numbers for a given interrupt domain. The domain
177bb69badSGrant Likely * structure is generally created by the PIC code for a given PIC instance
187bb69badSGrant Likely * (though a domain can cover more than one PIC if they have a flat number
197bb69badSGrant Likely * model). It's the domain callbacks that are responsible for setting the
207bb69badSGrant Likely * irq_chip on a given irq_desc after it's been mapped.
21cc79ca69SGrant Likely *
22e7a46c81SMarc Zyngier * The host code and data structures use a fwnode_handle pointer to
23e7a46c81SMarc Zyngier * identify the domain. In some cases, and in order to preserve source
24e7a46c81SMarc Zyngier * code compatibility, this fwnode pointer is "upgraded" to a DT
25e7a46c81SMarc Zyngier * device_node. For those firmware infrastructures that do not provide
26e7a46c81SMarc Zyngier * a unique identifier for an interrupt controller, the irq_domain
27e7a46c81SMarc Zyngier * code offers a fwnode allocator.
2808a543adSGrant Likely */
297bb69badSGrant Likely
3008a543adSGrant Likely #ifndef _LINUX_IRQDOMAIN_H
3108a543adSGrant Likely #define _LINUX_IRQDOMAIN_H
3208a543adSGrant Likely
337bb69badSGrant Likely #include <linux/types.h>
34aeef2052SThomas Gleixner #include <linux/irqdomain_defs.h>
351b537708SJiang Liu #include <linux/irqhandler.h>
36f110711aSMarc Zyngier #include <linux/of.h>
37f1d78358SMasahiro Yamada #include <linux/mutex.h>
387bb69badSGrant Likely #include <linux/radix-tree.h>
3908a543adSGrant Likely
4008a543adSGrant Likely struct device_node;
4108219fb1SAndy Shevchenko struct fwnode_handle;
4208a543adSGrant Likely struct irq_domain;
43f8264e34SJiang Liu struct irq_chip;
44f8264e34SJiang Liu struct irq_data;
45d22558ddSMarc Zyngier struct irq_desc;
4606ee6d57SThomas Gleixner struct cpumask;
47c3e7239aSThomas Gleixner struct seq_file;
48bec04037SDou Liyang struct irq_affinity_desc;
49b78780d9SThomas Gleixner struct msi_parent_ops;
507bb69badSGrant Likely
5111e4438eSMarc Zyngier #define IRQ_DOMAIN_IRQ_SPEC_PARAMS 16
5211e4438eSMarc Zyngier
5311e4438eSMarc Zyngier /**
5411e4438eSMarc Zyngier * struct irq_fwspec - generic IRQ specifier structure
5511e4438eSMarc Zyngier *
5611e4438eSMarc Zyngier * @fwnode: Pointer to a firmware-specific descriptor
5711e4438eSMarc Zyngier * @param_count: Number of device-specific parameters
5811e4438eSMarc Zyngier * @param: Device-specific parameters
5911e4438eSMarc Zyngier *
6011e4438eSMarc Zyngier * This structure, directly modeled after of_phandle_args, is used to
6111e4438eSMarc Zyngier * pass a device-specific description of an interrupt.
6211e4438eSMarc Zyngier */
6311e4438eSMarc Zyngier struct irq_fwspec {
6411e4438eSMarc Zyngier struct fwnode_handle *fwnode;
6511e4438eSMarc Zyngier int param_count;
6611e4438eSMarc Zyngier u32 param[IRQ_DOMAIN_IRQ_SPEC_PARAMS];
6711e4438eSMarc Zyngier };
6811e4438eSMarc Zyngier
690ab8d0f6SMarc Zyngier /* Conversion function from of_phandle_args fields to fwspec */
700ab8d0f6SMarc Zyngier void of_phandle_args_to_fwspec(struct device_node *np, const u32 *args,
710ab8d0f6SMarc Zyngier unsigned int count, struct irq_fwspec *fwspec);
720ab8d0f6SMarc Zyngier
7308a543adSGrant Likely /**
7408a543adSGrant Likely * struct irq_domain_ops - Methods for irq_domain objects
757bb69badSGrant Likely * @match: Match an interrupt controller device node to a host, returns
767bb69badSGrant Likely * 1 on a match
777bb69badSGrant Likely * @map: Create or update a mapping between a virtual irq number and a hw
787bb69badSGrant Likely * irq number. This is called only once for a given mapping.
797bb69badSGrant Likely * @unmap: Dispose of such a mapping
807bb69badSGrant Likely * @xlate: Given a device tree node and interrupt specifier, decode
8108a543adSGrant Likely * the hardware irq number and linux irq type value.
827bb69badSGrant Likely *
837bb69badSGrant Likely * Functions below are provided by the driver and called whenever a new mapping
847bb69badSGrant Likely * is created or an old mapping is disposed. The driver can then proceed to
857bb69badSGrant Likely * whatever internal data structures management is required. It also needs
867bb69badSGrant Likely * to setup the irq_desc when returning from map().
8708a543adSGrant Likely */
8808a543adSGrant Likely struct irq_domain_ops {
89ad3aedfbSMarc Zyngier int (*match)(struct irq_domain *d, struct device_node *node,
90ad3aedfbSMarc Zyngier enum irq_domain_bus_token bus_token);
91651e8b54SMarc Zyngier int (*select)(struct irq_domain *d, struct irq_fwspec *fwspec,
92651e8b54SMarc Zyngier enum irq_domain_bus_token bus_token);
937bb69badSGrant Likely int (*map)(struct irq_domain *d, unsigned int virq, irq_hw_number_t hw);
947bb69badSGrant Likely void (*unmap)(struct irq_domain *d, unsigned int virq);
957bb69badSGrant Likely int (*xlate)(struct irq_domain *d, struct device_node *node,
9608a543adSGrant Likely const u32 *intspec, unsigned int intsize,
9708a543adSGrant Likely unsigned long *out_hwirq, unsigned int *out_type);
98f8264e34SJiang Liu #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
99f8264e34SJiang Liu /* extended V2 interfaces to support hierarchy irq_domains */
100f8264e34SJiang Liu int (*alloc)(struct irq_domain *d, unsigned int virq,
101f8264e34SJiang Liu unsigned int nr_irqs, void *arg);
102f8264e34SJiang Liu void (*free)(struct irq_domain *d, unsigned int virq,
103f8264e34SJiang Liu unsigned int nr_irqs);
104702cb0a0SThomas Gleixner int (*activate)(struct irq_domain *d, struct irq_data *irqd, bool reserve);
105f8264e34SJiang Liu void (*deactivate)(struct irq_domain *d, struct irq_data *irq_data);
10611e4438eSMarc Zyngier int (*translate)(struct irq_domain *d, struct irq_fwspec *fwspec,
10711e4438eSMarc Zyngier unsigned long *out_hwirq, unsigned int *out_type);
108f8264e34SJiang Liu #endif
109c3e7239aSThomas Gleixner #ifdef CONFIG_GENERIC_IRQ_DEBUGFS
110c3e7239aSThomas Gleixner void (*debug_show)(struct seq_file *m, struct irq_domain *d,
111c3e7239aSThomas Gleixner struct irq_data *irqd, int ind);
112c3e7239aSThomas Gleixner #endif
11308a543adSGrant Likely };
11408a543adSGrant Likely
1154946f15eSRikard Falkeborn extern const struct irq_domain_ops irq_generic_chip_ops;
116088f40b7SThomas Gleixner
117088f40b7SThomas Gleixner struct irq_domain_chip_generic;
118088f40b7SThomas Gleixner
11908a543adSGrant Likely /**
12008a543adSGrant Likely * struct irq_domain - Hardware interrupt number translation object
1217bb69badSGrant Likely * @link: Element in global irq_domain list.
1221aa0dd94SGrant Likely * @name: Name of interrupt domain
123f876ea3bSThomas Gleixner * @ops: Pointer to irq_domain methods
124f876ea3bSThomas Gleixner * @host_data: Private data pointer for use by owner. Not touched by irq_domain
1257bb69badSGrant Likely * core code.
126f876ea3bSThomas Gleixner * @flags: Per irq_domain flags
1279dc6be3dSThomas Gleixner * @mapcount: The number of mapped interrupts
128*9dbb8e34SJohan Hovold * @mutex: Domain lock, hierarchical domains use root domain's lock
129*9dbb8e34SJohan Hovold * @root: Pointer to root domain, or containing structure if non-hierarchical
1301aa0dd94SGrant Likely *
131f876ea3bSThomas Gleixner * Optional elements:
1324b821300SDou Liyang * @fwnode: Pointer to firmware node associated with the irq_domain. Pretty easy
1334b821300SDou Liyang * to swap it for the of_node via the irq_domain_get_of_node accessor
1341aa0dd94SGrant Likely * @gc: Pointer to a list of generic chips. There is a helper function for
1351aa0dd94SGrant Likely * setting up one or more generic chips for interrupt controllers
1361aa0dd94SGrant Likely * drivers using the generic chip library which uses this pointer.
1374443664fSThomas Gleixner * @dev: Pointer to the device which instantiated the irqdomain
1384443664fSThomas Gleixner * With per device irq domains this is not necessarily the same
1394443664fSThomas Gleixner * as @pm_dev.
1406a9fc419SThomas Gleixner * @pm_dev: Pointer to a device that can be utilized for power management
141f876ea3bSThomas Gleixner * purposes related to the irq domain.
142f8264e34SJiang Liu * @parent: Pointer to parent irq_domain to support hierarchy irq_domains
143b78780d9SThomas Gleixner * @msi_parent_ops: Pointer to MSI parent domain methods for per device domain init
1441aa0dd94SGrant Likely *
145f876ea3bSThomas Gleixner * Revmap data, used internally by the irq domain code:
1461da02736SMarc Zyngier * @revmap_size: Size of the linear map table @revmap[]
1471aa0dd94SGrant Likely * @revmap_tree: Radix map tree for hwirqs that don't fit in the linear map
14848b15a79SMarc Zyngier * @revmap: Linear table of irq_data pointers
14908a543adSGrant Likely */
15008a543adSGrant Likely struct irq_domain {
1517bb69badSGrant Likely struct list_head link;
1520bb4afb4SGrant Likely const char *name;
153a18dc81bSGrant Likely const struct irq_domain_ops *ops;
1547bb69badSGrant Likely void *host_data;
155f8264e34SJiang Liu unsigned int flags;
1569dc6be3dSThomas Gleixner unsigned int mapcount;
157*9dbb8e34SJohan Hovold struct mutex mutex;
158*9dbb8e34SJohan Hovold struct irq_domain *root;
1597bb69badSGrant Likely
1601aa0dd94SGrant Likely /* Optional data */
161f110711aSMarc Zyngier struct fwnode_handle *fwnode;
162ad3aedfbSMarc Zyngier enum irq_domain_bus_token bus_token;
163088f40b7SThomas Gleixner struct irq_domain_chip_generic *gc;
1644443664fSThomas Gleixner struct device *dev;
1656a9fc419SThomas Gleixner struct device *pm_dev;
166f8264e34SJiang Liu #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
167f8264e34SJiang Liu struct irq_domain *parent;
168f8264e34SJiang Liu #endif
169b78780d9SThomas Gleixner #ifdef CONFIG_GENERIC_MSI_IRQ
170b78780d9SThomas Gleixner const struct msi_parent_ops *msi_parent_ops;
171b78780d9SThomas Gleixner #endif
172cef5075cSGrant Likely
1731aa0dd94SGrant Likely /* reverse map data. The linear map gets appended to the irq_domain */
174ddaf144cSGrant Likely irq_hw_number_t hwirq_max;
1751aa0dd94SGrant Likely unsigned int revmap_size;
1761aa0dd94SGrant Likely struct radix_tree_root revmap_tree;
177d4a45c68SMarc Zyngier struct irq_data __rcu *revmap[];
17808a543adSGrant Likely };
17908a543adSGrant Likely
180f8264e34SJiang Liu /* Irq domain flags */
181f8264e34SJiang Liu enum {
182f8264e34SJiang Liu /* Irq domain is hierarchical */
183f8264e34SJiang Liu IRQ_DOMAIN_FLAG_HIERARCHY = (1 << 0),
184f8264e34SJiang Liu
1856a6544e5SMarc Zyngier /* Irq domain name was allocated in __irq_domain_add() */
1862546287cSZenghui Yu IRQ_DOMAIN_NAME_ALLOCATED = (1 << 1),
18736d72731SJiang Liu
1880abefbaaSQais Yousef /* Irq domain is an IPI domain with virq per cpu */
1890abefbaaSQais Yousef IRQ_DOMAIN_FLAG_IPI_PER_CPU = (1 << 2),
1900abefbaaSQais Yousef
1910abefbaaSQais Yousef /* Irq domain is an IPI domain with single virq */
1920abefbaaSQais Yousef IRQ_DOMAIN_FLAG_IPI_SINGLE = (1 << 3),
1930abefbaaSQais Yousef
194631a9639SEric Auger /* Irq domain implements MSIs */
195631a9639SEric Auger IRQ_DOMAIN_FLAG_MSI = (1 << 4),
196631a9639SEric Auger
197dcb83f6eSJason Gunthorpe /*
198dcb83f6eSJason Gunthorpe * Irq domain implements isolated MSI, see msi_device_has_isolated_msi()
199dcb83f6eSJason Gunthorpe */
200dcb83f6eSJason Gunthorpe IRQ_DOMAIN_FLAG_ISOLATED_MSI = (1 << 5),
201631a9639SEric Auger
2024f86a06eSMarc Zyngier /* Irq domain doesn't translate anything */
2033dad5f9aSThomas Gleixner IRQ_DOMAIN_FLAG_NO_MAP = (1 << 6),
2044f86a06eSMarc Zyngier
205b749e6d3SThomas Gleixner /* Irq domain is a MSI parent domain */
206b749e6d3SThomas Gleixner IRQ_DOMAIN_FLAG_MSI_PARENT = (1 << 8),
207b749e6d3SThomas Gleixner
208e71c5d0bSThomas Gleixner /* Irq domain is a MSI device domain */
209e71c5d0bSThomas Gleixner IRQ_DOMAIN_FLAG_MSI_DEVICE = (1 << 9),
210e71c5d0bSThomas Gleixner
2116f1a4891SThomas Gleixner /*
212f8264e34SJiang Liu * Flags starting from IRQ_DOMAIN_FLAG_NONCORE are reserved
213f8264e34SJiang Liu * for implementation specific purposes and ignored by the
214f8264e34SJiang Liu * core code.
215f8264e34SJiang Liu */
216f8264e34SJiang Liu IRQ_DOMAIN_FLAG_NONCORE = (1 << 16),
217f8264e34SJiang Liu };
218f8264e34SJiang Liu
irq_domain_get_of_node(struct irq_domain * d)21910abc7dfSMarc Zyngier static inline struct device_node *irq_domain_get_of_node(struct irq_domain *d)
22010abc7dfSMarc Zyngier {
221f110711aSMarc Zyngier return to_of_node(d->fwnode);
22210abc7dfSMarc Zyngier }
22310abc7dfSMarc Zyngier
irq_domain_set_pm_device(struct irq_domain * d,struct device * dev)2241f8863bfSMarc Zyngier static inline void irq_domain_set_pm_device(struct irq_domain *d,
2251f8863bfSMarc Zyngier struct device *dev)
2261f8863bfSMarc Zyngier {
2271f8863bfSMarc Zyngier if (d)
2286a9fc419SThomas Gleixner d->pm_dev = dev;
2291f8863bfSMarc Zyngier }
2301f8863bfSMarc Zyngier
2317bb69badSGrant Likely #ifdef CONFIG_IRQ_DOMAIN
232d59f6617SThomas Gleixner struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id,
233b977fcf4SMarc Zyngier const char *name, phys_addr_t *pa);
234d59f6617SThomas Gleixner
235d59f6617SThomas Gleixner enum {
236d59f6617SThomas Gleixner IRQCHIP_FWNODE_REAL,
237d59f6617SThomas Gleixner IRQCHIP_FWNODE_NAMED,
238d59f6617SThomas Gleixner IRQCHIP_FWNODE_NAMED_ID,
239d59f6617SThomas Gleixner };
240d59f6617SThomas Gleixner
241d59f6617SThomas Gleixner static inline
irq_domain_alloc_named_fwnode(const char * name)242d59f6617SThomas Gleixner struct fwnode_handle *irq_domain_alloc_named_fwnode(const char *name)
243d59f6617SThomas Gleixner {
244d59f6617SThomas Gleixner return __irq_domain_alloc_fwnode(IRQCHIP_FWNODE_NAMED, 0, name, NULL);
245d59f6617SThomas Gleixner }
246d59f6617SThomas Gleixner
247d59f6617SThomas Gleixner static inline
irq_domain_alloc_named_id_fwnode(const char * name,int id)248d59f6617SThomas Gleixner struct fwnode_handle *irq_domain_alloc_named_id_fwnode(const char *name, int id)
249d59f6617SThomas Gleixner {
250d59f6617SThomas Gleixner return __irq_domain_alloc_fwnode(IRQCHIP_FWNODE_NAMED_ID, id, name,
251d59f6617SThomas Gleixner NULL);
252d59f6617SThomas Gleixner }
253d59f6617SThomas Gleixner
irq_domain_alloc_fwnode(phys_addr_t * pa)254b977fcf4SMarc Zyngier static inline struct fwnode_handle *irq_domain_alloc_fwnode(phys_addr_t *pa)
255d59f6617SThomas Gleixner {
256b977fcf4SMarc Zyngier return __irq_domain_alloc_fwnode(IRQCHIP_FWNODE_REAL, 0, NULL, pa);
257d59f6617SThomas Gleixner }
258d59f6617SThomas Gleixner
259b145dcc4SMarc Zyngier void irq_domain_free_fwnode(struct fwnode_handle *fwnode);
26020c36ce2SBixuan Cui struct irq_domain *__irq_domain_add(struct fwnode_handle *fwnode, unsigned int size,
261ddaf144cSGrant Likely irq_hw_number_t hwirq_max, int direct_max,
262fa40f377SGrant Likely const struct irq_domain_ops *ops,
263fa40f377SGrant Likely void *host_data);
26467196feaSAndy Shevchenko struct irq_domain *irq_domain_create_simple(struct fwnode_handle *fwnode,
265781d0f46SMark Brown unsigned int size,
266781d0f46SMark Brown unsigned int first_irq,
267781d0f46SMark Brown const struct irq_domain_ops *ops,
268781d0f46SMark Brown void *host_data);
269a8db8cf0SGrant Likely struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
2701bc04f2cSGrant Likely unsigned int size,
2711bc04f2cSGrant Likely unsigned int first_irq,
2721bc04f2cSGrant Likely irq_hw_number_t first_hwirq,
273a18dc81bSGrant Likely const struct irq_domain_ops *ops,
274a8db8cf0SGrant Likely void *host_data);
275b6e95788SAndy Shevchenko struct irq_domain *irq_domain_create_legacy(struct fwnode_handle *fwnode,
276b6e95788SAndy Shevchenko unsigned int size,
277b6e95788SAndy Shevchenko unsigned int first_irq,
278b6e95788SAndy Shevchenko irq_hw_number_t first_hwirq,
279b6e95788SAndy Shevchenko const struct irq_domain_ops *ops,
280b6e95788SAndy Shevchenko void *host_data);
281651e8b54SMarc Zyngier extern struct irq_domain *irq_find_matching_fwspec(struct irq_fwspec *fwspec,
282ad3aedfbSMarc Zyngier enum irq_domain_bus_token bus_token);
283cc79ca69SGrant Likely extern void irq_set_default_host(struct irq_domain *host);
2849f199dd3SMarc Zyngier extern struct irq_domain *irq_get_default_host(void);
285ac0a0cd2SQais Yousef extern int irq_domain_alloc_descs(int virq, unsigned int nr_irqs,
28606ee6d57SThomas Gleixner irq_hw_number_t hwirq, int node,
287bec04037SDou Liyang const struct irq_affinity_desc *affinity);
288cc79ca69SGrant Likely
of_node_to_fwnode(struct device_node * node)2891bf4ddc4SMarc Zyngier static inline struct fwnode_handle *of_node_to_fwnode(struct device_node *node)
2901bf4ddc4SMarc Zyngier {
2911bf4ddc4SMarc Zyngier return node ? &node->fwnode : NULL;
2921bf4ddc4SMarc Zyngier }
2931bf4ddc4SMarc Zyngier
294db3e50f3SSakari Ailus extern const struct fwnode_operations irqchip_fwnode_ops;
295db3e50f3SSakari Ailus
is_fwnode_irqchip(struct fwnode_handle * fwnode)29675aba7b0SSuravee Suthikulpanit static inline bool is_fwnode_irqchip(struct fwnode_handle *fwnode)
29775aba7b0SSuravee Suthikulpanit {
298db3e50f3SSakari Ailus return fwnode && fwnode->ops == &irqchip_fwnode_ops;
29975aba7b0SSuravee Suthikulpanit }
30075aba7b0SSuravee Suthikulpanit
30161d0a000SMarc Zyngier extern void irq_domain_update_bus_token(struct irq_domain *domain,
30261d0a000SMarc Zyngier enum irq_domain_bus_token bus_token);
30361d0a000SMarc Zyngier
304651e8b54SMarc Zyngier static inline
irq_find_matching_fwnode(struct fwnode_handle * fwnode,enum irq_domain_bus_token bus_token)305651e8b54SMarc Zyngier struct irq_domain *irq_find_matching_fwnode(struct fwnode_handle *fwnode,
306651e8b54SMarc Zyngier enum irq_domain_bus_token bus_token)
307651e8b54SMarc Zyngier {
308651e8b54SMarc Zyngier struct irq_fwspec fwspec = {
309651e8b54SMarc Zyngier .fwnode = fwnode,
310651e8b54SMarc Zyngier };
311651e8b54SMarc Zyngier
312651e8b54SMarc Zyngier return irq_find_matching_fwspec(&fwspec, bus_token);
313651e8b54SMarc Zyngier }
314651e8b54SMarc Zyngier
irq_find_matching_host(struct device_node * node,enum irq_domain_bus_token bus_token)315130b8c6cSMarc Zyngier static inline struct irq_domain *irq_find_matching_host(struct device_node *node,
316130b8c6cSMarc Zyngier enum irq_domain_bus_token bus_token)
317130b8c6cSMarc Zyngier {
3181bf4ddc4SMarc Zyngier return irq_find_matching_fwnode(of_node_to_fwnode(node), bus_token);
319130b8c6cSMarc Zyngier }
320130b8c6cSMarc Zyngier
irq_find_host(struct device_node * node)321ad3aedfbSMarc Zyngier static inline struct irq_domain *irq_find_host(struct device_node *node)
322ad3aedfbSMarc Zyngier {
32364619343SMarc Zyngier struct irq_domain *d;
32464619343SMarc Zyngier
32564619343SMarc Zyngier d = irq_find_matching_host(node, DOMAIN_BUS_WIRED);
32664619343SMarc Zyngier if (!d)
32764619343SMarc Zyngier d = irq_find_matching_host(node, DOMAIN_BUS_ANY);
32864619343SMarc Zyngier
32964619343SMarc Zyngier return d;
330ad3aedfbSMarc Zyngier }
331ad3aedfbSMarc Zyngier
irq_domain_add_simple(struct device_node * of_node,unsigned int size,unsigned int first_irq,const struct irq_domain_ops * ops,void * host_data)33267196feaSAndy Shevchenko static inline struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
33367196feaSAndy Shevchenko unsigned int size,
33467196feaSAndy Shevchenko unsigned int first_irq,
33567196feaSAndy Shevchenko const struct irq_domain_ops *ops,
33667196feaSAndy Shevchenko void *host_data)
33767196feaSAndy Shevchenko {
33867196feaSAndy Shevchenko return irq_domain_create_simple(of_node_to_fwnode(of_node), size, first_irq, ops, host_data);
33967196feaSAndy Shevchenko }
34067196feaSAndy Shevchenko
341fa40f377SGrant Likely /**
342fa40f377SGrant Likely * irq_domain_add_linear() - Allocate and register a linear revmap irq_domain.
343fa40f377SGrant Likely * @of_node: pointer to interrupt controller's device tree node.
344fa40f377SGrant Likely * @size: Number of interrupts in the domain.
345fa40f377SGrant Likely * @ops: map/unmap domain callbacks
346fa40f377SGrant Likely * @host_data: Controller private data pointer
347fa40f377SGrant Likely */
irq_domain_add_linear(struct device_node * of_node,unsigned int size,const struct irq_domain_ops * ops,void * host_data)348fa40f377SGrant Likely static inline struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
349fa40f377SGrant Likely unsigned int size,
350fa40f377SGrant Likely const struct irq_domain_ops *ops,
351fa40f377SGrant Likely void *host_data)
352fa40f377SGrant Likely {
3531bf4ddc4SMarc Zyngier return __irq_domain_add(of_node_to_fwnode(of_node), size, size, 0, ops, host_data);
354fa40f377SGrant Likely }
355e37af801SMarc Zyngier
356e37af801SMarc Zyngier #ifdef CONFIG_IRQ_DOMAIN_NOMAP
irq_domain_add_nomap(struct device_node * of_node,unsigned int max_irq,const struct irq_domain_ops * ops,void * host_data)357fa40f377SGrant Likely static inline struct irq_domain *irq_domain_add_nomap(struct device_node *of_node,
358fa40f377SGrant Likely unsigned int max_irq,
359fa40f377SGrant Likely const struct irq_domain_ops *ops,
360fa40f377SGrant Likely void *host_data)
361fa40f377SGrant Likely {
3621bf4ddc4SMarc Zyngier return __irq_domain_add(of_node_to_fwnode(of_node), 0, max_irq, max_irq, ops, host_data);
363fa40f377SGrant Likely }
364e37af801SMarc Zyngier
365e37af801SMarc Zyngier extern unsigned int irq_create_direct_mapping(struct irq_domain *host);
366e37af801SMarc Zyngier #endif
367e37af801SMarc Zyngier
irq_domain_add_tree(struct device_node * of_node,const struct irq_domain_ops * ops,void * host_data)368cef5075cSGrant Likely static inline struct irq_domain *irq_domain_add_tree(struct device_node *of_node,
369cef5075cSGrant Likely const struct irq_domain_ops *ops,
370cef5075cSGrant Likely void *host_data)
371cef5075cSGrant Likely {
3721bf4ddc4SMarc Zyngier return __irq_domain_add(of_node_to_fwnode(of_node), 0, ~0, 0, ops, host_data);
3731bf4ddc4SMarc Zyngier }
3741bf4ddc4SMarc Zyngier
irq_domain_create_linear(struct fwnode_handle * fwnode,unsigned int size,const struct irq_domain_ops * ops,void * host_data)3751bf4ddc4SMarc Zyngier static inline struct irq_domain *irq_domain_create_linear(struct fwnode_handle *fwnode,
3761bf4ddc4SMarc Zyngier unsigned int size,
3771bf4ddc4SMarc Zyngier const struct irq_domain_ops *ops,
3781bf4ddc4SMarc Zyngier void *host_data)
3791bf4ddc4SMarc Zyngier {
3801bf4ddc4SMarc Zyngier return __irq_domain_add(fwnode, size, size, 0, ops, host_data);
3811bf4ddc4SMarc Zyngier }
3821bf4ddc4SMarc Zyngier
irq_domain_create_tree(struct fwnode_handle * fwnode,const struct irq_domain_ops * ops,void * host_data)3831bf4ddc4SMarc Zyngier static inline struct irq_domain *irq_domain_create_tree(struct fwnode_handle *fwnode,
3841bf4ddc4SMarc Zyngier const struct irq_domain_ops *ops,
3851bf4ddc4SMarc Zyngier void *host_data)
3861bf4ddc4SMarc Zyngier {
3871bf4ddc4SMarc Zyngier return __irq_domain_add(fwnode, 0, ~0, 0, ops, host_data);
388cef5075cSGrant Likely }
38958ee99adSPaul Mundt
39058ee99adSPaul Mundt extern void irq_domain_remove(struct irq_domain *host);
39158ee99adSPaul Mundt
392ddaf144cSGrant Likely extern int irq_domain_associate(struct irq_domain *domain, unsigned int irq,
393ddaf144cSGrant Likely irq_hw_number_t hwirq);
394ddaf144cSGrant Likely extern void irq_domain_associate_many(struct irq_domain *domain,
39598aa468eSGrant Likely unsigned int irq_base,
39698aa468eSGrant Likely irq_hw_number_t hwirq_base, int count);
39798aa468eSGrant Likely
398bb4c6910SLaurent Vivier extern unsigned int irq_create_mapping_affinity(struct irq_domain *host,
399bb4c6910SLaurent Vivier irq_hw_number_t hwirq,
400bb4c6910SLaurent Vivier const struct irq_affinity_desc *affinity);
401c0131f09SMarc Zyngier extern unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec);
402cc79ca69SGrant Likely extern void irq_dispose_mapping(unsigned int virq);
403d3dcb436SGrant Likely
irq_create_mapping(struct irq_domain * host,irq_hw_number_t hwirq)404bb4c6910SLaurent Vivier static inline unsigned int irq_create_mapping(struct irq_domain *host,
405bb4c6910SLaurent Vivier irq_hw_number_t hwirq)
406bb4c6910SLaurent Vivier {
407bb4c6910SLaurent Vivier return irq_create_mapping_affinity(host, hwirq, NULL);
408bb4c6910SLaurent Vivier }
409bb4c6910SLaurent Vivier
410d22558ddSMarc Zyngier extern struct irq_desc *__irq_resolve_mapping(struct irq_domain *domain,
411d22558ddSMarc Zyngier irq_hw_number_t hwirq,
412d22558ddSMarc Zyngier unsigned int *irq);
413d22558ddSMarc Zyngier
irq_resolve_mapping(struct irq_domain * domain,irq_hw_number_t hwirq)414d22558ddSMarc Zyngier static inline struct irq_desc *irq_resolve_mapping(struct irq_domain *domain,
415d22558ddSMarc Zyngier irq_hw_number_t hwirq)
416d22558ddSMarc Zyngier {
417d22558ddSMarc Zyngier return __irq_resolve_mapping(domain, hwirq, NULL);
418d22558ddSMarc Zyngier }
419d22558ddSMarc Zyngier
420d3dcb436SGrant Likely /**
4211da02736SMarc Zyngier * irq_find_mapping() - Find a linux irq from a hw irq number.
422d3dcb436SGrant Likely * @domain: domain owning this hardware interrupt
423d3dcb436SGrant Likely * @hwirq: hardware irq number in that domain space
424d3dcb436SGrant Likely */
irq_find_mapping(struct irq_domain * domain,irq_hw_number_t hwirq)425d22558ddSMarc Zyngier static inline unsigned int irq_find_mapping(struct irq_domain *domain,
426d22558ddSMarc Zyngier irq_hw_number_t hwirq)
427d22558ddSMarc Zyngier {
428d22558ddSMarc Zyngier unsigned int irq;
429d22558ddSMarc Zyngier
430d22558ddSMarc Zyngier if (__irq_resolve_mapping(domain, hwirq, &irq))
431d22558ddSMarc Zyngier return irq;
432d22558ddSMarc Zyngier
433d22558ddSMarc Zyngier return 0;
434d22558ddSMarc Zyngier }
4351da02736SMarc Zyngier
irq_linear_revmap(struct irq_domain * domain,irq_hw_number_t hwirq)436d3dcb436SGrant Likely static inline unsigned int irq_linear_revmap(struct irq_domain *domain,
437d3dcb436SGrant Likely irq_hw_number_t hwirq)
438d3dcb436SGrant Likely {
4391da02736SMarc Zyngier return irq_find_mapping(domain, hwirq);
440d3dcb436SGrant Likely }
4411da02736SMarc Zyngier
442a18dc81bSGrant Likely extern const struct irq_domain_ops irq_domain_simple_ops;
44316b2e6e2SGrant Likely
44416b2e6e2SGrant Likely /* stock xlate functions */
44516b2e6e2SGrant Likely int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr,
44616b2e6e2SGrant Likely const u32 *intspec, unsigned int intsize,
44716b2e6e2SGrant Likely irq_hw_number_t *out_hwirq, unsigned int *out_type);
44816b2e6e2SGrant Likely int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
44916b2e6e2SGrant Likely const u32 *intspec, unsigned int intsize,
45016b2e6e2SGrant Likely irq_hw_number_t *out_hwirq, unsigned int *out_type);
45116b2e6e2SGrant Likely int irq_domain_xlate_onetwocell(struct irq_domain *d, struct device_node *ctrlr,
45216b2e6e2SGrant Likely const u32 *intspec, unsigned int intsize,
45316b2e6e2SGrant Likely irq_hw_number_t *out_hwirq, unsigned int *out_type);
45416b2e6e2SGrant Likely
455b5c231d8SBrian Masney int irq_domain_translate_twocell(struct irq_domain *d,
456b5c231d8SBrian Masney struct irq_fwspec *fwspec,
457b5c231d8SBrian Masney unsigned long *out_hwirq,
458b5c231d8SBrian Masney unsigned int *out_type);
459b5c231d8SBrian Masney
460b01ecceaSYash Shah int irq_domain_translate_onecell(struct irq_domain *d,
461b01ecceaSYash Shah struct irq_fwspec *fwspec,
462b01ecceaSYash Shah unsigned long *out_hwirq,
463b01ecceaSYash Shah unsigned int *out_type);
464b01ecceaSYash Shah
465d17bf24eSQais Yousef /* IPI functions */
4667cec18a3SMatt Redfearn int irq_reserve_ipi(struct irq_domain *domain, const struct cpumask *dest);
4677cec18a3SMatt Redfearn int irq_destroy_ipi(unsigned int irq, const struct cpumask *dest);
468d17bf24eSQais Yousef
469f8264e34SJiang Liu /* V2 interfaces to support hierarchy IRQ domains. */
470f8264e34SJiang Liu extern struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
471f8264e34SJiang Liu unsigned int virq);
4725f22f5c6SStefan Agner extern void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
47345ec846cSMarc Zyngier irq_hw_number_t hwirq,
47445ec846cSMarc Zyngier const struct irq_chip *chip,
4755f22f5c6SStefan Agner void *chip_data, irq_flow_handler_t handler,
4765f22f5c6SStefan Agner void *handler_data, const char *handler_name);
4775c8f77a2SBartosz Golaszewski extern void irq_domain_reset_irq_data(struct irq_data *irq_data);
478f8264e34SJiang Liu #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
4792a5e9a07SMarc Zyngier extern struct irq_domain *irq_domain_create_hierarchy(struct irq_domain *parent,
480afb7da83SJiang Liu unsigned int flags, unsigned int size,
4812a5e9a07SMarc Zyngier struct fwnode_handle *fwnode,
482afb7da83SJiang Liu const struct irq_domain_ops *ops, void *host_data);
4832a5e9a07SMarc Zyngier
irq_domain_add_hierarchy(struct irq_domain * parent,unsigned int flags,unsigned int size,struct device_node * node,const struct irq_domain_ops * ops,void * host_data)4842a5e9a07SMarc Zyngier static inline struct irq_domain *irq_domain_add_hierarchy(struct irq_domain *parent,
4852a5e9a07SMarc Zyngier unsigned int flags,
4862a5e9a07SMarc Zyngier unsigned int size,
4872a5e9a07SMarc Zyngier struct device_node *node,
4882a5e9a07SMarc Zyngier const struct irq_domain_ops *ops,
4892a5e9a07SMarc Zyngier void *host_data)
4902a5e9a07SMarc Zyngier {
4912a5e9a07SMarc Zyngier return irq_domain_create_hierarchy(parent, flags, size,
4922a5e9a07SMarc Zyngier of_node_to_fwnode(node),
4932a5e9a07SMarc Zyngier ops, host_data);
4942a5e9a07SMarc Zyngier }
4952a5e9a07SMarc Zyngier
496f8264e34SJiang Liu extern int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base,
497f8264e34SJiang Liu unsigned int nr_irqs, int node, void *arg,
498bec04037SDou Liyang bool realloc,
499bec04037SDou Liyang const struct irq_affinity_desc *affinity);
500f8264e34SJiang Liu extern void irq_domain_free_irqs(unsigned int virq, unsigned int nr_irqs);
50142e1cc2dSThomas Gleixner extern int irq_domain_activate_irq(struct irq_data *irq_data, bool early);
502f8264e34SJiang Liu extern void irq_domain_deactivate_irq(struct irq_data *irq_data);
503f8264e34SJiang Liu
irq_domain_alloc_irqs(struct irq_domain * domain,unsigned int nr_irqs,int node,void * arg)504f8264e34SJiang Liu static inline int irq_domain_alloc_irqs(struct irq_domain *domain,
505f8264e34SJiang Liu unsigned int nr_irqs, int node, void *arg)
506f8264e34SJiang Liu {
50706ee6d57SThomas Gleixner return __irq_domain_alloc_irqs(domain, -1, nr_irqs, node, arg, false,
50806ee6d57SThomas Gleixner NULL);
509f8264e34SJiang Liu }
510f8264e34SJiang Liu
5116a6544e5SMarc Zyngier extern int irq_domain_alloc_irqs_hierarchy(struct irq_domain *domain,
512c466595cSMarc Zyngier unsigned int irq_base,
513c466595cSMarc Zyngier unsigned int nr_irqs, void *arg);
514f8264e34SJiang Liu extern int irq_domain_set_hwirq_and_chip(struct irq_domain *domain,
515f8264e34SJiang Liu unsigned int virq,
516f8264e34SJiang Liu irq_hw_number_t hwirq,
51745ec846cSMarc Zyngier const struct irq_chip *chip,
518f8264e34SJiang Liu void *chip_data);
519f8264e34SJiang Liu extern void irq_domain_free_irqs_common(struct irq_domain *domain,
520f8264e34SJiang Liu unsigned int virq,
521f8264e34SJiang Liu unsigned int nr_irqs);
522f8264e34SJiang Liu extern void irq_domain_free_irqs_top(struct irq_domain *domain,
523f8264e34SJiang Liu unsigned int virq, unsigned int nr_irqs);
524f8264e34SJiang Liu
525495c38d3SDavid Daney extern int irq_domain_push_irq(struct irq_domain *domain, int virq, void *arg);
526495c38d3SDavid Daney extern int irq_domain_pop_irq(struct irq_domain *domain, int virq);
527495c38d3SDavid Daney
52836d72731SJiang Liu extern int irq_domain_alloc_irqs_parent(struct irq_domain *domain,
529f8264e34SJiang Liu unsigned int irq_base,
53036d72731SJiang Liu unsigned int nr_irqs, void *arg);
531f8264e34SJiang Liu
53236d72731SJiang Liu extern void irq_domain_free_irqs_parent(struct irq_domain *domain,
53336d72731SJiang Liu unsigned int irq_base,
53436d72731SJiang Liu unsigned int nr_irqs);
535f8264e34SJiang Liu
53655567976SMarc Zyngier extern int irq_domain_disconnect_hierarchy(struct irq_domain *domain,
53755567976SMarc Zyngier unsigned int virq);
53855567976SMarc Zyngier
irq_domain_is_hierarchy(struct irq_domain * domain)539f8264e34SJiang Liu static inline bool irq_domain_is_hierarchy(struct irq_domain *domain)
540f8264e34SJiang Liu {
541f8264e34SJiang Liu return domain->flags & IRQ_DOMAIN_FLAG_HIERARCHY;
542f8264e34SJiang Liu }
5430abefbaaSQais Yousef
irq_domain_is_ipi(struct irq_domain * domain)5440abefbaaSQais Yousef static inline bool irq_domain_is_ipi(struct irq_domain *domain)
5450abefbaaSQais Yousef {
5460abefbaaSQais Yousef return domain->flags &
5470abefbaaSQais Yousef (IRQ_DOMAIN_FLAG_IPI_PER_CPU | IRQ_DOMAIN_FLAG_IPI_SINGLE);
5480abefbaaSQais Yousef }
5490abefbaaSQais Yousef
irq_domain_is_ipi_per_cpu(struct irq_domain * domain)5500abefbaaSQais Yousef static inline bool irq_domain_is_ipi_per_cpu(struct irq_domain *domain)
5510abefbaaSQais Yousef {
5520abefbaaSQais Yousef return domain->flags & IRQ_DOMAIN_FLAG_IPI_PER_CPU;
5530abefbaaSQais Yousef }
5540abefbaaSQais Yousef
irq_domain_is_ipi_single(struct irq_domain * domain)5550abefbaaSQais Yousef static inline bool irq_domain_is_ipi_single(struct irq_domain *domain)
5560abefbaaSQais Yousef {
5570abefbaaSQais Yousef return domain->flags & IRQ_DOMAIN_FLAG_IPI_SINGLE;
5580abefbaaSQais Yousef }
559631a9639SEric Auger
irq_domain_is_msi(struct irq_domain * domain)560631a9639SEric Auger static inline bool irq_domain_is_msi(struct irq_domain *domain)
561631a9639SEric Auger {
562631a9639SEric Auger return domain->flags & IRQ_DOMAIN_FLAG_MSI;
563631a9639SEric Auger }
564631a9639SEric Auger
irq_domain_is_msi_parent(struct irq_domain * domain)565b749e6d3SThomas Gleixner static inline bool irq_domain_is_msi_parent(struct irq_domain *domain)
566b749e6d3SThomas Gleixner {
567b749e6d3SThomas Gleixner return domain->flags & IRQ_DOMAIN_FLAG_MSI_PARENT;
568b749e6d3SThomas Gleixner }
569b749e6d3SThomas Gleixner
irq_domain_is_msi_device(struct irq_domain * domain)570e71c5d0bSThomas Gleixner static inline bool irq_domain_is_msi_device(struct irq_domain *domain)
571e71c5d0bSThomas Gleixner {
572e71c5d0bSThomas Gleixner return domain->flags & IRQ_DOMAIN_FLAG_MSI_DEVICE;
573e71c5d0bSThomas Gleixner }
574e71c5d0bSThomas Gleixner
575f8264e34SJiang Liu #else /* CONFIG_IRQ_DOMAIN_HIERARCHY */
irq_domain_alloc_irqs(struct irq_domain * domain,unsigned int nr_irqs,int node,void * arg)576f8264e34SJiang Liu static inline int irq_domain_alloc_irqs(struct irq_domain *domain,
577f8264e34SJiang Liu unsigned int nr_irqs, int node, void *arg)
578f8264e34SJiang Liu {
579f8264e34SJiang Liu return -1;
580f8264e34SJiang Liu }
581f8264e34SJiang Liu
irq_domain_free_irqs(unsigned int virq,unsigned int nr_irqs)5821e2a7d78SJon Hunter static inline void irq_domain_free_irqs(unsigned int virq,
5831e2a7d78SJon Hunter unsigned int nr_irqs) { }
5841e2a7d78SJon Hunter
irq_domain_is_hierarchy(struct irq_domain * domain)585f8264e34SJiang Liu static inline bool irq_domain_is_hierarchy(struct irq_domain *domain)
586f8264e34SJiang Liu {
587f8264e34SJiang Liu return false;
588f8264e34SJiang Liu }
5890abefbaaSQais Yousef
irq_domain_is_ipi(struct irq_domain * domain)5900abefbaaSQais Yousef static inline bool irq_domain_is_ipi(struct irq_domain *domain)
5910abefbaaSQais Yousef {
5920abefbaaSQais Yousef return false;
5930abefbaaSQais Yousef }
5940abefbaaSQais Yousef
irq_domain_is_ipi_per_cpu(struct irq_domain * domain)5950abefbaaSQais Yousef static inline bool irq_domain_is_ipi_per_cpu(struct irq_domain *domain)
5960abefbaaSQais Yousef {
5970abefbaaSQais Yousef return false;
5980abefbaaSQais Yousef }
5990abefbaaSQais Yousef
irq_domain_is_ipi_single(struct irq_domain * domain)6000abefbaaSQais Yousef static inline bool irq_domain_is_ipi_single(struct irq_domain *domain)
6010abefbaaSQais Yousef {
6020abefbaaSQais Yousef return false;
6030abefbaaSQais Yousef }
604631a9639SEric Auger
irq_domain_is_msi(struct irq_domain * domain)605631a9639SEric Auger static inline bool irq_domain_is_msi(struct irq_domain *domain)
606631a9639SEric Auger {
607631a9639SEric Auger return false;
608631a9639SEric Auger }
609631a9639SEric Auger
irq_domain_is_msi_parent(struct irq_domain * domain)610b749e6d3SThomas Gleixner static inline bool irq_domain_is_msi_parent(struct irq_domain *domain)
611b749e6d3SThomas Gleixner {
612b749e6d3SThomas Gleixner return false;
613b749e6d3SThomas Gleixner }
614b749e6d3SThomas Gleixner
irq_domain_is_msi_device(struct irq_domain * domain)615e71c5d0bSThomas Gleixner static inline bool irq_domain_is_msi_device(struct irq_domain *domain)
616e71c5d0bSThomas Gleixner {
617e71c5d0bSThomas Gleixner return false;
618e71c5d0bSThomas Gleixner }
619e71c5d0bSThomas Gleixner
620f8264e34SJiang Liu #endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */
621f8264e34SJiang Liu
622d593f25fSGrant Likely #else /* CONFIG_IRQ_DOMAIN */
irq_dispose_mapping(unsigned int virq)623d593f25fSGrant Likely static inline void irq_dispose_mapping(unsigned int virq) { }
irq_find_matching_fwnode(struct fwnode_handle * fwnode,enum irq_domain_bus_token bus_token)624471036b2SSuravee Suthikulpanit static inline struct irq_domain *irq_find_matching_fwnode(
625471036b2SSuravee Suthikulpanit struct fwnode_handle *fwnode, enum irq_domain_bus_token bus_token)
626471036b2SSuravee Suthikulpanit {
627471036b2SSuravee Suthikulpanit return NULL;
628471036b2SSuravee Suthikulpanit }
629d593f25fSGrant Likely #endif /* !CONFIG_IRQ_DOMAIN */
6307e713301SGrant Likely
63108a543adSGrant Likely #endif /* _LINUX_IRQDOMAIN_H */
632