From patchwork Tue Sep 24 21:54: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: 13811246 Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazon11011045.outbound.protection.outlook.com [52.101.65.45]) (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 62559146D57; Tue, 24 Sep 2024 21:54:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.65.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727214893; cv=fail; b=pRXKPx4PcE8uyc0t81wgG6kWPtitPEoo8vtf02LuAsr2UgWTxSuCj1wN268W6GmE+dPg6o6mNfeD+tFisk5OgTnnh2N38o05gQe3yIvlc83t8T6OdfPMsIQnwqk0/Zc4j00dVYvjm7zV6EoHkYYvurgJ0+6euegVNkmvuPoGS5Y= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727214893; c=relaxed/simple; bh=BeyPTbzXB0p83a1iDoPE8wdWVX5cIR92xtr2AQREEaE=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=Zxg+E7wcMZBgJkFfk8YKH3leqApD+uK/XWekFPUZhXZnFmbw3TwOsXgCg9KKh+yINssTYrUnDoFYiPVMlfHwmWtLJnfhhUsl1idowbadrkZp6wnvbBRe1Wt/C7VBLgc9FIgoXChOtifjQiTj2dRgda0DCgDelK4N/wzqt37Cnyo= 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=diXVmmxm; arc=fail smtp.client-ip=52.101.65.45 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="diXVmmxm" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sViUq7u7Q6RhWZLo9CvP97FGi6ZY/JJblpxQ0HKyG46yHiJRO4FvPHIcjDijZfEspJqVBDTAQkXh3cGOmVVe7A9PsSC4V1O3AfFEiKQM7oX6EJCkoaM59Wm5zLNMZsvmvmK8Tsy2iAsntgZzF+ExI5SCsgtNHE862AxCNXKujmHXjZc9ji/wB5M/jXqLLHLi+r7+mowZ/KaGYrQZLS0+pWocfzbebyg5Evk/7QZHCA4uiv/JCc9nX6HrB0aUXUa4yWKyQC7P4CUK0Z2WS0IdHfyn1ch3GgbC9mRQ8nWCVJC/8xci7WJjSPDevVd7l+va8oJzl2qPizenwgu2gWqV4g== 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=9RoEzTNJc4n8DQOkJda0OBl5sxDTOoJ+3O175i+1cbc=; b=iYU6tXLW7tZntx8acZTEMEqyudMYSe3yAlrB5Yg2O8UgxeUNI1E+jVbPdRcjsUrgb+wD3+Fg9XryVJMHgzns7Q/2p47tq9k53vx6vCBA1kgbKyfcVnEBBmwEDeU/66qXSTOsnTDQpgK8SzJyltFb+d+46T4Ufswi4/4Tv0YJ3vIjSyRxDek8ozvBJUAtFvItZt7eHqemDrv6Cuqpa2zUP/go29sGdUUSDPOzLEed9mthzpdTCrHUl9O1DbfQrnOi7A04jvPrL6/z9WY1ciTgIkVd+1UwlzGhTHWhMYtZgRK6F9nXZh3umuGp4bifn/0J6vax/d2d5QR6Crg7GwrzJw== 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=9RoEzTNJc4n8DQOkJda0OBl5sxDTOoJ+3O175i+1cbc=; b=diXVmmxmK1e7bNZKL2ojrCJH+/vOmt0DLLydt7ulAGbyqbY2kS6VfD92Tj05UKrfBMNNGgiqVy2NPQ5nWVuRwrFjue7oDqiTnxlLaADtiUnFlV27TgZvM+s71Ux79GLNmJwCHUo/cra9uDvkllAEwIlqp2iX7F6TLQrHSAL475/E6053kGVsjMoiyKZYUxnB88JInxsTO0CnKVUmqgDjNU/8yPKVFE565qoEFbhMyuX9oTkk+rhdlF1EmSCrOCTKO5cP8jOB+bOyzZZuqdziXNTf6OuvFSKkaUbZi2YldO8zNqtaQnWERCtqlp/vNlTOC3UJFDUC8pswh6YW4FU5SA== 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 AM8PR04MB7953.eurprd04.prod.outlook.com (2603:10a6:20b:246::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.27; Tue, 24 Sep 2024 21:54:48 +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.7982.022; Tue, 24 Sep 2024 21:54:48 +0000 From: Frank Li Date: Tue, 24 Sep 2024 17:54:20 -0400 Subject: [PATCH 2/3] PCI: dwc: Using for_each_of_range_untranslate to elminate cpu_addr_fixup() Message-Id: <20240924-pci_fixup_addr-v1-2-57d14a91ec4f@nxp.com> References: <20240924-pci_fixup_addr-v1-0-57d14a91ec4f@nxp.com> In-Reply-To: <20240924-pci_fixup_addr-v1-0-57d14a91ec4f@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=1727214875; l=5033; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=BeyPTbzXB0p83a1iDoPE8wdWVX5cIR92xtr2AQREEaE=; b=SsLwtq0uV9JmndeiSrDufhL7glkNzted4mzPwT6wF9YqeWfdiK+eHUohpQUakGQN7DMKaEWmZ xh0vrE7ikq4BsPtrmSGqbXHbN/F341JaWHyMQTKIJevviXQZFIN+mv7 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY5PR20CA0023.namprd20.prod.outlook.com (2603:10b6:a03:1f4::36) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AM8PR04MB7953:EE_ X-MS-Office365-Filtering-Correlation-Id: d6223548-0c59-4bed-adeb-08dcdce382ad X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|52116014|366016|1800799024|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?yUvOZJw2+Xwv/SgS2tGRdovEPqT8r6J?= =?utf-8?q?MIYqXQlHbCaf/1jQyqGAGF110+V2NRC7PCw6QaD1Wy6coea3SqmUiGfUe+StIrTAQ?= =?utf-8?q?leGd7xgACzSVppNtNk65N60/e09mCJNt0GKip32B6hAKHn1TZUI7sagkM9/9Phx5y?= =?utf-8?q?tI82dFVVtUzVu0wqNXYZmWZvesICeq/wPaX4DtGTJLgnjou4uWFaV+0U2b5I2aVN3?= =?utf-8?q?rfL/XHHjBRmO3AHuiocw4McHkbKPbilajAcRTF5kfXLsOST31OXntSFOV+gjXweJH?= =?utf-8?q?uqvKj1yIflCrVD/3Nn+NLE4+yi4HlTmFFfSNR9fRB6q51F6LEQ9Jgc7owC2VNERJx?= =?utf-8?q?3AlXwgFMaFPzSF4XKuE7aSIEzEkvQ2iwjGNEfxWZatbZMnuvnzuK12RuySxG73ouQ?= =?utf-8?q?fkMmvQzDS129hjRB6hQNoLuDdpzqsaDHasK0dSjiO9LtUuXAT745z6jPByBYZi1oO?= =?utf-8?q?xg09F9m8GebE1mscJm6CHSLbr3jQz59YNWmrcbWo9yKJ6OyJFiXjPusv9H4Tell2f?= =?utf-8?q?szqnquQd46M4W3S96SVMf+x1MwU1TvIxIs+o6/oOhbAJxpyfuWIwqJaBtVxZPn3rJ?= =?utf-8?q?OgntW+gqBXnLqluiXSvoWteV6FhxiCyQuU4KFcKnEmgsCaDMrFJyw0xvig1Ul7Qwt?= =?utf-8?q?1+AhrkGRjnnM+pMi5e7G0yFiNIwu9EthNRdMuKqRio/dcLKtDbSLJltZsYixvX2SE?= =?utf-8?q?+bIsNw/nARKePFfYzs7mimW0aUzwGAcG7iyRXPN0k55R1Ml7jSug2Z9Gf9hGPauj0?= =?utf-8?q?YRejrDHo3xuCpMn6C+tTMBYSN2nQBeOy8UchSZchGhEq8BfJHeBzfIXhlIwTxbDdB?= =?utf-8?q?3Ct20Ivz+s9wKd1DEiLQqdJRW3tpYFzgy4PeWuBy/4oTcCMdP/GWm7/5LELV0xx+6?= =?utf-8?q?UTmdpG8vmoDbvquEy+ORH7mXti/fjpY0ls3DklkL8jWizvc6eiyJnPGdzPWU6RYOo?= =?utf-8?q?CDsQRzdHOsfNGC6nJ85VdbzMiLDTaj67WgmeEROCYrxAeukjJyuZxIekmGU448jwb?= =?utf-8?q?YmSItTbkc5g5N3KiFy0zv/OxPQlfqAnQ3chtCB0jtj1axBvWU66MGRsjDefPBYiw0?= =?utf-8?q?3/hhelZLPopgH9i6Mn5ZPoSOPKJ08ZV0mFRvmXEFTlTZTjXUMHujRQ/w4NSe8KikG?= =?utf-8?q?FPXpZ/0WkQHYd17irhj3MFrcKRqxBgYs/gxRAA8SFXXLqY0xXqltHvSmb3IIlv0of?= =?utf-8?q?Fg/AtUiYbOUko74Po/hxRfMzjMnEtL+nLpDSTKpYhf1HmyWLr+TY3l0EOY85FUEPP?= =?utf-8?q?4GTY7L83RWbEanA8m0M2lee8Za04uTA93PuBzvO08stIXr3IUCaeKS4A6RL1TAKuJ?= =?utf-8?q?DQ28A+YynqnnRj5nlygRhf75fCWpAqOCSN9nIhAFINxlZUzHRraQ8no=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)(7416014)(376014)(52116014)(366016)(1800799024)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?qMS6GwqmQUFypU6Ukrxgj1klmSaE?= =?utf-8?q?fivyn/JN0TgUylDnqhTSLLPLuUhLGNqKC9BUAXfdBWWMZvAeTSVA+HtVq6SlP+m2W?= =?utf-8?q?f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-8?q?Tr13jfN3PcIPIY4o2bZRpsd1VaGkjhP5HHolM6NW0sClr13xhmyuF7m6ooIUUqtAo?= =?utf-8?q?c1W65HrV2IliFF8YPFCJBM47TQDqW/vaxayVTWGJje/h6f/PP2GlNiRv2AqaS2/mV?= =?utf-8?q?GYbCCfCtlrfqe1ExGkA0oct+WfTaaLjkNKytATPTidMi6ZoPcoKRjKjwPMRYBCh4N?= =?utf-8?q?mzSA9CpogsAdWonOCQCqS20xvx6Y8kYGm8Bi9NQK2fr4vx/3mqz7QVAzR7OjGa6Zn?= =?utf-8?q?wQAqEom4jGJ52MBgwFi1ZpGjQZ6QaKgZ64O7gu03gr+Ne06zZufUPHCTcIv3WZ90y?= =?utf-8?q?wNz8GqGsMiGayefYtke/DMCMNR+cSNvEp2hLHWDdeVw3TqmTni00q5zSUKrWIbG93?= =?utf-8?q?3OZWqCDp1+e5RnL6sZAwfrddkORZTbxqnTjVmm7cKw5Gb/NG8Pzj5KK33h9ZUkTud?= =?utf-8?q?D7eOPAFfBBZ+orYlNvZXFTfncg0DtmDLKDaEgfABumkZZnVJ66ficD7OxfQXYgPV4?= =?utf-8?q?aHpqOoCI6Lxm5tAwLy4ubJuK/1Pvn/TUBwVkNLu1EBIiB9MT/gF4Hzd8=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d6223548-0c59-4bed-adeb-08dcdce382ad X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Sep 2024 21:54:48.8593 (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: EmLY7S02ij7hTB2IHCeZu+4jGHBSra3YDtyWwINU5DtjPa8K5Z2zd8wdgr6manIv6REClXZxZJQ9WSwDUYW1vA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7953 for_each_of_range_untranslate() can get address informaiton just ahead of PCIe controller. Most system it is the same as CPU address, but some hardware like i.MX8QXP convert it to difference address by bus fabric. See below diagram: ┌─────────┐ ┌────────────┐ ┌─────┐ │ │ IA: 0x8ff0_0000 │ │ │ CPU ├───►│ BUS ├─────────────────┐ │ PCI │ └─────┘ │ │ IA: 0x8ff8_0000 │ │ │ CPU Addr │ Fabric ├─────────────┐ │ │ Controller │ 0x7000_0000 │ │ │ │ │ │ │ │ │ │ │ │ PCI Addr │ │ │ └──► CfgSpace ─┼────────────► │ ├─────────┐ │ │ │ 0 │ │ │ │ │ │ └─────────┘ │ └──────► IOSpace ─┼────────────► │ │ │ 0 │ │ │ └──────────► MemSpace ─┼────────────► IA: 0x8000_0000 │ │ 0x8000_0000 └────────────┘ bus@5f000000 { compatible = "simple-bus"; #address-cells = <1>; #size-cells = <1>; ranges = <0x5f000000 0x0 0x5f000000 0x21000000>, <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 'IA' here means the address just before PCIe controle. After ATU use this IA instead CPU address, cpu_addr_fixup() can be removed. Signed-off-by: Frank Li --- drivers/pci/controller/dwc/pcie-designware-host.c | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c index 3e41865c72904..68c679a2e1737 100644 --- a/drivers/pci/controller/dwc/pcie-designware-host.c +++ b/drivers/pci/controller/dwc/pcie-designware-host.c @@ -418,6 +418,27 @@ static void dw_pcie_host_request_msg_tlp_res(struct dw_pcie_rp *pp) } } +static int dw_pcie_get_untranslate_addr(struct device_node *np, resource_size_t pci_addr, + resource_size_t *i_addr) +{ + struct of_range_parser parser; + struct of_range range; + int ret; + + ret = of_range_parser_init(&parser, np); + if (ret) + return ret; + + for_each_of_pci_range_untranslate(&parser, &range) { + if (pci_addr == range.bus_addr) { + *i_addr = range.cpu_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 +448,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 +462,11 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp) pp->cfg0_size = resource_size(res); pp->cfg0_base = res->start; + index = of_property_match_string(np, "reg-names", "config"); + if (index < 0) + return -EINVAL; + 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 +489,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(np, 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 +763,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->dev->of_node, 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) -