Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp256827pxu; Wed, 25 Nov 2020 02:15:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJxiT8MiWSW4NOPrj9xtf6q/fPR699vkLki/A08htMZ+hVG2bjsh/rUALinCf5jYoQENeVBm X-Received: by 2002:a17:906:7a57:: with SMTP id i23mr1470097ejo.74.1606299337527; Wed, 25 Nov 2020 02:15:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606299337; cv=none; d=google.com; s=arc-20160816; b=n63Nd89MIwan8AsCwu9Fr5Cc8/8IqKZAtDPG0Wb1DR80RuuhA5f5oXOO7S+4AbMKNK q0nQ4Yn1Fe/7RiCRHtByDQgxkhejDXsPBe+aiilCiE0Ulotokvvq9mLwDMmfxCO3XuG6 +GinF3c9QnoTzHgxhwYr0uoegMGR6SBy1buca67JWuCABU3+nxg5CLndi7kuX+jiHvRA OfNXMjeYkcVScYpfsibfXZz0DWJTQkl6KbDir2AjxXj15Ur5HF0dEklc8E7AGy7nZ15t agsWv56oCfU452KV5vg1RMa6+mGT10uVRX0ckyGU5SNb5SFdIx+fQVqD2ZGytnbAIyCz ildg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=dBj3ElIQISAbDs/2c0jKAE09FMkxqkkG9msAZTAky/Y=; b=SMOfxIKamqs/IkTM4NULDRo7eoPVf7rckAVw+2zA5WRUizdLu3hmGyt9KFgmutZOai uGwEZuyisrCb+VafPqSVpqFUXVWHt595UWTnp+w5mj/ZBgyGN/IPoj6VPr4nUKVveaaH eKCDov9gNBzFrMhTVGQIDdnwGyyTRUXUYEbSgJmBTi0h6S14oo07IL8ilE2/Le3BEMIB +KSfi/3F4109T7p2xfQzAxrk/XRhqt96nlveD4Uqj1KO2PrKRKNLPKVx14F6/tuxdWAv 3RjG85hImPzxdjwe1RQfUuuZ6wqewjm+woAlSX90hYTrDuzeBhaZBX7J4fCwbTfeomzC vI+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZBg+ztGx; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r12si916291eda.364.2020.11.25.02.15.13; Wed, 25 Nov 2020 02:15:37 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZBg+ztGx; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729016AbgKYKMA (ORCPT + 99 others); Wed, 25 Nov 2020 05:12:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728981AbgKYKLx (ORCPT ); Wed, 25 Nov 2020 05:11:53 -0500 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39B74C0613D6; Wed, 25 Nov 2020 02:11:53 -0800 (PST) Received: by mail-pf1-x443.google.com with SMTP id y7so1827077pfq.11; Wed, 25 Nov 2020 02:11:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dBj3ElIQISAbDs/2c0jKAE09FMkxqkkG9msAZTAky/Y=; b=ZBg+ztGxxXFvJXoYmB902xfMalKQkFaKLz4xUKhdodOLFc0vrGCg+viuYhy4a9ALb0 7hMTTovcmnVpoh2Bc+mVCQVJikn5CkTtytwFWVEqOiNVVtXJxW4iXeRVgIRda86myne+ 1jQgcw8TkPk72WOki5kbImGvKABkDN+OqLxDhnldy1o3SEjw1Kul5BxAdo8YilDZ1NzC ZaE0b4ajpA4WuMWCfnAwgx1rWmsGP4qrNe/Vyn4lIb+i7gVsLiJDrUK/yID5jBg4TLy1 xdVXOiOiazMo0aa5vMH9ZxRKd9Up1gLAxZhc0w88QGAdx6GZhvLeHeL1rNRqWJSXiub7 YNWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dBj3ElIQISAbDs/2c0jKAE09FMkxqkkG9msAZTAky/Y=; b=YPyI36abU6zZTrVKl95rsQ/NyqY8hb920chpn6cKu0uFjVleg3/lUAKCaWBJHPo4Ik zdN32E2th5bAjOpJYsqmglsm/hfdt92eWlDzX57OBJlqBrz5SsaXoLvAnBFrM/J/JzKp BlosYyYK6M0WiXUP96n3ZmxNxLo6hx5bWw5LC2PJtANjlbHT1rbZGuha/Lti2HBBlNCg 2YqQbEqniPZDuHXsWYsu0Y11z068O6/2XXBEkY+f3Grrz95EwVLKo9eQO7eEVdj24mjd 5mAt1EirSM7Gao471sZbuWsxmaO9lmmZYijoDE0iEVowy0cCXRbTrrLFt/nET61NTSDW D5AQ== X-Gm-Message-State: AOAM532GU6MduF8YoXlibw+0qnbOMkMjDOYlbHE5TPojBDjAMKWbCkft 2PUMKZCRB2sF7oA+wPJH7WY= X-Received: by 2002:a17:90a:a81:: with SMTP id 1mr3219106pjw.165.1606299112834; Wed, 25 Nov 2020 02:11:52 -0800 (PST) Received: from Asurada-Nvidia.nvidia.com (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id r130sm1599496pfc.41.2020.11.25.02.11.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 02:11:52 -0800 (PST) From: Nicolin Chen To: will@kernel.org Cc: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, linux-tegra@vger.kernel.org, jonathanh@nvidia.com, vdumpa@nvidia.com, thierry.reding@gmail.com, joro@8bytes.org Subject: [PATCH RESEND v2 3/5] iommu/tegra-smmu: Use fwspec in tegra_smmu_(de)attach_dev Date: Wed, 25 Nov 2020 02:10:11 -0800 Message-Id: <20201125101013.14953-4-nicoleotsuka@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201125101013.14953-1-nicoleotsuka@gmail.com> References: <20201125101013.14953-1-nicoleotsuka@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In tegra_smmu_(de)attach_dev() functions, we poll DTB for each client's iommus property to get swgroup ID in order to prepare "as" and enable smmu. Actually tegra_smmu_configure() prepared an fwspec for each client, and added to the fwspec all swgroup IDs of client DT node in DTB. So this patch uses fwspec in tegra_smmu_(de)attach_dev() so as to replace the redundant DT polling code. Reviewed-by: Dmitry Osipenko Tested-by: Dmitry Osipenko Acked-by: Thierry Reding Signed-off-by: Nicolin Chen --- drivers/iommu/tegra-smmu.c | 56 ++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index 6a3ecc334481..297d49f3f80e 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -484,60 +484,50 @@ static void tegra_smmu_as_unprepare(struct tegra_smmu *smmu, static int tegra_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) { + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct tegra_smmu *smmu = dev_iommu_priv_get(dev); struct tegra_smmu_as *as = to_smmu_as(domain); - struct device_node *np = dev->of_node; - struct of_phandle_args args; - unsigned int index = 0; - int err = 0; - - while (!of_parse_phandle_with_args(np, "iommus", "#iommu-cells", index, - &args)) { - unsigned int swgroup = args.args[0]; - - if (args.np != smmu->dev->of_node) { - of_node_put(args.np); - continue; - } + unsigned int index; + int err; - of_node_put(args.np); + if (!fwspec) + return -ENOENT; + for (index = 0; index < fwspec->num_ids; index++) { err = tegra_smmu_as_prepare(smmu, as); - if (err < 0) - return err; + if (err) + goto disable; - tegra_smmu_enable(smmu, swgroup, as->id); - index++; + tegra_smmu_enable(smmu, fwspec->ids[index], as->id); } if (index == 0) return -ENODEV; return 0; + +disable: + while (index--) { + tegra_smmu_disable(smmu, fwspec->ids[index], as->id); + tegra_smmu_as_unprepare(smmu, as); + } + + return err; } static void tegra_smmu_detach_dev(struct iommu_domain *domain, struct device *dev) { + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct tegra_smmu_as *as = to_smmu_as(domain); - struct device_node *np = dev->of_node; struct tegra_smmu *smmu = as->smmu; - struct of_phandle_args args; - unsigned int index = 0; - - while (!of_parse_phandle_with_args(np, "iommus", "#iommu-cells", index, - &args)) { - unsigned int swgroup = args.args[0]; + unsigned int index; - if (args.np != smmu->dev->of_node) { - of_node_put(args.np); - continue; - } - - of_node_put(args.np); + if (!fwspec) + return; - tegra_smmu_disable(smmu, swgroup, as->id); + for (index = 0; index < fwspec->num_ids; index++) { + tegra_smmu_disable(smmu, fwspec->ids[index], as->id); tegra_smmu_as_unprepare(smmu, as); - index++; } } -- 2.17.1