From patchwork Mon Nov 4 11:52:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chao hao X-Patchwork-Id: 11225643 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7BEF51599 for ; Mon, 4 Nov 2019 12:04:36 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 2C54C217F4 for ; Mon, 4 Nov 2019 12:04:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Blnx3dlC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2C54C217F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mNhdqN4YJfFLMzgJChVemUjup375/ki6L1/lFpt6/f4=; b=Blnx3dlC9g5qc7 30GqiMj3pyIymKcwfrv1Qdq6yBje6wdEBdkL7F2uAUfj+sQoWz+OO8gwCw4MDhCjOOIduVPDpGmAw rCfpG7ZAQCyN4qq8pkWJ6lszH7DzSLHx4g5E69EzYsDUvn4i5F4REReUf6cBu6+F2McreiF9z2ShO dmEd0/vJE842IedRRaXBpH86TRyj11Rgu5Ck2hQAvjhE5lNgYp2h202rpFEh9x5Qx4cQdf5W2YI9A /4qafMWoH82XmPUcEiYvqh7WWgkNQXMkb24Af7GgC265+BFvtfR05TQCHPw3sfGxP5Vi6neQZNmRK gBjDeFSd9upUTpVYalfw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iRb60-0007vN-Q6; Mon, 04 Nov 2019 12:04:32 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iRb4Z-0006Li-4r; Mon, 04 Nov 2019 12:03:05 +0000 X-UUID: 129d968aeb5c4634bd407d64775a6af5-20191104 X-UUID: 129d968aeb5c4634bd407d64775a6af5-20191104 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1952705030; Mon, 04 Nov 2019 04:03:07 -0800 Received: from MTKMBS06N1.mediatek.inc (172.21.101.129) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 4 Nov 2019 03:53:11 -0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs06n1.mediatek.inc (172.21.101.129) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 4 Nov 2019 19:53:12 +0800 Received: from localhost.localdomain (10.15.20.246) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 4 Nov 2019 19:53:08 +0800 From: Chao Hao To: Joerg Roedel , Rob Herring , "Matthias Brugger" Subject: [RESEND,PATCH 11/13] iommu/mediatek: Add iova reserved function Date: Mon, 4 Nov 2019 19:52:36 +0800 Message-ID: <20191104115238.2394-12-chao.hao@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20191104115238.2394-1-chao.hao@mediatek.com> References: <20191104115238.2394-1-chao.hao@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191104_040303_240507_54FFC122 X-CRM114-Status: GOOD ( 12.01 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [216.200.240.184 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anan Sun , devicetree@vger.kernel.org, Cui Zhang , Jun Yan , wsd_upstream@mediatek.com, linux-kernel@vger.kernel.org, Chao Hao , iommu@lists.linux-foundation.org, linux-mediatek@lists.infradead.org, Yong Wu , Miles Chen , linux-arm-kernel@lists.infradead.org, Guangming Cao Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org For multiple iommu_domains, we need to reserve some iova regions, so we will add mtk_iommu_resv_iova_region structure. It includes the start address and size of iova and iommu_resv_type. Based on the function, we will realize multiple mtk_iommu_domains Signed-off-by: Anan Sun Signed-off-by: Chao Hao --- drivers/iommu/mtk_iommu.c | 47 +++++++++++++++++++++++++++++++++++++++ drivers/iommu/mtk_iommu.h | 12 ++++++++++ 2 files changed, 59 insertions(+) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 8c06d2a793a7..c0cd7da71c2c 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -697,6 +697,51 @@ static int mtk_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) return iommu_fwspec_add_ids(dev, args->args, 1); } +/* reserve/dir-map iova region */ +static void mtk_iommu_get_resv_regions(struct device *dev, + struct list_head *head) +{ + struct mtk_iommu_data *data = dev_iommu_fwspec_get(dev)->iommu_priv; + unsigned int i, total_cnt = data->plat_data->resv_cnt; + const struct mtk_iommu_resv_iova_region *resv_data; + struct iommu_resv_region *region; + unsigned long base = 0; + size_t size = 0; + int prot = IOMMU_WRITE | IOMMU_READ; + + resv_data = data->plat_data->resv_region; + + for (i = 0; i < total_cnt; i++) { + size = 0; + if (resv_data[i].iova_size) { + base = (unsigned long)resv_data[i].iova_base; + size = resv_data[i].iova_size; + } + if (!size) + continue; + + region = iommu_alloc_resv_region(base, size, prot, + resv_data[i].type); + if (!region) + return; + + list_add_tail(®ion->list, head); + + dev_dbg(data->dev, "%s iova 0x%x ~ 0x%x\n", + (resv_data[i].type == IOMMU_RESV_DIRECT) ? "dm" : "rsv", + (unsigned int)base, (unsigned int)(base + size - 1)); + } +} + +static void mtk_iommu_put_resv_regions(struct device *dev, + struct list_head *head) +{ + struct iommu_resv_region *entry, *next; + + list_for_each_entry_safe(entry, next, head, list) + kfree(entry); +} + static const struct iommu_ops mtk_iommu_ops = { .domain_alloc = mtk_iommu_domain_alloc, .domain_free = mtk_iommu_domain_free, @@ -711,6 +756,8 @@ static const struct iommu_ops mtk_iommu_ops = { .remove_device = mtk_iommu_remove_device, .device_group = mtk_iommu_device_group, .of_xlate = mtk_iommu_of_xlate, + .get_resv_regions = mtk_iommu_get_resv_regions, + .put_resv_regions = mtk_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 d8aef0d57b1a..10476b23adee 100644 --- a/drivers/iommu/mtk_iommu.h +++ b/drivers/iommu/mtk_iommu.h @@ -36,6 +36,12 @@ enum mtk_iommu_plat { M4U_MT8183, }; +struct mtk_iommu_resv_iova_region { + dma_addr_t iova_base; + size_t iova_size; + enum iommu_resv_type type; +}; + /* * reserved IOVA Domain for IOMMU users of HW limitation. */ @@ -68,6 +74,12 @@ struct mtk_iommu_plat_data { u32 dom_cnt; unsigned char larbid_remap[2][MTK_LARB_NR_MAX]; const struct mtk_domain_data *dom_data; + /* + * reserve/dir-mapping iova region data + * todo: for different reserve needs on multiple iommu domains + */ + const unsigned int resv_cnt; + const struct mtk_iommu_resv_iova_region *resv_region; }; struct mtk_iommu_domain;