From nobody Sat Nov 23 11:45:05 2024 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (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 910BB149011; Thu, 21 Nov 2024 04:26:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732163173; cv=none; b=oGifiwM1ziMVdX8PbacBxsxXIY3x0q8cJOnxpbDk4RMhYXHqGn/d814itKfxnVTGb62ZicnsoggO7XvqZxqj86PsDF6+iTDWwIzQp7fze9tSXpbY/6HVaYnSq1I0bbB4ErZlka9QEvCmBOg+WL8pLpzUkYHTQ4zV2Szp/IT+Jq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732163173; c=relaxed/simple; bh=h7xF7qzQH+4asbQvWDK+eJM8NqxpJys5ZkVVO6WWAXE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VEevf+R63tXGBCdEMsNgXlnQmda7m+IV0GNGYAMrL9q+FUHvlranWBLasbFXTK95w2bL2/yYgTRANAVAO9ix/iSvG6mXIfdCl8fdup7+V94SNYoKT2PvbT/QY6ugWphIWcUCxLqG2ryzGl6scN2DSNWFMhcZMDXdhs8Nn7hVmrQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=lJ7Fk6GJ; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="lJ7Fk6GJ" X-UUID: b985490aa7c011ef99858b75a2457dd9-20241121 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=mJDZ8TbEOg8kfWuALOz+YShjGUyzgs27hJEVqgGGWq4=; b=lJ7Fk6GJHltgO5mTmTR7V8w82jcMT+ncF2fNdF0gODkrxb4fHG1+Oxwewpy5y6gwEzyeQxPxtzuMWrVsfWK3zSwQbYWL+QR8kZQMCuBTFgPf3EJSfWYgTwG53Mu/ysY4i2pc281E4FWX/SqErO60Nc2wpaXkvudeN2FJsxxHGqc=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.44,REQID:7072b010-d679-496a-83b1-da887196d3be,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:464815b,CLOUDID:8e35d6fe-58af-4a77-b036-41f515d81476,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:81|82|102,TC:nil,Content:0,EDM:-3,IP :nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0, LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: b985490aa7c011ef99858b75a2457dd9-20241121 Received: from mtkmbs14n2.mediatek.inc [(172.21.101.76)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1235469517; Thu, 21 Nov 2024 12:26:05 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Thu, 21 Nov 2024 12:26:04 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Thu, 21 Nov 2024 12:26:04 +0800 From: Jason-JH.Lin To: Jassi Brar , Chun-Kuang Hu , AngeloGioacchino Del Regno , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , Mauro Carvalho Chehab CC: David Airlie , Simona Vetter , Moudy Ho , , , , , , , "Jason-JH . Lin" , Singo Chang , Nancy Lin , Subject: [PATCH 5/8] soc: mediatek: mtk-cmdq: Add mminfra_offset compatibility for DRAM address Date: Thu, 21 Nov 2024 12:25:59 +0800 Message-ID: <20241121042602.32730-6-jason-jh.lin@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20241121042602.32730-1-jason-jh.lin@mediatek.com> References: <20241121042602.32730-1-jason-jh.lin@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since GCE has been moved to mminfra in MT8196, all transactions from mminfra to DRAM will have their addresses adjusted by subtracting a mminfra offset. This information should be handled inside the CMDQ driver, allowing CMDQ users to call CMDQ APIs as usual. Therefore, CMDQ driver needs to use the mbox API to get the mminfra_offset value of the SoC, and then add it to the DRAM address when generating instructions to ensure GCE accesses the correct DRAM address. Signed-off-by: Jason-JH.Lin --- drivers/soc/mediatek/mtk-cmdq-helper.c | 43 +++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/soc/mediatek/mtk-cmdq-helper.c b/drivers/soc/mediatek/= mtk-cmdq-helper.c index ffdf3cecf6fe..bd2aa9152afc 100644 --- a/drivers/soc/mediatek/mtk-cmdq-helper.c +++ b/drivers/soc/mediatek/mtk-cmdq-helper.c @@ -222,6 +222,9 @@ int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u32= pa_base, u16 offset, u32 if (cmdq_subsys_is_valid(cl->chan, subsys)) { err =3D cmdq_pkt_append_command(pkt, inst); } else { + if (cmdq_addr_need_offset(cl->chan, pa_base)) + pa_base +=3D cmdq_get_offset_pa(cl->chan); + err =3D cmdq_pkt_assign(pkt, 0, CMDQ_ADDR_HIGH(pa_base)); if (err < 0) return err; @@ -255,12 +258,16 @@ int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u8 subs= ys, u32 pa_base, } err =3D cmdq_pkt_write(pkt, subsys, pa_base, offset_mask, value); } else { + if (cmdq_addr_need_offset(cl->chan, pa_base)) + pa_base +=3D cmdq_get_offset_pa(cl->chan); + err =3D cmdq_pkt_assign(pkt, 0, CMDQ_ADDR_HIGH(pa_base)); if (err < 0) return err; =20 err =3D cmdq_pkt_write_s_mask_value(pkt, 0, CMDQ_ADDR_LOW(offset), value= , mask); } + return err; } EXPORT_SYMBOL(cmdq_pkt_write_mask); @@ -347,10 +354,22 @@ EXPORT_SYMBOL(cmdq_pkt_write_s_mask_value); =20 int cmdq_pkt_mem_move(struct cmdq_pkt *pkt, dma_addr_t src_addr, dma_addr_= t dst_addr) { + struct cmdq_client *cl =3D (struct cmdq_client *)pkt->cl; const u16 high_addr_reg_idx =3D CMDQ_THR_SPR_IDX0; const u16 value_reg_idx =3D CMDQ_THR_SPR_IDX1; int ret; =20 + if (!cl) { + pr_err("%s %d: pkt->cl is NULL!\n", __func__, __LINE__); + return -EINVAL; + } + + if (cmdq_addr_need_offset(cl->chan, src_addr)) + src_addr +=3D cmdq_get_offset_pa(cl->chan); + + if (cmdq_addr_need_offset(cl->chan, dst_addr)) + dst_addr +=3D cmdq_get_offset_pa(cl->chan); + /* read the value of src_addr into high_addr_reg_idx */ ret =3D cmdq_pkt_assign(pkt, high_addr_reg_idx, CMDQ_ADDR_HIGH(src_addr)); if (ret < 0) @@ -450,6 +469,9 @@ int cmdq_pkt_poll(struct cmdq_pkt *pkt, u8 subsys, u32 = pa_base, } =20 if (!cmdq_subsys_is_valid(cl->chan, subsys)) { + if (cmdq_addr_need_offset(cl->chan, pa_base)) + pa_base +=3D cmdq_get_offset_pa(cl->chan); + err =3D cmdq_pkt_assign(pkt, CMDQ_POLL_ADDR_GPR, pa_base); if (err < 0) return err; @@ -480,10 +502,19 @@ EXPORT_SYMBOL(cmdq_pkt_poll_mask); =20 int cmdq_pkt_poll_addr(struct cmdq_pkt *pkt, dma_addr_t addr, u32 value, u= 32 mask) { + struct cmdq_client *cl =3D (struct cmdq_client *)pkt->cl; struct cmdq_instruction inst =3D { {0} }; u8 use_mask =3D 0; int ret; =20 + if (!cl) { + pr_err("%s %d: pkt->cl is NULL!\n", __func__, __LINE__); + return -EINVAL; + } + + if (cmdq_addr_need_offset(cl->chan, addr)) + addr +=3D cmdq_get_offset_pa(cl->chan); + /* * Append an MASK instruction to set the mask for following POLL instruct= ion * which enables use_mask bit. @@ -561,11 +592,21 @@ EXPORT_SYMBOL(cmdq_pkt_assign); =20 int cmdq_pkt_jump_abs(struct cmdq_pkt *pkt, dma_addr_t addr, u8 shift_pa) { + struct cmdq_client *cl =3D (struct cmdq_client *)pkt->cl; struct cmdq_instruction inst =3D { .op =3D CMDQ_CODE_JUMP, .offset =3D CMDQ_JUMP_ABSOLUTE, - .value =3D addr >> shift_pa }; + + if (!cl) { + pr_err("%s %d: pkt->cl is NULL!\n", __func__, __LINE__); + return -EINVAL; + } + + if (cmdq_addr_need_offset(cl->chan, addr)) + addr +=3D cmdq_get_offset_pa(cl->chan); + + inst.value =3D addr >> shift_pa; return cmdq_pkt_append_command(pkt, inst); } EXPORT_SYMBOL(cmdq_pkt_jump_abs); --=20 2.43.0