Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4170039pxb; Tue, 25 Jan 2022 05:04:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJwqt5NDv0I1chr4ps6NteOIN7rLICZtof1fb8ArkyANy0ethFk8F7L1NWwaxeafm+aIqt0q X-Received: by 2002:a05:6a00:1896:b0:4c9:6027:e847 with SMTP id x22-20020a056a00189600b004c96027e847mr8586340pfh.15.1643115878742; Tue, 25 Jan 2022 05:04:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643115878; cv=none; d=google.com; s=arc-20160816; b=shMF4CIF2IdGhFQ+xoQg7dYPbFZPscXk+nvNj3s+SiOuEJtfFw5os034FMDxflv3xi oLSjlsJnScsIBUzI8r57XO0CaKLPUN15CbYAr4Oiq+AsZTFbynDCpJ0JF0Ia4gThQpRm rohxa195Pt3EjcurXKzAepcC44FWju4KUFYR1jiWbEJPVMaSbDTkLQ7kfqxj/UlCRlRI v06ULxBgKRP51EnkWlBFD+YzdPOreITskm8UPCI44+bl4LSVMeiFKUj286hRYAgAhtXd 8vX/u9UtS5Q4mEUfcoYCRH3LEQ2Vjczc4Wlv328nixsWDUd4GYpyMR939/6g4ywSZ7A8 kVpg== 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=S2jjFiflgwEcBmNbPqbruCYveuxPSIfck6GUaSXOjMI=; b=ChlSvxXS16TktMuJ+SavkyKaVtUYhGDoeLQ0rG39cwWTYKxCajWwt7YtwKDfq01Qvj hHuvHBov9KNl+arVx+lL6V0rDJ91g7helml/eEXF+o/Rd6PwGTYtvP5mYObHCuosguQf TEWopcXwcaC11+eDJsICCDXIL9OhK4VkyvIhcoHrAL0FwOO4z5UklG9fkU+JPKOzOct6 s0Q+ssQkoHNkibbiSQcXc4m1C9BNSl5pQUUl9bCd0usevaXemVcEjagzeIDnIByzgBWE tS4ZmVb39LTZZ2Vq85c/10VVXGBa0KzZ94mZ3wck5Mzkx8QgzsgaSrdtNIgqOb6P6rly S/fg== 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 i1si16125942pgm.277.2022.01.25.05.04.25; Tue, 25 Jan 2022 05:04:38 -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 S1454639AbiAYJJ1 (ORCPT + 99 others); Tue, 25 Jan 2022 04:09:27 -0500 Received: from mailgw01.mediatek.com ([60.244.123.138]:56956 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1455157AbiAYJDO (ORCPT ); Tue, 25 Jan 2022 04:03:14 -0500 X-UUID: 7bbfde51197340bc9a7ccc06b54e7137-20220125 X-UUID: 7bbfde51197340bc9a7ccc06b54e7137-20220125 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 352859111; Tue, 25 Jan 2022 17:00:57 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Tue, 25 Jan 2022 17:00:56 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 25 Jan 2022 17:00:54 +0800 From: Yong Wu To: Joerg Roedel , Rob Herring , "Matthias Brugger" , Will Deacon CC: Robin Murphy , Krzysztof Kozlowski , Tomasz Figa , , , , , , , Hsin-Yi Wang , , , , , , "AngeloGioacchino Del Regno" , , , , Subject: [PATCH v4 32/35] iommu/mediatek: Get the proper bankid for multi banks Date: Tue, 25 Jan 2022 16:56:31 +0800 Message-ID: <20220125085634.17972-33-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220125085634.17972-1-yong.wu@mediatek.com> References: <20220125085634.17972-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 banks_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 banks_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 | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 22586d1aed72..c6de9304bbc6 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -191,6 +191,7 @@ struct mtk_iommu_plat_data { u8 banks_num; bool banks_enable[MTK_IOMMU_BANK_MAX]; + unsigned int banks_portmsk[MTK_IOMMU_BANK_MAX]; unsigned char larbid_remap[MTK_LARB_COM_MAX][MTK_LARB_SUBCOM_MAX]; }; @@ -478,6 +479,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; + + if (plat_data->banks_num == 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->banks_num && i < MTK_IOMMU_BANK_MAX; i++) { + if (!plat_data->banks_enable[i]) + continue; + + if (portmsk & plat_data->banks_portmsk[i]) { + bankid = i; + break; + } + } + return bankid; /* default is 0 */ +} + static int mtk_iommu_get_iova_region_id(struct device *dev, const struct mtk_iommu_plat_data *plat_data) { @@ -630,13 +655,14 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain, struct list_head *hw_list = data->hw_list; struct device *m4udev = data->dev; struct mtk_iommu_bank_data *bank; - 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); mutex_lock(&dom->mutex); if (!dom->bank) { /* Data is in the frstdata in sharing pgtable case. */ @@ -778,6 +804,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); @@ -788,12 +815,18 @@ static struct iommu_group *mtk_iommu_device_group(struct device *dev) if (regionid < 0) return ERR_PTR(regionid); + bankid = mtk_iommu_get_bank_id(dev, data->plat_data); mutex_lock(&data->mutex); - 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); } -- 2.18.0