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