From nobody Mon Feb 9 16:16:56 2026 Received: from PH0PR06CU001.outbound.protection.outlook.com (mail-westus3azon11011028.outbound.protection.outlook.com [40.107.208.28]) (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 86D5C3793CF; Fri, 30 Jan 2026 11:03:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.208.28 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769770990; cv=fail; b=lXl2pQ9j8ZbcS4sVxO58lU0TedTRsCLEE5USXER1KJc+i17Xj7VqOhFpyjg8hZcQFOIIIZK2J8dIFhPTVFJ5qMQWDXHz5AOG4/yOwoIabJpmPLejJTcOs3e1Fo9Vr0GN1azU7jNQ0nUCwy4Siea56OLoTYAWe8aORxJz9Fvv3/Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769770990; c=relaxed/simple; bh=6YPJj7G/yfSWdwKv875Sd4tani3JXImmFT3LEIs4DME=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qSjUB1i1T3oXDEFf/Nz8pfzJjfFVy/sv2ypzAU65n/FjgnCr3mFI/QwdRKqzyzsky/q+mYE7tVAWODWcV9t+h9tx/6bEg1vNcWp66zzcuatT8BOGp4wF0QcCk9OPMBXZzneuC3LcOUdAtdYOocvVtIcpEIptUaI7AEjA6u3w5P4= 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=WMiZ1o8F; arc=fail smtp.client-ip=40.107.208.28 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="WMiZ1o8F" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ULHyvdZHXYQx9EFrbwfdCyjgyLcYSMfwhoCXhnqZK2ZQhQKYhPySv0bYSsNgRhdv4+YkNksF8Utk45s1oMjTEuCpyiurmx2e29NUPxd5QgB/AkOGY4UpcZJ93Tcd5/KiAp+umRyZ5T5TTXISg9dTULNxq8SPCSGz7ABN/ptb8pjLW64GgJ43k0q98vOCCQ/G7mqK0CW9zceC3JVgoAsyWGybxfyMzQIDO3EUI5twbC2oOtONJdS8yc5sUUjONagu4PuiAYZ85WPuQSViemt7rgMYN6ysHfAUzqTmoVaUHFxb8YmbRIzHDiQTZzCpLScI3PKRq5i91CWNwlaTUA977Q== 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=NAerwXgi8PQoIOcqFtrvo5FRRoOtvr0fj2A1TTwlpHinMm9vqtcqrHpXRQb/wqeftnA9NFmI+Et3UNR92Joh+5heSJ2F3kjBhylZUS3Ne/TYqQYUP3tqVU7i41bBdfH88XNcF7+DRKNV0Fh3ZupyJSmnUgXT6/eE3aBN0Fb4dIVam23snXNZFjQXZ+jVzZS3EKFpcB4ckTmF9oczJm00jX3t0NEyFa7zYHxWUtwHAce1gonCZLLWW8Ae0yD0RM7fUUGhni4t30uAHsVZiGQgdLlPhia2Xx6E00rsyofWR7699PUdzucWpUtLUywwoFQoOld/UO5WcJ5H1y2EHlcDQw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 198.47.21.194) smtp.rcpttodomain=lists.infradead.org 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=WMiZ1o8FJUNk0WwuEtfvNJ85+IdSpa/Sm0KTMpl4Ywz4mEO7+4+oofVzaLYiDDWvpfei8cLuAjJ/0MVVBIXHMKGpkKJLExnJtDo68N2ofSHRIBjXUuskgnkkEfNSwcbFz4ZpxuR3mCA9X+BKA9z3ME3N8hUFLde7Sgyd0d4PxiA= Received: from BY3PR05CA0055.namprd05.prod.outlook.com (2603:10b6:a03:39b::30) by CY8PR10MB6491.namprd10.prod.outlook.com (2603:10b6:930:5d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.11; Fri, 30 Jan 2026 11:03:05 +0000 Received: from SJ5PEPF000001F3.namprd05.prod.outlook.com (2603:10b6:a03:39b:cafe::ea) by BY3PR05CA0055.outlook.office365.com (2603:10b6:a03:39b::30) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9587.5 via Frontend Transport; Fri, 30 Jan 2026 11:02:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 198.47.21.194) 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.194 as permitted sender) receiver=protection.outlook.com; client-ip=198.47.21.194; helo=flwvzet200.ext.ti.com; pr=C Received: from flwvzet200.ext.ti.com (198.47.21.194) by SJ5PEPF000001F3.mail.protection.outlook.com (10.167.242.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.3 via Frontend Transport; Fri, 30 Jan 2026 11:03:03 +0000 Received: from DFLE204.ent.ti.com (10.64.6.62) by flwvzet200.ext.ti.com (10.248.192.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Fri, 30 Jan 2026 05:03:01 -0600 Received: from DFLE202.ent.ti.com (10.64.6.60) by DFLE204.ent.ti.com (10.64.6.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Fri, 30 Jan 2026 05:03:01 -0600 Received: from lelvem-mr06.itg.ti.com (10.180.75.8) by DFLE202.ent.ti.com (10.64.6.60) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20 via Frontend Transport; Fri, 30 Jan 2026 05:03:01 -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 60UB2HBm1204392; Fri, 30 Jan 2026 05:02:57 -0600 From: Sai Sree Kartheek Adivi To: , , , , , , , , , , , , CC: , Subject: [PATCH v4 09/19] dmaengine: ti: k3-udma: refactor resource setup functions Date: Fri, 30 Jan 2026 16:31:49 +0530 Message-ID: <20260130110159.359501-10-s-adivi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260130110159.359501-1-s-adivi@ti.com> References: <20260130110159.359501-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: SJ5PEPF000001F3:EE_|CY8PR10MB6491:EE_ X-MS-Office365-Filtering-Correlation-Id: 7040c22c-61e9-4d47-b0b4-08de5fef240e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|82310400026|36860700013|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?AHCUbQlzXJiHsbwEU7ZnZNxvtOsbbirK8mP5HN/TjrnfJiN34ncMdXrqETke?= =?us-ascii?Q?xVjSvyFeYyeeekHA0Z9XUGBn8dq5Hk5lUgYKWSsU0zAT2/QY3uAFCncmVgaU?= =?us-ascii?Q?UJoupUfg+KHQiqgxN0yhUP/VSUWfS2sCHxPL7czpIBR8CI7wVVAH/0ZAPPHL?= =?us-ascii?Q?LwtvZCqJaEVb2XdUY5PUkIowbLM/gR+hnHV5gZ8QmirsWhz25XTFNl29n+hj?= =?us-ascii?Q?hhWt5ys+eRPTl1u0ZoFE/m7gMoZiinZY2DNz0zLXPkJmnGJ4Z3nbutkf34Ht?= =?us-ascii?Q?gYn7aSEh5owl4xJh995JtazW+ahpyJaAeATdvz+EF46K35Lu5/Gr4pG5WT6P?= =?us-ascii?Q?uGa+yWECk5FMOHledPJleKZunuQLMxtkVWsaQc+1c5XHZnXgcmho1p7ZIpfG?= =?us-ascii?Q?PYKdFoUpCoHP4ZIpjuXj7fcpI63BN1HbZwNRs6JIOz83vdVjYnPBl9FNZ3bC?= =?us-ascii?Q?VkaFihifKTGYbsabK4ferdkl4bP7HqNj7+4W4B/iwtDwRz5zq1YSxBxHm/6X?= =?us-ascii?Q?nqooCRYNYnSRiN6rN6KLAw82+gWGs8Og0RLxbMGu8ZXN66IXra5wgRrzIHSy?= =?us-ascii?Q?QK40m0repj+PEwib0lKO6I9jpiFC14xPFKsgiV9ylUukz7FUqrI8IIjW/3pU?= =?us-ascii?Q?7EcHxO7Ob1MJ6idBW57q9uI0vNEUJbG2a7YTPh99RTY6HSP8j0qbrgb5xRbN?= =?us-ascii?Q?697i2IO/2MMesB4UMUD1i1if6LZULxKMzTJrvGgKPV6wFCvHa6mR8O2kKIlq?= =?us-ascii?Q?mO4fvGDJrroNtK8xDcewD2bPYjmQqJydIFKsxEFboMEiVnLbtz6+S4vXBS5C?= =?us-ascii?Q?ngURBwQtCnqod2tPvGYt+q3BTgun4JtJBKT0tRYCQO35+2i0yr7rG+zBT/qG?= =?us-ascii?Q?u9fiKuD3wYMSy/kJYc6RNEhLuBSuVypzLKCQpAzC9J0zbNfTs7N9394Ql/pn?= =?us-ascii?Q?bxLrHKyKpdvjqCm5BQ+4I5U28Xk1P1xr1hRxQc7kjmt1HBY7UZCSef/D3rHs?= =?us-ascii?Q?S5LHcCCP29uJ7SIhoXd2hO4YEKQpQXElLU3kzdj81dGqriIEt9dugmbIjzKh?= =?us-ascii?Q?tciwOCbgnWtWV3zkILXGz43sJWtc1nE+/b95ZDH5x6S40TVTrma7XLZWgKfO?= =?us-ascii?Q?fUeHPEZfYTL4WCiDCl7ARf568YqkGSgfjBQADSefgwB20AaKOHJ/c60xIlP5?= =?us-ascii?Q?8KGFD4RCraEMOZ/S95QjpCfJ0Ow4MmZQpESQ1kf/5AroS2dt74eNiGwJd/F1?= =?us-ascii?Q?Gifj8HPqaGgSoXKk4IrCUJExTuESV50KXxFLf2LXCfFBI0NgIWNTI3bKBobT?= =?us-ascii?Q?FYbMmozJLbNSPd/ZEWppK2g8xep6I4yGhaW7kwyGKrPa8dk5KKeZme/kRskN?= =?us-ascii?Q?PjW2u27OkcQxNfQ2VP1gZeoYRWoasrVlDbK/8rnRuAW9K1oJLVbG5viuOixl?= =?us-ascii?Q?ZKUtbYpuEy0wnKuF3c9k05fpw/iOY20nMMofi24x2Svy6cKIYUmZp32kpkIC?= =?us-ascii?Q?nyGA1giSrCUn87uKrkcullpBdEMZxZEmCjnr9Cro6lP/87OYatVcI/8fvrny?= =?us-ascii?Q?UjzYALuj01MMaCzxuaOb3WkzhGn9aTIeaPj/77d8dVqEBRbKIKzY4is86Vmh?= =?us-ascii?Q?Qucu/XDcSkUUhV/2mFNQUZZmmFXElKEscZ5+JjJR5RsER1W2sRNrPkBol1XC?= =?us-ascii?Q?K7140Fj+CKKjb7AHT2B0pPsbg38=3D?= X-Forefront-Antispam-Report: CIP:198.47.21.194;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:flwvzet200.ext.ti.com;PTR:ErrorRetry;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(82310400026)(36860700013)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cI6lDySEejzDACLUL6KX2G1SCPYS5bZThKU0n5iLjCvmpuvgCYfp60jixawdknJe71YNqVyqTZSLfXXIyFk8wLso0eqnu1vLezCQZL22DzSP2A2Yi1p+W9ynx3koUUbNvD92P+esDNq0uNVSh0L0Gr5AIY9/PP7L26JmV2Rkw10YVcHp2USYI98N2PJgjbDgJlsIHT7i+x+siRRpMKdSEnuJsdb6i2uh05T57tQrgBq/sBCBPpn5oHctlZKYoaFYAxgPN6O3U0b3/ZfefqqYlUFEAkkLH9CCwgeafY2ymxj0N+0dNv4WlUoH69p6onNsOt3UcLVThT9YFPePfenKzG5QSgeKNHW0vzAG7OZn6XXht/p2PIFJpYauvGNT+QpoPBd1CpQh4dG0BAxb0vWJYOMYWAysyChJN7GbiaP+WUbnEKsdX6fLgm2xlJy/U2yE X-OriginatorOrg: ti.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jan 2026 11:03:03.8634 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7040c22c-61e9-4d47-b0b4-08de5fef240e 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.194];Helo=[flwvzet200.ext.ti.com] X-MS-Exchange-CrossTenant-AuthSource: SJ5PEPF000001F3.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB6491 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