From patchwork Fri Apr 19 15:07:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13636485 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 7E234C4345F for ; Fri, 19 Apr 2024 15:08:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MjaqrOcnETVctCH/w4g3a2BYH7PIEoQkEFR51hknqqs=; b=kAE8PoswGQkBeI jWdhTTIRZFqTsVaEynH2368vLEwE9YIIDlcqCpaMhsCuukENBGfD3Zn2gS6iN4wk1kYQqGFrdYnrJ cQqo2DOBlrFX0+LuGdutRdkWSHRT1kbEqijBPAHVsoDT/ggwJsfUBzTO+JoD4OH9VuNeT4+syGbbM K+feACp6FZGVYYGDbQ+BxgDOFOssJk9R3KmULX9oKKfBiEsVDCTFE4NHmjIjN0D+lyTlIESAOsLBo sxXwbrFiTRLd4drJ+bLik1Jmg337v1P464raBtsRHKizxVQ/hLuPZUw3/TissT2bPSHY31guCbLDh tvKBReh5lEuHbpJy7QLw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxpqZ-000000065L4-2RqX; Fri, 19 Apr 2024 15:08:16 +0000 Received: from mail-dbaeur03on20601.outbound.protection.outlook.com ([2a01:111:f403:260d::601] helo=EUR03-DBA-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxpqQ-000000065EX-2HnN for linux-arm-kernel@lists.infradead.org; Fri, 19 Apr 2024 15:08:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X11P3bNeubFZsRqBfun+KPanFSZtLKG4IBi5ZC8Bhu570T40VmH4XF+kXnNJ16pQPSTzCl8GBT0eZguwFeA7iCcABYsP8A/uCzdmNgZdQSJ/R0XsUj8alfAXIBm2TE0cJfSHpwMMRFkMmog5C+7bsJZFIA0dmUKDvzMneJXQv2ozxIhgTUufTE2SdVQzzdN8R2QuBpoUQ8ajyezYakYEV7QUc1mzTCZ/vtpjPO3NTjAvDWHAMANUyqqSoXacrdxEeu7Z8Z2fNrO50ES7pld0JOgARx2JdPlMyF/RbwBy2PZYCViZgPx4lwEp8lsV1EPRddOLcgpl5STJsxqiEihFqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=Rbob5Skd0aZ0iLEPzrStt1DsImjOZD7ZLxlgYrgl26Y=; b=GqA1UGSAde/MXVarpdT8dLBUqgid75lZgTv8V36wRI6rcschp6MaX6CyEwSB0+Q8DhD8thXavZCIuamax1UGsMBDgpG5lVKQM7a0dTr8Aj6gxKrxQ/Nw/StdsghETeacFl9f7NfeaiuTq4R3TS4r1Nn6DHNlzIsBY60TONhi1pmUSvmmdqg0chrsZHqGZF9wQhSByesKDu1PPwOEQBzFJ11zbAWbQL3A0sPbUazXJAyGXo04v/dLAFTZK9q9EHeGyOfETnk9bY48j9BgVY5vnsb6rskuijfI6VjRamkXkLknjXI/0M+NbCWl7zwlTV8wKpYsA8CXfMfNL64rP4u69g== 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=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Rbob5Skd0aZ0iLEPzrStt1DsImjOZD7ZLxlgYrgl26Y=; b=fwutf3+6ruvgjL36s4GLBiH2y7W0TmmOYYGaSWE8vQ9JlNNzbTP9lSoDBCjDAI7sZ/b8NOq+nCQwnwXXmMIzyWPCj7H4jnSEagbKXdiV1YNjVYauAGAxGv9YYVWyL43WSMx8uGXYmJZqfqMDAJgYLMdEaW1OQSut36yMAFcJhVA= 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 GV1PR04MB10330.eurprd04.prod.outlook.com (2603:10a6:150:1cf::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.39; Fri, 19 Apr 2024 15:07:51 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::1e67:dfc9:d0c1:fe58]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::1e67:dfc9:d0c1:fe58%7]) with mapi id 15.20.7472.037; Fri, 19 Apr 2024 15:07:51 +0000 From: Frank Li To: vkoul@kernel.org Cc: Frank.Li@nxp.com, conor+dt@kernel.org, devicetree@vger.kernel.org, dmaengine@vger.kernel.org, festevam@gmail.com, imx@lists.linux.dev, joy.zou@nxp.com, kernel@pengutronix.de, krzysztof.kozlowski+dt@linaro.org, linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com, linux-kernel@vger.kernel.org, robh@kernel.org, s.hauer@pengutronix.de, shawnguo@kernel.org Subject: [PATCH v5 2/3] dmaengine: imx-sdma: utilize compiler to calculate ADDRS_ARRAY_SIZE_V Date: Fri, 19 Apr 2024 11:07:28 -0400 Message-Id: <20240419150729.1071904-2-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240419150729.1071904-1-Frank.Li@nxp.com> References: <20240419150729.1071904-1-Frank.Li@nxp.com> X-ClientProxiedBy: BYAPR21CA0008.namprd21.prod.outlook.com (2603:10b6:a03:114::18) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|GV1PR04MB10330:EE_ X-MS-Office365-Filtering-Correlation-Id: 547299e4-6431-4d9e-e8a6-08dc60827ba3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BMppfv10gNqUSjyHUT/fn0CG3RGckrt9gKK50BypLummq+DDaSd3sKhj/Pa5t5Azk9eKmB0Ct3O0GIzLfErjNWieV5a/cAXMUy7R0aeWU5BEtvzKOpJF0em6WDvZlTbtbY73KHWRC1da/By6+5tbpMpQt/hEnSOm+HxcyBLi7q6Tsn6W4z2kLkhb5KJC44ARAg9VspZm3nI9XRXp+XxThRHzSjTHNaejiSyTQp4inPXSnMXuX/LaMzuxvkVaaCjGU0Axlxlof4mK1TvnMVZKspfflj5nXSTFL9/tYMqqd76fMsXSlHZfj3+ugJOBBO5jesBTcFv9m1fIKeEt+mLE5eLEV+O+Ogc/07UKuxhcWkPrrafuorWAUNrbLwf0FuFuy77RuVbrWkQvnTjjFVB1eA+Qixy0rUjfs2XlzIi6+6il53zVakImT89OIJZHqrGGqpJ2/mZrs1+Yu4B6gqErStC9wa/UZQ1BQPhMW6XLC98PCXs3UDIKRjvn4Or9bVfW06brbcze2JVPm0qbcby0PJqq3d3/T9uy8t1vXcnytE7sjkV9ICiE/eTqFGTe8+B6HHQ71wEv+mLyFdcBvwANZapokbCofPsY6zGbIFnqeZfLAKDD9w6VQM9KTIvnerJAKu8RnHvzR5nYkj0SVXyvUoj5yWuNhmUdrZPHrN/hbC5AVb/MWHUAMAXYGrCnHTfjMQ0D+Rt1CoNQ/TJR8BiaxGZVNK1ni4ekTHQtbCxvWCfFMT15NyvB7UhL4PGHocndTvNF5bE7xxptbKjLHU1IeWdyHqCg08SgOgk91UkuwrDxUcw8tYl/B4UWtXiwRavwmGXUhXNGG/3JxYqw6itFwKYXv6iKTb7vXG9y5z/fw0UxorARTPGTcg9rV1jLjBEj+Y9s+HZte/BWR+7dZr1Y6B+hIMYqTy18qcDIMeoGDsi7OFsSTH8V69/7YbGK3zhcmdv6pUQq9AECzftsFzelZQstBZddtWUZlqnZMdsCzHjAeZVcdSzJ5fYcT/Ni0iHisCJ8lOBZjZmqpSRoU4XuSwIC5nX+OxJHkMAUucutj4xVpf9da6msaueRVygjoVkqsW/mEJQ5GBKFtsgrW5Ax84tWteuO+q5D1Z6LuxyJwN2cZ0rgA1EWRd/JH78S4AoZ0hTASUctVNoU91EO4U8SQCyLaXStgtjHQRCXoHtCHw4zfxNRFZC9dVAxVCPMYABNOe7LZTrSc5dgWZXasCVVAAWqAhplt5aq8E5bZQMJUyWkEb+/E/ok+p1Vgx4CA/rRnLxHGQiodtt2J6ulD5EHnhPYGdvwG+Ogsu4ySeO1WV/X5LT9kcelk6jfmNBSza0jRpcBSb2gxIWWAGMoopr9dA== 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:(13230031)(7416005)(376005)(52116005)(366007)(1800799015)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 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2opc93FBn7OkGzEHQ2p0nkZphkq/aL7r1blMbIj5D5H5AiX84zi1T5KIB2GvEoCihwQZRY/h+qVAyfR6lbHeLhSOd1O1ndmzO+jGFuV0g0HnPrTAhGtAjPi0jZq4EQOD3xgz9KgoSmLqS/1G1pPrGN2kCeEG+mjILinL757flwTGR47FAplW4UpQJsiIxjKRflK/eahvWt6tw0bvREELm5900425nb3nSGRY3RD+/E2GAhKim6EVoz0VFLZx1oFs1UWBL+UNAnGpPH9gn3XaCTPMneS3CgNnZMiLAzR3e0pAF9GTkW3S9XBRrd+3UKDBCBZWX2FL1HCHbZoseRVBM5v3HOJdNyC2j2HMK5sl0/F3l0pb2xIVosuyB49jpToBW8XojciKhrTn/04hqAmQck667Isf1fW/fG/mZSUpvnml2zylMM88URBaeVXYcaVbN0QQme667wisp/71Y5MHLfLAqitJa0JYifPoMa94HLq7VqF8anHhEyXNYYimoY/Fbh1RgR4640jHAoIKVxkEBGM9itPzFxdDlGzw7w X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 547299e4-6431-4d9e-e8a6-08dc60827ba3 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2024 15:07:51.7869 (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: peAwbJHSKoknBAoiV4wa2NEmnwO3HTMlwKZOl/aAAqo84CAyvyjaTUjOU178JM+elaQipZu/LbU5ok2eciPZHA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB10330 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240419_080806_631343_F18FAA0C X-CRM114-Status: GOOD ( 10.77 ) 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 The macros SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V actually related with the struct sdma_script_start_addrs. struct sdma_script_start_addrs { ... /* End of v1 array */ ... /* End of v2 array */ ... /* End of v3 array */ ... /* End of v4 array */ }; When add new field of sdma_script_start_addrs, it is easy to miss update SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V. Employ offsetof for SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V macros instead of hardcoding numbers. the preprocessing stage will calculate the size for each version automatically. Signed-off-by: Frank Li --- Notes: Change at v5 - new patch drivers/dma/imx-sdma.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index f68ab34a3c880..4a4d44ed03c8b 100644 --- a/drivers/dma/imx-sdma.c +++ b/drivers/dma/imx-sdma.c @@ -240,11 +240,11 @@ struct sdma_script_start_addrs { s32 utra_addr; s32 ram_code_start_addr; /* End of v1 array */ - s32 mcu_2_ssish_addr; + union { s32 v1_end; s32 mcu_2_ssish_addr; }; s32 ssish_2_mcu_addr; s32 hdmi_dma_addr; /* End of v2 array */ - s32 zcanfd_2_mcu_addr; + union { s32 v2_end; s32 zcanfd_2_mcu_addr; }; s32 zqspi_2_mcu_addr; s32 mcu_2_ecspi_addr; s32 mcu_2_sai_addr; @@ -252,8 +252,9 @@ struct sdma_script_start_addrs { s32 uart_2_mcu_rom_addr; s32 uartsh_2_mcu_rom_addr; /* End of v3 array */ - s32 mcu_2_zqspi_addr; + union { s32 v3_end; s32 mcu_2_zqspi_addr; }; /* End of v4 array */ + s32 v4_end[0]; }; /* @@ -1915,10 +1916,17 @@ static void sdma_issue_pending(struct dma_chan *chan) spin_unlock_irqrestore(&sdmac->vc.lock, flags); } -#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1 34 -#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V2 38 -#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V3 45 -#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V4 46 +#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1 \ +(offsetof(struct sdma_script_start_addrs, v1_end) / sizeof(s32)) + +#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V2 \ +(offsetof(struct sdma_script_start_addrs, v2_end) / sizeof(s32)) + +#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V3 \ +(offsetof(struct sdma_script_start_addrs, v3_end) / sizeof(s32)) + +#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V4 \ +(offsetof(struct sdma_script_start_addrs, v4_end) / sizeof(s32)) static void sdma_add_scripts(struct sdma_engine *sdma, const struct sdma_script_start_addrs *addr)