Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp321568pxb; Wed, 11 Nov 2020 04:44:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+R6IqNa2s2YidjmTyPaEELVlvSMAlow3aBPhjmYVkicfgUepn/M74TzXvLeuo7vTFCh7p X-Received: by 2002:aa7:cc0e:: with SMTP id q14mr4648169edt.326.1605098647541; Wed, 11 Nov 2020 04:44:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605098647; cv=none; d=google.com; s=arc-20160816; b=q4cxDom9EKcl101cFxTDgGa4/oP4i0lWZ+Cv1dv/MuyV5PtoICkiTHDDCr/koelle9 80x85JmF4eGYNkJujJQoKBbb5Pzcz3QNr5ljNyh3ulKMecWkBPAcUhr56r7BheIpybSI vsHTz8hxFWWLWZGmnOGEr2rVzaMRXAWEZLSIn9avvFrcSOr50TKbSFI+kzk0yTKuGAKD QJttoWdG9UJuwDTYSSJ2nOv544V8JudBnHOR94y0UiVFfRZgGOao8eDz8TwZB7+kS8fK BtaKqkbTshUnyMKhTbH3TCr32RuLvZE0hzxMzFZwYZO9IU4TTkcKizZjgTGrelMlD/nz Rk9A== 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=iJgDT5nc9zpsnp5WsHFyIr5fn3+1b4gEIvgVgcXjNiA=; b=sF15eQ97KGVQO+RbjKltbM1KFCjDA5uTDfU2juGS7xX7aMnEkc6Z6Gb/l4EKlVUJ9f oi810a2ndVWTAXu5cEY4YjOPdwXb7xRF3Ch710RkB8e7TBcnDsUjo8yDlX8UdnYeUqqj bzJZWegeMg0RmqEnUBw9fFp4NsJH+NrElB5lboYBw3AvwgYW7bMn/c5+Lkz631whlxeN +lojL5afMVK1+O7KyxiW962W+GHAkoHCCZmVVS13SGaCKUPOcRnMZ2yAJ2X/Ra2aLrHu Bz3ZO+7a1vGqHNugD+B04aG6/g+2F7x/ee+sX4L3A7UCJgOiVkQVphIworfjt2Gk7QaP +CPw== 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 g13si1266033ejr.684.2020.11.11.04.43.44; Wed, 11 Nov 2020 04:44:07 -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 S1726918AbgKKMl3 (ORCPT + 99 others); Wed, 11 Nov 2020 07:41:29 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:58242 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726897AbgKKMlV (ORCPT ); Wed, 11 Nov 2020 07:41:21 -0500 X-UUID: 4946802b89d74c5cacccc267b9fa8a40-20201111 X-UUID: 4946802b89d74c5cacccc267b9fa8a40-20201111 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw02.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 1519778830; Wed, 11 Nov 2020 20:41:18 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 11 Nov 2020 20:41:16 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 11 Nov 2020 20:41:15 +0800 From: Yong Wu To: Joerg Roedel , Matthias Brugger , Rob Herring , Will Deacon , Robin Murphy CC: Krzysztof Kozlowski , Evan Green , Tomasz Figa , , , , , , , , , Nicolas Boichat , , , Greg Kroah-Hartman , Subject: [PATCH v4 16/24] iommu/mediatek: Add iova reserved function Date: Wed, 11 Nov 2020 20:38:30 +0800 Message-ID: <20201111123838.15682-17-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20201111123838.15682-1-yong.wu@mediatek.com> References: <20201111123838.15682-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. This patch adds iova reserved flow. It's a preparing patch for supporting multi-domain. Signed-off-by: Anan sun Signed-off-by: Chao Hao Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 28 ++++++++++++++++++++++++++++ drivers/iommu/mtk_iommu.h | 5 +++++ 2 files changed, 33 insertions(+) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 90aae34f4da0..bf3f4e0f4748 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -156,6 +156,11 @@ static LIST_HEAD(m4ulist); /* List all the M4U HWs */ #define for_each_m4u(data) list_for_each_entry(data, &m4ulist, list) +struct mtk_iommu_iova_region { + dma_addr_t iova_base; + unsigned long long size; +}; + /* * There may be 1 or 2 M4U HWs, But we always expect they are in the same domain * for the performance. @@ -544,6 +549,27 @@ 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); + const struct mtk_iommu_iova_region *resv; + struct iommu_resv_region *region; + int prot = IOMMU_WRITE | IOMMU_READ; + unsigned int i; + + for (i = 0; i < data->plat_data->iova_region_nr; i++) { + resv = data->plat_data->iova_region + i; + + 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, @@ -558,6 +584,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, }; diff --git a/drivers/iommu/mtk_iommu.h b/drivers/iommu/mtk_iommu.h index 5e03a029c4dc..e867cd3aeeac 100644 --- a/drivers/iommu/mtk_iommu.h +++ b/drivers/iommu/mtk_iommu.h @@ -45,10 +45,15 @@ enum mtk_iommu_plat { M4U_MT8183, }; +struct mtk_iommu_iova_region; + struct mtk_iommu_plat_data { enum mtk_iommu_plat m4u_plat; u32 flags; u32 inv_sel_reg; + + unsigned int iova_region_nr; + const struct mtk_iommu_iova_region *iova_region; unsigned char larbid_remap[MTK_LARB_COM_MAX][MTK_LARB_SUBCOM_MAX]; }; -- 2.18.0