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: 13813699 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 AABA3CDE03D for ; Thu, 26 Sep 2024 22:12:06 +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=nARaTiApnM29p7FFkZmqPwG9iKsUGfbVyzLNVeSGHmE=; b=kBycE+HLvSS+VMoETwOP/s032L HXgnsUKVEU8La3sgmw5tnRr2kW2mE7+M1e4cnohEKD3jKvlYo8o7BM0xB3W4pUY+N3u8TcabeDzxq XpJncseFMC4BTgfySSuh8nR+KbL+SMEFfrM9pFxdr+IZxXCSie6JoXLG7WGxE38T06bozD+0ca8mF L2o3uM3wWf0PCmFSWy7DX4aOiypzh2TUeCH58AZMOTararCH6v+ZEK3ZTVJ+3IvG6G6NHiXB+w2hD MgFVEKTOTdUWExjj0OnpCw3VM4W+pzsJSNird99Pq0mvMAKuSHhv2ehDrC1c7qF31dDZab0d6TnDw 0Y1w3iMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stwiI-00000009SD1-13F6; Thu, 26 Sep 2024 22:11:54 +0000 Received: from mail-westeuropeazlp170110003.outbound.protection.outlook.com ([2a01:111:f403:c201::3] helo=AS8PR04CU009.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stwet-00000009ReW-1LvG for linux-arm-kernel@lists.infradead.org; Thu, 26 Sep 2024 22:08:24 +0000 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) 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_150823_555762_5D5B78B9 X-CRM114-Status: GOOD ( 21.31 ) 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 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,