From patchwork Thu Sep 26 22:07:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13813689 Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazon11011021.outbound.protection.outlook.com [52.101.70.21]) (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 F00601898E6; Thu, 26 Sep 2024 22:08:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.70.21 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727388504; cv=fail; b=CSjtZ7leBiwEIZTdrY4sM1mHK4puWRpoPAtEduf+DJ04YSQXUA9fp9NXxrili7rUNnX0i2cq2L4eQ1coFKP9kXarZJG/9JSW/8119agCf6569Xo0shmE56k16lgEr6ZjLSrKvGiYQkrLk4/ftthG/F9hysaSuVMRIuCnmhcWNig= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727388504; c=relaxed/simple; bh=ajAZyLgV+oZQd0uLwTR8EeTZ2PcQRwQ2YwA49Ppzjeg=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=p9fn6li5sKtATulT8NtrtMvIeZ18nXBz1ZMzCwD8Jjxyqg0JcdR6lCkup5EYI091I0RLjU/VvL0ZOPxKruxN5phqqfbg0xNN5IJh1fF2nCaoJnTdYGUGtz6H7dwe3qoAu8VYMWlNXfGHs2ze13T5xPjGRgan0fxch/XSsVpcPMA= 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=k2vqNVtU; arc=fail smtp.client-ip=52.101.70.21 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="k2vqNVtU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cW4q0L+PIfqkBeCuIk1m6vcTQZMq/YzdjliVAAU6yGP3Y4c5xwS8bb7YrFokPXSebHX2O7KcOvEC4FbqMZXvln5TausM3xXXeh2ZgcSzs0pik2rTbGciJO4mHC1KYarSobbRXaAw42xOj2iMU6mTViKyaXRfcsOPzpu6gMpC5iEvdCxrKL8uEfz0hKepMiZv3qtfh5Aiv6IdZnjzE+OmG35CMdiXrrqlAVZG2EiFyWCyq7XLR6a29kWq7ILH0DCo1CIjMsu25toiMDO0YIpzbS1wfmc9beNkjZ7WXVLu8ThgUd4nMOgKtBEpX79akuw0PL3xmqEUUWsYh5ajiDLvJg== 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=nARaTiApnM29p7FFkZmqPwG9iKsUGfbVyzLNVeSGHmE=; b=Wk0oNvmh2GOMrgW042lG6pOHTXs+tWbu7GaeUcfLeCldRDzMzM2N4qVCyVIU0vLZUboYCxDc0lN7bE8Enb67lyhAu3CqD4tJEoXcpE5gupYmEh/CjhVnImW4z7jV/DXZGH4SeWLf48mF2zZO8lAoTrtHc/BiBQZtachIPZxtKecDyikGUDaSTyqPZEaNyaZj3p/4VfREhFhYpKGGF618DmGwiVQ+uPfnkindPfBKYQJMsLtCoYhqOC5FQki2lj8y0Rj2VMIStMJEOX74BTgBYpZHjSQaqc/68/Ry0TgKl7JYuUEEZ9HoOS61cWM/CJiQNxr8XJFxYwRc1LNbAdURyg== 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=nARaTiApnM29p7FFkZmqPwG9iKsUGfbVyzLNVeSGHmE=; b=k2vqNVtU0vlGHMvnxIj/fTiHICGgKnNMbFzILy0M64soqrDrdkozb4tGO3cTCwtjKLdMb+UJxmgsb8V6OMC5UXP3FxlmkLHKo9mBOTtI7Www/ucZeiH3rT0fZmjhwBAJSPEun+mwYjYPPJcZVGWzT0/wE7aaW5ZoPspaALSc2JI7C6nYaaiuuh8YWQXZxGNYzCl8HhlGNd1ScHQorEeRHbJjHZd4MCYAj2ksMYvhq9SXbVE+3hqvOtUerop1gUxRs8f66RScTPXn/z41lUDBpnCH/y0Ed5VNbRwOejmDShCVVoEbXX4KYwCssEVlgGA0JoCQhmU07xa/KwgFROtGKQ== 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 VE1PR04MB7408.eurprd04.prod.outlook.com (2603:10a6:800:1b3::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.23; Thu, 26 Sep 2024 22:08:18 +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.7982.022; Thu, 26 Sep 2024 22:08:18 +0000 From: Frank Li Date: Thu, 26 Sep 2024 18:07:48 -0400 Subject: [PATCH 2/2] PCI: imx6: Add IOMMU and ITS MSI support for i.MX95 Message-Id: <20240926-imx95_lut-v1-2-d0c62087dbab@nxp.com> References: <20240926-imx95_lut-v1-0-d0c62087dbab@nxp.com> In-Reply-To: <20240926-imx95_lut-v1-0-d0c62087dbab@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=1727388480; l=6401; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=ajAZyLgV+oZQd0uLwTR8EeTZ2PcQRwQ2YwA49Ppzjeg=; b=/WiAr7yqAaBdN7zKkrqITQ1LzVkObYwiuQBCZE4CvVtqqUnA/j6Xfbv5369dpRB1Ys5CqbSZh 2qtomGwigmECtUUTwI2FpJjgskLlCASYLee4vC7U0Acss7fPXxzNE3O X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR08CA0024.namprd08.prod.outlook.com (2603:10b6:a03:100::37) 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_|VE1PR04MB7408:EE_ X-MS-Office365-Filtering-Correlation-Id: c8768ffa-8a08-476c-65f8-08dcde77b9cd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|7416014|376014|366016|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?ZmR16OlBouHZPVEw4WiO6KeEj6f+KTH?= =?utf-8?q?9dKwPLswCAMi+8zjIzh+bDgjf4eP1QwbdwU9h1z/SNK1TtQCapTsH0CN1NBmeSga/?= =?utf-8?q?UudBL2Hmjdetpn9d7//SG+TCYa1zxHcbuVg3mpfltUnJ73yQG6PWbgL+OJUc8CSGq?= =?utf-8?q?0PP29nYnrbkqg4XpEobKUeUilUXzCdXli8D+tsHgOW15AA7IAaotdXQsrDkwY0ivR?= =?utf-8?q?gpQRL17xddGj/4J0wqTKGU2U2dUC22eAqnkA3Ooit/o+p5LdjPB7K1Y5k+kjOtU1S?= =?utf-8?q?YrzmUtYEHjxMCAPtv6ENqiin/7c23oI3TsWphFsnZ6WqzbnPOYoZpumxfe8ndZqox?= =?utf-8?q?9sofGj25/EKpnO3lGIK+Vw1d2pZ6JLQ4xZNkbKrZ4ZCh2ljW84wnIISPwu9BsVdfb?= =?utf-8?q?vjZF7p1j3eAAMWEpw/vr/xmP/97SdtBioq7VmpU8wLpCEyb6fZMzSfJrzEY3z7OUb?= =?utf-8?q?RjPwVueyyaNVqPR5J6oJt+NiIA/rslhv/RaxP2iUniuqiGZkoXY1Dpcq87mzuXwRC?= =?utf-8?q?z3yzfJcsYFvgiKJpS4IqnTZecGs7Gc3BTBOsVJn39tKdtEYxV+IzEMEGDHMl09HCR?= =?utf-8?q?M+cYznXbf7j2YVBCSdeSOy6DkeMXVrlKZ8liQu3A95+2BJvnv6f6x9SoGFe81vDHn?= =?utf-8?q?+i4g7Svs9u0giAj3nn1I4B8nPw+OhTFQsh5rdlsPOkyllaro8ubAK6NL8EGH7Kouj?= =?utf-8?q?1w+SdCbqNHai+9aGqddfl0Fy9gcl2n/G3kcDJHB/4VzzdmXEdQM9dTJKRPdfQBh5p?= =?utf-8?q?1F/bih0JAOkJhnPzg2Hj4hkFx2qPyeTQRuz7An6rSNFWYI2EP1SXKg+sZ02yhDL2Y?= =?utf-8?q?vbk1RDzt5e7qMzaWeUVy5MRvwAmFustf+YsXwijfVqXT4u9HNawvuP0IVtx7kUbFQ?= =?utf-8?q?ILirKkzYTMq+96iJZ6S8/DG4jq0LaZ/sJ9M0wq3tdmsjDZ0vL1RWgtaBYSACD4hIY?= =?utf-8?q?xBJHPlhJOi4p3YxBROAANtePEAS1wPBYLthIlI4io6ac/kIKe3THmJPNUtqctVjYA?= =?utf-8?q?dIFnm/8p/2T1CllieYs2IMHlzSYywXDR+VSeh7CFB3icACD/nSzafC/CDZrdPARh2?= =?utf-8?q?oQ2wyzsV8QMDG490qQ4fPorAScIOz+Zb+bCX9xlNYKgb9kkGKym/0WYVZYET2NaNm?= =?utf-8?q?OCZ75fLG4vQH1wAabp/sowQW3OR5Ao7FTkmcCIy6L0o5ae6u/Wn6j9cYNQibY6TAX?= =?utf-8?q?7x51i4bRd6S1j6db1YrTrGsAW3yK1+NpjvnPScm2pkiSQVZWlvHVAxnMZRevvBQaA?= =?utf-8?q?SL4gPBHQ8e/FM485Gfy0FE4A1GrhG1rsFPRZv81RWQZcbr1LDBB1kN1BXzkfIDRMe?= =?utf-8?q?teiJ+q1Q+qzLoM49vDYa8oCHptSWAm4mzXzB6bZydDtS/yIE7U+bEUg=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)(1800799024)(52116014)(7416014)(376014)(366016)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?+H+07yRuPl7IXDemaEef8NbchOwn?= =?utf-8?q?IH7iaeJiBifgvs/McpYEbTviLm/S0oG5qwpA1QsykkU2wF37QvxwIrseyU7x1Vc+C?= =?utf-8?q?6DdtSL2IWHgAjDSIjp1wnOphV28Jvg8dpsSqZiODwsy1KSgMfYsj+9Jaea7Ii2tN0?= =?utf-8?q?OVPceYzf6XE8ITGbo4hOkf/cntQDGyMkRWPQ5BHWGwdhoFDPClQEMSdx7GmDbE1F/?= =?utf-8?q?7qoHtaySA1UMHkVyiIG8RdKIvnXM2ccU0Gn1paoO6FAn8Fe5af2gwVo+RbK8dKE0j?= =?utf-8?q?3zhleh1fqcpWUoLvw3kyz0Ai+uvqizls60tolUIlkIOX7OoP6mXtiwgAs8ZFbWEmI?= =?utf-8?q?bKrGHGRGNon3X9ixmmwCcJiPVnbUO3t7DtmD/UV2vhaDSUMKFotC/6Y/jeFAfnQx1?= =?utf-8?q?aqjBPxkc83xMWejnCWazeIZEOoM1f9c/GyapocTAmhuvKdfZmq3lqSdjpkOel68Cz?= =?utf-8?q?w1pi00FT/YmDfauxlr5lt5m+DXctzIqk6N3k5Ql/wHdzx6mp2KFRakyI2nfW/jzCQ?= =?utf-8?q?iQNe2+b/jbXyln/L1OEgzbEUTaxmFG0ZmaIZoV3Y+UYzOPRYWr1oQpdxL22TrJO0O?= =?utf-8?q?NBuyqOCjrc1QOf/CoxzsIUrTcPdgcC+fqWd4BX963xOliQ1YiEHD+4wooC+Y1qgi4?= =?utf-8?q?7Ojvv6tb1+OJCgikWPe7+N8J30ZYLU/v9t9NInp95aZ+86xbGwbbA9m5v5wVeG80W?= =?utf-8?q?xIyMmty6TpOoBtQvKJfLUvndXCAaOLV0JJZsaK+HM73bg7jDkP3NwAUw1l4UxgxWp?= =?utf-8?q?dsniNGBhS+z/NFutZgUwIQwPZ4i+jkfz1pjMprfEW7PHA3Ti6Gv8hW/yIa+DIe3nP?= =?utf-8?q?1mCRzZ0unrlrmTwC7+PrepOsp+qcSAtnvXAJFZ9+82KqHdddrWkFVl5VdyHam/RUN?= =?utf-8?q?6beF0F3bBWJexfOQExUeZMgw8b52Hpi4wylSJsXnTBgI/k4ViD9EF+XsmH3hunixu?= =?utf-8?q?2c8R4nF0L2v2N3A8EmESwT4I+UvjojQIh8uTcFMib7sdXt0hao5WfJjGI4LqAq+m7?= =?utf-8?q?5Fk6VbHXUrU0T83vtnoBPuElplkDCq5UZl/ScWd8Lh6rR0xSQbhA05i9PQpbolPIo?= =?utf-8?q?9DvwTDrw7MBHZrJDhDbYolTwbDCtMXJBPy8g0Kl1uFbyQIAREdLI3ri0WaN3SCR1U?= =?utf-8?q?sKR48GHTdk1Mwxh5nWqY/bl1LtzjnpQHAFiN2SHWv18zNO68+0XKvBjoFZPsnWbQa?= =?utf-8?q?nIc1qXmVhp8H1jzg0VMsI8VWJFRIO7++uti4am4Bufr69We+uHZON0qbvqZQsAp/5?= =?utf-8?q?SPnjqxz13IAIXoFs5U9RlNmlW+r6TahL0WVlwg3A7Yoolc5RTPAFovWEKUhDtUDcn?= =?utf-8?q?NGxdUUr2PoJe9bZ5FiuyuSbJHSq94QjYs1nrWwn9PZpZSDttg1wmmc+0el1mCPMS6?= =?utf-8?q?CAp1RD8GpL321c3F+eJL3AezYceHx4Gq5TZLFNduPGeMBylJZM8kfFqAu38K+oL05?= =?utf-8?q?SEeLE0doK4pVCtG16T6pgJoD4oxX/RM8rNAV2jSG0PnIzxpaEGm855xs=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c8768ffa-8a08-476c-65f8-08dcde77b9cd X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Sep 2024 22:08:18.0650 (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: 6SkgU/WIRf/9Ta4ZmNLH/RKr6Q7Kkfw9DD5aKH5GxwSzN7To/JaUT1xOYGi1KnOi3DkAesoCic37nLaxgL0jsA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7408 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 --- 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..1fe07f64d0d88 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_bus *bus, 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(bus->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_bus *bus, struct pci_dev *pdev) +{ + struct imx_pcie *imx_pcie; + + imx_pcie = to_imx_pcie(to_dw_pcie_from_pp(bus->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->ops->enable_device = imx_pcie_enable_device; + pp->bridge->ops->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,