From patchwork Mon Oct 28 19:05:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13853948 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 05601D3E2BA for ; Mon, 28 Oct 2024 19:25:15 +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=72nw29hHFDlpi9crET+L23if2rJ656JTjj/1lPj7nXM=; b=fSRyu2sNwvQu83E5SktEpmqAFi t70gWsu6B0qmQNJhHcyX81tk3ZODzkbEKI+6sA+D9rWmAOePWsQMQfKMeajD7t+BMS7gYgTRKhct+ BR4ILEFD2X29sD5qT/Ah17kiK7zkzKANyzzmehqge9FJJZGVk9a8xWwrSuVuD1i/4dwl0iJVtdYCb 9krVMMGGRPaobv3FkEliG2K1B46PHqFsULysAZ//U/2rivuwAyj+AQXCWPFmjuqwngFs6rW4gylhK N5D4EdX5J+dbZyqRmLCUXs37KGylUoKiIxnnp/td8E50hcu08LWwXcJfiTiQM5WB6je9oUH2T2i0B jrN+9RlQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5VMO-0000000Bzoj-2g6N; Mon, 28 Oct 2024 19:25:04 +0000 Received: from mail-vi1eur03on20602.outbound.protection.outlook.com ([2a01:111:f403:260c::602] helo=EUR03-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5V4G-0000000BwcM-2fSk for linux-arm-kernel@lists.infradead.org; Mon, 28 Oct 2024 19:06:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=k00L9f9BI4YCq9756XeJ287hUTvHIJVk5PNGhHPIeReAf1qxwDXzzyBz+iH8dhyaGWJTNz7p2kwXxNskAFJCoiP6j4KM4zFGmUhun8lNHjM8jLtVmxRqa7YUnjO/15p/Zlx3guCkKoJV33D6mXhRkhQNf4orlZ1rLaMiclh0LWSoVv6gshpGoIhdZ0n1+UywsejgbyXhfGytxKtdS8YMsCpC3YJFzFWBO0ct56/ZqbwOzOuGz/GnBZJM+XjFl/jNcnaOfKMLGfWqyj6QsKJuD5H80EX7AkniUt3lyHlNJAp3nQKewXUjt9Ca0opLJULjVbmCeQcEdRA9iPL4tGEiSQ== 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=72nw29hHFDlpi9crET+L23if2rJ656JTjj/1lPj7nXM=; b=jqyNrWEbXumyQ8Jtu1oS6TfvB3nPYiPKXDvoQQyWu1TYdRdsb1WkV4z1poXr8vyEuMVLqvp7r+vM2vDTuTuOoYa3DRBycG95gvO3+0abuxjspkk0LWuZbyp8tt37lmkR5/t6duDy0w3MTdX++ts368YGHrAWAEgo9loaI/1DcWOv35n6rciSD2J4lwp2Dg7GX129UWJ7M6x3ZTWELfLxDB0eIYe/fQy8yzOLC+SAr0vMeQP4TPCUwlUErNhxDumH4nP0XrfC0yTBBWIapJs8/GTnacqrk64XtmDnxxY1vnjZrXlzuLAkdQVH6sZMDs5bVWlsF7huSpfIJrrR+lYAcQ== 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=72nw29hHFDlpi9crET+L23if2rJ656JTjj/1lPj7nXM=; b=YQgvxOlrCjV0BhbDAPSweEuhr5pwW/M/Alb56QDsrCzbtVLA6H5GHxkB9UUJExh4J13VcgkJ1shQ6aG+GRLCi8f11AQey+EjwBNgspFmvcWv414RUed63n0ynTlkKI8QNo4IlqtFlhhec4j9RtUhlmC9uN7vRMvnRrEygEguG1+vWBEOzNTBIMTOtnI2PTbs/EmkQqKS2QUqTFgUARpk+tKzlzj/DglUni4LctNBXKNjUhav2B+LOr/eMUjUlqFeOyooZWdoI9EcaPa5/qZ4POhZhXSRwyFXQUwAD2xEotkVTOoOAOfaFwU82UZo9H4rZ6CsYW9NMcSLEXn87cq5tQ== 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 DBBPR04MB7946.eurprd04.prod.outlook.com (2603:10a6:10:1ec::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Mon, 28 Oct 2024 19:06:17 +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.021; Mon, 28 Oct 2024 19:06:17 +0000 From: Frank Li Date: Mon, 28 Oct 2024 15:05:56 -0400 Subject: [PATCH v6 2/7] PCI: dwc: Using parent_bus_addr in of_range to eliminate cpu_addr_fixup() Message-Id: <20241028-pci_fixup_addr-v6-2-ebebcd8fd4ff@nxp.com> References: <20241028-pci_fixup_addr-v6-0-ebebcd8fd4ff@nxp.com> In-Reply-To: <20241028-pci_fixup_addr-v6-0-ebebcd8fd4ff@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=1730142363; l=6907; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=xiXouNpVhhagOvQdXFLvlfaRhzcVDADSufDDS7ir13g=; b=1XAtPwmnz6utgJb/RgXFDtavRFJLTmEvREIQo8R68WR2nw0mr9p7AuMh2ILH2KG9QuZC0XOqd GVmw+rYESP/AvIAsufScZqwYRpxvl/2uw0EzbJk+uSP9fWALk43Bj0/ X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR03CA0005.namprd03.prod.outlook.com (2603:10b6:a02:a8::18) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|DBBPR04MB7946:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ef1ffbe-4d91-4a31-5adc-08dcf78399b4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|366016|7416014|376014|1800799024|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?tncp/HuV7NsTf2TYhjaL/nylJbSnSH5?= =?utf-8?q?4l3KB4DtBFMTGm4M2reijg3NpEXJa7rwYkQkV3aAPTZPxj4PtEcZNzs/5dBVuIK1j?= =?utf-8?q?1B2UJFzbevalQYOQn8PY1TjREplfTpapvbIf2dNU/fc0hgtX2VuTRG3L3K8NmSLc6?= =?utf-8?q?KfZefBuTjoJc6HjocAKnuGHOdNF7V1hVuS2gjLHCG39myQdnrL4vasXrrA4BJzjik?= =?utf-8?q?0Z6RUGyEjvlBCHjpdVHIfa6R/h9MH+W5CzkWGplglQ5itAbyqwQKpe1KX2SdZ93mI?= =?utf-8?q?wmEJE7K+cRWz0uKmp3iFy7gfdy3j0a+X03vbfLGhA9QY+0tHZi0Lpq4kukPWiEiSH?= =?utf-8?q?WNRbAlwK1gmWu8CMd+IDI4cwXq4DyIJ+TzctWQK4d8ErbEhbzLJx8/8nZm7jzWK+G?= =?utf-8?q?ci51S21LE9QYZPXQt1flZ23fsna62OyXwmhyYTSezT0tAMsyYv001OYlolRVq4iTe?= =?utf-8?q?IktO2X5phYQICWzMcsdiYb/zb0WufdvcnLP6HWJUqzONRdjHu+XWR2lgfX6w3oq9h?= =?utf-8?q?Kcs7WfLpjNVKJJyTQgmYUF6BHQttnqtmduisT8P7OQvUhBbmiB37ETUJSMyvBlldz?= =?utf-8?q?xmGtPNxqB4NjgJL2os+yBs+c7zCgTJyoKl26UyiaJsV+OUlPr9YJm1/Izj+HofS3Q?= =?utf-8?q?FOXqLPi2nQSOleO77WxxBhROjSeBOuHcKPUVMlwQmXp7YXqBIkyNJswYvc/7a7TRT?= =?utf-8?q?9/Usf1kEufEk7PiweK1FT9OvVrEX3d3A6v0c4b7Mf6CDpOzW0RCNYEoNVG3EeqJmt?= =?utf-8?q?UslLg0HmgDM7k2zQP8yzdhik+7g30ASjGVGyFx9mN5hoPdSyw38ktDI/9NzotOHsM?= =?utf-8?q?hAQ2xVFOLklP6rwHJ5lsLR6+BYse2g0+uvcRzsSeoYt/GAnQ26N+q+KaKuqJ3XKZP?= =?utf-8?q?Ci1lxQx2K5uDlRrS/Zx4GTyAyl2NetFS88kvsstb6ZmTTnYXcf6rjkfE8gNq6irwb?= =?utf-8?q?ty1VL3BrudiISKtgagaqdSZEhyXP+layxNKzTKPTdb7jfTFB0/7Inc9ie0RIio/sC?= =?utf-8?q?GS5jzoQJuNV39+mJ1Rro84xw0n3+IAlI8kwBqoFx4OJ7x5Ozug+V7w4EGxWiF35Qy?= =?utf-8?q?NZ9K/MJtemGXXEAvjLAzOpAj8PuZMnGwg8Nv+NsHzQkROpgAj7Qk3l25N8a+IvCGs?= =?utf-8?q?RRceBbDlLau7TRZL2ZBic/K87+vCdCr/OJ02+6/jbYtezspwyyJGC45iVmy5B7wrG?= =?utf-8?q?duLK91iqEorU5XQXXCnxK35/6Ng0Xf665Ohzlkz5WFE/f5R66LAfFgl2/wWS3JXnX?= =?utf-8?q?qrCFO+nJbCqDzoWjSgfTD+cugGKH+Q8ehSiix8BDmrvvek9x49pD25TUx9z4EjJia?= =?utf-8?q?czuh5sg+5ait?= 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)(366016)(7416014)(376014)(1800799024)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?qDZxvvlRYjRMbJ4g7xOoulLH/q2T?= =?utf-8?q?faxnusJC3dYbN1RXhwNRns4j9H1jV8eMWTn26p4BkDPNT8Fve8dXIwk3/vg/tZqPQ?= =?utf-8?q?euwuI8L79zN2Ds5t503SFndzDlCDrUKNwJc6D0bx/XukidyZxxw62LBTITacS6TD6?= =?utf-8?q?2Ld40pWgLT9U9w/1k+awErwIF7eIUMQwFvh108Wg0K/WX6beziJoFe++tCqPqhv6w?= =?utf-8?q?+/CSybP+4VSeFV/zpUDlixrj5RYinVQXz21R6UvLCxUCumuEdJY/zUFED44d+tK1z?= =?utf-8?q?cF2I+IhW9bu0mb0PJEVRR0QllO1nB643Dal+1/Go1PnoMDRHm+gL5w1vnBpQDV18+?= =?utf-8?q?wzeVJFfN0VedKfae6C5p+ZHvW+VzeEfVV2WtpJQ+xbWO/wVEAh7U/6y4z3Y8tyPB2?= =?utf-8?q?DzxduauZVU2z8m2+Jk+HY/AnvPyT0BQsPDDfqrZYq9euFFpkgIDATuxvr4YgmiMjb?= =?utf-8?q?NRFfGrgbedUBy+b/H8jk2osKUPYGfQnOdqqexPJmBzKMs7DaAAUaAgRFajCD7eQ+z?= =?utf-8?q?0FUHonGhBJHYQoQchmZ+33qTfkmL49NOgckxT87GGZCk68643P8PlCpeXR9DpP59/?= =?utf-8?q?sG4O7Z191IqbO55ea6SlQqfur4yHWX5Nh30G9N1l8vK+IuRN6omxBl8Z89Tf4UTfb?= =?utf-8?q?cnTgc6v+mzg/fDaZRNhJvehUldmTiCBW+mT3uCx5zV3cHP7/pw/iTJGT4KLPsw7lT?= =?utf-8?q?IDMTkKPMMO6O83RZAjoKZBUPgAVBIIR+kZYj/huEyY4rZGdgx2QmZwPee02UUAKow?= =?utf-8?q?jtOhoOni6teynNhJLR/FBxqQpDBgDjv0/+yHf5wmTYm0hRQyYYq8WtDZSEmPPAUSl?= =?utf-8?q?fzKDz7y7T9ios4D5AiFakfJM+gOJBlzoFs5Kn1wVIYTAdB+iRuavzH9lIRXVjNl7g?= =?utf-8?q?BK+w155+blRjXyMgYu/C4VSyhs2RQ7Sak1S/rnZDkC4rbOzs9N6z0SZJvz+CuFm/q?= =?utf-8?q?F2+QOQ5N/kMdYGqD7WQodv27yuzD719RD7Ix/RqroynlBNEUyY7FrFlLNDHRKH9kR?= =?utf-8?q?AJ705fZ/0+Dq8kq0Ng2vaydNod53p3MhBzGZYfea6Q+uHZ38gZ5SDIFFXQNkXfq12?= =?utf-8?q?/b4calDJwkFSkLakOud+xJVs7+G7A5k0RZb/0IVRQ+1qpbtRB8Hwsqe+BEWkQaZxR?= =?utf-8?q?8C1dD9t+9DZZBp+mLfZR8qBPrM2D7JcjYjIDwUF5IcGc8DVBgvJVLm2hJk5pnnrTJ?= =?utf-8?q?KVwfK/5YgjhdVQSyo8+jDmGwx2p27xLC80S6TWD96UM+Vty0XEPm2hxdG+d3bInLP?= =?utf-8?q?NnIDuBwu382N6YDqDArWFIN8VxVbqIczovBlxl8g753ZR03fDQ/iSWaVq4MLt1Rw+?= =?utf-8?q?e1bJvsz+PbeHi1HioCEGcaGuaVtlkPROrny9KoHjYHYrIr4fXsE+rjLWW9WyQhgD2?= =?utf-8?q?K/yWa1KZir9nu5oSOLIX1wqI6DImdODqhH7xFWINojkHA4aErC5+it9uzirXC+94w?= =?utf-8?q?Uc2fCscQsRH4TtsCVJPuv7JHC907Wd3aok14TKZD9f6UkprJQsJAF3+hjtGjs+CMb?= =?utf-8?q?YzShTYzZHuCd?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3ef1ffbe-4d91-4a31-5adc-08dcf78399b4 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 19:06:17.2531 (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: +H2/7q3a05XVFq77nLUer3jVCQhN6+brmNfuZ1W9SBtiE2eRVbjuA+OH/D7TgPfOyR5R5TGfscue3S7eF5A+rA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7946 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241028_120620_907638_DB19601B X-CRM114-Status: GOOD ( 16.01 ) 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 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 --- 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 | 49 +++++++++++++++++++++++ drivers/pci/controller/dwc/pcie-designware.h | 8 ++++ 2 files changed, 57 insertions(+) diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c index 3e41865c72904..a4f2578700eb3 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; @@ -733,6 +779,9 @@ static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp) atu.cpu_addr = entry->res->start; atu.pci_addr = entry->res->start - entry->offset; + if (dw_pcie_get_untranslate_addr(pci, atu.pci_addr, &atu.cpu_addr)) + return -EINVAL; + /* 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)