From nobody Thu Apr 2 20:18:02 2026 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010036.outbound.protection.outlook.com [52.101.201.36]) (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 82BD133C1A5; Wed, 18 Feb 2026 09:53:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.36 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771408429; cv=fail; b=W6Ssq2hXTyNkD6M0FbRY+JkAhXMFlKNazBpOHFsyQjF69pAfnOnX1r9BcDXxmnwVM/XDQUU1D8h89JGW9ODGZ8dNiYSNVXQh86AvOfLRdvlkqHw9pKixRzzlhH4BTs7YgR4j6Vz9dTtN5ihfqVyFsUZuoRYE0rY/rCAwtSWFRkM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771408429; c=relaxed/simple; bh=6YPJj7G/yfSWdwKv875Sd4tani3JXImmFT3LEIs4DME=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=As50qaKadxa9aSUdRGKenYxic45UEZ1q36r1A5aD8RW5sGxRDxDZVcUKS3My5VWaKT2mYAcum6gk5jSX6NvhgED6PUTohq/2lqRMVMqPXp5/zqjaV9fqMsiJi2EpiPFVcf3MTSoQbzOaLpA+cfMtK96Aw0ylgxrn7DM54NBgQiQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=bt9IGoH5; arc=fail smtp.client-ip=52.101.201.36 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="bt9IGoH5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=zSbhx5kquuG5xVS7pspLzv48Oq7MKD7epvh2k8t4tdv0cQ2UCMP8w2Py5vYgft+T/1UclGX/cQvYpPNnU96zhcloibcHZU75aba5f41GVrboaUOZ966kwchbzuoMcsbN9MTg6uKxEsj1WZFpClNR3svQVUxrJ8443eCk6bELiFyf2cLkt0tel+ia12qIY/t8eCGerdws7tA2cwVEracKTG4/+ob3AzlLwUH0xF9ZAsOOeHRghe306vedn2aT6GGQaW5vwgt5VPX122zxsHxeANlyIYh2OZ7Afbk2ZB7/TKzkoKX9s3KdoKKAUTu8+FofaQcuncv+CT6jLoL/3/GVBQ== 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=5gekJ6whbvIF0xbgZx6yOUGKGTTLk14V3LVjdu698qM=; b=uvXEVRK1L9hTK55kBYeL2rc9+3Jxid5p0hNDkh8MsJlrPoHINlnV3nNN4g7d8aDh4048lPpNzobPFl3cbbQuyL/kG19UcjNBsLcISdEchriMbLqXfQpqOfT6Nh/RliUs8O0/+5YDJO7vPw5xjZSnqMGKfoTKVZH+TKvEEKppQDjvYKWDG6ACMv3N7tKcsZ+RmmM/Xqkau9vqesl2g5SPH/85/pouU1utcH92iMmnQPhKxFwO9pNQ5WPecpMb/pzADysWQSV0NfmzLiZHINweBTpVJArYSqe4RIlzRsCtTzYFDHg5HQg5dA1q9HG8KCbAcHypkjmQqMbAc1gP2UyIQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 198.47.21.195) smtp.rcpttodomain=nxp.com smtp.mailfrom=ti.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=ti.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5gekJ6whbvIF0xbgZx6yOUGKGTTLk14V3LVjdu698qM=; b=bt9IGoH5K90YYz+UD/LQvr9DEyRLkd0GfjSTex8WRJ148Zq5j0yJiAltzHeTXs/vewN/M05QdITByr67sgRmCamwjmb3rPeerXfdRc/Co51PgIlfuK/ezkNo8nezMMhOvBZc324yNRlFBKFPA6+ZfMybRfcc3rBZDw+cnB8yXto= Received: from MN2PR15CA0042.namprd15.prod.outlook.com (2603:10b6:208:237::11) by SAWPR10MB997814.namprd10.prod.outlook.com (2603:10b6:806:4e2::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9632.14; Wed, 18 Feb 2026 09:53:45 +0000 Received: from BN2PEPF000055DF.namprd21.prod.outlook.com (2603:10b6:208:237:cafe::58) by MN2PR15CA0042.outlook.office365.com (2603:10b6:208:237::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9632.14 via Frontend Transport; Wed, 18 Feb 2026 09:53:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 198.47.21.195) smtp.mailfrom=ti.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ti.com; Received-SPF: Pass (protection.outlook.com: domain of ti.com designates 198.47.21.195 as permitted sender) receiver=protection.outlook.com; client-ip=198.47.21.195; helo=flwvzet201.ext.ti.com; pr=C Received: from flwvzet201.ext.ti.com (198.47.21.195) by BN2PEPF000055DF.mail.protection.outlook.com (10.167.245.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.0 via Frontend Transport; Wed, 18 Feb 2026 09:53:44 +0000 Received: from DFLE201.ent.ti.com (10.64.6.59) by flwvzet201.ext.ti.com (10.248.192.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 18 Feb 2026 03:53:40 -0600 Received: from DFLE201.ent.ti.com (10.64.6.59) by DFLE201.ent.ti.com (10.64.6.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 18 Feb 2026 03:53:39 -0600 Received: from lelvem-mr06.itg.ti.com (10.180.75.8) by DFLE201.ent.ti.com (10.64.6.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20 via Frontend Transport; Wed, 18 Feb 2026 03:53:39 -0600 Received: from uda0498651.dhcp.ti.com (uda0498651.dhcp.ti.com [172.24.233.239]) by lelvem-mr06.itg.ti.com (8.18.1/8.18.1) with ESMTP id 61I9qpIG200561; Wed, 18 Feb 2026 03:53:35 -0600 From: Sai Sree Kartheek Adivi To: , , , , , , , , , , , , , CC: , Subject: [PATCH v5 09/18] dmaengine: ti: k3-udma: refactor resource setup functions Date: Wed, 18 Feb 2026 15:22:34 +0530 Message-ID: <20260218095243.2832115-10-s-adivi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260218095243.2832115-1-s-adivi@ti.com> References: <20260218095243.2832115-1-s-adivi@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000055DF:EE_|SAWPR10MB997814:EE_ X-MS-Office365-Filtering-Correlation-Id: 01933a7d-d889-4b02-76b2-08de6ed39a80 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|376014|7416014|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?0Ocr6lXhTnr7XN0vb5k0FvrG0LmW9BlKWt7HNcgtkDL3U1A0DfSBJAH6maWN?= =?us-ascii?Q?s6vbi0uyWCMxaQNdEjAYz9+mlujFUoBW58VsybbfYs0JEumampGLPUuOzudA?= =?us-ascii?Q?KB4KNA1ImmZHZ2VYlbdlBbf1DtNys2xdnhFQTQOablhgoNJWkCn5OafYHya5?= =?us-ascii?Q?ibwz4zgfR56wQjnCLrBRUPqiL/aJKKg/w4IYuLdywU7f8xndTrHsq9y+Fgp4?= =?us-ascii?Q?KoqzmQ+CbGIaLvZENOgrDjweR9A2aZgPvn9dA64O4VGeJC0fimCbZTBgTbAc?= =?us-ascii?Q?wBLlIUv6/+5km38ZiP5b62PmNYYKA4Da19C8cLCAGVQa6W3r6nluyUT2rZNL?= =?us-ascii?Q?gjHoPxlmOKBemG8wsRnkYgDJxWn661uj5dAVJnj2CZDnT4r09VUAjPbUyhhN?= =?us-ascii?Q?TVrgtVEQLPrVhwBFZJLBQu1rrrjyrwmi/i8dqJXvEGKVMOyiDspi1N1/7tiX?= =?us-ascii?Q?7OGq+EfbtOqEI6y7UMhV1sq/hRtq+rDhgX/ay+Bgr955EyTEB3NRCBrW3atI?= =?us-ascii?Q?LfI2XF+iLY9FegrMzShBXzATmGws0kVM3iMFNRwZsEW4CjPvvdMbGHjKOWzJ?= =?us-ascii?Q?gQqM3oTOySD9bpGNC/mCmJyBxWPyWzCFFXdtqevueIyTDgl8896KLx9Z6/ZH?= =?us-ascii?Q?CqjsRNwQvxl+UF5jzptDuF8xmc4X0KhdzGebqFDbs/iRfc5zQuAIK7rtLlNT?= =?us-ascii?Q?we7s19NyDzTnRMGD/GDRXvssq+Zt68XqB0kYZwjiM/lEx5RLaC2BAstVTfRi?= =?us-ascii?Q?e9AJde7KcXFxQOtL6EVUJuKD/9To083HjXZi95kGHc7BBfhaz14ZtxfR7CSa?= =?us-ascii?Q?7t0LP9RyjC4lNZi7RFomXOjDsc/o3zAl6xlaZCemZZwy01CqoXkI4WKTyJlY?= =?us-ascii?Q?SvRhPHa9gmpEXltAi4CCWFHs6w3ZiRV0HganlmL02oIh2UOglSGDjgNSpauD?= =?us-ascii?Q?5rHKXMQknPWFCr4gS7MuQwOlZJkipw174vqAwpRDhyIkVOR4xQ5FvAhmnOz5?= =?us-ascii?Q?Gv+WXqIZ4NLkX50n8mafTLjeLlLpBif9vKj6OR2pCXCNwauVKR3IJh5qgbK+?= =?us-ascii?Q?MIPqsSD9H2XAWLAVmY/g11K07mCWN95hkjEuJsPXMs2Z/QZh4u911fxpd/x+?= =?us-ascii?Q?4ZWWtd2cGiyL/zTONxc3ySWaI4ecD72e2Lkz4R+2V3KjxzplsRUGmxegc3p/?= =?us-ascii?Q?uUujlz2ItsIiZHF8tn+Ou8PPHtAeZtaZRbQVLEBEz/DVnDAFziKEXP57ws65?= =?us-ascii?Q?B4s0WdRX7sHsskq2UF9amc0Pr8fgoGAjxElEYUFXhOoAJSTQ90zuC5DxGmJW?= =?us-ascii?Q?MVbuS+X0o+i/zswAcR33o/zp22Gtcw/ZDTbuXLHfWUZRF1y7C3BhQ02oOkZE?= =?us-ascii?Q?httABbL3ga1HoY9HuxBGcyU0jFbRNFxVTxMGf4l8ue7zev3szkg8rF2FIA9u?= =?us-ascii?Q?GpTMoLxpfPt9Drhy53G9ZtAO10d3esEgsUh9yFu7sbuWdcm8YZ3arUj75r1g?= =?us-ascii?Q?Rem56xTLCpOjRaoSG27XhlfIGr5Ng2f+1e40G/CcbYAj0mmQUvRD3ZJlf8Zw?= =?us-ascii?Q?qwVD4BHBnxR95mcsshOATntqGxoUJVt1Cb2MeciwYa2LDT6l/eX0HM9tD6pd?= =?us-ascii?Q?CQ3ar/tSV5mb88zcpkviZU3WumnxzppZaxOo60EfM1lQzrwrhNezPtiOrdF8?= =?us-ascii?Q?K3U/rfhcDSZ3xIboaAEjsjxF4Oo=3D?= X-Forefront-Antispam-Report: CIP:198.47.21.195;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:flwvzet201.ext.ti.com;PTR:ErrorRetry;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(376014)(7416014)(1800799024)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: C/bRZvyrbBbJTTLo8oFw9Bi2TB/ZzjIv9LUawiyp/TvaRYFQt2bg88vdviHKY6fUXTpkjr3NfEmO2WlDr8vJAcMTRuwTiNbTcy+2YPf8pRyTYH4bFJ02xPx8mAXqCbH6uuZdxhNIxycGKCVy+vyVZcFmayAKgWLjlGnmwAuQffqHzKfP71yw0RDfMb1rv0qWltYjqKyxt1z+7Vicgv/9vN8LZwIuXsTp/FJHFpH53X4MCReWr8hNrxlRXpHuWKTP4C9XxuGrwz1ay8C/YPGyolwiamPckswUVE75Kb1T/HmArFlAGWDTPgWj+3FYeAxNo4gJJEYMwaMG0m+D26NcgRLz0kGVuoi/2TeB3k3WYePQ3vqzZw6Wu/eWitp91uciIm5NiI/CyQavyP7lIIgDfldomOVDYYG25eDcBPD4fxeVBgNbvL0e1VbzhlE+fMu1 X-OriginatorOrg: ti.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Feb 2026 09:53:44.1238 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 01933a7d-d889-4b02-76b2-08de6ed39a80 X-MS-Exchange-CrossTenant-Id: e5b49634-450b-4709-8abb-1e2b19b982b7 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=e5b49634-450b-4709-8abb-1e2b19b982b7;Ip=[198.47.21.195];Helo=[flwvzet201.ext.ti.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000055DF.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SAWPR10MB997814 Content-Type: text/plain; charset="utf-8" The implementation of setup_resources, bcdma_setup_resources and pktdma_setup_resources is largely shared between all K3 UDMA variants with the only major difference being SCI resources setup. So, - Move the functions to k3-udma-common.c. - Split SCI resource setup for bcdma and pktdma into separate functions in variant specific driver (k3-udma.c). - Add function pointers for setup_sci_resources in udma_dev and call them as part of the actual resource setup implementations in k3-udma-common.c to retain the existing functionality. - Also since setup_resources call udma_setup_resources which is not required for all K3 UDMA variants, Add a function pointer in udma_dev and use that to call udma_setup_resources. This refactor improves code reuse and maintainability across multiple variants. No functional changes intended. Signed-off-by: Sai Sree Kartheek Adivi --- drivers/dma/ti/k3-udma-common.c | 204 ++++++++++++++++++++++++++++++++ drivers/dma/ti/k3-udma.c | 182 +--------------------------- drivers/dma/ti/k3-udma.h | 8 ++ 3 files changed, 218 insertions(+), 176 deletions(-) diff --git a/drivers/dma/ti/k3-udma-common.c b/drivers/dma/ti/k3-udma-commo= n.c index 882d27b3c9ee5..b419b23c401a1 100644 --- a/drivers/dma/ti/k3-udma-common.c +++ b/drivers/dma/ti/k3-udma-common.c @@ -8,7 +8,9 @@ #include #include #include +#include #include +#include #include =20 #include "k3-udma.h" @@ -2333,5 +2335,207 @@ void bcdma_free_bchan_resources(struct udma_chan *u= c) } EXPORT_SYMBOL_GPL(bcdma_free_bchan_resources); =20 +int bcdma_setup_resources(struct udma_dev *ud) +{ + int ret; + struct device *dev =3D ud->dev; + u32 cap; + + /* Set up the throughput level start indexes */ + cap =3D udma_read(ud->mmrs[MMR_GCFG], 0x2c); + if (BCDMA_CAP3_UBCHAN_CNT(cap)) { + ud->bchan_tpl.levels =3D 3; + ud->bchan_tpl.start_idx[1] =3D BCDMA_CAP3_UBCHAN_CNT(cap); + ud->bchan_tpl.start_idx[0] =3D BCDMA_CAP3_HBCHAN_CNT(cap); + } else if (BCDMA_CAP3_HBCHAN_CNT(cap)) { + ud->bchan_tpl.levels =3D 2; + ud->bchan_tpl.start_idx[0] =3D BCDMA_CAP3_HBCHAN_CNT(cap); + } else { + ud->bchan_tpl.levels =3D 1; + } + + cap =3D udma_read(ud->mmrs[MMR_GCFG], 0x30); + if (BCDMA_CAP4_URCHAN_CNT(cap)) { + ud->rchan_tpl.levels =3D 3; + ud->rchan_tpl.start_idx[1] =3D BCDMA_CAP4_URCHAN_CNT(cap); + ud->rchan_tpl.start_idx[0] =3D BCDMA_CAP4_HRCHAN_CNT(cap); + } else if (BCDMA_CAP4_HRCHAN_CNT(cap)) { + ud->rchan_tpl.levels =3D 2; + ud->rchan_tpl.start_idx[0] =3D BCDMA_CAP4_HRCHAN_CNT(cap); + } else { + ud->rchan_tpl.levels =3D 1; + } + + if (BCDMA_CAP4_UTCHAN_CNT(cap)) { + ud->tchan_tpl.levels =3D 3; + ud->tchan_tpl.start_idx[1] =3D BCDMA_CAP4_UTCHAN_CNT(cap); + ud->tchan_tpl.start_idx[0] =3D BCDMA_CAP4_HTCHAN_CNT(cap); + } else if (BCDMA_CAP4_HTCHAN_CNT(cap)) { + ud->tchan_tpl.levels =3D 2; + ud->tchan_tpl.start_idx[0] =3D BCDMA_CAP4_HTCHAN_CNT(cap); + } else { + ud->tchan_tpl.levels =3D 1; + } + + ud->bchan_map =3D devm_kmalloc_array(dev, BITS_TO_LONGS(ud->bchan_cnt), + sizeof(unsigned long), GFP_KERNEL); + ud->bchans =3D devm_kcalloc(dev, ud->bchan_cnt, sizeof(*ud->bchans), + GFP_KERNEL); + ud->tchan_map =3D devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tchan_cnt), + sizeof(unsigned long), GFP_KERNEL); + ud->tchans =3D devm_kcalloc(dev, ud->tchan_cnt, sizeof(*ud->tchans), + GFP_KERNEL); + ud->rchan_map =3D devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rchan_cnt), + sizeof(unsigned long), GFP_KERNEL); + ud->rchans =3D devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rchans), + GFP_KERNEL); + /* BCDMA do not really have flows, but the driver expect it */ + ud->rflow_in_use =3D devm_kcalloc(dev, BITS_TO_LONGS(ud->rchan_cnt), + sizeof(unsigned long), + GFP_KERNEL); + ud->rflows =3D devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rflows), + GFP_KERNEL); + + if (!ud->bchan_map || !ud->tchan_map || !ud->rchan_map || + !ud->rflow_in_use || !ud->bchans || !ud->tchans || !ud->rchans || + !ud->rflows) + return -ENOMEM; + + if (ud->bcdma_setup_sci_resources) { + ret =3D ud->bcdma_setup_sci_resources(ud); + if (ret) + return ret; + } + + return 0; +} + +int pktdma_setup_resources(struct udma_dev *ud) +{ + int ret; + struct device *dev =3D ud->dev; + u32 cap3; + + /* Set up the throughput level start indexes */ + cap3 =3D udma_read(ud->mmrs[MMR_GCFG], 0x2c); + if (UDMA_CAP3_UCHAN_CNT(cap3)) { + ud->tchan_tpl.levels =3D 3; + ud->tchan_tpl.start_idx[1] =3D UDMA_CAP3_UCHAN_CNT(cap3); + ud->tchan_tpl.start_idx[0] =3D UDMA_CAP3_HCHAN_CNT(cap3); + } else if (UDMA_CAP3_HCHAN_CNT(cap3)) { + ud->tchan_tpl.levels =3D 2; + ud->tchan_tpl.start_idx[0] =3D UDMA_CAP3_HCHAN_CNT(cap3); + } else { + ud->tchan_tpl.levels =3D 1; + } + + ud->rchan_tpl.levels =3D ud->tchan_tpl.levels; + ud->rchan_tpl.start_idx[0] =3D ud->tchan_tpl.start_idx[0]; + ud->rchan_tpl.start_idx[1] =3D ud->tchan_tpl.start_idx[1]; + + ud->tchan_map =3D devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tchan_cnt), + sizeof(unsigned long), GFP_KERNEL); + ud->tchans =3D devm_kcalloc(dev, ud->tchan_cnt, sizeof(*ud->tchans), + GFP_KERNEL); + ud->rchan_map =3D devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rchan_cnt), + sizeof(unsigned long), GFP_KERNEL); + ud->rchans =3D devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rchans), + GFP_KERNEL); + ud->rflow_in_use =3D devm_kcalloc(dev, BITS_TO_LONGS(ud->rflow_cnt), + sizeof(unsigned long), + GFP_KERNEL); + ud->rflows =3D devm_kcalloc(dev, ud->rflow_cnt, sizeof(*ud->rflows), + GFP_KERNEL); + ud->tflow_map =3D devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tflow_cnt), + sizeof(unsigned long), GFP_KERNEL); + + if (!ud->tchan_map || !ud->rchan_map || !ud->tflow_map || !ud->tchans || + !ud->rchans || !ud->rflows || !ud->rflow_in_use) + return -ENOMEM; + + if (ud->pktdma_setup_sci_resources) { + ret =3D ud->pktdma_setup_sci_resources(ud); + if (ret) + return ret; + } + + return 0; +} + +int setup_resources(struct udma_dev *ud) +{ + struct device *dev =3D ud->dev; + int ch_count, ret; + + switch (ud->match_data->type) { + case DMA_TYPE_UDMA: + ret =3D ud->udma_setup_resources(ud); + break; + case DMA_TYPE_BCDMA: + ret =3D bcdma_setup_resources(ud); + break; + case DMA_TYPE_PKTDMA: + ret =3D pktdma_setup_resources(ud); + break; + default: + return -EINVAL; + } + + if (ret) + return ret; + + ch_count =3D ud->bchan_cnt + ud->tchan_cnt + ud->rchan_cnt; + if (ud->bchan_cnt) + ch_count -=3D bitmap_weight(ud->bchan_map, ud->bchan_cnt); + ch_count -=3D bitmap_weight(ud->tchan_map, ud->tchan_cnt); + ch_count -=3D bitmap_weight(ud->rchan_map, ud->rchan_cnt); + if (!ch_count) + return -ENODEV; + + ud->channels =3D devm_kcalloc(dev, ch_count, sizeof(*ud->channels), + GFP_KERNEL); + if (!ud->channels) + return -ENOMEM; + + switch (ud->match_data->type) { + case DMA_TYPE_UDMA: + dev_info(dev, + "Channels: %d (tchan: %u, rchan: %u, gp-rflow: %u)\n", + ch_count, + ud->tchan_cnt - bitmap_weight(ud->tchan_map, + ud->tchan_cnt), + ud->rchan_cnt - bitmap_weight(ud->rchan_map, + ud->rchan_cnt), + ud->rflow_cnt - bitmap_weight(ud->rflow_gp_map, + ud->rflow_cnt)); + break; + case DMA_TYPE_BCDMA: + dev_info(dev, + "Channels: %d (bchan: %u, tchan: %u, rchan: %u)\n", + ch_count, + ud->bchan_cnt - bitmap_weight(ud->bchan_map, + ud->bchan_cnt), + ud->tchan_cnt - bitmap_weight(ud->tchan_map, + ud->tchan_cnt), + ud->rchan_cnt - bitmap_weight(ud->rchan_map, + ud->rchan_cnt)); + break; + case DMA_TYPE_PKTDMA: + dev_info(dev, + "Channels: %d (tchan: %u, rchan: %u)\n", + ch_count, + ud->tchan_cnt - bitmap_weight(ud->tchan_map, + ud->tchan_cnt), + ud->rchan_cnt - bitmap_weight(ud->rchan_map, + ud->rchan_cnt)); + break; + default: + break; + } + + return ch_count; +} +EXPORT_SYMBOL_GPL(setup_resources); + MODULE_DESCRIPTION("Texas Instruments K3 UDMA Common Library"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c index fa9a464f4b953..83cf3d01f67fb 100644 --- a/drivers/dma/ti/k3-udma.c +++ b/drivers/dma/ti/k3-udma.c @@ -2083,7 +2083,7 @@ static const char * const range_names[] =3D { [RM_RANGE_TFLOW] =3D "ti,sci-rm-range-tflow", }; =20 -static int udma_setup_resources(struct udma_dev *ud) +int udma_setup_resources(struct udma_dev *ud) { int ret, i, j; struct device *dev =3D ud->dev; @@ -2245,74 +2245,13 @@ static int udma_setup_resources(struct udma_dev *ud) return 0; } =20 -static int bcdma_setup_resources(struct udma_dev *ud) +static int bcdma_setup_sci_resources(struct udma_dev *ud) { int ret, i, j; struct device *dev =3D ud->dev; struct ti_sci_resource *rm_res, irq_res; struct udma_tisci_rm *tisci_rm =3D &ud->tisci_rm; const struct udma_oes_offsets *oes =3D &ud->soc_data->oes; - u32 cap; - - /* Set up the throughput level start indexes */ - cap =3D udma_read(ud->mmrs[MMR_GCFG], 0x2c); - if (BCDMA_CAP3_UBCHAN_CNT(cap)) { - ud->bchan_tpl.levels =3D 3; - ud->bchan_tpl.start_idx[1] =3D BCDMA_CAP3_UBCHAN_CNT(cap); - ud->bchan_tpl.start_idx[0] =3D BCDMA_CAP3_HBCHAN_CNT(cap); - } else if (BCDMA_CAP3_HBCHAN_CNT(cap)) { - ud->bchan_tpl.levels =3D 2; - ud->bchan_tpl.start_idx[0] =3D BCDMA_CAP3_HBCHAN_CNT(cap); - } else { - ud->bchan_tpl.levels =3D 1; - } - - cap =3D udma_read(ud->mmrs[MMR_GCFG], 0x30); - if (BCDMA_CAP4_URCHAN_CNT(cap)) { - ud->rchan_tpl.levels =3D 3; - ud->rchan_tpl.start_idx[1] =3D BCDMA_CAP4_URCHAN_CNT(cap); - ud->rchan_tpl.start_idx[0] =3D BCDMA_CAP4_HRCHAN_CNT(cap); - } else if (BCDMA_CAP4_HRCHAN_CNT(cap)) { - ud->rchan_tpl.levels =3D 2; - ud->rchan_tpl.start_idx[0] =3D BCDMA_CAP4_HRCHAN_CNT(cap); - } else { - ud->rchan_tpl.levels =3D 1; - } - - if (BCDMA_CAP4_UTCHAN_CNT(cap)) { - ud->tchan_tpl.levels =3D 3; - ud->tchan_tpl.start_idx[1] =3D BCDMA_CAP4_UTCHAN_CNT(cap); - ud->tchan_tpl.start_idx[0] =3D BCDMA_CAP4_HTCHAN_CNT(cap); - } else if (BCDMA_CAP4_HTCHAN_CNT(cap)) { - ud->tchan_tpl.levels =3D 2; - ud->tchan_tpl.start_idx[0] =3D BCDMA_CAP4_HTCHAN_CNT(cap); - } else { - ud->tchan_tpl.levels =3D 1; - } - - ud->bchan_map =3D devm_kmalloc_array(dev, BITS_TO_LONGS(ud->bchan_cnt), - sizeof(unsigned long), GFP_KERNEL); - ud->bchans =3D devm_kcalloc(dev, ud->bchan_cnt, sizeof(*ud->bchans), - GFP_KERNEL); - ud->tchan_map =3D devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tchan_cnt), - sizeof(unsigned long), GFP_KERNEL); - ud->tchans =3D devm_kcalloc(dev, ud->tchan_cnt, sizeof(*ud->tchans), - GFP_KERNEL); - ud->rchan_map =3D devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rchan_cnt), - sizeof(unsigned long), GFP_KERNEL); - ud->rchans =3D devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rchans), - GFP_KERNEL); - /* BCDMA do not really have flows, but the driver expect it */ - ud->rflow_in_use =3D devm_kcalloc(dev, BITS_TO_LONGS(ud->rchan_cnt), - sizeof(unsigned long), - GFP_KERNEL); - ud->rflows =3D devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rflows), - GFP_KERNEL); - - if (!ud->bchan_map || !ud->tchan_map || !ud->rchan_map || - !ud->rflow_in_use || !ud->bchans || !ud->tchans || !ud->rchans || - !ud->rflows) - return -ENOMEM; =20 /* Get resource ranges from tisci */ for (i =3D 0; i < RM_RANGE_LAST; i++) { @@ -2476,51 +2415,13 @@ static int bcdma_setup_resources(struct udma_dev *u= d) return 0; } =20 -static int pktdma_setup_resources(struct udma_dev *ud) +static int pktdma_setup_sci_resources(struct udma_dev *ud) { int ret, i, j; struct device *dev =3D ud->dev; struct ti_sci_resource *rm_res, irq_res; struct udma_tisci_rm *tisci_rm =3D &ud->tisci_rm; const struct udma_oes_offsets *oes =3D &ud->soc_data->oes; - u32 cap3; - - /* Set up the throughput level start indexes */ - cap3 =3D udma_read(ud->mmrs[MMR_GCFG], 0x2c); - if (UDMA_CAP3_UCHAN_CNT(cap3)) { - ud->tchan_tpl.levels =3D 3; - ud->tchan_tpl.start_idx[1] =3D UDMA_CAP3_UCHAN_CNT(cap3); - ud->tchan_tpl.start_idx[0] =3D UDMA_CAP3_HCHAN_CNT(cap3); - } else if (UDMA_CAP3_HCHAN_CNT(cap3)) { - ud->tchan_tpl.levels =3D 2; - ud->tchan_tpl.start_idx[0] =3D UDMA_CAP3_HCHAN_CNT(cap3); - } else { - ud->tchan_tpl.levels =3D 1; - } - - ud->rchan_tpl.levels =3D ud->tchan_tpl.levels; - ud->rchan_tpl.start_idx[0] =3D ud->tchan_tpl.start_idx[0]; - ud->rchan_tpl.start_idx[1] =3D ud->tchan_tpl.start_idx[1]; - - ud->tchan_map =3D devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tchan_cnt), - sizeof(unsigned long), GFP_KERNEL); - ud->tchans =3D devm_kcalloc(dev, ud->tchan_cnt, sizeof(*ud->tchans), - GFP_KERNEL); - ud->rchan_map =3D devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rchan_cnt), - sizeof(unsigned long), GFP_KERNEL); - ud->rchans =3D devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rchans), - GFP_KERNEL); - ud->rflow_in_use =3D devm_kcalloc(dev, BITS_TO_LONGS(ud->rflow_cnt), - sizeof(unsigned long), - GFP_KERNEL); - ud->rflows =3D devm_kcalloc(dev, ud->rflow_cnt, sizeof(*ud->rflows), - GFP_KERNEL); - ud->tflow_map =3D devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tflow_cnt), - sizeof(unsigned long), GFP_KERNEL); - - if (!ud->tchan_map || !ud->rchan_map || !ud->tflow_map || !ud->tchans || - !ud->rchans || !ud->rflows || !ud->rflow_in_use) - return -ENOMEM; =20 /* Get resource ranges from tisci */ for (i =3D 0; i < RM_RANGE_LAST; i++) { @@ -2631,80 +2532,6 @@ static int pktdma_setup_resources(struct udma_dev *u= d) return 0; } =20 -static int setup_resources(struct udma_dev *ud) -{ - struct device *dev =3D ud->dev; - int ch_count, ret; - - switch (ud->match_data->type) { - case DMA_TYPE_UDMA: - ret =3D udma_setup_resources(ud); - break; - case DMA_TYPE_BCDMA: - ret =3D bcdma_setup_resources(ud); - break; - case DMA_TYPE_PKTDMA: - ret =3D pktdma_setup_resources(ud); - break; - default: - return -EINVAL; - } - - if (ret) - return ret; - - ch_count =3D ud->bchan_cnt + ud->tchan_cnt + ud->rchan_cnt; - if (ud->bchan_cnt) - ch_count -=3D bitmap_weight(ud->bchan_map, ud->bchan_cnt); - ch_count -=3D bitmap_weight(ud->tchan_map, ud->tchan_cnt); - ch_count -=3D bitmap_weight(ud->rchan_map, ud->rchan_cnt); - if (!ch_count) - return -ENODEV; - - ud->channels =3D devm_kcalloc(dev, ch_count, sizeof(*ud->channels), - GFP_KERNEL); - if (!ud->channels) - return -ENOMEM; - - switch (ud->match_data->type) { - case DMA_TYPE_UDMA: - dev_info(dev, - "Channels: %d (tchan: %u, rchan: %u, gp-rflow: %u)\n", - ch_count, - ud->tchan_cnt - bitmap_weight(ud->tchan_map, - ud->tchan_cnt), - ud->rchan_cnt - bitmap_weight(ud->rchan_map, - ud->rchan_cnt), - ud->rflow_cnt - bitmap_weight(ud->rflow_gp_map, - ud->rflow_cnt)); - break; - case DMA_TYPE_BCDMA: - dev_info(dev, - "Channels: %d (bchan: %u, tchan: %u, rchan: %u)\n", - ch_count, - ud->bchan_cnt - bitmap_weight(ud->bchan_map, - ud->bchan_cnt), - ud->tchan_cnt - bitmap_weight(ud->tchan_map, - ud->tchan_cnt), - ud->rchan_cnt - bitmap_weight(ud->rchan_map, - ud->rchan_cnt)); - break; - case DMA_TYPE_PKTDMA: - dev_info(dev, - "Channels: %d (tchan: %u, rchan: %u)\n", - ch_count, - ud->tchan_cnt - bitmap_weight(ud->tchan_map, - ud->tchan_cnt), - ud->rchan_cnt - bitmap_weight(ud->rchan_map, - ud->rchan_cnt)); - break; - default: - break; - } - - return ch_count; -} - static int udma_probe(struct platform_device *pdev) { struct device_node *navss_node =3D pdev->dev.parent->of_node; @@ -2747,6 +2574,9 @@ static int udma_probe(struct platform_device *pdev) ud->decrement_byte_counters =3D udma_decrement_byte_counters; ud->psil_pair =3D navss_psil_pair; ud->psil_unpair =3D navss_psil_unpair; + ud->udma_setup_resources =3D udma_setup_resources; + ud->bcdma_setup_sci_resources =3D bcdma_setup_sci_resources; + ud->pktdma_setup_sci_resources =3D pktdma_setup_sci_resources; =20 ret =3D udma_get_mmrs(pdev, ud); if (ret) diff --git a/drivers/dma/ti/k3-udma.h b/drivers/dma/ti/k3-udma.h index e4b512d9ffb2e..6a95eb1ece064 100644 --- a/drivers/dma/ti/k3-udma.h +++ b/drivers/dma/ti/k3-udma.h @@ -353,6 +353,9 @@ struct udma_dev { u32 dst_thread); int (*psil_unpair)(struct udma_dev *ud, u32 src_thread, u32 dst_thread); + int (*udma_setup_resources)(struct udma_dev *ud); + int (*bcdma_setup_sci_resources)(struct udma_dev *ud); + int (*pktdma_setup_sci_resources)(struct udma_dev *ud); }; =20 struct udma_desc { @@ -675,6 +678,11 @@ struct udma_bchan *__udma_reserve_bchan(struct udma_de= v *ud, enum udma_tp_level struct udma_tchan *__udma_reserve_tchan(struct udma_dev *ud, enum udma_tp_= level tpl, int id); struct udma_rchan *__udma_reserve_rchan(struct udma_dev *ud, enum udma_tp_= level tpl, int id); =20 +int udma_setup_resources(struct udma_dev *ud); +int bcdma_setup_resources(struct udma_dev *ud); +int pktdma_setup_resources(struct udma_dev *ud); +int setup_resources(struct udma_dev *ud); + /* Direct access to UDMA low lever resources for the glue layer */ int xudma_navss_psil_pair(struct udma_dev *ud, u32 src_thread, u32 dst_thr= ead); int xudma_navss_psil_unpair(struct udma_dev *ud, u32 src_thread, --=20 2.34.1