Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp743803pxb; Fri, 8 Jan 2021 17:54:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJyeh67KH3o9+usZRiUCYrcjmrvs8alcN3PUZEcJmuiu14Mn4RZEnnRs8pIHad224lkXzw/l X-Received: by 2002:a05:6402:1d13:: with SMTP id dg19mr7010735edb.111.1610157248026; Fri, 08 Jan 2021 17:54:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610157248; cv=none; d=google.com; s=arc-20160816; b=wmllxHM9P9OxpaaBh3MQ8NmUf2VxrsH3KcIt/zRuwxdq4X6HiAPdtey2XLdNLzNQO4 DZQ66khu6zquid56mvapAlMTP50QsLNfRkqfAMGb/2JKAnUryuAqgzjgd9hWcFhnmaXC HMdTh+nYn6hcwQT5LwJBhKqixxg2L9R8AF0WCHkwA0xfdJOZpHETYC49ZCpI6A4k9G+o HPu9H85QdHZ2UMilPgKeH/eFAkbC+ioVPgdjlYp01T8DayiwDTE97ONysm0XxkE0tQHH Q6b+Dc9iNuSxHOTDaakUiycNDWgmAcd7bIkw3PjdhU3rQXY3qdyLYNIlL0lKRJiPmK78 CZOw== 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=gv8jzLEq9rTxt8w2LdSAHkd80xt6MQloCL4w1vf44KI=; b=ftyMuj6YImreTX03C2nnHfgvQhiF2iDty/Qr9zACouLVKEnsVG6jy3WsaH1vah1Ea3 ++TqDIxs2XiB8ifrInYNQZGz9+juxD2GQ0uRC1/+hci1BwHOa41Du1BZaQ12pgvcJqk+ uDty0vu50KWOrVrClI/PuYtma/SkpOwBleSX3Sbxo1QqU/9ohnn1XlWe+Fy1G39irq6F 9WFj3tBCjQaR+DeYgmKLxenCEUuNtFP5xE+pWKN1OOMgl2AbZgaS6zKC03iGbRv+A21u kOcBkQSSb95gGyM42NEfmbvX6dv4gHaFjEXg2HGxrazvhHViXMsyhTzwNt6pBbi1tE3r KBsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=gY+r96Ny; 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 hr15si3038957ejc.287.2021.01.08.17.53.44; Fri, 08 Jan 2021 17:54:08 -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=gY+r96Ny; 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 S1726754AbhAIBvr (ORCPT + 99 others); Fri, 8 Jan 2021 20:51:47 -0500 Received: from m43-15.mailgun.net ([69.72.43.15]:42207 "EHLO m43-15.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726523AbhAIBvn (ORCPT ); Fri, 8 Jan 2021 20:51:43 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1610157085; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=gv8jzLEq9rTxt8w2LdSAHkd80xt6MQloCL4w1vf44KI=; b=gY+r96NySWtS8A8J374H4xY80YCOjXNPT8vQ3pESJccvAh8EkbQ8DxzKNlKbWI/JhY5+WU9c bWfJM78+goLEhTMobVt6iCHxhAYFYcS8fBsRhD/SdPZnYEoByieChy3EDII2JcleQN/rzhjr C3ezaaeQtQ6ejyHR8H52TdqV6HQ= 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-n01.prod.us-west-2.postgun.com with SMTP id 5ff90bf8415a6293c5c63d46 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Sat, 09 Jan 2021 01:50:48 GMT Sender: isaacm=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 5E46FC433ED; Sat, 9 Jan 2021 01:50:48 +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, URIBL_BLOCKED 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 206B1C433C6; Sat, 9 Jan 2021 01:50:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 206B1C433C6 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 4/5] iommu: Introduce map_sg() as an IOMMU op for IOMMU drivers Date: Fri, 8 Jan 2021 17:50:30 -0800 Message-Id: <1610157031-26301-5-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 Add support for IOMMU drivers to have their own map_sg() callbacks. This completes the path for having iommu_map_sg() invoke an IOMMU driver's map_sg() callback, which can then invoke the io-pgtable map_sg() callback with the entire scatter-gather list, so that it can be processed entirely in the io-pgtable layer. For IOMMU drivers that do not provide a callback, the default implementation of iterating through the scatter-gather list, while calling iommu_map() will be used. Signed-off-by: Isaac J. Manjarres --- drivers/iommu/iommu.c | 13 +++++++++++++ include/linux/iommu.h | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 0da0687..46acd5c 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2535,11 +2535,24 @@ static size_t __iommu_map_sg(struct iommu_domain *domain, unsigned long iova, struct scatterlist *sg, unsigned int nents, int prot, gfp_t gfp) { + const struct iommu_ops *ops = domain->ops; size_t len = 0, mapped = 0; phys_addr_t start; unsigned int i = 0; int ret; + if (ops->map_sg) { + ret = ops->map_sg(domain, iova, sg, nents, prot, gfp, &mapped); + + if (ops->iotlb_sync_map) + ops->iotlb_sync_map(domain); + + if (ret) + goto out_err; + + return mapped; + } + while (i <= nents) { phys_addr_t s_phys = sg_phys(sg); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 0e40a38..bac7681 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -192,6 +192,8 @@ struct iommu_iotlb_gather { * @attach_dev: attach device to an iommu domain * @detach_dev: detach device from an iommu domain * @map: map a physically contiguous memory region to an iommu domain + * @map_sg: map a scatter-gather list of physically contiguous chunks to + * an iommu domain. * @unmap: unmap a physically contiguous memory region from an iommu domain * @flush_iotlb_all: Synchronously flush all hardware TLBs for this domain * @iotlb_sync_map: Sync mappings created recently using @map to the hardware @@ -243,6 +245,9 @@ struct iommu_ops { void (*detach_dev)(struct iommu_domain *domain, struct device *dev); int (*map)(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t size, int prot, gfp_t gfp); + int (*map_sg)(struct iommu_domain *domain, unsigned long iova, + struct scatterlist *sg, unsigned int nents, int prot, + gfp_t gfp, size_t *mapped); size_t (*unmap)(struct iommu_domain *domain, unsigned long iova, size_t size, struct iommu_iotlb_gather *iotlb_gather); void (*flush_iotlb_all)(struct iommu_domain *domain); -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project