xref: /linux/include/linux/of_irq.h (revision bdbddf72a2ab1cfea699959795d70df3931eefe7)
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 
12 typedef int (*of_irq_init_cb_t)(struct device_node *, struct device_node *);
13 
14 struct of_imap_parser {
15 	struct device_node *node;
16 	const __be32 *imap;
17 	const __be32 *imap_end;
18 	u32 parent_offset;
19 };
20 
21 struct 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)
45 extern unsigned int of_irq_workarounds;
46 extern struct device_node *of_irq_dflt_pic;
47 int 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)
of_irq_parse_oldworld(const struct device_node * device,int index,struct of_phandle_args * out_irq)52 static 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 
59 extern int of_irq_parse_raw(const __be32 *addr, struct of_phandle_args *out_irq);
60 extern unsigned int irq_create_of_mapping(struct of_phandle_args *irq_data);
61 extern int of_irq_to_resource(struct device_node *dev, int index,
62 			      struct resource *r);
63 
64 #ifdef CONFIG_OF_IRQ
65 extern void of_irq_init(const struct of_device_id *matches);
66 extern int of_irq_parse_one(struct device_node *device, int index,
67 			  struct of_phandle_args *out_irq);
68 extern int of_irq_count(struct device_node *dev);
69 extern int of_irq_get(struct device_node *dev, int index);
70 extern const struct cpumask *of_irq_get_affinity(struct device_node *dev,
71 						      int index);
72 extern int of_irq_get_byname(struct device_node *dev, const char *name);
73 extern int of_irq_to_resource_table(struct device_node *dev,
74 		struct resource *res, int nr_irqs);
75 extern struct device_node *of_irq_find_parent(struct device_node *child);
76 extern int of_imap_parser_init(struct of_imap_parser *parser,
77 			       struct device_node *node,
78 			       struct of_imap_item *item);
79 extern struct of_imap_item *of_imap_parser_one(struct of_imap_parser *parser,
80 					       struct of_imap_item *item);
81 extern struct irq_domain *of_msi_get_domain(struct device *dev,
82 					    const struct device_node *np,
83 					    enum irq_domain_bus_token token);
84 extern struct irq_domain *of_msi_map_get_device_domain(struct device *dev,
85 							u32 id,
86 							u32 bus_token);
87 extern void of_msi_configure(struct device *dev, const struct device_node *np);
88 extern u32 of_msi_xlate(struct device *dev, struct device_node **msi_np, u32 id_in);
89 #else
of_irq_init(const struct of_device_id * matches)90 static inline void of_irq_init(const struct of_device_id *matches)
91 {
92 }
of_irq_parse_one(struct device_node * device,int index,struct of_phandle_args * out_irq)93 static inline int of_irq_parse_one(struct device_node *device, int index,
94 				   struct of_phandle_args *out_irq)
95 {
96 	return -EINVAL;
97 }
of_irq_count(struct device_node * dev)98 static inline int of_irq_count(struct device_node *dev)
99 {
100 	return 0;
101 }
of_irq_get(struct device_node * dev,int index)102 static inline int of_irq_get(struct device_node *dev, int index)
103 {
104 	return 0;
105 }
of_irq_get_byname(struct device_node * dev,const char * name)106 static inline int of_irq_get_byname(struct device_node *dev, const char *name)
107 {
108 	return 0;
109 }
of_irq_get_affinity(struct device_node * dev,int index)110 static inline const struct cpumask *of_irq_get_affinity(struct device_node *dev,
111 							int index)
112 {
113 	return NULL;
114 }
of_irq_to_resource_table(struct device_node * dev,struct resource * res,int nr_irqs)115 static inline int of_irq_to_resource_table(struct device_node *dev,
116 					   struct resource *res, int nr_irqs)
117 {
118 	return 0;
119 }
of_irq_find_parent(struct device_node * child)120 static inline void *of_irq_find_parent(struct device_node *child)
121 {
122 	return NULL;
123 }
of_imap_parser_init(struct of_imap_parser * parser,struct device_node * node,struct of_imap_item * item)124 static 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 }
of_imap_parser_one(struct of_imap_parser * parser,struct of_imap_item * item)130 static 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 }
of_msi_get_domain(struct device * dev,struct device_node * np,enum irq_domain_bus_token token)135 static 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 }
of_msi_map_get_device_domain(struct device * dev,u32 id,u32 bus_token)141 static inline struct irq_domain *of_msi_map_get_device_domain(struct device *dev,
142 						u32 id, u32 bus_token)
143 {
144 	return NULL;
145 }
of_msi_configure(struct device * dev,struct device_node * np)146 static inline void of_msi_configure(struct device *dev, struct device_node *np)
147 {
148 }
of_msi_xlate(struct device * dev,struct device_node ** msi_np,u32 id_in)149 static 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  */
161 extern unsigned int irq_of_parse_and_map(struct device_node *node, int index);
162 
163 #else /* !CONFIG_OF && !CONFIG_SPARC */
irq_of_parse_and_map(struct device_node * dev,int index)164 static 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 */
172