Skip to content

Commit 653b50c

Browse files
committed
platform-msi: Let core code handle MSI descriptors
Use the core functionality for platform MSI interrupt domains. The platform device MSI interrupt domains will be converted in a later step. Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Nishanth Menon <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e8604b1 commit 653b50c

File tree

1 file changed

+48
-64
lines changed

1 file changed

+48
-64
lines changed

drivers/base/platform-msi.c

Lines changed: 48 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -107,57 +107,6 @@ static void platform_msi_update_chip_ops(struct msi_domain_info *info)
107107
info->flags &= ~MSI_FLAG_LEVEL_CAPABLE;
108108
}
109109

110-
static void platform_msi_free_descs(struct device *dev, int base, int nvec)
111-
{
112-
struct msi_desc *desc, *tmp;
113-
114-
list_for_each_entry_safe(desc, tmp, dev_to_msi_list(dev), list) {
115-
if (desc->msi_index >= base &&
116-
desc->msi_index < (base + nvec)) {
117-
list_del(&desc->list);
118-
free_msi_entry(desc);
119-
}
120-
}
121-
}
122-
123-
static int platform_msi_alloc_descs_with_irq(struct device *dev, int virq,
124-
int nvec)
125-
{
126-
struct msi_desc *desc;
127-
int i, base = 0;
128-
129-
if (!list_empty(dev_to_msi_list(dev))) {
130-
desc = list_last_entry(dev_to_msi_list(dev),
131-
struct msi_desc, list);
132-
base = desc->msi_index + 1;
133-
}
134-
135-
for (i = 0; i < nvec; i++) {
136-
desc = alloc_msi_entry(dev, 1, NULL);
137-
if (!desc)
138-
break;
139-
140-
desc->msi_index = base + i;
141-
desc->irq = virq ? virq + i : 0;
142-
143-
list_add_tail(&desc->list, dev_to_msi_list(dev));
144-
}
145-
146-
if (i != nvec) {
147-
/* Clean up the mess */
148-
platform_msi_free_descs(dev, base, nvec);
149-
150-
return -ENOMEM;
151-
}
152-
153-
return 0;
154-
}
155-
156-
static int platform_msi_alloc_descs(struct device *dev, int nvec)
157-
{
158-
return platform_msi_alloc_descs_with_irq(dev, 0, nvec);
159-
}
160-
161110
/**
162111
* platform_msi_create_irq_domain - Create a platform MSI interrupt domain
163112
* @fwnode: Optional fwnode of the interrupt controller
@@ -180,7 +129,8 @@ struct irq_domain *platform_msi_create_irq_domain(struct fwnode_handle *fwnode,
180129
platform_msi_update_dom_ops(info);
181130
if (info->flags & MSI_FLAG_USE_DEF_CHIP_OPS)
182131
platform_msi_update_chip_ops(info);
183-
info->flags |= MSI_FLAG_DEV_SYSFS;
132+
info->flags |= MSI_FLAG_DEV_SYSFS | MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS |
133+
MSI_FLAG_FREE_MSI_DESCS;
184134

185135
domain = msi_create_irq_domain(fwnode, info, parent);
186136
if (domain)
@@ -262,20 +212,10 @@ int platform_msi_domain_alloc_irqs(struct device *dev, unsigned int nvec,
262212
if (err)
263213
return err;
264214

265-
err = platform_msi_alloc_descs(dev, nvec);
266-
if (err)
267-
goto out_free_priv_data;
268-
269215
err = msi_domain_alloc_irqs(dev->msi.domain, dev, nvec);
270216
if (err)
271-
goto out_free_desc;
272-
273-
return 0;
217+
platform_msi_free_priv_data(dev);
274218

275-
out_free_desc:
276-
platform_msi_free_descs(dev, 0, nvec);
277-
out_free_priv_data:
278-
platform_msi_free_priv_data(dev);
279219
return err;
280220
}
281221
EXPORT_SYMBOL_GPL(platform_msi_domain_alloc_irqs);
@@ -287,7 +227,6 @@ EXPORT_SYMBOL_GPL(platform_msi_domain_alloc_irqs);
287227
void platform_msi_domain_free_irqs(struct device *dev)
288228
{
289229
msi_domain_free_irqs(dev->msi.domain, dev);
290-
platform_msi_free_descs(dev, 0, MAX_DEV_MSIS);
291230
platform_msi_free_priv_data(dev);
292231
}
293232
EXPORT_SYMBOL_GPL(platform_msi_domain_free_irqs);
@@ -361,6 +300,51 @@ __platform_msi_create_device_domain(struct device *dev,
361300
return NULL;
362301
}
363302

303+
static void platform_msi_free_descs(struct device *dev, int base, int nvec)
304+
{
305+
struct msi_desc *desc, *tmp;
306+
307+
list_for_each_entry_safe(desc, tmp, dev_to_msi_list(dev), list) {
308+
if (desc->msi_index >= base &&
309+
desc->msi_index < (base + nvec)) {
310+
list_del(&desc->list);
311+
free_msi_entry(desc);
312+
}
313+
}
314+
}
315+
316+
static int platform_msi_alloc_descs_with_irq(struct device *dev, int virq,
317+
int nvec)
318+
{
319+
struct msi_desc *desc;
320+
int i, base = 0;
321+
322+
if (!list_empty(dev_to_msi_list(dev))) {
323+
desc = list_last_entry(dev_to_msi_list(dev),
324+
struct msi_desc, list);
325+
base = desc->msi_index + 1;
326+
}
327+
328+
for (i = 0; i < nvec; i++) {
329+
desc = alloc_msi_entry(dev, 1, NULL);
330+
if (!desc)
331+
break;
332+
333+
desc->msi_index = base + i;
334+
desc->irq = virq + i;
335+
336+
list_add_tail(&desc->list, dev_to_msi_list(dev));
337+
}
338+
339+
if (i != nvec) {
340+
/* Clean up the mess */
341+
platform_msi_free_descs(dev, base, nvec);
342+
return -ENOMEM;
343+
}
344+
345+
return 0;
346+
}
347+
364348
/**
365349
* platform_msi_device_domain_free - Free interrupts associated with a platform-msi
366350
* device domain

0 commit comments

Comments
 (0)