Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2189950pxb; Mon, 11 Jan 2021 03:27:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJwTfgIRPx1+l5eUpMW4vLPNCFr2TQte4OSF/TL57LJ5fiOGyIXJHqJyCS29HyX/QBSZC8vc X-Received: by 2002:aa7:dc0d:: with SMTP id b13mr13865883edu.170.1610364478329; Mon, 11 Jan 2021 03:27:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610364478; cv=none; d=google.com; s=arc-20160816; b=EEdDHejfPhYXYo+kCj7Sz7RdnmHHQ6uHprmLvd9KzwYyEPj368jZkUYb8WGr/NTYp2 wx40wm2Eq+kJlfg7knmbp8Zz07/fUI+WDZKmJDnGn4xDjF71flCgiLxTfenYaiLvUwi3 B5EypJd64Vvk5TsxMtTt4V86QxNdRxfIZ6gwBwfYi8qaWQW/FfbjmQzbHQA+VaUPHsi+ rLCSTfVHxnnAmBJWem92d9bY4/9WQwh35z+kafIuhGU4qwOYSGMPhsZlZWVkEhn0yBc+ fTe4M6l0EdBRnmPUVxuFvAeeFOCCVtmmhBRq3MQ0TMHx86vkseGBG6/WvjY1PLm7IWw1 pgtg== 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=CgNX2qaEX3G1gO8Y28KW2ADhS5MEvCP/RMYm8j5TbYs=; b=Mg2Qyg/F3g0jqezWLYQPUnjFACAvlOZA+wk25iujIqW1kbx2hi0wsbfgIYO8R579Q7 iUIv9KsszCljb4sfYGs5nkhVBxXRPDjISgMkqvo80/Wxt5D8wOEbuuvDaL2fKMwsycqm 4p8fOUu3C/cCZBQmwukaFNqzRWk//e1lIBjW7NkxHZkPehgdOIJKG55uRbjSDvW/M8Xl n/zDPGxs92HlMjoxHHztG4xla3d1UcQjQ0YvTs/6SHn0qeFBanipaOcpaCrIkTq0/Im7 kM8US05MdDlzB4GkT4p8pBhiDtvcQ1Ur16q4BRAOHraKBGES8beMmFlQIN/iuXqVALwx LC5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 15si6689745ejg.14.2021.01.11.03.27.34; Mon, 11 Jan 2021 03:27:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729666AbhAKLYk (ORCPT + 99 others); Mon, 11 Jan 2021 06:24:40 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:33662 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729637AbhAKLYi (ORCPT ); Mon, 11 Jan 2021 06:24:38 -0500 X-UUID: b6e1ef51e15a4244b8bda8116f3737a1-20210111 X-UUID: b6e1ef51e15a4244b8bda8116f3737a1-20210111 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.14 Build 0819 with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 400351509; Mon, 11 Jan 2021 19:23:53 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 11 Jan 2021 19:23:52 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 11 Jan 2021 19:23:51 +0800 From: Yong Wu To: Joerg Roedel , Rob Herring , Matthias Brugger , Will Deacon , Robin Murphy CC: Krzysztof Kozlowski , Evan Green , Tomasz Figa , , , , , , , , , Nicolas Boichat , , Subject: [PATCH v6 29/33] iommu/mediatek: Add iova reserved function Date: Mon, 11 Jan 2021 19:19:10 +0800 Message-ID: <20210111111914.22211-30-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210111111914.22211-1-yong.wu@mediatek.com> References: <20210111111914.22211-1-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For multiple iommu_domains, we need to reserve some iova regions. Take a example, If the default iova region is 0 ~ 4G, but the 0x4000_0000 ~ 0x43ff_ffff is only for the special CCU0 domain. Thus we should exclude this region for the default iova region. Signed-off-by: Anan sun Signed-off-by: Chao Hao Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index b42fd2535b77..764dc0b93477 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -626,6 +626,35 @@ static int mtk_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) return iommu_fwspec_add_ids(dev, args->args, 1); } +static void mtk_iommu_get_resv_regions(struct device *dev, + struct list_head *head) +{ + struct mtk_iommu_data *data = dev_iommu_priv_get(dev); + unsigned int domid = mtk_iommu_get_domain_id(dev, data->plat_data), i; + const struct mtk_iommu_iova_region *resv, *curdom; + struct iommu_resv_region *region; + int prot = IOMMU_WRITE | IOMMU_READ; + + if (domid < 0) + return; + curdom = data->plat_data->iova_region + domid; + for (i = 0; i < data->plat_data->iova_region_nr; i++) { + resv = data->plat_data->iova_region + i; + + /* Only reserve when the region is inside the current domain */ + if (resv->iova_base <= curdom->iova_base || + resv->iova_base + resv->size >= curdom->iova_base + curdom->size) + continue; + + region = iommu_alloc_resv_region(resv->iova_base, resv->size, + prot, IOMMU_RESV_RESERVED); + if (!region) + return; + + list_add_tail(®ion->list, head); + } +} + static const struct iommu_ops mtk_iommu_ops = { .domain_alloc = mtk_iommu_domain_alloc, .domain_free = mtk_iommu_domain_free, @@ -641,6 +670,8 @@ static const struct iommu_ops mtk_iommu_ops = { .release_device = mtk_iommu_release_device, .device_group = mtk_iommu_device_group, .of_xlate = mtk_iommu_of_xlate, + .get_resv_regions = mtk_iommu_get_resv_regions, + .put_resv_regions = generic_iommu_put_resv_regions, .pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M, }; -- 2.18.0