]>
Commit | Line | Data |
---|---|---|
3b7d1921 EB |
1 | #ifndef LINUX_MSI_H |
2 | #define LINUX_MSI_H | |
3 | ||
b50cac55 | 4 | #include <linux/kobject.h> |
4aa9bc95 ME |
5 | #include <linux/list.h> |
6 | ||
3b7d1921 EB |
7 | struct msi_msg { |
8 | u32 address_lo; /* low 32 bits of msi message address */ | |
9 | u32 address_hi; /* high 32 bits of msi message address */ | |
10 | u32 data; /* 16 bits of msi message data */ | |
11 | }; | |
12 | ||
38737d82 | 13 | extern int pci_msi_ignore_mask; |
c54c1879 | 14 | /* Helper functions */ |
1c9db525 | 15 | struct irq_data; |
39431acb | 16 | struct msi_desc; |
25a98bd4 | 17 | struct pci_dev; |
2366d06e | 18 | void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg); |
2366d06e | 19 | void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg); |
891d4a48 | 20 | |
3b7d1921 EB |
21 | struct msi_desc { |
22 | struct { | |
24d27553 | 23 | __u8 is_msix : 1; |
31ea5d4d YW |
24 | __u8 multiple: 3; /* log2 num of messages allocated */ |
25 | __u8 multi_cap : 3; /* log2 num of messages supported */ | |
f7625980 BH |
26 | __u8 maskbit : 1; /* mask-pending bit supported ? */ |
27 | __u8 is_64 : 1; /* Address size: 0=32bit 1=64bit */ | |
f7625980 BH |
28 | __u16 entry_nr; /* specific enabled entry */ |
29 | unsigned default_irq; /* default pre-assigned irq */ | |
f2440d9a | 30 | } msi_attrib; |
3b7d1921 | 31 | |
f2440d9a | 32 | u32 masked; /* mask bits */ |
4aa9bc95 | 33 | unsigned int irq; |
65f6ae66 | 34 | unsigned int nvec_used; /* number of messages */ |
4aa9bc95 | 35 | struct list_head list; |
3b7d1921 | 36 | |
264d9caa MW |
37 | union { |
38 | void __iomem *mask_base; | |
39 | u8 mask_pos; | |
40 | }; | |
25a98bd4 | 41 | struct device *dev; |
3b7d1921 | 42 | |
392ee1e6 EB |
43 | /* Last set MSI message */ |
44 | struct msi_msg msg; | |
3b7d1921 EB |
45 | }; |
46 | ||
d31eb342 | 47 | /* Helpers to hide struct msi_desc implementation details */ |
25a98bd4 | 48 | #define msi_desc_to_dev(desc) ((desc)->dev) |
4a7cc831 | 49 | #define dev_to_msi_list(dev) (&(dev)->msi_list) |
d31eb342 JL |
50 | #define first_msi_entry(dev) \ |
51 | list_first_entry(dev_to_msi_list((dev)), struct msi_desc, list) | |
52 | #define for_each_msi_entry(desc, dev) \ | |
53 | list_for_each_entry((desc), dev_to_msi_list((dev)), list) | |
54 | ||
55 | #ifdef CONFIG_PCI_MSI | |
56 | #define first_pci_msi_entry(pdev) first_msi_entry(&(pdev)->dev) | |
57 | #define for_each_pci_msi_entry(desc, pdev) \ | |
58 | for_each_msi_entry((desc), &(pdev)->dev) | |
59 | ||
25a98bd4 | 60 | struct pci_dev *msi_desc_to_pci_dev(struct msi_desc *desc); |
c179c9b9 JL |
61 | void *msi_desc_to_pci_sysdata(struct msi_desc *desc); |
62 | #else /* CONFIG_PCI_MSI */ | |
63 | static inline void *msi_desc_to_pci_sysdata(struct msi_desc *desc) | |
64 | { | |
65 | return NULL; | |
66 | } | |
d31eb342 JL |
67 | #endif /* CONFIG_PCI_MSI */ |
68 | ||
891d4a48 | 69 | void __pci_read_msi_msg(struct msi_desc *entry, struct msi_msg *msg); |
83a18912 JL |
70 | void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg); |
71 | void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg); | |
72 | ||
23ed8d57 TG |
73 | u32 __pci_msix_desc_mask_irq(struct msi_desc *desc, u32 flag); |
74 | u32 __pci_msi_desc_mask_irq(struct msi_desc *desc, u32 mask, u32 flag); | |
75 | void pci_msi_mask_irq(struct irq_data *data); | |
76 | void pci_msi_unmask_irq(struct irq_data *data); | |
77 | ||
83a18912 JL |
78 | /* Conversion helpers. Should be removed after merging */ |
79 | static inline void __write_msi_msg(struct msi_desc *entry, struct msi_msg *msg) | |
80 | { | |
81 | __pci_write_msi_msg(entry, msg); | |
82 | } | |
83 | static inline void write_msi_msg(int irq, struct msi_msg *msg) | |
84 | { | |
85 | pci_write_msi_msg(irq, msg); | |
86 | } | |
23ed8d57 TG |
87 | static inline void mask_msi_irq(struct irq_data *data) |
88 | { | |
89 | pci_msi_mask_irq(data); | |
90 | } | |
91 | static inline void unmask_msi_irq(struct irq_data *data) | |
92 | { | |
93 | pci_msi_unmask_irq(data); | |
94 | } | |
891d4a48 | 95 | |
3b7d1921 | 96 | /* |
4287d824 TP |
97 | * The arch hooks to setup up msi irqs. Those functions are |
98 | * implemented as weak symbols so that they /can/ be overriden by | |
99 | * architecture specific code if needed. | |
3b7d1921 | 100 | */ |
f7feaca7 | 101 | int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc); |
3b7d1921 | 102 | void arch_teardown_msi_irq(unsigned int irq); |
2366d06e BH |
103 | int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type); |
104 | void arch_teardown_msi_irqs(struct pci_dev *dev); | |
ac8344c4 | 105 | void arch_restore_msi_irqs(struct pci_dev *dev); |
4287d824 TP |
106 | |
107 | void default_teardown_msi_irqs(struct pci_dev *dev); | |
ac8344c4 | 108 | void default_restore_msi_irqs(struct pci_dev *dev); |
3b7d1921 | 109 | |
c2791b80 | 110 | struct msi_controller { |
0cbdcfcf TR |
111 | struct module *owner; |
112 | struct device *dev; | |
0d5a6db3 TP |
113 | struct device_node *of_node; |
114 | struct list_head list; | |
020c3126 MZ |
115 | #ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN |
116 | struct irq_domain *domain; | |
117 | #endif | |
0cbdcfcf | 118 | |
c2791b80 | 119 | int (*setup_irq)(struct msi_controller *chip, struct pci_dev *dev, |
0cbdcfcf | 120 | struct msi_desc *desc); |
c2791b80 | 121 | void (*teardown_irq)(struct msi_controller *chip, unsigned int irq); |
0cbdcfcf TR |
122 | }; |
123 | ||
f3cf8bb0 | 124 | #ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN |
d9109698 | 125 | |
aeeb5965 | 126 | #include <linux/irqhandler.h> |
d9109698 JL |
127 | #include <asm/msi.h> |
128 | ||
f3cf8bb0 JL |
129 | struct irq_domain; |
130 | struct irq_chip; | |
131 | struct device_node; | |
132 | struct msi_domain_info; | |
133 | ||
134 | /** | |
135 | * struct msi_domain_ops - MSI interrupt domain callbacks | |
136 | * @get_hwirq: Retrieve the resulting hw irq number | |
137 | * @msi_init: Domain specific init function for MSI interrupts | |
138 | * @msi_free: Domain specific function to free a MSI interrupts | |
d9109698 JL |
139 | * @msi_check: Callback for verification of the domain/info/dev data |
140 | * @msi_prepare: Prepare the allocation of the interrupts in the domain | |
141 | * @msi_finish: Optional callbacl to finalize the allocation | |
142 | * @set_desc: Set the msi descriptor for an interrupt | |
143 | * @handle_error: Optional error handler if the allocation fails | |
144 | * | |
145 | * @get_hwirq, @msi_init and @msi_free are callbacks used by | |
146 | * msi_create_irq_domain() and related interfaces | |
147 | * | |
148 | * @msi_check, @msi_prepare, @msi_finish, @set_desc and @handle_error | |
149 | * are callbacks used by msi_irq_domain_alloc_irqs() and related | |
150 | * interfaces which are based on msi_desc. | |
f3cf8bb0 JL |
151 | */ |
152 | struct msi_domain_ops { | |
aeeb5965 JL |
153 | irq_hw_number_t (*get_hwirq)(struct msi_domain_info *info, |
154 | msi_alloc_info_t *arg); | |
f3cf8bb0 JL |
155 | int (*msi_init)(struct irq_domain *domain, |
156 | struct msi_domain_info *info, | |
157 | unsigned int virq, irq_hw_number_t hwirq, | |
aeeb5965 | 158 | msi_alloc_info_t *arg); |
f3cf8bb0 JL |
159 | void (*msi_free)(struct irq_domain *domain, |
160 | struct msi_domain_info *info, | |
161 | unsigned int virq); | |
d9109698 JL |
162 | int (*msi_check)(struct irq_domain *domain, |
163 | struct msi_domain_info *info, | |
164 | struct device *dev); | |
165 | int (*msi_prepare)(struct irq_domain *domain, | |
166 | struct device *dev, int nvec, | |
167 | msi_alloc_info_t *arg); | |
168 | void (*msi_finish)(msi_alloc_info_t *arg, int retval); | |
169 | void (*set_desc)(msi_alloc_info_t *arg, | |
170 | struct msi_desc *desc); | |
171 | int (*handle_error)(struct irq_domain *domain, | |
172 | struct msi_desc *desc, int error); | |
f3cf8bb0 JL |
173 | }; |
174 | ||
175 | /** | |
176 | * struct msi_domain_info - MSI interrupt domain data | |
aeeb5965 JL |
177 | * @flags: Flags to decribe features and capabilities |
178 | * @ops: The callback data structure | |
179 | * @chip: Optional: associated interrupt chip | |
180 | * @chip_data: Optional: associated interrupt chip data | |
181 | * @handler: Optional: associated interrupt flow handler | |
182 | * @handler_data: Optional: associated interrupt flow handler data | |
183 | * @handler_name: Optional: associated interrupt flow handler name | |
184 | * @data: Optional: domain specific data | |
f3cf8bb0 JL |
185 | */ |
186 | struct msi_domain_info { | |
aeeb5965 | 187 | u32 flags; |
f3cf8bb0 JL |
188 | struct msi_domain_ops *ops; |
189 | struct irq_chip *chip; | |
aeeb5965 JL |
190 | void *chip_data; |
191 | irq_flow_handler_t handler; | |
192 | void *handler_data; | |
193 | const char *handler_name; | |
f3cf8bb0 JL |
194 | void *data; |
195 | }; | |
196 | ||
aeeb5965 JL |
197 | /* Flags for msi_domain_info */ |
198 | enum { | |
199 | /* | |
200 | * Init non implemented ops callbacks with default MSI domain | |
201 | * callbacks. | |
202 | */ | |
203 | MSI_FLAG_USE_DEF_DOM_OPS = (1 << 0), | |
204 | /* | |
205 | * Init non implemented chip callbacks with default MSI chip | |
206 | * callbacks. | |
207 | */ | |
208 | MSI_FLAG_USE_DEF_CHIP_OPS = (1 << 1), | |
209 | /* Build identity map between hwirq and irq */ | |
210 | MSI_FLAG_IDENTITY_MAP = (1 << 2), | |
211 | /* Support multiple PCI MSI interrupts */ | |
212 | MSI_FLAG_MULTI_PCI_MSI = (1 << 3), | |
213 | /* Support PCI MSIX interrupts */ | |
214 | MSI_FLAG_PCI_MSIX = (1 << 4), | |
215 | }; | |
216 | ||
f3cf8bb0 JL |
217 | int msi_domain_set_affinity(struct irq_data *data, const struct cpumask *mask, |
218 | bool force); | |
219 | ||
220 | struct irq_domain *msi_create_irq_domain(struct device_node *of_node, | |
221 | struct msi_domain_info *info, | |
222 | struct irq_domain *parent); | |
d9109698 JL |
223 | int msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev, |
224 | int nvec); | |
225 | void msi_domain_free_irqs(struct irq_domain *domain, struct device *dev); | |
f3cf8bb0 JL |
226 | struct msi_domain_info *msi_get_domain_info(struct irq_domain *domain); |
227 | ||
228 | #endif /* CONFIG_GENERIC_MSI_IRQ_DOMAIN */ | |
229 | ||
3878eaef JL |
230 | #ifdef CONFIG_PCI_MSI_IRQ_DOMAIN |
231 | void pci_msi_domain_write_msg(struct irq_data *irq_data, struct msi_msg *msg); | |
232 | struct irq_domain *pci_msi_create_irq_domain(struct device_node *node, | |
233 | struct msi_domain_info *info, | |
234 | struct irq_domain *parent); | |
235 | int pci_msi_domain_alloc_irqs(struct irq_domain *domain, struct pci_dev *dev, | |
236 | int nvec, int type); | |
237 | void pci_msi_domain_free_irqs(struct irq_domain *domain, struct pci_dev *dev); | |
8e047ada JL |
238 | struct irq_domain *pci_msi_create_default_irq_domain(struct device_node *node, |
239 | struct msi_domain_info *info, struct irq_domain *parent); | |
240 | ||
3878eaef JL |
241 | irq_hw_number_t pci_msi_domain_calc_hwirq(struct pci_dev *dev, |
242 | struct msi_desc *desc); | |
243 | int pci_msi_domain_check_cap(struct irq_domain *domain, | |
244 | struct msi_domain_info *info, struct device *dev); | |
245 | #endif /* CONFIG_PCI_MSI_IRQ_DOMAIN */ | |
246 | ||
3b7d1921 | 247 | #endif /* LINUX_MSI_H */ |