From patchwork Wed Dec 18 23:08:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13914238 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2082.outbound.protection.outlook.com [40.107.22.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D1D41FDE26; Wed, 18 Dec 2024 23:09:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563373; cv=fail; b=a6Ur655h4kbs1pQiXrniShJNYnm55Ea89LEbnFsueGtOfGHA8jxXKsRczLoFr3dgVLU615EfHxqgh6OM3FM/CguX/W2uDBd/Yt4KDBLqnSQrg6Olz5TSls+Pgy9BZRCrsC0f6X+y5c7kaeD3XWvSgExjDogEvYdQKAWbZlVCJPo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563373; c=relaxed/simple; bh=cLEkpOzWDRZk+G7yo89vdyDGtgAmLrqYZZa7SH+fYhc=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=hu00kSBjBzWOHJK/39jGVtk1fEFGmmoWqcMz5TnWiZOMXeWqkQhJNewGDltG5a6HS2Vu0JuwRrbMfkNuUsp0a9l5Za5jB5n6P2DfkghVCftewIs0qw6wOccPXXknSpT4b/ggat0G3+VNt9gSYEJ0tg/b1Ll8XYQ8B0bpY4kE7Po= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=AawwPuAp; arc=fail smtp.client-ip=40.107.22.82 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="AawwPuAp" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vaYdJ2wLjmmJV3xWTQ8LC8cMRSHIDOjOHgQ5HlkQe+zW3kDlIxQJFsLKwWI8PrMea9n8zz3H3twsXrlNkRB3IxwrTBIg6oFZM8GjsfR18P6PYqVHA71FB3QKs/TqFZw7khg3kXUmxNuReMTQtKoQCE0HswuFxz/2OC6s5orWwUktSWxeC8lHawd4dUjFbtfZZdtJtY2uSSxXe3ks0RVmYOk+28YLfChK4mfkhyX70C7/hwGfx7NBtGST7y62QpKwd4rV9OGNeo41696qfALSZWny/E/0kHgLfat3/c5MFHWWDetzWC+c0FxOgj9gSHJOaVkDe4E6Xno102kw85mmYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=UUqKjyu4iesfDGdWp0mMyRh8NSm81pkKsC7XKJ0FTec=; b=UURrI0chQfJArJL1IErtC8IbdXJ3c7wMvSP2wlLlw/Q/D29QTpxUpN02SanAbT59wf4O9CRCjOfyTEIXrtQlLVHBXRN/a1OyoCIL/keIPxrsDb/U/E3QIwhvDOudv3b89OVG0HEZ7d9s1E6J3FGrzTnRhAB5n3xDQak+URGwsKZ2UZmX8BAtE9qQLEc2o4oZZJK0IJSqJ255YsTi6uKYJsXnRdMX82Irf6X/fg6JfHZLXgCKD94R6DCOIYt0ezMIZaab6zGbSvhbrinwjWWI4psovysClr+j9lzB4+0Cd8RUopHzO3+9S9b/Acqb96gIlvRmJKbmc9Wm3xy0OzOCdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UUqKjyu4iesfDGdWp0mMyRh8NSm81pkKsC7XKJ0FTec=; b=AawwPuApiA6uOnkKJqWoVxQ8cHqw23si70805NWj1NBOd2CvyfMbki2liJflVOjpCYXPSytBYfpHc9UifOrl9oiAVKHaq0stRlDteSqM6liOcdJ9lgGJC830EEgiGtfyaSqEryVOvGg3rsUAUsaNJRByDw2GwTBVBvg1CRCJR2TOPdnqPlxiMMBoCa6osaiZ/z3CvkpjnOXiOxXmaOFrh63HAXuww3s+wNXn70vb7rbK5XOiYCTh64zUKEQibypoYxbzAyjLt80ToZaAnqHyzP9s/sYsmHHg2oXdebvex0J9R7YeG4PYCBnu9P+vP731VP2midcj7GztDwxjwj9vEA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by DB9PR04MB9939.eurprd04.prod.outlook.com (2603:10a6:10:4c4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.22; Wed, 18 Dec 2024 23:09:30 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.8272.005; Wed, 18 Dec 2024 23:09:29 +0000 From: Frank Li Date: Wed, 18 Dec 2024 18:08:41 -0500 Subject: [PATCH v13 6/9] PCI: endpoint: Add pci_epf_align_inbound_addr() helper for address alignment Message-Id: <20241218-ep-msi-v13-6-646e2192dc24@nxp.com> References: <20241218-ep-msi-v13-0-646e2192dc24@nxp.com> In-Reply-To: <20241218-ep-msi-v13-0-646e2192dc24@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman , "Rafael J. Wysocki" , Thomas Gleixner , Anup Patel , Marc Zyngier Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, jdmason@kudzu.us, linux-arm-kernel@lists.infradead.org, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1734563338; l=3395; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=cLEkpOzWDRZk+G7yo89vdyDGtgAmLrqYZZa7SH+fYhc=; b=C39v0uNfyK10Ox21VMlwGjoNNXDHIVqO9nFn6qXIlEJ4FhDDAx0w1lHOIx1kZDrH0K0e+RvDW Tdt4ZQexwqeBMGreNN3l86QwaiI06sPW+ihlXrc3oc3ZsXyXezkdsCb X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0075.namprd13.prod.outlook.com (2603:10b6:a03:2c4::20) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|DB9PR04MB9939:EE_ X-MS-Office365-Filtering-Correlation-Id: 966937db-8ef7-4e65-38a1-08dd1fb906b9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016|52116014|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?SabVmRtc9TNeKlR+MjsBLrEBqaSaBqk?= =?utf-8?q?GaDuYmjy8TXIpF631rMPTHSpMcLnQBMpxPMB3mFCf6xcIG+8irqX3aOokFNJd37hQ?= =?utf-8?q?BAlQQ0tw6p72LYyawI0ArG9EV7a/hs8vw/YiCvD3Xsh2rOCImJpYf9iqG+DOWQx8i?= =?utf-8?q?iMycQm2kkRV4CK1+PrIkI7aHwQkPmff7tzI0TVj18M7NHIqpbzwtjeqkgPjpTHEi4?= =?utf-8?q?jdfgrknijqIn2csLV6i4MOCWGE2ainJU/vyhyfvdh63m7MSgU8V96FXAKdE7BDQLm?= =?utf-8?q?Kt6NOnEq2j5FOax+D4VZpZNrMpbGurM7q8m8EeJZjN/cKyKgQXHsti4zZ0MrmpUJL?= =?utf-8?q?fzpnwFNmS/+EEJeSyrl/PqolSIu4jIgqQ/uuZBh1J8VTjBDnsyO9WepCg93frMkmu?= =?utf-8?q?2vxMUu9rSJPsDXwdMXo67z+cuLsz+ZPScb6z9SZsWn/EVPCy0OFkIZFi8CrAj/1z6?= =?utf-8?q?yEvoSNy1DDDaaCh039NQfCkYinydPZkz/+jErzOmghqaIrGxDp3mKhO4mVcvgHNuP?= =?utf-8?q?j1PU/MZFgfjAvu8ic8Ti8amJ9ZHmRiWoxNHmcjRIWbOvaO5mWbuaqNhiAUQ5KwhR9?= =?utf-8?q?t8CQDqpc9PzJNx403i8cxUGzv0e/BvBhKPRrx1t4ypZbqGWnN+8tK+9Yodqqpd0AN?= =?utf-8?q?zHhGjxsvvkArAj08anm9CxaZkI/Grwo36kmuvI3C/L22WvLQoMrQcv1eCbAMXRNnX?= =?utf-8?q?RmRet2vZHhGkFM75J2O+ZGTpaEXuhgxec79x74kdrckFAMyfaaQPv08ivTmSNNgbu?= =?utf-8?q?IdFYGtQPWA8mLpJQmyeq5/tb8lk58dfqKDMzpxLi8beJCgGWausVbs5lIByozpquX?= =?utf-8?q?91v7lAGbJad4Yv22eK/jVKs2DOrIaz0MZJVVsgTMUS2nzJOnt9GVaQSL/mXjqZJN9?= =?utf-8?q?CUmUMg970q42cAWl8jMmPTXTDCpD90FnQNPaUFMrf2Kxu5WB8TmbgsxueAWmM0osF?= =?utf-8?q?z8VWZ/Ad3rmcTrW75ReK+9LURf0ZSxfzx8ulyl4LbAIs2vQ/B50KTAiPf34kPgW32?= =?utf-8?q?BolNj2EFp5aj/pGNGjtQpLdHnf8pbE6dYE/gIDDvKU0YpiGvx5ZXfaQGnPUxM56ra?= =?utf-8?q?CbtBDehoB0rmgi1bsP7KhiGY70F/w7cp9mItcC21vx7N6FL2CQmHSwYyCFlJAIHZL?= =?utf-8?q?BYIoiz565xwDf8ySmRM8o1DJPLJmI1DGak0hBDV1kK17pCvlCeivzFLigreKmfhDK?= =?utf-8?q?PX84digDD7SH6Sbp549f8Ey8oc7Fma9TMXvJzuxxjgyk8daOpfq6ijTofMuKkkWob?= =?utf-8?q?vkwxW0DF0xVNvb0VUWLkoDMlvum3xJuOkvgqxAPBQSHhFvzNPuAekHIFt0nqyMqwx?= =?utf-8?q?Hp3p2lAoGx+AVR0DoNfJkWOWmstDL4pg9uEp/mIVRXnNahz8mc78/fdqOLiuvzFjV?= =?utf-8?q?pN5ftNFPyGgWZU1g6km4VQsrdKugWYwIA=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(366016)(52116014)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?tuF062KE48P5P/FKQFjuHgTijbUJ?= =?utf-8?q?lZzXq518tjwRTCdYs2nQn6tPRlKaWkhR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YnTW00SswJzcgyMQ2RPyRl9pNIinv8lr?= =?utf-8?q?7qoD+wYlk25z1NqaC1H74bjYupKGOua/q4nTzr1dHZ0vcX/CdEBGdDAObJYebESqA?= =?utf-8?q?jokESzjIMXFMLHl3s7Pe29kT/6l9Mvvpr1mnCQTKgFUl1pJ2DInTHIoxs7Vs2QuIg?= =?utf-8?q?tn7sEBJzAEZShypsQLH5IhfClkk8GQkT/BaODNbbDV2pnfDu6ARQ9dzWcGQfOSg+j?= =?utf-8?q?q6Qa427kWIh42uADwj9bmLucihVO303yhpGHAtk+QLSOmnRyPzuC6uLQlMLO2r4E3?= =?utf-8?q?4R8rB42GIqxcz5UdC8GE5IHntx3chVkZG3x8LHGsUqtyMDeV0kQJFzQoC4kGnr045?= =?utf-8?q?D1kzzBa0bsPQ1LaYUoKCC8TZmrA+1t+M78E2+6vd6MoRVInLCvki0kXuLVS/jU1AH?= =?utf-8?q?5wWYNXiEDukWEvksVLj9/GpC4IuM0o1Q+d+gvS/JxyOo59HYmHsbzWn6xjgDCyf9J?= =?utf-8?q?ElU4b77g/YLwMrA9fL0KK6tCYHtqXq+9ntSn75PvPyRMMr6jmWpmUvc8SzoGirbU+?= =?utf-8?q?cnZo3m9EisKOtuDAz4gRahkrtwZxSVudPajKtWKMfVigF90ILZGc8Gp7HEyY7lA59?= =?utf-8?q?oLMqwQmd3W7c?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 966937db-8ef7-4e65-38a1-08dd1fb906b9 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Dec 2024 23:09:29.9448 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: pNFM1dkWl2D1MGuJKqPtZTtWgtPbH5IosXzkz4hAfm8HN7kmhSVRRPLMC/3eXZh/GGewrvPTUUFI/3tew6dzTA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9939 Introduce the helper function pci_epf_align_inbound_addr() to adjust addresses according to PCI BAR alignment requirements, converting addresses into base and offset values. Signed-off-by: Frank Li --- Change form v9 to v13 - none change from v8 to v9 - pci_epf_align_inbound_addr(), base and off must be not NULL - rm pci_epf_align_inbound_addr_lo_hi() change from v7 to v8 - change name to pci_epf_align_inbound_addr() - update comment said only need for memory, which not allocated by pci_epf_alloc_space(). change from v6 to v7 - new patch --- drivers/pci/endpoint/pci-epf-core.c | 44 +++++++++++++++++++++++++++++++++++++ include/linux/pci-epf.h | 3 +++ 2 files changed, 47 insertions(+) diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index 8fa2797d4169a..d7a80f9c1e661 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -464,6 +464,50 @@ struct pci_epf *pci_epf_create(const char *name) } EXPORT_SYMBOL_GPL(pci_epf_create); +/** + * pci_epf_align_inbound_addr() - Get base address and offset that match BAR's + * alignment requirement + * @epf: the EPF device + * @addr: the address of the memory + * @bar: the BAR number corresponding to map addr + * @base: return base address, which match BAR's alignment requirement. + * @off: return offset. + * + * Helper function to convert input 'addr' to base and offset, which match + * BAR's alignment requirement. + * + * The pci_epf_alloc_space() function already accounts for alignment. This is + * primarily intended for use with other memory regions not allocated by + * pci_epf_alloc_space(), such as peripheral register spaces or the trigger + * address for a platform MSI controller. + */ +int pci_epf_align_inbound_addr(struct pci_epf *epf, enum pci_barno bar, + u64 addr, u64 *base, size_t *off) +{ + const struct pci_epc_features *epc_features; + u64 align; + + if (!base || !off) + return -EINVAL; + + epc_features = pci_epc_get_features(epf->epc, epf->func_no, epf->vfunc_no); + if (!epc_features) { + dev_err(&epf->dev, "epc_features not implemented\n"); + return -EOPNOTSUPP; + } + + align = epc_features->align; + align = align ? align : 128; + if (epc_features->bar[bar].type == BAR_FIXED) + align = max(epc_features->bar[bar].fixed_size, align); + + *base = round_down(addr, align); + *off = addr & (align - 1); + + return 0; +} +EXPORT_SYMBOL_GPL(pci_epf_align_inbound_addr); + static void pci_epf_dev_release(struct device *dev) { struct pci_epf *epf = to_pci_epf(dev); diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index 5374e6515ffa0..2847d195433bf 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -238,6 +238,9 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar, enum pci_epc_interface_type type); void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar, enum pci_epc_interface_type type); + +int pci_epf_align_inbound_addr(struct pci_epf *epf, enum pci_barno bar, + u64 addr, u64 *base, size_t *off); int pci_epf_bind(struct pci_epf *epf); void pci_epf_unbind(struct pci_epf *epf); int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf);