From patchwork Fri Oct 8 17:20:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil Muthuswamy X-Patchwork-Id: 12545847 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CDF1C433EF for ; Fri, 8 Oct 2021 17:20:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B6C461058 for ; Fri, 8 Oct 2021 17:20:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238227AbhJHRWh (ORCPT ); Fri, 8 Oct 2021 13:22:37 -0400 Received: from mail-oln040093003008.outbound.protection.outlook.com ([40.93.3.8]:60035 "EHLO na01-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S238230AbhJHRWg (ORCPT ); Fri, 8 Oct 2021 13:22:36 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YtwTPqz4P/sc9eiSXuzZEiBEn3O1eaYrlyBziR9BvECyaNDYx/r2FH/TMn3f4M7eCagKv+g2zxUYzzoLpjZWy+yv2umNeXqTKJ9YpDTFMZ1MAWPjzhyvXfR5UH0qoiZH6yZPRhS2uNcVopNKyc6H6Tid/po45ONL9LH0/Je6S0Xp2KqdIZn+uVfilp0ZvlnyiSQZ/7zOvbFLmnPOOxMm4L7u/7SBJlVVRuXfq5MoXP1fKDG8oeCY5LPt9ZbpfNye6EgnhDwQGVvxYNQPJ9pyqEWJc8IQoz5UPlTHjJybrfEmI+mGAGbRwOo8MQ/8wGaC/gSrPMOevis38EoyW3b7Gg== 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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6X4yc5p3EzdfW6Hrfw/xfS7h7zQHX09/4wr0MYvzs1Y=; b=CGBL3l9zsWzAFXH69MPORXjtx8QzD7tJ+vSNl7qCQ4NIU0iSCpYVDEXpo0eSyNCXxizdvaddrQCUrHh82j83L98vA3s/kV4yqQDP/5lzNouWkQEc1ddjqZrSTlbQv2APUI0ix8Jf2ANSWrV+YzczequEyOK9t6CqjFEhoarHQNo8PTUhf9tHscYX2vTrE7McV/7WREKgXeprng2i9815mCpdwuj6spfu3rVWgRSYcYJeXWoV8coqnaHQsFzhAuc1PKaoxzelkDusFcJbYB9nb/Jy/0NsY4eoptiioKeJjBMk6l/69+6whly9+Esuugz9bGtfCg74OrsNFzIXK8FJaw== 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=6X4yc5p3EzdfW6Hrfw/xfS7h7zQHX09/4wr0MYvzs1Y=; b=EhrI8Dv/vrO57haSRqkuLXnEPDX8+JMe/k2JEwWbvKZnQ/aOT/txHWSHaTR/0b9gphuedLuC9iG2hd3lbLH4zlRN2D73daVVxj9Beqt8W+JeWj/d7qbQYtDzj6zk/0+gkJoIV4CduTb9r2Iww5dVRWWY/zdLxfc0VN2rX+l4r6o= Received: from MW4PR21MB2002.namprd21.prod.outlook.com (2603:10b6:303:68::18) by MW2PR2101MB1049.namprd21.prod.outlook.com (2603:10b6:302:a::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.4; Fri, 8 Oct 2021 17:20:36 +0000 Received: from MW4PR21MB2002.namprd21.prod.outlook.com ([fe80::89fe:5bf:5eb2:4c55]) by MW4PR21MB2002.namprd21.prod.outlook.com ([fe80::89fe:5bf:5eb2:4c55%4]) with mapi id 15.20.4608.008; Fri, 8 Oct 2021 17:20:36 +0000 From: Sunil Muthuswamy To: Marc Zyngier , 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: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "\"H. Peter Anvin\"" , Arnd Bergmann , "linux-hyperv@vger.kernel.org" , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH v2 1/2] PCI: hv: Make the code arch neutral Thread-Topic: [PATCH v2 1/2] PCI: hv: Make the code arch neutral Thread-Index: Ade8Z/d+RNK9WO8BTSODIa+n2Enr/Q== Date: Fri, 8 Oct 2021 17:20:35 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ActionId=dde418a1-eb6c-4067-accf-bee5d847478b;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ContentBits=0;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=true;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Method=Standard;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=Internal;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2021-10-08T17:12:22Z;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47; 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: d5760a0e-f24c-45d1-634d-08d98a7ff13b x-ms-traffictypediagnostic: MW2PR2101MB1049: 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: NG7fEDWNfj9VWC9XD3OndIhfZCvvhjCqsKp7u5utoOgVnWDnwZJwh3oJTC8LM5ZhhDg4FNi1LHBEqCt2954PffBFCaoR241g6YZxZkEcU/7aJ778hKfrI7schha9NonjuAPMENJSAz9TDFwaVNCaDRzQkeq3f7bVAtDDL21L0Vc0hArdPkZs5xztDY8U1nvWgctdJupjWuUpc1XqgUYWXO94nEjh4izQsotwB+vlPxrv7xCRd+ZvQ/bYcpT3/I+FO8B6eHCXAND1XPpHRv1yvTQLRNkKcJdlaY75Xqz3lA+TZWXzv6ShN+CEG5Bmrs6pk3gmza9ZKOTdfACO2uUy20GWQ5r0r8lOHNhzdix6JdhwsQn2XObHGsCfKpjieFyzGrlBdqCxJEM7kkmUeZyn1C760hG+Vxy7JLIz+jN+O0EROFgkQvKRJipto2lrZa3w+NdEP39U/Z01WTFDVJ3gSPMhwKW07WEvcfXDcrgJVUXnACaOt9EZZnqs3ZGyRQe+troPAjNLgDSRHAFV6f9FzTG0ABZ40CXbcGjnW5qrabIp7o3KPTdHdgKOR9xsJg6wfIEDyssLde6f+cQRkyiqf8IfxdBFSUuaxqu5RBi7F7Y3yXRqovGvU0NLvsYADcCTLXB7cYjyXl5UzF1zvawGkxDjzRGlIUPXL4b73VFzjWDPpB39naY2nRGoWKwFzAbAOlu/r9M1XrQ4AT82y2Zb/Z4GlGlyfCE6OOBYjhhqJ/0= 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)(38070700005)(71200400001)(8990500004)(86362001)(5660300002)(10290500003)(186003)(4326008)(82950400001)(508600001)(76116006)(66946007)(82960400001)(33656002)(8676002)(6506007)(921005)(122000001)(2906002)(30864003)(66556008)(9686003)(54906003)(66476007)(8936002)(7696005)(316002)(66446008)(64756008)(38100700002)(83380400001)(110136005)(55016002)(7416002)(52536014);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-2?q?2xJnXocvIt7hMQCaxS2xbnW?= =?iso-8859-2?q?83s92cBhnUDHaIm4NK0xJmK/QpGFXnZieAW/fO6kQSsRuHdPWbo08j+kNtRY?= =?iso-8859-2?q?JbDYt8YfHOry5zeXcW1mZ3DAsmU4ISBLp8kEi8kXOrPUvU9A6KrBypJhcN0Q?= =?iso-8859-2?q?rbHbDZwgUWHIDcb6TDDPyBnpul0vdCm+/tK1p+iGaLdsmobC8b6y+fm/4Sev?= =?iso-8859-2?q?ti3XE6kmE18jL65oviPQO8E6a3HdeXMYBhmK1rxz1ODQwTolBSpWPID93Jvq?= =?iso-8859-2?q?HvTjBmUIgKDMWcF1M9fc2S1y1VgyIFu1b/UZIPeDCKT8bIVL0vo23w3TlWQ3?= =?iso-8859-2?q?MMl6dsThyKI67miiO2k9ofNQYecLNMiZSwl8fGyi3jJ473qNFpdvzxlCbHE2?= =?iso-8859-2?q?ZxKgawKQwiNMKZtnlVJ0239sF88E/ssxljMU5FXq2WdgoVKlQcdRPr8Z+f+r?= =?iso-8859-2?q?l8hWXHDvE+3FkwG3e4VREgnG8h+Y2w5Hn3l+4xtHfAFoMU2YiV+pFEfdz++L?= =?iso-8859-2?q?YVO3VNhc+3bIgc4cmZqjLZ9uYhZPnEvyOoG/VbAndWzcKWCXj5rEipbu8apu?= =?iso-8859-2?q?2PFUPsIKlWSJV8jaJ1HKXgsFpbXUBaoJiAy07n4ydrb+XTYFo/lsg69RtYek?= =?iso-8859-2?q?RnIB4br121kkBWn9ypJIJ9MOi4sxtHZ+dFo+XKQi87MwaJTDF7RXjQnO84mN?= =?iso-8859-2?q?y4ndyCgXU0MJ1zrNOjAm0faORNksQXSwDtuewjYqMWce/sc3uJRTMB9sSxVm?= =?iso-8859-2?q?l7Dugv5+B38sLRmq7wCuJ+C/MdOrJW/fpdr1UWSDlmblMfO94Xtsy9iWOGKG?= =?iso-8859-2?q?Uguza/EMPeN86TvFG4BsTxeQphNr8duS2JxA/c4MfnFnQUAdhBR475Hjnkay?= =?iso-8859-2?q?g6xLc7ftlmrIQqHUieswzN3j4Hj+7q0TlCti970DiCWB+f/iVeoGK7BxFKFq?= =?iso-8859-2?q?SxF0enui/UcIxR7KZ+vQwwoMgy9Bu0XWNXjYDVr7CPk3Dtt7790Ta0RfLugw?= =?iso-8859-2?q?gmvwVSOpQrQOU356eIWhJ+qhdiaohS56lMNlv9aYwNQcnW3rg7qWW127muNu?= =?iso-8859-2?q?yc3rvLhGOxqdYuwJz94kZEmuVCR+kifjBbbRVQhIaRZks3ZYFk1Tp6T4JbXq?= =?iso-8859-2?q?XHskrDOiNWanbNmyyFhhI0vw3lO7pxxL11IiTyiG4dUGVMWh9KAKjzd8eKvM?= =?iso-8859-2?q?PmEUMv0UuNrnT3I6jBmtrAk9GN/s92F0C9aErI7uwoY2H4Q7fQEE+G4PW1IZ?= =?iso-8859-2?q?aB73sap8qjatKS/n5236vecz6t3903c/BL1oKPZPcKLfCnb/4bHneHGAKe0/?= =?iso-8859-2?q?VHKkhMx0bEIndlpQ8IzNxHkKn8+Iwo4LcX0wfhDcZwSMGii/YcpGvpYHg8DL?= =?iso-8859-2?q?0ieGmp9kLc+FJEVQp8YE1WP8pYAz59csk7rma9FPrrwMJ1A6j95WEUe00B+W?= =?iso-8859-2?q?RsoG4?= 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: d5760a0e-f24c-45d1-634d-08d98a7ff13b X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Oct 2021 17:20:36.1141 (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: rUDxDTuNmlBeT5bqM6HmCab3i5s2HjK8uxHFYQa6svvV2I6fxU5zDDZSMu8pZPxat73AfEQ6uSH5DpCXT5H6e8QCR9OeQDungmuPE7dC6+A= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR2101MB1049 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org This patch makes the Hyper-V vPCI code architectural neutral by introducing an irqchip that takes care of architectural dependencies. 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 --- In v2: v2 changes are described in the cover letter. MAINTAINERS | 2 + arch/x86/include/asm/hyperv-tlfs.h | 33 +++++++++++++ arch/x86/include/asm/mshyperv.h | 7 --- drivers/pci/controller/Makefile | 2 +- drivers/pci/controller/pci-hyperv-irqchip.c | 51 ++++++++++++++++++++ drivers/pci/controller/pci-hyperv-irqchip.h | 21 +++++++++ drivers/pci/controller/pci-hyperv.c | 52 +++++++++++++-------- include/asm-generic/hyperv-tlfs.h | 33 ------------- 8 files changed, 141 insertions(+), 60 deletions(-) create mode 100644 drivers/pci/controller/pci-hyperv-irqchip.c create mode 100644 drivers/pci/controller/pci-hyperv-irqchip.h diff --git a/MAINTAINERS b/MAINTAINERS index ca6d6fde85cf..ba8c979c17b2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8688,6 +8688,8 @@ F: drivers/iommu/hyperv-iommu.c F: drivers/net/ethernet/microsoft/ F: drivers/net/hyperv/ F: drivers/pci/controller/pci-hyperv-intf.c +F: drivers/pci/controller/pci-hyperv-irqchip.c +F: drivers/pci/controller/pci-hyperv-irqchip.h F: drivers/pci/controller/pci-hyperv.c F: drivers/scsi/storvsc_drv.c F: drivers/uio/uio_hv_generic.c 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..c2b9ab94408e 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -176,13 +176,6 @@ bool hv_vcpu_is_preempted(int vcpu); static inline void hv_apic_init(void) {} #endif -static inline void hv_set_msi_entry_from_desc(union hv_msi_entry *msi_entry, - struct msi_desc *msi_desc) -{ - msi_entry->address.as_uint32 = msi_desc->msg.address_lo; - msi_entry->data.as_uint32 = msi_desc->msg.data; -} - struct irq_domain *hv_create_pci_msi_domain(void); int hv_map_ioapic_interrupt(int ioapic_id, bool level, int vcpu, int vector, diff --git a/drivers/pci/controller/Makefile b/drivers/pci/controller/Makefile index aaf30b3dcc14..2c301d0fc23b 100644 --- a/drivers/pci/controller/Makefile +++ b/drivers/pci/controller/Makefile @@ -2,7 +2,7 @@ obj-$(CONFIG_PCIE_CADENCE) += cadence/ obj-$(CONFIG_PCI_FTPCI100) += pci-ftpci100.o obj-$(CONFIG_PCI_IXP4XX) += pci-ixp4xx.o -obj-$(CONFIG_PCI_HYPERV) += pci-hyperv.o +obj-$(CONFIG_PCI_HYPERV) += pci-hyperv.o pci-hyperv-irqchip.o obj-$(CONFIG_PCI_HYPERV_INTERFACE) += pci-hyperv-intf.o obj-$(CONFIG_PCI_MVEBU) += pci-mvebu.o obj-$(CONFIG_PCI_AARDVARK) += pci-aardvark.o diff --git a/drivers/pci/controller/pci-hyperv-irqchip.c b/drivers/pci/controller/pci-hyperv-irqchip.c new file mode 100644 index 000000000000..5f334f7d66cb --- /dev/null +++ b/drivers/pci/controller/pci-hyperv-irqchip.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Hyper-V vPCI irqchip. + * + * Copyright (C) 2021, Microsoft, Inc. + * + * Author : Sunil Muthuswamy + */ + +#include +#include +#include +#include +#include + +#ifdef CONFIG_X86_64 +int hv_pci_irqchip_init(struct irq_domain **parent_domain, + bool *fasteoi_handler, + u8 *delivery_mode) +{ + *parent_domain = x86_vector_domain; + *fasteoi_handler = false; + *delivery_mode = APIC_DELIVERY_MODE_FIXED; + + return 0; +} + +void hv_pci_irqchip_free(void) {} + +unsigned int hv_msi_get_int_vector(struct irq_data *data) +{ + struct irq_cfg *cfg = irqd_cfg(data); + + return cfg->vector; +} + +void hv_set_msi_entry_from_desc(union hv_msi_entry *msi_entry, + struct msi_desc *msi_desc) +{ + msi_entry->address.as_uint32 = msi_desc->msg.address_lo; + msi_entry->data.as_uint32 = msi_desc->msg.data; +} + +int hv_msi_prepare(struct irq_domain *domain, struct device *dev, + int nvec, msi_alloc_info_t *info) +{ + return pci_msi_prepare(domain, dev, nvec, info); +} + +#endif diff --git a/drivers/pci/controller/pci-hyperv-irqchip.h b/drivers/pci/controller/pci-hyperv-irqchip.h new file mode 100644 index 000000000000..8fbf17f03385 --- /dev/null +++ b/drivers/pci/controller/pci-hyperv-irqchip.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Architecture specific vector management for the Hyper-V vPCI. + * + * Copyright (C) 2021, Microsoft, Inc. + * + * Author : Sunil Muthuswamy + */ + +int hv_pci_irqchip_init(struct irq_domain **parent_domain, + bool *fasteoi_handler, + u8 *delivery_mode); + +void hv_pci_irqchip_free(void); +unsigned int hv_msi_get_int_vector(struct irq_data *data); +void hv_set_msi_entry_from_desc(union hv_msi_entry *msi_entry, + struct msi_desc *msi_desc); + +int hv_msi_prepare(struct irq_domain *domain, struct device *dev, + int nvec, msi_alloc_info_t *info); diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index eaec915ffe62..2d3916206986 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -43,14 +43,12 @@ #include #include #include -#include -#include -#include #include #include #include #include #include +#include "pci-hyperv-irqchip.h" /* * Protocol versions. The low word is the minor version, the high word the @@ -81,6 +79,10 @@ static enum pci_protocol_version_t pci_protocol_versions[] = { PCI_PROTOCOL_VERSION_1_1, }; +static struct irq_domain *parent_domain; +static bool fasteoi; +static u8 delivery_mode; + #define PCI_CONFIG_MMIO_LENGTH 0x2000 #define CFG_PAGE_OFFSET 0x1000 #define CFG_PAGE_SIZE (PCI_CONFIG_MMIO_LENGTH - CFG_PAGE_OFFSET) @@ -1217,7 +1219,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; @@ -1246,11 +1247,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?). */ @@ -1347,7 +1349,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 = delivery_mode; /* * Create MSI w/ dummy vCPU set, overwritten by subsequent retarget in @@ -1377,7 +1379,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 = delivery_mode; cpu = hv_compose_msi_req_get_cpu(affinity); int_pkt->int_desc.processor_array[0] = hv_cpu_number_to_vp_number(cpu); @@ -1397,7 +1399,7 @@ static u32 hv_compose_msi_req_v3( int_pkt->int_desc.vector = vector; int_pkt->int_desc.reserved = 0; int_pkt->int_desc.vector_count = 1; - int_pkt->int_desc.delivery_mode = APIC_DELIVERY_MODE_FIXED; + int_pkt->int_desc.delivery_mode = delivery_mode; cpu = hv_compose_msi_req_get_cpu(affinity); int_pkt->int_desc.processor_array[0] = hv_cpu_number_to_vp_number(cpu); @@ -1419,7 +1421,6 @@ static u32 hv_compose_msi_req_v3( */ 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; @@ -1470,7 +1471,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: @@ -1478,14 +1479,14 @@ 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; case PCI_PROTOCOL_VERSION_1_4: size = hv_compose_msi_req_v3(&ctxt.int_pkts.v3, dest, hpdev->desc.win_slot.slot, - cfg->vector); + hv_msi_get_int_vector(data)); break; default: @@ -1601,7 +1602,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, }; @@ -1625,12 +1626,13 @@ static int hv_pcie_init_irq_domain(struct hv_pcibus_device *hbus) 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 = + fasteoi ? handle_fasteoi_irq : handle_edge_irq; + hbus->msi_info.handler_name = fasteoi ? "fasteoi" : "edge"; 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"); @@ -3531,13 +3533,21 @@ static void __exit exit_hv_pci_drv(void) hvpci_block_ops.read_block = NULL; hvpci_block_ops.write_block = NULL; hvpci_block_ops.reg_blk_invalidate = NULL; + + hv_pci_irqchip_free(); } static int __init init_hv_pci_drv(void) { + int ret; + if (!hv_is_hyperv_initialized()) return -ENODEV; + ret = hv_pci_irqchip_init(&parent_domain, &fasteoi, &delivery_mode); + 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); @@ -3546,7 +3556,11 @@ static int __init init_hv_pci_drv(void) hvpci_block_ops.write_block = hv_write_config_block; hvpci_block_ops.reg_blk_invalidate = hv_register_block_invalidate; - return vmbus_driver_register(&hv_pci_drv); + ret = vmbus_driver_register(&hv_pci_drv); + if (ret) + hv_pci_irqchip_free(); + + return ret; } module_init(init_hv_pci_drv); 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 Fri Oct 8 17:21:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil Muthuswamy X-Patchwork-Id: 12545849 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8FBACC433EF for ; Fri, 8 Oct 2021 17:21:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6115E60EFE for ; Fri, 8 Oct 2021 17:21:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229606AbhJHRX3 (ORCPT ); Fri, 8 Oct 2021 13:23:29 -0400 Received: from mail-oln040093003003.outbound.protection.outlook.com ([40.93.3.3]:5171 "EHLO na01-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231217AbhJHRX2 (ORCPT ); Fri, 8 Oct 2021 13:23:28 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NOtrpgsTr7nS4Lp5oNiKy+IEdFGBW/li+gL+KA0IgmNBwW38H5Kz9QzdAD6gao4692PD10CeERsiFvSgxXzPTMpbBNHPxROyClc2gmM624KxR9gf5eEH3Npvn1SslPMVCluPBuEXORo2r0BiskubiJVtyJAhBgNUUdbYG6op5Xmzt6c5yVlpEPqpEYFnYgf6UEkjxzE6MckFlmXrlPg39oNzwdip+RO7x+RED8AiuASzJfTOKKmoTnc91lWX7eMckfF+WFNiUm0OKagVwH/H6lN3a/gAKjgPfMyIiG+EiuhgoB8RIEQj4SzHK+wTphX7Pa2zG8yR14qyrcm7yCwcvA== 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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+eEuKBd7Ay6pJYDUhhzSOldIdM72wrxCrAtaAXCNRsQ=; b=VQSd7/gGrIcgqcns6i7745TijTuAhufOZ84/aM7pEtEFrBzT9wGychrhZJhIR7j0DDt396w97usFNLwXqT9qmDoZrD/r8CCreHcUmtkql6wAKCscQXBCIDwOTZZrahX4IzBFvPmpwvmTqkgZD4FmyCK7ogsjd+OLc398oDVvkQEBMPGNbfO7mUMF0sr5sUaPBXlYqzJmHKbWwavNCryfCLiKU8UTIn1pufdzkcn/TBznWZlA/FFnCVC7DCO7Z4bj7/xrN9jm9jRnypeHVTC0xn9ja3MB2zza5fne3xVpGC3Ru1FcP1y4UK/KmFKBvwt3yM7nzJ2mXq+5OG8HS9TUrw== 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=+eEuKBd7Ay6pJYDUhhzSOldIdM72wrxCrAtaAXCNRsQ=; b=Bs31Cez480v/ko70A+VyUXXodvjNEVGM6shJuwO8ZRWekK3xN/XO9+ecYAUL3SI2fJDmzPIrmvdQzu3T8AZDyJnniVuv1FX6POoExawT+Vf70A4794ku12AHCcVnQ+Opb2otENxE59KZFEidHk2C4cfFPyI5h4iwKlGhQsQwTBU= Received: from MW4PR21MB2002.namprd21.prod.outlook.com (2603:10b6:303:68::18) by MW2PR2101MB1049.namprd21.prod.outlook.com (2603:10b6:302:a::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.4; Fri, 8 Oct 2021 17:21:29 +0000 Received: from MW4PR21MB2002.namprd21.prod.outlook.com ([fe80::89fe:5bf:5eb2:4c55]) by MW4PR21MB2002.namprd21.prod.outlook.com ([fe80::89fe:5bf:5eb2:4c55%4]) with mapi id 15.20.4608.008; Fri, 8 Oct 2021 17:21:29 +0000 From: Sunil Muthuswamy To: Marc Zyngier , 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: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "\"H. Peter Anvin\"" , Arnd Bergmann , "linux-hyperv@vger.kernel.org" , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH v2 2/2] PCI: hv: Support for Hyper-V vPCI for ARM64 Thread-Topic: [PATCH v2 2/2] PCI: hv: Support for Hyper-V vPCI for ARM64 Thread-Index: Ade8aA2v7N19jp6XTU2lQwhKOEXJNw== Date: Fri, 8 Oct 2021 17:21:29 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ActionId=977fe94e-ee0a-4530-9ff9-e2b7cc82b99a;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ContentBits=0;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=true;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Method=Standard;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=Internal;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2021-10-08T17:12:26Z;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47; 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: ed359b89-b2af-41d6-3f83-08d98a80110e x-ms-traffictypediagnostic: MW2PR2101MB1049: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7219; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: WWOvU6EMjP84jHuI/NgD+wFtYDU+qYCFItac7MJKfMnkNLFGjFPb6DxO8jiin2AIf0Fcu4qcZ7c1w8yOdJPJk4okybV1tSvxW185bTKc7z1yjPtPNaohDMpw4+MnFpZZWss/uRvq3k8SF0eKvvSoFr6WKaRh9yo5tJUghFfzF3BfA1ZDZfcyh7M0Rvspn6OaKM94bg0DlB/y3aWd/4lQX0jJWvBIcYN7te15IedkLPMo8ZaU0ovUTZv/Q84cTEsrwJQ7P6fcQgi7W2QPdEr7rDInQ4ZdUn/YAwMNwLojAHhrFTbp+z0eh9gFW7JpePU3qV22XCYRp6jmlAToGIf0IFoCOf+5o2hRRBnaIL2aKM3o7aZ80D6EIUrxQElOVdktDj613MUtPjXwvLz8KK2ASDdecMXRkE1QJWNkvywxp1Bd173P6ffI0SvG2DsfKEsiM/KFUvYXj9GDm3fFJ8K7Efqb+HCi/z0FJ9o0zqXLNxRAcu8OnCO7LGXTYNUqimCfBLvMRMF2W77UZW53tA51Elb61YExUcN06JHeKKsEj7xDVHsMLGL6eRnzldmmOimecaGlYzDi3AInQur7j99kpFbjcX5YFSiCKJ7JQlIR5f2+01IlDnx+60bcHXEcxh3NgqMAJfVK4dFacuQ8bsQ18kgMZFfjBLRARhIDGaMmGu8f4488IzdsRnA9iD+Vl+SSDti8XbxwwPtBeM5BSIenz3BQOPjCTT9Cn8vjNp2s15s= 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)(38070700005)(71200400001)(8990500004)(86362001)(5660300002)(10290500003)(186003)(4326008)(82950400001)(508600001)(76116006)(66946007)(82960400001)(33656002)(8676002)(6506007)(921005)(122000001)(2906002)(66556008)(9686003)(54906003)(66476007)(8936002)(7696005)(316002)(66446008)(64756008)(38100700002)(83380400001)(110136005)(55016002)(7416002)(52536014);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-2?q?9G+4+lVTnXsrYpA00TyeWzN?= =?iso-8859-2?q?K9+9s1dhwpPd0XNen1DD5cAiivN9PiZXfZYj96VHStA0lOc+5PlyxqMZHi0C?= =?iso-8859-2?q?u3hC7Y3MpS06+4NQK/yvqDCetUyktP0xjOnmEWWbLRgpZ8iYHE7cJXuZl/Vf?= =?iso-8859-2?q?fEhhpasbhGh5TrxRJw6q2P1mCgM4ybbYOpMLaZY+4ZO2Jow0ZQUB1mf7+9Rc?= =?iso-8859-2?q?81ucNF1t9QM4XtxeG4D3AScf9EZZMaZulxxMEo1viVfgiCmYtGr7LcbBB1XA?= =?iso-8859-2?q?vAlSohUe+8xxpvAuEKe7KiIeQvUY969JhxZ61XeXW4L+zZevVh/38Hiexziz?= =?iso-8859-2?q?J97gBr7+Bmbj4+ReuffPZlt6joz7tL/4UbLgNqN2LZfY0vgM1/L2pZDpFfu6?= =?iso-8859-2?q?in/BYcVns4ApvVMsQCGu9yZ0I2vEyO7+3wV7xpeXFDV1UPqCfKXptijEQN30?= =?iso-8859-2?q?jZlPpf+XOzDW8DUWO46PBwG1ByV/4XwcKpwLwJ2FXWrKMn/gLrmcOsWJQgmu?= =?iso-8859-2?q?ZJciicd3tV+gEIgqftOclix43pgmfwSMoHPm/cXEUaCJm4lGq8Uu/Q1GZKbX?= =?iso-8859-2?q?K08VH4TY7hu9wJ3+i/bo9qWQN8+at7HaDU02oZqHUniDuWZICtLbx93uure0?= =?iso-8859-2?q?D92/jKtdU0wSi/2L/DWkurMz4Hn+u1yhzuWgPRu/BkqstHkwEkZvfasiecEO?= =?iso-8859-2?q?vmaoKoNuq/iG8qlUP3oel/L5wYI/w0+9IlUtlUw8lCGvo7VIRatgbXAkaUpw?= =?iso-8859-2?q?U3f8OB6uOuelVay/18oRmpojru7sDacd1PSWOdqS17x4UCT6ZzUJ247bESwx?= =?iso-8859-2?q?h/IhdH7fqPOXCwo8RH6FSdiG1RipEu2ZARI/1CO6UyYvZHIVZN8TRJwT5tQc?= =?iso-8859-2?q?G1Ns9o5revVFsK//7KMyhmVbXkeW0LdJw0X0Kom9BdpQJKpItBgCrDfCe+X0?= =?iso-8859-2?q?bqBp4C2/Wm3GVWlUPQArNp1RqS27F4nHNpIPPE1lnpqnbf8SPFh8Rqm+dZNm?= =?iso-8859-2?q?ZEF2drR2/cLEJhlv+JqYhYz2B718IuHXlrucHgdThOllcREUlmKvprqBgsvY?= =?iso-8859-2?q?ZmiqVFggPRHSxnUndeWVX0A08T4qIPwhaBigAiXuWsO7rZFbIAIozfQ/gOF9?= =?iso-8859-2?q?9Ine0rjWB7wygkNBP2c4sueXOcRUcbjF8da9om3kC2WbwVmwYrV71/cA0elO?= =?iso-8859-2?q?iS/fHHQ03lUaZlYn51AEBktpznB/rRfFF+lrxIFmeyX3sypiccTyEyZsAQ8g?= =?iso-8859-2?q?RMtJN3wAgOr7Q4vIY+r2ozGUwA6MchtEc+49ywHgzUDxyY5fyufvBvrryDJi?= =?iso-8859-2?q?JPabbDE/Phpprssyo29edwp1MuuS2Pj2Yw0szynYDwzFCYh5y6+FNvVzxUCJ?= =?iso-8859-2?q?1MIySNzokyiGfDsq2CNDUPAnKsrOLsW+fjuPotcRC6bwN7IrjMbe9yPcZbfU?= =?iso-8859-2?q?Tpbou?= 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: ed359b89-b2af-41d6-3f83-08d98a80110e X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Oct 2021 17:21:29.5044 (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: oZYq/R6KivHszp3+yXgTSxQDeDlyerv147wIy9cKZtkmnnqVJ83rUFxf+KULKhE7S2fjx2+6p+uxD2xKmli3qqt1uLxKz159HmLlRLDzPaE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR2101MB1049 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 --- In v2: v2 changes are described in the cover letter. arch/arm64/include/asm/hyperv-tlfs.h | 9 + drivers/pci/Kconfig | 2 +- drivers/pci/controller/Kconfig | 2 +- drivers/pci/controller/pci-hyperv-irqchip.c | 205 ++++++++++++++++++++ drivers/pci/controller/pci-hyperv.c | 6 + 5 files changed, 222 insertions(+), 2 deletions(-) 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/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 326f7d13024f..15271f8a0dd1 100644 --- a/drivers/pci/controller/Kconfig +++ b/drivers/pci/controller/Kconfig @@ -280,7 +280,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-irqchip.c b/drivers/pci/controller/pci-hyperv-irqchip.c index 5f334f7d66cb..193f6abedb9e 100644 --- a/drivers/pci/controller/pci-hyperv-irqchip.c +++ b/drivers/pci/controller/pci-hyperv-irqchip.c @@ -48,4 +48,209 @@ int hv_msi_prepare(struct irq_domain *domain, struct device *dev, return pci_msi_prepare(domain, dev, nvec, info); } +#elif CONFIG_ARM64 + +/* + * 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 and + * starting with a power of two to satisfy power of 2 multi-MSI requirement. + */ +#define HV_PCI_MSI_SPI_START 64 +#define HV_PCI_MSI_SPI_NR (1020 - HV_PCI_MSI_SPI_START) + +struct hv_pci_chip_data { + DECLARE_BITMAP(spi_map, HV_PCI_MSI_SPI_NR); + struct mutex map_lock; +}; + +/* Hyper-V vPCI MSI GIC IRQ domain */ +static struct irq_domain *hv_msi_gic_irq_domain; + +/* Hyper-V PCI MSI IRQ chip */ +static struct irq_chip hv_msi_irq_chip = { + .name = "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 +}; + +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; +} + +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; +} + +int hv_msi_prepare(struct irq_domain *domain, struct device *dev, + int nvec, msi_alloc_info_t *info) +{ + return 0; +} + +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; + struct irq_data *irqd = irq_domain_get_irq_data(domain, virq); + int first = irqd->hwirq - HV_PCI_MSI_SPI_START; + + mutex_lock(&chip_data->map_lock); + bitmap_release_region(chip_data->spi_map, + first, + get_count_order(nr_irqs)); + mutex_unlock(&chip_data->map_lock); + irq_domain_reset_irq_data(irqd); + irq_domain_free_irqs_parent(domain, virq, nr_irqs); +} + +static int hv_pci_vec_alloc_device_irq(struct irq_domain *domain, + unsigned int nr_irqs, + irq_hw_number_t *hwirq) +{ + struct hv_pci_chip_data *chip_data = domain->host_data; + unsigned int index; + + /* Find and allocate region from the SPI bitmap */ + mutex_lock(&chip_data->map_lock); + index = bitmap_find_free_region(chip_data->spi_map, + HV_PCI_MSI_SPI_NR, + get_count_order(nr_irqs)); + mutex_unlock(&chip_data->map_lock); + if (index < 0) + return -ENOSPC; + + *hwirq = index + HV_PCI_MSI_SPI_START; + + return 0; +} + +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); +} + +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; + + ret = hv_pci_vec_alloc_device_irq(domain, nr_irqs, &hwirq); + if (ret) + return ret; + + for (i = 0; i < nr_irqs; i++) { + ret = hv_pci_vec_irq_gic_domain_alloc(domain, virq + i, + hwirq + i); + if (ret) + goto free_irq; + + ret = irq_domain_set_hwirq_and_chip(domain, virq + i, + hwirq + i, &hv_msi_irq_chip, + domain->host_data); + if (ret) + goto free_irq; + + pr_debug("pID:%d vID:%u\n", (int)(hwirq + i), virq + i); + } + + return 0; + +free_irq: + hv_pci_vec_irq_domain_free(domain, virq, nr_irqs); + + return ret; +} + +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, +}; + +int hv_pci_irqchip_init(struct irq_domain **parent_domain, + bool *fasteoi_handler, + u8 *delivery_mode) +{ + 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; + + mutex_init(&chip_data->map_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; + } + + *parent_domain = hv_msi_gic_irq_domain; + *fasteoi_handler = true; + + /* Delivery mode: Fixed */ + *delivery_mode = 0; + + return 0; + +free_chip: + kfree(chip_data); + if (fn) + irq_domain_free_fwnode(fn); + + return ret; +} + +void hv_pci_irqchip_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); +} + #endif diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 2d3916206986..a77d0eaedac3 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -1204,6 +1205,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); } /** @@ -1321,6 +1324,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); } @@ -1597,6 +1602,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, };