From patchwork Thu Sep 19 22:03:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13808002 X-Patchwork-Delegate: manivannanece23@gmail.com Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013012.outbound.protection.outlook.com [52.101.67.12]) (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 A33681B3730; Thu, 19 Sep 2024 22:04:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.12 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726783456; cv=fail; b=ZUHIIS3WGADIy5uxS5eVn6oXngo1+7f1+HDzVMxAeTzz1KJJ481QsJa3aTNVfberFT3XB0fD43D91foUsiZBIcxF9a1U/JvrirVkMho4BdE8vDtyd1WIjwQZ7RzA7g94mA++avQlLLeFOl7CKQA0V6Q0UeojDvlBF0iQGY99y5s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726783456; c=relaxed/simple; bh=IvDSx+5i049oIIKoV7c+Nt9hoWVe30sf6LUsRsEVyts=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=dFtL1+6tR4kDHaGRpoNS832mTZBW7vl/mwZa3zWBOzabqK3Oy55rug66wJP6ny1joLNmpRWJ7PYopXRD695H1RHP5SVMmZLg2Kzb4bMEwU4PSEJbFY0uAsUk/Xo93i2LrKiks+G1enVPbRz9V9jTYx4G0GT6VdiaDnHdY609M9U= 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=LldW8aq7; arc=fail smtp.client-ip=52.101.67.12 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="LldW8aq7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PlzelnPjjmiENpC0U0nFzvje4TJJhDVcVbEcDJjYqKVA1DGQIejUGvTiI8YsCCxST/KfatNfv6e3roIPma+OpDta9n1DXEUJUtXF6TmLbNhvDrjPUMDt0yRaCIQxefbcW3XE2FVre+dsoMAqnE+r/9fNAHBzx3nDsrB96mIa+Lp8phWwvueJJzv/xC/NgohfjzXExJNQU3atAwW7Qoi4R9CjIv+EUfiaSHCsCjeIqQj6RtQlUjphHLzpnjpU//n+a8ZAZotRSLXbFZsn1+GpvcT3TxO9VaNScZMfPMK8vxGrJxjUavJh1cplmQk0hS9DJgQ+R5zPzcmFxAjf67lqNA== 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=X7Ha+PhzSPk6i0O0WiL73tZPl+bDGRz4gAUcUjnaIKQ=; b=Fd0NowaE6VpwPCzfKujkbt0yjzFTa9TOZW+TBYBqhOMTCMy0gRJDHOX12AloP98XSRG51MHQETlD4tJPPhtgXJOQA9EQ6LbzCUjkcst5iQFOdecFwaMeu2BW321lVWd7MvoPaur8uIHZh6/tvBwzsW2sBsWkJ3PpfBNStG8DwCrTm+kbVeGyJ/X1KFkhglnScqJMHYBhCQaXDZlspAbI0U9KAbwqdTcOkSiym7F7Jx+upUHy3rTB7SicJLdEEcacr9muB/LT4FQ9b11Oz79TsQ+9ni/PMQ+HlvtdSmxIyGdDwlrT5nbHTd9uh2n9Z5xOniAqUP6wVCG5rpmDQkuEvg== 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=X7Ha+PhzSPk6i0O0WiL73tZPl+bDGRz4gAUcUjnaIKQ=; b=LldW8aq72zRis632/wB7V1MgdWR7LSpSriHHQQskTkcPJC19RB7ASDEY3US3ad6fBOUXt0Ts2nGA9/AXZL6lUN+s+sYq1Wl2q7+leYYYHnVfZzUzxVgIzbYhZ2f11UX5etkOrh1fSiZH3rgtqW5cS1OiARc4otTgxvYeZ3McxnEYomb93hIgklc3vIsxrEpwDf/SLmlj9gIZrRdKehwZkUPjrNH4cytt5FXTfx4D8IUx3t5ArE3fR9wGwfX1yCjaH7SbE0DeclTrB9jGxutAk8KjEMz4TjvEQCF0BDqZ8iodJsOOxw2eZuftza8wloO4c28Xi8k8OtyiNcFVonXU/Q== 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 GVXPR04MB9849.eurprd04.prod.outlook.com (2603:10a6:150:112::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.22; Thu, 19 Sep 2024 22:04:11 +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.018; Thu, 19 Sep 2024 22:04:11 +0000 From: Frank Li Date: Thu, 19 Sep 2024 18:03:06 -0400 Subject: [PATCH 6/9] PCI: dwc: ep: Use 'ranges' from DT if 'addr_space' is missing Message-Id: <20240919-pcie_ep_range-v1-6-b3e9d62780b7@nxp.com> References: <20240919-pcie_ep_range-v1-0-b3e9d62780b7@nxp.com> In-Reply-To: <20240919-pcie_ep_range-v1-0-b3e9d62780b7@nxp.com> To: Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Bjorn Helgaas , Krzysztof Kozlowski , Conor Dooley , Abraham I , Saravana Kannan , Jingoo Han , Gustavo Pimentel , Jesper Nilsson , Richard Zhu , Lucas Stach , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam Cc: linux-pci@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@axis.com, linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev, =?utf-8?q?Krzys?= =?utf-8?q?ztof_Wilczy=C5=84ski?= , Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1726783409; l=2289; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=IvDSx+5i049oIIKoV7c+Nt9hoWVe30sf6LUsRsEVyts=; b=jz60UOGw+jLEXYfe4F9c3vtcL5GqAwzNZpasMWSInrFNVVaw8bWcSDvN4hpdlGnKkASZVxNE+ BZImx7+vWQ3Cft3dXQei5jNMSdV0b/4x2ZH6kZXt9iyieTR8p9Yttnw X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR05CA0057.namprd05.prod.outlook.com (2603:10b6:a03:33f::32) 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_|GVXPR04MB9849:EE_ X-MS-Office365-Filtering-Correlation-Id: a433eefb-3742-4fde-6785-08dcd8f6fe1b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|7416014|376014|366016|1800799024|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?II9Vk8UI7BOj3x7vfD7UnoGf5KpykIV?= =?utf-8?q?zJkN4yr9Nai5oQUVZE6xi3LAwQJh/h3g+gNeIuWw6/8RT9gGmB844MFgiHxmMpfO6?= =?utf-8?q?qGSFUriU68qq+YHvqTy+hbJepi2mDaMxT6YBN2gF/nY5ikArLwj67jVWT3WPTPJo7?= =?utf-8?q?SIEEFYjC5krhnvfG9EuCILGLfvggOC6Du30CG1vmPrF3/gIJ55KuTBCthhpifFWnC?= =?utf-8?q?hjkNpU5D8yRV/7xDr1uNbCZYJya6XAnIrAgNIODfxoGWHirrt+zdMs+2DIAt4F9Gn?= =?utf-8?q?NIFgY9puQLvyQ116XLecJWACjW9cXFJRIyD9Ka+GgwtEB8fzS2ZkS8H3Bbpn0SyLd?= =?utf-8?q?+s7HDUPIapFccu7JTNjCW15TBoAfFm2oeTVtd+ZaohVzSxgdC96O2p4uwrZql/Y7G?= =?utf-8?q?gQj0pwz3OcTXs8NMFODH20kBP56OItDwcQfvFTubetSKxZQinhpp6/D8VNzyrKF5S?= =?utf-8?q?BOLUuJscRAcnB8wGmvABMajJW3UnRViJn8f6FTpp+DHQlzKN1erYENbDq1FTDDTte?= =?utf-8?q?zcOgQUqLFTWxqAnalLYwfl0geUIGj1vWZy2XvaV/AuH1I0hR3qtvBjcNOFxCqPlPS?= =?utf-8?q?PWSbuTgEzKjVEymrbUVDtyzzNv1mm2+UGBearoUaI9vFZPWbC7RnWCj3dBYaw7NU1?= =?utf-8?q?inHjPvM1FHqZLd30cy9Q6EFtvvbN+hEzZfE7nh73+rKMZnODpK9NgOtnmAGxtbOGe?= =?utf-8?q?HGQZqWjj8BiXiudZddHbkYoN8wfCFr/AXj9oHOBH+rPKnEgWqVUi7txCxNhfNgOY7?= =?utf-8?q?9xFmWCgo81MviMcKYHTZHn3LekgGH/lL1HXnmpl0p0d0VcvJyvsEux75vv2YYNG6J?= =?utf-8?q?kAZTcFkIIO3CJaeoON0z7ijyBOsXBpWYVEtJe4i0hCf+kRMjUtOxlZL2/X/prv0r9?= =?utf-8?q?zy0AjgxMJEGThEidCfF3SD2TWtt8wcj89oP3KONqjcXvD/wrUiZ990kx7uu426gmr?= =?utf-8?q?CJoXDlEsQudTqKCp3p7dL1Cjy8TpXYsrem26GT00BGcdWwsSCbjBOk4/8h14GqVjq?= =?utf-8?q?9z/F3SpL1PED4lROEDo0ll/d9mR/KQ2xU9VAHMrdJQO0uBz2SO/bbmR03zD845KNK?= =?utf-8?q?MORxE4fAvAPeNGVHozrXa99wdKl6V/ThGqcpjfrw6kMPA8wUC7CkEwTCyuEUr9OYQ?= =?utf-8?q?XT2PEOsIOot+UuhQcmJi5bJd4CtDtKpErimHpz7PLciW2x4EDYTMy0wsYfhaEwfkx?= =?utf-8?q?Ng1KT4ArAgtQZek0s+mV7PuSWjLEzQUDp/DwGQxSaoiDw4twKHkbhczx9tjHcvrDo?= =?utf-8?q?No+IkenH0A5n74yZmpQ1ad6quPNkZhcMP08mdMN57vhn1w7YHGkbz/jlCSbcMiVwz?= =?utf-8?q?4qOf2gmbHraI9rqSDVng7bFjnWuYYep3+uYJ4Ax11VkB58v+wzrY0as=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)(52116014)(7416014)(376014)(366016)(1800799024)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =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LJ9tAAX8mNDWHMBXN/NWKtM+tm3fN+tcDZelacNhg?= =?utf-8?q?eLUrSW/4tlQE0xW8IZvYN2eLZhZ9K9hzqB+tktVuQTKQxqnMbnVG4eHTdPUEIJV3P?= =?utf-8?q?BwFJ8hZCNcQsiNoYQMYBZtUQIt2NLCocySnNKClHlYdhiqzoRs3XYZVr047mUZFxW?= =?utf-8?q?AmZY2oTcs9+5t18XzIvf5DMea3tKLrWOcMfzFMJ4njzNK+R+Hd7AgEm1hsc5ZmeWs?= =?utf-8?q?85BML7kPU/xRzIMOLt1LTK35FE7AehxwERo9asVFQ6bjwrDYp3/7GpyOwqQ459TyV?= =?utf-8?q?mNTYGM22KXqkQo9E43NpCBajAbm7JjnIhlv2bBnXLaRSFuZlL+FI9Ld/mWpDyJc+8?= =?utf-8?q?e4RZSg6LfLdnzKqYYsVQiCSCAJhEOlHDQ04ETZr3zNiQy+rKfhbBL0kHlIyjGW8yW?= =?utf-8?q?EeJVA0U2pbgBtB2M8pbmPejTPlRI6QJIXRm1fF6E1eHow+tKtFdxCD7c0fY32CXq+?= =?utf-8?q?jE8EGmByKxz+tWx25z9K0UwN5PzQQdTm3VHP1itZwj+cxjLuwyY9P1CpY5dJF9Of3?= =?utf-8?q?mMMibrx5wgWoMUJd5HU94DhGAbfTnjTNqVeqfWNJ0ttTDt8Wbu0FfCRLpJ24zUrTg?= =?utf-8?q?6BEjL9DLP3b0mAXGeeYFO0dJ4cKeUpmuK9pdvszFwcgfcwboYiOKer4T+Eh5Adho0?= =?utf-8?q?uUCJgXd9xcBi?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: a433eefb-3742-4fde-6785-08dcd8f6fe1b X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2024 22:04:11.7657 (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: PnQlMB0pO35G2L7K+t095RhmL8kKLAEVhnb3rhJWsfXmrKmnFHwwtRxDNSND2QDPOlZgX6hCULJbtzEoNitGjg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB9849 Some systems (such as i.MX8QXP) have different CPU and PCI addresses, requiring address translation. If 'addr_space' is missing, retrieve the address translation information from the 'ranges' property in the device tree. This allows support for systems where CPU and PCI addresses differ without relying solely on 'addr_space'. Update the driver to use 'ranges' from the device tree when 'addr_space' is not provided, keeping compatibility with existed systems. Signed-off-by: Frank Li --- drivers/pci/controller/dwc/pcie-designware-ep.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c index feac1a435f764..1b013d2fe694a 100644 --- a/drivers/pci/controller/dwc/pcie-designware-ep.c +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c @@ -294,7 +294,7 @@ static int dw_pcie_ep_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no, atu.func_no = func_no; atu.type = PCIE_ATU_TYPE_MEM; - atu.cpu_addr = addr; + atu.cpu_addr = addr + ep->range.bus_addr - ep->range.cpu_addr; atu.pci_addr = pci_addr; atu.size = size; ret = dw_pcie_ep_outbound_atu(ep, &atu); @@ -861,6 +861,7 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) struct device *dev = pci->dev; struct platform_device *pdev = to_platform_device(dev); struct device_node *np = dev->of_node; + struct of_pci_range_parser parser; INIT_LIST_HEAD(&ep->func_list); @@ -869,11 +870,21 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) return ret; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "addr_space"); - if (!res) - return -EINVAL; + if (!res) { + ret = of_pci_range_parser_init(&parser, np); + if (ret) + return ret; + + for_each_of_pci_range(&parser, &ep->range) + if ((ep->range.flags & IORESOURCE_TYPE_BITS) == IORESOURCE_MEM) + break; - ep->range.cpu_addr = ep->range.pci_addr = res->start; - ep->range.size = resource_size(res); + if (!ep->range.size) + return -EINVAL; + } else { + ep->range.cpu_addr = ep->range.bus_addr = res->start; + ep->range.size = resource_size(res); + } if (ep->ops->pre_init) ep->ops->pre_init(ep);