From patchwork Mon Sep 30 19:42:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13816903 Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazon11012036.outbound.protection.outlook.com [52.101.66.36]) (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 75853199FC7; Mon, 30 Sep 2024 19:42:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.66.36 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727725377; cv=fail; b=BvHFxyVFRzuF7FqP7UYl6oVi3UUYiiUs/dRf4CVY5BPsAjjJqN2bkGUBKoJMXruxGsL4pD1DEN/Puuq11/o8rEzt5VTOyxL0sTJT5+45r6LYj/bM+CRVq63GUrEsJV+FZRZ0dgRVhjNsOoViQ8q2HiSm+raXWLQg2Hp/QoEtAIM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727725377; c=relaxed/simple; bh=OREvL7vqU5D1pI9TulNzKxJCjsrDXsupI4DL+EY4/Co=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=cmWZAsi5Q2QjobWCJWTRFu7HNj5oaVE7Xyld/9aMdH2cA7fgVbCMyI6K+2fMsPUQsE8FXupdPvIrZYWoS3NdthuGB9MK7HPq6W4N+4lzdzRSPWIA5q9k1xS+D6TQjP8ILl4BfCGU3qDhBRAycmgnZkNyIvAOeNJi0gVurr9Fog4= 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=LEwM2NVp; arc=fail smtp.client-ip=52.101.66.36 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="LEwM2NVp" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iVN8vmtCUI1bO2OROmRf3rlMkp9XeRMa8KiLdHJpbBy7pdNJ0ADi0fk3fab+3cVC67QDOfZBE3wIbp5MU+EAw/eDb22FMncGnAwX/I+1ogvMzbNB8zaU0J9zDWN0J7YtRcY823hciQ4Gwo0x9qbbF6RwgKdr+VAGL+E/zIt5sYOrsRlMfhUQIR6kY4Dxf/W/WsoyqlCetKr9bQNbIESIeapGE4HoouuIBid07nOKedLZbIG+UzcGUUh6+KaAL0JINW48uMljhS+k80H6vL0VIuOEI1j8d2+9BBp02TUaKQIdptFePQ7tFzPkIA2UVaTBOlMxgSzSIClPwYmzj2mxag== 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=RsNjTO2JALhoDDDoueTOVkkG65B/pDGx9V+st1y/KHE=; b=gf+5EbYMCjvzAylsfjpmbqGYN3f4izlsEaU0LAdLYrTzxsudU+LcGpXwZeonaivujrT38Zy3fpya5Ce3bDpeYFTogXBOCD3zEREq9K0KZWBIq9x1t2Ic7rKI7SJy1qHsUvOrptAj+KRK0P6huzIY+xh7I6LJ//fXQMb3SMIvDpr6/2geElx7fA/BbIeX+KPp2FM+5PBgy57X07aeHAB6qAHJiW5XRexfpA+N827Bn20X28T4km/LAFLuInw05FnBBJFMJLmCfrNwR55W2pSXSPEDqijqU5U3f4whHEnOoV8NNxiA1RuCi/dkEkpB489wVNcqS1TP5X9g7WNv7AdIBA== 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=RsNjTO2JALhoDDDoueTOVkkG65B/pDGx9V+st1y/KHE=; b=LEwM2NVp1j6R7XvoVS655NX1IMJ0gEJ3RrofWlLmu0zg927wl47NGSPnMOlyq4LaFS0h/y7oRiPaOhoQ8p7ASdjf+27sDQdRtcj5MiIOIgKvMKHlErQIOckeXJZ5wRoK55wvaEQ5VJ0djrFvL40eXPoRLWq7UGE5TR2rJMWm5xxoIECdb5BpVPtfpmPL+VaT+nDHB07sbkKj/Js2Ze8FulxTomPLhWgjSFIWq0BtneLVrZq80bbg7QK03zWcUsOkPXqx/hUoRa8PtO/0GZA0AUNEjYdIHJu3Ni9WhUfnDJJujNZEFUVP88SemrL0lAoNHKywbczadApoZFJPwuF37w== 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:52 +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:52 +0000 From: Frank Li Date: Mon, 30 Sep 2024 15:42:21 -0400 Subject: [PATCH v2 1/2] PCI: Add enable_device() and disable_device() callbacks for bridges Message-Id: <20240930-imx95_lut-v2-1-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=2850; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=OREvL7vqU5D1pI9TulNzKxJCjsrDXsupI4DL+EY4/Co=; b=RqmKxOkRwsBQOKa+uPjogC3a6gO0ILQoO62arITPZQMdYYMVLUbuT3EPUNnE+1w04GgFbTCYx vuI/bVMbsqvDRBn0yAKofZJWjWyj/t3pEMdPEJicAg4ZvpkWmMJKSl5 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: ad03690e-6b4e-4da8-3832-08dce18812dd 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?yPdb5yGkiFD+O3sUvw3isNDo019v8+E?= =?utf-8?q?IuWVylHHTeZbrMxFhBzJ3hoJ3vEzWB0xezuKQOtd2LLORUsHppmikBp8Ifv932rJh?= =?utf-8?q?DPSsihe9CIY4dHVP47qruUwUlg8Kvu+WQZedwhP2srPO0CrrcmZB75IdjkQ8hegsL?= =?utf-8?q?06UTsufny6dx2PGu0B1BJI3hl/paFuPgr+j1RWYowCN3aObzBXhuSfz4Etd+FiF0K?= =?utf-8?q?DyJll0lLqAT3qdA/iTikJuM2ZjDE4R8zUxkX8ho/3mMKG+yHUUE7wREJlwksARARm?= =?utf-8?q?xktn0p6XDMj1cD1thltm2jaRPunanWW2EM1kKibEH1Qij26LmyhZYFnD871PV4Qs0?= =?utf-8?q?z7MboMK4znE00ILPpNic3vqJRxlV5A6nYyRum/FoVxEZLy7Gke+aFjiyErhwHgr0V?= =?utf-8?q?tX0OxCiOyqS7YrauUtratIZTK/if1S0B5HcrPNFMJHdn9Piv7fjgwVrl4yLLf0wLo?= =?utf-8?q?t0XHNZlhZcPPXt5Ftbi3XXAKnG2ZKdZSA9KdtVdurph8lIPK0FVHHKNyotQvHXN6v?= =?utf-8?q?oGumECYPvSwHyWtWXUO4F7lrT4VknUiEAhlJ+YkJMU4fqdoT1O017LdnDbC8AvnVf?= =?utf-8?q?2PUFdzz4yREHlM9/LK1ptOue8CBORZ+k/HOLa2K72bMyleW//KAU3F2tJ74TJIKvc?= =?utf-8?q?drq5mwI3RWhfvkLdyMsaYTL4+oGIV0rlJVfpimMNgM4wMjnUs3dqU9la7f26G3Uf8?= =?utf-8?q?k+7B/3VIHQzosvg205C28pwC59lwAIdQ2jVMKqIzCQWbeEv/2OlCrdpvsbTwvClop?= =?utf-8?q?txUVD0MEiDQcEG26Y2pxebkRI1EKfVm9q7E5PKUA4pNHBbLQ6T19H5SQKzdwh4re1?= =?utf-8?q?a29J6XmhMLaVcD/pwF08iut0hbsbQEV2sQKHKYpw2p6oB8ZlPbm8t8in66DF0+2bz?= =?utf-8?q?1iglNHGCgYCRZhBeSeQHbetIBLUTDq+sd7Kbo+GcmG2SR9lXn3gaLCrP35onDvPb/?= =?utf-8?q?GZLqeruPPodButTgKE8VvmBHYv1HfUB9lwSdbwt8k8/OUm0BkXXPUp49cTiIpljoj?= =?utf-8?q?75W6hbx5CVNo1ZtMM9LroqkI6p1RK7kZZlBt2HTDYvWYi2Ng6tE8rEWsvFkKfRlOE?= =?utf-8?q?/nP/ANCNCprQJxXgMiDoW5iH+UlUyiXUHAWKmW2jGGpFmtTUAI0ll+acwsHlP1UDq?= =?utf-8?q?ATVQ1+vzI7CpuCjAWSUyPda6uQCU9QTNZG/Cp6cGykhTl9jQ9nZ/Evm1L3iXc7iFW?= =?utf-8?q?ix56yTkBrMoTU8+q9yFBUdLpDXM4rSW631o8fR2rhRWxEz0dd1qA9Srb0L1ht7Tf/?= =?utf-8?q?Wmw14pbeQY/4dQKRqZWG1Nr165FDVKA2gV8zuYXVLu5sUtj4ftr9jx2g=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?8Ulo0ww92hi3RIp0OYwy09lex8Xw?= =?utf-8?q?qg3vLjT6ec398Wm6OqtuHkQb2WT8BHN4QVeTtFFxTUlDqWI1M0iwLtZ2k+gVbJwQI?= =?utf-8?q?zsyNMWEpO89epJQTzUpROqA5A0OsXLsf6DnI17WtNwaqsrzj/mJ59QmH6rS9Xld56?= =?utf-8?q?xkDgQ0S/1IH6CLxFl75h1BmzpLTHsdVdSmfNFB+4OabpVMpq5yMHp7sBoPjnn5eFx?= =?utf-8?q?cRwfhyfAXuaaQ0zZEphXunWCkt1lLEfV4/1t40SZye5mIY+c1qrsJwyEgV6mNjYpK?= =?utf-8?q?W7DOcfcqX2QDp+rXLijV2eKMXDYgtPWjhOcP6ejLBcxaWI8RZpdnXr9qv5kRjmzn1?= =?utf-8?q?Vy7L6TS4jwbzSfc37wCAY7Abl/eZQqb8oo6p4vRaBvtRyX23ln5x9i5xR0SnEnIJ6?= =?utf-8?q?Tkx/9uhgDyW8V60KnF0v2lmDNYyv58XbjO1fmwBX/nAgbPGdib/Anksd5ppSsRs1Z?= =?utf-8?q?3oDC2x1x1AweE1E9p5asHty8qCBgMEEaCSwwRNByWxGgFCIZInLmt28gTBk2DY3zX?= =?utf-8?q?6kZA8Js47psF6rC7j6aPL+gsSvYWHsIE/AGGtvGHlXU/pCIPqOxIXu2KzXelR36hj?= =?utf-8?q?ndu6Qp6rc6/c6KzCPr68447vZMiZOiqGhBF5Owh6iD8cYM6ZlE01E8AFC4wiEwui7?= =?utf-8?q?+xIiWnIOs2hVuz6kIZ2jaP7Ft8t4BziX7Vz8jrEjYaXqac49Re8PFqorhIq0zLemO?= =?utf-8?q?9ZA437xrE/EvkZZN5mD4gchOzclcQUlcXfKDadlbdJFR3NN0EHVINuSsrV+vS4ItI?= =?utf-8?q?czUF54KtBhj7oziRmtgFvrUPEV8pRjuc6W0yQ/pKUlS2i5KnZzpJtBrTt01skyJ0Z?= =?utf-8?q?XPoB5rtHbMMBNunPk2dBlMO73XXa09EoskktfgwKgUn3RJR4vwPjcqYLouLnXb7fF?= =?utf-8?q?woa6sy36HV/Tb1qjhJY/z1uky47e2RV9cad927y1PhQ/zrT3TVRNaI6andSHG9n0c?= =?utf-8?q?yZPpNh+8be+Sy2kI0VGXkdsdD9tv0NqVV975oKJQbCd+QE0CWZW3TvLDIxC2FbVtJ?= =?utf-8?q?nnWRdJhTKRMgoMqLuymbw6zbRu2OlHvI6kjZR1cClfYGMOpt7tDizko0fgCjBFFwu?= =?utf-8?q?mQ2pVWnOkLykcZGKslZHOntzyC10Xq30VjBpoxZWgHkVzyyT1Z014Banah0xa2vg5?= =?utf-8?q?SMDC7HZAXfaapo+J3wTZ7alOmMgyCcMjr9xeLSA8b387+QZlk5DsghywKdudPPhXn?= =?utf-8?q?i8+FzceE/A1AaQPTtIR4ZlgDFWsOZvoOAWyxPLvcjA0bM9VaVOzsmvmGcvHNNJYFg?= =?utf-8?q?ybPO7YdTFBvSJrmq6Mw2RHeAPhJ4uvpvioUNFV476lE+w6LyqAO2RqDftGh95y4B0?= =?utf-8?q?UT6QXSi4FHHSdSd04os6UmRGVZJSUMt54ZVriWGZ+gIOHDXfW4LNviRUYNOBDU4MW?= =?utf-8?q?qE+x4lzUec806CpnwkLfHQCn9eQb8wWfssrFt7R/dR7HllE54Knq+3Nq4dQH6NiFF?= =?utf-8?q?qFaiTcZdMpBvsbhAuJSigjeBj/U/QTgm8UmYwbnP/o9m7Kyxc9fyakEE=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ad03690e-6b4e-4da8-3832-08dce18812dd 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:52.8837 (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: 92mq3BVGPWYhXI4UmSIq7i1/Ai5uZ9cXYathcMNL5yhBymBJ33cU+otnflk59iW6MKpJyWLJQra8tyFr7X4m4Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB6806 Some PCIe bridges require special handling when enabling or disabling PCIe devices. For example, on the i.MX95 platform, a lookup table must be configured to inform the hardware how to convert pci_device_id to stream (bus master) ID, which is used by the IOMMU and MSI controller to identify bus master device. Enablement will be failure when there is not enough lookup table resource. Avoid DMA write to wrong position. That is the reason why pci_fixup_enable can't work since not return value for fixup function. Signed-off-by: Frank Li --- Change from v1 to v2 - move enable(disable)device ops to pci_host_bridge --- drivers/pci/pci.c | 14 ++++++++++++++ include/linux/pci.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 7d85c04fbba2a..fcdeb12622568 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2056,6 +2056,7 @@ int __weak pcibios_enable_device(struct pci_dev *dev, int bars) static int do_pci_enable_device(struct pci_dev *dev, int bars) { int err; + struct pci_host_bridge *host_bridge; struct pci_dev *bridge; u16 cmd; u8 pin; @@ -2068,6 +2069,13 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars) if (bridge) pcie_aspm_powersave_config_link(bridge); + host_bridge = pci_find_host_bridge(dev->bus); + if (host_bridge && host_bridge->enable_device) { + err = host_bridge->enable_device(host_bridge, dev); + if (err) + return err; + } + err = pcibios_enable_device(dev, bars); if (err < 0) return err; @@ -2262,12 +2270,18 @@ void pci_disable_enabled_device(struct pci_dev *dev) */ void pci_disable_device(struct pci_dev *dev) { + struct pci_host_bridge *host_bridge; + dev_WARN_ONCE(&dev->dev, atomic_read(&dev->enable_cnt) <= 0, "disabling already-disabled device"); if (atomic_dec_return(&dev->enable_cnt) != 0) return; + host_bridge = pci_find_host_bridge(dev->bus); + if (host_bridge && host_bridge->disable_device) + host_bridge->disable_device(host_bridge, dev); + do_pci_disable_device(dev); dev->is_busmaster = 0; diff --git a/include/linux/pci.h b/include/linux/pci.h index 573b4c4c2be61..ac15b02e14ddd 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -578,6 +578,8 @@ struct pci_host_bridge { u8 (*swizzle_irq)(struct pci_dev *, u8 *); /* Platform IRQ swizzler */ int (*map_irq)(const struct pci_dev *, u8, u8); void (*release_fn)(struct pci_host_bridge *); + int (*enable_device)(struct pci_host_bridge *bridge, struct pci_dev *dev); + void (*disable_device)(struct pci_host_bridge *bridge, struct pci_dev *dev); void *release_data; unsigned int ignore_reset_delay:1; /* For entire hierarchy */ unsigned int no_ext_tags:1; /* No Extended Tags */ 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,