From patchwork Mon Sep 30 19:42:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13816904 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013071.outbound.protection.outlook.com [52.101.67.71]) (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 9362619ABBF; Mon, 30 Sep 2024 19:43:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727725383; cv=fail; b=EgA6zcoe5dA1zqsIl5fSjqUgOPTSuJx3kBIn1O0T4Cwr+hAuN3b3RDEHtSN126lKYM5DStk3fiRP5HFbZ2tKjRdTrvcoTOQVbqWPXwQS5bByCWzxLiH/O6VpDexiM8QEzsGQCiyN53Eb0NrqltxS9bPUTgZL89MqG9WcIWPoAZw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727725383; c=relaxed/simple; bh=/ow1flkLRne6EE1Hp9S1E0GszHPqqrka8qrwUMZ+km8=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=VU7T8zNiPpJKRWcqcK5RxPQhurDRNH453sTq2iJA7EceL6h2vBxmW8FS1nzd0Lv3/Oydb7/1LLJ5MBnaV3lelTgCaE4E4GuUDR4YVScjNHBKyn8XLwtA9DqWmokYEF3u8Qckd5BDOglHy+rTKqEjdkobklmVY8Lumjl34QrbWzg= 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=D7kd6oN6; arc=fail smtp.client-ip=52.101.67.71 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="D7kd6oN6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BDY6YFpILIFHcH5WJvQPh1VkOZC2g03vLjYUtDgukDCubFmrdK683Cv9BHJjxVFSyG1H9IUDFG2RV/wiZJ7zIAaVQsp1AU4Jn7mCyVzt8ANoSwcGGiRnadG2/mWRH6T1jVu4Ch/jN40k/vkdQOtrWhWSo0LfwdBzFfjRVTKg6aAXJTPC5WSrBTBiNUj9bfrYQreRctF9cI49ycMLnLeBK24V6y1GkDgjYMocey/7BhPeQPzMZkvgrao8Iee0ToYsXhrhrXfOBBFSU14HCWYnVnjF08f5RlNp1rhqgViiQh7u070Od78U6kG/icdA48GelB7Mv5EX+G/PQOXpCXgt1A== 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=QmfZ4SDUA4oFkthjzUWy3zBEbHAEc0AvX7E1l1sa70U=; b=hdmuVSZAa9coYj3pmGDW23O6oc4qenbrgCAl9qxtZnvI/XyEYnUgbCAOyT93zg/1vWjW7F80L783X2qm3YwkBsENckfrRFwAR4mKpQg0ACZMHZuDi9XYkryyWDpaUKiVKJuwSyxHyy6MJH0+eQQ5SLKCNCPa2E6qDe0F9B9BHYh1KIplHpnKWzkHjp2/F+kcrRbuQfKFuupZdjicYQM54o/wPxfyZh9N1oriBJp2xSY0eVjRfWArFNaWMtHAa67PukU7tyxfcLahfJhEHXtBHLhz6ryIz0YYMkJkC8hIFcqxAFl81pBFxHfrlVs+0AMeL+URNq6B96KO4NevvEP51w== 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=QmfZ4SDUA4oFkthjzUWy3zBEbHAEc0AvX7E1l1sa70U=; b=D7kd6oN6mDITqUkdssCFrtlWcCDlrh7+bMuzJ7jbOfivN8CJBmOt+QYngMVUv4ClF3vcbET43+k1MKI+MVYJhisoFUV2Qeoou2FwkupJTUyKGCjJ8dJ+j5aOeZmegPT7NaESNYSF84jJKFC6ZDYbv7TVwaUh5V3XiGsfskDg2epkT3bgVUrnTSXPIOaLBj/sUtMUPbd+IBraWWr8JkDPrtfbatQ3S/JBeb/a7mIacOgb92FkSarn+/zFmA/7AetLhImaLVt4i5H3PI9+GqPpUQlHwKNv1R1o8WaVZuYNsQVW7ugb/+/pJAH3fXBdhm+oWkRVg+K6PznTYEiIb9o3hQ== 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 AM7PR04MB6806.eurprd04.prod.outlook.com (2603:10a6:20b:103::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.26; Mon, 30 Sep 2024 19:42:59 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8005.024; Mon, 30 Sep 2024 19:42:59 +0000 From: Frank Li Date: Mon, 30 Sep 2024 15:42:22 -0400 Subject: [PATCH v2 2/2] PCI: imx6: Add IOMMU and ITS MSI support for i.MX95 Message-Id: <20240930-imx95_lut-v2-2-3b6467ba539a@nxp.com> References: <20240930-imx95_lut-v2-0-3b6467ba539a@nxp.com> In-Reply-To: <20240930-imx95_lut-v2-0-3b6467ba539a@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, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1727725360; l=6499; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=/ow1flkLRne6EE1Hp9S1E0GszHPqqrka8qrwUMZ+km8=; b=VSHAB168heyaN9gExA3KwUUhlDKS+QsVzhS7sU5Awy37yr2hsoIuZAjXUcsNOsf6MoeyuCeaK kMK+jzIySY9CdCwrvBjAaMcMs6nqR62wt7zhlYPGtHXIqVOtT25oYVD X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY3PR05CA0004.namprd05.prod.outlook.com (2603:10b6:a03:254::9) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AM7PR04MB6806:EE_ X-MS-Office365-Filtering-Correlation-Id: 7864536c-2eb8-46ee-975d-08dce188167e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016|52116014|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?QjsvDeuwLNqHv0P0xUyQylS4oJSK49j?= =?utf-8?q?UO6Ivn31CagwsfCyTXov+9nqXch8c2j3/9Leg3J4vVr4OOPWoeiDcKgig0ZPJX8xi?= =?utf-8?q?L5X3VhG6t3RCtmhpI97aP7G2CXk4TRmT6vGA7P41OuWStYmcQvTNB4TD2M7yXc/CG?= =?utf-8?q?thlX8e6H84m+sobl33mB8cGVy+9pdmRPUPDiGjtTqWUUIvXhTRMB8j/Wqy4vH8Ail?= =?utf-8?q?SkpdowRe9mMOn86t2NKX94imEnlfdnsZGxDO3Mp7IpkJGJRMOXQ/MC2K69yF7uo2M?= =?utf-8?q?iIQDEULkjLPpVAeVJhXC8w3cj/UUx2wOMGFzxTDYAw7F7qPhUj5Rl3jEUS5jeCVRR?= =?utf-8?q?xTJwla9JvqaFj2yJaf+fUSjyNZ6hgqGK/XH+agi079IYN13YU0ywrm8qcdfZAU0kZ?= =?utf-8?q?GQhtV7LST7XY2yGio6RajMKvGqOOrAbFY0uDd9ebprZS2AgXMfoc9gyx9UDhavr4l?= =?utf-8?q?cI6xWZeWwCvQod1OQiq6+cRLEf6pNmVWyQoL1vPRmDNlNnvG540t2+dUg89ttXC3x?= =?utf-8?q?ImK2n8Pt2AfqMwkTztoE1xETCDdw/8QZfw1hH0gdfZbt2NDybUBqZxyPCZMJVmCxd?= =?utf-8?q?LwVzN1vkcXwGhxKvWZp36IA6IYH3ifJVqKavba3SODJMtaJenkjDyIN+1DC3mPzmN?= =?utf-8?q?mhHU+PaIcrUWkL4I9oRu76bUBWUmaaKHSspGXYbQ1HFz94YkovY8WN2V2qg1c/c7G?= =?utf-8?q?4ijLSIUXpg+xiSqMa9FX+djU9xtm83cDjTpEue/EgGQhhfC5OolQgMt1azh1Y0qhw?= =?utf-8?q?TjZAOH8AJTVng/MEROZYX6JwaKcl7EfKovhIfhGd3wk3GrIPa7lY/kjlqTZlcBwU0?= =?utf-8?q?OTtge2FVwYx2N17OsNyayQfSyINwD83IC78jvzYO6IhX/AWVM2igBH5XjEc3m0oKq?= =?utf-8?q?n3NJGNG69PG8NDvt/ZmIJzuspjnJ1Zc23pur4wwhj1Kz/GzEy/hsf7/VwGa2tlkCG?= =?utf-8?q?9rwC1vP/1jOnHokFsRNocQTSTpQl+GlP3fffDeXfbs5i2XKW13RM9lpDgRXXAebWW?= =?utf-8?q?InI0xArfok13DdMJEZDUtemGcKZjQa+++qEwXfNotkV/oqoduNEF+t6VT1tInFY3f?= =?utf-8?q?LY2h1BtJaWDVHQXDWbSMPxt9GNNIZp7otdEi+PTdODJhAP52MsGLvipoeftcZy3am?= =?utf-8?q?CFJTl5ZdwMmidW0W3PxB9UDE5qzeYytG3140JYJ4Ae9ZttgfPX39aawbCFNXFlvUT?= =?utf-8?q?UXTqTT2AOk6a+b4UKJUgdXHjXZ8YJ7Fr/jsx1tVuFUvP2bxBtkdNoD3eP8t/mexvF?= =?utf-8?q?xZ64OCHtL2fKSEH8J+xOfErCAxq1SrVfowg4838h21Qj++YSzq4LZgvE=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)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?jFX9qOByxinH33ncN7fImwUY4CS9?= =?utf-8?q?WhBfcTiosJt7nu6rBunBVrxgiQ4zCqUHyIDENIDWiwnESE8lEJj5kFZnR6sfHn6Oo?= =?utf-8?q?36zOsuzv5F2vq4T7z8CQs3qT7jzna6+62HjPfvaAPUmsQ0uHIRxZYtyTweiJtqnBa?= =?utf-8?q?81hukJ8C20gyVyel7Nk3VOOcIao0bfcogjK0rcSZvmq5WL8F6I0O1/l5lQzlA+TJX?= =?utf-8?q?yCUB84MtfnZLT58sKsHwBvcRWQddbWhRKuvteWAiPPKMldrj2D5EuRGrhnEpis5Ge?= =?utf-8?q?dwJjB7cVs1s2/IGCiSi+s3UYYqi7OG4XB0YlHWnkGjjmYq3DIfp6BiPZpnO138xL/?= =?utf-8?q?N3Nthl+ZZjVwM++cI3WSL6hfezQ8MwevuHvvOma9m/3Pr6m57xs+jtvlnBjV1VYEc?= =?utf-8?q?Ne4XxVh8cpu5hE+4zZMBlOqx+pffcI7XtIl4VOIvvhc22xaF6/ELb9zr5otEU0BSH?= =?utf-8?q?k/JrzL13AgEReR6jtMsX6DYlbbt7o2XlbVk5MtXDn5qI9YUSDpzNfZ9+dT7fsTTXs?= =?utf-8?q?r7maEFxa0jmpacebZ0LnI5ZASCQZPaTgF0zFgaRdHRKVOLXh+3f/5HD3lm9YvmOYY?= =?utf-8?q?Q5Hj1f5spkAcVGzxJUCQFg9o1ycpmXZ9NrICrADMfzQKAwBw07YxK/yde4/OSQeTw?= =?utf-8?q?unGsFIl1iQJMN6qXY7PZo9MN69jSomSOz1kTUpuhRqWbGg+St5yDFmmootncUfhOB?= =?utf-8?q?NgEsUK0/Cf1nuJGk1ueHIdCTL5XU/VYwCnVK/hWVkEnFGilFrkSYVy+vP1PL8waon?= =?utf-8?q?eoo9X/gVbeWagb+EXAOooyCqUTGvQtUylc4NZXPjzujvlkfMiH2uPgWfxNCJzMaG/?= =?utf-8?q?v3kvNAFr6sqKqUIhfex+u1OfAX1v2eroI7f9esKuOsZOCWe3TdYyJv4QN4V4SNfXT?= =?utf-8?q?EBds3n3miqPfNdWgCfXyLN8J+L5uN/d6SJ3nVoZH9ZWuhnH49fSiO1crFrs+VUZRm?= =?utf-8?q?NaA3CDahuj33SPPo21nKNKdN0haJBxy2N2KeHmGmE8tt4i3EWI672GLrRZ7q/SqnC?= =?utf-8?q?CMtnjGLt972M5x9Lr29fHdC5vfNrN2v0dJaF3tqVU3dfVLyJhgrbAul9mAOJ48I9b?= =?utf-8?q?XvsqeD7nHuXhAta8MvPsww6fp2qjZEYzT+J3plhcOio9QQRALmaWLYtVPHRj7hWy+?= =?utf-8?q?8WvpV6H0gTe4BEUu29b/Vh6Wwc2Xpo91JntjmgY13lIZVEBQRPUeiW+eBGt3fD7kl?= =?utf-8?q?BHlS+mQtLGa+OOQEo+qo4yUTwSzPA2tid4S0UHA1qPeuMKxWayhmaom8zqziWKjky?= =?utf-8?q?ObUIvNX2XtLMOMPZO4DI2/9SUGOqSb+S1aXyjmLrH+EXPCF7x0VahTzZqHByoUsc/?= =?utf-8?q?DvhZk/aqjoj4d+0ApFv/1uhERyzqhKdeusdIHRJPnl6SPq7NBboNQgm6uB4751LcK?= =?utf-8?q?ewnBJcfEJHIGc7mKNglXXrt8h4X45Ic90evd0I/4FEHCGDD2TzgevsVsI6gqJr+/f?= =?utf-8?q?XRwz42jNQ0W/w2vHbMEH00ECpPt/sigOIu7OQQYSzX28T5PoE//DBTRM=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7864536c-2eb8-46ee-975d-08dce188167e X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2024 19:42:58.9980 (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: 5j4MJN7KwPstC6C6ZeBBrC8jqf34aKs3w7N4xfCaDobkBOpgfNgZjZmpdP8aT1L69He4E8CvU3LcUDpaOxY/9g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB6806 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 examining the msi-map and smmu-map to ensure consistent mapping of PCI BDF to the same stream IDs. Subsequently, LUT-related registers are configured. In the absence of an msi-map, the built-in MSI controller is utilized as a fallback. Additionally, register a PCI bus callback function enable_device() and disable_device() to config LUT when enable a new PCI device. Signed-off-by: Frank Li --- change from v1 to v2 - set callback to pci_host_bridge instead pci->ops. --- drivers/pci/controller/dwc/pci-imx6.c | 133 +++++++++++++++++++++++++++++++++- 1 file changed, 132 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index 94f3411352bf0..29186058ba256 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 { @@ -82,6 +98,7 @@ enum imx_pcie_variants { #define IMX_PCIE_FLAG_HAS_PHY_RESET BIT(5) #define IMX_PCIE_FLAG_HAS_SERDES BIT(6) #define IMX_PCIE_FLAG_SUPPORT_64BIT BIT(7) +#define IMX_PCIE_FLAG_HAS_LUT BIT(8) #define imx_check_flag(pci, val) (pci->drvdata->flags & val) @@ -134,6 +151,7 @@ struct imx_pcie { struct device *pd_pcie_phy; struct phy *phy; const struct imx_pcie_drvdata *drvdata; + struct mutex lock; }; /* Parameters for the waiting for PCIe PHY PLL to lock on i.MX7 */ @@ -925,6 +943,111 @@ 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 reqid, u8 sid) +{ + struct dw_pcie *pci = imx_pcie->pci; + struct device *dev = pci->dev; + u32 data1, data2; + int i; + + if (sid >= 64) { + dev_err(dev, "Invalid SID for index %d\n", sid); + return -EINVAL; + } + + 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_DATA1, &data1); + if (data1 & IMX95_PE0_LUT_VLD) + continue; + + 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 = 0xffff; + data2 |= FIELD_PREP(IMX95_PE0_LUT_REQID, reqid); + + regmap_write(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA2, data2); + + regmap_write(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_ACSCTRL, i); + + return 0; + } + + dev_err(dev, "All lut already used\n"); + return -EINVAL; +} + +static void imx_pcie_remove_lut(struct imx_pcie *imx_pcie, u16 reqid) +{ + u32 data2 = 0; + 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) == reqid) { + 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); + } + } +} + +static int imx_pcie_enable_device(struct pci_host_bridge *bridge, struct pci_dev *pdev) +{ + u32 sid_i = 0, sid_m = 0, rid = pci_dev_id(pdev); + struct imx_pcie *imx_pcie; + struct device *dev; + int err; + + imx_pcie = to_imx_pcie(to_dw_pcie_from_pp(bridge->sysdata)); + dev = imx_pcie->pci->dev; + + err = of_map_id(dev->of_node, rid, "iommu-map", "iommu-map-mask", NULL, &sid_i); + if (err) + return err; + + err = of_map_id(dev->of_node, rid, "msi-map", "msi-map-mask", NULL, &sid_m); + if (err) + return err; + + if (sid_i != rid && sid_m != rid) + if ((sid_i & IMX95_SID_MASK) != (sid_m & IMX95_SID_MASK)) { + dev_err(dev, "its and iommu stream id miss match, please check dts file\n"); + return -EINVAL; + } + + /* if iommu-map is not existed then use msi-map's stream id*/ + if (sid_i == rid) + sid_i = sid_m; + + sid_i &= IMX95_SID_MASK; + + if (sid_i != rid) + return imx_pcie_add_lut(imx_pcie, rid, sid_i); + + /* Use dwc built-in MSI controller */ + return 0; +} + +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); @@ -941,6 +1064,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) @@ -1292,6 +1420,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) { @@ -1587,7 +1717,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,