From patchwork Thu Feb 22 15:41:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chun-Kuang Hu X-Patchwork-Id: 204828 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp25830dyb; Thu, 22 Feb 2024 07:44:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW6pTUJQAECPdGCQKXM9i1EsK/wqVOHYISO54J7JPaL8uCAnEUz0S9QfkmPU0SYfH3THZ+LsrZKs6WytiMoGcIEdRcwwA== X-Google-Smtp-Source: AGHT+IFaP+iBRWMS+lbZEZ3SsqBDHfq9LtLR3IpajzV9IhiinIX//lBzeAKhjSzEbTdTMSPay+Xj X-Received: by 2002:a05:6808:3845:b0:3c1:7ea6:ff71 with SMTP id ej5-20020a056808384500b003c17ea6ff71mr2081955oib.12.1708616693384; Thu, 22 Feb 2024 07:44:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708616693; cv=pass; d=google.com; s=arc-20160816; b=IdZ2efTt3S9sdnlf3uSTHrS9/i4JsUb2pm6+C2/Zv4uNPlR4z47seZGYCWqCNiy/nS HgwBRItQqVn9gXup0sN95KF3luGV05jQWuvOCq6bl01HgQkxw8w6HdFUKIUgxpSkjfJF XQuCHpifOyxXP0CW5hH5ZkKu2lNuKWg0/5N0M2+BwxhE5dcoO4UcrgUsskWHOhY+mYgJ vbYK0RYwkQYYGva+izx0c6frsx4Ut7Qub1xydCwbKzSuM/V2c5REGTPlyoEsSw0XVrqa RVtTXKGA+ypjVJeUadBBihj6Yc/n+H6eGpZu0m1djHWi52cHKAHPQoPQwhBghMvNd5pr NHyA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=hwUROcBrFm6NVio+xuFMjF7z84GtRU/t16s+qSv3qrM=; fh=vD8tJ9d2mp7H51jNKyMUDglMjHY1Ew4hzsuiSabS+YY=; b=B1pvY1vQ6SSQcb/GppgOuDdIn4uI3EP337Xkm+LKkiaJQIt0JVs6k4C/Yb7ZCHAs3w rCGOC/QQ2RpCp4oYob7CYJ/OCqWqNyQax6j6+UqNCjgFHdRBWi+Y237YAIaXDhxi5QDZ rdTM7QTudY1+ktpPJGQbhT2uc1DWLoJ5/cIe9gVGEuTJs4J04hOyiHKbWAUH8FRIxKnb 9sy9PBntgvB3PsjKhwJwHq6FrxHQywbVfaa65lsAd4CGTQBlrQpBRpfuvXWDNVZyLFFf plheLlIbb9zxR6ARR/hZCsh8F/C1huJt+9EpYGLA+XmLHJOSGhRz2BZhs1bDxVlUokXs cvMQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="I9h3a/Eg"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-76804-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76804-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id j14-20020ac8664e000000b0042dc8edb6e7si12800247qtp.657.2024.02.22.07.44.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 07:44:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76804-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="I9h3a/Eg"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-76804-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76804-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2D7001C249B3 for ; Thu, 22 Feb 2024 15:44:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6987015696B; Thu, 22 Feb 2024 15:41:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="I9h3a/Eg" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A7E79156966; Thu, 22 Feb 2024 15:41:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708616511; cv=none; b=W7WYvRkYCalw2BlSROBhFS7YP8i82aNDwPLwQrXSGNAoTRsp36Rw7BpIiS3l5YX+YHehLm6kO4PwhKUbjVE6TJoCtEze6uuc9mOWck5Gs3R2MhAHkNpzldxD++HLykmSrBGFhaTZg9Fkgda/Isn/BLpRdpfK+skKKAWM/j6IyXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708616511; c=relaxed/simple; bh=9avcaQo+g1SO3OnMBO0SW08LTKb5Q/Pc21HFm51gndM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GhskCZVaa56Zz74Q0RcvxuroO9dPbkEtMgL0r32kyY+JHGOtyqcKHoG/tWBfYSHTW5q+dI1zbzbC9saNBQTXG3ctf+lj3pH/zY4U4wR4KKG0TRNvna3/hElcjM/0030v9fBw+zqqy6S3n7ETCDVgs2mVBDE7xT/qclmXfB3N6yA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=I9h3a/Eg; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84D17C433A6; Thu, 22 Feb 2024 15:41:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708616511; bh=9avcaQo+g1SO3OnMBO0SW08LTKb5Q/Pc21HFm51gndM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I9h3a/EgFD0efBdf9svW4VSrGmDb6rsd2zPtk3U/b2zo/X5iMDU8AfEEL2k0d9tGW Yyh37Kn8PPwqqS7Aseq8cxgUFfX7wQtEJOLjs0B8MAiQ5LNayOfTCeWgdUndvS7IdT hvOR274o+TGEjGTKzdy/5EuYnO26HTEcMV1C0uvzAEZYinyEesdVnBtZ7LLclZeYSo apxaQmIxZvulopyzfm/b3aYiSP7p6hvXwVclkGiwOcwQIBS4O/c1ADziRgE4nD8cn0 nU8xAHIhys2JpoCwhGzc7wEBdc41y3GgISPPlwxN+eqxQwzUV+qnowsbht3Uw3SX7U erKvjaBM/Ad0Q== From: Chun-Kuang Hu To: Matthias Brugger , AngeloGioacchino Del Regno , Mauro Carvalho Chehab , Moudy Ho , "Jason-JH . Lin" , linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Cc: Chun-Kuang Hu Subject: [PATCH v2 07/12] soc: mediatek: cmdq: Refine cmdq_pkt_create() and cmdq_pkt_destroy() Date: Thu, 22 Feb 2024 15:41:15 +0000 Message-Id: <20240222154120.16959-8-chunkuang.hu@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222154120.16959-1-chunkuang.hu@kernel.org> References: <20240222154120.16959-1-chunkuang.hu@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791614457932764824 X-GMAIL-MSGID: 1791614457932764824 cmdq_pkt_create() and cmdq_pkt_destroy() is not suitable for client drivers so each client driver has implement its own function. This refinement would pass struct cmdq_pkt pointer into cmdq_pkt_create(). In addition, client driver has the struct cmdq_client information, so it's not necessary to store this information in struct cmdq_pkt. After this refinement, client drivers could use these helper funciton instead of implementing its own version. Signed-off-by: Chun-Kuang Hu --- drivers/soc/mediatek/mtk-cmdq-helper.c | 24 +++++++----------------- include/linux/soc/mediatek/mtk-cmdq.h | 14 ++++++++------ 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/drivers/soc/mediatek/mtk-cmdq-helper.c b/drivers/soc/mediatek/mtk-cmdq-helper.c index bbe41302210a..1a1f1b260a06 100644 --- a/drivers/soc/mediatek/mtk-cmdq-helper.c +++ b/drivers/soc/mediatek/mtk-cmdq-helper.c @@ -106,22 +106,16 @@ void cmdq_mbox_destroy(struct cmdq_client *client) } EXPORT_SYMBOL(cmdq_mbox_destroy); -struct cmdq_pkt *cmdq_pkt_create(struct cmdq_client *client, size_t size) +int cmdq_pkt_create(struct cmdq_client *client, struct cmdq_pkt *pkt, size_t size) { - struct cmdq_pkt *pkt; struct device *dev; dma_addr_t dma_addr; - pkt = kzalloc(sizeof(*pkt), GFP_KERNEL); - if (!pkt) - return ERR_PTR(-ENOMEM); pkt->va_base = kzalloc(size, GFP_KERNEL); - if (!pkt->va_base) { - kfree(pkt); - return ERR_PTR(-ENOMEM); - } + if (!pkt->va_base) + return -ENOMEM; + pkt->buf_size = size; - pkt->cl = (void *)client; dev = client->chan->mbox->dev; dma_addr = dma_map_single(dev, pkt->va_base, pkt->buf_size, @@ -129,24 +123,20 @@ struct cmdq_pkt *cmdq_pkt_create(struct cmdq_client *client, size_t size) if (dma_mapping_error(dev, dma_addr)) { dev_err(dev, "dma map failed, size=%u\n", (u32)(u64)size); kfree(pkt->va_base); - kfree(pkt); - return ERR_PTR(-ENOMEM); + return -ENOMEM; } pkt->pa_base = dma_addr; - return pkt; + return 0; } EXPORT_SYMBOL(cmdq_pkt_create); -void cmdq_pkt_destroy(struct cmdq_pkt *pkt) +void cmdq_pkt_destroy(struct cmdq_client *client, struct cmdq_pkt *pkt) { - struct cmdq_client *client = (struct cmdq_client *)pkt->cl; - dma_unmap_single(client->chan->mbox->dev, pkt->pa_base, pkt->buf_size, DMA_TO_DEVICE); kfree(pkt->va_base); - kfree(pkt); } EXPORT_SYMBOL(cmdq_pkt_destroy); diff --git a/include/linux/soc/mediatek/mtk-cmdq.h b/include/linux/soc/mediatek/mtk-cmdq.h index f82e789550ae..d9d0ee5ecb7a 100644 --- a/include/linux/soc/mediatek/mtk-cmdq.h +++ b/include/linux/soc/mediatek/mtk-cmdq.h @@ -62,17 +62,19 @@ void cmdq_mbox_destroy(struct cmdq_client *client); /** * cmdq_pkt_create() - create a CMDQ packet * @client: the CMDQ mailbox client + * @pkt: the CMDQ packet * @size: required CMDQ buffer size * - * Return: CMDQ packet pointer + * Return: 0 for success; else the error code is returned */ -struct cmdq_pkt *cmdq_pkt_create(struct cmdq_client *client, size_t size); +int cmdq_pkt_create(struct cmdq_client *client, struct cmdq_pkt *pkt, size_t size); /** * cmdq_pkt_destroy() - destroy the CMDQ packet + * @client: the CMDQ mailbox client * @pkt: the CMDQ packet */ -void cmdq_pkt_destroy(struct cmdq_pkt *pkt); +void cmdq_pkt_destroy(struct cmdq_client *client, struct cmdq_pkt *pkt); /** * cmdq_pkt_write() - append write command to the CMDQ packet @@ -312,12 +314,12 @@ static inline struct cmdq_client *cmdq_mbox_create(struct device *dev, int index static inline void cmdq_mbox_destroy(struct cmdq_client *client) { } -static inline struct cmdq_pkt *cmdq_pkt_create(struct cmdq_client *client, size_t size) +static inline int cmdq_pkt_create(struct cmdq_client *client, struct cmdq_pkt *pkt, size_t size) { - return ERR_PTR(-EINVAL); + return -EINVAL; } -static inline void cmdq_pkt_destroy(struct cmdq_pkt *pkt) { } +static inline void cmdq_pkt_destroy(struct cmdq_client *client, struct cmdq_pkt *pkt) { } static inline int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u16 offset, u32 value) {