From patchwork Thu May 30 12:25:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: CLEMENT MATHIEU--DRIF X-Patchwork-Id: 13680332 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4B2DBC25B74 for ; Thu, 30 May 2024 12:25:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCeqG-0006yU-N1; Thu, 30 May 2024 08:25:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sCeqD-0006xk-4x for qemu-devel@nongnu.org; Thu, 30 May 2024 08:25:09 -0400 Received: from smarthost3.eviden.com ([80.78.11.84]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sCeq8-00060c-PE for qemu-devel@nongnu.org; Thu, 30 May 2024 08:25:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eviden.com; i=@eviden.com; q=dns/txt; s=mail; t=1717071905; x=1748607905; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=HVKnFkrmgwdohMnHQE5psyw3hmzpcGX7tSLYpwPUtPg=; b=IPtAJfAiloqZRDL0Dy5gUXGbReO3RZOtZIsZEuNqacmtxkoxITrEDO0T LZS4yp1UqZEwhdH36a4k/vKXSvDHd8iSgJHO3vUn6wqhq8qyX3VF4NQMh VtPnXjgKUvSfp+i+Hn8FuB7ezTCtbTdK7Y/8K6ATDysU+gon1luuOEtED r8C1K4wT7ftHefjLVcG2T/irTvuQPIk+SLK62iN9yHB6m4/16eZDtx8q7 mhpayNNwXi+QPJO8rYwA2bQAUKw49yPeJvCrqbVnv6lWYzcesbibvFfMp fFJuCULyAqcao1n6hQoVuf0O8kDYoMweby4V78X2ideDDlZbW/jrOfF2i g==; X-IronPort-AV: E=Sophos;i="6.08,201,1712613600"; d="scan'208";a="13581111" X-MGA-submission: MDFFSogs6Qum6mvTEluzHApt1FNFthsGIzL8llpUFVpVjQavGTWsX3RY2poZj8ZPMel7HwgxJ05pGO5OxNPkj8ZZS5nPhniYw1F8q5Yp+Zy2VStRcmnbVkodNi5VaZ02+HvnKZXY4VgRKL/cvljPZHOXMlSYfYcXOZ8KUss0/sfWAQ== Received: from mail-he1eur01lp2051.outbound.protection.outlook.com (HELO EUR01-HE1-obe.outbound.protection.outlook.com) ([104.47.0.51]) by smarthost3.eviden.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 May 2024 14:25:01 +0200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KGi56cIw2J080kev3LMaMS2BMTPZPpxNzpgU/4zSvl/CRFrqP21dxvFe+hVywsWawUhfQ0YC81XB921dRAAmMwJtkrVZu//Fh8nS/c9EuRpfEOS5hWXRrxI3KG7SEKp9t+itYMLcVuhzudKBRdt4XAe8cS2x5QUbYRt7UemKMOz5OiJ/s//jRH7AcakXjfHuaGCyrml5lJQjCge+wKTvIcdjGRH3aceN860w/AiTpria3UBWvHZW7TvUjKb3UGqqUdtEVnRAj0emMcc5lhvniInnVDLVCVfnorJ+t9+oRT+GT623YUoyKhDnqfg1ATMNTpzQJolnoAURRMwooThyOw== 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=HVKnFkrmgwdohMnHQE5psyw3hmzpcGX7tSLYpwPUtPg=; b=SM3mtnpdwd1yjqAcl5Ccbhs67otKF29h6f5tmQ7s6FD3+qiPa6XNANFUs4C4u+WoWTmgmsmmqI0zTGszJircYNISODxZwK15aQlauIG6UhMHsiWiVeBIU9vlyDbAeYrnmYpXMtdx2CSv8PmuNsP3+GDTTaTqhTfHZ9mhMQJP8yE93eHyGwCmUv1vK1dfcNP04PTmBUCpfEmZdndgYexub6wgVSsy8qeYDmFVo732pRxO11XiWq2saF2/lEXc4UFI8PrQl0PUGgZ7CbNhJfiNr5HtWXM7vUw6G+GFB29fVmTfAfQKnBKFXqKg1Cz+q9Amv0SDit5GpBNOyn85pNdhAg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=eviden.com; dmarc=pass action=none header.from=eviden.com; dkim=pass header.d=eviden.com; arc=none Received: from AM8PR07MB7602.eurprd07.prod.outlook.com (2603:10a6:20b:24b::7) by AS8PR07MB8069.eurprd07.prod.outlook.com (2603:10a6:20b:358::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21; Thu, 30 May 2024 12:25:00 +0000 Received: from AM8PR07MB7602.eurprd07.prod.outlook.com ([fe80::fbd7:ca71:b636:6f9d]) by AM8PR07MB7602.eurprd07.prod.outlook.com ([fe80::fbd7:ca71:b636:6f9d%5]) with mapi id 15.20.7633.018; Thu, 30 May 2024 12:25:00 +0000 From: CLEMENT MATHIEU--DRIF To: "qemu-devel@nongnu.org" CC: "jasowang@redhat.com" , "zhenzhong.duan@intel.com" , "kevin.tian@intel.com" , "yi.l.liu@intel.com" , "joao.m.martins@oracle.com" , "peterx@redhat.com" , CLEMENT MATHIEU--DRIF Subject: [PATCH v1 1/8] pcie: add a helper to declare the PRI capability for a pcie device Thread-Topic: [PATCH v1 1/8] pcie: add a helper to declare the PRI capability for a pcie device Thread-Index: AQHasoxj3XXMvKtwP02RxAFJg4tHdg== Date: Thu, 30 May 2024 12:25:00 +0000 Message-ID: <20240530122439.42888-2-clement.mathieu--drif@eviden.com> References: <20240530122439.42888-1-clement.mathieu--drif@eviden.com> In-Reply-To: <20240530122439.42888-1-clement.mathieu--drif@eviden.com> Accept-Language: en-GB, fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=eviden.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: AM8PR07MB7602:EE_|AS8PR07MB8069:EE_ x-ms-office365-filtering-correlation-id: 2bd6d0bf-546e-464c-1d36-08dc80a38653 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230031|376005|1800799015|366007|38070700009; x-microsoft-antispam-message-info: =?utf-8?q?DiewgTZ0B0CSFa/Oj+sdibjjegMC8BC?= =?utf-8?q?A8MbPmFs0n675oSE42LCsLGZuircJoyMbxTOQBHl//4X1Jyj/hI7pAGUXGYZS10LC?= =?utf-8?q?vcAqO3wEyKTFmACNCjyhHr4EP8Ng9Iie0+Pa4hB07coUIHceyDmc3OTvH7hLwNQfd?= =?utf-8?q?x9XVWwzGlnXQzVxzP/a4LSi7LIIFNfPFQYomu2olvTPuFTBIGn9fpDHam1r8ugekE?= =?utf-8?q?MTHzBV5kVPrKjaNoA/aWXuGix7ZQ/ZnPtwpTeBhz5wuxAajIQDdBOhCu8tIdENacq?= =?utf-8?q?j/SPjDWFKSoU04EgIOIwcEna+4l3PTKR37k5b5tCxBZQyWgCR5uzZxLK+dwJNVxkD?= =?utf-8?q?A+JFCfI4tclRycgDt34i/81XO7rUdQ88/ro6Q2DuiuEMUlhbIGoQDF6ipWFy6j8pL?= =?utf-8?q?jHwZtoXlzEHGmHMqb7izKq/2RQECj/tTrrWg/oiMed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-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM8PR07MB7602.eurprd07.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(376005)(1800799015)(366007)(38070700009); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?yjsRIpCiDAJW1uoAvrazHkGFBany?= =?utf-8?q?1tPbeNOJcIqJlspWVlG2MTIn+3z3tPo0opspm3QxFSFonxkbkRv0fPRuC22YmVn2l?= =?utf-8?q?+u/1RIRTibAe1rPoj79Y3yyG5YIghWXHxGVL1Bh684CFdR7mLgMytitGOWX3XnlMI?= =?utf-8?q?LMH5UMdn50ANxARee7/XOPvNsAQ3ET8znPNlA9Di6aa86XWpkwBJhP0wzxMGnXiNB?= =?utf-8?q?Kft6uCbhBPl+Jd5HtKyTpU5zVmm6K4feNZve8rCXdZULnF+SwDBKB1RG2wm3xHjsq?= =?utf-8?q?wm1hnjkKslf6Njs2FAiy2PXnxu/3OVDYzG7edmAzM8S3iRrzks0Y3ds7ofdOtvxWR?= =?utf-8?q?au9b0IteE98zuUByt9VDmCe90VlawQH4P9YjyIa/fIsjXV+aJMYLKtFvcT7oUBySF?= =?utf-8?q?4gEfdtmk+4GxFoGAk+K5XKuw9Aax3rPHgPsFLAp4oLMDuAOjIRVtHZje4VDLV9DJi?= =?utf-8?q?RuW+M01VSoGoFDi/0h/Y/BlWOSO7Yt3zRCvnDKbUE0DX5tGPevVJ2jBbPN+sJQXpf?= =?utf-8?q?dfKDISnPL/M9lYbGHTdKEFdR9unuxXghzvr+SbQz1qiTEyak2Y2XI+dJYzZ3DY6xI?= =?utf-8?q?C1EpEZP4LzCQhnlCwezJvWDpaeGc+dWehqlJ0lPMo0SoK1qXM9TpnSUiCV4wuHUPo?= =?utf-8?q?15KCmVVldag5lO0zA17xw51BUGtmjV9qfPPIUdurN10gEwOsp8FaO76B0qA/5HTj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1.0 X-OriginatorOrg: eviden.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: AM8PR07MB7602.eurprd07.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2bd6d0bf-546e-464c-1d36-08dc80a38653 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 May 2024 12:25:00.0946 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 7d1c7785-2d8a-437d-b842-1ed5d8fbe00a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: PK3jXAXn42tHcufiEVyrGDZSBvkzF+2+X9y50/g0auETSNQXv1FKLYV4jYBJwKFyLTV+CT4gE2ZdGV+Rs5KqTq1cXsRyRp5WPnHFw/2qgP3HsaUnmg75Gb/nByHqCIrr X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR07MB8069 Received-SPF: pass client-ip=80.78.11.84; envelope-from=clement.mathieu--drif@eviden.com; helo=smarthost3.eviden.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org the pri configuration offset is also stored into the PCIExpressDevice to make it easier to get the PRI status register Signed-off-by: Clément Mathieu--Drif --- hw/pci/pcie.c | 25 +++++++++++++++++++++++++ include/hw/pci/pcie.h | 5 ++++- include/hw/pci/pcie_regs.h | 4 ++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 4efd84fed5..053bca6949 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -1202,6 +1202,31 @@ void pcie_pasid_init(PCIDevice *dev, uint16_t offset, uint8_t pasid_width, dev->exp.pasid_cap = offset; } +/* PRI */ +void pcie_pri_init(PCIDevice *dev, uint16_t offset, uint32_t outstanding_pr_cap, + bool prg_response_pasid_req) +{ + static const uint16_t control_reg_rw_mask = 0x3; + static const uint16_t status_reg_rw1_mask = 0x3; + static const uint32_t pr_alloc_reg_rw_mask = 0xffffffff; + + uint16_t status_reg = prg_response_pasid_req ? PCI_PRI_STATUS_PASID : 0; + status_reg |= PCI_PRI_STATUS_STOPPED; /* Stopped by default */ + + pcie_add_capability(dev, PCI_EXT_CAP_ID_PRI, PCI_PRI_VER, offset, + PCI_EXT_CAP_PRI_SIZEOF); + /* Disabled by default */ + + pci_set_word(dev->config + offset + PCI_PRI_STATUS, status_reg); + pci_set_long(dev->config + offset + PCI_PRI_MAX_REQ, outstanding_pr_cap); + + pci_set_word(dev->wmask + offset + PCI_PRI_CTRL, control_reg_rw_mask); + pci_set_word(dev->w1cmask + offset + PCI_PRI_STATUS, status_reg_rw1_mask); + pci_set_long(dev->wmask + offset + PCI_PRI_ALLOC_REQ, pr_alloc_reg_rw_mask); + + dev->exp.pri_cap = offset; +} + bool pcie_pasid_enabled(const PCIDevice *dev) { if (!pci_is_express(dev) || !dev->exp.pasid_cap) { diff --git a/include/hw/pci/pcie.h b/include/hw/pci/pcie.h index 0c127b29dc..198d6da817 100644 --- a/include/hw/pci/pcie.h +++ b/include/hw/pci/pcie.h @@ -72,9 +72,10 @@ struct PCIExpressDevice { uint16_t aer_cap; PCIEAERLog aer_log; - /* Offset of ATS and PASID capabilities in config space */ + /* Offset of ATS, PRI and PASID capabilities in config space */ uint16_t ats_cap; uint16_t pasid_cap; + uint16_t pri_cap; /* ACS */ uint16_t acs_cap; @@ -154,6 +155,8 @@ void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev, void pcie_pasid_init(PCIDevice *dev, uint16_t offset, uint8_t pasid_width, bool exec_perm, bool priv_mod); +void pcie_pri_init(PCIDevice *dev, uint16_t offset, uint32_t outstanding_pr_cap, + bool prg_response_pasid_req); bool pcie_pasid_enabled(const PCIDevice *dev); bool pcie_ats_enabled(const PCIDevice *dev); diff --git a/include/hw/pci/pcie_regs.h b/include/hw/pci/pcie_regs.h index 0a86598f80..bb8791d1b3 100644 --- a/include/hw/pci/pcie_regs.h +++ b/include/hw/pci/pcie_regs.h @@ -89,6 +89,10 @@ typedef enum PCIExpLinkWidth { /* PASID */ #define PCI_PASID_VER 1 #define PCI_EXT_CAP_PASID_MAX_WIDTH 20 + +/* PRI */ +#define PCI_PRI_VER 1 + /* AER */ #define PCI_ERR_VER 2 #define PCI_ERR_SIZEOF 0x48