Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp848729pxb; Fri, 22 Apr 2022 12:31:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHNdWi1ZFcC6v8gNgXljI/dusanBChYHmslHqAWRlExLWIHgK2/DiQjLFScYQo7fNYWEly X-Received: by 2002:a17:902:cf05:b0:156:2aa:6e13 with SMTP id i5-20020a170902cf0500b0015602aa6e13mr6124287plg.137.1650655882865; Fri, 22 Apr 2022 12:31:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650655882; cv=none; d=google.com; s=arc-20160816; b=IKD++42Y4UZMvP/e32h/cb5hIFRED4d5/d/u2OiIYq7beqGHEDf8zqcouzdj86cPjq j7g72T4XJq36RAXQsXCtPJhg/dVNct60jhOnIZg6WgdeZTIUj4W3nhqb7t++19ytmP59 2HBVYSVgjrGAITd0EsSJ8M+5rHO8NK/crHhpwsO3QxqKFc6+/4CaUqjzomx3B8cSha7g IB4Y8pDVxJq6Ea4WrlQc2RuKsS5S/7V8HvSZOCRZTJ0soEu9Go1YBBH6FsBVHAxZnX6E R5u8iMmqwZh5JLPf9Z797ImQt0FJncmhkAIt1GhfeTKhRWJW31aaYAN3wLKs0ZnVgH39 kmKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Rv9KzmiEthqqplTndeP3ejQCoQTjzUDpZ38M3fSI2no=; b=nfDgDPjv1jJNAkkwqy+Lhw5NO+fX/4wE/Bm1ypbV5H7A9kw5bpLzSu6Ur+dlXZiswz 4ITOQ8VR9Ummv3Zg8pCG9407WznN27WhD4ztjTmgYl2J25EFGyEsJzzqRRqqyiXYzn0F 4l3FM2Px7D4IMXGLfrqxavKCzQH40nH0UTTVQET3ddo0nqzPl158Zr4SQO6RFHvSjmv7 t1X8xfe8BFownRG8BlFOlhZhC6kLhafNtViKZbcEjX82cTPlpGvqVXHJl6uLq4x5B7Td qqeuffoKhDo+TW6QadVyLDSSFJvOU/PbYM7MOUx5LZz1W9ry0XeXKHjHZloPo67J/5Fe 1xKg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id pl17-20020a17090b269100b001d7eae3307bsi2888213pjb.40.2022.04.22.12.31.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 12:31:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 36CF91E0330; Fri, 22 Apr 2022 11:41:02 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388866AbiDULkD (ORCPT + 99 others); Thu, 21 Apr 2022 07:40:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1388855AbiDULj5 (ORCPT ); Thu, 21 Apr 2022 07:39:57 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BB0622229E for ; Thu, 21 Apr 2022 04:37:07 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 88B6E1516; Thu, 21 Apr 2022 04:37:07 -0700 (PDT) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 89C773F5A1; Thu, 21 Apr 2022 04:37:06 -0700 (PDT) From: Robin Murphy To: hch@lst.de, linux@armlinux.org.uk Cc: linux-arm-kernel@lists.infradead.org, m.szyprowski@samsung.com, arnd@kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] ARM/dma-mapping: Merge IOMMU ops Date: Thu, 21 Apr 2022 12:36:59 +0100 Message-Id: <394482083c51c7596587a87edf012010f846feb0.1650539846.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.35.3.dirty In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no 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 The dma_sync_* operations are now the only difference between the coherent and non-coherent IOMMU ops. Some minor tweaks to make those safe for coherent devices with minimal overhead, and we can condense down to a single set of DMA ops. Signed-off-by: Robin Murphy --- arch/arm/mm/dma-mapping.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 10e5e5800d78..dd46cce61579 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1341,6 +1341,9 @@ static void arm_iommu_sync_sg_for_cpu(struct device *dev, struct scatterlist *s; int i; + if (dev->dma_coherent) + return; + for_each_sg(sg, s, nents, i) __dma_page_dev_to_cpu(sg_page(s), s->offset, s->length, dir); @@ -1360,6 +1363,9 @@ static void arm_iommu_sync_sg_for_device(struct device *dev, struct scatterlist *s; int i; + if (dev->dma_coherent) + return; + for_each_sg(sg, s, nents, i) __dma_page_cpu_to_dev(sg_page(s), s->offset, s->length, dir); } @@ -1493,12 +1499,13 @@ static void arm_iommu_sync_single_for_cpu(struct device *dev, { struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); dma_addr_t iova = handle & PAGE_MASK; - struct page *page = phys_to_page(iommu_iova_to_phys(mapping->domain, iova)); + struct page *page; unsigned int offset = handle & ~PAGE_MASK; - if (!iova) + if (dev->dma_coherent || !iova) return; + page = phys_to_page(iommu_iova_to_phys(mapping->domain, iova)); __dma_page_dev_to_cpu(page, offset, size, dir); } @@ -1507,12 +1514,13 @@ static void arm_iommu_sync_single_for_device(struct device *dev, { struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); dma_addr_t iova = handle & PAGE_MASK; - struct page *page = phys_to_page(iommu_iova_to_phys(mapping->domain, iova)); + struct page *page; unsigned int offset = handle & ~PAGE_MASK; - if (!iova) + if (dev->dma_coherent || !iova) return; + page = phys_to_page(iommu_iova_to_phys(mapping->domain, iova)); __dma_page_cpu_to_dev(page, offset, size, dir); } @@ -1536,22 +1544,6 @@ static const struct dma_map_ops iommu_ops = { .unmap_resource = arm_iommu_unmap_resource, }; -static const struct dma_map_ops iommu_coherent_ops = { - .alloc = arm_iommu_alloc_attrs, - .free = arm_iommu_free_attrs, - .mmap = arm_iommu_mmap_attrs, - .get_sgtable = arm_iommu_get_sgtable, - - .map_page = arm_iommu_map_page, - .unmap_page = arm_iommu_unmap_page, - - .map_sg = arm_iommu_map_sg, - .unmap_sg = arm_iommu_unmap_sg, - - .map_resource = arm_iommu_map_resource, - .unmap_resource = arm_iommu_unmap_resource, -}; - /** * arm_iommu_create_mapping * @bus: pointer to the bus holding the client device (for IOMMU calls) @@ -1750,10 +1742,7 @@ static void arm_setup_iommu_dma_ops(struct device *dev, u64 dma_base, u64 size, return; } - if (coherent) - set_dma_ops(dev, &iommu_coherent_ops); - else - set_dma_ops(dev, &iommu_ops); + set_dma_ops(dev, &iommu_ops); } static void arm_teardown_iommu_dma_ops(struct device *dev) -- 2.35.3.dirty