From patchwork Thu Oct 12 11:11:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mao Jinlong X-Patchwork-Id: 151936 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1146749vqb; Thu, 12 Oct 2023 04:12:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEKBxGVzDeKVEeEPGFzp7khUyCxNlk5aFGrqXjfrhV+7HyOaTXjFcDID8ylRqFOh53eTeFu X-Received: by 2002:a05:6359:b9a:b0:14d:2dd5:a777 with SMTP id gf26-20020a0563590b9a00b0014d2dd5a777mr19890018rwb.2.1697109154289; Thu, 12 Oct 2023 04:12:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697109154; cv=none; d=google.com; s=arc-20160816; b=XlM+v1wTnsErBu8Z2OhiutnaRFk4qPPvCGlfHBnZi/fwYwFY2jmIzM1M0NgP/G+HIC CzOtP9JN1Dzo342CnPnV3gCKBA5yYVmy+ifHgOtYZBDI+PNSex7Yo8jDsxYuCa4TmW8R Vpnx/dFUy54wxDtANO3qDLuI39OOKpeEZCxM3HUoiIWJEOZbjFMX+l03VNHnM9Rs4epg YOdO/wSMJDpxXY3R2VRUnxlT/ef+QH/gtOuJdHuSftp/Pv1iISiPP/LpuwjpqDT34KN5 mKGDQJn1vOJjIaFbnyMk/DdLQ4gSzQhhtWKimv5EQ3hEOPaV3tfavB9TMJlKytIvyYVu bqJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=Wad0ld8fBaOFsRuaoa9MCZdNhz5XSOOmm/PwmyCiGok=; fh=d1Uj+RYCPjmr+Q98i2DK+ELI3Haga4hVXJxJFGToQb0=; b=cCfb92uscl3PfHxCLNnzv8gj6pRm8O/hACr7ZMiAivHbsZ51P/UTnsE+fHueA2ACCv xXsnZls/jcGokZzF49JQsWP7U39pSXLZIi/PRtXIzp/KTCtgSB9/t2x2nhHSQsm+jq0O 4VycpTrycWx1Jc3MWcTPiC2W8h+UwU7DTAMqIZwnWVPjhiNAYwlywL5zZZfR7/QoQZ7Y poORXXXhQvVfm/nfmcubT4t1gnwjet+NeiK/mJHW/L3FoNbGl3o7iK2tc5ZaQvYc2BO4 I1Btpx7P1uz4pKT898m/50I9Zj80xgl4IYoIcvv40sAKiQyyYJvCci/ul5CVv87FxzCJ 8rIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=GsUF2keC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id fa28-20020a056a002d1c00b0068e48477befsi8176633pfb.211.2023.10.12.04.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 04:12:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=GsUF2keC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 8C491822CAA1; Thu, 12 Oct 2023 04:12:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378175AbjJLLM1 (ORCPT + 19 others); Thu, 12 Oct 2023 07:12:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347154AbjJLLM0 (ORCPT ); Thu, 12 Oct 2023 07:12:26 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 980FFCA; Thu, 12 Oct 2023 04:12:24 -0700 (PDT) Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39C9rPr8020129; Thu, 12 Oct 2023 11:12:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=qcppdkim1; bh=Wad0ld8fBaOFsRuaoa9MCZdNhz5XSOOmm/PwmyCiGok=; b=GsUF2keC0fgt/Y+fQ0yJ7y5A9dOw6cVUU1UW84tRhuQkcZ7SFMFQkArnA5ngnhRwMK2E YYk84bGzmzDb91MJdclvlvZ2j/pTujZOBNO820f9mOTLNVjiqLbGzr9h2BvAZOTjmstj H1uI/XB0khU4iaCf+z83RflhWUsbHL49cT/MncvhSBitVxKMFoKfjWGALtRz4+AVE0/S NyPv7PK7GsWzmITH7y9g65FtrOrYt0nT3cT2worciOYmSOHe6oRucvwhtjakBp97BkgR 61SlXAx1nuTa6ZcRJf/2VQBTXamZB6TJFvDQwJkvdbS4p0xFNQ0iA1IWkfMC+myOJvLj uQ== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tpd480965-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 11:12:11 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39CBC92H018941 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 11:12:10 GMT Received: from jinlmao-gv.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.36; Thu, 12 Oct 2023 04:12:06 -0700 From: Mao Jinlong To: Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , Alexander Shishkin CC: Shilpa Suresh , , , , , Tingwei Zhang , Jinlong Mao , Yuanfang Zhang , Tao Zhang Subject: [PATCH] coresight: etr: Use noncontiguous api instead of noncoherent Date: Thu, 12 Oct 2023 19:11:52 +0800 Message-ID: <20231012111152.37849-1-quic_jinlmao@quicinc.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: LleLBYSHs7md_mnIwcGwIyBq-B8CyXIV X-Proofpoint-ORIG-GUID: LleLBYSHs7md_mnIwcGwIyBq-B8CyXIV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_05,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 impostorscore=0 adultscore=0 mlxlogscore=807 bulkscore=0 priorityscore=1501 spamscore=0 malwarescore=0 clxscore=1015 mlxscore=0 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120091 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 12 Oct 2023 04:12:33 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779547928231039566 X-GMAIL-MSGID: 1779547928231039566 From: Shilpa Suresh The iommu support for noncoherent is removed by commit(dma-mapping: remove the {alloc,free}_noncoherent methods 81d88ce55092edf1a1f928efb373f289c6b90efd). Use alloc_noncontiguous function for etr flat buffer allocation. Signed-off-by: Shilpa Suresh Signed-off-by: Mao Jinlong --- .../hwtracing/coresight/coresight-tmc-etr.c | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index 66dc5f97a009..80e5aa4a16c9 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -24,6 +24,7 @@ struct etr_flat_buf { dma_addr_t daddr; void *vaddr; size_t size; + struct sg_table *sgt; }; /* @@ -608,14 +609,24 @@ static int tmc_etr_alloc_flat_buf(struct tmc_drvdata *drvdata, if (!flat_buf) return -ENOMEM; - flat_buf->vaddr = dma_alloc_noncoherent(real_dev, etr_buf->size, - &flat_buf->daddr, - DMA_FROM_DEVICE, GFP_KERNEL); - if (!flat_buf->vaddr) { + flat_buf->sgt = dma_alloc_noncontiguous(real_dev, etr_buf->size, + DMA_FROM_DEVICE, GFP_KERNEL, 0); + if (!flat_buf->sgt) { kfree(flat_buf); return -ENOMEM; } + flat_buf->daddr = sg_dma_address(flat_buf->sgt->sgl); + flat_buf->vaddr = dma_vmap_noncontiguous(real_dev, etr_buf->size, + flat_buf->sgt); + if (!flat_buf->vaddr) { + dma_free_noncontiguous(real_dev, etr_buf->size, + flat_buf->sgt, + DMA_FROM_DEVICE); + flat_buf->sgt = NULL; + return -ENOMEM; + } + flat_buf->size = etr_buf->size; flat_buf->dev = &drvdata->csdev->dev; etr_buf->hwaddr = flat_buf->daddr; @@ -631,9 +642,12 @@ static void tmc_etr_free_flat_buf(struct etr_buf *etr_buf) if (flat_buf && flat_buf->daddr) { struct device *real_dev = flat_buf->dev->parent; - dma_free_noncoherent(real_dev, etr_buf->size, - flat_buf->vaddr, flat_buf->daddr, + dma_vunmap_noncontiguous(real_dev, flat_buf->vaddr); + dma_free_noncontiguous(real_dev, etr_buf->size, + flat_buf->sgt, DMA_FROM_DEVICE); + flat_buf->vaddr = NULL; + flat_buf->sgt = NULL; } kfree(flat_buf); } @@ -642,6 +656,9 @@ static void tmc_etr_sync_flat_buf(struct etr_buf *etr_buf, u64 rrp, u64 rwp) { struct etr_flat_buf *flat_buf = etr_buf->private; struct device *real_dev = flat_buf->dev->parent; + s64 buf_len; + int i; + struct scatterlist *sg; /* * Adjust the buffer to point to the beginning of the trace data @@ -658,13 +675,19 @@ static void tmc_etr_sync_flat_buf(struct etr_buf *etr_buf, u64 rrp, u64 rwp) * the only reason why we would get a wrap around is when the buffer * is full. Sync the entire buffer in one go for this case. */ + if (etr_buf->offset + etr_buf->len > etr_buf->size) - dma_sync_single_for_cpu(real_dev, flat_buf->daddr, - etr_buf->size, DMA_FROM_DEVICE); - else - dma_sync_single_for_cpu(real_dev, - flat_buf->daddr + etr_buf->offset, - etr_buf->len, DMA_FROM_DEVICE); + dma_sync_sgtable_for_cpu(real_dev, flat_buf->sgt, + DMA_FROM_DEVICE); + else { + buf_len = etr_buf->len; + for_each_sg(flat_buf->sgt->sgl, sg, flat_buf->sgt->orig_nents, i) { + dma_sync_sg_for_cpu(real_dev, sg, 1, DMA_FROM_DEVICE); + buf_len -= sg->length; + if (buf_len <= 0) + break; + } + } } static ssize_t tmc_etr_get_data_flat_buf(struct etr_buf *etr_buf,