Skip to content

BCM2712 IOMMU: Allocate tables on demand; make IOVA base address and size configurable#6997

Closed
njhollinghurst wants to merge 1 commit intoraspberrypi:rpi-6.12.yfrom
njhollinghurst:iommu-202508
Closed

BCM2712 IOMMU: Allocate tables on demand; make IOVA base address and size configurable#6997
njhollinghurst wants to merge 1 commit intoraspberrypi:rpi-6.12.yfrom
njhollinghurst:iommu-202508

Conversation

@njhollinghurst
Copy link
Contributor

@njhollinghurst njhollinghurst commented Aug 12, 2025

The first change is a draft of something we might actually want to do for Raspberry Pi 5.
The second change is just for testing, to see if increasing IOVA can help resolve an issue with two 64Mpix cameras.

This has now been rebased and includes allocate-on-demand.

@njhollinghurst njhollinghurst changed the title Make BCM2712 IOMMU IOVA base address and size configurable BCM2712 IOMMU: Allocate tables on demand; make IOVA base address and size configurable Aug 15, 2025
@njhollinghurst
Copy link
Contributor Author

njhollinghurst commented Aug 15, 2025

Briefly tested with labwc (4K HDMI plus DPI), chromium-browser, rpicam-still, ffplay; to exercise all three IOMMUs for RP1 (CFE, DPI), Codecs (ISP-BE, HEVC) and HVS, while also testing bypass for RP1.

In this scenario, IOMMU allocated (16K) pages reached 93, so the change seems to be saving about 4.5 MBytes.

More soak testing would be advisable.

@njhollinghurst njhollinghurst force-pushed the iommu-202508 branch 2 times, most recently from d638a92 to 5e8b30d Compare August 15, 2025 17:10
@njhollinghurst njhollinghurst marked this pull request as ready for review August 15, 2025 18:06
@njhollinghurst njhollinghurst marked this pull request as draft August 16, 2025 15:17
@njhollinghurst njhollinghurst force-pushed the iommu-202508 branch 4 times, most recently from 5e474ac to 35f25eb Compare August 19, 2025 12:33
@njhollinghurst
Copy link
Contributor Author

After speaking to @jc-kynesim I've reverted the freeing of unused tables (seen in some of the intermediate pushes but no longer present in the commit); tables pages are retained for re-use.

This reduces the risk that dma_map*() calls will fail on -ENOMEM, and reduces "thrashing" of the kernel page allocator.

In practice the IOVA allocator seems to prefer to re-use the highest available addresses rather than walking through the entire space, so it seems benign.

Allocate space for level-2 IOMMU translation tables on demand.
This should save memory in most cases but means that map_pages()
can now fail with -ENOMEM. Unused pages are retained for re-use.

Add OF properties to override the default aperture size (2GB)
and base address (40GB); this doesn't include any dma-iova-offset.

Various tidy-ups. The internal representation of aperture limits
*does* include dma_iova_offset, as that is more commonly useful.
Clarify the distinction between Linux pages and IOMMU table pages.
Fix wrong definition of MMMU_CTRL_PT_INVALID_EN flag.

Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
@njhollinghurst njhollinghurst force-pushed the iommu-202508 branch 2 times, most recently from 2d70a54 to bb59636 Compare August 19, 2025 13:51
@njhollinghurst
Copy link
Contributor Author

This has become a mess. I'm going to start again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant