From patchwork Tue Jan 28 22:07:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13953231 Received: from OSPPR02CU001.outbound.protection.outlook.com (mail-norwayeastazon11013032.outbound.protection.outlook.com [40.107.159.32]) (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 1FF1D1E0B74 for ; Tue, 28 Jan 2025 22:08:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.159.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738102128; cv=fail; b=YfDq+aHh+cPGWAKkZgb0tKlQotMLNxax+A37bvdio36U1UUrQ/uu6+4wNYCQcY14Z2Sc2zHQBO9qNWTMQ3An1TZ6Qw74szaeNzLJFG8BNLTgxxSHuDAgs0JlQgPUp78epuiWrzVOYQg0rTilQ/PLw9BSAdxPVeFk+7KMnHxxY7g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738102128; c=relaxed/simple; bh=ugQwsOgSZA1155syuYkmLaAvf8QM3mw8WwLdBYfCiCE=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=FJ6nZjvcIueXyMuG6VbdJyYupRar8kpMewjNMYULQn6SVOFUbYo0C4EzdPHpk+Cu71kdSZPpOf9oUPhYka1U6BIBoUUVmOiEutE1+K3L317gaAQrnhBmhq1uNgdnknemGoBmi4SdYH/GU8vGeLRcND5oL82C8CZuu6HWi4YyTN0= 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=msSS9SUz; arc=fail smtp.client-ip=40.107.159.32 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="msSS9SUz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ALMsEQGhXm6dM/VVcsXGMM5u4tJvpY5/MfO4XONvKM2WmYlj3M+VGqySLhyX55lW1x/H6O1Z6btGUUe+2cK+bAF2j0Ngnw4UvyeIIuduR+y9MyiMduylB05sJS8O+C8rboI4Fy1ny5wCzusCgu1Knf6U2akDrdSOjithHbCvmo0JwYP3ZA1gjURMJ9ZQBaGz28JLOPTK+nrAJp4BYjA3JbNCVcVl9qx/7XT2/of0DaQxUcNmGWZ2fokOLHiL0ayU4eD9nhCK8nMrJvinIxVEPS9oVubqv5S9ecaj7EbMQ61VEEA0rQYd11p+x1duB9xS0UtjLONnQq71kfMUeXFa7A== 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=AR+2m4CQnHQSIMlrcvoieh13m5iawrwuvaQGxMLHjm4=; b=d8xxQIfxGI80DrCCwfrBw9hv2ehxkDOmwMT3X7SzcmYnhxPLPKhPQjAxdeC6Iq8aEBGV88dOvdPY8QvG8wnsmjhBGAUkWJycAxkiK7DItRtSnuOG43S1BiLcoZqxW3R2SdFWqFSIhCYaFmyuLRd7qL6Zt7tES3A9Q3OtQCzeg6i5pCPGG3Kg7xHa11uX5gFkP/QmOhqeC0f4kViChv4u279mcBGFiFVsT31CENk4GJ/Et2PeDpAZ0Le+hKteBr9iARCcxu1sElbtxMbyrfu4GfEteSI9EQj27EBLAbtc9KEL1GsE+strIKijYksshxiRbyykxuRcrlWcf0Ojgz74yA== 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=AR+2m4CQnHQSIMlrcvoieh13m5iawrwuvaQGxMLHjm4=; b=msSS9SUzkde18Dge7be4mvOZ3yXw8jtJz39mz1UtfP8XpLmvPCkil714vUUJRcKjUYzR0dvMyYvOMuZ5UhZUQUeqCOZ1nfjZNeBuRVsBk9kXzxKIDPEXACHTBWHoXUJXTSy/N7brhh29iQMKLdIP7os34aoyRCbn1HW95Um4Bdq1G+MZGoX0zZSSgRkn5FMUkfIlXg+V3eAADqb2F5DLkdfM2scck6Pq/KzoO3NxclSKpvh5+/7wX7vuHZVn/pBVKOsPgAdNBNhruxICpYn21NANElKCO48LDVJJZ+f53ZMmO2HK+CMbe3uP7W0n1C31SBQUSNkeY4NxmUmq516ZfQ== 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:43 +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:43 +0000 From: Frank Li Date: Tue, 28 Jan 2025 17:07:37 -0500 Subject: [PATCH v9 4/7] PCI: dwc: Use devicetree 'ranges' property to get rid of cpu_addr_fixup() callback Message-Id: <20250128-pci_fixup_addr-v9-4-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=8990; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=ugQwsOgSZA1155syuYkmLaAvf8QM3mw8WwLdBYfCiCE=; b=u6HcIQblCH1F6kIy9TTvhw8EgsD0kHST1G4KRLjrEwjac8iNghQXBO9XP6eyopGXTg83IeNKE wwLHG01HlFgBEEwrPm0era1L/SQ0llFVVq074Nz5i7tTKwCnxxu+M9c 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: d9427fa6-894a-468d-553a-08dd3fe85455 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?T4lg2WLQCwizUiERzBYyM5BGwnoiTxO?= =?utf-8?q?oiq5cFm46lglW13+WG2kjJ3swoMxe/KG8Ka8HSCiC5HHeqaBhwFzHFrHz7MDAwzcB?= =?utf-8?q?Zj3fdubKWPGrFgE63Cj6bKnmvaRo9h7bBW+Pj3ahRL8PnkuzkhwD1Q2sl3k/0viVp?= =?utf-8?q?DxNh+5sTrr4tfbnwiksxJUHOySk2fRMv5PzRwpKVLLd2O+BZYT3i8o/S93hqi3XcA?= =?utf-8?q?TtDiIyp3aTDxynLe6feB/bA7exeBGlNNCP9ZsRQT5X+O7OQZ6uBsovwigAoEfsdg7?= =?utf-8?q?w0DjTbhaL37pcSwgt+h57PTV3N+aYXOjX73oBc4R/4wP2S3i72toiMy3hAMI3HHuw?= =?utf-8?q?mYqBN95sDhv8v9x+UOhrXXnM8gEHpdaxXtaS+0lFM+Spl3la3qS2Q5o2Sju++MCyw?= =?utf-8?q?BgVlT6Slj4wki370An1Tv2OmVkmS/o00yG/ATDoOMhFcifR+LfpvdkNsuI9mvf95c?= =?utf-8?q?D0WV3ORTvHqcT/j+SzRJJCZx+f0/oaru6iG6/tA+7WV10ITqwWiE7ToSXnGUK1HZL?= =?utf-8?q?ZGb6ME0kHDdJWKSVmDsNRNuV/PjSl53Y6t7rfrJ2dKm0EoFiFIe37wCSmGZN7d18X?= =?utf-8?q?oM8zgyFfURnvcwvoRRfFL4x2qHK24pU3ebOYiZSLuTvZ65HTxVtEg7Tkf2/4huymf?= =?utf-8?q?g6DEwM53We+mwtIemcyhaMiN7+h1omAX+DtA50BAotR+FtrHMRpvU8WiNH2KnOWQM?= =?utf-8?q?CrYEy7jFlur2LZ/yDkOaXQg0ytdkodEZEhkuKRJ3b803cbeRayu+x8EnebW6Bnnch?= =?utf-8?q?J6Se5kKwywdEEvoND8w0t8a7eqyJvnFXRIhhQayJO/ha/ktTlKBABdL0B4U9Vrl2o?= =?utf-8?q?yxdbg23c1GYiaV10xtpJEdaytCxj841VqeVHiOS2WYARfuckbihJu1yqDFhuiOBAb?= =?utf-8?q?7cBeHM/Wmvk6o2kZ4fobnpP8uAR3rO+TwvPHb9HLbPe6L1LaP2P2cU5ULuDaPm/1N?= =?utf-8?q?kcsxTI/I6V2Nfen7hUaUE31qnaBjAQV7hma5Wjb26q1Lq6vh9Y/LDn6+JLsyqn+4m?= =?utf-8?q?19grm1ZHL85NUYZSp5v2CcOK5lWaNLAB2rTuEf/ed11Tf3WnyJ5R7k3FSSC/EecyL?= =?utf-8?q?woSAxJ9e/mhDlomMB7RTjJ++hv4LdCwb5P5xZlGYBdhmZOwBrw5xqdgyJARKiSycZ?= =?utf-8?q?cZDeEgHGKJIPv0BO0UkF++QEdRbXOHP42nQ15hhgk9H73OsYeah1mB/7xX+D+3yXK?= =?utf-8?q?p74uy2pdyEAqrQGZ11J957GGnpbBxFTd9/kKL3waFue6P01NzRDNWO7nf3rMrIMBJ?= =?utf-8?q?+mSg5qRHHMsp3gAAFQtrfAj+Yc1quwt+Ny30GpBgGrbR7MVfKyBcI2Iuh142nslPa?= =?utf-8?q?D6sESxvk2IUPxue29KuPtcFJfCXV7p+lOBittrr3uXeaMrAWpxkGik171JnSiWjmG?= =?utf-8?q?iyOvNV6iu8TUyGrhJqNdjZxMs9hUZ6M2Q=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?l31UG+TdUqDIbloBktJhyIJx0hLA?= =?utf-8?q?9HhCE1pUCSfC/tbAy4s1ijeAsDntUUE7mn7j8TmpJAA/PcqFcnjZKbfEUZCqHS85v?= =?utf-8?q?9nrACyRV9V2BwFhdEA3aoeEAXYyw8A98QqUygyM0f0lrnwbCdNsfJILkKZh4EghNw?= =?utf-8?q?qzkcdG+oLKTy8PsziFwmQOvSxVQOicui58roSpvuX9rfuCjYk4A8PoMfelLPY6/Vi?= =?utf-8?q?aJSHTD3E3YOsRrMEMcCHtWZmfwnXNfuUzNXR4k0qyL+tO1tdYFild/L2pGRVW2qkR?= =?utf-8?q?QjSecAmawGd6VxM7TioL48BezdwOfdhiL4qZMxJBnV6ggz/oNk4O2oLAB/QGeJfSc?= =?utf-8?q?APwMBXDpRDvYzgGO2z54k5lQ9+D1jVvy9pzHzB6LnNuDl+6xrNhCj0XMq1o4QpgBR?= =?utf-8?q?f3++8+cH4BoW74mwJSEPbYuQNKp2cLa1Y9zwzj/Kt8LtMIoBpkr2GgHPRDS64QeB5?= =?utf-8?q?B9vZ5B9TOhpvT/l2TK4gT1xY6L40qvP9OGpohNK02jVQmcl8SYAOtqkAZUfUCsb9B?= =?utf-8?q?OXXoV0/8EjXe7OfxKZEXYGWYBc9Nk7HJoGYz+tsHeP46uq61G8eAuzMEfqSKAlX31?= =?utf-8?q?TxT4be9h2XZnnMCHnNXlW1Nx6JUMFQcoc3fIkSIsyaGyXIMVApWB8ONLgR9bOptI8?= =?utf-8?q?V3K8rCz+LI8mYqc3oWn61IDFTICqOc2w5bnu3QnY1iiXS1ZTC+m4vBdNblGRHL9h0?= =?utf-8?q?EL9zAr7jc5vcxcwhBw0qDVSit9tyrRfu6BvbvRRJqzZ1NMEGoklEr9sobyqJiyuq7?= =?utf-8?q?7X+iQ08sDyeArOKr42RwYJHHZQm8VJvNLH09wiKsSAXk0eZFZ8iAeKuEfQ6lp8uJB?= =?utf-8?q?FQrTkY0UP50ieCfNw/3YN8jhpT6JApxzxj3FcGActl7sX98Xd5G6UNvtQYxHSTqRO?= =?utf-8?q?YONIzMy+Ug3uWem+SVIlrTnnCfauFQxQRqGuIm5DGqa2aHM/srpFetcvVKCXmSG2T?= =?utf-8?q?Oqdxca21q2gC1r2LlcJ+blJm8yvdWS2r4wKcc4YC9kBZoTniOKSbPgtgnc3he/0d8?= =?utf-8?q?Q5r9t6mOpJiCxjdXP762Pve5zX0VvfdUO7m5XCKWx1sgmyeIDvjkAmR16eMngD+mc?= =?utf-8?q?dN5c6/YGEHR3hJEPZuwFNVfV/Z4PDkT5FoEYN0uHLxJe0LCBEzM6dSMWz1HBk4KEm?= =?utf-8?q?q+0VrrQMirTiEa6Q7zw+TSidJhLmrumCQ0wzLc5+Q4q3z8sfcPywVBH5iTvNZGIPt?= =?utf-8?q?HuXV5HBODKYahzs/S1TIEl1X3Yzs8Ykr7aVHCXQpOGxrJxO2XOvMB6LjkPbWq9oSQ?= =?utf-8?q?LdmHWzKretYn3C3kNLvRCHbj5IG1zQtqAanHsinIphBnGyqyl4TFVnz3YJw02pmm+?= =?utf-8?q?x5XgmkCAoiAep35RVltbWYlHMxMwGHZ6w98fbjjRilShFKXSG0Qs1NGlKaJ5PIRIW?= =?utf-8?q?jx+w3KruI8lbjpf7kamYkxN6qlYVmnS5ySc78a9K0KS6R1hqg8wKB6LexHFfdYBBX?= =?utf-8?q?BmNYjplniCV/lwB9J7LbUoMjhzory3JppaAzcT0I3Ful11hYUTOkAPk5Vv6w2i86e?= =?utf-8?q?lOY38ka7aVFj?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d9427fa6-894a-468d-553a-08dd3fe85455 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:43.7340 (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: XjuYLdUNBh8tHWD8P3DPwVWon3uCIs+IWi/2gQaunxG5lmm8o2zj9J+hKwACHmas9pbpPkSWHu64Fs12nyswgg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8555 parent_bus_offset in resource_entry 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 Intermediate 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 v8 to v9 - use resoure_entry parent_bus_offset to simple code logic - add check for use_parent_dt_ranges and cpu_addr_fixup to make sure only one set. Change from v7 to v8 - Add dev_warning_once at dw_pcie_iatu_detect() to reminder cpu_addr_fixup() user to correct their code - use 'use_parent_dt_ranges' control enable use dt parent bus node ranges. - rename dw_pcie_get_untranslate_addr to dw_pcie_get_parent_addr(). - of_property_read_reg() already have comments, so needn't add more. - return actual err code from function Change from v6 to v7 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 | 34 +++++++++++++++++++++-- drivers/pci/controller/dwc/pcie-designware.c | 9 ++++++ drivers/pci/controller/dwc/pcie-designware.h | 8 ++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c index 1206b26bff3f2..a0c8e6f66ec4d 100644 --- a/drivers/pci/controller/dwc/pcie-designware-host.c +++ b/drivers/pci/controller/dwc/pcie-designware-host.c @@ -413,8 +413,10 @@ static void dw_pcie_host_request_msg_tlp_res(struct dw_pcie_rp *pp) res->name = "msg"; res->flags = win->res->flags | IORESOURCE_BUSY; - if (!devm_request_resource(pci->dev, win->res, res)) + if (!devm_request_resource(pci->dev, win->res, res)) { pp->msg_res = res; + pp->msg_parent_bus_offset = win->parent_bus_offset; + } } } @@ -427,6 +429,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); @@ -448,6 +451,26 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp) if (IS_ERR(pp->va_cfg0_base)) return PTR_ERR(pp->va_cfg0_base); + if (pci->use_parent_dt_ranges) { + if (pci->ops->cpu_addr_fixup) { + dev_err(dev, "Use parent bus DT ranges, cpu_addr_fixup() must be removed\n"); + return -EINVAL; + } + + 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 + * 'use_parent_dt_ranges' to true, The + * 'cpu_addr_fixup()' can be eliminated. + */ + of_property_read_reg(np, index, &pp->cfg0_base, NULL); + } + bridge = devm_pci_alloc_host_bridge(dev, 0); if (!bridge) return -ENOMEM; @@ -460,6 +483,9 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp) pp->io_size = resource_size(win->res); pp->io_bus_addr = win->res->start - win->offset; pp->io_base = pci_pio_to_address(win->res->start); + /* In case ranges in pci node provide wrong information */ + if (pci->use_parent_dt_ranges) + pp->io_base -= win->parent_bus_offset; } /* Set default bus ops */ @@ -739,6 +765,10 @@ static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp) atu.parent_bus_addr = entry->res->start; atu.pci_addr = entry->res->start - entry->offset; + /* In case ranges in pci node provide wrong information */ + if (pci->use_parent_dt_ranges) + atu.parent_bus_addr -= entry->parent_bus_offset; + /* 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) - @@ -902,7 +932,7 @@ static int dw_pcie_pme_turn_off(struct dw_pcie *pci) atu.size = resource_size(pci->pp.msg_res); atu.index = pci->pp.msg_atu_index; - atu.parent_bus_addr = pci->pp.msg_res->start; + atu.parent_bus_addr = pci->pp.msg_res->start - pci->pp.msg_parent_bus_offset; ret = dw_pcie_prog_outbound_atu(pci, &atu); if (ret) diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c index 9d0a5f75effcc..909b14986660c 100644 --- a/drivers/pci/controller/dwc/pcie-designware.c +++ b/drivers/pci/controller/dwc/pcie-designware.c @@ -841,6 +841,15 @@ void dw_pcie_iatu_detect(struct dw_pcie *pci) pci->region_align = 1 << fls(min); pci->region_limit = (max << 32) | (SZ_4G - 1); + if (pci->ops && pci->ops->cpu_addr_fixup) { + /* + * If the parent 'ranges' property in DT correctly describes + * the address translation, cpu_addr_fixup() callback is not + * needed. + */ + dev_warn_once(pci->dev, "cpu_addr_fixup() usage detected. Please fix DT!\n"); + } + dev_info(pci->dev, "iATU: unroll %s, %u ob, %u ib, align %uK, limit %lluG\n", dw_pcie_cap_is(pci, IATU_UNROLL) ? "T" : "F", pci->num_ob_windows, pci->num_ib_windows, diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h index ac23604c829f4..483911ab9e629 100644 --- a/drivers/pci/controller/dwc/pcie-designware.h +++ b/drivers/pci/controller/dwc/pcie-designware.h @@ -380,6 +380,7 @@ struct dw_pcie_rp { bool use_atu_msg; int msg_atu_index; struct resource *msg_res; + resource_size_t msg_parent_bus_offset; bool use_linkup_irq; }; @@ -465,6 +466,13 @@ struct dw_pcie { struct reset_control_bulk_data core_rsts[DW_PCIE_NUM_CORE_RSTS]; struct gpio_desc *pe_rst; bool suspended; + /* + * This flag indicates that the vendor driver uses devicetree 'ranges' + * property to allow iATU to use the Intermediate Address (IA) for + * outbound mapping. Using this flag also avoids the usage of + * 'cpu_addr_fixup' callback implementation in the driver. + */ + bool use_parent_dt_ranges; }; #define to_dw_pcie_from_pp(port) container_of((port), struct dw_pcie, pp)