Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp506597pxb; Thu, 23 Sep 2021 05:08:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJcxcWXOUU8n4m5mbD6NS7Q/AXbQmDpQqgMpyHkL4NhWmUu4wEbjYGhkjLACOxsdspl0Zv X-Received: by 2002:a05:6402:399:: with SMTP id o25mr5115892edv.118.1632398909350; Thu, 23 Sep 2021 05:08:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632398909; cv=none; d=google.com; s=arc-20160816; b=d0wP0/l1HSieAvZ2Oo93JRPLAP+twJyx40CSII751IImYRrUG2qme8xzJ31FI68Tsg JvYOfDxIRJB3hpqK+jOWJv/+3mlOLLtPr/GoWR7T0nOiU5nOhOccm6LoEXa34vjkjV6E 8btXoDLXa9l1zpl0RH29kIeYmrswhIfa3mXszTFjAYRaega9jg9exKm1rVGK8dpGZykL HS65lBpg5u1T075DA9VRt6OXic2gir/OHuQH6r013HNI1FCfBGcb+C3eCDJUuLmQWUoL S/g/EkmSH9Qi2eNa+jJ02l0uFBB9Wkwou1al224t5riNNn4UhhKFszN8lzaS0Uaql4zK YZsQ== 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=peeTJRegOEXOtOt2DMvuXi84r7JOxELjRf3YZIXtFY4=; b=mw+4FT0pv5B7ckFUEhlv01CMwr7Ou71I/jWZHkoUsd6ukjGuNMsKetmo6ZOLhvhmTW EPi8+HKyMlxsZKOfNrCb4eBEnNL8BIaCihoUPW17coUvjW8pipmBwG+v0bUVVb1wCWOZ DCyU8ks6hAuJGIzsiIeBmiT7GPqt5+ubgg6TfdFmdzk5Qz3vHWBLci7mTht+twPraGmI +zY43qpEiIg6GrMS5bUaOsiZggGoXzBlM6uKebNz/ijKDjgGkbP2PVvpViciV33RDhHh aqMLO5Ru3Mla0Wl1d8T9+sHWsQhHWcg9wjlXrUfXsO/rsibpkCuXcRfc7h900nVgISrC +7VA== 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 v4si5587936ejk.129.2021.09.23.05.08.05; Thu, 23 Sep 2021 05:08:29 -0700 (PDT) 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 S240979AbhIWMFO (ORCPT + 99 others); Thu, 23 Sep 2021 08:05:14 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:55432 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S240749AbhIWMFH (ORCPT ); Thu, 23 Sep 2021 08:05:07 -0400 X-UUID: ca2e26bd5c9744f99af8f19ad2016197-20210923 X-UUID: ca2e26bd5c9744f99af8f19ad2016197-20210923 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1186673699; Thu, 23 Sep 2021 20:03:33 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 23 Sep 2021 20:03:32 +0800 Received: from localhost.localdomain (10.17.3.154) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 23 Sep 2021 20:03:31 +0800 From: Yong Wu To: Joerg Roedel , Rob Herring , Matthias Brugger , Will Deacon , Robin Murphy CC: Krzysztof Kozlowski , Tomasz Figa , , , , , , , Hsin-Yi Wang , , , , , Subject: [PATCH v3 30/33] iommu/mediatek: Get the proper bankid for multi banks Date: Thu, 23 Sep 2021 19:58:37 +0800 Message-ID: <20210923115840.17813-31-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210923115840.17813-1-yong.wu@mediatek.com> References: <20210923115840.17813-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 We preassign some ports in a special bank via the new defined bank_portmsk. Put it in the plat_data means it is not expected to be adjusted dynamically. If the iommu id in the iommu consumer's dtsi node is inside this bank_portmsk, then we switch it to this special iommu bank, and initialise the IOMMU bank HW. Each a bank has the independent pgtable(4GB iova range). Each a bank is a independent iommu domain/group. Currently we don't separate different iova ranges inside a bank. Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 38 +++++++++++++++++++++++++++++++++++--- drivers/iommu/mtk_iommu.h | 1 + 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 6e3f7b97f3f5..5d648f50cbe1 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -352,6 +352,30 @@ static irqreturn_t mtk_iommu_isr(int irq, void *dev_id) return IRQ_HANDLED; } +static unsigned int mtk_iommu_get_bank_id(struct device *dev, + const struct mtk_iommu_plat_data *plat_data) +{ + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + unsigned int i, portmsk = 0, bankid = 0; /* bank default is 0 */ + + if (plat_data->bank_nr == 1) + return bankid; + + for (i = 0; i < fwspec->num_ids; i++) + portmsk |= BIT(MTK_M4U_TO_PORT(fwspec->ids[i])); + + for (i = 0; i < plat_data->bank_nr; i++) { + if (!plat_data->bank_enable[i]) + continue; + + if (portmsk & plat_data->bank_portmsk[i]) { + bankid = i; + break; + } + } + return bankid; +} + static int mtk_iommu_get_iova_region_id(struct device *dev, const struct mtk_iommu_plat_data *plat_data) { @@ -503,13 +527,14 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain, struct list_head *hw_list = data->hw_list; struct mtk_iommu_bank_data *bank; struct device *m4udev = data->dev; - unsigned int bankid = 0; + unsigned int bankid; int ret, region_id; region_id = mtk_iommu_get_iova_region_id(dev, data->plat_data); if (region_id < 0) return region_id; + bankid = mtk_iommu_get_bank_id(dev, data->plat_data); bank = &data->bank[bankid]; if (!dom->bank) { /* Data is in the frstdata in sharing pgtable case. */ @@ -636,6 +661,7 @@ static struct iommu_group *mtk_iommu_device_group(struct device *dev) struct mtk_iommu_data *c_data = dev_iommu_priv_get(dev), *data; struct list_head *hw_list = c_data->hw_list; struct iommu_group *group; + unsigned int bankid, groupid; int regionid; data = mtk_iommu_get_frst_data(hw_list); @@ -645,12 +671,18 @@ static struct iommu_group *mtk_iommu_device_group(struct device *dev) regionid = mtk_iommu_get_iova_region_id(dev, data->plat_data); if (regionid < 0) return ERR_PTR(regionid); + bankid = mtk_iommu_get_bank_id(dev, data->plat_data); - group = data->m4u_group[regionid]; + /* + * If the bank function is enabled, each a bank is a iommu group/domain. + * otherwise, each a iova region is a iommu group/domain. + */ + groupid = bankid ? bankid : regionid; + group = data->m4u_group[groupid]; if (!group) { group = iommu_group_alloc(); if (!IS_ERR(group)) - data->m4u_group[regionid] = group; + data->m4u_group[groupid] = group; } else { iommu_group_ref_get(group); } diff --git a/drivers/iommu/mtk_iommu.h b/drivers/iommu/mtk_iommu.h index dc0190edebf0..cf4b3d10cf2c 100644 --- a/drivers/iommu/mtk_iommu.h +++ b/drivers/iommu/mtk_iommu.h @@ -65,6 +65,7 @@ struct mtk_iommu_plat_data { unsigned int bank_nr; bool bank_enable[MTK_IOMMU_BANK_MAX]; + unsigned int bank_portmsk[MTK_IOMMU_BANK_MAX]; unsigned char larbid_remap[MTK_LARB_COM_MAX][MTK_LARB_SUBCOM_MAX]; }; -- 2.18.0