Skip to content

Commit 4691db0

Browse files
covanamliuw
authored andcommitted
x86/hyperv: Switch to msi_create_parent_irq_domain()
Move away from the legacy MSI domain setup, switch to use msi_create_parent_irq_domain(). While doing the conversion, I noticed that hv_irq_compose_msi_msg() is doing more than it is supposed to (composing message content). The interrupt allocation bits should be moved into hv_msi_domain_alloc(). However, I have no hardware to test this change, therefore I leave a TODO note. Signed-off-by: Nam Cao <namcao@linutronix.de> Acked-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Nuno Das Neves <nunodasneves@linux.microsoft.com> Reviewed-by: Nuno Das Neves <nunodasneves@linux.microsoft.com> Signed-off-by: Wei Liu <wei.liu@kernel.org>
1 parent c5eebe0 commit 4691db0

2 files changed

Lines changed: 77 additions & 35 deletions

File tree

arch/x86/hyperv/irqdomain.c

Lines changed: 76 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/pci.h>
1212
#include <linux/irq.h>
1313
#include <linux/export.h>
14+
#include <linux/irqchip/irq-msi-lib.h>
1415
#include <asm/mshyperv.h>
1516

1617
static int hv_map_interrupt(union hv_device_id device_id, bool level,
@@ -289,59 +290,99 @@ static void hv_teardown_msi_irq(struct pci_dev *dev, struct irq_data *irqd)
289290
(void)hv_unmap_msi_interrupt(dev, &old_entry);
290291
}
291292

292-
static void hv_msi_free_irq(struct irq_domain *domain,
293-
struct msi_domain_info *info, unsigned int virq)
294-
{
295-
struct irq_data *irqd = irq_get_irq_data(virq);
296-
struct msi_desc *desc;
297-
298-
if (!irqd)
299-
return;
300-
301-
desc = irq_data_get_msi_desc(irqd);
302-
if (!desc || !desc->irq || WARN_ON_ONCE(!dev_is_pci(desc->dev)))
303-
return;
304-
305-
hv_teardown_msi_irq(to_pci_dev(desc->dev), irqd);
306-
}
307-
308293
/*
309294
* IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices,
310295
* which implement the MSI or MSI-X Capability Structure.
311296
*/
312297
static struct irq_chip hv_pci_msi_controller = {
313298
.name = "HV-PCI-MSI",
314-
.irq_unmask = pci_msi_unmask_irq,
315-
.irq_mask = pci_msi_mask_irq,
316299
.irq_ack = irq_chip_ack_parent,
317-
.irq_retrigger = irq_chip_retrigger_hierarchy,
318300
.irq_compose_msi_msg = hv_irq_compose_msi_msg,
319-
.irq_set_affinity = msi_domain_set_affinity,
320-
.flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MOVE_DEFERRED,
301+
.irq_set_affinity = irq_chip_set_affinity_parent,
321302
};
322303

323-
static struct msi_domain_ops pci_msi_domain_ops = {
324-
.msi_free = hv_msi_free_irq,
325-
.msi_prepare = pci_msi_prepare,
304+
static bool hv_init_dev_msi_info(struct device *dev, struct irq_domain *domain,
305+
struct irq_domain *real_parent, struct msi_domain_info *info)
306+
{
307+
struct irq_chip *chip = info->chip;
308+
309+
if (!msi_lib_init_dev_msi_info(dev, domain, real_parent, info))
310+
return false;
311+
312+
chip->flags |= IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MOVE_DEFERRED;
313+
314+
info->ops->msi_prepare = pci_msi_prepare;
315+
316+
return true;
317+
}
318+
319+
#define HV_MSI_FLAGS_SUPPORTED (MSI_GENERIC_FLAGS_MASK | MSI_FLAG_PCI_MSIX)
320+
#define HV_MSI_FLAGS_REQUIRED (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS)
321+
322+
static struct msi_parent_ops hv_msi_parent_ops = {
323+
.supported_flags = HV_MSI_FLAGS_SUPPORTED,
324+
.required_flags = HV_MSI_FLAGS_REQUIRED,
325+
.bus_select_token = DOMAIN_BUS_NEXUS,
326+
.bus_select_mask = MATCH_PCI_MSI,
327+
.chip_flags = MSI_CHIP_FLAG_SET_ACK,
328+
.prefix = "HV-",
329+
.init_dev_msi_info = hv_init_dev_msi_info,
326330
};
327331

328-
static struct msi_domain_info hv_pci_msi_domain_info = {
329-
.flags = MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS |
330-
MSI_FLAG_PCI_MSIX,
331-
.ops = &pci_msi_domain_ops,
332-
.chip = &hv_pci_msi_controller,
333-
.handler = handle_edge_irq,
334-
.handler_name = "edge",
332+
static int hv_msi_domain_alloc(struct irq_domain *d, unsigned int virq, unsigned int nr_irqs,
333+
void *arg)
334+
{
335+
/*
336+
* TODO: The allocation bits of hv_irq_compose_msi_msg(), i.e. everything except
337+
* entry_to_msi_msg() should be in here.
338+
*/
339+
340+
int ret;
341+
342+
ret = irq_domain_alloc_irqs_parent(d, virq, nr_irqs, arg);
343+
if (ret)
344+
return ret;
345+
346+
for (int i = 0; i < nr_irqs; ++i) {
347+
irq_domain_set_info(d, virq + i, 0, &hv_pci_msi_controller, NULL,
348+
handle_edge_irq, NULL, "edge");
349+
}
350+
return 0;
351+
}
352+
353+
static void hv_msi_domain_free(struct irq_domain *d, unsigned int virq, unsigned int nr_irqs)
354+
{
355+
for (int i = 0; i < nr_irqs; ++i) {
356+
struct irq_data *irqd = irq_domain_get_irq_data(d, virq);
357+
struct msi_desc *desc;
358+
359+
desc = irq_data_get_msi_desc(irqd);
360+
if (!desc || !desc->irq || WARN_ON_ONCE(!dev_is_pci(desc->dev)))
361+
continue;
362+
363+
hv_teardown_msi_irq(to_pci_dev(desc->dev), irqd);
364+
}
365+
irq_domain_free_irqs_top(d, virq, nr_irqs);
366+
}
367+
368+
static const struct irq_domain_ops hv_msi_domain_ops = {
369+
.select = msi_lib_irq_domain_select,
370+
.alloc = hv_msi_domain_alloc,
371+
.free = hv_msi_domain_free,
335372
};
336373

337374
struct irq_domain * __init hv_create_pci_msi_domain(void)
338375
{
339376
struct irq_domain *d = NULL;
340-
struct fwnode_handle *fn;
341377

342-
fn = irq_domain_alloc_named_fwnode("HV-PCI-MSI");
343-
if (fn)
344-
d = pci_msi_create_irq_domain(fn, &hv_pci_msi_domain_info, x86_vector_domain);
378+
struct irq_domain_info info = {
379+
.fwnode = irq_domain_alloc_named_fwnode("HV-PCI-MSI"),
380+
.ops = &hv_msi_domain_ops,
381+
.parent = x86_vector_domain,
382+
};
383+
384+
if (info.fwnode)
385+
d = msi_create_parent_irq_domain(&info, &hv_msi_parent_ops);
345386

346387
/* No point in going further if we can't get an irq domain */
347388
BUG_ON(!d);

drivers/hv/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ config HYPERV
1010
select X86_HV_CALLBACK_VECTOR if X86
1111
select OF_EARLY_FLATTREE if OF
1212
select SYSFB if EFI && !HYPERV_VTL_MODE
13+
select IRQ_MSI_LIB if X86
1314
help
1415
Select this option to run Linux as a Hyper-V client operating
1516
system.

0 commit comments

Comments
 (0)