From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAAF1C10F00 for ; Tue, 12 Mar 2019 06:05:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 916AD214D8 for ; Tue, 12 Mar 2019 06:05:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727212AbfCLGF6 (ORCPT ); Tue, 12 Mar 2019 02:05:58 -0400 Received: from mga04.intel.com ([192.55.52.120]:22851 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727077AbfCLGF4 (ORCPT ); Tue, 12 Mar 2019 02:05:56 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Mar 2019 23:05:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,470,1544515200"; d="scan'208";a="141228403" Received: from allen-box.sh.intel.com ([10.239.159.136]) by orsmga002.jf.intel.com with ESMTP; 11 Mar 2019 23:05:53 -0700 From: Lu Baolu To: David Woodhouse , Joerg Roedel , ashok.raj@intel.com, jacob.jun.pan@intel.com, alan.cox@intel.com, kevin.tian@intel.com, mika.westerberg@linux.intel.com, pengfei.xu@intel.com Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu , Jacob Pan Subject: [PATCH v1 2/9] iommu/vt-d: Add helpers for domain mapping/unmapping Date: Tue, 12 Mar 2019 13:59:58 +0800 Message-Id: <20190312060005.12189-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190312060005.12189-1-baolu.lu@linux.intel.com> References: <20190312060005.12189-1-baolu.lu@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds two helpers to map or unmap a physically contiguous memory region in the page table of an iommu domain. Cc: Ashok Raj Cc: Jacob Pan Signed-off-by: Lu Baolu Tested-by: Xu Pengfei Tested-by: Mika Westerberg --- drivers/iommu/intel-iommu.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/intel-iommu.h | 5 +++++ 2 files changed, 40 insertions(+) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 7b433772bce0..791261afb4a9 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -5847,3 +5847,38 @@ static void __init check_tylersburg_isoch(void) pr_warn("Recommended TLB entries for ISOCH unit is 16; your BIOS set %d\n", vtisochctrl); } + +/* + * Map a physically contiguous memory region in the dma page table + * of an iommu domain. + */ +int +domain_iomap_range(struct dmar_domain *domain, unsigned long addr, + phys_addr_t paddr, size_t size, int prot) +{ + return domain_mapping(domain, + mm_to_dma_pfn(IOVA_PFN(addr)), + NULL, + mm_to_dma_pfn(IOVA_PFN(paddr)), + aligned_nrpages(addr, size), + prot); +} + +/* + * Unmap a physically contiguous memory region in the dma page table + * of an iommu domain. Return the free page list that should be freed + * after iotlb flush. We can't free these pages here since it possibly + * is still used by iotlb cache for a DMA translation. + */ +struct page * +domain_iounmap_range(struct dmar_domain *domain, unsigned long addr, + size_t size) +{ + unsigned long nrpages, start_pfn, last_pfn; + + nrpages = aligned_nrpages(addr, size); + start_pfn = mm_to_dma_pfn(IOVA_PFN(addr)); + last_pfn = start_pfn + nrpages - 1; + + return domain_unmap(domain, start_pfn, last_pfn); +} diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index 6925a18a5ca3..74afedfe193b 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -663,6 +663,11 @@ int for_each_device_domain(int (*fn)(struct device_domain_info *info, void iommu_flush_write_buffer(struct intel_iommu *iommu); int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct device *dev); +int domain_iomap_range(struct dmar_domain *domain, unsigned long addr, + phys_addr_t paddr, size_t size, int prot); +struct page *domain_iounmap_range(struct dmar_domain *domain, + unsigned long addr, size_t size); + #ifdef CONFIG_INTEL_IOMMU_SVM int intel_svm_init(struct intel_iommu *iommu); extern int intel_svm_enable_prq(struct intel_iommu *iommu); -- 2.17.1