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