From patchwork Tue Jan 14 20:37:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13939514 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 26BCBC02183 for ; Tue, 14 Jan 2025 20:46:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To: In-Reply-To:References:Message-Id:Content-Transfer-Encoding:Content-Type: Subject:Date:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nIYnl0QMss/E9dnZTRNT1diPgdnd40NFqD7KFzCG44U=; b=oWjJTdpLlwNcxdmT5V7koUX1il uyd/gk8z8KLVIbbSfawrLpdHo3mUhuYDrsujOOVkGJDLmdA7qYdBEA3UCajLMa6tdb/Jq6uBeWO7d STM4jAaX/PFO4uO2Z4ENwfOsEj/2V4CfcyZLews5xxhD/6gSiPYCGU3a9WadHZybhHCH+ZJpBaoU0 oDeoUBkojW0qYbnVQSCxr6VLT3pjHpEH7+S0uFlQtljS9Ri7magk3F75TPQaGBUpucyrD7vIxITyR rl1H45irMRdhLQ0k0W5pE8JX8wFcgMgn6kNsX0xx1WEXkb8yk/rL79ZYPaktvF/R1ltJE+Iv1CfR4 9PU3Iwvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tXnnU-00000009igp-3JDS; Tue, 14 Jan 2025 20:46:00 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tXnfa-00000009hQk-3fja for linux-arm-kernel@bombadil.infradead.org; Tue, 14 Jan 2025 20:37:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=MIME-Version:Cc:To:In-Reply-To: References:Message-Id:Content-Transfer-Encoding:Content-Type:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=nIYnl0QMss/E9dnZTRNT1diPgdnd40NFqD7KFzCG44U=; b=U2Vx1sUgBdwOVjtX0DUUbxy8hC N3mUYtJrJrrZ6F80tMGWU5DNWfgdaBz2G6ArQfBSwIJR11B0zvjInuNZ64slVU1B6KXDWC5azPVmy SvQn6EZzi9xyH42UniKqAoUEl5/tuMGhVOy1MrWbhaU38GYM8SbYwLH263xk24/uRzk4MZL+0iYqI hessX7jK0gwFnUTK0OpHvLVUn2N+dD1EnGV7AAx5y94E5G/NPAQY1rmFa3As+5tGNXK4/fZkbEkU0 ESaRlMU5swa/A4KWAvmpJWEkCUuTPwCax+SM++TZMOJd4LOwyKlXMxGG+lS5o9rzAe9FmndqVHvmP y8zinunw==; Received: from mail-am6eur05on2061c.outbound.protection.outlook.com ([2a01:111:f403:2612::61c] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tXnfW-0000000AcLE-11TI for linux-arm-kernel@lists.infradead.org; Tue, 14 Jan 2025 20:37:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=e+xUg1XLUVYNWCT0eyLciqRCGyO6byLcSTnMiyuE8c+fi8nZOoXFjsPjRNDrC0WtH2ifVRvYYzzAvrj6NBKwN24ww+3NIUWwmtsy1D7DEoj6DzhEuRDZTTq8cRZ8qxKPdHjOia6EdlUBrftAdQb6l6WrurB3lbxv8U8BYKGSJOS20NCtTYaXOc7O20jSL2+h9jnEf5Vn9H8qqeWwds1wHW6W3oGsyzi1Nv67E5v41VzQTrGjywYSwycSOyGZKLS5Ja0VRy4bOxz3AGhPmoQxAaBbm/bPGQUuVTUOq3IVYxVpliNLeSrvd/57x8CsFfgiwM6oyxgCyRQPkw07VJi8Jg== 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=nIYnl0QMss/E9dnZTRNT1diPgdnd40NFqD7KFzCG44U=; b=VEdDKZJMOauir+swUQdOzUZG24E8I614w9Mi9NCUTskRmZ0GnE6QsT0P6y/6IFreTYMIEy5HiJt4rOiTgzmO5IyHQzPmNw1AwHFiKuUFr1zSbPBiOxnoNcEKLP/kAYD5z0V7FRBxkF8T6d34jKdFnJPCwcoUuBM8np+NMToBT7qRuu/MqvenQ0tSDslc64qHNQhuLD7pGVp/F4kA0qhf1E6Z2emLc4pE/TJqpFzjj/F6d0hFbwx1w/8cGFPshBz50dMzkdke5KqCPqpBXn94HxiuZpye67BvjKQvDbKDGkZa4lydGuyFzDi7AUiOHQPA/DthojamPS+GDTz2VbiAnA== 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=nIYnl0QMss/E9dnZTRNT1diPgdnd40NFqD7KFzCG44U=; b=dUJLRRa4mA3Hf3IPq/CoXdKLyeeNxey6X6ZYnyprWYfBqXZoefyHEc8xrneUW3lDD7OBzFBvtug9XV3Xajjw/3vCafzp+2PFNXL+3vC0UWrjMa3eDwr39UvsUacfe10TWinBIn/M331Xrlg92iJoHkvXA6v4yl3CigVX6WnHeqEVqPmJpw1nEtwfA95Arw8Zwdqc8vuxQR6ZoSYpJ9isM2OecAW9GOeM2+ycu7v+XqYPQ7TUwfXkn1kg5bi7XQERO3HpChVLFMuu/4SDh3RaGBGX7v8Tv9Uk8K4soqLwJFF38kzstIuSl8dIhcg3QCTUW5vlcJ1HSMBinspFevzNxg== 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 PA2PR04MB10374.eurprd04.prod.outlook.com (2603:10a6:102:41e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.18; Tue, 14 Jan 2025 20:37:41 +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.8335.017; Tue, 14 Jan 2025 20:37:41 +0000 From: Frank Li Date: Tue, 14 Jan 2025 15:37:09 -0500 Subject: [PATCH v9 2/2] PCI: imx6: Add IOMMU and ITS MSI support for i.MX95 Message-Id: <20250114-imx95_lut-v9-2-39f58dbed03a@nxp.com> References: <20250114-imx95_lut-v9-0-39f58dbed03a@nxp.com> In-Reply-To: <20250114-imx95_lut-v9-0-39f58dbed03a@nxp.com> To: Bjorn Helgaas , Richard Zhu , Lucas Stach , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev, Frank.li@nxp.com, alyssa@rosenzweig.io, bpf@vger.kernel.org, broonie@kernel.org, jgg@ziepe.ca, joro@8bytes.org, l.stach@pengutronix.de, lgirdwood@gmail.com, maz@kernel.org, p.zabel@pengutronix.de, robin.murphy@arm.com, will@kernel.org, Robin Murphy , Marc Zyngier , Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1736887043; l=10863; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=RQX2/sgMFQZpgSFRGn7Mr1SVILSMirf9nBRzmg2vfMg=; b=M8MUuP9CBJD2joro+ohSQe09zb8ZqAEuJgLtzOotlh7fA2HwZrWozDXeN5TuGzfHVC9DJN4rv UxSkLl8WP70CXA+5+39Fij2puzdGur4EzTXXAH1mlao4hKqLIqgfHJW X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY5PR17CA0022.namprd17.prod.outlook.com (2603:10b6:a03:1b8::35) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PA2PR04MB10374:EE_ X-MS-Office365-Filtering-Correlation-Id: e9b5e9c5-d6cd-4713-ac56-08dd34db4afa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|7416014|376014|1800799024|366016|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?H5CCHI+6UG4srkm/ytaCRmZImnR119Q?= =?utf-8?q?p1qfyGfhjenPVeJ+iwboaQYz+hgeWnS/nimwmehf+VS9TsOV1CiTR663shfJfobYq?= =?utf-8?q?x0TNx8QLlOzXLX4X8l1sadDOUyNZ27kaRYZDTkbM/vsftERYVx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Ze2ptZf+KUlS+kR3U?= =?utf-8?q?MWMZCe4kin2kE/mwcE3eLubcUVcBWDcjX1oOFwmynZND0ow4noPNzigUS7Ri1VJ1v?= =?utf-8?q?akwoZserraKoNXrjZUZRPrMKFDVMmykrmeBfgCYzY0iw7iagDYER0mqq63CC/btAo?= =?utf-8?q?dJkipDmJIvXLf9Apf3U/Sj/kvT5cSY9eD7GlLa8CIZDSvgHjJeYsMAK5UeH7fxY3X?= =?utf-8?q?0adsZSQIiztdvo1SQRolbaRgQVkgqfgW2NPIqqz4QbnRdUmPMrUDVKapJpbi5QZmU?= =?utf-8?q?TXW6xWMG3YRYe4fk1eSznkFrNQstYnaqgmEVOoCeh6qjGOBcRGv9l6Lf6CdbYNQkz?= =?utf-8?q?179dGqUWZnbqO+VcX3dz3vpnRuxTeZKQQ8jze9NAtXFPcurWUzEAvjSnBjWebSv0l?= =?utf-8?q?hWc9UdUCfJbWJ5S1KOg+rZFv6F2p1VdiA=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)(52116014)(7416014)(376014)(1800799024)(366016)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Rv6Tzq3GpgT83Q4FiW08CS9wgShz?= =?utf-8?q?QhXqCDELfZJDmoFoTX3/f/9M7BYhnxQXDaa9JeYM0RPIHlSHubd8jZ7eeXh8nqFNV?= =?utf-8?q?W3U8DXpCBOK0KMh3fbHa4pleMovADV3VzdRMslLLZcxOlXvKtviDXsiBtjjSE9ZGb?= =?utf-8?q?eCPdrL/l24dEX2QRJ72adkpvnXLDlwOdd+sFPAEgSltRhpGQtOEWlFYP4KAQjCbAd?= =?utf-8?q?egGoEd1FKZdQ7XEyHfIrkR/VjyEqvv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irODqlxGRV1IZOhZvx0cYR9s/pUQtO8E2xSZUS39CvIC?= =?utf-8?q?ItZOS25ZxS9vUBV/lFGYGx3e5xMczGwXdDLVePrc8XqP0jv70qWa5JpGqGK0G7pBr?= =?utf-8?q?ho9UmPCJR11Zpn8BXnZr4mS+YarDlNRJuszazmT5hFs+58sQ6G2b8y28Wv+hHxy3K?= =?utf-8?q?idPdNiJtmK5yJOV5ozLbLkAkpiILmU7V0ahu/0wvUF34n1wNg3RHnRnbO48wGsvOP?= =?utf-8?q?ZTGc2bk2oBk1mLQAZeH6yRefGjuY4px6OSsy02h25vvZK5Mwvt7WZ+HpEKWFznBtV?= =?utf-8?q?cLgkKpN0o1iTHML0I4lUy1lEaQiRyOSmwP47Zq+66BLaU1zWm/LDki2ZvZdmTdF2d?= =?utf-8?q?PwgpY+mjeYyeH9NBFZ97P4GcjPG4GVsXbr9G2xeMoE4LjoiWyqzpBi5HU3IIolI0Q?= =?utf-8?q?fbZYoED8jqz9?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e9b5e9c5-d6cd-4713-ac56-08dd34db4afa X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jan 2025 20:37:41.7732 (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: RFMKCUzBRKp1urAHD6mGTi6m71Uw+IvLT3xUgdanQYhNFWgajAWZ1A2axHXrZPhbqTNPEMEdLn280eACTBmDQw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA2PR04MB10374 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250114_203746_596859_1CDBBB3E X-CRM114-Status: GOOD ( 23.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org For the i.MX95, configuration of a LUT is necessary to convert Bus Device Function (BDF) to stream IDs, which are utilized by both IOMMU and ITS. This involves checking msi-map and iommu-map device tree properties to ensure consistent mapping of PCI BDF to the same stream IDs. Subsequently, LUT-related registers are configured. If an msi-map isn't detected, platform relies on DWC built-in controller for MSIs that does not need streamdIDs. Register a PCI bus callback function to handle enable_device() and disable_device() operations, setting up the LUT whenever a new PCI device is enabled. Known limitations: - If iommu-map exists in the device tree but the IOMMU controller is disabled, stream IDs are programmed into the LUT. However, if an RID is out of range of the iommu-map, enabling the PCI device fails, although the PCI device can work without the IOMMU. - If msi-map exists in the device tree but the MSI controller is disabled, MSIs will not work. The DWC driver skips initializing the built-in MSI controller, falling back to legacy PCI INTx only. Acked-by: Richard Zhu Signed-off-by: Frank Li --- Chagne from v8 to v9 - update commit message. Rob agree parse msi-map and iommu-map by existed of APIs. https://lore.kernel.org/imx/20250113225905.GA3325507-robh@kernel.org/ - update comments to make logic clear - use if (!err_i) else if (!err_m) Change from v7 to v8 - update comment message according to Lorenzo Pieralisi's suggestion. - rework err target table - improve err==0 && target ==NULL description, use 1:1 map RID to stream ID. - invalidate case -> unexisted case, never happen - sid_i will not do mask, add comments said only MSI glue layer add controller id. - rework iommu map and msi map return value check logic according to Lorenzo Pieralisi's suggestion Change from v5 to v7 - change comment rid to RID - some mini change according to mani's feedback Change from v4 to v5 - rework commt message - add comment for mutex - s/reqid/rid/ - keep only one loop when enable lut - add warning when try to add duplicate rid - Replace hardcode 0xffff with IMX95_PE0_LUT_MASK - Fix some error message Change from v3 to v4 - Check target value at of_map_id(). - of_node_put() for target. - add case for msi-map exist, but rid entry is not exist. Change from v2 to v3 - Use the "target" argument of of_map_id() - Check if rid already in lut table when enable device change from v1 to v2 - set callback to pci_host_bridge instead pci->ops. --- drivers/pci/controller/dwc/pci-imx6.c | 199 +++++++++++++++++++++++++++++++++- 1 file changed, 198 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index c8d5c90aa4d45..bc3f8471d65ab 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -55,6 +55,22 @@ #define IMX95_PE0_GEN_CTRL_3 0x1058 #define IMX95_PCIE_LTSSM_EN BIT(0) +#define IMX95_PE0_LUT_ACSCTRL 0x1008 +#define IMX95_PEO_LUT_RWA BIT(16) +#define IMX95_PE0_LUT_ENLOC GENMASK(4, 0) + +#define IMX95_PE0_LUT_DATA1 0x100c +#define IMX95_PE0_LUT_VLD BIT(31) +#define IMX95_PE0_LUT_DAC_ID GENMASK(10, 8) +#define IMX95_PE0_LUT_STREAM_ID GENMASK(5, 0) + +#define IMX95_PE0_LUT_DATA2 0x1010 +#define IMX95_PE0_LUT_REQID GENMASK(31, 16) +#define IMX95_PE0_LUT_MASK GENMASK(15, 0) + +#define IMX95_SID_MASK GENMASK(5, 0) +#define IMX95_MAX_LUT 32 + #define to_imx_pcie(x) dev_get_drvdata((x)->dev) enum imx_pcie_variants { @@ -87,6 +103,7 @@ enum imx_pcie_variants { * workaround suspend resume on some devices which are affected by this errata. */ #define IMX_PCIE_FLAG_BROKEN_SUSPEND BIT(9) +#define IMX_PCIE_FLAG_HAS_LUT BIT(10) #define imx_check_flag(pci, val) (pci->drvdata->flags & val) @@ -139,6 +156,9 @@ struct imx_pcie { struct device *pd_pcie_phy; struct phy *phy; const struct imx_pcie_drvdata *drvdata; + + /* Ensure that only one device's LUT is configured at any given time */ + struct mutex lock; }; /* Parameters for the waiting for PCIe PHY PLL to lock on i.MX7 */ @@ -930,6 +950,175 @@ static void imx_pcie_stop_link(struct dw_pcie *pci) imx_pcie_ltssm_disable(dev); } +static int imx_pcie_add_lut(struct imx_pcie *imx_pcie, u16 rid, u8 sid) +{ + struct dw_pcie *pci = imx_pcie->pci; + struct device *dev = pci->dev; + u32 data1, data2; + int free = -1; + int i; + + if (sid >= 64) { + dev_err(dev, "Invalid SID for index %d\n", sid); + return -EINVAL; + } + + guard(mutex)(&imx_pcie->lock); + + /* + * Iterate through all LUT entries to check for duplicate RID and + * identify the first available entry. Configure this available entry + * immediately after verification to avoid rescanning it. + */ + for (i = 0; i < IMX95_MAX_LUT; i++) { + regmap_write(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_ACSCTRL, IMX95_PEO_LUT_RWA | i); + regmap_read(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA1, &data1); + + if (!(data1 & IMX95_PE0_LUT_VLD)) { + if (free < 0) + free = i; + continue; + } + + regmap_read(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA2, &data2); + + /* Do not add duplicate RID */ + if (rid == FIELD_GET(IMX95_PE0_LUT_REQID, data2)) { + dev_warn(dev, "Existing LUT entry available for RID (%d)", rid); + return 0; + } + } + + if (free < 0) { + dev_err(dev, "LUT entry is not available\n"); + return -ENOSPC; + } + + data1 = FIELD_PREP(IMX95_PE0_LUT_DAC_ID, 0); + data1 |= FIELD_PREP(IMX95_PE0_LUT_STREAM_ID, sid); + data1 |= IMX95_PE0_LUT_VLD; + regmap_write(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA1, data1); + + data2 = IMX95_PE0_LUT_MASK; /* Match all bits of RID */ + data2 |= FIELD_PREP(IMX95_PE0_LUT_REQID, rid); + regmap_write(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA2, data2); + + regmap_write(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_ACSCTRL, free); + + return 0; +} + +static void imx_pcie_remove_lut(struct imx_pcie *imx_pcie, u16 rid) +{ + u32 data2; + int i; + + guard(mutex)(&imx_pcie->lock); + + for (i = 0; i < IMX95_MAX_LUT; i++) { + regmap_write(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_ACSCTRL, IMX95_PEO_LUT_RWA | i); + regmap_read(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA2, &data2); + if (FIELD_GET(IMX95_PE0_LUT_REQID, data2) == rid) { + regmap_write(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA1, 0); + regmap_write(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA2, 0); + regmap_write(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_ACSCTRL, i); + + break; + } + } +} + +static int imx_pcie_enable_device(struct pci_host_bridge *bridge, struct pci_dev *pdev) +{ + struct imx_pcie *imx_pcie = to_imx_pcie(to_dw_pcie_from_pp(bridge->sysdata)); + u32 sid_i, sid_m, rid = pci_dev_id(pdev); + struct device_node *target; + struct device *dev; + int err_i, err_m; + u32 sid; + + dev = imx_pcie->pci->dev; + + target = NULL; + err_i = of_map_id(dev->of_node, rid, "iommu-map", "iommu-map-mask", &target, &sid_i); + if (target) { + of_node_put(target); + } else { + /* + * "target == NULL && err_i == 0" means RID out of map range. + * Use 1:1 map RID to stream ID. Hardware can't support this + * because stream ID only 6 bits + */ + err_i = -EINVAL; + } + + target = NULL; + err_m = of_map_id(dev->of_node, rid, "msi-map", "msi-map-mask", &target, &sid_m); + + /* + * err_m target + * 0 NULL RID out of range. Use 1:1 map RID to + * stream ID, Current hardware can't + * support it, so return -EINVAL. + * != 0 NULL msi-map does not exist, use built-in MSI. + * 0 != NULL Get correct streamID from RID. + * != 0 != NULL Invalid combination. + */ + if (!err_m && !target) + return -EINVAL; + else if (target) + of_node_put(target); /* Find stream ID map entry for RID in msi-map */ + + /* + * msi-map iommu-map + * N N DWC MSI Ctrl + * Y Y ITS + SMMU, require the same sid + * Y N ITS + * N Y DWC MSI Ctrl + SMMU + */ + if (err_i && err_m) + return 0; + + if (!err_i && !err_m) { + /* + * Glue Layer + * <==========> + * ┌─────┐ ┌──────────┐ + * │ LUT │ 6bit stream ID │ │ + * │ │─────────────────►│ MSI │ + * └─────┘ 2bit ctrl ID │ │ + * ┌───────────►│ │ + * (i.MX95) │ │ │ + * 00 PCIe0 │ │ │ + * 01 ENETC │ │ │ + * 10 PCIe1 │ │ │ + * │ └──────────┘ + * MSI glue layer auto add 2 bits controller ID ahead of stream + * ID, so mask this 2bits to get stream ID. And IOMMU glue + * layer doesn't do that. + */ + if (sid_i != (sid_m & IMX95_SID_MASK)) { + dev_err(dev, "iommu-map and msi-map entries mismatch!\n"); + return -EINVAL; + } + } + + if (!err_i) + sid = sid_i; + else if (!err_m) + sid = sid_m & IMX95_SID_MASK; + + return imx_pcie_add_lut(imx_pcie, rid, sid); +} + +static void imx_pcie_disable_device(struct pci_host_bridge *bridge, struct pci_dev *pdev) +{ + struct imx_pcie *imx_pcie; + + imx_pcie = to_imx_pcie(to_dw_pcie_from_pp(bridge->sysdata)); + imx_pcie_remove_lut(imx_pcie, pci_dev_id(pdev)); +} + static int imx_pcie_host_init(struct dw_pcie_rp *pp) { struct dw_pcie *pci = to_dw_pcie_from_pp(pp); @@ -946,6 +1135,11 @@ static int imx_pcie_host_init(struct dw_pcie_rp *pp) } } + if (pp->bridge && imx_check_flag(imx_pcie, IMX_PCIE_FLAG_HAS_LUT)) { + pp->bridge->enable_device = imx_pcie_enable_device; + pp->bridge->disable_device = imx_pcie_disable_device; + } + imx_pcie_assert_core_reset(imx_pcie); if (imx_pcie->drvdata->init_phy) @@ -1330,6 +1524,8 @@ static int imx_pcie_probe(struct platform_device *pdev) imx_pcie->pci = pci; imx_pcie->drvdata = of_device_get_match_data(dev); + mutex_init(&imx_pcie->lock); + /* Find the PHY if one is defined, only imx7d uses it */ np = of_parse_phandle(node, "fsl,imx7d-pcie-phy", 0); if (np) { @@ -1627,7 +1823,8 @@ static const struct imx_pcie_drvdata drvdata[] = { }, [IMX95] = { .variant = IMX95, - .flags = IMX_PCIE_FLAG_HAS_SERDES, + .flags = IMX_PCIE_FLAG_HAS_SERDES | + IMX_PCIE_FLAG_HAS_LUT, .clk_names = imx8mq_clks, .clks_cnt = ARRAY_SIZE(imx8mq_clks), .ltssm_off = IMX95_PE0_GEN_CTRL_3,