Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: rpi-6.12.y
Choose a base branch
from

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
Copy link
Contributor Author

njhollinghurst commented Aug 15, 2025

Although it's configurable, I have held off increasing the default aperture size (which remains 2GB per IOMMU) so we can be certain that worst-case memory usage can't increase.

A bit more investigation may be needed to see if the DMA framework's allocator is willing to re-use virtual addresses (it appears so) rather than keep generating new ones; or if it would be beneficial to scavenge or free unused L2 pages (which might require keeping a use-count for each one and perhaps a free-list). But that's something for a future PR.

@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
Allocate space for level-2 IOMMU translation tables as needed.
This should save memory in most cases but it means that map()
can now fail with -ENOMEM. We don't currently free unused tables.

Add OF properties to override the default aperture size (2GB)
and base address (40GB; this doesn't include 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 <[email protected]>
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