xref: /linux/include/linux/msi_api.h (revision f0bae243b2bcf2b160ae547463bf542762beef8f)
16b6941f6SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0 */
26b6941f6SThomas Gleixner #ifndef LINUX_MSI_API_H
36b6941f6SThomas Gleixner #define LINUX_MSI_API_H
46b6941f6SThomas Gleixner 
56b6941f6SThomas Gleixner /*
66b6941f6SThomas Gleixner  * APIs which are relevant for device driver code for allocating and
76b6941f6SThomas Gleixner  * freeing MSI interrupts and querying the associations between
86b6941f6SThomas Gleixner  * hardware/software MSI indices and the Linux interrupt number.
96b6941f6SThomas Gleixner  */
106b6941f6SThomas Gleixner 
116b6941f6SThomas Gleixner struct device;
126b6941f6SThomas Gleixner 
13f1139f90SThomas Gleixner /*
14f1139f90SThomas Gleixner  * Per device interrupt domain related constants.
15f1139f90SThomas Gleixner  */
16f1139f90SThomas Gleixner enum msi_domain_ids {
17f1139f90SThomas Gleixner 	MSI_DEFAULT_DOMAIN,
18f1139f90SThomas Gleixner 	MSI_MAX_DEVICE_IRQDOMAINS,
19f1139f90SThomas Gleixner };
20f1139f90SThomas Gleixner 
2106bff9e3SThomas Gleixner /**
22efd42049SThomas Gleixner  * union msi_instance_cookie - MSI instance cookie
23efd42049SThomas Gleixner  * @value:	u64 value store
24efd42049SThomas Gleixner  * @ptr:	Pointer to usage site specific data
25efd42049SThomas Gleixner  *
26efd42049SThomas Gleixner  * This cookie is handed to the IMS allocation function and stored in the
27efd42049SThomas Gleixner  * MSI descriptor for the interrupt chip callbacks.
28efd42049SThomas Gleixner  *
29efd42049SThomas Gleixner  * The content of this cookie is MSI domain implementation defined.  For
30efd42049SThomas Gleixner  * PCI/IMS implementations this could be a PASID or a pointer to queue
31efd42049SThomas Gleixner  * memory.
32efd42049SThomas Gleixner  */
33efd42049SThomas Gleixner union msi_instance_cookie {
34efd42049SThomas Gleixner 	u64	value;
35efd42049SThomas Gleixner 	void	*ptr;
36efd42049SThomas Gleixner };
37efd42049SThomas Gleixner 
38efd42049SThomas Gleixner /**
3906bff9e3SThomas Gleixner  * msi_map - Mapping between MSI index and Linux interrupt number
4006bff9e3SThomas Gleixner  * @index:	The MSI index, e.g. slot in the MSI-X table or
4106bff9e3SThomas Gleixner  *		a software managed index if >= 0. If negative
4206bff9e3SThomas Gleixner  *		the allocation function failed and it contains
4306bff9e3SThomas Gleixner  *		the error code.
4406bff9e3SThomas Gleixner  * @virq:	The associated Linux interrupt number
4506bff9e3SThomas Gleixner  */
4606bff9e3SThomas Gleixner struct msi_map {
4706bff9e3SThomas Gleixner 	int	index;
4806bff9e3SThomas Gleixner 	int	virq;
4906bff9e3SThomas Gleixner };
5006bff9e3SThomas Gleixner 
51*3d393b21SThomas Gleixner /*
52*3d393b21SThomas Gleixner  * Constant to be used for dynamic allocations when the allocation is any
53*3d393b21SThomas Gleixner  * free MSI index, which is either an entry in a hardware table or a
54*3d393b21SThomas Gleixner  * software managed index.
55*3d393b21SThomas Gleixner  */
56*3d393b21SThomas Gleixner #define MSI_ANY_INDEX		UINT_MAX
57*3d393b21SThomas Gleixner 
5898043704SAhmed S. Darwish unsigned int msi_domain_get_virq(struct device *dev, unsigned int domid, unsigned int index);
5998043704SAhmed S. Darwish 
6098043704SAhmed S. Darwish /**
6198043704SAhmed S. Darwish  * msi_get_virq - Lookup the Linux interrupt number for a MSI index on the default interrupt domain
6298043704SAhmed S. Darwish  * @dev:	Device for which the lookup happens
6398043704SAhmed S. Darwish  * @index:	The MSI index to lookup
6498043704SAhmed S. Darwish  *
6598043704SAhmed S. Darwish  * Return: The Linux interrupt number on success (> 0), 0 if not found
6698043704SAhmed S. Darwish  */
6798043704SAhmed S. Darwish static inline unsigned int msi_get_virq(struct device *dev, unsigned int index)
6898043704SAhmed S. Darwish {
6998043704SAhmed S. Darwish 	return msi_domain_get_virq(dev, MSI_DEFAULT_DOMAIN, index);
7098043704SAhmed S. Darwish }
716b6941f6SThomas Gleixner 
726b6941f6SThomas Gleixner #endif
73