Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
3b7d1921 EB |
2 | #ifndef LINUX_MSI_H |
3 | #define LINUX_MSI_H | |
4 | ||
ef3350c5 TG |
5 | /* |
6 | * This header file contains MSI data structures and functions which are | |
7 | * only relevant for: | |
8 | * - Interrupt core code | |
9 | * - PCI/MSI core code | |
10 | * - MSI interrupt domain implementations | |
11 | * - IOMMU, low level VFIO, NTB and other justified exceptions | |
12 | * dealing with low level MSI details. | |
13 | * | |
14 | * Regular device drivers have no business with any of these functions and | |
15 | * especially storing MSI descriptor pointers in random code is considered | |
6b6941f6 TG |
16 | * abuse. |
17 | * | |
18 | * Device driver relevant functions are available in <linux/msi_api.h> | |
ef3350c5 TG |
19 | */ |
20 | ||
22db089a | 21 | #include <linux/irqdomain_defs.h> |
3ba1f050 | 22 | #include <linux/cpumask.h> |
6b6941f6 | 23 | #include <linux/msi_api.h> |
cd6cf065 | 24 | #include <linux/xarray.h> |
b5f687f9 | 25 | #include <linux/mutex.h> |
4aa9bc95 | 26 | #include <linux/list.h> |
ebca4396 | 27 | #include <linux/irq.h> |
2d958b02 TG |
28 | #include <linux/bits.h> |
29 | ||
8073c1ac TG |
30 | #include <asm/msi.h> |
31 | ||
32 | /* Dummy shadow structures if an architecture does not define them */ | |
33 | #ifndef arch_msi_msg_addr_lo | |
34 | typedef struct arch_msi_msg_addr_lo { | |
35 | u32 address_lo; | |
36 | } __attribute__ ((packed)) arch_msi_msg_addr_lo_t; | |
37 | #endif | |
38 | ||
39 | #ifndef arch_msi_msg_addr_hi | |
40 | typedef struct arch_msi_msg_addr_hi { | |
41 | u32 address_hi; | |
42 | } __attribute__ ((packed)) arch_msi_msg_addr_hi_t; | |
43 | #endif | |
44 | ||
45 | #ifndef arch_msi_msg_data | |
46 | typedef struct arch_msi_msg_data { | |
47 | u32 data; | |
48 | } __attribute__ ((packed)) arch_msi_msg_data_t; | |
49 | #endif | |
4aa9bc95 | 50 | |
bf210f79 JG |
51 | #ifndef arch_is_isolated_msi |
52 | #define arch_is_isolated_msi() false | |
53 | #endif | |
54 | ||
8073c1ac TG |
55 | /** |
56 | * msi_msg - Representation of a MSI message | |
57 | * @address_lo: Low 32 bits of msi message address | |
58 | * @arch_addrlo: Architecture specific shadow of @address_lo | |
59 | * @address_hi: High 32 bits of msi message address | |
60 | * (only used when device supports it) | |
61 | * @arch_addrhi: Architecture specific shadow of @address_hi | |
62 | * @data: MSI message data (usually 16 bits) | |
63 | * @arch_data: Architecture specific shadow of @data | |
64 | */ | |
3b7d1921 | 65 | struct msi_msg { |
8073c1ac TG |
66 | union { |
67 | u32 address_lo; | |
68 | arch_msi_msg_addr_lo_t arch_addr_lo; | |
69 | }; | |
70 | union { | |
71 | u32 address_hi; | |
72 | arch_msi_msg_addr_hi_t arch_addr_hi; | |
73 | }; | |
74 | union { | |
75 | u32 data; | |
76 | arch_msi_msg_data_t arch_data; | |
77 | }; | |
3b7d1921 EB |
78 | }; |
79 | ||
38737d82 | 80 | extern int pci_msi_ignore_mask; |
c54c1879 | 81 | /* Helper functions */ |
39431acb | 82 | struct msi_desc; |
25a98bd4 | 83 | struct pci_dev; |
c09fcc4b | 84 | struct platform_msi_priv_data; |
bf5e758f | 85 | struct device_attribute; |
64258eaa | 86 | struct irq_domain; |
3d393b21 | 87 | struct irq_affinity_desc; |
bf6e054e | 88 | |
2366d06e | 89 | void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg); |
2f44e29c | 90 | #ifdef CONFIG_GENERIC_MSI_IRQ |
2366d06e | 91 | void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg); |
2f44e29c | 92 | #else |
13e7accb | 93 | static inline void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg) { } |
2f44e29c | 94 | #endif |
891d4a48 | 95 | |
c09fcc4b MZ |
96 | typedef void (*irq_write_msi_msg_t)(struct msi_desc *desc, |
97 | struct msi_msg *msg); | |
98 | ||
e58f2259 TG |
99 | /** |
100 | * pci_msi_desc - PCI/MSI specific MSI descriptor data | |
101 | * | |
102 | * @msi_mask: [PCI MSI] MSI cached mask bits | |
103 | * @msix_ctrl: [PCI MSI-X] MSI-X cached per vector control bits | |
104 | * @is_msix: [PCI MSI/X] True if MSI-X | |
105 | * @multiple: [PCI MSI/X] log2 num of messages allocated | |
106 | * @multi_cap: [PCI MSI/X] log2 num of messages supported | |
107 | * @can_mask: [PCI MSI/X] Masking supported? | |
108 | * @is_64: [PCI MSI/X] Address size: 0=32bit 1=64bit | |
e58f2259 TG |
109 | * @default_irq:[PCI MSI/X] The default pre-assigned non-MSI irq |
110 | * @mask_pos: [PCI MSI] Mask register position | |
111 | * @mask_base: [PCI MSI-X] Mask register base address | |
112 | */ | |
113 | struct pci_msi_desc { | |
114 | union { | |
115 | u32 msi_mask; | |
116 | u32 msix_ctrl; | |
117 | }; | |
118 | struct { | |
119 | u8 is_msix : 1; | |
120 | u8 multiple : 3; | |
121 | u8 multi_cap : 3; | |
122 | u8 can_mask : 1; | |
123 | u8 is_64 : 1; | |
124 | u8 is_virtual : 1; | |
e58f2259 TG |
125 | unsigned default_irq; |
126 | } msi_attrib; | |
127 | union { | |
128 | u8 mask_pos; | |
129 | void __iomem *mask_base; | |
130 | }; | |
131 | }; | |
132 | ||
efd42049 TG |
133 | /** |
134 | * union msi_domain_cookie - Opaque MSI domain specific data | |
135 | * @value: u64 value store | |
136 | * @ptr: Pointer to domain specific data | |
137 | * @iobase: Domain specific IOmem pointer | |
138 | * | |
139 | * The content of this data is implementation defined and used by the MSI | |
140 | * domain to store domain specific information which is requried for | |
141 | * interrupt chip callbacks. | |
142 | */ | |
143 | union msi_domain_cookie { | |
144 | u64 value; | |
145 | void *ptr; | |
146 | void __iomem *iobase; | |
147 | }; | |
148 | ||
149 | /** | |
150 | * struct msi_desc_data - Generic MSI descriptor data | |
151 | * @dcookie: Cookie for MSI domain specific data which is required | |
152 | * for irq_chip callbacks | |
153 | * @icookie: Cookie for the MSI interrupt instance provided by | |
154 | * the usage site to the allocation function | |
155 | * | |
156 | * The content of this data is implementation defined, e.g. PCI/IMS | |
157 | * implementations define the meaning of the data. The MSI core ignores | |
158 | * this data completely. | |
159 | */ | |
160 | struct msi_desc_data { | |
161 | union msi_domain_cookie dcookie; | |
162 | union msi_instance_cookie icookie; | |
163 | }; | |
164 | ||
645474e2 TG |
165 | #define MSI_MAX_INDEX ((unsigned int)USHRT_MAX) |
166 | ||
fc88419c JL |
167 | /** |
168 | * struct msi_desc - Descriptor structure for MSI based interrupts | |
fc88419c JL |
169 | * @irq: The base interrupt number |
170 | * @nvec_used: The number of vectors used | |
171 | * @dev: Pointer to the device which uses this descriptor | |
172 | * @msg: The last set MSI message cached for reuse | |
0972fa57 | 173 | * @affinity: Optional pointer to a cpu affinity mask for this descriptor |
bf5e758f | 174 | * @sysfs_attr: Pointer to sysfs device attribute |
fc88419c | 175 | * |
d7cc609f LG |
176 | * @write_msi_msg: Callback that may be called when the MSI message |
177 | * address or data changes | |
178 | * @write_msi_msg_data: Data parameter for the callback. | |
179 | * | |
20c6d424 | 180 | * @msi_index: Index of the msi descriptor |
0f180958 | 181 | * @pci: PCI specific msi descriptor data |
efd42049 | 182 | * @data: Generic MSI descriptor data |
fc88419c | 183 | */ |
3b7d1921 | 184 | struct msi_desc { |
fc88419c | 185 | /* Shared device/bus type independent data */ |
fc88419c JL |
186 | unsigned int irq; |
187 | unsigned int nvec_used; | |
188 | struct device *dev; | |
189 | struct msi_msg msg; | |
bec04037 | 190 | struct irq_affinity_desc *affinity; |
aaebdf8d JG |
191 | #ifdef CONFIG_IRQ_MSI_IOMMU |
192 | const void *iommu_cookie; | |
193 | #endif | |
bf5e758f TG |
194 | #ifdef CONFIG_SYSFS |
195 | struct device_attribute *sysfs_attrs; | |
196 | #endif | |
3b7d1921 | 197 | |
d7cc609f LG |
198 | void (*write_msi_msg)(struct msi_desc *entry, void *data); |
199 | void *write_msi_msg_data; | |
200 | ||
20c6d424 | 201 | u16 msi_index; |
efd42049 TG |
202 | union { |
203 | struct pci_msi_desc pci; | |
204 | struct msi_desc_data data; | |
205 | }; | |
3b7d1921 EB |
206 | }; |
207 | ||
1046f71d TG |
208 | /* |
209 | * Filter values for the MSI descriptor iterators and accessor functions. | |
210 | */ | |
211 | enum msi_desc_filter { | |
212 | /* All descriptors */ | |
213 | MSI_DESC_ALL, | |
214 | /* Descriptors which have no interrupt associated */ | |
215 | MSI_DESC_NOTASSOCIATED, | |
216 | /* Descriptors which have an interrupt associated */ | |
217 | MSI_DESC_ASSOCIATED, | |
218 | }; | |
219 | ||
f1139f90 TG |
220 | |
221 | /** | |
222 | * struct msi_dev_domain - The internals of MSI domain info per device | |
223 | * @store: Xarray for storing MSI descriptor pointers | |
64258eaa | 224 | * @irqdomain: Pointer to a per device interrupt domain |
f1139f90 TG |
225 | */ |
226 | struct msi_dev_domain { | |
227 | struct xarray store; | |
64258eaa | 228 | struct irq_domain *domain; |
f1139f90 TG |
229 | }; |
230 | ||
013bd8e5 TG |
231 | /** |
232 | * msi_device_data - MSI per device data | |
233 | * @properties: MSI properties which are interesting to drivers | |
fc22e7db | 234 | * @platform_data: Platform-MSI specific data |
cd6cf065 | 235 | * @mutex: Mutex protecting the MSI descriptor store |
f1139f90 | 236 | * @__domains: Internal data for per device MSI domains |
cd6cf065 | 237 | * @__iter_idx: Index to search the next entry for iterators |
013bd8e5 TG |
238 | */ |
239 | struct msi_device_data { | |
240 | unsigned long properties; | |
fc22e7db | 241 | struct platform_msi_priv_data *platform_data; |
b5f687f9 | 242 | struct mutex mutex; |
f1139f90 | 243 | struct msi_dev_domain __domains[MSI_MAX_DEVICE_IRQDOMAINS]; |
cd6cf065 | 244 | unsigned long __iter_idx; |
013bd8e5 TG |
245 | }; |
246 | ||
247 | int msi_setup_device_data(struct device *dev); | |
248 | ||
b5f687f9 TG |
249 | void msi_lock_descs(struct device *dev); |
250 | void msi_unlock_descs(struct device *dev); | |
cf15f43a | 251 | |
94ff94cf TG |
252 | struct msi_desc *msi_domain_first_desc(struct device *dev, unsigned int domid, |
253 | enum msi_desc_filter filter); | |
1046f71d TG |
254 | |
255 | /** | |
94ff94cf TG |
256 | * msi_first_desc - Get the first MSI descriptor of the default irqdomain |
257 | * @dev: Device to operate on | |
258 | * @filter: Descriptor state filter | |
259 | * | |
260 | * Must be called with the MSI descriptor mutex held, i.e. msi_lock_descs() | |
261 | * must be invoked before the call. | |
262 | * | |
263 | * Return: Pointer to the first MSI descriptor matching the search | |
264 | * criteria, NULL if none found. | |
265 | */ | |
266 | static inline struct msi_desc *msi_first_desc(struct device *dev, | |
267 | enum msi_desc_filter filter) | |
268 | { | |
269 | return msi_domain_first_desc(dev, MSI_DEFAULT_DOMAIN, filter); | |
270 | } | |
271 | ||
272 | struct msi_desc *msi_next_desc(struct device *dev, unsigned int domid, | |
273 | enum msi_desc_filter filter); | |
274 | ||
275 | /** | |
276 | * msi_domain_for_each_desc - Iterate the MSI descriptors in a specific domain | |
277 | * | |
278 | * @desc: struct msi_desc pointer used as iterator | |
279 | * @dev: struct device pointer - device to iterate | |
280 | * @domid: The id of the interrupt domain which should be walked. | |
281 | * @filter: Filter for descriptor selection | |
282 | * | |
283 | * Notes: | |
284 | * - The loop must be protected with a msi_lock_descs()/msi_unlock_descs() | |
285 | * pair. | |
286 | * - It is safe to remove a retrieved MSI descriptor in the loop. | |
287 | */ | |
288 | #define msi_domain_for_each_desc(desc, dev, domid, filter) \ | |
289 | for ((desc) = msi_domain_first_desc((dev), (domid), (filter)); (desc); \ | |
290 | (desc) = msi_next_desc((dev), (domid), (filter))) | |
291 | ||
292 | /** | |
293 | * msi_for_each_desc - Iterate the MSI descriptors in the default irqdomain | |
1046f71d TG |
294 | * |
295 | * @desc: struct msi_desc pointer used as iterator | |
296 | * @dev: struct device pointer - device to iterate | |
297 | * @filter: Filter for descriptor selection | |
298 | * | |
299 | * Notes: | |
300 | * - The loop must be protected with a msi_lock_descs()/msi_unlock_descs() | |
301 | * pair. | |
302 | * - It is safe to remove a retrieved MSI descriptor in the loop. | |
303 | */ | |
94ff94cf TG |
304 | #define msi_for_each_desc(desc, dev, filter) \ |
305 | msi_domain_for_each_desc((desc), (dev), MSI_DEFAULT_DOMAIN, (filter)) | |
1046f71d | 306 | |
25a98bd4 | 307 | #define msi_desc_to_dev(desc) ((desc)->dev) |
d31eb342 | 308 | |
aaebdf8d JG |
309 | #ifdef CONFIG_IRQ_MSI_IOMMU |
310 | static inline const void *msi_desc_get_iommu_cookie(struct msi_desc *desc) | |
311 | { | |
312 | return desc->iommu_cookie; | |
313 | } | |
314 | ||
315 | static inline void msi_desc_set_iommu_cookie(struct msi_desc *desc, | |
316 | const void *iommu_cookie) | |
317 | { | |
318 | desc->iommu_cookie = iommu_cookie; | |
319 | } | |
320 | #else | |
321 | static inline const void *msi_desc_get_iommu_cookie(struct msi_desc *desc) | |
322 | { | |
323 | return NULL; | |
324 | } | |
325 | ||
326 | static inline void msi_desc_set_iommu_cookie(struct msi_desc *desc, | |
327 | const void *iommu_cookie) | |
328 | { | |
329 | } | |
330 | #endif | |
331 | ||
fc8ab388 TG |
332 | int msi_domain_insert_msi_desc(struct device *dev, unsigned int domid, |
333 | struct msi_desc *init_desc); | |
334 | /** | |
335 | * msi_insert_msi_desc - Allocate and initialize a MSI descriptor in the | |
336 | * default irqdomain and insert it at @init_desc->msi_index | |
337 | * @dev: Pointer to the device for which the descriptor is allocated | |
338 | * @init_desc: Pointer to an MSI descriptor to initialize the new descriptor | |
339 | * | |
340 | * Return: 0 on success or an appropriate failure code. | |
341 | */ | |
342 | static inline int msi_insert_msi_desc(struct device *dev, struct msi_desc *init_desc) | |
343 | { | |
344 | return msi_domain_insert_msi_desc(dev, MSI_DEFAULT_DOMAIN, init_desc); | |
345 | } | |
346 | ||
377712c5 TG |
347 | void msi_domain_free_msi_descs_range(struct device *dev, unsigned int domid, |
348 | unsigned int first, unsigned int last); | |
645474e2 TG |
349 | |
350 | /** | |
377712c5 TG |
351 | * msi_free_msi_descs_range - Free a range of MSI descriptors of a device |
352 | * in the default irqdomain | |
353 | * | |
354 | * @dev: Device for which to free the descriptors | |
355 | * @first: Index to start freeing from (inclusive) | |
356 | * @last: Last index to be freed (inclusive) | |
357 | */ | |
358 | static inline void msi_free_msi_descs_range(struct device *dev, unsigned int first, | |
359 | unsigned int last) | |
360 | { | |
361 | msi_domain_free_msi_descs_range(dev, MSI_DEFAULT_DOMAIN, first, last); | |
362 | } | |
363 | ||
364 | /** | |
365 | * msi_free_msi_descs - Free all MSI descriptors of a device in the default irqdomain | |
645474e2 TG |
366 | * @dev: Device to free the descriptors |
367 | */ | |
368 | static inline void msi_free_msi_descs(struct device *dev) | |
369 | { | |
2f2940d1 | 370 | msi_free_msi_descs_range(dev, 0, MSI_MAX_INDEX); |
645474e2 | 371 | } |
60290525 | 372 | |
3b7d1921 | 373 | /* |
077ee78e TG |
374 | * The arch hooks to setup up msi irqs. Default functions are implemented |
375 | * as weak symbols so that they /can/ be overriden by architecture specific | |
b227be0d | 376 | * code if needed. These hooks can only be enabled by the architecture. |
077ee78e TG |
377 | * |
378 | * If CONFIG_PCI_MSI_ARCH_FALLBACKS is not selected they are replaced by | |
379 | * stubs with warnings. | |
3b7d1921 | 380 | */ |
077ee78e | 381 | #ifdef CONFIG_PCI_MSI_ARCH_FALLBACKS |
f7feaca7 | 382 | int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc); |
3b7d1921 | 383 | void arch_teardown_msi_irq(unsigned int irq); |
2366d06e BH |
384 | int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type); |
385 | void arch_teardown_msi_irqs(struct pci_dev *dev); | |
335b4223 MH |
386 | #endif /* CONFIG_PCI_MSI_ARCH_FALLBACKS */ |
387 | ||
388 | /* | |
389 | * Xen uses non-default msi_domain_ops and hence needs a way to populate sysfs | |
390 | * entries of MSI IRQs. | |
391 | */ | |
392 | #if defined(CONFIG_PCI_XEN) || defined(CONFIG_PCI_MSI_ARCH_FALLBACKS) | |
bf5e758f TG |
393 | #ifdef CONFIG_SYSFS |
394 | int msi_device_populate_sysfs(struct device *dev); | |
395 | void msi_device_destroy_sysfs(struct device *dev); | |
396 | #else /* CONFIG_SYSFS */ | |
397 | static inline int msi_device_populate_sysfs(struct device *dev) { return 0; } | |
398 | static inline void msi_device_destroy_sysfs(struct device *dev) { } | |
399 | #endif /* !CONFIG_SYSFS */ | |
335b4223 | 400 | #endif /* CONFIG_PCI_XEN || CONFIG_PCI_MSI_ARCH_FALLBACKS */ |
077ee78e TG |
401 | |
402 | /* | |
ae72f315 TG |
403 | * The restore hook is still available even for fully irq domain based |
404 | * setups. Courtesy to XEN/X86. | |
077ee78e | 405 | */ |
ae72f315 | 406 | bool arch_restore_msi_irqs(struct pci_dev *dev); |
3b7d1921 | 407 | |
13e7accb | 408 | #ifdef CONFIG_GENERIC_MSI_IRQ |
d9109698 | 409 | |
aeeb5965 | 410 | #include <linux/irqhandler.h> |
d9109698 | 411 | |
f3cf8bb0 | 412 | struct irq_domain; |
552c494a | 413 | struct irq_domain_ops; |
f3cf8bb0 | 414 | struct irq_chip; |
9c78c1a8 | 415 | struct irq_fwspec; |
f3cf8bb0 | 416 | struct device_node; |
be5436c8 | 417 | struct fwnode_handle; |
f3cf8bb0 JL |
418 | struct msi_domain_info; |
419 | ||
420 | /** | |
421 | * struct msi_domain_ops - MSI interrupt domain callbacks | |
422 | * @get_hwirq: Retrieve the resulting hw irq number | |
423 | * @msi_init: Domain specific init function for MSI interrupts | |
424 | * @msi_free: Domain specific function to free a MSI interrupts | |
d9109698 | 425 | * @msi_prepare: Prepare the allocation of the interrupts in the domain |
8f986fd7 TG |
426 | * @prepare_desc: Optional function to prepare the allocated MSI descriptor |
427 | * in the domain | |
d9109698 | 428 | * @set_desc: Set the msi descriptor for an interrupt |
43e9e705 TG |
429 | * @domain_alloc_irqs: Optional function to override the default allocation |
430 | * function. | |
431 | * @domain_free_irqs: Optional function to override the default free | |
432 | * function. | |
f6d3486a TG |
433 | * @msi_post_free: Optional function which is invoked after freeing |
434 | * all interrupts. | |
9c78c1a8 TG |
435 | * @msi_translate: Optional translate callback to support the odd wire to |
436 | * MSI bridges, e.g. MBIGEN | |
d9109698 | 437 | * |
1dd2c6a0 TG |
438 | * @get_hwirq, @msi_init and @msi_free are callbacks used by the underlying |
439 | * irqdomain. | |
d9109698 | 440 | * |
8f986fd7 | 441 | * @msi_check, @msi_prepare, @prepare_desc and @set_desc are callbacks used by the |
f2480e7d | 442 | * msi_domain_alloc/free_irqs*() variants. |
43e9e705 TG |
443 | * |
444 | * @domain_alloc_irqs, @domain_free_irqs can be used to override the | |
445 | * default allocation/free functions (__msi_domain_alloc/free_irqs). This | |
446 | * is initially for a wrapper around XENs seperate MSI universe which can't | |
447 | * be wrapped into the regular irq domains concepts by mere mortals. This | |
448 | * allows to universally use msi_domain_alloc/free_irqs without having to | |
449 | * special case XEN all over the place. | |
f3cf8bb0 JL |
450 | */ |
451 | struct msi_domain_ops { | |
aeeb5965 JL |
452 | irq_hw_number_t (*get_hwirq)(struct msi_domain_info *info, |
453 | msi_alloc_info_t *arg); | |
f3cf8bb0 JL |
454 | int (*msi_init)(struct irq_domain *domain, |
455 | struct msi_domain_info *info, | |
456 | unsigned int virq, irq_hw_number_t hwirq, | |
aeeb5965 | 457 | msi_alloc_info_t *arg); |
f3cf8bb0 JL |
458 | void (*msi_free)(struct irq_domain *domain, |
459 | struct msi_domain_info *info, | |
460 | unsigned int virq); | |
d9109698 JL |
461 | int (*msi_prepare)(struct irq_domain *domain, |
462 | struct device *dev, int nvec, | |
463 | msi_alloc_info_t *arg); | |
8f986fd7 TG |
464 | void (*prepare_desc)(struct irq_domain *domain, msi_alloc_info_t *arg, |
465 | struct msi_desc *desc); | |
d9109698 JL |
466 | void (*set_desc)(msi_alloc_info_t *arg, |
467 | struct msi_desc *desc); | |
43e9e705 TG |
468 | int (*domain_alloc_irqs)(struct irq_domain *domain, |
469 | struct device *dev, int nvec); | |
470 | void (*domain_free_irqs)(struct irq_domain *domain, | |
471 | struct device *dev); | |
f6d3486a TG |
472 | void (*msi_post_free)(struct irq_domain *domain, |
473 | struct device *dev); | |
9c78c1a8 TG |
474 | int (*msi_translate)(struct irq_domain *domain, struct irq_fwspec *fwspec, |
475 | irq_hw_number_t *hwirq, unsigned int *type); | |
f3cf8bb0 JL |
476 | }; |
477 | ||
478 | /** | |
479 | * struct msi_domain_info - MSI interrupt domain data | |
aeeb5965 | 480 | * @flags: Flags to decribe features and capabilities |
22db089a | 481 | * @bus_token: The domain bus token |
61bf992f TG |
482 | * @hwsize: The hardware table size or the software index limit. |
483 | * If 0 then the size is considered unlimited and | |
484 | * gets initialized to the maximum software index limit | |
485 | * by the domain creation code. | |
aeeb5965 JL |
486 | * @ops: The callback data structure |
487 | * @chip: Optional: associated interrupt chip | |
488 | * @chip_data: Optional: associated interrupt chip data | |
489 | * @handler: Optional: associated interrupt flow handler | |
490 | * @handler_data: Optional: associated interrupt flow handler data | |
491 | * @handler_name: Optional: associated interrupt flow handler name | |
492 | * @data: Optional: domain specific data | |
f3cf8bb0 JL |
493 | */ |
494 | struct msi_domain_info { | |
22db089a AD |
495 | u32 flags; |
496 | enum irq_domain_bus_token bus_token; | |
61bf992f | 497 | unsigned int hwsize; |
22db089a AD |
498 | struct msi_domain_ops *ops; |
499 | struct irq_chip *chip; | |
500 | void *chip_data; | |
501 | irq_flow_handler_t handler; | |
502 | void *handler_data; | |
503 | const char *handler_name; | |
504 | void *data; | |
f3cf8bb0 JL |
505 | }; |
506 | ||
ebca4396 TG |
507 | /** |
508 | * struct msi_domain_template - Template for MSI device domains | |
509 | * @name: Storage for the resulting name. Filled in by the core. | |
510 | * @chip: Interrupt chip for this domain | |
511 | * @ops: MSI domain ops | |
512 | * @info: MSI domain info data | |
513 | */ | |
514 | struct msi_domain_template { | |
515 | char name[48]; | |
516 | struct irq_chip chip; | |
517 | struct msi_domain_ops ops; | |
518 | struct msi_domain_info info; | |
519 | }; | |
520 | ||
2d958b02 TG |
521 | /* |
522 | * Flags for msi_domain_info | |
523 | * | |
524 | * Bit 0-15: Generic MSI functionality which is not subject to restriction | |
525 | * by parent domains | |
526 | * | |
527 | * Bit 16-31: Functionality which depends on the underlying parent domain and | |
528 | * can be masked out by msi_parent_ops::init_dev_msi_info() when | |
529 | * a device MSI domain is initialized. | |
530 | */ | |
aeeb5965 JL |
531 | enum { |
532 | /* | |
533 | * Init non implemented ops callbacks with default MSI domain | |
534 | * callbacks. | |
535 | */ | |
536 | MSI_FLAG_USE_DEF_DOM_OPS = (1 << 0), | |
537 | /* | |
538 | * Init non implemented chip callbacks with default MSI chip | |
539 | * callbacks. | |
540 | */ | |
541 | MSI_FLAG_USE_DEF_CHIP_OPS = (1 << 1), | |
f3b0946d | 542 | /* Needs early activate, required for PCI */ |
2d958b02 | 543 | MSI_FLAG_ACTIVATE_EARLY = (1 << 2), |
22d0b12f TG |
544 | /* |
545 | * Must reactivate when irq is started even when | |
546 | * MSI_FLAG_ACTIVATE_EARLY has been set. | |
547 | */ | |
2d958b02 | 548 | MSI_FLAG_MUST_REACTIVATE = (1 << 3), |
013bd8e5 | 549 | /* Populate sysfs on alloc() and destroy it on free() */ |
2d958b02 | 550 | MSI_FLAG_DEV_SYSFS = (1 << 4), |
645474e2 | 551 | /* Allocate simple MSI descriptors */ |
2d958b02 | 552 | MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS = (1 << 5), |
645474e2 | 553 | /* Free MSI descriptors */ |
2d958b02 | 554 | MSI_FLAG_FREE_MSI_DESCS = (1 << 6), |
9d1c58c8 TG |
555 | /* Use dev->fwnode for MSI device domain creation */ |
556 | MSI_FLAG_USE_DEV_FWNODE = (1 << 7), | |
9bbe13a5 TG |
557 | /* Set parent->dev into domain->pm_dev on device domain creation */ |
558 | MSI_FLAG_PARENT_PM_DEV = (1 << 8), | |
2d958b02 TG |
559 | |
560 | /* Mask for the generic functionality */ | |
561 | MSI_GENERIC_FLAGS_MASK = GENMASK(15, 0), | |
562 | ||
563 | /* Mask for the domain specific functionality */ | |
564 | MSI_DOMAIN_FLAGS_MASK = GENMASK(31, 16), | |
565 | ||
566 | /* Support multiple PCI MSI interrupts */ | |
567 | MSI_FLAG_MULTI_PCI_MSI = (1 << 16), | |
568 | /* Support PCI MSIX interrupts */ | |
569 | MSI_FLAG_PCI_MSIX = (1 << 17), | |
570 | /* Is level-triggered capable, using two messages */ | |
571 | MSI_FLAG_LEVEL_CAPABLE = (1 << 18), | |
572 | /* MSI-X entries must be contiguous */ | |
573 | MSI_FLAG_MSIX_CONTIGUOUS = (1 << 19), | |
b834e3c0 TG |
574 | /* PCI/MSI-X vectors can be dynamically allocated/freed post MSI-X enable */ |
575 | MSI_FLAG_PCI_MSIX_ALLOC_DYN = (1 << 20), | |
e23d4192 TG |
576 | /* Support for PCI/IMS */ |
577 | MSI_FLAG_PCI_IMS = (1 << 21), | |
aeeb5965 JL |
578 | }; |
579 | ||
b78780d9 TG |
580 | /** |
581 | * struct msi_parent_ops - MSI parent domain callbacks and configuration info | |
582 | * | |
583 | * @supported_flags: Required: The supported MSI flags of the parent domain | |
ac81e94a TG |
584 | * @required_flags: Optional: The required MSI flags of the parent MSI domain |
585 | * @bus_select_token: Optional: The bus token of the real parent domain for | |
586 | * irq_domain::select() | |
587 | * @bus_select_mask: Optional: A mask of supported BUS_DOMAINs for | |
588 | * irq_domain::select() | |
b78780d9 TG |
589 | * @prefix: Optional: Prefix for the domain and chip name |
590 | * @init_dev_msi_info: Required: Callback for MSI parent domains to setup parent | |
591 | * domain specific domain flags, domain ops and interrupt chip | |
592 | * callbacks when a per device domain is created. | |
593 | */ | |
594 | struct msi_parent_ops { | |
595 | u32 supported_flags; | |
ac81e94a TG |
596 | u32 required_flags; |
597 | u32 bus_select_token; | |
598 | u32 bus_select_mask; | |
b78780d9 TG |
599 | const char *prefix; |
600 | bool (*init_dev_msi_info)(struct device *dev, struct irq_domain *domain, | |
601 | struct irq_domain *msi_parent_domain, | |
602 | struct msi_domain_info *msi_child_info); | |
603 | }; | |
604 | ||
605 | bool msi_parent_init_dev_msi_info(struct device *dev, struct irq_domain *domain, | |
606 | struct irq_domain *msi_parent_domain, | |
607 | struct msi_domain_info *msi_child_info); | |
608 | ||
f3cf8bb0 JL |
609 | int msi_domain_set_affinity(struct irq_data *data, const struct cpumask *mask, |
610 | bool force); | |
611 | ||
be5436c8 | 612 | struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode, |
f3cf8bb0 JL |
613 | struct msi_domain_info *info, |
614 | struct irq_domain *parent); | |
4cd5f440 | 615 | |
27a6dea3 TG |
616 | bool msi_create_device_irq_domain(struct device *dev, unsigned int domid, |
617 | const struct msi_domain_template *template, | |
618 | unsigned int hwsize, void *domain_data, | |
619 | void *chip_data); | |
620 | void msi_remove_device_irq_domain(struct device *dev, unsigned int domid); | |
621 | ||
26e91b75 TG |
622 | bool msi_match_device_irq_domain(struct device *dev, unsigned int domid, |
623 | enum irq_domain_bus_token bus_token); | |
624 | ||
f2480e7d TG |
625 | int msi_domain_alloc_irqs_range_locked(struct device *dev, unsigned int domid, |
626 | unsigned int first, unsigned int last); | |
627 | int msi_domain_alloc_irqs_range(struct device *dev, unsigned int domid, | |
628 | unsigned int first, unsigned int last); | |
629 | int msi_domain_alloc_irqs_all_locked(struct device *dev, unsigned int domid, int nirqs); | |
630 | ||
3d393b21 TG |
631 | struct msi_map msi_domain_alloc_irq_at(struct device *dev, unsigned int domid, unsigned int index, |
632 | const struct irq_affinity_desc *affdesc, | |
633 | union msi_instance_cookie *cookie); | |
f2480e7d | 634 | |
4cd5f440 TG |
635 | void msi_domain_free_irqs_range_locked(struct device *dev, unsigned int domid, |
636 | unsigned int first, unsigned int last); | |
637 | void msi_domain_free_irqs_range(struct device *dev, unsigned int domid, | |
638 | unsigned int first, unsigned int last); | |
4cd5f440 TG |
639 | void msi_domain_free_irqs_all_locked(struct device *dev, unsigned int domid); |
640 | void msi_domain_free_irqs_all(struct device *dev, unsigned int domid); | |
641 | ||
f3cf8bb0 JL |
642 | struct msi_domain_info *msi_get_domain_info(struct irq_domain *domain); |
643 | ||
be5436c8 | 644 | struct irq_domain *platform_msi_create_irq_domain(struct fwnode_handle *fwnode, |
c09fcc4b MZ |
645 | struct msi_domain_info *info, |
646 | struct irq_domain *parent); | |
b2eba39b MZ |
647 | |
648 | /* When an MSI domain is used as an intermediate domain */ | |
649 | int msi_domain_prepare_irqs(struct irq_domain *domain, struct device *dev, | |
650 | int nvec, msi_alloc_info_t *args); | |
2145ac93 MZ |
651 | int msi_domain_populate_irqs(struct irq_domain *domain, struct device *dev, |
652 | int virq, int nvec, msi_alloc_info_t *args); | |
0fb7fb71 TG |
653 | void msi_domain_depopulate_descs(struct device *dev, int virq, int nvec); |
654 | ||
552c494a | 655 | struct irq_domain * |
1f83515b MZ |
656 | __platform_msi_create_device_domain(struct device *dev, |
657 | unsigned int nvec, | |
658 | bool is_tree, | |
659 | irq_write_msi_msg_t write_msi_msg, | |
660 | const struct irq_domain_ops *ops, | |
661 | void *host_data); | |
662 | ||
663 | #define platform_msi_create_device_domain(dev, nvec, write, ops, data) \ | |
664 | __platform_msi_create_device_domain(dev, nvec, false, write, ops, data) | |
665 | #define platform_msi_create_device_tree_domain(dev, nvec, write, ops, data) \ | |
666 | __platform_msi_create_device_domain(dev, nvec, true, write, ops, data) | |
667 | ||
9835cec6 TG |
668 | int platform_msi_device_domain_alloc(struct irq_domain *domain, unsigned int virq, |
669 | unsigned int nr_irqs); | |
670 | void platform_msi_device_domain_free(struct irq_domain *domain, unsigned int virq, | |
671 | unsigned int nvec); | |
552c494a | 672 | void *platform_msi_get_host_data(struct irq_domain *domain); |
c88f9110 TG |
673 | /* Per device platform MSI */ |
674 | int platform_device_msi_init_and_alloc_irqs(struct device *dev, unsigned int nvec, | |
675 | irq_write_msi_msg_t write_msi_msg); | |
676 | void platform_device_msi_free_irqs_all(struct device *dev); | |
17cde5e6 JG |
677 | |
678 | bool msi_device_has_isolated_msi(struct device *dev); | |
679 | #else /* CONFIG_GENERIC_MSI_IRQ */ | |
680 | static inline bool msi_device_has_isolated_msi(struct device *dev) | |
681 | { | |
682 | /* | |
683 | * Arguably if the platform does not enable MSI support then it has | |
684 | * "isolated MSI", as an interrupt controller that cannot receive MSIs | |
bf210f79 JG |
685 | * is inherently isolated by our definition. The default definition for |
686 | * arch_is_isolated_msi() is conservative and returns false anyhow. | |
17cde5e6 | 687 | */ |
bf210f79 | 688 | return arch_is_isolated_msi(); |
17cde5e6 | 689 | } |
13e7accb | 690 | #endif /* CONFIG_GENERIC_MSI_IRQ */ |
f3cf8bb0 | 691 | |
a474d3fb TG |
692 | /* PCI specific interfaces */ |
693 | #ifdef CONFIG_PCI_MSI | |
694 | struct pci_dev *msi_desc_to_pci_dev(struct msi_desc *desc); | |
695 | void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg); | |
696 | void __pci_read_msi_msg(struct msi_desc *entry, struct msi_msg *msg); | |
697 | void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg); | |
698 | void pci_msi_mask_irq(struct irq_data *data); | |
699 | void pci_msi_unmask_irq(struct irq_data *data); | |
be5436c8 | 700 | struct irq_domain *pci_msi_create_irq_domain(struct fwnode_handle *fwnode, |
3878eaef JL |
701 | struct msi_domain_info *info, |
702 | struct irq_domain *parent); | |
b6eec9b7 | 703 | u32 pci_msi_domain_get_msi_rid(struct irq_domain *domain, struct pci_dev *pdev); |
54fa97ee | 704 | struct irq_domain *pci_msi_get_device_domain(struct pci_dev *pdev); |
a474d3fb | 705 | #else /* CONFIG_PCI_MSI */ |
54fa97ee MZ |
706 | static inline struct irq_domain *pci_msi_get_device_domain(struct pci_dev *pdev) |
707 | { | |
708 | return NULL; | |
709 | } | |
a474d3fb TG |
710 | static inline void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg) { } |
711 | #endif /* !CONFIG_PCI_MSI */ | |
3878eaef | 712 | |
3b7d1921 | 713 | #endif /* LINUX_MSI_H */ |