Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __OF_IRQ_H
3#define __OF_IRQ_H
4
5#include <linux/types.h>
6#include <linux/errno.h>
7#include <linux/irq.h>
8#include <linux/irqdomain.h>
9#include <linux/ioport.h>
10#include <linux/of.h>
11
12typedef int (*of_irq_init_cb_t)(struct device_node *, struct device_node *);
13
14struct of_imap_parser {
15 struct device_node *node;
16 const __be32 *imap;
17 const __be32 *imap_end;
18 u32 parent_offset;
19};
20
21struct of_imap_item {
22 struct of_phandle_args parent_args;
23 u32 child_imap_count;
24 u32 child_imap[16]; /* Arbitrary size.
25 * Should be #address-cells + #interrupt-cells but
26 * avoid using allocation and so, expect that 16
27 * should be enough
28 */
29};
30
31/*
32 * If the iterator is exited prematurely (break, goto, return) of_node_put() has
33 * to be called on item.parent_args.np
34 */
35#define for_each_of_imap_item(parser, item) \
36 for (; of_imap_parser_one(parser, item);)
37
38/*
39 * Workarounds only applied to 32bit powermac machines
40 */
41#define OF_IMAP_OLDWORLD_MAC 0x00000001
42#define OF_IMAP_NO_PHANDLE 0x00000002
43
44#if defined(CONFIG_PPC32) && defined(CONFIG_PPC_PMAC)
45extern unsigned int of_irq_workarounds;
46extern struct device_node *of_irq_dflt_pic;
47int of_irq_parse_oldworld(const struct device_node *device, int index,
48 struct of_phandle_args *out_irq);
49#else /* CONFIG_PPC32 && CONFIG_PPC_PMAC */
50#define of_irq_workarounds (0)
51#define of_irq_dflt_pic (NULL)
52static inline int of_irq_parse_oldworld(const struct device_node *device, int index,
53 struct of_phandle_args *out_irq)
54{
55 return -EINVAL;
56}
57#endif /* CONFIG_PPC32 && CONFIG_PPC_PMAC */
58
59extern int of_irq_parse_raw(const __be32 *addr, struct of_phandle_args *out_irq);
60extern unsigned int irq_create_of_mapping(struct of_phandle_args *irq_data);
61extern int of_irq_to_resource(struct device_node *dev, int index,
62 struct resource *r);
63
64#ifdef CONFIG_OF_IRQ
65extern void of_irq_init(const struct of_device_id *matches);
66extern int of_irq_parse_one(struct device_node *device, int index,
67 struct of_phandle_args *out_irq);
68extern int of_irq_count(struct device_node *dev);
69extern int of_irq_get(struct device_node *dev, int index);
70extern const struct cpumask *of_irq_get_affinity(struct device_node *dev,
71 int index);
72extern int of_irq_get_byname(struct device_node *dev, const char *name);
73extern int of_irq_to_resource_table(struct device_node *dev,
74 struct resource *res, int nr_irqs);
75extern struct device_node *of_irq_find_parent(struct device_node *child);
76extern int of_imap_parser_init(struct of_imap_parser *parser,
77 struct device_node *node,
78 struct of_imap_item *item);
79extern struct of_imap_item *of_imap_parser_one(struct of_imap_parser *parser,
80 struct of_imap_item *item);
81extern struct irq_domain *of_msi_get_domain(struct device *dev,
82 const struct device_node *np,
83 enum irq_domain_bus_token token);
84extern struct irq_domain *of_msi_map_get_device_domain(struct device *dev,
85 u32 id,
86 u32 bus_token);
87extern void of_msi_configure(struct device *dev, const struct device_node *np);
88extern u32 of_msi_xlate(struct device *dev, struct device_node **msi_np, u32 id_in);
89#else
90static inline void of_irq_init(const struct of_device_id *matches)
91{
92}
93static inline int of_irq_parse_one(struct device_node *device, int index,
94 struct of_phandle_args *out_irq)
95{
96 return -EINVAL;
97}
98static inline int of_irq_count(struct device_node *dev)
99{
100 return 0;
101}
102static inline int of_irq_get(struct device_node *dev, int index)
103{
104 return 0;
105}
106static inline int of_irq_get_byname(struct device_node *dev, const char *name)
107{
108 return 0;
109}
110static inline const struct cpumask *of_irq_get_affinity(struct device_node *dev,
111 int index)
112{
113 return NULL;
114}
115static inline int of_irq_to_resource_table(struct device_node *dev,
116 struct resource *res, int nr_irqs)
117{
118 return 0;
119}
120static inline void *of_irq_find_parent(struct device_node *child)
121{
122 return NULL;
123}
124static inline int of_imap_parser_init(struct of_imap_parser *parser,
125 struct device_node *node,
126 struct of_imap_item *item)
127{
128 return -ENOSYS;
129}
130static inline struct of_imap_item *of_imap_parser_one(struct of_imap_parser *parser,
131 struct of_imap_item *item)
132{
133 return NULL;
134}
135static inline struct irq_domain *of_msi_get_domain(struct device *dev,
136 struct device_node *np,
137 enum irq_domain_bus_token token)
138{
139 return NULL;
140}
141static inline struct irq_domain *of_msi_map_get_device_domain(struct device *dev,
142 u32 id, u32 bus_token)
143{
144 return NULL;
145}
146static inline void of_msi_configure(struct device *dev, struct device_node *np)
147{
148}
149static inline u32 of_msi_xlate(struct device *dev, struct device_node **msi_np, u32 id_in)
150{
151 return id_in;
152}
153#endif
154
155#if defined(CONFIG_OF_IRQ) || defined(CONFIG_SPARC)
156/*
157 * irq_of_parse_and_map() is used by all OF enabled platforms; but SPARC
158 * implements it differently. However, the prototype is the same for all,
159 * so declare it here regardless of the CONFIG_OF_IRQ setting.
160 */
161extern unsigned int irq_of_parse_and_map(struct device_node *node, int index);
162
163#else /* !CONFIG_OF && !CONFIG_SPARC */
164static inline unsigned int irq_of_parse_and_map(struct device_node *dev,
165 int index)
166{
167 return 0;
168}
169#endif /* !CONFIG_OF */
170
171#endif /* __OF_IRQ_H */