From patchwork Tue Jan 28 22:07:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13953230 Received: from OSPPR02CU001.outbound.protection.outlook.com (mail-norwayeastazon11013024.outbound.protection.outlook.com [40.107.159.24]) (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 B63DD19755B for ; Tue, 28 Jan 2025 22:08:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.159.24 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738102122; cv=fail; b=W0bLFlo2h8+NMfzpFK98mzsaQcsIB7NbaGlo818Pc79wZ9YGi0xa3z09SdLQATurUEfoQZlUHpkrjWJJ6lL5VYgEKXPU/Fyb11jSC5KGw8Pg7YmuV3Jcot/6R6x6bQBqY2BuPMPH/KIqxKqm8w4sbMK97GxbArVvW0/pxx3L6JM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738102122; c=relaxed/simple; bh=xDd9TefF0lK4uHkh/J6G2tkWLfne0/VQDc21sWcAiYg=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=oLLfmT1RwJkD1GWVqhZY03uIyB2ZaT45/pD3YeOS8qdwuBnnpEtUBa/mDQVS/SDRPH9RhCQq+6cpWmH/YBc8fe03Fa2ApT/OSf2ZEXgpRgXzs1YsYjF9DXagm7sLfhXzZwCLT42suUXhjZTdaST7zDUAw3bnWSY7RK2DV9kYGdc= 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=HcHUwzww; arc=fail smtp.client-ip=40.107.159.24 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="HcHUwzww" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NliEYE8On6GVsrvdhj0BnnmX6pXumHqk5ABYUDeTBvOgup+pMfcX1/vxyvMpNTY+TlDiYh/PTF4/9azrcEobCkO4GY5CxPTQDdcTuKULn66GCoA+/0G429J//Ig2w0GvJ5J4u/6H/3UhcI/+JVRtJ5XUfThchrJWRADoQZbpHzsP08Mt/uThVkPtxgWqg0khDAT8lTlbVKNXAq9CXhq4VX2CZwCWlJtI0FiMfiR0C4HcG6fP5KH6jbtyqe9nFHB4EvcfpLWwjAWzV632B2jSScbAWLSedPPdVElanTkXbwcDDza6577yB3PgEzSycSGhZMvHGse462v3Sd8rtPqmrg== 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=5TzfpaF1gM/sUK/g+VlPeyqOC46cDtlQN6XZqFyFtYM=; b=ePCmgbRcJOQgY9ynGWiwHwRLcDHSzh4GlQPdfMamr/LHa4aLdcZb+S9fqCINEC6eqi/ONikf9SNRCgXC8uBynWBL6yIWDyJ9zSoRTQixiRQ64Q/IWhC0kc7yLmKsBCCHlKAjR/ALSmYvbiAYFyPwoIPjCAbbYxSgUF5huW1eJt2fqy2uls1W9xgAyEQJZak8Mm/j9I2KjwWBcWSOdvo39HTKQ6BLbsQpdRB2KjAtb2im4rE2GDJyLoN0Xg8s0Zdb2wij1Pgxj9KmJklV+6ITe7CFYEbyIAqx+4w2s7we0Iwh/cWhuapDzGZUjBFIdLyNbv0IIOQpnpDmnvBrTmHNcg== 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=5TzfpaF1gM/sUK/g+VlPeyqOC46cDtlQN6XZqFyFtYM=; b=HcHUwzwwm8BicdEIXy6FNFdF3aNUDzUEcE3/nB1md/c9OftdYI5+1F1j/exO2dE+6usDR8PqrgsNnrUE7w82n2qtAH8KRB5uUbHtZU/QWT6nXRKxPDr7nNYFWSEe3gWeAQWfZNQ5beyLUJr/XEFlvX1kTTcByIolHZW/vpNlC1MxcqWaQpdkvRBWFbOU03xOsm0nLLWPkCnq1ddazYwfMC4JyF44ixg/iS631kLImk2YK0Zh/GwGQXAH6hyDMTrtcIthBJ5r18KEs0KkFJwOdgQ278xAyN6pXTTek067gDcU/7SC9GbY+W9hS192eeNCJUAJmZ8aWrdH2a/oqlLVYQ== 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 AM9PR04MB8555.eurprd04.prod.outlook.com (2603:10a6:20b:436::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8398.18; Tue, 28 Jan 2025 22:08:38 +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.8377.021; Tue, 28 Jan 2025 22:08:38 +0000 From: Frank Li Date: Tue, 28 Jan 2025 17:07:36 -0500 Subject: [PATCH v9 3/7] PCI: Add parent_bus_offset to resource_entry Message-Id: <20250128-pci_fixup_addr-v9-3-3c4bb506f665@nxp.com> References: <20250128-pci_fixup_addr-v9-0-3c4bb506f665@nxp.com> In-Reply-To: <20250128-pci_fixup_addr-v9-0-3c4bb506f665@nxp.com> To: Rob Herring , Saravana Kannan , Jingoo Han , Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Bjorn Helgaas , Richard Zhu , Lucas Stach , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev, Niklas Cassel , Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1738102099; l=4272; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=xDd9TefF0lK4uHkh/J6G2tkWLfne0/VQDc21sWcAiYg=; b=x6rEXtYPQr2iyX+EHkUdtEriWbrtkBn6bQMQThrD1Y4xW/dZS2Jo1ZjuzUQBJYyUrZ/falMcS UUK34NX510PCcJDKfZD4xhQ8E6gehk6Hg2FtuetDDt8mvBLoKNvvlxx X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR03CA0130.namprd03.prod.outlook.com (2603:10b6:a03:33c::15) 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_|AM9PR04MB8555:EE_ X-MS-Office365-Filtering-Correlation-Id: 3177cf8b-9858-425c-1b1a-08dd3fe8517a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|7416014|376014|52116014|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?YhNXTgKo0RATYuNR7do1BM7CrJvFmNB?= =?utf-8?q?nBcI0xnsOlpnKPO2WzmdOx4aLoQyhnw9onGmB9IEt+LNkTzZ6e6iKcgV1IcdmMRk8?= =?utf-8?q?bUGheSnkRNmWd1bJkN9Y0guw5RlNWPCRppXncwFKw5kGaSYiuOcAM5E9DrntkGZTR?= =?utf-8?q?j1QudWYddKnbktLK6lfwDD6sXyQzeBZ04u+m4O5OWTnlMDzOWHm5fSASxDREtOoGK?= =?utf-8?q?7ckx316H5ao4t2hsboRCXhRAzl9bJX4wvy/JuTaB6+ChafhHPUuRnCwqEes+C+6n8?= =?utf-8?q?KLYwOVA19fe6aXmfUpiztVqGziVKjwetZgJK3w/5YgxJjR4uKyTv89NZpEEf4RzG4?= =?utf-8?q?LbYMPRad8UWcxsuk6TPijfqiK5hTzm/62ypfW4ErA4tUQEHrLe8Ui0dtyWtatK9Rh?= =?utf-8?q?oN5DmhcyciYqIWk2USrL1BST1HYmoCjp0ppJYbK3eBiQ8eUTMK1PHW9kzJAu7nFvt?= =?utf-8?q?pm0LhAcvkttNxN4C6fwOLucibrIoNuPVm8nJQzHMvfMZBMwd+zXyaa/AJMgn7HeO2?= =?utf-8?q?pfGne2WMOsB5hzjgCreQ3xNtaTOiZBFVF3kgRB8QKJtJP/7Ydewh7iQWhDZqkWivL?= =?utf-8?q?x29TUwyBcrueNv6gOMDuaca19X6cthGWRxE8hg+7T1m199Lntq+TItygMa+z+K1VB?= =?utf-8?q?QKZWFUwVTJTCba/N9ioi0IvE2eDt73KZa1d5gYgdBTqAfbqmYgoeiJvF0rSueIef/?= =?utf-8?q?8MXGQg0WQJ8k571X0Kgo/bxns/Vei4HPEK0O3u0BIby59Mzm2/RYgznb+llRW1pxT?= =?utf-8?q?2q6jMRAEwU+9wX0iq1uqixK45E0aDHlY6icTgZvEqSpIRuuL7VBv7AjMSNlQVkRqY?= =?utf-8?q?Y6ddykWA1cFlvdIK0GOAaP9RHepsMkTP5NKbua6JChT2tkYCeQb1IP6h9AGEhpB0O?= =?utf-8?q?pi/XxnoYPdaSOXowZBQX2xidXDU5qB4bQEAi2QLLr/K7dL7Aj/H4M8HBNFBe4/pzr?= =?utf-8?q?GJCR6A4+ovbUREw0lbNUAx0wQv8J4rZL9061s6inL7/GbGpoyeDhLx6Ma9I2bXzVw?= =?utf-8?q?0HHfBBp9dtYNVTM1uXOdIAF5Gh/u87WIHPhThU+Rgl91jCnNx5fnccEwjPtHeZVI1?= =?utf-8?q?tHkApJmDGCR70Durt8hyGZ4dL3AFVxhehqpoQeIS+NUnabqfx6e24a8Aq8m1en5Gv?= =?utf-8?q?+JO/BR2OMWhFE2un6bZ2rEAxlzB7//YjKrninzxlc2laAZTnAS75wUVCDpR5aUofG?= =?utf-8?q?qQDW3Z0vJeI6dZ1Rwqqm/dJ0hwMXcUFrBhaIy1ag6cD5dog4TTRgqFbUvcvcossI4?= =?utf-8?q?W6N7qAmppW9KBhbSdB3yfTI+gbr8A1vvpDrxbSyi0d2e8EIJlhAB/4TujCH3hBw27?= =?utf-8?q?50NveQ/3pl4D3EPHQw2PJq72pY+qQnh25YPRmSs3MEIyaJqb6N6inYUgVvQmNSyOc?= =?utf-8?q?LFHa7mk9DwFFntzMmyJGJhgr6tahCILuA=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)(1800799024)(366016)(7416014)(376014)(52116014)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?klMVNo8Q57WMThr68KPPoQNN+JN1?= =?utf-8?q?JzxYbK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upChhOOWfDGTzk6F97MQ6/6ny9qG8QxjgTtERuYDkWOjv4GkQpDGkPDCh7clkH?= =?utf-8?q?FHGdcmaXpzBi/CpZDWBb0WbkVp9dVWt12r+aZD0D844DnLTueVNBQF+vzzzuahusZ?= =?utf-8?q?gzDcuFkgNS77toOMNxksbOnfbtnWMpyTMzbEQT+MX8SLxsOIx7YLbBXrswOv4dhcx?= =?utf-8?q?P6bU5a9TQgoo0hNC3FQPyAOsRWqC72XBaLevSAGf4KLJgy2Cco6F+WxmoW5PUYttk?= =?utf-8?q?HMj834XavMKsyP1YOiW7j/FibfWn6qv1r8tjDcf/kwY841IomELEaSn1Y0RJd6IUK?= =?utf-8?q?QXW0dl/noai8jyHN/9r+muihwrVAgu1OCG+8LXcJ/UCKZRDcW7bdjFg05+aqBxX1s?= =?utf-8?q?X/kbqMTUhSyyE5Q2gDo3THgOEgvJVQHGPt6z+y+SgWF6wU58I0S24NtFI4QwTb2WR?= =?utf-8?q?hDY1rC+7RDOyDcuO6zp668j5gMfp6j1ssQTYnc7Y8rq4ylT1Qp+ua8c9gG10to/+S?= =?utf-8?q?aNoXqqvkEo1s5qxDhdaix7rqwmH7ewVeCyO86KhqdN0o1E4I+FDZxQnig8GkY8ZrH?= =?utf-8?q?3qtLvR9o+bh2YLCfaq5k6c+Cwg6FbHkwJuEU94j59+69l9uC3oFF9SBaqLcoOxZ3v?= =?utf-8?q?Yv9QpjKW+dUr?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3177cf8b-9858-425c-1b1a-08dd3fe8517a X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2025 22:08:38.9330 (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: G6ieKBKCWDgoQWQBsqpf4tEVJrYjdEYfn2xU+pNHh72ShLb0fww8FlFSJGkfUcXXSxE6jlV48/4vU9fxC1DvXQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8555 Introduce `parent_bus_offset` in `resource_entry` and a new API, `pci_add_resource_parent_bus_offset()`, to provide necessary information for PCI controllers with address translation units. Typical PCI data flow involves: CPU (CPU address) -> Bus Fabric (Intermediate address) -> PCI Controller (PCI bus address) -> PCI Bus. While most bus fabrics preserve address consistency, some modify addresses to intermediate values. The `parent_bus_offset` enables PCI controllers to translate these intermediate addresses correctly to PCI bus addresses. Pave the road to remove hardcoded cpu_addr_fixup() and similar patterns in PCI controller drivers. Signed-off-by: Frank Li --- change from v9 to v10 - new patch --- drivers/pci/bus.c | 11 +++++++++-- drivers/pci/of.c | 12 +++++++++++- include/linux/pci.h | 2 ++ include/linux/resource_ext.h | 1 + 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 98910bc0fcc4e..52e88c391e256 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -31,8 +31,8 @@ struct pci_bus_resource { struct resource *res; }; -void pci_add_resource_offset(struct list_head *resources, struct resource *res, - resource_size_t offset) +void pci_add_resource_parent_bus_offset(struct list_head *resources, struct resource *res, + resource_size_t offset, resource_size_t parent_bus_offset) { struct resource_entry *entry; @@ -43,8 +43,15 @@ void pci_add_resource_offset(struct list_head *resources, struct resource *res, } entry->offset = offset; + entry->parent_bus_offset = parent_bus_offset; resource_list_add_tail(entry, resources); } + +void pci_add_resource_offset(struct list_head *resources, struct resource *res, + resource_size_t offset) +{ + pci_add_resource_parent_bus_offset(resources, res, offset, 0); +} EXPORT_SYMBOL(pci_add_resource_offset); void pci_add_resource(struct list_head *resources, struct resource *res) diff --git a/drivers/pci/of.c b/drivers/pci/of.c index 7a806f5c0d201..aa4a2e266c55e 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -402,7 +402,17 @@ static int devm_of_pci_get_host_bridge_resources(struct device *dev, res->flags &= ~IORESOURCE_MEM_64; } - pci_add_resource_offset(resources, res, res->start - range.pci_addr); + /* + * IORESOURCE_IO res->start is io space start address. + * IORESOURCE_MEM res->start is cpu start address, which is the + * same as range.cpu_addr. + * + * Use (range.cpu_addr - range.parent_bus_addr) to align both + * IO and MEM's parent_bus_offset always offset to cpu address. + */ + + pci_add_resource_parent_bus_offset(resources, res, res->start - range.pci_addr, + range.cpu_addr - range.parent_bus_addr); } /* Check for dma-ranges property */ diff --git a/include/linux/pci.h b/include/linux/pci.h index 47b31ad724fa5..0d7e67b47be47 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1510,6 +1510,8 @@ static inline void pci_release_config_region(struct pci_dev *pdev, void pci_add_resource(struct list_head *resources, struct resource *res); void pci_add_resource_offset(struct list_head *resources, struct resource *res, resource_size_t offset); +void pci_add_resource_parent_bus_offset(struct list_head *resources, struct resource *res, + resource_size_t offset, resource_size_t parent_bus_offset); void pci_free_resource_list(struct list_head *resources); void pci_bus_add_resource(struct pci_bus *bus, struct resource *res); struct resource *pci_bus_resource_n(const struct pci_bus *bus, int n); diff --git a/include/linux/resource_ext.h b/include/linux/resource_ext.h index ff0339df56afc..b6ec6cc318203 100644 --- a/include/linux/resource_ext.h +++ b/include/linux/resource_ext.h @@ -24,6 +24,7 @@ struct resource_entry { struct list_head node; struct resource *res; /* In master (CPU) address space */ resource_size_t offset; /* Translation offset for bridge */ + resource_size_t parent_bus_offset; /* Parent bus address offset for bridge */ struct resource __res; /* Default storage for res */ };