xref: /openbmc/linux/include/linux/msi.h (revision 4d75f5c664195b970e1cd2fd25b65b5eff257a0a)
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.h>
23 #include <linux/msi_api.h>
24 #include <linux/xarray.h>
25 #include <linux/mutex.h>
26 #include <linux/list.h>
27 #include <linux/irq.h>
28 #include <linux/bits.h>
29 
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
50 
51 #ifndef arch_is_isolated_msi
52 #define arch_is_isolated_msi() false
53 #endif
54 
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  */
65 struct msi_msg {
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 	};
78 };
79 
80 extern int pci_msi_ignore_mask;
81 /* Helper functions */
82 struct msi_desc;
83 struct pci_dev;
84 struct platform_msi_priv_data;
85 struct device_attribute;
86 struct irq_domain;
87 struct irq_affinity_desc;
88 
89 void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
90 #ifdef CONFIG_GENERIC_MSI_IRQ
91 void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg);
92 #else
get_cached_msi_msg(unsigned int irq,struct msi_msg * msg)93 static inline void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg) { }
94 #endif
95 
96 typedef void (*irq_write_msi_msg_t)(struct msi_desc *desc,
97 				    struct msi_msg *msg);
98 
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
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;
125 		unsigned default_irq;
126 	} msi_attrib;
127 	union {
128 		u8	mask_pos;
129 		void __iomem *mask_base;
130 	};
131 };
132 
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 
165 #define MSI_MAX_INDEX		((unsigned int)USHRT_MAX)
166 
167 /**
168  * struct msi_desc - Descriptor structure for MSI based interrupts
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
173  * @affinity:	Optional pointer to a cpu affinity mask for this descriptor
174  * @iommu_msi_iova: Optional shifted IOVA from the IOMMU to override the msi_addr.
175  *                  Only used if iommu_msi_shift != 0
176  * @iommu_msi_shift: Indicates how many bits of the original address should be
177  *                   preserved when using iommu_msi_iova.
178  * @sysfs_attr:	Pointer to sysfs device attribute
179  *
180  * @write_msi_msg:	Callback that may be called when the MSI message
181  *			address or data changes
182  * @write_msi_msg_data:	Data parameter for the callback.
183  *
184  * @msi_index:	Index of the msi descriptor
185  * @pci:	PCI specific msi descriptor data
186  * @data:	Generic MSI descriptor data
187  */
188 struct msi_desc {
189 	/* Shared device/bus type independent data */
190 	unsigned int			irq;
191 	unsigned int			nvec_used;
192 	struct device			*dev;
193 	struct msi_msg			msg;
194 	struct irq_affinity_desc	*affinity;
195 #ifdef CONFIG_IRQ_MSI_IOMMU
196 	u64				iommu_msi_iova : 58;
197 	u64				iommu_msi_shift : 6;
198 #endif
199 #ifdef CONFIG_SYSFS
200 	struct device_attribute		*sysfs_attrs;
201 #endif
202 
203 	void (*write_msi_msg)(struct msi_desc *entry, void *data);
204 	void *write_msi_msg_data;
205 
206 	u16				msi_index;
207 	union {
208 		struct pci_msi_desc	pci;
209 		struct msi_desc_data	data;
210 	};
211 };
212 
213 /*
214  * Filter values for the MSI descriptor iterators and accessor functions.
215  */
216 enum msi_desc_filter {
217 	/* All descriptors */
218 	MSI_DESC_ALL,
219 	/* Descriptors which have no interrupt associated */
220 	MSI_DESC_NOTASSOCIATED,
221 	/* Descriptors which have an interrupt associated */
222 	MSI_DESC_ASSOCIATED,
223 };
224 
225 
226 /**
227  * struct msi_dev_domain - The internals of MSI domain info per device
228  * @store:		Xarray for storing MSI descriptor pointers
229  * @irqdomain:		Pointer to a per device interrupt domain
230  */
231 struct msi_dev_domain {
232 	struct xarray		store;
233 	struct irq_domain	*domain;
234 };
235 
236 /**
237  * msi_device_data - MSI per device data
238  * @properties:		MSI properties which are interesting to drivers
239  * @platform_data:	Platform-MSI specific data
240  * @mutex:		Mutex protecting the MSI descriptor store
241  * @__domains:		Internal data for per device MSI domains
242  * @__iter_idx:		Index to search the next entry for iterators
243  */
244 struct msi_device_data {
245 	unsigned long			properties;
246 	struct platform_msi_priv_data	*platform_data;
247 	struct mutex			mutex;
248 	struct msi_dev_domain		__domains[MSI_MAX_DEVICE_IRQDOMAINS];
249 	unsigned long			__iter_idx;
250 };
251 
252 int msi_setup_device_data(struct device *dev);
253 
254 void msi_lock_descs(struct device *dev);
255 void msi_unlock_descs(struct device *dev);
256 
257 struct msi_desc *msi_domain_first_desc(struct device *dev, unsigned int domid,
258 				       enum msi_desc_filter filter);
259 
260 /**
261  * msi_first_desc - Get the first MSI descriptor of the default irqdomain
262  * @dev:	Device to operate on
263  * @filter:	Descriptor state filter
264  *
265  * Must be called with the MSI descriptor mutex held, i.e. msi_lock_descs()
266  * must be invoked before the call.
267  *
268  * Return: Pointer to the first MSI descriptor matching the search
269  *	   criteria, NULL if none found.
270  */
msi_first_desc(struct device * dev,enum msi_desc_filter filter)271 static inline struct msi_desc *msi_first_desc(struct device *dev,
272 					      enum msi_desc_filter filter)
273 {
274 	return msi_domain_first_desc(dev, MSI_DEFAULT_DOMAIN, filter);
275 }
276 
277 struct msi_desc *msi_next_desc(struct device *dev, unsigned int domid,
278 			       enum msi_desc_filter filter);
279 
280 /**
281  * msi_domain_for_each_desc - Iterate the MSI descriptors in a specific domain
282  *
283  * @desc:	struct msi_desc pointer used as iterator
284  * @dev:	struct device pointer - device to iterate
285  * @domid:	The id of the interrupt domain which should be walked.
286  * @filter:	Filter for descriptor selection
287  *
288  * Notes:
289  *  - The loop must be protected with a msi_lock_descs()/msi_unlock_descs()
290  *    pair.
291  *  - It is safe to remove a retrieved MSI descriptor in the loop.
292  */
293 #define msi_domain_for_each_desc(desc, dev, domid, filter)			\
294 	for ((desc) = msi_domain_first_desc((dev), (domid), (filter)); (desc);	\
295 	     (desc) = msi_next_desc((dev), (domid), (filter)))
296 
297 /**
298  * msi_for_each_desc - Iterate the MSI descriptors in the default irqdomain
299  *
300  * @desc:	struct msi_desc pointer used as iterator
301  * @dev:	struct device pointer - device to iterate
302  * @filter:	Filter for descriptor selection
303  *
304  * Notes:
305  *  - The loop must be protected with a msi_lock_descs()/msi_unlock_descs()
306  *    pair.
307  *  - It is safe to remove a retrieved MSI descriptor in the loop.
308  */
309 #define msi_for_each_desc(desc, dev, filter)					\
310 	msi_domain_for_each_desc((desc), (dev), MSI_DEFAULT_DOMAIN, (filter))
311 
312 #define msi_desc_to_dev(desc)		((desc)->dev)
313 
msi_desc_set_iommu_msi_iova(struct msi_desc * desc,u64 msi_iova,unsigned int msi_shift)314 static inline void msi_desc_set_iommu_msi_iova(struct msi_desc *desc, u64 msi_iova,
315 					       unsigned int msi_shift)
316 {
317 #ifdef CONFIG_IRQ_MSI_IOMMU
318 	desc->iommu_msi_iova = msi_iova >> msi_shift;
319 	desc->iommu_msi_shift = msi_shift;
320 #endif
321 }
322 
323 int msi_domain_insert_msi_desc(struct device *dev, unsigned int domid,
324 			       struct msi_desc *init_desc);
325 /**
326  * msi_insert_msi_desc - Allocate and initialize a MSI descriptor in the
327  *			 default irqdomain and insert it at @init_desc->msi_index
328  * @dev:	Pointer to the device for which the descriptor is allocated
329  * @init_desc:	Pointer to an MSI descriptor to initialize the new descriptor
330  *
331  * Return: 0 on success or an appropriate failure code.
332  */
msi_insert_msi_desc(struct device * dev,struct msi_desc * init_desc)333 static inline int msi_insert_msi_desc(struct device *dev, struct msi_desc *init_desc)
334 {
335 	return msi_domain_insert_msi_desc(dev, MSI_DEFAULT_DOMAIN, init_desc);
336 }
337 
338 void msi_domain_free_msi_descs_range(struct device *dev, unsigned int domid,
339 				     unsigned int first, unsigned int last);
340 
341 /**
342  * msi_free_msi_descs_range - Free a range of MSI descriptors of a device
343  *			      in the default irqdomain
344  *
345  * @dev:	Device for which to free the descriptors
346  * @first:	Index to start freeing from (inclusive)
347  * @last:	Last index to be freed (inclusive)
348  */
msi_free_msi_descs_range(struct device * dev,unsigned int first,unsigned int last)349 static inline void msi_free_msi_descs_range(struct device *dev, unsigned int first,
350 					    unsigned int last)
351 {
352 	msi_domain_free_msi_descs_range(dev, MSI_DEFAULT_DOMAIN, first, last);
353 }
354 
355 /**
356  * msi_free_msi_descs - Free all MSI descriptors of a device in the default irqdomain
357  * @dev:	Device to free the descriptors
358  */
msi_free_msi_descs(struct device * dev)359 static inline void msi_free_msi_descs(struct device *dev)
360 {
361 	msi_free_msi_descs_range(dev, 0, MSI_MAX_INDEX);
362 }
363 
364 /*
365  * The arch hooks to setup up msi irqs. Default functions are implemented
366  * as weak symbols so that they /can/ be overriden by architecture specific
367  * code if needed. These hooks can only be enabled by the architecture.
368  *
369  * If CONFIG_PCI_MSI_ARCH_FALLBACKS is not selected they are replaced by
370  * stubs with warnings.
371  */
372 #ifdef CONFIG_PCI_MSI_ARCH_FALLBACKS
373 int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc);
374 void arch_teardown_msi_irq(unsigned int irq);
375 int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type);
376 void arch_teardown_msi_irqs(struct pci_dev *dev);
377 #endif /* CONFIG_PCI_MSI_ARCH_FALLBACKS */
378 
379 /*
380  * Xen uses non-default msi_domain_ops and hence needs a way to populate sysfs
381  * entries of MSI IRQs.
382  */
383 #if defined(CONFIG_PCI_XEN) || defined(CONFIG_PCI_MSI_ARCH_FALLBACKS)
384 #ifdef CONFIG_SYSFS
385 int msi_device_populate_sysfs(struct device *dev);
386 void msi_device_destroy_sysfs(struct device *dev);
387 #else /* CONFIG_SYSFS */
msi_device_populate_sysfs(struct device * dev)388 static inline int msi_device_populate_sysfs(struct device *dev) { return 0; }
msi_device_destroy_sysfs(struct device * dev)389 static inline void msi_device_destroy_sysfs(struct device *dev) { }
390 #endif /* !CONFIG_SYSFS */
391 #endif /* CONFIG_PCI_XEN || CONFIG_PCI_MSI_ARCH_FALLBACKS */
392 
393 /*
394  * The restore hook is still available even for fully irq domain based
395  * setups. Courtesy to XEN/X86.
396  */
397 bool arch_restore_msi_irqs(struct pci_dev *dev);
398 
399 #ifdef CONFIG_GENERIC_MSI_IRQ
400 
401 #include <linux/irqhandler.h>
402 
403 struct irq_domain;
404 struct irq_domain_ops;
405 struct irq_chip;
406 struct device_node;
407 struct fwnode_handle;
408 struct msi_domain_info;
409 
410 /**
411  * struct msi_domain_ops - MSI interrupt domain callbacks
412  * @get_hwirq:		Retrieve the resulting hw irq number
413  * @msi_init:		Domain specific init function for MSI interrupts
414  * @msi_free:		Domain specific function to free a MSI interrupts
415  * @msi_prepare:	Prepare the allocation of the interrupts in the domain
416  * @prepare_desc:	Optional function to prepare the allocated MSI descriptor
417  *			in the domain
418  * @set_desc:		Set the msi descriptor for an interrupt
419  * @domain_alloc_irqs:	Optional function to override the default allocation
420  *			function.
421  * @domain_free_irqs:	Optional function to override the default free
422  *			function.
423  * @msi_post_free:	Optional function which is invoked after freeing
424  *			all interrupts.
425  *
426  * @get_hwirq, @msi_init and @msi_free are callbacks used by the underlying
427  * irqdomain.
428  *
429  * @msi_check, @msi_prepare, @prepare_desc and @set_desc are callbacks used by the
430  * msi_domain_alloc/free_irqs*() variants.
431  *
432  * @domain_alloc_irqs, @domain_free_irqs can be used to override the
433  * default allocation/free functions (__msi_domain_alloc/free_irqs). This
434  * is initially for a wrapper around XENs seperate MSI universe which can't
435  * be wrapped into the regular irq domains concepts by mere mortals.  This
436  * allows to universally use msi_domain_alloc/free_irqs without having to
437  * special case XEN all over the place.
438  */
439 struct msi_domain_ops {
440 	irq_hw_number_t	(*get_hwirq)(struct msi_domain_info *info,
441 				     msi_alloc_info_t *arg);
442 	int		(*msi_init)(struct irq_domain *domain,
443 				    struct msi_domain_info *info,
444 				    unsigned int virq, irq_hw_number_t hwirq,
445 				    msi_alloc_info_t *arg);
446 	void		(*msi_free)(struct irq_domain *domain,
447 				    struct msi_domain_info *info,
448 				    unsigned int virq);
449 	int		(*msi_prepare)(struct irq_domain *domain,
450 				       struct device *dev, int nvec,
451 				       msi_alloc_info_t *arg);
452 	void		(*prepare_desc)(struct irq_domain *domain, msi_alloc_info_t *arg,
453 					struct msi_desc *desc);
454 	void		(*set_desc)(msi_alloc_info_t *arg,
455 				    struct msi_desc *desc);
456 	int		(*domain_alloc_irqs)(struct irq_domain *domain,
457 					     struct device *dev, int nvec);
458 	void		(*domain_free_irqs)(struct irq_domain *domain,
459 					    struct device *dev);
460 	void		(*msi_post_free)(struct irq_domain *domain,
461 					 struct device *dev);
462 };
463 
464 /**
465  * struct msi_domain_info - MSI interrupt domain data
466  * @flags:		Flags to decribe features and capabilities
467  * @bus_token:		The domain bus token
468  * @hwsize:		The hardware table size or the software index limit.
469  *			If 0 then the size is considered unlimited and
470  *			gets initialized to the maximum software index limit
471  *			by the domain creation code.
472  * @ops:		The callback data structure
473  * @chip:		Optional: associated interrupt chip
474  * @chip_data:		Optional: associated interrupt chip data
475  * @handler:		Optional: associated interrupt flow handler
476  * @handler_data:	Optional: associated interrupt flow handler data
477  * @handler_name:	Optional: associated interrupt flow handler name
478  * @data:		Optional: domain specific data
479  */
480 struct msi_domain_info {
481 	u32				flags;
482 	enum irq_domain_bus_token	bus_token;
483 	unsigned int			hwsize;
484 	struct msi_domain_ops		*ops;
485 	struct irq_chip			*chip;
486 	void				*chip_data;
487 	irq_flow_handler_t		handler;
488 	void				*handler_data;
489 	const char			*handler_name;
490 	void				*data;
491 };
492 
493 /**
494  * struct msi_domain_template - Template for MSI device domains
495  * @name:	Storage for the resulting name. Filled in by the core.
496  * @chip:	Interrupt chip for this domain
497  * @ops:	MSI domain ops
498  * @info:	MSI domain info data
499  */
500 struct msi_domain_template {
501 	char			name[48];
502 	struct irq_chip		chip;
503 	struct msi_domain_ops	ops;
504 	struct msi_domain_info	info;
505 };
506 
507 /*
508  * Flags for msi_domain_info
509  *
510  * Bit 0-15:	Generic MSI functionality which is not subject to restriction
511  *		by parent domains
512  *
513  * Bit 16-31:	Functionality which depends on the underlying parent domain and
514  *		can be masked out by msi_parent_ops::init_dev_msi_info() when
515  *		a device MSI domain is initialized.
516  */
517 enum {
518 	/*
519 	 * Init non implemented ops callbacks with default MSI domain
520 	 * callbacks.
521 	 */
522 	MSI_FLAG_USE_DEF_DOM_OPS	= (1 << 0),
523 	/*
524 	 * Init non implemented chip callbacks with default MSI chip
525 	 * callbacks.
526 	 */
527 	MSI_FLAG_USE_DEF_CHIP_OPS	= (1 << 1),
528 	/* Needs early activate, required for PCI */
529 	MSI_FLAG_ACTIVATE_EARLY		= (1 << 2),
530 	/*
531 	 * Must reactivate when irq is started even when
532 	 * MSI_FLAG_ACTIVATE_EARLY has been set.
533 	 */
534 	MSI_FLAG_MUST_REACTIVATE	= (1 << 3),
535 	/* Populate sysfs on alloc() and destroy it on free() */
536 	MSI_FLAG_DEV_SYSFS		= (1 << 4),
537 	/* Allocate simple MSI descriptors */
538 	MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS	= (1 << 5),
539 	/* Free MSI descriptors */
540 	MSI_FLAG_FREE_MSI_DESCS		= (1 << 6),
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 	/* Support for PCI/IMS */
559 	MSI_FLAG_PCI_IMS		= (1 << 21),
560 };
561 
562 /**
563  * struct msi_parent_ops - MSI parent domain callbacks and configuration info
564  *
565  * @supported_flags:	Required: The supported MSI flags of the parent domain
566  * @prefix:		Optional: Prefix for the domain and chip name
567  * @init_dev_msi_info:	Required: Callback for MSI parent domains to setup parent
568  *			domain specific domain flags, domain ops and interrupt chip
569  *			callbacks when a per device domain is created.
570  */
571 struct msi_parent_ops {
572 	u32		supported_flags;
573 	const char	*prefix;
574 	bool		(*init_dev_msi_info)(struct device *dev, struct irq_domain *domain,
575 					     struct irq_domain *msi_parent_domain,
576 					     struct msi_domain_info *msi_child_info);
577 };
578 
579 bool msi_parent_init_dev_msi_info(struct device *dev, struct irq_domain *domain,
580 				  struct irq_domain *msi_parent_domain,
581 				  struct msi_domain_info *msi_child_info);
582 
583 int msi_domain_set_affinity(struct irq_data *data, const struct cpumask *mask,
584 			    bool force);
585 
586 struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode,
587 					 struct msi_domain_info *info,
588 					 struct irq_domain *parent);
589 
590 bool msi_create_device_irq_domain(struct device *dev, unsigned int domid,
591 				  const struct msi_domain_template *template,
592 				  unsigned int hwsize, void *domain_data,
593 				  void *chip_data);
594 void msi_remove_device_irq_domain(struct device *dev, unsigned int domid);
595 
596 bool msi_match_device_irq_domain(struct device *dev, unsigned int domid,
597 				 enum irq_domain_bus_token bus_token);
598 
599 int msi_domain_alloc_irqs_range_locked(struct device *dev, unsigned int domid,
600 				       unsigned int first, unsigned int last);
601 int msi_domain_alloc_irqs_range(struct device *dev, unsigned int domid,
602 				unsigned int first, unsigned int last);
603 int msi_domain_alloc_irqs_all_locked(struct device *dev, unsigned int domid, int nirqs);
604 
605 struct msi_map msi_domain_alloc_irq_at(struct device *dev, unsigned int domid, unsigned int index,
606 				       const struct irq_affinity_desc *affdesc,
607 				       union msi_instance_cookie *cookie);
608 
609 void msi_domain_free_irqs_range_locked(struct device *dev, unsigned int domid,
610 				       unsigned int first, unsigned int last);
611 void msi_domain_free_irqs_range(struct device *dev, unsigned int domid,
612 				unsigned int first, unsigned int last);
613 void msi_domain_free_irqs_all_locked(struct device *dev, unsigned int domid);
614 void msi_domain_free_irqs_all(struct device *dev, unsigned int domid);
615 
616 struct msi_domain_info *msi_get_domain_info(struct irq_domain *domain);
617 
618 struct irq_domain *platform_msi_create_irq_domain(struct fwnode_handle *fwnode,
619 						  struct msi_domain_info *info,
620 						  struct irq_domain *parent);
621 int platform_msi_domain_alloc_irqs(struct device *dev, unsigned int nvec,
622 				   irq_write_msi_msg_t write_msi_msg);
623 void platform_msi_domain_free_irqs(struct device *dev);
624 
625 /* When an MSI domain is used as an intermediate domain */
626 int msi_domain_prepare_irqs(struct irq_domain *domain, struct device *dev,
627 			    int nvec, msi_alloc_info_t *args);
628 int msi_domain_populate_irqs(struct irq_domain *domain, struct device *dev,
629 			     int virq, int nvec, msi_alloc_info_t *args);
630 void msi_domain_depopulate_descs(struct device *dev, int virq, int nvec);
631 
632 struct irq_domain *
633 __platform_msi_create_device_domain(struct device *dev,
634 				    unsigned int nvec,
635 				    bool is_tree,
636 				    irq_write_msi_msg_t write_msi_msg,
637 				    const struct irq_domain_ops *ops,
638 				    void *host_data);
639 
640 #define platform_msi_create_device_domain(dev, nvec, write, ops, data)	\
641 	__platform_msi_create_device_domain(dev, nvec, false, write, ops, data)
642 #define platform_msi_create_device_tree_domain(dev, nvec, write, ops, data) \
643 	__platform_msi_create_device_domain(dev, nvec, true, write, ops, data)
644 
645 int platform_msi_device_domain_alloc(struct irq_domain *domain, unsigned int virq,
646 				     unsigned int nr_irqs);
647 void platform_msi_device_domain_free(struct irq_domain *domain, unsigned int virq,
648 				     unsigned int nvec);
649 void *platform_msi_get_host_data(struct irq_domain *domain);
650 
651 bool msi_device_has_isolated_msi(struct device *dev);
652 #else /* CONFIG_GENERIC_MSI_IRQ */
msi_device_has_isolated_msi(struct device * dev)653 static inline bool msi_device_has_isolated_msi(struct device *dev)
654 {
655 	/*
656 	 * Arguably if the platform does not enable MSI support then it has
657 	 * "isolated MSI", as an interrupt controller that cannot receive MSIs
658 	 * is inherently isolated by our definition. The default definition for
659 	 * arch_is_isolated_msi() is conservative and returns false anyhow.
660 	 */
661 	return arch_is_isolated_msi();
662 }
663 #endif /* CONFIG_GENERIC_MSI_IRQ */
664 
665 /* PCI specific interfaces */
666 #ifdef CONFIG_PCI_MSI
667 struct pci_dev *msi_desc_to_pci_dev(struct msi_desc *desc);
668 void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg);
669 void __pci_read_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
670 void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
671 void pci_msi_mask_irq(struct irq_data *data);
672 void pci_msi_unmask_irq(struct irq_data *data);
673 struct irq_domain *pci_msi_create_irq_domain(struct fwnode_handle *fwnode,
674 					     struct msi_domain_info *info,
675 					     struct irq_domain *parent);
676 u32 pci_msi_domain_get_msi_rid(struct irq_domain *domain, struct pci_dev *pdev);
677 struct irq_domain *pci_msi_get_device_domain(struct pci_dev *pdev);
678 #else /* CONFIG_PCI_MSI */
pci_msi_get_device_domain(struct pci_dev * pdev)679 static inline struct irq_domain *pci_msi_get_device_domain(struct pci_dev *pdev)
680 {
681 	return NULL;
682 }
pci_write_msi_msg(unsigned int irq,struct msi_msg * msg)683 static inline void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg) { }
684 #endif /* !CONFIG_PCI_MSI */
685 
686 #endif /* LINUX_MSI_H */
687