Skip to content
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

dma: Remove use of Cell<Option<>> in DMA driver #1946

Open
wants to merge 1 commit into
base: main-2.x
Choose a base branch
from

Conversation

swenson
Copy link
Contributor

@swenson swenson commented Feb 5, 2025

Generally we only like to keep one copy of AxiDmaReg in existence, and use Rust's borrowing rules around &mut to ensure that it is safely accessed. However, this is not generally possible when implementing the Mmio trait, since the method receiver must be immutable.

Cell<Option<>> or RefCell can provide interior mutability so that we can safely share mutable references from immutable receivers, but it complicates the code and adds bloat to the binary.

However, since Caliptra is single-threaded, as long as we are careful about how we structure the code so that we don't ever have two AxiDmaReg instances in existence at the same time (which might cause conflicts in programming the underlying registers), then we will have fulfilled the contract with the unsafe code. This safety is ensured as long as there are no nested callers of Dma::with_dma.

Based on feedback from #1904.

@swenson swenson added the Caliptra v2.0 Items to be considered for v2.0 Release label Feb 5, 2025
Generally we only like to keep one copy of `AxiDmaReg` in existence,
and use Rust's borrowing rules around `&mut` to ensure that it is safely
accessed. However, this is not generally possible when implementing the
`Mmio` trait, since it requires interior mutability.

`Cell<Option<>>` or `RefCell` can provide interior mutability so that we
can safely share mutable references from immutable receivers, but it
complicates the code and adds bloat to the binary.

However, since Caliptra is single-threaded, as long as we are careful
about how we structure the code so that we don't ever have two
`AxiDmaReg` instances in existence at the same time (which might cause
conflicts in programming the underlying registers), then we will have
fulfilled the contract with the `unsafe` code. This safety is ensured as
long as there are no nested callers of `Dma::with_dma`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Caliptra v2.0 Items to be considered for v2.0 Release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants