From patchwork Tue Sep 24 21:54:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13811256 Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazon11011005.outbound.protection.outlook.com [52.101.65.5]) (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 A3255149E1A for ; Tue, 24 Sep 2024 21:54:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.65.5 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727214887; cv=fail; b=ePJ0kTJRTzn3Z9bSpva+HvKzC4w7kZlfex5poO+rR/ur/cxOYDzRn0Diukqz6Ws0CM1znGrA8WzjeqI4EBvalqXAGvUnX05CQM1DlvlVu/k1Z9CA45BPaZvDeGvXcwCdLB3SmVFoR7S7m7dR64D0mMjYogxZmpraf+Weg/waXvM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727214887; c=relaxed/simple; bh=z4KaswFJYOePVkot3vtaaDaA7AqrHslIbrV1jsqJ4FY=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=FNT7NYyQFdOiwgFOKr5b3gwdOesoGl62syTaACZE583gM7cWVphoUQ6dqxMKL5O9gMVZJe3BoKhNoZfQ5H3HN3RfoWds7BrpWjn7XS3we+ORwHh3sX7Bycwm9GzkdyM2Jkp3exwBLzpMKXtEJVJbbOmG0XWhT6qZ3OyMuF3Ut2A= 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=KbzyCQnl; arc=fail smtp.client-ip=52.101.65.5 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="KbzyCQnl" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Mj8Yv/z4E3zqjOAuoGRoMqjUDo/qFdEc6bLpx/iACevm5Y+PdCRQdVBdNvsyNor2E80HnXXJwCQ4FXEfMGncLiVF2LOK21oSaewAtKEj5BRLwXMk2VjO7GxX7xpRoOCgkr316fvjJlnG4ZpaXMEDetdZhKI4y2nLgBaChLglEx1/yFEH7a8XK/8yWX4euyWp4mbfjWHeSVpreAOowKjJmTmO9Y/qaVkrrUZt6ZKIJpYi34igbmfp2/78DU06G6/XAWrzYRDbpnTVSRt/s/NdJWfe7AGM8yXsxU2ZsFT6zFSukuCVd415lu5ql2uC4xYte9W3rC1xIlc16qMiU/NcXQ== 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=xN+yv2c3XxYPdVprLkTMIJC2lil7IeASvtS18gALS4Y=; b=qtQRcafNdsa9Zm+2my51dUzVw0yUkly9WnBqjCkzxc7o5dQfWruu/wG5r8R0IY6yk03Wsp8FZfXT+BKs5n0H6dx5ZpOHZQrmPRpffBM+4EUaBFlO/xkmhSxn6C9OyHuDR93aRQyP8cIKb2D70ayDNMRscJKGfQy+PXotaYU2QWzpaCRuD4oxTXEvc0CDpZrnBnDAergql3Ij4NWKJXenkyGlT10f7zsvbY75YsiMyv+4yEevBYqchhjZC7eMNzd53DW5uGldIJ8ub91HZkv/clrk9nI7qL51ahWnT1LT3FIh8b/l7wRW89G8tpPy4XhoWk6UftxvisO7OxxR0iP1Rw== 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=xN+yv2c3XxYPdVprLkTMIJC2lil7IeASvtS18gALS4Y=; b=KbzyCQnl5Hel+ULqZ0oiNzOjbv9nLvmMwHUNs6t629xoS75POgdzHOUTqd4geb/wQLdB/X6CFldR0nHhaxAwlO/lxvdOGeWTKk1fWqqFWTJa1Wtn9Jr46/mXCbr1uHXdrX5J5ETpfOpfGG8I2/J3XH8ZToDNwgQUZUd7bXXT6oMFfHShPyFGOVO2id0btoZsmeWonomjaBX7yO8BbqzgWOj50FSLUMRBAjjO4xP2c4vt4ahGUdHtwB5jU5T3Mx0+P8fmud0wJ5mufXm4WkueSClZxsWNjq6MCwjdqFqyj3SETCJVi+oWxNjqnp1Fll++xNnB48r5tgjnC9f/nNHhAg== 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:44 +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:44 +0000 From: Frank Li Date: Tue, 24 Sep 2024 17:54:19 -0400 Subject: [PATCH 1/3] of: address: Add helper function to get untranslated 'ranges' information Message-Id: <20240924-pci_fixup_addr-v1-1-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=7228; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=z4KaswFJYOePVkot3vtaaDaA7AqrHslIbrV1jsqJ4FY=; b=vdiTM/i9IXmSRCY8OIRTUgBORXi6IhsA05iSjV+r0f+Wjozi/1DoExUY+j0YsF1uqcc+hkwLw 6C4E/T7BV8qCN04UWEcJ6uE0zamT8VHdNbcjkGH8qQDqRW/+HNUG3p4 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: imx@lists.linux.dev 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: 520c3e4d-4506-48af-5e15-08dcdce37fec 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?LWkDbHoaCY7szP8o5V1lzoZ6ptXILR/?= =?utf-8?q?0x6kPbc+D2HMwxBKoNKEtQV2mwOKAXaqvSuJc9XUwP8nwFEsQDT2irPPw9DZV/SF1?= =?utf-8?q?2H/tXwivFg8uDd1hMLbi6/PFCFHWUZ0SZ2C+oG3/eL6cucfUAXuJdtSEBN9dv0yWf?= =?utf-8?q?VgW8qb+eihHKrUcN2+ITp4MptOV/+HmHb/goHEyx6tuSG3I7ollyNFQdTtdeWQoIO?= =?utf-8?q?Fww3eYvfL2SrR7MEbB1lLgEa3FnJCQlg/+HcV8UQ2mJMrlDjpe/dvMpv230LkyfG4?= =?utf-8?q?sZT/gUr/+8pgUDNl+tWICQMvq6VKeTI7GQ7bypHHQk1iU2XIB+nARn0+yomCVmJJw?= =?utf-8?q?HFRpOOqGwU0RpTJuMfBVqT5th/GnQODkiH1IAYSpzAG5gCWTLdzwDnnuJCzE6dwJ+?= =?utf-8?q?T1N3B2dPpVBs+CmfVIagBY482D5d69EH0CRDIWoN3L6I3RC5W+/feDUUOZ4y3/RhP?= =?utf-8?q?zFSHZyBjDTFcZAcdsoTckoapjnFG8aJTeyvh+wmSUHZ88Dovpv+QlBHwJkNk9uLxP?= =?utf-8?q?d1A9rpXqbGuKIPlYccj09qbH1MLayvOjXovk4xM+eT7iGNv7JruRck6/IP5m5wGRB?= =?utf-8?q?1yxHyiMrQcxgPiR12E1250M3eOLLlfNmasgUEEVtTdQHRA2KnF3RtUQNrMW49teSl?= =?utf-8?q?xaPckirSf1Sb6pbHAw4r62JdW7FYD/7XWqyaCCbFJHj5Wr8VO3dX1PXKeqYwu2kWM?= =?utf-8?q?MYs2NteOhtPo2IDbokw42J7sRKC9TwgGukQolI5SsLW1p1RbOqfKAzcgqOvWW17Sr?= =?utf-8?q?zSLH0V61H+7rkHSdLZMT5ARF9YC7XWBHpQzT11+qZGQiHkNCcAc9NrGr9+bFiEPE8?= =?utf-8?q?/8JZ5Cj3C166UJi8QPsXZDfKP1QtrBlRtHyJRUsvA2UaudFVYPhtgXjimLLs7ruRX?= =?utf-8?q?nAFqOOjQLmESGpWIpa0HkLRwIF3hi8vGsU4NyN2upzZFpjpJk5lJW4GiATCLykqsw?= =?utf-8?q?sGYxnIk20L699y9DrkoarVpzX9C2JknaoCYglAINKuRrFlRvR+kams+5kUNOsQB8Y?= =?utf-8?q?B/DPwCT+yPw8xlqOgLAb+Z9irs7vrkP1FeoZAqqfqExusR4HwrzsLg3QF8GOvEROn?= =?utf-8?q?lL5w5NQttwpIzi3IxEGWcY1kysE5+GxQav0zUnyoHk8uV8jhhwx1zblO9v1NuNK+S?= =?utf-8?q?nVwbQEO1oLqJ1z9OltYOGWq3bZuzT5mcWbDJ1qsSgMkmLetvBY3RHK1d5oDOnMYze?= =?utf-8?q?i6drkzwBJ0QTy8GK0A9IHfuxcXaGGf2wY10VdFSqY8kzklWWSc4H7yGzGrhC/HgY7?= =?utf-8?q?ccJ3zmqqUou+kRzsFT+Flbwc64kDre164C4BO5cmHDj9BGE53GGFELz+JRdIsHDUs?= =?utf-8?q?H1dgipfFW1wjMcmBCHXIsIr37v/nya6nEe5+1UJLoXdN5WExpYcp+jA=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?jX+ioKuI2aOR/tN57yg1xhxwb8fr?= =?utf-8?q?suVqQgUnY2UzW5tzCZXZ8zdlnrRou3guKCC8hO/+ZRall9TuZgWyIZ75cIlsLRRCo?= =?utf-8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Y+2yZ0zI+K+vK84Dx/yyHyXCrNgyTrswRzkHZ1w46vMonX9p7uPi8zbuF+8Btdm0O?= =?utf-8?q?eMc3mP/7SZn22CE0W5ODAr42/4pE9TcruLCUHaI1HyjIBPInX7lPgQh8UtZUXIcNi?= =?utf-8?q?JVKi9lniS2quUBtrIVj7yiR7Ws13plAp53UFRxt7ixKH5WAYl8zYhzNiOgtVuEMJT?= =?utf-8?q?csJGmBscjEYIaSgdytwgHyI55Jym3b8vOW0s6dH/hooLUU45OOYLZSV2ETZ9RI5/Q?= =?utf-8?q?IwfXZ1chqH6cviLm8wm4+Ytqg4fc61aWT6bgUz5OWzbpt429Fs7Xvpjp0y0daRJos?= =?utf-8?q?7E7ecabjg03R9ULF4exj/Sl7CePloCQKdX8m3eSJnNWeW7ESvxog04j+Wl2kog8cm?= =?utf-8?q?T8F+s6FEQYmVlW/sPBVH29fA3rOb1bPPQZrGf0wO/AU99TdckMSFoaJIM0AM4jTLF?= =?utf-8?q?HZEQ9c9/H2BWUKBswlcQiOLKK+3+MeLJDJtgplNbRaEmi/xQNVSGhzNiu9Jlya0+0?= =?utf-8?q?1UnfbVGkf+UKbhLz8ouJ+iAUvJ+XbLma8VfRqEB4JnXwe724LRFjvvcI=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 520c3e4d-4506-48af-5e15-08dcdce37fec 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:44.2479 (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: xlH/YPmN1kfSyRt+S4CqWKmm0g+BCZJihXm89zcF51eYFl4LBlP1FP11v8GfzYgsKdkI7IYT5kMYkntPnlUC8Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7953 Introduce `for_each_of_range_untranslate()` to retrieve untranslated CPU address information, similar to `of_property_read_reg()`. This is required for hardware like i.MX8QXP to configure the PCIe controller ATU and eliminate the need for workaround address fixups in drivers. Currently, many drivers use hardcoded CPU addresses for fixups, but this information is already described in the Device Tree. With correct hardware descriptions, such fixups can be removed. ┌─────────┐ ┌────────────┐ ┌─────┐ │ │ 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>; pcieb: 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>; ... }; }; Currently all function related 'range' return CPU address. THe new help function for_each_of_range_untranslate() can get above diagram IA address informaiton. Signed-off-by: Frank Li --- drivers/of/address.c | 33 +++++++++++++++++++++++---------- include/linux/of_address.h | 9 ++++++++- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 286f0c161e332..09c73936e573f 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -787,8 +787,9 @@ int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser, EXPORT_SYMBOL_GPL(of_pci_dma_range_parser_init); #define of_dma_range_parser_init of_pci_dma_range_parser_init -struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser, - struct of_pci_range *range) +struct of_pci_range *of_pci_range_parser_one_common(struct of_pci_range_parser *parser, + struct of_pci_range *range, + bool translate) { int na = parser->na; int ns = parser->ns; @@ -806,11 +807,13 @@ struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser, range->bus_addr = of_read_number(parser->range + busflag_na, na - busflag_na); if (parser->dma) - range->cpu_addr = of_translate_dma_address(parser->node, - parser->range + na); + range->cpu_addr = translate ? of_translate_dma_address(parser->node, + parser->range + na) : + of_read_number(parser->range + na, parser->pna); else - range->cpu_addr = of_translate_address(parser->node, - parser->range + na); + range->cpu_addr = translate ? of_translate_address(parser->node, + parser->range + na) : + of_read_number(parser->range + na, parser->pna); range->size = of_read_number(parser->range + parser->pna + na, ns); parser->range += np; @@ -823,11 +826,13 @@ struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser, flags = parser->bus->get_flags(parser->range); bus_addr = of_read_number(parser->range + busflag_na, na - busflag_na); if (parser->dma) - cpu_addr = of_translate_dma_address(parser->node, - parser->range + na); + cpu_addr = translate ? of_translate_dma_address(parser->node, + parser->range + na) : + of_read_number(parser->range + np, np); else - cpu_addr = of_translate_address(parser->node, - parser->range + na); + cpu_addr = translate ? of_translate_address(parser->node, + parser->range + na) : + of_read_number(parser->range + np, np); size = of_read_number(parser->range + parser->pna + na, ns); if (flags != range->flags) @@ -842,6 +847,14 @@ struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser, return range; } +EXPORT_SYMBOL_GPL(of_pci_range_parser_one_common); + +struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser, + struct of_pci_range *range) +{ + return of_pci_range_parser_one_common(parser, range, true); +} + EXPORT_SYMBOL_GPL(of_pci_range_parser_one); static u64 of_translate_ioport(struct device_node *dev, const __be32 *in_addr, diff --git a/include/linux/of_address.h b/include/linux/of_address.h index 26a19daf0d092..692aae853217a 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -32,8 +32,11 @@ struct of_pci_range { #define of_range of_pci_range #define for_each_of_pci_range(parser, range) \ - for (; of_pci_range_parser_one(parser, range);) + for (; of_pci_range_parser_one_common(parser, range, true);) +#define for_each_of_pci_range_untranslate(parser, range) \ + for (; of_pci_range_parser_one_common(parser, range, false);) #define for_each_of_range for_each_of_pci_range +#define for_each_of_range_untranslate for_each_of_pci_range_untranslate /* * of_range_count - Get the number of "ranges" or "dma-ranges" entries @@ -78,6 +81,10 @@ extern int of_pci_range_parser_init(struct of_pci_range_parser *parser, struct device_node *node); extern int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser, struct device_node *node); +extern struct of_pci_range *of_pci_range_parser_one_common( + struct of_pci_range_parser *parser, + struct of_pci_range *range, + bool translate); extern struct of_pci_range *of_pci_range_parser_one( struct of_pci_range_parser *parser, struct of_pci_range *range); 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: 13811257 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013018.outbound.protection.outlook.com [52.101.67.18]) (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 907131AB529 for ; Tue, 24 Sep 2024 21:54:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.18 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727214893; cv=fail; b=J3CxPX5xp1zRt76xHKpBRd7xEsM1bh/Zhvpj5ygK/4I4CO1fz5vwINeCIy2P5fLBLd/KcfGuYMkSCjUleL8sgm+OWwzKB53beYyH4YF/rSK0mWIIdySfy/iKSNFyThbHbHdsy/tuEdWymAw1+dyvQkRTKvxbmoxAfRlUep7+Uig= 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.67.18 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: imx@lists.linux.dev 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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xBgYs/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?fE+WlgqzXgEFMexcZDvo7/gdFjdUZSmsqTdL6xWQP+PyubdSUonzM7bO4ww37mOjz?= =?utf-8?q?oA7uWdRWoucUNaE2gOP8tlqdSM9+Va9LoC6toZs4McW1bnK1M+EY5h4L1iyWcu3ul?= =?utf-8?q?17Vk+2gA3IfgDFt6ABjRRBx2adOobZ1qaiBudHcaKEF1Tpdi5UcFRpZ4PmlLYYO8o?= =?utf-8?q?t2u/MU0/jPNDajji8cxeM01Sz+1ys3RVbIRfyhQFGL8LGevVj7VEYoMNkOms6pM+W?= =?utf-8?q?4f0oqsABf70MiUEHnXzUMXX2zhvr7Z5iM+/n6qt2m1/GF5Yzp0S9Lat5TG6Cgs8b9?= =?utf-8?q?bwn1EAmHr1l5nj0SNlPkTmv6fA9/xtpGc6/+p1qUd8ZiUMtlWVBk07dPWhZ4uZedp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=?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) - From patchwork Tue Sep 24 21:54:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13811258 Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazon11011065.outbound.protection.outlook.com [52.101.70.65]) (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 3C2471474B9 for ; Tue, 24 Sep 2024 21:54:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.70.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727214898; cv=fail; b=Sax9yXvsydv+gtNdSyTUM5NaSD1lV2qKWoaxQpPZLSV/DtDT+UvVsnrkLJRNBlhFrahXkbXuZHhwo/pnAUl0/pIH0g7k7J+xSfved1bBPMaxUKkYaeIjK1uZuBy+12nMFww4h+v2P5vI1nxO91ohuAoEQLQmuyacZHp4ahyRvx4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727214898; c=relaxed/simple; bh=WtubovOE5VC0USN3mA9HgJEJll0OGg/alCRBKftPknw=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=BBXIyii6g8NyrLDZBlVb2u7jTAK8gU6HDPOaggzvaBubpWVgf0HHSjdve4732G2Uv0yPKDz79kOHCN47jgq4DSmMbgZ8KGLB8S4x3amEmBToCkIDtRfrSWYm7nlmWRlVOeYbyDxHvlMO0PntgawidsDGkHQl1/71eOMXVmqqBFs= 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=Lcs6s+n7; arc=fail smtp.client-ip=52.101.70.65 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="Lcs6s+n7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SAUL5LrMa4hzomudfHPahg2RgLgZUxLkNzkdA9YEjnkePpiHRancwlPVaFpnmtHFm/7b6/xC6qrhLP07+5dJsbpV5TCf+MC1xRkl2snT/T4SR6a39cckJmRnYXVsbMRa/bEWWkfws69Ox3cgHGmLWG/mP9VU2OVa0eKWmrJhv/GkocGtLdevtxpVXEDiub5Ict8hExLQZZXcQRxZGsw7e0Y9ZkM+OFJ4tSHicp++b3VywiV22E4qmmMcFpydE/eZeL4RGemATwYHktin3cDMNtmzkfYtX+m1WltuQ73023jHUYl4XC5g8Lw+kqkbN47RWIs6oiQ5dGhw1BauPXXtuw== 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=C0xL+G0rT5ezWJiBDM9Zvqas10zfxi7UAPdA8m0uBAw=; b=hJytZS0NbqmRRpAX3+2vwCqUESXbHH9IHxazwrByjHJEZX9hl56RzELl3i7DZJn/y4tzazjgI7cT6NbzS2CjJFF702j8QpeVzeKe8v5MwmtEMwf1ZmOi16b7o9GNYS+oKOI1r1vXX/zRgBDdr0SR1wz6klKHxAQwTGRGIAOAZEs58c9eaeWOkQoQ26yvdALBIpHusb/uYZO7r496asnv3TIQanTJQYcBxwHkqMps2WgtrY3w+7QUU9Sa+jSRtShIEwUQjY0FZbh0fu+msTtsMCoIyedkB8cKM/Fr9qK+fBiofM+G+pYNPQ6aHEGeXhpSpe3WZFfdQ+8RGoz+6WTmRA== 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=C0xL+G0rT5ezWJiBDM9Zvqas10zfxi7UAPdA8m0uBAw=; b=Lcs6s+n7VlyVkwdbgo8IYh5ANlg5l4tkdKuURGPArns7e9fQxz1oKiv6w38Idqq10nSPIQHdWlhqwkbJ6vNY/BkJ8qWNTArWaB3usPZPV6OO38l2YYctCTPK5X+TKOAlQL+wp71sULodT536VXninZ0QEVQhVgdKNnC3S+4OrMzkWg7v1Df5pctx/mju0sGqMH8yg40VrGp/dsN3FiKv/fL2iMQ9JTvZTtMidlDzHxvf71zxAdV6V511dJQCjamhHf7J3/EPzWmJ2PkEvOlS+CQV4sxVlL2Wg6klwtw4plKW/qYG+VIHwDXJtLmpxEqxbNYY0Etng+rxYbhjZiii6g== 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:53 +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:53 +0000 From: Frank Li Date: Tue, 24 Sep 2024 17:54:21 -0400 Subject: [PATCH 3/3] PCI: imx6: Remove cpu_addr_fixup() Message-Id: <20240924-pci_fixup_addr-v1-3-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=2111; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=WtubovOE5VC0USN3mA9HgJEJll0OGg/alCRBKftPknw=; b=w88E2ZJalyQxG5SyBTHH8T8yrLFR0ECBixQoDGMPXB7lRVy+ZZWpjl1jCvOtTjIb0ImFIDIQU SUD4LJd3LTmDTcgw9MqRgJoSxJhZyeeOEVumzrwqv/wxBPCUy4U1/+B 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: imx@lists.linux.dev 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: cbac7874-735a-47de-483b-08dcdce3856f 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?01hTvD5oxLFu2IbJiYIynWdjYsE/RQA?= =?utf-8?q?x8++qatkwTTH1fCo6NZBwMALRp+NzIeb/CX3kCmcicTmdBQaGBIA9whap3ENB2j/0?= =?utf-8?q?UF6nA33E08xlRTN4w7N3OfU8blhn7wYHqkdk3zACoumWC7XoNGJSM7BZHgE5d7NSm?= =?utf-8?q?Bxk7s+VPHXuZn3rqEHOEgr+o5imDtJPaCVRDYMm3Sg4fve3/KCiZgqMgMWbdsB5aI?= =?utf-8?q?MgGkmb5qb3XksFnw1bXW/04wgSY0dMTpb92E7WnO/SuWWoHnfi9SGFCyi9iOzDyTM?= =?utf-8?q?0+kAGXkst3P9wF3iJ+lqtcDJ7ltuP/33Drwguz1sdaTRM40lo+wwTKju51hv3oS9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=?utf-8?q?NT//4sxjVat2Zgja7bT+ueGJzV0plGBVrHuux1JC/2Iy13ra632IHPOvP2jD6/BzP?= =?utf-8?q?0o9VRB7joCjeCu7PWOK/27HwhfbHl9hPNS49cTU7aLPS8HCHFiVc/dzJmkurKIEg+?= =?utf-8?q?SAZb8jBTRreP+sBU4I8L1WpAMdeaSuaude+61mIAVq3WuzaCOao7kv4=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?W1MrQm52NRGWLFnELtlS5NsVrg3s?= =?utf-8?q?M4Xch9Kn+aweU525Y3BOK8aMeBd68Y2EKWpb6R4Yfw9034ueVEYUfo06+xlTdmwd4?= =?utf-8?q?9juM6etdSvd42WgCjOkzsfusBC1il9vAMQdJcsIcyEhg+B8ju+BAsjD21d8S6PpA6?= =?utf-8?q?jnS81Tp9D5B5ekS6Ao1bYWxEkmQKYavLjpDcH4j2oPIb0ZcEO7hEPtjcVOBd7Qr2A?= =?utf-8?q?lnx1O2DArlWOF7eSxVlV+55DzVvX6XsTaoUJq+gfZHxoKZYBEDx363mr8jTssMPj8?= =?utf-8?q?t5Mv77Tm68BVuHnxMy6Hy1zALi7TTTG++OT5siOA8eecaGNAskvw/l63jX/kbJbzx?= =?utf-8?q?HlHFoaVkvDEq3yQqfoleD/dDdz0sYyghVXpcDBPXyWSX6CrHsAWxtx3/8QnzIvhzo?= =?utf-8?q?y0iGQeZNchZCGeJuEKlQbTdOZqeYjt6H4uCOSaPfYvmzqnkUrasdEw+TfYsPTCqZX?= =?utf-8?q?YsQWSpzkOSk2o5s1ZCXx6hO9gePF85/W1+wOrwocB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sir5+E4gW3b8tptK0zRe?= =?utf-8?q?LVQhKIp7CgL167pry63X7HLGmFFSd2rDrWVRhIcozJo0DcsaQRhg7UsY605McYhbX?= =?utf-8?q?Di8cwxUKwpXc9k5HKmsaPLRikVPNztYBL4+Uv2tPpYBONY6VYmmGsw0k=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: cbac7874-735a-47de-483b-08dcdce3856f 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:53.5103 (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: OynFQzY98+nuIvM7W6eUxVTH451xHgpo1EjfzGaduWJy2AkmuMZhJLIJtikKc6eTtiDUVL+Lc0z9bzgN2kvcuA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7953 Remove cpu_addr_fixup() because dwc common driver already handle address translate. Signed-off-by: Frank Li Reviewed-by: Richard Zhu --- drivers/pci/controller/dwc/pci-imx6.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index 1e58c24137e7f..76174b3a0388c 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -82,7 +82,6 @@ enum imx_pcie_variants { #define IMX_PCIE_FLAG_HAS_PHY_RESET BIT(5) #define IMX_PCIE_FLAG_HAS_SERDES BIT(6) #define IMX_PCIE_FLAG_SUPPORT_64BIT BIT(7) -#define IMX_PCIE_FLAG_CPU_ADDR_FIXUP BIT(8) #define imx_check_flag(pci, val) (pci->drvdata->flags & val) @@ -1015,22 +1014,6 @@ static void imx_pcie_host_exit(struct dw_pcie_rp *pp) regulator_disable(imx_pcie->vpcie); } -static u64 imx_pcie_cpu_addr_fixup(struct dw_pcie *pcie, u64 cpu_addr) -{ - struct imx_pcie *imx_pcie = to_imx_pcie(pcie); - struct dw_pcie_rp *pp = &pcie->pp; - struct resource_entry *entry; - - if (!(imx_pcie->drvdata->flags & IMX_PCIE_FLAG_CPU_ADDR_FIXUP)) - return cpu_addr; - - entry = resource_list_first_type(&pp->bridge->windows, IORESOURCE_MEM); - if (!entry) - return cpu_addr; - - return cpu_addr - entry->offset; -} - static const struct dw_pcie_host_ops imx_pcie_host_ops = { .init = imx_pcie_host_init, .deinit = imx_pcie_host_exit, @@ -1039,7 +1022,6 @@ static const struct dw_pcie_host_ops imx_pcie_host_ops = { static const struct dw_pcie_ops dw_pcie_ops = { .start_link = imx_pcie_start_link, .stop_link = imx_pcie_stop_link, - .cpu_addr_fixup = imx_pcie_cpu_addr_fixup, }; static void imx_pcie_ep_init(struct dw_pcie_ep *ep) @@ -1598,8 +1580,7 @@ static const struct imx_pcie_drvdata drvdata[] = { }, [IMX8Q] = { .variant = IMX8Q, - .flags = IMX_PCIE_FLAG_HAS_PHYDRV | - IMX_PCIE_FLAG_CPU_ADDR_FIXUP, + .flags = IMX_PCIE_FLAG_HAS_PHYDRV, .clk_names = imx8q_clks, .clks_cnt = ARRAY_SIZE(imx8q_clks), },