diff mbox series

[PATCHv2,3/6] iommu/arm-smmu: Implement iommu_ops->def_domain_type call-back

Message ID 558b1aee4c699a0a5b14b325178d22a79958488f.1587392905.git.saiprakash.ranjan@codeaurora.org (mailing list archive)
State New, archived
Headers show
Series iommu/arm-smmu: Allow client devices to select identity mapping | expand

Commit Message

Sai Prakash Ranjan April 20, 2020, 2:37 p.m. UTC
Implement the new def_domain_type call-back for the ARM
SMMU driver. We need this to support requesting the domain
type by the client devices.

Signed-off-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
---
 drivers/iommu/arm-smmu.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Robin Murphy April 20, 2020, 3:26 p.m. UTC | #1
On 2020-04-20 3:37 pm, Sai Prakash Ranjan wrote:
> Implement the new def_domain_type call-back for the ARM
> SMMU driver. We need this to support requesting the domain
> type by the client devices.
> 
> Signed-off-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
> ---
>   drivers/iommu/arm-smmu.c | 20 ++++++++++++++++++++
>   1 file changed, 20 insertions(+)
> 
> diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
> index e622f4e33379..b5d1d52dfbb8 100644
> --- a/drivers/iommu/arm-smmu.c
> +++ b/drivers/iommu/arm-smmu.c
> @@ -1609,6 +1609,25 @@ static void arm_smmu_get_resv_regions(struct device *dev,
>   	iommu_dma_get_resv_regions(dev, head);
>   }
>   
> +static int arm_smmu_def_domain_type(struct device *dev)
> +{
> +	struct iommu_fwspec *fwspec;
> +	struct arm_smmu_device *smmu;
> +
> +	fwspec = dev_iommu_fwspec_get(dev);
> +	if (!fwspec || fwspec->ops != &arm_smmu_ops)
> +		return -ENODEV;
> +
> +	smmu = arm_smmu_get_by_fwnode(fwspec->iommu_fwnode);
> +	if (!smmu)
> +		return -ENODEV;
> +

AFAICS this should only ever be called for a device in a group, which 
means an initial ->probe_device has succeeded and rather than 
defensively going the long way round, we can safely assume this:

	struct arm_smmu_master_cfg = dev_iommu_priv_get(dev);
	struct arm_smmu_impl *impl = cfg->smmu->impl;

	if (impl && impl->req_domain)
		return impl->req_domain(dev);

Or have I misunderstood the flow?

Robin.

> +	if (smmu->impl && smmu->impl->req_domain)
> +		return smmu->impl->req_domain(dev);
> +
> +	return 0;
> +}
> +
>   static struct iommu_ops arm_smmu_ops = {
>   	.capable		= arm_smmu_capable,
>   	.domain_alloc		= arm_smmu_domain_alloc,
> @@ -1627,6 +1646,7 @@ static struct iommu_ops arm_smmu_ops = {
>   	.of_xlate		= arm_smmu_of_xlate,
>   	.get_resv_regions	= arm_smmu_get_resv_regions,
>   	.put_resv_regions	= generic_iommu_put_resv_regions,
> +	.def_domain_type	= arm_smmu_def_domain_type,
>   	.pgsize_bitmap		= -1UL, /* Restricted during device attach */
>   };
>   
>
Sai Prakash Ranjan April 20, 2020, 4:27 p.m. UTC | #2
Hi Robin,

On 2020-04-20 20:56, Robin Murphy wrote:
> On 2020-04-20 3:37 pm, Sai Prakash Ranjan wrote:
>> Implement the new def_domain_type call-back for the ARM
>> SMMU driver. We need this to support requesting the domain
>> type by the client devices.
>> 
>> Signed-off-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
>> ---
>>   drivers/iommu/arm-smmu.c | 20 ++++++++++++++++++++
>>   1 file changed, 20 insertions(+)
>> 
>> diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
>> index e622f4e33379..b5d1d52dfbb8 100644
>> --- a/drivers/iommu/arm-smmu.c
>> +++ b/drivers/iommu/arm-smmu.c
>> @@ -1609,6 +1609,25 @@ static void arm_smmu_get_resv_regions(struct 
>> device *dev,
>>   	iommu_dma_get_resv_regions(dev, head);
>>   }
>>   +static int arm_smmu_def_domain_type(struct device *dev)
>> +{
>> +	struct iommu_fwspec *fwspec;
>> +	struct arm_smmu_device *smmu;
>> +
>> +	fwspec = dev_iommu_fwspec_get(dev);
>> +	if (!fwspec || fwspec->ops != &arm_smmu_ops)
>> +		return -ENODEV;
>> +
>> +	smmu = arm_smmu_get_by_fwnode(fwspec->iommu_fwnode);
>> +	if (!smmu)
>> +		return -ENODEV;
>> +
> 
> AFAICS this should only ever be called for a device in a group, which
> means an initial ->probe_device has succeeded and rather than
> defensively going the long way round, we can safely assume this:
> 
> 	struct arm_smmu_master_cfg = dev_iommu_priv_get(dev);
> 	struct arm_smmu_impl *impl = cfg->smmu->impl;
> 
> 	if (impl && impl->req_domain)
> 		return impl->req_domain(dev);
> 

Yes you are right, will use this.

Thanks,
Sai
diff mbox series

Patch

diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index e622f4e33379..b5d1d52dfbb8 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -1609,6 +1609,25 @@  static void arm_smmu_get_resv_regions(struct device *dev,
 	iommu_dma_get_resv_regions(dev, head);
 }
 
+static int arm_smmu_def_domain_type(struct device *dev)
+{
+	struct iommu_fwspec *fwspec;
+	struct arm_smmu_device *smmu;
+
+	fwspec = dev_iommu_fwspec_get(dev);
+	if (!fwspec || fwspec->ops != &arm_smmu_ops)
+		return -ENODEV;
+
+	smmu = arm_smmu_get_by_fwnode(fwspec->iommu_fwnode);
+	if (!smmu)
+		return -ENODEV;
+
+	if (smmu->impl && smmu->impl->req_domain)
+		return smmu->impl->req_domain(dev);
+
+	return 0;
+}
+
 static struct iommu_ops arm_smmu_ops = {
 	.capable		= arm_smmu_capable,
 	.domain_alloc		= arm_smmu_domain_alloc,
@@ -1627,6 +1646,7 @@  static struct iommu_ops arm_smmu_ops = {
 	.of_xlate		= arm_smmu_of_xlate,
 	.get_resv_regions	= arm_smmu_get_resv_regions,
 	.put_resv_regions	= generic_iommu_put_resv_regions,
+	.def_domain_type	= arm_smmu_def_domain_type,
 	.pgsize_bitmap		= -1UL, /* Restricted during device attach */
 };