Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1338249ybz; Thu, 16 Apr 2020 07:28:21 -0700 (PDT) X-Google-Smtp-Source: APiQypIUB1Ea/vx3DZoTcA03C7M5oUjLwz/rp1YfvY5g33ONryhsjbev6e3Rl64f5JgccuL3so49 X-Received: by 2002:a50:9e2a:: with SMTP id z39mr31202800ede.178.1587047301199; Thu, 16 Apr 2020 07:28:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587047301; cv=none; d=google.com; s=arc-20160816; b=hs5Q4r4hbaNOOCnOdDuTPC4h51ft0YW1oqn77uDvrhqORZmHDQxKv5Kot2bT4zL8Gb kjLXZeySXP2V+r0p1Ux3D9wA0FOeq8aGKc2I0mj1HBHhRQKO1aVwxIzAyev3qCcyud5W NaGJbnbWAq7X6yaN5jDshEO3xeEgl8XdQ5ADFUnntc04CU14pp/sRzYyHAgbSpAOATsk Cc7ThzUnr4oagZIFnAtLiGvfYu2uzjd7CDfjIs/axZqZMJtu1vcqbGyj+ZPnnYTKJk9V sl806EhBPPNwV2+y0+SaTqyCcIjw0k5335lqgyXQ9ZKA/INt8Jw91evvq964iNFB7ZgG bH2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=bDDfJDhG+qUYf8sZyzsLUPZuv/RjT3XDO3Vb3VGnXmQ=; b=CiUcT3xuUY87df4tKpXcouyoZSlHljvkQ7ilf3ajGNzn6n7yemI4sDNes3D5RwZGIk CM5piHYMb9WdzlcE4BnX1shY9190DJujJXQvcSpln26yHsOpDcMRsGDpFoLr0Wd7+jsN 6rbnX9MHq3f7+GD6CJKJ/1thW7RIKJY50tmhjAe+6KXgOAJ1PBRd8XisVa4+K+OWAr08 b5F30QYlNww0TUFTI5JQMEMLl0OeVgK/aH3FHzJXojH6vjd2wv2+0lK0FbzkgOsh1uno jHXDJ4IZALFD0wXXeNBlWPSXXqZwbeUh87n5Reu8hUorTDgHve9lOA0gewTLIlcU3jtk gLxQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m18si12037741ejj.432.2020.04.16.07.27.58; Thu, 16 Apr 2020 07:28:21 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2410061AbgDPO0K (ORCPT + 99 others); Thu, 16 Apr 2020 10:26:10 -0400 Received: from foss.arm.com ([217.140.110.172]:33168 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2409360AbgDPN6b (ORCPT ); Thu, 16 Apr 2020 09:58:31 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 95ABD1FB; Thu, 16 Apr 2020 06:58:30 -0700 (PDT) Received: from [10.57.59.184] (unknown [10.57.59.184]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4786A3F237; Thu, 16 Apr 2020 06:58:27 -0700 (PDT) Subject: Re: [PATCH 2/2] iommu/arm-smmu: Allow client devices to select direct mapping To: Sai Prakash Ranjan , Will Deacon , Joerg Roedel , Jordan Crouse , Rob Clark Cc: "iommu@lists.linux-foundation.org" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "linux-arm-msm@vger.kernel.org" , Stephen Boyd , Matthias Kaehlcke , Bjorn Andersson , Rajendra Nayak , Tomasz Figa References: <813cc5b2da10c27db982254b274bf26008a9e6da.1579692800.git.saiprakash.ranjan@codeaurora.org> From: Robin Murphy Message-ID: <3f12cefb-3887-859c-ddf5-c7a0fc755152@arm.com> Date: Thu, 16 Apr 2020 14:58:25 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <813cc5b2da10c27db982254b274bf26008a9e6da.1579692800.git.saiprakash.ranjan@codeaurora.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-01-22 11:48 am, Sai Prakash Ranjan wrote: > From: Jordan Crouse > > Some client devices want to directly map the IOMMU themselves instead > of using the DMA domain. Allow those devices to opt in to direct > mapping by way of a list of compatible strings. > > Signed-off-by: Jordan Crouse > Co-developed-by: Sai Prakash Ranjan > Signed-off-by: Sai Prakash Ranjan > --- > drivers/iommu/arm-smmu-qcom.c | 39 +++++++++++++++++++++++++++++++++++ > drivers/iommu/arm-smmu.c | 3 +++ > drivers/iommu/arm-smmu.h | 5 +++++ > 3 files changed, 47 insertions(+) > > diff --git a/drivers/iommu/arm-smmu-qcom.c b/drivers/iommu/arm-smmu-qcom.c > index 64a4ab270ab7..ff746acd1c81 100644 > --- a/drivers/iommu/arm-smmu-qcom.c > +++ b/drivers/iommu/arm-smmu-qcom.c > @@ -3,6 +3,7 @@ > * Copyright (c) 2019, The Linux Foundation. All rights reserved. > */ > > +#include > #include > > #include "arm-smmu.h" > @@ -11,6 +12,43 @@ struct qcom_smmu { > struct arm_smmu_device smmu; > }; > > +static const struct arm_smmu_client_match_data qcom_adreno = { > + .direct_mapping = true, > +}; > + > +static const struct arm_smmu_client_match_data qcom_mdss = { > + .direct_mapping = true, > +}; Might it make sense to group these by the desired SMMU behaviour rather than (apparently) what kind of device the client happens to be, which seems like a completely arbitrary distinction from the SMMU driver's PoV? > + > +static const struct of_device_id qcom_smmu_client_of_match[] = { > + { .compatible = "qcom,adreno", .data = &qcom_adreno }, > + { .compatible = "qcom,mdp4", .data = &qcom_mdss }, > + { .compatible = "qcom,mdss", .data = &qcom_mdss }, > + { .compatible = "qcom,sc7180-mdss", .data = &qcom_mdss }, > + { .compatible = "qcom,sdm845-mdss", .data = &qcom_mdss }, > + {}, > +}; > + > +static const struct arm_smmu_client_match_data * > +qcom_smmu_client_data(struct device *dev) > +{ > + const struct of_device_id *match = > + of_match_device(qcom_smmu_client_of_match, dev); > + > + return match ? match->data : NULL; of_device_get_match_data() is your friend. > +} > + > +static int qcom_smmu_request_domain(struct device *dev) > +{ > + const struct arm_smmu_client_match_data *client; > + > + client = qcom_smmu_client_data(dev); > + if (client) > + iommu_request_dm_for_dev(dev); > + > + return 0; > +} > + > static int qcom_sdm845_smmu500_reset(struct arm_smmu_device *smmu) > { > int ret; > @@ -41,6 +79,7 @@ static int qcom_smmu500_reset(struct arm_smmu_device *smmu) > } > > static const struct arm_smmu_impl qcom_smmu_impl = { > + .req_domain = qcom_smmu_request_domain, > .reset = qcom_smmu500_reset, > }; > > diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c > index 16c4b87af42b..67dd9326247a 100644 > --- a/drivers/iommu/arm-smmu.c > +++ b/drivers/iommu/arm-smmu.c > @@ -1448,6 +1448,9 @@ static int arm_smmu_add_device(struct device *dev) > device_link_add(dev, smmu->dev, > DL_FLAG_PM_RUNTIME | DL_FLAG_AUTOREMOVE_SUPPLIER); > > + if (smmu->impl && smmu->impl->req_domain) > + return smmu->impl->req_domain(dev); > + There are about 5 different patchsets flying around at the moment that all touch default domain allocation, so this is a fast-moving target, but I think where the dust should settle is with arm_smmu_ops forwarding .def_domain_type (or whatever it ends up as) calls to arm_smmu_impl as appropriate. > return 0; > > out_cfg_free: > diff --git a/drivers/iommu/arm-smmu.h b/drivers/iommu/arm-smmu.h > index 8d1cd54d82a6..059dc9c39f64 100644 > --- a/drivers/iommu/arm-smmu.h > +++ b/drivers/iommu/arm-smmu.h > @@ -244,6 +244,10 @@ enum arm_smmu_arch_version { > ARM_SMMU_V2, > }; > > +struct arm_smmu_client_match_data { > + bool direct_mapping; > +}; Does this need to be public? I don't see the other users... Robin. > + > enum arm_smmu_implementation { > GENERIC_SMMU, > ARM_MMU500, > @@ -386,6 +390,7 @@ struct arm_smmu_impl { > int (*init_context)(struct arm_smmu_domain *smmu_domain); > void (*tlb_sync)(struct arm_smmu_device *smmu, int page, int sync, > int status); > + int (*req_domain)(struct device *dev); > }; > > static inline void __iomem *arm_smmu_page(struct arm_smmu_device *smmu, int n) >