From nobody Sun Nov 24 14:13:52 2024 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2047.outbound.protection.outlook.com [40.107.104.47]) (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 AD7391BC9FE; Mon, 4 Nov 2024 19:23:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.104.47 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730748208; cv=fail; b=Zsd2qq5rRiston81RKJ/afkf6lIoWx0x0C4laL7pdDxRyK1ppwCKfywbzW9KkRLeYSgWgDbKlJ0Q+tfwnCgmnJzadhsal2sC0gpulwVRYHrXd7giw5Svs4MY7XIyv+W5bFceUF6xRDPnjF046PWRxNRUkxL8MPEGsZUMg9fHQks= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730748208; c=relaxed/simple; bh=8CKgz0CXHgolk8bfnP5P9n7wD4iGkd6sl+5AuBcqB38=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=pgfDPaUcX3tivTAR5dZzqQj8jabC+ei2cWj8UYgexLC6TeGGq7ihpVRB1qOd/x6mzno62Lk39xpiu2Jo4uGn6puutOs5TWBVEkSa5hdnmFk6AxxndrrnhAct+uOfkMktzwcwpVEA4wLQxoljcXZLdfWZPsRzCPYAxHhrA6hO9ls= 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=H5n+TbXf; arc=fail smtp.client-ip=40.107.104.47 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="H5n+TbXf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Zuj4S/8NepRymJCwsAiOQOCLVLsiZ9KDEe5Ge/EinzaxNlAxKN8cXkae46x3Qn9QUmQ+zulnIv/hZDRAogWyWhxViGPL7Wq+k97RBK8k8+zlYknOOt1/Lx2c6DphWjhlp4CjPyfYTKQ9HX6aS6IpuBG+TvqgNZoDLpWaHzsfAZvRvm4Vgi7okhXr/8TSQDQwm8CAgUdNoUPDiAPUw91CgoNZx8pn/oIPdkV3Al+jmbkmL0VAyyYllCl/AxVnFRz85/0VwySrmmcYihAzncv0RbAiZxqsU52lftiGO5RHSAu+J3RD09MFXmrkGqFOrl2UuaRD4+TajGZCT3eM7ehu7w== 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=3+Z6+TCJdDoy8UwE3Y9/Bs3kkPwtKnXI87qBGTTmAy8=; b=WuuFIkMTkMFDtbC6AaWKOKVoVXHL1wj+7d5L262b6Svpo///PokxbKDd4Li9bxDBVjh931rC6/25nIoOoWmml2Rm04eb8VZRP9oyfM2O1p7ZbYbNxyZpb2m6sYAufHZpsUxk+VkZQFwgTBqvXbG50E/zsdjFPuSdEtOSt9YJu2X3mssTvAlGAF9YAAaKT/XXy0kqdgcFZ87nOvRyIDEBX1VsN/r15TZyK3aUN7dYZ1KR2bzXUDw0e3pkYrfmO3qx0PzEonLXaWJlgZJ723N1AmG6CbOcVO+eqkFSR90JIt2+O08binJzFkN341pvoM8U2YjknnyIL4KUNbIbikM3YA== 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=3+Z6+TCJdDoy8UwE3Y9/Bs3kkPwtKnXI87qBGTTmAy8=; b=H5n+TbXfPYzDEDcA/oebki1wKmfIbcDLvKzJqOYq4p94nu+QxpBVafwJIqOHBZxA0Lt3BT3ZDleP1o921ghEK3/lbSFf+mGGdVOoNKmagxLqWWoXzfyAgsZ7VE1hpOF8SK+ojdqUiSw+/SwwhlHbpgfxIQS5+NHdp0TNLYvNS02B821a+V449DPl8/mE+R0ePkXwQZu/TMZjB2YJIg9P4FkScs4BTcE3T4XuHcPfgSO65MwMDVGnQGkS74o/UlScrnEljJ4yAiDD2XVEjS2Jd8SCH8Q+Dj8k/L76z19mnVs90ldJIaR4KWW4HKZNTMEbwnWy16H5m+TF/sc7q7Bvjw== 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 AM7PR04MB6886.eurprd04.prod.outlook.com (2603:10a6:20b:106::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.30; Mon, 4 Nov 2024 19:23:25 +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.8114.028; Mon, 4 Nov 2024 19:23:25 +0000 From: Frank Li Date: Mon, 04 Nov 2024 14:22:59 -0500 Subject: [PATCH v5 1/2] PCI: Add enable_device() and disable_device() callbacks for bridges Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241104-imx95_lut-v5-1-feb972f3f13b@nxp.com> References: <20241104-imx95_lut-v5-0-feb972f3f13b@nxp.com> In-Reply-To: <20241104-imx95_lut-v5-0-feb972f3f13b@nxp.com> To: Bjorn Helgaas , Richard Zhu , Lucas Stach , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=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=1730748193; l=4072; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=8CKgz0CXHgolk8bfnP5P9n7wD4iGkd6sl+5AuBcqB38=; b=dcSFC3MwwFcbr4holoLbUXJvikUCgME+sFBu83RzwZi1VDYdbP9VGI2nFYMUFYBbkkwMK/DSF eer7aKWDJBlBGACBF76LbyFgji0htAtHM/DV9UfFTF1vrQ1YJByB5Gc X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY5PR03CA0025.namprd03.prod.outlook.com (2603:10b6:a03:1e0::35) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AM7PR04MB6886:EE_ X-MS-Office365-Filtering-Correlation-Id: 8d239559-d862-4aff-cca8-08dcfd06276a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|52116014|1800799024|376014|366016|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?MHpFbldLOHZYNmQxQUdTaDg3NUhzYjVlZWtITWZTYnpLaitKR25SaFB6ZWI5?= =?utf-8?B?R3FxMmZCblVpN0FzYllqV25pT0hsWFJPSWJUNHh3OFNVeEs3U1NNVnljY09v?= =?utf-8?B?L3kvcnZyak13MnFVbVIybTFINnBKN014VEpYaHpCVmFucHBzUUlieHo5eElZ?= =?utf-8?B?Z01CbE1sWXZmNk5scmFCMDBiRHM4Qkl5UjJBd3dacTFBM0ZUTDh1VDlob2Vw?= =?utf-8?B?Z3pOM2VBVnhDK3B2RDBwbUVTeFE4eXlGSEJ2TUNqbHhhRnlpaTFJeGRQekhq?= =?utf-8?B?NmJwSWxPd1hJSnM2S3ZQV3RHMklDNkMrMHp5ektYVlZKM0VUZ1ZaYys4YXdj?= =?utf-8?B?Nk0wWTU4MGJKQU1ubitGMkIybEIrMXJicThrRzBQcUkrOVcxNTNTMThnOC9E?= =?utf-8?B?Y0FCeFlJbWlBMG1hTzVqNnBqT21WV21vS0hTRkNVNXhMNkdyMVpBOTZEdWJL?= =?utf-8?B?TTlnSzhLaTEyRHJzUFNCNW1tUjEwRVh2aFErL1l1SHkyczE1UitwaDBoN3k3?= =?utf-8?B?dFp5RFRoUENJUGFhV0N1MTdHL2pzZkpiZE5PcURRTWNEWWJ5RE1MSUdHQTY0?= =?utf-8?B?M21uTUVLNnZ5S2ZXRlc5NGJUVzBTRTZsOU44dUJJbkdhVEZZdDdEMmpWbmhw?= =?utf-8?B?dlUxZzJlL0dOQU9NTmJJR1ZNZjNjTmRBRWNBbW83SUdSU3lFSXVpczhFdzZs?= =?utf-8?B?cXpYZlNzQmhKSzNQSFNreFZaVzNZNlAzenVoOGR1aE8ydTRmS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dpQWdMU2pzOGNjdTA4WW5oVWhvaGFj?= =?utf-8?B?Qk05anBpZXZhVW5qVHVMRGlmZjhuL21OeTNOeWFtRTA1V0xKY1hwSTdidGcy?= =?utf-8?B?MlkvYWt4UXRUQWE4bWpSM3lhY21ZUmZTRWovZktQREJ5OEZZZXBoWWFNb3Jr?= =?utf-8?B?T1JIRGVnL0RsYzVia2VmRTZnbGgvakg3UHp5YnROSzR0OVJBWE5JdENsVzEx?= =?utf-8?Q?rp9w0RYLaoHhs?= 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)(7416014)(52116014)(1800799024)(376014)(366016)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?blVPUDhwNjFKLzl1bTQ0bFgrV1lRKy9RSlpvSHc1REVlSjdoNkN0NU44bytk?= =?utf-8?B?dTZBaDgrRGJLNDkrSUlNc2xITU5FaFZQbmpXRTVpM2x5SVZ6KzQ3UFhIYXhM?= =?utf-8?B?ZE93M1BUQ3BuQnJta2ZuNW1XSGdmbmEzWDA2TFFCRXo3bm9aZEgyLy96amRU?= =?utf-8?B?NVNEMWNmRjNkemdrSmtFVjl0UGVOdnJqdTVsYllHTy93ZXFEZGlVaGxtWHN4?= =?utf-8?B?TFNSRlRSYmhUS21MTWtiTHc3ZDBPYlB3OWpzZ1MvUmZIVFdDTUpaR0ZIeGZC?= =?utf-8?B?bUlMVGRuNm0xb1daUGxoRVd0dllHQklXbndjaXh4M1lkVFRES2hWMThoSXIw?= =?utf-8?B?elNITXVlNjBBM3lyMmJBMkZzMkRvbTFJdmNUSDFWM2JTa2k5SE5Ra3V5N0lK?= =?utf-8?B?YUFNc3ZLUXdGRGhqODl3MVdlWU94YnRrR3ViKzBEa3gwQ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pra1NIOUU4WmxyMlNUKzFTb2paNEJOQjRUb2tT?= =?utf-8?B?NTh0Rk9GTVR3MmxKNnMyZHBXMyt6SWpsUERkS3RUSHRLQUtFNk9xdlI2NWdU?= =?utf-8?B?dWYxZDhRK24wUVRtNlZlQnhJVzJuM051QmpJVzQ3RTlRZTEva3d2R1BHRE9i?= =?utf-8?B?eTA5cTJXZGdGT0tkc2lKUGRRKy83anh2dG02SXFhRnh6eEcrcElGaWt5VVY3?= =?utf-8?B?T0VCUkx4aFJUZTZ4UlpUOHFvRCtjSzFPdWhBL3l4L29MTTVmemp3UjMyZVZr?= =?utf-8?B?S3RzZzROb2RINDRIU3JoMFFJd0YvTUNBSnd4bWhsbFplT3pJVDIxSXA5a2pa?= =?utf-8?B?NWxGUTlnaisvQ3VqekhQUnFCOVlsWWg5WXhPM1IxbkdnOGNKaTdqVGRSOElv?= =?utf-8?B?eTY0QXQ3VVR1ZlM2a2Z3ZjNOd1FHcG01R0hVQ1NvTE1mODh5TEMvVUFhUTlW?= =?utf-8?B?NWNOVHdGYVJiTHpzZmhudWVYcEQvQlBMRi9pY2hmNXBTVWZiMjlTZWs2WXo5?= =?utf-8?B?Zmc0T0VqOU1hU0lRcjFGUWpGTCs2TDJpWTZMWUxTWjZnY0xBRmdMVXlzOTVo?= =?utf-8?B?cVI2ckoyamxvb3FHTWx1b1pKYy9Ea05qdWw1TDc0dkxtV0Vvb2FVT3lBTit4?= =?utf-8?B?cTlMeUZuRUk1SnRmTFNXWkxCanpna0ttdjNMRVczOWc2SlAxaThTSHdvZVA3?= =?utf-8?B?NmR4WjhLUGJZaVNRQ3c5a1A0TlJUbVozallvUWllSmFRbXRYc2RPMTdNMjVI?= =?utf-8?Q?iJqs=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8d239559-d862-4aff-cca8-08dcfd06276a X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2024 19:23:25.3793 (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: 4wA3lh6PyzaTVjOD2B7Th2iaOFuWMwfht0iRo6RjBHvxGzEiuPzSBNZb/0JfLdK9uou+krexcaJ58JqE5EBsnw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB6886 Some PCIe host bridges require special handling when enabling or disabling PCIe Endpoints. For example, the i.MX95 platform has a lookup table to map Requester IDs to StreamIDs, which are used by the SMMU and MSI controller to identify the source of DMA accesses. Without this mapping, DMA accesses may target unintended memory, which would corrupt memory or read the wrong data. Add a host bridge .enable_device() hook the imx6 driver can use to configure the Requester ID to StreamID mapping. The hardware table isn't big enough to map all possible Requester IDs, so this hook may fail if no table space is available. In that case, return failure from pci_enable_device(). It might make more sense to make pci_set_master() decline to enable bus mastering and return failure, but it currently doesn't have a way to return failure. Signed-off-by: Frank Li Acked-by: Bjorn Helgaas Acked-by: Manivannan Sadhasivam Reviewed-by: Marc Zyngier Tested-by: Marc Zyngier --- Change from v4 to v5 - Add two static help functions int pci_host_bridge_enable_device(dev); void pci_host_bridge_disable_device(dev); - remove tags because big change Acked-by: Bjorn Helgaas Reviewed-by: Marc Zyngier Tested-by: Marc Zyngier Change from v3 to v4 - Add Bjorn's ack tag Change from v2 to v3 - use Bjorn suggest's commit message. - call disable_device() when error happen. Change from v1 to v2 - move enable(disable)device ops to pci_host_bridge --- drivers/pci/pci.c | 36 +++++++++++++++++++++++++++++++++++- include/linux/pci.h | 2 ++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 67013df89a694..4735bc665ab3b 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2055,6 +2055,28 @@ int __weak pcibios_enable_device(struct pci_dev *dev= , int bars) return pci_enable_resources(dev, bars); } =20 +static int pci_host_bridge_enable_device(struct pci_dev *dev) +{ + struct pci_host_bridge *host_bridge =3D pci_find_host_bridge(dev->bus); + int err; + + if (host_bridge && host_bridge->enable_device) { + err =3D host_bridge->enable_device(host_bridge, dev); + if (err) + return err; + } + + return 0; +} + +static void pci_host_bridge_disable_device(struct pci_dev *dev) +{ + struct pci_host_bridge *host_bridge =3D pci_find_host_bridge(dev->bus); + + if (host_bridge && host_bridge->disable_device) + host_bridge->disable_device(host_bridge, dev); +} + static int do_pci_enable_device(struct pci_dev *dev, int bars) { int err; @@ -2070,9 +2092,13 @@ static int do_pci_enable_device(struct pci_dev *dev,= int bars) if (bridge) pcie_aspm_powersave_config_link(bridge); =20 + err =3D pci_host_bridge_enable_device(dev); + if (err) + return err; + err =3D pcibios_enable_device(dev, bars); if (err < 0) - return err; + goto err_enable; pci_fixup_device(pci_fixup_enable, dev); =20 if (dev->msi_enabled || dev->msix_enabled) @@ -2087,6 +2113,12 @@ static int do_pci_enable_device(struct pci_dev *dev,= int bars) } =20 return 0; + +err_enable: + pci_host_bridge_disable_device(dev); + + return err; + } =20 /** @@ -2270,6 +2302,8 @@ void pci_disable_device(struct pci_dev *dev) if (atomic_dec_return(&dev->enable_cnt) !=3D 0) return; =20 + pci_host_bridge_disable_device(dev); + do_pci_disable_device(dev); =20 dev->is_busmaster =3D 0; diff --git a/include/linux/pci.h b/include/linux/pci.h index a17edc6c28fda..5f75c30f263be 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -596,6 +596,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 *de= v); void *release_data; unsigned int ignore_reset_delay:1; /* For entire hierarchy */ unsigned int no_ext_tags:1; /* No Extended Tags */ --=20 2.34.1 From nobody Sun Nov 24 14:13:52 2024 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2076.outbound.protection.outlook.com [40.107.104.76]) (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 422D21CDFC0; Mon, 4 Nov 2024 19:23:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.104.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730748216; cv=fail; b=EHusY7PEm05WPwZ8nS5iXDg9U3sh5pCUFv1UfLhjv0jE8G8kk9CMSy7Y7bKpK5CdAmL/4CCblCGHFGdzbviyOUIIYAjlfG531OeEizTKO5CUtNf9W1FoCPdvko54YbOR/+YQ1S7CLz8sOgsWBRuhSSEaGljdXWpVYm+mfH1fI60= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730748216; c=relaxed/simple; bh=+aIiIuuWGwNys2L38Y01Wb94GgVrnLzwlwttSKeybKc=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=esYTb7phFpMxVyjM/GMZHT8zntMng3b49S1Dz7oxfOsjv0UVVRtsK0qrBBTwYWkBwQHoPxxz+iPujJZ535I/kmsDy8U0Rof/+85Xzgq3XTSPHFcc+jkHLRHMLludLWPNlfk4g5CLAeOm+/CO9rqKlfs1Scfi1G9cLMRP3Hz9D5U= 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=juJcFmgG; arc=fail smtp.client-ip=40.107.104.76 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="juJcFmgG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pnbi08pdQR5Sjv0tzl90CFj1pduCEPM2/WDkpU3EwfObk4uThHn9EwoPTfLE20xmHAYSe9vCr8/enkwb4f8o/B5Rh0a2a9go0sH8Y51zJqXDGGJnbzzFhlE8B86HexHX4RE32M1FtKOFVSH2AgmhJpHkd3y+P54wKCIuTPt9GVQRWXXStU/1msCOweBql/CQtwJqn6ntVkkdQYLK1JsLoXY57rkesC94V0BT0pq7mugpBEvEPqt37eEkGRmPi/Ule0eWR3hsCBksEyOq3Lbj+xiyiwVv9v41ICsDCzfRtmJ4jN5CEqUah7b3JU5McTCVFe+11LWhf0V7rf/hxr1sYw== 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=tQjjFi3dBR7ct2082uGxiptRJvIFAG5bMc0X6N5857c=; b=ywtpIUbQtKc1NY+VSWVg8TRLEe05TXI8RUPDUoix+hd+YyirDD05NjMeNMK9kawModW+9KQSrzQhjt+mpa7G4uMdm+tiGRcNY63NH7lSUPSAbzVVGnkVG0ezYoYh5NvSeR7k/rWMCXzrwAUUrWIG/kaKeyxLKRe7CUbp+UCViSWPuhj2XgzynfXlx1O+qDFijrdJX3hdz3B+cSWGZb3mzmOh9CZADqLzHGgVZPw10IE5KyIpiBh6VtXUTx4EZIOZcWYEimagGC7tcrHamyaXm0xN7PXv+ohfNvMBDNqoYEMo5LFuJTpH2p7w3ql6RtX/94nsreencyiMrNxz/gwaOg== 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=tQjjFi3dBR7ct2082uGxiptRJvIFAG5bMc0X6N5857c=; b=juJcFmgG7BxPH3Uhv+zCvYVL7VKML83JoSWmE3wfFO6dXJ1NhaR3kVJLXFbJJKxlkxD/bqKCX94hHUp+XfJjVVKrabg+mmDg1edud0OUyuDP90dQBqiLRpkddrlx2SVrzrdw/70qGwFVIug+3rA1nf4DAp/4ZmkjRkCu1DjmPNZN1GZYe7o4aOpcxYJXEG2G0BqPzVAl2csanrYA1eXLOUAscd9F74g0+tN/kFzN+F6zqHhEe9OuMjqyFhP+NtHb/oUd6PSySjz89bGmQbyJF9ockmANbnZfONkTFhIRa0sel4/r6OGjhZOBk4Iv9NeSN2cyEYBHc9w5IJMq2v35Qw== 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 AM7PR04MB6886.eurprd04.prod.outlook.com (2603:10a6:20b:106::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.30; Mon, 4 Nov 2024 19:23:31 +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.8114.028; Mon, 4 Nov 2024 19:23:31 +0000 From: Frank Li Date: Mon, 04 Nov 2024 14:23:00 -0500 Subject: [PATCH v5 2/2] PCI: imx6: Add IOMMU and ITS MSI support for i.MX95 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241104-imx95_lut-v5-2-feb972f3f13b@nxp.com> References: <20241104-imx95_lut-v5-0-feb972f3f13b@nxp.com> In-Reply-To: <20241104-imx95_lut-v5-0-feb972f3f13b@nxp.com> To: Bjorn Helgaas , Richard Zhu , Lucas Stach , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=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=1730748193; l=8517; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=+aIiIuuWGwNys2L38Y01Wb94GgVrnLzwlwttSKeybKc=; b=bH+v7y/ABezCJFM7lwh4MoCDxsYBRmAGhqGn+M70SXZ2LTSsZcO5wimcUJwldWy2gmJmHmw2V khKjjjEW8T7CVNV1Q5e43DJgBuHEYj6X1kPbUoT8mViWcsImisp7LBu X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY5PR03CA0025.namprd03.prod.outlook.com (2603:10b6:a03:1e0::35) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AM7PR04MB6886:EE_ X-MS-Office365-Filtering-Correlation-Id: 272d4d66-a657-4464-3fb3-08dcfd062b1e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|52116014|1800799024|376014|366016|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?ZzFpQjZMWEI5WWRwNWxyTk0yRlc2b01OSG9mMzdTQmZMU0tOSFp2dzd1eklz?= =?utf-8?B?eXE5ZFRRaDVaU0VyLzBXa3JobDRhc3gxTTd6ZG5oeVdjWmhxc3lyV2lSc2I5?= =?utf-8?B?eFVxVGVTcXJRS2Rqdkd1aVUrZVNYOVltakxsQjNUUFlnWjFjNDRLemVtemla?= =?utf-8?B?TFlBY0FKY2NlNGFmU2tmZ0pKVEdsNVpYZkFnN01kZzB0Rms4dy9SSTBrZHhZ?= =?utf-8?B?K1Jza3R1NVpDK2RTbk9DZGR1enI1dTdUZmdNTzRKYWNwNW1vTlk3R0h6bm1R?= =?utf-8?B?N3hOQVU2bUNEbEN3OURuMlJ4NGdob2ZHdG9EaThjdFU5RFlWeTMzOHBDTjZU?= =?utf-8?B?bnN2ZEsvOEV6VEpjUW85amR4U1JBMzMyOGNCTXU3aHRKWnFNOVNKbTBxYVR3?= =?utf-8?B?N2ZFcUgvaUNPdDQrRWxUK050TmN3ck53NUNlYUJZQmVRaTViWkVVcTJMMTVa?= =?utf-8?B?OXZjQXpXNXNCa1lWeThzbDhVcWxpSjA1UklQbHVlZ3orWksxS2E5T250c2RL?= =?utf-8?B?UER6VWh3V1c1eTRKeXY4dkg1VWhYTEtGY09Wd25GdG5VWEJROHVjTDQ3M3Vy?= =?utf-8?B?MkRialVVRnM4YmJSTTRsM2ZIUjhBeC93V3cyUXp3SlRYeWJyVk5wYTkwSUVV?= =?utf-8?B?N1BGTVJXZFM1ZDcwUWRETk9DV1c5WDhYZkpRY3Z0ems2ZkF6cVd4L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M1RWaTBTZWI1cDhBMFhX?= =?utf-8?B?WnVIYS8rYmZyM25TcXk4MGZEcWYwUFYxeW93L0RWRTFHM0V6KzFxWjIwMko0?= =?utf-8?B?d0IwNTBiT2s2T1gzVXM1eWxnVDgzeXFFM2VOeFVEWUJ0MDhTclNhWmM5Q21h?= =?utf-8?B?UkpaeHQ0STFyR0FXdXdaM2ZVWldOR2ROSS9UZVcrMld4Rlc2ZFhhN3FOVjJS?= =?utf-8?B?czZnYlFiZ1U5M0IzWEh3ZlBoSHk4T2NDc2l2ZVlnRXYybW5XUVFzN2NqL3hB?= =?utf-8?Q?+1YVN4K1pEQNG?= 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)(7416014)(52116014)(1800799024)(376014)(366016)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?ZWdWaWNNZmg0VStUcHhJN3EvcW1ua0ZRdm0rOHUwL2orRGNhVVNLOVR6cnRZ?= =?utf-8?B?eURTbWJ5aUJkWGRLRUtJNWlSNWZESzZmemhUMzJ0NlpzQk0yc0pzVWRLMm9j?= =?utf-8?B?Z21uYXN5YXZrTEcrTi9abnRGb3FNa3NMZm1aTEErd1Q5UzV4K0JrVmtRbFll?= =?utf-8?B?V01lN2E2SHNDVmxHZnRrSmNLOWdsalh6ZFZDaHBPdHVoc2RBVmNheERCQWhY?= =?utf-8?B?cS9KYU9IM2hhMzBFTjNPbnRUMUl3SVlFZUNGS1RmK3A4cVV0NjdZVGFhT21y?= =?utf-8?B?OUl6dUFJUU5hbTBkRS9BVzR5Sm5EakZjNnVBT3NPcGgrZ1JSY3BDZmppTFFx?= =?utf-8?B?NDZ2T1hBa0lXeXRGc0g4ODNmUXlxYzY3d0Zva1dmOU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S-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2024 19:23:31.5908 (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: WgnyzpVLsObcU/OSN0wNt/9IaBWWsoFKv2V2zL801v3wVmOK4G4QzQRgqGfDJMv/zrLZNvXOTZAKL+qhNs57fw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB6886 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. 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. Acked-by: Richard Zhu Signed-off-by: Frank Li --- 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 | 176 ++++++++++++++++++++++++++++++= +++- 1 file changed, 175 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller= /dwc/pci-imx6.c index 94f3411352bf0..e75dc361e284e 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) =20 +#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) =20 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) =20 #define imx_check_flag(pci, val) (pci->drvdata->flags & val) =20 @@ -134,6 +151,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; }; =20 /* Parameters for the waiting for PCIe PHY PLL to lock on i.MX7 */ @@ -925,6 +945,152 @@ static void imx_pcie_stop_link(struct dw_pcie *pci) imx_pcie_ltssm_disable(dev); } =20 +static int imx_pcie_add_lut(struct imx_pcie *imx_pcie, u16 rid, u8 sid) +{ + struct dw_pcie *pci =3D imx_pcie->pci; + struct device *dev =3D pci->dev; + u32 data1, data2; + int free =3D -1; + int i; + + if (sid >=3D 64) { + dev_err(dev, "Invalid SID for index %d\n", sid); + return -EINVAL; + } + + guard(mutex)(&imx_pcie->lock); + + for (i =3D 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 =3D i; + continue; + } + + regmap_read(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA2, &data2); + + /* Needn't add duplicated Request ID */ + if (rid =3D=3D FIELD_GET(IMX95_PE0_LUT_REQID, data2)) { + dev_warn(dev, "Try to enable rid(%d) twice without disable it\n", rid); + return 0; + } + } + + if (free < 0) { + dev_err(dev, "LUT entry is not available\n"); + return -EINVAL; + } + + data1 =3D FIELD_PREP(IMX95_PE0_LUT_DAC_ID, 0); + data1 |=3D FIELD_PREP(IMX95_PE0_LUT_STREAM_ID, sid); + data1 |=3D IMX95_PE0_LUT_VLD; + regmap_write(imx_pcie->iomuxc_gpr, IMX95_PE0_LUT_DATA1, data1); + + data2 =3D IMX95_PE0_LUT_MASK; /* Match all bits of rid */ + data2 |=3D 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 =3D 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) =3D=3D 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 p= ci_dev *pdev) +{ + struct imx_pcie *imx_pcie =3D to_imx_pcie(to_dw_pcie_from_pp(bridge->sysd= ata)); + u32 sid_i =3D 0, sid_m =3D 0, rid =3D pci_dev_id(pdev); + struct device_node *target; + struct device *dev; + int err_i, err_m; + + dev =3D imx_pcie->pci->dev; + + target =3D NULL; + err_i =3D of_map_id(dev->of_node, rid, "iommu-map", "iommu-map-mask", &ta= rget, &sid_i); + if (target) + of_node_put(target); + else + err_i =3D -EINVAL; + + target =3D NULL; + err_m =3D of_map_id(dev->of_node, rid, "msi-map", "msi-map-mask", &target= , &sid_m); + + /* + * Return failure if msi-map exist and no entry for rid because dwc common + * driver will skip setting up built-in MSI controller if msi-map existed. + * + * err_m target + * 0 NULL Return failure, function not work. + * !0 NULL msi-map not exist, use built-in MSI. + * 0 !NULL Find one entry. + * !0 !NULL Invalidate case. + */ + if (!err_m && !target) + return -EINVAL; + else if (target) + of_node_put(target); /* Find entry for rid in msi-map */ + + /* + * msi-map iommu-map + * Y Y ITS + SMMU, require the same sid + * Y N ITS + * N Y DWC MSI Ctrl + SMMU + * N N DWC MSI Ctrl + */ + if (!err_i && !err_m) + if ((sid_i & IMX95_SID_MASK) !=3D (sid_m & IMX95_SID_MASK)) { + dev_err(dev, "iommu-map and msi-map entries mismatch!\n"); + return -EINVAL; + } + + /* + * Both iommu-map and msi-map not exist, use dwc built-in MSI + * controller, do nothing here. + */ + if (err_i && err_m) + return 0; + + if (!err_i) + return imx_pcie_add_lut(imx_pcie, rid, sid_i); + else if (!err_m) + /* Hardware auto add 2 bit controller id ahead of stream ID */ + return imx_pcie_add_lut(imx_pcie, rid, sid_m & IMX95_SID_MASK); + + return 0; +} + +static void imx_pcie_disable_device(struct pci_host_bridge *bridge, struct= pci_dev *pdev) +{ + struct imx_pcie *imx_pcie; + + imx_pcie =3D 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 =3D to_dw_pcie_from_pp(pp); @@ -941,6 +1107,11 @@ static int imx_pcie_host_init(struct dw_pcie_rp *pp) } } =20 + if (pp->bridge && imx_check_flag(imx_pcie, IMX_PCIE_FLAG_HAS_LUT)) { + pp->bridge->enable_device =3D imx_pcie_enable_device; + pp->bridge->disable_device =3D imx_pcie_disable_device; + } + imx_pcie_assert_core_reset(imx_pcie); =20 if (imx_pcie->drvdata->init_phy) @@ -1292,6 +1463,8 @@ static int imx_pcie_probe(struct platform_device *pde= v) imx_pcie->pci =3D pci; imx_pcie->drvdata =3D of_device_get_match_data(dev); =20 + mutex_init(&imx_pcie->lock); + /* Find the PHY if one is defined, only imx7d uses it */ np =3D of_parse_phandle(node, "fsl,imx7d-pcie-phy", 0); if (np) { @@ -1587,7 +1760,8 @@ static const struct imx_pcie_drvdata drvdata[] =3D { }, [IMX95] =3D { .variant =3D IMX95, - .flags =3D IMX_PCIE_FLAG_HAS_SERDES, + .flags =3D IMX_PCIE_FLAG_HAS_SERDES | + IMX_PCIE_FLAG_HAS_LUT, .clk_names =3D imx8mq_clks, .clks_cnt =3D ARRAY_SIZE(imx8mq_clks), .ltssm_off =3D IMX95_PE0_GEN_CTRL_3, --=20 2.34.1