From patchwork Mon Sep 13 17:36:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil Muthuswamy X-Patchwork-Id: 1527521 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=microsoft.com header.i=@microsoft.com header.a=rsa-sha256 header.s=selector2 header.b=A7HWhlNm; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4H7YZJ34Jkz9sVw for ; Tue, 14 Sep 2021 03:36:56 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243337AbhIMRiH (ORCPT ); Mon, 13 Sep 2021 13:38:07 -0400 Received: from mail-oln040093003003.outbound.protection.outlook.com ([40.93.3.3]:4645 "EHLO na01-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S238180AbhIMRiG (ORCPT ); Mon, 13 Sep 2021 13:38:06 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CNV+Oh3NaHofBy+UEewZVdOElZuuqpiC0MN6/efrinyWAplEhWUdVnWj0m0cbZDIt+i5hzTsV4Pkc8EPJso906+TOjEHRGvq/3ZNUgHqvK5RpjZMAZgi89rvS4edowe6eodcp9I5zrxlmIukbLN6EWkJx15+MNUO34IoegCpgcKCGVtiCKdFYPdkH0ieFR/DT/zNDzW2bTBwo1O2duASqcoyNUoS5H3krZ755PPKTZ5gKsxuqt3FOBQRTi3yM5U9eM46v/jOt05L+tCdfRH1HQ4Zbq3iF3+DwkfyNKJHB3QTxPr3NyOHKUIrUCK6ghc/Sq/vRrYn+srI5tdk9YSpQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Bqjwzcjy2bIUQyMyzt8ZOHCz2SAMCWTBOou43sef7Dk=; b=TmWw71itBeh5b9vj/blHFUHClTuIXQQiZyIPM1RLT6ThIcCf1l9T5ERXlgc9gduW5G6AzH/FXbYeE0jhrW6/+d+iApPO40fA9/yj7AJ8UeDicC4KSUeG2vYR1OZA2gSbjVV0DBiRnSvWlXuMffymF8QC5VdD79sepgYLLNAfJHkQwdNnoL+NlgDdcUMZ27NalbL1Uk4Hew/fCMWFRE71KgQFGlgSH/8jwEsQpisPj/FcR756WszFFfQ3DUdQAtw4Nrk0rrTC5cvds6tigOGXxTYOD8Q5ft1phQDKHbIulzoC25qPuuGBocnOF7bxf14l9e7nU6EQhVCK4rMUgvSDsA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Bqjwzcjy2bIUQyMyzt8ZOHCz2SAMCWTBOou43sef7Dk=; b=A7HWhlNm0RseSDl8U+4COySHk7M+MGZHbn/I2Vj9taGAvQdptB5+x4HvURRoVG3HFajzkDvj3xCelKm2him5oj53RzHjWVGQMzDrNOcKdevNfsjTpe3S63rxs3sP/4camb9WreWmpxRia6i/OSLzY+xwyzWlyh//BaP7IYdi3X0= Received: from MW4PR21MB2002.namprd21.prod.outlook.com (2603:10b6:303:68::18) by MWHPR21MB0830.namprd21.prod.outlook.com (2603:10b6:300:76::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.8; Mon, 13 Sep 2021 17:36:47 +0000 Received: from MW4PR21MB2002.namprd21.prod.outlook.com ([fe80::b134:7809:fcff:8c8b]) by MW4PR21MB2002.namprd21.prod.outlook.com ([fe80::b134:7809:fcff:8c8b%4]) with mapi id 15.20.4523.011; Mon, 13 Sep 2021 17:36:47 +0000 From: Sunil Muthuswamy To: Michael Kelley , Boqun Feng , KY Srinivasan , Haiyang Zhang , Stephen Hemminger , Dexuan Cui , Lorenzo Pieralisi , Rob Herring , =?iso-8859-2?q?=22Krzysztof_Wilczy=F1ski=22?= , Bjorn Helgaas , Wei Liu CC: "linux-hyperv@vger.kernel.org" , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH 1/2] PCI: hv: Make the code arch neutral Thread-Topic: [PATCH 1/2] PCI: hv: Make the code arch neutral Thread-Index: AdeoxSGQR+XTDCnuQJejgIDf8UzhEg== Date: Mon, 13 Sep 2021 17:36:46 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: a4fa2991-034c-423e-c0f3-08d976dd0ffc x-ms-traffictypediagnostic: MWHPR21MB0830: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: DqBRif7FAoruaxdJ53Ii0Sg3FkxAjvlAZ319AKd9AHJ7EaZR7GLLtvjKumXP1aDBfEW+AeaLxkIydzdKM30P+5N4cgmZnfld3L8Yd8xclifxwP+ptzJXICDVDPr17ThIKNCX2+DKniPl/FEZWjw6wuvJtZ1WvTyh5tEq4kxsvuYwH7EYdVPu5nJRKPJ+xQZ6qpN5J2XIIs9vbs5URwrEsj7Y6e3IWA4SekQOveCw3qt2Ne3tJm01AlMpWRnczWn3isS4nWinZ4dLVXSI4ZpnkxPEnE0fWN5kCNPGE+j/sFUkY0MMUyt9DsIXmZQEmKrrLzqzK9lh/2kxOOXQMPzQ6lQ51joE2b+o3yVXYTqylahTcio4T3bHxf5KwmBbbvAqe24ogeJgtZySQfdG0vZap0fAQKvGIm37amjTHvxq7u7gm5Kx8mBX7JN3hTA3w+gOblU5LYLa9B/9vOwOXCiVutp6V0uKGDwaFUwCpIHKs0DX9HJUHo5IkqnwVCXTi6jWmcZvDC4vMtB7r8sbdAjDuMK/O5APAjEmQNljh5lgfVWeZ6gOLugUYvwEkxR5BsGRAKPH16Tl7exW5w9yp6HZkZkTujoXznA9BshXrQY9Trde46Pq88iF+Di0YI687DES5owKug/L0Hb2s0uMSWMaPfKqas0I1k6bTK97v/ie5uTYP0rFMWqI/scVc+q2amrWpFV9lV8NdvP6D3lqWKXMztJrTQ1w+lmwOCUEczDDojk= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW4PR21MB2002.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(6506007)(9686003)(508600001)(76116006)(55016002)(52536014)(83380400001)(7696005)(38070700005)(71200400001)(33656002)(66446008)(64756008)(82950400001)(66556008)(66476007)(82960400001)(66946007)(86362001)(38100700002)(186003)(122000001)(921005)(8676002)(8936002)(8990500004)(2906002)(4326008)(316002)(54906003)(110136005)(10290500003)(5660300002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-2?q?8HKPSXME+4XyV06IYX5esN9?= =?iso-8859-2?q?sFEQ41PUqZk6Yv+1mWhIrjgf2MLx7o9CJxPv4drbCMEbgk6UUVIXJqU7DhmW?= =?iso-8859-2?q?CIUMKkQsk3CLObT8hVsme1VL/ZoSa3GePpwbwJtkbeCZG1fDTldKibFg4A9F?= =?iso-8859-2?q?9DbqSv8OmhG9s9zaWcOMrkxSsG1kdoavyI6vy7LNg+sSblNsOkxOqlt8ye2t?= =?iso-8859-2?q?lbEMjwO9fSvrdmjdo0v5nNIkX89a5ASD2EIgJVHfzK5NjO3LjGbIiMjrOuIw?= =?iso-8859-2?q?g2Bhv0dvD3dhG3YhIJmx3oFyOMdYwZvz4wNFjUVmlD3XvgxFdmwS3HoaPfQM?= =?iso-8859-2?q?Xtr5hMC/ClxmQDh5hzFisppGCfRJNyObrZ6rjXQ6cLpiZP86mxeWPgDVqiK+?= =?iso-8859-2?q?pq0Ftors1T1YSQ6Ga6wZmK8uurRw9YC+2jip2PifEFTy+lODwNIL0sAEPGpA?= =?iso-8859-2?q?ul3P65P8J965JRKAaYNyYiBRkXWSE92/r5ottYpBb5CFmXLkeUKKbhUEKwvy?= =?iso-8859-2?q?HFlLIeVL20FI3EoOaF3wqDU4hex5tQWkk0we9xQBrhtcypYfM0bRGBi2EmzV?= =?iso-8859-2?q?LTsyu1Kt22LolFjsBlKBd7FjuhyWDNcJ0Cp2woBrIY2SJTjckP5ojf4oOeBr?= =?iso-8859-2?q?/m+6McmOWkmeNwi6doMXYPWoRAc2gCNPm6X2ZEroJwb7FwQx0yl3kGIM3H9n?= =?iso-8859-2?q?wasuQFuMm10tj0Rr2D8G3l7dJAkWdgUj0DfdUot9Z6Z40bA/bQ0tulp58+cb?= =?iso-8859-2?q?ZurDs/g8M6ln5nC+hKBCjYMQl9Zx3v3d5DtN1dmaJcvgot0u+nNqSwBqliRS?= =?iso-8859-2?q?OEoNbMlRZpHTZ1Tc97Vzx37q+58jfiNsxcP+LcWYZrRAw0I43se/CRVeK+TD?= =?iso-8859-2?q?5zqJFBAgTZVI4F8WgBfrZZ+qKKoyn30zBBCMXy9uF6AIw4OvgX7xOugcmiQM?= =?iso-8859-2?q?QFdqPTqZa28KsemUWWa2aE04D6elU8aMAfgKQO4vACkMT8TAc8b7fo/6ZVur?= =?iso-8859-2?q?MuWi4cy166LEGdl6Z8EkNHFKtb/fNCZvLtgjYDH3nZu/SxWtJgNrfd/ejr6q?= =?iso-8859-2?q?C64FEMke+skkMZMjePhgvASOI0rQRnJX0qz6SJT7N7O25RCG4Srk2fpWRhXk?= =?iso-8859-2?q?fgq6weQxYqLlx+wK+asjOXYYlm1BhHt6WUPpkoYzEJDG5XdzebeVmkKZpWZJ?= =?iso-8859-2?q?Qg4f4WMByqq8AQw6AvApGFZmc09MSBLnZZ/IOO3EDNzKPFx2D/nlmCth00Oc?= =?iso-8859-2?q?kmtrbdOebWR2iPtvnl9sBZ2BjfxkNBXCGtM0kMlgzVcBVTe13MYjsUD7BiTN?= =?iso-8859-2?q?6gJfZ/zdZRAU0F0EfWf81w8SKFHt930zqsR4WlhsaCf1zh8lFM1AOx/py7YL?= =?iso-8859-2?q?kPKYrwIMeVDKjVMAdY439oRQNCfkr+IS2qjVo9E9L1gKFgCtGfWuARoHG+tO?= =?iso-8859-2?q?0gvFC?= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW4PR21MB2002.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a4fa2991-034c-423e-c0f3-08d976dd0ffc X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Sep 2021 17:36:46.9225 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: dmWAksxVL+vkvdyDzSckacIUhdD//L39cZCzC2HHa39IX5iit+X/PypnJM7hH1WR5SrFBRZzwXq1AqL/c6xW5H4eRGvIhzf9LMPYDtcxa2Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR21MB0830 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org This patch makes the Hyper-V vPCI code architectural neutral by moving the architectural dependent pieces into arch specific code. This allows for the implementation of Hyper-V vPCI for other architecture such as ARM64. There are no functional changes expected from this patch. Signed-off-by: Sunil Muthuswamy --- arch/x86/include/asm/hyperv-tlfs.h | 33 ++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 25 ++++++++++++++++ drivers/pci/controller/pci-hyperv.c | 44 +++++++++++++++++++---------- include/asm-generic/hyperv-tlfs.h | 33 ---------------------- 4 files changed, 87 insertions(+), 48 deletions(-) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index 2322d6bd5883..fdf3d28fbdd5 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -585,6 +585,39 @@ enum hv_interrupt_type { HV_X64_INTERRUPT_TYPE_MAXIMUM = 0x000A, }; +union hv_msi_address_register { + u32 as_uint32; + struct { + u32 reserved1:2; + u32 destination_mode:1; + u32 redirection_hint:1; + u32 reserved2:8; + u32 destination_id:8; + u32 msi_base:12; + }; +} __packed; + +union hv_msi_data_register { + u32 as_uint32; + struct { + u32 vector:8; + u32 delivery_mode:3; + u32 reserved1:3; + u32 level_assert:1; + u32 trigger_mode:1; + u32 reserved2:16; + }; +} __packed; + +/* HvRetargetDeviceInterrupt hypercall */ +union hv_msi_entry { + u64 as_uint64; + struct { + union hv_msi_address_register address; + union hv_msi_data_register data; + } __packed; +}; + #include #endif diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index adccbc209169..9c53dfef360c 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -10,6 +10,7 @@ #include #include #include +#include typedef int (*hyperv_fill_flush_list_func)( struct hv_guest_mapping_flush_list *flush, @@ -168,6 +169,30 @@ int hyperv_fill_flush_guest_mapping_list( struct hv_guest_mapping_flush_list *flush, u64 start_gfn, u64 end_gfn); +#define hv_msi_handler handle_edge_irq +#define hv_msi_handler_name "edge" +#define hv_msi_prepare pci_msi_prepare +#define hv_msi_irq_delivery_mode APIC_DELIVERY_MODE_FIXED + +static inline struct irq_domain *hv_msi_parent_vector_domain(void) +{ + return x86_vector_domain; +} + +static inline unsigned int hv_msi_get_int_vector(struct irq_data *data) +{ + struct irq_cfg *cfg = irqd_cfg(data); + + return cfg->vector; +} + +static inline int hv_pci_arch_init(void) +{ + return 0; +} + +static inline void hv_pci_arch_free(void) {} + #ifdef CONFIG_X86_64 void hv_apic_init(void); void __init hv_init_spinlocks(void); diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 62dbe98d1fe1..b7213b57b4ec 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -44,8 +44,8 @@ #include #include #include -#include -#include +//#include +//#include #include #include #include @@ -1192,7 +1192,6 @@ static void hv_irq_mask(struct irq_data *data) static void hv_irq_unmask(struct irq_data *data) { struct msi_desc *msi_desc = irq_data_get_msi_desc(data); - struct irq_cfg *cfg = irqd_cfg(data); struct hv_retarget_device_interrupt *params; struct hv_pcibus_device *hbus; struct cpumask *dest; @@ -1221,11 +1220,12 @@ static void hv_irq_unmask(struct irq_data *data) (hbus->hdev->dev_instance.b[7] << 8) | (hbus->hdev->dev_instance.b[6] & 0xf8) | PCI_FUNC(pdev->devfn); - params->int_target.vector = cfg->vector; + params->int_target.vector = hv_msi_get_int_vector(data); /* - * Honoring apic->delivery_mode set to APIC_DELIVERY_MODE_FIXED by - * setting the HV_DEVICE_INTERRUPT_TARGET_MULTICAST flag results in a + * For x64, honoring apic->delivery_mode set to + * APIC_DELIVERY_MODE_FIXED by setting the + * HV_DEVICE_INTERRUPT_TARGET_MULTICAST flag results in a * spurious interrupt storm. Not doing so does not seem to have a * negative effect (yet?). */ @@ -1322,7 +1322,7 @@ static u32 hv_compose_msi_req_v1( int_pkt->wslot.slot = slot; int_pkt->int_desc.vector = vector; int_pkt->int_desc.vector_count = 1; - int_pkt->int_desc.delivery_mode = APIC_DELIVERY_MODE_FIXED; + int_pkt->int_desc.delivery_mode = hv_msi_irq_delivery_mode; /* * Create MSI w/ dummy vCPU set, overwritten by subsequent retarget in @@ -1343,7 +1343,7 @@ static u32 hv_compose_msi_req_v2( int_pkt->wslot.slot = slot; int_pkt->int_desc.vector = vector; int_pkt->int_desc.vector_count = 1; - int_pkt->int_desc.delivery_mode = APIC_DELIVERY_MODE_FIXED; + int_pkt->int_desc.delivery_mode = hv_msi_irq_delivery_mode; /* * Create MSI w/ dummy vCPU set targeting just one vCPU, overwritten @@ -1370,7 +1370,6 @@ static u32 hv_compose_msi_req_v2( */ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) { - struct irq_cfg *cfg = irqd_cfg(data); struct hv_pcibus_device *hbus; struct vmbus_channel *channel; struct hv_pci_dev *hpdev; @@ -1420,7 +1419,7 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) size = hv_compose_msi_req_v1(&ctxt.int_pkts.v1, dest, hpdev->desc.win_slot.slot, - cfg->vector); + hv_msi_get_int_vector(data)); break; case PCI_PROTOCOL_VERSION_1_2: @@ -1428,7 +1427,7 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) size = hv_compose_msi_req_v2(&ctxt.int_pkts.v2, dest, hpdev->desc.win_slot.slot, - cfg->vector); + hv_msi_get_int_vector(data)); break; default: @@ -1544,7 +1543,7 @@ static struct irq_chip hv_msi_irq_chip = { }; static struct msi_domain_ops hv_msi_ops = { - .msi_prepare = pci_msi_prepare, + .msi_prepare = hv_msi_prepare, .msi_free = hv_msi_free, }; @@ -1563,17 +1562,26 @@ static struct msi_domain_ops hv_msi_ops = { */ static int hv_pcie_init_irq_domain(struct hv_pcibus_device *hbus) { + struct irq_domain *parent_domain; + + parent_domain = hv_msi_parent_vector_domain(); + if (!parent_domain) { + dev_err(&hbus->hdev->device, + "Failed to get parent MSI domain\n"); + return -ENODEV; + } + hbus->msi_info.chip = &hv_msi_irq_chip; hbus->msi_info.ops = &hv_msi_ops; hbus->msi_info.flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS | MSI_FLAG_MULTI_PCI_MSI | MSI_FLAG_PCI_MSIX); - hbus->msi_info.handler = handle_edge_irq; - hbus->msi_info.handler_name = "edge"; + hbus->msi_info.handler = hv_msi_handler; + hbus->msi_info.handler_name = hv_msi_handler_name; hbus->msi_info.data = hbus; hbus->irq_domain = pci_msi_create_irq_domain(hbus->fwnode, &hbus->msi_info, - x86_vector_domain); + parent_domain); if (!hbus->irq_domain) { dev_err(&hbus->hdev->device, "Failed to build an MSI IRQ domain\n"); @@ -3478,9 +3486,15 @@ static void __exit exit_hv_pci_drv(void) static int __init init_hv_pci_drv(void) { + int ret; + if (!hv_is_hyperv_initialized()) return -ENODEV; + ret = hv_pci_arch_init(); + if (ret) + return ret; + /* Set the invalid domain number's bit, so it will not be used */ set_bit(HVPCI_DOM_INVALID, hvpci_dom_map); diff --git a/include/asm-generic/hyperv-tlfs.h b/include/asm-generic/hyperv-tlfs.h index 56348a541c50..45cc0c3b8ed7 100644 --- a/include/asm-generic/hyperv-tlfs.h +++ b/include/asm-generic/hyperv-tlfs.h @@ -539,39 +539,6 @@ enum hv_interrupt_source { HV_INTERRUPT_SOURCE_IOAPIC, }; -union hv_msi_address_register { - u32 as_uint32; - struct { - u32 reserved1:2; - u32 destination_mode:1; - u32 redirection_hint:1; - u32 reserved2:8; - u32 destination_id:8; - u32 msi_base:12; - }; -} __packed; - -union hv_msi_data_register { - u32 as_uint32; - struct { - u32 vector:8; - u32 delivery_mode:3; - u32 reserved1:3; - u32 level_assert:1; - u32 trigger_mode:1; - u32 reserved2:16; - }; -} __packed; - -/* HvRetargetDeviceInterrupt hypercall */ -union hv_msi_entry { - u64 as_uint64; - struct { - union hv_msi_address_register address; - union hv_msi_data_register data; - } __packed; -}; - union hv_ioapic_rte { u64 as_uint64; From patchwork Mon Sep 13 17:37:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil Muthuswamy X-Patchwork-Id: 1527522 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=microsoft.com header.i=@microsoft.com header.a=rsa-sha256 header.s=selector2 header.b=hgUFKGNN; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4H7YZw2WCxz9sRN for ; Tue, 14 Sep 2021 03:37:28 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238180AbhIMRim (ORCPT ); Mon, 13 Sep 2021 13:38:42 -0400 Received: from mail-eastus2namln1000.outbound.protection.outlook.com ([40.93.3.0]:55903 "EHLO na01-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S240913AbhIMRim (ORCPT ); Mon, 13 Sep 2021 13:38:42 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gvr79oUMz9REvs8oDzcRXxQCPp1asoHzf82PbDtE4eamS0JITBN1w2/6Tb1rKeAJiCRmvtbKBWQ4LVq51xsxqe/ag9rICIXCq/R9+d9Aj6OoBHDQibm0j6Omtsdlv+Rml77uGC4WoZfk/iniKTTdIRSlFlPQEyHiF9wy3LNFbX0pCaWZ7vPb5sfT8PCHBiJnuy9Ul8a7Kve16ONInMauO3fnxnZyazYChmUQcxsVjv/YSzqRh/ZRPNDPKZhQvPyR+30c6REquKLWlAc3qmLHTHRMsCQSy0vWbFzQueD9VpGCXTQumz9Is9XcQ9j9DZzT5w1P0LXXbo96KHtOxkPqwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=wZ4vfdnXyfCY1rndNdfbMT0RKnEZLeX62cMJjI4dwF8=; b=KA6ZtJkZh3FLdcvq4Ru3YbIzTrN6AFSq/49B5RBX/nVqAMARV/2OSGBRXxLuUDuZQk5iO00a9Dxaz5N0CtwSEJwsavNuEdKbBYRj/Q/vRynzG4CxC0FPXSn186fGnRnp5Bq7XN2NuLNJINx7cvB4ZPPoZ6+9rl50DsL+J5+NGhHDydK6QXrvAC0Mnsoels8xFYCi45SotJBVCECSHTSfQBm5UHLCnwxN/bBxSqS1HmCgIiElYnVj1Ibs8RqLMma1QeFb37jqU9LQuvCHTFD++1SoVgABCWeKvDkpb9r+dYM4rtGdxopY0mwA8u5FwPy00Udmy3hEa1bhemernnm6jA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wZ4vfdnXyfCY1rndNdfbMT0RKnEZLeX62cMJjI4dwF8=; b=hgUFKGNNvMhycG3k1zpA8utxESiYB2I95fX8x62kUnz0djNTYnfkb60UNiR3JjKiE0QTvCk01rbdNeQ/T+WJYpIxjFSbdp8buMZ0vd1wbDHrXUCJwawR6WG0nFZrozg8h/Mj6HqC50uENRwsvymklaLB0A4b857nfVLQzkRNXLk= Received: from MW4PR21MB2002.namprd21.prod.outlook.com (2603:10b6:303:68::18) by MWHPR21MB0830.namprd21.prod.outlook.com (2603:10b6:300:76::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.8; Mon, 13 Sep 2021 17:37:22 +0000 Received: from MW4PR21MB2002.namprd21.prod.outlook.com ([fe80::b134:7809:fcff:8c8b]) by MW4PR21MB2002.namprd21.prod.outlook.com ([fe80::b134:7809:fcff:8c8b%4]) with mapi id 15.20.4523.011; Mon, 13 Sep 2021 17:37:22 +0000 From: Sunil Muthuswamy To: Michael Kelley , Boqun Feng , KY Srinivasan , Haiyang Zhang , Stephen Hemminger , Dexuan Cui , Lorenzo Pieralisi , Rob Herring , =?iso-8859-2?q?=22Krzysztof_Wilczy=F1ski=22?= , Bjorn Helgaas , Wei Liu CC: "linux-hyperv@vger.kernel.org" , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH 2/2] PCI: hv: Support for Hyper-V vPCI for ARM64 Thread-Topic: [PATCH 2/2] PCI: hv: Support for Hyper-V vPCI for ARM64 Thread-Index: AdeoxTZsllWVtNf9RIGrn88zMhJayQ== Date: Mon, 13 Sep 2021 17:37:22 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d1a9e7dc-5381-4b89-6d02-08d976dd24d3 x-ms-traffictypediagnostic: MWHPR21MB0830: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4303; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 6IFP8nb78+LjS1hVnFy1ppT7pDeFUjtI61WG5sxcIZ/8MyhNeyLGPkZPFHtlWGpW1z45rETz1KTaslVYOLXDIs/rCaJ3qcUINc6CF38til5gKYUfATg/D/KFKxIGJJgpUOZVw3sjjDMNk6mfefuvvln4m0iQSO5k53tvPIFHLmUqkAUT39h/q3ZK4qoNDEalMUm+yqM/BqBhhIFcdX6WCkivht9FOzzO9/DhookyodyB6CRw7LuQ8HRPOq+/u2tzqN6ahcO7HDFLzshDBKGqFwJpkTPypB92nKLQczaXJG6RYKefN9rfVAEUBis3HFGDIylW0qSdTrEZt/h+Hnl9/moGsS4cWmFjCe1xWCPj+3LMOe/N3i8iYA4CjzXdxcjEKDDkJ7bg13A4zhZHss7p4YhRoH8PJCHIFz+2drdjt9b6YAjIflbF85cpVI86zSunGKnJnYjYgp/dpjRMHDhY9JoAJ2i4JpKjkLhVIAqUnAV1qRAlovoD+k6WZm3Onzb4IjTy+viVs81bONrsLEcEnUKFnrkyPDxooA3x2hg6ISOthRqtFeO95e0ztqbLJNyFhUKm0TxTNUsrKVYcWeF7eMjK1SwfEcLF+f/1+fs+YoSMZ/C3SnSDknFYUn4U78k/wOn5Lp33/ckYaxf9LE8e+lbY/AHg9yNSk6PS7D6b1yON94c/oLTgfIWWysnPcD1tZx8OIpTlqV9q0OfE2BH2dSjRrTYlZsNTSYYlvgP4u2vi5GaW59O8vtNJJ8Byfiqr x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW4PR21MB2002.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(6506007)(9686003)(508600001)(76116006)(55016002)(52536014)(83380400001)(7696005)(38070700005)(71200400001)(33656002)(30864003)(66446008)(64756008)(82950400001)(66556008)(66476007)(82960400001)(66946007)(86362001)(38100700002)(186003)(122000001)(921005)(8676002)(8936002)(8990500004)(2906002)(4326008)(316002)(54906003)(110136005)(10290500003)(5660300002)(2004002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-2?q?9kBMSc5D0OY6LRSLKvvIsao?= =?iso-8859-2?q?+3N8VYjjUHoLbZlz53MYu96hLBkQTvGlaLRiiIiL1UxbvwqVcjATPpRQMYC6?= =?iso-8859-2?q?kWrS5fXeoIJI699HDBUA2micyj86NcHdCcbOAEpjJ68H7Bsjl2gr5bO8QaEs?= =?iso-8859-2?q?Q6F/C12fpCAO2wB80Q2vuB8xmmCpq7v7jSlwxQVXV9Brsetxq4w85KY6Booo?= =?iso-8859-2?q?AwnfTi+M6hQ8+8AQfP7KJVv80NCpZNnFtkPeorMc+NM02q6R3MUjz+jEY2Lx?= =?iso-8859-2?q?bR1jxvu5mIBXCyPMwAzb/B/IpD89Xltq7tLk9QsGFrzr3+EEO0XSOlz2SU7b?= =?iso-8859-2?q?RP1BxIpYwIKMtx/nk065vl3Wt7XLZ6Dkpjx+KBzSHyOI6Ay7Wu7NwyUNgVQq?= =?iso-8859-2?q?A81+T65p7XJr5EPphthCaAAW2+p3s92tRKOKIiFH7PSoXnaOtajkxfnYcuMn?= =?iso-8859-2?q?dHYrp7R7+/RlYIxuNpdcw2eDzBtYsHyEI+0zbS3Y1z9AOnl1UraCLZaY1sqD?= =?iso-8859-2?q?n5uj5dsWckZzRprTEeaD+Yj9gYEa1iJbe9QAdTWt20MyDb8TdB+kYIpnRvsx?= =?iso-8859-2?q?2PTTN0DlBnvSfQ5tINwJM8W5a9d+3klRKIxBP+XbkfqKp7lBeB0A0k1JfrwX?= =?iso-8859-2?q?ztquv1q7XiKOSM7olREYbEDh7Y+jgTL4lIWOuy2cfsDUycpSPlwGx1iseVHc?= =?iso-8859-2?q?RVjsM3MGlg7ufP2AsT6XxvBu0wH/jDLoKreFHLBhwoQm6ivxd+OA3QvOkv3F?= =?iso-8859-2?q?A6lLorAEKpgwXTaklRjLPfbcoMj0W1O4df9g+kQ5bkpjH3OlaAZe95QSzNZP?= =?iso-8859-2?q?b7VCkCF/BvFh5a5owP4duPnUPb+o/Dv/b4bd2KQ8vNnIIYSwVX9WtSB5aCzn?= =?iso-8859-2?q?1vNFgN7kLpqdzbkEvnahrR6C1SdEtYQvh7GUSN27u1PpOiWxwKRXBAdr/7or?= =?iso-8859-2?q?xnWW5svOWwXqnmHhU++cMkvd0jUvaTs76TLbcTeL1dLTEKvfncRvzMHEmtiJ?= =?iso-8859-2?q?BmWPX34jsUXYG3eMaY/D3onWTqnoldoJgqLQxGCk2oQBVDiBh22iMOj4o7FV?= =?iso-8859-2?q?/gII7Z95idDz9DUxIbwDr7nCe58VP7py6egEO/11gvEvkkalABh4RQxhE8xo?= =?iso-8859-2?q?c3nn+OR+XhXyGrsr7fnxLCfyzwC0l4tWYX9jWtut2aSDCodAhMEG6bF1J0U3?= =?iso-8859-2?q?PhGDamiygERcMd2QQ0qyBa+oNKkWCvOEhu/wO5BjC72HQ/z03VYggMD1ZLwM?= =?iso-8859-2?q?VKlkNmJT8Y9WUL8NUZRbqTRqEAoy8Hb0kiTIPRnlPTwfXVjZcf+xbs5KuOmO?= =?iso-8859-2?q?fC9kIKjNRPb8q/RPXISal006uwicvLYz/2SrtDkOWx0MR2O6rjFy2mSeIKy7?= =?iso-8859-2?q?jX4GdJiBFFGyKrKGSysGHOMOgPJEqLcZBss6IPag75nNttuzxduCHI0QIwZ5?= =?iso-8859-2?q?DEi1O?= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW4PR21MB2002.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d1a9e7dc-5381-4b89-6d02-08d976dd24d3 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Sep 2021 17:37:22.5997 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 6xvDXWhFD/QwrlqgUpwPM0oqx+Nbx8diJOpaYCjfXsMOB26CMrP9YxZ+PE/64Rfw9RY4I4qVbJvkpPmY/jEU5KIoPU6GOazNrYAxeftx7EI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR21MB0830 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org This patch adds support for Hyper-V vPCI by adding a PCI MSI IRQ domain specific to Hyper-V that is based on SPIs. The IRQ domain parents itself to the arch GIC IRQ domain for basic vector management. Signed-off-by: Sunil Muthuswamy --- arch/arm64/hyperv/Makefile | 2 +- arch/arm64/hyperv/hv_pci.c | 275 +++++++++++++++++++++++++++ arch/arm64/include/asm/hyperv-tlfs.h | 9 + arch/arm64/include/asm/mshyperv.h | 26 +++ drivers/pci/Kconfig | 2 +- drivers/pci/controller/Kconfig | 2 +- drivers/pci/controller/pci-hyperv.c | 5 + 7 files changed, 318 insertions(+), 3 deletions(-) create mode 100644 arch/arm64/hyperv/hv_pci.c diff --git a/arch/arm64/hyperv/Makefile b/arch/arm64/hyperv/Makefile index 87c31c001da9..af7a66e43ef4 100644 --- a/arch/arm64/hyperv/Makefile +++ b/arch/arm64/hyperv/Makefile @@ -1,2 +1,2 @@ # SPDX-License-Identifier: GPL-2.0 -obj-y := hv_core.o mshyperv.o +obj-y := hv_core.o mshyperv.o hv_pci.o diff --git a/arch/arm64/hyperv/hv_pci.c b/arch/arm64/hyperv/hv_pci.c new file mode 100644 index 000000000000..06179e4a6a2d --- /dev/null +++ b/arch/arm64/hyperv/hv_pci.c @@ -0,0 +1,275 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Architecture specific vector management for the Hyper-V vPCI. + * + * Copyright (C) 2018, Microsoft, Inc. + * + * Author : Sunil Muthuswamy + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or + * NON INFRINGEMENT. See the GNU General Public License for more + * details. + */ + +#include +#include +#include +#include +#include + +/* + * SPI vectors to use for vPCI; arch SPIs range is [32, 1019], but leaving a bit + * of room at the start to allow for SPIs to be specified through ACPI. + */ +#define HV_PCI_MSI_SPI_START 50 +#define HV_PCI_MSI_SPI_NR (1020 - HV_PCI_MSI_SPI_START) + +struct hv_pci_chip_data { + spinlock_t lock; + DECLARE_BITMAP(bm, HV_PCI_MSI_SPI_NR); +}; + +/* Hyper-V vPCI MSI GIC IRQ domain */ +static struct irq_domain *hv_msi_gic_irq_domain; + +static struct irq_chip hv_msi_irq_chip = { + .name = "Hyper-V ARM64 PCI MSI", + .irq_set_affinity = irq_chip_set_affinity_parent, + .irq_eoi = irq_chip_eoi_parent, + .irq_mask = irq_chip_mask_parent, + .irq_unmask = irq_chip_unmask_parent +}; + +/** + * Frees the specified number of interrupts. + * @domain: The IRQ domain + * @virq: The virtual IRQ number. + * @nr_irqs: Number of IRQ's to free. + */ +static void hv_pci_vec_irq_domain_free(struct irq_domain *domain, + unsigned int virq, unsigned int nr_irqs) +{ + struct hv_pci_chip_data *chip_data = domain->host_data; + unsigned long flags; + unsigned int i; + + for (i = 0; i < nr_irqs; i++) { + struct irq_data *irqd = irq_domain_get_irq_data(domain, + virq + i); + + spin_lock_irqsave(&chip_data->lock, flags); + clear_bit(irqd->hwirq - HV_PCI_MSI_SPI_START, chip_data->bm); + spin_unlock_irqrestore(&chip_data->lock, flags); + irq_domain_reset_irq_data(irqd); + } + + irq_domain_free_irqs_parent(domain, virq, nr_irqs); +} + +/** + * Allocate an interrupt from the domain. + * @hwirq: Will be set to the allocated H/W IRQ. + * + * Return: 0 on success and error value on failure. + */ +static int hv_pci_vec_alloc_device_irq(struct irq_domain *domain, + unsigned int virq, irq_hw_number_t *hwirq) +{ + struct hv_pci_chip_data *chip_data = domain->host_data; + unsigned long flags; + unsigned int index; + + spin_lock_irqsave(&chip_data->lock, flags); + index = find_first_zero_bit(chip_data->bm, HV_PCI_MSI_SPI_NR); + if (index == HV_PCI_MSI_SPI_NR) { + spin_unlock_irqrestore(&chip_data->lock, flags); + pr_err("No more free IRQ vector available\n"); + return -ENOSPC; + } + + set_bit(index, chip_data->bm); + spin_unlock_irqrestore(&chip_data->lock, flags); + *hwirq = index + HV_PCI_MSI_SPI_START; + + return 0; +} + +/** + * Allocate an interrupt from the parent GIC domain. + * @domain: The IRQ domain. + * @virq: The virtual IRQ number. + * @hwirq: The H/W IRQ number that needs to be allocated. + * + * Return: 0 on success and error value on failure. + */ +static int hv_pci_vec_irq_gic_domain_alloc(struct irq_domain *domain, + unsigned int virq, + irq_hw_number_t hwirq) +{ + struct irq_fwspec fwspec; + + fwspec.fwnode = domain->parent->fwnode; + fwspec.param_count = 2; + fwspec.param[0] = hwirq; + fwspec.param[1] = IRQ_TYPE_EDGE_RISING; + + return irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec); +} + +/** + * Allocate specified number of interrupts from the domain. + * @domain: The IRQ domain. + * @virq: The starting virtual IRQ number. + * @nr_irqs: Number of IRQ's to allocate. + * @args: The MSI alloc information. + * + * Return: 0 on success and error value on failure. + */ +static int hv_pci_vec_irq_domain_alloc(struct irq_domain *domain, + unsigned int virq, unsigned int nr_irqs, + void *args) +{ + irq_hw_number_t hwirq; + unsigned int i; + int ret; + + for (i = 0; i < nr_irqs; i++) { + ret = hv_pci_vec_alloc_device_irq(domain, virq, &hwirq); + if (ret) + goto free_irq; + + ret = hv_pci_vec_irq_gic_domain_alloc(domain, virq + i, hwirq); + if (ret) + goto free_irq; + + ret = irq_domain_set_hwirq_and_chip(domain, virq + i, + hwirq, &hv_msi_irq_chip, + domain->host_data); + if (ret) + goto free_irq; + + irqd_set_single_target(irq_desc_get_irq_data(irq_to_desc(virq + i))); + pr_debug("pID:%d vID:%u\n", (int)hwirq, virq + i); + } + + return 0; + +free_irq: + if (i > 0) + hv_pci_vec_irq_domain_free(domain, virq, i - 1); + + return ret; +} + +/** + * Activate the interrupt. + * @domain: The IRQ domain. + * @irqd: IRQ data. + * @reserve: Indicates whether the IRQ's can be reserved. + * + * Return: 0 on success and error value on failure. + */ +static int hv_pci_vec_irq_domain_activate(struct irq_domain *domain, + struct irq_data *irqd, bool reserve) +{ + /* All available online CPUs are available for targeting */ + irq_data_update_effective_affinity(irqd, cpu_online_mask); + return 0; +} + +static const struct irq_domain_ops hv_pci_domain_ops = { + .alloc = hv_pci_vec_irq_domain_alloc, + .free = hv_pci_vec_irq_domain_free, + .activate = hv_pci_vec_irq_domain_activate, +}; + + +/** + * This routine performs the architecture specific initialization for vector + * domain to operate. It allocates an IRQ domain tree as a child of the GIC + * IRQ domain. + * + * Return: 0 on success and error value on failure. + */ +int hv_pci_vector_init(void) +{ + static struct hv_pci_chip_data *chip_data; + struct fwnode_handle *fn = NULL; + int ret = -ENOMEM; + + chip_data = kzalloc(sizeof(*chip_data), GFP_KERNEL); + if (!chip_data) + return ret; + + spin_lock_init(&chip_data->lock); + fn = irq_domain_alloc_named_fwnode("Hyper-V ARM64 vPCI"); + if (!fn) + goto free_chip; + + hv_msi_gic_irq_domain = acpi_irq_create_hierarchy(0, HV_PCI_MSI_SPI_NR, + fn, &hv_pci_domain_ops, chip_data); + + if (!hv_msi_gic_irq_domain) { + pr_err("Failed to create Hyper-V ARMV vPCI MSI IRQ domain\n"); + goto free_chip; + } + + return 0; + +free_chip: + kfree(chip_data); + if (fn) + irq_domain_free_fwnode(fn); + + return ret; +} + +/* This routine performs the cleanup for the IRQ domain. */ +void hv_pci_vector_free(void) +{ + static struct hv_pci_chip_data *chip_data; + + if (!hv_msi_gic_irq_domain) + return; + + /* Host data cannot be null if the domain was created successfully */ + chip_data = hv_msi_gic_irq_domain->host_data; + irq_domain_remove(hv_msi_gic_irq_domain); + hv_msi_gic_irq_domain = NULL; + kfree(chip_data); +} + +/* Performs the architecture specific initialization for Hyper-V vPCI. */ +int hv_pci_arch_init(void) +{ + return hv_pci_vector_init(); +} +EXPORT_SYMBOL_GPL(hv_pci_arch_init); + +/* Architecture specific cleanup for Hyper-V vPCI. */ +void hv_pci_arch_free(void) +{ + hv_pci_vector_free(); +} +EXPORT_SYMBOL_GPL(hv_pci_arch_free); + +struct irq_domain *hv_msi_parent_vector_domain(void) +{ + return hv_msi_gic_irq_domain; +} +EXPORT_SYMBOL_GPL(hv_msi_parent_vector_domain); + +unsigned int hv_msi_get_int_vector(struct irq_data *irqd) +{ + irqd = irq_domain_get_irq_data(hv_msi_gic_irq_domain, irqd->irq); + + return irqd->hwirq; +} +EXPORT_SYMBOL_GPL(hv_msi_get_int_vector); diff --git a/arch/arm64/include/asm/hyperv-tlfs.h b/arch/arm64/include/asm/hyperv-tlfs.h index 4d964a7f02ee..bc6c7ac934a1 100644 --- a/arch/arm64/include/asm/hyperv-tlfs.h +++ b/arch/arm64/include/asm/hyperv-tlfs.h @@ -64,6 +64,15 @@ #define HV_REGISTER_STIMER0_CONFIG 0x000B0000 #define HV_REGISTER_STIMER0_COUNT 0x000B0001 +union hv_msi_entry { + u64 as_uint64[2]; + struct { + u64 address; + u32 data; + u32 reserved; + } __packed; +}; + #include #endif diff --git a/arch/arm64/include/asm/mshyperv.h b/arch/arm64/include/asm/mshyperv.h index 20070a847304..68bc1617707b 100644 --- a/arch/arm64/include/asm/mshyperv.h +++ b/arch/arm64/include/asm/mshyperv.h @@ -20,6 +20,8 @@ #include #include +#include +#include #include /* @@ -49,6 +51,30 @@ static inline u64 hv_get_register(unsigned int reg) ARM_SMCCC_OWNER_VENDOR_HYP, \ HV_SMCCC_FUNC_NUMBER) +#define hv_msi_handler NULL +#define hv_msi_handler_name NULL +#define hv_msi_irq_delivery_mode 0 +#define hv_msi_prepare NULL + +int hv_pci_arch_init(void); +void hv_pci_arch_free(void); +struct irq_domain *hv_msi_parent_vector_domain(void); +unsigned int hv_msi_get_int_vector(struct irq_data *data); +static inline irq_hw_number_t +hv_msi_domain_ops_get_hwirq(struct msi_domain_info *info, + msi_alloc_info_t *arg) +{ + return arg->hwirq; +} + +static inline void hv_set_msi_entry_from_desc(union hv_msi_entry *msi_entry, + struct msi_desc *msi_desc) +{ + msi_entry->address = ((u64)msi_desc->msg.address_hi << 32) | + msi_desc->msg.address_lo; + msi_entry->data = msi_desc->msg.data; +} + #include #endif diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index 0c473d75e625..36dc94407510 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig @@ -184,7 +184,7 @@ config PCI_LABEL config PCI_HYPERV tristate "Hyper-V PCI Frontend" - depends on X86_64 && HYPERV && PCI_MSI && PCI_MSI_IRQ_DOMAIN && SYSFS + depends on (X86_64 || ARM64) && HYPERV && PCI_MSI && PCI_MSI_IRQ_DOMAIN && SYSFS select PCI_HYPERV_INTERFACE help The PCI device frontend driver allows the kernel to import arbitrary diff --git a/drivers/pci/controller/Kconfig b/drivers/pci/controller/Kconfig index 5e1e3796efa4..8a19a3dc339c 100644 --- a/drivers/pci/controller/Kconfig +++ b/drivers/pci/controller/Kconfig @@ -279,7 +279,7 @@ config PCIE_BRCMSTB config PCI_HYPERV_INTERFACE tristate "Hyper-V PCI Interface" - depends on X86 && HYPERV && PCI_MSI && PCI_MSI_IRQ_DOMAIN && X86_64 + depends on (X86_64 || ARM64) && HYPERV && PCI_MSI && PCI_MSI_IRQ_DOMAIN help The Hyper-V PCI Interface is a helper driver allows other drivers to have a common interface with the Hyper-V PCI frontend driver. diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index b7213b57b4ec..79a29a18e84e 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1177,6 +1177,8 @@ static int hv_set_affinity(struct irq_data *data, const struct cpumask *dest, static void hv_irq_mask(struct irq_data *data) { pci_msi_mask_irq(data); + if (data->parent_data->chip->irq_mask) + irq_chip_mask_parent(data); } /** @@ -1294,6 +1296,8 @@ static void hv_irq_unmask(struct irq_data *data) dev_err(&hbus->hdev->device, "%s() failed: %#llx", __func__, res); + if (data->parent_data->chip->irq_unmask) + irq_chip_unmask_parent(data); pci_msi_unmask_irq(data); } @@ -1538,6 +1542,7 @@ static struct irq_chip hv_msi_irq_chip = { .irq_compose_msi_msg = hv_compose_msi_msg, .irq_set_affinity = hv_set_affinity, .irq_ack = irq_chip_ack_parent, + .irq_eoi = irq_chip_eoi_parent, .irq_mask = hv_irq_mask, .irq_unmask = hv_irq_unmask, };