From mboxrd@z Thu Jan 1 00:00:00 1970 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 C3EEEC9832F for ; Mon, 28 Sep 2026 02:59:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding: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=a15/C6QzRzzsL5TYHeYHQt/0QQVuGNSGXjd2F6SNLCQ=; b=gI17R3Sn6uFysob05lTHc4kpLN LEV8AtwF0ngNDPRWFWGw7Pu2w1A/DgcqJxtsxsEYq1ALIM9TYVkmBB/vrLBHrpDQG/bReA9y0TDzD 7UU1KnbugW2pYESDJmSoRT+4hqmMWV28PW0BXK+m99wXTKcr2tOmbRBx36b3qrFSY3JxgmoguxaIi 5qmJ8WK1daJ+S7niAi6mDfhBcjDGnzjpfqiNZQt1sr7FAgQzY78EL4YkiLonhcDab+dmPfzjimWrP mv9OVPayYu6Xc1RdfUHrg7v+/giJ8+8/nmuEUG4j+5/VXmtJxNXCNQimZU6TciAxV37JVrBlBhu69 UTkuAoDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1xB1aO-0000000HCuk-45Zi; Mon, 28 Sep 2026 02:59:24 +0000 Received: from mx0a-0002e601.pphosted.com ([148.163.150.75]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1xB1aL-0000000HCrU-3Nm8 for linux-arm-kernel@lists.infradead.org; Mon, 28 Sep 2026 02:59:23 +0000 Received: from pps.filterd (m0384305.ppops.net [127.0.0.1]) by m0384305.ppops.net (8.18.1.11/8.18.1.11) with ESMTP id 68RNiAXg3706250; Sun, 27 Sep 2026 21:59:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= proofpoint-05-2026; bh=a15/C6QzRzzsL5TYHeYHQt/0QQVuGNSGXjd2F6SNL CQ=; b=UEnPVBgTB+3fh1g4rrl28YxaC6UE0ZOVxSstuWLnzSGeFhvDyHtNv4t2t NMyfXgOBsU/g+9TVtqlKP7jNqnfNMVV9BHJadO4/NzKT6629JENuPk/ya3Pc1Pl+ SllWCJ22RBzmia81kpMaVJIEVfMIsjrKBbuWRBIls/DGzm5aXUCvVCYPCl8j1Ahi jreN4pS76bKjBr+xGdaxvwhXdaIC/yoy8IP5gOWo4IF9kcW823VSSlgSBgjIlUC+ RfRQ2wir6oYC8W6WzGYRDKX+kbOJkGkyulC8DyQIILBOt7qHkOxnc+4O9o+zfTjz y//E6p3DqSbMTtlmC5iFB5AcmAE3g== Received: from sn4pr0501cu005.outbound.protection.outlook.com (mail-southcentralusazon11011026.outbound.protection.outlook.com [40.93.194.26]) by m0384305.ppops.net (PPS) with ESMTPS id 4gy00nb1sj-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sun, 27 Sep 2026 21:59:18 -0500 (CDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=e6gQW9ncN/3NPLqgYsPz7sLbLm3Q2NmVJuyiW4a30LiYyUBhyM/9udOpzHXT6C7tsDSdbdQtO7t+2MEHs7Yx+tSvsagIfvF+ub4Z4ywOSP5FFxLUEp04GfOnN9KfnQGmlkgZtIQrXDQ1xu1uekvEJOYl38HTHTIPV6trPXWPtDPPHsYfpCeeG+LVFB8xC0ImkV8g1Bs+6xRSrcUgtN9X2ZOKo1Me2/qlb0Fsy9b5ZendB6ArTJsE/cqZz/l4+9sAgelLDluktZSOhekcVI+r6eNkXV9cRAf7Xw1T5sK6l2AKRWDVSP8c0+CccsRTJAh2TtKmGdjVKcj5hy23Dbt1xA== 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=a15/C6QzRzzsL5TYHeYHQt/0QQVuGNSGXjd2F6SNLCQ=; b=Dahme1AiFVRKTQ0eSyJqP75kLk8oO1cyP6uHabcHRJWlDMYfanLYYsZGsFqaQvQzFC/VG4vwKe0jcwuE+2wfWoQcta63/MolFkDYNWl0mCC8S9u9Ak2xs5MrU0lseej53IyNbDwO7oXVEokTCJH1zZLLQ8skllBgqvpegm+MhDoHJT8mI0G0o1zXqB27VOlVqhSTeApg4Gq8q+ZbOPVwROrNHgmCdMQyihAv4mYIYE8WZKaV6KC/pG+yQCYmuSgPH2ed6qmvIjj8fqqXBw74it6NWz9z+R/mH8YILgXZfhtP9W8nhPt6QkYFZawZy56s952i1HyPvfxv0wpTebpl+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 198.47.21.194) 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=a15/C6QzRzzsL5TYHeYHQt/0QQVuGNSGXjd2F6SNLCQ=; b=lIJAZUK3qOrHI1rgxE/oSorzbu/afr1UgoL/DhsJGpLwz/tsR5A1veo6jRPf8ybKyg9UTJFdW2BK7CfaXJDw0rQsWVU0gH1qnQf4UPC9vvZh+snybxKOEWPzfhTCD/8gmzxTZzeSS9c7rlaIWBv2wAfr17FxmRTg16FmJVKWUnE= Received: from DS1PR04CA0002.namprd04.prod.outlook.com (2603:10b6:8:44f::16) by LV8PR10MB7751.namprd10.prod.outlook.com (2603:10b6:408:1e6::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.472.7; Mon, 28 Sep 2026 02:59:13 +0000 Received: from DS2PEPF000061C4.namprd02.prod.outlook.com (2603:10b6:8:44f:cafe::97) by DS1PR04CA0002.outlook.office365.com (2603:10b6:8:44f::16) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.451.23 via Frontend Transport; Mon, 28 Sep 2026 02:59:13 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; 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 DS2PEPF000061C4.mail.protection.outlook.com (10.167.23.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.472.14 via Frontend Transport; Mon, 28 Sep 2026 02:59:12 +0000 Received: from DFLE205.ent.ti.com (10.64.6.63) 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.45; Sun, 27 Sep 2026 21:58:45 -0500 Received: from DFLE215.ent.ti.com (10.64.6.73) by DFLE205.ent.ti.com (10.64.6.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Sun, 27 Sep 2026 21:58:45 -0500 Received: from lelvem-mr06.itg.ti.com (10.180.75.8) by DFLE215.ent.ti.com (10.64.6.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45 via Frontend Transport; Sun, 27 Sep 2026 21:58:45 -0500 Received: from uda0498651.dhcp.ti.com (uda0498651.dhcp.ti.com [10.24.51.254]) by lelvem-mr06.itg.ti.com (8.18.1/8.18.1) with ESMTP id 68S2vqqH2256662; Sun, 27 Sep 2026 21:58:40 -0500 From: Sai Sree Kartheek Adivi To: , , , , , , , , , , , , , CC: , Subject: [PATCH v10 10/19] dmaengine: ti: k3-udma: refactor resource setup functions Date: Mon, 28 Sep 2026 08:26:16 +0530 Message-ID: <20260928025749.1055383-11-s-adivi@ti.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260928025749.1055383-1-s-adivi@ti.com> References: <20260928025749.1055383-1-s-adivi@ti.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF000061C4:EE_|LV8PR10MB7751:EE_ X-MS-Office365-Filtering-Correlation-Id: d8b7b5b1-091c-419c-7d2f-08df1d0c79d4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|7416014|376014|82310400026|36860700016|921020|3023799007|6133799003|10067099003|56012099006|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: 1xz587+ImIll6OQYKCJ8VCPa7nx8+KCau6+5mNgz26QIuV75XLsvIEsGGvuKH/Uqk6o7ca42AqLFozqUR0EaZJREmBFejEMHL10U49AjXHbo3KvyIo6J3pZu6d2MVNGUi4Bas0fIHVLlrL3YrrfUuXXgcRR84ZFymYMaY6RyUkzIct+zWPtZeC8kD0oVn+l31i8rwuQYDD9q3nuDEVEjUazCJFZKvyVIXbvLOc8OVy4oArTUGl9q9ypTzBfK03HD9O66gjwxdFt+FwkiXf/DsVl9fTxjJmHQyU42oajyQ36JiPFCtfrl6I4HeJyn/zgWw67PFQ8NdCj2I9/zELZRS24NA3WCwS1IGsCmSxLXGr9MOXuy+7r5GgEf+IwUNscZ2Tv8CBAPSZzfsvapplMzIdoIABh+u0JT7r0uqQwv4jLHcBcLNT4ThwtOhfK7trTtgOPfnR2N0gGwyRqJZT1B7TNpdyfAF7w9thF+eK/Jc5v/4rfZux1TEZwN1/CySuTCtSqzoyT/pfd3y5ZD43ptNPdyZ+Nl3r2csEMmsqq5fBIlCmCUZyGVmqS6hrTLT+7Yx0Sz2fUJazaG6UpbiXEOJi5X4buPpBc866Xtwza7EULLy4UWJT58m51DC4EfGd3NcHcUbkSu+5ZQCTR8akltJhBAw0Sq43LxO8WclWecK8/QRSKVwQp7HLmWIMX9X37Qs0sxfADXtBOe7YMPJDf7TEho+cOHU+YuHVv2LsXW11tIe8Dok8kh8a/t97DBzZEv 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)(1800799024)(23010399003)(7416014)(376014)(82310400026)(36860700016)(921020)(3023799007)(6133799003)(10067099003)(56012099006)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YpnQbxhUinOrP69vUOpUx/wclUl7SDFXWd0zqzqyOZFUxwYp5eIFrNVTweAdM3eQdg143c6XMR+vs2H9Jdzfv4qcjQ5wzCjsTgr4Ov7HlnAkXg18FWrg1/FEA/CPDpxhGLq7orbSWa984JFpF0htydRcaXgEhVEZgevibIfJ3dH3KBwwLk0UlOjZDnZvs6cCTTPF831trSwhGyKWDydUh4d2D05zSkgF+AoH4urXqKO97xLK4M1+k+7KfWfYayA757wMUVmzBoFjIhcVi3pwFFY22Mhm7bTblDaKm3eI/EMqTXoVaTbQsLNt/RaBqHrGBD0PLmcjHyF+0wi+mxSsI8FkWsnN11kAllqWRZTIW9kpAA248YHlzt3syZzIEGuIZQ+5kOPlUkKL1VAd7xzRfY+MFxwdR8IB6D/cCczPrVC1uyLn9IFzTEnVeUFNo83F X-Exchange-RoutingPolicyChecked: EmkBjcjVa59W3a8tg5qJ87MbZejVvbzYAHcFQ26nW2R5yy0PsqQA+md6jR9eTVIlCtwUHWydLY419vdRyRXvRnCl5NtP66RlcIDi62B2n/Ts27NeFKQNiIXrC7lDMACQpIX0Qn4+9/YZc0hL3A7cMmJ59dBaIpP1hc1JL+6Q7m+64sghlspfvJLb+1iyGzK3OfR5bG8vInkMjY3Ef/Oa74c/jytAmOk5qd3yOn0QYkAyxIDhdxa4Z5neyyD2mRw9UZxFwHiDj+aHnz1vnwG/b/CAy4x8agifwQ1CQN2HJLfuIgR3v9/+EWX0YdXFYfPLYESDEIzj1ZyBUg6KH+e4Zg== X-OriginatorOrg: ti.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2026 02:59:12.9707 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d8b7b5b1-091c-419c-7d2f-08df1d0c79d4 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: DS2PEPF000061C4.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR10MB7751 X-Proofpoint-GUID: D37xmGs4QpdVXIqIroOklIqkKuOOJgAM X-Authority-Analysis: v=2.4 cv=fKysTpae c=1 sm=1 tr=0 ts=6ab9d807 cx=c_pps a=HGE+/hAEzspoXCOliImplg==:117 a=iwqwCZQqcuTv3JOpYdM7/Q==:17 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=VdqzKS8jKosA:10 a=V5UXEbMT0ywA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Z8NIEmU8O1QQgoT56wFK:22 a=taLDd7a_hP9WKsMzeGRc:22 a=sozttTNsAAAA:8 a=I_B2hWj7ayHADsQg9NcA:9 X-Proofpoint-ORIG-GUID: D37xmGs4QpdVXIqIroOklIqkKuOOJgAM X-Proofpoint-Spam-Info: AW1haW4tMjYwOTI4MDAxMSBTYWx0ZWRfX7ze5nzbEDma3 BA52pUvyoScm1zp5mfqoVKrFEF/BZYj0DnThHaHaqGTeje42LKQthJz+iIYAhjziZlc7kEfBeqh mNVVqp7pHKGq7B45zVPFObZuGIndNHU= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTI4MDAxMSBTYWx0ZWRfXyYAfV7HkbXkh fwnB/ZCjiOLdh7jsMJLWFnzuduNUmzbrG3Bne+9tcPBqkUqgsDfxwG12IeH5LRWuAjl082Pcgg5 pJqBO/21fwfxbx9+RProJ0m4vKdxaJxVKYIGL0BmXC3tfCFq+RhLy1qIgHTot1+V+JafSNgyslz BWPSan3udXJErUQRi1kw/PHnOXjfwk3Y0UTJwKEuxjW/xVJUgXGIaAXm+bkzkehh9lBTD1KyTGo mwvGU07MwocicwtHEosjnV6ZMD84rRbrI22gxfncC1Pvjv5zKJirUnvz3kxn26188X5EUp7dxvb Xmtc7Cmbb0bRiCRyBbvVwoHkAAMRPZC5akp1julENUQa3pvEohqHp+/fatRzSLfnVJMZ5EVfral cb0pX5s0dqyEqaOxyA58M0csUEpRgo4sY0IYogAhz/j7U51mOXT7Vm3rhbVUASRrCEbELK4NTDG YQtbMxDqZH5HK1Qwsvw== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-09-26_05,2026-09-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 spamscore=0 priorityscore=1501 malwarescore=0 impostorscore=0 adultscore=0 phishscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609280011 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260927_195921_868027_A0229056 X-CRM114-Status: GOOD ( 16.82 ) 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 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. - Rename setup_resources to k3_udma_setup_resources to avoid polluting global kernel namespace with generic symbol. 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 | 200 ++++++++++++++++++++++++++++++++ drivers/dma/ti/k3-udma.c | 184 ++--------------------------- drivers/dma/ti/k3-udma.h | 6 + 3 files changed, 213 insertions(+), 177 deletions(-) diff --git a/drivers/dma/ti/k3-udma-common.c b/drivers/dma/ti/k3-udma-common.c index 34f8eab9ddb57..d0afbab01786f 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 #include "k3-udma.h" @@ -2334,5 +2336,203 @@ void bcdma_free_bchan_resources(struct udma_chan *uc) } EXPORT_SYMBOL_GPL(bcdma_free_bchan_resources); +static int bcdma_setup_resources(struct udma_dev *ud) +{ + int ret; + struct device *dev = ud->dev; + u32 cap; + + /* Set up the throughput level start indexes */ + cap = udma_read(ud->mmrs[MMR_GCFG], 0x2c); + if (BCDMA_CAP3_UBCHAN_CNT(cap)) { + ud->bchan_tpl.levels = 3; + ud->bchan_tpl.start_idx[1] = BCDMA_CAP3_UBCHAN_CNT(cap); + ud->bchan_tpl.start_idx[0] = BCDMA_CAP3_HBCHAN_CNT(cap); + } else if (BCDMA_CAP3_HBCHAN_CNT(cap)) { + ud->bchan_tpl.levels = 2; + ud->bchan_tpl.start_idx[0] = BCDMA_CAP3_HBCHAN_CNT(cap); + } else { + ud->bchan_tpl.levels = 1; + } + + cap = udma_read(ud->mmrs[MMR_GCFG], 0x30); + if (BCDMA_CAP4_URCHAN_CNT(cap)) { + ud->rchan_tpl.levels = 3; + ud->rchan_tpl.start_idx[1] = BCDMA_CAP4_URCHAN_CNT(cap); + ud->rchan_tpl.start_idx[0] = BCDMA_CAP4_HRCHAN_CNT(cap); + } else if (BCDMA_CAP4_HRCHAN_CNT(cap)) { + ud->rchan_tpl.levels = 2; + ud->rchan_tpl.start_idx[0] = BCDMA_CAP4_HRCHAN_CNT(cap); + } else { + ud->rchan_tpl.levels = 1; + } + + if (BCDMA_CAP4_UTCHAN_CNT(cap)) { + ud->tchan_tpl.levels = 3; + ud->tchan_tpl.start_idx[1] = BCDMA_CAP4_UTCHAN_CNT(cap); + ud->tchan_tpl.start_idx[0] = BCDMA_CAP4_HTCHAN_CNT(cap); + } else if (BCDMA_CAP4_HTCHAN_CNT(cap)) { + ud->tchan_tpl.levels = 2; + ud->tchan_tpl.start_idx[0] = BCDMA_CAP4_HTCHAN_CNT(cap); + } else { + ud->tchan_tpl.levels = 1; + } + + ud->bchan_map = devm_bitmap_zalloc(dev, ud->bchan_cnt, GFP_KERNEL); + ud->bchans = devm_kcalloc(dev, ud->bchan_cnt, sizeof(*ud->bchans), + GFP_KERNEL); + ud->tchan_map = devm_bitmap_zalloc(dev, ud->tchan_cnt, GFP_KERNEL); + ud->tchans = devm_kcalloc(dev, ud->tchan_cnt, sizeof(*ud->tchans), + GFP_KERNEL); + ud->rchan_map = devm_bitmap_zalloc(dev, ud->rchan_cnt, GFP_KERNEL); + ud->rchans = 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 = devm_kcalloc(dev, BITS_TO_LONGS(ud->rchan_cnt), + sizeof(unsigned long), + GFP_KERNEL); + ud->rflows = 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 = ud->bcdma_setup_sci_resources(ud); + if (ret) + return ret; + } + + return 0; +} + +static int pktdma_setup_resources(struct udma_dev *ud) +{ + int ret; + struct device *dev = ud->dev; + u32 cap3; + + /* Set up the throughput level start indexes */ + cap3 = udma_read(ud->mmrs[MMR_GCFG], 0x2c); + if (UDMA_CAP3_UCHAN_CNT(cap3)) { + ud->tchan_tpl.levels = 3; + ud->tchan_tpl.start_idx[1] = UDMA_CAP3_UCHAN_CNT(cap3); + ud->tchan_tpl.start_idx[0] = UDMA_CAP3_HCHAN_CNT(cap3); + } else if (UDMA_CAP3_HCHAN_CNT(cap3)) { + ud->tchan_tpl.levels = 2; + ud->tchan_tpl.start_idx[0] = UDMA_CAP3_HCHAN_CNT(cap3); + } else { + ud->tchan_tpl.levels = 1; + } + + ud->rchan_tpl.levels = ud->tchan_tpl.levels; + ud->rchan_tpl.start_idx[0] = ud->tchan_tpl.start_idx[0]; + ud->rchan_tpl.start_idx[1] = ud->tchan_tpl.start_idx[1]; + + ud->tchan_map = devm_bitmap_zalloc(dev, ud->tchan_cnt, GFP_KERNEL); + ud->tchans = devm_kcalloc(dev, ud->tchan_cnt, sizeof(*ud->tchans), + GFP_KERNEL); + ud->rchan_map = devm_bitmap_zalloc(dev, ud->rchan_cnt, GFP_KERNEL); + ud->rchans = devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rchans), + GFP_KERNEL); + ud->rflow_in_use = devm_kcalloc(dev, BITS_TO_LONGS(ud->rflow_cnt), + sizeof(unsigned long), + GFP_KERNEL); + ud->rflows = devm_kcalloc(dev, ud->rflow_cnt, sizeof(*ud->rflows), + GFP_KERNEL); + ud->tflow_map = devm_bitmap_zalloc(dev, ud->tflow_cnt, 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 = ud->pktdma_setup_sci_resources(ud); + if (ret) + return ret; + } + + return 0; +} + +int k3_udma_setup_resources(struct udma_dev *ud) +{ + struct device *dev = ud->dev; + int ch_count, ret; + + switch (ud->match_data->type) { + case DMA_TYPE_UDMA: + if (!ud->udma_setup_resources) + return -EINVAL; + ret = ud->udma_setup_resources(ud); + break; + case DMA_TYPE_BCDMA: + ret = bcdma_setup_resources(ud); + break; + case DMA_TYPE_PKTDMA: + ret = pktdma_setup_resources(ud); + break; + default: + return -EINVAL; + } + + if (ret) + return ret; + + ch_count = ud->bchan_cnt + ud->tchan_cnt + ud->rchan_cnt; + if (ud->bchan_cnt) + ch_count -= bitmap_weight(ud->bchan_map, ud->bchan_cnt); + ch_count -= bitmap_weight(ud->tchan_map, ud->tchan_cnt); + ch_count -= bitmap_weight(ud->rchan_map, ud->rchan_cnt); + if (!ch_count) + return -ENODEV; + + ud->channels = 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(k3_udma_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 21978f17e327f..9a261747c8709 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[] = { [RM_RANGE_TFLOW] = "ti,sci-rm-range-tflow", }; -static int udma_setup_resources(struct udma_dev *ud) +int udma_setup_resources(struct udma_dev *ud) { int ret, i, j; struct device *dev = ud->dev; @@ -2245,74 +2245,13 @@ static int udma_setup_resources(struct udma_dev *ud) return 0; } -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 = ud->dev; struct ti_sci_resource *rm_res, irq_res; struct udma_tisci_rm *tisci_rm = &ud->tisci_rm; const struct udma_oes_offsets *oes = &ud->soc_data->oes; - u32 cap; - - /* Set up the throughput level start indexes */ - cap = udma_read(ud->mmrs[MMR_GCFG], 0x2c); - if (BCDMA_CAP3_UBCHAN_CNT(cap)) { - ud->bchan_tpl.levels = 3; - ud->bchan_tpl.start_idx[1] = BCDMA_CAP3_UBCHAN_CNT(cap); - ud->bchan_tpl.start_idx[0] = BCDMA_CAP3_HBCHAN_CNT(cap); - } else if (BCDMA_CAP3_HBCHAN_CNT(cap)) { - ud->bchan_tpl.levels = 2; - ud->bchan_tpl.start_idx[0] = BCDMA_CAP3_HBCHAN_CNT(cap); - } else { - ud->bchan_tpl.levels = 1; - } - - cap = udma_read(ud->mmrs[MMR_GCFG], 0x30); - if (BCDMA_CAP4_URCHAN_CNT(cap)) { - ud->rchan_tpl.levels = 3; - ud->rchan_tpl.start_idx[1] = BCDMA_CAP4_URCHAN_CNT(cap); - ud->rchan_tpl.start_idx[0] = BCDMA_CAP4_HRCHAN_CNT(cap); - } else if (BCDMA_CAP4_HRCHAN_CNT(cap)) { - ud->rchan_tpl.levels = 2; - ud->rchan_tpl.start_idx[0] = BCDMA_CAP4_HRCHAN_CNT(cap); - } else { - ud->rchan_tpl.levels = 1; - } - - if (BCDMA_CAP4_UTCHAN_CNT(cap)) { - ud->tchan_tpl.levels = 3; - ud->tchan_tpl.start_idx[1] = BCDMA_CAP4_UTCHAN_CNT(cap); - ud->tchan_tpl.start_idx[0] = BCDMA_CAP4_HTCHAN_CNT(cap); - } else if (BCDMA_CAP4_HTCHAN_CNT(cap)) { - ud->tchan_tpl.levels = 2; - ud->tchan_tpl.start_idx[0] = BCDMA_CAP4_HTCHAN_CNT(cap); - } else { - ud->tchan_tpl.levels = 1; - } - - ud->bchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->bchan_cnt), - sizeof(unsigned long), GFP_KERNEL); - ud->bchans = devm_kcalloc(dev, ud->bchan_cnt, sizeof(*ud->bchans), - GFP_KERNEL); - ud->tchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tchan_cnt), - sizeof(unsigned long), GFP_KERNEL); - ud->tchans = devm_kcalloc(dev, ud->tchan_cnt, sizeof(*ud->tchans), - GFP_KERNEL); - ud->rchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rchan_cnt), - sizeof(unsigned long), GFP_KERNEL); - ud->rchans = 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 = devm_kcalloc(dev, BITS_TO_LONGS(ud->rchan_cnt), - sizeof(unsigned long), - GFP_KERNEL); - ud->rflows = 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; /* Get resource ranges from tisci */ for (i = 0; i < RM_RANGE_LAST; i++) { @@ -2476,51 +2415,13 @@ static int bcdma_setup_resources(struct udma_dev *ud) return 0; } -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 = ud->dev; struct ti_sci_resource *rm_res, irq_res; struct udma_tisci_rm *tisci_rm = &ud->tisci_rm; const struct udma_oes_offsets *oes = &ud->soc_data->oes; - u32 cap3; - - /* Set up the throughput level start indexes */ - cap3 = udma_read(ud->mmrs[MMR_GCFG], 0x2c); - if (UDMA_CAP3_UCHAN_CNT(cap3)) { - ud->tchan_tpl.levels = 3; - ud->tchan_tpl.start_idx[1] = UDMA_CAP3_UCHAN_CNT(cap3); - ud->tchan_tpl.start_idx[0] = UDMA_CAP3_HCHAN_CNT(cap3); - } else if (UDMA_CAP3_HCHAN_CNT(cap3)) { - ud->tchan_tpl.levels = 2; - ud->tchan_tpl.start_idx[0] = UDMA_CAP3_HCHAN_CNT(cap3); - } else { - ud->tchan_tpl.levels = 1; - } - - ud->rchan_tpl.levels = ud->tchan_tpl.levels; - ud->rchan_tpl.start_idx[0] = ud->tchan_tpl.start_idx[0]; - ud->rchan_tpl.start_idx[1] = ud->tchan_tpl.start_idx[1]; - - ud->tchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tchan_cnt), - sizeof(unsigned long), GFP_KERNEL); - ud->tchans = devm_kcalloc(dev, ud->tchan_cnt, sizeof(*ud->tchans), - GFP_KERNEL); - ud->rchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rchan_cnt), - sizeof(unsigned long), GFP_KERNEL); - ud->rchans = devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rchans), - GFP_KERNEL); - ud->rflow_in_use = devm_kcalloc(dev, BITS_TO_LONGS(ud->rflow_cnt), - sizeof(unsigned long), - GFP_KERNEL); - ud->rflows = devm_kcalloc(dev, ud->rflow_cnt, sizeof(*ud->rflows), - GFP_KERNEL); - ud->tflow_map = 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; /* Get resource ranges from tisci */ for (i = 0; i < RM_RANGE_LAST; i++) { @@ -2631,80 +2532,6 @@ static int pktdma_setup_resources(struct udma_dev *ud) return 0; } -static int setup_resources(struct udma_dev *ud) -{ - struct device *dev = ud->dev; - int ch_count, ret; - - switch (ud->match_data->type) { - case DMA_TYPE_UDMA: - ret = udma_setup_resources(ud); - break; - case DMA_TYPE_BCDMA: - ret = bcdma_setup_resources(ud); - break; - case DMA_TYPE_PKTDMA: - ret = pktdma_setup_resources(ud); - break; - default: - return -EINVAL; - } - - if (ret) - return ret; - - ch_count = ud->bchan_cnt + ud->tchan_cnt + ud->rchan_cnt; - if (ud->bchan_cnt) - ch_count -= bitmap_weight(ud->bchan_map, ud->bchan_cnt); - ch_count -= bitmap_weight(ud->tchan_map, ud->tchan_cnt); - ch_count -= bitmap_weight(ud->rchan_map, ud->rchan_cnt); - if (!ch_count) - return -ENODEV; - - ud->channels = 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 = pdev->dev.parent->of_node; @@ -2747,6 +2574,9 @@ static int udma_probe(struct platform_device *pdev) ud->decrement_byte_counters = udma_decrement_byte_counters; ud->psil_pair = navss_psil_pair; ud->psil_unpair = navss_psil_unpair; + ud->udma_setup_resources = udma_setup_resources; + ud->bcdma_setup_sci_resources = bcdma_setup_sci_resources; + ud->pktdma_setup_sci_resources = pktdma_setup_sci_resources; ret = udma_get_mmrs(pdev, ud); if (ret) @@ -2876,7 +2706,7 @@ static int udma_probe(struct platform_device *pdev) INIT_LIST_HEAD(&ud->ddev.channels); INIT_LIST_HEAD(&ud->desc_to_purge); - ch_count = setup_resources(ud); + ch_count = k3_udma_setup_resources(ud); if (ch_count <= 0) return ch_count; diff --git a/drivers/dma/ti/k3-udma.h b/drivers/dma/ti/k3-udma.h index 329df7eb156b2..d64b670d42490 100644 --- a/drivers/dma/ti/k3-udma.h +++ b/drivers/dma/ti/k3-udma.h @@ -357,6 +357,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); }; struct udma_desc { @@ -679,6 +682,9 @@ struct udma_bchan *__udma_reserve_bchan(struct udma_dev *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); +int udma_setup_resources(struct udma_dev *ud); +int k3_udma_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_thread); int xudma_navss_psil_unpair(struct udma_dev *ud, u32 src_thread, -- 2.54.0