Skip to content

Commit 87cd332

Browse files
sunilmutdcui
authored andcommitted
PCI: hv: Make the code arch neutral by adding arch specific interfaces
Encapsulate arch dependencies in Hyper-V vPCI through a set of arch-dependent interfaces. Adding these arch specific interfaces will allow for an implementation for other architectures, such as arm64. There are no functional changes expected from this patch. Link: https://lore.kernel.org/r/1641411156-31705-2-git-send-email-sunilmut@linux.microsoft.com Signed-off-by: Sunil Muthuswamy <sunilmut@microsoft.com> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Reviewed-by: Marc Zyngier <maz@kernel.org> Reviewed-by: Michael Kelley <mikelley@microsoft.com> Signed-off-by: Tyler Hicks <tyhicks@linux.microsoft.com> Signed-off-by: Allen Pais <apais@linux.microsoft.com>
1 parent 4af6070 commit 87cd332

3 files changed

Lines changed: 83 additions & 53 deletions

File tree

arch/x86/include/asm/hyperv-tlfs.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,39 @@ enum hv_interrupt_type {
585585
HV_X64_INTERRUPT_TYPE_MAXIMUM = 0x000A,
586586
};
587587

588+
union hv_msi_address_register {
589+
u32 as_uint32;
590+
struct {
591+
u32 reserved1:2;
592+
u32 destination_mode:1;
593+
u32 redirection_hint:1;
594+
u32 reserved2:8;
595+
u32 destination_id:8;
596+
u32 msi_base:12;
597+
};
598+
} __packed;
599+
600+
union hv_msi_data_register {
601+
u32 as_uint32;
602+
struct {
603+
u32 vector:8;
604+
u32 delivery_mode:3;
605+
u32 reserved1:3;
606+
u32 level_assert:1;
607+
u32 trigger_mode:1;
608+
u32 reserved2:16;
609+
};
610+
} __packed;
611+
612+
/* HvRetargetDeviceInterrupt hypercall */
613+
union hv_msi_entry {
614+
u64 as_uint64;
615+
struct {
616+
union hv_msi_address_register address;
617+
union hv_msi_data_register data;
618+
} __packed;
619+
};
620+
588621
#include <asm-generic/hyperv-tlfs.h>
589622

590623
#endif

drivers/pci/controller/pci-hyperv.c

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@
4343
#include <linux/pci-ecam.h>
4444
#include <linux/delay.h>
4545
#include <linux/semaphore.h>
46-
#include <linux/irqdomain.h>
47-
#include <asm/irqdomain.h>
48-
#include <asm/apic.h>
4946
#include <linux/irq.h>
5047
#include <linux/msi.h>
5148
#include <linux/hyperv.h>
@@ -577,6 +574,42 @@ struct hv_pci_compl {
577574

578575
static void hv_pci_onchannelcallback(void *context);
579576

577+
#ifdef CONFIG_X86
578+
#define DELIVERY_MODE APIC_DELIVERY_MODE_FIXED
579+
#define FLOW_HANDLER handle_edge_irq
580+
#define FLOW_NAME "edge"
581+
582+
static int hv_pci_irqchip_init(void)
583+
{
584+
return 0;
585+
}
586+
587+
static struct irq_domain *hv_pci_get_root_domain(void)
588+
{
589+
return x86_vector_domain;
590+
}
591+
592+
static unsigned int hv_msi_get_int_vector(struct irq_data *data)
593+
{
594+
struct irq_cfg *cfg = irqd_cfg(data);
595+
596+
return cfg->vector;
597+
}
598+
599+
static void hv_set_msi_entry_from_desc(union hv_msi_entry *msi_entry,
600+
struct msi_desc *msi_desc)
601+
{
602+
msi_entry->address.as_uint32 = msi_desc->msg.address_lo;
603+
msi_entry->data.as_uint32 = msi_desc->msg.data;
604+
}
605+
606+
static int hv_msi_prepare(struct irq_domain *domain, struct device *dev,
607+
int nvec, msi_alloc_info_t *info)
608+
{
609+
return pci_msi_prepare(domain, dev, nvec, info);
610+
}
611+
#endif /* CONFIG_X86 */
612+
580613
/**
581614
* hv_pci_generic_compl() - Invoked for a completion packet
582615
* @context: Set up by the sender of the packet.
@@ -1189,14 +1222,6 @@ static void hv_msi_free(struct irq_domain *domain, struct msi_domain_info *info,
11891222
put_pcichild(hpdev);
11901223
}
11911224

1192-
static int hv_set_affinity(struct irq_data *data, const struct cpumask *dest,
1193-
bool force)
1194-
{
1195-
struct irq_data *parent = data->parent_data;
1196-
1197-
return parent->chip->irq_set_affinity(parent, dest, force);
1198-
}
1199-
12001225
static void hv_irq_mask(struct irq_data *data)
12011226
{
12021227
pci_msi_mask_irq(data);
@@ -1237,7 +1262,6 @@ static int hv_msi_prepare(struct irq_domain *domain, struct device *dev,
12371262
static void hv_irq_unmask(struct irq_data *data)
12381263
{
12391264
struct msi_desc *msi_desc = irq_data_get_msi_desc(data);
1240-
struct irq_cfg *cfg = irqd_cfg(data);
12411265
struct hv_retarget_device_interrupt *params;
12421266
struct tran_int_desc *int_desc;
12431267
struct hv_pcibus_device *hbus;
@@ -1274,7 +1298,7 @@ static void hv_irq_unmask(struct irq_data *data)
12741298
(hbus->hdev->dev_instance.b[7] << 8) |
12751299
(hbus->hdev->dev_instance.b[6] & 0xf8) |
12761300
PCI_FUNC(pdev->devfn);
1277-
params->int_target.vector = cfg->vector;
1301+
params->int_target.vector = hv_msi_get_int_vector(data);
12781302

12791303
/*
12801304
* Honoring apic->delivery_mode set to APIC_DELIVERY_MODE_FIXED by
@@ -1375,7 +1399,7 @@ static u32 hv_compose_msi_req_v1(
13751399
int_pkt->wslot.slot = slot;
13761400
int_pkt->int_desc.vector = vector;
13771401
int_pkt->int_desc.vector_count = vector_count;
1378-
int_pkt->int_desc.delivery_mode = APIC_DELIVERY_MODE_FIXED;
1402+
int_pkt->int_desc.delivery_mode = DELIVERY_MODE;
13791403

13801404
/*
13811405
* Create MSI w/ dummy vCPU set, overwritten by subsequent retarget in
@@ -1405,7 +1429,7 @@ static u32 hv_compose_msi_req_v2(
14051429
int_pkt->wslot.slot = slot;
14061430
int_pkt->int_desc.vector = vector;
14071431
int_pkt->int_desc.vector_count = vector_count;
1408-
int_pkt->int_desc.delivery_mode = APIC_DELIVERY_MODE_FIXED;
1432+
int_pkt->int_desc.delivery_mode = DELIVERY_MODE;
14091433
cpu = hv_compose_msi_req_get_cpu(affinity);
14101434
int_pkt->int_desc.processor_array[0] =
14111435
hv_cpu_number_to_vp_number(cpu);
@@ -1425,7 +1449,7 @@ static u32 hv_compose_msi_req_v3(
14251449
int_pkt->int_desc.vector = vector;
14261450
int_pkt->int_desc.reserved = 0;
14271451
int_pkt->int_desc.vector_count = vector_count;
1428-
int_pkt->int_desc.delivery_mode = APIC_DELIVERY_MODE_FIXED;
1452+
int_pkt->int_desc.delivery_mode = DELIVERY_MODE;
14291453
cpu = hv_compose_msi_req_get_cpu(affinity);
14301454
int_pkt->int_desc.processor_array[0] =
14311455
hv_cpu_number_to_vp_number(cpu);
@@ -1653,7 +1677,7 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
16531677
static struct irq_chip hv_msi_irq_chip = {
16541678
.name = "Hyper-V PCIe MSI",
16551679
.irq_compose_msi_msg = hv_compose_msi_msg,
1656-
.irq_set_affinity = hv_set_affinity,
1680+
.irq_set_affinity = irq_chip_set_affinity_parent,
16571681
.irq_ack = irq_chip_ack_parent,
16581682
.irq_mask = hv_irq_mask,
16591683
.irq_unmask = hv_irq_unmask,
@@ -1684,12 +1708,12 @@ static int hv_pcie_init_irq_domain(struct hv_pcibus_device *hbus)
16841708
hbus->msi_info.flags = (MSI_FLAG_USE_DEF_DOM_OPS |
16851709
MSI_FLAG_USE_DEF_CHIP_OPS | MSI_FLAG_MULTI_PCI_MSI |
16861710
MSI_FLAG_PCI_MSIX);
1687-
hbus->msi_info.handler = handle_edge_irq;
1688-
hbus->msi_info.handler_name = "edge";
1711+
hbus->msi_info.handler = FLOW_HANDLER;
1712+
hbus->msi_info.handler_name = FLOW_NAME;
16891713
hbus->msi_info.data = hbus;
16901714
hbus->irq_domain = pci_msi_create_irq_domain(hbus->fwnode,
16911715
&hbus->msi_info,
1692-
x86_vector_domain);
1716+
hv_pci_get_root_domain());
16931717
if (!hbus->irq_domain) {
16941718
dev_err(&hbus->hdev->device,
16951719
"Failed to build an MSI IRQ domain\n");
@@ -3651,9 +3675,15 @@ static void __exit exit_hv_pci_drv(void)
36513675

36523676
static int __init init_hv_pci_drv(void)
36533677
{
3678+
int ret;
3679+
36543680
if (!hv_is_hyperv_initialized())
36553681
return -ENODEV;
36563682

3683+
ret = hv_pci_irqchip_init();
3684+
if (ret)
3685+
return ret;
3686+
36573687
/* Set the invalid domain number's bit, so it will not be used */
36583688
set_bit(HVPCI_DOM_INVALID, hvpci_dom_map);
36593689

include/asm-generic/hyperv-tlfs.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -539,39 +539,6 @@ enum hv_interrupt_source {
539539
HV_INTERRUPT_SOURCE_IOAPIC,
540540
};
541541

542-
union hv_msi_address_register {
543-
u32 as_uint32;
544-
struct {
545-
u32 reserved1:2;
546-
u32 destination_mode:1;
547-
u32 redirection_hint:1;
548-
u32 reserved2:8;
549-
u32 destination_id:8;
550-
u32 msi_base:12;
551-
};
552-
} __packed;
553-
554-
union hv_msi_data_register {
555-
u32 as_uint32;
556-
struct {
557-
u32 vector:8;
558-
u32 delivery_mode:3;
559-
u32 reserved1:3;
560-
u32 level_assert:1;
561-
u32 trigger_mode:1;
562-
u32 reserved2:16;
563-
};
564-
} __packed;
565-
566-
/* HvRetargetDeviceInterrupt hypercall */
567-
union hv_msi_entry {
568-
u64 as_uint64;
569-
struct {
570-
union hv_msi_address_register address;
571-
union hv_msi_data_register data;
572-
} __packed;
573-
};
574-
575542
union hv_ioapic_rte {
576543
u64 as_uint64;
577544

0 commit comments

Comments
 (0)