Generic IOMMU bindings support for Xen platform devices
cover Generic IOMMU bindings support for Xen platform devices
The "mmu-masters" is a property of ARM legacy SMMU dt-binding. This property will be deprecated in favour of the generic IOMMU bindings. In this case we have to add the generic IOMMU bindings support for Xen platform devices.
---
This series has been tested on Seattle SoftIron server. The platform device can be passthrough to guest with both Legacy and Generic IOMMU bindings. I noticed that Sameer has a iommu_fwspec series in review. It would be nice to look at it and see if we can re-use it in this series.
Wei Chen (7):
xen/arm: SMMU: Implement the add_device callback in SMMU xen/arm: SMMU: Introduce a helper to add DT device to SMMU xen/arm: Prepare SMMU resources for protected devices xen/arm: SMMU: Detect types of device tree binding xen/arm: SMMU: Keep registering legacy master in SMMU probe xen/arm: SMMU: Support generic IOMMU bindings
xen: Fix a typo in error message of iommu_do_dt_domctl
xen/arch/arm/domain_build.c | 12 ++ xen/drivers/passthrough/arm/smmu.c | 232 ++++++++++++++++++++++++++++++---- xen/drivers/passthrough/device_tree.c | 24 +++- xen/include/xen/iommu.h | 1 + 4 files changed, 243 insertions(+), 26 deletions(-)
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 1/7 xen/arm: SMMU: Implement the add_device callback in SMMU
This add_device callback function is taking care of adding a device to SMMU and make sure it is fully prepare to be used by the SMMU afterwards.
In previous code, we don't implement the add_device callback in iommu_ops for ARM SMMU. We placed the work of add_device to assign_device callback. The function assign_device should not care about adding the device to an iommu_group. It might not even be able to decide how to do that. In this patch, we move this work back to add_device callback.
This add_device callback is only called while we are handling all devices for constructing the Domain0.
--- xen/drivers/passthrough/arm/smmu.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)
xen/drivers/passthrough/arm/smmu.c +23 -11
@@ -2591,6 +2591,26 @@ static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)xfree (domain); } +static int arm_smmu_xen_add_device (u8 devfn,struct device *dev) +{ +if (dt_device_is_protected (dev->of_node)) { +if (!dev->archdata.iommu) { + dev->archdata.iommu = xzalloc(struct arm_smmu_xen_device); +if (!dev->archdata.iommu) +return -ENOMEM ; + } + +if (!dev_iommu_group (dev)) +return arm_smmu_add_device (dev); + } + +/* +* Return 0 if the device is not protected to follow the behavior +* of PCI add device. +*/ +return 0 ; +} +static int arm_smmu_assign_dev (struct domain *d,u8 devfn,struct device *dev,u32 flag) {
@@ -2600,17 +2620,8 @@ static int arm_smmu_assign_dev(struct domain *d, u8 devfn, xen_domain =dom_iommu (d)->arch.priv; -if (!dev->archdata.iommu) { - dev->archdata.iommu = xzalloc(struct arm_smmu_xen_device); -if (!dev->archdata.iommu) -return -ENOMEM ; - } - -if (!dev_iommu_group (dev)) { - ret =arm_smmu_add_device (dev); -if (ret) -return ret; - } +if (!dev_iommu_group (dev)) +return -ENODEV ;spin_lock (&xen_domain->lock);
@@ -2784,6 +2795,7 @@ static const struct iommu_ops arm_smmu_iommu_ops = { .teardown = arm_smmu_iommu_domain_teardown, .iotlb_flush = arm_smmu_iotlb_flush, .iotlb_flush_all = arm_smmu_iotlb_flush_all, + .add_device = arm_smmu_xen_add_device, .assign_device = arm_smmu_assign_dev, .reassign_device = arm_smmu_reassign_dev, .map_page = arm_smmu_map_page,
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 1/7] xen/arm: SMMU: Implement the add_device callback in SMMU
Quoted 33 lines · Wei Chen
This
add_devicecallback function is taking care of adding a device to SMMU and make sure it is fully prepare to be used by the SMMU afterwards.In previous code, we don't implement the
add_devicecallback iniommu_opsfor ARM SMMU. We placed the work ofadd_devicetoassign_devicecallback. The functionassign_deviceshould not care about adding the device to aniommu_group. It might not even be able to decide how to do that. In this patch, we move this work back toadd_devicecallback.This
add_devicecallback is only called while we are handling all devices for constructing the Domain0.Signed-off-by Wei Chen <[email protected]>--- xen/drivers/passthrough/arm/smmu.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)xen/drivers/passthrough/arm/smmu.c +6
-0@@ -2591,6 +2591,26 @@ static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)xfree (domain); } +static int arm_smmu_xen_add_device (u8 devfn,struct device *dev) +{ +if (dt_device_is_protected (dev->of_node)) { +if (!dev->archdata.iommu) { + dev->archdata.iommu = xzalloc(struct arm_smmu_xen_device); +if (!dev->archdata.iommu)
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain) · line 2609
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c +10
-0+return -ENOMEM ; + } + +if (!dev_iommu_group (dev)) +return arm_smmu_add_device (dev); + } + +/* +* Return 0 if the device is not protected to follow the behavior +* of PCI add device.
What does this comment mean?
Quoted 44 lines
xen/drivers/passthrough/arm/smmu.c +7
-11+*/ +return 0 ; +} +static int arm_smmu_assign_dev (struct domain *d,u8 devfn,struct device *dev,u32 flag) {@@ -2600,17 +2620,8 @@ static int arm_smmu_assign_dev(struct domain *d, u8 devfn, xen_domain =dom_iommu (d)->arch.priv; -if (!dev->archdata.iommu) { - dev->archdata.iommu = xzalloc(struct arm_smmu_xen_device); -if (!dev->archdata.iommu) -return -ENOMEM ; - } - -if (!dev_iommu_group (dev)) { - ret =arm_smmu_add_device (dev); -if (ret) -return ret; - } +if (!dev_iommu_group (dev)) +return -ENODEV ;spin_lock (&xen_domain->lock);@@ -2784,6 +2795,7 @@ static const struct iommu_ops arm_smmu_iommu_ops = { .teardown = arm_smmu_iommu_domain_teardown, .iotlb_flush = arm_smmu_iotlb_flush, .iotlb_flush_all = arm_smmu_iotlb_flush_all, + .add_device = arm_smmu_xen_add_device, .assign_device = arm_smmu_assign_dev, .reassign_device = arm_smmu_reassign_dev, .map_page = arm_smmu_map_page,Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 1/7] xen/arm: SMMU: Implement the add_device callback in SMMU
Hi Stefano,
Quoted 50 lines
-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 2017年7月4日 5:58
To: Wei Chen <[email protected]>
Cc: [email protected]; [email protected]; Steve Capper <[email protected]>; Kaly Xin <[email protected]>; Julien Grall <[email protected]>; nd <[email protected]>
Subject: Re: [Xen-devel] [PATCH 1/7] xen/arm: SMMU: Implement theadd_devicecallback in SMMUQuoted 14 lines · Wei Chen
This
add_devicecallback function is taking care of adding a device to SMMU and make sure it is fully prepare to be used by the SMMU afterwards.In previous code, we don't implement the
add_devicecallback iniommu_opsfor ARM SMMU. We placed the work ofadd_devicetoassign_devicecallback. The functionassign_deviceshould not care about adding the device to aniommu_group. It might not even be able to decide how to do that. In this patch, we move this work back toadd_devicecallback.This
add_devicecallback is only called while we are handling all devices for constructing the Domain0.Review
Quoted 6 lines
Signed-off-by Wei Chen <[email protected]>--- xen/drivers/passthrough/arm/smmu.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)(quoted diff) +0
-0
b/xen/drivers/passthrough/arm/smmu.cxen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct
Quoted 4 lines
index 74c09b0..2efa52d 100644
xen/drivers/passthrough/arm/smmu.c +0
-0@@ -2591,6 +2591,26 @@ static void arm_smmu_destroy_iommu_domain(struct
iommu_domain*domain)Quoted 13 lines
xen/drivers/passthrough/arm/smmu.c +10
-0xfree (domain); } +static int arm_smmu_xen_add_device (u8 devfn,struct device *dev) +{ +if (dt_device_is_protected (dev->of_node)) { +if (!dev->archdata.iommu) { + dev->archdata.iommu = xzalloc(struct arm_smmu_xen_device); +if (!dev->archdata.iommu) +return -ENOMEM ; + } + +if (!dev_iommu_group (dev))
Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain) · line 2609
Quoted 6 lines
xen/drivers/passthrough/arm/smmu.c +6
-0+return arm_smmu_add_device (dev); + } + +/* +* Return 0 if the device is not protected to follow the behavior +* of PCI add device. What does this comment mean?
While I was looking at the iommu_add_device which is used by PCI counterpart. I found it will always return 0 even for device that are not protected by an IOMMU. I would much prefer to keep platform devices have similar behavior as PCI devices.
So while I was implementing iommu_add_dt_device and arm_smmu_xen_add_device, I returned 0 if the device is not protected by IOMMU.
Quoted 41 lines
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_assign_dev(struct domain *d, u8
Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c +4
-0+*/ +return 0 ; +} +static int arm_smmu_assign_dev (struct domain *d,u8 devfn,struct device *dev,u32 flag) {@@ -2600,17 +2620,8 @@ static int arm_smmu_assign_dev(struct domain *d, u8devfn,
Quoted 31 lines
xen/drivers/passthrough/arm/smmu.c +3
-12xen_domain =dom_iommu (d)->arch.priv; -if (!dev->archdata.iommu) { - dev->archdata.iommu = xzalloc(struct arm_smmu_xen_device); -if (!dev->archdata.iommu) -return -ENOMEM ; - } - -if (!dev_iommu_group (dev)) { - ret =arm_smmu_add_device (dev); -if (ret) -return ret; - } +if (!dev_iommu_group (dev)) +return -ENODEV ;spin_lock (&xen_domain->lock);@@ -2784,6 +2795,7 @@ static const struct iommu_ops arm_smmu_iommu_ops = { .teardown = arm_smmu_iommu_domain_teardown, .iotlb_flush = arm_smmu_iotlb_flush, .iotlb_flush_all = arm_smmu_iotlb_flush_all, + .add_device = arm_smmu_xen_add_device, .assign_device = arm_smmu_assign_dev, .reassign_device = arm_smmu_reassign_dev, .map_page = arm_smmu_map_page, --2.7.4
Quoted 5 lines
Quoted 5 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 1/7] xen/arm: SMMU: Implement the add_device callback in SMMU
Quoted 62 lines · Wei Chen
Hi Stefano,
Quoted 50 lines
-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 2017年7月4日 5:58
To: Wei Chen <[email protected]>
Cc: [email protected]; [email protected]; Steve Capper <[email protected]>; Kaly Xin <[email protected]>; Julien Grall <[email protected]>; nd <[email protected]>
Subject: Re: [Xen-devel] [PATCH 1/7] xen/arm: SMMU: Implement theadd_devicecallback in SMMUQuoted 14 lines · Wei Chen
This
add_devicecallback function is taking care of adding a device to SMMU and make sure it is fully prepare to be used by the SMMU afterwards.In previous code, we don't implement the
add_devicecallback iniommu_opsfor ARM SMMU. We placed the work ofadd_devicetoassign_devicecallback. The functionassign_deviceshould not care about adding the device to aniommu_group. It might not even be able to decide how to do that. In this patch, we move this work back toadd_devicecallback.This
add_devicecallback is only called while we are handling all devices for constructing the Domain0.Review
Quoted 6 lines
Signed-off-by Wei Chen <[email protected]>--- xen/drivers/passthrough/arm/smmu.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)(quoted diff) +0
-0
b/xen/drivers/passthrough/arm/smmu.cxen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct
Quoted 4 lines
index 74c09b0..2efa52d 100644
xen/drivers/passthrough/arm/smmu.c +0
-0@@ -2591,6 +2591,26 @@ static void arm_smmu_destroy_iommu_domain(struct
iommu_domain*domain)Quoted 13 lines
xen/drivers/passthrough/arm/smmu.c +10
-0xfree (domain); } +static int arm_smmu_xen_add_device (u8 devfn,struct device *dev) +{ +if (dt_device_is_protected (dev->of_node)) { +if (!dev->archdata.iommu) { + dev->archdata.iommu = xzalloc(struct arm_smmu_xen_device); +if (!dev->archdata.iommu) +return -ENOMEM ; + } + +if (!dev_iommu_group (dev))Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain) · line 2609
Quoted 6 lines
xen/drivers/passthrough/arm/smmu.c +6
-0+return arm_smmu_add_device (dev); + } + +/* +* Return 0 if the device is not protected to follow the behavior +* of PCI add device. What does this comment mean?
Quoted 6 lines
While I was looking at the
iommu_add_devicewhich is used by PCI counterpart. I found it will always return 0 even for device that are not protected by an IOMMU. I would much prefer to keep platform devices have similar behavior as PCI devices.So while I was implementing
iommu_add_dt_deviceandarm_smmu_xen_add_device, I returned 0 if the device is not protected by IOMMU.
I understand now. Please rephrase to:
"Return 0 (not an error) if the device is not protected by an SMMU, to match the behavior of iommu_add_device."
Quoted 41 lines
Quoted 41 lines
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_assign_dev(struct domain *d, u8
Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c +4
-0+*/ +return 0 ; +} +static int arm_smmu_assign_dev (struct domain *d,u8 devfn,struct device *dev,u32 flag) {@@ -2600,17 +2620,8 @@ static int arm_smmu_assign_dev(struct domain *d, u8devfn,
Quoted 31 lines
xen/drivers/passthrough/arm/smmu.c +3
-12xen_domain =dom_iommu (d)->arch.priv; -if (!dev->archdata.iommu) { - dev->archdata.iommu = xzalloc(struct arm_smmu_xen_device); -if (!dev->archdata.iommu) -return -ENOMEM ; - } - -if (!dev_iommu_group (dev)) { - ret =arm_smmu_add_device (dev); -if (ret) -return ret; - } +if (!dev_iommu_group (dev)) +return -ENODEV ;spin_lock (&xen_domain->lock);@@ -2784,6 +2795,7 @@ static const struct iommu_ops arm_smmu_iommu_ops = { .teardown = arm_smmu_iommu_domain_teardown, .iotlb_flush = arm_smmu_iotlb_flush, .iotlb_flush_all = arm_smmu_iotlb_flush_all, + .add_device = arm_smmu_xen_add_device, .assign_device = arm_smmu_assign_dev, .reassign_device = arm_smmu_reassign_dev, .map_page = arm_smmu_map_page, --2.7.4
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 1/7] xen/arm: SMMU: Implement the add_device callback in SMMU
Quoted 84 lines
-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 2017年7月6日 1:58
To: Wei Chen <[email protected]>
Cc: Stefano Stabellini <[email protected]>; [email protected]; Steve Capper <[email protected]>; Kaly Xin <[email protected]>; Julien Grall <[email protected]>; nd <[email protected]>
Subject: RE: [Xen-devel] [PATCH 1/7] xen/arm: SMMU: Implement theadd_devicecallback in SMMUQuoted 10 lines · Wei Chen
Hi Stefano,
Quoted 8 lines
-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 2017年7月4日 5:58
To: Wei Chen <[email protected]>
Cc: [email protected]; [email protected]; Steve Capper <[email protected]>; Kaly Xin <[email protected]>; Julien Grall <[email protected]>; nd <[email protected]>
Subject: Re: [Xen-devel] [PATCH 1/7] xen/arm: SMMU: Implement the
add_deviceQuoted 14 lines
Quoted 14 lines
callback in SMMU
Quoted 11 lines · Wei Chen
This
add_devicecallback function is taking care of adding a device to SMMU and make sure it is fully prepare to be used by the SMMU afterwards.In previous code, we don't implement the
add_devicecallback iniommu_opsfor ARM SMMU. We placed the work ofadd_devicetoassign_devicecallback. The functionassign_deviceshould not care about adding the device to aniommu_group. It might not even be able to decide how to do that. In this patch, we move this work back toadd_devicecallback.Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
This
add_devicecallback is only called while we are handling all devices for constructing the Domain0.Signed-off-by Wei Chen <[email protected]>--- xen/drivers/passthrough/arm/smmu.c | 34 +++++++++++++++++++++++-----------
Quoted 9 lines
Quoted 9 lines
Review
Quoted 3 lines
1 file changed, 23 insertions(+), 11 deletions(-)(quoted diff) +0
-0
b/xen/drivers/passthrough/arm/smmu.cxen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct
Quoted 4 lines
index 74c09b0..2efa52d 100644
xen/drivers/passthrough/arm/smmu.c +0
-0@@ -2591,6 +2591,26 @@ static void arm_smmu_destroy_iommu_domain(struct
iommu_domain*domain)Quoted 8 lines
Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)
Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c +5
-0xfree (domain); } +static int arm_smmu_xen_add_device (u8 devfn,struct device *dev) +{ +if (dt_device_is_protected (dev->of_node)) { +if (!dev->archdata.iommu) { + dev->archdata.iommu = xzalloc(struct
arm_smmu_xen_device);Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c +5
-0+if (!dev->archdata.iommu) +return -ENOMEM ; + } + +if (!dev_iommu_group (dev))Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain) · line 2609
Quoted 6 lines
xen/drivers/passthrough/arm/smmu.c +6
-0+return arm_smmu_add_device (dev); + } + +/* +* Return 0 if the device is not protected to follow the behavior +* of PCI add device. What does this comment mean?
Quoted 2 lines
While I was looking at the
iommu_add_devicewhich is used by PCI counterpart. I found it will always return 0 even for device that are not protected by anIOMMU.
Quoted 1 line
I would much prefer to keep platform devices have similar behavior as PCI
devices.
Quoted 1 line
Quoted 9 lines
Quoted 1 line
So while I was implementing
iommu_add_dt_deviceandarm_smmu_xen_add_device,I
Quoted 1 line
returned 0 if the device is not protected by IOMMU.
I understand now. Please rephrase to:
"Return 0 (not an error) if the device is not protected by an SMMU, to match the behavior of
iommu_add_device."
Ok, I will do it in next version.
Quoted 29 lines
Quoted 10 lines
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_assign_dev(struct domain *d,
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c +4
-0+*/ +return 0 ; +} +static int arm_smmu_assign_dev (struct domain *d,u8 devfn,struct device *dev,u32 flag) {@@ -2600,17 +2620,8 @@ static int arm_smmu_assign_dev(struct domain *d,u8
Quoted 18 lines
Quoted 18 lines
devfn,
Quoted 17 lines
xen/drivers/passthrough/arm/smmu.c +2
-11xen_domain =dom_iommu (d)->arch.priv; -if (!dev->archdata.iommu) { - dev->archdata.iommu = xzalloc(struct arm_smmu_xen_device); -if (!dev->archdata.iommu) -return -ENOMEM ; - } - -if (!dev_iommu_group (dev)) { - ret =arm_smmu_add_device (dev); -if (ret) -return ret; - } +if (!dev_iommu_group (dev)) +return -ENODEV ;
Quoted 21 lines
Quoted 3 lines
Quoted 3 lines
xen/drivers/passthrough/arm/smmu.c static const struct iommu_ops arm_smmu_iommu_ops =
Quoted 3 lines
xen/drivers/passthrough/arm/smmu.c +0
-0spin_lock (&xen_domain->lock);@@ -2784,6 +2795,7 @@ static const struct iommu_ops arm_smmu_iommu_ops ={
Quoted 17 lines
Quoted 16 lines
Quoted 16 lines
xen/drivers/passthrough/arm/smmu.c +1
-1.teardown = arm_smmu_iommu_domain_teardown, .iotlb_flush = arm_smmu_iotlb_flush, .iotlb_flush_all = arm_smmu_iotlb_flush_all, + .add_device = arm_smmu_xen_add_device, .assign_device = arm_smmu_assign_dev, .reassign_device = arm_smmu_reassign_dev, .map_page = arm_smmu_map_page, --2.7.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 1/7] xen/arm: SMMU: Implement the add_device callback in SMMU
In reply to Wei ChenHi Wei,
Quoted 24 lines · Wei Chen
This
add_devicecallback function is taking care of adding a device to SMMU and make sure it is fully prepare to be used by the SMMU afterwards.In previous code, we don't implement the
add_devicecallback iniommu_opsfor ARM SMMU. We placed the work ofadd_devicetoassign_devicecallback. The functionassign_deviceshould not care about adding the device to aniommu_group. It might not even be able to decide how to do that. In this patch, we move this work back toadd_devicecallback.This
add_devicecallback is only called while we are handling all devices for constructing the Domain0.Signed-off-by Wei Chen <[email protected]>--- xen/drivers/passthrough/arm/smmu.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)xen/drivers/passthrough/arm/smmu.c +0
-0
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain) · line 2594
Quoted 4 lines
xen/drivers/passthrough/arm/smmu.c +1
-0@@ -2591,6 +2591,26 @@ static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)xfree (domain); } +static int arm_smmu_xen_add_device (u8 devfn,struct device *dev)
Coding style: struct device *dev
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 1/7] xen/arm: SMMU: Implement the add_device callback in SMMU
Hi Julien,
Quoted 38 lines
-----Original Message-----
From: Julien Grall [mailto:[email protected]]
Sent: 2017年7月4日 23:41
To: Wei Chen <[email protected]>; [email protected]
Cc: [email protected]; Steve Capper <[email protected]>; Kaly Xin <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 1/7] xen/arm: SMMU: Implement theadd_devicecallback in SMMUHi Wei,
Quoted 14 lines · Wei Chen
This
add_devicecallback function is taking care of adding a device to SMMU and make sure it is fully prepare to be used by the SMMU afterwards.In previous code, we don't implement the
add_devicecallback iniommu_opsfor ARM SMMU. We placed the work ofadd_devicetoassign_devicecallback. The functionassign_deviceshould not care about adding the device to aniommu_group. It might not even be able to decide how to do that. In this patch, we move this work back toadd_devicecallback.This
add_devicecallback is only called while we are handling all devices for constructing the Domain0.Review
Quoted 6 lines
Signed-off-by Wei Chen <[email protected]>--- xen/drivers/passthrough/arm/smmu.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)(quoted diff) +0
-0
b/xen/drivers/passthrough/arm/smmu.cxen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct
Quoted 4 lines
index 74c09b0..2efa52d 100644
xen/drivers/passthrough/arm/smmu.c +0
-0@@ -2591,6 +2591,26 @@ static void arm_smmu_destroy_iommu_domain(struct
iommu_domain*domain)
Quoted 7 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain) · line 2594
Quoted 4 lines
xen/drivers/passthrough/arm/smmu.c +1
-0xfree (domain); } +static int arm_smmu_xen_add_device (u8 devfn,struct device *dev)Coding style: struct device *dev
This is the second comment that I hadn't addressed. I will fix it. Thank you!
Quoted 4 lines
Cheers,
--
Julien Grall
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 2/7 xen/arm: SMMU: Introduce a helper to add DT device to SMMU
In reply to Wei ChenIn current code, we only have the iommu_add_device to add PCI device to IOMMU. But for ARM SMMU, we don't have a separate helper to add platform device with device tree to SMMU. This work was included in the iommu_assign_dt_device. But sometimes, we just want to add device to SMMU to do some preparation for further use. In this case, we can't call iommu_assign_dt_device.
In previous patch, we have implement the add_device callback for SMMU, so we can separate this work from assign_device now.
--- xen/drivers/passthrough/device_tree.c | 20 ++++++++++++++++++++ xen/include/xen/iommu.h | 1 + 2 files changed, 21 insertions(+)
xen/drivers/passthrough/device_tree.c +20 -0
@@ -24,6 +24,26 @@static spinlock_t dtdevs_lock =SPIN_LOCK_UNLOCKED ; +int iommu_add_dt_device (struct domain *d,struct dt_device_node *dev) +{ +int rc; + +struct domain_iommu *hd =dom_iommu (d); + +if ( !iommu_enabled || !hd->platform_ops || + !hd->platform_ops->add_device ) +return 0 ; + +spin_lock (&dtdevs_lock); + +/* The devfn field doesn't matter to DT device. */ + rc = hd->platform_ops->add_device (0 ,dt_to_dev (dev)); + +spin_unlock (&dtdevs_lock); + +return rc; +} +int iommu_assign_dt_device (struct domain *d,struct dt_device_node *dev) {int rc = -EBUSY ;
xen/include/xen/iommu.h +1 -0
@@ -132,6 +132,7 @@ void iommu_read_msi_from_ire(struct msi_desc *msi_desc, struct msi_msg *msg);#ifdef CONFIG_HAS_DEVICE_TREE #include <xen/device_tree.h> +int iommu_add_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_assign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_deassign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_dt_domain_init (struct domain *d);
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 2/7] xen/arm: SMMU: Introduce a helper to add DT device to SMMU
Quoted 23 lines · Wei Chen
In current code, we only have the
iommu_add_deviceto add PCI device to IOMMU. But for ARM SMMU, we don't have a separate helper to add platform device with device tree to SMMU. This work was included in theiommu_assign_dt_device. But sometimes, we just want to add device to SMMU to do some preparation for further use. In this case, we can't calliommu_assign_dt_device.In previous patch, we have implement the
add_devicecallback for SMMU, so we can separate this work fromassign_devicenow.Signed-off-by Wei Chen <[email protected]>--- xen/drivers/passthrough/device_tree.c | 20 ++++++++++++++++++++ xen/include/xen/iommu.h | 1 + 2 files changed, 21 insertions(+)xen/drivers/passthrough/device_tree.c +0
-0@@ -24,6 +24,26 @@static spinlock_t dtdevs_lock =SPIN_LOCK_UNLOCKED ;
xen/drivers/passthrough/device_tree.c line 35
Quoted 10 lines
xen/drivers/passthrough/device_tree.c +9
-0+int iommu_add_dt_device (struct domain *d,struct dt_device_node *dev) +{ +int rc; + +struct domain_iommu *hd =dom_iommu (d); + +if ( !iommu_enabled || !hd->platform_ops || + !hd->platform_ops->add_device ) +return 0 ;
Shouldn't we also have:
if ( !dt_device_is_protected(dev) )
return 0;
?
Quoted 34 lines
xen/drivers/passthrough/device_tree.c +10
-0+spin_lock (&dtdevs_lock); + +/* The devfn field doesn't matter to DT device. */ + rc = hd->platform_ops->add_device (0 ,dt_to_dev (dev)); + +spin_unlock (&dtdevs_lock); + +return rc; +} +int iommu_assign_dt_device (struct domain *d,struct dt_device_node *dev) {int rc = -EBUSY ;xen/include/xen/iommu.h +1
-0@@ -132,6 +132,7 @@ void iommu_read_msi_from_ire(struct msi_desc *msi_desc, struct msi_msg *msg);#ifdef CONFIG_HAS_DEVICE_TREE #include <xen/device_tree.h> +int iommu_add_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_assign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_deassign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_dt_domain_init (struct domain *d);Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 2/7] xen/arm: SMMU: Introduce a helper to add DT device to SMMU
Hi Stefano,
Quoted 48 lines
-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 2017年7月4日 6:03
To: Wei Chen <[email protected]>
Cc: [email protected]; [email protected]; Steve Capper <[email protected]>; Kaly Xin <[email protected]>; Julien Grall <[email protected]>; nd <[email protected]>
Subject: Re: [Xen-devel] [PATCH 2/7] xen/arm: SMMU: Introduce a helper to add DT device to SMMUQuoted 10 lines · Wei Chen
In current code, we only have the
iommu_add_deviceto add PCI device to IOMMU. But for ARM SMMU, we don't have a separate helper to add platform device with device tree to SMMU. This work was included in theiommu_assign_dt_device. But sometimes, we just want to add device to SMMU to do some preparation for further use. In this case, we can't calliommu_assign_dt_device.In previous patch, we have implement the
add_devicecallback for SMMU, so we can separate this work fromassign_devicenow.Review
Quoted 7 lines
Signed-off-by Wei Chen <[email protected]>--- xen/drivers/passthrough/device_tree.c | 20 ++++++++++++++++++++ xen/include/xen/iommu.h | 1 + 2 files changed, 21 insertions(+)(quoted diff) +0
-0
b/xen/drivers/passthrough/device_tree.cQuoted 6 lines
index 99ed49e..a8f403a 100644
xen/drivers/passthrough/device_tree.c +0
-0@@ -24,6 +24,26 @@static spinlock_t dtdevs_lock =SPIN_LOCK_UNLOCKED ;xen/drivers/passthrough/device_tree.c line 35
Quoted 10 lines
xen/drivers/passthrough/device_tree.c +9
-0+int iommu_add_dt_device (struct domain *d,struct dt_device_node *dev) +{ +int rc; + +struct domain_iommu *hd =dom_iommu (d); + +if ( !iommu_enabled || !hd->platform_ops || + !hd->platform_ops->add_device ) +return 0 ;Shouldn't we also have:
Quoted 5 lines
if ( !dt_device_is_protected(dev) )
return 0;?
When we're using the legacy binding, the master IDs will be registered to SMMU and the protected flag of relevant master devices will be set to true (dt_device_is_protected will return true). But for generic IOMMU bindings, before we call ops->add_device, we didn't register the master device's master id to SMMU and hadn't set the protected flag, The dt_device_is_protected will always return false.
In this case, we can't call dt_device_is_protected(dev) here.
Quoted 12 lines
Quoted 12 lines
xen/drivers/passthrough/device_tree.c +10
-0+spin_lock (&dtdevs_lock); + +/* The devfn field doesn't matter to DT device. */ + rc = hd->platform_ops->add_device (0 ,dt_to_dev (dev)); + +spin_unlock (&dtdevs_lock); + +return rc; +} +int iommu_assign_dt_device (struct domain *d,struct dt_device_node *dev)
Quoted 24 lines
xen/include/xen/iommu.h void iommu_read_msi_from_ire(struct msi_desc *msi_desc,
Quoted 7 lines
xen/drivers/passthrough/device_tree.c +0
-0{int rc = -EBUSY ;xen/include/xen/iommu.h +0
-0@@ -132,6 +132,7 @@ void iommu_read_msi_from_ire(struct msi_desc *msi_desc,struct
msi_msg*msg);Quoted 16 lines
xen/include/xen/iommu.h +1
-1#ifdef CONFIG_HAS_DEVICE_TREE #include <xen/device_tree.h> +int iommu_add_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_assign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_deassign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_dt_domain_init (struct domain *d); --2.7.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 2/7] xen/arm: SMMU: Introduce a helper to add DT device to SMMU
Quoted 56 lines · Wei Chen
Hi Stefano,
Quoted 48 lines
-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 2017年7月4日 6:03
To: Wei Chen <[email protected]>
Cc: [email protected]; [email protected]; Steve Capper <[email protected]>; Kaly Xin <[email protected]>; Julien Grall <[email protected]>; nd <[email protected]>
Subject: Re: [Xen-devel] [PATCH 2/7] xen/arm: SMMU: Introduce a helper to add DT device to SMMUQuoted 10 lines · Wei Chen
In current code, we only have the
iommu_add_deviceto add PCI device to IOMMU. But for ARM SMMU, we don't have a separate helper to add platform device with device tree to SMMU. This work was included in theiommu_assign_dt_device. But sometimes, we just want to add device to SMMU to do some preparation for further use. In this case, we can't calliommu_assign_dt_device.In previous patch, we have implement the
add_devicecallback for SMMU, so we can separate this work fromassign_devicenow.Review
Quoted 7 lines
Signed-off-by Wei Chen <[email protected]>--- xen/drivers/passthrough/device_tree.c | 20 ++++++++++++++++++++ xen/include/xen/iommu.h | 1 + 2 files changed, 21 insertions(+)(quoted diff) +0
-0
b/xen/drivers/passthrough/device_tree.cQuoted 6 lines
index 99ed49e..a8f403a 100644
xen/drivers/passthrough/device_tree.c +0
-0@@ -24,6 +24,26 @@static spinlock_t dtdevs_lock =SPIN_LOCK_UNLOCKED ;xen/drivers/passthrough/device_tree.c line 35
Quoted 10 lines
xen/drivers/passthrough/device_tree.c +9
-0+int iommu_add_dt_device (struct domain *d,struct dt_device_node *dev) +{ +int rc; + +struct domain_iommu *hd =dom_iommu (d); + +if ( !iommu_enabled || !hd->platform_ops || + !hd->platform_ops->add_device ) +return 0 ;Shouldn't we also have:
Quoted 5 lines
if ( !dt_device_is_protected(dev) )
return 0;?
Quoted 7 lines
When we're using the legacy binding, the master IDs will be registered to SMMU and the protected flag of relevant master devices will be set to true (
dt_device_is_protectedwill return true). But for generic IOMMU bindings, before we callops->add_device, we didn't register the master device's master id to SMMU and hadn't set the protected flag, Thedt_device_is_protectedwill always return false.In this case, we can't call
dt_device_is_protected(dev)here.
I get it. Please add an in-code comment here to explain the situation.
Quoted 37 lines
Quoted 12 lines
Quoted 12 lines
xen/drivers/passthrough/device_tree.c +10
-0+spin_lock (&dtdevs_lock); + +/* The devfn field doesn't matter to DT device. */ + rc = hd->platform_ops->add_device (0 ,dt_to_dev (dev)); + +spin_unlock (&dtdevs_lock); + +return rc; +} +int iommu_assign_dt_device (struct domain *d,struct dt_device_node *dev)Quoted 24 lines
xen/include/xen/iommu.h void iommu_read_msi_from_ire(struct msi_desc *msi_desc,
Quoted 7 lines
xen/drivers/passthrough/device_tree.c +0
-0{int rc = -EBUSY ;xen/include/xen/iommu.h +0
-0@@ -132,6 +132,7 @@ void iommu_read_msi_from_ire(struct msi_desc *msi_desc,struct
msi_msg*msg);Quoted 16 lines
xen/include/xen/iommu.h +1
-1#ifdef CONFIG_HAS_DEVICE_TREE #include <xen/device_tree.h> +int iommu_add_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_assign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_deassign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_dt_domain_init (struct domain *d); --2.7.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 5 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 2/7] xen/arm: SMMU: Introduce a helper to add DT device to SMMU
Quoted 77 lines
-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 2017年7月6日 2:02
To: Wei Chen <[email protected]>
Cc: Stefano Stabellini <[email protected]>; Kaly Xin <[email protected]>; Julien Grall <[email protected]>; Steve Capper <[email protected]>; nd <[email protected]>; [email protected]
Subject: Re: [Xen-devel] [PATCH 2/7] xen/arm: SMMU: Introduce a helper to add DT device to SMMUQuoted 10 lines · Wei Chen
Hi Stefano,
Quoted 8 lines
-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 2017年7月4日 6:03
To: Wei Chen <[email protected]>
Cc: [email protected]; [email protected]; Steve Capper <[email protected]>; Kaly Xin <[email protected]>; Julien Grall <[email protected]>; nd <[email protected]>
Subject: Re: [Xen-devel] [PATCH 2/7] xen/arm: SMMU: Introduce a helper toadd
Quoted 40 lines
Quoted 40 lines
DT device to SMMU
Quoted 10 lines · Wei Chen
In current code, we only have the
iommu_add_deviceto add PCI device to IOMMU. But for ARM SMMU, we don't have a separate helper to add platform device with device tree to SMMU. This work was included in theiommu_assign_dt_device. But sometimes, we just want to add device to SMMU to do some preparation for further use. In this case, we can't calliommu_assign_dt_device.In previous patch, we have implement the
add_devicecallback for SMMU, so we can separate this work fromassign_devicenow.Review
Quoted 7 lines
Signed-off-by Wei Chen <[email protected]>--- xen/drivers/passthrough/device_tree.c | 20 ++++++++++++++++++++ xen/include/xen/iommu.h | 1 + 2 files changed, 21 insertions(+)(quoted diff) +0
-0
b/xen/drivers/passthrough/device_tree.cQuoted 6 lines
index 99ed49e..a8f403a 100644
xen/drivers/passthrough/device_tree.c +0
-0@@ -24,6 +24,26 @@static spinlock_t dtdevs_lock =SPIN_LOCK_UNLOCKED ;xen/drivers/passthrough/device_tree.c line 35
Quoted 10 lines
xen/drivers/passthrough/device_tree.c +9
-0+int iommu_add_dt_device (struct domain *d,struct dt_device_node *dev) +{ +int rc; + +struct domain_iommu *hd =dom_iommu (d); + +if ( !iommu_enabled || !hd->platform_ops || + !hd->platform_ops->add_device ) +return 0 ;Shouldn't we also have:
Quoted 7 lines
Quoted 5 lines
if ( !dt_device_is_protected(dev) )
return 0;?
When we're using the legacy binding, the master IDs will be registered to
SMMU and
Quoted 1 line
the protected flag of relevant master devices will be set to true
(
dt_device_is_protectedQuoted 3 lines
will return true). But for generic IOMMU bindings, before we call ops-
add_device,
we didn't register the master device's master id to SMMU and hadn't set the
Quoted 7 lines
protected
Quoted 3 lines
flag, The
dt_device_is_protectedwill always return false.In this case, we can't call
dt_device_is_protected(dev)here.I get it. Please add an in-code comment here to explain the situation.
Ok, I will do it.
Quoted 22 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
xen/drivers/passthrough/device_tree.c +10
-0+spin_lock (&dtdevs_lock); + +/* The devfn field doesn't matter to DT device. */ + rc = hd->platform_ops->add_device (0 ,dt_to_dev (dev)); + +spin_unlock (&dtdevs_lock); + +return rc; +} +Quoted 8 lines
Quoted 8 lines
xen/include/xen/iommu.h void iommu_read_msi_from_ire(struct msi_desc
Quoted 8 lines
xen/drivers/passthrough/device_tree.c +0
-0int iommu_assign_dt_device (struct domain *d,struct dt_device_node *dev) {int rc = -EBUSY ;xen/include/xen/iommu.h +0
-0@@ -132,6 +132,7 @@ void iommu_read_msi_from_ire(struct msi_desc
*msi_desc,Quoted 1 line
Quoted 1 line
struct
msi_msg*msg);
Quoted 24 lines
Quoted 5 lines
Quoted 5 lines
xen/include/xen/iommu.h void iommu_read_msi_from_ire(struct msi_desc *msi_desc, struct msi_msg *msg);
Quoted 5 lines
xen/include/xen/iommu.h +1
-0#ifdef CONFIG_HAS_DEVICE_TREE #include <xen/device_tree.h> +int iommu_add_dt_device (struct domain *d,struct dt_device_node *dev); int iommu_assign_dt_device(struct domain *d, struct dt_device_node*dev);
Quoted 1 line
Quoted 1 line
xen/include/xen/iommu.h void iommu_read_msi_from_ire(struct msi_desc · line 137
Quoted 1 line
xen/include/xen/iommu.h +0
-0int iommu_deassign_dt_device(struct domain *d, struct dt_device_node*dev);
Quoted 16 lines
Quoted 10 lines
Quoted 10 lines
xen/include/xen/iommu.h +0
-1int iommu_dt_domain_init (struct domain *d); --2.7.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 3/7 xen/arm: Prepare SMMU resources for protected devices
In reply to Wei ChenIn previous code, while we are constructing Dom0, we will assign all devices except passthrough devices to Dom0. In the later, when we start the DomU, the assign_device will prepare SMMU resources for the devices passthrough to DomU. This is ok when we kept the add_device code in assign_device. But currently, we have separated add_device from assign_device. If we don't prepare SMMU resources for passthrough devices, these devices would not work properly in DomU.
So, while we are handling all devices DT node in construction Dom0, we will call add_device to prepare SMMU resources for all protected devices, regardless of passthrough or not.
--- xen/arch/arm/domain_build.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
xen/arch/arm/domain_build.c +12 -0
@@ -1082,6 +1082,18 @@ static int handle_device(struct domain *d, struct dt_device_node *dev,dt_dprintk ("%s passthrough = %d nirq = %d naddr = %u\n" ,dt_node_full_name (dev), need_mapping, nirq, naddr); +/* +* If this device is behind the SMMU, the add_device callback will +* prepare resource for it. Otherwise, add_device has no effect. +*/ + res =iommu_add_dt_device (d, dev); +if ( res ) + { +printk (XENLOG_ERR "Failed to add device to IOMMU for %s\n" , +dt_node_full_name (dev)); +return res; + } +if (dt_device_is_protected (dev) && need_mapping ) {dt_dprintk ("%s setup iommu\n" ,dt_node_full_name (dev));
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 3/7] xen/arm: Prepare SMMU resources for protected devices
Quoted 9 lines · Wei Chen
In previous code, while we are constructing Dom0, we will assign all devices except passthrough devices to Dom0. In the later, when we start the DomU, the
assign_devicewill prepare SMMU resources for the devices passthrough to DomU. This is ok when we kept theadd_devicecode inassign_device. But currently, we have separatedadd_devicefromassign_device. If we don't prepare SMMU resources for passthrough devices, these devices would not work properly in DomU.
Quoted 5 lines
So, while we are handling all devices DT node in construction Dom0, we will call
add_deviceto prepare SMMU resources for all protected devices, regardless of passthrough or not.Signed-off-by Wei Chen <[email protected]>
Quoted 36 lines
--- xen/arch/arm/domain_build.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)xen/arch/arm/domain_build.c +12
-0@@ -1082,6 +1082,18 @@ static int handle_device(struct domain *d, struct dt_device_node *dev,dt_dprintk ("%s passthrough = %d nirq = %d naddr = %u\n" ,dt_node_full_name (dev), need_mapping, nirq, naddr); +/* +* If this device is behind the SMMU, the add_device callback will +* prepare resource for it. Otherwise, add_device has no effect. +*/ + res =iommu_add_dt_device (d, dev); +if ( res ) + { +printk (XENLOG_ERR "Failed to add device to IOMMU for %s\n" , +dt_node_full_name (dev)); +return res; + } +if (dt_device_is_protected (dev) && need_mapping ) {dt_dprintk ("%s setup iommu\n" ,dt_node_full_name (dev));Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 4/7 xen/arm: SMMU: Detect types of device tree binding
In reply to Wei ChenThe device tree provides two types of IOMMU bindings, one is legacy another is generic. The legacy bindings will be depercated in favour of the generic bindings. But in the transitional period, we have to support both of them.
The codes to handle these two types of bindings are very differnet, so we have to detect the binding types while doing SMMU probing.
This detect code is based on Linux ARM SMMUv2 driver:
https://github.com/torvalds/linux/blob/master/drivers/iommu/arm-smmu.c
--- xen/drivers/passthrough/arm/smmu.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
xen/drivers/passthrough/arm/smmu.c +23 -0
@@ -143,6 +143,8 @@ typedef enum irqreturn irqreturn_t;#define dev_name (dev) dt_node_full_name(dev_to_dt(dev)) +#define pr_notice (fmt, ...) printk(XENLOG_INFO fmt, ## __VA_ARGS__) +/* Alias to Xen allocation helpers */ #define kfree xfree#define kmalloc (size, flags) _xmalloc(size, sizeof(void *))
@@ -681,6 +683,8 @@ struct arm_smmu_option_prop {const char *prop; }; +static bool using_legacy_binding, using_generic_binding; +static struct arm_smmu_option_prop arm_smmu_options[] = { {ARM_SMMU_OPT_SECURE_CFG_ACCESS ,"calxeda,smmu-secure-config-access" }, {0 ,NULL },
@@ -2289,6 +2293,25 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev)struct rb_node *node;struct of_phandle_args masterspec;int num_irqs, i, err; +bool legacy_binding; + +/* +* Xen: Do the same check as Linux. Checking the SMMU device tree bindings +* are either using generic or legacy one. +* +* The "mmu-masters" property is only existed in legacy bindings. +*/ + legacy_binding =dt_find_property (dev->of_node,"mmu-masters" ,NULL ); +if (legacy_binding && !using_generic_binding) { +if (!using_legacy_binding) +pr_notice ("deprecated \"mmu-masters\" DT property in use\n" ); + using_legacy_binding = true; + }else if (!legacy_binding && !using_legacy_binding) { + using_generic_binding = true; + }else { +dev_err (dev,"not probing due to mismatched DT properties\n" ); +return -ENODEV ; + } smmu =devm_kzalloc (dev,sizeof (*smmu),GFP_KERNEL );if (!smmu) {
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 4/7] xen/arm: SMMU: Detect types of device tree binding
Quoted 2 lines · Wei Chen
The device tree provides two types of IOMMU bindings, one is legacy another is generic. The legacy bindings will be depercated in favour
^ deprecated
Quoted 4 lines
of the generic bindings. But in the transitional period, we have to support both of them.
The codes to handle these two types of bindings are very differnet,
^ code ^ different
Please use a spellchecker.
Quoted 24 lines
so we have to detect the binding types while doing SMMU probing.
This detect code is based on Linux ARM SMMUv2 driver:
https://github.com/torvalds/linux/blob/master/drivers/iommu/arm-smmu.cSigned-off-by Wei Chen <[email protected]>--- xen/drivers/passthrough/arm/smmu.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)xen/drivers/passthrough/arm/smmu.c +2
-0@@ -143,6 +143,8 @@ typedef enum irqreturn irqreturn_t;#define dev_name (dev) dt_node_full_name(dev_to_dt(dev)) +#define pr_notice (fmt, ...) printk(XENLOG_INFO fmt, ## __VA_ARGS__) +/* Alias to Xen allocation helpers */ #define kfree xfree#define kmalloc (size, flags) _xmalloc(size, sizeof(void *))
xen/drivers/passthrough/arm/smmu.c struct arm_smmu_option_prop { · line 686
Quoted 4 lines
xen/drivers/passthrough/arm/smmu.c +1
-0@@ -681,6 +683,8 @@ struct arm_smmu_option_prop {const char *prop; }; +static bool using_legacy_binding, using_generic_binding;
__initdata?
But why do these two variables need to be static? Can't they just be local variables in arm_smmu_device_dt_probe?
Is it to enforce that all smmus on a given platform are either using the legacy or the generic bindings, but not a mix of the two? If so, it should be clearly written. Also, I am not sure we should really be checking for that. It seems to me that one smmu could be using generic bindings and another could be using legacy bindings. Is it specified anywhere that it cannot be the case?
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct platform_device *pdev) · line 2299
Quoted 11 lines
xen/drivers/passthrough/arm/smmu.c +4
-0static struct arm_smmu_option_prop arm_smmu_options[] = { {ARM_SMMU_OPT_SECURE_CFG_ACCESS ,"calxeda,smmu-secure-config-access" }, {0 ,NULL },@@ -2289,6 +2293,25 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev)struct rb_node *node;struct of_phandle_args masterspec;int num_irqs, i, err; +bool legacy_binding; + +/* +* Xen: Do the same check as Linux. Checking the SMMU device tree bindings
^ do ^ Check that
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct platform_device *pdev) · line 2300
Quoted 1 line
xen/drivers/passthrough/arm/smmu.c +1
-0+* are either using generic or legacy one.
^ bindings
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct platform_device *pdev) · line 2302
Quoted 2 lines
xen/drivers/passthrough/arm/smmu.c +2
-0+* +* The "mmu-masters" property is only existed in legacy bindings.
^ only exists in the legacy bindings
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct platform_device *pdev) · line 2310
Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c +8
-0+*/ + legacy_binding =dt_find_property (dev->of_node,"mmu-masters" ,NULL ); +if (legacy_binding && !using_generic_binding) { +if (!using_legacy_binding) +pr_notice ("deprecated \"mmu-masters\" DT property in use\n" ); + using_legacy_binding = true; + }else if (!legacy_binding && !using_legacy_binding) { + using_generic_binding = true;
Please simplify this series of if/else.
Quoted 19 lines
xen/drivers/passthrough/arm/smmu.c +4
-0+ }else { +dev_err (dev,"not probing due to mismatched DT properties\n" ); +return -ENODEV ; + }xen/drivers/passthrough/arm/smmu.c +0
-0smmu =devm_kzalloc (dev,sizeof (*smmu),GFP_KERNEL );if (!smmu) {Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 4/7] xen/arm: SMMU: Detect types of device tree binding
Hi Stefano,
Quoted 15 lines
-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 2017年7月4日 6:30
To: Wei Chen <[email protected]>
Cc: [email protected]; [email protected]; Steve Capper <[email protected]>; Kaly Xin <[email protected]>; Julien Grall <[email protected]>; nd <[email protected]>
Subject: Re: [Xen-devel] [PATCH 4/7] xen/arm: SMMU: Detect types of device tree bindingQuoted 2 lines · Wei Chen
The device tree provides two types of IOMMU bindings, one is legacy another is generic. The legacy bindings will be depercated in favour
^ deprecated
Quoted 7 lines
Quoted 4 lines
of the generic bindings. But in the transitional period, we have to support both of them.
The codes to handle these two types of bindings are very differnet,
^ code ^ different
Please use a spellchecker.
Thanks, I will fix them.
Quoted 29 lines
Quoted 6 lines
so we have to detect the binding types while doing SMMU probing.
This detect code is based on Linux ARM SMMUv2 driver:
https://github.com/torvalds/linux/blob/master/drivers/iommu/arm-smmu.cReview
Quoted 6 lines
Signed-off-by Wei Chen <[email protected]>--- xen/drivers/passthrough/arm/smmu.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)(quoted diff) +0
-0
b/xen/drivers/passthrough/arm/smmu.cQuoted 16 lines
index 2efa52d..441c296 100644
xen/drivers/passthrough/arm/smmu.c +2
-0@@ -143,6 +143,8 @@ typedef enum irqreturn irqreturn_t;#define dev_name (dev) dt_node_full_name(dev_to_dt(dev)) +#define pr_notice (fmt, ...) printk(XENLOG_INFO fmt, ## __VA_ARGS__) +/* Alias to Xen allocation helpers */ #define kfree xfree#define kmalloc (size, flags) _xmalloc(size, sizeof(void *))@@ -681,6 +683,8 @@ struct arm_smmu_option_prop {const char *prop; };
Quoted 4 lines
xen/drivers/passthrough/arm/smmu.c struct arm_smmu_option_prop { · line 686
Quoted 1 line
xen/drivers/passthrough/arm/smmu.c +1
-0+static bool using_legacy_binding, using_generic_binding;
__initdata?
I think these two variables are not only used in initialization. They also have been used in ops->add_device. Althrough the add_device is only be invoked while construct_dom0.
Quoted 6 lines
But why do these two variables need to be static? Can't they just be local variables in
arm_smmu_device_dt_probe?Is it to enforce that all smmus on a given platform are either using the legacy or the generic bindings, but not a mix of the two? If so, it should be clearly written. Also, I am not sure we should really be
Yes, this checking will enforce all smmus are using the same bindings.
Quoted 4 lines
checking for that. It seems to me that one smmu could be using generic bindings and another could be using legacy bindings. Is it specified anywhere that it cannot be the case?
In theory, different SMMUs can use different bindings. About this concern, I have discussed with Robin Murphy and Julien. We have three reasons:
The first is that, we ported this checking from Linux, we are trying to keep the code very close to the Linux driver. To ease backporting changes.
The second is that, we think it is a good change to try to phase out the legacy binding and request to use generic bindings everywhere if you start to use in one SMMU.
The other less technical reason for not supporting both at once is that anyone who can update their DT to add or update SMMUs with the new binding has no good excuse for not updating the whole lot. It's the likes of Seattle and ThunderX boxes with firmware that won't get updated for which we have to preserve "mmu-masters" support.
Quoted 17 lines
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c +0
-0static struct arm_smmu_option_prop arm_smmu_options[] = { {ARM_SMMU_OPT_SECURE_CFG_ACCESS ,"calxeda,smmu-secure-config-access" }, {0 ,NULL },@@ -2289,6 +2293,25 @@ static int arm_smmu_device_dt_probe(struct
platform_device*pdev)xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct platform_device *pdev)
Quoted 7 lines
xen/drivers/passthrough/arm/smmu.c +4
-0struct rb_node *node;struct of_phandle_args masterspec;int num_irqs, i, err; +bool legacy_binding; + +/* +* Xen: Do the same check as Linux. Checking the SMMU device tree bindings
^ do ^ Check that
Quoted 7 lines
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct platform_device *pdev) · line 2300
Quoted 1 line
xen/drivers/passthrough/arm/smmu.c +1
-0+* are either using generic or legacy one. ^ bindings
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct platform_device *pdev) · line 2302
Quoted 2 lines
xen/drivers/passthrough/arm/smmu.c +2
-0+* +* The "mmu-masters" property is only existed in legacy bindings. ^ only exists in the legacy bindings
Thanks, I will fix above typos.
Quoted 11 lines
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct platform_device *pdev) · line 2310
Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c +8
-0+*/ + legacy_binding =dt_find_property (dev->of_node,"mmu-masters" ,NULL ); +if (legacy_binding && !using_generic_binding) { +if (!using_legacy_binding) +pr_notice ("deprecated \"mmu-masters\" DT property in use\n" ); + using_legacy_binding = true; + }else if (!legacy_binding && !using_legacy_binding) { + using_generic_binding = true;Please simplify this series of if/else.
This code is the same as Linux SMMU driver. If we agree on enforcing all smmus are using the same binding, I prefer to keep the code the same.
Quoted 15 lines
Quoted 15 lines
xen/drivers/passthrough/arm/smmu.c +4
-0+ }else { +dev_err (dev,"not probing due to mismatched DT properties\n" ); +return -ENODEV ; + }xen/drivers/passthrough/arm/smmu.c +0
-1smmu =devm_kzalloc (dev,sizeof (*smmu),GFP_KERNEL );if (!smmu) { --2.7.4
Quoted 5 lines
Quoted 5 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 4/7] xen/arm: SMMU: Detect types of device tree binding
Quoted 56 lines · Wei Chen
Hi Stefano,
Quoted 15 lines
-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 2017年7月4日 6:30
To: Wei Chen <[email protected]>
Cc: [email protected]; [email protected]; Steve Capper <[email protected]>; Kaly Xin <[email protected]>; Julien Grall <[email protected]>; nd <[email protected]>
Subject: Re: [Xen-devel] [PATCH 4/7] xen/arm: SMMU: Detect types of device tree bindingQuoted 2 lines · Wei Chen
The device tree provides two types of IOMMU bindings, one is legacy another is generic. The legacy bindings will be depercated in favour
^ deprecated
Quoted 7 lines
Quoted 4 lines
of the generic bindings. But in the transitional period, we have to support both of them.
The codes to handle these two types of bindings are very differnet,
^ code ^ different
Please use a spellchecker.
Thanks, I will fix them.
Quoted 29 lines
Quoted 6 lines
so we have to detect the binding types while doing SMMU probing.
This detect code is based on Linux ARM SMMUv2 driver:
https://github.com/torvalds/linux/blob/master/drivers/iommu/arm-smmu.cReview
Quoted 6 lines
Signed-off-by Wei Chen <[email protected]>--- xen/drivers/passthrough/arm/smmu.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)(quoted diff) +0
-0
b/xen/drivers/passthrough/arm/smmu.cQuoted 16 lines
index 2efa52d..441c296 100644
xen/drivers/passthrough/arm/smmu.c +2
-0@@ -143,6 +143,8 @@ typedef enum irqreturn irqreturn_t;#define dev_name (dev) dt_node_full_name(dev_to_dt(dev)) +#define pr_notice (fmt, ...) printk(XENLOG_INFO fmt, ## __VA_ARGS__) +/* Alias to Xen allocation helpers */ #define kfree xfree#define kmalloc (size, flags) _xmalloc(size, sizeof(void *))@@ -681,6 +683,8 @@ struct arm_smmu_option_prop {const char *prop; };
Quoted 8 lines
Quoted 4 lines
xen/drivers/passthrough/arm/smmu.c struct arm_smmu_option_prop { · line 686
Quoted 1 line
xen/drivers/passthrough/arm/smmu.c +1
-0+static bool using_legacy_binding, using_generic_binding;
__initdata?I think these two variables are not only used in initialization. They also have been used in
ops->add_device. Althrough theadd_deviceis only be invoked whileconstruct_dom0.
I don't think that add_device is supposed to be limited at boot. It's best to avoid __initdata then.
Quoted 24 lines
Quoted 6 lines
But why do these two variables need to be static? Can't they just be local variables in
arm_smmu_device_dt_probe?Is it to enforce that all smmus on a given platform are either using the legacy or the generic bindings, but not a mix of the two? If so, it should be clearly written. Also, I am not sure we should really be
Yes, this checking will enforce all smmus are using the same bindings.
Quoted 4 lines
checking for that. It seems to me that one smmu could be using generic bindings and another could be using legacy bindings. Is it specified anywhere that it cannot be the case?
In theory, different SMMUs can use different bindings. About this concern, I have discussed with Robin Murphy and Julien. We have three reasons:
The first is that, we ported this checking from Linux, we are trying to keep the code very close to the Linux driver. To ease backporting changes.
The second is that, we think it is a good change to try to phase out the legacy binding and request to use generic bindings everywhere if you start to use in one SMMU.
Quoted 5 lines
The other less technical reason for not supporting both at once is that anyone who can update their DT to add or update SMMUs with the new binding has no good excuse for not updating the whole lot. It's the likes of Seattle and ThunderX boxes with firmware that won't get updated for which we have to preserve "mmu-masters" support.
I would like these reasons to be written in the commit message. I would also like to detect and print a clear warning when SMMUs are using mismatched bindings.
Quoted 39 lines
Quoted 17 lines
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c +0
-0static struct arm_smmu_option_prop arm_smmu_options[] = { {ARM_SMMU_OPT_SECURE_CFG_ACCESS ,"calxeda,smmu-secure-config-access" }, {0 ,NULL },@@ -2289,6 +2293,25 @@ static int arm_smmu_device_dt_probe(struct
platform_device*pdev)xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct platform_device *pdev)
Quoted 7 lines
xen/drivers/passthrough/arm/smmu.c +4
-0struct rb_node *node;struct of_phandle_args masterspec;int num_irqs, i, err; +bool legacy_binding; + +/* +* Xen: Do the same check as Linux. Checking the SMMU device tree bindings
^ do ^ Check thatQuoted 7 lines
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct platform_device *pdev) · line 2300
Quoted 1 line
xen/drivers/passthrough/arm/smmu.c +1
-0+* are either using generic or legacy one. ^ bindings
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct platform_device *pdev) · line 2302
Quoted 2 lines
xen/drivers/passthrough/arm/smmu.c +2
-0+* +* The "mmu-masters" property is only existed in legacy bindings. ^ only exists in the legacy bindings
Thanks, I will fix above typos.
Quoted 11 lines
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct platform_device *pdev) · line 2310
Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c +8
-0+*/ + legacy_binding =dt_find_property (dev->of_node,"mmu-masters" ,NULL ); +if (legacy_binding && !using_generic_binding) { +if (!using_legacy_binding) +pr_notice ("deprecated \"mmu-masters\" DT property in use\n" ); + using_legacy_binding = true; + }else if (!legacy_binding && !using_legacy_binding) { + using_generic_binding = true;Please simplify this series of if/else.
Quoted 2 lines
This code is the same as Linux SMMU driver. If we agree on enforcing all smmus are using the same binding, I prefer to keep the code the same.
Is it?! Wow... All right then, but I would still like a warning to be printed when we find out that an SMMU is using legacy bindings and others are using generic bindings.
Quoted 21 lines
Quoted 15 lines
Quoted 15 lines
xen/drivers/passthrough/arm/smmu.c +4
-0+ }else { +dev_err (dev,"not probing due to mismatched DT properties\n" ); +return -ENODEV ; + }xen/drivers/passthrough/arm/smmu.c +0
-1smmu =devm_kzalloc (dev,sizeof (*smmu),GFP_KERNEL );if (!smmu) { --2.7.4
Quoted 5 lines
Quoted 5 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 5 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 4/7] xen/arm: SMMU: Detect types of device tree binding
Quoted 74 lines
-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 2017年7月6日 2:08
To: Wei Chen <[email protected]>
Cc: Stefano Stabellini <[email protected]>; Kaly Xin <[email protected]>; Julien Grall <[email protected]>; Steve Capper <[email protected]>; nd <[email protected]>; [email protected]
Subject: Re: [Xen-devel] [PATCH 4/7] xen/arm: SMMU: Detect types of device tree bindingQuoted 61 lines · Wei Chen
Hi Stefano,
Quoted 15 lines
-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 2017年7月4日 6:30
To: Wei Chen <[email protected]>
Cc: [email protected]; [email protected]; Steve Capper <[email protected]>; Kaly Xin <[email protected]>; Julien Grall <[email protected]>; nd <[email protected]>
Subject: Re: [Xen-devel] [PATCH 4/7] xen/arm: SMMU: Detect types of device tree bindingQuoted 2 lines · Wei Chen
The device tree provides two types of IOMMU bindings, one is legacy another is generic. The legacy bindings will be depercated in favour
^ deprecated
Quoted 7 lines
Quoted 4 lines
of the generic bindings. But in the transitional period, we have to support both of them.
The codes to handle these two types of bindings are very differnet,
^ code ^ different
Please use a spellchecker.
Thanks, I will fix them.
Quoted 33 lines
Quoted 6 lines
so we have to detect the binding types while doing SMMU probing.
This detect code is based on Linux ARM SMMUv2 driver:
https://github.com/torvalds/linux/blob/master/drivers/iommu/arm-smmu.cReview
Quoted 6 lines
Signed-off-by Wei Chen <[email protected]>--- xen/drivers/passthrough/arm/smmu.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)(quoted diff) +0
-0
b/xen/drivers/passthrough/arm/smmu.cQuoted 13 lines
index 2efa52d..441c296 100644
xen/drivers/passthrough/arm/smmu.c +2
-0@@ -143,6 +143,8 @@ typedef enum irqreturn irqreturn_t;#define dev_name (dev) dt_node_full_name(dev_to_dt(dev)) +#define pr_notice (fmt, ...) printk(XENLOG_INFO fmt, ## __VA_ARGS__) +/* Alias to Xen allocation helpers */ #define kfree xfree#define kmalloc (size, flags) _xmalloc(size, sizeof(void *))xen/drivers/passthrough/arm/smmu.c struct arm_smmu_option_prop { · line 686
Quoted 4 lines
xen/drivers/passthrough/arm/smmu.c +1
-0@@ -681,6 +683,8 @@ struct arm_smmu_option_prop {const char *prop; }; +static bool using_legacy_binding, using_generic_binding;
__initdata?
Quoted 7 lines
Quoted 3 lines
I think these two variables are not only used in initialization. They also have been used in
ops->add_device. Althrough theadd_deviceis only be invoked whileconstruct_dom0.I don't think that
add_deviceis supposed to be limited at boot. It's best to avoid__initdatathen.
Yes. So let keep these two variables without __initdata here.
Quoted 30 lines
Quoted 18 lines
Quoted 7 lines
But why do these two variables need to be static? Can't they just be local variables in
arm_smmu_device_dt_probe?Is it to enforce that all smmus on a given platform are either using the legacy or the generic bindings, but not a mix of the two? If so, it should be clearly written. Also, I am not sure we should really be
Yes, this checking will enforce all smmus are using the same bindings.
Quoted 4 lines
checking for that. It seems to me that one smmu could be using generic bindings and another could be using legacy bindings. Is it specified anywhere that it cannot be the case?
In theory, different SMMUs can use different bindings. About this concern, I have discussed with Robin Murphy and Julien. We have three reasons:
Quoted 8 lines
The first is that, we ported this checking from Linux, we are trying to keep the code very close to the Linux driver. To ease backporting changes.
The second is that, we think it is a good change to try to phase out the legacy binding and request to use generic bindings everywhere if you start to use in one SMMU.
The other less technical reason for not supporting both at once is that
anyone
Quoted 1 line
who can update their DT to add or update SMMUs with the new binding has no
good
Quoted 1 line
excuse for not updating the whole lot. It's the likes of Seattle and
Quoted 9 lines
ThunderX
Quoted 1 line
boxes with firmware that won't get updated for which we have to preserve
"mmu-masters"
Quoted 1 line
support.
I would like these reasons to be written in the commit message. I would also like to detect and print a clear warning when SMMUs are using mismatched bindings.
Ok.
Quoted 43 lines
Quoted 4 lines
Quoted 4 lines
xen/drivers/passthrough/arm/smmu.c struct arm_smmu_option_prop { · line 688
Quoted 4 lines
xen/drivers/passthrough/arm/smmu.c +0
-0static struct arm_smmu_option_prop arm_smmu_options[] = { { ARM_SMMU_OPT_SECURE_CFG_ACCESS, "calxeda,smmu-secure-config-access" },
Quoted 22 lines
Quoted 14 lines
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct
Quoted 2 lines
xen/drivers/passthrough/arm/smmu.c +0
-0{ 0, NULL},@@ -2289,6 +2293,25 @@ static int arm_smmu_device_dt_probe(struct
platform_device*pdev)xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct platform_device *pdev)
Quoted 7 lines
xen/drivers/passthrough/arm/smmu.c +4
-0struct rb_node *node;struct of_phandle_args masterspec;int num_irqs, i, err; +bool legacy_binding; + +/* +* Xen: Do the same check as Linux. Checking the SMMU device tree bindings
^ do ^ Check thatQuoted 7 lines
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct platform_device *pdev) · line 2300
Quoted 1 line
xen/drivers/passthrough/arm/smmu.c +1
-0+* are either using generic or legacy one. ^ bindings
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct platform_device *pdev) · line 2302
Quoted 2 lines
xen/drivers/passthrough/arm/smmu.c +2
-0+* +* The "mmu-masters" property is only existed in legacy bindings. ^ only exists in the legacy bindings
Quoted 4 lines
Thanks, I will fix above typos.
Quoted 2 lines
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct · line 2304
Quoted 2 lines
xen/drivers/passthrough/arm/smmu.c +2
-0+*/ + legacy_binding = dt_find_property(dev->of_node, "mmu-masters",NULL);
Quoted 3 lines
Quoted 3 lines
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct platform_device *pdev)
Quoted 3 lines
xen/drivers/passthrough/arm/smmu.c +3
-0+if (legacy_binding && !using_generic_binding) { +if (!using_legacy_binding) + pr_notice("deprecated \"mmu-masters\" DT property inuse\n");
Quoted 7 lines
Quoted 6 lines
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct platform_device *pdev) · line 2310
Quoted 3 lines
xen/drivers/passthrough/arm/smmu.c +3
-0+ using_legacy_binding = true; + }else if (!legacy_binding && !using_legacy_binding) { + using_generic_binding = true;Please simplify this series of if/else.
Quoted 8 lines
Quoted 1 line
This code is the same as Linux SMMU driver. If we agree on enforcing all
smmus
Quoted 1 line
are using the same binding, I prefer to keep the code the same.
Is it?! Wow... All right then, but I would still like a warning to be printed when we find out that an SMMU is using legacy bindings and others are using generic bindings.
Ok, I will add this warning message.
Quoted 28 lines
Quoted 4 lines
Quoted 4 lines
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_dt_probe(struct · line 2312
Quoted 4 lines
xen/drivers/passthrough/arm/smmu.c +2
-0+ }else { + dev_err(dev, "not probing due to mismatched DTproperties\n");
Quoted 23 lines
Quoted 12 lines
Quoted 12 lines
xen/drivers/passthrough/arm/smmu.c +2
-0+return -ENODEV ; + }xen/drivers/passthrough/arm/smmu.c +0
-1smmu =devm_kzalloc (dev,sizeof (*smmu),GFP_KERNEL );if (!smmu) { --2.7.4
Quoted 5 lines
Quoted 5 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 5/7 xen/arm: SMMU: Keep registering legacy master in SMMU probe
In reply to Wei ChenThe legacy IOMMU bindings place the SMMU MasterIDs in the SMMU device tree node. In current code, we register the SMMU masters while probing SMMU. It's better to keep registering legacy masters in the SMMU probing progress. If we move registering legacy SMMU masters to add_device or assign_device, we have to go through all SMMUs to find correct SMMU for master device. It's inefficient and doesn't bring any enhancement.
Similarly, if we want to register generic masters in SMMU probing, we have to go through whole device tree to find master devices for all SMMUs. So we only keep registering legacy master in SMMU probing.
--- xen/drivers/passthrough/arm/smmu.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-)
xen/drivers/passthrough/arm/smmu.c +19 -12
@@ -2375,21 +2375,28 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev)if (err)return err; - i =0 ; smmu->masters =RB_ROOT ; -while (!of_parse_phandle_with_args (dev->of_node,"mmu-masters" , -"#stream-id-cells" , i, - &masterspec)) { - err =register_smmu_master (smmu, dev, &masterspec); -if (err) { -dev_err (dev,"failed to add master %s\n" , - masterspec.np->name); - goto out_put_masters; - } +/* +* The SMMU MasterIDs are listed in SMMU device tree node while using +* the legacy IOMMU bindins. So in the SMMU probing progress, we will +* register the SMMU master only for legacy bindings. +*/ +if (using_legacy_binding) { + i =0 ; +while (!of_parse_phandle_with_args (dev->of_node,"mmu-masters" , +"#stream-id-cells" , i, + &masterspec)) { + err =register_smmu_master (smmu, dev, &masterspec); +if (err) { +dev_err (dev,"failed to add master %s\n" , + masterspec.np->name); + goto out_put_masters; + } - i++; + i++; + } +dev_notice (dev,"registered %d legacy master devices\n" , i); } -dev_notice (dev,"registered %d master devices\n" , i);parse_driver_options (smmu);
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 5/7] xen/arm: SMMU: Keep registering legacy master in SMMU probe
Quoted 7 lines · Wei Chen
The legacy IOMMU bindings place the SMMU MasterIDs in the SMMU device tree node. In current code, we register the SMMU masters while probing SMMU. It's better to keep registering legacy masters in the SMMU probing progress. If we move registering legacy SMMU masters to
add_deviceorassign_device, we have to go through all SMMUs to find correct SMMU for master device. It's inefficient and doesn't bring any enhancement.
Quoted 5 lines
Similarly, if we want to register generic masters in SMMU probing, we have to go through whole device tree to find master devices for all SMMUs. So we only keep registering legacy master in SMMU probing.
Signed-off-by Wei Chen <[email protected]>
Quoted 58 lines
--- xen/drivers/passthrough/arm/smmu.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-)xen/drivers/passthrough/arm/smmu.c +19
-12@@ -2375,21 +2375,28 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev)if (err)return err; - i =0 ; smmu->masters =RB_ROOT ; -while (!of_parse_phandle_with_args (dev->of_node,"mmu-masters" , -"#stream-id-cells" , i, - &masterspec)) { - err =register_smmu_master (smmu, dev, &masterspec); -if (err) { -dev_err (dev,"failed to add master %s\n" , - masterspec.np->name); - goto out_put_masters; - } +/* +* The SMMU MasterIDs are listed in SMMU device tree node while using +* the legacy IOMMU bindins. So in the SMMU probing progress, we will +* register the SMMU master only for legacy bindings. +*/ +if (using_legacy_binding) { + i =0 ; +while (!of_parse_phandle_with_args (dev->of_node,"mmu-masters" , +"#stream-id-cells" , i, + &masterspec)) { + err =register_smmu_master (smmu, dev, &masterspec); +if (err) { +dev_err (dev,"failed to add master %s\n" , + masterspec.np->name); + goto out_put_masters; + } - i++; + i++; + } +dev_notice (dev,"registered %d legacy master devices\n" , i); } -dev_notice (dev,"registered %d master devices\n" , i);parse_driver_options (smmu);Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 6/7 xen/arm: SMMU: Support generic IOMMU bindings
In reply to Wei ChenThe SMMU MasterIDs are placed at the master devices' DT node while using the generic bindings. In this case, it's very hard for us to register SMMU masters while probing SMMU as we had done for legacy bindings. Because we have to go through whole device tree for all SMMU devices to find their master devices.
It's better to register SMMU master for generic bindings in add_device callback. This callback will only be called while constructing Dom0.
--- xen/drivers/passthrough/arm/smmu.c | 144 ++++++++++++++++++++++++++++++++++++- 1 file changed, 143 insertions(+), 1 deletion(-)
xen/drivers/passthrough/arm/smmu.c +143 -1
@@ -2621,8 +2621,150 @@ static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)xfree (domain); } +static int arm_smmu_add_generic_master_id (struct arm_smmu_device *smmu, +struct device *master_dev,u16 fwid) +{ +struct arm_smmu_master *master; +struct device_node *master_np = master_dev->of_node; + + master =find_smmu_master (smmu, master_np); +if (!master) { +dev_notice (smmu->dev, +"This smmu master [%s] hasn't been registered, creating now!\n" , + master_np->full_name); + master =devm_kzalloc (smmu->dev,sizeof (*master),GFP_KERNEL ); +if (!master) +return -ENOMEM ; + + master->of_node = master_np; + master->cfg.num_streamids =0 ; + +/* +* Xen: Let Xen know that the device is protected by a SMMU. +* Only do while registering the master. +*/ +dt_device_set_protected (master_np); + } + +/* +* If the smmu is using the stream index mode, check whether +* the streamid exceeds the max allowed id, +*/ +if (!(smmu->features &ARM_SMMU_FEAT_STREAM_MATCH ) && + (fwid >= smmu->num_mapping_groups)) { +dev_err (smmu->dev, +"Stream ID for master device %s greater than maximum allowed (%d)\n" , + master_np->name, smmu->num_mapping_groups); +return -ERANGE ; + } + +if (master->cfg.num_streamids >=MAX_MASTER_STREAMIDS ) { +dev_err (smmu->dev, +"Reached maximum number (%d) of stream IDs for master device %s\n" , +MAX_MASTER_STREAMIDS , master_np->name); +return -ENOSPC ; + } + +/* +* If this is the first time we add id to this master, +* we have to register this master to rb tree. +*/ +if (!master->cfg.num_streamids) { +int ret; + ret =insert_smmu_master (smmu, master); +if ( ret && ret != -EEXIST ) { +dev_err (smmu->dev, +"Insert %s to smmu's master rb tree failed\n" , master_np->name); +return ret; + } + } + + master->cfg.streamids[master->cfg.num_streamids] = fwid; + master->cfg.num_streamids++; +dev_dbg (smmu->dev, +"Add new streamid [%d] to smmu [%s] for master [%s]!\n" , + fwid, smmu->dev->of_node->name, master_np->name); + +return 0 ; +} + +static struct arm_smmu_device *find_smmu (const struct device *dev); + +static int arm_smmu_of_xlate (struct device *dev,struct of_phandle_args *args) +{ +struct arm_smmu_device *smmu; +u32 mask =0 , fwid =0 ; + + smmu =find_smmu (dt_to_dev (args->np)); +if (!smmu) { +dev_err (dev,"Could not find smmu device!\n" ); +return -ENODEV ; + } + +if (args->args_count >0 ) + fwid |= (u16 )args->args[0 ]; + +if (args->args_count >1 ) + fwid |= (u16 )args->args[1 ] <<SMR_MASK_SHIFT ; +else if (!of_property_read_u32 (args->np,"stream-match-mask" , &mask)) + fwid |= (u16 )mask <<SMR_MASK_SHIFT ; + +dev_dbg (dev,"%s fwid:%08x mask:%08x args_count:%d\n" , + args->np->full_name, fwid, + mask, args->args_count); + +return arm_smmu_add_generic_master_id (smmu, dev, (u16 )fwid); +} + +/* +* Parse "iommus" information from generic bindings of platfomr master +* device, and then xlate to master IDs and register to SMMU device. +*/ +static int arm_smmu_platform_iommu_init (struct device *dev) +{ +struct of_phandle_args iommu_spec; +int idx =0 , ret; + +/* +* We don't currently walk up the tree looking for a parent IOMMU. +* See the `Notes:' section of +* Documentation/devicetree/bindings/iommu/iommu.txt +*/ +while (!of_parse_phandle_with_args (dev->of_node,"iommus" , +"#iommu-cells" , + idx, &iommu_spec)) { + ret =arm_smmu_of_xlate (dev, &iommu_spec); +if (ret) { +dev_err (dev, +"Do of_xlate for platform device failed, err=%d\n" , ret); +return ret; + } + + idx++; + } + +/* +* Return 0 if the device is not protected to follow the behavior +* of PCI add device. +*/ +return 0 ; +} +static int arm_smmu_xen_add_device (u8 devfn,struct device *dev) { +int ret; + +/* +* iommu_add_dt_device() is only called for the hardware domain. +* If the SMMU is using generic bindings, we should parse and +* register Master IDs while this function had been invoked. +*/ +if (using_generic_binding) { + ret =arm_smmu_platform_iommu_init (dev); +if (ret) +return ret; + } +if (dt_device_is_protected (dev->of_node)) {if (!dev->archdata.iommu) { dev->archdata.iommu = xzalloc(struct arm_smmu_xen_device);
@@ -2832,7 +2974,7 @@ static const struct iommu_ops arm_smmu_iommu_ops = { .unmap_page = arm_smmu_unmap_page, }; -static __init const struct arm_smmu_device *find_smmu (const struct device *dev) +static struct arm_smmu_device *find_smmu (const struct device *dev) {struct arm_smmu_device *smmu;bool found = false;
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 6/7] xen/arm: SMMU: Support generic IOMMU bindings
Quoted 102 lines · Wei Chen
The SMMU MasterIDs are placed at the master devices' DT node while using the generic bindings. In this case, it's very hard for us to register SMMU masters while probing SMMU as we had done for legacy bindings. Because we have to go through whole device tree for all SMMU devices to find their master devices.
It's better to register SMMU master for generic bindings in
add_devicecallback. This callback will only be called while constructing Dom0.Signed-off-by Wei Chen <[email protected]>--- xen/drivers/passthrough/arm/smmu.c | 144 ++++++++++++++++++++++++++++++++++++- 1 file changed, 143 insertions(+), 1 deletion(-)xen/drivers/passthrough/arm/smmu.c +80
-0@@ -2621,8 +2621,150 @@ static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)xfree (domain); } +static int arm_smmu_add_generic_master_id (struct arm_smmu_device *smmu, +struct device *master_dev,u16 fwid) +{ +struct arm_smmu_master *master; +struct device_node *master_np = master_dev->of_node; + + master =find_smmu_master (smmu, master_np); +if (!master) { +dev_notice (smmu->dev, +"This smmu master [%s] hasn't been registered, creating now!\n" , + master_np->full_name); + master =devm_kzalloc (smmu->dev,sizeof (*master),GFP_KERNEL ); +if (!master) +return -ENOMEM ; + + master->of_node = master_np; + master->cfg.num_streamids =0 ; + +/* +* Xen: Let Xen know that the device is protected by a SMMU. +* Only do while registering the master. +*/ +dt_device_set_protected (master_np); + } + +/* +* If the smmu is using the stream index mode, check whether +* the streamid exceeds the max allowed id, +*/ +if (!(smmu->features &ARM_SMMU_FEAT_STREAM_MATCH ) && + (fwid >= smmu->num_mapping_groups)) { +dev_err (smmu->dev, +"Stream ID for master device %s greater than maximum allowed (%d)\n" , + master_np->name, smmu->num_mapping_groups); +return -ERANGE ; + } + +if (master->cfg.num_streamids >=MAX_MASTER_STREAMIDS ) { +dev_err (smmu->dev, +"Reached maximum number (%d) of stream IDs for master device %s\n" , +MAX_MASTER_STREAMIDS , master_np->name); +return -ENOSPC ; + } + +/* +* If this is the first time we add id to this master, +* we have to register this master to rb tree. +*/ +if (!master->cfg.num_streamids) { +int ret; + ret =insert_smmu_master (smmu, master); +if ( ret && ret != -EEXIST ) { +dev_err (smmu->dev, +"Insert %s to smmu's master rb tree failed\n" , master_np->name); +return ret; + } + } + + master->cfg.streamids[master->cfg.num_streamids] = fwid; + master->cfg.num_streamids++; +dev_dbg (smmu->dev, +"Add new streamid [%d] to smmu [%s] for master [%s]!\n" , + fwid, smmu->dev->of_node->name, master_np->name); + +return 0 ; +} + +static struct arm_smmu_device *find_smmu (const struct device *dev); + +static int arm_smmu_of_xlate (struct device *dev,struct of_phandle_args *args) +{ +struct arm_smmu_device *smmu; +u32 mask =0 , fwid =0 ; + + smmu =find_smmu (dt_to_dev (args->np)); +if (!smmu) { +dev_err (dev,"Could not find smmu device!\n" ); +return -ENODEV ; + } +
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain) · line 2713
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c +10
-0+if (args->args_count >0 ) + fwid |= (u16 )args->args[0 ]; + +if (args->args_count >1 ) + fwid |= (u16 )args->args[1 ] <<SMR_MASK_SHIFT ; +else if (!of_property_read_u32 (args->np,"stream-match-mask" , &mask)) + fwid |= (u16 )mask <<SMR_MASK_SHIFT ; +dev_dbg (dev,"%s fwid:%08x mask:%08x args_count:%d\n" , + args->np->full_name, fwid, + mask, args->args_count);
I don't understand why fwid is declared as u32 but used as a u16 below. Shouldn't it be declared as u16 in the first place?
Quoted 14 lines
xen/drivers/passthrough/arm/smmu.c +14
-0+return arm_smmu_add_generic_master_id (smmu, dev, (u16 )fwid); +} + +/* +* Parse "iommus" information from generic bindings of platfomr master +* device, and then xlate to master IDs and register to SMMU device. +*/ +static int arm_smmu_platform_iommu_init (struct device *dev) +{ +struct of_phandle_args iommu_spec; +int idx =0 , ret; + +/* +* We don't currently walk up the tree looking for a parent IOMMU.
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain) · line 2739
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c +10
-0+* See the `Notes:' section of +* Documentation/devicetree/bindings/iommu/iommu.txt +*/ +while (!of_parse_phandle_with_args (dev->of_node,"iommus" , +"#iommu-cells" , + idx, &iommu_spec)) { + ret =arm_smmu_of_xlate (dev, &iommu_spec); +if (ret) { +dev_err (dev, +"Do of_xlate for platform device failed, err=%d\n" , ret);
^ remove Do
Quoted 32 lines
xen/drivers/passthrough/arm/smmu.c +26
-0+return ret; + } + + idx++; + } + +/* +* Return 0 if the device is not protected to follow the behavior +* of PCI add device. +*/ +return 0 ; +} +static int arm_smmu_xen_add_device (u8 devfn,struct device *dev) { +int ret; + +/* +* iommu_add_dt_device() is only called for the hardware domain. +* If the SMMU is using generic bindings, we should parse and +* register Master IDs while this function had been invoked. +*/ +if (using_generic_binding) { + ret =arm_smmu_platform_iommu_init (dev); +if (ret) +return ret; + } +if (dt_device_is_protected (dev->of_node)) {if (!dev->archdata.iommu) { dev->archdata.iommu = xzalloc(struct arm_smmu_xen_device);
xen/drivers/passthrough/arm/smmu.c static const struct iommu_ops arm_smmu_iommu_ops = { · line 2980
Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c +1
-1@@ -2832,7 +2974,7 @@ static const struct iommu_ops arm_smmu_iommu_ops = { .unmap_page = arm_smmu_unmap_page, }; -static __init const struct arm_smmu_device *find_smmu (const struct device *dev) +static struct arm_smmu_device *find_smmu (const struct device *dev) {struct arm_smmu_device *smmu;bool found = false;
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 6/7] xen/arm: SMMU: Support generic IOMMU bindings
Hi Stefano,
Quoted 126 lines
-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 2017年7月4日 7:00
To: Wei Chen <[email protected]>
Cc: [email protected]; [email protected]; Steve Capper <[email protected]>; Kaly Xin <[email protected]>; Julien Grall <[email protected]>; nd <[email protected]>
Subject: Re: [Xen-devel] [PATCH 6/7] xen/arm: SMMU: Support generic IOMMU bindingsQuoted 6 lines · Wei Chen
The SMMU MasterIDs are placed at the master devices' DT node while using the generic bindings. In this case, it's very hard for us to register SMMU masters while probing SMMU as we had done for legacy bindings. Because we have to go through whole device tree for all SMMU devices to find their master devices.
Quoted 6 lines
It's better to register SMMU master for generic bindings in
add_devicecallback. This callback will only be called while constructing Dom0.Signed-off-by Wei Chen <[email protected]>--- xen/drivers/passthrough/arm/smmu.c | 144++++++++++++++++++++++++++++++++++++-
Review
Quoted 3 lines
1 file changed, 143 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/xen/drivers/passthrough/arm/smmu.cxen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct
Quoted 4 lines
index 895024c..25f2207 100644
xen/drivers/passthrough/arm/smmu.c +0
-0@@ -2621,8 +2621,150 @@ static void arm_smmu_destroy_iommu_domain(struct
iommu_domain*domain)xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)
Quoted 13 lines
xen/drivers/passthrough/arm/smmu.c +10
-0xfree (domain); } +static int arm_smmu_add_generic_master_id (struct arm_smmu_device *smmu, +struct device *master_dev,u16 fwid) +{ +struct arm_smmu_master *master; +struct device_node *master_np = master_dev->of_node; + + master =find_smmu_master (smmu, master_np); +if (!master) { + dev_notice(smmu->dev, + "This smmu master [%s] hasn't been registered, creatingnow!\n",
Quoted 13 lines
xen/drivers/passthrough/arm/smmu.c +13
-0+ master_np->full_name); + master =devm_kzalloc (smmu->dev,sizeof (*master),GFP_KERNEL ); +if (!master) +return -ENOMEM ; + + master->of_node = master_np; + master->cfg.num_streamids =0 ; + +/* +* Xen: Let Xen know that the device is protected by a SMMU. +* Only do while registering the master. +*/ +dt_device_set_protected (master_np);xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c +10
-0+ } + +/* +* If the smmu is using the stream index mode, check whether +* the streamid exceeds the max allowed id, +*/ +if (!(smmu->features &ARM_SMMU_FEAT_STREAM_MATCH ) && + (fwid >= smmu->num_mapping_groups)) { + dev_err(smmu->dev, + "Stream ID for master device %s greater than maximum allowed(%d)\n",
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)
Quoted 7 lines
xen/drivers/passthrough/arm/smmu.c +7
-0+ master_np->name, smmu->num_mapping_groups); +return -ERANGE ; + } + +if (master->cfg.num_streamids >=MAX_MASTER_STREAMIDS ) { + dev_err(smmu->dev, + "Reached maximum number (%d) of stream IDs for masterdevice %s\n",
Quoted 4 lines
xen/drivers/passthrough/arm/smmu.c +4
-0+ MAX_MASTER_STREAMIDS, master_np->name); +return -ENOSPC ; + } +xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c +10
-0+/* +* If this is the first time we add id to this master, +* we have to register this master to rb tree. +*/ +if (!master->cfg.num_streamids) { +int ret; + ret =insert_smmu_master (smmu, master); +if ( ret && ret != -EEXIST ) { + dev_err(smmu->dev, + "Insert %s to smmu's master rb tree failed\n",
master_np->name);Quoted 6 lines
xen/drivers/passthrough/arm/smmu.c +6
-0+return ret; + } + } + + master->cfg.streamids[master->cfg.num_streamids] = fwid; + master->cfg.num_streamids++;xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c +10
-0+dev_dbg (smmu->dev, +"Add new streamid [%d] to smmu [%s] for master [%s]!\n" , + fwid, smmu->dev->of_node->name, master_np->name); + +return 0 ; +} + +static struct arm_smmu_device *find_smmu (const struct device *dev); + +static int arm_smmu_of_xlate(struct device *dev, struct of_phandle_args*args)
Quoted 15 lines
xen/drivers/passthrough/arm/smmu.c +15
-0+{ +struct arm_smmu_device *smmu; +u32 mask =0 , fwid =0 ; + + smmu =find_smmu (dt_to_dev (args->np)); +if (!smmu) { +dev_err (dev,"Could not find smmu device!\n" ); +return -ENODEV ; + } + +if (args->args_count >0 ) + fwid |= (u16 )args->args[0 ]; + +if (args->args_count >1 ) + fwid |= (u16 )args->args[1 ] <<SMR_MASK_SHIFT ;
Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain) · line 2714
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c +5
-0+else if (!of_property_read_u32 (args->np,"stream-match-mask" , &mask)) + fwid |= (u16 )mask <<SMR_MASK_SHIFT ; +dev_dbg (dev,"%s fwid:%08x mask:%08x args_count:%d\n" , + args->np->full_name, fwid, + mask, args->args_count);I don't understand why fwid is declared as u32 but used as a u16 below. Shouldn't it be declared as u16 in the first place?
Oh, it's my mistake. In Linux, the fwid will be passed to iommu_fwspec_add_ids, it requires u32 parameter. But after I ported this code to Xen, we passed the fwid to arm_smmu_add_generic_master_id, a u16 parameter is enough.
I will fix it.
Quoted 19 lines
Quoted 19 lines
xen/drivers/passthrough/arm/smmu.c +18
-0+return arm_smmu_add_generic_master_id (smmu, dev, (u16 )fwid); +} + +/* +* Parse "iommus" information from generic bindings of platfomr master +* device, and then xlate to master IDs and register to SMMU device. +*/ +static int arm_smmu_platform_iommu_init(struct device *dev) +{ + struct of_phandle_args iommu_spec; + int idx = 0, ret; + + /* + * We don't currently walk up the tree looking for a parent IOMMU. + * See the `Notes:' section of + * Documentation/devicetree/bindings/iommu/iommu.txt + */ + while (!of_parse_phandle_with_args(dev->of_node, "iommus",
Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)
Quoted 6 lines
xen/drivers/passthrough/arm/smmu.c +6
-0+ "#iommu-cells", + idx, &iommu_spec)) { + ret =arm_smmu_of_xlate (dev, &iommu_spec); +if (ret) { + dev_err(dev, + "Do of_xlate for platform device failed, err=%d\n",ret);
^ remove Do
Ok.
Quoted 35 lines
Quoted 35 lines
xen/drivers/passthrough/arm/smmu.c +26
-0+return ret; + } + + idx++; + } + +/* +* Return 0 if the device is not protected to follow the behavior +* of PCI add device. +*/ +return 0 ; +} +static int arm_smmu_xen_add_device (u8 devfn,struct device *dev) { +int ret; + +/* +* iommu_add_dt_device() is only called for the hardware domain. +* If the SMMU is using generic bindings, we should parse and +* register Master IDs while this function had been invoked. +*/ +if (using_generic_binding) { + ret =arm_smmu_platform_iommu_init (dev); +if (ret) +return ret; + } +if (dt_device_is_protected (dev->of_node)) {if (!dev->archdata.iommu) { dev->archdata.iommu = xzalloc(struct arm_smmu_xen_device);@@ -2832,7 +2974,7 @@ static const struct iommu_ops arm_smmu_iommu_ops = { .unmap_page = arm_smmu_unmap_page, };
Quoted 6 lines
xen/drivers/passthrough/arm/smmu.c static const struct iommu_ops arm_smmu_iommu_ops = { · line 2835
Quoted 1 line
xen/drivers/passthrough/arm/smmu.c +0
-1-static __init const struct arm_smmu_device *find_smmu(const struct device*dev)
Quoted 4 lines
xen/drivers/passthrough/arm/smmu.c +1
-0+static struct arm_smmu_device *find_smmu (const struct device *dev) {struct arm_smmu_device *smmu;bool found = false;
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 6/7] xen/arm: SMMU: Support generic IOMMU bindings
Hi,
Quoted 74 lines · Wei Chen
Hi Stefano,
Quoted 72 lines
-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 2017年7月4日 7:00
To: Wei Chen <[email protected]>
Cc: [email protected]; [email protected]; Steve Capper <[email protected]>; Kaly Xin <[email protected]>; Julien Grall <[email protected]>; nd <[email protected]>
Subject: Re: [Xen-devel] [PATCH 6/7] xen/arm: SMMU: Support generic IOMMU bindingsQuoted 6 lines · Wei Chen
The SMMU MasterIDs are placed at the master devices' DT node while using the generic bindings. In this case, it's very hard for us to register SMMU masters while probing SMMU as we had done for legacy bindings. Because we have to go through whole device tree for all SMMU devices to find their master devices.
Quoted 6 lines
It's better to register SMMU master for generic bindings in
add_devicecallback. This callback will only be called while constructing Dom0.Signed-off-by Wei Chen <[email protected]>--- xen/drivers/passthrough/arm/smmu.c | 144++++++++++++++++++++++++++++++++++++-
Review
Quoted 3 lines
1 file changed, 143 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/xen/drivers/passthrough/arm/smmu.cxen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct
Quoted 4 lines
index 895024c..25f2207 100644
xen/drivers/passthrough/arm/smmu.c +0
-0@@ -2621,8 +2621,150 @@ static void arm_smmu_destroy_iommu_domain(struct
iommu_domain*domain)xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)
Quoted 13 lines
xen/drivers/passthrough/arm/smmu.c +10
-0xfree (domain); } +static int arm_smmu_add_generic_master_id (struct arm_smmu_device *smmu, +struct device *master_dev,u16 fwid) +{ +struct arm_smmu_master *master; +struct device_node *master_np = master_dev->of_node; + + master =find_smmu_master (smmu, master_np); +if (!master) { + dev_notice(smmu->dev, + "This smmu master [%s] hasn't been registered, creatingnow!\n",
Quoted 13 lines
xen/drivers/passthrough/arm/smmu.c +13
-0+ master_np->full_name); + master =devm_kzalloc (smmu->dev,sizeof (*master),GFP_KERNEL ); +if (!master) +return -ENOMEM ; + + master->of_node = master_np; + master->cfg.num_streamids =0 ; + +/* +* Xen: Let Xen know that the device is protected by a SMMU. +* Only do while registering the master. +*/ +dt_device_set_protected (master_np);xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c +10
-0+ } + +/* +* If the smmu is using the stream index mode, check whether +* the streamid exceeds the max allowed id, +*/ +if (!(smmu->features &ARM_SMMU_FEAT_STREAM_MATCH ) && + (fwid >= smmu->num_mapping_groups)) { + dev_err(smmu->dev, + "Stream ID for master device %s greater than maximum allowed(%d)\n",t
Quoted 1 line
xen/drivers/passthrough/arm/smmu.c +1
-0+ master_np->name, smmu->num_mapping_groups);
You allocate memory that will be lost forever if it fails for the first ID.
Quoted 9 lines
Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)
Quoted 6 lines
xen/drivers/passthrough/arm/smmu.c +6
-0+return -ERANGE ; + } + +if (master->cfg.num_streamids >=MAX_MASTER_STREAMIDS ) { + dev_err(smmu->dev, + "Reached maximum number (%d) of stream IDs for masterdevice %s\n",
Quoted 2 lines
xen/drivers/passthrough/arm/smmu.c +2
-0+ MAX_MASTER_STREAMIDS, master_np->name); +return -ENOSPC ;
Ditto.
Quoted 55 lines
Quoted 45 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)
Quoted 12 lines
xen/drivers/passthrough/arm/smmu.c +12
-0+ } + +/* +* If this is the first time we add id to this master, +* we have to register this master to rb tree. +*/ +if (!master->cfg.num_streamids) { +int ret; + ret =insert_smmu_master (smmu, master); +if ( ret && ret != -EEXIST ) { + dev_err(smmu->dev, + "Insert %s to smmu's master rb tree failed\n",
master_np->name);Quoted 6 lines
xen/drivers/passthrough/arm/smmu.c +6
-0+return ret; + } + } + + master->cfg.streamids[master->cfg.num_streamids] = fwid; + master->cfg.num_streamids++;xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c +10
-0+dev_dbg (smmu->dev, +"Add new streamid [%d] to smmu [%s] for master [%s]!\n" , + fwid, smmu->dev->of_node->name, master_np->name); + +return 0 ; +} + +static struct arm_smmu_device *find_smmu (const struct device *dev); + +static int arm_smmu_of_xlate(struct device *dev, struct of_phandle_args*args)
Quoted 15 lines
xen/drivers/passthrough/arm/smmu.c +15
-0+{ +struct arm_smmu_device *smmu; +u32 mask =0 , fwid =0 ; + + smmu =find_smmu (dt_to_dev (args->np)); +if (!smmu) { +dev_err (dev,"Could not find smmu device!\n" ); +return -ENODEV ; + } + +if (args->args_count >0 ) + fwid |= (u16 )args->args[0 ]; + +if (args->args_count >1 ) + fwid |= (u16 )args->args[1 ] <<SMR_MASK_SHIFT ;Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain) · line 2714
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c +5
-0+else if (!of_property_read_u32 (args->np,"stream-match-mask" , &mask)) + fwid |= (u16 )mask <<SMR_MASK_SHIFT ; +dev_dbg (dev,"%s fwid:%08x mask:%08x args_count:%d\n" , + args->np->full_name, fwid, + mask, args->args_count);I don't understand why fwid is declared as u32 but used as a u16 below. Shouldn't it be declared as u16 in the first place?
Quoted 3 lines
Oh, it's my mistake. In Linux, the fwid will be passed
toiommu_fwspec_add_ids, it requires u32 parameter. But after I ported this code to Xen, we passed the fwid toarm_smmu_add_generic_master_id, a u16 parameter is enough
u16 is not enough. If you look at the code you ported:
if (args->args_count > 0)
fwid |= (u16)args->args[0];
if (!of_property_read_u32(args->np, "stream-match-mask", &mask)
fwid |= mask << SMR_MASK_SHIFT;
SMR_MASK_SHIFT is 16, so the top 16-bit will be set to the mask. With your u16 cast you loose those bits and therefore will not support properly SMMU when the property "stream-match-mask" has been set.
Looking at our SMMU driver, I think we don't yet support sharing SMRS (you would need to double check). I would be ok if you don't support them, but at least you need to avoid blindly skipping the property because this is going to be difficult to debug. This means we need to print an error message and bail out if someone set that.
This kind of porting error could have been mitigated if this series was rebased as suggested multiple time on top of the fwspec work from QC (see [1]).
Regardless that, I would much prefer to rebase this work on top of the fwspec series. This is going to simplify a lot the logic and avoid code duplication, arm_smmu_add_generic_master_id is very similar to register_smmu_master.
Lastly, as I mentioned to you, any code not present in the Linux SMMU driver should be commented with /* Xen: ... */. This is helping us to know what has changed. For instance, I cannot find arm_smmu_add_generic_master_id in Linux code.
Cheers,
[1] https://lists.xen.org/archives/html/xen-devel/2017-06/msg00862.html
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 6/7] xen/arm: SMMU: Support generic IOMMU bindings
Hi Julien,
Quoted 87 lines
-----Original Message-----
From: Julien Grall [mailto:[email protected]]
Sent: 2017年7月4日 15:27
To: Wei Chen <[email protected]>; Stefano Stabellini <[email protected]>
Cc: [email protected]; Steve Capper <[email protected]>; Kaly Xin <[email protected]>; nd <[email protected]>
Subject: Re: [Xen-devel] [PATCH 6/7] xen/arm: SMMU: Support generic IOMMU bindingsHi,
Quoted 38 lines · Wei Chen
Hi Stefano,
Quoted 36 lines
-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 2017年7月4日 7:00
To: Wei Chen <[email protected]>
Cc: [email protected]; [email protected]; Steve Capper <[email protected]>; Kaly Xin <[email protected]>; Julien Grall <[email protected]>; nd <[email protected]>
Subject: Re: [Xen-devel] [PATCH 6/7] xen/arm: SMMU: Support generic IOMMU bindingsQuoted 6 lines · Wei Chen
The SMMU MasterIDs are placed at the master devices' DT node while using the generic bindings. In this case, it's very hard for us to register SMMU masters while probing SMMU as we had done for legacy bindings. Because we have to go through whole device tree for all SMMU devices to find their master devices.
Quoted 6 lines
It's better to register SMMU master for generic bindings in
add_devicecallback. This callback will only be called while constructing Dom0.Signed-off-by Wei Chen <[email protected]>--- xen/drivers/passthrough/arm/smmu.c | 144++++++++++++++++++++++++++++++++++++-
Review
Quoted 3 lines
1 file changed, 143 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/xen/drivers/passthrough/arm/smmu.cxen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct
Quoted 4 lines
index 895024c..25f2207 100644
xen/drivers/passthrough/arm/smmu.c +0
-0@@ -2621,8 +2621,150 @@ static void arm_smmu_destroy_iommu_domain(struct
iommu_domain*domain)Quoted 3 lines
xen/drivers/passthrough/arm/smmu.c +0
-0xfree (domain); }Quoted 10 lines
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c +10
-0+static int arm_smmu_add_generic_master_id (struct arm_smmu_device *smmu, +struct device *master_dev,u16 fwid) +{ +struct arm_smmu_master *master; +struct device_node *master_np = master_dev->of_node; + + master =find_smmu_master (smmu, master_np); +if (!master) { + dev_notice(smmu->dev, + "This smmu master [%s] hasn't been registered,creating
Quoted 16 lines
Quoted 16 lines
now!\n",
Quoted 15 lines
xen/drivers/passthrough/arm/smmu.c +15
-0+ master_np->full_name); + master =devm_kzalloc (smmu->dev,sizeof (*master),GFP_KERNEL ); +if (!master) +return -ENOMEM ; + + master->of_node = master_np; + master->cfg.num_streamids =0 ; + +/* +* Xen: Let Xen know that the device is protected by a SMMU. +* Only do while registering the master. +*/ +dt_device_set_protected (master_np); + } +Quoted 8 lines
Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)
Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c +8
-0+/* +* If the smmu is using the stream index mode, check whether +* the streamid exceeds the max allowed id, +*/ +if (!(smmu->features &ARM_SMMU_FEAT_STREAM_MATCH ) && + (fwid >= smmu->num_mapping_groups)) { + dev_err(smmu->dev, + "Stream ID for master device %s greater than maximumallowed
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
(%d)\n",t
Quoted 1 line
xen/drivers/passthrough/arm/smmu.c +1
-0+ master_np->name, smmu->num_mapping_groups);You allocate memory that will be lost forever if it fails for the first ID.
Yes, it seems the register_smmu_master has the same issue. I will try to fix it, and abstract the same logic of register_smmu_master and arm_smmu_add_generic_master_id to a separate function.
Quoted 11 lines
Quoted 9 lines
Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)
Quoted 6 lines
xen/drivers/passthrough/arm/smmu.c +6
-0+return -ERANGE ; + } + +if (master->cfg.num_streamids >=MAX_MASTER_STREAMIDS ) { + dev_err(smmu->dev, + "Reached maximum number (%d) of stream IDs for masterdevice %s\n",
Quoted 2 lines
xen/drivers/passthrough/arm/smmu.c +2
-0+ MAX_MASTER_STREAMIDS, master_np->name); +return -ENOSPC ;Ditto.
Got it.
Quoted 65 lines
Quoted 56 lines
Quoted 46 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)
Quoted 13 lines
xen/drivers/passthrough/arm/smmu.c +12
-0+ } + +/* +* If this is the first time we add id to this master, +* we have to register this master to rb tree. +*/ +if (!master->cfg.num_streamids) { +int ret; + ret =insert_smmu_master (smmu, master); +if ( ret && ret != -EEXIST ) { + dev_err(smmu->dev, + "Insert %s to smmu's master rb tree failed\n",
master_np->name);Quoted 6 lines
xen/drivers/passthrough/arm/smmu.c +6
-0+return ret; + } + } + + master->cfg.streamids[master->cfg.num_streamids] = fwid; + master->cfg.num_streamids++;xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c +10
-0+dev_dbg (smmu->dev, +"Add new streamid [%d] to smmu [%s] for master [%s]!\n" , + fwid, smmu->dev->of_node->name, master_np->name); + +return 0 ; +} + +static struct arm_smmu_device *find_smmu (const struct device *dev); + +static int arm_smmu_of_xlate(struct device *dev, struct of_phandle_args*args)
Quoted 15 lines
xen/drivers/passthrough/arm/smmu.c +15
-0+{ +struct arm_smmu_device *smmu; +u32 mask =0 , fwid =0 ; + + smmu =find_smmu (dt_to_dev (args->np)); +if (!smmu) { +dev_err (dev,"Could not find smmu device!\n" ); +return -ENODEV ; + } + +if (args->args_count >0 ) + fwid |= (u16 )args->args[0 ]; + +if (args->args_count >1 ) + fwid |= (u16 )args->args[1 ] <<SMR_MASK_SHIFT ;Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain) · line 2714
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c +5
-0+else if (!of_property_read_u32 (args->np,"stream-match-mask" , &mask)) + fwid |= (u16 )mask <<SMR_MASK_SHIFT ; +dev_dbg (dev,"%s fwid:%08x mask:%08x args_count:%d\n" , + args->np->full_name, fwid, + mask, args->args_count);I don't understand why fwid is declared as u32 but used as a u16 below. Shouldn't it be declared as u16 in the first place?
Quoted 4 lines
Oh, it's my mistake. In Linux, the fwid will be passed to
iommu_fwspec_add_ids,
it requires u32 parameter. But after I ported this code to Xen, we passed the fwid toarm_smmu_add_generic_master_id, a u16 parameter is enoughu16 is not enough. If you look at the code you ported:
if (
args->args_count> 0)
fwid |= (u16)args->args[0];
Quoted 7 lines
if (!of_property_read_u32(args->np, "stream-match-mask", &mask)
fwid |= mask <<SMR_MASK_SHIFT;
SMR_MASK_SHIFTis 16, so the top 16-bit will be set to the mask. With your u16 cast you loose those bits and therefore will not support properly SMMU when the property "stream-match-mask" has been set.
Yes, that's the reason why we use u32. Thanks for your reminder, Although the master->cfg.streamids is using u16, we'd better to keep U32 here and add a warning message to notice whom set "stream-match-mask"
Quoted 6 lines
Looking at our SMMU driver, I think we don't yet support sharing SMRS (you would need to double check). I would be ok if you don't support them, but at least you need to avoid blindly skipping the property because this is going to be difficult to debug. This means we need to print an error message and bail out if someone set that.
Yes, we don't currently share SMRs.
Quoted 9 lines
This kind of porting error could have been mitigated if this series was rebased as suggested multiple time on top of the fwspec work from QC (see [1]).
Regardless that, I would much prefer to rebase this work on top of the fwspec series. This is going to simplify a lot the logic and avoid code duplication,
arm_smmu_add_generic_master_idis very similar toregister_smmu_master.
If the fwspec work can be merged recently, I think it's good to rebase On it.
Quoted 5 lines
Lastly, as I mentioned to you, any code not present in the Linux SMMU driver should be commented with /* Xen: ... */. This is helping us to know what has changed. For instance, I cannot find
arm_smmu_add_generic_master_idin Linux code.
Sorry about it, I forgot this comment. I will add this comment to code.
Quoted 6 lines
Cheers,
[1] https://lists.xen.org/archives/html/xen-devel/2017-06/msg00862.html
--
Julien Grall
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 6/7] xen/arm: SMMU: Support generic IOMMU bindings
Quoted 1 line · Wei Chen
Hi Julien,
Hi Wei,
Please avoid replying in HTML on the xen-devel.
Quoted 4 lines
Quoted 4 lines
This kind of porting error could have been mitigated if this series was rebased as suggested multiple time on top of the fwspec work from QC (see [1]).
Quoted 8 lines
Quoted 5 lines
Regardless that, I would much prefer to rebase this work on top of the fwspec series. This is going to simplify a lot the logic and avoid code duplication,
arm_smmu_add_generic_master_idis very similar toregister_smmu_master.If the fwspec work can be merged recently, I think it's good to rebase On it.
I am not sure to understand what you mean here. It is possible to rebase on a series without the series to be merged upstream.
Anyway, I have CCed Sameer to get a status update here.
Quoted 15 lines
Quoted 6 lines
Lastly, as I mentioned to you, any code not present in the Linux SMMU driver should be commented with /* Xen: ... */. This is helping us to know what has changed. For instance, I cannot find
arm_smmu_add_generic_master_idin Linux code.Sorry about it, I forgot this comment. I will add this comment to code.
Quoted 6 lines
Cheers,
[1] https://lists.xen.org/archives/html/xen-devel/2017-06/msg00862.html
--
Julien Grall
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 6/7] xen/arm: SMMU: Support generic IOMMU bindings
Hi Julien,
Quoted 11 lines
-----Original Message-----
From: Julien Grall [mailto:[email protected]]
Sent: 2017年7月5日 21:08
To: Wei Chen <[email protected]>; Stefano Stabellini <[email protected]>
Cc: [email protected]; Steve Capper <[email protected]>; Kaly Xin <[email protected]>; nd <[email protected]>; Sameer Goel <[email protected]>
Subject: Re: [Xen-devel] [PATCH 6/7] xen/arm: SMMU: Support generic IOMMU bindings
Quoted 7 lines
Quoted 1 line · Wei Chen
Hi Julien,
Hi Wei,
Please avoid replying in HTML on the xen-devel.
Sorry about it.
It's very strange, I have checked my client, the configuration is plain text. If the issue is still existed, please remind me.
Thank you!
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
This kind of porting error could have been mitigated if this series was rebased as suggested multiple time on top of the fwspec work from QC (see [1]).
Regardless that, I would much prefer to rebase this work on top of the fwspec series. This is going to simplify a lot the logic and avoid code duplication,
arm_smmu_add_generic_master_idis very similar toregister_smmu_master.
Quoted 6 lines
Quoted 2 lines
If the fwspec work can be merged recently, I think it's good to rebase On it.
I am not sure to understand what you mean here. It is possible to rebase on a series without the series to be merged upstream.
Now, I understand. I had always thought we must rebase a merged series otherwise If my series had been merged, we would encounter compiling issue.
I think this my mis-understanding. If the rebase series doesn't need to be merged, I think it's ok to rebase on fwspec.
Quoted 15 lines
Anyway, I have CCed Sameer to get a status update here.
Quoted 13 lines
Quoted 6 lines
Lastly, as I mentioned to you, any code not present in the Linux SMMU driver should be commented with /* Xen: ... */. This is helping us to know what has changed. For instance, I cannot find
arm_smmu_add_generic_master_idin Linux code.Sorry about it, I forgot this comment. I will add this comment to code.
Quoted 4 lines
Cheers,
[1] https://lists.xen.org/archives/html/xen-devel/2017-06/msg00862.html
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
--
Julien GrallCheers,
--
Julien Grall
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 6/7] xen/arm: SMMU: Support generic IOMMU bindings
In reply to Wei ChenQuoted 39 lines · Wei Chen
Quoted 39 lines
Quoted 27 lines
Quoted 17 lines
Quoted 1 line
+static int arm_smmu_of_xlate(struct device *dev, struct
of_phandle_args*args)
Quoted 15 lines
xen/drivers/passthrough/arm/smmu.c +15
-0+{ +struct arm_smmu_device *smmu; +u32 mask =0 , fwid =0 ; + + smmu =find_smmu (dt_to_dev (args->np)); +if (!smmu) { +dev_err (dev,"Could not find smmu device!\n" ); +return -ENODEV ; + } + +if (args->args_count >0 ) + fwid |= (u16 )args->args[0 ]; + +if (args->args_count >1 ) + fwid |= (u16 )args->args[1 ] <<SMR_MASK_SHIFT ;Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain) · line 2714
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c +5
-0+else if (!of_property_read_u32 (args->np,"stream-match-mask" , &mask)) + fwid |= (u16 )mask <<SMR_MASK_SHIFT ; +dev_dbg (dev,"%s fwid:%08x mask:%08x args_count:%d\n" , + args->np->full_name, fwid, + mask, args->args_count);I don't understand why fwid is declared as u32 but used as a u16 below. Shouldn't it be declared as u16 in the first place?
Quoted 4 lines
Oh, it's my mistake. In Linux, the fwid will be passed to
iommu_fwspec_add_ids,
it requires u32 parameter. But after I ported this code to Xen, we passed the fwid toarm_smmu_add_generic_master_id, a u16 parameter is enoughu16 is not enough. If you look at the code you ported:
if (
args->args_count> 0)
fwid |= (u16)args->args[0];if (!of_property_read_u32(args->np, "stream-match-mask", &mask)
fwid |= mask <<SMR_MASK_SHIFT;
Quoted 8 lines
Quoted 4 lines
SMR_MASK_SHIFTis 16, so the top 16-bit will be set to the mask. With your u16 cast you loose those bits and therefore will not support properly SMMU when the property "stream-match-mask" has been set.Yes, that's the reason why we use u32. Thanks for your reminder, Although the
master->cfg.streamidsis using u16, we'd better to keep U32 here and add a warning message to notice whom set "stream-match-mask"
Even if you are using a u32 for fwid, you are still losing all the top 16 bits in the operations above because of the (u16) casts. This code looks wrong.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 6/7] xen/arm: SMMU: Support generic IOMMU bindings
Quoted 60 lines
-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 2017年7月6日 2:15
To: Wei Chen <[email protected]>
Cc: Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Kaly Xin <[email protected]>; nd <[email protected]>; Steve Capper <[email protected]>; [email protected]
Subject: Re: [Xen-devel] [PATCH 6/7] xen/arm: SMMU: Support generic IOMMU bindingsQuoted 1 line · Wei Chen
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
+static int arm_smmu_of_xlate(struct device *dev, struct
of_phandle_argsQuoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
*args)
Quoted 6 lines
xen/drivers/passthrough/arm/smmu.c +6
-0+{ +struct arm_smmu_device *smmu; +u32 mask =0 , fwid =0 ; + + smmu =find_smmu (dt_to_dev (args->np)); +if (!smmu) {xen/drivers/passthrough/arm/smmu.c static void arm_smmu_destroy_iommu_domain(struct iommu_domain *domain)
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c +10
-0+dev_err (dev,"Could not find smmu device!\n" ); +return -ENODEV ; + } + +if (args->args_count >0 ) + fwid |= (u16 )args->args[0 ]; + +if (args->args_count >1 ) + fwid |= (u16 )args->args[1 ] <<SMR_MASK_SHIFT ; + else if (!of_property_read_u32(args->np, "stream-match-mask",&mask))
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
xen/drivers/passthrough/arm/smmu.c +4
-0+ fwid |= (u16 )mask <<SMR_MASK_SHIFT ; +dev_dbg (dev,"%s fwid:%08x mask:%08x args_count:%d\n" , + args->np->full_name, fwid, + mask, args->args_count);Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
I don't understand why fwid is declared as u32 but used as a u16 below. Shouldn't it be declared as u16 in the first place?
Oh, it's my mistake. In Linux, the fwid will be passed to
iommu_fwspec_add_ids,
it requires u32 parameter. But after I ported this code to Xen, wepassed
Quoted 14 lines
Quoted 13 lines
Quoted 1 line
the fwid to
arm_smmu_add_generic_master_id, a u16 parameter is enoughu16 is not enough. If you look at the code you ported:
if (
args->args_count> 0)
fwid |= (u16)args->args[0];if (!of_property_read_u32(args->np, "stream-match-mask", &mask)
fwid |= mask <<SMR_MASK_SHIFT;
SMR_MASK_SHIFTis 16, so the top 16-bit will be set to the mask. With your u16 cast you loose those bits and therefore will not support properly SMMU when the property "stream-match-mask" has been set.
Quoted 7 lines
Quoted 3 lines
Yes, that's the reason why we use u32. Thanks for your reminder, Although the
master->cfg.streamidsis using u16, we'd better to keep U32 here and add a warning message to notice whom set "stream-match-mask"Even if you are using a u32 for fwid, you are still losing all the top 16 bits in the operations above because of the (u16) casts. This code looks wrong.
I think it's better to change thearm_smmu_add_generic_master_id(..., u16 fwid)
toarm_smmu_add_generic_master_id(..., u32 fwid). And keep the fwid in arm_smmu_of_xlate to u32 to guarantee the data integrity from device tree. Let arm_smmu_add_generic_master_id to determine whether to drop top 16-bits or not.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 7/7 xen: Fix a typo in error message of iommu_do_dt_domctl
In reply to Wei ChenIt's a error message about XEN_DOMCTL_deassign_device, but the print message is XEN_DOMCTL_assign_device.
--- xen/drivers/passthrough/device_tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/drivers/passthrough/device_tree.c +2 -2
@@ -209,8 +209,8 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, ret =iommu_deassign_dt_device (d, dev);if ( ret ) -printk (XENLOG_G_ERR "XEN_DOMCTL_assign_dt_device: assign \"%s\"" -" to dom%u failed (%d)\n" , +printk (XENLOG_G_ERR "XEN_DOMCTL_deassign_device: deassign \"%s\"" +" from dom%u failed (%d)\n" ,dt_node_full_name (dev), d->domain_id, ret);break ;
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 7/7] xen: Fix a typo in error message of iommu_do_dt_domctl
Quoted 4 lines · Wei Chen
It's a error message about
XEN_DOMCTL_deassign_device, but the print message isXEN_DOMCTL_assign_device.Signed-off-by Wei Chen <[email protected]>
Quoted 28 lines
--- xen/drivers/passthrough/device_tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xen/drivers/passthrough/device_tree.c +2
-2@@ -209,8 +209,8 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, ret =iommu_deassign_dt_device (d, dev);if ( ret ) -printk (XENLOG_G_ERR "XEN_DOMCTL_assign_dt_device: assign \"%s\"" -" to dom%u failed (%d)\n" , +printk (XENLOG_G_ERR "XEN_DOMCTL_deassign_device: deassign \"%s\"" +" from dom%u failed (%d)\n" ,dt_node_full_name (dev), d->domain_id, ret);break ;Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel