From nobody Sat May 11 11:43:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1693544377; cv=pass; d=zohomail.com; s=zohoarc; b=JwqXsosqerb+tKXAE1LtxHYlEvatOTgsAwK7MErZ8Q/aNpis4Ly5z0KqosPH15+F7uy+Hf9NcbAg0T3UuWVZYX+jDXhIhhPBI3xpW+uq3NKFQUBQyBjQg+spWV8dEEJGsrqFV8qLC5wKGkHmT6HFba1rs5J5TySCWECnQkclvo0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693544377; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZC2l0vFk7lQvmeX715YMFbry0xa9KxT1+wYTczHy+Ts=; b=Nil3k1jEeOBpLQ5cuwltFwvVIjj9VsghPTmUdo6C96Yi01KPrge87pn0MhqyJ1F6kdesU4+01elrHAbJcl2cu7qbyainAaAqhUR5mvHCYDjp8sT3KuA6Fo3M6Zy24LnpsvWxlqvxOWWnXVYwz2vchU49diopZCrJRI5iUx7BaWI= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1693544377383742.897697519445; Thu, 31 Aug 2023 21:59:37 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.594198.927436 (Exim 4.92) (envelope-from ) id 1qbwFc-0000Qw-3i; Fri, 01 Sep 2023 04:59:20 +0000 Received: by outflank-mailman (output) from mailman id 594198.927436; Fri, 01 Sep 2023 04:59:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwFc-0000Qp-0n; Fri, 01 Sep 2023 04:59:20 +0000 Received: by outflank-mailman (input) for mailman id 594198; Fri, 01 Sep 2023 04:59:18 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwFa-0000Nr-M1 for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 04:59:18 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2061d.outbound.protection.outlook.com [2a01:111:f400:7eab::61d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4c62c828-4884-11ee-8783-cb3800f73035; Fri, 01 Sep 2023 06:59:16 +0200 (CEST) Received: from CY5PR17CA0052.namprd17.prod.outlook.com (2603:10b6:930:12::30) by IA0PR12MB7674.namprd12.prod.outlook.com (2603:10b6:208:434::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.21; Fri, 1 Sep 2023 04:59:11 +0000 Received: from CY4PEPF0000EE37.namprd05.prod.outlook.com (2603:10b6:930:12:cafe::d3) by CY5PR17CA0052.outlook.office365.com (2603:10b6:930:12::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.22 via Frontend Transport; Fri, 1 Sep 2023 04:59:11 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE37.mail.protection.outlook.com (10.167.242.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.16 via Frontend Transport; Fri, 1 Sep 2023 04:59:10 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 31 Aug 2023 23:59:10 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 31 Aug 2023 23:59:09 -0500 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Thu, 31 Aug 2023 23:59:08 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4c62c828-4884-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jR5pEtfBwCpghDODLPo4YolLTi9/N6jMeQi7NO+84WfbV6F9F7icsvGNkbex66K9r7ATAOGuJkKHQ1p5FZvFuVpxIyrzKQ4LtvJT9g5sqExWAjwnh/SYCguE73rXfefwJjVLdkeL1Ybw3SKqpESLNAIGutSIOD5JUA4PkvyJL7wRzoxfqeM89HuGvStzXU8/ABU8TWok7gDBnMjGsaSKCuaZHl+n/bgyVuNZQyvIBMc8SIOBZYpV5F4l0zkSc69TdYresiyF6n0J95YGcgq9BdJJEqJPedHdDrr3jRn7IEZMdJcEpB0ySGJxwWFbMWa45DeijityDStO3GlOks9aeQ== 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=ZC2l0vFk7lQvmeX715YMFbry0xa9KxT1+wYTczHy+Ts=; b=ASMl42MQ6bIcwEVB395ebU/ubUsMZIsRiBlEcHU/Ea4mNrKSI/MttPqmjg81/ZV7yWrJ85Xmvk82Z/2Akm+NyPMuVYwoOCULBaGkO5GChf6csC+VEmfnwzvK1paqlVpc8DZwSI/YAr1YiqgT1/+Ab61h/omsyUDeyPKe7HQv1BCTsoj4/fpa8L2ta9pXdQKgdmY9YQk7UfTjBUwV8LR+cpaZlFr5tVdsjs1KnlSxTlwqF6R6hsUoYo4F+KHT5y0dx8Guecr+us3WPrIr7mTLY73muoKVI260uhYyKUhkDxHGIYaOl/r5sJE/iyMTgr/kQ2hPRBu+pt4wkgpD17iSWw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZC2l0vFk7lQvmeX715YMFbry0xa9KxT1+wYTczHy+Ts=; b=Kggt8T25TYEWefCoHKqOvKLlPxtf0D65xisVtEgiGsac85fPTRB/9EKUVdormvX3HrIpv24pvDHjyXUMrlNmxssRUQP6Rv35pZk621EO27OqNsBoHXPd26HehpvTRBebpwQ8mZFOmPSxrU2O9r+MjUfrpV5trkQrYyN8UVcpNSQ= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Stewart Hildebrand To: CC: Stewart Hildebrand , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini , Paul Durrant , Kevin Tian Subject: [PATCH v5 1/5] xen/pci: convert pci_find_*cap* to pci_sbdf_t Date: Fri, 1 Sep 2023 00:57:28 -0400 Message-ID: <20230901045742.235975-2-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230901045742.235975-1-stewart.hildebrand@amd.com> References: <20230901045742.235975-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE37:EE_|IA0PR12MB7674:EE_ X-MS-Office365-Filtering-Correlation-Id: 47de36dd-b8ab-4159-11a8-08dbaaa82e44 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: T5TyRQgQCLZSHOgollpB/M2qUTBNTUJdJMVPu9ugP32RAkt+Cpa2api+E3L/FHncZJg0thFzA4aWz9WUGUMZDOwYDFVAENXHza6LkivHXrUvWWr0zqKYwO04eXcRDYmonbt0NwCUnwTMB8CV1s4Qmrckl1krfwX/5e9fCEA75e2cXWIjEPoL5tybCBwFT29db2zoyilqoN3ONoczXaM+pGJYb4AnMI/KXo38DyG0lYzlyOJaPAonea+7r9dBGi8OysfrSs93KWnNsFTxA/M0P9rjNw344ARMovJqxy5ih/cAz9L3BmSJBrQm3B8Wy6tzu7fYF0ekYEFVaRBTBROxIuIcRifA0GKAglpyVQY8CVxagQEDLFtjFsMjXffX50KK9hG0TUe4fHeNpr4KAjPtChvPq8c4NjCcncZX4f3qmDKccRf9iEx6s2LrJ2yyjPbeCbEfddfN6VbE0CdjfcRfBfUK9opTPCdOkS+PnZlMsufyW89UZKd8fO/n4dnwlaToD7aIaGpl7J741ovSC76wY8JGx/ITU1petlvYbDklSXesLJ4gVHaumiFvp6pCD5G/Sdr5bawhCnYSgoC7qMZn54+ITNxpIf6kuNhfXr9DWKFJ3S33R0k0xs17BLUDZd4rFmGKL6ijovvFkx4yxu8gUwGrRWmZOVLEDaHrNNQiIViEzmLi1Mj4pE+7VudHwqpd03ZJ9RXiC7KK0rw+Djc2Qrsah5K9aYqivRIx6L50R6Ke8S9EnWQ9Id/vXj749Wo2eKzKoiZtnLVIjW89WLatjA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(396003)(346002)(376002)(136003)(1800799009)(186009)(451199024)(82310400011)(36840700001)(46966006)(40470700004)(356005)(82740400003)(6666004)(36756003)(40460700003)(36860700001)(86362001)(81166007)(47076005)(40480700001)(2616005)(1076003)(30864003)(2906002)(426003)(336012)(26005)(83380400001)(478600001)(70586007)(70206006)(8936002)(54906003)(8676002)(4326008)(44832011)(5660300002)(7416002)(41300700001)(6916009)(316002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 04:59:10.9403 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 47de36dd-b8ab-4159-11a8-08dbaaa82e44 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE37.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7674 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1693544378960100001 Content-Type: text/plain; charset="utf-8" Convert pci_find_*cap* functions and call sites to pci_sbdf_t, and remove s= ome now unused local variables. Also change to more appropriate types on lines = that are already being modified as a result of the pci_sbdf_t conversion. Signed-off-by: Stewart Hildebrand Reviewed-by: Jan Beulich --- I built with EXTRA_CFLAGS_XEN_CORE=3D"-Wunused-but-set-variable" (and unfortunately -Wno-error=3Dunused-but-set-variable too) to identify locatio= ns of unneeded local variables as a result of the change to pci_sbdf_t. v4->v5: * add Jan's R-b v3->v4: * use more appropriate types on lines that are being modified anyway * remove "no functional change" from commit description v2->v3: * new patch --- xen/arch/x86/msi.c | 40 ++++++---------------- xen/drivers/char/ehci-dbgp.c | 3 +- xen/drivers/passthrough/amd/iommu_detect.c | 2 +- xen/drivers/passthrough/ats.c | 4 +-- xen/drivers/passthrough/ats.h | 6 ++-- xen/drivers/passthrough/msi.c | 6 ++-- xen/drivers/passthrough/pci.c | 21 +++++------- xen/drivers/passthrough/vtd/quirks.c | 10 ++---- xen/drivers/passthrough/vtd/x86/ats.c | 3 +- xen/drivers/pci/pci.c | 32 +++++++++-------- xen/drivers/vpci/msi.c | 4 +-- xen/drivers/vpci/msix.c | 4 +-- xen/include/xen/pci.h | 11 +++--- 13 files changed, 58 insertions(+), 88 deletions(-) diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c index 41b82f3e87cb..8d4fd43b10a6 100644 --- a/xen/arch/x86/msi.c +++ b/xen/arch/x86/msi.c @@ -283,7 +283,7 @@ static void msi_set_enable(struct pci_dev *dev, int ena= ble) u8 slot =3D PCI_SLOT(dev->devfn); u8 func =3D PCI_FUNC(dev->devfn); =20 - pos =3D pci_find_cap_offset(seg, bus, slot, func, PCI_CAP_ID_MSI); + pos =3D pci_find_cap_offset(dev->sbdf, PCI_CAP_ID_MSI); if ( pos ) __msi_set_enable(seg, bus, slot, func, pos, enable); } @@ -291,12 +291,9 @@ static void msi_set_enable(struct pci_dev *dev, int en= able) static void msix_set_enable(struct pci_dev *dev, int enable) { int pos; - u16 control, seg =3D dev->seg; - u8 bus =3D dev->bus; - u8 slot =3D PCI_SLOT(dev->devfn); - u8 func =3D PCI_FUNC(dev->devfn); + uint16_t control; =20 - pos =3D pci_find_cap_offset(seg, bus, slot, func, PCI_CAP_ID_MSIX); + pos =3D pci_find_cap_offset(dev->sbdf, PCI_CAP_ID_MSIX); if ( pos ) { control =3D pci_conf_read16(dev->sbdf, msix_control_reg(pos)); @@ -603,13 +600,10 @@ static int msi_capability_init(struct pci_dev *dev, struct msi_desc *entry; int pos; unsigned int i, mpos; - u16 control, seg =3D dev->seg; - u8 bus =3D dev->bus; - u8 slot =3D PCI_SLOT(dev->devfn); - u8 func =3D PCI_FUNC(dev->devfn); + uint16_t control; =20 ASSERT(pcidevs_locked()); - pos =3D pci_find_cap_offset(seg, bus, slot, func, PCI_CAP_ID_MSI); + pos =3D pci_find_cap_offset(dev->sbdf, PCI_CAP_ID_MSI); if ( !pos ) return -ENODEV; control =3D pci_conf_read16(dev->sbdf, msi_control_reg(pos)); @@ -680,8 +674,8 @@ static u64 read_pci_mem_bar(u16 seg, u8 bus, u8 slot, u= 8 func, u8 bir, int vf) { struct pci_dev *pdev =3D pci_get_pdev(NULL, PCI_SBDF(seg, bus, slot, func)= ); - unsigned int pos =3D pci_find_ext_capability(seg, bus, - PCI_DEVFN(slot, func), + unsigned int pos =3D pci_find_ext_capability(PCI_SBDF(seg, bus, sl= ot, + func), PCI_EXT_CAP_ID_SRIOV); uint16_t ctrl =3D pci_conf_read16(PCI_SBDF(seg, bus, slot, func), pos + PCI_SRIOV_CTRL); @@ -772,8 +766,7 @@ static int msix_capability_init(struct pci_dev *dev, u8 slot =3D PCI_SLOT(dev->devfn); u8 func =3D PCI_FUNC(dev->devfn); bool maskall =3D msix->host_maskall, zap_on_error =3D false; - unsigned int pos =3D pci_find_cap_offset(seg, bus, slot, func, - PCI_CAP_ID_MSIX); + unsigned int pos =3D pci_find_cap_offset(dev->sbdf, PCI_CAP_ID_MSIX); =20 if ( !pos ) return -ENODEV; @@ -1097,12 +1090,7 @@ static void _pci_cleanup_msix(struct arch_msix *msix) static void __pci_disable_msix(struct msi_desc *entry) { struct pci_dev *dev =3D entry->dev; - u16 seg =3D dev->seg; - u8 bus =3D dev->bus; - u8 slot =3D PCI_SLOT(dev->devfn); - u8 func =3D PCI_FUNC(dev->devfn); - unsigned int pos =3D pci_find_cap_offset(seg, bus, slot, func, - PCI_CAP_ID_MSIX); + unsigned int pos =3D pci_find_cap_offset(dev->sbdf, PCI_CAP_ID_MSIX); u16 control =3D pci_conf_read16(dev->sbdf, msix_control_reg(entry->msi_attrib.pos)); bool maskall =3D dev->msix->host_maskall; @@ -1206,8 +1194,7 @@ void pci_cleanup_msi(struct pci_dev *pdev) =20 int pci_reset_msix_state(struct pci_dev *pdev) { - unsigned int pos =3D pci_find_cap_offset(pdev->seg, pdev->bus, pdev->s= bdf.dev, - pdev->sbdf.fn, PCI_CAP_ID_MSIX); + unsigned int pos =3D pci_find_cap_offset(pdev->sbdf, PCI_CAP_ID_MSIX); =20 ASSERT(pos); /* @@ -1229,10 +1216,6 @@ int pci_reset_msix_state(struct pci_dev *pdev) int pci_msi_conf_write_intercept(struct pci_dev *pdev, unsigned int reg, unsigned int size, uint32_t *data) { - u16 seg =3D pdev->seg; - u8 bus =3D pdev->bus; - u8 slot =3D PCI_SLOT(pdev->devfn); - u8 func =3D PCI_FUNC(pdev->devfn); struct msi_desc *entry; unsigned int pos; =20 @@ -1240,8 +1223,7 @@ int pci_msi_conf_write_intercept(struct pci_dev *pdev= , unsigned int reg, { entry =3D find_msi_entry(pdev, -1, PCI_CAP_ID_MSIX); pos =3D entry ? entry->msi_attrib.pos - : pci_find_cap_offset(seg, bus, slot, func, - PCI_CAP_ID_MSIX); + : pci_find_cap_offset(pdev->sbdf, PCI_CAP_ID_MSIX); ASSERT(pos); =20 if ( reg >=3D pos && reg < msix_pba_offset_reg(pos) + 4 ) diff --git a/xen/drivers/char/ehci-dbgp.c b/xen/drivers/char/ehci-dbgp.c index 72be4d9cc970..00cbdd5454dd 100644 --- a/xen/drivers/char/ehci-dbgp.c +++ b/xen/drivers/char/ehci-dbgp.c @@ -687,7 +687,8 @@ static unsigned int __init __find_dbgp(u8 bus, u8 slot,= u8 func) if ( (class >> 8) !=3D PCI_CLASS_SERIAL_USB_EHCI ) return 0; =20 - return pci_find_cap_offset(0, bus, slot, func, PCI_CAP_ID_EHCI_DEBUG); + return pci_find_cap_offset(PCI_SBDF(0, bus, slot, func), + PCI_CAP_ID_EHCI_DEBUG); } =20 static unsigned int __init find_dbgp(struct ehci_dbgp *dbgp, diff --git a/xen/drivers/passthrough/amd/iommu_detect.c b/xen/drivers/passt= hrough/amd/iommu_detect.c index 2317fa6a7d8d..cede44e6518f 100644 --- a/xen/drivers/passthrough/amd/iommu_detect.c +++ b/xen/drivers/passthrough/amd/iommu_detect.c @@ -27,7 +27,7 @@ static int __init get_iommu_msi_capabilities( { int pos; =20 - pos =3D pci_find_cap_offset(seg, bus, dev, func, PCI_CAP_ID_MSI); + pos =3D pci_find_cap_offset(PCI_SBDF(seg, bus, dev, func), PCI_CAP_ID_= MSI); =20 if ( !pos ) return -ENODEV; diff --git a/xen/drivers/passthrough/ats.c b/xen/drivers/passthrough/ats.c index 253f5c2e1042..0da183d057c5 100644 --- a/xen/drivers/passthrough/ats.c +++ b/xen/drivers/passthrough/ats.c @@ -24,11 +24,9 @@ boolean_param("ats", ats_enabled); int enable_ats_device(struct pci_dev *pdev, struct list_head *ats_list) { u32 value; - u16 seg =3D pdev->seg; - u8 bus =3D pdev->bus, devfn =3D pdev->devfn; int pos; =20 - pos =3D pci_find_ext_capability(seg, bus, devfn, PCI_EXT_CAP_ID_ATS); + pos =3D pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS); BUG_ON(!pos); =20 if ( iommu_verbose ) diff --git a/xen/drivers/passthrough/ats.h b/xen/drivers/passthrough/ats.h index baa5f6a6dc04..f5e1d254e0d3 100644 --- a/xen/drivers/passthrough/ats.h +++ b/xen/drivers/passthrough/ats.h @@ -32,7 +32,8 @@ static inline int pci_ats_enabled(int seg, int bus, int d= evfn) u32 value; int pos; =20 - pos =3D pci_find_ext_capability(seg, bus, devfn, PCI_EXT_CAP_ID_ATS); + pos =3D pci_find_ext_capability(PCI_SBDF(seg, bus, devfn), + PCI_EXT_CAP_ID_ATS); BUG_ON(!pos); =20 value =3D pci_conf_read16(PCI_SBDF(seg, bus, devfn), pos + ATS_REG_CTL= ); @@ -45,7 +46,8 @@ static inline int pci_ats_device(int seg, int bus, int de= vfn) if ( !ats_enabled ) return 0; =20 - return pci_find_ext_capability(seg, bus, devfn, PCI_EXT_CAP_ID_ATS); + return pci_find_ext_capability(PCI_SBDF(seg, bus, devfn), + PCI_EXT_CAP_ID_ATS); } =20 #endif /* _ATS_H_ */ diff --git a/xen/drivers/passthrough/msi.c b/xen/drivers/passthrough/msi.c index fb78e2ebe8a4..13d904692ef8 100644 --- a/xen/drivers/passthrough/msi.c +++ b/xen/drivers/passthrough/msi.c @@ -24,8 +24,7 @@ int pdev_msi_init(struct pci_dev *pdev) =20 INIT_LIST_HEAD(&pdev->msi_list); =20 - pos =3D pci_find_cap_offset(pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn= ), - PCI_FUNC(pdev->devfn), PCI_CAP_ID_MSI); + pos =3D pci_find_cap_offset(pdev->sbdf, PCI_CAP_ID_MSI); if ( pos ) { uint16_t ctrl =3D pci_conf_read16(pdev->sbdf, msi_control_reg(pos)= ); @@ -33,8 +32,7 @@ int pdev_msi_init(struct pci_dev *pdev) pdev->msi_maxvec =3D multi_msi_capable(ctrl); } =20 - pos =3D pci_find_cap_offset(pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn= ), - PCI_FUNC(pdev->devfn), PCI_CAP_ID_MSIX); + pos =3D pci_find_cap_offset(pdev->sbdf, PCI_CAP_ID_MSIX); if ( pos ) { struct arch_msix *msix =3D xzalloc(struct arch_msix); diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index ed1f689227fa..04d00c7c37df 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -361,8 +361,7 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg,= u8 bus, u8 devfn) break; =20 case DEV_TYPE_PCIe_ENDPOINT: - pos =3D pci_find_cap_offset(pseg->nr, bus, PCI_SLOT(devfn), - PCI_FUNC(devfn), PCI_CAP_ID_EXP); + pos =3D pci_find_cap_offset(pdev->sbdf, PCI_CAP_ID_EXP); BUG_ON(!pos); cap =3D pci_conf_read16(pdev->sbdf, pos + PCI_EXP_DEVCAP); if ( cap & PCI_EXP_DEVCAP_PHANTOM ) @@ -565,13 +564,12 @@ struct pci_dev *pci_get_pdev(const struct domain *d, = pci_sbdf_t sbdf) static void pci_enable_acs(struct pci_dev *pdev) { int pos; - u16 cap, ctrl, seg =3D pdev->seg; - u8 bus =3D pdev->bus; + uint16_t cap, ctrl; =20 if ( !is_iommu_enabled(pdev->domain) ) return; =20 - pos =3D pci_find_ext_capability(seg, bus, pdev->devfn, PCI_EXT_CAP_ID_= ACS); + pos =3D pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ACS); if (!pos) return; =20 @@ -704,7 +702,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, =20 if ( !pdev->info.is_virtfn && !pdev->vf_rlen[0] ) { - unsigned int pos =3D pci_find_ext_capability(seg, bus, devfn, + unsigned int pos =3D pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_SRIOV); uint16_t ctrl =3D pci_conf_read16(pdev->sbdf, pos + PCI_SRIOV_CTRL= ); =20 @@ -916,7 +914,8 @@ enum pdev_type pdev_type(u16 seg, u8 bus, u8 devfn) { u16 class_device, creg; u8 d =3D PCI_SLOT(devfn), f =3D PCI_FUNC(devfn); - int pos =3D pci_find_cap_offset(seg, bus, d, f, PCI_CAP_ID_EXP); + unsigned int pos =3D pci_find_cap_offset(PCI_SBDF(seg, bus, devfn), + PCI_CAP_ID_EXP); =20 class_device =3D pci_conf_read16(PCI_SBDF(seg, bus, d, f), PCI_CLASS_D= EVICE); switch ( class_device ) @@ -1184,10 +1183,7 @@ static int hest_match_pci(const struct acpi_hest_aer= _common *p, static bool hest_match_type(const struct acpi_hest_header *hest_hdr, const struct pci_dev *pdev) { - unsigned int pos =3D pci_find_cap_offset(pdev->seg, pdev->bus, - PCI_SLOT(pdev->devfn), - PCI_FUNC(pdev->devfn), - PCI_CAP_ID_EXP); + unsigned int pos =3D pci_find_cap_offset(pdev->sbdf, PCI_CAP_ID_EXP); u8 pcie =3D MASK_EXTR(pci_conf_read16(pdev->sbdf, pos + PCI_EXP_FLAGS), PCI_EXP_FLAGS_TYPE); =20 @@ -1258,8 +1254,7 @@ bool pcie_aer_get_firmware_first(const struct pci_dev= *pdev) { struct aer_hest_parse_info info =3D { .pdev =3D pdev }; =20 - return pci_find_cap_offset(pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn), - PCI_FUNC(pdev->devfn), PCI_CAP_ID_EXP) && + return pci_find_cap_offset(pdev->sbdf, PCI_CAP_ID_EXP) && apei_hest_parse(aer_hest_parse, &info) >=3D 0 && info.firmware_first; } diff --git a/xen/drivers/passthrough/vtd/quirks.c b/xen/drivers/passthrough= /vtd/quirks.c index 5d706a539788..5a56565ea883 100644 --- a/xen/drivers/passthrough/vtd/quirks.c +++ b/xen/drivers/passthrough/vtd/quirks.c @@ -495,8 +495,6 @@ int me_wifi_quirk(struct domain *domain, uint8_t bus, u= int8_t devfn, =20 void pci_vtd_quirk(const struct pci_dev *pdev) { - int seg =3D pdev->seg; - int bus =3D pdev->bus; int pos; bool ff; u32 val, val2; @@ -532,12 +530,10 @@ void pci_vtd_quirk(const struct pci_dev *pdev) /* Sandybridge-EP (Romley) */ case 0x3c00: /* host bridge */ case 0x3c01 ... 0x3c0b: /* root ports */ - pos =3D pci_find_ext_capability(seg, bus, pdev->devfn, - PCI_EXT_CAP_ID_ERR); + pos =3D pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ERR); if ( !pos ) { - pos =3D pci_find_ext_capability(seg, bus, pdev->devfn, - PCI_EXT_CAP_ID_VNDR); + pos =3D pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_VND= R); while ( pos ) { val =3D pci_conf_read32(pdev->sbdf, pos + PCI_VNDR_HEADER); @@ -546,7 +542,7 @@ void pci_vtd_quirk(const struct pci_dev *pdev) pos +=3D PCI_VNDR_HEADER; break; } - pos =3D pci_find_next_ext_capability(seg, bus, pdev->devfn= , pos, + pos =3D pci_find_next_ext_capability(pdev->sbdf, pos, PCI_EXT_CAP_ID_VNDR); } ff =3D 0; diff --git a/xen/drivers/passthrough/vtd/x86/ats.c b/xen/drivers/passthroug= h/vtd/x86/ats.c index 9de419775f90..1f5913bed9d2 100644 --- a/xen/drivers/passthrough/vtd/x86/ats.c +++ b/xen/drivers/passthrough/vtd/x86/ats.c @@ -57,8 +57,7 @@ int ats_device(const struct pci_dev *pdev, const struct a= cpi_drhd_unit *drhd) return 0; =20 ats_drhd =3D find_ats_dev_drhd(drhd->iommu); - pos =3D pci_find_ext_capability(pdev->seg, pdev->bus, pdev->devfn, - PCI_EXT_CAP_ID_ATS); + pos =3D pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS); =20 if ( pos && (ats_drhd =3D=3D NULL) ) { diff --git a/xen/drivers/pci/pci.c b/xen/drivers/pci/pci.c index c73a8c4124af..3569ccb24e9e 100644 --- a/xen/drivers/pci/pci.c +++ b/xen/drivers/pci/pci.c @@ -8,25 +8,25 @@ #include #include =20 -int pci_find_cap_offset(u16 seg, u8 bus, u8 dev, u8 func, u8 cap) +unsigned int pci_find_cap_offset(pci_sbdf_t sbdf, unsigned int cap) { u8 id; int max_cap =3D 48; u8 pos =3D PCI_CAPABILITY_LIST; u16 status; =20 - status =3D pci_conf_read16(PCI_SBDF(seg, bus, dev, func), PCI_STATUS); + status =3D pci_conf_read16(sbdf, PCI_STATUS); if ( (status & PCI_STATUS_CAP_LIST) =3D=3D 0 ) return 0; =20 while ( max_cap-- ) { - pos =3D pci_conf_read8(PCI_SBDF(seg, bus, dev, func), pos); + pos =3D pci_conf_read8(sbdf, pos); if ( pos < 0x40 ) break; =20 pos &=3D ~3; - id =3D pci_conf_read8(PCI_SBDF(seg, bus, dev, func), pos + PCI_CAP= _LIST_ID); + id =3D pci_conf_read8(sbdf, pos + PCI_CAP_LIST_ID); =20 if ( id =3D=3D 0xff ) break; @@ -39,19 +39,20 @@ int pci_find_cap_offset(u16 seg, u8 bus, u8 dev, u8 fun= c, u8 cap) return 0; } =20 -int pci_find_next_cap(u16 seg, u8 bus, unsigned int devfn, u8 pos, int cap) +unsigned int pci_find_next_cap(pci_sbdf_t sbdf, unsigned int pos, + unsigned int cap) { u8 id; int ttl =3D 48; =20 while ( ttl-- ) { - pos =3D pci_conf_read8(PCI_SBDF(seg, bus, devfn), pos); + pos =3D pci_conf_read8(sbdf, pos); if ( pos < 0x40 ) break; =20 pos &=3D ~3; - id =3D pci_conf_read8(PCI_SBDF(seg, bus, devfn), pos + PCI_CAP_LIS= T_ID); + id =3D pci_conf_read8(sbdf, pos + PCI_CAP_LIST_ID); =20 if ( id =3D=3D 0xff ) break; @@ -65,21 +66,21 @@ int pci_find_next_cap(u16 seg, u8 bus, unsigned int dev= fn, u8 pos, int cap) =20 /** * pci_find_ext_capability - Find an extended capability - * @seg/@bus/@devfn: PCI device to query + * @sbdf: PCI device to query * @cap: capability code * * Returns the address of the requested extended capability structure * within the device's PCI configuration space or 0 if the device does * not support it. */ -int pci_find_ext_capability(int seg, int bus, int devfn, int cap) +unsigned int pci_find_ext_capability(pci_sbdf_t sbdf, unsigned int cap) { - return pci_find_next_ext_capability(seg, bus, devfn, 0, cap); + return pci_find_next_ext_capability(sbdf, 0, cap); } =20 /** * pci_find_next_ext_capability - Find another extended capability - * @seg/@bus/@devfn: PCI device to query + * @sbdf: PCI device to query * @start: starting position * @cap: capability code * @@ -87,13 +88,14 @@ int pci_find_ext_capability(int seg, int bus, int devfn= , int cap) * within the device's PCI configuration space or 0 if the device does * not support it. */ -int pci_find_next_ext_capability(int seg, int bus, int devfn, int start, i= nt cap) +unsigned int pci_find_next_ext_capability(pci_sbdf_t sbdf, unsigned int st= art, + unsigned int cap) { u32 header; int ttl =3D 480; /* 3840 bytes, minimum 8 bytes per capability */ - int pos =3D max(start, 0x100); + unsigned int pos =3D max(start, 0x100U); =20 - header =3D pci_conf_read32(PCI_SBDF(seg, bus, devfn), pos); + header =3D pci_conf_read32(sbdf, pos); =20 /* * If we have no capabilities, this is indicated by cap ID, @@ -109,7 +111,7 @@ int pci_find_next_ext_capability(int seg, int bus, int = devfn, int start, int cap pos =3D PCI_EXT_CAP_NEXT(header); if ( pos < 0x100 ) break; - header =3D pci_conf_read32(PCI_SBDF(seg, bus, devfn), pos); + header =3D pci_conf_read32(sbdf, pos); } return 0; } diff --git a/xen/drivers/vpci/msi.c b/xen/drivers/vpci/msi.c index 2814b63d2be7..a253ccbd7db7 100644 --- a/xen/drivers/vpci/msi.c +++ b/xen/drivers/vpci/msi.c @@ -184,9 +184,7 @@ static void cf_check mask_write( =20 static int cf_check init_msi(struct pci_dev *pdev) { - uint8_t slot =3D PCI_SLOT(pdev->devfn), func =3D PCI_FUNC(pdev->devfn); - unsigned int pos =3D pci_find_cap_offset(pdev->seg, pdev->bus, slot, f= unc, - PCI_CAP_ID_MSI); + unsigned int pos =3D pci_find_cap_offset(pdev->sbdf, PCI_CAP_ID_MSI); uint16_t control; int ret; =20 diff --git a/xen/drivers/vpci/msix.c b/xen/drivers/vpci/msix.c index 1be861343dba..d1126a417da9 100644 --- a/xen/drivers/vpci/msix.c +++ b/xen/drivers/vpci/msix.c @@ -659,14 +659,12 @@ int vpci_make_msix_hole(const struct pci_dev *pdev) static int cf_check init_msix(struct pci_dev *pdev) { struct domain *d =3D pdev->domain; - uint8_t slot =3D PCI_SLOT(pdev->devfn), func =3D PCI_FUNC(pdev->devfn); unsigned int msix_offset, i, max_entries; uint16_t control; struct vpci_msix *msix; int rc; =20 - msix_offset =3D pci_find_cap_offset(pdev->seg, pdev->bus, slot, func, - PCI_CAP_ID_MSIX); + msix_offset =3D pci_find_cap_offset(pdev->sbdf, PCI_CAP_ID_MSIX); if ( !msix_offset ) return 0; =20 diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h index 7d8a7cd21301..ea6a4c9abf38 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -193,11 +193,12 @@ int pci_mmcfg_read(unsigned int seg, unsigned int bus, unsigned int devfn, int reg, int len, u32 *value); int pci_mmcfg_write(unsigned int seg, unsigned int bus, unsigned int devfn, int reg, int len, u32 value); -int pci_find_cap_offset(u16 seg, u8 bus, u8 dev, u8 func, u8 cap); -int pci_find_next_cap(u16 seg, u8 bus, unsigned int devfn, u8 pos, int cap= ); -int pci_find_ext_capability(int seg, int bus, int devfn, int cap); -int pci_find_next_ext_capability(int seg, int bus, int devfn, int start, - int cap); +unsigned int pci_find_cap_offset(pci_sbdf_t sbdf, unsigned int cap); +unsigned int pci_find_next_cap(pci_sbdf_t sbdf, unsigned int pos, + unsigned int cap); +unsigned int pci_find_ext_capability(pci_sbdf_t sbdf, unsigned int cap); +unsigned int pci_find_next_ext_capability(pci_sbdf_t sbdf, unsigned int st= art, + unsigned int cap); const char *parse_pci(const char *, unsigned int *seg, unsigned int *bus, unsigned int *dev, unsigned int *func); const char *parse_pci_seg(const char *, unsigned int *seg, unsigned int *b= us, --=20 2.42.0 From nobody Sat May 11 11:43:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1693544395; cv=pass; d=zohomail.com; s=zohoarc; b=H0unpGodHsqvV+aKkJhnLGWeh5bmRgqgtpj52dzCrAyAiiojZ1Gd+A2/FpG2PNKOWwZXm9CcF9rqdtOOTZK/+aIFW3bgn3Gt+zKsQ22UFMbCK9pZ4/qUH1Cad+ZN/j2i9BsoswRt8p+X8xTgniRcM2vkjscw9pe55pisuaoXcMY= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693544395; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vTvGSsnvPNixHgnOIgBXlqmXYsXnEHucB1rNpscARZY=; b=ASy7fxTzlGppvL3c6eIeayHtMyTgy/PGfOqRgy+kYr2DMHGxpO0L4Mb/zPK7KsJuGpC+W8qFeTw2fu/1EiJZUIAZ9GpYXMoa5v2W+CqZ/DGuxhoOfN7ug/W4AlHn6Oun/ajNGefK85uQByu4GZqAgrQlUM5PCUz+DXD+I7B1gfs= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1693544395513514.575060392929; Thu, 31 Aug 2023 21:59:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.594201.927446 (Exim 4.92) (envelope-from ) id 1qbwFv-0000vj-GQ; Fri, 01 Sep 2023 04:59:39 +0000 Received: by outflank-mailman (output) from mailman id 594201.927446; Fri, 01 Sep 2023 04:59:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwFv-0000vc-Dh; Fri, 01 Sep 2023 04:59:39 +0000 Received: by outflank-mailman (input) for mailman id 594201; Fri, 01 Sep 2023 04:59:38 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwFu-0000Nr-CM for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 04:59:38 +0000 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2061e.outbound.protection.outlook.com [2a01:111:f400:7e8b::61e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 59c52397-4884-11ee-8783-cb3800f73035; Fri, 01 Sep 2023 06:59:37 +0200 (CEST) Received: from CYZPR12CA0001.namprd12.prod.outlook.com (2603:10b6:930:8b::8) by CH3PR12MB9393.namprd12.prod.outlook.com (2603:10b6:610:1c5::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.22; Fri, 1 Sep 2023 04:59:32 +0000 Received: from CY4PEPF0000EE3A.namprd03.prod.outlook.com (2603:10b6:930:8b:cafe::37) by CYZPR12CA0001.outlook.office365.com (2603:10b6:930:8b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.26 via Frontend Transport; Fri, 1 Sep 2023 04:59:32 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EE3A.mail.protection.outlook.com (10.167.242.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.16 via Frontend Transport; Fri, 1 Sep 2023 04:59:31 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 31 Aug 2023 23:59:31 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 31 Aug 2023 23:59:30 -0500 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Thu, 31 Aug 2023 23:59:29 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 59c52397-4884-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LDx174aM0GO6DnkPkhWJXu3LeOYu3CR0pH5qIMcvLtUKeFINcrT8LYibDZs8Q5+Vr4AIxeuycshUjb0hL06MHYFwKPWOXl9C5FM3+XILO7n8BT1ijF/+FzAsyajijAyuZspyaj4ADO+0KrnyJXdJTZC9wUavYbUl8hHToC9eyvEewJ6kJNYuv4pT8hzmIOoKvA8h5d+8egqTQ7EtjxxaL/WOFy9XyJ1Sdve8qd1fGK096yFVttJz7feDbw4mVeNslkOSVbOCWSUer4txudj1R90If9Bl0yDAFMCaetqDajnQh5M1Oe3bCFwodB/UtD0OtJd7tjX3P56uYtwPYtoapw== 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=vTvGSsnvPNixHgnOIgBXlqmXYsXnEHucB1rNpscARZY=; b=JGYMBk8e6Er4wQ9/ct0jmSS6bjwg4QNEs8jseuIEHhcKhcT5tbAq6KDjqp34MnGa6oNO6saNIofPR1G7Kdjvt9FoSkMMTLzJD1itfjtOZXkWnl43lTCr+CCKdniJuMp2KgreUOCHnX8Q0Fb2vmLUGJgZb3wioPuS6s/XJcA7mLEFrScguDcG6v380QLPWftrQN1hsyMdo5Kbobvzmv/UIQzNUvaTbAiTi5ts6oAI1+x8UprnAN1sC03zGhAqx/qFUqsun8kT/UpUVk2fNftLlSY+HG48axQCMRp8faZ4/xCVgPfIPjq/0K0C45RNXJ6v+8obBhhZVri41NE5BEf4+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vTvGSsnvPNixHgnOIgBXlqmXYsXnEHucB1rNpscARZY=; b=uM8D7pxXsGzzPtBO06mWP6KTkZL47lMc3Pr7LkVJK884CenbQgOfwK7X0xCZ3JrEcZOHln7F0Uw+EVchSApxlT99ghlvPqRO5rGXak9jr8ArA21SxTBQEVk9Fi96ckv/OYgQDEtkDnk672814LPyA/JtVR8upvxOgebRm4M3Ndg= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Stewart Hildebrand To: CC: Stewart Hildebrand , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v5 2/5] x86/msi: rearrange read_pci_mem_bar slightly Date: Fri, 1 Sep 2023 00:57:29 -0400 Message-ID: <20230901045742.235975-3-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230901045742.235975-1-stewart.hildebrand@amd.com> References: <20230901045742.235975-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3A:EE_|CH3PR12MB9393:EE_ X-MS-Office365-Filtering-Correlation-Id: 2f8f8675-5617-45a0-4b65-08dbaaa83aa1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1hzyOp105N6jwjYukE5RGKMDl14iUz+PlS7vvsKKTM26ODKP0xIbmjr5adzAEZiQM9AVc6r36G8IsWJU6GJugStzggfzUmDTfXu6OgvCkjqgf9e9fz1rVAq4SSBlluDUOfsX41o2coN88q5yPsJJzIV/P/guxOAJFMWdNfCwcrparCvL9SOY6rEY3WCYrvW0KOQoP65m54aHYTrQ9QCZrucqT+GWErviljnJ5apmEUJdNp5/AdKDwtDkjNYfd4CIqJ897a/DphdVkHPkkL9x8nKpKqaFHoKV/uLRKxL3Nh1eIpwKpIQ1Ky4J7NSKVUoG4Dg3EkSKRXIKw80i1ucKLescjJ8j8OxwSKeFPeHBvLAGxsNfqQM3NNQ/FYbMMlgAJooIwwYBdV7qMaNA2Wl8tMpU/9Y3iAtztA78zB/jXndHjYkEVvbf9gTOvc7DBJFP6Va7uMKIxHlOFwyqfWRC7B+VMhhgXytjSdaYKIU1XDsBLL2PNMf5dkT5gxyvbm70bQ16eHu56SaSuAlkXaFb4+mc2ZqV6sRSLHsRkKZ5/7m8SF3ExLhYf59KEl4AsqTjgYmOtHzjnD7zpt3ih4B9+Zuf06avajUsCMzU3BrYjg5Cmvn4M+l7C/isglnj+1SD5lLdKmpwKSoWi/nsnlvxINbCLQd60oPJ6+A1YZQt5KCManInyp7GS+2Uzn+NEYiCtkskX4qe4Im1IqZDu5VlfRMsmYdZf5Tv7gzGUvY+5FFF8F8Zp9t05uMhnMr7AzlaF0hzQvP09Rk6UQAjOHAzqg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(376002)(346002)(39860400002)(136003)(396003)(82310400011)(186009)(1800799009)(451199024)(40470700004)(46966006)(36840700001)(40480700001)(82740400003)(36756003)(41300700001)(336012)(426003)(26005)(1076003)(966005)(40460700003)(54906003)(356005)(70586007)(70206006)(81166007)(83380400001)(316002)(6916009)(478600001)(2906002)(5660300002)(86362001)(44832011)(8936002)(2616005)(36860700001)(8676002)(47076005)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 04:59:31.6840 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2f8f8675-5617-45a0-4b65-08dbaaa83aa1 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE3A.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9393 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1693544397097100001 Content-Type: text/plain; charset="utf-8" Use pdev->sbdf instead of the PCI_SBDF macro in calls to pci_* functions where appropriate. Move NULL check earlier. Suggested-by: Jan Beulich Signed-off-by: Stewart Hildebrand Reviewed-by: Jan Beulich Suggested-by tag added based on conversation at [1] --- v4->v5: * add Jan's R-b v3->v4: * new patch Suggested-by tag added based on conversation at [1] [1] https://lists.xenproject.org/archives/html/xen-devel/2023-08/msg01886.h= tml --- xen/arch/x86/msi.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c index 8d4fd43b10a6..a78367d7cf5d 100644 --- a/xen/arch/x86/msi.c +++ b/xen/arch/x86/msi.c @@ -674,19 +674,19 @@ static u64 read_pci_mem_bar(u16 seg, u8 bus, u8 slot,= u8 func, u8 bir, int vf) { struct pci_dev *pdev =3D pci_get_pdev(NULL, PCI_SBDF(seg, bus, slot, func)= ); - unsigned int pos =3D pci_find_ext_capability(PCI_SBDF(seg, bus, sl= ot, - func), - PCI_EXT_CAP_ID_SRIOV); - uint16_t ctrl =3D pci_conf_read16(PCI_SBDF(seg, bus, slot, func), - pos + PCI_SRIOV_CTRL); - uint16_t num_vf =3D pci_conf_read16(PCI_SBDF(seg, bus, slot, func), - pos + PCI_SRIOV_NUM_VF); - uint16_t offset =3D pci_conf_read16(PCI_SBDF(seg, bus, slot, func), - pos + PCI_SRIOV_VF_OFFSET); - uint16_t stride =3D pci_conf_read16(PCI_SBDF(seg, bus, slot, func), - pos + PCI_SRIOV_VF_STRIDE); - - if ( !pdev || !pos || + unsigned int pos; + uint16_t ctrl, num_vf, offset, stride; + + if ( !pdev ) + return 0; + + pos =3D pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_SRIOV); + ctrl =3D pci_conf_read16(pdev->sbdf, pos + PCI_SRIOV_CTRL); + num_vf =3D pci_conf_read16(pdev->sbdf, pos + PCI_SRIOV_NUM_VF); + offset =3D pci_conf_read16(pdev->sbdf, pos + PCI_SRIOV_VF_OFFSET); + stride =3D pci_conf_read16(pdev->sbdf, pos + PCI_SRIOV_VF_STRIDE); + + if ( !pos || !(ctrl & PCI_SRIOV_CTRL_VFE) || !(ctrl & PCI_SRIOV_CTRL_MSE) || !num_vf || !offset || (num_vf > 1 && !stride) || --=20 2.42.0 From nobody Sat May 11 11:43:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1693544444; cv=pass; d=zohomail.com; s=zohoarc; b=QZfA0IHZjLMIhNreMQ1RTP0yRQKGn4gkNiGnUBy2yGR8savWHnXK3K3rSCtgqxaWXHV52UD3Axbp4ol70jEIfOtNcknvd5IaHGWW7aBTUqWqVsgh1WpXUeGN59kgl5Lk/MTdG9l3HJcFU99/llcCfYfYIDIY97QxOIWJM+IRfZ8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693544444; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zd6P0fZ6k3o3WMUNghQi6mMI+CPAIsveeO98Isieabc=; b=To+3VqeO6bHfXWaLFVmlWHmy9nPz5ThbbxJbAiAzHjhmJGa1gaoYVdhFkaqqEqtUDMFV6FtJwmLNe50qVaxdpS2HBgLdJ5aRhvGr5YgcipBYMGWQ8QW6vMRvMrpAKsUZSSY4lZBliDyp+oo0KlUuvG1uxsdrYxZc6nJbnA0iGRQ= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1693544444280663.8704931504578; Thu, 31 Aug 2023 22:00:44 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.594220.927516 (Exim 4.92) (envelope-from ) id 1qbwGY-0004dI-6h; Fri, 01 Sep 2023 05:00:18 +0000 Received: by outflank-mailman (output) from mailman id 594220.927516; Fri, 01 Sep 2023 05:00:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGY-0004dA-32; Fri, 01 Sep 2023 05:00:18 +0000 Received: by outflank-mailman (input) for mailman id 594220; Fri, 01 Sep 2023 05:00:16 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGW-0001Hn-D0 for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:16 +0000 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on20618.outbound.protection.outlook.com [2a01:111:f400:7e8c::618]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6fda6b53-4884-11ee-9b0d-b553b5be7939; Fri, 01 Sep 2023 07:00:14 +0200 (CEST) Received: from CYZPR12CA0019.namprd12.prod.outlook.com (2603:10b6:930:8b::27) by MN2PR12MB4344.namprd12.prod.outlook.com (2603:10b6:208:26e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.22; Fri, 1 Sep 2023 05:00:11 +0000 Received: from CY4PEPF0000EE3A.namprd03.prod.outlook.com (2603:10b6:930:8b:cafe::46) by CYZPR12CA0019.outlook.office365.com (2603:10b6:930:8b::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.25 via Frontend Transport; Fri, 1 Sep 2023 05:00:10 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EE3A.mail.protection.outlook.com (10.167.242.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.16 via Frontend Transport; Fri, 1 Sep 2023 05:00:10 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 1 Sep 2023 00:00:09 -0500 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 1 Sep 2023 00:00:08 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6fda6b53-4884-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gzlIMWOg0FP4cgVpARgUZWqyRITroDg2UPYnZiyhYfcZhMpAg5Mg199WN4FmtGA4zMBBsrGvZwGxKQR/BwKtbv1vBvK7nU8CAEwamqbqpeBrC8KMsBxzBuQUfnCx9fuaLByBe/mLZ4SSIJuFToXWStvju0vyOxFIFz9W17eKVxvohxN6GD2gN58xMgwis3IFbh4YAOzv0XU3BMxLpSVpapC1lQok5xGuo+ch+WTWl9jbJjFvhysd7uh7MsYL5ciZGf0gr1X3aDQplE4tU2g1meXp3BLBV5FvuPGonE49YEGp8r/6dZMmdGhyjNoL7wLqiNE94FXgEAu6iV6HE8gSPg== 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=zd6P0fZ6k3o3WMUNghQi6mMI+CPAIsveeO98Isieabc=; b=UvAL820KC35RbZejaLdh6STcCwpMlr5QaAes+9ak/Inf6gCioWpR6zBHHDz9faPp85bmYpWM/AFB835fK7v7fwjyPE/RDYiZ3RZxelj2/940TSc2z2wXOwgcyVB74clXg48V/fjpDY2RBvAcjVAdbdoht1tsgxdx1GmjA84CY18M/rfn6ELLeYmqpEvM8hfZz7eQqhMBxdc+W9bWJwgJk40Rsj0nz84o68Ja9HEGl86/L5Ip6zkauxl/Z/5h5kvT4cqwEDH1GmBvIVMpJFllAW1MUzITY/Il9M3y2MNy4ld6n3/k5VXal4lEznfTajHUMIcrc53kH+Z69uij2d/Ejg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zd6P0fZ6k3o3WMUNghQi6mMI+CPAIsveeO98Isieabc=; b=2UmqsIQlpyIvfucEbQ6vvCKIuPuLY63DVdZ7PD8GVTWIHIJJn7Xlih6BG4xyAwIo2Si0QwIC3L3lLJ00UqRQKl6aB/lYRr4cQMYbc6GAh9MbvdMR3tWCHXwVTpBNaCEztnTAP3bGHmWndQbJuttP1tet08pQplb7/x9OF12eUis= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Stewart Hildebrand To: CC: Stewart Hildebrand , Andrew Cooper , George Dunlap , "Jan Beulich" , Julien Grall , "Stefano Stabellini" , Wei Liu Subject: [PATCH v5 3/5] xen/pci: update PCI_STATUS_* constants Date: Fri, 1 Sep 2023 00:57:30 -0400 Message-ID: <20230901045742.235975-4-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230901045742.235975-1-stewart.hildebrand@amd.com> References: <20230901045742.235975-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3A:EE_|MN2PR12MB4344:EE_ X-MS-Office365-Filtering-Correlation-Id: 8671c735-8bbf-46ae-0024-08dbaaa851c6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5tf0om0kWnVBHXxoscfu1/afuAUO7NgASO06LKNuf6UTwA7OMk3nAH+20dz2EW0ahk5sqS+wHblXGD45hRjx1JBe/9kjOSzemLFPG+G9zYoCxHnB9/vjWg2sM+0QsjSRbwpXuAGrVGYFaQvwosjAqNR5naBO3OsqZyWsPtyFQ9mMZAfwKfDMfPcTUR9xWDMN/mR0BMMAauSeepzY15YBP9UfCgGFsoRBMGA0uEXCNaiMQxo/YVF0/GELu0VPJJ1n1wFCpMMh09x059/JpuP8IG17cMhhB6MVwiVtL3GgKjoYu2EmVG6ReyY4ejE6Q6r7Sr+t4mAEh44DTGDe/ysDqfENFjf5dxPLITfkhCM+Dafz1pjmMfIf+JybDlVeiTxDSWw5D+CN7VLXLOPrRUYlEorELa6aNbhL1PGEfSqwtl5syrsJEi8cTvWMYz3+wdK53i3rLdUiUTGtKD8ryk9mz890GltyuOWyVD2Ox6nHhDhZ4z5pszgaG0+MSOeXOY9/NNEiYrPOuaU3ybRWeXcQv4ntBpch0cGaSPQSnulagBO7OPBtKXEkZQ+395jKmjbpgdQYcOOXVNd3KErwRd8h4ttnApVktlRzFW0FmXCQyX44J8IgNiRFwiFpolNOYdoGeRDp4R3W6EDn7psglAnRwU1HuUc1DJv9Y6Vn+6HM6jMJ6xbptjb/eWQrXrQA4vQvs1vYVcmqKVjSwHJDo+xFIc2hal1ZQxIl0mfpltlwd8f7g2LDaiZE/vCyLOGx4h8prhN/XkIl5D1/PgJ/SJYz0w== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(376002)(136003)(39860400002)(346002)(82310400011)(451199024)(186009)(1800799009)(36840700001)(46966006)(40470700004)(6666004)(36860700001)(82740400003)(356005)(40480700001)(81166007)(478600001)(47076005)(54906003)(316002)(41300700001)(70206006)(70586007)(86362001)(40460700003)(2906002)(5660300002)(426003)(6916009)(36756003)(4744005)(336012)(2616005)(1076003)(44832011)(26005)(8676002)(8936002)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:10.5121 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8671c735-8bbf-46ae-0024-08dbaaa851c6 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE3A.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4344 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1693544446358100003 Content-Type: text/plain; charset="utf-8" Interrupt status introduced in PCI 2.3 Immediate readiness introduced in PCIe 4.0 Signed-off-by: Stewart Hildebrand Reviewed-by: Jan Beulich --- v4->v5: * new patch --- xen/include/xen/pci_regs.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xen/include/xen/pci_regs.h b/xen/include/xen/pci_regs.h index a90aff1712ba..84b18736a85d 100644 --- a/xen/include/xen/pci_regs.h +++ b/xen/include/xen/pci_regs.h @@ -50,6 +50,8 @@ #define PCI_COMMAND_INTX_DISABLE 0x400 /* INTx Emulation Disable */ =20 #define PCI_STATUS 0x06 /* 16 bits */ +#define PCI_STATUS_IMM_READY 0x01 /* Immediate Readiness */ +#define PCI_STATUS_INTERRUPT 0x08 /* Interrupt status */ #define PCI_STATUS_CAP_LIST 0x10 /* Support Capability List */ #define PCI_STATUS_66MHZ 0x20 /* Support 66 Mhz PCI 2.1 bus */ #define PCI_STATUS_UDF 0x40 /* Support User Definable Features [obsolete= ] */ --=20 2.42.0 From nobody Sat May 11 11:43:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1693545091; cv=pass; d=zohomail.com; s=zohoarc; b=XQAXSFcxw7xR0EcYEJynB7L8s8zh6aC0+cDWbWJKfaG8Q3TLkcUnElUORqTjZMUyDx/Xp2h3NpQx2Dmz6qWeIXrN2mIHRVY6Wp4QDAMsfVmc1aTkJY2hgu6Gh1LttngI9YF9IK8gYLd6sZCIh6XE5CsghKdrBJC4eFaowtMAeNQ= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693545091; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8KaFay1YX9Z8ga1iLYKzEiksiXOhKppKo65QZoKXwB8=; b=Rq6v1NGFQneewYzCEP+ifwTzdRqjzuLFb+C901+7nFbemI4JQ8ao3SrOEtY3y9g6C3/MXJBlxkV8WK++2jLJdAJA1u3PKmmgxrUbOp5muYculWn8Do/qQbehQLJuiNPtiOqNnLdfUicon7TQCAObMH3xWa0KIXVT2fvfDH4esio= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1693545091657627.5336319860519; Thu, 31 Aug 2023 22:11:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.594262.927561 (Exim 4.92) (envelope-from ) id 1qbwR8-0001TY-K2; Fri, 01 Sep 2023 05:11:14 +0000 Received: by outflank-mailman (output) from mailman id 594262.927561; Fri, 01 Sep 2023 05:11:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwR8-0001Sh-ET; Fri, 01 Sep 2023 05:11:14 +0000 Received: by outflank-mailman (input) for mailman id 594262; Fri, 01 Sep 2023 05:11:12 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGz-0000Nr-Fi for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:45 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2062e.outbound.protection.outlook.com [2a01:111:f400:fe5a::62e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 802edf13-4884-11ee-8783-cb3800f73035; Fri, 01 Sep 2023 07:00:43 +0200 (CEST) Received: from CYXPR03CA0024.namprd03.prod.outlook.com (2603:10b6:930:d0::6) by SA3PR12MB9228.namprd12.prod.outlook.com (2603:10b6:806:39c::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.21; Fri, 1 Sep 2023 05:00:39 +0000 Received: from CY4PEPF0000EE36.namprd05.prod.outlook.com (2603:10b6:930:d0:cafe::e0) by CYXPR03CA0024.outlook.office365.com (2603:10b6:930:d0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.26 via Frontend Transport; Fri, 1 Sep 2023 05:00:38 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE36.mail.protection.outlook.com (10.167.242.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.17 via Frontend Transport; Fri, 1 Sep 2023 05:00:38 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 1 Sep 2023 00:00:37 -0500 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 1 Sep 2023 00:00:36 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 802edf13-4884-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ALwvTiVUKP2LQF75EQ4M+lHRB/TQENH+gIgDX76ZiF3WdchiZtCEWONgYCBp6eUfXpGTJTjWBwvPO8BNjkYB+MYd85ypUKh/EYePIF3Cph25ndvf68REvGA1QyxKqbpxeTk2g/MCMTOJhbLDdZSTwn6y9BVbs8V6DGObQ3p8o0wMq4sa6KwSWiKMRFMQBH/bOHLcScMtVDnWxxlZf9hcav+tDSiYC5FqEzZtA3NgwIVX6hj8wA0tBr0NkYV0KEL3y0cFoGYeGMzOhVebn6HlS0FUdtdKpP11muS/gl8XqOxeeLpOt60YQpfgVSG/Mgoh4IooEXWO1tM8B756CGb6Bg== 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=8KaFay1YX9Z8ga1iLYKzEiksiXOhKppKo65QZoKXwB8=; b=NuFS3lhaCNw/RU0x1VS53d920Ag+6pL+O2N9GsrIzA59Rq0Q5vX5iHeWvKRnFzKvNkepR7uWpXO7TEAoeNeKCZLtjs6U0sOPNiJ8C7mW7fo85qWWDlPzFU3yhehRznSiQ1JUhqhHvraPwUo7WzxdzBnGG91SwSFtKBWKG5vyRDujAPjvx6HQvbit0FEwLcS7CbogXoeyu57+tKGi3JSmUqfFrCFHWbCI2ObkEnkEjzJlFiYlwhHfeHH14VwTLOTucLyy9XG9sa6xW8o/u0AJnmVxQnrH6Mirz7si6A9YZvJ9xEuIA8pzlizCzJTQSbOB1rhxFQRfmbgRfyn6EtghJw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8KaFay1YX9Z8ga1iLYKzEiksiXOhKppKo65QZoKXwB8=; b=2+xToq1c3rldSz2P2GatSA9a9MZgg3TC2zQ32xI9auzwxzfiiYwsSQCx0ZDTNTZTswRO2tHN+a53ExaUakjeXx9Za+2q+TctHrY+hi/5gMfH+ywieBp3HkjvBEFTSSK04sKYDVyS14B6H6DpsXnZxQ2Bd9sT7SPEcqP1kNzHfTc= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Stewart Hildebrand To: CC: Stewart Hildebrand , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Andrew Cooper , George Dunlap , "Jan Beulich" , Julien Grall , "Stefano Stabellini" , Wei Liu Subject: [PATCH v5 4/5] xen/vpci: header: status register handler Date: Fri, 1 Sep 2023 00:57:31 -0400 Message-ID: <20230901045742.235975-5-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230901045742.235975-1-stewart.hildebrand@amd.com> References: <20230901045742.235975-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE36:EE_|SA3PR12MB9228:EE_ X-MS-Office365-Filtering-Correlation-Id: b2c3caae-94ad-4aa0-0895-08dbaaa86291 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xmVTJfwepUxRAI4b5u7VJxt9BSNe9tL+3Hi6kSQrHajETJ7SW5WWJ6D0DdPDh7Fnxv6baRpww+DbhLkjuw5vgXLYqJ6jOJmwM0VTNmM28+V3ySBp1w4aIhQWFrJyB9EVxSAY8sjeenZys3d44vidsqIFNZUtALYBN0L2sZrP4CeLQg+YxZEULc2GchuTSjE5djW4WK4CCbAuVaoGfGDjzlXmhqCVfhvKDctR1nYm9cXBHdnoltlLV93ErnCKM3q2oUO/LYwp/E9ieLtVBA/28IFpM32j7EYHicUeSaDj7XgEXaLetz/vyvB3g+1FfIaz0FdupgkpObPvJ8J8jouUAA2g8deeqHj8n/xAnTvwVd7iPPfUD/bFY8Tv0at9MXrQZpSEk/q4JxYw9ONAQCPUxzqU+hyM31wnoW0b9Pd2tTeL6/voN4L+5HopHqwIFT3J2IAPah55ykOlR+tXasxJsr8+qENxRU13NjVVgY1Qa3eiYwK4v80bR9Woqxpc+xlUe6dbUCOz/q2Ws9kBRvcHbaOfF/WRFILkusGxrNblv5bSTomr3oESdBBjISfPnDVYD/PPvDaTmD9b+M+Smq0txGiaxixE2AaOFEyI54n5FPfZIdH17vwe3eFNuFjuBbTFFocexkLMFx+nHbWQstC1/WX7ZdZUQqBacRaVXXQfiL1ClHGalhFCB/iSC8iimN2RDzmr6GUAgCa9/OqPW/O2dSQ8CtSDoSU04xNaiTZAfSBz/JbLHezdrimGvqeWlkVyXBSsW+NdrGx6c2Gaazwt6HBscKthfM7jdnCL9acAMfs= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(39860400002)(396003)(376002)(136003)(1800799009)(186009)(451199024)(82310400011)(36840700001)(40470700004)(46966006)(82740400003)(66899024)(356005)(6666004)(40460700003)(36756003)(86362001)(81166007)(36860700001)(40480700001)(47076005)(2616005)(1076003)(2906002)(426003)(336012)(26005)(83380400001)(478600001)(8936002)(70586007)(70206006)(54906003)(8676002)(4326008)(44832011)(5660300002)(41300700001)(6916009)(316002)(36900700001)(357404004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:38.6863 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b2c3caae-94ad-4aa0-0895-08dbaaa86291 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE36.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB9228 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1693545093180100001 Content-Type: text/plain; charset="utf-8" Introduce a handler for the PCI status register, with ability to mask the capabilities bit. The status register contains reserved bits, read-only bit= s, and write-1-to-clear bits, so introduce bitmasks to handle these in vPCI. I= f a bit in the bitmask is set, then the special meaning applies: res_mask: read as zero, write ignore ro_mask: read normal, write ignore rw1c_mask: read normal, write 1 to clear The mask_cap_list flag will be set in a follow-on patch. Signed-off-by: Stewart Hildebrand --- v4->v5: * add support for res_mask * add support for ro_mask (squash ro_mask patch) * add constants for reserved, read-only, and rw1c masks v3->v4: * move mask_cap_list setting to the capabilities patch * single pci_conf_read16 in status_read * align mask_cap_list bitfield in struct vpci_header * change to rw1c bit mask instead of treating whole register as rw1c * drop subsystem prefix on renamed add_register function v2->v3: * new patch --- xen/drivers/vpci/header.c | 18 +++++++++++++++ xen/drivers/vpci/vpci.c | 46 +++++++++++++++++++++++++++++++------- xen/include/xen/pci_regs.h | 8 +++++++ xen/include/xen/vpci.h | 10 +++++++++ 4 files changed, 74 insertions(+), 8 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 767c1ba718d7..791791e6c9b6 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -413,6 +413,18 @@ static void cf_check cmd_write( pci_conf_write16(pdev->sbdf, reg, cmd); } =20 +static uint32_t cf_check status_read(const struct pci_dev *pdev, + unsigned int reg, void *data) +{ + struct vpci_header *header =3D data; + uint32_t status =3D pci_conf_read16(pdev->sbdf, reg); + + if ( header->mask_cap_list ) + status &=3D ~PCI_STATUS_CAP_LIST; + + return status; +} + static void cf_check bar_write( const struct pci_dev *pdev, unsigned int reg, uint32_t val, void *data) { @@ -544,6 +556,12 @@ static int cf_check init_bars(struct pci_dev *pdev) if ( rc ) return rc; =20 + rc =3D vpci_add_register_mask(pdev->vpci, status_read, vpci_hw_write16, + PCI_STATUS, 2, header, PCI_STATUS_RESERVED= _MASK, + PCI_STATUS_RO_MASK, PCI_STATUS_RW1C_MASK); + if ( rc ) + return rc; + if ( pdev->ignore_bars ) return 0; =20 diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 3bec9a4153da..6e6ad4b80a0d 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -29,6 +29,9 @@ struct vpci_register { unsigned int offset; void *private; struct list_head node; + uint32_t res_mask; + uint32_t ro_mask; + uint32_t rw1c_mask; }; =20 #ifdef __XEN__ @@ -145,9 +148,16 @@ uint32_t cf_check vpci_hw_read32( return pci_conf_read32(pdev->sbdf, reg); } =20 -int vpci_add_register(struct vpci *vpci, vpci_read_t *read_handler, - vpci_write_t *write_handler, unsigned int offset, - unsigned int size, void *data) +void cf_check vpci_hw_write16( + const struct pci_dev *pdev, unsigned int reg, uint32_t val, void *data) +{ + pci_conf_write16(pdev->sbdf, reg, val); +} + +static int add_register(struct vpci *vpci, vpci_read_t *read_handler, + vpci_write_t *write_handler, unsigned int offset, + unsigned int size, void *data, uint32_t res_mask, + uint32_t ro_mask, uint32_t rw1c_mask) { struct list_head *prev; struct vpci_register *r; @@ -167,6 +177,9 @@ int vpci_add_register(struct vpci *vpci, vpci_read_t *r= ead_handler, r->size =3D size; r->offset =3D offset; r->private =3D data; + r->res_mask =3D res_mask & (0xffffffffU >> (32 - 8 * size)); + r->ro_mask =3D ro_mask & (0xffffffffU >> (32 - 8 * size)); + r->rw1c_mask =3D rw1c_mask & (0xffffffffU >> (32 - 8 * size)); =20 spin_lock(&vpci->lock); =20 @@ -193,6 +206,23 @@ int vpci_add_register(struct vpci *vpci, vpci_read_t *= read_handler, return 0; } =20 +int vpci_add_register(struct vpci *vpci, vpci_read_t *read_handler, + vpci_write_t *write_handler, unsigned int offset, + unsigned int size, void *data) +{ + return add_register(vpci, read_handler, write_handler, offset, size, d= ata, + 0, 0, 0); +} + +int vpci_add_register_mask(struct vpci *vpci, vpci_read_t *read_handler, + vpci_write_t *write_handler, unsigned int offse= t, + unsigned int size, void *data, uint32_t res_mas= k, + uint32_t ro_mask, uint32_t rw1c_mask) +{ + return add_register(vpci, read_handler, write_handler, offset, size, d= ata, + res_mask, ro_mask, rw1c_mask); +} + int vpci_remove_register(struct vpci *vpci, unsigned int offset, unsigned int size) { @@ -376,6 +406,7 @@ uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, u= nsigned int size) } =20 val =3D r->read(pdev, r->offset, r->private); + val &=3D ~r->res_mask; =20 /* Check if the read is in the middle of a register. */ if ( r->offset < emu.offset ) @@ -407,11 +438,6 @@ uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, = unsigned int size) =20 /* * Perform a maybe partial write to a register. - * - * Note that this will only work for simple registers, if Xen needs to - * trap accesses to rw1c registers (like the status PCI header register) - * the logic in vpci_write will have to be expanded in order to correctly - * deal with them. */ static void vpci_write_helper(const struct pci_dev *pdev, const struct vpci_register *r, unsigned int = size, @@ -424,9 +450,13 @@ static void vpci_write_helper(const struct pci_dev *pd= ev, uint32_t val; =20 val =3D r->read(pdev, r->offset, r->private); + val &=3D ~r->res_mask; + val &=3D ~r->rw1c_mask; data =3D merge_result(val, data, size, offset); } =20 + data &=3D ~r->res_mask; + data &=3D ~r->ro_mask; r->write(pdev, r->offset, data & (0xffffffffU >> (32 - 8 * r->size)), r->private); } diff --git a/xen/include/xen/pci_regs.h b/xen/include/xen/pci_regs.h index 84b18736a85d..b7cb200969c6 100644 --- a/xen/include/xen/pci_regs.h +++ b/xen/include/xen/pci_regs.h @@ -66,6 +66,14 @@ #define PCI_STATUS_REC_MASTER_ABORT 0x2000 /* Set on master abort */ #define PCI_STATUS_SIG_SYSTEM_ERROR 0x4000 /* Set when we drive SERR */ #define PCI_STATUS_DETECTED_PARITY 0x8000 /* Set on parity error */ +#define PCI_STATUS_RESERVED_MASK 0x06 +#define PCI_STATUS_RO_MASK (PCI_STATUS_IMM_READY | PCI_STATUS_INTERRUPT |= \ + PCI_STATUS_CAP_LIST | PCI_STATUS_CAP_LIST | PCI_STATUS_66MHZ | \ + PCI_STATUS_UDF | PCI_STATUS_FAST_BACK | PCI_STATUS_DEVSEL_MASK) +#define PCI_STATUS_RW1C_MASK (PCI_STATUS_PARITY | \ + PCI_STATUS_SIG_TARGET_ABORT | PCI_STATUS_REC_TARGET_ABORT | \ + PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_SIG_SYSTEM_ERROR | \ + PCI_STATUS_DETECTED_PARITY) =20 #define PCI_CLASS_REVISION 0x08 /* High 24 bits are class, low 8 revision = */ #define PCI_REVISION_ID 0x08 /* Revision ID */ diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 0b8a2a3c745b..0a6c9e19b399 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -37,6 +37,12 @@ int __must_check vpci_add_register(struct vpci *vpci, vpci_write_t *write_handler, unsigned int offset, unsigned int size, void *data); +int __must_check vpci_add_register_mask(struct vpci *vpci, + vpci_read_t *read_handler, + vpci_write_t *write_handler, + unsigned int offset, unsigned int = size, + void *data, uint32_t res_mask, + uint32_t ro_mask, uint32_t rw1c_ma= sk); int __must_check vpci_remove_register(struct vpci *vpci, unsigned int offs= et, unsigned int size); =20 @@ -50,6 +56,8 @@ uint32_t cf_check vpci_hw_read16( const struct pci_dev *pdev, unsigned int reg, void *data); uint32_t cf_check vpci_hw_read32( const struct pci_dev *pdev, unsigned int reg, void *data); +void cf_check vpci_hw_write16( + const struct pci_dev *pdev, unsigned int reg, uint32_t val, void *data= ); =20 /* * Check for pending vPCI operations on this vcpu. Returns true if the vcpu @@ -94,6 +102,8 @@ struct vpci { * upon to know whether BARs are mapped into the guest p2m. */ bool bars_mapped : 1; + /* Store whether to hide all capabilities from the guest. */ + bool mask_cap_list : 1; /* FIXME: currently there's no support for SR-IOV. */ } header; =20 --=20 2.42.0 From nobody Sat May 11 11:43:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1693545325; cv=pass; d=zohomail.com; s=zohoarc; b=SmEjIZV8BUgHKamnsoHPAirXaRky3oZRnnAk9QlrtPBPyiUzP+U7kDn0tth8JGSXs9FFxO5eY9fHFzqYotUmWQk6JW/DCON1Ccd3s/9nOLuH/GBnxEpNzSS7MPE8rml0qkov3LwHY3pTBtR6wbUYON869wTEJwhB7YEk/unsIA4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693545325; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EWgrFE1PFgTCu8cgThjyBQIC11fyPr/WMl8soFJau04=; b=eov+GEQd6X9MLyodUZi4V50SJUApAmnc2bxZObYZep16MyaCZSnbq5XSBwa7WQyKaxqmOTkRDSh3l4F0o4VbdzgvUrVIA3bgWNMXIXfAolV41evbysCmrVnmpmgHuFTlvQup9NhRXz6OTH8O2ah1cbIMn2Y6N3B2prYS8ZsAdRE= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1693545325823158.89212802601855; Thu, 31 Aug 2023 22:15:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.594357.927685 (Exim 4.92) (envelope-from ) id 1qbwUj-0001Ga-Dw; Fri, 01 Sep 2023 05:14:57 +0000 Received: by outflank-mailman (output) from mailman id 594357.927685; Fri, 01 Sep 2023 05:14:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwUj-0001GT-BB; Fri, 01 Sep 2023 05:14:57 +0000 Received: by outflank-mailman (input) for mailman id 594357; Fri, 01 Sep 2023 05:14:56 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwUi-0001GN-03 for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:14:56 +0000 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on20616.outbound.protection.outlook.com [2a01:111:f400:7e8c::616]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7c2335fe-4886-11ee-8783-cb3800f73035; Fri, 01 Sep 2023 07:14:54 +0200 (CEST) Received: from MW4PR04CA0348.namprd04.prod.outlook.com (2603:10b6:303:8a::23) by CH0PR12MB5188.namprd12.prod.outlook.com (2603:10b6:610:bb::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.22; Fri, 1 Sep 2023 05:14:48 +0000 Received: from CO1PEPF000044FD.namprd21.prod.outlook.com (2603:10b6:303:8a:cafe::7a) by MW4PR04CA0348.outlook.office365.com (2603:10b6:303:8a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.25 via Frontend Transport; Fri, 1 Sep 2023 05:14:48 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000044FD.mail.protection.outlook.com (10.167.241.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.2 via Frontend Transport; Fri, 1 Sep 2023 05:14:47 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 1 Sep 2023 00:14:47 -0500 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 1 Sep 2023 00:14:45 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7c2335fe-4886-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YdY06kseYzjerhRqBZ9zVe8f8CFXvHIuLjWaFPOdwwGDjmMHLy8ZUg8Vp7p3hAeb6uEgn0uzg2kvbGNmMCMCnRd7oUIF/g/bhmNs+cES2ubqyxnFFqSkiVIFAiMFbNz86ii4vB+Sq9eSHc1TGS3/26rF1+NR/kKfi+FbZEio6afyXvreGBwxWInI1/LAtnSQH02o1fodIFqQtoJZ8l/4zkMUxUTuhEW2jCT01NxTtAvGsjyy0XKF8y4Y/Gvaml/7cCmDykrXjNyhyz6nwdKyQK5F8/obDKMvjnMkWozlrRs+OWqFRzdrtcqJkbldXCNgyPv1jUc63LHS0+U1ZGQEfg== 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=EWgrFE1PFgTCu8cgThjyBQIC11fyPr/WMl8soFJau04=; b=FQDOdkseF2A6nt3vS3PI/GTkpz1Dxp8hxd7th1V1cqdduLt39NhQeIJ8+knPy4f2gNe84Er+ICFMCLWlejbqum9Y8hBYvq1j4X9Ch0N63HDIhnElplTQ76HqZvOhkPTCVUNsHzjg77kSEnlNiTRj4+0EI4qb98O4WJm2/rn+Tie87yWSpgvIuH8vlEGfsdxWmzOZj9v8b48PDfQyF7OFKpra5O+Dr/2PmMVAuyMvGQg6kIs/ZhrJwe0t3jAspDT46j4gUeta0sC4Een6+eWO6ZHQoldesso9k5V9mSBdC69B1T/7wnVq98efzWyOnrIK1mz3J6AeshvnyPkCwVjuxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EWgrFE1PFgTCu8cgThjyBQIC11fyPr/WMl8soFJau04=; b=J6kdAQjeqLkS7bHW636KUKc3VGkFdw7mFfj0QvoBuiVOu9fFCcoLx+HLHiNjJVL7MTVC2axIPLDCGg//Kt1HKBda6dWgFg2Rz/yx/cnAA/AisHmvP++p+Qg4/gFWr+RI10BW8x/p8Ve3vOB7vZHdrSUYqx9Odh4gI58XQmd0bUA= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Stewart Hildebrand To: CC: Stewart Hildebrand , Andrew Cooper , George Dunlap , "Jan Beulich" , Julien Grall , "Stefano Stabellini" , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v5 5/5] xen/vpci: header: filter PCI capabilities Date: Fri, 1 Sep 2023 01:13:53 -0400 Message-ID: <20230901051357.236049-1-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230901045742.235975-1-stewart.hildebrand@amd.com> References: <20230901045742.235975-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044FD:EE_|CH0PR12MB5188:EE_ X-MS-Office365-Filtering-Correlation-Id: 2a342d2c-33ef-41eb-8b07-08dbaaaa5ccd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zQif1+PdSaApbuz2d6GvtRDV5Z6CZ8zj2tvIicfZfaAmSiMWZ/X/VWqVVxu9HcB+SNs5uETERwCd0TLpS6eMdgNaIW4QCqjxBsm90BlT/ZVf5POP3no0Ln86cKs4w/k2hSjShOyLWI5oF/up9b8Yael6E+S1PnW6b/HlGeSas1prQvLMSJcsC/5OCBc0E2M9w2Wi9JHV+Gv0fQPW6dRGH1sU+paGtCcluR9FixbUuMUdhv21EGRo0zE1L/EQXy/MqOeCDVR6vGYM+DhdsWaLwYQ9ZdbDoliseDcr1j9l7t5xcjly1V81iDyQwxRXXsXnUaFtwzyENZ8we2n1C5Fmy/8VdQ4To5xHmWMuwu/ZwCsW9qhWic/Ne12S6e27HQ/AgYa7Ax/NNSWZWuzRTewTOjI18A6LHlerCu3nUNsG5fyikd22XPRviY3smdMbHMH5uEhSiLeVdhEWszkwYz+Gv/LADDWoiaFyK1c5pa7fjcYbJowEEIKcmWMCYgnaYm6gDHtSpNV3AnJSyC0I/2al8b/QrZAW7i0wvxNDjUA8Y7RnQ4WizuImJJll/M1FduXrXz3ppwzguC0hx9qBpQM/CU4gucDYaa2s9I1RTyIIkzn/u3ZxyiFjQtdZa+XHW6EVTCFkRSIvKi7KANvbbCHRtYvNDa85bYBJkvG5h7XcZOq+Gsc5ff/LlqdRvj/+Jwx0BMUJhGhwZbCNoWxAPWnan/sjUi+kSWpLZJsIlgGMX4B1rJv+arhw2TIabPj0pohvYv6/Yonz6/GoeFvCrHIX7w== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(376002)(136003)(39860400002)(346002)(82310400011)(451199024)(186009)(1800799009)(36840700001)(46966006)(40470700004)(6666004)(36860700001)(82740400003)(356005)(40480700001)(83380400001)(81166007)(478600001)(47076005)(54906003)(316002)(41300700001)(70206006)(70586007)(86362001)(40460700003)(2906002)(5660300002)(426003)(6916009)(36756003)(336012)(2616005)(1076003)(44832011)(26005)(8676002)(8936002)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:14:47.9631 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2a342d2c-33ef-41eb-8b07-08dbaaaa5ccd X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000044FD.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5188 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1693545327114100001 Content-Type: text/plain; charset="utf-8" Currently, Xen vPCI only supports virtualizing the MSI and MSI-X capabiliti= es. Hide all other PCI capabilities (including extended capabilities) from domU= s for now, even though there may be certain devices/drivers that depend on being = able to discover certain capabilities. We parse the physical PCI capabilities linked list and add vPCI register handlers for the next elements, inserting our own next value, thus presenti= ng a modified linked list to the domU. Introduce helper functions vpci_hw_read8 and vpci_read_val. The vpci_read_v= al helper function returns a fixed value, which may be used for RAZ registers,= or registers whose value doesn't change. Introduce pci_find_next_cap_ttl() helper while adapting the logic from pci_find_next_cap() to suit our needs, and implement the existing pci_find_next_cap() in terms of the new helper. Signed-off-by: Stewart Hildebrand Reviewed-by: Jan Beulich --- v4->v5: * use more appropriate types, continued * get rid of unnecessary hook function * add Jan's R-b v3->v4: * move mask_cap_list setting to this patch * leave pci_find_next_cap signature alone * use more appropriate types v2->v3: * get rid of > 0 in loop condition * implement pci_find_next_cap in terms of new pci_find_next_cap_ttl functio= n so that hypothetical future callers wouldn't be required to pass &ttl. * change NULL to (void *)0 for RAZ value passed to vpci_read_val * change type of ttl to unsigned int * remember to mask off the low 2 bits of next in the initial loop iteration * change return type of pci_find_next_cap and pci_find_next_cap_ttl * avoid wrapping the PCI_STATUS_CAP_LIST condition by using ! instead of = =3D=3D 0 v1->v2: * change type of ttl to int * use switch statement instead of if/else * adapt existing pci_find_next_cap helper instead of rolling our own * pass ttl as in/out * "pass through" the lower 2 bits of the next pointer * squash helper functions into this patch to avoid transient dead code situ= ation * extended capabilities RAZ/WI --- xen/drivers/pci/pci.c | 26 +++++++++----- xen/drivers/vpci/header.c | 76 +++++++++++++++++++++++++++++++++++++++ xen/drivers/vpci/vpci.c | 12 +++++++ xen/include/xen/pci.h | 3 ++ xen/include/xen/vpci.h | 5 +++ 5 files changed, 113 insertions(+), 9 deletions(-) diff --git a/xen/drivers/pci/pci.c b/xen/drivers/pci/pci.c index 3569ccb24e9e..8799d60c2156 100644 --- a/xen/drivers/pci/pci.c +++ b/xen/drivers/pci/pci.c @@ -39,31 +39,39 @@ unsigned int pci_find_cap_offset(pci_sbdf_t sbdf, unsig= ned int cap) return 0; } =20 -unsigned int pci_find_next_cap(pci_sbdf_t sbdf, unsigned int pos, - unsigned int cap) +unsigned int pci_find_next_cap_ttl(pci_sbdf_t sbdf, unsigned int pos, + bool (*is_match)(unsigned int), + unsigned int cap, unsigned int *ttl) { - u8 id; - int ttl =3D 48; + unsigned int id; =20 - while ( ttl-- ) + while ( (*ttl)-- ) { pos =3D pci_conf_read8(sbdf, pos); if ( pos < 0x40 ) break; =20 - pos &=3D ~3; - id =3D pci_conf_read8(sbdf, pos + PCI_CAP_LIST_ID); + id =3D pci_conf_read8(sbdf, (pos & ~3) + PCI_CAP_LIST_ID); =20 if ( id =3D=3D 0xff ) break; - if ( id =3D=3D cap ) + if ( (is_match && is_match(id)) || (!is_match && id =3D=3D cap) ) return pos; =20 - pos +=3D PCI_CAP_LIST_NEXT; + pos =3D (pos & ~3) + PCI_CAP_LIST_NEXT; } + return 0; } =20 +unsigned int pci_find_next_cap(pci_sbdf_t sbdf, unsigned int pos, + unsigned int cap) +{ + unsigned int ttl =3D 48; + + return pci_find_next_cap_ttl(sbdf, pos, NULL, cap, &ttl) & ~3; +} + /** * pci_find_ext_capability - Find an extended capability * @sbdf: PCI device to query diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 791791e6c9b6..f7d02a7f7bfa 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -525,6 +525,18 @@ static void cf_check rom_write( rom->addr =3D val & PCI_ROM_ADDRESS_MASK; } =20 +static bool cf_check vpci_cap_supported(unsigned int id) +{ + switch ( id ) + { + case PCI_CAP_ID_MSI: + case PCI_CAP_ID_MSIX: + return true; + default: + return false; + } +} + static int cf_check init_bars(struct pci_dev *pdev) { uint16_t cmd; @@ -562,6 +574,70 @@ static int cf_check init_bars(struct pci_dev *pdev) if ( rc ) return rc; =20 + if ( !is_hardware_domain(pdev->domain) ) + { + if ( !(pci_conf_read16(pdev->sbdf, PCI_STATUS) & PCI_STATUS_CAP_LI= ST) ) + { + /* RAZ/WI */ + rc =3D vpci_add_register(pdev->vpci, vpci_read_val, NULL, + PCI_CAPABILITY_LIST, 1, (void *)0); + if ( rc ) + return rc; + } + else + { + /* Only expose capabilities to the guest that vPCI can handle.= */ + unsigned int next, ttl =3D 48; + + next =3D pci_find_next_cap_ttl(pdev->sbdf, PCI_CAPABILITY_LIST, + vpci_cap_supported, 0, &ttl); + + rc =3D vpci_add_register(pdev->vpci, vpci_read_val, NULL, + PCI_CAPABILITY_LIST, 1, + (void *)(uintptr_t)next); + if ( rc ) + return rc; + + next &=3D ~3; + + if ( !next ) + /* + * If we don't have any supported capabilities to expose t= o the + * guest, mask the PCI_STATUS_CAP_LIST bit in the status + * register. + */ + header->mask_cap_list =3D true; + + while ( next && ttl ) + { + unsigned int pos =3D next; + + next =3D pci_find_next_cap_ttl(pdev->sbdf, + pos + PCI_CAP_LIST_NEXT, + vpci_cap_supported, 0, &ttl); + + rc =3D vpci_add_register(pdev->vpci, vpci_hw_read8, NULL, + pos + PCI_CAP_LIST_ID, 1, NULL); + if ( rc ) + return rc; + + rc =3D vpci_add_register(pdev->vpci, vpci_read_val, NULL, + pos + PCI_CAP_LIST_NEXT, 1, + (void *)(uintptr_t)next); + if ( rc ) + return rc; + + next &=3D ~3; + } + } + + /* Extended capabilities RAZ/WI */ + rc =3D vpci_add_register(pdev->vpci, vpci_read_val, NULL, 0x100, 4, + (void *)0); + if ( rc ) + return rc; + } + if ( pdev->ignore_bars ) return 0; =20 diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 6e6ad4b80a0d..94cbae312abe 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -136,6 +136,18 @@ static void cf_check vpci_ignored_write( { } =20 +uint32_t cf_check vpci_read_val( + const struct pci_dev *pdev, unsigned int reg, void *data) +{ + return (uintptr_t)data; +} + +uint32_t cf_check vpci_hw_read8( + const struct pci_dev *pdev, unsigned int reg, void *data) +{ + return pci_conf_read8(pdev->sbdf, reg); +} + uint32_t cf_check vpci_hw_read16( const struct pci_dev *pdev, unsigned int reg, void *data) { diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h index ea6a4c9abf38..cceac8654f07 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -194,6 +194,9 @@ int pci_mmcfg_read(unsigned int seg, unsigned int bus, int pci_mmcfg_write(unsigned int seg, unsigned int bus, unsigned int devfn, int reg, int len, u32 value); unsigned int pci_find_cap_offset(pci_sbdf_t sbdf, unsigned int cap); +unsigned int pci_find_next_cap_ttl(pci_sbdf_t sbdf, unsigned int pos, + bool (*is_match)(unsigned int), + unsigned int cap, unsigned int *ttl); unsigned int pci_find_next_cap(pci_sbdf_t sbdf, unsigned int pos, unsigned int cap); unsigned int pci_find_ext_capability(pci_sbdf_t sbdf, unsigned int cap); diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 0a6c9e19b399..866bbf656e2b 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -51,7 +51,12 @@ uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, un= signed int size); void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, uint32_t data); =20 +uint32_t cf_check vpci_read_val( + const struct pci_dev *pdev, unsigned int reg, void *data); + /* Passthrough handlers. */ +uint32_t cf_check vpci_hw_read8( + const struct pci_dev *pdev, unsigned int reg, void *data); uint32_t cf_check vpci_hw_read16( const struct pci_dev *pdev, unsigned int reg, void *data); uint32_t cf_check vpci_hw_read32( --=20 2.42.0