From patchwork Thu Feb 16 05:33:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Wu X-Patchwork-Id: 57874 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp128637wrn; Wed, 15 Feb 2023 22:00:19 -0800 (PST) X-Google-Smtp-Source: AK7set+k7rgTfqBZ5+AIinwIFzHz9SLaSJntI+X8yeJT4B7yReseEDR2qS9kJe5DV6eofVJoX7UR X-Received: by 2002:a17:902:d154:b0:19a:b74a:7f7e with SMTP id t20-20020a170902d15400b0019ab74a7f7emr4272016plt.28.1676527219239; Wed, 15 Feb 2023 22:00:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676527219; cv=none; d=google.com; s=arc-20160816; b=DP6tk2W06L/xCM1FRXd2VO7oGI6IWnQ3NxWpPpkFGG5/TRnX4mKp2CuMbmiJ193n4r Prpoxisks0wT9+/C5Cw499A7VKd0SRGvd8boN77GgRKZUioWEp/P5d062M9ygF3St/oD o8DrCsfPZjTYrLMHpVBtyQPKJy0ivRRCHxCUNtmVH42nmu5U5sbsNZY8bgp83OxlgRhN Jy/I8csw3hMylmvIBEcidI++tnNFOwRThJVlkP6Nj3HFY2qi1IzfJzZX0kUZquXWRBvA 8vp47cdbstPvtEOpH5pn7UTqgLoPzmBG/kQE5jnorPNiSWV2wWr5DhE19S+kYHozZEq4 bUEg== 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:dkim-signature; bh=+3xIGt0fW/waO3hH0M9YaCdUr6JQu37ebiTFAwKMZzw=; b=u3bRIGd05Hyi91ZTT3fBGcbAgZUSCzJGzpZvZHhD6qj/n0yEPuPQ/d8px4ti7oP/a8 o0Per248O2poXuadHHgb3a1WTfBNBLRmhaSkzpOTexpp3T5ePC1CaXrXSblwN5jJRoVc lU5YLtD/GXeY62Zmq0Dma7lkNMfhWjS2IjEbAU4S/R6OCIdEpsoIXl/SahOBwKcn0HUn /iPTJY1z1qeMFWztyUPeNGofBGjU1qLb7gvI+ItEWhSjvNZuYj3ZLwUa3DB/Jdx1QTnW InWi6HnFtWca1Q5812cq6yT4QaaPpHuzEmSiYQDd3/S3JaYYwGUz9h/hWoO9/SF2y+hH LAAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=mM2K8gyg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l8-20020a170903120800b0019aa279fd7dsi671647plh.154.2023.02.15.22.00.05; Wed, 15 Feb 2023 22:00:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=mM2K8gyg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229812AbjBPFet (ORCPT + 99 others); Thu, 16 Feb 2023 00:34:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229806AbjBPFep (ORCPT ); Thu, 16 Feb 2023 00:34:45 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DDAF1EFC0; Wed, 15 Feb 2023 21:34:30 -0800 (PST) X-UUID: 8d8010d4adbb11ed945fc101203acc17-20230216 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=+3xIGt0fW/waO3hH0M9YaCdUr6JQu37ebiTFAwKMZzw=; b=mM2K8gyghSAevaYrx0slfCqceR/p7tvNKzofKYcYwNA+MbpqjIF+vgdcEef3Zr77R323HmiZloqeYu8adKREs14YyH69BUu0fjm6NJwXsgt88tSlwtYJ5IbtX7+x6JGINBBwPGUx6HfzoAhqlhOiPhwU3L70vUM09g57D6FGAqE=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.19,REQID:c7a0f2b2-d052-44c8-8345-ffbc0c1a7a57,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:885ddb2,CLOUDID:4b54bb25-564d-42d9-9875-7c868ee415ec,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0 X-CID-BVR: 0 X-UUID: 8d8010d4adbb11ed945fc101203acc17-20230216 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1738367379; Thu, 16 Feb 2023 13:34:16 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Thu, 16 Feb 2023 13:34:15 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Thu, 16 Feb 2023 13:34:14 +0800 From: Yong Wu To: Joerg Roedel , Will Deacon , Rob Herring , Matthias Brugger CC: Robin Murphy , Krzysztof Kozlowski , Yong Wu , AngeloGioacchino Del Regno , , , , , , , , , , Subject: [PATCH v7 3/6] iommu/mediatek: Adjust mtk_iommu_config flow Date: Thu, 16 Feb 2023 13:33:19 +0800 Message-ID: <20230216053322.11596-4-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20230216053322.11596-1-yong.wu@mediatek.com> References: <20230216053322.11596-1-yong.wu@mediatek.com> MIME-Version: 1.0 X-MTK: N X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,RDNS_NONE, SPF_HELO_PASS,SPF_PASS,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757966205574432795?= X-GMAIL-MSGID: =?utf-8?q?1757966205574432795?= From: "Chengci.Xu" For reduce indention without functional change, prepare for MT8188. If there are many ports in a same larb, current flow will update larb_mmu->mmu or update INFRA register for too many times. So we save all ports to portid_msk in the front of mtk_iommu_config(), and then update only once for IOMMU configure. By this modification, we can prevent MT8188 from sending to many SMC calls, avoiding enter ATF for each port. Signed-off-by: Chengci.Xu Reviewed-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 58 +++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 9802e5c1a625..7ba05fa58c20 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -583,41 +583,47 @@ static int mtk_iommu_config(struct mtk_iommu_data *data, struct device *dev, unsigned int larbid, portid; struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); const struct mtk_iommu_iova_region *region; - u32 peri_mmuen, peri_mmuen_msk; + unsigned long portid_msk = 0; int i, ret = 0; for (i = 0; i < fwspec->num_ids; ++i) { - larbid = MTK_M4U_TO_LARB(fwspec->ids[i]); portid = MTK_M4U_TO_PORT(fwspec->ids[i]); + portid_msk |= BIT(portid); + } - if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_MM)) { - larb_mmu = &data->larb_imu[larbid]; + if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_MM)) { + /* All ports should be in the same larb. just use 0 here */ + larbid = MTK_M4U_TO_LARB(fwspec->ids[0]); + larb_mmu = &data->larb_imu[larbid]; + region = data->plat_data->iova_region + regionid; - region = data->plat_data->iova_region + regionid; + for_each_set_bit(portid, &portid_msk, 32) larb_mmu->bank[portid] = upper_32_bits(region->iova_base); - dev_dbg(dev, "%s iommu for larb(%s) port %d region %d rgn-bank %d.\n", - enable ? "enable" : "disable", dev_name(larb_mmu->dev), - portid, regionid, larb_mmu->bank[portid]); - - if (enable) - larb_mmu->mmu |= MTK_SMI_MMU_EN(portid); - else - larb_mmu->mmu &= ~MTK_SMI_MMU_EN(portid); - } else if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_INFRA)) { - peri_mmuen_msk = BIT(portid); - /* PCI dev has only one output id, enable the next writing bit for PCIe */ - if (dev_is_pci(dev)) - peri_mmuen_msk |= BIT(portid + 1); - - peri_mmuen = enable ? peri_mmuen_msk : 0; - ret = regmap_update_bits(data->pericfg, PERICFG_IOMMU_1, - peri_mmuen_msk, peri_mmuen); - if (ret) - dev_err(dev, "%s iommu(%s) inframaster 0x%x fail(%d).\n", - enable ? "enable" : "disable", - dev_name(data->dev), peri_mmuen_msk, ret); + dev_dbg(dev, "%s iommu for larb(%s) port 0x%lx region %d rgn-bank %d.\n", + enable ? "enable" : "disable", dev_name(larb_mmu->dev), + portid_msk, regionid, upper_32_bits(region->iova_base)); + + if (enable) + larb_mmu->mmu |= portid_msk; + else + larb_mmu->mmu &= ~portid_msk; + } else if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_INFRA)) { + /* PCI dev has only one output id, enable the next writing bit for PCIe */ + if (dev_is_pci(dev)) { + if (fwspec->num_ids != 1) { + dev_err(dev, "PCI dev can only have one port.\n"); + return -ENODEV; + } + portid_msk |= BIT(portid + 1); } + + ret = regmap_update_bits(data->pericfg, PERICFG_IOMMU_1, + (u32)portid_msk, enable ? (u32)portid_msk : 0); + if (ret) + dev_err(dev, "%s iommu(%s) inframaster 0x%lx fail(%d).\n", + enable ? "enable" : "disable", + dev_name(data->dev), portid_msk, ret); } return ret; }