From patchwork Tue Dec 10 22:48:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13902391 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2063.outbound.protection.outlook.com [40.107.22.63]) (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 A99051EE7DA; Tue, 10 Dec 2024 22:49:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733870963; cv=fail; b=mAfbohdc3/z560FtDawdaVq2qZzTryH1/4i47/hBToP3qngUGQgwkLD2rnU1lqsrgl1XTI264OOJCM6WIkY9+G9Xld7UWS6MSdJgVePrFN95PIHQglL5Xa4DhJmblQIvnB6iK81kdNcgkGbAseTsdM2GqmQLcWWyTru2cELpLS0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733870963; c=relaxed/simple; bh=HRvECFQA7StWB7pWk/IGaoQ4Bvx9a2u8BEJbLRBEmYc=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=HG6A3qyWhJua1SuTnSCLKmAdDImnZgQRe1aj4mDNjKjrkJBfhZh4b+Bo8O9ONJ/z/zoA+NoyERqeyIk/57y67rq9rgRb73X90zfpLoBg9fE55kx+uVTavhR7kaBugaWoWSQwsWbTsItB/ITDpIuFuzJjCdM2WAOEY3DvINjxI2k= 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=bVZGUtQB; arc=fail smtp.client-ip=40.107.22.63 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="bVZGUtQB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AcJyiUXoh2kymg2rHe6b5Y7lX5gbiIZiqh4CsG9lhpCEx4ow3x/uPafBzuZ/vi/93BM6AIZL4ngtxYAG9jaCQ7fqHFKvoZSqZRLLUQ98ePv8aJICbhxtR0tmtv7rK1VRVM9ryGxF2+21ecll4qneArGTztls+YESRZsTCJUSNyZ6PnI/46JSW05A1Y7a3eyC/lUsnnambCtuZq1Slzu3E01+YhSKmHvf0QYzA1xz4xdouOwV5mHskrb1fVEz83jce4RU+fsqAt17bMtPDC2KvB38uRyAVI2t3ZubHVTmFu762JW3ZIZvkgSxnPsvJcmhXEbsO20VLmrEfeyrQ0CdDw== 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=E7IKGdrjwj1RdTdGQ56GK0ia4qm/q9umJDVy+Eznp6A=; b=A/YuIIYjjnXX9NKbt3FjFt46jN1AGU3hmjPm64JihzP0XsxWqenimhJGgmCyfk9woJWune6bm2sZ83LuwGvU4tm8tmtyIesnsa2iTzAESJWaMfljv73SoHMXc54qSJVY/iBdYIFQ3EKPJQJAxJhLS+sumCicAMyQB65cUkGbXmosXCRyXBizYiM5xBQiB3UsUmvgmq9m7itkHNoLTS5ENWLij/JdvMiF6yKSZ4do/a61UqLH82K44ZBaMrup/ysmjv4uA+OTUIcLFXhEhEniOcjM6IYcZD0pau2bw2jv697pTSVmuPZp4bZ4ePLBtpXSnGnQjjcnWsa8TswrRR1vSA== 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=E7IKGdrjwj1RdTdGQ56GK0ia4qm/q9umJDVy+Eznp6A=; b=bVZGUtQBg/NIvr7/uWR0hc68DSRjMQA+RKZ9oyc3UG4RnfXeX1GU5pHkBCU/DAeGEtX3INsOYc57hN//z+2i8G1vSRgKJKAD8A3fFuRE5dl1nwBJsf3ooO+czUNItrjG8heqiNR8Vd+0KiLYse2YjcIcNlJYXe3vLxmInaS5lic3ivJI8+H7rf8H5gdxN4xDEsoQZv8NPyLTtMeg7pHsg7yFuFSHwV/dToI8jOaHnDbW6mTkEwYwGLm3QPuaJamh+tAeML4/tkXpAwXiJe9mtQOHG5DVvL1B32Nts+poxXcx3WO9Ehjd3Q4yerYILrgjRW3gvTrKjzJbTKrF9mY05A== 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 VI1PR04MB6784.eurprd04.prod.outlook.com (2603:10a6:803:13e::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Tue, 10 Dec 2024 22:49:19 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.8230.010; Tue, 10 Dec 2024 22:49:19 +0000 From: Frank Li Date: Tue, 10 Dec 2024 17:48:58 -0500 Subject: [PATCH v8 1/2] PCI: Add enable_device() and disable_device() callbacks for bridges Message-Id: <20241210-imx95_lut-v8-1-2e730b2e5fde@nxp.com> References: <20241210-imx95_lut-v8-0-2e730b2e5fde@nxp.com> In-Reply-To: <20241210-imx95_lut-v8-0-2e730b2e5fde@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, Robin Murphy , Marc Zyngier , Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1733870948; l=4347; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=HRvECFQA7StWB7pWk/IGaoQ4Bvx9a2u8BEJbLRBEmYc=; b=2dHOhD6AYxIFhpI9rhrCSVylul64jHTTKVtwVlC1m1h8Riy5dVxCbEzVSJo6NEKzplISAyhxh crS4db/POyBCV2ybZLILuQwkKEiGHayzmVm1Do9ZfXLpjLj6M5INhdD X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR05CA0020.namprd05.prod.outlook.com (2603:10b6:a03:c0::33) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|VI1PR04MB6784:EE_ X-MS-Office365-Filtering-Correlation-Id: 014e3707-9ed1-4644-0f7e-08dd196ce22a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024|7416014|52116014|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?X1u0wMl1QopHKBewb2ykdjF9ofnKaP9?= =?utf-8?q?mfJeD59ilAJ7tKrmc6pJfMf5zB21qwlcx8GcfYhhtMmHCkW4+Zf/9HLRNLVyMPtMl?= =?utf-8?q?vWzhJR2Jznfh6C2001tA5xv2ebK4+FiQhVMPovT73dQqOJObKxlaVjI8ALF47nTRE?= =?utf-8?q?VAlJebyiLdLUPfVsRalstCPRBKLXj1Dvr1SlfaY8GG+TCVFbvc+7hXsuCM1j95Gc2?= =?utf-8?q?Q/1mklx3jv3nTJUyhwwOABfY33YzR8dN7gQasHEHAGPkW3Uy8QkJPnfxadc/eju1l?= =?utf-8?q?15ql6TxCPBqbIfMWLD8ny+Vhm+Tjnkh5aaGQOmJGi9/IvqLoDnaA9gKa+p9zFIbd5?= =?utf-8?q?QBdpoeDbmOgOhw0aapW0SX/0qqz/Sw+QxF3Fu8RuuA0BxvSB2KvRyrp9mMyqhDiHA?= =?utf-8?q?xiX+XB66yqtcGCqbVxkWElCKGzfN5YIe+wpSWp/kRAy2pHQCP5/4mtYC+1DRweD2j?= =?utf-8?q?BDHEBpKldKPtxDHoV9N7fBQWlJoOp7UWjv9KbB0uyZU36xPa3zYo7fmegJ5sb98mX?= =?utf-8?q?B+wNZS96ma/hFmtIEbeQ3Y9K7hU4LhrUZpUEbUWY6Xkch9FsaS0Tr01Cjd4Arrqfe?= =?utf-8?q?zuBau8Mq0Z9819ATDifCUWxY4/34q8zfDSNYG7JyqqepkS+4spRQ8v+ur3X7c7Gwv?= =?utf-8?q?hJXoyy9tapxiKai8Kx9wvfVfSJRBouy+gn2ef/fH4mTYOs4/tN86CoMz7aF5xynMI?= =?utf-8?q?r9rYihet7gy64aP+mVzpOTNefMufvE/1YNh/i4RyARFQqr2ONyXEyEQSa98/qRfc0?= =?utf-8?q?ABHns7QaNO3w4hsVTZ5sVpS53vD8QyWMMipl1QrL3ZH9COtv2sh/yHAvCguZIMhF4?= =?utf-8?q?1sYE7jEjNLYNn0nDlu0DISJWBr1hk7rq8H4bJeXpaftcwKvZB/liLQC2hQg4f0nZN?= =?utf-8?q?JYyEjgt22NxPU1cABBZGKvuLnALgpe+hk+7bjbAWpVuHRwwByTANZV8nIYUA9QqTh?= =?utf-8?q?CCnsMWUM3JZbNJOF8cTvyLIOiMa387L7ZlvY2cyyXtClv66VENUNdNIGpRtMEqXRU?= =?utf-8?q?TwaFfaRjbod5w8YoP/ZIscANRvrIG3N0xkq890A3k5Q4PSBcwUIPK7xHGEhCC2eB+?= =?utf-8?q?PtlmGKuE1anmtIlwbzmbs7HLnlsib67nD5dDcqTdsj8mOIy3x3w7eL0jjSDrX0EO5?= =?utf-8?q?zjzN9SiKOTZjAILP4vQqS4KQDAq+T1yvhTA4eqoK/Nzy8XgoqYr7nJPl/HinltfcG?= =?utf-8?q?X7CRTQCcUJJUlN234tg1LEc6Qaff3oIuIWQhnbwtVnbsPTh8+dZXulwDmqfyK7gG+?= =?utf-8?q?q7Gj1wJUEPOoM2nAuom9ndV5bus8Da45DCFl6LSdrB+NY0BDFseu9RzPyiTpnQufJ?= =?utf-8?q?KU3ekv7JJ07j/5d0T8g3IinnFmAn6loJwKGHCwxkLrpqLUQyTB6b8i0=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)(366016)(376014)(1800799024)(7416014)(52116014)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount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?q?pmVv0JHp9aLfQHy2DEquOWyhtJveERybZWPiI50yGYlROLHuQTRKAztOYdkF7A2ZK?= =?utf-8?q?3slvCLlRh/cR9qdI47KrSCLekuO2fQX9XSEK+zW/blWRftNZrPHElaXU2uAERjXQw?= =?utf-8?q?0ahNpuMite8nGXba+4yc7srJyri7C9pRfBNU5UhKjaw6XlpGHIhkNhhiXlAY/favc?= =?utf-8?q?a4GDLSYbxUld1Dhevgn1NUD2+H7Ed8ekFd0/tFTl9J9HoLF5N9Sv4jHmrE6j2occB?= =?utf-8?q?oVvUk4bH0S0gRIibgLnsbj7vKqBMIfmL1qwDE/+oo6wG6PytYKlxm0sIePHj3tAWI?= =?utf-8?q?++iM0LOEe41gbWyDhWjCpoREr5J1pxMKzfqzAZJaBPRi9TQQAkA6SOa5uDMGlC3b0?= =?utf-8?q?BF0w7f1BOCUY20mxzNr4DvIWJIvugC7XoyaEOQDQYrCcIH9JW0O/MJGHHlx41WQ5V?= =?utf-8?q?koMN8iH7lXDXEdzwUtsPUFF8RgOYwfeLvTwFdmwka/fjfHuJuWYE24p3oMGyF+XH0?= =?utf-8?q?Bbsh1eB7wtnuif3sIguqleMv8NLMhQ0ilCyLkPhDHpppkXiLl6KYuHq56zq4p6424?= =?utf-8?q?1E17Ztu3oxT1W27W+BQwK3gTh+ZA3G8rt2YmG4XCROP6PPTeoOR8bNyaMINK1eKR/?= =?utf-8?q?9euzVZXSzxXQVYcNbLgdVmueW8Z+3Ts/LrUQJsiHUBYeo3BQP074lxpFfUJo33hA5?= =?utf-8?q?yPtiK6S3TG88?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 014e3707-9ed1-4644-0f7e-08dd196ce22a X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2024 22:49:19.8889 (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: AerULrSAY7tx0TBvFSli0gPM7aisS5C5s9+rwZ9ylpIh+eQxo76oDJtck5CrosmBbcnS1eT+Z/Updfa+EsapSQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6784 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. Reviewed-by: Marc Zyngier Tested-by: Marc Zyngier Acked-by: Manivannan Sadhasivam Signed-off-by: Frank Li --- Change from v6 to v8 - none Change from v5 to v6 - Add Marc testedby and Reviewed-by tag - Add Mani's acked tag 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 0b29ec6e8e5e2..773ca3cbd3221 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2059,6 +2059,28 @@ int __weak pcibios_enable_device(struct pci_dev *dev, int bars) return pci_enable_resources(dev, bars); } +static int pci_host_bridge_enable_device(struct pci_dev *dev) +{ + struct pci_host_bridge *host_bridge = pci_find_host_bridge(dev->bus); + int err; + + if (host_bridge && host_bridge->enable_device) { + err = 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 = 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; @@ -2074,9 +2096,13 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars) if (bridge) pcie_aspm_powersave_config_link(bridge); + err = pci_host_bridge_enable_device(dev); + if (err) + return err; + err = pcibios_enable_device(dev, bars); if (err < 0) - return err; + goto err_enable; pci_fixup_device(pci_fixup_enable, dev); if (dev->msi_enabled || dev->msix_enabled) @@ -2091,6 +2117,12 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars) } return 0; + +err_enable: + pci_host_bridge_disable_device(dev); + + return err; + } /** @@ -2274,6 +2306,8 @@ void pci_disable_device(struct pci_dev *dev) if (atomic_dec_return(&dev->enable_cnt) != 0) return; + pci_host_bridge_disable_device(dev); + do_pci_disable_device(dev); dev->is_busmaster = 0; diff --git a/include/linux/pci.h b/include/linux/pci.h index db9b47ce3eefd..bcbef004dd561 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -595,6 +595,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 */