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,
18*e23d4192SThomas Gleixner MSI_SECONDARY_DOMAIN,
19f1139f90SThomas Gleixner MSI_MAX_DEVICE_IRQDOMAINS,
20f1139f90SThomas Gleixner };
21f1139f90SThomas Gleixner
2206bff9e3SThomas Gleixner /**
23efd42049SThomas Gleixner * union msi_instance_cookie - MSI instance cookie
24efd42049SThomas Gleixner * @value: u64 value store
25efd42049SThomas Gleixner * @ptr: Pointer to usage site specific data
26efd42049SThomas Gleixner *
27efd42049SThomas Gleixner * This cookie is handed to the IMS allocation function and stored in the
28efd42049SThomas Gleixner * MSI descriptor for the interrupt chip callbacks.
29efd42049SThomas Gleixner *
30efd42049SThomas Gleixner * The content of this cookie is MSI domain implementation defined. For
31efd42049SThomas Gleixner * PCI/IMS implementations this could be a PASID or a pointer to queue
32efd42049SThomas Gleixner * memory.
33efd42049SThomas Gleixner */
34efd42049SThomas Gleixner union msi_instance_cookie {
35efd42049SThomas Gleixner u64 value;
36efd42049SThomas Gleixner void *ptr;
37efd42049SThomas Gleixner };
38efd42049SThomas Gleixner
39efd42049SThomas Gleixner /**
4006bff9e3SThomas Gleixner * msi_map - Mapping between MSI index and Linux interrupt number
4106bff9e3SThomas Gleixner * @index: The MSI index, e.g. slot in the MSI-X table or
4206bff9e3SThomas Gleixner * a software managed index if >= 0. If negative
4306bff9e3SThomas Gleixner * the allocation function failed and it contains
4406bff9e3SThomas Gleixner * the error code.
4506bff9e3SThomas Gleixner * @virq: The associated Linux interrupt number
4606bff9e3SThomas Gleixner */
4706bff9e3SThomas Gleixner struct msi_map {
4806bff9e3SThomas Gleixner int index;
4906bff9e3SThomas Gleixner int virq;
5006bff9e3SThomas Gleixner };
5106bff9e3SThomas Gleixner
523d393b21SThomas Gleixner /*
533d393b21SThomas Gleixner * Constant to be used for dynamic allocations when the allocation is any
543d393b21SThomas Gleixner * free MSI index, which is either an entry in a hardware table or a
553d393b21SThomas Gleixner * software managed index.
563d393b21SThomas Gleixner */
573d393b21SThomas Gleixner #define MSI_ANY_INDEX UINT_MAX
583d393b21SThomas Gleixner
5998043704SAhmed S. Darwish unsigned int msi_domain_get_virq(struct device *dev, unsigned int domid, unsigned int index);
6098043704SAhmed S. Darwish
6198043704SAhmed S. Darwish /**
6298043704SAhmed S. Darwish * msi_get_virq - Lookup the Linux interrupt number for a MSI index on the default interrupt domain
6398043704SAhmed S. Darwish * @dev: Device for which the lookup happens
6498043704SAhmed S. Darwish * @index: The MSI index to lookup
6598043704SAhmed S. Darwish *
6698043704SAhmed S. Darwish * Return: The Linux interrupt number on success (> 0), 0 if not found
6798043704SAhmed S. Darwish */
msi_get_virq(struct device * dev,unsigned int index)6898043704SAhmed S. Darwish static inline unsigned int msi_get_virq(struct device *dev, unsigned int index)
6998043704SAhmed S. Darwish {
7098043704SAhmed S. Darwish return msi_domain_get_virq(dev, MSI_DEFAULT_DOMAIN, index);
7198043704SAhmed S. Darwish }
726b6941f6SThomas Gleixner
736b6941f6SThomas Gleixner #endif
74