From patchwork Tue Apr 20 08:27:45 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: 12213615 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=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 54AACC433B4 for ; Tue, 20 Apr 2021 09:31:43 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B188F61107 for ; Tue, 20 Apr 2021 09:31:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B188F61107 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4XPn9sKBYLweOEB7nxVo7oUOA4bDIMI4scQMvJT/0Fk=; b=SHtdG+AYw9dzQ/hqd4xEyGwjX cVgJekM+/kaaJuWi8yXqw41Wu5yGbeOVY8SFkDiuLdtCJcF/pD+d2ERUa6BykAR6B9AZwrhCAZteH BbbPl+iUN0VfJwohxRFcuUb6S66+QG11onVKB6XHezM2QNLh922txuwE+z9k1UF4TdXuql4aGr2JG PrfNmPk3xAHH555hA27u6ZUEws9KdPQli8utufZwlsUEjnSuX8npOCTFfUHG645RheCkCZ4F815c1 9Qg/Zt+y1jXKvqIIZ9Aj4z7j9VUUez6ya//m042DUCIrcvzOH21ZjUfJa6ECnEQeYq39OTDN/RBFP 68pdQzXSw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lYmhZ-00BkgJ-TY; Tue, 20 Apr 2021 09:29:50 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lYmgT-00BkPA-01 for linux-arm-kernel@desiato.infradead.org; Tue, 20 Apr 2021 09:28:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=vlPvcVY6ca1hieVFHgAQUeH1GJuQX19ZuCI3QmNhyVQ=; b=cCcUQ+Vc5lT0UXqaOebUvgHRKl /ufpAfqJJxE88BdbfQrC4aJn1DCuT+uEQnSMUzTMJjqV2cf+u6kjQnaWu4dNBCpGoWMFxn9vFIu4u okHvZhlMVw1tmJHcgfQMkSVdWhju/MkNZNT3CvGarECQ/P+vD2I+KM45QDlz0WaCpN33Vp8LFo2So Jg6E/PhnqDcG1cNRsK0Vtvo+1CsO6Yy4PVzRdB5StE7HnmuP9FvLfmE3XP3YMsckPLt4xw7d8SetL XwEZ5ccayfzDCdPRG2q7/2LcnxuZLIzBWUqL3Suh2HD4fymCtz9J5PfA8SmHesSvrmESO6VmRMs93 Ifu74yOg==; Received: from szxga07-in.huawei.com ([45.249.212.35]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lYmgQ-00Byp3-3w for linux-arm-kernel@lists.infradead.org; Tue, 20 Apr 2021 09:28:39 +0000 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FPdbV3Xh4z7vrv; Tue, 20 Apr 2021 17:26:14 +0800 (CST) Received: from A2006125610.china.huawei.com (10.47.83.26) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Tue, 20 Apr 2021 17:28:26 +0800 From: Shameer Kolothum To: , , CC: , , , , , , , , , Subject: [PATCH v3 04/10] iommu/dma: Add a helper function to reserve RMRs for IOMMU drivers Date: Tue, 20 Apr 2021 10:27:45 +0200 Message-ID: <20210420082751.1829-5-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210420082751.1829-1-shameerali.kolothum.thodi@huawei.com> References: <20210420082751.1829-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.83.26] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210420_022838_495703_A3B1230D X-CRM114-Status: GOOD ( 15.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org IOMMU drivers can use this to implement their .get_resv_regions callback for any RMR address regions specific to a device. As per ACPI IORT E.b spec, a check is added to make sure OS has preserved the PCIe configuration done by boot firmware. Signed-off-by: Shameer Kolothum Reported-by: kernel test robot Reported-by: kernel test robot --- drivers/iommu/dma-iommu.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/dma-iommu.h | 7 +++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index a942cc04eee1..c624000bf230 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -191,6 +191,41 @@ void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list) } EXPORT_SYMBOL(iommu_dma_get_resv_regions); +void iommu_dma_get_rmr_resv_regions(struct device *dev, struct iommu_rmr *rmr, + struct list_head *list) +{ + int prot = IOMMU_READ | IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO; + struct iommu_resv_region *region; + enum iommu_resv_type type; + + /* + * For ACPI, please make sure the OS has preserved the PCIe configuration + * performed by the boot firmware(See IORT revision E.b). + */ + if (!is_of_node(dev_iommu_fwspec_get(dev)->iommu_fwnode) && + 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; + } + + 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); +} +EXPORT_SYMBOL(iommu_dma_get_rmr_resv_regions); + /** * iommu_dma_get_rmrs - Retrieve Reserved Memory Regions(RMRs) associated * with a given IOMMU diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h index beb84c4fe5b1..dbad5073c9e0 100644 --- a/include/linux/dma-iommu.h +++ b/include/linux/dma-iommu.h @@ -40,6 +40,8 @@ void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list); void iommu_dma_free_cpu_cached_iovas(unsigned int cpu, struct iommu_domain *domain); +void iommu_dma_get_rmr_resv_regions(struct device *dev, struct iommu_rmr *rmr, + struct list_head *list); int iommu_dma_get_rmrs(struct fwnode_handle *iommu, struct list_head *list); struct iommu_rmr *iommu_dma_alloc_rmr(u64 base, u64 length, u32 sid, u32 flags); @@ -89,6 +91,11 @@ static inline void iommu_dma_free_cpu_cached_iovas(unsigned int cpu, { } +static void iommu_dma_get_rmr_resv_regions(struct device *dev, struct iommu_rmr *rmr, + struct list_head *list) +{ +} + int iommu_dma_get_rmrs(struct fwnode_handle *iommu, struct list_head *list); { return 0;