History

genirq/msi: Provide msi_device_populate/destroy_sysfs()

Add new allocation functions which can be activated by domain info flags. They store the groups pointer in struct msi_device_data.

Thomas Gleixner committed 4 years ago

Commit bf6e0541 parent 686073e2 files · +44 −2Browse files

Unified · Split

2 files
  1. include/linux/msi.h +4 −0
  2. kernel/irq/msi.c +40 −2
include/linux/msi.h+4−0
@@ -56,6 +56,8 @@ struct irq_data; · 55 unmodified lines
5656 struct msi_desc;
5757 struct pci_dev;
5858 struct platform_msi_priv_data;
59+struct attribute_group;
60+
5961 void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
6062 #ifdef CONFIG_GENERIC_MSI_IRQ
6163 void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg);
@@ -174,9 +176,11 @@ struct msi_desc { · 112 unmodified lines
174176 /**
175177 * msi_device_data - MSI per device data
176178 * @properties: MSI properties which are interesting to drivers
179+ * @attrs: Pointer to the sysfs attribute group
177180 */
178181 struct msi_device_data {
179182 unsigned long properties;
183+ const struct attribute_group **attrs;
180184 };
181185
182186 int msi_setup_device_data(struct device *dev);
kernel/irq/msi.c+40−2
@@ -199,6 +199,20 @@ error_attrs: · 198 unmodified lines
199199 return ERR_PTR(ret);
200200 }
201201
202+/**
203+ * msi_device_populate_sysfs - Populate msi_irqs sysfs entries for a device
204+ * @dev: The device (PCI, platform etc) which will get sysfs entries
205+ */
206+int msi_device_populate_sysfs(struct device *dev)
207+{
208+ const struct attribute_group **group = msi_populate_sysfs(dev);
209+
210+ if (IS_ERR(group))
211+ return PTR_ERR(group);
212+ dev->msi.data->attrs = group;
213+ return 0;
214+}
215+
202216 /**
203217 * msi_destroy_sysfs - Destroy msi_irqs sysfs entries for devices
204218 * @dev: The device(PCI, platform etc) who will remove sysfs entries
@@ -225,6 +239,17 @@ void msi_destroy_sysfs(struct device *dev, const struct attribute_group **msi_ir · 20 unmodified lines
225239 kfree(msi_irq_groups);
226240 }
227241 }
242+
243+/**
244+ * msi_device_destroy_sysfs - Destroy msi_irqs sysfs entries for a device
245+ * @dev: The device (PCI, platform etc) for which to remove
246+ * sysfs entries
247+ */
248+void msi_device_destroy_sysfs(struct device *dev)
249+{
250+ msi_destroy_sysfs(dev, dev->msi.data->attrs);
251+ dev->msi.data->attrs = NULL;
252+}
228253 #endif
229254
230255 #ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
@@ -672,8 +697,19 @@ int msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev, · 441 unmodified lines
672697 {
673698 struct msi_domain_info *info = domain->host_data;
674699 struct msi_domain_ops *ops = info->ops;
700+ int ret;
701+
702+ ret = ops->domain_alloc_irqs(domain, dev, nvec);
703+ if (ret)
704+ return ret;
705+
706+ if (!(info->flags & MSI_FLAG_DEV_SYSFS))
707+ return 0;
675708
676− return ops->domain_alloc_irqs(domain, dev, nvec);
709+ ret = msi_device_populate_sysfs(dev);
710+ if (ret)
711+ msi_domain_free_irqs(domain, dev);
712+ return ret;
677713 }
678714
679715 void __msi_domain_free_irqs(struct irq_domain *domain, struct device *dev)
@@ -712,7 +748,9 @@ void msi_domain_free_irqs(struct irq_domain *domain, struct device *dev) · 32 unmodified lines
712748 struct msi_domain_info *info = domain->host_data;
713749 struct msi_domain_ops *ops = info->ops;
714750
715− return ops->domain_free_irqs(domain, dev);
751+ if (info->flags & MSI_FLAG_DEV_SYSFS)
752+ msi_device_destroy_sysfs(dev);
753+ ops->domain_free_irqs(domain, dev);
716754 }
717755
718756 /**