linux-stable/include/linux/msi_api.h

74 lines
2 KiB
C
Raw Normal View History

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef LINUX_MSI_API_H
#define LINUX_MSI_API_H
/*
* APIs which are relevant for device driver code for allocating and
* freeing MSI interrupts and querying the associations between
* hardware/software MSI indices and the Linux interrupt number.
*/
struct device;
/*
* Per device interrupt domain related constants.
*/
enum msi_domain_ids {
MSI_DEFAULT_DOMAIN,
MSI_SECONDARY_DOMAIN,
MSI_MAX_DEVICE_IRQDOMAINS,
};
/**
* union msi_instance_cookie - MSI instance cookie
* @value: u64 value store
* @ptr: Pointer to usage site specific data
*
* This cookie is handed to the IMS allocation function and stored in the
* MSI descriptor for the interrupt chip callbacks.
*
* The content of this cookie is MSI domain implementation defined. For
* PCI/IMS implementations this could be a PASID or a pointer to queue
* memory.
*/
union msi_instance_cookie {
u64 value;
void *ptr;
};
/**
* msi_map - Mapping between MSI index and Linux interrupt number
* @index: The MSI index, e.g. slot in the MSI-X table or
* a software managed index if >= 0. If negative
* the allocation function failed and it contains
* the error code.
* @virq: The associated Linux interrupt number
*/
struct msi_map {
int index;
int virq;
};
genirq/msi: Provide msi_domain_alloc_irq_at() For supporting post MSI-X enable allocations and for the upcoming PCI/IMS support a separate interface is required which allows not only the allocation of a specific index, but also the allocation of any, i.e. the next free index. The latter is especially required for IMS because IMS completely does away with index to functionality mappings which are often found in MSI/MSI-X implementation. But even with MSI-X there are devices where only the first few indices have a fixed functionality and the rest is freely assignable by software, e.g. to queues. msi_domain_alloc_irq_at() is also different from the range based interfaces as it always enforces that the MSI descriptor is allocated by the core code and not preallocated by the caller like the PCI/MSI[-X] enable code path does. msi_domain_alloc_irq_at() can be invoked with the index argument set to MSI_ANY_INDEX which makes the core code pick the next free index. The irq domain can provide a prepare_desc() operation callback in it's msi_domain_ops to do domain specific post allocation initialization before the actual Linux interrupt and the associated interrupt descriptor and hierarchy alloccations are conducted. The function also takes an optional @icookie argument which is of type union msi_instance_cookie. This cookie is not used by the core code and is stored in the allocated msi_desc::data::icookie. The meaning of the cookie is completely implementation defined. In case of IMS this might be a PASID or a pointer to a device queue, but for the MSI core it's opaque and not used in any way. The function returns a struct msi_map which on success contains the allocated index number and the Linux interrupt number so the caller can spare the index to Linux interrupt number lookup. On failure map::index contains the error code and map::virq is 0. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Acked-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20221124232326.501359457@linutronix.de
2022-11-24 23:26:18 +00:00
/*
* Constant to be used for dynamic allocations when the allocation is any
* free MSI index, which is either an entry in a hardware table or a
* software managed index.
*/
#define MSI_ANY_INDEX UINT_MAX
unsigned int msi_domain_get_virq(struct device *dev, unsigned int domid, unsigned int index);
/**
* msi_get_virq - Lookup the Linux interrupt number for a MSI index on the default interrupt domain
* @dev: Device for which the lookup happens
* @index: The MSI index to lookup
*
* Return: The Linux interrupt number on success (> 0), 0 if not found
*/
static inline unsigned int msi_get_virq(struct device *dev, unsigned int index)
{
return msi_domain_get_virq(dev, MSI_DEFAULT_DOMAIN, index);
}
#endif