From patchwork Tue Nov 19 19:44:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13880495 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 F1CEDD6C28D for ; Tue, 19 Nov 2024 19:47:51 +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=zMo3hBX8GeMdL53WMeb8f+oFb+ZgvK88u9g588A/Bz8=; b=wXN0mfh0uk4hJQUk7OunyN1n8o wWe01qNkXUVYrVSg5DVR7H4L6Np25PqV2dkasOq4g+39gJlXY0MZ5NH7GN//a9xGGb3euutCllPFM 5PMW5OuzBu7cDXGf6Wiz1JZwH504oeH9f89QgfuQe6qKv/agz06HrLJteRj3jGaomXMSI5ynuhIkL au+E1szA+8P3bm5pS19AzF9zBDq+/q2kDIf5X3aKiYpk8MZTIMIudDZa7pOEiJ+xsYfw7TryqZh0N afFIGxVZ97YgUcpT+UJit9rjgATFVc9+BbQTI9H8VhAR7xLq0AFoV6Sxvzt/+VFhbrKJbVzcEKchE 2P93OdfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tDUCJ-0000000DaBg-06Ex; Tue, 19 Nov 2024 19:47:39 +0000 Received: from mail-vi1eur05on20601.outbound.protection.outlook.com ([2a01:111:f403:2613::601] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tDU9a-0000000DZS6-3aZv for linux-arm-kernel@lists.infradead.org; Tue, 19 Nov 2024 19:44:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oSap2T2G5yPjhmHzu1ufqvXIbi4vpR2SzLmRbtC6CDKF3RTUMEZAKvZ+dPDoRYqZ2uZ5oT3gXkvff8Ohpgk/fpZ16ID/lWliyA18hZwu45hrp7zV98GGTkljxm6z0i5Zr0OIDuKA4649Taf6BJIwnTisjYHiAFHQ5ffvUNLB7DC1sRztddls5W8yHrCEyCsw8DXcxO+xwgQGWMIqk/Nh2y35X4JRapwm5Uvji3ZxfTm+60l7yZFcfZIXOqjplL8Zt9Q+apa+yANur4g09GAB6pYnZ/pb8bi1FlYoM0K7/PL40xrVCw02Zv8PGIUxDRh/l32IhF5g61IUgBbdANokQg== 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=zMo3hBX8GeMdL53WMeb8f+oFb+ZgvK88u9g588A/Bz8=; b=WZrnjyrzUavolmo7BVilXyhQ7EI7LR+eBoqLeGWmas3IyUj4CpMVOp9yK2VTnkahITUP+VfPldhxr2wARcpE3gDrXtMeMmoZviy1ViiS4kTVsplsiVhZ/0s4+VvKGajC3+L3au3POAq2jNfs8K8AmhWpLtw1eOmnEmJTzPb3+Be6tebEpd45jDRStbZ6ZzSUYTspxuoILnFK8CLaJu/ervBR23doYFemCmNO080swe6oKeVz/ARNMiKaxtr4/WLzVi+u74nRzZK6C/w18GN6TICePJTW+mrOpN6kP7EChXhtjq4pkA+8omlm3fAhHiEeIoCTXbjSMGd8LAmtPpTKZg== 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=zMo3hBX8GeMdL53WMeb8f+oFb+ZgvK88u9g588A/Bz8=; b=ZfVtg563NtoFPQ0Ji+loiZBtEshOFevKTV7Uuqc/Ckj1SAOxIXd5kwxD+D6Y8mdVgJb6QTxG9rkg1/L4zLuKs44TAjyzKncr7D40O5eOJIwdW+WJf/LSkpoGZfmNcEBaeM+V2q0CxJXNcOWQZmFFLWZgVAd3kbHcSUyeIxWBZ4+hZFCGm1wZ2AOvDdVx40S4+lx2NUc6+IM/oMjDRItCUaeIB1bAleNbz2nx/CyJpMUZ7pv4KuyM1uNXdRs4+vkDLVVZHHnDnDTBen4sRRTP7Ncc+xUus9z0JPpQl62er+shy7PW0CpvahswFOpK9IGKbNq7dS3zUa+79zM/dKqQng== 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 GVXPR04MB11068.eurprd04.prod.outlook.com (2603:10a6:150:215::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.22; Tue, 19 Nov 2024 19:44:46 +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.8158.021; Tue, 19 Nov 2024 19:44:46 +0000 From: Frank Li Date: Tue, 19 Nov 2024 14:44:20 -0500 Subject: [PATCH v8 2/7] PCI: dwc: Use devicetree 'ranges' property to get rid of cpu_addr_fixup() callback Message-Id: <20241119-pci_fixup_addr-v8-2-c4bfa5193288@nxp.com> References: <20241119-pci_fixup_addr-v8-0-c4bfa5193288@nxp.com> In-Reply-To: <20241119-pci_fixup_addr-v8-0-c4bfa5193288@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=1732045469; l=8867; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=pBEr3qIZ3MtXH8tsEo1g0q/TpoDEnc9FIkQttuF8yAU=; b=KZDByhYYt5+VS4oBF47h3gWxfMGGXGgWkRF98wXxz0OpFfcGPdbHAJ5LWbo/uwZaRYA941MNC 1ndPTBaw00RBfTidx8qI8xR7bKYKW4l9+OWoXpUJ1XZcK5esbwmMvfx X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR05CA0009.namprd05.prod.outlook.com (2603:10b6:a03:33b::14) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|GVXPR04MB11068:EE_ X-MS-Office365-Filtering-Correlation-Id: 8b7987f9-93c7-4cd5-77fb-08dd08d29d6e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|52116014|376014|7416014|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?PLPRDRX3woC6UZElE8zdfuFQd3N0qxz?= =?utf-8?q?o/sfF5XznGgIvt3gVJd3DIHS3oLF67Kq7376bX2SIiSlO3IGVFhtXskilGwTm142n?= =?utf-8?q?xxRv4GS8FtFksftEOwRhpaSH6aM3xVnV33S3QJYEad4MyABxHoHYTBxXaRDsNNSj1?= =?utf-8?q?hgHIX/V+yLRPZ8gizNXDmOxSmup3Sx7LpL5rHvwu13AXYeBiOmrM/vY/dN+qGbK9+?= =?utf-8?q?AndEnBIKysE8dzSu56lfCrG33aTZtlJBnlbDncMRNSdNxQ/iTHAnaOqmOjcH3oQ6o?= =?utf-8?q?r8etW7sudqN6u/YhFtRG2l++WzjIOWjrQkpLVsD3k9MgM8/EDtP5p/tLgDgrO+S1q?= =?utf-8?q?ZK3sKigqpSuUjVRfMYo7CvargATo/KcfZLwkEv6hkvN48O/uC+OepigQt3IN/NXZy?= =?utf-8?q?G2D3F5S2y3lwes6QEBWoXANld2hI1zo2IFBEhpNJMyd8w9gjMaOmlBnzbbZI/fpAa?= =?utf-8?q?beDX/jdp2D1kL5HQ3WWKfzTrlPLj1fKeJ6slfIpgBpHa/wOdHFB7NLUzCGia7FFq7?= =?utf-8?q?hqDqczYAe4rTmZwXo9AzKAGgv1xRWCf7wqVeY2QXf7f+s8JMvob3BLwTVHOJ0aOPk?= =?utf-8?q?8nf/JWuZmU7LZ7DGSoiaoYOqUUMo6Q00OlJm4mEDdtsnVJbjywOxiDYn+d+EH7pRq?= =?utf-8?q?Wl5XqulDsmw9RhFYkM+65umlHN6CzegOnWpqYjwA9YMrmFskVTpuiIMESlMHD8qcW?= =?utf-8?q?2UYg+5yB8LWTujkrnI1JfZJ/PmGk9yCThaBhLD/zRXoZcQc2LcBHg2+U+mn9XxBYT?= =?utf-8?q?TxeMkNqQ2bZo1b7myTY7siH1b1W1ZbBrbprRoBXjGn07zNAFyNIOz9BVmYTmSX6LJ?= =?utf-8?q?y5vFWJ4gvpiKYmiVMkfXWmza9UoN/RrV9WnmfSqBzkCHDXhIy0dZYNLGACG2XBvMO?= =?utf-8?q?JdqFxsd/KP1+zhNpzMFIjw+uTtvObxLiLsj0RVdmjVXT4N9gURjl1WQizwJ9bEWEl?= =?utf-8?q?dC1BRDttuBEYPXspboVaE1DJMiDBhUEbYnTiisPRTSQBjpywEyeJ9OXz3DQncxHLy?= =?utf-8?q?Kb6iGz62k+rkCQ/kj7FsBBuJexfv1m6RAfISMIkJTeLmNRNDvDCVC4g7QEzP715rn?= =?utf-8?q?HQloNt/StTxkb1s2aDTLj4KR8PPNgOqT/D9Q0oh0WltH1YOhShsd1/3E4tfnAKdHD?= =?utf-8?q?FZRuy+Z7NugLsgqDsrgh4GxXEmvgCj3d6hNty+X3+bqzN3NpEcRH4n0to/lCoF7Oi?= =?utf-8?q?oDcQy4feaQkK7QyavwOHYM2fsptpHTZwNrT7Vadoi1985H3V/NgezFHM/PdcJHSNm?= =?utf-8?q?1y2VcR04ivUGbqPDRkwoKK6PWmA7k7pkl82XwbFpsxjNvcYQJHXJbPvBqFaFZvfF+?= =?utf-8?q?4J7WhxCHWeiT?= 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)(52116014)(376014)(7416014)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?+IiDq/r1F9Qb5F2FtOVt/nNrJy+T?= =?utf-8?q?cXRvqnyhnGa5QbXGoA8hZ360LoS+kV2KSSN0kbUD2B5A7GetvLQS5ePO0xlou7KHT?= =?utf-8?q?2Q3aYcSEN2eA0lysDe/4CNkDPMZprPmnALN3kbz6AeFjb3TCfAF6QuLVMTusrgbIt?= =?utf-8?q?I7o14juvHpo++Yazcuu19Q+AuYtY+YnWhRBcKVZgU/LjdSWmdxHdygWkX8+ZXN855?= =?utf-8?q?Bx7h7VREQcftmdXsbXBZ35khTUaWJflkRNowz8P4PF1bJ2/XYN3v+JOtOF0GR7jzr?= =?utf-8?q?6zC07aSfNs9jY4wW0YZy4jbR5BSDqPb/xWuBW004S+x2G3htoqV1QWTM56/ZC7O02?= =?utf-8?q?xSowUGAU43BKyid4aM6kC32ii3Pxb1J6gs2h0hpyG8jrHFrF2OOLnYtC1h7Ai4uzO?= =?utf-8?q?vkyORr+E+kfa9ejvqDGVjIqJE5EZKGbRnwku0a3uu5MHXeTJp35ctixkN7jiyJrXx?= =?utf-8?q?NrQiDhR8AMuPnLA0TJlnNjm7ChNMlNwvvkH1Fcrgsk4L6gAPTpwBAW58naPzEeNQI?= =?utf-8?q?JBDw1B4RtBliR+4Jpxgh+SBP1fb3OvAckdzJ+xfGuyjjGVHaMrSxjsnv1lKBy9mWu?= =?utf-8?q?KXSPIlap8BOy0PJSJw3zR/PcoDrE7aC2JXs4XySPMYVrJecc1p2ZZimtasnqh/Ih0?= =?utf-8?q?5GvYaquSky54/vhDx2Wv7BviaqkGQo1BpFgM22Q9tAJlApUBowMoQ4u8UTy2+R3XG?= =?utf-8?q?FeRjmtdyD/u47P+Eh2hDaO16FoTaAZEspBH9J9ExPwGGEyuytE5vIuCbDindIeud2?= =?utf-8?q?uWmweDnQOphdVqt3ZLIiAr3M4+YQIyw6FNqoXZOagqG5+t75ZR0wSTbGy2ltZjcnH?= =?utf-8?q?CQS60vXFsyWAJHDq89L2fKqlkivjUV4slTyvozu1fHlpkYsbK3fipuq3U9qn5Vffk?= =?utf-8?q?AFexggbiWYV96lc+oDSI5sqV6yHVbjjuFBi28uStrXXvBq0In8LJel0Sz0O+m4fyH?= =?utf-8?q?gDJ9cIxsCNsPpZmAtaR7pTsG9jAVTc1O+tyeHuVRamjhOwrHkm4G2U7FZkMY8vfxi?= =?utf-8?q?c7j3oqgD6KppwF2MflzSDZdTBqXwIUcUtjHcmz6mmjyRA1jimtB48QGxpuj7+1nau?= =?utf-8?q?jtbXUgbyjiOjJsR/7ayLOzlL8kLDRy8tdJ3dV4B5J0jxynhZp0EsDAtdU17rGrCjI?= =?utf-8?q?PIL1MXFKxredMQHYadoWy/CaeDwe2vLL7rl7fA1r03AI8xxdiGi+9NsITcQ/vTxfW?= =?utf-8?q?QPc/fI22hdimyBZSG2+bxA5JUTlamxLp4YkybZxBxbcdMhAQA8dj7B+FZ45R3QPbb?= =?utf-8?q?4DKKtT7njsyKGhGT9Vp59fIJUDRvWirmxqkEUw9TjMZI2mT2kresZgSgUeDVqvULn?= =?utf-8?q?imFsryWMXUiYXJ38GBDsFah6seMRkXgbgVspQKGD5ypXsEjzgzfhPAga/8u5DYFrp?= =?utf-8?q?vILr/ih37DyOn4pCvMhWL7cG6hwtnPZwyHJzWUbjQfuBLUdEEmArOOxqmTGiDRVmE?= =?utf-8?q?rAO00uk0DuCpu9J1Es0VW1nDCnYUbKhaCFhAs6KHKmWC8zQK+5HLxHUA=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b7987f9-93c7-4cd5-77fb-08dd08d29d6e X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2024 19:44:44.9652 (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: F7bHEOBH8hZEi5Wb+wwBJCcdXvxd1iOl92kC8RtRKHqy8OICK2LHXkICz9veKa1jsTtzwpxozSuIGh6DVr/96w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB11068 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241119_114451_063335_DC3DEE49 X-CRM114-Status: GOOD ( 16.64 ) 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 --- 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 | 57 ++++++++++++++++++++++- drivers/pci/controller/dwc/pcie-designware.c | 9 ++++ drivers/pci/controller/dwc/pcie-designware.h | 7 +++ 3 files changed, 72 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..f882b11fd7b94 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_parent_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->use_parent_dt_ranges) { + *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->use_parent_dt_ranges) { + 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); + } + 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,10 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp) pp->io_base = pci_pio_to_address(win->res->start); } + ret = dw_pcie_get_parent_addr(pci, pp->io_bus_addr, &pp->io_base); + if (ret) + return ret; + /* Set default bus ops */ bridge->ops = &dw_pcie_ops; bridge->child_ops = &dw_child_pcie_ops; @@ -722,6 +769,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 +779,15 @@ 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; + ret = dw_pcie_get_parent_addr(pci, entry->res->start, &parent_bus_addr); + if (ret) + return ret; + + 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.c b/drivers/pci/controller/dwc/pcie-designware.c index 6d6cbc8b5b2c6..e1ac9c81ad531 100644 --- a/drivers/pci/controller/dwc/pcie-designware.c +++ b/drivers/pci/controller/dwc/pcie-designware.c @@ -840,6 +840,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 347ab74ac35aa..4f31d4259a0de 100644 --- a/drivers/pci/controller/dwc/pcie-designware.h +++ b/drivers/pci/controller/dwc/pcie-designware.h @@ -463,6 +463,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)