• Yong Wu's avatar
    iommu/mediatek: Fix iova_to_phys PA start for 4GB mode · 7cc6d758
    Yong Wu authored
    [ Upstream commit 76ce6546 ]
    
    In M4U 4GB mode, the physical address is remapped as below:
    
    CPU Physical address:
    
    ====================
    
    0      1G       2G     3G       4G     5G
    |---A---|---B---|---C---|---D---|---E---|
    +--I/O--+------------Memory-------------+
    
    IOMMU output physical address:
     =============================
    
                                    4G      5G     6G      7G      8G
                                    |---E---|---B---|---C---|---D---|
                                    +------------Memory-------------+
    
    The Region 'A'(I/O) can not be mapped by M4U; For Region 'B'/'C'/'D', the
    bit32 of the CPU physical address always is needed to set, and for Region
    'E', the CPU physical address keep as is. something looks like this:
    CPU PA         ->    M4U OUTPUT PA
    0x4000_0000          0x1_4000_0000 (Add bit32)
    0x8000_0000          0x1_8000_0000 ...
    0xc000_0000          0x1_c000_0000 ...
    0x1_0000_0000        0x1_0000_0000 (No change)
    
    Additionally, the iommu consumers always use the CPU phyiscal address.
    
    The PA in the iova_to_phys that is got from v7s always is u32, But
    from the CPU point of view, PA only need add BIT(32) when PA < 0x4000_0000.
    
    Fixes: 30e2fccf ("iommu/mediatek: Enlarge the validate PA range
    for 4GB mode")
    Signed-off-by: default avatarYong Wu <yong.wu@mediatek.com>
    Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
    Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
    7cc6d758
mtk_iommu.c 21.4 KB