From patchwork Thu Aug 5 08:07:24 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: 492249 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp55958jap; Thu, 5 Aug 2021 01:10:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9sRDWy9DT2QYxtUqxrNaGJVVQxYKgb4SFPBml659vp/GC6zb3ztMo+LsT3udSW6kwm0f8 X-Received: by 2002:a05:6402:42c7:: with SMTP id i7mr4854729edc.161.1628151007738; Thu, 05 Aug 2021 01:10:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628151007; cv=none; d=google.com; s=arc-20160816; b=S33/schxWb6OGEMNdc7k7rx/CEo8rlUvSqxUns3ZR12ml8PGCOp72prP3c0szm06yZ uDTttCbkROOa20N4A41FX9pIdwznHeRcMdlV8v1aV8t4z2onFfZqB7/WjKhOPVWcOzSi goP5qA4nwB5JqCreW7xSKNe8HcR2kl/ydd64JNGqYAIOty6JgsnwyAs3l532inAl5D/6 T8TB2+5XphBa2Ap+iOYQ7D2V9C2bNoIT4txvfZe1pwLeY/l8ulAuwHCAcbUM/1AWgXrs gIRJ4LvnpXhT/os4osiNJNaDI5RZoG05WhiZ5qsBvGZtKacdXF8LQYW1LJjiDKwhMfPJ j9uw== 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=a/O879fzSLfFh5eAZx7NFXunZe21Lim+UM6IJCf/EgU=; b=STYy2sJ7XPGDdiF5r6X6Jndg7efPvRwWirKErTlukTLbWc9fwXNGF5YI2mG8H4eZzd MtsGwGN8oHo9Dh2+ElR3qq2jWQ9WCBmR2JWYqaC/fLUd8AjNv0hVrOTF4TRkGY2yh3Et i6b5dQFdcZjh3dulBVu/r7lDLVO5yOBEpeyzCGJfnJv+cSQozkLhzaNCknGATBV39Vot BsOGegYS/7EHmZzls603KHqOPeBmoIpjSXQCwN7oGkb/yG8bzn5Vpmm9gs2xsfPoOFtp pZOfWuVnji81O0OF9z2WWUKlNuEWHzT2rWTzIdnBYOHRu4/+KFRjhpKhtvj5tsTkLTX2 Glxg== 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 zo11si4796360ejb.23.2021.08.05.01.10.07; Thu, 05 Aug 2021 01:10:07 -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 S235821AbhHEIKO (ORCPT + 4 others); Thu, 5 Aug 2021 04:10:14 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3593 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239048AbhHEIKO (ORCPT ); Thu, 5 Aug 2021 04:10:14 -0400 Received: from fraeml714-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GgLqp4z5jz6G9VM; Thu, 5 Aug 2021 16:09:42 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml714-chm.china.huawei.com (10.206.15.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 5 Aug 2021 10:09:58 +0200 Received: from A2006125610.china.huawei.com (10.47.91.4) by lhreml710-chm.china.huawei.com (10.201.108.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 5 Aug 2021 09:09:51 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , , Subject: [PATCH v7 9/9] iommu/dma: Reserve any RMR regions associated with a dev Date: Thu, 5 Aug 2021 09:07:24 +0100 Message-ID: <20210805080724.480-10-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> References: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.91.4] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To lhreml710-chm.china.huawei.com (10.201.108.61) 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 | 56 +++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 1b6e27475279..c1ae0c3d4b33 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -207,22 +207,68 @@ void iommu_dma_put_rmrs(struct fwnode_handle *iommu_fwnode, } EXPORT_SYMBOL(iommu_dma_put_rmrs); +static bool iommu_dma_dev_has_rmr(struct iommu_fwspec *fwspec, + struct iommu_resv_region *e) +{ + int i; + + for (i = 0; i < fwspec->num_ids; i++) { + if (e->fw_data.rmr.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_resv_region *rmr, *tmp; + + 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_safe(rmr, tmp, &rmr_list, list) { + if (!iommu_dma_dev_has_rmr(fwspec, rmr)) + continue; + + /* Remove from iommu RMR list and add to dev resv_regions */ + list_del_init(&rmr->list); + list_add_tail(&rmr->list, list); + } + + iommu_dma_put_rmrs(fwspec->iommu_fwnode, &rmr_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);