Skip to content

Commit 552c494

Browse files
author
Marc Zyngier
committed
platform-msi: Allow creation of a MSI-based stacked irq domain
We almost have all the needed bits requiredable to create a irq domain on top of a MSI domain. For this, we enable a few things: - the virq is stored in the msi_desc - device, msi_alloc_info and domain-specific data are stored in the platform_priv_data structure - we introduce a new API for platform-msi: /* Create a MSI-based domain */ struct irq_domain * platform_msi_create_device_domain(struct device *dev, unsigned int nvec, irq_write_msi_msg_t write_msi_msg, const struct irq_domain_ops *ops, void *host_data); /* Allocate MSIs in an MSI domain */ int platform_msi_domain_alloc(struct irq_domain *domain, unsigned int virq, unsigned int nr_irqs); /* Free MSIs from an MSI domain */ void platform_msi_domain_free(struct irq_domain *domain, unsigned int virq, unsigned int nvec); /* Obtain the host data passed to platform_msi_create_device_domain */ void *platform_msi_get_host_data(struct irq_domain *domain); platform_msi_create_device_domain() is a hybrid of irqdomain creation and interrupt allocation, creating a domain backed by the MSIs associated to a device. IRQs can then be allocated in that domain using platform_msi_domain_alloc(). This now allows a wired irq to MSI bridge to be created. Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
1 parent 2145ac9 commit 552c494

2 files changed

Lines changed: 140 additions & 2 deletions

File tree

‎drivers/base/platform-msi.c‎

Lines changed: 128 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
* and the callback to write the MSI message.
3333
*/
3434
struct platform_msi_priv_data {
35+
struct device *dev;
36+
void *host_data;
37+
msi_alloc_info_t arg;
3538
irq_write_msi_msg_t write_msg;
3639
int devid;
3740
};
@@ -124,8 +127,9 @@ static void platform_msi_free_descs(struct device *dev, int base, int nvec)
124127
}
125128
}
126129

127-
static int platform_msi_alloc_descs(struct device *dev, int nvec,
128-
struct platform_msi_priv_data *data)
130+
static int platform_msi_alloc_descs_with_irq(struct device *dev, int virq,
131+
int nvec,
132+
struct platform_msi_priv_data *data)
129133

130134
{
131135
struct msi_desc *desc;
@@ -145,6 +149,7 @@ static int platform_msi_alloc_descs(struct device *dev, int nvec,
145149
desc->platform.msi_priv_data = data;
146150
desc->platform.msi_index = base + i;
147151
desc->nvec_used = 1;
152+
desc->irq = virq ? virq + i : 0;
148153

149154
list_add_tail(&desc->list, dev_to_msi_list(dev));
150155
}
@@ -159,6 +164,13 @@ static int platform_msi_alloc_descs(struct device *dev, int nvec,
159164
return 0;
160165
}
161166

167+
static int platform_msi_alloc_descs(struct device *dev, int nvec,
168+
struct platform_msi_priv_data *data)
169+
170+
{
171+
return platform_msi_alloc_descs_with_irq(dev, 0, nvec, data);
172+
}
173+
162174
/**
163175
* platform_msi_create_irq_domain - Create a platform MSI interrupt domain
164176
* @fwnode: Optional fwnode of the interrupt controller
@@ -225,6 +237,7 @@ platform_msi_alloc_priv_data(struct device *dev, unsigned int nvec,
225237
}
226238

227239
datap->write_msg = write_msi_msg;
240+
datap->dev = dev;
228241

229242
return datap;
230243
}
@@ -288,3 +301,116 @@ void platform_msi_domain_free_irqs(struct device *dev)
288301
msi_domain_free_irqs(dev->msi_domain, dev);
289302
platform_msi_free_descs(dev, 0, MAX_DEV_MSIS);
290303
}
304+
305+
/**
306+
* platform_msi_get_host_data - Query the private data associated with
307+
* a platform-msi domain
308+
* @domain: The platform-msi domain
309+
*
310+
* Returns the private data provided when calling
311+
* platform_msi_create_device_domain.
312+
*/
313+
void *platform_msi_get_host_data(struct irq_domain *domain)
314+
{
315+
struct platform_msi_priv_data *data = domain->host_data;
316+
return data->host_data;
317+
}
318+
319+
/**
320+
* platform_msi_create_device_domain - Create a platform-msi domain
321+
*
322+
* @dev: The device generating the MSIs
323+
* @nvec: The number of MSIs that need to be allocated
324+
* @write_msi_msg: Callback to write an interrupt message for @dev
325+
* @ops: The hierarchy domain operations to use
326+
* @host_data: Private data associated to this domain
327+
*
328+
* Returns an irqdomain for @nvec interrupts
329+
*/
330+
struct irq_domain *
331+
platform_msi_create_device_domain(struct device *dev,
332+
unsigned int nvec,
333+
irq_write_msi_msg_t write_msi_msg,
334+
const struct irq_domain_ops *ops,
335+
void *host_data)
336+
{
337+
struct platform_msi_priv_data *data;
338+
struct irq_domain *domain;
339+
int err;
340+
341+
data = platform_msi_alloc_priv_data(dev, nvec, write_msi_msg);
342+
if (IS_ERR(data))
343+
return NULL;
344+
345+
data->host_data = host_data;
346+
domain = irq_domain_create_hierarchy(dev->msi_domain, 0, nvec,
347+
of_node_to_fwnode(dev->of_node),
348+
ops, data);
349+
if (!domain)
350+
goto free_priv;
351+
352+
err = msi_domain_prepare_irqs(domain->parent, dev, nvec, &data->arg);
353+
if (err)
354+
goto free_domain;
355+
356+
return domain;
357+
358+
free_domain:
359+
irq_domain_remove(domain);
360+
free_priv:
361+
platform_msi_free_priv_data(data);
362+
return NULL;
363+
}
364+
365+
/**
366+
* platform_msi_domain_free - Free interrupts associated with a platform-msi
367+
* domain
368+
*
369+
* @domain: The platform-msi domain
370+
* @virq: The base irq from which to perform the free operation
371+
* @nvec: How many interrupts to free from @virq
372+
*/
373+
void platform_msi_domain_free(struct irq_domain *domain, unsigned int virq,
374+
unsigned int nvec)
375+
{
376+
struct platform_msi_priv_data *data = domain->host_data;
377+
struct msi_desc *desc;
378+
for_each_msi_entry(desc, data->dev) {
379+
if (WARN_ON(!desc->irq || desc->nvec_used != 1))
380+
return;
381+
if (!(desc->irq >= virq && desc->irq < (virq + nvec)))
382+
continue;
383+
384+
irq_domain_free_irqs_common(domain, desc->irq, 1);
385+
}
386+
}
387+
388+
/**
389+
* platform_msi_domain_alloc - Allocate interrupts associated with
390+
* a platform-msi domain
391+
*
392+
* @domain: The platform-msi domain
393+
* @virq: The base irq from which to perform the allocate operation
394+
* @nvec: How many interrupts to free from @virq
395+
*
396+
* Return 0 on success, or an error code on failure. Must be called
397+
* with irq_domain_mutex held (which can only be done as part of a
398+
* top-level interrupt allocation).
399+
*/
400+
int platform_msi_domain_alloc(struct irq_domain *domain, unsigned int virq,
401+
unsigned int nr_irqs)
402+
{
403+
struct platform_msi_priv_data *data = domain->host_data;
404+
int err;
405+
406+
err = platform_msi_alloc_descs_with_irq(data->dev, virq, nr_irqs, data);
407+
if (err)
408+
return err;
409+
410+
err = msi_domain_populate_irqs(domain->parent, data->dev,
411+
virq, nr_irqs, &data->arg);
412+
if (err)
413+
platform_msi_domain_free(domain, virq, nr_irqs);
414+
415+
return err;
416+
}

‎include/linux/msi.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ struct msi_controller {
174174
#include <asm/msi.h>
175175

176176
struct irq_domain;
177+
struct irq_domain_ops;
177178
struct irq_chip;
178179
struct device_node;
179180
struct fwnode_handle;
@@ -285,6 +286,17 @@ int msi_domain_prepare_irqs(struct irq_domain *domain, struct device *dev,
285286
int nvec, msi_alloc_info_t *args);
286287
int msi_domain_populate_irqs(struct irq_domain *domain, struct device *dev,
287288
int virq, int nvec, msi_alloc_info_t *args);
289+
struct irq_domain *
290+
platform_msi_create_device_domain(struct device *dev,
291+
unsigned int nvec,
292+
irq_write_msi_msg_t write_msi_msg,
293+
const struct irq_domain_ops *ops,
294+
void *host_data);
295+
int platform_msi_domain_alloc(struct irq_domain *domain, unsigned int virq,
296+
unsigned int nr_irqs);
297+
void platform_msi_domain_free(struct irq_domain *domain, unsigned int virq,
298+
unsigned int nvec);
299+
void *platform_msi_get_host_data(struct irq_domain *domain);
288300
#endif /* CONFIG_GENERIC_MSI_IRQ_DOMAIN */
289301

290302
#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN

0 commit comments

Comments
 (0)