Skip to content

Commit

Permalink
genirq/msi: Provide msi_device_populate/destroy_sysfs()
Browse files Browse the repository at this point in the history
Add new allocation functions which can be activated by domain info
flags. They store the groups pointer in struct msi_device_data.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Michael Kelley <mikelley@microsoft.com>
Tested-by: Nishanth Menon <nm@ti.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/20211210221813.988659194@linutronix.de
  • Loading branch information
KAGA-KOKO committed Dec 16, 2021
1 parent 686073e commit bf6e054
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
4 changes: 4 additions & 0 deletions include/linux/msi.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ struct irq_data;
struct msi_desc;
struct pci_dev;
struct platform_msi_priv_data;
struct attribute_group;

void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
#ifdef CONFIG_GENERIC_MSI_IRQ
void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg);
Expand Down Expand Up @@ -174,9 +176,11 @@ struct msi_desc {
/**
* msi_device_data - MSI per device data
* @properties: MSI properties which are interesting to drivers
* @attrs: Pointer to the sysfs attribute group
*/
struct msi_device_data {
unsigned long properties;
const struct attribute_group **attrs;
};

int msi_setup_device_data(struct device *dev);
Expand Down
42 changes: 40 additions & 2 deletions kernel/irq/msi.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,20 @@ const struct attribute_group **msi_populate_sysfs(struct device *dev)
return ERR_PTR(ret);
}

/**
* msi_device_populate_sysfs - Populate msi_irqs sysfs entries for a device
* @dev: The device (PCI, platform etc) which will get sysfs entries
*/
int msi_device_populate_sysfs(struct device *dev)
{
const struct attribute_group **group = msi_populate_sysfs(dev);

if (IS_ERR(group))
return PTR_ERR(group);
dev->msi.data->attrs = group;
return 0;
}

/**
* msi_destroy_sysfs - Destroy msi_irqs sysfs entries for devices
* @dev: The device(PCI, platform etc) who will remove sysfs entries
Expand All @@ -225,6 +239,17 @@ void msi_destroy_sysfs(struct device *dev, const struct attribute_group **msi_ir
kfree(msi_irq_groups);
}
}

/**
* msi_device_destroy_sysfs - Destroy msi_irqs sysfs entries for a device
* @dev: The device (PCI, platform etc) for which to remove
* sysfs entries
*/
void msi_device_destroy_sysfs(struct device *dev)
{
msi_destroy_sysfs(dev, dev->msi.data->attrs);
dev->msi.data->attrs = NULL;
}
#endif

#ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
Expand Down Expand Up @@ -672,8 +697,19 @@ int msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev,
{
struct msi_domain_info *info = domain->host_data;
struct msi_domain_ops *ops = info->ops;
int ret;

ret = ops->domain_alloc_irqs(domain, dev, nvec);
if (ret)
return ret;

if (!(info->flags & MSI_FLAG_DEV_SYSFS))
return 0;

return ops->domain_alloc_irqs(domain, dev, nvec);
ret = msi_device_populate_sysfs(dev);
if (ret)
msi_domain_free_irqs(domain, dev);
return ret;
}

void __msi_domain_free_irqs(struct irq_domain *domain, struct device *dev)
Expand Down Expand Up @@ -712,7 +748,9 @@ void msi_domain_free_irqs(struct irq_domain *domain, struct device *dev)
struct msi_domain_info *info = domain->host_data;
struct msi_domain_ops *ops = info->ops;

return ops->domain_free_irqs(domain, dev);
if (info->flags & MSI_FLAG_DEV_SYSFS)
msi_device_destroy_sysfs(dev);
ops->domain_free_irqs(domain, dev);
}

/**
Expand Down

0 comments on commit bf6e054

Please sign in to comment.