Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp743968pxb; Fri, 8 Jan 2021 17:54:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJxaaa2CtAOrLMBwGi+X9866Lse4oo3PNtdqUWGvXQBO3W/2XuU3+urcHe5DkLwnrChOE7Lo X-Received: by 2002:aa7:cf04:: with SMTP id a4mr7151508edy.99.1610157276816; Fri, 08 Jan 2021 17:54:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610157276; cv=none; d=google.com; s=arc-20160816; b=Le9JZn8RM7FogesyWoZD1CRUmZeW7ONkl5JxnxQOeuTTb2fUNCNN5h2K16ldHWp6eN oHS2WQlOYpERZDkcTsIwcPjpBf+a6vIP/hNZPNsSJo/B7kZ8EpukjouZSlsQNRtPSTYV 7Rb5YGMomQ1yw5X5eYQV5zEu0rpt2emEZRuAFmt4Yz8VVhGtkDY/p8U+caXphKVSccks ykMEIB2441J9DV9Ztzyl3LD/Xo/lx1/uCkhJR4euMHggEDxSORAcxQytqBB+aG4RucA3 X+gIdcFuAY3LdjUFXPFwhl1r4ZeIZ77pOrOvrC334XF7cc5GT4sS4BhgLUoPLqMYRtgv mfew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dmarc-filter:sender:dkim-signature; bh=nyKJ1KS+aQ96lRUCRz7VQNC6CbJC+csGV/JXbEdEAbw=; b=gDmXpx0E/goXfFbtpVomrcKYszgjp2xaJN2wn4KeUPpgdVchUiF9H/yB6U0MKqxzSm UkxCqlTKKiugoIlH44SLLfVqBRXs9mU+MRkudZt1SFY0+Gud6le0AQczd/sfwwFeDtCt r8iXkECHIgAT3sFoFCsuC5o+/2mJv94m7C74woWKia/eMhcMYPeRmd2wEezqoJmCFE5e lfZ/+WX7BiAUghANhFAuFDPIlcBJGXBIxBesPpU+Dakt4FLGjPSmYE0WlG2nhLWBNDVE fTNqXIn1Z2AmdCVtaqU3WbO2RC7RLeGYX43JwdRLinZUZc8DCndr53nzz0Ecp5/kY9Op 0WKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=VfQ1gFwB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ov28si4258094ejb.512.2021.01.08.17.54.13; Fri, 08 Jan 2021 17:54:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=VfQ1gFwB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726708AbhAIBvm (ORCPT + 99 others); Fri, 8 Jan 2021 20:51:42 -0500 Received: from m43-15.mailgun.net ([69.72.43.15]:62186 "EHLO m43-15.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726523AbhAIBvm (ORCPT ); Fri, 8 Jan 2021 20:51:42 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1610157081; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=nyKJ1KS+aQ96lRUCRz7VQNC6CbJC+csGV/JXbEdEAbw=; b=VfQ1gFwB38zqtYC0UW4mmN7qmyTa/8lR4xXoce9r4o1mihx62SPfakN2RIrcZtJG4kwDoGel ebGzDCoDJ2QjayrETUbZY3ZkHjtxMm7F10yBk1Q6VuRUcYS9TEmj/x5ttfNHBM9g/7ysYgMR i+G8MzrSsfLbGXFmRgv271FQDiM= X-Mailgun-Sending-Ip: 69.72.43.15 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n08.prod.us-east-1.postgun.com with SMTP id 5ff90bf746a6c7cde79e90f4 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Sat, 09 Jan 2021 01:50:47 GMT Sender: isaacm=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 48A4DC43462; Sat, 9 Jan 2021 01:50:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00,SPF_FAIL autolearn=no autolearn_force=no version=3.4.0 Received: from isaacm-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: isaacm) by smtp.codeaurora.org (Postfix) with ESMTPSA id F33D3C43466; Sat, 9 Jan 2021 01:50:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org F33D3C43466 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=isaacm@codeaurora.org From: "Isaac J. Manjarres" To: will@kernel.org, robin.murphy@arm.com, joro@8bytes.org Cc: "Isaac J. Manjarres" , pdaly@codeaurora.org, pratikp@codeaurora.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] iommu/io-pgtable-arm-v7s: Hook up map_sg() Date: Fri, 8 Jan 2021 17:50:29 -0800 Message-Id: <1610157031-26301-4-git-send-email-isaacm@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1610157031-26301-1-git-send-email-isaacm@codeaurora.org> References: <1610157031-26301-1-git-send-email-isaacm@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement the map_sg io-pgtable op for the ARMv7s io-pgtable code, so that IOMMU drivers can call it when they need to map a scatter-gather list. Signed-off-by: Isaac J. Manjarres --- drivers/iommu/io-pgtable-arm-v7s.c | 90 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c index 1d92ac9..40d96d2 100644 --- a/drivers/iommu/io-pgtable-arm-v7s.c +++ b/drivers/iommu/io-pgtable-arm-v7s.c @@ -545,6 +545,95 @@ static int arm_v7s_map(struct io_pgtable_ops *ops, unsigned long iova, return ret; } +static int arm_v7s_map_by_pgsize(struct io_pgtable_ops *ops, + unsigned long iova, phys_addr_t paddr, + size_t size, int prot, gfp_t gfp, + size_t *mapped) +{ + struct arm_v7s_io_pgtable *data = io_pgtable_ops_to_data(ops); + struct io_pgtable *iop = &data->iop; + struct io_pgtable_cfg *cfg = &iop->cfg; + unsigned int min_pagesz = 1 << __ffs(cfg->pgsize_bitmap); + int ret; + size_t pgsize; + + if (!IS_ALIGNED(iova | paddr | size, min_pagesz)) { + pr_err("unaligned: iova 0x%lx pa %pa size 0x%zx min_pagesz 0x%x\n", + iova, &paddr, size, min_pagesz); + return -EINVAL; + } + + if (WARN_ON((iova + size) >= (1ULL << cfg->ias) || + (paddr + size) >= (1ULL << cfg->oas))) + return -ERANGE; + + while (size) { + pgsize = iommu_pgsize(cfg->pgsize_bitmap, iova | paddr, size); + ret = __arm_v7s_map(data, iova, paddr, pgsize, prot, 1, + data->pgd, gfp); + + if (iop->cfg.quirks & IO_PGTABLE_QUIRK_TLBI_ON_MAP) { + io_pgtable_tlb_flush_walk(&data->iop, iova, size, + ARM_V7S_BLOCK_SIZE(2)); + } else { + wmb(); + } + + if (ret) + return ret; + + iova += pgsize; + paddr += pgsize; + *mapped += pgsize; + size -= pgsize; + } + + return 0; +} + +static int arm_v7s_map_sg(struct io_pgtable_ops *ops, unsigned long iova, + struct scatterlist *sg, unsigned int nents, + int iommu_prot, gfp_t gfp, size_t *mapped) +{ + size_t len = 0; + unsigned int i = 0; + int ret; + phys_addr_t start; + + *mapped = 0; + + /* If no access, then nothing to do */ + if (!(iommu_prot & (IOMMU_READ | IOMMU_WRITE))) + return 0; + + while (i <= nents) { + phys_addr_t s_phys = sg_phys(sg); + + if (len && s_phys != start + len) { + ret = arm_v7s_map_by_pgsize(ops, iova + *mapped, start, + len, iommu_prot, gfp, + mapped); + + if (ret) + return ret; + + len = 0; + } + + if (len) { + len += sg->length; + } else { + len = sg->length; + start = s_phys; + } + + if (++i < nents) + sg = sg_next(sg); + } + + return 0; +} + static void arm_v7s_free_pgtable(struct io_pgtable *iop) { struct arm_v7s_io_pgtable *data = io_pgtable_to_data(iop); @@ -783,6 +872,7 @@ static struct io_pgtable *arm_v7s_alloc_pgtable(struct io_pgtable_cfg *cfg, data->iop.ops = (struct io_pgtable_ops) { .map = arm_v7s_map, + .map_sg = arm_v7s_map_sg, .unmap = arm_v7s_unmap, .iova_to_phys = arm_v7s_iova_to_phys, }; -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project