Re: [PATCH v12 2/2] iommu/mediatek: Allow page table PA up to 35bit

2022-07-04 Thread Yong Wu via iommu
On Thu, 2022-06-30 at 17:29 +0800, yf.w...@mediatek.com wrote: > From: Yunfei Wang > > Single memory zone feature will remove ZONE_DMA32 and ZONE_DMA. So > add > the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT to let level 1 and level > 2 > pgtable support at most 35bit PA. > > Signed-off-by: Ning

[PATCH v3 7/7] iommu/mediatek: Remove unused "mapping" member from mtk_iommu_data

2022-06-30 Thread Yong Wu via iommu
Just remove a unused variable that only is for mtk_iommu_v1. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno Reviewed-by: Matthias Brugger --- drivers/iommu/mtk_iommu.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c

[PATCH v3 6/7] iommu/mediatek: Improve safety for mediatek, smi property in larb nodes

2022-06-30 Thread Yong Wu via iommu
No functional change. Just improve safety from dts. All the larbs that connect to one IOMMU must connect with the same smi-common. This patch checks all the mediatek,smi property for each larb, If their mediatek,smi are different, it will return fails. Also avoid there is no available smi-larb

[PATCH v3 5/7] iommu/mediatek: Validate number of phandles associated with "mediatek, larbs"

2022-06-30 Thread Yong Wu via iommu
From: Guenter Roeck Fix the smatch warnings: drivers/iommu/mtk_iommu.c:878 mtk_iommu_mm_dts_parse() error: uninitialized symbol 'larbnode'. If someone abuse the dtsi node(Don't follow the definition of dt-binding), for example "mediatek,larbs" is provided as boolean property, "larb_nr" will be

[PATCH v3 4/7] iommu/mediatek: Add error path for loop of mm_dts_parse

2022-06-30 Thread Yong Wu via iommu
The mtk_iommu_mm_dts_parse will parse the smi larbs nodes. if the i+1 larb is parsed fail, we should put_device for the 0..i larbs. There are two places need to comment: 1) The larbid may be not linear mapping, we should loop whole the array in the error path. 2) I move this line position:

[PATCH v3 3/7] iommu/mediatek: Use component_match_add

2022-06-30 Thread Yong Wu via iommu
In order to simplify the error patch(avoid call of_node_put), Use component_match_add instead component_match_add_release since we are only interested in the "device" here. Then we could always call of_node_put in normal path. Strictly this is not a fixes patch, but it is a prepare for adding the

[PATCH v3 2/7] iommu/mediatek: Add platform_device_put for recovering the device refcnt

2022-06-30 Thread Yong Wu via iommu
Add platform_device_put to match with of_find_device_by_node. Meanwhile, I add a new variable "pcommdev" which is for smi common device. Otherwise, "platform_device_put(plarbdev)" for smi-common dev may be not readable. And add a checking for whether pcommdev is NULL. Fixes: d2e9a1102cfc

[PATCH v3 1/7] iommu/mediatek: Use dev_err_probe to mute probe_defer err log

2022-06-30 Thread Yong Wu via iommu
Mute the probe defer log: [2.654806] mtk-iommu 14018000.iommu: mm dts parse fail(-517). [2.656168] mtk-iommu 1c01f000.iommu: mm dts parse fail(-517). Fixes: d2e9a1102cfc ("iommu/mediatek: Contain MM IOMMU flow with the MM TYPE") Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del

[PATCH v3 0/7] iommu/mediatek: Improve safety from invalid dts input

2022-06-30 Thread Yong Wu via iommu
This patchset contains misc improve patches. Mainly to improve safety from invalid dts input. Change notes: v3: a) Add platform_device_put from Robin. b) Use component_match_add instead component_match_add_release suggested from Robin. v2:

Re: [PATCH v3 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

2022-06-30 Thread Yong Wu via iommu
On Wed, 2022-06-29 at 12:47 -0700, Nicolin Chen wrote: > On Fri, Jun 24, 2022 at 03:19:43PM -0300, Jason Gunthorpe wrote: > > On Fri, Jun 24, 2022 at 06:35:49PM +0800, Yong Wu wrote: > > > > > > > It's not used in VFIO context. "return 0" just satisfy the > > > > > iommu > > > > > framework to go

Re: [PATCH v3 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

2022-06-24 Thread Yong Wu via iommu
On Fri, 2022-06-24 at 06:16 +, Tian, Kevin wrote: > > From: Yong Wu > > Sent: Friday, June 24, 2022 1:39 PM > > > > On Thu, 2022-06-23 at 19:44 -0700, Nicolin Chen wrote: > > > On Fri, Jun 24, 2022 at 09:35:49AM +0800, Baolu Lu wrote: > > > > External email: Use caution opening links or

Re: [PATCH v3 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

2022-06-23 Thread Yong Wu via iommu
On Thu, 2022-06-23 at 19:44 -0700, Nicolin Chen wrote: > On Fri, Jun 24, 2022 at 09:35:49AM +0800, Baolu Lu wrote: > > External email: Use caution opening links or attachments > > > > > > On 2022/6/24 04:00, Nicolin Chen wrote: > > > diff --git a/drivers/iommu/mtk_iommu_v1.c > > >

Re: [PATCH v2 2/5] iommu/mediatek: Add error path for loop of mm_dts_parse

2022-06-22 Thread Yong Wu via iommu
On Thu, 2022-06-16 at 15:49 +0200, Matthias Brugger wrote: > > On 16/06/2022 07:42, Yong Wu wrote: > > The mtk_iommu_mm_dts_parse will parse the smi larbs nodes. if the > > i+1 > > larb is parsed fail(return -EINVAL), we should of_node_put for the > > 0..i > > larbs. In the fail path, one

Re: [PATCH v2 2/5] iommu/mediatek: Add error path for loop of mm_dts_parse

2022-06-22 Thread Yong Wu via iommu
On Thu, 2022-06-16 at 11:31 +0100, Robin Murphy wrote: > On 2022-06-16 11:08, Yong Wu wrote: > > On Thu, 2022-06-16 at 09:59 +0100, Robin Murphy wrote: > > > On 2022-06-16 06:42, Yong Wu wrote: > > > > The mtk_iommu_mm_dts_parse will parse the smi larbs nodes. if > > > > the > > > > i+1 > > > >

Re: [PATCH v10 1/2] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit

2022-06-21 Thread Yong Wu via iommu
On Thu, 2022-06-16 at 20:07 +0800, yf.w...@mediatek.com wrote: > From: Yunfei Wang > > Single memory zone feature will remove ZONE_DMA32 and ZONE_DMA and > cause pgtable PA size larger than 32bit. > > Since Mediatek IOMMU hardware support at most 35bit PA in pgtable, > so add a quirk to allow

Re: [PATCH v2 2/5] iommu/mediatek: Add error path for loop of mm_dts_parse

2022-06-16 Thread Yong Wu via iommu
On Thu, 2022-06-16 at 09:59 +0100, Robin Murphy wrote: > On 2022-06-16 06:42, Yong Wu wrote: > > The mtk_iommu_mm_dts_parse will parse the smi larbs nodes. if the > > i+1 > > larb is parsed fail(return -EINVAL), we should of_node_put for the > > 0..i > > larbs. In the fail path, one of_node_put

Re: [PATCH v3 6/6] iommu: mtk_iommu: Lookup phandle to retrieve syscon to pericfg

2022-06-16 Thread Yong Wu via iommu
On Mon, 2022-06-13 at 10:13 +0200, AngeloGioacchino Del Regno wrote: > Il 13/06/22 07:32, Yong Wu ha scritto: > > On Thu, 2022-06-09 at 12:08 +0200, AngeloGioacchino Del Regno > > wrote: > > > On some SoCs (of which only MT8195 is supported at the time of > > > writing), > > > the "R" and "W"

[PATCH v2 5/5] iommu/mediatek: Remove a unused "mapping" which is only for v1

2022-06-15 Thread Yong Wu via iommu
Just remove a unused variable that only is for mtk_iommu_v1. Fixes: 9485a04a5bb9 ("iommu/mediatek: Separate mtk_iommu_data for v1 and v2") Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c

[PATCH v2 4/5] iommu/mediatek: Improve safety for mediatek, smi property in larb nodes

2022-06-15 Thread Yong Wu via iommu
No functional change. Just improve safety from dts. All the larbs that connect to one IOMMU must connect with the same smi-common. This patch checks all the mediatek,smi property for each larb, If their mediatek,smi are different, it will return fails. Also avoid there is no available smi-larb

[PATCH v2 3/5] iommu/mediatek: Validate number of phandles associated with "mediatek, larbs"

2022-06-15 Thread Yong Wu via iommu
From: Guenter Roeck Fix the smatch warnings: drivers/iommu/mtk_iommu.c:878 mtk_iommu_mm_dts_parse() error: uninitialized symbol 'larbnode'. If someone abuse the dtsi node(Don't follow the definition of dt-binding), for example "mediatek,larbs" is provided as boolean property, "larb_nr" will be

[PATCH v2 2/5] iommu/mediatek: Add error path for loop of mm_dts_parse

2022-06-15 Thread Yong Wu via iommu
The mtk_iommu_mm_dts_parse will parse the smi larbs nodes. if the i+1 larb is parsed fail(return -EINVAL), we should of_node_put for the 0..i larbs. In the fail path, one of_node_put matches with of_parse_phandle in it. Fixes: d2e9a1102cfc ("iommu/mediatek: Contain MM IOMMU flow with the MM

[PATCH v2 1/5] iommu/mediatek: Use dev_err_probe to mute probe_defer err log

2022-06-15 Thread Yong Wu via iommu
Mute the probe defer log: [2.654806] mtk-iommu 14018000.iommu: mm dts parse fail(-517). [2.656168] mtk-iommu 1c01f000.iommu: mm dts parse fail(-517). Fixes: d2e9a1102cfc ("iommu/mediatek: Contain MM IOMMU flow with the MM TYPE") Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del

[PATCH v2 0/5] iommu/mediatek: Improve safety from dts

2022-06-15 Thread Yong Wu via iommu
This patchset contains misc improve patches: [1/5] When mt8195 v7, I added a error log for dts parse fail, but it doesn't ignore probe_defer case.(v6 doesn't have this err log.) [2/5] Add a error path for MM dts parse. [3/5][4/5] To improve safety from dts. Base on this:

Re: [PATCH v8 1/3] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit

2022-06-15 Thread Yong Wu via iommu
On Tue, 2022-06-14 at 13:56 +0100, Will Deacon wrote: > > @@ -74,17 +74,22 @@ struct io_pgtable_cfg { > > * to support up to 35 bits PA where the bit32, bit33 and > > bit34 are > > * encoded in the bit9, bit4 and bit5 of the PTE respectively. > > * > > +*

Re: [PATCH v8 3/3] iommu/mediatek: Allow page table PA up to 35bit

2022-06-13 Thread Yong Wu via iommu
On Sat, 2022-06-11 at 18:26 +0800, yf.w...@mediatek.com wrote: > From: Yunfei Wang > > Single memory zone feature will remove ZONE_DMA32 and ZONE_DMA. So > add > the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT to let level 1 and level > 2 > pgtable support at most 35bit PA. > > Signed-off-by: Ning

Re: [PATCH v8 2/3] iommu/mediatek: Rename MTK_IOMMU_TLB_ADDR to MTK_IOMMU_ADDR

2022-06-13 Thread Yong Wu via iommu
On Sat, 2022-06-11 at 18:26 +0800, yf.w...@mediatek.com wrote: > From: Yunfei Wang > > Rename MTK_IOMMU_TLB_ADDR to MTK_IOMMU_ADDR, and update > MTK_IOMMU_ADDR > definition for better generality. Comment more about why you need this. Prepare for supporting TTBR up to 35bit which also need this

Re: [PATCH v3 3/3] iommu: mtk_iommu: Add support for MT6795 Helio X10 M4Us

2022-06-12 Thread Yong Wu via iommu
On Thu, 2022-06-09 at 12:40 +0200, AngeloGioacchino Del Regno wrote: > Add support for the M4Us found in the MT6795 Helio X10 SoC. > > Signed-off-by: AngeloGioacchino Del Regno < > angelogioacchino.delre...@collabora.com> Retitle to: iommu/mediatek: Xxx, then Reviewed-by: Yong Wu > --- >

Re: [PATCH v3 1/3] dt-bindings: mediatek: Add bindings for MT6795 M4U

2022-06-12 Thread Yong Wu via iommu
On Thu, 2022-06-09 at 12:39 +0200, AngeloGioacchino Del Regno wrote: > Add bindings for the MediaTek Helio X10 (MT6795) IOMMU/M4U. > > Signed-off-by: AngeloGioacchino Del Regno < > angelogioacchino.delre...@collabora.com> > Acked-by: Rob Herring > --- > .../bindings/iommu/mediatek,iommu.yaml

Re: [PATCH v3 2/3] iommu: mtk_iommu: Introduce new flag TF_PORT_TO_ADDR_MT8173

2022-06-12 Thread Yong Wu via iommu
On Thu, 2022-06-09 at 12:40 +0200, AngeloGioacchino Del Regno wrote: > In preparation for adding support for MT6795, add a new flag named > TF_PORT_TO_ADDR_MT8173 and use that instead of checking for m4u_plat > type in mtk_iommu_hw_init() to avoid seeing a long list of m4u_plat > checks there in

Re: [PATCH v3 6/6] iommu: mtk_iommu: Lookup phandle to retrieve syscon to pericfg

2022-06-12 Thread Yong Wu via iommu
On Thu, 2022-06-09 at 12:08 +0200, AngeloGioacchino Del Regno wrote: > On some SoCs (of which only MT8195 is supported at the time of > writing), > the "R" and "W" (I/O) enable bits for the IOMMUs are in the > pericfg_ao > register space and not in the IOMMU space: as it happened already > with >

Re: [PATCH v3 2/6] iommu: mtk_iommu: Lookup phandle to retrieve syscon to infracfg

2022-06-12 Thread Yong Wu via iommu
On Thu, 2022-06-09 at 12:07 +0200, AngeloGioacchino Del Regno wrote: > This driver will get support for more SoCs and the list of infracfg > compatibles is expected to grow: in order to prevent getting this > situation out of control and see a long list of compatible strings, > add support to

Re: [PATCH 1/3] dt-bindings: iommu: mediatek: add binding documentation for MT8365 SoC

2022-06-02 Thread Yong Wu via iommu
On Thu, 2022-06-02 at 16:42 +0800, Macpaul Lin wrote: > On 6/2/22 4:27 PM, Macpaul Lin wrote: > > On 6/2/22 2:18 PM, Yong Wu wrote: > > > On Mon, 2022-05-30 at 20:03 +0200, Fabien Parent wrote: > > > > Add IOMMU binding documentation for the MT8365 SoC. > > > > > > > > Signed-off-by: Fabien

Re: [PATCH 2/3] iommu: mtk_iommu: add support for 6-bit encoded port IDs

2022-06-02 Thread Yong Wu via iommu
Hi Fabien, Thanks for very much for this patch. Retitle to iommu/mediatek: Xxx On Mon, 2022-05-30 at 20:03 +0200, Fabien Parent wrote: > Until now the port ID was always encoded as a 5-bit data. On MT8365, > the port ID is encoded as a 6-bit data. This requires to rework the > macros

Re: [PATCH 1/3] dt-bindings: iommu: mediatek: add binding documentation for MT8365 SoC

2022-06-02 Thread Yong Wu via iommu
On Mon, 2022-05-30 at 20:03 +0200, Fabien Parent wrote: > Add IOMMU binding documentation for the MT8365 SoC. > > Signed-off-by: Fabien Parent > --- > .../bindings/iommu/mediatek,iommu.yaml| 2 + > include/dt-bindings/memory/mt8365-larb-port.h | 96 > +++ > 2 files

Re: [PATCH v2 3/7] iommu: mtk_iommu: Lookup phandle to retrieve syscon to pericfg

2022-05-26 Thread Yong Wu via iommu
On Wed, 2022-05-18 at 12:04 +0200, AngeloGioacchino Del Regno wrote: > On some SoCs (of which only MT8195 is supported at the time of > writing), > the "R" and "W" (I/O) enable bits for the IOMMUs are in the > pericfg_ao > register space and not in the IOMMU space: as it happened already > with >

Re: [PATCH v2 2/7] iommu: mtk_iommu: Lookup phandle to retrieve syscon to infracfg

2022-05-26 Thread Yong Wu via iommu
On Wed, 2022-05-18 at 12:04 +0200, AngeloGioacchino Del Regno wrote: > This driver will get support for more SoCs and the list of infracfg > compatibles is expected to grow: in order to prevent getting this > situation out of control and see a long list of compatible strings, > add support to

Re: [PATCH v2 1/7] dt-bindings: iommu: mediatek: Add phandles for mediatek infra/pericfg

2022-05-26 Thread Yong Wu via iommu
On Wed, 2022-05-18 at 12:04 +0200, AngeloGioacchino Del Regno wrote: > Add properties "mediatek,infracfg" and "mediatek,pericfg" to let the > mtk_iommu driver retrieve phandles to the infracfg and pericfg > syscon(s) > instead of performing a per-soc compatible lookup. > > Signed-off-by:

Re: [PATCH v2 2/2] iommu: mtk_iommu: Add support for MT6795 Helio X10 M4Us

2022-05-26 Thread Yong Wu via iommu
On Wed, 2022-05-18 at 12:18 +0200, AngeloGioacchino Del Regno wrote: > Add support for the M4Us found in the MT6795 Helio X10 SoC. > > Signed-off-by: AngeloGioacchino Del Regno < > angelogioacchino.delre...@collabora.com> > --- > drivers/iommu/mtk_iommu.c | 17 - > 1 file

Re: [PATCH v5 2/2] iommu/mediatek: Allow page table PA up to 35bit

2022-05-19 Thread Yong Wu via iommu
On Mon, 2022-05-16 at 22:16 +0800, yf.w...@mediatek.com wrote: > From: Yunfei Wang > > Add the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT support, so that > allows > page table PA up to 35bit, not only in ZONE_DMA32. Comment why this is needed. e.g. For single normal zone. > > Signed-off-by:

Re: [PATCH 2/2] iommu: mtk_iommu: Add support for MT6795 Helio X10 M4Us

2022-05-17 Thread Yong Wu via iommu
On Tue, 2022-05-17 at 11:26 +0200, AngeloGioacchino Del Regno wrote: > Il 17/05/22 11:08, Yong Wu ha scritto: > > On Fri, 2022-05-13 at 17:14 +0200, AngeloGioacchino Del Regno > > wrote: > > > Add support for the M4Us found in the MT6795 Helio X10 SoC. > > > > > > Signed-off-by: AngeloGioacchino

Re: [PATCH 2/2] iommu: mtk_iommu: Add support for MT6795 Helio X10 M4Us

2022-05-17 Thread Yong Wu via iommu
On Fri, 2022-05-13 at 17:14 +0200, AngeloGioacchino Del Regno wrote: > Add support for the M4Us found in the MT6795 Helio X10 SoC. > > Signed-off-by: AngeloGioacchino Del Regno < > angelogioacchino.delre...@collabora.com> > --- > drivers/iommu/mtk_iommu.c | 20 +++- > 1 file

Re: [PATCH] iommu/dma: Fix iova map result check bug

2022-05-11 Thread Yong Wu via iommu
On Sat, 2022-05-07 at 16:52 +0800, yf.w...@mediatek.com wrote: > From: Yunfei Wang > > The data type of the return value of the iommu_map_sg_atomic > is ssize_t, but the data type of iova size is size_t, > e.g. one is int while the other is unsigned int. > > When iommu_map_sg_atomic return

[PATCH 4/4] iommu/mediatek: Improve safety for mediatek, smi property in larb nodes

2022-05-11 Thread Yong Wu via iommu
No functional change. Just improve safety from dts. All the larbs that connect to one IOMMU must connect with the same smi-common. This patch checks all the mediatek,smi property for each larb, If their mediatek,smi are different, it will return fails. Also avoid there is no available smi-larb

[PATCH 3/4] iommu/mediatek: Validate number of phandles associated with "mediatek, larbs"

2022-05-11 Thread Yong Wu via iommu
From: Guenter Roeck Fix the smatch warnings: drivers/iommu/mtk_iommu.c:878 mtk_iommu_mm_dts_parse() error: uninitialized symbol 'larbnode'. If someone abuse the dtsi node(Don't follow the definition of dt-binding), for example "mediatek,larbs" is provided as boolean property, the code may

[PATCH 2/4] iommu/mediatek: Add error path for loop of mm_dts_parse

2022-05-11 Thread Yong Wu via iommu
The mtk_iommu_mm_dts_parse will parse the smi larbs nodes. if the i+1 larb is parsed fail(return -EINVAL), we should of_node_put for the 0..i larbs. Fixes: d2e9a1102cfc ("iommu/mediatek: Contain MM IOMMU flow with the MM TYPE") Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 21

[PATCH 1/4] iommu/mediatek: Use dev_err_probe to mute probe_defer err log

2022-05-11 Thread Yong Wu via iommu
Mute the probe defer log: [2.654806] mtk-iommu 14018000.iommu: mm dts parse fail(-517). [2.656168] mtk-iommu 1c01f000.iommu: mm dts parse fail(-517). Fixes: d2e9a1102cfc ("iommu/mediatek: Contain MM IOMMU flow with the MM TYPE") Signed-off-by: Yong Wu --- The Fixes tag commit-id is from

[PATCH 0/4] iommu/mediatek: Improve safety from dts

2022-05-11 Thread Yong Wu via iommu
This patchset contains several improved patches: [1/4] When mt8195 v7, I added a error log for dts parse fail, but it doesn't ignore probe_defer case.(v6 doesn't have this err log.) [2/4] Add a error path for MM dts parse. [3/4][4/4] To improve safety from dts. Base on this:

Re: [PATCH v3] iommu/mediatek: Fix NULL pointer dereference when printing dev_name

2022-05-05 Thread Yong Wu via iommu
On Thu, 2022-05-05 at 21:27 +0800, Miles Chen wrote: > When larbdev is NULL (in the case I hit, the node is incorrectly set > iommus = < NUM>), it will cause device_link_add() fail and > kernel crashes when we try to print dev_name(larbdev). > > Let's fail the probe if a larbdev is NULL to avoid

Re: [PATCH 2/2] iommu/mediatek: Enable allocating page table in normal memory

2022-05-03 Thread Yong Wu via iommu
Hi YF, Thanks very much for this patch. Nearly all the lastest SoC like mt8192/mt8195 support this. On Fri, 2022-04-29 at 22:34 +0800, yf.w...@mediatek.com wrote: > From: Yunfei Wang > > Add the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT support, so that > level 2 page table can allocate in

[PATCH v7 36/36] iommu/mediatek: Add mt8186 iommu support

2022-05-03 Thread Yong Wu via iommu
Add mt8186 iommu supports. Signed-off-by: Anan Sun Signed-off-by: Yong Wu Reviewed-by: Matthias Brugger Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 16 1 file changed, 16 insertions(+) diff --git a/drivers/iommu/mtk_iommu.c

[PATCH v7 35/36] iommu/mediatek: mt8195: Enable multi banks for infra iommu

2022-05-03 Thread Yong Wu via iommu
Enable the multi-bank functions for infra-iommu. We put PCIE in bank0 and USB in the last bank(bank4). and we don't use the other banks currently, disable them. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 7 +-- 1 file changed, 5

[PATCH v7 34/36] iommu/mediatek: Backup/restore regsiters for multi banks

2022-05-03 Thread Yong Wu via iommu
Each bank has some independent registers. thus backup/restore them for each a bank when suspend and resume. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 46 ++- 1 file changed, 31 insertions(+), 15

[PATCH v7 33/36] iommu/mediatek: Initialise/Remove for multi bank dev

2022-05-03 Thread Yong Wu via iommu
The registers for each bank of the IOMMU base are in order, delta is 0x1000. Initialise the base for each bank. For all the previous SoC, we only have bank0. thus use "do {} while()" to allow bank0 always go. When removing the device, Not always all the banks are initialised, it depend on if

[PATCH v7 32/36] iommu/mediatek: Get the proper bankid for multi banks

2022-05-03 Thread Yong Wu via iommu
We preassign some ports in a special bank via the new defined banks_portmsk. Put it in the plat_data means it is not expected to be adjusted dynamically. If the iommu id in the iommu consumer's dtsi node is inside this banks_portmsk, then we switch it to this special iommu bank, and initialise

[PATCH v7 31/36] iommu/mediatek: Change the domid to iova_region_id

2022-05-03 Thread Yong Wu via iommu
Prepare for adding bankid, also no functional change. In the previous SoC, each a iova_region is a domain; In the multi-banks case, each a bank is a domain, then the original function name "mtk_iommu_get_domain_id" is not proper. Use "iova_region_id" instead of "domain_id". Signed-off-by: Yong

[PATCH v7 30/36] iommu/mediatek: Initialise bank HW for each a bank

2022-05-03 Thread Yong Wu via iommu
The mt8195 IOMMU HW max support 5 banks, and regarding the banks' registers, it looks like: |bank0 | bank1 | bank2 | bank3 | bank4| |global | |control| null |regs |

[PATCH v7 29/36] iommu/mediatek: Add mtk_iommu_bank_data structure

2022-05-03 Thread Yong Wu via iommu
Prepare for supporting multi-banks for the IOMMU HW, No functional change. Add a new structure(mtk_iommu_bank_data) for each a bank. Each a bank have the independent HW base/IRQ/tlb-range ops, and each a bank has its special iommu-domain(independent pgtable), thus, also move the domain

[PATCH v7 28/36] iommu/mediatek-v1: Just rename mtk_iommu to mtk_iommu_v1

2022-05-03 Thread Yong Wu via iommu
No functional change. Just rename this for readable. Differentiate this from mtk_iommu.c Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu_v1.c | 211 +-- 1 file changed, 103 insertions(+), 108 deletions(-) diff --git

[PATCH v7 27/36] iommu/mediatek: Remove mtk_iommu.h

2022-05-03 Thread Yong Wu via iommu
Currently there is a suspend structure in the header file. It's no need to keep a header file only for this. Move these into the c file and rm this header file. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c| 14 +-

[PATCH v7 26/36] iommu/mediatek: Separate mtk_iommu_data for v1 and v2

2022-05-03 Thread Yong Wu via iommu
Prepare for adding the structure "mtk_iommu_bank_data". No functional change. The mtk_iommu_domain in v1 and v2 are different, we could not add current data as bank[0] in v1 simplistically. Currently we have no plan to add new SoC for v1, in order to avoid affect v1 when we add many new features

[PATCH v7 25/36] iommu/mediatek: Just move code position in hw_init

2022-05-03 Thread Yong Wu via iommu
No functional change too, prepare for mt8195 IOMMU support bank functions. Some global control settings are in bank0 while the other banks have their bank independent setting. Here only move the global control settings and the independent registers together. Signed-off-by: Yong Wu Reviewed-by:

[PATCH v7 24/36] iommu/mediatek: Only adjust code about register base

2022-05-03 Thread Yong Wu via iommu
No functional change. Use "base" instead of the data->base. This is avoid to touch too many lines in the next patches. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 51 +-- 1 file changed, 27 insertions(+),

[PATCH v7 23/36] iommu/mediatek: Add mt8195 support

2022-05-03 Thread Yong Wu via iommu
mt8195 has 3 IOMMU, containing 2 MM IOMMUs, one is for vdo, the other is for vpp. and 1 INFRA IOMMU. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 41 +++ drivers/iommu/mtk_iommu.h | 1 + 2 files changed, 42

[PATCH v7 21/36] iommu/mediatek: Add infra iommu support

2022-05-03 Thread Yong Wu via iommu
The infra iommu enable bits in mt8195 is in the pericfg register segment, use regmap to update it. If infra iommu master translation fault, It doesn't have the larbid/portid, thus print out the whole register value. Since regmap_update_bits may fail, add return value for mtk_iommu_config.

[PATCH v7 22/36] iommu/mediatek: Add PCIe support

2022-05-03 Thread Yong Wu via iommu
Currently the code for of_iommu_configure_dev_id is like this: static int of_iommu_configure_dev_id(struct device_node *master_np, struct device *dev, const u32 *id) { struct of_phandle_args iommu_spec = {

[PATCH v7 20/36] iommu/mediatek: Add a PM_CLK_AO flag for infra iommu

2022-05-03 Thread Yong Wu via iommu
The power/clock of infra iommu is always on, and it doesn't have the device link with the master devices, then the infra iommu device's PM status is not active, thus we add A PM_CLK_AO flag for infra iommu. The tlb operation is a bit not clear here, there are 2 special cases. Comment them in the

[PATCH v7 19/36] iommu/mediatek: Allow IOMMU_DOMAIN_UNMANAGED for PCIe VFIO

2022-05-03 Thread Yong Wu via iommu
Allow the type IOMMU_DOMAIN_UNMANAGED since vfio_iommu_type1.c always call iommu_domain_alloc. The PCIe EP works ok when going through vfio. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff

[PATCH v7 18/36] iommu/mediatek: Adjust device link when it is sub-common

2022-05-03 Thread Yong Wu via iommu
For MM IOMMU, We always add device link between smi-common and IOMMU HW. In mt8195, we add smi-sub-common. Thus, if the node is sub-common, we still need find again to get smi-common, then do device link. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno ---

[PATCH v7 17/36] iommu/mediatek: Contain MM IOMMU flow with the MM TYPE

2022-05-03 Thread Yong Wu via iommu
Prepare for supporting INFRA_IOMMU, and APU_IOMMU later. For Infra IOMMU/APU IOMMU, it doesn't have the "larb""port". thus, Use the MM flag contain the MM_IOMMU special flow, Also, it moves a big chunk code about parsing the mediatek,larbs into a function, this is only needed for MM IOMMU. and

[PATCH v7 16/36] iommu/mediatek: Add IOMMU_TYPE flag

2022-05-03 Thread Yong Wu via iommu
Add IOMMU_TYPE definition. In the mt8195, we have another IOMMU_TYPE: infra iommu, also there will be another APU_IOMMU, thus, use 2bits for the IOMMU_TYPE. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 12 ++-- 1 file changed, 10

[PATCH v7 15/36] iommu/mediatek: Add SUB_COMMON_3BITS flag

2022-05-03 Thread Yong Wu via iommu
In prevous SoC, the sub common id occupy 2 bits. the mt8195's sub common id has 3bits. Add a new flag for this. and rename the previous flag to _2BITS. For readable, I put these two flags together, then move the other flags. no functional change. Signed-off-by: Yong Wu Reviewed-by:

[PATCH v7 14/36] iommu/mediatek: Always enable output PA over 32bits in isr

2022-05-03 Thread Yong Wu via iommu
Currently the output PA[32:33] is contained by the flag IOVA_34. This is not right. the iova_34 has no relation with pa[32:33], the 32bits iova still could map to pa[32:33]. Move it out from the flag. No need fix tag since currently only mt8192 use the calulation and it always has this IOVA_34

[PATCH v7 13/36] iommu/mediatek: Remove the granule in the tlb flush

2022-05-03 Thread Yong Wu via iommu
The MediaTek IOMMU doesn't care about granule when tlb flushing. Remove this variable. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c

[PATCH v7 12/36] iommu/mediatek: Add a flag STD_AXI_MODE

2022-05-03 Thread Yong Wu via iommu
Add a new flag STD_AXI_MODE which is prepared for infra and apu iommu which use the standard axi mode. All the current SoC don't use this flag. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)

[PATCH v7 11/36] iommu/mediatek: Add a flag DCM_DISABLE

2022-05-03 Thread Yong Wu via iommu
In the infra iommu, we should disable DCM. add a new flag for this. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 9 - 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c

[PATCH v7 10/36] iommu/mediatek: Add 12G~16G support for multi domains

2022-05-03 Thread Yong Wu via iommu
In mt8192, we preassign 0-4G; 4G-8G; 8G-12G for different multimedia engines. This depends on the "dma-ranges=" in the iommu consumer's dtsi node. Adds 12G-16G region here. and reword the previous comment. we don't limit which master locate in which region. CCU still is 8G-12G. Don't change it

[PATCH v7 09/36] iommu/mediatek: Adapt sharing and non-sharing pgtable case

2022-05-03 Thread Yong Wu via iommu
In previous mt2712, Both IOMMUs are MM IOMMU, and they will share pgtable. However in the latest SoC, another is infra IOMMU, there is no reason to share pgtable between MM with INFRA IOMMU. This patch manage to implement the two case(sharing and non-sharing pgtable). Currently we use

[PATCH v7 08/36] iommu/mediatek: Add mutex for data in the mtk_iommu_domain

2022-05-03 Thread Yong Wu via iommu
Same with the previous patch, add a mutex for the "data" in the mtk_iommu_domain. Just improve the safety for multi devices enter attach_device at the same time. We don't get the real issue for this. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c

[PATCH v7 07/36] iommu/mediatek: Add mutex for m4u_group and m4u_dom in data

2022-05-03 Thread Yong Wu via iommu
Add a mutex to protect the data in the structure mtk_iommu_data, like ->"m4u_group" ->"m4u_dom". For the internal data, we should protect it in ourselves driver. Add a mutex for this. This could be a fix for the multi-groups support. Fixes: c3045f39244e ("iommu/mediatek: Support for multi

[PATCH v7 05/36] iommu/mediatek: Add list_del in mtk_iommu_remove

2022-05-03 Thread Yong Wu via iommu
Lack the list_del in the mtk_iommu_remove, and remove bus_set_iommu(*, NULL) since there may be several iommu HWs. we can not bus_set_iommu null when one iommu driver unbind. This could be a fix for mt2712 which support 2 M4U HW and list them. Fixes: 7c3a2ec02806 ("iommu/mediatek: Merge 2 M4U

[PATCH v7 06/36] iommu/mediatek: Remove clk_disable in mtk_iommu_remove

2022-05-03 Thread Yong Wu via iommu
After the commit b34ea31fe013 ("iommu/mediatek: Always enable the clk on resume"), the iommu clock is controlled by the runtime callback. thus remove the clk control in the mtk_iommu_remove. Otherwise, it will warning like: echo 14018000.iommu > /sys/bus/platform/drivers/mtk-iommu/unbind [

[PATCH v7 04/36] iommu/mediatek: Fix 2 HW sharing pgtable issue

2022-05-03 Thread Yong Wu via iommu
In the commit 4f956c97d26b ("iommu/mediatek: Move domain_finalise into attach_device"), I overlooked the sharing pgtable case. After that commit, the "data" in the mtk_iommu_domain_finalise always is the data of the current IOMMU HW. Fix this for the sharing pgtable case. Only affect mt2712 which

[PATCH v7 03/36] dt-bindings: mediatek: mt8186: Add binding for MM iommu

2022-05-03 Thread Yong Wu via iommu
Add mt8186 iommu binding. "-mm" means the iommu is for Multimedia. Signed-off-by: Yong Wu Acked-by: Krzysztof Kozlowski Reviewed-by: Rob Herring Reviewed-by: Matthias Brugger Reviewed-by: AngeloGioacchino Del Regno --- .../bindings/iommu/mediatek,iommu.yaml| 4 +

[PATCH v7 02/36] dt-bindings: mediatek: mt8195: Add binding for infra IOMMU

2022-05-03 Thread Yong Wu via iommu
In mt8195, we have a new IOMMU that is for INFRA IOMMU. its masters mainly are PCIe and USB. Different with MM IOMMU, all these masters connect with IOMMU directly, there is no mediatek,larbs property for infra IOMMU. Another thing is about PCIe ports. currently the function

[PATCH v7 01/36] dt-bindings: mediatek: mt8195: Add binding for MM IOMMU

2022-05-03 Thread Yong Wu via iommu
This patch adds descriptions for mt8195 IOMMU which also use ARM Short-Descriptor translation table format. In mt8195, there are two smi-common HW and IOMMU, one is for vdo(video output), the other is for vpp(video processing pipe). They connects with different smi-larbs, then some

[PATCH v7 00/36] MT8195 and MT8186 IOMMU SUPPORT

2022-05-03 Thread Yong Wu via iommu
This patchset adds MT8195 and MT8186 iommu support. MT8195 have 3 IOMMU HWs. 2 IOMMU HW is for multimedia, and 1 IOMMU HW is for infra-master, like PCIe/USB. About the 2 MM IOMMU HW, something like this: IOMMU(VDO) IOMMU(VPP) | |

Re: [PATCH v6 31/34] iommu/mediatek: Get the proper bankid for multi banks

2022-04-30 Thread Yong Wu via iommu
Hi Matthias, Thanks very much for reviewing. On Thu, 2022-04-28 at 16:14 +0200, Matthias Brugger wrote: > > On 07/04/2022 09:57, Yong Wu wrote: > > We preassign some ports in a special bank via the new defined > > banks_portmsk. Put it in the plat_data means it is not expected to > > be > >

Re: [PATCH v2] iommu/mediatek: fix NULL pointer dereference when printing dev_name

2022-04-25 Thread Yong Wu via iommu
On Mon, 2022-04-25 at 11:03 +0100, Robin Murphy wrote: > On 2022-04-25 09:24, Miles Chen via iommu wrote: > > When larbdev is NULL (in the case I hit, the node is incorrectly > > set > > iommus = < NUM>), it will cause device_link_add() fail and > > kernel crashes when we try to print

[PATCH v3 2/2] iommu/mediatek: Add mt8186 iommu support

2022-04-07 Thread Yong Wu via iommu
Add mt8186 iommu supports. Signed-off-by: Anan Sun Signed-off-by: Yong Wu Reviewed-by: Matthias Brugger --- drivers/iommu/mtk_iommu.c | 17 + 1 file changed, 17 insertions(+) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 22c95ed78b3c..8d2b6dc89177

[PATCH v3 1/2] dt-bindings: mediatek: mt8186: Add binding for MM iommu

2022-04-07 Thread Yong Wu via iommu
Add mt8186 iommu binding. "-mm" means the iommu is for Multimedia. Signed-off-by: Yong Wu Acked-by: Krzysztof Kozlowski Reviewed-by: Rob Herring Reviewed-by: Matthias Brugger --- .../bindings/iommu/mediatek,iommu.yaml| 4 + .../dt-bindings/memory/mt8186-memory-port.h | 217

[PATCH v3 0/2] MT8186 IOMMU SUPPORT

2022-04-07 Thread Yong Wu via iommu
This patchset adds mt8186 iommu support. Change note: v3: Rebase on v5.18-rc1 and mt8195 iommu v6: https://lore.kernel.org/linux-iommu/20220407075726.17771-1-yong...@mediatek.com/ v2: https://lore.kernel.org/linux-iommu/20220223072402.17518-1-yong...@mediatek.com/ a)Base on v5.17-rc1

[PATCH v6 34/34] iommu/mediatek: mt8195: Enable multi banks for infra iommu

2022-04-07 Thread Yong Wu via iommu
Enable the multi-bank functions for infra-iommu. We put PCIE in bank0 and USB in the last bank(bank4). and we don't use the other banks currently, disable them. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 7 +-- 1 file changed, 5

[PATCH v6 33/34] iommu/mediatek: Backup/restore regsiters for multi banks

2022-04-07 Thread Yong Wu via iommu
Each bank has some independent registers. thus backup/restore them for each a bank when suspend and resume. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 46 ++- 1 file changed, 31 insertions(+), 15

[PATCH v6 32/34] iommu/mediatek: Initialise/Remove for multi bank dev

2022-04-07 Thread Yong Wu via iommu
The registers for each bank of the IOMMU base are in order, delta is 0x1000. Initialise the base for each bank. For all the previous SoC, we only have bank0. thus use "do {} while()" to allow bank0 always go. When removing the device, Not always all the banks are initialised, it depend on if

[PATCH v6 31/34] iommu/mediatek: Get the proper bankid for multi banks

2022-04-07 Thread Yong Wu via iommu
We preassign some ports in a special bank via the new defined banks_portmsk. Put it in the plat_data means it is not expected to be adjusted dynamically. If the iommu id in the iommu consumer's dtsi node is inside this banks_portmsk, then we switch it to this special iommu bank, and initialise

[PATCH v6 30/34] iommu/mediatek: Change the domid to iova_region_id

2022-04-07 Thread Yong Wu via iommu
Prepare for adding bankid, also no functional change. In the previous SoC, each a iova_region is a domain; In the multi-banks case, each a bank is a domain, then the original function name "mtk_iommu_get_domain_id" is not proper. Use "iova_region_id" instead of "domain_id". Signed-off-by: Yong

[PATCH v6 28/34] iommu/mediatek: Add mtk_iommu_bank_data structure

2022-04-07 Thread Yong Wu via iommu
Prepare for supporting multi-banks for the IOMMU HW, No functional change. Add a new structure(mtk_iommu_bank_data) for each a bank. Each a bank have the independent HW base/IRQ/tlb-range ops, and each a bank has its special iommu-domain(independent pgtable), thus, also move the domain

[PATCH v6 29/34] iommu/mediatek: Initialise bank HW for each a bank

2022-04-07 Thread Yong Wu via iommu
The mt8195 IOMMU HW max support 5 banks, and regarding the banks' registers, it looks like: |bank0 | bank1 | bank2 | bank3 | bank4| |global | |control| null |regs |

[PATCH v6 27/34] iommu/mediatek-v1: Just rename mtk_iommu to mtk_iommu_v1

2022-04-07 Thread Yong Wu via iommu
No functional change. Just rename this for readable. Differentiate this from mtk_iommu.c Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu_v1.c | 211 +-- 1 file changed, 103 insertions(+), 108 deletions(-) diff --git

[PATCH v6 26/34] iommu/mediatek: Remove mtk_iommu.h

2022-04-07 Thread Yong Wu via iommu
Currently there is a suspend structure in the header file. It's no need to keep a header file only for this. Move these into the c file and rm this header file. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c| 14 +-

  1   2   >