From patchwork Tue May 21 13:11:41 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: 13669432 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 CA099C25B7C for ; Tue, 21 May 2024 13:12:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9PHl-000807-7h; Tue, 21 May 2024 09:12:09 -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 1s9PHU-0007i4-FC for qemu-devel@nongnu.org; Tue, 21 May 2024 09:11:55 -0400 Received: from smarthost4.eviden.com ([80.78.11.85]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9PHP-0001aH-MQ for qemu-devel@nongnu.org; Tue, 21 May 2024 09:11:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eviden.com; i=@eviden.com; q=dns/txt; s=mail; t=1716297107; x=1747833107; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=JJToM5aUVZELZtQhaipfZSocc6vx0ws4JjCmNvITMS4=; b=Q4ORA9NQzvt/9qGsZ9NsecRk1oRlnQPuGSjQc/a/Pn1skVBgL26ybrtK 0KPrntxOrabZlrLTnw7k1L4OUUGZbqYciTjGSppBD3MUjvz0HTC7z6xZq WmpQI7eJPtg3ZgxuWsUjLg8Qnf8r28NIx1vUv+r1nm5H5itON/HTNHuZb DTXWzMyjrApZfRT25uk1UlfCyAao8Qd8sqCB6KyZCfvQ6g0qUL8tkheEc yuLtJd+CwM7hSn4lfGoYqsJusau8Y/1XTmaSwDHMeAstcbF5GYQ/v9C6k SVhPrZXKCZIAHKHmqlRVywD96bz8q1UK6kWE0vgV/3+s8MsJSQus8E8zn A==; X-IronPort-AV: E=Sophos;i="6.08,177,1712613600"; d="scan'208";a="13061499" X-MGA-submission: MDGGmiUBTtPJ58NJ3am1XcxCnTVKvHX9z2M7Zb68JTmXlydljWyvft7Sm5CVtmJ/EZellkdczteT8VVfZ+n5jRFC2pxw5JcfGc9+HZDZEFY0xm0pnnf3UqKQ3549K3yQ7PbrgWA1U1ifSvOvcooiQ6MHa9HwwwQlYqbYmCfci6cDiw== Received: from mail-db8eur05lp2105.outbound.protection.outlook.com (HELO EUR05-DB8-obe.outbound.protection.outlook.com) ([104.47.17.105]) by smarthost4.eviden.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 15:11:42 +0200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PVqjDoiaN5fLIVimr0e/TAcbscvVjwz39szuZOhf71/yzbppimVUs6TA/FUsugN2X6i48CbCKdpwbX4WBnIGVJ7Yb7JOZlpDpoZCbNhMpe3a8DEohFfaDJQp6IHzJMXq3Zb4uqMvGuPrWpVIisIjIE/qpurYX4L27vCV6zmvENtKVURxiGeDjN+v84o9DEOOhAxm8h7bRw/8zfHn4DtZGba9Llx3owq82lTeKa9pvK1N7buU9M/9uP4sTOG3zXLHmeckdB+4R2xPbJjwU7QLoEBUoaBLwE/nzLXlepOCFcoj4lMuz2FuiwEJSwPInWnVd7aAxrIeSJKi+KfmgVQEyw== 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=JJToM5aUVZELZtQhaipfZSocc6vx0ws4JjCmNvITMS4=; b=Taq9Lwr2dFpCIF8fy9Ul+bxt/Wm6eMeqm/D++C+M8oV2rdGBd5Cl7gCLCeybGq7xpba77VplJSaGBU3N2bkOwcYnnPTQrd11sDYobyCO5lgsh5oAhCzB3xul6P8BHm1Tm6qPA4BAJ+vztt9uFaT/+/Kyr9INIVudGDfHZ65qT75gwZcPkg/I9XR9Jd0T3FrcpoU0R5Ac0iixNUGoBGsFrsuEzqZpBlVRZVhm3gtlP/y6S4UHRwhYmrn34hgcYwByIB9Py7+XSKIq/i2yjZSmlal77nTFJEC5RaLvL62H5Zp45qxRc5m0hCn5RZWNsC2DwLthOjIu5gxUj2o+yEiY/Q== 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 AM8PR07MB8148.eurprd07.prod.outlook.com (2603:10a6:20b:323::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.35; Tue, 21 May 2024 13:11:41 +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.7587.035; Tue, 21 May 2024 13:11:41 +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 ats_vtd 06/22] pcie: add helper to declare PASID capability for a pcie device Thread-Topic: [PATCH ats_vtd 06/22] pcie: add helper to declare PASID capability for a pcie device Thread-Index: AQHaq4BsddIhOUtVnUa3KEFa1N4Zig== Date: Tue, 21 May 2024 13:11:41 +0000 Message-ID: <20240521130946.117849-7-clement.mathieu--drif@eviden.com> References: <20240521130946.117849-1-clement.mathieu--drif@eviden.com> In-Reply-To: <20240521130946.117849-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_|AM8PR07MB8148:EE_ x-ms-office365-filtering-correlation-id: 2cbb2d2f-5b03-4f81-814c-08dc79978e86 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230031|366007|1800799015|376005|38070700009; x-microsoft-antispam-message-info: =?utf-8?q?8JQochH+45kDhjJ9gcMRK4/4N9Bukao?= =?utf-8?q?BPgqajZc5QuA2jWSMZF5mTvUktHCODgDuqcfhtiLOpAVz1MoIAoIbkd31cfV4PilA?= =?utf-8?q?PVGdhbO8x2sNl1X2ebnbfZAWsicLwp87Whm1/bPNqNlmxEy34BypeZBGeE7XVl+2j?= =?utf-8?q?3OqoRPTsXOKTh7LRrCnGJ4YuDG3IPUqxzTDB/tDzEIgS8tYwmVxkIr51W19ZLxivo?= =?utf-8?q?M1kQt7Z58gBV8mHiWMRJ8kj5ytYxG0hqT3oKX3JTSvsYw9TvxGEt0vfBiHfJPoMvj?= =?utf-8?q?FjIpm5TZqc/tBoN+UKBlftkZPhlfQSCnTDZXZeL8/2QWO08ScSHNtwNOgRD4+yeuW?= =?utf-8?q?trWj2lQI4W51NzPFgnTbEyykeeZM/5ojetFT6kXBa9MhtMdwZTayKK1AOz0kDqCpN?= =?utf-8?q?/xkTmvqM3XJg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Po3PhkYT2BAvV+tZwAg=3D=3D?= x-forefront-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)(366007)(1800799015)(376005)(38070700009); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?vtf1jaTJ2L3/9nBOfrHuBH6Hv04I?= =?utf-8?q?JckISOI4OE0pxyA2i5e92jNH/uyYu8SaHEty2ds8O9shUQ+//hfP5gUHZ2lVwsdpQ?= =?utf-8?q?ZmjjvhozT9kk6ezk9KXZtmy4wR8rXzY4IIWCXGoXKMk3ZW4n5pplOcYpiEzjT3Smv?= =?utf-8?q?AcZU2EVZVfxDMA16Knu0VFQ64HmD/nnkVHSxG80ruE7bsOCLHSXJWgViytIxs59Wt?= =?utf-8?q?DITpTY5V4j2XhSBIP2x39JTbtNwTRolf76vPo4VITTcgIZavsp6vGiEVKJmscTT/k?= =?utf-8?q?tCf33dWurkuLgGnahzec80G7aya0oRh1g+fozps/7KHJluIBzCvfAJjrWiH142sLz?= =?utf-8?q?aGtLFbSXTW4uZkcl/w7tNfRY9sxm1FwYe0sftQMOH9GZt+zZ4Q+VRDU2G14BHM2+H?= =?utf-8?q?hA6UER7MyQ1swWSZxNPh1WoEyW31i0weuEjuREQwXOMJuZZ1yLnRkWMmFWVIWqZ/C?= =?utf-8?q?Ecf6R+P9Ki5EvFBn+C9ej7iO0ZObuUJxSR6AQSyJNTEJcHP3wBE9f9hHWh/Hyc1c1?= =?utf-8?q?T4no0byAUOV/LTx/MbOdIeoe+6yNC/j5qOwp7gC8s2q6pk25ZiP68jMuToZ2QSh8k?= =?utf-8?q?R2fN8KjIpiqb7Rx4D032t5fzYXCK9Q+YiuKxtlralHivrJHyD3m78C44knIi3kM3A?= =?utf-8?q?zaAdhf0XW8wMC41kZrFhQfnfc1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sg8buaPnCTNZNGuYDmtGUdtaWRQtM=3D?= Content-ID: MIME-Version: 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: 2cbb2d2f-5b03-4f81-814c-08dc79978e86 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 May 2024 13:11:41.7446 (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: ZMRGYmhClema51FExHKXmDWGnVVZdqvdFnIt8sqY8NTBuoXx+zfuzDfvQl9aY7cO/G9rGOHdr1MXBEwtBfYFN5+3QFCyDOH4BO4pQ/tiUn7XLUOUBGbtY3yxHKEkIySk X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR07MB8148 Received-SPF: pass client-ip=80.78.11.85; envelope-from=clement.mathieu--drif@eviden.com; helo=smarthost4.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 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 Signed-off-by: Clément Mathieu--Drif --- hw/pci/pcie.c | 24 +++++++++++++++++++++++ include/hw/pci/pcie.h | 6 +++++- include/hw/pci/pcie_regs.h | 3 +++ include/standard-headers/linux/pci_regs.h | 1 + 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 4b2f0805c6..d6a052b616 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -1177,3 +1177,27 @@ void pcie_acs_reset(PCIDevice *dev) pci_set_word(dev->config + dev->exp.acs_cap + PCI_ACS_CTRL, 0); } } + +/* PASID */ +void pcie_pasid_init(PCIDevice *dev, uint16_t offset, uint8_t pasid_width, + bool exec_perm, bool priv_mod) +{ + assert(pasid_width <= PCI_EXT_CAP_PASID_MAX_WIDTH); + static const uint16_t control_reg_rw_mask = 0x07; + uint16_t capability_reg = pasid_width; + + pcie_add_capability(dev, PCI_EXT_CAP_ID_PASID, PCI_PASID_VER, offset, + PCI_EXT_CAP_PASID_SIZEOF); + + capability_reg <<= PCI_PASID_CAP_WIDTH_SHIFT; + capability_reg |= exec_perm ? PCI_PASID_CAP_EXEC : 0; + capability_reg |= priv_mod ? PCI_PASID_CAP_PRIV : 0; + pci_set_word(dev->config + offset + PCI_PASID_CAP, capability_reg); + + /* Everything is disabled by default */ + pci_set_word(dev->config + offset + PCI_PASID_CTRL, 0); + + pci_set_word(dev->wmask + offset + PCI_PASID_CTRL, control_reg_rw_mask); + + dev->exp.pasid_cap = offset; +} diff --git a/include/hw/pci/pcie.h b/include/hw/pci/pcie.h index 5eddb90976..b870958c99 100644 --- a/include/hw/pci/pcie.h +++ b/include/hw/pci/pcie.h @@ -72,8 +72,9 @@ struct PCIExpressDevice { uint16_t aer_cap; PCIEAERLog aer_log; - /* Offset of ATS capability in config space */ + /* Offset of ATS and PASID capabilities in config space */ uint16_t ats_cap; + uint16_t pasid_cap; /* ACS */ uint16_t acs_cap; @@ -150,4 +151,7 @@ void pcie_cap_slot_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); + +void pcie_pasid_init(PCIDevice *dev, uint16_t offset, uint8_t pasid_width, + bool exec_perm, bool priv_mod); #endif /* QEMU_PCIE_H */ diff --git a/include/hw/pci/pcie_regs.h b/include/hw/pci/pcie_regs.h index 9d3b6868dc..0a86598f80 100644 --- a/include/hw/pci/pcie_regs.h +++ b/include/hw/pci/pcie_regs.h @@ -86,6 +86,9 @@ typedef enum PCIExpLinkWidth { #define PCI_ARI_VER 1 #define PCI_ARI_SIZEOF 8 +/* PASID */ +#define PCI_PASID_VER 1 +#define PCI_EXT_CAP_PASID_MAX_WIDTH 20 /* AER */ #define PCI_ERR_VER 2 #define PCI_ERR_SIZEOF 0x48 diff --git a/include/standard-headers/linux/pci_regs.h b/include/standard-headers/linux/pci_regs.h index a39193213f..406dce8e82 100644 --- a/include/standard-headers/linux/pci_regs.h +++ b/include/standard-headers/linux/pci_regs.h @@ -935,6 +935,7 @@ #define PCI_PASID_CAP_EXEC 0x0002 /* Exec permissions Supported */ #define PCI_PASID_CAP_PRIV 0x0004 /* Privilege Mode Supported */ #define PCI_PASID_CAP_WIDTH 0x1f00 +#define PCI_PASID_CAP_WIDTH_SHIFT 8 #define PCI_PASID_CTRL 0x06 /* PASID control register */ #define PCI_PASID_CTRL_ENABLE 0x0001 /* Enable bit */ #define PCI_PASID_CTRL_EXEC 0x0002 /* Exec permissions Enable */