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);