From patchwork Thu May 13 13:45:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 437334 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp345906jao; Thu, 13 May 2021 06:47:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLt5xj5u92E5u0Ja6oh+t0F9sXVWtO8UAslyt3dWn4jYQoZYHfIKXc5eXY+gqU4lB+MkzC X-Received: by 2002:a92:d486:: with SMTP id p6mr29793131ilg.235.1620913640063; Thu, 13 May 2021 06:47:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620913640; cv=none; d=google.com; s=arc-20160816; b=a0Bt6Jp3bBT4gQcAR3OhEK/Qhl1OTEAupogcKkm/hzi5oVRxrazR70xeyKvCUr+B39 C2wcqP1O2RcEWticMbDruqDKlz0/VWgsCDjkPnXKUBuYV69Ukmc8eVIurgo2ByGorpoF G0QUT9zPvVXZd/PEpXTYQ7UyMDBv7G8Fcbo8oRwa0l9YyPHYykELzohRUO2DT90IW6uB qCQOnU/tr3f2Ew4Py4YaNeR5BBgiDSm5kC23ZIJ76cBuK9/3zkfE13sErrryPTuFBpSM Q2iObiBP7IczyuYxtX4oBE4BdhFddEGYK2mzu9mEe2Ad1j0SlHwjHwcBFctIKum9BwHL Kq4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=npxOUUA+qAqRTzOee+vFMD+o6lO24I1Xwq3hH7pZ1EU=; b=w8ppy3J6+43lXb+dV3sfLTawO+WR7l2oGcvTH7PfHb1EWqAxUg8KxkefzzQgapvUSa Xe2uEBqQL05s4iN5Xf5mWeOcswQ08RmkY40wk3DAxuYMFww+O9FZHcQJSQoTGL+QSgSg 85N7K8K9qMpEyTtCqIR4Ht0qRen8BfnQ1YH0Qzjy9CFGDdU9kXBYw4XlPZ2DTr8u2f4W 1th0ioRfgflyOJURXxHodMDr42rVEyOwayMrzECopKWlYJtgB2w91o/sjw6cHNjwF6RC khaL5BS2+jmLhmXigjl0gh3q16NMyCU/WLqvV2E3BVPH9dxnzf89c+SfwuDJGuWyQfnt 6ReQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-acpi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u10si3346494ilv.5.2021.05.13.06.47.19; Thu, 13 May 2021 06:47:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-acpi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-acpi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234047AbhEMNs2 (ORCPT + 4 others); Thu, 13 May 2021 09:48:28 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:3749 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234160AbhEMNsZ (ORCPT ); Thu, 13 May 2021 09:48:25 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FgtD70GSdzqSrx; Thu, 13 May 2021 21:43:51 +0800 (CST) Received: from A2006125610.china.huawei.com (10.47.81.63) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Thu, 13 May 2021 21:47:06 +0800 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v4 8/8] iommu/dma: Reserve any RMR regions associated with a dev Date: Thu, 13 May 2021 14:45:50 +0100 Message-ID: <20210513134550.2117-9-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210513134550.2117-1-shameerali.kolothum.thodi@huawei.com> References: <20210513134550.2117-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.81.63] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Get ACPI IORT RMR regions associated with a dev reserved so that there is a unity mapping for them in SMMU. Signed-off-by: Shameer Kolothum --- drivers/iommu/dma-iommu.c | 66 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 2d9caf548a32..6838caf3e8ff 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -174,22 +174,78 @@ void iommu_put_dma_cookie(struct iommu_domain *domain) } EXPORT_SYMBOL(iommu_put_dma_cookie); +static bool iommu_dma_dev_has_rmr(struct iommu_fwspec *fwspec, + struct iommu_rmr *e) +{ + int i; + + for (i = 0; i < fwspec->num_ids; i++) { + if (e->sid == fwspec->ids[i]) + return true; + } + + return false; +} + +static void iommu_dma_get_rmr_resv_regions(struct device *dev, + struct list_head *list) +{ + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + struct list_head rmr_list; + struct iommu_rmr *rmr; + + INIT_LIST_HEAD(&rmr_list); + if (iommu_dma_get_rmrs(fwspec->iommu_fwnode, &rmr_list)) + return; + + if (dev_is_pci(dev)) { + struct pci_dev *pdev = to_pci_dev(dev); + struct pci_host_bridge *host = pci_find_host_bridge(pdev->bus); + + if (!host->preserve_config) + return; + } + + list_for_each_entry(rmr, &rmr_list, list) { + int prot = IOMMU_READ | IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO; + struct iommu_resv_region *region; + enum iommu_resv_type type; + + if (!iommu_dma_dev_has_rmr(fwspec, rmr)) + continue; + + if (rmr->flags & IOMMU_RMR_REMAP_PERMITTED) + type = IOMMU_RESV_DIRECT_RELAXABLE; + else + type = IOMMU_RESV_DIRECT; + + region = iommu_alloc_resv_region(rmr->base_address, + rmr->length, prot, + type); + if (!region) + return; + + list_add_tail(®ion->list, list); + } +} /** * iommu_dma_get_resv_regions - Reserved region driver helper * @dev: Device from iommu_get_resv_regions() * @list: Reserved region list from iommu_get_resv_regions() * * IOMMU drivers can use this to implement their .get_resv_regions callback - * for general non-IOMMU-specific reservations. Currently, this covers GICv3 - * ITS region reservation on ACPI based ARM platforms that may require HW MSI - * reservation. + * for general non-IOMMU-specific reservations. Currently this covers, + * -GICv3 ITS region reservation on ACPI based ARM platforms that may + * require HW MSI reservation. + * -Any ACPI IORT RMR memory range reservations (IORT spec rev E.b) */ void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list) { - if (!is_of_node(dev_iommu_fwspec_get(dev)->iommu_fwnode)) + if (!is_of_node(dev_iommu_fwspec_get(dev)->iommu_fwnode)) { iort_iommu_msi_get_resv_regions(dev, list); - + iommu_dma_get_rmr_resv_regions(dev, list); + } } EXPORT_SYMBOL(iommu_dma_get_resv_regions);