Commit fc22e7db authored by Thomas Gleixner's avatar Thomas Gleixner

platform-msi: Store platform private data pointer in msi_device_data

Storing the platform private data in a MSI descriptor is sloppy at
best. The data belongs to the device and not to the descriptor.
Add a pointer to struct msi_device_data and store the pointer there.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Tested-by: default avatarNishanth Menon <nm@ti.com>
Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/20211210221814.287680528@linutronix.de
parent 9835cec6
...@@ -38,9 +38,7 @@ static DEFINE_IDA(platform_msi_devid_ida); ...@@ -38,9 +38,7 @@ static DEFINE_IDA(platform_msi_devid_ida);
*/ */
static irq_hw_number_t platform_msi_calc_hwirq(struct msi_desc *desc) static irq_hw_number_t platform_msi_calc_hwirq(struct msi_desc *desc)
{ {
u32 devid; u32 devid = desc->dev->msi.data->platform_data->devid;
devid = desc->platform.msi_priv_data->devid;
return (devid << (32 - DEV_ID_SHIFT)) | desc->platform.msi_index; return (devid << (32 - DEV_ID_SHIFT)) | desc->platform.msi_index;
} }
...@@ -85,11 +83,8 @@ static void platform_msi_update_dom_ops(struct msi_domain_info *info) ...@@ -85,11 +83,8 @@ static void platform_msi_update_dom_ops(struct msi_domain_info *info)
static void platform_msi_write_msg(struct irq_data *data, struct msi_msg *msg) static void platform_msi_write_msg(struct irq_data *data, struct msi_msg *msg)
{ {
struct msi_desc *desc = irq_data_get_msi_desc(data); struct msi_desc *desc = irq_data_get_msi_desc(data);
struct platform_msi_priv_data *priv_data;
priv_data = desc->platform.msi_priv_data;
priv_data->write_msg(desc, msg); desc->dev->msi.data->platform_data->write_msg(desc, msg);
} }
static void platform_msi_update_chip_ops(struct msi_domain_info *info) static void platform_msi_update_chip_ops(struct msi_domain_info *info)
...@@ -126,9 +121,7 @@ static void platform_msi_free_descs(struct device *dev, int base, int nvec) ...@@ -126,9 +121,7 @@ static void platform_msi_free_descs(struct device *dev, int base, int nvec)
} }
static int platform_msi_alloc_descs_with_irq(struct device *dev, int virq, static int platform_msi_alloc_descs_with_irq(struct device *dev, int virq,
int nvec, int nvec)
struct platform_msi_priv_data *data)
{ {
struct msi_desc *desc; struct msi_desc *desc;
int i, base = 0; int i, base = 0;
...@@ -144,7 +137,6 @@ static int platform_msi_alloc_descs_with_irq(struct device *dev, int virq, ...@@ -144,7 +137,6 @@ static int platform_msi_alloc_descs_with_irq(struct device *dev, int virq,
if (!desc) if (!desc)
break; break;
desc->platform.msi_priv_data = data;
desc->platform.msi_index = base + i; desc->platform.msi_index = base + i;
desc->irq = virq ? virq + i : 0; desc->irq = virq ? virq + i : 0;
...@@ -161,11 +153,9 @@ static int platform_msi_alloc_descs_with_irq(struct device *dev, int virq, ...@@ -161,11 +153,9 @@ static int platform_msi_alloc_descs_with_irq(struct device *dev, int virq,
return 0; return 0;
} }
static int platform_msi_alloc_descs(struct device *dev, int nvec, static int platform_msi_alloc_descs(struct device *dev, int nvec)
struct platform_msi_priv_data *data)
{ {
return platform_msi_alloc_descs_with_irq(dev, 0, nvec, data); return platform_msi_alloc_descs_with_irq(dev, 0, nvec);
} }
/** /**
...@@ -199,8 +189,7 @@ struct irq_domain *platform_msi_create_irq_domain(struct fwnode_handle *fwnode, ...@@ -199,8 +189,7 @@ struct irq_domain *platform_msi_create_irq_domain(struct fwnode_handle *fwnode,
return domain; return domain;
} }
static struct platform_msi_priv_data * static int platform_msi_alloc_priv_data(struct device *dev, unsigned int nvec,
platform_msi_alloc_priv_data(struct device *dev, unsigned int nvec,
irq_write_msi_msg_t write_msi_msg) irq_write_msi_msg_t write_msi_msg)
{ {
struct platform_msi_priv_data *datap; struct platform_msi_priv_data *datap;
...@@ -213,41 +202,44 @@ platform_msi_alloc_priv_data(struct device *dev, unsigned int nvec, ...@@ -213,41 +202,44 @@ platform_msi_alloc_priv_data(struct device *dev, unsigned int nvec,
* capable devices). * capable devices).
*/ */
if (!dev->msi.domain || !write_msi_msg || !nvec || nvec > MAX_DEV_MSIS) if (!dev->msi.domain || !write_msi_msg || !nvec || nvec > MAX_DEV_MSIS)
return ERR_PTR(-EINVAL); return -EINVAL;
if (dev->msi.domain->bus_token != DOMAIN_BUS_PLATFORM_MSI) { if (dev->msi.domain->bus_token != DOMAIN_BUS_PLATFORM_MSI) {
dev_err(dev, "Incompatible msi_domain, giving up\n"); dev_err(dev, "Incompatible msi_domain, giving up\n");
return ERR_PTR(-EINVAL); return -EINVAL;
} }
err = msi_setup_device_data(dev); err = msi_setup_device_data(dev);
if (err) if (err)
return ERR_PTR(err); return err;
/* Already had a helping of MSI? Greed... */ /* Already initialized? */
if (!list_empty(dev_to_msi_list(dev))) if (dev->msi.data->platform_data)
return ERR_PTR(-EBUSY); return -EBUSY;
datap = kzalloc(sizeof(*datap), GFP_KERNEL); datap = kzalloc(sizeof(*datap), GFP_KERNEL);
if (!datap) if (!datap)
return ERR_PTR(-ENOMEM); return -ENOMEM;
datap->devid = ida_simple_get(&platform_msi_devid_ida, datap->devid = ida_simple_get(&platform_msi_devid_ida,
0, 1 << DEV_ID_SHIFT, GFP_KERNEL); 0, 1 << DEV_ID_SHIFT, GFP_KERNEL);
if (datap->devid < 0) { if (datap->devid < 0) {
err = datap->devid; err = datap->devid;
kfree(datap); kfree(datap);
return ERR_PTR(err); return err;
} }
datap->write_msg = write_msi_msg; datap->write_msg = write_msi_msg;
datap->dev = dev; datap->dev = dev;
dev->msi.data->platform_data = datap;
return datap; return 0;
} }
static void platform_msi_free_priv_data(struct platform_msi_priv_data *data) static void platform_msi_free_priv_data(struct device *dev)
{ {
struct platform_msi_priv_data *data = dev->msi.data->platform_data;
dev->msi.data->platform_data = NULL;
ida_simple_remove(&platform_msi_devid_ida, data->devid); ida_simple_remove(&platform_msi_devid_ida, data->devid);
kfree(data); kfree(data);
} }
...@@ -264,14 +256,13 @@ static void platform_msi_free_priv_data(struct platform_msi_priv_data *data) ...@@ -264,14 +256,13 @@ static void platform_msi_free_priv_data(struct platform_msi_priv_data *data)
int platform_msi_domain_alloc_irqs(struct device *dev, unsigned int nvec, int platform_msi_domain_alloc_irqs(struct device *dev, unsigned int nvec,
irq_write_msi_msg_t write_msi_msg) irq_write_msi_msg_t write_msi_msg)
{ {
struct platform_msi_priv_data *priv_data;
int err; int err;
priv_data = platform_msi_alloc_priv_data(dev, nvec, write_msi_msg); err = platform_msi_alloc_priv_data(dev, nvec, write_msi_msg);
if (IS_ERR(priv_data)) if (err)
return PTR_ERR(priv_data); return err;
err = platform_msi_alloc_descs(dev, nvec, priv_data); err = platform_msi_alloc_descs(dev, nvec);
if (err) if (err)
goto out_free_priv_data; goto out_free_priv_data;
...@@ -284,8 +275,7 @@ int platform_msi_domain_alloc_irqs(struct device *dev, unsigned int nvec, ...@@ -284,8 +275,7 @@ int platform_msi_domain_alloc_irqs(struct device *dev, unsigned int nvec,
out_free_desc: out_free_desc:
platform_msi_free_descs(dev, 0, nvec); platform_msi_free_descs(dev, 0, nvec);
out_free_priv_data: out_free_priv_data:
platform_msi_free_priv_data(priv_data); platform_msi_free_priv_data(dev);
return err; return err;
} }
EXPORT_SYMBOL_GPL(platform_msi_domain_alloc_irqs); EXPORT_SYMBOL_GPL(platform_msi_domain_alloc_irqs);
...@@ -296,15 +286,9 @@ EXPORT_SYMBOL_GPL(platform_msi_domain_alloc_irqs); ...@@ -296,15 +286,9 @@ EXPORT_SYMBOL_GPL(platform_msi_domain_alloc_irqs);
*/ */
void platform_msi_domain_free_irqs(struct device *dev) void platform_msi_domain_free_irqs(struct device *dev)
{ {
if (!list_empty(dev_to_msi_list(dev))) {
struct msi_desc *desc;
desc = first_msi_entry(dev);
platform_msi_free_priv_data(desc->platform.msi_priv_data);
}
msi_domain_free_irqs(dev->msi.domain, dev); msi_domain_free_irqs(dev->msi.domain, dev);
platform_msi_free_descs(dev, 0, MAX_DEV_MSIS); platform_msi_free_descs(dev, 0, MAX_DEV_MSIS);
platform_msi_free_priv_data(dev);
} }
EXPORT_SYMBOL_GPL(platform_msi_domain_free_irqs); EXPORT_SYMBOL_GPL(platform_msi_domain_free_irqs);
...@@ -351,10 +335,11 @@ __platform_msi_create_device_domain(struct device *dev, ...@@ -351,10 +335,11 @@ __platform_msi_create_device_domain(struct device *dev,
struct irq_domain *domain; struct irq_domain *domain;
int err; int err;
data = platform_msi_alloc_priv_data(dev, nvec, write_msi_msg); err = platform_msi_alloc_priv_data(dev, nvec, write_msi_msg);
if (IS_ERR(data)) if (err)
return NULL; return NULL;
data = dev->msi.data->platform_data;
data->host_data = host_data; data->host_data = host_data;
domain = irq_domain_create_hierarchy(dev->msi.domain, 0, domain = irq_domain_create_hierarchy(dev->msi.domain, 0,
is_tree ? 0 : nvec, is_tree ? 0 : nvec,
...@@ -372,7 +357,7 @@ __platform_msi_create_device_domain(struct device *dev, ...@@ -372,7 +357,7 @@ __platform_msi_create_device_domain(struct device *dev,
free_domain: free_domain:
irq_domain_remove(domain); irq_domain_remove(domain);
free_priv: free_priv:
platform_msi_free_priv_data(data); platform_msi_free_priv_data(dev);
return NULL; return NULL;
} }
...@@ -420,7 +405,7 @@ int platform_msi_device_domain_alloc(struct irq_domain *domain, unsigned int vir ...@@ -420,7 +405,7 @@ int platform_msi_device_domain_alloc(struct irq_domain *domain, unsigned int vir
struct platform_msi_priv_data *data = domain->host_data; struct platform_msi_priv_data *data = domain->host_data;
int err; int err;
err = platform_msi_alloc_descs_with_irq(data->dev, virq, nr_irqs, data); err = platform_msi_alloc_descs_with_irq(data->dev, virq, nr_irqs);
if (err) if (err)
return err; return err;
......
...@@ -108,11 +108,9 @@ struct pci_msi_desc { ...@@ -108,11 +108,9 @@ struct pci_msi_desc {
/** /**
* platform_msi_desc - Platform device specific msi descriptor data * platform_msi_desc - Platform device specific msi descriptor data
* @msi_priv_data: Pointer to platform private data
* @msi_index: The index of the MSI descriptor for multi MSI * @msi_index: The index of the MSI descriptor for multi MSI
*/ */
struct platform_msi_desc { struct platform_msi_desc {
struct platform_msi_priv_data *msi_priv_data;
u16 msi_index; u16 msi_index;
}; };
...@@ -177,10 +175,12 @@ struct msi_desc { ...@@ -177,10 +175,12 @@ struct msi_desc {
* msi_device_data - MSI per device data * msi_device_data - MSI per device data
* @properties: MSI properties which are interesting to drivers * @properties: MSI properties which are interesting to drivers
* @attrs: Pointer to the sysfs attribute group * @attrs: Pointer to the sysfs attribute group
* @platform_data: Platform-MSI specific data
*/ */
struct msi_device_data { struct msi_device_data {
unsigned long properties; unsigned long properties;
const struct attribute_group **attrs; const struct attribute_group **attrs;
struct platform_msi_priv_data *platform_data;
}; };
int msi_setup_device_data(struct device *dev); int msi_setup_device_data(struct device *dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment