From patchwork Tue Jan 14 20:37:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13939513 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2D7ACE77188 for ; Tue, 14 Jan 2025 20:44:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To: In-Reply-To:References:Message-Id:Content-Transfer-Encoding:Content-Type: Subject:Date:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=MmwAe2VoE8j+DJ0+j5VhBvk/btfBB1rp50/AKcSAkMc=; b=ZU0h9BeCyExiYshV3J9/iO58GP ANATAfh61MNtht2qtHiu+FTaGGwMrh7zkThFFebIa4I/D9rWWDlQfPx+/AGGc6ML7r3voRJy3+MCd XCrGPZ9rCkufhV5/iL5+jmb+qzMw9b21SH9fL/fW6GPydwz0hDpDzH7UMaep81sQKvHXJuYrbVuzD nL5tlXP5h6/q1jScf+DMBWdiF0iOCnVcsU8ex5xnHWuVh4Rc0wjxcuoYeDhHqMNhDWfw3KIs8POSo 0jDm0tfcuyOImBdXIIjg7r26c9r3irJDhFy4cO4Ro9jpDJgNhV9Dho0GVLdS1YbYVvmFP5V6puBSV tcR0gTpA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tXnmG-00000009iQB-0Y7m; Tue, 14 Jan 2025 20:44:44 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tXnfX-00000009hQ9-0FjX for linux-arm-kernel@bombadil.infradead.org; Tue, 14 Jan 2025 20:37:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=MIME-Version:Cc:To:In-Reply-To: References:Message-Id:Content-Transfer-Encoding:Content-Type:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=MmwAe2VoE8j+DJ0+j5VhBvk/btfBB1rp50/AKcSAkMc=; b=han6ujE5Sr7l9mRa1SHBWzQBhU zkso6lh6AOb9iYDzjFUpFaheCE4eSlUxaUHlMdH3ZakeGhBr2NqLpBXhPZ1K2nYSxqem80ZXk6WxV 1L/U+pFf1QkE5Mg0oSR8RXazKGJe8/KSeB4+6NCQ0PLUXUe/KwzesP55vhMG6MCH/EnIzEphzmyod vlV0r3YduA/Kcsax+HCyB+1NLus9cjNNMHLM1rQAFYCXxUoUie6VfjAq0Ayl04YghtXg2xhk8dxpf nD5yUbsbWqo8G3BPR/h568X4HAUqAWvdCdvs3JyyQ+Zgv8fK2z6wBpphvmm1BOJvGUGFbS9V1Wesv AdJYVEZw==; Received: from mail-am6eur05on2061c.outbound.protection.outlook.com ([2a01:111:f403:2612::61c] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tXnfQ-0000000AcLE-3ojb for linux-arm-kernel@lists.infradead.org; Tue, 14 Jan 2025 20:37:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AsMwesqljd9IP1SfiOxC82sUQPiy2gZEB52pYCeGsM/S8t2LJRAmcOPT4LvDBsnJM6Kjdx9dB1LlDAd0x7Y5um1BtFHzBfsjYgeMXsRU5xDuBIxeQL95Qa1DDG4YHVb/SdDjHXBkUmiaLUZdKpz6xas8SGn43DqHEh+rfHzbywGIkFDR//bnQsaud6L2TSdGcso1iJQJoj0Pkxebp+2xlI7Iucvguyjoln2qfR0I8cFj+fkCrqTnlzQJmna7/qi5tZ1KMw2bQBTp1QF04W9RRnwjmFYbWJ8HVrIlI/lCE5hJy+B6Hq+q/hvknncya77tEs4ikj/poz2kAJ2yRLu4qQ== 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=MmwAe2VoE8j+DJ0+j5VhBvk/btfBB1rp50/AKcSAkMc=; b=ZCowjRa4ozY9ernEIZ4NzfXQzRDG9kbrmJNYNjf67TN11tVXoFXgcGSAZ10CdK1CYy/5NfwOOADllM8IYcinQZCpzbfoi4cJA8Wrcg+a7NUW5ChguLssx2+fXqH2Nzahu0FyHBOLTUxGJdMcIbZSxzT8aLxmaiAj2lVY4wnKnxWIWekhuiE69AfJkFv+sKanQMGM0FpGBFc7b2RX0jeYfJ7ubpTB6T1+p5yta+tt6Cu8zUnhHHMln6/WLOyOc0mk67Di0UuSkK652b6DKlm+88lRTnYya+1VUX6l5HYmgxdoHXsOxmKVMR4vkCXyC7fG398jJruYBcnIFnXLgfsutg== 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=MmwAe2VoE8j+DJ0+j5VhBvk/btfBB1rp50/AKcSAkMc=; b=nTJuLZeT0j2aEK+/cPA9wHkjuM5qxWkQ9FrcrBMpuN4m0iExogWgM6tlOrjGye6rn0mu9sLJwa3v9UJC/eC11KnDvI7uBia37tpA0bqcnELsQNWPbvI6fvUQaCqcZi3qSaJtN7OVY9cogpKtfO7xaJgm9p3tY4G5IS8Z5gI57ue6gXSoqIFEzb8jZmSGPaZgnfpWmY6wTFxTO5qY4ITNMcBJw7YX8ulh2JrPv9c5ItmUqjZE0Yz3did++2KUwiytCc0TSnd3AlnayO94oUyRyIF11FqWV/Bg7lOcnC9sd2Caa9dwfAijmcDqbI8eKF8dvinfkF6GV8UJ65m5E9QQFg== 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 PA2PR04MB10374.eurprd04.prod.outlook.com (2603:10a6:102:41e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.18; Tue, 14 Jan 2025 20:37:35 +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.8335.017; Tue, 14 Jan 2025 20:37:35 +0000 From: Frank Li Date: Tue, 14 Jan 2025 15:37:08 -0500 Subject: [PATCH v9 1/2] PCI: Add enable_device() and disable_device() callbacks for bridges Message-Id: <20250114-imx95_lut-v9-1-39f58dbed03a@nxp.com> References: <20250114-imx95_lut-v9-0-39f58dbed03a@nxp.com> In-Reply-To: <20250114-imx95_lut-v9-0-39f58dbed03a@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=1736887043; l=4347; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=oum1+Vq6vj4Bu6UlAhpzm57t9Jq7KQ1Jox+WAf+lq3U=; b=mgIeM9Sf2r3Rie8MioZgjmvW+QYs6fo6ShswYKJ8QuAUAlfhxumk9lw1CIGnlns01dXjekk8E IBITebUmZkxCxRTL74Zzi6FO2/NFeEOhesFVs/fizslKPj2MhkJJh9W X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY5PR17CA0022.namprd17.prod.outlook.com (2603:10b6:a03:1b8::35) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PA2PR04MB10374:EE_ X-MS-Office365-Filtering-Correlation-Id: 5084e7f7-4b7c-4178-0b49-08dd34db4746 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|7416014|376014|1800799024|366016|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?RHKpVoLYyJ3QocGU9CHmkcCcfWMRkF1?= =?utf-8?q?QxdJTK/8QGmraToGHWjxwh8AnQOWSbHwbiu/6SkcWLmnToa/dam0rkeDxuKq8YOcO?= =?utf-8?q?ISrYwehLsaSZdynaW6vDc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WSMC7B9xszFXuFgEATWlIPpeg5oI9vWdqBCiPDNrwUm5bPydKT+kyo?= =?utf-8?q?9aMSshDlFOcVuMGcGFLb1iC549oGbxHxoBBS5Enyr143Fuf4Qbk/CjmG8iE0YR/3E?= =?utf-8?q?ghp/Uco62qA5UHgTMoaCkgnd9JpxRKwfjhySReW3dJ0Z4Gchza/zfpvvk1bO2edD8?= =?utf-8?q?TPHwchyQ8Zkj8l2rsfSr2Ay1mmiShk6E2GkOX8B2sZISHg8pvXCB07UoGNsk7WWuN?= =?utf-8?q?sqXYkABgDgX6GJeGWE1x5v9z5+14RmTkMmoiVPh2GIOa0U5aIXJzrABHhjqbMIFp0?= =?utf-8?q?3YHNKbSCoPIdlTj3vYeqcl0Tm7uMZQgMimmXvCQXkcvH6Zsc2XXiWdjdEZf3VbOCU?= =?utf-8?q?UIxD8H3G3wRX09PxUNQfNL7oxO7oS+pK6qJzL5g8UbtFhy0ZUeGEQbK5IMV+uTIdp?= =?utf-8?q?AjyaLzC3zF08vQIRnnNzShl1ob/uxNpnw=3D=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)(52116014)(7416014)(376014)(1800799024)(366016)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?x+Y1CbP7Slw3llfwk2o4Uei3U4eJ?= =?utf-8?q?fvwLOYCrGLdSI7gR7KA7Qdy3bl1oEkW5L9UfrsGZTo2ryyHzUxM2LcBgkm3D1dZfL?= =?utf-8?q?+feR+Sb14ezRS0usWpqIOTq6diePMMGCpEMUUhX8cUs3oxA348X45BifbgE1wnEN9?= =?utf-8?q?XErECU5rJKD0kldBPM1M51/olA+nFnnW+paet+MqwlT5Pz+Po/nptn4qvBgUsrNmr?=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f-8?q?0ZQ7SNTNXOROiuGXTOFo9Ok2bx86YroL/Fz3p2vUWfwHD1J2Op/118eR8z/6ZUa15?= =?utf-8?q?PfORkNmmd/ottsqmYlWFvB//F0RD53x/7PSz5xn17jBTOT/v6VfEjZfgBpmDqgxBN?= =?utf-8?q?tFhEKgWVC7HSB+g3FgC9xSh4c6Y0BIzX8aqEomo2BAdW7PgMeFgwL1ExN6iJLuRbq?= =?utf-8?q?d8s6m3EIvtWjmAcfHES8dUxxBCdE/9S9a94m9276ke+DjlhLBuBmnLQr/5xt8qwej?= =?utf-8?q?JViOdfUtk7A95c8NwPV+TdGlq5AW9W4rZkiwH7yZVIR53VU23rhSASqwhgCXcm0+b?= =?utf-8?q?Q6nqj9PDrKxS15t6RjayJMPvnIFRDOSIWvdiN9eCGMssUGL4NRKH3m3yQHFLjY8wZ?= =?utf-8?q?dmjDI1vjNCntNJVvIgqyUPSjIaAon8dnndjMp39zUoqhJE7oV7ZlY9ux7G7C+Blht?= =?utf-8?q?toTR3hDSvBGf?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5084e7f7-4b7c-4178-0b49-08dd34db4746 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jan 2025 20:37:35.5641 (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: 7URkDMnekgg85S444dkmnqnUL2hlZBAXKYNPQgQn8kHruiLHipFmxHXscYeRycQvuSNft4qYsR2Rnjkz31zAbA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA2PR04MB10374 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250114_203742_666537_C5F220D9 X-CRM114-Status: GOOD ( 20.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 v9 - 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 */