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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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 */