From patchwork Tue Oct 29 16:36:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13855151 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2062.outbound.protection.outlook.com [40.107.20.62]) (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 EAB941D3644 for ; Tue, 29 Oct 2024 16:36:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730219823; cv=fail; b=GsMhsQjTDF+mOQSFHUrbGCIEUbOGxb6VyyYvsbcOGMh6pBLbhHAF7IX+E+6rk80zJXiJghR+pTCMZ/T+UFBMYuuLgxDjIs4+4oWMdQLmnaEtiKpKPCKBKfiXZiSjEAO+04SaWRAKPLB+O6hsqZ35C7ynvVDaUlCzCCJdayJah1o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730219823; c=relaxed/simple; bh=iJ6/KG8KKdayrGbVtcslMDA3WnqF1vdb/oRmxj7ytWo=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=SscoE+K906WvvRxf+Zv3Ol58NITgM36cuBjZdiqog5I7QvbAfT4pV7eqIO7y1iNTnciCsUq2dL1vPCf0jZaW9v934N6CG1Lp0ZE5nBv0RKlPP2skDV8ZZ392bgnhgL6TV4g/CxRunPw+hZfjNTbEnf+KGfKPEdq4YTPhfR8u+zs= 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=Nd2zkdWd; arc=fail smtp.client-ip=40.107.20.62 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="Nd2zkdWd" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=no2EibCM2q/PwFQZnjfCZ3uyDf6xmybAfevqnKeTxodDeUtfrffCAs3wZvCz2K/HH16tb7Un+Co8awAt/8R22JHQTh6FDKUrCTpbEA9dC/jym4Pgt21cxu2DEYun/pbidRYWuv3JoP4kGMnRN2BwN+mxEcutMRiJtrbJUHTGfHVuquC6//63KQ7I1zZ4L4M5NWy7v1OUuMbE1DOgdMzS7fj/AhWcBtIqIKI+XgtfBuW8SZlunv1VqsD7CKsZICI35hMP4Ix3Hwfxm6mhqH37ytACzMsQabtFu1BoRkXJFyRFMwkr2WY4AAxd+4J66hVXxFsWQtYLbsLoltyhm8ry6g== 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=L/VhIsVSTv0d5u3ZhfKuu8Af1yUZKW5mR3qA1hzH6eg=; b=WPRJyaZUmUorQXf2OnX1OyD6XK6Mvne36sZzhlij18w16epGGn+NHfA+BKVeIJzN5sD6hjnhJGe+d6TglFWI1UlRGOzp6+LOtDUbhWpoGVpvt0d57AzFF0m55iG4RkbNGLTOSvHWbE90iFkg2KKa2j+ZIEE4JMtiT/F/s+p7Gxz6WIXa2CyQPMMCvv9/Z/8CKGZkdgEEowjX4VlHV5sSCuU5fnBo/x+LmwowE/VATj1XBX0pcZLLLFkErhwPpE94793kbn1UYghn4BkqV39D8byOHR4b8u+UDJxCK2eGRcAznlq3q4UI9Ja0R1aqpTbRb3Mdv4RoUl2Wwb+iIOqlQg== 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=L/VhIsVSTv0d5u3ZhfKuu8Af1yUZKW5mR3qA1hzH6eg=; b=Nd2zkdWdRTuQGfjT+aW3/ESI+sIPPEkLzBwsYc1BL/aNkozNm6FocIHJj4rz7EkAo9MiW6ejMMwjp+PICGnMqYpyFBXluZmzAQeoUZCzPa3Klm0ylvFhZg/gevB0M+B9VS8PyKJJBQ34h419XitOndcNgpKq+ZOtR0a7NCRz9AQz+V2lXOF7JifB4oQmwOLVJM5LKXJ9/CDj/+KC2hz0eSoL0SGBC8u+WZMYdvRpUefIgp4cxJSmeJoXj60u841/8StdfOXnN47GhS327Y4poLNTHMe7/IM+udHco8Z4CBsfFD2zAVc6lr/LblYx3zMTAy13B3tgtD9K+UT2XwmZuQ== 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 DBBPR04MB7577.eurprd04.prod.outlook.com (2603:10a6:10:206::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Tue, 29 Oct 2024 16:36:58 +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.8093.027; Tue, 29 Oct 2024 16:36:58 +0000 From: Frank Li Date: Tue, 29 Oct 2024 12:36:35 -0400 Subject: [PATCH v7 2/7] PCI: dwc: Using parent_bus_addr in of_range to eliminate cpu_addr_fixup() Message-Id: <20241029-pci_fixup_addr-v7-2-8310dc24fb7c@nxp.com> References: <20241029-pci_fixup_addr-v7-0-8310dc24fb7c@nxp.com> In-Reply-To: <20241029-pci_fixup_addr-v7-0-8310dc24fb7c@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, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1730219803; l=7546; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=iJ6/KG8KKdayrGbVtcslMDA3WnqF1vdb/oRmxj7ytWo=; b=/jyC1OwyX6tQ2kmRI4ZCCYPxvzLkz0MGYm4a0Brx5F1Kkn8GhdcAtbdlD06qrkdD0LTIsD2uo OBcTNM26FD1BCYGNjWDZyfWNRxIg2plSPnneyymPTKZvICtRsXJwVDO X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY5PR13CA0035.namprd13.prod.outlook.com (2603:10b6:a03:180::48) To DB9PR04MB9626.eurprd04.prod.outlook.com (2603:10a6:10:309::18) 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_|DBBPR04MB7577:EE_ X-MS-Office365-Filtering-Correlation-Id: 85cc176b-3eb8-4586-3f14-08dcf837e7bd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|7416014|52116014|376014|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Yx0o28YwqKaC4XSsjCmF6fBfBBqxy6e?= =?utf-8?q?lJgkHbyT6QnQvltOa/4lqOrYgfluUvjhZBYoyoCHCEdidQzp09uMkU7+vvMaaVdcJ?= =?utf-8?q?ENLPvAErHvNaDXca01XZcS97zRQ/yJ7b2AaSHODjjz3ZIWHFU+QYgt/WvjxiVQE2H?= =?utf-8?q?llLjgnSESwFvfyLA3FJj3DV5Y6l6fZ1xaRdez4Pi35C40jiKEHwsTMIHrpHbJ4RUy?= =?utf-8?q?k8owXSkO+WNBH8WyIVcYCJM6G4yRG3LmVbxIGjiZe7hvbzUVbnKFWqPhKv6cpWZ1i?= =?utf-8?q?KMklWlDzj4hwWx2aFELpbDf4XOTdz0ipXkF1Dz+5GHcG0EdO2orOBqhfezJOHKN1F?= =?utf-8?q?cLkTWdRLfpKIFk7Z2yaAYHPNFLSvxsABqls2vxJda8L/gu3YUPcO7SYwgjRAajvc/?= =?utf-8?q?rB7RTemwhw9puYOguWDCNO+DGCSgqhOsPlNHKy7krCfqLREzMKYQC7/hZEkTp2mmd?= =?utf-8?q?60rm0C1D4/rcNAZA5YSJvwWihFLYawqEbLEXa06lhmfu3ThZjEbGg+koU0kdtwni6?= =?utf-8?q?h51SijzZnK4NM0LrLCOciQeziGnyMFQtH6q2XnvpPl9OT6rzFBTHZcP8+Z1laijLZ?= =?utf-8?q?cv9BySrU56gK9sn2CR8ppSIk0yREXzWDKTViJDSM1oPy5lRyU8AmNfPymyWRjVLN2?= =?utf-8?q?wABnbAUOLVJPcQEny9hFRvqfr3ft/yVB1kvYcbxJsfJnraM56vRCS/iiopHWNJEip?= =?utf-8?q?3Kw38/7UHCfTsRCpEku/zIIO8lSmiuR+V87S9TQsXriox3FdGYy5BNRlEscsA4EQH?= =?utf-8?q?YTUtMSctskUJOmLYIOradiZk1HDTg3WciIgiv3wKMDvfWWShB0olfckmNTotxUmak?= =?utf-8?q?tfDRFEEUkTUGauPmAHmWYhiMv+Ut84MGlKYajxHrGy//bLoz/vMrmB49u19uru4Se?= =?utf-8?q?H6Bqlevo2Cafgv8SDy7RewIdYzkRFs0Q9Y6LG2pmucRKvCL27sdIWvDnILx3G/+eW?= =?utf-8?q?P97kj7QF79neLMhOpWwGKueVq9YKDkoN3VVDoyb5em6HPh0GDIS85ZuNmDa8/AFOP?= =?utf-8?q?T3AwzK72GV45ZuhqaqnxwJowoyiGc6zAfTAyUBT+WnD1OVagieT5RYhUNBqZfEfsz?= =?utf-8?q?efgmKmuzdNMWE/ahN2XeuFqpOxVbCHhZdL88fDb2nTZ01V3TTnESc2rI5kK9bqvwa?= =?utf-8?q?OLtXg2JDo/FBj88PrBVnJHQlJAYcgchLjWILKTo2GhaGm7jxVekTc2oWSVkJsyBMM?= =?utf-8?q?V1vi3tlJ5VPrMXUUBOKR64DhFs7euLfypLbSbbLhB21QjxQbpBg17cSAEDjZhrtXJ?= =?utf-8?q?cDIKEiLpyiJoijyN5OSZsMraclBjwr4FTM+0beo/+QT4uLyDfsSLE3mNhdqprlKrZ?= =?utf-8?q?V2RmrKP2RFn9?= 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)(52116014)(376014)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?T9KJgRQrq/lFD9gcwRszVz1bxNmK?= =?utf-8?q?MSg5N/BEmoe0t3kTRAkR87aWUoA97U4cBeudMXrMDbxBUdEU7T8/UT4AnzZytsH5m?= =?utf-8?q?ARC0fGVvQ/Fz1Fzc4XSCqjoTssRp8t0FsE3Yj0rTP1j2FRFSWFcGGYMqmVLGcDu2U?= =?utf-8?q?h66SHyX+OAcRG8Pj05IYEIhmpaYyZ3PK726Lo9xBmG76E3DsMBwOKBJc/ALCDySFN?= =?utf-8?q?qFXGID0c5/RCnv4h/N+XmhcFalRUAV3XzOeqCDhD37sf6R6qMgoHWCML6wyyu66KA?= =?utf-8?q?sHqQ2qoKWCXR0vFQOvRQ4PuDTLdBh571WvbZWzP/p9+gUvqujn7lFF76vYvmeHtUb?= =?utf-8?q?709JTuU2CJskgwGW4itC3hFjp82h+icuoua/lCSU9/x+g+xanZIQYYrIXFSq5bUo2?= =?utf-8?q?oPO+zOpz4Wrx1bYo7UQkEy5wmVnTW9ysKYul6yNlfJCCmF52dHrUGA9XUI+7XxpH+?= =?utf-8?q?pQdzvEK7NY60lzNEL3sp533xCehKx7KIQaNefqZT4sDgtzo6XFktvmu1OEXKthDBj?= =?utf-8?q?KkPisx5xKhD1uWaJ9Aqom6F7TvJScJmnt4uEnk4ziVJentTd/ztml2VOyxPv+22d5?= =?utf-8?q?cwpCEHRkFFxMTfjeO+4e8LZnamThEAayQiLut1Vi4fAkvJKuos5o2qPVp6fcS/xZz?= =?utf-8?q?ww2hY/+PfCOBGCV5KH7vJ2NKqXjP118nI1PMx7aozPcMk1yLQ2J0DjlQ6pfBuHEHd?= =?utf-8?q?j+lHnCMaUe1K6fLI2/h1WXJ4VefcPrSxz3VEpt8/cxtU74yHv/B/hElySB7sa3P6F?= =?utf-8?q?jkfmZ3x4rWnFDPYasgP6gRJvVKiO9pn/CkKq2eMoZQXMMI5mDKGAtV2hef8YXFt/M?= =?utf-8?q?x5fjMEIEA3ghJZfnS6owywoVzNxKuhLMB1V3c6tfavnvHnoUsPHOoFLgoqay5I5FM?= =?utf-8?q?a+B7Szii6YvnNHYA1FpXlRsFCaZaoOF4rw9o7+tJ2d/ui1FcOmq2wXRE+fh/uuIo1?= =?utf-8?q?s1evo2fFyk1ce0Yks2NTMjwy6pH2P8Cv/Bp/ijm0nr+ClzNqX1iuVZdERRX25uEI0?= =?utf-8?q?GwbaYcjO1NpzBoh3S9a14IXCIKGrs931HPIeaQRyX0dtJpr0PHp5H1yCg6vf65e9T?= =?utf-8?q?gOSToZPoeegpdJe+QCT9VpYvzIvQlLApo+zUXMvBk/syr7FsqO1Z9WBnENA9oLRxs?= =?utf-8?q?DMrPLAgiTCFzc8TfUw37TCGe+YzCb4zEp+Bvw7C5Q1kLueZBaWI39ryfoxcDsQYNQ?= =?utf-8?q?JeATNuQja94LtecDZX/9Q4BSXALeot2oO3pm8YDHATSa5k2PZ8Y90Kp6axmUgVQNO?= =?utf-8?q?D0jUvfDvOF002mwBkt4aY8azPOhPCde7craitrdigX4X5svsvdtFoXFDXIq5whotv?= =?utf-8?q?uO5okO5onWWGEVDHB1fJbOLFWWVBR4gwZOSr6xwDooTXx5ldLXcbOp1ssq68HrJNa?= =?utf-8?q?AmfyBimWoV+vWwtpK8BOFubewjcHfKST5DCdun8QAlixC9F4zT9iEJ/RgV9tEyRh0?= =?utf-8?q?9UnhK+6vdbpIjys1kKiWl9ANVbIMHuxW8q0jLo3o/J4+1DBlmI2v5eOREN5n+x4/I?= =?utf-8?q?RWIVMhanDGA8?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 85cc176b-3eb8-4586-3f14-08dcf837e7bd X-MS-Exchange-CrossTenant-AuthSource: DB9PR04MB9626.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2024 16:36:57.8597 (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: 6DYc4LQEd0Bs4wItpa5YksZoJgZ/d708Zgq7udOL247gdwDdiWb9sBuKa4q5o/94gdmnH8sMMCVBXohcgUkG/g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7577 parent_bus_addr in struct of_range can indicate address information just ahead of PCIe controller. Most system's bus fabric use 1:1 map between input and output address. but some hardware like i.MX8QXP doesn't use 1:1 map. See below diagram: ┌─────────┐ ┌────────────┐ ┌─────┐ │ │ IA: 0x8ff8_0000 │ │ │ CPU ├───►│ ┌────►├─────────────────┐ │ PCI │ └─────┘ │ │ │ IA: 0x8ff0_0000 │ │ │ CPU Addr │ │ ┌─►├─────────────┐ │ │ Controller │ 0x7ff8_0000─┼───┘ │ │ │ │ │ │ │ │ │ │ │ │ │ PCI Addr 0x7ff0_0000─┼──────┘ │ │ └──► IOSpace ─┼────────────► │ │ │ │ │ 0 0x7000_0000─┼────────►├─────────┐ │ │ │ └─────────┘ │ └──────► CfgSpace ─┼────────────► BUS Fabric │ │ │ 0 │ │ │ └──────────► MemSpace ─┼────────────► IA: 0x8000_0000 │ │ 0x8000_0000 └────────────┘ bus@5f000000 { compatible = "simple-bus"; #address-cells = <1>; #size-cells = <1>; ranges = <0x80000000 0x0 0x70000000 0x10000000>; pcie@5f010000 { compatible = "fsl,imx8q-pcie"; reg = <0x5f010000 0x10000>, <0x8ff00000 0x80000>; reg-names = "dbi", "config"; #address-cells = <3>; #size-cells = <2>; device_type = "pci"; bus-range = <0x00 0xff>; ranges = <0x81000000 0 0x00000000 0x8ff80000 0 0x00010000>, <0x82000000 0 0x80000000 0x80000000 0 0x0ff00000>; ... }; }; Term internal address (IA) here means the address just before PCIe controller. After ATU use this IA instead CPU address, cpu_addr_fixup() can be removed. Signed-off-by: Frank Li --- Add a resource_size_t parent_bus_addr local varible to fix 32bit build error. | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202410291546.kvgEWJv7-lkp@intel.com/ Chagne from v5 to v6 -add comments for of_property_read_reg(). Change from v4 to v5 - remove confused 0x5f00_0000 range in sample dts. - reorder address at above diagram. Change from v3 to v4 - none Change from v2 to v3 - %s/cpu_untranslate_addr/parent_bus_addr/g - update diagram. - improve commit message. Change from v1 to v2 - update because patch1 change get untranslate address method. - add using_dtbus_info in case break back compatibility for exited platform. --- drivers/pci/controller/dwc/pcie-designware-host.c | 55 ++++++++++++++++++++++- drivers/pci/controller/dwc/pcie-designware.h | 8 ++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c index 3e41865c72904..ea01b7bda0a76 100644 --- a/drivers/pci/controller/dwc/pcie-designware-host.c +++ b/drivers/pci/controller/dwc/pcie-designware-host.c @@ -418,6 +418,34 @@ static void dw_pcie_host_request_msg_tlp_res(struct dw_pcie_rp *pp) } } +static int dw_pcie_get_untranslate_addr(struct dw_pcie *pci, resource_size_t pci_addr, + resource_size_t *i_addr) +{ + struct device *dev = pci->dev; + struct device_node *np = dev->of_node; + struct of_range_parser parser; + struct of_range range; + int ret; + + if (!pci->using_dtbus_info) { + *i_addr = pci_addr; + return 0; + } + + ret = of_range_parser_init(&parser, np); + if (ret) + return ret; + + for_each_of_pci_range(&parser, &range) { + if (pci_addr == range.bus_addr) { + *i_addr = range.parent_bus_addr; + break; + } + } + + return 0; +} + int dw_pcie_host_init(struct dw_pcie_rp *pp) { struct dw_pcie *pci = to_dw_pcie_from_pp(pp); @@ -427,6 +455,7 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp) struct resource_entry *win; struct pci_host_bridge *bridge; struct resource *res; + int index; int ret; raw_spin_lock_init(&pp->lock); @@ -440,6 +469,20 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp) pp->cfg0_size = resource_size(res); pp->cfg0_base = res->start; + if (pci->using_dtbus_info) { + index = of_property_match_string(np, "reg-names", "config"); + if (index < 0) + return -EINVAL; + /* + * Retrieve the parent bus address of PCI config space. + * If the parent bus ranges in the device tree provide + * the correct address conversion information, set + * 'using_dtbus_info' to true, The 'cpu_addr_fixup()' + * can be eliminated. + */ + of_property_read_reg(np, index, &pp->cfg0_base, NULL); + } + pp->va_cfg0_base = devm_pci_remap_cfg_resource(dev, res); if (IS_ERR(pp->va_cfg0_base)) return PTR_ERR(pp->va_cfg0_base); @@ -462,6 +505,9 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp) pp->io_base = pci_pio_to_address(win->res->start); } + if (dw_pcie_get_untranslate_addr(pci, pp->io_bus_addr, &pp->io_base)) + return -ENODEV; + /* Set default bus ops */ bridge->ops = &dw_pcie_ops; bridge->child_ops = &dw_child_pcie_ops; @@ -722,6 +768,8 @@ static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp) i = 0; resource_list_for_each_entry(entry, &pp->bridge->windows) { + resource_size_t parent_bus_addr; + if (resource_type(entry->res) != IORESOURCE_MEM) continue; @@ -730,9 +778,14 @@ static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp) atu.index = i; atu.type = PCIE_ATU_TYPE_MEM; - atu.cpu_addr = entry->res->start; + parent_bus_addr = entry->res->start; atu.pci_addr = entry->res->start - entry->offset; + if (dw_pcie_get_untranslate_addr(pci, entry->res->start, &parent_bus_addr)) + return -EINVAL; + + atu.cpu_addr = parent_bus_addr; + /* Adjust iATU size if MSG TLP region was allocated before */ if (pp->msg_res && pp->msg_res->parent == entry->res) atu.size = resource_size(entry->res) - diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h index 347ab74ac35aa..f8067393ad35a 100644 --- a/drivers/pci/controller/dwc/pcie-designware.h +++ b/drivers/pci/controller/dwc/pcie-designware.h @@ -463,6 +463,14 @@ struct dw_pcie { struct reset_control_bulk_data core_rsts[DW_PCIE_NUM_CORE_RSTS]; struct gpio_desc *pe_rst; bool suspended; + /* + * Use device tree 'ranges' property of bus node instead using + * cpu_addr_fixup(). Some old platform dts 'ranges' in bus node may not + * reflect real hardware's behavior. In case break these platform back + * compatibility, add below flags. Set it true if dts already correct + * indicate bus fabric address convert. + */ + bool using_dtbus_info; }; #define to_dw_pcie_from_pp(port) container_of((port), struct dw_pcie, pp)