From patchwork Thu Sep 26 22:07:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13813694 Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazon11011023.outbound.protection.outlook.com [52.101.65.23]) (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 1FA9E189F3C for ; Thu, 26 Sep 2024 22:08:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.65.23 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727388501; cv=fail; b=UvIzIAKoXu8Os/KR9zXLMw2tUoAGw5bwk7EttJ+baxaP3l3oHwN12YfO0BVqs9KNR1ISdtAdx2DfXf9rkJdXIjcwrrfM2rizSCqL2aGv21M8smiyRkCcifm7ooZP2DTqZFUHfuFf+O+xm01LTFIBUriom+cCACb+SlQNfOoJ99A= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727388501; c=relaxed/simple; bh=14hFnbXmRluLjGSiKRej/f7VpiNO+1DgtI8irwhuSwI=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=bbIGkJkg0aiveoxqFgGyHXvJYrd1jdKVlOfxxBDkvlcJ5JZoEa812qqnXZwA53RghEPbQ/Xto4HwPbX4BJQ8LrVbAHn8cjm8pe50v+dcntd+XWTcHFOkMfcQYz3B1s+GoeGlN7s70Z84FZ+q593mN6wR0SuVHuexOXs8UfqXLvk= 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=Uc8cVz5j; arc=fail smtp.client-ip=52.101.65.23 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="Uc8cVz5j" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rgNX8glxbPmh9XY6O2jn2ng7Wq6t5pXXNWGroQXoqA2u9XLLitRxVJpisHdk1OdgRcJQB2aumNfy5XKFTgC+8bxiwvbQbU8bdsYJcWRKJgp5gmSBCaUvpgmEsdyqQ4WJQ/ieUvcoh1Vh0qORmWk0pcK20wAgHdQwdBGKbai9g1BksXu5NtJ+gR/JTAUkh2SMXUk6QbJomf/YwnK07v2GsHe4y6KhZjIvv5Ak9t9+ZRL3zsoQJyft2BepV1tzoGZDPsfwkhAAP6FcB2OO9Wmnx3MHB/2BBqMgdAnQk3MFRu6N7Nvk7mQrzCHO1gXCzuBZs7iZffcOZ/EjwvqPVSCkXA== 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=CzCT7+s1b0Q80pJCAftFwbhXnxu+FudVU3zL4cQP3CI=; b=ptGspLNwkStXVIfkuoPEpDzp5VjZGid+vqvPvCkUUur3ffXv+o70ODbtxRJExVZL4t8rVM5qKtw/65hbTnPLr2TbCYwcluLOsxzPfnSSnUVJw8PZ5iq9fDlZvEQCocLRcOKsYbSIaubhL3PqjYNSzx3UWC4cJMijgiq11/VPj5C5kd4LfoYPGALy+GUSuGtHbVtBNI3ACiBLCiKsYFosZRoHp94heQRV1aKKOm9TieYUNYxutQIjPQWUvaFYKSsKFauJntIFUA9c3+NjUwrOjCV8l2oOvMy5h7WRlCH9eJV0AGqt4LphNIAzWOIHJSkXxbD+lUNVxAegDSE4KhYYZg== 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=CzCT7+s1b0Q80pJCAftFwbhXnxu+FudVU3zL4cQP3CI=; b=Uc8cVz5jKIUjD4B+5QHLYC2MoQNEgKecVTg+4tSw2wCdGQUg2AE0wrhW9cNARxNS0Gxe8RkhJ/scThZaYddke4YuhQchVaMvi5YOeHKtd/bc98u8ridfcQ75AleQji+E9URaK1dgvVkQG4225ttJYVfPs48m8cINq0+poakFGhrRF3r0wrgXqy3juvEgc9WwOpICZfmEaaSVU4oeasgbwJ1tnazxO3I/jIDnlFs5Vf5TAwZ0SIDLlcUT4b4hG9dZM1MmRW0UO7FvQLsx71f0qqHBgvD9GHn7Rq61TWFdnKF9JiNJmx42EfldoXCbS1NpilrLH3DKUoHoCnnmp8Y2yQ== 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:12 +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:12 +0000 From: Frank Li Date: Thu, 26 Sep 2024 18:07:47 -0400 Subject: [PATCH 1/2] PCI: Add enable_device() and disable_device() callbacks for bridges Message-Id: <20240926-imx95_lut-v1-1-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=2692; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=14hFnbXmRluLjGSiKRej/f7VpiNO+1DgtI8irwhuSwI=; b=lT+wylHwx8H3K95Ji3hWk8mu5rKX9pmIT5c/dl5aaueI8yWK29XEX5kC0v6wnGkr86Ga+GGe/ ++R1+SImQ5gAjJPybKk5SyrIsL1X5qcuEvQgKszPTO7wOWJhluhzQxD 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: imx@lists.linux.dev 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: 21db92c6-1f41-49a8-2dff-08dcde77b637 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?gnKC7llsOh+WZtMcHvMRCW3oINEZucV?= =?utf-8?q?p2O/hJytHbWp9SjIGceyhPsVzbpD4CtQjcbPmDRVDlyW6ukafSiIZsB8+kc9JiUYr?= =?utf-8?q?+HjP0uAuX7y8qcu0lhcb/IP35TQVnLnPO1MVkR6AxmiIwPWgSpI9B9SUsWKks3jKa?= =?utf-8?q?79GXes1EpNK7WeC6metRbdTNy59VktRJUbvpS7GxsRxShZ+aqAMPdPBBSjfTtYwuQ?= =?utf-8?q?EgtOKm06llOVYsyrV2t4aHkqh24qB0/6ArYDt7xlGIs0a/UJOuDgO20wkL7BuMjHC?= =?utf-8?q?jbXx3Q/lbgVAsgPy9mDkNJLh4sy6hSsbyZHWFdQqj3UmmA3p75jwwVXDRX0UGDGCD?= =?utf-8?q?QkpBjckANmMS8V2FOP0BuQIOPkd/OBHwt4k2rqTKDv6h/VWP9IQcrC9aFm4CrXtTb?= =?utf-8?q?5kxh3Am5yfknGdaWbpzfUgTqyOzpRLZuzdMh90muEk/WBEzueaI6Nkr+CALh8JXe1?= =?utf-8?q?EQ7dIM6kpUBFN9T68lRjvuhUcehvMgJaSI/kWKQCzG8nxWlRSAyl8UxzOM8Dn1LDq?= =?utf-8?q?PoggcKfTEgnpzqvpuCvOIqTISfpk7m8pg0xruWB+dgIEBSMKjI1FvJm3Z+vSscNvN?= =?utf-8?q?dzrtGLoA5t6p7K5/ibGgJ14jnMEAcmG8aQKSS1xZ4+nvNQQcZL5nLpzpTJrXJedBW?= =?utf-8?q?PDnKMem88xZSzNe8qjuXdwFbeUP8PeSFGuE0/FAclje66lzU8esH+dvmMNEWdt3nV?= =?utf-8?q?8d5w/rdrrxgr2OKbMYaMHvBM1ezj4tGlIfxeNRMwSH/WdSR3qV9b7E8aS3Gy2hCEP?= =?utf-8?q?dg3Dkmjoq5wdxLoGWRzwfwdNkMszjumpOwdxwc4Aa2LpS0Zp6tV8VWd79+gUpEM0t?= =?utf-8?q?Fk/gjsA5PujGERnzSJ5/lqDFP+7tKt48jwd7AL8u8475h0W1ZfeAJZlHKkTCWQhGV?= =?utf-8?q?DvLN82IJtGmC3aZgo+K6wls5Oq3O8RR/qJBZS+DErAequIgcKaFu2/3GhvGisZcU0?= =?utf-8?q?Iphg4SgQtudaBCxlXzVu0SiPBtDYpxViQQDd8yEmKzcWwF3jnkBiqPxb4TTpZ86XS?= =?utf-8?q?cV97peKks3shW5D6B3ffdm2VUz66hOcAKiHFdIlVuz6vMxrPYeAeQU18dlcsjxgDO?= =?utf-8?q?fdfOrKSTuJ4CgSEdP3T/9c6YLb5bIzXqXUNpqnsuVFX9SG2HwRiPoSO8D26/DpqT4?= =?utf-8?q?9H1DVKYCo/sPPEo5BahvwgMhwd2TGYYbpOy8uTPrVPZmdgWokHdiBZgySglUfSwFW?= =?utf-8?q?m+FFBC+R5GmFGCJ4h7M80RJnZvZxcfG9tk2ubvgmF/ZjwN9R3IEk7KramG5vuGIf8?= =?utf-8?q?DWkc/nHxt75yLlNHF7yZlDzx0oRo+Pv2PlM7f6bpg8p1gcB6HvCoV/oVxHz2j/HtI?= =?utf-8?q?AfE5WDO1OAS7wBXEboVxN/o5dddCqJi18XPLDpwf9pG+Au3CzVw6rtk=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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TcGl61CuaNwNO+Kvgtfe3xx8xblU2l?= =?utf-8?q?coqs++5UBIqNxyosWR0ZqlDHoNbFhBazMwAdpQJ+W/PJRqyIACKO4r5+RJU4tf4vP?= =?utf-8?q?x8ib9NOvmUkekkBU23NJTu3IbUZ1UCC5x+ow0Da1QK7kOFqP1uw6mw0kklw6q+vs2?= =?utf-8?q?5Q0s2VLlILy5NywthsFayRIMkz5QrfhSvAJJYBrFwIIbj0DQovy250+ivD/e6YwVs?= =?utf-8?q?xotDtZeBA6IzxPo/XxwaniuXrShX4jqgfvBW50iovdDjEcT6ct/sVVNCjGXlGlhUv?= =?utf-8?q?Hm8FcIOuOYWmHMnfJQoLsFiZuWx7j6I5jb4AATHoLD+G3gF1KvT3rrf0dCfUkS+wt?= =?utf-8?q?TIavn5N852jU0ParFDfOpmZ13yz0Rr6j+kv0Yvv9xYdbG3vHXHAKPglmvT2aypW5o?= =?utf-8?q?VN/sm7/Aplh/joa7J+i06Yh5L4YXeVPXeIaS3TFeHVL4rlVFMIDQNl3VAd+WoCPET?= =?utf-8?q?szII8rOpbr7t3iE6cuC2/XQjtTNFTdBtMWLz6Lqxv4Q3MYww7moIvz1HBOPtNwOHz?= =?utf-8?q?E7fSyaiO/jFnrPXbQR6KEnkCPT86xmhzDWKFONMDyeJCLjHx603CAU7hkuTYWw9ZG?= =?utf-8?q?8NVR/7lza7WO0FMeZXjTaI2vj5KgWLfQicOLL8SWFfFs6NhzDIy6yDg0=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21db92c6-1f41-49a8-2dff-08dcde77b637 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:12.0308 (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: Wg+XxoCfKRQarqpZ4s8aqk8/AwBLb0LWRugYzLovU2jDaS/+JbCI1guqX5wA6euI0MBsFMpmLaz43dhMTg4v2A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7408 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 --- drivers/pci/pci.c | 19 +++++++++++++++++++ include/linux/pci.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 7d85c04fbba2a..e0f83ed53d964 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2057,6 +2057,7 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars) { int err; struct pci_dev *bridge; + struct pci_bus *bus; u16 cmd; u8 pin; @@ -2068,6 +2069,15 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars) if (bridge) pcie_aspm_powersave_config_link(bridge); + bus = dev->bus; + while (bus) { + if (bus->ops->enable_device) + err = bus->ops->enable_device(bus, dev); + if (err) + return err; + bus = bus->parent; + } + err = pcibios_enable_device(dev, bars); if (err < 0) return err; @@ -2262,12 +2272,21 @@ void pci_disable_enabled_device(struct pci_dev *dev) */ void pci_disable_device(struct pci_dev *dev) { + struct pci_bus *bus; + dev_WARN_ONCE(&dev->dev, atomic_read(&dev->enable_cnt) <= 0, "disabling already-disabled device"); if (atomic_dec_return(&dev->enable_cnt) != 0) return; + bus = dev->bus; + while (bus) { + if (bus->ops->disable_device) + bus->ops->disable_device(bus, dev); + bus = bus->parent; + } + do_pci_disable_device(dev); dev->is_busmaster = 0; diff --git a/include/linux/pci.h b/include/linux/pci.h index 573b4c4c2be61..42c25b8efd538 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -803,6 +803,8 @@ static inline int pcibios_err_to_errno(int err) struct pci_ops { int (*add_bus)(struct pci_bus *bus); void (*remove_bus)(struct pci_bus *bus); + int (*enable_device)(struct pci_bus *bus, struct pci_dev *dev); + void (*disable_device)(struct pci_bus *bus, struct pci_dev *dev); void __iomem *(*map_bus)(struct pci_bus *bus, unsigned int devfn, int where); int (*read)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val); int (*write)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val); 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: 13813695 Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazon11011023.outbound.protection.outlook.com [52.101.65.23]) (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 5E8BA189F3C for ; Thu, 26 Sep 2024 22:08:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.65.23 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727388503; cv=fail; b=ON1vBJSZjLmrFco21z7dfDc9WmB7+MFt5wfKpxnVgvA2/Dlskcht0j8SwDugNyrAfUGyhPFtA3jaX1sIqnBQDjXL1gXtae3L33pTJj+/h+FL5SIeWwfqw6joeIEFQC1jex1tFnLHhMGiCHWrpN2G078rrEFClMFg8qayg4bnsM0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727388503; c=relaxed/simple; bh=ajAZyLgV+oZQd0uLwTR8EeTZ2PcQRwQ2YwA49Ppzjeg=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=thoSgFHd36nYfGt7ngotXhGPpllG4KvPnTKC4mWfC9SEZJQxkWZ120/KYwIumgiIQVXB/+82ecjHisSy4buDAiF2iYn1Nwlg89RzOsDx5A0AqaAEztYPIwNQEkEDP1GqJOXKAKsaHw5ky+U2C8dOQxepFZr1dIBdoemsRIGuDH8= 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.65.23 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: imx@lists.linux.dev 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/97SdtBio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1rsFPRZv81RWQZcbr1LDBB1kN1BXzkfIDRMe?= =?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?=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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,